@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.
- package/dist/components/block-handle.js.map +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/dom.js +5 -3
- package/dist/dom.js.map +1 -1
- package/dist/extensions/table/schema.js +5 -1
- package/dist/extensions/table/schema.js.map +1 -1
- package/dist/extensions/table/table-controls.js.map +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +79 -8
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/table/view.js +169 -16
- package/dist/extensions/table/view.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/extensions/table/view.d.ts +32 -5
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n moveRangeToNewColumn,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport {\n blockElementOf,\n bubbleShift,\n childBlocks,\n COLUMN_GROUP,\n contentAt,\n contentSpan,\n firstLine,\n handleLeft,\n scrollParent,\n sideBySide,\n} from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\n/** A mouse: \"+\" comes out of the bubble while the pointer is on it. */\nlet fine: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\n/** In a column the handle is only the grip, in the gap before it, leaving room for the resize bar. */\nconst compact = shallowRef(false)\n/** Next to a table: further out, clear of its row handles. */\nconst table = shallowRef(false)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => {\n menuOpen.value = false\n // the menu had the focus; the selected blocks still answer Delete and copy\n requestAnimationFrame(() => view.value?.focus())\n})\n\n/**\n * Where a drag would drop: before or after a block (a line across), or\n * beside a column, into a new column (a line down, `column` set).\n */\ninterface Drop {\n pos: number\n top: number\n left: number\n width: number\n height?: number\n column?: { row: string; index: number }\n}\nconst drop = shallowRef<Drop | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n compact.value = !!content.closest(COLUMN_GROUP)\n table.value = content.classList.contains('dou-editor__content--table')\n position.value = {\n top: line.top - box.top,\n left: handleLeft(content) - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY, lastX)\n if (content) place(content)\n })\n}\n\n/** A wide table scrolled sideways: the handle next to it follows its left edge. */\nfunction onScroll(event: Event) {\n const content = event.target\n if (\n !(content instanceof HTMLElement) ||\n !content.classList.contains('dou-editor__content--table')\n )\n return\n if (position.value && hovered.value && blockElementOf(content)?.dataset.blockId === hovered.value)\n place(content)\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n fine = window.matchMedia('(hover: hover) and (pointer: fine)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n root.value?.addEventListener('scroll', onScroll, true)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n root.value?.removeEventListener('scroll', onScroll, true)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\n/*\n * The bubble floats outside the text. When the editor's container cuts off\n * the room there (it clips, or the screen ends), the bubble moves in by as\n * much as it lacks, counting the \"+\" that comes out on hover, so the grip\n * stays under the pointer when it does, and a finger's reach on touch screens.\n */\nconst handle = useTemplateRef<HTMLElement>('handle')\n/** The width \"+\" adds to the bubble (its button, see the styles). */\nconst ADD_WIDTH = 20\n/** How far a finger's reach goes left of the bubble (the grip's ::before, past the bubble's border and padding). */\nconst TOUCH_REACH = 12\nconst shift = shallowRef(0)\n\nfunction clipLeft(from: HTMLElement): number {\n for (let node = from.parentElement; node; node = node.parentElement) {\n if (getComputedStyle(node).overflowX !== 'visible') return node.getBoundingClientRect().left\n }\n return 0\n}\n\nfunction fit() {\n const element = handle.value\n const host = root.value\n if (!element || !host || !visible.value) return\n let left = element.getBoundingClientRect().left - shift.value\n const plus = element.querySelector<HTMLElement>('.dou-editor__add')\n if (fine?.matches && !compact.value && plus && !plus.offsetWidth) left -= ADD_WIDTH\n const style = getComputedStyle(element)\n const clear =\n table.value && position.value\n ? host.getBoundingClientRect().left +\n position.value.left +\n Number.parseFloat(style.getPropertyValue('--dou-editor-handle-offset')) -\n 1\n : undefined\n const edge = clipLeft(host)\n /*\n * A finger's reach moves the bubble in too, but only as far as plain text\n * lets it: next to a table, a cut-off reach stays cut off rather than\n * pushing the bubble onto the row handles or past them.\n */\n const next = Math.max(\n bubbleShift(left, edge, clear),\n touch.value && !table.value ? bubbleShift(left - TOUCH_REACH, edge) : 0,\n )\n if (next !== shift.value) shift.value = next\n}\n\nwatch([position, visible, compact, table], fit, { flush: 'post' })\nlet sizes: ResizeObserver | null = null\nonMounted(() => {\n sizes = new ResizeObserver(fit)\n if (handle.value) sizes.observe(handle.value)\n})\nonBeforeUnmount(() => sizes?.disconnect())\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\n/** Beside a column, past its edge: a new column there, when the set takes one more. */\n/** How far into the last column a drop still makes a new column after it. */\nconst LAST_COLUMN_EDGE = 16\n\nfunction columnDrop(content: HTMLElement, moving: SiblingRange, box: DOMRect): Drop | null {\n const instance = view.value\n const group = content.closest<HTMLElement>(COLUMN_GROUP)\n const column = group?.parentElement\n const rowGroup = column?.parentElement\n const rowId = rowGroup?.parentElement?.dataset.blockId\n if (!instance || !column || !rowGroup || !rowId) return null\n const columns = childBlocks(rowGroup)\n const index = columns.indexOf(column)\n if (index < 0 || !sideBySide(columns)) return null\n const rect = column.getBoundingClientRect()\n // right of the last column there may be no room (the editor's edge): its last strip counts\n const right = index === columns.length - 1 ? rect.right - LAST_COLUMN_EDGE : rect.right\n const at = lastX < rect.left ? index : lastX > right ? index + 1 : -1\n if (at < 0) return null\n const row = findBlockById(instance.state.doc, rowId)\n if (!row || !moveRangeToNewColumn(moving, row.pos, at)(instance.state)) return null\n const gap =\n columns.length > 1\n ? columns[1]!.getBoundingClientRect().left - columns[0]!.getBoundingClientRect().right\n : 0\n const x =\n at === 0\n ? columns[0]!.getBoundingClientRect().left - gap / 2\n : at === columns.length\n ? columns.at(-1)!.getBoundingClientRect().right - 1\n : (columns[at - 1]!.getBoundingClientRect().right +\n columns[at]!.getBoundingClientRect().left) /\n 2\n const rowRect = rowGroup.getBoundingClientRect()\n return {\n pos: row.pos,\n top: rowRect.top - box.top,\n left: x - box.left,\n width: 0,\n height: rowRect.height,\n column: { row: rowId, index: at },\n }\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY, lastX)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const beside = columnDrop(content, range, box)\n if (beside) return (drop.value = beside)\n const rect = content.getBoundingClientRect()\n const span = contentSpan(content)\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = span.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child ? contentSpan(child).left : span.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: span.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n const row = spot.column && findBlockById(instance.state.doc, spot.column.row)\n const command = spot.column\n ? row && moveRangeToNewColumn(moving, row.pos, spot.column.index)\n : moveRangeTo(moving, spot.pos)\n if (!command || !command(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n ref=\"handle\"\n :class=\"['dou-editor__handle', { 'is-compact': compact, 'is-table': table }]\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n '--dou-editor-handle-shift': `${shift}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n :class=\"['dou-editor__drop', { 'is-vertical': drop.column }]\"\n :style=\"\n drop.column\n ? { top: `${drop.top}px`, left: `${drop.left}px`, height: `${drop.height}px` }\n : { top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\n \"\n />\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n moveRangeToNewColumn,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport {\n blockElementOf,\n bubbleShift,\n childBlocks,\n COLUMN_GROUP,\n contentAt,\n contentSpan,\n firstLine,\n handleLeft,\n scrollParent,\n sideBySide,\n} from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\n/** A mouse: \"+\" comes out of the bubble while the pointer is on it. */\nlet fine: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\n/** In a column the handle is only the grip, in the gap before it, leaving room for the resize bar. */\nconst compact = shallowRef(false)\n/** Next to a table: further out, clear of its row handles. */\nconst table = shallowRef(false)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => {\n menuOpen.value = false\n // the menu had the focus; the selected blocks still answer Delete and copy\n requestAnimationFrame(() => view.value?.focus())\n})\n\n/**\n * Where a drag would drop: before or after a block (a line across), or\n * beside a column, into a new column (a line down, `column` set).\n */\ninterface Drop {\n pos: number\n top: number\n left: number\n width: number\n height?: number\n column?: { row: string; index: number }\n}\nconst drop = shallowRef<Drop | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n compact.value = !!content.closest(COLUMN_GROUP)\n table.value = content.classList.contains('dou-editor__content--table')\n position.value = {\n top: line.top - box.top,\n left: handleLeft(content) - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY, lastX)\n if (content) place(content)\n })\n}\n\n/** A wide table scrolled sideways: the handle next to it follows its left edge. */\nfunction onScroll(event: Event) {\n const target = event.target\n if (!(target instanceof HTMLElement)) return\n const content = target.classList.contains('dou-editor-table__viewport')\n ? target.closest<HTMLElement>('.dou-editor__content--table')\n : target.classList.contains('dou-editor__content--table')\n ? target\n : null\n if (!content) return\n if (position.value && hovered.value && blockElementOf(content)?.dataset.blockId === hovered.value)\n place(content)\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n fine = window.matchMedia('(hover: hover) and (pointer: fine)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n root.value?.addEventListener('scroll', onScroll, true)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n root.value?.removeEventListener('scroll', onScroll, true)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\n/*\n * The bubble floats outside the text. When the editor's container cuts off\n * the room there (it clips, or the screen ends), the bubble moves in by as\n * much as it lacks, counting the \"+\" that comes out on hover, so the grip\n * stays under the pointer when it does, and a finger's reach on touch screens.\n */\nconst handle = useTemplateRef<HTMLElement>('handle')\n/** The width \"+\" adds to the bubble (its button, see the styles). */\nconst ADD_WIDTH = 20\n/** How far a finger's reach goes left of the bubble (the grip's ::before, past the bubble's border and padding). */\nconst TOUCH_REACH = 12\nconst shift = shallowRef(0)\n\nfunction clipLeft(from: HTMLElement): number {\n for (let node = from.parentElement; node; node = node.parentElement) {\n if (getComputedStyle(node).overflowX !== 'visible') return node.getBoundingClientRect().left\n }\n return 0\n}\n\nfunction fit() {\n const element = handle.value\n const host = root.value\n if (!element || !host || !visible.value) return\n let left = element.getBoundingClientRect().left - shift.value\n const plus = element.querySelector<HTMLElement>('.dou-editor__add')\n if (fine?.matches && !compact.value && plus && !plus.offsetWidth) left -= ADD_WIDTH\n const style = getComputedStyle(element)\n const clear =\n table.value && position.value\n ? host.getBoundingClientRect().left +\n position.value.left +\n Number.parseFloat(style.getPropertyValue('--dou-editor-handle-offset')) -\n 1\n : undefined\n const edge = clipLeft(host)\n /*\n * A finger's reach moves the bubble in too, but only as far as plain text\n * lets it: next to a table, a cut-off reach stays cut off rather than\n * pushing the bubble onto the row handles or past them.\n */\n const next = Math.max(\n bubbleShift(left, edge, clear),\n touch.value && !table.value ? bubbleShift(left - TOUCH_REACH, edge) : 0,\n )\n if (next !== shift.value) shift.value = next\n}\n\nwatch([position, visible, compact, table], fit, { flush: 'post' })\nlet sizes: ResizeObserver | null = null\nonMounted(() => {\n sizes = new ResizeObserver(fit)\n if (handle.value) sizes.observe(handle.value)\n})\nonBeforeUnmount(() => sizes?.disconnect())\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\n/** Beside a column, past its edge: a new column there, when the set takes one more. */\n/** How far into the last column a drop still makes a new column after it. */\nconst LAST_COLUMN_EDGE = 16\n\nfunction columnDrop(content: HTMLElement, moving: SiblingRange, box: DOMRect): Drop | null {\n const instance = view.value\n const group = content.closest<HTMLElement>(COLUMN_GROUP)\n const column = group?.parentElement\n const rowGroup = column?.parentElement\n const rowId = rowGroup?.parentElement?.dataset.blockId\n if (!instance || !column || !rowGroup || !rowId) return null\n const columns = childBlocks(rowGroup)\n const index = columns.indexOf(column)\n if (index < 0 || !sideBySide(columns)) return null\n const rect = column.getBoundingClientRect()\n // right of the last column there may be no room (the editor's edge): its last strip counts\n const right = index === columns.length - 1 ? rect.right - LAST_COLUMN_EDGE : rect.right\n const at = lastX < rect.left ? index : lastX > right ? index + 1 : -1\n if (at < 0) return null\n const row = findBlockById(instance.state.doc, rowId)\n if (!row || !moveRangeToNewColumn(moving, row.pos, at)(instance.state)) return null\n const gap =\n columns.length > 1\n ? columns[1]!.getBoundingClientRect().left - columns[0]!.getBoundingClientRect().right\n : 0\n const x =\n at === 0\n ? columns[0]!.getBoundingClientRect().left - gap / 2\n : at === columns.length\n ? columns.at(-1)!.getBoundingClientRect().right - 1\n : (columns[at - 1]!.getBoundingClientRect().right +\n columns[at]!.getBoundingClientRect().left) /\n 2\n const rowRect = rowGroup.getBoundingClientRect()\n return {\n pos: row.pos,\n top: rowRect.top - box.top,\n left: x - box.left,\n width: 0,\n height: rowRect.height,\n column: { row: rowId, index: at },\n }\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY, lastX)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const beside = columnDrop(content, range, box)\n if (beside) return (drop.value = beside)\n const rect = content.getBoundingClientRect()\n const span = contentSpan(content)\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = span.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child ? contentSpan(child).left : span.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: span.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n const row = spot.column && findBlockById(instance.state.doc, spot.column.row)\n const command = spot.column\n ? row && moveRangeToNewColumn(moving, row.pos, spot.column.index)\n : moveRangeTo(moving, spot.pos)\n if (!command || !command(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n ref=\"handle\"\n :class=\"['dou-editor__handle', { 'is-compact': compact, 'is-table': table }]\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n '--dou-editor-handle-shift': `${shift}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n :class=\"['dou-editor__drop', { 'is-vertical': drop.column }]\"\n :style=\"\n drop.column\n ? { top: `${drop.top}px`, left: `${drop.left}px`, height: `${drop.height}px` }\n : { top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\n \"\n />\n</template>\n"],"mappings":""}
|
|
@@ -92,8 +92,10 @@ var block_handle_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
92
92
|
}
|
|
93
93
|
/** A wide table scrolled sideways: the handle next to it follows its left edge. */
|
|
94
94
|
function onScroll(event) {
|
|
95
|
-
const
|
|
96
|
-
if (!(
|
|
95
|
+
const target = event.target;
|
|
96
|
+
if (!(target instanceof HTMLElement)) return;
|
|
97
|
+
const content = target.classList.contains("dou-editor-table__viewport") ? target.closest(".dou-editor__content--table") : target.classList.contains("dou-editor__content--table") ? target : null;
|
|
98
|
+
if (!content) return;
|
|
97
99
|
if (position.value && hovered.value && blockElementOf(content)?.dataset.blockId === hovered.value) place(content);
|
|
98
100
|
}
|
|
99
101
|
function leave(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeClass","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n moveRangeToNewColumn,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport {\n blockElementOf,\n bubbleShift,\n childBlocks,\n COLUMN_GROUP,\n contentAt,\n contentSpan,\n firstLine,\n handleLeft,\n scrollParent,\n sideBySide,\n} from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\n/** A mouse: \"+\" comes out of the bubble while the pointer is on it. */\nlet fine: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\n/** In a column the handle is only the grip, in the gap before it, leaving room for the resize bar. */\nconst compact = shallowRef(false)\n/** Next to a table: further out, clear of its row handles. */\nconst table = shallowRef(false)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => {\n menuOpen.value = false\n // the menu had the focus; the selected blocks still answer Delete and copy\n requestAnimationFrame(() => view.value?.focus())\n})\n\n/**\n * Where a drag would drop: before or after a block (a line across), or\n * beside a column, into a new column (a line down, `column` set).\n */\ninterface Drop {\n pos: number\n top: number\n left: number\n width: number\n height?: number\n column?: { row: string; index: number }\n}\nconst drop = shallowRef<Drop | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n compact.value = !!content.closest(COLUMN_GROUP)\n table.value = content.classList.contains('dou-editor__content--table')\n position.value = {\n top: line.top - box.top,\n left: handleLeft(content) - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY, lastX)\n if (content) place(content)\n })\n}\n\n/** A wide table scrolled sideways: the handle next to it follows its left edge. */\nfunction onScroll(event: Event) {\n const content = event.target\n if (\n !(content instanceof HTMLElement) ||\n !content.classList.contains('dou-editor__content--table')\n )\n return\n if (position.value && hovered.value && blockElementOf(content)?.dataset.blockId === hovered.value)\n place(content)\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n fine = window.matchMedia('(hover: hover) and (pointer: fine)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n root.value?.addEventListener('scroll', onScroll, true)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n root.value?.removeEventListener('scroll', onScroll, true)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\n/*\n * The bubble floats outside the text. When the editor's container cuts off\n * the room there (it clips, or the screen ends), the bubble moves in by as\n * much as it lacks, counting the \"+\" that comes out on hover, so the grip\n * stays under the pointer when it does, and a finger's reach on touch screens.\n */\nconst handle = useTemplateRef<HTMLElement>('handle')\n/** The width \"+\" adds to the bubble (its button, see the styles). */\nconst ADD_WIDTH = 20\n/** How far a finger's reach goes left of the bubble (the grip's ::before, past the bubble's border and padding). */\nconst TOUCH_REACH = 12\nconst shift = shallowRef(0)\n\nfunction clipLeft(from: HTMLElement): number {\n for (let node = from.parentElement; node; node = node.parentElement) {\n if (getComputedStyle(node).overflowX !== 'visible') return node.getBoundingClientRect().left\n }\n return 0\n}\n\nfunction fit() {\n const element = handle.value\n const host = root.value\n if (!element || !host || !visible.value) return\n let left = element.getBoundingClientRect().left - shift.value\n const plus = element.querySelector<HTMLElement>('.dou-editor__add')\n if (fine?.matches && !compact.value && plus && !plus.offsetWidth) left -= ADD_WIDTH\n const style = getComputedStyle(element)\n const clear =\n table.value && position.value\n ? host.getBoundingClientRect().left +\n position.value.left +\n Number.parseFloat(style.getPropertyValue('--dou-editor-handle-offset')) -\n 1\n : undefined\n const edge = clipLeft(host)\n /*\n * A finger's reach moves the bubble in too, but only as far as plain text\n * lets it: next to a table, a cut-off reach stays cut off rather than\n * pushing the bubble onto the row handles or past them.\n */\n const next = Math.max(\n bubbleShift(left, edge, clear),\n touch.value && !table.value ? bubbleShift(left - TOUCH_REACH, edge) : 0,\n )\n if (next !== shift.value) shift.value = next\n}\n\nwatch([position, visible, compact, table], fit, { flush: 'post' })\nlet sizes: ResizeObserver | null = null\nonMounted(() => {\n sizes = new ResizeObserver(fit)\n if (handle.value) sizes.observe(handle.value)\n})\nonBeforeUnmount(() => sizes?.disconnect())\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\n/** Beside a column, past its edge: a new column there, when the set takes one more. */\n/** How far into the last column a drop still makes a new column after it. */\nconst LAST_COLUMN_EDGE = 16\n\nfunction columnDrop(content: HTMLElement, moving: SiblingRange, box: DOMRect): Drop | null {\n const instance = view.value\n const group = content.closest<HTMLElement>(COLUMN_GROUP)\n const column = group?.parentElement\n const rowGroup = column?.parentElement\n const rowId = rowGroup?.parentElement?.dataset.blockId\n if (!instance || !column || !rowGroup || !rowId) return null\n const columns = childBlocks(rowGroup)\n const index = columns.indexOf(column)\n if (index < 0 || !sideBySide(columns)) return null\n const rect = column.getBoundingClientRect()\n // right of the last column there may be no room (the editor's edge): its last strip counts\n const right = index === columns.length - 1 ? rect.right - LAST_COLUMN_EDGE : rect.right\n const at = lastX < rect.left ? index : lastX > right ? index + 1 : -1\n if (at < 0) return null\n const row = findBlockById(instance.state.doc, rowId)\n if (!row || !moveRangeToNewColumn(moving, row.pos, at)(instance.state)) return null\n const gap =\n columns.length > 1\n ? columns[1]!.getBoundingClientRect().left - columns[0]!.getBoundingClientRect().right\n : 0\n const x =\n at === 0\n ? columns[0]!.getBoundingClientRect().left - gap / 2\n : at === columns.length\n ? columns.at(-1)!.getBoundingClientRect().right - 1\n : (columns[at - 1]!.getBoundingClientRect().right +\n columns[at]!.getBoundingClientRect().left) /\n 2\n const rowRect = rowGroup.getBoundingClientRect()\n return {\n pos: row.pos,\n top: rowRect.top - box.top,\n left: x - box.left,\n width: 0,\n height: rowRect.height,\n column: { row: rowId, index: at },\n }\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY, lastX)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const beside = columnDrop(content, range, box)\n if (beside) return (drop.value = beside)\n const rect = content.getBoundingClientRect()\n const span = contentSpan(content)\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = span.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child ? contentSpan(child).left : span.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: span.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n const row = spot.column && findBlockById(instance.state.doc, spot.column.row)\n const command = spot.column\n ? row && moveRangeToNewColumn(moving, row.pos, spot.column.index)\n : moveRangeTo(moving, spot.pos)\n if (!command || !command(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n ref=\"handle\"\n :class=\"['dou-editor__handle', { 'is-compact': compact, 'is-table': table }]\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n '--dou-editor-handle-shift': `${shift}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n :class=\"['dou-editor__drop', { 'is-vertical': drop.column }]\"\n :style=\"\n drop.column\n ? { top: `${drop.top}px`, left: `${drop.left}px`, height: `${drop.height}px` }\n : { top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\n \"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;AAiPA,IAAM,YAAY;;AAElB,IAAM,cAAc;AA4OpB,IAAM,mBAAmB;;;;EAjazB,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;E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GR,MAAA,QAAA,CAAQ,CAAC,MAAM,GAAA,CAAA,C;;;;IA9DtB,SAAAE,cAYS,CAZTN,mBAYS,UAAA;KAXP,MAAK;KACL,UAAS;KACT,OAAM;KACL,cAAYI,MAAA,QAAA,CAAQ,CAAC;KACrB,OAAOA,MAAA,QAAA,CAAQ,CAAC;KAChB,eAAa;KACb,eAAa;KACb,aAAW;KACX,iBAAe;I,IAEhBC,YAAoBD,MAAA,gBAAA,CAAA,C;;G,wBA1ChB,CAAAU,OAAA,QAAA,KAAO,C,IAmGT,KAAA,SADRlB,UAAA,GAAAC,mBAQE,OAAA;;IANC,OAAKI,eAAA,CAAA,oBAAA,EAAA,eAAwC,KAAA,MAAK,OAAM,CAAA,CAAA;IACxD,OAAKC,eAAS,KAAA,MAAK,SAA2B;KAAA,KAAA,GAAA,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,QAAA,GAAiB,KAAA,MAAK,OAAM;IAAA,IAA2B;KAAA,KAAA,GAAA,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,OAAA,GAAgB,KAAA,MAAK,MAAK;IAAA,C"}
|
|
1
|
+
{"version":3,"file":"block-handle.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeClass","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n moveRangeToNewColumn,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport {\n blockElementOf,\n bubbleShift,\n childBlocks,\n COLUMN_GROUP,\n contentAt,\n contentSpan,\n firstLine,\n handleLeft,\n scrollParent,\n sideBySide,\n} from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\n/** A mouse: \"+\" comes out of the bubble while the pointer is on it. */\nlet fine: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\n/** In a column the handle is only the grip, in the gap before it, leaving room for the resize bar. */\nconst compact = shallowRef(false)\n/** Next to a table: further out, clear of its row handles. */\nconst table = shallowRef(false)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => {\n menuOpen.value = false\n // the menu had the focus; the selected blocks still answer Delete and copy\n requestAnimationFrame(() => view.value?.focus())\n})\n\n/**\n * Where a drag would drop: before or after a block (a line across), or\n * beside a column, into a new column (a line down, `column` set).\n */\ninterface Drop {\n pos: number\n top: number\n left: number\n width: number\n height?: number\n column?: { row: string; index: number }\n}\nconst drop = shallowRef<Drop | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n compact.value = !!content.closest(COLUMN_GROUP)\n table.value = content.classList.contains('dou-editor__content--table')\n position.value = {\n top: line.top - box.top,\n left: handleLeft(content) - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY, lastX)\n if (content) place(content)\n })\n}\n\n/** A wide table scrolled sideways: the handle next to it follows its left edge. */\nfunction onScroll(event: Event) {\n const target = event.target\n if (!(target instanceof HTMLElement)) return\n const content = target.classList.contains('dou-editor-table__viewport')\n ? target.closest<HTMLElement>('.dou-editor__content--table')\n : target.classList.contains('dou-editor__content--table')\n ? target\n : null\n if (!content) return\n if (position.value && hovered.value && blockElementOf(content)?.dataset.blockId === hovered.value)\n place(content)\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n fine = window.matchMedia('(hover: hover) and (pointer: fine)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n root.value?.addEventListener('scroll', onScroll, true)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n root.value?.removeEventListener('scroll', onScroll, true)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\n/*\n * The bubble floats outside the text. When the editor's container cuts off\n * the room there (it clips, or the screen ends), the bubble moves in by as\n * much as it lacks, counting the \"+\" that comes out on hover, so the grip\n * stays under the pointer when it does, and a finger's reach on touch screens.\n */\nconst handle = useTemplateRef<HTMLElement>('handle')\n/** The width \"+\" adds to the bubble (its button, see the styles). */\nconst ADD_WIDTH = 20\n/** How far a finger's reach goes left of the bubble (the grip's ::before, past the bubble's border and padding). */\nconst TOUCH_REACH = 12\nconst shift = shallowRef(0)\n\nfunction clipLeft(from: HTMLElement): number {\n for (let node = from.parentElement; node; node = node.parentElement) {\n if (getComputedStyle(node).overflowX !== 'visible') return node.getBoundingClientRect().left\n }\n return 0\n}\n\nfunction fit() {\n const element = handle.value\n const host = root.value\n if (!element || !host || !visible.value) return\n let left = element.getBoundingClientRect().left - shift.value\n const plus = element.querySelector<HTMLElement>('.dou-editor__add')\n if (fine?.matches && !compact.value && plus && !plus.offsetWidth) left -= ADD_WIDTH\n const style = getComputedStyle(element)\n const clear =\n table.value && position.value\n ? host.getBoundingClientRect().left +\n position.value.left +\n Number.parseFloat(style.getPropertyValue('--dou-editor-handle-offset')) -\n 1\n : undefined\n const edge = clipLeft(host)\n /*\n * A finger's reach moves the bubble in too, but only as far as plain text\n * lets it: next to a table, a cut-off reach stays cut off rather than\n * pushing the bubble onto the row handles or past them.\n */\n const next = Math.max(\n bubbleShift(left, edge, clear),\n touch.value && !table.value ? bubbleShift(left - TOUCH_REACH, edge) : 0,\n )\n if (next !== shift.value) shift.value = next\n}\n\nwatch([position, visible, compact, table], fit, { flush: 'post' })\nlet sizes: ResizeObserver | null = null\nonMounted(() => {\n sizes = new ResizeObserver(fit)\n if (handle.value) sizes.observe(handle.value)\n})\nonBeforeUnmount(() => sizes?.disconnect())\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\n/** Beside a column, past its edge: a new column there, when the set takes one more. */\n/** How far into the last column a drop still makes a new column after it. */\nconst LAST_COLUMN_EDGE = 16\n\nfunction columnDrop(content: HTMLElement, moving: SiblingRange, box: DOMRect): Drop | null {\n const instance = view.value\n const group = content.closest<HTMLElement>(COLUMN_GROUP)\n const column = group?.parentElement\n const rowGroup = column?.parentElement\n const rowId = rowGroup?.parentElement?.dataset.blockId\n if (!instance || !column || !rowGroup || !rowId) return null\n const columns = childBlocks(rowGroup)\n const index = columns.indexOf(column)\n if (index < 0 || !sideBySide(columns)) return null\n const rect = column.getBoundingClientRect()\n // right of the last column there may be no room (the editor's edge): its last strip counts\n const right = index === columns.length - 1 ? rect.right - LAST_COLUMN_EDGE : rect.right\n const at = lastX < rect.left ? index : lastX > right ? index + 1 : -1\n if (at < 0) return null\n const row = findBlockById(instance.state.doc, rowId)\n if (!row || !moveRangeToNewColumn(moving, row.pos, at)(instance.state)) return null\n const gap =\n columns.length > 1\n ? columns[1]!.getBoundingClientRect().left - columns[0]!.getBoundingClientRect().right\n : 0\n const x =\n at === 0\n ? columns[0]!.getBoundingClientRect().left - gap / 2\n : at === columns.length\n ? columns.at(-1)!.getBoundingClientRect().right - 1\n : (columns[at - 1]!.getBoundingClientRect().right +\n columns[at]!.getBoundingClientRect().left) /\n 2\n const rowRect = rowGroup.getBoundingClientRect()\n return {\n pos: row.pos,\n top: rowRect.top - box.top,\n left: x - box.left,\n width: 0,\n height: rowRect.height,\n column: { row: rowId, index: at },\n }\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY, lastX)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const beside = columnDrop(content, range, box)\n if (beside) return (drop.value = beside)\n const rect = content.getBoundingClientRect()\n const span = contentSpan(content)\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = span.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child ? contentSpan(child).left : span.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: span.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n const row = spot.column && findBlockById(instance.state.doc, spot.column.row)\n const command = spot.column\n ? row && moveRangeToNewColumn(moving, row.pos, spot.column.index)\n : moveRangeTo(moving, spot.pos)\n if (!command || !command(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n ref=\"handle\"\n :class=\"['dou-editor__handle', { 'is-compact': compact, 'is-table': table }]\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n '--dou-editor-handle-shift': `${shift}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n :class=\"['dou-editor__drop', { 'is-vertical': drop.column }]\"\n :style=\"\n drop.column\n ? { top: `${drop.top}px`, left: `${drop.left}px`, height: `${drop.height}px` }\n : { top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\n \"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;AAmPA,IAAM,YAAY;;AAElB,IAAM,cAAc;AA4OpB,IAAM,mBAAmB;;;;EAnazB,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;EAOhF,MAAM,QAAQ,WAAW,KAAK;EAC9B,IAAI,QAA+B;;EAEnC,IAAI,OAA8B;EAClC,MAAM,gBAAiB,MAAM,QAAQ,CAAC,CAAC,OAAO;;EAG9C,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,WAA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ZTN,mBAYS,UAAA;KAXP,MAAK;KACL,UAAS;KACT,OAAM;KACL,cAAYI,MAAA,QAAA,CAAQ,CAAC;KACrB,OAAOA,MAAA,QAAA,CAAQ,CAAC;KAChB,eAAa;KACb,eAAa;KACb,aAAW;KACX,iBAAe;I,IAEhBC,YAAoBD,MAAA,gBAAA,CAAA,C;;G,wBA1ChB,CAAAU,OAAA,QAAA,KAAO,C,IAmGT,KAAA,SADRlB,UAAA,GAAAC,mBAQE,OAAA;;IANC,OAAKI,eAAA,CAAA,oBAAA,EAAA,eAAwC,KAAA,MAAK,OAAM,CAAA,CAAA;IACxD,OAAKC,eAAS,KAAA,MAAK,SAA2B;KAAA,KAAA,GAAA,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,QAAA,GAAiB,KAAA,MAAK,OAAM;IAAA,IAA2B;KAAA,KAAA,GAAA,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,OAAA,GAAgB,KAAA,MAAK,MAAK;IAAA,C"}
|
package/dist/dom.js
CHANGED
|
@@ -110,10 +110,12 @@ function contentSpan(content) {
|
|
|
110
110
|
left: rect.left,
|
|
111
111
|
right: rect.right
|
|
112
112
|
};
|
|
113
|
-
const
|
|
113
|
+
const viewport = content.querySelector(":scope > .dou-editor-table__viewport");
|
|
114
|
+
const start = Number.parseFloat(getComputedStyle(viewport ?? content).paddingInlineStart) || 0;
|
|
115
|
+
const end = Number.parseFloat(getComputedStyle(content).marginInlineEnd) || 0;
|
|
114
116
|
return {
|
|
115
|
-
left: rect.left +
|
|
116
|
-
right: rect.right +
|
|
117
|
+
left: rect.left + start,
|
|
118
|
+
right: rect.right + end
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
121
|
/**
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { EditorView } from 'prosemirror-view'\n\nconst isBlock = (element: Element): element is HTMLElement =>\n element.classList.contains('dou-editor__block')\n\n/** The blocks right inside a container element: the editing area or a group. */\nexport const childBlocks = (container: Element): HTMLElement[] =>\n Array.from(container.children).filter(isBlock)\n\nconst contentOf = (block: HTMLElement) =>\n block.querySelector<HTMLElement>(':scope > .dou-editor__content')\n\nconst groupOf = (block: HTMLElement) =>\n block.querySelector<HTMLElement>(':scope > .dou-editor__group')\n\n/** Where a block starts: its content's top, or its children's for a block without visible content (columns). */\nfunction topOf(block: HTMLElement): number {\n const content = contentOf(block)\n const shown = content?.getClientRects().length ? content : (groupOf(block) ?? block)\n return shown.getBoundingClientRect().top\n}\n\n/** The last of `blocks` whose top is above `y` (the first when none is). */\nfunction lastAbove(blocks: HTMLElement[], y: number): HTMLElement {\n let low = 0\n let high = blocks.length - 1\n let found = 0\n while (low <= high) {\n const middle = (low + high) >> 1\n if (topOf(blocks[middle]!) <= y) {\n found = middle\n low = middle + 1\n } else high = middle - 1\n }\n return blocks[found]!\n}\n\n/** The group of a set of columns, around an element in one of them. */\nexport const COLUMNS_GROUP = '.dou-editor__content--columns + .dou-editor__group'\n/** The group of one column (its blocks). */\nexport const COLUMN_GROUP = '.dou-editor__content--column + .dou-editor__group'\n\n/** Whether columns sit side by side; a narrow editor stacks them. */\nexport function sideBySide(columns: HTMLElement[]): boolean {\n return (\n columns.length > 1 &&\n Math.abs(columns[0]!.getBoundingClientRect().top - columns[1]!.getBoundingClientRect().top) < 1\n )\n}\n\n/**\n * The column at `x` among side-by-side ones: the gap before a column\n * belongs to it (its handle sits there), what is left of the first to the\n * first and right of the last to the last.\n */\nexport function columnAtX(columns: HTMLElement[], x: number): number {\n let index = 0\n for (let next = 1; next < columns.length; next++)\n if (x >= columns[next - 1]!.getBoundingClientRect().right) index = next\n return index\n}\n\n/**\n * The content element (paragraph, heading, …) at height `y` in viewport\n * coordinates: the last one whose top is above it, nested ones included.\n * Blocks follow each other from top to bottom, so a binary search finds\n * the block, then the same again among its children. In a set of\n * columns, `x` picks the column (stacked columns go by `y` too).\n */\nexport function contentAt(view: EditorView, y: number, x?: number): HTMLElement | null {\n let container: Element = view.dom\n for (;;) {\n const blocks = childBlocks(container)\n if (!blocks.length) return null\n const block = lastAbove(blocks, y)\n const content = contentOf(block)\n const group = groupOf(block)\n if (group && content?.classList.contains('dou-editor__content--columns')) {\n const columns = childBlocks(group)\n if (!columns.length) return null\n const column =\n x !== undefined && sideBySide(columns)\n ? columns[columnAtX(columns, x)]!\n : lastAbove(columns, y)\n const inner = groupOf(column)\n if (!inner) return null\n container = inner\n continue\n }\n // the children, when shown (a closed toggle hides them) and `y` reaches them\n const first = group?.getClientRects().length ? childBlocks(group)[0] : undefined\n if (group && first && topOf(first) <= y) {\n container = group\n continue\n }\n return content\n }\n}\n\n/** The block element around a content element. */\nexport function blockElementOf(content: HTMLElement): HTMLElement | null {\n return content.closest<HTMLElement>('.dou-editor__block')\n}\n\n/** The nearest ancestor that scrolls vertically, or `null` for the page. */\nexport function scrollParent(element: HTMLElement): HTMLElement | null {\n for (let node = element.parentElement; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node)\n if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight)\n return node\n }\n return null\n}\n\n/** Where the first line of a content element sits: its top and height. */\nexport function firstLine(content: HTMLElement): { top: number; height: number } {\n const rect = content.getBoundingClientRect()\n const style = getComputedStyle(content)\n const lineHeight = Number.parseFloat(style.lineHeight)\n const padding = Number.parseFloat(style.paddingTop) || 0\n const height = Number.isFinite(lineHeight) ? Math.min(lineHeight, rect.height) : rect.height\n return { top: rect.top + (height < rect.height ? padding : 0), height }\n}\n\n/** A top-level table: only it reaches into the margins (a table in a column or a list doesn't). */\nconst isWideTable = (content: HTMLElement) =>\n content.classList.contains('dou-editor__content--table') &&\n !!content.parentElement?.parentElement?.classList.contains('dou-editor__surface')\n\n/**\n * Where a block's content goes across: its box, less what a top-level\n * table's frame reaches into the margins (its start padding and end margin),\n * which keeps the table in line with the text. The editor lays out left to\n * right, so the logical start and end are the left and right.\n */\nexport function contentSpan(content: HTMLElement): { left: number; right: number } {\n const rect = content.getBoundingClientRect()\n if (!isWideTable(content)) return { left: rect.left, right: rect.right }\n const style = getComputedStyle(content)\n return {\n left: rect.left + (Number.parseFloat(style.paddingInlineStart) || 0),\n right: rect.right + (Number.parseFloat(style.marginInlineEnd) || 0),\n }\n}\n\n/**\n * Where the block handle goes: before the content, or before what shows of\n * a table, whose left edge moves out into the margin as it scrolls.\n */\nexport function handleLeft(content: HTMLElement): number {\n const rect = content.getBoundingClientRect()\n if (!isWideTable(content)) return rect.left\n const table = content.querySelector('table')\n return table ? Math.max(rect.left, table.getBoundingClientRect().left) : contentSpan(content).left\n}\n\n/**\n * How far the block handle's bubble moves in over the text: by as much as\n * its `start` (its left edge, \"+\" included when it can come out) lacks of\n * `clip` plus 2px. Next to a table, a bubble that has to move in goes on\n * past `clear`, right of the table's row handles, rather than onto them.\n */\nexport function bubbleShift(start: number, clip: number, clear?: number): number {\n const shift = Math.max(0, Math.ceil(clip + 2 - start))\n if (!shift || clear === undefined) return shift\n return Math.max(shift, Math.ceil(clear - start))\n}\n\n/** The right edge of the editor's text column: the surface less its padding (a reading width). */\nexport function columnRight(surface: HTMLElement): number {\n const padding = Number.parseFloat(getComputedStyle(surface).paddingRight) || 0\n return surface.getBoundingClientRect().right - padding\n}\n"],"mappings":";AAEA,IAAM,WAAW,YACf,QAAQ,UAAU,SAAS,mBAAmB;;AAGhD,IAAa,eAAe,cAC1B,MAAM,KAAK,UAAU,QAAQ,CAAC,CAAC,OAAO,OAAO;AAE/C,IAAM,aAAa,UACjB,MAAM,cAA2B,+BAA+B;AAElE,IAAM,WAAW,UACf,MAAM,cAA2B,6BAA6B;;AAGhE,SAAS,MAAM,OAA4B;CACzC,MAAM,UAAU,UAAU,KAAK;CAE/B,QADc,SAAS,eAAe,CAAC,CAAC,SAAS,UAAW,QAAQ,KAAK,KAAK,MAAA,CACjE,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E,OAAO,KAAK,SAAS,OAAO,WAAW,MAAM,eAAe,KAAK;CACnE;AACF;;;;;AAMA,SAAgB,WAAW,SAA8B;CACvD,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,IAAI,CAAC,YAAY,OAAO,GAAG,OAAO,KAAK;CACvC,MAAM,QAAQ,QAAQ,cAAc,OAAO;CAC3C,OAAO,QAAQ,KAAK,IAAI,KAAK,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,IAAI,YAAY,OAAO,CAAC,CAAC;AAChG;;;;;;;AAQA,SAAgB,YAAY,OAAe,MAAc,OAAwB;CAC/E,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO,IAAI,KAAK,CAAC;CACrD,IAAI,CAAC,SAAS,UAAU,KAAA,GAAW,OAAO;CAC1C,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,KAAK,CAAC;AACjD;;AAGA,SAAgB,YAAY,SAA8B;CACxD,MAAM,UAAU,OAAO,WAAW,iBAAiB,OAAO,CAAC,CAAC,YAAY,KAAK;CAC7E,OAAO,QAAQ,sBAAsB,CAAC,CAAC,QAAQ;AACjD"}
|
|
1
|
+
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { EditorView } from 'prosemirror-view'\n\nconst isBlock = (element: Element): element is HTMLElement =>\n element.classList.contains('dou-editor__block')\n\n/** The blocks right inside a container element: the editing area or a group. */\nexport const childBlocks = (container: Element): HTMLElement[] =>\n Array.from(container.children).filter(isBlock)\n\nconst contentOf = (block: HTMLElement) =>\n block.querySelector<HTMLElement>(':scope > .dou-editor__content')\n\nconst groupOf = (block: HTMLElement) =>\n block.querySelector<HTMLElement>(':scope > .dou-editor__group')\n\n/** Where a block starts: its content's top, or its children's for a block without visible content (columns). */\nfunction topOf(block: HTMLElement): number {\n const content = contentOf(block)\n const shown = content?.getClientRects().length ? content : (groupOf(block) ?? block)\n return shown.getBoundingClientRect().top\n}\n\n/** The last of `blocks` whose top is above `y` (the first when none is). */\nfunction lastAbove(blocks: HTMLElement[], y: number): HTMLElement {\n let low = 0\n let high = blocks.length - 1\n let found = 0\n while (low <= high) {\n const middle = (low + high) >> 1\n if (topOf(blocks[middle]!) <= y) {\n found = middle\n low = middle + 1\n } else high = middle - 1\n }\n return blocks[found]!\n}\n\n/** The group of a set of columns, around an element in one of them. */\nexport const COLUMNS_GROUP = '.dou-editor__content--columns + .dou-editor__group'\n/** The group of one column (its blocks). */\nexport const COLUMN_GROUP = '.dou-editor__content--column + .dou-editor__group'\n\n/** Whether columns sit side by side; a narrow editor stacks them. */\nexport function sideBySide(columns: HTMLElement[]): boolean {\n return (\n columns.length > 1 &&\n Math.abs(columns[0]!.getBoundingClientRect().top - columns[1]!.getBoundingClientRect().top) < 1\n )\n}\n\n/**\n * The column at `x` among side-by-side ones: the gap before a column\n * belongs to it (its handle sits there), what is left of the first to the\n * first and right of the last to the last.\n */\nexport function columnAtX(columns: HTMLElement[], x: number): number {\n let index = 0\n for (let next = 1; next < columns.length; next++)\n if (x >= columns[next - 1]!.getBoundingClientRect().right) index = next\n return index\n}\n\n/**\n * The content element (paragraph, heading, …) at height `y` in viewport\n * coordinates: the last one whose top is above it, nested ones included.\n * Blocks follow each other from top to bottom, so a binary search finds\n * the block, then the same again among its children. In a set of\n * columns, `x` picks the column (stacked columns go by `y` too).\n */\nexport function contentAt(view: EditorView, y: number, x?: number): HTMLElement | null {\n let container: Element = view.dom\n for (;;) {\n const blocks = childBlocks(container)\n if (!blocks.length) return null\n const block = lastAbove(blocks, y)\n const content = contentOf(block)\n const group = groupOf(block)\n if (group && content?.classList.contains('dou-editor__content--columns')) {\n const columns = childBlocks(group)\n if (!columns.length) return null\n const column =\n x !== undefined && sideBySide(columns)\n ? columns[columnAtX(columns, x)]!\n : lastAbove(columns, y)\n const inner = groupOf(column)\n if (!inner) return null\n container = inner\n continue\n }\n // the children, when shown (a closed toggle hides them) and `y` reaches them\n const first = group?.getClientRects().length ? childBlocks(group)[0] : undefined\n if (group && first && topOf(first) <= y) {\n container = group\n continue\n }\n return content\n }\n}\n\n/** The block element around a content element. */\nexport function blockElementOf(content: HTMLElement): HTMLElement | null {\n return content.closest<HTMLElement>('.dou-editor__block')\n}\n\n/** The nearest ancestor that scrolls vertically, or `null` for the page. */\nexport function scrollParent(element: HTMLElement): HTMLElement | null {\n for (let node = element.parentElement; node; node = node.parentElement) {\n const { overflowY } = getComputedStyle(node)\n if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight)\n return node\n }\n return null\n}\n\n/** Where the first line of a content element sits: its top and height. */\nexport function firstLine(content: HTMLElement): { top: number; height: number } {\n const rect = content.getBoundingClientRect()\n const style = getComputedStyle(content)\n const lineHeight = Number.parseFloat(style.lineHeight)\n const padding = Number.parseFloat(style.paddingTop) || 0\n const height = Number.isFinite(lineHeight) ? Math.min(lineHeight, rect.height) : rect.height\n return { top: rect.top + (height < rect.height ? padding : 0), height }\n}\n\n/** A top-level table: only it reaches into the margins (a table in a column or a list doesn't). */\nconst isWideTable = (content: HTMLElement) =>\n content.classList.contains('dou-editor__content--table') &&\n !!content.parentElement?.parentElement?.classList.contains('dou-editor__surface')\n\n/**\n * Where a block's content goes across: its box, less what a top-level\n * table's frame reaches into the margins (its start padding and end margin),\n * which keeps the table in line with the text. The editor lays out left to\n * right, so the logical start and end are the left and right.\n */\nexport function contentSpan(content: HTMLElement): { left: number; right: number } {\n const rect = content.getBoundingClientRect()\n if (!isWideTable(content)) return { left: rect.left, right: rect.right }\n const viewport = content.querySelector<HTMLElement>(':scope > .dou-editor-table__viewport')\n const start = Number.parseFloat(getComputedStyle(viewport ?? content).paddingInlineStart) || 0\n const end = Number.parseFloat(getComputedStyle(content).marginInlineEnd) || 0\n return {\n left: rect.left + start,\n right: rect.right + end,\n }\n}\n\n/**\n * Where the block handle goes: before the content, or before what shows of\n * a table, whose left edge moves out into the margin as it scrolls.\n */\nexport function handleLeft(content: HTMLElement): number {\n const rect = content.getBoundingClientRect()\n if (!isWideTable(content)) return rect.left\n const table = content.querySelector('table')\n return table ? Math.max(rect.left, table.getBoundingClientRect().left) : contentSpan(content).left\n}\n\n/**\n * How far the block handle's bubble moves in over the text: by as much as\n * its `start` (its left edge, \"+\" included when it can come out) lacks of\n * `clip` plus 2px. Next to a table, a bubble that has to move in goes on\n * past `clear`, right of the table's row handles, rather than onto them.\n */\nexport function bubbleShift(start: number, clip: number, clear?: number): number {\n const shift = Math.max(0, Math.ceil(clip + 2 - start))\n if (!shift || clear === undefined) return shift\n return Math.max(shift, Math.ceil(clear - start))\n}\n\n/** The right edge of the editor's text column: the surface less its padding (a reading width). */\nexport function columnRight(surface: HTMLElement): number {\n const padding = Number.parseFloat(getComputedStyle(surface).paddingRight) || 0\n return surface.getBoundingClientRect().right - padding\n}\n"],"mappings":";AAEA,IAAM,WAAW,YACf,QAAQ,UAAU,SAAS,mBAAmB;;AAGhD,IAAa,eAAe,cAC1B,MAAM,KAAK,UAAU,QAAQ,CAAC,CAAC,OAAO,OAAO;AAE/C,IAAM,aAAa,UACjB,MAAM,cAA2B,+BAA+B;AAElE,IAAM,WAAW,UACf,MAAM,cAA2B,6BAA6B;;AAGhE,SAAS,MAAM,OAA4B;CACzC,MAAM,UAAU,UAAU,KAAK;CAE/B,QADc,SAAS,eAAe,CAAC,CAAC,SAAS,UAAW,QAAQ,KAAK,KAAK,MAAA,CACjE,sBAAsB,CAAC,CAAC;AACvC;;AAGA,SAAS,UAAU,QAAuB,GAAwB;CAChE,IAAI,MAAM;CACV,IAAI,OAAO,OAAO,SAAS;CAC3B,IAAI,QAAQ;CACZ,OAAO,OAAO,MAAM;EAClB,MAAM,SAAU,MAAM,QAAS;EAC/B,IAAI,MAAM,OAAO,OAAQ,KAAK,GAAG;GAC/B,QAAQ;GACR,MAAM,SAAS;EACjB,OAAO,OAAO,SAAS;CACzB;CACA,OAAO,OAAO;AAChB;;AAGA,IAAa,gBAAgB;;AAE7B,IAAa,eAAe;;AAG5B,SAA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sB,CAAC,CAAC,IAAI,IAAI,YAAY,OAAO,CAAC,CAAC;AAChG;;;;;;;AAQA,SAAgB,YAAY,OAAe,MAAc,OAAwB;CAC/E,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO,IAAI,KAAK,CAAC;CACrD,IAAI,CAAC,SAAS,UAAU,KAAA,GAAW,OAAO;CAC1C,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,KAAK,CAAC;AACjD;;AAGA,SAAgB,YAAY,SAA8B;CACxD,MAAM,UAAU,OAAO,WAAW,iBAAiB,OAAO,CAAC,CAAC,YAAY,KAAK;CAC7E,OAAO,QAAQ,sBAAsB,CAAC,CAAC,QAAQ;AACjD"}
|
|
@@ -232,7 +232,11 @@ var tableSpec = {
|
|
|
232
232
|
class: "dou-editor__content dou-editor__content--table",
|
|
233
233
|
"data-content-type": "table"
|
|
234
234
|
},
|
|
235
|
-
[
|
|
235
|
+
[
|
|
236
|
+
"div",
|
|
237
|
+
{ class: "dou-editor-table__viewport" },
|
|
238
|
+
["table", ["tbody", 0]]
|
|
239
|
+
]
|
|
236
240
|
]
|
|
237
241
|
};
|
|
238
242
|
var tableNodes = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/extensions/table/schema.ts"],"sourcesContent":["import type { Node as PMNode, NodeSpec, NodeType } from 'prosemirror-model'\nimport { TableMap } from 'prosemirror-tables'\nimport {\n createId,\n inlineNodes,\n inlineOf,\n type BlockProps,\n type GridCell,\n type PartialTableCell,\n type PartialTableRow,\n type RowsSpec,\n type TableCell,\n type TableGrid,\n type TableRow,\n} from '../../core/model'\n\n/** A column of a table: a stable id, and how its cells align. */\nexport interface TableColumn {\n id: string\n /** In pixels; without it the column takes its share of the width. */\n width?: number\n align?: TableAlign\n}\n\nexport type TableAlign = 'left' | 'center' | 'right'\n\nconst ALIGNS = new Set(['left', 'center', 'right'])\n\n/** The columns as stored on the table node: id and alignment (widths live on the cells). */\ninterface StoredColumn {\n id: string\n align?: TableAlign\n}\n\nexport const isAlign = (value: unknown): value is TableAlign => ALIGNS.has(value as string)\n\n/** One column record per column of the grid, keeping ids and alignment that are there. */\nexport function fitColumns(columns: unknown, width: number): StoredColumn[] {\n const list = Array.isArray(columns) ? (columns as Partial<TableColumn>[]) : []\n const seen = new Set<string>()\n const result: StoredColumn[] = []\n for (let index = 0; index < width; index++) {\n const column = list[index] ?? {}\n let id = typeof column.id === 'string' && column.id ? column.id : createId()\n if (seen.has(id)) id = createId()\n seen.add(id)\n result.push(isAlign(column.align) ? { id, align: column.align } : { id })\n }\n return result\n}\n\nexport const isHeaderAt = (attrs: Record<string, unknown>, row: number, col: number) =>\n (!!attrs.headerRow && row === 0) || (!!attrs.headerColumn && col === 0)\n\n/* table node ↔ rows */\n\n/** The columns with their widths, which live on the cells. */\nfunction columnsOf(node: PMNode, map: TableMap): TableColumn[] {\n const columns = fitColumns(node.attrs.columns, map.width)\n const widths: (number | undefined)[] = []\n for (let index = 0; index < map.map.length; index++) {\n const col = index % map.width\n if (widths[col] !== undefined) continue\n const pos = map.map[index]!\n const width = (node.nodeAt(pos)!.attrs.colwidth as number[] | null)?.[\n col - map.findCell(pos).left\n ]\n if (width) widths[col] = width\n }\n return columns.map((column, index) =>\n widths[index] ? { ...column, width: widths[index] } : column,\n )\n}\n\nfunction readRows(node: PMNode): { props: BlockProps; rows: TableRow[] } {\n const map = TableMap.get(node)\n const rows: TableRow[] = []\n for (let row = 0; row < map.height; row++) {\n const cells: TableCell[] = []\n for (let col = 0; col < map.width; col++) {\n const pos = map.map[row * map.width + col]!\n const rect = map.findCell(pos)\n if (rect.left !== col || rect.top !== row) {\n // covered by a merged cell\n cells.push({ content: [] })\n continue\n }\n const item: TableCell = { content: inlineOf(node.nodeAt(pos)!) }\n if (rect.right - rect.left > 1) item.colspan = rect.right - rect.left\n if (rect.bottom - rect.top > 1) item.rowspan = rect.bottom - rect.top\n cells.push(item)\n }\n rows.push({ id: (node.child(row).attrs.id as string | null) ?? '', cells })\n }\n return {\n props: {\n headerRow: !!node.attrs.headerRow,\n headerColumn: !!node.attrs.headerColumn,\n columns: columnsOf(node, map),\n },\n rows,\n }\n}\n\nfunction gridOf(node: PMNode): TableGrid {\n const map = TableMap.get(node)\n const cells: GridCell[] = []\n const seen = new Set<number>()\n for (const pos of map.map) {\n if (seen.has(pos)) continue\n seen.add(pos)\n const rect = map.findCell(pos)\n cells.push({\n row: rect.top,\n col: rect.left,\n rowspan: rect.bottom - rect.top,\n colspan: rect.right - rect.left,\n node: node.nodeAt(pos)!,\n offset: pos,\n })\n }\n const rows: string[] = []\n node.forEach((row) => rows.push((row.attrs.id as string | null) ?? ''))\n return {\n props: { headerRow: !!node.attrs.headerRow, headerColumn: !!node.attrs.headerColumn },\n columns: columnsOf(node, map),\n rows,\n cells,\n }\n}\n\nconst DEFAULT_SIZE = 3\n\nfunction writeRows(type: NodeType, props: BlockProps, given: PartialTableRow[]): PMNode {\n const schema = type.schema\n const rows: PartialTableRow[] = given.length\n ? given\n : Array.from({ length: DEFAULT_SIZE }, () => ({\n cells: Array.from({ length: DEFAULT_SIZE }, () => ''),\n }))\n const listed = Array.isArray(props.columns) ? (props.columns as Partial<TableColumn>[]) : []\n const width = Math.max(1, listed.length, ...rows.map((row) => row.cells.length))\n const height = rows.length\n const columns = fitColumns(listed, width)\n const widths = Array.from({ length: width }, (_, index) => {\n const value = Number(listed[index]?.width)\n return value > 0 ? Math.round(value) : 0\n })\n const attrs = {\n headerRow: props.headerRow === undefined ? true : !!props.headerRow,\n headerColumn: !!props.headerColumn,\n columns,\n }\n const covered = Array.from({ length: height }, () => Array.from({ length: width }, () => false))\n const free = (top: number, left: number, bottom: number, right: number) => {\n for (let row = top; row < bottom; row++)\n for (let col = left; col < right; col++) if (covered[row]![col]) return false\n return true\n }\n const rowNodes = rows.map((row, r) => {\n const cells: PMNode[] = []\n for (let c = 0; c < width; c++) {\n if (covered[r]![c]) continue\n const raw = row.cells[c]\n const cell: PartialTableCell = typeof raw === 'string' ? { content: raw } : (raw ?? {})\n // spans stay inside the table and never overlap another merged cell\n let colspan = Math.max(1, Math.min(Math.floor(cell.colspan ?? 1) || 1, width - c))\n let rowspan = Math.max(1, Math.min(Math.floor(cell.rowspan ?? 1) || 1, height - r))\n while (colspan > 1 && !free(r, c, r + 1, c + colspan)) colspan--\n while (rowspan > 1 && !free(r, c, r + rowspan, c + colspan)) rowspan--\n for (let y = r; y < r + rowspan; y++)\n for (let x = c; x < c + colspan; x++) covered[y]![x] = true\n const span = widths.slice(c, c + colspan)\n const cellType = isHeaderAt(attrs, r, c) ? schema.nodes.tableHeader! : schema.nodes.tableCell!\n cells.push(\n cellType.create(\n { colspan, rowspan, colwidth: span.some(Boolean) ? span : null },\n inlineNodes(schema, cell.content, false),\n ),\n )\n }\n return schema.nodes.tableRow!.create({ id: row.id || createId() }, cells)\n })\n return type.create(attrs, rowNodes)\n}\n\nexport const tableRows: RowsSpec = { read: readRows, write: writeRows, grid: gridOf }\n\n/* DOM */\n\nfunction cellAttrs(dom: HTMLElement) {\n const widthAttr = dom.getAttribute('data-colwidth')\n const colspan = Number(dom.getAttribute('colspan') || 1)\n const widths =\n widthAttr && /^\\d+(,\\d+)*$/.test(widthAttr) ? widthAttr.split(',').map(Number) : null\n return {\n colspan,\n rowspan: Number(dom.getAttribute('rowspan') || 1),\n colwidth: widths && widths.length === colspan ? widths : null,\n }\n}\n\nfunction cellDOM(tag: 'td' | 'th') {\n return (node: PMNode) => {\n const attrs: Record<string, string> = {}\n if (node.attrs.colspan !== 1) attrs.colspan = String(node.attrs.colspan)\n if (node.attrs.rowspan !== 1) attrs.rowspan = String(node.attrs.rowspan)\n if (node.attrs.colwidth) attrs['data-colwidth'] = (node.attrs.colwidth as number[]).join(',')\n return [tag, attrs, 0] as const\n }\n}\n\nconst cellSpec = (role: 'cell' | 'header_cell', tag: 'td' | 'th'): NodeSpec => ({\n content: 'inline*',\n tableRole: role,\n isolating: true,\n attrs: { colspan: { default: 1 }, rowspan: { default: 1 }, colwidth: { default: null } },\n parseDOM: [{ tag, getAttrs: (dom) => cellAttrs(dom as HTMLElement) }],\n toDOM: cellDOM(tag),\n})\n\n/** The table's alignment per column, from the first row of a pasted table. */\nfunction columnsFromDOM(table: HTMLElement): StoredColumn[] {\n const first = table.querySelector('tr')\n const columns: StoredColumn[] = []\n for (const cell of Array.from(first?.children ?? [])) {\n const align = (cell as HTMLElement).style.textAlign || cell.getAttribute('align')\n const span = Number(cell.getAttribute('colspan') || 1)\n for (let index = 0; index < span; index++)\n columns.push(isAlign(align) ? { id: createId(), align } : { id: createId() })\n }\n return columns\n}\n\nexport const tableSpec: NodeSpec = {\n content: 'tableRow+',\n tableRole: 'table',\n isolating: true,\n attrs: {\n headerRow: { default: true },\n headerColumn: { default: false },\n columns: { default: [] },\n },\n rows: tableRows,\n parseDOM: [\n {\n tag: 'table',\n getAttrs: (dom) => {\n const table = dom as HTMLElement\n const rows = Array.from(table.querySelectorAll('tr'))\n const firstCells = Array.from(rows[0]?.children ?? [])\n return {\n headerRow: firstCells.length > 0 && firstCells.every((cell) => cell.tagName === 'TH'),\n headerColumn:\n rows.length > 1 && rows.every((row) => row.firstElementChild?.tagName === 'TH'),\n columns: columnsFromDOM(table),\n }\n },\n },\n ],\n toDOM: () => [\n 'div',\n { class: 'dou-editor__content dou-editor__content--table', 'data-content-type': 'table' },\n ['table', ['tbody', 0]],\n ],\n}\n\nexport const tableNodes: Record<string, NodeSpec> = {\n // rows a merged cell covers completely have no cells of their own\n tableRow: {\n content: '(tableCell | tableHeader)*',\n tableRole: 'row',\n attrs: { id: { default: null } },\n parseDOM: [\n { tag: 'tr', getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.rowId ?? null }) },\n ],\n toDOM: (node) => ['tr', { 'data-row-id': node.attrs.id }, 0],\n },\n tableCell: cellSpec('cell', 'td'),\n tableHeader: cellSpec('header_cell', 'th'),\n}\n"],"mappings":";;;AA0BA,IAAM,yBA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GAAG;GAAG;EAAC;CAC7D;CACA,WAAW,SAAS,QAAQ,IAAI;CAChC,aAAa,SAAS,eAAe,IAAI;AAC3C"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/extensions/table/schema.ts"],"sourcesContent":["import type { Node as PMNode, NodeSpec, NodeType } from 'prosemirror-model'\nimport { TableMap } from 'prosemirror-tables'\nimport {\n createId,\n inlineNodes,\n inlineOf,\n type BlockProps,\n type GridCell,\n type PartialTableCell,\n type PartialTableRow,\n type RowsSpec,\n type TableCell,\n type TableGrid,\n type TableRow,\n} from '../../core/model'\n\n/** A column of a table: a stable id, and how its cells align. */\nexport interface TableColumn {\n id: string\n /** In pixels; without it the column takes its share of the width. */\n width?: number\n align?: TableAlign\n}\n\nexport type TableAlign = 'left' | 'center' | 'right'\n\nconst ALIGNS = new Set(['left', 'center', 'right'])\n\n/** The columns as stored on the table node: id and alignment (widths live on the cells). */\ninterface StoredColumn {\n id: string\n align?: TableAlign\n}\n\nexport const isAlign = (value: unknown): value is TableAlign => ALIGNS.has(value as string)\n\n/** One column record per column of the grid, keeping ids and alignment that are there. */\nexport function fitColumns(columns: unknown, width: number): StoredColumn[] {\n const list = Array.isArray(columns) ? (columns as Partial<TableColumn>[]) : []\n const seen = new Set<string>()\n const result: StoredColumn[] = []\n for (let index = 0; index < width; index++) {\n const column = list[index] ?? {}\n let id = typeof column.id === 'string' && column.id ? column.id : createId()\n if (seen.has(id)) id = createId()\n seen.add(id)\n result.push(isAlign(column.align) ? { id, align: column.align } : { id })\n }\n return result\n}\n\nexport const isHeaderAt = (attrs: Record<string, unknown>, row: number, col: number) =>\n (!!attrs.headerRow && row === 0) || (!!attrs.headerColumn && col === 0)\n\n/* table node ↔ rows */\n\n/** The columns with their widths, which live on the cells. */\nfunction columnsOf(node: PMNode, map: TableMap): TableColumn[] {\n const columns = fitColumns(node.attrs.columns, map.width)\n const widths: (number | undefined)[] = []\n for (let index = 0; index < map.map.length; index++) {\n const col = index % map.width\n if (widths[col] !== undefined) continue\n const pos = map.map[index]!\n const width = (node.nodeAt(pos)!.attrs.colwidth as number[] | null)?.[\n col - map.findCell(pos).left\n ]\n if (width) widths[col] = width\n }\n return columns.map((column, index) =>\n widths[index] ? { ...column, width: widths[index] } : column,\n )\n}\n\nfunction readRows(node: PMNode): { props: BlockProps; rows: TableRow[] } {\n const map = TableMap.get(node)\n const rows: TableRow[] = []\n for (let row = 0; row < map.height; row++) {\n const cells: TableCell[] = []\n for (let col = 0; col < map.width; col++) {\n const pos = map.map[row * map.width + col]!\n const rect = map.findCell(pos)\n if (rect.left !== col || rect.top !== row) {\n // covered by a merged cell\n cells.push({ content: [] })\n continue\n }\n const item: TableCell = { content: inlineOf(node.nodeAt(pos)!) }\n if (rect.right - rect.left > 1) item.colspan = rect.right - rect.left\n if (rect.bottom - rect.top > 1) item.rowspan = rect.bottom - rect.top\n cells.push(item)\n }\n rows.push({ id: (node.child(row).attrs.id as string | null) ?? '', cells })\n }\n return {\n props: {\n headerRow: !!node.attrs.headerRow,\n headerColumn: !!node.attrs.headerColumn,\n columns: columnsOf(node, map),\n },\n rows,\n }\n}\n\nfunction gridOf(node: PMNode): TableGrid {\n const map = TableMap.get(node)\n const cells: GridCell[] = []\n const seen = new Set<number>()\n for (const pos of map.map) {\n if (seen.has(pos)) continue\n seen.add(pos)\n const rect = map.findCell(pos)\n cells.push({\n row: rect.top,\n col: rect.left,\n rowspan: rect.bottom - rect.top,\n colspan: rect.right - rect.left,\n node: node.nodeAt(pos)!,\n offset: pos,\n })\n }\n const rows: string[] = []\n node.forEach((row) => rows.push((row.attrs.id as string | null) ?? ''))\n return {\n props: { headerRow: !!node.attrs.headerRow, headerColumn: !!node.attrs.headerColumn },\n columns: columnsOf(node, map),\n rows,\n cells,\n }\n}\n\nconst DEFAULT_SIZE = 3\n\nfunction writeRows(type: NodeType, props: BlockProps, given: PartialTableRow[]): PMNode {\n const schema = type.schema\n const rows: PartialTableRow[] = given.length\n ? given\n : Array.from({ length: DEFAULT_SIZE }, () => ({\n cells: Array.from({ length: DEFAULT_SIZE }, () => ''),\n }))\n const listed = Array.isArray(props.columns) ? (props.columns as Partial<TableColumn>[]) : []\n const width = Math.max(1, listed.length, ...rows.map((row) => row.cells.length))\n const height = rows.length\n const columns = fitColumns(listed, width)\n const widths = Array.from({ length: width }, (_, index) => {\n const value = Number(listed[index]?.width)\n return value > 0 ? Math.round(value) : 0\n })\n const attrs = {\n headerRow: props.headerRow === undefined ? true : !!props.headerRow,\n headerColumn: !!props.headerColumn,\n columns,\n }\n const covered = Array.from({ length: height }, () => Array.from({ length: width }, () => false))\n const free = (top: number, left: number, bottom: number, right: number) => {\n for (let row = top; row < bottom; row++)\n for (let col = left; col < right; col++) if (covered[row]![col]) return false\n return true\n }\n const rowNodes = rows.map((row, r) => {\n const cells: PMNode[] = []\n for (let c = 0; c < width; c++) {\n if (covered[r]![c]) continue\n const raw = row.cells[c]\n const cell: PartialTableCell = typeof raw === 'string' ? { content: raw } : (raw ?? {})\n // spans stay inside the table and never overlap another merged cell\n let colspan = Math.max(1, Math.min(Math.floor(cell.colspan ?? 1) || 1, width - c))\n let rowspan = Math.max(1, Math.min(Math.floor(cell.rowspan ?? 1) || 1, height - r))\n while (colspan > 1 && !free(r, c, r + 1, c + colspan)) colspan--\n while (rowspan > 1 && !free(r, c, r + rowspan, c + colspan)) rowspan--\n for (let y = r; y < r + rowspan; y++)\n for (let x = c; x < c + colspan; x++) covered[y]![x] = true\n const span = widths.slice(c, c + colspan)\n const cellType = isHeaderAt(attrs, r, c) ? schema.nodes.tableHeader! : schema.nodes.tableCell!\n cells.push(\n cellType.create(\n { colspan, rowspan, colwidth: span.some(Boolean) ? span : null },\n inlineNodes(schema, cell.content, false),\n ),\n )\n }\n return schema.nodes.tableRow!.create({ id: row.id || createId() }, cells)\n })\n return type.create(attrs, rowNodes)\n}\n\nexport const tableRows: RowsSpec = { read: readRows, write: writeRows, grid: gridOf }\n\n/* DOM */\n\nfunction cellAttrs(dom: HTMLElement) {\n const widthAttr = dom.getAttribute('data-colwidth')\n const colspan = Number(dom.getAttribute('colspan') || 1)\n const widths =\n widthAttr && /^\\d+(,\\d+)*$/.test(widthAttr) ? widthAttr.split(',').map(Number) : null\n return {\n colspan,\n rowspan: Number(dom.getAttribute('rowspan') || 1),\n colwidth: widths && widths.length === colspan ? widths : null,\n }\n}\n\nfunction cellDOM(tag: 'td' | 'th') {\n return (node: PMNode) => {\n const attrs: Record<string, string> = {}\n if (node.attrs.colspan !== 1) attrs.colspan = String(node.attrs.colspan)\n if (node.attrs.rowspan !== 1) attrs.rowspan = String(node.attrs.rowspan)\n if (node.attrs.colwidth) attrs['data-colwidth'] = (node.attrs.colwidth as number[]).join(',')\n return [tag, attrs, 0] as const\n }\n}\n\nconst cellSpec = (role: 'cell' | 'header_cell', tag: 'td' | 'th'): NodeSpec => ({\n content: 'inline*',\n tableRole: role,\n isolating: true,\n attrs: { colspan: { default: 1 }, rowspan: { default: 1 }, colwidth: { default: null } },\n parseDOM: [{ tag, getAttrs: (dom) => cellAttrs(dom as HTMLElement) }],\n toDOM: cellDOM(tag),\n})\n\n/** The table's alignment per column, from the first row of a pasted table. */\nfunction columnsFromDOM(table: HTMLElement): StoredColumn[] {\n const first = table.querySelector('tr')\n const columns: StoredColumn[] = []\n for (const cell of Array.from(first?.children ?? [])) {\n const align = (cell as HTMLElement).style.textAlign || cell.getAttribute('align')\n const span = Number(cell.getAttribute('colspan') || 1)\n for (let index = 0; index < span; index++)\n columns.push(isAlign(align) ? { id: createId(), align } : { id: createId() })\n }\n return columns\n}\n\nexport const tableSpec: NodeSpec = {\n content: 'tableRow+',\n tableRole: 'table',\n isolating: true,\n attrs: {\n headerRow: { default: true },\n headerColumn: { default: false },\n columns: { default: [] },\n },\n rows: tableRows,\n parseDOM: [\n {\n tag: 'table',\n getAttrs: (dom) => {\n const table = dom as HTMLElement\n const rows = Array.from(table.querySelectorAll('tr'))\n const firstCells = Array.from(rows[0]?.children ?? [])\n return {\n headerRow: firstCells.length > 0 && firstCells.every((cell) => cell.tagName === 'TH'),\n headerColumn:\n rows.length > 1 && rows.every((row) => row.firstElementChild?.tagName === 'TH'),\n columns: columnsFromDOM(table),\n }\n },\n },\n ],\n toDOM: () => [\n 'div',\n { class: 'dou-editor__content dou-editor__content--table', 'data-content-type': 'table' },\n ['div', { class: 'dou-editor-table__viewport' }, ['table', ['tbody', 0]]],\n ],\n}\n\nexport const tableNodes: Record<string, NodeSpec> = {\n // rows a merged cell covers completely have no cells of their own\n tableRow: {\n content: '(tableCell | tableHeader)*',\n tableRole: 'row',\n attrs: { id: { default: null } },\n parseDOM: [\n { tag: 'tr', getAttrs: (dom) => ({ id: (dom as HTMLElement).dataset.rowId ?? null }) },\n ],\n toDOM: (node) => ['tr', { 'data-row-id': node.attrs.id }, 0],\n },\n tableCell: cellSpec('cell', 'td'),\n tableHeader: cellSpec('header_cell', 'th'),\n}\n"],"mappings":";;;AA0BA,IAAM,yBAAS,IAAI,IAAI;CAAC;CAAQ;CAAU;AAAO,CAAC;AAQlD,IAAa,WAAW,UAAwC,OAAO,IAAI,KAAe;;AAG1F,SAAgB,WAAW,SAAkB,OAA+B;CAC1E,MAAM,OAAO,MAAM,QAAQ,OAAO,IAAK,UAAqC,CAAC;CAC7E,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,SAAyB,CAAC;CAChC,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,SAAS;EAC1C,MAAM,SAAS,KAAK,UAAU,CAAC;EAC/B,IAAI,KAAK,OAAO,OAAO,OAAO,YAAY,OAAO,KAAK,OAAO,KAAK,SAAS;EAC3E,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,SAAS;EAChC,KAAK,IAAI,EAAE;EACX,OAAO,KAAK,QAAQ,OAAO,KAAK,IAAI;GAAE;GAAI,OAAO,OAAO;EAAM,IAAI,EAAE,GAAG,CAAC;CAC1E;CACA,OAAO;AACT;AAEA,IAAa,cAAc,OAAgC,KAAa,QACrE,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