@dou-ui/editor 0.1.0-alpha.3 → 0.1.0-alpha.30

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.
Files changed (159) hide show
  1. package/dist/collaboration/binding.js +371 -57
  2. package/dist/collaboration/binding.js.map +1 -1
  3. package/dist/collaboration/cursors.js +42 -10
  4. package/dist/collaboration/cursors.js.map +1 -1
  5. package/dist/collaboration/index.js +61 -11
  6. package/dist/collaboration/index.js.map +1 -1
  7. package/dist/collaboration/inline-diff.js +138 -0
  8. package/dist/collaboration/inline-diff.js.map +1 -0
  9. package/dist/collaboration/merged-props.js +152 -0
  10. package/dist/collaboration/merged-props.js.map +1 -0
  11. package/dist/collaboration/order.js +41 -1
  12. package/dist/collaboration/order.js.map +1 -1
  13. package/dist/collaboration/table.js +64 -25
  14. package/dist/collaboration/table.js.map +1 -1
  15. package/dist/collaboration/text.js +213 -1
  16. package/dist/collaboration/text.js.map +1 -1
  17. package/dist/components/block-handle.js.map +1 -1
  18. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +127 -17
  19. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  20. package/dist/components/slash-choices.js +6 -0
  21. package/dist/components/slash-choices.js.map +1 -0
  22. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
  23. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
  24. package/dist/components/slash-menu.js.map +1 -1
  25. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
  26. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  27. package/dist/core/block-selection.js +32 -4
  28. package/dist/core/block-selection.js.map +1 -1
  29. package/dist/core/blocks.js +21 -3
  30. package/dist/core/blocks.js.map +1 -1
  31. package/dist/core/cjk.js +54 -0
  32. package/dist/core/cjk.js.map +1 -0
  33. package/dist/core/commands.js +125 -13
  34. package/dist/core/commands.js.map +1 -1
  35. package/dist/core/comments.js +85 -3
  36. package/dist/core/comments.js.map +1 -1
  37. package/dist/core/convert.js +3 -3
  38. package/dist/core/convert.js.map +1 -1
  39. package/dist/core/extension.js +6 -2
  40. package/dist/core/extension.js.map +1 -1
  41. package/dist/core/model.js +10 -3
  42. package/dist/core/model.js.map +1 -1
  43. package/dist/core/output.js +26 -10
  44. package/dist/core/output.js.map +1 -1
  45. package/dist/core/prepare.js +12 -5
  46. package/dist/core/prepare.js.map +1 -1
  47. package/dist/core/schema.js.map +1 -1
  48. package/dist/core/transaction.js +19 -4
  49. package/dist/core/transaction.js.map +1 -1
  50. package/dist/define-block.js +8 -4
  51. package/dist/define-block.js.map +1 -1
  52. package/dist/document.js +59 -4
  53. package/dist/document.js.map +1 -1
  54. package/dist/dom.js +109 -13
  55. package/dist/dom.js.map +1 -1
  56. package/dist/editor.js.map +1 -1
  57. package/dist/editor.vue_vue_type_script_setup_true_lang.js +6 -5
  58. package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  59. package/dist/editor2.js.map +1 -1
  60. package/dist/extensions/callout/html.js +5 -4
  61. package/dist/extensions/callout/html.js.map +1 -1
  62. package/dist/extensions/columns/column-picker.js +6 -0
  63. package/dist/extensions/columns/column-picker.js.map +1 -0
  64. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
  65. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  66. package/dist/extensions/columns/columns-controls.js +6 -0
  67. package/dist/extensions/columns/columns-controls.js.map +1 -0
  68. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
  69. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
  70. package/dist/extensions/columns/html.js +34 -0
  71. package/dist/extensions/columns/html.js.map +1 -0
  72. package/dist/extensions/columns/index.js +57 -0
  73. package/dist/extensions/columns/index.js.map +1 -0
  74. package/dist/extensions/columns/keys.js +53 -0
  75. package/dist/extensions/columns/keys.js.map +1 -0
  76. package/dist/extensions/columns/plugin.js +213 -0
  77. package/dist/extensions/columns/plugin.js.map +1 -0
  78. package/dist/extensions/columns/schema.js +58 -0
  79. package/dist/extensions/columns/schema.js.map +1 -0
  80. package/dist/extensions/columns/select-columns.js +6 -0
  81. package/dist/extensions/columns/select-columns.js.map +1 -0
  82. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
  83. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
  84. package/dist/extensions/editor-kit.js +3 -1
  85. package/dist/extensions/editor-kit.js.map +1 -1
  86. package/dist/extensions/list-html.js +1 -1
  87. package/dist/extensions/list-html.js.map +1 -1
  88. package/dist/extensions/table/plugin.js +33 -1
  89. package/dist/extensions/table/plugin.js.map +1 -1
  90. package/dist/extensions/table/schema.js +5 -1
  91. package/dist/extensions/table/schema.js.map +1 -1
  92. package/dist/extensions/table/table-controls.js.map +1 -1
  93. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +80 -9
  94. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
  95. package/dist/extensions/table/view.js +181 -3
  96. package/dist/extensions/table/view.js.map +1 -1
  97. package/dist/flow/board-block.js +6 -0
  98. package/dist/flow/board-block.js.map +1 -0
  99. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
  100. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
  101. package/dist/flow/board.js +221 -0
  102. package/dist/flow/board.js.map +1 -0
  103. package/dist/flow/index.js +173 -0
  104. package/dist/flow/index.js.map +1 -0
  105. package/dist/index.js +3 -2
  106. package/dist/index.js.map +1 -1
  107. package/dist/locale.js +78 -6
  108. package/dist/locale.js.map +1 -1
  109. package/dist/markdown/cjk-friendly.js +62 -0
  110. package/dist/markdown/cjk-friendly.js.map +1 -0
  111. package/dist/markdown/index.js +4 -3
  112. package/dist/markdown/index.js.map +1 -1
  113. package/dist/style.css +1 -1
  114. package/dist/style.js +2 -0
  115. package/dist/types/collaboration/binding.d.ts +12 -0
  116. package/dist/types/collaboration/cursors.d.ts +29 -1
  117. package/dist/types/collaboration/index.d.ts +53 -6
  118. package/dist/types/collaboration/inline-diff.d.ts +9 -0
  119. package/dist/types/collaboration/merged-props.d.ts +20 -0
  120. package/dist/types/collaboration/order.d.ts +5 -0
  121. package/dist/types/collaboration/table.d.ts +5 -1
  122. package/dist/types/collaboration/text.d.ts +20 -0
  123. package/dist/types/components/slash-choices.vue.d.ts +18 -0
  124. package/dist/types/core/blocks.d.ts +10 -0
  125. package/dist/types/core/cjk.d.ts +23 -0
  126. package/dist/types/core/commands.d.ts +17 -2
  127. package/dist/types/core/comments.d.ts +39 -3
  128. package/dist/types/core/convert.d.ts +10 -2
  129. package/dist/types/core/extension.d.ts +58 -4
  130. package/dist/types/core/model.d.ts +6 -1
  131. package/dist/types/core/prepare.d.ts +16 -2
  132. package/dist/types/core/schema.d.ts +1 -1
  133. package/dist/types/core/transaction.d.ts +6 -0
  134. package/dist/types/define-block.d.ts +16 -4
  135. package/dist/types/document.d.ts +5 -2
  136. package/dist/types/dom.d.ts +41 -4
  137. package/dist/types/editor.d.ts +15 -1
  138. package/dist/types/editor.vue.d.ts +24 -0
  139. package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
  140. package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
  141. package/dist/types/extensions/columns/html.d.ts +10 -0
  142. package/dist/types/extensions/columns/index.d.ts +9 -0
  143. package/dist/types/extensions/columns/keys.d.ts +6 -0
  144. package/dist/types/extensions/columns/plugin.d.ts +28 -0
  145. package/dist/types/extensions/columns/schema.d.ts +17 -0
  146. package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
  147. package/dist/types/extensions/editor-kit.d.ts +4 -1
  148. package/dist/types/extensions/table/view.d.ts +36 -2
  149. package/dist/types/flow/board-block.vue.d.ts +16 -0
  150. package/dist/types/flow/board.d.ts +53 -0
  151. package/dist/types/flow/index.d.ts +65 -0
  152. package/dist/types/index.d.ts +29 -4
  153. package/dist/types/locale.d.ts +34 -0
  154. package/dist/types/markdown/cjk-friendly.d.ts +6 -0
  155. package/dist/types/markdown/index.d.ts +11 -4
  156. package/dist/types/use-comments.d.ts +1 -0
  157. package/dist/use-comments.js +63 -9
  158. package/dist/use-comments.js.map +1 -1
  159. package/package.json +14 -5
