@dou-ui/editor 0.1.0-alpha.2 → 0.1.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/collaboration/binding.js +371 -57
- package/dist/collaboration/binding.js.map +1 -1
- package/dist/collaboration/cursors.js +42 -10
- package/dist/collaboration/cursors.js.map +1 -1
- package/dist/collaboration/index.js +61 -11
- package/dist/collaboration/index.js.map +1 -1
- package/dist/collaboration/inline-diff.js +138 -0
- package/dist/collaboration/inline-diff.js.map +1 -0
- package/dist/collaboration/merged-props.js +152 -0
- package/dist/collaboration/merged-props.js.map +1 -0
- package/dist/collaboration/order.js +41 -1
- package/dist/collaboration/order.js.map +1 -1
- package/dist/collaboration/table.js +64 -25
- package/dist/collaboration/table.js.map +1 -1
- package/dist/collaboration/text.js +213 -1
- package/dist/collaboration/text.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 +125 -17
- 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/components/slash-choices.js +6 -0
- package/dist/components/slash-choices.js.map +1 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
- package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/slash-menu.js.map +1 -1
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
- package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/core/block-selection.js +32 -4
- package/dist/core/block-selection.js.map +1 -1
- package/dist/core/blocks.js +21 -3
- package/dist/core/blocks.js.map +1 -1
- package/dist/core/commands.js +125 -13
- package/dist/core/commands.js.map +1 -1
- package/dist/core/comments.js +85 -3
- package/dist/core/comments.js.map +1 -1
- package/dist/core/convert.js +3 -3
- package/dist/core/convert.js.map +1 -1
- package/dist/core/editor.js +2 -1
- package/dist/core/editor.js.map +1 -1
- package/dist/core/extension.js +6 -2
- package/dist/core/extension.js.map +1 -1
- package/dist/core/model.js +10 -3
- package/dist/core/model.js.map +1 -1
- package/dist/core/plugins.js +108 -5
- package/dist/core/plugins.js.map +1 -1
- package/dist/core/prepare.js +12 -5
- package/dist/core/prepare.js.map +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/transaction.js +19 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/define-block.js +8 -4
- package/dist/define-block.js.map +1 -1
- package/dist/document.js +59 -4
- package/dist/document.js.map +1 -1
- package/dist/dom.js +112 -13
- package/dist/dom.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/editor.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/editor2.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/callout/html.js +5 -4
- package/dist/extensions/callout/html.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/extensions/columns/column-picker.js +6 -0
- package/dist/extensions/columns/column-picker.js.map +1 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/columns-controls.js +6 -0
- package/dist/extensions/columns/columns-controls.js.map +1 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
- package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/columns/html.js +34 -0
- package/dist/extensions/columns/html.js.map +1 -0
- package/dist/extensions/columns/index.js +57 -0
- package/dist/extensions/columns/index.js.map +1 -0
- package/dist/extensions/columns/keys.js +53 -0
- package/dist/extensions/columns/keys.js.map +1 -0
- package/dist/extensions/columns/plugin.js +213 -0
- package/dist/extensions/columns/plugin.js.map +1 -0
- package/dist/extensions/columns/schema.js +58 -0
- package/dist/extensions/columns/schema.js.map +1 -0
- package/dist/extensions/columns/select-columns.js +6 -0
- package/dist/extensions/columns/select-columns.js.map +1 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
- package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/extensions/editor-kit.js +3 -1
- package/dist/extensions/editor-kit.js.map +1 -1
- package/dist/extensions/list-html.js +1 -1
- package/dist/extensions/list-html.js.map +1 -1
- package/dist/extensions/table/plugin.js +33 -1
- package/dist/extensions/table/plugin.js.map +1 -1
- package/dist/extensions/table/table-controls.js.map +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/extensions/table/view.js +25 -1
- package/dist/extensions/table/view.js.map +1 -1
- package/dist/flow/board-block.js +6 -0
- package/dist/flow/board-block.js.map +1 -0
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/flow/board.js +221 -0
- package/dist/flow/board.js.map +1 -0
- package/dist/flow/index.js +173 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/locale.js +78 -6
- package/dist/locale.js.map +1 -1
- package/dist/markdown/index.js +2 -2
- package/dist/markdown/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -1
- package/dist/types/collaboration/binding.d.ts +12 -0
- package/dist/types/collaboration/cursors.d.ts +29 -1
- package/dist/types/collaboration/index.d.ts +53 -6
- package/dist/types/collaboration/inline-diff.d.ts +9 -0
- package/dist/types/collaboration/merged-props.d.ts +20 -0
- package/dist/types/collaboration/order.d.ts +5 -0
- package/dist/types/collaboration/table.d.ts +5 -1
- package/dist/types/collaboration/text.d.ts +20 -0
- package/dist/types/components/slash-choices.vue.d.ts +18 -0
- package/dist/types/core/blocks.d.ts +10 -0
- package/dist/types/core/commands.d.ts +17 -2
- package/dist/types/core/comments.d.ts +39 -3
- package/dist/types/core/convert.d.ts +10 -2
- package/dist/types/core/extension.d.ts +58 -4
- package/dist/types/core/model.d.ts +6 -1
- package/dist/types/core/plugins.d.ts +9 -0
- package/dist/types/core/prepare.d.ts +16 -2
- package/dist/types/core/schema.d.ts +1 -1
- package/dist/types/core/transaction.d.ts +6 -0
- package/dist/types/define-block.d.ts +16 -4
- package/dist/types/document.d.ts +5 -2
- package/dist/types/dom.d.ts +43 -4
- package/dist/types/editor.d.ts +9 -1
- package/dist/types/editor.vue.d.ts +24 -0
- package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
- package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
- package/dist/types/extensions/columns/html.d.ts +10 -0
- package/dist/types/extensions/columns/index.d.ts +9 -0
- package/dist/types/extensions/columns/keys.d.ts +6 -0
- package/dist/types/extensions/columns/plugin.d.ts +28 -0
- package/dist/types/extensions/columns/schema.d.ts +17 -0
- package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
- package/dist/types/extensions/editor-kit.d.ts +4 -1
- package/dist/types/extensions/table/view.d.ts +8 -1
- package/dist/types/flow/board-block.vue.d.ts +16 -0
- package/dist/types/flow/board.d.ts +53 -0
- package/dist/types/flow/index.d.ts +65 -0
- package/dist/types/index.d.ts +29 -4
- package/dist/types/locale.d.ts +34 -0
- package/dist/types/markdown/index.d.ts +8 -1
- package/dist/use-comments.js +2 -2
- package/dist/use-comments.js.map +1 -1
- package/package.json +14 -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,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,CAfe,QAAA,MAAM,YAAzBH,UAAA,GAAAI,YAYcC,MAAA,WAAA,GAAA;;IAZqB,WAAU;;IAKhC,MAAIC,cAKW,CAJxBC,YAIwBF,MAAA,qBAAA,GAAA;KAJA,eAAa,OAAA;KAAS,uBAAoB;;KAC/C,SAAAC,cAAuB,EAAxCN,UAAA,IAAA,GAAAC,mBAEkBC,UAAA,MAAAM,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,CAfe,QAAA,MAAM,YAAzBH,UAAA,GAAAI,YAYcC,MAAA,WAAA,GAAA;;IAZqB,WAAU;;IAKhC,MAAIC,cAKW,CAJxBC,YAIwBF,MAAA,qBAAA,GAAA;KAJA,eAAa,OAAA;KAAS,uBAAoB;;KAC/C,SAAAC,cAAuB,EAAxCN,UAAA,IAAA,GAAAC,mBAEkBC,UAAA,MAAAM,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,YAgBEF,MAAA,aAAA,GAAA;IAfI,SAAA;IAAJ,KAAI;IACJ,OAAM;IACL,eAAa,QAAA,MAAM;IACnB,UAAU,MAAA,OAAO,YAAQ;IACzB,UAAQ,CAAG,QAAA,MAAM;IACjB,gBAAc,QAAA,QAAQ,eAAW;IACjC,QAAQ,QAAA,QAAQ,eAAW;IAC3B,UAAU;IACV,MAAM,QAAA,QAAQ,QAAI;IAClB,YAAU,QAAA,QAAQ,WAAO;IACzB,eAAa;IACb,YAAY,QAAA;IACZ,UAAUA,MAAA,MAAA,CAAM,CAAC,YAAQ;IACzB,cAAY,UAAA;IACZ,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,OAAA"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createId } from "../core/model.js";
|
|
2
2
|
import { blockAround, findBlockById } from "../core/blocks.js";
|
|
3
3
|
import { originKey } from "../core/editor.js";
|
|
4
|
-
import { ownStepKey } from "../core/transaction.js";
|
|
5
|
-
import { keysBetween, orderKeys } from "./order.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { joinStepKey, ownStepKey } from "../core/transaction.js";
|
|
5
|
+
import { keptIndexes, keysBetween, orderKeys } from "./order.js";
|
|
6
|
+
import { createDiffBudget } from "./inline-diff.js";
|
|
7
|
+
import { inlineFrom, insertInline, keepInlineComments, prepareTextFromBase, updateText } from "./text.js";
|
|
8
|
+
import { cellAt, cellStart, clearTable, prepareTableText, readTable, writeTable } from "./table.js";
|
|
8
9
|
import { placeOf } from "./cursors.js";
|
|
10
|
+
import { mergedPropsOf, newMerged, readMerged, writeMerged } from "./merged-props.js";
|
|
9
11
|
import { Plugin, PluginKey, TextSelection } from "prosemirror-state";
|
|
10
12
|
import { Fragment } from "prosemirror-model";
|
|
11
13
|
import * as Y from "yjs";
|
|
@@ -39,9 +41,15 @@ function contentFrom(yblock, schema) {
|
|
|
39
41
|
const name = yblock.get("type");
|
|
40
42
|
const known = schema.nodes[name];
|
|
41
43
|
const type = known?.isInGroup("blockContent") ? known : schema.nodes.paragraph;
|
|
42
|
-
const
|
|
44
|
+
const stored = yblock.get("props");
|
|
45
|
+
const props = stored?.toJSON() ?? {};
|
|
46
|
+
const merged = mergedPropsOf(type);
|
|
43
47
|
const attrs = {};
|
|
44
|
-
for (const attr of Object.keys(type.spec.attrs ?? {}))
|
|
48
|
+
for (const attr of Object.keys(type.spec.attrs ?? {})) {
|
|
49
|
+
if (!(attr in props)) continue;
|
|
50
|
+
const spec = merged?.[attr];
|
|
51
|
+
attrs[attr] = spec ? readMerged(stored.get(attr), spec) : props[attr];
|
|
52
|
+
}
|
|
45
53
|
if (type.spec.rows) return readTable(yblock, type, attrs);
|
|
46
54
|
if (!type.inlineContent) return type.create(attrs);
|
|
47
55
|
const text = yblock.get("text");
|
|
@@ -57,27 +65,38 @@ function writeContent(yblock, content) {
|
|
|
57
65
|
return;
|
|
58
66
|
}
|
|
59
67
|
const props = new Y.Map();
|
|
60
|
-
|
|
68
|
+
const merged = mergedPropsOf(content.type);
|
|
61
69
|
yblock.set("props", props);
|
|
70
|
+
for (const [name, value] of Object.entries(content.attrs)) {
|
|
71
|
+
const spec = merged?.[name];
|
|
72
|
+
props.set(name, spec ? newMerged(value, spec) : value);
|
|
73
|
+
}
|
|
62
74
|
if (content.inlineContent) insertInline(text, 0, content, 0, content.content.size);
|
|
63
75
|
}
|
|
64
76
|
/**
|
|
65
77
|
* Bring a stored block's type, props and text from `before` to `after`.
|
|
66
78
|
* Returns whether the stored block holds more than `after` shows (see `writeTable`).
|
|
67
79
|
*/
|
|
68
|
-
function updateContent(yblock, before, after) {
|
|
80
|
+
function updateContent(yblock, before, after, current = before, plans) {
|
|
69
81
|
if (before.type !== after.type) yblock.set("type", after.type.name);
|
|
70
|
-
if (after.type.spec.rows) return writeTable(yblock, before.type === after.type ? before : null, after);
|
|
82
|
+
if (after.type.spec.rows) return writeTable(yblock, before.type === after.type ? before : null, after, plans);
|
|
71
83
|
clearTable(yblock);
|
|
72
84
|
const props = yblock.get("props");
|
|
73
|
-
|
|
85
|
+
const merged = mergedPropsOf(after.type);
|
|
86
|
+
for (const [name, value] of Object.entries(after.attrs)) {
|
|
87
|
+
const spec = merged?.[name];
|
|
88
|
+
if (spec) writeMerged(props, name, spec, value, before.type === after.type ? before.attrs[name] : void 0);
|
|
89
|
+
else if (before.type !== after.type || JSON.stringify(before.attrs[name]) !== JSON.stringify(value)) props.set(name, value);
|
|
90
|
+
}
|
|
74
91
|
for (const name of Array.from(props.keys())) if (!(name in after.attrs)) props.delete(name);
|
|
75
92
|
const text = yblock.get("text");
|
|
76
93
|
if (!after.inlineContent) {
|
|
77
94
|
if (text.length) text.delete(0, text.length);
|
|
78
95
|
return false;
|
|
79
96
|
}
|
|
80
|
-
|
|
97
|
+
const plan = plans?.get(text);
|
|
98
|
+
if (plan) plan(text);
|
|
99
|
+
else updateText(text, current, after);
|
|
81
100
|
return false;
|
|
82
101
|
}
|
|
83
102
|
/**
|
|
@@ -180,6 +199,332 @@ function writeDoc(map, doc) {
|
|
|
180
199
|
}
|
|
181
200
|
});
|
|
182
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Write the changes from `before` to `after` into the map: the content of
|
|
204
|
+
* blocks that changed, blocks added and removed, and the places of the
|
|
205
|
+
* blocks that moved. Returns the blocks that hold more than `after` shows,
|
|
206
|
+
* to be read back (see `writeTable`). Call it inside a transaction.
|
|
207
|
+
*/
|
|
208
|
+
function writeChanges(map, before, after, schema) {
|
|
209
|
+
const stale = [];
|
|
210
|
+
for (const [id, placed] of after.blocks) {
|
|
211
|
+
const yblock = map.get(id);
|
|
212
|
+
const old = before.blocks.get(id);
|
|
213
|
+
if (!yblock) {
|
|
214
|
+
const created = new Y.Map();
|
|
215
|
+
map.set(id, created);
|
|
216
|
+
writeContent(created, placed.content);
|
|
217
|
+
} else if (old && old.content !== placed.content) {
|
|
218
|
+
if (updateContent(yblock, old.content, placed.content)) stale.push(id);
|
|
219
|
+
} else if (!old) {
|
|
220
|
+
if (updateContent(yblock, contentFrom(yblock, schema), placed.content)) stale.push(id);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const id of before.blocks.keys()) if (!after.blocks.has(id)) map.delete(id);
|
|
224
|
+
for (const [key, ids] of after.children) {
|
|
225
|
+
const old = before.children.get(key);
|
|
226
|
+
if (old && old.length === ids.length && old.every((id, i) => ids[i] === id)) {
|
|
227
|
+
if (ids.every((id) => map.get(id).get("order") !== void 0)) continue;
|
|
228
|
+
}
|
|
229
|
+
const parent = key === ROOT ? null : key;
|
|
230
|
+
const keys = ids.map((id) => {
|
|
231
|
+
const yblock = map.get(id);
|
|
232
|
+
const order = yblock.get("order");
|
|
233
|
+
return yblock.get("parent") === parent && order !== void 0 ? order : null;
|
|
234
|
+
});
|
|
235
|
+
const next = orderKeys(keys);
|
|
236
|
+
ids.forEach((id, index) => {
|
|
237
|
+
if (keys[index] === next[index]) return;
|
|
238
|
+
const yblock = map.get(id);
|
|
239
|
+
if (yblock.get("parent") !== parent) yblock.set("parent", parent);
|
|
240
|
+
yblock.set("order", next[index]);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return stale;
|
|
244
|
+
}
|
|
245
|
+
/** The content node of block `id`. */
|
|
246
|
+
var contentOf = (index, id) => index.blocks.get(id).content;
|
|
247
|
+
/** A content node as a string, to tell equal blocks apart quickly. */
|
|
248
|
+
var keyOf = (content) => JSON.stringify(content.toJSON());
|
|
249
|
+
/**
|
|
250
|
+
* Pairs of `a` and `b` with equal keys, in the order of both: the equal
|
|
251
|
+
* start and end, then in the middle each of `a` with the first free equal
|
|
252
|
+
* one of `b`, keeping the longest run in order. Indexes into `a` and `b`;
|
|
253
|
+
* about linear, so a long document stays fast.
|
|
254
|
+
*/
|
|
255
|
+
function equalPairs(a, b) {
|
|
256
|
+
const pairs = [];
|
|
257
|
+
let start = 0;
|
|
258
|
+
while (start < a.length && start < b.length && a[start] === b[start]) {
|
|
259
|
+
pairs.push([start, start]);
|
|
260
|
+
start++;
|
|
261
|
+
}
|
|
262
|
+
let endA = a.length;
|
|
263
|
+
let endB = b.length;
|
|
264
|
+
const tail = [];
|
|
265
|
+
while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
|
|
266
|
+
endA--;
|
|
267
|
+
endB--;
|
|
268
|
+
tail.push([endA, endB]);
|
|
269
|
+
}
|
|
270
|
+
const free = /* @__PURE__ */ new Map();
|
|
271
|
+
for (let j = endB - 1; j >= start; j--) {
|
|
272
|
+
const list = free.get(b[j]);
|
|
273
|
+
if (list) list.push(j);
|
|
274
|
+
else free.set(b[j], [j]);
|
|
275
|
+
}
|
|
276
|
+
const middle = [];
|
|
277
|
+
for (let i = start; i < endA; i++) {
|
|
278
|
+
const j = free.get(a[i])?.pop();
|
|
279
|
+
if (j !== void 0) middle.push([i, j]);
|
|
280
|
+
}
|
|
281
|
+
const kept = keptIndexes(middle.map(([, j]) => String(j).padStart(10, "0")));
|
|
282
|
+
middle.forEach((pair, index) => kept.has(index) && pairs.push(pair));
|
|
283
|
+
for (let k = tail.length - 1; k >= 0; k--) pairs.push(tail[k]);
|
|
284
|
+
return pairs;
|
|
285
|
+
}
|
|
286
|
+
/** How alike two texts are, 0 to 1, by the pairs of letters they share. */
|
|
287
|
+
function likeness(a, b) {
|
|
288
|
+
if (a === b) return 1;
|
|
289
|
+
if (a.length < 2 || b.length < 2) return 0;
|
|
290
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
291
|
+
for (let i = 0; i < a.length - 1; i++) {
|
|
292
|
+
const pair = a.slice(i, i + 2);
|
|
293
|
+
pairs.set(pair, (pairs.get(pair) ?? 0) + 1);
|
|
294
|
+
}
|
|
295
|
+
let shared = 0;
|
|
296
|
+
for (let i = 0; i < b.length - 1; i++) {
|
|
297
|
+
const pair = b.slice(i, i + 2);
|
|
298
|
+
const left = pairs.get(pair);
|
|
299
|
+
if (left) {
|
|
300
|
+
shared++;
|
|
301
|
+
pairs.set(pair, left - 1);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return 2 * shared / (a.length + b.length - 2);
|
|
305
|
+
}
|
|
306
|
+
/** How alike two blocks must be to count as one edited. */
|
|
307
|
+
var ALIKE = .4;
|
|
308
|
+
/** How many stored blocks ahead a block is looked for between two equal ones. */
|
|
309
|
+
var LOOK_AHEAD = 32;
|
|
310
|
+
/** How alike a block moved out of its order must be to count as the same one edited. */
|
|
311
|
+
var MOVED_ALIKE = .8;
|
|
312
|
+
/** The most comparisons spent on blocks moved out of their order. */
|
|
313
|
+
var MOVED_PAIRS = 4e4;
|
|
314
|
+
/**
|
|
315
|
+
* Which block of `before` each block of `after` stands for: by id when it
|
|
316
|
+
* keeps one, otherwise by place among the blocks of the same parent: first
|
|
317
|
+
* the blocks with equal content, kept in order, then between those, each
|
|
318
|
+
* block with the most alike one of its type further on (its text is
|
|
319
|
+
* changed in place). A block with nothing alike enough is new. Returns
|
|
320
|
+
* new id → old id.
|
|
321
|
+
*/
|
|
322
|
+
function matchBlocks(before, after) {
|
|
323
|
+
const match = /* @__PURE__ */ new Map();
|
|
324
|
+
const used = /* @__PURE__ */ new Set();
|
|
325
|
+
for (const id of after.blocks.keys()) if (before.blocks.has(id)) {
|
|
326
|
+
match.set(id, id);
|
|
327
|
+
used.add(id);
|
|
328
|
+
}
|
|
329
|
+
const pair = (a, b) => {
|
|
330
|
+
match.set(a, b);
|
|
331
|
+
used.add(b);
|
|
332
|
+
};
|
|
333
|
+
const visit = (key, oldKey) => {
|
|
334
|
+
const ids = after.children.get(key) ?? [];
|
|
335
|
+
const fresh = ids.filter((id) => !match.has(id));
|
|
336
|
+
const olds = (oldKey === null ? [] : before.children.get(oldKey) ?? []).filter((id) => !used.has(id));
|
|
337
|
+
const anchors = equalPairs(fresh.map((id) => keyOf(contentOf(after, id))), olds.map((id) => keyOf(contentOf(before, id))));
|
|
338
|
+
let i = 0;
|
|
339
|
+
let j = 0;
|
|
340
|
+
for (const [ai, aj] of [...anchors, [fresh.length, olds.length]]) {
|
|
341
|
+
for (; i < ai; i++) {
|
|
342
|
+
const node = contentOf(after, fresh[i]);
|
|
343
|
+
const text = node.textContent;
|
|
344
|
+
let best = -1;
|
|
345
|
+
let score = ALIKE;
|
|
346
|
+
for (let k = j; k < Math.min(aj, j + LOOK_AHEAD); k++) {
|
|
347
|
+
const old = contentOf(before, olds[k]);
|
|
348
|
+
if (old.type !== node.type) continue;
|
|
349
|
+
const like = likeness(text, old.textContent);
|
|
350
|
+
if (like > score || best < 0 && like >= score) {
|
|
351
|
+
best = k;
|
|
352
|
+
score = like;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (best >= 0) {
|
|
356
|
+
pair(fresh[i], olds[best]);
|
|
357
|
+
j = best + 1;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (ai < fresh.length) pair(fresh[ai], olds[aj]);
|
|
361
|
+
i = ai + 1;
|
|
362
|
+
j = aj + 1;
|
|
363
|
+
}
|
|
364
|
+
const leftNew = fresh.filter((id) => !match.has(id));
|
|
365
|
+
const leftOld = olds.filter((id) => !used.has(id));
|
|
366
|
+
if (leftNew.length && leftOld.length) {
|
|
367
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
368
|
+
for (let k = leftOld.length - 1; k >= 0; k--) {
|
|
369
|
+
const id = leftOld[k];
|
|
370
|
+
const text = keyOf(contentOf(before, id));
|
|
371
|
+
const list = byKey.get(text);
|
|
372
|
+
if (list) list.push(id);
|
|
373
|
+
else byKey.set(text, [id]);
|
|
374
|
+
}
|
|
375
|
+
const rest = [];
|
|
376
|
+
for (const id of leftNew) {
|
|
377
|
+
const old = byKey.get(keyOf(contentOf(after, id)))?.pop();
|
|
378
|
+
if (old) pair(id, old);
|
|
379
|
+
else rest.push(id);
|
|
380
|
+
}
|
|
381
|
+
if (rest.length * leftOld.length <= MOVED_PAIRS) for (const id of rest) {
|
|
382
|
+
const node = contentOf(after, id);
|
|
383
|
+
let best = null;
|
|
384
|
+
let score = MOVED_ALIKE;
|
|
385
|
+
for (const old of leftOld) {
|
|
386
|
+
if (used.has(old) || contentOf(before, old).type !== node.type) continue;
|
|
387
|
+
const like = likeness(node.textContent, contentOf(before, old).textContent);
|
|
388
|
+
if (like >= score) {
|
|
389
|
+
best = old;
|
|
390
|
+
score = like;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (best) pair(id, best);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
for (const id of ids) if (after.children.has(id)) visit(id, match.get(id) ?? null);
|
|
397
|
+
};
|
|
398
|
+
visit(ROOT, ROOT);
|
|
399
|
+
return match;
|
|
400
|
+
}
|
|
401
|
+
/** Every block id in `index` under `id`, at any depth. */
|
|
402
|
+
function descendants(index, id, out = []) {
|
|
403
|
+
for (const child of index.children.get(id) ?? []) {
|
|
404
|
+
out.push(child);
|
|
405
|
+
descendants(index, child, out);
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Change the map from `base` to `doc`, leaving what changed in the map since
|
|
411
|
+
* `base` was read: blocks of `doc` are matched to those of `base` (see
|
|
412
|
+
* `matchBlocks`), and those of `base` to the stored ones; only blocks that
|
|
413
|
+
* differ between `base` and `doc` are written, removed or moved. Without
|
|
414
|
+
* `base`, the map as it is now. Call it inside a transaction.
|
|
415
|
+
*/
|
|
416
|
+
function updateDoc(map, doc, schema, base) {
|
|
417
|
+
const current = readDoc(map, schema);
|
|
418
|
+
if (!current) return void writeDoc(map, doc);
|
|
419
|
+
const now = indexDoc(current);
|
|
420
|
+
const from = base ? indexDoc(base) : now;
|
|
421
|
+
const to = indexDoc(doc);
|
|
422
|
+
const toBase = matchBlocks(from, to);
|
|
423
|
+
const baseToNow = base ? matchBlocks(now, from) : null;
|
|
424
|
+
/** The stored block a block of `base` is now, if it still is. */
|
|
425
|
+
const nowOf = (old) => {
|
|
426
|
+
const there = baseToNow ? baseToNow.get(old) : old;
|
|
427
|
+
return there !== void 0 && now.blocks.has(there) ? there : null;
|
|
428
|
+
};
|
|
429
|
+
/** The stored block each block of `doc` is written to. */
|
|
430
|
+
const stored = /* @__PURE__ */ new Map();
|
|
431
|
+
for (const [id, old] of toBase) {
|
|
432
|
+
const there = nowOf(old);
|
|
433
|
+
if (there) stored.set(id, there);
|
|
434
|
+
}
|
|
435
|
+
const gone = /* @__PURE__ */ new Set();
|
|
436
|
+
const walk = (key, inGone) => {
|
|
437
|
+
for (const id of to.children.get(key) ?? []) {
|
|
438
|
+
const lost = toBase.get(id) !== void 0 && !stored.has(id) || inGone && !stored.has(id);
|
|
439
|
+
if (lost) gone.add(id);
|
|
440
|
+
walk(id, lost);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
walk(ROOT, false);
|
|
444
|
+
for (const id of to.blocks.keys()) if (!stored.has(id) && !gone.has(id)) stored.set(id, map.has(id) ? createId() : id);
|
|
445
|
+
const kept = new Set(stored.values());
|
|
446
|
+
const inDoc = new Set(toBase.values());
|
|
447
|
+
const budget = createDiffBudget();
|
|
448
|
+
const contentUpdates = /* @__PURE__ */ new Map();
|
|
449
|
+
const textPlans = /* @__PURE__ */ new Map();
|
|
450
|
+
for (const [id, placed] of to.blocks) {
|
|
451
|
+
if (gone.has(id)) continue;
|
|
452
|
+
const target = stored.get(id);
|
|
453
|
+
const there = now.blocks.get(target)?.content;
|
|
454
|
+
if (!there) continue;
|
|
455
|
+
const old = toBase.get(id);
|
|
456
|
+
const was = old !== void 0 ? from.blocks.get(old).content : null;
|
|
457
|
+
const compared = was ? keepInlineComments(was, placed.content, budget) : placed.content;
|
|
458
|
+
if (was && compared.eq(was)) continue;
|
|
459
|
+
const before = was && was.type === there.type && was.type === placed.content.type ? was : there;
|
|
460
|
+
const after = before === was ? compared : keepInlineComments(before, placed.content, budget);
|
|
461
|
+
const yblock = map.get(target);
|
|
462
|
+
contentUpdates.set(id, {
|
|
463
|
+
before,
|
|
464
|
+
after,
|
|
465
|
+
current: there
|
|
466
|
+
});
|
|
467
|
+
if (after.type.spec.rows) prepareTableText(yblock, before.type === after.type ? before : null, after, textPlans, budget);
|
|
468
|
+
else if (after.inlineContent) {
|
|
469
|
+
const text = yblock.get("text");
|
|
470
|
+
const currentInline = there.inlineContent ? there : after.type.create(after.attrs, inlineFrom(text, schema, !!after.type.spec.code));
|
|
471
|
+
const baseInline = before.inlineContent ? before : currentInline;
|
|
472
|
+
textPlans.set(text, prepareTextFromBase(baseInline, after, currentInline, budget));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (const old of from.blocks.keys()) {
|
|
476
|
+
const there = inDoc.has(old) ? null : nowOf(old);
|
|
477
|
+
if (!there) continue;
|
|
478
|
+
for (const id of [there, ...descendants(now, there)]) if (!kept.has(id) && map.has(id)) map.delete(id);
|
|
479
|
+
}
|
|
480
|
+
for (const [id, placed] of to.blocks) {
|
|
481
|
+
if (gone.has(id)) continue;
|
|
482
|
+
const target = stored.get(id);
|
|
483
|
+
const yblock = map.get(target);
|
|
484
|
+
if (!now.blocks.has(target)) {
|
|
485
|
+
const created = new Y.Map();
|
|
486
|
+
map.set(target, created);
|
|
487
|
+
writeContent(created, placed.content);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const update = contentUpdates.get(id);
|
|
491
|
+
if (update) updateContent(yblock, update.before, update.after, update.current, textPlans);
|
|
492
|
+
}
|
|
493
|
+
for (const [key, all] of to.children) {
|
|
494
|
+
if (gone.has(key)) continue;
|
|
495
|
+
const ids = all.filter((id) => !gone.has(id));
|
|
496
|
+
const parent = key === ROOT ? null : stored.get(key);
|
|
497
|
+
const oldParent = key === ROOT ? ROOT : toBase.get(key);
|
|
498
|
+
const siblings = oldParent === void 0 ? [] : from.children.get(oldParent) ?? [];
|
|
499
|
+
const at = new Map(siblings.map((id, index) => [id, index]));
|
|
500
|
+
const inBase = ids.map((id) => {
|
|
501
|
+
const old = toBase.get(id);
|
|
502
|
+
return old !== void 0 && at.has(old) ? String(at.get(old)).padStart(10, "0") : null;
|
|
503
|
+
});
|
|
504
|
+
const stays = keptIndexes(inBase);
|
|
505
|
+
const moved = new Set(ids.filter((_, index) => !stays.has(index)).map((id) => stored.get(id)));
|
|
506
|
+
if (!moved.size) continue;
|
|
507
|
+
const list = (now.children.get(parentKey(parent)) ?? []).filter((id) => map.has(id) && !moved.has(id));
|
|
508
|
+
let previous = null;
|
|
509
|
+
for (const id of ids) {
|
|
510
|
+
const target = stored.get(id);
|
|
511
|
+
if (moved.has(target)) list.splice(previous === null ? 0 : list.indexOf(previous) + 1, 0, target);
|
|
512
|
+
if (list.includes(target)) previous = target;
|
|
513
|
+
}
|
|
514
|
+
const keys = list.map((id) => {
|
|
515
|
+
const yblock = map.get(id);
|
|
516
|
+
const order = yblock.get("order");
|
|
517
|
+
return !moved.has(id) && yblock.get("parent") === parent && order !== void 0 ? order : null;
|
|
518
|
+
});
|
|
519
|
+
const next = orderKeys(keys);
|
|
520
|
+
list.forEach((id, index) => {
|
|
521
|
+
if (keys[index] === next[index]) return;
|
|
522
|
+
const yblock = map.get(id);
|
|
523
|
+
if (yblock.get("parent") !== parent) yblock.set("parent", parent);
|
|
524
|
+
yblock.set("order", next[index]);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
183
528
|
/** The document a map holds, read without an editor; `null` while the map is empty. */
|
|
184
529
|
function readDoc(map, schema) {
|
|
185
530
|
const children = placeAll(map);
|
|
@@ -258,46 +603,9 @@ function syncPlugin(binding) {
|
|
|
258
603
|
if (!old || old.length !== ids.length || old.some((id, i) => ids[i] !== id)) structural = true;
|
|
259
604
|
}
|
|
260
605
|
if (structural) binding.stopCapturing?.();
|
|
261
|
-
const stale =
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const yblock = map.get(id);
|
|
265
|
-
const old = before.blocks.get(id);
|
|
266
|
-
if (!yblock) {
|
|
267
|
-
const created = new Y.Map();
|
|
268
|
-
map.set(id, created);
|
|
269
|
-
writeContent(created, placed.content);
|
|
270
|
-
} else if (old && old.content !== placed.content) {
|
|
271
|
-
if (updateContent(yblock, old.content, placed.content)) stale.push(id);
|
|
272
|
-
} else if (!old) {
|
|
273
|
-
if (updateContent(yblock, contentFrom(yblock, schema), placed.content)) stale.push(id);
|
|
274
|
-
}
|
|
275
|
-
cache.set(id, placed.content);
|
|
276
|
-
}
|
|
277
|
-
for (const id of before.blocks.keys()) if (!after.blocks.has(id)) {
|
|
278
|
-
map.delete(id);
|
|
279
|
-
cache.delete(id);
|
|
280
|
-
}
|
|
281
|
-
for (const [key, ids] of after.children) {
|
|
282
|
-
const old = before.children.get(key);
|
|
283
|
-
if (old && old.length === ids.length && old.every((id, i) => ids[i] === id)) {
|
|
284
|
-
if (ids.every((id) => map.get(id).get("order") !== void 0)) continue;
|
|
285
|
-
}
|
|
286
|
-
const parent = key === ROOT ? null : key;
|
|
287
|
-
const keys = ids.map((id) => {
|
|
288
|
-
const yblock = map.get(id);
|
|
289
|
-
const order = yblock.get("order");
|
|
290
|
-
return yblock.get("parent") === parent && order !== void 0 ? order : null;
|
|
291
|
-
});
|
|
292
|
-
const next = orderKeys(keys);
|
|
293
|
-
ids.forEach((id, index) => {
|
|
294
|
-
if (keys[index] === next[index]) return;
|
|
295
|
-
const yblock = map.get(id);
|
|
296
|
-
if (yblock.get("parent") !== parent) yblock.set("parent", parent);
|
|
297
|
-
yblock.set("order", next[index]);
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}, tracked ? binding.origin : binding.untracked);
|
|
606
|
+
const stale = ydoc.transact(() => writeChanges(map, before, after, schema), tracked ? binding.origin : binding.untracked);
|
|
607
|
+
for (const id of after.blocks.keys()) cache.set(id, after.blocks.get(id).content);
|
|
608
|
+
for (const id of before.blocks.keys()) if (!after.blocks.has(id)) cache.delete(id);
|
|
301
609
|
if (structural) binding.stopCapturing?.();
|
|
302
610
|
synced = after;
|
|
303
611
|
if (stale.length) {
|
|
@@ -313,7 +621,8 @@ function syncPlugin(binding) {
|
|
|
313
621
|
init: () => ({
|
|
314
622
|
remote: false,
|
|
315
623
|
tracked: false,
|
|
316
|
-
own: false
|
|
624
|
+
own: false,
|
|
625
|
+
join: false
|
|
317
626
|
}),
|
|
318
627
|
apply(tr, value) {
|
|
319
628
|
const meta = tr.getMeta(collaborationKey);
|
|
@@ -321,18 +630,22 @@ function syncPlugin(binding) {
|
|
|
321
630
|
if (meta?.remote) return {
|
|
322
631
|
remote: true,
|
|
323
632
|
tracked: false,
|
|
324
|
-
own: false
|
|
633
|
+
own: false,
|
|
634
|
+
join: false
|
|
325
635
|
};
|
|
326
636
|
const tracked = tr.getMeta("addToHistory") !== false;
|
|
327
637
|
const own = tr.getMeta(ownStepKey) === true;
|
|
328
|
-
|
|
638
|
+
const join = tr.getMeta(joinStepKey) === true;
|
|
639
|
+
return !join && !!tr.getMeta("appendedTransaction") && !value.remote ? {
|
|
329
640
|
remote: false,
|
|
330
641
|
tracked: value.tracked || tracked,
|
|
331
|
-
own: value.own || own
|
|
642
|
+
own: value.own || own,
|
|
643
|
+
join: value.join || join
|
|
332
644
|
} : {
|
|
333
645
|
remote: false,
|
|
334
646
|
tracked,
|
|
335
|
-
own
|
|
647
|
+
own,
|
|
648
|
+
join
|
|
336
649
|
};
|
|
337
650
|
}
|
|
338
651
|
},
|
|
@@ -365,6 +678,7 @@ function syncPlugin(binding) {
|
|
|
365
678
|
}
|
|
366
679
|
binding.selectionBefore = placeOf(binding, previous.doc, previous.selection.head);
|
|
367
680
|
if (state.own) binding.stopCapturing?.();
|
|
681
|
+
else if (state.join) binding.joinCapturing?.();
|
|
368
682
|
writeMap(current, state.tracked);
|
|
369
683
|
if (state.own) binding.stopCapturing?.();
|
|
370
684
|
},
|
|
@@ -376,6 +690,6 @@ function syncPlugin(binding) {
|
|
|
376
690
|
}
|
|
377
691
|
});
|
|
378
692
|
}
|
|
379
|
-
export { collaborationKey, createBinding, readDoc, syncPlugin, writeDoc };
|
|
693
|
+
export { collaborationKey, createBinding, readDoc, syncPlugin, updateDoc, writeDoc };
|
|
380
694
|
|
|
381
695
|
//# sourceMappingURL=binding.js.map
|