@dou-ui/editor 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (168) 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 +371 -57
  5. package/dist/collaboration/binding.js.map +1 -1
  6. package/dist/collaboration/cursors.js +42 -10
  7. package/dist/collaboration/cursors.js.map +1 -1
  8. package/dist/collaboration/index.js +61 -11
  9. package/dist/collaboration/index.js.map +1 -1
  10. package/dist/collaboration/inline-diff.js +138 -0
  11. package/dist/collaboration/inline-diff.js.map +1 -0
  12. package/dist/collaboration/merged-props.js +152 -0
  13. package/dist/collaboration/merged-props.js.map +1 -0
  14. package/dist/collaboration/order.js +41 -1
  15. package/dist/collaboration/order.js.map +1 -1
  16. package/dist/collaboration/table.js +64 -25
  17. package/dist/collaboration/table.js.map +1 -1
  18. package/dist/collaboration/text.js +213 -1
  19. package/dist/collaboration/text.js.map +1 -1
  20. package/dist/components/block-handle.js.map +1 -1
  21. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +125 -17
  22. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  23. package/dist/components/bubble-toolbar.js.map +1 -1
  24. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
  25. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  26. package/dist/components/comment-card.js.map +1 -1
  27. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
  28. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
  29. package/dist/components/slash-choices.js +6 -0
  30. package/dist/components/slash-choices.js.map +1 -0
  31. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
  32. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
  33. package/dist/components/slash-menu.js.map +1 -1
  34. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
  35. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  36. package/dist/core/block-selection.js +32 -4
  37. package/dist/core/block-selection.js.map +1 -1
  38. package/dist/core/blocks.js +21 -3
  39. package/dist/core/blocks.js.map +1 -1
  40. package/dist/core/commands.js +125 -13
  41. package/dist/core/commands.js.map +1 -1
  42. package/dist/core/comments.js +85 -3
  43. package/dist/core/comments.js.map +1 -1
  44. package/dist/core/convert.js +3 -3
  45. package/dist/core/convert.js.map +1 -1
  46. package/dist/core/editor.js +2 -1
  47. package/dist/core/editor.js.map +1 -1
  48. package/dist/core/extension.js +6 -2
  49. package/dist/core/extension.js.map +1 -1
  50. package/dist/core/model.js +10 -3
  51. package/dist/core/model.js.map +1 -1
  52. package/dist/core/plugins.js +108 -5
  53. package/dist/core/plugins.js.map +1 -1
  54. package/dist/core/prepare.js +12 -5
  55. package/dist/core/prepare.js.map +1 -1
  56. package/dist/core/schema.js.map +1 -1
  57. package/dist/core/transaction.js +19 -4
  58. package/dist/core/transaction.js.map +1 -1
  59. package/dist/define-block.js +8 -4
  60. package/dist/define-block.js.map +1 -1
  61. package/dist/document.js +59 -4
  62. package/dist/document.js.map +1 -1
  63. package/dist/dom.js +112 -13
  64. package/dist/dom.js.map +1 -1
  65. package/dist/editor.js.map +1 -1
  66. package/dist/editor.vue_vue_type_script_setup_true_lang.js +3 -3
  67. package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  68. package/dist/editor2.js.map +1 -1
  69. package/dist/extensions/align/align-menu.js.map +1 -1
  70. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
  71. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  72. package/dist/extensions/callout/html.js +5 -4
  73. package/dist/extensions/callout/html.js.map +1 -1
  74. package/dist/extensions/colors/color-menu.js.map +1 -1
  75. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
  76. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  77. package/dist/extensions/columns/column-picker.js +6 -0
  78. package/dist/extensions/columns/column-picker.js.map +1 -0
  79. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
  80. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  81. package/dist/extensions/columns/columns-controls.js +6 -0
  82. package/dist/extensions/columns/columns-controls.js.map +1 -0
  83. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
  84. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
  85. package/dist/extensions/columns/html.js +34 -0
  86. package/dist/extensions/columns/html.js.map +1 -0
  87. package/dist/extensions/columns/index.js +57 -0
  88. package/dist/extensions/columns/index.js.map +1 -0
  89. package/dist/extensions/columns/keys.js +53 -0
  90. package/dist/extensions/columns/keys.js.map +1 -0
  91. package/dist/extensions/columns/plugin.js +213 -0
  92. package/dist/extensions/columns/plugin.js.map +1 -0
  93. package/dist/extensions/columns/schema.js +58 -0
  94. package/dist/extensions/columns/schema.js.map +1 -0
  95. package/dist/extensions/columns/select-columns.js +6 -0
  96. package/dist/extensions/columns/select-columns.js.map +1 -0
  97. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
  98. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
  99. package/dist/extensions/editor-kit.js +3 -1
  100. package/dist/extensions/editor-kit.js.map +1 -1
  101. package/dist/extensions/list-html.js +1 -1
  102. package/dist/extensions/list-html.js.map +1 -1
  103. package/dist/extensions/table/plugin.js +33 -1
  104. package/dist/extensions/table/plugin.js.map +1 -1
  105. package/dist/extensions/table/table-controls.js.map +1 -1
  106. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +1 -1
  107. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
  108. package/dist/extensions/table/view.js +25 -1
  109. package/dist/extensions/table/view.js.map +1 -1
  110. package/dist/flow/board-block.js +6 -0
  111. package/dist/flow/board-block.js.map +1 -0
  112. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
  113. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
  114. package/dist/flow/board.js +221 -0
  115. package/dist/flow/board.js.map +1 -0
  116. package/dist/flow/index.js +173 -0
  117. package/dist/flow/index.js.map +1 -0
  118. package/dist/index.js +3 -2
  119. package/dist/index.js.map +1 -1
  120. package/dist/locale.js +78 -6
  121. package/dist/locale.js.map +1 -1
  122. package/dist/markdown/index.js +2 -2
  123. package/dist/markdown/index.js.map +1 -1
  124. package/dist/style.css +1 -1
  125. package/dist/style.js +2 -1
  126. package/dist/types/collaboration/binding.d.ts +12 -0
  127. package/dist/types/collaboration/cursors.d.ts +29 -1
  128. package/dist/types/collaboration/index.d.ts +53 -6
  129. package/dist/types/collaboration/inline-diff.d.ts +9 -0
  130. package/dist/types/collaboration/merged-props.d.ts +20 -0
  131. package/dist/types/collaboration/order.d.ts +5 -0
  132. package/dist/types/collaboration/table.d.ts +5 -1
  133. package/dist/types/collaboration/text.d.ts +20 -0
  134. package/dist/types/components/slash-choices.vue.d.ts +18 -0
  135. package/dist/types/core/blocks.d.ts +10 -0
  136. package/dist/types/core/commands.d.ts +17 -2
  137. package/dist/types/core/comments.d.ts +39 -3
  138. package/dist/types/core/convert.d.ts +10 -2
  139. package/dist/types/core/extension.d.ts +58 -4
  140. package/dist/types/core/model.d.ts +6 -1
  141. package/dist/types/core/plugins.d.ts +9 -0
  142. package/dist/types/core/prepare.d.ts +16 -2
  143. package/dist/types/core/schema.d.ts +1 -1
  144. package/dist/types/core/transaction.d.ts +6 -0
  145. package/dist/types/define-block.d.ts +16 -4
  146. package/dist/types/document.d.ts +5 -2
  147. package/dist/types/dom.d.ts +43 -4
  148. package/dist/types/editor.d.ts +9 -1
  149. package/dist/types/editor.vue.d.ts +24 -0
  150. package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
  151. package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
  152. package/dist/types/extensions/columns/html.d.ts +10 -0
  153. package/dist/types/extensions/columns/index.d.ts +9 -0
  154. package/dist/types/extensions/columns/keys.d.ts +6 -0
  155. package/dist/types/extensions/columns/plugin.d.ts +28 -0
  156. package/dist/types/extensions/columns/schema.d.ts +17 -0
  157. package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
  158. package/dist/types/extensions/editor-kit.d.ts +4 -1
  159. package/dist/types/extensions/table/view.d.ts +8 -1
  160. package/dist/types/flow/board-block.vue.d.ts +16 -0
  161. package/dist/types/flow/board.d.ts +53 -0
  162. package/dist/types/flow/index.d.ts +65 -0
  163. package/dist/types/index.d.ts +29 -4
  164. package/dist/types/locale.d.ts +34 -0
  165. package/dist/types/markdown/index.d.ts +8 -1
  166. package/dist/use-comments.js +2 -2
  167. package/dist/use-comments.js.map +1 -1
  168. package/package.json +14 -5