@@ -1 +1 @@
1
- {"version":3,"file":"binding.js","names":[],"sources":["../../src/collaboration/binding.ts"],"sourcesContent":["import { Fragment, type Node as PMNode, type ResolvedPos, type Schema } from 'prosemirror-model'\nimport {\n Plugin,\n PluginKey,\n TextSelection,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport * as Y from 'yjs'\nimport { blockAround, findBlockById } from '../core/blocks'\nimport { createId } from '../core/model'\nimport { originKey } from '../core/editor'\nimport { ownStepKey } from '../core/transaction'\nimport { placeOf } from './cursors'\nimport { keysBetween, orderKeys } from './order'\nimport { cellAt, cellStart, clearTable, readTable, writeTable } from './table'\nimport { inlineFrom, insertInline, updateText, type Attributes } from './text'\n\n/*\n * How a document is stored in Yjs. Every block is one entry of a `Y.Map`,\n * by id, holding its type, its props, its text and its place: the id of its\n * parent and an order key among its siblings. Moving a block only changes\n * its place, so text typed into it meanwhile by someone else stays in it.\n *\n * map: Y.Map<id, Y.Map {\n * type: string\n * props: Y.Map<name, value>\n * text: Y.Text (marks as formatting attributes, inline nodes as embeds)\n * parent: string | null\n * order: string\n * }>\n *\n * Tables keep their rows, columns and cells in more entries; see `./table`.\n */\n\nexport type YBlock = Y.Map<unknown>\n\nconst ROOT = '\\u0000root'\n\nconst parentKey = (parent: string | null) => parent ?? ROOT\n\n/** The place of every block as the editor shows it, read from the document. */\ninterface Placed {\n /** The content node (paragraph, heading, …). */\n content: PMNode\n parent: string | null\n}\n\ninterface Index {\n blocks: Map<string, Placed>\n /** Child ids in order, by parent (`ROOT` for the top level). */\n children: Map<string, string[]>\n}\n\nfunction indexDoc(doc: PMNode): Index {\n const blocks = new Map<string, Placed>()\n const children = new Map<string, string[]>()\n const visit = (container: PMNode, parent: string | null) => {\n const ids: string[] = []\n container.forEach((block) => {\n const id = block.attrs.id as string\n ids.push(id)\n blocks.set(id, { content: block.firstChild!, parent })\n if (block.childCount > 1) visit(block.child(1), id)\n })\n children.set(parentKey(parent), ids)\n }\n visit(doc, null)\n return { blocks, children }\n}\n\n/** The content node a stored block stands for. Unknown types become paragraphs. */\nfunction contentFrom(yblock: YBlock, schema: Schema): PMNode {\n const name = yblock.get('type') as string\n const known = schema.nodes[name]\n const type = known?.isInGroup('blockContent') ? known : schema.nodes.paragraph!\n const props = (yblock.get('props') as Y.Map<unknown> | undefined)?.toJSON() ?? {}\n const attrs: Attributes = {}\n for (const attr of Object.keys(type.spec.attrs ?? {}))\n if (attr in props) attrs[attr] = props[attr]\n if (type.spec.rows) return readTable(yblock, type, attrs)\n if (!type.inlineContent) return type.create(attrs)\n const text = yblock.get('text') as Y.Text | undefined\n const inline = text ? inlineFrom(text, schema, !!type.spec.code) : []\n return type.createChecked(attrs, inline.length ? Fragment.from(inline) : null)\n}\n\nfunction writeContent(yblock: YBlock, content: PMNode) {\n yblock.set('type', content.type.name)\n const text = new Y.Text()\n yblock.set('text', text)\n if (content.type.spec.rows) {\n writeTable(yblock, null, content)\n return\n }\n const props = new Y.Map<unknown>()\n for (const [name, value] of Object.entries(content.attrs)) props.set(name, value)\n yblock.set('props', props)\n if (content.inlineContent) insertInline(text, 0, content, 0, content.content.size)\n}\n\n/**\n * Bring a stored block's type, props and text from `before` to `after`.\n * Returns whether the stored block holds more than `after` shows (see `writeTable`).\n */\nfunction updateContent(yblock: YBlock, before: PMNode, after: PMNode): boolean {\n if (before.type !== after.type) yblock.set('type', after.type.name)\n if (after.type.spec.rows)\n return writeTable(yblock, before.type === after.type ? before : null, after)\n clearTable(yblock)\n const props = yblock.get('props') as Y.Map<unknown>\n for (const [name, value] of Object.entries(after.attrs)) {\n if (JSON.stringify(props.get(name)) !== JSON.stringify(value)) props.set(name, value)\n }\n for (const name of Array.from(props.keys())) if (!(name in after.attrs)) props.delete(name)\n\n const text = yblock.get('text') as Y.Text\n if (!after.inlineContent) {\n if (text.length) text.delete(0, text.length)\n return false\n }\n updateText(text, before, after)\n return false\n}\n\n/* the stored tree → document */\n\n/**\n * Where every stored block goes. A parent that no longer exists (deleted\n * while someone moved a block into it) leaves the block at the top level;\n * a cycle (two blocks moved into each other at the same time) is broken at\n * its smallest id. Every client reads the same data the same way, so all\n * end up with the same tree.\n */\nfunction placeAll(map: Y.Map<YBlock>): Map<string, string[]> {\n const parentOf = new Map<string, string | null>()\n map.forEach((yblock, id) => {\n const parent = yblock.get('parent') as string | null | undefined\n parentOf.set(id, parent && parent !== id && map.has(parent) ? parent : null)\n })\n const settled = new Set<string>()\n for (const id of parentOf.keys()) {\n const path: string[] = []\n const onPath = new Set<string>()\n let current: string | null = id\n while (current !== null && !settled.has(current)) {\n if (onPath.has(current)) {\n const cycle = path.slice(path.indexOf(current))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh copy\n const breakAt = [...cycle].sort()[0]!\n parentOf.set(breakAt, null)\n break\n }\n path.push(current)\n onPath.add(current)\n current = parentOf.get(current) ?? null\n }\n for (const visited of path) settled.add(visited)\n }\n const children = new Map<string, string[]>()\n for (const [id, parent] of parentOf) {\n const key = parentKey(parent)\n const list = children.get(key)\n if (list) list.push(id)\n else children.set(key, [id])\n }\n const orderOf = (id: string) => (map.get(id)!.get('order') as string | undefined) ?? ''\n for (const list of children.values()) {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts our own list\n list.sort((a, b) => {\n const x = orderOf(a)\n const y = orderOf(b)\n return x < y ? -1 : x > y ? 1 : a < b ? -1 : a > b ? 1 : 0\n })\n }\n return children\n}\n\n/** Whether `$pos` is inside table structure below `depth`. */\nfunction inTable($pos: ResolvedPos, depth: number) {\n for (let d = $pos.depth; d > depth; d--) if ($pos.node(d).type.spec.tableRole) return true\n return false\n}\n\n/** A position as its table cell and offset in it, if it is in one. */\nfunction cellPlace(doc: PMNode, pos: number) {\n const info = blockAround(doc.resolve(pos))\n if (!info?.content.type.spec.rows) return null\n const cell = cellAt(info.content, pos - info.contentPos - 1)\n return cell && { block: info.node.attrs.id as string, ...cell }\n}\n\n/** Put a cursor that was in a replaced table back into its cell. */\nfunction keepCellSelection(state: EditorState, tr: Transaction) {\n const { selection } = state\n if (!(selection instanceof TextSelection)) return\n const back = (pos: number) => {\n const place = cellPlace(state.doc, pos)\n if (!place) return null\n const info = findBlockById(tr.doc, place.block)\n const cell = info && cellStart(info.content, place.key)\n return cell ? info.contentPos + 1 + cell.offset + Math.min(place.index, cell.size) : null\n }\n const anchor = back(selection.anchor)\n const head = back(selection.head)\n if (anchor !== null && head !== null) tr.setSelection(TextSelection.create(tr.doc, anchor, head))\n}\n\n/* the binding */\n\nexport const collaborationKey = new PluginKey<{\n remote: boolean\n tracked: boolean\n /** An undo step of its own (`transact`). */\n own: boolean\n}>('dou-editor-collaboration')\n\nexport interface Binding {\n map: Y.Map<YBlock>\n /** The origin of this editor's own changes; the undo manager tracks it. */\n origin: object\n /** The origin of changes that are not undone (`setBlocks`, fixes). */\n untracked: object\n view: EditorView | null\n /** Ends the current undo step, so a structural change is undone on its own. */\n stopCapturing?: () => void\n /** Where the cursor was before the change being written, for undo to return to. */\n selectionBefore?: unknown\n /** Set while the undo manager takes a step back or forward. */\n undoing?: 'undo' | 'redo'\n}\n\nexport function createBinding(map: Y.Map<YBlock>): Binding {\n return { map, origin: { binding: 'tracked' }, untracked: { binding: 'untracked' }, view: null }\n}\n\n/** Write the blocks of `doc` into an empty map. */\nexport function writeDoc(map: Y.Map<YBlock>, doc: PMNode) {\n const index = indexDoc(doc)\n map.doc!.transact(() => {\n for (const [key, ids] of index.children) {\n const keys = keysBetween(null, null, ids.length)\n ids.forEach((id, i) => {\n const yblock = new Y.Map<unknown>()\n map.set(id, yblock)\n yblock.set('parent', key === ROOT ? null : key)\n yblock.set('order', keys[i])\n writeContent(yblock, index.blocks.get(id)!.content)\n })\n }\n })\n}\n\n/** The document a map holds, read without an editor; `null` while the map is empty. */\nexport function readDoc(map: Y.Map<YBlock>, schema: Schema): PMNode | null {\n const children = placeAll(map)\n const build = (id: string): PMNode => {\n const content = contentFrom(map.get(id)!, schema)\n const kids = children.get(id)\n const parts = kids?.length\n ? [content, schema.nodes.blockGroup!.create(null, kids.map(build))]\n : [content]\n return schema.nodes.block!.create({ id }, parts)\n }\n const top = children.get(ROOT) ?? []\n return top.length ? schema.nodes.doc!.create(null, top.map(build)) : null\n}\n\nexport function syncPlugin(binding: Binding): Plugin {\n const { map } = binding\n const ydoc = map.doc!\n let schema: Schema\n // the document as last written to or read from the map\n let synced: Index | null = null\n // content nodes read from the map, by id, until the block changes there\n const cache = new Map<string, PMNode>()\n let placeholderId = createId()\n\n function buildDoc(): PMNode {\n const children = placeAll(map)\n const build = (id: string): PMNode => {\n let content = cache.get(id)\n if (!content) {\n content = contentFrom(map.get(id)!, schema)\n cache.set(id, content)\n }\n const kids = children.get(id)\n const parts = kids?.length\n ? [content, schema.nodes.blockGroup!.create(null, kids.map(build))]\n : [content]\n return schema.nodes.block!.create({ id }, parts)\n }\n const top = children.get(ROOT) ?? []\n // an empty map still shows one empty paragraph; it is stored once typed in\n const blocks = top.length\n ? top.map(build)\n : [schema.nodes.block!.create({ id: placeholderId }, schema.nodes.paragraph!.create())]\n return schema.nodes.doc!.create(null, blocks)\n }\n\n /** Show the map's current state in the editor. */\n function readMap(view: EditorView) {\n const doc = view.state.doc\n const next = buildDoc()\n const start = doc.content.findDiffStart(next.content)\n if (start !== null) {\n const end = doc.content.findDiffEnd(next.content)!\n const overlap = start - Math.min(end.a, end.b)\n if (overlap > 0) {\n end.a += overlap\n end.b += overlap\n }\n let from = start\n let to = end.a\n const $from = doc.resolve(from)\n const $to = doc.resolve(to)\n const shared = $from.sharedDepth(to)\n // a change across table cells or rows: swap them whole, a partial cut breaks the grid\n if (!$from.node(shared).inlineContent && (inTable($from, shared) || inTable($to, shared))) {\n if ($from.depth > shared) from = $from.before(shared + 1)\n if ($to.depth > shared) to = $to.after(shared + 1)\n }\n const tail = doc.content.size - to\n const tr = view.state.tr.replace(from, to, next.slice(from, next.content.size - tail))\n if (to !== end.a || from !== start) keepCellSelection(view.state, tr)\n tr.setMeta(collaborationKey, { remote: true })\n tr.setMeta('remote', true)\n // this user's undo comes back through the shared document too\n if (binding.undoing) tr.setMeta(originKey, binding.undoing)\n tr.setMeta('addToHistory', false)\n view.dispatch(tr)\n }\n synced = indexDoc(view.state.doc)\n }\n\n /** Write the editor's changes since the last sync into the map. */\n function writeMap(view: EditorView, tracked: boolean) {\n const doc = view.state.doc\n const before = synced ?? indexDoc(doc)\n const after = indexDoc(doc)\n // moving, indenting or adding blocks is an undo step of its own\n let structural = false\n for (const [key, ids] of after.children) {\n const old = before.children.get(key)\n if (!old || old.length !== ids.length || old.some((id, i) => ids[i] !== id)) structural = true\n }\n if (structural) binding.stopCapturing?.()\n // blocks that hold more than the editor shows, to be read back\n const stale: string[] = []\n ydoc.transact(\n () => {\n for (const [id, placed] of after.blocks) {\n const yblock = map.get(id)\n const old = before.blocks.get(id)\n if (!yblock) {\n const created = new Y.Map<unknown>()\n map.set(id, created)\n writeContent(created, placed.content)\n } else if (old && old.content !== placed.content) {\n if (updateContent(yblock, old.content, placed.content)) stale.push(id)\n } else if (!old) {\n // stored, but not shown before (e.g. the empty placeholder came back)\n if (updateContent(yblock, contentFrom(yblock, schema), placed.content)) stale.push(id)\n }\n cache.set(id, placed.content)\n }\n for (const id of before.blocks.keys()) {\n if (!after.blocks.has(id)) {\n map.delete(id)\n cache.delete(id)\n }\n }\n // places: only lists that changed, and only the blocks that moved in them\n for (const [key, ids] of after.children) {\n const old = before.children.get(key)\n if (old && old.length === ids.length && old.every((id, i) => ids[i] === id)) {\n if (ids.every((id) => map.get(id)!.get('order') !== undefined)) continue\n }\n const parent = key === ROOT ? null : key\n const keys = ids.map((id) => {\n const yblock = map.get(id)!\n const order = yblock.get('order') as string | undefined\n return yblock.get('parent') === parent && order !== undefined ? order : null\n })\n const next = orderKeys(keys)\n ids.forEach((id, index) => {\n if (keys[index] === next[index]) return\n const yblock = map.get(id)!\n if (yblock.get('parent') !== parent) yblock.set('parent', parent)\n yblock.set('order', next[index])\n })\n }\n },\n tracked ? binding.origin : binding.untracked,\n )\n if (structural) binding.stopCapturing?.()\n synced = after\n if (stale.length) {\n for (const id of stale) cache.delete(id)\n // not from inside this update: show the rest once it is done\n queueMicrotask(() => {\n if (binding.view === view) readMap(view)\n })\n }\n }\n\n return new Plugin({\n key: collaborationKey,\n state: {\n init: () => ({ remote: false, tracked: false, own: false }),\n apply(tr, value) {\n const meta = tr.getMeta(collaborationKey) as { remote?: boolean } | undefined\n if (!tr.docChanged) return value\n if (meta?.remote) return { remote: true, tracked: false, own: false }\n // a transaction can come with appended ones (e.g. id fixes), written\n // together: undone together if any of them is\n const tracked = tr.getMeta('addToHistory') !== false\n const own = tr.getMeta(ownStepKey) === true\n const appended = !!tr.getMeta('appendedTransaction') && !value.remote\n return appended\n ? { remote: false, tracked: value.tracked || tracked, own: value.own || own }\n : { remote: false, tracked, own }\n },\n },\n view(view) {\n schema = view.state.schema\n binding.view = view\n const observer = (\n events: Y.YEvent<Y.AbstractType<unknown>>[],\n transaction: Y.Transaction,\n ) => {\n if (transaction.origin === binding.origin || transaction.origin === binding.untracked)\n return\n // forget the cached content of every block that changed\n for (const event of events) {\n if (event.target === map) {\n for (const id of (event as Y.YMapEvent<unknown>).keysChanged) cache.delete(id)\n continue\n }\n // the path from the map starts with the block's id\n const id = event.path[0]\n if (typeof id === 'string') cache.delete(id)\n }\n readMap(view)\n }\n map.observeDeep(observer)\n if (map.size) readMap(view)\n else synced = indexDoc(view.state.doc)\n placeholderId = (view.state.doc.firstChild?.attrs.id as string | undefined) ?? placeholderId\n return {\n update(current, previous: EditorState) {\n if (current.state.doc === previous.doc) return\n const state = collaborationKey.getState(current.state)!\n if (state.remote) {\n synced = indexDoc(current.state.doc)\n return\n }\n // read before writing: the map still holds the previous text\n binding.selectionBefore = placeOf(binding, previous.doc, previous.selection.head)\n if (state.own) binding.stopCapturing?.()\n writeMap(current, state.tracked)\n if (state.own) binding.stopCapturing?.()\n },\n destroy() {\n map.unobserveDeep(observer)\n binding.view = null\n },\n }\n },\n })\n}\n\nexport type { Transaction }\n"],"mappings":";;;;;;;;;;;;AAsCA,IAAM,OAAO;AAEb,IAAM,aAAa,WAA0B,UAAU;AAevD,SAAS,SAAS,KAAoB;CACpC,MAAM,yBAAS,IAAI,IAAoB;CACvC,MAAM,2BAAW,IAAI,IAAsB;CAC3C,MAAM,SAAS,WAAmB,WAA0B;EAC1D,MAAM,MAAgB,CAAC;EACvB,UAAU,SAAS,UAAU;GAC3B,MAAM,KAAK,MAAM,MAAM;GACvB,IAAI,KAAK,EAAE;GACX,OAAO,IAAI,IAAI;IAAE,SAAS,MAAM;IAAa;GAAO,CAAC;GACrD,IAAI,MAAM,aAAa,GAAG,MAAM,MAAM,MAAM,CAAC,GAAG,EAAE;EACpD,CAAC;EACD,SAAS,IAAI,UAAU,MAAM,GAAG,GAAG;CACrC;CACA,MAAM,KAAK,IAAI;CACf,OAAO;EAAE;EAAQ;CAAS;AAC5B;;AAGA,SAAS,YAAY,QAAgB,QAAwB;CAC3D,MAAM,OAAO,OAAO,IAAI,MAAM;CAC9B,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,OAAO,OAAO,UAAU,cAAc,IAAI,QAAQ,OAAO,MAAM;CACrE,MAAM,QAAS,OAAO,IAAI,OAAO,CAAC,EAAiC,OAAO,KAAK,CAAC;CAChF,MAAM,QAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,KAAK,SAAS,CAAC,CAAC,GAClD,IAAI,QAAQ,OAAO,MAAM,QAAQ,MAAM;CACzC,IAAI,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AC1B,IAAI,MAAM,WAAW,KAAK;MACxB,KAAK,MAAM,MAAO,MAA+B,aAAa,MAAM,OAAO,EAAE;MAC7E;KACF;KAEA,MAAM,KAAK,MAAM,KAAK;KACtB,IAAI,OAAO,OAAO,UAAU,MAAM,OAAO,EAAE;IAC7C;IACA,QAAQ,IAAI;GACd;GACA,IAAI,YAAY,QAAQ;GACxB,IAAI,IAAI,MAAM,QAAQ,IAAI;QACrB,SAAS,SAAS,KAAK,MAAM,GAAG;GACrC,gBAAiB,KAAK,MAAM,IAAI,YAAY,MAAM,MAA6B;GAC/E,OAAO;IACL,OAAO,SAAS,UAAuB;KACrC,IAAI,QAAQ,MAAM,QAAQ,SAAS,KAAK;KACxC,MAAM,QAAQ,iBAAiB,SAAS,QAAQ,KAAK;KACrD,IAAI,MAAM,QAAQ;MAChB,SAAS,SAAS,QAAQ,MAAM,GAAG;MACnC;KACF;KAEA,QAAQ,kBAAkB,QAAQ,SAAS,SAAS,KAAK,SAAS,UAAU,IAAI;KAChF,IAAI,MAAM,KAAK,QAAQ,gBAAgB;KACvC,SAAS,SAAS,MAAM,OAAO;KAC/B,IAAI,MAAM,KAAK,QAAQ,gBAAgB;IACzC;IACA,UAAU;KACR,IAAI,cAAc,QAAQ;KAC1B,QAAQ,OAAO;IACjB;GACF;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"binding.js","names":["keepComments"],"sources":["../../src/collaboration/binding.ts"],"sourcesContent":["import { Fragment, type Node as PMNode, type ResolvedPos, type Schema } from 'prosemirror-model'\nimport {\n Plugin,\n PluginKey,\n TextSelection,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport * as Y from 'yjs'\nimport { blockAround, findBlockById } from '../core/blocks'\nimport { createId } from '../core/model'\nimport { originKey } from '../core/editor'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { placeOf } from './cursors'\nimport { keptIndexes, keysBetween, orderKeys } from './order'\nimport { mergedPropsOf, newMerged, readMerged, writeMerged } from './merged-props'\nimport { cellAt, cellStart, clearTable, prepareTableText, readTable, writeTable } from './table'\nimport {\n inlineFrom,\n insertInline,\n keepInlineComments as keepComments,\n prepareTextFromBase,\n updateText,\n type Attributes,\n type TextUpdatePlan,\n} from './text'\nimport { createDiffBudget } from './inline-diff'\n\n/*\n * How a document is stored in Yjs. Every block is one entry of a `Y.Map`,\n * by id, holding its type, its props, its text and its place: the id of its\n * parent and an order key among its siblings. Moving a block only changes\n * its place, so text typed into it meanwhile by someone else stays in it.\n *\n * map: Y.Map<id, Y.Map {\n * type: string\n * props: Y.Map<name, value>\n * text: Y.Text (marks as formatting attributes, inline nodes as embeds)\n * parent: string | null\n * order: string\n * }>\n *\n * Tables keep their rows, columns and cells in more entries; see `./table`.\n * Props a block type merges item by item are maps too; see `./merged-props`.\n */\n\nexport type YBlock = Y.Map<unknown>\n\nconst ROOT = '\\u0000root'\n\nconst parentKey = (parent: string | null) => parent ?? ROOT\n\n/** The place of every block as the editor shows it, read from the document. */\ninterface Placed {\n /** The content node (paragraph, heading, …). */\n content: PMNode\n parent: string | null\n}\n\ninterface Index {\n blocks: Map<string, Placed>\n /** Child ids in order, by parent (`ROOT` for the top level). */\n children: Map<string, string[]>\n}\n\nfunction indexDoc(doc: PMNode): Index {\n const blocks = new Map<string, Placed>()\n const children = new Map<string, string[]>()\n const visit = (container: PMNode, parent: string | null) => {\n const ids: string[] = []\n container.forEach((block) => {\n const id = block.attrs.id as string\n ids.push(id)\n blocks.set(id, { content: block.firstChild!, parent })\n if (block.childCount > 1) visit(block.child(1), id)\n })\n children.set(parentKey(parent), ids)\n }\n visit(doc, null)\n return { blocks, children }\n}\n\n/** The content node a stored block stands for. Unknown types become paragraphs. */\nfunction contentFrom(yblock: YBlock, schema: Schema): PMNode {\n const name = yblock.get('type') as string\n const known = schema.nodes[name]\n const type = known?.isInGroup('blockContent') ? known : schema.nodes.paragraph!\n const stored = yblock.get('props') as Y.Map<unknown> | undefined\n const props = stored?.toJSON() ?? {}\n const merged = mergedPropsOf(type)\n const attrs: Attributes = {}\n for (const attr of Object.keys(type.spec.attrs ?? {})) {\n if (!(attr in props)) continue\n const spec = merged?.[attr]\n attrs[attr] = spec ? readMerged(stored!.get(attr), spec) : props[attr]\n }\n if (type.spec.rows) return readTable(yblock, type, attrs)\n if (!type.inlineContent) return type.create(attrs)\n const text = yblock.get('text') as Y.Text | undefined\n const inline = text ? inlineFrom(text, schema, !!type.spec.code) : []\n return type.createChecked(attrs, inline.length ? Fragment.from(inline) : null)\n}\n\nfunction writeContent(yblock: YBlock, content: PMNode) {\n yblock.set('type', content.type.name)\n const text = new Y.Text()\n yblock.set('text', text)\n if (content.type.spec.rows) {\n writeTable(yblock, null, content)\n return\n }\n const props = new Y.Map<unknown>()\n const merged = mergedPropsOf(content.type)\n yblock.set('props', props)\n for (const [name, value] of Object.entries(content.attrs)) {\n const spec = merged?.[name]\n props.set(name, spec ? newMerged(value, spec) : value)\n }\n if (content.inlineContent) insertInline(text, 0, content, 0, content.content.size)\n}\n\n/**\n * Bring a stored block's type, props and text from `before` to `after`.\n * Returns whether the stored block holds more than `after` shows (see `writeTable`).\n */\nfunction updateContent(\n yblock: YBlock,\n before: PMNode,\n after: PMNode,\n current = before,\n plans?: Map<Y.Text, TextUpdatePlan>,\n): boolean {\n if (before.type !== after.type) yblock.set('type', after.type.name)\n if (after.type.spec.rows)\n return writeTable(yblock, before.type === after.type ? before : null, after, plans)\n clearTable(yblock)\n const props = yblock.get('props') as Y.Map<unknown>\n const merged = mergedPropsOf(after.type)\n for (const [name, value] of Object.entries(after.attrs)) {\n const spec = merged?.[name]\n if (spec)\n writeMerged(\n props,\n name,\n spec,\n value,\n before.type === after.type ? before.attrs[name] : undefined,\n )\n else if (\n before.type !== after.type ||\n JSON.stringify(before.attrs[name]) !== JSON.stringify(value)\n )\n props.set(name, value)\n }\n for (const name of Array.from(props.keys())) if (!(name in after.attrs)) props.delete(name)\n\n const text = yblock.get('text') as Y.Text\n if (!after.inlineContent) {\n if (text.length) text.delete(0, text.length)\n return false\n }\n const plan = plans?.get(text)\n if (plan) plan(text)\n else updateText(text, current, after)\n return false\n}\n\n/* the stored tree → document */\n\n/**\n * Where every stored block goes. A parent that no longer exists (deleted\n * while someone moved a block into it) leaves the block at the top level;\n * a cycle (two blocks moved into each other at the same time) is broken at\n * its smallest id. Every client reads the same data the same way, so all\n * end up with the same tree.\n */\nfunction placeAll(map: Y.Map<YBlock>): Map<string, string[]> {\n const parentOf = new Map<string, string | null>()\n map.forEach((yblock, id) => {\n const parent = yblock.get('parent') as string | null | undefined\n parentOf.set(id, parent && parent !== id && map.has(parent) ? parent : null)\n })\n const settled = new Set<string>()\n for (const id of parentOf.keys()) {\n const path: string[] = []\n const onPath = new Set<string>()\n let current: string | null = id\n while (current !== null && !settled.has(current)) {\n if (onPath.has(current)) {\n const cycle = path.slice(path.indexOf(current))\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh copy\n const breakAt = [...cycle].sort()[0]!\n parentOf.set(breakAt, null)\n break\n }\n path.push(current)\n onPath.add(current)\n current = parentOf.get(current) ?? null\n }\n for (const visited of path) settled.add(visited)\n }\n const children = new Map<string, string[]>()\n for (const [id, parent] of parentOf) {\n const key = parentKey(parent)\n const list = children.get(key)\n if (list) list.push(id)\n else children.set(key, [id])\n }\n const orderOf = (id: string) => (map.get(id)!.get('order') as string | undefined) ?? ''\n for (const list of children.values()) {\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts our own list\n list.sort((a, b) => {\n const x = orderOf(a)\n const y = orderOf(b)\n return x < y ? -1 : x > y ? 1 : a < b ? -1 : a > b ? 1 : 0\n })\n }\n return children\n}\n\n/** Whether `$pos` is inside table structure below `depth`. */\nfunction inTable($pos: ResolvedPos, depth: number) {\n for (let d = $pos.depth; d > depth; d--) if ($pos.node(d).type.spec.tableRole) return true\n return false\n}\n\n/** A position as its table cell and offset in it, if it is in one. */\nfunction cellPlace(doc: PMNode, pos: number) {\n const info = blockAround(doc.resolve(pos))\n if (!info?.content.type.spec.rows) return null\n const cell = cellAt(info.content, pos - info.contentPos - 1)\n return cell && { block: info.node.attrs.id as string, ...cell }\n}\n\n/** Put a cursor that was in a replaced table back into its cell. */\nfunction keepCellSelection(state: EditorState, tr: Transaction) {\n const { selection } = state\n if (!(selection instanceof TextSelection)) return\n const back = (pos: number) => {\n const place = cellPlace(state.doc, pos)\n if (!place) return null\n const info = findBlockById(tr.doc, place.block)\n const cell = info && cellStart(info.content, place.key)\n return cell ? info.contentPos + 1 + cell.offset + Math.min(place.index, cell.size) : null\n }\n const anchor = back(selection.anchor)\n const head = back(selection.head)\n if (anchor !== null && head !== null) tr.setSelection(TextSelection.create(tr.doc, anchor, head))\n}\n\n/* the binding */\n\nexport const collaborationKey = new PluginKey<{\n remote: boolean\n tracked: boolean\n /** An undo step of its own (`transact`). */\n own: boolean\n /** Joins the undo step before (the frames of a drag on a whiteboard). */\n join: boolean\n}>('dou-editor-collaboration')\n\nexport interface Binding {\n map: Y.Map<YBlock>\n /** The origin of this editor's own changes; the undo manager tracks it. */\n origin: object\n /** The origin of changes that are not undone (`setBlocks`, fixes). */\n untracked: object\n view: EditorView | null\n /** Ends the current undo step, so a structural change is undone on its own. */\n stopCapturing?: () => void\n /** Makes the next change join the current undo step. */\n joinCapturing?: () => void\n /** Where the cursor was before the change being written, for undo to return to. */\n selectionBefore?: unknown\n /** Set while the undo manager takes a step back or forward. */\n undoing?: 'undo' | 'redo'\n}\n\nexport function createBinding(map: Y.Map<YBlock>): Binding {\n return { map, origin: { binding: 'tracked' }, untracked: { binding: 'untracked' }, view: null }\n}\n\n/** Write the blocks of `doc` into an empty map. */\nexport function writeDoc(map: Y.Map<YBlock>, doc: PMNode) {\n const index = indexDoc(doc)\n map.doc!.transact(() => {\n for (const [key, ids] of index.children) {\n const keys = keysBetween(null, null, ids.length)\n ids.forEach((id, i) => {\n const yblock = new Y.Map<unknown>()\n map.set(id, yblock)\n yblock.set('parent', key === ROOT ? null : key)\n yblock.set('order', keys[i])\n writeContent(yblock, index.blocks.get(id)!.content)\n })\n }\n })\n}\n\n/**\n * Write the changes from `before` to `after` into the map: the content of\n * blocks that changed, blocks added and removed, and the places of the\n * blocks that moved. Returns the blocks that hold more than `after` shows,\n * to be read back (see `writeTable`). Call it inside a transaction.\n */\nfunction writeChanges(map: Y.Map<YBlock>, before: Index, after: Index, schema: Schema): string[] {\n const stale: string[] = []\n for (const [id, placed] of after.blocks) {\n const yblock = map.get(id)\n const old = before.blocks.get(id)\n if (!yblock) {\n const created = new Y.Map<unknown>()\n map.set(id, created)\n writeContent(created, placed.content)\n } else if (old && old.content !== placed.content) {\n if (updateContent(yblock, old.content, placed.content)) stale.push(id)\n } else if (!old) {\n // stored, but not shown before (e.g. the empty placeholder came back)\n if (updateContent(yblock, contentFrom(yblock, schema), placed.content)) stale.push(id)\n }\n }\n for (const id of before.blocks.keys()) if (!after.blocks.has(id)) map.delete(id)\n // places: only lists that changed, and only the blocks that moved in them\n for (const [key, ids] of after.children) {\n const old = before.children.get(key)\n if (old && old.length === ids.length && old.every((id, i) => ids[i] === id)) {\n if (ids.every((id) => map.get(id)!.get('order') !== undefined)) continue\n }\n const parent = key === ROOT ? null : key\n const keys = ids.map((id) => {\n const yblock = map.get(id)!\n const order = yblock.get('order') as string | undefined\n return yblock.get('parent') === parent && order !== undefined ? order : null\n })\n const next = orderKeys(keys)\n ids.forEach((id, index) => {\n if (keys[index] === next[index]) return\n const yblock = map.get(id)!\n if (yblock.get('parent') !== parent) yblock.set('parent', parent)\n yblock.set('order', next[index])\n })\n }\n return stale\n}\n\n/* writing a new version from elsewhere, without an editor (`updateMap`) */\n\n/** The content node of block `id`. */\nconst contentOf = (index: Index, id: string) => index.blocks.get(id)!.content\n\n/** A content node as a string, to tell equal blocks apart quickly. */\nconst keyOf = (content: PMNode) => JSON.stringify(content.toJSON())\n\n/**\n * Pairs of `a` and `b` with equal keys, in the order of both: the equal\n * start and end, then in the middle each of `a` with the first free equal\n * one of `b`, keeping the longest run in order. Indexes into `a` and `b`;\n * about linear, so a long document stays fast.\n */\nfunction equalPairs(a: string[], b: string[]): [number, number][] {\n const pairs: [number, number][] = []\n let start = 0\n while (start < a.length && start < b.length && a[start] === b[start]) {\n pairs.push([start, start])\n start++\n }\n let endA = a.length\n let endB = b.length\n const tail: [number, number][] = []\n while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {\n endA--\n endB--\n tail.push([endA, endB])\n }\n // the middle: each of `a` takes the first free equal one of `b`, then the\n // longest run increasing in `b` stays\n const free = new Map<string, number[]>()\n for (let j = endB - 1; j >= start; j--) {\n const list = free.get(b[j]!)\n if (list) list.push(j)\n else free.set(b[j]!, [j])\n }\n const middle: [number, number][] = []\n for (let i = start; i < endA; i++) {\n const j = free.get(a[i]!)?.pop()\n if (j !== undefined) middle.push([i, j])\n }\n const kept = keptIndexes(middle.map(([, j]) => String(j).padStart(10, '0')))\n middle.forEach((pair, index) => kept.has(index) && pairs.push(pair))\n for (let k = tail.length - 1; k >= 0; k--) pairs.push(tail[k]!)\n return pairs\n}\n\n/** How alike two texts are, 0 to 1, by the pairs of letters they share. */\nfunction likeness(a: string, b: string): number {\n if (a === b) return 1\n if (a.length < 2 || b.length < 2) return 0\n const pairs = new Map<string, number>()\n for (let i = 0; i < a.length - 1; i++) {\n const pair = a.slice(i, i + 2)\n pairs.set(pair, (pairs.get(pair) ?? 0) + 1)\n }\n let shared = 0\n for (let i = 0; i < b.length - 1; i++) {\n const pair = b.slice(i, i + 2)\n const left = pairs.get(pair)\n if (left) {\n shared++\n pairs.set(pair, left - 1)\n }\n }\n return (2 * shared) / (a.length + b.length - 2)\n}\n\n/** How alike two blocks must be to count as one edited. */\nconst ALIKE = 0.4\n/** How many stored blocks ahead a block is looked for between two equal ones. */\nconst LOOK_AHEAD = 32\n/** How alike a block moved out of its order must be to count as the same one edited. */\nconst MOVED_ALIKE = 0.8\n/** The most comparisons spent on blocks moved out of their order. */\nconst MOVED_PAIRS = 40_000\n\n/**\n * Which block of `before` each block of `after` stands for: by id when it\n * keeps one, otherwise by place among the blocks of the same parent: first\n * the blocks with equal content, kept in order, then between those, each\n * block with the most alike one of its type further on (its text is\n * changed in place). A block with nothing alike enough is new. Returns\n * new id → old id.\n */\nfunction matchBlocks(before: Index, after: Index): Map<string, string> {\n const match = new Map<string, string>()\n const used = new Set<string>()\n for (const id of after.blocks.keys())\n if (before.blocks.has(id)) {\n match.set(id, id)\n used.add(id)\n }\n const pair = (a: string, b: string) => {\n match.set(a, b)\n used.add(b)\n }\n const visit = (key: string, oldKey: string | null) => {\n const ids = after.children.get(key) ?? []\n const fresh = ids.filter((id) => !match.has(id))\n const olds = (oldKey === null ? [] : (before.children.get(oldKey) ?? [])).filter(\n (id) => !used.has(id),\n )\n const anchors = equalPairs(\n fresh.map((id) => keyOf(contentOf(after, id))),\n olds.map((id) => keyOf(contentOf(before, id))),\n )\n let i = 0\n let j = 0\n for (const [ai, aj] of [...anchors, [fresh.length, olds.length] as [number, number]]) {\n // between two equal blocks: each takes the most alike block of its type ahead\n for (; i < ai; i++) {\n const node = contentOf(after, fresh[i]!)\n const text = node.textContent\n let best = -1\n let score = ALIKE\n for (let k = j; k < Math.min(aj, j + LOOK_AHEAD); k++) {\n const old = contentOf(before, olds[k]!)\n if (old.type !== node.type) continue\n const like = likeness(text, old.textContent)\n if (like > score || (best < 0 && like >= score)) {\n best = k\n score = like\n }\n }\n if (best >= 0) {\n pair(fresh[i]!, olds[best]!)\n j = best + 1\n }\n }\n if (ai < fresh.length) pair(fresh[ai]!, olds[aj]!)\n i = ai + 1\n j = aj + 1\n }\n // what is left: blocks moved past others, e.g. paragraphs put in another order;\n // the same content first, then very alike text, wherever it is in the list\n const leftNew = fresh.filter((id) => !match.has(id))\n const leftOld = olds.filter((id) => !used.has(id))\n if (leftNew.length && leftOld.length) {\n const byKey = new Map<string, string[]>()\n // last first, so `pop` takes them in order\n for (let k = leftOld.length - 1; k >= 0; k--) {\n const id = leftOld[k]!\n const text = keyOf(contentOf(before, id))\n const list = byKey.get(text)\n if (list) list.push(id)\n else byKey.set(text, [id])\n }\n const rest: string[] = []\n for (const id of leftNew) {\n const old = byKey.get(keyOf(contentOf(after, id)))?.pop()\n if (old) pair(id, old)\n else rest.push(id)\n }\n if (rest.length * leftOld.length <= MOVED_PAIRS)\n for (const id of rest) {\n const node = contentOf(after, id)\n let best: string | null = null\n let score = MOVED_ALIKE\n for (const old of leftOld) {\n if (used.has(old) || contentOf(before, old).type !== node.type) continue\n const like = likeness(node.textContent, contentOf(before, old).textContent)\n if (like >= score) {\n best = old\n score = like\n }\n }\n if (best) pair(id, best)\n }\n }\n for (const id of ids) if (after.children.has(id)) visit(id, match.get(id) ?? null)\n }\n visit(ROOT, ROOT)\n return match\n}\n\n/** Every block id in `index` under `id`, at any depth. */\nfunction descendants(index: Index, id: string, out: string[] = []): string[] {\n for (const child of index.children.get(id) ?? []) {\n out.push(child)\n descendants(index, child, out)\n }\n return out\n}\n\n/**\n * Change the map from `base` to `doc`, leaving what changed in the map since\n * `base` was read: blocks of `doc` are matched to those of `base` (see\n * `matchBlocks`), and those of `base` to the stored ones; only blocks that\n * differ between `base` and `doc` are written, removed or moved. Without\n * `base`, the map as it is now. Call it inside a transaction.\n */\nexport function updateDoc(map: Y.Map<YBlock>, doc: PMNode, schema: Schema, base?: PMNode | null) {\n const current = readDoc(map, schema)\n if (!current) return void writeDoc(map, doc)\n const now = indexDoc(current)\n const from = base ? indexDoc(base) : now\n const to = indexDoc(doc)\n const toBase = matchBlocks(from, to)\n const baseToNow = base ? matchBlocks(now, from) : null\n /** The stored block a block of `base` is now, if it still is. */\n const nowOf = (old: string) => {\n const there = baseToNow ? baseToNow.get(old) : old\n return there !== undefined && now.blocks.has(there) ? there : null\n }\n /** The stored block each block of `doc` is written to. */\n const stored = new Map<string, string>()\n for (const [id, old] of toBase) {\n const there = nowOf(old)\n if (there) stored.set(id, there)\n }\n // removed by someone else since `base`: it stays removed, even if `doc`\n // changed it, and so do the blocks `doc` adds under it\n const gone = new Set<string>()\n const walk = (key: string, inGone: boolean) => {\n for (const id of to.children.get(key) ?? []) {\n const old = toBase.get(id)\n const lost = (old !== undefined && !stored.has(id)) || (inGone && !stored.has(id))\n if (lost) gone.add(id)\n walk(id, lost)\n }\n }\n walk(ROOT, false)\n // ids of `doc` for its new blocks: kept unless the map has them already\n for (const id of to.blocks.keys())\n if (!stored.has(id) && !gone.has(id)) stored.set(id, map.has(id) ? createId() : id)\n const kept = new Set(stored.values())\n const inDoc = new Set(toBase.values())\n\n // Plan every content change before touching the shared map. Exact\n // diff has a work limit; exceeding it must reject the whole write.\n const budget = createDiffBudget()\n const contentUpdates = new Map<string, { before: PMNode; after: PMNode; current: PMNode }>()\n const textPlans = new Map<Y.Text, TextUpdatePlan>()\n for (const [id, placed] of to.blocks) {\n if (gone.has(id)) continue\n const target = stored.get(id)!\n const there = now.blocks.get(target)?.content\n if (!there) continue\n const old = toBase.get(id)\n const was = old !== undefined ? from.blocks.get(old)!.content : null\n const compared = was ? keepComments(was, placed.content, budget) : placed.content\n if (was && compared.eq(was)) continue\n const before = was && was.type === there.type && was.type === placed.content.type ? was : there\n const after = before === was ? compared : keepComments(before, placed.content, budget)\n const yblock = map.get(target)!\n contentUpdates.set(id, { before, after, current: there })\n if (after.type.spec.rows) {\n prepareTableText(yblock, before.type === after.type ? before : null, after, textPlans, budget)\n } else if (after.inlineContent) {\n const text = yblock.get('text') as Y.Text\n const currentInline = there.inlineContent\n ? there\n : after.type.create(after.attrs, inlineFrom(text, schema, !!after.type.spec.code))\n const baseInline = before.inlineContent ? before : currentInline\n textPlans.set(text, prepareTextFromBase(baseInline, after, currentInline, budget))\n }\n }\n\n // removed: what `base` had and `doc` hasn't, with what is stored under it\n for (const old of from.blocks.keys()) {\n const there = inDoc.has(old) ? null : nowOf(old)\n if (!there) continue\n for (const id of [there, ...descendants(now, there)])\n if (!kept.has(id) && map.has(id)) map.delete(id)\n }\n\n // content: new blocks written, those changed since `base` brought to `doc`\n for (const [id, placed] of to.blocks) {\n if (gone.has(id)) continue\n const target = stored.get(id)!\n const yblock = map.get(target)\n if (!now.blocks.has(target)) {\n const created = new Y.Map<unknown>()\n map.set(target, created)\n writeContent(created, placed.content)\n continue\n }\n const update = contentUpdates.get(id)\n if (update) updateContent(yblock!, update.before, update.after, update.current, textPlans)\n }\n\n // places: in each list of `doc`, the blocks new there or out of their order in `base`\n for (const [key, all] of to.children) {\n if (gone.has(key)) continue\n const ids = all.filter((id) => !gone.has(id))\n const parent = key === ROOT ? null : stored.get(key)!\n const oldParent = key === ROOT ? ROOT : toBase.get(key)\n const siblings = oldParent === undefined ? [] : (from.children.get(oldParent) ?? [])\n const at = new Map(siblings.map((id, index) => [id, index]))\n const inBase = ids.map((id) => {\n const old = toBase.get(id)\n return old !== undefined && at.has(old) ? String(at.get(old)!).padStart(10, '0') : null\n })\n const stays = keptIndexes(inBase)\n const moved = new Set(ids.filter((_, index) => !stays.has(index)).map((id) => stored.get(id)!))\n if (!moved.size) continue\n // the stored list, without what goes elsewhere, with the moved ones put after their neighbour in `doc`\n const list = (now.children.get(parentKey(parent)) ?? []).filter(\n (id) => map.has(id) && !moved.has(id),\n )\n let previous: string | null = null\n for (const id of ids) {\n const target = stored.get(id)!\n if (moved.has(target))\n list.splice(previous === null ? 0 : list.indexOf(previous) + 1, 0, target)\n if (list.includes(target)) previous = target\n }\n const keys = list.map((id) => {\n const yblock = map.get(id)!\n const order = yblock.get('order') as string | undefined\n return !moved.has(id) && yblock.get('parent') === parent && order !== undefined ? order : null\n })\n const next = orderKeys(keys)\n list.forEach((id, index) => {\n if (keys[index] === next[index]) return\n const yblock = map.get(id)!\n if (yblock.get('parent') !== parent) yblock.set('parent', parent)\n yblock.set('order', next[index])\n })\n }\n}\n\n/** The document a map holds, read without an editor; `null` while the map is empty. */\nexport function readDoc(map: Y.Map<YBlock>, schema: Schema): PMNode | null {\n const children = placeAll(map)\n const build = (id: string): PMNode => {\n const content = contentFrom(map.get(id)!, schema)\n const kids = children.get(id)\n const parts = kids?.length\n ? [content, schema.nodes.blockGroup!.create(null, kids.map(build))]\n : [content]\n return schema.nodes.block!.create({ id }, parts)\n }\n const top = children.get(ROOT) ?? []\n return top.length ? schema.nodes.doc!.create(null, top.map(build)) : null\n}\n\nexport function syncPlugin(binding: Binding): Plugin {\n const { map } = binding\n const ydoc = map.doc!\n let schema: Schema\n // the document as last written to or read from the map\n let synced: Index | null = null\n // content nodes read from the map, by id, until the block changes there\n const cache = new Map<string, PMNode>()\n let placeholderId = createId()\n\n function buildDoc(): PMNode {\n const children = placeAll(map)\n const build = (id: string): PMNode => {\n let content = cache.get(id)\n if (!content) {\n content = contentFrom(map.get(id)!, schema)\n cache.set(id, content)\n }\n const kids = children.get(id)\n const parts = kids?.length\n ? [content, schema.nodes.blockGroup!.create(null, kids.map(build))]\n : [content]\n return schema.nodes.block!.create({ id }, parts)\n }\n const top = children.get(ROOT) ?? []\n // an empty map still shows one empty paragraph; it is stored once typed in\n const blocks = top.length\n ? top.map(build)\n : [schema.nodes.block!.create({ id: placeholderId }, schema.nodes.paragraph!.create())]\n return schema.nodes.doc!.create(null, blocks)\n }\n\n /** Show the map's current state in the editor. */\n function readMap(view: EditorView) {\n const doc = view.state.doc\n const next = buildDoc()\n const start = doc.content.findDiffStart(next.content)\n if (start !== null) {\n const end = doc.content.findDiffEnd(next.content)!\n const overlap = start - Math.min(end.a, end.b)\n if (overlap > 0) {\n end.a += overlap\n end.b += overlap\n }\n let from = start\n let to = end.a\n const $from = doc.resolve(from)\n const $to = doc.resolve(to)\n const shared = $from.sharedDepth(to)\n // a change across table cells or rows: swap them whole, a partial cut breaks the grid\n if (!$from.node(shared).inlineContent && (inTable($from, shared) || inTable($to, shared))) {\n if ($from.depth > shared) from = $from.before(shared + 1)\n if ($to.depth > shared) to = $to.after(shared + 1)\n }\n const tail = doc.content.size - to\n const tr = view.state.tr.replace(from, to, next.slice(from, next.content.size - tail))\n if (to !== end.a || from !== start) keepCellSelection(view.state, tr)\n tr.setMeta(collaborationKey, { remote: true })\n tr.setMeta('remote', true)\n // this user's undo comes back through the shared document too\n if (binding.undoing) tr.setMeta(originKey, binding.undoing)\n tr.setMeta('addToHistory', false)\n view.dispatch(tr)\n }\n synced = indexDoc(view.state.doc)\n }\n\n /** Write the editor's changes since the last sync into the map. */\n function writeMap(view: EditorView, tracked: boolean) {\n const doc = view.state.doc\n const before = synced ?? indexDoc(doc)\n const after = indexDoc(doc)\n // moving, indenting or adding blocks is an undo step of its own\n let structural = false\n for (const [key, ids] of after.children) {\n const old = before.children.get(key)\n if (!old || old.length !== ids.length || old.some((id, i) => ids[i] !== id)) structural = true\n }\n if (structural) binding.stopCapturing?.()\n const stale = ydoc.transact(\n () => writeChanges(map, before, after, schema),\n tracked ? binding.origin : binding.untracked,\n )\n for (const id of after.blocks.keys()) cache.set(id, after.blocks.get(id)!.content)\n for (const id of before.blocks.keys()) if (!after.blocks.has(id)) cache.delete(id)\n if (structural) binding.stopCapturing?.()\n synced = after\n if (stale.length) {\n for (const id of stale) cache.delete(id)\n // not from inside this update: show the rest once it is done\n queueMicrotask(() => {\n if (binding.view === view) readMap(view)\n })\n }\n }\n\n return new Plugin({\n key: collaborationKey,\n state: {\n init: () => ({ remote: false, tracked: false, own: false, join: false }),\n apply(tr, value) {\n const meta = tr.getMeta(collaborationKey) as { remote?: boolean } | undefined\n if (!tr.docChanged) return value\n if (meta?.remote) return { remote: true, tracked: false, own: false, join: false }\n // a transaction can come with appended ones (e.g. id fixes), written\n // together: undone together if any of them is\n const tracked = tr.getMeta('addToHistory') !== false\n const own = tr.getMeta(ownStepKey) === true\n const join = tr.getMeta(joinStepKey) === true\n // a step joined on purpose stands on its own here (its\n // `appendedTransaction` is for the built-in history)\n const appended = !join && !!tr.getMeta('appendedTransaction') && !value.remote\n return appended\n ? {\n remote: false,\n tracked: value.tracked || tracked,\n own: value.own || own,\n join: value.join || join,\n }\n : { remote: false, tracked, own, join }\n },\n },\n view(view) {\n schema = view.state.schema\n binding.view = view\n const observer = (\n events: Y.YEvent<Y.AbstractType<unknown>>[],\n transaction: Y.Transaction,\n ) => {\n if (transaction.origin === binding.origin || transaction.origin === binding.untracked)\n return\n // forget the cached content of every block that changed\n for (const event of events) {\n if (event.target === map) {\n for (const id of (event as Y.YMapEvent<unknown>).keysChanged) cache.delete(id)\n continue\n }\n // the path from the map starts with the block's id\n const id = event.path[0]\n if (typeof id === 'string') cache.delete(id)\n }\n readMap(view)\n }\n map.observeDeep(observer)\n if (map.size) readMap(view)\n else synced = indexDoc(view.state.doc)\n placeholderId = (view.state.doc.firstChild?.attrs.id as string | undefined) ?? placeholderId\n return {\n update(current, previous: EditorState) {\n if (current.state.doc === previous.doc) return\n const state = collaborationKey.getState(current.state)!\n if (state.remote) {\n synced = indexDoc(current.state.doc)\n return\n }\n // read before writing: the map still holds the previous text\n binding.selectionBefore = placeOf(binding, previous.doc, previous.selection.head)\n if (state.own) binding.stopCapturing?.()\n else if (state.join) binding.joinCapturing?.()\n writeMap(current, state.tracked)\n if (state.own) binding.stopCapturing?.()\n },\n destroy() {\n map.unobserveDeep(observer)\n binding.view = null\n },\n }\n },\n })\n}\n\nexport type { Transaction }\n"],"mappings":";;;;;;;;;;;;;;AAiDA,IAAM,OAAO;AAEb,IAAM,aAAa,WAA0B,UAAU;AAevD,SAAS,SAAS,KAAoB;CACpC,MAAM,yBAAS,IAAI,IAAoB;CACvC,MAAM,2BAAW,IAAI,IAAsB;CAC3C,MAAM,SAAS,WAAmB,WAA0B;EAC1D,MAAM,MAAgB,CAAC;EACvB,UAAU,SAAS,UAAU;GAC3B,MAAM,KAAK,MAAM,MAAM;GACvB,IAAI,KAAK,EAAE;GACX,OAAO,IAAI,IAAI;IAAE,SAAS,MAAM;IAAa;GAAO,CAAC;GACrD,IAAI,MAAM,aAAa,GAAG,MAAM,MAAM,MAAM,CAAC,GAAG,EAAE;EACpD,CAAC;EACD,SAAS,IAAI,UAAU,MAAM,GAAG,GAAG;CACrC;CACA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AEF,KAAK,MAAM,SAAS,QAAQ;KAC1B,IAAI,MAAM,WAAW,KAAK;MACxB,KAAK,MAAM,MAAO,MAA+B,aAAa,MAAM,OAAO,EAAE;MAC7E;KACF;KAEA,MAAM,KAAK,MAAM,KAAK;KACtB,IAAI,OAAO,OAAO,UAAU,MAAM,OAAO,EAAE;IAC7C;IACA,QAAQ,IAAI;GACd;GACA,IAAI,YAAY,QAAQ;GACxB,IAAI,IAAI,MAAM,QAAQ,IAAI;QACrB,SAAS,SAAS,KAAK,MAAM,GAAG;GACrC,gBAAiB,KAAK,MAAM,IAAI,YAAY,MAAM,MAA6B;GAC/E,OAAO;IACL,OAAO,SAAS,UAAuB;KACrC,IAAI,QAAQ,MAAM,QAAQ,SAAS,KAAK;KACxC,MAAM,QAAQ,iBAAiB,SAAS,QAAQ,KAAK;KACrD,IAAI,MAAM,QAAQ;MAChB,SAAS,SAAS,QAAQ,MAAM,GAAG;MACnC;KACF;KAEA,QAAQ,kBAAkB,QAAQ,SAAS,SAAS,KAAK,SAAS,UAAU,IAAI;KAChF,IAAI,MAAM,KAAK,QAAQ,gBAAgB;UAClC,IAAI,MAAM,MAAM,QAAQ,gBAAgB;KAC7C,SAAS,SAAS,MAAM,OAAO;KAC/B,IAAI,MAAM,KAAK,QAAQ,gBAAgB;IACzC;IACA,UAAU;KACR,IAAI,cAAc,QAAQ;KAC1B,QAAQ,OAAO;IACjB;GACF;EACF;CACF,CAAC;AACH"}
@@ -5,10 +5,42 @@ import { Decoration, DecorationSet } from "prosemirror-view";
5
5
  import * as Y from "yjs";
6
6
  // src/collaboration/cursors.ts
7
7
  /** The text a place points into: the block's own, or one of its table cells. */
8
- function textOf(binding, block, cell) {
9
- const yblock = binding.map.get(block);
10
- if (!cell) return yblock?.get("text");
11
- return (yblock?.get("cells"))?.get(cell);
8
+ function textOf(map, block, cell) {
9
+ const yblock = map.get(block);
10
+ if (!(yblock instanceof Y.Map)) return void 0;
11
+ if (!cell) {
12
+ if (yblock.has("cells")) return void 0;
13
+ const text = yblock.get("text");
14
+ return text instanceof Y.Text ? text : void 0;
15
+ }
16
+ const cells = yblock.get("cells");
17
+ const text = cells instanceof Y.Map ? cells.get(cell) : void 0;
18
+ return text instanceof Y.Text ? text : void 0;
19
+ }
20
+ function placeAt(map, target, holdsText) {
21
+ const yblock = map.get(target.block);
22
+ if (!target.cell && yblock instanceof Y.Map && !holdsText(String(yblock.get("type")))) return null;
23
+ const text = textOf(map, target.block, target.cell);
24
+ if (!text) return null;
25
+ const offset = Math.max(0, Math.min(Math.floor(target.offset ?? text.length), text.length));
26
+ const position = Y.relativePositionToJSON(Y.createRelativePositionFromTypeIndex(text, offset));
27
+ return target.cell ? {
28
+ block: target.block,
29
+ cell: target.cell,
30
+ position
31
+ } : {
32
+ block: target.block,
33
+ position
34
+ };
35
+ }
36
+ /** A cursor at `head`, selecting from `anchor`; `null` when either has no text to be in. */
37
+ function cursorIn(map, head, anchor, holdsText) {
38
+ const to = placeAt(map, head, holdsText);
39
+ const from = anchor === head ? to : placeAt(map, anchor, holdsText);
40
+ return to && from ? {
41
+ anchor: from,
42
+ head: to
43
+ } : null;
12
44
  }
13
45
  /** A document position as a place that survives other people's edits. */
14
46
  function placeOf(binding, doc, pos) {
@@ -23,7 +55,7 @@ function placeOf(binding, doc, pos) {
23
55
  cell = found.key;
24
56
  index = found.index;
25
57
  }
26
- const text = textOf(binding, id, cell);
58
+ const text = textOf(binding.map, id, cell);
27
59
  if (!text) return null;
28
60
  const offset = Math.max(0, Math.min(index, text.length));
29
61
  const position = Y.relativePositionToJSON(Y.createRelativePositionFromTypeIndex(text, offset));
@@ -49,7 +81,7 @@ function positionOf(binding, doc, place) {
49
81
  start += cell.offset;
50
82
  size = cell.size;
51
83
  }
52
- const offset = absolute && textOf(binding, place.block, place.cell) === absolute.type ? Math.min(absolute.index, size) : 0;
84
+ const offset = absolute && textOf(binding.map, place.block, place.cell) === absolute.type ? Math.min(absolute.index, size) : 0;
53
85
  return start + offset;
54
86
  }
55
87
  function cursorElement(user) {
@@ -67,7 +99,7 @@ function decorations(binding, awareness, state) {
67
99
  const found = [];
68
100
  awareness.getStates().forEach((value, client) => {
69
101
  if (client === awareness.clientID) return;
70
- const cursor = value.cursor;
102
+ const cursor = value.editor;
71
103
  const user = value.user;
72
104
  if (!cursor) return;
73
105
  const anchor = positionOf(binding, state.doc, cursor.anchor);
@@ -128,7 +160,7 @@ function cursorsPlugin(binding, awareness) {
128
160
  const json = JSON.stringify(cursor);
129
161
  if (json === last) return;
130
162
  last = json;
131
- awareness.setLocalStateField("cursor", cursor);
163
+ awareness.setLocalStateField("editor", cursor);
132
164
  };
133
165
  const onFocus = () => share();
134
166
  view.dom.addEventListener("focus", onFocus);
@@ -139,12 +171,12 @@ function cursorsPlugin(binding, awareness) {
139
171
  awareness.off("change", onChange);
140
172
  view.dom.removeEventListener("focus", onFocus);
141
173
  view.dom.removeEventListener("blur", onFocus);
142
- awareness.setLocalStateField("cursor", null);
174
+ awareness.setLocalStateField("editor", null);
143
175
  }
144
176
  };
145
177
  }
146
178
  });
147
179
  }
148
- export { cursorsPlugin, placeOf, positionOf };
180
+ export { cursorIn, cursorsPlugin, placeOf, positionOf };
149
181
 
150
182
  //# sourceMappingURL=cursors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cursors.js","names":[],"sources":["../../src/collaboration/cursors.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type EditorState } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport * as Y from 'yjs'\nimport { blockAround, findBlockById } from '../core/blocks'\nimport type { Binding, YBlock } from './binding'\nimport { cellAt, cellStart } from './table'\n\n/** What the editor needs of a Yjs awareness instance (`y-protocols/awareness`). */\nexport interface AwarenessLike {\n clientID: number\n getLocalState(): Record<string, unknown> | null\n setLocalStateField(field: string, value: unknown): void\n getStates(): Map<number, Record<string, unknown>>\n on(event: 'change', listener: (...args: unknown[]) => void): void\n off(event: 'change', listener: (...args: unknown[]) => void): void\n}\n\n/** A place in the text: the block and a position in its text that follows edits. */\ninterface Place {\n block: string\n /** In a table: the cell, `row id:column id`. */\n cell?: string\n position: unknown\n}\n\n/** The text a place points into: the block's own, or one of its table cells. */\nfunction textOf(binding: Binding, block: string, cell?: string): Y.Text | undefined {\n const yblock = binding.map.get(block) as YBlock | undefined\n if (!cell) return yblock?.get('text') as Y.Text | undefined\n return (yblock?.get('cells') as Y.Map<Y.Text> | undefined)?.get(cell)\n}\n\ninterface Cursor {\n anchor: Place\n head: Place\n}\n\n/** A document position as a place that survives other people's edits. */\nexport function placeOf(binding: Binding, doc: PMNode, pos: number): Place | null {\n const info = blockAround(doc.resolve(pos))\n if (!info) return null\n const id = info.node.attrs.id as string\n let index = pos - info.contentPos - 1\n let cell: string | undefined\n if (info.content.type.spec.rows) {\n const found = cellAt(info.content, index)\n if (!found) return null\n cell = found.key\n index = found.index\n }\n const text = textOf(binding, id, cell)\n if (!text) return null\n const offset = Math.max(0, Math.min(index, text.length))\n const position = Y.relativePositionToJSON(Y.createRelativePositionFromTypeIndex(text, offset))\n return cell ? { block: id, cell, position } : { block: id, position }\n}\n\n/** Back from a place to a document position, or `null` if its block is gone. */\nexport function positionOf(binding: Binding, doc: PMNode, place: Place): number | null {\n const info = findBlockById(doc, place.block)\n if (!info) return null\n const absolute = Y.createAbsolutePositionFromRelativePosition(\n Y.createRelativePositionFromJSON(place.position),\n binding.map.doc!,\n )\n let start = info.contentPos + 1\n let size = info.content.content.size\n if (place.cell) {\n const cell = info.content.type.spec.rows ? cellStart(info.content, place.cell) : null\n if (!cell) return null\n start += cell.offset\n size = cell.size\n }\n const offset =\n absolute && textOf(binding, place.block, place.cell) === absolute.type\n ? Math.min(absolute.index, size)\n : 0\n return start + offset\n}\n\nfunction cursorElement(user: { name: string; color: string }) {\n const cursor = document.createElement('span')\n cursor.className = 'dou-editor__cursor'\n cursor.style.setProperty('--dou-editor-cursor-color', user.color)\n const label = document.createElement('span')\n label.className = 'dou-editor__cursor-label'\n label.textContent = user.name\n // word joiners keep the caret from breaking the line around it\n cursor.append('⁠', label, '⁠')\n return cursor\n}\n\nconst cursorsKey = new PluginKey<DecorationSet>('dou-editor-cursors')\n\nfunction decorations(binding: Binding, awareness: AwarenessLike, state: EditorState) {\n const found: Decoration[] = []\n awareness.getStates().forEach((value, client) => {\n if (client === awareness.clientID) return\n const cursor = value.cursor as Cursor | null | undefined\n const user = value.user as { name?: string; color?: string } | undefined\n if (!cursor) return\n const anchor = positionOf(binding, state.doc, cursor.anchor)\n const head = positionOf(binding, state.doc, cursor.head)\n if (anchor === null || head === null) return\n const shown = { name: user?.name ?? '', color: user?.color ?? '#6b7280' }\n found.push(\n Decoration.widget(head, () => cursorElement(shown), {\n key: `cursor-${client}-${shown.name}-${shown.color}`,\n side: 10,\n }),\n )\n if (anchor !== head) {\n found.push(\n Decoration.inline(Math.min(anchor, head), Math.max(anchor, head), {\n class: 'dou-editor__remote-selection',\n style: `--dou-editor-cursor-color: ${shown.color}`,\n }),\n )\n }\n })\n return DecorationSet.create(state.doc, found)\n}\n\n/** Shares this user's cursor and shows everyone else's. */\nexport function cursorsPlugin(binding: Binding, awareness: AwarenessLike): Plugin {\n return new Plugin<DecorationSet>({\n key: cursorsKey,\n state: {\n init: (_config, state) => decorations(binding, awareness, state),\n apply(tr, value, _old, state) {\n if (tr.docChanged || tr.getMeta(cursorsKey)) return decorations(binding, awareness, state)\n return value\n },\n },\n props: {\n decorations(state) {\n return cursorsKey.getState(state)\n },\n },\n view(view) {\n let scheduled = false\n // others' cursors changed: redraw on the next frame, never inside a dispatch\n const onChange = () => {\n if (scheduled) return\n scheduled = true\n queueMicrotask(() => {\n scheduled = false\n if (binding.view === view) view.dispatch(view.state.tr.setMeta(cursorsKey, true))\n })\n }\n awareness.on('change', onChange)\n let last = ''\n const share = () => {\n let cursor: Cursor | null = null\n if (view.hasFocus()) {\n const { anchor, head } = view.state.selection\n const a = placeOf(binding, view.state.doc, anchor)\n const h = placeOf(binding, view.state.doc, head)\n if (a && h) cursor = { anchor: a, head: h }\n }\n const json = JSON.stringify(cursor)\n if (json === last) return\n last = json\n awareness.setLocalStateField('cursor', cursor)\n }\n const onFocus = () => share()\n view.dom.addEventListener('focus', onFocus)\n view.dom.addEventListener('blur', onFocus)\n return {\n update: share,\n destroy() {\n awareness.off('change', onChange)\n view.dom.removeEventListener('focus', onFocus)\n view.dom.removeEventListener('blur', onFocus)\n awareness.setLocalStateField('cursor', null)\n },\n }\n },\n })\n}\n"],"mappings":";;;;;;;AA2BA,SAAS,OAAO,SAAkB,OAAe,MAAmC;CAClF,MAAM,SAAS,QAAQ,IAAI,IAAI,KAAK;CACpC,IAAI,CAAC,MAAM,OAAO,QAAQ,IAAI,MAAM;CACpC,QAAQ,QAAQ,IAAI,OAAO,EAAA,EAAiC,IAAI,IAAI;AACtE;;AAQA,SAAgB,QAAQ,SAAkB,KAAa,KAA2B;CAChF,MAAM,OAAO,YAAY,IAAI,QAAQ,GAAG,CAAC;CACzC,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,KAAK,KAAK,KAAK,MAAM;CAC3B,IAAI,QAAQ,MAAM,KAAK,aAAa;CACpC,IAAI;CACJ,IAAI,KAAK,QAAQ,KAAK,KAAK,MAAM;EAC/B,MAAM,QAAQ,OAAO,KAAK,SAAS,KAAK;EACxC,IAAI,CAAC,OAAO,OAAO;EACnB,OAAO,MAAM;EACb,QAAQ,MAAM;CAChB;CACA,MAAM,OAAO,OAAO,SAAS,IAAI,IAAI;CACrC,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,OAAO,KAAK,MAAM,CAAC;CACvD,MAAM,WAAW,EAAE,uBAAuB,EAAE,oCAAoC,MAAM,MAAM,CAAC;CAC7F,OAAO,OAAO;EAAE,OAAO;EAAI;EAAM;CAAS,IAAI;EAAE,OAAO;EAAI;CAAS;AACtE;;AAGA,SAAgB,WAAW,SAAkB,KAAa,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AAM,KAAK,IAAI;KAC/C,IAAI,KAAK,GAAG,SAAS;MAAE,QAAQ;MAAG,MAAM;KAAE;IAC5C;IACA,MAAM,OAAO,KAAK,UAAU,MAAM;IAClC,IAAI,SAAS,MAAM;IACnB,OAAO;IACP,UAAU,mBAAmB,UAAU,MAAM;GAC/C;GACA,MAAM,gBAAgB,MAAM;GAC5B,KAAK,IAAI,iBAAiB,SAAS,OAAO;GAC1C,KAAK,IAAI,iBAAiB,QAAQ,OAAO;GACzC,OAAO;IACL,QAAQ;IACR,UAAU;KACR,UAAU,IAAI,UAAU,QAAQ;KAChC,KAAK,IAAI,oBAAoB,SAAS,OAAO;KAC7C,KAAK,IAAI,oBAAoB,QAAQ,OAAO;KAC5C,UAAU,mBAAmB,UAAU,IAAI;IAC7C;GACF;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"cursors.js","names":[],"sources":["../../src/collaboration/cursors.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type EditorState } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport * as Y from 'yjs'\nimport { blockAround, findBlockById } from '../core/blocks'\nimport type { Binding, YBlock } from './binding'\nimport { cellAt, cellStart } from './table'\n\n/** What the editor needs of a Yjs awareness instance (`y-protocols/awareness`). */\nexport interface AwarenessLike {\n clientID: number\n getLocalState(): Record<string, unknown> | null\n setLocalStateField(field: string, value: unknown): void\n getStates(): Map<number, Record<string, unknown>>\n on(event: 'change', listener: (...args: unknown[]) => void): void\n off(event: 'change', listener: (...args: unknown[]) => void): void\n}\n\n/** A place in the text: the block and a position in its text that follows edits. */\nexport interface EditorPresencePlace {\n block: string\n /** In a table: the cell, `row id:column id`. */\n cell?: string\n /** A Yjs relative position as JSON (`Y.relativePositionToJSON`). */\n position: unknown\n}\ntype Place = EditorPresencePlace\n\n/**\n * Where a person's cursor is, shared in the awareness field `editor`\n * (`null` when they have none). The selection runs from `anchor` to\n * `head`; the cursor with the name is drawn at `head`.\n */\nexport interface EditorPresence {\n anchor: EditorPresencePlace\n head: EditorPresencePlace\n}\ntype Cursor = EditorPresence\n\n/** The text a place points into: the block's own, or one of its table cells. */\nfunction textOf(map: Y.Map<unknown>, block: string, cell?: string): Y.Text | undefined {\n const yblock = map.get(block)\n if (!(yblock instanceof Y.Map)) return undefined\n if (!cell) {\n // a table's text is in its cells\n if ((yblock as YBlock).has('cells')) return undefined\n const text = (yblock as YBlock).get('text')\n return text instanceof Y.Text ? text : undefined\n }\n const cells = (yblock as YBlock).get('cells')\n const text = cells instanceof Y.Map ? cells.get(cell) : undefined\n return text instanceof Y.Text ? text : undefined\n}\n\n/** A place in a block's text, given without an editor. */\nexport interface EditorCursorTarget {\n block: string\n /** In a table: the cell, `row id:column id`. */\n cell?: string\n /**\n * Where in the text: the number of characters before it (UTF-16 code\n * units, as `string.length` counts them; an inline node such as a mention\n * counts as one). Kept within the text; left out, its end.\n */\n offset?: number\n}\n\n/** Whether blocks of a stored type hold text of their own, e.g. not an image or a divider. */\nexport type HoldsText = (type: string) => boolean\n\nfunction placeAt(\n map: Y.Map<unknown>,\n target: EditorCursorTarget,\n holdsText: HoldsText,\n): Place | null {\n const yblock = map.get(target.block)\n if (!target.cell && yblock instanceof Y.Map && !holdsText(String(yblock.get('type')))) return null\n const text = textOf(map, target.block, target.cell)\n if (!text) return null\n const offset = Math.max(0, Math.min(Math.floor(target.offset ?? text.length), text.length))\n const position = Y.relativePositionToJSON(Y.createRelativePositionFromTypeIndex(text, offset))\n return target.cell\n ? { block: target.block, cell: target.cell, position }\n : { block: target.block, position }\n}\n\n/** A cursor at `head`, selecting from `anchor`; `null` when either has no text to be in. */\nexport function cursorIn(\n map: Y.Map<unknown>,\n head: EditorCursorTarget,\n anchor: EditorCursorTarget,\n holdsText: HoldsText,\n): EditorPresence | null {\n const to = placeAt(map, head, holdsText)\n const from = anchor === head ? to : placeAt(map, anchor, holdsText)\n return to && from ? { anchor: from, head: to } : null\n}\n\n/** A document position as a place that survives other people's edits. */\nexport function placeOf(binding: Binding, doc: PMNode, pos: number): Place | null {\n const info = blockAround(doc.resolve(pos))\n if (!info) return null\n const id = info.node.attrs.id as string\n let index = pos - info.contentPos - 1\n let cell: string | undefined\n if (info.content.type.spec.rows) {\n const found = cellAt(info.content, index)\n if (!found) return null\n cell = found.key\n index = found.index\n }\n const text = textOf(binding.map as Y.Map<unknown>, id, cell)\n if (!text) return null\n const offset = Math.max(0, Math.min(index, text.length))\n const position = Y.relativePositionToJSON(Y.createRelativePositionFromTypeIndex(text, offset))\n return cell ? { block: id, cell, position } : { block: id, position }\n}\n\n/** Back from a place to a document position, or `null` if its block is gone. */\nexport function positionOf(binding: Binding, doc: PMNode, place: Place): number | null {\n const info = findBlockById(doc, place.block)\n if (!info) return null\n const absolute = Y.createAbsolutePositionFromRelativePosition(\n Y.createRelativePositionFromJSON(place.position),\n binding.map.doc!,\n )\n let start = info.contentPos + 1\n let size = info.content.content.size\n if (place.cell) {\n const cell = info.content.type.spec.rows ? cellStart(info.content, place.cell) : null\n if (!cell) return null\n start += cell.offset\n size = cell.size\n }\n const offset =\n absolute && textOf(binding.map as Y.Map<unknown>, place.block, place.cell) === absolute.type\n ? Math.min(absolute.index, size)\n : 0\n return start + offset\n}\n\nfunction cursorElement(user: { name: string; color: string }) {\n const cursor = document.createElement('span')\n cursor.className = 'dou-editor__cursor'\n cursor.style.setProperty('--dou-editor-cursor-color', user.color)\n const label = document.createElement('span')\n label.className = 'dou-editor__cursor-label'\n label.textContent = user.name\n // word joiners keep the caret from breaking the line around it\n cursor.append('⁠', label, '⁠')\n return cursor\n}\n\nconst cursorsKey = new PluginKey<DecorationSet>('dou-editor-cursors')\n\nfunction decorations(binding: Binding, awareness: AwarenessLike, state: EditorState) {\n const found: Decoration[] = []\n awareness.getStates().forEach((value, client) => {\n if (client === awareness.clientID) return\n const cursor = value.editor as Cursor | null | undefined\n const user = value.user as { name?: string; color?: string } | undefined\n if (!cursor) return\n const anchor = positionOf(binding, state.doc, cursor.anchor)\n const head = positionOf(binding, state.doc, cursor.head)\n if (anchor === null || head === null) return\n const shown = { name: user?.name ?? '', color: user?.color ?? '#6b7280' }\n found.push(\n Decoration.widget(head, () => cursorElement(shown), {\n key: `cursor-${client}-${shown.name}-${shown.color}`,\n side: 10,\n }),\n )\n if (anchor !== head) {\n found.push(\n Decoration.inline(Math.min(anchor, head), Math.max(anchor, head), {\n class: 'dou-editor__remote-selection',\n style: `--dou-editor-cursor-color: ${shown.color}`,\n }),\n )\n }\n })\n return DecorationSet.create(state.doc, found)\n}\n\n/** Shares this user's cursor and shows everyone else's. */\nexport function cursorsPlugin(binding: Binding, awareness: AwarenessLike): Plugin {\n return new Plugin<DecorationSet>({\n key: cursorsKey,\n state: {\n init: (_config, state) => decorations(binding, awareness, state),\n apply(tr, value, _old, state) {\n if (tr.docChanged || tr.getMeta(cursorsKey)) return decorations(binding, awareness, state)\n return value\n },\n },\n props: {\n decorations(state) {\n return cursorsKey.getState(state)\n },\n },\n view(view) {\n let scheduled = false\n // others' cursors changed: redraw on the next frame, never inside a dispatch\n const onChange = () => {\n if (scheduled) return\n scheduled = true\n queueMicrotask(() => {\n scheduled = false\n if (binding.view === view) view.dispatch(view.state.tr.setMeta(cursorsKey, true))\n })\n }\n awareness.on('change', onChange)\n let last = ''\n const share = () => {\n let cursor: Cursor | null = null\n if (view.hasFocus()) {\n const { anchor, head } = view.state.selection\n const a = placeOf(binding, view.state.doc, anchor)\n const h = placeOf(binding, view.state.doc, head)\n if (a && h) cursor = { anchor: a, head: h }\n }\n const json = JSON.stringify(cursor)\n if (json === last) return\n last = json\n awareness.setLocalStateField('editor', cursor)\n }\n const onFocus = () => share()\n view.dom.addEventListener('focus', onFocus)\n view.dom.addEventListener('blur', onFocus)\n return {\n update: share,\n destroy() {\n awareness.off('change', onChange)\n view.dom.removeEventListener('focus', onFocus)\n view.dom.removeEventListener('blur', onFocus)\n awareness.setLocalStateField('editor', null)\n },\n }\n },\n })\n}\n"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@ -1,8 +1,8 @@
1
1
  import { blocksToDoc, docToBlocks } from "../core/model.js";
2
2
  import { defineEditorExtension, resolveEditorExtensions } from "../core/extension.js";
3
3
  import { editorKit } from "../extensions/editor-kit.js";
4
- import { cursorsPlugin, positionOf } from "./cursors.js";
5
- import { createBinding, readDoc, syncPlugin, writeDoc } from "./binding.js";
4
+ import { cursorIn, cursorsPlugin, positionOf } from "./cursors.js";
5
+ import { createBinding, readDoc, syncPlugin, updateDoc, writeDoc } from "./binding.js";
6
6
  import { applySharedCommentAction, collaborationColors, readSharedComments } from "dou-ui";
7
7
  import { shallowRef } from "vue";
8
8
  import { Plugin, TextSelection } from "prosemirror-state";
@@ -29,6 +29,9 @@ function collaboration(options) {
29
29
  captureTimeout: 500
30
30
  });
31
31
  binding.stopCapturing = () => undoManager.stopCapturing();
32
+ binding.joinCapturing = () => {
33
+ if (undoManager.undoStack.length) undoManager.lastChange = Date.now();
34
+ };
32
35
  undoManager.on("stack-item-added", (event) => {
33
36
  if (!event.stackItem.meta.has("selection")) event.stackItem.meta.set("selection", binding.selectionBefore ?? null);
34
37
  });
@@ -80,29 +83,76 @@ function collaboration(options) {
80
83
  })
81
84
  });
82
85
  }
