@dou-ui/editor 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (50) hide show
  1. package/dist/code/code-editor-block.js.map +1 -1
  2. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
  3. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/collaboration/binding.js +344 -42
  5. package/dist/collaboration/binding.js.map +1 -1
  6. package/dist/collaboration/index.js +30 -10
  7. package/dist/collaboration/index.js.map +1 -1
  8. package/dist/components/block-handle.js.map +1 -1
  9. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  11. package/dist/components/bubble-toolbar.js.map +1 -1
  12. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
  13. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  14. package/dist/components/comment-card.js.map +1 -1
  15. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
  16. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
  17. package/dist/core/convert.js +3 -3
  18. package/dist/core/convert.js.map +1 -1
  19. package/dist/core/editor.js +2 -1
  20. package/dist/core/editor.js.map +1 -1
  21. package/dist/core/plugins.js +108 -5
  22. package/dist/core/plugins.js.map +1 -1
  23. package/dist/core/prepare.js +12 -5
  24. package/dist/core/prepare.js.map +1 -1
  25. package/dist/dom.js +6 -1
  26. package/dist/dom.js.map +1 -1
  27. package/dist/extensions/align/align-menu.js.map +1 -1
  28. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
  29. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  30. package/dist/extensions/callout/html.js +5 -4
  31. package/dist/extensions/callout/html.js.map +1 -1
  32. package/dist/extensions/colors/color-menu.js.map +1 -1
  33. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
  34. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  35. package/dist/extensions/list-html.js +1 -1
  36. package/dist/extensions/list-html.js.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/markdown/index.js +2 -2
  39. package/dist/markdown/index.js.map +1 -1
  40. package/dist/style.css +1 -1
  41. package/dist/style.js +0 -1
  42. package/dist/types/collaboration/binding.d.ts +8 -0
  43. package/dist/types/collaboration/index.d.ts +36 -4
  44. package/dist/types/core/convert.d.ts +10 -2
  45. package/dist/types/core/plugins.d.ts +9 -0
  46. package/dist/types/core/prepare.d.ts +16 -2
  47. package/dist/types/dom.d.ts +2 -0
  48. package/dist/types/index.d.ts +2 -1
  49. package/dist/types/markdown/index.d.ts +8 -1
  50. package/package.json +5 -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,M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Node as PMNode,\n type ResolvedPos,\n type Schema,\n} from 'prosemirror-model'\nimport { Transform } from 'prosemirror-transform'\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 { keptIndexes, 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/**\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/**\n * `after` with the comment marks of `before` on the text both start and\n * end with, when `after` has none: a version read from Markdown, which\n * doesn't carry them, leaves the threads where the text stays the same.\n */\nfunction keepComments(before: PMNode, after: PMNode): PMNode {\n const type = after.type.schema.marks.comment\n if (!type || !after.inlineContent || !before.inlineContent || before.type !== after.type)\n return after\n let theirs = false\n after.descendants((node) => {\n if (type.isInSet(node.marks)) theirs = true\n })\n if (theirs) return after\n const ranges: { from: number; to: number; mark: Mark }[] = []\n before.forEach((child, pos) => {\n for (const mark of child.marks)\n if (mark.type === type) ranges.push({ from: pos, to: pos + child.nodeSize, mark })\n })\n if (!ranges.length) return after\n const a = before.textBetween(0, before.content.size, '', '')\n const b = after.textBetween(0, after.content.size, '', '')\n let head = 0\n while (head < a.length && head < b.length && a[head] === b[head]) head++\n let tail = 0\n while (\n tail < a.length - head &&\n tail < b.length - head &&\n a[a.length - 1 - tail] === b[b.length - 1 - tail]\n )\n tail++\n const tr = new Transform(after)\n const shift = b.length - a.length\n for (const { from, to, mark } of ranges) {\n // the start both share, and the end, moved by what changed between\n if (from < head) tr.addMark(from, Math.min(to, head), mark)\n const end = a.length - tail\n if (to > end) tr.addMark(Math.max(from, end) + shift, to + shift, mark)\n }\n return tr.doc\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 // 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 old = toBase.get(id)\n const was = old !== undefined ? from.blocks.get(old)!.content : null\n if (was && keepComments(was, placed.content).eq(was)) continue\n const there = now.blocks.get(target)!.content\n updateContent(yblock!, there, keepComments(there, placed.content))\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 }),\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":";;;;;;;;;;;;;AA6CA,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,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,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"}
@@ -2,7 +2,7 @@ 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
4
  import { cursorsPlugin, positionOf } from "./cursors.js";
5
- import { createBinding, readDoc, syncPlugin, writeDoc } from "./binding.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";
@@ -80,29 +80,49 @@ function collaboration(options) {
80
80
  })
81
81
  });
