/** * @module * Pure document state model. * * The editor's hard bugs were all state-sync bugs: block edits living only in * the shadow tree while `parse()` rebuilt from stale source, the source * textarea being re-seeded from the pre-edit document, source mode surviving a * switch to read-only and yielding `""`. Those are decisions about *state*, not * about the DOM, so they live here where they can be tested directly. * * `` owns a `DocumentState` and renders it; the DOM is a * projection, never the source of truth. */ /** A single block in the document. */ export interface DocumentBlock { type: string; raw: string; attrs: Record; } /** * Editor state. * * Exactly one of the two representations is authoritative at a time: * `sourceText` while `sourceMode` is true, `blocks` otherwise. Every transition * that flips `sourceMode` converts between them, so the two can never drift. */ export interface DocumentState { blocks: DocumentBlock[]; sourceMode: boolean; /** Authoritative document text while `sourceMode` is true. */ sourceText: string; } /** Build state from markdown. Starts in block mode. */ export declare function stateFromMarkdown(markdown: string): DocumentState; /** Serialize the block list back to markdown, ignoring source mode. */ export declare function serializeBlocks(blocks: readonly DocumentBlock[]): string; /** * The document's markdown, from whichever representation is authoritative. * This is what `.raw`, `serialize()` and form submission must all agree on. */ export declare function serializeState(state: DocumentState): string; /** Replace a block's content. Out-of-range indices are ignored. */ export declare function commitBlock(state: DocumentState, index: number, raw: string, attrs?: Record): DocumentState; /** Insert a block at `index`, clamped to the document bounds. */ export declare function insertBlock(state: DocumentState, index: number, block: DocumentBlock): DocumentState; /** Remove the block at `index`. Out-of-range indices are ignored. */ export declare function removeBlock(state: DocumentState, index: number): DocumentState; /** * Switch to source mode, seeding the text from the *current* blocks so * uncommitted-to-source block edits are carried across rather than discarded. */ export declare function enterSourceMode(state: DocumentState): DocumentState; /** Record a source-mode edit. No-op outside source mode. */ export declare function setSourceText(state: DocumentState, text: string): DocumentState; /** * Leave source mode, re-parsing the edited text into blocks. Used both by the * Visual toggle and by any transition that makes source mode unavailable * (read-only, disabled), so edits are never dropped on the floor. */ export declare function exitSourceMode(state: DocumentState): DocumentState; /** * Apply an editability change. Source mode requires an editable, unblocked * document; losing that demotes to block mode instead of leaving a hidden * block list and an empty serialization. */ export declare function setEditable(state: DocumentState, editable: boolean): DocumentState; /** Replace the whole document, preserving the current mode. */ export declare function replaceMarkdown(state: DocumentState, markdown: string): DocumentState; //# sourceMappingURL=document.d.ts.map