86
+ /** The extensions the editors of the shared document use; `[editorKit()]` when left out. */
87
+ var schemas = /* @__PURE__ */ new WeakMap();
88
+ var defaultSchema;
89
+ /** The schema of a list of extensions, resolved once per list; without one, of `[editorKit()]`. */
90
+ function schemaOf(extensions) {
91
+ if (!extensions) return defaultSchema ??= resolveEditorExtensions([editorKit()]).schema;
92
+ let schema = schemas.get(extensions);
93
+ if (!schema) {
94
+ schema = resolveEditorExtensions(extensions).schema;
95
+ schemas.set(extensions, schema);
96
+ }
97
+ return schema;
98
+ }
99
+ /**
100
+ * The value for the awareness field `editor` that puts a cursor at `head`,
101
+ * selecting from `options.anchor` when given, without an editor: e.g. on
102
+ * the server, for a program writing into the document with `updateMap`, so
103
+ * the people in the editor see where it writes. `null` when the block isn't
104
+ * in the map or has no text, e.g. an image, a divider, or a table without
105
+ * `cell`.
106
+ */
107
+ function cursorAt(map, head, options = {}) {
108
+ const schema = schemaOf(options.extensions);
109
+ const holdsText = (name) => {
110
+ const known = schema.nodes[name];
111
+ return (known?.isInGroup("blockContent") ? known : schema.nodes.paragraph).inlineContent;
112
+ };
113
+ return cursorIn(map, head, options.anchor ?? head, holdsText);
114
+ }
115
+ /** Runs `write` as one transaction of the map's document, from `origin`. */
116
+ function transact(map, write, origin) {
117
+ if (map.doc) map.doc.transact(write, origin ?? null);
118
+ else write();
119
+ }
83
120
  /**
84
121
  * Write a document into an empty map, e.g. when a document that so far was
85
122
  * saved as JSON starts being edited together. Do it once, where the
86
123
  * document is created (often on the server): two clients filling the same
87
124
  * empty map at the same time would both add their copy.
88
125
  */
