@prosekit/extensions 0.7.24 → 0.9.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.
- package/dist/commit/style.css +2 -1
- package/dist/commit/style.js +0 -0
- package/dist/enter-rule-RdhEA900.js +96 -0
- package/dist/gap-cursor/style.css +8 -5
- package/dist/gap-cursor/style.js +0 -0
- package/dist/input-rule-Gji4N7Oe.js +93 -0
- package/dist/list/style.css +7 -7
- package/dist/list/style.js +0 -0
- package/dist/loro/style.css +21 -17
- package/dist/loro/style.js +0 -0
- package/dist/mark-rule-wEOcDt6i.js +160 -0
- package/dist/placeholder/style.css +5 -5
- package/dist/placeholder/style.js +0 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
- package/dist/prosekit-extensions-autocomplete.js +122 -174
- package/dist/prosekit-extensions-blockquote.d.ts +51 -8
- package/dist/prosekit-extensions-blockquote.js +64 -78
- package/dist/prosekit-extensions-bold.d.ts +61 -8
- package/dist/prosekit-extensions-bold.js +61 -73
- package/dist/prosekit-extensions-code-block.d.ts +172 -20
- package/dist/prosekit-extensions-code-block.js +201 -184
- package/dist/prosekit-extensions-code.d.ts +61 -8
- package/dist/prosekit-extensions-code.js +44 -55
- package/dist/prosekit-extensions-commit.d.ts +53 -4
- package/dist/prosekit-extensions-commit.js +142 -183
- package/dist/prosekit-extensions-doc.d.ts +22 -0
- package/dist/prosekit-extensions-doc.js +16 -0
- package/dist/prosekit-extensions-drop-cursor.d.ts +34 -3
- package/dist/prosekit-extensions-drop-cursor.js +14 -8
- package/dist/prosekit-extensions-enter-rule.d.ts +106 -5
- package/dist/prosekit-extensions-enter-rule.js +3 -8
- package/dist/prosekit-extensions-file.d.ts +126 -8
- package/dist/prosekit-extensions-file.js +111 -132
- package/dist/prosekit-extensions-gap-cursor.d.ts +29 -2
- package/dist/prosekit-extensions-gap-cursor.js +21 -9
- package/dist/prosekit-extensions-hard-break.d.ts +58 -0
- package/dist/prosekit-extensions-hard-break.js +58 -0
- package/dist/prosekit-extensions-heading.d.ts +69 -9
- package/dist/prosekit-extensions-heading.js +121 -95
- package/dist/prosekit-extensions-horizontal-rule.d.ts +41 -8
- package/dist/prosekit-extensions-horizontal-rule.js +53 -71
- package/dist/prosekit-extensions-image.d.ts +53 -7
- package/dist/prosekit-extensions-image.js +71 -62
- package/dist/prosekit-extensions-input-rule.d.ts +134 -6
- package/dist/prosekit-extensions-input-rule.js +3 -14
- package/dist/prosekit-extensions-italic.d.ts +61 -8
- package/dist/prosekit-extensions-italic.js +51 -63
- package/dist/prosekit-extensions-link.d.ts +65 -10
- package/dist/prosekit-extensions-link.js +95 -100
- package/dist/prosekit-extensions-list.d.ts +114 -17
- package/dist/prosekit-extensions-list.js +115 -158
- package/dist/prosekit-extensions-loro.d.ts +78 -11
- package/dist/prosekit-extensions-loro.js +49 -77
- package/dist/prosekit-extensions-mark-rule.d.ts +41 -2
- package/dist/prosekit-extensions-mark-rule.js +3 -6
- package/dist/prosekit-extensions-mention.d.ts +40 -4
- package/dist/prosekit-extensions-mention.js +52 -50
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +20 -2
- package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
- package/dist/prosekit-extensions-paragraph.d.ts +65 -0
- package/dist/prosekit-extensions-paragraph.js +60 -0
- package/dist/prosekit-extensions-placeholder.d.ts +32 -2
- package/dist/prosekit-extensions-placeholder.js +39 -56
- package/dist/prosekit-extensions-readonly.d.ts +13 -1
- package/dist/prosekit-extensions-readonly.js +13 -14
- package/dist/prosekit-extensions-search.d.ts +77 -3
- package/dist/prosekit-extensions-search.js +48 -47
- package/dist/prosekit-extensions-strike.d.ts +50 -8
- package/dist/prosekit-extensions-strike.js +44 -49
- package/dist/prosekit-extensions-table.d.ts +237 -26
- package/dist/prosekit-extensions-table.js +3 -34
- package/dist/prosekit-extensions-text-align.d.ts +72 -8
- package/dist/prosekit-extensions-text-align.js +63 -44
- package/dist/prosekit-extensions-text.d.ts +22 -0
- package/dist/prosekit-extensions-text.js +15 -0
- package/dist/prosekit-extensions-underline.d.ts +46 -7
- package/dist/prosekit-extensions-underline.js +33 -37
- package/dist/prosekit-extensions-virtual-selection.d.ts +24 -2
- package/dist/prosekit-extensions-virtual-selection.js +49 -52
- package/dist/prosekit-extensions-yjs.d.ts +99 -14
- package/dist/prosekit-extensions-yjs.js +88 -131
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/search/style.css +5 -5
- package/dist/search/style.js +0 -0
- package/dist/shiki-highlighter-chunk-Cd3WeOKL.d.ts +19 -0
- package/dist/shiki-highlighter-chunk.d.ts +2 -0
- package/dist/shiki-highlighter-chunk.js +34 -43
- package/dist/table/style.css +18 -17
- package/dist/table/style.js +0 -0
- package/dist/table-DnVliJ6E.js +287 -0
- package/dist/virtual-selection/style.css +2 -2
- package/dist/virtual-selection/style.js +0 -0
- package/dist/yjs/style.css +15 -17
- package/dist/yjs/style.js +0 -0
- package/package.json +103 -52
- package/dist/_tsup-dts-rollup.d.ts +0 -2500
- package/dist/chunk-6UYLCVBX.js +0 -185
- package/dist/chunk-BV3SHIMW.js +0 -98
- package/dist/chunk-D54VSLLS.js +0 -105
- package/dist/chunk-HFAZX2J3.js +0 -306
@@ -1,6 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import { PlainExtension } from "@prosekit/core";
|
2
|
+
import { InputRule } from "@prosekit/pm/inputrules";
|
3
|
+
import { Attrs, MarkType, NodeType, ProseMirrorNode } from "@prosekit/pm/model";
|
4
|
+
|
5
|
+
//#region src/input-rule/index.d.ts
|
6
|
+
/**
|
7
|
+
* Defines an input rule extension.
|
8
|
+
*
|
9
|
+
* @param rule - The ProseMirror input rule to add.
|
10
|
+
*
|
11
|
+
* @public
|
12
|
+
*/
|
13
|
+
/**
|
14
|
+
* Defines an input rule extension.
|
15
|
+
*
|
16
|
+
* @param rule - The ProseMirror input rule to add.
|
17
|
+
*
|
18
|
+
* @public
|
19
|
+
*/
|
20
|
+
declare function defineInputRule(rule: InputRule): PlainExtension;
|
21
|
+
/**
|
22
|
+
* Options for {@link defineMarkInputRule}.
|
23
|
+
*
|
24
|
+
* @public
|
25
|
+
*/
|
26
|
+
interface MarkInputRuleOptions {
|
27
|
+
/**
|
28
|
+
* The regular expression to match against, which should end with `$` and has
|
29
|
+
* exactly one capture group. All other matched text outside the capture group
|
30
|
+
* will be deleted.
|
31
|
+
*/
|
32
|
+
regex: RegExp;
|
33
|
+
/**
|
34
|
+
* The type of mark to set.
|
35
|
+
*/
|
36
|
+
type: string | MarkType;
|
37
|
+
/**
|
38
|
+
* Attributes to set on the mark.
|
39
|
+
*/
|
40
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
41
|
+
/**
|
42
|
+
* Whether this rule should fire inside marks marked as [code](https://prosemirror.net/docs/ref/#model.MarkSpec.code).
|
43
|
+
*
|
44
|
+
* @default `false`
|
45
|
+
*/
|
46
|
+
inCodeMark?: boolean;
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
declare function createMarkInputRule({
|
52
|
+
regex,
|
53
|
+
type,
|
54
|
+
attrs,
|
55
|
+
inCodeMark
|
56
|
+
}: MarkInputRuleOptions): InputRule;
|
57
|
+
/**
|
58
|
+
* Defines an input rule for automatically adding inline marks when a given
|
59
|
+
* pattern is typed.
|
60
|
+
*
|
61
|
+
* @public
|
62
|
+
*/
|
63
|
+
declare function defineMarkInputRule(options: MarkInputRuleOptions): PlainExtension;
|
64
|
+
/**
|
65
|
+
* Defines an input rule that changes the type of a textblock when the matched
|
66
|
+
* text is typed into it.
|
67
|
+
*
|
68
|
+
* See also [textblockTypeInputRule](https://prosemirror.net/docs/ref/#inputrules.textblockTypeInputRule)
|
69
|
+
*
|
70
|
+
* @param options
|
71
|
+
*
|
72
|
+
* @public
|
73
|
+
*/
|
74
|
+
declare function defineTextBlockInputRule({
|
75
|
+
regex,
|
76
|
+
type,
|
77
|
+
attrs
|
78
|
+
}: {
|
79
|
+
/**
|
80
|
+
* The regular expression to match against, which should end with `$`. It
|
81
|
+
* usually also starts with `^` to that it is only matched at the start of a
|
82
|
+
* textblock.
|
83
|
+
*/
|
84
|
+
regex: RegExp;
|
85
|
+
/**
|
86
|
+
* The node type to replace the matched text with.
|
87
|
+
*/
|
88
|
+
type: string | NodeType;
|
89
|
+
/**
|
90
|
+
* Attributes to set on the node.
|
91
|
+
*/
|
92
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
93
|
+
}): PlainExtension;
|
94
|
+
/**
|
95
|
+
* Defines an input rule for automatically wrapping a textblock when a given
|
96
|
+
* string is typed.
|
97
|
+
*
|
98
|
+
* See also [wrappingInputRule](https://prosemirror.net/docs/ref/#inputrules.wrappingInputRule)
|
99
|
+
*
|
100
|
+
* @param options
|
101
|
+
*
|
102
|
+
* @public
|
103
|
+
*/
|
104
|
+
declare function defineWrappingInputRule({
|
105
|
+
regex,
|
106
|
+
type,
|
107
|
+
attrs,
|
108
|
+
join
|
109
|
+
}: {
|
110
|
+
/**
|
111
|
+
* The regular expression to match against, which should end with `$`. It
|
112
|
+
* usually also starts with `^` to that it is only matched at the start of a
|
113
|
+
* textblock.
|
114
|
+
*/
|
115
|
+
regex: RegExp;
|
116
|
+
/**
|
117
|
+
* The type of node to wrap in.
|
118
|
+
*/
|
119
|
+
type: string | NodeType;
|
120
|
+
/**
|
121
|
+
* Attributes to set on the node.
|
122
|
+
*/
|
123
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
124
|
+
/**
|
125
|
+
* By default, if there's a node with the same type above the newly wrapped
|
126
|
+
* node, the rule will try to
|
127
|
+
* [join](https://prosemirror.net/docs/ref/#transform.Transform.join) those
|
128
|
+
* two nodes. You can pass a join predicate, which takes a regular expression
|
129
|
+
* match and the node before the wrapped node, and can return a boolean to
|
130
|
+
* indicate whether a join should happen.
|
131
|
+
*/
|
132
|
+
join?: (match: RegExpMatchArray, node: ProseMirrorNode) => boolean;
|
133
|
+
}): PlainExtension; //#endregion
|
134
|
+
export { MarkInputRuleOptions, createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule };
|
@@ -1,14 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
defineMarkInputRule,
|
5
|
-
defineTextBlockInputRule,
|
6
|
-
defineWrappingInputRule
|
7
|
-
} from "./chunk-BV3SHIMW.js";
|
8
|
-
export {
|
9
|
-
createMarkInputRule,
|
10
|
-
defineInputRule,
|
11
|
-
defineMarkInputRule,
|
12
|
-
defineTextBlockInputRule,
|
13
|
-
defineWrappingInputRule
|
14
|
-
};
|
1
|
+
import { createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule } from "./input-rule-Gji4N7Oe.js";
|
2
|
+
|
3
|
+
export { createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule };
|
@@ -1,8 +1,61 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
2
|
+
import { Attrs } from "@prosekit/pm/model";
|
3
|
+
|
4
|
+
//#region src/italic/italic-commands.d.ts
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
8
|
+
/**
|
9
|
+
* @internal
|
10
|
+
*/
|
11
|
+
type ItalicCommandsExtension = Extension<{
|
12
|
+
Commands: {
|
13
|
+
toggleItalic: [];
|
14
|
+
};
|
15
|
+
}>;
|
16
|
+
/**
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
declare function defineItalicCommands(): ItalicCommandsExtension;
|
20
|
+
//#endregion
|
21
|
+
//#region src/italic/italic-spec.d.ts
|
22
|
+
/**
|
23
|
+
* @internal
|
24
|
+
*/
|
25
|
+
type ItalicSpecExtension = Extension<{
|
26
|
+
Marks: {
|
27
|
+
italic: Attrs;
|
28
|
+
};
|
29
|
+
}>;
|
30
|
+
/**
|
31
|
+
* @internal
|
32
|
+
*/
|
33
|
+
declare function defineItalicSpec(): ItalicSpecExtension;
|
34
|
+
|
35
|
+
//#endregion
|
36
|
+
//#region src/italic/italic.d.ts
|
37
|
+
/**
|
38
|
+
* @internal
|
39
|
+
*/
|
40
|
+
type ItalicExtension = Union<[ItalicSpecExtension, ItalicCommandsExtension]>;
|
41
|
+
/**
|
42
|
+
* @public
|
43
|
+
*/
|
44
|
+
declare function defineItalic(): ItalicExtension;
|
45
|
+
|
46
|
+
//#endregion
|
47
|
+
//#region src/italic/italic-input-rule.d.ts
|
48
|
+
/**
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
declare function defineItalicInputRule(): PlainExtension;
|
52
|
+
|
53
|
+
//#endregion
|
54
|
+
//#region src/italic/italic-keymap.d.ts
|
55
|
+
/**
|
56
|
+
* @internal
|
57
|
+
*/
|
58
|
+
declare function defineItalicKeymap(): PlainExtension;
|
59
|
+
|
60
|
+
//#endregion
|
61
|
+
export { ItalicCommandsExtension, ItalicExtension, ItalicSpecExtension, defineItalic, defineItalicCommands, defineItalicInputRule, defineItalicKeymap, defineItalicSpec };
|
@@ -1,78 +1,66 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from "./chunk-BV3SHIMW.js";
|
1
|
+
import { defineMarkInputRule } from "./input-rule-Gji4N7Oe.js";
|
2
|
+
import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
// src/italic/italic-commands.ts
|
11
|
-
import {
|
12
|
-
defineCommands,
|
13
|
-
toggleMark
|
14
|
-
} from "@prosekit/core";
|
4
|
+
//#region src/italic/italic-commands.ts
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
15
8
|
function defineItalicCommands() {
|
16
|
-
|
17
|
-
toggleItalic: () => toggleMark({ type: "italic" })
|
18
|
-
});
|
9
|
+
return defineCommands({ toggleItalic: () => toggleMark({ type: "italic" }) });
|
19
10
|
}
|
20
11
|
|
21
|
-
|
22
|
-
|
12
|
+
//#endregion
|
13
|
+
//#region src/italic/italic-input-rule.ts
|
14
|
+
/**
|
15
|
+
* @internal
|
16
|
+
*/
|
23
17
|
function defineItalicInputRule() {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
return defineMarkInputRule({
|
19
|
+
regex: canUseRegexLookbehind() ? /(?<=\s|^)\*([^\s*]|[^\s*][^*]*[^\s*])\*$/ : /\*([^\s*]|[^\s*][^*]*[^\s*])\*$/,
|
20
|
+
type: "italic"
|
21
|
+
});
|
28
22
|
}
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
//#endregion
|
25
|
+
//#region src/italic/italic-keymap.ts
|
26
|
+
/**
|
27
|
+
* @internal
|
28
|
+
*/
|
35
29
|
function defineItalicKeymap() {
|
36
|
-
|
37
|
-
"Mod-i": toggleMark2({ type: "italic" })
|
38
|
-
});
|
30
|
+
return defineKeymap({ "Mod-i": toggleMark({ type: "italic" }) });
|
39
31
|
}
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
//#endregion
|
34
|
+
//#region src/italic/italic-spec.ts
|
35
|
+
/**
|
36
|
+
* @internal
|
37
|
+
*/
|
45
38
|
function defineItalicSpec() {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
39
|
+
return defineMarkSpec({
|
40
|
+
name: "italic",
|
41
|
+
parseDOM: [
|
42
|
+
{ tag: "i" },
|
43
|
+
{ tag: "em" },
|
44
|
+
{ style: "font-style=italic" },
|
45
|
+
{
|
46
|
+
style: "font-style=normal",
|
47
|
+
clearMark: (m) => m.type.name === "italic"
|
48
|
+
}
|
49
|
+
],
|
50
|
+
toDOM() {
|
51
|
+
return ["em", 0];
|
52
|
+
}
|
53
|
+
});
|
61
54
|
}
|
62
55
|
|
63
|
-
|
56
|
+
//#endregion
|
57
|
+
//#region src/italic/italic.ts
|
58
|
+
/**
|
59
|
+
* @public
|
60
|
+
*/
|
64
61
|
function defineItalic() {
|
65
|
-
|
66
|
-
defineItalicSpec(),
|
67
|
-
defineItalicCommands(),
|
68
|
-
defineItalicKeymap(),
|
69
|
-
defineItalicInputRule()
|
70
|
-
);
|
62
|
+
return union(defineItalicSpec(), defineItalicCommands(), defineItalicKeymap(), defineItalicInputRule());
|
71
63
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
defineItalicInputRule,
|
76
|
-
defineItalicKeymap,
|
77
|
-
defineItalicSpec
|
78
|
-
};
|
64
|
+
|
65
|
+
//#endregion
|
66
|
+
export { defineItalic, defineItalicCommands, defineItalicInputRule, defineItalicKeymap, defineItalicSpec };
|
@@ -1,10 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/link/index.d.ts
|
4
|
+
/**
|
5
|
+
* @public
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @public
|
9
|
+
*/
|
10
|
+
interface LinkAttrs {
|
11
|
+
href: string;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* @internal
|
15
|
+
*/
|
16
|
+
type LinkSpecExtension = Extension<{
|
17
|
+
Marks: {
|
18
|
+
link: LinkAttrs;
|
19
|
+
};
|
20
|
+
}>;
|
21
|
+
/**
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
declare function defineLinkSpec(): LinkSpecExtension;
|
25
|
+
/**
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
type LinkCommandsExtension = Extension<{
|
29
|
+
Commands: {
|
30
|
+
addLink: [attrs: LinkAttrs];
|
31
|
+
removeLink: [];
|
32
|
+
toggleLink: [attrs: LinkAttrs];
|
33
|
+
expandLink: [];
|
34
|
+
};
|
35
|
+
}>;
|
36
|
+
declare function defineLinkCommands(): LinkCommandsExtension;
|
37
|
+
/**
|
38
|
+
* Apply link marks after pressing Space.
|
39
|
+
*
|
40
|
+
* @internal
|
41
|
+
*/
|
42
|
+
declare function defineLinkInputRule(): PlainExtension;
|
43
|
+
/**
|
44
|
+
* Apply link marks after typing Enter.
|
45
|
+
*
|
46
|
+
* @internal
|
47
|
+
*/
|
48
|
+
declare function defineLinkEnterRule(): PlainExtension;
|
49
|
+
/**
|
50
|
+
* Apply and remove link marks to the text during typing.
|
51
|
+
*
|
52
|
+
* @internal
|
53
|
+
*/
|
54
|
+
declare function defineLinkMarkRule(): PlainExtension;
|
55
|
+
/**
|
56
|
+
* @internal
|
57
|
+
*/
|
58
|
+
type LinkExtension = Union<[LinkSpecExtension, LinkCommandsExtension]>;
|
59
|
+
/**
|
60
|
+
* @public
|
61
|
+
*/
|
62
|
+
declare function defineLink(): LinkExtension;
|
63
|
+
|
64
|
+
//#endregion
|
65
|
+
export { LinkAttrs, LinkCommandsExtension, LinkExtension, LinkSpecExtension, defineLink, defineLinkCommands, defineLinkEnterRule, defineLinkInputRule, defineLinkMarkRule, defineLinkSpec };
|
@@ -1,115 +1,110 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from "./
|
4
|
-
import {
|
5
|
-
defineEnterRule
|
6
|
-
} from "./chunk-D54VSLLS.js";
|
7
|
-
import {
|
8
|
-
defineInputRule
|
9
|
-
} from "./chunk-BV3SHIMW.js";
|
10
|
-
|
11
|
-
// src/link/index.ts
|
12
|
-
import {
|
13
|
-
addMark,
|
14
|
-
defineCommands,
|
15
|
-
defineMarkSpec,
|
16
|
-
expandMark,
|
17
|
-
removeMark,
|
18
|
-
toggleMark,
|
19
|
-
union
|
20
|
-
} from "@prosekit/core";
|
1
|
+
import { defineInputRule } from "./input-rule-Gji4N7Oe.js";
|
2
|
+
import { defineEnterRule } from "./enter-rule-RdhEA900.js";
|
3
|
+
import { defineMarkRule } from "./mark-rule-wEOcDt6i.js";
|
4
|
+
import { addMark, defineCommands, defineMarkSpec, expandMark, removeMark, toggleMark, union } from "@prosekit/core";
|
21
5
|
import { InputRule } from "@prosekit/pm/inputrules";
|
22
6
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
);
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
var LINK_ENTER_RE = new RegExp(LINK_ENTER_PATTERN, "gi");
|
36
|
-
var LINK_INPUT_RE = new RegExp(LINK_INPUT_PATTERN, "gi");
|
37
|
-
var LINK_MARK_RE = new RegExp(LINK_MARK_PATTERN, "gi");
|
7
|
+
//#region src/link/link-regex.ts
|
8
|
+
const TLD_RE_PATTERN = "a(?:a(?:a|rp)|b(?:arth|b(?:ott|vie)?|c|le|ogado|udhabi)|c(?:ademy|c(?:enture|ountants?)|o|tor)?|d(?:s|ult)?|e(?:g|ro|tna)?|f(?:l|rica)?|g(?:akhan|ency)?|i(?:g|r(?:bus|force|tel))?|kdn|l(?:faromeo|i(?:baba|pay)|l(?:finanz|state|y)|s(?:ace|tom))?|m(?:azon|e(?:rican(?:express|family)|x)|fam|ica|sterdam)?|n(?:alytics|droid|quan|z)|ol?|p(?:artments|p(?:le)?)|q(?:uarelle)?|r(?:a(?:b|mco)|chi|my|pa|te?)?|s(?:da|ia|sociates)?|t(?:hleta|torney)?|u(?:ction|di(?:ble|o)?|spost|t(?:hor|os?))?|vianca|ws?|xa?|z(?:ure)?)|b(?:a(?:by|idu|n(?:a(?:mex|narepublic)|d|k)|r(?:c(?:elona|lay(?:card|s))|efoot|gains)?|s(?:eball|ketball)|uhaus|yern)?|b(?:c|t|va)?|c[gn]|d|e(?:a(?:ts|uty)|er|ntley|rlin|st(?:buy)?|t)?|f|g|h(?:arti)?|i(?:ble|d|ke|ngo?|o|z)?|j|l(?:ack(?:friday)?|o(?:ckbuster|g|omberg)|ue)|m[sw]?|n(?:pparibas)?|o(?:ats|ehringer|fa|m|nd|o(?:k(?:ing)?)?|s(?:ch|t(?:ik|on))|t|utique|x)?|r(?:adesco|idgestone|o(?:adway|ker|ther)|ussels)?|s|t|u(?:ild(?:ers)?|siness|y|zz)|v|w|y|zh?)|c(?:a(?:b|fe|l(?:l|vinklein)?|m(?:era|p)?|non|p(?:etown|ital(?:one)?)|r(?:avan|ds|e(?:ers?)?|s)?|s(?:a|e|h|ino)|t(?:ering|holic)?)?|b(?:a|n|re|s)|c|d|e(?:nter|o|rn)|f[ad]?|g|h(?:a(?:n(?:el|nel)|rity|se|t)|eap|intai|r(?:istmas|ome)|urch)?|i(?:priani|rcle|sco|t(?:adel|ic?|y(?:eats)?))?|k|l(?:aims|eaning|i(?:ck|ni(?:c|que))|o(?:thing|ud)|ub(?:med)?)?|m|n|o(?:ach|des|ffee|l(?:lege|ogne)|m(?:cast|m(?:bank|unity)|p(?:a(?:ny|re)|uter)|sec)?|n(?:dos|s(?:truction|ulting)|t(?:act|ractors))|o(?:king(?:channel)?|l|p)|rsica|u(?:ntry|pons?|rses))?|pa|r(?:edit(?:card|union)?|icket|own|s|uises?)?|u(?:isinella)?|v|w|x|y(?:mru|ou)?|z)|d(?:a(?:bur|d|nce|t(?:a|e|ing|sun)|y)|clk|ds|e(?:al(?:er|s)?|gree|l(?:ivery|l|oitte|ta)|mocrat|nt(?:al|ist)|si(?:gn)?|v)?|hl|i(?:amonds|et|gital|rect(?:ory)?|s(?:co(?:unt|ver)|h)|y)|j|k|m|np|o(?:c(?:s|tor)|g|mains|t|wnload)?|rive|tv|u(?:bai|nlop|pont|rban)|v(?:ag|r)|z)|e(?:a(?:rth|t)|co?|d(?:eka|u(?:cation)?)|e|g|m(?:ail|erck)|n(?:ergy|gineer(?:ing)?|terprises)|pson|quipment|r(?:icsson|ni)?|s(?:q|tate)?|t(?:isalat)?|u(?:rovision|s)?|vents|x(?:change|p(?:ert|osed|ress)|traspace))|f(?:a(?:ge|i(?:l|rwinds|th)|mily|ns?|rm(?:ers)?|s(?:hion|t))|e(?:dex|edback|rr(?:ari|ero))|i(?:at|d(?:elity|o)|lm|na(?:l|nc(?:e|ial))|r(?:e(?:stone)?|mdale)|sh(?:ing)?|t(?:ness)?)?|j|k|l(?:i(?:ckr|ghts|r)|o(?:rist|wers)|y)|m|o(?:o(?:d(?:network)?|tball)?|r(?:d|ex|sale|um)|undation|x)?|r(?:e(?:e|senius)|l|o(?:gans|nt(?:door|ier)))?|tr|u(?:jitsu|nd?|rniture|tbol)|yi)|g(?:a(?:l(?:l(?:ery|o|up))?|mes?|p|rden|y)?|b(?:iz)?|dn?|e(?:a|nt(?:ing)?|orge)?|f|g(?:ee)?|h|i(?:fts?|v(?:es|ing))?|l(?:ass|e|ob(?:al|o))?|m(?:ail|bh|o|x)?|n|o(?:daddy|l(?:d(?:point)?|f)|o(?:dyear|g(?:le)?)?|p|t|v)|p|q|r(?:a(?:inger|phics|tis)|een|ipe|o(?:cery|up))?|s|t|u(?:ardian|cci|ge|i(?:de|tars)|ru)?|w|y)|h(?:a(?:ir|mburg|ngout|us)|bo|dfc(?:bank)?|e(?:alth(?:care)?|l(?:p|sinki)|r(?:e|mes))|gtv|i(?:phop|samitsu|tachi|v)|kt?|m|n|o(?:ckey|l(?:dings|iday)|me(?:depot|goods|s(?:ense)?)|nda|rse|s(?:pital|t(?:ing)?)|t(?:el(?:es|s)|mail)?|use|w)|r|sbc|t|u(?:ghes)?|y(?:att|undai))|i(?:bm|c(?:bc|e|u)|d|e(?:ee)?|fm|kano|l|m(?:amat|db|mo(?:bilien)?)?|n(?:c|dustries|f(?:initi|o)|g|k|s(?:titute|ur(?:ance|e))|t(?:ernational|uit)?|vestments)?|o|piranga|q|r(?:ish)?|s(?:maili|t(?:anbul)?)?|t(?:au|v)?)|j(?:a(?:guar|va)|cb|e(?:ep|tzt|welry)?|io|ll|mp?|nj|o(?:b(?:s|urg)|t|y)?|p(?:morgan|rs)?|u(?:egos|niper))|k(?:aufen|ddi|e(?:rry(?:hotels|logistics|properties))?|fh|g|h|i(?:a|ds|m|nd(?:er|le)|tchen|wi)?|m|n|o(?:eln|matsu|sher)|p(?:mg|n)?|r(?:d|ed)?|uokgroup|w|y(?:oto)?|z)|l(?:a(?:caixa|m(?:borghini|er)|n(?:c(?:aster|ia)|d(?:rover)?|xess)|salle|t(?:ino|robe)?|w(?:yer)?)?|b|c|ds|e(?:ase|clerc|frak|g(?:al|o)|xus)|gbt|i(?:dl|fe(?:insurance|style)?|ghting|ke|lly|m(?:ited|o)|n(?:coln|de|k)|psy|v(?:e|ing))?|k|l[cp]|o(?:ans?|c(?:ker|us)|l|ndon|tt[eo]|ve)|pl(?:financial)?|r|s|t(?:da?)?|u(?:ndbeck|x(?:e|ury))?|v|y)|m(?:a(?:cys|drid|i(?:f|son)|keup|n(?:agement|go)?|p|r(?:ket(?:ing|s)?|riott|shalls)|serati|ttel)?|ba|c(?:kinsey)?|d|e(?:d(?:ia)?|et|lbourne|m(?:e|orial)|nu?|rckmsd)?|g|h|i(?:ami|crosoft|l|n[it]|t(?:subishi)?)|k|l[bs]?|ma?|n|o(?:bi(?:le)?|da|e|i|m|n(?:ash|ey|ster)|r(?:mon|tgage)|scow|to(?:rcycles)?|v(?:ie)?)?|p|q|r|sd?|t[nr]?|u(?:s(?:eum|ic)|tual)?|v|w|x|y|z)|n(?:a(?:b|goya|me|tura|vy)?|ba|c|e(?:c|t(?:bank|flix|work)?|ustar|ws?|x(?:t(?:direct)?|us))?|fl?|go?|hk|i(?:co|k(?:e|on)|nja|ssa[ny])?|l|o(?:kia|rt(?:hwesternmutual|on)|w(?:ruz|tv)?)?|p|r[aw]?|tt|u|yc|z)|o(?:b(?:i|server)|ffice|kinawa|l(?:ayan(?:group)?|dnavy|lo)|m(?:ega)?|n(?:e|g|l(?:ine)?)|oo|pen|r(?:a(?:cle|nge)|g(?:anic)?|igins)|saka|t(?:suka|t)|vh)|p(?:a(?:ge|nasonic|r(?:is|s|t(?:ners|s|y))|ssagens|y)?|ccw|et?|f(?:izer)?|g|h(?:armacy|d|ilips|o(?:ne|to(?:graphy|s)?)|ysio)?|i(?:c(?:s|t(?:et|ures))|d|n[gk]?|oneer|zza)|k|l(?:a(?:ce|y(?:station)?)|u(?:mbing|s))?|m|nc?|o(?:hl|ker|litie|rn|st)|r(?:a(?:merica|xi)|ess|ime|o(?:d(?:uctions)?|f|gressive|mo|pert(?:ies|y)|tection)?|u(?:dential)?)?|s|t|ub|wc?|y)|q(?:a|pon|ue(?:bec|st))|r(?:a(?:cing|dio)|e(?:a(?:d|l(?:estate|t(?:or|y)))|cipes|d(?:stone|umbrella)?|hab|i(?:sen?|t)|liance|n(?:t(?:als)?)?|p(?:air|ort|ublican)|st(?:aurant)?|views?|xroth)?|i(?:c(?:h(?:ardli)?|oh)|l|o|p)|o(?:c(?:her|ks)|deo|gers|om)?|s(?:vp)?|u(?:gby|hr|n)?|we?|yukyu)|s(?:a(?:arland|fe(?:ty)?|kura|l(?:e|on)|ms(?:club|ung)|n(?:dvik(?:coromant)?|ofi)|p|rl|s|ve|xo)?|b[is]?|c(?:a|b|h(?:aeffler|midt|o(?:larships|ol)|ule|warz)|ience|ot)?|d|e(?:a(?:rch|t)|cur(?:e|ity)|ek|lect|ner|rvices|ven|w|xy?)?|fr|g|h(?:a(?:ngrila|rp|w)|ell|i(?:a|ksha)|o(?:es|p(?:ping)?|uji|w(?:time)?))?|i(?:lk|n(?:a|gles)|te)?|j|k(?:in?|y(?:pe)?)?|l(?:ing)?|m(?:art|ile)?|n(?:cf)?|o(?:c(?:cer|ial)|ft(?:bank|ware)|hu|l(?:ar|utions)|n[gy]|y)?|p(?:a(?:ce)?|o(?:rt|t))|rl?|s|t(?:a(?:da|ples|r|te(?:bank|farm))|c(?:group)?|o(?:ckholm|r(?:age|e))|ream|ud(?:io|y)|yle)?|u(?:cks|pp(?:l(?:ies|y)|ort)|r(?:f|gery)|zuki)?|v|w(?:atch|iss)|x|y(?:dney|stems)?|z)|t(?:a(?:b|ipei|lk|obao|rget|t(?:a(?:motors|r)|too)|xi?)|ci?|dk?|e(?:am|ch(?:nology)?|l|masek|nnis|va)|f|g|h(?:d|eat(?:er|re))?|i(?:aa|ckets|enda|ffany|ps|r(?:es|ol))|j(?:maxx|x)?|k(?:maxx)?|l|m(?:all)?|n|o(?:day|kyo|ols|p|ray|shiba|tal|urs|wn|y(?:ota|s))?|r(?:a(?:d(?:e|ing)|ining|vel(?:channel|ers(?:insurance)?)?)|ust|v)?|t|u(?:be|i|nes|shu)|vs?|w|z)|u(?:a|b(?:ank|s)|g|k|n(?:i(?:com|versity)|o)|ol|ps|s|y|z)|v(?:a(?:cations|n(?:a|guard))?|c|e(?:gas|ntures|r(?:isign|sicherung)|t)?|g|i(?:ajes|deo|g|king|llas|n|p|rgin|s(?:a|ion)|v[ao])?|laanderen|n|o(?:dka|l(?:kswagen|vo)|t(?:e|ing|o)|yage)|u(?:elos)?)|w(?:a(?:l(?:es|mart|ter)|ng(?:gou)?|tch(?:es)?)|e(?:ather(?:channel)?|b(?:cam|er|site)|d(?:ding)?|i(?:bo|r))|f|hoswho|i(?:en|ki|lliamhill|n(?:dows|e|ners)?)|me|o(?:lterskluwer|odside|r(?:ks?|ld)|w)|s|t[cf])|x(?:box|erox|finity|i(?:huan|n)|xx|yz)|y(?:a(?:chts|hoo|maxun|ndex)|e|o(?:dobashi|ga|kohama|u(?:tube)?)|t|un)|z(?:a(?:ppos|ra)?|ero|ip|m|one|uerich|w)";
|
9
|
+
const PUNCTUATION_CHAR_PATTERN = "\\.\\,\\;\\!\\?";
|
10
|
+
const STOP_CHAR_PATTERN = "[" + PUNCTUATION_CHAR_PATTERN + "]";
|
11
|
+
const END_CHAR_PATTERN = "[^\\s" + PUNCTUATION_CHAR_PATTERN + "]";
|
12
|
+
const LINK_RE_BASE_PATTERN = "((?:(?:(?:https?:)?\\/\\/)?(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:" + TLD_RE_PATTERN + "))(?::\\d{2,5})?(?:/(?:\\S*" + END_CHAR_PATTERN + ")?)?(?:\\?(?:\\S*" + END_CHAR_PATTERN + "))?(?:\\#(?:\\S*" + END_CHAR_PATTERN + ")?)?)";
|
13
|
+
const LINK_ENTER_PATTERN = LINK_RE_BASE_PATTERN + STOP_CHAR_PATTERN + "?$";
|
14
|
+
const LINK_INPUT_PATTERN = LINK_RE_BASE_PATTERN + STOP_CHAR_PATTERN + "?\\s$";
|
15
|
+
const LINK_MARK_PATTERN = LINK_RE_BASE_PATTERN + "(?=" + STOP_CHAR_PATTERN + "|\\s|$)";
|
16
|
+
const LINK_ENTER_RE = new RegExp(LINK_ENTER_PATTERN, "gi");
|
17
|
+
const LINK_INPUT_RE = new RegExp(LINK_INPUT_PATTERN, "gi");
|
18
|
+
const LINK_MARK_RE = new RegExp(LINK_MARK_PATTERN, "gi");
|
38
19
|
|
39
|
-
|
20
|
+
//#endregion
|
21
|
+
//#region src/link/index.ts
|
22
|
+
/**
|
23
|
+
* @internal
|
24
|
+
*/
|
40
25
|
function defineLinkSpec() {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
61
|
-
});
|
26
|
+
return defineMarkSpec({
|
27
|
+
name: "link",
|
28
|
+
inclusive: false,
|
29
|
+
attrs: { href: { validate: "string" } },
|
30
|
+
parseDOM: [{
|
31
|
+
tag: "a[href]",
|
32
|
+
getAttrs: (dom) => {
|
33
|
+
return { href: dom.getAttribute("href") || "" };
|
34
|
+
}
|
35
|
+
}],
|
36
|
+
toDOM(node) {
|
37
|
+
const { href } = node.attrs;
|
38
|
+
return [
|
39
|
+
"a",
|
40
|
+
{ href },
|
41
|
+
0
|
42
|
+
];
|
43
|
+
}
|
44
|
+
});
|
62
45
|
}
|
63
46
|
function defineLinkCommands() {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
47
|
+
return defineCommands({
|
48
|
+
addLink: (attrs) => addMark({
|
49
|
+
type: "link",
|
50
|
+
attrs
|
51
|
+
}),
|
52
|
+
removeLink: () => removeMark({ type: "link" }),
|
53
|
+
toggleLink: (attrs) => toggleMark({
|
54
|
+
type: "link",
|
55
|
+
attrs
|
56
|
+
}),
|
57
|
+
expandLink: () => expandMark({ type: "link" })
|
58
|
+
});
|
70
59
|
}
|
60
|
+
/**
|
61
|
+
* Apply link marks after pressing Space.
|
62
|
+
*
|
63
|
+
* @internal
|
64
|
+
*/
|
71
65
|
function defineLinkInputRule() {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
})
|
79
|
-
);
|
66
|
+
return defineInputRule(new InputRule(LINK_INPUT_RE, (state, match, from) => {
|
67
|
+
const href = match[1];
|
68
|
+
if (!href) return null;
|
69
|
+
const mark = state.schema.marks.link.create({ href });
|
70
|
+
return state.tr.addMark(from, from + href.length, mark).insertText(" ");
|
71
|
+
}));
|
80
72
|
}
|
73
|
+
/**
|
74
|
+
* Apply link marks after typing Enter.
|
75
|
+
*
|
76
|
+
* @internal
|
77
|
+
*/
|
81
78
|
function defineLinkEnterRule() {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
79
|
+
return defineEnterRule({
|
80
|
+
regex: LINK_ENTER_RE,
|
81
|
+
handler: ({ state, from, match }) => {
|
82
|
+
const href = match[1];
|
83
|
+
if (!href) return null;
|
84
|
+
const mark = state.schema.marks.link.create({ href });
|
85
|
+
const tr = state.tr.addMark(from, from + href.length, mark);
|
86
|
+
return tr.docChanged ? tr : null;
|
87
|
+
}
|
88
|
+
});
|
92
89
|
}
|
90
|
+
/**
|
91
|
+
* Apply and remove link marks to the text during typing.
|
92
|
+
*
|
93
|
+
* @internal
|
94
|
+
*/
|
93
95
|
function defineLinkMarkRule() {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
return defineMarkRule({
|
97
|
+
regex: LINK_MARK_RE,
|
98
|
+
type: "link",
|
99
|
+
attrs: (match) => ({ href: match[1] })
|
100
|
+
});
|
99
101
|
}
|
102
|
+
/**
|
103
|
+
* @public
|
104
|
+
*/
|
100
105
|
function defineLink() {
|
101
|
-
|
102
|
-
defineLinkSpec(),
|
103
|
-
defineLinkCommands(),
|
104
|
-
defineLinkInputRule(),
|
105
|
-
defineLinkEnterRule()
|
106
|
-
);
|
106
|
+
return union(defineLinkSpec(), defineLinkCommands(), defineLinkInputRule(), defineLinkEnterRule());
|
107
107
|
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
defineLinkEnterRule,
|
112
|
-
defineLinkInputRule,
|
113
|
-
defineLinkMarkRule,
|
114
|
-
defineLinkSpec
|
115
|
-
};
|
108
|
+
|
109
|
+
//#endregion
|
110
|
+
export { defineLink, defineLinkCommands, defineLinkEnterRule, defineLinkInputRule, defineLinkMarkRule, defineLinkSpec };
|