import { type CanonicalInputPipeline, type ClipboardDiagnosticReport, type CanonicalSubtreeRenderer, type DocumentVersion, type FoundationEditor, type PersistedEditorDocument, type SmartMark, type SmartOperation, type SmartSelection, type SmartTransaction } from "smartrte-core/foundation"; import { type EditorCapabilityPreset } from "./capabilityPresets.js"; export interface SmartEditorCheckpoint { envelope: PersistedEditorDocument; selection: SmartSelection; storedMarks?: SmartMark[]; savedRevision: number; } export interface SmartEditorChange { revision: number; documentChanged: boolean; transaction: SmartTransaction; } export interface SmartEditorHandle { getValue(): PersistedEditorDocument; replaceValue(doc: PersistedEditorDocument, opts?: { keepSelection?: boolean; }): void; isDirty(): boolean; markSaved(revision: number): void; getRevision(): number; focus(): void; executeOperations(operations: readonly SmartOperation[], opts?: ExecuteOperationsOptions): void; createCheckpoint(): SmartEditorCheckpoint; restoreCheckpoint(checkpoint: SmartEditorCheckpoint): void; saveVersion(opts?: SaveVersionOptions): DocumentVersion; restoreVersion(version: DocumentVersion, opts?: { keepSelection?: boolean; }): void; } export interface SaveVersionOptions { label?: string; authorId?: string; } export interface ExecuteOperationsOptions { historyGroup?: string; addToHistory?: boolean; /** Keep structural commands anchored to the same stable inline-owner IDs. */ preserveSelectionById?: boolean; /** Put the caret in a newly-created inline owner after the operation. */ selectionOwnerId?: string; selectionOffset?: number; } export interface CanonicalEditorRuntimeOptions { initialValue?: string | PersistedEditorDocument; onChange?: (change: SmartEditorChange) => void; onHtmlChange?: (html: string) => void; onClipboardDiagnostic?: (report: ClipboardDiagnosticReport) => void; /** * Renderer-integrated content-visibility (Phase 11 Tier 3, opt-in, * default off) - only applies content-visibility:auto to a top-level * block the renderer's own diff already proved untouched this render * pass and that isn't the actively-selected block. See * surface/renderer.ts's syncContentVisibility for why this differs from * the disproven naive per-block experiment. */ contentVisibility?: boolean; /** Which built-in plugins this instance is constructed with - see capabilityPresets.ts. Defaults to "full" (every plugin), matching this runtime's only behavior before this option existed. */ preset?: EditorCapabilityPreset; /** * Bakes real KaTeX-rendered HTML into `onHtmlChange`'s formula elements * instead of leaving them as empty placeholders (docs/bugs/ * formula-not-rendered-in-static-html-consumers.md). Off by default - * the live editing surface already renders formulas correctly on its * own via surface/renderer.ts's imperative katex.render() calls, which * this option has no effect on; it exists purely for consumers that take * this HTML string and display it *without* also running KaTeX against * it themselves (e.g. a read-only preview panel built from saved HTML). */ renderFormulaHtml?: boolean; } /** Persistent, React-independent owner for one product editor instance. */ export declare class CanonicalEditorRuntime implements SmartEditorHandle { readonly editor: FoundationEditor; private root; private renderer; private pipeline; private unsubscribe; private savedRevision; private onChange?; private onHtmlChange?; private readonly onClipboardDiagnostic?; private readonly contentVisibility; private readonly renderFormulaHtml; private htmlChangeTimer; private pendingHtmlDocument; constructor(options?: CanonicalEditorRuntimeOptions); setCallbacks(onChange?: (change: SmartEditorChange) => void, onHtmlChange?: (html: string) => void): void; private scheduleHtmlChange; mount(root: HTMLElement): void; unmount(): void; getValue(): PersistedEditorDocument; replaceValue(doc: PersistedEditorDocument, opts?: { keepSelection?: boolean; }): void; isDirty(): boolean; markSaved(revision: number): void; getRevision(): number; focus(): void; executeOperations(operations: readonly SmartOperation[], opts?: ExecuteOperationsOptions): void; createCheckpoint(): SmartEditorCheckpoint; restoreCheckpoint(checkpoint: SmartEditorCheckpoint): void; /** * A pure read of current state, like `createCheckpoint` - never touches * the undo stack, never a `transact()` call. The runtime doesn't call a * `VersionProvider` itself (same division as `mediaProvider.upload` * being called directly from the React component, not the runtime) - * this just builds the payload a caller then hands to a provider. */ saveVersion(opts?: SaveVersionOptions): DocumentVersion; /** * Reuses `replaceValue` (the same "load a full snapshot" mechanism * `restoreCheckpoint` already uses) rather than replaying the version as * a sequence of operations - a version can be arbitrarily old, and * `replaceState` already validates/repairs an incoming document the same * way loading any document does. Deliberately does NOT reuse the * version's own stored `revision`: `replaceState` sets the live * revision counter to whatever it's given verbatim, so restoring an old * version's envelope as-is would roll a monotonic counter backward - * colliding with `StaleTransactionError`'s bookkeeping and this * runtime's own `isDirty()` comparison. Always re-stamps to * `currentRevision + 1` instead. Not undoable, same as checkpoint * restore today (`replaceState`'s emitted transaction always sets * `addToHistory: false`). Per the Phase 12a spec's explicit * recommendation, restore is non-destructive of version history at the * UI layer: the caller (`VersionHistoryPanel`) saves a new version * recording the restored state immediately after calling this, rather * than this method silently discarding anything - the version list only * ever grows, never rewrites. */ restoreVersion(version: DocumentVersion, opts?: { keepSelection?: boolean; }): void; /** Instrumentation for product-path composition and takeover tests. */ get surface(): { root: HTMLElement; renderer: CanonicalSubtreeRenderer; pipeline: CanonicalInputPipeline; }; } export declare const createCanonicalEditorRuntime: (options?: CanonicalEditorRuntimeOptions) => CanonicalEditorRuntime;