@@ -1 +1 @@
1
- {"version":3,"file":"table-controls.js","names":["_sfc_main"],"sources":["../../../src/extensions/table/table-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownFromLineIcon,\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n ArrowUpToLineIcon,\n CheckIcon,\n EraserIcon,\n GripHorizontalIcon,\n GripVerticalIcon,\n LayoutColumnsIcon,\n LayoutRowsIcon,\n MergeIcon,\n PlusIcon,\n SplitIcon,\n TextAlignCenterIcon,\n TextAlignLeftIcon,\n TextAlignRightIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection, type Command } from 'prosemirror-state'\nimport { CellSelection, TableMap, addColumn, addRow, type Rect } from 'prosemirror-tables'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { createId } from '../../core/model'\nimport { useMenuEscape } from '../../components/menu-escape'\nimport { useEditor } from '../../editor'\nimport {\n alignColumns,\n band,\n boundaries,\n clearCells,\n deleteColumns,\n deleteRows,\n inMergedCell,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n selectLines,\n splitMergedCell,\n tableAt,\n toggleHeader,\n} from './commands'\nimport { fitColumns, type TableAlign } from './schema'\n\nconst { view, state, root, messages } = useEditor()\n\n/** The table and the cell the controls are about: the hovered one, or the selection's. */\ninterface Target {\n /** Position right before the table node. */\n pos: number\n /** The cell's place in the grid. */\n rect: Rect\n}\n\nconst hovered = shallowRef<Target | null>(null)\nconst columnMenu = shallowRef(false)\nconst rowMenu = shallowRef(false)\nconst menuOpen = computed(() => columnMenu.value || rowMenu.value)\nuseMenuEscape(menuOpen, () => {\n columnMenu.value = false\n rowMenu.value = false\n})\nconst barShown = computed(() => !!layout.value?.bar && !menuOpen.value && !dragging.value)\n// the toolbar over selected cells stands in for the handles; a merged cell's goes below it\nconst handlesHidden = computed(() => barShown.value && hasCellSelection.value)\n\nfunction targetOf(cell: HTMLElement): Target | null {\n const current = view.value\n if (!current || !current.dom.contains(cell)) return null\n const $pos = current.state.doc.resolve(current.posAtDOM(cell, 0))\n const found = tableAt($pos)\n if (!found) return null\n // the cell node starts right before its content\n for (let depth = $pos.depth; depth > 0; depth--) {\n const role = $pos.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') {\n const cellPos = $pos.before(depth) - found.pos - 1\n return { pos: found.pos, rect: found.map.findCell(cellPos) }\n }\n }\n return null\n}\n\n/** The selection's cell when the pointer is elsewhere. */\nconst selected = computed<Target | null>(() => {\n const current = state.value\n if (!current) return null\n const selection = current.selection\n const $cell = selection instanceof CellSelection ? selection.$headCell : null\n const found = tableAt(selection.$head)\n if (!found) return null\n const start = found.pos + 1\n if ($cell) return { pos: found.pos, rect: found.map.findCell($cell.pos - start) }\n for (let depth = selection.$head.depth; depth > 0; depth--) {\n const role = selection.$head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell')\n return { pos: found.pos, rect: found.map.findCell(selection.$head.before(depth) - start) }\n }\n return null\n})\n\nconst target = computed(() => hovered.value ?? selected.value)\n\n/* where things go */\n\ninterface Layout {\n /** The table, relative to the editor. */\n table: { top: number; left: number; width: number; height: number }\n /** The visible part of the table, when it scrolls sideways. */\n frame: { left: number; right: number }\n column: { left: number; width: number }\n row: { top: number; height: number }\n /**\n * Where the cell toolbar goes (its centre): above selected cells, or below\n * the merged cell with the cursor.\n */\n bar: { top: number; left: number; below: boolean } | null\n}\n\nconst layout = shallowRef<Layout | null>(null)\n\nfunction cellElement(tablePos: number, row: number, col: number): HTMLElement | null {\n const current = view.value\n const table = current?.state.doc.nodeAt(tablePos)\n if (!current || !table) return null\n const map = TableMap.get(table)\n if (row >= map.height || col >= map.width) return null\n const pos = tablePos + 1 + map.map[row * map.width + col]!\n return current.nodeDOM(pos) as HTMLElement | null\n}\n\nfunction measure() {\n const current = view.value\n const host = root.value\n const at = target.value\n if (!current || !host || !at) return (layout.value = null)\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const tableElement = frameElement?.querySelector('table')\n if (!tableNode || !frameElement || !tableElement) return (layout.value = null)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = frameElement.getBoundingClientRect()\n const first = cellElement(at.pos, at.rect.top, at.rect.left)?.getBoundingClientRect()\n if (!first) return (layout.value = null)\n let bar: Layout['bar'] = null\n const boxes = barCells(current).map((pos) =>\n (current.nodeDOM(pos) as HTMLElement).getBoundingClientRect(),\n )\n if (boxes.length) {\n const left = Math.max(Math.min(...boxes.map((item) => item.left)), frameBox.left)\n const right = Math.min(Math.max(...boxes.map((item) => item.right)), frameBox.right)\n const below = !(current.state.selection instanceof CellSelection)\n bar = {\n top: below\n ? Math.max(...boxes.map((item) => item.bottom)) - box.top\n : Math.min(...boxes.map((item) => item.top)) - box.top,\n left: (left + right) / 2 - box.left,\n below,\n }\n }\n layout.value = {\n table: {\n top: tableBox.top - box.top,\n left: tableBox.left - box.left,\n width: tableBox.width,\n height: tableBox.height,\n },\n frame: { left: frameBox.left - box.left, right: frameBox.right - box.left },\n column: { left: first.left - box.left, width: first.width },\n row: { top: first.top - box.top, height: first.height },\n bar,\n }\n}\n\n/** The cells the toolbar is about: a cell selection's corners, or the merged cell with the cursor. */\nfunction barCells(current: NonNullable<typeof view.value>): number[] {\n const selection = current.state.selection\n if (selection instanceof CellSelection)\n return selection.$anchorCell.pos === selection.$headCell.pos\n ? []\n : [selection.$anchorCell.pos, selection.$headCell.pos]\n if (!inMergedCell(current.state)) return []\n const $head = selection.$head\n for (let depth = $head.depth; depth > 0; depth--) {\n const role = $head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') return [$head.before(depth)]\n }\n return []\n}\n\nlet frame = 0\nlet lastTarget: EventTarget | null = null\n\nfunction schedule() {\n if (frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (!menuOpen.value && !dragging.value) {\n const element = lastTarget instanceof Element ? lastTarget : null\n const cell = element?.closest<HTMLElement>('.dou-editor-table td, .dou-editor-table th')\n const inControls = element?.closest('.dou-editor-table-controls')\n if (cell) hovered.value = targetOf(cell)\n else if (!inControls) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n hovered.value = null\n schedule()\n}\n\nconst onScroll = () => schedule()\n\nonMounted(() => {\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n // the table frame scrolls sideways; the page scrolls too\n window.addEventListener('scroll', onScroll, true)\n window.addEventListener('resize', onScroll)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('resize', onScroll)\n if (frame) cancelAnimationFrame(frame)\n endDrag(false)\n})\n\nwatch([state, target], () => schedule())\n\n/* actions */\n\nfunction run(command: Command) {\n const current = view.value\n if (!current) return\n command(current.state, current.dispatch)\n current.focus()\n}\n\nfunction openMenu(axis: 'row' | 'column', pressed: Drag) {\n // the lines pressed on, even if the handles moved since\n const current = view.value\n if (!current) return\n current.dispatch(\n selectLines(current.state.tr, pressed.tablePos, axis, pressed.start, pressed.end),\n )\n // one menu at a time\n rowMenu.value = axis === 'row'\n columnMenu.value = axis === 'column'\n}\n\n/**\n * Whole lines are selected to show what a menu or a drag is about; after\n * it, the cursor goes into their first cell so the handles come back.\n */\nfunction collapseLines() {\n const current = view.value\n const selection = current?.state.selection\n if (!current || !(selection instanceof CellSelection)) return\n if (!selection.isRowSelection() && !selection.isColSelection()) return\n const $cell = current.state.doc.resolve(selection.$anchorCell.pos + 1)\n current.dispatch(current.state.tr.setSelection(TextSelection.near($cell)))\n}\n\nwatch(menuOpen, (open) => {\n if (open) return\n collapseLines()\n schedule()\n})\n\nconst can = (command: Command) => {\n const current = state.value\n return !!current && command(current)\n}\n\nconst tableNode = computed(() => {\n const at = target.value\n return at ? (state.value?.doc.nodeAt(at.pos) ?? null) : null\n})\n\nconst columnAlign = computed<TableAlign>(() => {\n const node = tableNode.value\n const at = target.value\n if (!node || !at) return 'left'\n return (fitColumns(node.attrs.columns, TableMap.get(node).width)[at.rect.left]?.align ??\n 'left') as TableAlign\n})\n\nconst aligns: { value: TableAlign; icon: unknown; label: () => string }[] = [\n { value: 'left', icon: TextAlignLeftIcon, label: () => messages.value.table.alignLeft },\n { value: 'center', icon: TextAlignCenterIcon, label: () => messages.value.table.alignCenter },\n { value: 'right', icon: TextAlignRightIcon, label: () => messages.value.table.alignRight },\n]\n\n/** The + bars: a column at the right end, a row at the bottom. */\nfunction addAtEnd(axis: 'row' | 'column') {\n const current = view.value\n const at = target.value\n if (!current || !at) return\n const table = current.state.doc.nodeAt(at.pos)!\n const map = TableMap.get(table)\n const rect = {\n left: 0,\n top: 0,\n right: map.width,\n bottom: map.height,\n map,\n table,\n tableStart: at.pos + 1,\n }\n let tr = current.state.tr\n if (axis === 'row') tr = addRow(tr, rect, map.height)\n else {\n const columns = fitColumns(table.attrs.columns, map.width)\n columns.push({ id: createId() })\n tr = addColumn(tr, rect, map.width).setNodeAttribute(at.pos, 'columns', columns)\n }\n current.dispatch(tr)\n}\n\n/* dragging rows and columns by their handle */\n\ninterface Drag {\n axis: 'row' | 'column'\n tablePos: number\n /** The lines that move: the target's, with any merged cells they belong to. */\n start: number\n end: number\n x: number\n y: number\n /** Where they go: the line they go before, or `null` for where they are. */\n to: number | null\n}\n\nlet drag: Drag | null = null\nconst dragging = shallowRef(false)\nconst drop = shallowRef<{ axis: 'row' | 'column'; at: number } | null>(null)\n/** A copy of the dragged lines that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction onHandleDown(axis: 'row' | 'column', event: PointerEvent) {\n const current = view.value\n const at = target.value\n if (event.button !== 0 || !current || !at || !current.editable) return\n const map = TableMap.get(current.state.doc.nodeAt(at.pos)!)\n const [from, to] = axis === 'row' ? [at.rect.top, at.rect.bottom] : [at.rect.left, at.rect.right]\n const lines = band(map, axis, from, to)\n drag = { axis, tablePos: at.pos, ...lines, x: event.clientX, y: event.clientY, to: null }\n window.addEventListener('pointermove', onDragMove)\n window.addEventListener('pointerup', onDragUp)\n window.addEventListener('pointercancel', onDragCancel)\n}\n\n/** Each boundary a run can go to, and where it is (relative to the editor). */\nfunction cutPlaces(moving: Drag): { cut: number; at: number }[] {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return []\n const box = host.getBoundingClientRect()\n const tableBox = element.getBoundingClientRect()\n const map = TableMap.get(table)\n const places: { cut: number; at: number }[] = []\n if (moving.axis === 'row') {\n const tops: number[] = []\n table.forEach((_row, offset) => {\n const row = current.nodeDOM(moving.tablePos + 1 + offset) as HTMLElement | null\n tops.push((row?.getBoundingClientRect().top ?? tableBox.top) - box.top)\n })\n for (const cut of boundaries(map, 'row'))\n places.push({ cut, at: cut < map.height ? tops[cut]! : tableBox.bottom - box.top })\n return places\n }\n for (const cut of boundaries(map, 'column')) {\n if (cut === map.width) {\n places.push({ cut, at: tableBox.right - box.left })\n continue\n }\n // no merged cell crosses a boundary, so the first row has a cell starting there\n let row = 0\n while (row < map.height && map.findCell(map.map[row * map.width + cut]!).left !== cut) row++\n const cell = cellElement(moving.tablePos, row, cut)\n if (cell) places.push({ cut, at: cell.getBoundingClientRect().left - box.left })\n }\n return places\n}\n\nfunction showGhost(moving: Drag) {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return\n const map = TableMap.get(table)\n const copy = document.createElement('table')\n copy.className = 'dou-editor-table'\n const body = document.createElement('tbody')\n copy.append(body)\n let width = 0\n const [rows, cols] =\n moving.axis === 'row'\n ? [\n [moving.start, moving.end],\n [0, map.width],\n ]\n : [\n [0, map.height],\n [moving.start, moving.end],\n ]\n for (let row = rows[0]!; row < rows[1]!; row++) {\n const line = document.createElement('tr')\n let lineWidth = 0\n for (let col = cols[0]!; col < cols[1]!; col++) {\n const rect = map.findCell(map.map[row * map.width + col]!)\n if (rect.top !== row || rect.left !== col) continue\n const cell = cellElement(moving.tablePos, row, col)\n if (!cell) continue\n const clone = cell.cloneNode(true) as HTMLElement\n clone.classList.remove('selectedCell')\n clone.style.width = `${cell.getBoundingClientRect().width}px`\n lineWidth += cell.getBoundingClientRect().width\n line.append(clone)\n }\n width = Math.max(width, lineWidth)\n body.append(line)\n }\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost dou-editor-table__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n ghost.style.width = `${Math.min(width, 360) + 2}px`\n ghost.append(copy)\n host.append(ghost)\n}\n\nfunction onDragMove(event: PointerEvent) {\n const moving = drag\n if (!moving) return\n if (!dragging.value) {\n if (Math.hypot(event.clientX - moving.x, event.clientY - moving.y) < 4) return\n dragging.value = true\n columnMenu.value = false\n rowMenu.value = false\n const current = view.value\n if (current)\n current.dispatch(\n selectLines(current.state.tr, moving.tablePos, moving.axis, moving.start, moving.end),\n )\n showGhost(moving)\n }\n if (ghost) ghost.style.transform = `translate(${event.clientX + 12}px, ${event.clientY + 12}px)`\n const host = root.value\n if (!host) return\n const box = host.getBoundingClientRect()\n const pointer = moving.axis === 'row' ? event.clientY - box.top : event.clientX - box.left\n let best: { cut: number; at: number } | null = null\n for (const place of cutPlaces(moving))\n if (!best || Math.abs(place.at - pointer) < Math.abs(best.at - pointer)) best = place\n // a boundary of the run itself leaves it where it is\n if (!best || (best.cut >= moving.start && best.cut <= moving.end)) {\n moving.to = null\n drop.value = null\n return\n }\n moving.to = best.cut\n drop.value = { axis: moving.axis, at: best.at }\n}\n\nfunction onDragUp() {\n endDrag(true)\n}\n\nfunction onDragCancel() {\n endDrag(false)\n}\n\nfunction endDrag(apply: boolean) {\n window.removeEventListener('pointermove', onDragMove)\n window.removeEventListener('pointerup', onDragUp)\n window.removeEventListener('pointercancel', onDragCancel)\n const moving = drag\n drag = null\n ghost?.remove()\n ghost = null\n drop.value = null\n if (!dragging.value) {\n // a press without a drag opens the menu; on release rather than on\n // click, as the press may close another menu and move the handles\n if (apply && moving) openMenu(moving.axis, moving)\n return\n }\n dragging.value = false\n if (apply && moving?.to !== null && moving)\n run(moveLinesTo(moving.tablePos, moving.axis, moving.start, moving.end, moving.to))\n collapseLines()\n schedule()\n}\n\nconst hasCellSelection = computed(() => {\n const selection = state.value?.selection\n return selection instanceof CellSelection && selection.$anchorCell.pos !== selection.$headCell.pos\n})\n\nconst visible = computed(() => !!layout.value && !!target.value)\n</script>\n\n<template>\n <div v-if=\"visible && layout\" class=\"dou-editor-table-controls\" @mousedown.prevent>\n <!-- column handle, above the column -->\n <DouDropdown\n v-model:open=\"columnMenu\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-column\"\n :class=\"{ 'is-active': columnMenu }\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(Math.max(layout.column.left + layout.column.width / 2, layout.frame.left + 12), layout.frame.right - 12)}px`,\n }\"\n :aria-label=\"messages.table.column\"\n :title=\"messages.table.column\"\n @pointerdown=\"onHandleDown('column', $event)\"\n >\n <GripHorizontalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertColumn('before'))\">\n <template #prefix><ArrowLeftToLineIcon /></template>\n {{ messages.table.insertLeft }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertColumn('after'))\">\n <template #prefix><ArrowRightToLineIcon /></template>\n {{ messages.table.insertRight }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('column', -1))\"\n @click=\"run(moveLines('column', -1))\"\n >\n <template #prefix><ArrowLeftIcon /></template>\n {{ messages.table.moveLeft }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!can(moveLines('column', 1))\"\n @click=\"run(moveLines('column', 1))\"\n >\n <template #prefix><ArrowRightIcon /></template>\n {{ messages.table.moveRight }}\n </DouDropdownItem>\n <DouDropdownSub divided :title=\"aligns.find((item) => item.value === columnAlign)!.label()\">\n <template #prefix>\n <component :is=\"aligns.find((item) => item.value === columnAlign)!.icon\" />\n </template>\n <DouDropdownItem\n v-for=\"item in aligns\"\n :key=\"item.value\"\n @click=\"run(alignColumns(item.value))\"\n >\n <template #prefix><component :is=\"item.icon\" /></template>\n {{ item.label() }}\n <template v-if=\"item.value === columnAlign\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </DouDropdownSub>\n <DouDropdownItem v-if=\"target?.rect.left === 0\" @click=\"run(toggleHeader('headerColumn'))\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.table.headerColumn }}\n <template v-if=\"tableNode?.attrs.headerColumn\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteColumns)\" @click=\"run(deleteColumns)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteColumn }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- row handle, left of the row -->\n <DouDropdown\n v-model:open=\"rowMenu\"\n trigger=\"manual\"\n placement=\"right-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-row\"\n :class=\"{ 'is-active': rowMenu }\"\n :style=\"{\n top: `${layout.row.top + layout.row.height / 2}px`,\n left: `${layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.row\"\n :title=\"messages.table.row\"\n @pointerdown=\"onHandleDown('row', $event)\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertRow('before'))\">\n <template #prefix><ArrowUpToLineIcon /></template>\n {{ messages.table.insertAbove }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertRow('after'))\">\n <template #prefix><ArrowDownFromLineIcon /></template>\n {{ messages.table.insertBelow }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('row', -1))\"\n @click=\"run(moveLines('row', -1))\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.table.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem :disabled=\"!can(moveLines('row', 1))\" @click=\"run(moveLines('row', 1))\">\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.table.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n v-if=\"target?.rect.top === 0\"\n divided\n @click=\"run(toggleHeader('headerRow'))\"\n >\n <template #prefix><LayoutRowsIcon /></template>\n {{ messages.table.headerRow }}\n <template v-if=\"tableNode?.attrs.headerRow\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteRows)\" @click=\"run(deleteRows)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteRow }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- + bars -->\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-column\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(layout.table.left + layout.table.width, layout.frame.right)}px`,\n height: `${layout.table.height}px`,\n }\"\n :aria-label=\"messages.table.addColumn\"\n :title=\"messages.table.addColumn\"\n @click=\"addAtEnd('column')\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-row\"\n :style=\"{\n top: `${layout.table.top + layout.table.height}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.addRow\"\n :title=\"messages.table.addRow\"\n @click=\"addAtEnd('row')\"\n >\n <PlusIcon />\n </button>\n\n <!-- where dragged lines go -->\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :class=\"{ 'is-vertical': drop.axis === 'column' }\"\n :style=\"\n drop.axis === 'row'\n ? {\n top: `${drop.at}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\n : {\n top: `${layout.table.top}px`,\n left: `${drop.at}px`,\n height: `${layout.table.height}px`,\n }\n \"\n />\n\n <!-- cells: merge, unmerge, clear -->\n <div\n v-if=\"barShown && layout.bar && !dragging\"\n class=\"dou-editor-table__cells\"\n :class=\"{ 'is-below': layout.bar.below }\"\n :style=\"{ top: `${layout.bar.top}px`, left: `${layout.bar.left}px` }\"\n >\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :disabled=\"!can(mergeCells)\"\n @click=\"run(mergeCells)\"\n >\n <MergeIcon />{{ messages.table.merge }}\n </button>\n <button\n v-if=\"can(splitMergedCell)\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n @click=\"run(splitMergedCell)\"\n >\n <SplitIcon />{{ messages.table.split }}\n </button>\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :aria-label=\"messages.table.clear\"\n :title=\"messages.table.clear\"\n @click=\"run(clearCells)\"\n >\n <EraserIcon />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"table-controls.js","names":["_sfc_main"],"sources":["../../../src/extensions/table/table-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownFromLineIcon,\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n ArrowUpToLineIcon,\n CheckIcon,\n EraserIcon,\n GripHorizontalIcon,\n GripVerticalIcon,\n LayoutColumnsIcon,\n LayoutRowsIcon,\n MergeIcon,\n PlusIcon,\n SplitIcon,\n TextAlignCenterIcon,\n TextAlignLeftIcon,\n TextAlignRightIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection, type Command } from 'prosemirror-state'\nimport { CellSelection, TableMap, addColumn, addRow, type Rect } from 'prosemirror-tables'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { createId } from '../../core/model'\nimport { useMenuEscape } from '../../components/menu-escape'\nimport { useEditor } from '../../editor'\nimport {\n alignColumns,\n band,\n boundaries,\n clearCells,\n deleteColumns,\n deleteRows,\n inMergedCell,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n selectLines,\n splitMergedCell,\n tableAt,\n toggleHeader,\n} from './commands'\nimport { fitColumns, type TableAlign } from './schema'\n\nconst { view, state, root, messages } = useEditor()\n\n/** The table and the cell the controls are about: the hovered one, or the selection's. */\ninterface Target {\n /** Position right before the table node. */\n pos: number\n /** The cell's place in the grid. */\n rect: Rect\n}\n\nconst hovered = shallowRef<Target | null>(null)\nconst columnMenu = shallowRef(false)\nconst rowMenu = shallowRef(false)\nconst menuOpen = computed(() => columnMenu.value || rowMenu.value)\nuseMenuEscape(menuOpen, () => {\n columnMenu.value = false\n rowMenu.value = false\n})\nconst barShown = computed(() => !!layout.value?.bar && !menuOpen.value && !dragging.value)\n// the toolbar over selected cells stands in for the handles; a merged cell's goes below it\nconst handlesHidden = computed(() => barShown.value && hasCellSelection.value)\n\nfunction targetOf(cell: HTMLElement): Target | null {\n const current = view.value\n if (!current || !current.dom.contains(cell)) return null\n const $pos = current.state.doc.resolve(current.posAtDOM(cell, 0))\n const found = tableAt($pos)\n if (!found) return null\n // the cell node starts right before its content\n for (let depth = $pos.depth; depth > 0; depth--) {\n const role = $pos.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') {\n const cellPos = $pos.before(depth) - found.pos - 1\n return { pos: found.pos, rect: found.map.findCell(cellPos) }\n }\n }\n return null\n}\n\n/** The selection's cell when the pointer is elsewhere. */\nconst selected = computed<Target | null>(() => {\n const current = state.value\n if (!current) return null\n const selection = current.selection\n const $cell = selection instanceof CellSelection ? selection.$headCell : null\n const found = tableAt(selection.$head)\n if (!found) return null\n const start = found.pos + 1\n if ($cell) return { pos: found.pos, rect: found.map.findCell($cell.pos - start) }\n for (let depth = selection.$head.depth; depth > 0; depth--) {\n const role = selection.$head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell')\n return { pos: found.pos, rect: found.map.findCell(selection.$head.before(depth) - start) }\n }\n return null\n})\n\nconst target = computed(() => hovered.value ?? selected.value)\n\n/* where things go */\n\ninterface Layout {\n /** The table, relative to the editor. */\n table: { top: number; left: number; width: number; height: number }\n /** The visible part of the table, when it scrolls sideways. */\n frame: { left: number; right: number }\n column: { left: number; width: number }\n row: { top: number; height: number }\n /**\n * Where the cell toolbar goes (its centre): above selected cells, or below\n * the merged cell with the cursor.\n */\n bar: { top: number; left: number; below: boolean } | null\n}\n\nconst layout = shallowRef<Layout | null>(null)\n\nfunction cellElement(tablePos: number, row: number, col: number): HTMLElement | null {\n const current = view.value\n const table = current?.state.doc.nodeAt(tablePos)\n if (!current || !table) return null\n const map = TableMap.get(table)\n if (row >= map.height || col >= map.width) return null\n const pos = tablePos + 1 + map.map[row * map.width + col]!\n return current.nodeDOM(pos) as HTMLElement | null\n}\n\nfunction measure() {\n const current = view.value\n const host = root.value\n const at = target.value\n if (!current || !host || !at) return (layout.value = null)\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const tableElement = frameElement?.querySelector('table')\n if (!tableNode || !frameElement || !tableElement) return (layout.value = null)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = frameElement.getBoundingClientRect()\n const first = cellElement(at.pos, at.rect.top, at.rect.left)?.getBoundingClientRect()\n if (!first) return (layout.value = null)\n let bar: Layout['bar'] = null\n const boxes = barCells(current).map((pos) =>\n (current.nodeDOM(pos) as HTMLElement).getBoundingClientRect(),\n )\n if (boxes.length) {\n const left = Math.max(Math.min(...boxes.map((item) => item.left)), frameBox.left)\n const right = Math.min(Math.max(...boxes.map((item) => item.right)), frameBox.right)\n const below = !(current.state.selection instanceof CellSelection)\n bar = {\n top: below\n ? Math.max(...boxes.map((item) => item.bottom)) - box.top\n : Math.min(...boxes.map((item) => item.top)) - box.top,\n left: (left + right) / 2 - box.left,\n below,\n }\n }\n layout.value = {\n table: {\n top: tableBox.top - box.top,\n left: tableBox.left - box.left,\n width: tableBox.width,\n height: tableBox.height,\n },\n // a top-level table's frame reaches into the margins, the table starting\n // after its padding: what shows of it starts at whichever is further in\n frame: {\n left: Math.max(frameBox.left, tableBox.left) - box.left,\n right: frameBox.right - box.left,\n },\n column: { left: first.left - box.left, width: first.width },\n row: { top: first.top - box.top, height: first.height },\n bar,\n }\n}\n\n/** The cells the toolbar is about: a cell selection's corners, or the merged cell with the cursor. */\nfunction barCells(current: NonNullable<typeof view.value>): number[] {\n const selection = current.state.selection\n if (selection instanceof CellSelection)\n return selection.$anchorCell.pos === selection.$headCell.pos\n ? []\n : [selection.$anchorCell.pos, selection.$headCell.pos]\n if (!inMergedCell(current.state)) return []\n const $head = selection.$head\n for (let depth = $head.depth; depth > 0; depth--) {\n const role = $head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') return [$head.before(depth)]\n }\n return []\n}\n\nlet frame = 0\nlet lastTarget: EventTarget | null = null\n\nfunction schedule() {\n if (frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (!menuOpen.value && !dragging.value) {\n const element = lastTarget instanceof Element ? lastTarget : null\n const cell = element?.closest<HTMLElement>('.dou-editor-table td, .dou-editor-table th')\n const inControls = element?.closest('.dou-editor-table-controls')\n if (cell) hovered.value = targetOf(cell)\n else if (!inControls) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n hovered.value = null\n schedule()\n}\n\nconst onScroll = () => schedule()\n\nonMounted(() => {\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n // the table frame scrolls sideways; the page scrolls too\n window.addEventListener('scroll', onScroll, true)\n window.addEventListener('resize', onScroll)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('resize', onScroll)\n if (frame) cancelAnimationFrame(frame)\n endDrag(false)\n})\n\nwatch([state, target], () => schedule())\n\n/* actions */\n\nfunction run(command: Command) {\n const current = view.value\n if (!current) return\n command(current.state, current.dispatch)\n current.focus()\n}\n\nfunction openMenu(axis: 'row' | 'column', pressed: Drag) {\n // the lines pressed on, even if the handles moved since\n const current = view.value\n if (!current) return\n current.dispatch(\n selectLines(current.state.tr, pressed.tablePos, axis, pressed.start, pressed.end),\n )\n // one menu at a time\n rowMenu.value = axis === 'row'\n columnMenu.value = axis === 'column'\n}\n\n/**\n * Whole lines are selected to show what a menu or a drag is about; after\n * it, the cursor goes into their first cell so the handles come back.\n */\nfunction collapseLines() {\n const current = view.value\n const selection = current?.state.selection\n if (!current || !(selection instanceof CellSelection)) return\n if (!selection.isRowSelection() && !selection.isColSelection()) return\n const $cell = current.state.doc.resolve(selection.$anchorCell.pos + 1)\n current.dispatch(current.state.tr.setSelection(TextSelection.near($cell)))\n}\n\nwatch(menuOpen, (open) => {\n if (open) return\n collapseLines()\n schedule()\n})\n\nconst can = (command: Command) => {\n const current = state.value\n return !!current && command(current)\n}\n\nconst tableNode = computed(() => {\n const at = target.value\n return at ? (state.value?.doc.nodeAt(at.pos) ?? null) : null\n})\n\nconst columnAlign = computed<TableAlign>(() => {\n const node = tableNode.value\n const at = target.value\n if (!node || !at) return 'left'\n return (fitColumns(node.attrs.columns, TableMap.get(node).width)[at.rect.left]?.align ??\n 'left') as TableAlign\n})\n\nconst aligns: { value: TableAlign; icon: unknown; label: () => string }[] = [\n { value: 'left', icon: TextAlignLeftIcon, label: () => messages.value.table.alignLeft },\n { value: 'center', icon: TextAlignCenterIcon, label: () => messages.value.table.alignCenter },\n { value: 'right', icon: TextAlignRightIcon, label: () => messages.value.table.alignRight },\n]\n\n/** The + bars: a column at the right end, a row at the bottom. */\nfunction addAtEnd(axis: 'row' | 'column') {\n const current = view.value\n const at = target.value\n if (!current || !at) return\n const table = current.state.doc.nodeAt(at.pos)!\n const map = TableMap.get(table)\n const rect = {\n left: 0,\n top: 0,\n right: map.width,\n bottom: map.height,\n map,\n table,\n tableStart: at.pos + 1,\n }\n let tr = current.state.tr\n if (axis === 'row') tr = addRow(tr, rect, map.height)\n else {\n const columns = fitColumns(table.attrs.columns, map.width)\n columns.push({ id: createId() })\n tr = addColumn(tr, rect, map.width).setNodeAttribute(at.pos, 'columns', columns)\n }\n current.dispatch(tr)\n}\n\n/* dragging rows and columns by their handle */\n\ninterface Drag {\n axis: 'row' | 'column'\n tablePos: number\n /** The lines that move: the target's, with any merged cells they belong to. */\n start: number\n end: number\n x: number\n y: number\n /** Where they go: the line they go before, or `null` for where they are. */\n to: number | null\n}\n\nlet drag: Drag | null = null\nconst dragging = shallowRef(false)\nconst drop = shallowRef<{ axis: 'row' | 'column'; at: number } | null>(null)\n/** A copy of the dragged lines that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction onHandleDown(axis: 'row' | 'column', event: PointerEvent) {\n const current = view.value\n const at = target.value\n if (event.button !== 0 || !current || !at || !current.editable) return\n const map = TableMap.get(current.state.doc.nodeAt(at.pos)!)\n const [from, to] = axis === 'row' ? [at.rect.top, at.rect.bottom] : [at.rect.left, at.rect.right]\n const lines = band(map, axis, from, to)\n drag = { axis, tablePos: at.pos, ...lines, x: event.clientX, y: event.clientY, to: null }\n window.addEventListener('pointermove', onDragMove)\n window.addEventListener('pointerup', onDragUp)\n window.addEventListener('pointercancel', onDragCancel)\n}\n\n/** Each boundary a run can go to, and where it is (relative to the editor). */\nfunction cutPlaces(moving: Drag): { cut: number; at: number }[] {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return []\n const box = host.getBoundingClientRect()\n const tableBox = element.getBoundingClientRect()\n const map = TableMap.get(table)\n const places: { cut: number; at: number }[] = []\n if (moving.axis === 'row') {\n const tops: number[] = []\n table.forEach((_row, offset) => {\n const row = current.nodeDOM(moving.tablePos + 1 + offset) as HTMLElement | null\n tops.push((row?.getBoundingClientRect().top ?? tableBox.top) - box.top)\n })\n for (const cut of boundaries(map, 'row'))\n places.push({ cut, at: cut < map.height ? tops[cut]! : tableBox.bottom - box.top })\n return places\n }\n for (const cut of boundaries(map, 'column')) {\n if (cut === map.width) {\n places.push({ cut, at: tableBox.right - box.left })\n continue\n }\n // no merged cell crosses a boundary, so the first row has a cell starting there\n let row = 0\n while (row < map.height && map.findCell(map.map[row * map.width + cut]!).left !== cut) row++\n const cell = cellElement(moving.tablePos, row, cut)\n if (cell) places.push({ cut, at: cell.getBoundingClientRect().left - box.left })\n }\n return places\n}\n\nfunction showGhost(moving: Drag) {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return\n const map = TableMap.get(table)\n const copy = document.createElement('table')\n copy.className = 'dou-editor-table'\n const body = document.createElement('tbody')\n copy.append(body)\n let width = 0\n const [rows, cols] =\n moving.axis === 'row'\n ? [\n [moving.start, moving.end],\n [0, map.width],\n ]\n : [\n [0, map.height],\n [moving.start, moving.end],\n ]\n for (let row = rows[0]!; row < rows[1]!; row++) {\n const line = document.createElement('tr')\n let lineWidth = 0\n for (let col = cols[0]!; col < cols[1]!; col++) {\n const rect = map.findCell(map.map[row * map.width + col]!)\n if (rect.top !== row || rect.left !== col) continue\n const cell = cellElement(moving.tablePos, row, col)\n if (!cell) continue\n const clone = cell.cloneNode(true) as HTMLElement\n clone.classList.remove('selectedCell')\n clone.style.width = `${cell.getBoundingClientRect().width}px`\n lineWidth += cell.getBoundingClientRect().width\n line.append(clone)\n }\n width = Math.max(width, lineWidth)\n body.append(line)\n }\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost dou-editor-table__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n ghost.style.width = `${Math.min(width, 360) + 2}px`\n ghost.append(copy)\n host.append(ghost)\n}\n\nfunction onDragMove(event: PointerEvent) {\n const moving = drag\n if (!moving) return\n if (!dragging.value) {\n if (Math.hypot(event.clientX - moving.x, event.clientY - moving.y) < 4) return\n dragging.value = true\n columnMenu.value = false\n rowMenu.value = false\n const current = view.value\n if (current)\n current.dispatch(\n selectLines(current.state.tr, moving.tablePos, moving.axis, moving.start, moving.end),\n )\n showGhost(moving)\n }\n if (ghost) ghost.style.transform = `translate(${event.clientX + 12}px, ${event.clientY + 12}px)`\n const host = root.value\n if (!host) return\n const box = host.getBoundingClientRect()\n const pointer = moving.axis === 'row' ? event.clientY - box.top : event.clientX - box.left\n let best: { cut: number; at: number } | null = null\n for (const place of cutPlaces(moving))\n if (!best || Math.abs(place.at - pointer) < Math.abs(best.at - pointer)) best = place\n // a boundary of the run itself leaves it where it is\n if (!best || (best.cut >= moving.start && best.cut <= moving.end)) {\n moving.to = null\n drop.value = null\n return\n }\n moving.to = best.cut\n drop.value = { axis: moving.axis, at: best.at }\n}\n\nfunction onDragUp() {\n endDrag(true)\n}\n\nfunction onDragCancel() {\n endDrag(false)\n}\n\nfunction endDrag(apply: boolean) {\n window.removeEventListener('pointermove', onDragMove)\n window.removeEventListener('pointerup', onDragUp)\n window.removeEventListener('pointercancel', onDragCancel)\n const moving = drag\n drag = null\n ghost?.remove()\n ghost = null\n drop.value = null\n if (!dragging.value) {\n // a press without a drag opens the menu; on release rather than on\n // click, as the press may close another menu and move the handles\n if (apply && moving) openMenu(moving.axis, moving)\n return\n }\n dragging.value = false\n if (apply && moving?.to !== null && moving)\n run(moveLinesTo(moving.tablePos, moving.axis, moving.start, moving.end, moving.to))\n collapseLines()\n schedule()\n}\n\nconst hasCellSelection = computed(() => {\n const selection = state.value?.selection\n return selection instanceof CellSelection && selection.$anchorCell.pos !== selection.$headCell.pos\n})\n\nconst visible = computed(() => !!layout.value && !!target.value)\n</script>\n\n<template>\n <div v-if=\"visible && layout\" class=\"dou-editor-table-controls\" @mousedown.prevent>\n <!-- column handle, above the column -->\n <DouDropdown\n v-model:open=\"columnMenu\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-column\"\n :class=\"{ 'is-active': columnMenu }\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(Math.max(layout.column.left + layout.column.width / 2, layout.frame.left + 12), layout.frame.right - 12)}px`,\n }\"\n :aria-label=\"messages.table.column\"\n :title=\"messages.table.column\"\n @pointerdown=\"onHandleDown('column', $event)\"\n >\n <GripHorizontalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertColumn('before'))\">\n <template #prefix><ArrowLeftToLineIcon /></template>\n {{ messages.table.insertLeft }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertColumn('after'))\">\n <template #prefix><ArrowRightToLineIcon /></template>\n {{ messages.table.insertRight }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('column', -1))\"\n @click=\"run(moveLines('column', -1))\"\n >\n <template #prefix><ArrowLeftIcon /></template>\n {{ messages.table.moveLeft }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!can(moveLines('column', 1))\"\n @click=\"run(moveLines('column', 1))\"\n >\n <template #prefix><ArrowRightIcon /></template>\n {{ messages.table.moveRight }}\n </DouDropdownItem>\n <DouDropdownSub divided :title=\"aligns.find((item) => item.value === columnAlign)!.label()\">\n <template #prefix>\n <component :is=\"aligns.find((item) => item.value === columnAlign)!.icon\" />\n </template>\n <DouDropdownItem\n v-for=\"item in aligns\"\n :key=\"item.value\"\n @click=\"run(alignColumns(item.value))\"\n >\n <template #prefix><component :is=\"item.icon\" /></template>\n {{ item.label() }}\n <template v-if=\"item.value === columnAlign\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </DouDropdownSub>\n <DouDropdownItem v-if=\"target?.rect.left === 0\" @click=\"run(toggleHeader('headerColumn'))\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.table.headerColumn }}\n <template v-if=\"tableNode?.attrs.headerColumn\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteColumns)\" @click=\"run(deleteColumns)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteColumn }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- row handle, left of the row -->\n <DouDropdown\n v-model:open=\"rowMenu\"\n trigger=\"manual\"\n placement=\"right-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-row\"\n :class=\"{ 'is-active': rowMenu }\"\n :style=\"{\n top: `${layout.row.top + layout.row.height / 2}px`,\n left: `${layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.row\"\n :title=\"messages.table.row\"\n @pointerdown=\"onHandleDown('row', $event)\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertRow('before'))\">\n <template #prefix><ArrowUpToLineIcon /></template>\n {{ messages.table.insertAbove }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertRow('after'))\">\n <template #prefix><ArrowDownFromLineIcon /></template>\n {{ messages.table.insertBelow }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('row', -1))\"\n @click=\"run(moveLines('row', -1))\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.table.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem :disabled=\"!can(moveLines('row', 1))\" @click=\"run(moveLines('row', 1))\">\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.table.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n v-if=\"target?.rect.top === 0\"\n divided\n @click=\"run(toggleHeader('headerRow'))\"\n >\n <template #prefix><LayoutRowsIcon /></template>\n {{ messages.table.headerRow }}\n <template v-if=\"tableNode?.attrs.headerRow\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteRows)\" @click=\"run(deleteRows)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteRow }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- + bars -->\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-column\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(layout.table.left + layout.table.width, layout.frame.right)}px`,\n height: `${layout.table.height}px`,\n }\"\n :aria-label=\"messages.table.addColumn\"\n :title=\"messages.table.addColumn\"\n @click=\"addAtEnd('column')\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-row\"\n :style=\"{\n top: `${layout.table.top + layout.table.height}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.addRow\"\n :title=\"messages.table.addRow\"\n @click=\"addAtEnd('row')\"\n >\n <PlusIcon />\n </button>\n\n <!-- where dragged lines go -->\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :class=\"{ 'is-vertical': drop.axis === 'column' }\"\n :style=\"\n drop.axis === 'row'\n ? {\n top: `${drop.at}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\n : {\n top: `${layout.table.top}px`,\n left: `${drop.at}px`,\n height: `${layout.table.height}px`,\n }\n \"\n />\n\n <!-- cells: merge, unmerge, clear -->\n <div\n v-if=\"barShown && layout.bar && !dragging\"\n class=\"dou-editor-table__cells\"\n :class=\"{ 'is-below': layout.bar.below }\"\n :style=\"{ top: `${layout.bar.top}px`, left: `${layout.bar.left}px` }\"\n >\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :disabled=\"!can(mergeCells)\"\n @click=\"run(mergeCells)\"\n >\n <MergeIcon />{{ messages.table.merge }}\n </button>\n <button\n v-if=\"can(splitMergedCell)\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n @click=\"run(splitMergedCell)\"\n >\n <SplitIcon />{{ messages.table.split }}\n </button>\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :aria-label=\"messages.table.clear\"\n :title=\"messages.table.clear\"\n @click=\"run(clearCells)\"\n >\n <EraserIcon />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":""}
@@ -115,7 +115,7 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
115
115
  height: tableBox.height
116
116
  },
