/** * ProseMirror → Loro. * * The write direction is a **reconciliation**, never a rewrite: it walks the * `pm_doc` against the containers already in the Loro document and emits only * the operations that differ. That is not an optimisation, it is the whole * point — replacing a paragraph's text container because one character changed * would destroy every concurrent edit another peer made inside it, and would * write a new `block_id` container on every keystroke. * * This module is the only one in the binding that constructs Loro containers, * so it is the only one that names a wasm build. */ import type { Node as PmNode, Schema } from 'prosemirror-model'; import type { ContainerID, LoroDoc } from 'loro-crdt'; import { LoroPmMapping, type PmChildItem } from './types.js'; import { type LoroNodeMap } from './convert.js'; /** * Teach the Loro document how each ProseMirror mark expands. * * Loro refuses `mark()` for a key it has no style config for, so this has to * run before the first write. `inclusive: false` marks (links, typically) stop * at their boundary; everything else grows with text typed at its end, which is * what ProseMirror's own `storedMarks` behaviour looks like. */ export declare function configureTextStyle(doc: LoroDoc, schema: Schema): void; /** A node's children, with consecutive text nodes collected into runs. */ export declare function pmChildItems(pm_node: PmNode): PmChildItem[]; /** Can this container be updated in place to hold this item, or must it go? */ /** * One reconciliation pass. * * `deferred`, when present, turns on the split that keeps undo safe. See * {@link createScaffolding}. */ export interface WritePass { mapping: LoroPmMapping; /** Node containers whose missing scaffolding was postponed, and their target. */ deferred?: Map; } /** * Reconcile one node container against one ProseMirror node. * * Returns true when some of this node's scaffolding was postponed — in which * case the node is deliberately **not** cached, so the follow-up pass walks it * again instead of short-circuiting on a node that is only half written. */ export declare function syncNode(container: LoroNodeMap, pm_node: PmNode, pass: WritePass): boolean; /** * Make the Loro document hold exactly this `pm_doc`, in the fewest operations. * * This is also the answer to `restore_unreachable` in * `04-crdt-and-history.md`: a checkpoint that survived compaction only as a * snapshot cannot be reverted to, but its `pm_doc` can be read out of a fork * and written forward through here, which is what "restore writes forward" * means at the schema layer. * * Must be called inside a `transact()` — it mutates but does not commit. */ export declare function writePmDocToLoro(doc: LoroDoc, pm_doc: PmNode, mapping?: LoroPmMapping, deferred?: Map): void; /** * Create the containers a deferred pass postponed — and nothing else. * * **Why this is a separate commit.** A `children` list and a `LoroText` run are * artefacts of how a `pm_doc` is encoded, not edits anybody made. If they are * created inside the same commit as the text that goes in them, that commit's * undo step deletes the container — and a container deletion takes every * concurrent edit inside it with it, because there is nothing left to rebase * onto. Measured: A types "local" into an empty paragraph, B types "R" into the * same paragraph, A presses undo, and B's "R" is gone. With the containers * created under an origin the `UndoManager` excludes, the undo step holds only * A's five characters, so the same flow leaves "R" standing. * * Block containers are deliberately **not** created here. Undoing "press Enter" * has to remove the paragraph, and a paragraph that a peer typed into is a real * block deletion — the user's own structural edit, not someone else's writing. */ export declare function createScaffolding(doc: LoroDoc, deferred: Map): void; //# sourceMappingURL=write.d.ts.map