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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/code/code-editor-block.js.map +1 -1
  2. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
  3. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/collaboration/binding.js +344 -42
  5. package/dist/collaboration/binding.js.map +1 -1
  6. package/dist/collaboration/index.js +30 -10
  7. package/dist/collaboration/index.js.map +1 -1
  8. package/dist/components/block-handle.js.map +1 -1
  9. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  11. package/dist/components/bubble-toolbar.js.map +1 -1
  12. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
  13. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  14. package/dist/components/comment-card.js.map +1 -1
  15. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
  16. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
  17. package/dist/core/convert.js +3 -3
  18. package/dist/core/convert.js.map +1 -1
  19. package/dist/core/editor.js +2 -1
  20. package/dist/core/editor.js.map +1 -1
  21. package/dist/core/plugins.js +108 -5
  22. package/dist/core/plugins.js.map +1 -1
  23. package/dist/core/prepare.js +12 -5
  24. package/dist/core/prepare.js.map +1 -1
  25. package/dist/dom.js +6 -1
  26. package/dist/dom.js.map +1 -1
  27. package/dist/extensions/align/align-menu.js.map +1 -1
  28. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
  29. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  30. package/dist/extensions/callout/html.js +5 -4
  31. package/dist/extensions/callout/html.js.map +1 -1
  32. package/dist/extensions/colors/color-menu.js.map +1 -1
  33. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
  34. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  35. package/dist/extensions/list-html.js +1 -1
  36. package/dist/extensions/list-html.js.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/markdown/index.js +2 -2
  39. package/dist/markdown/index.js.map +1 -1
  40. package/dist/style.css +1 -1
  41. package/dist/style.js +0 -1
  42. package/dist/types/collaboration/binding.d.ts +8 -0
  43. package/dist/types/collaboration/index.d.ts +36 -4
  44. package/dist/types/core/convert.d.ts +10 -2
  45. package/dist/types/core/plugins.d.ts +9 -0
  46. package/dist/types/core/prepare.d.ts +16 -2
  47. package/dist/types/dom.d.ts +2 -0
  48. package/dist/types/index.d.ts +2 -1
  49. package/dist/types/markdown/index.d.ts +8 -1
  50. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"bubble-toolbar.js","names":["_sfc_main"],"sources":["../../src/components/bubble-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, ChevronDownIcon, LinkIcon, MessagePlusIcon, UnlinkIcon } from '@dou-ui/icons'\nimport {\n DouButton,\n DouDropdown,\n DouDropdownItem,\n DouInput,\n DouToggle,\n DouToggleGroup,\n DouToolbar,\n DouToolbarSeparator,\n DouTooltip,\n isComposing,\n useFloating,\n useZIndex,\n type ToggleValue,\n type VirtualElement,\n} from 'dou-ui'\nimport { toggleMark } from 'prosemirror-commands'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n nextTick,\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 { getBlockSelection } from '../core/block-selection'\nimport { blockAround } from '../core/blocks'\nimport { setBlockType } from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { isSafeHref } from '../core/schema'\nimport { editorKey, provideToolbarMenus } from '../editor'\n\nconst { view, state, focused, dragging, messages, kit, comments } = inject(editorKey)!\nconst panel = useTemplateRef<HTMLElement>('panel')\n\n// while the pointer is down the selection is still being made\nconst pressing = shallowRef(false)\nconst menuOpen = shallowRef(false)\n// the extensions' menus keep the toolbar too\nconst toolbarMenus = provideToolbarMenus()\n// so does the focus in the toolbar, e.g. back on a menu's button after Escape\nconst panelFocused = shallowRef(false)\nwatch(focused, (value) => value && (panelFocused.value = false))\nfunction onPanelFocusOut(event: FocusEvent) {\n if (!panel.value?.contains(event.relatedTarget as Node | null)) panelFocused.value = false\n}\nfunction onPanelKeyDown(event: KeyboardEvent) {\n if (event.key !== 'Escape' || linking.value || event.defaultPrevented) return\n event.preventDefault()\n view.value?.focus()\n}\nconst linking = shallowRef<{ from: number; to: number } | null>(null)\nconst href = shallowRef('')\nconst linkInput = useTemplateRef<InstanceType<typeof DouInput>>('linkInput')\n\nconst formattable = computed(() => {\n const current = state.value\n if (!current || getBlockSelection(current)) return false\n const { selection } = current\n if (!(selection instanceof TextSelection) || selection.empty) return false\n // nothing to format in code, or across a divider only\n let text = false\n current.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !node.type.spec.code) text = true\n return !text\n })\n return text\n})\n\nconst open = computed(\n () =>\n !!linking.value ||\n menuOpen.value ||\n [...toolbarMenus].some((menu) => menu.value) ||\n panelFocused.value ||\n (focused.value && formattable.value && !pressing.value && !dragging.value),\n)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const range = linking.value ?? current?.state.selection\n if (!current || !range) return new DOMRect()\n const start = current.coordsAtPos(range.from, 1)\n const end = current.coordsAtPos(range.to, -1)\n // a selection over several lines: centre on the first one\n const sameLine = Math.abs(start.top - end.top) < 4\n const left = sameLine ? start.left : start.left\n const right = sameLine\n ? end.right\n : Math.max(start.left + 1, current.dom.getBoundingClientRect().right)\n return new DOMRect(left, start.top, Math.max(1, right - left), start.bottom - start.top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'top',\n offset: 8,\n})\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button === 0 && view.value?.dom.contains(event.target as Node)) pressing.value = true\n}\nfunction onPointerUp() {\n if (pressing.value) pressing.value = false\n}\n/*\n * A menu opened with the mouse leaves the focus in the text: until it\n * closes, Escape closes it and the arrow keys and Enter go into it,\n * instead of acting on the text.\n */\nfunction onKeyDown(event: KeyboardEvent) {\n if (!view.value?.dom.contains(event.target as Node)) return\n const trigger = panel.value?.querySelector<HTMLElement>('[aria-expanded=\"true\"][aria-controls]')\n if (!trigger) return\n const menu = document.getElementById(trigger.getAttribute('aria-controls')!)\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n menuOpen.value = false\n for (const item of toolbarMenus) item.value = false\n return\n }\n if (!menu || !['ArrowDown', 'ArrowUp', 'Home', 'End', 'Enter'].includes(event.key)) return\n event.preventDefault()\n event.stopPropagation()\n const items = Array.from(\n menu.querySelectorAll<HTMLElement>('[role^=\"menuitem\"]:not([aria-disabled=\"true\"])'),\n )\n const last = event.key === 'ArrowUp' || event.key === 'End'\n ;(last ? items.at(-1) : items[0])?.focus()\n}\n\nonMounted(() => {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('pointerup', onPointerUp, true)\n document.addEventListener('keydown', onKeyDown, true)\n})\nonBeforeUnmount(() => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('pointerup', onPointerUp, true)\n document.removeEventListener('keydown', onKeyDown, true)\n})\n\n/* marks */\n\nconst schema = kit.schema\nconst marks = kit.formats.filter((format) => schema.marks[format.mark])\n\nconst active = computed<ToggleValue[]>(() => {\n const current = state.value\n if (!current) return []\n const { from, to } = current.selection\n return marks\n .filter((mark) => current.doc.rangeHasMark(from, to, schema.marks[mark.mark]!))\n .map((mark) => mark.mark)\n})\n\nfunction onMarks(value: ToggleValue | ToggleValue[] | null) {\n const pressed = Array.isArray(value) ? value : []\n const changed = marks.find(\n (mark) => pressed.includes(mark.mark) !== active.value.includes(mark.mark),\n )\n const current = view.value\n if (!changed || !current) return\n toggleMark(schema.marks[changed.mark]!)(current.state, current.dispatch)\n}\n\n/* turning the block into another type */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst currentBlock = computed(() => {\n const current = state.value\n const info = current && blockAround(current.selection.$from)\n return info ? blockFromNode(info.node) : null\n})\n// text inside a table cell keeps its cell; only whole blocks change type\nconst turnable = computed(() => {\n const $from = state.value?.selection.$from\n return !!$from && $from.depth > 0 && $from.node($from.depth - 1).type.name === 'block'\n})\nconst currentOption = computed(() => {\n const block = currentBlock.value\n return block\n ? turnOptions.find((option) => isCurrent(option, block.type, block.props))\n : undefined\n})\n\nfunction turnInto(option: BlockOption) {\n const current = view.value\n if (!current) return\n setBlockType(option.type, option.props)(current.state, current.dispatch)\n requestAnimationFrame(() => current.focus())\n}\n\n/* links */\n\nconst linkMark = schema.marks.link\nconst currentHref = computed(() => {\n const current = state.value\n if (!current) return ''\n const { from, to } = current.selection\n let found = ''\n current.doc.nodesBetween(from, to, (node) => {\n const mark = linkMark?.isInSet(node.marks)\n if (mark) found ||= mark.attrs.href as string\n })\n return found\n})\n\n/** `Mod+K` and the link button: edit the link of the selected text. */\nfunction editLink(): boolean {\n const current = view.value\n if (!current || !linkMark || !formattable.value) return false\n const { from, to } = current.state.selection\n linking.value = { from, to }\n href.value = currentHref.value\n void nextTick(() => linkInput.value?.focus())\n return true\n}\n\n/** `example.com` becomes `https://example.com`; other relative links stay. */\nfunction normalise(value: string): string {\n const text = value.trim()\n if (/^[\\w-]+(\\.[\\w-]+)+(?:[/?#:]|$)/.test(text) && !text.includes(' ')) return `https://${text}`\n return text\n}\n\nfunction applyLink() {\n const current = view.value\n const range = linking.value\n if (!current || !range || !linkMark) return\n const value = normalise(href.value)\n const tr = current.state.tr.removeMark(range.from, range.to, linkMark)\n if (value && isSafeHref(value)) tr.addMark(range.from, range.to, linkMark.create({ href: value }))\n current.dispatch(tr)\n closeLink()\n}\n\nfunction removeLink() {\n href.value = ''\n applyLink()\n}\n\nfunction closeLink() {\n const current = view.value\n const range = linking.value\n linking.value = null\n if (!current) return\n if (range)\n current.dispatch(\n current.state.tr.setSelection(TextSelection.create(current.state.doc, range.from, range.to)),\n )\n current.focus()\n}\n\nfunction onLinkKey(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter') {\n event.preventDefault()\n applyLink()\n } else if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n closeLink()\n }\n}\n\nfunction onLinkBlur(event: FocusEvent) {\n // leaving for anywhere but the toolbar ends editing without saving\n if (!panel.value?.contains(event.relatedTarget as Node)) linking.value = null\n}\n\ndefineExpose({ editLink })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-bubble\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown=\"!linking && $event.preventDefault()\"\n @focusin=\"panelFocused = true\"\n @focusout=\"onPanelFocusOut\"\n @keydown=\"onPanelKeyDown\"\n >\n <div v-if=\"linking\" class=\"dou-editor-bubble__link\">\n <DouInput\n ref=\"linkInput\"\n v-model=\"href\"\n size=\"sm\"\n :placeholder=\"messages.linkPlaceholder\"\n :aria-label=\"messages.link\"\n @keydown=\"onLinkKey\"\n @blur=\"onLinkBlur\"\n >\n <template #prefix><LinkIcon /></template>\n </DouInput>\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.applyLink\"\n @mousedown.prevent\n @click=\"applyLink\"\n >\n <CheckIcon />\n </DouButton>\n <DouButton\n v-if=\"currentHref\"\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.removeLink\"\n @mousedown.prevent\n @click=\"removeLink\"\n >\n <UnlinkIcon />\n </DouButton>\n </div>\n <DouToolbar v-else size=\"sm\" :aria-label=\"messages.formatting\">\n <DouDropdown\n v-if=\"turnable\"\n v-model:open=\"menuOpen\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <DouButton size=\"sm\" variant=\"ghost\" class=\"dou-editor-bubble__type\">\n {{ currentOption ? labelOf(currentOption.label, messages) : messages.turnInto }}\n <template #trailing><ChevronDownIcon /></template>\n </DouButton>\n <template #menu>\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=\"option === currentOption\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </template>\n </DouDropdown>\n <DouToolbarSeparator v-if=\"turnable && marks.length\" />\n <DouToggleGroup\n v-if=\"marks.length\"\n type=\"multiple\"\n :model-value=\"active\"\n :aria-label=\"messages.formatting\"\n @update:model-value=\"onMarks\"\n >\n <DouTooltip\n v-for=\"mark in marks\"\n :key=\"mark.mark\"\n :content=\"labelOf(mark.label, messages)\"\n :shortcut=\"mark.hotkey\"\n placement=\"bottom\"\n >\n <DouToggle :value=\"mark.mark\" :aria-label=\"labelOf(mark.label, messages)\">\n <component :is=\"mark.icon\" />\n </DouToggle>\n </DouTooltip>\n </DouToggleGroup>\n <template v-if=\"kit.toolbar.length\">\n <DouToolbarSeparator v-if=\"marks.length\" />\n <component :is=\"control\" v-for=\"(control, index) in kit.toolbar\" :key=\"index\" />\n </template>\n <DouToolbarSeparator v-if=\"linkMark\" />\n <DouTooltip v-if=\"linkMark\" :content=\"messages.link\" shortcut=\"mod+k\" placement=\"bottom\">\n <DouToggle\n :pressed=\"!!currentHref\"\n :aria-label=\"messages.link\"\n @update:pressed=\"editLink\"\n >\n <LinkIcon />\n </DouToggle>\n </DouTooltip>\n <template v-if=\"comments.writable.value\">\n <DouToolbarSeparator />\n <DouTooltip :content=\"messages.comment\" shortcut=\"mod+alt+m\" placement=\"bottom\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.comment\"\n @click=\"comments.start()\"\n >\n <MessagePlusIcon />\n </DouButton>\n </DouTooltip>\n </template>\n </DouToolbar>\n </div>\n </Transition>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"bubble-toolbar.js","names":["_sfc_main"],"sources":["../../src/components/bubble-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, ChevronDownIcon, LinkIcon, MessagePlusIcon, UnlinkIcon } from '@dou-ui/icons'\nimport {\n DouButton,\n DouDropdown,\n DouDropdownItem,\n DouInput,\n DouToggle,\n DouToggleGroup,\n DouToolbar,\n DouToolbarSeparator,\n DouTooltip,\n isComposing,\n useFloating,\n useZIndex,\n type ToggleValue,\n type VirtualElement,\n} from 'dou-ui'\nimport { toggleMark } from 'prosemirror-commands'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { columnRight } from '../dom'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport { getBlockSelection } from '../core/block-selection'\nimport { blockAround } from '../core/blocks'\nimport { setBlockType } from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { isSafeHref } from '../core/schema'\nimport { editorKey, provideToolbarMenus } from '../editor'\n\nconst { view, state, focused, dragging, messages, kit, comments } = inject(editorKey)!\nconst panel = useTemplateRef<HTMLElement>('panel')\n\n// while the pointer is down the selection is still being made\nconst pressing = shallowRef(false)\nconst menuOpen = shallowRef(false)\n// the extensions' menus keep the toolbar too\nconst toolbarMenus = provideToolbarMenus()\n// so does the focus in the toolbar, e.g. back on a menu's button after Escape\nconst panelFocused = shallowRef(false)\nwatch(focused, (value) => value && (panelFocused.value = false))\nfunction onPanelFocusOut(event: FocusEvent) {\n if (!panel.value?.contains(event.relatedTarget as Node | null)) panelFocused.value = false\n}\nfunction onPanelKeyDown(event: KeyboardEvent) {\n if (event.key !== 'Escape' || linking.value || event.defaultPrevented) return\n event.preventDefault()\n view.value?.focus()\n}\nconst linking = shallowRef<{ from: number; to: number } | null>(null)\nconst href = shallowRef('')\nconst linkInput = useTemplateRef<InstanceType<typeof DouInput>>('linkInput')\n\nconst formattable = computed(() => {\n const current = state.value\n if (!current || getBlockSelection(current)) return false\n const { selection } = current\n if (!(selection instanceof TextSelection) || selection.empty) return false\n // nothing to format in code, or across a divider only\n let text = false\n current.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !node.type.spec.code) text = true\n return !text\n })\n return text\n})\n\nconst open = computed(\n () =>\n !!linking.value ||\n menuOpen.value ||\n [...toolbarMenus].some((menu) => menu.value) ||\n panelFocused.value ||\n (focused.value && formattable.value && !pressing.value && !dragging.value),\n)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const range = linking.value ?? current?.state.selection\n if (!current || !range) return new DOMRect()\n const start = current.coordsAtPos(range.from, 1)\n const end = current.coordsAtPos(range.to, -1)\n // a selection over several lines: centre on the first one\n const sameLine = Math.abs(start.top - end.top) < 4\n const left = sameLine ? start.left : start.left\n const right = sameLine ? end.right : Math.max(start.left + 1, columnRight(current.dom))\n return new DOMRect(left, start.top, Math.max(1, right - left), start.bottom - start.top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'top',\n offset: 8,\n})\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button === 0 && view.value?.dom.contains(event.target as Node)) pressing.value = true\n}\nfunction onPointerUp() {\n if (pressing.value) pressing.value = false\n}\n/*\n * A menu opened with the mouse leaves the focus in the text: until it\n * closes, Escape closes it and the arrow keys and Enter go into it,\n * instead of acting on the text.\n */\nfunction onKeyDown(event: KeyboardEvent) {\n if (!view.value?.dom.contains(event.target as Node)) return\n const trigger = panel.value?.querySelector<HTMLElement>('[aria-expanded=\"true\"][aria-controls]')\n if (!trigger) return\n const menu = document.getElementById(trigger.getAttribute('aria-controls')!)\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n menuOpen.value = false\n for (const item of toolbarMenus) item.value = false\n return\n }\n if (!menu || !['ArrowDown', 'ArrowUp', 'Home', 'End', 'Enter'].includes(event.key)) return\n event.preventDefault()\n event.stopPropagation()\n const items = Array.from(\n menu.querySelectorAll<HTMLElement>('[role^=\"menuitem\"]:not([aria-disabled=\"true\"])'),\n )\n const last = event.key === 'ArrowUp' || event.key === 'End'\n ;(last ? items.at(-1) : items[0])?.focus()\n}\n\nonMounted(() => {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('pointerup', onPointerUp, true)\n document.addEventListener('keydown', onKeyDown, true)\n})\nonBeforeUnmount(() => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('pointerup', onPointerUp, true)\n document.removeEventListener('keydown', onKeyDown, true)\n})\n\n/* marks */\n\nconst schema = kit.schema\nconst marks = kit.formats.filter((format) => schema.marks[format.mark])\n\nconst active = computed<ToggleValue[]>(() => {\n const current = state.value\n if (!current) return []\n const { from, to } = current.selection\n return marks\n .filter((mark) => current.doc.rangeHasMark(from, to, schema.marks[mark.mark]!))\n .map((mark) => mark.mark)\n})\n\nfunction onMarks(value: ToggleValue | ToggleValue[] | null) {\n const pressed = Array.isArray(value) ? value : []\n const changed = marks.find(\n (mark) => pressed.includes(mark.mark) !== active.value.includes(mark.mark),\n )\n const current = view.value\n if (!changed || !current) return\n toggleMark(schema.marks[changed.mark]!)(current.state, current.dispatch)\n}\n\n/* turning the block into another type */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst currentBlock = computed(() => {\n const current = state.value\n const info = current && blockAround(current.selection.$from)\n return info ? blockFromNode(info.node) : null\n})\n// text inside a table cell keeps its cell; only whole blocks change type\nconst turnable = computed(() => {\n const $from = state.value?.selection.$from\n return !!$from && $from.depth > 0 && $from.node($from.depth - 1).type.name === 'block'\n})\nconst currentOption = computed(() => {\n const block = currentBlock.value\n return block\n ? turnOptions.find((option) => isCurrent(option, block.type, block.props))\n : undefined\n})\n\nfunction turnInto(option: BlockOption) {\n const current = view.value\n if (!current) return\n setBlockType(option.type, option.props)(current.state, current.dispatch)\n requestAnimationFrame(() => current.focus())\n}\n\n/* links */\n\nconst linkMark = schema.marks.link\nconst currentHref = computed(() => {\n const current = state.value\n if (!current) return ''\n const { from, to } = current.selection\n let found = ''\n current.doc.nodesBetween(from, to, (node) => {\n const mark = linkMark?.isInSet(node.marks)\n if (mark) found ||= mark.attrs.href as string\n })\n return found\n})\n\n/** `Mod+K` and the link button: edit the link of the selected text. */\nfunction editLink(): boolean {\n const current = view.value\n if (!current || !linkMark || !formattable.value) return false\n const { from, to } = current.state.selection\n linking.value = { from, to }\n href.value = currentHref.value\n void nextTick(() => linkInput.value?.focus())\n return true\n}\n\n/** `example.com` becomes `https://example.com`; other relative links stay. */\nfunction normalise(value: string): string {\n const text = value.trim()\n if (/^[\\w-]+(\\.[\\w-]+)+(?:[/?#:]|$)/.test(text) && !text.includes(' ')) return `https://${text}`\n return text\n}\n\nfunction applyLink() {\n const current = view.value\n const range = linking.value\n if (!current || !range || !linkMark) return\n const value = normalise(href.value)\n const tr = current.state.tr.removeMark(range.from, range.to, linkMark)\n if (value && isSafeHref(value)) tr.addMark(range.from, range.to, linkMark.create({ href: value }))\n current.dispatch(tr)\n closeLink()\n}\n\nfunction removeLink() {\n href.value = ''\n applyLink()\n}\n\nfunction closeLink() {\n const current = view.value\n const range = linking.value\n linking.value = null\n if (!current) return\n if (range)\n current.dispatch(\n current.state.tr.setSelection(TextSelection.create(current.state.doc, range.from, range.to)),\n )\n current.focus()\n}\n\nfunction onLinkKey(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter') {\n event.preventDefault()\n applyLink()\n } else if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n closeLink()\n }\n}\n\nfunction onLinkBlur(event: FocusEvent) {\n // leaving for anywhere but the toolbar ends editing without saving\n if (!panel.value?.contains(event.relatedTarget as Node)) linking.value = null\n}\n\ndefineExpose({ editLink })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-bubble\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown=\"!linking && $event.preventDefault()\"\n @focusin=\"panelFocused = true\"\n @focusout=\"onPanelFocusOut\"\n @keydown=\"onPanelKeyDown\"\n >\n <div v-if=\"linking\" class=\"dou-editor-bubble__link\">\n <DouInput\n ref=\"linkInput\"\n v-model=\"href\"\n size=\"sm\"\n :placeholder=\"messages.linkPlaceholder\"\n :aria-label=\"messages.link\"\n @keydown=\"onLinkKey\"\n @blur=\"onLinkBlur\"\n >\n <template #prefix><LinkIcon /></template>\n </DouInput>\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.applyLink\"\n @mousedown.prevent\n @click=\"applyLink\"\n >\n <CheckIcon />\n </DouButton>\n <DouButton\n v-if=\"currentHref\"\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.removeLink\"\n @mousedown.prevent\n @click=\"removeLink\"\n >\n <UnlinkIcon />\n </DouButton>\n </div>\n <DouToolbar v-else size=\"sm\" :aria-label=\"messages.formatting\">\n <DouDropdown\n v-if=\"turnable\"\n v-model:open=\"menuOpen\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <DouButton size=\"sm\" variant=\"ghost\" class=\"dou-editor-bubble__type\">\n {{ currentOption ? labelOf(currentOption.label, messages) : messages.turnInto }}\n <template #trailing><ChevronDownIcon /></template>\n </DouButton>\n <template #menu>\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=\"option === currentOption\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </template>\n </DouDropdown>\n <DouToolbarSeparator v-if=\"turnable && marks.length\" />\n <DouToggleGroup\n v-if=\"marks.length\"\n type=\"multiple\"\n :model-value=\"active\"\n :aria-label=\"messages.formatting\"\n @update:model-value=\"onMarks\"\n >\n <DouTooltip\n v-for=\"mark in marks\"\n :key=\"mark.mark\"\n :content=\"labelOf(mark.label, messages)\"\n :shortcut=\"mark.hotkey\"\n placement=\"bottom\"\n >\n <DouToggle :value=\"mark.mark\" :aria-label=\"labelOf(mark.label, messages)\">\n <component :is=\"mark.icon\" />\n </DouToggle>\n </DouTooltip>\n </DouToggleGroup>\n <template v-if=\"kit.toolbar.length\">\n <DouToolbarSeparator v-if=\"marks.length\" />\n <component :is=\"control\" v-for=\"(control, index) in kit.toolbar\" :key=\"index\" />\n </template>\n <DouToolbarSeparator v-if=\"linkMark\" />\n <DouTooltip v-if=\"linkMark\" :content=\"messages.link\" shortcut=\"mod+k\" placement=\"bottom\">\n <DouToggle\n :pressed=\"!!currentHref\"\n :aria-label=\"messages.link\"\n @update:pressed=\"editLink\"\n >\n <LinkIcon />\n </DouToggle>\n </DouTooltip>\n <template v-if=\"comments.writable.value\">\n <DouToolbarSeparator />\n <DouTooltip :content=\"messages.comment\" shortcut=\"mod+alt+m\" placement=\"bottom\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.comment\"\n @click=\"comments.start()\"\n >\n <MessagePlusIcon />\n </DouButton>\n </DouTooltip>\n </template>\n </DouToolbar>\n </div>\n </Transition>\n</template>\n"],"mappings":""}
