@prosekit/extensions 0.12.2 → 0.14.0
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/{drop-indicator-B1QHFb5m.js → drop-indicator-B_oMfeVP.js} +11 -10
- package/dist/drop-indicator-B_oMfeVP.js.map +1 -0
- package/dist/{enter-rule-CzWOZF_Z.js → enter-rule-D-p4ykfv.js} +1 -1
- package/dist/enter-rule-D-p4ykfv.js.map +1 -0
- package/dist/{file-DrfcSid-.js → file-iLVR0eM0.js} +3 -3
- package/dist/file-iLVR0eM0.js.map +1 -0
- package/dist/{index-oIc1a2f2.d.ts → index-cp1u4e0e.d.ts} +1 -1
- package/dist/index-cp1u4e0e.d.ts.map +1 -0
- package/dist/{input-rule-dmsb3j6w.js → input-rule-COGr_GBb.js} +1 -1
- package/dist/input-rule-COGr_GBb.js.map +1 -0
- package/dist/list/style.css +5 -5
- package/dist/list/style.css.map +1 -1
- package/dist/{mark-rule-BcLB4Uv2.js → mark-rule-CYe8zk4q.js} +6 -6
- package/dist/mark-rule-CYe8zk4q.js.map +1 -0
- package/dist/{paste-rule-pVb4sqvJ.js → paste-rule-BaDghcaU.js} +7 -7
- package/dist/paste-rule-BaDghcaU.js.map +1 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +11 -3
- package/dist/prosekit-extensions-autocomplete.d.ts.map +1 -1
- package/dist/prosekit-extensions-autocomplete.js +171 -60
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-background-color.d.ts +62 -0
- package/dist/prosekit-extensions-background-color.d.ts.map +1 -0
- package/dist/prosekit-extensions-background-color.js +76 -0
- package/dist/prosekit-extensions-background-color.js.map +1 -0
- package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +2 -2
- package/dist/prosekit-extensions-blockquote.js.map +1 -1
- package/dist/prosekit-extensions-bold.d.ts.map +1 -1
- package/dist/prosekit-extensions-bold.js +1 -1
- package/dist/prosekit-extensions-bold.js.map +1 -1
- package/dist/prosekit-extensions-code-block.d.ts +1 -1
- package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
- package/dist/prosekit-extensions-code-block.js +4 -4
- package/dist/prosekit-extensions-code-block.js.map +1 -1
- package/dist/prosekit-extensions-code.d.ts.map +1 -1
- package/dist/prosekit-extensions-code.js +1 -1
- package/dist/prosekit-extensions-code.js.map +1 -1
- package/dist/prosekit-extensions-commit.d.ts +0 -1
- package/dist/prosekit-extensions-commit.d.ts.map +1 -1
- package/dist/prosekit-extensions-commit.js +1 -1
- package/dist/prosekit-extensions-commit.js.map +1 -1
- package/dist/prosekit-extensions-doc.d.ts +0 -1
- package/dist/prosekit-extensions-doc.d.ts.map +1 -1
- package/dist/prosekit-extensions-doc.js.map +1 -1
- package/dist/prosekit-extensions-drop-cursor.d.ts.map +1 -1
- package/dist/prosekit-extensions-drop-cursor.js.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts +0 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.js +1 -1
- package/dist/prosekit-extensions-enter-rule.d.ts +0 -1
- package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-enter-rule.js +1 -1
- package/dist/prosekit-extensions-file.d.ts +1 -1
- package/dist/prosekit-extensions-file.js +1 -1
- package/dist/prosekit-extensions-gap-cursor.d.ts +0 -1
- package/dist/prosekit-extensions-gap-cursor.d.ts.map +1 -1
- package/dist/prosekit-extensions-gap-cursor.js.map +1 -1
- package/dist/prosekit-extensions-hard-break.d.ts.map +1 -1
- package/dist/prosekit-extensions-hard-break.js.map +1 -1
- package/dist/prosekit-extensions-heading.d.ts.map +1 -1
- package/dist/prosekit-extensions-heading.js +7 -7
- package/dist/prosekit-extensions-heading.js.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
- package/dist/prosekit-extensions-image.d.ts +9 -2
- package/dist/prosekit-extensions-image.d.ts.map +1 -1
- package/dist/prosekit-extensions-image.js +17 -4
- package/dist/prosekit-extensions-image.js.map +1 -1
- package/dist/prosekit-extensions-input-rule.d.ts +0 -1
- package/dist/prosekit-extensions-input-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-input-rule.js +1 -1
- package/dist/prosekit-extensions-italic.d.ts.map +1 -1
- package/dist/prosekit-extensions-italic.js +1 -1
- package/dist/prosekit-extensions-italic.js.map +1 -1
- package/dist/prosekit-extensions-link.d.ts +0 -1
- package/dist/prosekit-extensions-link.d.ts.map +1 -1
- package/dist/prosekit-extensions-link.js +4 -4
- package/dist/prosekit-extensions-link.js.map +1 -1
- package/dist/prosekit-extensions-list.d.ts +0 -1
- package/dist/prosekit-extensions-list.d.ts.map +1 -1
- package/dist/prosekit-extensions-list.js +3 -3
- package/dist/prosekit-extensions-list.js.map +1 -1
- package/dist/prosekit-extensions-loro.d.ts +16 -17
- package/dist/prosekit-extensions-loro.d.ts.map +1 -1
- package/dist/prosekit-extensions-loro.js +14 -7
- package/dist/prosekit-extensions-loro.js.map +1 -1
- package/dist/prosekit-extensions-mark-rule.d.ts +0 -1
- package/dist/prosekit-extensions-mark-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-mention.d.ts.map +1 -1
- package/dist/prosekit-extensions-mention.js.map +1 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +0 -1
- package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +1 -1
- package/dist/prosekit-extensions-mod-click-prevention.js.map +1 -1
- package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
- package/dist/prosekit-extensions-paragraph.js +1 -1
- package/dist/prosekit-extensions-paragraph.js.map +1 -1
- package/dist/prosekit-extensions-paste-rule.d.ts +0 -1
- package/dist/prosekit-extensions-paste-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-paste-rule.js +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts.map +1 -1
- package/dist/prosekit-extensions-placeholder.js +3 -4
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-readonly.d.ts +0 -1
- package/dist/prosekit-extensions-readonly.d.ts.map +1 -1
- package/dist/prosekit-extensions-readonly.js.map +1 -1
- package/dist/prosekit-extensions-search.d.ts +0 -1
- package/dist/prosekit-extensions-search.d.ts.map +1 -1
- package/dist/prosekit-extensions-search.js.map +1 -1
- package/dist/prosekit-extensions-strike.d.ts +0 -1
- package/dist/prosekit-extensions-strike.d.ts.map +1 -1
- package/dist/prosekit-extensions-strike.js +3 -3
- package/dist/prosekit-extensions-strike.js.map +1 -1
- package/dist/prosekit-extensions-table.d.ts.map +1 -1
- package/dist/prosekit-extensions-table.js +1 -2
- package/dist/prosekit-extensions-text-align.d.ts +0 -1
- package/dist/prosekit-extensions-text-align.d.ts.map +1 -1
- package/dist/prosekit-extensions-text-align.js +6 -6
- package/dist/prosekit-extensions-text-align.js.map +1 -1
- package/dist/prosekit-extensions-text-color.d.ts +62 -0
- package/dist/prosekit-extensions-text-color.d.ts.map +1 -0
- package/dist/prosekit-extensions-text-color.js +76 -0
- package/dist/prosekit-extensions-text-color.js.map +1 -0
- package/dist/prosekit-extensions-text.d.ts +0 -1
- package/dist/prosekit-extensions-text.d.ts.map +1 -1
- package/dist/prosekit-extensions-text.js.map +1 -1
- package/dist/prosekit-extensions-underline.d.ts +0 -1
- package/dist/prosekit-extensions-underline.d.ts.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts +0 -1
- package/dist/prosekit-extensions-virtual-selection.d.ts.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.js.map +1 -1
- package/dist/prosekit-extensions-yjs.d.ts +9 -2
- package/dist/prosekit-extensions-yjs.d.ts.map +1 -1
- package/dist/prosekit-extensions-yjs.js +1 -1
- package/dist/prosekit-extensions-yjs.js.map +1 -1
- package/dist/{shiki-highlighter-chunk-rkzofy4z.d.ts → shiki-highlighter-chunk-DNNm2Vow.d.ts} +1 -1
- package/dist/shiki-highlighter-chunk-DNNm2Vow.d.ts.map +1 -0
- package/dist/shiki-highlighter-chunk.d.ts +1 -1
- package/dist/shiki-highlighter-chunk.js.map +1 -1
- package/dist/{table-BRDh_9mG.js → table-4oHfV-Ql.js} +2 -2
- package/dist/table-4oHfV-Ql.js.map +1 -0
- package/package.json +33 -18
- package/src/autocomplete/autocomplete-helpers.ts +19 -14
- package/src/autocomplete/autocomplete-plugin.ts +260 -126
- package/src/autocomplete/autocomplete-rule.ts +3 -3
- package/src/autocomplete/autocomplete.spec.ts +244 -40
- package/src/autocomplete/autocomplete.ts +9 -7
- package/src/background-color/background-color-commands.spec.ts +71 -0
- package/src/background-color/background-color-commands.ts +35 -0
- package/src/background-color/background-color-spec.spec.ts +286 -0
- package/src/background-color/background-color-spec.ts +58 -0
- package/src/background-color/background-color.ts +21 -0
- package/src/background-color/index.ts +8 -0
- package/src/blockquote/blockquote-commands.ts +1 -7
- package/src/blockquote/blockquote-keymap.spec.ts +5 -9
- package/src/blockquote/blockquote-keymap.ts +2 -7
- package/src/blockquote/blockquote-spec.ts +1 -4
- package/src/blockquote/blockquote.ts +3 -12
- package/src/blockquote/index.ts +3 -12
- package/src/bold/bold-commands.ts +1 -5
- package/src/bold/bold-input-rule.spec.ts +1 -5
- package/src/bold/bold-input-rule.ts +1 -4
- package/src/bold/bold-keymap.ts +1 -5
- package/src/bold/bold-spec.ts +1 -4
- package/src/bold/bold.ts +3 -12
- package/src/bold/index.ts +3 -12
- package/src/code/code-commands.ts +1 -5
- package/src/code/code-input-rule.ts +1 -4
- package/src/code/code-keymap.ts +1 -5
- package/src/code/code-spec.ts +1 -4
- package/src/code/code.ts +3 -12
- package/src/code/index.ts +3 -12
- package/src/code-block/code-block-commands.ts +1 -8
- package/src/code-block/code-block-highlight.ts +2 -8
- package/src/code-block/code-block-keymap.ts +2 -9
- package/src/code-block/code-block-shiki.ts +1 -4
- package/src/code-block/code-block-spec.spec.ts +4 -11
- package/src/code-block/code-block-spec.ts +1 -4
- package/src/code-block/code-block.ts +4 -16
- package/src/code-block/index.ts +5 -21
- package/src/code-block/shiki-highlighter-chunk.ts +1 -7
- package/src/code-block/shiki-highlighter.ts +1 -4
- package/src/code-block/shiki-parser.ts +1 -4
- package/src/commit/index.ts +7 -36
- package/src/doc/index.ts +1 -4
- package/src/drop-cursor/drop-cursor.ts +1 -4
- package/src/drop-cursor/index.ts +1 -5
- package/src/drop-indicator/drop-indicator-facet.ts +12 -21
- package/src/drop-indicator/index.ts +1 -5
- package/src/enter-rule/index.ts +2 -11
- package/src/file/file-paste-handler.spec.ts +3 -16
- package/src/file/index.ts +3 -16
- package/src/gap-cursor/gap-cursor.ts +1 -4
- package/src/gap-cursor/index.ts +1 -4
- package/src/hard-break/hard-break-commands.ts +1 -5
- package/src/hard-break/hard-break-keymap.spec.ts +6 -12
- package/src/hard-break/hard-break-keymap.ts +1 -4
- package/src/hard-break/hard-break-spec.ts +1 -4
- package/src/hard-break/hard-break.ts +3 -12
- package/src/hard-break/index.ts +3 -12
- package/src/heading/heading-commands.ts +1 -7
- package/src/heading/heading-keymap.spec.ts +8 -12
- package/src/heading/heading-keymap.ts +7 -14
- package/src/heading/heading-spec.ts +1 -4
- package/src/heading/heading.ts +3 -12
- package/src/heading/index.ts +3 -12
- package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -5
- package/src/horizontal-rule/horizontal-rule-commands.ts +2 -9
- package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +5 -9
- package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -5
- package/src/horizontal-rule/horizontal-rule-spec.ts +1 -4
- package/src/horizontal-rule/horizontal-rule.ts +3 -12
- package/src/horizontal-rule/index.ts +3 -13
- package/src/image/image-commands/upload-image.spec.ts +245 -0
- package/src/image/image-commands/upload-image.ts +46 -11
- package/src/image/image-commands.ts +2 -8
- package/src/image/image-spec.ts +1 -4
- package/src/image/image-upload-handler.ts +2 -8
- package/src/image/image.ts +3 -12
- package/src/image/index.ts +3 -13
- package/src/input-rule/index.ts +2 -13
- package/src/italic/index.ts +3 -12
- package/src/italic/italic-commands.spec.ts +2 -10
- package/src/italic/italic-commands.ts +1 -5
- package/src/italic/italic-input-rule.spec.ts +1 -5
- package/src/italic/italic-input-rule.ts +1 -4
- package/src/italic/italic-keymap.ts +1 -5
- package/src/italic/italic-spec.ts +1 -4
- package/src/italic/italic.ts +3 -12
- package/src/link/index.spec.ts +10 -13
- package/src/link/index.ts +1 -5
- package/src/link/link-paste-rule.spec.ts +2 -9
- package/src/link/link-regex.spec.ts +1 -5
- package/src/list/index.ts +3 -12
- package/src/list/list-commands.ts +1 -5
- package/src/list/list-input-rules.ts +1 -4
- package/src/list/list-keymap.spec.ts +6 -10
- package/src/list/list-keymap.ts +2 -8
- package/src/list/list-plugins.ts +1 -4
- package/src/list/list-serializer.ts +2 -9
- package/src/list/list-spec.ts +3 -13
- package/src/list/list.spec.ts +10 -21
- package/src/list/list.ts +3 -12
- package/src/list/style.css +5 -5
- package/src/loro/index.ts +3 -13
- package/src/loro/loro-commands.ts +2 -8
- package/src/loro/loro-cursor-plugin.ts +21 -21
- package/src/loro/loro-keymap.ts +3 -11
- package/src/loro/loro-sync-plugin.ts +2 -8
- package/src/loro/loro-undo-plugin.ts +2 -8
- package/src/loro/loro.ts +16 -21
- package/src/mark-rule/apply.ts +3 -13
- package/src/mark-rule/mark-rule.spec.ts +2 -13
- package/src/mark-rule/mark-rule.ts +2 -13
- package/src/mark-rule/range.ts +2 -8
- package/src/mark-rule/types.ts +1 -4
- package/src/mention/index.ts +1 -8
- package/src/mod-click-prevention/index.ts +2 -9
- package/src/paragraph/paragraph-commands.ts +1 -5
- package/src/paragraph/paragraph-keymap.ts +2 -5
- package/src/paragraph/paragraph-spec.ts +1 -4
- package/src/paragraph/paragraph.ts +3 -14
- package/src/paste-rule/index.ts +2 -10
- package/src/paste-rule/mark-paste-rule.spec.ts +3 -13
- package/src/paste-rule/mark-paste-rule.ts +4 -14
- package/src/paste-rule/paste-rule-plugin.ts +2 -11
- package/src/paste-rule/paste-rule.spec.ts +4 -19
- package/src/paste-rule/split-text-by-regex.spec.ts +1 -5
- package/src/placeholder/index.ts +4 -16
- package/src/readonly/index.ts +2 -8
- package/src/search/index.ts +1 -6
- package/src/strike/index.ts +2 -2
- package/src/table/index.ts +10 -40
- package/src/table/table-commands/delete-cell-selection.spec.ts +1 -5
- package/src/table/table-commands/exit-table.spec.ts +1 -5
- package/src/table/table-commands/insert-table.spec.ts +1 -5
- package/src/table/table-commands/insert-table.ts +1 -4
- package/src/table/table-commands/move-table-column.spec.ts +1 -5
- package/src/table/table-commands/move-table-column.ts +1 -4
- package/src/table/table-commands/move-table-row.spec.ts +1 -5
- package/src/table/table-commands/move-table-row.ts +1 -4
- package/src/table/table-commands/select-table-cell.spec.ts +1 -5
- package/src/table/table-commands/select-table-column.spec.ts +1 -5
- package/src/table/table-commands/select-table-row.spec.ts +1 -5
- package/src/table/table-commands/select-table.spec.ts +1 -5
- package/src/table/table-commands/select-table.ts +1 -4
- package/src/table/table-commands.ts +8 -32
- package/src/table/table-plugins.ts +2 -8
- package/src/table/table-spec.spec.ts +2 -11
- package/src/table/table-spec.ts +2 -8
- package/src/table/table-utils.ts +2 -6
- package/src/table/table.ts +2 -8
- package/src/table/test-utils.ts +1 -4
- package/src/testing/clipboard.ts +1 -2
- package/src/testing/index.ts +9 -14
- package/src/testing/keyboard.ts +0 -30
- package/src/text/index.ts +1 -4
- package/src/text-align/index.ts +6 -6
- package/src/text-color/index.ts +3 -0
- package/src/text-color/text-color-commands.spec.ts +71 -0
- package/src/text-color/text-color-commands.ts +35 -0
- package/src/text-color/text-color-spec.spec.ts +297 -0
- package/src/text-color/text-color-spec.ts +58 -0
- package/src/text-color/text-color.ts +21 -0
- package/src/virtual-selection/index.ts +3 -14
- package/src/yjs/index.ts +5 -20
- package/src/yjs/yjs-commands.ts +2 -8
- package/src/yjs/yjs-cursor-plugin.ts +3 -5
- package/src/yjs/yjs-keymap.ts +3 -11
- package/src/yjs/yjs-sync-plugin.ts +1 -4
- package/src/yjs/yjs-types.ts +10 -0
- package/src/yjs/yjs-undo-plugin.ts +2 -8
- package/src/yjs/yjs.ts +6 -24
- package/dist/drop-indicator-B1QHFb5m.js.map +0 -1
- package/dist/enter-rule-CzWOZF_Z.js.map +0 -1
- package/dist/file-DrfcSid-.js.map +0 -1
- package/dist/index-oIc1a2f2.d.ts.map +0 -1
- package/dist/input-rule-dmsb3j6w.js.map +0 -1
- package/dist/mark-rule-BcLB4Uv2.js.map +0 -1
- package/dist/paste-rule-pVb4sqvJ.js.map +0 -1
- package/dist/shiki-highlighter-chunk-rkzofy4z.d.ts.map +0 -1
- package/dist/table-BRDh_9mG.js.map +0 -1
- package/src/testing/format-html.ts +0 -5
|
@@ -4,11 +4,16 @@ import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
|
|
4
4
|
|
|
5
5
|
//#region src/autocomplete/autocomplete-helpers.ts
|
|
6
6
|
function defaultCanMatch({ state }) {
|
|
7
|
-
|
|
7
|
+
const $pos = state.selection.$from;
|
|
8
|
+
return !isInsideCodeBlock($pos) && !isInsideCodeMark($pos);
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
+
function isInsideCodeBlock($pos) {
|
|
10
11
|
for (let d = $pos.depth; d > 0; d--) if ($pos.node(d).type.spec.code) return true;
|
|
11
|
-
return
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
function isInsideCodeMark($pos) {
|
|
15
|
+
for (const mark of $pos.marks()) if (mark.type.spec.code) return true;
|
|
16
|
+
return false;
|
|
12
17
|
}
|
|
13
18
|
function getPluginState(state) {
|
|
14
19
|
return pluginKey.getState(state);
|
|
@@ -23,6 +28,23 @@ const pluginKey = new PluginKey("prosekit-autocomplete");
|
|
|
23
28
|
|
|
24
29
|
//#endregion
|
|
25
30
|
//#region src/autocomplete/autocomplete-plugin.ts
|
|
31
|
+
/**
|
|
32
|
+
* Creates a plugin that handles autocomplete functionality.
|
|
33
|
+
*
|
|
34
|
+
* Workflow:
|
|
35
|
+
*
|
|
36
|
+
* 1. {@link handleTextInput}: called when text is going to be input, but the
|
|
37
|
+
* transaction is not yet created. Injects a new matching as a transaction
|
|
38
|
+
* meta if applicable. This is the only place to create a new matching if
|
|
39
|
+
* there is no existing matching.
|
|
40
|
+
* 2. {@link handleTransaction}: called when a transaction is going to be
|
|
41
|
+
* applied. Updates the plugin state based on the transaction. This step
|
|
42
|
+
* determines if a matching should be created, updated or removed.
|
|
43
|
+
* 3. {@link handleUpdate}: called when the editor state is updated. This is the
|
|
44
|
+
* place to call `onMatch` and register `deleteMatch` and `ignoreMatch`
|
|
45
|
+
* callbacks.
|
|
46
|
+
* 4. {@link getDecorations}: creates the decorations for the current matching.
|
|
47
|
+
*/
|
|
26
48
|
function createAutocompletePlugin({ getRules }) {
|
|
27
49
|
return new Plugin({
|
|
28
50
|
key: pluginKey,
|
|
@@ -34,82 +56,171 @@ function createAutocompletePlugin({ getRules }) {
|
|
|
34
56
|
};
|
|
35
57
|
},
|
|
36
58
|
apply: (tr, prevValue, oldState, newState) => {
|
|
37
|
-
|
|
38
|
-
if (!tr.docChanged && oldState.selection.eq(newState.selection) && !meta) return prevValue;
|
|
39
|
-
if (meta) {
|
|
40
|
-
let ignores = prevValue.ignores;
|
|
41
|
-
if (!ignores.includes(meta.ignore)) ignores = [...ignores, meta.ignore];
|
|
42
|
-
return {
|
|
43
|
-
matching: null,
|
|
44
|
-
ignores
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const ignoreSet = new Set(prevValue.ignores.map((pos) => tr.mapping.map(pos)));
|
|
48
|
-
let matching = calcPluginStateMatching(newState, getRules());
|
|
49
|
-
if (matching && ignoreSet.has(matching.from)) matching = null;
|
|
50
|
-
return {
|
|
51
|
-
matching,
|
|
52
|
-
ignores: Array.from(ignoreSet)
|
|
53
|
-
};
|
|
59
|
+
return handleTransaction(tr, prevValue, oldState, newState, getRules);
|
|
54
60
|
}
|
|
55
61
|
},
|
|
56
|
-
view: () => ({ update:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
state: view.state,
|
|
71
|
-
match,
|
|
72
|
-
from,
|
|
73
|
-
to,
|
|
74
|
-
deleteMatch,
|
|
75
|
-
ignoreMatch
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
} }),
|
|
79
|
-
props: { decorations: (state) => {
|
|
80
|
-
const pluginState = getPluginState(state);
|
|
81
|
-
if (pluginState?.matching) {
|
|
82
|
-
const { from, to } = pluginState.matching;
|
|
83
|
-
const deco = Decoration.inline(from, to, { class: "prosemirror-prediction-match" });
|
|
84
|
-
return DecorationSet.create(state.doc, [deco]);
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
} }
|
|
62
|
+
view: () => ({ update: handleUpdate }),
|
|
63
|
+
props: {
|
|
64
|
+
handleTextInput: (view, from, to, textAdded, getTr) => {
|
|
65
|
+
const meta = handleTextInput(view, from, to, textAdded, getRules);
|
|
66
|
+
if (meta) {
|
|
67
|
+
const tr = getTr();
|
|
68
|
+
setTrMeta(tr, meta);
|
|
69
|
+
view.dispatch(tr);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
},
|
|
74
|
+
decorations: getDecorations
|
|
75
|
+
}
|
|
88
76
|
});
|
|
89
77
|
}
|
|
78
|
+
function handleTextInput(view, from, to, textAdded, getRules) {
|
|
79
|
+
if (from !== to) return;
|
|
80
|
+
const textFull = getTextBackward(view.state.doc.resolve(from)) + textAdded;
|
|
81
|
+
const textTo = to + textAdded.length;
|
|
82
|
+
const textFrom = textTo - textFull.length;
|
|
83
|
+
const ignores = getPluginState(view.state)?.ignores ?? [];
|
|
84
|
+
const currMatching = matchRule(view.state, getRules(), textFull, textFrom, textTo, ignores);
|
|
85
|
+
if (currMatching) return {
|
|
86
|
+
type: "enter",
|
|
87
|
+
matching: currMatching
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function handleTransaction(tr, prevValue, oldState, newState, getRules) {
|
|
91
|
+
const meta = getTrMeta(tr);
|
|
92
|
+
if (!meta && !tr.docChanged && oldState.selection.eq(newState.selection)) return prevValue;
|
|
93
|
+
const ignoreSet = /* @__PURE__ */ new Set();
|
|
94
|
+
for (const ignore of prevValue.ignores) {
|
|
95
|
+
const result = tr.mapping.mapResult(ignore);
|
|
96
|
+
if (!result.deletedBefore && !result.deletedAfter) ignoreSet.add(result.pos);
|
|
97
|
+
}
|
|
98
|
+
const ignores = Array.from(ignoreSet);
|
|
99
|
+
const prevMatching = prevValue.matching && mapMatching(prevValue.matching, tr.mapping);
|
|
100
|
+
if (!meta) {
|
|
101
|
+
if (!prevMatching) return {
|
|
102
|
+
matching: null,
|
|
103
|
+
ignores
|
|
104
|
+
};
|
|
105
|
+
const { selection } = newState;
|
|
106
|
+
if (selection.to < prevMatching.from || selection.from > prevMatching.to) {
|
|
107
|
+
ignores.push(prevMatching.from);
|
|
108
|
+
return {
|
|
109
|
+
matching: null,
|
|
110
|
+
ignores
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const text = getTextBetween(newState.doc, prevMatching.from, prevMatching.to);
|
|
114
|
+
return {
|
|
115
|
+
matching: matchRule(newState, getRules(), text, prevMatching.from, prevMatching.to, ignores) ?? null,
|
|
116
|
+
ignores
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (meta.type === "enter") {
|
|
120
|
+
if (prevMatching && prevMatching.from !== meta.matching.from) ignores.push(prevMatching.from);
|
|
121
|
+
return {
|
|
122
|
+
matching: meta.matching,
|
|
123
|
+
ignores
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (meta.type === "leave") {
|
|
127
|
+
if (prevMatching) ignores.push(prevMatching.from);
|
|
128
|
+
return {
|
|
129
|
+
matching: null,
|
|
130
|
+
ignores
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`Invalid transaction meta: ${meta}`);
|
|
134
|
+
}
|
|
135
|
+
function handleUpdate(view, prevState) {
|
|
136
|
+
const prevValue = getPluginState(prevState);
|
|
137
|
+
const currValue = getPluginState(view.state);
|
|
138
|
+
if (!prevValue || !currValue) return;
|
|
139
|
+
const prevMatching = prevValue.matching;
|
|
140
|
+
const currMatching = currValue.matching;
|
|
141
|
+
if (prevMatching && prevMatching.rule !== currMatching?.rule) prevMatching.rule.onLeave?.();
|
|
142
|
+
if (currMatching) {
|
|
143
|
+
const { from, to, match, rule } = currMatching;
|
|
144
|
+
const textSnapshot = getTextBetween(view.state.doc, from, to);
|
|
145
|
+
const deleteMatch = () => {
|
|
146
|
+
if (getTextBetween(view.state.doc, from, to) === textSnapshot) view.dispatch(view.state.tr.delete(from, to));
|
|
147
|
+
};
|
|
148
|
+
const ignoreMatch = () => {
|
|
149
|
+
view.dispatch(setTrMeta(view.state.tr, { type: "leave" }));
|
|
150
|
+
};
|
|
151
|
+
rule.onMatch({
|
|
152
|
+
state: view.state,
|
|
153
|
+
match,
|
|
154
|
+
from,
|
|
155
|
+
to,
|
|
156
|
+
deleteMatch,
|
|
157
|
+
ignoreMatch
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function getDecorations(state) {
|
|
162
|
+
const pluginState = getPluginState(state);
|
|
163
|
+
if (pluginState?.matching) {
|
|
164
|
+
const { from, to, match } = pluginState.matching;
|
|
165
|
+
const deco = Decoration.inline(from, to, {
|
|
166
|
+
"class": "prosekit-autocomplete-match",
|
|
167
|
+
"data-autocomplete-match-text": match[0]
|
|
168
|
+
});
|
|
169
|
+
return DecorationSet.create(state.doc, [deco]);
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
90
173
|
const MAX_MATCH = 200;
|
|
91
|
-
|
|
92
|
-
|
|
174
|
+
/** Get the text before the given position at the current block. */
|
|
175
|
+
function getTextBackward($pos) {
|
|
93
176
|
const parentOffset = $pos.parentOffset;
|
|
94
|
-
|
|
177
|
+
return getTextBetween($pos.parent, Math.max(0, parentOffset - MAX_MATCH), parentOffset);
|
|
178
|
+
}
|
|
179
|
+
function getTextBetween(node, from, to) {
|
|
180
|
+
return node.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER);
|
|
181
|
+
}
|
|
182
|
+
function matchRule(state, rules, text, textFrom, textTo, ignores) {
|
|
183
|
+
let maxIgnore = -1;
|
|
184
|
+
for (const ignore of ignores) if (ignore >= textFrom && ignore < textTo && ignore > maxIgnore) maxIgnore = ignore;
|
|
185
|
+
if (maxIgnore >= 0) {
|
|
186
|
+
const cut = maxIgnore + 1 - textFrom;
|
|
187
|
+
text = text.slice(cut);
|
|
188
|
+
textFrom += cut;
|
|
189
|
+
}
|
|
190
|
+
if (textFrom >= textTo || !text) return;
|
|
95
191
|
for (const rule of rules) {
|
|
96
192
|
if (!rule.canMatch({ state })) continue;
|
|
97
193
|
rule.regex.lastIndex = 0;
|
|
98
|
-
const match = rule.regex.exec(
|
|
194
|
+
const match = rule.regex.exec(text);
|
|
99
195
|
if (!match) continue;
|
|
100
|
-
const
|
|
196
|
+
const matchTo = textTo;
|
|
101
197
|
return {
|
|
102
198
|
rule,
|
|
103
199
|
match,
|
|
104
|
-
from:
|
|
105
|
-
to
|
|
200
|
+
from: textFrom + match.index,
|
|
201
|
+
to: matchTo
|
|
106
202
|
};
|
|
107
203
|
}
|
|
108
|
-
|
|
204
|
+
}
|
|
205
|
+
function mapMatching(matching, mapping) {
|
|
206
|
+
return {
|
|
207
|
+
rule: matching.rule,
|
|
208
|
+
match: matching.match,
|
|
209
|
+
from: mapping.map(matching.from),
|
|
210
|
+
to: mapping.map(matching.to, -1)
|
|
211
|
+
};
|
|
109
212
|
}
|
|
110
213
|
|
|
111
214
|
//#endregion
|
|
112
215
|
//#region src/autocomplete/autocomplete.ts
|
|
216
|
+
/**
|
|
217
|
+
* Defines an autocomplete extension that executes logic when the text before
|
|
218
|
+
* the cursor matches the given regular expression.
|
|
219
|
+
*
|
|
220
|
+
* When a match is found, an inline decoration is applied to the matched text
|
|
221
|
+
* with the class `prosekit-autocomplete-match` and a `data-autocomplete-match-text`
|
|
222
|
+
* attribute containing the full matched string.
|
|
223
|
+
*/
|
|
113
224
|
function defineAutocomplete(rule) {
|
|
114
225
|
return defineFacetPayload(autocompleteFacet, [rule]);
|
|
115
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-autocomplete.js","names":["pluginKey: PluginKey<PredictionPluginState>","parentOffset: number","textBefore: string","rules: AutocompleteRule[]"],"sources":["../src/autocomplete/autocomplete-helpers.ts","../src/autocomplete/autocomplete-plugin.ts","../src/autocomplete/autocomplete.ts","../src/autocomplete/autocomplete-rule.ts"],"sourcesContent":["import type { ResolvedPos } from '@prosekit/pm/model'\nimport {\n PluginKey,\n type EditorState,\n type Transaction,\n} from '@prosekit/pm/state'\n\nimport type { AutocompleteRule } from './autocomplete-rule'\n\nexport function defaultCanMatch({ state }: { state: EditorState }): boolean {\n return state.selection.empty && !isInsideCode(state.selection.$from)\n}\n\nfunction isInsideCode($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n if ($pos.node(d).type.spec.code) {\n return true\n }\n }\n\n return $pos.marks().some((mark) => mark.type.name === 'code')\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginMatching {\n rule: AutocompleteRule\n from: number\n to: number\n match: RegExpExecArray\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginState {\n /**\n * The matching positions that should be ignored.\n */\n ignores: number[]\n\n /**\n * The current active matching.\n */\n matching: PredictionPluginMatching | null\n}\n\n/**\n * @internal\n */\ninterface PredictionTransactionMeta {\n /**\n * The from position that should be ignored.\n */\n ignore: number\n}\n\nexport function getPluginState(state: EditorState): PredictionPluginState | undefined {\n return pluginKey.getState(state)\n}\n\nexport function getTrMeta(tr: Transaction): PredictionTransactionMeta | undefined {\n return tr.getMeta(pluginKey) as PredictionTransactionMeta | undefined\n}\n\nexport function setTrMeta(\n tr: Transaction,\n meta: PredictionTransactionMeta,\n): Transaction {\n return tr.setMeta(pluginKey, meta)\n}\n\nexport const pluginKey: PluginKey<PredictionPluginState> = new PluginKey<PredictionPluginState>('prosekit-autocomplete')\n","import { OBJECT_REPLACEMENT_CHARACTER } from '@prosekit/core'\nimport {\n Plugin,\n type EditorState,\n type Transaction,\n} from '@prosekit/pm/state'\nimport {\n Decoration,\n DecorationSet,\n} from '@prosekit/pm/view'\n\nimport {\n getPluginState,\n getTrMeta,\n pluginKey,\n setTrMeta,\n type PredictionPluginMatching,\n type PredictionPluginState,\n} from './autocomplete-helpers'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\nexport function createAutocompletePlugin({\n getRules,\n}: {\n getRules: () => AutocompleteRule[]\n}): Plugin {\n return new Plugin<PredictionPluginState>({\n key: pluginKey,\n\n state: {\n init: (): PredictionPluginState => {\n return { ignores: [], matching: null }\n },\n apply: (\n tr: Transaction,\n prevValue: PredictionPluginState,\n oldState: EditorState,\n newState: EditorState,\n ): PredictionPluginState => {\n const meta = getTrMeta(tr)\n\n // No changes\n if (\n !tr.docChanged\n && oldState.selection.eq(newState.selection)\n && !meta\n ) {\n return prevValue\n }\n\n // Receiving a meta means that we are ignoring a match\n if (meta) {\n let ignores = prevValue.ignores\n if (!ignores.includes(meta.ignore)) {\n ignores = [...ignores, meta.ignore]\n }\n return { matching: null, ignores }\n }\n\n // Calculate the new ignores\n const ignoreSet = new Set(prevValue.ignores.map(pos => tr.mapping.map(pos)))\n\n // Calculate the new matching\n let matching = calcPluginStateMatching(newState, getRules())\n\n // Check if the matching should be ignored\n if (matching && ignoreSet.has(matching.from)) {\n matching = null\n }\n\n // Return the new matching and ignores\n return { matching, ignores: Array.from(ignoreSet) }\n },\n },\n\n view: () => ({\n update: (view, prevState) => {\n const prevValue = getPluginState(prevState)\n const currValue = getPluginState(view.state)\n\n if (\n prevValue?.matching\n && prevValue.matching.rule !== currValue?.matching?.rule\n ) {\n // Deactivate the previous rule\n prevValue.matching.rule.onLeave?.()\n }\n\n if (\n currValue?.matching\n && !currValue.ignores.includes(currValue.matching.from)\n ) {\n // Activate the current rule\n\n const { from, to, match, rule } = currValue.matching\n\n const textContent = view.state.doc.textBetween(\n from,\n to,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n\n const deleteMatch = () => {\n if (\n view.state.doc.textBetween(\n from,\n to,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n ) === textContent\n ) {\n view.dispatch(view.state.tr.delete(from, to))\n }\n }\n\n const ignoreMatch = () => {\n view.dispatch(\n setTrMeta(view.state.tr, { ignore: from }),\n )\n }\n\n rule.onMatch({\n state: view.state,\n match,\n from,\n to,\n deleteMatch,\n ignoreMatch,\n })\n }\n },\n }),\n\n props: {\n decorations: (state: EditorState) => {\n const pluginState = getPluginState(state)\n if (pluginState?.matching) {\n const { from, to } = pluginState.matching\n const deco = Decoration.inline(from, to, {\n class: 'prosemirror-prediction-match',\n })\n return DecorationSet.create(state.doc, [deco])\n }\n return null\n },\n },\n })\n}\n\nconst MAX_MATCH = 200\n\nfunction calcPluginStateMatching(\n state: EditorState,\n rules: AutocompleteRule[],\n): PredictionPluginMatching | null {\n const $pos = state.selection.$from\n\n const parentOffset: number = $pos.parentOffset\n\n const textBefore: string = $pos.parent.textBetween(\n Math.max(0, parentOffset - MAX_MATCH),\n parentOffset,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n\n for (const rule of rules) {\n if (!rule.canMatch({ state })) {\n continue\n }\n\n rule.regex.lastIndex = 0\n const match = rule.regex.exec(textBefore)\n if (!match) {\n continue\n }\n\n const to = $pos.pos\n const from = to - textBefore.length + match.index\n\n return { rule, match, from, to }\n }\n\n return null\n}\n","import {\n defineFacet,\n defineFacetPayload,\n pluginFacet,\n type Extension,\n type PluginPayload,\n} from '@prosekit/core'\n\nimport { createAutocompletePlugin } from './autocomplete-plugin'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\nexport function defineAutocomplete(rule: AutocompleteRule): Extension {\n return defineFacetPayload(autocompleteFacet, [rule])\n}\n\nconst autocompleteFacet = defineFacet<AutocompleteRule, PluginPayload>({\n reduce: () => {\n let rules: AutocompleteRule[] = []\n const getRules = () => rules\n const plugin = createAutocompletePlugin({ getRules })\n\n return function reducer(inputs) {\n rules = inputs\n return plugin\n }\n },\n parent: pluginFacet,\n singleton: true,\n})\n","import type { EditorState } from '@prosekit/pm/state'\n\nimport { defaultCanMatch } from './autocomplete-helpers'\n\n/**\n * Options for the {@link MatchHandler} callback.\n */\nexport interface MatchHandlerOptions {\n /**\n * The editor state.\n */\n state: EditorState\n\n /**\n * The result of `RegExp.exec`.\n */\n match: RegExpExecArray\n\n /**\n * The start position of the matched text.\n */\n from: number\n\n /**\n * The end position of the matched text.\n */\n to: number\n\n /**\n * Call this function to ignore the match. You probably want to call this\n * function when the user presses the `Escape` key.\n */\n ignoreMatch: () => void\n\n /**\n * Call this function to delete the matched text. For example, in a slash\n * menu, you might want to delete the matched text first then do something\n * else when the user presses the `Enter` key.\n */\n deleteMatch: () => void\n}\n\n/**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\nexport type MatchHandler = (options: MatchHandlerOptions) => void\n\n/**\n * Options for the {@link CanMatchPredicate} callback.\n */\nexport interface CanMatchOptions {\n /**\n * The editor state.\n */\n state: EditorState\n}\n\n/**\n * A predicate to determine if the rule can be applied in the current editor state.\n */\nexport type CanMatchPredicate = (options: CanMatchOptions) => boolean\n\n/**\n * Options for creating an {@link AutocompleteRule}\n */\nexport interface AutocompleteRuleOptions {\n /**\n * The regular expression to match against the text before the cursor. The\n * last match before the cursor is used.\n *\n * For a slash menu, you might use `/(?<!\\S)\\/(|\\S.*)$/u`.\n * For a mention, you might use `/@\\w*$/`\n */\n regex: RegExp\n\n /**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\n onEnter: MatchHandler\n\n /**\n * A callback that is called when the rule stops matching.\n */\n onLeave?: VoidFunction\n\n /**\n * A predicate to determine if the rule can be applied in the current editor\n * state. If not provided, it defaults to only allowing matches in empty\n * selections that are not inside a code block or code mark.\n */\n canMatch?: CanMatchPredicate\n}\n\n/**\n * An autocomplete rule that can be used to create an autocomplete extension.\n *\n * @public\n */\nexport class AutocompleteRule {\n /** @internal */\n readonly regex: RegExp\n /** @internal */\n readonly onMatch: MatchHandler\n /** @internal */\n readonly onLeave?: VoidFunction\n /** @internal */\n readonly canMatch: (options: { state: EditorState }) => boolean\n\n constructor(options: AutocompleteRuleOptions) {\n this.regex = options.regex\n this.onMatch = options.onEnter\n this.onLeave = options.onLeave\n this.canMatch = options.canMatch ?? defaultCanMatch\n }\n}\n"],"mappings":";;;;;AASA,SAAgB,gBAAgB,EAAE,SAA0C;AAC1E,QAAO,MAAM,UAAU,SAAS,CAAC,aAAa,MAAM,UAAU,MAAM;;AAGtE,SAAS,aAAa,MAA4B;AAChD,MAAK,IAAI,IAAI,KAAK,OAAO,IAAI,GAAG,IAC9B,KAAI,KAAK,KAAK,EAAE,CAAC,KAAK,KAAK,KACzB,QAAO;AAIX,QAAO,KAAK,OAAO,CAAC,MAAM,SAAS,KAAK,KAAK,SAAS,OAAO;;AAsC/D,SAAgB,eAAe,OAAuD;AACpF,QAAO,UAAU,SAAS,MAAM;;AAGlC,SAAgB,UAAU,IAAwD;AAChF,QAAO,GAAG,QAAQ,UAAU;;AAG9B,SAAgB,UACd,IACA,MACa;AACb,QAAO,GAAG,QAAQ,WAAW,KAAK;;AAGpC,MAAaA,YAA8C,IAAI,UAAiC,wBAAwB;;;;ACpDxH,SAAgB,yBAAyB,EACvC,YAGS;AACT,QAAO,I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B,YAAY,SAAkC;AAC5C,OAAK,QAAQ,QAAQ;AACrB,OAAK,UAAU,QAAQ;AACvB,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,QAAQ,YAAY"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-autocomplete.js","names":[],"sources":["../src/autocomplete/autocomplete-helpers.ts","../src/autocomplete/autocomplete-plugin.ts","../src/autocomplete/autocomplete.ts","../src/autocomplete/autocomplete-rule.ts"],"sourcesContent":["import type { ResolvedPos } from '@prosekit/pm/model'\nimport { PluginKey, type EditorState, type Transaction } from '@prosekit/pm/state'\n\nimport type { AutocompleteRule } from './autocomplete-rule'\n\nexport function defaultCanMatch({ state }: { state: EditorState }): boolean {\n const $pos = state.selection.$from\n return !isInsideCodeBlock($pos) && !isInsideCodeMark($pos)\n}\n\nfunction isInsideCodeBlock($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n if ($pos.node(d).type.spec.code) {\n return true\n }\n }\n return false\n}\n\nfunction isInsideCodeMark($pos: ResolvedPos): boolean {\n for (const mark of $pos.marks()) {\n if (mark.type.spec.code) {\n return true\n }\n }\n return false\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginMatching {\n rule: AutocompleteRule\n from: number\n to: number\n match: RegExpExecArray\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginState {\n /**\n * The matching positions that should be ignored.\n */\n ignores: Array<number>\n\n /**\n * The current active matching.\n */\n matching: PredictionPluginMatching | null\n}\n\n/**\n * @internal\n */\nexport type PredictionTransactionMeta = {\n type: 'enter'\n matching: PredictionPluginMatching\n} | {\n type: 'leave'\n}\n\nexport function getPluginState(state: EditorState): PredictionPluginState | undefined {\n return pluginKey.getState(state)\n}\n\nexport function getTrMeta(tr: Transaction): PredictionTransactionMeta | undefined {\n return tr.getMeta(pluginKey) as PredictionTransactionMeta | undefined\n}\n\nexport function setTrMeta(\n tr: Transaction,\n meta: PredictionTransactionMeta,\n): Transaction {\n return tr.setMeta(pluginKey, meta)\n}\n\nexport const pluginKey: PluginKey<PredictionPluginState> = new PluginKey<PredictionPluginState>('prosekit-autocomplete')\n","import { OBJECT_REPLACEMENT_CHARACTER } from '@prosekit/core'\nimport type { ProseMirrorNode, ResolvedPos } from '@prosekit/pm/model'\nimport { Plugin, type EditorState, type Transaction } from '@prosekit/pm/state'\nimport type { Mapping } from '@prosekit/pm/transform'\nimport type { EditorView } from '@prosekit/pm/view'\nimport { Decoration, DecorationSet } from '@prosekit/pm/view'\n\nimport {\n getPluginState,\n getTrMeta,\n pluginKey,\n setTrMeta,\n type PredictionPluginMatching,\n type PredictionPluginState,\n type PredictionTransactionMeta,\n} from './autocomplete-helpers'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\n/**\n * Creates a plugin that handles autocomplete functionality.\n *\n * Workflow:\n *\n * 1. {@link handleTextInput}: called when text is going to be input, but the\n * transaction is not yet created. Injects a new matching as a transaction\n * meta if applicable. This is the only place to create a new matching if\n * there is no existing matching.\n * 2. {@link handleTransaction}: called when a transaction is going to be\n * applied. Updates the plugin state based on the transaction. This step\n * determines if a matching should be created, updated or removed.\n * 3. {@link handleUpdate}: called when the editor state is updated. This is the\n * place to call `onMatch` and register `deleteMatch` and `ignoreMatch`\n * callbacks.\n * 4. {@link getDecorations}: creates the decorations for the current matching.\n */\nexport function createAutocompletePlugin({\n getRules,\n}: {\n getRules: () => AutocompleteRule[]\n}): Plugin {\n return new Plugin<PredictionPluginState>({\n key: pluginKey,\n\n state: {\n init: (): PredictionPluginState => {\n return { ignores: [], matching: null }\n },\n apply: (tr, prevValue, oldState, newState): PredictionPluginState => {\n return handleTransaction(tr, prevValue, oldState, newState, getRules)\n },\n },\n\n view: () => ({\n update: handleUpdate,\n }),\n\n props: {\n handleTextInput: (view, from, to, textAdded, getTr) => {\n const meta = handleTextInput(view, from, to, textAdded, getRules)\n if (meta) {\n const tr = getTr()\n setTrMeta(tr, meta)\n view.dispatch(tr)\n return true\n }\n return false\n },\n decorations: getDecorations,\n },\n })\n}\n\nfunction handleTextInput(\n view: EditorView,\n from: number,\n to: number,\n textAdded: string,\n getRules: () => AutocompleteRule[],\n): PredictionTransactionMeta | undefined {\n // Only handle insertions\n if (from !== to) {\n return\n }\n\n const textBackward = getTextBackward(view.state.doc.resolve(from))\n const textFull = textBackward + textAdded\n const textTo = to + textAdded.length\n const textFrom = textTo - textFull.length\n\n const pluginState = getPluginState(view.state)\n const ignores = pluginState?.ignores ?? []\n\n const currMatching = matchRule(\n view.state,\n getRules(),\n textFull,\n textFrom,\n textTo,\n ignores,\n )\n\n if (currMatching) {\n return { type: 'enter', matching: currMatching }\n }\n}\n\nfunction handleTransaction(\n tr: Transaction,\n prevValue: PredictionPluginState,\n oldState: EditorState,\n newState: EditorState,\n getRules: () => AutocompleteRule[],\n): PredictionPluginState {\n const meta = getTrMeta(tr)\n\n if (\n !meta\n && !tr.docChanged\n && oldState.selection.eq(newState.selection)\n ) {\n // No changes\n return prevValue\n }\n\n // Handle position mapping changes\n const ignoreSet = new Set<number>()\n for (const ignore of prevValue.ignores) {\n const result = tr.mapping.mapResult(ignore)\n if (!result.deletedBefore && !result.deletedAfter) {\n ignoreSet.add(result.pos)\n }\n }\n const ignores = Array.from(ignoreSet)\n\n const prevMatching = prevValue.matching && mapMatching(prevValue.matching, tr.mapping)\n\n // If there is no new matching from `handleTextInput`\n if (!meta) {\n if (!prevMatching) {\n return { matching: null, ignores }\n }\n\n const { selection } = newState\n // If the text selection is before the matching or after the matching,\n // we leave the matching\n if (selection.to < prevMatching.from || selection.from > prevMatching.to) {\n ignores.push(prevMatching.from)\n return { matching: null, ignores }\n }\n\n // Get the text between the existing matching\n const text = getTextBetween(newState.doc, prevMatching.from, prevMatching.to)\n // Check the text again to see if it still matches the rule\n const currMatching = matchRule(\n newState,\n getRules(),\n text,\n prevMatching.from,\n prevMatching.to,\n ignores,\n )\n return { matching: currMatching ?? null, ignores }\n }\n\n // If a new matching is being entered from `handleTextInput`\n if (meta.type === 'enter') {\n // Ignore the previous matching if it is not the same as the new matching\n if (prevMatching && prevMatching.from !== meta.matching.from) {\n ignores.push(prevMatching.from)\n }\n\n // Return the new matching\n return { matching: meta.matching, ignores }\n }\n\n // If a matching is being exited\n if (meta.type === 'leave') {\n if (prevMatching) {\n ignores.push(prevMatching.from)\n }\n return { matching: null, ignores }\n }\n\n throw new Error(`Invalid transaction meta: ${meta satisfies never}`)\n}\n\nfunction handleUpdate(view: EditorView, prevState: EditorState): void {\n const prevValue = getPluginState(prevState)\n const currValue = getPluginState(view.state)\n\n if (!prevValue || !currValue) {\n // Should not happen\n return\n }\n\n const prevMatching = prevValue.matching\n const currMatching = currValue.matching\n\n // Deactivate the previous rule\n if (prevMatching && prevMatching.rule !== currMatching?.rule) {\n prevMatching.rule.onLeave?.()\n }\n\n // Activate the current rule\n if (currMatching) {\n const { from, to, match, rule } = currMatching\n\n const textSnapshot = getTextBetween(view.state.doc, from, to)\n\n const deleteMatch = () => {\n if (getTextBetween(view.state.doc, from, to) === textSnapshot) {\n view.dispatch(view.state.tr.delete(from, to))\n }\n }\n\n const ignoreMatch = () => {\n view.dispatch(\n setTrMeta(view.state.tr, { type: 'leave' }),\n )\n }\n\n rule.onMatch({\n state: view.state,\n match,\n from,\n to,\n deleteMatch,\n ignoreMatch,\n })\n }\n}\n\nfunction getDecorations(state: EditorState): DecorationSet | null {\n const pluginState = getPluginState(state)\n if (pluginState?.matching) {\n const { from, to, match } = pluginState.matching\n const deco = Decoration.inline(from, to, {\n 'class': 'prosekit-autocomplete-match',\n 'data-autocomplete-match-text': match[0],\n })\n return DecorationSet.create(state.doc, [deco])\n }\n return null\n}\n\nconst MAX_MATCH = 200\n\n/** Get the text before the given position at the current block. */\nfunction getTextBackward($pos: ResolvedPos): string {\n const parentOffset: number = $pos.parentOffset\n return getTextBetween(\n $pos.parent,\n Math.max(0, parentOffset - MAX_MATCH),\n parentOffset,\n )\n}\n\nfunction getTextBetween(node: ProseMirrorNode, from: number, to: number): string {\n return node.textBetween(\n from,\n to,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n}\n\nfunction matchRule(\n state: EditorState,\n rules: AutocompleteRule[],\n text: string,\n textFrom: number,\n textTo: number,\n ignores: Array<number>,\n): PredictionPluginMatching | undefined {\n // Find the rightmost ignore point within the text range\n let maxIgnore = -1\n for (const ignore of ignores) {\n if (ignore >= textFrom && ignore < textTo && ignore > maxIgnore) {\n maxIgnore = ignore\n }\n }\n\n // If an ignore point is within the text range, we ignore the text to the left\n // of the ignore point (including the character right after the ignore point).\n if (maxIgnore >= 0) {\n const cut = maxIgnore + 1 - textFrom\n text = text.slice(cut)\n textFrom += cut\n }\n\n if (textFrom >= textTo || !text) {\n return\n }\n\n for (const rule of rules) {\n if (!rule.canMatch({ state })) {\n continue\n }\n\n rule.regex.lastIndex = 0\n const match = rule.regex.exec(text)\n if (!match) {\n continue\n }\n\n const matchTo = textTo\n const matchFrom = textFrom + match.index\n\n return { rule, match, from: matchFrom, to: matchTo }\n }\n}\n\nfunction mapMatching(matching: PredictionPluginMatching, mapping: Mapping): PredictionPluginMatching {\n return {\n rule: matching.rule,\n match: matching.match,\n from: mapping.map(matching.from),\n to: mapping.map(matching.to, -1),\n }\n}\n","import { defineFacet, defineFacetPayload, pluginFacet, type Extension, type PluginPayload } from '@prosekit/core'\n\nimport { createAutocompletePlugin } from './autocomplete-plugin'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\n/**\n * Defines an autocomplete extension that executes logic when the text before\n * the cursor matches the given regular expression.\n *\n * When a match is found, an inline decoration is applied to the matched text\n * with the class `prosekit-autocomplete-match` and a `data-autocomplete-match-text`\n * attribute containing the full matched string.\n */\nexport function defineAutocomplete(rule: AutocompleteRule): Extension {\n return defineFacetPayload(autocompleteFacet, [rule])\n}\n\nconst autocompleteFacet = defineFacet<AutocompleteRule, PluginPayload>({\n reduce: () => {\n let rules: AutocompleteRule[] = []\n const getRules = () => rules\n const plugin = createAutocompletePlugin({ getRules })\n\n return function reducer(inputs) {\n rules = inputs\n return plugin\n }\n },\n parent: pluginFacet,\n singleton: true,\n})\n","import type { EditorState } from '@prosekit/pm/state'\n\nimport { defaultCanMatch } from './autocomplete-helpers'\n\n/**\n * Options for the {@link MatchHandler} callback.\n */\nexport interface MatchHandlerOptions {\n /**\n * The editor state.\n */\n state: EditorState\n\n /**\n * The result of `RegExp.exec`.\n */\n match: RegExpExecArray\n\n /**\n * The start position of the matched text.\n */\n from: number\n\n /**\n * The end position of the matched text.\n */\n to: number\n\n /**\n * Call this function to ignore the match. You probably want to call this\n * function when the user presses the `Escape` key.\n */\n ignoreMatch: () => void\n\n /**\n * Call this function to delete the matched text. For example, in a slash\n * menu, you might want to delete the matched text first then do something\n * else when the user presses the `Enter` key.\n */\n deleteMatch: () => void\n}\n\n/**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\nexport type MatchHandler = (options: MatchHandlerOptions) => void\n\n/**\n * Options for the {@link CanMatchPredicate} callback.\n */\nexport interface CanMatchOptions {\n /**\n * The editor state.\n */\n state: EditorState\n}\n\n/**\n * A predicate to determine if the rule can be applied in the current editor state.\n */\nexport type CanMatchPredicate = (options: CanMatchOptions) => boolean\n\n/**\n * Options for creating an {@link AutocompleteRule}\n */\nexport interface AutocompleteRuleOptions {\n /**\n * The regular expression to match against the text before the cursor. The\n * last match before the cursor is used.\n *\n * For a slash menu, you might use `/(?<!\\S)\\/(\\S.*)?$/u`.\n * For a mention, you might use `/@\\w*$/`\n */\n regex: RegExp\n\n /**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\n onEnter: MatchHandler\n\n /**\n * A callback that is called when the rule stops matching.\n */\n onLeave?: VoidFunction\n\n /**\n * A predicate to determine if the rule can be applied in the current editor\n * state. If not provided, it defaults to only allowing matches that are not\n * inside a code block or code mark.\n */\n canMatch?: CanMatchPredicate\n}\n\n/**\n * An autocomplete rule that can be used to create an autocomplete extension.\n *\n * @public\n */\nexport class AutocompleteRule {\n /** @internal */\n readonly regex: RegExp\n /** @internal */\n readonly onMatch: MatchHandler\n /** @internal */\n readonly onLeave?: VoidFunction\n /** @internal */\n readonly canMatch: (options: { state: EditorState }) => boolean\n\n constructor(options: AutocompleteRuleOptions) {\n this.regex = options.regex\n this.onMatch = options.onEnter\n this.onLeave = options.onLeave\n this.canMatch = options.canMatch ?? defaultCanMatch\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,gBAAgB,EAAE,SAA0C;CAC1E,MAAM,OAAO,MAAM,UAAU;AAC7B,QAAO,CAAC,kBAAkB,KAAK,IAAI,CAAC,iBAAiB,KAAK;;AAG5D,SAAS,kBAAkB,MAA4B;AACrD,MAAK,IAAI,IAAI,KAAK,OAAO,IAAI,GAAG,IAC9B,KAAI,KAAK,KAAK,EAAE,CAAC,KAAK,KAAK,KACzB,QAAO;AAGX,QAAO;;AAGT,SAAS,iBAAiB,MAA4B;AACpD,MAAK,MAAM,QAAQ,KAAK,OAAO,CAC7B,KAAI,KAAK,KAAK,KAAK,KACjB,QAAO;AAGX,QAAO;;AAsCT,SAAgB,eAAe,OAAuD;AACpF,QAAO,UAAU,SAAS,MAAM;;AAGlC,SAAgB,UAAU,IAAwD;AAChF,QAAO,GAAG,QAAQ,UAAU;;AAG9B,SAAgB,UACd,IACA,MACa;AACb,QAAO,GAAG,QAAQ,WAAW,KAAK;;AAGpC,MAAa,YAA8C,IAAI,UAAiC,wBAAwB;;;;;;;;;;;;;;;;;;;;;AC3CxH,SAAgB,yBAAyB,EACvC,YAGS;AACT,QAAO,IAAI,OAA8B;EACvC,KAAK;EAEL,OAAO;GACL,YAAmC;AACjC,WAAO;KAAE,SAAS,EAAE;KAAE,UAAU;KAAM;;GAExC,QAAQ,IAAI,WAAW,UAAU,aAAoC;AACnE,WAAO,kBAAkB,IAAI,WAAW,UAAU,UAAU,SAAS;;GAExE;EAED,aAAa,EACX,QAAQ,cACT;EAED,OAAO;GACL,kBAAkB,MAAM,MAAM,IAAI,WAAW,UAAU;IACrD,MAAM,OA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,oBAAoB,YAA6C;CACrE,cAAc;EACZ,IAAI,QAA4B,EAAE;EAClC,MAAM,iBAAiB;EACvB,MAAM,SAAS,yBAAyB,EAAE,UAAU,CAAC;AAErD,SAAO,SAAS,QAAQ,QAAQ;AAC9B,WAAQ;AACR,UAAO;;;CAGX,QAAQ;CACR,WAAW;CACZ,CAAC;;;;;;;;;ACsEF,IAAa,mBAAb,MAA8B;CAU5B,YAAY,SAAkC;AAC5C,OAAK,QAAQ,QAAQ;AACrB,OAAK,UAAU,QAAQ;AACvB,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,QAAQ,YAAY"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Extension, Union } from "@prosekit/core";
|
|
2
|
+
import { Command } from "@prosekit/pm/state";
|
|
3
|
+
|
|
4
|
+
//#region src/background-color/background-color-spec.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Attributes for the `backgroundColor` mark.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
interface BackgroundColorAttrs {
|
|
11
|
+
color: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
type BackgroundColorSpecExtension = Extension<{
|
|
17
|
+
Marks: {
|
|
18
|
+
backgroundColor: BackgroundColorAttrs;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
declare function defineBackgroundColorSpec(): BackgroundColorSpecExtension;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/background-color/background-color-commands.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare function addBackgroundColor(attrs: BackgroundColorAttrs): Command;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function removeBackgroundColor(): Command;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
type BackgroundColorCommandsExtension = Extension<{
|
|
39
|
+
Commands: {
|
|
40
|
+
addBackgroundColor: [attrs: BackgroundColorAttrs];
|
|
41
|
+
removeBackgroundColor: [];
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare function defineBackgroundColorCommands(): BackgroundColorCommandsExtension;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/background-color/background-color.d.ts
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
type BackgroundColorExtension = Union<[BackgroundColorSpecExtension, BackgroundColorCommandsExtension]>;
|
|
54
|
+
/**
|
|
55
|
+
* Defines the `backgroundColor` mark and some commands for it.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
declare function defineBackgroundColor(): BackgroundColorExtension;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { type BackgroundColorAttrs, type BackgroundColorCommandsExtension, type BackgroundColorExtension, type BackgroundColorSpecExtension, addBackgroundColor, defineBackgroundColor, defineBackgroundColorCommands, defineBackgroundColorSpec, removeBackgroundColor };
|
|
62
|
+
//# sourceMappingURL=prosekit-extensions-background-color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-background-color.d.ts","names":[],"sources":["../src/background-color/background-color-spec.ts","../src/background-color/background-color-commands.ts","../src/background-color/background-color.ts"],"mappings":";;;;;;;AAOA;;UAAiB,oBAAA;EACf,KAAA;AAAA;AAMF;;;AAAA,KAAY,4BAAA,GAA+B,SAAA;EACzC,KAAA;IACE,eAAA,EAAiB,oBAAA;EAAA;AAAA;;;AAOrB;iBAAgB,yBAAA,CAAA,GAA6B,4BAAA;;;;AAhB7C;;iBCCgB,kBAAA,CAAmB,KAAA,EAAO,oBAAA,GAAuB,OAAA;;;ADMjE;iBCCgB,qBAAA,CAAA,GAAyB,OAAA;;;;KAO7B,gCAAA,GAAmC,SAAA;EAC7C,QAAA;IACE,kBAAA,GAAqB,KAAA,EAAO,oBAAA;IAC5B,qBAAA;EAAA;AAAA;;;;iBAOY,6BAAA,CAAA,GAAiC,gCAAA;;;;ADzBjD;;KECY,wBAAA,GAA2B,KAAA,EAAO,4BAAA,EAA8B,gCAAA;;;AFM5E;;;iBECgB,qBAAA,CAAA,GAAyB,wBAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { addMark, defineCommands, defineMarkSpec, removeMark, union } from "@prosekit/core";
|
|
2
|
+
|
|
3
|
+
//#region src/background-color/background-color-commands.ts
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
function addBackgroundColor(attrs) {
|
|
8
|
+
return addMark({
|
|
9
|
+
type: "backgroundColor",
|
|
10
|
+
attrs
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function removeBackgroundColor() {
|
|
17
|
+
return removeMark({ type: "backgroundColor" });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function defineBackgroundColorCommands() {
|
|
23
|
+
return defineCommands({
|
|
24
|
+
addBackgroundColor,
|
|
25
|
+
removeBackgroundColor
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/background-color/background-color-spec.ts
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
function defineBackgroundColorSpec() {
|
|
35
|
+
return defineMarkSpec({
|
|
36
|
+
name: "backgroundColor",
|
|
37
|
+
attrs: { color: { validate: "string" } },
|
|
38
|
+
parseDOM: [{
|
|
39
|
+
tag: ":where([style*=\"background-color:\"], [data-background-color])",
|
|
40
|
+
getAttrs: (node) => {
|
|
41
|
+
const value = node.getAttribute("data-background-color");
|
|
42
|
+
if (value && value !== "inherit") return { color: value };
|
|
43
|
+
const color = node.style.backgroundColor;
|
|
44
|
+
if (color && color !== "inherit") return { color };
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
consuming: false
|
|
48
|
+
}],
|
|
49
|
+
toDOM(mark) {
|
|
50
|
+
const color = mark.attrs.color;
|
|
51
|
+
return [
|
|
52
|
+
"span",
|
|
53
|
+
{
|
|
54
|
+
"style": `background-color: ${color};`,
|
|
55
|
+
"data-background-color": color
|
|
56
|
+
},
|
|
57
|
+
0
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/background-color/background-color.ts
|
|
65
|
+
/**
|
|
66
|
+
* Defines the `backgroundColor` mark and some commands for it.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
function defineBackgroundColor() {
|
|
71
|
+
return union(defineBackgroundColorSpec(), defineBackgroundColorCommands());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { addBackgroundColor, defineBackgroundColor, defineBackgroundColorCommands, defineBackgroundColorSpec, removeBackgroundColor };
|
|
76
|
+
//# sourceMappingURL=prosekit-extensions-background-color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-background-color.js","names":[],"sources":["../src/background-color/background-color-commands.ts","../src/background-color/background-color-spec.ts","../src/background-color/background-color.ts"],"sourcesContent":["import { addMark, defineCommands, removeMark, type Extension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nimport type { BackgroundColorAttrs } from './background-color-spec'\n\n/**\n * @internal\n */\nexport function addBackgroundColor(attrs: BackgroundColorAttrs): Command {\n return addMark({ type: 'backgroundColor', attrs })\n}\n\n/**\n * @internal\n */\nexport function removeBackgroundColor(): Command {\n return removeMark({ type: 'backgroundColor' })\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorCommandsExtension = Extension<{\n Commands: {\n addBackgroundColor: [attrs: BackgroundColorAttrs]\n removeBackgroundColor: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorCommands(): BackgroundColorCommandsExtension {\n return defineCommands({ addBackgroundColor, removeBackgroundColor })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\n\n/**\n * Attributes for the `backgroundColor` mark.\n *\n * @public\n */\nexport interface BackgroundColorAttrs {\n color: string\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorSpecExtension = Extension<{\n Marks: {\n backgroundColor: BackgroundColorAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorSpec(): BackgroundColorSpecExtension {\n return defineMarkSpec<'backgroundColor', BackgroundColorAttrs>({\n name: 'backgroundColor',\n attrs: {\n color: {\n validate: 'string',\n },\n },\n parseDOM: [\n {\n tag: ':where([style*=\"background-color:\"], [data-background-color])',\n getAttrs: (node): BackgroundColorAttrs | false => {\n // When both `data-background-color` and `style=\"background-color\"` are present, we\n // prioritize the `data-background-color` attribute. This avoids the\n // browser's default behavior of changing hex colors to rgba in style\n // attribute.\n const value = node.getAttribute('data-background-color')\n if (value && value !== 'inherit') {\n return { color: value }\n }\n const color = node.style.backgroundColor\n if (color && color !== 'inherit') {\n return { color }\n }\n return false\n },\n consuming: false,\n },\n ],\n toDOM(mark) {\n const color = (mark.attrs as BackgroundColorAttrs).color\n return ['span', { 'style': `background-color: ${color};`, 'data-background-color': color }, 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBackgroundColorCommands, type BackgroundColorCommandsExtension } from './background-color-commands'\nimport { defineBackgroundColorSpec, type BackgroundColorSpecExtension } from './background-color-spec'\n\n/**\n * @internal\n */\nexport type BackgroundColorExtension = Union<[BackgroundColorSpecExtension, BackgroundColorCommandsExtension]>\n\n/**\n * Defines the `backgroundColor` mark and some commands for it.\n *\n * @public\n */\nexport function defineBackgroundColor(): BackgroundColorExtension {\n return union(\n defineBackgroundColorSpec(),\n defineBackgroundColorCommands(),\n )\n}\n"],"mappings":";;;;;;AAQA,SAAgB,mBAAmB,OAAsC;AACvE,QAAO,QAAQ;EAAE,MAAM;EAAmB;EAAO,CAAC;;;;;AAMpD,SAAgB,wBAAiC;AAC/C,QAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;;;;;AAgBhD,SAAgB,gCAAkE;AAChF,QAAO,eAAe;EAAE;EAAoB;EAAuB,CAAC;;;;;;;;ACVtE,SAAgB,4BAA0D;AACxE,QAAO,eAAwD;EAC7D,MAAM;EACN,OAAO,EACL,OAAO,EACL,UAAU,UACX,EACF;EACD,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAuC;IAKhD,MAAM,QAAQ,KAAK,aAAa,wBAAwB;AACxD,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO,OAAO;IAEzB,MAAM,QAAQ,KAAK,MAAM;AACzB,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO;AAElB,WAAO;;GAET,WAAW;GACZ,CACF;EACD,MAAM,MAAM;GACV,MAAM,QAAS,KAAK,MAA+B;AACnD,UAAO;IAAC;IAAQ;KAAE,SAAS,qBAAqB,MAAM;KAAI,yBAAyB;KAAO;IAAE;IAAE;;EAEjG,CAAC;;;;;;;;;;ACzCJ,SAAgB,wBAAkD;AAChE,QAAO,MACL,2BAA2B,EAC3B,+BAA+B,CAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-blockquote.d.ts","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts"],"
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-blockquote.d.ts","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts"],"mappings":";;;;KAEY,2BAAA,GAA8B,SAAA;EACxC,QAAA;IACE,aAAA;IACA,gBAAA;IACA,gBAAA;EAAA;AAAA;;;;iBAOY,wBAAA,CAAA,GAA4B,2BAAA;;;KCVhC,uBAAA,GAA0B,SAAA;EACpC,KAAA;IACE,UAAA,EAAY,KAAA;EAAA;AAAA;AAAA,iBAIA,oBAAA,CAAA,GAAwB,uBAAA;;;;ADPxC;;KEQY,mBAAA,GAAsB,KAAA,EAC/B,uBAAA,EAAyB,2BAAA;;;;iBAMZ,gBAAA,CAAA,GAAoB,mBAAA;;;;;;AFfpC;iBGMgB,yBAAA,CAAA,GAA6B,cAAA;;;;;;iBCY7B,sBAAA,CAAA,GAA0B,cAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as defineWrappingInputRule } from "./input-rule-
|
|
1
|
+
import { a as defineWrappingInputRule } from "./input-rule-COGr_GBb.js";
|
|
2
2
|
import { defineCommands, defineKeymap, defineNodeSpec, insertNode, isAtBlockStart, toggleWrap, union, wrap } from "@prosekit/core";
|
|
3
3
|
import { joinBackward } from "@prosekit/pm/commands";
|
|
4
4
|
|
|
@@ -49,7 +49,7 @@ function backspaceUnsetBlockquote() {
|
|
|
49
49
|
*/
|
|
50
50
|
function defineBlockquoteKeymap() {
|
|
51
51
|
return defineKeymap({
|
|
52
|
-
"
|
|
52
|
+
"Mod-B": toggleBlockquoteKeybinding(),
|
|
53
53
|
"Backspace": backspaceUnsetBlockquote()
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-blockquote.js","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-blockquote.js","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts"],"sourcesContent":["import { defineCommands, insertNode, toggleWrap, wrap, type Extension } from '@prosekit/core'\n\nexport type BlockquoteCommandsExtension = Extension<{\n Commands: {\n setBlockquote: []\n insertBlockquote: []\n toggleBlockquote: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBlockquoteCommands(): BlockquoteCommandsExtension {\n return defineCommands({\n setBlockquote: () => {\n return wrap({ type: 'blockquote' })\n },\n insertBlockquote: () => {\n return insertNode({ type: 'blockquote' })\n },\n toggleBlockquote: () => {\n return toggleWrap({ type: 'blockquote' })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineWrappingInputRule } from '../input-rule'\n\n/**\n * Wraps the text block in a blockquote when `>` is typed at the start of a new\n * line followed by a space.\n */\nexport function defineBlockquoteInputRule(): PlainExtension {\n return defineWrappingInputRule({\n regex: /^>\\s/,\n type: 'blockquote',\n })\n}\n","import { defineKeymap, isAtBlockStart, toggleWrap, type PlainExtension } from '@prosekit/core'\nimport { joinBackward } from '@prosekit/pm/commands'\nimport type { Command } from '@prosekit/pm/state'\n\nfunction toggleBlockquoteKeybinding(): Command {\n return toggleWrap({ type: 'blockquote' })\n}\n\nfunction backspaceUnsetBlockquote(): Command {\n return (state, dispatch, view) => {\n const $pos = isAtBlockStart(state, view)\n if ($pos?.node(-1).type.name === 'blockquote') {\n return joinBackward(state, dispatch, view)\n }\n return false\n }\n}\n/**\n * @internal\n */\nexport function defineBlockquoteKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-B': toggleBlockquoteKeybinding(),\n 'Backspace': backspaceUnsetBlockquote(),\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\nexport type BlockquoteSpecExtension = Extension<{\n Nodes: {\n blockquote: Attrs\n }\n}>\n\nexport function defineBlockquoteSpec(): BlockquoteSpecExtension {\n return defineNodeSpec({\n name: 'blockquote',\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [{ tag: 'blockquote' }],\n toDOM() {\n return ['blockquote', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBlockquoteCommands, type BlockquoteCommandsExtension } from './blockquote-commands'\nimport { defineBlockquoteInputRule } from './blockquote-input-rule'\nimport { defineBlockquoteKeymap } from './blockquote-keymap'\nimport { defineBlockquoteSpec, type BlockquoteSpecExtension } from './blockquote-spec'\n\n/**\n * @internal\n */\nexport type BlockquoteExtension = Union<\n [BlockquoteSpecExtension, BlockquoteCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineBlockquote(): BlockquoteExtension {\n return union(\n defineBlockquoteSpec(),\n defineBlockquoteInputRule(),\n defineBlockquoteCommands(),\n defineBlockquoteKeymap(),\n )\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,2BAAwD;AACtE,QAAO,eAAe;EACpB,qBAAqB;AACnB,UAAO,KAAK,EAAE,MAAM,cAAc,CAAC;;EAErC,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE3C,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE5C,CAAC;;;;;;;;;AChBJ,SAAgB,4BAA4C;AAC1D,QAAO,wBAAwB;EAC7B,OAAO;EACP,MAAM;EACP,CAAC;;;;;ACRJ,SAAS,6BAAsC;AAC7C,QAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;AAG3C,SAAS,2BAAoC;AAC3C,SAAQ,OAAO,UAAU,SAAS;AAEhC,MADa,eAAe,OAAO,KAAK,EAC9B,KAAK,GAAG,CAAC,KAAK,SAAS,aAC/B,QAAO,aAAa,OAAO,UAAU,KAAK;AAE5C,SAAO;;;;;;AAMX,SAAgB,yBAAyC;AACvD,QAAO,aAAa;EAClB,SAAS,4BAA4B;EACrC,aAAa,0BAA0B;EACxC,CAAC;;;;;ACfJ,SAAgB,uBAAgD;AAC9D,QAAO,eAAe;EACpB,MAAM;EACN,SAAS;EACT,OAAO;EACP,UAAU;EACV,UAAU,CAAC,EAAE,KAAK,cAAc,CAAC;EACjC,QAAQ;AACN,UAAO,CAAC,cAAc,EAAE;;EAE3B,CAAC;;;;;;;;ACFJ,SAAgB,mBAAwC;AACtD,QAAO,MACL,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,CACzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-bold.d.ts","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts"],"
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-bold.d.ts","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts"],"mappings":";;;;;;;KAKY,qBAAA,GAAwB,SAAA;EAClC,QAAA;IACE,UAAA;EAAA;AAAA;;;;iBAOY,kBAAA,CAAA,GAAsB,qBAAA;;;;;AATtC;KCCY,iBAAA,GAAoB,SAAA;EAC9B,KAAA;IACE,IAAA,EAAM,KAAA;EAAA;AAAA;;;;iBAOM,cAAA,CAAA,GAAkB,iBAAA;;;;ADVlC;;KEKY,aAAA,GAAgB,KAAA,EAAO,iBAAA,EAAmB,qBAAA;;;;iBAKtC,UAAA,CAAA,GAAc,aAAA;;;;;;iBCRd,mBAAA,CAAA,GAAuB,cAAA;;;;;;iBCFvB,gBAAA,CAAA,GAAoB,cAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as defineMarkInputRule } from "./input-rule-
|
|
1
|
+
import { r as defineMarkInputRule } from "./input-rule-COGr_GBb.js";
|
|
2
2
|
import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
|
|
3
3
|
|
|
4
4
|
//#region src/bold/bold-commands.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-bold.js","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-bold.js","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type BoldCommandsExtension = Extension<{\n Commands: {\n toggleBold: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldCommands(): BoldCommandsExtension {\n return defineCommands({\n toggleBold: () => toggleMark({ type: 'bold' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineBoldInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/\n : /\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/,\n type: 'bold',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineBoldKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-b': toggleMark({ type: 'bold' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type BoldSpecExtension = Extension<{\n Marks: {\n bold: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldSpec(): BoldSpecExtension {\n return defineMarkSpec({\n name: 'bold',\n parseDOM: [\n { tag: 'strong' },\n // This works around a Google Docs misbehavior where\n // pasted content will be inexplicably wrapped in `<b>`\n // tags with a font-weight normal.\n {\n tag: 'b',\n getAttrs: (node: string | HTMLElement): null | false => {\n return (\n typeof node !== 'string'\n && node.style.fontWeight !== 'normal'\n && null\n )\n },\n },\n { style: 'font-weight=400', clearMark: (m) => m.type.name == 'strong' },\n {\n style: 'font-weight',\n getAttrs: (value: string | HTMLElement): null | false => {\n return (\n typeof value === 'string'\n && /^(bold(er)?|[5-9]\\d{2,})$/.test(value)\n && null\n )\n },\n },\n ],\n toDOM() {\n return ['strong', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBoldCommands, type BoldCommandsExtension } from './bold-commands'\nimport { defineBoldInputRule } from './bold-input-rule'\nimport { defineBoldKeymap } from './bold-keymap'\nimport { defineBoldSpec, type BoldSpecExtension } from './bold-spec'\n\n/**\n * @internal\n */\nexport type BoldExtension = Union<[BoldSpecExtension, BoldCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineBold(): BoldExtension {\n return union(\n defineBoldSpec(),\n defineBoldCommands(),\n defineBoldKeymap(),\n defineBoldInputRule(),\n )\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,EACpB,kBAAkB,WAAW,EAAE,MAAM,QAAQ,CAAC,EAC/C,CAAC;;;;;;;;ACVJ,SAAgB,sBAAsC;AACpD,QAAO,oBAAoB;EACzB,OAAO,uBAAuB,GAC1B,iDACA;EACJ,MAAM;EACP,CAAC;;;;;;;;ACRJ,SAAgB,mBAAmC;AACjD,QAAO,aAAa,EAClB,SAAS,WAAW,EAAE,MAAM,QAAQ,CAAC,EACtC,CAAC;;;;;;;;ACOJ,SAAgB,iBAAoC;AAClD,QAAO,eAAe;EACpB,MAAM;EACN,UAAU;GACR,EAAE,KAAK,UAAU;GAIjB;IACE,KAAK;IACL,WAAW,SAA6C;AACtD,YACE,OAAO,SAAS,YACb,KAAK,MAAM,eAAe,YAC1B;;IAGR;GACD;IAAE,OAAO;IAAmB,YAAY,MAAM,EAAE,KAAK,QAAQ;IAAU;GACvE;IACE,OAAO;IACP,WAAW,UAA8C;AACvD,YACE,OAAO,UAAU,YACd,4BAA4B,KAAK,MAAM,IACvC;;IAGR;GACF;EACD,QAAQ;AACN,UAAO,CAAC,UAAU,EAAE;;EAEvB,CAAC;;;;;;;;ACjCJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as ShikiHighlighterOptions } from "./shiki-highlighter-chunk-
|
|
1
|
+
import { r as ShikiHighlighterOptions } from "./shiki-highlighter-chunk-DNNm2Vow.js";
|
|
2
2
|
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
|
3
3
|
import { Parser } from "prosemirror-highlight";
|
|
4
4
|
import { BundledLanguage as ShikiBundledLanguage, BundledLanguageInfo as ShikiBundledLanguageInfo, BundledTheme as ShikiBundledTheme, BundledThemeInfo as ShikiBundledThemeInfo, SpecialLanguage, bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-code-block.d.ts","names":[],"sources":["../src/code-block/code-block-types.ts","../src/code-block/code-block-commands.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-shiki.ts"],"
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-code-block.d.ts","names":[],"sources":["../src/code-block/code-block-types.ts","../src/code-block/code-block-commands.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../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,5 @@
|
|
|
1
|
-
import { i as defineTextBlockInputRule } from "./input-rule-
|
|
2
|
-
import { n as defineTextBlockEnterRule } from "./enter-rule-
|
|
1
|
+
import { i as defineTextBlockInputRule } from "./input-rule-COGr_GBb.js";
|
|
2
|
+
import { n as defineTextBlockEnterRule } from "./enter-rule-D-p4ykfv.js";
|
|
3
3
|
import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
|
|
4
4
|
import { TextSelection } from "@prosekit/pm/state";
|
|
5
5
|
import { createHighlightPlugin } from "prosemirror-highlight";
|
|
@@ -194,8 +194,8 @@ function defineCodeBlockHighlight({ parser }) {
|
|
|
194
194
|
//#region src/code-block/shiki-highlighter.ts
|
|
195
195
|
let loaded;
|
|
196
196
|
async function load() {
|
|
197
|
-
const { createOrGetHighlighter
|
|
198
|
-
loaded = createOrGetHighlighter
|
|
197
|
+
const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
|
|
198
|
+
loaded = createOrGetHighlighter;
|
|
199
199
|
}
|
|
200
200
|
function createOrGetHighlighter(options) {
|
|
201
201
|
if (!loaded) return { promise: load() };
|