@prosekit/extensions 0.14.1 → 0.14.2
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-DJq8pF92.js.map +1 -1
- package/dist/file-upload-I9m1EJAM.js.map +1 -1
- package/dist/{mark-paste-rule-n_2Ehmb5.js → mark-paste-rule--F1QPUcU.js} +2 -2
- package/dist/mark-paste-rule--F1QPUcU.js.map +1 -0
- package/dist/{mark-rule-CUnXwBuy.js → mark-rule-Bqdm49Eq.js} +2 -2
- package/dist/mark-rule-Bqdm49Eq.js.map +1 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +1 -1
- package/dist/prosekit-extensions-autocomplete.js +17 -17
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-background-color.d.ts +1 -1
- package/dist/prosekit-extensions-background-color.js.map +1 -1
- package/dist/prosekit-extensions-blockquote.d.ts +13 -13
- package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +5 -4
- package/dist/prosekit-extensions-blockquote.js.map +1 -1
- package/dist/prosekit-extensions-bold.d.ts +12 -12
- package/dist/prosekit-extensions-bold.d.ts.map +1 -1
- package/dist/prosekit-extensions-bold.js.map +1 -1
- package/dist/prosekit-extensions-code-block.d.ts +52 -35
- package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
- package/dist/prosekit-extensions-code-block.js +76 -70
- package/dist/prosekit-extensions-code-block.js.map +1 -1
- package/dist/prosekit-extensions-code.d.ts +12 -12
- package/dist/prosekit-extensions-code.d.ts.map +1 -1
- package/dist/prosekit-extensions-code.js.map +1 -1
- package/dist/prosekit-extensions-commit.d.ts +1 -1
- package/dist/prosekit-extensions-commit.js +1 -1
- package/dist/prosekit-extensions-enter-rule.d.ts +2 -2
- package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-enter-rule.js.map +1 -1
- package/dist/prosekit-extensions-hard-break.d.ts +7 -7
- 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 +15 -15
- package/dist/prosekit-extensions-heading.d.ts.map +1 -1
- package/dist/prosekit-extensions-heading.js.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.d.ts +7 -7
- package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js +10 -9
- package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
- package/dist/prosekit-extensions-image.d.ts +11 -11
- package/dist/prosekit-extensions-image.d.ts.map +1 -1
- package/dist/prosekit-extensions-image.js +9 -9
- package/dist/prosekit-extensions-image.js.map +1 -1
- package/dist/prosekit-extensions-italic.d.ts +12 -12
- package/dist/prosekit-extensions-italic.d.ts.map +1 -1
- package/dist/prosekit-extensions-italic.js.map +1 -1
- package/dist/prosekit-extensions-link.js +2 -2
- package/dist/prosekit-extensions-link.js.map +1 -1
- package/dist/prosekit-extensions-list.d.ts +26 -26
- package/dist/prosekit-extensions-list.d.ts.map +1 -1
- package/dist/prosekit-extensions-list.js +25 -25
- package/dist/prosekit-extensions-list.js.map +1 -1
- package/dist/prosekit-extensions-loro.d.ts +16 -16
- package/dist/prosekit-extensions-loro.d.ts.map +1 -1
- package/dist/prosekit-extensions-loro.js.map +1 -1
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-math.d.ts +3 -3
- package/dist/prosekit-extensions-math.d.ts.map +1 -1
- package/dist/prosekit-extensions-math.js +4 -0
- package/dist/prosekit-extensions-math.js.map +1 -1
- package/dist/prosekit-extensions-mod-click-prevention.js +1 -1
- package/dist/prosekit-extensions-paragraph.d.ts +7 -7
- package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
- package/dist/prosekit-extensions-paragraph.js.map +1 -1
- package/dist/prosekit-extensions-paste-rule.js +1 -1
- package/dist/prosekit-extensions-placeholder.d.ts +1 -1
- package/dist/prosekit-extensions-placeholder.js +2 -2
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-readonly.js +1 -1
- package/dist/prosekit-extensions-strike.js.map +1 -1
- package/dist/prosekit-extensions-table.d.ts +47 -47
- package/dist/prosekit-extensions-table.d.ts.map +1 -1
- package/dist/prosekit-extensions-table.js +1 -1
- package/dist/prosekit-extensions-text-align.d.ts +1 -1
- package/dist/prosekit-extensions-text-color.d.ts +1 -1
- package/dist/prosekit-extensions-text-color.js.map +1 -1
- package/dist/prosekit-extensions-virtual-selection.js +1 -1
- package/dist/prosekit-extensions-yjs.d.ts +3 -3
- package/dist/prosekit-extensions-yjs.d.ts.map +1 -1
- package/dist/prosekit-extensions-yjs.js.map +1 -1
- package/dist/{table-UJVYsrB7.js → table-B81i9oH9.js} +28 -28
- package/dist/table-B81i9oH9.js.map +1 -0
- package/package.json +8 -7
- package/src/autocomplete/autocomplete-helpers.ts +1 -1
- package/src/autocomplete/autocomplete-plugin.ts +2 -2
- package/src/autocomplete/autocomplete-rule.ts +1 -1
- package/src/autocomplete/autocomplete.spec.ts +4 -4
- package/src/autocomplete/autocomplete.ts +2 -2
- package/src/autocomplete/index.ts +2 -2
- package/src/background-color/background-color-commands.spec.ts +1 -1
- package/src/background-color/background-color-commands.ts +1 -1
- package/src/background-color/background-color-spec.spec.ts +1 -1
- package/src/background-color/background-color.ts +2 -2
- package/src/background-color/index.ts +3 -3
- package/src/blockquote/blockquote-input-rule.ts +1 -1
- package/src/blockquote/blockquote-keymap.spec.ts +1 -1
- package/src/blockquote/blockquote-keymap.ts +9 -7
- package/src/blockquote/blockquote.ts +4 -4
- package/src/blockquote/index.ts +5 -5
- package/src/bold/bold-input-rule.spec.ts +2 -2
- package/src/bold/bold-input-rule.ts +1 -1
- package/src/bold/bold.ts +4 -4
- package/src/bold/index.ts +5 -5
- package/src/code/code-input-rule.ts +1 -1
- package/src/code/code.ts +4 -4
- package/src/code/index.ts +5 -5
- package/src/code-block/code-block-commands.ts +1 -1
- package/src/code-block/code-block-highlight.ts +11 -1
- package/src/code-block/code-block-input-rule.ts +3 -3
- package/src/code-block/code-block-shiki.ts +13 -5
- package/src/code-block/code-block-spec.spec.ts +2 -2
- package/src/code-block/code-block-spec.ts +1 -1
- package/src/code-block/code-block.ts +4 -4
- package/src/code-block/index.ts +9 -9
- package/src/code-block/shiki-highlighter.ts +2 -2
- package/src/code-block/shiki-parser.ts +2 -2
- package/src/drop-cursor/index.ts +1 -1
- package/src/drop-indicator/drop-indicator.ts +1 -1
- package/src/drop-indicator/index.ts +1 -1
- package/src/enter-rule/index.ts +3 -3
- package/src/file/file-drop-handler.ts +1 -1
- package/src/file/file-paste-handler.spec.ts +3 -3
- package/src/file/file-paste-handler.ts +1 -1
- package/src/file/index.ts +3 -3
- package/src/gap-cursor/index.ts +1 -1
- package/src/hard-break/hard-break-keymap.spec.ts +2 -2
- package/src/hard-break/hard-break-keymap.ts +1 -1
- package/src/hard-break/hard-break.ts +3 -3
- package/src/hard-break/index.ts +4 -4
- package/src/heading/heading-commands.ts +1 -1
- package/src/heading/heading-input-rule.ts +2 -2
- package/src/heading/heading-keymap.spec.ts +1 -1
- package/src/heading/heading-spec.ts +1 -1
- package/src/heading/heading.ts +4 -4
- package/src/heading/index.ts +6 -6
- package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -1
- package/src/horizontal-rule/horizontal-rule-commands.ts +13 -11
- package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +2 -2
- package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -1
- package/src/horizontal-rule/horizontal-rule.ts +3 -3
- package/src/horizontal-rule/index.ts +4 -4
- package/src/image/image-commands/insert-image.ts +1 -1
- package/src/image/image-commands/upload-image.spec.ts +4 -4
- package/src/image/image-commands/upload-image.ts +2 -2
- package/src/image/image-commands.ts +3 -3
- package/src/image/image-upload-handler.ts +2 -2
- package/src/image/image.ts +2 -2
- package/src/image/index.ts +6 -6
- package/src/italic/index.ts +5 -5
- package/src/italic/italic-commands.spec.ts +4 -4
- package/src/italic/italic-input-rule.spec.ts +2 -2
- package/src/italic/italic-input-rule.ts +1 -1
- package/src/italic/italic.ts +4 -4
- package/src/link/index.spec.ts +2 -2
- package/src/link/index.ts +6 -6
- package/src/link/link-paste-rule.spec.ts +2 -2
- package/src/link/link-paste-rule.ts +3 -3
- package/src/link/link-regex.spec.ts +1 -1
- package/src/list/index.ts +8 -8
- package/src/list/list-drop-indicator.ts +2 -2
- package/src/list/list-input-rules.ts +1 -1
- package/src/list/list-keymap.spec.ts +1 -1
- package/src/list/list-spec.ts +1 -1
- package/src/list/list-types.spec.ts +2 -2
- package/src/list/list.spec.ts +6 -6
- package/src/list/list.ts +7 -7
- package/src/loro/index.ts +6 -6
- package/src/loro/loro.ts +5 -5
- package/src/mark-rule/apply.ts +2 -2
- package/src/mark-rule/index.ts +2 -2
- package/src/mark-rule/mark-rule.spec.ts +4 -4
- package/src/mark-rule/mark-rule.ts +2 -2
- package/src/math/index.ts +4 -4
- package/src/math/math-block.ts +8 -1
- package/src/math/math-inline.ts +1 -1
- package/src/math/math.ts +3 -3
- package/src/paragraph/index.ts +7 -7
- package/src/paragraph/paragraph-keymap.ts +1 -1
- package/src/paragraph/paragraph.ts +3 -3
- package/src/paste-rule/index.ts +2 -2
- package/src/paste-rule/mark-paste-rule.spec.ts +8 -8
- package/src/paste-rule/mark-paste-rule.ts +2 -2
- package/src/paste-rule/paste-rule.spec.ts +2 -2
- package/src/paste-rule/paste-rule.ts +1 -1
- package/src/paste-rule/split-text-by-regex.spec.ts +1 -1
- package/src/placeholder/index.ts +1 -1
- package/src/strike/index.ts +1 -1
- package/src/table/index.ts +14 -14
- package/src/table/table-commands/delete-cell-selection.spec.ts +3 -3
- package/src/table/table-commands/exit-table.spec.ts +2 -2
- package/src/table/table-commands/insert-table.spec.ts +1 -1
- package/src/table/table-commands/move-table-column.spec.ts +2 -2
- package/src/table/table-commands/move-table-row.spec.ts +2 -2
- package/src/table/table-commands/select-table-cell.spec.ts +3 -3
- package/src/table/table-commands/select-table-cell.ts +1 -1
- package/src/table/table-commands/select-table-column.spec.ts +2 -2
- package/src/table/table-commands/select-table-column.ts +1 -1
- package/src/table/table-commands/select-table-row.spec.ts +2 -2
- package/src/table/table-commands/select-table-row.ts +1 -1
- package/src/table/table-commands/select-table.spec.ts +2 -2
- package/src/table/table-commands/select-table.ts +1 -1
- package/src/table/table-commands.ts +9 -9
- package/src/table/table-drop-indicator.ts +2 -2
- package/src/table/table-spec.spec.ts +4 -4
- package/src/table/table.ts +4 -4
- package/src/table/test-utils.ts +1 -1
- package/src/testing/index.ts +24 -24
- package/src/text-color/index.ts +3 -3
- package/src/text-color/text-color-commands.spec.ts +1 -1
- package/src/text-color/text-color-commands.ts +1 -1
- package/src/text-color/text-color-spec.spec.ts +1 -1
- package/src/text-color/text-color.ts +2 -2
- package/src/yjs/index.ts +7 -7
- package/src/yjs/yjs-cursor-plugin.ts +1 -1
- package/src/yjs/yjs-undo-plugin.ts +3 -2
- package/src/yjs/yjs.ts +6 -6
- package/dist/mark-paste-rule-n_2Ehmb5.js.map +0 -1
- package/dist/mark-rule-CUnXwBuy.js.map +0 -1
- package/dist/table-UJVYsrB7.js.map +0 -1
|
@@ -32,40 +32,6 @@ type CodeBlockCommandsExtension = Extension<{
|
|
|
32
32
|
*/
|
|
33
33
|
declare function defineCodeBlockCommands(): CodeBlockCommandsExtension;
|
|
34
34
|
//#endregion
|
|
35
|
-
//#region src/code-block/code-block-spec.d.ts
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
type CodeBlockSpecExtension = Extension<{
|
|
40
|
-
Nodes: {
|
|
41
|
-
codeBlock: CodeBlockAttrs;
|
|
42
|
-
};
|
|
43
|
-
}>;
|
|
44
|
-
/**
|
|
45
|
-
* Defines the `codeBlock` node spec.
|
|
46
|
-
*
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/code-block/code-block.d.ts
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtension]>;
|
|
56
|
-
/**
|
|
57
|
-
* Adds `codeBlock` nodes to the editor. This includes the following extensions:
|
|
58
|
-
*
|
|
59
|
-
* - {@link defineCodeBlockSpec}
|
|
60
|
-
* - {@link defineCodeBlockInputRule}
|
|
61
|
-
* - {@link defineCodeBlockEnterRule}
|
|
62
|
-
* - {@link defineCodeBlockKeymap}
|
|
63
|
-
* - {@link defineCodeBlockCommands}.
|
|
64
|
-
*
|
|
65
|
-
* @public
|
|
66
|
-
*/
|
|
67
|
-
declare function defineCodeBlock(): CodeBlockExtension;
|
|
68
|
-
//#endregion
|
|
69
35
|
//#region src/code-block/code-block-highlight.d.ts
|
|
70
36
|
/**
|
|
71
37
|
* @public
|
|
@@ -77,7 +43,16 @@ type HighlightParser = Parser;
|
|
|
77
43
|
* @public
|
|
78
44
|
*/
|
|
79
45
|
type CodeBlockHighlightOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* A parser instance from the `prosemirror-highlight` package.
|
|
48
|
+
*/
|
|
80
49
|
parser: HighlightParser;
|
|
50
|
+
/**
|
|
51
|
+
* ProseMirror node types to highlight.
|
|
52
|
+
*
|
|
53
|
+
* @default ['codeBlock', 'mathBlock']
|
|
54
|
+
*/
|
|
55
|
+
nodeTypes?: string[];
|
|
81
56
|
};
|
|
82
57
|
/**
|
|
83
58
|
* Adds syntax highlighting to code blocks. This function requires a `Parser`
|
|
@@ -90,7 +65,8 @@ type CodeBlockHighlightOptions = {
|
|
|
90
65
|
* @public
|
|
91
66
|
*/
|
|
92
67
|
declare function defineCodeBlockHighlight({
|
|
93
|
-
parser
|
|
68
|
+
parser,
|
|
69
|
+
nodeTypes
|
|
94
70
|
}: CodeBlockHighlightOptions): Extension;
|
|
95
71
|
//#endregion
|
|
96
72
|
//#region src/code-block/code-block-input-rule.d.ts
|
|
@@ -120,6 +96,12 @@ declare function defineCodeBlockKeymap(): PlainExtension;
|
|
|
120
96
|
* @public
|
|
121
97
|
*/
|
|
122
98
|
interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {
|
|
99
|
+
/**
|
|
100
|
+
* ProseMirror node types to highlight.
|
|
101
|
+
*
|
|
102
|
+
* @default ['codeBlock', 'mathBlock']
|
|
103
|
+
*/
|
|
104
|
+
nodeTypes?: string[];
|
|
123
105
|
/**
|
|
124
106
|
* A list of Shiki themes to pre-load. The first theme in the list will be
|
|
125
107
|
* used to render the code block.
|
|
@@ -151,10 +133,45 @@ interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' |
|
|
|
151
133
|
* @public
|
|
152
134
|
*/
|
|
153
135
|
declare function defineCodeBlockShiki({
|
|
136
|
+
nodeTypes,
|
|
154
137
|
themes,
|
|
155
138
|
langs,
|
|
156
139
|
...rest
|
|
157
140
|
}?: CodeBlockShikiOptions): Extension;
|
|
158
141
|
//#endregion
|
|
142
|
+
//#region src/code-block/code-block-spec.d.ts
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
type CodeBlockSpecExtension = Extension<{
|
|
147
|
+
Nodes: {
|
|
148
|
+
codeBlock: CodeBlockAttrs;
|
|
149
|
+
};
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Defines the `codeBlock` node spec.
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/code-block/code-block.d.ts
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtension]>;
|
|
163
|
+
/**
|
|
164
|
+
* Adds `codeBlock` nodes to the editor. This includes the following extensions:
|
|
165
|
+
*
|
|
166
|
+
* - {@link defineCodeBlockSpec}
|
|
167
|
+
* - {@link defineCodeBlockInputRule}
|
|
168
|
+
* - {@link defineCodeBlockEnterRule}
|
|
169
|
+
* - {@link defineCodeBlockKeymap}
|
|
170
|
+
* - {@link defineCodeBlockCommands}.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
declare function defineCodeBlock(): CodeBlockExtension;
|
|
175
|
+
//#endregion
|
|
159
176
|
export { type CodeBlockAttrs, type CodeBlockCommandsExtension, type CodeBlockExtension, type CodeBlockHighlightOptions, type CodeBlockSpecExtension, type HighlightParser, type ShikiBundledLanguage, type ShikiBundledLanguageInfo, type ShikiBundledTheme, type ShikiBundledThemeInfo, defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
|
|
160
177
|
//# sourceMappingURL=prosekit-extensions-code-block.d.ts.map
|
|
@@ -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-
|
|
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-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-shiki.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"mappings":";;;;;;;;;;;UAKiB,cAAA;EACf,QAAA;AAAA;;;;;;KCCU,0BAAA,GAA6B,SAAA;EACvC,QAAA;IACE,YAAA,GAAe,KAAA,GAAQ,c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
-
import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
|
|
4
3
|
import { TextSelection } from "@prosekit/pm/state";
|
|
4
|
+
import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
|
|
5
5
|
import { createHighlightPlugin } from "prosemirror-highlight";
|
|
6
6
|
import { createParser } from "prosemirror-highlight/shiki";
|
|
7
7
|
import { bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
|
|
@@ -41,6 +41,25 @@ function defineCodeBlockCommands() {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/code-block/code-block-highlight.ts
|
|
46
|
+
/**
|
|
47
|
+
* Adds syntax highlighting to code blocks. This function requires a `Parser`
|
|
48
|
+
* instance from the `prosemirror-highlight` package. See the
|
|
49
|
+
* [documentation](https://github.com/ocavue/prosemirror-highlight) for more
|
|
50
|
+
* information.
|
|
51
|
+
*
|
|
52
|
+
* @param options
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
function defineCodeBlockHighlight({ parser, nodeTypes = ["codeBlock", "mathBlock"] }) {
|
|
57
|
+
return definePlugin(createHighlightPlugin({
|
|
58
|
+
parser,
|
|
59
|
+
nodeTypes
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
44
63
|
//#endregion
|
|
45
64
|
//#region src/code-block/code-block-input-rule.ts
|
|
46
65
|
/**
|
|
@@ -108,6 +127,62 @@ const existCodeBlock = (state, dispatch) => {
|
|
|
108
127
|
return false;
|
|
109
128
|
};
|
|
110
129
|
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/code-block/shiki-highlighter.ts
|
|
132
|
+
let loaded;
|
|
133
|
+
async function load() {
|
|
134
|
+
const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
|
|
135
|
+
loaded = createOrGetHighlighter;
|
|
136
|
+
}
|
|
137
|
+
function createOrGetHighlighter(options) {
|
|
138
|
+
if (!loaded) return { promise: load() };
|
|
139
|
+
return loaded(options);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/code-block/shiki-parser.ts
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
function createLazyParser(highlighterOptions) {
|
|
148
|
+
let parser;
|
|
149
|
+
return function lazyParser(options) {
|
|
150
|
+
const language = options.language || "";
|
|
151
|
+
const { highlighter, promise } = createOrGetHighlighter({
|
|
152
|
+
...highlighterOptions,
|
|
153
|
+
langs: [language]
|
|
154
|
+
});
|
|
155
|
+
if (!highlighter) return promise;
|
|
156
|
+
if (!parser) parser = createParser(highlighter, { theme: highlighterOptions.themes[0] });
|
|
157
|
+
return parser(options);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/code-block/code-block-shiki.ts
|
|
163
|
+
/**
|
|
164
|
+
* Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
|
|
165
|
+
*
|
|
166
|
+
* It will set two CSS variables on the code block elements:
|
|
167
|
+
*
|
|
168
|
+
* - `--prosemirror-highlight`: sets text color
|
|
169
|
+
* - `--prosemirror-highlight-bg`: sets background color
|
|
170
|
+
*
|
|
171
|
+
* @param options - The options to configure the Shiki highlighter.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
function defineCodeBlockShiki({ nodeTypes, themes = ["one-dark-pro"], langs = ["text"], ...rest } = {}) {
|
|
176
|
+
return defineCodeBlockHighlight({
|
|
177
|
+
parser: createLazyParser({
|
|
178
|
+
themes,
|
|
179
|
+
langs,
|
|
180
|
+
...rest
|
|
181
|
+
}),
|
|
182
|
+
nodeTypes
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
111
186
|
//#endregion
|
|
112
187
|
//#region src/code-block/code-block-spec.ts
|
|
113
188
|
/**
|
|
@@ -174,75 +249,6 @@ function defineCodeBlock() {
|
|
|
174
249
|
return union(defineCodeBlockSpec(), defineCodeBlockInputRule(), defineCodeBlockEnterRule(), defineCodeBlockKeymap(), defineCodeBlockCommands());
|
|
175
250
|
}
|
|
176
251
|
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/code-block/code-block-highlight.ts
|
|
179
|
-
/**
|
|
180
|
-
* Adds syntax highlighting to code blocks. This function requires a `Parser`
|
|
181
|
-
* instance from the `prosemirror-highlight` package. See the
|
|
182
|
-
* [documentation](https://github.com/ocavue/prosemirror-highlight) for more
|
|
183
|
-
* information.
|
|
184
|
-
*
|
|
185
|
-
* @param options
|
|
186
|
-
*
|
|
187
|
-
* @public
|
|
188
|
-
*/
|
|
189
|
-
function defineCodeBlockHighlight({ parser }) {
|
|
190
|
-
return definePlugin(createHighlightPlugin({ parser }));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
//#endregion
|
|
194
|
-
//#region src/code-block/shiki-highlighter.ts
|
|
195
|
-
let loaded;
|
|
196
|
-
async function load() {
|
|
197
|
-
const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
|
|
198
|
-
loaded = createOrGetHighlighter;
|
|
199
|
-
}
|
|
200
|
-
function createOrGetHighlighter(options) {
|
|
201
|
-
if (!loaded) return { promise: load() };
|
|
202
|
-
return loaded(options);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/code-block/shiki-parser.ts
|
|
207
|
-
/**
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
function createLazyParser(highlighterOptions) {
|
|
211
|
-
let parser;
|
|
212
|
-
return function lazyParser(options) {
|
|
213
|
-
const language = options.language || "";
|
|
214
|
-
const { highlighter, promise } = createOrGetHighlighter({
|
|
215
|
-
...highlighterOptions,
|
|
216
|
-
langs: [language]
|
|
217
|
-
});
|
|
218
|
-
if (!highlighter) return promise;
|
|
219
|
-
if (!parser) parser = createParser(highlighter, { theme: highlighterOptions.themes[0] });
|
|
220
|
-
return parser(options);
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/code-block/code-block-shiki.ts
|
|
226
|
-
/**
|
|
227
|
-
* Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
|
|
228
|
-
*
|
|
229
|
-
* It will set two CSS variables on the code block elements:
|
|
230
|
-
*
|
|
231
|
-
* - `--prosemirror-highlight`: sets text color
|
|
232
|
-
* - `--prosemirror-highlight-bg`: sets background color
|
|
233
|
-
*
|
|
234
|
-
* @param options - The options to configure the Shiki highlighter.
|
|
235
|
-
*
|
|
236
|
-
* @public
|
|
237
|
-
*/
|
|
238
|
-
function defineCodeBlockShiki({ themes = ["one-dark-pro"], langs = ["text"], ...rest } = {}) {
|
|
239
|
-
return defineCodeBlockHighlight({ parser: createLazyParser({
|
|
240
|
-
themes,
|
|
241
|
-
langs,
|
|
242
|
-
...rest
|
|
243
|
-
}) });
|
|
244
|
-
}
|
|
245
|
-
|
|
246
252
|
//#endregion
|
|
247
253
|
export { defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
|
|
248
254
|
//# sourceMappingURL=prosekit-extensions-code-block.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-code-block.js","names":[],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, setNodeAttrs, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule'\nimport { defineTextBlockInputRule } from '../input-rule'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import { defaultBlockAt, defineKeymap, type PlainExtension } from '@prosekit/core'\nimport { TextSelection, type Command } from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeBlockCommands, type CodeBlockCommandsExtension } from './code-block-commands'\nimport { defineCodeBlockEnterRule, defineCodeBlockInputRule } from './code-block-input-rule'\nimport { defineCodeBlockKeymap } from './code-block-keymap'\nimport { defineCodeBlockSpec, type CodeBlockSpecExtension } from './code-block-spec'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n","import { definePlugin, type Extension } from '@prosekit/core'\nimport { createHighlightPlugin, type Parser } from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n parser: HighlightParser\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser }),\n )\n}\n","import type { HighlighterOptions, HighlighterResult } from './shiki-highlighter-chunk'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle'\nimport { createOrGetHighlighter, type HighlighterOptions } from './shiki-highlighter'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight'\nimport type { ShikiBundledLanguage, ShikiBundledTheme } from './shiki-bundle'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk'\nimport { createLazyParser } from './shiki-parser'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser })\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,SAAgB,0BAAsD;AACpE,QAAO,eAAe;EACpB,eAAe,UAA2B;AACxC,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEnD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,oBAAoB,UAA0B;AAC5C,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEpD,CAAC;;;;;;;;;;ACvBJ,SAAgB,2BAA2C;AACzD,QAAO,yBAAyB;EAC9B,OAAO;EACP,MAAM;EACN,OAAO;EACR,CAAC;;;;;;;AAQJ,SAAgB,2BAA2C;AACzD,QAAO,yBAAyB;EAC9B,OAAO;EACP,MAAM;EACN,OAAO;EACR,CAAC;;AAGJ,SAAS,SAAS,OAAyC;AACzD,QAAO,EAAE,UAAU,MAAM,MAAM,IAAI;;;;;;;;AC5BrC,SAAgB,wBAAwC;AACtD,QAAO,aAAa,EAClB,OAAO,gBACR,CAAC;;;;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EAAM,CAAC,EACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-code-block.js","names":[],"sources":["../src/code-block/code-block-commands.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/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, setNodeAttrs, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import { definePlugin, type Extension } from '@prosekit/core'\nimport { createHighlightPlugin, type Parser } from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n /**\n * A parser instance from the `prosemirror-highlight` package.\n */\n parser: HighlightParser\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n nodeTypes = ['codeBlock', 'mathBlock'],\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser, nodeTypes }),\n )\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule/index.ts'\nimport { defineTextBlockInputRule } from '../input-rule/index.ts'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import { defaultBlockAt, defineKeymap, type PlainExtension } from '@prosekit/core'\nimport { TextSelection, type Command } from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import type { HighlighterOptions, HighlighterResult } from './shiki-highlighter-chunk.ts'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk.ts')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle.ts'\nimport { createOrGetHighlighter, type HighlighterOptions } from './shiki-highlighter.ts'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight.ts'\nimport type { ShikiBundledLanguage, ShikiBundledTheme } from './shiki-bundle.ts'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk.ts'\nimport { createLazyParser } from './shiki-parser.ts'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n nodeTypes,\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser, nodeTypes })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeBlockCommands, type CodeBlockCommandsExtension } from './code-block-commands.ts'\nimport { defineCodeBlockEnterRule, defineCodeBlockInputRule } from './code-block-input-rule.ts'\nimport { defineCodeBlockKeymap } from './code-block-keymap.ts'\nimport { defineCodeBlockSpec, type CodeBlockSpecExtension } from './code-block-spec.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,SAAgB,0BAAsD;AACpE,QAAO,eAAe;EACpB,eAAe,UAA2B;AACxC,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEnD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa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,KAAK,IAC5C,2BAA2B,KAAK,cAAc,OAAO,CAAC,EACxC;;GAEtB,CACF;EACD,MAAM,MAAM;GACV,MAAM,EAAE,aAAa,KAAK;AAC1B,UAAO;IACL;IACA,EAAE,iBAAiB,YAAY,QAAW;IAE1C;KAAC;KAAQ,EAAE,OAAO,WAAW,YAAY,aAAa,QAAW;KAAE;KAAE;IACtE;;EAEJ,CAAC;;AAGJ,SAAS,2BAA2B,SAAiD;AACnF,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,OAAO,QAAQ,aAAa,gBAAgB;AAClD,KAAI,KACF,QAAO;CAIT,MAAM,QADY,QAAQ,UACF,MAAM,iBAAiB;AAC/C,KAAI,MACF,QAAO,MAAM;AAGf,QAAO;;;;;;;;;;;;;;;;ACzCT,SAAgB,kBAAsC;AACpD,QAAO,MACL,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,CAC1B"}
|
|
@@ -15,6 +15,18 @@ type CodeCommandsExtension = Extension<{
|
|
|
15
15
|
*/
|
|
16
16
|
declare function defineCodeCommands(): CodeCommandsExtension;
|
|
17
17
|
//#endregion
|
|
18
|
+
//#region src/code/code-input-rule.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
declare function defineCodeInputRule(): PlainExtension;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/code/code-keymap.d.ts
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
declare function defineCodeKeymap(): PlainExtension;
|
|
29
|
+
//#endregion
|
|
18
30
|
//#region src/code/code-spec.d.ts
|
|
19
31
|
/**
|
|
20
32
|
* @internal
|
|
@@ -39,17 +51,5 @@ type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>;
|
|
|
39
51
|
*/
|
|
40
52
|
declare function defineCode(): CodeExtension;
|
|
41
53
|
//#endregion
|
|
42
|
-
//#region src/code/code-input-rule.d.ts
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
declare function defineCodeInputRule(): PlainExtension;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/code/code-keymap.d.ts
|
|
49
|
-
/**
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
declare function defineCodeKeymap(): PlainExtension;
|
|
53
|
-
//#endregion
|
|
54
54
|
export { type CodeCommandsExtension, type CodeExtension, type CodeSpecExtension, defineCode, defineCodeCommands, defineCodeInputRule, defineCodeKeymap, defineCodeSpec };
|
|
55
55
|
//# sourceMappingURL=prosekit-extensions-code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-code.d.ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-code.d.ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"mappings":";;;;;;;KAKY,qBAAA,GAAwB,SAAA;EAClC,QAAA;IACE,UAAA;EAAA;AAAA;;;;iBAOY,kBAAA,CAAA,GAAsB,qBAAA;;;;;;iBCPtB,mBAAA,CAAA,GAAuB,cAAA;;;;;;iBCFvB,gBAAA,CAAA,GAAoB,cAAA;;;;;AFApC;KGCY,iBAAA,GAAoB,SAAA;EAC9B,KAAA;IACE,IAAA,EAAM,KAAA;EAAA;AAAA;;;;iBAOM,cAAA,CAAA,GAAkB,iBAAA;;;;AHVlC;;KIKY,aAAA,GAAgB,KAAA,EAAO,iBAAA,EAAmB,qBAAA;;;;iBAKtC,UAAA,CAAA,GAAc,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-code.js","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type CodeCommandsExtension = Extension<{\n Commands: {\n toggleCode: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeCommands(): CodeCommandsExtension {\n return defineCommands({\n toggleCode: () => toggleMark({ type: 'code' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineCodeInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/\n : /`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/,\n type: 'code',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineCodeKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-e': toggleMark({ type: 'code' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type CodeSpecExtension = Extension<{\n Marks: {\n code: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeSpec(): CodeSpecExtension {\n return defineMarkSpec({\n name: 'code',\n parseDOM: [{ tag: 'code' }],\n code: true,\n toDOM() {\n return ['code', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeCommands, type CodeCommandsExtension } from './code-commands'\nimport { defineCodeInputRule } from './code-input-rule'\nimport { defineCodeKeymap } from './code-keymap'\nimport { defineCodeSpec, type CodeSpecExtension } from './code-spec'\n\n/**\n * @internal\n */\nexport type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineCode(): CodeExtension {\n return union(\n defineCodeSpec(),\n defineCodeCommands(),\n defineCodeKeymap(),\n defineCodeInputRule(),\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,2CACA;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,CAAC,EAAE,KAAK,QAAQ,CAAC;EAC3B,MAAM;EACN,QAAQ;AACN,UAAO,CAAC,QAAQ,EAAE;;EAErB,CAAC;;;;;;;;ACRJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-code.js","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type CodeCommandsExtension = Extension<{\n Commands: {\n toggleCode: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeCommands(): CodeCommandsExtension {\n return defineCommands({\n toggleCode: () => toggleMark({ type: 'code' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule/index.ts'\n\n/**\n * @internal\n */\nexport function defineCodeInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/\n : /`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/,\n type: 'code',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineCodeKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-e': toggleMark({ type: 'code' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type CodeSpecExtension = Extension<{\n Marks: {\n code: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeSpec(): CodeSpecExtension {\n return defineMarkSpec({\n name: 'code',\n parseDOM: [{ tag: 'code' }],\n code: true,\n toDOM() {\n return ['code', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeCommands, type CodeCommandsExtension } from './code-commands.ts'\nimport { defineCodeInputRule } from './code-input-rule.ts'\nimport { defineCodeKeymap } from './code-keymap.ts'\nimport { defineCodeSpec, type CodeSpecExtension } from './code-spec.ts'\n\n/**\n * @internal\n */\nexport type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineCode(): CodeExtension {\n return union(\n defineCodeSpec(),\n defineCodeCommands(),\n defineCodeKeymap(),\n defineCodeInputRule(),\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,2CACA;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,CAAC,EAAE,KAAK,QAAQ,CAAC;EAC3B,MAAM;EACN,QAAQ;AACN,UAAO,CAAC,QAAQ,EAAE;;EAErB,CAAC;;;;;;;;ACRJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeJSON, PlainExtension, StepJSON } from "@prosekit/core";
|
|
2
1
|
import { Transaction } from "@prosekit/pm/state";
|
|
2
|
+
import { NodeJSON, PlainExtension, StepJSON } from "@prosekit/core";
|
|
3
3
|
import { ProseMirrorNode } from "@prosekit/pm/model";
|
|
4
4
|
|
|
5
5
|
//#region src/commit/index.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineDefaultState, definePlugin, jsonFromNode, union } from "@prosekit/core";
|
|
2
1
|
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
|
2
|
+
import { defineDefaultState, definePlugin, jsonFromNode, union } from "@prosekit/core";
|
|
3
3
|
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
|
4
4
|
import { DOMSerializer, Fragment, Slice } from "@prosekit/pm/model";
|
|
5
5
|
import { Step } from "@prosekit/pm/transform";
|
|
@@ -7,13 +7,13 @@ import { EnterRule, EnterRuleHandler, EnterRuleHandlerOptions, TextBlockEnterRul
|
|
|
7
7
|
*
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
interface EnterRuleOptions extends EnterRule {}
|
|
11
11
|
/**
|
|
12
12
|
* Options for {@link defineTextBlockEnterRule}.
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
interface TextBlockEnterRuleOptions extends TextBlockEnterRuleOptions$1 {}
|
|
17
17
|
/**
|
|
18
18
|
* Defines an enter rule. An enter rule applies when the text directly in front of
|
|
19
19
|
* the cursor matches `regex` and user presses Enter. The `regex` should end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-enter-rule.d.ts","names":[],"sources":["../src/enter-rule/index.ts"],"mappings":";;;;;AAiBA;;;;
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-enter-rule.d.ts","names":[],"sources":["../src/enter-rule/index.ts"],"mappings":";;;;;AAiBA;;;;UAAiB,gBAAA,SAAyB,SAAA;;;;;AAkB1C;UAXiB,yBAAA,SAAkC,2BAAA;;;;;;;AAwBnD;;;iBAbgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAmB,cAAA;;;;;;;;;;iBAa5C,wBAAA,CAAyB,OAAA,EAAS,yBAAA,GAA4B,cAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-enter-rule.js","names":[],"sources":["../src/enter-rule/index.ts"],"sourcesContent":["import { defineFacet, defineFacetPayload, pluginFacet, type PlainExtension, type PluginPayload } from '@prosekit/core'\nimport {\n createEnterRulePlugin,\n createTextBlockEnterRule,\n type EnterRule,\n type EnterRuleHandler,\n type EnterRuleHandlerOptions,\n type TextBlockEnterRuleOptions as
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-enter-rule.js","names":[],"sources":["../src/enter-rule/index.ts"],"sourcesContent":["import { defineFacet, defineFacetPayload, pluginFacet, type PlainExtension, type PluginPayload } from '@prosekit/core'\nimport {\n createEnterRulePlugin,\n createTextBlockEnterRule,\n type EnterRule,\n type EnterRuleHandler,\n type EnterRuleHandlerOptions,\n type TextBlockEnterRuleOptions as TextBlockEnterRuleOptionsBase,\n} from 'prosemirror-enter-rules'\n\nexport type { EnterRuleHandler, EnterRuleHandlerOptions }\n\n/**\n * Options for {@link defineEnterRule}.\n *\n * @public\n */\nexport interface EnterRuleOptions extends EnterRule {}\n\n/**\n * Options for {@link defineTextBlockEnterRule}.\n *\n * @public\n */\nexport interface TextBlockEnterRuleOptions extends TextBlockEnterRuleOptionsBase {}\n\n/**\n * Defines an enter rule. An enter rule applies when the text directly in front of\n * the cursor matches `regex` and user presses Enter. The `regex` should end\n * with `$`.\n *\n * @param options\n *\n * @public\n */\nexport function defineEnterRule(options: EnterRuleOptions): PlainExtension {\n return defineFacetPayload(enterRuleFacet, [options]) as PlainExtension\n}\n\n/**\n * Defines an enter rule that replaces the matched text with a block node.\n *\n * See also {@link defineEnterRule}.\n *\n * @param options\n *\n * @public\n */\nexport function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension {\n return defineEnterRule(createTextBlockEnterRule(options))\n}\n\nconst enterRuleFacet = defineFacet<EnterRule, PluginPayload>({\n reducer: (rules: EnterRule[]): PluginPayload => {\n return createEnterRulePlugin({ rules })\n },\n\n parent: pluginFacet,\n})\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAgB,gBAAgB,SAA2C;AACzE,QAAO,mBAAmB,gBAAgB,CAAC,QAAQ,CAAC;;;;;;;;;;;AAYtD,SAAgB,yBAAyB,SAAoD;AAC3F,QAAO,gBAAgB,yBAAyB,QAAQ,CAAC;;AAG3D,MAAM,iBAAiB,YAAsC;CAC3D,UAAU,UAAsC;AAC9C,SAAO,sBAAsB,EAAE,OAAO,CAAC;;CAGzC,QAAQ;CACT,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
|
2
1
|
import { Command } from "@prosekit/pm/state";
|
|
2
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
|
3
3
|
import { Attrs } from "@prosekit/pm/model";
|
|
4
4
|
|
|
5
5
|
//#region src/hard-break/hard-break-commands.d.ts
|
|
@@ -16,6 +16,12 @@ type HardBreakCommandsExtension = Extension<{
|
|
|
16
16
|
*/
|
|
17
17
|
declare function defineHardBreakCommands(): HardBreakCommandsExtension;
|
|
18
18
|
//#endregion
|
|
19
|
+
//#region src/hard-break/hard-break-keymap.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
declare function defineHardBreakKeymap(): PlainExtension;
|
|
24
|
+
//#endregion
|
|
19
25
|
//#region src/hard-break/hard-break-spec.d.ts
|
|
20
26
|
/**
|
|
21
27
|
* @internal
|
|
@@ -40,11 +46,5 @@ type HardBreakExtension = Union<[HardBreakSpecExtension, HardBreakCommandsExtens
|
|
|
40
46
|
*/
|
|
41
47
|
declare function defineHardBreak(): HardBreakExtension;
|
|
42
48
|
//#endregion
|
|
43
|
-
//#region src/hard-break/hard-break-keymap.d.ts
|
|
44
|
-
/**
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
declare function defineHardBreakKeymap(): PlainExtension;
|
|
48
|
-
//#endregion
|
|
49
49
|
export { type HardBreakCommandsExtension, type HardBreakExtension, type HardBreakSpecExtension, defineHardBreak, defineHardBreakCommands, defineHardBreakKeymap, defineHardBreakSpec };
|
|
50
50
|
//# sourceMappingURL=prosekit-extensions-hard-break.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-hard-break.d.ts","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-hard-break.d.ts","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-keymap.ts","../src/hard-break/hard-break-spec.ts","../src/hard-break/hard-break.ts"],"mappings":";;;;;;;;KAMY,0BAAA,GAA6B,SAAA;EACvC,QAAA;IACE,eAAA;EAAA;AAAA;AAcJ;;;AAAA,iBAAgB,uBAAA,CAAA,GAA2B,0BAAA;;;;;;iBCf3B,qBAAA,CAAA,GAAyB,cAAA;;;;;;KCD7B,sBAAA,GAAyB,SAAA;EACnC,KAAA;IACE,SAAA,EAAW,KAAA;EAAA;AAAA;;;;iBAOC,mBAAA,CAAA,GAAuB,sBAAA;;;;;AFTvC;KGGY,kBAAA,GAAqB,KAAA,EAC9B,sBAAA,EAAwB,0BAAA;;;;iBAMX,eAAA,CAAA,GAAmB,kBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-hard-break.js","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-keymap.ts","../src/hard-break/hard-break-spec.ts","../src/hard-break/hard-break.ts"],"sourcesContent":["import { defineCommands, insertNode, type Extension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\n/**\n * @internal\n */\nexport type HardBreakCommandsExtension = Extension<{\n Commands: {\n insertHardBreak: []\n }\n}>\n\n/**\n * @internal\n */\nexport function insertHardBreak(): Command {\n return insertNode({ type: 'hardBreak' })\n}\n\n/**\n * @internal\n */\nexport function defineHardBreakCommands(): HardBreakCommandsExtension {\n return defineCommands({\n insertHardBreak: insertHardBreak,\n })\n}\n","import { defineKeymap, type PlainExtension } from '@prosekit/core'\n\nimport { insertHardBreak } from './hard-break-commands'\n\n/**\n * @internal\n */\nexport function defineHardBreakKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-Enter': insertHardBreak(),\n 'Shift-Enter': insertHardBreak(),\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type HardBreakSpecExtension = Extension<{\n Nodes: {\n hardBreak: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHardBreakSpec(): HardBreakSpecExtension {\n return defineNodeSpec({\n name: 'hardBreak',\n inline: true,\n selectable: false,\n leafText: () => '\\n',\n group: 'inline',\n parseDOM: [{ tag: 'br' }],\n toDOM() {\n return ['br']\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands'\nimport { defineHardBreakKeymap } from './hard-break-keymap'\nimport { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec'\n\n/**\n * @internal\n */\nexport type HardBreakExtension = Union<\n [HardBreakSpecExtension, HardBreakCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineHardBreak(): HardBreakExtension {\n return union(\n defineHardBreakSpec(),\n defineHardBreakKeymap(),\n defineHardBreakCommands(),\n )\n}\n"],"mappings":";;;;;;AAeA,SAAgB,kBAA2B;AACzC,QAAO,WAAW,EAAE,MAAM,aAAa,CAAC;;;;;AAM1C,SAAgB,0BAAsD;AACpE,QAAO,eAAe,EACH,iBAClB,CAAC;;;;;;;;AClBJ,SAAgB,wBAAwC;AACtD,QAAO,aAAa;EAClB,aAAa,iBAAiB;EAC9B,eAAe,iBAAiB;EACjC,CAAC;;;;;;;;ACIJ,SAAgB,sBAA8C;AAC5D,QAAO,eAAe;EACpB,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,gBAAgB;EAChB,OAAO;EACP,UAAU,CAAC,EAAE,KAAK,MAAM,CAAC;EACzB,QAAQ;AACN,UAAO,CAAC,KAAK;;EAEhB,CAAC;;;;;;;;ACVJ,SAAgB,kBAAsC;AACpD,QAAO,MACL,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,CAC1B"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-hard-break.js","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-keymap.ts","../src/hard-break/hard-break-spec.ts","../src/hard-break/hard-break.ts"],"sourcesContent":["import { defineCommands, insertNode, type Extension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\n/**\n * @internal\n */\nexport type HardBreakCommandsExtension = Extension<{\n Commands: {\n insertHardBreak: []\n }\n}>\n\n/**\n * @internal\n */\nexport function insertHardBreak(): Command {\n return insertNode({ type: 'hardBreak' })\n}\n\n/**\n * @internal\n */\nexport function defineHardBreakCommands(): HardBreakCommandsExtension {\n return defineCommands({\n insertHardBreak: insertHardBreak,\n })\n}\n","import { defineKeymap, type PlainExtension } from '@prosekit/core'\n\nimport { insertHardBreak } from './hard-break-commands.ts'\n\n/**\n * @internal\n */\nexport function defineHardBreakKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-Enter': insertHardBreak(),\n 'Shift-Enter': insertHardBreak(),\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type HardBreakSpecExtension = Extension<{\n Nodes: {\n hardBreak: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHardBreakSpec(): HardBreakSpecExtension {\n return defineNodeSpec({\n name: 'hardBreak',\n inline: true,\n selectable: false,\n leafText: () => '\\n',\n group: 'inline',\n parseDOM: [{ tag: 'br' }],\n toDOM() {\n return ['br']\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineHardBreakCommands, type HardBreakCommandsExtension } from './hard-break-commands.ts'\nimport { defineHardBreakKeymap } from './hard-break-keymap.ts'\nimport { defineHardBreakSpec, type HardBreakSpecExtension } from './hard-break-spec.ts'\n\n/**\n * @internal\n */\nexport type HardBreakExtension = Union<\n [HardBreakSpecExtension, HardBreakCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineHardBreak(): HardBreakExtension {\n return union(\n defineHardBreakSpec(),\n defineHardBreakKeymap(),\n defineHardBreakCommands(),\n )\n}\n"],"mappings":";;;;;;AAeA,SAAgB,kBAA2B;AACzC,QAAO,WAAW,EAAE,MAAM,aAAa,CAAC;;;;;AAM1C,SAAgB,0BAAsD;AACpE,QAAO,eAAe,EACH,iBAClB,CAAC;;;;;;;;AClBJ,SAAgB,wBAAwC;AACtD,QAAO,aAAa;EAClB,aAAa,iBAAiB;EAC9B,eAAe,iBAAiB;EACjC,CAAC;;;;;;;;ACIJ,SAAgB,sBAA8C;AAC5D,QAAO,eAAe;EACpB,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,gBAAgB;EAChB,OAAO;EACP,UAAU,CAAC,EAAE,KAAK,MAAM,CAAC;EACzB,QAAQ;AACN,UAAO,CAAC,KAAK;;EAEhB,CAAC;;;;;;;;ACVJ,SAAgB,kBAAsC;AACpD,QAAO,MACL,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,CAC1B"}
|
|
@@ -21,6 +21,21 @@ type HeadingCommandsExtension = Extension<{
|
|
|
21
21
|
*/
|
|
22
22
|
declare function defineHeadingCommands(): HeadingCommandsExtension;
|
|
23
23
|
//#endregion
|
|
24
|
+
//#region src/heading/heading-input-rule.d.ts
|
|
25
|
+
/**
|
|
26
|
+
* Converts the text block to a heading when `#` is typed at the start of a new
|
|
27
|
+
* line followed by a space.
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
declare function defineHeadingInputRule(): PlainExtension;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/heading/heading-keymap.d.ts
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
declare function defineHeadingKeymap(): PlainExtension;
|
|
38
|
+
//#endregion
|
|
24
39
|
//#region src/heading/heading-spec.d.ts
|
|
25
40
|
/**
|
|
26
41
|
* @internal
|
|
@@ -45,20 +60,5 @@ type HeadingExtension = Union<[HeadingSpecExtension, HeadingCommandsExtension]>;
|
|
|
45
60
|
*/
|
|
46
61
|
declare function defineHeading(): HeadingExtension;
|
|
47
62
|
//#endregion
|
|
48
|
-
//#region src/heading/heading-input-rule.d.ts
|
|
49
|
-
/**
|
|
50
|
-
* Converts the text block to a heading when `#` is typed at the start of a new
|
|
51
|
-
* line followed by a space.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
declare function defineHeadingInputRule(): PlainExtension;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/heading/heading-keymap.d.ts
|
|
58
|
-
/**
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
declare function defineHeadingKeymap(): PlainExtension;
|
|
62
|
-
//#endregion
|
|
63
63
|
export { type HeadingAttrs, type HeadingCommandsExtension, type HeadingExtension, type HeadingSpecExtension, defineHeading, defineHeadingCommands, defineHeadingInputRule, defineHeadingKeymap, defineHeadingSpec };
|
|
64
64
|
//# sourceMappingURL=prosekit-extensions-heading.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-heading.d.ts","names":[],"sources":["../src/heading/heading-types.ts","../src/heading/heading-commands.ts","../src/heading/heading-
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-heading.d.ts","names":[],"sources":["../src/heading/heading-types.ts","../src/heading/heading-commands.ts","../src/heading/heading-input-rule.ts","../src/heading/heading-keymap.ts","../src/heading/heading-spec.ts","../src/heading/heading.ts"],"mappings":";;;UAAiB,YAAA;EACf,KAAA;AAAA;;;;AADF;;KCOY,wBAAA,GAA2B,SAAA;EACrC,QAAA;IACE,UAAA,GAAa,KAAA,GAAQ,YAAA;IACrB,aAAA,GAAgB,KAAA,GAAQ,YAAA;IACxB,aAAA,GAAgB,KAAA,GAAQ,YAAA;EAAA;AAAA;;;;iBAOZ,qBAAA,CAAA,GAAyB,wBAAA;;;;;ADlBzC;;;;iBEYgB,sBAAA,CAAA,GAA0B,cAAA;;;;;AFZ1C;iBGsBgB,mBAAA,CAAA,GAAuB,cAAA;;;;AHtBvC;;KIOY,oBAAA,GAAuB,SAAA;EACjC,KAAA;IACE,OAAA,EAAS,YAAA;EAAA;AAAA;;AHFb;;iBGSgB,iBAAA,CAAA,GAAqB,oBAAA;;;AJhBrC;;;AAAA,KKUY,gBAAA,GAAmB,KAAA,EAC5B,oBAAA,EAAsB,wBAAA;;AJJzB;;iBIUgB,aAAA,CAAA,GAAiB,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-heading.js","names":[],"sources":["../src/heading/heading-commands.ts","../src/heading/heading-input-rule.ts","../src/heading/heading-keymap.ts","../src/heading/heading-spec.ts","../src/heading/heading.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { HeadingAttrs } from './heading-types'\n\n/**\n * @internal\n */\nexport type HeadingCommandsExtension = Extension<{\n Commands: {\n setHeading: [attrs?: HeadingAttrs | undefined]\n insertHeading: [attrs?: HeadingAttrs | undefined]\n toggleHeading: [attrs?: HeadingAttrs | undefined]\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHeadingCommands(): HeadingCommandsExtension {\n return defineCommands({\n setHeading: (attrs?: HeadingAttrs) => {\n return setBlockType({ type: 'heading', attrs })\n },\n insertHeading: (attrs?: HeadingAttrs) => {\n return insertNode({ type: 'heading', attrs })\n },\n toggleHeading: (attrs?: HeadingAttrs) => {\n return toggleNode({ type: 'heading', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockInputRule } from '../input-rule'\n\nimport type { HeadingAttrs } from './heading-types'\n\n/**\n * Converts the text block to a heading when `#` is typed at the start of a new\n * line followed by a space.\n *\n * @internal\n */\nexport function defineHeadingInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^(#{1,6})\\s$/,\n type: 'heading',\n attrs: (match) => {\n const level: number = match[1]?.length ?? 1\n return { level } satisfies HeadingAttrs\n },\n })\n}\n","import { defineKeymap, isAtBlockStart, toggleNode, unsetBlockType, withSkipCodeBlock, type PlainExtension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nfunction toggleHeadingKeybinding(level: number): Command {\n return withSkipCodeBlock(toggleNode({ type: 'heading', attrs: { level } }))\n}\n\n/**\n * Set the block type to default (usually `paragraph`) when pressing Backspace at\n * the start of a heading block.\n */\nconst backspaceUnsetHeading: Command = (state, dispatch, view) => {\n const $pos = isAtBlockStart(state, view)\n if ($pos?.parent.type.name === 'heading') {\n return unsetBlockType()(state, dispatch, view)\n }\n return false\n}\n\n/**\n * @internal\n */\nexport function defineHeadingKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-Alt-1': toggleHeadingKeybinding(1),\n 'Mod-Alt-2': toggleHeadingKeybinding(2),\n 'Mod-Alt-3': toggleHeadingKeybinding(3),\n 'Mod-Alt-4': toggleHeadingKeybinding(4),\n 'Mod-Alt-5': toggleHeadingKeybinding(5),\n 'Mod-Alt-6': toggleHeadingKeybinding(6),\n 'Backspace': backspaceUnsetHeading,\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { HeadingAttrs } from './heading-types'\n\n/**\n * @internal\n */\nexport type HeadingSpecExtension = Extension<{\n Nodes: {\n heading: HeadingAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHeadingSpec(): HeadingSpecExtension {\n return defineNodeSpec({\n name: 'heading',\n attrs: { level: { default: 1, validate: 'number' } },\n content: 'inline*',\n group: 'block',\n defining: true,\n parseDOM: [\n { tag: 'h1', attrs: { level: 1 } },\n { tag: 'h2', attrs: { level: 2 } },\n { tag: 'h3', attrs: { level: 3 } },\n { tag: 'h4', attrs: { level: 4 } },\n { tag: 'h5', attrs: { level: 5 } },\n { tag: 'h6', attrs: { level: 6 } },\n ],\n toDOM(node) {\n return [`h${node.attrs.level}`, 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands'\nimport { defineHeadingInputRule } from './heading-input-rule'\nimport { defineHeadingKeymap } from './heading-keymap'\nimport { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec'\n\n/**\n * @internal\n */\nexport type HeadingExtension = Union<\n [HeadingSpecExtension, HeadingCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineHeading(): HeadingExtension {\n return union(\n defineHeadingSpec(),\n defineHeadingInputRule(),\n defineHeadingKeymap(),\n defineHeadingCommands(),\n )\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,wBAAkD;AAChE,QAAO,eAAe;EACpB,aAAa,UAAyB;AACpC,UAAO,aAAa;IAAE,MAAM;IAAW;IAAO,CAAC;;EAEjD,gBAAgB,UAAyB;AACvC,UAAO,WAAW;IAAE,MAAM;IAAW;IAAO,CAAC;;EAE/C,gBAAgB,UAAyB;AACvC,UAAO,WAAW;IAAE,MAAM;IAAW;IAAO,CAAC;;EAEhD,CAAC;;;;;;;;;;;ACjBJ,SAAgB,yBAAyC;AACvD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,QAAO,MACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,CACxB"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-heading.js","names":[],"sources":["../src/heading/heading-commands.ts","../src/heading/heading-input-rule.ts","../src/heading/heading-keymap.ts","../src/heading/heading-spec.ts","../src/heading/heading.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { HeadingAttrs } from './heading-types.ts'\n\n/**\n * @internal\n */\nexport type HeadingCommandsExtension = Extension<{\n Commands: {\n setHeading: [attrs?: HeadingAttrs | undefined]\n insertHeading: [attrs?: HeadingAttrs | undefined]\n toggleHeading: [attrs?: HeadingAttrs | undefined]\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHeadingCommands(): HeadingCommandsExtension {\n return defineCommands({\n setHeading: (attrs?: HeadingAttrs) => {\n return setBlockType({ type: 'heading', attrs })\n },\n insertHeading: (attrs?: HeadingAttrs) => {\n return insertNode({ type: 'heading', attrs })\n },\n toggleHeading: (attrs?: HeadingAttrs) => {\n return toggleNode({ type: 'heading', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockInputRule } from '../input-rule/index.ts'\n\nimport type { HeadingAttrs } from './heading-types.ts'\n\n/**\n * Converts the text block to a heading when `#` is typed at the start of a new\n * line followed by a space.\n *\n * @internal\n */\nexport function defineHeadingInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^(#{1,6})\\s$/,\n type: 'heading',\n attrs: (match) => {\n const level: number = match[1]?.length ?? 1\n return { level } satisfies HeadingAttrs\n },\n })\n}\n","import { defineKeymap, isAtBlockStart, toggleNode, unsetBlockType, withSkipCodeBlock, type PlainExtension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nfunction toggleHeadingKeybinding(level: number): Command {\n return withSkipCodeBlock(toggleNode({ type: 'heading', attrs: { level } }))\n}\n\n/**\n * Set the block type to default (usually `paragraph`) when pressing Backspace at\n * the start of a heading block.\n */\nconst backspaceUnsetHeading: Command = (state, dispatch, view) => {\n const $pos = isAtBlockStart(state, view)\n if ($pos?.parent.type.name === 'heading') {\n return unsetBlockType()(state, dispatch, view)\n }\n return false\n}\n\n/**\n * @internal\n */\nexport function defineHeadingKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-Alt-1': toggleHeadingKeybinding(1),\n 'Mod-Alt-2': toggleHeadingKeybinding(2),\n 'Mod-Alt-3': toggleHeadingKeybinding(3),\n 'Mod-Alt-4': toggleHeadingKeybinding(4),\n 'Mod-Alt-5': toggleHeadingKeybinding(5),\n 'Mod-Alt-6': toggleHeadingKeybinding(6),\n 'Backspace': backspaceUnsetHeading,\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { HeadingAttrs } from './heading-types.ts'\n\n/**\n * @internal\n */\nexport type HeadingSpecExtension = Extension<{\n Nodes: {\n heading: HeadingAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineHeadingSpec(): HeadingSpecExtension {\n return defineNodeSpec({\n name: 'heading',\n attrs: { level: { default: 1, validate: 'number' } },\n content: 'inline*',\n group: 'block',\n defining: true,\n parseDOM: [\n { tag: 'h1', attrs: { level: 1 } },\n { tag: 'h2', attrs: { level: 2 } },\n { tag: 'h3', attrs: { level: 3 } },\n { tag: 'h4', attrs: { level: 4 } },\n { tag: 'h5', attrs: { level: 5 } },\n { tag: 'h6', attrs: { level: 6 } },\n ],\n toDOM(node) {\n return [`h${node.attrs.level}`, 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineHeadingCommands, type HeadingCommandsExtension } from './heading-commands.ts'\nimport { defineHeadingInputRule } from './heading-input-rule.ts'\nimport { defineHeadingKeymap } from './heading-keymap.ts'\nimport { defineHeadingSpec, type HeadingSpecExtension } from './heading-spec.ts'\n\n/**\n * @internal\n */\nexport type HeadingExtension = Union<\n [HeadingSpecExtension, HeadingCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineHeading(): HeadingExtension {\n return union(\n defineHeadingSpec(),\n defineHeadingInputRule(),\n defineHeadingKeymap(),\n defineHeadingCommands(),\n )\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,wBAAkD;AAChE,QAAO,eAAe;EACpB,aAAa,UAAyB;AACpC,UAAO,aAAa;IAAE,MAAM;IAAW;IAAO,CAAC;;EAEjD,gBAAgB,UAAyB;AACvC,UAAO,WAAW;IAAE,MAAM;IAAW;IAAO,CAAC;;EAE/C,gBAAgB,UAAyB;AACvC,UAAO,WAAW;IAAE,MAAM;IAAW;IAAO,CAAC;;EAEhD,CAAC;;;;;;;;;;;ACjBJ,SAAgB,yBAAyC;AACvD,QAAO,yBAAyB;EAC9B,OAAO;EACP,MAAM;EACN,QAAQ,UAAU;AAEhB,UAAO,EAAE,OADa,MAAM,IAAI,UAAU,GAC1B;;EAEnB,CAAC;;;;;ACjBJ,SAAS,wBAAwB,OAAwB;AACvD,QAAO,kBAAkB,WAAW;EAAE,MAAM;EAAW,OAAO,EAAE,OAAO;EAAE,CAAC,CAAC;;;;;;AAO7E,MAAM,yBAAkC,OAAO,UAAU,SAAS;AAEhE,KADa,eAAe,OAAO,KAAK,EAC9B,OAAO,KAAK,SAAS,UAC7B,QAAO,gBAAgB,CAAC,OAAO,UAAU,KAAK;AAEhD,QAAO;;;;;AAMT,SAAgB,sBAAsC;AACpD,QAAO,aAAa;EAClB,aAAa,wBAAwB,EAAE;EACvC,aAAa,wBAAwB,EAAE;EACvC,aAAa,wBAAwB,EAAE;EACvC,aAAa,wBAAwB,EAAE;EACvC,aAAa,wBAAwB,EAAE;EACvC,aAAa,wBAAwB,EAAE;EACvC,aAAa;EACd,CAAC;;;;;;;;ACfJ,SAAgB,oBAA0C;AACxD,QAAO,eAAe;EACpB,MAAM;EACN,OAAO,EAAE,OAAO;GAAE,SAAS;GAAG,UAAU;GAAU,EAAE;EACpD,SAAS;EACT,OAAO;EACP,UAAU;EACV,UAAU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