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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 // 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":""}
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 /** Where the \"+\" row button starts: under the table, or flush under its scrollbar track. */\n rowAddTop: number\n rowAddAfterScrollbar: boolean\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) {\n observeFrame(null)\n return (layout.value = null)\n }\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const viewportElement =\n frameElement?.querySelector<HTMLElement>(':scope > .dou-editor-table__viewport') ?? frameElement\n const tableElement = viewportElement?.querySelector('table')\n if (!tableNode || !frameElement || !viewportElement || !tableElement) {\n observeFrame(null)\n return (layout.value = null)\n }\n observeFrame(frameElement)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = viewportElement.getBoundingClientRect()\n const outerBox = frameElement.getBoundingClientRect()\n const scrollable = frameElement.classList.contains('is-scrollable')\n observedScrollable = scrollable\n const barElement = scrollable\n ? frameElement.querySelector<HTMLElement>(':scope > .dou-editor-table__scrollbar')\n : null\n const barBox = barElement?.getBoundingClientRect()\n const rowAddBottom = barBox && barBox.height > 0 ? barBox.bottom : outerBox.bottom\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 rowAddTop: (scrollable ? rowAddBottom : tableBox.bottom) - box.top,\n rowAddAfterScrollbar: scrollable,\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\nlet lastPoint: { x: number; y: number } | null = null\n\nlet observedFrame: HTMLElement | null = null\nlet observedScrollable = false\nconst frameResize =\n typeof ResizeObserver !== 'undefined' ? new ResizeObserver(() => schedule()) : null\nconst frameClasses =\n typeof MutationObserver !== 'undefined'\n ? new MutationObserver(() => {\n if (!observedFrame) return\n const scrollable = observedFrame.classList.contains('is-scrollable')\n if (scrollable === observedScrollable) return\n observedScrollable = scrollable\n schedule()\n })\n : null\n\n/** Watch the active table frame so container resizes and `is-scrollable` toggles re-place the \"+\" bar. */\nfunction observeFrame(element: HTMLElement | null) {\n if (element === observedFrame) return\n frameResize?.disconnect()\n frameClasses?.disconnect()\n observedFrame = element\n observedScrollable = !!element?.classList.contains('is-scrollable')\n if (!element) return\n frameResize?.observe(element)\n frameClasses?.observe(element, { attributes: true, attributeFilter: ['class'] })\n}\n\n/**\n * True while the pointer crosses the strip between a scrollable table's bottom\n * edge and its row \"+\" button — over the custom scrollbar or the open lane\n * beside it when a scrolled wide table reaches into the start margin.\n */\nfunction inBottomBridge(element: Element | null, point: { x: number; y: number } | null): boolean {\n const active = hovered.value\n const current = view.value\n if (!active || !current) return false\n const frameElement = current.nodeDOM(active.pos) as HTMLElement | null\n if (!frameElement) return false\n if (element?.closest('.dou-editor-table__scrollbar')?.parentElement === frameElement) return true\n if (!point || !frameElement.classList.contains('is-scrollable')) return false\n const viewportElement =\n frameElement.querySelector<HTMLElement>(':scope > .dou-editor-table__viewport') ?? frameElement\n const tableElement = viewportElement.querySelector('table')\n if (!tableElement) return false\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = viewportElement.getBoundingClientRect()\n const barBox = frameElement\n .querySelector<HTMLElement>(':scope > .dou-editor-table__scrollbar')\n ?.getBoundingClientRect()\n const left = Math.max(frameBox.left, tableBox.left)\n const right = Math.min(tableBox.right, frameBox.right)\n const top = tableBox.bottom - 1\n const bottom =\n (barBox && barBox.height > 0 ? barBox.bottom : frameElement.getBoundingClientRect().bottom) + 1\n return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom\n}\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 && !inBottomBridge(element, lastPoint)) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n lastPoint = { x: event.clientX, y: event.clientY }\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n lastPoint = 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 observeFrame(null)\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 :class=\"{ 'is-after-scrollbar': layout.rowAddAfterScrollbar }\"\n :style=\"{\n top: `${layout.rowAddTop}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":""}
@@ -85,14 +85,27 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
85
85
  const current = view.value;
86
86
  const host = root.value;
87
87
  const at = target.value;
