@damiro/stylo 0.7.0 → 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/README.md +24 -10
- package/dist/{InPlaceView-CS1qy-Ba.js → InPlaceView-Bu91_3Ig.js} +1199 -855
- package/dist/InPlaceView-Bu91_3Ig.js.map +1 -0
- package/dist/Preview-AaGGwLQP.js +170 -0
- package/dist/Preview-AaGGwLQP.js.map +1 -0
- package/dist/SplitView.d.ts +4 -2
- package/dist/SplitView.d.ts.map +1 -1
- package/dist/Stylo.d.ts.map +1 -1
- package/dist/editor/SourceView.d.ts +4 -2
- package/dist/editor/SourceView.d.ts.map +1 -1
- package/dist/editor/extensions.d.ts +2 -2
- package/dist/editor/extensions.d.ts.map +1 -1
- package/dist/editor/useCodeMirror.d.ts +4 -2
- package/dist/editor/useCodeMirror.d.ts.map +1 -1
- package/dist/editor/wikilink-complete.d.ts +5 -3
- package/dist/editor/wikilink-complete.d.ts.map +1 -1
- package/dist/embed-B2Dfkpd_.js +124 -0
- package/dist/embed-B2Dfkpd_.js.map +1 -0
- package/dist/embed.d.ts +14 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/frontmatter-DGUkb9z-.js +39 -0
- package/dist/frontmatter-DGUkb9z-.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/inplace/InPlaceView.d.ts +11 -2
- package/dist/inplace/InPlaceView.d.ts.map +1 -1
- package/dist/inplace/config.d.ts +8 -0
- package/dist/inplace/config.d.ts.map +1 -1
- package/dist/inplace/context-menu-actions.d.ts +5 -14
- package/dist/inplace/context-menu-actions.d.ts.map +1 -1
- package/dist/inplace/context-menu-helpers.d.ts +30 -0
- package/dist/inplace/context-menu-helpers.d.ts.map +1 -0
- package/dist/inplace/context-menu-shell.d.ts +23 -0
- package/dist/inplace/context-menu-shell.d.ts.map +1 -0
- package/dist/inplace/context-menu-types.d.ts +46 -0
- package/dist/inplace/context-menu-types.d.ts.map +1 -0
- package/dist/inplace/context-menu.d.ts +2 -42
- package/dist/inplace/context-menu.d.ts.map +1 -1
- package/dist/inplace/decorate.d.ts.map +1 -1
- package/dist/inplace/edit-boundaries.d.ts +1 -25
- package/dist/inplace/edit-boundaries.d.ts.map +1 -1
- package/dist/inplace/edit-divider.d.ts +27 -0
- package/dist/inplace/edit-divider.d.ts.map +1 -0
- package/dist/inplace/embed-registry.d.ts +39 -0
- package/dist/inplace/embed-registry.d.ts.map +1 -0
- package/dist/inplace/embed.d.ts +8 -0
- package/dist/inplace/embed.d.ts.map +1 -0
- package/dist/inplace/extension.d.ts +6 -0
- package/dist/inplace/extension.d.ts.map +1 -1
- package/dist/inplace/inline-md.d.ts +6 -1
- package/dist/inplace/inline-md.d.ts.map +1 -1
- package/dist/inplace/link-row.d.ts +21 -0
- package/dist/inplace/link-row.d.ts.map +1 -0
- package/dist/inplace/math-edit.d.ts +36 -0
- package/dist/inplace/math-edit.d.ts.map +1 -0
- package/dist/inplace/math.d.ts +12 -0
- package/dist/inplace/math.d.ts.map +1 -1
- package/dist/inplace/menu-plugin.d.ts.map +1 -1
- package/dist/inplace/nodes-blocks.d.ts +14 -0
- package/dist/inplace/nodes-blocks.d.ts.map +1 -0
- package/dist/inplace/nodes-inline.d.ts +16 -0
- package/dist/inplace/nodes-inline.d.ts.map +1 -0
- package/dist/inplace/nodes.d.ts +3 -2
- package/dist/inplace/nodes.d.ts.map +1 -1
- package/dist/inplace/scan.d.ts +6 -0
- package/dist/inplace/scan.d.ts.map +1 -1
- package/dist/inplace/selection-bar-position.d.ts +31 -0
- package/dist/inplace/selection-bar-position.d.ts.map +1 -0
- package/dist/inplace/selection-bar.d.ts +0 -2
- package/dist/inplace/selection-bar.d.ts.map +1 -1
- package/dist/inplace/table-widget-caret.d.ts +11 -0
- package/dist/inplace/table-widget-caret.d.ts.map +1 -0
- package/dist/inplace/table-widget-render.d.ts +18 -0
- package/dist/inplace/table-widget-render.d.ts.map +1 -0
- package/dist/inplace/table-widget.d.ts +5 -2
- package/dist/inplace/table-widget.d.ts.map +1 -1
- package/dist/inplace/tables.d.ts.map +1 -1
- package/dist/inplace/theme-callout.d.ts +50 -0
- package/dist/inplace/theme-callout.d.ts.map +1 -0
- package/dist/inplace/theme-canvas.d.ts +166 -0
- package/dist/inplace/theme-canvas.d.ts.map +1 -0
- package/dist/inplace/theme-fonts.d.ts +4 -0
- package/dist/inplace/theme-fonts.d.ts.map +1 -0
- package/dist/inplace/theme-menu.d.ts +87 -0
- package/dist/inplace/theme-menu.d.ts.map +1 -0
- package/dist/inplace/theme-popups.d.ts +94 -0
- package/dist/inplace/theme-popups.d.ts.map +1 -0
- package/dist/inplace/theme-table-gizmos.d.ts +57 -0
- package/dist/inplace/theme-table-gizmos.d.ts.map +1 -0
- package/dist/inplace/theme-table.d.ts +30 -0
- package/dist/inplace/theme-table.d.ts.map +1 -0
- package/dist/inplace/theme.d.ts +5 -0
- package/dist/inplace/theme.d.ts.map +1 -1
- package/dist/inplace/wikilinks.d.ts.map +1 -1
- package/dist/inplace/wrap-at.d.ts +32 -0
- package/dist/inplace/wrap-at.d.ts.map +1 -0
- package/dist/{markdown-N3lRmU2n.js → markdown-BYXs9Tj8.js} +2 -2
- package/dist/{markdown-N3lRmU2n.js.map → markdown-BYXs9Tj8.js.map} +1 -1
- package/dist/render/Embed.d.ts +24 -0
- package/dist/render/Embed.d.ts.map +1 -0
- package/dist/render/Preview.d.ts +6 -2
- package/dist/render/Preview.d.ts.map +1 -1
- package/dist/render/embed-cache.d.ts +10 -0
- package/dist/render/embed-cache.d.ts.map +1 -0
- package/dist/render/remark-embed.d.ts +19 -0
- package/dist/render/remark-embed.d.ts.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/stylo.js +70 -54
- package/dist/stylo.js.map +1 -1
- package/dist/toolbar/block.d.ts +0 -26
- package/dist/toolbar/block.d.ts.map +1 -1
- package/dist/toolbar/command-helpers.d.ts +57 -0
- package/dist/toolbar/command-helpers.d.ts.map +1 -0
- package/dist/toolbar/commands.d.ts +1 -21
- package/dist/toolbar/commands.d.ts.map +1 -1
- package/dist/toolbar/frontmatter-toggle.d.ts +13 -0
- package/dist/toolbar/frontmatter-toggle.d.ts.map +1 -0
- package/dist/toolbar/heading.d.ts +10 -0
- package/dist/toolbar/heading.d.ts.map +1 -0
- package/dist/toolbar/inline-ops.d.ts +3 -53
- package/dist/toolbar/inline-ops.d.ts.map +1 -1
- package/dist/toolbar/link-ops.d.ts +22 -0
- package/dist/toolbar/link-ops.d.ts.map +1 -0
- package/dist/toolbar/rule.d.ts +11 -0
- package/dist/toolbar/rule.d.ts.map +1 -0
- package/dist/toolbar/table-position.d.ts +32 -0
- package/dist/toolbar/table-position.d.ts.map +1 -0
- package/dist/toolbar/table.d.ts +1 -16
- package/dist/toolbar/table.d.ts.map +1 -1
- package/dist/toolbar/underline-ops.d.ts +15 -0
- package/dist/toolbar/underline-ops.d.ts.map +1 -0
- package/dist/toolbar/wikilink-ops.d.ts +22 -0
- package/dist/toolbar/wikilink-ops.d.ts.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/{useCodeMirror-GPSkaYW6.js → useCodeMirror-DtwupFgc.js} +559 -531
- package/dist/useCodeMirror-DtwupFgc.js.map +1 -0
- package/package.json +2 -1
- package/dist/InPlaceView-CS1qy-Ba.js.map +0 -1
- package/dist/Preview-Bw0k3Mev.js +0 -93
- package/dist/Preview-Bw0k3Mev.js.map +0 -1
- package/dist/callout-oLE630ZP.js +0 -37
- package/dist/callout-oLE630ZP.js.map +0 -1
- package/dist/useCodeMirror-GPSkaYW6.js.map +0 -1
- package/dist/wikilink-CTR8IFKc.js +0 -42
- package/dist/wikilink-CTR8IFKc.js.map +0 -1
|
@@ -1,169 +1,135 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as e, t } from "./frontmatter-DGUkb9z-.js";
|
|
2
2
|
import { useEffect as n, useRef as r } from "react";
|
|
3
3
|
import { EditorView as i, keymap as a, placeholder as o } from "@codemirror/view";
|
|
4
4
|
import { Annotation as s, ChangeSet as c, Compartment as l, EditorSelection as u, EditorState as d, Facet as f, Prec as p } from "@codemirror/state";
|
|
5
5
|
import { defaultKeymap as ee, history as te, historyKeymap as m, redo as h, undo as g } from "@codemirror/commands";
|
|
6
6
|
import { markdown as _, markdownLanguage as v } from "@codemirror/lang-markdown";
|
|
7
|
-
import { openSearchPanel as y, search as b, searchKeymap as
|
|
8
|
-
import { HighlightStyle as
|
|
9
|
-
import { tags as
|
|
10
|
-
import { autocompletion as
|
|
11
|
-
//#region src/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return [e.doc.lineAt(t).number, e.doc.lineAt(n).number];
|
|
22
|
-
}
|
|
23
|
-
function se(e, t) {
|
|
24
|
-
let n = "#".repeat(t) + " ", r = e.state, [i, a] = w(r), o = [];
|
|
25
|
-
for (let e = i; e <= a; e++) {
|
|
26
|
-
let i = r.doc.line(e), a = /^(#{1,6}) +/.exec(i.text);
|
|
27
|
-
a && a[1].length === t ? o.push({
|
|
28
|
-
from: i.from,
|
|
29
|
-
to: i.from + a[0].length
|
|
30
|
-
}) : a ? o.push({
|
|
31
|
-
from: i.from,
|
|
32
|
-
to: i.from + a[0].length,
|
|
33
|
-
insert: n
|
|
34
|
-
}) : o.push({
|
|
35
|
-
from: i.from,
|
|
36
|
-
insert: n
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return e.dispatch({
|
|
40
|
-
changes: o,
|
|
41
|
-
scrollIntoView: !0
|
|
42
|
-
}), e.focus(), !0;
|
|
43
|
-
}
|
|
44
|
-
function ce(e) {
|
|
45
|
-
let t = e.state, [n, r] = w(t), i = [];
|
|
46
|
-
for (let e = n; e <= r; e++) {
|
|
47
|
-
let n = t.doc.line(e), r = /^#{1,6} +/.exec(n.text);
|
|
48
|
-
r && i.push({
|
|
49
|
-
from: n.from,
|
|
50
|
-
to: n.from + r[0].length
|
|
51
|
-
});
|
|
7
|
+
import { openSearchPanel as y, search as b, searchKeymap as ne } from "@codemirror/search";
|
|
8
|
+
import { HighlightStyle as x, syntaxHighlighting as S, syntaxTree as C } from "@codemirror/language";
|
|
9
|
+
import { tags as w } from "@lezer/highlight";
|
|
10
|
+
import { autocompletion as re } from "@codemirror/autocomplete";
|
|
11
|
+
//#region src/toolbar/link-ops.ts
|
|
12
|
+
function T(e, t) {
|
|
13
|
+
let n = /\[([^\]]*)\]\([^)]*\)/g;
|
|
14
|
+
for (let r; r = n.exec(e);) {
|
|
15
|
+
let e = r.index, n = e + r[0].length;
|
|
16
|
+
if (t >= e && t <= n) return {
|
|
17
|
+
from: e,
|
|
18
|
+
to: n,
|
|
19
|
+
label: r[1] ?? ""
|
|
20
|
+
};
|
|
52
21
|
}
|
|
53
|
-
return
|
|
54
|
-
changes: i,
|
|
55
|
-
scrollIntoView: !0
|
|
56
|
-
}), e.focus(), !0) : !1;
|
|
22
|
+
return null;
|
|
57
23
|
}
|
|
58
|
-
function
|
|
59
|
-
let n =
|
|
60
|
-
for (let
|
|
61
|
-
let r =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
to: r.from + i[0].length
|
|
73
|
-
});
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (i) continue;
|
|
77
|
-
let l = typeof t.insert == "function" ? t.insert(c++) : t.insert, u = t.siblings?.exec(r.text);
|
|
78
|
-
if (u) s.push({
|
|
79
|
-
from: r.from + (u[1] ?? "").length,
|
|
80
|
-
to: r.from + u[0].length,
|
|
81
|
-
insert: l
|
|
82
|
-
});
|
|
83
|
-
else {
|
|
84
|
-
let e = /^\s*/.exec(r.text)[0].length;
|
|
85
|
-
s.push({
|
|
86
|
-
from: r.from + e,
|
|
87
|
-
insert: l
|
|
88
|
-
});
|
|
24
|
+
function ie(e, t) {
|
|
25
|
+
let n = /\[([^\]]*)\]\(([^)]*)\)/g;
|
|
26
|
+
for (let r; r = n.exec(e);) {
|
|
27
|
+
let e = r.index, n = e + r[0].length;
|
|
28
|
+
if (t >= e && t <= n) {
|
|
29
|
+
let t = r[1] ?? "", i = r[2] ?? "", a = e + 1 + t.length + 2;
|
|
30
|
+
return {
|
|
31
|
+
from: e,
|
|
32
|
+
to: n,
|
|
33
|
+
label: t,
|
|
34
|
+
url: i,
|
|
35
|
+
urlFrom: a,
|
|
36
|
+
urlTo: a + i.length
|
|
37
|
+
};
|
|
89
38
|
}
|
|
90
39
|
}
|
|
91
|
-
return
|
|
92
|
-
changes: s,
|
|
93
|
-
scrollIntoView: !0
|
|
94
|
-
}), e.focus(), !0) : !1;
|
|
40
|
+
return null;
|
|
95
41
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
42
|
+
function ae(e, t, n) {
|
|
43
|
+
let r = T(e, t);
|
|
44
|
+
if (r) return {
|
|
45
|
+
text: e.slice(0, r.from) + r.label + e.slice(r.to),
|
|
46
|
+
from: r.from,
|
|
47
|
+
to: r.from + r.label.length
|
|
48
|
+
};
|
|
49
|
+
let i = e.slice(t, n) || "text", a = t + i.length + 3;
|
|
50
|
+
return {
|
|
51
|
+
text: e.slice(0, t) + `[${i}](url)` + e.slice(n),
|
|
52
|
+
from: a,
|
|
53
|
+
to: a + 3
|
|
54
|
+
};
|
|
98
55
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
to: n.to,
|
|
112
|
-
insert: "---"
|
|
113
|
-
},
|
|
114
|
-
selection: u.cursor(n.from + 3),
|
|
115
|
-
scrollIntoView: !0
|
|
116
|
-
}) : e.dispatch({
|
|
117
|
-
changes: {
|
|
118
|
-
from: n.to,
|
|
119
|
-
insert: "\n\n---\n"
|
|
120
|
-
},
|
|
121
|
-
selection: u.cursor(n.to + 6),
|
|
122
|
-
scrollIntoView: !0
|
|
123
|
-
}), e.focus(), !0;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/toolbar/wikilink-ops.ts
|
|
58
|
+
function E(t, n) {
|
|
59
|
+
for (let r of t.matchAll(e)) {
|
|
60
|
+
let e = r.index ?? 0, t = e + r[0].length;
|
|
61
|
+
if (n >= e && n <= t) return {
|
|
62
|
+
from: e,
|
|
63
|
+
to: t,
|
|
64
|
+
label: r[2] || r[1] || ""
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
124
68
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
69
|
+
function oe(t, n) {
|
|
70
|
+
for (let r of t.matchAll(e)) {
|
|
71
|
+
let e = r.index ?? 0, t = e + r[0].length;
|
|
72
|
+
if (n < e || n > t) continue;
|
|
73
|
+
let i = r[1] ?? "", a = e + 2;
|
|
74
|
+
return {
|
|
75
|
+
from: e,
|
|
76
|
+
to: t,
|
|
77
|
+
target: i,
|
|
78
|
+
label: r[2] ?? "",
|
|
79
|
+
targetFrom: a,
|
|
80
|
+
targetTo: a + i.length
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
127
84
|
}
|
|
128
|
-
function
|
|
129
|
-
let
|
|
130
|
-
if (r) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
scrollIntoView: !0
|
|
154
|
-
});
|
|
85
|
+
function se(e, t, n) {
|
|
86
|
+
let r = E(e, t);
|
|
87
|
+
if (r) return {
|
|
88
|
+
text: e.slice(0, r.from) + r.label + e.slice(r.to),
|
|
89
|
+
from: r.from,
|
|
90
|
+
to: r.from + r.label.length
|
|
91
|
+
};
|
|
92
|
+
let i = e.slice(t, n) || "target";
|
|
93
|
+
return {
|
|
94
|
+
text: e.slice(0, t) + `[[${i}]]` + e.slice(n),
|
|
95
|
+
from: t + 2,
|
|
96
|
+
to: t + 2 + i.length
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/toolbar/underline-ops.ts
|
|
101
|
+
function ce(e, t) {
|
|
102
|
+
let n = /<u>([\s\S]*?)<\/u>/gi;
|
|
103
|
+
for (let r; r = n.exec(e);) {
|
|
104
|
+
let e = r.index, n = e + r[0].length;
|
|
105
|
+
if (t >= e && t <= n) return {
|
|
106
|
+
from: e,
|
|
107
|
+
to: n,
|
|
108
|
+
inner: r[1] ?? ""
|
|
109
|
+
};
|
|
155
110
|
}
|
|
156
|
-
return
|
|
111
|
+
return null;
|
|
157
112
|
}
|
|
158
|
-
function
|
|
159
|
-
|
|
113
|
+
function le(e, t, n) {
|
|
114
|
+
let r = ce(e, t);
|
|
115
|
+
if (r) return {
|
|
116
|
+
text: e.slice(0, r.from) + r.inner + e.slice(r.to),
|
|
117
|
+
from: r.from,
|
|
118
|
+
to: r.from + r.inner.length
|
|
119
|
+
};
|
|
120
|
+
let i = e.slice(t, n) || "text";
|
|
121
|
+
return {
|
|
122
|
+
text: e.slice(0, t) + `<u>${i}</u>` + e.slice(n),
|
|
123
|
+
from: t + 3,
|
|
124
|
+
to: t + 3 + i.length
|
|
125
|
+
};
|
|
160
126
|
}
|
|
161
127
|
//#endregion
|
|
162
128
|
//#region src/toolbar/inline-ops.ts
|
|
163
|
-
function
|
|
129
|
+
function D(e) {
|
|
164
130
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
165
131
|
}
|
|
166
|
-
function
|
|
132
|
+
function ue(e, t, n) {
|
|
167
133
|
let r = t, i = t;
|
|
168
134
|
if (n < 0) for (; r > 0 && "*~`$".includes(e[r - 1]);) r--;
|
|
169
135
|
else for (; i < e.length && "*~`$".includes(e[i]);) i++;
|
|
@@ -172,7 +138,7 @@ function ge(e, t, n) {
|
|
|
172
138
|
from: r
|
|
173
139
|
};
|
|
174
140
|
}
|
|
175
|
-
function
|
|
141
|
+
function de(e, t) {
|
|
176
142
|
let n = [];
|
|
177
143
|
for (let r = 0; r < e.length;) {
|
|
178
144
|
if (e[r] !== t) {
|
|
@@ -188,15 +154,15 @@ function _e(e, t) {
|
|
|
188
154
|
}
|
|
189
155
|
return n;
|
|
190
156
|
}
|
|
191
|
-
function
|
|
157
|
+
function fe(e, t, n) {
|
|
192
158
|
return e < n || t < n ? !1 : n > 1 || e % 2 == 1 && t % 2 == 1;
|
|
193
159
|
}
|
|
194
|
-
function
|
|
160
|
+
function pe(e, t, n, r) {
|
|
195
161
|
let i = r.length, a = r[0], o = e.slice(t, n), s = 0;
|
|
196
162
|
for (; o[s] === a;) s++;
|
|
197
163
|
let c = 0;
|
|
198
164
|
for (; o[o.length - 1 - c] === a;) c++;
|
|
199
|
-
if (o.length >= 2 * i && o.startsWith(r) && o.endsWith(r) &&
|
|
165
|
+
if (o.length >= 2 * i && o.startsWith(r) && o.endsWith(r) && fe(s, c, i)) return {
|
|
200
166
|
changes: [{
|
|
201
167
|
from: t,
|
|
202
168
|
to: t + i,
|
|
@@ -209,10 +175,10 @@ function ye(e, t, n, r) {
|
|
|
209
175
|
from: t,
|
|
210
176
|
to: n - 2 * i
|
|
211
177
|
};
|
|
212
|
-
let l =
|
|
178
|
+
let l = ue(e, t, -1), u = ue(e, n, 1), d = de(l.text, a), f = de(u.text, a).reverse();
|
|
213
179
|
for (let e = 0; e < Math.min(d.length, f.length); e++) {
|
|
214
180
|
let r = d[e], a = f[e];
|
|
215
|
-
if (!
|
|
181
|
+
if (!fe(r.len, a.len, i)) continue;
|
|
216
182
|
let o = l.from + r.start + r.len, s = n + a.start;
|
|
217
183
|
return {
|
|
218
184
|
changes: [{
|
|
@@ -242,26 +208,26 @@ function ye(e, t, n, r) {
|
|
|
242
208
|
to: n + i
|
|
243
209
|
};
|
|
244
210
|
}
|
|
245
|
-
function
|
|
211
|
+
function me(e, t) {
|
|
246
212
|
let n = e;
|
|
247
213
|
for (let e of [...t].sort((e, t) => t.from - e.from)) n = n.slice(0, e.from) + e.insert + n.slice(e.to);
|
|
248
214
|
return n;
|
|
249
215
|
}
|
|
250
|
-
function
|
|
251
|
-
let i =
|
|
216
|
+
function O(e, t, n, r) {
|
|
217
|
+
let i = pe(e, t, n, r);
|
|
252
218
|
return {
|
|
253
|
-
text:
|
|
219
|
+
text: me(e, i.changes),
|
|
254
220
|
from: i.from,
|
|
255
221
|
to: i.to
|
|
256
222
|
};
|
|
257
223
|
}
|
|
258
|
-
function
|
|
259
|
-
let n =
|
|
224
|
+
function he(e, t) {
|
|
225
|
+
let n = T(e, t);
|
|
260
226
|
if (n) return {
|
|
261
227
|
from: n.from,
|
|
262
228
|
to: n.to
|
|
263
229
|
};
|
|
264
|
-
let r =
|
|
230
|
+
let r = oe(e, t);
|
|
265
231
|
if (r) return {
|
|
266
232
|
from: r.from,
|
|
267
233
|
to: r.to
|
|
@@ -273,7 +239,7 @@ function xe(e, t) {
|
|
|
273
239
|
"*",
|
|
274
240
|
"`"
|
|
275
241
|
]) {
|
|
276
|
-
let r = RegExp(
|
|
242
|
+
let r = RegExp(D(n) + "(?!\\s)(?:[^]*?\\S)??" + D(n), "g");
|
|
277
243
|
for (let a; a = r.exec(e);) {
|
|
278
244
|
if (a[0].length <= 2 * n.length) continue;
|
|
279
245
|
let e = a.index + n.length, r = a.index + a[0].length - n.length;
|
|
@@ -285,121 +251,10 @@ function xe(e, t) {
|
|
|
285
251
|
}
|
|
286
252
|
return i;
|
|
287
253
|
}
|
|
288
|
-
function D(e, t) {
|
|
289
|
-
let n = /\[([^\]]*)\]\([^)]*\)/g;
|
|
290
|
-
for (let r; r = n.exec(e);) {
|
|
291
|
-
let e = r.index, n = e + r[0].length;
|
|
292
|
-
if (t >= e && t <= n) return {
|
|
293
|
-
from: e,
|
|
294
|
-
to: n,
|
|
295
|
-
label: r[1] ?? ""
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
function Se(e, t) {
|
|
301
|
-
let n = /\[([^\]]*)\]\(([^)]*)\)/g;
|
|
302
|
-
for (let r; r = n.exec(e);) {
|
|
303
|
-
let e = r.index, n = e + r[0].length;
|
|
304
|
-
if (t >= e && t <= n) {
|
|
305
|
-
let t = r[1] ?? "", i = r[2] ?? "", a = e + 1 + t.length + 2;
|
|
306
|
-
return {
|
|
307
|
-
from: e,
|
|
308
|
-
to: n,
|
|
309
|
-
label: t,
|
|
310
|
-
url: i,
|
|
311
|
-
urlFrom: a,
|
|
312
|
-
urlTo: a + i.length
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return null;
|
|
317
|
-
}
|
|
318
|
-
function Ce(e, t, n) {
|
|
319
|
-
let r = D(e, t);
|
|
320
|
-
if (r) return {
|
|
321
|
-
text: e.slice(0, r.from) + r.label + e.slice(r.to),
|
|
322
|
-
from: r.from,
|
|
323
|
-
to: r.from + r.label.length
|
|
324
|
-
};
|
|
325
|
-
let i = e.slice(t, n) || "text", a = t + i.length + 3;
|
|
326
|
-
return {
|
|
327
|
-
text: e.slice(0, t) + `[${i}](url)` + e.slice(n),
|
|
328
|
-
from: a,
|
|
329
|
-
to: a + 3
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function we(e, t) {
|
|
333
|
-
let n = /<u>([\s\S]*?)<\/u>/gi;
|
|
334
|
-
for (let r; r = n.exec(e);) {
|
|
335
|
-
let e = r.index, n = e + r[0].length;
|
|
336
|
-
if (t >= e && t <= n) return {
|
|
337
|
-
from: e,
|
|
338
|
-
to: n,
|
|
339
|
-
inner: r[1] ?? ""
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
function O(e, t, n) {
|
|
345
|
-
let r = we(e, t);
|
|
346
|
-
if (r) return {
|
|
347
|
-
text: e.slice(0, r.from) + r.inner + e.slice(r.to),
|
|
348
|
-
from: r.from,
|
|
349
|
-
to: r.from + r.inner.length
|
|
350
|
-
};
|
|
351
|
-
let i = e.slice(t, n) || "text";
|
|
352
|
-
return {
|
|
353
|
-
text: e.slice(0, t) + `<u>${i}</u>` + e.slice(n),
|
|
354
|
-
from: t + 3,
|
|
355
|
-
to: t + 3 + i.length
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
function k(e, n) {
|
|
359
|
-
for (let r of e.matchAll(t)) {
|
|
360
|
-
let e = r.index ?? 0, t = e + r[0].length;
|
|
361
|
-
if (n >= e && n <= t) return {
|
|
362
|
-
from: e,
|
|
363
|
-
to: t,
|
|
364
|
-
label: r[2] || r[1] || ""
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
function A(e, n) {
|
|
370
|
-
for (let r of e.matchAll(t)) {
|
|
371
|
-
let e = r.index ?? 0, t = e + r[0].length;
|
|
372
|
-
if (n < e || n > t) continue;
|
|
373
|
-
let i = r[1] ?? "", a = e + 2;
|
|
374
|
-
return {
|
|
375
|
-
from: e,
|
|
376
|
-
to: t,
|
|
377
|
-
target: i,
|
|
378
|
-
label: r[2] ?? "",
|
|
379
|
-
targetFrom: a,
|
|
380
|
-
targetTo: a + i.length
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
return null;
|
|
384
|
-
}
|
|
385
|
-
function Te(e, t, n) {
|
|
386
|
-
let r = k(e, t);
|
|
387
|
-
if (r) return {
|
|
388
|
-
text: e.slice(0, r.from) + r.label + e.slice(r.to),
|
|
389
|
-
from: r.from,
|
|
390
|
-
to: r.from + r.label.length
|
|
391
|
-
};
|
|
392
|
-
let i = e.slice(t, n) || "target";
|
|
393
|
-
return {
|
|
394
|
-
text: e.slice(0, t) + `[[${i}]]` + e.slice(n),
|
|
395
|
-
from: t + 2,
|
|
396
|
-
to: t + 2 + i.length
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
254
|
//#endregion
|
|
400
255
|
//#region src/inplace/table-cell-dom.ts
|
|
401
|
-
var
|
|
402
|
-
function
|
|
256
|
+
var ge = (e) => [e.head, ...e.body].map((e) => [...e]), _e = (e) => e.map((e) => e.map((e) => e.trim())), ve = (e) => e.replace(/\\\|/g, "|");
|
|
257
|
+
function k(e, t) {
|
|
403
258
|
let n = e.ownerDocument.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = 0;
|
|
404
259
|
for (let e = n.nextNode(); e; e = n.nextNode()) {
|
|
405
260
|
if (e === t) return r;
|
|
@@ -407,12 +262,12 @@ function j(e, t) {
|
|
|
407
262
|
}
|
|
408
263
|
return r;
|
|
409
264
|
}
|
|
410
|
-
function
|
|
265
|
+
function ye(e) {
|
|
411
266
|
let t = e.ownerDocument.getSelection(), n = t?.anchorNode;
|
|
412
|
-
return !n || !e.contains(n) ? 0 : n.nodeType === Node.TEXT_NODE ?
|
|
267
|
+
return !n || !e.contains(n) ? 0 : n.nodeType === Node.TEXT_NODE ? k(e, n) + (t?.anchorOffset ?? 0) : (t?.anchorOffset ?? 0) > 0 ? (e.textContent ?? "").length : 0;
|
|
413
268
|
}
|
|
414
|
-
function
|
|
415
|
-
let t = e.ownerDocument.getSelection(), n = (e.textContent ?? "").length, r = (t, r) => !t || !e.contains(t) ? n : t.nodeType === Node.TEXT_NODE ?
|
|
269
|
+
function be(e) {
|
|
270
|
+
let t = e.ownerDocument.getSelection(), n = (e.textContent ?? "").length, r = (t, r) => !t || !e.contains(t) ? n : t.nodeType === Node.TEXT_NODE ? k(e, t) + r : r > 0 ? n : 0;
|
|
416
271
|
if (!t || t.rangeCount === 0) return {
|
|
417
272
|
from: n,
|
|
418
273
|
to: n
|
|
@@ -423,7 +278,7 @@ function Ae(e) {
|
|
|
423
278
|
to: Math.max(i, a)
|
|
424
279
|
};
|
|
425
280
|
}
|
|
426
|
-
function
|
|
281
|
+
function xe(e, t, n) {
|
|
427
282
|
let r = e.ownerDocument, i = null, a = 0;
|
|
428
283
|
if (r.caretPositionFromPoint) {
|
|
429
284
|
let e = r.caretPositionFromPoint(t, n);
|
|
@@ -432,18 +287,18 @@ function je(e, t, n) {
|
|
|
432
287
|
let e = r.caretRangeFromPoint(t, n);
|
|
433
288
|
e && ([i, a] = [e.startContainer, e.startOffset]);
|
|
434
289
|
}
|
|
435
|
-
return !i || !e.contains(i) ? 0 :
|
|
290
|
+
return !i || !e.contains(i) ? 0 : k(e, i) + (i.nodeType === Node.TEXT_NODE ? a : 0);
|
|
436
291
|
}
|
|
437
|
-
var
|
|
438
|
-
function
|
|
439
|
-
let r = e.textContent ?? "", i =
|
|
440
|
-
if (a) return
|
|
292
|
+
var Se = /[\p{L}\p{N}_]/u;
|
|
293
|
+
function Ce(e, t, n) {
|
|
294
|
+
let r = e.textContent ?? "", i = xe(e, t, n), a = he(r, i);
|
|
295
|
+
if (a) return A(e, a.from, a.to), !0;
|
|
441
296
|
let o = i, s = i;
|
|
442
|
-
for (; o > 0 &&
|
|
443
|
-
for (; s < r.length &&
|
|
444
|
-
return s <= o ? !1 : (
|
|
297
|
+
for (; o > 0 && Se.test(r[o - 1]);) o--;
|
|
298
|
+
for (; s < r.length && Se.test(r[s]);) s++;
|
|
299
|
+
return s <= o ? !1 : (A(e, o, s), !0);
|
|
445
300
|
}
|
|
446
|
-
function
|
|
301
|
+
function A(e, t, n = t) {
|
|
447
302
|
e.focus();
|
|
448
303
|
let r = e.ownerDocument, i = r.createRange(), a = e.firstChild;
|
|
449
304
|
if (a && a.nodeType === Node.TEXT_NODE) {
|
|
@@ -456,34 +311,81 @@ function M(e, t, n = t) {
|
|
|
456
311
|
}
|
|
457
312
|
//#endregion
|
|
458
313
|
//#region src/toolbar/cell-inline.ts
|
|
459
|
-
function
|
|
314
|
+
function we(e) {
|
|
460
315
|
let t = e.dom.ownerDocument.activeElement;
|
|
461
316
|
return !(t instanceof HTMLElement) || !e.dom.contains(t) ? null : t.matches(".cm-inplace-tcell") ? t : null;
|
|
462
317
|
}
|
|
463
|
-
function
|
|
464
|
-
let { from: n, to: r } =
|
|
465
|
-
e.textContent = i.text,
|
|
466
|
-
}
|
|
467
|
-
function
|
|
468
|
-
let n =
|
|
469
|
-
return n ? (
|
|
470
|
-
}
|
|
471
|
-
var
|
|
472
|
-
b: (e, t, n) =>
|
|
473
|
-
i: (e, t, n) =>
|
|
474
|
-
u:
|
|
475
|
-
k:
|
|
476
|
-
K:
|
|
318
|
+
function Te(e, t) {
|
|
319
|
+
let { from: n, to: r } = be(e), i = t(e.textContent ?? "", n, r);
|
|
320
|
+
e.textContent = i.text, A(e, i.from, i.to), e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
321
|
+
}
|
|
322
|
+
function j(e, t) {
|
|
323
|
+
let n = we(e);
|
|
324
|
+
return n ? (Te(n, t), !0) : !1;
|
|
325
|
+
}
|
|
326
|
+
var Ee = {
|
|
327
|
+
b: (e, t, n) => O(e, t, n, "**"),
|
|
328
|
+
i: (e, t, n) => O(e, t, n, "*"),
|
|
329
|
+
u: le,
|
|
330
|
+
k: ae,
|
|
331
|
+
K: se
|
|
477
332
|
};
|
|
478
|
-
function
|
|
333
|
+
function De(e, t) {
|
|
479
334
|
if (!(e.metaKey || e.ctrlKey) || e.altKey) return !1;
|
|
480
|
-
let n =
|
|
481
|
-
return n ? (e.preventDefault(),
|
|
335
|
+
let n = Ee[e.shiftKey ? e.key.toUpperCase() : e.key.toLowerCase()];
|
|
336
|
+
return n ? (e.preventDefault(), Te(t, n), !0) : !1;
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/toolbar/block.ts
|
|
340
|
+
function M(e) {
|
|
341
|
+
let { from: t, to: n } = e.selection.main;
|
|
342
|
+
return [e.doc.lineAt(t).number, e.doc.lineAt(n).number];
|
|
343
|
+
}
|
|
344
|
+
function Oe(e, t) {
|
|
345
|
+
let n = e.state, [r, i] = M(n), a = r === i && !n.doc.line(r).text.trim(), o = !a;
|
|
346
|
+
for (let e = r; e <= i && o; e++) {
|
|
347
|
+
let r = n.doc.line(e).text;
|
|
348
|
+
r.trim() && !t.match.test(r) && (o = !1);
|
|
349
|
+
}
|
|
350
|
+
let s = [], c = 0;
|
|
351
|
+
for (let e = r; e <= i; e++) {
|
|
352
|
+
let r = n.doc.line(e);
|
|
353
|
+
if (!r.text.trim() && !a) continue;
|
|
354
|
+
let i = t.match.exec(r.text);
|
|
355
|
+
if (o) {
|
|
356
|
+
i && s.push({
|
|
357
|
+
from: r.from,
|
|
358
|
+
to: r.from + i[0].length
|
|
359
|
+
});
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (i) continue;
|
|
363
|
+
let l = typeof t.insert == "function" ? t.insert(c++) : t.insert, u = t.siblings?.exec(r.text);
|
|
364
|
+
if (u) s.push({
|
|
365
|
+
from: r.from + (u[1] ?? "").length,
|
|
366
|
+
to: r.from + u[0].length,
|
|
367
|
+
insert: l
|
|
368
|
+
});
|
|
369
|
+
else {
|
|
370
|
+
let e = /^\s*/.exec(r.text)[0].length;
|
|
371
|
+
s.push({
|
|
372
|
+
from: r.from + e,
|
|
373
|
+
insert: l
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return s.length ? (e.dispatch({
|
|
378
|
+
changes: s,
|
|
379
|
+
scrollIntoView: !0
|
|
380
|
+
}), e.focus(), !0) : !1;
|
|
381
|
+
}
|
|
382
|
+
function ke(e, t) {
|
|
383
|
+
return t.test(e.doc.lineAt(e.selection.main.head).text);
|
|
482
384
|
}
|
|
483
385
|
//#endregion
|
|
484
386
|
//#region src/toolbar/fence.ts
|
|
485
|
-
function
|
|
486
|
-
for (let n =
|
|
387
|
+
function N(e, t) {
|
|
388
|
+
for (let n = C(e).resolveInner(t, 0); n; n = n.parent) {
|
|
487
389
|
if (n.name === "FencedCode") return {
|
|
488
390
|
from: n.from,
|
|
489
391
|
to: n.to
|
|
@@ -492,8 +394,8 @@ function F(e, t) {
|
|
|
492
394
|
}
|
|
493
395
|
return null;
|
|
494
396
|
}
|
|
495
|
-
function
|
|
496
|
-
let t = e.state, n =
|
|
397
|
+
function Ae(e) {
|
|
398
|
+
let t = e.state, n = N(t, t.selection.main.head);
|
|
497
399
|
if (n) {
|
|
498
400
|
let r = t.doc.lineAt(n.from), i = t.doc.lineAt(n.to), a = [{
|
|
499
401
|
from: r.from,
|
|
@@ -507,7 +409,7 @@ function Le(e) {
|
|
|
507
409
|
scrollIntoView: !0
|
|
508
410
|
});
|
|
509
411
|
} else {
|
|
510
|
-
let [n, r] =
|
|
412
|
+
let [n, r] = M(t);
|
|
511
413
|
e.dispatch({
|
|
512
414
|
changes: [{
|
|
513
415
|
from: t.doc.line(n).from,
|
|
@@ -522,11 +424,11 @@ function Le(e) {
|
|
|
522
424
|
}
|
|
523
425
|
return e.focus(), !0;
|
|
524
426
|
}
|
|
525
|
-
function
|
|
526
|
-
return
|
|
427
|
+
function P(e) {
|
|
428
|
+
return N(e, e.selection.main.head) !== null;
|
|
527
429
|
}
|
|
528
|
-
function
|
|
529
|
-
let t =
|
|
430
|
+
function je(e) {
|
|
431
|
+
let t = N(e, e.selection.main.head);
|
|
530
432
|
if (!t) return null;
|
|
531
433
|
let n = e.doc.lineAt(t.from), r = /^(\s*(?:`{3,}|~{3,})[ \t]*)(.*?)[ \t]*$/.exec(n.text);
|
|
532
434
|
if (!r) return null;
|
|
@@ -537,18 +439,18 @@ function Re(e) {
|
|
|
537
439
|
lang: r[2]
|
|
538
440
|
};
|
|
539
441
|
}
|
|
540
|
-
var
|
|
541
|
-
function
|
|
442
|
+
var Me = /^\s*\$\$\s*$/;
|
|
443
|
+
function Ne(e, t) {
|
|
542
444
|
let n = 0, r = 0;
|
|
543
|
-
for (let i = 1; i <= e.doc.lines; i++) if (
|
|
445
|
+
for (let i = 1; i <= e.doc.lines; i++) if (Me.test(e.doc.line(i).text)) {
|
|
544
446
|
if (r++, r % 2 == 1) {
|
|
545
447
|
if (n = i, i > t) return null;
|
|
546
448
|
} else if (i >= t) return [n, i];
|
|
547
449
|
}
|
|
548
450
|
return null;
|
|
549
451
|
}
|
|
550
|
-
function
|
|
551
|
-
let t = e.state, [n, r] =
|
|
452
|
+
function Pe(e) {
|
|
453
|
+
let t = e.state, [n, r] = M(t), i = Ne(t, t.doc.lineAt(t.selection.main.head).number);
|
|
552
454
|
if (i) {
|
|
553
455
|
let n = t.doc.line(i[0]), r = t.doc.line(i[1]);
|
|
554
456
|
e.dispatch({
|
|
@@ -574,16 +476,53 @@ function Ve(e) {
|
|
|
574
476
|
});
|
|
575
477
|
return e.focus(), !0;
|
|
576
478
|
}
|
|
577
|
-
function
|
|
578
|
-
return
|
|
479
|
+
function F(e) {
|
|
480
|
+
return Ne(e, e.doc.lineAt(e.selection.main.head).number) !== null;
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/toolbar/heading.ts
|
|
484
|
+
function Fe(e, t) {
|
|
485
|
+
let n = "#".repeat(t) + " ", r = e.state, [i, a] = M(r), o = [];
|
|
486
|
+
for (let e = i; e <= a; e++) {
|
|
487
|
+
let i = r.doc.line(e), a = /^(#{1,6}) +/.exec(i.text);
|
|
488
|
+
a && a[1].length === t ? o.push({
|
|
489
|
+
from: i.from,
|
|
490
|
+
to: i.from + a[0].length
|
|
491
|
+
}) : a ? o.push({
|
|
492
|
+
from: i.from,
|
|
493
|
+
to: i.from + a[0].length,
|
|
494
|
+
insert: n
|
|
495
|
+
}) : o.push({
|
|
496
|
+
from: i.from,
|
|
497
|
+
insert: n
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
return e.dispatch({
|
|
501
|
+
changes: o,
|
|
502
|
+
scrollIntoView: !0
|
|
503
|
+
}), e.focus(), !0;
|
|
504
|
+
}
|
|
505
|
+
function Ie(e) {
|
|
506
|
+
let t = e.state, [n, r] = M(t), i = [];
|
|
507
|
+
for (let e = n; e <= r; e++) {
|
|
508
|
+
let n = t.doc.line(e), r = /^#{1,6} +/.exec(n.text);
|
|
509
|
+
r && i.push({
|
|
510
|
+
from: n.from,
|
|
511
|
+
to: n.from + r[0].length
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return i.length ? (e.dispatch({
|
|
515
|
+
changes: i,
|
|
516
|
+
scrollIntoView: !0
|
|
517
|
+
}), e.focus(), !0) : !1;
|
|
579
518
|
}
|
|
580
519
|
//#endregion
|
|
581
520
|
//#region src/toolbar/inline.ts
|
|
582
|
-
function
|
|
521
|
+
function I(e, t) {
|
|
583
522
|
let n = e.state.doc.toString();
|
|
584
523
|
return e.dispatch({
|
|
585
524
|
...e.state.changeByRange((e) => {
|
|
586
|
-
let r =
|
|
525
|
+
let r = pe(n, e.from, e.to, t);
|
|
587
526
|
return {
|
|
588
527
|
changes: r.changes,
|
|
589
528
|
range: r.from === r.to ? u.cursor(r.from) : u.range(r.from, r.to)
|
|
@@ -592,8 +531,8 @@ function R(e, t) {
|
|
|
592
531
|
scrollIntoView: !0
|
|
593
532
|
}), e.focus(), !0;
|
|
594
533
|
}
|
|
595
|
-
function
|
|
596
|
-
let n = e.selection.main, r = e.doc.lineAt(n.head), i = RegExp(
|
|
534
|
+
function L(e, t) {
|
|
535
|
+
let n = e.selection.main, r = e.doc.lineAt(n.head), i = RegExp(D(t) + "(?!\\s)(?:[^]*?\\S)??" + D(t), "g");
|
|
597
536
|
for (let e; e = i.exec(r.text);) {
|
|
598
537
|
if (e[0].length <= 2 * t.length || t === "$" && (r.text[e.index - 1] === "$" || r.text[e.index + e[0].length] === "$")) continue;
|
|
599
538
|
let i = r.from + e.index;
|
|
@@ -601,16 +540,16 @@ function z(e, t) {
|
|
|
601
540
|
}
|
|
602
541
|
return !1;
|
|
603
542
|
}
|
|
604
|
-
function
|
|
605
|
-
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r =
|
|
543
|
+
function Le(e) {
|
|
544
|
+
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = T(n.text, t - n.from);
|
|
606
545
|
return r ? {
|
|
607
546
|
from: n.from + r.from,
|
|
608
547
|
to: n.from + r.to,
|
|
609
548
|
text: r.label
|
|
610
549
|
} : null;
|
|
611
550
|
}
|
|
612
|
-
function
|
|
613
|
-
let t =
|
|
551
|
+
function Re(e) {
|
|
552
|
+
let t = Le(e.state);
|
|
614
553
|
if (t) return e.dispatch({
|
|
615
554
|
changes: {
|
|
616
555
|
from: t.from,
|
|
@@ -631,19 +570,19 @@ function Ue(e) {
|
|
|
631
570
|
scrollIntoView: !0
|
|
632
571
|
}), e.focus(), !0;
|
|
633
572
|
}
|
|
634
|
-
function
|
|
635
|
-
return
|
|
573
|
+
function ze(e) {
|
|
574
|
+
return Le(e) !== null;
|
|
636
575
|
}
|
|
637
|
-
function
|
|
638
|
-
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r =
|
|
576
|
+
function Be(e) {
|
|
577
|
+
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = E(n.text, t - n.from);
|
|
639
578
|
return r ? {
|
|
640
579
|
from: n.from + r.from,
|
|
641
580
|
to: n.from + r.to,
|
|
642
581
|
text: r.label
|
|
643
582
|
} : null;
|
|
644
583
|
}
|
|
645
|
-
function
|
|
646
|
-
let t =
|
|
584
|
+
function Ve(e) {
|
|
585
|
+
let t = Be(e.state);
|
|
647
586
|
if (t) return e.dispatch({
|
|
648
587
|
changes: {
|
|
649
588
|
from: t.from,
|
|
@@ -664,19 +603,19 @@ function Ke(e) {
|
|
|
664
603
|
scrollIntoView: !0
|
|
665
604
|
}), e.focus(), !0;
|
|
666
605
|
}
|
|
667
|
-
function
|
|
668
|
-
return
|
|
606
|
+
function He(e) {
|
|
607
|
+
return Be(e) !== null;
|
|
669
608
|
}
|
|
670
|
-
function
|
|
671
|
-
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r =
|
|
609
|
+
function Ue(e) {
|
|
610
|
+
let { head: t } = e.selection.main, n = e.doc.lineAt(t), r = ce(n.text, t - n.from);
|
|
672
611
|
return r ? {
|
|
673
612
|
from: n.from + r.from,
|
|
674
613
|
to: n.from + r.to,
|
|
675
614
|
inner: r.inner
|
|
676
615
|
} : null;
|
|
677
616
|
}
|
|
678
|
-
function
|
|
679
|
-
let t =
|
|
617
|
+
function We(e) {
|
|
618
|
+
let t = Ue(e.state);
|
|
680
619
|
if (t) return e.dispatch({
|
|
681
620
|
changes: {
|
|
682
621
|
from: t.from,
|
|
@@ -697,29 +636,29 @@ function Ye(e) {
|
|
|
697
636
|
scrollIntoView: !0
|
|
698
637
|
}), e.focus(), !0;
|
|
699
638
|
}
|
|
700
|
-
function
|
|
701
|
-
return
|
|
639
|
+
function Ge(e) {
|
|
640
|
+
return Ue(e) !== null;
|
|
702
641
|
}
|
|
703
642
|
//#endregion
|
|
704
643
|
//#region src/toolbar/table-grid.ts
|
|
705
|
-
function
|
|
644
|
+
function Ke(e) {
|
|
706
645
|
let t = e.trim();
|
|
707
646
|
return t.includes("-") && t.includes("|") && /^[\s|:-]+$/.test(t);
|
|
708
647
|
}
|
|
709
|
-
function
|
|
648
|
+
function qe(e) {
|
|
710
649
|
let t = e.trim();
|
|
711
650
|
t.startsWith("|") && (t = t.slice(1)), t.endsWith("|") && !t.endsWith("\\|") && (t = t.slice(0, -1));
|
|
712
651
|
let n = [], r = "";
|
|
713
652
|
for (let e = 0; e < t.length; e++) t[e] === "\\" && t[e + 1] === "|" ? (r += "\\|", e++) : t[e] === "|" ? (n.push(r.trim()), r = "") : r += t[e];
|
|
714
653
|
return n.push(r.trim()), n;
|
|
715
654
|
}
|
|
716
|
-
function
|
|
655
|
+
function Je(e) {
|
|
717
656
|
let t = e.trim(), n = t.startsWith(":"), r = t.endsWith(":");
|
|
718
657
|
return n && r ? "center" : r ? "right" : n ? "left" : "";
|
|
719
658
|
}
|
|
720
|
-
function
|
|
721
|
-
if (e.length < 2 || !
|
|
722
|
-
let t =
|
|
659
|
+
function R(e) {
|
|
660
|
+
if (e.length < 2 || !Ke(e[1])) return null;
|
|
661
|
+
let t = qe(e[1]).map(Je), n = e.filter((e, t) => t !== 1).map(qe), r = Math.max(t.length, ...n.map((e) => e.length)), i = n.map((e) => {
|
|
723
662
|
let t = e.slice(0, r);
|
|
724
663
|
for (; t.length < r;) t.push("");
|
|
725
664
|
return t;
|
|
@@ -730,11 +669,11 @@ function B(e) {
|
|
|
730
669
|
aligns: a
|
|
731
670
|
};
|
|
732
671
|
}
|
|
733
|
-
function
|
|
672
|
+
function Ye(e) {
|
|
734
673
|
return e.replace(/\\\|/g, "|").length;
|
|
735
674
|
}
|
|
736
|
-
function
|
|
737
|
-
let r = t -
|
|
675
|
+
function Xe(e, t, n) {
|
|
676
|
+
let r = t - Ye(e);
|
|
738
677
|
if (r <= 0) return e;
|
|
739
678
|
if (n === "right") return " ".repeat(r) + e;
|
|
740
679
|
if (n === "center") {
|
|
@@ -743,23 +682,23 @@ function tt(e, t, n) {
|
|
|
743
682
|
}
|
|
744
683
|
return e + " ".repeat(r);
|
|
745
684
|
}
|
|
746
|
-
function
|
|
685
|
+
function Ze(e, t) {
|
|
747
686
|
let n = Math.max(3, e);
|
|
748
687
|
return t === "left" ? ":" + "-".repeat(n - 1) : t === "right" ? "-".repeat(n - 1) + ":" : t === "center" ? ":" + "-".repeat(n - 2) + ":" : "-".repeat(n);
|
|
749
688
|
}
|
|
750
|
-
function
|
|
689
|
+
function z(e) {
|
|
751
690
|
let t = e.aligns.length, n = [];
|
|
752
691
|
for (let r = 0; r < t; r++) {
|
|
753
692
|
let t = 3;
|
|
754
|
-
for (let n of e.rows) t = Math.max(t,
|
|
693
|
+
for (let n of e.rows) t = Math.max(t, Ye(n[r] ?? ""));
|
|
755
694
|
n.push(t);
|
|
756
695
|
}
|
|
757
|
-
let r = (t) => "| " + t.map((t, r) =>
|
|
758
|
-
i.push("| " + e.aligns.map((e, t) =>
|
|
696
|
+
let r = (t) => "| " + t.map((t, r) => Xe(t ?? "", n[r], e.aligns[r])).join(" | ") + " |", i = [r(e.rows[0] ?? [])];
|
|
697
|
+
i.push("| " + e.aligns.map((e, t) => Ze(n[t], e)).join(" | ") + " |");
|
|
759
698
|
for (let t = 1; t < e.rows.length; t++) i.push(r(e.rows[t]));
|
|
760
699
|
return i.join("\n");
|
|
761
700
|
}
|
|
762
|
-
function
|
|
701
|
+
function Qe(e) {
|
|
763
702
|
let t = [];
|
|
764
703
|
for (let n = 0; n < e.length; n++) {
|
|
765
704
|
if (e[n] === "\\") {
|
|
@@ -781,8 +720,8 @@ function rt(e) {
|
|
|
781
720
|
return n;
|
|
782
721
|
}
|
|
783
722
|
//#endregion
|
|
784
|
-
//#region src/toolbar/table.ts
|
|
785
|
-
function
|
|
723
|
+
//#region src/toolbar/table-position.ts
|
|
724
|
+
function B(e, t) {
|
|
786
725
|
let n = e.lineAt(t);
|
|
787
726
|
if (!n.text.includes("|")) return null;
|
|
788
727
|
let r = n.number;
|
|
@@ -800,13 +739,13 @@ function H(e, t) {
|
|
|
800
739
|
if (i - r < 1) return null;
|
|
801
740
|
let a = [];
|
|
802
741
|
for (let t = r; t <= i; t++) a.push(e.line(t).text);
|
|
803
|
-
return
|
|
742
|
+
return R(a) ? {
|
|
804
743
|
from: e.line(r).from,
|
|
805
744
|
to: e.line(i).to,
|
|
806
745
|
lines: a
|
|
807
746
|
} : null;
|
|
808
747
|
}
|
|
809
|
-
function
|
|
748
|
+
function $e(e, t, n) {
|
|
810
749
|
let r = t;
|
|
811
750
|
for (let t = 0; t < e.length; t++) {
|
|
812
751
|
let i = e[t];
|
|
@@ -822,7 +761,7 @@ function it(e, t, n) {
|
|
|
822
761
|
onDelimiter: !0
|
|
823
762
|
};
|
|
824
763
|
}
|
|
825
|
-
let a =
|
|
764
|
+
let a = Qe(i), o = 0;
|
|
826
765
|
for (let t = 0; t < a.length && (o = t, !(e <= a[t].end)); t++);
|
|
827
766
|
let s = a[o], c = s ? Math.max(0, Math.min(e, s.contentEnd) - s.contentStart) : 0;
|
|
828
767
|
return {
|
|
@@ -836,22 +775,24 @@ function it(e, t, n) {
|
|
|
836
775
|
}
|
|
837
776
|
return null;
|
|
838
777
|
}
|
|
839
|
-
function
|
|
778
|
+
function V(e, t, n) {
|
|
840
779
|
let r = e.split("\n"), i = n.onDelimiter ? 1 : n.row === 0 ? 0 : n.row + 1, a = t;
|
|
841
780
|
for (let e = 0; e < i; e++) a += r[e].length + 1;
|
|
842
|
-
let o =
|
|
781
|
+
let o = Qe(r[i]), s = o[Math.min(n.col, o.length - 1)];
|
|
843
782
|
return s ? a + s.contentStart + Math.min(n.offset, s.contentEnd - s.contentStart) : a;
|
|
844
783
|
}
|
|
845
|
-
function
|
|
846
|
-
let i =
|
|
847
|
-
return i ?
|
|
784
|
+
function et(e, t, n, r) {
|
|
785
|
+
let i = B(e, t);
|
|
786
|
+
return i ? V(i.lines.join("\n"), i.from, {
|
|
848
787
|
row: n,
|
|
849
788
|
col: r,
|
|
850
789
|
offset: 0,
|
|
851
790
|
onDelimiter: !1
|
|
852
791
|
}) : null;
|
|
853
792
|
}
|
|
854
|
-
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/toolbar/table.ts
|
|
795
|
+
function tt(e, t) {
|
|
855
796
|
requestAnimationFrame(() => {
|
|
856
797
|
let n = e.dom.querySelectorAll(".cm-inplace-table-edit");
|
|
857
798
|
if (n.length === 0) return;
|
|
@@ -871,7 +812,7 @@ function ot(e, t) {
|
|
|
871
812
|
s?.removeAllRanges(), s?.addRange(o), a.focus();
|
|
872
813
|
});
|
|
873
814
|
}
|
|
874
|
-
function
|
|
815
|
+
function nt(e) {
|
|
875
816
|
let { from: t, to: n } = e.state.selection.main, r = e.state.doc.lineAt(t), i = r.text.slice(0, t - r.from).trim() ? "\n\n" : "", a = t + i.length + 2;
|
|
876
817
|
return e.dispatch({
|
|
877
818
|
changes: {
|
|
@@ -881,30 +822,30 @@ function st(e) {
|
|
|
881
822
|
},
|
|
882
823
|
selection: u.range(a, a + 8),
|
|
883
824
|
scrollIntoView: !0
|
|
884
|
-
}), e.focus(),
|
|
825
|
+
}), e.focus(), tt(e, a), !0;
|
|
885
826
|
}
|
|
886
|
-
function
|
|
887
|
-
return
|
|
827
|
+
function H(e) {
|
|
828
|
+
return B(e.doc, e.selection.main.head) !== null;
|
|
888
829
|
}
|
|
889
|
-
function
|
|
890
|
-
let n =
|
|
830
|
+
function U(e, t) {
|
|
831
|
+
let n = B(e.state.doc, e.state.selection.main.head);
|
|
891
832
|
if (!n) return !1;
|
|
892
|
-
let r =
|
|
833
|
+
let r = R(n.lines), i = $e(n.lines, n.from, e.state.selection.main.head);
|
|
893
834
|
if (!r || !i) return !1;
|
|
894
835
|
let a = t(r, i);
|
|
895
836
|
if (!a) return !1;
|
|
896
|
-
let o =
|
|
837
|
+
let o = z(r);
|
|
897
838
|
return e.dispatch({
|
|
898
839
|
changes: {
|
|
899
840
|
from: n.from,
|
|
900
841
|
to: n.to,
|
|
901
842
|
insert: o
|
|
902
843
|
},
|
|
903
|
-
selection: u.cursor(
|
|
844
|
+
selection: u.cursor(V(o, n.from, a)),
|
|
904
845
|
scrollIntoView: !0
|
|
905
846
|
}), e.focus(), !0;
|
|
906
847
|
}
|
|
907
|
-
function
|
|
848
|
+
function rt(e, t, n) {
|
|
908
849
|
let r = e.aligns.length, { row: i, col: a } = t;
|
|
909
850
|
return a += n, a >= r ? (i++, a = 0) : a < 0 && (i--, a = r - 1), i < 0 ? null : (i >= e.rows.length && e.rows.push(Array(r).fill("")), {
|
|
910
851
|
row: i,
|
|
@@ -913,7 +854,7 @@ function ct(e, t, n) {
|
|
|
913
854
|
onDelimiter: !1
|
|
914
855
|
});
|
|
915
856
|
}
|
|
916
|
-
function
|
|
857
|
+
function it(e, t) {
|
|
917
858
|
let n = t.row + 1;
|
|
918
859
|
return n >= e.rows.length && e.rows.push(Array(e.aligns.length).fill("")), {
|
|
919
860
|
row: n,
|
|
@@ -922,58 +863,58 @@ function lt(e, t) {
|
|
|
922
863
|
onDelimiter: !1
|
|
923
864
|
};
|
|
924
865
|
}
|
|
925
|
-
var
|
|
866
|
+
var at = a.of([
|
|
926
867
|
{
|
|
927
868
|
key: "Tab",
|
|
928
|
-
run: (e) =>
|
|
869
|
+
run: (e) => U(e, (e, t) => rt(e, t, 1))
|
|
929
870
|
},
|
|
930
871
|
{
|
|
931
872
|
key: "Shift-Tab",
|
|
932
|
-
run: (e) =>
|
|
873
|
+
run: (e) => U(e, (e, t) => rt(e, t, -1))
|
|
933
874
|
},
|
|
934
875
|
{
|
|
935
876
|
key: "Enter",
|
|
936
|
-
run: (e) =>
|
|
877
|
+
run: (e) => U(e, it)
|
|
937
878
|
}
|
|
938
|
-
]),
|
|
879
|
+
]), ot = d.transactionFilter.of((e) => {
|
|
939
880
|
if (!e.docChanged || !e.isUserEvent("input") && !e.isUserEvent("delete")) return e;
|
|
940
|
-
let t = e.newSelection.main.head, n =
|
|
881
|
+
let t = e.newSelection.main.head, n = B(e.newDoc, t);
|
|
941
882
|
if (!n) return e;
|
|
942
|
-
let r =
|
|
883
|
+
let r = R(n.lines);
|
|
943
884
|
if (!r) return e;
|
|
944
|
-
let i =
|
|
885
|
+
let i = z(r);
|
|
945
886
|
if (i === n.lines.join("\n")) return e;
|
|
946
|
-
let a =
|
|
887
|
+
let a = $e(n.lines, n.from, t), o = c.of([{
|
|
947
888
|
from: n.from,
|
|
948
889
|
to: n.to,
|
|
949
890
|
insert: i
|
|
950
891
|
}], e.newDoc.length);
|
|
951
892
|
return {
|
|
952
893
|
changes: e.changes.compose(o),
|
|
953
|
-
selection: a ? u.cursor(
|
|
894
|
+
selection: a ? u.cursor(V(i, n.from, a)) : e.newSelection,
|
|
954
895
|
effects: e.effects,
|
|
955
896
|
scrollIntoView: e.scrollIntoView
|
|
956
897
|
};
|
|
957
|
-
}),
|
|
958
|
-
let n = e
|
|
959
|
-
return n !== null &&
|
|
960
|
-
},
|
|
898
|
+
}), W = (e) => /^\s{0,3}#{1,6}(?:\s|$)/.test(e.doc.lineAt(e.selection.main.head).text), G = (e) => {
|
|
899
|
+
let n = t(e.doc);
|
|
900
|
+
return n !== null && e.selection.main.head <= n.to;
|
|
901
|
+
}, K = (e) => G(e) || P(e) || F(e), st = (e) => (t) => e !== "`" && L(t, "`") || e !== "$" && L(t, "$"), ct = (e) => e.selection.main.empty && !e.wordAt(e.selection.main.head), q = (...e) => (t) => e.some((e) => e(t)), J = /^(\s*)(?:[-*+] \[[ xX]\] +|\d+\. +|[-*+] +)/, lt = {
|
|
961
902
|
match: /^ {0,3}> ?/,
|
|
962
903
|
insert: "> "
|
|
963
|
-
},
|
|
904
|
+
}, ut = {
|
|
964
905
|
match: /^(\s*)[-*+] +(?!\[[ xX]\])/,
|
|
965
906
|
insert: "- ",
|
|
966
|
-
siblings:
|
|
967
|
-
},
|
|
907
|
+
siblings: J
|
|
908
|
+
}, dt = {
|
|
968
909
|
match: /^(\s*)\d+\. +/,
|
|
969
910
|
insert: (e) => `${e + 1}. `,
|
|
970
|
-
siblings:
|
|
971
|
-
},
|
|
911
|
+
siblings: J
|
|
912
|
+
}, ft = {
|
|
972
913
|
match: /^(\s*)[-*+] \[[ xX]\] +/,
|
|
973
914
|
insert: "- [ ] ",
|
|
974
|
-
siblings:
|
|
915
|
+
siblings: J
|
|
975
916
|
};
|
|
976
|
-
function
|
|
917
|
+
function pt(e, t, n) {
|
|
977
918
|
return {
|
|
978
919
|
id: e,
|
|
979
920
|
title: t,
|
|
@@ -983,47 +924,122 @@ function vt(e, t, n) {
|
|
|
983
924
|
}
|
|
984
925
|
};
|
|
985
926
|
}
|
|
986
|
-
function
|
|
927
|
+
function Y(e, t, n, r) {
|
|
987
928
|
return {
|
|
988
929
|
id: e,
|
|
989
930
|
title: t,
|
|
990
|
-
run: (e) =>
|
|
991
|
-
isActive: (e) =>
|
|
992
|
-
disabled:
|
|
931
|
+
run: (e) => j(e, (e, t, r) => O(e, t, r, n)) || I(e, n),
|
|
932
|
+
isActive: (e) => L(e, n),
|
|
933
|
+
disabled: q(K, st(n), ct),
|
|
993
934
|
keys: r
|
|
994
935
|
};
|
|
995
936
|
}
|
|
996
|
-
function
|
|
937
|
+
function X(e) {
|
|
997
938
|
let t = RegExp(`^#{${e}} `);
|
|
998
939
|
return {
|
|
999
940
|
id: `h${e}`,
|
|
1000
941
|
title: `Heading ${e}`,
|
|
1001
|
-
run: (t) =>
|
|
942
|
+
run: (t) => Fe(t, e),
|
|
1002
943
|
isActive: (e) => t.test(e.doc.lineAt(e.selection.main.head).text),
|
|
1003
|
-
disabled:
|
|
944
|
+
disabled: q(H, K),
|
|
1004
945
|
keys: [`Mod-Alt-${e}`]
|
|
1005
946
|
};
|
|
1006
947
|
}
|
|
1007
|
-
function
|
|
948
|
+
function Z(e, t, n, ...r) {
|
|
1008
949
|
return {
|
|
1009
950
|
id: e,
|
|
1010
951
|
title: t,
|
|
1011
|
-
run: (e) =>
|
|
1012
|
-
isActive: (e) =>
|
|
1013
|
-
disabled:
|
|
952
|
+
run: (e) => Oe(e, n),
|
|
953
|
+
isActive: (e) => ke(e, n.match),
|
|
954
|
+
disabled: q(H, K, ...r)
|
|
1014
955
|
};
|
|
1015
956
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region src/toolbar/frontmatter-toggle.ts
|
|
959
|
+
function mt(e) {
|
|
960
|
+
let n = e.state, r = t(n.doc);
|
|
961
|
+
if (r) {
|
|
962
|
+
let t = n.doc.lineAt(r.from), i = n.doc.lineAt(r.to);
|
|
963
|
+
e.dispatch({
|
|
964
|
+
changes: [{
|
|
965
|
+
from: t.from,
|
|
966
|
+
to: Math.min(t.to + 1, n.doc.length)
|
|
967
|
+
}, {
|
|
968
|
+
from: i.from,
|
|
969
|
+
to: Math.min(i.to + 1, n.doc.length)
|
|
970
|
+
}],
|
|
971
|
+
scrollIntoView: !0
|
|
972
|
+
});
|
|
973
|
+
} else {
|
|
974
|
+
let t = n.doc.lineAt(n.selection.main.to).number;
|
|
975
|
+
e.dispatch({
|
|
976
|
+
changes: [{
|
|
977
|
+
from: 0,
|
|
978
|
+
insert: "---\n"
|
|
979
|
+
}, {
|
|
980
|
+
from: n.doc.line(t).to,
|
|
981
|
+
insert: "\n---"
|
|
982
|
+
}],
|
|
983
|
+
selection: u.cursor(4),
|
|
984
|
+
scrollIntoView: !0
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
return e.focus(), !0;
|
|
988
|
+
}
|
|
989
|
+
function ht(e) {
|
|
990
|
+
return t(e.doc) !== null;
|
|
991
|
+
}
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region src/toolbar/rule.ts
|
|
994
|
+
var gt = /^ {0,3}([-*_])[ \t]*(?:\1[ \t]*){2,}$/;
|
|
995
|
+
function _t(e) {
|
|
996
|
+
let t = e.state, n = t.doc.lineAt(t.selection.main.head);
|
|
997
|
+
return gt.test(n.text) ? e.dispatch({
|
|
998
|
+
changes: {
|
|
999
|
+
from: n.from,
|
|
1000
|
+
to: Math.min(n.to + 1, t.doc.length)
|
|
1001
|
+
},
|
|
1002
|
+
scrollIntoView: !0
|
|
1003
|
+
}) : n.text.trim() === "" ? e.dispatch({
|
|
1004
|
+
changes: {
|
|
1005
|
+
from: n.from,
|
|
1006
|
+
to: n.to,
|
|
1007
|
+
insert: "---"
|
|
1008
|
+
},
|
|
1009
|
+
selection: u.cursor(n.from + 3),
|
|
1010
|
+
scrollIntoView: !0
|
|
1011
|
+
}) : e.dispatch({
|
|
1012
|
+
changes: {
|
|
1013
|
+
from: n.to,
|
|
1014
|
+
insert: "\n\n---\n"
|
|
1015
|
+
},
|
|
1016
|
+
selection: u.cursor(n.to + 6),
|
|
1017
|
+
scrollIntoView: !0
|
|
1018
|
+
}), e.focus(), !0;
|
|
1019
|
+
}
|
|
1020
|
+
function vt(e) {
|
|
1021
|
+
return gt.test(e.doc.lineAt(e.selection.main.head).text);
|
|
1022
|
+
}
|
|
1023
|
+
//#endregion
|
|
1024
|
+
//#region src/editor/save.ts
|
|
1025
|
+
var Q = f.define({ combine: (e) => e[0] ?? null });
|
|
1026
|
+
function yt(e) {
|
|
1027
|
+
let t = e.state.facet(Q);
|
|
1028
|
+
return t ? (t(e.state.doc.toString()), !0) : !1;
|
|
1029
|
+
}
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region src/toolbar/commands.ts
|
|
1032
|
+
var $ = [
|
|
1033
|
+
pt("undo", "Undo", g),
|
|
1034
|
+
pt("redo", "Redo", h),
|
|
1019
1035
|
{
|
|
1020
1036
|
id: "save",
|
|
1021
1037
|
title: "Save",
|
|
1022
1038
|
run: (e) => {
|
|
1023
|
-
let t =
|
|
1039
|
+
let t = yt(e);
|
|
1024
1040
|
return e.focus(), t;
|
|
1025
1041
|
},
|
|
1026
|
-
disabled: (e) => e.facet(
|
|
1042
|
+
disabled: (e) => e.facet(Q) == null
|
|
1027
1043
|
},
|
|
1028
1044
|
{
|
|
1029
1045
|
id: "search",
|
|
@@ -1031,173 +1047,173 @@ var yt = [
|
|
|
1031
1047
|
run: (e) => y(e),
|
|
1032
1048
|
keys: ["Mod-f"]
|
|
1033
1049
|
},
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1050
|
+
X(1),
|
|
1051
|
+
X(2),
|
|
1052
|
+
X(3),
|
|
1037
1053
|
{
|
|
1038
1054
|
id: "body",
|
|
1039
1055
|
title: "Body",
|
|
1040
|
-
run: (e) => (
|
|
1056
|
+
run: (e) => (Ie(e) || e.focus(), !0),
|
|
1041
1057
|
isActive: (e) => !/^#{1,6} /.test(e.doc.lineAt(e.selection.main.head).text),
|
|
1042
|
-
disabled:
|
|
1058
|
+
disabled: q(H, K)
|
|
1043
1059
|
},
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1060
|
+
Y("bold", "Bold", "**", ["Mod-b"]),
|
|
1061
|
+
Y("italic", "Italic", "*", ["Mod-i"]),
|
|
1062
|
+
Y("strike", "Strikethrough", "~~"),
|
|
1047
1063
|
{
|
|
1048
1064
|
id: "underline",
|
|
1049
1065
|
title: "Underline",
|
|
1050
|
-
run: (e) =>
|
|
1051
|
-
isActive:
|
|
1052
|
-
disabled:
|
|
1066
|
+
run: (e) => j(e, le) || We(e),
|
|
1067
|
+
isActive: Ge,
|
|
1068
|
+
disabled: q(K, st("u"), ct),
|
|
1053
1069
|
keys: ["Mod-u"]
|
|
1054
1070
|
},
|
|
1055
|
-
|
|
1071
|
+
Y("code", "Inline code", "`"),
|
|
1056
1072
|
{
|
|
1057
1073
|
id: "codeBlock",
|
|
1058
1074
|
title: "Code block",
|
|
1059
|
-
run: (e) =>
|
|
1060
|
-
isActive: (e) =>
|
|
1061
|
-
disabled:
|
|
1075
|
+
run: (e) => j(e, (e, t, n) => O(e, t, n, "`")) || (H(e.state) ? I(e, "`") : Ae(e)),
|
|
1076
|
+
isActive: (e) => H(e) ? L(e, "`") : P(e),
|
|
1077
|
+
disabled: q(G, F, W)
|
|
1062
1078
|
},
|
|
1063
1079
|
{
|
|
1064
1080
|
id: "link",
|
|
1065
1081
|
title: "Link",
|
|
1066
|
-
run: (e) =>
|
|
1067
|
-
isActive:
|
|
1068
|
-
disabled:
|
|
1082
|
+
run: (e) => j(e, ae) || Re(e),
|
|
1083
|
+
isActive: ze,
|
|
1084
|
+
disabled: K,
|
|
1069
1085
|
keys: ["Mod-k"]
|
|
1070
1086
|
},
|
|
1071
1087
|
{
|
|
1072
1088
|
id: "wikilink",
|
|
1073
1089
|
title: "Wikilink",
|
|
1074
|
-
run: (e) =>
|
|
1075
|
-
isActive:
|
|
1076
|
-
disabled:
|
|
1090
|
+
run: (e) => j(e, se) || Ve(e),
|
|
1091
|
+
isActive: He,
|
|
1092
|
+
disabled: K,
|
|
1077
1093
|
keys: ["Mod-Shift-k"]
|
|
1078
1094
|
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1095
|
+
Z("quote", "Blockquote", lt),
|
|
1096
|
+
Z("bulletList", "Bulleted list", ut, W),
|
|
1097
|
+
Z("orderedList", "Numbered list", dt, W),
|
|
1098
|
+
Z("task", "Task list", ft, W),
|
|
1083
1099
|
{
|
|
1084
1100
|
id: "hr",
|
|
1085
1101
|
title: "Divider",
|
|
1086
|
-
run:
|
|
1087
|
-
isActive:
|
|
1088
|
-
disabled:
|
|
1102
|
+
run: _t,
|
|
1103
|
+
isActive: vt,
|
|
1104
|
+
disabled: q(H, K)
|
|
1089
1105
|
},
|
|
1090
1106
|
{
|
|
1091
1107
|
id: "frontmatter",
|
|
1092
1108
|
title: "Frontmatter",
|
|
1093
|
-
run:
|
|
1094
|
-
isActive:
|
|
1095
|
-
disabled:
|
|
1109
|
+
run: mt,
|
|
1110
|
+
isActive: ht,
|
|
1111
|
+
disabled: q(H, P, F, W)
|
|
1096
1112
|
},
|
|
1097
1113
|
{
|
|
1098
1114
|
id: "table",
|
|
1099
1115
|
title: "Table",
|
|
1100
|
-
run:
|
|
1101
|
-
isActive:
|
|
1102
|
-
disabled:
|
|
1116
|
+
run: nt,
|
|
1117
|
+
isActive: H,
|
|
1118
|
+
disabled: q(H, G, P, F, W)
|
|
1103
1119
|
},
|
|
1104
|
-
|
|
1120
|
+
Y("math", "Inline math", "$"),
|
|
1105
1121
|
{
|
|
1106
1122
|
id: "mathBlock",
|
|
1107
1123
|
title: "Block math",
|
|
1108
|
-
run: (e) =>
|
|
1109
|
-
isActive: (e) =>
|
|
1110
|
-
disabled:
|
|
1124
|
+
run: (e) => j(e, (e, t, n) => O(e, t, n, "$")) || (H(e.state) ? I(e, "$") : Pe(e)),
|
|
1125
|
+
isActive: (e) => H(e) ? L(e, "$") : F(e),
|
|
1126
|
+
disabled: q(G, P, W)
|
|
1111
1127
|
}
|
|
1112
|
-
], bt = Object.fromEntries(
|
|
1128
|
+
], bt = Object.fromEntries($.map((e) => [e.id, e])), xt = p.high(a.of($.filter((e) => e.keys && e.keys.length > 0).flatMap((e) => e.keys.map((t) => ({
|
|
1113
1129
|
key: t,
|
|
1114
1130
|
preventDefault: !0,
|
|
1115
1131
|
run: ((t) => !e.disabled?.(t.state) && e.run(t))
|
|
1116
|
-
}))))), St =
|
|
1132
|
+
}))))), St = x.define([
|
|
1117
1133
|
{
|
|
1118
1134
|
tag: [
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1135
|
+
w.keyword,
|
|
1136
|
+
w.modifier,
|
|
1137
|
+
w.controlKeyword,
|
|
1138
|
+
w.operatorKeyword,
|
|
1139
|
+
w.definitionKeyword,
|
|
1140
|
+
w.moduleKeyword
|
|
1125
1141
|
],
|
|
1126
1142
|
color: "var(--stylo-syntax-keyword)"
|
|
1127
1143
|
},
|
|
1128
1144
|
{
|
|
1129
1145
|
tag: [
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1146
|
+
w.string,
|
|
1147
|
+
w.special(w.string),
|
|
1148
|
+
w.regexp,
|
|
1149
|
+
w.attributeValue
|
|
1134
1150
|
],
|
|
1135
1151
|
color: "var(--stylo-syntax-string)"
|
|
1136
1152
|
},
|
|
1137
1153
|
{
|
|
1138
|
-
tag: [
|
|
1154
|
+
tag: [w.escape, w.character],
|
|
1139
1155
|
color: "var(--stylo-syntax-escape)"
|
|
1140
1156
|
},
|
|
1141
1157
|
{
|
|
1142
1158
|
tag: [
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1159
|
+
w.comment,
|
|
1160
|
+
w.lineComment,
|
|
1161
|
+
w.blockComment,
|
|
1162
|
+
w.docComment
|
|
1147
1163
|
],
|
|
1148
1164
|
color: "var(--stylo-syntax-comment)",
|
|
1149
1165
|
fontStyle: "italic"
|
|
1150
1166
|
},
|
|
1151
1167
|
{
|
|
1152
1168
|
tag: [
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1169
|
+
w.number,
|
|
1170
|
+
w.integer,
|
|
1171
|
+
w.float
|
|
1156
1172
|
],
|
|
1157
1173
|
color: "var(--stylo-syntax-number)"
|
|
1158
1174
|
},
|
|
1159
1175
|
{
|
|
1160
1176
|
tag: [
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1177
|
+
w.bool,
|
|
1178
|
+
w.null,
|
|
1179
|
+
w.atom,
|
|
1180
|
+
w.constant(w.name)
|
|
1165
1181
|
],
|
|
1166
1182
|
color: "var(--stylo-syntax-constant)"
|
|
1167
1183
|
},
|
|
1168
1184
|
{
|
|
1169
1185
|
tag: [
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1186
|
+
w.function(w.variableName),
|
|
1187
|
+
w.function(w.propertyName),
|
|
1188
|
+
w.macroName
|
|
1173
1189
|
],
|
|
1174
1190
|
color: "var(--stylo-syntax-function)"
|
|
1175
1191
|
},
|
|
1176
1192
|
{
|
|
1177
1193
|
tag: [
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1194
|
+
w.typeName,
|
|
1195
|
+
w.className,
|
|
1196
|
+
w.namespace
|
|
1181
1197
|
],
|
|
1182
1198
|
color: "var(--stylo-syntax-type)"
|
|
1183
1199
|
},
|
|
1184
1200
|
{
|
|
1185
|
-
tag: [
|
|
1201
|
+
tag: [w.propertyName, w.attributeName],
|
|
1186
1202
|
color: "var(--stylo-syntax-property)"
|
|
1187
1203
|
},
|
|
1188
1204
|
{
|
|
1189
|
-
tag: [
|
|
1205
|
+
tag: [w.tagName],
|
|
1190
1206
|
color: "var(--stylo-syntax-tag)"
|
|
1191
1207
|
},
|
|
1192
1208
|
{
|
|
1193
|
-
tag: [
|
|
1209
|
+
tag: [w.meta, w.annotation],
|
|
1194
1210
|
color: "var(--stylo-syntax-comment)"
|
|
1195
1211
|
},
|
|
1196
1212
|
{
|
|
1197
|
-
tag: [
|
|
1213
|
+
tag: [w.invalid],
|
|
1198
1214
|
color: "var(--stylo-syntax-invalid)"
|
|
1199
1215
|
}
|
|
1200
|
-
]), Ct =
|
|
1216
|
+
]), Ct = S(St), wt = i.theme({
|
|
1201
1217
|
"&": {
|
|
1202
1218
|
color: "var(--stylo-text)",
|
|
1203
1219
|
backgroundColor: "var(--stylo-bg)",
|
|
@@ -1282,39 +1298,47 @@ function Et(e) {
|
|
|
1282
1298
|
}
|
|
1283
1299
|
};
|
|
1284
1300
|
}
|
|
1285
|
-
function Dt(e) {
|
|
1286
|
-
return async (
|
|
1287
|
-
let
|
|
1288
|
-
if (!
|
|
1289
|
-
let
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1301
|
+
function Dt(e, t) {
|
|
1302
|
+
return async (n) => {
|
|
1303
|
+
let r = n.matchBefore(Tt);
|
|
1304
|
+
if (!r || r.from + 2 === n.pos && !n.explicit) return null;
|
|
1305
|
+
let i = r.text.slice(2), a;
|
|
1306
|
+
try {
|
|
1307
|
+
a = (await e(i)).map(Et);
|
|
1308
|
+
} catch (e) {
|
|
1309
|
+
return t?.(e, {
|
|
1310
|
+
source: "wikiLinkSource",
|
|
1311
|
+
input: i
|
|
1312
|
+
}), null;
|
|
1313
|
+
}
|
|
1314
|
+
return a.length ? {
|
|
1315
|
+
from: r.from + 2,
|
|
1316
|
+
to: n.pos,
|
|
1317
|
+
options: a,
|
|
1294
1318
|
filter: !1
|
|
1295
1319
|
} : null;
|
|
1296
1320
|
};
|
|
1297
1321
|
}
|
|
1298
|
-
function Ot(e) {
|
|
1299
|
-
return e ? [
|
|
1322
|
+
function Ot(e, t) {
|
|
1323
|
+
return e ? [re(), v.data.of({ autocomplete: Dt(e, t) })] : [];
|
|
1300
1324
|
}
|
|
1301
1325
|
//#endregion
|
|
1302
1326
|
//#region src/editor/extensions.ts
|
|
1303
|
-
function kt(e, t) {
|
|
1327
|
+
function kt(e, t, n) {
|
|
1304
1328
|
return [
|
|
1305
1329
|
te(),
|
|
1306
1330
|
a.of([...ee, ...m]),
|
|
1307
|
-
p.high(
|
|
1331
|
+
p.high(at),
|
|
1308
1332
|
xt,
|
|
1309
|
-
|
|
1333
|
+
ot,
|
|
1310
1334
|
b({ top: !0 }),
|
|
1311
|
-
a.of(
|
|
1335
|
+
a.of(ne),
|
|
1312
1336
|
_({
|
|
1313
1337
|
base: v,
|
|
1314
1338
|
codeLanguages: e
|
|
1315
1339
|
}),
|
|
1316
1340
|
Ct,
|
|
1317
|
-
Ot(t),
|
|
1341
|
+
Ot(t, n),
|
|
1318
1342
|
i.lineWrapping,
|
|
1319
1343
|
wt
|
|
1320
1344
|
];
|
|
@@ -1324,50 +1348,54 @@ function At(e) {
|
|
|
1324
1348
|
d.readOnly.of(e.readOnly),
|
|
1325
1349
|
i.editable.of(!e.readOnly),
|
|
1326
1350
|
e.placeholder ? o(e.placeholder) : [],
|
|
1327
|
-
e.save ?
|
|
1351
|
+
e.save ? Q.of(e.save) : []
|
|
1328
1352
|
];
|
|
1329
1353
|
}
|
|
1330
1354
|
//#endregion
|
|
1331
1355
|
//#region src/editor/useCodeMirror.ts
|
|
1332
1356
|
var jt = s.define();
|
|
1333
|
-
function Mt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c, onViewChange: u, extensions: f, codeLanguages: ee, wikiLinkSource: te }) {
|
|
1334
|
-
let
|
|
1335
|
-
|
|
1336
|
-
let
|
|
1337
|
-
|
|
1338
|
-
let
|
|
1339
|
-
b.current =
|
|
1340
|
-
let
|
|
1357
|
+
function Mt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c, onViewChange: u, extensions: f, codeLanguages: ee, wikiLinkSource: te, onResolveError: m }) {
|
|
1358
|
+
let h = r(null), g = r(null), _ = r(t);
|
|
1359
|
+
_.current = t;
|
|
1360
|
+
let v = r(c);
|
|
1361
|
+
v.current = c;
|
|
1362
|
+
let y = r((e) => v.current?.(e)).current, b = r(m);
|
|
1363
|
+
b.current = m;
|
|
1364
|
+
let ne = r((e, t) => {
|
|
1365
|
+
b.current?.(e, t);
|
|
1366
|
+
}).current, x = c != null, S = r(u);
|
|
1367
|
+
S.current = u;
|
|
1368
|
+
let C = r(new l());
|
|
1341
1369
|
return n(() => {
|
|
1342
|
-
let t =
|
|
1370
|
+
let t = h.current;
|
|
1343
1371
|
if (!t) return;
|
|
1344
1372
|
let n = new i({
|
|
1345
1373
|
parent: t,
|
|
1346
1374
|
state: d.create({
|
|
1347
1375
|
doc: e,
|
|
1348
1376
|
extensions: [
|
|
1349
|
-
kt(ee, te),
|
|
1350
|
-
|
|
1377
|
+
kt(ee, te, ne),
|
|
1378
|
+
C.current.of(At({
|
|
1351
1379
|
readOnly: o,
|
|
1352
1380
|
placeholder: s,
|
|
1353
|
-
save:
|
|
1381
|
+
save: x ? y : void 0
|
|
1354
1382
|
})),
|
|
1355
1383
|
p.high(a.of([{
|
|
1356
1384
|
key: "Mod-s",
|
|
1357
|
-
run:
|
|
1385
|
+
run: yt
|
|
1358
1386
|
}])),
|
|
1359
1387
|
...f ?? [],
|
|
1360
1388
|
i.updateListener.of((e) => {
|
|
1361
|
-
e.docChanged && (e.transactions.some((e) => !!e.annotation(jt)) ||
|
|
1389
|
+
e.docChanged && (e.transactions.some((e) => !!e.annotation(jt)) || _.current(e.state.doc.toString()));
|
|
1362
1390
|
})
|
|
1363
1391
|
]
|
|
1364
1392
|
})
|
|
1365
1393
|
});
|
|
1366
|
-
return
|
|
1367
|
-
|
|
1394
|
+
return g.current = n, S.current?.(n), () => {
|
|
1395
|
+
S.current?.(null), n.destroy(), g.current = null;
|
|
1368
1396
|
};
|
|
1369
1397
|
}, []), n(() => {
|
|
1370
|
-
let t =
|
|
1398
|
+
let t = g.current;
|
|
1371
1399
|
if (!t) return;
|
|
1372
1400
|
let n = t.state.doc.toString();
|
|
1373
1401
|
n !== e && t.dispatch({
|
|
@@ -1379,19 +1407,19 @@ function Mt({ value: e, onChange: t, readOnly: o = !1, placeholder: s, onSave: c
|
|
|
1379
1407
|
annotations: jt.of(!0)
|
|
1380
1408
|
});
|
|
1381
1409
|
}, [e]), n(() => {
|
|
1382
|
-
|
|
1410
|
+
g.current?.dispatch({ effects: C.current.reconfigure(At({
|
|
1383
1411
|
readOnly: o,
|
|
1384
1412
|
placeholder: s,
|
|
1385
|
-
save:
|
|
1413
|
+
save: x ? y : void 0
|
|
1386
1414
|
})) });
|
|
1387
1415
|
}, [
|
|
1388
1416
|
o,
|
|
1389
1417
|
s,
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
]),
|
|
1418
|
+
x,
|
|
1419
|
+
y
|
|
1420
|
+
]), h;
|
|
1393
1421
|
}
|
|
1394
1422
|
//#endregion
|
|
1395
|
-
export {
|
|
1423
|
+
export { _e as _, R as a, oe as b, P as c, ge as d, xe as f, be as g, Ce as h, et as i, we as l, ye as m, bt as n, z as o, A as p, _t as r, je as s, Mt as t, De as u, ve as v, ie as x, E as y };
|
|
1396
1424
|
|
|
1397
|
-
//# sourceMappingURL=useCodeMirror-
|
|
1425
|
+
//# sourceMappingURL=useCodeMirror-DtwupFgc.js.map
|