@prosekit/extensions 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commit/style.css +1 -1
- package/dist/commit/style.js +0 -0
- package/dist/enter-rule-RdhEA900.js +96 -0
- package/dist/gap-cursor/style.css +6 -3
- package/dist/gap-cursor/style.js +0 -0
- package/dist/input-rule-Gji4N7Oe.js +93 -0
- package/dist/list/style.css +7 -7
- package/dist/list/style.js +0 -0
- package/dist/loro/style.css +13 -9
- package/dist/loro/style.js +0 -0
- package/dist/mark-rule-wEOcDt6i.js +160 -0
- package/dist/placeholder/style.css +3 -3
- package/dist/placeholder/style.js +0 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
- package/dist/prosekit-extensions-autocomplete.js +126 -174
- package/dist/prosekit-extensions-blockquote.d.ts +48 -8
- package/dist/prosekit-extensions-blockquote.js +64 -78
- package/dist/prosekit-extensions-bold.d.ts +54 -8
- package/dist/prosekit-extensions-bold.js +61 -73
- package/dist/prosekit-extensions-code-block.d.ts +159 -20
- package/dist/prosekit-extensions-code-block.js +201 -184
- package/dist/prosekit-extensions-code.d.ts +54 -8
- package/dist/prosekit-extensions-code.js +44 -56
- package/dist/prosekit-extensions-commit.d.ts +52 -4
- package/dist/prosekit-extensions-commit.js +140 -183
- package/dist/prosekit-extensions-doc.d.ts +19 -2
- package/dist/prosekit-extensions-doc.js +14 -12
- package/dist/prosekit-extensions-drop-cursor.d.ts +35 -3
- package/dist/prosekit-extensions-drop-cursor.js +14 -8
- package/dist/prosekit-extensions-enter-rule.d.ts +105 -5
- package/dist/prosekit-extensions-enter-rule.js +3 -8
- package/dist/prosekit-extensions-file.d.ts +129 -8
- package/dist/prosekit-extensions-file.js +124 -132
- package/dist/prosekit-extensions-gap-cursor.d.ts +26 -2
- package/dist/prosekit-extensions-gap-cursor.js +21 -9
- package/dist/prosekit-extensions-hard-break.d.ts +53 -0
- package/dist/prosekit-extensions-hard-break.js +58 -0
- package/dist/prosekit-extensions-heading.d.ts +63 -9
- package/dist/prosekit-extensions-heading.js +121 -95
- package/dist/prosekit-extensions-horizontal-rule.d.ts +38 -8
- package/dist/prosekit-extensions-horizontal-rule.js +53 -71
- package/dist/prosekit-extensions-image.d.ts +50 -7
- package/dist/prosekit-extensions-image.js +71 -62
- package/dist/prosekit-extensions-input-rule.d.ts +129 -6
- package/dist/prosekit-extensions-input-rule.js +3 -14
- package/dist/prosekit-extensions-italic.d.ts +54 -8
- package/dist/prosekit-extensions-italic.js +51 -63
- package/dist/prosekit-extensions-link.d.ts +62 -10
- package/dist/prosekit-extensions-link.js +95 -100
- package/dist/prosekit-extensions-list.d.ts +104 -17
- package/dist/prosekit-extensions-list.js +115 -158
- package/dist/prosekit-extensions-loro.d.ts +69 -11
- package/dist/prosekit-extensions-loro.js +49 -77
- package/dist/prosekit-extensions-mark-rule.d.ts +37 -2
- package/dist/prosekit-extensions-mark-rule.js +3 -6
- package/dist/prosekit-extensions-mention.d.ts +39 -4
- package/dist/prosekit-extensions-mention.js +52 -50
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +17 -2
- package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
- package/dist/prosekit-extensions-paragraph.d.ts +60 -7
- package/dist/prosekit-extensions-paragraph.js +46 -45
- package/dist/prosekit-extensions-placeholder.d.ts +33 -2
- package/dist/prosekit-extensions-placeholder.js +39 -56
- package/dist/prosekit-extensions-readonly.d.ts +10 -1
- package/dist/prosekit-extensions-readonly.js +13 -14
- package/dist/prosekit-extensions-search.d.ts +74 -3
- package/dist/prosekit-extensions-search.js +48 -47
- package/dist/prosekit-extensions-strike.d.ts +47 -8
- package/dist/prosekit-extensions-strike.js +44 -49
- package/dist/prosekit-extensions-table.d.ts +231 -26
- package/dist/prosekit-extensions-table.js +3 -34
- package/dist/prosekit-extensions-text-align.d.ts +71 -8
- package/dist/prosekit-extensions-text-align.js +63 -44
- package/dist/prosekit-extensions-text.d.ts +19 -2
- package/dist/prosekit-extensions-text.js +13 -11
- package/dist/prosekit-extensions-underline.d.ts +43 -7
- package/dist/prosekit-extensions-underline.js +33 -37
- package/dist/prosekit-extensions-virtual-selection.d.ts +21 -2
- package/dist/prosekit-extensions-virtual-selection.js +49 -52
- package/dist/prosekit-extensions-yjs.d.ts +90 -14
- package/dist/prosekit-extensions-yjs.js +88 -131
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/search/style.css +4 -3
- package/dist/search/style.js +0 -0
- package/dist/shiki-highlighter-chunk-CZGvZlhf.d.ts +18 -0
- package/dist/shiki-highlighter-chunk.d.ts +2 -0
- package/dist/shiki-highlighter-chunk.js +32 -39
- package/dist/table/style.css +10 -13
- package/dist/table/style.js +0 -0
- package/dist/table-DnVliJ6E.js +287 -0
- package/dist/virtual-selection/style.css +2 -2
- package/dist/virtual-selection/style.js +0 -0
- package/dist/yjs/style.css +9 -8
- package/dist/yjs/style.js +0 -0
- package/package.json +81 -54
- package/dist/_tsup-dts-rollup.d.ts +0 -2459
- package/dist/chunk-6UYLCVBX.js +0 -185
- package/dist/chunk-D54VSLLS.js +0 -105
- package/dist/chunk-I2UMHK3L.js +0 -99
- package/dist/chunk-QVFEYPQ6.js +0 -306
@@ -1,217 +1,234 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from "
|
4
|
-
import {
|
5
|
-
|
6
|
-
} from "
|
7
|
-
|
8
|
-
// src/code-block/code-block.ts
|
9
|
-
import {
|
10
|
-
union
|
11
|
-
} from "@prosekit/core";
|
1
|
+
import { defineTextBlockInputRule } from "./input-rule-Gji4N7Oe.js";
|
2
|
+
import { defineTextBlockEnterRule } from "./enter-rule-RdhEA900.js";
|
3
|
+
import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
|
4
|
+
import { TextSelection } from "@prosekit/pm/state";
|
5
|
+
import { createHighlightPlugin } from "prosemirror-highlight";
|
6
|
+
import { createParser } from "prosemirror-highlight/shiki";
|
7
|
+
import { bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
toggleNode
|
20
|
-
} from "@prosekit/core";
|
9
|
+
//#region src/code-block/code-block-commands.ts
|
10
|
+
/**
|
11
|
+
* Adds commands for working with `codeBlock` nodes.
|
12
|
+
*
|
13
|
+
* @public
|
14
|
+
*/
|
21
15
|
function defineCodeBlockCommands() {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
return defineCommands({
|
17
|
+
setCodeBlock: (attrs) => {
|
18
|
+
return setBlockType({
|
19
|
+
type: "codeBlock",
|
20
|
+
attrs
|
21
|
+
});
|
22
|
+
},
|
23
|
+
insertCodeBlock: (attrs) => {
|
24
|
+
return insertNode({
|
25
|
+
type: "codeBlock",
|
26
|
+
attrs
|
27
|
+
});
|
28
|
+
},
|
29
|
+
toggleCodeBlock: (attrs) => {
|
30
|
+
return toggleNode({
|
31
|
+
type: "codeBlock",
|
32
|
+
attrs
|
33
|
+
});
|
34
|
+
},
|
35
|
+
setCodeBlockAttrs: (attrs) => {
|
36
|
+
return setNodeAttrs({
|
37
|
+
type: "codeBlock",
|
38
|
+
attrs
|
39
|
+
});
|
40
|
+
}
|
41
|
+
});
|
36
42
|
}
|
37
43
|
|
38
|
-
|
44
|
+
//#endregion
|
45
|
+
//#region src/code-block/code-block-input-rule.ts
|
46
|
+
/**
|
47
|
+
* Adds input rules for `codeBlock` nodes.
|
48
|
+
*
|
49
|
+
* @public
|
50
|
+
*/
|
39
51
|
function defineCodeBlockInputRule() {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
52
|
+
return defineTextBlockInputRule({
|
53
|
+
regex: /^```(\S*)\s$/,
|
54
|
+
type: "codeBlock",
|
55
|
+
attrs: getAttrs
|
56
|
+
});
|
45
57
|
}
|
58
|
+
/**
|
59
|
+
* Adds enter rules for `codeBlock` nodes.
|
60
|
+
*
|
61
|
+
* @public
|
62
|
+
*/
|
46
63
|
function defineCodeBlockEnterRule() {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
64
|
+
return defineTextBlockEnterRule({
|
65
|
+
regex: /^```(\S*)$/,
|
66
|
+
type: "codeBlock",
|
67
|
+
attrs: getAttrs
|
68
|
+
});
|
52
69
|
}
|
53
70
|
function getAttrs(match) {
|
54
|
-
|
71
|
+
return { language: match[1] || "" };
|
55
72
|
}
|
56
73
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
import {
|
63
|
-
TextSelection
|
64
|
-
} from "@prosekit/pm/state";
|
74
|
+
//#endregion
|
75
|
+
//#region src/code-block/code-block-keymap.ts
|
76
|
+
/**
|
77
|
+
* Defines the keymap for code blocks.
|
78
|
+
*/
|
65
79
|
function defineCodeBlockKeymap() {
|
66
|
-
|
67
|
-
Enter: existCodeBlock
|
68
|
-
});
|
80
|
+
return defineKeymap({ Enter: existCodeBlock });
|
69
81
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
82
|
+
/**
|
83
|
+
* Exit a code block and insert a default block below if the cursor is at the
|
84
|
+
* end of the code block and the code block is ended with two new lines.
|
85
|
+
*/
|
86
|
+
const existCodeBlock = (state, dispatch) => {
|
87
|
+
if (!state.selection.empty) return false;
|
88
|
+
const { $head } = state.selection;
|
89
|
+
const parent = $head.parent;
|
90
|
+
if (parent.isTextblock && parent.type.spec.code && $head.parentOffset === parent.content.size && parent.textContent.endsWith("\n\n")) {
|
91
|
+
const grandParent = $head.node(-1);
|
92
|
+
const insertIndex = $head.indexAfter(-1);
|
93
|
+
const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex));
|
94
|
+
if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) return false;
|
95
|
+
if (dispatch) {
|
96
|
+
const { tr } = state;
|
97
|
+
tr.delete($head.pos - 2, $head.pos);
|
98
|
+
const pos = tr.selection.$head.after();
|
99
|
+
const node = type.createAndFill();
|
100
|
+
if (node) {
|
101
|
+
tr.replaceWith(pos, pos, node);
|
102
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
|
103
|
+
dispatch(tr.scrollIntoView());
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
return false;
|
97
109
|
};
|
98
110
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
111
|
+
//#endregion
|
112
|
+
//#region src/code-block/code-block-spec.ts
|
113
|
+
/**
|
114
|
+
* Defines the `codeBlock` node spec.
|
115
|
+
*
|
116
|
+
* @public
|
117
|
+
*/
|
103
118
|
function defineCodeBlockSpec() {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
119
|
+
return defineNodeSpec({
|
120
|
+
name: "codeBlock",
|
121
|
+
content: "text*",
|
122
|
+
group: "block",
|
123
|
+
code: true,
|
124
|
+
defining: true,
|
125
|
+
marks: "",
|
126
|
+
attrs: { language: {
|
127
|
+
default: "",
|
128
|
+
validate: "string"
|
129
|
+
} },
|
130
|
+
parseDOM: [{
|
131
|
+
tag: "pre",
|
132
|
+
preserveWhitespace: "full",
|
133
|
+
getAttrs: (node) => ({ language: node.getAttribute("data-language") || "" })
|
134
|
+
}],
|
135
|
+
toDOM(node) {
|
136
|
+
const attrs = node.attrs;
|
137
|
+
return [
|
138
|
+
"pre",
|
139
|
+
{ "data-language": attrs.language },
|
140
|
+
["code", 0]
|
141
|
+
];
|
142
|
+
}
|
143
|
+
});
|
126
144
|
}
|
127
145
|
|
128
|
-
|
146
|
+
//#endregion
|
147
|
+
//#region src/code-block/code-block.ts
|
148
|
+
/**
|
149
|
+
* Adds `codeBlock` nodes to the editor. This includes the following extensions:
|
150
|
+
*
|
151
|
+
* - {@link defineCodeBlockSpec}
|
152
|
+
* - {@link defineCodeBlockInputRule}
|
153
|
+
* - {@link defineCodeBlockEnterRule}
|
154
|
+
* - {@link defineCodeBlockKeymap}
|
155
|
+
* - {@link defineCodeBlockCommands}.
|
156
|
+
*
|
157
|
+
* @public
|
158
|
+
*/
|
129
159
|
function defineCodeBlock() {
|
130
|
-
|
131
|
-
defineCodeBlockSpec(),
|
132
|
-
defineCodeBlockInputRule(),
|
133
|
-
defineCodeBlockEnterRule(),
|
134
|
-
defineCodeBlockKeymap(),
|
135
|
-
defineCodeBlockCommands()
|
136
|
-
);
|
160
|
+
return union(defineCodeBlockSpec(), defineCodeBlockInputRule(), defineCodeBlockEnterRule(), defineCodeBlockKeymap(), defineCodeBlockCommands());
|
137
161
|
}
|
138
162
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
163
|
+
//#endregion
|
164
|
+
//#region src/code-block/code-block-highlight.ts
|
165
|
+
/**
|
166
|
+
* Adds syntax highlighting to code blocks. This function requires a `Parser`
|
167
|
+
* instance from the `prosemirror-highlight` package. See the
|
168
|
+
* [documentation](https://github.com/ocavue/prosemirror-highlight) for more
|
169
|
+
* information.
|
170
|
+
*
|
171
|
+
* @param options
|
172
|
+
*
|
173
|
+
* @public
|
174
|
+
*/
|
175
|
+
function defineCodeBlockHighlight({ parser }) {
|
176
|
+
return definePlugin(createHighlightPlugin({ parser }));
|
152
177
|
}
|
153
178
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// src/code-block/shiki-highlighter.ts
|
158
|
-
var loaded;
|
179
|
+
//#endregion
|
180
|
+
//#region src/code-block/shiki-highlighter.ts
|
181
|
+
let loaded;
|
159
182
|
async function load() {
|
160
|
-
|
161
|
-
|
183
|
+
const { createOrGetHighlighter: createOrGetHighlighter$1 } = await import("./shiki-highlighter-chunk.js");
|
184
|
+
loaded = createOrGetHighlighter$1;
|
162
185
|
}
|
163
186
|
function createOrGetHighlighter(options) {
|
164
|
-
|
165
|
-
|
166
|
-
}
|
167
|
-
return loaded(options);
|
187
|
+
if (!loaded) return { promise: load() };
|
188
|
+
return loaded(options);
|
168
189
|
}
|
169
190
|
|
170
|
-
|
191
|
+
//#endregion
|
192
|
+
//#region src/code-block/shiki-parser.ts
|
193
|
+
/**
|
194
|
+
* @internal
|
195
|
+
*/
|
171
196
|
function createLazyParser(highlighterOptions) {
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
parser = createParser(highlighter, {
|
184
|
-
theme: highlighterOptions.themes[0]
|
185
|
-
});
|
186
|
-
}
|
187
|
-
return parser(options);
|
188
|
-
};
|
197
|
+
let parser;
|
198
|
+
return function lazyParser(options) {
|
199
|
+
const language = options.language || "";
|
200
|
+
const { highlighter, promise } = createOrGetHighlighter({
|
201
|
+
...highlighterOptions,
|
202
|
+
langs: [language]
|
203
|
+
});
|
204
|
+
if (!highlighter) return promise;
|
205
|
+
if (!parser) parser = createParser(highlighter, { theme: highlighterOptions.themes[0] });
|
206
|
+
return parser(options);
|
207
|
+
};
|
189
208
|
}
|
190
209
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
210
|
+
//#endregion
|
211
|
+
//#region src/code-block/code-block-shiki.ts
|
212
|
+
/**
|
213
|
+
* Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
|
214
|
+
*
|
215
|
+
* It will set two CSS variables on the code block elements:
|
216
|
+
*
|
217
|
+
* - `--prosemirror-highlight`: sets text color
|
218
|
+
* - `--prosemirror-highlight-bg`: sets background color
|
219
|
+
*
|
220
|
+
* @param options - The options to configure the Shiki highlighter.
|
221
|
+
*
|
222
|
+
* @public
|
223
|
+
*/
|
224
|
+
function defineCodeBlockShiki({ themes = ["one-dark-pro"], langs = ["text"],...rest } = {}) {
|
225
|
+
const parser = createLazyParser({
|
226
|
+
themes,
|
227
|
+
langs,
|
228
|
+
...rest
|
229
|
+
});
|
230
|
+
return defineCodeBlockHighlight({ parser });
|
199
231
|
}
|
200
232
|
|
201
|
-
|
202
|
-
|
203
|
-
bundledLanguagesInfo,
|
204
|
-
bundledThemesInfo
|
205
|
-
} from "shiki";
|
206
|
-
export {
|
207
|
-
defineCodeBlock,
|
208
|
-
defineCodeBlockCommands,
|
209
|
-
defineCodeBlockEnterRule,
|
210
|
-
defineCodeBlockHighlight,
|
211
|
-
defineCodeBlockInputRule,
|
212
|
-
defineCodeBlockKeymap,
|
213
|
-
defineCodeBlockShiki,
|
214
|
-
defineCodeBlockSpec,
|
215
|
-
bundledLanguagesInfo as shikiBundledLanguagesInfo,
|
216
|
-
bundledThemesInfo as shikiBundledThemesInfo
|
217
|
-
};
|
233
|
+
//#endregion
|
234
|
+
export { defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
|
@@ -1,8 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
2
|
+
import { Attrs } from "@prosekit/pm/model";
|
3
|
+
|
4
|
+
//#region src/code/code-commands.d.ts
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
8
|
+
type CodeCommandsExtension = Extension<{
|
9
|
+
Commands: {
|
10
|
+
toggleCode: [];
|
11
|
+
};
|
12
|
+
}>;
|
13
|
+
/**
|
14
|
+
* @internal
|
15
|
+
*/
|
16
|
+
declare function defineCodeCommands(): CodeCommandsExtension;
|
17
|
+
//#endregion
|
18
|
+
//#region src/code/code-spec.d.ts
|
19
|
+
/**
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
type CodeSpecExtension = Extension<{
|
23
|
+
Marks: {
|
24
|
+
code: Attrs;
|
25
|
+
};
|
26
|
+
}>;
|
27
|
+
/**
|
28
|
+
* @internal
|
29
|
+
*/
|
30
|
+
declare function defineCodeSpec(): CodeSpecExtension;
|
31
|
+
//#endregion
|
32
|
+
//#region src/code/code.d.ts
|
33
|
+
/**
|
34
|
+
* @internal
|
35
|
+
*/
|
36
|
+
type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>;
|
37
|
+
/**
|
38
|
+
* @public
|
39
|
+
*/
|
40
|
+
declare function defineCode(): CodeExtension;
|
41
|
+
//#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
|
+
export { CodeCommandsExtension, CodeExtension, CodeSpecExtension, defineCode, defineCodeCommands, defineCodeInputRule, defineCodeKeymap, defineCodeSpec };
|
@@ -1,71 +1,59 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from "./chunk-I2UMHK3L.js";
|
1
|
+
import { defineMarkInputRule } from "./input-rule-Gji4N7Oe.js";
|
2
|
+
import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
// src/code/code-commands.ts
|
11
|
-
import {
|
12
|
-
defineCommands,
|
13
|
-
toggleMark
|
14
|
-
} from "@prosekit/core";
|
4
|
+
//#region src/code/code-commands.ts
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
15
8
|
function defineCodeCommands() {
|
16
|
-
|
17
|
-
toggleCode: () => toggleMark({ type: "code" })
|
18
|
-
});
|
9
|
+
return defineCommands({ toggleCode: () => toggleMark({ type: "code" }) });
|
19
10
|
}
|
20
11
|
|
21
|
-
|
22
|
-
|
12
|
+
//#endregion
|
13
|
+
//#region src/code/code-input-rule.ts
|
14
|
+
/**
|
15
|
+
* @internal
|
16
|
+
*/
|
23
17
|
function defineCodeInputRule() {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
return defineMarkInputRule({
|
19
|
+
regex: canUseRegexLookbehind() ? /(?<=\s|^)`([^\s`]|[^\s`][^`]*[^\s`])`$/ : /`([^\s`]|[^\s`][^`]*[^\s`])`$/,
|
20
|
+
type: "code"
|
21
|
+
});
|
28
22
|
}
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
//#endregion
|
25
|
+
//#region src/code/code-keymap.ts
|
26
|
+
/**
|
27
|
+
* @internal
|
28
|
+
*/
|
35
29
|
function defineCodeKeymap() {
|
36
|
-
|
37
|
-
"Mod-e": toggleMark2({ type: "code" })
|
38
|
-
});
|
30
|
+
return defineKeymap({ "Mod-e": toggleMark({ type: "code" }) });
|
39
31
|
}
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
//#endregion
|
34
|
+
//#region src/code/code-spec.ts
|
35
|
+
/**
|
36
|
+
* @internal
|
37
|
+
*/
|
45
38
|
function defineCodeSpec() {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
return defineMarkSpec({
|
40
|
+
name: "code",
|
41
|
+
parseDOM: [{ tag: "code" }],
|
42
|
+
code: true,
|
43
|
+
toDOM() {
|
44
|
+
return ["code", 0];
|
45
|
+
}
|
46
|
+
});
|
54
47
|
}
|
55
48
|
|
56
|
-
|
49
|
+
//#endregion
|
50
|
+
//#region src/code/code.ts
|
51
|
+
/**
|
52
|
+
* @public
|
53
|
+
*/
|
57
54
|
function defineCode() {
|
58
|
-
|
59
|
-
defineCodeSpec(),
|
60
|
-
defineCodeCommands(),
|
61
|
-
defineCodeKeymap(),
|
62
|
-
defineCodeInputRule()
|
63
|
-
);
|
55
|
+
return union(defineCodeSpec(), defineCodeCommands(), defineCodeKeymap(), defineCodeInputRule());
|
64
56
|
}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
defineCodeInputRule,
|
69
|
-
defineCodeKeymap,
|
70
|
-
defineCodeSpec
|
71
|
-
};
|
57
|
+
|
58
|
+
//#endregion
|
59
|
+
export { defineCode, defineCodeCommands, defineCodeInputRule, defineCodeKeymap, defineCodeSpec };
|
@@ -1,4 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import { NodeJSON, PlainExtension, StepJSON } from "@prosekit/core";
|
2
|
+
import { Transaction } from "@prosekit/pm/state";
|
3
|
+
import { ProseMirrorNode } from "@prosekit/pm/model";
|
4
|
+
|
5
|
+
//#region src/commit/index.d.ts
|
6
|
+
|
7
|
+
/**
|
8
|
+
* A JSON representation of a commit.
|
9
|
+
*/
|
10
|
+
interface Commit {
|
11
|
+
/**
|
12
|
+
* The current doc node in the JSON format
|
13
|
+
*/
|
14
|
+
doc: NodeJSON;
|
15
|
+
/**
|
16
|
+
* The parent node in the JSON format
|
17
|
+
*/
|
18
|
+
parent: NodeJSON;
|
19
|
+
/**
|
20
|
+
* An array of steps in the JSON format that transform the parent node to the
|
21
|
+
* current doc node.
|
22
|
+
*/
|
23
|
+
steps: StepJSON[];
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Define an extension to display the changes from the given commit in the editor.
|
27
|
+
*/
|
28
|
+
declare function defineCommitViewer(commit: Commit): PlainExtension;
|
29
|
+
declare class CommitRecorder {
|
30
|
+
private parent;
|
31
|
+
private doc;
|
32
|
+
private steps;
|
33
|
+
/**
|
34
|
+
* Return a commit object including all changes since the last commit. `null`
|
35
|
+
* will be returned if there is no change.
|
36
|
+
*/
|
37
|
+
commit(): Commit | null;
|
38
|
+
/**
|
39
|
+
* @internal
|
40
|
+
*/
|
41
|
+
init(doc: ProseMirrorNode): void;
|
42
|
+
/**
|
43
|
+
* @internal
|
44
|
+
*/
|
45
|
+
apply(tr: Transaction): void;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Define an extension that can record the changes in the editor.
|
49
|
+
*/
|
50
|
+
declare function defineCommitRecorder(commitRecorder: CommitRecorder): PlainExtension;
|
51
|
+
//#endregion
|
52
|
+
export { Commit, CommitRecorder, defineCommitRecorder, defineCommitViewer };
|