88
- if (!current || !host || !at) return layout.value = null;
88
+ if (!current || !host || !at) {
89
+ observeFrame(null);
90
+ return layout.value = null;
91
+ }
89
92
  const tableNode = current.state.doc.nodeAt(at.pos);
90
93
  const frameElement = current.nodeDOM(at.pos);
91
- const tableElement = frameElement?.querySelector("table");
92
- if (!tableNode || !frameElement || !tableElement) return layout.value = null;
94
+ const viewportElement = frameElement?.querySelector(":scope > .dou-editor-table__viewport") ?? frameElement;
95
+ const tableElement = viewportElement?.querySelector("table");
96
+ if (!tableNode || !frameElement || !viewportElement || !tableElement) {
97
+ observeFrame(null);
98
+ return layout.value = null;
99
+ }
100
+ observeFrame(frameElement);
93
101
  const box = host.getBoundingClientRect();
94
102
  const tableBox = tableElement.getBoundingClientRect();
95
- const frameBox = frameElement.getBoundingClientRect();
103
+ const frameBox = viewportElement.getBoundingClientRect();
104
+ const outerBox = frameElement.getBoundingClientRect();
105
+ const scrollable = frameElement.classList.contains("is-scrollable");
106
+ observedScrollable = scrollable;
107
+ const barBox = (scrollable ? frameElement.querySelector(":scope > .dou-editor-table__scrollbar") : null)?.getBoundingClientRect();
108
+ const rowAddBottom = barBox && barBox.height > 0 ? barBox.bottom : outerBox.bottom;
96
109
  const first = cellElement(at.pos, at.rect.top, at.rect.left)?.getBoundingClientRect();
97
110
  if (!first) return layout.value = null;
98
111
  let bar = null;
@@ -118,6 +131,8 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
118
131
  left: Math.max(frameBox.left, tableBox.left) - box.left,
119
132
  right: frameBox.right - box.left
120
133
  },
134
+ rowAddTop: (scrollable ? rowAddBottom : tableBox.bottom) - box.top,
135
+ rowAddAfterScrollbar: scrollable,
121
136
  column: {
122
137
  left: first.left - box.left,
123
138
  width: first.width
@@ -143,6 +158,56 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
143
158
  }
144
159
  let frame = 0;
145
160
  let lastTarget = null;
161
+ let lastPoint = null;
162
+ let observedFrame = null;
163
+ let observedScrollable = false;
164
+ const frameResize = typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => schedule()) : null;
165
+ const frameClasses = typeof MutationObserver !== "undefined" ? new MutationObserver(() => {
166
+ if (!observedFrame) return;
167
+ const scrollable = observedFrame.classList.contains("is-scrollable");
168
+ if (scrollable === observedScrollable) return;
169
+ observedScrollable = scrollable;
170
+ schedule();
171
+ }) : null;
172
+ /** Watch the active table frame so container resizes and `is-scrollable` toggles re-place the "+" bar. */
173
+ function observeFrame(element) {
174
+ if (element === observedFrame) return;
175
+ frameResize?.disconnect();
176
+ frameClasses?.disconnect();
177
+ observedFrame = element;
178
+ observedScrollable = !!element?.classList.contains("is-scrollable");
179
+ if (!element) return;
180
+ frameResize?.observe(element);
181
+ frameClasses?.observe(element, {
182
+ attributes: true,
183
+ attributeFilter: ["class"]
184
+ });
185
+ }
186
+ /**
187
+ * True while the pointer crosses the strip between a scrollable table's bottom
188
+ * edge and its row "+" button — over the custom scrollbar or the open lane
189
+ * beside it when a scrolled wide table reaches into the start margin.
190
+ */
191
+ function inBottomBridge(element, point) {
192
+ const active = hovered.value;
193
+ const current = view.value;
194
+ if (!active || !current) return false;
195
+ const frameElement = current.nodeDOM(active.pos);
196
+ if (!frameElement) return false;
197
+ if (element?.closest(".dou-editor-table__scrollbar")?.parentElement === frameElement) return true;
198
+ if (!point || !frameElement.classList.contains("is-scrollable")) return false;
199
+ const viewportElement = frameElement.querySelector(":scope > .dou-editor-table__viewport") ?? frameElement;
200
+ const tableElement = viewportElement.querySelector("table");
201
+ if (!tableElement) return false;
202
+ const tableBox = tableElement.getBoundingClientRect();
203
+ const frameBox = viewportElement.getBoundingClientRect();
204
+ const barBox = frameElement.querySelector(":scope > .dou-editor-table__scrollbar")?.getBoundingClientRect();
205
+ const left = Math.max(frameBox.left, tableBox.left);
206
+ const right = Math.min(tableBox.right, frameBox.right);
207
+ const top = tableBox.bottom - 1;
208
+ const bottom = (barBox && barBox.height > 0 ? barBox.bottom : frameElement.getBoundingClientRect().bottom) + 1;
209
+ return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom;
210
+ }
146
211
  function schedule() {
147
212
  if (frame) return;
148
213
  frame = requestAnimationFrame(() => {
@@ -152,7 +217,7 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
152
217
  const cell = element?.closest(".dou-editor-table td, .dou-editor-table th");
153
218
  const inControls = element?.closest(".dou-editor-table-controls");
154
219
  if (cell) hovered.value = targetOf(cell);
155
- else if (!inControls) hovered.value = null;
220
+ else if (!inControls && !inBottomBridge(element, lastPoint)) hovered.value = null;
156
221
  }
157
222
  measure();
158
223
  });
