@prosekit/extensions 0.3.2 → 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.
@@ -1,10 +1,16 @@
1
1
  import { Attrs } from '@prosekit/pm/model';
2
- import type { BundledTheme } from 'shikiji';
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';
@@ -16,6 +22,7 @@ import { Parser } from 'prosemirror-highlight';
16
22
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
17
23
  import { PluginKey } from '@prosekit/pm/state';
18
24
  import { ProseMirrorNode } from '@prosekit/pm/model';
25
+ import type { SpecialLanguage } from 'shiki';
19
26
  import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
20
27
  import { Transaction } from '@prosekit/pm/state';
21
28
  import { UnwrapListOptions } from 'prosemirror-flat-list';
@@ -39,6 +46,24 @@ declare class AutocompleteRule {
39
46
  export { AutocompleteRule }
40
47
  export { AutocompleteRule as AutocompleteRule_alias_1 }
41
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
+
42
67
  /**
43
68
  * The attributes for the `codeBlock` node.
44
69
  *
@@ -50,10 +75,39 @@ declare interface CodeBlockAttrs {
50
75
  export { CodeBlockAttrs }
51
76
  export { CodeBlockAttrs as CodeBlockAttrs_alias_1 }
52
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
+
53
102
  export declare function createAutocompletePlugin({ getRules, }: {
54
103
  getRules: () => AutocompleteRule[];
55
104
  }): Plugin_2;
56
105
 
106
+ /**
107
+ * @internal
108
+ */
109
+ export declare function createLazyParser(highlighterOptions: HighlighterOptions): Parser;
110
+
57
111
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
58
112
 
59
113
  export declare const default_alias_1: {
@@ -128,7 +182,7 @@ toggleCode: [];
128
182
  *
129
183
  * @public
130
184
  */
131
- export declare function defineCodeBlock(): Extension< {
185
+ declare function defineCodeBlock(): Extension< {
132
186
  NODES: "codeBlock";
133
187
  COMMAND_ARGS: {
134
188
  setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
@@ -137,6 +191,8 @@ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
137
191
  setCodeBlockAttrs: [attrs: CodeBlockAttrs];
138
192
  };
139
193
  }>;
194
+ export { defineCodeBlock }
195
+ export { defineCodeBlock as defineCodeBlock_alias_1 }
140
196
 
141
197
  /**
142
198
  * Adds commands for working with `codeBlock` nodes.
@@ -192,20 +248,13 @@ export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
192
248
  export declare function defineCodeBlockKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
193
249
 
194
250
  /**
195
- * Adds syntax highlighting to code blocks using the [shikiji](https://github.com/antfu/shikiji) package.
251
+ * Adds syntax highlighting to code blocks using the [shiki](https://github.com/shikijs/shiki) package.
196
252
  *
197
253
  * @public
198
254
  */
199
- declare function defineCodeBlockShikiji(options?: {
200
- /**
201
- * The shikiji theme to use.
202
- *
203
- * @default 'one-dark-pro'
204
- */
205
- theme?: BundledTheme;
206
- }): Extension;
207
- export { defineCodeBlockShikiji }
208
- 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 }
209
258
 
210
259
  /**
211
260
  * Defines the `codeBlock` node spec.
@@ -618,6 +667,8 @@ export declare type EnterRuleOptions = {
618
667
  stop?: boolean;
619
668
  };
620
669
 
670
+ export { getHighlighter }
671
+
621
672
  export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
622
673
 
623
674
  export declare function getTrMeta(tr: Transaction): PredictionPluginState;
@@ -626,6 +677,12 @@ export declare interface HeadingAttrs {
626
677
  level: number;
627
678
  }
628
679
 
680
+ declare type HighlighterOptions = {
681
+ themes: BundledTheme[];
682
+ langs: (BundledLanguage | SpecialLanguage)[];
683
+ langAlias?: Record<string, BundledLanguage>;
684
+ };
685
+
629
686
  /**
630
687
  * @public
631
688
  *
@@ -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 { defineCodeBlockShikiji_alias_1 as defineCodeBlockShikiji } from './_tsup-dts-rollup';
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 { HighlightParser_alias_1 as HighlightParser } from './_tsup-dts-rollup';
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/index.ts
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/index.ts
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
- defineCodeBlockShikiji,
222
- defineCodeBlockSpec
210
+ defineCodeBlockShiki,
211
+ defineCodeBlockSpec,
212
+ bundledLanguagesInfo as shikiBundledLanguagesInfo,
213
+ bundledThemesInfo as shikiBundledThemesInfo
223
214
  };
@@ -0,0 +1,5 @@
1
+ // src/code-block/shiki-import.ts
2
+ import { getHighlighter } from "shiki/bundle/full";
3
+ export {
4
+ getHighlighter
5
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.4.0",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -138,19 +138,11 @@
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.5.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
- "shikiji": "^0.10.2",
154
146
  "tsup": "^8.0.2",
155
147
  "typescript": "^5.3.3",
156
148
  "vitest": "^1.2.2"