@prosekit/extensions 0.1.4 → 0.1.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.
@@ -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;
@@ -48,7 +48,11 @@ export declare function createPredictionPlugin(options: SuggestionOptions): Plug
48
48
 
49
49
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
50
50
 
51
- export declare const default_alias_1: UserProjectConfigExport;
51
+ export declare const default_alias_1: {
52
+ test: {
53
+ environment: "jsdom";
54
+ };
55
+ };
52
56
 
53
57
  export declare function defaultCanMatch({ state }: {
54
58
  state: EditorState;
@@ -107,7 +111,14 @@ toggleCode: [];
107
111
  * @public
108
112
  */
109
113
  export declare function defineCodeBlock(options?: {
114
+ /**
115
+ * @deprecated Use `highlight` instead.
116
+ */
110
117
  hljs?: HLJSApi;
118
+ /**
119
+ * A parser for the `prosemirror-highlight` package to use for syntax highlighting.
120
+ */
121
+ parser?: HighlightParser;
111
122
  }): Extension< {
112
123
  NODES: "codeBlock";
113
124
  COMMAND_ARGS: {
@@ -121,7 +132,14 @@ setCodeBlockLanguage: [language: string];
121
132
  };
122
133
  }>;
123
134
 
124
- export declare function defineCodeBlockHighlight(options: {
135
+ export declare function defineCodeBlockHighlight({ parser }: {
136
+ parser: Parser;
137
+ }): Extension<ExtensionTyping<string, string, CommandArgs>>;
138
+
139
+ /**
140
+ * @deprecated
141
+ */
142
+ export declare function defineCodeBlockHighlightDeprecated(options: {
125
143
  hljs?: HLJSApi;
126
144
  }): Extension<ExtensionTyping<string, string, CommandArgs>>;
127
145
 
@@ -376,6 +394,13 @@ export declare interface HeadingAttrs {
376
394
  level: number;
377
395
  }
378
396
 
397
+ /**
398
+ * @public
399
+ *
400
+ * An alias for the `Parser` type from the `prosemirror-highlight` package.
401
+ */
402
+ export declare type HighlightParser = Parser;
403
+
379
404
  export declare interface ImageAttrs {
380
405
  src?: string | null;
381
406
  }
@@ -3,3 +3,4 @@ export { defineCodeBlockInputRule } from './_tsup-dts-rollup';
3
3
  export { defineCodeBlockCommands } from './_tsup-dts-rollup';
4
4
  export { defineCodeBlock } from './_tsup-dts-rollup';
5
5
  export { CodeBlockAttrs_alias_1 as CodeBlockAttrs } from './_tsup-dts-rollup';
6
+ export { HighlightParser } from './_tsup-dts-rollup';
@@ -3,17 +3,26 @@ import {
3
3
  defineCommands,
4
4
  defineInputRule,
5
5
  defineNodeSpec,
6
- union,
7
- getNodeType
6
+ getNodeType,
7
+ union
8
8
  } from "@prosekit/core";
9
9
  import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
10
10
 
11
11
  // src/code-block/code-block-highlight.ts
12
12
  import { definePlugin } from "@prosekit/core";
13
+ import { createHighlightPlugin } from "prosemirror-highlight";
14
+ function defineCodeBlockHighlight({ parser }) {
15
+ return definePlugin(
16
+ createHighlightPlugin({ parser, nodeTypes: ["codeBlock"] })
17
+ );
18
+ }
19
+
20
+ // src/code-block/code-block-highlight-deprecated.ts
21
+ import { definePlugin as definePlugin2 } from "@prosekit/core";
13
22
  import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
14
23
  import { DecorationSet } from "@prosekit/pm/view";
15
24
  import { getHighlightDecorations } from "prosemirror-highlightjs";
16
- function defineCodeBlockHighlight(options) {
25
+ function defineCodeBlockHighlightDeprecated(options) {
17
26
  const hljs = options.hljs;
18
27
  const plugin = new ProseMirrorPlugin({
19
28
  key,
@@ -41,7 +50,7 @@ function defineCodeBlockHighlight(options) {
41
50
  }
42
51
  }
43
52
  });
44
- return definePlugin(plugin);
53
+ return definePlugin2(plugin);
45
54
  }
46
55
  var key = new PluginKey("prosekit-code-block-highlight");
47
56
  var blockTypes = ["codeBlock"];
@@ -72,6 +81,7 @@ function defineCodeBlockSpec() {
72
81
  const attrs = node.attrs;
73
82
  return [
74
83
  "pre",
84
+ // TODO: remove class 'hljs'
75
85
  { "data-language": attrs.language, class: "hljs" },
76
86
  ["code", 0]
77
87
  ];
@@ -103,12 +113,20 @@ function defineCodeBlockCommands() {
103
113
  });
104
114
  }
105
115
  function defineCodeBlock(options) {
106
- return union([
116
+ const extensions = [
107
117
  defineCodeBlockSpec(),
108
118
  defineCodeBlockInputRule(),
109
- defineCodeBlockHighlight({ hljs: options == null ? void 0 : options.hljs }),
110
119
  defineCodeBlockCommands()
111
- ]);
120
+ ];
121
+ const parser = options == null ? void 0 : options.parser;
122
+ if (parser) {
123
+ extensions.push(defineCodeBlockHighlight({ parser }));
124
+ }
125
+ const hljs = options == null ? void 0 : options.hljs;
126
+ if (hljs) {
127
+ extensions.push(defineCodeBlockHighlightDeprecated({ hljs }));
128
+ }
129
+ return union(extensions);
112
130
  }
113
131
  export {
114
132
  defineCodeBlock,
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.5",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -125,13 +125,14 @@
125
125
  "@prosekit/pm": "^0.1.0",
126
126
  "highlight.js": "^11.9.0",
127
127
  "prosemirror-flat-list": "^0.4.5",
128
+ "prosemirror-highlight": "^0.3.1",
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.2"
135
136
  },
136
137
  "scripts": {
137
138
  "build:tsup": "tsup",