@prosekit/extensions 0.4.3 → 0.4.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.
@@ -29,7 +29,7 @@ import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
29
29
  import { Transaction } from '@prosekit/pm/state';
30
30
  import { UnwrapListOptions } from 'prosemirror-flat-list';
31
31
 
32
- export declare function applyMarkRules(rules: MarkRule[], transactions: readonly Transaction[], oldState: EditorState, newState: EditorState): Transaction | null;
32
+ export declare function applyMarkRules(rules: MarkRuleOptions[], transactions: readonly Transaction[], oldState: EditorState, newState: EditorState): Transaction | null;
33
33
 
34
34
  declare class AutocompleteRule {
35
35
  readonly regex: RegExp;
@@ -118,6 +118,11 @@ export declare function createAutocompletePlugin({ getRules, }: {
118
118
  */
119
119
  export declare function createLazyParser(highlighterOptions: HighlighterOptions): Parser;
120
120
 
121
+ /**
122
+ * @internal
123
+ */
124
+ export declare function createMarkInputRule({ regex, type, attrs, }: MarkInputRuleOptions): InputRule;
125
+
121
126
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
122
127
 
123
128
  export declare const default_alias_1: {
@@ -165,6 +170,8 @@ toggleBold: [];
165
170
  };
166
171
  }>;
167
172
 
173
+ export declare function defineBoldInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
174
+
168
175
  export declare function defineBoldKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
169
176
 
170
177
  export declare function defineBoldSpec(): Extension< {
@@ -283,6 +290,10 @@ toggleCode: [];
283
290
  };
284
291
  }>;
285
292
 
293
+ export declare function defineCodeInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
294
+
295
+ export declare function defineCodeKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
296
+
286
297
  /**
287
298
  * @public
288
299
  */
@@ -385,9 +396,9 @@ toggleItalic: [];
385
396
  };
386
397
  }>;
387
398
 
388
- export declare function defineItalicKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
399
+ export declare function defineItalicInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
389
400
 
390
- export declare function defineItalicKeymap_alias_1(): Extension<ExtensionTyping<string, string, CommandArgs>>;
401
+ export declare function defineItalicKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
391
402
 
