@prosekit/extensions 0.2.4 → 0.3.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.
@@ -15,7 +15,6 @@ import { Parser } from 'prosemirror-highlight';
15
15
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
16
16
  import { PluginKey } from '@prosekit/pm/state';
17
17
  import { ProseMirrorNode } from '@prosekit/pm/model';
18
- import type { Selection as Selection_2 } from '@prosekit/pm/state';
19
18
  import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
20
19
  import { Transaction } from '@prosekit/pm/state';
21
20
  import { UnwrapListOptions } from 'prosemirror-flat-list';
@@ -75,6 +74,12 @@ export declare function defineBlockquote(): Extension< {
75
74
  NODES: "blockquote";
76
75
  }>;
77
76
 
77
+ /**
78
+ * Wraps the text block in a blockquote when `>` is typed at the start of a new
79
+ * line followed by a space.
80
+ */
81
+ export declare function defineBlockquoteInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
82
+
78
83
  export declare function defineBlockquoteSpec(): Extension< {
79
84
  NODES: "blockquote";
80
85
  }>;
@@ -125,7 +130,10 @@ toggleCode: [];
125
130
  export declare function defineCodeBlock(): Extension< {
126
131
  NODES: "codeBlock";
127
132
  COMMAND_ARGS: {
128
- setCodeBlockLanguage: [language: string];
133
+ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
134
+ insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
135
+ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
136
+ setCodeBlockAttrs: [attrs: CodeBlockAttrs];
129
137
  };
130
138
  }>;
131
139
 
@@ -136,7 +144,10 @@ setCodeBlockLanguage: [language: string];
136
144
  */
137
145
  declare function defineCodeBlockCommands(): Extension< {
138
146
  COMMAND_ARGS: {
139
- setCodeBlockLanguage: [language: string];
147
+ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
148
+ insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
149
+ toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
150
+ setCodeBlockAttrs: [attrs: CodeBlockAttrs];
140
151
  };
141
152
  }>;
142
153
  export { defineCodeBlockCommands }
@@ -188,7 +199,7 @@ declare function defineCodeBlockShikiji(options?: {
188
199
  /**
189
200
  * The shikiji theme to use.
190
201
  *
191
- * @default 'github-light'
202
+ * @default 'one-dark-pro'
192
203
  */
193
204
  theme?: BundledTheme;
194
205
  }): Extension;
@@ -257,6 +268,10 @@ toggleHeading: [attrs?: HeadingAttrs | undefined];
257
268
  };
258
269
  }>;
259
270
 
271
+ /**
272
+ * Converts the text block to a heading when `#` is typed at the start of a new
273
+ * line followed by a space.
274
+ */
260
275
  export declare function defineHeadingInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
261
276
 
262
277
  export declare function defineHeadingKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
@@ -327,6 +342,7 @@ COMMAND_ARGS: {
327
342
  addLink: [attrs: LinkAttrs];
328
343
  removeLink: [];
329
344
  toggleLink: [attrs: LinkAttrs];
345
+ expandLink: [];
330
346
  };
331
347
  }>;
332
348
 
@@ -335,6 +351,7 @@ COMMAND_ARGS: {
335
351
  addLink: [attrs: LinkAttrs];
336
352
  removeLink: [];
337
353
  toggleLink: [attrs: LinkAttrs];
354
+ expandLink: [];
338
355
  };
339
356
  }>;
340
357
 
@@ -500,6 +517,18 @@ export declare function defineUnderlineSpec(): Extension< {
500
517
  MARKS: "underline";
501
518
  }>;
502
519
 
520
+ /**
521
+ * Shows a virtual selection when the editor is not focused. When the editor is
522
+ * not focused, the selected inline content will be wrapped in a `<span>`
523
+ * element with the class `prosekit-virtual-selection`.
524
+ *
525
+ * This is useful when you want to move the focus to an element outside the
526
+ * editor, but still want to show the selection.
527
+ *
528
+ * @public
529
+ */
530
+ export declare function defineVirtualSelection(): Extension;
531
+
503
532
  /**
504
533
  * Defines an input rule for automatically wrapping a textblock when a given
505
534
  * string is typed.
@@ -599,13 +628,6 @@ export declare interface ImageAttrs {
599
628
  src?: string | null;
600
629
  }
601
630
 
602
- /**
603
- * @internal
604
- *
605
- * @deprecated Use the one from `@prosekit/core` instead.
606
- */
607
- export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
608
-
609
631
  /**
610
632
  * @public
611
633
  */
