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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/code/code-editor-block.js.map +1 -1
  2. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
  3. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/collaboration/binding.js +344 -42
  5. package/dist/collaboration/binding.js.map +1 -1
  6. package/dist/collaboration/index.js +30 -10
  7. package/dist/collaboration/index.js.map +1 -1
  8. package/dist/components/block-handle.js.map +1 -1
  9. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  11. package/dist/components/bubble-toolbar.js.map +1 -1
  12. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
  13. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  14. package/dist/components/comment-card.js.map +1 -1
  15. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
  16. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
  17. package/dist/core/convert.js +3 -3
  18. package/dist/core/convert.js.map +1 -1
  19. package/dist/core/editor.js +2 -1
  20. package/dist/core/editor.js.map +1 -1
  21. package/dist/core/plugins.js +108 -5
  22. package/dist/core/plugins.js.map +1 -1
  23. package/dist/core/prepare.js +12 -5
  24. package/dist/core/prepare.js.map +1 -1
  25. package/dist/dom.js +6 -1
  26. package/dist/dom.js.map +1 -1
  27. package/dist/extensions/align/align-menu.js.map +1 -1
  28. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
  29. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  30. package/dist/extensions/callout/html.js +5 -4
  31. package/dist/extensions/callout/html.js.map +1 -1
  32. package/dist/extensions/colors/color-menu.js.map +1 -1
  33. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
  34. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  35. package/dist/extensions/list-html.js +1 -1
  36. package/dist/extensions/list-html.js.map +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/markdown/index.js +2 -2
  39. package/dist/markdown/index.js.map +1 -1
  40. package/dist/style.css +1 -1
  41. package/dist/style.js +0 -1
  42. package/dist/types/collaboration/binding.d.ts +8 -0
  43. package/dist/types/collaboration/index.d.ts +36 -4
  44. package/dist/types/core/convert.d.ts +10 -2
  45. package/dist/types/core/plugins.d.ts +9 -0
  46. package/dist/types/core/prepare.d.ts +16 -2
  47. package/dist/types/dom.d.ts +2 -0
  48. package/dist/types/index.d.ts +2 -1
  49. package/dist/types/markdown/index.d.ts +8 -1
  50. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"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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A;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,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
+ {"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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EkBC,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"}
@@ -2,12 +2,13 @@ import { createId } from "../core/model.js";
2
2
  import { blockAround, findBlockById } from "../core/blocks.js";
3
3
  import { originKey } from "../core/editor.js";
4
4
  import { ownStepKey } from "../core/transaction.js";
5
- import { keysBetween, orderKeys } from "./order.js";
5
+ import { keptIndexes, keysBetween, orderKeys } from "./order.js";
6
6
  import { inlineFrom, insertInline, updateText } from "./text.js";
7
7
  import { cellAt, cellStart, clearTable, readTable, writeTable } from "./table.js";
8
8
  import { placeOf } from "./cursors.js";
9
9
  import { Plugin, PluginKey, TextSelection } from "prosemirror-state";
10
10
  import { Fragment } from "prosemirror-model";
11
+ import { Transform } from "prosemirror-transform";
11
12
  import * as Y from "yjs";
12
13
  // src/collaboration/binding.ts
13
14
  var ROOT = "\0root";
@@ -180,6 +181,344 @@ function writeDoc(map, doc) {
180
181
  }
181
182
  });
182
183
  }
