@prosekit/extensions 0.2.5 → 0.3.1
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 -12
- package/dist/chunk-6DQPSMHC.js +111 -0
- package/dist/list/style.css +1 -1
- package/dist/prosekit-extensions-blockquote.d.ts +1 -0
- package/dist/prosekit-extensions-blockquote.js +12 -1
- package/dist/prosekit-extensions-code-block.js +3 -92
- package/dist/prosekit-extensions-link.d.ts +2 -0
- package/dist/prosekit-extensions-link.js +61 -5
- package/dist/prosekit-extensions-placeholder.js +1 -9
- package/dist/prosekit-extensions-virtual-selection.d.ts +1 -0
- package/dist/prosekit-extensions-virtual-selection.js +58 -0
- package/dist/virtual-selection/style.css +6 -0
- package/package.json +17 -6
- package/src/index.ts +0 -1
@@ -15,7 +15,6 @@ import { Parser } from 'prosemirror-highlight';
|
|
15
15
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
16
16
|
import { PluginKey } from '@prosekit/pm/state';
|
17
17
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
18
|
-
import type { Selection as Selection_2 } from '@prosekit/pm/state';
|
19
18
|
import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
|
20
19
|
import { Transaction } from '@prosekit/pm/state';
|
21
20
|
import { UnwrapListOptions } from 'prosemirror-flat-list';
|
@@ -75,6 +74,12 @@ export declare function defineBlockquote(): Extension< {
|
|
75
74
|
NODES: "blockquote";
|
76
75
|
}>;
|
77
76
|
|
77
|
+
/**
|
78
|
+
* Wraps the text block in a blockquote when `>` is typed at the start of a new
|
79
|
+
* line followed by a space.
|
80
|
+
*/
|
81
|
+
export declare function defineBlockquoteInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
82
|
+
|
78
83
|
export declare function defineBlockquoteSpec(): Extension< {
|
79
84
|
NODES: "blockquote";
|
80
85
|
}>;
|
@@ -129,7 +134,6 @@ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
|
129
134
|
insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
130
135
|
toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
131
136
|
setCodeBlockAttrs: [attrs: CodeBlockAttrs];
|
132
|
-
setCodeBlockLanguage: [language: string];
|
133
137
|
};
|
134
138
|
}>;
|
135
139
|
|
@@ -144,7 +148,6 @@ setCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
|
144
148
|
insertCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
145
149
|
toggleCodeBlock: [attrs?: CodeBlockAttrs | undefined];
|
146
150
|
setCodeBlockAttrs: [attrs: CodeBlockAttrs];
|
147
|
-
setCodeBlockLanguage: [language: string];
|
148
151
|
};
|
149
152
|
}>;
|
150
153
|
export { defineCodeBlockCommands }
|
@@ -243,7 +246,7 @@ export declare function defineDropCursor(options?: DropCursorOptions): Extension
|
|
243
246
|
*
|
244
247
|
* @public
|
245
248
|
*/
|
246
|
-
export declare function defineEnterRule({ regex, handler, }: EnterRuleOptions): Extension;
|
249
|
+
export declare function defineEnterRule({ regex, handler, stop, }: EnterRuleOptions): Extension;
|
247
250
|
|
248
251
|
/**
|
249
252
|
* @public
|
@@ -265,6 +268,10 @@ toggleHeading: [attrs?: HeadingAttrs | undefined];
|
|
265
268
|
};
|
266
269
|
}>;
|
267
270
|
|
271
|
+
/**
|
272
|
+
* Converts the text block to a heading when `#` is typed at the start of a new
|
273
|
+
* line followed by a space.
|
274
|
+
*/
|
268
275
|
export declare function defineHeadingInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
269
276
|
|
270
277
|
export declare function defineHeadingKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
@@ -335,6 +342,7 @@ COMMAND_ARGS: {
|
|
335
342
|
addLink: [attrs: LinkAttrs];
|
336
343
|
removeLink: [];
|
337
344
|
toggleLink: [attrs: LinkAttrs];
|
345
|
+
expandLink: [];
|
338
346
|
};
|
339
347
|
}>;
|
340
348
|
|
@@ -343,9 +351,14 @@ COMMAND_ARGS: {
|
|
343
351
|
addLink: [attrs: LinkAttrs];
|
344
352
|
removeLink: [];
|
345
353
|
toggleLink: [attrs: LinkAttrs];
|
354
|
+
expandLink: [];
|
346
355
|
};
|
347
356
|
}>;
|
348
357
|
|
358
|
+
export declare function defineLinkEnterRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
359
|
+
|
360
|
+
export declare function defineLinkInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
361
|
+
|
349
362
|
export declare function defineLinkSpec(): Extension< {
|
350
363
|
MARKS: "link";
|
351
364
|
}>;
|
@@ -460,7 +473,7 @@ MARKS: "strike";
|
|
460
473
|
*
|
461
474
|
* @public
|
462
475
|
*/
|
463
|
-
export declare function defineTextBlockEnterRule({ regex, type, attrs, }: TextBlockEnterRuleOptions): Extension;
|
476
|
+
export declare function defineTextBlockEnterRule({ regex, type, attrs, stop, }: TextBlockEnterRuleOptions): Extension;
|
464
477
|
|
465
478
|
/**
|
466
479
|
* Defines an input rule that changes the type of a textblock when the matched
|
@@ -508,6 +521,18 @@ export declare function defineUnderlineSpec(): Extension< {
|
|
508
521
|
MARKS: "underline";
|
509
522
|
}>;
|
510
523
|
|
524
|
+
/**
|
525
|
+
* Shows a virtual selection when the editor is not focused. When the editor is
|
526
|
+
* not focused, the selected inline content will be wrapped in a `<span>`
|
527
|
+
* element with the class `prosekit-virtual-selection`.
|
528
|
+
*
|
529
|
+
* This is useful when you want to move the focus to an element outside the
|
530
|
+
* editor, but still want to show the selection.
|
531
|
+
*
|
532
|
+
* @public
|
533
|
+
*/
|
534
|
+
export declare function defineVirtualSelection(): Extension;
|
535
|
+
|
511
536
|
/**
|
512
537
|
* Defines an input rule for automatically wrapping a textblock when a given
|
513
538
|
* string is typed.
|
@@ -584,6 +609,12 @@ export declare type EnterRuleOptions = {
|
|
584
609
|
* A handler function to be called when an enter rule is triggered.
|
585
610
|
*/
|
586
611
|
handler: EnterRuleHandler;
|
612
|
+
/**
|
613
|
+
* Whether to stop further handlers from being called if this rule is triggered.
|
614
|
+
*
|
615
|
+
* @default false
|
616
|
+
*/
|
617
|
+
stop?: boolean;
|
587
618
|
};
|
588
619
|
|
589
620
|
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
@@ -607,12 +638,9 @@ export declare interface ImageAttrs {
|
|
607
638
|
src?: string | null;
|
608
639
|
}
|
609
640
|
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
* @deprecated Use the one from `@prosekit/core` instead.
|
614
|
-
*/
|
615
|
-
export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
|
641
|
+
export declare const LINK_RE: RegExp;
|
642
|
+
|
643
|
+
export declare const LINK_SPACE_RE: RegExp;
|
616
644
|
|
617
645
|
/**
|
618
646
|
* @public
|
@@ -628,7 +656,7 @@ declare type MatchHandler = (options: {
|
|
628
656
|
to: number;
|
629
657
|
ignoreMatch: () => void;
|
630
658
|
deleteMatch: () => void;
|
631
|
-
}) =>
|
659
|
+
}) => void;
|
632
660
|
export { MatchHandler }
|
633
661
|
export { MatchHandler as MatchHandler_alias_1 }
|
634
662
|
|
@@ -686,6 +714,12 @@ export declare type TextBlockEnterRuleOptions = {
|
|
686
714
|
* Attributes to set on the node.
|
687
715
|
*/
|
688
716
|
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
717
|
+
/**
|
718
|
+
* Whether to stop further handlers from being called if this rule is triggered.
|
719
|
+
*
|
720
|
+
* @default true
|
721
|
+
*/
|
722
|
+
stop?: boolean;
|
689
723
|
};
|
690
724
|
|
691
725
|
export { }
|
@@ -0,0 +1,111 @@
|
|
1
|
+
// src/enter-rule/index.ts
|
2
|
+
import {
|
3
|
+
Facet,
|
4
|
+
OBJECT_REPLACEMENT_CHARACTER,
|
5
|
+
getNodeType,
|
6
|
+
isTextSelection,
|
7
|
+
pluginFacet
|
8
|
+
} from "@prosekit/core";
|
9
|
+
import { keydownHandler } from "@prosekit/pm/keymap";
|
10
|
+
import {
|
11
|
+
ProseMirrorPlugin
|
12
|
+
} from "@prosekit/pm/state";
|
13
|
+
function defineEnterRule({
|
14
|
+
regex,
|
15
|
+
handler,
|
16
|
+
stop = false
|
17
|
+
}) {
|
18
|
+
const rule = new EnterRule(regex, handler, stop);
|
19
|
+
return enterRule.extension([rule]);
|
20
|
+
}
|
21
|
+
function defineTextBlockEnterRule({
|
22
|
+
regex,
|
23
|
+
type,
|
24
|
+
attrs,
|
25
|
+
stop = true
|
26
|
+
}) {
|
27
|
+
return defineEnterRule({
|
28
|
+
regex,
|
29
|
+
handler: ({ state, from, to, match }) => {
|
30
|
+
const nodeType = getNodeType(state.schema, type);
|
31
|
+
const $start = state.doc.resolve(from);
|
32
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) {
|
33
|
+
return null;
|
34
|
+
}
|
35
|
+
const nodeAttrs = attrs && typeof attrs === "function" ? attrs(match) : attrs;
|
36
|
+
return state.tr.delete(from, to).setBlockType(from, from, nodeType, nodeAttrs);
|
37
|
+
},
|
38
|
+
stop
|
39
|
+
});
|
40
|
+
}
|
41
|
+
var EnterRule = class {
|
42
|
+
constructor(regex, handler, stop) {
|
43
|
+
this.regex = regex;
|
44
|
+
this.handler = handler;
|
45
|
+
this.stop = stop;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
var enterRule = Facet.define({
|
49
|
+
converter: () => {
|
50
|
+
let rules = [];
|
51
|
+
const command = (state, dispatch, view) => {
|
52
|
+
if (!view)
|
53
|
+
return false;
|
54
|
+
return execRules(view, rules, dispatch);
|
55
|
+
};
|
56
|
+
const handler = keydownHandler({ Enter: command });
|
57
|
+
const plugin = new ProseMirrorPlugin({ props: { handleKeyDown: handler } });
|
58
|
+
const pluginFunc = () => [plugin];
|
59
|
+
return {
|
60
|
+
create: (inputs) => {
|
61
|
+
rules = inputs;
|
62
|
+
return pluginFunc;
|
63
|
+
},
|
64
|
+
update: (inputs) => {
|
65
|
+
rules = inputs;
|
66
|
+
return null;
|
67
|
+
}
|
68
|
+
};
|
69
|
+
},
|
70
|
+
next: pluginFacet
|
71
|
+
});
|
72
|
+
function execRules(view, rules, dispatch) {
|
73
|
+
if (view.composing)
|
74
|
+
return false;
|
75
|
+
const state = view.state;
|
76
|
+
const selection = state.selection;
|
77
|
+
if (!isTextSelection(selection))
|
78
|
+
return false;
|
79
|
+
const $cursor = selection.$cursor;
|
80
|
+
if (!$cursor || $cursor.parent.type.spec.code)
|
81
|
+
return false;
|
82
|
+
const textBefore = $cursor.parent.textBetween(
|
83
|
+
Math.max(0, $cursor.parentOffset - MAX_MATCH),
|
84
|
+
$cursor.parentOffset,
|
85
|
+
null,
|
86
|
+
OBJECT_REPLACEMENT_CHARACTER
|
87
|
+
);
|
88
|
+
for (const rule of rules) {
|
89
|
+
rule.regex.lastIndex = 0;
|
90
|
+
const match = rule.regex.exec(textBefore);
|
91
|
+
const tr = match && rule.handler({
|
92
|
+
state,
|
93
|
+
from: $cursor.pos - match[0].length,
|
94
|
+
to: $cursor.pos,
|
95
|
+
match
|
96
|
+
});
|
97
|
+
if (!tr)
|
98
|
+
continue;
|
99
|
+
dispatch == null ? void 0 : dispatch(tr);
|
100
|
+
if (rule.stop) {
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
var MAX_MATCH = 200;
|
107
|
+
|
108
|
+
export {
|
109
|
+
defineEnterRule,
|
110
|
+
defineTextBlockEnterRule
|
111
|
+
};
|
package/dist/list/style.css
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.
|
1
|
+
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.6/node_modules/prosemirror-flat-list/dist/style.css */
|
2
2
|
.prosemirror-flat-list {
|
3
3
|
padding: 0;
|
4
4
|
margin-top: 0;
|
@@ -1,3 +1,7 @@
|
|
1
|
+
import {
|
2
|
+
defineWrappingInputRule
|
3
|
+
} from "./chunk-DYFRBXUX.js";
|
4
|
+
|
1
5
|
// src/blockquote/index.ts
|
2
6
|
import { defineNodeSpec, union } from "@prosekit/core";
|
3
7
|
function defineBlockquoteSpec() {
|
@@ -12,10 +16,17 @@ function defineBlockquoteSpec() {
|
|
12
16
|
}
|
13
17
|
});
|
14
18
|
}
|
19
|
+
function defineBlockquoteInputRule() {
|
20
|
+
return defineWrappingInputRule({
|
21
|
+
regex: /^>\s/,
|
22
|
+
type: "blockquote"
|
23
|
+
});
|
24
|
+
}
|
15
25
|
function defineBlockquote() {
|
16
|
-
return union([defineBlockquoteSpec()]);
|
26
|
+
return union([defineBlockquoteSpec(), defineBlockquoteInputRule()]);
|
17
27
|
}
|
18
28
|
export {
|
19
29
|
defineBlockquote,
|
30
|
+
defineBlockquoteInputRule,
|
20
31
|
defineBlockquoteSpec
|
21
32
|
};
|
@@ -1,3 +1,6 @@
|
|
1
|
+
import {
|
2
|
+
defineTextBlockEnterRule
|
3
|
+
} from "./chunk-6DQPSMHC.js";
|
1
4
|
import {
|
2
5
|
defineTextBlockInputRule
|
3
6
|
} from "./chunk-DYFRBXUX.js";
|
@@ -26,13 +29,6 @@ function defineCodeBlockCommands() {
|
|
26
29
|
},
|
27
30
|
setCodeBlockAttrs: (attrs) => {
|
28
31
|
return setNodeAttrs({ type: "codeBlock", attrs });
|
29
|
-
},
|
30
|
-
/**
|
31
|
-
* @deprecated Use `setCodeBlockAttrs` instead.
|
32
|
-
*/
|
33
|
-
setCodeBlockLanguage: (language) => {
|
34
|
-
const attrs = { language };
|
35
|
-
return setNodeAttrs({ type: "codeBlock", attrs });
|
36
32
|
}
|
37
33
|
});
|
38
34
|
}
|
@@ -48,91 +44,6 @@ function defineCodeBlockHighlight({
|
|
48
44
|
);
|
49
45
|
}
|
50
46
|
|
51
|
-
// src/enter-rule/index.ts
|
52
|
-
import {
|
53
|
-
Facet,
|
54
|
-
getNodeType,
|
55
|
-
isTextSelection,
|
56
|
-
keymapFacet,
|
57
|
-
OBJECT_REPLACEMENT_CHARACTER
|
58
|
-
} from "@prosekit/core";
|
59
|
-
function defineEnterRule({
|
60
|
-
regex,
|
61
|
-
handler
|
62
|
-
}) {
|
63
|
-
const rule = new EnterRule(regex, handler);
|
64
|
-
return inputRuleFacet.extension([rule]);
|
65
|
-
}
|
66
|
-
function defineTextBlockEnterRule({
|
67
|
-
regex,
|
68
|
-
type,
|
69
|
-
attrs
|
70
|
-
}) {
|
71
|
-
return defineEnterRule({
|
72
|
-
regex,
|
73
|
-
handler: ({ state, from, to, match }) => {
|
74
|
-
const nodeType = getNodeType(state.schema, type);
|
75
|
-
const $start = state.doc.resolve(from);
|
76
|
-
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) {
|
77
|
-
return null;
|
78
|
-
}
|
79
|
-
const nodeAttrs = attrs && typeof attrs === "function" ? attrs(match) : attrs;
|
80
|
-
return state.tr.delete(from, to).setBlockType(from, from, nodeType, nodeAttrs);
|
81
|
-
}
|
82
|
-
});
|
83
|
-
}
|
84
|
-
var EnterRule = class {
|
85
|
-
constructor(regex, handler) {
|
86
|
-
this.regex = regex;
|
87
|
-
this.handler = handler;
|
88
|
-
}
|
89
|
-
};
|
90
|
-
var inputRuleFacet = Facet.define({
|
91
|
-
convert: (inputs) => {
|
92
|
-
return {
|
93
|
-
Enter: (state, dispatch, view) => {
|
94
|
-
if (!view)
|
95
|
-
return false;
|
96
|
-
return execRules(view, inputs, dispatch);
|
97
|
-
}
|
98
|
-
};
|
99
|
-
},
|
100
|
-
next: keymapFacet
|
101
|
-
});
|
102
|
-
function execRules(view, rules, dispatch) {
|
103
|
-
if (view.composing)
|
104
|
-
return false;
|
105
|
-
const state = view.state;
|
106
|
-
const selection = state.selection;
|
107
|
-
if (!isTextSelection(selection))
|
108
|
-
return false;
|
109
|
-
const $cursor = selection.$cursor;
|
110
|
-
if (!$cursor || $cursor.parent.type.spec.code)
|
111
|
-
return false;
|
112
|
-
const textBefore = $cursor.parent.textBetween(
|
113
|
-
Math.max(0, $cursor.parentOffset - MAX_MATCH),
|
114
|
-
$cursor.parentOffset,
|
115
|
-
null,
|
116
|
-
OBJECT_REPLACEMENT_CHARACTER
|
117
|
-
);
|
118
|
-
for (const rule of rules) {
|
119
|
-
rule.regex.lastIndex = 0;
|
120
|
-
const match = rule.regex.exec(textBefore);
|
121
|
-
const tr = match && rule.handler({
|
122
|
-
state,
|
123
|
-
from: $cursor.pos - match[0].length,
|
124
|
-
to: $cursor.pos,
|
125
|
-
match
|
126
|
-
});
|
127
|
-
if (!tr)
|
128
|
-
continue;
|
129
|
-
dispatch == null ? void 0 : dispatch(tr);
|
130
|
-
return true;
|
131
|
-
}
|
132
|
-
return false;
|
133
|
-
}
|
134
|
-
var MAX_MATCH = 200;
|
135
|
-
|
136
47
|
// src/code-block/code-block-input-rule.ts
|
137
48
|
function defineCodeBlockInputRule() {
|
138
49
|
return defineTextBlockInputRule({
|
@@ -1,4 +1,6 @@
|
|
1
1
|
export { defineLinkSpec } from './_tsup-dts-rollup';
|
2
2
|
export { defineLinkCommands } from './_tsup-dts-rollup';
|
3
|
+
export { defineLinkInputRule } from './_tsup-dts-rollup';
|
4
|
+
export { defineLinkEnterRule } from './_tsup-dts-rollup';
|
3
5
|
export { defineLink } from './_tsup-dts-rollup';
|
4
6
|
export { LinkAttrs } from './_tsup-dts-rollup';
|
@@ -1,15 +1,39 @@
|
|
1
|
+
import {
|
2
|
+
defineEnterRule
|
3
|
+
} from "./chunk-6DQPSMHC.js";
|
4
|
+
import {
|
5
|
+
defineInputRule
|
6
|
+
} from "./chunk-DYFRBXUX.js";
|
7
|
+
|
1
8
|
// src/link/index.ts
|
2
9
|
import {
|
3
|
-
defineCommands,
|
4
10
|
addMark,
|
11
|
+
defineCommands,
|
5
12
|
defineMarkSpec,
|
6
|
-
|
13
|
+
expandMark,
|
7
14
|
removeMark,
|
8
|
-
toggleMark
|
15
|
+
toggleMark,
|
16
|
+
union
|
9
17
|
} from "@prosekit/core";
|
18
|
+
import { InputRule } from "@prosekit/pm/inputrules";
|
19
|
+
|
20
|
+
// src/link/link-regex.ts
|
21
|
+
var 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)";
|
22
|
+
var LINK_RE_BASE_PATTERN = (
|
23
|
+
// start of the link group
|
24
|
+
"((?:(?:(?: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*)?)"
|
25
|
+
);
|
26
|
+
var LINK_STOP_PATTERN = "(?:\\.|\\,|\\;\\!)?";
|
27
|
+
var LINK_RE_PATTERN = LINK_RE_BASE_PATTERN + LINK_STOP_PATTERN + "$";
|
28
|
+
var LINK_SPACE_RE_PATTERN = LINK_RE_BASE_PATTERN + LINK_STOP_PATTERN + "\\s$";
|
29
|
+
var LINK_RE = new RegExp(LINK_RE_PATTERN, "gi");
|
30
|
+
var LINK_SPACE_RE = new RegExp(LINK_SPACE_RE_PATTERN, "gi");
|
31
|
+
|
32
|
+
// src/link/index.ts
|
10
33
|
function defineLinkSpec() {
|
11
34
|
return defineMarkSpec({
|
12
35
|
name: "link",
|
36
|
+
inclusive: false,
|
13
37
|
parseDOM: [
|
14
38
|
{
|
15
39
|
tag: "a[href]",
|
@@ -33,14 +57,46 @@ function defineLinkCommands() {
|
|
33
57
|
return defineCommands({
|
34
58
|
addLink: (attrs) => addMark({ type: "link", attrs }),
|
35
59
|
removeLink: () => removeMark({ type: "link" }),
|
36
|
-
toggleLink: (attrs) => toggleMark({ type: "link", attrs })
|
60
|
+
toggleLink: (attrs) => toggleMark({ type: "link", attrs }),
|
61
|
+
expandLink: () => expandMark({ type: "link" })
|
62
|
+
});
|
63
|
+
}
|
64
|
+
function defineLinkInputRule() {
|
65
|
+
return defineInputRule(
|
66
|
+
new InputRule(LINK_SPACE_RE, (state, match, from) => {
|
67
|
+
const href = match[1];
|
68
|
+
if (!href)
|
69
|
+
return null;
|
70
|
+
const mark = state.schema.marks.link.create({ href });
|
71
|
+
return state.tr.addMark(from, from + href.length, mark).insertText(" ");
|
72
|
+
})
|
73
|
+
);
|
74
|
+
}
|
75
|
+
function defineLinkEnterRule() {
|
76
|
+
return defineEnterRule({
|
77
|
+
regex: LINK_RE,
|
78
|
+
handler: ({ state, from, match }) => {
|
79
|
+
const href = match[1];
|
80
|
+
if (!href)
|
81
|
+
return null;
|
82
|
+
const mark = state.schema.marks.link.create({ href });
|
83
|
+
const tr = state.tr.addMark(from, from + href.length, mark);
|
84
|
+
return tr.docChanged ? tr : null;
|
85
|
+
}
|
37
86
|
});
|
38
87
|
}
|
39
88
|
function defineLink() {
|
40
|
-
return union([
|
89
|
+
return union([
|
90
|
+
defineLinkSpec(),
|
91
|
+
defineLinkCommands(),
|
92
|
+
defineLinkInputRule(),
|
93
|
+
defineLinkEnterRule()
|
94
|
+
]);
|
41
95
|
}
|
42
96
|
export {
|
43
97
|
defineLink,
|
44
98
|
defineLinkCommands,
|
99
|
+
defineLinkEnterRule,
|
100
|
+
defineLinkInputRule,
|
45
101
|
defineLinkSpec
|
46
102
|
};
|
@@ -1,16 +1,8 @@
|
|
1
1
|
// src/placeholder/index.ts
|
2
|
-
import { definePlugin } from "@prosekit/core";
|
2
|
+
import { definePlugin, isInCodeBlock } from "@prosekit/core";
|
3
3
|
import "@prosekit/pm/model";
|
4
4
|
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
5
5
|
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
6
|
-
|
7
|
-
// src/utils/is-in-code-block.ts
|
8
|
-
function isInCodeBlock(selection) {
|
9
|
-
const type = selection.$from.parent.type;
|
10
|
-
return type.spec.code && type.isBlock;
|
11
|
-
}
|
12
|
-
|
13
|
-
// src/placeholder/index.ts
|
14
6
|
function definePlaceholder(options) {
|
15
7
|
return definePlugin(createPlaceholderPlugin(options));
|
16
8
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { defineVirtualSelection } from './_tsup-dts-rollup';
|
@@ -0,0 +1,58 @@
|
|
1
|
+
// src/virtual-selection/index.ts
|
2
|
+
import { definePlugin } from "@prosekit/core";
|
3
|
+
import {
|
4
|
+
PluginKey,
|
5
|
+
ProseMirrorPlugin
|
6
|
+
} from "@prosekit/pm/state";
|
7
|
+
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
8
|
+
function defineVirtualSelection() {
|
9
|
+
return definePlugin(virtualSelectionPlugin);
|
10
|
+
}
|
11
|
+
var key = new PluginKey("prosekit-virtual-selection");
|
12
|
+
function getFocusMeta(tr) {
|
13
|
+
return tr.getMeta(key);
|
14
|
+
}
|
15
|
+
function setFocusMeta(tr, value) {
|
16
|
+
return tr.setMeta(key, value);
|
17
|
+
}
|
18
|
+
function getFocusState(state) {
|
19
|
+
return key.getState(state);
|
20
|
+
}
|
21
|
+
var virtualSelectionPlugin = new ProseMirrorPlugin({
|
22
|
+
key,
|
23
|
+
state: {
|
24
|
+
init: () => false,
|
25
|
+
apply: (tr, value) => {
|
26
|
+
var _a;
|
27
|
+
return (_a = getFocusMeta(tr)) != null ? _a : value;
|
28
|
+
}
|
29
|
+
},
|
30
|
+
props: {
|
31
|
+
handleDOMEvents: {
|
32
|
+
focus: (view) => {
|
33
|
+
view.dispatch(setFocusMeta(view.state.tr, false));
|
34
|
+
},
|
35
|
+
blur: (view) => {
|
36
|
+
const { dom, root } = view;
|
37
|
+
const activeElement = root.activeElement;
|
38
|
+
if (activeElement === dom)
|
39
|
+
return;
|
40
|
+
view.dispatch(setFocusMeta(view.state.tr, true));
|
41
|
+
}
|
42
|
+
},
|
43
|
+
decorations: (state) => {
|
44
|
+
const { selection, doc } = state;
|
45
|
+
if (selection.empty || !getFocusState(state)) {
|
46
|
+
return null;
|
47
|
+
}
|
48
|
+
return DecorationSet.create(doc, [
|
49
|
+
Decoration.inline(selection.from, selection.to, {
|
50
|
+
class: "prosekit-virtual-selection"
|
51
|
+
})
|
52
|
+
]);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
export {
|
57
|
+
defineVirtualSelection
|
58
|
+
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.3.1",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -120,17 +120,25 @@
|
|
120
120
|
"types": "./dist/prosekit-extensions-underline.d.ts",
|
121
121
|
"import": "./dist/prosekit-extensions-underline.js",
|
122
122
|
"default": "./dist/prosekit-extensions-underline.js"
|
123
|
+
},
|
124
|
+
"./virtual-selection": {
|
125
|
+
"types": "./dist/prosekit-extensions-virtual-selection.d.ts",
|
126
|
+
"import": "./dist/prosekit-extensions-virtual-selection.js",
|
127
|
+
"default": "./dist/prosekit-extensions-virtual-selection.js"
|
128
|
+
},
|
129
|
+
"./virtual-selection/style.css": {
|
130
|
+
"default": "./dist/virtual-selection/style.css"
|
123
131
|
}
|
124
132
|
},
|
125
133
|
"files": [
|
126
134
|
"dist"
|
127
135
|
],
|
128
136
|
"dependencies": {
|
129
|
-
"@prosekit/core": "^0.
|
137
|
+
"@prosekit/core": "^0.3.0",
|
130
138
|
"@prosekit/pm": "^0.1.1",
|
131
139
|
"prosemirror-dropcursor": "^1.8.1",
|
132
|
-
"prosemirror-flat-list": "^0.4.
|
133
|
-
"prosemirror-highlight": "^0.4.
|
140
|
+
"prosemirror-flat-list": "^0.4.6",
|
141
|
+
"prosemirror-highlight": "^0.4.1"
|
134
142
|
},
|
135
143
|
"peerDependencies": {
|
136
144
|
"shikiji": ">= 0.9.0"
|
@@ -142,10 +150,10 @@
|
|
142
150
|
},
|
143
151
|
"devDependencies": {
|
144
152
|
"@prosekit/dev": "*",
|
145
|
-
"shikiji": "^0.
|
153
|
+
"shikiji": "^0.10.2",
|
146
154
|
"tsup": "^8.0.1",
|
147
155
|
"typescript": "^5.3.3",
|
148
|
-
"vitest": "^1.2.
|
156
|
+
"vitest": "^1.2.2"
|
149
157
|
},
|
150
158
|
"scripts": {
|
151
159
|
"build:tsup": "tsup",
|
@@ -207,6 +215,9 @@
|
|
207
215
|
],
|
208
216
|
"underline": [
|
209
217
|
"./dist/prosekit-extensions-underline.d.ts"
|
218
|
+
],
|
219
|
+
"virtual-selection": [
|
220
|
+
"./dist/prosekit-extensions-virtual-selection.d.ts"
|
210
221
|
]
|
211
222
|
}
|
212
223
|
}
|
package/src/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {}
|