@aiquants/markdown-explorer 0.10.0 → 0.12.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 +26 -1
- package/README.md +66 -6
- package/dist/EditSurface-BTAhzvHi.js +509 -0
- package/dist/EditSurface-Dfj6Sxxb.cjs +2 -0
- package/dist/ExplorerSplit-DekOjAUZ.cjs +1 -0
- package/dist/{ExplorerSplit-D0zf7Cr_.js → ExplorerSplit-MPHjw3nW.js} +251 -248
- package/dist/{MultiLayout-Jy9BKofx.js → MultiLayout-DtSW4rEQ.js} +4 -4
- package/dist/{MultiLayout-Bq10p3a3.cjs → MultiLayout-HMzVDYWq.cjs} +1 -1
- package/dist/{NativeScrollBar-Dt6xH5Mb.cjs → NativeScrollBar-B0AkVF3E.cjs} +1 -1
- package/dist/{NativeScrollBar-CyiyL47o.js → NativeScrollBar-CNQr7JY1.js} +1 -1
- package/dist/{TreeLayout-8pRo1ANN.js → TreeLayout-CJO9tOPq.js} +3 -3
- package/dist/{TreeLayout-kVWFEKJD.cjs → TreeLayout-_XQR-9tV.cjs} +1 -1
- package/dist/client/MarkdownExplorer.d.cts +3 -2
- package/dist/client/MarkdownExplorer.d.ts +3 -2
- package/dist/core/contracts.d.cts +17 -0
- package/dist/core/contracts.d.ts +17 -0
- package/dist/core/labels.d.cts +2 -0
- package/dist/core/labels.d.ts +2 -0
- package/dist/core/treeSettings.d.cts +2 -1
- package/dist/core/treeSettings.d.ts +2 -1
- package/dist/dataRoute-CH3yOKR0.cjs +1 -0
- package/dist/dataRoute-Pm_0ue_4.js +279 -0
- package/dist/index-DpIVKG8Y.cjs +13 -0
- package/dist/{index-CfcJEnrC.js → index-o6OpR4ND.js} +967 -907
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/location-BUNWJ4eB.cjs +1 -0
- package/dist/{location-Dc1qNEGm.js → location-DWd6SQhN.js} +123 -112
- package/dist/{merge-D0aGvFKC.cjs → merge-Bs7o3GyP.cjs} +1 -1
- package/dist/{merge-SRCxtHk2.js → merge-DDJaJmMU.js} +1 -1
- package/dist/sanitizePolicy-BfUlXI5E.cjs +1 -0
- package/dist/sanitizePolicy-djLC3fRN.js +96 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +143 -226
- package/dist/server.cjs +1 -1
- package/dist/server.js +548 -540
- package/docs/behavior/dom-hooks.md +2 -2
- package/docs/behavior/localization.md +1 -0
- package/docs/behavior/security.md +2 -0
- package/package.json +3 -3
- package/dist/EditSurface-1Jf0CG-f.js +0 -371
- package/dist/EditSurface-B-l3Do_C.cjs +0 -2
- package/dist/ExplorerSplit-WX8afxrQ.cjs +0 -1
- package/dist/dataRoute-8pyILcjL.cjs +0 -1
- package/dist/dataRoute-Csl1WBDz.js +0 -278
- package/dist/index-sNJrKoGN.cjs +0 -13
- package/dist/location-CRYkEWiC.cjs +0 -1
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { jsx as q, jsxs as $, Fragment as ue } from "react/jsx-runtime";
|
|
2
|
+
import { useState as fe, useRef as D, useLayoutEffect as H, useEffectEvent as ee, useEffect as Y, useImperativeHandle as me, useMemo as G, startTransition as he, useCallback as U } from "react";
|
|
3
|
+
import { v as z, f as J, g as pe, u as Q, h as se, l as ge, i as ve, j as be, F as xe, E as ke, k as we, p as Ee, A as ye, m as Se } from "./index-o6OpR4ND.js";
|
|
4
|
+
import { history as qe, historyKeymap as Le, defaultKeymap as Te, historyField as Me } from "@codemirror/commands";
|
|
5
|
+
import { markdown as Ae, markdownLanguage as Oe } from "@codemirror/lang-markdown";
|
|
6
|
+
import { syntaxHighlighting as Ce, HighlightStyle as Ie } from "@codemirror/language";
|
|
7
|
+
import { highlightSelectionMatches as Re, searchKeymap as De } from "@codemirror/search";
|
|
8
|
+
import { EditorState as ae, EditorSelection as X, StateField as Ne, RangeSetBuilder as _e } from "@codemirror/state";
|
|
9
|
+
import { EditorView as N, lineNumbers as He, highlightActiveLineGutter as Fe, drawSelection as Ve, highlightActiveLine as Pe, keymap as Be, Decoration as K, WidgetType as ze } from "@codemirror/view";
|
|
10
|
+
import { tags as y } from "@lezer/highlight";
|
|
11
|
+
import { MarkdownViewer as Ke } from "@aiquants/markdown";
|
|
12
|
+
import { d as We, f as B, E as je } from "./dataRoute-Pm_0ue_4.js";
|
|
13
|
+
import { H as Ge, c as Ue, M as Xe } from "./sanitizePolicy-djLC3fRN.js";
|
|
14
|
+
import $e from "isomorphic-dompurify";
|
|
15
|
+
const ie = { history: Me }, Ye = Ie.define([
|
|
16
|
+
{ tag: [y.heading1, y.heading2, y.heading3, y.heading4, y.heading5, y.heading6, y.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
|
|
17
|
+
{ tag: y.strong, fontWeight: "700" },
|
|
18
|
+
{ tag: y.emphasis, fontStyle: "italic" },
|
|
19
|
+
{ tag: y.strikethrough, textDecoration: "line-through" },
|
|
20
|
+
{ tag: y.link, color: "var(--aqmx-syntax-link)", textDecoration: "underline" },
|
|
21
|
+
{ tag: y.url, color: "var(--aqmx-syntax-url)" },
|
|
22
|
+
{ tag: y.monospace, color: "var(--aqmx-syntax-code)" },
|
|
23
|
+
{ tag: y.quote, color: "var(--aqmx-syntax-quote)" },
|
|
24
|
+
{ tag: [y.processingInstruction, y.contentSeparator, y.labelName, y.meta], color: "var(--aqmx-syntax-mark)" }
|
|
25
|
+
]), Je = N.theme({
|
|
26
|
+
"&": { height: "100%", color: "var(--aqmx-text)", backgroundColor: "var(--aqmx-surface)", fontSize: "var(--aqmx-font-size-title)" },
|
|
27
|
+
"&.cm-focused": { outline: "none" },
|
|
28
|
+
".cm-scroller": { fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', lineHeight: "var(--aqmx-line-height-prose)" },
|
|
29
|
+
".cm-content": { caretColor: "var(--aqmx-text)", paddingBlock: "var(--aqmx-space-6)" },
|
|
30
|
+
".cm-line": { paddingInline: "var(--aqmx-space-6)" },
|
|
31
|
+
"&.cm-focused .cm-cursor": { borderLeftColor: "var(--aqmx-text)" },
|
|
32
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "var(--aqmx-editor-selection)" },
|
|
33
|
+
".cm-activeLine": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
34
|
+
".cm-gutters": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-editor-gutter)", borderInlineEnd: "var(--aqmx-space-1) solid var(--aqmx-border)" },
|
|
35
|
+
".cm-activeLineGutter": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
36
|
+
".cm-searchMatch": { outline: "var(--aqmx-space-1) solid var(--aqmx-border-strong)" },
|
|
37
|
+
".cm-panels": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-text)" }
|
|
38
|
+
}), le = "data-aqmx-conflict-actions", Qe = K.line({ attributes: { "data-aqmx-conflict-line": "marker" } }), Ze = K.line({ attributes: { "data-aqmx-conflict-line": "ours" } }), et = K.line({ attributes: { "data-aqmx-conflict-line": "theirs" } });
|
|
39
|
+
class tt extends ze {
|
|
40
|
+
constructor(t, n) {
|
|
41
|
+
super(), this.index = t, this.labels = n;
|
|
42
|
+
}
|
|
43
|
+
index;
|
|
44
|
+
labels;
|
|
45
|
+
eq(t) {
|
|
46
|
+
return t.index === this.index && t.labels === this.labels;
|
|
47
|
+
}
|
|
48
|
+
toDOM(t) {
|
|
49
|
+
const n = document.createElement("div");
|
|
50
|
+
n.setAttribute(le, String(this.index));
|
|
51
|
+
for (const [s, c] of [
|
|
52
|
+
["ours", this.labels.useOurs],
|
|
53
|
+
["theirs", this.labels.useTheirs],
|
|
54
|
+
["both", this.labels.keepBoth]
|
|
55
|
+
]) {
|
|
56
|
+
const i = document.createElement("button");
|
|
57
|
+
i.type = "button", i.textContent = c, i.setAttribute("data-aqmx-conflict-choice", s), i.addEventListener("mousedown", (l) => l.preventDefault()), i.addEventListener("click", () => {
|
|
58
|
+
const l = P(t.state.doc)[this.index];
|
|
59
|
+
l !== void 0 && (ce(t, l, s), t.focus());
|
|
60
|
+
}), n.append(i);
|
|
61
|
+
}
|
|
62
|
+
return n;
|
|
63
|
+
}
|
|
64
|
+
ignoreEvent() {
|
|
65
|
+
return !0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const P = (e) => pe(e.iterLines()), te = (e, t) => {
|
|
69
|
+
const n = new _e();
|
|
70
|
+
return P(e).forEach((s, c) => {
|
|
71
|
+
const i = e.line(s.start);
|
|
72
|
+
n.add(i.from, i.from, K.widget({ widget: new tt(c, t), block: !0, side: -1 }));
|
|
73
|
+
for (let l = s.start; l <= s.end; l += 1) {
|
|
74
|
+
const a = e.line(l).from, v = l === s.start || l === s.separator || l === s.end ? Qe : l < s.separator ? Ze : et;
|
|
75
|
+
n.add(a, a, v);
|
|
76
|
+
}
|
|
77
|
+
}), n.finish();
|
|
78
|
+
}, nt = (e) => Ne.define({
|
|
79
|
+
create: (t) => te(t.doc, e),
|
|
80
|
+
update: (t, n) => n.docChanged ? te(n.state.doc, e) : t,
|
|
81
|
+
provide: (t) => N.decorations.from(t)
|
|
82
|
+
}), ce = (e, t, n) => {
|
|
83
|
+
const { doc: s } = e.state, c = (m, d) => {
|
|
84
|
+
const h = [];
|
|
85
|
+
for (let u = m; u <= d; u += 1) h.push(s.line(u).text);
|
|
86
|
+
return h;
|
|
87
|
+
}, i = c(t.start + 1, t.separator - 1), l = c(t.separator + 1, t.end - 1), a = n === "ours" ? i : n === "theirs" ? l : [...i, ...l];
|
|
88
|
+
let v = s.line(t.start).from, r = s.line(t.end).to;
|
|
89
|
+
a.length === 0 && (t.end < s.lines ? r += 1 : t.start > 1 && (v -= 1));
|
|
90
|
+
const o = a.join(`
|
|
91
|
+
`);
|
|
92
|
+
e.dispatch({ changes: { from: v, to: r, insert: o }, selection: X.cursor(v), scrollIntoView: !0, userEvent: "input.resolve" });
|
|
93
|
+
}, rt = ({ parent: e, scroll: t, text: n, saved: s, labels: c, onChange: i, onSave: l }) => {
|
|
94
|
+
const a = [
|
|
95
|
+
N.scrollHandler.of((o, m, d) => (ot(o, m.head, d, t), !0)),
|
|
96
|
+
He(),
|
|
97
|
+
Fe(),
|
|
98
|
+
qe(),
|
|
99
|
+
Ve(),
|
|
100
|
+
Pe(),
|
|
101
|
+
Re(),
|
|
102
|
+
N.lineWrapping,
|
|
103
|
+
Ae({ base: Oe }),
|
|
104
|
+
Ce(Ye),
|
|
105
|
+
nt(c),
|
|
106
|
+
Be.of([
|
|
107
|
+
{
|
|
108
|
+
key: "Mod-s",
|
|
109
|
+
preventDefault: !0,
|
|
110
|
+
run: () => (l(), !0)
|
|
111
|
+
},
|
|
112
|
+
...De,
|
|
113
|
+
...Le,
|
|
114
|
+
...Te
|
|
115
|
+
]),
|
|
116
|
+
N.contentAttributes.of({ "aria-label": c.editor, "aria-multiline": "true" }),
|
|
117
|
+
N.updateListener.of((o) => {
|
|
118
|
+
o.docChanged && i();
|
|
119
|
+
}),
|
|
120
|
+
Je
|
|
121
|
+
], v = it(s, a) ?? ae.create({ doc: n, extensions: a }), r = new N({ state: v, parent: e });
|
|
122
|
+
return {
|
|
123
|
+
text: () => r.state.doc.toString(),
|
|
124
|
+
replaceText: (o) => {
|
|
125
|
+
const m = r.state.doc.toString();
|
|
126
|
+
if (m === o) return;
|
|
127
|
+
let d = 0;
|
|
128
|
+
const h = Math.min(m.length, o.length);
|
|
129
|
+
for (; d < h && m.charCodeAt(d) === o.charCodeAt(d); ) d += 1;
|
|
130
|
+
let u = 0;
|
|
131
|
+
for (; u < h - d && m.charCodeAt(m.length - 1 - u) === o.charCodeAt(o.length - 1 - u); ) u += 1;
|
|
132
|
+
r.dispatch({ changes: { from: d, to: m.length - u, insert: o.slice(d, o.length - u) }, userEvent: "input.replace" });
|
|
133
|
+
},
|
|
134
|
+
reveal: ({ line: o, column: m }, d) => {
|
|
135
|
+
const { doc: h } = r.state, u = h.line(Math.min(Math.max(o, 1), h.lines)), x = Math.min(u.from + m, u.to);
|
|
136
|
+
r.dispatch({ selection: X.cursor(x), effects: ne(r, x, d, t) });
|
|
137
|
+
},
|
|
138
|
+
showLine: (o) => {
|
|
139
|
+
const { doc: m } = r.state, d = m.line(Math.min(Math.max(o, 1), m.lines)).from;
|
|
140
|
+
r.dispatch({ effects: ne(r, d, null, t) });
|
|
141
|
+
},
|
|
142
|
+
topLine: () => {
|
|
143
|
+
const o = t.scrollerOf(r.scrollDOM), m = z(o, r.contentDOM), d = J(o) + o.clientHeight, { documentTop: h } = r, { doc: u } = r.state;
|
|
144
|
+
let x = r.lineBlockAtHeight(Math.max(m - h, 0));
|
|
145
|
+
for (; u.lineAt(x.from).text.trim() === "" && x.to < u.length; ) {
|
|
146
|
+
const O = r.lineBlockAt(x.to + 1);
|
|
147
|
+
if (h + O.top >= d) break;
|
|
148
|
+
x = O;
|
|
149
|
+
}
|
|
150
|
+
const S = r.coordsAtPos(x.from), k = S === null ? h + x.top : S.top;
|
|
151
|
+
return { line: r.state.doc.lineAt(x.from).number, clientTop: k, offset: k - m };
|
|
152
|
+
},
|
|
153
|
+
scrollElement: r.scrollDOM,
|
|
154
|
+
focus: () => r.focus(),
|
|
155
|
+
conflicts: () => P(r.state.doc),
|
|
156
|
+
resolveAtCursor: (o) => {
|
|
157
|
+
const m = P(r.state.doc), d = r.state.doc.lineAt(r.state.selection.main.head).number, h = m.find((u) => u.end >= d);
|
|
158
|
+
return h === void 0 ? !1 : (ce(r, h, o), !0);
|
|
159
|
+
},
|
|
160
|
+
nextConflict: () => {
|
|
161
|
+
const o = P(r.state.doc);
|
|
162
|
+
if (o[0] === void 0) return !1;
|
|
163
|
+
const d = r.state.doc.lineAt(r.state.selection.main.head).number, h = o.findIndex((k) => k.start > d), u = h < 0 ? 0 : h, x = r.state.doc.line(o[u].start).from;
|
|
164
|
+
r.dispatch({ selection: X.cursor(x), effects: N.scrollIntoView(x, { y: "center" }) });
|
|
165
|
+
const S = r.contentDOM.querySelector(`[${le}="${String(u)}"] button`);
|
|
166
|
+
return S instanceof HTMLElement ? S.focus({ preventScroll: !0 }) : r.focus(), !0;
|
|
167
|
+
},
|
|
168
|
+
save: () => r.state.toJSON(ie),
|
|
169
|
+
destroy: () => r.destroy()
|
|
170
|
+
};
|
|
171
|
+
}, ne = (e, t, n, s) => {
|
|
172
|
+
const c = s.scrollerOf(e.scrollDOM), i = (n === null ? z(c, e.contentDOM) : n) - J(c);
|
|
173
|
+
return N.scrollIntoView(t, { y: "start", yMargin: i });
|
|
174
|
+
}, ot = (e, t, n, s) => {
|
|
175
|
+
const c = st(e, t), i = s.scrollerOf(e.scrollDOM), l = J(i), a = z(i, e.contentDOM), v = l + i.clientHeight;
|
|
176
|
+
let r = 0;
|
|
177
|
+
switch (n.y) {
|
|
178
|
+
case "start":
|
|
179
|
+
r = c.top - (l + n.yMargin);
|
|
180
|
+
break;
|
|
181
|
+
case "center":
|
|
182
|
+
r = (c.top + c.bottom) / 2 - (a + v) / 2;
|
|
183
|
+
break;
|
|
184
|
+
case "end":
|
|
185
|
+
r = c.bottom - (v - n.yMargin);
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
c.top < a + n.yMargin ? r = c.top - (a + n.yMargin) : c.bottom > v - n.yMargin && (r = Math.min(c.bottom - (v - n.yMargin), c.top - (a + n.yMargin)));
|
|
189
|
+
}
|
|
190
|
+
if (r !== 0 && (i.scrollTop += r), n.y === "start") return;
|
|
191
|
+
const o = at(e, t);
|
|
192
|
+
o !== null && s.reveal(o);
|
|
193
|
+
}, st = (e, t) => {
|
|
194
|
+
const { node: n, offset: s } = e.domAtPos(t);
|
|
195
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
196
|
+
const l = n.ownerDocument?.createRange();
|
|
197
|
+
if (l !== void 0) {
|
|
198
|
+
l.setStart(n, s), l.setEnd(n, s);
|
|
199
|
+
const [a] = l.getClientRects();
|
|
200
|
+
if (a !== void 0 && a.height > 0) return { top: a.top, bottom: a.bottom };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const c = e.lineBlockAt(t), i = e.documentTop + c.top;
|
|
204
|
+
return { top: i, bottom: i + c.height };
|
|
205
|
+
}, at = (e, t) => {
|
|
206
|
+
const { node: n } = e.domAtPos(t);
|
|
207
|
+
for (let s = n instanceof Element ? n : n.parentElement; s !== null; s = s.parentElement)
|
|
208
|
+
if (s.parentElement === e.contentDOM) return s;
|
|
209
|
+
return null;
|
|
210
|
+
}, it = (e, t) => {
|
|
211
|
+
if (e == null) return null;
|
|
212
|
+
try {
|
|
213
|
+
return ae.fromJSON(e, { extensions: t }, ie);
|
|
214
|
+
} catch {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}, lt = 610, ct = 987, re = Object.freeze({ kind: "unavailable" }), dt = "true", ut = "false", ft = (e) => e === dt ? !0 : e === ut ? !1 : null, mt = (e) => {
|
|
218
|
+
const t = new DOMParser().parseFromString(e, "text/html"), n = [];
|
|
219
|
+
for (const s of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")) {
|
|
220
|
+
const c = s.localName === "img", i = s.getAttribute(c ? "data-asset-src" : "data-doc-path");
|
|
221
|
+
i !== null && n.push({ target: { kind: c ? "asset" : "doc", path: i }, exists: ft(s.getAttribute(c ? "data-asset-exists" : "data-doc-exists")) });
|
|
222
|
+
}
|
|
223
|
+
return n;
|
|
224
|
+
}, ht = ({ path: e, instant: t, preview: n, initial: s, onView: c }) => {
|
|
225
|
+
const i = new AbortController(), l = { asset: /* @__PURE__ */ new Map(), doc: /* @__PURE__ */ new Map() };
|
|
226
|
+
let a = s, v = null, r = !1, o = !1, m = null, d = null, h = [], u, x = !1, S, k = null;
|
|
227
|
+
const O = (f) => {
|
|
228
|
+
f.parsed === a.parsed && f.failure === a.failure && f.busy === a.busy && f.tier === a.tier || (a = f, c(f));
|
|
229
|
+
}, w = (f, p) => {
|
|
230
|
+
r || (r = !0, console.error(`[markdown-explorer] ${f}`, ...p === void 0 ? [] : [p]));
|
|
231
|
+
}, g = (f) => {
|
|
232
|
+
if (t !== null)
|
|
233
|
+
for (const { target: p, exists: b } of t.marksOf(f)) l[p.kind].set(p.path, b);
|
|
234
|
+
}, E = () => {
|
|
235
|
+
clearTimeout(S), S = void 0, k?.abort(), k = null;
|
|
236
|
+
}, L = () => {
|
|
237
|
+
d = null, h = [], clearTimeout(u), u = void 0;
|
|
238
|
+
}, T = (f, p) => {
|
|
239
|
+
O({ parsed: a.parsed, failure: f, busy: !1, tier: p });
|
|
240
|
+
}, R = () => {
|
|
241
|
+
clearTimeout(u), u = h.length === 0 ? void 0 : setTimeout(F, ct);
|
|
242
|
+
}, M = () => {
|
|
243
|
+
if (t === null || d === null) return;
|
|
244
|
+
const f = d, p = [], b = { asset: /* @__PURE__ */ new Set(), doc: /* @__PURE__ */ new Set() };
|
|
245
|
+
let _;
|
|
246
|
+
try {
|
|
247
|
+
_ = t.sanitize(f.html, (I) => {
|
|
248
|
+
const Z = l[I.kind].get(I.path);
|
|
249
|
+
return Z === void 0 && !b[I.kind].has(I.path) && (b[I.kind].add(I.path), p.push(I)), Z ?? void 0;
|
|
250
|
+
});
|
|
251
|
+
} catch (I) {
|
|
252
|
+
L(), I instanceof Ge ? T(B("too-large"), "instant") : (w("the draft sanitizer failed", I), T(B("failed"), "instant"));
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
h = p;
|
|
256
|
+
const V = a.parsed !== null && a.parsed.htmlContent === _ && a.parsed.headings === f.headings ? a.parsed : { htmlContent: _, headings: f.headings };
|
|
257
|
+
O({ parsed: V, failure: null, busy: !1, tier: "instant" }), R();
|
|
258
|
+
}, F = () => {
|
|
259
|
+
if (u = void 0, x || d === null || h.length === 0) return;
|
|
260
|
+
x = !0;
|
|
261
|
+
const f = h;
|
|
262
|
+
n(e, d.text, i.signal).then((p) => {
|
|
263
|
+
if (x = !1, !(i.signal.aborted || !("kind" in p))) {
|
|
264
|
+
p.kind === "preview" && g(p.htmlContent);
|
|
265
|
+
for (const b of f) l[b.kind].has(b.path) || l[b.kind].set(b.path, null);
|
|
266
|
+
M();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}, A = (f) => {
|
|
270
|
+
E(), L(), O({ ...a, busy: !0, tier: "server" });
|
|
271
|
+
const p = new AbortController();
|
|
272
|
+
k = p, S = setTimeout(() => {
|
|
273
|
+
S = void 0, n(e, f, p.signal).then((b) => {
|
|
274
|
+
if (!(p.signal.aborted || !("kind" in b))) {
|
|
275
|
+
if (k = null, b.kind === "failure") {
|
|
276
|
+
T(b.failure, "server");
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
g(b.htmlContent), O({ parsed: { htmlContent: b.htmlContent, headings: b.headings }, failure: null, busy: !1, tier: "server" });
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}, lt);
|
|
283
|
+
}, W = async (f, p) => {
|
|
284
|
+
let b;
|
|
285
|
+
try {
|
|
286
|
+
b = await f.convert({ path: e, text: p }, i.signal);
|
|
287
|
+
} catch (V) {
|
|
288
|
+
return i.signal.aborted || w("the draft converter rejected a conversion, which its contract allows only once the signal aborted", V), re;
|
|
289
|
+
}
|
|
290
|
+
const _ = We(b);
|
|
291
|
+
return _ === null ? b : (w(`the draft converter answered outside its contract: ${_}`), re);
|
|
292
|
+
}, C = (f, p) => {
|
|
293
|
+
switch (p.kind) {
|
|
294
|
+
case "preview":
|
|
295
|
+
if (E(), p.headings.length > je) {
|
|
296
|
+
L(), T(B("too-large"), "instant");
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
d = { text: f, html: p.htmlContent, headings: p.headings.map(({ text: b, depth: _, id: V }) => ({ text: b, depth: _, id: V })) }, M();
|
|
300
|
+
return;
|
|
301
|
+
case "failure":
|
|
302
|
+
E(), L(), T(B(p.failure.reason, p.failure.code), "instant");
|
|
303
|
+
return;
|
|
304
|
+
case "unavailable":
|
|
305
|
+
A(f);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}, j = async (f) => {
|
|
309
|
+
o = !0;
|
|
310
|
+
try {
|
|
311
|
+
for (; m !== null && !i.signal.aborted; ) {
|
|
312
|
+
const p = m;
|
|
313
|
+
m = null;
|
|
314
|
+
const b = await W(f, p);
|
|
315
|
+
if (i.signal.aborted) return;
|
|
316
|
+
C(p, b);
|
|
317
|
+
}
|
|
318
|
+
} finally {
|
|
319
|
+
o = !1;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
return t !== null && t.seed !== null && g(t.seed), {
|
|
323
|
+
update: (f) => {
|
|
324
|
+
if (!(i.signal.aborted || f === v)) {
|
|
325
|
+
if (v = f, clearTimeout(u), u = void 0, t === null) {
|
|
326
|
+
A(f);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
m = f, o || j(t.converter);
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
dispose: () => {
|
|
333
|
+
i.abort(), m = null, clearTimeout(u), u = void 0, E();
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}, pt = (e, t) => Ue($e(window), e, t, Xe), gt = "[data-aqmd-scroll-container]", vt = Object.freeze(["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"]), de = (e, t) => {
|
|
337
|
+
const n = ge(e.peek(t));
|
|
338
|
+
return n !== null && n.document.kind === "markdown" ? { htmlContent: n.document.htmlContent, headings: n.document.headings } : null;
|
|
339
|
+
}, bt = (e, t, n, s, c) => {
|
|
340
|
+
if (n === void 0) return null;
|
|
341
|
+
let i;
|
|
342
|
+
try {
|
|
343
|
+
i = pt(e, t);
|
|
344
|
+
} catch (l) {
|
|
345
|
+
return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview", l), null;
|
|
346
|
+
}
|
|
347
|
+
return { converter: n, sanitize: i, marksOf: mt, seed: de(s, c)?.htmlContent ?? null };
|
|
348
|
+
}, oe = (e, t) => {
|
|
349
|
+
const n = e.querySelector(gt), s = ve(e, t.line);
|
|
350
|
+
n === null || s === null || (n.scrollTop += be(s, t.line) - (z(n, s) + t.offset));
|
|
351
|
+
}, xt = ({ path: e, readDraft: t, viewer: n, editorPoint: s, handleRef: c }) => {
|
|
352
|
+
const { config: i, data: l, documents: a, draftConverter: v, labels: r } = Q(), [o, m] = fe(() => ({ parsed: de(a, e), failure: null, busy: !0, tier: v === void 0 ? "server" : "instant" })), d = D(null), h = D(null), u = D(o);
|
|
353
|
+
H(() => {
|
|
354
|
+
u.current = o;
|
|
355
|
+
});
|
|
356
|
+
const x = ee(() => t());
|
|
357
|
+
Y(() => {
|
|
358
|
+
const w = bt(i.iframeHosts, i.dataPath, v, a, e), g = ht({ path: e, instant: w, preview: l.preview, initial: u.current, onView: (E) => he(() => m(E)) });
|
|
359
|
+
return h.current = g, g.update(x()), () => {
|
|
360
|
+
g.dispose(), h.current = null;
|
|
361
|
+
};
|
|
362
|
+
}, [i, l, a, v, e]);
|
|
363
|
+
const S = ee(() => {
|
|
364
|
+
const w = d.current, g = s();
|
|
365
|
+
w !== null && g !== null && oe(w, g);
|
|
366
|
+
});
|
|
367
|
+
H(() => {
|
|
368
|
+
o.parsed !== null && S();
|
|
369
|
+
}, [o.parsed]), me(
|
|
370
|
+
c,
|
|
371
|
+
() => ({
|
|
372
|
+
follow: (w) => {
|
|
373
|
+
const g = d.current;
|
|
374
|
+
g !== null && oe(g, w);
|
|
375
|
+
},
|
|
376
|
+
draft: (w) => {
|
|
377
|
+
h.current?.update(w);
|
|
378
|
+
}
|
|
379
|
+
}),
|
|
380
|
+
[]
|
|
381
|
+
);
|
|
382
|
+
const k = G(() => ({ ...n, showToc: !1, showStyle: !1, showAlign: !1, renderScrollBar: void 0 }), [n]), O = G(
|
|
383
|
+
() => o.parsed === null ? null : /* @__PURE__ */ q("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ q(Ke, { ...k, parseResult: o.parsed, content: null }) }),
|
|
384
|
+
[k, o.parsed]
|
|
385
|
+
);
|
|
386
|
+
return /* @__PURE__ */ $("section", { ref: d, className: "aqmx-edit-preview", "aria-label": r.previewRegion, "aria-busy": o.busy, "data-aqmx-preview-tier": o.tier, "data-testid": "markdown-explorer-edit-preview", children: [
|
|
387
|
+
o.failure === null ? null : /* @__PURE__ */ q("p", { className: "aqmx-callout aqmx-document-notice", "data-aqmx-tone": "warning", "data-testid": "markdown-explorer-edit-preview-failure", children: r.previewFailed(se(r, o.failure.reason)) }),
|
|
388
|
+
O ?? (o.failure === null ? /* @__PURE__ */ q("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-preview-skeleton", children: vt.map((w) => /* @__PURE__ */ q("span", {}, w)) }) : null),
|
|
389
|
+
o.busy ? /* @__PURE__ */ q("p", { className: "aqmx-sr-only", children: r.previewUpdating }) : null
|
|
390
|
+
] });
|
|
391
|
+
}, kt = 144, wt = Object.freeze(["e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"]), Et = (e) => {
|
|
392
|
+
if (typeof e != "object" || e === null) return !1;
|
|
393
|
+
const { generation: t, topLine: n } = e;
|
|
394
|
+
return "state" in e && typeof t == "number" && typeof n == "number";
|
|
395
|
+
}, yt = (e) => {
|
|
396
|
+
e.key === "Escape" && Se(e);
|
|
397
|
+
}, St = (e) => {
|
|
398
|
+
e.stopPropagation();
|
|
399
|
+
}, Pt = (e) => {
|
|
400
|
+
const { path: t, name: n, session: s } = e, { edits: c, labels: i, announcer: l } = Q(), { phase: a } = s, v = U(() => c.retry(t), [c, t]);
|
|
401
|
+
switch (Y(() => {
|
|
402
|
+
a.kind === "failed" && l.announce(i.documentFailed(n, se(i, a.failure.reason)));
|
|
403
|
+
}, [a, l, i, n]), a.kind) {
|
|
404
|
+
case "opening":
|
|
405
|
+
return /* @__PURE__ */ $(ue, { children: [
|
|
406
|
+
/* @__PURE__ */ q("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-skeleton", children: wt.map((r) => /* @__PURE__ */ q("span", {}, r)) }),
|
|
407
|
+
/* @__PURE__ */ q("p", { className: "aqmx-sr-only", children: i.editLoading })
|
|
408
|
+
] });
|
|
409
|
+
case "grant":
|
|
410
|
+
return /* @__PURE__ */ q("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ q(ke, { href: a.href, onRetry: v, testId: "markdown-explorer-edit-grant" }) });
|
|
411
|
+
case "failed":
|
|
412
|
+
return /* @__PURE__ */ q("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ q(xe, { failure: a.failure, alert: !1, onRetry: v, testId: "markdown-explorer-edit-failure" }) });
|
|
413
|
+
case "editing":
|
|
414
|
+
return /* @__PURE__ */ q(qt, { ...e });
|
|
415
|
+
}
|
|
416
|
+
}, qt = ({ path: e, name: t, session: n, layout: s, viewer: c, region: i, paneScroll: l }) => {
|
|
417
|
+
const { edits: a, labels: v } = Q(), r = D(null), o = D(null), m = D(null), d = we() && s === "fill", h = D({ layout: s, region: i, paneScroll: l });
|
|
418
|
+
H(() => {
|
|
419
|
+
h.current = { layout: s, region: i, paneScroll: l };
|
|
420
|
+
});
|
|
421
|
+
const u = D(n.generation);
|
|
422
|
+
H(() => {
|
|
423
|
+
u.current = n.generation;
|
|
424
|
+
});
|
|
425
|
+
const x = D(d);
|
|
426
|
+
H(() => {
|
|
427
|
+
x.current = d;
|
|
428
|
+
});
|
|
429
|
+
const S = G(() => ({ editor: v.editorLabel(t), useOurs: v.conflictUseOurs, useTheirs: v.conflictUseTheirs, keepBoth: v.conflictKeepBoth }), [v, t]);
|
|
430
|
+
H(() => {
|
|
431
|
+
const g = r.current, E = a.draft(e);
|
|
432
|
+
if (g === null || E === null) return;
|
|
433
|
+
const L = a.editorState.get(e), T = Et(L) && L.generation === u.current ? L : null;
|
|
434
|
+
let R = null, M = null;
|
|
435
|
+
const F = () => {
|
|
436
|
+
R !== null && clearTimeout(R), R = null, M !== null && a.setDraft(e, M.text());
|
|
437
|
+
}, A = rt({
|
|
438
|
+
parent: g,
|
|
439
|
+
scroll: {
|
|
440
|
+
scrollerOf: (C) => {
|
|
441
|
+
const { layout: j, region: f, paneScroll: p } = h.current, b = f();
|
|
442
|
+
return j === "fill" || b === null ? C : p.scrollerOf(b, C);
|
|
443
|
+
},
|
|
444
|
+
reveal: (C) => h.current.paneScroll.reveal(C)
|
|
445
|
+
},
|
|
446
|
+
text: E,
|
|
447
|
+
saved: T === null ? void 0 : T.state,
|
|
448
|
+
labels: S,
|
|
449
|
+
onChange: () => {
|
|
450
|
+
R ??= setTimeout(F, kt), x.current && M !== null && m.current?.draft(M.text());
|
|
451
|
+
},
|
|
452
|
+
onSave: () => {
|
|
453
|
+
a.save(e);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
M = A, o.current = A;
|
|
457
|
+
const W = a.bindEditor(e, {
|
|
458
|
+
flush: F,
|
|
459
|
+
adopt: (C) => A.replaceText(C),
|
|
460
|
+
returnPoint: () => {
|
|
461
|
+
const C = A.topLine();
|
|
462
|
+
return { line: C.line, clientTop: C.clientTop };
|
|
463
|
+
},
|
|
464
|
+
nextConflict: () => A.nextConflict()
|
|
465
|
+
});
|
|
466
|
+
return T !== null && A.showLine(T.topLine), () => {
|
|
467
|
+
F(), a.editorState.set(e, { state: A.save(), generation: u.current, topLine: A.topLine().line }), W(), A.destroy(), M = null, o.current = null;
|
|
468
|
+
};
|
|
469
|
+
}, [a, e, S]);
|
|
470
|
+
const { request: k } = n;
|
|
471
|
+
H(() => {
|
|
472
|
+
const g = o.current, E = a.draft(e);
|
|
473
|
+
g === null || E === null || k === null || (k.anchor !== null && g.reveal(Ee(E, k.anchor), k.anchor.clientTop), g.focus(), a.consumeRequest(e));
|
|
474
|
+
}, [a, e, k, S]);
|
|
475
|
+
const O = U(() => {
|
|
476
|
+
const g = o.current;
|
|
477
|
+
if (g === null) throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");
|
|
478
|
+
return g.text();
|
|
479
|
+
}, []), w = U(() => {
|
|
480
|
+
const g = o.current;
|
|
481
|
+
if (g === null) return null;
|
|
482
|
+
const E = g.topLine();
|
|
483
|
+
return { line: E.line, offset: E.offset };
|
|
484
|
+
}, []);
|
|
485
|
+
return Y(() => {
|
|
486
|
+
const g = o.current;
|
|
487
|
+
if (!d || g === null) return;
|
|
488
|
+
const E = g.scrollElement;
|
|
489
|
+
let L = 0;
|
|
490
|
+
const T = () => {
|
|
491
|
+
L = 0;
|
|
492
|
+
const M = w();
|
|
493
|
+
M !== null && m.current?.follow(M);
|
|
494
|
+
}, R = () => {
|
|
495
|
+
L === 0 && (L = requestAnimationFrame(T));
|
|
496
|
+
};
|
|
497
|
+
return E.addEventListener("scroll", R, { passive: !0 }), () => {
|
|
498
|
+
E.removeEventListener("scroll", R), cancelAnimationFrame(L);
|
|
499
|
+
};
|
|
500
|
+
}, [d, w, S]),
|
|
501
|
+
/* @__PURE__ */ $("div", { className: "aqmx-edit", "data-aqmx-edit-layout": s, "data-testid": "markdown-explorer-edit", onKeyDown: yt, onDoubleClick: St, children: [
|
|
502
|
+
/* @__PURE__ */ q("div", { ref: r, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", ...ye }),
|
|
503
|
+
d ? /* @__PURE__ */ q(xt, { path: e, readDraft: O, viewer: c, editorPoint: w, handleRef: m }) : null
|
|
504
|
+
] });
|
|
505
|
+
};
|
|
506
|
+
export {
|
|
507
|
+
kt as DRAFT_WRITE_INTERVAL_MS,
|
|
508
|
+
Pt as default
|
|
509
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),g=require("react"),w=require("./index-DpIVKG8Y.cjs"),z=require("@codemirror/commands"),$=require("@codemirror/lang-markdown"),ee=require("@codemirror/language"),X=require("@codemirror/search"),V=require("@codemirror/state"),y=require("@codemirror/view"),L=require("@lezer/highlight"),ie=require("@aiquants/markdown"),H=require("./dataRoute-CH3yOKR0.cjs"),G=require("./sanitizePolicy-BfUlXI5E.cjs"),ae=require("isomorphic-dompurify"),te={history:z.historyField},le=ee.HighlightStyle.define([{tag:[L.tags.heading1,L.tags.heading2,L.tags.heading3,L.tags.heading4,L.tags.heading5,L.tags.heading6,L.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:L.tags.strong,fontWeight:"700"},{tag:L.tags.emphasis,fontStyle:"italic"},{tag:L.tags.strikethrough,textDecoration:"line-through"},{tag:L.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:L.tags.url,color:"var(--aqmx-syntax-url)"},{tag:L.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:L.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[L.tags.processingInstruction,L.tags.contentSeparator,L.tags.labelName,L.tags.meta],color:"var(--aqmx-syntax-mark)"}]),ce=y.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),ne="data-aqmx-conflict-actions",ue=y.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),de=y.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),fe=y.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class me extends y.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(ne,String(this.index));for(const[s,c]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const a=document.createElement("button");a.type="button",a.textContent=c,a.setAttribute("data-aqmx-conflict-choice",s),a.addEventListener("mousedown",l=>l.preventDefault()),a.addEventListener("click",()=>{const l=B(t.state.doc)[this.index];l!==void 0&&(re(t,l,s),t.focus())}),n.append(a)}return n}ignoreEvent(){return!0}}const B=e=>w.findConflictsInLines(e.iterLines()),Y=(e,t)=>{const n=new V.RangeSetBuilder;return B(e).forEach((s,c)=>{const a=e.line(s.start);n.add(a.from,a.from,y.Decoration.widget({widget:new me(c,t),block:!0,side:-1}));for(let l=s.start;l<=s.end;l+=1){const i=e.line(l).from,x=l===s.start||l===s.separator||l===s.end?ue:l<s.separator?de:fe;n.add(i,i,x)}}),n.finish()},he=e=>V.StateField.define({create:t=>Y(t.doc,e),update:(t,n)=>n.docChanged?Y(n.state.doc,e):t,provide:t=>y.EditorView.decorations.from(t)}),re=(e,t,n)=>{const{doc:s}=e.state,c=(m,u)=>{const h=[];for(let d=m;d<=u;d+=1)h.push(s.line(d).text);return h},a=c(t.start+1,t.separator-1),l=c(t.separator+1,t.end-1),i=n==="ours"?a:n==="theirs"?l:[...a,...l];let x=s.line(t.start).from,r=s.line(t.end).to;i.length===0&&(t.end<s.lines?r+=1:t.start>1&&(x-=1));const o=i.join(`
|
|
2
|
+
`);e.dispatch({changes:{from:x,to:r,insert:o},selection:V.EditorSelection.cursor(x),scrollIntoView:!0,userEvent:"input.resolve"})},pe=({parent:e,scroll:t,text:n,saved:s,labels:c,onChange:a,onSave:l})=>{const i=[y.EditorView.scrollHandler.of((o,m,u)=>(ge(o,m.head,u,t),!0)),y.lineNumbers(),y.highlightActiveLineGutter(),z.history(),y.drawSelection(),y.highlightActiveLine(),X.highlightSelectionMatches(),y.EditorView.lineWrapping,$.markdown({base:$.markdownLanguage}),ee.syntaxHighlighting(le),he(c),y.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(l(),!0)},...X.searchKeymap,...z.historyKeymap,...z.defaultKeymap]),y.EditorView.contentAttributes.of({"aria-label":c.editor,"aria-multiline":"true"}),y.EditorView.updateListener.of(o=>{o.docChanged&&a()}),ce],x=be(s,i)??V.EditorState.create({doc:n,extensions:i}),r=new y.EditorView({state:x,parent:e});return{text:()=>r.state.doc.toString(),replaceText:o=>{const m=r.state.doc.toString();if(m===o)return;let u=0;const h=Math.min(m.length,o.length);for(;u<h&&m.charCodeAt(u)===o.charCodeAt(u);)u+=1;let d=0;for(;d<h-u&&m.charCodeAt(m.length-1-d)===o.charCodeAt(o.length-1-d);)d+=1;r.dispatch({changes:{from:u,to:m.length-d,insert:o.slice(u,o.length-d)},userEvent:"input.replace"})},reveal:({line:o,column:m},u)=>{const{doc:h}=r.state,d=h.line(Math.min(Math.max(o,1),h.lines)),E=Math.min(d.from+m,d.to);r.dispatch({selection:V.EditorSelection.cursor(E),effects:J(r,E,u,t)})},showLine:o=>{const{doc:m}=r.state,u=m.line(Math.min(Math.max(o,1),m.lines)).from;r.dispatch({effects:J(r,u,null,t)})},topLine:()=>{const o=t.scrollerOf(r.scrollDOM),m=w.visibleTopOf(o,r.contentDOM),u=w.frameTopOf(o)+o.clientHeight,{documentTop:h}=r,{doc:d}=r.state;let E=r.lineBlockAtHeight(Math.max(m-h,0));for(;d.lineAt(E.from).text.trim()===""&&E.to<d.length;){const D=r.lineBlockAt(E.to+1);if(h+D.top>=u)break;E=D}const O=r.coordsAtPos(E.from),q=O===null?h+E.top:O.top;return{line:r.state.doc.lineAt(E.from).number,clientTop:q,offset:q-m}},scrollElement:r.scrollDOM,focus:()=>r.focus(),conflicts:()=>B(r.state.doc),resolveAtCursor:o=>{const m=B(r.state.doc),u=r.state.doc.lineAt(r.state.selection.main.head).number,h=m.find(d=>d.end>=u);return h===void 0?!1:(re(r,h,o),!0)},nextConflict:()=>{const o=B(r.state.doc);if(o[0]===void 0)return!1;const u=r.state.doc.lineAt(r.state.selection.main.head).number,h=o.findIndex(q=>q.start>u),d=h<0?0:h,E=r.state.doc.line(o[d].start).from;r.dispatch({selection:V.EditorSelection.cursor(E),effects:y.EditorView.scrollIntoView(E,{y:"center"})});const O=r.contentDOM.querySelector(`[${ne}="${String(d)}"] button`);return O instanceof HTMLElement?O.focus({preventScroll:!0}):r.focus(),!0},save:()=>r.state.toJSON(te),destroy:()=>r.destroy()}},J=(e,t,n,s)=>{const c=s.scrollerOf(e.scrollDOM),a=(n===null?w.visibleTopOf(c,e.contentDOM):n)-w.frameTopOf(c);return y.EditorView.scrollIntoView(t,{y:"start",yMargin:a})},ge=(e,t,n,s)=>{const c=ve(e,t),a=s.scrollerOf(e.scrollDOM),l=w.frameTopOf(a),i=w.visibleTopOf(a,e.contentDOM),x=l+a.clientHeight;let r=0;switch(n.y){case"start":r=c.top-(l+n.yMargin);break;case"center":r=(c.top+c.bottom)/2-(i+x)/2;break;case"end":r=c.bottom-(x-n.yMargin);break;default:c.top<i+n.yMargin?r=c.top-(i+n.yMargin):c.bottom>x-n.yMargin&&(r=Math.min(c.bottom-(x-n.yMargin),c.top-(i+n.yMargin)))}if(r!==0&&(a.scrollTop+=r),n.y==="start")return;const o=xe(e,t);o!==null&&s.reveal(o)},ve=(e,t)=>{const{node:n,offset:s}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const l=n.ownerDocument?.createRange();if(l!==void 0){l.setStart(n,s),l.setEnd(n,s);const[i]=l.getClientRects();if(i!==void 0&&i.height>0)return{top:i.top,bottom:i.bottom}}}const c=e.lineBlockAt(t),a=e.documentTop+c.top;return{top:a,bottom:a+c.height}},xe=(e,t)=>{const{node:n}=e.domAtPos(t);for(let s=n instanceof Element?n:n.parentElement;s!==null;s=s.parentElement)if(s.parentElement===e.contentDOM)return s;return null},be=(e,t)=>{if(e==null)return null;try{return V.EditorState.fromJSON(e,{extensions:t},te)}catch{return null}},Ee=610,we=987,Q=Object.freeze({kind:"unavailable"}),ke="true",ye="false",qe=e=>e===ke?!0:e===ye?!1:null,Se=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const s of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const c=s.localName==="img",a=s.getAttribute(c?"data-asset-src":"data-doc-path");a!==null&&n.push({target:{kind:c?"asset":"doc",path:a},exists:qe(s.getAttribute(c?"data-asset-exists":"data-doc-exists"))})}return n},Te=({path:e,instant:t,preview:n,initial:s,onView:c})=>{const a=new AbortController,l={asset:new Map,doc:new Map};let i=s,x=null,r=!1,o=!1,m=null,u=null,h=[],d,E=!1,O,q=null;const D=f=>{f.parsed===i.parsed&&f.failure===i.failure&&f.busy===i.busy&&f.tier===i.tier||(i=f,c(f))},S=(f,p)=>{r||(r=!0,console.error(`[markdown-explorer] ${f}`,...p===void 0?[]:[p]))},v=f=>{if(t!==null)for(const{target:p,exists:b}of t.marksOf(f))l[p.kind].set(p.path,b)},T=()=>{clearTimeout(O),O=void 0,q?.abort(),q=null},M=()=>{u=null,h=[],clearTimeout(d),d=void 0},A=(f,p)=>{D({parsed:i.parsed,failure:f,busy:!1,tier:p})},_=()=>{clearTimeout(d),d=h.length===0?void 0:setTimeout(P,we)},R=()=>{if(t===null||u===null)return;const f=u,p=[],b={asset:new Set,doc:new Set};let j;try{j=t.sanitize(f.html,N=>{const U=l[N.kind].get(N.path);return U===void 0&&!b[N.kind].has(N.path)&&(b[N.kind].add(N.path),p.push(N)),U??void 0})}catch(N){M(),N instanceof G.HtmlNestingLimitError?A(H.failureOf("too-large"),"instant"):(S("the draft sanitizer failed",N),A(H.failureOf("failed"),"instant"));return}h=p;const F=i.parsed!==null&&i.parsed.htmlContent===j&&i.parsed.headings===f.headings?i.parsed:{htmlContent:j,headings:f.headings};D({parsed:F,failure:null,busy:!1,tier:"instant"}),_()},P=()=>{if(d=void 0,E||u===null||h.length===0)return;E=!0;const f=h;n(e,u.text,a.signal).then(p=>{if(E=!1,!(a.signal.aborted||!("kind"in p))){p.kind==="preview"&&v(p.htmlContent);for(const b of f)l[b.kind].has(b.path)||l[b.kind].set(b.path,null);R()}})},C=f=>{T(),M(),D({...i,busy:!0,tier:"server"});const p=new AbortController;q=p,O=setTimeout(()=>{O=void 0,n(e,f,p.signal).then(b=>{if(!(p.signal.aborted||!("kind"in b))){if(q=null,b.kind==="failure"){A(b.failure,"server");return}v(b.htmlContent),D({parsed:{htmlContent:b.htmlContent,headings:b.headings},failure:null,busy:!1,tier:"server"})}})},Ee)},K=async(f,p)=>{let b;try{b=await f.convert({path:e,text:p},a.signal)}catch(F){return a.signal.aborted||S("the draft converter rejected a conversion, which its contract allows only once the signal aborted",F),Q}const j=H.draftAnswerViolation(b);return j===null?b:(S(`the draft converter answered outside its contract: ${j}`),Q)},I=(f,p)=>{switch(p.kind){case"preview":if(T(),p.headings.length>H.EXPLORER_MAX_HEADINGS){M(),A(H.failureOf("too-large"),"instant");return}u={text:f,html:p.htmlContent,headings:p.headings.map(({text:b,depth:j,id:F})=>({text:b,depth:j,id:F}))},R();return;case"failure":T(),M(),A(H.failureOf(p.failure.reason,p.failure.code),"instant");return;case"unavailable":C(f);return}},W=async f=>{o=!0;try{for(;m!==null&&!a.signal.aborted;){const p=m;m=null;const b=await K(f,p);if(a.signal.aborted)return;I(p,b)}}finally{o=!1}};return t!==null&&t.seed!==null&&v(t.seed),{update:f=>{if(!(a.signal.aborted||f===x)){if(x=f,clearTimeout(d),d=void 0,t===null){C(f);return}m=f,o||W(t.converter)}},dispose:()=>{a.abort(),m=null,clearTimeout(d),d=void 0,T()}}},Le=(e,t)=>G.createHtmlSanitizer(ae(window),e,t,G.MAX_HTML_NESTING_DEPTH),Oe="[data-aqmd-scroll-container]",Me=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),oe=(e,t)=>{const n=w.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},Ae=(e,t,n,s,c)=>{if(n===void 0)return null;let a;try{a=Le(e,t)}catch(l){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",l),null}return{converter:n,sanitize:a,marksOf:Se,seed:oe(s,c)?.htmlContent??null}},Z=(e,t)=>{const n=e.querySelector(Oe),s=w.blockAtLine(e,t.line);n===null||s===null||(n.scrollTop+=w.lineTopIn(s,t.line)-(w.visibleTopOf(n,s)+t.offset))},Re=({path:e,readDraft:t,viewer:n,editorPoint:s,handleRef:c})=>{const{config:a,data:l,documents:i,draftConverter:x,labels:r}=w.useExplorer(),[o,m]=g.useState(()=>({parsed:oe(i,e),failure:null,busy:!0,tier:x===void 0?"server":"instant"})),u=g.useRef(null),h=g.useRef(null),d=g.useRef(o);g.useLayoutEffect(()=>{d.current=o});const E=g.useEffectEvent(()=>t());g.useEffect(()=>{const S=Ae(a.iframeHosts,a.dataPath,x,i,e),v=Te({path:e,instant:S,preview:l.preview,initial:d.current,onView:T=>g.startTransition(()=>m(T))});return h.current=v,v.update(E()),()=>{v.dispose(),h.current=null}},[a,l,i,x,e]);const O=g.useEffectEvent(()=>{const S=u.current,v=s();S!==null&&v!==null&&Z(S,v)});g.useLayoutEffect(()=>{o.parsed!==null&&O()},[o.parsed]),g.useImperativeHandle(c,()=>({follow:S=>{const v=u.current;v!==null&&Z(v,S)},draft:S=>{h.current?.update(S)}}),[]);const q=g.useMemo(()=>({...n,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0}),[n]),D=g.useMemo(()=>o.parsed===null?null:k.jsx("div",{className:"aqmx-document-viewer",children:k.jsx(ie.MarkdownViewer,{...q,parseResult:o.parsed,content:null})}),[q,o.parsed]);return k.jsxs("section",{ref:u,className:"aqmx-edit-preview","aria-label":r.previewRegion,"aria-busy":o.busy,"data-aqmx-preview-tier":o.tier,"data-testid":"markdown-explorer-edit-preview",children:[o.failure===null?null:k.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:r.previewFailed(w.failureTitleOf(r,o.failure.reason))}),D??(o.failure===null?k.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:Me.map(S=>k.jsx("span",{},S))}):null),o.busy?k.jsx("p",{className:"aqmx-sr-only",children:r.previewUpdating}):null]})},se=144,Ce=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),De=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},Ie=e=>{e.key==="Escape"&&w.consumeKey(e)},Ne=e=>{e.stopPropagation()},_e=e=>{const{path:t,name:n,session:s}=e,{edits:c,labels:a,announcer:l}=w.useExplorer(),{phase:i}=s,x=g.useCallback(()=>c.retry(t),[c,t]);switch(g.useEffect(()=>{i.kind==="failed"&&l.announce(a.documentFailed(n,w.failureTitleOf(a,i.failure.reason)))},[i,l,a,n]),i.kind){case"opening":return k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:Ce.map(r=>k.jsx("span",{},r))}),k.jsx("p",{className:"aqmx-sr-only",children:a.editLoading})]});case"grant":return k.jsx("div",{className:"aqmx-edit-message",children:k.jsx(w.EditGrantNotice,{href:i.href,onRetry:x,testId:"markdown-explorer-edit-grant"})});case"failed":return k.jsx("div",{className:"aqmx-edit-message",children:k.jsx(w.FailureView,{failure:i.failure,alert:!1,onRetry:x,testId:"markdown-explorer-edit-failure"})});case"editing":return k.jsx(je,{...e})}},je=({path:e,name:t,session:n,layout:s,viewer:c,region:a,paneScroll:l})=>{const{edits:i,labels:x}=w.useExplorer(),r=g.useRef(null),o=g.useRef(null),m=g.useRef(null),u=w.usePreviewShown()&&s==="fill",h=g.useRef({layout:s,region:a,paneScroll:l});g.useLayoutEffect(()=>{h.current={layout:s,region:a,paneScroll:l}});const d=g.useRef(n.generation);g.useLayoutEffect(()=>{d.current=n.generation});const E=g.useRef(u);g.useLayoutEffect(()=>{E.current=u});const O=g.useMemo(()=>({editor:x.editorLabel(t),useOurs:x.conflictUseOurs,useTheirs:x.conflictUseTheirs,keepBoth:x.conflictKeepBoth}),[x,t]);g.useLayoutEffect(()=>{const v=r.current,T=i.draft(e);if(v===null||T===null)return;const M=i.editorState.get(e),A=De(M)&&M.generation===d.current?M:null;let _=null,R=null;const P=()=>{_!==null&&clearTimeout(_),_=null,R!==null&&i.setDraft(e,R.text())},C=pe({parent:v,scroll:{scrollerOf:I=>{const{layout:W,region:f,paneScroll:p}=h.current,b=f();return W==="fill"||b===null?I:p.scrollerOf(b,I)},reveal:I=>h.current.paneScroll.reveal(I)},text:T,saved:A===null?void 0:A.state,labels:O,onChange:()=>{_??=setTimeout(P,se),E.current&&R!==null&&m.current?.draft(R.text())},onSave:()=>{i.save(e)}});R=C,o.current=C;const K=i.bindEditor(e,{flush:P,adopt:I=>C.replaceText(I),returnPoint:()=>{const I=C.topLine();return{line:I.line,clientTop:I.clientTop}},nextConflict:()=>C.nextConflict()});return A!==null&&C.showLine(A.topLine),()=>{P(),i.editorState.set(e,{state:C.save(),generation:d.current,topLine:C.topLine().line}),K(),C.destroy(),R=null,o.current=null}},[i,e,O]);const{request:q}=n;g.useLayoutEffect(()=>{const v=o.current,T=i.draft(e);v===null||T===null||q===null||(q.anchor!==null&&v.reveal(w.positionInSource(T,q.anchor),q.anchor.clientTop),v.focus(),i.consumeRequest(e))},[i,e,q,O]);const D=g.useCallback(()=>{const v=o.current;if(v===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return v.text()},[]),S=g.useCallback(()=>{const v=o.current;if(v===null)return null;const T=v.topLine();return{line:T.line,offset:T.offset}},[]);return g.useEffect(()=>{const v=o.current;if(!u||v===null)return;const T=v.scrollElement;let M=0;const A=()=>{M=0;const R=S();R!==null&&m.current?.follow(R)},_=()=>{M===0&&(M=requestAnimationFrame(A))};return T.addEventListener("scroll",_,{passive:!0}),()=>{T.removeEventListener("scroll",_),cancelAnimationFrame(M)}},[u,S,O]),k.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":s,"data-testid":"markdown-explorer-edit",onKeyDown:Ie,onDoubleClick:Ne,children:[k.jsx("div",{ref:r,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",...w.ALLOW_KEY_REPEAT}),u?k.jsx(Re,{path:e,readDraft:D,viewer:c,editorPoint:S,handleRef:m}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=se;exports.default=_e;
|