82
82
  }
83
+ /** The extensions the editors of the shared document use; `[editorKit()]` when left out. */
84
+ var schemaOf = (extensions = [editorKit()]) => resolveEditorExtensions(extensions).schema;
85
+ /** Runs `write` as one transaction of the map's document, from `origin`. */
86
+ function transact(map, write, origin) {
87
+ if (map.doc) map.doc.transact(write, origin ?? null);
88
+ else write();
89
+ }
83
90
  /**
84
91
  * Write a document into an empty map, e.g. when a document that so far was
85
92
  * saved as JSON starts being edited together. Do it once, where the
86
93
  * document is created (often on the server): two clients filling the same
87
94
  * empty map at the same time would both add their copy.
88
95
  */
89
- function fillMap(map, doc, extensions = [editorKit()]) {
90
- const schema = resolveEditorExtensions(extensions).schema;
91
- writeDoc(map, blocksToDoc(schema, doc.blocks));
96
+ function fillMap(map, doc, options = {}) {
97
+ const schema = schemaOf(options.extensions);
98
+ transact(map, () => writeDoc(map, blocksToDoc(schema, doc.blocks)), options.origin);
99
+ }
100
+ /**
101
+ * Change a shared map from `options.base` to `doc`, without an editor, e.g.
102
+ * on the server when a program wrote a new version while people edit the
103
+ * document. Only what differs is written: blocks keep their id and their
104
+ * text is changed character by character, so the cursors, undo and comment
105
+ * threads of the others stay. Blocks with new ids (e.g. read from Markdown)
106
+ * are matched to the stored ones by content and place; one that matches
107
+ * none is written as a new block, and one left over is removed. An empty
108
+ * map is filled.
109
+ */
110
+ function updateMap(map, doc, options = {}) {
111
+ const schema = schemaOf(options.extensions);
112
+ const { base } = options;
113
+ transact(map, () => updateDoc(map, blocksToDoc(schema, doc.blocks), schema, base && blocksToDoc(schema, base.blocks)), options.origin);
92
114
  }
93
115
  /**
94
116
  * 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.
117
+ * version on the server. An empty map reads as no blocks.
97
118
  */
98
- function readMap(map, extensions = [editorKit()]) {
99
- const schema = resolveEditorExtensions(extensions).schema;
100
- const doc = readDoc(map, schema);
119
+ function readMap(map, options = {}) {
120
+ const doc = readDoc(map, schemaOf(options.extensions));
101
121
  return {
102
122
  version: 1,
103
123
  blocks: doc ? docToBlocks(doc) : []
104
124
  };
105
125
  }
106
- export { collaboration, collaborationColors, fillMap, readMap };
126
+ export { collaboration, collaborationColors, fillMap, readMap, updateMap };
107
127
 
108
128
  //# 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"],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,WAAqC,CAAC,CAAC;CACvD,MAAM,oBAAqB,QAAQ,QAAQ,mBAAmB,MAA0B;CACxF,IAAI,QAAQ,YAAY;CAExB,MAAM,iBAAiB,IAAI,OAAO,EAChC,YAAY;EACV,OAAQ,QAAQ,WAAW;EAC3B,YAAY;EACZ,OAAO,EAAE,eAAe,OAAQ,UAAU,WAAW,EAAE;CACzD,EACF,CAAC;CAED,OAAO,sBAAsB;EAC3B,MAAM;EACN,kBAAkB;EAClB,UAAU,gBACC;GACL;GACA,QAAQ,WACN,yBAAyB,QAA4B,QAAQ,QAAQ,SAAS;EAClF,KACA,KAAA;EACJ,eAAe;GACb,WAAW,OAAO;GAClB,GAAI,YAAY,CAAC,cAAc,SAAS,SAAS,CAAC,IAAI,CAAC;GACvD,GAAI,SAAS,CAAC,cAAc,IAAI,CAAC;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 { 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 { 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\ntype ExtensionList = (EditorExtension | EditorExtension[])[]\n\n/** The extensions the editors of the shared document use; `[editorKit()]` when left out. */\nconst schemaOf = (extensions: ExtensionList = [editorKit()]) =>\n resolveEditorExtensions(extensions).schema\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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AQ,YAAY,QAAQ,KAAK,MAAM,CACzC,GACF,QAAQ,MACV;AACF;;;;;AAWA,SAAgB,QAAQ,KAAqB,UAA0B,CAAC,GAAmB;CACzF,MAAM,MAAM,QAAQ,KAAsB,SAAS,QAAQ,UAAU,CAAC;CACtE,OAAO;EAAE,SAAS;EAAG,QAAQ,MAAM,YAAY,GAAG,IAAI,CAAC;CAAE;AAC3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n drop.value = { pos, top: y - box.top, left: left - box.left, width: box.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: rect.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":""}
@@ -314,7 +314,7 @@ var block_handle_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
314
314
  pos,
315
315
  top: y - box.top,
316
316
  left: left - box.left,
317
- width: box.right - left
317
+ width: rect.right - left
318
318
  };
319
319
  }