@@ -5,6 +5,7 @@ import { isCurrent } from "../catalog.js";
5
5
  import { blockAround } from "../core/blocks.js";
6
6
  import { setBlockType } from "../core/commands.js";
7
7
  import { getBlockSelection } from "../core/block-selection.js";
8
+ import { columnRight } from "../dom.js";
8
9
  import { editorKey, provideToolbarMenus } from "../editor.js";
9
10
  import { DouButton, DouDropdown, DouDropdownItem, DouInput, DouToggle, DouToggleGroup, DouToolbar, DouToolbarSeparator, DouTooltip, isComposing, useFloating, useZIndex } from "dou-ui";
10
11
  import { Fragment, Transition, computed, createBlock, createCommentVNode, createElementBlock, createSlots, createTextVNode, createVNode, defineComponent, inject, nextTick, normalizeStyle, onBeforeUnmount, onMounted, openBlock, renderList, resolveDynamicComponent, shallowRef, toDisplayString, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
@@ -59,7 +60,7 @@ var bubble_toolbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
59
60
  const end = current.coordsAtPos(range.to, -1);
60
61
  const sameLine = Math.abs(start.top - end.top) < 4;
61
62
  const left = sameLine ? start.left : start.left;
62
- const right = sameLine ? end.right : Math.max(start.left + 1, current.dom.getBoundingClientRect().right);
63
+ const right = sameLine ? end.right : Math.max(start.left + 1, columnRight(current.dom));
63
64
  return new DOMRect(left, start.top, Math.max(1, right - left), start.bottom - start.top);
64
65
  } };
