@prosekit/extensions 0.2.1 → 0.2.2

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';
@@ -568,6 +570,8 @@ export declare interface ImageAttrs {
568
570
  src?: string | null;
569
571
  }
570
572
 
573
+ export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
574
+
571
575
  /**
572
576
  * @public
573
577
  */
@@ -646,4 +650,6 @@ export declare type TextBlockEnterRuleOptions = {
646
650
  attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
647
651
  };
648
652
 
653
+ export declare function withSkipCodeBlock(command: Command): Command;
654
+
649
655
  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
+ };
@@ -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$/,
@@ -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.2",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -121,7 +121,7 @@
121
121
  "dist"
122
122
  ],
123
123
  "dependencies": {
124
- "@prosekit/core": "^0.2.0",
124
+ "@prosekit/core": "^0.2.2",
125
125
  "@prosekit/pm": "^0.1.1",
126
126
  "prosemirror-flat-list": "^0.4.5",
127
127
  "prosemirror-highlight": "^0.4.0"