@prosekit/extensions 0.4.4 → 0.4.6
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.
- package/dist/_tsup-dts-rollup.d.ts +46 -10
- package/dist/{chunk-MX6UNVWH.js → chunk-7G7COECS.js} +8 -7
- package/dist/chunk-CJ3SOSL6.js +100 -0
- package/dist/{chunk-ASTUC4KT.js → chunk-HLBUHIMJ.js} +2 -1
- package/dist/prosekit-extensions-autocomplete.js +2 -0
- package/dist/prosekit-extensions-blockquote.js +1 -1
- package/dist/prosekit-extensions-bold.d.ts +1 -0
- package/dist/prosekit-extensions-bold.js +20 -3
- package/dist/prosekit-extensions-code-block.js +2 -2
- package/dist/prosekit-extensions-code.d.ts +2 -1
- package/dist/prosekit-extensions-code.js +21 -4
- package/dist/prosekit-extensions-enter-rule.js +1 -1
- package/dist/prosekit-extensions-heading.js +1 -1
- package/dist/prosekit-extensions-input-rule.d.ts +3 -0
- package/dist/prosekit-extensions-input-rule.js +5 -1
- package/dist/prosekit-extensions-italic.d.ts +2 -1
- package/dist/prosekit-extensions-italic.js +16 -3
- package/dist/prosekit-extensions-link.js +3 -3
- package/dist/prosekit-extensions-list.js +1 -1
- package/dist/prosekit-extensions-mark-rule.d.ts +1 -1
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-strike.d.ts +1 -0
- package/dist/prosekit-extensions-strike.js +15 -2
- package/package.json +2 -2
- package/dist/chunk-DYFRBXUX.js +0 -56
@@ -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:
|
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
|
399
|
+
export declare function defineItalicInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
389
400
|
|
390
|
-
export declare function
|
401
|
+
export declare function defineItalicKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
391
402
|
|
392
403
|
export declare function defineItalicSpec(): Extension< {
|
393
404
|
MARKS: "italic";
|
@@ -481,6 +492,14 @@ 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.
|
@@ -539,6 +558,8 @@ toggleStrike: [];
|
|
539
558
|
};
|
540
559
|
}>;
|
541
560
|
|
561
|
+
export declare function defineStrikeInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
562
|
+
|
542
563
|
export declare function defineStrikeKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
543
564
|
|
544
565
|
export declare function defineStrikeSpec(): Extension< {
|
@@ -628,8 +649,9 @@ export declare function defineTextBlockEnterRule({ regex, type, attrs, stop, }:
|
|
628
649
|
*/
|
629
650
|
export declare function defineTextBlockInputRule({ regex, type, attrs, }: {
|
630
651
|
/**
|
631
|
-
* The regular expression to match against
|
632
|
-
* with `^` to that it is only matched at the start of a
|
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.
|
633
655
|
*/
|
634
656
|
regex: RegExp;
|
635
657
|
/**
|
@@ -686,8 +708,9 @@ export declare function defineVirtualSelection(): Extension;
|
|
686
708
|
*/
|
687
709
|
export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
|
688
710
|
/**
|
689
|
-
* The regular expression to match against
|
690
|
-
* with `^` to that it is only matched at the start of a
|
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.
|
691
714
|
*/
|
692
715
|
regex: RegExp;
|
693
716
|
/**
|
@@ -839,12 +862,25 @@ export declare interface LinkAttrs {
|
|
839
862
|
export { ListDOMSerializer }
|
840
863
|
|
841
864
|
/**
|
842
|
-
* @
|
865
|
+
* Options for {@link defineMarkInputRule}.
|
866
|
+
*
|
867
|
+
* @public
|
843
868
|
*/
|
844
|
-
export declare interface
|
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
|
+
*/
|
845
875
|
regex: RegExp;
|
876
|
+
/**
|
877
|
+
* The type of mark to set.
|
878
|
+
*/
|
846
879
|
type: string | MarkType;
|
847
|
-
|
880
|
+
/**
|
881
|
+
* Attributes to set on the mark.
|
882
|
+
*/
|
883
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
848
884
|
}
|
849
885
|
|
850
886
|
/**
|
@@ -3,7 +3,11 @@ 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 {
|
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
|
|
@@ -77,8 +81,7 @@ function getCheckRanges(transactions, oldState, newState) {
|
|
77
81
|
|
78
82
|
// src/mark-rule/apply.ts
|
79
83
|
function getExpectedMarkings(rules, doc, from, to) {
|
80
|
-
|
81
|
-
const text = doc.textBetween(from, to, OBJECT_REPLACEMENT_CHARACTER);
|
84
|
+
const text = doc.textBetween(from, to, null, OBJECT_REPLACEMENT_CHARACTER);
|
82
85
|
const ranges = [];
|
83
86
|
for (const rule of rules) {
|
84
87
|
rule.regex.lastIndex = 0;
|
@@ -88,7 +91,7 @@ function getExpectedMarkings(rules, doc, from, to) {
|
|
88
91
|
const index = match.index;
|
89
92
|
if (index == null)
|
90
93
|
continue;
|
91
|
-
const attrs = (
|
94
|
+
const attrs = maybeRun(rule.attrs, match);
|
92
95
|
const mark = markType.create(attrs);
|
93
96
|
ranges.push([from + index, from + index + match[0].length, mark]);
|
94
97
|
}
|
@@ -155,9 +158,7 @@ function applyMarkRules(rules, transactions, oldState, newState) {
|
|
155
158
|
|
156
159
|
// src/mark-rule/extension.ts
|
157
160
|
function defineMarkRule(options) {
|
158
|
-
|
159
|
-
const getAttrs = attrs && typeof attrs === "object" ? () => attrs : attrs;
|
160
|
-
return markRuleFacet.extension([{ regex, type, getAttrs }]);
|
161
|
+
return markRuleFacet.extension([options]);
|
161
162
|
}
|
162
163
|
var markRuleFacet = Facet.define({
|
163
164
|
converter: () => {
|
@@ -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
|
+
};
|
@@ -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
|
36
|
+
const nodeAttrs = maybeRun(attrs, match);
|
36
37
|
return state.tr.delete(from, to).setBlockType(from, from, nodeType, nodeAttrs);
|
37
38
|
},
|
38
39
|
stop
|
@@ -75,12 +75,14 @@ function createAutocompletePlugin({
|
|
75
75
|
const textContent = view.state.doc.textBetween(
|
76
76
|
from,
|
77
77
|
to,
|
78
|
+
null,
|
78
79
|
OBJECT_REPLACEMENT_CHARACTER
|
79
80
|
);
|
80
81
|
const deleteMatch = () => {
|
81
82
|
if (view.state.doc.textBetween(
|
82
83
|
from,
|
83
84
|
to,
|
85
|
+
null,
|
84
86
|
OBJECT_REPLACEMENT_CHARACTER
|
85
87
|
) === textContent) {
|
86
88
|
view.dispatch(view.state.tr.delete(from, to));
|
@@ -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
|
-
|
7
|
-
|
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([
|
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-
|
3
|
+
} from "./chunk-HLBUHIMJ.js";
|
4
4
|
import {
|
5
5
|
defineTextBlockInputRule
|
6
|
-
} from "./chunk-
|
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 {
|
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
|
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([
|
40
|
+
return union([
|
41
|
+
defineCodeSpec(),
|
42
|
+
defineCodeCommands(),
|
43
|
+
defineCodeKeymap(),
|
44
|
+
defineCodeInputRule()
|
45
|
+
]);
|
30
46
|
}
|
31
47
|
export {
|
32
48
|
defineCode,
|
33
49
|
defineCodeCommands,
|
34
|
-
|
35
|
-
|
50
|
+
defineCodeInputRule,
|
51
|
+
defineCodeKeymap,
|
52
|
+
defineCodeSpec
|
36
53
|
};
|
@@ -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-
|
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 {
|
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
|
-
|
7
|
-
|
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-
|
3
|
+
} from "./chunk-7G7COECS.js";
|
4
4
|
import {
|
5
5
|
defineEnterRule
|
6
|
-
} from "./chunk-
|
6
|
+
} from "./chunk-HLBUHIMJ.js";
|
7
7
|
import {
|
8
8
|
defineInputRule
|
9
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-CJ3SOSL6.js";
|
10
10
|
|
11
11
|
// src/link/index.ts
|
12
12
|
import {
|
@@ -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.
|
4
|
+
"version": "0.4.6",
|
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.
|
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",
|
package/dist/chunk-DYFRBXUX.js
DELETED
@@ -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
|
-
};
|