@prosekit/extensions 0.7.14 → 0.7.16
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/_tsup-dts-rollup.d.ts +60 -26
- package/dist/prosekit-extensions-blockquote.d.ts +5 -2
- package/dist/prosekit-extensions-blockquote.js +63 -9
- package/dist/prosekit-extensions-code-block.js +15 -42
- package/dist/shiki-highlighter-chunk-C5VVQ2TD.js +50 -0
- package/package.json +5 -5
- package/dist/shiki-import-UFUFVKJ2.js +0 -5
@@ -2,6 +2,7 @@ import { Attrs } from '@prosekit/pm/model';
|
|
2
2
|
import { Attrs as Attrs_2 } from 'prosemirror-model';
|
3
3
|
import type { Awareness } from 'y-protocols/awareness';
|
4
4
|
import { BaseCommandsExtension } from '@prosekit/core';
|
5
|
+
import type { BundledHighlighterOptions } from 'shiki';
|
5
6
|
import { BundledLanguage } from 'shiki';
|
6
7
|
import { BundledLanguageInfo } from 'shiki';
|
7
8
|
import { bundledLanguagesInfo } from 'shiki';
|
@@ -22,7 +23,6 @@ import { ExtractMarkActions } from '@prosekit/core';
|
|
22
23
|
import { ExtractNodeActions } from '@prosekit/core';
|
23
24
|
import { FindParentNodeResult } from '@prosekit/core';
|
24
25
|
import { GapCursor } from 'prosemirror-gapcursor';
|
25
|
-
import { getSingletonHighlighter } from 'shiki/bundle/full';
|
26
26
|
import type { Highlighter } from 'shiki';
|
27
27
|
import { HistoryExtension } from '@prosekit/core';
|
28
28
|
import { IndentListOptions } from 'prosemirror-flat-list';
|
@@ -90,19 +90,31 @@ declare class AutocompleteRule {
|
|
90
90
|
export { AutocompleteRule }
|
91
91
|
export { AutocompleteRule as AutocompleteRule_alias_1 }
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
declare type BlockquoteCommandsExtension = Extension<{
|
94
|
+
Commands: {
|
95
|
+
setBlockquote: [];
|
96
|
+
insertBlockquote: [];
|
97
|
+
toggleBlockquote: [];
|
98
|
+
};
|
99
|
+
}>;
|
100
|
+
export { BlockquoteCommandsExtension }
|
101
|
+
export { BlockquoteCommandsExtension as BlockquoteCommandsExtension_alias_1 }
|
97
102
|
|
98
103
|
/**
|
99
104
|
* @internal
|
100
105
|
*/
|
101
|
-
export declare type
|
106
|
+
export declare type BlockquoteExtension = Union<[
|
107
|
+
BlockquoteSpecExtension,
|
108
|
+
BlockquoteCommandsExtension
|
109
|
+
]>;
|
110
|
+
|
111
|
+
declare type BlockquoteSpecExtension = Extension<{
|
102
112
|
Nodes: {
|
103
113
|
blockquote: Attrs;
|
104
114
|
};
|
105
115
|
}>;
|
116
|
+
export { BlockquoteSpecExtension }
|
117
|
+
export { BlockquoteSpecExtension as BlockquoteSpecExtension_alias_1 }
|
106
118
|
|
107
119
|
/**
|
108
120
|
* @internal
|
@@ -199,28 +211,28 @@ export { CodeBlockHighlightOptions }
|
|
199
211
|
export { CodeBlockHighlightOptions as CodeBlockHighlightOptions_alias_1 }
|
200
212
|
|
201
213
|
/**
|
214
|
+
* The options to configure the Shiki highlighter.
|
215
|
+
*
|
202
216
|
* @public
|
203
217
|
*/
|
204
|
-
export declare interface CodeBlockShikiOptions {
|
218
|
+
export declare interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {
|
205
219
|
/**
|
206
|
-
* A list of
|
220
|
+
* A list of Shiki themes to pre-load. The first theme in the list will be
|
207
221
|
* used to render the code block.
|
208
222
|
*
|
209
223
|
* @default ['one-dark-pro']
|
210
224
|
*/
|
211
225
|
themes?: BundledTheme[];
|
212
226
|
/**
|
213
|
-
* A list of
|
227
|
+
* A list of Shiki languages to pre-load.
|
214
228
|
*
|
215
229
|
* @default ['text']
|
216
230
|
*/
|
217
231
|
langs?: (BundledLanguage | SpecialLanguage)[];
|
218
232
|
/**
|
219
|
-
*
|
220
|
-
*
|
221
|
-
* @example { 'my-lang': 'javascript' }
|
233
|
+
* The RegExp engine to use. By default, the JavaScript engine is used.
|
222
234
|
*/
|
223
|
-
|
235
|
+
engine?: ShikiHighlighterOptions['engine'];
|
224
236
|
}
|
225
237
|
|
226
238
|
/**
|
@@ -309,6 +321,10 @@ export declare function createLazyParser(highlighterOptions: HighlighterOptions)
|
|
309
321
|
*/
|
310
322
|
export declare function createMarkInputRule({ regex, type, attrs, }: MarkInputRuleOptions): InputRule;
|
311
323
|
|
324
|
+
export declare function createOrGetHighlighter(options: HighlighterOptions): HighlighterResult;
|
325
|
+
|
326
|
+
export declare function createOrGetHighlighter_alias_1(options: HighlighterOptions): HighlighterResult;
|
327
|
+
|
312
328
|
export { DedentListOptions }
|
313
329
|
|
314
330
|
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
@@ -326,13 +342,31 @@ export declare function defineAutocomplete(rule: AutocompleteRule): Extension;
|
|
326
342
|
*/
|
327
343
|
export declare function defineBlockquote(): BlockquoteExtension;
|
328
344
|
|
345
|
+
/**
|
346
|
+
* @internal
|
347
|
+
*/
|
348
|
+
declare function defineBlockquoteCommands(): BlockquoteCommandsExtension;
|
349
|
+
export { defineBlockquoteCommands }
|
350
|
+
export { defineBlockquoteCommands as defineBlockquoteCommands_alias_1 }
|
351
|
+
|
329
352
|
/**
|
330
353
|
* Wraps the text block in a blockquote when `>` is typed at the start of a new
|
331
354
|
* line followed by a space.
|
332
355
|
*/
|
333
|
-
|
356
|
+
declare function defineBlockquoteInputRule(): PlainExtension;
|
357
|
+
export { defineBlockquoteInputRule }
|
358
|
+
export { defineBlockquoteInputRule as defineBlockquoteInputRule_alias_1 }
|
334
359
|
|
335
|
-
|
360
|
+
/**
|
361
|
+
* @internal
|
362
|
+
*/
|
363
|
+
declare function defineBlockquoteKeymap(): PlainExtension;
|
364
|
+
export { defineBlockquoteKeymap }
|
365
|
+
export { defineBlockquoteKeymap as defineBlockquoteKeymap_alias_1 }
|
366
|
+
|
367
|
+
declare function defineBlockquoteSpec(): BlockquoteSpecExtension;
|
368
|
+
export { defineBlockquoteSpec }
|
369
|
+
export { defineBlockquoteSpec as defineBlockquoteSpec_alias_1 }
|
336
370
|
|
337
371
|
/**
|
338
372
|
* @public
|
@@ -426,13 +460,13 @@ export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
|
|
426
460
|
export declare function defineCodeBlockKeymap(): PlainExtension;
|
427
461
|
|
428
462
|
/**
|
429
|
-
* Adds syntax highlighting to code blocks using the [
|
463
|
+
* Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
|
430
464
|
*
|
431
|
-
* @param options
|
465
|
+
* @param options - The options to configure the Shiki highlighter.
|
432
466
|
*
|
433
467
|
* @public
|
434
468
|
*/
|
435
|
-
declare function defineCodeBlockShiki({ themes, langs,
|
469
|
+
declare function defineCodeBlockShiki({ themes, langs, ...rest }?: CodeBlockShikiOptions): Extension;
|
436
470
|
export { defineCodeBlockShiki }
|
437
471
|
export { defineCodeBlockShiki as defineCodeBlockShiki_alias_1 }
|
438
472
|
|
@@ -1124,8 +1158,6 @@ export declare function getCheckRanges(transactions: readonly Transaction[], old
|
|
1124
1158
|
|
1125
1159
|
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
1126
1160
|
|
1127
|
-
export { getSingletonHighlighter }
|
1128
|
-
|
1129
1161
|
export declare function getTrMeta(tr: Transaction): PredictionPluginState;
|
1130
1162
|
|
1131
1163
|
declare interface HeadingAttrs {
|
@@ -1166,13 +1198,14 @@ declare type HeadingSpecExtension = Extension<{
|
|
1166
1198
|
export { HeadingSpecExtension }
|
1167
1199
|
export { HeadingSpecExtension as HeadingSpecExtension_alias_1 }
|
1168
1200
|
|
1169
|
-
|
1201
|
+
declare interface HighlighterOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs'> {
|
1170
1202
|
themes: BundledTheme[];
|
1171
1203
|
langs: (BundledLanguage | SpecialLanguage)[];
|
1172
|
-
|
1173
|
-
}
|
1204
|
+
}
|
1205
|
+
export { HighlighterOptions }
|
1206
|
+
export { HighlighterOptions as HighlighterOptions_alias_1 }
|
1174
1207
|
|
1175
|
-
declare type HighlighterResult = {
|
1208
|
+
export declare type HighlighterResult = {
|
1176
1209
|
highlighter: Highlighter;
|
1177
1210
|
promise?: undefined;
|
1178
1211
|
} | {
|
@@ -1532,8 +1565,6 @@ export declare interface PredictionPluginState {
|
|
1532
1565
|
} | null;
|
1533
1566
|
}
|
1534
1567
|
|
1535
|
-
export declare function prepareHighlighter(options: HighlighterOptions): HighlighterResult;
|
1536
|
-
|
1537
1568
|
/**
|
1538
1569
|
* @example
|
1539
1570
|
*
|
@@ -1790,6 +1821,9 @@ export declare function setupTestFromExtension<E extends Extension>(extension: E
|
|
1790
1821
|
m: ExtractMarkActions<E>;
|
1791
1822
|
};
|
1792
1823
|
|
1824
|
+
export declare interface ShikiHighlighterOptions extends BundledHighlighterOptions<BundledLanguage, BundledTheme> {
|
1825
|
+
}
|
1826
|
+
|
1793
1827
|
/**
|
1794
1828
|
* @internal
|
1795
1829
|
*/
|
@@ -1,5 +1,8 @@
|
|
1
|
+
export { defineBlockquote } from './_tsup-dts-rollup';
|
2
|
+
export { BlockquoteExtension } from './_tsup-dts-rollup';
|
1
3
|
export { defineBlockquoteSpec } from './_tsup-dts-rollup';
|
2
4
|
export { defineBlockquoteInputRule } from './_tsup-dts-rollup';
|
3
|
-
export {
|
5
|
+
export { defineBlockquoteCommands_alias_1 as defineBlockquoteCommands } from './_tsup-dts-rollup';
|
6
|
+
export { defineBlockquoteKeymap } from './_tsup-dts-rollup';
|
4
7
|
export { BlockquoteSpecExtension } from './_tsup-dts-rollup';
|
5
|
-
export {
|
8
|
+
export { BlockquoteCommandsExtension_alias_1 as BlockquoteCommandsExtension } from './_tsup-dts-rollup';
|
@@ -3,10 +3,61 @@ import {
|
|
3
3
|
} from "./chunk-LAQZC3ZM.js";
|
4
4
|
|
5
5
|
// src/blockquote/index.ts
|
6
|
+
import { union } from "@prosekit/core";
|
7
|
+
|
8
|
+
// src/blockquote/commands.ts
|
6
9
|
import {
|
7
|
-
|
8
|
-
|
10
|
+
defineCommands,
|
11
|
+
insertNode,
|
12
|
+
toggleWrap,
|
13
|
+
wrap
|
9
14
|
} from "@prosekit/core";
|
15
|
+
function defineBlockquoteCommands() {
|
16
|
+
return defineCommands({
|
17
|
+
setBlockquote: () => {
|
18
|
+
return wrap({ type: "blockquote" });
|
19
|
+
},
|
20
|
+
insertBlockquote: () => {
|
21
|
+
return insertNode({ type: "blockquote" });
|
22
|
+
},
|
23
|
+
toggleBlockquote: () => {
|
24
|
+
return toggleWrap({ type: "blockquote" });
|
25
|
+
}
|
26
|
+
});
|
27
|
+
}
|
28
|
+
|
29
|
+
// src/blockquote/input-rule.ts
|
30
|
+
function defineBlockquoteInputRule() {
|
31
|
+
return defineWrappingInputRule({
|
32
|
+
regex: /^>\s/,
|
33
|
+
type: "blockquote"
|
34
|
+
});
|
35
|
+
}
|
36
|
+
|
37
|
+
// src/blockquote/keymap.ts
|
38
|
+
import { defineKeymap, isAtBlockStart, toggleWrap as toggleWrap2 } from "@prosekit/core";
|
39
|
+
import { joinBackward } from "@prosekit/pm/commands";
|
40
|
+
function toggleBlockquoteKeybinding() {
|
41
|
+
return toggleWrap2({ type: "blockquote" });
|
42
|
+
}
|
43
|
+
function backspaceUnsetBlockquote() {
|
44
|
+
return (state, dispatch, view) => {
|
45
|
+
const $pos = isAtBlockStart(state, view);
|
46
|
+
if (($pos == null ? void 0 : $pos.node(-1).type.name) === "blockquote") {
|
47
|
+
return joinBackward(state, dispatch, view);
|
48
|
+
}
|
49
|
+
return false;
|
50
|
+
};
|
51
|
+
}
|
52
|
+
function defineBlockquoteKeymap() {
|
53
|
+
return defineKeymap({
|
54
|
+
"mod-shift-b": toggleBlockquoteKeybinding(),
|
55
|
+
Backspace: backspaceUnsetBlockquote()
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
// src/blockquote/spec.ts
|
60
|
+
import { defineNodeSpec } from "@prosekit/core";
|
10
61
|
function defineBlockquoteSpec() {
|
11
62
|
return defineNodeSpec({
|
12
63
|
name: "blockquote",
|
@@ -19,17 +70,20 @@ function defineBlockquoteSpec() {
|
|
19
70
|
}
|
20
71
|
});
|
21
72
|
}
|
22
|
-
|
23
|
-
|
24
|
-
regex: /^>\s/,
|
25
|
-
type: "blockquote"
|
26
|
-
});
|
27
|
-
}
|
73
|
+
|
74
|
+
// src/blockquote/index.ts
|
28
75
|
function defineBlockquote() {
|
29
|
-
return union(
|
76
|
+
return union(
|
77
|
+
defineBlockquoteSpec(),
|
78
|
+
defineBlockquoteInputRule(),
|
79
|
+
defineBlockquoteCommands(),
|
80
|
+
defineBlockquoteKeymap()
|
81
|
+
);
|
30
82
|
}
|
31
83
|
export {
|
32
84
|
defineBlockquote,
|
85
|
+
defineBlockquoteCommands,
|
33
86
|
defineBlockquoteInputRule,
|
87
|
+
defineBlockquoteKeymap,
|
34
88
|
defineBlockquoteSpec
|
35
89
|
};
|
@@ -142,59 +142,32 @@ function defineCodeBlockHighlight({
|
|
142
142
|
import { createParser } from "prosemirror-highlight/shiki";
|
143
143
|
|
144
144
|
// src/code-block/shiki-highlighter.ts
|
145
|
-
var
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
const { getSingletonHighlighter } = await import("./shiki-import-UFUFVKJ2.js");
|
150
|
-
if (!highlighter) {
|
151
|
-
highlighter = await getSingletonHighlighter(options);
|
152
|
-
}
|
153
|
-
}
|
154
|
-
async function loadLanguages(langs) {
|
155
|
-
for (const lang of langs) {
|
156
|
-
if (!highlighter) break;
|
157
|
-
await highlighter.loadLanguage(lang);
|
158
|
-
loadedLangs.add(lang);
|
159
|
-
}
|
145
|
+
var loaded;
|
146
|
+
async function load() {
|
147
|
+
const { createOrGetHighlighter: createOrGetHighlighter2 } = await import("./shiki-highlighter-chunk-C5VVQ2TD.js");
|
148
|
+
loaded = createOrGetHighlighter2;
|
160
149
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
await highlighter.loadTheme(theme);
|
165
|
-
loadedThemes.add(theme);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
function prepareHighlighter(options) {
|
169
|
-
if (!highlighter) {
|
170
|
-
return { promise: createHighlighter(options) };
|
171
|
-
}
|
172
|
-
const langs = options.langs.filter((lang) => !loadedLangs.has(lang));
|
173
|
-
if (langs.length > 0) {
|
174
|
-
return { promise: loadLanguages(langs) };
|
175
|
-
}
|
176
|
-
const themes = options.themes.filter((theme) => !loadedThemes.has(theme));
|
177
|
-
if (themes.length > 0) {
|
178
|
-
return { promise: loadThemes(themes) };
|
150
|
+
function createOrGetHighlighter(options) {
|
151
|
+
if (!loaded) {
|
152
|
+
return { promise: load() };
|
179
153
|
}
|
180
|
-
return
|
154
|
+
return loaded(options);
|
181
155
|
}
|
182
156
|
|
183
157
|
// src/code-block/shiki-parser.ts
|
184
158
|
function createLazyParser(highlighterOptions) {
|
185
159
|
let parser;
|
186
|
-
prepareHighlighter(highlighterOptions);
|
187
160
|
return function lazyParser(options) {
|
188
161
|
const language = options.language || "";
|
189
|
-
const { highlighter
|
190
|
-
|
191
|
-
|
162
|
+
const { highlighter, promise } = createOrGetHighlighter({
|
163
|
+
...highlighterOptions,
|
164
|
+
langs: [language]
|
192
165
|
});
|
193
|
-
if (!
|
166
|
+
if (!highlighter) {
|
194
167
|
return promise;
|
195
168
|
}
|
196
169
|
if (!parser) {
|
197
|
-
parser = createParser(
|
170
|
+
parser = createParser(highlighter, {
|
198
171
|
theme: highlighterOptions.themes[0]
|
199
172
|
});
|
200
173
|
}
|
@@ -206,9 +179,9 @@ function createLazyParser(highlighterOptions) {
|
|
206
179
|
function defineCodeBlockShiki({
|
207
180
|
themes = ["one-dark-pro"],
|
208
181
|
langs = ["text"],
|
209
|
-
|
182
|
+
...rest
|
210
183
|
} = {}) {
|
211
|
-
const parser = createLazyParser({ themes, langs,
|
184
|
+
const parser = createLazyParser({ themes, langs, ...rest });
|
212
185
|
return defineCodeBlockHighlight({ parser });
|
213
186
|
}
|
214
187
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// src/code-block/shiki-highlighter-chunk.ts
|
2
|
+
import {
|
3
|
+
createHighlighter,
|
4
|
+
createJavaScriptRegexEngine
|
5
|
+
} from "shiki/bundle/full";
|
6
|
+
var highlighter;
|
7
|
+
var loadedLangs = /* @__PURE__ */ new Set();
|
8
|
+
var loadedThemes = /* @__PURE__ */ new Set();
|
9
|
+
async function createAndCacheHighlighter({
|
10
|
+
...options
|
11
|
+
}) {
|
12
|
+
if (!highlighter) {
|
13
|
+
if (!options.engine) {
|
14
|
+
const engine = createJavaScriptRegexEngine();
|
15
|
+
options.engine = engine;
|
16
|
+
}
|
17
|
+
highlighter = await createHighlighter(options);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
async function loadLanguages(langs) {
|
21
|
+
for (const lang of langs) {
|
22
|
+
if (!highlighter) break;
|
23
|
+
await highlighter.loadLanguage(lang);
|
24
|
+
loadedLangs.add(lang);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async function loadThemes(themes) {
|
28
|
+
for (const theme of themes) {
|
29
|
+
if (!highlighter) break;
|
30
|
+
await highlighter.loadTheme(theme);
|
31
|
+
loadedThemes.add(theme);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
function createOrGetHighlighter(options) {
|
35
|
+
if (!highlighter) {
|
36
|
+
return { promise: createAndCacheHighlighter(options) };
|
37
|
+
}
|
38
|
+
const langs = options.langs.filter((lang) => !loadedLangs.has(lang));
|
39
|
+
if (langs.length > 0) {
|
40
|
+
return { promise: loadLanguages(langs) };
|
41
|
+
}
|
42
|
+
const themes = options.themes.filter((theme) => !loadedThemes.has(theme));
|
43
|
+
if (themes.length > 0) {
|
44
|
+
return { promise: loadThemes(themes) };
|
45
|
+
}
|
46
|
+
return { highlighter };
|
47
|
+
}
|
48
|
+
export {
|
49
|
+
createOrGetHighlighter
|
50
|
+
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.7.
|
4
|
+
"version": "0.7.16",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -209,8 +209,8 @@
|
|
209
209
|
"prosemirror-highlight": "^0.8.0",
|
210
210
|
"prosemirror-search": "^1.0.0",
|
211
211
|
"prosemirror-tables": "^1.5.0",
|
212
|
-
"shiki": "^1.
|
213
|
-
"@prosekit/core": "^0.7.
|
212
|
+
"shiki": "^1.15.2",
|
213
|
+
"@prosekit/core": "^0.7.11",
|
214
214
|
"@prosekit/pm": "^0.1.8"
|
215
215
|
},
|
216
216
|
"peerDependencies": {
|
@@ -236,10 +236,10 @@
|
|
236
236
|
"devDependencies": {
|
237
237
|
"@vitest/browser": "^2.0.5",
|
238
238
|
"just-pick": "^4.2.0",
|
239
|
-
"loro-crdt": "^0.16.
|
239
|
+
"loro-crdt": "^0.16.10",
|
240
240
|
"loro-prosemirror": "^0.0.7",
|
241
241
|
"tsup": "^8.2.4",
|
242
|
-
"type-fest": "^4.
|
242
|
+
"type-fest": "^4.26.0",
|
243
243
|
"typescript": "^5.5.4",
|
244
244
|
"vitest": "^2.0.5",
|
245
245
|
"y-prosemirror": "^1.2.12",
|