@prosekit/extensions 0.3.1 → 0.4.0
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 +73 -13
- package/dist/prosekit-extensions-code-block.d.ts +10 -4
- package/dist/prosekit-extensions-code-block.js +81 -90
- package/dist/prosekit-extensions-list.d.ts +1 -0
- package/dist/prosekit-extensions-list.js +2 -0
- package/dist/shiki-import-25BJYIO2.js +5 -0
- package/package.json +5 -13
@@ -1,13 +1,20 @@
|
|
1
1
|
import { Attrs } from '@prosekit/pm/model';
|
2
|
-
import
|
2
|
+
import { BundledLanguage } from 'shiki';
|
3
|
+
import { BundledLanguageInfo } from 'shiki';
|
4
|
+
import { bundledLanguagesInfo } from 'shiki';
|
5
|
+
import { BundledTheme } from 'shiki';
|
6
|
+
import { BundledThemeInfo } from 'shiki';
|
7
|
+
import { bundledThemesInfo } from 'shiki';
|
3
8
|
import { CommandArgs } from '@prosekit/core';
|
4
9
|
import { DedentListOptions } from 'prosemirror-flat-list';
|
5
10
|
import { EditorState } from '@prosekit/pm/state';
|
6
11
|
import { Extension } from '@prosekit/core';
|
7
12
|
import { ExtensionTyping } from '@prosekit/core';
|
13
|
+
import { getHighlighter } from 'shiki/bundle/full';
|
8
14
|
import { IndentListOptions } from 'prosemirror-flat-list';
|
9
15
|
import { InputRule } from '@prosekit/pm/inputrules';
|
10
16
|
import { ListAttributes } from 'prosemirror-flat-list';
|
17
|
+
import { ListDOMSerializer } from 'prosemirror-flat-list';
|
11
18
|
import { NodeRange } from 'prosemirror-model';
|
12
19
|
import { NodeType } from '@prosekit/pm/model';
|
13
20
|
import { Options } from 'tsup';
|
@@ -15,6 +22,7 @@ import { Parser } from 'prosemirror-highlight';
|
|
15
22
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
16
23
|
import { PluginKey } from '@prosekit/pm/state';
|
17
24
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
25
|
+
import type { SpecialLanguage } from 'shiki';
|
18
26
|
import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
|
19
27
|
import { Transaction } from '@prosekit/pm/state';
|
20
28
|
import { UnwrapListOptions } from 'prosemirror-flat-list';
|
@@ -38,6 +46,24 @@ declare class AutocompleteRule {
|
|
38
46
|
export { AutocompleteRule }
|
39
47
|
export { AutocompleteRule as AutocompleteRule_alias_1 }
|
40
48
|
|
49
|
+
export { BundledLanguage as ShikiBundledLanguage }
|
50
|
+
export { BundledLanguage as ShikiBundledLanguage_alias_1 }
|
51
|
+
|
52
|
+
export { BundledLanguageInfo as ShikiBundledLanguageInfo }
|
53
|
+
export { BundledLanguageInfo as ShikiBundledLanguageInfo_alias_1 }
|
54
|
+
|
55
|
+
export { bundledLanguagesInfo as shikiBundledLanguagesInfo }
|
56
|
+
export { bundledLanguagesInfo as shikiBundledLanguagesInfo_alias_1 }
|
57
|
+
|
58
|
+
export { BundledTheme as ShikiBundledTheme }
|
59
|
+
export { BundledTheme as ShikiBundledTheme_alias_1 }
|
60
|
+
|
61
|
+
export { BundledThemeInfo as ShikiBundledThemeInfo }
|
62
|
+
export { BundledThemeInfo as ShikiBundledThemeInfo_alias_1 }
|
63
|
+
|
64
|
+
export { bundledThemesInfo as shikiBundledThemesInfo }
|
65
|
+
export { bundledThemesInfo as shikiBundledThemesInfo_alias_1 }
|
66
|
+
|
41
67
|
/**
|
42
68
|
* The attributes for the `codeBlock` node.
|
43
69
|
*
|
@@ -49,10 +75,39 @@ declare interface CodeBlockAttrs {
|
|
49
75
|
export { CodeBlockAttrs }
|
50
76
|
export { CodeBlockAttrs as CodeBlockAttrs_alias_1 }
|
51
77
|
|
78
|
+
/**
|
79
|
+
* @public
|
80
|
+
*/
|
81
|
+
export declare interface CodeBlockShikiOptions {
|
82
|
+
/**
|
83
|
+
* Theme registation
|
84
|
+
*
|
85
|
+
* @default ['one-dark-pro']
|
86
|
+
*/
|
87
|
+
themes?: BundledTheme[];
|
88
|
+
/**
|
89
|
+
* Language registation
|
90
|
+
*
|
91
|
+
* @default ['text']
|
92
|
+
*/
|
93
|
+
langs?: (BundledLanguage | SpecialLanguage)[];
|
94
|
+
/**
|
95
|
+
* Alias of languages
|
96
|
+
*
|
97
|
+
* @example { 'my-lang': 'javascript' }
|
98
|
+
*/
|
99
|
+
langAlias?: Record<string, BundledLanguage>;
|
100
|
+
}
|
101
|
+
|
52
102
|
export declare function createAutocompletePlugin({ getRules, }: {
|
53
103
|
getRules: () => AutocompleteRule[];
|
54
104
|
}): Plugin_2;
|
55
105
|
|
106
|
+
/**
|
107
|
+
* @internal
|
108
|
+
*/
|
109
|
+
export declare function createLazyParser(highlighterOptions: HighlighterOptions): Parser;
|
110
|
+
|
56
111
|
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
57
112
|
|
58
113
|
export declare const default_alias_1: {
|
@@ -127,7 +182,7 @@ toggleCode: [];
|
|
127
182
|
*
|
128
183
|
* @public
|
129
184
|
*/
|
130
|
-
|
185
|
+
declare function defineCodeBlock(): Extension< {
|
131
186
|
NODES: "codeBlock";
|
132
187
|
COMMAND_ARGS: {
|
133
188
|
setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
@@ -136,6 +191,8 @@ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
|
136
191
|
setCodeBlockAttrs: [attrs: CodeBlockAttrs];
|
137
192
|
};
|
138
193
|
}>;
|
194
|
+
export { defineCodeBlock }
|
195
|
+
export { defineCodeBlock as defineCodeBlock_alias_1 }
|
139
196
|
|
140
197
|
/**
|
141
198
|
* Adds commands for working with `codeBlock` nodes.
|
@@ -191,20 +248,13 @@ export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
|
|
191
248
|
export declare function defineCodeBlockKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
192
249
|
|
193
250
|
/**
|
194
|
-
* Adds syntax highlighting to code blocks using the [
|
251
|
+
* Adds syntax highlighting to code blocks using the [shiki](https://github.com/shikijs/shiki) package.
|
195
252
|
*
|
196
253
|
* @public
|
197
254
|
*/
|
198
|
-
declare function
|
199
|
-
|
200
|
-
|
201
|
-
*
|
202
|
-
* @default 'one-dark-pro'
|
203
|
-
*/
|
204
|
-
theme?: BundledTheme;
|
205
|
-
}): Extension;
|
206
|
-
export { defineCodeBlockShikiji }
|
207
|
-
export { defineCodeBlockShikiji as defineCodeBlockShikiji_alias_1 }
|
255
|
+
declare function defineCodeBlockShiki({ themes, langs, langAlias, }?: CodeBlockShikiOptions): Extension;
|
256
|
+
export { defineCodeBlockShiki }
|
257
|
+
export { defineCodeBlockShiki as defineCodeBlockShiki_alias_1 }
|
208
258
|
|
209
259
|
/**
|
210
260
|
* Defines the `codeBlock` node spec.
|
@@ -617,6 +667,8 @@ export declare type EnterRuleOptions = {
|
|
617
667
|
stop?: boolean;
|
618
668
|
};
|
619
669
|
|
670
|
+
export { getHighlighter }
|
671
|
+
|
620
672
|
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
621
673
|
|
622
674
|
export declare function getTrMeta(tr: Transaction): PredictionPluginState;
|
@@ -625,6 +677,12 @@ export declare interface HeadingAttrs {
|
|
625
677
|
level: number;
|
626
678
|
}
|
627
679
|
|
680
|
+
declare type HighlighterOptions = {
|
681
|
+
themes: BundledTheme[];
|
682
|
+
langs: (BundledLanguage | SpecialLanguage)[];
|
683
|
+
langAlias?: Record<string, BundledLanguage>;
|
684
|
+
};
|
685
|
+
|
628
686
|
/**
|
629
687
|
* @public
|
630
688
|
*
|
@@ -649,6 +707,8 @@ export declare interface LinkAttrs {
|
|
649
707
|
href: string;
|
650
708
|
}
|
651
709
|
|
710
|
+
export { ListDOMSerializer }
|
711
|
+
|
652
712
|
declare type MatchHandler = (options: {
|
653
713
|
state: EditorState;
|
654
714
|
match: RegExpExecArray;
|
@@ -1,9 +1,15 @@
|
|
1
|
-
export { defineCodeBlock } from './_tsup-dts-rollup';
|
1
|
+
export { defineCodeBlock_alias_1 as defineCodeBlock } from './_tsup-dts-rollup';
|
2
2
|
export { defineCodeBlockCommands_alias_1 as defineCodeBlockCommands } from './_tsup-dts-rollup';
|
3
|
-
export { defineCodeBlockEnterRule_alias_1 as defineCodeBlockEnterRule } from './_tsup-dts-rollup';
|
4
3
|
export { defineCodeBlockHighlight_alias_1 as defineCodeBlockHighlight } from './_tsup-dts-rollup';
|
4
|
+
export { HighlightParser_alias_1 as HighlightParser } from './_tsup-dts-rollup';
|
5
|
+
export { defineCodeBlockEnterRule_alias_1 as defineCodeBlockEnterRule } from './_tsup-dts-rollup';
|
5
6
|
export { defineCodeBlockInputRule_alias_1 as defineCodeBlockInputRule } from './_tsup-dts-rollup';
|
6
|
-
export {
|
7
|
+
export { defineCodeBlockShiki_alias_1 as defineCodeBlockShiki } from './_tsup-dts-rollup';
|
7
8
|
export { defineCodeBlockSpec_alias_1 as defineCodeBlockSpec } from './_tsup-dts-rollup';
|
8
9
|
export { CodeBlockAttrs_alias_1 as CodeBlockAttrs } from './_tsup-dts-rollup';
|
9
|
-
export {
|
10
|
+
export { shikiBundledLanguagesInfo } from './_tsup-dts-rollup';
|
11
|
+
export { shikiBundledThemesInfo } from './_tsup-dts-rollup';
|
12
|
+
export { ShikiBundledLanguage } from './_tsup-dts-rollup';
|
13
|
+
export { ShikiBundledLanguageInfo } from './_tsup-dts-rollup';
|
14
|
+
export { ShikiBundledTheme } from './_tsup-dts-rollup';
|
15
|
+
export { ShikiBundledThemeInfo } from './_tsup-dts-rollup';
|
@@ -5,7 +5,7 @@ import {
|
|
5
5
|
defineTextBlockInputRule
|
6
6
|
} from "./chunk-DYFRBXUX.js";
|
7
7
|
|
8
|
-
// src/code-block/
|
8
|
+
// src/code-block/code-block.ts
|
9
9
|
import { union } from "@prosekit/core";
|
10
10
|
|
11
11
|
// src/code-block/code-block-commands.ts
|
@@ -33,17 +33,6 @@ function defineCodeBlockCommands() {
|
|
33
33
|
});
|
34
34
|
}
|
35
35
|
|
36
|
-
// src/code-block/code-block-highlight.ts
|
37
|
-
import { definePlugin } from "@prosekit/core";
|
38
|
-
import { createHighlightPlugin } from "prosemirror-highlight";
|
39
|
-
function defineCodeBlockHighlight({
|
40
|
-
parser
|
41
|
-
}) {
|
42
|
-
return definePlugin(
|
43
|
-
createHighlightPlugin({ parser, nodeTypes: ["codeBlock"] })
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
36
|
// src/code-block/code-block-input-rule.ts
|
48
37
|
function defineCodeBlockInputRule() {
|
49
38
|
return defineTextBlockInputRule({
|
@@ -100,81 +89,6 @@ var existCodeBlock = (state, dispatch) => {
|
|
100
89
|
return false;
|
101
90
|
};
|
102
91
|
|
103
|
-
// src/code-block/code-block-shikiji.ts
|
104
|
-
import { ProseKitError } from "@prosekit/core";
|
105
|
-
import { createParser } from "prosemirror-highlight/shikiji";
|
106
|
-
async function importGetHighlighter() {
|
107
|
-
try {
|
108
|
-
const { getHighlighter } = await import("shikiji");
|
109
|
-
return getHighlighter;
|
110
|
-
} catch (error) {
|
111
|
-
throw new ProseKitError(
|
112
|
-
"Failed to import package 'shikiji'. Make sure you've installed it.",
|
113
|
-
{ cause: error }
|
114
|
-
);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
async function createHighlighter(theme) {
|
118
|
-
const getHighlighter = await importGetHighlighter();
|
119
|
-
const fallbackLang = "md";
|
120
|
-
return await getHighlighter({
|
121
|
-
langs: [fallbackLang],
|
122
|
-
themes: [theme]
|
123
|
-
});
|
124
|
-
}
|
125
|
-
function createHighlighterLoader() {
|
126
|
-
let shikijiImport;
|
127
|
-
let highlighter;
|
128
|
-
const loadLangs = /* @__PURE__ */ new Set();
|
129
|
-
const loadThemes = /* @__PURE__ */ new Set();
|
130
|
-
return function highlighterLoader(lang, theme) {
|
131
|
-
if (!shikijiImport) {
|
132
|
-
shikijiImport = createHighlighter(theme).then((result) => {
|
133
|
-
highlighter = result;
|
134
|
-
});
|
135
|
-
return { promise: shikijiImport };
|
136
|
-
}
|
137
|
-
if (!highlighter) {
|
138
|
-
return { promise: shikijiImport };
|
139
|
-
}
|
140
|
-
if (!loadLangs.has(lang)) {
|
141
|
-
const promise = highlighter.loadLanguage(lang).then(() => {
|
142
|
-
loadLangs.add(lang);
|
143
|
-
}).catch(() => {
|
144
|
-
});
|
145
|
-
return { promise };
|
146
|
-
}
|
147
|
-
if (!loadThemes.has(theme)) {
|
148
|
-
const promise = highlighter.loadTheme(theme).then(() => {
|
149
|
-
loadThemes.add(theme);
|
150
|
-
}).catch(() => {
|
151
|
-
});
|
152
|
-
return { promise };
|
153
|
-
}
|
154
|
-
return { highlighter };
|
155
|
-
};
|
156
|
-
}
|
157
|
-
function createLazyParser(theme) {
|
158
|
-
let parser;
|
159
|
-
const highlighterLoader = createHighlighterLoader();
|
160
|
-
return function lazyParser(options) {
|
161
|
-
const language = options.language || "";
|
162
|
-
const { highlighter, promise } = highlighterLoader(language, theme);
|
163
|
-
if (!highlighter) {
|
164
|
-
return promise || [];
|
165
|
-
}
|
166
|
-
if (!parser) {
|
167
|
-
parser = createParser(highlighter);
|
168
|
-
}
|
169
|
-
return parser(options);
|
170
|
-
};
|
171
|
-
}
|
172
|
-
function defineCodeBlockShikiji(options) {
|
173
|
-
const theme = (options == null ? void 0 : options.theme) || "one-dark-pro";
|
174
|
-
const parser = createLazyParser(theme);
|
175
|
-
return defineCodeBlockHighlight({ parser });
|
176
|
-
}
|
177
|
-
|
178
92
|
// src/code-block/code-block-spec.ts
|
179
93
|
import { defineNodeSpec } from "@prosekit/core";
|
180
94
|
function defineCodeBlockSpec() {
|
@@ -202,7 +116,7 @@ function defineCodeBlockSpec() {
|
|
202
116
|
});
|
203
117
|
}
|
204
118
|
|
205
|
-
// src/code-block/
|
119
|
+
// src/code-block/code-block.ts
|
206
120
|
function defineCodeBlock() {
|
207
121
|
return union([
|
208
122
|
defineCodeBlockSpec(),
|
@@ -212,12 +126,89 @@ function defineCodeBlock() {
|
|
212
126
|
defineCodeBlockCommands()
|
213
127
|
]);
|
214
128
|
}
|
129
|
+
|
130
|
+
// src/code-block/code-block-highlight.ts
|
131
|
+
import { definePlugin } from "@prosekit/core";
|
132
|
+
import { createHighlightPlugin } from "prosemirror-highlight";
|
133
|
+
function defineCodeBlockHighlight({
|
134
|
+
parser
|
135
|
+
}) {
|
136
|
+
return definePlugin(
|
137
|
+
createHighlightPlugin({ parser, nodeTypes: ["codeBlock"] })
|
138
|
+
);
|
139
|
+
}
|
140
|
+
|
141
|
+
// src/code-block/shiki-parser.ts
|
142
|
+
import { createParser } from "prosemirror-highlight/shiki";
|
143
|
+
function createHighlighterLoader() {
|
144
|
+
let highlighterPromise;
|
145
|
+
let highlighter;
|
146
|
+
const loadLangs = /* @__PURE__ */ new Set();
|
147
|
+
return function highlighterLoader(lang, options) {
|
148
|
+
if (!highlighterPromise) {
|
149
|
+
highlighterPromise = import("./shiki-import-25BJYIO2.js").then(({ getHighlighter }) => {
|
150
|
+
return getHighlighter(options);
|
151
|
+
}).then((h) => {
|
152
|
+
highlighter = h;
|
153
|
+
});
|
154
|
+
return { promise: highlighterPromise };
|
155
|
+
}
|
156
|
+
if (!highlighter) {
|
157
|
+
return { promise: highlighterPromise };
|
158
|
+
}
|
159
|
+
if (!loadLangs.has(lang)) {
|
160
|
+
const promise = highlighter.loadLanguage(lang).then(() => {
|
161
|
+
loadLangs.add(lang);
|
162
|
+
}).catch((error) => {
|
163
|
+
console.warn(`Failed to load language '${lang}'`, error);
|
164
|
+
});
|
165
|
+
return { promise };
|
166
|
+
}
|
167
|
+
return { highlighter };
|
168
|
+
};
|
169
|
+
}
|
170
|
+
function createLazyParser(highlighterOptions) {
|
171
|
+
let parser;
|
172
|
+
const highlighterLoader = createHighlighterLoader();
|
173
|
+
return function lazyParser(options) {
|
174
|
+
const language = options.language || "";
|
175
|
+
const { highlighter, promise } = highlighterLoader(
|
176
|
+
language,
|
177
|
+
highlighterOptions
|
178
|
+
);
|
179
|
+
if (!highlighter) {
|
180
|
+
return promise || [];
|
181
|
+
}
|
182
|
+
if (!parser) {
|
183
|
+
parser = createParser(highlighter);
|
184
|
+
}
|
185
|
+
return parser(options);
|
186
|
+
};
|
187
|
+
}
|
188
|
+
|
189
|
+
// src/code-block/code-block-shiki.ts
|
190
|
+
function defineCodeBlockShiki({
|
191
|
+
themes = ["one-dark-pro"],
|
192
|
+
langs = ["text"],
|
193
|
+
langAlias = {}
|
194
|
+
} = {}) {
|
195
|
+
const parser = createLazyParser({ themes, langs, langAlias });
|
196
|
+
return defineCodeBlockHighlight({ parser });
|
197
|
+
}
|
198
|
+
|
199
|
+
// src/code-block/shiki-bundle.ts
|
200
|
+
import {
|
201
|
+
bundledLanguagesInfo,
|
202
|
+
bundledThemesInfo
|
203
|
+
} from "shiki";
|
215
204
|
export {
|
216
205
|
defineCodeBlock,
|
217
206
|
defineCodeBlockCommands,
|
218
207
|
defineCodeBlockEnterRule,
|
219
208
|
defineCodeBlockHighlight,
|
220
209
|
defineCodeBlockInputRule,
|
221
|
-
|
222
|
-
defineCodeBlockSpec
|
210
|
+
defineCodeBlockShiki,
|
211
|
+
defineCodeBlockSpec,
|
212
|
+
bundledLanguagesInfo as shikiBundledLanguagesInfo,
|
213
|
+
bundledThemesInfo as shikiBundledThemesInfo
|
223
214
|
};
|
@@ -4,3 +4,4 @@ export { defineListKeymap } from './_tsup-dts-rollup';
|
|
4
4
|
export { defineListInputRules } from './_tsup-dts-rollup';
|
5
5
|
export { defineListCommands } from './_tsup-dts-rollup';
|
6
6
|
export { defineList } from './_tsup-dts-rollup';
|
7
|
+
export { ListDOMSerializer } from './_tsup-dts-rollup';
|
@@ -27,6 +27,7 @@ import {
|
|
27
27
|
listInputRules,
|
28
28
|
listKeymap
|
29
29
|
} from "prosemirror-flat-list";
|
30
|
+
import { ListDOMSerializer } from "prosemirror-flat-list";
|
30
31
|
function defineListSpec() {
|
31
32
|
return defineNodeSpec({ ...createListSpec(), name: "list" });
|
32
33
|
}
|
@@ -65,6 +66,7 @@ function defineList() {
|
|
65
66
|
]);
|
66
67
|
}
|
67
68
|
export {
|
69
|
+
ListDOMSerializer,
|
68
70
|
defineList,
|
69
71
|
defineListCommands,
|
70
72
|
defineListInputRules,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.4.0",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -134,24 +134,16 @@
|
|
134
134
|
"dist"
|
135
135
|
],
|
136
136
|
"dependencies": {
|
137
|
-
"@prosekit/core": "^0.
|
137
|
+
"@prosekit/core": "^0.4.0",
|
138
138
|
"@prosekit/pm": "^0.1.1",
|
139
139
|
"prosemirror-dropcursor": "^1.8.1",
|
140
140
|
"prosemirror-flat-list": "^0.4.6",
|
141
|
-
"prosemirror-highlight": "^0.
|
142
|
-
|
143
|
-
"peerDependencies": {
|
144
|
-
"shikiji": ">= 0.9.0"
|
145
|
-
},
|
146
|
-
"peerDependenciesMeta": {
|
147
|
-
"shikiji": {
|
148
|
-
"optional": true
|
149
|
-
}
|
141
|
+
"prosemirror-highlight": "^0.5.0",
|
142
|
+
"shiki": "^1.1.2"
|
150
143
|
},
|
151
144
|
"devDependencies": {
|
152
145
|
"@prosekit/dev": "*",
|
153
|
-
"
|
154
|
-
"tsup": "^8.0.1",
|
146
|
+
"tsup": "^8.0.2",
|
155
147
|
"typescript": "^5.3.3",
|
156
148
|
"vitest": "^1.2.2"
|
157
149
|
},
|