@dou-ui/editor 0.1.0-alpha.2 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code/code-editor-block.js.map +1 -1
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/block-handle.js.map +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/bubble-toolbar.js.map +1 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/comment-card.js.map +1 -1
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/core/editor.js +2 -1
- package/dist/core/editor.js.map +1 -1
- package/dist/core/plugins.js +108 -5
- package/dist/core/plugins.js.map +1 -1
- package/dist/dom.js +6 -1
- package/dist/dom.js.map +1 -1
- package/dist/extensions/align/align-menu.js.map +1 -1
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
- package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/colors/color-menu.js.map +1 -1
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
- package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +0 -1
- package/dist/types/core/plugins.d.ts +9 -0
- package/dist/types/dom.d.ts +2 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-editor-block.js","names":["_sfc_main"],"sources":["../../src/code/code-editor-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouCodeEditor, type CodeExtension } from '@dou-ui/code'\nimport { ChevronDownIcon } from '@dou-ui/icons'\nimport {\n DouCopyButton,\n DouDropdown,\n DouDropdownItem,\n DouDropdownRadioGroup,\n useGlobalConfig,\n} from 'dou-ui'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, shallowRef } from 'vue'\nimport { useEditor } from '../editor'\nimport { findCodeLanguage } from './languages'\nimport type { CodeEditorViewOptions, CodeEditorViewState } from './types'\n\nconst props = defineProps<{\n state: CodeEditorViewState\n options: CodeEditorViewOptions\n extensions: CodeExtension[]\n view: EditorView\n updateProps: (props: Record<string, unknown>) => void\n}>()\nconst emit = defineEmits<{ focus: [] }>()\n\nconst { messages } = useEditor()\nconst config = useGlobalConfig()\nconst editor = shallowRef<InstanceType<typeof DouCodeEditor>>()\n\nconst value = computed(() => String(props.state.block.props.language ?? ''))\nconst entry = computed(() => findCodeLanguage(props.options.languages, value.value))\n// a language the picker doesn't have (pasted, or set in code) still shows by its name\nconst choices = computed(() => {\n const list = [\n { value: '', label: messages.value.codeBlock.plainText },\n ...props.options.languages.map((item) => ({\n value: item.language.name,\n label: item.label,\n })),\n ]\n if (value.value && !entry.value) list.push({ value: value.value, label: value.value })\n return list\n})\nconst picked = computed(() => entry.value?.language.name ?? value.value)\nconst label = computed(() => entry.value?.label ?? value.value)\nconst ariaLabel = computed(() =>\n label.value ? `${messages.value.types.codeBlock} ${label.value}` : messages.value.types.codeBlock,\n)\n\nfunction choose(next: unknown) {\n props.updateProps({ language: String(next ?? '') })\n editor.value?.focus()\n}\n\n// read when the button is pressed: the code changes as it is edited\nconst code = () => editor.value?.doc.toString() ?? props.state.text\n</script>\n\n<template>\n <div class=\"dou-editor-code__bar\">\n <DouDropdown v-if=\"state.editable\" placement=\"bottom-end\">\n <button type=\"button\" class=\"dou-editor-code__language\" :title=\"messages.codeBlock.language\">\n {{ label || messages.codeBlock.plainText }}\n <ChevronDownIcon />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"picked\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"item in choices\" :key=\"item.value\" :value=\"item.value\">\n {{ item.label }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span v-else-if=\"label\" class=\"dou-editor-code__language is-static\">{{ label }}</span>\n <DouCopyButton :text=\"code\" size=\"sm\" />\n </div>\n <DouCodeEditor\n ref=\"editor\"\n class=\"dou-editor-code__editor\"\n :model-value=\"state.text\"\n :language=\"entry?.language ?? null\"\n :readonly=\"!state.editable\"\n :line-numbers=\"options.lineNumbers ?? false\"\n :gutter=\"options.lineNumbers ?? false\"\n :wrap=\"options.wrap ?? false\"\n :tab-size=\"options.tabSize ?? 2\"\n :tab-indents=\"true\"\n :extensions=\"extensions\"\n :teleport=\"config.teleport || 'body'\"\n :aria-label=\"ariaLabel\"\n @focus=\"emit('focus')\"\n />\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"code-editor-block.js","names":["_sfc_main"],"sources":["../../src/code/code-editor-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouCodeEditor, type CodeExtension } from '@dou-ui/code'\nimport { ChevronDownIcon } from '@dou-ui/icons'\nimport {\n DouCopyButton,\n DouDropdown,\n DouDropdownItem,\n DouDropdownRadioGroup,\n useGlobalConfig,\n} from 'dou-ui'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, shallowRef } from 'vue'\nimport { useEditor } from '../editor'\nimport { findCodeLanguage } from './languages'\nimport type { CodeEditorViewOptions, CodeEditorViewState } from './types'\n\nconst props = defineProps<{\n state: CodeEditorViewState\n options: CodeEditorViewOptions\n extensions: CodeExtension[]\n view: EditorView\n updateProps: (props: Record<string, unknown>) => void\n}>()\nconst emit = defineEmits<{ focus: [] }>()\n\nconst { messages } = useEditor()\nconst config = useGlobalConfig()\nconst editor = shallowRef<InstanceType<typeof DouCodeEditor>>()\n\nconst value = computed(() => String(props.state.block.props.language ?? ''))\nconst entry = computed(() => findCodeLanguage(props.options.languages, value.value))\n// a language the picker doesn't have (pasted, or set in code) still shows by its name\nconst choices = computed(() => {\n const list = [\n { value: '', label: messages.value.codeBlock.plainText },\n ...props.options.languages.map((item) => ({\n value: item.language.name,\n label: item.label,\n })),\n ]\n if (value.value && !entry.value) list.push({ value: value.value, label: value.value })\n return list\n})\nconst picked = computed(() => entry.value?.language.name ?? value.value)\nconst label = computed(() => entry.value?.label ?? value.value)\nconst ariaLabel = computed(() =>\n label.value ? `${messages.value.types.codeBlock} ${label.value}` : messages.value.types.codeBlock,\n)\n\nfunction choose(next: unknown) {\n props.updateProps({ language: String(next ?? '') })\n editor.value?.focus()\n}\n\n// read when the button is pressed: the code changes as it is edited\nconst code = () => editor.value?.doc.toString() ?? props.state.text\n</script>\n\n<template>\n <div class=\"dou-editor-code__bar\">\n <DouDropdown v-if=\"state.editable\" placement=\"bottom-end\">\n <button type=\"button\" class=\"dou-editor-code__language\" :title=\"messages.codeBlock.language\">\n {{ label || messages.codeBlock.plainText }}\n <ChevronDownIcon />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"picked\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"item in choices\" :key=\"item.value\" :value=\"item.value\">\n {{ item.label }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span v-else-if=\"label\" class=\"dou-editor-code__language is-static\">{{ label }}</span>\n <DouCopyButton :text=\"code\" size=\"sm\" />\n </div>\n <DouCodeEditor\n ref=\"editor\"\n class=\"dou-editor-code__editor\"\n :model-value=\"state.text\"\n :language=\"entry?.language ?? null\"\n :readonly=\"!state.editable\"\n :line-numbers=\"options.lineNumbers ?? false\"\n :gutter=\"options.lineNumbers ?? false\"\n :bordered=\"false\"\n :wrap=\"options.wrap ?? false\"\n :tab-size=\"options.tabSize ?? 2\"\n :tab-indents=\"true\"\n :extensions=\"extensions\"\n :teleport=\"config.teleport || 'body'\"\n :aria-label=\"ariaLabel\"\n @focus=\"emit('focus')\"\n />\n</template>\n"],"mappings":""}
|
|
@@ -89,6 +89,7 @@ var code_editor_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*
|
|
|
89
89
|
readonly: !__props.state.editable,
|
|
90
90
|
"line-numbers": __props.options.lineNumbers ?? false,
|
|
91
91
|
gutter: __props.options.lineNumbers ?? false,
|
|
92
|
+
bordered: false,
|
|
92
93
|
wrap: __props.options.wrap ?? false,
|
|
93
94
|
"tab-size": __props.options.tabSize ?? 2,
|
|
94
95
|
"tab-indents": true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-editor-block.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_createElementVNode","_createBlock","_unref","_withCtx","_createVNode","_renderList","_createTextVNode","_toDisplayString","_createCommentVNode"],"sources":["../../src/code/code-editor-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouCodeEditor, type CodeExtension } from '@dou-ui/code'\nimport { ChevronDownIcon } from '@dou-ui/icons'\nimport {\n DouCopyButton,\n DouDropdown,\n DouDropdownItem,\n DouDropdownRadioGroup,\n useGlobalConfig,\n} from 'dou-ui'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, shallowRef } from 'vue'\nimport { useEditor } from '../editor'\nimport { findCodeLanguage } from './languages'\nimport type { CodeEditorViewOptions, CodeEditorViewState } from './types'\n\nconst props = defineProps<{\n state: CodeEditorViewState\n options: CodeEditorViewOptions\n extensions: CodeExtension[]\n view: EditorView\n updateProps: (props: Record<string, unknown>) => void\n}>()\nconst emit = defineEmits<{ focus: [] }>()\n\nconst { messages } = useEditor()\nconst config = useGlobalConfig()\nconst editor = shallowRef<InstanceType<typeof DouCodeEditor>>()\n\nconst value = computed(() => String(props.state.block.props.language ?? ''))\nconst entry = computed(() => findCodeLanguage(props.options.languages, value.value))\n// a language the picker doesn't have (pasted, or set in code) still shows by its name\nconst choices = computed(() => {\n const list = [\n { value: '', label: messages.value.codeBlock.plainText },\n ...props.options.languages.map((item) => ({\n value: item.language.name,\n label: item.label,\n })),\n ]\n if (value.value && !entry.value) list.push({ value: value.value, label: value.value })\n return list\n})\nconst picked = computed(() => entry.value?.language.name ?? value.value)\nconst label = computed(() => entry.value?.label ?? value.value)\nconst ariaLabel = computed(() =>\n label.value ? `${messages.value.types.codeBlock} ${label.value}` : messages.value.types.codeBlock,\n)\n\nfunction choose(next: unknown) {\n props.updateProps({ language: String(next ?? '') })\n editor.value?.focus()\n}\n\n// read when the button is pressed: the code changes as it is edited\nconst code = () => editor.value?.doc.toString() ?? props.state.text\n</script>\n\n<template>\n <div class=\"dou-editor-code__bar\">\n <DouDropdown v-if=\"state.editable\" placement=\"bottom-end\">\n <button type=\"button\" class=\"dou-editor-code__language\" :title=\"messages.codeBlock.language\">\n {{ label || messages.codeBlock.plainText }}\n <ChevronDownIcon />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"picked\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"item in choices\" :key=\"item.value\" :value=\"item.value\">\n {{ item.label }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span v-else-if=\"label\" class=\"dou-editor-code__language is-static\">{{ label }}</span>\n <DouCopyButton :text=\"code\" size=\"sm\" />\n </div>\n <DouCodeEditor\n ref=\"editor\"\n class=\"dou-editor-code__editor\"\n :model-value=\"state.text\"\n :language=\"entry?.language ?? null\"\n :readonly=\"!state.editable\"\n :line-numbers=\"options.lineNumbers ?? false\"\n :gutter=\"options.lineNumbers ?? false\"\n :wrap=\"options.wrap ?? false\"\n :tab-size=\"options.tabSize ?? 2\"\n :tab-indents=\"true\"\n :extensions=\"extensions\"\n :teleport=\"config.teleport || 'body'\"\n :aria-label=\"ariaLabel\"\n @focus=\"emit('focus')\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAgBA,MAAM,QAAQ;EAOd,MAAM,OAAO;EAEb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,WAFc,QAAA,QAAR,SAAI;MAA5B,OAAAR,UAAA,GAAAI,YAEkBC,MAAA,eAAA,GAAA;OAFwB,KAAK,KAAK;OAAQ,OAAO,KAAK;;OACtE,SAAAC,cAAgB,CAAbG,gBAAAC,gBAAA,KAAK,KAAK,GAAA,CAAA,C;;;;;;IAPnB,SAAAJ,cAGS,CAHTH,mBAGS,UAAA;KAHD,MAAK;KAAS,OAAM;KAA6B,OAAOE,MAAA,QAAA,CAAQ,CAAC,UAAU;I,IAC9EI,gBAAAC,gBAAA,MAAA,SAASL,MAAA,QAAA,CAAQ,CAAC,UAAU,SAAS,IAAG,KAC3C,CAAA,GAAAE,YAAmBF,MAAA,eAAA,CAAA,C;;G,MAUN,MAAA,SAAjBL,UAAA,GAAAC,mBAAsF,QAAtF,YAAsFS,gBAAf,MAAA,KAAK,GAAA,CAAA,K,8BAC5EH,YAAwCF,MAAA,aAAA,GAAA;IAAxB,MAAM;IAAM,MAAK;G,MAEnCE,
|
|
1
|
+
{"version":3,"file":"code-editor-block.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_createElementVNode","_createBlock","_unref","_withCtx","_createVNode","_renderList","_createTextVNode","_toDisplayString","_createCommentVNode"],"sources":["../../src/code/code-editor-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DouCodeEditor, type CodeExtension } from '@dou-ui/code'\nimport { ChevronDownIcon } from '@dou-ui/icons'\nimport {\n DouCopyButton,\n DouDropdown,\n DouDropdownItem,\n DouDropdownRadioGroup,\n useGlobalConfig,\n} from 'dou-ui'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, shallowRef } from 'vue'\nimport { useEditor } from '../editor'\nimport { findCodeLanguage } from './languages'\nimport type { CodeEditorViewOptions, CodeEditorViewState } from './types'\n\nconst props = defineProps<{\n state: CodeEditorViewState\n options: CodeEditorViewOptions\n extensions: CodeExtension[]\n view: EditorView\n updateProps: (props: Record<string, unknown>) => void\n}>()\nconst emit = defineEmits<{ focus: [] }>()\n\nconst { messages } = useEditor()\nconst config = useGlobalConfig()\nconst editor = shallowRef<InstanceType<typeof DouCodeEditor>>()\n\nconst value = computed(() => String(props.state.block.props.language ?? ''))\nconst entry = computed(() => findCodeLanguage(props.options.languages, value.value))\n// a language the picker doesn't have (pasted, or set in code) still shows by its name\nconst choices = computed(() => {\n const list = [\n { value: '', label: messages.value.codeBlock.plainText },\n ...props.options.languages.map((item) => ({\n value: item.language.name,\n label: item.label,\n })),\n ]\n if (value.value && !entry.value) list.push({ value: value.value, label: value.value })\n return list\n})\nconst picked = computed(() => entry.value?.language.name ?? value.value)\nconst label = computed(() => entry.value?.label ?? value.value)\nconst ariaLabel = computed(() =>\n label.value ? `${messages.value.types.codeBlock} ${label.value}` : messages.value.types.codeBlock,\n)\n\nfunction choose(next: unknown) {\n props.updateProps({ language: String(next ?? '') })\n editor.value?.focus()\n}\n\n// read when the button is pressed: the code changes as it is edited\nconst code = () => editor.value?.doc.toString() ?? props.state.text\n</script>\n\n<template>\n <div class=\"dou-editor-code__bar\">\n <DouDropdown v-if=\"state.editable\" placement=\"bottom-end\">\n <button type=\"button\" class=\"dou-editor-code__language\" :title=\"messages.codeBlock.language\">\n {{ label || messages.codeBlock.plainText }}\n <ChevronDownIcon />\n </button>\n <template #menu>\n <DouDropdownRadioGroup :model-value=\"picked\" @update:model-value=\"choose\">\n <DouDropdownItem v-for=\"item in choices\" :key=\"item.value\" :value=\"item.value\">\n {{ item.label }}\n </DouDropdownItem>\n </DouDropdownRadioGroup>\n </template>\n </DouDropdown>\n <span v-else-if=\"label\" class=\"dou-editor-code__language is-static\">{{ label }}</span>\n <DouCopyButton :text=\"code\" size=\"sm\" />\n </div>\n <DouCodeEditor\n ref=\"editor\"\n class=\"dou-editor-code__editor\"\n :model-value=\"state.text\"\n :language=\"entry?.language ?? null\"\n :readonly=\"!state.editable\"\n :line-numbers=\"options.lineNumbers ?? false\"\n :gutter=\"options.lineNumbers ?? false\"\n :bordered=\"false\"\n :wrap=\"options.wrap ?? false\"\n :tab-size=\"options.tabSize ?? 2\"\n :tab-indents=\"true\"\n :extensions=\"extensions\"\n :teleport=\"config.teleport || 'body'\"\n :aria-label=\"ariaLabel\"\n @focus=\"emit('focus')\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAgBA,MAAM,QAAQ;EAOd,MAAM,OAAO;EAEb,MAAM,EAAE,aAAa,UAAU;EAC/B,MAAM,SAAS,gBAAgB;EAC/B,MAAM,SAAS,WAA+C;EAE9D,MAAM,QAAQ,eAAe,OAAO,MAAM,MAAM,MAAM,MAAM,YAAY,EAAE,CAAC;EAC3E,MAAM,QAAQ,eAAe,iBAAiB,MAAM,QAAQ,WAAW,MAAM,KAAK,CAAC;EAEnF,MAAM,UAAU,eAAe;GAC7B,MAAM,OAAO,CACX;IAAE,OAAO;IAAI,OAAO,SAAS,MAAM,UAAU;GAAU,GACvD,GAAG,MAAM,QAAQ,UAAU,KAAK,UAAU;IACxC,OAAO,KAAK,SAAS;IACrB,OAAO,KAAK;GACd,EAAE,CACJ;GACA,IAAI,MAAM,SAAS,CAAC,MAAM,OAAO,KAAK,KAAK;IAAE,OAAO,MAAM;IAAO,OAAO,MAAM;GAAM,CAAC;GACrF,OAAO;EACT,CAAC;EACD,MAAM,SAAS,eAAe,MAAM,OAAO,SAAS,QAAQ,MAAM,KAAK;EACvE,MAAM,QAAQ,eAAe,MAAM,OAAO,SAAS,MAAM,KAAK;EAC9D,MAAM,YAAY,eAChB,MAAM,QAAQ,GAAG,SAAS,MAAM,MAAM,UAAU,GAAG,MAAM,UAAU,SAAS,MAAM,MAAM,SAC1F;EAEA,SAAS,OAAO,MAAe;GAC7B,MAAM,YAAY,EAAE,UAAU,OAAO,QAAQ,EAAE,EAAE,CAAC;GAClD,OAAO,OAAO,MAAM;EACtB;EAGA,MAAM,aAAa,OAAO,OAAO,IAAI,SAAS,KAAK,MAAM,MAAM;;G,wDAI7DG,mBAgBM,OAhBN,YAgBM,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,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n drop.value = { pos, top: y - box.top, left: left - box.left, width: box.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"block-handle.js","names":["_sfc_main"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: rect.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-handle.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n drop.value = { pos, top: y - box.top, left: left - box.left, width: box.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EA0CA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;EAOhF,MAAM,QAAQ,WAAW,KAAK;EAC9B,IAAI,QAA+B;EACnC,MAAM,gBAAiB,MAAM,QAAQ,CAAC,CAAC,OAAO;;EAG9C,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,WAAW,WAAiE,IAAI;EACtF,MAAM,WAAW,WAAW,KAAK;EACjC,cAAc,gBAAiB,SAAS,QAAQ,KAAM;EAEtD,MAAM,OAAO,WAA6E,IAAI;EAE9F,MAAM,UAAU,WAAW,KAAK;EAEhC,MAAM,UAAU,eAAe;GAC7B,IAAI,CAAC,SAAS,OAAO,OAAO;GAC5B,IAAI,SAAS,SAAS,SAAS,OAAO,OAAO;GAC7C,IAAI,MAAM,OAAO,OAAO,QAAQ,SAAU,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,kBAAkB,MAAM,KAAK;GAC1F,OAAO,CAAC,QAAQ;EAClB,CAAC;EAED,SAAS,MAAM,SAAsB;GAEnC,MAAM,KADQ,eAAe,OAClB,CAAA,EAAO,QAAQ;GAC1B,MAAM,OAAO,KAAK;GAClB,IAAI,CAAC,MAAM,CAAC,MAAM;GAClB,MAAM,MAAM,KAAK,sBAAsB;GACvC,MAAM,OAAO,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setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_withDirectives","_createElementVNode","_normalizeStyle","_withModifiers","_unref","_createVNode","_withCtx","_renderList","_createBlock","_createSlots","_resolveDynamicComponent","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../src/components/block-handle.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n CheckIcon,\n CopyIcon,\n GripVerticalIcon,\n PlusIcon,\n TrashIcon,\n} from '@dou-ui/icons'\nimport { DouDropdown, DouDropdownItem, DouDropdownSub } from 'dou-ui'\nimport { TextSelection } from 'prosemirror-state'\nimport { computed, inject, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'\nimport { isCurrent } from '../catalog'\nimport { labelOf, type BlockOption } from '../core/extension'\nimport {\n blockSelectionKey,\n blockSelectionRange,\n getBlockSelection,\n selectBlocks,\n} from '../core/block-selection'\nimport {\n blockAround,\n blocksIn,\n findBlockById,\n siblingRangeBetween,\n type SiblingRange,\n} from '../core/blocks'\nimport {\n duplicateBlocks,\n insertBlockAfter,\n swapBlocks,\n moveRangeTo,\n deleteBlocks,\n setBlockType,\n} from '../core/commands'\nimport { blockFromNode } from '../core/model'\nimport { slashKey } from '../core/slash'\nimport { blockElementOf, contentAt, firstLine, scrollParent } from '../dom'\nimport { editorKey } from '../editor'\nimport { useMenuEscape } from './menu-escape'\n\nconst { view, state, focused, messages, root, dragging, kit } = inject(editorKey)!\n\n/**\n * Touch screens have no hover: there the handle shows only the grip, next\n * to the block with the cursor (or the selected blocks) while the editor\n * has focus. A tap on it opens the menu, a press and drag moves the block.\n */\nconst touch = shallowRef(false)\nlet media: MediaQueryList | null = null\nconst onMedia = () => (touch.value = !!media?.matches)\n\n/** The block the handle is next to, by id. */\nconst hovered = shallowRef<string | null>(null)\nconst position = shallowRef<{ top: number; left: number; height: number } | null>(null)\nconst menuOpen = shallowRef(false)\nuseMenuEscape(menuOpen, () => (menuOpen.value = false))\n\nconst drop = shallowRef<{ pos: number; top: number; left: number; width: number } | null>(null)\n// typing hides the handle until the pointer moves again\nconst resting = shallowRef(false)\n\nconst visible = computed(() => {\n if (!position.value) return false\n if (menuOpen.value || dragging.value) return true\n if (touch.value) return focused.value || (!!state.value && !!getBlockSelection(state.value))\n return !resting.value\n})\n\nfunction place(content: HTMLElement) {\n const block = blockElementOf(content)\n const id = block?.dataset.blockId\n const host = root.value\n if (!id || !host) return\n const box = host.getBoundingClientRect()\n const line = firstLine(content)\n hovered.value = id\n position.value = {\n top: line.top - box.top,\n left: content.getBoundingClientRect().left - box.left,\n height: line.height,\n }\n}\n\nlet frame = 0\nlet lastY = 0\nlet lastX = 0\n\nfunction track(event: PointerEvent) {\n // a finger only moves the handle by moving the cursor; a drag reports itself\n if (event.pointerType === 'touch') return\n lastY = event.clientY\n lastX = event.clientX\n resting.value = false\n if (menuOpen.value || frame) return\n frame = requestAnimationFrame(() => {\n frame = 0\n if (dragging.value) return updateDrop()\n const current = view.value\n if (!current || menuOpen.value) return\n const content = contentAt(current, lastY)\n if (content) place(content)\n })\n}\n\nfunction leave(event: PointerEvent) {\n if (menuOpen.value || dragging.value || event.pointerType === 'touch') return\n position.value = null\n hovered.value = null\n}\n\n/** On touch screens: put the handle next to the block with the cursor. */\nfunction follow() {\n const current = view.value\n if (!current || dragging.value) return\n const selected = blockSelectionRange(current.state)\n const info = selected ? blocksIn(selected)[0] : blockAround(current.state.selection.$from)\n const element = info\n ? (current.nodeDOM(info.pos) as HTMLElement | null)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__content',\n )\n : null\n if (element) place(element)\n else {\n position.value = null\n hovered.value = null\n }\n}\n\nlet followFrame = 0\nfunction scheduleFollow() {\n if (!touch.value || followFrame) return\n followFrame = requestAnimationFrame(() => {\n followFrame = 0\n if (touch.value && !menuOpen.value) follow()\n })\n}\n\nwatch([state, focused, touch], scheduleFollow)\n\nonMounted(() => {\n media = window.matchMedia('(pointer: coarse)')\n onMedia()\n media.addEventListener('change', onMedia)\n window.addEventListener('resize', scheduleFollow)\n root.value?.addEventListener('pointermove', track)\n root.value?.addEventListener('pointerleave', leave)\n})\nonBeforeUnmount(() => {\n media?.removeEventListener('change', onMedia)\n window.removeEventListener('resize', scheduleFollow)\n if (followFrame) cancelAnimationFrame(followFrame)\n root.value?.removeEventListener('pointermove', track)\n root.value?.removeEventListener('pointerleave', leave)\n if (frame) cancelAnimationFrame(frame)\n stopDrag()\n})\n\n// follow edits: keep the handle on its block, or hide it while typing\nwatch(state, (next, previous) => {\n if (touch.value || !next || !previous || next.doc === previous.doc || dragging.value) return\n if (!menuOpen.value) resting.value = true\n requestAnimationFrame(() => {\n const current = view.value\n if (!current || !hovered.value) return\n const element = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(hovered.value)}\"] > .dou-editor__content`,\n )\n if (element) place(element)\n else position.value = null\n })\n})\n\nconst target = computed(() => {\n const doc = state.value?.doc\n return doc && hovered.value ? findBlockById(doc, hovered.value) : null\n})\n\n/** The hovered block, or every selected block when it is one of them. */\nfunction rangeForHovered(): SiblingRange | null {\n const current = view.value\n const info = target.value\n if (!current || !info) return null\n const selected = blockSelectionRange(current.state)\n if (selected && info.pos >= selected.start && info.pos < selected.end) return selected\n return siblingRangeBetween(current.state.doc, info.pos + 1, info.pos + 1)\n}\n\n/** Select the blocks the menu or a drag acts on. */\nfunction selectTarget(): SiblingRange | null {\n const current = view.value\n const range = rangeForHovered()\n if (!current || !range) return null\n const blocks = blocksIn(range)\n selectBlocks(blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id)(\n current.state,\n current.dispatch,\n )\n return blockSelectionRange(current.state)\n}\n\n/* the + button */\n\nfunction add(event: MouseEvent) {\n const current = view.value\n const info = target.value\n if (!current || !info) return\n const empty = info.content.isTextblock && info.content.content.size === 0\n if (!empty || info.content.type.name !== 'paragraph') {\n insertBlockAfter(info.pos)(current.state, current.dispatch)\n // Alt+click adds the block above instead\n if (event.altKey) swapBlocks(-1)(current.state, current.dispatch)\n } else {\n const tr = current.state.tr.setSelection(\n TextSelection.create(current.state.doc, info.contentPos + 1),\n )\n current.dispatch(tr)\n }\n const from = current.state.selection.from\n current.dispatch(current.state.tr.insertText('/').setMeta(slashKey, { from, query: '' }))\n current.focus()\n}\n\n/* the block menu */\n\nconst turnOptions = kit.blockOptions.filter(\n (option) => !!kit.schema.nodes[option.type]?.isTextblock,\n)\nconst current = computed(() => {\n const info = target.value\n return info ? blockFromNode(info.node) : null\n})\n\nfunction after(action: () => void) {\n action()\n // the menu gives focus back to the handle; the editor takes it after\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction keep(run: (current: NonNullable<typeof view.value>) => void) {\n after(() => {\n const instance = view.value\n if (!instance) return\n const selection = getBlockSelection(instance.state)\n run(instance)\n if (selection) selectBlocks(selection.anchor, selection.head)(instance.state, instance.dispatch)\n })\n}\n\nconst turnInto = (option: BlockOption) =>\n keep((instance) => setBlockType(option.type, option.props)(instance.state, instance.dispatch))\nconst duplicate = () => keep((instance) => duplicateBlocks(instance.state, instance.dispatch))\nconst move = (direction: -1 | 1) =>\n keep((instance) => swapBlocks(direction)(instance.state, instance.dispatch))\n\nfunction remove() {\n after(() => {\n const instance = view.value\n const range = instance && blockSelectionRange(instance.state)\n if (!instance || !range) return\n const tr = deleteBlocks(instance.state.tr, blocksIn(range)).setMeta(blockSelectionKey, null)\n instance.dispatch(tr.scrollIntoView())\n position.value = null\n })\n}\n\nconst canMove = (direction: -1 | 1) => {\n const instance = view.value\n return !!instance && !!state.value && swapBlocks(direction)(instance.state)\n}\n\n/* dragging */\n\nlet start: { x: number; y: number; pointer: number; touch: boolean } | null = null\nlet range: SiblingRange | null = null\nlet scroller: HTMLElement | null = null\nlet scrollFrame = 0\n/** A copy of the dragged blocks that follows the pointer. */\nlet ghost: HTMLElement | null = null\n\nfunction showGhost(moving: SiblingRange) {\n const instance = view.value\n const host = root.value\n if (!instance || !host) return\n ghost = document.createElement('div')\n ghost.className = 'dou-editor__surface dou-editor__ghost'\n ghost.setAttribute('aria-hidden', 'true')\n let width = 0\n for (const block of blocksIn(moving)) {\n const element = instance.nodeDOM(block.pos) as HTMLElement | null\n if (!element) continue\n width = Math.max(width, element.getBoundingClientRect().width)\n const copy = element.cloneNode(true) as HTMLElement\n copy.classList.remove('is-selected')\n for (const node of [copy, ...copy.querySelectorAll('[id], .is-selected')]) {\n node.removeAttribute('id')\n node.classList.remove('is-selected')\n }\n ghost.append(copy)\n }\n ghost.style.width = `${Math.min(width, 360)}px`\n host.append(ghost)\n moveGhost()\n}\n\nfunction moveGhost() {\n if (!ghost) return\n // above a finger, which would hide it; below and right of a mouse pointer\n const y = start?.touch ? lastY - ghost.offsetHeight - 24 : lastY + 12\n ghost.style.transform = `translate(${lastX + 12}px, ${y}px)`\n}\n\nfunction onGripDown(event: PointerEvent) {\n if (event.button !== 0) return\n start = {\n x: event.clientX,\n y: event.clientY,\n pointer: event.pointerId,\n touch: event.pointerType === 'touch',\n }\n ;(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId)\n}\n\nfunction onGripMove(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n lastX = event.clientX\n lastY = event.clientY\n if (!dragging.value) {\n // a finger wobbles more than a mouse while tapping\n const slop = start.touch ? 8 : 4\n if (Math.hypot(event.clientX - start.x, event.clientY - start.y) < slop) return\n range = selectTarget()\n if (!range) return stopDrag()\n dragging.value = true\n scroller = root.value && scrollParent(root.value)\n window.addEventListener('keydown', onDragKey, true)\n showGhost(range)\n autoScroll()\n }\n moveGhost()\n updateDrop()\n}\n\nfunction onGripUp(event: PointerEvent) {\n if (!start || event.pointerId !== start.pointer) return\n if (dragging.value) finishDrag()\n else if (menuOpen.value) menuOpen.value = false\n else {\n selectTarget()\n menuOpen.value = true\n }\n start = null\n}\n\nfunction onDragKey(event: KeyboardEvent) {\n if (event.key !== 'Escape') return\n event.preventDefault()\n event.stopPropagation()\n stopDrag()\n}\n\nfunction updateDrop() {\n const instance = view.value\n const host = root.value\n if (!instance || !host || !range) return\n const content = contentAt(instance, lastY)\n const id = content && blockElementOf(content)?.dataset.blockId\n const info = id ? findBlockById(instance.state.doc, id) : null\n if (!content || !info) return (drop.value = null)\n const box = host.getBoundingClientRect()\n const rect = content.getBoundingClientRect()\n const below = lastY > rect.top + rect.height / 2\n let pos: number\n let y: number\n let left = rect.left\n if (!below) {\n pos = info.pos\n y = rect.top\n } else if (info.group) {\n // the lower half of a block with children: in front of its first child\n pos = info.contentPos + info.content.nodeSize + 1\n y = rect.bottom\n const child = blockElementOf(content)?.querySelector<HTMLElement>(\n ':scope > .dou-editor__group > .dou-editor__block > .dou-editor__content',\n )\n left = child?.getBoundingClientRect().left ?? rect.left\n } else {\n pos = info.pos + info.node.nodeSize\n y = blockElementOf(content)!.getBoundingClientRect().bottom\n }\n if (!moveRangeTo(range, pos)(instance.state)) return (drop.value = null)\n // to the end of the text column, which a reading width can end before the editor\n drop.value = { pos, top: y - box.top, left: left - box.left, width: rect.right - left }\n}\n\nfunction autoScroll() {\n scrollFrame = requestAnimationFrame(() => {\n if (!dragging.value) return\n const edge = 48\n const top = scroller ? scroller.getBoundingClientRect().top : 0\n const bottom = scroller ? scroller.getBoundingClientRect().bottom : window.innerHeight\n let speed = 0\n if (lastY < top + edge) speed = -Math.ceil(((top + edge - lastY) / edge) * 16)\n else if (lastY > bottom - edge) speed = Math.ceil(((lastY - bottom + edge) / edge) * 16)\n if (speed) {\n if (scroller) scroller.scrollTop += speed\n else window.scrollBy(0, speed)\n updateDrop()\n }\n autoScroll()\n })\n}\n\nfunction finishDrag() {\n const instance = view.value\n const spot = drop.value\n const moving = range\n stopDrag()\n if (!instance || !spot || !moving) return\n const ids = blocksIn(moving).map((block) => block.node.attrs.id as string)\n if (!moveRangeTo(moving, spot.pos)(instance.state, instance.dispatch)) return\n selectBlocks(ids[0]!, ids.at(-1)!)(instance.state, instance.dispatch)\n instance.focus()\n}\n\nfunction stopDrag() {\n dragging.value = false\n drop.value = null\n range = null\n start = null\n ghost?.remove()\n ghost = null\n if (scrollFrame) cancelAnimationFrame(scrollFrame)\n scrollFrame = 0\n window.removeEventListener('keydown', onDragKey, true)\n}\n\nwatch(menuOpen, (value) => {\n if (value) return\n if (touch.value) scheduleFollow()\n else if (!root.value?.matches(':hover')) position.value = null\n})\n</script>\n\n<template>\n <div\n v-show=\"visible\"\n class=\"dou-editor__handle\"\n :style=\"\n position\n ? {\n top: `${position.top}px`,\n left: `${position.left}px`,\n '--dou-editor-line': `${position.height}px`,\n }\n : undefined\n \"\n @mousedown.prevent\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__add\"\n :aria-label=\"messages.addBlock\"\n :title=\"messages.addBlock\"\n @click=\"add\"\n >\n <PlusIcon />\n </button>\n <DouDropdown\n v-model:open=\"menuOpen\"\n trigger=\"manual\"\n placement=\"bottom-start\"\n class=\"dou-editor-menu\"\n >\n <button\n type=\"button\"\n tabindex=\"-1\"\n class=\"dou-editor__handle-button dou-editor__grip\"\n :aria-label=\"messages.dragHandle\"\n :title=\"messages.dragHandle\"\n @pointerdown=\"onGripDown\"\n @pointermove=\"onGripMove\"\n @pointerup=\"onGripUp\"\n @pointercancel=\"stopDrag\"\n >\n <GripVerticalIcon />\n </button>\n <template #menu>\n <DouDropdownSub :title=\"messages.turnInto\">\n <DouDropdownItem\n v-for=\"option in turnOptions\"\n :key=\"option.key\"\n @click=\"turnInto(option)\"\n >\n <template #prefix><component :is=\"option.icon\" /></template>\n {{ labelOf(option.label, messages) }}\n <template v-if=\"current && isCurrent(option, current.type, current.props)\" #suffix>\n <CheckIcon />\n </template>\n </DouDropdownItem>\n </DouDropdownSub>\n <template v-if=\"current\">\n <component\n :is=\"entry\"\n v-for=\"(entry, index) in kit.blockMenu\"\n :key=\"index\"\n :block=\"current\"\n />\n </template>\n <DouDropdownItem :shortcut=\"touch ? undefined : 'mod+d'\" @click=\"duplicate\">\n <template #prefix><CopyIcon /></template>\n {{ messages.duplicate }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(-1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+up'\"\n @click=\"move(-1)\"\n >\n <template #prefix><ArrowUpIcon /></template>\n {{ messages.moveUp }}\n </DouDropdownItem>\n <DouDropdownItem\n :disabled=\"!canMove(1)\"\n :shortcut=\"touch ? undefined : 'mod+shift+down'\"\n @click=\"move(1)\"\n >\n <template #prefix><ArrowDownIcon /></template>\n {{ messages.moveDown }}\n </DouDropdownItem>\n <DouDropdownItem\n divided\n tone=\"danger\"\n :shortcut=\"touch ? undefined : 'delete'\"\n @click=\"remove\"\n >\n <template #prefix><TrashIcon /></template>\n {{ messages.delete }}\n </DouDropdownItem>\n </template>\n </DouDropdown>\n </div>\n <div\n v-if=\"drop\"\n class=\"dou-editor__drop\"\n :style=\"{ top: `${drop.top}px`, left: `${drop.left}px`, width: `${drop.width}px` }\"\n />\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EA0CA,MAAM,EAAE,MAAM,OAAO,SAAS,UAAU,MAAM,UAAU,QAAQ,OAAO,SAAS;;;;;;EAOhF,MAAM,QAAQ,WAAW,KAAK;EAC9B,IAAI,QAA+B;EACnC,MAAM,gBAAiB,MAAM,QAAQ,CAAC,CAAC,OAAO;;EAG9C,MAAM,UAAU,WAA0B,IAAI;EAC9C,MAAM,WAAW,WAAiE,IAAI;EACtF,MAAM,WAAW,WAAW,KAAK;EACjC,cAAc,gBAAiB,SAAS,QAAQ,KAAM;EAEtD,MAAM,OAAO,WAA6E,IAAI;EAE9F,MAAM,UAAU,WAAW,KAAK;EAEhC,MAAM,UAAU,eAAe;GAC7B,IAAI,CAAC,SAAS,OAAO,OAAO;GAC5B,IAAI,SAAS,SAAS,SAAS,OAAO,OAAO;GAC7C,IAAI,MAAM,OAAO,OAAO,QAAQ,SAAU,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,kBAAkB,MAAM,KAAK;GAC1F,OAAO,CAAC,QAA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OAAA;;IAFA,OAAM;IACL,OAAKI,eAAA;KAAA,KAAA,GAAY,KAAA,MAAK,IAAG;KAAA,MAAA,GAAe,KAAA,MAAK,KAAI;KAAA,OAAA,GAAgB,KAAA,MAAK,MAAK;IAAA,CAAA"}
|
|
@@ -1 +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
|
|
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,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,MAAM;GACtB,IAAI,CAAC,WAAW,kBAAkB,OAAO,GAAG,OAAO;G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A,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,MAAM;GACtB,IAAI,CAAC,WAAW,kBAAkB,OAAO,GAAG,OAAO;GACnD,MAAM,EAAE,cAAc;GACtB,IAAI,EAAE,qBAAqB,kBAAkB,UAAU,OAAO,OAAO;GAErE,IAAI,OAAO;GACX,QAAQ,IAAI,aAAa,UAAU,MAAM,UAAU,KAAK,SAAS;IAC/D,IAAI,KAAK,eAAe,CAAC,KAAK,KAAK,KAAK,MAAM,OAAO;IACrD,OAAO,CAAC;GACV,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Q,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
|
|
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
|
|
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, {
|