@prosekit/extensions 0.2.3 → 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.
@@ -1,8 +1,6 @@
1
1
  import { Attrs } from '@prosekit/pm/model';
2
2
  import type { BundledTheme } from 'shikiji';
3
- import type { Command } from '@prosekit/pm/state';
4
3
  import { CommandArgs } from '@prosekit/core';
5
- import type { ContentMatch } from '@prosekit/pm/model';
6
4
  import { DedentListOptions } from 'prosemirror-flat-list';
7
5
  import { EditorState } from '@prosekit/pm/state';
8
6
  import { Extension } from '@prosekit/core';
@@ -12,7 +10,6 @@ import { InputRule } from '@prosekit/pm/inputrules';
12
10
  import { ListAttributes } from 'prosemirror-flat-list';
13
11
  import { NodeRange } from 'prosemirror-model';
14
12
  import { NodeType } from '@prosekit/pm/model';
15
- import { NodeType as NodeType_2 } from 'prosemirror-model';
16
13
  import { Options } from 'tsup';
17
14
  import { Parser } from 'prosemirror-highlight';
18
15
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
@@ -65,8 +62,6 @@ export declare const default_alias_1: {
65
62
  };
66
63
  };
67
64
 
68
- export declare function defaultBlockAt(match: ContentMatch): NodeType_2 | null;
69
-
70
65
  export declare function defaultCanMatch({ state }: {
71
66
  state: EditorState;
72
67
  }): boolean;
@@ -130,6 +125,10 @@ toggleCode: [];
130
125
  export declare function defineCodeBlock(): Extension< {
131
126
  NODES: "codeBlock";
132
127
  COMMAND_ARGS: {
128
+ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
129
+ insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
130
+ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
131
+ setCodeBlockAttrs: [attrs: CodeBlockAttrs];
133
132
  setCodeBlockLanguage: [language: string];
134
133
  };
135
134
  }>;
@@ -141,6 +140,10 @@ setCodeBlockLanguage: [language: string];
141
140
  */
142
141
  declare function defineCodeBlockCommands(): Extension< {
143
142
  COMMAND_ARGS: {
143
+ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
144
+ insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
145
+ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
146
+ setCodeBlockAttrs: [attrs: CodeBlockAttrs];
144
147
  setCodeBlockLanguage: [language: string];
145
148
  };
146
149
  }>;
@@ -193,7 +196,7 @@ declare function defineCodeBlockShikiji(options?: {
193
196
  /**
194
197
  * The shikiji theme to use.
195
198
  *
196
- * @default 'github-light'
199
+ * @default 'one-dark-pro'
197
200
  */
198
201
  theme?: BundledTheme;
199
202
  }): Extension;
@@ -330,6 +333,7 @@ export declare function defineLink(): Extension< {
330
333
  MARKS: "link";
331
334
  COMMAND_ARGS: {
332
335
  addLink: [attrs: LinkAttrs];
336
+ removeLink: [];
333
337
  toggleLink: [attrs: LinkAttrs];
334
338
  };
335
339
  }>;
@@ -337,6 +341,7 @@ toggleLink: [attrs: LinkAttrs];
337
341
  export declare function defineLinkCommands(): Extension< {
338
342
  COMMAND_ARGS: {
339
343
  addLink: [attrs: LinkAttrs];
344
+ removeLink: [];
340
345
  toggleLink: [attrs: LinkAttrs];
341
346
  };
342
347
  }>;
