@prosekit/extensions 0.1.4 → 0.1.6

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.
@@ -8,12 +8,12 @@ import { IndentListOptions } from 'prosemirror-flat-list';
8
8
  import { ListAttributes } from 'prosemirror-flat-list';
9
9
  import { NodeRange } from 'prosemirror-model';
10
10
  import { Options } from 'tsup';
11
+ import { Parser } from 'prosemirror-highlight';
11
12
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
12
13
  import { PluginKey } from '@prosekit/pm/state';
13
14
  import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
14
15
  import { Transaction } from '@prosekit/pm/state';
15
16
  import { UnwrapListOptions } from 'prosemirror-flat-list';
16
- import { UserProjectConfigExport } from 'vitest/dist/config.js';
17
17
 
18
18
  declare class AutocompleteRule {
19
19
  readonly regex: RegExp;
@@ -34,6 +34,11 @@ declare class AutocompleteRule {
34
34
  export { AutocompleteRule }
35
35
  export { AutocompleteRule as AutocompleteRule_alias_1 }
36
36
 
37
+ /**
38
+ * The attributes for the `codeBlock` node.
39
+ *
40
+ * @public
41
+ */
37
42
  declare interface CodeBlockAttrs {
38
43
  language?: string;
39
44
  }
@@ -48,7 +53,11 @@ export declare function createPredictionPlugin(options: SuggestionOptions): Plug
48
53
 
49
54
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
50
55
 
51
- export declare const default_alias_1: UserProjectConfigExport;
56
+ export declare const default_alias_1: {
57
+ test: {
58
+ environment: "jsdom";
59
+ };
60
+ };
52
61
 
53
62
  export declare function defaultCanMatch({ state }: {
54
63
  state: EditorState;
@@ -104,10 +113,25 @@ toggleCode: [];
104
113
  }>;
105
114
 
106
115
  /**
116
+ * Adds `codeBlock` nodes to the editor. This includes the following extensions:
117
+ *
118
+ * - {@link defineCodeBlockSpec}
119
+ * - {@link defineCodeBlockInputRule}
120
+ * - {@link defineCodeBlockCommands}.
121
+ *
107
122
  * @public
108
123
  */
109
124
  export declare function defineCodeBlock(options?: {
125
+ /**
126
+ * @deprecated Use `defineCodeBlockHighlight` function instead.
127
+ */
110
128
  hljs?: HLJSApi;
129
+ /**
130
+ * A parser for the `prosemirror-highlight` package to use for syntax highlighting.
131
+ *
132
+ * @deprecated Use the standalone `defineCodeBlockHighlight` function instead.
133
+ */
134
+ parser?: HighlightParser;
111
135
  }): Extension< {
112
136
  NODES: "codeBlock";
113
137
  COMMAND_ARGS: {
@@ -115,21 +139,59 @@ setCodeBlockLanguage: [language: string];
115
139
  };
116
140
  }>;
117
141
 
118
- export declare function defineCodeBlockCommands(): Extension< {
142
+ /**
143
+ * Adds commands for working with `codeBlock` nodes.
144
+ *
145
+ * @public
146
+ */
147
+ declare function defineCodeBlockCommands(): Extension< {
119
148
  COMMAND_ARGS: {
120
149
  setCodeBlockLanguage: [language: string];
121
150
  };
122
151
  }>;
152
+ export { defineCodeBlockCommands }
153
+ export { defineCodeBlockCommands as defineCodeBlockCommands_alias_1 }
154
+
155
+ /**
156
+ * Adds syntax highlighting to code blocks. This function requires a `Parser`
157
+ * instance from the `prosemirror-highlight` package. See the
158
+ * [documentation](https://github.com/ocavue/prosemirror-highlight) for more
159
+ * information.
160
+ *
161
+ * @public
162
+ */
163
+ declare function defineCodeBlockHighlight({ parser, }: {
164
+ parser: HighlightParser;
165
+ }): Extension;
166
+ export { defineCodeBlockHighlight }
167
+ export { defineCodeBlockHighlight as defineCodeBlockHighlight_alias_1 }
123
168
 
124
- export declare function defineCodeBlockHighlight(options: {
169
+ /**
170
+ * @deprecated
171
+ */
172
+ export declare function defineCodeBlockHighlightDeprecated(options: {
125
173
  hljs?: HLJSApi;
126
174
  }): Extension<ExtensionTyping<string, string, CommandArgs>>;
127
175
 
128
- export declare function defineCodeBlockInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
176
+ /**
177
+ * Adds input rules for `codeBlock` nodes.
178
+ *
179
+ * @public
180
+ */
181
+ declare function defineCodeBlockInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
182
+ export { defineCodeBlockInputRule }
183
+ export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
129
184
 
130
- export declare function defineCodeBlockSpec(): Extension< {
185
+ /**
186
+ * Defines the `codeBlock` node spec.
187
+ *
188
+ * @public
189
+ */
190
+ declare function defineCodeBlockSpec(): Extension< {
131
191
  NODES: "codeBlock";
132
192
  }>;
193
+ export { defineCodeBlockSpec }
194
+ export { defineCodeBlockSpec as defineCodeBlockSpec_alias_1 }
133
195
 
134
196
  export declare function defineCodeCommands(): Extension< {
135
197
  COMMAND_ARGS: {
@@ -376,6 +438,15 @@ export declare interface HeadingAttrs {
376
438
  level: number;
377
439
  }
378
440
 
441
+ /**
442
+ * @public
443
+ *
444
+ * An alias for the `Parser` type from the `prosemirror-highlight` package.
445
+ */
446
+ declare type HighlightParser = Parser;
447
+ export { HighlightParser }
448
+ export { HighlightParser as HighlightParser_alias_1 }
449
+
379
450
  export declare interface ImageAttrs {
380
451
  src?: string | null;
381
452
  }
@@ -1,5 +1,7 @@
1
- export { defineCodeBlockSpec } from './_tsup-dts-rollup';
2
- export { defineCodeBlockInputRule } from './_tsup-dts-rollup';
3
- export { defineCodeBlockCommands } from './_tsup-dts-rollup';
4
1
  export { defineCodeBlock } from './_tsup-dts-rollup';
2
+ export { defineCodeBlockCommands_alias_1 as defineCodeBlockCommands } from './_tsup-dts-rollup';
3
+ export { defineCodeBlockHighlight_alias_1 as defineCodeBlockHighlight } from './_tsup-dts-rollup';
4
+ export { defineCodeBlockInputRule_alias_1 as defineCodeBlockInputRule } from './_tsup-dts-rollup';
5
+ export { defineCodeBlockSpec_alias_1 as defineCodeBlockSpec } from './_tsup-dts-rollup';
5
6
  export { CodeBlockAttrs_alias_1 as CodeBlockAttrs } from './_tsup-dts-rollup';
7
+ export { HighlightParser_alias_1 as HighlightParser } from './_tsup-dts-rollup';
@@ -1,19 +1,41 @@
1
1
  // src/code-block/index.ts
2
- import {
3
- defineCommands,
4
- defineInputRule,
5
- defineNodeSpec,
6
- union,
7
- getNodeType
8
- } from "@prosekit/core";
9
- import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
2
+ import { union } from "@prosekit/core";
3
+
4
+ // src/code-block/code-block-commands.ts
5
+ import { defineCommands } from "@prosekit/core";
6
+ function defineCodeBlockCommands() {
7
+ return defineCommands({
8
+ setCodeBlockLanguage: (language) => (state, dispatch) => {
9
+ const pos = state.selection.$from.before();
10
+ const codeBlock = state.doc.nodeAt(pos);
11
+ if (!codeBlock || codeBlock.type.name !== "codeBlock") {
12
+ return false;
13
+ }
14
+ const { tr } = state;
15
+ tr.setNodeMarkup(pos, void 0, { language });
16
+ dispatch == null ? void 0 : dispatch(tr);
17
+ return true;
18
+ }
19
+ });
20
+ }
10
21
 
11
22
  // src/code-block/code-block-highlight.ts
12
23
  import { definePlugin } from "@prosekit/core";
24
+ import { createHighlightPlugin } from "prosemirror-highlight";
25
+ function defineCodeBlockHighlight({
26
+ parser
27
+ }) {
28
+ return definePlugin(
29
+ createHighlightPlugin({ parser, nodeTypes: ["codeBlock"] })
30
+ );
31
+ }
32
+
33
+ // src/code-block/code-block-highlight-deprecated.ts
34
+ import { definePlugin as definePlugin2 } from "@prosekit/core";
13
35
  import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
14
36
  import { DecorationSet } from "@prosekit/pm/view";
15
37
  import { getHighlightDecorations } from "prosemirror-highlightjs";
16
- function defineCodeBlockHighlight(options) {
38
+ function defineCodeBlockHighlightDeprecated(options) {
17
39
  const hljs = options.hljs;
18
40
  const plugin = new ProseMirrorPlugin({
19
41
  key,
@@ -41,7 +63,7 @@ function defineCodeBlockHighlight(options) {
41
63
  }
42
64
  }
43
65
  });
44
- return definePlugin(plugin);
66
+ return definePlugin2(plugin);
45
67
  }
46
68
  var key = new PluginKey("prosekit-code-block-highlight");
47
69
  var blockTypes = ["codeBlock"];
@@ -49,7 +71,21 @@ function languageExtractor(node) {
49
71
  return node.attrs.language || "javascript";
50
72
  }
51
73
 
52
- // src/code-block/index.ts
74
+ // src/code-block/code-block-input-rule.ts
75
+ import { defineInputRule, getNodeType } from "@prosekit/core";
76
+ import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
77
+ function defineCodeBlockInputRule() {
78
+ return defineInputRule(({ schema }) => {
79
+ const nodeType = getNodeType(schema, "codeBlock");
80
+ const getAttrs = (match) => {
81
+ return { language: match[1] || "" };
82
+ };
83
+ return textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
84
+ });
85
+ }
86
+
87
+ // src/code-block/code-block-spec.ts
88
+ import { defineNodeSpec } from "@prosekit/core";
53
89
  function defineCodeBlockSpec() {
54
90
  return defineNodeSpec({
55
91
  name: "codeBlock",
@@ -72,47 +108,35 @@ function defineCodeBlockSpec() {
72
108
  const attrs = node.attrs;
73
109
  return [
74
110
  "pre",
111
+ // TODO: remove class 'hljs'
75
112
  { "data-language": attrs.language, class: "hljs" },
76
113
  ["code", 0]
77
114
  ];
78
115
  }
79
116
  });
80
117
  }
81
- function defineCodeBlockInputRule() {
82
- return defineInputRule(({ schema }) => {
83
- const nodeType = getNodeType(schema, "codeBlock");
84
- const getAttrs = (match) => {
85
- return { language: match[1] || "" };
86
- };
87
- return textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
88
- });
89
- }
90
- function defineCodeBlockCommands() {
91
- return defineCommands({
92
- setCodeBlockLanguage: (language) => (state, dispatch) => {
93
- const pos = state.selection.$from.before();
94
- const codeBlock = state.doc.nodeAt(pos);
95
- if (!codeBlock || codeBlock.type.name !== "codeBlock") {
96
- return false;
97
- }
98
- const { tr } = state;
99
- tr.setNodeMarkup(pos, void 0, { language });
100
- dispatch == null ? void 0 : dispatch(tr);
101
- return true;
102
- }
103
- });
104
- }
118
+
119
+ // src/code-block/index.ts
105
120
  function defineCodeBlock(options) {
106
- return union([
121
+ const extensions = [
107
122
  defineCodeBlockSpec(),
108
123
  defineCodeBlockInputRule(),
109
- defineCodeBlockHighlight({ hljs: options == null ? void 0 : options.hljs }),
110
124
  defineCodeBlockCommands()
111
- ]);
125
+ ];
126
+ const parser = options == null ? void 0 : options.parser;
127
+ if (parser) {
128
+ extensions.push(defineCodeBlockHighlight({ parser }));
129
+ }
130
+ const hljs = options == null ? void 0 : options.hljs;
131
+ if (hljs) {
132
+ extensions.push(defineCodeBlockHighlightDeprecated({ hljs }));
133
+ }
134
+ return union(extensions);
112
135
  }
113
136
  export {
114
137
  defineCodeBlock,
115
138
  defineCodeBlockCommands,
139
+ defineCodeBlockHighlight,
116
140
  defineCodeBlockInputRule,
117
141
  defineCodeBlockSpec
118
142
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -121,17 +121,18 @@
121
121
  "dist"
122
122
  ],
123
123
  "dependencies": {
124
- "@prosekit/core": "^0.1.0",
125
- "@prosekit/pm": "^0.1.0",
124
+ "@prosekit/core": "^0.1.8",
125
+ "@prosekit/pm": "^0.1.1",
126
126
  "highlight.js": "^11.9.0",
127
127
  "prosemirror-flat-list": "^0.4.5",
128
+ "prosemirror-highlight": "^0.3.2",
128
129
  "prosemirror-highlightjs": "^0.9.1"
129
130
  },
130
131
  "devDependencies": {
131
132
  "@prosekit/dev": "*",
132
133
  "tsup": "^8.0.1",
133
- "typescript": "^5.3.2",
134
- "vitest": "^0.34.6"
134
+ "typescript": "^5.3.3",
135
+ "vitest": "^1.0.4"
135
136
  },
136
137
  "scripts": {
137
138
  "build:tsup": "tsup",