@@ -160,11 +225,16 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
160
225
  function track(event) {
161
226
  if (event.pointerType === "touch") return;
162
227
  lastTarget = event.target;
228
+ lastPoint = {
229
+ x: event.clientX,
230
+ y: event.clientY
231
+ };
163
232
  schedule();
164
233
  }
165
234
  function leave() {
166
235
  if (menuOpen.value || dragging.value) return;
167
236
  lastTarget = null;
237
+ lastPoint = null;
168
238
  hovered.value = null;
169
239
  schedule();
170
240
  }
@@ -180,6 +250,7 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
180
250
  root.value?.removeEventListener("pointerleave", leave);
181
251
  window.removeEventListener("scroll", onScroll, true);
182
252
  window.removeEventListener("resize", onScroll);
253
+ observeFrame(null);
183
254
  if (frame) cancelAnimationFrame(frame);
184
255
  endDrag(false);
185
256
  });
@@ -633,16 +704,16 @@ var table_controls_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
633
704
  createElementVNode("button", {
634
705
  type: "button",
635
706
  tabindex: "-1",
636
- class: "dou-editor-table__add is-row",
707
+ class: normalizeClass(["dou-editor-table__add is-row", { "is-after-scrollbar": layout.value.rowAddAfterScrollbar }]),
637
708
  style: normalizeStyle({
638
- top: `${layout.value.table.top + layout.value.table.height}px`,
709
+ top: `${layout.value.rowAddTop}px`,
639
710
  left: `${layout.value.frame.left}px`,
640
711
  width: `${Math.min(layout.value.table.left + layout.value.table.width, layout.value.frame.right) - layout.value.frame.left}px`
641
712
  }),
642
713
  "aria-label": unref(messages).table.addRow,
643
714
  title: unref(messages).table.addRow,
644
715
  onClick: _cache[19] || (_cache[19] = ($event) => addAtEnd("row"))
645
- }, [createVNode(unref(PlusIcon))], 12, _hoisted_4),
716
+ }, [createVNode(unref(PlusIcon))], 14, _hoisted_4),
646
717
  drop.value ? (openBlock(), createElementBlock("div", {
647
718
  key: 0,
648
719
  class: normalizeClass(["dou-editor__drop", { "is-vertical": drop.value.axis === "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 // 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,C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CAAU;K,IAEtBD,YAAaC,MAAA,SAAA,CAAA,GAAGE,gBAAAC,gBAAAH,MAAA,QAAA,CAAQ,CAAC,MAAM,KAAK,GAAA,CAAA,C;KAG9B,IAAIA,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
+ {"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 /** Where the \"+\" row button starts: under the table, or flush under its scrollbar track. */\n rowAddTop: number\n rowAddAfterScrollbar: boolean\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) {\n observeFrame(null)\n return (layout.value = null)\n }\n const tableNode = current.state.doc.nodeAt(at.pos)\n const frameElement = current.nodeDOM(at.pos) as HTMLElement | null\n const viewportElement =\n frameElement?.querySelector<HTMLElement>(':scope > .dou-editor-table__viewport') ?? frameElement\n const tableElement = viewportElement?.querySelector('table')\n if (!tableNode || !frameElement || !viewportElement || !tableElement) {\n observeFrame(null)\n return (layout.value = null)\n }\n observeFrame(frameElement)\n const box = host.getBoundingClientRect()\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = viewportElement.getBoundingClientRect()\n const outerBox = frameElement.getBoundingClientRect()\n const scrollable = frameElement.classList.contains('is-scrollable')\n observedScrollable = scrollable\n const barElement = scrollable\n ? frameElement.querySelector<HTMLElement>(':scope > .dou-editor-table__scrollbar')\n : null\n const barBox = barElement?.getBoundingClientRect()\n const rowAddBottom = barBox && barBox.height > 0 ? barBox.bottom : outerBox.bottom\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 rowAddTop: (scrollable ? rowAddBottom : tableBox.bottom) - box.top,\n rowAddAfterScrollbar: scrollable,\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\nlet lastPoint: { x: number; y: number } | null = null\n\nlet observedFrame: HTMLElement | null = null\nlet observedScrollable = false\nconst frameResize =\n typeof ResizeObserver !== 'undefined' ? new ResizeObserver(() => schedule()) : null\nconst frameClasses =\n typeof MutationObserver !== 'undefined'\n ? new MutationObserver(() => {\n if (!observedFrame) return\n const scrollable = observedFrame.classList.contains('is-scrollable')\n if (scrollable === observedScrollable) return\n observedScrollable = scrollable\n schedule()\n })\n : null\n\n/** Watch the active table frame so container resizes and `is-scrollable` toggles re-place the \"+\" bar. */\nfunction observeFrame(element: HTMLElement | null) {\n if (element === observedFrame) return\n frameResize?.disconnect()\n frameClasses?.disconnect()\n observedFrame = element\n observedScrollable = !!element?.classList.contains('is-scrollable')\n if (!element) return\n frameResize?.observe(element)\n frameClasses?.observe(element, { attributes: true, attributeFilter: ['class'] })\n}\n\n/**\n * True while the pointer crosses the strip between a scrollable table's bottom\n * edge and its row \"+\" button — over the custom scrollbar or the open lane\n * beside it when a scrolled wide table reaches into the start margin.\n */\nfunction inBottomBridge(element: Element | null, point: { x: number; y: number } | null): boolean {\n const active = hovered.value\n const current = view.value\n if (!active || !current) return false\n const frameElement = current.nodeDOM(active.pos) as HTMLElement | null\n if (!frameElement) return false\n if (element?.closest('.dou-editor-table__scrollbar')?.parentElement === frameElement) return true\n if (!point || !frameElement.classList.contains('is-scrollable')) return false\n const viewportElement =\n frameElement.querySelector<HTMLElement>(':scope > .dou-editor-table__viewport') ?? frameElement\n const tableElement = viewportElement.querySelector('table')\n if (!tableElement) return false\n const tableBox = tableElement.getBoundingClientRect()\n const frameBox = viewportElement.getBoundingClientRect()\n const barBox = frameElement\n .querySelector<HTMLElement>(':scope > .dou-editor-table__scrollbar')\n ?.getBoundingClientRect()\n const left = Math.max(frameBox.left, tableBox.left)\n const right = Math.min(tableBox.right, frameBox.right)\n const top = tableBox.bottom - 1\n const bottom =\n (barBox && barBox.height > 0 ? barBox.bottom : frameElement.getBoundingClientRect().bottom) + 1\n return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom\n}\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 && !inBottomBridge(element, lastPoint)) hovered.value = null\n }\n measure()\n })\n}\n\nfunction track(event: PointerEvent) {\n if (event.pointerType === 'touch') return\n lastTarget = event.target\n lastPoint = { x: event.clientX, y: event.clientY }\n schedule()\n}\n\nfunction leave() {\n if (menuOpen.value || dragging.value) return\n lastTarget = null\n lastPoint = 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 observeFrame(null)\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 :class=\"{ 'is-after-scrollbar': layout.rowAddAfterScrollbar }\"\n :style=\"{\n top: `${layout.rowAddTop}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;KAC7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