@prosekit/extensions 0.2.4 → 0.2.5
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.
@@ -125,6 +125,10 @@ toggleCode: [];
|
|
125
125
|
export declare function defineCodeBlock(): Extension< {
|
126
126
|
NODES: "codeBlock";
|
127
127
|
COMMAND_ARGS: {
|
128
|
+
setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
129
|
+
insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
130
|
+
toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
131
|
+
setCodeBlockAttrs: [attrs: CodeBlockAttrs];
|
128
132
|
setCodeBlockLanguage: [language: string];
|
129
133
|
};
|
130
134
|
}>;
|
@@ -136,6 +140,10 @@ setCodeBlockLanguage: [language: string];
|
|
136
140
|
*/
|
137
141
|
declare function defineCodeBlockCommands(): Extension< {
|
138
142
|
COMMAND_ARGS: {
|
143
|
+
setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
144
|
+
insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
145
|
+
toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
146
|
+
setCodeBlockAttrs: [attrs: CodeBlockAttrs];
|
139
147
|
setCodeBlockLanguage: [language: string];
|
140
148
|
};
|
141
149
|
}>;
|
@@ -188,7 +196,7 @@ declare function defineCodeBlockShikiji(options?: {
|
|
188
196
|
/**
|
189
197
|
* The shikiji theme to use.
|
190
198
|
*
|
191
|
-
* @default '
|
199
|
+
* @default 'one-dark-pro'
|
192
200
|
*/
|
193
201
|
theme?: BundledTheme;
|
194
202
|
}): Extension;
|
@@ -6,19 +6,33 @@ import {
|
|
6
6
|
import { union } from "@prosekit/core";
|
7
7
|
|
8
8
|
// src/code-block/code-block-commands.ts
|
9
|
-
import {
|
9
|
+
import {
|
10
|
+
defineCommands,
|
11
|
+
insertNode,
|
12
|
+
setBlockType,
|
13
|
+
setNodeAttrs,
|
14
|
+
toggleNode
|
15
|
+
} from "@prosekit/core";
|
10
16
|
function defineCodeBlockCommands() {
|
11
17
|
return defineCommands({
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
setCodeBlock: (attrs) => {
|
19
|
+
return setBlockType({ type: "codeBlock", attrs });
|
20
|
+
},
|
21
|
+
insertCodeBlock: (attrs) => {
|
22
|
+
return insertNode({ type: "codeBlock", attrs });
|
23
|
+
},
|
24
|
+
toggleCodeBlock: (attrs) => {
|
25
|
+
return toggleNode({ type: "codeBlock", attrs });
|
26
|
+
},
|
27
|
+
setCodeBlockAttrs: (attrs) => {
|
28
|
+
return setNodeAttrs({ type: "codeBlock", attrs });
|
29
|
+
},
|
30
|
+
/**
|
31
|
+
* @deprecated Use `setCodeBlockAttrs` instead.
|
32
|
+
*/
|
33
|
+
setCodeBlockLanguage: (language) => {
|
34
|
+
const attrs = { language };
|
35
|
+
return setNodeAttrs({ type: "codeBlock", attrs });
|
22
36
|
}
|
23
37
|
});
|
24
38
|
}
|
@@ -176,36 +190,52 @@ var existCodeBlock = (state, dispatch) => {
|
|
176
190
|
};
|
177
191
|
|
178
192
|
// src/code-block/code-block-shikiji.ts
|
193
|
+
import { ProseKitError } from "@prosekit/core";
|
179
194
|
import { createParser } from "prosemirror-highlight/shikiji";
|
195
|
+
async function importGetHighlighter() {
|
196
|
+
try {
|
197
|
+
const { getHighlighter } = await import("shikiji");
|
198
|
+
return getHighlighter;
|
199
|
+
} catch (error) {
|
200
|
+
throw new ProseKitError(
|
201
|
+
"Failed to import package 'shikiji'. Make sure you've installed it.",
|
202
|
+
{ cause: error }
|
203
|
+
);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
async function createHighlighter(theme) {
|
207
|
+
const getHighlighter = await importGetHighlighter();
|
208
|
+
const fallbackLang = "md";
|
209
|
+
return await getHighlighter({
|
210
|
+
langs: [fallbackLang],
|
211
|
+
themes: [theme]
|
212
|
+
});
|
213
|
+
}
|
180
214
|
function createHighlighterLoader() {
|
181
215
|
let shikijiImport;
|
182
216
|
let highlighter;
|
183
|
-
const
|
184
|
-
const
|
217
|
+
const loadLangs = /* @__PURE__ */ new Set();
|
218
|
+
const loadThemes = /* @__PURE__ */ new Set();
|
185
219
|
return function highlighterLoader(lang, theme) {
|
186
220
|
if (!shikijiImport) {
|
187
|
-
shikijiImport =
|
188
|
-
|
189
|
-
highlighter = await getHighlighter({
|
190
|
-
langs: [fallbackLang],
|
191
|
-
themes: []
|
192
|
-
});
|
221
|
+
shikijiImport = createHighlighter(theme).then((result) => {
|
222
|
+
highlighter = result;
|
193
223
|
});
|
194
224
|
return { promise: shikijiImport };
|
195
225
|
}
|
196
226
|
if (!highlighter) {
|
197
227
|
return { promise: shikijiImport };
|
198
228
|
}
|
199
|
-
if (!
|
229
|
+
if (!loadLangs.has(lang)) {
|
200
230
|
const promise = highlighter.loadLanguage(lang).then(() => {
|
201
|
-
|
231
|
+
loadLangs.add(lang);
|
202
232
|
}).catch(() => {
|
203
233
|
});
|
204
234
|
return { promise };
|
205
235
|
}
|
206
|
-
if (!
|
236
|
+
if (!loadThemes.has(theme)) {
|
207
237
|
const promise = highlighter.loadTheme(theme).then(() => {
|
208
|
-
|
238
|
+
loadThemes.add(theme);
|
209
239
|
}).catch(() => {
|
210
240
|
});
|
211
241
|
return { promise };
|
@@ -229,7 +259,7 @@ function createLazyParser(theme) {
|
|
229
259
|
};
|
230
260
|
}
|
231
261
|
function defineCodeBlockShikiji(options) {
|
232
|
-
const theme = (options == null ? void 0 : options.theme) || "
|
262
|
+
const theme = (options == null ? void 0 : options.theme) || "one-dark-pro";
|
233
263
|
const parser = createLazyParser(theme);
|
234
264
|
return defineCodeBlockHighlight({ parser });
|
235
265
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.2.
|
4
|
+
"version": "0.2.5",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -126,7 +126,7 @@
|
|
126
126
|
"dist"
|
127
127
|
],
|
128
128
|
"dependencies": {
|
129
|
-
"@prosekit/core": "^0.2.
|
129
|
+
"@prosekit/core": "^0.2.6",
|
130
130
|
"@prosekit/pm": "^0.1.1",
|
131
131
|
"prosemirror-dropcursor": "^1.8.1",
|
132
132
|
"prosemirror-flat-list": "^0.4.5",
|
@@ -142,10 +142,10 @@
|
|
142
142
|
},
|
143
143
|
"devDependencies": {
|
144
144
|
"@prosekit/dev": "*",
|
145
|
-
"shikiji": "^0.9.
|
145
|
+
"shikiji": "^0.9.19",
|
146
146
|
"tsup": "^8.0.1",
|
147
147
|
"typescript": "^5.3.3",
|
148
|
-
"vitest": "^1.
|
148
|
+
"vitest": "^1.2.0"
|
149
149
|
},
|
150
150
|
"scripts": {
|
151
151
|
"build:tsup": "tsup",
|