320
320
  function autoScroll() {
@@ -1 +1 @@
1
- {"version":3,"file":"block-handle.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n drop.value = { pos, top: y - box.top, left: left - box.left, width: box.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EA0CA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;EAOhF,MAAM,QAAQ,WAAW,KAAK;EAC9B,IAAI,QAA+B;EACnC,MAAM,gBAAiB,MAAM,QAAQ,CAAC,CAAC,OAAO;;EAG9C,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,WAAW,WAAiE,IAAI;EACtF,MAAM,WAAW,WAAW,KAAK;EACjC,cAAc,gBAAiB,SAAS,QAAQ,KAAM;EAEtD,MAAM,OAAO,WAA6E,IAAI;EAE9F,MAAM,UAAU,WAAW,KAAK;EAEhC,MAAM,UAAU,eAAe;GAC7B,IAAI,CAAC,SAAS,OAAO,OAAO;GAC5B,IAAI,SAAS,SAAS,SAAS,OAA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X,iBAAe;I,IAEhBC,YAAoBD,MAAA,gBAAA,CAAA,C;;G,wBAxChB,CAAAU,OAAA,QAAA,KAAO,C,IAiGT,KAAA,SADRjB,UAAA,GAAAC,mBAIE,OAAA;;IAFA,OAAM;IACL,OAAKI,eAAA;KAAA,KAAA,GAAY,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,OAAA,GAAgB,KAAA,MAAK,MAAK;IAAA,CAAA"}
1
+ {"version":3,"file":"block-handle.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: rect.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EA0CA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;EAOhF,MAAM,QAAQ,WAAW,KAAK;EAC9B,IAAI,QAA+B;EACnC,MAAM,gBAAiB,MAAM,QAAQ,CAAC,CAAC,OAAO;;EAG9C,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,WAAW,WAAiE,IAAI;EACtF,MAAM,WAAW,WAAW,KAAK;EACjC,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