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