@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineCodeBlock,
|
|
3
|
+
type CodeBlockExtension,
|
|
4
|
+
} from './code-block'
|
|
5
|
+
export {
|
|
6
|
+
defineCodeBlockCommands,
|
|
7
|
+
type CodeBlockCommandsExtension,
|
|
8
|
+
} from './code-block-commands'
|
|
9
|
+
export {
|
|
10
|
+
defineCodeBlockHighlight,
|
|
11
|
+
type CodeBlockHighlightOptions,
|
|
12
|
+
type HighlightParser,
|
|
13
|
+
} from './code-block-highlight'
|
|
14
|
+
export {
|
|
15
|
+
defineCodeBlockEnterRule,
|
|
16
|
+
defineCodeBlockInputRule,
|
|
17
|
+
} from './code-block-input-rule'
|
|
18
|
+
export { defineCodeBlockKeymap } from './code-block-keymap'
|
|
19
|
+
export { defineCodeBlockShiki } from './code-block-shiki'
|
|
20
|
+
export {
|
|
21
|
+
defineCodeBlockSpec,
|
|
22
|
+
type CodeBlockSpecExtension,
|
|
23
|
+
} from './code-block-spec'
|
|
24
|
+
export type { CodeBlockAttrs } from './code-block-types'
|
|
25
|
+
export {
|
|
26
|
+
shikiBundledLanguagesInfo,
|
|
27
|
+
shikiBundledThemesInfo,
|
|
28
|
+
type ShikiBundledLanguage,
|
|
29
|
+
type ShikiBundledLanguageInfo,
|
|
30
|
+
type ShikiBundledTheme,
|
|
31
|
+
type ShikiBundledThemeInfo,
|
|
32
|
+
} from './shiki-bundle'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export {
|
|
2
|
+
bundledLanguagesInfo as shikiBundledLanguagesInfo,
|
|
3
|
+
bundledThemesInfo as shikiBundledThemesInfo,
|
|
4
|
+
type BundledLanguage as ShikiBundledLanguage,
|
|
5
|
+
type BundledLanguageInfo as ShikiBundledLanguageInfo,
|
|
6
|
+
type BundledTheme as ShikiBundledTheme,
|
|
7
|
+
type BundledThemeInfo as ShikiBundledThemeInfo,
|
|
8
|
+
} from 'shiki'
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BundledHighlighterOptions,
|
|
3
|
+
BundledLanguage,
|
|
4
|
+
BundledTheme,
|
|
5
|
+
Highlighter,
|
|
6
|
+
SpecialLanguage,
|
|
7
|
+
} from 'shiki'
|
|
8
|
+
import { createHighlighter } from 'shiki/bundle/full'
|
|
9
|
+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
|
|
10
|
+
|
|
11
|
+
let highlighterPromise: Promise<void> | undefined
|
|
12
|
+
let highlighter: Highlighter | undefined
|
|
13
|
+
const loadedLangs = new Set<BundledLanguage | SpecialLanguage>()
|
|
14
|
+
const loadedThemes = new Set<BundledTheme>()
|
|
15
|
+
|
|
16
|
+
export interface ShikiHighlighterOptions extends BundledHighlighterOptions<BundledLanguage, BundledTheme> {}
|
|
17
|
+
|
|
18
|
+
export interface HighlighterOptions extends Omit<ShikiHighlighterOptions, 'langs' | 'themes'> {
|
|
19
|
+
themes: BundledTheme[]
|
|
20
|
+
langs: (BundledLanguage | SpecialLanguage)[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function ensureHighlighter({
|
|
24
|
+
...options
|
|
25
|
+
}: HighlighterOptions): Promise<void> {
|
|
26
|
+
if (!highlighterPromise) {
|
|
27
|
+
// If no engine is provided, use the JavaScript engine, which is
|
|
28
|
+
// smaller than the WASM engine.
|
|
29
|
+
if (!options.engine) {
|
|
30
|
+
const engine = createJavaScriptRegexEngine({ forgiving: true })
|
|
31
|
+
options.engine = engine
|
|
32
|
+
}
|
|
33
|
+
highlighterPromise = createHighlighter(options).then((createdHighlighter) => {
|
|
34
|
+
highlighter = createdHighlighter
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
return highlighterPromise
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function loadLanguages(langs: (BundledLanguage | SpecialLanguage)[]) {
|
|
41
|
+
for (const lang of langs) {
|
|
42
|
+
if (!highlighter) break
|
|
43
|
+
await highlighter.loadLanguage(lang)
|
|
44
|
+
loadedLangs.add(lang)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function loadThemes(themes: BundledTheme[]) {
|
|
49
|
+
for (const theme of themes) {
|
|
50
|
+
if (!highlighter) break
|
|
51
|
+
await highlighter.loadTheme(theme)
|
|
52
|
+
loadedThemes.add(theme)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type HighlighterResult =
|
|
57
|
+
| {
|
|
58
|
+
highlighter: Highlighter
|
|
59
|
+
promise?: undefined
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
highlighter?: undefined
|
|
63
|
+
promise: Promise<void>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createOrGetHighlighter(
|
|
67
|
+
options: HighlighterOptions,
|
|
68
|
+
): HighlighterResult {
|
|
69
|
+
if (!highlighter) {
|
|
70
|
+
return { promise: ensureHighlighter(options) }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const langs = options.langs.filter((lang) => !loadedLangs.has(lang))
|
|
74
|
+
if (langs.length > 0) {
|
|
75
|
+
return { promise: loadLanguages(langs) }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const themes = options.themes.filter((theme) => !loadedThemes.has(theme))
|
|
79
|
+
if (themes.length > 0) {
|
|
80
|
+
return { promise: loadThemes(themes) }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { highlighter }
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HighlighterOptions,
|
|
3
|
+
HighlighterResult,
|
|
4
|
+
} from './shiki-highlighter-chunk'
|
|
5
|
+
|
|
6
|
+
let loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined
|
|
7
|
+
|
|
8
|
+
async function load() {
|
|
9
|
+
const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk')
|
|
10
|
+
loaded = createOrGetHighlighter
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createOrGetHighlighter(
|
|
14
|
+
options: HighlighterOptions,
|
|
15
|
+
): HighlighterResult {
|
|
16
|
+
if (!loaded) {
|
|
17
|
+
return { promise: load() }
|
|
18
|
+
}
|
|
19
|
+
return loaded(options)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type { HighlighterOptions }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Parser } from 'prosemirror-highlight'
|
|
2
|
+
import { createParser } from 'prosemirror-highlight/shiki'
|
|
3
|
+
|
|
4
|
+
import type { ShikiBundledLanguage } from './shiki-bundle'
|
|
5
|
+
import {
|
|
6
|
+
createOrGetHighlighter,
|
|
7
|
+
type HighlighterOptions,
|
|
8
|
+
} from './shiki-highlighter'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function createLazyParser(
|
|
14
|
+
highlighterOptions: HighlighterOptions,
|
|
15
|
+
): Parser {
|
|
16
|
+
let parser: Parser | undefined
|
|
17
|
+
|
|
18
|
+
return function lazyParser(options) {
|
|
19
|
+
const language = (options.language || '') as ShikiBundledLanguage
|
|
20
|
+
const { highlighter, promise } = createOrGetHighlighter({
|
|
21
|
+
...highlighterOptions,
|
|
22
|
+
langs: [language],
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
if (!highlighter) {
|
|
26
|
+
return promise
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!parser) {
|
|
30
|
+
parser = createParser(highlighter, {
|
|
31
|
+
theme: highlighterOptions.themes[0],
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
return parser(options)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineDefaultState,
|
|
3
|
+
definePlugin,
|
|
4
|
+
jsonFromNode,
|
|
5
|
+
union,
|
|
6
|
+
type NodeJSON,
|
|
7
|
+
type PlainExtension,
|
|
8
|
+
type StepJSON,
|
|
9
|
+
} from '@prosekit/core'
|
|
10
|
+
import {
|
|
11
|
+
DOMSerializer,
|
|
12
|
+
Fragment,
|
|
13
|
+
Slice,
|
|
14
|
+
type ProseMirrorNode,
|
|
15
|
+
} from '@prosekit/pm/model'
|
|
16
|
+
import {
|
|
17
|
+
PluginKey,
|
|
18
|
+
ProseMirrorPlugin,
|
|
19
|
+
type Transaction,
|
|
20
|
+
} from '@prosekit/pm/state'
|
|
21
|
+
import { Step } from '@prosekit/pm/transform'
|
|
22
|
+
import {
|
|
23
|
+
Decoration,
|
|
24
|
+
DecorationSet,
|
|
25
|
+
type EditorView,
|
|
26
|
+
} from '@prosekit/pm/view'
|
|
27
|
+
import {
|
|
28
|
+
ChangeSet,
|
|
29
|
+
type Change,
|
|
30
|
+
} from 'prosemirror-changeset'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A JSON representation of a commit.
|
|
34
|
+
*/
|
|
35
|
+
interface Commit {
|
|
36
|
+
/**
|
|
37
|
+
* The current doc node in the JSON format
|
|
38
|
+
*/
|
|
39
|
+
doc: NodeJSON
|
|
40
|
+
/**
|
|
41
|
+
* The parent node in the JSON format
|
|
42
|
+
*/
|
|
43
|
+
parent: NodeJSON
|
|
44
|
+
/**
|
|
45
|
+
* An array of steps in the JSON format that transform the parent node to the
|
|
46
|
+
* current doc node.
|
|
47
|
+
*/
|
|
48
|
+
steps: StepJSON[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getChanges(
|
|
52
|
+
doc: ProseMirrorNode,
|
|
53
|
+
parent: ProseMirrorNode,
|
|
54
|
+
steps: Step[],
|
|
55
|
+
): readonly Change[] {
|
|
56
|
+
const initSet = ChangeSet.create(parent)
|
|
57
|
+
const currSet = initSet.addSteps(
|
|
58
|
+
doc,
|
|
59
|
+
steps.map((step) => step.getMap()),
|
|
60
|
+
null,
|
|
61
|
+
)
|
|
62
|
+
return currSet.changes
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function renderDivWeight(view: EditorView): HTMLElement {
|
|
66
|
+
const document = view.dom.ownerDocument
|
|
67
|
+
return document.createElement('div')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function decorateDeletionSlice(
|
|
71
|
+
slice: Slice,
|
|
72
|
+
): Array<(view: EditorView) => HTMLElement> {
|
|
73
|
+
// Get the fragment of the deleted content
|
|
74
|
+
let { openStart, openEnd, content } = slice
|
|
75
|
+
|
|
76
|
+
while (openStart > 0 && openEnd > 0 && content.childCount === 1) {
|
|
77
|
+
openStart--
|
|
78
|
+
openEnd--
|
|
79
|
+
content = content.child(0).content
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Nothing to render
|
|
83
|
+
if (content.childCount === 0) {
|
|
84
|
+
return []
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// For example, if the slice is
|
|
88
|
+
// {
|
|
89
|
+
// openStart: 1,
|
|
90
|
+
// openEnd: 1,
|
|
91
|
+
// content: <p>Hello</p><p>World</p>
|
|
92
|
+
// }
|
|
93
|
+
// We should render the following decorations:
|
|
94
|
+
// <span>Hello</span>
|
|
95
|
+
// <div></div>
|
|
96
|
+
// <span>World</span>
|
|
97
|
+
if (openStart > 0 && openEnd > 0 && content.childCount === 2) {
|
|
98
|
+
const head = Fragment.from([content.child(0)])
|
|
99
|
+
const tail = Fragment.from([content.child(1)])
|
|
100
|
+
return [
|
|
101
|
+
...decorateDeletionSlice(new Slice(head, openStart, openStart)),
|
|
102
|
+
renderDivWeight,
|
|
103
|
+
...decorateDeletionSlice(new Slice(tail, openEnd, openEnd)),
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// For example, if the slice is
|
|
108
|
+
// {
|
|
109
|
+
// openStart: 1,
|
|
110
|
+
// openEnd: 0,
|
|
111
|
+
// content: <p>Hello</p><p>World</p>
|
|
112
|
+
// }
|
|
113
|
+
// We should render the following decorations:
|
|
114
|
+
// <span>Hello</span>
|
|
115
|
+
// <div><p>World</p></div>
|
|
116
|
+
if (openStart > 0 && content.childCount >= 2) {
|
|
117
|
+
const nodes = content.content
|
|
118
|
+
const head = Fragment.from(nodes.slice(0, 1))
|
|
119
|
+
const body = Fragment.from(nodes.slice(1))
|
|
120
|
+
|
|
121
|
+
return [
|
|
122
|
+
...decorateDeletionSlice(new Slice(head, openStart, openStart)),
|
|
123
|
+
...decorateDeletionSlice(new Slice(body, 0, openEnd)),
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// For example, if the slice is
|
|
128
|
+
// {
|
|
129
|
+
// openStart: 0,
|
|
130
|
+
// openEnd: 1,
|
|
131
|
+
// content: <p>Hello</p><p>World</p>
|
|
132
|
+
// }
|
|
133
|
+
// We should render the following decorations:
|
|
134
|
+
// <div><p>Hello</p></div>
|
|
135
|
+
// <span>World</span>
|
|
136
|
+
if (openEnd > 0 && content.childCount >= 2) {
|
|
137
|
+
const nodes = content.content
|
|
138
|
+
const body = Fragment.from(nodes.slice(0, -1))
|
|
139
|
+
const tail = Fragment.from(nodes.slice(-1))
|
|
140
|
+
return [
|
|
141
|
+
...decorateDeletionSlice(new Slice(body, openStart, 0)),
|
|
142
|
+
...decorateDeletionSlice(new Slice(tail, openEnd, openEnd)),
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const schema = content.child(0).type.schema
|
|
147
|
+
const isInline = content.child(0).isInline
|
|
148
|
+
|
|
149
|
+
const render = (view: EditorView): HTMLElement => {
|
|
150
|
+
const document = view.dom.ownerDocument
|
|
151
|
+
|
|
152
|
+
// Render the fragment to HTML
|
|
153
|
+
const element = document.createElement(isInline ? 'span' : 'div')
|
|
154
|
+
const serializer = DOMSerializer.fromSchema(schema)
|
|
155
|
+
serializer.serializeFragment(content, { document }, element)
|
|
156
|
+
|
|
157
|
+
// Add the class to the element
|
|
158
|
+
element.classList.add('prosekit-commit-deletion')
|
|
159
|
+
return element
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return [render]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function decorateDeletion(
|
|
166
|
+
/** The doc node before the deletion */
|
|
167
|
+
doc: ProseMirrorNode,
|
|
168
|
+
/** The start position of the deleted text in the doc node */
|
|
169
|
+
from: number,
|
|
170
|
+
/** The end position of the deleted text in the doc node */
|
|
171
|
+
to: number,
|
|
172
|
+
/** The insert position of the decoration in the doc node after the change */
|
|
173
|
+
pos: number,
|
|
174
|
+
): Decoration[] {
|
|
175
|
+
const slice = doc.slice(from, to)
|
|
176
|
+
|
|
177
|
+
const renders = decorateDeletionSlice(slice)
|
|
178
|
+
const count = renders.length
|
|
179
|
+
|
|
180
|
+
return renders.map((render, index) =>
|
|
181
|
+
Decoration.widget(pos, render, {
|
|
182
|
+
side: -20 - count + index,
|
|
183
|
+
// Ensure the text in the decoration is able to be selected.
|
|
184
|
+
ignoreSelection: true,
|
|
185
|
+
})
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function decorateAddition(
|
|
190
|
+
/** The start position of the inserted text in the doc node */
|
|
191
|
+
from: number,
|
|
192
|
+
/** The end position of the inserted text in the doc node */
|
|
193
|
+
to: number,
|
|
194
|
+
): Decoration {
|
|
195
|
+
return Decoration.inline(from, to, { class: 'prosekit-commit-addition' })
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function decorateChange(prev: ProseMirrorNode, change: Change): Decoration[] {
|
|
199
|
+
const { fromA, toA, fromB, toB } = change
|
|
200
|
+
const decorations: Decoration[] = []
|
|
201
|
+
|
|
202
|
+
if (fromA < toA) {
|
|
203
|
+
decorations.push(...decorateDeletion(prev, fromA, toA, fromB))
|
|
204
|
+
}
|
|
205
|
+
if (fromB < toB) {
|
|
206
|
+
decorations.push(decorateAddition(fromB, toB))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return decorations
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function decorateCommit(
|
|
213
|
+
doc: ProseMirrorNode,
|
|
214
|
+
parent: ProseMirrorNode,
|
|
215
|
+
steps: Step[],
|
|
216
|
+
): DecorationSet {
|
|
217
|
+
const changes = getChanges(doc, parent, steps)
|
|
218
|
+
const decorations = changes.flatMap((change) => decorateChange(parent, change))
|
|
219
|
+
return DecorationSet.create(doc, decorations)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function defineCommitDecoration(commit: Commit): PlainExtension {
|
|
223
|
+
const key = new PluginKey<DecorationSet>('prosekit-commit-decoration')
|
|
224
|
+
|
|
225
|
+
return definePlugin(({ schema }): ProseMirrorPlugin => {
|
|
226
|
+
const parent = schema.nodeFromJSON(commit.parent)
|
|
227
|
+
const steps = commit.steps.map((step) => Step.fromJSON(schema, step))
|
|
228
|
+
|
|
229
|
+
return new ProseMirrorPlugin({
|
|
230
|
+
key,
|
|
231
|
+
state: {
|
|
232
|
+
init: (_, instance): DecorationSet => {
|
|
233
|
+
return decorateCommit(instance.doc, parent, steps)
|
|
234
|
+
},
|
|
235
|
+
apply: (tr, deco: DecorationSet): DecorationSet => {
|
|
236
|
+
return deco.map(tr.mapping, tr.doc)
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
props: {
|
|
240
|
+
decorations: (state): DecorationSet | undefined => {
|
|
241
|
+
return key.getState(state)
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Define an extension to display the changes from the given commit in the editor.
|
|
250
|
+
*/
|
|
251
|
+
function defineCommitViewer(commit: Commit): PlainExtension {
|
|
252
|
+
return union(
|
|
253
|
+
defineDefaultState({ defaultDoc: commit.doc }),
|
|
254
|
+
defineCommitDecoration(commit),
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
class CommitRecorder {
|
|
259
|
+
private parent: ProseMirrorNode | null = null
|
|
260
|
+
private doc: ProseMirrorNode | null = null
|
|
261
|
+
private steps: Step[] = []
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Return a commit object including all changes since the last commit. `null`
|
|
265
|
+
* will be returned if there is no change.
|
|
266
|
+
*/
|
|
267
|
+
commit(): Commit | null {
|
|
268
|
+
if (
|
|
269
|
+
!this.parent
|
|
270
|
+
|| !this.doc
|
|
271
|
+
|| this.steps.length === 0
|
|
272
|
+
|| this.parent.eq(this.doc)
|
|
273
|
+
) {
|
|
274
|
+
return null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const commit: Commit = {
|
|
278
|
+
doc: jsonFromNode(this.doc),
|
|
279
|
+
parent: jsonFromNode(this.parent),
|
|
280
|
+
steps: this.steps.map((step) => step.toJSON() as StepJSON),
|
|
281
|
+
}
|
|
282
|
+
this.init(this.doc)
|
|
283
|
+
return commit
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
init(doc: ProseMirrorNode): void {
|
|
290
|
+
this.doc = doc
|
|
291
|
+
this.parent = doc
|
|
292
|
+
this.steps = []
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @internal
|
|
297
|
+
*/
|
|
298
|
+
apply(tr: Transaction): void {
|
|
299
|
+
this.steps.push(...tr.steps)
|
|
300
|
+
this.doc = tr.doc
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Define an extension that can record the changes in the editor.
|
|
306
|
+
*/
|
|
307
|
+
function defineCommitRecorder(commitRecorder: CommitRecorder): PlainExtension {
|
|
308
|
+
const key = new PluginKey<DecorationSet>('prosekit-commit-recorder')
|
|
309
|
+
|
|
310
|
+
return definePlugin(
|
|
311
|
+
new ProseMirrorPlugin({
|
|
312
|
+
key,
|
|
313
|
+
state: {
|
|
314
|
+
init: (_, state): void => {
|
|
315
|
+
commitRecorder.init(state.doc)
|
|
316
|
+
},
|
|
317
|
+
apply: (tr): void => {
|
|
318
|
+
commitRecorder.apply(tr)
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export {
|
|
326
|
+
CommitRecorder,
|
|
327
|
+
defineCommitRecorder,
|
|
328
|
+
defineCommitViewer,
|
|
329
|
+
type Commit,
|
|
330
|
+
}
|
package/src/doc/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNodeSpec,
|
|
3
|
+
type Extension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
import type { Attrs } from '@prosekit/pm/model'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type DocExtension = Extension<{ Nodes: { doc: Attrs } }>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export function defineDoc(): DocExtension {
|
|
16
|
+
return defineNodeSpec({
|
|
17
|
+
name: 'doc',
|
|
18
|
+
content: 'block+',
|
|
19
|
+
topNode: true,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definePlugin,
|
|
3
|
+
type PlainExtension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
import { dropCursor } from 'prosemirror-dropcursor'
|
|
6
|
+
|
|
7
|
+
export interface DropCursorOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The color of the cursor. Use `false` to apply no color and rely only on class.
|
|
10
|
+
*
|
|
11
|
+
* @default 'black'
|
|
12
|
+
*/
|
|
13
|
+
color?: string | false
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The precise width of the cursor in pixels.
|
|
17
|
+
*
|
|
18
|
+
* @default 1
|
|
19
|
+
*/
|
|
20
|
+
width?: number
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A CSS class name to add to the cursor element.
|
|
24
|
+
*/
|
|
25
|
+
class?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export type DropCursorExtension = PlainExtension
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Show up a decoration at the drop position when something is dragged over the editor.
|
|
35
|
+
*
|
|
36
|
+
* See [prosemirror-dropcursor](https://github.com/ProseMirror/prosemirror-dropcursor) for more information.
|
|
37
|
+
*
|
|
38
|
+
* You probably want to use `<DropIndicator />` component instead of this extension.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export function defineDropCursor(
|
|
43
|
+
options?: DropCursorOptions,
|
|
44
|
+
): DropCursorExtension {
|
|
45
|
+
return definePlugin(() => dropCursor(options))
|
|
46
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineFacet,
|
|
3
|
+
defineFacetPayload,
|
|
4
|
+
pluginFacet,
|
|
5
|
+
type PlainExtension,
|
|
6
|
+
type PluginPayload,
|
|
7
|
+
} from '@prosekit/core'
|
|
8
|
+
|
|
9
|
+
import { createDropIndicatorPlugin } from './drop-indicator-plugin'
|
|
10
|
+
import type {
|
|
11
|
+
DragEventHandler,
|
|
12
|
+
ShowHandler,
|
|
13
|
+
} from './types'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function defineDropIndicatorPayload(
|
|
19
|
+
payload: DropIndicatorPayload,
|
|
20
|
+
): PlainExtension {
|
|
21
|
+
return defineFacetPayload(dropIndicatorFacet, [payload]) as PlainExtension
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface DropIndicatorPayload {
|
|
28
|
+
/**
|
|
29
|
+
* A callback that is called when the drop indicator should be shown.
|
|
30
|
+
*/
|
|
31
|
+
onShow?: ShowHandler
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A callback that is called when the drop indicator should be hidden.
|
|
35
|
+
*/
|
|
36
|
+
onHide?: VoidFunction
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A callback that is called when the `dragover` event is fired. You can
|
|
40
|
+
* return `false` to disable the current drop point and thus hide the drop
|
|
41
|
+
* indicator.
|
|
42
|
+
*/
|
|
43
|
+
onDrag?: DragEventHandler
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const dropIndicatorFacet = defineFacet<DropIndicatorPayload, PluginPayload>({
|
|
47
|
+
parent: pluginFacet,
|
|
48
|
+
singleton: true,
|
|
49
|
+
reducer: (payloads: DropIndicatorPayload[]): PluginPayload => {
|
|
50
|
+
let showHandlers = payloads.map(p => p.onShow).filter(x => !!x)
|
|
51
|
+
let hideHandlers = payloads.map(p => p.onHide).filter(x => !!x)
|
|
52
|
+
let dragHandlers = payloads.map(p => p.onDrag).filter(x => !!x)
|
|
53
|
+
|
|
54
|
+
let showHandler: ShowHandler = (options) => {
|
|
55
|
+
for (let fn of showHandlers) {
|
|
56
|
+
fn(options)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let hideHandler: VoidFunction = () => {
|
|
61
|
+
for (let fn of hideHandlers) {
|
|
62
|
+
fn()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let dragHandler: DragEventHandler = (options): boolean => {
|
|
67
|
+
for (let fn of dragHandlers) {
|
|
68
|
+
if (fn(options) === false) return false
|
|
69
|
+
}
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (showHandlers.length === 0) {
|
|
74
|
+
// No `onShow` event handler, so we don't need to create a plugin.
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return createDropIndicatorPlugin({
|
|
79
|
+
onDrag: dragHandler,
|
|
80
|
+
onShow: showHandler,
|
|
81
|
+
onHide: hideHandler,
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
})
|