@prosekit/extensions 0.11.3 → 0.11.5
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/commit/style.css +2 -0
- package/dist/commit/style.css.map +1 -0
- package/dist/commit/style.js +1 -0
- package/dist/{drop-indicator-B8P652g2.js → drop-indicator-D1eHOhSi.js} +6 -5
- package/dist/drop-indicator-D1eHOhSi.js.map +1 -0
- package/dist/enter-rule-RdhEA900.js +2 -1
- package/dist/enter-rule-RdhEA900.js.map +1 -0
- package/dist/gap-cursor/style.css +2 -0
- package/dist/gap-cursor/style.css.map +1 -0
- package/dist/gap-cursor/style.js +1 -0
- package/dist/{input-rule-Gji4N7Oe.js → input-rule-B17tpW4m.js} +3 -3
- package/dist/input-rule-B17tpW4m.js.map +1 -0
- package/dist/list/style.css +2 -0
- package/dist/list/style.css.map +1 -0
- package/dist/list/style.js +1 -0
- package/dist/loro/style.css +2 -0
- package/dist/loro/style.css.map +1 -0
- package/dist/loro/style.js +1 -0
- package/dist/{mark-rule-D7zaa32n.js → mark-rule-BCqIZMDu.js} +3 -3
- package/dist/mark-rule-BCqIZMDu.js.map +1 -0
- package/dist/{paste-rule-Cca3n5TA.js → paste-rule-DIEJKIje.js} +5 -15
- package/dist/paste-rule-DIEJKIje.js.map +1 -0
- package/dist/placeholder/style.css +2 -0
- package/dist/placeholder/style.css.map +1 -0
- package/dist/placeholder/style.js +1 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +2 -1
- package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -0
- package/dist/prosekit-extensions-autocomplete.js +2 -9
- package/dist/prosekit-extensions-autocomplete.js.map +1 -0
- package/dist/prosekit-extensions-blockquote.d.ts +2 -1
- package/dist/prosekit-extensions-blockquote.d.ts.map +1 -0
- package/dist/prosekit-extensions-blockquote.js +4 -4
- package/dist/prosekit-extensions-blockquote.js.map +1 -0
- package/dist/prosekit-extensions-bold.d.ts +2 -1
- package/dist/prosekit-extensions-bold.d.ts.map +1 -0
- package/dist/prosekit-extensions-bold.js +3 -2
- package/dist/prosekit-extensions-bold.js.map +1 -0
- package/dist/prosekit-extensions-code-block.d.ts +2 -1
- package/dist/prosekit-extensions-code-block.d.ts.map +1 -0
- package/dist/prosekit-extensions-code-block.js +5 -6
- package/dist/prosekit-extensions-code-block.js.map +1 -0
- package/dist/prosekit-extensions-code.d.ts +2 -1
- package/dist/prosekit-extensions-code.d.ts.map +1 -0
- package/dist/prosekit-extensions-code.js +3 -2
- package/dist/prosekit-extensions-code.js.map +1 -0
- package/dist/prosekit-extensions-commit.d.ts +2 -1
- package/dist/prosekit-extensions-commit.d.ts.map +1 -0
- package/dist/prosekit-extensions-commit.js +11 -13
- package/dist/prosekit-extensions-commit.js.map +1 -0
- package/dist/prosekit-extensions-doc.d.ts +2 -1
- package/dist/prosekit-extensions-doc.d.ts.map +1 -0
- package/dist/prosekit-extensions-doc.js +2 -1
- package/dist/prosekit-extensions-doc.js.map +1 -0
- package/dist/prosekit-extensions-drop-cursor.d.ts +2 -1
- package/dist/prosekit-extensions-drop-cursor.d.ts.map +1 -0
- package/dist/prosekit-extensions-drop-cursor.js +2 -1
- package/dist/prosekit-extensions-drop-cursor.js.map +1 -0
- package/dist/prosekit-extensions-drop-indicator.d.ts +2 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts.map +1 -0
- package/dist/prosekit-extensions-drop-indicator.js +1 -1
- package/dist/prosekit-extensions-enter-rule.d.ts +2 -1
- package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -0
- package/dist/prosekit-extensions-file.d.ts +2 -1
- package/dist/prosekit-extensions-file.d.ts.map +1 -0
- package/dist/prosekit-extensions-file.js +4 -16
- package/dist/prosekit-extensions-file.js.map +1 -0
- package/dist/prosekit-extensions-gap-cursor.d.ts +2 -2
- package/dist/prosekit-extensions-gap-cursor.d.ts.map +1 -0
- package/dist/prosekit-extensions-gap-cursor.js +2 -1
- package/dist/prosekit-extensions-gap-cursor.js.map +1 -0
- package/dist/prosekit-extensions-hard-break.d.ts +2 -1
- package/dist/prosekit-extensions-hard-break.d.ts.map +1 -0
- package/dist/prosekit-extensions-hard-break.js +2 -1
- package/dist/prosekit-extensions-hard-break.js.map +1 -0
- package/dist/prosekit-extensions-heading.d.ts +2 -1
- package/dist/prosekit-extensions-heading.d.ts.map +1 -0
- package/dist/prosekit-extensions-heading.js +5 -6
- package/dist/prosekit-extensions-heading.js.map +1 -0
- package/dist/prosekit-extensions-horizontal-rule.d.ts +2 -1
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -0
- package/dist/prosekit-extensions-horizontal-rule.js +5 -6
- package/dist/prosekit-extensions-horizontal-rule.js.map +1 -0
- package/dist/prosekit-extensions-image.d.ts +2 -1
- package/dist/prosekit-extensions-image.d.ts.map +1 -0
- package/dist/prosekit-extensions-image.js +3 -3
- package/dist/prosekit-extensions-image.js.map +1 -0
- package/dist/prosekit-extensions-input-rule.d.ts +2 -1
- package/dist/prosekit-extensions-input-rule.d.ts.map +1 -0
- package/dist/prosekit-extensions-input-rule.js +1 -1
- package/dist/prosekit-extensions-italic.d.ts +2 -1
- package/dist/prosekit-extensions-italic.d.ts.map +1 -0
- package/dist/prosekit-extensions-italic.js +3 -2
- package/dist/prosekit-extensions-italic.js.map +1 -0
- package/dist/prosekit-extensions-link.d.ts +2 -1
- package/dist/prosekit-extensions-link.d.ts.map +1 -0
- package/dist/prosekit-extensions-link.js +6 -5
- package/dist/prosekit-extensions-link.js.map +1 -0
- package/dist/prosekit-extensions-list.d.ts +22 -21
- package/dist/prosekit-extensions-list.d.ts.map +1 -0
- package/dist/prosekit-extensions-list.js +6 -7
- package/dist/prosekit-extensions-list.js.map +1 -0
- package/dist/prosekit-extensions-loro.d.ts +14 -13
- package/dist/prosekit-extensions-loro.d.ts.map +1 -0
- package/dist/prosekit-extensions-loro.js +2 -1
- package/dist/prosekit-extensions-loro.js.map +1 -0
- package/dist/prosekit-extensions-mark-rule.d.ts +2 -1
- package/dist/prosekit-extensions-mark-rule.d.ts.map +1 -0
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-mention.d.ts +2 -1
- package/dist/prosekit-extensions-mention.d.ts.map +1 -0
- package/dist/prosekit-extensions-mention.js +2 -1
- package/dist/prosekit-extensions-mention.js.map +1 -0
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +2 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +1 -0
- package/dist/prosekit-extensions-mod-click-prevention.js +2 -1
- package/dist/prosekit-extensions-mod-click-prevention.js.map +1 -0
- package/dist/prosekit-extensions-paragraph.d.ts +2 -1
- package/dist/prosekit-extensions-paragraph.d.ts.map +1 -0
- package/dist/prosekit-extensions-paragraph.js +2 -1
- package/dist/prosekit-extensions-paragraph.js.map +1 -0
- package/dist/prosekit-extensions-paste-rule.d.ts +2 -1
- package/dist/prosekit-extensions-paste-rule.d.ts.map +1 -0
- package/dist/prosekit-extensions-paste-rule.js +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts +2 -1
- package/dist/prosekit-extensions-placeholder.d.ts.map +1 -0
- package/dist/prosekit-extensions-placeholder.js +5 -4
- package/dist/prosekit-extensions-placeholder.js.map +1 -0
- package/dist/prosekit-extensions-readonly.d.ts +2 -1
- package/dist/prosekit-extensions-readonly.d.ts.map +1 -0
- package/dist/prosekit-extensions-readonly.js +2 -1
- package/dist/prosekit-extensions-readonly.js.map +1 -0
- package/dist/prosekit-extensions-search.d.ts +2 -1
- package/dist/prosekit-extensions-search.d.ts.map +1 -0
- package/dist/prosekit-extensions-search.js +3 -3
- package/dist/prosekit-extensions-search.js.map +1 -0
- package/dist/prosekit-extensions-strike.d.ts +2 -1
- package/dist/prosekit-extensions-strike.d.ts.map +1 -0
- package/dist/prosekit-extensions-strike.js +3 -2
- package/dist/prosekit-extensions-strike.js.map +1 -0
- package/dist/prosekit-extensions-table.d.ts +56 -114
- package/dist/prosekit-extensions-table.d.ts.map +1 -0
- package/dist/prosekit-extensions-table.js +3 -2
- package/dist/prosekit-extensions-text-align.d.ts +2 -1
- package/dist/prosekit-extensions-text-align.d.ts.map +1 -0
- package/dist/prosekit-extensions-text-align.js +2 -1
- package/dist/prosekit-extensions-text-align.js.map +1 -0
- package/dist/prosekit-extensions-text.d.ts +2 -1
- package/dist/prosekit-extensions-text.d.ts.map +1 -0
- package/dist/prosekit-extensions-text.js +2 -1
- package/dist/prosekit-extensions-text.js.map +1 -0
- package/dist/prosekit-extensions-underline.d.ts +2 -1
- package/dist/prosekit-extensions-underline.d.ts.map +1 -0
- package/dist/prosekit-extensions-underline.js +2 -1
- package/dist/prosekit-extensions-underline.js.map +1 -0
- package/dist/prosekit-extensions-virtual-selection.d.ts +2 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts.map +1 -0
- package/dist/prosekit-extensions-virtual-selection.js +3 -3
- package/dist/prosekit-extensions-virtual-selection.js.map +1 -0
- package/dist/prosekit-extensions-yjs.d.ts +2 -1
- package/dist/prosekit-extensions-yjs.d.ts.map +1 -0
- package/dist/prosekit-extensions-yjs.js +2 -1
- package/dist/prosekit-extensions-yjs.js.map +1 -0
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/prosekit-extensions.js +1 -0
- package/dist/search/style.css +2 -0
- package/dist/search/style.css.map +1 -0
- package/dist/search/style.js +1 -0
- package/dist/shiki-highlighter-chunk-DSPM0T27.d.ts +2 -1
- package/dist/shiki-highlighter-chunk-DSPM0T27.d.ts.map +1 -0
- package/dist/shiki-highlighter-chunk.js +3 -5
- package/dist/shiki-highlighter-chunk.js.map +1 -0
- package/dist/table/style.css +2 -0
- package/dist/table/style.css.map +1 -0
- package/dist/table/style.js +1 -0
- package/dist/table-Bi7WsMI3.js +297 -0
- package/dist/table-Bi7WsMI3.js.map +1 -0
- package/dist/virtual-selection/style.css +2 -0
- package/dist/virtual-selection/style.css.map +1 -0
- package/dist/virtual-selection/style.js +1 -0
- package/dist/yjs/style.css +2 -0
- package/dist/yjs/style.css.map +1 -0
- package/dist/yjs/style.js +1 -0
- package/package.json +10 -9
- package/src/autocomplete/autocomplete-helpers.ts +74 -0
- package/src/autocomplete/autocomplete-plugin.ts +186 -0
- package/src/autocomplete/autocomplete-rule.ts +117 -0
- package/src/autocomplete/autocomplete.spec.ts +132 -0
- package/src/autocomplete/autocomplete.ts +29 -0
- package/src/autocomplete/index.ts +9 -0
- package/src/blockquote/blockquote-commands.ts +32 -0
- package/src/blockquote/blockquote-input-rule.ts +14 -0
- package/src/blockquote/blockquote-keymap.spec.ts +45 -0
- package/src/blockquote/blockquote-keymap.ts +31 -0
- package/src/blockquote/blockquote-spec.ts +24 -0
- package/src/blockquote/blockquote.ts +34 -0
- package/src/blockquote/index.ts +14 -0
- package/src/bold/bold-commands.ts +23 -0
- package/src/bold/bold-input-rule.spec.ts +51 -0
- package/src/bold/bold-input-rule.ts +18 -0
- package/src/bold/bold-keymap.ts +14 -0
- package/src/bold/bold-spec.ts +53 -0
- package/src/bold/bold.ts +32 -0
- package/src/bold/index.ts +14 -0
- package/src/code/code-commands.ts +23 -0
- package/src/code/code-input-rule.ts +18 -0
- package/src/code/code-keymap.ts +14 -0
- package/src/code/code-spec.ts +28 -0
- package/src/code/code.ts +32 -0
- package/src/code/index.ts +14 -0
- package/src/code-block/code-block-commands.ts +44 -0
- package/src/code-block/code-block-highlight.ts +40 -0
- package/src/code-block/code-block-input-rule.ts +36 -0
- package/src/code-block/code-block-keymap.ts +61 -0
- package/src/code-block/code-block-shiki.ts +58 -0
- package/src/code-block/code-block-spec.spec.ts +164 -0
- package/src/code-block/code-block-spec.ts +71 -0
- package/src/code-block/code-block-types.ts +8 -0
- package/src/code-block/code-block.ts +46 -0
- package/src/code-block/index.ts +32 -0
- package/src/code-block/shiki-bundle.ts +8 -0
- package/src/code-block/shiki-highlighter-chunk.ts +84 -0
- package/src/code-block/shiki-highlighter.ts +22 -0
- package/src/code-block/shiki-parser.ts +36 -0
- package/src/commit/index.ts +330 -0
- package/src/commit/style.css +7 -0
- package/src/doc/index.ts +21 -0
- package/src/drop-cursor/drop-cursor.ts +46 -0
- package/src/drop-cursor/index.ts +5 -0
- package/src/drop-indicator/drop-indicator-facet.ts +84 -0
- package/src/drop-indicator/drop-indicator-plugin.ts +147 -0
- package/src/drop-indicator/drop-indicator.ts +37 -0
- package/src/drop-indicator/drop-target.ts +168 -0
- package/src/drop-indicator/index.ts +14 -0
- package/src/drop-indicator/types.ts +90 -0
- package/src/enter-rule/index.ts +241 -0
- package/src/file/file-drop-handler.ts +75 -0
- package/src/file/file-paste-handler.spec.ts +95 -0
- package/src/file/file-paste-handler.ts +59 -0
- package/src/file/file-upload.ts +119 -0
- package/src/file/helpers.ts +39 -0
- package/src/file/index.ts +16 -0
- package/src/gap-cursor/gap-cursor.ts +28 -0
- package/src/gap-cursor/index.ts +4 -0
- package/src/gap-cursor/style.css +25 -0
- package/src/hard-break/hard-break-commands.ts +31 -0
- package/src/hard-break/hard-break-keymap.spec.ts +45 -0
- package/src/hard-break/hard-break-keymap.ts +16 -0
- package/src/hard-break/hard-break-spec.ts +31 -0
- package/src/hard-break/hard-break.ts +32 -0
- package/src/hard-break/index.ts +13 -0
- package/src/heading/heading-commands.ts +37 -0
- package/src/heading/heading-input-rule.ts +22 -0
- package/src/heading/heading-keymap.spec.ts +53 -0
- package/src/heading/heading-keymap.ts +40 -0
- package/src/heading/heading-spec.ts +39 -0
- package/src/heading/heading-types.ts +3 -0
- package/src/heading/heading.ts +34 -0
- package/src/heading/index.ts +15 -0
- package/src/horizontal-rule/horizontal-rule-commands.spec.ts +61 -0
- package/src/horizontal-rule/horizontal-rule-commands.ts +37 -0
- package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +61 -0
- package/src/horizontal-rule/horizontal-rule-input-rule.ts +26 -0
- package/src/horizontal-rule/horizontal-rule-spec.ts +21 -0
- package/src/horizontal-rule/horizontal-rule.ts +29 -0
- package/src/horizontal-rule/index.ts +14 -0
- package/src/image/image-commands.ts +27 -0
- package/src/image/image-spec.ts +72 -0
- package/src/image/image.ts +25 -0
- package/src/image/index.ts +13 -0
- package/src/index.ts +1 -0
- package/src/input-rule/index.ts +237 -0
- package/src/italic/index.ts +14 -0
- package/src/italic/italic-commands.spec.ts +75 -0
- package/src/italic/italic-commands.ts +23 -0
- package/src/italic/italic-input-rule.spec.ts +25 -0
- package/src/italic/italic-input-rule.ts +18 -0
- package/src/italic/italic-keymap.ts +14 -0
- package/src/italic/italic-spec.ts +35 -0
- package/src/italic/italic.ts +34 -0
- package/src/link/index.spec.ts +88 -0
- package/src/link/index.ts +156 -0
- package/src/link/link-paste-rule.spec.ts +194 -0
- package/src/link/link-paste-rule.ts +22 -0
- package/src/link/link-regex.spec.ts +82 -0
- package/src/link/link-regex.ts +79 -0
- package/src/link/link-types.ts +8 -0
- package/src/list/index.ts +25 -0
- package/src/list/list-commands.ts +61 -0
- package/src/list/list-drop-indicator.ts +37 -0
- package/src/list/list-input-rules.ts +14 -0
- package/src/list/list-keymap.spec.ts +39 -0
- package/src/list/list-keymap.ts +48 -0
- package/src/list/list-plugins.ts +35 -0
- package/src/list/list-serializer.ts +38 -0
- package/src/list/list-spec.ts +60 -0
- package/src/list/list-types.spec.ts +10 -0
- package/src/list/list-types.ts +23 -0
- package/src/list/list.spec.ts +134 -0
- package/src/list/list.ts +38 -0
- package/src/list/style.css +128 -0
- package/src/loro/index.ts +17 -0
- package/src/loro/loro-commands.ts +27 -0
- package/src/loro/loro-cursor-plugin.ts +28 -0
- package/src/loro/loro-keymap.ts +23 -0
- package/src/loro/loro-sync-plugin.ts +14 -0
- package/src/loro/loro-undo-plugin.ts +12 -0
- package/src/loro/loro.ts +75 -0
- package/src/loro/style.css +33 -0
- package/src/mark-rule/apply.ts +129 -0
- package/src/mark-rule/index.ts +2 -0
- package/src/mark-rule/mark-rule.spec.ts +123 -0
- package/src/mark-rule/mark-rule.ts +48 -0
- package/src/mark-rule/range.ts +107 -0
- package/src/mark-rule/types.ts +30 -0
- package/src/mention/index.ts +90 -0
- package/src/mod-click-prevention/index.ts +35 -0
- package/src/paragraph/index.ts +7 -0
- package/src/paragraph/paragraph-commands.ts +29 -0
- package/src/paragraph/paragraph-keymap.ts +15 -0
- package/src/paragraph/paragraph-spec.ts +31 -0
- package/src/paragraph/paragraph.ts +37 -0
- package/src/paste-rule/index.ts +10 -0
- package/src/paste-rule/mark-paste-rule.spec.ts +112 -0
- package/src/paste-rule/mark-paste-rule.ts +194 -0
- package/src/paste-rule/paste-rule-plugin.ts +53 -0
- package/src/paste-rule/paste-rule.spec.ts +96 -0
- package/src/paste-rule/paste-rule.ts +60 -0
- package/src/paste-rule/split-text-by-regex.spec.ts +97 -0
- package/src/paste-rule/split-text-by-regex.ts +44 -0
- package/src/placeholder/index.ts +113 -0
- package/src/placeholder/style.css +7 -0
- package/src/readonly/index.ts +22 -0
- package/src/search/index.ts +140 -0
- package/src/search/style.css +13 -0
- package/src/strike/index.ts +101 -0
- package/src/table/index.ts +53 -0
- package/src/table/style.css +42 -0
- package/src/table/table-commands/delete-cell-selection.spec.ts +41 -0
- package/src/table/table-commands/delete-cell-selection.ts +1 -0
- package/src/table/table-commands/exit-table.spec.ts +45 -0
- package/src/table/table-commands/exit-table.ts +49 -0
- package/src/table/table-commands/insert-table.spec.ts +39 -0
- package/src/table/table-commands/insert-table.ts +80 -0
- package/src/table/table-commands/move-table-column.spec.ts +618 -0
- package/src/table/table-commands/move-table-column.ts +4 -0
- package/src/table/table-commands/move-table-row.spec.ts +380 -0
- package/src/table/table-commands/move-table-row.ts +4 -0
- package/src/table/table-commands/select-table-cell.spec.ts +34 -0
- package/src/table/table-commands/select-table-cell.ts +35 -0
- package/src/table/table-commands/select-table-column.spec.ts +33 -0
- package/src/table/table-commands/select-table-column.ts +39 -0
- package/src/table/table-commands/select-table-row.spec.ts +32 -0
- package/src/table/table-commands/select-table-row.ts +39 -0
- package/src/table/table-commands/select-table.spec.ts +36 -0
- package/src/table/table-commands/select-table.ts +50 -0
- package/src/table/table-commands.ts +110 -0
- package/src/table/table-drop-indicator.ts +40 -0
- package/src/table/table-plugins.ts +15 -0
- package/src/table/table-spec.spec.ts +113 -0
- package/src/table/table-spec.ts +109 -0
- package/src/table/table-utils.ts +16 -0
- package/src/table/table.ts +49 -0
- package/src/table/test-utils.ts +28 -0
- package/src/testing/clipboard.ts +58 -0
- package/src/testing/format-html.ts +5 -0
- package/src/testing/index.ts +161 -0
- package/src/testing/keyboard.ts +36 -0
- package/src/testing/markdown.ts +23 -0
- package/src/text/index.ts +24 -0
- package/src/text-align/index.ts +133 -0
- package/src/types/assert-type-equal.ts +8 -0
- package/src/underline/index.ts +83 -0
- package/src/virtual-selection/index.ts +100 -0
- package/src/virtual-selection/style.css +5 -0
- package/src/yjs/index.ts +22 -0
- package/src/yjs/style.css +31 -0
- package/src/yjs/yjs-commands.ts +27 -0
- package/src/yjs/yjs-cursor-plugin.ts +25 -0
- package/src/yjs/yjs-keymap.ts +23 -0
- package/src/yjs/yjs-sync-plugin.ts +23 -0
- package/src/yjs/yjs-undo-plugin.ts +87 -0
- package/src/yjs/yjs.ts +84 -0
- package/dist/table-C_qAMj5-.js +0 -734
package/src/loro/loro.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Priority,
|
|
3
|
+
union,
|
|
4
|
+
withPriority,
|
|
5
|
+
type PlainExtension,
|
|
6
|
+
type Union,
|
|
7
|
+
} from '@prosekit/core'
|
|
8
|
+
import type {
|
|
9
|
+
CursorAwareness,
|
|
10
|
+
LoroDocType,
|
|
11
|
+
LoroSyncPluginProps,
|
|
12
|
+
LoroUndoPluginProps,
|
|
13
|
+
} from 'loro-prosemirror'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
defineLoroCommands,
|
|
17
|
+
type LoroCommandsExtension,
|
|
18
|
+
} from './loro-commands'
|
|
19
|
+
import {
|
|
20
|
+
defineLoroCursorPlugin,
|
|
21
|
+
type LoroCursorOptions,
|
|
22
|
+
} from './loro-cursor-plugin'
|
|
23
|
+
import { defineLoroKeymap } from './loro-keymap'
|
|
24
|
+
import { defineLoroSyncPlugin } from './loro-sync-plugin'
|
|
25
|
+
import { defineLoroUndoPlugin } from './loro-undo-plugin'
|
|
26
|
+
|
|
27
|
+
export interface LoroOptions {
|
|
28
|
+
/**
|
|
29
|
+
* The Loro instance handles the state of shared data.
|
|
30
|
+
*/
|
|
31
|
+
doc: LoroDocType
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The Awareness instance.
|
|
35
|
+
*/
|
|
36
|
+
awareness: CursorAwareness
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extra options for `LoroSyncPlugin`.
|
|
40
|
+
*/
|
|
41
|
+
sync?: Omit<LoroSyncPluginProps, 'doc'>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Extra options for the `LoroUndoPlugin`.
|
|
45
|
+
*/
|
|
46
|
+
undo?: Omit<LoroUndoPluginProps, 'doc'>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Extra options for `LoroCursorPlugin`.
|
|
50
|
+
*/
|
|
51
|
+
cursor?: Omit<LoroCursorOptions, 'awareness'>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export type LoroExtension = Union<[LoroCommandsExtension, PlainExtension]>
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export function defineLoro(options: LoroOptions): LoroExtension {
|
|
63
|
+
const { doc, awareness, sync, undo, cursor } = options
|
|
64
|
+
|
|
65
|
+
return withPriority(
|
|
66
|
+
union([
|
|
67
|
+
defineLoroKeymap(),
|
|
68
|
+
defineLoroCommands(),
|
|
69
|
+
defineLoroCursorPlugin({ ...cursor, awareness }),
|
|
70
|
+
defineLoroUndoPlugin({ ...undo, doc }),
|
|
71
|
+
defineLoroSyncPlugin({ ...sync, doc }),
|
|
72
|
+
]),
|
|
73
|
+
Priority.high,
|
|
74
|
+
)
|
|
75
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.ProseMirror-loro-cursor:first-child {
|
|
2
|
+
margin-top: 16px;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* This gives the remote user caret. The colors are automatically overwritten */
|
|
6
|
+
.ProseMirror-loro-cursor {
|
|
7
|
+
position: relative;
|
|
8
|
+
margin-right: -1px;
|
|
9
|
+
margin-left: -1px;
|
|
10
|
+
border-right: 1px solid black;
|
|
11
|
+
border-left: 1px solid black;
|
|
12
|
+
border-color: orange;
|
|
13
|
+
word-break: normal;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* This renders the username above the caret */
|
|
18
|
+
.ProseMirror-loro-cursor > div {
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: -1.05em;
|
|
21
|
+
left: -1px;
|
|
22
|
+
padding-right: 2px;
|
|
23
|
+
padding-left: 2px;
|
|
24
|
+
background-color: rgb(250, 129, 0);
|
|
25
|
+
color: white;
|
|
26
|
+
font-style: normal;
|
|
27
|
+
font-weight: normal;
|
|
28
|
+
font-size: 13px;
|
|
29
|
+
line-height: normal;
|
|
30
|
+
font-family: serif;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
user-select: none;
|
|
33
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMarkType,
|
|
3
|
+
maybeRun,
|
|
4
|
+
OBJECT_REPLACEMENT_CHARACTER,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import type {
|
|
7
|
+
Mark,
|
|
8
|
+
ProseMirrorNode,
|
|
9
|
+
} from '@prosekit/pm/model'
|
|
10
|
+
import type {
|
|
11
|
+
EditorState,
|
|
12
|
+
Transaction,
|
|
13
|
+
} from '@prosekit/pm/state'
|
|
14
|
+
|
|
15
|
+
import { getCheckRanges } from './range'
|
|
16
|
+
import type { MarkRuleOptions } from './types'
|
|
17
|
+
|
|
18
|
+
type MarkRange = [from: number, to: number, mark: Mark]
|
|
19
|
+
|
|
20
|
+
function getExpectedMarkings(
|
|
21
|
+
rules: MarkRuleOptions[],
|
|
22
|
+
doc: ProseMirrorNode,
|
|
23
|
+
from: number,
|
|
24
|
+
to: number,
|
|
25
|
+
): MarkRange[] {
|
|
26
|
+
const text = doc.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER)
|
|
27
|
+
const ranges: MarkRange[] = []
|
|
28
|
+
|
|
29
|
+
for (const rule of rules) {
|
|
30
|
+
rule.regex.lastIndex = 0
|
|
31
|
+
const matches = text.matchAll(rule.regex)
|
|
32
|
+
const markType = getMarkType(doc.type.schema, rule.type)
|
|
33
|
+
|
|
34
|
+
for (const match of matches) {
|
|
35
|
+
const index = match.index
|
|
36
|
+
if (index == null) continue
|
|
37
|
+
const attrs = maybeRun(rule.attrs, match)
|
|
38
|
+
const mark = markType.create(attrs)
|
|
39
|
+
ranges.push([from + index, from + index + match[0].length, mark])
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Sort by start position. If start positions are equal, the longer match
|
|
44
|
+
// should be prioritized.
|
|
45
|
+
ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1])
|
|
46
|
+
|
|
47
|
+
// Remove overlapped marks.
|
|
48
|
+
const result: MarkRange[] = []
|
|
49
|
+
let freeIndex = 0
|
|
50
|
+
|
|
51
|
+
for (const range of ranges) {
|
|
52
|
+
if (range[0] >= freeIndex) {
|
|
53
|
+
result.push(range)
|
|
54
|
+
freeIndex = range[1]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getReceivedMarkings(
|
|
62
|
+
rules: MarkRuleOptions[],
|
|
63
|
+
doc: ProseMirrorNode,
|
|
64
|
+
from: number,
|
|
65
|
+
to: number,
|
|
66
|
+
): MarkRange[] {
|
|
67
|
+
const result: MarkRange[] = []
|
|
68
|
+
const schema = doc.type.schema
|
|
69
|
+
const markTypes = rules.map((rule) => getMarkType(schema, rule.type))
|
|
70
|
+
|
|
71
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
72
|
+
if (!node.isInline) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const markType of markTypes) {
|
|
77
|
+
const mark = node.marks.find((mark) => mark.type === markType)
|
|
78
|
+
if (mark) {
|
|
79
|
+
result.push([pos, pos + node.nodeSize, mark])
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function markRangeEquals(a: MarkRange, b: MarkRange): boolean {
|
|
87
|
+
return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function markRangeDiffs(a: MarkRange[], b: MarkRange[]): MarkRange[] {
|
|
91
|
+
return a.filter((x) => !b.some((y) => markRangeEquals(x, y)))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function applyMarkRules(
|
|
95
|
+
rules: MarkRuleOptions[],
|
|
96
|
+
transactions: readonly Transaction[],
|
|
97
|
+
oldState: EditorState,
|
|
98
|
+
newState: EditorState,
|
|
99
|
+
): Transaction | null {
|
|
100
|
+
if (transactions.length === 0 || transactions.every((tr) => !tr.docChanged)) {
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ranges = getCheckRanges(transactions, oldState, newState)
|
|
105
|
+
|
|
106
|
+
const toRemove: MarkRange[] = []
|
|
107
|
+
const toCreate: MarkRange[] = []
|
|
108
|
+
|
|
109
|
+
for (const [from, to] of ranges) {
|
|
110
|
+
const expected = getExpectedMarkings(rules, newState.doc, from, to)
|
|
111
|
+
const received = getReceivedMarkings(rules, newState.doc, from, to)
|
|
112
|
+
|
|
113
|
+
toRemove.push(...markRangeDiffs(received, expected))
|
|
114
|
+
toCreate.push(...markRangeDiffs(expected, received))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (toCreate.length === 0 && toRemove.length === 0) {
|
|
118
|
+
return null
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const tr = newState.tr
|
|
122
|
+
for (const [from, to, mark] of toRemove) {
|
|
123
|
+
tr.removeMark(from, to, mark)
|
|
124
|
+
}
|
|
125
|
+
for (const [from, to, mark] of toCreate) {
|
|
126
|
+
tr.addMark(from, to, mark)
|
|
127
|
+
}
|
|
128
|
+
return tr
|
|
129
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEditor,
|
|
3
|
+
defineBaseCommands,
|
|
4
|
+
defineMarkSpec,
|
|
5
|
+
elementFromNode,
|
|
6
|
+
union,
|
|
7
|
+
type Editor,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
10
|
+
import {
|
|
11
|
+
describe,
|
|
12
|
+
expect,
|
|
13
|
+
it,
|
|
14
|
+
} from 'vitest'
|
|
15
|
+
|
|
16
|
+
import { defineDoc } from '../doc'
|
|
17
|
+
import { defineParagraph } from '../paragraph'
|
|
18
|
+
import { defineText } from '../text'
|
|
19
|
+
|
|
20
|
+
import { defineMarkRule } from './index'
|
|
21
|
+
|
|
22
|
+
describe('defineMarkRule', () => {
|
|
23
|
+
const editor = createEditor({
|
|
24
|
+
extension: union(
|
|
25
|
+
defineDoc(),
|
|
26
|
+
defineText(),
|
|
27
|
+
defineParagraph(),
|
|
28
|
+
defineBaseCommands(),
|
|
29
|
+
defineMarkSpec({
|
|
30
|
+
name: 'tag' as const,
|
|
31
|
+
toDOM: () => {
|
|
32
|
+
return ['mark-tag', 0]
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
defineMarkRule({
|
|
36
|
+
regex: /#\d+/g,
|
|
37
|
+
type: 'tag',
|
|
38
|
+
}),
|
|
39
|
+
defineMarkSpec({
|
|
40
|
+
name: 'link' as const,
|
|
41
|
+
toDOM: () => {
|
|
42
|
+
return ['mark-link', 0]
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
defineMarkRule({
|
|
46
|
+
regex: /example\.com(#\d+)?/g,
|
|
47
|
+
type: 'link',
|
|
48
|
+
}),
|
|
49
|
+
defineMarkSpec({
|
|
50
|
+
name: 'email' as const,
|
|
51
|
+
toDOM: () => {
|
|
52
|
+
return ['mark-email', 0]
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
defineMarkRule({
|
|
56
|
+
regex: /[a-z]+@example\.com/g,
|
|
57
|
+
type: 'email',
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const triggerMarkRule = (doc: ProseMirrorNode): string => {
|
|
63
|
+
setDoc(editor, doc)
|
|
64
|
+
editor.commands.insertText({ from: 1, text: ' ' })
|
|
65
|
+
return elementFromNode(editor.state.doc).innerHTML
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const n = { ...editor.nodes, p: editor.nodes.paragraph }
|
|
69
|
+
|
|
70
|
+
it('can match tag', () => {
|
|
71
|
+
const doc = n.doc(n.p('#12345'))
|
|
72
|
+
const html = triggerMarkRule(doc)
|
|
73
|
+
|
|
74
|
+
expect(html).toMatchInlineSnapshot(`"<p> <mark-tag>#12345</mark-tag></p>"`)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('can match link', () => {
|
|
78
|
+
const doc = n.doc(n.p('example.com'))
|
|
79
|
+
const html = triggerMarkRule(doc)
|
|
80
|
+
|
|
81
|
+
expect(html).toMatchInlineSnapshot(
|
|
82
|
+
`"<p> <mark-link>example.com</mark-link></p>"`,
|
|
83
|
+
)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('can match link with anchor', () => {
|
|
87
|
+
const doc = n.doc(n.p('example.com#12345'))
|
|
88
|
+
const html = triggerMarkRule(doc)
|
|
89
|
+
|
|
90
|
+
expect(html).toMatchInlineSnapshot(
|
|
91
|
+
`"<p> <mark-link>example.com#12345</mark-link></p>"`,
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('can match email', () => {
|
|
96
|
+
const doc = n.doc(n.p('hello@example.com'))
|
|
97
|
+
const html = triggerMarkRule(doc)
|
|
98
|
+
|
|
99
|
+
expect(html).toMatchInlineSnapshot(
|
|
100
|
+
`"<p> <mark-email>hello@example.com</mark-email></p>"`,
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('can match email and tag', () => {
|
|
105
|
+
const doc = n.doc(n.p('hello@example.com#12345'))
|
|
106
|
+
const html = triggerMarkRule(doc)
|
|
107
|
+
|
|
108
|
+
expect(html).toMatchInlineSnapshot(
|
|
109
|
+
`"<p> <mark-email>hello@example.com</mark-email><mark-tag>#12345</mark-tag></p>"`,
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
function setDoc(editor: Editor, doc: ProseMirrorNode) {
|
|
115
|
+
if (!editor.mounted) {
|
|
116
|
+
const div = document.createElement('div')
|
|
117
|
+
editor.mount(div)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tr = editor.state.tr
|
|
121
|
+
tr.replaceWith(0, tr.doc.content.size, doc.content)
|
|
122
|
+
editor.view.dispatch(tr)
|
|
123
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineFacet,
|
|
3
|
+
defineFacetPayload,
|
|
4
|
+
pluginFacet,
|
|
5
|
+
type PlainExtension,
|
|
6
|
+
type PluginPayload,
|
|
7
|
+
} from '@prosekit/core'
|
|
8
|
+
import {
|
|
9
|
+
PluginKey,
|
|
10
|
+
ProseMirrorPlugin,
|
|
11
|
+
type EditorState,
|
|
12
|
+
type Transaction,
|
|
13
|
+
} from '@prosekit/pm/state'
|
|
14
|
+
|
|
15
|
+
import { applyMarkRules } from './apply'
|
|
16
|
+
import type { MarkRuleOptions } from './types'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A mark rule is something that can automatically apply marks to text if it
|
|
20
|
+
* matches a certain pattern, and remove them if it doesn't match anymore.
|
|
21
|
+
*/
|
|
22
|
+
export function defineMarkRule(options: MarkRuleOptions): PlainExtension {
|
|
23
|
+
return defineFacetPayload(markRuleFacet, [options]) as PlainExtension
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const markRuleFacet = defineFacet<MarkRuleOptions, PluginPayload>({
|
|
27
|
+
reduce: () => {
|
|
28
|
+
let rules: MarkRuleOptions[] = []
|
|
29
|
+
|
|
30
|
+
const plugin = new ProseMirrorPlugin({
|
|
31
|
+
key: new PluginKey('prosekit-mark-rule'),
|
|
32
|
+
appendTransaction: (
|
|
33
|
+
transactions: readonly Transaction[],
|
|
34
|
+
oldState: EditorState,
|
|
35
|
+
newState: EditorState,
|
|
36
|
+
) => {
|
|
37
|
+
return applyMarkRules(rules, transactions, oldState, newState)
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return function reducer(input) {
|
|
42
|
+
rules = input
|
|
43
|
+
return plugin
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
parent: pluginFacet,
|
|
48
|
+
})
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProseMirrorNode,
|
|
3
|
+
ResolvedPos,
|
|
4
|
+
} from '@prosekit/pm/model'
|
|
5
|
+
import type {
|
|
6
|
+
EditorState,
|
|
7
|
+
Transaction,
|
|
8
|
+
} from '@prosekit/pm/state'
|
|
9
|
+
import type { ProsemirrorNode } from 'prosemirror-flat-list'
|
|
10
|
+
|
|
11
|
+
function getSpanTextRanges($from: ResolvedPos, $to: ResolvedPos) {
|
|
12
|
+
const nodeRange = $from.blockRange($to)
|
|
13
|
+
if (!nodeRange) {
|
|
14
|
+
return []
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const stack: Array<[start: number, node: ProseMirrorNode]> = []
|
|
18
|
+
let start = nodeRange.start
|
|
19
|
+
|
|
20
|
+
for (let i = nodeRange.startIndex; i < nodeRange.endIndex; i++) {
|
|
21
|
+
const child = nodeRange.parent.child(i)
|
|
22
|
+
stack.push([start, child])
|
|
23
|
+
start += child.nodeSize
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ranges: Array<[number, number]> = []
|
|
27
|
+
|
|
28
|
+
while (stack.length > 0) {
|
|
29
|
+
const [start, node] = stack.pop()!
|
|
30
|
+
if (node.type.spec.code) {
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (node.type.isTextblock) {
|
|
35
|
+
ranges.push([start + 1, start + 1 + node.content.size])
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
node.forEach((child, offset) => {
|
|
40
|
+
stack.push([start + offset + 1, child])
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return ranges
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getInlineTextRange(
|
|
48
|
+
$from: ResolvedPos,
|
|
49
|
+
$to: ResolvedPos,
|
|
50
|
+
): [number, number] {
|
|
51
|
+
return [$from.start(), $to.end()]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getTextRanges(
|
|
55
|
+
doc: ProsemirrorNode,
|
|
56
|
+
from: number,
|
|
57
|
+
to: number,
|
|
58
|
+
): Array<[number, number]> {
|
|
59
|
+
const $from = doc.resolve(from)
|
|
60
|
+
const $to = doc.resolve(to)
|
|
61
|
+
|
|
62
|
+
if ($from.sameParent($to) && $from.parent.isTextblock) {
|
|
63
|
+
return [getInlineTextRange($from, $to)]
|
|
64
|
+
} else {
|
|
65
|
+
const nodeRange = $from.blockRange($to)
|
|
66
|
+
if (!nodeRange) {
|
|
67
|
+
return []
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return getSpanTextRanges($from, $to)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getMapRange(
|
|
75
|
+
transactions: readonly Transaction[],
|
|
76
|
+
oldState: EditorState,
|
|
77
|
+
newState: EditorState,
|
|
78
|
+
) {
|
|
79
|
+
let lo = oldState.selection.from
|
|
80
|
+
let hi = oldState.selection.to
|
|
81
|
+
|
|
82
|
+
for (const tr of transactions) {
|
|
83
|
+
for (const map of tr.mapping.maps) {
|
|
84
|
+
lo = map.map(lo)
|
|
85
|
+
hi = map.map(hi)
|
|
86
|
+
|
|
87
|
+
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
88
|
+
lo = Math.min(lo, hi, newStart)
|
|
89
|
+
hi = Math.max(lo, hi, newEnd)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
lo = Math.min(lo, hi, newState.selection.from)
|
|
95
|
+
hi = Math.min(lo, hi, newState.selection.to)
|
|
96
|
+
|
|
97
|
+
return [lo, hi] as const
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getCheckRanges(
|
|
101
|
+
transactions: readonly Transaction[],
|
|
102
|
+
oldState: EditorState,
|
|
103
|
+
newState: EditorState,
|
|
104
|
+
): Array<[number, number]> {
|
|
105
|
+
const [from, to] = getMapRange(transactions, oldState, newState)
|
|
106
|
+
return getTextRanges(newState.doc, from, to)
|
|
107
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Attrs,
|
|
3
|
+
MarkType,
|
|
4
|
+
} from '@prosekit/pm/model'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The options for {@link defineMarkRule}.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface MarkRuleOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The regular expression to match against. It must has a `g` flag to match
|
|
14
|
+
* all instances of the mark.
|
|
15
|
+
*/
|
|
16
|
+
regex: RegExp
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The mark type to apply to the matched text.
|
|
20
|
+
*/
|
|
21
|
+
type: string | MarkType
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Attributes to set on the mark. If a function is provided, it will be called
|
|
25
|
+
* with the matched result from the regular expression.
|
|
26
|
+
*
|
|
27
|
+
* @default null
|
|
28
|
+
*/
|
|
29
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null)
|
|
30
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCommands,
|
|
3
|
+
defineNodeSpec,
|
|
4
|
+
insertNode,
|
|
5
|
+
union,
|
|
6
|
+
type Extension,
|
|
7
|
+
type Union,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
|
|
10
|
+
export interface MentionAttrs {
|
|
11
|
+
id: string
|
|
12
|
+
value: string
|
|
13
|
+
kind: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type MentionSpecExtension = Extension<{
|
|
20
|
+
Nodes: {
|
|
21
|
+
mention: MentionAttrs
|
|
22
|
+
}
|
|
23
|
+
}>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export function defineMentionSpec(): MentionSpecExtension {
|
|
29
|
+
return defineNodeSpec<'mention', MentionAttrs>({
|
|
30
|
+
name: 'mention',
|
|
31
|
+
atom: true,
|
|
32
|
+
group: 'inline',
|
|
33
|
+
attrs: {
|
|
34
|
+
id: { validate: 'string' },
|
|
35
|
+
value: { validate: 'string' },
|
|
36
|
+
kind: { default: '', validate: 'string' },
|
|
37
|
+
},
|
|
38
|
+
inline: true,
|
|
39
|
+
leafText: (node) => (node.attrs as MentionAttrs).value.toString(),
|
|
40
|
+
parseDOM: [
|
|
41
|
+
{
|
|
42
|
+
tag: `span[data-mention]`,
|
|
43
|
+
getAttrs: (dom: HTMLElement): MentionAttrs => ({
|
|
44
|
+
id: dom.getAttribute('data-id') || '',
|
|
45
|
+
kind: dom.getAttribute('data-mention') || '',
|
|
46
|
+
value: dom.textContent || '',
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
toDOM(node) {
|
|
51
|
+
return [
|
|
52
|
+
'span',
|
|
53
|
+
{
|
|
54
|
+
'data-id': (node.attrs as MentionAttrs).id.toString(),
|
|
55
|
+
'data-mention': (node.attrs as MentionAttrs).kind.toString(),
|
|
56
|
+
},
|
|
57
|
+
(node.attrs as MentionAttrs).value.toString(),
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export type MentionCommandsExtension = Extension<{
|
|
67
|
+
Commands: {
|
|
68
|
+
insertMention: [attrs: MentionAttrs]
|
|
69
|
+
}
|
|
70
|
+
}>
|
|
71
|
+
|
|
72
|
+
export function defineMentionCommands(): MentionCommandsExtension {
|
|
73
|
+
return defineCommands({
|
|
74
|
+
insertMention: (attrs: MentionAttrs) => {
|
|
75
|
+
return insertNode({ type: 'mention', attrs })
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export type MentionExtension = Union<[MentionSpecExtension, MentionCommandsExtension]>
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export function defineMention(): MentionExtension {
|
|
89
|
+
return union(defineMentionSpec(), defineMentionCommands())
|
|
90
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definePlugin,
|
|
3
|
+
isApple,
|
|
4
|
+
type PlainExtension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import {
|
|
7
|
+
Plugin,
|
|
8
|
+
PluginKey,
|
|
9
|
+
} from '@prosekit/pm/state'
|
|
10
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type ModClickPreventionExtension = PlainExtension
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* By default, clicking a node while holding the mod key will select the node. This
|
|
19
|
+
* extension disables that behavior.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export function defineModClickPrevention(): ModClickPreventionExtension {
|
|
24
|
+
return definePlugin(new Plugin({ key, props: { handleClick } }))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const key = new PluginKey('prosekit-mod-click-prevention')
|
|
28
|
+
|
|
29
|
+
function handleClick(_view: EditorView, _pos: number, event: MouseEvent) {
|
|
30
|
+
return !!event[selectNodeModifier]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const selectNodeModifier: 'metaKey' | 'ctrlKey' = isApple
|
|
34
|
+
? 'metaKey'
|
|
35
|
+
: 'ctrlKey'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { defineParagraph } from './paragraph'
|
|
2
|
+
export type { ParagraphExtension } from './paragraph'
|
|
3
|
+
export { defineParagraphCommands } from './paragraph-commands'
|
|
4
|
+
export type { ParagraphCommandsExtension } from './paragraph-commands'
|
|
5
|
+
export { defineParagraphKeymap } from './paragraph-keymap'
|
|
6
|
+
export { defineParagraphSpec } from './paragraph-spec'
|
|
7
|
+
export type { ParagraphSpecExtension } from './paragraph-spec'
|