@prosekit/extensions 0.7.14 → 0.7.15
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.
@@ -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';
|
@@ -199,28 +199,28 @@ export { CodeBlockHighlightOptions }
|
|
199
199
|
export { CodeBlockHighlightOptions as CodeBlockHighlightOptions_alias_1 }
|
200
200
|
|
201
201
|
/**
|
202
|
+
* The options to configure the Shiki highlighter.
|
203
|
+
*
|
202
204
|
* @public
|
203
205
|
*/
|
204
|
-
export declare interface CodeBlockShikiOptions {
|
206
|
+
export declare interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {
|
205
207
|
/**
|
206
|
-
* A list of
|
208
|
+
* A list of Shiki themes to pre-load. The first theme in the list will be
|
207
209
|
* used to render the code block.
|
208
210
|
*
|
209
211
|
* @default ['one-dark-pro']
|
210
212
|
*/
|
211
213
|
themes?: BundledTheme[];
|
212
214
|
/**
|
213
|
-
* A list of
|
215
|
+
* A list of Shiki languages to pre-load.
|
214
216
|
*
|
215
217
|
* @default ['text']
|
216
218
|
*/
|
217
219
|
langs?: (BundledLanguage | SpecialLanguage)[];
|
218
220
|
/**
|
219
|
-
*
|
220
|
-
*
|
221
|
-
* @example { 'my-lang': 'javascript' }
|
221
|
+
* The RegExp engine to use. By default, the JavaScript engine is used.
|
222
222
|
*/
|
223
|
-
|
223
|
+
engine?: ShikiHighlighterOptions['engine'];
|
224
224
|
}
|
225
225
|
|
226
226
|
/**
|
@@ -309,6 +309,10 @@ export declare function createLazyParser(highlighterOptions: HighlighterOptions)
|
|
309
309
|
*/
|
310
310
|
export declare function createMarkInputRule({ regex, type, attrs, }: MarkInputRuleOptions): InputRule;
|
311
311
|
|
312
|
+
export declare function createOrGetHighlighter(options: HighlighterOptions): HighlighterResult;
|
313
|
+
|
314
|
+
export declare function createOrGetHighlighter_alias_1(options: HighlighterOptions): HighlighterResult;
|
315
|
+
|
312
316
|
export { DedentListOptions }
|
313
317
|
|
314
318
|
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
@@ -426,13 +430,13 @@ export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
|
|
426
430
|
export declare function defineCodeBlockKeymap(): PlainExtension;
|
427
431
|
|
428
432
|
/**
|
429
|
-
* Adds syntax highlighting to code blocks using the [
|
433
|
+
* Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
|
430
434
|
*
|
431
|
-
* @param options
|
435
|
+
* @param options - The options to configure the Shiki highlighter.
|
432
436
|
*
|
433
437
|
* @public
|
434
438
|
*/
|
435
|
-
declare function defineCodeBlockShiki({ themes, langs,
|
439
|
+
declare function defineCodeBlockShiki({ themes, langs, ...rest }?: CodeBlockShikiOptions): Extension;
|
436
440
|
export { defineCodeBlockShiki }
|
437
441
|
export { defineCodeBlockShiki as defineCodeBlockShiki_alias_1 }
|
438
442
|
|
@@ -1124,8 +1128,6 @@ export declare function getCheckRanges(transactions: readonly Transaction[], old
|
|
1124
1128
|
|
1125
1129
|
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
1126
1130
|
|
1127
|
-
export { getSingletonHighlighter }
|
1128
|
-
|
1129
1131
|
export declare function getTrMeta(tr: Transaction): PredictionPluginState;
|
1130
1132
|
|
1131
1133
|
declare interface HeadingAttrs {
|
@@ -1166,13 +1168,14 @@ declare type HeadingSpecExtension = Extension<{
|
|
1166
1168
|
export { HeadingSpecExtension }
|
1167
1169
|
export { HeadingSpecExtension as HeadingSpecExtension_alias_1 }
|
1168
1170
|
|
1169
|
-
|
1171
|
+
declare interface HighlighterOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs'> {
|
1170
1172
|
themes: BundledTheme[];
|
1171
1173
|
langs: (BundledLanguage | SpecialLanguage)[];
|
1172
|
-
|
1173
|
-
}
|
1174
|
+
}
|
1175
|
+
export { HighlighterOptions }
|
1176
|
+
export { HighlighterOptions as HighlighterOptions_alias_1 }
|
1174
1177
|
|
1175
|
-
declare type HighlighterResult = {
|
1178
|
+
export declare type HighlighterResult = {
|
1176
1179
|
highlighter: Highlighter;
|
1177
1180
|
promise?: undefined;
|
1178
1181
|
} | {
|
@@ -1532,8 +1535,6 @@ export declare interface PredictionPluginState {
|
|
1532
1535
|
} | null;
|
1533
1536
|
}
|
1534
1537
|
|
1535
|
-
export declare function prepareHighlighter(options: HighlighterOptions): HighlighterResult;
|
1536
|
-
|
1537
1538
|
/**
|
1538
1539
|
* @example
|
1539
1540
|
*
|
@@ -1790,6 +1791,9 @@ export declare function setupTestFromExtension<E extends Extension>(extension: E
|
|
1790
1791
|
m: ExtractMarkActions<E>;
|
1791
1792
|
};
|
1792
1793
|
|
1794
|
+
export declare interface ShikiHighlighterOptions extends BundledHighlighterOptions<BundledLanguage, BundledTheme> {
|
1795
|
+
}
|
1796
|
+
|
1793
1797
|
/**
|
1794
1798
|
* @internal
|
1795
1799
|
*/
|
@@ -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.15",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -209,7 +209,7 @@
|
|
209
209
|
"prosemirror-highlight": "^0.8.0",
|
210
210
|
"prosemirror-search": "^1.0.0",
|
211
211
|
"prosemirror-tables": "^1.5.0",
|
212
|
-
"shiki": "^1.
|
212
|
+
"shiki": "^1.15.2",
|
213
213
|
"@prosekit/core": "^0.7.10",
|
214
214
|
"@prosekit/pm": "^0.1.8"
|
215
215
|
},
|