@@ -604,6 +609,8 @@ export declare interface ImageAttrs {
604
609
 
605
610
  /**
606
611
  * @internal
612
+ *
613
+ * @deprecated Use the one from `@prosekit/core` instead.
607
614
  */
608
615
  export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
609
616
 
@@ -631,10 +638,6 @@ export declare interface MentionAttrs {
631
638
  value: string;
632
639
  }
633
640
 
634
- export declare const NO_BREAK_SPACE = "\u00A0";
635
-
636
- export declare const OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
637
-
638
641
  export declare interface PlaceholderOptions {
639
642
  /**
640
643
  * The placeholder text to use.
@@ -685,9 +688,4 @@ export declare type TextBlockEnterRuleOptions = {
685
688
  attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
686
689
  };
687
690
 
688
- /**
689
- * @internal
690
- */
691
- export declare function withSkipCodeBlock(command: Command): Command;
692
-
693
691
  export { }
@@ -1,7 +1,3 @@
1
- import {
2
- OBJECT_REPLACEMENT_CHARACTER
3
- } from "./chunk-HQZORKGY.js";
4
-
5
1
  // src/autocomplete/index.ts
6
2
  import {
7
3
  Facet,
@@ -9,6 +5,7 @@ import {
9
5
  } from "@prosekit/core";
10
6
 
11
7
  // src/autocomplete/plugin.ts
8
+ import { OBJECT_REPLACEMENT_CHARACTER } from "@prosekit/core";
12
9
  import { Plugin } from "@prosekit/pm/state";
13
10
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
14
11
 
@@ -1,6 +1,3 @@
1
- import {
2
- OBJECT_REPLACEMENT_CHARACTER
3
- } from "./chunk-HQZORKGY.js";
4
1
  import {
5
2
  defineTextBlockInputRule
6
3
  } from "./chunk-DYFRBXUX.js";
@@ -9,19 +6,33 @@ import {
9
6
  import { union } from "@prosekit/core";
10
7
 
11
8
  // src/code-block/code-block-commands.ts
12
- import { defineCommands } from "@prosekit/core";
9
+ import {
10
+ defineCommands,
11
+ insertNode,
12
+ setBlockType,
13
+ setNodeAttrs,
14
+ toggleNode
15
+ } from "@prosekit/core";
13
16
  function defineCodeBlockCommands() {
14
17
  return defineCommands({
15
- setCodeBlockLanguage: (language) => (state, dispatch) => {
16
- const pos = state.selection.$from.before();
17
- const codeBlock = state.doc.nodeAt(pos);
18
- if (!codeBlock || codeBlock.type.name !== "codeBlock") {
19
- return false;
20
- }
21
- const { tr } = state;
22
- tr.setNodeMarkup(pos, void 0, { language });
23
- dispatch == null ? void 0 : dispatch(tr);
24
- return true;
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 });
25
36
  }
26
37
  });
27
38
  }
@@ -42,7 +53,8 @@ import {
42
53
  Facet,
43
54
  getNodeType,
44
55
  isTextSelection,
45
- keymapFacet
56
+ keymapFacet,
57
+ OBJECT_REPLACEMENT_CHARACTER
46
58
  } from "@prosekit/core";
47
59
  function defineEnterRule({
48
60
  regex,
@@ -141,20 +153,8 @@ function getAttrs(match) {
141
153
  }
142
154
 
143
155
  // src/code-block/code-block-keymap.ts
144
- import { defineKeymap } from "@prosekit/core";
156
+ import { defaultBlockAt, defineKeymap } from "@prosekit/core";
145
157
  import { TextSelection } from "@prosekit/pm/state";
146
-
147
- // src/utils/default-block-at.ts
148
- function defaultBlockAt(match) {
149
- for (let i = 0; i < match.edgeCount; i++) {
150
- const { type } = match.edge(i);
151
- if (type.isTextblock && !type.hasRequiredAttrs())
152
- return type;
153
- }
154
- return null;
155
- }
156
-
157
- // src/code-block/code-block-keymap.ts
158
158
  function defineCodeBlockKeymap() {
159
159
  return defineKeymap({
160
160
  Enter: existCodeBlock
@@ -190,36 +190,52 @@ var existCodeBlock = (state, dispatch) => {
190
190
  };
191
191
 
192
192
  // src/code-block/code-block-shikiji.ts
193
+ import { ProseKitError } from "@prosekit/core";
193
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
+ }
194
214
  function createHighlighterLoader() {
195
215
  let shikijiImport;
196
216
  let highlighter;
197
- const languages = /* @__PURE__ */ new Set();
198
- const themes = /* @__PURE__ */ new Set();
217
+ const loadLangs = /* @__PURE__ */ new Set();
218
+ const loadThemes = /* @__PURE__ */ new Set();
199
219
  return function highlighterLoader(lang, theme) {
200
220
  if (!shikijiImport) {
201
- shikijiImport = import("shikiji").then(async ({ getHighlighter }) => {
202
- const fallbackLang = "md";
203
- highlighter = await getHighlighter({
204
- langs: [fallbackLang],
205
- themes: []
206
- });
221
+ shikijiImport = createHighlighter(theme).then((result) => {
222
+ highlighter = result;
207
223
  });
208
224
  return { promise: shikijiImport };
209
225
  }
210
226
  if (!highlighter) {
211
227
  return { promise: shikijiImport };
212
228
  }
213
- if (!languages.has(lang)) {
229
+ if (!loadLangs.has(lang)) {
214
230
  const promise = highlighter.loadLanguage(lang).then(() => {
215
- languages.add(lang);
231
+ loadLangs.add(lang);
216
232
  }).catch(() => {
217
233
  });
218
234
  return { promise };
219
235
  }
220
- if (!themes.has(theme)) {
236
+ if (!loadThemes.has(theme)) {
221
237
  const promise = highlighter.loadTheme(theme).then(() => {
222
- themes.add(theme);
238
+ loadThemes.add(theme);
223
239
  }).catch(() => {
224
240
  });
225
241
  return { promise };
@@ -243,7 +259,7 @@ function createLazyParser(theme) {
243
259
  };
244
260
  }
245
261
  function defineCodeBlockShikiji(options) {
246
- const theme = (options == null ? void 0 : options.theme) || "github-light";
262
+ const theme = (options == null ? void 0 : options.theme) || "one-dark-pro";
247
263
  const parser = createLazyParser(theme);
248
264
  return defineCodeBlockHighlight({ parser });
249
265
  }
@@ -1,6 +1,3 @@
1
- import {
2
- isInCodeBlock
3
- } from "./chunk-DI46QWLX.js";
4
1
  import {
5
2
  defineTextBlockInputRule
6
3
  } from "./chunk-DYFRBXUX.js";
@@ -13,20 +10,9 @@ import {
13
10
  insertNode,
14
11
  setBlockType,
15
12
  toggleNode,
16
- union
13
+ union,
14
+ withSkipCodeBlock
17
15
  } from "@prosekit/core";
18
-
19
- // src/utils/with-skip-code-block.ts
20
- function withSkipCodeBlock(command) {
21
- return (state, dispatch, view) => {
22
- if (isInCodeBlock(state.selection)) {
23
- return false;
24
- }
25
- return command(state, dispatch, view);
26
- };
27
- }
28
-
29
- // src/heading/index.ts
30
16
  function defineHeadingSpec() {
31
17
  return defineNodeSpec({
32
18
  name: "heading",
@@ -4,6 +4,7 @@ import {
4
4
  addMark,
5
5
  defineMarkSpec,
6
6
  union,
7
+ removeMark,
7
8
  toggleMark
8
9
  } from "@prosekit/core";
9
10
  function defineLinkSpec() {
@@ -31,6 +32,7 @@ function defineLinkSpec() {
31
32
  function defineLinkCommands() {
32
33
  return defineCommands({
33
34
  addLink: (attrs) => addMark({ type: "link", attrs }),
35
+ removeLink: () => removeMark({ type: "link" }),
34
36
  toggleLink: (attrs) => toggleMark({ type: "link", attrs })
35
37
  });
36
38
  }
@@ -1,12 +1,16 @@
1
- import {
2
- isInCodeBlock
3
- } from "./chunk-DI46QWLX.js";
4
-
5
1
  // src/placeholder/index.ts
6
2
  import { definePlugin } from "@prosekit/core";
7
3
  import "@prosekit/pm/model";
8
4
  import { Plugin, PluginKey } from "@prosekit/pm/state";
9
5
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
6
+
7
+ // src/utils/is-in-code-block.ts
8
+ function isInCodeBlock(selection) {
9
+ const type = selection.$from.parent.type;
10
+ return type.spec.code && type.isBlock;
11
+ }
12
+
13
+ // src/placeholder/index.ts
10
14
  function definePlaceholder(options) {
11
15
  return definePlugin(createPlaceholderPlugin(options));
12
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.2.3",
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.3",
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.17",
145
+ "shikiji": "^0.9.19",
146
146
  "tsup": "^8.0.1",
147
147
  "typescript": "^5.3.3",
148
- "vitest": "^1.1.3"
148
+ "vitest": "^1.2.0"
149
149
  },
150
150
  "scripts": {
151
151
  "build:tsup": "tsup",
@@ -1,9 +0,0 @@
1
- // src/utils/is-in-code-block.ts
2
- function isInCodeBlock(selection) {
3
- const type = selection.$from.parent.type;
4
- return type.spec.code && type.isBlock;
5
- }
6
-
7
- export {
8
- isInCodeBlock
9
- };
@@ -1,6 +0,0 @@
1
- // src/utils/unicode.ts
2
- var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
3
-
4
- export {
5
- OBJECT_REPLACEMENT_CHARACTER
6
- };