foldkit-richtext 0.5.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clipboard.d.ts +224 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +208 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/code.d.ts +27 -0
- package/dist/code.d.ts.map +1 -0
- package/dist/code.js +45 -0
- package/dist/code.js.map +1 -0
- package/dist/command.d.ts +300 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +1438 -0
- package/dist/command.js.map +1 -0
- package/dist/decoration.d.ts +44 -0
- package/dist/decoration.d.ts.map +1 -0
- package/dist/decoration.js +96 -0
- package/dist/decoration.js.map +1 -0
- package/dist/document.d.ts +1045 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +544 -0
- package/dist/document.js.map +1 -0
- package/dist/footnote.d.ts +35 -0
- package/dist/footnote.d.ts.map +1 -0
- package/dist/footnote.js +100 -0
- package/dist/footnote.js.map +1 -0
- package/dist/history.d.ts +470 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +81 -0
- package/dist/history.js.map +1 -0
- package/dist/html.d.ts +27 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +99 -0
- package/dist/html.js.map +1 -0
- package/dist/indent.d.ts +16 -0
- package/dist/indent.d.ts.map +1 -0
- package/dist/indent.js +101 -0
- package/dist/indent.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +37 -0
- package/dist/input.js.map +1 -0
- package/dist/kit.d.ts +179 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +202 -0
- package/dist/kit.js.map +1 -0
- package/dist/marks.d.ts +79 -0
- package/dist/marks.d.ts.map +1 -0
- package/dist/marks.js +127 -0
- package/dist/marks.js.map +1 -0
- package/dist/media.d.ts +30 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +148 -0
- package/dist/media.js.map +1 -0
- package/dist/migration.d.ts +55 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +124 -0
- package/dist/migration.js.map +1 -0
- package/dist/outline.d.ts +15 -0
- package/dist/outline.d.ts.map +1 -0
- package/dist/outline.js +39 -0
- package/dist/outline.js.map +1 -0
- package/dist/rendering.d.ts +96 -0
- package/dist/rendering.d.ts.map +1 -0
- package/dist/rendering.js +106 -0
- package/dist/rendering.js.map +1 -0
- package/dist/replicated.d.ts +340 -0
- package/dist/replicated.d.ts.map +1 -0
- package/dist/replicated.js +1727 -0
- package/dist/replicated.js.map +1 -0
- package/dist/search.d.ts +28 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +61 -0
- package/dist/search.js.map +1 -0
- package/dist/standard.d.ts +61 -0
- package/dist/standard.d.ts.map +1 -0
- package/dist/standard.js +231 -0
- package/dist/standard.js.map +1 -0
- package/dist/table.d.ts +38 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +160 -0
- package/dist/table.js.map +1 -0
- package/dist/transaction.d.ts +712 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +993 -0
- package/dist/transaction.js.map +1 -0
- package/dist/transform.d.ts +48 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +94 -0
- package/dist/transform.js.map +1 -0
- package/dist/url.d.ts +16 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +32 -0
- package/dist/url.js.map +1 -0
- package/package.json +7 -7
- package/dist/index.d.mts +0 -3787
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -6688
- package/dist/index.mjs.map +0 -1
- package/dist/rolldown-runtime-D8jQpDG7.mjs +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","names":["pathKey","markName"],"sources":["../src/transaction.ts"],"sourcesContent":["import { Equal, Schema } from 'effect'\nimport { markName, sameMark } from './marks.js'\nimport {\n assertEditorState,\n Block,\n eachBlock,\n EditorState,\n NodeId,\n Position,\n RunMark,\n Selection,\n compareRunPlaces,\n type BlockPath,\n type Document,\n type NodeReference,\n type RunPlace,\n type Text,\n} from './document.js'\nimport { defaultTransforms, type Transform } from './transform.js'\n\n/** How many normalization passes a transaction may spend before it gives up. */\nexport const MAX_NORMALIZATION_PASSES = 10\n\nconst Offset = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))\n\nconst InsertTextOperation = Schema.Struct({\n type: Schema.Literal('InsertText'),\n at: Position,\n text: Schema.String,\n})\nconst DeleteTextOperation = Schema.Struct({\n type: Schema.Literal('DeleteText'),\n node: NodeId,\n from: Offset,\n to: Offset,\n})\nconst AddMarkOperation = Schema.Struct({\n type: Schema.Literal('AddMark'),\n node: NodeId,\n mark: RunMark,\n})\nconst RemoveMarkOperation = Schema.Struct({\n type: Schema.Literal('RemoveMark'),\n node: NodeId,\n mark: Schema.String,\n})\nconst SetSelectionOperation = Schema.Struct({\n type: Schema.Literal('SetSelection'),\n selection: Schema.NullOr(Selection),\n})\nconst SplitNodeOperation = Schema.Struct({\n type: Schema.Literal('SplitNode'),\n block: NodeId,\n node: NodeId,\n offset: Offset,\n blockId: NodeId,\n textId: NodeId,\n})\nconst JoinNodeOperation = Schema.Struct({\n type: Schema.Literal('JoinNode'),\n into: NodeId,\n removed: NodeId,\n})\nconst MoveNodeOperation = Schema.Struct({\n type: Schema.Literal('MoveNode'),\n node: NodeId,\n to: Offset,\n /** The block list to move into: a node block's, or the document's when absent. */\n parent: Schema.optionalKey(NodeId),\n})\n/**\n * What a text block retypes to: a paragraph, or a heading at a level. Its runs are\n * its own and survive the change; only the block's type does not.\n */\nexport const TextBlock = Schema.Union([\n Schema.Struct({ type: Schema.Literal('Paragraph') }),\n Schema.Struct({ type: Schema.Literal('Heading'), level: Schema.Literals([1, 2, 3, 4, 5, 6]) }),\n])\nexport type TextBlock = typeof TextBlock.Type\n\n/**\n * What a block becomes, under its own identity and with its own content: a block that holds\n * text becomes a paragraph, a heading, or an application node kind that holds text, such as a\n * code block, keeping its runs; a node that holds blocks becomes another node kind, keeping\n * its nested blocks, as a list item becomes a task.\n */\nexport const RetypeTarget = Schema.Union([\n Schema.Struct({ type: Schema.Literal('Paragraph') }),\n Schema.Struct({ type: Schema.Literal('Heading'), level: Schema.Literals([1, 2, 3, 4, 5, 6]) }),\n Schema.Struct({\n type: Schema.Literal('Node'),\n kind: Schema.NonEmptyString,\n props: Schema.JsonObject,\n }),\n])\nexport type RetypeTarget = typeof RetypeTarget.Type\n\nconst RetypeBlockOperation = Schema.Struct({\n type: Schema.Literal('RetypeBlock'),\n node: NodeId,\n to: RetypeTarget,\n})\nconst SetPropsOperation = Schema.Struct({\n type: Schema.Literal('SetProps'),\n node: NodeId,\n props: Schema.JsonObject,\n})\nconst InsertNodeOperation = Schema.Struct({\n type: Schema.Literal('InsertNode'),\n block: Block,\n at: Offset,\n /** The block list to insert into: a node block's, or the document's when absent. */\n parent: Schema.optionalKey(NodeId),\n})\nconst DeleteNodeOperation = Schema.Struct({\n type: Schema.Literal('DeleteNode'),\n node: NodeId,\n})\nconst SplitRunOperation = Schema.Struct({\n type: Schema.Literal('SplitRun'),\n node: NodeId,\n offset: Offset,\n textId: NodeId,\n})\n\nexport const Operation = Schema.Union([\n InsertTextOperation,\n DeleteTextOperation,\n AddMarkOperation,\n RemoveMarkOperation,\n SetSelectionOperation,\n SplitNodeOperation,\n JoinNodeOperation,\n MoveNodeOperation,\n RetypeBlockOperation,\n SetPropsOperation,\n InsertNodeOperation,\n DeleteNodeOperation,\n SplitRunOperation,\n])\nexport type Operation = typeof Operation.Type\nexport const Transaction = Schema.Array(Operation)\nexport type Transaction = typeof Transaction.Type\n\n/** A text-run target: a validated id or a reusable node reference. */\nexport type TextTarget = NodeId | NodeReference\n\nconst targetId = (target: TextTarget): NodeId => (typeof target === 'string' ? target : target.id)\n\n/** Accepts a raw string or validated id; empty strings throw via `NodeId`. */\nconst freshId = (id: string | NodeId): NodeId => (typeof id === 'string' ? NodeId.make(id) : id)\n\n/**\n * Typesafe constructors for transaction operations. Each builder accepts a\n * `NodeId` or a `Node.make` reference and validates shape immediately\n * (misuse throws), while document-dependent checks — node kind, existence,\n * bounds, selection resolution — remain `apply` diagnostics. Compose with\n * `Node.at` for positions: `Edit.insertText(Text.at(5, 'after'), '!')`.\n */\nexport const Edit = {\n insertText: (at: Position, text: string): Extract<Operation, { readonly type: 'InsertText' }> =>\n InsertTextOperation.make({ type: 'InsertText', at, text }),\n\n deleteText: (\n node: TextTarget,\n from: number,\n to: number,\n ): Extract<Operation, { readonly type: 'DeleteText' }> => {\n if (from > to) throw new Error(`Edit.deleteText: from (${from}) must not exceed to (${to})`)\n return DeleteTextOperation.make({ type: 'DeleteText', node: targetId(node), from, to })\n },\n\n addMark: (node: TextTarget, mark: RunMark): Extract<Operation, { readonly type: 'AddMark' }> =>\n AddMarkOperation.make({ type: 'AddMark', node: targetId(node), mark }),\n\n removeMark: (\n node: TextTarget,\n mark: string,\n ): Extract<Operation, { readonly type: 'RemoveMark' }> =>\n RemoveMarkOperation.make({ type: 'RemoveMark', node: targetId(node), mark }),\n\n setSelection: (\n selection: Selection | null,\n ): Extract<Operation, { readonly type: 'SetSelection' }> =>\n SetSelectionOperation.make({ type: 'SetSelection', selection }),\n\n splitBlock: (\n block: TextTarget,\n node: TextTarget,\n offset: number,\n newBlock: string | NodeId,\n newRun: string | NodeId,\n ): Extract<Operation, { readonly type: 'SplitNode' }> =>\n SplitNodeOperation.make({\n type: 'SplitNode',\n block: targetId(block),\n node: targetId(node),\n offset,\n blockId: freshId(newBlock),\n textId: freshId(newRun),\n }),\n\n joinBlocks: (\n survivor: TextTarget,\n removed: TextTarget,\n ): Extract<Operation, { readonly type: 'JoinNode' }> =>\n JoinNodeOperation.make({\n type: 'JoinNode',\n into: targetId(survivor),\n removed: targetId(removed),\n }),\n\n moveBlock: (\n node: TextTarget,\n to: number,\n parent?: TextTarget,\n ): Extract<Operation, { readonly type: 'MoveNode' }> =>\n MoveNodeOperation.make({\n type: 'MoveNode',\n node: targetId(node),\n to,\n ...(parent === undefined ? {} : { parent: targetId(parent) }),\n }),\n\n retypeBlock: (\n node: TextTarget,\n to: RetypeTarget,\n ): Extract<Operation, { readonly type: 'RetypeBlock' }> =>\n RetypeBlockOperation.make({ type: 'RetypeBlock', node: targetId(node), to }),\n\n /** Sets the named props of a node block; props it does not name keep their values. */\n setProps: (\n node: TextTarget,\n props: Schema.JsonObject,\n ): Extract<Operation, { readonly type: 'SetProps' }> =>\n SetPropsOperation.make({ type: 'SetProps', node: targetId(node), props }),\n\n insertBlock: (\n block: Block,\n at: number,\n parent?: TextTarget,\n ): Extract<Operation, { readonly type: 'InsertNode' }> =>\n InsertNodeOperation.make({\n type: 'InsertNode',\n block,\n at,\n ...(parent === undefined ? {} : { parent: targetId(parent) }),\n }),\n\n deleteBlock: (node: TextTarget): Extract<Operation, { readonly type: 'DeleteNode' }> =>\n DeleteNodeOperation.make({ type: 'DeleteNode', node: targetId(node) }),\n\n splitRun: (\n node: TextTarget,\n offset: number,\n newRun: string | NodeId,\n ): Extract<Operation, { readonly type: 'SplitRun' }> =>\n SplitRunOperation.make({\n type: 'SplitRun',\n node: targetId(node),\n offset,\n textId: freshId(newRun),\n }),\n}\n\nexport interface ChangeSet {\n readonly dirtyNodes: ReadonlySet<NodeId>\n readonly insertedNodes: ReadonlySet<NodeId>\n readonly removedNodes: ReadonlySet<NodeId>\n readonly textChanged: ReadonlySet<NodeId>\n readonly structureChanged: boolean\n readonly selectionChanged: boolean\n}\n\n/** One replacement of [from, to) with inserted UTF-16 units, in sequential coordinates. */\nexport interface PositionStep {\n readonly node: NodeId\n readonly from: number\n readonly to: number\n readonly inserted: number\n}\n\n/**\n * Split relocation: offsets > at move to into with offset - at; offset == at\n * follows affinity (before stays, after moves to 0); lower offsets stay.\n */\nexport interface SplitStep {\n readonly node: NodeId\n readonly into: NodeId\n readonly at: number\n}\n\n/**\n * Merge relocation: offsets >= at move to into with base + offset - at;\n * lower offsets stay. Affinity is preserved, not consulted: the source\n * location ceases to exist, so every endpoint must move.\n */\nexport interface RelocateStep {\n readonly node: NodeId\n readonly into: NodeId\n readonly at: number\n readonly base: number\n}\n\n/**\n * Deletion collapse: every offset in node moves to offset 0 of into;\n * affinity is preserved. Emitted per removed run when a surviving run exists;\n * with no text left, positions cannot map and selection clears instead.\n */\nexport interface CollapseStep {\n readonly node: NodeId\n readonly into: NodeId\n}\n\n/** Maps a position through each edit, preserving insertion affinity. */\nexport const mapPosition = (\n position: Position,\n steps: ReadonlyArray<PositionStep | SplitStep | RelocateStep | CollapseStep>,\n): Position =>\n steps.reduce((current, step) => {\n if (current.node !== step.node) return current\n if ('base' in step) {\n if (current.offset < step.at) return current\n return { ...current, node: step.into, offset: step.base + current.offset - step.at }\n }\n if ('at' in step) {\n if (current.offset < step.at) return current\n if (current.offset === step.at && current.affinity === 'before') return current\n return { ...current, node: step.into, offset: current.offset - step.at }\n }\n if ('into' in step) {\n return { ...current, node: step.into, offset: 0 }\n }\n if (current.offset < step.from) return current\n const offset =\n current.offset > step.to\n ? current.offset + step.inserted - (step.to - step.from)\n : step.from + (current.affinity === 'after' ? step.inserted : 0)\n return offset === current.offset ? current : { ...current, offset }\n }, position)\n\n/**\n * Maps a whole selection through steps: both range endpoints, or a node target\n * whose identity a step relocated. Steps that only replace text have no `into`,\n * so a node selection is unaffected by them.\n */\nexport const mapThrough = (\n selection: Selection | null,\n steps: ReadonlyArray<PositionStep | SplitStep | RelocateStep | CollapseStep>,\n): Selection | null => {\n if (selection === null) return null\n if (selection.type === 'Node') {\n const step = steps.find(candidate => 'into' in candidate && candidate.node === selection.node)\n return step === undefined || !('into' in step) ? selection : { ...selection, node: step.into }\n }\n return {\n ...selection,\n anchor: mapPosition(selection.anchor, steps),\n focus: mapPosition(selection.focus, steps),\n }\n}\n\nexport type TransactionResult =\n | {\n readonly ok: true\n readonly state: EditorState\n readonly changeSet: ChangeSet\n readonly positionMap: ReadonlyArray<PositionStep | SplitStep | RelocateStep | CollapseStep>\n /**\n * The transactions that produced `state`, in order, each normalized before the next:\n * folding `apply` over them from the input state yields `state` again. A command can\n * need more than one, and an action has at least one per command.\n */\n readonly transactions: ReadonlyArray<Transaction>\n }\n | {\n readonly ok: false\n readonly error:\n | 'InvalidInput'\n | 'MissingText'\n | 'MissingNode'\n | 'InvalidRange'\n | 'InvalidSelection'\n | 'InvalidParent'\n | 'ForbiddenMark'\n | 'UnexpectedChild'\n | 'UnstableNormalization'\n }\n\nconst decodeTransaction = Schema.decodeUnknownSync(Transaction, { onExcessProperty: 'error' })\nconst sameSelection = (left: Selection | null, right: Selection | null): boolean => {\n if (left === null || right === null) return left === right\n if (left.type === 'Node') return right.type === 'Node' && left.node === right.node\n if (right.type !== 'Range') return false\n return (['anchor', 'focus'] as const).every(\n key =>\n left[key].node === right[key].node &&\n left[key].offset === right[key].offset &&\n left[key].affinity === right[key].affinity,\n )\n}\n\n/** The nested block list of a container, or undefined for any other block. */\nconst nestedOf = (block: Block): ReadonlyArray<Block> | undefined =>\n block.type === 'Node' && block.blocks !== undefined ? block.blocks : undefined\n\n/**\n * A block's address: root-first container indices. `[2]` is the third top-level\n * block; `[2, 0]` is the first block nested inside it (§116). The document's own\n * block list is the container at `[]`.\n */\nconst pathKey = (path: BlockPath): string => path.join('.')\nconst keyToPath = (key: string): BlockPath => (key === '' ? [] : key.split('.').map(Number))\n\ninterface DocumentIndex {\n readonly blockPaths: ReadonlyMap<NodeId, BlockPath>\n readonly runPaths: ReadonlyMap<NodeId, { readonly path: BlockPath; readonly index: number }>\n}\nconst indexes = new WeakMap<Document, DocumentIndex>()\n/** Where each block and run sits, built once per document: documents are immutable. */\nconst indexDocument = (document: Document): DocumentIndex => {\n const cached = indexes.get(document)\n if (cached !== undefined) return cached\n const blockPaths = new Map<NodeId, BlockPath>()\n const runPaths = new Map<NodeId, { readonly path: BlockPath; readonly index: number }>()\n eachBlock(document.children, (block, path) => {\n blockPaths.set(block.id, path)\n for (const [runIndex, run] of block.children.entries()) {\n runPaths.set(run.id, { path, index: runIndex })\n }\n })\n const index = { blockPaths, runPaths }\n indexes.set(document, index)\n return index\n}\n\n/**\n * Pure, atomic text transaction. Rejection returns no partially edited state.\n * `transforms` defaults to the registry's shipped rules; a Kit's transforms\n * arrive here when Kit support lands.\n */\nexport const apply = (\n state: EditorState,\n transaction: Transaction,\n transforms: ReadonlyArray<Transform> = defaultTransforms,\n): TransactionResult => {\n try {\n assertEditorState(state)\n decodeTransaction(transaction)\n } catch {\n return { ok: false, error: 'InvalidInput' }\n }\n const initial = indexDocument(state.document)\n let { blockPaths, runPaths } = initial\n /** The index as this transaction's own copy, once `indexInserted` has written to it. */\n let owned: { blocks: Map<NodeId, BlockPath>; runs: Map<NodeId, RunPlace> } | undefined\n const reindex = () => {\n ;({ blockPaths, runPaths } = indexDocument(document))\n owned = undefined\n }\n // Identities stay reserved for the whole transaction so a reused id can never\n // silently address two nodes across structural edits: the input's, and every one\n // the transaction adds.\n const added = new Set<NodeId>()\n const usedIds = {\n has: (id: NodeId): boolean =>\n initial.runPaths.has(id) || initial.blockPaths.has(id) || added.has(id),\n add: (id: NodeId): void => void added.add(id),\n }\n let document: Document = state.document\n // Working copies: each touched container is copied once per transaction, so N\n // edits in one paragraph cost O(N) rather than N copies of the same array. A\n // container is a block list — the document's, or a node block's nested blocks —\n // and a block's runs are copied separately, keyed by that block's path.\n const workingBlocks = new Map<string, Array<Block>>()\n const workingRuns = new Map<string, Array<Text>>()\n const blockAt = (path: BlockPath): Block | undefined =>\n blocksAt(path.slice(0, -1))[path[path.length - 1]!]\n /** The block list at a container path, reading through any pending copy. */\n function blocksAt(containerPath: BlockPath): ReadonlyArray<Block> {\n const pending = workingBlocks.get(pathKey(containerPath))\n if (pending !== undefined) return pending\n if (containerPath.length === 0) return document.children\n const parent = blockAt(containerPath)\n return parent?.type === 'Node' && parent.blocks !== undefined ? parent.blocks : []\n }\n /** Copies a container, and its ancestors, once: writes never touch the input. */\n const ensureContainer = (containerPath: BlockPath): Array<Block> => {\n const key = pathKey(containerPath)\n const existing = workingBlocks.get(key)\n if (existing !== undefined) return existing\n if (containerPath.length > 0) ensureContainer(containerPath.slice(0, -1))\n const copy = [...blocksAt(containerPath)]\n workingBlocks.set(key, copy)\n return copy\n }\n /** The block's runs as they stand: a pending copy if one exists, else the document's. */\n const runsAt = (path: BlockPath): ReadonlyArray<Text> =>\n workingRuns.get(pathKey(path)) ?? blockAt(path)?.children ?? []\n /** The block's run array, copied on first write and mutated in place after. */\n const runArray = (path: BlockPath): Array<Text> => {\n const key = pathKey(path)\n const existing = workingRuns.get(key)\n if (existing !== undefined) return existing\n ensureContainer(path.slice(0, -1))\n const copy = [...(blockAt(path)?.children ?? [])]\n workingRuns.set(key, copy)\n return copy\n }\n /**\n * Indexes a block just inserted at `at` in a container, and moves each later sibling's\n * subtree one place on, rather than indexing the whole document again: a paste inserts one\n * block at a time, and reindexing after each made it quadratic in the blocks pasted.\n */\n const indexInserted = (containerPath: BlockPath, at: number): void => {\n const index = (owned ??= { blocks: new Map(blockPaths), runs: new Map(runPaths) })\n blockPaths = index.blocks\n runPaths = index.runs\n const record = (block: Block, path: BlockPath): void => {\n index.blocks.set(block.id, path)\n block.children.forEach((run, place) => index.runs.set(run.id, { path, index: place }))\n if (block.type === 'Node' && block.blocks !== undefined) {\n block.blocks.forEach((child, place) => record(child, [...path, place]))\n }\n }\n const blocks = blocksAt(containerPath)\n for (let place = at; place < blocks.length; place++) {\n record(blocks[place]!, [...containerPath, place])\n }\n }\n const writeBlock = (path: BlockPath, block: Block): void => {\n const container = ensureContainer(path.slice(0, -1))\n container[path[path.length - 1]!] = block\n }\n /**\n * The block list a structural operation targets: the document's, or a node\n * block's nested blocks. A parent that cannot hold blocks is `InvalidParent`,\n * one that does not exist is `MissingNode`.\n */\n const containerPathOf = (\n parent: NodeId | undefined,\n ): { readonly path: BlockPath } | { readonly error: 'MissingNode' | 'InvalidParent' } => {\n if (parent === undefined) return { path: [] }\n const path = blockPaths.get(parent)\n if (path === undefined) return { error: 'MissingNode' }\n const block = blockAt(path)\n return block?.type === 'Node' && block.blocks !== undefined\n ? { path }\n : { error: 'InvalidParent' }\n }\n const materialize = (): void => {\n if (workingBlocks.size === 0 && workingRuns.size === 0) return\n // Runs fold into their block, then each container folds into its parent. A\n // container's copy already holds its child's final value, so the order of\n // the second pass does not matter; only touched containers are visited.\n for (const [key, runs] of workingRuns) {\n const path = keyToPath(key)\n const container = workingBlocks.get(pathKey(path.slice(0, -1)))!\n const index = path[path.length - 1]!\n container[index] = { ...container[index]!, children: runs }\n }\n workingRuns.clear()\n for (const [key, blocks] of workingBlocks) {\n const path = keyToPath(key)\n if (path.length === 0) {\n document = { ...document, children: blocks }\n continue\n }\n const parent = workingBlocks.get(pathKey(path.slice(0, -1)))!\n const index = path[path.length - 1]!\n const parentBlock = parent[index]!\n // Only a node block holds nested blocks, and only its path can be a\n // container, so this narrowing always holds.\n if (parentBlock.type === 'Node') parent[index] = { ...parentBlock, blocks }\n }\n workingBlocks.clear()\n }\n let selection = state.selection\n const dirtyNodes = new Set<NodeId>()\n const insertedNodes = new Set<NodeId>()\n const removedNodes = new Set<NodeId>()\n const textChanged = new Set<NodeId>()\n let structureChanged = false\n const positionMap: Array<PositionStep | SplitStep | RelocateStep | CollapseStep> = []\n /** `selectionIsValid` against the working document, read through the index this transaction keeps. */\n const selectionFits = (candidate: Selection | null): boolean => {\n if (candidate === null) return true\n if (candidate.type === 'Node')\n return blockPaths.has(candidate.node) || runPaths.has(candidate.node)\n return [candidate.anchor, candidate.focus].every(position => {\n const location = runPaths.get(position.node)\n const run = location === undefined ? undefined : runsAt(location.path)[location.index]\n // The offset's sign and integrality are the decoded transaction's already.\n return run !== undefined && position.offset <= run.text.length\n })\n }\n for (let operationIndex = 0; operationIndex < transaction.length; operationIndex++) {\n const operation = transaction[operationIndex]!\n if (operation.type === 'SetSelection') {\n // A pending edit could change what a position resolves against.\n materialize()\n if (!selectionFits(operation.selection)) {\n return { ok: false, error: 'InvalidSelection' }\n }\n selection = operation.selection\n continue\n }\n if (operation.type === 'SplitRun') {\n const location = runPaths.get(operation.node)\n if (location === undefined) return { ok: false, error: 'MissingText' }\n const { path, index: textIndex } = location\n const target = blockAt(path)\n if (target === undefined) return { ok: false, error: 'MissingText' }\n const run = runsAt(path)[textIndex]!\n if (operation.offset > run.text.length) return { ok: false, error: 'InvalidRange' }\n if (usedIds.has(operation.textId)) return { ok: false, error: 'InvalidInput' }\n if (operation.offset === 0) {\n // No left remainder: the new run would be an empty duplicate. Splitting\n // at 0 is the caller's no-op, not a silent identity change.\n continue\n }\n const children = runArray(path)\n children[textIndex] = { ...run, text: run.text.slice(0, operation.offset) }\n children.splice(textIndex + 1, 0, {\n ...run,\n id: operation.textId,\n text: run.text.slice(operation.offset),\n })\n usedIds.add(operation.textId)\n materialize()\n reindex()\n const relocate: SplitStep = {\n node: run.id,\n into: operation.textId,\n at: operation.offset,\n }\n positionMap.push(relocate)\n if (selection?.type === 'Range') {\n selection = {\n ...selection,\n anchor: mapPosition(selection.anchor, [relocate]),\n focus: mapPosition(selection.focus, [relocate]),\n }\n }\n dirtyNodes.add(target.id)\n dirtyNodes.add(run.id)\n dirtyNodes.add(operation.textId)\n textChanged.add(run.id)\n textChanged.add(operation.textId)\n insertedNodes.add(operation.textId)\n continue\n }\n if (operation.type === 'SplitNode') {\n materialize()\n const blockPath = blockPaths.get(operation.block)\n if (blockPath === undefined) return { ok: false, error: 'MissingNode' }\n const runLocation = runPaths.get(operation.node)\n if (runLocation === undefined) return { ok: false, error: 'MissingText' }\n const { path: runBlockPath, index: textIndex } = runLocation\n if (pathKey(runBlockPath) !== pathKey(blockPath)) return { ok: false, error: 'InvalidRange' }\n const target = blockAt(blockPath)!\n const run = target.children[textIndex]!\n if (operation.offset > run.text.length) return { ok: false, error: 'InvalidRange' }\n if (\n usedIds.has(operation.blockId) ||\n usedIds.has(operation.textId) ||\n operation.blockId === operation.textId\n ) {\n return { ok: false, error: 'InvalidInput' }\n }\n const leftBlock = {\n ...target,\n children: [\n ...target.children.slice(0, textIndex),\n { ...run, text: run.text.slice(0, operation.offset) },\n ],\n }\n const rightBlock = {\n ...target,\n id: operation.blockId,\n children: [\n { ...run, id: operation.textId, text: run.text.slice(operation.offset) },\n ...target.children.slice(textIndex + 1),\n ],\n }\n // The halves land in the block's own container, so a split inside a\n // container stays inside it.\n const containerPath = blockPath.slice(0, -1)\n const index = blockPath[blockPath.length - 1]!\n const container = ensureContainer(containerPath)\n container[index] = leftBlock\n container.splice(index + 1, 0, rightBlock)\n materialize()\n usedIds.add(operation.blockId)\n usedIds.add(operation.textId)\n reindex()\n const relocate: SplitStep = { node: run.id, into: operation.textId, at: operation.offset }\n positionMap.push(relocate)\n if (selection?.type === 'Range') {\n selection = {\n ...selection,\n anchor: mapPosition(selection.anchor, [relocate]),\n focus: mapPosition(selection.focus, [relocate]),\n }\n }\n dirtyNodes.add(target.id)\n dirtyNodes.add(operation.blockId)\n dirtyNodes.add(run.id)\n dirtyNodes.add(operation.textId)\n for (const moved of target.children.slice(textIndex + 1)) dirtyNodes.add(moved.id)\n textChanged.add(run.id)\n textChanged.add(operation.textId)\n insertedNodes.add(operation.blockId)\n insertedNodes.add(operation.textId)\n structureChanged = true\n continue\n }\n if (operation.type === 'JoinNode') {\n materialize()\n const intoPath = blockPaths.get(operation.into)\n if (intoPath === undefined) return { ok: false, error: 'MissingNode' }\n const removedPath = blockPaths.get(operation.removed)\n if (removedPath === undefined) return { ok: false, error: 'MissingNode' }\n // Siblings only: two blocks in different containers have no boundary\n // between them to remove.\n if (pathKey(intoPath.slice(0, -1)) !== pathKey(removedPath.slice(0, -1))) {\n return { ok: false, error: 'InvalidParent' }\n }\n const containerPath = intoPath.slice(0, -1)\n const intoIndex = intoPath[intoPath.length - 1]!\n const removedIndex = removedPath[removedPath.length - 1]!\n if (removedIndex !== intoIndex + 1) return { ok: false, error: 'InvalidRange' }\n const container = ensureContainer(containerPath)\n const survivor = container[intoIndex]!\n const removedBlocks: Array<Block> = []\n while (operationIndex < transaction.length) {\n const next = transaction[operationIndex]\n if (next?.type !== 'JoinNode' || next.into !== operation.into) break\n const removed = container[intoIndex + removedBlocks.length + 1]\n if (removed?.id !== next.removed) break\n // Opaque content cannot be merged without silently discarding it.\n if (survivor.type === 'Unknown' || removed.type === 'Unknown') {\n return { ok: false, error: 'InvalidRange' }\n }\n if (survivor.type === 'Node' || removed.type === 'Node') {\n if (\n survivor.type !== 'Node' ||\n removed.type !== 'Node' ||\n survivor.kind !== removed.kind ||\n !Equal.equals(survivor.props, removed.props)\n )\n return { ok: false, error: 'InvalidRange' }\n }\n // A container and a run holder merge differently: joining a list with a\n // paragraph would have to drop one side's shape.\n if ((nestedOf(survivor) === undefined) !== (nestedOf(removed) === undefined)) {\n return { ok: false, error: 'InvalidRange' }\n }\n removedBlocks.push(removed)\n operationIndex++\n }\n operationIndex--\n const mergedRuns = [...survivor.children, ...removedBlocks.flatMap(block => block.children)]\n if (survivor.type === 'Node' && survivor.blocks !== undefined) {\n container[intoIndex] = {\n ...survivor,\n children: mergedRuns,\n blocks: [...survivor.blocks, ...removedBlocks.flatMap(block => nestedOf(block) ?? [])],\n }\n } else {\n container[intoIndex] = { ...survivor, children: mergedRuns }\n }\n container.splice(removedIndex, removedBlocks.length)\n materialize()\n reindex()\n for (const removed of removedBlocks) {\n // A Node selection on a retired identity follows the survivor.\n if (selection?.type === 'Node' && selection.node === removed.id) {\n selection = { ...selection, node: operation.into }\n }\n }\n dirtyNodes.add(operation.into)\n for (const removed of removedBlocks) {\n dirtyNodes.add(removed.id)\n removedNodes.add(removed.id)\n for (const moved of removed.children) dirtyNodes.add(moved.id)\n }\n structureChanged = true\n continue\n }\n if (operation.type === 'MoveNode') {\n materialize()\n const fromPath = blockPaths.get(operation.node)\n if (fromPath === undefined) return { ok: false, error: 'MissingNode' }\n const target = containerPathOf(operation.parent)\n if ('error' in target) return { ok: false, error: target.error }\n // A block cannot hold itself: moving one into its own subtree would detach both.\n if (fromPath.every((index, depth) => target.path[depth] === index)) {\n return { ok: false, error: 'InvalidParent' }\n }\n const sourcePath = fromPath.slice(0, -1)\n const fromIndex = fromPath[fromPath.length - 1]!\n // A move within one container lands at an existing index; a move into\n // another can append, so its bound is that container's length.\n const sameContainer = pathKey(sourcePath) === pathKey(target.path)\n const limit = sameContainer ? blocksAt(target.path).length - 1 : blocksAt(target.path).length\n if (operation.to > limit) return { ok: false, error: 'InvalidRange' }\n if (sameContainer && operation.to === fromIndex) continue\n const source = ensureContainer(sourcePath)\n const [moved] = source.splice(fromIndex, 1)\n if (sameContainer) {\n source.splice(operation.to, 0, moved!)\n } else {\n // The removal is folded in and the destination found again before inserting: taking\n // the block out can shift the destination's path, and inserting can shift the\n // source's, so neither copy may be folded against the other's old indices.\n materialize()\n reindex()\n const destination = containerPathOf(operation.parent)\n if ('error' in destination) return { ok: false, error: destination.error }\n ensureContainer(destination.path).splice(operation.to, 0, moved!)\n }\n materialize()\n reindex()\n dirtyNodes.add(operation.node)\n structureChanged = true\n continue\n }\n if (operation.type === 'RetypeBlock') {\n const path = blockPaths.get(operation.node)\n if (path === undefined) return { ok: false, error: 'MissingNode' }\n const target = blockAt(path)\n const to = operation.to\n // Content keeps its shape: runs stay runs, and nested blocks stay nested, so a node\n // holding blocks retypes only to another node. Preserved content is never rewritten.\n const nested = target?.type === 'Node' && target.blocks !== undefined\n if (target === undefined || target.type === 'Unknown' || (nested && to.type !== 'Node')) {\n return { ok: false, error: 'InvalidRange' }\n }\n const already =\n to.type === 'Paragraph'\n ? target.type === 'Paragraph'\n : to.type === 'Heading'\n ? target.type === 'Heading' && target.level === to.level\n : target.type === 'Node' &&\n target.kind === to.kind &&\n Equal.equals(target.props, to.props)\n if (already) continue\n writeBlock(\n path,\n to.type === 'Paragraph'\n ? { type: 'Paragraph', id: target.id, children: target.children }\n : to.type === 'Heading'\n ? { type: 'Heading', id: target.id, level: to.level, children: target.children }\n : {\n type: 'Node',\n kind: to.kind,\n id: target.id,\n props: to.props,\n children: target.children,\n ...(nested ? { blocks: target.blocks } : {}),\n },\n )\n dirtyNodes.add(target.id)\n structureChanged = true\n continue\n }\n if (operation.type === 'SetProps') {\n const path = blockPaths.get(operation.node)\n if (path === undefined) return { ok: false, error: 'MissingNode' }\n const target = blockAt(path)\n // Only an application node has props; a text block's shape is its type.\n if (target?.type !== 'Node') return { ok: false, error: 'InvalidRange' }\n const props = { ...target.props, ...operation.props }\n if (Equal.equals(props, target.props)) continue\n writeBlock(path, { ...target, props })\n dirtyNodes.add(target.id)\n continue\n }\n if (operation.type === 'InsertNode') {\n const target = containerPathOf(operation.parent)\n if ('error' in target) return { ok: false, error: target.error }\n // A pending copy under a place the insert shifts would be folded back at the wrong\n // path. The container and its ancestors do not shift, so a run of inserts into one\n // container, as a paste is, keeps its copy rather than copying the list each time.\n const unshifted = new Set(\n Array.from({ length: target.path.length + 1 }, (_, depth) =>\n pathKey(target.path.slice(0, depth)),\n ),\n )\n if (workingRuns.size > 0 || [...workingBlocks.keys()].some(key => !unshifted.has(key))) {\n materialize()\n }\n if (operation.at > blocksAt(target.path).length) return { ok: false, error: 'InvalidRange' }\n const carried: Array<NodeId> = []\n eachBlock([operation.block], block => {\n carried.push(block.id)\n for (const run of block.children) carried.push(run.id)\n })\n if (new Set(carried).size !== carried.length || carried.some(id => usedIds.has(id))) {\n return { ok: false, error: 'InvalidInput' }\n }\n const container = ensureContainer(target.path)\n container.splice(operation.at, 0, operation.block)\n for (const id of carried) {\n usedIds.add(id)\n dirtyNodes.add(id)\n insertedNodes.add(id)\n }\n indexInserted(target.path, operation.at)\n structureChanged = true\n continue\n }\n if (operation.type === 'DeleteNode') {\n materialize()\n const path = blockPaths.get(operation.node)\n if (path === undefined) return { ok: false, error: 'MissingNode' }\n const containerPath = path.slice(0, -1)\n const index = path[path.length - 1]!\n const target = blockAt(path)!\n const container = ensureContainer(containerPath)\n container.splice(index, 1)\n materialize()\n reindex()\n // The nearest surviving run in document order — the first at or after the\n // removed block's place, else the last before it — or nothing, which\n // clears the selection. Walking the tree is what lets a delete beside a\n // container collapse into the container's own runs.\n const removedPlace = { path, index: 0 }\n let fallback: { readonly block: Block; readonly run: Text } | undefined\n let after: { readonly block: Block; readonly run: Text } | undefined\n eachBlock(document.children, (block, blockPath) => {\n for (const [runIndex, run] of block.children.entries()) {\n const place = { path: blockPath, index: runIndex }\n if (compareRunPlaces(place, removedPlace) >= 0) after ??= { block, run }\n else fallback = { block, run }\n }\n })\n const landing = after ?? fallback\n const collapses: Array<CollapseStep> = []\n const removedRuns: Array<NodeId> = []\n const collect = (block: Block): void => {\n for (const run of block.children) removedRuns.push(run.id)\n if (block.type === 'Node' && block.blocks !== undefined) block.blocks.forEach(collect)\n }\n collect(target)\n if (landing !== undefined) {\n for (const run of removedRuns) collapses.push({ node: run, into: landing.run.id })\n }\n if (selection?.type === 'Range') {\n selection =\n landing === undefined\n ? null\n : {\n ...selection,\n anchor: mapPosition(selection.anchor, collapses),\n focus: mapPosition(selection.focus, collapses),\n }\n } else if (selection?.type === 'Node') {\n const selectedNode = selection.node\n if (selectedNode === operation.node || removedRuns.includes(selectedNode)) {\n selection = landing === undefined ? null : { ...selection, node: landing.block.id }\n }\n }\n for (const step of collapses) positionMap.push(step)\n const removedIds: Array<NodeId> = []\n const collectIds = (block: Block): void => {\n removedIds.push(block.id, ...block.children.map(run => run.id))\n if (block.type === 'Node' && block.blocks !== undefined) block.blocks.forEach(collectIds)\n }\n collectIds(target)\n for (const id of removedIds) {\n dirtyNodes.add(id)\n removedNodes.add(id)\n }\n structureChanged = true\n continue\n }\n const id = operation.type === 'InsertText' ? operation.at.node : operation.node\n const location = runPaths.get(id)\n if (location === undefined) return { ok: false, error: 'MissingText' }\n const { path, index: textIndex } = location\n const block = blockAt(path)\n if (block === undefined) return { ok: false, error: 'MissingText' }\n const text = runsAt(path)[textIndex]!\n if (operation.type === 'AddMark') {\n // A run carries a mark name at most once, so adding is a *set*: append\n // when the name is absent, replace when its props differ, and no-op when\n // the mark is already exactly this one (which keeps state identity).\n const existing = text.marks.find(mark => markName(mark) === markName(operation.mark))\n if (existing !== undefined && sameMark(existing, operation.mark)) continue\n const children = runArray(path)\n children[textIndex] = {\n ...text,\n marks:\n existing === undefined\n ? [...text.marks, operation.mark]\n : text.marks.map(mark =>\n markName(mark) === markName(operation.mark) ? operation.mark : mark,\n ),\n }\n dirtyNodes.add(block.id)\n dirtyNodes.add(id)\n textChanged.add(id)\n continue\n }\n if (operation.type === 'RemoveMark') {\n if (!text.marks.some(mark => markName(mark) === operation.mark)) continue\n const children = runArray(path)\n children[textIndex] = {\n ...text,\n marks: text.marks.filter(mark => markName(mark) !== operation.mark),\n }\n dirtyNodes.add(block.id)\n dirtyNodes.add(id)\n textChanged.add(id)\n continue\n }\n const from = operation.type === 'InsertText' ? operation.at.offset : operation.from\n const to = operation.type === 'InsertText' ? from : operation.to\n const inserted = operation.type === 'InsertText' ? operation.text : ''\n if (from > to || to > text.text.length) return { ok: false, error: 'InvalidRange' }\n if (from === to && inserted.length === 0) continue\n const children = runArray(path)\n children[textIndex] = {\n ...text,\n text: text.text.slice(0, from) + inserted + text.text.slice(to),\n }\n const step = { node: id, from, to, inserted: inserted.length }\n positionMap.push(step)\n if (selection?.type === 'Range') {\n selection = {\n ...selection,\n anchor: mapPosition(selection.anchor, [step]),\n focus: mapPosition(selection.focus, [step]),\n }\n }\n dirtyNodes.add(block.id)\n dirtyNodes.add(id)\n textChanged.add(id)\n }\n // The op loop accumulates; the document is assembled once, here.\n materialize()\n // Normalization runs as transforms (§23): each is deterministic and idempotent\n // on normalized state, so the loop settles. The pass bound is a diagnostic,\n // not a hang: a transform that keeps changing the document is refused rather\n // than spinning.\n let pass = 0\n for (; pass < MAX_NORMALIZATION_PASSES; pass++) {\n let changed = false\n for (const transform of transforms) {\n const report = transform.apply(document, { dirtyNodes, pass })\n if (report.document === document) continue\n changed = true\n document = report.document\n for (const id of report.insertedNodes) insertedNodes.add(id)\n for (const id of report.removedNodes) removedNodes.add(id)\n for (const id of report.dirtyNodes) dirtyNodes.add(id)\n for (const id of report.textChanged) textChanged.add(id)\n for (const step of report.steps) positionMap.push(step)\n if (report.structureChanged) structureChanged = true\n if (report.steps.length > 0) selection = mapThrough(selection, report.steps)\n reindex()\n }\n if (!changed) break\n }\n if (pass === MAX_NORMALIZATION_PASSES) return { ok: false, error: 'UnstableNormalization' }\n return {\n ok: true,\n state:\n document === state.document && sameSelection(selection, state.selection)\n ? state\n : { document, selection },\n changeSet: {\n dirtyNodes,\n insertedNodes,\n removedNodes,\n textChanged,\n structureChanged,\n selectionChanged: !sameSelection(selection, state.selection),\n },\n positionMap,\n transactions: [transaction],\n }\n}\n"],"mappings":";;;;;;AAqBA,MAAa,2BAA2B;AAExC,MAAM,SAAS,OAAO,OAAO,MAAM,OAAO,MAAM,GAAG,OAAO,uBAAuB,CAAC,CAAC;AAEnF,MAAM,sBAAsB,OAAO,OAAO;CACxC,MAAM,OAAO,QAAQ,YAAY;CACjC,IAAI;CACJ,MAAM,OAAO;AACf,CAAC;AACD,MAAM,sBAAsB,OAAO,OAAO;CACxC,MAAM,OAAO,QAAQ,YAAY;CACjC,MAAM;CACN,MAAM;CACN,IAAI;AACN,CAAC;AACD,MAAM,mBAAmB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,SAAS;CAC9B,MAAM;CACN,MAAM;AACR,CAAC;AACD,MAAM,sBAAsB,OAAO,OAAO;CACxC,MAAM,OAAO,QAAQ,YAAY;CACjC,MAAM;CACN,MAAM,OAAO;AACf,CAAC;AACD,MAAM,wBAAwB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,cAAc;CACnC,WAAW,OAAO,OAAO,SAAS;AACpC,CAAC;AACD,MAAM,qBAAqB,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ,WAAW;CAChC,OAAO;CACP,MAAM;CACN,QAAQ;CACR,SAAS;CACT,QAAQ;AACV,CAAC;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itStep } from "./transaction.js";
|
|
3
|
+
/**
|
|
4
|
+
* Transforms normalize or derive semantic structure after edits (§23). A
|
|
5
|
+
* transform is a pure function of the document plus what the transaction
|
|
6
|
+
* touched: it returns a whole new document and the position steps and identity
|
|
7
|
+
* bookkeeping that go with it, so `apply` can fold it into the same ChangeSet
|
|
8
|
+
* and position map it was already building.
|
|
9
|
+
*
|
|
10
|
+
* Two rules make a registry safe to run in a loop (§24): a transform must be
|
|
11
|
+
* deterministic, and it must be idempotent on normalized state — so running it
|
|
12
|
+
* again after it has run changes nothing, which is how the loop knows it has
|
|
13
|
+
* settled.
|
|
14
|
+
*/
|
|
15
|
+
export interface TransformContext {
|
|
16
|
+
/** Blocks the transaction touched, plus whatever earlier transforms touched. */
|
|
17
|
+
readonly dirtyNodes: ReadonlySet<NodeId>;
|
|
18
|
+
/** Runs already spent, so a transform can bail out rather than spin. */
|
|
19
|
+
readonly pass: number;
|
|
20
|
+
}
|
|
21
|
+
export interface TransformReport {
|
|
22
|
+
readonly document: Document;
|
|
23
|
+
/** The same step vocabulary a transaction uses, so `apply` can fold either. */
|
|
24
|
+
readonly steps: ReadonlyArray<PositionStep | SplitStep | RelocateStep | CollapseStep>;
|
|
25
|
+
readonly insertedNodes: ReadonlySet<NodeId>;
|
|
26
|
+
readonly removedNodes: ReadonlySet<NodeId>;
|
|
27
|
+
readonly dirtyNodes: ReadonlySet<NodeId>;
|
|
28
|
+
/** Runs whose text a transform rewrote, such as a merge's accumulator. */
|
|
29
|
+
readonly textChanged: ReadonlySet<NodeId>;
|
|
30
|
+
/** Whether the block list changed shape, not just the runs inside a block. */
|
|
31
|
+
readonly structureChanged: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface Transform {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly apply: (document: Document, context: TransformContext) => TransformReport;
|
|
36
|
+
}
|
|
37
|
+
/** A transform that found nothing to do. */
|
|
38
|
+
export declare const unchanged: (document: Document) => TransformReport;
|
|
39
|
+
/**
|
|
40
|
+
* Merges adjacent runs whose mark sets match, within the blocks the transaction
|
|
41
|
+
* touched, at any depth. Merging strictly reduces the run count, so one pass reaches
|
|
42
|
+
* a stable state and a second pass finds nothing: the rule is idempotent, and only
|
|
43
|
+
* equal mark sets merge, so an unknown mark never drops.
|
|
44
|
+
*/
|
|
45
|
+
export declare const mergeAdjacentRuns: Transform;
|
|
46
|
+
/** The transforms every transaction runs, in order, unless a caller says otherwise. */
|
|
47
|
+
export declare const defaultTransforms: ReadonlyArray<Transform>;
|
|
48
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","names":[],"sources":["../src/transform.ts"],"mappings":";;;;;;;;;;;;;;iBAgBiB;;WAEN,YAAY,YAAY;;WAExB;;iBAGM;WACN,UAAU;;WAEV,OAAO,cAAc,eAAe,YAAY,eAAe;WAC/D,eAAe,YAAY;WAC3B,cAAc,YAAY;WAC1B,YAAY,YAAY;;WAExB,aAAa,YAAY;;WAEzB;;iBAGM;WACN;WACA,QAAQ,UAAU,UAAU,SAAS,qBAAqB;;;qBAIxD,YAAS,UAAc,aAAW;;;;;;;qBAqBlC,mBAAmB;;qBA+DnB,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import "./document.js";
|
|
2
|
+
import { sameMarkSet } from "./marks.js";
|
|
3
|
+
// src/transform.ts
|
|
4
|
+
/** A transform that found nothing to do. */
|
|
5
|
+
const unchanged = (document) => ({
|
|
6
|
+
document,
|
|
7
|
+
steps: [],
|
|
8
|
+
insertedNodes: /* @__PURE__ */ new Set(),
|
|
9
|
+
removedNodes: /* @__PURE__ */ new Set(),
|
|
10
|
+
dirtyNodes: /* @__PURE__ */ new Set(),
|
|
11
|
+
textChanged: /* @__PURE__ */ new Set(),
|
|
12
|
+
structureChanged: false
|
|
13
|
+
});
|
|
14
|
+
const mergeRunInto = (accumulator, run) => ({
|
|
15
|
+
...accumulator,
|
|
16
|
+
text: accumulator.text + run.text
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Merges adjacent runs whose mark sets match, within the blocks the transaction
|
|
20
|
+
* touched, at any depth. Merging strictly reduces the run count, so one pass reaches
|
|
21
|
+
* a stable state and a second pass finds nothing: the rule is idempotent, and only
|
|
22
|
+
* equal mark sets merge, so an unknown mark never drops.
|
|
23
|
+
*/
|
|
24
|
+
const mergeAdjacentRuns = {
|
|
25
|
+
name: "mergeAdjacentRuns",
|
|
26
|
+
apply: (document, context) => {
|
|
27
|
+
const steps = [];
|
|
28
|
+
const removedNodes = /* @__PURE__ */ new Set();
|
|
29
|
+
const dirtyNodes = /* @__PURE__ */ new Set();
|
|
30
|
+
const textChanged = /* @__PURE__ */ new Set();
|
|
31
|
+
const mergeRuns = (block) => {
|
|
32
|
+
const first = block.children[0];
|
|
33
|
+
if (!context.dirtyNodes.has(block.id) || first === void 0) return block;
|
|
34
|
+
let accumulator = first;
|
|
35
|
+
let changed = false;
|
|
36
|
+
const kept = [accumulator];
|
|
37
|
+
for (const run of block.children.slice(1)) if (sameMarkSet(accumulator.marks, run.marks)) {
|
|
38
|
+
steps.push({
|
|
39
|
+
node: run.id,
|
|
40
|
+
into: accumulator.id,
|
|
41
|
+
at: 0,
|
|
42
|
+
base: accumulator.text.length
|
|
43
|
+
});
|
|
44
|
+
accumulator = mergeRunInto(accumulator, run);
|
|
45
|
+
kept[kept.length - 1] = accumulator;
|
|
46
|
+
removedNodes.add(run.id);
|
|
47
|
+
dirtyNodes.add(accumulator.id);
|
|
48
|
+
textChanged.add(accumulator.id);
|
|
49
|
+
changed = true;
|
|
50
|
+
} else {
|
|
51
|
+
accumulator = run;
|
|
52
|
+
kept.push(run);
|
|
53
|
+
}
|
|
54
|
+
return changed ? {
|
|
55
|
+
...block,
|
|
56
|
+
children: kept
|
|
57
|
+
} : block;
|
|
58
|
+
};
|
|
59
|
+
const mergeWithin = (blocks) => {
|
|
60
|
+
let changed = false;
|
|
61
|
+
const next = blocks.map((block) => {
|
|
62
|
+
let merged = mergeRuns(block);
|
|
63
|
+
if (merged.type === "Node" && merged.blocks !== void 0) {
|
|
64
|
+
const nested = mergeWithin(merged.blocks);
|
|
65
|
+
if (nested !== merged.blocks) merged = {
|
|
66
|
+
...merged,
|
|
67
|
+
blocks: nested
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (merged !== block) changed = true;
|
|
71
|
+
return merged;
|
|
72
|
+
});
|
|
73
|
+
return changed ? next : blocks;
|
|
74
|
+
};
|
|
75
|
+
const children = mergeWithin(document.children);
|
|
76
|
+
return {
|
|
77
|
+
document: children === document.children ? document : {
|
|
78
|
+
...document,
|
|
79
|
+
children
|
|
80
|
+
},
|
|
81
|
+
steps,
|
|
82
|
+
insertedNodes: /* @__PURE__ */ new Set(),
|
|
83
|
+
removedNodes,
|
|
84
|
+
dirtyNodes,
|
|
85
|
+
textChanged,
|
|
86
|
+
structureChanged: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/** The transforms every transaction runs, in order, unless a caller says otherwise. */
|
|
91
|
+
const defaultTransforms = [mergeAdjacentRuns];
|
|
92
|
+
export { defaultTransforms, mergeAdjacentRuns, unchanged };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { NodeId, type Block, type Document, type Text } from './document.js'\nimport { sameMarkSet } from './marks.js'\nimport type { CollapseStep, PositionStep, RelocateStep, SplitStep } from './transaction.js'\n\n/**\n * Transforms normalize or derive semantic structure after edits (§23). A\n * transform is a pure function of the document plus what the transaction\n * touched: it returns a whole new document and the position steps and identity\n * bookkeeping that go with it, so `apply` can fold it into the same ChangeSet\n * and position map it was already building.\n *\n * Two rules make a registry safe to run in a loop (§24): a transform must be\n * deterministic, and it must be idempotent on normalized state — so running it\n * again after it has run changes nothing, which is how the loop knows it has\n * settled.\n */\nexport interface TransformContext {\n /** Blocks the transaction touched, plus whatever earlier transforms touched. */\n readonly dirtyNodes: ReadonlySet<NodeId>\n /** Runs already spent, so a transform can bail out rather than spin. */\n readonly pass: number\n}\n\nexport interface TransformReport {\n readonly document: Document\n /** The same step vocabulary a transaction uses, so `apply` can fold either. */\n readonly steps: ReadonlyArray<PositionStep | SplitStep | RelocateStep | CollapseStep>\n readonly insertedNodes: ReadonlySet<NodeId>\n readonly removedNodes: ReadonlySet<NodeId>\n readonly dirtyNodes: ReadonlySet<NodeId>\n /** Runs whose text a transform rewrote, such as a merge's accumulator. */\n readonly textChanged: ReadonlySet<NodeId>\n /** Whether the block list changed shape, not just the runs inside a block. */\n readonly structureChanged: boolean\n}\n\nexport interface Transform {\n readonly name: string\n readonly apply: (document: Document, context: TransformContext) => TransformReport\n}\n\n/** A transform that found nothing to do. */\nexport const unchanged = (document: Document): TransformReport => ({\n document,\n steps: [],\n insertedNodes: new Set(),\n removedNodes: new Set(),\n dirtyNodes: new Set(),\n textChanged: new Set(),\n structureChanged: false,\n})\n\nconst mergeRunInto = (accumulator: Text, run: Text): Text => ({\n ...accumulator,\n text: accumulator.text + run.text,\n})\n\n/**\n * Merges adjacent runs whose mark sets match, within the blocks the transaction\n * touched, at any depth. Merging strictly reduces the run count, so one pass reaches\n * a stable state and a second pass finds nothing: the rule is idempotent, and only\n * equal mark sets merge, so an unknown mark never drops.\n */\nexport const mergeAdjacentRuns: Transform = {\n name: 'mergeAdjacentRuns',\n apply: (document, context) => {\n const steps: Array<RelocateStep> = []\n const removedNodes = new Set<NodeId>()\n const dirtyNodes = new Set<NodeId>()\n const textChanged = new Set<NodeId>()\n const mergeRuns = (block: Block): Block => {\n const first = block.children[0]\n if (!context.dirtyNodes.has(block.id) || first === undefined) return block\n let accumulator = first\n let changed = false\n const kept: Array<Text> = [accumulator]\n for (const run of block.children.slice(1)) {\n if (sameMarkSet(accumulator.marks, run.marks)) {\n steps.push({\n node: run.id,\n into: accumulator.id,\n at: 0,\n base: accumulator.text.length,\n })\n accumulator = mergeRunInto(accumulator, run)\n kept[kept.length - 1] = accumulator\n removedNodes.add(run.id)\n dirtyNodes.add(accumulator.id)\n textChanged.add(accumulator.id)\n changed = true\n } else {\n accumulator = run\n kept.push(run)\n }\n }\n return changed ? { ...block, children: kept } : block\n }\n // Returns the same array when nothing inside changed, so untouched containers keep\n // their identity and `apply` can tell that this transform found nothing.\n const mergeWithin = (blocks: ReadonlyArray<Block>): ReadonlyArray<Block> => {\n let changed = false\n const next = blocks.map(block => {\n let merged = mergeRuns(block)\n if (merged.type === 'Node' && merged.blocks !== undefined) {\n const nested = mergeWithin(merged.blocks)\n if (nested !== merged.blocks) merged = { ...merged, blocks: nested }\n }\n if (merged !== block) changed = true\n return merged\n })\n return changed ? next : blocks\n }\n const children = mergeWithin(document.children)\n return {\n document: children === document.children ? document : { ...document, children },\n steps,\n insertedNodes: new Set(),\n removedNodes,\n dirtyNodes,\n textChanged,\n structureChanged: false,\n }\n },\n}\n\n/** The transforms every transaction runs, in order, unless a caller says otherwise. */\nexport const defaultTransforms: ReadonlyArray<Transform> = [mergeAdjacentRuns]\n"],"mappings":";;;;AA0CA,MAAa,aAAa,cAAyC;CACjE;CACA,OAAO,CAAC;CACR,+BAAe,IAAI,IAAI;CACvB,8BAAc,IAAI,IAAI;CACtB,4BAAY,IAAI,IAAI;CACpB,6BAAa,IAAI,IAAI;CACrB,kBAAkB;AACpB;AAEA,MAAM,gBAAgB,aAAmB,SAAqB;CAC5D,GAAG;CACH,MAAM,YAAY,OAAO,IAAI;AAC/B;;;;;;;AAQA,MAAa,oBAA+B;CAC1C,MAAM;CACN,QAAQ,UAAU,YAAY;EAC5B,MAAM,QAA6B,CAAC;EACpC,MAAM,+BAAe,IAAI,IAAY;EACrC,MAAM,6BAAa,IAAI,IAAY;EACnC,MAAM,8BAAc,IAAI,IAAY;EACpC,MAAM,aAAa,UAAwB;GACzC,MAAM,QAAQ,MAAM,SA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@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The URL policy every importer shares (§70, §124 §10). A link's `href` and an image's `src`
|
|
3
|
+
* arrive from pasted HTML or Markdown, which is untrusted, and the standard rendering writes
|
|
4
|
+
* them into attributes, so each passes here before it can become a prop, and again before
|
|
5
|
+
* the standard rendering writes it.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A URL safe to carry into props, or `undefined` when it is not. Control characters are
|
|
9
|
+
* removed first, because `java\tscript:` and a leading NUL are how a scheme check is
|
|
10
|
+
* usually walked past; then a URL that names a scheme outside the allowlist is refused,
|
|
11
|
+
* and one with no scheme — a relative path, a fragment, a protocol-relative URL — is
|
|
12
|
+
* kept. The value is never interpreted, only copied, so what a policy leaves through is
|
|
13
|
+
* still the application's to trust.
|
|
14
|
+
*/
|
|
15
|
+
export declare const safeUrl: (value: string | null) => string | undefined;
|
|
16
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","names":[],"sources":["../src/url.ts"],"mappings":";;;;;;;;;;;;;;qBAkBa,UAAO"}
|
package/dist/url.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/url.ts
|
|
2
|
+
/**
|
|
3
|
+
* The URL policy every importer shares (§70, §124 §10). A link's `href` and an image's `src`
|
|
4
|
+
* arrive from pasted HTML or Markdown, which is untrusted, and the standard rendering writes
|
|
5
|
+
* them into attributes, so each passes here before it can become a prop, and again before
|
|
6
|
+
* the standard rendering writes it.
|
|
7
|
+
*/
|
|
8
|
+
/** Schemes a link or a source may carry; anything else — `javascript:`, `data:` — is refused. */
|
|
9
|
+
const SAFE_SCHEMES = /* @__PURE__ */ new Set([
|
|
10
|
+
"http",
|
|
11
|
+
"https",
|
|
12
|
+
"mailto",
|
|
13
|
+
"tel"
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* A URL safe to carry into props, or `undefined` when it is not. Control characters are
|
|
17
|
+
* removed first, because `java\tscript:` and a leading NUL are how a scheme check is
|
|
18
|
+
* usually walked past; then a URL that names a scheme outside the allowlist is refused,
|
|
19
|
+
* and one with no scheme — a relative path, a fragment, a protocol-relative URL — is
|
|
20
|
+
* kept. The value is never interpreted, only copied, so what a policy leaves through is
|
|
21
|
+
* still the application's to trust.
|
|
22
|
+
*/
|
|
23
|
+
const safeUrl = (value) => {
|
|
24
|
+
if (value === null) return void 0;
|
|
25
|
+
const cleaned = value.replace(/[\u0000-\u001F\u007F]/g, "").trim();
|
|
26
|
+
if (cleaned.length === 0) return void 0;
|
|
27
|
+
const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(cleaned)?.[1]?.toLowerCase();
|
|
28
|
+
return scheme === void 0 || SAFE_SCHEMES.has(scheme) ? cleaned : void 0;
|
|
29
|
+
};
|
|
30
|
+
export { safeUrl };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=url.js.map
|
package/dist/url.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * The URL policy every importer shares (§70, §124 §10). A link's `href` and an image's `src`\n * arrive from pasted HTML or Markdown, which is untrusted, and the standard rendering writes\n * them into attributes, so each passes here before it can become a prop, and again before\n * the standard rendering writes it.\n */\n\n/** Schemes a link or a source may carry; anything else — `javascript:`, `data:` — is refused. */\nconst SAFE_SCHEMES = new Set(['http', 'https', 'mailto', 'tel'])\n\n/**\n * A URL safe to carry into props, or `undefined` when it is not. Control characters are\n * removed first, because `java\\tscript:` and a leading NUL are how a scheme check is\n * usually walked past; then a URL that names a scheme outside the allowlist is refused,\n * and one with no scheme — a relative path, a fragment, a protocol-relative URL — is\n * kept. The value is never interpreted, only copied, so what a policy leaves through is\n * still the application's to trust.\n */\nexport const safeUrl = (value: string | null): string | undefined => {\n if (value === null) return undefined\n const cleaned = value.replace(/[\\u0000-\\u001F\\u007F]/g, '').trim()\n if (cleaned.length === 0) return undefined\n const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(cleaned)?.[1]?.toLowerCase()\n return scheme === undefined || SAFE_SCHEMES.has(scheme) ? cleaned : undefined\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU;AAAK,CAAC;;;;;;;;;AAU/D,MAAa,WAAW,UAA6C;CACnE,IAAI,UAAU,MAAM,OAAO,KAAA;CAC3B,MAAM,UAAU,MAAM,QAAQ,0BAA0B,EAAE,CAAC,CAAC,KAAK;CACjE,IAAI,QAAQ,WAAW,GAAG,OAAO,KAAA;CACjC,MAAM,SAAS,8BAA8B,KAAK,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY;CAC7E,OAAO,WAAW,KAAA,KAAa,aAAa,IAAI,MAAM,IAAI,UAAU,KAAA;AACtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-richtext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Pure semantic documents and editing transactions for Foldkit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"foldkit-plus:source": "./src/index.ts",
|
|
32
|
-
"types": "./dist/index.d.
|
|
33
|
-
"import": "./dist/index.
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"LICENSE"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"foldkit-media": "0.
|
|
42
|
+
"foldkit-media": "0.5.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"effect": "^4.
|
|
45
|
+
"effect": "^4.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"effect": "^4.
|
|
48
|
+
"effect": "^4.1.1",
|
|
49
49
|
"tsdown": "^0.23.1",
|
|
50
50
|
"typescript": "7.0.2"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "tsdown",
|
|
53
|
+
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|
|
54
54
|
"typecheck": "tsc -b"
|
|
55
55
|
}
|
|
56
56
|
}
|