@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,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { setupTest } from '../testing'
|
|
8
|
+
import { pressKey } from '../testing/keyboard'
|
|
9
|
+
|
|
10
|
+
describe('defineHeadingKeymap', () => {
|
|
11
|
+
it('should toggle heading', async () => {
|
|
12
|
+
const { editor, n } = setupTest()
|
|
13
|
+
|
|
14
|
+
const doc = n.doc(n.p('<a>Foo'), n.p('Bar'))
|
|
15
|
+
const docH1 = n.doc(n.h1('Foo'), n.p('Bar'))
|
|
16
|
+
const docH3 = n.doc(n.h3('Foo'), n.p('Bar'))
|
|
17
|
+
|
|
18
|
+
editor.set(doc)
|
|
19
|
+
expect(editor.state.doc.toJSON()).toEqual(doc.toJSON())
|
|
20
|
+
await pressKey('mod-alt-1')
|
|
21
|
+
expect(editor.state.doc.toJSON()).toEqual(docH1.toJSON())
|
|
22
|
+
await pressKey('mod-alt-1')
|
|
23
|
+
expect(editor.state.doc.toJSON()).toEqual(doc.toJSON())
|
|
24
|
+
await pressKey('mod-alt-3')
|
|
25
|
+
expect(editor.state.doc.toJSON()).toEqual(docH3.toJSON())
|
|
26
|
+
await pressKey('mod-alt-1')
|
|
27
|
+
expect(editor.state.doc.toJSON()).toEqual(docH1.toJSON())
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should unset heading by pressing Backspace', async () => {
|
|
31
|
+
const { editor, n } = setupTest()
|
|
32
|
+
|
|
33
|
+
const doc1 = n.doc(n.h1('<a>'))
|
|
34
|
+
const doc2 = n.doc(n.p('<a>'))
|
|
35
|
+
|
|
36
|
+
editor.set(doc1)
|
|
37
|
+
expect(editor.state.doc.toJSON()).toEqual(doc1.toJSON())
|
|
38
|
+
await pressKey('Backspace')
|
|
39
|
+
expect(editor.state.doc.toJSON()).toEqual(doc2.toJSON())
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should unset heading by pressing Backspace around text', async () => {
|
|
43
|
+
const { editor, n } = setupTest()
|
|
44
|
+
|
|
45
|
+
const doc1 = n.doc(n.h1('Foo'), n.h1('<a>Bar'))
|
|
46
|
+
const doc2 = n.doc(n.h1('Foo'), n.p('<a>Bar'))
|
|
47
|
+
|
|
48
|
+
editor.set(doc1)
|
|
49
|
+
expect(editor.state.doc.toJSON()).toEqual(doc1.toJSON())
|
|
50
|
+
await pressKey('Backspace')
|
|
51
|
+
expect(editor.state.doc.toJSON()).toEqual(doc2.toJSON())
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineKeymap,
|
|
3
|
+
isAtBlockStart,
|
|
4
|
+
toggleNode,
|
|
5
|
+
unsetBlockType,
|
|
6
|
+
withSkipCodeBlock,
|
|
7
|
+
type PlainExtension,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
import type { Command } from '@prosekit/pm/state'
|
|
10
|
+
|
|
11
|
+
function toggleHeadingKeybinding(level: number): Command {
|
|
12
|
+
return withSkipCodeBlock(toggleNode({ type: 'heading', attrs: { level } }))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Set the block type to default (usually `paragraph`) when pressing Backspace at
|
|
17
|
+
* the start of a heading block.
|
|
18
|
+
*/
|
|
19
|
+
const backspaceUnsetHeading: Command = (state, dispatch, view) => {
|
|
20
|
+
const $pos = isAtBlockStart(state, view)
|
|
21
|
+
if ($pos?.parent.type.name === 'heading') {
|
|
22
|
+
return unsetBlockType()(state, dispatch, view)
|
|
23
|
+
}
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function defineHeadingKeymap(): PlainExtension {
|
|
31
|
+
return defineKeymap({
|
|
32
|
+
'mod-alt-1': toggleHeadingKeybinding(1),
|
|
33
|
+
'mod-alt-2': toggleHeadingKeybinding(2),
|
|
34
|
+
'mod-alt-3': toggleHeadingKeybinding(3),
|
|
35
|
+
'mod-alt-4': toggleHeadingKeybinding(4),
|
|
36
|
+
'mod-alt-5': toggleHeadingKeybinding(5),
|
|
37
|
+
'mod-alt-6': toggleHeadingKeybinding(6),
|
|
38
|
+
'Backspace': backspaceUnsetHeading,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNodeSpec,
|
|
3
|
+
type Extension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import type { HeadingAttrs } from './heading-types'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type HeadingSpecExtension = Extension<{
|
|
12
|
+
Nodes: {
|
|
13
|
+
heading: HeadingAttrs
|
|
14
|
+
}
|
|
15
|
+
}>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export function defineHeadingSpec(): HeadingSpecExtension {
|
|
21
|
+
return defineNodeSpec({
|
|
22
|
+
name: 'heading',
|
|
23
|
+
attrs: { level: { default: 1, validate: 'number' } },
|
|
24
|
+
content: 'inline*',
|
|
25
|
+
group: 'block',
|
|
26
|
+
defining: true,
|
|
27
|
+
parseDOM: [
|
|
28
|
+
{ tag: 'h1', attrs: { level: 1 } },
|
|
29
|
+
{ tag: 'h2', attrs: { level: 2 } },
|
|
30
|
+
{ tag: 'h3', attrs: { level: 3 } },
|
|
31
|
+
{ tag: 'h4', attrs: { level: 4 } },
|
|
32
|
+
{ tag: 'h5', attrs: { level: 5 } },
|
|
33
|
+
{ tag: 'h6', attrs: { level: 6 } },
|
|
34
|
+
],
|
|
35
|
+
toDOM(node) {
|
|
36
|
+
return [`h${node.attrs.level}`, 0]
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
union,
|
|
3
|
+
type Union,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defineHeadingCommands,
|
|
8
|
+
type HeadingCommandsExtension,
|
|
9
|
+
} from './heading-commands'
|
|
10
|
+
import { defineHeadingInputRule } from './heading-input-rule'
|
|
11
|
+
import { defineHeadingKeymap } from './heading-keymap'
|
|
12
|
+
import {
|
|
13
|
+
defineHeadingSpec,
|
|
14
|
+
type HeadingSpecExtension,
|
|
15
|
+
} from './heading-spec'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type HeadingExtension = Union<
|
|
21
|
+
[HeadingSpecExtension, HeadingCommandsExtension]
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export function defineHeading(): HeadingExtension {
|
|
28
|
+
return union(
|
|
29
|
+
defineHeadingSpec(),
|
|
30
|
+
defineHeadingInputRule(),
|
|
31
|
+
defineHeadingKeymap(),
|
|
32
|
+
defineHeadingCommands(),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineHeading,
|
|
3
|
+
type HeadingExtension,
|
|
4
|
+
} from './heading'
|
|
5
|
+
export {
|
|
6
|
+
defineHeadingCommands,
|
|
7
|
+
type HeadingCommandsExtension,
|
|
8
|
+
} from './heading-commands'
|
|
9
|
+
export { defineHeadingInputRule } from './heading-input-rule'
|
|
10
|
+
export { defineHeadingKeymap } from './heading-keymap'
|
|
11
|
+
export {
|
|
12
|
+
defineHeadingSpec,
|
|
13
|
+
type HeadingSpecExtension,
|
|
14
|
+
} from './heading-spec'
|
|
15
|
+
export type { HeadingAttrs } from './heading-types'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { setupTest } from '../testing'
|
|
8
|
+
|
|
9
|
+
describe('insertHorizontalRule', () => {
|
|
10
|
+
const { editor, n } = setupTest()
|
|
11
|
+
|
|
12
|
+
it('should insert a horizontal rule in an empty paragraph', () => {
|
|
13
|
+
const doc = n.doc(n.p('<a>'))
|
|
14
|
+
editor.set(doc)
|
|
15
|
+
|
|
16
|
+
editor.commands.insertHorizontalRule()
|
|
17
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
18
|
+
n.doc(n.horizontalRule()).toJSON(),
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should insert a horizontal rule after some text', () => {
|
|
23
|
+
const doc = n.doc(n.p('123<a>'))
|
|
24
|
+
editor.set(doc)
|
|
25
|
+
|
|
26
|
+
editor.commands.insertHorizontalRule()
|
|
27
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
28
|
+
n.doc(n.p('123'), n.horizontalRule()).toJSON(),
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should insert a horizontal rule before some text', () => {
|
|
33
|
+
const doc = n.doc(n.p('<a>123'))
|
|
34
|
+
editor.set(doc)
|
|
35
|
+
|
|
36
|
+
editor.commands.insertHorizontalRule()
|
|
37
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
38
|
+
n.doc(n.horizontalRule(), n.p('123')).toJSON(),
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should insert a horizontal rule between some text', () => {
|
|
43
|
+
const doc = n.doc(n.p('123<a>456'))
|
|
44
|
+
editor.set(doc)
|
|
45
|
+
|
|
46
|
+
editor.commands.insertHorizontalRule()
|
|
47
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
48
|
+
n.doc(n.p('123'), n.horizontalRule(), n.p('456')).toJSON(),
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should keep the selected text', () => {
|
|
53
|
+
const doc = n.doc(n.p('123<a>4<b>56'))
|
|
54
|
+
editor.set(doc)
|
|
55
|
+
|
|
56
|
+
editor.commands.insertHorizontalRule()
|
|
57
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
58
|
+
n.doc(n.p('123'), n.horizontalRule(), n.p('456')).toJSON(),
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCommands,
|
|
3
|
+
getNodeType,
|
|
4
|
+
type Extension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import {
|
|
7
|
+
Fragment,
|
|
8
|
+
Slice,
|
|
9
|
+
} from '@prosekit/pm/model'
|
|
10
|
+
import type { Command } from '@prosekit/pm/state'
|
|
11
|
+
|
|
12
|
+
export type HorizontalRuleCommandsExtension = Extension<{
|
|
13
|
+
Commands: {
|
|
14
|
+
insertHorizontalRule: []
|
|
15
|
+
}
|
|
16
|
+
}>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a command that inserts a horizontal rule at the current selection.
|
|
20
|
+
*/
|
|
21
|
+
export function insertHorizontalRule(): Command {
|
|
22
|
+
return (state, dispatch) => {
|
|
23
|
+
if (!dispatch) return true
|
|
24
|
+
|
|
25
|
+
const { schema, tr } = state
|
|
26
|
+
const type = getNodeType(schema, 'horizontalRule')
|
|
27
|
+
const node = type.createChecked()
|
|
28
|
+
const pos = tr.selection.anchor
|
|
29
|
+
tr.replaceRange(pos, pos, new Slice(Fragment.from(node), 0, 0))
|
|
30
|
+
dispatch(tr)
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function defineHorizontalRuleCommands(): HorizontalRuleCommandsExtension {
|
|
36
|
+
return defineCommands({ insertHorizontalRule })
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { setupTest } from '../testing'
|
|
8
|
+
import { inputText } from '../testing/keyboard'
|
|
9
|
+
|
|
10
|
+
describe('defineHorizontalRuleInputRule', () => {
|
|
11
|
+
const { editor, n } = setupTest()
|
|
12
|
+
it('should insert a horizontal rule when typing "---" in an empty paragraph', async () => {
|
|
13
|
+
const doc = n.doc(n.p('<a>'))
|
|
14
|
+
editor.set(doc)
|
|
15
|
+
|
|
16
|
+
await inputText('---')
|
|
17
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
18
|
+
n.doc(n.horizontalRule(), n.p()).toJSON(),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
await inputText('x')
|
|
22
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
23
|
+
n.doc(n.horizontalRule(), n.p('x')).toJSON(),
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('should insert a horizontal rule when typing "---" before some text', async () => {
|
|
28
|
+
const doc = n.doc(n.p('<a>123'))
|
|
29
|
+
editor.set(doc)
|
|
30
|
+
|
|
31
|
+
await inputText('---')
|
|
32
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
33
|
+
n.doc(n.horizontalRule(), n.p('123')).toJSON(),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
await inputText('x')
|
|
37
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
38
|
+
n.doc(n.horizontalRule(), n.p('x123')).toJSON(),
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should not insert a horizontal rule when typing "---" after some text', async () => {
|
|
43
|
+
const doc = n.doc(n.p('123<a>'))
|
|
44
|
+
editor.set(doc)
|
|
45
|
+
|
|
46
|
+
await inputText('---')
|
|
47
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
48
|
+
n.doc(n.p('123---')).toJSON(),
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should not insert a horizontal rule inside a code block', async () => {
|
|
53
|
+
const doc = n.doc(n.codeBlock('<a>'))
|
|
54
|
+
editor.set(doc)
|
|
55
|
+
|
|
56
|
+
await inputText('---')
|
|
57
|
+
expect(editor.view.state.doc.toJSON()).toEqual(
|
|
58
|
+
n.doc(n.codeBlock('---')).toJSON(),
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getNodeType,
|
|
3
|
+
union,
|
|
4
|
+
type PlainExtension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import { InputRule } from '@prosekit/pm/inputrules'
|
|
7
|
+
|
|
8
|
+
import { defineInputRule } from '../input-rule'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function defineHorizontalRuleInputRule(): PlainExtension {
|
|
14
|
+
return union(
|
|
15
|
+
defineInputRule(
|
|
16
|
+
new InputRule(/^---$/, (state, match, start, end) => {
|
|
17
|
+
const { schema } = state
|
|
18
|
+
const { tr } = state
|
|
19
|
+
const type = getNodeType(schema, 'horizontalRule')
|
|
20
|
+
const node = type.createChecked()
|
|
21
|
+
tr.delete(start, end).insert(start - 1, node)
|
|
22
|
+
return tr.scrollIntoView()
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -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
|
+
export type HorizontalRuleSpecExtension = Extension<{
|
|
8
|
+
Nodes: {
|
|
9
|
+
horizontalRule: Attrs
|
|
10
|
+
}
|
|
11
|
+
}>
|
|
12
|
+
|
|
13
|
+
export function defineHorizontalRuleSpec(): HorizontalRuleSpecExtension {
|
|
14
|
+
return defineNodeSpec({
|
|
15
|
+
name: 'horizontalRule',
|
|
16
|
+
group: 'block',
|
|
17
|
+
parseDOM: [{ tag: 'hr' }],
|
|
18
|
+
// Wrap the `<hr>` in a `<div>` so that we can make it taller and easier to click.
|
|
19
|
+
toDOM: () => ['div', { class: 'prosekit-horizontal-rule' }, ['hr']],
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
union,
|
|
3
|
+
type Union,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defineHorizontalRuleCommands,
|
|
8
|
+
type HorizontalRuleCommandsExtension,
|
|
9
|
+
} from './horizontal-rule-commands'
|
|
10
|
+
import { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule'
|
|
11
|
+
import {
|
|
12
|
+
defineHorizontalRuleSpec,
|
|
13
|
+
type HorizontalRuleSpecExtension,
|
|
14
|
+
} from './horizontal-rule-spec'
|
|
15
|
+
|
|
16
|
+
export type HorizontalRuleExtension = Union<
|
|
17
|
+
[HorizontalRuleSpecExtension, HorizontalRuleCommandsExtension]
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export function defineHorizontalRule(): HorizontalRuleExtension {
|
|
24
|
+
return union(
|
|
25
|
+
defineHorizontalRuleSpec(),
|
|
26
|
+
defineHorizontalRuleInputRule(),
|
|
27
|
+
defineHorizontalRuleCommands(),
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineHorizontalRule,
|
|
3
|
+
type HorizontalRuleExtension,
|
|
4
|
+
} from './horizontal-rule'
|
|
5
|
+
export {
|
|
6
|
+
defineHorizontalRuleCommands,
|
|
7
|
+
insertHorizontalRule,
|
|
8
|
+
type HorizontalRuleCommandsExtension,
|
|
9
|
+
} from './horizontal-rule-commands'
|
|
10
|
+
export { defineHorizontalRuleInputRule } from './horizontal-rule-input-rule'
|
|
11
|
+
export {
|
|
12
|
+
defineHorizontalRuleSpec,
|
|
13
|
+
type HorizontalRuleSpecExtension,
|
|
14
|
+
} from './horizontal-rule-spec'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineCommands,
|
|
3
|
+
insertNode,
|
|
4
|
+
type Extension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
|
|
7
|
+
import type { ImageAttrs } from './image-spec'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type ImageCommandsExtension = Extension<{
|
|
13
|
+
Commands: {
|
|
14
|
+
insertImage: [attrs?: ImageAttrs]
|
|
15
|
+
}
|
|
16
|
+
}>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function defineImageCommands(): ImageCommandsExtension {
|
|
22
|
+
return defineCommands({
|
|
23
|
+
insertImage: (attrs?: ImageAttrs) => {
|
|
24
|
+
return insertNode({ type: 'image', attrs })
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNodeSpec,
|
|
3
|
+
type Extension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ImageAttrs {
|
|
10
|
+
src?: string | null
|
|
11
|
+
width?: number | null
|
|
12
|
+
height?: number | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type ImageSpecExtension = Extension<{
|
|
19
|
+
Nodes: {
|
|
20
|
+
image: ImageAttrs
|
|
21
|
+
}
|
|
22
|
+
}>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function defineImageSpec(): ImageSpecExtension {
|
|
28
|
+
return defineNodeSpec({
|
|
29
|
+
name: 'image',
|
|
30
|
+
attrs: {
|
|
31
|
+
src: { default: null, validate: 'string|null' },
|
|
32
|
+
width: { default: null, validate: 'number|null' },
|
|
33
|
+
height: { default: null, validate: 'number|null' },
|
|
34
|
+
},
|
|
35
|
+
group: 'block',
|
|
36
|
+
defining: true,
|
|
37
|
+
draggable: true,
|
|
38
|
+
parseDOM: [
|
|
39
|
+
{
|
|
40
|
+
tag: 'img[src]',
|
|
41
|
+
getAttrs: (element): ImageAttrs => {
|
|
42
|
+
if (typeof element === 'string') {
|
|
43
|
+
return { src: null }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const src = element.getAttribute('src') || null
|
|
47
|
+
|
|
48
|
+
let width: number | null = null
|
|
49
|
+
let height: number | null = null
|
|
50
|
+
|
|
51
|
+
const rect = element.getBoundingClientRect()
|
|
52
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
53
|
+
width = rect.width
|
|
54
|
+
height = rect.height
|
|
55
|
+
} else if (
|
|
56
|
+
element instanceof HTMLImageElement
|
|
57
|
+
&& element.naturalWidth > 0
|
|
58
|
+
&& element.naturalHeight > 0
|
|
59
|
+
) {
|
|
60
|
+
width = element.naturalWidth
|
|
61
|
+
height = element.naturalHeight
|
|
62
|
+
}
|
|
63
|
+
return { src, width, height }
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
toDOM(node) {
|
|
68
|
+
const attrs = node.attrs as ImageAttrs
|
|
69
|
+
return ['img', attrs]
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
union,
|
|
3
|
+
type Union,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defineImageCommands,
|
|
8
|
+
type ImageCommandsExtension,
|
|
9
|
+
} from './image-commands'
|
|
10
|
+
import {
|
|
11
|
+
defineImageSpec,
|
|
12
|
+
type ImageSpecExtension,
|
|
13
|
+
} from './image-spec'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type ImageExtension = Union<[ImageSpecExtension, ImageCommandsExtension]>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export function defineImage(): ImageExtension {
|
|
24
|
+
return union(defineImageSpec(), defineImageCommands())
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
defineImage,
|
|
3
|
+
type ImageExtension,
|
|
4
|
+
} from './image'
|
|
5
|
+
export {
|
|
6
|
+
defineImageCommands,
|
|
7
|
+
type ImageCommandsExtension,
|
|
8
|
+
} from './image-commands'
|
|
9
|
+
export {
|
|
10
|
+
defineImageSpec,
|
|
11
|
+
type ImageAttrs,
|
|
12
|
+
type ImageSpecExtension,
|
|
13
|
+
} from './image-spec'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|