89
- function fillMap(map, doc, extensions = [editorKit()]) {
90
- const schema = resolveEditorExtensions(extensions).schema;
91
- writeDoc(map, blocksToDoc(schema, doc.blocks));
126
+ function fillMap(map, doc, options = {}) {
127
+ const schema = schemaOf(options.extensions);
128
+ transact(map, () => writeDoc(map, blocksToDoc(schema, doc.blocks)), options.origin);
129
+ }
130
+ /**
131
+ * Change a shared map from `options.base` to `doc`, without an editor, e.g.
132
+ * on the server when a program wrote a new version while people edit the
133
+ * document. Only what differs is written: blocks keep their id and their
134
+ * text is changed character by character, so the cursors, undo and comment
135
+ * threads of the others stay. Blocks with new ids (e.g. read from Markdown)
136
+ * are matched to the stored ones by content and place; one that matches
137
+ * none is written as a new block, and one left over is removed. An empty
138
+ * map is filled.
139
+ */
140
+ function updateMap(map, doc, options = {}) {
141
+ const schema = schemaOf(options.extensions);
142
+ const { base } = options;
143
+ transact(map, () => updateDoc(map, blocksToDoc(schema, doc.blocks), schema, base && blocksToDoc(schema, base.blocks)), options.origin);
92
144
  }
93
145
  /**
94
146
  * The document a shared map holds, read without an editor, e.g. to save a
95
- * version on the server. Pass the extensions the editors use; an empty map
96
- * reads as no blocks.
147
+ * version on the server. An empty map reads as no blocks.
97
148
  */
98
- function readMap(map, extensions = [editorKit()]) {
99
- const schema = resolveEditorExtensions(extensions).schema;
100
- const doc = readDoc(map, schema);
149
+ function readMap(map, options = {}) {
150
+ const doc = readDoc(map, schemaOf(options.extensions));
101
151
  return {
102
152
  version: 1,
103
153
  blocks: doc ? docToBlocks(doc) : []
104
154
  };
105
155
  }
106
- export { collaboration, collaborationColors, fillMap, readMap };
156
+ export { collaboration, collaborationColors, cursorAt, fillMap, readMap, updateMap };
107
157
 
108
158
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import {\n applySharedCommentAction,\n collaborationColors,\n readSharedComments,\n type CommentThread,\n type SharedCommentMap,\n} from 'dou-ui'\nimport { shallowRef } from 'vue'\nimport { Plugin, TextSelection, type Command } from 'prosemirror-state'\nimport * as Y from 'yjs'\nimport {\n defineEditorExtension,\n resolveEditorExtensions,\n type EditorExtension,\n} from '../core/extension'\nimport { blocksToDoc, docToBlocks, type EditorDocument, type PartialBlock } from '../core/model'\nimport { editorKit } from '../extensions/editor-kit'\nimport { createBinding, readDoc, syncPlugin, writeDoc, type YBlock } from './binding'\nimport { cursorsPlugin, positionOf, type AwarenessLike } from './cursors'\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The cursor color, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the document lives, e.g. `ydoc.getMap('document')`. */\n map: Y.Map<unknown>\n /** Shares cursors and selections (`y-protocols/awareness`). Without it, others' cursors are not shown. */\n awareness?: AwarenessLike\n /** This user, shown at their cursor to the others. Needs `awareness`. */\n user?: CollaborationUser\n /**\n * Where the comment threads live, e.g. `ydoc.getMap('comments')`, so\n * they reach everyone with the document. `v-model:comments` then only\n * mirrors them. Without it, the text's anchors still travel with the\n * document and the threads are the app's to share.\n */\n comments?: Y.Map<unknown>\n}\n\nexport { collaborationColors }\n\n/**\n * Edit together through a Yjs document. The document lives in `map`: the\n * editor's `v-model` only mirrors it and changes to `v-model` are not\n * written back. Undo only takes back this user's own changes.\n */\nexport function collaboration(options: CollaborationOptions): EditorExtension {\n const map = options.map as Y.Map<YBlock>\n const { awareness, user } = options\n if (awareness && user) {\n const color = user.color ?? collaborationColors[map.doc!.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n const binding = createBinding(map)\n const undoManager = new Y.UndoManager(map, {\n trackedOrigins: new Set([binding.origin]),\n captureTimeout: 500,\n })\n binding.stopCapturing = () => undoManager.stopCapturing()\n // put the cursor back where it was when the change was made\n undoManager.on('stack-item-added', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n if (!event.stackItem.meta.has('selection'))\n event.stackItem.meta.set('selection', binding.selectionBefore ?? null)\n })\n undoManager.on('stack-item-popped', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n const view = binding.view\n const place = event.stackItem.meta.get('selection') as Parameters<typeof positionOf>[2] | null\n if (!view || !place) return\n const pos = positionOf(binding, view.state.doc, place)\n if (pos === null) return\n view.dispatch(view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(pos))))\n })\n const run =\n (action: 'undo' | 'redo'): Command =>\n (_state, dispatch) => {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n if (dispatch) {\n binding.undoing = action\n try {\n undoManager[action]()\n } finally {\n binding.undoing = undefined\n }\n }\n return true\n }\n\n const shared = options.comments\n const threads = shallowRef<readonly CommentThread[]>([])\n const readThreads = () => (threads.value = readSharedComments(shared as SharedCommentMap))\n if (shared) readThreads()\n // follows the shared threads while the editor is there\n const commentsPlugin = new Plugin({\n view: () => {\n shared!.observe(readThreads)\n readThreads()\n return { destroy: () => shared!.unobserve(readThreads) }\n },\n })\n\n return defineEditorExtension({\n name: 'collaboration',\n externalDocument: true,\n comments: shared\n ? () => ({\n threads,\n apply: (action) =>\n applySharedCommentAction(shared as SharedCommentMap, action, binding.untracked),\n })\n : undefined,\n plugins: () => [\n syncPlugin(binding),\n ...(awareness ? [cursorsPlugin(binding, awareness)] : []),\n ...(shared ? [commentsPlugin] : []),\n ],\n history: () => ({ plugins: [], undo: run('undo'), redo: run('redo') }),\n })\n}\n\n/**\n * Write a document into an empty map, e.g. when a document that so far was\n * saved as JSON starts being edited together. Do it once, where the\n * document is created (often on the server): two clients filling the same\n * empty map at the same time would both add their copy.\n */\nexport function fillMap(\n map: Y.Map<unknown>,\n doc: EditorDocument<PartialBlock>,\n extensions: (EditorExtension | EditorExtension[])[] = [editorKit()],\n) {\n const schema = resolveEditorExtensions(extensions).schema\n writeDoc(map as Y.Map<YBlock>, blocksToDoc(schema, doc.blocks))\n}\n\n/**\n * The document a shared map holds, read without an editor, e.g. to save a\n * version on the server. Pass the extensions the editors use; an empty map\n * reads as no blocks.\n */\nexport function readMap(\n map: Y.Map<unknown>,\n extensions: (EditorExtension | EditorExtension[])[] = [editorKit()],\n): EditorDocument {\n const schema = resolveEditorExtensions(extensions).schema\n const doc = readDoc(map as Y.Map<YBlock>, schema)\n return { version: 1, blocks: doc ? docToBlocks(doc) : [] }\n}\n\nexport type { AwarenessLike }\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,SAAgB,cAAc,SAAgD;CAC5E,MAAM,MAAM,QAAQ;CACpB,MAAM,EAAE,WAAW,SAAS;CAC5B,IAAI,aAAa,MAAM;EACrB,MAAM,QAAQ,KAAK,SAAS,oBAAoB,IAAI,IAAK,WAAW,oBAAoB;EACxF,UAAU,mBAAmB,QAAQ;GAAE,MAAM,KAAK;GAAM;EAAM,CAAC;CACjE;CACA,MAAM,UAAU,cAAc,GAAG;CACjC,MAAM,cAAc,IAAI,EAAE,YAAY,KAAK;EACzC,gCAAgB,IAAI,IAAI,CAAC,QAAQ,MAAM,CAAC;EACxC,gBAAgB;CAClB,CAAC;CACD,QAAQ,sBAAsB,YAAY,cAAc;CAExD,YAAY,GAAG,qBAAqB,UAAyD;EAC3F,IAAI,CAAC,MAAM,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AAC;EACnC;EACA,gBAAgB;GAAE,SAAS,CAAC;GAAG,MAAM,IAAI,MAAM;GAAG,MAAM,IAAI,MAAM;EAAE;CACtE,CAAC;AACH;;;;;;;AAQA,SAAgB,QACd,KACA,KACA,aAAsD,CAAC,UAAU,CAAC,GAClE;CACA,MAAM,SAAS,wBAAwB,UAAU,CAAC,CAAC;CACnD,SAAS,KAAsB,YAAY,QAAQ,IAAI,MAAM,CAAC;AAChE;;;;;;AAOA,SAAgB,QACd,KACA,aAAsD,CAAC,UAAU,CAAC,GAClD;CAChB,MAAM,SAAS,wBAAwB,UAAU,CAAC,CAAC;CACnD,MAAM,MAAM,QAAQ,KAAsB,MAAM;CAChD,OAAO;EAAE,SAAS;EAAG,QAAQ,MAAM,YAAY,GAAG,IAAI,CAAC;CAAE;AAC3D"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/collaboration/index.ts"],"sourcesContent":["import {\n applySharedCommentAction,\n collaborationColors,\n readSharedComments,\n type CommentThread,\n type SharedCommentMap,\n} from 'dou-ui'\nimport type { Schema } from 'prosemirror-model'\nimport { shallowRef } from 'vue'\nimport { Plugin, TextSelection, type Command } from 'prosemirror-state'\nimport * as Y from 'yjs'\nimport {\n defineEditorExtension,\n resolveEditorExtensions,\n type EditorExtension,\n} from '../core/extension'\nimport { blocksToDoc, docToBlocks, type EditorDocument, type PartialBlock } from '../core/model'\nimport { editorKit } from '../extensions/editor-kit'\nimport { createBinding, readDoc, syncPlugin, updateDoc, writeDoc, type YBlock } from './binding'\nimport {\n cursorIn,\n cursorsPlugin,\n positionOf,\n type AwarenessLike,\n type EditorCursorTarget,\n type EditorPresence,\n type EditorPresencePlace,\n} from './cursors'\n\n/** How the people editing together see each other. */\nexport interface CollaborationUser {\n name: string\n /** The cursor color, any CSS color. Picked from the client id when left out. */\n color?: string\n}\n\nexport interface CollaborationOptions {\n /** Where the document lives, e.g. `ydoc.getMap('document')`. */\n map: Y.Map<unknown>\n /** Shares cursors and selections (`y-protocols/awareness`). Without it, others' cursors are not shown. */\n awareness?: AwarenessLike\n /** This user, shown at their cursor to the others. Needs `awareness`. */\n user?: CollaborationUser\n /**\n * Where the comment threads live, e.g. `ydoc.getMap('comments')`, so\n * they reach everyone with the document. `v-model:comments` then only\n * mirrors them. Without it, the text's anchors still travel with the\n * document and the threads are the app's to share.\n */\n comments?: Y.Map<unknown>\n}\n\nexport { collaborationColors }\n\n/**\n * Edit together through a Yjs document. The document lives in `map`: the\n * editor's `v-model` only mirrors it and changes to `v-model` are not\n * written back. Undo only takes back this user's own changes.\n */\nexport function collaboration(options: CollaborationOptions): EditorExtension {\n const map = options.map as Y.Map<YBlock>\n const { awareness, user } = options\n if (awareness && user) {\n const color = user.color ?? collaborationColors[map.doc!.clientID % collaborationColors.length]\n awareness.setLocalStateField('user', { name: user.name, color })\n }\n const binding = createBinding(map)\n const undoManager = new Y.UndoManager(map, {\n trackedOrigins: new Set([binding.origin]),\n captureTimeout: 500,\n })\n binding.stopCapturing = () => undoManager.stopCapturing()\n // as if the last change were just now: the next one is captured with it\n binding.joinCapturing = () => {\n if (undoManager.undoStack.length) undoManager.lastChange = Date.now()\n }\n // put the cursor back where it was when the change was made\n undoManager.on('stack-item-added', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n if (!event.stackItem.meta.has('selection'))\n event.stackItem.meta.set('selection', binding.selectionBefore ?? null)\n })\n undoManager.on('stack-item-popped', (event: { stackItem: { meta: Map<string, unknown> } }) => {\n const view = binding.view\n const place = event.stackItem.meta.get('selection') as Parameters<typeof positionOf>[2] | null\n if (!view || !place) return\n const pos = positionOf(binding, view.state.doc, place)\n if (pos === null) return\n view.dispatch(view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(pos))))\n })\n const run =\n (action: 'undo' | 'redo'): Command =>\n (_state, dispatch) => {\n const stack = action === 'undo' ? undoManager.undoStack : undoManager.redoStack\n if (!stack.length) return false\n if (dispatch) {\n binding.undoing = action\n try {\n undoManager[action]()\n } finally {\n binding.undoing = undefined\n }\n }\n return true\n }\n\n const shared = options.comments\n const threads = shallowRef<readonly CommentThread[]>([])\n const readThreads = () => (threads.value = readSharedComments(shared as SharedCommentMap))\n if (shared) readThreads()\n // follows the shared threads while the editor is there\n const commentsPlugin = new Plugin({\n view: () => {\n shared!.observe(readThreads)\n readThreads()\n return { destroy: () => shared!.unobserve(readThreads) }\n },\n })\n\n return defineEditorExtension({\n name: 'collaboration',\n externalDocument: true,\n comments: shared\n ? () => ({\n threads,\n apply: (action) =>\n applySharedCommentAction(shared as SharedCommentMap, action, binding.untracked),\n })\n : undefined,\n plugins: () => [\n syncPlugin(binding),\n ...(awareness ? [cursorsPlugin(binding, awareness)] : []),\n ...(shared ? [commentsPlugin] : []),\n ],\n history: () => ({ plugins: [], undo: run('undo'), redo: run('redo') }),\n })\n}\n\ntype ExtensionList = (EditorExtension | EditorExtension[])[]\n\n/** The extensions the editors of the shared document use; `[editorKit()]` when left out. */\nconst schemas = new WeakMap<ExtensionList, Schema>()\nlet defaultSchema: Schema | undefined\n\n/** The schema of a list of extensions, resolved once per list; without one, of `[editorKit()]`. */\nfunction schemaOf(extensions?: ExtensionList): Schema {\n if (!extensions) return (defaultSchema ??= resolveEditorExtensions([editorKit()]).schema)\n let schema = schemas.get(extensions)\n if (!schema) {\n schema = resolveEditorExtensions(extensions).schema\n schemas.set(extensions, schema)\n }\n return schema\n}\n\nexport interface CursorAtOptions {\n /** Where a selection starts; left out, only a cursor at `head`. */\n anchor?: EditorCursorTarget\n /** The extensions the editors use, for custom blocks. Defaults to `[editorKit()]`. */\n extensions?: ExtensionList\n}\n\n/**\n * The value for the awareness field `editor` that puts a cursor at `head`,\n * selecting from `options.anchor` when given, without an editor: e.g. on\n * the server, for a program writing into the document with `updateMap`, so\n * the people in the editor see where it writes. `null` when the block isn't\n * in the map or has no text, e.g. an image, a divider, or a table without\n * `cell`.\n */\nexport function cursorAt(\n map: Y.Map<unknown>,\n head: EditorCursorTarget,\n options: CursorAtOptions = {},\n): EditorPresence | null {\n const schema = schemaOf(options.extensions)\n const holdsText = (name: string) => {\n const known = schema.nodes[name]\n // unknown types are read as paragraphs\n const type = known?.isInGroup('blockContent') ? known : schema.nodes.paragraph!\n return type.inlineContent\n }\n return cursorIn(map, head, options.anchor ?? head, holdsText)\n}\n\n/** Runs `write` as one transaction of the map's document, from `origin`. */\nfunction transact(map: Y.Map<unknown>, write: () => void, origin: unknown) {\n if (map.doc) map.doc.transact(write, origin ?? null)\n else write()\n}\n\nexport interface FillMapOptions {\n /** The extensions the editors use, for custom blocks. Defaults to `[editorKit()]`. */\n extensions?: ExtensionList\n /** The origin of the Yjs transaction, so the others can tell who wrote it. */\n origin?: unknown\n}\n\n/**\n * Write a document into an empty map, e.g. when a document that so far was\n * saved as JSON starts being edited together. Do it once, where the\n * document is created (often on the server): two clients filling the same\n * empty map at the same time would both add their copy.\n */\nexport function fillMap(\n map: Y.Map<unknown>,\n doc: EditorDocument<PartialBlock>,\n options: FillMapOptions = {},\n) {\n const schema = schemaOf(options.extensions)\n transact(\n map,\n () => writeDoc(map as Y.Map<YBlock>, blocksToDoc(schema, doc.blocks)),\n options.origin,\n )\n}\n\nexport interface UpdateMapOptions extends FillMapOptions {\n /**\n * The version `doc` was made from, e.g. the one read with `readMap` and\n * given to a program that took a while to write `doc`. Only what differs\n * between `base` and `doc` is written, so what others changed in the map\n * meanwhile stays. Get it the same way as `doc`: when `doc` is read from\n * Markdown, read `base` from the Markdown the program was given. Left\n * out, the map as it is now.\n */\n base?: EditorDocument<PartialBlock>\n}\n\n/**\n * Change a shared map from `options.base` to `doc`, without an editor, e.g.\n * on the server when a program wrote a new version while people edit the\n * document. Only what differs is written: blocks keep their id and their\n * text is changed character by character, so the cursors, undo and comment\n * threads of the others stay. Blocks with new ids (e.g. read from Markdown)\n * are matched to the stored ones by content and place; one that matches\n * none is written as a new block, and one left over is removed. An empty\n * map is filled.\n */\nexport function updateMap(\n map: Y.Map<unknown>,\n doc: EditorDocument<PartialBlock>,\n options: UpdateMapOptions = {},\n) {\n const schema = schemaOf(options.extensions)\n const { base } = options\n transact(\n map,\n () =>\n updateDoc(\n map as Y.Map<YBlock>,\n blocksToDoc(schema, doc.blocks),\n schema,\n base && blocksToDoc(schema, base.blocks),\n ),\n options.origin,\n )\n}\n\nexport interface ReadMapOptions {\n /** The extensions the editors use, for custom blocks. Defaults to `[editorKit()]`. */\n extensions?: ExtensionList\n}\n\n/**\n * The document a shared map holds, read without an editor, e.g. to save a\n * version on the server. An empty map reads as no blocks.\n */\nexport function readMap(map: Y.Map<unknown>, options: ReadMapOptions = {}): EditorDocument {\n const doc = readDoc(map as Y.Map<YBlock>, schemaOf(options.extensions))\n return { version: 1, blocks: doc ? docToBlocks(doc) : [] }\n}\n\nexport type { AwarenessLike, EditorCursorTarget, EditorPresence, EditorPresencePlace }\n"],"mappings":";;;;;;;;;;;;;;;AA2DA,SAAgB,cAAc,SAAgD;CAC5E,MAAM,MAAM,QAAQ;CACpB,MAAM,EAAE,WAAW,SAAS;CAC5B,IAAI,aAAa,MAAM;EACrB,MAAM,QAAQ,KAAK,SAAS,oBAAoB,IAAI,IAAK,WAAW,oBAAoB;EACxF,UAAU,mBAAmB,QAAQ;GAAE,MAAM,KAAK;GAAM;EAAM,CAAC;CACjE;CACA,MAAM,UAAU,cAAc,GAAG;CACjC,MAAM,cAAc,IAAI,EAAE,YAAY,KAAK;EACzC,gCAAgB,IAAI,IAAI,CAAC,QAAQ,MAAM,CAAC;EACxC,gBAAgB;CAClB,CAAC;CACD,QAAQ,sBAAsB,YAAY,cAAc;CAExD,QAAQ,sBAAsB;EAC5B,IAAI,YAAY,UAAU,QAAQ,YAAY,aAAa,KAAK,IAAI;CACtE;CAEA,YAAY,GAAG,qBAAqB,UAAyD;EAC3F,IAAI,CAAC,MAAM,UAAU,KAAK,IAAI,WAAW,GACvC,MAAM,UAAU,KAAK,IAAI,aAAa,QAAQ,mBAAmB,IAAI;CACzE,CAAC;CACD,YAAY,GAAG,sBAAsB,UAAyD;EAC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