184
+ /**
185
+ * Write the changes from `before` to `after` into the map: the content of
186
+ * blocks that changed, blocks added and removed, and the places of the
187
+ * blocks that moved. Returns the blocks that hold more than `after` shows,
188
+ * to be read back (see `writeTable`). Call it inside a transaction.
189
+ */
190
+ function writeChanges(map, before, after, schema) {
191
+ const stale = [];
192
+ for (const [id, placed] of after.blocks) {
193
+ const yblock = map.get(id);
194
+ const old = before.blocks.get(id);
195
+ if (!yblock) {
196
+ const created = new Y.Map();
197
+ map.set(id, created);
198
+ writeContent(created, placed.content);
199
+ } else if (old && old.content !== placed.content) {
200
+ if (updateContent(yblock, old.content, placed.content)) stale.push(id);
201
+ } else if (!old) {
202
+ if (updateContent(yblock, contentFrom(yblock, schema), placed.content)) stale.push(id);
203
+ }
204
+ }
205
+ for (const id of before.blocks.keys()) if (!after.blocks.has(id)) map.delete(id);
206
+ for (const [key, ids] of after.children) {
207
+ const old = before.children.get(key);
208
+ if (old && old.length === ids.length && old.every((id, i) => ids[i] === id)) {
209
+ if (ids.every((id) => map.get(id).get("order") !== void 0)) continue;
210
+ }
211
+ const parent = key === ROOT ? null : key;
212
+ const keys = ids.map((id) => {
213
+ const yblock = map.get(id);
214
+ const order = yblock.get("order");
215
+ return yblock.get("parent") === parent && order !== void 0 ? order : null;
216
+ });
217
+ const next = orderKeys(keys);
218
+ ids.forEach((id, index) => {
219
+ if (keys[index] === next[index]) return;
220
+ const yblock = map.get(id);
221
+ if (yblock.get("parent") !== parent) yblock.set("parent", parent);
222
+ yblock.set("order", next[index]);
223
+ });
224
+ }
225
+ return stale;
226
+ }
227
+ /** The content node of block `id`. */
228
+ var contentOf = (index, id) => index.blocks.get(id).content;
229
+ /** A content node as a string, to tell equal blocks apart quickly. */
230
+ var keyOf = (content) => JSON.stringify(content.toJSON());
231
+ /**
232
+ * Pairs of `a` and `b` with equal keys, in the order of both: the equal
233
+ * start and end, then in the middle each of `a` with the first free equal
234
+ * one of `b`, keeping the longest run in order. Indexes into `a` and `b`;
235
+ * about linear, so a long document stays fast.
236
+ */
237
+ function equalPairs(a, b) {
238
+ const pairs = [];
239
+ let start = 0;
240
+ while (start < a.length && start < b.length && a[start] === b[start]) {
241
+ pairs.push([start, start]);
242
+ start++;
243
+ }
244
+ let endA = a.length;
245
+ let endB = b.length;
246
+ const tail = [];
247
+ while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
248
+ endA--;
249
+ endB--;
250
+ tail.push([endA, endB]);
251
+ }
252
+ const free = /* @__PURE__ */ new Map();
253
+ for (let j = endB - 1; j >= start; j--) {
254
+ const list = free.get(b[j]);
255
+ if (list) list.push(j);
256
+ else free.set(b[j], [j]);
257
+ }
258
+ const middle = [];
259
+ for (let i = start; i < endA; i++) {
260
+ const j = free.get(a[i])?.pop();
261
+ if (j !== void 0) middle.push([i, j]);
262
+ }
263
+ const kept = keptIndexes(middle.map(([, j]) => String(j).padStart(10, "0")));
264
+ middle.forEach((pair, index) => kept.has(index) && pairs.push(pair));
265
+ for (let k = tail.length - 1; k >= 0; k--) pairs.push(tail[k]);
266
+ return pairs;
267
+ }
268
+ /** How alike two texts are, 0 to 1, by the pairs of letters they share. */
269
+ function likeness(a, b) {
270
+ if (a === b) return 1;
271
+ if (a.length < 2 || b.length < 2) return 0;
272
+ const pairs = /* @__PURE__ */ new Map();
273
+ for (let i = 0; i < a.length - 1; i++) {
274
+ const pair = a.slice(i, i + 2);
275
+ pairs.set(pair, (pairs.get(pair) ?? 0) + 1);
276
+ }
277
+ let shared = 0;
278
+ for (let i = 0; i < b.length - 1; i++) {
279
+ const pair = b.slice(i, i + 2);
280
+ const left = pairs.get(pair);
281
+ if (left) {
282
+ shared++;
283
+ pairs.set(pair, left - 1);
284
+ }
285
+ }
286
+ return 2 * shared / (a.length + b.length - 2);
287
+ }
288
+ /** How alike two blocks must be to count as one edited. */
289
+ var ALIKE = .4;
290
+ /** How many stored blocks ahead a block is looked for between two equal ones. */
291
+ var LOOK_AHEAD = 32;
292
+ /** How alike a block moved out of its order must be to count as the same one edited. */
293
+ var MOVED_ALIKE = .8;
294
+ /** The most comparisons spent on blocks moved out of their order. */
295
+ var MOVED_PAIRS = 4e4;
296
+ /**
297
+ * Which block of `before` each block of `after` stands for: by id when it
298
+ * keeps one, otherwise by place among the blocks of the same parent: first
299
+ * the blocks with equal content, kept in order, then between those, each
300
+ * block with the most alike one of its type further on (its text is
301
+ * changed in place). A block with nothing alike enough is new. Returns
302
+ * new id → old id.
303
+ */
304
+ function matchBlocks(before, after) {
305
+ const match = /* @__PURE__ */ new Map();
306
+ const used = /* @__PURE__ */ new Set();
307
+ for (const id of after.blocks.keys()) if (before.blocks.has(id)) {
308
+ match.set(id, id);
309
+ used.add(id);
310
+ }
311
+ const pair = (a, b) => {
312
+ match.set(a, b);
313
+ used.add(b);
314
+ };
315
+ const visit = (key, oldKey) => {
316
+ const ids = after.children.get(key) ?? [];
317
+ const fresh = ids.filter((id) => !match.has(id));
318
+ const olds = (oldKey === null ? [] : before.children.get(oldKey) ?? []).filter((id) => !used.has(id));
319
+ const anchors = equalPairs(fresh.map((id) => keyOf(contentOf(after, id))), olds.map((id) => keyOf(contentOf(before, id))));
320
+ let i = 0;
321
+ let j = 0;
322
+ for (const [ai, aj] of [...anchors, [fresh.length, olds.length]]) {
323
+ for (; i < ai; i++) {
324
+ const node = contentOf(after, fresh[i]);
325
+ const text = node.textContent;
326
+ let best = -1;
327
+ let score = ALIKE;
328
+ for (let k = j; k < Math.min(aj, j + LOOK_AHEAD); k++) {
329
+ const old = contentOf(before, olds[k]);
330
+ if (old.type !== node.type) continue;
331
+ const like = likeness(text, old.textContent);
332
+ if (like > score || best < 0 && like >= score) {
333
+ best = k;
334
+ score = like;
335
+ }
336
+ }
337
+ if (best >= 0) {
338
+ pair(fresh[i], olds[best]);
339
+ j = best + 1;
340
+ }
341
+ }
342
+ if (ai < fresh.length) pair(fresh[ai], olds[aj]);
343
+ i = ai + 1;
344
+ j = aj + 1;
345
+ }
346
+ const leftNew = fresh.filter((id) => !match.has(id));
347
+ const leftOld = olds.filter((id) => !used.has(id));
348
+ if (leftNew.length && leftOld.length) {
349
+ const byKey = /* @__PURE__ */ new Map();
350
+ for (let k = leftOld.length - 1; k >= 0; k--) {
351
+ const id = leftOld[k];
352
+ const text = keyOf(contentOf(before, id));
353
+ const list = byKey.get(text);
354
+ if (list) list.push(id);
355
+ else byKey.set(text, [id]);
356
+ }
357
+ const rest = [];
358
+ for (const id of leftNew) {
359
+ const old = byKey.get(keyOf(contentOf(after, id)))?.pop();
360
+ if (old) pair(id, old);
361
+ else rest.push(id);
362
+ }
363
+ if (rest.length * leftOld.length <= MOVED_PAIRS) for (const id of rest) {
364
+ const node = contentOf(after, id);
365
+ let best = null;
366
+ let score = MOVED_ALIKE;
367
+ for (const old of leftOld) {
368
+ if (used.has(old) || contentOf(before, old).type !== node.type) continue;
369
+ const like = likeness(node.textContent, contentOf(before, old).textContent);
370
+ if (like >= score) {
371
+ best = old;
372
+ score = like;
373
+ }
374
+ }
375
+ if (best) pair(id, best);
376
+ }
377
+ }
378
+ for (const id of ids) if (after.children.has(id)) visit(id, match.get(id) ?? null);
379
+ };
380
+ visit(ROOT, ROOT);
381
+ return match;
382
+ }
383
+ /**
384
+ * `after` with the comment marks of `before` on the text both start and
385
+ * end with, when `after` has none: a version read from Markdown, which
386
+ * doesn't carry them, leaves the threads where the text stays the same.
387
+ */
388
+ function keepComments(before, after) {
389
+ const type = after.type.schema.marks.comment;
390
+ if (!type || !after.inlineContent || !before.inlineContent || before.type !== after.type) return after;
391
+ let theirs = false;
392
+ after.descendants((node) => {
393
+ if (type.isInSet(node.marks)) theirs = true;
394
+ });
395
+ if (theirs) return after;
396
+ const ranges = [];
397
+ before.forEach((child, pos) => {
398
+ for (const mark of child.marks) if (mark.type === type) ranges.push({
399
+ from: pos,
400
+ to: pos + child.nodeSize,
401
+ mark
402
+ });
403
+ });
404
+ if (!ranges.length) return after;
405
+ const a = before.textBetween(0, before.content.size, "", "");
406
+ const b = after.textBetween(0, after.content.size, "", "");
407
+ let head = 0;
408
+ while (head < a.length && head < b.length && a[head] === b[head]) head++;
409
+ let tail = 0;
410
+ while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) tail++;
411
+ const tr = new Transform(after);
412
+ const shift = b.length - a.length;
413
+ for (const { from, to, mark } of ranges) {
414
+ if (from < head) tr.addMark(from, Math.min(to, head), mark);
415
+ const end = a.length - tail;
416
+ if (to > end) tr.addMark(Math.max(from, end) + shift, to + shift, mark);
417
+ }
418
+ return tr.doc;
419
+ }
420
+ /** Every block id in `index` under `id`, at any depth. */
421
+ function descendants(index, id, out = []) {
422
+ for (const child of index.children.get(id) ?? []) {
423
+ out.push(child);
424
+ descendants(index, child, out);
425
+ }
426
+ return out;
427
+ }
428
+ /**
429
+ * Change the map from `base` to `doc`, leaving what changed in the map since
430
+ * `base` was read: blocks of `doc` are matched to those of `base` (see
431
+ * `matchBlocks`), and those of `base` to the stored ones; only blocks that
432
+ * differ between `base` and `doc` are written, removed or moved. Without
433
+ * `base`, the map as it is now. Call it inside a transaction.
434
+ */
435
+ function updateDoc(map, doc, schema, base) {
436
+ const current = readDoc(map, schema);
437
+ if (!current) return void writeDoc(map, doc);
438
+ const now = indexDoc(current);
439
+ const from = base ? indexDoc(base) : now;
440
+ const to = indexDoc(doc);
441
+ const toBase = matchBlocks(from, to);
442
+ const baseToNow = base ? matchBlocks(now, from) : null;
443
+ /** The stored block a block of `base` is now, if it still is. */
444
+ const nowOf = (old) => {
445
+ const there = baseToNow ? baseToNow.get(old) : old;
446
+ return there !== void 0 && now.blocks.has(there) ? there : null;
447
+ };
448
+ /** The stored block each block of `doc` is written to. */
449
+ const stored = /* @__PURE__ */ new Map();
450
+ for (const [id, old] of toBase) {
451
+ const there = nowOf(old);
452
+ if (there) stored.set(id, there);
453
+ }
454
+ const gone = /* @__PURE__ */ new Set();
455
+ const walk = (key, inGone) => {
456
+ for (const id of to.children.get(key) ?? []) {
457
+ const lost = toBase.get(id) !== void 0 && !stored.has(id) || inGone && !stored.has(id);
458
+ if (lost) gone.add(id);
459
+ walk(id, lost);
460
+ }
461
+ };
462
+ walk(ROOT, false);
463
+ for (const id of to.blocks.keys()) if (!stored.has(id) && !gone.has(id)) stored.set(id, map.has(id) ? createId() : id);
464
+ const kept = new Set(stored.values());
465
+ const inDoc = new Set(toBase.values());
466
+ for (const old of from.blocks.keys()) {
467
+ const there = inDoc.has(old) ? null : nowOf(old);
468
+ if (!there) continue;
469
+ for (const id of [there, ...descendants(now, there)]) if (!kept.has(id) && map.has(id)) map.delete(id);
470
+ }
471
+ for (const [id, placed] of to.blocks) {
472
+ if (gone.has(id)) continue;
473
+ const target = stored.get(id);
474
+ const yblock = map.get(target);
475
+ if (!now.blocks.has(target)) {
476
+ const created = new Y.Map();
477
+ map.set(target, created);
478
+ writeContent(created, placed.content);
479
+ continue;
480
+ }
481
+ const old = toBase.get(id);
482
+ const was = old !== void 0 ? from.blocks.get(old).content : null;
483
+ if (was && keepComments(was, placed.content).eq(was)) continue;
484
+ const there = now.blocks.get(target).content;
485
+ updateContent(yblock, there, keepComments(there, placed.content));
486
+ }
487
+ for (const [key, all] of to.children) {
488
+ if (gone.has(key)) continue;
489
+ const ids = all.filter((id) => !gone.has(id));
490
+ const parent = key === ROOT ? null : stored.get(key);
491
+ const oldParent = key === ROOT ? ROOT : toBase.get(key);
492
+ const siblings = oldParent === void 0 ? [] : from.children.get(oldParent) ?? [];
493
+ const at = new Map(siblings.map((id, index) => [id, index]));
494
+ const inBase = ids.map((id) => {
495
+ const old = toBase.get(id);
496
+ return old !== void 0 && at.has(old) ? String(at.get(old)).padStart(10, "0") : null;
497
+ });
498
+ const stays = keptIndexes(inBase);
499
+ const moved = new Set(ids.filter((_, index) => !stays.has(index)).map((id) => stored.get(id)));
500
+ if (!moved.size) continue;
501
+ const list = (now.children.get(parentKey(parent)) ?? []).filter((id) => map.has(id) && !moved.has(id));
502
+ let previous = null;
503
+ for (const id of ids) {
504
+ const target = stored.get(id);
505
+ if (moved.has(target)) list.splice(previous === null ? 0 : list.indexOf(previous) + 1, 0, target);
506
+ if (list.includes(target)) previous = target;
507
+ }
508
+ const keys = list.map((id) => {
509
+ const yblock = map.get(id);
510
+ const order = yblock.get("order");
511
+ return !moved.has(id) && yblock.get("parent") === parent && order !== void 0 ? order : null;
512
+ });
513
+ const next = orderKeys(keys);
514
+ list.forEach((id, index) => {
515
+ if (keys[index] === next[index]) return;
516
+ const yblock = map.get(id);
517
+ if (yblock.get("parent") !== parent) yblock.set("parent", parent);
518
+ yblock.set("order", next[index]);
519
+ });
520
+ }
521
+ }
183
522
  /** The document a map holds, read without an editor; `null` while the map is empty. */
