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