@@ -1,4 +1,4 @@
1
- /* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.5/node_modules/prosemirror-flat-list/dist/style.css */
1
+ /* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.6/node_modules/prosemirror-flat-list/dist/style.css */
2
2
  .prosemirror-flat-list {
3
3
  padding: 0;
4
4
  margin-top: 0;
@@ -1,2 +1,3 @@
1
1
  export { defineBlockquoteSpec } from './_tsup-dts-rollup';
2
+ export { defineBlockquoteInputRule } from './_tsup-dts-rollup';
2
3
  export { defineBlockquote } from './_tsup-dts-rollup';
@@ -1,3 +1,7 @@
1
+ import {
2
+ defineWrappingInputRule
3
+ } from "./chunk-DYFRBXUX.js";
4
+
1
5
  // src/blockquote/index.ts
2
6
  import { defineNodeSpec, union } from "@prosekit/core";
3
7
  function defineBlockquoteSpec() {
@@ -12,10 +16,17 @@ function defineBlockquoteSpec() {
12
16
  }
13
17
  });
14
18
  }
19
+ function defineBlockquoteInputRule() {
20
+ return defineWrappingInputRule({
21
+ regex: /^>\s/,
22
+ type: "blockquote"
23
+ });
24
+ }
15
25
  function defineBlockquote() {
16
- return union([defineBlockquoteSpec()]);
26
+ return union([defineBlockquoteSpec(), defineBlockquoteInputRule()]);
17
27
  }
18
28
  export {
19
29
  defineBlockquote,
30
+ defineBlockquoteInputRule,
20
31
  defineBlockquoteSpec
21
32
  };
@@ -6,19 +6,26 @@ import {
6
6
  import { union } from "@prosekit/core";
7
7
 
8
8
  // src/code-block/code-block-commands.ts
9
- import { defineCommands } from "@prosekit/core";
9
+ import {
10
+ defineCommands,
11
+ insertNode,
12
+ setBlockType,
13
+ setNodeAttrs,
14
+ toggleNode
15
+ } from "@prosekit/core";
10
16
  function defineCodeBlockCommands() {
11
17
  return defineCommands({
12
- setCodeBlockLanguage: (language) => (state, dispatch) => {
13
- const pos = state.selection.$from.before();
14
- const codeBlock = state.doc.nodeAt(pos);
15
- if (!codeBlock || codeBlock.type.name !== "codeBlock") {
16
- return false;
17
- }
18
- const { tr } = state;
19
- tr.setNodeMarkup(pos, void 0, { language });
20
- dispatch == null ? void 0 : dispatch(tr);
21
- 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 });
22
29
  }
23
30
  });
24
31
  }
@@ -176,36 +183,52 @@ var existCodeBlock = (state, dispatch) => {
176
183
  };
177
184
 
178
185
  // src/code-block/code-block-shikiji.ts
186
+ import { ProseKitError } from "@prosekit/core";
179
187
  import { createParser } from "prosemirror-highlight/shikiji";