117
117
  frame: {
118
- left: frameBox.left - box.left,
118
+ left: Math.max(frameBox.left, tableBox.left) - box.left,
119
119
  right: frameBox.right - box.left
120
120
  },
121
121
  column: {
@@ -1 +1 @@
1
- {"version":3,"file":"table-controls.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_withModifiers","_createVNode","_unref","_withCtx","_createTextVNode","_toDisplayString","_createBlock","_resolveDynamicComponent","_Fragment","_renderList","_createSlots","_createCommentVNode","_withDirectives","_createElementVNode","_normalizeClass","_normalizeStyle","_vShow"],"sources":["../../../src/extensions/table/table-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownFromLineIcon,\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n ArrowUpToLineIcon,\n CheckIcon,\n EraserIcon,\n GripHorizontalIcon,\n GripVerticalIcon,\n LayoutColumnsIcon,\n LayoutRowsIcon,\n MergeIcon,\n PlusIcon,\n SplitIcon,\n TextAlignCenterIcon,\n TextAlignLeftIcon,\n TextAlignRightIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection, type Command } from 'prosemirror-state'\nimport { CellSelection, TableMap, addColumn, addRow, type Rect } from 'prosemirror-tables'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { createId } from '../../core/model'\nimport { useMenuEscape } from '../../components/menu-escape'\nimport { useEditor } from '../../editor'\nimport {\n alignColumns,\n band,\n boundaries,\n clearCells,\n deleteColumns,\n deleteRows,\n inMergedCell,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n selectLines,\n splitMergedCell,\n tableAt,\n toggleHeader,\n} from './commands'\nimport { fitColumns, type TableAlign } from './schema'\n\nconst { view, state, root, messages } = useEditor()\n\n/** The table and the cell the controls are about: the hovered one, or the selection's. */\ninterface Target {\n /** Position right before the table node. */\n pos: number\n /** The cell's place in the grid. */\n rect: Rect\n}\n\nconst hovered = shallowRef<Target | null>(null)\nconst columnMenu = shallowRef(false)\nconst rowMenu = shallowRef(false)\nconst menuOpen = computed(() => columnMenu.value || rowMenu.value)\nuseMenuEscape(menuOpen, () => {\n columnMenu.value = false\n rowMenu.value = false\n})\nconst barShown = computed(() => !!layout.value?.bar && !menuOpen.value && !dragging.value)\n// the toolbar over selected cells stands in for the handles; a merged cell's goes below it\nconst handlesHidden = computed(() => barShown.value && hasCellSelection.value)\n\nfunction targetOf(cell: HTMLElement): Target | null {\n const current = view.value\n if (!current || !current.dom.contains(cell)) return null\n const $pos = current.state.doc.resolve(current.posAtDOM(cell, 0))\n const found = tableAt($pos)\n if (!found) return null\n // the cell node starts right before its content\n for (let depth = $pos.depth; depth > 0; depth--) {\n const role = $pos.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') {\n const cellPos = $pos.before(depth) - found.pos - 1\n return { pos: found.pos, rect: found.map.findCell(cellPos) }\n }\n }\n return null\n}\n\n/** The selection's cell when the pointer is elsewhere. */\nconst selected = computed<Target | null>(() => {\n const current = state.value\n if (!current) return null\n const selection = current.selection\n const $cell = selection instanceof CellSelection ? selection.$headCell : null\n const found = tableAt(selection.$head)\n if (!found) return null\n const start = found.pos + 1\n if ($cell) return { pos: found.pos, rect: found.map.findCell($cell.pos - start) }\n for (let depth = selection.$head.depth; depth > 0; depth--) {\n const role = selection.$head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell')\n return { pos: found.pos, rect: found.map.findCell(selection.$head.before(depth) - start) }\n }\n return null\n})\n\nconst target = computed(() => hovered.value ?? selected.value)\n\n/* where things go */\n\ninterface Layout {\n /** The table, relative to the editor. */\n table: { top: number; left: number; width: number; height: number }\n /** The visible part of the table, when it scrolls sideways. */\n frame: { left: number; right: number }\n column: { left: number; width: number }\n row: { top: number; height: number }\n /**\n * Where the cell toolbar goes (its centre): above selected cells, or below\n * the merged cell with the cursor.\n */\n bar: { top: number; left: number; below: boolean } | null\n}\n\nconst layout = shallowRef<Layout | null>(null)\n\nfunction cellElement(tablePos: number, row: number, col: number): HTMLElement | null {\n const current = view.value\n const table = current?.state.doc.nodeAt(tablePos)\n if (!current || !table) return null\n const map = TableMap.get(table)\n if (row >= map.height || col >= map.width) return null\n const pos = tablePos + 1 + map.map[row * map.width + col]!\n return current.nodeDOM(pos) as HTMLElement | null\n}\n\nfunction measure() {\n const current = view.value\n const host = root.value\n const at = target.value\n if (!current || !host || !at) return (layout.value = null)\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const tableElement = frameElement?.querySelector('table')\n if (!tableNode || !frameElement || !tableElement) return (layout.value = null)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = frameElement.getBoundingClientRect()\n const first = cellElement(at.pos, at.rect.top, at.rect.left)?.getBoundingClientRect()\n if (!first) return (layout.value = null)\n let bar: Layout['bar'] = null\n const boxes = barCells(current).map((pos) =>\n (current.nodeDOM(pos) as HTMLElement).getBoundingClientRect(),\n )\n if (boxes.length) {\n const left = Math.max(Math.min(...boxes.map((item) => item.left)), frameBox.left)\n const right = Math.min(Math.max(...boxes.map((item) => item.right)), frameBox.right)\n const below = !(current.state.selection instanceof CellSelection)\n bar = {\n top: below\n ? Math.max(...boxes.map((item) => item.bottom)) - box.top\n : Math.min(...boxes.map((item) => item.top)) - box.top,\n left: (left + right) / 2 - box.left,\n below,\n }\n }\n layout.value = {\n table: {\n top: tableBox.top - box.top,\n left: tableBox.left - box.left,\n width: tableBox.width,\n height: tableBox.height,\n },\n frame: { left: frameBox.left - box.left, right: frameBox.right - box.left },\n column: { left: first.left - box.left, width: first.width },\n row: { top: first.top - box.top, height: first.height },\n bar,\n }\n}\n\n/** The cells the toolbar is about: a cell selection's corners, or the merged cell with the cursor. */\nfunction barCells(current: NonNullable<typeof view.value>): number[] {\n const selection = current.state.selection\n if (selection instanceof CellSelection)\n return selection.$anchorCell.pos === selection.$headCell.pos\n ? []\n : [selection.$anchorCell.pos, selection.$headCell.pos]\n if (!inMergedCell(current.state)) return []\n const $head = selection.$head\n for (let depth = $head.depth; depth > 0; depth--) {\n const role = $head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') return [$head.before(depth)]\n }\n return []\n}\n\nlet frame = 0\nlet lastTarget: EventTarget | null = null\n\nfunction schedule() {\n if (frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (!menuOpen.value && !dragging.value) {\n const element = lastTarget instanceof Element ? lastTarget : null\n const cell = element?.closest<HTMLElement>('.dou-editor-table td, .dou-editor-table th')\n const inControls = element?.closest('.dou-editor-table-controls')\n if (cell) hovered.value = targetOf(cell)\n else if (!inControls) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n hovered.value = null\n schedule()\n}\n\nconst onScroll = () => schedule()\n\nonMounted(() => {\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n // the table frame scrolls sideways; the page scrolls too\n window.addEventListener('scroll', onScroll, true)\n window.addEventListener('resize', onScroll)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('resize', onScroll)\n if (frame) cancelAnimationFrame(frame)\n endDrag(false)\n})\n\nwatch([state, target], () => schedule())\n\n/* actions */\n\nfunction run(command: Command) {\n const current = view.value\n if (!current) return\n command(current.state, current.dispatch)\n current.focus()\n}\n\nfunction openMenu(axis: 'row' | 'column', pressed: Drag) {\n // the lines pressed on, even if the handles moved since\n const current = view.value\n if (!current) return\n current.dispatch(\n selectLines(current.state.tr, pressed.tablePos, axis, pressed.start, pressed.end),\n )\n // one menu at a time\n rowMenu.value = axis === 'row'\n columnMenu.value = axis === 'column'\n}\n\n/**\n * Whole lines are selected to show what a menu or a drag is about; after\n * it, the cursor goes into their first cell so the handles come back.\n */\nfunction collapseLines() {\n const current = view.value\n const selection = current?.state.selection\n if (!current || !(selection instanceof CellSelection)) return\n if (!selection.isRowSelection() && !selection.isColSelection()) return\n const $cell = current.state.doc.resolve(selection.$anchorCell.pos + 1)\n current.dispatch(current.state.tr.setSelection(TextSelection.near($cell)))\n}\n\nwatch(menuOpen, (open) => {\n if (open) return\n collapseLines()\n schedule()\n})\n\nconst can = (command: Command) => {\n const current = state.value\n return !!current && command(current)\n}\n\nconst tableNode = computed(() => {\n const at = target.value\n return at ? (state.value?.doc.nodeAt(at.pos) ?? null) : null\n})\n\nconst columnAlign = computed<TableAlign>(() => {\n const node = tableNode.value\n const at = target.value\n if (!node || !at) return 'left'\n return (fitColumns(node.attrs.columns, TableMap.get(node).width)[at.rect.left]?.align ??\n 'left') as TableAlign\n})\n\nconst aligns: { value: TableAlign; icon: unknown; label: () => string }[] = [\n { value: 'left', icon: TextAlignLeftIcon, label: () => messages.value.table.alignLeft },\n { value: 'center', icon: TextAlignCenterIcon, label: () => messages.value.table.alignCenter },\n { value: 'right', icon: TextAlignRightIcon, label: () => messages.value.table.alignRight },\n]\n\n/** The + bars: a column at the right end, a row at the bottom. */\nfunction addAtEnd(axis: 'row' | 'column') {\n const current = view.value\n const at = target.value\n if (!current || !at) return\n const table = current.state.doc.nodeAt(at.pos)!\n const map = TableMap.get(table)\n const rect = {\n left: 0,\n top: 0,\n right: map.width,\n bottom: map.height,\n map,\n table,\n tableStart: at.pos + 1,\n }\n let tr = current.state.tr\n if (axis === 'row') tr = addRow(tr, rect, map.height)\n else {\n const columns = fitColumns(table.attrs.columns, map.width)\n columns.push({ id: createId() })\n tr = addColumn(tr, rect, map.width).setNodeAttribute(at.pos, 'columns', columns)\n }\n current.dispatch(tr)\n}\n\n/* dragging rows and columns by their handle */\n\ninterface Drag {\n axis: 'row' | 'column'\n tablePos: number\n /** The lines that move: the target's, with any merged cells they belong to. */\n start: number\n end: number\n x: number\n y: number\n /** Where they go: the line they go before, or `null` for where they are. */\n to: number | null\n}\n\nlet drag: Drag | null = null\nconst dragging = shallowRef(false)\nconst drop = shallowRef<{ axis: 'row' | 'column'; at: number } | null>(null)\n/** A copy of the dragged lines that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction onHandleDown(axis: 'row' | 'column', event: PointerEvent) {\n const current = view.value\n const at = target.value\n if (event.button !== 0 || !current || !at || !current.editable) return\n const map = TableMap.get(current.state.doc.nodeAt(at.pos)!)\n const [from, to] = axis === 'row' ? [at.rect.top, at.rect.bottom] : [at.rect.left, at.rect.right]\n const lines = band(map, axis, from, to)\n drag = { axis, tablePos: at.pos, ...lines, x: event.clientX, y: event.clientY, to: null }\n window.addEventListener('pointermove', onDragMove)\n window.addEventListener('pointerup', onDragUp)\n window.addEventListener('pointercancel', onDragCancel)\n}\n\n/** Each boundary a run can go to, and where it is (relative to the editor). */\nfunction cutPlaces(moving: Drag): { cut: number; at: number }[] {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return []\n const box = host.getBoundingClientRect()\n const tableBox = element.getBoundingClientRect()\n const map = TableMap.get(table)\n const places: { cut: number; at: number }[] = []\n if (moving.axis === 'row') {\n const tops: number[] = []\n table.forEach((_row, offset) => {\n const row = current.nodeDOM(moving.tablePos + 1 + offset) as HTMLElement | null\n tops.push((row?.getBoundingClientRect().top ?? tableBox.top) - box.top)\n })\n for (const cut of boundaries(map, 'row'))\n places.push({ cut, at: cut < map.height ? tops[cut]! : tableBox.bottom - box.top })\n return places\n }\n for (const cut of boundaries(map, 'column')) {\n if (cut === map.width) {\n places.push({ cut, at: tableBox.right - box.left })\n continue\n }\n // no merged cell crosses a boundary, so the first row has a cell starting there\n let row = 0\n while (row < map.height && map.findCell(map.map[row * map.width + cut]!).left !== cut) row++\n const cell = cellElement(moving.tablePos, row, cut)\n if (cell) places.push({ cut, at: cell.getBoundingClientRect().left - box.left })\n }\n return places\n}\n\nfunction showGhost(moving: Drag) {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return\n const map = TableMap.get(table)\n const copy = document.createElement('table')\n copy.className = 'dou-editor-table'\n const body = document.createElement('tbody')\n copy.append(body)\n let width = 0\n const [rows, cols] =\n moving.axis === 'row'\n ? [\n [moving.start, moving.end],\n [0, map.width],\n ]\n : [\n [0, map.height],\n [moving.start, moving.end],\n ]\n for (let row = rows[0]!; row < rows[1]!; row++) {\n const line = document.createElement('tr')\n let lineWidth = 0\n for (let col = cols[0]!; col < cols[1]!; col++) {\n const rect = map.findCell(map.map[row * map.width + col]!)\n if (rect.top !== row || rect.left !== col) continue\n const cell = cellElement(moving.tablePos, row, col)\n if (!cell) continue\n const clone = cell.cloneNode(true) as HTMLElement\n clone.classList.remove('selectedCell')\n clone.style.width = `${cell.getBoundingClientRect().width}px`\n lineWidth += cell.getBoundingClientRect().width\n line.append(clone)\n }\n width = Math.max(width, lineWidth)\n body.append(line)\n }\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost dou-editor-table__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n ghost.style.width = `${Math.min(width, 360) + 2}px`\n ghost.append(copy)\n host.append(ghost)\n}\n\nfunction onDragMove(event: PointerEvent) {\n const moving = drag\n if (!moving) return\n if (!dragging.value) {\n if (Math.hypot(event.clientX - moving.x, event.clientY - moving.y) < 4) return\n dragging.value = true\n columnMenu.value = false\n rowMenu.value = false\n const current = view.value\n if (current)\n current.dispatch(\n selectLines(current.state.tr, moving.tablePos, moving.axis, moving.start, moving.end),\n )\n showGhost(moving)\n }\n if (ghost) ghost.style.transform = `translate(${event.clientX + 12}px, ${event.clientY + 12}px)`\n const host = root.value\n if (!host) return\n const box = host.getBoundingClientRect()\n const pointer = moving.axis === 'row' ? event.clientY - box.top : event.clientX - box.left\n let best: { cut: number; at: number } | null = null\n for (const place of cutPlaces(moving))\n if (!best || Math.abs(place.at - pointer) < Math.abs(best.at - pointer)) best = place\n // a boundary of the run itself leaves it where it is\n if (!best || (best.cut >= moving.start && best.cut <= moving.end)) {\n moving.to = null\n drop.value = null\n return\n }\n moving.to = best.cut\n drop.value = { axis: moving.axis, at: best.at }\n}\n\nfunction onDragUp() {\n endDrag(true)\n}\n\nfunction onDragCancel() {\n endDrag(false)\n}\n\nfunction endDrag(apply: boolean) {\n window.removeEventListener('pointermove', onDragMove)\n window.removeEventListener('pointerup', onDragUp)\n window.removeEventListener('pointercancel', onDragCancel)\n const moving = drag\n drag = null\n ghost?.remove()\n ghost = null\n drop.value = null\n if (!dragging.value) {\n // a press without a drag opens the menu; on release rather than on\n // click, as the press may close another menu and move the handles\n if (apply && moving) openMenu(moving.axis, moving)\n return\n }\n dragging.value = false\n if (apply && moving?.to !== null && moving)\n run(moveLinesTo(moving.tablePos, moving.axis, moving.start, moving.end, moving.to))\n collapseLines()\n schedule()\n}\n\nconst hasCellSelection = computed(() => {\n const selection = state.value?.selection\n return selection instanceof CellSelection && selection.$anchorCell.pos !== selection.$headCell.pos\n})\n\nconst visible = computed(() => !!layout.value && !!target.value)\n</script>\n\n<template>\n <div v-if=\"visible && layout\" class=\"dou-editor-table-controls\" @mousedown.prevent>\n <!-- column handle, above the column -->\n <DouDropdown\n v-model:open=\"columnMenu\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-column\"\n :class=\"{ 'is-active': columnMenu }\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(Math.max(layout.column.left + layout.column.width / 2, layout.frame.left + 12), layout.frame.right - 12)}px`,\n }\"\n :aria-label=\"messages.table.column\"\n :title=\"messages.table.column\"\n @pointerdown=\"onHandleDown('column', $event)\"\n >\n <GripHorizontalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertColumn('before'))\">\n <template #prefix><ArrowLeftToLineIcon /></template>\n {{ messages.table.insertLeft }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertColumn('after'))\">\n <template #prefix><ArrowRightToLineIcon /></template>\n {{ messages.table.insertRight }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('column', -1))\"\n @click=\"run(moveLines('column', -1))\"\n >\n <template #prefix><ArrowLeftIcon /></template>\n {{ messages.table.moveLeft }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!can(moveLines('column', 1))\"\n @click=\"run(moveLines('column', 1))\"\n >\n <template #prefix><ArrowRightIcon /></template>\n {{ messages.table.moveRight }}\n </DouDropdownItem>\n <DouDropdownSub divided :title=\"aligns.find((item) => item.value === columnAlign)!.label()\">\n <template #prefix>\n <component :is=\"aligns.find((item) => item.value === columnAlign)!.icon\" />\n </template>\n <DouDropdownItem\n v-for=\"item in aligns\"\n :key=\"item.value\"\n @click=\"run(alignColumns(item.value))\"\n >\n <template #prefix><component :is=\"item.icon\" /></template>\n {{ item.label() }}\n <template v-if=\"item.value === columnAlign\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </DouDropdownSub>\n <DouDropdownItem v-if=\"target?.rect.left === 0\" @click=\"run(toggleHeader('headerColumn'))\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.table.headerColumn }}\n <template v-if=\"tableNode?.attrs.headerColumn\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteColumns)\" @click=\"run(deleteColumns)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteColumn }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- row handle, left of the row -->\n <DouDropdown\n v-model:open=\"rowMenu\"\n trigger=\"manual\"\n placement=\"right-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-row\"\n :class=\"{ 'is-active': rowMenu }\"\n :style=\"{\n top: `${layout.row.top + layout.row.height / 2}px`,\n left: `${layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.row\"\n :title=\"messages.table.row\"\n @pointerdown=\"onHandleDown('row', $event)\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertRow('before'))\">\n <template #prefix><ArrowUpToLineIcon /></template>\n {{ messages.table.insertAbove }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertRow('after'))\">\n <template #prefix><ArrowDownFromLineIcon /></template>\n {{ messages.table.insertBelow }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('row', -1))\"\n @click=\"run(moveLines('row', -1))\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.table.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem :disabled=\"!can(moveLines('row', 1))\" @click=\"run(moveLines('row', 1))\">\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.table.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n v-if=\"target?.rect.top === 0\"\n divided\n @click=\"run(toggleHeader('headerRow'))\"\n >\n <template #prefix><LayoutRowsIcon /></template>\n {{ messages.table.headerRow }}\n <template v-if=\"tableNode?.attrs.headerRow\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteRows)\" @click=\"run(deleteRows)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteRow }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- + bars -->\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-column\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(layout.table.left + layout.table.width, layout.frame.right)}px`,\n height: `${layout.table.height}px`,\n }\"\n :aria-label=\"messages.table.addColumn\"\n :title=\"messages.table.addColumn\"\n @click=\"addAtEnd('column')\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-row\"\n :style=\"{\n top: `${layout.table.top + layout.table.height}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.addRow\"\n :title=\"messages.table.addRow\"\n @click=\"addAtEnd('row')\"\n >\n <PlusIcon />\n </button>\n\n <!-- where dragged lines go -->\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :class=\"{ 'is-vertical': drop.axis === 'column' }\"\n :style=\"\n drop.axis === 'row'\n ? {\n top: `${drop.at}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\n : {\n top: `${layout.table.top}px`,\n left: `${drop.at}px`,\n height: `${layout.table.height}px`,\n }\n \"\n />\n\n <!-- cells: merge, unmerge, clear -->\n <div\n v-if=\"barShown && layout.bar && !dragging\"\n class=\"dou-editor-table__cells\"\n :class=\"{ 'is-below': layout.bar.below }\"\n :style=\"{ top: `${layout.bar.top}px`, left: `${layout.bar.left}px` }\"\n >\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :disabled=\"!can(mergeCells)\"\n @click=\"run(mergeCells)\"\n >\n <MergeIcon />{{ messages.table.merge }}\n </button>\n <button\n v-if=\"can(splitMergedCell)\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n @click=\"run(splitMergedCell)\"\n >\n <SplitIcon />{{ messages.table.split }}\n </button>\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :aria-label=\"messages.table.clear\"\n :title=\"messages.table.clear\"\n @click=\"run(clearCells)\"\n >\n <EraserIcon />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAmDA,MAAM,EAAE,MAAM,OAAO,MAAM,aAAa,UAAU;;EAUlD,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,aAAa,WAAW,KAAK;EACnC,MAAM,UAAU,WAAW,KAAK;EAChC,MAAM,WAAW,eAAe,WAAW,SAAS,QAAQ,KAAK;EACjE,cAAc,gBAAgB;GAC5B,WAAW,QAAQ;GACnB,QAAQ,QAAQ;EAClB,CAAC;EACD,MAAM,WAAW,eAAe,CAAC,CAAC,OAAO,OAAO,OAAO,CAAC,SAAS,SAAS,CAAC,SAAS,KAAK;EAEzF,MAAM,gBAAgB,eAAe,SAAS,SAAS,iBAAiB,KAAK;EAE7E,SAAS,SAAS,MAAkC;GAClD,MAAM,UAAU,KAAK;GACrB,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,SAAS,IAAI,GAAG,OAAO;GACpD,MAAM,OAAO,QAAQ,MAAM,IAAI,QAAQ,QAAQ,SAAS,MAAM,CAAC,CAAC;GAChE,MAAM,QAAQ,QAAQ,IAAI;GAC1B,IAAI,CAAC,OAAO,OAAO;GAEnB,KAAK,IAAI,QAAQ,KAAK,OAAO,QAAQ,GAAG,SAAS;IAC/C,MAAM,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK;IACxC,IAAI,SAAS,UAAU,SAAS,eAAe;KAC7C,MAAM,UAAU,KAAK,OAAO,KAAK,IAAI,MAAM,MAAM;KACjD,OAAO;MAAE,KAAK,MAAM;MAAK,MAAM,MAAM,IAAI,SAAS,OAAO;KAAE;IAC7D;GACF;GACA,OAAO;EACT;;EAGA,MAAM,WAAW,eAA8B;GAC7C,MAAM,UAAU,MAAM;GACtB,IAAI,CAAC,SAAS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YG,MAAA,QAAA,CAAQ,CAAC,MAAM;MAC3B,OAAOA,MAAA,QAAA,CAAQ,CAAC,MAAM;MACtB,SAAK,OAAA,QAAA,OAAA,OAAA,WAAE,IAAIA,MAAA,UAAA,CAAU;K,IAEtBD,YAAcC,MAAA,UAAA,CAAA,C"}
1
+ {"version":3,"file":"table-controls.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_withModifiers","_createVNode","_unref","_withCtx","_createTextVNode","_toDisplayString","_createBlock","_resolveDynamicComponent","_Fragment","_renderList","_createSlots","_createCommentVNode","_withDirectives","_createElementVNode","_normalizeClass","_normalizeStyle","_vShow"],"sources":["../../../src/extensions/table/table-controls.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownFromLineIcon,\n ArrowDownIcon,\n ArrowLeftIcon,\n ArrowLeftToLineIcon,\n ArrowRightIcon,\n ArrowRightToLineIcon,\n ArrowUpIcon,\n ArrowUpToLineIcon,\n CheckIcon,\n EraserIcon,\n GripHorizontalIcon,\n GripVerticalIcon,\n LayoutColumnsIcon,\n LayoutRowsIcon,\n MergeIcon,\n PlusIcon,\n SplitIcon,\n TextAlignCenterIcon,\n TextAlignLeftIcon,\n TextAlignRightIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection, type Command } from 'prosemirror-state'\nimport { CellSelection, TableMap, addColumn, addRow, type Rect } from 'prosemirror-tables'\nimport { computed, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { createId } from '../../core/model'\nimport { useMenuEscape } from '../../components/menu-escape'\nimport { useEditor } from '../../editor'\nimport {\n alignColumns,\n band,\n boundaries,\n clearCells,\n deleteColumns,\n deleteRows,\n inMergedCell,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n selectLines,\n splitMergedCell,\n tableAt,\n toggleHeader,\n} from './commands'\nimport { fitColumns, type TableAlign } from './schema'\n\nconst { view, state, root, messages } = useEditor()\n\n/** The table and the cell the controls are about: the hovered one, or the selection's. */\ninterface Target {\n /** Position right before the table node. */\n pos: number\n /** The cell's place in the grid. */\n rect: Rect\n}\n\nconst hovered = shallowRef<Target | null>(null)\nconst columnMenu = shallowRef(false)\nconst rowMenu = shallowRef(false)\nconst menuOpen = computed(() => columnMenu.value || rowMenu.value)\nuseMenuEscape(menuOpen, () => {\n columnMenu.value = false\n rowMenu.value = false\n})\nconst barShown = computed(() => !!layout.value?.bar && !menuOpen.value && !dragging.value)\n// the toolbar over selected cells stands in for the handles; a merged cell's goes below it\nconst handlesHidden = computed(() => barShown.value && hasCellSelection.value)\n\nfunction targetOf(cell: HTMLElement): Target | null {\n const current = view.value\n if (!current || !current.dom.contains(cell)) return null\n const $pos = current.state.doc.resolve(current.posAtDOM(cell, 0))\n const found = tableAt($pos)\n if (!found) return null\n // the cell node starts right before its content\n for (let depth = $pos.depth; depth > 0; depth--) {\n const role = $pos.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') {\n const cellPos = $pos.before(depth) - found.pos - 1\n return { pos: found.pos, rect: found.map.findCell(cellPos) }\n }\n }\n return null\n}\n\n/** The selection's cell when the pointer is elsewhere. */\nconst selected = computed<Target | null>(() => {\n const current = state.value\n if (!current) return null\n const selection = current.selection\n const $cell = selection instanceof CellSelection ? selection.$headCell : null\n const found = tableAt(selection.$head)\n if (!found) return null\n const start = found.pos + 1\n if ($cell) return { pos: found.pos, rect: found.map.findCell($cell.pos - start) }\n for (let depth = selection.$head.depth; depth > 0; depth--) {\n const role = selection.$head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell')\n return { pos: found.pos, rect: found.map.findCell(selection.$head.before(depth) - start) }\n }\n return null\n})\n\nconst target = computed(() => hovered.value ?? selected.value)\n\n/* where things go */\n\ninterface Layout {\n /** The table, relative to the editor. */\n table: { top: number; left: number; width: number; height: number }\n /** The visible part of the table, when it scrolls sideways. */\n frame: { left: number; right: number }\n column: { left: number; width: number }\n row: { top: number; height: number }\n /**\n * Where the cell toolbar goes (its centre): above selected cells, or below\n * the merged cell with the cursor.\n */\n bar: { top: number; left: number; below: boolean } | null\n}\n\nconst layout = shallowRef<Layout | null>(null)\n\nfunction cellElement(tablePos: number, row: number, col: number): HTMLElement | null {\n const current = view.value\n const table = current?.state.doc.nodeAt(tablePos)\n if (!current || !table) return null\n const map = TableMap.get(table)\n if (row >= map.height || col >= map.width) return null\n const pos = tablePos + 1 + map.map[row * map.width + col]!\n return current.nodeDOM(pos) as HTMLElement | null\n}\n\nfunction measure() {\n const current = view.value\n const host = root.value\n const at = target.value\n if (!current || !host || !at) return (layout.value = null)\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const tableElement = frameElement?.querySelector('table')\n if (!tableNode || !frameElement || !tableElement) return (layout.value = null)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = frameElement.getBoundingClientRect()\n const first = cellElement(at.pos, at.rect.top, at.rect.left)?.getBoundingClientRect()\n if (!first) return (layout.value = null)\n let bar: Layout['bar'] = null\n const boxes = barCells(current).map((pos) =>\n (current.nodeDOM(pos) as HTMLElement).getBoundingClientRect(),\n )\n if (boxes.length) {\n const left = Math.max(Math.min(...boxes.map((item) => item.left)), frameBox.left)\n const right = Math.min(Math.max(...boxes.map((item) => item.right)), frameBox.right)\n const below = !(current.state.selection instanceof CellSelection)\n bar = {\n top: below\n ? Math.max(...boxes.map((item) => item.bottom)) - box.top\n : Math.min(...boxes.map((item) => item.top)) - box.top,\n left: (left + right) / 2 - box.left,\n below,\n }\n }\n layout.value = {\n table: {\n top: tableBox.top - box.top,\n left: tableBox.left - box.left,\n width: tableBox.width,\n height: tableBox.height,\n },\n // a top-level table's frame reaches into the margins, the table starting\n // after its padding: what shows of it starts at whichever is further in\n frame: {\n left: Math.max(frameBox.left, tableBox.left) - box.left,\n right: frameBox.right - box.left,\n },\n column: { left: first.left - box.left, width: first.width },\n row: { top: first.top - box.top, height: first.height },\n bar,\n }\n}\n\n/** The cells the toolbar is about: a cell selection's corners, or the merged cell with the cursor. */\nfunction barCells(current: NonNullable<typeof view.value>): number[] {\n const selection = current.state.selection\n if (selection instanceof CellSelection)\n return selection.$anchorCell.pos === selection.$headCell.pos\n ? []\n : [selection.$anchorCell.pos, selection.$headCell.pos]\n if (!inMergedCell(current.state)) return []\n const $head = selection.$head\n for (let depth = $head.depth; depth > 0; depth--) {\n const role = $head.node(depth).type.spec.tableRole\n if (role === 'cell' || role === 'header_cell') return [$head.before(depth)]\n }\n return []\n}\n\nlet frame = 0\nlet lastTarget: EventTarget | null = null\n\nfunction schedule() {\n if (frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (!menuOpen.value && !dragging.value) {\n const element = lastTarget instanceof Element ? lastTarget : null\n const cell = element?.closest<HTMLElement>('.dou-editor-table td, .dou-editor-table th')\n const inControls = element?.closest('.dou-editor-table-controls')\n if (cell) hovered.value = targetOf(cell)\n else if (!inControls) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n hovered.value = null\n schedule()\n}\n\nconst onScroll = () => schedule()\n\nonMounted(() => {\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n // the table frame scrolls sideways; the page scrolls too\n window.addEventListener('scroll', onScroll, true)\n window.addEventListener('resize', onScroll)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n window.removeEventListener('scroll', onScroll, true)\n window.removeEventListener('resize', onScroll)\n if (frame) cancelAnimationFrame(frame)\n endDrag(false)\n})\n\nwatch([state, target], () => schedule())\n\n/* actions */\n\nfunction run(command: Command) {\n const current = view.value\n if (!current) return\n command(current.state, current.dispatch)\n current.focus()\n}\n\nfunction openMenu(axis: 'row' | 'column', pressed: Drag) {\n // the lines pressed on, even if the handles moved since\n const current = view.value\n if (!current) return\n current.dispatch(\n selectLines(current.state.tr, pressed.tablePos, axis, pressed.start, pressed.end),\n )\n // one menu at a time\n rowMenu.value = axis === 'row'\n columnMenu.value = axis === 'column'\n}\n\n/**\n * Whole lines are selected to show what a menu or a drag is about; after\n * it, the cursor goes into their first cell so the handles come back.\n */\nfunction collapseLines() {\n const current = view.value\n const selection = current?.state.selection\n if (!current || !(selection instanceof CellSelection)) return\n if (!selection.isRowSelection() && !selection.isColSelection()) return\n const $cell = current.state.doc.resolve(selection.$anchorCell.pos + 1)\n current.dispatch(current.state.tr.setSelection(TextSelection.near($cell)))\n}\n\nwatch(menuOpen, (open) => {\n if (open) return\n collapseLines()\n schedule()\n})\n\nconst can = (command: Command) => {\n const current = state.value\n return !!current && command(current)\n}\n\nconst tableNode = computed(() => {\n const at = target.value\n return at ? (state.value?.doc.nodeAt(at.pos) ?? null) : null\n})\n\nconst columnAlign = computed<TableAlign>(() => {\n const node = tableNode.value\n const at = target.value\n if (!node || !at) return 'left'\n return (fitColumns(node.attrs.columns, TableMap.get(node).width)[at.rect.left]?.align ??\n 'left') as TableAlign\n})\n\nconst aligns: { value: TableAlign; icon: unknown; label: () => string }[] = [\n { value: 'left', icon: TextAlignLeftIcon, label: () => messages.value.table.alignLeft },\n { value: 'center', icon: TextAlignCenterIcon, label: () => messages.value.table.alignCenter },\n { value: 'right', icon: TextAlignRightIcon, label: () => messages.value.table.alignRight },\n]\n\n/** The + bars: a column at the right end, a row at the bottom. */\nfunction addAtEnd(axis: 'row' | 'column') {\n const current = view.value\n const at = target.value\n if (!current || !at) return\n const table = current.state.doc.nodeAt(at.pos)!\n const map = TableMap.get(table)\n const rect = {\n left: 0,\n top: 0,\n right: map.width,\n bottom: map.height,\n map,\n table,\n tableStart: at.pos + 1,\n }\n let tr = current.state.tr\n if (axis === 'row') tr = addRow(tr, rect, map.height)\n else {\n const columns = fitColumns(table.attrs.columns, map.width)\n columns.push({ id: createId() })\n tr = addColumn(tr, rect, map.width).setNodeAttribute(at.pos, 'columns', columns)\n }\n current.dispatch(tr)\n}\n\n/* dragging rows and columns by their handle */\n\ninterface Drag {\n axis: 'row' | 'column'\n tablePos: number\n /** The lines that move: the target's, with any merged cells they belong to. */\n start: number\n end: number\n x: number\n y: number\n /** Where they go: the line they go before, or `null` for where they are. */\n to: number | null\n}\n\nlet drag: Drag | null = null\nconst dragging = shallowRef(false)\nconst drop = shallowRef<{ axis: 'row' | 'column'; at: number } | null>(null)\n/** A copy of the dragged lines that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction onHandleDown(axis: 'row' | 'column', event: PointerEvent) {\n const current = view.value\n const at = target.value\n if (event.button !== 0 || !current || !at || !current.editable) return\n const map = TableMap.get(current.state.doc.nodeAt(at.pos)!)\n const [from, to] = axis === 'row' ? [at.rect.top, at.rect.bottom] : [at.rect.left, at.rect.right]\n const lines = band(map, axis, from, to)\n drag = { axis, tablePos: at.pos, ...lines, x: event.clientX, y: event.clientY, to: null }\n window.addEventListener('pointermove', onDragMove)\n window.addEventListener('pointerup', onDragUp)\n window.addEventListener('pointercancel', onDragCancel)\n}\n\n/** Each boundary a run can go to, and where it is (relative to the editor). */\nfunction cutPlaces(moving: Drag): { cut: number; at: number }[] {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return []\n const box = host.getBoundingClientRect()\n const tableBox = element.getBoundingClientRect()\n const map = TableMap.get(table)\n const places: { cut: number; at: number }[] = []\n if (moving.axis === 'row') {\n const tops: number[] = []\n table.forEach((_row, offset) => {\n const row = current.nodeDOM(moving.tablePos + 1 + offset) as HTMLElement | null\n tops.push((row?.getBoundingClientRect().top ?? tableBox.top) - box.top)\n })\n for (const cut of boundaries(map, 'row'))\n places.push({ cut, at: cut < map.height ? tops[cut]! : tableBox.bottom - box.top })\n return places\n }\n for (const cut of boundaries(map, 'column')) {\n if (cut === map.width) {\n places.push({ cut, at: tableBox.right - box.left })\n continue\n }\n // no merged cell crosses a boundary, so the first row has a cell starting there\n let row = 0\n while (row < map.height && map.findCell(map.map[row * map.width + cut]!).left !== cut) row++\n const cell = cellElement(moving.tablePos, row, cut)\n if (cell) places.push({ cut, at: cell.getBoundingClientRect().left - box.left })\n }\n return places\n}\n\nfunction showGhost(moving: Drag) {\n const current = view.value\n const host = root.value\n const table = current?.state.doc.nodeAt(moving.tablePos)\n const element = (current?.nodeDOM(moving.tablePos) as HTMLElement | null)?.querySelector('table')\n if (!current || !host || !table || !element) return\n const map = TableMap.get(table)\n const copy = document.createElement('table')\n copy.className = 'dou-editor-table'\n const body = document.createElement('tbody')\n copy.append(body)\n let width = 0\n const [rows, cols] =\n moving.axis === 'row'\n ? [\n [moving.start, moving.end],\n [0, map.width],\n ]\n : [\n [0, map.height],\n [moving.start, moving.end],\n ]\n for (let row = rows[0]!; row < rows[1]!; row++) {\n const line = document.createElement('tr')\n let lineWidth = 0\n for (let col = cols[0]!; col < cols[1]!; col++) {\n const rect = map.findCell(map.map[row * map.width + col]!)\n if (rect.top !== row || rect.left !== col) continue\n const cell = cellElement(moving.tablePos, row, col)\n if (!cell) continue\n const clone = cell.cloneNode(true) as HTMLElement\n clone.classList.remove('selectedCell')\n clone.style.width = `${cell.getBoundingClientRect().width}px`\n lineWidth += cell.getBoundingClientRect().width\n line.append(clone)\n }\n width = Math.max(width, lineWidth)\n body.append(line)\n }\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost dou-editor-table__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n ghost.style.width = `${Math.min(width, 360) + 2}px`\n ghost.append(copy)\n host.append(ghost)\n}\n\nfunction onDragMove(event: PointerEvent) {\n const moving = drag\n if (!moving) return\n if (!dragging.value) {\n if (Math.hypot(event.clientX - moving.x, event.clientY - moving.y) < 4) return\n dragging.value = true\n columnMenu.value = false\n rowMenu.value = false\n const current = view.value\n if (current)\n current.dispatch(\n selectLines(current.state.tr, moving.tablePos, moving.axis, moving.start, moving.end),\n )\n showGhost(moving)\n }\n if (ghost) ghost.style.transform = `translate(${event.clientX + 12}px, ${event.clientY + 12}px)`\n const host = root.value\n if (!host) return\n const box = host.getBoundingClientRect()\n const pointer = moving.axis === 'row' ? event.clientY - box.top : event.clientX - box.left\n let best: { cut: number; at: number } | null = null\n for (const place of cutPlaces(moving))\n if (!best || Math.abs(place.at - pointer) < Math.abs(best.at - pointer)) best = place\n // a boundary of the run itself leaves it where it is\n if (!best || (best.cut >= moving.start && best.cut <= moving.end)) {\n moving.to = null\n drop.value = null\n return\n }\n moving.to = best.cut\n drop.value = { axis: moving.axis, at: best.at }\n}\n\nfunction onDragUp() {\n endDrag(true)\n}\n\nfunction onDragCancel() {\n endDrag(false)\n}\n\nfunction endDrag(apply: boolean) {\n window.removeEventListener('pointermove', onDragMove)\n window.removeEventListener('pointerup', onDragUp)\n window.removeEventListener('pointercancel', onDragCancel)\n const moving = drag\n drag = null\n ghost?.remove()\n ghost = null\n drop.value = null\n if (!dragging.value) {\n // a press without a drag opens the menu; on release rather than on\n // click, as the press may close another menu and move the handles\n if (apply && moving) openMenu(moving.axis, moving)\n return\n }\n dragging.value = false\n if (apply && moving?.to !== null && moving)\n run(moveLinesTo(moving.tablePos, moving.axis, moving.start, moving.end, moving.to))\n collapseLines()\n schedule()\n}\n\nconst hasCellSelection = computed(() => {\n const selection = state.value?.selection\n return selection instanceof CellSelection && selection.$anchorCell.pos !== selection.$headCell.pos\n})\n\nconst visible = computed(() => !!layout.value && !!target.value)\n</script>\n\n<template>\n <div v-if=\"visible && layout\" class=\"dou-editor-table-controls\" @mousedown.prevent>\n <!-- column handle, above the column -->\n <DouDropdown\n v-model:open=\"columnMenu\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-column\"\n :class=\"{ 'is-active': columnMenu }\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(Math.max(layout.column.left + layout.column.width / 2, layout.frame.left + 12), layout.frame.right - 12)}px`,\n }\"\n :aria-label=\"messages.table.column\"\n :title=\"messages.table.column\"\n @pointerdown=\"onHandleDown('column', $event)\"\n >\n <GripHorizontalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertColumn('before'))\">\n <template #prefix><ArrowLeftToLineIcon /></template>\n {{ messages.table.insertLeft }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertColumn('after'))\">\n <template #prefix><ArrowRightToLineIcon /></template>\n {{ messages.table.insertRight }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('column', -1))\"\n @click=\"run(moveLines('column', -1))\"\n >\n <template #prefix><ArrowLeftIcon /></template>\n {{ messages.table.moveLeft }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!can(moveLines('column', 1))\"\n @click=\"run(moveLines('column', 1))\"\n >\n <template #prefix><ArrowRightIcon /></template>\n {{ messages.table.moveRight }}\n </DouDropdownItem>\n <DouDropdownSub divided :title=\"aligns.find((item) => item.value === columnAlign)!.label()\">\n <template #prefix>\n <component :is=\"aligns.find((item) => item.value === columnAlign)!.icon\" />\n </template>\n <DouDropdownItem\n v-for=\"item in aligns\"\n :key=\"item.value\"\n @click=\"run(alignColumns(item.value))\"\n >\n <template #prefix><component :is=\"item.icon\" /></template>\n {{ item.label() }}\n <template v-if=\"item.value === columnAlign\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </DouDropdownSub>\n <DouDropdownItem v-if=\"target?.rect.left === 0\" @click=\"run(toggleHeader('headerColumn'))\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.table.headerColumn }}\n <template v-if=\"tableNode?.attrs.headerColumn\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteColumns)\" @click=\"run(deleteColumns)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteColumn }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- row handle, left of the row -->\n <DouDropdown\n v-model:open=\"rowMenu\"\n trigger=\"manual\"\n placement=\"right-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n v-show=\"!handlesHidden\"\n class=\"dou-editor-table__handle is-row\"\n :class=\"{ 'is-active': rowMenu }\"\n :style=\"{\n top: `${layout.row.top + layout.row.height / 2}px`,\n left: `${layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.row\"\n :title=\"messages.table.row\"\n @pointerdown=\"onHandleDown('row', $event)\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownItem @click=\"run(insertRow('before'))\">\n <template #prefix><ArrowUpToLineIcon /></template>\n {{ messages.table.insertAbove }}\n </DouDropdownItem>\n <DouDropdownItem @click=\"run(insertRow('after'))\">\n <template #prefix><ArrowDownFromLineIcon /></template>\n {{ messages.table.insertBelow }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n :disabled=\"!can(moveLines('row', -1))\"\n @click=\"run(moveLines('row', -1))\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.table.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem :disabled=\"!can(moveLines('row', 1))\" @click=\"run(moveLines('row', 1))\">\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.table.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n v-if=\"target?.rect.top === 0\"\n divided\n @click=\"run(toggleHeader('headerRow'))\"\n >\n <template #prefix><LayoutRowsIcon /></template>\n {{ messages.table.headerRow }}\n <template v-if=\"tableNode?.attrs.headerRow\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n <DouDropdownItem divided @click=\"run(clearCells)\">\n <template #prefix><EraserIcon /></template>\n {{ messages.table.clear }}\n </DouDropdownItem>\n <DouDropdownItem tone=\"danger\" :disabled=\"!can(deleteRows)\" @click=\"run(deleteRows)\">\n <template #prefix><TrashIcon /></template>\n {{ messages.table.deleteRow }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n\n <!-- + bars -->\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-column\"\n :style=\"{\n top: `${layout.table.top}px`,\n left: `${Math.min(layout.table.left + layout.table.width, layout.frame.right)}px`,\n height: `${layout.table.height}px`,\n }\"\n :aria-label=\"messages.table.addColumn\"\n :title=\"messages.table.addColumn\"\n @click=\"addAtEnd('column')\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__add is-row\"\n :style=\"{\n top: `${layout.table.top + layout.table.height}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\"\n :aria-label=\"messages.table.addRow\"\n :title=\"messages.table.addRow\"\n @click=\"addAtEnd('row')\"\n >\n <PlusIcon />\n </button>\n\n <!-- where dragged lines go -->\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :class=\"{ 'is-vertical': drop.axis === 'column' }\"\n :style=\"\n drop.axis === 'row'\n ? {\n top: `${drop.at}px`,\n left: `${layout.frame.left}px`,\n width: `${Math.min(layout.table.left + layout.table.width, layout.frame.right) - layout.frame.left}px`,\n }\n : {\n top: `${layout.table.top}px`,\n left: `${drop.at}px`,\n height: `${layout.table.height}px`,\n }\n \"\n />\n\n <!-- cells: merge, unmerge, clear -->\n <div\n v-if=\"barShown && layout.bar && !dragging\"\n class=\"dou-editor-table__cells\"\n :class=\"{ 'is-below': layout.bar.below }\"\n :style=\"{ top: `${layout.bar.top}px`, left: `${layout.bar.left}px` }\"\n >\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :disabled=\"!can(mergeCells)\"\n @click=\"run(mergeCells)\"\n >\n <MergeIcon />{{ messages.table.merge }}\n </button>\n <button\n v-if=\"can(splitMergedCell)\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n @click=\"run(splitMergedCell)\"\n >\n <SplitIcon />{{ messages.table.split }}\n </button>\n <button\n v-if=\"hasCellSelection\"\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor-table__cells-button\"\n :aria-label=\"messages.table.clear\"\n :title=\"messages.table.clear\"\n @click=\"run(clearCells)\"\n >\n <EraserIcon />\n </button>\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAmDA,MAAM,EAAE,MAAM,OAAO,MAAM,aAAa,UAAU;;EAUlD,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,aAAa,WAAW,KAAK;EACnC,MAAM,UAAU,WAAW,KAAK;EAChC,MAAM,WAAW,eAAe,WAAW,SAAS,QAAQ,KAAK;EACjE,cAAc,gBAAgB;GAC5B,WAAW,QAAQ;GACnB,QAAQ,QAAQ;EAClB,CAAC;EACD,MAAM,WAAW,eAAe,CAAC,CAAC,OAAO,OAAO,OAAO,CAAC,SAAS,SAAS,CAAC,SAAS,KAAK;EAEzF,MAAM,gBAAgB,eAAe,SAAS,SAAS,iBAAiB,KAAK;EAE7E,SAAS,SAAS,MAAkC;GAClD,MAAM,UAAU,KAAK;GACrB,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,SAAS,IAAI,GAAG,OAAO;GACpD,MAAM,OAAO,QAAQ,MAAM,IAAI,QAAQ,QAAQ,SAAS,MAAM,CAAC,CAAC;GAChE,MAAM,QAAQ,QAAQ,IAAI;GAC1B,IAAI,CAAC,OAAO,OAAO;GAEnB,KAAK,IAAI,QAAQ,KAAK,OAAO,QAAQ,GAAG,SAA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A,MAAA,eAAA,CAAe,KAD3BJ,UAAA,GAAAC,mBAQS,UAAA;;MANP,MAAK;MACL,UAAS;MACT,OAAM;MACL,SAAK,OAAA,QAAA,OAAA,OAAA,WAAE,IAAIG,MAAA,eAAA,CAAe;K,IAE3BD,YAAaC,MAAA,SAAA,CAAA,GAAGE,gBAAAC,gBAAAH,MAAA,QAAA,CAAQ,CAAC,MAAM,KAAK,GAAA,CAAA,C;KAG9B,iBAAA,SADRJ,UAAA,GAAAC,mBAUS,UAAA;;MARP,MAAK;MACL,UAAS;MACT,OAAM;MACL,cAAYG,MAAA,QAAA,CAAQ,CAAC,MAAM;MAC3B,OAAOA,MAAA,QAAA,CAAQ,CAAC,MAAM;MACtB,SAAK,OAAA,QAAA,OAAA,OAAA,WAAE,IAAIA,MAAA,UAAA,CAAU;K,IAEtBD,YAAcC,MAAA,UAAA,CAAA,C"}
@@ -1,18 +1,42 @@
1
1
  import { TableView } from "prosemirror-tables";
2
2
  /**
3
3
  * A table in the editor: a scrolling frame (the block's content element)
4
- * around the table, with a `<colgroup>` that holds the column widths.
4
+ * around the table, with a `<colgroup>` that holds the column widths. When
5
+ * columns are cut off at either side of the frame, that side has a shadow:
6
+ * `is-cut-start` / `is-cut-end` on the frame.
5
7
  */
6
8
  var TableBlockView = class extends TableView {
9
+ observer = null;
10
+ onScroll = () => this.edges();
7
11
  constructor(node) {
8
12
  super(node, 96);
9
13
  this.dom.className = "dou-editor__content dou-editor__content--table";
10
14
  this.dom.dataset.contentType = "table";
11
15
  this.table.className = "dou-editor-table";
16
+ this.dom.addEventListener("scroll", this.onScroll, { passive: true });
17
+ if (typeof ResizeObserver !== "undefined") {
18
+ this.observer = new ResizeObserver(this.onScroll);
19
+ this.observer.observe(this.dom);
20
+ this.observer.observe(this.table);
21
+ }
22
+ }
23
+ /** Which sides cut columns off: the table's edges against the frame's, padding left out. */
24
+ edges() {
25
+ const frame = this.dom;
26
+ const style = getComputedStyle(frame);
27
+ const start = Number.parseFloat(style.paddingInlineStart) || 0;
28
+ const end = Number.parseFloat(style.paddingInlineEnd) || 0;
29
+ const hidden = frame.scrollWidth - frame.clientWidth;
30
+ frame.classList.toggle("is-cut-start", frame.scrollLeft > start + .5);
31
+ frame.classList.toggle("is-cut-end", frame.scrollLeft < hidden - end - .5);
12
32
  }
13
33
  ignoreMutation(record) {
14
34
  return record.type === "attributes" && record.target === this.dom ? true : super.ignoreMutation(record);
15
35
  }
36
+ destroy() {
37
+ this.dom.removeEventListener("scroll", this.onScroll);
38
+ this.observer?.disconnect();
39
+ }
16
40
  };
17
41
  export { TableBlockView };
18
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","names":[],"sources":["../../../src/extensions/table/view.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { TableView } from 'prosemirror-tables'\nimport type { NodeView, ViewMutationRecord } from 'prosemirror-view'\n\n/** The narrowest a column gets, without a width of its own and when resized. */\nexport const CELL_MIN_WIDTH = 96\n\n/**\n * A table in the editor: a scrolling frame (the block's content element)\n * around the table, with a `<colgroup>` that holds the column widths.\n */\nexport class TableBlockView extends TableView implements NodeView {\n constructor(node: PMNode) {\n super(node, CELL_MIN_WIDTH)\n this.dom.className = 'dou-editor__content dou-editor__content--table'\n this.dom.dataset.contentType = 'table'\n this.table.className = 'dou-editor-table'\n }\n\n override ignoreMutation(record: ViewMutationRecord) {\n // the frame's scroll position and classes are ours\n return record.type === 'attributes' && record.target === this.dom\n ? true\n : super.ignoreMutation(record)\n }\n}\n"],"mappings":";;;;;AAWA,IAAa,iBAAb,cAAoC,UAA8B;CAChE,YAAY,MAAc;EACxB,MAAM,MAAA,EAAoB;EAC1B,KAAK,IAAI,YAAY;EACrB,KAAK,IAAI,QAAQ,cAAc;EAC/B,KAAK,MAAM,YAAY;CACzB;CAEA,eAAwB,QAA4B;EAElD,OAAO,OAAO,SAAS,gBAAgB,OAAO,WAAW,KAAK,MAC1D,OACA,MAAM,eAAe,MAAM;CACjC;AACF"}
1
+ {"version":3,"file":"view.js","names":[],"sources":["../../../src/extensions/table/view.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { TableView } from 'prosemirror-tables'\nimport type { NodeView, ViewMutationRecord } from 'prosemirror-view'\n\n/** The narrowest a column gets, without a width of its own and when resized. */\nexport const CELL_MIN_WIDTH = 96\n\n/**\n * A table in the editor: a scrolling frame (the block's content element)\n * around the table, with a `<colgroup>` that holds the column widths. When\n * columns are cut off at either side of the frame, that side has a shadow:\n * `is-cut-start` / `is-cut-end` on the frame.\n */\nexport class TableBlockView extends TableView implements NodeView {\n private readonly observer: ResizeObserver | null = null\n private readonly onScroll = () => this.edges()\n\n constructor(node: PMNode) {\n super(node, CELL_MIN_WIDTH)\n this.dom.className = 'dou-editor__content dou-editor__content--table'\n this.dom.dataset.contentType = 'table'\n this.table.className = 'dou-editor-table'\n this.dom.addEventListener('scroll', this.onScroll, { passive: true })\n if (typeof ResizeObserver !== 'undefined') {\n // the frame's width, and the table's (columns added, removed, resized)\n this.observer = new ResizeObserver(this.onScroll)\n this.observer.observe(this.dom)\n this.observer.observe(this.table)\n }\n }\n\n /** Which sides cut columns off: the table's edges against the frame's, padding left out. */\n private edges() {\n const frame = this.dom\n const style = getComputedStyle(frame)\n const start = Number.parseFloat(style.paddingInlineStart) || 0\n const end = Number.parseFloat(style.paddingInlineEnd) || 0\n const hidden = frame.scrollWidth - frame.clientWidth\n frame.classList.toggle('is-cut-start', frame.scrollLeft > start + 0.5)\n frame.classList.toggle('is-cut-end', frame.scrollLeft < hidden - end - 0.5)\n }\n\n override ignoreMutation(record: ViewMutationRecord) {\n // the frame's scroll position and classes are ours\n return record.type === 'attributes' && record.target === this.dom\n ? true\n : super.ignoreMutation(record)\n }\n\n destroy() {\n this.dom.removeEventListener('scroll', this.onScroll)\n this.observer?.disconnect()\n }\n}\n"],"mappings":";;;;;;;AAaA,IAAa,iBAAb,cAAoC,UAA8B;CAChE,WAAmD;CACnD,iBAAkC,KAAK,MAAM;CAE7C,YAAY,MAAc;EACxB,MAAM,MAAA,EAAoB;EAC1B,KAAK,IAAI,YAAY;EACrB,KAAK,IAAI,QAAQ,cAAc;EAC/B,KAAK,MAAM,YAAY;EACvB,KAAK,IAAI,iBAAiB,UAAU,KAAK,UAAU,EAAE,SAAS,KAAK,CAAC;EACpE,IAAI,OAAO,mBAAmB,aAAa;GAEzC,KAAK,WAAW,IAAI,eAAe,KAAK,QAAQ;GAChD,KAAK,SAAS,QAAQ,KAAK,GAAG;GAC9B,KAAK,SAAS,QAAQ,KAAK,KAAK;EAClC;CACF;;CAGA,QAAgB;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,iBAAiB,KAAK;EACpC,MAAM,QAAQ,OAAO,WAAW,MAAM,kBAAkB,KAAK;EAC7D,MAAM,MAAM,OAAO,WAAW,MAAM,gBAAgB,KAAK;EACzD,MAAM,SAAS,MAAM,cAAc,MAAM;EACzC,MAAM,UAAU,OAAO,gBAAgB,MAAM,aAAa,QAAQ,EAAG;EACrE,MAAM,UAAU,OAAO,cAAc,MAAM,aAAa,SAAS,MAAM,EAAG;CAC5E;CAEA,eAAwB,QAA4B;EAElD,OAAO,OAAO,SAAS,gBAAgB,OAAO,WAAW,KAAK,MAC1D,OACA,MAAM,eAAe,MAAM;CACjC;CAEA,UAAU;EACR,KAAK,IAAI,oBAAoB,UAAU,KAAK,QAAQ;EACpD,KAAK,UAAU,WAAW;CAC5B;AACF"}
@@ -0,0 +1,6 @@
1
+ import board_block_vue_vue_type_script_setup_true_lang_default from "./board-block.vue_vue_type_script_setup_true_lang.js";
2
+ // src/flow/board-block.vue
3
+ var board_block_default = board_block_vue_vue_type_script_setup_true_lang_default;
4
+ export { board_block_default as default };
5
+
6
+ //# sourceMappingURL=board-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board-block.js","names":["_sfc_main"],"sources":["../../src/flow/board-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n defaultNode,\n defineNodeType,\n DouFlowControls,\n DouFlowEditor,\n defineFlowExtension,\n type NodeTypeSpec,\n type FlowDocument,\n type FlowExtension,\n type FlowHistoryHandler,\n type FlowNode,\n type FlowTransaction,\n} from '@dou-ui/flow'\nimport type { CommentAction, CommentThread } from 'dou-ui'\nimport { EyeIcon, PencilIcon, PlusIcon, SquareIcon } from '@dou-ui/icons'\nimport { DouButton, DouCommand, DouDialog, DouPopover, type CommandItem } from 'dou-ui'\nimport { NodeSelection } from 'prosemirror-state'\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { findBlockById } from '../core/blocks'\nimport { historyCommands } from '../core/editor'\nimport { labelOf } from '../core/extension'\nimport type { BlockProps } from '../core/model'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { useEditor } from '../editor'\nimport {\n BOARD_HEIGHT,\n BOARD_OPEN_EVENT,\n boardComments,\n boardOf,\n clampHeight,\n onlyBoardChanged,\n type BoardBlockSettings,\n} from './board'\n\n/** The board with the groups this reader folded or unfolded. */\nfunction withFolded(board: FlowDocument, folded: Map<string, boolean>): FlowDocument {\n if (!folded.size) return board\n const nodes = board.nodes.map((node) => {\n if (!folded.has(node.id)) return node\n const { collapsed: _, ...data } = node.data ?? {}\n return { ...node, data: folded.get(node.id) ? { ...data, collapsed: true } : data }\n })\n return { ...board, nodes }\n}\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n settings: BoardBlockSettings\n}>()\n\nconst { view, messages, comments } = useEditor()\nconst text = computed(() => messages.value.board)\nconst label = computed(() => labelOf(props.settings.label, messages.value))\nconst stored = computed(() => boardOf(props.block.props.board))\n/*\n * Whether a group is folded is each reader's own view, as with toggles: it\n * stays out of the document (what it holds there is kept), and is shown\n * from here.\n */\nconst folded = shallowRef(new Map<string, boolean>())\nconst board = computed(() => withFolded(stored.value, folded.value))\nconst empty = computed(() => !board.value.nodes.length)\n\n/* the fullscreen editor */\nconst open = shallowRef(false)\n/** The fullscreen editor is in place (its dialog done opening). */\nconst opened = shallowRef(false)\nwatch(open, (value) => {\n if (!value) shown.value = board.value\n})\n\n/*\n * Comment threads on the nodes and edges: the document's threads, author\n * and open thread, shown by the flow editors. The ids are kept on the nodes\n * and edges (see `boardComments`); a thread opened from outside, e.g. a\n * list of the document's comments, opens the fullscreen editor at it.\n */\nconst flowComments = computed(() =>\n props.settings.commentable && comments.enabled.value\n ? (comments.threads.value as CommentThread[])\n : undefined,\n)\nconst threadsHere = computed(\n () =>\n new Set(\n props.settings.commentable ? Object.keys(boardComments.anchors(props.block.props)) : [],\n ),\n)\nconst here = (id: string | null): id is string => !!id && threadsHere.value.has(id)\n/** The open thread, when it is on this board and the fullscreen editor shows it. */\nconst boardActive = computed(() =>\n opened.value && here(comments.active.value) ? comments.active.value : null,\n)\nwatch(\n () => comments.active.value,\n (id) => {\n if (here(id) && !open.value) openEditor()\n },\n)\n/*\n * The preview can't be pressed (it is inert and lets the pointer through to\n * the block), but its comment markers look like buttons: a click or tap on\n * one opens the board at its thread.\n */\nconst markerCursor = shallowRef(false)\nfunction markerAt(event: MouseEvent): string | null {\n if (!flowComments.value) return null\n const markers = root.value?.querySelectorAll<HTMLElement>(\n '.dou-editor-board__preview [data-thread]',\n )\n for (const marker of markers ?? []) {\n const box = marker.getBoundingClientRect()\n if (\n event.clientX >= box.left &&\n event.clientX <= box.right &&\n event.clientY >= box.top &&\n event.clientY <= box.bottom\n )\n return marker.dataset.thread ?? null\n }\n return null\n}\nfunction onPreviewClick(event: MouseEvent) {\n const id = markerAt(event)\n if (id) comments.open(id)\n}\nfunction onPreviewMove(event: PointerEvent) {\n if (event.pointerType === 'mouse') markerCursor.value = !!markerAt(event)\n}\n\nfunction onActive(id: string | null) {\n if (id !== boardActive.value) comments.open(id)\n}\nfunction onCommentAction(action: CommentAction) {\n comments.apply(action, { anchored: true })\n}\nfunction onClose() {\n settle()\n opened.value = false\n if (here(comments.active.value)) comments.open(null)\n}\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst canvas = useTemplateRef<HTMLElement>('canvas')\nconst preview = useTemplateRef<InstanceType<typeof DouFlowEditor>>('preview')\n\n/* the height, followed live while the bar is dragged */\nconst dragged = shallowRef<number | null>(null)\nconst height = computed(\n () => dragged.value ?? clampHeight(Number(props.block.props.height) || props.settings.height),\n)\n\n/* the preview is drawn once the block comes near the screen */\nconst seen = shallowRef(typeof IntersectionObserver === 'undefined')\nlet observer: IntersectionObserver | null = null\nlet resized: ResizeObserver | null = null\nlet frame = 0\n/** Fits the preview to its box again, once the nodes have been laid out. */\nfunction refit() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => preview.value?.fit())\n}\nonMounted(() => {\n const element = root.value!\n element.addEventListener(BOARD_OPEN_EVENT, openEditor)\n if (!seen.value) {\n observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n seen.value = true\n observer?.disconnect()\n observer = null\n },\n { rootMargin: '200px' },\n )\n observer.observe(element)\n }\n if (typeof ResizeObserver !== 'undefined') {\n let width = element.clientWidth\n resized = new ResizeObserver(() => {\n if (element.clientWidth === width) return\n width = element.clientWidth\n refit()\n })\n resized.observe(element)\n }\n})\nonBeforeUnmount(() => {\n settle()\n root.value?.removeEventListener(BOARD_OPEN_EVENT, openEditor)\n observer?.disconnect()\n resized?.disconnect()\n cancelAnimationFrame(frame)\n})\n/* what the preview shows: held while the fullscreen editor covers it, so it isn't redrawn each frame */\nconst shown = shallowRef(board.value)\nwatch(board, (value) => {\n if (!open.value) shown.value = value\n})\nwatch(shown, () => void nextTick(refit))\nwatch(height, () => void nextTick(refit))\n\nfunction openEditor() {\n if (!props.editable && empty.value) return\n steps.undo = 0\n steps.redo = 0\n pending = null\n open.value = true\n}\n\nconst contentPos = () => {\n const state = view.value?.state\n return state ? (findBlockById(state.doc, props.block.id)?.contentPos ?? null) : null\n}\n\n/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */\nfunction onOpened() {\n opened.value = true\n canvas.value?.querySelector<HTMLElement>('.dou-flow-editor')?.focus({ preventScroll: true })\n}\n\n/** Back in the document: the block selected, the editor focused. */\nfunction onClosed() {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n if (props.editable)\n editor.dispatch(editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)))\n editor.focus()\n}\n\n/*\n * Changes on the board go into the document as they are made, so `v-model`,\n * collaboration and the other blocks see them, and into the editor's undo\n * history: undo in the fullscreen editor is the document's, one step per\n * change on the board. The frames of a drag (or nudges with the arrow keys,\n * or typing in one node) join the step of the first one; only the fields\n * they change are written, so what others change meanwhile stays theirs. A\n * cancelled drag takes its step back.\n */\nconst GROUP_WINDOW = 1000\n/** A drag going on: its group, and when its last frame came. */\nlet pending: { group: string; time: number } | null = null\n/** The steps taken on the board since it was opened, and those undone. */\nconst steps = { undo: 0, redo: 0 }\n\n/** The board as the document keeps it: groups folded as they are there; and what this reader folded. */\nfunction toDocument(next: FlowDocument): FlowDocument {\n const before = new Map(stored.value.nodes.map((node) => [node.id, node]))\n let changed: Map<string, boolean> | null = null\n const nodes = next.nodes.map((node) => {\n const mine = !!node.data?.collapsed\n const theirs = before.get(node.id)?.data?.collapsed\n if (mine === !!theirs) {\n if (folded.value.has(node.id)) (changed ??= new Map(folded.value)).delete(node.id)\n return node\n }\n if (folded.value.get(node.id) !== mine) (changed ??= new Map(folded.value)).set(node.id, mine)\n const { collapsed: _, ...data } = node.data ?? {}\n if (theirs !== undefined) return { ...node, data: { ...data, collapsed: theirs } }\n // a node with no data before has none after\n if (Object.keys(data).length || before.get(node.id)?.data) return { ...node, data }\n const { data: __, ...rest } = node\n return rest as FlowNode\n })\n if (changed) folded.value = changed\n warnDataImages(next, before)\n return { ...next, nodes }\n}\n\nlet warned = false\n/** Pictures kept in the document as data URLs make it large: say so once, while developing. */\nfunction warnDataImages(next: FlowDocument, before: Map<string, FlowNode>) {\n if (warned || process.env.NODE_ENV === 'production') return\n const added = next.nodes.find(\n (node) =>\n typeof node.data?.src === 'string' &&\n node.data.src.startsWith('data:') &&\n before.get(node.id)?.data?.src !== node.data.src,\n )\n if (!added) return\n warned = true\n console.warn(\n `[@dou-ui/editor] a picture on the \"${props.block.type}\" block is kept in the document as a data URL; pass \\`upload\\` to whiteboardBlock() to keep only its address`,\n )\n}\n\nconst currentBoard = () => {\n const pos = contentPos()\n return pos === null ? null : (view.value?.state.doc.nodeAt(pos)?.attrs.board ?? null)\n}\n\n/** Writes the board as one undo step of its own. */\nfunction record(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n editor.dispatch(editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(ownStepKey, true))\n steps.undo++\n steps.redo = 0\n}\n\n/** Writes the board into the undo step before, the drag's. */\nfunction join(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n const tr = editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(joinStepKey, true)\n // for the built-in history: part of the step before, however long after\n editor.dispatch(tr.setMeta('appendedTransaction', editor.state.tr))\n}\n\n/** Ends the drag going on: the next change is a step of its own. */\nfunction settle() {\n pending = null\n}\n\nfunction forward(tr: FlowTransaction) {\n const editor = view.value\n const pos = contentPos()\n // a thread put on or taken off a node is written in a read-only document too, as on text\n const comment = tr.meta.origin === 'comment'\n if (!editor || pos === null || (!props.editable && !comment)) return\n const group = tr.meta.group\n const next = toDocument(tr.doc)\n // only folded or unfolded: nothing for the document\n if (JSON.stringify(next) === JSON.stringify(currentBoard())) return\n // not a step of the undo history, nor part of a drag going on\n if (comment) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n const now = Date.now()\n if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {\n // a cancelled drag putting the board back: part of its step\n if (tr.meta.history === false) return join(next)\n settle()\n }\n if (tr.meta.history === false) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n if (!group) return record(next)\n if (pending) {\n pending.time = now\n return join(next)\n }\n pending = { group, time: now }\n record(next)\n}\n\n/** Undo or redo in the document; refused when it would change something besides this board. */\nfunction travel(kind: 'undo' | 'redo') {\n settle()\n const editor = view.value\n if (!editor || !steps[kind]) return false\n const before = editor.state.doc\n const commands = historyCommands(editor.state)\n if (!commands[kind](editor.state, editor.dispatch, editor)) return false\n if (!onlyBoardChanged(before, editor.state.doc, props.block.id)) {\n // the board's own steps are used up: put back what was taken\n historyCommands(editor.state)[kind === 'undo' ? 'redo' : 'undo'](\n editor.state,\n editor.dispatch,\n editor,\n )\n steps[kind] = 0\n return false\n }\n steps[kind]--\n steps[kind === 'undo' ? 'redo' : 'undo']++\n return true\n}\n\n/** A cancelled drag: the board is back where it started, and its step is taken back. */\nfunction drop(group: string) {\n if (pending?.group !== group) return\n pending = null\n const editor = view.value\n if (!editor || !steps.undo) return\n if (historyCommands(editor.state).undo(editor.state, editor.dispatch, editor)) steps.undo--\n}\n\nconst history: FlowHistoryHandler = {\n undo: () => travel('undo'),\n redo: () => travel('redo'),\n canUndo: () => steps.undo > 0,\n canRedo: () => steps.redo > 0 && !pending,\n drop,\n close: settle,\n}\nconst bridge: FlowExtension = defineFlowExtension({\n name: 'editor-board-history',\n history: () => history,\n})\nconst extensions = [...props.settings.extensions, bridge]\n\n/*\n * Adding nodes: the types the extensions offer (`palette`), from a button\n * at the top left. When none is offered (`flowKit()` alone), a node of its\n * own with an input and an output, so what is added can be connected right\n * away.\n */\nconst offered = [\n ...props.settings.extensions.flat(),\n { nodeTypes: props.settings.editorProps.nodeTypes ?? [] },\n].some((extension) => extension.nodeTypes?.some((spec) => spec.palette))\nconst nodeTypes = computed(() => {\n const given = (props.settings.editorProps.nodeTypes ?? []) as NodeTypeSpec[]\n if (offered || !props.settings.fallbackNode) return given\n const name = text.value.node\n const step = defineNodeType({\n ...defaultNode,\n defaults: () => ({ label: name, inputs: [{ id: 'in' }], outputs: [{ id: 'out' }] }),\n palette: { label: name, icon: SquareIcon },\n }) as unknown as NodeTypeSpec\n return [step, ...given]\n})\nconst full = useTemplateRef<InstanceType<typeof DouFlowEditor>>('full')\nconst palette = computed(() => (props.editable ? (full.value?.paletteTypes ?? []) : []))\n/* several types: the same searchable list as when an edge is dropped on the canvas */\nconst adding = shallowRef(false)\nconst query = shallowRef('')\nconst addTrigger = useTemplateRef<InstanceType<typeof DouButton>>('addTrigger')\nconst command = useTemplateRef<InstanceType<typeof DouCommand>>('command')\nconst items = computed<CommandItem[]>(() =>\n palette.value.map((spec) => ({\n value: spec.type,\n label: spec.palette!.label,\n group: spec.palette!.group,\n description: spec.palette!.description,\n keywords: spec.palette!.keywords,\n icon: spec.palette!.icon,\n })),\n)\nwatch(adding, (value) => {\n if (!value) return\n query.value = ''\n // a phone's keyboard would cover the list: search only with a mouse\n if (!matchMedia('(pointer: coarse)').matches) void nextTick(() => command.value?.focus())\n})\n\nfunction addNode(type: string) {\n adding.value = false\n full.value?.insertNode(type)\n}\nfunction dragNode(type: string, event: PointerEvent) {\n if (event.button !== 0) return\n full.value?.startInsertDrag(type, event)\n // the list goes once the node is dropped, or the drag ends otherwise\n window.addEventListener(\n 'pointerup',\n () => {\n if (!adding.value) return\n adding.value = false\n // a drag let go of (or cancelled) off the canvas: back to the button\n void nextTick(() => {\n // the list may not be hidden yet: focus still in its search field\n const active = document.activeElement\n const list = command.value?.$el as HTMLElement | undefined\n if (!active || active === document.body || list?.contains(active))\n (addTrigger.value?.$el as HTMLElement | undefined)?.focus({ preventScroll: true })\n })\n },\n { once: true },\n )\n}\n\n/** A label cut into the letters the search matched and the rest. */\nfunction parts(name: string, indices: number[]) {\n const hit = new Set(indices)\n const out: { text: string; match: boolean }[] = []\n for (let i = 0; i < name.length; i++) {\n const match = hit.has(i)\n const last = out[out.length - 1]\n if (last && last.match === match) last.text += name[i]\n else out.push({ text: name[i]!, match })\n }\n return out\n}\n\n/* changing the height: drag the bar under the block, or the arrow keys on it */\nfunction onResizeStart(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n const bar = event.currentTarget as HTMLElement\n bar.setPointerCapture(event.pointerId)\n const startY = event.clientY\n const start = height.value\n const move = (e: PointerEvent) => (dragged.value = clampHeight(start + e.clientY - startY))\n const finish = (commit: boolean) => {\n bar.removeEventListener('pointermove', move)\n bar.removeEventListener('pointerup', up)\n bar.removeEventListener('pointercancel', cancel)\n window.removeEventListener('keydown', escape, true)\n const value = dragged.value\n dragged.value = null\n if (commit && value !== null && value !== start) props.updateProps({ height: value })\n }\n const up = () => finish(true)\n const cancel = () => finish(false)\n const escape = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return\n e.preventDefault()\n e.stopPropagation()\n finish(false)\n }\n bar.addEventListener('pointermove', move)\n bar.addEventListener('pointerup', up)\n bar.addEventListener('pointercancel', cancel)\n window.addEventListener('keydown', escape, true)\n}\n\nfunction onResizeKey(event: KeyboardEvent) {\n const by = { ArrowUp: -BOARD_HEIGHT.step, ArrowDown: BOARD_HEIGHT.step }[event.key]\n if (by) {\n event.preventDefault()\n props.updateProps({ height: clampHeight(height.value + by) })\n } else if (event.key === 'Escape') {\n event.preventDefault()\n onClosed()\n }\n}\n\nfunction resetHeight() {\n props.updateProps({ height: props.settings.height })\n}\n</script>\n\n<template>\n <div\n ref=\"root\"\n class=\"dou-editor-board\"\n :class=\"{ 'is-selected': selected, 'is-empty': empty }\"\n :style=\"{ height: `${height}px`, cursor: markerCursor ? 'pointer' : undefined }\"\n @dblclick=\"openEditor\"\n @click=\"onPreviewClick\"\n @pointermove=\"onPreviewMove\"\n @pointerleave=\"markerCursor = false\"\n >\n <div v-if=\"!empty\" class=\"dou-editor-board__preview\" role=\"img\" :aria-label=\"label\">\n <DouFlowEditor\n class=\"dou-editor-board__canvas\"\n inert\n v-if=\"seen\"\n ref=\"preview\"\n :model-value=\"shown\"\n v-bind=\"settings.editorProps\"\n :extensions=\"settings.extensions\"\n :node-types=\"nodeTypes\"\n readonly\n fit-view\n :fit-min-zoom=\"0.05\"\n :simple-zoom=\"0\"\n :min-zoom=\"0.05\"\n :max-zoom=\"1\"\n :bordered=\"false\"\n :searchable=\"false\"\n :comments=\"flowComments\"\n :commentable=\"false\"\n :pan-on-scroll=\"false\"\n />\n </div>\n <div v-else class=\"dou-editor-board__empty\">\n <span class=\"dou-editor-board__empty-text\">{{ text.empty }}</span>\n <DouButton v-if=\"editable\" size=\"sm\" variant=\"outline\" @click=\"openEditor\">\n <template #leading><PencilIcon /></template>\n {{ text.start }}\n </DouButton>\n </div>\n\n <div v-if=\"!empty\" class=\"dou-editor-board__actions\">\n <DouButton size=\"sm\" variant=\"outline\" class=\"dou-editor-board__open\" @click=\"openEditor\">\n <template #leading><PencilIcon v-if=\"editable\" /><EyeIcon v-else /></template>\n {{ editable ? text.edit : text.view }}\n </DouButton>\n </div>\n\n <div\n v-if=\"editable\"\n class=\"dou-editor-board__resize\"\n role=\"separator\"\n aria-orientation=\"horizontal\"\n tabindex=\"0\"\n :aria-label=\"text.resize\"\n :aria-valuemin=\"BOARD_HEIGHT.min\"\n :aria-valuemax=\"BOARD_HEIGHT.max\"\n :aria-valuenow=\"height\"\n data-editor-control\n @pointerdown=\"onResizeStart\"\n @keydown=\"onResizeKey\"\n @dblclick.stop=\"resetHeight\"\n />\n\n <DouDialog\n v-model:open=\"open\"\n :title=\"label\"\n fullscreen\n destroy-on-close\n @opened=\"onOpened\"\n @close=\"onClose\"\n @closed=\"onClosed\"\n >\n <div ref=\"canvas\" class=\"dou-editor-board__editor\" data-editor-control>\n <DouFlowEditor\n ref=\"full\"\n :model-value=\"board\"\n v-bind=\"settings.editorProps\"\n :extensions=\"extensions\"\n :node-types=\"nodeTypes\"\n :readonly=\"!editable\"\n fit-view\n :fit-min-zoom=\"0.1\"\n :simple-zoom=\"0.1\"\n :comments=\"flowComments\"\n :author=\"comments.author.value\"\n :commentable=\"comments.writable.value\"\n :active-comment=\"boardActive\"\n :aria-label=\"label\"\n @transaction=\"forward\"\n @update:active-comment=\"onActive\"\n @comment-action=\"onCommentAction\"\n >\n <DouFlowControls />\n <div v-if=\"palette.length\" class=\"dou-editor-board__add\">\n <DouButton\n v-if=\"palette.length === 1\"\n size=\"sm\"\n variant=\"outline\"\n @pointerdown=\"dragNode(palette[0]!.type, $event)\"\n @click=\"addNode(palette[0]!.type)\"\n >\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <DouPopover v-else v-model:open=\"adding\" placement=\"bottom-start\">\n <DouButton ref=\"addTrigger\" size=\"sm\" variant=\"outline\">\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <template #content>\n <DouCommand\n ref=\"command\"\n v-model:query=\"query\"\n class=\"dou-editor-board__types\"\n :items=\"items\"\n :placeholder=\"text.searchNodes\"\n :aria-label=\"text.addNode\"\n :empty-text=\"text.noNodes\"\n :max-height=\"280\"\n @select=\"addNode(String($event.value))\"\n >\n <template #item=\"{ item, indices }\">\n <span\n class=\"dou-editor-board__type\"\n @pointerdown=\"dragNode(String(item.value), $event)\"\n >\n <span class=\"dou-editor-board__type-icon\">\n <component :is=\"item.icon\" v-if=\"item.icon\" />\n </span>\n <span class=\"dou-command__label\">\n <template v-for=\"(part, at) in parts(item.label, indices)\" :key=\"at\">\n <mark v-if=\"part.match\" class=\"dou-command__match\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"item.description\" class=\"dou-command__description\">\n {{ item.description }}\n </span>\n </span>\n </template>\n </DouCommand>\n </template>\n </DouPopover>\n </div>\n <p v-if=\"palette.length && !board.nodes.length\" class=\"dou-editor-board__hint\">\n {{ text.emptyFlow }}\n </p>\n </DouFlowEditor>\n </div>\n </DouDialog>\n </div>\n</template>\n"],"mappings":""}