@dou-ui/editor 0.1.0-alpha.12 → 0.1.0-alpha.13
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/collaboration/cursors.js +42 -10
- package/dist/collaboration/cursors.js.map +1 -1
- package/dist/collaboration/index.js +30 -3
- package/dist/collaboration/index.js.map +1 -1
- package/dist/components/block-handle.js.map +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +73 -15
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/slash-choices.js +6 -0
- package/dist/components/slash-choices.js.map +1 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/slash-menu.js.map +1 -1
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/core/block-selection.js +32 -4
- package/dist/core/block-selection.js.map +1 -1
- package/dist/core/blocks.js +21 -3
- package/dist/core/blocks.js.map +1 -1
- package/dist/core/commands.js +125 -13
- package/dist/core/commands.js.map +1 -1
- package/dist/core/extension.js +6 -2
- package/dist/core/extension.js.map +1 -1
- package/dist/core/model.js +8 -2
- package/dist/core/model.js.map +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/transaction.js +12 -3
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +40 -4
- package/dist/document.js.map +1 -1
- package/dist/dom.js +96 -13
- package/dist/dom.js.map +1 -1
- package/dist/editor.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/editor2.js.map +1 -1
- package/dist/extensions/columns/column-picker.js +6 -0
- package/dist/extensions/columns/column-picker.js.map +1 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/columns-controls.js +6 -0
- package/dist/extensions/columns/columns-controls.js.map +1 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/html.js +34 -0
- package/dist/extensions/columns/html.js.map +1 -0
- package/dist/extensions/columns/index.js +57 -0
- package/dist/extensions/columns/index.js.map +1 -0
- package/dist/extensions/columns/keys.js +53 -0
- package/dist/extensions/columns/keys.js.map +1 -0
- package/dist/extensions/columns/plugin.js +213 -0
- package/dist/extensions/columns/plugin.js.map +1 -0
- package/dist/extensions/columns/schema.js +58 -0
- package/dist/extensions/columns/schema.js.map +1 -0
- package/dist/extensions/columns/select-columns.js +6 -0
- package/dist/extensions/columns/select-columns.js.map +1 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/editor-kit.js +3 -1
- package/dist/extensions/editor-kit.js.map +1 -1
- package/dist/extensions/table/plugin.js +33 -1
- package/dist/extensions/table/plugin.js.map +1 -1
- package/dist/extensions/table/table-controls.js.map +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/table/view.js +25 -1
- package/dist/extensions/table/view.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/locale.js +30 -0
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/collaboration/cursors.d.ts +29 -1
- package/dist/types/collaboration/index.d.ts +17 -2
- package/dist/types/components/slash-choices.vue.d.ts +18 -0
- package/dist/types/core/blocks.d.ts +10 -0
- package/dist/types/core/commands.d.ts +17 -2
- package/dist/types/core/extension.d.ts +53 -2
- package/dist/types/core/model.d.ts +6 -1
- package/dist/types/core/schema.d.ts +1 -1
- package/dist/types/document.d.ts +4 -2
- package/dist/types/dom.d.ts +34 -4
- package/dist/types/editor.vue.d.ts +10 -0
- package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
- package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
- package/dist/types/extensions/columns/html.d.ts +10 -0
- package/dist/types/extensions/columns/index.d.ts +9 -0
- package/dist/types/extensions/columns/keys.d.ts +6 -0
- package/dist/types/extensions/columns/plugin.d.ts +28 -0
- package/dist/types/extensions/columns/schema.d.ts +17 -0
- package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
- package/dist/types/extensions/editor-kit.d.ts +4 -1
- package/dist/types/extensions/table/view.d.ts +8 -1
- package/dist/types/index.d.ts +12 -2
- package/dist/types/locale.d.ts +17 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","names":[],"sources":["../../src/core/commands.ts"],"sourcesContent":["import { Fragment, type Node as PMNode, type Schema } from 'prosemirror-model'\nimport {\n NodeSelection,\n Selection,\n TextSelection,\n type Command,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport {\n blockAround,\n blocksIn,\n infoAt,\n nextInDocument,\n previousInDocument,\n selectedRange,\n type BlockInfo,\n type SiblingRange,\n} from './blocks'\nimport { createContentNode, type BlockProps } from './model'\nimport type { ContentType } from './schema'\n\nconst newBlock = (schema: Schema, content: PMNode, children?: Fragment) =>\n schema.nodes.block!.create(\n { id: null },\n children?.size ? [content, schema.nodes.blockGroup!.create(null, children)] : content,\n )\n\n/** The block and content around the cursor, when the selection is inside one textblock. */\nfunction cursorBlock(state: EditorState) {\n const { $from, $to } = state.selection\n if (!$from.parent.isTextblock || !$from.sameParent($to)) return null\n const info = blockAround($from)\n return info && info.content === $from.parent ? info : null\n}\n\n/* turning blocks into another type */\n\n/**\n * Turn every block the selection touches into `type`. Text formatting is\n * dropped when it can't be kept (in a code block); a type without text\n * (a divider, an embed) replaces the content and adds an empty paragraph\n * after it to keep typing in.\n */\nexport function setBlockType(type: ContentType, props: BlockProps = {}): Command {\n return (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n const schema = state.schema\n const nodeType = schema.nodes[type]\n if (!nodeType) return false\n if (!dispatch) return true\n const tr = state.tr\n const created = createContentNode(schema, type, props)\n const attrs = created.attrs\n if (!nodeType.isTextblock) {\n const blocks = blocksIn(range)\n const last = blocks.at(-1)!\n // last first, so earlier positions stay valid\n for (let index = blocks.length - 1; index >= 0; index--) {\n const block = blocks[index]!\n tr.replaceWith(block.contentPos, block.contentPos + block.content.nodeSize, created)\n }\n const after = tr.mapping.map(last.pos + last.node.nodeSize)\n tr.insert(after, newBlock(schema, schema.nodes.paragraph!.create()))\n tr.setSelection(TextSelection.create(tr.doc, after + 2))\n dispatch(tr.scrollIntoView())\n return true\n }\n for (const block of blocksIn(range)) {\n const from = tr.mapping.map(block.contentPos)\n const content = tr.doc.nodeAt(from)!\n // a block holding other nodes (a table) can't become text\n if (!content.isAtom && !content.inlineContent) continue\n if (content.isAtom) {\n tr.replaceWith(from, from + content.nodeSize, nodeType.create(attrs))\n } else {\n // only this content node: the block's children keep their type; alignment stays\n const align = content.attrs.align\n const kept = align != null && nodeType.spec.attrs?.align ? { ...attrs, align } : attrs\n tr.setBlockType(from + 1, from + content.nodeSize - 1, nodeType, kept)\n }\n }\n const { from, to } = state.selection\n if (state.selection instanceof TextSelection)\n tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(from), tr.mapping.map(to)))\n dispatch(tr.scrollIntoView())\n return true\n }\n}\n\n/** Set attributes on the content of the block at `pos`, e.g. tick a to-do. */\nexport function setContentAttrs(pos: number, attrs: Record<string, unknown>): Command {\n return (state, dispatch) => {\n const info = blockAround(state.doc.resolve(pos + 1))\n if (!info) return false\n if (dispatch) {\n const tr = state.tr.setNodeMarkup(info.contentPos, undefined, {\n ...info.content.attrs,\n ...attrs,\n })\n dispatch(tr)\n }\n return true\n }\n}\n\n/* Enter */\n\n/**\n * Split the block at the cursor. An empty list item turns back into a\n * paragraph, an empty nested paragraph moves up a level, and a block with\n * children gets its new block as the first child.\n */\nexport const splitBlock: Command = (state, dispatch) => {\n const schema = state.schema\n let tr = state.tr\n if (!state.selection.empty) {\n if (!cursorBlockAfterDelete(state)) return false\n tr = tr.deleteSelection()\n }\n const $from = tr.selection.$from\n const info = blockAround($from)\n if (!info || info.content !== $from.parent || !$from.parent.isTextblock) return false\n const content = info.content\n const type = content.type.name\n\n if (content.content.size === 0) {\n if (type !== 'paragraph' && !content.type.spec.code) {\n if (dispatch)\n dispatch(tr.setBlockType($from.pos, $from.pos, schema.nodes.paragraph!).scrollIntoView())\n return true\n }\n if (type === 'paragraph' && info.depth > 1) return liftBlocks(state, dispatch)\n }\n\n if (!dispatch) return true\n const offset = $from.parentOffset\n // lists continue themselves (with their default attributes: a to-do starts unticked)\n const nextType = content.type.spec.continues ? type : 'paragraph'\n const nextAttrs = null\n const contentEnd = info.contentPos + content.nodeSize - 1\n\n // at the very start of a non-empty block: open an empty block above it\n if (offset === 0 && content.content.size > 0) {\n const above = newBlock(schema, schema.nodes[nextType]!.create(nextAttrs))\n tr.insert(info.pos, above)\n dispatch(tr.scrollIntoView())\n return true\n }\n\n const rest = content.content.cut(offset)\n const moved = schema.nodes[nextType]!.create(nextAttrs, rest)\n tr.delete($from.pos, contentEnd)\n const block = newBlock(schema, moved)\n let insertAt: number\n if (info.group) {\n // first child: right below the line the cursor was on\n insertAt = tr.mapping.map(info.contentPos + content.nodeSize) + 1\n } else {\n insertAt = tr.mapping.map(info.pos + info.node.nodeSize)\n }\n tr.insert(insertAt, block)\n tr.setSelection(TextSelection.create(tr.doc, insertAt + 2))\n dispatch(tr.scrollIntoView())\n return true\n}\n\nfunction cursorBlockAfterDelete(state: EditorState) {\n return !!blockAround(state.selection.$from)\n}\n\n/** `Shift+Enter`: a line break, or a newline in code. */\nexport const insertBreak: Command = (state, dispatch) => {\n const { $from } = state.selection\n if (!$from.parent.isTextblock) return false\n if (dispatch) {\n const tr = $from.parent.type.spec.code\n ? state.tr.insertText('\\n')\n : state.tr.replaceSelectionWith(state.schema.nodes.hardBreak!.create())\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/** In a code block, `Enter` adds a newline. */\nexport const newlineInCode: Command = (state, dispatch) => {\n const { $from } = state.selection\n if (!$from.parent.type.spec.code) return false\n if (dispatch) dispatch(state.tr.insertText('\\n').scrollIntoView())\n return true\n}\n\n/** `Mod+Enter` in a code block: leave it for a new paragraph below. */\nexport const exitCode: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n if (!info || !info.content.type.spec.code) return false\n if (dispatch) {\n const at = info.pos + info.node.nodeSize\n const tr = state.tr.insert(at, newBlock(state.schema, state.schema.nodes.paragraph!.create()))\n tr.setSelection(TextSelection.create(tr.doc, at + 2))\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/* Backspace and Delete */\n\n/**\n * Move `source`'s text to the end of `target`'s content and put its\n * children where `source` was.\n */\nfunction mergeInto(tr: Transaction, target: BlockInfo, source: BlockInfo) {\n const joinAt = target.contentPos + target.content.nodeSize - 1\n const children = source.group ? source.group.content : Fragment.empty\n tr.replaceWith(source.pos, source.pos + source.node.nodeSize, children)\n let inline = source.content.content\n if (target.content.type.spec.code) {\n const text = source.content.textContent\n inline = text ? Fragment.from(tr.doc.type.schema.text(text)) : Fragment.empty\n }\n tr.insert(joinAt, inline)\n tr.setSelection(TextSelection.create(tr.doc, joinAt))\n}\n\n/**\n * `Backspace` at the start of a block: first turn it into a paragraph, then\n * move a nested block up a level, then join it with the block above.\n */\nexport const joinBackward: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n if (!info || !state.selection.empty || state.selection.$from.parentOffset > 0) return false\n const type = info.content.type.name\n if (type !== 'paragraph') {\n if (dispatch) {\n const pos = state.selection.from\n dispatch(state.tr.setBlockType(pos, pos, state.schema.nodes.paragraph!))\n }\n return true\n }\n if (info.depth > 1) return liftBlocks(state, dispatch)\n const previous = previousInDocument(state.doc, info)\n if (!previous) return false\n if (!dispatch) return true\n const tr = state.tr\n if (previous.content.isAtom) {\n // the block above is a divider: remove it\n tr.delete(previous.pos, previous.pos + previous.node.nodeSize)\n dispatch(tr.scrollIntoView())\n return true\n }\n mergeInto(tr, previous, info)\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/** `Delete` at the end of a block: pull the next block's text up. */\nexport const joinForward: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n const { $from } = state.selection\n if (!info || !state.selection.empty || $from.parentOffset < $from.parent.content.size)\n return false\n const next = nextInDocument(state.doc, info)\n if (!next) return false\n if (!dispatch) return true\n const tr = state.tr\n if (next.content.isAtom && !next.group) {\n tr.delete(next.pos, next.pos + next.node.nodeSize)\n } else {\n mergeInto(tr, info, next)\n }\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/** With a divider selected, `Backspace` or `Delete` removes its block. */\nexport const deleteSelectedAtom: Command = (state, dispatch) => {\n const selection = state.selection\n if (!(selection instanceof NodeSelection) || !selection.node.isAtom) return false\n const info = blockAround(selection.$from)\n if (!info) return false\n if (dispatch) dispatch(deleteBlocks(state.tr, [info]).scrollIntoView())\n return true\n}\n\n/* indenting */\n\n/** `Tab`: make the selected blocks children of the block above them. */\nexport const sinkBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range || range.from === 0) return false\n if (!dispatch) return true\n const schema = state.schema\n const blocks = blocksIn(range)\n const previousNode = range.parent.child(range.from - 1)\n const previous = infoAt(previousNode, range.start - previousNode.nodeSize, range.depth)\n const moving = Fragment.fromArray(blocks.map((block) => block.node))\n const tr = state.tr\n const { from, to } = state.selection\n tr.delete(range.start, range.end)\n let shift: number\n if (previous.group) {\n const at = previous.pos + previous.node.nodeSize - 2\n tr.insert(at, moving)\n shift = at - range.start\n } else {\n const at = previous.pos + previous.node.nodeSize - 1\n tr.insert(at, schema.nodes.blockGroup!.create(null, moving))\n shift = at + 1 - range.start\n }\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/**\n * `Shift+Tab`: move the selected blocks up a level, right after their\n * parent. The siblings that followed them become children of the last one,\n * so nothing changes order.\n */\nexport const liftBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range || range.depth <= 1) return false\n if (!dispatch) return true\n const schema = state.schema\n const doc = state.doc\n const $start = doc.resolve(range.start)\n const parentDepth = range.depth - 2\n const parent = infoAt($start.node(parentDepth), $start.before(parentDepth), parentDepth)\n const group = range.parent\n const blocks = blocksIn(range).map((block) => block.node)\n // siblings after the range go under the last moved block\n const following: PMNode[] = []\n for (let index = range.to + 1; index < group.childCount; index++)\n following.push(group.child(index))\n if (following.length) {\n const last = blocks.pop()!\n const ownGroup = last.childCount > 1 ? last.child(1).content : Fragment.empty\n const children = ownGroup.append(Fragment.fromArray(following))\n blocks.push(\n last.copy(\n Fragment.from(last.firstChild!).addToEnd(schema.nodes.blockGroup!.create(null, children)),\n ),\n )\n }\n const kept: PMNode[] = []\n for (let index = 0; index < range.from; index++) kept.push(group.child(index))\n const parentContent = parent.node.firstChild!\n const newParent = parent.node.copy(\n kept.length\n ? Fragment.from(parentContent).addToEnd(group.copy(Fragment.fromArray(kept)))\n : Fragment.from(parentContent),\n )\n const tr = state.tr\n const { from, to } = state.selection\n tr.replaceWith(parent.pos, parent.pos + parent.node.nodeSize, [newParent, ...blocks])\n // the moved blocks now start right after the rebuilt parent\n const shift = parent.pos + newParent.nodeSize - range.start\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n}\n\nfunction restoreSelection(tr: Transaction, state: EditorState, from: number, to: number) {\n const clamp = (pos: number) => Math.max(0, Math.min(pos, tr.doc.content.size))\n if (state.selection instanceof NodeSelection) {\n const $pos = tr.doc.resolve(clamp(from))\n if ($pos.nodeAfter) {\n tr.setSelection(NodeSelection.create(tr.doc, $pos.pos))\n return\n }\n }\n tr.setSelection(TextSelection.between(tr.doc.resolve(clamp(from)), tr.doc.resolve(clamp(to))))\n}\n\n/* moving, duplicating and removing blocks */\n\n/** `Mod+Shift+↑/↓`: swap the selected blocks with their neighbour. */\nexport function swapBlocks(direction: -1 | 1): Command {\n return (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n const neighbourIndex = direction < 0 ? range.from - 1 : range.to + 1\n if (neighbourIndex < 0 || neighbourIndex >= range.parent.childCount) return false\n if (!dispatch) return true\n const neighbour = range.parent.child(neighbourIndex)\n const tr = state.tr\n const { from, to } = state.selection\n let shift: number\n if (direction < 0) {\n const at = range.start - neighbour.nodeSize\n tr.delete(at, range.start)\n tr.insert(range.end - neighbour.nodeSize, neighbour)\n shift = -neighbour.nodeSize\n } else {\n tr.delete(range.end, range.end + neighbour.nodeSize)\n tr.insert(range.start, neighbour)\n shift = neighbour.nodeSize\n }\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n }\n}\n\n/**\n * Drag and drop: move the blocks of `range` to `target`, a position right\n * before or after a block, possibly at another level. Fails when the\n * target is inside the moved blocks. The cursor goes to the first one.\n */\nexport function moveRangeTo(range: SiblingRange, target: number): Command {\n return (state, dispatch) => {\n if (target >= range.start && target <= range.end) return false\n if (dispatch) {\n const nodes = blocksIn(range).map((block) => block.node)\n const tr = state.tr\n // a group may not be empty: take the whole group when every child moves\n const whole =\n range.parent.type.name === 'blockGroup' &&\n range.from === 0 &&\n range.to === range.parent.childCount - 1\n if (whole) tr.delete(range.start - 1, range.end + 1)\n else tr.delete(range.start, range.end)\n const at = tr.mapping.map(target)\n tr.insert(at, nodes)\n tr.setSelection(Selection.near(tr.doc.resolve(at + 2)))\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\n/** Remove blocks, keeping at least one empty paragraph in the document. */\nexport function deleteBlocks(tr: Transaction, blocks: BlockInfo[]): Transaction {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a copy\n const sorted = [...blocks].sort((a, b) => b.pos - a.pos)\n for (const block of sorted) {\n const from = tr.mapping.map(block.pos)\n const to = tr.mapping.map(block.pos + block.node.nodeSize)\n const $from = tr.doc.resolve(from)\n // a group may not be empty: remove the whole group when this was its only block\n if ($from.parent.type.name === 'blockGroup' && $from.parent.childCount === 1)\n tr.delete($from.before(), $from.after())\n else tr.delete(from, to)\n }\n if (tr.doc.childCount === 0 || tr.doc.content.size === 0) {\n tr.insert(0, newBlock(tr.doc.type.schema, tr.doc.type.schema.nodes.paragraph!.create()))\n }\n const near = Math.min(tr.mapping.map(sorted.at(-1)!.pos), tr.doc.content.size)\n tr.setSelection(Selection.near(tr.doc.resolve(near)))\n return tr\n}\n\n/** Copies of blocks with fresh ids (the id plugin assigns them). */\nexport function withoutIds(node: PMNode): PMNode {\n if (node.type.name !== 'block' && node.type.name !== 'blockGroup') return node\n const children: PMNode[] = []\n node.forEach((child) => children.push(withoutIds(child)))\n return node.type.name === 'block'\n ? node.type.create({ ...node.attrs, id: null }, children)\n : node.type.create(node.attrs, children)\n}\n\n/** Insert copies of the selected blocks right after them. */\nexport const duplicateBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n if (dispatch) {\n const copies = blocksIn(range).map((block) => withoutIds(block.node))\n const tr = state.tr.insert(range.end, copies)\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/** Insert an empty block of `type` after the block at `pos` and put the cursor in it. */\nexport function insertBlockAfter(pos: number, type: ContentType = 'paragraph'): Command {\n return (state, dispatch) => {\n const info = blockAround(state.doc.resolve(Math.min(pos + 1, state.doc.content.size)))\n if (!info) return false\n if (dispatch) {\n const at = info.pos + info.node.nodeSize\n const content = createContentNode(state.schema, type)\n const tr = state.tr.insert(at, newBlock(state.schema, content))\n tr.setSelection(Selection.near(tr.doc.resolve(at + 2)))\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\n/** The selection's blocks, for menus and the block selection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CACA,OAAO;AACT;;AAGA,SAAgB,iBAAiB,KAAa,OAAoB,aAAsB;CACtF,QAAQ,OAAO,aAAa;EAC1B,MAAM,OAAO,YAAY,MAAM,IAAI,QAAQ,KAAK,IAAI,MAAM,GAAG,MAAM,IAAI,QAAQ,IAAI,CAAC,CAAC;EACrF,IAAI,CAAC,MAAM,OAAO;EAClB,IAAI,UAAU;GACZ,MAAM,KAAK,KAAK,MAAM,KAAK,KAAK;GAChC,MAAM,UAAU,kBAAkB,MAAM,QAAQ,IAAI;GACpD,MAAM,KAAK,MAAM,GAAG,OAAO,IAAI,SAAS,MAAM,QAAQ,OAAO,CAAC;GAC9D,GAAG,aAAa,UAAU,KAAK,GAAG,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC;GACtD,SAAS,GAAG,eAAe,CAAC;EAC9B;EACA,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"commands.js","names":[],"sources":["../../src/core/commands.ts"],"sourcesContent":["import { Fragment, type Node as PMNode, type ResolvedPos, type Schema } from 'prosemirror-model'\nimport {\n NodeSelection,\n Selection,\n TextSelection,\n type Command,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n infoAt,\n layoutOf,\n nextInDocument,\n parentBlock,\n previousInDocument,\n selectedRange,\n type BlockInfo,\n type SiblingRange,\n} from './blocks'\nimport { createContentNode, nodeFromBlock, type BlockProps, type PartialBlock } from './model'\nimport type { ContentType } from './schema'\n\nconst newBlock = (schema: Schema, content: PMNode, children?: Fragment) =>\n schema.nodes.block!.create(\n { id: null },\n children?.size ? [content, schema.nodes.blockGroup!.create(null, children)] : content,\n )\n\n/** Whether a position is inside a column, at any depth. */\nfunction insideColumn($pos: ResolvedPos): boolean {\n for (let depth = $pos.depth; depth > 0; depth--)\n if (layoutOf($pos.node(depth)) === 'column') return true\n return false\n}\n\n/** The block and content around the cursor, when the selection is inside one textblock. */\nfunction cursorBlock(state: EditorState) {\n const { $from, $to } = state.selection\n if (!$from.parent.isTextblock || !$from.sameParent($to)) return null\n const info = blockAround($from)\n return info && info.content === $from.parent ? info : null\n}\n\n/* turning blocks into another type */\n\n/**\n * Turn every block the selection touches into `type`. Text formatting is\n * dropped when it can't be kept (in a code block); a type without text\n * (a divider, an embed) replaces the content and adds an empty paragraph\n * after it to keep typing in. A type that starts with children of its own\n * (`template` in its spec, e.g. columns) is added after the blocks instead,\n * or takes the place of an empty paragraph; blocks that lay out others\n * (columns) are left as they are.\n */\nexport function setBlockType(type: ContentType, props: BlockProps = {}): Command {\n return (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n const schema = state.schema\n const nodeType = schema.nodes[type]\n if (!nodeType) return false\n // columns don't nest\n if (nodeType.spec.layout === 'row' && insideColumn(state.selection.$from)) return false\n if (!dispatch) return true\n const template = nodeType.spec.template as ((props: BlockProps) => PartialBlock[]) | undefined\n if (template) {\n dispatch(insertTemplate(state.tr, blocksIn(range), type, props, template(props)))\n return true\n }\n const tr = state.tr\n const created = createContentNode(schema, type, props)\n const attrs = created.attrs\n if (!nodeType.isTextblock) {\n const blocks = blocksIn(range)\n const last = blocks.at(-1)!\n // last first, so earlier positions stay valid\n for (let index = blocks.length - 1; index >= 0; index--) {\n const block = blocks[index]!\n if (block.content.type.spec.layout) continue\n tr.replaceWith(block.contentPos, block.contentPos + block.content.nodeSize, created)\n }\n const after = tr.mapping.map(last.pos + last.node.nodeSize)\n tr.insert(after, newBlock(schema, schema.nodes.paragraph!.create()))\n tr.setSelection(TextSelection.create(tr.doc, after + 2))\n dispatch(tr.scrollIntoView())\n return true\n }\n for (const block of blocksIn(range)) {\n const from = tr.mapping.map(block.contentPos)\n const content = tr.doc.nodeAt(from)!\n // a block holding other nodes (a table) or laying out others (columns) can't become text\n if ((!content.isAtom && !content.inlineContent) || content.type.spec.layout) continue\n if (content.isAtom) {\n tr.replaceWith(from, from + content.nodeSize, nodeType.create(attrs))\n } else {\n // only this content node: the block's children keep their type; alignment stays\n const align = content.attrs.align\n const kept = align != null && nodeType.spec.attrs?.align ? { ...attrs, align } : attrs\n tr.setBlockType(from + 1, from + content.nodeSize - 1, nodeType, kept)\n }\n }\n const { from, to } = state.selection\n if (state.selection instanceof TextSelection)\n tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(from), tr.mapping.map(to)))\n dispatch(tr.scrollIntoView())\n return true\n }\n}\n\n/**\n * A new block of `type` with its starting children, after `blocks` (or in\n * place of the one empty paragraph), with the cursor in its first text.\n */\nfunction insertTemplate(\n tr: Transaction,\n blocks: BlockInfo[],\n type: ContentType,\n props: BlockProps,\n children: PartialBlock[],\n): Transaction {\n const schema = tr.doc.type.schema\n const last = blocks.at(-1)!\n const node = nodeFromBlock(schema, { type, props, children })\n const empty =\n blocks.length === 1 &&\n !last.group &&\n last.content.type.name === 'paragraph' &&\n last.content.content.size === 0\n const at = empty ? last.pos : last.pos + last.node.nodeSize\n if (empty) tr.replaceWith(at, at + last.node.nodeSize, node)\n else tr.insert(at, node)\n // the last of its level: an empty paragraph below to go on writing\n const $at = tr.doc.resolve(at)\n if ($at.index() === $at.parent.childCount - 1)\n tr.insert(at + node.nodeSize, newBlock(schema, schema.nodes.paragraph!.create()))\n tr.setSelection(Selection.near(tr.doc.resolve(at + 1)))\n return tr.scrollIntoView()\n}\n\n/** Set attributes on the content of the block at `pos`, e.g. tick a to-do. */\nexport function setContentAttrs(pos: number, attrs: Record<string, unknown>): Command {\n return (state, dispatch) => {\n const info = blockAround(state.doc.resolve(pos + 1))\n if (!info) return false\n if (dispatch) {\n const tr = state.tr.setNodeMarkup(info.contentPos, undefined, {\n ...info.content.attrs,\n ...attrs,\n })\n dispatch(tr)\n }\n return true\n }\n}\n\n/* Enter */\n\n/**\n * Split the block at the cursor. An empty list item turns back into a\n * paragraph, an empty nested paragraph moves up a level, and a block with\n * children gets its new block as the first child.\n */\nexport const splitBlock: Command = (state, dispatch) => {\n const schema = state.schema\n let tr = state.tr\n if (!state.selection.empty) {\n if (!cursorBlockAfterDelete(state)) return false\n tr = tr.deleteSelection()\n }\n const $from = tr.selection.$from\n const info = blockAround($from)\n if (!info || info.content !== $from.parent || !$from.parent.isTextblock) return false\n const content = info.content\n const type = content.type.name\n\n if (content.content.size === 0) {\n if (type !== 'paragraph' && !content.type.spec.code) {\n if (dispatch)\n dispatch(tr.setBlockType($from.pos, $from.pos, schema.nodes.paragraph!).scrollIntoView())\n return true\n }\n // nested: up a level, where there is one (not out of a column)\n if (type === 'paragraph' && info.depth > 1 && liftBlocks(state))\n return liftBlocks(state, dispatch)\n }\n\n if (!dispatch) return true\n const offset = $from.parentOffset\n // lists continue themselves (with their default attributes: a to-do starts unticked)\n const nextType = content.type.spec.continues ? type : 'paragraph'\n const nextAttrs = null\n const contentEnd = info.contentPos + content.nodeSize - 1\n\n // at the very start of a non-empty block: open an empty block above it\n if (offset === 0 && content.content.size > 0) {\n const above = newBlock(schema, schema.nodes[nextType]!.create(nextAttrs))\n tr.insert(info.pos, above)\n dispatch(tr.scrollIntoView())\n return true\n }\n\n const rest = content.content.cut(offset)\n const moved = schema.nodes[nextType]!.create(nextAttrs, rest)\n tr.delete($from.pos, contentEnd)\n const block = newBlock(schema, moved)\n let insertAt: number\n if (info.group) {\n // first child: right below the line the cursor was on\n insertAt = tr.mapping.map(info.contentPos + content.nodeSize) + 1\n } else {\n insertAt = tr.mapping.map(info.pos + info.node.nodeSize)\n }\n tr.insert(insertAt, block)\n tr.setSelection(TextSelection.create(tr.doc, insertAt + 2))\n dispatch(tr.scrollIntoView())\n return true\n}\n\nfunction cursorBlockAfterDelete(state: EditorState) {\n return !!blockAround(state.selection.$from)\n}\n\n/** `Shift+Enter`: a line break, or a newline in code. */\nexport const insertBreak: Command = (state, dispatch) => {\n const { $from } = state.selection\n if (!$from.parent.isTextblock) return false\n if (dispatch) {\n const tr = $from.parent.type.spec.code\n ? state.tr.insertText('\\n')\n : state.tr.replaceSelectionWith(state.schema.nodes.hardBreak!.create())\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/** In a code block, `Enter` adds a newline. */\nexport const newlineInCode: Command = (state, dispatch) => {\n const { $from } = state.selection\n if (!$from.parent.type.spec.code) return false\n if (dispatch) dispatch(state.tr.insertText('\\n').scrollIntoView())\n return true\n}\n\n/** `Mod+Enter` in a code block: leave it for a new paragraph below. */\nexport const exitCode: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n if (!info || !info.content.type.spec.code) return false\n if (dispatch) {\n const at = info.pos + info.node.nodeSize\n const tr = state.tr.insert(at, newBlock(state.schema, state.schema.nodes.paragraph!.create()))\n tr.setSelection(TextSelection.create(tr.doc, at + 2))\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/* Backspace and Delete */\n\n/**\n * Move `source`'s text to the end of `target`'s content and put its\n * children where `source` was.\n */\nfunction mergeInto(tr: Transaction, target: BlockInfo, source: BlockInfo) {\n const joinAt = target.contentPos + target.content.nodeSize - 1\n const children = source.group ? source.group.content : Fragment.empty\n tr.replaceWith(source.pos, source.pos + source.node.nodeSize, children)\n let inline = source.content.content\n if (target.content.type.spec.code) {\n const text = source.content.textContent\n inline = text ? Fragment.from(tr.doc.type.schema.text(text)) : Fragment.empty\n }\n tr.insert(joinAt, inline)\n tr.setSelection(TextSelection.create(tr.doc, joinAt))\n}\n\n/**\n * `Backspace` at the start of a block: first turn it into a paragraph, then\n * move a nested block up a level, then join it with the block above.\n */\nexport const joinBackward: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n if (!info || !state.selection.empty || state.selection.$from.parentOffset > 0) return false\n const type = info.content.type.name\n if (type !== 'paragraph') {\n if (dispatch) {\n const pos = state.selection.from\n dispatch(state.tr.setBlockType(pos, pos, state.schema.nodes.paragraph!))\n }\n return true\n }\n if (info.depth > 1 && liftBlocks(state)) return liftBlocks(state, dispatch)\n const previous = previousInDocument(state.doc, info)\n if (!previous) {\n // the start of a column: text stays in its column; an empty block goes\n // (and its column with it, when it was the only one there)\n if (!insideColumn(state.selection.$from)) return false\n if (dispatch && info.content.content.size === 0 && !info.group) {\n const tr = deleteBlocks(state.tr, [info])\n // the column goes with it: back to the end of the column before, if there is one\n const column = parentBlock(state.doc, info)\n if (column?.group?.childCount === 1 && state.doc.resolve(column.pos).index() > 0)\n tr.setSelection(Selection.near(tr.doc.resolve(tr.mapping.map(column.pos)), -1))\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n if (!dispatch) return true\n const tr = state.tr\n if (previous.content.isAtom) {\n // the block above is a divider: remove it\n tr.delete(previous.pos, previous.pos + previous.node.nodeSize)\n dispatch(tr.scrollIntoView())\n return true\n }\n mergeInto(tr, previous, info)\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/** `Delete` at the end of a block: pull the next block's text up. */\nexport const joinForward: Command = (state, dispatch) => {\n const info = cursorBlock(state)\n const { $from } = state.selection\n if (!info || !state.selection.empty || $from.parentOffset < $from.parent.content.size)\n return false\n const next = nextInDocument(state.doc, info)\n // the end of a column: nothing comes after it there\n if (!next) return insideColumn($from)\n // columns are not pulled into text\n if (layoutOf(next.node)) return true\n if (!dispatch) return true\n const tr = state.tr\n if (next.content.isAtom && !next.group) {\n tr.delete(next.pos, next.pos + next.node.nodeSize)\n } else {\n mergeInto(tr, info, next)\n }\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/** With a divider selected, `Backspace` or `Delete` removes its block. */\nexport const deleteSelectedAtom: Command = (state, dispatch) => {\n const selection = state.selection\n if (!(selection instanceof NodeSelection) || !selection.node.isAtom) return false\n const info = blockAround(selection.$from)\n if (!info) return false\n if (dispatch) dispatch(deleteBlocks(state.tr, [info]).scrollIntoView())\n return true\n}\n\n/* indenting */\n\n/** `Tab`: make the selected blocks children of the block above them. */\nexport const sinkBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range || range.from === 0) return false\n if (!dispatch) return true\n const schema = state.schema\n const blocks = blocksIn(range)\n const previousNode = range.parent.child(range.from - 1)\n // nothing goes into a set of columns but columns\n if (layoutOf(previousNode)) return false\n const previous = infoAt(previousNode, range.start - previousNode.nodeSize, range.depth)\n const moving = Fragment.fromArray(blocks.map((block) => block.node))\n const tr = state.tr\n const { from, to } = state.selection\n tr.delete(range.start, range.end)\n let shift: number\n if (previous.group) {\n const at = previous.pos + previous.node.nodeSize - 2\n tr.insert(at, moving)\n shift = at - range.start\n } else {\n const at = previous.pos + previous.node.nodeSize - 1\n tr.insert(at, schema.nodes.blockGroup!.create(null, moving))\n shift = at + 1 - range.start\n }\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/**\n * `Shift+Tab`: move the selected blocks up a level, right after their\n * parent. The siblings that followed them become children of the last one,\n * so nothing changes order.\n */\nexport const liftBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range || range.depth <= 1) return false\n const doc = state.doc\n const $start = doc.resolve(range.start)\n const parentDepth = range.depth - 2\n // the top level of a column: the blocks stay in it\n if (layoutOf($start.node(parentDepth))) return false\n if (!dispatch) return true\n const schema = state.schema\n const parent = infoAt($start.node(parentDepth), $start.before(parentDepth), parentDepth)\n const group = range.parent\n const blocks = blocksIn(range).map((block) => block.node)\n // siblings after the range go under the last moved block\n const following: PMNode[] = []\n for (let index = range.to + 1; index < group.childCount; index++)\n following.push(group.child(index))\n if (following.length) {\n const last = blocks.pop()!\n const ownGroup = last.childCount > 1 ? last.child(1).content : Fragment.empty\n const children = ownGroup.append(Fragment.fromArray(following))\n blocks.push(\n last.copy(\n Fragment.from(last.firstChild!).addToEnd(schema.nodes.blockGroup!.create(null, children)),\n ),\n )\n }\n const kept: PMNode[] = []\n for (let index = 0; index < range.from; index++) kept.push(group.child(index))\n const parentContent = parent.node.firstChild!\n const newParent = parent.node.copy(\n kept.length\n ? Fragment.from(parentContent).addToEnd(group.copy(Fragment.fromArray(kept)))\n : Fragment.from(parentContent),\n )\n const tr = state.tr\n const { from, to } = state.selection\n tr.replaceWith(parent.pos, parent.pos + parent.node.nodeSize, [newParent, ...blocks])\n // the moved blocks now start right after the rebuilt parent\n const shift = parent.pos + newParent.nodeSize - range.start\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n}\n\nfunction restoreSelection(tr: Transaction, state: EditorState, from: number, to: number) {\n const clamp = (pos: number) => Math.max(0, Math.min(pos, tr.doc.content.size))\n if (state.selection instanceof NodeSelection) {\n const $pos = tr.doc.resolve(clamp(from))\n if ($pos.nodeAfter) {\n tr.setSelection(NodeSelection.create(tr.doc, $pos.pos))\n return\n }\n }\n tr.setSelection(TextSelection.between(tr.doc.resolve(clamp(from)), tr.doc.resolve(clamp(to))))\n}\n\n/* moving, duplicating and removing blocks */\n\n/**\n * `Mod+Shift+↑/↓`: swap the selected blocks with their neighbour. At the\n * top or bottom of a column, the blocks move out of the set of columns,\n * above or below it.\n */\nexport function swapBlocks(direction: -1 | 1): Command {\n return (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n const neighbourIndex = direction < 0 ? range.from - 1 : range.to + 1\n if (neighbourIndex < 0 || neighbourIndex >= range.parent.childCount)\n return leaveColumn(state, range, direction, dispatch)\n if (!dispatch) return true\n const neighbour = range.parent.child(neighbourIndex)\n const tr = state.tr\n const { from, to } = state.selection\n let shift: number\n if (direction < 0) {\n const at = range.start - neighbour.nodeSize\n tr.delete(at, range.start)\n tr.insert(range.end - neighbour.nodeSize, neighbour)\n shift = -neighbour.nodeSize\n } else {\n tr.delete(range.end, range.end + neighbour.nodeSize)\n tr.insert(range.start, neighbour)\n shift = neighbour.nodeSize\n }\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n }\n}\n\n/** The blocks of `range`, at the edge of a column, moved above or below its set of columns. */\nfunction leaveColumn(\n state: EditorState,\n range: SiblingRange,\n direction: -1 | 1,\n dispatch?: (tr: Transaction) => void,\n): boolean {\n if (range.depth < 5) return false\n const $start = state.doc.resolve(range.start)\n const column = $start.node(range.depth - 2)\n const row = $start.node(range.depth - 4)\n if (layoutOf(column) !== 'column' || layoutOf(row) !== 'row') return false\n const rowPos = $start.before(range.depth - 4)\n const target = direction < 0 ? rowPos : rowPos + row.nodeSize\n if (!dispatch) return true\n const { from, to } = state.selection\n const first = state.doc.resolve(range.start).nodeAfter!.attrs.id as string\n let result: Transaction | null = null\n moveRangeTo(range, target)(state, (tr) => (result = tr))\n if (!result) return false\n const tr = result as Transaction\n // the same text selected, now where the blocks went\n const shift = findBlockById(tr.doc, first)!.pos - range.start\n restoreSelection(tr, state, from + shift, to + shift)\n dispatch(tr.scrollIntoView())\n return true\n}\n\n/**\n * Drag and drop: move the blocks of `range` to `target`, a position right\n * before or after a block, possibly at another level. Fails when the\n * target is inside the moved blocks. The cursor goes to the first one.\n */\nexport function moveRangeTo(range: SiblingRange, target: number): Command {\n return (state, dispatch) => {\n if (target >= range.start && target <= range.end) return false\n if (dispatch) {\n const nodes = blocksIn(range).map((block) => block.node)\n const tr = state.tr\n // a group may not be empty: take the whole group when every child moves\n const whole =\n range.parent.type.name === 'blockGroup' &&\n range.from === 0 &&\n range.to === range.parent.childCount - 1\n if (whole) tr.delete(range.start - 1, range.end + 1)\n else tr.delete(range.start, range.end)\n const at = tr.mapping.map(target)\n tr.insert(at, nodes)\n tr.setSelection(Selection.near(tr.doc.resolve(at + 2)))\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\n/**\n * Drag and drop beside a column: move the blocks of `range` into a new\n * column of the row at `rowPos`, before its column `index` (or after the\n * last). The new column is as wide as the others on average. A column the\n * blocks leave empty goes away. Fails when the row is among the moved\n * blocks or already has as many columns as it may (`maxColumns`).\n */\nexport function moveRangeToNewColumn(range: SiblingRange, rowPos: number, index: number): Command {\n return (state, dispatch) => {\n const row = state.doc.nodeAt(rowPos)\n const schema = state.schema\n const columnType = Object.values(schema.nodes).find((type) => type.spec.layout === 'column')\n if (!row || layoutOf(row) !== 'row' || row.childCount < 2 || !columnType) return false\n if (rowPos >= range.start && rowPos < range.end) return false\n const group = row.child(1)\n const start = rowPos + 1 + row.firstChild!.nodeSize + 1\n // a whole column of this row moving: the count stays\n const wholeColumn =\n range.depth >= 3 &&\n range.from === 0 &&\n range.to === range.parent.childCount - 1 &&\n state.doc.resolve(range.start).start(range.depth - 3) === start\n const max = (row.firstChild!.type.spec.maxColumns as number | undefined) ?? Infinity\n if (group.childCount >= max && !wholeColumn) return false\n if (!dispatch) return true\n let at = start\n const widths: number[] = []\n group.forEach((column, _offset, position) => {\n if (position < index) at += column.nodeSize\n widths.push(Number(column.firstChild!.attrs.width) || 1)\n })\n const average =\n Math.round((widths.reduce((sum, width) => sum + width, 0) / widths.length) * 1000) / 1000\n const nodes = blocksIn(range).map((block) => block.node)\n const column = schema.nodes.block!.create({ id: null }, [\n columnType.create(average === 1 ? {} : { width: average }),\n schema.nodes.blockGroup!.create(null, nodes),\n ])\n const tr = state.tr\n const whole =\n range.parent.type.name === 'blockGroup' &&\n range.from === 0 &&\n range.to === range.parent.childCount - 1\n if (whole) tr.delete(range.start - 1, range.end + 1)\n else tr.delete(range.start, range.end)\n const pos = tr.mapping.map(at)\n tr.insert(pos, column)\n tr.setSelection(Selection.near(tr.doc.resolve(pos + 1)))\n dispatch(tr.scrollIntoView())\n return true\n }\n}\n\n/** Remove blocks, keeping at least one empty paragraph in the document. */\nexport function deleteBlocks(tr: Transaction, blocks: BlockInfo[]): Transaction {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a copy\n const sorted = [...blocks].sort((a, b) => b.pos - a.pos)\n for (const block of sorted) {\n const from = tr.mapping.map(block.pos)\n const to = tr.mapping.map(block.pos + block.node.nodeSize)\n const $from = tr.doc.resolve(from)\n // a group may not be empty: remove the whole group when this was its only block\n if ($from.parent.type.name === 'blockGroup' && $from.parent.childCount === 1)\n tr.delete($from.before(), $from.after())\n else tr.delete(from, to)\n }\n if (tr.doc.childCount === 0 || tr.doc.content.size === 0) {\n tr.insert(0, newBlock(tr.doc.type.schema, tr.doc.type.schema.nodes.paragraph!.create()))\n }\n const near = Math.min(tr.mapping.map(sorted.at(-1)!.pos), tr.doc.content.size)\n tr.setSelection(Selection.near(tr.doc.resolve(near)))\n return tr\n}\n\n/** Copies of blocks with fresh ids (the id plugin assigns them). */\nexport function withoutIds(node: PMNode): PMNode {\n if (node.type.name !== 'block' && node.type.name !== 'blockGroup') return node\n const children: PMNode[] = []\n node.forEach((child) => children.push(withoutIds(child)))\n return node.type.name === 'block'\n ? node.type.create({ ...node.attrs, id: null }, children)\n : node.type.create(node.attrs, children)\n}\n\n/** Insert copies of the selected blocks right after them. */\nexport const duplicateBlocks: Command = (state, dispatch) => {\n const range = selectedRange(state)\n if (!range) return false\n if (dispatch) {\n const copies = blocksIn(range).map((block) => withoutIds(block.node))\n const tr = state.tr.insert(range.end, copies)\n dispatch(tr.scrollIntoView())\n }\n return true\n}\n\n/** Insert an empty block of `type` after the block at `pos` and put the cursor in it. */\nexport function insertBlockAfter(pos: number, type: ContentType = 'paragraph'): Command {\n return (state, dispatch) => {\n const info = blockAround(state.doc.resolve(Math.min(pos + 1, state.doc.content.size)))\n if (!info) return false\n if (dispatch) {\n const at = info.pos + info.node.nodeSize\n const content = createContentNode(state.schema, type)\n const tr = state.tr.insert(at, newBlock(state.schema, content))\n tr.setSelection(Selection.near(tr.doc.resolve(at + 2)))\n dispatch(tr.scrollIntoView())\n }\n return true\n }\n}\n\n/** The selection's blocks, for menus and the block selection. */\nexport function selectedBlocks(state: EditorState): BlockInfo[] {\n const range = selectedRange(state)\n return range ? blocksIn(range) : []\n}\n"],"mappings":";;;;;AAyBA,IAAM,YAAY,QAAgB,SAAiB,aACjD,OAAO,MAAM,MAAO,OAClB,EAAE,IAAI,KAAK,GACX,UAAU,OAAO,CAAC,SAAS,OAAO,MAAM,WAAY,OAAO,MAAM,QAAQ,CAAC,IAAI,OAChF;;AAGF,SAAS,aAAa,MAA4B;CAChD,KAAK,IAAI,QAAQ,KAAK,OAAO,QAAQ,GAAG,SACtC,IAAI,SAAS,KAAK,KAAK,KAAK,CAAC,MAAM,U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;CAAK,GAAG,QAAQ,IACtD,KAAK,KAAK,OAAO,KAAK,OAAO,QAAQ;AAC3C;;AAGA,IAAa,mBAA4B,OAAO,aAAa;CAC3D,MAAM,QAAQ,cAAc,KAAK;CACjC,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,UAAU;EACZ,MAAM,SAAS,SAAS,KAAK,CAAC,CAAC,KAAK,UAAU,WAAW,MAAM,IAAI,CAAC;EAEpE,SADW,MAAM,GAAG,OAAO,MAAM,KAAK,MAC7B,CAAA,CAAG,eAAe,CAAC;CAC9B;CACA,OAAO;AACT;;AAGA,SAAgB,iBAAiB,KAAa,OAAoB,aAAsB;CACtF,QAAQ,OAAO,aAAa;EAC1B,MAAM,OAAO,YAAY,MAAM,IAAI,QAAQ,KAAK,IAAI,MAAM,GAAG,MAAM,IAAI,QAAQ,IAAI,CAAC,CAAC;EACrF,IAAI,CAAC,MAAM,OAAO;EAClB,IAAI,UAAU;GACZ,MAAM,KAAK,KAAK,MAAM,KAAK,KAAK;GAChC,MAAM,UAAU,kBAAkB,MAAM,QAAQ,IAAI;GACpD,MAAM,KAAK,MAAM,GAAG,OAAO,IAAI,SAAS,MAAM,QAAQ,OAAO,CAAC;GAC9D,GAAG,aAAa,UAAU,KAAK,GAAG,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC;GACtD,SAAS,GAAG,eAAe,CAAC;EAC9B;EACA,OAAO;CACT;AACF"}
|
package/dist/core/extension.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { editorLocales } from "../locale.js";
|
|
1
2
|
import { createSchema } from "./schema.js";
|
|
2
3
|
import { parseHotkey } from "dou-ui";
|
|
3
4
|
// src/core/extension.ts
|
|
@@ -46,7 +47,7 @@ function merge(target, source, what, owner) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
/** Sort the extensions by priority, build the schema and collect what they add. */
|
|
49
|
-
function resolveEditorExtensions(list) {
|
|
50
|
+
function resolveEditorExtensions(list, messages = () => editorLocales["zh-CN"]) {
|
|
50
51
|
const extensions = flatten(list).map((extension, index) => ({
|
|
51
52
|
extension,
|
|
52
53
|
index
|
|
@@ -70,7 +71,10 @@ function resolveEditorExtensions(list) {
|
|
|
70
71
|
inlines,
|
|
71
72
|
marks
|
|
72
73
|
});
|
|
73
|
-
const context = {
|
|
74
|
+
const context = {
|
|
75
|
+
schema,
|
|
76
|
+
messages
|
|
77
|
+
};
|
|
74
78
|
const providers = extensions.filter((extension) => extension.history);
|
|
75
79
|
if (providers.length > 1) throw new Error("[@dou-ui/editor] only one extension may replace the undo history");
|
|
76
80
|
const keepers = extensions.filter((extension) => extension.comments);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","names":[],"sources":["../../src/core/extension.ts"],"sourcesContent":["import type { InputRule } from 'prosemirror-inputrules'\nimport type { MarkSpec, NodeSpec, Schema } from 'prosemirror-model'\nimport type { Command, Plugin } from 'prosemirror-state'\nimport type { NodeViewConstructor } from 'prosemirror-view'\nimport { parseHotkey, type CommentAction, type CommentThread } from 'dou-ui'\nimport type { Component, Ref } from 'vue'\nimport type { EditorMessages } from '../locale'\nimport type { BlockProps } from './model'\nimport type { EditorExtensionOutput } from './output'\nimport { createSchema } from './schema'\n\n/** Text shown in a menu: fixed, or read from the editor's messages so it follows the locale. */\nexport type Label = string | ((messages: EditorMessages) => string)\n\nexport const labelOf = (label: Label | undefined, messages: EditorMessages) =>\n typeof label === 'function' ? label(messages) : (label ?? '')\n\n/** An entry of the slash menu and of the “turn into” menus. */\nexport interface BlockOption {\n /** Unique among the options. */\n key: string\n /** The block type it inserts or turns blocks into. */\n type: string\n props?: BlockProps\n label: Label\n /** A short description under the label in the slash menu. */\n hint?: Label\n icon: Component\n /** Extra words the slash menu matches, besides the label (pinyin works well). */\n keywords?: string[]\n /** The Markdown shortcut, shown as a hint. */\n shortcut?: string\n}\n\n/** A toggle in the formatting toolbar for a mark. */\nexport interface FormatOption {\n mark: string\n label: Label\n icon: Component\n /** The shortcut shown in its tooltip, written as in `useHotkey`, e.g. `mod+b`. */\n hotkey?: string\n}\n\n/** Where the comment threads live, when not in `v-model:comments`. */\nexport interface CommentsProvider {\n /** The threads, kept up to date. */\n threads: Readonly<Ref<readonly CommentThread[]>>\n /** Make a change this user asked for. */\n apply: (action: CommentAction) => void\n}\n\nexport interface EditorExtensionContext {\n schema: Schema\n}\n\n/** What the extension replacing the undo history provides (e.g. collaboration). */\nexport interface HistoryProvider {\n plugins: Plugin[]\n undo: Command\n redo: Command\n}\n\n/**\n * A piece of the editor: block types, marks, behaviour and menu entries.\n * The built-in blocks are extensions too (see `editorKit`).\n */\nexport interface EditorExtension {\n name: string\n /** Higher runs first: its keys, input rules and plugins win. Defaults to 100. */\n priority?: number\n /**\n * Content node specs for new block types, by type name. They join the\n * `blockContent` group. Extra spec fields the editor reads:\n * `continues` (Enter continues the same type, like a list) and\n * `component` (a Vue component that renders the block).\n */\n blocks?: Record<string, NodeSpec>\n /**\n * Nodes that only live inside the extension's blocks, e.g. a table's\n * rows and cells. They join no group.\n */\n nodes?: Record<string, NodeSpec>\n /** Inline nodes, e.g. a mention. */\n inlines?: Record<string, NodeSpec>\n marks?: Record<string, MarkSpec>\n nodeViews?: Record<string, NodeViewConstructor>\n /**\n * Node views that draw Vue components, by node type. Each is made with\n * `mount`, which renders a component into an element inside the editor's\n * app, so it can call `useEditor()` and follows the ConfigProvider.\n */\n componentViews?: Record<string, (mount: MountComponent) => NodeViewConstructor>\n inputRules?: (context: EditorExtensionContext) => InputRule[]\n /**\n * Keys, written as in `useHotkey` (e.g. `mod+shift+h`, `shift+tab`,\n * `enter`), while the editor has focus. A command returning `false` lets\n * the key through to the next extension.\n */\n keymap?: (context: EditorExtensionContext) => Record<string, Command>\n plugins?: (context: EditorExtensionContext) => Plugin[]\n /**\n * The document lives outside the editor (e.g. in a Yjs document): the\n * initial `modelValue` and later outside changes to it are ignored, and\n * `v-model` only mirrors the document.\n */\n externalDocument?: boolean\n /** Replace the built-in undo history. Only one extension may. */\n history?: (context: EditorExtensionContext) => HistoryProvider\n /**\n * Keep the comment threads somewhere else than `v-model:comments`, e.g.\n * in a shared document. `v-model:comments` then only mirrors them.\n * Only one extension may.\n */\n comments?: (context: EditorExtensionContext) => CommentsProvider\n /** Entries for the slash menu and the “turn into” menus. */\n blockOptions?: BlockOption[]\n /** Toggles for the formatting toolbar. */\n formats?: FormatOption[]\n /**\n * Components rendered next to the editing area while it is editable,\n * e.g. a popup of suggestions. They can call `useEditor()`.\n */\n overlays?: Component[]\n /**\n * Controls added to the formatting toolbar, after the marks (e.g. a\n * color menu). They can call `useEditor()`.\n */\n toolbar?: Component[]\n /**\n * Entries added to the block menu of the handle, usually a\n * `DouDropdownSub` or `DouDropdownItem`s. Each gets the block the menu is\n * for as the `block` prop (a `Block`) and can call `useEditor()`.\n */\n blockMenu?: Component[]\n /**\n * How the extension's blocks, inline nodes and marks are written as HTML\n * and Markdown (`blocksToHTML`, `blocksToMarkdown`).\n */\n output?: EditorExtensionOutput\n /**\n * Rewrite HTML before it is read as blocks (when pasting, and in\n * `htmlToBlocks` and `markdownToBlocks`), e.g. turn a `<details>`\n * element into a toggle with its children. `blockElement` and\n * `splitContainer` help build the editor's markup.\n */\n prepareHTML?: (root: HTMLElement) => void\n}\n\n/**\n * Renders `component` into `element` with `props` (a reactive object stays\n * live), inside the editor's app. Returns a function that removes it.\n */\nexport type MountComponent = (\n component: Component,\n props: Record<string, unknown>,\n element: HTMLElement,\n) => () => void\n\n/** Declare an extension; only gives it a type. */\nexport function defineEditorExtension(extension: EditorExtension): EditorExtension {\n return extension\n}\n\n/** Everything the extensions contribute, gathered once per list of extensions. */\nexport interface ResolvedEditorExtensions {\n extensions: EditorExtension[]\n schema: Schema\n context: EditorExtensionContext\n nodeViews: Record<string, NodeViewConstructor>\n componentViews: Record<string, (mount: MountComponent) => NodeViewConstructor>\n blockOptions: BlockOption[]\n formats: FormatOption[]\n overlays: Component[]\n toolbar: Component[]\n blockMenu: Component[]\n inputRules: InputRule[]\n keymaps: Record<string, Command>[]\n plugins: Plugin[]\n history: HistoryProvider | null\n comments: CommentsProvider | null\n externalDocument: boolean\n}\n\nconst PM_KEYS: Record<string, string> = {\n ' ': 'Space',\n arrowup: 'ArrowUp',\n arrowdown: 'ArrowDown',\n arrowleft: 'ArrowLeft',\n arrowright: 'ArrowRight',\n pageup: 'PageUp',\n pagedown: 'PageDown',\n}\nconst PM_MODIFIERS: Record<string, string> = {\n mod: 'Mod',\n ctrl: 'Ctrl',\n alt: 'Alt',\n meta: 'Meta',\n shift: 'Shift',\n}\n\n/** `mod+shift+h` → `Mod-Shift-h`, the way the ProseMirror keymap names keys. */\nexport function toEditorKey(hotkey: string): string {\n const steps = parseHotkey(hotkey)\n if (steps.length !== 1)\n throw new Error(`[@dou-ui/editor] key sequences aren't supported in a keymap: \"${hotkey}\"`)\n const keys = steps[0]!\n const modifiers = Object.keys(PM_MODIFIERS)\n .filter((name) => keys.includes(name))\n .map((name) => PM_MODIFIERS[name])\n const key = keys.find((name) => !(name in PM_MODIFIERS)) ?? ''\n const name = PM_KEYS[key] ?? (key.length > 1 ? key[0]!.toUpperCase() + key.slice(1) : key)\n return [...modifiers, name].join('-')\n}\n\nconst toEditorKeymap = (bindings: Record<string, Command>) =>\n Object.fromEntries(Object.entries(bindings).map(([key, command]) => [toEditorKey(key), command]))\n\nfunction flatten(list: readonly (EditorExtension | EditorExtension[])[]): EditorExtension[] {\n const result: EditorExtension[] = []\n for (const item of list) {\n if (Array.isArray(item)) result.push(...flatten(item))\n else result.push(item)\n }\n return result\n}\n\nfunction merge<T>(\n target: Record<string, T>,\n source: Record<string, T> | undefined,\n what: string,\n owner: string,\n) {\n for (const [name, value] of Object.entries(source ?? {})) {\n if (name in target)\n throw new Error(`[@dou-ui/editor] ${what} \"${name}\" from \"${owner}\" is already defined`)\n target[name] = value\n }\n}\n\n/** Sort the extensions by priority, build the schema and collect what they add. */\nexport function resolveEditorExtensions(\n list: readonly (EditorExtension | EditorExtension[])[],\n): ResolvedEditorExtensions {\n const extensions = flatten(list)\n .map((extension, index) => ({ extension, index }))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh array\n .sort(\n (a, b) => (b.extension.priority ?? 100) - (a.extension.priority ?? 100) || a.index - b.index,\n )\n .map((entry) => entry.extension)\n\n const names = new Set<string>()\n const blocks: Record<string, NodeSpec> = {}\n const nodes: Record<string, NodeSpec> = {}\n const inlines: Record<string, NodeSpec> = {}\n const marks: Record<string, MarkSpec> = {}\n for (const extension of extensions) {\n if (names.has(extension.name))\n throw new Error(`[@dou-ui/editor] the extension \"${extension.name}\" is added twice`)\n names.add(extension.name)\n merge(blocks, extension.blocks, 'block type', extension.name)\n merge(nodes, extension.nodes, 'node', extension.name)\n merge(inlines, extension.inlines, 'inline node', extension.name)\n merge(marks, extension.marks, 'mark', extension.name)\n }\n const schema = createSchema({ blocks, nodes, inlines, marks })\n const context: EditorExtensionContext = { schema }\n\n const providers = extensions.filter((extension) => extension.history)\n if (providers.length > 1)\n throw new Error('[@dou-ui/editor] only one extension may replace the undo history')\n\n const keepers = extensions.filter((extension) => extension.comments)\n if (keepers.length > 1)\n throw new Error('[@dou-ui/editor] only one extension may keep the comment threads')\n\n return {\n extensions,\n schema,\n context,\n nodeViews: Object.assign({}, ...extensions.map((extension) => extension.nodeViews ?? {})),\n componentViews: Object.assign(\n {},\n ...extensions.map((extension) => extension.componentViews ?? {}),\n ),\n blockOptions: extensions.flatMap((extension) => extension.blockOptions ?? []),\n formats: extensions.flatMap((extension) => extension.formats ?? []),\n overlays: extensions.flatMap((extension) => extension.overlays ?? []),\n toolbar: extensions.flatMap((extension) => extension.toolbar ?? []),\n blockMenu: extensions.flatMap((extension) => extension.blockMenu ?? []),\n inputRules: extensions.flatMap((extension) => extension.inputRules?.(context) ?? []),\n keymaps: extensions.flatMap((extension) =>\n extension.keymap ? [toEditorKeymap(extension.keymap(context))] : [],\n ),\n plugins: extensions.flatMap((extension) => extension.plugins?.(context) ?? []),\n history: providers[0]?.history?.(context) ?? null,\n comments: keepers[0]?.comments?.(context) ?? null,\n externalDocument: extensions.some((extension) => extension.externalDocument),\n }\n}\n"],"mappings":";;;AAcA,IAAa,WAAW,OAA0B,aAChD,OAAO,UAAU,aAAa,MAAM,QAAQ,IAAK,SAAS;;AAgJ5D,SAAgB,sBAAsB,WAA6C;CACjF,OAAO;AACT;AAsBA,IAAM,UAAkC;CACtC,KAAK;CACL,SAAS;CACT,WAAW;CACX,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,UAAU;AACZ;AACA,IAAM,eAAuC;CAC3C,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,OAAO;AACT;;AAGA,SAAgB,YAAY,QAAwB;CAClD,MAAM,QAAQ,YAAY,MAAM;CAChC,IAAI,MAAM,WAAW,GACnB,MAAM,IAAI,MAAM,iEAAiE,OAAO,EAAE;CAC5F,MAAM,OAAO,MAAM;CACnB,MAAM,YAAY,OAAO,KAAK,YAAY,CAAC,CACxC,QAAQ,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,CACrC,KAAK,SAAS,aAAa,KAAK;CACnC,MAAM,MAAM,KAAK,MAAM,SAAS,EAAE,QAAQ,aAAa,KAAK;CAC5D,MAAM,OAAO,QAAQ,SAAS,IAAI,SAAS,IAAI,IAAI,EAAE,CAAE,YAAY,IAAI,IAAI,MAAM,CAAC,IAAI;CACtF,OAAO,CAAC,GAAG,WAAW,IAAI,CAAC,CAAC,KAAK,GAAG;AACtC;AAEA,IAAM,kBAAkB,aACtB,OAAO,YAAY,OAAO,QAAQ,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,aAAa,CAAC,YAAY,GAAG,GAAG,OAAO,CAAC,CAAC;AAElG,SAAS,QAAQ,MAA2E;CAC1F,MAAM,SAA4B,CAAC;CACnC,KAAK,MAAM,QAAQ,MACjB,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,GAAG,QAAQ,IAAI,CAAC;MAChD,O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WAAW,QAAQ,cAAc,UAAU,QAAQ;CACnE,IAAI,QAAQ,SAAS,GACnB,MAAM,IAAI,MAAM,kEAAkE;CAEpF,OAAO;EACL;EACA;EACA;EACA,WAAW,OAAO,OAAO,CAAC,GAAG,GAAG,WAAW,KAAK,cAAc,UAAU,aAAa,CAAC,CAAC,CAAC;EACxF,gBAAgB,OAAO,OACrB,CAAC,GACD,GAAG,WAAW,KAAK,cAAc,UAAU,kBAAkB,CAAC,CAAC,CACjE;EACA,cAAc,WAAW,SAAS,cAAc,UAAU,gBAAgB,CAAC,CAAC;EAC5E,SAAS,WAAW,SAAS,cAAc,UAAU,WAAW,CAAC,CAAC;EAClE,UAAU,WAAW,SAAS,cAAc,UAAU,YAAY,CAAC,CAAC;EACpE,SAAS,WAAW,SAAS,cAAc,UAAU,WAAW,CAAC,CAAC;EAClE,WAAW,WAAW,SAAS,cAAc,UAAU,aAAa,CAAC,CAAC;EACtE,YAAY,WAAW,SAAS,cAAc,UAAU,aAAa,OAAO,KAAK,CAAC,CAAC;EACnF,SAAS,WAAW,SAAS,cAC3B,UAAU,SAAS,CAAC,eAAe,UAAU,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CACpE;EACA,SAAS,WAAW,SAAS,cAAc,UAAU,UAAU,OAAO,KAAK,CAAC,CAAC;EAC7E,SAAS,UAAU,EAAE,EAAE,UAAU,OAAO,KAAK;EAC7C,UAAU,QAAQ,EAAE,EAAE,WAAW,OAAO,KAAK;EAC7C,kBAAkB,WAAW,MAAM,cAAc,UAAU,gBAAgB;CAC7E;AACF"}
|
|
1
|
+
{"version":3,"file":"extension.js","names":[],"sources":["../../src/core/extension.ts"],"sourcesContent":["import type { InputRule } from 'prosemirror-inputrules'\nimport type { MarkSpec, NodeSpec, Schema } from 'prosemirror-model'\nimport type { Command, Plugin } from 'prosemirror-state'\nimport type { NodeViewConstructor } from 'prosemirror-view'\nimport { parseHotkey, type CommentAction, type CommentThread } from 'dou-ui'\nimport type { Component, Ref } from 'vue'\nimport { editorLocales, type EditorMessages } from '../locale'\nimport type { BlockProps } from './model'\nimport type { EditorExtensionOutput } from './output'\nimport { createSchema } from './schema'\n\n/** Text shown in a menu: fixed, or read from the editor's messages so it follows the locale. */\nexport type Label = string | ((messages: EditorMessages) => string)\n\nexport const labelOf = (label: Label | undefined, messages: EditorMessages) =>\n typeof label === 'function' ? label(messages) : (label ?? '')\n\n/** An entry of the slash menu and of the “turn into” menus. */\nexport interface BlockOption {\n /** Unique among the options. */\n key: string\n /** The block type it inserts or turns blocks into. */\n type: string\n props?: BlockProps\n label: Label\n /** A short description under the label in the slash menu. */\n hint?: Label\n icon: Component\n /** Extra words the slash menu matches, besides the label (pinyin works well). */\n keywords?: string[]\n /** The Markdown shortcut, shown as a hint. */\n shortcut?: string\n /**\n * Variants to pick from in a panel beside the option in the slash menu,\n * e.g. how many columns. Choosing the option itself inserts the first.\n */\n choices?: BlockOptionChoices\n}\n\n/** One variant of a slash menu option. */\nexport interface BlockOptionChoice {\n /** The props it inserts with, over the option's own. */\n props: BlockProps\n /** Its name, also read out by screen readers. */\n label: Label\n}\n\n/** The variants of a slash menu option, picked in a panel beside it. */\nexport interface BlockOptionChoices {\n /** The panel's title, e.g. “Number of columns”; also the name screen readers give the panel. */\n title: Label\n items: BlockOptionChoice[]\n /**\n * Draws the variants (the panel around them and its title are drawn by\n * the menu). It gets the props in `BlockOptionChoicesProps` and emits\n * `hover` and `choose` with an index, as in `BlockOptionChoicesEmits`.\n * Without it, the panel lists their names.\n */\n component?: Component<BlockOptionChoicesProps>\n}\n\n/** What the `component` of `BlockOptionChoices` gets. */\nexport interface BlockOptionChoicesProps {\n items: BlockOptionChoice[]\n /** The index of the highlighted variant; -1 while the option itself is highlighted. */\n active: number\n messages: EditorMessages\n /**\n * For screen readers: give the element of variant `index` the id\n * `${idPrefix}-${index}` and `role=\"option\"` (with `aria-selected`), so\n * the editor can point at the highlighted one.\n */\n idPrefix: string\n}\n\n/** What the `component` of `BlockOptionChoices` emits. */\nexport interface BlockOptionChoicesEmits {\n /** The pointer is on variant `index`. */\n hover: [index: number]\n /** Variant `index` is picked: the menu inserts it. */\n choose: [index: number]\n}\n\n/** A toggle in the formatting toolbar for a mark. */\nexport interface FormatOption {\n mark: string\n label: Label\n icon: Component\n /** The shortcut shown in its tooltip, written as in `useHotkey`, e.g. `mod+b`. */\n hotkey?: string\n}\n\n/** Where the comment threads live, when not in `v-model:comments`. */\nexport interface CommentsProvider {\n /** The threads, kept up to date. */\n threads: Readonly<Ref<readonly CommentThread[]>>\n /** Make a change this user asked for. */\n apply: (action: CommentAction) => void\n}\n\nexport interface EditorExtensionContext {\n schema: Schema\n /**\n * The editor's messages, in its current locale, for text a plugin puts\n * in the document's markup (e.g. a name for screen readers). Outside an\n * editor (converting documents) the Chinese ones.\n */\n messages: () => EditorMessages\n}\n\n/** What the extension replacing the undo history provides (e.g. collaboration). */\nexport interface HistoryProvider {\n plugins: Plugin[]\n undo: Command\n redo: Command\n}\n\n/**\n * A piece of the editor: block types, marks, behaviour and menu entries.\n * The built-in blocks are extensions too (see `editorKit`).\n */\nexport interface EditorExtension {\n name: string\n /** Higher runs first: its keys, input rules and plugins win. Defaults to 100. */\n priority?: number\n /**\n * Content node specs for new block types, by type name. They join the\n * `blockContent` group. Extra spec fields the editor reads:\n * `continues` (Enter continues the same type, like a list) and\n * `component` (a Vue component that renders the block).\n */\n blocks?: Record<string, NodeSpec>\n /**\n * Nodes that only live inside the extension's blocks, e.g. a table's\n * rows and cells. They join no group.\n */\n nodes?: Record<string, NodeSpec>\n /** Inline nodes, e.g. a mention. */\n inlines?: Record<string, NodeSpec>\n marks?: Record<string, MarkSpec>\n nodeViews?: Record<string, NodeViewConstructor>\n /**\n * Node views that draw Vue components, by node type. Each is made with\n * `mount`, which renders a component into an element inside the editor's\n * app, so it can call `useEditor()` and follows the ConfigProvider.\n */\n componentViews?: Record<string, (mount: MountComponent) => NodeViewConstructor>\n inputRules?: (context: EditorExtensionContext) => InputRule[]\n /**\n * Keys, written as in `useHotkey` (e.g. `mod+shift+h`, `shift+tab`,\n * `enter`), while the editor has focus. A command returning `false` lets\n * the key through to the next extension.\n */\n keymap?: (context: EditorExtensionContext) => Record<string, Command>\n plugins?: (context: EditorExtensionContext) => Plugin[]\n /**\n * The document lives outside the editor (e.g. in a Yjs document): the\n * initial `modelValue` and later outside changes to it are ignored, and\n * `v-model` only mirrors the document.\n */\n externalDocument?: boolean\n /** Replace the built-in undo history. Only one extension may. */\n history?: (context: EditorExtensionContext) => HistoryProvider\n /**\n * Keep the comment threads somewhere else than `v-model:comments`, e.g.\n * in a shared document. `v-model:comments` then only mirrors them.\n * Only one extension may.\n */\n comments?: (context: EditorExtensionContext) => CommentsProvider\n /** Entries for the slash menu and the “turn into” menus. */\n blockOptions?: BlockOption[]\n /** Toggles for the formatting toolbar. */\n formats?: FormatOption[]\n /**\n * Components rendered next to the editing area while it is editable,\n * e.g. a popup of suggestions. They can call `useEditor()`.\n */\n overlays?: Component[]\n /**\n * Controls added to the formatting toolbar, after the marks (e.g. a\n * color menu). They can call `useEditor()`.\n */\n toolbar?: Component[]\n /**\n * Entries added to the block menu of the handle, usually a\n * `DouDropdownSub` or `DouDropdownItem`s. Each gets the block the menu is\n * for as the `block` prop (a `Block`) and can call `useEditor()`.\n */\n blockMenu?: Component[]\n /**\n * How the extension's blocks, inline nodes and marks are written as HTML\n * and Markdown (`blocksToHTML`, `blocksToMarkdown`).\n */\n output?: EditorExtensionOutput\n /**\n * Rewrite HTML before it is read as blocks (when pasting, and in\n * `htmlToBlocks` and `markdownToBlocks`), e.g. turn a `<details>`\n * element into a toggle with its children. `blockElement` and\n * `splitContainer` help build the editor's markup.\n */\n prepareHTML?: (root: HTMLElement) => void\n}\n\n/**\n * Renders `component` into `element` with `props` (a reactive object stays\n * live), inside the editor's app. Returns a function that removes it.\n */\nexport type MountComponent = (\n component: Component,\n props: Record<string, unknown>,\n element: HTMLElement,\n) => () => void\n\n/** Declare an extension; only gives it a type. */\nexport function defineEditorExtension(extension: EditorExtension): EditorExtension {\n return extension\n}\n\n/** Everything the extensions contribute, gathered once per list of extensions. */\nexport interface ResolvedEditorExtensions {\n extensions: EditorExtension[]\n schema: Schema\n context: EditorExtensionContext\n nodeViews: Record<string, NodeViewConstructor>\n componentViews: Record<string, (mount: MountComponent) => NodeViewConstructor>\n blockOptions: BlockOption[]\n formats: FormatOption[]\n overlays: Component[]\n toolbar: Component[]\n blockMenu: Component[]\n inputRules: InputRule[]\n keymaps: Record<string, Command>[]\n plugins: Plugin[]\n history: HistoryProvider | null\n comments: CommentsProvider | null\n externalDocument: boolean\n}\n\nconst PM_KEYS: Record<string, string> = {\n ' ': 'Space',\n arrowup: 'ArrowUp',\n arrowdown: 'ArrowDown',\n arrowleft: 'ArrowLeft',\n arrowright: 'ArrowRight',\n pageup: 'PageUp',\n pagedown: 'PageDown',\n}\nconst PM_MODIFIERS: Record<string, string> = {\n mod: 'Mod',\n ctrl: 'Ctrl',\n alt: 'Alt',\n meta: 'Meta',\n shift: 'Shift',\n}\n\n/** `mod+shift+h` → `Mod-Shift-h`, the way the ProseMirror keymap names keys. */\nexport function toEditorKey(hotkey: string): string {\n const steps = parseHotkey(hotkey)\n if (steps.length !== 1)\n throw new Error(`[@dou-ui/editor] key sequences aren't supported in a keymap: \"${hotkey}\"`)\n const keys = steps[0]!\n const modifiers = Object.keys(PM_MODIFIERS)\n .filter((name) => keys.includes(name))\n .map((name) => PM_MODIFIERS[name])\n const key = keys.find((name) => !(name in PM_MODIFIERS)) ?? ''\n const name = PM_KEYS[key] ?? (key.length > 1 ? key[0]!.toUpperCase() + key.slice(1) : key)\n return [...modifiers, name].join('-')\n}\n\nconst toEditorKeymap = (bindings: Record<string, Command>) =>\n Object.fromEntries(Object.entries(bindings).map(([key, command]) => [toEditorKey(key), command]))\n\nfunction flatten(list: readonly (EditorExtension | EditorExtension[])[]): EditorExtension[] {\n const result: EditorExtension[] = []\n for (const item of list) {\n if (Array.isArray(item)) result.push(...flatten(item))\n else result.push(item)\n }\n return result\n}\n\nfunction merge<T>(\n target: Record<string, T>,\n source: Record<string, T> | undefined,\n what: string,\n owner: string,\n) {\n for (const [name, value] of Object.entries(source ?? {})) {\n if (name in target)\n throw new Error(`[@dou-ui/editor] ${what} \"${name}\" from \"${owner}\" is already defined`)\n target[name] = value\n }\n}\n\n/** Sort the extensions by priority, build the schema and collect what they add. */\nexport function resolveEditorExtensions(\n list: readonly (EditorExtension | EditorExtension[])[],\n messages: () => EditorMessages = () => editorLocales['zh-CN']!,\n): ResolvedEditorExtensions {\n const extensions = flatten(list)\n .map((extension, index) => ({ extension, index }))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh array\n .sort(\n (a, b) => (b.extension.priority ?? 100) - (a.extension.priority ?? 100) || a.index - b.index,\n )\n .map((entry) => entry.extension)\n\n const names = new Set<string>()\n const blocks: Record<string, NodeSpec> = {}\n const nodes: Record<string, NodeSpec> = {}\n const inlines: Record<string, NodeSpec> = {}\n const marks: Record<string, MarkSpec> = {}\n for (const extension of extensions) {\n if (names.has(extension.name))\n throw new Error(`[@dou-ui/editor] the extension \"${extension.name}\" is added twice`)\n names.add(extension.name)\n merge(blocks, extension.blocks, 'block type', extension.name)\n merge(nodes, extension.nodes, 'node', extension.name)\n merge(inlines, extension.inlines, 'inline node', extension.name)\n merge(marks, extension.marks, 'mark', extension.name)\n }\n const schema = createSchema({ blocks, nodes, inlines, marks })\n const context: EditorExtensionContext = { schema, messages }\n\n const providers = extensions.filter((extension) => extension.history)\n if (providers.length > 1)\n throw new Error('[@dou-ui/editor] only one extension may replace the undo history')\n\n const keepers = extensions.filter((extension) => extension.comments)\n if (keepers.length > 1)\n throw new Error('[@dou-ui/editor] only one extension may keep the comment threads')\n\n return {\n extensions,\n schema,\n context,\n nodeViews: Object.assign({}, ...extensions.map((extension) => extension.nodeViews ?? {})),\n componentViews: Object.assign(\n {},\n ...extensions.map((extension) => extension.componentViews ?? {}),\n ),\n blockOptions: extensions.flatMap((extension) => extension.blockOptions ?? []),\n formats: extensions.flatMap((extension) => extension.formats ?? []),\n overlays: extensions.flatMap((extension) => extension.overlays ?? []),\n toolbar: extensions.flatMap((extension) => extension.toolbar ?? []),\n blockMenu: extensions.flatMap((extension) => extension.blockMenu ?? []),\n inputRules: extensions.flatMap((extension) => extension.inputRules?.(context) ?? []),\n keymaps: extensions.flatMap((extension) =>\n extension.keymap ? [toEditorKeymap(extension.keymap(context))] : [],\n ),\n plugins: extensions.flatMap((extension) => extension.plugins?.(context) ?? []),\n history: providers[0]?.history?.(context) ?? null,\n comments: keepers[0]?.comments?.(context) ?? null,\n externalDocument: extensions.some((extension) => extension.externalDocument),\n }\n}\n"],"mappings":";;;;AAcA,IAAa,WAAW,OAA0B,aAChD,OAAO,UAAU,aAAa,MAAM,QAAQ,IAAK,SAAS;;AAuM5D,SAAgB,sBAAsB,WAA6C;CACjF,OAAO;AACT;AAsBA,IAAM,UAAkC;CACtC,KAAK;CACL,SAAS;CACT,WAAW;CACX,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,UAAU;AACZ;AACA,IAAM,eAAuC;CAC3C,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,OAAO;AACT;;AAGA,SAAgB,YAAY,QAAwB;CAClD,MAAM,QAAQ,YAAY,MAAM;CAChC,IAAI,MAAM,WAAW,GACnB,MAAM,IAAI,MAAM,iEAAiE,OAAO,EAAE;CAC5F,MAAM,OAAO,MAAM;CACnB,MAAM,YAAY,OAAO,KAAK,YAAY,CAAC,CACxC,QAAQ,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,CACrC,KAAK,SAAS,aAAa,KAAK;CACnC,MAAM,MAAM,KAAK,MAAM,SAAS,EAAE,QAAQ,aAAa,KAAK;CAC5D,MAAM,OAAO,QAAQ,SAAS,IAAI,SAAS,IAAI,IAAI,EAAE,CAAE,YAAY,IAAI,IAAI,MAAM,CAAC,IAAI;CACtF,OAAO,CAAC,GAAG,WAAW,IAAI,CAAC,CAAC,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WAAW,OAAO,KAAK;EAC7C,kBAAkB,WAAW,MAAM,cAAc,UAAU,gBAAgB;CAC7E;AACF"}
|
package/dist/core/model.js
CHANGED
|
@@ -174,9 +174,15 @@ function createContentNode(schema, type, props, content, rows) {
|
|
|
174
174
|
if (nodeType.isAtom || !nodeType.inlineContent) return nodeType.create(attrs);
|
|
175
175
|
return nodeType.create(attrs, inlineNodes(schema, content, !!nodeType.spec.code));
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
/**
|
|
178
|
+
* The block node for `block`. With `fill`, a block that starts with
|
|
179
|
+
* children of its own (`template` in its spec, e.g. columns) and is given
|
|
180
|
+
* none gets them, as when it is picked from the slash menu.
|
|
181
|
+
*/
|
|
182
|
+
function nodeFromBlock(schema, block, fill = false) {
|
|
178
183
|
const content = createContentNode(schema, block.type ?? "paragraph", block.props, block.content, block.rows);
|
|
179
|
-
const
|
|
184
|
+
const template = fill ? content.type.spec.template : void 0;
|
|
185
|
+
const children = ((block.children?.length ? block.children : template?.(block.props ?? {})) ?? []).map((child) => nodeFromBlock(schema, child, fill));
|
|
180
186
|
const parts = children.length ? [content, schema.nodes.blockGroup.create(null, children)] : [content];
|
|
181
187
|
return schema.nodes.block.create({ id: block.id ?? createId() }, parts);
|
|
182
188
|
}
|
package/dist/core/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["import { Mark, type NodeType, type Node as PMNode, type Schema } from 'prosemirror-model'\nimport { isColor, type TextColor } from './colors'\nimport type { ContentType, MarkType } from './schema'\n\n/** A run of text with its formatting. */\nexport interface TextContent {\n type: 'text'\n text: string\n /** Formatting, in a fixed order: bold, italic, underline, strike, code. */\n marks?: MarkType[]\n /** The link target, when the text is a link. */\n link?: string\n /** The text color, by palette name (e.g. `red`), with the `colors` extension. */\n color?: TextColor\n /** The background color, by palette name (e.g. `yellow`), with the `colors` extension. */\n highlight?: TextColor\n /** The ids of the comment threads about this text. */\n comments?: string[]\n}\n\n/**\n * For the `colors` extension's marks (internal): a mark that carries one\n * color is stored on the text run under this name, e.g.\n * `{ text, color: 'red' }`, and keeps it in its `value` attribute.\n */\nexport type MarkField = 'color' | 'highlight'\n\n/** A line break inside a block (`Shift+Enter`). */\nexport interface BreakContent {\n type: 'break'\n}\n\n/** An inline node an extension adds, e.g. a mention. */\nexport interface InlineNodeContent {\n type: 'inline'\n /** The node's name, e.g. `mention`. */\n name: string\n props: Record<string, unknown>\n}\n\nexport type InlineContent = TextContent | BreakContent | InlineNodeContent\n\n/** A block's attributes: those of the built-in types, and any an extension declares. */\nexport interface BlockProps {\n /** Heading level, `1` to `3`. */\n level?: number\n /** Whether a to-do item is done. */\n checked?: boolean\n /** The language of a code block. */\n language?: string\n /** The tone of a callout: `info`, `tip`, `warning` or `danger`. */\n tone?: string\n /** How a paragraph, heading or quote lines up; left out when it follows the reading direction. */\n align?: 'left' | 'center' | 'right'\n [name: string]: unknown\n}\n\n/** A table cell: formatted text, and how far it reaches when merged. */\nexport interface TableCell {\n content: InlineContent[]\n /** Columns the cell spans, when more than one. */\n colspan?: number\n /** Rows the cell spans, when more than one. */\n rowspan?: number\n}\n\n/** A table row: one cell for every column, including those a merged cell covers. */\nexport interface TableRow {\n /** Stable across edits, like a block's id. */\n id: string\n cells: TableCell[]\n}\n\nexport interface PartialTableCell {\n content?: InlineContent[] | string\n colspan?: number\n rowspan?: number\n}\n\nexport interface PartialTableRow {\n id?: string\n cells: (PartialTableCell | string)[]\n}\n\n/** One block of the document, as `v-model` reads and writes it. */\nexport interface Block {\n /** Stable across edits; a random UUID unless you provide your own. */\n id: string\n type: ContentType\n props: BlockProps\n content: InlineContent[]\n /** The rows of a table; other blocks have none. */\n rows?: TableRow[]\n children: Block[]\n}\n\n/**\n * The document the editor edits, bound with `v-model`: plain JSON to store\n * and send as it is. The editor writes full blocks; it reads partial ones.\n */\nexport interface EditorDocument<B extends PartialBlock = Block> {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n blocks: B[]\n}\n\n/** A block to insert: everything but the type is optional. */\nexport interface PartialBlock {\n id?: string\n type?: ContentType\n props?: BlockProps\n /** Inline content, or plain text. */\n content?: InlineContent[] | string\n rows?: PartialTableRow[]\n children?: PartialBlock[]\n}\n\n/**\n * A content node spec field for blocks whose content is rows rather than\n * text (a table): how to read them into a block and build them back.\n */\nexport interface RowsSpec {\n read: (node: PMNode) => { props: BlockProps; rows: TableRow[] }\n write: (type: NodeType, props: BlockProps, rows: PartialTableRow[]) => PMNode\n /** The node as a grid of ids and cell nodes, for collaboration. */\n grid: (node: PMNode) => TableGrid\n}\n\n/** A table node laid out by ids. */\nexport interface TableGrid {\n /** The props other than `columns`. */\n props: BlockProps\n /** Each column's id and its other fields (width, alignment). */\n columns: { id: string; width?: number; align?: string }[]\n /** Row ids, top to bottom. */\n rows: string[]\n /** The cells that are shown, merged ones by their top-left place. */\n cells: GridCell[]\n}\n\nexport interface GridCell {\n row: number\n col: number\n rowspan: number\n colspan: number\n /** The cell node; its content is inline. */\n node: PMNode\n /** Where the cell starts, counted from the start of the table's content. */\n offset: number\n}\n\nconst MARK_ORDER: string[] = ['bold', 'italic', 'underline', 'strike', 'code']\n\n/** Built-in marks in a fixed order, then the others by name. */\nconst markRank = (name: string) => {\n const index = MARK_ORDER.indexOf(name)\n return index < 0 ? MARK_ORDER.length : index\n}\n\n/** A random id; UUIDs keep blocks created at the same time on two devices apart. */\nexport function createId(): string {\n const crypto = globalThis.crypto\n if (crypto?.randomUUID) return crypto.randomUUID()\n // a v4 UUID from `getRandomValues`, or `Math.random` as a last resort\n const bytes = new Uint8Array(16)\n if (crypto?.getRandomValues) crypto.getRandomValues(bytes)\n else for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256)\n bytes[6] = (bytes[6]! & 0x0f) | 0x40\n bytes[8] = (bytes[8]! & 0x3f) | 0x80\n const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n}\n\n/* document → blocks */\n\nexport function inlineOf(node: PMNode): InlineContent[] {\n const result: InlineContent[] = []\n node.forEach((child) => {\n if (child.type.name === 'hardBreak') {\n result.push({ type: 'break' })\n return\n }\n if (!child.isText) {\n result.push({ type: 'inline', name: child.type.name, props: { ...child.attrs } })\n return\n }\n const marks = child.marks\n .filter((mark) => !mark.type.spec.field)\n .map((mark) => mark.type.name)\n .filter((name): name is MarkType => name !== 'link' && name !== 'comment')\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts the filtered copy\n .sort((a, b) => markRank(a) - markRank(b) || a.localeCompare(b))\n const link = child.marks.find((mark) => mark.type.name === 'link')?.attrs.href as\n string | undefined\n const item: TextContent = { type: 'text', text: child.text ?? '' }\n if (marks.length) item.marks = marks\n if (link) item.link = link\n for (const mark of child.marks) {\n const field = mark.type.spec.field as MarkField | undefined\n if (field) item[field] = mark.attrs.value as TextColor\n }\n const comments = child.marks\n .filter((mark) => mark.type.name === 'comment')\n .map((mark) => mark.attrs.id as string)\n if (comments.length) item.comments = comments\n // merge with the previous run when the formatting is the same\n const previous = result.at(-1)\n if (\n previous?.type === 'text' &&\n previous.link === item.link &&\n previous.color === item.color &&\n previous.highlight === item.highlight &&\n String(previous.marks ?? '') === String(item.marks ?? '') &&\n String(previous.comments ?? '') === String(item.comments ?? '')\n )\n previous.text += item.text\n else result.push(item)\n })\n return result\n}\n\n/** A content node's attributes; those its spec lists as `optionalProps` only when set. */\nfunction propsOf(content: PMNode): BlockProps {\n const props: BlockProps = { ...content.attrs }\n for (const name of (content.type.spec.optionalProps as string[] | undefined) ?? [])\n if (props[name] === null || props[name] === undefined) delete props[name]\n return props\n}\n\n/**\n * Blocks already read, by node. Nodes never change, so a block that wasn't\n * edited is the same object as last time: reading a large document after\n * typing one key only builds the blocks on the path to that key.\n */\nconst blockCache = new WeakMap<PMNode, Block>()\n\nconst freeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n Object.freeze(value)\n for (const item of Object.values(value)) freeze(item)\n }\n return value\n}\n\n/** A block of the document; shared between reads, so frozen. */\nexport function blockFromNode(node: PMNode): Block {\n let block = blockCache.get(node)\n if (!block) {\n block = readBlock(node)\n // a change to a shared block throws, instead of corrupting later reads\n freeze(block)\n blockCache.set(node, block)\n }\n return block\n}\n\nfunction readBlock(node: PMNode): Block {\n const content = node.firstChild!\n const group = node.childCount > 1 ? node.child(1) : null\n const children: Block[] = []\n group?.forEach((child) => children.push(blockFromNode(child)))\n const rows = content.type.spec.rows as RowsSpec | undefined\n if (rows) {\n const read = rows.read(content)\n return {\n id: node.attrs.id as string,\n type: content.type.name as ContentType,\n props: read.props,\n content: [],\n rows: read.rows,\n children,\n }\n }\n return {\n id: node.attrs.id as string,\n type: content.type.name as ContentType,\n props: propsOf(content),\n content: content.type.spec.code ? codeText(content) : inlineOf(content),\n children,\n }\n}\n\nfunction codeText(node: PMNode): InlineContent[] {\n return node.textContent ? [{ type: 'text', text: node.textContent }] : []\n}\n\nexport function docToBlocks(doc: PMNode): Block[] {\n const blocks: Block[] = []\n doc.forEach((node) => blocks.push(blockFromNode(node)))\n return blocks\n}\n\n/* blocks → document */\n\nfunction marksFor(schema: Schema, item: TextContent): Mark[] {\n const marks: Mark[] = []\n for (const name of item.marks ?? []) {\n const type = schema.marks[name]\n if (type) marks.push(type.create())\n }\n if (item.link && schema.marks.link) marks.push(schema.marks.link.create({ href: item.link }))\n for (const type of Object.values(schema.marks)) {\n const field = type.spec.field as MarkField | undefined\n const value = field && item[field]\n if (!value) continue\n // a color outside the palette is dropped\n if (!isColor(value)) warnOnce(`\"${value}\" is not a palette color; dropped`)\n else marks.push(type.create({ value }))\n }\n for (const id of item.comments ?? []) marks.push(schema.marks.comment!.create({ id }))\n return Mark.setFrom(marks) as Mark[]\n}\n\nexport function inlineNodes(\n schema: Schema,\n content: PartialBlock['content'],\n code: boolean,\n): PMNode[] {\n if (content === undefined) return []\n const items: InlineContent[] =\n typeof content === 'string' ? [{ type: 'text', text: content }] : content\n const nodes: PMNode[] = []\n for (const item of items) {\n if (item.type === 'break') {\n nodes.push(code ? schema.text('\\n') : schema.nodes.hardBreak!.create())\n } else if (item.type === 'inline') {\n // an inline node whose extension is missing is left out\n const type = schema.nodes[item.name]\n if (type?.isInline && !code) nodes.push(type.create(item.props))\n } else if (item.text) {\n nodes.push(schema.text(item.text, code ? [] : marksFor(schema, item)))\n }\n }\n return nodes\n}\n\n/**\n * The attributes a content type declares, taken from `props` where given.\n * A spec's `normalizeProps` can clamp them, e.g. a heading's level.\n */\nexport function contentAttrs(type: NodeType, props: BlockProps = {}) {\n const attrs: Record<string, unknown> = {}\n for (const name of Object.keys(type.spec.attrs ?? {})) {\n if (props[name] !== undefined) attrs[name] = props[name]\n }\n const normalize = type.spec.normalizeProps as\n ((attrs: Record<string, unknown>) => Record<string, unknown>) | undefined\n return normalize ? normalize(attrs) : attrs\n}\n\nexport function createContentNode(\n schema: Schema,\n type: ContentType,\n props?: BlockProps,\n content?: PartialBlock['content'],\n rows?: PartialTableRow[],\n): PMNode {\n const nodeType = schema.nodes[type]?.isInGroup('blockContent')\n ? schema.nodes[type]!\n : schema.nodes.paragraph!\n const rowsSpec = nodeType.spec.rows as RowsSpec | undefined\n if (rowsSpec) return rowsSpec.write(nodeType, props ?? {}, rows ?? [])\n const attrs = contentAttrs(nodeType, props)\n if (nodeType.isAtom || !nodeType.inlineContent) return nodeType.create(attrs)\n return nodeType.create(attrs, inlineNodes(schema, content, !!nodeType.spec.code))\n}\n\nexport function nodeFromBlock(schema: Schema, block: PartialBlock): PMNode {\n const content = createContentNode(\n schema,\n block.type ?? 'paragraph',\n block.props,\n block.content,\n block.rows,\n )\n const children = (block.children ?? []).map((child) => nodeFromBlock(schema, child))\n const parts = children.length\n ? [content, schema.nodes.blockGroup!.create(null, children)]\n : [content]\n return schema.nodes.block!.create({ id: block.id ?? createId() }, parts)\n}\n\nexport function blocksToDoc(schema: Schema, blocks: PartialBlock[]): PMNode {\n const list = blocks.length ? blocks : [{ type: 'paragraph' as const }]\n return schema.nodes.doc!.create(\n null,\n list.map((block) => nodeFromBlock(schema, block)),\n )\n}\n\nconst warned = new Set<string>()\n\n/** A development warning, once per message. */\nexport function warnOnce(message: string) {\n if (process.env.NODE_ENV === 'production' || warned.has(message)) return\n warned.add(message)\n console.warn(`[@dou-ui/editor] ${message}`)\n}\n"],"mappings":";;;AAuJA,IAAM,aAAuB;CAAC;CAAQ;CAAU;CAAa;CAAU;AAAM;;AAG7E,IAAM,YAAY,SAAiB;CACjC,MAAM,QAAQ,WAAW,QAAQ,IAAI;CACrC,OAAO,QAAQ,IAAI,WAAW,SAAS;AACzC;;AAGA,SAAgB,WAAmB;CACjC,MAAM,SAAS,WAAW;CAC1B,IAAI,QAAQ,YAAY,OAAO,OAAO,WAAW;CAEjD,MAAM,wBAAQ,IAAI,WAAW,EAAE;CAC/B,IAAI,QAAQ,iBAAiB,OAAO,gBAAgB,KAAK;MACpD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,MAAM,KAAK,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;CAC3E,MAAM,KAAM,MAAM,KAAM,KAAQ;CAChC,MAAM,KAAM,MAAM,KAAM,KAAQ;CAChC,MAAM,MAAM,MAAM,KAAK,QAAQ,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;CACnF,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE;AACzG;AAIA,SAAgB,SAAS,MAA+B;CACtD,MAAM,SAA0B,CAAC;CACjC,KAAK,SAAS,UAAU;EACtB,IAAI,MA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YAAY,MAAM,YAAY,CAAC,EAAA,CAAG,KAAK,UAAU,cAAc,QAAQ,KAAK,CAAC;CACnF,MAAM,QAAQ,SAAS,SACnB,CAAC,SAAS,OAAO,MAAM,WAAY,OAAO,MAAM,QAAQ,CAAC,IACzD,CAAC,OAAO;CACZ,OAAO,OAAO,MAAM,MAAO,OAAO,EAAE,IAAI,MAAM,MAAM,SAAS,EAAE,GAAG,KAAK;AACzE;AAEA,SAAgB,YAAY,QAAgB,QAAgC;CAC1E,MAAM,OAAO,OAAO,SAAS,SAAS,CAAC,EAAE,MAAM,YAAqB,CAAC;CACrE,OAAO,OAAO,MAAM,IAAK,OACvB,MACA,KAAK,KAAK,UAAU,cAAc,QAAQ,KAAK,CAAC,CAClD;AACF;AAEA,IAAM,yBAAS,IAAI,IAAY;;AAG/B,SAAgB,SAAS,SAAiB;CACxC,IAAA,QAAA,IAAA,aAA6B,gBAAgB,OAAO,IAAI,OAAO,GAAG;CAClE,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,oBAAoB,SAAS;AAC5C"}
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/core/model.ts"],"sourcesContent":["import { Mark, type NodeType, type Node as PMNode, type Schema } from 'prosemirror-model'\nimport { isColor, type TextColor } from './colors'\nimport type { ContentType, MarkType } from './schema'\n\n/** A run of text with its formatting. */\nexport interface TextContent {\n type: 'text'\n text: string\n /** Formatting, in a fixed order: bold, italic, underline, strike, code. */\n marks?: MarkType[]\n /** The link target, when the text is a link. */\n link?: string\n /** The text color, by palette name (e.g. `red`), with the `colors` extension. */\n color?: TextColor\n /** The background color, by palette name (e.g. `yellow`), with the `colors` extension. */\n highlight?: TextColor\n /** The ids of the comment threads about this text. */\n comments?: string[]\n}\n\n/**\n * For the `colors` extension's marks (internal): a mark that carries one\n * color is stored on the text run under this name, e.g.\n * `{ text, color: 'red' }`, and keeps it in its `value` attribute.\n */\nexport type MarkField = 'color' | 'highlight'\n\n/** A line break inside a block (`Shift+Enter`). */\nexport interface BreakContent {\n type: 'break'\n}\n\n/** An inline node an extension adds, e.g. a mention. */\nexport interface InlineNodeContent {\n type: 'inline'\n /** The node's name, e.g. `mention`. */\n name: string\n props: Record<string, unknown>\n}\n\nexport type InlineContent = TextContent | BreakContent | InlineNodeContent\n\n/** A block's attributes: those of the built-in types, and any an extension declares. */\nexport interface BlockProps {\n /** Heading level, `1` to `3`. */\n level?: number\n /** Whether a to-do item is done. */\n checked?: boolean\n /** The language of a code block. */\n language?: string\n /** The tone of a callout: `info`, `tip`, `warning` or `danger`. */\n tone?: string\n /** How a paragraph, heading or quote lines up; left out when it follows the reading direction. */\n align?: 'left' | 'center' | 'right'\n [name: string]: unknown\n}\n\n/** A table cell: formatted text, and how far it reaches when merged. */\nexport interface TableCell {\n content: InlineContent[]\n /** Columns the cell spans, when more than one. */\n colspan?: number\n /** Rows the cell spans, when more than one. */\n rowspan?: number\n}\n\n/** A table row: one cell for every column, including those a merged cell covers. */\nexport interface TableRow {\n /** Stable across edits, like a block's id. */\n id: string\n cells: TableCell[]\n}\n\nexport interface PartialTableCell {\n content?: InlineContent[] | string\n colspan?: number\n rowspan?: number\n}\n\nexport interface PartialTableRow {\n id?: string\n cells: (PartialTableCell | string)[]\n}\n\n/** One block of the document, as `v-model` reads and writes it. */\nexport interface Block {\n /** Stable across edits; a random UUID unless you provide your own. */\n id: string\n type: ContentType\n props: BlockProps\n content: InlineContent[]\n /** The rows of a table; other blocks have none. */\n rows?: TableRow[]\n children: Block[]\n}\n\n/**\n * The document the editor edits, bound with `v-model`: plain JSON to store\n * and send as it is. The editor writes full blocks; it reads partial ones.\n */\nexport interface EditorDocument<B extends PartialBlock = Block> {\n /** The version of the format; see `migrateDocument`. */\n version: 1\n blocks: B[]\n}\n\n/** A block to insert: everything but the type is optional. */\nexport interface PartialBlock {\n id?: string\n type?: ContentType\n props?: BlockProps\n /** Inline content, or plain text. */\n content?: InlineContent[] | string\n rows?: PartialTableRow[]\n children?: PartialBlock[]\n}\n\n/**\n * A content node spec field for blocks whose content is rows rather than\n * text (a table): how to read them into a block and build them back.\n */\nexport interface RowsSpec {\n read: (node: PMNode) => { props: BlockProps; rows: TableRow[] }\n write: (type: NodeType, props: BlockProps, rows: PartialTableRow[]) => PMNode\n /** The node as a grid of ids and cell nodes, for collaboration. */\n grid: (node: PMNode) => TableGrid\n}\n\n/** A table node laid out by ids. */\nexport interface TableGrid {\n /** The props other than `columns`. */\n props: BlockProps\n /** Each column's id and its other fields (width, alignment). */\n columns: { id: string; width?: number; align?: string }[]\n /** Row ids, top to bottom. */\n rows: string[]\n /** The cells that are shown, merged ones by their top-left place. */\n cells: GridCell[]\n}\n\nexport interface GridCell {\n row: number\n col: number\n rowspan: number\n colspan: number\n /** The cell node; its content is inline. */\n node: PMNode\n /** Where the cell starts, counted from the start of the table's content. */\n offset: number\n}\n\nconst MARK_ORDER: string[] = ['bold', 'italic', 'underline', 'strike', 'code']\n\n/** Built-in marks in a fixed order, then the others by name. */\nconst markRank = (name: string) => {\n const index = MARK_ORDER.indexOf(name)\n return index < 0 ? MARK_ORDER.length : index\n}\n\n/** A random id; UUIDs keep blocks created at the same time on two devices apart. */\nexport function createId(): string {\n const crypto = globalThis.crypto\n if (crypto?.randomUUID) return crypto.randomUUID()\n // a v4 UUID from `getRandomValues`, or `Math.random` as a last resort\n const bytes = new Uint8Array(16)\n if (crypto?.getRandomValues) crypto.getRandomValues(bytes)\n else for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256)\n bytes[6] = (bytes[6]! & 0x0f) | 0x40\n bytes[8] = (bytes[8]! & 0x3f) | 0x80\n const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n}\n\n/* document → blocks */\n\nexport function inlineOf(node: PMNode): InlineContent[] {\n const result: InlineContent[] = []\n node.forEach((child) => {\n if (child.type.name === 'hardBreak') {\n result.push({ type: 'break' })\n return\n }\n if (!child.isText) {\n result.push({ type: 'inline', name: child.type.name, props: { ...child.attrs } })\n return\n }\n const marks = child.marks\n .filter((mark) => !mark.type.spec.field)\n .map((mark) => mark.type.name)\n .filter((name): name is MarkType => name !== 'link' && name !== 'comment')\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts the filtered copy\n .sort((a, b) => markRank(a) - markRank(b) || a.localeCompare(b))\n const link = child.marks.find((mark) => mark.type.name === 'link')?.attrs.href as\n string | undefined\n const item: TextContent = { type: 'text', text: child.text ?? '' }\n if (marks.length) item.marks = marks\n if (link) item.link = link\n for (const mark of child.marks) {\n const field = mark.type.spec.field as MarkField | undefined\n if (field) item[field] = mark.attrs.value as TextColor\n }\n const comments = child.marks\n .filter((mark) => mark.type.name === 'comment')\n .map((mark) => mark.attrs.id as string)\n if (comments.length) item.comments = comments\n // merge with the previous run when the formatting is the same\n const previous = result.at(-1)\n if (\n previous?.type === 'text' &&\n previous.link === item.link &&\n previous.color === item.color &&\n previous.highlight === item.highlight &&\n String(previous.marks ?? '') === String(item.marks ?? '') &&\n String(previous.comments ?? '') === String(item.comments ?? '')\n )\n previous.text += item.text\n else result.push(item)\n })\n return result\n}\n\n/** A content node's attributes; those its spec lists as `optionalProps` only when set. */\nfunction propsOf(content: PMNode): BlockProps {\n const props: BlockProps = { ...content.attrs }\n for (const name of (content.type.spec.optionalProps as string[] | undefined) ?? [])\n if (props[name] === null || props[name] === undefined) delete props[name]\n return props\n}\n\n/**\n * Blocks already read, by node. Nodes never change, so a block that wasn't\n * edited is the same object as last time: reading a large document after\n * typing one key only builds the blocks on the path to that key.\n */\nconst blockCache = new WeakMap<PMNode, Block>()\n\nconst freeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n Object.freeze(value)\n for (const item of Object.values(value)) freeze(item)\n }\n return value\n}\n\n/** A block of the document; shared between reads, so frozen. */\nexport function blockFromNode(node: PMNode): Block {\n let block = blockCache.get(node)\n if (!block) {\n block = readBlock(node)\n // a change to a shared block throws, instead of corrupting later reads\n freeze(block)\n blockCache.set(node, block)\n }\n return block\n}\n\nfunction readBlock(node: PMNode): Block {\n const content = node.firstChild!\n const group = node.childCount > 1 ? node.child(1) : null\n const children: Block[] = []\n group?.forEach((child) => children.push(blockFromNode(child)))\n const rows = content.type.spec.rows as RowsSpec | undefined\n if (rows) {\n const read = rows.read(content)\n return {\n id: node.attrs.id as string,\n type: content.type.name as ContentType,\n props: read.props,\n content: [],\n rows: read.rows,\n children,\n }\n }\n return {\n id: node.attrs.id as string,\n type: content.type.name as ContentType,\n props: propsOf(content),\n content: content.type.spec.code ? codeText(content) : inlineOf(content),\n children,\n }\n}\n\nfunction codeText(node: PMNode): InlineContent[] {\n return node.textContent ? [{ type: 'text', text: node.textContent }] : []\n}\n\nexport function docToBlocks(doc: PMNode): Block[] {\n const blocks: Block[] = []\n doc.forEach((node) => blocks.push(blockFromNode(node)))\n return blocks\n}\n\n/* blocks → document */\n\nfunction marksFor(schema: Schema, item: TextContent): Mark[] {\n const marks: Mark[] = []\n for (const name of item.marks ?? []) {\n const type = schema.marks[name]\n if (type) marks.push(type.create())\n }\n if (item.link && schema.marks.link) marks.push(schema.marks.link.create({ href: item.link }))\n for (const type of Object.values(schema.marks)) {\n const field = type.spec.field as MarkField | undefined\n const value = field && item[field]\n if (!value) continue\n // a color outside the palette is dropped\n if (!isColor(value)) warnOnce(`\"${value}\" is not a palette color; dropped`)\n else marks.push(type.create({ value }))\n }\n for (const id of item.comments ?? []) marks.push(schema.marks.comment!.create({ id }))\n return Mark.setFrom(marks) as Mark[]\n}\n\nexport function inlineNodes(\n schema: Schema,\n content: PartialBlock['content'],\n code: boolean,\n): PMNode[] {\n if (content === undefined) return []\n const items: InlineContent[] =\n typeof content === 'string' ? [{ type: 'text', text: content }] : content\n const nodes: PMNode[] = []\n for (const item of items) {\n if (item.type === 'break') {\n nodes.push(code ? schema.text('\\n') : schema.nodes.hardBreak!.create())\n } else if (item.type === 'inline') {\n // an inline node whose extension is missing is left out\n const type = schema.nodes[item.name]\n if (type?.isInline && !code) nodes.push(type.create(item.props))\n } else if (item.text) {\n nodes.push(schema.text(item.text, code ? [] : marksFor(schema, item)))\n }\n }\n return nodes\n}\n\n/**\n * The attributes a content type declares, taken from `props` where given.\n * A spec's `normalizeProps` can clamp them, e.g. a heading's level.\n */\nexport function contentAttrs(type: NodeType, props: BlockProps = {}) {\n const attrs: Record<string, unknown> = {}\n for (const name of Object.keys(type.spec.attrs ?? {})) {\n if (props[name] !== undefined) attrs[name] = props[name]\n }\n const normalize = type.spec.normalizeProps as\n ((attrs: Record<string, unknown>) => Record<string, unknown>) | undefined\n return normalize ? normalize(attrs) : attrs\n}\n\nexport function createContentNode(\n schema: Schema,\n type: ContentType,\n props?: BlockProps,\n content?: PartialBlock['content'],\n rows?: PartialTableRow[],\n): PMNode {\n const nodeType = schema.nodes[type]?.isInGroup('blockContent')\n ? schema.nodes[type]!\n : schema.nodes.paragraph!\n const rowsSpec = nodeType.spec.rows as RowsSpec | undefined\n if (rowsSpec) return rowsSpec.write(nodeType, props ?? {}, rows ?? [])\n const attrs = contentAttrs(nodeType, props)\n if (nodeType.isAtom || !nodeType.inlineContent) return nodeType.create(attrs)\n return nodeType.create(attrs, inlineNodes(schema, content, !!nodeType.spec.code))\n}\n\n/**\n * The block node for `block`. With `fill`, a block that starts with\n * children of its own (`template` in its spec, e.g. columns) and is given\n * none gets them, as when it is picked from the slash menu.\n */\nexport function nodeFromBlock(schema: Schema, block: PartialBlock, fill = false): PMNode {\n const content = createContentNode(\n schema,\n block.type ?? 'paragraph',\n block.props,\n block.content,\n block.rows,\n )\n const template = fill\n ? (content.type.spec.template as ((props: BlockProps) => PartialBlock[]) | undefined)\n : undefined\n const given = block.children?.length ? block.children : template?.(block.props ?? {})\n const children = (given ?? []).map((child) => nodeFromBlock(schema, child, fill))\n const parts = children.length\n ? [content, schema.nodes.blockGroup!.create(null, children)]\n : [content]\n return schema.nodes.block!.create({ id: block.id ?? createId() }, parts)\n}\n\nexport function blocksToDoc(schema: Schema, blocks: PartialBlock[]): PMNode {\n const list = blocks.length ? blocks : [{ type: 'paragraph' as const }]\n return schema.nodes.doc!.create(\n null,\n list.map((block) => nodeFromBlock(schema, block)),\n )\n}\n\nconst warned = new Set<string>()\n\n/** A development warning, once per message. */\nexport function warnOnce(message: string) {\n if (process.env.NODE_ENV === 'production' || warned.has(message)) return\n warned.add(message)\n console.warn(`[@dou-ui/editor] ${message}`)\n}\n"],"mappings":";;;AAuJA,IAAM,aAAuB;CAAC;CAAQ;CAAU;CAAa;CAAU;AAAM;;AAG7E,IAAM,YAAY,SAAiB;CACjC,MAAM,QAAQ,WAAW,QAAQ,IAAI;CACrC,OAAO,QAAQ,IAAI,WAAW,SAAS;AACzC;;AAGA,SAAgB,WAAmB;CACjC,MAAM,SAAS,WAAW;CAC1B,IAAI,QAAQ,YAAY,OAAO,OAAO,WAAW;CAEjD,MAAM,wBAAQ,IAAI,WAAW,EAAE;CAC/B,IAAI,QAAQ,iBAAiB,OAAO,gBAAgB,KAAK;MACpD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,MAAM,KAAK,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;CAC3E,MAAM,KAAM,MAAM,KAAM,KAAQ;CAChC,MAAM,KAAM,MAAM,KAAM,KAAQ;CAChC,MAAM,MAAM,MAAM,KAAK,QAAQ,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;CACnF,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE;AACzG;AAIA,SAAgB,SAAS,MAA+B;CACtD,MAAM,SAA0B,CAAC;CACjC,KAAK,SAAS,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,OACN,MAAM,SACN,MAAM,IACR;CACA,MAAM,WAAW,OACZ,QAAQ,KAAK,KAAK,WACnB,KAAA;CAEJ,MAAM,aADQ,MAAM,UAAU,SAAS,MAAM,WAAW,WAAW,MAAM,SAAS,CAAC,CAAC,MACzD,CAAC,EAAA,CAAG,KAAK,UAAU,cAAc,QAAQ,OAAO,IAAI,CAAC;CAChF,MAAM,QAAQ,SAAS,SACnB,CAAC,SAAS,OAAO,MAAM,WAAY,OAAO,MAAM,QAAQ,CAAC,IACzD,CAAC,OAAO;CACZ,OAAO,OAAO,MAAM,MAAO,OAAO,EAAE,IAAI,MAAM,MAAM,SAAS,EAAE,GAAG,KAAK;AACzE;AAEA,SAAgB,YAAY,QAAgB,QAAgC;CAC1E,MAAM,OAAO,OAAO,SAAS,SAAS,CAAC,EAAE,MAAM,YAAqB,CAAC;CACrE,OAAO,OAAO,MAAM,IAAK,OACvB,MACA,KAAK,KAAK,UAAU,cAAc,QAAQ,KAAK,CAAC,CAClD;AACF;AAEA,IAAM,yBAAS,IAAI,IAAY;;AAG/B,SAAgB,SAAS,SAAiB;CACxC,IAAA,QAAA,IAAA,aAA6B,gBAAgB,OAAO,IAAI,OAAO,GAAG;CAClE,OAAO,IAAI,OAAO;CAClB,QAAQ,KAAK,oBAAoB,SAAS;AAC5C"}
|
package/dist/core/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/core/schema.ts"],"sourcesContent":["import { alignable } from './align'\nimport { Schema, type DOMOutputSpec, type MarkSpec, type NodeSpec } from 'prosemirror-model'\n\n/**\n * The document is a list of blocks. Each block is a `block` node holding\n * one piece of content (a paragraph, a heading, a list item…) and,\n * optionally, a `blockGroup` of child blocks:\n *\n * doc\n * └─ block#id\n * ├─ paragraph \"Hello\"\n * └─ blockGroup\n * └─ block#id\n * └─ checkItem \"Nested\"\n *\n * The frame (doc, block, group, paragraph, text, line break) is fixed;\n * every other content type and mark comes from an extension. Every piece\n * of state lives in node attributes (never in a node view), so a\n * collaborative binding can sync it like any other change.\n */\n\n/** The DOM of a content node: `div.dou-editor__content--<type>[data-content-type]`. */\nexport const contentDOM = (type: string, extra: Record<string, string> = {}): DOMOutputSpec => [\n 'div',\n {\n class: `dou-editor__content dou-editor__content--${type}`,\n 'data-content-type': type,\n ...extra,\n },\n 0,\n]\n\n/** A content type holding formatted text, parsed back from its own DOM. */\nexport const textBlock = (type: string, spec: Partial<NodeSpec> = {}): NodeSpec => ({\n content: 'inline*',\n defining: true,\n parseDOM: [{ tag: `div[data-content-type=\"${type}\"]` }],\n toDOM: () => contentDOM(type),\n ...spec,\n})\n\nconst frame: Record<string, NodeSpec> = {\n doc: { content: 'block+' },\n\n block: {\n attrs: { id: { default: null } },\n content: 'blockContent blockGroup?',\n defining: true,\n parseDOM: [\n {\n tag: 'div[data-block-id]',\n getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.blockId ?? null }),\n },\n ],\n toDOM: (node) => ['div', { class: 'dou-editor__block', 'data-block-id': node.attrs.id }, 0],\n },\n\n blockGroup: {\n content: 'block+',\n parseDOM: [{ tag: 'div.dou-editor__group' }],\n toDOM: () => ['div', { class: 'dou-editor__group', role: 'group' }, 0],\n },\n\n paragraph: alignable(\n textBlock('paragraph', {\n group: 'blockContent',\n parseDOM: [{ tag: 'div[data-content-type=\"paragraph\"]' }, { tag: 'p' }],\n }),\n ),\n}\n\nconst inlineFrame: Record<string, NodeSpec> = {\n text: { group: 'inline' },\n\n hardBreak: {\n inline: true,\n // newlines from a code block become line breaks when it turns into text, and back\n linebreakReplacement: true,\n group: 'inline',\n selectable: false,\n parseDOM: [{ tag: 'br' }],\n toDOM: () => ['br'],\n },\n}\n\n/**\n * Where a comment thread is anchored: the text it is about carries the\n * thread's id. A text can be in several threads, so the mark excludes\n * nothing, not even itself; typing at its edge doesn't extend it.\n */\nconst commentMark: MarkSpec = {\n attrs: { id: {} },\n excludes: '',\n inclusive: false,\n parseDOM: [\n {\n tag: 'span[data-comment]',\n getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.comment }),\n },\n ],\n toDOM: (mark) => ['span', { class: 'dou-editor__comment', 'data-comment': mark.attrs.id }, 0],\n}\n\nexport interface SchemaParts {\n blocks: Record<string, NodeSpec>\n /** Nodes inside blocks, e.g. table rows and cells. */\n nodes?: Record<string, NodeSpec>\n inlines: Record<string, NodeSpec>\n marks: Record<string, MarkSpec>\n}\n\n/** The schema for a set of extensions' blocks, inline nodes and marks. */\nexport function createSchema({ blocks, nodes: inner = {}, inlines, marks }: SchemaParts): Schema {\n const nodes: Record<string, NodeSpec> = { ...frame }\n for (const [name, spec] of Object.entries(blocks)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = { ...spec, group: spec.group ? `blockContent ${spec.group}` : 'blockContent' }\n }\n for (const [name, spec] of Object.entries(inner)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = spec\n }\n Object.assign(nodes, inlineFrame)\n for (const [name, spec] of Object.entries(inlines)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = { inline: true, ...spec, group: spec.group ? `inline ${spec.group}` : 'inline' }\n }\n if ('comment' in marks) throw new Error('[@dou-ui/editor] \"comment\" is a built-in mark')\n // any text can be commented on, also text whose mark excludes all others (inline code)\n const others = Object.keys(marks).join(' ')\n const specs = Object.fromEntries(\n Object.entries(marks).map(([name, spec]) => [\n name,\n spec.excludes === '_' ? { ...spec, excludes: others } : spec,\n ]),\n )\n // first, so a comment wraps the formatting of the text it is about\n return new Schema({ nodes, marks: { comment: commentMark, ...specs } })\n}\n\n/** Links may only point to web pages, mail, phone numbers or relative paths. */\nexport function isSafeHref(href: string): boolean {\n // browsers ignore whitespace and control characters inside the scheme\n // eslint-disable-next-line no-control-regex\n const value = href.replace(/[\\u0000- ]/g, '')\n const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(value)?.[1]?.toLowerCase()\n return !scheme || ['http', 'https', 'mailto', 'tel'].includes(scheme)\n}\n\n/** The content types that come with `editorKit`; extensions add more. */\nexport type BuiltinContentType =\n | 'paragraph'\n | 'heading'\n | 'bulletItem'\n | 'numberedItem'\n | 'checkItem'\n | 'quote'\n | 'codeBlock'\n | 'divider'\n | 'toggle'\n | 'callout'\n | 'table'\n\nexport type ContentType = BuiltinContentType | (string & {})\n\nexport type BuiltinMarkType = 'bold' | 'italic' | 'underline' | 'strike' | 'code'\n\nexport type MarkType = BuiltinMarkType | (string & {})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,cAAc,MAAc,QAAgC,CAAC,MAAqB;CAC7F;CACA;EACE,OAAO,4CAA4C;EACnD,qBAAqB;EACrB,GAAG;CACL;CACA;AACF;;AAGA,IAAa,aAAa,MAAc,OAA0B,CAAC,OAAiB;CAClF,SAAS;CACT,UAAU;CACV,UAAU,CAAC,EAAE,KAAK,0BAA0B,KAAK,IAAI,CAAC;CACtD,aAAa,WAAW,IAAI;CAC5B,GAAG;AACL;AAEA,IAAM,QAAkC;CACtC,KAAK,EAAE,SAAS,SAAS;CAEzB,OAAO;EACL,OAAO,EAAE,IAAI,EAAE,SAAS,KAAK,EAAE;EAC/B,SAAS;EACT,UAAU;EACV,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAS,EAAE,IAAK,IAAoB,QAAQ,WAAW,KAAK;EACzE,CACF;EACA,QAAQ,SAAS;GAAC;GAAO;IAAE,OAAO;IAAqB,iBAAiB,KAAK,MAAM;GAAG;GAAG;EAAC;CAC5F;CAEA,YAAY;EACV,SAAS;EACT,UAAU,CAAC,EAAE,KAAK,wBAAwB,CAAC;EAC3C,aAAa;GAAC;GAAO;IAAE,OAAO;IAAqB,MAAM;GAAQ;GAAG;EAAC;CACvE;CAEA,WAAW,UACT,UAAU,aAAa;EACrB,OAAO;EACP,UAAU,CAAC,EAAE,KAAK,uCAAqC,GAAG,EA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AC/F;CACA,IAAI,aAAa,OAAO,MAAM,IAAI,MAAM,iDAA+C;CAEvF,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,GAAG;CAC1C,MAAM,QAAQ,OAAO,YACnB,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAC1C,MACA,KAAK,aAAa,MAAM;EAAE,GAAG;EAAM,UAAU;CAAO,IAAI,IAC1D,CAAC,CACH;CAEA,OAAO,IAAI,OAAO;EAAE;EAAO,OAAO;GAAE,SAAS;GAAa,GAAG;EAAM;CAAE,CAAC;AACxE;;AAGA,SAAgB,WAAW,MAAuB;CAGhD,MAAM,QAAQ,KAAK,QAAQ,eAAe,EAAE;CAC5C,MAAM,SAAS,yBAAyB,KAAK,KAAK,CAAC,GAAG,EAAE,EAAE,YAAY;CACtE,OAAO,CAAC,UAAU;EAAC;EAAQ;EAAS;EAAU;CAAK,CAAC,CAAC,SAAS,MAAM;AACtE"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/core/schema.ts"],"sourcesContent":["import { alignable } from './align'\nimport { Schema, type DOMOutputSpec, type MarkSpec, type NodeSpec } from 'prosemirror-model'\n\n/**\n * The document is a list of blocks. Each block is a `block` node holding\n * one piece of content (a paragraph, a heading, a list item…) and,\n * optionally, a `blockGroup` of child blocks:\n *\n * doc\n * └─ block#id\n * ├─ paragraph \"Hello\"\n * └─ blockGroup\n * └─ block#id\n * └─ checkItem \"Nested\"\n *\n * The frame (doc, block, group, paragraph, text, line break) is fixed;\n * every other content type and mark comes from an extension. Every piece\n * of state lives in node attributes (never in a node view), so a\n * collaborative binding can sync it like any other change.\n */\n\n/** The DOM of a content node: `div.dou-editor__content--<type>[data-content-type]`. */\nexport const contentDOM = (type: string, extra: Record<string, string> = {}): DOMOutputSpec => [\n 'div',\n {\n class: `dou-editor__content dou-editor__content--${type}`,\n 'data-content-type': type,\n ...extra,\n },\n 0,\n]\n\n/** A content type holding formatted text, parsed back from its own DOM. */\nexport const textBlock = (type: string, spec: Partial<NodeSpec> = {}): NodeSpec => ({\n content: 'inline*',\n defining: true,\n parseDOM: [{ tag: `div[data-content-type=\"${type}\"]` }],\n toDOM: () => contentDOM(type),\n ...spec,\n})\n\nconst frame: Record<string, NodeSpec> = {\n doc: { content: 'block+' },\n\n block: {\n attrs: { id: { default: null } },\n content: 'blockContent blockGroup?',\n defining: true,\n parseDOM: [\n {\n tag: 'div[data-block-id]',\n getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.blockId ?? null }),\n },\n ],\n toDOM: (node) => ['div', { class: 'dou-editor__block', 'data-block-id': node.attrs.id }, 0],\n },\n\n blockGroup: {\n content: 'block+',\n parseDOM: [{ tag: 'div.dou-editor__group' }],\n toDOM: () => ['div', { class: 'dou-editor__group', role: 'group' }, 0],\n },\n\n paragraph: alignable(\n textBlock('paragraph', {\n group: 'blockContent',\n parseDOM: [{ tag: 'div[data-content-type=\"paragraph\"]' }, { tag: 'p' }],\n }),\n ),\n}\n\nconst inlineFrame: Record<string, NodeSpec> = {\n text: { group: 'inline' },\n\n hardBreak: {\n inline: true,\n // newlines from a code block become line breaks when it turns into text, and back\n linebreakReplacement: true,\n group: 'inline',\n selectable: false,\n parseDOM: [{ tag: 'br' }],\n toDOM: () => ['br'],\n },\n}\n\n/**\n * Where a comment thread is anchored: the text it is about carries the\n * thread's id. A text can be in several threads, so the mark excludes\n * nothing, not even itself; typing at its edge doesn't extend it.\n */\nconst commentMark: MarkSpec = {\n attrs: { id: {} },\n excludes: '',\n inclusive: false,\n parseDOM: [\n {\n tag: 'span[data-comment]',\n getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.comment }),\n },\n ],\n toDOM: (mark) => ['span', { class: 'dou-editor__comment', 'data-comment': mark.attrs.id }, 0],\n}\n\nexport interface SchemaParts {\n blocks: Record<string, NodeSpec>\n /** Nodes inside blocks, e.g. table rows and cells. */\n nodes?: Record<string, NodeSpec>\n inlines: Record<string, NodeSpec>\n marks: Record<string, MarkSpec>\n}\n\n/** The schema for a set of extensions' blocks, inline nodes and marks. */\nexport function createSchema({ blocks, nodes: inner = {}, inlines, marks }: SchemaParts): Schema {\n const nodes: Record<string, NodeSpec> = { ...frame }\n for (const [name, spec] of Object.entries(blocks)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = { ...spec, group: spec.group ? `blockContent ${spec.group}` : 'blockContent' }\n }\n for (const [name, spec] of Object.entries(inner)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = spec\n }\n Object.assign(nodes, inlineFrame)\n for (const [name, spec] of Object.entries(inlines)) {\n if (name in nodes) throw new Error(`[@dou-ui/editor] \"${name}\" is a built-in node`)\n nodes[name] = { inline: true, ...spec, group: spec.group ? `inline ${spec.group}` : 'inline' }\n }\n if ('comment' in marks) throw new Error('[@dou-ui/editor] \"comment\" is a built-in mark')\n // any text can be commented on, also text whose mark excludes all others (inline code)\n const others = Object.keys(marks).join(' ')\n const specs = Object.fromEntries(\n Object.entries(marks).map(([name, spec]) => [\n name,\n spec.excludes === '_' ? { ...spec, excludes: others } : spec,\n ]),\n )\n // first, so a comment wraps the formatting of the text it is about\n return new Schema({ nodes, marks: { comment: commentMark, ...specs } })\n}\n\n/** Links may only point to web pages, mail, phone numbers or relative paths. */\nexport function isSafeHref(href: string): boolean {\n // browsers ignore whitespace and control characters inside the scheme\n // eslint-disable-next-line no-control-regex\n const value = href.replace(/[\\u0000- ]/g, '')\n const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(value)?.[1]?.toLowerCase()\n return !scheme || ['http', 'https', 'mailto', 'tel'].includes(scheme)\n}\n\n/** The content types that come with `editorKit`; extensions add more. */\nexport type BuiltinContentType =\n | 'paragraph'\n | 'heading'\n | 'bulletItem'\n | 'numberedItem'\n | 'checkItem'\n | 'quote'\n | 'codeBlock'\n | 'divider'\n | 'toggle'\n | 'callout'\n | 'table'\n | 'columns'\n | 'column'\n\nexport type ContentType = BuiltinContentType | (string & {})\n\nexport type BuiltinMarkType = 'bold' | 'italic' | 'underline' | 'strike' | 'code'\n\nexport type MarkType = BuiltinMarkType | (string & {})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,cAAc,MAAc,QAAgC,CAAC,MAAqB;CAC7F;CACA;EACE,OAAO,4CAA4C;EACnD,qBAAqB;EACrB,GAAG;CACL;CACA;AACF;;AAGA,IAAa,aAAa,MAAc,OAA0B,CAAC,OAAiB;CAClF,SAAS;CACT,UAAU;CACV,UAAU,CAAC,EAAE,KAAK,0BAA0B,KAAK,IAAI,CAAC;CACtD,aAAa,WAAW,IAAI;CAC5B,GAAG;AACL;AAEA,IAAM,QAAkC;CACtC,KAAK,EAAE,SAAS,SAAS;CAEzB,OAAO;EACL,OAAO,EAAE,IAAI,EAAE,SAAS,KAAK,EAAE;EAC/B,SAAS;EACT,UAAU;EACV,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAS,EAAE,IAAK,IAAoB,QAAQ,WAAW,KAAK;EACzE,CACF;EACA,QAAQ,SAAS;GAAC;GAAO;IAAE,OAAO;IAAqB,iBAAiB,KAAK,MAAM;GAAG;GAAG;EAAC;CAC5F;CAEA,YAAY;EACV,SAAS;EACT,UAAU,CAAC,EAAE,KAAK,wBAAwB,CAAC;EAC3C,aAAa;GAAC;GAAO;IAAE,OAAO;IAAqB,MAAM;GAAQ;GAAG;EAAC;CACvE;CAEA,WAAW,UACT,UAAU,aAAa;EACrB,OAAO;EACP,UAAU,CAAC,EAAE,KAAK,uCAAqC,GAAG,EAAE,KAAK,IAAI,CAAC;CACxE,CAAC,CACH;AACF;AAEA,IAAM,cAAwC;CAC5C,MAAM,EAAE,OAAO,SAAS;CAExB,WAAW;EACT,QAAQ;EAER,sBAAsB;EACtB,OAAO;EACP,YAAY;EACZ,UAAU,CAAC,EAAE,KAAK,KAAK,CAAC;EACxB,aAAa,CAAC,IAAI;CACpB;AACF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AAM;EAAE,GAAG;EAAM,UAAU;CAAO,IAAI,IAC1D,CAAC,CACH;CAEA,OAAO,IAAI,OAAO;EAAE;EAAO,OAAO;GAAE,SAAS;GAAa,GAAG;EAAM;CAAE,CAAC;AACxE;;AAGA,SAAgB,WAAW,MAAuB;CAGhD,MAAM,QAAQ,KAAK,QAAQ,eAAe,EAAE;CAC5C,MAAM,SAAS,yBAAyB,KAAK,KAAK,CAAC,GAAG,EAAE,EAAE,YAAY;CACtE,OAAO,CAAC,UAAU;EAAC;EAAQ;EAAS;EAAU;CAAK,CAAC,CAAC,SAAS,MAAM;AACtE"}
|
package/dist/core/transaction.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blockFromNode, contentAttrs, createContentNode, createId, nodeFromBlock } from "./model.js";
|
|
2
|
-
import { blockAround, findBlockById } from "./blocks.js";
|
|
2
|
+
import { blockAround, findBlockById, layoutOf, parentBlock } from "./blocks.js";
|
|
3
3
|
import { blockSelectionRange } from "./block-selection.js";
|
|
4
4
|
import { originKey } from "./editor.js";
|
|
5
5
|
import { NodeSelection, Selection, TextSelection } from "prosemirror-state";
|
|
@@ -55,11 +55,15 @@ var EditorTransaction = class {
|
|
|
55
55
|
const taken = usedIds(tr.doc);
|
|
56
56
|
const ids = [];
|
|
57
57
|
const nodes = blocks.map((block) => {
|
|
58
|
-
const node = nodeFromBlock(schema, freshIds(block, taken));
|
|
58
|
+
const node = nodeFromBlock(schema, freshIds(block, taken), true);
|
|
59
59
|
ids.push(node.attrs.id);
|
|
60
60
|
return node;
|
|
61
61
|
});
|
|
62
62
|
if (insertNodes(tr, placement ?? this.defaultPlacement(), nodes) === null) return [];
|
|
63
|
+
for (const id of ids) {
|
|
64
|
+
const info = findBlockById(tr.doc, id);
|
|
65
|
+
if (layoutOf(info?.node) === "row" && info && inColumn(tr.doc, info)) warn(`insertBlocks: columns don't go in a column; the block "${id}" is replaced by its columns' blocks`);
|
|
66
|
+
}
|
|
63
67
|
return ids;
|
|
64
68
|
}
|
|
65
69
|
/** Change a block's type, props, content or children. Returns `false` when it isn't found. */
|
|
@@ -260,6 +264,11 @@ function childPos(start, container, index = container.childCount) {
|
|
|
260
264
|
for (let i = 0; i < at; i++) pos += container.child(i).nodeSize;
|
|
261
265
|
return pos;
|
|
262
266
|
}
|
|
267
|
+
/** Whether a block sits in a column, at any depth. */
|
|
268
|
+
function inColumn(doc, info) {
|
|
269
|
+
for (let parent = parentBlock(doc, info); parent; parent = parentBlock(doc, parent)) if (layoutOf(parent.node) === "column") return true;
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
263
272
|
function replaceChildren(tr, info, children) {
|
|
264
273
|
const schema = tr.doc.type.schema;
|
|
265
274
|
const groupPos = info.contentPos + info.content.nodeSize;
|
|
@@ -267,7 +276,7 @@ function replaceChildren(tr, info, children) {
|
|
|
267
276
|
info.group?.descendants((node) => {
|
|
268
277
|
if (node.type.name === "block") taken.delete(node.attrs.id);
|
|
269
278
|
});
|
|
270
|
-
const nodes = children.map((child) => nodeFromBlock(schema, freshIds(child, taken)));
|
|
279
|
+
const nodes = children.map((child) => nodeFromBlock(schema, freshIds(child, taken), true));
|
|
271
280
|
const group = nodes.length ? schema.nodes.blockGroup.create(null, nodes) : null;
|
|
272
281
|
const end = info.group ? groupPos + info.group.nodeSize : groupPos;
|
|
273
282
|
if (group) tr.replaceWith(groupPos, end, group);
|