65
66
  const { style, placement, update } = useFloating(() => open.value ? anchor : null, panel, {
@@ -1 +1 @@
1
- {"version":3,"file":"bubble-toolbar.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_Transition","_withCtx","_createElementBlock","_normalizeStyle","_unref","_createVNode","_withModifiers","_createCommentVNode","_Fragment","_renderList","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString"],"sources":["../../src/components/bubble-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, ChevronDownIcon, LinkIcon, MessagePlusIcon, UnlinkIcon } from '@dou-ui/icons'\nimport {\n DouButton,\n DouDropdown,\n DouDropdownItem,\n DouInput,\n DouToggle,\n DouToggleGroup,\n DouToolbar,\n DouToolbarSeparator,\n DouTooltip,\n isComposing,\n useFloating,\n useZIndex,\n type ToggleValue,\n type VirtualElement,\n} from 'dou-ui'\nimport { toggleMark } from 'prosemirror-commands'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n nextTick,\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 { getBlockSelection } from '../core/block-selection'\nimport { blockAround } from '../core/blocks'\nimport { setBlockType } from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { isSafeHref } from '../core/schema'\nimport { editorKey, provideToolbarMenus } from '../editor'\n\nconst { view, state, focused, dragging, messages, kit, comments } = inject(editorKey)!\nconst panel = useTemplateRef<HTMLElement>('panel')\n\n// while the pointer is down the selection is still being made\nconst pressing = shallowRef(false)\nconst menuOpen = shallowRef(false)\n// the extensions' menus keep the toolbar too\nconst toolbarMenus = provideToolbarMenus()\n// so does the focus in the toolbar, e.g. back on a menu's button after Escape\nconst panelFocused = shallowRef(false)\nwatch(focused, (value) => value && (panelFocused.value = false))\nfunction onPanelFocusOut(event: FocusEvent) {\n if (!panel.value?.contains(event.relatedTarget as Node | null)) panelFocused.value = false\n}\nfunction onPanelKeyDown(event: KeyboardEvent) {\n if (event.key !== 'Escape' || linking.value || event.defaultPrevented) return\n event.preventDefault()\n view.value?.focus()\n}\nconst linking = shallowRef<{ from: number; to: number } | null>(null)\nconst href = shallowRef('')\nconst linkInput = useTemplateRef<InstanceType<typeof DouInput>>('linkInput')\n\nconst formattable = computed(() => {\n const current = state.value\n if (!current || getBlockSelection(current)) return false\n const { selection } = current\n if (!(selection instanceof TextSelection) || selection.empty) return false\n // nothing to format in code, or across a divider only\n let text = false\n current.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !node.type.spec.code) text = true\n return !text\n })\n return text\n})\n\nconst open = computed(\n () =>\n !!linking.value ||\n menuOpen.value ||\n [...toolbarMenus].some((menu) => menu.value) ||\n panelFocused.value ||\n (focused.value && formattable.value && !pressing.value && !dragging.value),\n)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const range = linking.value ?? current?.state.selection\n if (!current || !range) return new DOMRect()\n const start = current.coordsAtPos(range.from, 1)\n const end = current.coordsAtPos(range.to, -1)\n // a selection over several lines: centre on the first one\n const sameLine = Math.abs(start.top - end.top) < 4\n const left = sameLine ? start.left : start.left\n const right = sameLine\n ? end.right\n : Math.max(start.left + 1, current.dom.getBoundingClientRect().right)\n return new DOMRect(left, start.top, Math.max(1, right - left), start.bottom - start.top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'top',\n offset: 8,\n})\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button === 0 && view.value?.dom.contains(event.target as Node)) pressing.value = true\n}\nfunction onPointerUp() {\n if (pressing.value) pressing.value = false\n}\n/*\n * A menu opened with the mouse leaves the focus in the text: until it\n * closes, Escape closes it and the arrow keys and Enter go into it,\n * instead of acting on the text.\n */\nfunction onKeyDown(event: KeyboardEvent) {\n if (!view.value?.dom.contains(event.target as Node)) return\n const trigger = panel.value?.querySelector<HTMLElement>('[aria-expanded=\"true\"][aria-controls]')\n if (!trigger) return\n const menu = document.getElementById(trigger.getAttribute('aria-controls')!)\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n menuOpen.value = false\n for (const item of toolbarMenus) item.value = false\n return\n }\n if (!menu || !['ArrowDown', 'ArrowUp', 'Home', 'End', 'Enter'].includes(event.key)) return\n event.preventDefault()\n event.stopPropagation()\n const items = Array.from(\n menu.querySelectorAll<HTMLElement>('[role^=\"menuitem\"]:not([aria-disabled=\"true\"])'),\n )\n const last = event.key === 'ArrowUp' || event.key === 'End'\n ;(last ? items.at(-1) : items[0])?.focus()\n}\n\nonMounted(() => {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('pointerup', onPointerUp, true)\n document.addEventListener('keydown', onKeyDown, true)\n})\nonBeforeUnmount(() => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('pointerup', onPointerUp, true)\n document.removeEventListener('keydown', onKeyDown, true)\n})\n\n/* marks */\n\nconst schema = kit.schema\nconst marks = kit.formats.filter((format) => schema.marks[format.mark])\n\nconst active = computed<ToggleValue[]>(() => {\n const current = state.value\n if (!current) return []\n const { from, to } = current.selection\n return marks\n .filter((mark) => current.doc.rangeHasMark(from, to, schema.marks[mark.mark]!))\n .map((mark) => mark.mark)\n})\n\nfunction onMarks(value: ToggleValue | ToggleValue[] | null) {\n const pressed = Array.isArray(value) ? value : []\n const changed = marks.find(\n (mark) => pressed.includes(mark.mark) !== active.value.includes(mark.mark),\n )\n const current = view.value\n if (!changed || !current) return\n toggleMark(schema.marks[changed.mark]!)(current.state, current.dispatch)\n}\n\n/* turning the block into another type */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst currentBlock = computed(() => {\n const current = state.value\n const info = current && blockAround(current.selection.$from)\n return info ? blockFromNode(info.node) : null\n})\n// text inside a table cell keeps its cell; only whole blocks change type\nconst turnable = computed(() => {\n const $from = state.value?.selection.$from\n return !!$from && $from.depth > 0 && $from.node($from.depth - 1).type.name === 'block'\n})\nconst currentOption = computed(() => {\n const block = currentBlock.value\n return block\n ? turnOptions.find((option) => isCurrent(option, block.type, block.props))\n : undefined\n})\n\nfunction turnInto(option: BlockOption) {\n const current = view.value\n if (!current) return\n setBlockType(option.type, option.props)(current.state, current.dispatch)\n requestAnimationFrame(() => current.focus())\n}\n\n/* links */\n\nconst linkMark = schema.marks.link\nconst currentHref = computed(() => {\n const current = state.value\n if (!current) return ''\n const { from, to } = current.selection\n let found = ''\n current.doc.nodesBetween(from, to, (node) => {\n const mark = linkMark?.isInSet(node.marks)\n if (mark) found ||= mark.attrs.href as string\n })\n return found\n})\n\n/** `Mod+K` and the link button: edit the link of the selected text. */\nfunction editLink(): boolean {\n const current = view.value\n if (!current || !linkMark || !formattable.value) return false\n const { from, to } = current.state.selection\n linking.value = { from, to }\n href.value = currentHref.value\n void nextTick(() => linkInput.value?.focus())\n return true\n}\n\n/** `example.com` becomes `https://example.com`; other relative links stay. */\nfunction normalise(value: string): string {\n const text = value.trim()\n if (/^[\\w-]+(\\.[\\w-]+)+(?:[/?#:]|$)/.test(text) && !text.includes(' ')) return `https://${text}`\n return text\n}\n\nfunction applyLink() {\n const current = view.value\n const range = linking.value\n if (!current || !range || !linkMark) return\n const value = normalise(href.value)\n const tr = current.state.tr.removeMark(range.from, range.to, linkMark)\n if (value && isSafeHref(value)) tr.addMark(range.from, range.to, linkMark.create({ href: value }))\n current.dispatch(tr)\n closeLink()\n}\n\nfunction removeLink() {\n href.value = ''\n applyLink()\n}\n\nfunction closeLink() {\n const current = view.value\n const range = linking.value\n linking.value = null\n if (!current) return\n if (range)\n current.dispatch(\n current.state.tr.setSelection(TextSelection.create(current.state.doc, range.from, range.to)),\n )\n current.focus()\n}\n\nfunction onLinkKey(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter') {\n event.preventDefault()\n applyLink()\n } else if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n closeLink()\n }\n}\n\nfunction onLinkBlur(event: FocusEvent) {\n // leaving for anywhere but the toolbar ends editing without saving\n if (!panel.value?.contains(event.relatedTarget as Node)) linking.value = null\n}\n\ndefineExpose({ editLink })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-bubble\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown=\"!linking && $event.preventDefault()\"\n @focusin=\"panelFocused = true\"\n @focusout=\"onPanelFocusOut\"\n @keydown=\"onPanelKeyDown\"\n >\n <div v-if=\"linking\" class=\"dou-editor-bubble__link\">\n <DouInput\n ref=\"linkInput\"\n v-model=\"href\"\n size=\"sm\"\n :placeholder=\"messages.linkPlaceholder\"\n :aria-label=\"messages.link\"\n @keydown=\"onLinkKey\"\n @blur=\"onLinkBlur\"\n >\n <template #prefix><LinkIcon /></template>\n </DouInput>\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.applyLink\"\n @mousedown.prevent\n @click=\"applyLink\"\n >\n <CheckIcon />\n </DouButton>\n <DouButton\n v-if=\"currentHref\"\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.removeLink\"\n @mousedown.prevent\n @click=\"removeLink\"\n >\n <UnlinkIcon />\n </DouButton>\n </div>\n <DouToolbar v-else size=\"sm\" :aria-label=\"messages.formatting\">\n <DouDropdown\n v-if=\"turnable\"\n v-model:open=\"menuOpen\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <DouButton size=\"sm\" variant=\"ghost\" class=\"dou-editor-bubble__type\">\n {{ currentOption ? labelOf(currentOption.label, messages) : messages.turnInto }}\n <template #trailing><ChevronDownIcon /></template>\n </DouButton>\n <template #menu>\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=\"option === currentOption\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </template>\n </DouDropdown>\n <DouToolbarSeparator v-if=\"turnable && marks.length\" />\n <DouToggleGroup\n v-if=\"marks.length\"\n type=\"multiple\"\n :model-value=\"active\"\n :aria-label=\"messages.formatting\"\n @update:model-value=\"onMarks\"\n >\n <DouTooltip\n v-for=\"mark in marks\"\n :key=\"mark.mark\"\n :content=\"labelOf(mark.label, messages)\"\n :shortcut=\"mark.hotkey\"\n placement=\"bottom\"\n >\n <DouToggle :value=\"mark.mark\" :aria-label=\"labelOf(mark.label, messages)\">\n <component :is=\"mark.icon\" />\n </DouToggle>\n </DouTooltip>\n </DouToggleGroup>\n <template v-if=\"kit.toolbar.length\">\n <DouToolbarSeparator v-if=\"marks.length\" />\n <component :is=\"control\" v-for=\"(control, index) in kit.toolbar\" :key=\"index\" />\n </template>\n <DouToolbarSeparator v-if=\"linkMark\" />\n <DouTooltip v-if=\"linkMark\" :content=\"messages.link\" shortcut=\"mod+k\" placement=\"bottom\">\n <DouToggle\n :pressed=\"!!currentHref\"\n :aria-label=\"messages.link\"\n @update:pressed=\"editLink\"\n >\n <LinkIcon />\n </DouToggle>\n </DouTooltip>\n <template v-if=\"comments.writable.value\">\n <DouToolbarSeparator />\n <DouTooltip :content=\"messages.comment\" shortcut=\"mod+alt+m\" placement=\"bottom\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.comment\"\n @click=\"comments.start()\"\n >\n <MessagePlusIcon />\n </DouButton>\n </DouTooltip>\n </template>\n </DouToolbar>\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;EAuCA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,UAAU,KAAK,aAAa,OAAO,SAAS;EACpF,MAAM,QAAQ,eAA4B,OAAO;EAGjD,MAAM,WAAW,WAAW,KAAK;EACjC,MAAM,WAAW,WAAW,KAAK;EAEjC,MAAM,eAAe,oBAAoB;EAEzC,MAAM,eAAe,WAAW,KAAK;EACrC,MAAM,UAAU,UAAU,UAAU,aAAa,QAAQ,MAAM;EAC/D,SAAS,gBAAgB,OAAmB;GAC1C,IAAI,CAAC,MAAM,OAAO,SAAS,MAAM,aAA4B,GAAG,aAAa,QAAQ;EACvF;EACA,SAAS,eAAe,OAAsB;GAC5C,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S;OAAQ,WAAU;;OAC9E,SAAAH,cAMY,CANZI,YAMYD,MAAA,SAAA,GAAA;QALT,SAAO,CAAA,CAAI,YAAA;QACX,cAAYA,MAAA,QAAA,CAAQ,CAAC;QACrB,oBAAgB;;QAEjB,SAAAH,cAAY,CAAZI,YAAYD,MAAA,QAAA,CAAA,C;;;;;MAGAA,MAAA,QAAA,CAAQ,CAAC,SAAS,SAAlCN,UAAA,GAAAI,mBAYWM,UAAA,EAAA,KAAA,EAAA,GAAA,CAXTH,YAAuBD,MAAA,mBAAA,CAAA,GACvBC,YASaD,MAAA,UAAA,GAAA;OATA,SAASA,MAAA,QAAA,CAAQ,CAAC;OAAS,UAAS;OAAY,WAAU;;OACrE,SAAAH,cAOY,CAPZI,YAOYD,MAAA,SAAA,GAAA;QANV,MAAK;QACL,SAAQ;QACP,cAAYA,MAAA,QAAA,CAAQ,CAAC;QACrB,SAAK,OAAA,OAAA,OAAA,MAAA,WAAEA,MAAA,QAAA,CAAQ,CAAC,MAAK;;QAEtB,SAAAH,cAAmB,CAAnBI,YAAmBD,MAAA,eAAA,CAAA,C"}
1
+ {"version":3,"file":"bubble-toolbar.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_Transition","_withCtx","_createElementBlock","_normalizeStyle","_unref","_createVNode","_withModifiers","_createCommentVNode","_Fragment","_renderList","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString"],"sources":["../../src/components/bubble-toolbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, ChevronDownIcon, LinkIcon, MessagePlusIcon, UnlinkIcon } from '@dou-ui/icons'\nimport {\n DouButton,\n DouDropdown,\n DouDropdownItem,\n DouInput,\n DouToggle,\n DouToggleGroup,\n DouToolbar,\n DouToolbarSeparator,\n DouTooltip,\n isComposing,\n useFloating,\n useZIndex,\n type ToggleValue,\n type VirtualElement,\n} from 'dou-ui'\nimport { toggleMark } from 'prosemirror-commands'\nimport { TextSelection } from 'prosemirror-state'\nimport {\n computed,\n inject,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { isCurrent } from '../catalog'\nimport { columnRight } from '../dom'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport { getBlockSelection } from '../core/block-selection'\nimport { blockAround } from '../core/blocks'\nimport { setBlockType } from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { isSafeHref } from '../core/schema'\nimport { editorKey, provideToolbarMenus } from '../editor'\n\nconst { view, state, focused, dragging, messages, kit, comments } = inject(editorKey)!\nconst panel = useTemplateRef<HTMLElement>('panel')\n\n// while the pointer is down the selection is still being made\nconst pressing = shallowRef(false)\nconst menuOpen = shallowRef(false)\n// the extensions' menus keep the toolbar too\nconst toolbarMenus = provideToolbarMenus()\n// so does the focus in the toolbar, e.g. back on a menu's button after Escape\nconst panelFocused = shallowRef(false)\nwatch(focused, (value) => value && (panelFocused.value = false))\nfunction onPanelFocusOut(event: FocusEvent) {\n if (!panel.value?.contains(event.relatedTarget as Node | null)) panelFocused.value = false\n}\nfunction onPanelKeyDown(event: KeyboardEvent) {\n if (event.key !== 'Escape' || linking.value || event.defaultPrevented) return\n event.preventDefault()\n view.value?.focus()\n}\nconst linking = shallowRef<{ from: number; to: number } | null>(null)\nconst href = shallowRef('')\nconst linkInput = useTemplateRef<InstanceType<typeof DouInput>>('linkInput')\n\nconst formattable = computed(() => {\n const current = state.value\n if (!current || getBlockSelection(current)) return false\n const { selection } = current\n if (!(selection instanceof TextSelection) || selection.empty) return false\n // nothing to format in code, or across a divider only\n let text = false\n current.doc.nodesBetween(selection.from, selection.to, (node) => {\n if (node.isTextblock && !node.type.spec.code) text = true\n return !text\n })\n return text\n})\n\nconst open = computed(\n () =>\n !!linking.value ||\n menuOpen.value ||\n [...toolbarMenus].some((menu) => menu.value) ||\n panelFocused.value ||\n (focused.value && formattable.value && !pressing.value && !dragging.value),\n)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const range = linking.value ?? current?.state.selection\n if (!current || !range) return new DOMRect()\n const start = current.coordsAtPos(range.from, 1)\n const end = current.coordsAtPos(range.to, -1)\n // a selection over several lines: centre on the first one\n const sameLine = Math.abs(start.top - end.top) < 4\n const left = sameLine ? start.left : start.left\n const right = sameLine ? end.right : Math.max(start.left + 1, columnRight(current.dom))\n return new DOMRect(left, start.top, Math.max(1, right - left), start.bottom - start.top)\n },\n}\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'top',\n offset: 8,\n})\n// stacked like DouUI's own popups, above whatever opened before\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button === 0 && view.value?.dom.contains(event.target as Node)) pressing.value = true\n}\nfunction onPointerUp() {\n if (pressing.value) pressing.value = false\n}\n/*\n * A menu opened with the mouse leaves the focus in the text: until it\n * closes, Escape closes it and the arrow keys and Enter go into it,\n * instead of acting on the text.\n */\nfunction onKeyDown(event: KeyboardEvent) {\n if (!view.value?.dom.contains(event.target as Node)) return\n const trigger = panel.value?.querySelector<HTMLElement>('[aria-expanded=\"true\"][aria-controls]')\n if (!trigger) return\n const menu = document.getElementById(trigger.getAttribute('aria-controls')!)\n if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n menuOpen.value = false\n for (const item of toolbarMenus) item.value = false\n return\n }\n if (!menu || !['ArrowDown', 'ArrowUp', 'Home', 'End', 'Enter'].includes(event.key)) return\n event.preventDefault()\n event.stopPropagation()\n const items = Array.from(\n menu.querySelectorAll<HTMLElement>('[role^=\"menuitem\"]:not([aria-disabled=\"true\"])'),\n )\n const last = event.key === 'ArrowUp' || event.key === 'End'\n ;(last ? items.at(-1) : items[0])?.focus()\n}\n\nonMounted(() => {\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('pointerup', onPointerUp, true)\n document.addEventListener('keydown', onKeyDown, true)\n})\nonBeforeUnmount(() => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('pointerup', onPointerUp, true)\n document.removeEventListener('keydown', onKeyDown, true)\n})\n\n/* marks */\n\nconst schema = kit.schema\nconst marks = kit.formats.filter((format) => schema.marks[format.mark])\n\nconst active = computed<ToggleValue[]>(() => {\n const current = state.value\n if (!current) return []\n const { from, to } = current.selection\n return marks\n .filter((mark) => current.doc.rangeHasMark(from, to, schema.marks[mark.mark]!))\n .map((mark) => mark.mark)\n})\n\nfunction onMarks(value: ToggleValue | ToggleValue[] | null) {\n const pressed = Array.isArray(value) ? value : []\n const changed = marks.find(\n (mark) => pressed.includes(mark.mark) !== active.value.includes(mark.mark),\n )\n const current = view.value\n if (!changed || !current) return\n toggleMark(schema.marks[changed.mark]!)(current.state, current.dispatch)\n}\n\n/* turning the block into another type */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst currentBlock = computed(() => {\n const current = state.value\n const info = current && blockAround(current.selection.$from)\n return info ? blockFromNode(info.node) : null\n})\n// text inside a table cell keeps its cell; only whole blocks change type\nconst turnable = computed(() => {\n const $from = state.value?.selection.$from\n return !!$from && $from.depth > 0 && $from.node($from.depth - 1).type.name === 'block'\n})\nconst currentOption = computed(() => {\n const block = currentBlock.value\n return block\n ? turnOptions.find((option) => isCurrent(option, block.type, block.props))\n : undefined\n})\n\nfunction turnInto(option: BlockOption) {\n const current = view.value\n if (!current) return\n setBlockType(option.type, option.props)(current.state, current.dispatch)\n requestAnimationFrame(() => current.focus())\n}\n\n/* links */\n\nconst linkMark = schema.marks.link\nconst currentHref = computed(() => {\n const current = state.value\n if (!current) return ''\n const { from, to } = current.selection\n let found = ''\n current.doc.nodesBetween(from, to, (node) => {\n const mark = linkMark?.isInSet(node.marks)\n if (mark) found ||= mark.attrs.href as string\n })\n return found\n})\n\n/** `Mod+K` and the link button: edit the link of the selected text. */\nfunction editLink(): boolean {\n const current = view.value\n if (!current || !linkMark || !formattable.value) return false\n const { from, to } = current.state.selection\n linking.value = { from, to }\n href.value = currentHref.value\n void nextTick(() => linkInput.value?.focus())\n return true\n}\n\n/** `example.com` becomes `https://example.com`; other relative links stay. */\nfunction normalise(value: string): string {\n const text = value.trim()\n if (/^[\\w-]+(\\.[\\w-]+)+(?:[/?#:]|$)/.test(text) && !text.includes(' ')) return `https://${text}`\n return text\n}\n\nfunction applyLink() {\n const current = view.value\n const range = linking.value\n if (!current || !range || !linkMark) return\n const value = normalise(href.value)\n const tr = current.state.tr.removeMark(range.from, range.to, linkMark)\n if (value && isSafeHref(value)) tr.addMark(range.from, range.to, linkMark.create({ href: value }))\n current.dispatch(tr)\n closeLink()\n}\n\nfunction removeLink() {\n href.value = ''\n applyLink()\n}\n\nfunction closeLink() {\n const current = view.value\n const range = linking.value\n linking.value = null\n if (!current) return\n if (range)\n current.dispatch(\n current.state.tr.setSelection(TextSelection.create(current.state.doc, range.from, range.to)),\n )\n current.focus()\n}\n\nfunction onLinkKey(event: KeyboardEvent) {\n if (isComposing(event)) return\n if (event.key === 'Enter') {\n event.preventDefault()\n applyLink()\n } else if (event.key === 'Escape') {\n event.preventDefault()\n event.stopPropagation()\n closeLink()\n }\n}\n\nfunction onLinkBlur(event: FocusEvent) {\n // leaving for anywhere but the toolbar ends editing without saving\n if (!panel.value?.contains(event.relatedTarget as Node)) linking.value = null\n}\n\ndefineExpose({ editLink })\n</script>\n\n<template>\n <Transition name=\"dou-floating\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-bubble\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n @mousedown=\"!linking && $event.preventDefault()\"\n @focusin=\"panelFocused = true\"\n @focusout=\"onPanelFocusOut\"\n @keydown=\"onPanelKeyDown\"\n >\n <div v-if=\"linking\" class=\"dou-editor-bubble__link\">\n <DouInput\n ref=\"linkInput\"\n v-model=\"href\"\n size=\"sm\"\n :placeholder=\"messages.linkPlaceholder\"\n :aria-label=\"messages.link\"\n @keydown=\"onLinkKey\"\n @blur=\"onLinkBlur\"\n >\n <template #prefix><LinkIcon /></template>\n </DouInput>\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.applyLink\"\n @mousedown.prevent\n @click=\"applyLink\"\n >\n <CheckIcon />\n </DouButton>\n <DouButton\n v-if=\"currentHref\"\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.removeLink\"\n @mousedown.prevent\n @click=\"removeLink\"\n >\n <UnlinkIcon />\n </DouButton>\n </div>\n <DouToolbar v-else size=\"sm\" :aria-label=\"messages.formatting\">\n <DouDropdown\n v-if=\"turnable\"\n v-model:open=\"menuOpen\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <DouButton size=\"sm\" variant=\"ghost\" class=\"dou-editor-bubble__type\">\n {{ currentOption ? labelOf(currentOption.label, messages) : messages.turnInto }}\n <template #trailing><ChevronDownIcon /></template>\n </DouButton>\n <template #menu>\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=\"option === currentOption\" #suffix><CheckIcon /></template>\n </DouDropdownItem>\n </template>\n </DouDropdown>\n <DouToolbarSeparator v-if=\"turnable && marks.length\" />\n <DouToggleGroup\n v-if=\"marks.length\"\n type=\"multiple\"\n :model-value=\"active\"\n :aria-label=\"messages.formatting\"\n @update:model-value=\"onMarks\"\n >\n <DouTooltip\n v-for=\"mark in marks\"\n :key=\"mark.mark\"\n :content=\"labelOf(mark.label, messages)\"\n :shortcut=\"mark.hotkey\"\n placement=\"bottom\"\n >\n <DouToggle :value=\"mark.mark\" :aria-label=\"labelOf(mark.label, messages)\">\n <component :is=\"mark.icon\" />\n </DouToggle>\n </DouTooltip>\n </DouToggleGroup>\n <template v-if=\"kit.toolbar.length\">\n <DouToolbarSeparator v-if=\"marks.length\" />\n <component :is=\"control\" v-for=\"(control, index) in kit.toolbar\" :key=\"index\" />\n </template>\n <DouToolbarSeparator v-if=\"linkMark\" />\n <DouTooltip v-if=\"linkMark\" :content=\"messages.link\" shortcut=\"mod+k\" placement=\"bottom\">\n <DouToggle\n :pressed=\"!!currentHref\"\n :aria-label=\"messages.link\"\n @update:pressed=\"editLink\"\n >\n <LinkIcon />\n </DouToggle>\n </DouTooltip>\n <template v-if=\"comments.writable.value\">\n <DouToolbarSeparator />\n <DouTooltip :content=\"messages.comment\" shortcut=\"mod+alt+m\" placement=\"bottom\">\n <DouButton\n size=\"sm\"\n variant=\"ghost\"\n :aria-label=\"messages.comment\"\n @click=\"comments.start()\"\n >\n <MessagePlusIcon />\n </DouButton>\n </DouTooltip>\n </template>\n </DouToolbar>\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;EAwCA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,UAAU,KAAK,aAAa,OAAO,SAAS;EACpF,MAAM,QAAQ,eAA4B,OAAO;EAGjD,MAAM,WAAW,WAAW,KAAK;EACjC,MAAM,WAAW,WAAW,KAAK;EAEjC,MAAM,eAAe,oBAAoB;EAEzC,MAAM,eAAe,WAAW,KAAK;EACrC,MAAM,UAAU,UAAU,UAAU,aAAa,QAAQ,MAAM;EAC/D,SAAS,gBAAgB,OAAmB;GAC1C,IAAI,CAAC,MAAM,OAAO,SAAS,MAAM,aAA4B,GAAG,aAAa,QAAQ;EACvF;EACA,SAAS,eAAe,OAAsB;GAC5C,IAAI,MAAM,QAAQ,YAAY,QAAQ,SAAS,MAAM,kBAAkB;GACvE,MAAM,eAAe;GACrB,KAAK,OAAO,MAAM;EACpB;EACA,MAAM,UAAU,WAAgD,IAAI;EACpE,MAAM,OAAO,WAAW,EAAE;EAC1B,MAAM,YAAY,eAA8C,WAAW;EAE3E,MAAM,cAAc,eAAe;GACjC,MAAM,UAAU,MA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AlCN,UAAA,GAAAI,mBAYWM,UAAA,EAAA,KAAA,EAAA,GAAA,CAXTH,YAAuBD,MAAA,mBAAA,CAAA,GACvBC,YASaD,MAAA,UAAA,GAAA;OATA,SAASA,MAAA,QAAA,CAAQ,CAAC;OAAS,UAAS;OAAY,WAAU;;OACrE,SAAAH,cAOY,CAPZI,YAOYD,MAAA,SAAA,GAAA;QANV,MAAK;QACL,SAAQ;QACP,cAAYA,MAAA,QAAA,CAAQ,CAAC;QACrB,SAAK,OAAA,OAAA,OAAA,MAAA,WAAEA,MAAA,QAAA,CAAQ,CAAC,MAAK;;QAEtB,SAAAH,cAAmB,CAAnBI,YAAmBD,MAAA,eAAA,CAAA,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"comment-card.js","names":["_sfc_main"],"sources":["../../src/components/comment-card.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, watch } from 'vue'\nimport { commentRange, type CommentRange } from '../core/comments'\nimport { editorKey } from '../editor'\n\n/*\n * The thread a piece of text is about, beside that text: opened by a\n * click on highlighted text or `v-model:activeComment`, or empty while\n * a new thread's first comment is being written.\n */\n\nconst { view, state, comments, messages } = inject(editorKey)!\nconst panel = shallowRef<HTMLElement | null>(null)\n\nconst thread = computed<CommentThread | null>(() => {\n const id = comments.active.value\n return (id && comments.threads.value.find((item) => item.id === id)) || null\n})\n\nconst range = computed<CommentRange | null>(() => {\n if (comments.pending.value) return comments.pending.value\n const current = state.value\n return thread.value && current ? commentRange(current.doc, thread.value.id) : null\n})\n\nconst open = computed(() => !!range.value)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const at = range.value\n if (!current || !at) return new DOMRect()\n const start = current.coordsAtPos(at.from, 1)\n const end = current.coordsAtPos(at.to, -1)\n // text over several lines: from its start to the editor's right edge\n const right =\n Math.abs(start.top - end.top) < 4\n ? end.right\n : Math.max(start.left + 1, current.dom.getBoundingClientRect().right)\n return new DOMRect(\n start.left,\n start.top,\n Math.max(1, right - start.left),\n end.bottom - start.top,\n )\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nconst threadView = shallowRef<InstanceType<typeof DouCommentThread> | null>(null)\n\n/** Focus was in the card, or went nowhere when what held it went away. */\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) view.value?.focus()\n}\n\n// the card is a layer: Escape goes to a menu opened from it first, and a\n// press on such a menu isn't outside. A press on the editor's text is the\n// editor's: it opens the thread there, or closes the card.\nuseLayer({\n open,\n elements: () => [panel.value, view.value?.dom],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\n// asked to (by the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n threadView.value?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to the text, once\n// the card is gone (focus can sit in it while it fades out)\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) view.value?.focus()\n}\n</script>\n\n<template>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-comment\"\n role=\"dialog\"\n :aria-label=\"messages.commentThread\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <DouCommentThread\n ref=\"threadView\"\n :key=\"thread?.id ?? 'new'\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n :autofocus=\"!thread\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </div>\n </Transition>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"comment-card.js","names":["_sfc_main"],"sources":["../../src/components/comment-card.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, watch } from 'vue'\nimport { commentRange, type CommentRange } from '../core/comments'\nimport { editorKey } from '../editor'\nimport { columnRight } from '../dom'\n\n/*\n * The thread a piece of text is about, beside that text: opened by a\n * click on highlighted text or `v-model:activeComment`, or empty while\n * a new thread's first comment is being written.\n */\n\nconst { view, state, comments, messages } = inject(editorKey)!\nconst panel = shallowRef<HTMLElement | null>(null)\n\nconst thread = computed<CommentThread | null>(() => {\n const id = comments.active.value\n return (id && comments.threads.value.find((item) => item.id === id)) || null\n})\n\nconst range = computed<CommentRange | null>(() => {\n if (comments.pending.value) return comments.pending.value\n const current = state.value\n return thread.value && current ? commentRange(current.doc, thread.value.id) : null\n})\n\nconst open = computed(() => !!range.value)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const at = range.value\n if (!current || !at) return new DOMRect()\n const start = current.coordsAtPos(at.from, 1)\n const end = current.coordsAtPos(at.to, -1)\n // text over several lines: from its start to the text column's right edge\n const right =\n Math.abs(start.top - end.top) < 4\n ? end.right\n : Math.max(start.left + 1, columnRight(current.dom))\n return new DOMRect(\n start.left,\n start.top,\n Math.max(1, right - start.left),\n end.bottom - start.top,\n )\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nconst threadView = shallowRef<InstanceType<typeof DouCommentThread> | null>(null)\n\n/** Focus was in the card, or went nowhere when what held it went away. */\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) view.value?.focus()\n}\n\n// the card is a layer: Escape goes to a menu opened from it first, and a\n// press on such a menu isn't outside. A press on the editor's text is the\n// editor's: it opens the thread there, or closes the card.\nuseLayer({\n open,\n elements: () => [panel.value, view.value?.dom],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\n// asked to (by the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n threadView.value?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to the text, once\n// the card is gone (focus can sit in it while it fades out)\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) view.value?.focus()\n}\n</script>\n\n<template>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-comment\"\n role=\"dialog\"\n :aria-label=\"messages.commentThread\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <DouCommentThread\n ref=\"threadView\"\n :key=\"thread?.id ?? 'new'\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n :autofocus=\"!thread\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </div>\n </Transition>\n</template>\n"],"mappings":""}
@@ -1,3 +1,4 @@
1
+ import { columnRight } from "../dom.js";
1
2
  import { editorKey } from "../editor.js";
2
3
  import { commentRange } from "../core/comments.js";
3
4
  import { DouCommentThread, useFloating, useLayer, useZIndex } from "dou-ui";
@@ -25,7 +26,7 @@ var comment_card_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
25
26
  if (!current || !at) return new DOMRect();
26
27
  const start = current.coordsAtPos(at.from, 1);
27
28
  const end = current.coordsAtPos(at.to, -1);
28
- const right = Math.abs(start.top - end.top) < 4 ? end.right : Math.max(start.left + 1, current.dom.getBoundingClientRect().right);
29
+ const right = Math.abs(start.top - end.top) < 4 ? end.right : Math.max(start.left + 1, columnRight(current.dom));
29
30
  return new DOMRect(start.left, start.top, Math.max(1, right - start.left), end.bottom - start.top);
30
31
  } };
