@prosekit/extensions 0.0.0-next-20231120040948 → 0.0.0-next-20240427133255
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 +560 -91
- package/dist/chunk-ASTUC4KT.js +111 -0
- package/dist/chunk-DYFRBXUX.js +56 -0
- package/dist/list/style.css +17 -12
- package/dist/prosekit-extensions-autocomplete.js +8 -4
- package/dist/prosekit-extensions-blockquote.d.ts +1 -0
- package/dist/prosekit-extensions-blockquote.js +12 -1
- package/dist/prosekit-extensions-code-block.d.ts +14 -4
- package/dist/prosekit-extensions-code-block.js +171 -75
- package/dist/prosekit-extensions-drop-cursor.d.ts +2 -0
- package/dist/prosekit-extensions-drop-cursor.js +9 -0
- package/dist/prosekit-extensions-enter-rule.d.ts +5 -0
- package/dist/prosekit-extensions-enter-rule.js +8 -0
- package/dist/prosekit-extensions-heading.js +20 -14
- package/dist/prosekit-extensions-image.js +1 -0
- package/dist/prosekit-extensions-input-rule.d.ts +3 -0
- package/dist/prosekit-extensions-input-rule.js +10 -0
- package/dist/prosekit-extensions-link.d.ts +2 -0
- package/dist/prosekit-extensions-link.js +63 -5
- package/dist/prosekit-extensions-list.d.ts +1 -0
- package/dist/prosekit-extensions-list.js +7 -2
- package/dist/prosekit-extensions-mark-rule.d.ts +3 -0
- package/dist/prosekit-extensions-mark-rule.js +173 -0
- package/dist/prosekit-extensions-mention.d.ts +1 -0
- package/dist/prosekit-extensions-mention.js +15 -2
- package/dist/prosekit-extensions-placeholder.js +4 -1
- package/dist/prosekit-extensions-readonly.d.ts +1 -0
- package/dist/prosekit-extensions-readonly.js +16 -0
- package/dist/prosekit-extensions-table.d.ts +7 -0
- package/dist/prosekit-extensions-table.js +197 -0
- package/dist/prosekit-extensions-virtual-selection.d.ts +1 -0
- package/dist/prosekit-extensions-virtual-selection.js +58 -0
- package/dist/shiki-import-25BJYIO2.js +5 -0
- package/dist/table/style.css +34 -0
- package/dist/virtual-selection/style.css +6 -0
- package/package.json +71 -15
- package/dist/prosekit-extensions-suggestion.d.ts +0 -3
- package/dist/prosekit-extensions-suggestion.js +0 -161
- package/src/index.ts +0 -1
@@ -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,14 +1,39 @@
|
|
1
|
+
import {
|
2
|
+
defineEnterRule
|
3
|
+
} from "./chunk-ASTUC4KT.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
|
-
|
7
|
-
|
13
|
+
expandMark,
|
14
|
+
removeMark,
|
15
|
+
toggleMark,
|
16
|
+
union
|
8
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
|
9
33
|
function defineLinkSpec() {
|
10
34
|
return defineMarkSpec({
|
11
35
|
name: "link",
|
36
|
+
inclusive: false,
|
12
37
|
parseDOM: [
|
13
38
|
{
|
14
39
|
tag: "a[href]",
|
@@ -31,14 +56,47 @@ function defineLinkSpec() {
|
|
31
56
|
function defineLinkCommands() {
|
32
57
|
return defineCommands({
|
33
58
|
addLink: (attrs) => addMark({ type: "link", attrs }),
|
34
|
-
|
59
|
+
removeLink: () => removeMark({ type: "link" }),
|
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
|
+
}
|
35
86
|
});
|
36
87
|
}
|
37
88
|
function defineLink() {
|
38
|
-
return union([
|
89
|
+
return union([
|
90
|
+
defineLinkSpec(),
|
91
|
+
defineLinkCommands(),
|
92
|
+
defineLinkInputRule(),
|
93
|
+
defineLinkEnterRule()
|
94
|
+
]);
|
39
95
|
}
|
40
96
|
export {
|
41
97
|
defineLink,
|
42
98
|
defineLinkCommands,
|
99
|
+
defineLinkEnterRule,
|
100
|
+
defineLinkInputRule,
|
43
101
|
defineLinkSpec
|
44
102
|
};
|
@@ -4,3 +4,4 @@ export { defineListKeymap } from './_tsup-dts-rollup';
|
|
4
4
|
export { defineListInputRules } from './_tsup-dts-rollup';
|
5
5
|
export { defineListCommands } from './_tsup-dts-rollup';
|
6
6
|
export { defineList } from './_tsup-dts-rollup';
|
7
|
+
export { ListDOMSerializer } from './_tsup-dts-rollup';
|
@@ -1,8 +1,11 @@
|
|
1
|
+
import {
|
2
|
+
defineInputRule
|
3
|
+
} from "./chunk-DYFRBXUX.js";
|
4
|
+
|
1
5
|
// src/list/index.ts
|
2
6
|
import {
|
3
7
|
Priority,
|
4
8
|
defineCommands,
|
5
|
-
defineInputRule,
|
6
9
|
defineKeymap,
|
7
10
|
defineNodeSpec,
|
8
11
|
definePlugin,
|
@@ -24,6 +27,7 @@ import {
|
|
24
27
|
listInputRules,
|
25
28
|
listKeymap
|
26
29
|
} from "prosemirror-flat-list";
|
30
|
+
import { ListDOMSerializer } from "prosemirror-flat-list";
|
27
31
|
function defineListSpec() {
|
28
32
|
return defineNodeSpec({ ...createListSpec(), name: "list" });
|
29
33
|
}
|
@@ -34,7 +38,7 @@ function defineListKeymap() {
|
|
34
38
|
return defineKeymap(listKeymap);
|
35
39
|
}
|
36
40
|
function defineListInputRules() {
|
37
|
-
return
|
41
|
+
return union(listInputRules.map(defineInputRule));
|
38
42
|
}
|
39
43
|
function defineListCommands() {
|
40
44
|
return defineCommands({
|
@@ -62,6 +66,7 @@ function defineList() {
|
|
62
66
|
]);
|
63
67
|
}
|
64
68
|
export {
|
69
|
+
ListDOMSerializer,
|
65
70
|
defineList,
|
66
71
|
defineListCommands,
|
67
72
|
defineListInputRules,
|
@@ -0,0 +1,173 @@
|
|
1
|
+
// src/mark-rule/index.ts
|
2
|
+
import {
|
3
|
+
Facet,
|
4
|
+
OBJECT_REPLACEMENT_CHARACTER,
|
5
|
+
getMarkType,
|
6
|
+
pluginFacet
|
7
|
+
} from "@prosekit/core";
|
8
|
+
import "@prosekit/pm/model";
|
9
|
+
import { ProseMirrorPlugin } from "@prosekit/pm/state";
|
10
|
+
|
11
|
+
// src/mark-rule/changed-range.ts
|
12
|
+
import { isTextSelection } from "@prosekit/core";
|
13
|
+
function getSpanTextRanges($from, $to) {
|
14
|
+
const nodeRange = $from.blockRange($to);
|
15
|
+
if (!nodeRange) {
|
16
|
+
return [];
|
17
|
+
}
|
18
|
+
const stack = [];
|
19
|
+
let start = nodeRange.start;
|
20
|
+
for (let i = nodeRange.startIndex; i < nodeRange.endIndex; i++) {
|
21
|
+
const child = nodeRange.parent.child(i);
|
22
|
+
stack.push([start, child]);
|
23
|
+
start += child.nodeSize;
|
24
|
+
}
|
25
|
+
const ranges = [];
|
26
|
+
while (stack.length > 0) {
|
27
|
+
const [start2, node] = stack.pop();
|
28
|
+
if (node.type.spec.code) {
|
29
|
+
continue;
|
30
|
+
}
|
31
|
+
if (node.type.isTextblock) {
|
32
|
+
ranges.push([start2 + 1, start2 + 1 + node.content.size]);
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
node.forEach((child, offset) => {
|
36
|
+
stack.push([start2 + offset + 1, child]);
|
37
|
+
});
|
38
|
+
}
|
39
|
+
return ranges;
|
40
|
+
}
|
41
|
+
|
42
|
+
// src/mark-rule/index.ts
|
43
|
+
function defineMarkRule(options) {
|
44
|
+
return markRuleFacet.extension([options]);
|
45
|
+
}
|
46
|
+
function getAffectedRange(transactions, oldState, newState) {
|
47
|
+
let lo = oldState.selection.from;
|
48
|
+
let hi = oldState.selection.to;
|
49
|
+
for (const tr of transactions) {
|
50
|
+
for (const map of tr.mapping.maps) {
|
51
|
+
lo = map.map(lo);
|
52
|
+
hi = map.map(hi);
|
53
|
+
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
54
|
+
lo = Math.min(lo, hi, newStart);
|
55
|
+
hi = Math.max(hi, hi, newEnd);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
lo = Math.min(lo, hi, newState.selection.from);
|
60
|
+
hi = Math.min(lo, hi, newState.selection.to);
|
61
|
+
return [lo, hi];
|
62
|
+
}
|
63
|
+
function getCheckRanges(doc, from, to) {
|
64
|
+
const $from = doc.resolve(from);
|
65
|
+
const $to = doc.resolve(to);
|
66
|
+
if ($from.sameParent($to)) {
|
67
|
+
return [[$from.start(), $to.end()]];
|
68
|
+
} else {
|
69
|
+
const nodeRange = $from.blockRange($to);
|
70
|
+
if (!nodeRange) {
|
71
|
+
return [];
|
72
|
+
}
|
73
|
+
return getSpanTextRanges($from, $to);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
function getExpectedMarkings(rules, doc, from, to) {
|
77
|
+
const text = doc.textBetween(from, to, OBJECT_REPLACEMENT_CHARACTER);
|
78
|
+
const result = [];
|
79
|
+
for (const rule of rules) {
|
80
|
+
rule.regex.lastIndex = 0;
|
81
|
+
const matches = text.matchAll(rule.regex);
|
82
|
+
const markType = getMarkType(doc.type.schema, rule.type);
|
83
|
+
const getAttrs = rule.attrs;
|
84
|
+
for (const match of matches) {
|
85
|
+
const index = match.index;
|
86
|
+
if (index == null)
|
87
|
+
continue;
|
88
|
+
const attrs = getAttrs ? typeof getAttrs === "function" ? getAttrs(match) : getAttrs : null;
|
89
|
+
const mark = markType.create(attrs);
|
90
|
+
result.push([from + index, from + index + match[0].length, mark]);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
return result;
|
94
|
+
}
|
95
|
+
function getReceivedMarkings(rules, doc, from, to) {
|
96
|
+
const result = [];
|
97
|
+
const schema = doc.type.schema;
|
98
|
+
const markTypes = rules.map((rule) => getMarkType(schema, rule.type));
|
99
|
+
let seen = false;
|
100
|
+
doc.nodesBetween(from, to, (node) => {
|
101
|
+
if (!node.isTextblock || seen) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
seen = true;
|
105
|
+
node.content.forEach((child, offset) => {
|
106
|
+
for (const markType of markTypes) {
|
107
|
+
const mark = child.marks.find((mark2) => mark2.type === markType);
|
108
|
+
if (mark) {
|
109
|
+
result.push([from + offset, from + offset + child.nodeSize, mark]);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
});
|
113
|
+
});
|
114
|
+
return result;
|
115
|
+
}
|
116
|
+
function markingEquals(a, b) {
|
117
|
+
return a[0] === b[0] && a[1] === b[1] && a[2].eq(b[2]);
|
118
|
+
}
|
119
|
+
function markingDiffs(a, b) {
|
120
|
+
return a.filter((x) => !b.some((y) => markingEquals(x, y)));
|
121
|
+
}
|
122
|
+
function applyMarkRules(rules, transactions, oldState, newState) {
|
123
|
+
if (transactions.length === 0 || transactions.every((tr2) => !tr2.docChanged)) {
|
124
|
+
return null;
|
125
|
+
}
|
126
|
+
const [from, to] = getAffectedRange(transactions, oldState, newState);
|
127
|
+
const ranges = getCheckRanges(newState.doc, from, to);
|
128
|
+
const toRemove = [];
|
129
|
+
const toCreate = [];
|
130
|
+
for (const [from2, to2] of ranges) {
|
131
|
+
const expected = getExpectedMarkings(rules, newState.doc, from2, to2);
|
132
|
+
const received = getReceivedMarkings(rules, newState.doc, from2, to2);
|
133
|
+
toRemove.push(...markingDiffs(received, expected));
|
134
|
+
toCreate.push(...markingDiffs(expected, received));
|
135
|
+
}
|
136
|
+
if (toCreate.length === 0 && toRemove.length === 0) {
|
137
|
+
return null;
|
138
|
+
}
|
139
|
+
const tr = newState.tr;
|
140
|
+
for (const [from2, to2, mark] of toRemove) {
|
141
|
+
tr.removeMark(from2, to2, mark);
|
142
|
+
}
|
143
|
+
for (const [from2, to2, mark] of toCreate) {
|
144
|
+
tr.addMark(from2, to2, mark);
|
145
|
+
}
|
146
|
+
return tr;
|
147
|
+
}
|
148
|
+
var markRuleFacet = Facet.define({
|
149
|
+
converter: () => {
|
150
|
+
let rules = [];
|
151
|
+
const plugin = new ProseMirrorPlugin({
|
152
|
+
appendTransaction: (transactions, oldState, newState) => {
|
153
|
+
return applyMarkRules(rules, transactions, oldState, newState);
|
154
|
+
}
|
155
|
+
});
|
156
|
+
const pluginFunc = () => [plugin];
|
157
|
+
return {
|
158
|
+
create: (inputs) => {
|
159
|
+
rules = inputs;
|
160
|
+
return pluginFunc;
|
161
|
+
},
|
162
|
+
update: (inputs) => {
|
163
|
+
rules = inputs;
|
164
|
+
return null;
|
165
|
+
}
|
166
|
+
};
|
167
|
+
},
|
168
|
+
next: pluginFacet
|
169
|
+
});
|
170
|
+
export {
|
171
|
+
defineMarkRule,
|
172
|
+
getAffectedRange
|
173
|
+
};
|
@@ -1,5 +1,10 @@
|
|
1
1
|
// src/mention/index.ts
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
defineCommands,
|
4
|
+
defineNodeSpec,
|
5
|
+
insertNode,
|
6
|
+
union
|
7
|
+
} from "@prosekit/core";
|
3
8
|
function defineMentionSpec() {
|
4
9
|
return defineNodeSpec({
|
5
10
|
name: "mention",
|
@@ -34,10 +39,18 @@ function defineMentionSpec() {
|
|
34
39
|
}
|
35
40
|
});
|
36
41
|
}
|
42
|
+
function defineMentionCommands() {
|
43
|
+
return defineCommands({
|
44
|
+
insertMention: (attrs) => {
|
45
|
+
return insertNode({ type: "mention", attrs });
|
46
|
+
}
|
47
|
+
});
|
48
|
+
}
|
37
49
|
function defineMention() {
|
38
|
-
return union([defineMentionSpec()]);
|
50
|
+
return union([defineMentionSpec(), defineMentionCommands()]);
|
39
51
|
}
|
40
52
|
export {
|
41
53
|
defineMention,
|
54
|
+
defineMentionCommands,
|
42
55
|
defineMentionSpec
|
43
56
|
};
|
@@ -1,5 +1,5 @@
|
|
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";
|
@@ -14,6 +14,9 @@ function createPlaceholderPlugin(options) {
|
|
14
14
|
if (options.strategy === "doc" && !isDocEmpty(state.doc)) {
|
15
15
|
return null;
|
16
16
|
}
|
17
|
+
if (isInCodeBlock(state.selection)) {
|
18
|
+
return null;
|
19
|
+
}
|
17
20
|
const placeholderText = options.placeholder;
|
18
21
|
const deco = createPlaceholderDecoration(state, placeholderText);
|
19
22
|
if (!deco) {
|
@@ -0,0 +1 @@
|
|
1
|
+
export { defineReadonly } from './_tsup-dts-rollup';
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// src/readonly/index.ts
|
2
|
+
import { definePlugin } from "@prosekit/core";
|
3
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
4
|
+
function defineReadonly() {
|
5
|
+
return definePlugin(plugin);
|
6
|
+
}
|
7
|
+
var key = new PluginKey("readonly");
|
8
|
+
var plugin = new ProseMirrorPlugin({
|
9
|
+
key,
|
10
|
+
props: {
|
11
|
+
editable: () => false
|
12
|
+
}
|
13
|
+
});
|
14
|
+
export {
|
15
|
+
defineReadonly
|
16
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { defineTable } from './_tsup-dts-rollup';
|
2
|
+
export { defineTableCellSpec } from './_tsup-dts-rollup';
|
3
|
+
export { defineTableCommands } from './_tsup-dts-rollup';
|
4
|
+
export { defineTableHeaderCellSpec } from './_tsup-dts-rollup';
|
5
|
+
export { defineTablePlugins } from './_tsup-dts-rollup';
|
6
|
+
export { defineTableRowSpec } from './_tsup-dts-rollup';
|
7
|
+
export { defineTableSpec } from './_tsup-dts-rollup';
|
@@ -0,0 +1,197 @@
|
|
1
|
+
// src/table/index.ts
|
2
|
+
import { union } from "@prosekit/core";
|
3
|
+
|
4
|
+
// src/table/table-commands.ts
|
5
|
+
import {
|
6
|
+
defaultBlockAt,
|
7
|
+
defineCommands,
|
8
|
+
getNodeType,
|
9
|
+
insertNode
|
10
|
+
} from "@prosekit/core";
|
11
|
+
import { TextSelection } from "@prosekit/pm/state";
|
12
|
+
function createEmptyTable(schema, row, col, header) {
|
13
|
+
const table = getNodeType(schema, "table");
|
14
|
+
const tableRow = getNodeType(schema, "tableRow");
|
15
|
+
const tableCell = getNodeType(schema, "tableCell");
|
16
|
+
const tableHeaderCell = getNodeType(schema, "tableHeaderCell");
|
17
|
+
const createHeaderRow = () => {
|
18
|
+
return tableRow.createAndFill(
|
19
|
+
null,
|
20
|
+
Array.from({ length: col }, () => tableHeaderCell.createAndFill())
|
21
|
+
);
|
22
|
+
};
|
23
|
+
const createBodyRow = () => {
|
24
|
+
return tableRow.createAndFill(
|
25
|
+
null,
|
26
|
+
Array.from({ length: col }, () => tableCell.createAndFill())
|
27
|
+
);
|
28
|
+
};
|
29
|
+
const rows = [
|
30
|
+
...Array.from({ length: header ? 1 : 0 }, createHeaderRow),
|
31
|
+
...Array.from({ length: header ? row - 1 : row }, createBodyRow)
|
32
|
+
];
|
33
|
+
return table.createAndFill(null, rows);
|
34
|
+
}
|
35
|
+
function insertTable({
|
36
|
+
row,
|
37
|
+
col,
|
38
|
+
header
|
39
|
+
}) {
|
40
|
+
return (state, dispatch, view) => {
|
41
|
+
const table = createEmptyTable(state.schema, row, col, header);
|
42
|
+
return insertNode({ node: table })(state, dispatch, view);
|
43
|
+
};
|
44
|
+
}
|
45
|
+
var exitTable = (state, dispatch) => {
|
46
|
+
const { $head, $anchor } = state.selection;
|
47
|
+
if (!$head.sameParent($anchor)) {
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
let tableStart = -1;
|
51
|
+
let tableDepth = -1;
|
52
|
+
for (let depth = $head.depth; depth >= 0; depth--) {
|
53
|
+
const node2 = $head.node(depth);
|
54
|
+
if (node2.type.spec.tableRole === "table") {
|
55
|
+
tableStart = $head.before(depth);
|
56
|
+
tableDepth = depth;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
if (tableStart < 0 || tableDepth <= 0) {
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
const above = $head.node(tableDepth - 1);
|
63
|
+
const after = $head.indexAfter(tableDepth - 1);
|
64
|
+
const type = defaultBlockAt(above.contentMatchAt(after));
|
65
|
+
const node = type == null ? void 0 : type.createAndFill();
|
66
|
+
if (!type || !node || !above.canReplaceWith(after, after, type)) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
if (dispatch) {
|
70
|
+
const pos = $head.after(tableDepth);
|
71
|
+
const tr = state.tr.replaceWith(pos, pos, node);
|
72
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
|
73
|
+
dispatch(tr.scrollIntoView());
|
74
|
+
}
|
75
|
+
return true;
|
76
|
+
};
|
77
|
+
function defineTableCommands() {
|
78
|
+
return defineCommands({
|
79
|
+
insertTable,
|
80
|
+
exitTable: () => exitTable
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
// src/table/table-plugins.ts
|
85
|
+
import { definePlugin } from "@prosekit/core";
|
86
|
+
import { tableEditing, columnResizing } from "prosemirror-tables";
|
87
|
+
function defineTablePlugins() {
|
88
|
+
return definePlugin([tableEditing(), columnResizing()]);
|
89
|
+
}
|
90
|
+
|
91
|
+
// src/table/table-spec.ts
|
92
|
+
import { defineNodeSpec } from "@prosekit/core";
|
93
|
+
import "prosemirror-tables";
|
94
|
+
var cellAttrs = {
|
95
|
+
colspan: { default: 1 },
|
96
|
+
rowspan: { default: 1 },
|
97
|
+
colwidth: { default: null }
|
98
|
+
};
|
99
|
+
var cellContent = "block+";
|
100
|
+
function getCellAttrs(dom) {
|
101
|
+
if (typeof dom === "string") {
|
102
|
+
return {};
|
103
|
+
}
|
104
|
+
const widthAttr = dom.getAttribute("data-colwidth");
|
105
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
|
106
|
+
const colspan = Number(dom.getAttribute("colspan") || 1);
|
107
|
+
return {
|
108
|
+
colspan,
|
109
|
+
rowspan: Number(dom.getAttribute("rowspan") || 1),
|
110
|
+
colwidth: widths && widths.length == colspan ? widths : null
|
111
|
+
};
|
112
|
+
}
|
113
|
+
function setCellAttrs(node) {
|
114
|
+
const pmAttrs = node.attrs;
|
115
|
+
const domAttrs = {};
|
116
|
+
if (pmAttrs.colspan !== 1) {
|
117
|
+
domAttrs.colspan = pmAttrs.colspan;
|
118
|
+
}
|
119
|
+
if (pmAttrs.rowspan !== 1) {
|
120
|
+
domAttrs.rowspan = pmAttrs.rowspan;
|
121
|
+
}
|
122
|
+
if (pmAttrs.colwidth) {
|
123
|
+
domAttrs["data-colwidth"] = pmAttrs.colwidth.join(",");
|
124
|
+
}
|
125
|
+
return domAttrs;
|
126
|
+
}
|
127
|
+
function defineTableSpec() {
|
128
|
+
return defineNodeSpec({
|
129
|
+
name: "table",
|
130
|
+
tableRole: "table",
|
131
|
+
content: "tableRow+",
|
132
|
+
isolating: true,
|
133
|
+
group: "block",
|
134
|
+
parseDOM: [{ tag: "table" }],
|
135
|
+
toDOM() {
|
136
|
+
return ["table", ["tbody", 0]];
|
137
|
+
}
|
138
|
+
});
|
139
|
+
}
|
140
|
+
function defineTableRowSpec() {
|
141
|
+
return defineNodeSpec({
|
142
|
+
name: "tableRow",
|
143
|
+
tableRole: "row",
|
144
|
+
content: "(tableCell | tableHeaderCell)*",
|
145
|
+
parseDOM: [{ tag: "tr" }],
|
146
|
+
toDOM() {
|
147
|
+
return ["tr", 0];
|
148
|
+
}
|
149
|
+
});
|
150
|
+
}
|
151
|
+
function defineTableCellSpec() {
|
152
|
+
return defineNodeSpec({
|
153
|
+
name: "tableCell",
|
154
|
+
tableRole: "cell",
|
155
|
+
content: cellContent,
|
156
|
+
attrs: cellAttrs,
|
157
|
+
isolating: true,
|
158
|
+
parseDOM: [{ tag: "td", getAttrs: (dom) => getCellAttrs(dom) }],
|
159
|
+
toDOM(node) {
|
160
|
+
return ["td", setCellAttrs(node), 0];
|
161
|
+
}
|
162
|
+
});
|
163
|
+
}
|
164
|
+
function defineTableHeaderCellSpec() {
|
165
|
+
return defineNodeSpec({
|
166
|
+
name: "tableHeaderCell",
|
167
|
+
tableRole: "header_cell",
|
168
|
+
content: cellContent,
|
169
|
+
attrs: cellAttrs,
|
170
|
+
isolating: true,
|
171
|
+
parseDOM: [{ tag: "th", getAttrs: (dom) => getCellAttrs(dom) }],
|
172
|
+
toDOM(node) {
|
173
|
+
return ["th", setCellAttrs(node), 0];
|
174
|
+
}
|
175
|
+
});
|
176
|
+
}
|
177
|
+
|
178
|
+
// src/table/index.ts
|
179
|
+
function defineTable() {
|
180
|
+
return union([
|
181
|
+
defineTableSpec(),
|
182
|
+
defineTableRowSpec(),
|
183
|
+
defineTableCellSpec(),
|
184
|
+
defineTableHeaderCellSpec(),
|
185
|
+
defineTablePlugins(),
|
186
|
+
defineTableCommands()
|
187
|
+
]);
|
188
|
+
}
|
189
|
+
export {
|
190
|
+
defineTable,
|
191
|
+
defineTableCellSpec,
|
192
|
+
defineTableCommands,
|
193
|
+
defineTableHeaderCellSpec,
|
194
|
+
defineTablePlugins,
|
195
|
+
defineTableRowSpec,
|
196
|
+
defineTableSpec
|
197
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { defineVirtualSelection } from './_tsup-dts-rollup';
|