184
523
  function readDoc(map, schema) {
185
524
  const children = placeAll(map);
@@ -258,46 +597,9 @@ function syncPlugin(binding) {
258
597
  if (!old || old.length !== ids.length || old.some((id, i) => ids[i] !== id)) structural = true;
259
598
  }
260
599
  if (structural) binding.stopCapturing?.();
261
- const stale = [];
262
- ydoc.transact(() => {
263
- for (const [id, placed] of after.blocks) {
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);
600
+ const stale = ydoc.transact(() => writeChanges(map, before, after, schema), tracked ? binding.origin : binding.untracked);
601
+ for (const id of after.blocks.keys()) cache.set(id, after.blocks.get(id).content);
602
+ for (const id of before.blocks.keys()) if (!after.blocks.has(id)) cache.delete(id);
301
603
  if (structural) binding.stopCapturing?.();
302
604
  synced = after;
303
605
  if (stale.length) {
@@ -376,6 +678,6 @@ function syncPlugin(binding) {
376
678
  }
377
679
  });
378
680
  }
379
- export { collaborationKey, createBinding, readDoc, syncPlugin, writeDoc };
681
+ export { collaborationKey, createBinding, readDoc, syncPlugin, updateDoc, writeDoc };
380
682
 
381
683
  //# sourceMappingURL=binding.js.map