@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,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineFacet,
|
|
3
|
+
defineFacetPayload,
|
|
4
|
+
editorEventFacet,
|
|
5
|
+
type DropHandler,
|
|
6
|
+
type EditorEventPayload,
|
|
7
|
+
type PlainExtension,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
10
|
+
|
|
11
|
+
import { handleEvent } from './helpers'
|
|
12
|
+
|
|
13
|
+
export interface FileDropHandlerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The editor view.
|
|
16
|
+
*/
|
|
17
|
+
view: EditorView
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The event that triggered the drop.
|
|
21
|
+
*/
|
|
22
|
+
event: DragEvent
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The file that was dropped.
|
|
26
|
+
*/
|
|
27
|
+
file: File
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The position of the document where the file was dropped.
|
|
31
|
+
*/
|
|
32
|
+
pos: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A function that handles one of the files in a drop event.
|
|
37
|
+
*
|
|
38
|
+
* Returns `true` if the file was handled and thus should not be handled by
|
|
39
|
+
* other handlers.
|
|
40
|
+
*/
|
|
41
|
+
export type FileDropHandler = (
|
|
42
|
+
options: FileDropHandlerOptions,
|
|
43
|
+
) => boolean | void
|
|
44
|
+
|
|
45
|
+
export function defineFileDropHandler(
|
|
46
|
+
handler: FileDropHandler,
|
|
47
|
+
): PlainExtension {
|
|
48
|
+
return defineFacetPayload(facet, [handler]) as PlainExtension
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getFiles(event: DragEvent) {
|
|
52
|
+
return Array.from(event.dataTransfer?.files ?? [])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const facet = defineFacet<FileDropHandler, EditorEventPayload>({
|
|
56
|
+
parent: editorEventFacet,
|
|
57
|
+
singleton: true,
|
|
58
|
+
reducer: (handlers: FileDropHandler[]): EditorEventPayload => {
|
|
59
|
+
const dropHandler: DropHandler = (view, event): boolean => {
|
|
60
|
+
const position = view.posAtCoords({ left: event.x, top: event.y })
|
|
61
|
+
if (!position) {
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
const pos = position.inside > 0 ? position.inside : position.pos
|
|
65
|
+
|
|
66
|
+
return handleEvent<DragEvent>(
|
|
67
|
+
view,
|
|
68
|
+
event,
|
|
69
|
+
handlers.map((handler) => (options) => handler({ ...options, pos })),
|
|
70
|
+
getFiles,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
return ['drop', dropHandler]
|
|
74
|
+
},
|
|
75
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Priority,
|
|
3
|
+
union,
|
|
4
|
+
withPriority,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import {
|
|
7
|
+
beforeEach,
|
|
8
|
+
describe,
|
|
9
|
+
expect,
|
|
10
|
+
it,
|
|
11
|
+
vi,
|
|
12
|
+
} from 'vitest'
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
defineTestExtension,
|
|
16
|
+
setupTestFromExtension,
|
|
17
|
+
} from '../testing'
|
|
18
|
+
import { pasteFiles } from '../testing/clipboard'
|
|
19
|
+
|
|
20
|
+
import { defineFilePasteHandler } from './file-paste-handler'
|
|
21
|
+
|
|
22
|
+
function definePngPasteHandler(handler: VoidFunction) {
|
|
23
|
+
const extension = defineFilePasteHandler((options) => {
|
|
24
|
+
if (options.file.type === 'image/png') {
|
|
25
|
+
handler()
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
return withPriority(extension, Priority.high)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function defineImagePasteHandler(handler: VoidFunction) {
|
|
33
|
+
const extension = defineFilePasteHandler((options) => {
|
|
34
|
+
if (options.file.type.startsWith('image/')) {
|
|
35
|
+
handler()
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
return withPriority(extension, Priority.default)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function defineFallbackPasteHandler(handler: VoidFunction) {
|
|
43
|
+
const extension = defineFilePasteHandler(() => {
|
|
44
|
+
handler()
|
|
45
|
+
return true
|
|
46
|
+
})
|
|
47
|
+
return withPriority(extension, Priority.low)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('file paste handler', () => {
|
|
51
|
+
const pngHandler = vi.fn()
|
|
52
|
+
const imageHandler = vi.fn()
|
|
53
|
+
const fallbackHandler = vi.fn()
|
|
54
|
+
|
|
55
|
+
const extension = union(
|
|
56
|
+
defineTestExtension(),
|
|
57
|
+
defineImagePasteHandler(imageHandler),
|
|
58
|
+
definePngPasteHandler(pngHandler),
|
|
59
|
+
defineFallbackPasteHandler(fallbackHandler),
|
|
60
|
+
)
|
|
61
|
+
const { editor } = setupTestFromExtension(extension)
|
|
62
|
+
const paste = (files: File[]) => {
|
|
63
|
+
pasteFiles(editor.view, files)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
pngHandler.mockClear()
|
|
68
|
+
imageHandler.mockClear()
|
|
69
|
+
fallbackHandler.mockClear()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should handle file pasting', () => {
|
|
73
|
+
paste([new File([''], 'test.png', { type: 'image/png' })])
|
|
74
|
+
expect(pngHandler).toHaveBeenCalled()
|
|
75
|
+
expect(imageHandler).not.toHaveBeenCalled()
|
|
76
|
+
expect(fallbackHandler).not.toHaveBeenCalled()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should handle priority', () => {
|
|
80
|
+
paste([new File([''], 'test.jpg', { type: 'image/jpg' })])
|
|
81
|
+
expect(pngHandler).not.toHaveBeenCalled()
|
|
82
|
+
expect(imageHandler).toHaveBeenCalled()
|
|
83
|
+
expect(fallbackHandler).not.toHaveBeenCalled()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('should handle multiple files', () => {
|
|
87
|
+
paste([
|
|
88
|
+
new File([''], 'test.png', { type: 'image/png' }),
|
|
89
|
+
new File([''], 'test.pdf', { type: 'application/pdf' }),
|
|
90
|
+
])
|
|
91
|
+
expect(pngHandler).toHaveBeenCalled()
|
|
92
|
+
expect(imageHandler).not.toHaveBeenCalled()
|
|
93
|
+
expect(fallbackHandler).toHaveBeenCalled()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineFacet,
|
|
3
|
+
defineFacetPayload,
|
|
4
|
+
editorEventFacet,
|
|
5
|
+
type EditorEventPayload,
|
|
6
|
+
type PasteHandler,
|
|
7
|
+
type PlainExtension,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
10
|
+
|
|
11
|
+
import { handleEvent } from './helpers'
|
|
12
|
+
|
|
13
|
+
export interface FilePasteHandlerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The editor view.
|
|
16
|
+
*/
|
|
17
|
+
view: EditorView
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The event that triggered the paste.
|
|
21
|
+
*/
|
|
22
|
+
event: ClipboardEvent
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The file that was pasted.
|
|
26
|
+
*/
|
|
27
|
+
file: File
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A function that handles one of the files in a paste event.
|
|
32
|
+
*
|
|
33
|
+
* Returns `true` if the file was handled and thus should not be handled by
|
|
34
|
+
* other handlers.
|
|
35
|
+
*/
|
|
36
|
+
export type FilePasteHandler = (
|
|
37
|
+
options: FilePasteHandlerOptions,
|
|
38
|
+
) => boolean | void
|
|
39
|
+
|
|
40
|
+
export function defineFilePasteHandler(
|
|
41
|
+
handler: FilePasteHandler,
|
|
42
|
+
): PlainExtension {
|
|
43
|
+
return defineFacetPayload(facet, [handler]) as PlainExtension
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getFiles(event: ClipboardEvent) {
|
|
47
|
+
return Array.from(event.clipboardData?.files ?? [])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const facet = defineFacet<FilePasteHandler, EditorEventPayload>({
|
|
51
|
+
parent: editorEventFacet,
|
|
52
|
+
singleton: true,
|
|
53
|
+
reducer: (handlers: FilePasteHandler[]): EditorEventPayload => {
|
|
54
|
+
const pasteHandler: PasteHandler = (view, event): boolean => {
|
|
55
|
+
return handleEvent<ClipboardEvent>(view, event, handlers, getFiles)
|
|
56
|
+
}
|
|
57
|
+
return ['paste', pasteHandler]
|
|
58
|
+
},
|
|
59
|
+
})
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An interface representing the upload progress.
|
|
3
|
+
*/
|
|
4
|
+
export interface UploadProgress {
|
|
5
|
+
// A number representing the amount of work already performed by the
|
|
6
|
+
// underlying process.
|
|
7
|
+
loaded: number
|
|
8
|
+
// A number representing the total amount of work that the underlying
|
|
9
|
+
// process is in the progress of performing.
|
|
10
|
+
total: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UploaderOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The file to be uploaded.
|
|
16
|
+
*/
|
|
17
|
+
file: File
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A callback function that should be called with the upload progress updates.
|
|
21
|
+
*/
|
|
22
|
+
onProgress: (progress: UploadProgress) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The implementation of the actual upload function. You need to implement this
|
|
27
|
+
* function to upload files to your desired destination.
|
|
28
|
+
*/
|
|
29
|
+
export type Uploader<Result> = (options: UploaderOptions) => Promise<Result>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A class that represents a upload task.
|
|
33
|
+
*/
|
|
34
|
+
export class UploadTask<Result> {
|
|
35
|
+
/**
|
|
36
|
+
* An [object URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL)
|
|
37
|
+
* representing the file to be uploaded. This URL will be revoked once the
|
|
38
|
+
* upload is complete successfully.
|
|
39
|
+
*/
|
|
40
|
+
readonly objectURL: string
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A boolean indicating whether the upload is complete (either successfully or with an error).
|
|
44
|
+
*/
|
|
45
|
+
protected done = false
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A promise that fulfills once the upload is complete, or rejects if an error occurs.
|
|
49
|
+
*/
|
|
50
|
+
readonly finished: Promise<Result>
|
|
51
|
+
|
|
52
|
+
private subscribers: ((progress: UploadProgress) => void)[] = []
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new upload task. You can find the upload task by its object URL
|
|
56
|
+
* later using `UploadTask.get()`.
|
|
57
|
+
*
|
|
58
|
+
* @param options - The options for the upload task.
|
|
59
|
+
*/
|
|
60
|
+
constructor({ file, uploader }: { file: File; uploader: Uploader<Result> }) {
|
|
61
|
+
this.objectURL = URL.createObjectURL(file)
|
|
62
|
+
this.finished = new Promise((resolve, reject) => {
|
|
63
|
+
const maybePromise = uploader({
|
|
64
|
+
file,
|
|
65
|
+
onProgress: (progress) => {
|
|
66
|
+
for (const subscriber of this.subscribers) {
|
|
67
|
+
subscriber(progress)
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
Promise.resolve(maybePromise).then(
|
|
72
|
+
(result) => {
|
|
73
|
+
this.done = true
|
|
74
|
+
URL.revokeObjectURL(this.objectURL)
|
|
75
|
+
resolve(result)
|
|
76
|
+
},
|
|
77
|
+
(error) => {
|
|
78
|
+
this.done = true
|
|
79
|
+
reject(
|
|
80
|
+
new Error('[prosekit] Failed to upload file', { cause: error }),
|
|
81
|
+
)
|
|
82
|
+
},
|
|
83
|
+
)
|
|
84
|
+
})
|
|
85
|
+
store.set(this.objectURL, this)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Subscribes to progress updates. Returns a function to unsubscribe.
|
|
90
|
+
*/
|
|
91
|
+
public subscribeProgress(
|
|
92
|
+
callback: (progress: UploadProgress) => void,
|
|
93
|
+
): VoidFunction {
|
|
94
|
+
this.subscribers.push(callback)
|
|
95
|
+
return () => {
|
|
96
|
+
this.subscribers = this.subscribers.filter(
|
|
97
|
+
(subscriber) => subscriber !== callback,
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Finds an upload task by its object URL.
|
|
104
|
+
*/
|
|
105
|
+
static get<Result = unknown>(
|
|
106
|
+
objectURL: string,
|
|
107
|
+
): UploadTask<Result> | undefined {
|
|
108
|
+
return store.get(objectURL) as UploadTask<Result> | undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Deletes an upload task by its object URL.
|
|
113
|
+
*/
|
|
114
|
+
static delete(objectURL: string): void {
|
|
115
|
+
store.delete(objectURL)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const store = new Map<string, UploadTask<unknown>>()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
2
|
+
|
|
3
|
+
type FileHandler<E extends Event> = (options: {
|
|
4
|
+
view: EditorView
|
|
5
|
+
event: E
|
|
6
|
+
file: File
|
|
7
|
+
}) => boolean | void
|
|
8
|
+
|
|
9
|
+
function handleFile<E extends Event>(
|
|
10
|
+
view: EditorView,
|
|
11
|
+
event: E,
|
|
12
|
+
file: File,
|
|
13
|
+
handlers: FileHandler<E>[],
|
|
14
|
+
) {
|
|
15
|
+
// The last item in `handlers` should has the highest priority.
|
|
16
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
17
|
+
const handler = handlers[i]
|
|
18
|
+
if (handler({ view, event, file })) {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function handleEvent<E extends Event>(
|
|
26
|
+
view: EditorView,
|
|
27
|
+
event: E,
|
|
28
|
+
handlers: FileHandler<E>[],
|
|
29
|
+
getFiles: (event: E) => File[],
|
|
30
|
+
): boolean {
|
|
31
|
+
const files = getFiles(event)
|
|
32
|
+
let handled = false
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
if (handleFile(view, event, file, handlers)) {
|
|
35
|
+
handled = true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return handled
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineFileDropHandler,
|
|
3
|
+
type FileDropHandler,
|
|
4
|
+
type FileDropHandlerOptions,
|
|
5
|
+
} from './file-drop-handler'
|
|
6
|
+
export {
|
|
7
|
+
defineFilePasteHandler,
|
|
8
|
+
type FilePasteHandler,
|
|
9
|
+
type FilePasteHandlerOptions,
|
|
10
|
+
} from './file-paste-handler'
|
|
11
|
+
export {
|
|
12
|
+
UploadTask,
|
|
13
|
+
type Uploader,
|
|
14
|
+
type UploaderOptions,
|
|
15
|
+
type UploadProgress,
|
|
16
|
+
} from './file-upload'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definePlugin,
|
|
3
|
+
type PlainExtension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
import { gapCursor } from 'prosemirror-gapcursor'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type GapCursorExtension = PlainExtension
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Capture clicks near and arrow-key-motion past places that don't have a
|
|
14
|
+
* normally selectable position nearby, and create a gap cursor selection for
|
|
15
|
+
* them. The cursor is drawn as an element with class `ProseMirror-gapcursor`.
|
|
16
|
+
*
|
|
17
|
+
* You can either include `prosekit/extensions/gap-cursor.css` or add your own
|
|
18
|
+
* styles to make it visible.
|
|
19
|
+
*
|
|
20
|
+
* See
|
|
21
|
+
* [prosemirror-gapcursor](https://github.com/ProseMirror/prosemirror-gapcursor)
|
|
22
|
+
* for more information.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export function defineGapCursor(): GapCursorExtension {
|
|
27
|
+
return definePlugin(() => gapCursor())
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.ProseMirror-gapcursor {
|
|
2
|
+
display: none;
|
|
3
|
+
position: relative;
|
|
4
|
+
pointer-events: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.ProseMirror-gapcursor:after {
|
|
8
|
+
display: block;
|
|
9
|
+
position: absolute;
|
|
10
|
+
top: -2px;
|
|
11
|
+
width: 20px;
|
|
12
|
+
border-top: 1px solid currentColor;
|
|
13
|
+
content: "";
|
|
14
|
+
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@keyframes ProseMirror-cursor-blink {
|
|
18
|
+
to {
|
|
19
|
+
visibility: hidden;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
24
|
+
display: block;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCommands,
|
|
3
|
+
insertNode,
|
|
4
|
+
type Extension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import type { Command } from '@prosekit/pm/state'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type HardBreakCommandsExtension = Extension<{
|
|
12
|
+
Commands: {
|
|
13
|
+
insertHardBreak: []
|
|
14
|
+
}
|
|
15
|
+
}>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export function insertHardBreak(): Command {
|
|
21
|
+
return insertNode({ type: 'hardBreak' })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function defineHardBreakCommands(): HardBreakCommandsExtension {
|
|
28
|
+
return defineCommands({
|
|
29
|
+
insertHardBreak: insertHardBreak,
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { setupTest } from '../testing'
|
|
8
|
+
import {
|
|
9
|
+
inputText,
|
|
10
|
+
pressKey,
|
|
11
|
+
} from '../testing/keyboard'
|
|
12
|
+
|
|
13
|
+
describe('defineHardBreakKeymap', () => {
|
|
14
|
+
it('should insert hard break', async () => {
|
|
15
|
+
const { editor, n } = setupTest()
|
|
16
|
+
|
|
17
|
+
const doc1 = n.doc(n.p('foo<a>bar'))
|
|
18
|
+
const doc2 = n.doc(n.p('foo', n.hardBreak(), 'bar'))
|
|
19
|
+
|
|
20
|
+
editor.set(doc1)
|
|
21
|
+
expect(editor.state.doc.toJSON()).toEqual(doc1.toJSON())
|
|
22
|
+
await pressKey('Shift-Enter')
|
|
23
|
+
expect(editor.state.doc.toJSON()).toEqual(doc2.toJSON())
|
|
24
|
+
|
|
25
|
+
editor.set(doc1)
|
|
26
|
+
expect(editor.state.doc.toJSON()).toEqual(doc1.toJSON())
|
|
27
|
+
await pressKey('Mod-Enter')
|
|
28
|
+
expect(editor.state.doc.toJSON()).toEqual(doc2.toJSON())
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('can continue to type after a hard break', async () => {
|
|
32
|
+
const { editor, n } = setupTest()
|
|
33
|
+
|
|
34
|
+
const doc1 = n.doc(n.p('foo<a>bar'))
|
|
35
|
+
const doc2 = n.doc(n.p('foo', n.hardBreak(), 'bar'))
|
|
36
|
+
const doc3 = n.doc(n.p('foo', n.hardBreak(), 'bazbar'))
|
|
37
|
+
|
|
38
|
+
editor.set(doc1)
|
|
39
|
+
expect(editor.state.doc.toJSON()).toEqual(doc1.toJSON())
|
|
40
|
+
await pressKey('Shift-Enter')
|
|
41
|
+
expect(editor.state.doc.toJSON()).toEqual(doc2.toJSON())
|
|
42
|
+
await inputText('baz')
|
|
43
|
+
expect(editor.state.doc.toJSON()).toEqual(doc3.toJSON())
|
|
44
|
+
})
|
|
45
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineKeymap,
|
|
3
|
+
type PlainExtension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import { insertHardBreak } from './hard-break-commands'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export function defineHardBreakKeymap(): PlainExtension {
|
|
12
|
+
return defineKeymap({
|
|
13
|
+
'Mod-Enter': insertHardBreak(),
|
|
14
|
+
'Shift-Enter': insertHardBreak(),
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 HardBreakSpecExtension = Extension<{
|
|
11
|
+
Nodes: {
|
|
12
|
+
hardBreak: Attrs
|
|
13
|
+
}
|
|
14
|
+
}>
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function defineHardBreakSpec(): HardBreakSpecExtension {
|
|
20
|
+
return defineNodeSpec({
|
|
21
|
+
name: 'hardBreak',
|
|
22
|
+
inline: true,
|
|
23
|
+
selectable: false,
|
|
24
|
+
leafText: () => '\n',
|
|
25
|
+
group: 'inline',
|
|
26
|
+
parseDOM: [{ tag: 'br' }],
|
|
27
|
+
toDOM() {
|
|
28
|
+
return ['br']
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
union,
|
|
3
|
+
type Union,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defineHardBreakCommands,
|
|
8
|
+
type HardBreakCommandsExtension,
|
|
9
|
+
} from './hard-break-commands'
|
|
10
|
+
import { defineHardBreakKeymap } from './hard-break-keymap'
|
|
11
|
+
import {
|
|
12
|
+
defineHardBreakSpec,
|
|
13
|
+
type HardBreakSpecExtension,
|
|
14
|
+
} from './hard-break-spec'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type HardBreakExtension = Union<
|
|
20
|
+
[HardBreakSpecExtension, HardBreakCommandsExtension]
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export function defineHardBreak(): HardBreakExtension {
|
|
27
|
+
return union(
|
|
28
|
+
defineHardBreakSpec(),
|
|
29
|
+
defineHardBreakKeymap(),
|
|
30
|
+
defineHardBreakCommands(),
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineHardBreak,
|
|
3
|
+
type HardBreakExtension,
|
|
4
|
+
} from './hard-break'
|
|
5
|
+
export {
|
|
6
|
+
defineHardBreakCommands,
|
|
7
|
+
type HardBreakCommandsExtension,
|
|
8
|
+
} from './hard-break-commands'
|
|
9
|
+
export { defineHardBreakKeymap } from './hard-break-keymap'
|
|
10
|
+
export {
|
|
11
|
+
defineHardBreakSpec,
|
|
12
|
+
type HardBreakSpecExtension,
|
|
13
|
+
} from './hard-break-spec'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCommands,
|
|
3
|
+
insertNode,
|
|
4
|
+
setBlockType,
|
|
5
|
+
toggleNode,
|
|
6
|
+
type Extension,
|
|
7
|
+
} from '@prosekit/core'
|
|
8
|
+
|
|
9
|
+
import type { HeadingAttrs } from './heading-types'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export type HeadingCommandsExtension = Extension<{
|
|
15
|
+
Commands: {
|
|
16
|
+
setHeading: [attrs?: HeadingAttrs | undefined]
|
|
17
|
+
insertHeading: [attrs?: HeadingAttrs | undefined]
|
|
18
|
+
toggleHeading: [attrs?: HeadingAttrs | undefined]
|
|
19
|
+
}
|
|
20
|
+
}>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function defineHeadingCommands(): HeadingCommandsExtension {
|
|
26
|
+
return defineCommands({
|
|
27
|
+
setHeading: (attrs?: HeadingAttrs) => {
|
|
28
|
+
return setBlockType({ type: 'heading', attrs })
|
|
29
|
+
},
|
|
30
|
+
insertHeading: (attrs?: HeadingAttrs) => {
|
|
31
|
+
return insertNode({ type: 'heading', attrs })
|
|
32
|
+
},
|
|
33
|
+
toggleHeading: (attrs?: HeadingAttrs) => {
|
|
34
|
+
return toggleNode({ type: 'heading', attrs })
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PlainExtension } from '@prosekit/core'
|
|
2
|
+
|
|
3
|
+
import { defineTextBlockInputRule } from '../input-rule'
|
|
4
|
+
|
|
5
|
+
import type { HeadingAttrs } from './heading-types'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts the text block to a heading when `#` is typed at the start of a new
|
|
9
|
+
* line followed by a space.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function defineHeadingInputRule(): PlainExtension {
|
|
14
|
+
return defineTextBlockInputRule({
|
|
15
|
+
regex: /^(#{1,6})\s$/,
|
|
16
|
+
type: 'heading',
|
|
17
|
+
attrs: (match) => {
|
|
18
|
+
const level: number = match[1]?.length ?? 1
|
|
19
|
+
return { level } satisfies HeadingAttrs
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
}
|