@aiquants/markdown-explorer 0.20.0 → 0.21.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/CHANGELOG.md +24 -0
- package/README.md +5 -4
- package/dist/EditSurface-Bwl4S1vQ.cjs +7 -0
- package/dist/EditSurface-rKoy_ndP.js +880 -0
- package/dist/{ExplorerSplit-BAYa3WO3.js → ExplorerSplit-3WMRDA7G.js} +1 -1
- package/dist/{ExplorerSplit-DkE46pS0.cjs → ExplorerSplit-CdqEKz-I.cjs} +1 -1
- package/dist/{MultiLayout-DsxYURra.cjs → MultiLayout-BEg1X8Jx.cjs} +1 -1
- package/dist/{MultiLayout-BkhnkQs5.js → MultiLayout-Gf1xT-Le.js} +2 -2
- package/dist/{NativeScrollBar-CcNqDlO6.js → NativeScrollBar-0cpp2OIu.js} +1 -1
- package/dist/{NativeScrollBar-B57yWQVG.cjs → NativeScrollBar-idIQsvCv.cjs} +1 -1
- package/dist/{TreeLayout-DCGqVwt9.cjs → TreeLayout-DJY_WqzP.cjs} +1 -1
- package/dist/{TreeLayout-Cf2PzZEI.js → TreeLayout-DzZCgMTt.js} +2 -2
- package/dist/{index-DiLkl4dC.js → index-CJgHGeZs.js} +4 -4
- package/dist/{index-Bdve5EFS.cjs → index-bMaSoQTe.cjs} +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{merge-BIXNcrea.js → merge-BOcofJN5.js} +1 -1
- package/dist/{merge-DSfJceoQ.cjs → merge-BVk6pvO_.cjs} +1 -1
- package/docs/behavior/security.md +17 -7
- package/package.json +3 -3
- package/dist/EditSurface-D1yklbWu.js +0 -833
- package/dist/EditSurface-GxmyUeGE.cjs +0 -3
|
@@ -1,833 +0,0 @@
|
|
|
1
|
-
import { jsx as I, jsxs as Y, Fragment as Fe } from "react/jsx-runtime";
|
|
2
|
-
import { useState as ae, useRef as P, useLayoutEffect as D, useEffectEvent as me, useEffect as Ie, useImperativeHandle as Ge, useMemo as re, startTransition as Ue, useCallback as K, useId as We } from "react";
|
|
3
|
-
import { v as J, g as ce, h as Ke, u as ne, i as $e, l as Xe, j as je, k as Ce, m as Ye, n as Je, o as Qe, p as Ze, E as et, q as tt, s as rt, t as pe, w as he, A as nt, x as ge, y as ot, z as it, B as lt, G as st } from "./index-DiLkl4dC.js";
|
|
4
|
-
import { history as at, historyKeymap as ct, defaultKeymap as ut, historyField as dt, redo as ft, undo as mt, isolateHistory as pt } from "@codemirror/commands";
|
|
5
|
-
import { markdown as ht, markdownLanguage as gt } from "@codemirror/lang-markdown";
|
|
6
|
-
import { syntaxHighlighting as vt, HighlightStyle as wt } from "@codemirror/language";
|
|
7
|
-
import { highlightSelectionMatches as Et, searchKeymap as bt } from "@codemirror/search";
|
|
8
|
-
import { EditorState as qe, EditorSelection as se, StateField as St, RangeSetBuilder as xt } from "@codemirror/state";
|
|
9
|
-
import { EditorView as U, lineNumbers as yt, highlightActiveLineGutter as Tt, drawSelection as kt, highlightActiveLine as At, keymap as Lt, Decoration as oe, WidgetType as Mt } from "@codemirror/view";
|
|
10
|
-
import { tags as q } from "@lezer/highlight";
|
|
11
|
-
import { MarkdownViewer as Ot } from "@aiquants/markdown";
|
|
12
|
-
import { SOURCE_LINES_ATTRIBUTE as Re, parseSourceLines as It } from "@aiquants/markdown/source-lines";
|
|
13
|
-
import { d as Ct, f as Z, E as qt } from "./dataRoute-CObbjNxG.js";
|
|
14
|
-
import { H as Rt, c as _t, M as Nt } from "./sanitizePolicy-BWQtWhsL.js";
|
|
15
|
-
import Pt from "isomorphic-dompurify";
|
|
16
|
-
import { PanelGroup as Dt, Panel as ve, PanelResizeHandle as Bt } from "@aiquants/resize-panels";
|
|
17
|
-
import { C as Vt, F as Ht, E as zt, a as Ft, b as ee, d as Gt } from "./location-B-m9scLf.js";
|
|
18
|
-
import { u as Ut, a as Wt } from "./useSplitPersistence-Cc4tDxB4.js";
|
|
19
|
-
const _e = { history: dt }, Kt = wt.define([
|
|
20
|
-
{ tag: [q.heading1, q.heading2, q.heading3, q.heading4, q.heading5, q.heading6, q.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
|
|
21
|
-
{ tag: q.strong, fontWeight: "700" },
|
|
22
|
-
{ tag: q.emphasis, fontStyle: "italic" },
|
|
23
|
-
{ tag: q.strikethrough, textDecoration: "line-through" },
|
|
24
|
-
{ tag: q.link, color: "var(--aqmx-syntax-link)", textDecoration: "underline" },
|
|
25
|
-
{ tag: q.url, color: "var(--aqmx-syntax-url)" },
|
|
26
|
-
{ tag: q.monospace, color: "var(--aqmx-syntax-code)" },
|
|
27
|
-
{ tag: q.quote, color: "var(--aqmx-syntax-quote)" },
|
|
28
|
-
{ tag: [q.processingInstruction, q.contentSeparator, q.labelName, q.meta], color: "var(--aqmx-syntax-mark)" }
|
|
29
|
-
]), $t = U.theme({
|
|
30
|
-
"&": { height: "100%", color: "var(--aqmx-text)", backgroundColor: "var(--aqmx-surface)", fontSize: "var(--aqmx-font-size-title)" },
|
|
31
|
-
"&.cm-focused": { outline: "none" },
|
|
32
|
-
".cm-scroller": { fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', lineHeight: "var(--aqmx-line-height-prose)" },
|
|
33
|
-
".cm-content": { caretColor: "var(--aqmx-text)", paddingBlock: "var(--aqmx-space-6)" },
|
|
34
|
-
".cm-line": { paddingInline: "var(--aqmx-space-6)" },
|
|
35
|
-
"&.cm-focused .cm-cursor": { borderLeftColor: "var(--aqmx-text)" },
|
|
36
|
-
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "var(--aqmx-editor-selection)" },
|
|
37
|
-
".cm-activeLine": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
38
|
-
".cm-gutters": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-editor-gutter)", borderInlineEnd: "var(--aqmx-space-1) solid var(--aqmx-border)" },
|
|
39
|
-
".cm-activeLineGutter": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
40
|
-
".cm-searchMatch": { outline: "var(--aqmx-space-1) solid var(--aqmx-border-strong)" },
|
|
41
|
-
".cm-panels": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-text)" }
|
|
42
|
-
}), Ne = "data-aqmx-conflict-actions", Xt = oe.line({ attributes: { "data-aqmx-conflict-line": "marker" } }), jt = oe.line({ attributes: { "data-aqmx-conflict-line": "ours" } }), Yt = oe.line({ attributes: { "data-aqmx-conflict-line": "theirs" } });
|
|
43
|
-
class Jt extends Mt {
|
|
44
|
-
constructor(t, r) {
|
|
45
|
-
super(), this.index = t, this.labels = r;
|
|
46
|
-
}
|
|
47
|
-
index;
|
|
48
|
-
labels;
|
|
49
|
-
eq(t) {
|
|
50
|
-
return t.index === this.index && t.labels === this.labels;
|
|
51
|
-
}
|
|
52
|
-
toDOM(t) {
|
|
53
|
-
const r = document.createElement("div");
|
|
54
|
-
r.setAttribute(Ne, String(this.index));
|
|
55
|
-
for (const [n, s] of [
|
|
56
|
-
["ours", this.labels.useOurs],
|
|
57
|
-
["theirs", this.labels.useTheirs],
|
|
58
|
-
["both", this.labels.keepBoth]
|
|
59
|
-
]) {
|
|
60
|
-
const i = document.createElement("button");
|
|
61
|
-
i.type = "button", i.textContent = s, i.setAttribute("data-aqmx-conflict-choice", n), i.addEventListener("mousedown", (a) => a.preventDefault()), i.addEventListener("click", () => {
|
|
62
|
-
const a = j(t.state.doc)[this.index];
|
|
63
|
-
a !== void 0 && (Pe(t, a, n), t.focus());
|
|
64
|
-
}), r.append(i);
|
|
65
|
-
}
|
|
66
|
-
return r;
|
|
67
|
-
}
|
|
68
|
-
ignoreEvent() {
|
|
69
|
-
return !0;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const j = (e) => Ke(e.iterLines()), we = (e, t) => {
|
|
73
|
-
const r = new xt();
|
|
74
|
-
return j(e).forEach((n, s) => {
|
|
75
|
-
const i = e.line(n.start);
|
|
76
|
-
r.add(i.from, i.from, oe.widget({ widget: new Jt(s, t), block: !0, side: -1 }));
|
|
77
|
-
for (let a = n.start; a <= n.end; a += 1) {
|
|
78
|
-
const o = e.line(a).from, f = a === n.start || a === n.separator || a === n.end ? Xt : a < n.separator ? jt : Yt;
|
|
79
|
-
r.add(o, o, f);
|
|
80
|
-
}
|
|
81
|
-
}), r.finish();
|
|
82
|
-
}, Qt = (e) => St.define({
|
|
83
|
-
create: (t) => we(t.doc, e),
|
|
84
|
-
update: (t, r) => r.docChanged ? we(r.state.doc, e) : t,
|
|
85
|
-
provide: (t) => U.decorations.from(t)
|
|
86
|
-
}), Pe = (e, t, r) => {
|
|
87
|
-
const { doc: n } = e.state, s = (l, b) => {
|
|
88
|
-
const c = [];
|
|
89
|
-
for (let p = l; p <= b; p += 1) c.push(n.line(p).text);
|
|
90
|
-
return c;
|
|
91
|
-
}, i = s(t.start + 1, t.separator - 1), a = s(t.separator + 1, t.end - 1), o = r === "ours" ? i : r === "theirs" ? a : [...i, ...a];
|
|
92
|
-
let f = n.line(t.start).from, d = n.line(t.end).to;
|
|
93
|
-
o.length === 0 && (t.end < n.lines ? d += 1 : t.start > 1 && (f -= 1));
|
|
94
|
-
const h = o.join(`
|
|
95
|
-
`);
|
|
96
|
-
e.dispatch({ changes: { from: f, to: d, insert: h }, selection: se.cursor(f), scrollIntoView: !0, userEvent: "input.resolve" });
|
|
97
|
-
}, Zt = "input.preview", er = /^ {0,3}(`{3,}|~{3,})/u, tr = /^ {0,3}(`{3,}|~{3,})[ \t]*$/u, rr = (e, t, r) => {
|
|
98
|
-
if (!Number.isInteger(t) || t < 1 || t > e.lines) return null;
|
|
99
|
-
const n = er.exec(e.line(t).text)?.[1];
|
|
100
|
-
if (n === void 0) return null;
|
|
101
|
-
if (t === e.lines) return r === "" ? { from: e.length, to: e.length, lineBreak: !0 } : null;
|
|
102
|
-
const s = e.line(t + 1).from, i = s + r.length;
|
|
103
|
-
if (i > e.length || e.sliceString(s, i) !== r) return null;
|
|
104
|
-
if (i === e.length) return { from: s, to: i, lineBreak: !1 };
|
|
105
|
-
const a = e.lineAt(i), o = a.from === i ? tr.exec(a.text)?.[1] : void 0;
|
|
106
|
-
return o !== void 0 && o[0] === n[0] && o.length >= n.length ? { from: s, to: i, lineBreak: !1 } : null;
|
|
107
|
-
}, nr = ({ parent: e, scroll: t, text: r, saved: n, labels: s, onChange: i, onGeometry: a, onSave: o }) => {
|
|
108
|
-
let f = !1;
|
|
109
|
-
const d = [
|
|
110
|
-
U.scrollHandler.of((c, p, v) => (or(c, p.head, v, t), !0)),
|
|
111
|
-
yt(),
|
|
112
|
-
Tt(),
|
|
113
|
-
at(),
|
|
114
|
-
kt(),
|
|
115
|
-
At(),
|
|
116
|
-
Et(),
|
|
117
|
-
U.lineWrapping,
|
|
118
|
-
ht({ base: gt }),
|
|
119
|
-
vt(Kt),
|
|
120
|
-
Qt(s),
|
|
121
|
-
Lt.of([
|
|
122
|
-
{
|
|
123
|
-
key: "Mod-s",
|
|
124
|
-
preventDefault: !0,
|
|
125
|
-
run: () => (o(), !0)
|
|
126
|
-
},
|
|
127
|
-
...bt,
|
|
128
|
-
...ct,
|
|
129
|
-
...ut
|
|
130
|
-
]),
|
|
131
|
-
U.contentAttributes.of({ "aria-label": s.editor, "aria-multiline": "true" }),
|
|
132
|
-
U.updateListener.of((c) => {
|
|
133
|
-
c.docChanged && i(), (c.docChanged || c.heightChanged || c.geometryChanged) && a(c.docChanged && !f);
|
|
134
|
-
}),
|
|
135
|
-
$t
|
|
136
|
-
], h = sr(n, d) ?? qe.create({ doc: r, extensions: d }), l = new U({ state: h, parent: e }), b = (c) => {
|
|
137
|
-
f = !0;
|
|
138
|
-
try {
|
|
139
|
-
c();
|
|
140
|
-
} finally {
|
|
141
|
-
f = !1;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
return {
|
|
145
|
-
text: () => l.state.doc.toString(),
|
|
146
|
-
replaceText: (c) => {
|
|
147
|
-
const p = l.state.doc.toString();
|
|
148
|
-
if (p === c) return;
|
|
149
|
-
let v = 0;
|
|
150
|
-
const m = Math.min(p.length, c.length);
|
|
151
|
-
for (; v < m && p.charCodeAt(v) === c.charCodeAt(v); ) v += 1;
|
|
152
|
-
let E = 0;
|
|
153
|
-
for (; E < m - v && p.charCodeAt(p.length - 1 - E) === c.charCodeAt(c.length - 1 - E); ) E += 1;
|
|
154
|
-
l.dispatch({ changes: { from: v, to: p.length - E, insert: c.slice(v, c.length - E) }, userEvent: "input.replace" });
|
|
155
|
-
},
|
|
156
|
-
replaceBody: (c, p, v) => {
|
|
157
|
-
const m = rr(l.state.doc, c, p);
|
|
158
|
-
if (m === null) return !1;
|
|
159
|
-
const E = m.lineBreak ? `
|
|
160
|
-
${v}` : v;
|
|
161
|
-
return b(() => l.dispatch({ changes: { from: m.from, to: m.to, insert: E }, userEvent: Zt, annotations: pt.of("full") })), !0;
|
|
162
|
-
},
|
|
163
|
-
undo: () => b(() => mt(l)),
|
|
164
|
-
redo: () => b(() => ft(l)),
|
|
165
|
-
reveal: ({ line: c, column: p }, v) => {
|
|
166
|
-
const { doc: m } = l.state, E = m.line(Math.min(Math.max(c, 1), m.lines)), x = Math.min(E.from + p, E.to);
|
|
167
|
-
l.dispatch({ selection: se.cursor(x), effects: Ee(l, x, v, t) });
|
|
168
|
-
},
|
|
169
|
-
showLine: (c) => {
|
|
170
|
-
const { doc: p } = l.state, v = p.line(Math.min(Math.max(c, 1), p.lines)).from;
|
|
171
|
-
l.dispatch({ effects: Ee(l, v, null, t) });
|
|
172
|
-
},
|
|
173
|
-
topLine: () => {
|
|
174
|
-
const c = t.scrollerOf(l.scrollDOM), p = J(c, l.contentDOM), v = ce(c) + c.clientHeight, { documentTop: m } = l, { doc: E } = l.state;
|
|
175
|
-
let x = l.lineBlockAtHeight(Math.max(p - m, 0));
|
|
176
|
-
for (; E.lineAt(x.from).text.trim() === "" && x.to < E.length; ) {
|
|
177
|
-
const C = l.lineBlockAt(x.to + 1);
|
|
178
|
-
if (m + C.top >= v) break;
|
|
179
|
-
x = C;
|
|
180
|
-
}
|
|
181
|
-
const L = l.coordsAtPos(x.from), R = L === null ? m + x.top : L.top;
|
|
182
|
-
return { line: l.state.doc.lineAt(x.from).number, clientTop: R, offset: R - p };
|
|
183
|
-
},
|
|
184
|
-
lineSpans: (c) => {
|
|
185
|
-
const p = l.scrollDOM, v = p.scrollTop + l.documentTop - J(p, l.contentDOM), { doc: m } = l.state, E = (x) => m.line(Math.min(Math.max(x, 1), m.lines)).from;
|
|
186
|
-
return c.map(({ first: x, last: L }) => ({ top: v + l.lineBlockAt(E(x)).top, bottom: v + l.lineBlockAt(E(L)).bottom }));
|
|
187
|
-
},
|
|
188
|
-
scrollElement: l.scrollDOM,
|
|
189
|
-
focus: () => l.focus(),
|
|
190
|
-
conflicts: () => j(l.state.doc),
|
|
191
|
-
resolveAtCursor: (c) => {
|
|
192
|
-
const p = j(l.state.doc), v = l.state.doc.lineAt(l.state.selection.main.head).number, m = p.find((E) => E.end >= v);
|
|
193
|
-
return m === void 0 ? !1 : (Pe(l, m, c), !0);
|
|
194
|
-
},
|
|
195
|
-
nextConflict: () => {
|
|
196
|
-
const c = j(l.state.doc);
|
|
197
|
-
if (c[0] === void 0) return !1;
|
|
198
|
-
const v = l.state.doc.lineAt(l.state.selection.main.head).number, m = c.findIndex((R) => R.start > v), E = m < 0 ? 0 : m, x = l.state.doc.line(c[E].start).from;
|
|
199
|
-
l.dispatch({ selection: se.cursor(x), effects: U.scrollIntoView(x, { y: "center" }) });
|
|
200
|
-
const L = l.contentDOM.querySelector(`[${Ne}="${String(E)}"] button`);
|
|
201
|
-
return L instanceof HTMLElement ? L.focus({ preventScroll: !0 }) : l.focus(), !0;
|
|
202
|
-
},
|
|
203
|
-
save: () => l.state.toJSON(_e),
|
|
204
|
-
destroy: () => l.destroy()
|
|
205
|
-
};
|
|
206
|
-
}, Ee = (e, t, r, n) => {
|
|
207
|
-
const s = n.scrollerOf(e.scrollDOM), i = (r === null ? J(s, e.contentDOM) : r) - ce(s);
|
|
208
|
-
return U.scrollIntoView(t, { y: "start", yMargin: i });
|
|
209
|
-
}, or = (e, t, r, n) => {
|
|
210
|
-
const s = ir(e, t), i = n.scrollerOf(e.scrollDOM), a = ce(i), o = J(i, e.contentDOM), f = a + i.clientHeight;
|
|
211
|
-
let d = 0;
|
|
212
|
-
switch (r.y) {
|
|
213
|
-
case "start":
|
|
214
|
-
d = s.top - (a + r.yMargin);
|
|
215
|
-
break;
|
|
216
|
-
case "center":
|
|
217
|
-
d = (s.top + s.bottom) / 2 - (o + f) / 2;
|
|
218
|
-
break;
|
|
219
|
-
case "end":
|
|
220
|
-
d = s.bottom - (f - r.yMargin);
|
|
221
|
-
break;
|
|
222
|
-
default:
|
|
223
|
-
s.top < o + r.yMargin ? d = s.top - (o + r.yMargin) : s.bottom > f - r.yMargin && (d = Math.min(s.bottom - (f - r.yMargin), s.top - (o + r.yMargin)));
|
|
224
|
-
}
|
|
225
|
-
if (d !== 0 && (i.scrollTop += d), r.y === "start") return;
|
|
226
|
-
const h = lr(e, t);
|
|
227
|
-
h !== null && n.reveal(h);
|
|
228
|
-
}, ir = (e, t) => {
|
|
229
|
-
const { node: r, offset: n } = e.domAtPos(t);
|
|
230
|
-
if (r.nodeType === Node.TEXT_NODE) {
|
|
231
|
-
const a = r.ownerDocument?.createRange();
|
|
232
|
-
if (a !== void 0) {
|
|
233
|
-
a.setStart(r, n), a.setEnd(r, n);
|
|
234
|
-
const [o] = a.getClientRects();
|
|
235
|
-
if (o !== void 0 && o.height > 0) return { top: o.top, bottom: o.bottom };
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const s = e.lineBlockAt(t), i = e.documentTop + s.top;
|
|
239
|
-
return { top: i, bottom: i + s.height };
|
|
240
|
-
}, lr = (e, t) => {
|
|
241
|
-
const { node: r } = e.domAtPos(t);
|
|
242
|
-
for (let n = r instanceof Element ? r : r.parentElement; n !== null; n = n.parentElement)
|
|
243
|
-
if (n.parentElement === e.contentDOM) return n;
|
|
244
|
-
return null;
|
|
245
|
-
}, sr = (e, t) => {
|
|
246
|
-
if (e == null) return null;
|
|
247
|
-
try {
|
|
248
|
-
return qe.fromJSON(e, { extensions: t }, _e);
|
|
249
|
-
} catch {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
}, ar = 610, cr = 987, be = Object.freeze({ kind: "unavailable" }), ur = "true", dr = "false", fr = (e) => e === ur ? !0 : e === dr ? !1 : null, mr = (e) => {
|
|
253
|
-
const t = new DOMParser().parseFromString(e, "text/html"), r = [];
|
|
254
|
-
for (const n of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")) {
|
|
255
|
-
const s = n.localName === "img", i = n.getAttribute(s ? "data-asset-src" : "data-doc-path");
|
|
256
|
-
i !== null && r.push({ target: { kind: s ? "asset" : "doc", path: i }, exists: fr(n.getAttribute(s ? "data-asset-exists" : "data-doc-exists")) });
|
|
257
|
-
}
|
|
258
|
-
return r;
|
|
259
|
-
}, pr = ({ path: e, instant: t, preview: r, initial: n, onView: s }) => {
|
|
260
|
-
const i = new AbortController(), a = { asset: /* @__PURE__ */ new Map(), doc: /* @__PURE__ */ new Map() };
|
|
261
|
-
let o = n, f = null, d = !1, h = !1, l = null, b = null, c = [], p, v = !1, m, E = null;
|
|
262
|
-
const x = (S) => {
|
|
263
|
-
S.parsed === o.parsed && S.failure === o.failure && S.busy === o.busy && S.tier === o.tier || (o = S, s(S));
|
|
264
|
-
}, L = (S, y) => {
|
|
265
|
-
d || (d = !0, console.error(`[markdown-explorer] ${S}`, ...y === void 0 ? [] : [y]));
|
|
266
|
-
}, R = (S) => {
|
|
267
|
-
if (t !== null)
|
|
268
|
-
for (const { target: y, exists: u } of t.marksOf(S)) a[y.kind].set(y.path, u);
|
|
269
|
-
}, C = () => {
|
|
270
|
-
clearTimeout(m), m = void 0, E?.abort(), E = null;
|
|
271
|
-
}, V = () => {
|
|
272
|
-
b = null, c = [], clearTimeout(p), p = void 0;
|
|
273
|
-
}, B = (S, y) => {
|
|
274
|
-
x({ parsed: o.parsed, failure: S, busy: !1, tier: y });
|
|
275
|
-
}, G = () => {
|
|
276
|
-
clearTimeout(p), p = c.length === 0 ? void 0 : setTimeout(k, cr);
|
|
277
|
-
}, w = () => {
|
|
278
|
-
if (t === null || b === null) return;
|
|
279
|
-
const S = b, y = [], u = { asset: /* @__PURE__ */ new Set(), doc: /* @__PURE__ */ new Set() };
|
|
280
|
-
let T;
|
|
281
|
-
try {
|
|
282
|
-
T = t.sanitize(S.html, (M) => {
|
|
283
|
-
const z = a[M.kind].get(M.path);
|
|
284
|
-
return z === void 0 && !u[M.kind].has(M.path) && (u[M.kind].add(M.path), y.push(M)), z ?? void 0;
|
|
285
|
-
});
|
|
286
|
-
} catch (M) {
|
|
287
|
-
V(), M instanceof Rt ? B(Z("too-large"), "instant") : (L("the draft sanitizer failed", M), B(Z("failed"), "instant"));
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
c = y;
|
|
291
|
-
const O = o.parsed !== null && o.parsed.htmlContent === T && o.parsed.headings === S.headings ? o.parsed : { htmlContent: T, headings: S.headings };
|
|
292
|
-
x({ parsed: O, failure: null, busy: !1, tier: "instant" }), G();
|
|
293
|
-
}, k = () => {
|
|
294
|
-
if (p = void 0, v || b === null || c.length === 0) return;
|
|
295
|
-
v = !0;
|
|
296
|
-
const S = c;
|
|
297
|
-
r(e, b.text, i.signal).then((y) => {
|
|
298
|
-
if (v = !1, !(i.signal.aborted || !("kind" in y))) {
|
|
299
|
-
y.kind === "preview" && R(y.htmlContent);
|
|
300
|
-
for (const u of S) a[u.kind].has(u.path) || a[u.kind].set(u.path, null);
|
|
301
|
-
w();
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}, A = (S) => {
|
|
305
|
-
C(), V(), x({ ...o, busy: !0, tier: "server" });
|
|
306
|
-
const y = new AbortController();
|
|
307
|
-
E = y, m = setTimeout(() => {
|
|
308
|
-
m = void 0, r(e, S, y.signal).then((u) => {
|
|
309
|
-
if (!(y.signal.aborted || !("kind" in u))) {
|
|
310
|
-
if (E = null, u.kind === "failure") {
|
|
311
|
-
B(u.failure, "server");
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
R(u.htmlContent), x({ parsed: { htmlContent: u.htmlContent, headings: u.headings }, failure: null, busy: !1, tier: "server" });
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}, ar);
|
|
318
|
-
}, g = async (S, y) => {
|
|
319
|
-
let u;
|
|
320
|
-
try {
|
|
321
|
-
u = await S.convert({ path: e, text: y }, i.signal);
|
|
322
|
-
} catch (O) {
|
|
323
|
-
return i.signal.aborted || L("the draft converter rejected a conversion, which its contract allows only once the signal aborted", O), be;
|
|
324
|
-
}
|
|
325
|
-
const T = Ct(u);
|
|
326
|
-
return T === null ? u : (L(`the draft converter answered outside its contract: ${T}`), be);
|
|
327
|
-
}, _ = (S, y) => {
|
|
328
|
-
switch (y.kind) {
|
|
329
|
-
case "preview":
|
|
330
|
-
if (C(), y.headings.length > qt) {
|
|
331
|
-
V(), B(Z("too-large"), "instant");
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
b = { text: S, html: y.htmlContent, headings: y.headings.map(({ text: u, depth: T, id: O }) => ({ text: u, depth: T, id: O })) }, w();
|
|
335
|
-
return;
|
|
336
|
-
case "failure":
|
|
337
|
-
C(), V(), B(Z(y.failure.reason, y.failure.code), "instant");
|
|
338
|
-
return;
|
|
339
|
-
case "unavailable":
|
|
340
|
-
A(S);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
}, H = async (S) => {
|
|
344
|
-
h = !0;
|
|
345
|
-
try {
|
|
346
|
-
for (; l !== null && !i.signal.aborted; ) {
|
|
347
|
-
const y = l;
|
|
348
|
-
l = null;
|
|
349
|
-
const u = await g(S, y);
|
|
350
|
-
if (i.signal.aborted) return;
|
|
351
|
-
_(y, u);
|
|
352
|
-
}
|
|
353
|
-
} finally {
|
|
354
|
-
h = !1;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
return t !== null && t.seed !== null && R(t.seed), {
|
|
358
|
-
update: (S) => {
|
|
359
|
-
if (!(i.signal.aborted || S === f)) {
|
|
360
|
-
if (f = S, clearTimeout(p), p = void 0, t === null) {
|
|
361
|
-
A(S);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
l = S, h || H(t.converter);
|
|
365
|
-
}
|
|
366
|
-
},
|
|
367
|
-
dispose: () => {
|
|
368
|
-
i.abort(), l = null, clearTimeout(p), p = void 0, C();
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}, hr = (e, t) => _t(Pt(window), e, t, Nt), gr = (e, t) => e.flatMap((r, n) => {
|
|
372
|
-
const s = t[n];
|
|
373
|
-
return s === void 0 ? [] : [
|
|
374
|
-
{ editor: s.top, preview: r.top },
|
|
375
|
-
{ editor: s.bottom, preview: r.bottom }
|
|
376
|
-
];
|
|
377
|
-
}), W = (e, t) => {
|
|
378
|
-
const r = e[t];
|
|
379
|
-
if (r === void 0) throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length - 1)}; got ${String(t)}`);
|
|
380
|
-
return r;
|
|
381
|
-
}, vr = (e) => {
|
|
382
|
-
const t = [];
|
|
383
|
-
for (const n of e) {
|
|
384
|
-
let s = 0, i = t.length;
|
|
385
|
-
for (; s < i; ) {
|
|
386
|
-
const a = s + i >> 1;
|
|
387
|
-
W(t, a).pair.preview <= n.preview ? s = a + 1 : i = a;
|
|
388
|
-
}
|
|
389
|
-
t[s] = { pair: n, before: s === 0 ? void 0 : W(t, s - 1) };
|
|
390
|
-
}
|
|
391
|
-
const r = [];
|
|
392
|
-
for (let n = t.at(-1); n !== void 0; n = n.before) r.push(n.pair);
|
|
393
|
-
return r.reverse();
|
|
394
|
-
}, wr = (e, t) => {
|
|
395
|
-
const r = Math.max(t.editorMax, 0), n = Math.max(t.previewMax, 0), s = r - t.editorViewport, i = n - t.previewViewport, a = e.filter((d) => d.editor > 0 && d.editor < s && d.preview > 0 && d.preview < i).sort((d, h) => d.editor - h.editor || d.preview - h.preview);
|
|
396
|
-
let o = { editor: 0, preview: 0 };
|
|
397
|
-
const f = [o];
|
|
398
|
-
for (const d of vr(a))
|
|
399
|
-
d.editor > o.editor && d.preview > o.preview && (f.push(d), o = d);
|
|
400
|
-
return f.push({ editor: r, preview: n }), {
|
|
401
|
-
toPreview: (d) => Se(f, "editor", "preview", d),
|
|
402
|
-
toEditor: (d) => Se(f, "preview", "editor", d)
|
|
403
|
-
};
|
|
404
|
-
}, Se = (e, t, r, n) => {
|
|
405
|
-
const s = W(e, 0), i = W(e, e.length - 1);
|
|
406
|
-
if (Number.isNaN(n) || n <= s[t]) return s[r];
|
|
407
|
-
if (n >= i[t]) return i[r];
|
|
408
|
-
let a = 0, o = e.length - 1;
|
|
409
|
-
for (; o - a > 1; ) {
|
|
410
|
-
const h = a + o >> 1;
|
|
411
|
-
W(e, h)[t] <= n ? a = h : o = h;
|
|
412
|
-
}
|
|
413
|
-
const f = W(e, a), d = W(e, o);
|
|
414
|
-
return f[r] + (d[r] - f[r]) * (n - f[t]) / (d[t] - f[t]);
|
|
415
|
-
}, Er = 610, xe = 89, ye = 0.5, br = ({ editor: e, preview: t, previewBlocks: r, editorSpans: n, requestFrame: s, cancelFrame: i, now: a }) => {
|
|
416
|
-
let o = "editor", f = 0, d = null, h = null, l = !1, b = null, c = null;
|
|
417
|
-
const p = { editor: 0, preview: 0 }, v = { editor: null, preview: null };
|
|
418
|
-
let m = null, E = () => {
|
|
419
|
-
};
|
|
420
|
-
const x = (g) => {
|
|
421
|
-
d !== null && g !== d || (o = g, f = a() + Er);
|
|
422
|
-
}, L = (g, _) => {
|
|
423
|
-
g !== o && d === null && a() >= f && !R(g, _) && (o = g), w();
|
|
424
|
-
}, R = (g, _) => {
|
|
425
|
-
const H = v[g];
|
|
426
|
-
return a() < p[g] || H !== null && Math.abs(_.position() - H) < ye;
|
|
427
|
-
}, C = e.onScroll(() => L("editor", e)), V = e.onIntent(() => x("editor")), B = () => {
|
|
428
|
-
const g = t();
|
|
429
|
-
return g !== m && (E(), m = g, E = g === null ? () => {
|
|
430
|
-
} : G(g)), g;
|
|
431
|
-
}, G = (g) => {
|
|
432
|
-
const _ = g.onScroll(() => L("preview", g)), H = g.onIntent(() => x("preview"));
|
|
433
|
-
return () => {
|
|
434
|
-
_(), H();
|
|
435
|
-
};
|
|
436
|
-
}, w = () => {
|
|
437
|
-
!l && h === null && (h = s(k));
|
|
438
|
-
}, k = () => {
|
|
439
|
-
h = null;
|
|
440
|
-
const g = B();
|
|
441
|
-
g !== null && (b ??= r(), c ??= wr(gr(b, n(b)), { editorMax: e.max(), previewMax: g.max(), editorViewport: e.viewport(), previewViewport: g.viewport() }), o === "editor" ? A(g, "preview", c.toPreview(e.position())) : A(e, "editor", c.toEditor(g.position())));
|
|
442
|
-
}, A = (g, _, H) => {
|
|
443
|
-
if (Math.abs(g.position() - H) < ye) {
|
|
444
|
-
v[_] = g.position();
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
p[_] = a() + xe, v[_] = g.scrollTo(H);
|
|
448
|
-
};
|
|
449
|
-
return w(), {
|
|
450
|
-
editorChanged: (g) => {
|
|
451
|
-
c = null, g && x("editor"), w();
|
|
452
|
-
},
|
|
453
|
-
previewChanged: () => {
|
|
454
|
-
b = null, c = null, p.preview = a() + xe, w();
|
|
455
|
-
},
|
|
456
|
-
showAlone: (g) => {
|
|
457
|
-
d = g, !(g === null || g === o) && (o = g, f = 0, w());
|
|
458
|
-
},
|
|
459
|
-
dispose: () => {
|
|
460
|
-
l = !0, h !== null && i(h), h = null, C(), V(), E();
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
}, Te = Object.freeze(["wheel", "pointerdown", "keydown", "focusin"]), De = (e) => ({
|
|
464
|
-
position: () => e.scrollTop,
|
|
465
|
-
max: () => Math.max(e.scrollHeight - e.clientHeight, 0),
|
|
466
|
-
viewport: () => e.clientHeight,
|
|
467
|
-
scrollTo: (t) => (e.scrollTo({ top: t, behavior: "instant" }), e.scrollTop),
|
|
468
|
-
onScroll: (t) => (e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t)),
|
|
469
|
-
onIntent: (t) => {
|
|
470
|
-
for (const r of Te) e.addEventListener(r, t, { capture: !0, passive: !0 });
|
|
471
|
-
return () => {
|
|
472
|
-
for (const r of Te) e.removeEventListener(r, t, { capture: !0 });
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
}), X = "[data-aqmd-scroll-container]", Sr = "[data-aqmd-content]", xr = `[${Re}]`, yr = Object.freeze(["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"]), Be = (e, t) => {
|
|
476
|
-
const r = Ye(e.peek(t));
|
|
477
|
-
return r !== null && r.document.kind === "markdown" ? { htmlContent: r.document.htmlContent, headings: r.document.headings } : null;
|
|
478
|
-
}, Tr = (e, t, r, n, s) => {
|
|
479
|
-
if (r === void 0) return null;
|
|
480
|
-
let i;
|
|
481
|
-
try {
|
|
482
|
-
i = hr(e, t);
|
|
483
|
-
} catch (a) {
|
|
484
|
-
return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview", a), null;
|
|
485
|
-
}
|
|
486
|
-
return { converter: r, sanitize: i, marksOf: mr, seed: Be(n, s)?.htmlContent ?? null };
|
|
487
|
-
}, kr = (e) => {
|
|
488
|
-
const t = [];
|
|
489
|
-
let r = null;
|
|
490
|
-
for (const n of e.querySelectorAll(xr)) {
|
|
491
|
-
const s = It(n.getAttribute(Re));
|
|
492
|
-
if (s === null || n.getClientRects().length === 0) continue;
|
|
493
|
-
r ??= e.scrollTop - J(e, n);
|
|
494
|
-
const { top: i, bottom: a } = n.getBoundingClientRect();
|
|
495
|
-
t.push({ first: s.first, last: s.last, top: r + i, bottom: r + a });
|
|
496
|
-
}
|
|
497
|
-
return t;
|
|
498
|
-
}, Ar = ({ path: e, readDraft: t, viewer: r, spreadsheetEditor: n, concealed: s, onEditAt: i, onLayout: a, handleRef: o }) => {
|
|
499
|
-
const { config: f, data: d, documents: h, draftConverter: l, labels: b } = ne(), [c, p] = ae(() => ({ parsed: Be(h, e), failure: null, busy: !0, tier: l === void 0 ? "server" : "instant" })), v = P(null), m = P(null), E = P(c);
|
|
500
|
-
D(() => {
|
|
501
|
-
E.current = c;
|
|
502
|
-
});
|
|
503
|
-
const x = me(() => t());
|
|
504
|
-
Ie(() => {
|
|
505
|
-
const w = Tr(f.iframeHosts, f.dataPath, l, h, e), k = pr({ path: e, instant: w, preview: d.preview, initial: E.current, onView: (A) => Ue(() => p(A)) });
|
|
506
|
-
return m.current = k, k.update(x()), () => {
|
|
507
|
-
k.dispose(), m.current = null;
|
|
508
|
-
};
|
|
509
|
-
}, [f, d, h, l, e]);
|
|
510
|
-
const L = me(() => a());
|
|
511
|
-
D(() => {
|
|
512
|
-
c.parsed !== null && L();
|
|
513
|
-
}, [c.parsed]);
|
|
514
|
-
const R = c.parsed !== null;
|
|
515
|
-
D(() => {
|
|
516
|
-
const w = R ? v.current?.querySelector(X) : null;
|
|
517
|
-
if (!(w instanceof HTMLElement)) return;
|
|
518
|
-
w.tabIndex = 0;
|
|
519
|
-
const k = new ResizeObserver(() => L());
|
|
520
|
-
k.observe(w);
|
|
521
|
-
const A = w.querySelector(Sr);
|
|
522
|
-
return A !== null && k.observe(A), () => k.disconnect();
|
|
523
|
-
}, [R]);
|
|
524
|
-
const C = P(null);
|
|
525
|
-
Ge(
|
|
526
|
-
o,
|
|
527
|
-
() => ({
|
|
528
|
-
draft: (w) => {
|
|
529
|
-
m.current?.update(w);
|
|
530
|
-
},
|
|
531
|
-
scrollPort: () => {
|
|
532
|
-
const w = v.current?.querySelector(X);
|
|
533
|
-
return w instanceof HTMLElement ? (C.current?.scroller !== w && (C.current = { scroller: w, port: De(w) }), C.current.port) : null;
|
|
534
|
-
},
|
|
535
|
-
blocks: () => {
|
|
536
|
-
const w = v.current?.querySelector(X);
|
|
537
|
-
return w instanceof HTMLElement ? kr(w) : [];
|
|
538
|
-
},
|
|
539
|
-
focus: () => {
|
|
540
|
-
const w = v.current?.querySelector(X);
|
|
541
|
-
w instanceof HTMLElement && w.focus({ preventScroll: !0 });
|
|
542
|
-
},
|
|
543
|
-
anchor: (w) => {
|
|
544
|
-
const k = v.current, A = k?.querySelector(X);
|
|
545
|
-
return k === null || !(A instanceof HTMLElement) ? null : je(k, w(A));
|
|
546
|
-
},
|
|
547
|
-
place: ({ line: w, clientTop: k }, A) => {
|
|
548
|
-
const g = v.current, _ = g === null ? null : $e(g, w);
|
|
549
|
-
_ !== null && (A(_).scrollTop += Xe(_, w) - k);
|
|
550
|
-
}
|
|
551
|
-
}),
|
|
552
|
-
[]
|
|
553
|
-
);
|
|
554
|
-
const V = (w) => {
|
|
555
|
-
const k = v.current, { target: A } = w;
|
|
556
|
-
if (i === void 0 || k === null || !(A instanceof Element) || !Je(A)) return;
|
|
557
|
-
const g = Qe(A, k, k.ownerDocument.getSelection());
|
|
558
|
-
g !== null && i(g);
|
|
559
|
-
}, B = re(() => ({ ...r, showToc: !1, showStyle: !1, showAlign: !1, renderScrollBar: void 0, spreadsheetEditor: n }), [r, n]), G = re(
|
|
560
|
-
() => c.parsed === null ? null : /* @__PURE__ */ I("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ I(Ot, { ...B, parseResult: c.parsed, content: null }) }),
|
|
561
|
-
[B, c.parsed]
|
|
562
|
-
);
|
|
563
|
-
return /* @__PURE__ */ Y(
|
|
564
|
-
"section",
|
|
565
|
-
{
|
|
566
|
-
ref: v,
|
|
567
|
-
className: "aqmx-edit-preview",
|
|
568
|
-
"aria-label": b.previewRegion,
|
|
569
|
-
"aria-busy": c.busy,
|
|
570
|
-
inert: s !== null,
|
|
571
|
-
hidden: s === "removed",
|
|
572
|
-
"data-aqmx-preview-tier": c.tier,
|
|
573
|
-
"data-testid": "markdown-explorer-edit-preview",
|
|
574
|
-
onDoubleClick: i === void 0 ? void 0 : V,
|
|
575
|
-
children: [
|
|
576
|
-
c.failure === null ? null : /* @__PURE__ */ I("p", { className: "aqmx-callout aqmx-document-notice", "data-aqmx-tone": "warning", "data-testid": "markdown-explorer-edit-preview-failure", children: b.previewFailed(Ce(b, c.failure.reason)) }),
|
|
577
|
-
G ?? (c.failure === null ? /* @__PURE__ */ I("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-preview-skeleton", children: yr.map((w) => /* @__PURE__ */ I("span", {}, w)) }) : null),
|
|
578
|
-
c.busy ? /* @__PURE__ */ I("p", { className: "aqmx-sr-only", children: b.previewUpdating }) : null
|
|
579
|
-
]
|
|
580
|
-
}
|
|
581
|
-
);
|
|
582
|
-
}, ke = "data-aqmx-edit-split", le = "--aqmx-edit-share", Ae = "--aqmx-edit-gutter", Lr = "data-aqmx-edit-split-probe", Mr = "aqmx-edit-split", Or = "aqmx-edit-editor", Ir = "aqmx-edit-preview", Le = { value: Ft, unit: "percentage" }, Me = { value: zt, unit: "percentage" }, Oe = (e) => {
|
|
583
|
-
if (e.length !== 2) return null;
|
|
584
|
-
const [t = 0, r = 0] = e, n = t + r;
|
|
585
|
-
return n > 0 ? t / n * 100 : null;
|
|
586
|
-
}, te = (e) => {
|
|
587
|
-
const t = e.current?.parentElement;
|
|
588
|
-
if (t == null) throw new Error("[markdown-explorer] the edit split is not mounted in its surface");
|
|
589
|
-
return t;
|
|
590
|
-
}, Cr = (e, t, r) => {
|
|
591
|
-
const [n, s] = ae(null);
|
|
592
|
-
return D(() => {
|
|
593
|
-
const i = e.current, a = t.current;
|
|
594
|
-
if (i === null || a === null) throw new Error("[markdown-explorer] the edit split is not mounted");
|
|
595
|
-
const o = { frame: i.getBoundingClientRect().width, measure: a.getBoundingClientRect().width }, f = () => {
|
|
596
|
-
o.frame > 0 && o.measure > 0 && s(Gt(o.frame, o.measure, r));
|
|
597
|
-
};
|
|
598
|
-
f();
|
|
599
|
-
const d = new ResizeObserver((h) => {
|
|
600
|
-
for (const l of h) {
|
|
601
|
-
const [b] = l.borderBoxSize;
|
|
602
|
-
b !== void 0 && (l.target === i && (o.frame = b.inlineSize), l.target === a && (o.measure = b.inlineSize));
|
|
603
|
-
}
|
|
604
|
-
f();
|
|
605
|
-
});
|
|
606
|
-
return d.observe(i), d.observe(a), () => d.disconnect();
|
|
607
|
-
}, [e, t, r]), n;
|
|
608
|
-
}, qr = ({ editorId: e }) => {
|
|
609
|
-
const { edits: t, labels: r } = ne(), n = P(null), s = P(null), i = Ut() ? Vt : Ht, a = Cr(n, s, i), [o] = ae(() => t.editorShare());
|
|
610
|
-
D(() => {
|
|
611
|
-
const h = te(n);
|
|
612
|
-
return h.style.setProperty(Ae, `${String(i)}px`), () => {
|
|
613
|
-
h.style.removeProperty(Ae);
|
|
614
|
-
};
|
|
615
|
-
}, [i]), D(() => {
|
|
616
|
-
const h = te(n);
|
|
617
|
-
return h.style.setProperty(le, `${String(o)}%`), () => {
|
|
618
|
-
h.style.removeProperty(le);
|
|
619
|
-
};
|
|
620
|
-
}, [o]), D(() => {
|
|
621
|
-
if (a === null) return;
|
|
622
|
-
const h = te(n);
|
|
623
|
-
return h.setAttribute(ke, a), () => h.removeAttribute(ke);
|
|
624
|
-
}, [a]);
|
|
625
|
-
const f = Wt(
|
|
626
|
-
K(
|
|
627
|
-
(h) => {
|
|
628
|
-
const l = Oe(h);
|
|
629
|
-
l !== null && t.setEditorShare(l);
|
|
630
|
-
},
|
|
631
|
-
[t]
|
|
632
|
-
)
|
|
633
|
-
), d = K(
|
|
634
|
-
(h, l) => {
|
|
635
|
-
const b = Oe(h);
|
|
636
|
-
b !== null && te(n).style.setProperty(le, `${String(b)}%`), f.layoutChanged(h, l);
|
|
637
|
-
},
|
|
638
|
-
[f]
|
|
639
|
-
);
|
|
640
|
-
return /* @__PURE__ */ Y("div", { ref: n, className: "aqmx-edit-split", "data-testid": "markdown-explorer-edit-split", children: [
|
|
641
|
-
/* @__PURE__ */ I("span", { ref: s, className: "aqmx-edit-split-probe", "aria-hidden": "true", [Lr]: "" }),
|
|
642
|
-
a === null ? null : /* @__PURE__ */ Y(Dt, { id: Mr, direction: a === "beside" ? "horizontal" : "vertical", onLayout: d, className: "aqmx-edit-split-group", children: [
|
|
643
|
-
/* @__PURE__ */ I(ve, { id: Or, defaultSize: { value: o, unit: "percentage" }, minSize: Le, maxSize: Me, contentOverflow: "hidden" }),
|
|
644
|
-
/* @__PURE__ */ I(
|
|
645
|
-
Bt,
|
|
646
|
-
{
|
|
647
|
-
thickness: i,
|
|
648
|
-
indicator: { visible: !0, thickness: ee.gripThickness, length: ee.gripLength, barThickness: ee.barThickness, barLength: ee.barLength },
|
|
649
|
-
title: r.editViewSplitResize,
|
|
650
|
-
"aria-label": r.editViewSplitResize,
|
|
651
|
-
"aria-controls": e,
|
|
652
|
-
onDragging: f.draggingChanged,
|
|
653
|
-
className: "aqmx-split-handle aqmx-edit-split-handle"
|
|
654
|
-
}
|
|
655
|
-
),
|
|
656
|
-
/* @__PURE__ */ I(ve, { id: Ir, defaultSize: { value: 100 - o, unit: "percentage" }, minSize: Le, maxSize: Me, contentOverflow: "hidden" })
|
|
657
|
-
] })
|
|
658
|
-
] });
|
|
659
|
-
}, Rr = 144, _r = "[data-aqmd-spreadsheet-fullscreen]", Nr = Object.freeze(["e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"]), Pr = (e) => {
|
|
660
|
-
if (typeof e != "object" || e === null) return !1;
|
|
661
|
-
const { generation: t, topLine: r } = e;
|
|
662
|
-
return "state" in e && typeof t == "number" && typeof r == "number";
|
|
663
|
-
}, Dr = (e) => {
|
|
664
|
-
e.stopPropagation();
|
|
665
|
-
}, nn = (e) => {
|
|
666
|
-
const { path: t, name: r, session: n } = e, { edits: s, labels: i, announcer: a } = ne(), { phase: o } = n, f = K(() => s.retry(t), [s, t]);
|
|
667
|
-
switch (Ie(() => {
|
|
668
|
-
o.kind === "failed" && a.announce(i.documentFailed(r, Ce(i, o.failure.reason)));
|
|
669
|
-
}, [o, a, i, r]), o.kind) {
|
|
670
|
-
case "opening":
|
|
671
|
-
return /* @__PURE__ */ Y(Fe, { children: [
|
|
672
|
-
/* @__PURE__ */ I("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-skeleton", children: Nr.map((d) => /* @__PURE__ */ I("span", {}, d)) }),
|
|
673
|
-
/* @__PURE__ */ I("p", { className: "aqmx-sr-only", children: i.editLoading })
|
|
674
|
-
] });
|
|
675
|
-
case "grant":
|
|
676
|
-
return /* @__PURE__ */ I("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ I(et, { href: o.href, onRetry: f, testId: "markdown-explorer-edit-grant" }) });
|
|
677
|
-
case "failed":
|
|
678
|
-
return /* @__PURE__ */ I("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ I(Ze, { failure: o.failure, alert: !1, onRetry: f, testId: "markdown-explorer-edit-failure" }) });
|
|
679
|
-
case "editing":
|
|
680
|
-
return /* @__PURE__ */ I(Br, { ...e });
|
|
681
|
-
}
|
|
682
|
-
}, Br = ({ path: e, name: t, session: r, layout: n, viewer: s, region: i, paneScroll: a }) => {
|
|
683
|
-
const { edits: o, labels: f } = ne(), d = P(null), h = We(), l = P(null), b = P(null), c = P(null), p = n === "fill", v = tt(), m = rt(r, v, p), E = m !== "editor" || r.previewPrepared, x = E && p, L = P({ layout: n, region: i, paneScroll: a });
|
|
684
|
-
D(() => {
|
|
685
|
-
L.current = { layout: n, region: i, paneScroll: a };
|
|
686
|
-
});
|
|
687
|
-
const R = P(r.generation);
|
|
688
|
-
D(() => {
|
|
689
|
-
R.current = r.generation;
|
|
690
|
-
});
|
|
691
|
-
const C = P({ view: m, previewMounted: E });
|
|
692
|
-
D(() => {
|
|
693
|
-
C.current = { view: m, previewMounted: E };
|
|
694
|
-
});
|
|
695
|
-
const V = P(null), B = P(null), G = P(!1), w = re(() => ({ editor: f.editorLabel(t), useOurs: f.conflictUseOurs, useTheirs: f.conflictUseTheirs, keepBoth: f.conflictKeepBoth }), [f, t]), k = K((u) => {
|
|
696
|
-
const { region: T, paneScroll: O } = L.current, M = T();
|
|
697
|
-
return M === null ? u : O.scrollerOf(M, u);
|
|
698
|
-
}, []);
|
|
699
|
-
D(() => {
|
|
700
|
-
const u = d.current, T = o.draft(e);
|
|
701
|
-
if (u === null || T === null) return;
|
|
702
|
-
const O = o.editorState.get(e), M = Pr(O) && O.generation === R.current ? O : null;
|
|
703
|
-
let z = null, $ = null;
|
|
704
|
-
const ie = () => {
|
|
705
|
-
z !== null && clearTimeout(z), z = null, $ !== null && o.setDraft(e, $.text());
|
|
706
|
-
}, F = nr({
|
|
707
|
-
parent: u,
|
|
708
|
-
scroll: {
|
|
709
|
-
scrollerOf: (N) => {
|
|
710
|
-
const { layout: Q, region: He, paneScroll: ze } = L.current, fe = He();
|
|
711
|
-
return Q === "fill" || fe === null ? N : ze.scrollerOf(fe, N);
|
|
712
|
-
},
|
|
713
|
-
reveal: (N) => L.current.paneScroll.reveal(N)
|
|
714
|
-
},
|
|
715
|
-
text: T,
|
|
716
|
-
saved: M === null ? void 0 : M.state,
|
|
717
|
-
labels: w,
|
|
718
|
-
onGeometry: (N) => c.current?.editorChanged(N),
|
|
719
|
-
onChange: () => {
|
|
720
|
-
z ??= setTimeout(ie, Rr), C.current.previewMounted && $ !== null && b.current?.draft($.text());
|
|
721
|
-
},
|
|
722
|
-
onSave: () => {
|
|
723
|
-
o.save(e);
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
$ = F, l.current = F;
|
|
727
|
-
const ue = () => {
|
|
728
|
-
const N = F.topLine();
|
|
729
|
-
return { line: N.line, clientTop: N.clientTop };
|
|
730
|
-
}, de = () => b.current?.anchor(k) ?? null, Ve = o.bindEditor(e, {
|
|
731
|
-
flush: ie,
|
|
732
|
-
adopt: (N) => F.replaceText(N),
|
|
733
|
-
returnPoint: () => {
|
|
734
|
-
const N = C.current.view === "preview" && L.current.layout === "content" ? de() : null;
|
|
735
|
-
return N === null ? ue() : { line: N.lines.first, clientTop: N.clientTop };
|
|
736
|
-
},
|
|
737
|
-
nextConflict: () => C.current.view !== "preview" ? F.nextConflict() : F.conflicts().length === 0 ? !1 : (G.current = !0, o.setView(e, "editor"), !0),
|
|
738
|
-
beforeView: (N) => {
|
|
739
|
-
if (L.current.layout === "fill") return;
|
|
740
|
-
if (N === "preview") {
|
|
741
|
-
V.current = { to: "preview", point: ue() };
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
const Q = de();
|
|
745
|
-
V.current = Q === null ? null : { to: "editor", anchor: Q };
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
return M !== null && F.showLine(M.topLine), () => {
|
|
749
|
-
ie(), o.editorState.set(e, { state: F.save(), generation: R.current, topLine: F.topLine().line }), Ve(), F.destroy(), $ = null, l.current = null;
|
|
750
|
-
};
|
|
751
|
-
}, [o, e, w, k]);
|
|
752
|
-
const { request: A } = r;
|
|
753
|
-
D(() => {
|
|
754
|
-
const u = l.current, T = o.draft(e);
|
|
755
|
-
u === null || T === null || A === null || (A.anchor !== null && u.reveal(pe(T, A.anchor), A.anchor.clientTop), u.focus(), o.consumeRequest(e));
|
|
756
|
-
}, [o, e, A, w]), D(() => {
|
|
757
|
-
m !== "editor" && !r.previewPrepared && o.preparePreview(e);
|
|
758
|
-
}, [o, e, m, r.previewPrepared]), D(() => {
|
|
759
|
-
const u = V.current, T = B.current, O = G.current;
|
|
760
|
-
V.current = null, B.current = null, G.current = !1;
|
|
761
|
-
const M = l.current;
|
|
762
|
-
if (u?.to === "preview") b.current?.place(u.point, k);
|
|
763
|
-
else if (u?.to === "editor" && M !== null) {
|
|
764
|
-
const z = o.draft(e);
|
|
765
|
-
z !== null && M.reveal(pe(z, u.anchor), u.anchor.clientTop);
|
|
766
|
-
}
|
|
767
|
-
O ? M?.nextConflict() : T === "editor" ? M?.focus() : T === "preview" && b.current?.focus();
|
|
768
|
-
}, [o, e, m, k]);
|
|
769
|
-
const g = re(
|
|
770
|
-
() => ({
|
|
771
|
-
write: ({ fenceLine: u, expected: T, text: O }) => l.current?.replaceBody(u, T, O) === !0,
|
|
772
|
-
undo: () => l.current?.undo(),
|
|
773
|
-
redo: () => l.current?.redo()
|
|
774
|
-
}),
|
|
775
|
-
[]
|
|
776
|
-
), _ = K(() => {
|
|
777
|
-
const u = l.current;
|
|
778
|
-
if (u === null) throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");
|
|
779
|
-
return u.text();
|
|
780
|
-
}, []);
|
|
781
|
-
D(() => {
|
|
782
|
-
const u = l.current;
|
|
783
|
-
if (!x || u === null) return;
|
|
784
|
-
const T = br({
|
|
785
|
-
editor: De(u.scrollElement),
|
|
786
|
-
preview: () => b.current?.scrollPort() ?? null,
|
|
787
|
-
previewBlocks: () => b.current?.blocks() ?? [],
|
|
788
|
-
editorSpans: (O) => u.lineSpans(O),
|
|
789
|
-
requestFrame: (O) => requestAnimationFrame(O),
|
|
790
|
-
cancelFrame: (O) => cancelAnimationFrame(O),
|
|
791
|
-
now: () => performance.now()
|
|
792
|
-
});
|
|
793
|
-
return T.showAlone(he(C.current.view)), c.current = T, () => {
|
|
794
|
-
T.dispose(), c.current = null;
|
|
795
|
-
};
|
|
796
|
-
}, [x, o, e, w]), D(() => {
|
|
797
|
-
c.current?.showAlone(he(m));
|
|
798
|
-
}, [m]);
|
|
799
|
-
const H = K(() => c.current?.previewChanged(), []), S = K((u) => o.start(e, u), [o, e]);
|
|
800
|
-
return (
|
|
801
|
-
/* @__PURE__ */ Y("div", { className: "aqmx-edit", "data-aqmx-edit-layout": n, "data-aqmx-edit-view": m, "data-testid": "markdown-explorer-edit", onKeyDown: (u) => {
|
|
802
|
-
if (u.target instanceof Element && u.target.closest(_r) !== null) return;
|
|
803
|
-
if (u.key === "Escape") {
|
|
804
|
-
ge(u);
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
if (!ot(u.nativeEvent, it(navigator.platform))) return;
|
|
808
|
-
ge(u);
|
|
809
|
-
const T = st(m);
|
|
810
|
-
B.current = T, lt(o, e, T, p);
|
|
811
|
-
}, onDoubleClick: Dr, children: [
|
|
812
|
-
/* @__PURE__ */ I("div", { ref: d, id: h, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", inert: m === "preview", hidden: m === "preview" && !p, ...nt }),
|
|
813
|
-
m === "split" ? /* @__PURE__ */ I(qr, { editorId: h }) : null,
|
|
814
|
-
E ? /* @__PURE__ */ I(
|
|
815
|
-
Ar,
|
|
816
|
-
{
|
|
817
|
-
path: e,
|
|
818
|
-
readDraft: _,
|
|
819
|
-
viewer: s,
|
|
820
|
-
spreadsheetEditor: g,
|
|
821
|
-
concealed: m !== "editor" ? null : p ? "overlay" : "removed",
|
|
822
|
-
onEditAt: m === "preview" ? S : void 0,
|
|
823
|
-
onLayout: H,
|
|
824
|
-
handleRef: b
|
|
825
|
-
}
|
|
826
|
-
) : null
|
|
827
|
-
] })
|
|
828
|
-
);
|
|
829
|
-
};
|
|
830
|
-
export {
|
|
831
|
-
Rr as DRAFT_WRITE_INTERVAL_MS,
|
|
832
|
-
nn as default
|
|
833
|
-
};
|