@damiro/stylo 0.17.0 → 0.18.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 +5 -3
- package/dist/{InPlaceView-CRb5AkfX.js → InPlaceView-Z8c9cqW8.js} +4 -4
- package/dist/{InPlaceView-CRb5AkfX.js.map → InPlaceView-Z8c9cqW8.js.map} +1 -1
- package/dist/{Preview-5lm2uUVj.js → Preview-BRA_R_Gp.js} +3 -3
- package/dist/{Preview-5lm2uUVj.js.map → Preview-BRA_R_Gp.js.map} +1 -1
- package/dist/Stylo.d.ts.map +1 -1
- package/dist/{embed-DKKeCE1Y.js → embed-DJAydn-v.js} +2 -2
- package/dist/{embed-DKKeCE1Y.js.map → embed-DJAydn-v.js.map} +1 -1
- package/dist/{embed-cache-CcBfVrc9.js → embed-cache-BU9Smn-h.js} +24 -17
- package/dist/embed-cache-BU9Smn-h.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/stylo.js +391 -166
- package/dist/stylo.js.map +1 -1
- package/dist/toolbar/OverflowBar.d.ts +19 -0
- package/dist/toolbar/OverflowBar.d.ts.map +1 -0
- package/dist/toolbar/OverflowMenu.d.ts +24 -0
- package/dist/toolbar/OverflowMenu.d.ts.map +1 -0
- package/dist/toolbar/Toolbar.d.ts +5 -1
- package/dist/toolbar/Toolbar.d.ts.map +1 -1
- package/dist/toolbar/overflow-fit.d.ts +27 -0
- package/dist/toolbar/overflow-fit.d.ts.map +1 -0
- package/dist/toolbar/toolbar-model.d.ts +31 -0
- package/dist/toolbar/toolbar-model.d.ts.map +1 -0
- package/dist/toolbar/use-toolbar-overflow.d.ts +17 -0
- package/dist/toolbar/use-toolbar-overflow.d.ts.map +1 -0
- package/dist/types/toolbar.d.ts +16 -0
- package/dist/types/toolbar.d.ts.map +1 -1
- package/dist/{useCodeMirror-B07wRexo.js → useCodeMirror-Fn6qEfMx.js} +2 -2
- package/dist/{useCodeMirror-B07wRexo.js.map → useCodeMirror-Fn6qEfMx.js.map} +1 -1
- package/package.json +1 -1
- package/dist/embed-cache-CcBfVrc9.js.map +0 -1
package/dist/stylo.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { c as e, t, u as n } from "./embed-cache-
|
|
2
|
-
import { g as r, k as i, l as a, n as o, t as s } from "./useCodeMirror-
|
|
1
|
+
import { c as e, t, u as n } from "./embed-cache-BU9Smn-h.js";
|
|
2
|
+
import { g as r, k as i, l as a, n as o, t as s } from "./useCodeMirror-Fn6qEfMx.js";
|
|
3
3
|
import { n as c, r as l } from "./config-DTBxVhtH.js";
|
|
4
|
-
import { Suspense as u, forwardRef as d, lazy as f,
|
|
5
|
-
import { EditorView as
|
|
6
|
-
import { createPortal as
|
|
7
|
-
import { jsx as
|
|
4
|
+
import { Suspense as u, forwardRef as d, lazy as f, useCallback as p, useEffect as m, useImperativeHandle as h, useLayoutEffect as g, useReducer as _, useRef as v, useState as y, useSyncExternalStore as b } from "react";
|
|
5
|
+
import { EditorView as x, showPanel as S } from "@codemirror/view";
|
|
6
|
+
import { createPortal as C } from "react-dom";
|
|
7
|
+
import { Fragment as w, jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
8
8
|
//#region src/editor/SourceView.tsx
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
-
let [h,
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
}).current,
|
|
16
|
-
|
|
17
|
-
let [
|
|
9
|
+
var D = () => () => {}, O = () => null;
|
|
10
|
+
function k({ value: e, onChange: t, readOnly: r, placeholder: a, codeLanguages: o, wikiLinkSource: c, tagSource: l, onResolveError: u, onSave: d, onViewChange: f, canvasHeader: p, hostExtensions: m }) {
|
|
11
|
+
let [h, g] = y(null), _ = v(f);
|
|
12
|
+
_.current = f;
|
|
13
|
+
let x = v((e) => {
|
|
14
|
+
g(e), _.current?.(e);
|
|
15
|
+
}).current, w = v(p);
|
|
16
|
+
w.current = p;
|
|
17
|
+
let [E] = y(() => p ? new i() : null), k = b(E?.subscribe ?? D, E?.getSnapshot ?? O), [A] = y(() => E ? [S.of(E.panel)] : []), j = s({
|
|
18
18
|
value: e,
|
|
19
19
|
onChange: t,
|
|
20
20
|
readOnly: r,
|
|
@@ -24,41 +24,41 @@ function E({ value: e, onChange: t, readOnly: r, placeholder: a, codeLanguages:
|
|
|
24
24
|
tagSource: l,
|
|
25
25
|
onResolveError: u,
|
|
26
26
|
onSave: d,
|
|
27
|
-
onViewChange:
|
|
27
|
+
onViewChange: x,
|
|
28
28
|
hostExtensions: m,
|
|
29
29
|
extensions: A
|
|
30
30
|
});
|
|
31
|
-
return /* @__PURE__ */
|
|
31
|
+
return /* @__PURE__ */ T("div", {
|
|
32
32
|
className: n.source,
|
|
33
33
|
ref: j,
|
|
34
|
-
children: k &&
|
|
34
|
+
children: k && w.current && C(w.current({ view: h }), k)
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/inplace/lazyInPlace.ts
|
|
39
|
-
var
|
|
39
|
+
var A = f(async () => ({ default: (await import("./InPlaceView-Z8c9cqW8.js")).InPlaceView })), j = f(async () => ({ default: (await import("./Preview-BRA_R_Gp.js")).Preview }));
|
|
40
40
|
//#endregion
|
|
41
41
|
//#region src/SplitView.tsx
|
|
42
|
-
function
|
|
43
|
-
let [
|
|
44
|
-
return
|
|
45
|
-
let e =
|
|
42
|
+
function M({ value: e, onChange: t, onWikiLinkClick: r, readOnly: i, placeholder: a, codeLanguages: o, wikiLinkSource: s, tagSource: c, embedSource: l, onResolveError: d, frontmatter: f, softBreaks: p, onTaskToggle: h, onSave: g, onViewChange: _, canvasHeader: b, hostExtensions: x }) {
|
|
43
|
+
let [S, C] = y(null), w = v(null), D = v(!1);
|
|
44
|
+
return m(() => {
|
|
45
|
+
let e = S?.scrollDOM, t = w.current;
|
|
46
46
|
if (!e || !t) return;
|
|
47
47
|
let n = (e, t) => {
|
|
48
|
-
if (
|
|
48
|
+
if (D.current) return;
|
|
49
49
|
let n = e.scrollHeight - e.clientHeight;
|
|
50
|
-
n <= 0 || (
|
|
51
|
-
|
|
50
|
+
n <= 0 || (D.current = !0, t.scrollTop = e.scrollTop / n * (t.scrollHeight - t.clientHeight), requestAnimationFrame(() => {
|
|
51
|
+
D.current = !1;
|
|
52
52
|
}));
|
|
53
53
|
}, r = () => n(e, t), i = () => n(t, e);
|
|
54
54
|
return e.addEventListener("scroll", r, { passive: !0 }), t.addEventListener("scroll", i, { passive: !0 }), () => {
|
|
55
55
|
e.removeEventListener("scroll", r), t.removeEventListener("scroll", i);
|
|
56
56
|
};
|
|
57
|
-
}, [
|
|
57
|
+
}, [S]), /* @__PURE__ */ E("div", {
|
|
58
58
|
className: n.split,
|
|
59
|
-
children: [/* @__PURE__ */
|
|
59
|
+
children: [/* @__PURE__ */ T("div", {
|
|
60
60
|
className: n.splitPane,
|
|
61
|
-
children: /* @__PURE__ */
|
|
61
|
+
children: /* @__PURE__ */ T(k, {
|
|
62
62
|
value: e,
|
|
63
63
|
onChange: t,
|
|
64
64
|
readOnly: i,
|
|
@@ -67,29 +67,29 @@ function k({ value: e, onChange: t, onWikiLinkClick: r, readOnly: i, placeholder
|
|
|
67
67
|
wikiLinkSource: s,
|
|
68
68
|
tagSource: c,
|
|
69
69
|
onResolveError: d,
|
|
70
|
-
onSave:
|
|
70
|
+
onSave: g,
|
|
71
71
|
onViewChange: (e) => {
|
|
72
|
-
|
|
72
|
+
C(e), _?.(e);
|
|
73
73
|
},
|
|
74
74
|
canvasHeader: b,
|
|
75
75
|
hostExtensions: x
|
|
76
76
|
})
|
|
77
|
-
}), /* @__PURE__ */
|
|
77
|
+
}), /* @__PURE__ */ T("div", {
|
|
78
78
|
className: n.splitPane,
|
|
79
|
-
ref:
|
|
80
|
-
children: /* @__PURE__ */
|
|
81
|
-
fallback: /* @__PURE__ */
|
|
79
|
+
ref: w,
|
|
80
|
+
children: /* @__PURE__ */ T(u, {
|
|
81
|
+
fallback: /* @__PURE__ */ T("div", {
|
|
82
82
|
className: n.preview,
|
|
83
83
|
"aria-busy": "true"
|
|
84
84
|
}),
|
|
85
|
-
children: /* @__PURE__ */
|
|
85
|
+
children: /* @__PURE__ */ T(j, {
|
|
86
86
|
value: e,
|
|
87
87
|
onWikiLinkClick: r,
|
|
88
88
|
embedSource: l,
|
|
89
89
|
onResolveError: d,
|
|
90
90
|
frontmatter: f,
|
|
91
91
|
codeLanguages: o,
|
|
92
|
-
softBreaks:
|
|
92
|
+
softBreaks: p,
|
|
93
93
|
onTaskToggle: h
|
|
94
94
|
})
|
|
95
95
|
})
|
|
@@ -98,8 +98,8 @@ function k({ value: e, onChange: t, onWikiLinkClick: r, readOnly: i, placeholder
|
|
|
98
98
|
}
|
|
99
99
|
//#endregion
|
|
100
100
|
//#region src/toolbar/floating-watchdog.ts
|
|
101
|
-
function
|
|
102
|
-
|
|
101
|
+
function N(e, t) {
|
|
102
|
+
m(() => {
|
|
103
103
|
if (!t) return;
|
|
104
104
|
let n = 0, r = !1, i = () => {
|
|
105
105
|
let t = e.current;
|
|
@@ -110,9 +110,9 @@ function A(e, t) {
|
|
|
110
110
|
}
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/toolbar/keyboard-inset.ts
|
|
113
|
-
function
|
|
114
|
-
let [t, n] =
|
|
115
|
-
return
|
|
113
|
+
function P(e) {
|
|
114
|
+
let [t, n] = y(0);
|
|
115
|
+
return m(() => {
|
|
116
116
|
let t = typeof window > "u" ? null : window.visualViewport;
|
|
117
117
|
if (!e || !t) {
|
|
118
118
|
n(0);
|
|
@@ -125,8 +125,130 @@ function j(e) {
|
|
|
125
125
|
}, [e]), t;
|
|
126
126
|
}
|
|
127
127
|
//#endregion
|
|
128
|
-
//#region src/toolbar/
|
|
129
|
-
|
|
128
|
+
//#region src/toolbar/OverflowMenu.tsx
|
|
129
|
+
var F = /* @__PURE__ */ E("svg", {
|
|
130
|
+
viewBox: "0 0 24 24",
|
|
131
|
+
fill: "currentColor",
|
|
132
|
+
stroke: "none",
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ T("circle", {
|
|
135
|
+
cx: "5",
|
|
136
|
+
cy: "12",
|
|
137
|
+
r: "1.8"
|
|
138
|
+
}),
|
|
139
|
+
/* @__PURE__ */ T("circle", {
|
|
140
|
+
cx: "12",
|
|
141
|
+
cy: "12",
|
|
142
|
+
r: "1.8"
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ T("circle", {
|
|
145
|
+
cx: "19",
|
|
146
|
+
cy: "12",
|
|
147
|
+
r: "1.8"
|
|
148
|
+
})
|
|
149
|
+
]
|
|
150
|
+
}), I = (e) => e ?? F;
|
|
151
|
+
function L({ entries: e, icon: t }) {
|
|
152
|
+
let [r, i] = y(!1), a = v(null), o = v(null);
|
|
153
|
+
m(() => {
|
|
154
|
+
if (!r) return;
|
|
155
|
+
let e = (e) => {
|
|
156
|
+
a.current?.contains(e.target) || i(!1);
|
|
157
|
+
}, t = (e) => {
|
|
158
|
+
if (e.key !== "Escape") return;
|
|
159
|
+
let t = a.current?.contains(document.activeElement);
|
|
160
|
+
i(!1), t && o.current?.focus();
|
|
161
|
+
};
|
|
162
|
+
return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
|
|
163
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
164
|
+
};
|
|
165
|
+
}, [r]);
|
|
166
|
+
let s = () => Array.from(a.current?.querySelectorAll("[role^=menuitem]:enabled") ?? []);
|
|
167
|
+
return /* @__PURE__ */ E("div", {
|
|
168
|
+
ref: a,
|
|
169
|
+
className: n.toolbarMore,
|
|
170
|
+
"data-stylo-overflow": "",
|
|
171
|
+
onKeyDown: (e) => {
|
|
172
|
+
if ((e.key === "ArrowDown" || e.key === "ArrowUp") && r) {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
let t = s(), n = t.indexOf(document.activeElement), r = e.key === "ArrowDown";
|
|
175
|
+
t[n < 0 ? r ? 0 : t.length - 1 : (n + (r ? 1 : -1) + t.length) % t.length]?.focus();
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
onBlur: (e) => {
|
|
179
|
+
r && !a.current?.contains(e.relatedTarget) && i(!1);
|
|
180
|
+
},
|
|
181
|
+
children: [/* @__PURE__ */ T("button", {
|
|
182
|
+
ref: o,
|
|
183
|
+
type: "button",
|
|
184
|
+
className: n.toolbarButton,
|
|
185
|
+
title: "More",
|
|
186
|
+
"aria-label": "More",
|
|
187
|
+
"aria-haspopup": "menu",
|
|
188
|
+
"aria-expanded": r,
|
|
189
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
190
|
+
onClick: (e) => {
|
|
191
|
+
let t = !r;
|
|
192
|
+
i(t), t && e.detail === 0 && requestAnimationFrame(() => s()[0]?.focus());
|
|
193
|
+
},
|
|
194
|
+
children: I(t)
|
|
195
|
+
}), r && /* @__PURE__ */ T("div", {
|
|
196
|
+
className: n.toolbarMenu,
|
|
197
|
+
role: "menu",
|
|
198
|
+
"data-stylo-overflow-menu": "",
|
|
199
|
+
children: e.map((e, t) => e === "|" ? /* @__PURE__ */ T("div", {
|
|
200
|
+
className: n.toolbarMenuDivider,
|
|
201
|
+
role: "separator"
|
|
202
|
+
}, `d-${t}`) : /* @__PURE__ */ E("button", {
|
|
203
|
+
type: "button",
|
|
204
|
+
role: e.active === void 0 ? "menuitem" : "menuitemcheckbox",
|
|
205
|
+
"aria-checked": e.active,
|
|
206
|
+
"data-active": e.active ? "" : void 0,
|
|
207
|
+
className: n.toolbarMenuItem,
|
|
208
|
+
"data-command": e.key,
|
|
209
|
+
disabled: e.disabled,
|
|
210
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
211
|
+
onClick: () => {
|
|
212
|
+
a.current?.contains(document.activeElement) && o.current?.focus(), i(!1), e.run();
|
|
213
|
+
},
|
|
214
|
+
children: [e.icon, /* @__PURE__ */ T("span", { children: e.title })]
|
|
215
|
+
}, e.key))
|
|
216
|
+
})]
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/toolbar/overflow-fit.ts
|
|
221
|
+
function R(e) {
|
|
222
|
+
let t = [];
|
|
223
|
+
for (let n of e) n.sep && (t.length === 0 || t[t.length - 1].sep) || t.push(n);
|
|
224
|
+
for (; t.length && t[t.length - 1].sep;) t.pop();
|
|
225
|
+
return t;
|
|
226
|
+
}
|
|
227
|
+
function z(e) {
|
|
228
|
+
let t = e.findIndex((e) => e.folded), n = e.map((e) => e.folded).lastIndexOf(!0);
|
|
229
|
+
return R(e.filter((e, r) => e.folded || e.sep && r > t && r < n));
|
|
230
|
+
}
|
|
231
|
+
function B(e, t, n, r = 0) {
|
|
232
|
+
let i = e.map(() => !1), a = () => {
|
|
233
|
+
let a = R(e.filter((e, t) => !i[t]));
|
|
234
|
+
return a.reduce((e, t) => e + t.width, 0) + r * Math.max(0, a.length - 1) + (i.some(Boolean) ? n + (a.length ? r : 0) : 0) <= t;
|
|
235
|
+
}, o = (t) => {
|
|
236
|
+
for (let n = e.length - 1; n >= 0; n--) {
|
|
237
|
+
let r = e[n];
|
|
238
|
+
if (!i[n] && !r.sep && r.pinned === t) return n;
|
|
239
|
+
}
|
|
240
|
+
return -1;
|
|
241
|
+
};
|
|
242
|
+
for (; !a();) {
|
|
243
|
+
let e = o(!1) >= 0 ? o(!1) : o(!0);
|
|
244
|
+
if (e < 0) break;
|
|
245
|
+
i[e] = !0;
|
|
246
|
+
}
|
|
247
|
+
return i;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/toolbar/toolbar-model.ts
|
|
251
|
+
function V(e) {
|
|
130
252
|
let t = [], n = [];
|
|
131
253
|
for (let r of e) {
|
|
132
254
|
if (r !== "|") {
|
|
@@ -137,7 +259,7 @@ function M(e) {
|
|
|
137
259
|
}
|
|
138
260
|
return n.length && t.push(n), t;
|
|
139
261
|
}
|
|
140
|
-
function
|
|
262
|
+
function H(e, t) {
|
|
141
263
|
if (typeof e != "string") {
|
|
142
264
|
let { id: t, icon: n, title: r, run: i, isActive: a, disabled: o } = e;
|
|
143
265
|
return {
|
|
@@ -159,105 +281,206 @@ function N(e, t) {
|
|
|
159
281
|
disabled: n.disabled
|
|
160
282
|
} : null;
|
|
161
283
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/toolbar/use-toolbar-overflow.ts
|
|
286
|
+
var U = (e) => parseFloat(e) || 0;
|
|
287
|
+
function W(e) {
|
|
288
|
+
let t = getComputedStyle(e);
|
|
289
|
+
return e.getBoundingClientRect().width + U(t.marginLeft) + U(t.marginRight);
|
|
290
|
+
}
|
|
291
|
+
function G(e, t) {
|
|
292
|
+
let [n, r] = y([]), i = t.map((e) => `${e.key}${e.sep ? "|" : ""}${e.pinned ? "!" : ""}`).join("\0"), a = p(() => {
|
|
293
|
+
let n = e.current, i = n?.closest("[role=toolbar]");
|
|
294
|
+
if (!i || !n) return;
|
|
295
|
+
let a = Array.from(n.children), o = a.pop();
|
|
296
|
+
if (!o || a.length !== t.length) return;
|
|
297
|
+
let s = getComputedStyle(i), c = i.clientWidth - U(s.paddingLeft) - U(s.paddingRight), l = B(t.map((e, t) => ({
|
|
298
|
+
sep: e.sep,
|
|
299
|
+
pinned: e.pinned,
|
|
300
|
+
width: W(a[t])
|
|
301
|
+
})), c, W(o), U(getComputedStyle(n).columnGap));
|
|
302
|
+
r((e) => e.length === l.length && e.every((e, t) => e === l[t]) ? e : l);
|
|
303
|
+
}, [e, i]);
|
|
304
|
+
return g(() => {
|
|
305
|
+
let t = e.current, n = t?.closest("[role=toolbar]");
|
|
306
|
+
if (!n || !t || (a(), typeof ResizeObserver > "u")) return;
|
|
307
|
+
let r = new ResizeObserver(a);
|
|
308
|
+
return r.observe(n), r.observe(t), () => r.disconnect();
|
|
309
|
+
}, [e, a]), n;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/toolbar/OverflowBar.tsx
|
|
313
|
+
var K = () => /* @__PURE__ */ T("span", {
|
|
314
|
+
className: n.toolbarSep,
|
|
315
|
+
"aria-hidden": "true"
|
|
316
|
+
});
|
|
317
|
+
function q({ items: e, icons: t, overflowIcon: r, resolve: i, run: a, renderItem: o }) {
|
|
318
|
+
let s = v(null), c = e.filter((e) => e === "|" || H(e, t) !== null), l = G(s, c.map((e, t) => ({
|
|
319
|
+
key: e === "|" ? `sep-${t}` : typeof e == "string" ? e : e.id,
|
|
320
|
+
sep: e === "|",
|
|
321
|
+
pinned: typeof e == "object" && !!e.pinned
|
|
322
|
+
}))), u = c.map((e, t) => ({
|
|
323
|
+
it: e,
|
|
324
|
+
sep: e === "|",
|
|
325
|
+
folded: !!l[t]
|
|
326
|
+
})), d = R(u.filter((e) => !e.folded)), f = z(u), p = f.map((e) => {
|
|
327
|
+
let t = e.it === "|" ? null : i(e.it);
|
|
328
|
+
if (!t) return "|";
|
|
329
|
+
let { btn: n, off: r, active: o } = t;
|
|
330
|
+
return {
|
|
331
|
+
key: n.key,
|
|
332
|
+
title: n.title,
|
|
333
|
+
icon: n.icon,
|
|
334
|
+
disabled: r,
|
|
335
|
+
active: n.isActive ? o : void 0,
|
|
336
|
+
run: () => a(n)
|
|
337
|
+
};
|
|
338
|
+
});
|
|
339
|
+
return /* @__PURE__ */ E(w, { children: [
|
|
340
|
+
d.map((e, t) => e.it === "|" ? /* @__PURE__ */ T(K, {}, `sep-${t}`) : o(e.it)),
|
|
341
|
+
f.length > 0 && /* @__PURE__ */ T(L, {
|
|
342
|
+
entries: p,
|
|
343
|
+
icon: r
|
|
344
|
+
}),
|
|
345
|
+
/* @__PURE__ */ T("div", {
|
|
346
|
+
className: n.toolbarMeasureClip,
|
|
347
|
+
"aria-hidden": "true",
|
|
348
|
+
children: /* @__PURE__ */ E("div", {
|
|
349
|
+
ref: s,
|
|
350
|
+
className: n.toolbarMeasure,
|
|
351
|
+
children: [c.map((e, r) => e === "|" ? /* @__PURE__ */ T(K, {}, r) : /* @__PURE__ */ T("button", {
|
|
352
|
+
type: "button",
|
|
353
|
+
tabIndex: -1,
|
|
354
|
+
className: n.toolbarButton,
|
|
355
|
+
children: H(e, t).icon
|
|
356
|
+
}, r)), /* @__PURE__ */ T("button", {
|
|
357
|
+
type: "button",
|
|
358
|
+
tabIndex: -1,
|
|
359
|
+
className: n.toolbarButton,
|
|
360
|
+
children: I(r)
|
|
361
|
+
})]
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
] });
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/toolbar/Toolbar.tsx
|
|
368
|
+
function J({ view: e, items: t, icons: i, disabled: s, sticky: c, stickyVisibility: l, overflow: u, overflowIcon: d }) {
|
|
369
|
+
let [, f] = _((e) => e + 1, 0), [p, h] = y(!1), g = P(c === "bottom"), b = v(null);
|
|
370
|
+
N(b, c === "top"), m(() => {
|
|
165
371
|
if (!e) return;
|
|
166
372
|
let t = e.contentDOM;
|
|
167
|
-
|
|
373
|
+
h(e.hasFocus);
|
|
168
374
|
let n = () => {
|
|
169
|
-
|
|
375
|
+
h(!0), f();
|
|
170
376
|
}, r = () => {
|
|
171
|
-
|
|
377
|
+
h(!1), f();
|
|
172
378
|
}, i = [
|
|
173
379
|
"keyup",
|
|
174
380
|
"mouseup",
|
|
175
381
|
"input"
|
|
176
382
|
];
|
|
177
|
-
for (let e of i) t.addEventListener(e,
|
|
383
|
+
for (let e of i) t.addEventListener(e, f);
|
|
178
384
|
return t.addEventListener("focus", n), t.addEventListener("blur", r), () => {
|
|
179
|
-
for (let e of i) t.removeEventListener(e,
|
|
385
|
+
for (let e of i) t.removeEventListener(e, f);
|
|
180
386
|
t.removeEventListener("focus", n), t.removeEventListener("blur", r);
|
|
181
387
|
};
|
|
182
388
|
}, [e]);
|
|
183
|
-
let
|
|
389
|
+
let x = !!c && l === "dynamic" && !p, S = e ? !!r(e) : !1, C = u === "menu", w = [
|
|
184
390
|
n.toolbar,
|
|
185
391
|
c && n.toolbarSticky,
|
|
186
392
|
c === "top" && n.toolbarStickyTop,
|
|
187
393
|
c === "bottom" && n.toolbarStickyBottom,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
394
|
+
x && n.toolbarStickyHidden,
|
|
395
|
+
C && n.toolbarOverflow
|
|
396
|
+
].filter(Boolean).join(" "), E = c === "bottom" ? { transform: `translateY(-${g}px)` } : void 0, D = (t) => {
|
|
397
|
+
let n = H(t, i);
|
|
398
|
+
if (!n) return null;
|
|
399
|
+
let r = typeof t == "string" ? o[t] : void 0, c = e ? r ? a(e.state, r, S) : {
|
|
400
|
+
disabled: !!n.disabled?.(e.state),
|
|
401
|
+
active: !!n.isActive?.(e.state)
|
|
402
|
+
} : {
|
|
403
|
+
disabled: !0,
|
|
404
|
+
active: !1
|
|
405
|
+
}, l = !!(s || !e || c.disabled);
|
|
406
|
+
return {
|
|
407
|
+
btn: n,
|
|
408
|
+
off: l,
|
|
409
|
+
active: !l && c.active
|
|
410
|
+
};
|
|
411
|
+
}, O = (t) => {
|
|
412
|
+
e && (t.run(e), f());
|
|
413
|
+
}, k = (e) => {
|
|
414
|
+
let t = D(e);
|
|
415
|
+
if (!t) return null;
|
|
416
|
+
let { btn: r, off: i, active: a } = t;
|
|
417
|
+
return /* @__PURE__ */ T("button", {
|
|
418
|
+
type: "button",
|
|
419
|
+
className: n.toolbarButton,
|
|
420
|
+
"data-command": r.key,
|
|
421
|
+
title: r.title,
|
|
422
|
+
"aria-label": r.title,
|
|
423
|
+
"aria-pressed": r.isActive ? a : void 0,
|
|
424
|
+
"data-active": a ? "" : void 0,
|
|
425
|
+
disabled: i,
|
|
426
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
427
|
+
onClick: () => O(r),
|
|
428
|
+
children: r.icon
|
|
429
|
+
}, r.key);
|
|
430
|
+
}, A = C ? /* @__PURE__ */ T(q, {
|
|
431
|
+
items: t,
|
|
432
|
+
icons: i,
|
|
433
|
+
overflowIcon: d,
|
|
434
|
+
resolve: D,
|
|
435
|
+
run: O,
|
|
436
|
+
renderItem: k
|
|
437
|
+
}) : V(t).map((e, t) => e === "|" ? /* @__PURE__ */ T("span", {
|
|
438
|
+
className: n.toolbarSep,
|
|
439
|
+
"aria-hidden": "true"
|
|
440
|
+
}, `sep-${t}`) : /* @__PURE__ */ T("div", {
|
|
441
|
+
className: n.toolbarGroup,
|
|
442
|
+
children: e.map(k)
|
|
443
|
+
}, `group-${t}`));
|
|
444
|
+
return /* @__PURE__ */ T("div", {
|
|
445
|
+
ref: b,
|
|
446
|
+
className: w,
|
|
193
447
|
role: "toolbar",
|
|
194
448
|
"aria-label": "Formatting",
|
|
195
|
-
"aria-hidden":
|
|
196
|
-
style:
|
|
197
|
-
children:
|
|
198
|
-
className: n.toolbarSep,
|
|
199
|
-
"aria-hidden": "true"
|
|
200
|
-
}, `sep-${r}`) : /* @__PURE__ */ S("div", {
|
|
201
|
-
className: n.toolbarGroup,
|
|
202
|
-
children: t.map((t) => {
|
|
203
|
-
let r = N(t, i);
|
|
204
|
-
if (!r) return null;
|
|
205
|
-
let c = typeof t == "string" ? o[t] : void 0, l = e ? c ? a(e.state, c, b) : {
|
|
206
|
-
disabled: !!r.disabled?.(e.state),
|
|
207
|
-
active: !!r.isActive?.(e.state)
|
|
208
|
-
} : {
|
|
209
|
-
disabled: !0,
|
|
210
|
-
active: !1
|
|
211
|
-
}, d = s || !e || l.disabled, f = !d && l.active;
|
|
212
|
-
return /* @__PURE__ */ S("button", {
|
|
213
|
-
type: "button",
|
|
214
|
-
className: n.toolbarButton,
|
|
215
|
-
"data-command": r.key,
|
|
216
|
-
title: r.title,
|
|
217
|
-
"aria-label": r.title,
|
|
218
|
-
"aria-pressed": r.isActive ? f : void 0,
|
|
219
|
-
"data-active": f ? "" : void 0,
|
|
220
|
-
disabled: d,
|
|
221
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
222
|
-
onClick: () => {
|
|
223
|
-
e && (r.run(e), u());
|
|
224
|
-
},
|
|
225
|
-
children: r.icon
|
|
226
|
-
}, r.key);
|
|
227
|
-
})
|
|
228
|
-
}, `group-${r}`))
|
|
449
|
+
"aria-hidden": x || void 0,
|
|
450
|
+
style: E,
|
|
451
|
+
children: A
|
|
229
452
|
});
|
|
230
453
|
}
|
|
231
454
|
//#endregion
|
|
232
455
|
//#region src/Stylo.tsx
|
|
233
|
-
var
|
|
234
|
-
let
|
|
456
|
+
var Y = d(function({ value: r, onChange: i, mode: a = "in-place", onSave: o, onFrontmatter: s, onWikiLinkClick: l, onLinkClick: d, readOnly: f, placeholder: p, className: g, inPlace: _, codeLanguages: b, wikiLinkSource: S, tagSource: C, embedSource: w, onResolveError: D, toolbar: O, icons: N, frontmatter: P, softBreaks: F, onTaskToggle: I, canvasHeader: L, extensions: R }, z) {
|
|
457
|
+
let B = a === "preview" || a === "split" || a === "in-place" ? a : "source", [V, H] = y(null), U = B === "preview" ? null : c(O), W = O && typeof O == "object" ? O : void 0, G = W?.render, K = W?.sticky === "top" ? "top" : W?.sticky ? "bottom" : !1, q = W?.stickyVisibility, Y = v(s);
|
|
235
458
|
Y.current = s;
|
|
236
|
-
let X =
|
|
237
|
-
X.current =
|
|
238
|
-
let Z =
|
|
459
|
+
let X = v(D);
|
|
460
|
+
X.current = D;
|
|
461
|
+
let Z = v((e, t) => {
|
|
239
462
|
X.current?.(e, t);
|
|
240
|
-
}).current, Q =
|
|
241
|
-
Q.current =
|
|
242
|
-
let $ =
|
|
243
|
-
|
|
463
|
+
}).current, Q = v(w);
|
|
464
|
+
Q.current = w;
|
|
465
|
+
let $ = v(void 0);
|
|
466
|
+
m(() => {
|
|
244
467
|
let t = e(r)?.frontmatter ?? null;
|
|
245
468
|
t !== $.current && ($.current = t, Y.current?.(t));
|
|
246
|
-
}, [r]),
|
|
247
|
-
focus: () =>
|
|
248
|
-
getView: () =>
|
|
469
|
+
}, [r]), h(z, () => ({
|
|
470
|
+
focus: () => V?.focus(),
|
|
471
|
+
getView: () => V,
|
|
249
472
|
insertAtCursor: (e) => {
|
|
250
|
-
|
|
473
|
+
V && (V.dispatch(V.state.replaceSelection(e)), V.focus());
|
|
251
474
|
},
|
|
252
475
|
scrollToHeading: (e) => {
|
|
253
|
-
if (!
|
|
254
|
-
let t = e.trim().toLowerCase(), { doc: n } =
|
|
476
|
+
if (!V) return !1;
|
|
477
|
+
let t = e.trim().toLowerCase(), { doc: n } = V.state;
|
|
255
478
|
for (let e = 1; e <= n.lines; e++) {
|
|
256
479
|
let r = n.line(e), i = /^ {0,3}#{1,6}[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/.exec(r.text);
|
|
257
|
-
if (!(!i || i[1] === void 0) && i[1].trim().toLowerCase() === t) return
|
|
480
|
+
if (!(!i || i[1] === void 0) && i[1].trim().toLowerCase() === t) return V.dispatch({
|
|
258
481
|
selection: { anchor: r.from },
|
|
259
|
-
effects:
|
|
260
|
-
}),
|
|
482
|
+
effects: x.scrollIntoView(r.from, { y: "start" })
|
|
483
|
+
}), V.focus(), !0;
|
|
261
484
|
}
|
|
262
485
|
return !1;
|
|
263
486
|
},
|
|
@@ -265,107 +488,109 @@ var F = d(function({ value: r, onChange: i, mode: a = "in-place", onSave: o, onF
|
|
|
265
488
|
let n = Q.current;
|
|
266
489
|
n && t(n, e);
|
|
267
490
|
}
|
|
268
|
-
}), [
|
|
491
|
+
}), [V]);
|
|
269
492
|
let ee = [
|
|
270
493
|
n.root,
|
|
271
|
-
|
|
272
|
-
|
|
494
|
+
K === "bottom" && n.stickyToolbarRootBottom,
|
|
495
|
+
K === "top" && n.stickyToolbarRootTop,
|
|
273
496
|
"stylo",
|
|
274
|
-
|
|
497
|
+
g
|
|
275
498
|
].filter(Boolean).join(" ");
|
|
276
|
-
return /* @__PURE__ */
|
|
499
|
+
return /* @__PURE__ */ E("div", {
|
|
277
500
|
className: ee,
|
|
278
|
-
"data-stylo-mode":
|
|
501
|
+
"data-stylo-mode": B,
|
|
279
502
|
children: [
|
|
280
|
-
|
|
281
|
-
let e = /* @__PURE__ */
|
|
282
|
-
view:
|
|
283
|
-
items:
|
|
503
|
+
U && (() => {
|
|
504
|
+
let e = /* @__PURE__ */ T(J, {
|
|
505
|
+
view: V,
|
|
506
|
+
items: U,
|
|
284
507
|
icons: N,
|
|
285
508
|
disabled: f,
|
|
286
|
-
sticky:
|
|
287
|
-
stickyVisibility:
|
|
509
|
+
sticky: K,
|
|
510
|
+
stickyVisibility: q,
|
|
511
|
+
overflow: W?.overflow,
|
|
512
|
+
overflowIcon: W?.overflowIcon
|
|
288
513
|
});
|
|
289
|
-
return
|
|
514
|
+
return G ? G(e, { view: V }) : e;
|
|
290
515
|
})(),
|
|
291
|
-
|
|
516
|
+
B === "source" && /* @__PURE__ */ T(k, {
|
|
292
517
|
value: r,
|
|
293
518
|
onChange: i,
|
|
294
519
|
readOnly: f,
|
|
295
|
-
placeholder:
|
|
296
|
-
codeLanguages:
|
|
297
|
-
wikiLinkSource:
|
|
298
|
-
tagSource:
|
|
520
|
+
placeholder: p,
|
|
521
|
+
codeLanguages: b,
|
|
522
|
+
wikiLinkSource: S,
|
|
523
|
+
tagSource: C,
|
|
299
524
|
onResolveError: Z,
|
|
300
525
|
onSave: o,
|
|
301
|
-
onViewChange:
|
|
302
|
-
canvasHeader:
|
|
303
|
-
hostExtensions:
|
|
526
|
+
onViewChange: H,
|
|
527
|
+
canvasHeader: L,
|
|
528
|
+
hostExtensions: R
|
|
304
529
|
}),
|
|
305
|
-
|
|
306
|
-
fallback: /* @__PURE__ */
|
|
530
|
+
B === "preview" && /* @__PURE__ */ T(u, {
|
|
531
|
+
fallback: /* @__PURE__ */ T("div", {
|
|
307
532
|
className: n.preview,
|
|
308
533
|
"aria-busy": "true"
|
|
309
534
|
}),
|
|
310
|
-
children: /* @__PURE__ */
|
|
535
|
+
children: /* @__PURE__ */ T(j, {
|
|
311
536
|
value: r,
|
|
312
537
|
onWikiLinkClick: l,
|
|
313
|
-
embedSource:
|
|
538
|
+
embedSource: w,
|
|
314
539
|
onResolveError: Z,
|
|
315
|
-
frontmatter:
|
|
316
|
-
codeLanguages:
|
|
317
|
-
softBreaks:
|
|
318
|
-
onTaskToggle:
|
|
540
|
+
frontmatter: P,
|
|
541
|
+
codeLanguages: b,
|
|
542
|
+
softBreaks: F,
|
|
543
|
+
onTaskToggle: I
|
|
319
544
|
})
|
|
320
545
|
}),
|
|
321
|
-
|
|
546
|
+
B === "split" && /* @__PURE__ */ T(M, {
|
|
322
547
|
value: r,
|
|
323
548
|
onChange: i,
|
|
324
549
|
onWikiLinkClick: l,
|
|
325
550
|
readOnly: f,
|
|
326
|
-
placeholder:
|
|
327
|
-
codeLanguages:
|
|
328
|
-
wikiLinkSource:
|
|
329
|
-
tagSource:
|
|
330
|
-
embedSource:
|
|
551
|
+
placeholder: p,
|
|
552
|
+
codeLanguages: b,
|
|
553
|
+
wikiLinkSource: S,
|
|
554
|
+
tagSource: C,
|
|
555
|
+
embedSource: w,
|
|
331
556
|
onResolveError: Z,
|
|
332
|
-
frontmatter:
|
|
333
|
-
softBreaks:
|
|
334
|
-
onTaskToggle:
|
|
557
|
+
frontmatter: P,
|
|
558
|
+
softBreaks: F,
|
|
559
|
+
onTaskToggle: I,
|
|
335
560
|
onSave: o,
|
|
336
|
-
onViewChange:
|
|
337
|
-
canvasHeader:
|
|
338
|
-
hostExtensions:
|
|
561
|
+
onViewChange: H,
|
|
562
|
+
canvasHeader: L,
|
|
563
|
+
hostExtensions: R
|
|
339
564
|
}),
|
|
340
|
-
|
|
341
|
-
fallback: /* @__PURE__ */
|
|
565
|
+
B === "in-place" && /* @__PURE__ */ T(u, {
|
|
566
|
+
fallback: /* @__PURE__ */ T("div", {
|
|
342
567
|
className: n.inplace,
|
|
343
568
|
"aria-busy": "true"
|
|
344
569
|
}),
|
|
345
|
-
children: /* @__PURE__ */
|
|
570
|
+
children: /* @__PURE__ */ T(A, {
|
|
346
571
|
value: r,
|
|
347
572
|
onChange: i,
|
|
348
573
|
readOnly: f,
|
|
349
|
-
placeholder:
|
|
574
|
+
placeholder: p,
|
|
350
575
|
onWikiLinkClick: l,
|
|
351
576
|
onLinkClick: d,
|
|
352
|
-
inPlace:
|
|
353
|
-
codeLanguages:
|
|
354
|
-
wikiLinkSource:
|
|
355
|
-
tagSource:
|
|
356
|
-
embedSource:
|
|
577
|
+
inPlace: _,
|
|
578
|
+
codeLanguages: b,
|
|
579
|
+
wikiLinkSource: S,
|
|
580
|
+
tagSource: C,
|
|
581
|
+
embedSource: w,
|
|
357
582
|
onResolveError: Z,
|
|
358
583
|
onSave: o,
|
|
359
|
-
onViewChange:
|
|
360
|
-
canvasHeader:
|
|
361
|
-
hostExtensions:
|
|
584
|
+
onViewChange: H,
|
|
585
|
+
canvasHeader: L,
|
|
586
|
+
hostExtensions: R
|
|
362
587
|
})
|
|
363
588
|
})
|
|
364
589
|
]
|
|
365
590
|
});
|
|
366
591
|
});
|
|
367
|
-
|
|
592
|
+
Y.displayName = "Stylo";
|
|
368
593
|
//#endregion
|
|
369
|
-
export {
|
|
594
|
+
export { Y as Stylo, e as splitFrontmatter };
|
|
370
595
|
|
|
371
596
|
//# sourceMappingURL=stylo.js.map
|