@prosekit/extensions 0.2.1 → 0.2.3

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,5 +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';
3
4
  import { CommandArgs } from '@prosekit/core';
4
5
  import type { ContentMatch } from '@prosekit/pm/model';
5
6
  import { DedentListOptions } from 'prosemirror-flat-list';
@@ -17,6 +18,7 @@ import { Parser } from 'prosemirror-highlight';
17
18
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
18
19
  import { PluginKey } from '@prosekit/pm/state';
19
20
  import { ProseMirrorNode } from '@prosekit/pm/model';
21
+ import type { Selection as Selection_2 } from '@prosekit/pm/state';
20
22
  import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
21
23
  import { Transaction } from '@prosekit/pm/state';
22
24
  import { UnwrapListOptions } from 'prosemirror-flat-list';
@@ -222,6 +224,15 @@ export declare function defineCodeSpec(): Extension< {
222
224
  MARKS: "code";
223
225
  }>;
224
226
 
227
+ /**
228
+ * Show up a decoration at the drop position when something is dragged over the editor.
229
+ *
230
+ * See [prosemirror-dropcursor](https://github.com/ProseMirror/prosemirror-dropcursor) for more information.
231
+ *
232
+ * @public
233
+ */
234
+ export declare function defineDropCursor(options?: DropCursorOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
235
+
225
236
  /**
226
237
  * Defines an enter rule. An enter rule applies when the text directly in front of
227
238
  * the cursor matches `regex` and user presses Enter. The `regex` should end
@@ -451,6 +462,8 @@ export declare function defineTextBlockEnterRule({ regex, type, attrs, }: TextBl
451
462
  * text is typed into it.
452
463
  *
453
464
  * See also [textblockTypeInputRule](https://prosemirror.net/docs/ref/#inputrules.textblockTypeInputRule)
465
+ *
466
+ * @public
454
467
  */
455
468
  export declare function defineTextBlockInputRule({ regex, type, attrs, }: {
456
469
  /**
@@ -495,6 +508,8 @@ MARKS: "underline";
495
508
  * string is typed.
496
509
  *
497
510
  * See also [wrappingInputRule](https://prosemirror.net/docs/ref/#inputrules.wrappingInputRule)
511
+ *
512
+ * @public
498
513
  */
499
514
  export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
500
515
  /**
@@ -521,6 +536,25 @@ export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
521
536
  join?: (match: RegExpMatchArray, node: ProseMirrorNode) => boolean;
522
537
  }): Extension;
523
538
 
539
+ export declare interface DropCursorOptions {
540
+ /**
541
+ * The color of the cursor. Use `false` to apply no color and rely only on class.
542
+ *
543
+ * @default 'black'
544
+ */
545
+ color?: string | false;
546
+ /**
547
+ * The precise width of the cursor in pixels.
548
+ *
549
+ * @default 1
550
+ */
551
+ width?: number;
552
+ /**
553
+ * A CSS class name to add to the cursor element.
554
+ */
555
+ class?: string;
556
+ }
557
+
524
558
  /**
525
559
  * @public
526
560
  */
@@ -568,6 +602,11 @@ export declare interface ImageAttrs {
568
602
  src?: string | null;
569
603
  }
570
604
 
605
+ /**
606
+ * @internal
607
+ */
608
+ export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
609
+
571
610
  /**
572
611
  * @public
573
612
  */
@@ -646,4 +685,9 @@ export declare type TextBlockEnterRuleOptions = {
646
685
  attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
647
686
  };
648
687
 
688
+ /**
689
+ * @internal
690
+ */
691
+ export declare function withSkipCodeBlock(command: Command): Command;
692
+
649
693
  export { }
@@ -0,0 +1,9 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ export { defineDropCursor } from './_tsup-dts-rollup';
2
+ export { DropCursorOptions } from './_tsup-dts-rollup';
@@ -0,0 +1,9 @@
1
+ // src/drop-cursor/index.ts
2
+ import { definePlugin } from "@prosekit/core";
3
+ import { dropCursor } from "prosemirror-dropcursor";
4
+ function defineDropCursor(options) {
5
+ return definePlugin(() => dropCursor(options));
6
+ }
7
+ export {
8
+ defineDropCursor
9
+ };
@@ -1,3 +1,6 @@
1
+ import {
2
+ isInCodeBlock
3
+ } from "./chunk-DI46QWLX.js";
1
4
  import {
2
5
  defineTextBlockInputRule
3
6
  } from "./chunk-DYFRBXUX.js";
@@ -12,6 +15,18 @@ import {
12
15
  toggleNode,
13
16
  union
14
17
  } 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
15
30
  function defineHeadingSpec() {
16
31
  return defineNodeSpec({
17
32
  name: "heading",
@@ -34,14 +49,17 @@ function defineHeadingSpec() {
34
49
  }
35
50
  function defineHeadingKeymap() {
36
51
  return defineKeymap({
37
- "mod-1": toggleNode({ type: "heading", attrs: { level: 1 } }),
38
- "mod-2": toggleNode({ type: "heading", attrs: { level: 2 } }),
39
- "mod-3": toggleNode({ type: "heading", attrs: { level: 3 } }),
40
- "mod-4": toggleNode({ type: "heading", attrs: { level: 4 } }),
41
- "mod-5": toggleNode({ type: "heading", attrs: { level: 5 } }),
42
- "mod-6": toggleNode({ type: "heading", attrs: { level: 6 } })
52
+ "mod-1": toggleHeadingKeybinding(1),
53
+ "mod-2": toggleHeadingKeybinding(2),
54
+ "mod-3": toggleHeadingKeybinding(3),
55
+ "mod-4": toggleHeadingKeybinding(4),
56
+ "mod-5": toggleHeadingKeybinding(5),
57
+ "mod-6": toggleHeadingKeybinding(6)
43
58
  });
44
59
  }
60
+ function toggleHeadingKeybinding(level) {
61
+ return withSkipCodeBlock(toggleNode({ type: "heading", attrs: { level } }));
62
+ }
45
63
  function defineHeadingInputRule() {
46
64
  return defineTextBlockInputRule({
47
65
  regex: /^(#{1,6})\s$/,
@@ -13,6 +13,7 @@ function defineImageSpec() {
13
13
  },
14
14
  group: "block",
15
15
  defining: true,
16
+ draggable: true,
16
17
  parseDOM: [
17
18
  {
18
19
  tag: "img[src]",
@@ -1,3 +1,7 @@
1
+ import {
2
+ isInCodeBlock
3
+ } from "./chunk-DI46QWLX.js";
4
+
1
5
  // src/placeholder/index.ts
2
6
  import { definePlugin } from "@prosekit/core";
3
7
  import "@prosekit/pm/model";
@@ -14,6 +18,9 @@ function createPlaceholderPlugin(options) {
14
18
  if (options.strategy === "doc" && !isDocEmpty(state.doc)) {
15
19
  return null;
16
20
  }
21
+ if (isInCodeBlock(state.selection)) {
22
+ return null;
23
+ }
17
24
  const placeholderText = options.placeholder;
18
25
  const deco = createPlaceholderDecoration(state, placeholderText);
19
26
  if (!deco) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -55,6 +55,11 @@
55
55
  "import": "./dist/prosekit-extensions-code-block.js",
56
56
  "default": "./dist/prosekit-extensions-code-block.js"
57
57
  },
58
+ "./drop-cursor": {
59
+ "types": "./dist/prosekit-extensions-drop-cursor.d.ts",
60
+ "import": "./dist/prosekit-extensions-drop-cursor.js",
61
+ "default": "./dist/prosekit-extensions-drop-cursor.js"
62
+ },
58
63
  "./heading": {
59
64
  "types": "./dist/prosekit-extensions-heading.d.ts",
60
65
  "import": "./dist/prosekit-extensions-heading.js",
@@ -121,8 +126,9 @@
121
126
  "dist"
122
127
  ],
123
128
  "dependencies": {
124
- "@prosekit/core": "^0.2.0",
129
+ "@prosekit/core": "^0.2.3",
125
130
  "@prosekit/pm": "^0.1.1",
131
+ "prosemirror-dropcursor": "^1.8.1",
126
132
  "prosemirror-flat-list": "^0.4.5",
127
133
  "prosemirror-highlight": "^0.4.0"
128
134
  },
@@ -136,10 +142,10 @@
136
142
  },
137
143
  "devDependencies": {
138
144
  "@prosekit/dev": "*",
139
- "shikiji": "^0.9.16",
145
+ "shikiji": "^0.9.17",
140
146
  "tsup": "^8.0.1",
141
147
  "typescript": "^5.3.3",
142
- "vitest": "^1.1.1"
148
+ "vitest": "^1.1.3"
143
149
  },
144
150
  "scripts": {
145
151
  "build:tsup": "tsup",
@@ -166,6 +172,9 @@
166
172
  "code-block": [
167
173
  "./dist/prosekit-extensions-code-block.d.ts"
168
174
  ],
175
+ "drop-cursor": [
176
+ "./dist/prosekit-extensions-drop-cursor.d.ts"
177
+ ],
169
178
  "heading": [
170
179
  "./dist/prosekit-extensions-heading.d.ts"
171
180
  ],