UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

54 lines 2.42 kB
import type { Root as HastRoot } from 'hast'; import type { Position } from "./useEditable.mjs"; import type { Code, VariantCode } from "../CodeHighlighter/types.mjs"; import type { CodeHighlighterContextType } from "../CodeHighlighter/CodeHighlighterContext.mjs"; import { preloadEditingEngine, resetEditingEngineCache } from "./editingEngineCache.mjs"; export type { Position }; /** * Warms the editing engine so the next edit applies synchronously. Back-compat * alias for {@link preloadEditingEngine}; the cache is shared with `useEditable`. */ export declare const preloadSourceEditingEngine: typeof preloadEditingEngine; /** Clears the shared editing-engine cache. Back-compat alias; for tests. */ export declare const resetSourceEditingEngineCache: typeof resetEditingEngineCache; /** * Internal `setSource` shape used by the editing pipeline. The 3rd and 4th * arguments (caret position, pre-parsed HAST) are wired between sibling * hooks (`useEditable` → `Pre` → `useSourceEditing`) and are NOT part of * the public `useCode` contract — host code should treat `setSource` as * `(source, fileName?) => void`. */ export type SetSource = (source: string, fileName?: string, position?: Position, preParsed?: HastRoot) => void; interface UseSourceEditingProps { context?: CodeHighlighterContextType; selectedVariantKey: string; effectiveCode: Code; selectedVariant: VariantCode | null; disabled?: boolean; } export interface UseSourceEditingResult { setSource?: SetSource; /** * Clears the entire controlled code state back to `undefined`, discarding * user edits across **all variants and files** owned by the surrounding * `CodeControllerContext` (not just the currently selected file or * variant), and falling back to the original code provided to the * `CodeHighlighter`. Only available when a `CodeControllerContext` with * `setCode` is in scope and editing is not disabled. */ reset?: () => void; } /** * Hook for managing source code editing functionality. * * Returns a `setSource(source, fileName?)` callback that updates the correct file * (main or extra) within the controlled code for the current variant. * If `fileName` is omitted, the currently selected file is assumed. */ export declare function useSourceEditing({ context, selectedVariantKey, effectiveCode, selectedVariant, disabled }: UseSourceEditingProps): UseSourceEditingResult;