392
403
  export declare function defineItalicSpec(): Extension< {
393
404
  MARKS: "italic";
@@ -481,11 +492,21 @@ export declare function defineListSpec(): Extension<{
481
492
  NODES: "list";
482
493
  }>;
483
494
 
495
+ /**
496
+ * Defines an input rule for automatically adding inline marks when a given
497
+ * pattern is typed.
498
+ *
499
+ * @public
500
+ */
501
+ export declare function defineMarkInputRule(options: MarkInputRuleOptions): Extension;
502
+
484
503
  /**
485
504
  * A mark rule is something that can automatically apply marks to text if it
486
505
  * matches a certain pattern, and remove them if it doesn't match anymore.
487
506
  */
488
- export declare function defineMarkRule(options: MarkRuleOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
507
+ declare function defineMarkRule(options: MarkRuleOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
508
+ export { defineMarkRule }
509
+ export { defineMarkRule as defineMarkRule_alias_1 }
489
510
 
490
511
  /**
491
512
  * @public
@@ -537,6 +558,8 @@ toggleStrike: [];
537
558
  };
538
559
  }>;
539
560
 
561
+ export declare function defineStrikeInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
562
+
540
563
  export declare function defineStrikeKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
541
564
 
542
565
  export declare function defineStrikeSpec(): Extension< {
@@ -626,8 +649,9 @@ export declare function defineTextBlockEnterRule({ regex, type, attrs, stop, }:
626
649
  */
627
650
  export declare function defineTextBlockInputRule({ regex, type, attrs, }: {
628
651
  /**
629
- * The regular expression to match against. You'll usually want to start it
630
- * with `^` to that it is only matched at the start of a textblock.
652
+ * The regular expression to match against, which should end with `$`. It
653
+ * usually also starts with `^` to that it is only matched at the start of a
654
+ * textblock.
631
655
  */
632
656
  regex: RegExp;
633
657
  /**
@@ -684,8 +708,9 @@ export declare function defineVirtualSelection(): Extension;
684
708
  */
685
709
  export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
686
710
  /**
687
- * The regular expression to match against. You'll usually want to start it
688
- * with `^` to that it is only matched at the start of a textblock.
711
+ * The regular expression to match against, which should end with `$`. It
712
+ * usually also starts with `^` to that it is only matched at the start of a
713
+ * textblock.
689
714
  */
690
715
  regex: RegExp;
691
716
  /**
@@ -837,13 +862,25 @@ export declare interface LinkAttrs {
837
862
  export { ListDOMSerializer }
838
863
 
839
864
  /**
840
- * @internal
865
+ * Options for {@link defineMarkInputRule}.
866
+ *
867
+ * @public
841
868
  */
842
- export declare class MarkRule {
843
- readonly regex: RegExp;
844
- readonly type: string | MarkType;
845
- readonly getAttrs: (match: RegExpMatchArray) => Attrs | null;
846
- constructor({ regex, type, attrs }: MarkRuleOptions);
869
+ export declare interface MarkInputRuleOptions {
870
+ /**
871
+ * The regular expression to match against, which should end with `$` and has
872
+ * exactly one capture group. All other matched text outside the capture group
873
+ * will be deleted.
874
+ */
875
+ regex: RegExp;
876
+ /**
877
+ * The type of mark to set.
878
+ */
879
+ type: string | MarkType;
880
+ /**
881
+ * Attributes to set on the mark.
882
+ */
883
+ attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
847
884
  }
848
885
 
849
886
  /**
@@ -0,0 +1,100 @@
1
+ // src/input-rule/index.ts
2
+ import {
3
+ Facet,
4
+ getMarkType,
5
+ getNodeType,
6
+ isMarkAbsent,
7
+ maybeRun,
8
+ pluginFacet
9
+ } from "@prosekit/core";
10
+ import {
11
+ InputRule,
12
+ inputRules,
13
+ textblockTypeInputRule,
14
+ wrappingInputRule
15
+ } from "@prosekit/pm/inputrules";
16
+ import "@prosekit/pm/model";
17
+ import "@prosekit/pm/state";
18
+ function defineInputRule(rule) {
19
+ return inputRuleFacet.extension([() => rule]);
20
+ }
21
+ function createMarkInputRule({
22
+ regex,
23
+ type,
24
+ attrs = null
25
+ }) {
26
+ const rule = new InputRule(regex, (state, match, start, end) => {
27
+ var _a;
28
+ const { tr, schema } = state;
29
+ const [fullText, markText] = match;
30
+ if (!markText) {
31
+ return null;
32
+ }
33
+ const markStart = start + fullText.indexOf(markText);
34
+ const markEnd = markStart + markText.length;
35
+ if (!(start <= markStart && markStart < markEnd && markEnd <= end)) {
36
+ return null;
37
+ }
38
+ const markType = getMarkType(schema, type);
39
+ const mark = markType.create(maybeRun(attrs, match));
40
+ if (!isMarkAbsent(tr.doc, markStart, markEnd, markType, attrs)) {
41
+ return null;
42
+ }
43
+ const initialStoredMarks = (_a = tr.storedMarks) != null ? _a : [];
44
+ tr.addMark(markStart, markEnd, mark);
45
+ if (markEnd < end) {
46
+ tr.delete(markEnd, end);
47
+ }
48
+ if (start < markStart) {
49
+ tr.delete(start, markStart);
50
+ }
51
+ tr.setStoredMarks(initialStoredMarks);
52
+ return tr;
53
+ });
54
+ return rule;
55
+ }
56
+ function defineMarkInputRule(options) {
57
+ return defineInputRule(createMarkInputRule(options));
58
+ }
59
+ function defineTextBlockInputRule({
60
+ regex,
61
+ type,
62
+ attrs
63
+ }) {
64
+ return inputRuleFacet.extension([
65
+ ({ schema }) => {
66
+ const nodeType = getNodeType(schema, type);
67
+ return textblockTypeInputRule(regex, nodeType, attrs);
68
+ }
69
+ ]);
70
+ }
71
+ function defineWrappingInputRule({
72
+ regex,
73
+ type,
74
+ attrs,
75
+ join
76
+ }) {
77
+ return inputRuleFacet.extension([
78
+ ({ schema }) => {
79
+ const nodeType = getNodeType(schema, type);
80
+ return wrappingInputRule(regex, nodeType, attrs, join);
81
+ }
82
+ ]);
83
+ }
84
+ var inputRuleFacet = Facet.define({
85
+ convert: (inputs) => {
86
+ return (context) => {
87
+ const rules = inputs.flatMap((callback) => callback(context));
88
+ return [inputRules({ rules })];
89
+ };
90
+ },
91
+ next: pluginFacet
92
+ });
93
+
94
+ export {
95
+ defineInputRule,
96
+ createMarkInputRule,
97
+ defineMarkInputRule,
98
+ defineTextBlockInputRule,
99
+ defineWrappingInputRule
100
+ };
@@ -1,9 +1,13 @@
1
- // src/mark-rule/index.ts
1
+ // src/mark-rule/extension.ts
2
2
  import { Facet, pluginFacet } from "@prosekit/core";
3
3
  import { ProseMirrorPlugin } from "@prosekit/pm/state";
4
4
 
5
5
  // src/mark-rule/apply.ts
6
- import { OBJECT_REPLACEMENT_CHARACTER, getMarkType } from "@prosekit/core";
6
+ import {
7
+ OBJECT_REPLACEMENT_CHARACTER,
8
+ getMarkType,
9
+ maybeRun
10
+ } from "@prosekit/core";
7
11
  import "@prosekit/pm/model";
8
12
  import "@prosekit/pm/state";
9
13
 
@@ -62,7 +66,7 @@ function getMapRange(transactions, oldState, newState) {
62
66
  hi = map.map(hi);
63
67
  map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
64
68
  lo = Math.min(lo, hi, newStart);
65
- hi = Math.max(hi, hi, newEnd);
69
+ hi = Math.max(lo, hi, newEnd);
66
70
  });
67
71
  }
68
72
  }
@@ -78,7 +82,7 @@ function getCheckRanges(transactions, oldState, newState) {
78
82
  // src/mark-rule/apply.ts
79
83
  function getExpectedMarkings(rules, doc, from, to) {
80
84
  const text = doc.textBetween(from, to, OBJECT_REPLACEMENT_CHARACTER);
81
- const result = [];
85
+ const ranges = [];
82
86
  for (const rule of rules) {
83
87
  rule.regex.lastIndex = 0;
84
88
  const matches = text.matchAll(rule.regex);
@@ -87,9 +91,18 @@ function getExpectedMarkings(rules, doc, from, to) {
87
91
  const index = match.index;
88
92
  if (index == null)
89
93
  continue;
90
- const attrs = rule.getAttrs(match);
94
+ const attrs = maybeRun(rule.attrs, match);
91
95
  const mark = markType.create(attrs);
92
- result.push([mark, from + index, from + index + match[0].length]);
96
+ ranges.push([from + index, from + index + match[0].length, mark]);
97
+ }
98
+ }
99
+ ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
100
+ const result = [];
101
+ let freeIndex = 0;
102
+ for (const range of ranges) {
103
+ if (range[0] >= freeIndex) {
104
+ result.push(range);
105
+ freeIndex = range[1];
93
106
  }
94
107
  }
95
108
  return result;
@@ -105,17 +118,17 @@ function getReceivedMarkings(rules, doc, from, to) {
105
118
  for (const markType of markTypes) {
106
119
  const mark = node.marks.find((mark2) => mark2.type === markType);
107
120
  if (mark) {
108
- result.push([mark, pos, pos + node.nodeSize]);
121
+ result.push([pos, pos + node.nodeSize, mark]);
109
122
  }
110
123
  }
111
124
  });
112
125
  return result;
113
126
  }
114
- function markingEquals(a, b) {
115
- return a[1] === b[1] && a[2] === b[2] && a[0].eq(b[0]);
127
+ function markRangeEquals(a, b) {
128
+ return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2]);
116
129
  }
117
- function markingDiffs(a, b) {
118
- return a.filter((x) => !b.some((y) => markingEquals(x, y)));
130
+ function markRangeDiffs(a, b) {
131
+ return a.filter((x) => !b.some((y) => markRangeEquals(x, y)));
119
132
  }
120
133
  function applyMarkRules(rules, transactions, oldState, newState) {
121
134
  if (transactions.length === 0 || transactions.every((tr2) => !tr2.docChanged)) {
@@ -127,35 +140,25 @@ function applyMarkRules(rules, transactions, oldState, newState) {
127
140
  for (const [from, to] of ranges) {
128
141
  const expected = getExpectedMarkings(rules, newState.doc, from, to);
129
142
  const received = getReceivedMarkings(rules, newState.doc, from, to);
130
- toRemove.push(...markingDiffs(received, expected));
131
- toCreate.push(...markingDiffs(expected, received));
143
+ toRemove.push(...markRangeDiffs(received, expected));
144
+ toCreate.push(...markRangeDiffs(expected, received));
132
145
  }
133
146
  if (toCreate.length === 0 && toRemove.length === 0) {
134
147
  return null;
135
148
  }
136
149
  const tr = newState.tr;
137
- for (const [mark, from, to] of toRemove) {
150
+ for (const [from, to, mark] of toRemove) {
138
151
  tr.removeMark(from, to, mark);
139
152
  }
140
- for (const [mark, from, to] of toCreate) {
153
+ for (const [from, to, mark] of toCreate) {
141
154
  tr.addMark(from, to, mark);
142
155
  }
143
156
  return tr;
144
157
  }
145
158
 
146
- // src/mark-rule/rule.ts
147
- import "@prosekit/pm/model";
148
- var MarkRule = class {
149
- constructor({ regex, type, attrs = null }) {
150
- this.regex = regex;
151
- this.type = type;
152
- this.getAttrs = typeof attrs === "function" ? attrs : () => attrs;
153
- }
154
- };
155
-
156
- // src/mark-rule/index.ts
159
+ // src/mark-rule/extension.ts
157
160
  function defineMarkRule(options) {
158
- return markRuleFacet.extension([new MarkRule(options)]);
161
+ return markRuleFacet.extension([options]);
159
162
  }
160
163
  var markRuleFacet = Facet.define({
161
164
  converter: () => {
@@ -4,6 +4,7 @@ import {
4
4
  OBJECT_REPLACEMENT_CHARACTER,
5
5
  getNodeType,
6
6
  isTextSelection,
7
+ maybeRun,
7
8
  pluginFacet
8
9
  } from "@prosekit/core";
9
10
  import { keydownHandler } from "@prosekit/pm/keymap";
@@ -32,7 +33,7 @@ function defineTextBlockEnterRule({
32
33
  if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) {
33
34
  return null;
34
35
  }
35
- const nodeAttrs = attrs && typeof attrs === "function" ? attrs(match) : attrs;
36
+ const nodeAttrs = maybeRun(attrs, match);
36
37
  return state.tr.delete(from, to).setBlockType(from, from, nodeType, nodeAttrs);
37
38
  },
38
39
  stop
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineWrappingInputRule
3
- } from "./chunk-DYFRBXUX.js";
3
+ } from "./chunk-CJ3SOSL6.js";
4
4
 
5
5
  // src/blockquote/index.ts
6
6
  import { defineNodeSpec, union } from "@prosekit/core";
@@ -1,4 +1,5 @@
1
1
  export { defineBoldSpec } from './_tsup-dts-rollup';
2
2
  export { defineBoldCommands } from './_tsup-dts-rollup';
3
3
  export { defineBoldKeymap } from './_tsup-dts-rollup';
4
+ export { defineBoldInputRule } from './_tsup-dts-rollup';
4
5
  export { defineBold } from './_tsup-dts-rollup';
@@ -1,10 +1,15 @@
1
+ import {
2
+ defineMarkInputRule
3
+ } from "./chunk-CJ3SOSL6.js";
4
+
1
5
  // src/bold/index.ts
2
6
  import {
7
+ canUseRegexLookbehind,
3
8
  defineCommands,
4
9
  defineKeymap,
5
10
  defineMarkSpec,
6
- union,
7
- toggleMark
11
+ toggleMark,
12
+ union
8
13
  } from "@prosekit/core";
9
14
  function defineBoldSpec() {
10
15
  return defineMarkSpec({
@@ -43,12 +48,24 @@ function defineBoldKeymap() {
43
48
  "Mod-b": toggleMark({ type: "bold" })
44
49
  });
45
50
  }
51
+ function defineBoldInputRule() {
52
+ return defineMarkInputRule({
53
+ regex: canUseRegexLookbehind() ? /(?<=\s|^)\*\*([^\s*]|[^\s*][^*]*[^\s*])\*\*$/ : /\*\*([^\s*]|[^\s*][^*]*[^\s*])\*\*$/,
54
+ type: "bold"
55
+ });
56
+ }
46
57
  function defineBold() {
47
- return union([defineBoldSpec(), defineBoldCommands(), defineBoldKeymap()]);
58
+ return union([
59
+ defineBoldSpec(),
60
+ defineBoldCommands(),
61
+ defineBoldKeymap(),
62
+ defineBoldInputRule()
63
+ ]);
48
64
  }
49
65
  export {
50
66
  defineBold,
51
67
  defineBoldCommands,
68
+ defineBoldInputRule,
52
69
  defineBoldKeymap,
53
70
  defineBoldSpec
54
71
  };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  defineTextBlockEnterRule
3
- } from "./chunk-ASTUC4KT.js";
3
+ } from "./chunk-HLBUHIMJ.js";
4
4
  import {
5
5
  defineTextBlockInputRule
6
- } from "./chunk-DYFRBXUX.js";
6
+ } from "./chunk-CJ3SOSL6.js";
7
7
 
8
8
  // src/code-block/code-block.ts
9
9
  import { union } from "@prosekit/core";
@@ -1,4 +1,5 @@
1
1
  export { defineCodeSpec } from './_tsup-dts-rollup';
2
2
  export { defineCodeCommands } from './_tsup-dts-rollup';
3
- export { defineItalicKeymap } from './_tsup-dts-rollup';
3
+ export { defineCodeKeymap } from './_tsup-dts-rollup';
4
+ export { defineCodeInputRule } from './_tsup-dts-rollup';
4
5
  export { defineCode } from './_tsup-dts-rollup';
@@ -1,5 +1,10 @@
1
+ import {
2
+ defineMarkInputRule
3
+ } from "./chunk-CJ3SOSL6.js";
4
+
1
5
  // src/code/index.ts
2
6
  import {
7
+ canUseRegexLookbehind,
3
8
  defineCommands,
4
9
  defineKeymap,
5
10
  defineMarkSpec,
@@ -20,17 +25,29 @@ function defineCodeCommands() {
20
25
  toggleCode: () => toggleMark({ type: "code" })
21
26
  });
22
27
  }
23
- function defineItalicKeymap() {
28
+ function defineCodeKeymap() {
24
29
  return defineKeymap({
25
30
  "Mod-e": toggleMark({ type: "code" })
26
31
  });
27
32
  }
33
+ function defineCodeInputRule() {
34
+ return defineMarkInputRule({
35
+ regex: canUseRegexLookbehind() ? /(?<=\s|^)`([^\s`]|[^\s`][^`]*[^\s`])`$/ : /`([^\s`]|[^\s`][^`]*[^\s`])`$/,
36
+ type: "code"
37
+ });
38
+ }
28
39
  function defineCode() {
29
- return union([defineCodeSpec(), defineCodeCommands(), defineItalicKeymap()]);
40
+ return union([
41
+ defineCodeSpec(),
42
+ defineCodeCommands(),
43
+ defineCodeKeymap(),
44
+ defineCodeInputRule()
45
+ ]);
30
46
  }
31
47
  export {
32
48
  defineCode,
33
49
  defineCodeCommands,
34
- defineCodeSpec,
35
- defineItalicKeymap
50
+ defineCodeInputRule,
51
+ defineCodeKeymap,
52
+ defineCodeSpec
36
53
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineEnterRule,
3
3
  defineTextBlockEnterRule
4
- } from "./chunk-ASTUC4KT.js";
4
+ } from "./chunk-HLBUHIMJ.js";
5
5
  export {
6
6
  defineEnterRule,
7
7
  defineTextBlockEnterRule
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineTextBlockInputRule
3
- } from "./chunk-DYFRBXUX.js";
3
+ } from "./chunk-CJ3SOSL6.js";
4
4
 
5
5
  // src/heading/index.ts
6
6
  import {
@@ -1,3 +1,6 @@
1
1
  export { defineInputRule } from './_tsup-dts-rollup';
2
+ export { createMarkInputRule } from './_tsup-dts-rollup';
3
+ export { defineMarkInputRule } from './_tsup-dts-rollup';
2
4
  export { defineTextBlockInputRule } from './_tsup-dts-rollup';
3
5
  export { defineWrappingInputRule } from './_tsup-dts-rollup';
6
+ export { MarkInputRuleOptions } from './_tsup-dts-rollup';
@@ -1,10 +1,14 @@
1
1
  import {
2
+ createMarkInputRule,
2
3
  defineInputRule,
4
+ defineMarkInputRule,
3
5
  defineTextBlockInputRule,
4
6
  defineWrappingInputRule
5
- } from "./chunk-DYFRBXUX.js";
7
+ } from "./chunk-CJ3SOSL6.js";
6
8
  export {
9
+ createMarkInputRule,
7
10
  defineInputRule,
11
+ defineMarkInputRule,
8
12
  defineTextBlockInputRule,
9
13
  defineWrappingInputRule
10
14
  };
@@ -1,4 +1,5 @@
1
1
  export { defineItalicSpec } from './_tsup-dts-rollup';
2
2
  export { defineItalicCommands } from './_tsup-dts-rollup';
3
- export { defineItalicKeymap_alias_1 as defineItalicKeymap } from './_tsup-dts-rollup';
3
+ export { defineItalicKeymap } from './_tsup-dts-rollup';
4
+ export { defineItalicInputRule } from './_tsup-dts-rollup';
4
5
  export { defineItalic } from './_tsup-dts-rollup';
@@ -1,10 +1,15 @@
1
+ import {
2
+ defineMarkInputRule
3
+ } from "./chunk-CJ3SOSL6.js";
4
+
1
5
  // src/italic/index.ts
2
6
  import {
7
+ canUseRegexLookbehind,
3
8
  defineCommands,
4
9
  defineKeymap,
5
10
  defineMarkSpec,
6
- union,
7
- toggleMark
11
+ toggleMark,
12
+ union
8
13
  } from "@prosekit/core";
9
14
  function defineItalicSpec() {
10
15
  return defineMarkSpec({
@@ -33,16 +38,24 @@ function defineItalicKeymap() {
33
38
  "Mod-i": toggleMark({ type: "italic" })
34
39
  });
35
40
  }
41
+ function defineItalicInputRule() {
42
+ return defineMarkInputRule({
43
+ regex: canUseRegexLookbehind() ? /(?<=\s|^)\*([^\s*]|[^\s*][^*]*[^\s*])\*$/ : /\*([^\s*]|[^\s*][^*]*[^\s*])\*$/,
44
+ type: "italic"
45
+ });
46
+ }
36
47
  function defineItalic() {
37
48
  return union([
38
49
  defineItalicSpec(),
39
50
  defineItalicCommands(),
40
- defineItalicKeymap()
51
+ defineItalicKeymap(),
52
+ defineItalicInputRule()
41
53
  ]);
42
54
  }
43
55
  export {
44
56
  defineItalic,
45
57
  defineItalicCommands,
58
+ defineItalicInputRule,
46
59
  defineItalicKeymap,
47
60
  defineItalicSpec
48
61
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  defineMarkRule
3
- } from "./chunk-TXF4SPMB.js";
3
+ } from "./chunk-FG6YUKCN.js";
4
4
  import {
5
5
  defineEnterRule
6
- } from "./chunk-ASTUC4KT.js";
6
+ } from "./chunk-HLBUHIMJ.js";
7
7
  import {
8
8
  defineInputRule
9
- } from "./chunk-DYFRBXUX.js";
9
+ } from "./chunk-CJ3SOSL6.js";
10
10
 
11
11
  // src/link/index.ts
12
12
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineInputRule
3
- } from "./chunk-DYFRBXUX.js";
3
+ } from "./chunk-CJ3SOSL6.js";
4
4
 
5
5
  // src/list/index.ts
6
6
  import {
@@ -1,2 +1,2 @@
1
- export { defineMarkRule } from './_tsup-dts-rollup';
1
+ export { defineMarkRule_alias_1 as defineMarkRule } from './_tsup-dts-rollup';
2
2
  export { MarkRuleOptions } from './_tsup-dts-rollup';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkRule
3
- } from "./chunk-TXF4SPMB.js";
3
+ } from "./chunk-FG6YUKCN.js";
4
4
  export {
5
5
  defineMarkRule
6
6
  };
@@ -1,4 +1,5 @@
1
1
  export { defineStrikeSpec } from './_tsup-dts-rollup';
2
2
  export { defineStrikeCommands } from './_tsup-dts-rollup';
3
3
  export { defineStrikeKeymap } from './_tsup-dts-rollup';
4
+ export { defineStrikeInputRule } from './_tsup-dts-rollup';
4
5
  export { defineStrike } from './_tsup-dts-rollup';
@@ -1,10 +1,15 @@
1
+ import {
2
+ defineMarkInputRule
3
+ } from "./chunk-CJ3SOSL6.js";
4
+
1
5
  // src/strike/index.ts
2
6
  import {
3
7
  defineCommands,
4
8
  defineKeymap,
5
9
  defineMarkSpec,
6
10
  union,
7
- toggleMark
11
+ toggleMark,
12
+ canUseRegexLookbehind
8
13
  } from "@prosekit/core";
9
14
  function defineStrikeSpec() {
10
15
  return defineMarkSpec({
@@ -32,16 +37,24 @@ function defineStrikeKeymap() {
32
37
  "Mod-shift-x": toggleMark({ type: "strike" })
33
38
  });
34
39
  }
40
+ function defineStrikeInputRule() {
41
+ return defineMarkInputRule({
42
+ regex: canUseRegexLookbehind() ? /(?<=\s|^)~~([^\s~]|[^\s~][^~]*[^\s~])~~$/ : /~~([^\s~]|[^\s~][^~]*[^\s~])~~$/,
43
+ type: "strike"
44
+ });
45
+ }
35
46
  function defineStrike() {
36
47
  return union([
37
48
  defineStrikeSpec(),
38
49
  defineStrikeCommands(),
39
- defineStrikeKeymap()
50
+ defineStrikeKeymap(),
51
+ defineStrikeInputRule()
40
52
  ]);
41
53
  }
42
54
  export {
43
55
  defineStrike,
44
56
  defineStrikeCommands,
57
+ defineStrikeInputRule,
45
58
  defineStrikeKeymap,
46
59
  defineStrikeSpec
47
60
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.4.3",
4
+ "version": "0.4.5",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -152,7 +152,7 @@
152
152
  "dist"
153
153
  ],
154
154
  "dependencies": {
155
- "@prosekit/core": "^0.4.0",
155
+ "@prosekit/core": "^0.4.2",
156
156
  "@prosekit/pm": "^0.1.2",
157
157
  "prosemirror-dropcursor": "^1.8.1",
158
158
  "prosemirror-flat-list": "^0.5.0",
@@ -1,56 +0,0 @@
1
- // src/input-rule/index.ts
2
- import {
3
- Facet,
4
- getNodeType,
5
- pluginFacet
6
- } from "@prosekit/core";
7
- import {
8
- inputRules,
9
- textblockTypeInputRule,
10
- wrappingInputRule
11
- } from "@prosekit/pm/inputrules";
12
- import "@prosekit/pm/model";
13
- import "@prosekit/pm/state";
14
- function defineInputRule(rule) {
15
- return inputRuleFacet.extension([() => rule]);
16
- }
17
- function defineTextBlockInputRule({
18
- regex,
19
- type,
20
- attrs
21
- }) {
22
- return inputRuleFacet.extension([
23
- ({ schema }) => {
24
- const nodeType = getNodeType(schema, type);
25
- return textblockTypeInputRule(regex, nodeType, attrs);
26
- }
27
- ]);
28
- }
29
- function defineWrappingInputRule({
30
- regex,
31
- type,
32
- attrs,
33
- join
34
- }) {
35
- return inputRuleFacet.extension([
36
- ({ schema }) => {
37
- const nodeType = getNodeType(schema, type);
38
- return wrappingInputRule(regex, nodeType, attrs, join);
39
- }
40
- ]);
41
- }
42
- var inputRuleFacet = Facet.define({
43
- convert: (inputs) => {
44
- return (context) => {
45
- const rules = inputs.flatMap((callback) => callback(context));
46
- return [inputRules({ rules })];
47
- };
48
- },
49
- next: pluginFacet
50
- });
51
-
52
- export {
53
- defineInputRule,
54
- defineTextBlockInputRule,
55
- defineWrappingInputRule
56
- };