188
+ async function importGetHighlighter() {
189
+ try {
190
+ const { getHighlighter } = await import("shikiji");
191
+ return getHighlighter;
192
+ } catch (error) {
193
+ throw new ProseKitError(
194
+ "Failed to import package 'shikiji'. Make sure you've installed it.",
195
+ { cause: error }
196
+ );
197
+ }
198
+ }
199
+ async function createHighlighter(theme) {
200
+ const getHighlighter = await importGetHighlighter();
201
+ const fallbackLang = "md";
202
+ return await getHighlighter({
203
+ langs: [fallbackLang],
204
+ themes: [theme]
205
+ });
206
+ }
180
207
  function createHighlighterLoader() {
181
208
  let shikijiImport;
182
209
  let highlighter;
183
- const languages = /* @__PURE__ */ new Set();
184
- const themes = /* @__PURE__ */ new Set();
210
+ const loadLangs = /* @__PURE__ */ new Set();
211
+ const loadThemes = /* @__PURE__ */ new Set();
185
212
  return function highlighterLoader(lang, theme) {
186
213
  if (!shikijiImport) {
187
- shikijiImport = import("shikiji").then(async ({ getHighlighter }) => {
188
- const fallbackLang = "md";
189
- highlighter = await getHighlighter({
190
- langs: [fallbackLang],
191
- themes: []
192
- });
214
+ shikijiImport = createHighlighter(theme).then((result) => {
215
+ highlighter = result;
193
216
  });
194
217
  return { promise: shikijiImport };
195
218
  }
196
219
  if (!highlighter) {
197
220
  return { promise: shikijiImport };
198
221
  }
199
- if (!languages.has(lang)) {
222
+ if (!loadLangs.has(lang)) {
200
223
  const promise = highlighter.loadLanguage(lang).then(() => {
201
- languages.add(lang);
224
+ loadLangs.add(lang);
202
225
  }).catch(() => {
203
226
  });
204
227
  return { promise };
205
228
  }
206
- if (!themes.has(theme)) {
229
+ if (!loadThemes.has(theme)) {
207
230
  const promise = highlighter.loadTheme(theme).then(() => {
208
- themes.add(theme);
231
+ loadThemes.add(theme);
209
232
  }).catch(() => {
210
233
  });
211
234
  return { promise };
@@ -229,7 +252,7 @@ function createLazyParser(theme) {
229
252
  };
230
253
  }
231
254
  function defineCodeBlockShikiji(options) {
232
- const theme = (options == null ? void 0 : options.theme) || "github-light";
255
+ const theme = (options == null ? void 0 : options.theme) || "one-dark-pro";
233
256
  const parser = createLazyParser(theme);
234
257
  return defineCodeBlockHighlight({ parser });
235
258
  }
@@ -5,7 +5,8 @@ import {
5
5
  defineMarkSpec,
6
6
  union,
7
7
  removeMark,
8
- toggleMark
8
+ toggleMark,
9
+ expandMark
9
10
  } from "@prosekit/core";
10
11
  function defineLinkSpec() {
11
12
  return defineMarkSpec({
@@ -33,7 +34,8 @@ function defineLinkCommands() {
33
34
  return defineCommands({
34
35
  addLink: (attrs) => addMark({ type: "link", attrs }),
35
36
  removeLink: () => removeMark({ type: "link" }),
36
- toggleLink: (attrs) => toggleMark({ type: "link", attrs })
37
+ toggleLink: (attrs) => toggleMark({ type: "link", attrs }),
38
+ expandLink: () => expandMark({ type: "link" })
37
39
  });
38
40
  }
39
41
  function defineLink() {
@@ -1,16 +1,8 @@
1
1
  // src/placeholder/index.ts
2
- import { definePlugin } from "@prosekit/core";
2
+ import { definePlugin, isInCodeBlock } from "@prosekit/core";
3
3
  import "@prosekit/pm/model";
4
4
  import { Plugin, PluginKey } from "@prosekit/pm/state";
5
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
14
6
  function definePlaceholder(options) {
15
7
  return definePlugin(createPlaceholderPlugin(options));
16
8
  }
@@ -0,0 +1 @@
1
+ export { defineVirtualSelection } from './_tsup-dts-rollup';
@@ -0,0 +1,59 @@
1
+ // src/virtual-selection/index.ts
2
+ import { definePlugin } from "@prosekit/core";
3
+ import {
4
+ PluginKey,
5
+ ProseMirrorPlugin
6
+ } from "@prosekit/pm/state";
7
+ import { Decoration, DecorationSet } from "@prosekit/pm/view";
8
+ function defineVirtualSelection() {
9
+ return definePlugin(virtualSelectionPlugin);
10
+ }
11
+ var key = new PluginKey("prosekit-virtual-selection");
12
+ function getFocusMeta(tr) {
13
+ return tr.getMeta(key);
14
+ }
15
+ function setFocusMeta(tr, value) {
16
+ return tr.setMeta(key, value);
17
+ }
18
+ function getFocusState(state) {
19
+ return key.getState(state);
20
+ }
21
+ var virtualSelectionPlugin = new ProseMirrorPlugin({
22
+ key,
23
+ state: {
24
+ init: () => false,
25
+ apply: (tr, value) => {
26
+ var _a;
27
+ return (_a = getFocusMeta(tr)) != null ? _a : value;
28
+ }
29
+ },
30
+ props: {
31
+ handleDOMEvents: {
32
+ focus: (view) => {
33
+ view.dispatch(setFocusMeta(view.state.tr, false));
34
+ },
35
+ blur: (view) => {
36
+ var _a;
37
+ const dom = view.dom;
38
+ const activeElement = (_a = dom == null ? void 0 : dom.ownerDocument) == null ? void 0 : _a.activeElement;
39
+ if (activeElement === dom)
40
+ return;
41
+ view.dispatch(setFocusMeta(view.state.tr, true));
42
+ }
43
+ },
44
+ decorations: (state) => {
45
+ const { selection, doc } = state;
46
+ if (selection.empty || !getFocusState(state)) {
47
+ return null;
48
+ }
49
+ return DecorationSet.create(doc, [
50
+ Decoration.inline(selection.from, selection.to, {
51
+ class: "prosekit-virtual-selection"
52
+ })
53
+ ]);
54
+ }
55
+ }
56
+ });
57
+ export {
58
+ defineVirtualSelection
59
+ };
@@ -0,0 +1,6 @@
1
+ /* src/virtual-selection/style.css */
2
+ .prosekit-virtual-selection {
3
+ background-color: Highlight;
4
+ box-shadow: 0 0 0 3px Highlight;
5
+ border-radius: 2px;
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.3.0",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -120,17 +120,25 @@
120
120
  "types": "./dist/prosekit-extensions-underline.d.ts",
121
121
  "import": "./dist/prosekit-extensions-underline.js",
122
122
  "default": "./dist/prosekit-extensions-underline.js"
123
+ },
124
+ "./virtual-selection": {
125
+ "types": "./dist/prosekit-extensions-virtual-selection.d.ts",
126
+ "import": "./dist/prosekit-extensions-virtual-selection.js",
127
+ "default": "./dist/prosekit-extensions-virtual-selection.js"
128
+ },
129
+ "./virtual-selection/style.css": {
130
+ "default": "./dist/virtual-selection/style.css"
123
131
  }
124
132
  },
125
133
  "files": [
126
134
  "dist"
127
135
  ],
128
136
  "dependencies": {
129
- "@prosekit/core": "^0.2.4",
137
+ "@prosekit/core": "^0.3.0",
130
138
  "@prosekit/pm": "^0.1.1",
131
139
  "prosemirror-dropcursor": "^1.8.1",
132
- "prosemirror-flat-list": "^0.4.5",
133
- "prosemirror-highlight": "^0.4.0"
140
+ "prosemirror-flat-list": "^0.4.6",
141
+ "prosemirror-highlight": "^0.4.1"
134
142
  },
135
143
  "peerDependencies": {
136
144
  "shikiji": ">= 0.9.0"
@@ -142,10 +150,10 @@
142
150
  },
143
151
  "devDependencies": {
144
152
  "@prosekit/dev": "*",
145
- "shikiji": "^0.9.18",
153
+ "shikiji": "^0.10.2",
146
154
  "tsup": "^8.0.1",
147
155
  "typescript": "^5.3.3",
148
- "vitest": "^1.1.3"
156
+ "vitest": "^1.2.2"
149
157
  },
150
158
  "scripts": {
151
159
  "build:tsup": "tsup",
@@ -207,6 +215,9 @@
207
215
  ],
208
216
  "underline": [
209
217
  "./dist/prosekit-extensions-underline.d.ts"
218
+ ],
219
+ "virtual-selection": [
220
+ "./dist/prosekit-extensions-virtual-selection.d.ts"
210
221
  ]
211
222
  }
212
223
  }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export {}