31
32
  const { style, placement, update } = useFloating(() => open.value ? anchor : null, panel, {
@@ -1 +1 @@
1
- {"version":3,"file":"comment-card.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_Transition","_withCtx","_createElementBlock","_unref","_normalizeStyle","_createCommentVNode"],"sources":["../../src/components/comment-card.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, watch } from 'vue'\nimport { commentRange, type CommentRange } from '../core/comments'\nimport { editorKey } from '../editor'\n\n/*\n * The thread a piece of text is about, beside that text: opened by a\n * click on highlighted text or `v-model:activeComment`, or empty while\n * a new thread's first comment is being written.\n */\n\nconst { view, state, comments, messages } = inject(editorKey)!\nconst panel = shallowRef<HTMLElement | null>(null)\n\nconst thread = computed<CommentThread | null>(() => {\n const id = comments.active.value\n return (id && comments.threads.value.find((item) => item.id === id)) || null\n})\n\nconst range = computed<CommentRange | null>(() => {\n if (comments.pending.value) return comments.pending.value\n const current = state.value\n return thread.value && current ? commentRange(current.doc, thread.value.id) : null\n})\n\nconst open = computed(() => !!range.value)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const at = range.value\n if (!current || !at) return new DOMRect()\n const start = current.coordsAtPos(at.from, 1)\n const end = current.coordsAtPos(at.to, -1)\n // text over several lines: from its start to the editor's right edge\n const right =\n Math.abs(start.top - end.top) < 4\n ? end.right\n : Math.max(start.left + 1, current.dom.getBoundingClientRect().right)\n return new DOMRect(\n start.left,\n start.top,\n Math.max(1, right - start.left),\n end.bottom - start.top,\n )\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nconst threadView = shallowRef<InstanceType<typeof DouCommentThread> | null>(null)\n\n/** Focus was in the card, or went nowhere when what held it went away. */\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) view.value?.focus()\n}\n\n// the card is a layer: Escape goes to a menu opened from it first, and a\n// press on such a menu isn't outside. A press on the editor's text is the\n// editor's: it opens the thread there, or closes the card.\nuseLayer({\n open,\n elements: () => [panel.value, view.value?.dom],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\n// asked to (by the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n threadView.value?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to the text, once\n// the card is gone (focus can sit in it while it fades out)\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) view.value?.focus()\n}\n</script>\n\n<template>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-comment\"\n role=\"dialog\"\n :aria-label=\"messages.commentThread\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <DouCommentThread\n ref=\"threadView\"\n :key=\"thread?.id ?? 'new'\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n :autofocus=\"!thread\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;EAmBA,MAAM,EAAE,MAAM,OAAO,UAAU,aAAa,OAAO,SAAS;EAC5D,MAAM,QAAQ,WAA+B,IAAI;EAEjD,MAA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script_setup_true_lang.js","names":["_openBlock","_createBlock","_Transition","_withCtx","_createElementBlock","_unref","_normalizeStyle","_createCommentVNode"],"sources":["../../src/components/comment-card.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n DouCommentThread,\n useFloating,\n useLayer,\n useZIndex,\n type CommentThread,\n type VirtualElement,\n} from 'dou-ui'\nimport { computed, inject, nextTick, shallowRef, watch } from 'vue'\nimport { commentRange, type CommentRange } from '../core/comments'\nimport { editorKey } from '../editor'\nimport { columnRight } from '../dom'\n\n/*\n * The thread a piece of text is about, beside that text: opened by a\n * click on highlighted text or `v-model:activeComment`, or empty while\n * a new thread's first comment is being written.\n */\n\nconst { view, state, comments, messages } = inject(editorKey)!\nconst panel = shallowRef<HTMLElement | null>(null)\n\nconst thread = computed<CommentThread | null>(() => {\n const id = comments.active.value\n return (id && comments.threads.value.find((item) => item.id === id)) || null\n})\n\nconst range = computed<CommentRange | null>(() => {\n if (comments.pending.value) return comments.pending.value\n const current = state.value\n return thread.value && current ? commentRange(current.doc, thread.value.id) : null\n})\n\nconst open = computed(() => !!range.value)\n\nconst anchor: VirtualElement = {\n getBoundingClientRect() {\n const current = view.value\n const at = range.value\n if (!current || !at) return new DOMRect()\n const start = current.coordsAtPos(at.from, 1)\n const end = current.coordsAtPos(at.to, -1)\n // text over several lines: from its start to the text column's right edge\n const right =\n Math.abs(start.top - end.top) < 4\n ? end.right\n : Math.max(start.left + 1, columnRight(current.dom))\n return new DOMRect(\n start.left,\n start.top,\n Math.max(1, right - start.left),\n end.bottom - start.top,\n )\n },\n}\n\nconst { style, placement, update } = useFloating(() => (open.value ? anchor : null), panel, {\n open,\n placement: 'bottom-start',\n offset: 6,\n})\nconst { next } = useZIndex()\nconst zIndex = shallowRef(0)\nwatch(open, (value) => value && (zIndex.value = next()), { immediate: true })\nwatch(state, () => open.value && void nextTick(update))\n\nconst threadView = shallowRef<InstanceType<typeof DouCommentThread> | null>(null)\n\n/** Focus was in the card, or went nowhere when what held it went away. */\nconst focusLost = () => {\n const el = document.activeElement\n return !el || el === document.body || !!panel.value?.contains(el)\n}\n\nfunction close() {\n const refocus = focusLost()\n comments.close()\n if (refocus) view.value?.focus()\n}\n\n// the card is a layer: Escape goes to a menu opened from it first, and a\n// press on such a menu isn't outside. A press on the editor's text is the\n// editor's: it opens the thread there, or closes the card.\nuseLayer({\n open,\n elements: () => [panel.value, view.value?.dom],\n onEscape: () => close(),\n onOutside: () => comments.close(),\n})\n\n// asked to (by the keyboard shortcut, or a thread just started): the reply box\nwatch(\n () => comments.focusRequest.value,\n async () => {\n await nextTick()\n await nextTick()\n threadView.value?.focus()\n },\n)\n\n// a thread resolved or removed from the card: back to the text, once\n// the card is gone (focus can sit in it while it fades out)\nfunction onClosed() {\n const el = document.activeElement\n if (!el || el === document.body) view.value?.focus()\n}\n</script>\n\n<template>\n <Transition name=\"dou-floating\" @after-leave=\"onClosed\">\n <div\n v-if=\"open\"\n ref=\"panel\"\n class=\"dou-floating dou-editor-comment\"\n role=\"dialog\"\n :aria-label=\"messages.commentThread\"\n :style=\"[style, { zIndex }]\"\n :data-placement=\"placement\"\n >\n <DouCommentThread\n ref=\"threadView\"\n :key=\"thread?.id ?? 'new'\"\n :thread=\"thread\"\n :author=\"comments.author.value\"\n :readonly=\"!comments.writable.value\"\n :autofocus=\"!thread\"\n @action=\"comments.apply\"\n @cancel=\"close\"\n />\n </div>\n </Transition>\n</template>\n"],"mappings":";;;;;;;;;;EAoBA,MAAM,EAAE,MAAM,OAAO,UAAU,aAAa,OAAO,SAAS;EAC5D,MAAM,QAAQ,WAA+B,IAAI;EAEjD,MAAM,SAAS,eAAqC;GAClD,MAAM,KAAK,SAAS,OAAO;GAC3B,OAAQ,MAAM,SAAS,QAAQ,MAAM,MAAM,SAAS,KAAK,OAAO,EAAE,KAAM;EAC1E,CAAC;EAED,MAAM,QAAQ,eAAoC;GAChD,IAAI,SAAS,QAAQ,OAAO,OAAO,SAAS,QAAQ;GACpD,MAAM,UAAU,MAAM;GAC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BAAgB,CAAC,MAAM,OAAO,KAAK,OAAO,GAAG;GAC7C,gBAAgB,MAAM;GACtB,iBAAiB,SAAS,MAAM;EAClC,CAAC;EAGD,YACQ,SAAS,aAAa,OAC5B,YAAY;GACV,MAAM,SAAS;GACf,MAAM,SAAS;GACf,WAAW,OAAO,MAAM;EAC1B,CACF;EAIA,SAAS,WAAW;GAClB,MAAM,KAAK,SAAS;GACpB,IAAI,CAAC,MAAM,OAAO,SAAS,MAAM,KAAK,OAAO,MAAM;EACrD;;GAIE,OAAAA,UAAA,GAAAC,YAqBaC,YAAA;IArBD,MAAK;IAAgB,cAAa;;IAC5C,SAAAC,cAmBM,CAlBE,KAAA,SADRH,UAAA,GAAAI,mBAmBM,OAAA;;KAjBA,SAAA;KAAJ,KAAI;KACJ,OAAM;KACN,MAAK;KACJ,cAAYC,MAAA,QAAA,CAAQ,CAAC;KACrB,OAAKC,eAAA,CAAGD,MAAA,KAAA,GAAK,EAAA,QAAI,OAAA,MAAM,CAAA,CAAA;KACvB,kBAAgBA,MAAA,SAAA;I,KAEjBL,UAAA,GAAAC,YASEI,MAAA,gBAAA,GAAA;KARI,SAAA;KAAJ,KAAI;KACH,KAAK,OAAA,OAAQ,MAAE;KACf,QAAQ,OAAA;KACR,QAAQA,MAAA,QAAA,CAAQ,CAAC,OAAO;KACxB,UAAQ,CAAGA,MAAA,QAAA,CAAQ,CAAC,SAAS;KAC7B,WAAS,CAAG,OAAA;KACZ,UAAQA,MAAA,QAAA,CAAQ,CAAC;KACjB,UAAQ"}
@@ -19,9 +19,9 @@ function kitOf(extensions) {
19
19
  function blocksToHTML(blocks, extensions) {
20
20
  return writeHTML(blocks, kitOf(extensions));
21
21
  }
22
- /** Read HTML as blocks with the given extensions. Needs `DOMParser` (a browser, or a DOM library). */
23
- function htmlToBlocks(html, extensions) {
24
- return parseHTML(html, kitOf(extensions));
22
+ /** Read HTML as blocks with the given extensions. Needs a `DOMParser`: the browser's, or `options.domParser`. */
23
+ function htmlToBlocks(html, extensions, options = {}) {
24
+ return parseHTML(html, kitOf(extensions), options.domParser);
25
25
  }
26
26
  export { blocksToHTML, htmlToBlocks, kitOf };
27
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"convert.js","names":[],"sources":["../../src/core/convert.ts"],"sourcesContent":["import {\n resolveEditorExtensions,\n type EditorExtension,\n type ResolvedEditorExtensions,\n} from './extension'\nimport type { Block, PartialBlock } from './model'\nimport { writeHTML } from './output'\nimport { parseHTML } from './prepare'\n\nexport type EditorExtensionList = readonly (EditorExtension | EditorExtension[])[]\n\nconst resolved = new WeakMap<EditorExtensionList, ResolvedEditorExtensions>()\n\n/** Resolve a list of extensions once; the same array gives the same result. */\nexport function kitOf(extensions: EditorExtensionList): ResolvedEditorExtensions {\n let kit = resolved.get(extensions)\n if (!kit) {\n kit = resolveEditorExtensions(extensions)\n resolved.set(extensions, kit)\n }\n return kit\n}\n\n/**\n * Write blocks as HTML with the given extensions, e.g. to show a document\n * outside the editor. Works without a browser.\n */\nexport function blocksToHTML(blocks: PartialBlock[], extensions: EditorExtensionList): string {\n return writeHTML(blocks, kitOf(extensions))\n}\n\n/** Read HTML as blocks with the given extensions. Needs `DOMParser` (a browser, or a DOM library). */\nexport function htmlToBlocks(html: string, extensions: EditorExtensionList): Block[] {\n return parseHTML(html, kitOf(extensions))\n}\n"],"mappings":";;;;AAWA,IAAM,2BAAW,IAAI,QAAuD;;AAG5E,SAAgB,MAAM,YAA2D;CAC/E,IAAI,MAAM,SAAS,IAAI,UAAU;CACjC,IAAI,CAAC,KAAK;EACR,MAAM,wBAAwB,UAAU;EACxC,SAAS,IAAI,YAAY,GAAG;CAC9B;CACA,OAAO;AACT;;;;;AAMA,SAAgB,aAAa,QAAwB,YAAyC;CAC5F,OAAO,UAAU,QAAQ,MAAM,UAAU,CAAC;AAC5C;;AAGA,SAAgB,aAAa,MAAc,YAA0C;CACnF,OAAO,UAAU,MAAM,MAAM,UAAU,CAAC;AAC1C"}
1
+ {"version":3,"file":"convert.js","names":[],"sources":["../../src/core/convert.ts"],"sourcesContent":["import {\n resolveEditorExtensions,\n type EditorExtension,\n type ResolvedEditorExtensions,\n} from './extension'\nimport type { Block, PartialBlock } from './model'\nimport { writeHTML } from './output'\nimport { parseHTML, type DOMParserLike } from './prepare'\n\nexport type EditorExtensionList = readonly (EditorExtension | EditorExtension[])[]\n\nconst resolved = new WeakMap<EditorExtensionList, ResolvedEditorExtensions>()\n\n/** Resolve a list of extensions once; the same array gives the same result. */\nexport function kitOf(extensions: EditorExtensionList): ResolvedEditorExtensions {\n let kit = resolved.get(extensions)\n if (!kit) {\n kit = resolveEditorExtensions(extensions)\n resolved.set(extensions, kit)\n }\n return kit\n}\n\n/**\n * Write blocks as HTML with the given extensions, e.g. to show a document\n * outside the editor. Works without a browser.\n */\nexport function blocksToHTML(blocks: PartialBlock[], extensions: EditorExtensionList): string {\n return writeHTML(blocks, kitOf(extensions))\n}\n\nexport interface HTMLToBlocksOptions {\n /**\n * Reads the HTML. Defaults to the global `DOMParser`; where there is none\n * (Node, Bun), pass one from a DOM library such as happy-dom or linkedom.\n */\n domParser?: DOMParserLike\n}\n\n/** Read HTML as blocks with the given extensions. Needs a `DOMParser`: the browser's, or `options.domParser`. */\nexport function htmlToBlocks(\n html: string,\n extensions: EditorExtensionList,\n options: HTMLToBlocksOptions = {},\n): Block[] {\n return parseHTML(html, kitOf(extensions), options.domParser)\n}\n"],"mappings":";;;;AAWA,IAAM,2BAAW,IAAI,QAAuD;;AAG5E,SAAgB,MAAM,YAA2D;CAC/E,IAAI,MAAM,SAAS,IAAI,UAAU;CACjC,IAAI,CAAC,KAAK;EACR,MAAM,wBAAwB,UAAU;EACxC,SAAS,IAAI,YAAY,GAAG;CAC9B;CACA,OAAO;AACT;;;;;AAMA,SAAgB,aAAa,QAAwB,YAAyC;CAC5F,OAAO,UAAU,QAAQ,MAAM,UAAU,CAAC;AAC5C;;AAWA,SAAgB,aACd,MACA,YACA,UAA+B,CAAC,GACvB;CACT,OAAO,UAAU,MAAM,MAAM,UAAU,GAAG,QAAQ,SAAS;AAC7D"}
@@ -2,7 +2,7 @@ import { blocksToDoc, docToBlocks } from "./model.js";
2
2
  import { blockSelectionPlugin } from "./block-selection.js";
3
3
  import { editorInputRules } from "./input-rules.js";
4
4
  import { editorKeymap } from "./keymap.js";
5
- import { idPlugin, placeholderPlugin } from "./plugins.js";
5
+ import { idPlugin, listPlugin, placeholderPlugin } from "./plugins.js";
6
6
  import { preparePastePlugin } from "./prepare.js";
7
7
  import { keymap } from "prosemirror-keymap";
8
8
  import { EditorState, Plugin, PluginKey } from "prosemirror-state";
@@ -52,6 +52,7 @@ function createPlugins(options) {
52
52
  ...builtInHistory ? [history()] : [],
53
53
  preparePastePlugin(kit),
54
54
  idPlugin(),
55
+ listPlugin(),
55
56
  placeholderPlugin(options.placeholder)
56
57
  ];
57
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"editor.js","names":[],"sources":["../../src/core/editor.ts"],"sourcesContent":["import { baseKeymap } from 'prosemirror-commands'\nimport { history, redo, undo } from 'prosemirror-history'\nimport { keymap } from 'prosemirror-keymap'\nimport type { Node as PMNode } from 'prosemirror-model'\nimport { EditorState, Plugin, PluginKey, type Command, type Transaction } from 'prosemirror-state'\nimport { EditorView, type NodeViewConstructor } from 'prosemirror-view'\nimport { blockSelectionPlugin } from './block-selection'\nimport type { ResolvedEditorExtensions } from './extension'\nimport { editorInputRules } from './input-rules'\nimport { editorKeymap, type KeymapOptions } from './keymap'\nimport { blocksToDoc, docToBlocks, type Block, type PartialBlock } from './model'\nimport { idPlugin, placeholderPlugin, type PlaceholderOptions } from './plugins'\nimport { preparePastePlugin } from './prepare'\n\nexport interface CreateEditorOptions {\n /** Where the editor goes. */\n element: HTMLElement\n /** The resolved extensions: schema, plugins, node views. */\n kit: ResolvedEditorExtensions\n /** More node views, e.g. ones that render Vue components. */\n nodeViews?: Record<string, NodeViewConstructor>\n blocks?: PartialBlock[]\n editable?: boolean\n placeholder: PlaceholderOptions\n /** Called after each change to the document, with the transaction and the state before it. */\n onChange?: (view: EditorView, tr: Transaction, before: EditorState) => void\n /** Called after every state change, including the selection. */\n onUpdate?: (view: EditorView, before: EditorState) => void\n /**\n * Extra plugins, placed before the built-in ones so their keys win.\n * The collaboration extension adds its sync and cursor plugins here.\n */\n plugins?: Plugin[]\n /**\n * Key plugins placed after the extensions' keys, so an extension can\n * take one of their keys, and before the built-in ones.\n */\n keymaps?: Plugin[]\n /** Leave out the built-in undo history (collaboration brings its own). */\n history?: boolean\n undo?: KeymapOptions['undo']\n redo?: KeymapOptions['redo']\n /** Attributes for the editable element, e.g. an accessible name. */\n attributes?: () => Record<string, string>\n}\n\n/** The transaction meta that names who made a change, for the `transaction` event. */\nexport const originKey = 'douOrigin'\n\nconst historyKey = new PluginKey<{ undo: Command; redo: Command }>('douHistory')\n\n/**\n * The undo and redo the editor runs: the built-in history's, or those of\n * the extension or props that replace it. For node views that edit their\n * text themselves, so their undo is the document's.\n */\nexport function historyCommands(state: EditorState): {\n undo: Command\n redo: Command\n} {\n return historyKey.getState(state) ?? { undo, redo }\n}\n\nexport function createPlugins(options: Omit<CreateEditorOptions, 'element'>): Plugin[] {\n const { kit } = options\n const provider = kit.history\n const builtInHistory = options.history !== false && !provider\n const commands = {\n undo: options.undo ?? provider?.undo ?? undo,\n redo: options.redo ?? provider?.redo ?? redo,\n }\n return [\n new Plugin({\n key: historyKey,\n state: { init: () => commands, apply: (_tr, value) => value },\n }),\n ...(options.plugins ?? []),\n ...kit.plugins,\n editorInputRules(kit.inputRules),\n blockSelectionPlugin(),\n ...kit.keymaps.map((bindings) => keymap(bindings)),\n ...(options.keymaps ?? []),\n editorKeymap(commands),\n keymap(baseKeymap),\n ...(provider?.plugins ?? []),\n ...(builtInHistory ? [history()] : []),\n preparePastePlugin(kit),\n idPlugin(),\n placeholderPlugin(options.placeholder),\n ]\n}\n\nexport function createState(\n kit: ResolvedEditorExtensions,\n blocks: PartialBlock[] | undefined,\n plugins: Plugin[],\n): EditorState {\n return EditorState.create({\n schema: kit.schema,\n doc: blocksToDoc(kit.schema, blocks ?? []),\n plugins,\n })\n}\n\nconst viewNodeViews = new WeakMap<EditorView, Record<string, NodeViewConstructor>>()\n\n/** Fresh functions, so the view redraws every node view (e.g. after `editable` changes). */\nconst fresh = (nodeViews: Record<string, NodeViewConstructor>) =>\n Object.fromEntries(\n Object.entries(nodeViews).map(([name, create]) => [\n name,\n ((...args) => create(...args)) as NodeViewConstructor,\n ]),\n )\n\nexport function createEditorView(options: CreateEditorOptions): EditorView {\n const editable = options.editable ?? true\n const plugins = createPlugins(options)\n const nodeViews = { ...options.kit.nodeViews, ...options.nodeViews }\n const view: EditorView = new EditorView(options.element, {\n state: createState(options.kit, options.blocks, plugins),\n editable: () => editable,\n nodeViews: fresh(nodeViews),\n attributes: () => ({\n class: 'dou-editor__surface',\n role: 'textbox',\n 'aria-multiline': 'true',\n ...options.attributes?.(),\n }),\n // `this`, not `view`: plugins (e.g. collaboration) dispatch while the view is being created\n dispatchTransaction(this: EditorView, tr) {\n const before = this.state\n const next = before.apply(tr)\n this.updateState(next)\n if (next.doc !== before.doc) options.onChange?.(this, tr, before)\n options.onUpdate?.(this, before)\n },\n })\n viewNodeViews.set(view, nodeViews)\n return view\n}\n\nexport function setEditable(view: EditorView, value: boolean) {\n // node views draw controls (checkboxes…) that are disabled while read-only\n view.setProps({ editable: () => value, nodeViews: fresh(viewNodeViews.get(view) ?? {}) })\n}\n\n/** Replace the whole document, e.g. when `v-model` changes from outside. */\nexport function replaceBlocks(view: EditorView, blocks: PartialBlock[]) {\n const state = view.state\n const doc = blocksToDoc(state.schema, blocks)\n const tr = state.tr.replaceWith(0, state.doc.content.size, doc.content)\n tr.setMeta('addToHistory', false)\n tr.setMeta(originKey, 'external')\n view.dispatch(tr)\n}\n\n/**\n * Replace the document with `blocks` as one change undo takes back, e.g.\n * an older version. Only what differs is replaced, so the blocks that stay\n * keep their place, and with collaboration only they are written.\n */\nexport function restoreBlocks(view: EditorView, blocks: PartialBlock[]) {\n const state = view.state\n const next = blocksToDoc(state.schema, blocks)\n const start = state.doc.content.findDiffStart(next.content)\n if (start === null) return false\n const end = state.doc.content.findDiffEnd(next.content)!\n // the two ends can cross where the same text repeats: widen them to agree\n const overlap = start - Math.min(end.a, end.b)\n if (overlap > 0) {\n end.a += overlap\n end.b += overlap\n }\n view.dispatch(\n state.tr\n .replace(start, end.a, next.slice(start, end.b))\n .setMeta(originKey, 'restore')\n .scrollIntoView(),\n )\n return true\n}\n\nexport function getBlocks(view: EditorView): Block[] {\n return docToBlocks(view.state.doc)\n}\n\nexport function runCommand(view: EditorView, command: Command): boolean {\n return command(view.state, view.dispatch, view)\n}\n\nexport type { PMNode }\n"],"mappings":";;;;;;;;;;;;;AA+CA,IAAa,YAAY;AAEzB,IAAM,aAAa,IAAI,UAA4C,YAAY;;;;;;AAO/E,SAAgB,gBAAgB,OAG9B;CACA,OAAO,WAAW,SAAS,KAAK,KAAK;EAAE;EAAM;CAAK;AACpD;AAEA,SAAgB,cAAc,SAAyD;CACrF,MAAM,EAAE,QAAQ;CAChB,MAAM,WAAW,IAAI;CACrB,MAAM,iBAAiB,QAAQ,YAAY,SAAS,CAAC;CACrD,MAAM,WAAW;EACf,MAAM,QAAQ,QAAQ,UAAU,QAAQ;EACxC,MAAM,QAAQ,QAAQ,UAAU,QAAQ;CAC1C;CACA,OAAO;EACL,IAAI,OAAO;GACT,KAAK;GACL,OAAO;IAAE,YAAY;IAAU,QAAQ,KAAK,UAAU;GAAM;EAC9D,CAAC;EACD,GAAI,QAAQ,WAAW,CAAC;EACxB,GAAG,IAAI;EACP,iBAAiB,IAAI,UAAU;EAC/B,qBAAqB;EACrB,GAAG,IAAI,QAAQ,KAAK,aAAa,OAAO,QAAQ,CAAC;EACjD,GAAI,QAAQ,WAAW,CAAC;EACxB,aAAa,QAAQ;EACrB,OAAO,UAAU;EACjB,GAAI,UAAU,WAAW,CAAC;EAC1B,GAAI,iBAAiB,CAAC,QAAQ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,QAAwB;CACtE,MAAM,QAAQ,KAAK;CACnB,MAAM,MAAM,YAAY,MAAM,QAAQ,MAAM;CAC5C,MAAM,KAAK,MAAM,GAAG,YAAY,GAAG,MAAM,IAAI,QAAQ,MAAM,IAAI,OAAO;CACtE,GAAG,QAAQ,gBAAgB,KAAK;CAChC,GAAG,QAAQ,WAAW,UAAU;CAChC,KAAK,SAAS,EAAE;AAClB;;;;;;AAOA,SAAgB,cAAc,MAAkB,QAAwB;CACtE,MAAM,QAAQ,KAAK;CACnB,MAAM,OAAO,YAAY,MAAM,QAAQ,MAAM;CAC7C,MAAM,QAAQ,MAAM,IAAI,QAAQ,cAAc,KAAK,OAAO;CAC1D,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,MAAM,MAAM,IAAI,QAAQ,YAAY,KAAK,OAAO;CAEtD,MAAM,UAAU,QAAQ,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC;CAC7C,IAAI,UAAU,GAAG;EACf,IAAI,KAAK;EACT,IAAI,KAAK;CACX;CACA,KAAK,SACH,MAAM,GACH,QAAQ,OAAO,IAAI,GAAG,KAAK,MAAM,OAAO,IAAI,CAAC,CAAC,CAAC,CAC/C,QAAQ,WAAW,SAAS,CAAC,CAC7B,eAAe,CACpB;CACA,OAAO;AACT;AAEA,SAAgB,UAAU,MAA2B;CACnD,OAAO,YAAY,KAAK,MAAM,GAAG;AACnC;AAEA,SAAgB,WAAW,MAAkB,SAA2B;CACtE,OAAO,QAAQ,KAAK,OAAO,KAAK,UAAU,IAAI;AAChD"}
1
+ {"version":3,"file":"editor.js","names":[],"sources":["../../src/core/editor.ts"],"sourcesContent":["import { baseKeymap } from 'prosemirror-commands'\nimport { history, redo, undo } from 'prosemirror-history'\nimport { keymap } from 'prosemirror-keymap'\nimport type { Node as PMNode } from 'prosemirror-model'\nimport { EditorState, Plugin, PluginKey, type Command, type Transaction } from 'prosemirror-state'\nimport { EditorView, type NodeViewConstructor } from 'prosemirror-view'\nimport { blockSelectionPlugin } from './block-selection'\nimport type { ResolvedEditorExtensions } from './extension'\nimport { editorInputRules } from './input-rules'\nimport { editorKeymap, type KeymapOptions } from './keymap'\nimport { blocksToDoc, docToBlocks, type Block, type PartialBlock } from './model'\nimport { idPlugin, listPlugin, placeholderPlugin, type PlaceholderOptions } from './plugins'\nimport { preparePastePlugin } from './prepare'\n\nexport interface CreateEditorOptions {\n /** Where the editor goes. */\n element: HTMLElement\n /** The resolved extensions: schema, plugins, node views. */\n kit: ResolvedEditorExtensions\n /** More node views, e.g. ones that render Vue components. */\n nodeViews?: Record<string, NodeViewConstructor>\n blocks?: PartialBlock[]\n editable?: boolean\n placeholder: PlaceholderOptions\n /** Called after each change to the document, with the transaction and the state before it. */\n onChange?: (view: EditorView, tr: Transaction, before: EditorState) => void\n /** Called after every state change, including the selection. */\n onUpdate?: (view: EditorView, before: EditorState) => void\n /**\n * Extra plugins, placed before the built-in ones so their keys win.\n * The collaboration extension adds its sync and cursor plugins here.\n */\n plugins?: Plugin[]\n /**\n * Key plugins placed after the extensions' keys, so an extension can\n * take one of their keys, and before the built-in ones.\n */\n keymaps?: Plugin[]\n /** Leave out the built-in undo history (collaboration brings its own). */\n history?: boolean\n undo?: KeymapOptions['undo']\n redo?: KeymapOptions['redo']\n /** Attributes for the editable element, e.g. an accessible name. */\n attributes?: () => Record<string, string>\n}\n\n/** The transaction meta that names who made a change, for the `transaction` event. */\nexport const originKey = 'douOrigin'\n\nconst historyKey = new PluginKey<{ undo: Command; redo: Command }>('douHistory')\n\n/**\n * The undo and redo the editor runs: the built-in history's, or those of\n * the extension or props that replace it. For node views that edit their\n * text themselves, so their undo is the document's.\n */\nexport function historyCommands(state: EditorState): {\n undo: Command\n redo: Command\n} {\n return historyKey.getState(state) ?? { undo, redo }\n}\n\nexport function createPlugins(options: Omit<CreateEditorOptions, 'element'>): Plugin[] {\n const { kit } = options\n const provider = kit.history\n const builtInHistory = options.history !== false && !provider\n const commands = {\n undo: options.undo ?? provider?.undo ?? undo,\n redo: options.redo ?? provider?.redo ?? redo,\n }\n return [\n new Plugin({\n key: historyKey,\n state: { init: () => commands, apply: (_tr, value) => value },\n }),\n ...(options.plugins ?? []),\n ...kit.plugins,\n editorInputRules(kit.inputRules),\n blockSelectionPlugin(),\n ...kit.keymaps.map((bindings) => keymap(bindings)),\n ...(options.keymaps ?? []),\n editorKeymap(commands),\n keymap(baseKeymap),\n ...(provider?.plugins ?? []),\n ...(builtInHistory ? [history()] : []),\n preparePastePlugin(kit),\n idPlugin(),\n listPlugin(),\n placeholderPlugin(options.placeholder),\n ]\n}\n\nexport function createState(\n kit: ResolvedEditorExtensions,\n blocks: PartialBlock[] | undefined,\n plugins: Plugin[],\n): EditorState {\n return EditorState.create({\n schema: kit.schema,\n doc: blocksToDoc(kit.schema, blocks ?? []),\n plugins,\n })\n}\n\nconst viewNodeViews = new WeakMap<EditorView, Record<string, NodeViewConstructor>>()\n\n/** Fresh functions, so the view redraws every node view (e.g. after `editable` changes). */\nconst fresh = (nodeViews: Record<string, NodeViewConstructor>) =>\n Object.fromEntries(\n Object.entries(nodeViews).map(([name, create]) => [\n name,\n ((...args) => create(...args)) as NodeViewConstructor,\n ]),\n )\n\nexport function createEditorView(options: CreateEditorOptions): EditorView {\n const editable = options.editable ?? true\n const plugins = createPlugins(options)\n const nodeViews = { ...options.kit.nodeViews, ...options.nodeViews }\n const view: EditorView = new EditorView(options.element, {\n state: createState(options.kit, options.blocks, plugins),\n editable: () => editable,\n nodeViews: fresh(nodeViews),\n attributes: () => ({\n class: 'dou-editor__surface',\n role: 'textbox',\n 'aria-multiline': 'true',\n ...options.attributes?.(),\n }),\n // `this`, not `view`: plugins (e.g. collaboration) dispatch while the view is being created\n dispatchTransaction(this: EditorView, tr) {\n const before = this.state\n const next = before.apply(tr)\n this.updateState(next)\n if (next.doc !== before.doc) options.onChange?.(this, tr, before)\n options.onUpdate?.(this, before)\n },\n })\n viewNodeViews.set(view, nodeViews)\n return view\n}\n\nexport function setEditable(view: EditorView, value: boolean) {\n // node views draw controls (checkboxes…) that are disabled while read-only\n view.setProps({ editable: () => value, nodeViews: fresh(viewNodeViews.get(view) ?? {}) })\n}\n\n/** Replace the whole document, e.g. when `v-model` changes from outside. */\nexport function replaceBlocks(view: EditorView, blocks: PartialBlock[]) {\n const state = view.state\n const doc = blocksToDoc(state.schema, blocks)\n const tr = state.tr.replaceWith(0, state.doc.content.size, doc.content)\n tr.setMeta('addToHistory', false)\n tr.setMeta(originKey, 'external')\n view.dispatch(tr)\n}\n\n/**\n * Replace the document with `blocks` as one change undo takes back, e.g.\n * an older version. Only what differs is replaced, so the blocks that stay\n * keep their place, and with collaboration only they are written.\n */\nexport function restoreBlocks(view: EditorView, blocks: PartialBlock[]) {\n const state = view.state\n const next = blocksToDoc(state.schema, blocks)\n const start = state.doc.content.findDiffStart(next.content)\n if (start === null) return false\n const end = state.doc.content.findDiffEnd(next.content)!\n // the two ends can cross where the same text repeats: widen them to agree\n const overlap = start - Math.min(end.a, end.b)\n if (overlap > 0) {\n end.a += overlap\n end.b += overlap\n }\n view.dispatch(\n state.tr\n .replace(start, end.a, next.slice(start, end.b))\n .setMeta(originKey, 'restore')\n .scrollIntoView(),\n )\n return true\n}\n\nexport function getBlocks(view: EditorView): Block[] {\n return docToBlocks(view.state.doc)\n}\n\nexport function runCommand(view: EditorView, command: Command): boolean {\n return command(view.state, view.dispatch, view)\n}\n\nexport type { PMNode }\n"],"mappings":";;;;;;;;;;;;;AA+CA,IAAa,YAAY;AAEzB,IAAM,aAAa,IAAI,UAA4C,YAAY;;;;;;AAO/E,SAAgB,gBAAgB,OAG9B;CACA,OAAO,WAAW,SAAS,KAAK,KAAK;EAAE;EAAM;CAAK;AACpD;AAEA,SAAgB,cAAc,SAAyD;CACrF,MAAM,EAAE,QAAQ;CAChB,MAAM,WAAW,IAAI;CACrB,MAAM,iBAAiB,QAAQ,YAAY,SAAS,CAAC;CACrD,MAAM,WAAW;EACf,MAAM,QAAQ,QAAQ,UAAU,QAAQ;EACxC,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EA,SAAgB,UAAU,MAA2B;CACnD,OAAO,YAAY,KAAK,MAAM,GAAG;AACnC;AAEA,SAAgB,WAAW,MAAkB,SAA2B;CACtE,OAAO,QAAQ,KAAK,OAAO,KAAK,UAAU,IAAI;AAChD"}
@@ -1,6 +1,7 @@
1
1
  import { createId } from "./model.js";
2
2
  import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { Decoration, DecorationSet } from "prosemirror-view";
4
+ import { ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
4
5
  // src/core/plugins.ts
5
6
  /**
6
7
  * Whether a transaction came from another collaborator. Collaborative
@@ -38,6 +39,111 @@ function idPlugin() {
38
39
  }
39
40
  });
40
41
  }
42
+ /**
43
+ * Whether a transaction may have changed which blocks there are, their
44
+ * types or their nesting. Typing and deleting inside one text block, marks
45
+ * and attributes don't; decorations that only follow the block structure
46
+ * then just map through the change instead of being rebuilt.
47
+ */
48
+ function changesBlockStructure(tr) {
49
+ if (!tr.docChanged) return false;
50
+ return tr.steps.some((step, index) => {
51
+ if (step instanceof ReplaceAroundStep) return true;
52
+ if (!(step instanceof ReplaceStep)) return false;
53
+ const { from, to, slice } = step;
54
+ if (slice.openStart || slice.openEnd) return true;
55
+ let blocks = false;
56
+ slice.content.forEach((node) => {
57
+ if (!node.isInline) blocks = true;
58
+ });
59
+ if (blocks) return true;
60
+ const doc = tr.docs[index];
61
+ const $from = doc.resolve(from);
62
+ return !$from.parent.isTextblock || !$from.sameParent(doc.resolve(to));
63
+ });
64
+ }
65
+ /** Plugin state for decorations that only depend on the block structure. */
66
+ var structureDecorations = (build, update = (_set, tr) => build(tr.doc)) => ({
67
+ init: (_config, state) => build(state.doc),
68
+ apply: (tr, value) => !tr.docChanged ? value : changesBlockStructure(tr) ? update(value, tr) : value.map(tr.mapping, tr.doc)
69
+ });
70
+ var isList = (block) => !!block?.firstChild?.type.spec.continues;
71
+ /** Whether a sibling block is an item of the same list as `block`. */
72
+ var sameList = (sibling, block) => isList(sibling) && sibling.firstChild.type === block.firstChild.type;
73
+ /**
74
+ * The content of blocks that continue like a list (`continues` in their
75
+ * spec) gets `is-list`, so the stylesheet can space list items apart by the list gap
76
+ * instead of the block gap. The first and last block of a run of them also
77
+ * get `is-list-start` / `is-list-end`, where the block gap comes back. A run
78
+ * is one type: a to-do list right after a numbered one is a list of its
79
+ * own. Nested items under a list item, of any type, carry on its run.
80
+ */
81
+ /** The list decorations of top-level blocks `first` to `final` (and their children). */
82
+ function listDecorationsOf(doc, first, final) {
83
+ const decorations = [];
84
+ const visit = (container, start, inList, from = 0, to = Infinity) => {
85
+ const last = container.childCount - 1;
86
+ container.forEach((block, offset, index) => {
87
+ if (index < from || index > to) return;
88
+ const pos = start + offset;
89
+ const content = block.firstChild;
90
+ const groupPos = pos + 1 + content.nodeSize;
91
+ const list = isList(block);
92
+ if (list) {
93
+ const classes = ["is-list"];
94
+ const previous = index > 0 ? container.child(index - 1) : null;
95
+ if (!(previous ? sameList(previous, block) : inList)) {
96
+ classes.push("is-list-start");
97
+ if (previous && isList(previous)) classes.push("is-list-after");
98
+ }
99
+ const end = !(index < last ? sameList(container.child(index + 1), block) : inList);
100
+ if (end && block.childCount < 2) classes.push("is-list-end");
101
+ decorations.push(Decoration.node(pos + 1, groupPos, { class: classes.join(" ") }));
102
+ if (end && block.childCount > 1) decorations.push(Decoration.node(groupPos, groupPos + block.child(1).nodeSize, { class: "is-list-end" }));
103
+ }
104
+ if (block.childCount > 1) visit(block.child(1), groupPos + 1, list);
105
+ });
106
+ };
107
+ visit(doc, 0, false, first, final);
108
+ return decorations;
109
+ }
110
+ var listDecorations = (doc) => DecorationSet.create(doc, listDecorationsOf(doc, 0, doc.childCount - 1));
111
+ /**
112
+ * After blocks were added, removed or changed type: only the top-level
113
+ * blocks the change touched, and one on either side (whose run may have
114
+ * started or ended there), are worked out again.
115
+ */
116
+ function updateListDecorations(set, tr) {
117
+ const { doc, mapping } = tr;
118
+ let from = doc.content.size;
119
+ let to = 0;
120
+ mapping.maps.forEach((map, index) => {
121
+ const rest = mapping.slice(index + 1);
122
+ map.forEach((_oldStart, _oldEnd, start, end) => {
123
+ from = Math.min(from, rest.map(start, -1));
124
+ to = Math.max(to, rest.map(end, 1));
125
+ });
126
+ });
127
+ const mapped = set.map(mapping, doc);
128
+ if (from > to) return mapped;
129
+ const first = Math.max(0, doc.resolve(from).index(0) - 1);
130
+ const last = Math.min(doc.childCount - 1, doc.resolve(to).index(0) + 1);
131
+ let start = 0;
132
+ for (let index = 0; index < first; index++) start += doc.child(index).nodeSize;
133
+ let end = start;
134
+ for (let index = first; index <= last; index++) end += doc.child(index).nodeSize;
135
+ return mapped.remove(mapped.find(start, end)).add(doc, listDecorationsOf(doc, first, last));
136
+ }
137
+ /** Marks list-like blocks and the ends of their runs, for spacing. */
138
+ function listPlugin() {
139
+ return new Plugin({
140
+ key: new PluginKey("dou-editor-lists"),
141
+ state: structureDecorations(listDecorations, updateListDecorations),
142
+ props: { decorations(state) {
143
+ return this.getState(state);
144
+ } }
145
+ });
146
+ }
41
147
  /** Numbered items count up within each run of consecutive numbered siblings. */
42
148
  function numberDecorations(doc) {
43
149
  const decorations = [];
@@ -59,10 +165,7 @@ function numberDecorations(doc) {
59
165
  function numberingPlugin() {
60
166
  return new Plugin({
61
167
  key: new PluginKey("dou-editor-numbering"),
62
- state: {
63
- init: (_config, state) => numberDecorations(state.doc),
64
- apply: (tr, value) => tr.docChanged ? numberDecorations(tr.doc) : value
65
- },
168
+ state: structureDecorations(numberDecorations),
66
169
  props: { decorations(state) {
67
170
  return this.getState(state);
68
171
  } }
@@ -97,6 +200,6 @@ function placeholderPlugin(options) {
97
200
  } }
98
201
  });
99
202
  }
100
- export { idPlugin, isRemote, numberingPlugin, placeholderPlugin };
203
+ export { changesBlockStructure, idPlugin, isRemote, listPlugin, numberingPlugin, placeholderPlugin };
101
204
 
102
205
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":[],"sources":["../../src/core/plugins.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type Transaction } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { createId } from './model'\n\n/**\n * Whether a transaction came from another collaborator. Collaborative\n * bindings mark theirs; the Yjs binding uses the `y-sync$` key.\n */\nexport function isRemote(tr: Transaction): boolean {\n const meta = tr.getMeta('y-sync$') as { isChangeOrigin?: boolean } | undefined\n return !!meta?.isChangeOrigin || tr.getMeta('remote') === true\n}\n\n/**\n * Every block gets a unique id. Splitting a block copies its attributes,\n * so the copy gets a fresh id here; the first occurrence keeps the old one.\n * Changes from collaborators are left alone, so two editors never fight\n * over an id.\n */\nexport function idPlugin(): Plugin {\n return new Plugin({\n key: new PluginKey('dou-editor-ids'),\n appendTransaction(transactions, _old, state) {\n if (!transactions.some((tr) => tr.docChanged) || transactions.every(isRemote)) return null\n const seen = new Set<string>()\n let tr: Transaction | null = null\n state.doc.descendants((node, pos) => {\n if (node.type.name !== 'block') return node.type.name === 'blockGroup'\n const id = node.attrs.id as string | null\n if (!id || seen.has(id)) {\n tr ??= state.tr\n const fresh = createId()\n tr.setNodeAttribute(pos, 'id', fresh)\n seen.add(fresh)\n } else seen.add(id)\n return true\n })\n if (tr) (tr as Transaction).setMeta('addToHistory', false)\n return tr\n },\n })\n}\n\n/** Numbered items count up within each run of consecutive numbered siblings. */\nfunction numberDecorations(doc: PMNode): DecorationSet {\n const decorations: Decoration[] = []\n const visit = (container: PMNode, start: number) => {\n let count = 0\n container.forEach((block, offset) => {\n const pos = start + offset\n const content = block.firstChild\n if (content?.type.name === 'numberedItem') {\n count++\n decorations.push(\n Decoration.node(pos + 1, pos + 1 + content.nodeSize, { 'data-index': String(count) }),\n )\n } else count = 0\n if (block.childCount > 1) visit(block.child(1), pos + 1 + content!.nodeSize + 1)\n })\n }\n visit(doc, 0)\n return DecorationSet.create(doc, decorations)\n}\n\nexport function numberingPlugin(): Plugin {\n return new Plugin<DecorationSet>({\n key: new PluginKey('dou-editor-numbering'),\n state: {\n init: (_config, state) => numberDecorations(state.doc),\n apply: (tr, value) => (tr.docChanged ? numberDecorations(tr.doc) : value),\n },\n props: {\n decorations(state) {\n return this.getState(state)\n },\n },\n })\n}\n\nexport interface PlaceholderOptions {\n /** The hint in the empty block the cursor is in. */\n text: () => string\n /** The hint in an empty heading. */\n heading: () => string\n /** The hint when the whole document is one empty paragraph. */\n empty: () => string\n}\n\n/** A hint inside the empty block under the cursor, and in an empty document. */\nexport function placeholderPlugin(options: PlaceholderOptions): Plugin {\n return new Plugin({\n key: new PluginKey('dou-editor-placeholder'),\n props: {\n decorations(state) {\n const { doc, selection } = state\n const decorations: Decoration[] = []\n const onlyBlock =\n doc.childCount === 1 && doc.firstChild!.childCount === 1 && doc.firstChild!.firstChild!\n if (onlyBlock && onlyBlock.type.name === 'paragraph' && onlyBlock.content.size === 0) {\n decorations.push(\n Decoration.node(1, 1 + onlyBlock.nodeSize, {\n class: 'is-empty',\n 'data-placeholder': options.empty(),\n }),\n )\n return DecorationSet.create(doc, decorations)\n }\n const { $from } = selection\n const parent = $from.parent\n if (!selection.empty || !parent.isTextblock || parent.content.size > 0) return null\n if (parent.type.spec.code) return null\n const text = parent.type.name === 'heading' ? options.heading() : options.text()\n const start = $from.before()\n decorations.push(\n Decoration.node(start, start + parent.nodeSize, {\n class: 'is-empty',\n 'data-placeholder': text,\n }),\n )\n return DecorationSet.create(doc, decorations)\n },\n },\n })\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,SAAS,IAA0B;CAEjD,OAAO,CAAC,CADK,GAAG,QAAQ,SACf,CAAA,EAAM,kBAAkB,GAAG,QAAQ,QAAQ,MAAM;AAC5D;;;;;;;AAQA,SAAgB,WAAmB;CACjC,OAAO,IAAI,OAAO;EAChB,KAAK,IAAI,UAAU,gBAAgB;EACnC,kBAAkB,cAAc,MAAM,OAAO;GAC3C,IAAI,CAAC,aAAa,MAAM,OAAO,GAAG,UAAU,KAAK,aAA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AAO,EACL,YAAY,OAAO;GACjB,OAAO,KAAK,SAAS,KAAK;EAC5B,EACF;CACF,CAAC;AACH;;AAYA,SAAgB,kBAAkB,SAAqC;CACrE,OAAO,IAAI,OAAO;EAChB,KAAK,IAAI,UAAU,wBAAwB;EAC3C,OAAO,EACL,YAAY,OAAO;GACjB,MAAM,EAAE,KAAK,cAAc;GAC3B,MAAM,cAA4B,CAAC;GACnC,MAAM,YACJ,IAAI,eAAe,KAAK,IAAI,WAAY,eAAe,KAAK,IAAI,WAAY;GAC9E,IAAI,aAAa,UAAU,KAAK,SAAS,eAAe,UAAU,QAAQ,SAAS,GAAG;IACpF,YAAY,KACV,WAAW,KAAK,GAAG,IAAI,UAAU,UAAU;KACzC,OAAO;KACP,oBAAoB,QAAQ,MAAM;IACpC,CAAC,CACH;IACA,OAAO,cAAc,OAAO,KAAK,WAAW;GAC9C;GACA,MAAM,EAAE,UAAU;GAClB,MAAM,SAAS,MAAM;GACrB,IAAI,CAAC,UAAU,SAAS,CAAC,OAAO,eAAe,OAAO,QAAQ,OAAO,GAAG,OAAO;GAC/E,IAAI,OAAO,KAAK,KAAK,MAAM,OAAO;GAClC,MAAM,OAAO,OAAO,KAAK,SAAS,YAAY,QAAQ,QAAQ,IAAI,QAAQ,KAAK;GAC/E,MAAM,QAAQ,MAAM,OAAO;GAC3B,YAAY,KACV,WAAW,KAAK,OAAO,QAAQ,OAAO,UAAU;IAC9C,OAAO;IACP,oBAAoB;GACtB,CAAC,CACH;GACA,OAAO,cAAc,OAAO,KAAK,WAAW;EAC9C,EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"plugins.js","names":[],"sources":["../../src/core/plugins.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type Transaction } from 'prosemirror-state'\nimport { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { createId } from './model'\n\n/**\n * Whether a transaction came from another collaborator. Collaborative\n * bindings mark theirs; the Yjs binding uses the `y-sync$` key.\n */\nexport function isRemote(tr: Transaction): boolean {\n const meta = tr.getMeta('y-sync$') as { isChangeOrigin?: boolean } | undefined\n return !!meta?.isChangeOrigin || tr.getMeta('remote') === true\n}\n\n/**\n * Every block gets a unique id. Splitting a block copies its attributes,\n * so the copy gets a fresh id here; the first occurrence keeps the old one.\n * Changes from collaborators are left alone, so two editors never fight\n * over an id.\n */\nexport function idPlugin(): Plugin {\n return new Plugin({\n key: new PluginKey('dou-editor-ids'),\n appendTransaction(transactions, _old, state) {\n if (!transactions.some((tr) => tr.docChanged) || transactions.every(isRemote)) return null\n const seen = new Set<string>()\n let tr: Transaction | null = null\n state.doc.descendants((node, pos) => {\n if (node.type.name !== 'block') return node.type.name === 'blockGroup'\n const id = node.attrs.id as string | null\n if (!id || seen.has(id)) {\n tr ??= state.tr\n const fresh = createId()\n tr.setNodeAttribute(pos, 'id', fresh)\n seen.add(fresh)\n } else seen.add(id)\n return true\n })\n if (tr) (tr as Transaction).setMeta('addToHistory', false)\n return tr\n },\n })\n}\n\n/**\n * Whether a transaction may have changed which blocks there are, their\n * types or their nesting. Typing and deleting inside one text block, marks\n * and attributes don't; decorations that only follow the block structure\n * then just map through the change instead of being rebuilt.\n */\nexport function changesBlockStructure(tr: Transaction): boolean {\n if (!tr.docChanged) return false\n return tr.steps.some((step, index) => {\n if (step instanceof ReplaceAroundStep) return true\n if (!(step instanceof ReplaceStep)) return false\n const { from, to, slice } = step\n if (slice.openStart || slice.openEnd) return true\n let blocks = false\n slice.content.forEach((node) => {\n if (!node.isInline) blocks = true\n })\n if (blocks) return true\n const doc = tr.docs[index]!\n const $from = doc.resolve(from)\n return !$from.parent.isTextblock || !$from.sameParent(doc.resolve(to))\n })\n}\n\n/** Plugin state for decorations that only depend on the block structure. */\nconst structureDecorations = (\n build: (doc: PMNode) => DecorationSet,\n update: (set: DecorationSet, tr: Transaction) => DecorationSet = (_set, tr) => build(tr.doc),\n) => ({\n init: (_config: unknown, state: { doc: PMNode }) => build(state.doc),\n apply: (tr: Transaction, value: DecorationSet) =>\n !tr.docChanged\n ? value\n : changesBlockStructure(tr)\n ? update(value, tr)\n : value.map(tr.mapping, tr.doc),\n})\n\nconst isList = (block: PMNode | null) => !!block?.firstChild?.type.spec.continues\n\n/** Whether a sibling block is an item of the same list as `block`. */\nconst sameList = (sibling: PMNode, block: PMNode) =>\n isList(sibling) && sibling.firstChild!.type === block.firstChild!.type\n\n/**\n * The content of blocks that continue like a list (`continues` in their\n * spec) gets `is-list`, so the stylesheet can space list items apart by the list gap\n * instead of the block gap. The first and last block of a run of them also\n * get `is-list-start` / `is-list-end`, where the block gap comes back. A run\n * is one type: a to-do list right after a numbered one is a list of its\n * own. Nested items under a list item, of any type, carry on its run.\n */\n/** The list decorations of top-level blocks `first` to `final` (and their children). */\nfunction listDecorationsOf(doc: PMNode, first: number, final: number): Decoration[] {\n const decorations: Decoration[] = []\n const visit = (container: PMNode, start: number, inList: boolean, from = 0, to = Infinity) => {\n const last = container.childCount - 1\n container.forEach((block, offset, index) => {\n if (index < from || index > to) return\n const pos = start + offset\n const content = block.firstChild!\n const groupPos = pos + 1 + content.nodeSize\n const list = isList(block)\n if (list) {\n // all on the content (or the children's group), never on the block\n // itself: the view looks up a block's own decorations by scanning\n // all of its parent's, and a selector matching blocks by what they\n // hold would be checked again for every block when blocks change\n const classes = ['is-list']\n const previous = index > 0 ? container.child(index - 1) : null\n if (!(previous ? sameList(previous, block) : inList)) {\n classes.push('is-list-start')\n // right after another list: the two edges overlap\n if (previous && isList(previous)) classes.push('is-list-after')\n }\n const end = !(index < last ? sameList(container.child(index + 1), block) : inList)\n if (end && block.childCount < 2) classes.push('is-list-end')\n decorations.push(Decoration.node(pos + 1, groupPos, { class: classes.join(' ') }))\n if (end && block.childCount > 1)\n decorations.push(\n Decoration.node(groupPos, groupPos + block.child(1).nodeSize, { class: 'is-list-end' }),\n )\n }\n if (block.childCount > 1) visit(block.child(1), groupPos + 1, list)\n })\n }\n visit(doc, 0, false, first, final)\n return decorations\n}\n\nconst listDecorations = (doc: PMNode) =>\n DecorationSet.create(doc, listDecorationsOf(doc, 0, doc.childCount - 1))\n\n/**\n * After blocks were added, removed or changed type: only the top-level\n * blocks the change touched, and one on either side (whose run may have\n * started or ended there), are worked out again.\n */\nfunction updateListDecorations(set: DecorationSet, tr: Transaction): DecorationSet {\n const { doc, mapping } = tr\n let from = doc.content.size\n let to = 0\n mapping.maps.forEach((map, index) => {\n const rest = mapping.slice(index + 1)\n map.forEach((_oldStart, _oldEnd, start, end) => {\n from = Math.min(from, rest.map(start, -1))\n to = Math.max(to, rest.map(end, 1))\n })\n })\n const mapped = set.map(mapping, doc)\n if (from > to) return mapped\n const first = Math.max(0, doc.resolve(from).index(0) - 1)\n const last = Math.min(doc.childCount - 1, doc.resolve(to).index(0) + 1)\n let start = 0\n for (let index = 0; index < first; index++) start += doc.child(index).nodeSize\n let end = start\n for (let index = first; index <= last; index++) end += doc.child(index).nodeSize\n return mapped.remove(mapped.find(start, end)).add(doc, listDecorationsOf(doc, first, last))\n}\n\n/** Marks list-like blocks and the ends of their runs, for spacing. */\nexport function listPlugin(): Plugin {\n return new Plugin<DecorationSet>({\n key: new PluginKey('dou-editor-lists'),\n state: structureDecorations(listDecorations, updateListDecorations),\n props: {\n decorations(state) {\n return this.getState(state)\n },\n },\n })\n}\n\n/** Numbered items count up within each run of consecutive numbered siblings. */\nfunction numberDecorations(doc: PMNode): DecorationSet {\n const decorations: Decoration[] = []\n const visit = (container: PMNode, start: number) => {\n let count = 0\n container.forEach((block, offset) => {\n const pos = start + offset\n const content = block.firstChild\n if (content?.type.name === 'numberedItem') {\n count++\n decorations.push(\n Decoration.node(pos + 1, pos + 1 + content.nodeSize, { 'data-index': String(count) }),\n )\n } else count = 0\n if (block.childCount > 1) visit(block.child(1), pos + 1 + content!.nodeSize + 1)\n })\n }\n visit(doc, 0)\n return DecorationSet.create(doc, decorations)\n}\n\nexport function numberingPlugin(): Plugin {\n return new Plugin<DecorationSet>({\n key: new PluginKey('dou-editor-numbering'),\n state: structureDecorations(numberDecorations),\n props: {\n decorations(state) {\n return this.getState(state)\n },\n },\n })\n}\n\nexport interface PlaceholderOptions {\n /** The hint in the empty block the cursor is in. */\n text: () => string\n /** The hint in an empty heading. */\n heading: () => string\n /** The hint when the whole document is one empty paragraph. */\n empty: () => string\n}\n\n/** A hint inside the empty block under the cursor, and in an empty document. */\nexport function placeholderPlugin(options: PlaceholderOptions): Plugin {\n return new Plugin({\n key: new PluginKey('dou-editor-placeholder'),\n props: {\n decorations(state) {\n const { doc, selection } = state\n const decorations: Decoration[] = []\n const onlyBlock =\n doc.childCount === 1 && doc.firstChild!.childCount === 1 && doc.firstChild!.firstChild!\n if (onlyBlock && onlyBlock.type.name === 'paragraph' && onlyBlock.content.size === 0) {\n decorations.push(\n Decoration.node(1, 1 + onlyBlock.nodeSize, {\n class: 'is-empty',\n 'data-placeholder': options.empty(),\n }),\n )\n return DecorationSet.create(doc, decorations)\n }\n const { $from } = selection\n const parent = $from.parent\n if (!selection.empty || !parent.isTextblock || parent.content.size > 0) return null\n if (parent.type.spec.code) return null\n const text = parent.type.name === 'heading' ? options.heading() : options.text()\n const start = $from.before()\n decorations.push(\n Decoration.node(start, start + parent.nodeSize, {\n class: 'is-empty',\n 'data-placeholder': text,\n }),\n )\n return DecorationSet.create(doc, decorations)\n },\n },\n })\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,SAAS,IAA0B;CAEjD,OAAO,CAAC,CADK,GAAG,QAAQ,SACf,CAAA,EAAM,kBAAkB,GAAG,QAAQ,QAAQ,MAAM;AAC5D;;;;;;;AAQA,SAAgB,WAAmB;CACjC,OAAO,IAAI,OAAO;EAChB,KAAK,IAAI,UAAU,gBAAgB;EACnC,kBAAkB,cAAc,MAAM,OAAO;GAC3C,IAAI,CAAC,aAAa,MAAM,OAAO,GAAG,UAAU,KAAK,aAAa,MAAM,QAAQ,GAAG,OAAO;GACtF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