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":"command.js","names":["markName"],"sources":["../src/command.ts"],"sourcesContent":["import { Equal, Match, Schema } from 'effect'\nimport {\n NodeId,\n blockAtPath,\n compareRunPlaces,\n eachBlock,\n positionInBlock,\n locateBlock,\n rangeStart,\n locateRun,\n pathKey,\n textContent,\n type Block,\n type BlockPath,\n type Document,\n type EditorState,\n type MarkValue,\n type Position,\n type RunMark,\n type Selection,\n type Text as Run,\n} from './document.js'\nimport { withFreshIds, type Slice } from './clipboard.js'\nimport { toText } from './html.js'\nimport {\n markName,\n edgeMarks,\n resolveInsertion,\n propsFailure,\n sameMark,\n shippedRegistry,\n type MarkRegistry,\n} from './marks.js'\nimport { blockKind, standsWithin, type NodeRegistry } from './kit.js'\nimport { indent, indentationAt, offsetIn, outdent } from './indent.js'\nimport { findMatches, type SearchMatch } from './search.js'\nimport {\n FootnoteDefinition,\n FootnoteRef,\n footnotesOf,\n nextFootnoteLabel,\n referenceLabel,\n} from './footnote.js'\nimport {\n deleteColumn,\n deleteRow,\n insertColumn,\n insertRow,\n moveToCell,\n tableAt,\n type TableEdit,\n} from './table.js'\nimport {\n Edit,\n apply,\n type ChangeSet,\n type Operation,\n type TextBlock,\n type TransactionResult,\n} from './transaction.js'\n\n/**\n * Editor intent: what the user is trying to do. Commands resolve against the\n * current document and selection into a Transaction of low-level operations, so\n * durable history keeps its meaning (§19). Identities a command needs come from\n * the caller's `mint`; nothing here reads a clock or a hidden counter.\n */\nexport type Command =\n | {\n readonly type: 'InsertText'\n readonly text: string\n /** Stored marks: a bare name, or a value when the mark carries props. */\n readonly marks?: ReadonlyArray<string | MarkValue>\n }\n | { readonly type: 'DeleteBackward' }\n | { readonly type: 'DeleteForward' }\n | { readonly type: 'SplitBlock' }\n | { readonly type: 'ToggleMark'; readonly mark: string | MarkValue }\n /**\n * Puts exactly this mark on every run the selection covers, replacing a same-named mark\n * whose props differ: how a link gets a new `href`. A caret acts on the extent of the\n * mark around it (`markExtent`), and does nothing outside one.\n */\n | { readonly type: 'SetMark'; readonly mark: string | MarkValue }\n /**\n * Takes the named mark off every run the selection covers; a caret, off its extent. Given a\n * mark value, only off the runs carrying exactly that value: one discussion's highlight,\n * leaving another's inside it.\n */\n | { readonly type: 'ClearMark'; readonly mark: string | MarkValue }\n | { readonly type: 'SetSelection'; readonly selection: Selection | null }\n | { readonly type: 'Paste'; readonly slice: Slice }\n /** Retypes the block the selection starts in: a paragraph, or a heading. */\n | { readonly type: 'RetypeBlock'; readonly to: TextBlock }\n /**\n * Wraps the block the selection starts in, in new containers listed outermost first: a\n * `Quote`, or a `List` holding a `ListItem`. The block keeps its identity and its runs,\n * so the caret stays where it was. Given a vocabulary, a list wrap right after a list of the\n * same kind and props adds the block to it as a new item.\n */\n | { readonly type: 'WrapBlock'; readonly containers: ReadonlyArray<Container> }\n /**\n * Retypes the text block the selection starts in to a node kind that holds text, such as a\n * `CodeBlock`. The block and its runs keep their identities, text, and marks.\n */\n | { readonly type: 'ConvertBlock'; readonly to: Container }\n /**\n * Retypes the container the selection starts in (the node block holding its block, such as\n * a list item) to another node kind, where it stands: its identity and every block it holds\n * are kept, so edits made inside it meanwhile survive. Only from the container's first block,\n * which is where a marker for the container is typed. Given a vocabulary, the new kind must\n * hold blocks, hold each block the container holds, and stand where the container does.\n */\n | { readonly type: 'RetypeContainer'; readonly to: Container }\n /**\n * Lifts the block the selection starts in out of its container, the inverse of a wrap:\n * repeated while the new parent's declaration refuses it, so a list item's paragraph leaves\n * both the item and the list. The block keeps its identity, and the caret with it.\n */\n | { readonly type: 'LiftBlock' }\n /**\n * Moves a block, and everything it holds, before or after another block, in its own container\n * or another one the vocabulary lets it stand in (§149). It addresses blocks rather than the\n * selection, so a handle or a key can move the block it stands for; identities are kept, and\n * the selection with them. A container the move leaves empty is deleted.\n */\n | { readonly type: 'MoveBlock'; readonly node: NodeId; readonly to: Beside }\n /**\n * Sets the named props of a node block, such as a task item's `checked`, keeping the rest.\n * It addresses the block by identity, as `MoveBlock` does, so a checkbox sends it for its\n * own item. Given a vocabulary, props that decode as the kind's must still decode after.\n */\n | { readonly type: 'SetProps'; readonly node: NodeId; readonly props: Schema.JsonObject }\n /**\n * Inserts a block, and everything it holds, before or after another block, under fresh\n * identities from `mint`: an image chosen from a file, a table from a menu, a copy of a block\n * for its handle's Duplicate. The caret goes to the start of its first text, when it has any.\n * Without `to` it goes beside the caret's block: before it when that block is empty, so a\n * slash command typed on a blank line puts its block there and the line stays to type on,\n * and after it otherwise.\n */\n | { readonly type: 'InsertBlock'; readonly block: Block; readonly to?: Beside | undefined }\n /**\n * Deletes a block and everything it holds, with any container that would be left empty by it,\n * as a block handle's Delete does. A caret inside it moves to the nearest text that stays; a\n * document left with no block gets an empty paragraph, so there is somewhere to type.\n */\n | { readonly type: 'DeleteBlock'; readonly node: NodeId }\n /**\n * A row above or below the caret's table cell, as wide as the table's widest row, with the caret\n * moved into it. The table is the standard vocabulary's (`Table`, `TableRow`, `TableCell`).\n */\n | { readonly type: 'InsertRow'; readonly where: 'before' | 'after' }\n /** A cell beside the caret's in every row, before or after it: a column. */\n | { readonly type: 'InsertColumn'; readonly where: 'before' | 'after' }\n /** The caret's row, deleted; the last one deletes the table. */\n | { readonly type: 'DeleteRow' }\n /** The caret's column, deleted from every row that has it; the last one deletes the table. */\n | { readonly type: 'DeleteColumn' }\n /**\n * Tab. In a kind declared `indents` (code), a level of indentation at the caret, or at the\n * start of every line a range covers; in a table cell, the caret to the next cell, adding a row\n * after the last. Refused anywhere else (`InvalidSelection`), so Tab can move focus there.\n */\n | { readonly type: 'Indent' }\n /** Shift+Tab: a level of indentation off each line in code; the previous cell in a table. */\n | { readonly type: 'Outdent' }\n /**\n * Find and replace: the match at index `at` of `query` (in document order, as `findMatches`\n * lists them), or every match when `at` is absent, becomes `replacement`, as one transaction.\n * Case does not count unless `caseSensitive`. The caret ends after the earliest replacement.\n */\n | {\n readonly type: 'Replace'\n readonly query: string\n readonly replacement: string\n readonly caseSensitive?: boolean | undefined\n readonly at?: number | undefined\n }\n /**\n * A footnote at the caret, or at the end of a range: a reference showing the next free label\n * (`nextFootnoteLabel`), and its definition after the last top-level block holding `text`, with\n * the caret at the definition's start, ready to write the note.\n */\n | { readonly type: 'InsertFootnote'; readonly text?: string | undefined }\n /**\n * A footnote's label, `from`, becomes `to`: on its definition, and on every reference, whose\n * text becomes `to` where it showed `from`. Refused (`InvalidInput`) when `to` is blank or\n * another footnote's, or when no footnote is labelled `from`.\n */\n | { readonly type: 'RenameFootnote'; readonly from: string; readonly to: string }\n\n/** Where `MoveBlock` puts a block: before or after a sibling, named by identity. */\nexport const Beside = Schema.Union([\n // Each shape refuses the other's key: `{ before, after }` would name two places.\n Schema.Struct({ before: NodeId, after: Schema.optionalKey(Schema.Never) }),\n Schema.Struct({ after: NodeId, before: Schema.optionalKey(Schema.Never) }),\n])\nexport type Beside = typeof Beside.Type\n\n/** A container a block is wrapped in: a node kind, and the props it starts with. */\nexport const Container = Schema.Struct({\n kind: Schema.NonEmptyString,\n props: Schema.optionalKey(Schema.JsonObject),\n})\nexport type Container = typeof Container.Type\n\n/** Caller-owned identity source. Live edits mint; replay applies transactions. */\nexport interface CommandIds {\n readonly mint: () => string\n}\n\n/** What a command needs beyond state and identity, such as a Kit's mark policy. */\nexport interface RunOptions {\n readonly marks?: MarkRegistry | undefined\n /** The node vocabulary, so an edit a constraint forbids is refused here (§125). */\n readonly nodes?: NodeRegistry | undefined\n}\n\n/**\n * Whether the block at a path is declared to carry no marks, in which case adding one\n * is refused at the command layer rather than reported only by `validate` (§125). A\n * preserved block is left alone: it has no declaration to read, and preserving it\n * matters more than forbidding a mark on it.\n */\nconst forbidsMarks = (\n document: Document,\n path: BlockPath,\n nodes: NodeRegistry | undefined,\n): boolean => {\n if (nodes === undefined) return false\n const block = blockAtPath(document, path)\n if (block === undefined || block.type === 'Unknown') return false\n return kindForbidsMarks(nodes, blockKind(block))\n}\n\nconst kindForbidsMarks = (nodes: NodeRegistry, kind: string): boolean => {\n const declared = nodes.definitionFor(kind)\n return declared?.kind === 'node' && declared.marks === 'none'\n}\n\n/**\n * Whether the block at a path accepts a child of this kind. A declaration without a\n * constraint accepts any block, and a vocabulary that does not declare the parent is\n * not consulted — `validate` reports an undeclared kind, and an edit should not fail\n * for a reason the caller never stated.\n */\nconst acceptsChild = (\n document: Document,\n path: BlockPath,\n kind: string,\n nodes: NodeRegistry | undefined,\n): boolean => {\n const parent = blockAtPath(document, path)\n return parent === undefined || kindAccepts(nodes, blockKind(parent), kind)\n}\n\n/** Whether a kind's declaration lets it hold another as a nested block; undeclared is open. */\nconst kindAccepts = (\n nodes: NodeRegistry | undefined,\n parentKind: string,\n childKind: string,\n): boolean => {\n if (nodes === undefined) return true\n const declared = nodes.definitionFor(parentKind)\n if (declared?.kind !== 'node' || typeof declared.children === 'string') return true\n return declared.children.of.includes(childKind)\n}\n\n/** Whether the vocabulary declares props for a new node that these do not decode as. */\nconst refusesProps = (nodes: NodeRegistry | undefined, container: Container): boolean => {\n const declared = nodes?.definitionFor(container.kind)\n return (\n declared !== undefined &&\n declared.kind !== 'block' &&\n propsFailure(declared.props, container.props ?? {})\n )\n}\n\n/** Whether the vocabulary declares `kind` as a node that holds runs, as `CodeBlock` is. */\nconst declaresText = (nodes: NodeRegistry | undefined, kind: string): boolean => {\n const declared = nodes?.definitionFor(kind)\n return declared?.kind === 'node' && declared.children === textContent\n}\n\n/**\n * Whether a block is an atom, holding neither text nor blocks, as an image is. Without a\n * vocabulary, a node with nothing in it is one.\n */\nexport const isAtom = (nodes: NodeRegistry | undefined, block: Block): boolean => {\n if (block.type !== 'Node') return false\n const declared = nodes?.definitionFor(block.kind)\n return declared === undefined\n ? block.blocks === undefined && block.children.length === 0\n : declared.kind === 'atom'\n}\n\n/** Whether the vocabulary names `itemKind` among the kinds `listKind` holds, as `List` names `ListItem`. */\nconst holdsItem = (nodes: NodeRegistry, listKind: string, itemKind: string): boolean => {\n const declared = nodes.definitionFor(listKind)\n return (\n declared?.kind === 'node' &&\n typeof declared.children !== 'string' &&\n declared.children.of.includes(itemKind)\n )\n}\n\n/**\n * Whether a kind can be a new container. Unlike an existing parent, a kind a wrap creates\n * must be declared as holding nested blocks when there is a vocabulary: wrapping in an\n * undeclared kind, or a text kind such as `CodeBlock`, would make content `validate`\n * refuses.\n */\nconst holdsBlocks = (nodes: NodeRegistry | undefined, kind: string): boolean => {\n if (nodes === undefined) return true\n const declared = nodes.definitionFor(kind)\n return declared?.kind === 'node' && declared.children !== textContent\n}\n\ntype Failure =\n | 'InvalidSelection'\n | 'MissingText'\n | 'InvalidInput'\n | 'InvalidParent'\n | 'ForbiddenMark'\n | 'UnexpectedChild'\nconst failure = (error: Failure): TransactionResult => ({ ok: false, error })\n\ninterface Located {\n readonly path: BlockPath\n readonly runIndex: number\n readonly blockId: NodeId\n readonly id: NodeId\n readonly text: string\n readonly marks: ReadonlyArray<RunMark>\n}\n\n/** Document order over a located run, by the shared place rule. */\nconst locatedOrder = (\n left: { readonly path: BlockPath; readonly runIndex: number },\n right: { readonly path: BlockPath; readonly runIndex: number },\n): number =>\n compareRunPlaces(\n { path: left.path, index: left.runIndex },\n { path: right.path, index: right.runIndex },\n )\n\nconst locate = (document: Document, node: NodeId): Located | undefined => {\n const found = locateRun(document, node)\n if (found === undefined) return undefined\n const block = blockAtPath(document, found.path)\n if (block === undefined) return undefined\n return {\n path: found.path,\n runIndex: found.index,\n blockId: block.id,\n id: found.run.id,\n text: found.run.text,\n marks: found.run.marks,\n }\n}\n\nconst isCollapsed = (selection: Extract<Selection, { readonly type: 'Range' }>): boolean =>\n selection.anchor.node === selection.focus.node &&\n selection.anchor.offset === selection.focus.offset\n\n/** Whether a selection covers text: a range that is not a caret. What a mark or a link applies to. */\nexport const coversText = (selection: Selection | null): boolean =>\n selection?.type === 'Range' && !isCollapsed(selection)\n\n/** A caret is a range whose endpoints coincide; direction is not yet meaningful. */\nconst caretAt = (position: Position): Selection => ({\n type: 'Range',\n anchor: position,\n focus: position,\n})\n\n/** Orders a range's endpoints by document order without losing direction. */\nconst ordered = (\n document: Document,\n selection: Extract<Selection, { readonly type: 'Range' }>,\n): { readonly start: Position; readonly end: Position } | undefined => {\n const anchor = locate(document, selection.anchor.node)\n const focus = locate(document, selection.focus.node)\n if (anchor === undefined || focus === undefined) return undefined\n const byPlace = locatedOrder(anchor, focus)\n const after = byPlace !== 0 ? byPlace > 0 : selection.anchor.offset > selection.focus.offset\n return after\n ? { start: selection.focus, end: selection.anchor }\n : { start: selection.anchor, end: selection.focus }\n}\n\ninterface Span {\n readonly run: Located\n readonly from: number\n readonly to: number\n}\n\n/** Runs intersecting an ordered [start, end), with the covered sub-range. */\nconst covered = (document: Document, start: Position, end: Position): ReadonlyArray<Span> => {\n const startAt = locate(document, start.node)\n const endAt = locate(document, end.node)\n if (startAt === undefined || endAt === undefined) return []\n const spans: Array<Span> = []\n // The walk is document order, so comparing each run's place against the\n // endpoints' places picks out the covered span however deep it sits.\n eachBlock(document.children, (block, path) => {\n for (const [runIndex, run] of block.children.entries()) {\n const place = { path, runIndex }\n if (locatedOrder(place, startAt) < 0 || locatedOrder(place, endAt) > 0) continue\n const from = locatedOrder(place, startAt) === 0 ? start.offset : 0\n const to = locatedOrder(place, endAt) === 0 ? end.offset : run.text.length\n if (from >= to) continue\n spans.push({\n run: {\n path,\n runIndex,\n blockId: block.id,\n id: run.id,\n text: run.text,\n marks: run.marks,\n },\n from,\n to,\n })\n }\n })\n return spans\n}\n\n/** Marks every run in the list carries; empty when there are no runs. */\nconst sharedMarks = (runs: ReadonlyArray<ReadonlyArray<RunMark>>): ReadonlySet<string> => {\n let common: Set<string> | undefined\n for (const marks of runs) {\n const names = new Set(marks.map(markName))\n if (common === undefined) {\n common = names\n continue\n }\n for (const name of common) if (!names.has(name)) common.delete(name)\n }\n return common ?? new Set()\n}\n\n/**\n * The marks every run the selection covers carries: the ones a toggle would\n * remove, which is what an \"active\" toolbar button means. A caret reports its\n * run's marks — an empty run can carry them, which is how a caret holds a format\n * — and a range is not bold when it straddles a bold run and a plain one. A node\n * selection reports what its whole subtree agrees on. A read, not a command:\n * nothing here changes anything.\n */\nexport const marksInRange = (\n document: Document,\n selection: Selection | null,\n): ReadonlySet<string> => {\n if (selection === null) return new Set()\n if (selection.type === 'Node') {\n const found = locateBlock(document, selection.node)\n if (found === undefined) return new Set()\n const runs: Array<ReadonlyArray<RunMark>> = []\n eachBlock([found.block], each => {\n for (const run of each.children) runs.push(run.marks)\n })\n return sharedMarks(runs)\n }\n const bounds = ordered(document, selection)\n if (bounds === undefined) return new Set()\n if (isCollapsed(selection)) {\n const caret = locate(document, selection.anchor.node)\n return caret === undefined ? new Set() : sharedMarks([caret.marks])\n }\n return sharedMarks(covered(document, bounds.start, bounds.end).map(span => span.run.marks))\n}\n\n/** A mark around a caret, and the range of runs it spans. */\nexport interface MarkExtent {\n readonly mark: RunMark\n readonly selection: Extract<Selection, { readonly type: 'Range' }>\n}\n\n/**\n * The named mark on the run a position is in, and the adjacent runs of its block carrying\n * the same mark with the same props: the whole link a caret sits in, which is what a link\n * editor shows and what `SetMark` and `ClearMark` act on at a caret. Undefined when that\n * run does not carry the mark. A read, like `marksInRange`.\n */\nexport const markExtent = (\n document: Document,\n position: Position,\n name: string,\n): MarkExtent | undefined => {\n const found = locateRun(document, position.node)\n const mark = found?.run.marks.find(held => markName(held) === name)\n if (found === undefined || mark === undefined) return undefined\n const runs = blockAtPath(document, found.path)!.children\n const carries = (index: number) => runs[index]?.marks.some(held => sameMark(held, mark)) === true\n let first = found.index\n while (carries(first - 1)) first--\n let last = found.index\n while (carries(last + 1)) last++\n const end = runs[last]!\n return {\n mark,\n selection: {\n type: 'Range',\n anchor: { node: runs[first]!.id, offset: 0, affinity: 'after' },\n focus: { node: end.id, offset: end.text.length, affinity: 'before' },\n },\n }\n}\n\n/**\n * The text style of the block a selection starts in, in the shape `RetypeBlock` takes, so a\n * style picker compares what it would send with what is there. Undefined for a node\n * selection, one that resolves to nothing, or a block a retype does not reach, such as a code\n * block.\n */\nexport const textBlockAt = (\n document: Document,\n selection: Selection | null,\n): TextBlock | undefined => {\n if (selection?.type !== 'Range') return undefined\n const path = startPath(document, selection)\n const block = path === undefined ? undefined : blockAtPath(document, path)\n if (block?.type === 'Paragraph') return { type: 'Paragraph' }\n if (block?.type === 'Heading') return { type: 'Heading', level: block.level }\n return undefined\n}\n\n/**\n * Why block `moving` may not move into the container at `container` (§149), or undefined when\n * it may. Within its own container it always may. Elsewhere, the container must hold its kind,\n * the kind must stand in the container's kind (a `ListItem` only in a `List`), it may not leave\n * a container declared isolating, and it may not go inside itself.\n */\nconst moveFailure = (\n document: Document,\n moving: { readonly path: BlockPath; readonly block: Block },\n container: BlockPath,\n nodes: NodeRegistry | undefined,\n): Failure | undefined => {\n if (moving.path.every((index, depth) => container[depth] === index)) return 'InvalidParent'\n const source = moving.path.slice(0, -1)\n if (pathKey(source) === pathKey(container)) return undefined\n const kind = blockKind(moving.block)\n const parent = container.length === 0 ? undefined : blockAtPath(document, container)\n if (\n !acceptsChild(document, container, kind, nodes) ||\n !standsWithin(nodes?.definitionFor(kind), parent === undefined ? undefined : blockKind(parent))\n ) {\n return 'UnexpectedChild'\n }\n for (let depth = source.length; depth > 0; depth--) {\n const holder = source.slice(0, depth)\n const inside = holder.every((index, at) => container[at] === index)\n if (!inside && isIsolating(document, holder, nodes)) return 'InvalidParent'\n }\n return undefined\n}\n\nconst isIsolating = (document: Document, path: BlockPath, nodes: NodeRegistry | undefined) => {\n const block = blockAtPath(document, path)\n const declared = block === undefined ? undefined : nodes?.definitionFor(blockKind(block))\n return declared?.kind === 'node' && declared.isolating === true\n}\n\n/**\n * The outermost container a block leaving `source` empties, walking up while each held nothing\n * else: a list whose only item's only block moved out goes with it. Never the container it lands\n * in, or one holding that. An isolating one is never reached, since a move may not leave it.\n */\nconst emptiedBy = (\n document: Document,\n source: BlockPath,\n container: BlockPath,\n): NodeId | undefined => {\n let emptied: NodeId | undefined\n for (let path = source; path.length > 0; path = path.slice(0, -1)) {\n const block = blockAtPath(document, path)\n const holdsTarget = path.every((index, depth) => container[depth] === index)\n if (block?.type !== 'Node' || (block.blocks?.length ?? 0) > 1 || holdsTarget) break\n emptied = block.id\n }\n return emptied\n}\n\n/**\n * The blocks `node` may move beside, in document order (§149): the blocks of every container it\n * may move into, which is what a drag offers. Empty when the document does not hold it.\n */\nexport const moveTargets = (\n document: Document,\n node: NodeId,\n nodes?: NodeRegistry,\n): ReadonlyArray<NodeId> => {\n const moving = locateBlock(document, node)\n if (moving === undefined) return []\n const targets: Array<NodeId> = []\n eachBlock(document.children, (block, path) => {\n if (moveFailure(document, moving, path.slice(0, -1), nodes) === undefined)\n targets.push(block.id)\n })\n return targets\n}\n\n/** Where a selection starts: its first run's block, or the block a node selection names. */\nconst startPath = (document: Document, selection: Selection | null): BlockPath | undefined => {\n if (selection === null) return undefined\n if (selection.type === 'Node') return locateBlock(document, selection.node)?.path\n const start = ordered(document, selection)?.start\n return start === undefined ? undefined : locateRun(document, start.node)?.path\n}\n\n/**\n * The blocks a selection starts in, outermost first: a caret in a list item's paragraph gives\n * the list, the item, and the paragraph. What a block handle picks from, and a breadcrumb draws.\n * Empty when the selection is null or resolves to nothing.\n */\nexport const blocksAt = (document: Document, selection: Selection | null): ReadonlyArray<Block> => {\n const path = startPath(document, selection) ?? []\n return path.map((_, depth) => blockAtPath(document, path.slice(0, depth + 1))!)\n}\n\n/** Whether `prefix` is a path to one of the blocks `path` lies inside, or `path` itself. */\nconst startsWith = (path: BlockPath, prefix: BlockPath): boolean =>\n prefix.length <= path.length && prefix.every((index, at) => path[at] === index)\n\n/** Document order of two block paths: a container comes before what it holds. */\nconst pathOrder = (left: BlockPath, right: BlockPath): number => {\n for (let at = 0; at < Math.min(left.length, right.length); at++) {\n if (left[at] !== right[at]) return left[at]! - right[at]!\n }\n return left.length - right.length\n}\n\n/** Whether two blocks can be joined into one: what `JoinNode` accepts. */\nconst joinable = (survivor: Block, removed: Block): boolean => {\n if (survivor.type === 'Unknown' || removed.type === 'Unknown') return false\n if (nestedBlocks(survivor) !== undefined || nestedBlocks(removed) !== undefined) return false\n if (survivor.type !== 'Node' && removed.type !== 'Node') return true\n return (\n survivor.type === 'Node' &&\n removed.type === 'Node' &&\n survivor.kind === removed.kind &&\n Equal.equals(survivor.props, removed.props)\n )\n}\n\nconst nestedBlocks = (block: Block): ReadonlyArray<Block> | undefined =>\n block.type === 'Node' && block.blocks !== undefined ? block.blocks : undefined\n\n/** Whether going from one block to another leaves an isolating container, as a table cell is. */\nconst crossesIsolating = (\n document: Document,\n from: BlockPath,\n to: BlockPath,\n nodes: NodeRegistry | undefined,\n): boolean =>\n [from, to].some((path, side) => {\n const other = side === 0 ? to : from\n for (let depth = 1; depth < path.length; depth++) {\n const container = path.slice(0, depth)\n if (startsWith(other, container)) continue\n const block = blockAtPath(document, container)\n const declared = block?.type === 'Node' ? nodes?.definitionFor(block.kind) : undefined\n if (declared?.kind === 'node' && declared.isolating === true) return true\n }\n return false\n })\n\n/** The innermost first or last block inside the block at `path`: itself when it holds none. */\nconst edgeLeaf = (document: Document, path: BlockPath, last: boolean): BlockPath => {\n let at = path\n for (;;) {\n const held = nestedBlocks(blockAtPath(document, at)!)\n if (held === undefined || held.length === 0) return at\n at = [...at, last ? held.length - 1 : 0]\n }\n}\n\n/** The first block after the one at `path` that holds no blocks, in document order. */\nconst nextLeaf = (document: Document, path: BlockPath): BlockPath | undefined => {\n let found: BlockPath | undefined\n eachBlock(document.children, (block, at) => {\n if (found !== undefined || pathOrder(at, path) <= 0 || startsWith(path, at)) return\n if ((nestedBlocks(block) ?? []).length === 0) found = at\n })\n return found\n}\n\n/** One result followed by another, as one: what `runAction` does for two commands. */\nconst followedBy = (first: TransactionResult, second: TransactionResult): TransactionResult =>\n !first.ok || !second.ok\n ? second.ok\n ? first\n : second\n : {\n ok: true,\n state: second.state,\n changeSet: unionChangeSet(first.changeSet, second.changeSet),\n positionMap: [...first.positionMap, ...second.positionMap],\n transactions: [...first.transactions, ...second.transactions],\n }\n\n/**\n * Deletes a range that leaves its container, as selecting from one kind of block into another\n * (or everything) and pressing Delete does: the text after `start` in its block and before\n * `end` in its block goes, every block wholly between them goes, and the block `end` is in\n * comes up beside the one `start` is in, joining it when the two can be one. A container it\n * leaves empty goes too. A range that leaves a table cell (an isolating container) only loses\n * its text: the cells stay, as a table's structure is not a selection's to remove. The caret\n * ends at `start`.\n */\nconst clearRange = (\n state: EditorState,\n start: Position,\n end: Position,\n options: RunOptions,\n): TransactionResult => {\n const document = state.document\n const startAt = locate(document, start.node)\n const endAt = locate(document, end.node)\n if (startAt === undefined || endAt === undefined) return failure('MissingText')\n const startPath = startAt.path\n const endPath = endAt.path\n const spans = covered(document, start, end)\n if (crossesIsolating(document, startPath, endPath, options.nodes)) {\n return apply(state, [\n ...spans.map(span => Edit.deleteText(span.run.id, span.from, span.to)),\n Edit.setSelection(caretAt(start)),\n ])\n }\n // The ends lose what the range covers of them; everything between them goes whole.\n const ends = spans.filter(\n span =>\n pathKey(span.run.path) === pathKey(startPath) || pathKey(span.run.path) === pathKey(endPath),\n )\n const between: Array<{ readonly id: NodeId; readonly path: BlockPath }> = []\n eachBlock(document.children, (block, path) => {\n if (pathOrder(path, startPath) <= 0 || pathOrder(path, endPath) >= 0) return\n if (startsWith(endPath, path) || startsWith(startPath, path)) return\n if (between.some(outer => startsWith(path, outer.path))) return\n between.push({ id: block.id, path })\n })\n const first = apply(state, [\n ...ends.map(span => Edit.deleteText(span.run.id, span.from, span.to)),\n ...between.map(block => Edit.deleteBlock(block.id)),\n Edit.setSelection(caretAt(start)),\n ])\n if (!first.ok) return first\n // Bring the end block beside the start one, join them if they can be one, and take away\n // the containers the move left empty.\n const startBlock = blockAtPath(document, startPath)!\n const endBlock = blockAtPath(document, endPath)!\n const now = first.state.document\n const survivorAt = locateBlock(now, startBlock.id)\n const removedAt = locateBlock(now, endBlock.id)\n if (survivorAt === undefined || removedAt === undefined) return first\n const operations: Array<Operation> = []\n const parentPath = survivorAt.path.slice(0, -1)\n const parent = parentPath.length === 0 ? undefined : blockAtPath(now, parentPath)\n const index = survivorAt.path[survivorAt.path.length - 1]!\n const siblings = pathKey(removedAt.path.slice(0, -1)) === pathKey(parentPath)\n // It comes up only where its kind may stand: a list holds items, not a paragraph.\n if (\n !siblings &&\n parentPath.length > 0 &&\n !acceptsChild(now, parentPath, blockKind(removedAt.block), options.nodes)\n ) {\n return first\n }\n if (!siblings) operations.push(Edit.moveBlock(endBlock.id, index + 1, parent?.id))\n const adjacent = siblings ? removedAt.path[removedAt.path.length - 1] === index + 1 : true\n if (adjacent && joinable(survivorAt.block, removedAt.block)) {\n operations.push(Edit.joinBlocks(startBlock.id, endBlock.id))\n }\n if (!siblings) {\n // Each container the end block was in, innermost first, goes when nothing else is left in it.\n for (let depth = removedAt.path.length - 1; depth > 0; depth--) {\n const container = blockAtPath(now, removedAt.path.slice(0, depth))\n if (container === undefined || startsWith(survivorAt.path, removedAt.path.slice(0, depth))) {\n break\n }\n // It held the end block, or the container holding it, and is empty once that goes.\n if ((nestedBlocks(container) ?? []).length > 1) break\n operations.push(Edit.deleteBlock(container.id))\n }\n }\n if (operations.length === 0) return first\n return followedBy(first, apply(first.state, [...operations, Edit.setSelection(caretAt(start))]))\n}\n\n/** The last run in a block's subtree, or undefined when it holds none. */\nconst lastRunOf = (block: Block): Run | undefined => {\n if (block.type === 'Node' && block.blocks !== undefined) {\n for (let index = block.blocks.length - 1; index >= 0; index--) {\n const found = lastRunOf(block.blocks[index]!)\n if (found !== undefined) return found\n }\n }\n return block.children[block.children.length - 1]\n}\n\n/** The block list a path lives in: the document's, or a container's nested blocks. */\nconst containerBlocks = (document: Document, containerPath: BlockPath): ReadonlyArray<Block> => {\n if (containerPath.length === 0) return document.children\n const container = blockAtPath(document, containerPath)\n return container?.type === 'Node' && container.blocks !== undefined ? container.blocks : []\n}\n\n/**\n * Deletes an ordered [start, end): one operation per covered run, then the\n * blocks the range spanned are joined, so selecting across a paragraph boundary\n * and deleting removes the boundary too. The first block survives, which is\n * where the caret already is. Returns undefined when the range needs a join this\n * version cannot express — one across containers, which has no boundary to\n * remove — so the caller refuses rather than deleting half of what was selected.\n */\nconst deleteRange = (\n document: Document,\n start: Position,\n end: Position,\n): ReadonlyArray<Operation> | undefined => {\n const startAt = locate(document, start.node)\n const endAt = locate(document, end.node)\n const deletions: Array<Operation> = covered(document, start, end).map(span =>\n Edit.deleteText(span.run.id, span.from, span.to),\n )\n if (startAt === undefined || endAt === undefined) return deletions\n // Within one block there is no boundary to remove.\n if (pathKey(startAt.path) === pathKey(endAt.path)) return deletions\n const containerPath = startAt.path.slice(0, -1)\n // The boundary only exists between siblings; a range that leaves its container\n // needs a merge this version does not define.\n if (pathKey(containerPath) !== pathKey(endAt.path.slice(0, -1))) return undefined\n const blocks = containerBlocks(document, containerPath)\n const from = startAt.path[startAt.path.length - 1]!\n const to = endAt.path[endAt.path.length - 1]!\n const survivor = blocks[from]!\n for (let index = from + 1; index <= to; index++) {\n const block = blocks[index]\n if (block === undefined) continue\n // A block between that cannot be one with the first (an image, a table, a list) is for\n // `clearRange`, which removes it rather than joining it.\n if (!joinable(survivor, block)) return undefined\n deletions.push(Edit.joinBlocks(survivor.id, block.id))\n }\n return deletions\n}\n\nconst segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n\n/** A caret uses UTF-16 offsets, while a deletion removes a whole grapheme. */\nconst graphemeDeletion = (\n block: Block,\n caret: Position,\n runIndex: number,\n backward: boolean,\n): { operations: ReadonlyArray<Operation>; caret: Position } | undefined => {\n const starts: Array<number> = []\n let length = 0\n for (const run of block.children) {\n starts.push(length)\n length += run.text.length\n }\n const at = starts[runIndex]! + caret.offset\n if (backward ? at === 0 : at === length) return undefined\n const text = block.children.map(run => run.text).join('')\n let from = 0\n let to = 0\n for (const segment of segmenter.segment(text)) {\n const end = segment.index + segment.segment.length\n if (backward ? end >= at : end > at) {\n from = segment.index\n to = end\n break\n }\n }\n const operations: Array<Operation> = []\n let graphemeStart: Position | undefined\n for (const [index, run] of block.children.entries()) {\n const start = starts[index]!\n const localFrom = Math.max(0, from - start)\n const localTo = Math.min(run.text.length, to - start)\n if (localFrom >= localTo) continue\n graphemeStart ??= { node: run.id, offset: localFrom, affinity: 'after' }\n operations.push(Edit.deleteText(run.id, localFrom, localTo))\n }\n if (graphemeStart === undefined) return undefined\n // A backward deletion removes what is to the caret's left, so the caret lands\n // where the grapheme began; a forward one removes to its right, and the caret\n // already sits at the surviving boundary.\n return { operations, caret: backward ? graphemeStart : caret }\n}\n\n/**\n * The operations that lift a block out of its container, or `undefined` when it is at the\n * top level with nothing to leave. One step moves it into the container's parent: before\n * the container when it was first, after it when it was last, and between the two halves\n * of a split container when it was in the middle. A container it leaves empty is deleted.\n * Steps repeat while the vocabulary says the new parent does not hold the block's kind;\n * without a vocabulary, one step is taken. A container the vocabulary declares isolating is\n * never left, so a lift that would start by leaving one lifts nothing.\n *\n * Each step is computed against the document the steps before it produced, applied with no\n * normalization, because a split or a deletion moves the indices the next step reads.\n */\nconst liftOperations = (\n document: Document,\n node: NodeId,\n ids: CommandIds,\n nodes: NodeRegistry | undefined,\n): ReadonlyArray<Operation> | undefined => {\n const operations: Array<Operation> = []\n let current = document\n for (;;) {\n const found = locateBlock(current, node)\n if (found === undefined || found.path.length === 1) break\n const containerPath = found.path.slice(0, -1)\n const container = blockAtPath(current, containerPath)\n if (container?.type !== 'Node' || container.blocks === undefined) break\n const declared = nodes?.definitionFor(container.kind)\n if (declared?.kind === 'node' && declared.isolating === true) break\n const parentPath = containerPath.slice(0, -1)\n const parent = parentPath.length === 0 ? undefined : blockAtPath(current, parentPath)\n const at = containerPath[containerPath.length - 1]!\n const index = found.path[found.path.length - 1]!\n const siblings = container.blocks\n const step: Array<Operation> = []\n if (index === 0) {\n step.push(Edit.moveBlock(node, at, parent?.id))\n if (siblings.length === 1) step.push(Edit.deleteBlock(container.id))\n } else if (index === siblings.length - 1) {\n step.push(Edit.moveBlock(node, at + 1, parent?.id))\n } else {\n // The blocks after it go into a second container of the same kind, so the list or\n // quote continues on the far side of the lifted block.\n const rest = NodeId.make(ids.mint())\n step.push(\n Edit.insertBlock({ ...container, id: rest, children: [], blocks: [] }, at + 1, parent?.id),\n ...siblings\n .slice(index + 1)\n .map((sibling, offset) => Edit.moveBlock(sibling.id, offset, rest)),\n Edit.moveBlock(node, at + 1, parent?.id),\n )\n }\n const stepped = apply({ document: current, selection: null }, step, [])\n // Each step is built from the document it applies to, so a refusal is a bug here.\n if (!stepped.ok) throw new Error(`liftOperations: a lift step was refused (${stepped.error})`)\n operations.push(...step)\n current = stepped.state.document\n if (parent === undefined || kindAccepts(nodes, blockKind(parent), blockKind(found.block))) break\n }\n return operations.length === 0 ? undefined : operations\n}\n\n/** A list item around a block: its container, where that stands, and the list holding it. */\ninterface ItemAround {\n readonly container: Extract<Block, { readonly type: 'Node' }>\n readonly containerPath: BlockPath\n readonly list: Block\n}\n\n/**\n * The item a block sits in, when the vocabulary says its container is one: a kind its own\n * parent declares it holds, as a `List` declares `ListItem`, and not isolating, as a table\n * cell is. Enter treats such a container as the unit it splits.\n */\nconst itemAround = (\n document: Document,\n path: BlockPath,\n nodes: NodeRegistry | undefined,\n): ItemAround | undefined => {\n if (nodes === undefined) return undefined\n const containerPath = path.slice(0, -1)\n const container = blockAtPath(document, containerPath)\n const list = blockAtPath(document, containerPath.slice(0, -1))\n if (container?.type !== 'Node' || list?.type !== 'Node') return undefined\n const declaredItem = nodes.definitionFor(container.kind)\n const isolating = declaredItem?.kind === 'node' && declaredItem.isolating === true\n return holdsItem(nodes, list.kind, container.kind) && !isolating\n ? { container, containerPath, list }\n : undefined\n}\n\n/**\n * Whether Enter in the block at `path`, over to `end`, leaves no heading text after the caret,\n * so the new block is a paragraph: what follows a title is text. Mid-heading, both halves stay\n * the heading they were. Over a range, what follows is what the removal leaves: the heading's\n * own rest when the range ends inside it, or the next block's text, which was never the\n * heading's, when it ends there.\n */\nconst endsHeading = (document: Document, path: BlockPath, end: Position): boolean => {\n const block = blockAtPath(document, path)\n const endAt = locate(document, end.node)\n return (\n block?.type === 'Heading' &&\n endAt !== undefined &&\n (pathKey(endAt.path) !== pathKey(path) ||\n (end.offset >= endAt.text.length &&\n block.children.slice(endAt.runIndex + 1).every(run => run.text.length === 0)))\n )\n}\n\n/**\n * Enter inside a list item. An empty block that is the item's whole content leaves the list,\n * as Backspace does. Otherwise the block splits and the second half, with every block after\n * it in the item, becomes a new item of the same kind and props right after this one.\n */\nconst splitItem = (\n state: EditorState,\n at: Located,\n offset: number,\n { container, containerPath, list }: ItemAround,\n ids: CommandIds,\n nodes: NodeRegistry | undefined,\n): TransactionResult => {\n const blocks = container.blocks ?? []\n const index = at.path[at.path.length - 1]!\n const empty = blockAtPath(state.document, at.path)?.children.every(run => run.text === '')\n if (empty === true && blocks.length === 1) {\n return apply(state, liftOperations(state.document, at.blockId, ids, nodes) ?? [])\n }\n const textId = ids.mint()\n const blockId = ids.mint()\n const itemId = NodeId.make(ids.mint())\n const declared = nodes?.definitionFor(container.kind)\n const props = { ...container.props, ...(declared?.kind === 'node' ? declared.splitProps : {}) }\n // The declaration's props are laid over the item's, so together they must still decode.\n if (declared?.kind === 'node' && propsFailure(declared.props, props))\n return failure('InvalidInput')\n return apply(state, [\n Edit.splitBlock(at.blockId, at.id, offset, blockId, textId),\n ...(endsHeading(state.document, at.path, { node: at.id, offset, affinity: 'after' })\n ? [Edit.retypeBlock(NodeId.make(blockId), { type: 'Paragraph' })]\n : []),\n Edit.insertBlock(\n { ...container, id: itemId, props, children: [], blocks: [] },\n containerPath[containerPath.length - 1]! + 1,\n list.id,\n ),\n Edit.moveBlock(NodeId.make(blockId), 0, itemId),\n ...blocks\n .slice(index + 1)\n .map((later, position) => Edit.moveBlock(later.id, position + 1, itemId)),\n Edit.setSelection(caretAt({ node: NodeId.make(textId), offset: 0, affinity: 'after' })),\n ])\n}\n\n/** The block a block-level command acts on, and where it stands. */\ninterface StartingBlock {\n readonly block: Block\n readonly path: BlockPath\n readonly parentPath: BlockPath\n /** The containing block, or none at the document's top level. */\n readonly parent: Block | undefined\n /** The selection it was found from, which a command that renames runs has to move. */\n readonly selection: Extract<Selection, { readonly type: 'Range' }>\n}\n\n/**\n * A block-level intent acts on the block the selection starts in: the caret's own block,\n * or the first block of a range. Acting on every block a range covers would be a surprise,\n * and a menu or a marker is typed at a caret anyway.\n */\nconst startingBlock = (\n document: Document,\n selection: Extract<Selection, { readonly type: 'Range' }>,\n): StartingBlock | { readonly error: Failure } => {\n const start = isCollapsed(selection) ? selection.anchor : ordered(document, selection)?.start\n if (start === undefined) return { error: 'InvalidSelection' }\n const at = locate(document, start.node)\n const block = at === undefined ? undefined : blockAtPath(document, at.path)\n if (at === undefined || block === undefined) return { error: 'MissingText' }\n const parentPath = at.path.slice(0, -1)\n return {\n block,\n path: at.path,\n parentPath,\n parent: parentPath.length === 0 ? undefined : blockAtPath(document, parentPath),\n selection,\n }\n}\n\n/**\n * Retype, wrap, convert, retype a container, and lift: each reshapes the starting block, or\n * the container holding it, where it stands.\n */\nconst runBlockCommand = (\n state: EditorState,\n command: Extract<\n Command,\n {\n readonly type: 'RetypeBlock' | 'WrapBlock' | 'ConvertBlock' | 'RetypeContainer' | 'LiftBlock'\n }\n >,\n starting: StartingBlock,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n const { block, path, parentPath, parent } = starting\n const index = path[path.length - 1]!\n if (command.type === 'LiftBlock') {\n const lifted = liftOperations(state.document, block.id, ids, options.nodes)\n return lifted === undefined ? failure('InvalidInput') : apply(state, lifted)\n }\n if (command.type === 'RetypeContainer') {\n if (parent?.type !== 'Node' || parent.blocks === undefined || index !== 0) {\n return failure('InvalidInput')\n }\n const { kind } = command.to\n if (refusesProps(options.nodes, command.to)) return failure('InvalidInput')\n const outerPath = parentPath.slice(0, -1)\n const outer = outerPath.length === 0 ? undefined : blockAtPath(state.document, outerPath)\n const declared = options.nodes?.definitionFor(kind)\n const allowed =\n holdsBlocks(options.nodes, kind) &&\n acceptsChild(state.document, outerPath, kind, options.nodes) &&\n standsWithin(declared, outer === undefined ? undefined : blockKind(outer)) &&\n parent.blocks.every(\n child =>\n kindAccepts(options.nodes, kind, blockKind(child)) &&\n standsWithin(options.nodes?.definitionFor(blockKind(child)), kind),\n )\n if (!allowed) return failure('UnexpectedChild')\n return apply(state, [\n Edit.retypeBlock(parent.id, { type: 'Node', kind, props: command.to.props ?? {} }),\n ])\n }\n if (command.type === 'RetypeBlock') {\n // A retype keeps the block where it is, so the parent's constraint decides whether\n // the new kind belongs there.\n if (!acceptsChild(state.document, parentPath, command.to.type, options.nodes)) {\n return failure('UnexpectedChild')\n }\n // Leaving a node kind that holds text — a code block back to a paragraph — keeps the\n // block and its runs, as entering one does. Only a vocabulary says a kind holds text:\n // without one, a node could be an image, whose content a retype would destroy.\n if (\n block.type !== 'Paragraph' &&\n block.type !== 'Heading' &&\n (block.type !== 'Node' || !declaresText(options.nodes, block.kind))\n ) {\n return failure('InvalidInput')\n }\n return apply(state, [Edit.retypeBlock(block.id, command.to)])\n }\n\n if (command.type === 'WrapBlock') {\n const [outer] = command.containers\n if (outer === undefined) return failure('InvalidInput')\n if (command.containers.some(container => refusesProps(options.nodes, container))) {\n return failure('InvalidInput')\n }\n const kinds = [...command.containers.map(container => container.kind), blockKind(block)]\n const parentKind = parent === undefined ? undefined : blockKind(parent)\n // Both sides of every link in the chain: what each container holds, and where each kind,\n // the wrapped block's included, may stand (§149).\n const allowed =\n acceptsChild(state.document, parentPath, outer.kind, options.nodes) &&\n command.containers.every(\n (container, at) =>\n holdsBlocks(options.nodes, container.kind) &&\n kindAccepts(options.nodes, container.kind, kinds[at + 1]!),\n ) &&\n kinds.every((kind, at) =>\n standsWithin(options.nodes?.definitionFor(kind), at === 0 ? parentKind : kinds[at - 1]),\n )\n if (!allowed) return failure('UnexpectedChild')\n // A list wrap right after a list of the same kind and props adds an item to it, as\n // Markdown reads the two; a second list beside the first would print as one.\n const siblings =\n parent === undefined\n ? state.document.children\n : parent.type === 'Node'\n ? (parent.blocks ?? [])\n : []\n const before = siblings[index - 1]\n const item = command.containers[1]\n const joins =\n options.nodes !== undefined &&\n item !== undefined &&\n holdsItem(options.nodes, outer.kind, item.kind) &&\n before?.type === 'Node' &&\n before.kind === outer.kind &&\n Equal.equals(before.props, outer.props ?? {})\n const created = joins ? command.containers.slice(1) : command.containers\n const containerIds = created.map(() => NodeId.make(ids.mint()))\n // Built from the inside out, so each container holds the next and the innermost is\n // empty until the block moves into it.\n const chain = created.reduceRight<Block | undefined>(\n (inner, container, at) => ({\n type: 'Node',\n kind: container.kind,\n id: containerIds[at]!,\n props: container.props ?? {},\n children: [],\n blocks: inner === undefined ? [] : [inner],\n }),\n undefined,\n )!\n return apply(state, [\n joins\n ? Edit.insertBlock(chain, before.blocks?.length ?? 0, before.id)\n : Edit.insertBlock(chain, index, parent?.id),\n Edit.moveBlock(block.id, 0, containerIds[containerIds.length - 1]!),\n ])\n }\n\n // A node kind's content is its Kit's contract, so only a paragraph or heading converts.\n if (block.type !== 'Paragraph' && block.type !== 'Heading') return failure('InvalidInput')\n const kind = command.to.kind\n if (refusesProps(options.nodes, command.to)) return failure('InvalidInput')\n const holdsText = options.nodes === undefined || declaresText(options.nodes, kind)\n if (!holdsText || !acceptsChild(state.document, parentPath, kind, options.nodes)) {\n return failure('UnexpectedChild')\n }\n if (\n options.nodes !== undefined &&\n kindForbidsMarks(options.nodes, kind) &&\n block.children.some(run => run.marks.length > 0)\n ) {\n return failure('ForbiddenMark')\n }\n return apply(state, [\n Edit.retypeBlock(block.id, { type: 'Node', kind, props: command.to.props ?? {} }),\n ])\n}\n\n/**\n * Resolves one intent into a transaction and applies it atomically. Commands\n * describe intent; the returned `positionMap` and `ChangeSet` describe the\n * document effect, and rejection returns no partially edited state.\n */\nexport const run = (\n state: EditorState,\n command: Command,\n ids: CommandIds,\n options: RunOptions = {},\n): TransactionResult => {\n // The vocabulary an edit may add: the caller's Kit, or the shipped marks.\n const declared = options.marks ?? shippedRegistry\n // A range that leaves its container (a selection over several kinds of block, or all of\n // them) is cleared first, and what replaces it then acts on the caret that is left.\n const range = state.selection\n if (\n (command.type === 'InsertText' ||\n command.type === 'DeleteBackward' ||\n command.type === 'DeleteForward' ||\n command.type === 'SplitBlock' ||\n command.type === 'Paste') &&\n range?.type === 'Range' &&\n !isCollapsed(range)\n ) {\n const span = ordered(state.document, range)\n if (span !== undefined && deleteRange(state.document, span.start, span.end) === undefined) {\n const cleared = clearRange(state, span.start, span.end, options)\n if (!cleared.ok || command.type === 'DeleteBackward' || command.type === 'DeleteForward') {\n return cleared\n }\n return followedBy(cleared, run(cleared.state, command, ids, options))\n }\n }\n if (command.type === 'SetSelection') {\n return apply(state, [Edit.setSelection(command.selection)])\n }\n if (command.type === 'SetProps') {\n const target = locateBlock(state.document, command.node)?.block\n if (target?.type !== 'Node') return failure('InvalidInput')\n // Refused only when it makes valid props invalid: props already outside the kind's\n // schema (a key from an older version, say) cannot be deleted, so refusing every change\n // to them would leave the block uneditable.\n const refuses = (props: Schema.JsonObject) =>\n refusesProps(options.nodes, { kind: target.kind, props })\n if (refuses({ ...target.props, ...command.props }) && !refuses(target.props)) {\n return failure('InvalidInput')\n }\n return apply(state, [Edit.setProps(command.node, command.props)])\n }\n if (\n command.type === 'InsertRow' ||\n command.type === 'InsertColumn' ||\n command.type === 'DeleteRow' ||\n command.type === 'DeleteColumn'\n ) {\n const at = tableAt(state.document, state.selection)\n if (at === undefined) return failure('InvalidSelection')\n const edited: TableEdit = Match.value(command).pipe(\n Match.discriminatorsExhaustive('type')({\n InsertRow: ({ where }) => insertRow(state, at, where, ids.mint),\n InsertColumn: ({ where }) => insertColumn(state, at, where, ids.mint),\n DeleteRow: () => deleteRow(state, at),\n DeleteColumn: () => deleteColumn(state, at),\n }),\n )\n // The last row or column takes the table with it, as a handle's Delete would.\n return 'deleteTable' in edited\n ? run(state, { type: 'DeleteBlock', node: edited.deleteTable }, ids, options)\n : edited\n }\n if (command.type === 'Indent' || command.type === 'Outdent') {\n // Code inside a table cell indents: the innermost meaning of Tab wins.\n const code = linesHolder(state, options.nodes)\n if (code !== undefined) {\n return command.type === 'Indent' ? indent(state, code) : outdent(state, code)\n }\n // A list item inside a table cell nests; a table inside a list item moves between cells.\n const item = itemAtCaret(state, options.nodes)\n const at = tableAt(state.document, state.selection)\n const tableDepth =\n at === undefined ? -1 : (locateBlock(state.document, at.table.id)?.path.length ?? -1)\n if (item !== undefined && item.containerPath.length > tableDepth) {\n return command.type === 'Indent'\n ? sinkItem(state, item, ids, options)\n : liftItem(state, item, ids, options)\n }\n if (at === undefined) return failure('InvalidSelection')\n return moveToCell(state, at, command.type === 'Indent' ? 'next' : 'previous', ids.mint)\n }\n if (command.type === 'Replace') {\n const matches = findMatches(state.document, command.query, command)\n const chosen = command.at === undefined ? matches : matches.slice(command.at, command.at + 1)\n return replaceMatches(state, chosen, command.replacement, ids, options)\n }\n if (command.type === 'InsertFootnote')\n return insertFootnote(state, command.text ?? '', ids, options)\n if (command.type === 'RenameFootnote') {\n return renameFootnote(state, command.from, command.to.trim(), ids, options)\n }\n if (command.type === 'InsertBlock') {\n const to = command.to ?? besideCaret(state)\n if (to === undefined) return failure('InvalidSelection')\n const beside = locateBlock(state.document, 'before' in to ? to.before : to.after)\n if (beside === undefined) return failure('InvalidInput')\n const containerPath = beside.path.slice(0, -1)\n const holder =\n containerPath.length === 0 ? undefined : blockAtPath(state.document, containerPath)\n const kind = blockKind(command.block)\n if (\n (holder !== undefined && !acceptsChild(state.document, containerPath, kind, options.nodes)) ||\n !standsWithin(\n options.nodes?.definitionFor(kind),\n holder === undefined ? undefined : blockKind(holder),\n )\n ) {\n return failure('UnexpectedChild')\n }\n const [inserted] = withFreshIds({ version: 1, blocks: [command.block] }, ids.mint).blocks\n const at = beside.path[beside.path.length - 1]! + ('after' in to ? 1 : 0)\n const first = firstRunIn([inserted!])\n return apply(state, [\n Edit.insertBlock(inserted!, at, holder?.id),\n ...(first === undefined\n ? []\n : [Edit.setSelection(caretAt({ node: first.id, offset: 0, affinity: 'after' }))]),\n ])\n }\n if (command.type === 'DeleteBlock') {\n const deleting = locateBlock(state.document, command.node)\n if (deleting === undefined) return failure('InvalidInput')\n // Never a path, so no container counts as holding where the block goes.\n const target = emptiedBy(state.document, deleting.path.slice(0, -1), [-1]) ?? command.node\n const gone = locateBlock(state.document, target)!\n const inside = (path: BlockPath) => gone.path.every((index, depth) => path[depth] === index)\n const runs: Array<{ readonly run: Run; readonly inside: boolean; readonly after: boolean }> = []\n eachBlock(state.document.children, (block, path) => {\n for (const run of block.children) {\n runs.push({ run, inside: inside(path), after: pathOrder(path, gone.path) > 0 })\n }\n })\n const selection = state.selection\n const holds =\n selection !== null &&\n (selection.type === 'Node'\n ? locateBlock(state.document, selection.node) !== undefined &&\n inside(locateBlock(state.document, selection.node)!.path)\n : [selection.anchor, selection.focus].some(end =>\n runs.some(entry => entry.inside && entry.run.id === end.node),\n ))\n // By place, not by the runs the block held: an atom holds none.\n const following = runs.find(entry => entry.after && !entry.inside)\n const preceding = [...runs].reverse().find(entry => !entry.after && !entry.inside)\n const landing =\n following !== undefined\n ? { node: following.run.id, offset: 0, affinity: 'after' as const }\n : preceding !== undefined\n ? {\n node: preceding.run.id,\n offset: preceding.run.text.length,\n affinity: 'after' as const,\n }\n : undefined\n const emptiesDocument = gone.path.length === 1 && state.document.children.length === 1\n if (emptiesDocument) {\n const textId = NodeId.make(ids.mint())\n const paragraph: Block = {\n type: 'Paragraph',\n id: NodeId.make(ids.mint()),\n children: [{ type: 'Text', id: textId, text: '', marks: [] }],\n }\n return apply(state, [\n Edit.insertBlock(paragraph, 1),\n Edit.deleteBlock(target),\n Edit.setSelection(caretAt({ node: textId, offset: 0, affinity: 'after' })),\n ])\n }\n return apply(state, [\n Edit.deleteBlock(target),\n ...(holds ? [Edit.setSelection(landing === undefined ? null : caretAt(landing))] : []),\n ])\n }\n if (command.type === 'MoveBlock') {\n const moving = locateBlock(state.document, command.node)\n const beside = locateBlock(\n state.document,\n 'before' in command.to ? command.to.before : command.to.after,\n )\n if (moving === undefined || beside === undefined) return failure('InvalidInput')\n const container = beside.path.slice(0, -1)\n const refused = moveFailure(state.document, moving, container, options.nodes)\n if (refused !== undefined) return failure(refused)\n const source = moving.path.slice(0, -1)\n const within = pathKey(source) === pathKey(container)\n const from = moving.path[moving.path.length - 1]!\n const place = beside.path[beside.path.length - 1]! + ('after' in command.to ? 1 : 0)\n // The operation's index is after the block leaves, which shifts every later sibling up.\n const to = within && from < place ? place - 1 : place\n const parent = container.length === 0 ? undefined : blockAtPath(state.document, container)?.id\n const emptied = emptiedBy(state.document, source, container)\n // A node selection on a container the move deletes would dangle; the block it held is what\n // it was selecting, so it goes there.\n const gone = emptied === undefined ? undefined : locateBlock(state.document, emptied)\n const selected =\n state.selection?.type === 'Node'\n ? locateBlock(state.document, state.selection.node)\n : undefined\n const inside = (path: BlockPath, holder: BlockPath) =>\n holder.every((index, depth) => path[depth] === index)\n const lost =\n gone !== undefined &&\n selected !== undefined &&\n inside(selected.path, gone.path) &&\n !inside(selected.path, moving.path)\n return apply(state, [\n Edit.moveBlock(command.node, to, parent),\n ...(emptied === undefined ? [] : [Edit.deleteBlock(emptied)]),\n ...(lost ? [Edit.setSelection({ type: 'Node', node: command.node })] : []),\n ])\n }\n const selection = state.selection\n // A selected block is deleted by Delete or Backspace, has a paragraph opened after it by\n // Enter, and is replaced by what is typed over it.\n if (selection?.type === 'Node') {\n const paragraph: Block = {\n type: 'Paragraph',\n id: NodeId.make('paragraph'),\n children: [{ type: 'Text', id: NodeId.make('text'), text: '', marks: [] }],\n }\n const after = { type: 'InsertBlock', block: paragraph, to: { after: selection.node } } as const\n if (command.type === 'DeleteBackward' || command.type === 'DeleteForward') {\n return run(state, { type: 'DeleteBlock', node: selection.node }, ids, options)\n }\n if (command.type === 'SplitBlock') return run(state, after, ids, options)\n if (command.type === 'InsertText') {\n return runAction(\n state,\n [after, { type: 'DeleteBlock', node: selection.node }, command],\n ids,\n options,\n )\n }\n }\n if (selection === null || selection.type === 'Node') return failure('InvalidSelection')\n\n if (command.type === 'InsertText') {\n // Stored marks are explicit: when the command carries them, the inserted\n // text must end up with exactly that set, whatever run it lands in. Without\n // them, the boundary rule decides (typing after bold continues bold).\n // At a block's outer edge, a mark that does not extend there is left behind: the text\n // carries the rest, as stored marks would.\n const edge =\n command.marks === undefined && isCollapsed(selection)\n ? edgeMarks(state.document, selection.anchor, options.marks)\n : undefined\n const stored = command.marks ?? edge\n const target = isCollapsed(selection)\n ? stored === undefined\n ? resolveInsertion(state.document, selection.anchor, options.marks)\n : selection.anchor\n : ordered(state.document, selection)?.start\n if (target === undefined) return failure('InvalidSelection')\n const at = locate(state.document, target.node)\n if (at === undefined) return failure('MissingText')\n const marks: Array<RunMark> = []\n if (stored !== undefined) {\n for (const mark of stored) {\n // Marks kept from the run were already there; only marks a caller names are checked.\n if (edge === undefined && !declared.accepts(mark)) return failure('InvalidInput')\n marks.push(mark)\n }\n // A mark-free kind refuses the format however it arrives, so inserting text\n // that carries marks into a CodeBlock is refused like the toggle that set them.\n if (marks.length > 0 && forbidsMarks(state.document, at.path, options.nodes)) {\n return failure('ForbiddenMark')\n }\n }\n const deletions = isCollapsed(selection)\n ? []\n : deleteRange(state.document, target, ordered(state.document, selection)!.end)\n if (deletions === undefined) return failure('InvalidParent')\n if (command.text.length === 0) {\n return apply(\n state,\n deletions.length === 0 ? [] : [...deletions, Edit.setSelection(caretAt(target))],\n )\n }\n if (stored === undefined) {\n return apply(state, [\n ...deletions,\n Edit.insertText(target, command.text),\n Edit.setSelection(\n caretAt({ ...target, offset: target.offset + command.text.length, affinity: 'after' }),\n ),\n ])\n }\n // Split the inserted span out of its run — at the end first, so the start\n // offset stays valid — then give the span exactly these marks.\n const span = isCollapsed(selection) ? undefined : ordered(state.document, selection)\n // Where the text that survives the range deletion begins in the original\n // run. A range that runs past this run takes its whole tail with it.\n const tailFrom =\n span === undefined\n ? target.offset\n : span.end.node === target.node\n ? span.end.offset\n : at.text.length\n const operations: Array<Operation> = [...deletions, Edit.insertText(target, command.text)]\n const end = target.offset + command.text.length\n if (tailFrom < at.text.length) operations.push(Edit.splitRun(target.node, end, ids.mint()))\n const piece = target.offset > 0 ? NodeId.make(ids.mint()) : target.node\n if (target.offset > 0) operations.push(Edit.splitRun(target.node, target.offset, piece))\n for (const mark of marks) {\n if (!at.marks.some(existing => sameMark(existing, mark))) {\n operations.push(Edit.addMark(piece, mark))\n }\n }\n for (const mark of at.marks) {\n if (!marks.some(kept => markName(kept) === markName(mark))) {\n operations.push(Edit.removeMark(piece, markName(mark)))\n }\n }\n return apply(state, operations)\n }\n\n if (\n command.type === 'RetypeBlock' ||\n command.type === 'WrapBlock' ||\n command.type === 'ConvertBlock' ||\n command.type === 'RetypeContainer' ||\n command.type === 'LiftBlock'\n ) {\n const target = startingBlock(state.document, selection)\n return 'error' in target\n ? failure(target.error)\n : runBlockCommand(state, command, target, ids, options)\n }\n\n if (command.type === 'DeleteBackward' || command.type === 'DeleteForward') {\n if (!isCollapsed(selection)) {\n const span = ordered(state.document, selection)\n if (span === undefined) return failure('InvalidSelection')\n const deletions = deleteRange(state.document, span.start, span.end)\n if (deletions === undefined) return failure('InvalidParent')\n return apply(state, [...deletions, Edit.setSelection(caretAt(span.start))])\n }\n const caret = selection.anchor\n const at = locate(state.document, caret.node)\n if (at === undefined) return failure('MissingText')\n const backward = command.type === 'DeleteBackward'\n const block = blockAtPath(state.document, at.path)\n if (block === undefined) return failure('MissingText')\n const deletion = graphemeDeletion(block, caret, at.runIndex, backward)\n if (deletion !== undefined) {\n return apply(state, [...deletion.operations, Edit.setSelection(caretAt(deletion.caret))])\n }\n // Backspace at the start of a node kind that holds text, such as a code block, turns it\n // back into a paragraph, undoing the fence, rather than joining text across two kinds\n // whose marks and content rules differ. Only a vocabulary says the kind holds text.\n if (backward && block.type === 'Node' && declaresText(options.nodes, block.kind)) {\n return run(state, { type: 'RetypeBlock', to: { type: 'Paragraph' } }, ids, options)\n }\n // A heading does too, undoing the `# ` that made it, before a second press joins it.\n if (backward && block.type === 'Heading') {\n return run(state, { type: 'RetypeBlock', to: { type: 'Paragraph' } }, ids, options)\n }\n // A block edge joins the sibling in the same container, wherever it sits.\n const containerPath = at.path.slice(0, -1)\n const siblings = containerBlocks(state.document, containerPath)\n const index = at.path[at.path.length - 1]!\n const neighborBlock = siblings[backward ? index - 1 : index + 1]\n // An atom cannot take text, so the edge selects it, and a second press deletes it. A\n // block left with nothing in it goes first, as Backspace on an empty line would.\n if (neighborBlock !== undefined && isAtom(options.nodes, neighborBlock)) {\n return apply(state, [\n ...(textOfBlock(block) === '' ? [Edit.deleteBlock(block.id)] : []),\n Edit.setSelection({ type: 'Node', node: neighborBlock.id }),\n ])\n }\n if (neighborBlock === undefined && backward) {\n // Backspace at the start of a container's first block has nothing to join with, so\n // it lifts the block out, undoing what `> ` or `- ` did. Only with a vocabulary: it\n // is what says a list item's paragraph must leave the list too, and a table cell must\n // not be left at all. Otherwise the edge stays a no-op.\n const lifted =\n containerPath.length > 0 && options.nodes !== undefined\n ? liftOperations(state.document, siblings[index]!.id, ids, options.nodes)\n : undefined\n return apply(state, lifted ?? [])\n }\n // Past a sibling it cannot join, or forward past the end of its container, the edge\n // reaches the nearest block on that side that holds no blocks: inside a list or a quote,\n // its last or first line, which joins the line at the caret as clearing the empty range\n // between them would. A table cell or code cannot take the line, so there an emptied line\n // goes and Backspace steps into it, and Delete beside a line with text does nothing.\n if (\n neighborBlock === undefined ||\n !joinable(backward ? neighborBlock : block, backward ? block : neighborBlock)\n ) {\n const leafPath =\n neighborBlock === undefined\n ? nextLeaf(state.document, at.path)\n : edgeLeaf(state.document, [...containerPath, index + (backward ? -1 : 1)], backward)\n const leaf = leafPath === undefined ? undefined : blockAtPath(state.document, leafPath)\n if (leafPath === undefined || leaf === undefined) return apply(state, [])\n const empty = textOfBlock(block) === ''\n if (isAtom(options.nodes, leaf)) {\n return apply(state, [Edit.setSelection({ type: 'Node', node: leaf.id })])\n }\n const first = leaf.children[0]\n const last = leaf.children[leaf.children.length - 1]\n const target = backward ? last : first\n if (target === undefined) return apply(state, [])\n const edge = {\n node: target.id,\n offset: backward ? target.text.length : 0,\n affinity: 'after' as const,\n }\n // An empty line beside a list or a quote goes, rather than taking its line out of it.\n const stepsOnly = empty && neighborBlock !== undefined\n // Across a table cell, clearing the range only steps the caret, as it should.\n if (!stepsOnly && (backward ? joinable(leaf, block) : joinable(block, leaf))) {\n return backward\n ? clearRange(state, edge, caret, options)\n : clearRange(state, caret, edge, options)\n }\n if (neighborBlock === undefined || (!backward && !empty)) return apply(state, [])\n return apply(state, [\n ...(empty ? [Edit.deleteBlock(block.id)] : []),\n Edit.setSelection(caretAt(edge)),\n ])\n }\n const survivor = backward ? neighborBlock : siblings[index]!\n const removed = backward ? siblings[index]! : neighborBlock\n // The caret lands at the junction: the end of what the survivor already had,\n // or the removed block's last run when the survivor holds no runs.\n const lastRun = lastRunOf(survivor) ?? lastRunOf(removed)\n return apply(state, [\n Edit.joinBlocks(survivor.id, removed.id),\n Edit.setSelection(\n caretAt(\n lastRun === undefined\n ? { node: survivor.id, offset: 0, affinity: 'after' }\n : { node: lastRun.id, offset: lastRun.text.length, affinity: 'after' },\n ),\n ),\n ])\n }\n\n if (command.type === 'SplitBlock') {\n const span = isCollapsed(selection) ? undefined : ordered(state.document, selection)\n if (!isCollapsed(selection) && span === undefined) return failure('InvalidSelection')\n const caret = span?.start ?? selection.anchor\n const at = locate(state.document, caret.node)\n if (at === undefined) return failure('MissingText')\n const deletions = span === undefined ? [] : deleteRange(state.document, span.start, span.end)\n if (deletions === undefined) return failure('InvalidParent')\n const holder = blockAtPath(state.document, at.path)\n const definition =\n holder?.type === 'Node' ? options.nodes?.definitionFor(holder.kind) : undefined\n if (holder !== undefined && definition?.kind === 'node' && definition.lineBreaks === true) {\n const last = holder.children[holder.children.length - 1]\n const onEmptyLastLine =\n span === undefined &&\n last?.id === at.id &&\n caret.offset === at.text.length &&\n holder.children\n .map(run => run.text)\n .join('')\n .endsWith('\\n')\n // Enter on an empty last line leaves the block, so one at the end of a document can be\n // left at all; anywhere else it is a line break in the text.\n return onEmptyLastLine\n ? runAction(\n state,\n [\n { type: 'DeleteBackward' },\n {\n type: 'InsertBlock',\n block: {\n type: 'Paragraph',\n id: NodeId.make('paragraph'),\n children: [{ type: 'Text', id: NodeId.make('text'), text: '', marks: [] }],\n },\n to: { after: holder.id },\n },\n ],\n ids,\n options,\n )\n : run(\n state,\n // In code, the new line starts as indented as the one it broke.\n {\n type: 'InsertText',\n text:\n definition.indents === true\n ? `\\n${indentationAt(textOfBlock(holder), offsetIn(holder, caret) ?? 0)}`\n : '\\n',\n },\n ids,\n options,\n )\n }\n const item = itemAround(state.document, at.path, options.nodes)\n if (item !== undefined) {\n // Over a range inside an item, Enter deletes the range and then splits the item, as it\n // would at a caret; the two commands already say how.\n return span === undefined\n ? splitItem(state, at, caret.offset, item, ids, options.nodes)\n : runAction(state, [{ type: 'DeleteBackward' }, { type: 'SplitBlock' }], ids, options)\n }\n const textId = ids.mint()\n const blockId = ids.mint()\n return apply(state, [\n ...deletions,\n Edit.splitBlock(at.blockId, at.id, caret.offset, blockId, textId),\n ...(endsHeading(state.document, at.path, span?.end ?? caret)\n ? [Edit.retypeBlock(NodeId.make(blockId), { type: 'Paragraph' })]\n : []),\n Edit.setSelection(caretAt({ node: NodeId.make(textId), offset: 0, affinity: 'after' })),\n ])\n }\n\n if (command.type === 'ToggleMark' || command.type === 'SetMark' || command.type === 'ClearMark') {\n const mark = command.mark\n const name = markName(mark)\n let span = ordered(state.document, selection)\n if (isCollapsed(selection)) {\n // A toggle at a caret has nothing to cover; setting or clearing one acts on the mark\n // the caret is in, so a link can be edited without selecting it first.\n const extent =\n command.type === 'ToggleMark'\n ? undefined\n : markExtent(state.document, selection.anchor, name)\n if (extent === undefined) return apply(state, [])\n span = ordered(state.document, extent.selection)\n }\n if (span === undefined) return failure('InvalidSelection')\n // A value clears only the runs carrying exactly it, so those are all the runs it covers.\n const spans = covered(state.document, span.start, span.end).filter(\n entry =>\n command.type !== 'ClearMark' ||\n typeof mark === 'string' ||\n entry.run.marks.some(held => sameMark(held, mark)),\n )\n if (spans.length === 0) return apply(state, [])\n // A toggle keys on the name: the mark is present on every covered run, or\n // it is absent everywhere. Props are the mark's own business.\n const adding =\n command.type === 'SetMark' ||\n (command.type === 'ToggleMark' &&\n !spans.every(entry => entry.run.marks.some(held => markName(held) === name)))\n const operations: Array<Operation> = []\n const targets: Array<NodeId> = []\n for (const [index, entry] of spans.entries()) {\n let target = entry.run.id\n let base = 0\n if (index === 0 && entry.from > 0) {\n const textId = ids.mint()\n operations.push(Edit.splitRun(target, entry.from, textId))\n target = NodeId.make(textId)\n base = entry.from\n }\n if (index === spans.length - 1 && entry.to < entry.run.text.length) {\n operations.push(Edit.splitRun(target, entry.to - base, ids.mint()))\n }\n targets.push(target)\n }\n if (adding) {\n // Adding needs the vocabulary to declare the mark and accept its props; removing a\n // preserved one by name is always allowed.\n if (!declared.accepts(mark)) return failure('InvalidInput')\n if (spans.some(entry => forbidsMarks(state.document, entry.run.path, options.nodes))) {\n return failure('ForbiddenMark')\n }\n for (const target of targets) operations.push(Edit.addMark(target, mark))\n } else {\n for (const target of targets) operations.push(Edit.removeMark(target, name))\n }\n return apply(state, operations)\n }\n\n if (command.type === 'Paste') {\n const content = command.slice.blocks\n if (content.length === 0) return apply(state, [])\n const span = isCollapsed(selection) ? undefined : ordered(state.document, selection)\n if (!isCollapsed(selection) && span === undefined) return failure('InvalidSelection')\n const caret = span?.start ?? selection.anchor\n const at = locate(state.document, caret.node)\n if (at === undefined) return failure('MissingText')\n // Into code, or any kind whose text keeps line breaks, what is pasted is its text.\n const into = blockAtPath(state.document, at.path)\n const holds = into?.type === 'Node' ? options.nodes?.definitionFor(into.kind) : undefined\n if (holds?.kind === 'node' && holds.lineBreaks === true) {\n return run(state, { type: 'InsertText', text: toText(content) }, ids, options)\n }\n const index = at.path[at.path.length - 1]!\n const containerPath = at.path.slice(0, -1)\n // The content lands in the caret's own container, so pasting inside a list\n // item stays inside the list.\n const parent =\n containerPath.length === 0 ? undefined : blockAtPath(state.document, containerPath)?.id\n const replacements = span === undefined ? [] : deleteRange(state.document, span.start, span.end)\n if (replacements === undefined) return failure('InvalidParent')\n const operations: Array<Operation> = [...replacements]\n const inserted = withFreshIds(command.slice, ids.mint).blocks\n // The content lands in the caret's container, so that container's constraint decides\n // which kinds it accepts (§125), and each kind's own says whether it may stand there (§149).\n const holder =\n containerPath.length === 0 ? undefined : blockAtPath(state.document, containerPath)\n if (\n inserted.some(\n piece =>\n (containerPath.length > 0 &&\n !acceptsChild(state.document, containerPath, blockKind(piece), options.nodes)) ||\n !standsWithin(\n options.nodes?.definitionFor(blockKind(piece)),\n holder === undefined ? undefined : blockKind(holder),\n ),\n )\n ) {\n return failure('UnexpectedChild')\n }\n const block = blockAtPath(state.document, at.path)\n if (block === undefined) return failure('MissingText')\n // The block splits at the caret and the content lands between the halves. The first\n // piece joins the text before the caret and the last the text after it, when each can be\n // one block with it, so a pasted word or line lands inside the sentence; a half left with\n // nothing in it goes, unless it is the only place after a table or an image to type.\n const end = span?.end ?? caret\n const endBlock = blockAtPath(state.document, locate(state.document, end.node)?.path ?? at.path)\n const beforeEmpty = offsetIn(block, caret) === 0\n const afterEmpty =\n endBlock === undefined || offsetIn(endBlock, end) === textOfBlock(endBlock).length\n const tailText = NodeId.make(ids.mint())\n const tail = NodeId.make(ids.mint())\n operations.push(Edit.splitBlock(at.blockId, at.id, caret.offset, tail, tailText))\n for (const [offset, piece] of inserted.entries()) {\n operations.push(Edit.insertBlock(piece, index + 1 + offset, parent))\n }\n const first = inserted[0]!\n const last = inserted[inserted.length - 1]!\n const lastRun = last.children[last.children.length - 1]\n // Set before the joins, which carry it with the runs they move.\n operations.push(\n Edit.setSelection(\n caretAt(\n lastRun === undefined\n ? { node: tailText, offset: 0, affinity: 'after' }\n : { node: lastRun.id, offset: lastRun.text.length, affinity: 'after' },\n ),\n ),\n )\n const joinsHead = joinable(block, first)\n const joinsTail = joinable(last, block)\n if (joinsHead) operations.push(Edit.joinBlocks(at.blockId, first.id))\n if (joinsTail) {\n operations.push(Edit.joinBlocks(joinsHead && last === first ? at.blockId : last.id, tail))\n }\n if (!joinsHead && beforeEmpty) operations.push(Edit.deleteBlock(at.blockId))\n if (!joinsTail && afterEmpty && lastRun !== undefined) operations.push(Edit.deleteBlock(tail))\n return apply(state, operations)\n }\n\n return apply(state, [])\n}\n\n/** Where an `InsertBlock` without a place goes: beside the caret's block, before it when empty. */\nconst besideCaret = (state: EditorState): Beside | undefined => {\n if (state.selection?.type !== 'Range') return undefined\n const run = locateRun(\n state.document,\n ordered(state.document, state.selection)?.start.node ?? state.selection.anchor.node,\n )\n const block = run === undefined ? undefined : blockAtPath(state.document, run.path)\n if (block === undefined) return undefined\n const empty = block.children.every(child => child.text === '')\n return empty ? { before: block.id } : { after: block.id }\n}\n\nconst textOfBlock = (block: Block): string => block.children.map(run => run.text).join('')\n\n/** The block the selection starts in when its kind indents its lines, as code does. */\nconst linesHolder = (state: EditorState, nodes: NodeRegistry | undefined): Block | undefined => {\n if (state.selection?.type !== 'Range') return undefined\n const start = ordered(state.document, state.selection)?.start\n const run = start === undefined ? undefined : locateRun(state.document, start.node)\n const block = run === undefined ? undefined : blockAtPath(state.document, run.path)\n if (block?.type !== 'Node') return undefined\n const definition = nodes?.definitionFor(block.kind)\n return definition?.kind === 'node' && definition.indents === true ? block : undefined\n}\n\n/**\n * Whether Tab means something where the selection is: in code, or in a table cell. An editor\n * takes Tab only there, so anywhere else it still moves focus out of the editor.\n */\nexport const takesTab = (\n document: Document,\n selection: Selection | null,\n nodes?: NodeRegistry,\n): boolean =>\n linesHolder({ document, selection }, nodes) !== undefined ||\n itemAtCaret({ document, selection }, nodes) !== undefined ||\n tableAt(document, selection) !== undefined\n\n/** The list item the selection starts in, when the vocabulary says its list holds it. */\nconst itemAtCaret = (state: EditorState, nodes: NodeRegistry | undefined) => {\n if (state.selection?.type !== 'Range') return undefined\n const start = ordered(state.document, state.selection)?.start\n const run = start === undefined ? undefined : locateRun(state.document, start.node)\n return run === undefined ? undefined : itemAround(state.document, run.path, nodes)\n}\n\n/** Whether two props hold the same values, for a list that two items may share. */\nconst sameProps = (left: Schema.JsonObject, right: Schema.JsonObject): boolean => {\n const keys = Object.keys(left)\n return (\n keys.length === Object.keys(right).length &&\n keys.every(key => Object.hasOwn(right, key) && Equal.equals(left[key], right[key]))\n )\n}\n\n/**\n * Tab in a list item: the item moves under the item before it, as the last item of the list\n * that item ends with, or of a new one like its own when it ends with none. It keeps its\n * identity, and the caret with it. The first item has nothing to go under, and stays.\n */\nconst sinkItem = (\n state: EditorState,\n item: ItemAround,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n if (item.list.type !== 'Node') return apply(state, [])\n const list = item.list\n const index = item.containerPath[item.containerPath.length - 1]!\n const previous = (list.blocks ?? [])[index - 1]\n if (previous?.type !== 'Node') return apply(state, [])\n const nested = previous.blocks?.at(-1)\n const last = nested?.type === 'Node' ? nested.blocks?.at(-1) : undefined\n if (\n nested?.type === 'Node' &&\n nested.kind === list.kind &&\n sameProps(nested.props, list.props) &&\n last !== undefined\n ) {\n return run(\n state,\n { type: 'MoveBlock', node: item.container.id, to: { after: last.id } },\n ids,\n options,\n )\n }\n const created = NodeId.make(ids.mint())\n return apply(state, [\n Edit.insertBlock(\n { type: 'Node', kind: list.kind, id: created, props: list.props, children: [], blocks: [] },\n (previous.blocks ?? []).length,\n previous.id,\n ),\n Edit.moveBlock(item.container.id, 0, created),\n ])\n}\n\n/**\n * Shift+Tab in a list item: a nested item moves out to follow the item its list is in, and an\n * item at the top level leaves its list, as `LiftBlock` takes it. A list the move empties goes.\n */\nconst liftItem = (\n state: EditorState,\n item: ItemAround,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n const listPath = item.containerPath.slice(0, -1)\n const outerItem = blockAtPath(state.document, listPath.slice(0, -1))\n const outerList = blockAtPath(state.document, listPath.slice(0, -2))\n const nestedInItem =\n outerItem?.type === 'Node' &&\n outerList?.type === 'Node' &&\n options.nodes !== undefined &&\n holdsItem(options.nodes, outerList.kind, outerItem.kind)\n return nestedInItem\n ? run(\n state,\n { type: 'MoveBlock', node: item.container.id, to: { after: outerItem.id } },\n ids,\n options,\n )\n : run(state, { type: 'LiftBlock' }, ids, options)\n}\n\n/**\n * Replaces matches, last first, each read again from its block's offset in the state the one\n * after it left: a replacement later in a block leaves an earlier match's offset alone, though\n * the runs it touched may have merged or split, so positions found before it would not do.\n */\nconst replaceMatches = (\n state: EditorState,\n matches: ReadonlyArray<SearchMatch>,\n replacement: string,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n let done = apply(state, [])\n for (const match of [...matches].reverse()) {\n if (!done.ok) return done\n const block = locateBlock(done.state.document, match.block)?.block\n const from = block === undefined ? undefined : positionInBlock(block, match.at)\n const to = block === undefined ? undefined : positionInBlock(block, match.at + match.length)\n if (from === undefined || to === undefined) return failure('MissingText')\n const step = runAction(\n done.state,\n [\n { type: 'SetSelection', selection: { type: 'Range', anchor: from, focus: to } },\n // Over a range, an insertion replaces it, so an empty replacement deletes the match.\n { type: 'InsertText', text: replacement },\n ],\n ids,\n options,\n )\n if (!step.ok) return step\n done = {\n ok: true,\n state: step.state,\n changeSet: unionChangeSet(done.changeSet, step.changeSet),\n positionMap: [...done.positionMap, ...step.positionMap],\n transactions: [...done.transactions, ...step.transactions],\n }\n }\n return done\n}\n\nconst insertFootnote = (\n state: EditorState,\n text: string,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n const selection = state.selection\n if (selection?.type !== 'Range') return failure('InvalidSelection')\n const start = rangeStart(state.document, selection)\n const last = state.document.children[state.document.children.length - 1]\n if (start === undefined || last === undefined) return failure('InvalidSelection')\n const end = start === selection.anchor ? selection.focus : selection.anchor\n const label = nextFootnoteLabel(state.document)\n // Placeholder identities: InsertBlock mints fresh ones.\n const definition: Block = {\n type: 'Node',\n kind: FootnoteDefinition.name,\n id: NodeId.make('footnote'),\n props: { label },\n children: [],\n blocks: [\n {\n type: 'Paragraph',\n id: NodeId.make('footnote-text'),\n children: [{ type: 'Text', id: NodeId.make('footnote-run'), text, marks: [] }],\n },\n ],\n }\n return runAction(\n state,\n [\n { type: 'SetSelection', selection: { type: 'Range', anchor: end, focus: end } },\n { type: 'InsertText', text: label, marks: [FootnoteRef.of({ label })] },\n { type: 'InsertBlock', block: definition, to: { after: last.id } },\n ],\n ids,\n options,\n )\n}\n\nconst renameFootnote = (\n state: EditorState,\n from: string,\n to: string,\n ids: CommandIds,\n options: RunOptions,\n): TransactionResult => {\n const notes = footnotesOf(state.document)\n const note = notes.find(each => each.label === from)\n if (note === undefined || to === '' || (to !== from && notes.some(each => each.label === to))) {\n return failure('InvalidInput')\n }\n const relabelled = FootnoteRef.of({ label: to })\n const references: Array<Command> = []\n eachBlock(state.document.children, block => {\n for (const run of block.children) {\n if (referenceLabel(run) !== from) continue\n references.push(\n {\n type: 'SetSelection',\n selection: {\n type: 'Range',\n anchor: { node: run.id, offset: 0, affinity: 'after' },\n focus: { node: run.id, offset: run.text.length, affinity: 'before' },\n },\n },\n {\n type: 'InsertText',\n text: run.text === from ? to : run.text,\n marks: run.marks.map(each => (markName(each) === FootnoteRef.name ? relabelled : each)),\n },\n )\n }\n })\n // The caret goes back where it was, unless it was in a reference the rename rewrote.\n const selection = state.selection\n const inReference =\n selection?.type === 'Range' &&\n (note.references.includes(selection.anchor.node) ||\n note.references.includes(selection.focus.node))\n return runAction(\n state,\n [\n ...(note.definition === undefined\n ? []\n : [{ type: 'SetProps' as const, node: note.definition, props: { label: to } }]),\n ...references,\n ...(inReference || selection === null ? [] : [{ type: 'SetSelection' as const, selection }]),\n ],\n ids,\n options,\n )\n}\n\n/** The first run anywhere in these blocks, nested ones included, in document order. */\nconst firstRunIn = (blocks: ReadonlyArray<Block>): Run | undefined => {\n let found: Run | undefined\n eachBlock(blocks, block => {\n found ??= block.children[0]\n })\n return found\n}\n\n/** An ordered list of commands that commit as one action (§124 §5). */\nexport type Action = ReadonlyArray<Command>\n\n/**\n * A composed action's invalidation summary is the union of its commands': an identity\n * one command retired and a later one restored appears in both sets, and a patch reads\n * that as \"remove it, then render it\", so it never under-invalidates.\n */\nexport const unionChangeSet = (left: ChangeSet, right: ChangeSet): ChangeSet => ({\n dirtyNodes: new Set([...left.dirtyNodes, ...right.dirtyNodes]),\n insertedNodes: new Set([...left.insertedNodes, ...right.insertedNodes]),\n removedNodes: new Set([...left.removedNodes, ...right.removedNodes]),\n textChanged: new Set([...left.textChanged, ...right.textChanged]),\n structureChanged: left.structureChanged || right.structureChanged,\n selectionChanged: left.selectionChanged || right.selectionChanged,\n})\n\n/**\n * Resolves commands in order and commits them as one action: one resulting state, one\n * composed ChangeSet, and one identity stream, so a caller can treat \"remove the query,\n * then apply the choice\" as a single transition. It stops at the first refusal and\n * returns that command's error; state is a value, so nothing partial escapes.\n */\nexport const runAction = (\n state: EditorState,\n commands: Action,\n ids: CommandIds,\n options: RunOptions = {},\n): TransactionResult => {\n const [first, ...rest] = commands\n // An empty action is a no-op, as an empty transaction is.\n if (first === undefined) return apply(state, [])\n const started = run(state, first, ids, options)\n if (!started.ok) return started\n let current = started.state\n let changeSet = started.changeSet\n let positionMap = started.positionMap\n let transactions = started.transactions\n for (const command of rest) {\n const result = run(current, command, ids, options)\n if (!result.ok) return result\n current = result.state\n changeSet = unionChangeSet(changeSet, result.changeSet)\n positionMap = [...positionMap, ...result.positionMap]\n transactions = [...transactions, ...result.transactions]\n }\n return { ok: true, state: current, changeSet, positionMap, transactions }\n}\n"],"mappings":";;;;;;;;;;;;;AAiMA,MAAa,SAAS,OAAO,MAAM,CAEjC,OAAO,OAAO;CAAE,QAAQ;CAAQ,OAAO,OAAO,YAAY,OAAO,KAAK;AAAE,CAAC,GACzE,OAAO,OAAO;CAAE,OAAO;CAAQ,QAAQ,OAAO,YAAY,OAAO,KAAK;AAAE,CAAC,CAC3E,CAAC;;AAID,MAAa,YAAY,OAAO,OAAO;CACrC,MAAM,OAAO;CACb,OAAO,OAAO,YAAY,OAAO,UAAU;AAC7C,CAAC;;;;;;;AAqBD,MAAM,gBACJ,UACA,MACA,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AAW,OAAO,SAAS;EACtD,cAAc,CAAC,GAAG,aAAa,GAAG,OAAO,WAAW;EACpD,eAAe,CAAC,GAAG,cAAc,GAAG,OAAO,YAAY;CACzD;CACA,OAAO;EAAE,IAAI;EAAM,OAAO;EAAS;EAAW;EAAa;CAAa;AAC1E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Document, NodeId, Position } from "./document.js";
|
|
2
|
+
/**
|
|
3
|
+
* One decoration over a document range. `kind` is a fixed word the presentation is
|
|
4
|
+
* chosen by (`search`, `syntax`, `cursor`, …); `data` is the renderer's own payload,
|
|
5
|
+
* which the core never reads.
|
|
6
|
+
*/
|
|
7
|
+
export interface Decoration<Data = unknown> {
|
|
8
|
+
readonly from: Position;
|
|
9
|
+
readonly to: Position;
|
|
10
|
+
readonly kind: string;
|
|
11
|
+
readonly data?: Data;
|
|
12
|
+
}
|
|
13
|
+
/** A set of decorations is a value, computed for one render and then discarded. */
|
|
14
|
+
export type DecorationSet<Data = unknown> = ReadonlyArray<Decoration<Data>>;
|
|
15
|
+
/** A decoration's sub-range inside one run, in that run's own offsets. */
|
|
16
|
+
export interface DecorationSpan<Data = unknown> {
|
|
17
|
+
readonly from: number;
|
|
18
|
+
readonly to: number;
|
|
19
|
+
readonly decoration: Decoration<Data>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The decorations covering each run, as offsets into it, in document order. A decoration
|
|
23
|
+
* that crosses runs is cut at each run's edge, so a renderer never has to reason about
|
|
24
|
+
* document order; a decoration whose endpoints do not resolve is skipped rather than
|
|
25
|
+
* guessed at, the way every other read treats a position it cannot resolve, and a
|
|
26
|
+
* direction is honoured rather than required to run forwards.
|
|
27
|
+
*
|
|
28
|
+
* The runs are indexed once, so a decoration costs the runs it covers: a hundred search
|
|
29
|
+
* matches over a long document is one walk, not a hundred.
|
|
30
|
+
*/
|
|
31
|
+
export declare const decorationsIn: <Data>(document: Document, set: DecorationSet<Data>) => ReadonlyMap<NodeId, ReadonlyArray<DecorationSpan<Data>>>;
|
|
32
|
+
/** A stretch of one run's text, and the decorations covering all of it. */
|
|
33
|
+
export interface RunPiece<Data = unknown> {
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly decorations: ReadonlyArray<Decoration<Data>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A run's text cut at every edge of the spans over it, each piece with the decorations
|
|
39
|
+
* that cover it — what every interpreter draws, so each draws the same pieces. An empty run,
|
|
40
|
+
* or one no span touches, is one undecorated piece: an interpreter still has to render
|
|
41
|
+
* somewhere for a caret to sit, and nothing can be drawn over no text.
|
|
42
|
+
*/
|
|
43
|
+
export declare const runPieces: <Data>(text: string, spans: ReadonlyArray<DecorationSpan<Data>>) => ReadonlyArray<RunPiece<Data>>;
|
|
44
|
+
//# sourceMappingURL=decoration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoration.d.ts","names":[],"sources":["../src/decoration.ts"],"mappings":";;;;;;iBAmBiB,WAAW;WACjB,MAAM;WACN,IAAI;WACJ;WACA,OAAO;;;YAIN,cAAc,kBAAkB,cAAc,WAAW;;iBAGpD,eAAe;WACrB;WACA;WACA,YAAY,WAAW;;;;;;;;;;;;qBAarB,gBAAiB,MAAI,UACtB,UAAQ,KACb,cAAc,UAClB,YAAY,QAAQ,cAAc,eAAe;;iBAsCnC,SAAS;WACf;WACA,aAAa,cAAc,WAAW;;;;;;;;qBASpC,YAAa,MAAI,cAChB,OACL,cAAc,eAAe,WACnC,cAAc,SAAS"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { eachBlock } from "./document.js";
|
|
2
|
+
// src/decoration.ts
|
|
3
|
+
/**
|
|
4
|
+
* Decorations (§64): the ephemeral third kind beside Marks and Annotations. A
|
|
5
|
+
* decoration is presentation derived from current state — a search match, a lint
|
|
6
|
+
* warning, a remote cursor, a syntax token — rendered by an interpreter and then
|
|
7
|
+
* discarded. It is never serialized, never part of undo, and never authored content,
|
|
8
|
+
* which is why this module holds contracts rather than document data.
|
|
9
|
+
*
|
|
10
|
+
* The projection here is shared on purpose: a read-only renderer, the editable adapter,
|
|
11
|
+
* and any other interpreter all need the same answer to "which decorations cover this
|
|
12
|
+
* run, and where", so they compute it once, in the core, rather than each cutting ranges
|
|
13
|
+
* their own way.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The decorations covering each run, as offsets into it, in document order. A decoration
|
|
17
|
+
* that crosses runs is cut at each run's edge, so a renderer never has to reason about
|
|
18
|
+
* document order; a decoration whose endpoints do not resolve is skipped rather than
|
|
19
|
+
* guessed at, the way every other read treats a position it cannot resolve, and a
|
|
20
|
+
* direction is honoured rather than required to run forwards.
|
|
21
|
+
*
|
|
22
|
+
* The runs are indexed once, so a decoration costs the runs it covers: a hundred search
|
|
23
|
+
* matches over a long document is one walk, not a hundred.
|
|
24
|
+
*/
|
|
25
|
+
const decorationsIn = (document, set) => {
|
|
26
|
+
const spans = /* @__PURE__ */ new Map();
|
|
27
|
+
if (set.length === 0) return spans;
|
|
28
|
+
const runs = [];
|
|
29
|
+
const indexByRun = /* @__PURE__ */ new Map();
|
|
30
|
+
eachBlock(document.children, (block) => {
|
|
31
|
+
for (const run of block.children) {
|
|
32
|
+
indexByRun.set(run.id, runs.length);
|
|
33
|
+
runs.push({
|
|
34
|
+
id: run.id,
|
|
35
|
+
length: run.text.length
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
for (const decoration of set) {
|
|
40
|
+
const anchor = indexByRun.get(decoration.from.node);
|
|
41
|
+
const focus = indexByRun.get(decoration.to.node);
|
|
42
|
+
if (anchor === void 0 || focus === void 0) continue;
|
|
43
|
+
const forward = anchor <= focus;
|
|
44
|
+
const first = forward ? anchor : focus;
|
|
45
|
+
const last = forward ? focus : anchor;
|
|
46
|
+
const firstOffset = forward ? decoration.from.offset : decoration.to.offset;
|
|
47
|
+
const lastOffset = forward ? decoration.to.offset : decoration.from.offset;
|
|
48
|
+
for (let index = first; index <= last; index += 1) {
|
|
49
|
+
const run = runs[index];
|
|
50
|
+
const from = Math.max(0, index === first ? firstOffset : 0);
|
|
51
|
+
const to = Math.min(run.length, index === last ? lastOffset : run.length);
|
|
52
|
+
if (from >= to) continue;
|
|
53
|
+
const covered = spans.get(run.id);
|
|
54
|
+
const span = {
|
|
55
|
+
from,
|
|
56
|
+
to,
|
|
57
|
+
decoration
|
|
58
|
+
};
|
|
59
|
+
if (covered === void 0) spans.set(run.id, [span]);
|
|
60
|
+
else covered.push(span);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const covered of spans.values()) covered.sort((left, right) => left.from - right.from);
|
|
64
|
+
return spans;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A run's text cut at every edge of the spans over it, each piece with the decorations
|
|
68
|
+
* that cover it — what every interpreter draws, so each draws the same pieces. An empty run,
|
|
69
|
+
* or one no span touches, is one undecorated piece: an interpreter still has to render
|
|
70
|
+
* somewhere for a caret to sit, and nothing can be drawn over no text.
|
|
71
|
+
*/
|
|
72
|
+
const runPieces = (text, spans) => {
|
|
73
|
+
if (spans.length === 0 || text.length === 0) return [{
|
|
74
|
+
text,
|
|
75
|
+
decorations: []
|
|
76
|
+
}];
|
|
77
|
+
const edges = /* @__PURE__ */ new Set([0, text.length]);
|
|
78
|
+
for (const span of spans) {
|
|
79
|
+
edges.add(Math.max(0, Math.min(text.length, span.from)));
|
|
80
|
+
edges.add(Math.max(0, Math.min(text.length, span.to)));
|
|
81
|
+
}
|
|
82
|
+
const cuts = [...edges].sort((left, right) => left - right);
|
|
83
|
+
const pieces = [];
|
|
84
|
+
for (let index = 0; index < cuts.length - 1; index += 1) {
|
|
85
|
+
const from = cuts[index];
|
|
86
|
+
const to = cuts[index + 1];
|
|
87
|
+
pieces.push({
|
|
88
|
+
text: text.slice(from, to),
|
|
89
|
+
decorations: spans.filter((span) => span.from <= from && to <= span.to).map((span) => span.decoration)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return pieces;
|
|
93
|
+
};
|
|
94
|
+
export { decorationsIn, runPieces };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=decoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoration.js","names":[],"sources":["../src/decoration.ts"],"sourcesContent":["/**\n * Decorations (§64): the ephemeral third kind beside Marks and Annotations. A\n * decoration is presentation derived from current state — a search match, a lint\n * warning, a remote cursor, a syntax token — rendered by an interpreter and then\n * discarded. It is never serialized, never part of undo, and never authored content,\n * which is why this module holds contracts rather than document data.\n *\n * The projection here is shared on purpose: a read-only renderer, the editable adapter,\n * and any other interpreter all need the same answer to \"which decorations cover this\n * run, and where\", so they compute it once, in the core, rather than each cutting ranges\n * their own way.\n */\nimport { eachBlock, type Document, type NodeId, type Position } from './document.js'\n\n/**\n * One decoration over a document range. `kind` is a fixed word the presentation is\n * chosen by (`search`, `syntax`, `cursor`, …); `data` is the renderer's own payload,\n * which the core never reads.\n */\nexport interface Decoration<Data = unknown> {\n readonly from: Position\n readonly to: Position\n readonly kind: string\n readonly data?: Data\n}\n\n/** A set of decorations is a value, computed for one render and then discarded. */\nexport type DecorationSet<Data = unknown> = ReadonlyArray<Decoration<Data>>\n\n/** A decoration's sub-range inside one run, in that run's own offsets. */\nexport interface DecorationSpan<Data = unknown> {\n readonly from: number\n readonly to: number\n readonly decoration: Decoration<Data>\n}\n\n/**\n * The decorations covering each run, as offsets into it, in document order. A decoration\n * that crosses runs is cut at each run's edge, so a renderer never has to reason about\n * document order; a decoration whose endpoints do not resolve is skipped rather than\n * guessed at, the way every other read treats a position it cannot resolve, and a\n * direction is honoured rather than required to run forwards.\n *\n * The runs are indexed once, so a decoration costs the runs it covers: a hundred search\n * matches over a long document is one walk, not a hundred.\n */\nexport const decorationsIn = <Data>(\n document: Document,\n set: DecorationSet<Data>,\n): ReadonlyMap<NodeId, ReadonlyArray<DecorationSpan<Data>>> => {\n const spans = new Map<NodeId, Array<DecorationSpan<Data>>>()\n if (set.length === 0) return spans\n // Document order is depth-first, which is what `compareRunPlaces` orders by too.\n const runs: Array<{ readonly id: NodeId; readonly length: number }> = []\n const indexByRun = new Map<NodeId, number>()\n eachBlock(document.children, block => {\n for (const run of block.children) {\n indexByRun.set(run.id, runs.length)\n runs.push({ id: run.id, length: run.text.length })\n }\n })\n for (const decoration of set) {\n const anchor = indexByRun.get(decoration.from.node)\n const focus = indexByRun.get(decoration.to.node)\n if (anchor === undefined || focus === undefined) continue\n const forward = anchor <= focus\n const first = forward ? anchor : focus\n const last = forward ? focus : anchor\n const firstOffset = forward ? decoration.from.offset : decoration.to.offset\n const lastOffset = forward ? decoration.to.offset : decoration.from.offset\n for (let index = first; index <= last; index += 1) {\n const run = runs[index]!\n const from = Math.max(0, index === first ? firstOffset : 0)\n const to = Math.min(run.length, index === last ? lastOffset : run.length)\n if (from >= to) continue\n const covered = spans.get(run.id)\n const span = { from, to, decoration }\n if (covered === undefined) spans.set(run.id, [span])\n else covered.push(span)\n }\n }\n // A renderer walks a run's text forwards, so its spans are in that order.\n for (const covered of spans.values()) covered.sort((left, right) => left.from - right.from)\n return spans\n}\n\n/** A stretch of one run's text, and the decorations covering all of it. */\nexport interface RunPiece<Data = unknown> {\n readonly text: string\n readonly decorations: ReadonlyArray<Decoration<Data>>\n}\n\n/**\n * A run's text cut at every edge of the spans over it, each piece with the decorations\n * that cover it — what every interpreter draws, so each draws the same pieces. An empty run,\n * or one no span touches, is one undecorated piece: an interpreter still has to render\n * somewhere for a caret to sit, and nothing can be drawn over no text.\n */\nexport const runPieces = <Data>(\n text: string,\n spans: ReadonlyArray<DecorationSpan<Data>>,\n): ReadonlyArray<RunPiece<Data>> => {\n if (spans.length === 0 || text.length === 0) return [{ text, decorations: [] }]\n const edges = new Set<number>([0, text.length])\n for (const span of spans) {\n edges.add(Math.max(0, Math.min(text.length, span.from)))\n edges.add(Math.max(0, Math.min(text.length, span.to)))\n }\n const cuts = [...edges].sort((left, right) => left - right)\n const pieces: Array<RunPiece<Data>> = []\n for (let index = 0; index < cuts.length - 1; index += 1) {\n const from = cuts[index]!\n const to = cuts[index + 1]!\n pieces.push({\n text: text.slice(from, to),\n decorations: spans\n .filter(span => span.from <= from && to <= span.to)\n .map(span => span.decoration),\n })\n }\n return pieces\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,iBACX,UACA,QAC6D;CAC7D,MAAM,wBAAQ,IAAI,IAAyC;CAC3D,IAAI,IAAI,WAAW,GAAG,OAAO;CAE7B,MAAM,OAAgE,CAAC;CACvE,MAAM,6BAAa,IAAI,IAAoB;CAC3C,UAAU,SAAS,WAAU,UAAS;EACpC,KAAK,MAAM,OAAO,MAAM,UAAU;GAChC,WAAW,IAAI,IAAI,IAAI,KAAK,MAAM;GAClC,KAAK,KAAK;IAAE,IAAI,IAAI;IAAI,QAAQ,IAAI,KAAK;GAAO,CAAC;EACnD;CACF,CAAC;CACD,KAAK,MAAM,cAAc,KAAK;EAC5B,MAAM,SAAS,WAAW,IAAI,WAAW,KAAK,IAAI;EAClD,MAAM,QAAQ,WAAW,IAAI,WAAW,GAAG,IAAI;EAC/C,IAAI,WAAW,KAAA,KAAa,UAAU,KAAA,GAAW;EACjD,MAAM,UAAU,UAAU;EAC1B,MAAM,QAAQ,UAAU,SAAS;EACjC,MAAM,OAAO,UAAU,QAAQ;EAC/B,MAAM,cAAc,UAAU,WAAW,KAAK,SAAS,WAAW,GAAG;EACrE,MAAM,aAAa,UAAU,WAAW,GAAG,SAAS,WAAW,KAAK;EACpE,KAAK,IAAI,QAAQ,OAAO,SAAS,MAAM,SAAS,GAAG;GACjD,MAAM,MAAM,KAAK;GACjB,MAAM,OAAO,KAAK,IAAI,GAAG,UAAU,QAAQ,cAAc,CAAC;GAC1D,MAAM,KAAK,KAAK,IAAI,IAAI,QAAQ,UAAU,OAAO,aAAa,IAAI,MAAM;GACxE,IAAI,QAAQ,IAAI;GAChB,MAAM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