@aiquants/markdown-explorer 0.11.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 +18 -1
- package/README.md +64 -5
- package/dist/EditSurface-BTAhzvHi.js +509 -0
- package/dist/EditSurface-Dfj6Sxxb.cjs +2 -0
- package/dist/{ExplorerSplit-51frK8xf.cjs → ExplorerSplit-DekOjAUZ.cjs} +1 -1
- package/dist/{ExplorerSplit-DwlWWfRv.js → ExplorerSplit-MPHjw3nW.js} +52 -52
- package/dist/{MultiLayout-CeR_l6Rb.js → MultiLayout-DtSW4rEQ.js} +4 -4
- package/dist/{MultiLayout-B4PtS45V.cjs → MultiLayout-HMzVDYWq.cjs} +1 -1
- package/dist/{NativeScrollBar-Dp4YWBp7.cjs → NativeScrollBar-B0AkVF3E.cjs} +1 -1
- package/dist/{NativeScrollBar-CVWeTlHC.js → NativeScrollBar-CNQr7JY1.js} +1 -1
- package/dist/{TreeLayout-min5AOhr.js → TreeLayout-CJO9tOPq.js} +3 -3
- package/dist/{TreeLayout-D-NyhuVM.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 +16 -0
- package/dist/core/contracts.d.ts +16 -0
- package/dist/dataRoute-CH3yOKR0.cjs +1 -0
- package/dist/{dataRoute-CU9CKP44.js → dataRoute-Pm_0ue_4.js} +93 -92
- package/dist/{index-DJ_FUtYM.cjs → index-DpIVKG8Y.cjs} +8 -8
- package/dist/{index-BPj19kIo.js → index-o6OpR4ND.js} +963 -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-LNl0QOXI.cjs → location-BUNWJ4eB.cjs} +1 -1
- package/dist/{location-BT23fKeh.js → location-DWd6SQhN.js} +1 -1
- package/dist/{merge-AnqxGn__.cjs → merge-Bs7o3GyP.cjs} +1 -1
- package/dist/{merge-hyUGPGbJ.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 +3 -3
- package/docs/behavior/dom-hooks.md +1 -1
- package/docs/behavior/security.md +2 -0
- package/package.json +3 -3
- package/dist/EditSurface-BK_Pz_LF.js +0 -371
- package/dist/EditSurface-CfbYYXrc.cjs +0 -2
- package/dist/dataRoute-CIFFX5bd.cjs +0 -1
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { jsxs as P, jsx as x, Fragment as se } from "react/jsx-runtime";
|
|
2
|
-
import { useState as U, useRef as A, useEffect as N, useEffectEvent as le, useLayoutEffect as C, useImperativeHandle as ie, useMemo as $, useCallback as J } from "react";
|
|
3
|
-
import { v as D, f as V, g as ae, u as K, h as Y, i as ce, l as ue, F as de, E as fe, j as me, p as pe, A as he, k as ge } from "./index-BPj19kIo.js";
|
|
4
|
-
import { history as xe, historyKeymap as be, defaultKeymap as ve, historyField as Ee } from "@codemirror/commands";
|
|
5
|
-
import { markdown as ye, markdownLanguage as ke } from "@codemirror/lang-markdown";
|
|
6
|
-
import { syntaxHighlighting as we, HighlightStyle as qe } from "@codemirror/language";
|
|
7
|
-
import { highlightSelectionMatches as Se, searchKeymap as Le } from "@codemirror/search";
|
|
8
|
-
import { EditorState as X, EditorSelection as H, StateField as Te, RangeSetBuilder as Me } from "@codemirror/state";
|
|
9
|
-
import { EditorView as w, lineNumbers as Ae, highlightActiveLineGutter as Oe, drawSelection as Ce, highlightActiveLine as Re, keymap as Ie, Decoration as _, WidgetType as Ne } from "@codemirror/view";
|
|
10
|
-
import { tags as g } from "@lezer/highlight";
|
|
11
|
-
import { MarkdownViewer as De } from "@aiquants/markdown";
|
|
12
|
-
const Q = { history: Ee }, _e = qe.define([
|
|
13
|
-
{ tag: [g.heading1, g.heading2, g.heading3, g.heading4, g.heading5, g.heading6, g.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
|
|
14
|
-
{ tag: g.strong, fontWeight: "700" },
|
|
15
|
-
{ tag: g.emphasis, fontStyle: "italic" },
|
|
16
|
-
{ tag: g.strikethrough, textDecoration: "line-through" },
|
|
17
|
-
{ tag: g.link, color: "var(--aqmx-syntax-link)", textDecoration: "underline" },
|
|
18
|
-
{ tag: g.url, color: "var(--aqmx-syntax-url)" },
|
|
19
|
-
{ tag: g.monospace, color: "var(--aqmx-syntax-code)" },
|
|
20
|
-
{ tag: g.quote, color: "var(--aqmx-syntax-quote)" },
|
|
21
|
-
{ tag: [g.processingInstruction, g.contentSeparator, g.labelName, g.meta], color: "var(--aqmx-syntax-mark)" }
|
|
22
|
-
]), Fe = w.theme({
|
|
23
|
-
"&": { height: "100%", color: "var(--aqmx-text)", backgroundColor: "var(--aqmx-surface)", fontSize: "var(--aqmx-font-size-title)" },
|
|
24
|
-
"&.cm-focused": { outline: "none" },
|
|
25
|
-
".cm-scroller": { fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', lineHeight: "var(--aqmx-line-height-prose)" },
|
|
26
|
-
".cm-content": { caretColor: "var(--aqmx-text)", paddingBlock: "var(--aqmx-space-6)" },
|
|
27
|
-
".cm-line": { paddingInline: "var(--aqmx-space-6)" },
|
|
28
|
-
"&.cm-focused .cm-cursor": { borderLeftColor: "var(--aqmx-text)" },
|
|
29
|
-
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "var(--aqmx-editor-selection)" },
|
|
30
|
-
".cm-activeLine": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
31
|
-
".cm-gutters": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-editor-gutter)", borderInlineEnd: "var(--aqmx-space-1) solid var(--aqmx-border)" },
|
|
32
|
-
".cm-activeLineGutter": { backgroundColor: "var(--aqmx-editor-active-line)" },
|
|
33
|
-
".cm-searchMatch": { outline: "var(--aqmx-space-1) solid var(--aqmx-border-strong)" },
|
|
34
|
-
".cm-panels": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-text)" }
|
|
35
|
-
}), Z = "data-aqmx-conflict-actions", Be = _.line({ attributes: { "data-aqmx-conflict-line": "marker" } }), He = _.line({ attributes: { "data-aqmx-conflict-line": "ours" } }), Pe = _.line({ attributes: { "data-aqmx-conflict-line": "theirs" } });
|
|
36
|
-
class Ve extends Ne {
|
|
37
|
-
constructor(t, n) {
|
|
38
|
-
super(), this.index = t, this.labels = n;
|
|
39
|
-
}
|
|
40
|
-
index;
|
|
41
|
-
labels;
|
|
42
|
-
eq(t) {
|
|
43
|
-
return t.index === this.index && t.labels === this.labels;
|
|
44
|
-
}
|
|
45
|
-
toDOM(t) {
|
|
46
|
-
const n = document.createElement("div");
|
|
47
|
-
n.setAttribute(Z, String(this.index));
|
|
48
|
-
for (const [s, d] of [
|
|
49
|
-
["ours", this.labels.useOurs],
|
|
50
|
-
["theirs", this.labels.useTheirs],
|
|
51
|
-
["both", this.labels.keepBoth]
|
|
52
|
-
]) {
|
|
53
|
-
const c = document.createElement("button");
|
|
54
|
-
c.type = "button", c.textContent = d, c.setAttribute("data-aqmx-conflict-choice", s), c.addEventListener("mousedown", (a) => a.preventDefault()), c.addEventListener("click", () => {
|
|
55
|
-
const a = I(t.state.doc)[this.index];
|
|
56
|
-
a !== void 0 && (ee(t, a, s), t.focus());
|
|
57
|
-
}), n.append(c);
|
|
58
|
-
}
|
|
59
|
-
return n;
|
|
60
|
-
}
|
|
61
|
-
ignoreEvent() {
|
|
62
|
-
return !0;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const I = (e) => ae(e.iterLines()), j = (e, t) => {
|
|
66
|
-
const n = new Me();
|
|
67
|
-
return I(e).forEach((s, d) => {
|
|
68
|
-
const c = e.line(s.start);
|
|
69
|
-
n.add(c.from, c.from, _.widget({ widget: new Ve(d, t), block: !0, side: -1 }));
|
|
70
|
-
for (let a = s.start; a <= s.end; a += 1) {
|
|
71
|
-
const r = e.line(a).from, p = a === s.start || a === s.separator || a === s.end ? Be : a < s.separator ? He : Pe;
|
|
72
|
-
n.add(r, r, p);
|
|
73
|
-
}
|
|
74
|
-
}), n.finish();
|
|
75
|
-
}, Ke = (e) => Te.define({
|
|
76
|
-
create: (t) => j(t.doc, e),
|
|
77
|
-
update: (t, n) => n.docChanged ? j(n.state.doc, e) : t,
|
|
78
|
-
provide: (t) => w.decorations.from(t)
|
|
79
|
-
}), ee = (e, t, n) => {
|
|
80
|
-
const { doc: s } = e.state, d = (m, l) => {
|
|
81
|
-
const f = [];
|
|
82
|
-
for (let u = m; u <= l; u += 1) f.push(s.line(u).text);
|
|
83
|
-
return f;
|
|
84
|
-
}, c = d(t.start + 1, t.separator - 1), a = d(t.separator + 1, t.end - 1), r = n === "ours" ? c : n === "theirs" ? a : [...c, ...a];
|
|
85
|
-
let p = s.line(t.start).from, o = s.line(t.end).to;
|
|
86
|
-
r.length === 0 && (t.end < s.lines ? o += 1 : t.start > 1 && (p -= 1));
|
|
87
|
-
const i = r.join(`
|
|
88
|
-
`);
|
|
89
|
-
e.dispatch({ changes: { from: p, to: o, insert: i }, selection: H.cursor(p), scrollIntoView: !0, userEvent: "input.resolve" });
|
|
90
|
-
}, We = ({ parent: e, scroll: t, text: n, saved: s, labels: d, onChange: c, onSave: a }) => {
|
|
91
|
-
const r = [
|
|
92
|
-
w.scrollHandler.of((i, m, l) => (je(i, m.head, l, t), !0)),
|
|
93
|
-
Ae(),
|
|
94
|
-
Oe(),
|
|
95
|
-
xe(),
|
|
96
|
-
Ce(),
|
|
97
|
-
Re(),
|
|
98
|
-
Se(),
|
|
99
|
-
w.lineWrapping,
|
|
100
|
-
ye({ base: ke }),
|
|
101
|
-
we(_e),
|
|
102
|
-
Ke(d),
|
|
103
|
-
Ie.of([
|
|
104
|
-
{
|
|
105
|
-
key: "Mod-s",
|
|
106
|
-
preventDefault: !0,
|
|
107
|
-
run: () => (a(), !0)
|
|
108
|
-
},
|
|
109
|
-
...Le,
|
|
110
|
-
...be,
|
|
111
|
-
...ve
|
|
112
|
-
]),
|
|
113
|
-
w.contentAttributes.of({ "aria-label": d.editor, "aria-multiline": "true" }),
|
|
114
|
-
w.updateListener.of((i) => {
|
|
115
|
-
i.docChanged && c();
|
|
116
|
-
}),
|
|
117
|
-
Fe
|
|
118
|
-
], p = Ue(s, r) ?? X.create({ doc: n, extensions: r }), o = new w({ state: p, parent: e });
|
|
119
|
-
return {
|
|
120
|
-
text: () => o.state.doc.toString(),
|
|
121
|
-
replaceText: (i) => {
|
|
122
|
-
const m = o.state.doc.toString();
|
|
123
|
-
if (m === i) return;
|
|
124
|
-
let l = 0;
|
|
125
|
-
const f = Math.min(m.length, i.length);
|
|
126
|
-
for (; l < f && m.charCodeAt(l) === i.charCodeAt(l); ) l += 1;
|
|
127
|
-
let u = 0;
|
|
128
|
-
for (; u < f - l && m.charCodeAt(m.length - 1 - u) === i.charCodeAt(i.length - 1 - u); ) u += 1;
|
|
129
|
-
o.dispatch({ changes: { from: l, to: m.length - u, insert: i.slice(l, i.length - u) }, userEvent: "input.replace" });
|
|
130
|
-
},
|
|
131
|
-
reveal: ({ line: i, column: m }, l) => {
|
|
132
|
-
const { doc: f } = o.state, u = f.line(Math.min(Math.max(i, 1), f.lines)), h = Math.min(u.from + m, u.to);
|
|
133
|
-
o.dispatch({ selection: H.cursor(h), effects: z(o, h, l, t) });
|
|
134
|
-
},
|
|
135
|
-
showLine: (i) => {
|
|
136
|
-
const { doc: m } = o.state, l = m.line(Math.min(Math.max(i, 1), m.lines)).from;
|
|
137
|
-
o.dispatch({ effects: z(o, l, null, t) });
|
|
138
|
-
},
|
|
139
|
-
topLine: () => {
|
|
140
|
-
const i = t.scrollerOf(o.scrollDOM), m = D(i, o.contentDOM), l = V(i) + i.clientHeight, { documentTop: f } = o, { doc: u } = o.state;
|
|
141
|
-
let h = o.lineBlockAtHeight(Math.max(m - f, 0));
|
|
142
|
-
for (; u.lineAt(h.from).text.trim() === "" && h.to < u.length; ) {
|
|
143
|
-
const L = o.lineBlockAt(h.to + 1);
|
|
144
|
-
if (f + L.top >= l) break;
|
|
145
|
-
h = L;
|
|
146
|
-
}
|
|
147
|
-
const y = o.coordsAtPos(h.from), S = y === null ? f + h.top : y.top;
|
|
148
|
-
return { line: o.state.doc.lineAt(h.from).number, clientTop: S, offset: S - m };
|
|
149
|
-
},
|
|
150
|
-
scrollElement: o.scrollDOM,
|
|
151
|
-
focus: () => o.focus(),
|
|
152
|
-
conflicts: () => I(o.state.doc),
|
|
153
|
-
resolveAtCursor: (i) => {
|
|
154
|
-
const m = I(o.state.doc), l = o.state.doc.lineAt(o.state.selection.main.head).number, f = m.find((u) => u.end >= l);
|
|
155
|
-
return f === void 0 ? !1 : (ee(o, f, i), !0);
|
|
156
|
-
},
|
|
157
|
-
nextConflict: () => {
|
|
158
|
-
const i = I(o.state.doc);
|
|
159
|
-
if (i[0] === void 0) return !1;
|
|
160
|
-
const l = o.state.doc.lineAt(o.state.selection.main.head).number, f = i.findIndex((S) => S.start > l), u = f < 0 ? 0 : f, h = o.state.doc.line(i[u].start).from;
|
|
161
|
-
o.dispatch({ selection: H.cursor(h), effects: w.scrollIntoView(h, { y: "center" }) });
|
|
162
|
-
const y = o.contentDOM.querySelector(`[${Z}="${String(u)}"] button`);
|
|
163
|
-
return y instanceof HTMLElement ? y.focus({ preventScroll: !0 }) : o.focus(), !0;
|
|
164
|
-
},
|
|
165
|
-
save: () => o.state.toJSON(Q),
|
|
166
|
-
destroy: () => o.destroy()
|
|
167
|
-
};
|
|
168
|
-
}, z = (e, t, n, s) => {
|
|
169
|
-
const d = s.scrollerOf(e.scrollDOM), c = (n === null ? D(d, e.contentDOM) : n) - V(d);
|
|
170
|
-
return w.scrollIntoView(t, { y: "start", yMargin: c });
|
|
171
|
-
}, je = (e, t, n, s) => {
|
|
172
|
-
const d = ze(e, t), c = s.scrollerOf(e.scrollDOM), a = V(c), r = D(c, e.contentDOM), p = a + c.clientHeight;
|
|
173
|
-
let o = 0;
|
|
174
|
-
switch (n.y) {
|
|
175
|
-
case "start":
|
|
176
|
-
o = d.top - (a + n.yMargin);
|
|
177
|
-
break;
|
|
178
|
-
case "center":
|
|
179
|
-
o = (d.top + d.bottom) / 2 - (r + p) / 2;
|
|
180
|
-
break;
|
|
181
|
-
case "end":
|
|
182
|
-
o = d.bottom - (p - n.yMargin);
|
|
183
|
-
break;
|
|
184
|
-
default:
|
|
185
|
-
d.top < r + n.yMargin ? o = d.top - (r + n.yMargin) : d.bottom > p - n.yMargin && (o = Math.min(d.bottom - (p - n.yMargin), d.top - (r + n.yMargin)));
|
|
186
|
-
}
|
|
187
|
-
if (o !== 0 && (c.scrollTop += o), n.y === "start") return;
|
|
188
|
-
const i = Ge(e, t);
|
|
189
|
-
i !== null && s.reveal(i);
|
|
190
|
-
}, ze = (e, t) => {
|
|
191
|
-
const { node: n, offset: s } = e.domAtPos(t);
|
|
192
|
-
if (n.nodeType === Node.TEXT_NODE) {
|
|
193
|
-
const a = n.ownerDocument?.createRange();
|
|
194
|
-
if (a !== void 0) {
|
|
195
|
-
a.setStart(n, s), a.setEnd(n, s);
|
|
196
|
-
const [r] = a.getClientRects();
|
|
197
|
-
if (r !== void 0 && r.height > 0) return { top: r.top, bottom: r.bottom };
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const d = e.lineBlockAt(t), c = e.documentTop + d.top;
|
|
201
|
-
return { top: c, bottom: c + d.height };
|
|
202
|
-
}, Ge = (e, t) => {
|
|
203
|
-
const { node: n } = e.domAtPos(t);
|
|
204
|
-
for (let s = n instanceof Element ? n : n.parentElement; s !== null; s = s.parentElement)
|
|
205
|
-
if (s.parentElement === e.contentDOM) return s;
|
|
206
|
-
return null;
|
|
207
|
-
}, Ue = (e, t) => {
|
|
208
|
-
if (e == null) return null;
|
|
209
|
-
try {
|
|
210
|
-
return X.fromJSON(e, { extensions: t }, Q);
|
|
211
|
-
} catch {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
}, $e = 610, Je = "[data-aqmd-scroll-container]", Ye = Object.freeze(["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"]), Xe = Object.freeze({ parsed: null, failure: null, busy: !0 }), G = (e, t) => {
|
|
215
|
-
const n = e.querySelector(Je), s = ce(e, t.line);
|
|
216
|
-
n === null || s === null || (n.scrollTop += ue(s, t.line) - (D(n, s) + t.offset));
|
|
217
|
-
}, Qe = ({ path: e, text: t, viewer: n, editorPoint: s, handleRef: d }) => {
|
|
218
|
-
const { data: c, labels: a } = K(), [r, p] = U(Xe), o = A(null);
|
|
219
|
-
N(() => {
|
|
220
|
-
const l = new AbortController();
|
|
221
|
-
p((u) => u.busy ? u : { ...u, busy: !0 });
|
|
222
|
-
const f = setTimeout(() => {
|
|
223
|
-
c.preview(e, t, l.signal).then((u) => {
|
|
224
|
-
l.signal.aborted || !("kind" in u) || (u.kind === "failure" ? p((h) => ({ parsed: h.parsed, failure: u.failure, busy: !1 })) : p({ parsed: { htmlContent: u.htmlContent, headings: [...u.headings] }, failure: null, busy: !1 }));
|
|
225
|
-
});
|
|
226
|
-
}, $e);
|
|
227
|
-
return () => {
|
|
228
|
-
clearTimeout(f), l.abort();
|
|
229
|
-
};
|
|
230
|
-
}, [c, e, t]);
|
|
231
|
-
const i = le(() => {
|
|
232
|
-
const l = o.current, f = s();
|
|
233
|
-
l !== null && f !== null && G(l, f);
|
|
234
|
-
});
|
|
235
|
-
C(() => {
|
|
236
|
-
r.parsed !== null && i();
|
|
237
|
-
}, [r.parsed]), ie(
|
|
238
|
-
d,
|
|
239
|
-
() => ({
|
|
240
|
-
follow: (l) => {
|
|
241
|
-
const f = o.current;
|
|
242
|
-
f !== null && G(f, l);
|
|
243
|
-
}
|
|
244
|
-
}),
|
|
245
|
-
[]
|
|
246
|
-
);
|
|
247
|
-
const m = $(() => ({ ...n, showToc: !1, showStyle: !1, showAlign: !1, renderScrollBar: void 0 }), [n]);
|
|
248
|
-
return /* @__PURE__ */ P("section", { ref: o, className: "aqmx-edit-preview", "aria-label": a.previewRegion, "aria-busy": r.busy, "data-testid": "markdown-explorer-edit-preview", children: [
|
|
249
|
-
r.failure === null ? null : /* @__PURE__ */ x("p", { className: "aqmx-callout aqmx-document-notice", "data-aqmx-tone": "warning", "data-testid": "markdown-explorer-edit-preview-failure", children: a.previewFailed(Y(a, r.failure.reason)) }),
|
|
250
|
-
r.parsed !== null ? /* @__PURE__ */ x("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ x(De, { ...m, parseResult: r.parsed, content: null }) }) : r.failure === null ? /* @__PURE__ */ x("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-preview-skeleton", children: Ye.map((l) => /* @__PURE__ */ x("span", {}, l)) }) : null,
|
|
251
|
-
r.busy ? /* @__PURE__ */ x("p", { className: "aqmx-sr-only", children: a.previewUpdating }) : null
|
|
252
|
-
] });
|
|
253
|
-
}, Ze = 144, et = Object.freeze(["e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"]), tt = (e) => {
|
|
254
|
-
if (typeof e != "object" || e === null) return !1;
|
|
255
|
-
const { generation: t, topLine: n } = e;
|
|
256
|
-
return "state" in e && typeof t == "number" && typeof n == "number";
|
|
257
|
-
}, nt = (e) => {
|
|
258
|
-
e.key === "Escape" && ge(e);
|
|
259
|
-
}, ot = (e) => {
|
|
260
|
-
e.stopPropagation();
|
|
261
|
-
}, gt = (e) => {
|
|
262
|
-
const { path: t, name: n, session: s } = e, { edits: d, labels: c, announcer: a } = K(), { phase: r } = s, p = J(() => d.retry(t), [d, t]);
|
|
263
|
-
switch (N(() => {
|
|
264
|
-
r.kind === "failed" && a.announce(c.documentFailed(n, Y(c, r.failure.reason)));
|
|
265
|
-
}, [r, a, c, n]), r.kind) {
|
|
266
|
-
case "opening":
|
|
267
|
-
return /* @__PURE__ */ P(se, { children: [
|
|
268
|
-
/* @__PURE__ */ x("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-skeleton", children: et.map((o) => /* @__PURE__ */ x("span", {}, o)) }),
|
|
269
|
-
/* @__PURE__ */ x("p", { className: "aqmx-sr-only", children: c.editLoading })
|
|
270
|
-
] });
|
|
271
|
-
case "grant":
|
|
272
|
-
return /* @__PURE__ */ x("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ x(fe, { href: r.href, onRetry: p, testId: "markdown-explorer-edit-grant" }) });
|
|
273
|
-
case "failed":
|
|
274
|
-
return /* @__PURE__ */ x("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ x(de, { failure: r.failure, alert: !1, onRetry: p, testId: "markdown-explorer-edit-failure" }) });
|
|
275
|
-
case "editing":
|
|
276
|
-
return /* @__PURE__ */ x(rt, { ...e });
|
|
277
|
-
}
|
|
278
|
-
}, rt = ({ path: e, name: t, session: n, layout: s, viewer: d, region: c, paneScroll: a }) => {
|
|
279
|
-
const { edits: r, labels: p } = K(), o = A(null), i = A(null), m = A(null), l = me() && s === "fill", [f, u] = U(null), h = A({ layout: s, region: c, paneScroll: a });
|
|
280
|
-
C(() => {
|
|
281
|
-
h.current = { layout: s, region: c, paneScroll: a };
|
|
282
|
-
});
|
|
283
|
-
const y = A(n.generation);
|
|
284
|
-
C(() => {
|
|
285
|
-
y.current = n.generation;
|
|
286
|
-
});
|
|
287
|
-
const S = A(l);
|
|
288
|
-
C(() => {
|
|
289
|
-
S.current = l;
|
|
290
|
-
});
|
|
291
|
-
const L = $(() => ({ editor: p.editorLabel(t), useOurs: p.conflictUseOurs, useTheirs: p.conflictUseTheirs, keepBoth: p.conflictKeepBoth }), [p, t]);
|
|
292
|
-
C(() => {
|
|
293
|
-
const b = o.current, E = r.draft(e);
|
|
294
|
-
if (b === null || E === null) return;
|
|
295
|
-
const q = r.editorState.get(e), O = tt(q) && q.generation === y.current ? q : null;
|
|
296
|
-
let T = null, M = null;
|
|
297
|
-
const B = () => {
|
|
298
|
-
if (T !== null && clearTimeout(T), T = null, M === null) return;
|
|
299
|
-
const v = M.text();
|
|
300
|
-
r.setDraft(e, v), S.current && u(v);
|
|
301
|
-
}, k = We({
|
|
302
|
-
parent: b,
|
|
303
|
-
scroll: {
|
|
304
|
-
scrollerOf: (v) => {
|
|
305
|
-
const { layout: ne, region: oe, paneScroll: re } = h.current, W = oe();
|
|
306
|
-
return ne === "fill" || W === null ? v : re.scrollerOf(W, v);
|
|
307
|
-
},
|
|
308
|
-
reveal: (v) => h.current.paneScroll.reveal(v)
|
|
309
|
-
},
|
|
310
|
-
text: E,
|
|
311
|
-
saved: O === null ? void 0 : O.state,
|
|
312
|
-
labels: L,
|
|
313
|
-
onChange: () => {
|
|
314
|
-
T ??= setTimeout(B, Ze);
|
|
315
|
-
},
|
|
316
|
-
onSave: () => {
|
|
317
|
-
r.save(e);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
M = k, i.current = k;
|
|
321
|
-
const te = r.bindEditor(e, {
|
|
322
|
-
flush: B,
|
|
323
|
-
adopt: (v) => k.replaceText(v),
|
|
324
|
-
returnPoint: () => {
|
|
325
|
-
const v = k.topLine();
|
|
326
|
-
return { line: v.line, clientTop: v.clientTop };
|
|
327
|
-
},
|
|
328
|
-
nextConflict: () => k.nextConflict()
|
|
329
|
-
});
|
|
330
|
-
return O !== null && k.showLine(O.topLine), () => {
|
|
331
|
-
B(), r.editorState.set(e, { state: k.save(), generation: y.current, topLine: k.topLine().line }), te(), k.destroy(), M = null, i.current = null;
|
|
332
|
-
};
|
|
333
|
-
}, [r, e, L]);
|
|
334
|
-
const { request: R } = n;
|
|
335
|
-
C(() => {
|
|
336
|
-
const b = i.current, E = r.draft(e);
|
|
337
|
-
b === null || E === null || R === null || (R.anchor !== null && b.reveal(pe(E, R.anchor), R.anchor.clientTop), b.focus(), r.consumeRequest(e));
|
|
338
|
-
}, [r, e, R, L]), N(() => {
|
|
339
|
-
l && (r.flush(e), u(r.draft(e)));
|
|
340
|
-
}, [r, e, l]);
|
|
341
|
-
const F = J(() => {
|
|
342
|
-
const b = i.current;
|
|
343
|
-
if (b === null) return null;
|
|
344
|
-
const E = b.topLine();
|
|
345
|
-
return { line: E.line, offset: E.offset };
|
|
346
|
-
}, []);
|
|
347
|
-
return N(() => {
|
|
348
|
-
const b = i.current;
|
|
349
|
-
if (!l || b === null) return;
|
|
350
|
-
const E = b.scrollElement;
|
|
351
|
-
let q = 0;
|
|
352
|
-
const O = () => {
|
|
353
|
-
q = 0;
|
|
354
|
-
const M = F();
|
|
355
|
-
M !== null && m.current?.follow(M);
|
|
356
|
-
}, T = () => {
|
|
357
|
-
q === 0 && (q = requestAnimationFrame(O));
|
|
358
|
-
};
|
|
359
|
-
return E.addEventListener("scroll", T, { passive: !0 }), () => {
|
|
360
|
-
E.removeEventListener("scroll", T), cancelAnimationFrame(q);
|
|
361
|
-
};
|
|
362
|
-
}, [l, F, L]),
|
|
363
|
-
/* @__PURE__ */ P("div", { className: "aqmx-edit", "data-aqmx-edit-layout": s, "data-testid": "markdown-explorer-edit", onKeyDown: nt, onDoubleClick: ot, children: [
|
|
364
|
-
/* @__PURE__ */ x("div", { ref: o, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", ...he }),
|
|
365
|
-
l && f !== null ? /* @__PURE__ */ x(Qe, { path: e, text: f, viewer: d, editorPoint: F, handleRef: m }) : null
|
|
366
|
-
] });
|
|
367
|
-
};
|
|
368
|
-
export {
|
|
369
|
-
Ze as DRAFT_WRITE_INTERVAL_MS,
|
|
370
|
-
gt as default
|
|
371
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),p=require("react"),g=require("./index-DJ_FUtYM.cjs"),N=require("@codemirror/commands"),F=require("@codemirror/lang-markdown"),K=require("@codemirror/language"),B=require("@codemirror/search"),A=require("@codemirror/state"),b=require("@codemirror/view"),v=require("@lezer/highlight"),Z=require("@aiquants/markdown"),z={history:N.historyField},ee=K.HighlightStyle.define([{tag:[v.tags.heading1,v.tags.heading2,v.tags.heading3,v.tags.heading4,v.tags.heading5,v.tags.heading6,v.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:v.tags.strong,fontWeight:"700"},{tag:v.tags.emphasis,fontStyle:"italic"},{tag:v.tags.strikethrough,textDecoration:"line-through"},{tag:v.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:v.tags.url,color:"var(--aqmx-syntax-url)"},{tag:v.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:v.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[v.tags.processingInstruction,v.tags.contentSeparator,v.tags.labelName,v.tags.meta],color:"var(--aqmx-syntax-mark)"}]),te=b.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)"}}),G="data-aqmx-conflict-actions",ne=b.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),oe=b.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),re=b.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class se extends b.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(G,String(this.index));for(const[s,d]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const c=document.createElement("button");c.type="button",c.textContent=d,c.setAttribute("data-aqmx-conflict-choice",s),c.addEventListener("mousedown",l=>l.preventDefault()),c.addEventListener("click",()=>{const l=D(t.state.doc)[this.index];l!==void 0&&(U(t,l,s),t.focus())}),n.append(c)}return n}ignoreEvent(){return!0}}const D=e=>g.findConflictsInLines(e.iterLines()),H=(e,t)=>{const n=new A.RangeSetBuilder;return D(e).forEach((s,d)=>{const c=e.line(s.start);n.add(c.from,c.from,b.Decoration.widget({widget:new se(d,t),block:!0,side:-1}));for(let l=s.start;l<=s.end;l+=1){const r=e.line(l).from,h=l===s.start||l===s.separator||l===s.end?ne:l<s.separator?oe:re;n.add(r,r,h)}}),n.finish()},ie=e=>A.StateField.define({create:t=>H(t.doc,e),update:(t,n)=>n.docChanged?H(n.state.doc,e):t,provide:t=>b.EditorView.decorations.from(t)}),U=(e,t,n)=>{const{doc:s}=e.state,d=(m,i)=>{const f=[];for(let u=m;u<=i;u+=1)f.push(s.line(u).text);return f},c=d(t.start+1,t.separator-1),l=d(t.separator+1,t.end-1),r=n==="ours"?c:n==="theirs"?l:[...c,...l];let h=s.line(t.start).from,o=s.line(t.end).to;r.length===0&&(t.end<s.lines?o+=1:t.start>1&&(h-=1));const a=r.join(`
|
|
2
|
-
`);e.dispatch({changes:{from:h,to:o,insert:a},selection:A.EditorSelection.cursor(h),scrollIntoView:!0,userEvent:"input.resolve"})},ae=({parent:e,scroll:t,text:n,saved:s,labels:d,onChange:c,onSave:l})=>{const r=[b.EditorView.scrollHandler.of((a,m,i)=>(le(a,m.head,i,t),!0)),b.lineNumbers(),b.highlightActiveLineGutter(),N.history(),b.drawSelection(),b.highlightActiveLine(),B.highlightSelectionMatches(),b.EditorView.lineWrapping,F.markdown({base:F.markdownLanguage}),K.syntaxHighlighting(ee),ie(d),b.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(l(),!0)},...B.searchKeymap,...N.historyKeymap,...N.defaultKeymap]),b.EditorView.contentAttributes.of({"aria-label":d.editor,"aria-multiline":"true"}),b.EditorView.updateListener.of(a=>{a.docChanged&&c()}),te],h=de(s,r)??A.EditorState.create({doc:n,extensions:r}),o=new b.EditorView({state:h,parent:e});return{text:()=>o.state.doc.toString(),replaceText:a=>{const m=o.state.doc.toString();if(m===a)return;let i=0;const f=Math.min(m.length,a.length);for(;i<f&&m.charCodeAt(i)===a.charCodeAt(i);)i+=1;let u=0;for(;u<f-i&&m.charCodeAt(m.length-1-u)===a.charCodeAt(a.length-1-u);)u+=1;o.dispatch({changes:{from:i,to:m.length-u,insert:a.slice(i,a.length-u)},userEvent:"input.replace"})},reveal:({line:a,column:m},i)=>{const{doc:f}=o.state,u=f.line(Math.min(Math.max(a,1),f.lines)),E=Math.min(u.from+m,u.to);o.dispatch({selection:A.EditorSelection.cursor(E),effects:P(o,E,i,t)})},showLine:a=>{const{doc:m}=o.state,i=m.line(Math.min(Math.max(a,1),m.lines)).from;o.dispatch({effects:P(o,i,null,t)})},topLine:()=>{const a=t.scrollerOf(o.scrollDOM),m=g.visibleTopOf(a,o.contentDOM),i=g.frameTopOf(a)+a.clientHeight,{documentTop:f}=o,{doc:u}=o.state;let E=o.lineBlockAtHeight(Math.max(m-f,0));for(;u.lineAt(E.from).text.trim()===""&&E.to<u.length;){const M=o.lineBlockAt(E.to+1);if(f+M.top>=i)break;E=M}const k=o.coordsAtPos(E.from),L=k===null?f+E.top:k.top;return{line:o.state.doc.lineAt(E.from).number,clientTop:L,offset:L-m}},scrollElement:o.scrollDOM,focus:()=>o.focus(),conflicts:()=>D(o.state.doc),resolveAtCursor:a=>{const m=D(o.state.doc),i=o.state.doc.lineAt(o.state.selection.main.head).number,f=m.find(u=>u.end>=i);return f===void 0?!1:(U(o,f,a),!0)},nextConflict:()=>{const a=D(o.state.doc);if(a[0]===void 0)return!1;const i=o.state.doc.lineAt(o.state.selection.main.head).number,f=a.findIndex(L=>L.start>i),u=f<0?0:f,E=o.state.doc.line(a[u].start).from;o.dispatch({selection:A.EditorSelection.cursor(E),effects:b.EditorView.scrollIntoView(E,{y:"center"})});const k=o.contentDOM.querySelector(`[${G}="${String(u)}"] button`);return k instanceof HTMLElement?k.focus({preventScroll:!0}):o.focus(),!0},save:()=>o.state.toJSON(z),destroy:()=>o.destroy()}},P=(e,t,n,s)=>{const d=s.scrollerOf(e.scrollDOM),c=(n===null?g.visibleTopOf(d,e.contentDOM):n)-g.frameTopOf(d);return b.EditorView.scrollIntoView(t,{y:"start",yMargin:c})},le=(e,t,n,s)=>{const d=ce(e,t),c=s.scrollerOf(e.scrollDOM),l=g.frameTopOf(c),r=g.visibleTopOf(c,e.contentDOM),h=l+c.clientHeight;let o=0;switch(n.y){case"start":o=d.top-(l+n.yMargin);break;case"center":o=(d.top+d.bottom)/2-(r+h)/2;break;case"end":o=d.bottom-(h-n.yMargin);break;default:d.top<r+n.yMargin?o=d.top-(r+n.yMargin):d.bottom>h-n.yMargin&&(o=Math.min(d.bottom-(h-n.yMargin),d.top-(r+n.yMargin)))}if(o!==0&&(c.scrollTop+=o),n.y==="start")return;const a=ue(e,t);a!==null&&s.reveal(a)},ce=(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[r]=l.getClientRects();if(r!==void 0&&r.height>0)return{top:r.top,bottom:r.bottom}}}const d=e.lineBlockAt(t),c=e.documentTop+d.top;return{top:c,bottom:c+d.height}},ue=(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},de=(e,t)=>{if(e==null)return null;try{return A.EditorState.fromJSON(e,{extensions:t},z)}catch{return null}},fe=610,me="[data-aqmd-scroll-container]",he=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),pe=Object.freeze({parsed:null,failure:null,busy:!0}),W=(e,t)=>{const n=e.querySelector(me),s=g.blockAtLine(e,t.line);n===null||s===null||(n.scrollTop+=g.lineTopIn(s,t.line)-(g.visibleTopOf(n,s)+t.offset))},ge=({path:e,text:t,viewer:n,editorPoint:s,handleRef:d})=>{const{data:c,labels:l}=g.useExplorer(),[r,h]=p.useState(pe),o=p.useRef(null);p.useEffect(()=>{const i=new AbortController;h(u=>u.busy?u:{...u,busy:!0});const f=setTimeout(()=>{c.preview(e,t,i.signal).then(u=>{i.signal.aborted||!("kind"in u)||(u.kind==="failure"?h(E=>({parsed:E.parsed,failure:u.failure,busy:!1})):h({parsed:{htmlContent:u.htmlContent,headings:[...u.headings]},failure:null,busy:!1}))})},fe);return()=>{clearTimeout(f),i.abort()}},[c,e,t]);const a=p.useEffectEvent(()=>{const i=o.current,f=s();i!==null&&f!==null&&W(i,f)});p.useLayoutEffect(()=>{r.parsed!==null&&a()},[r.parsed]),p.useImperativeHandle(d,()=>({follow:i=>{const f=o.current;f!==null&&W(f,i)}}),[]);const m=p.useMemo(()=>({...n,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0}),[n]);return x.jsxs("section",{ref:o,className:"aqmx-edit-preview","aria-label":l.previewRegion,"aria-busy":r.busy,"data-testid":"markdown-explorer-edit-preview",children:[r.failure===null?null:x.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:l.previewFailed(g.failureTitleOf(l,r.failure.reason))}),r.parsed!==null?x.jsx("div",{className:"aqmx-document-viewer",children:x.jsx(Z.MarkdownViewer,{...m,parseResult:r.parsed,content:null})}):r.failure===null?x.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:he.map(i=>x.jsx("span",{},i))}):null,r.busy?x.jsx("p",{className:"aqmx-sr-only",children:l.previewUpdating}):null]})},$=144,xe=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),Ee=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"},be=e=>{e.key==="Escape"&&g.consumeKey(e)},ve=e=>{e.stopPropagation()},ye=e=>{const{path:t,name:n,session:s}=e,{edits:d,labels:c,announcer:l}=g.useExplorer(),{phase:r}=s,h=p.useCallback(()=>d.retry(t),[d,t]);switch(p.useEffect(()=>{r.kind==="failed"&&l.announce(c.documentFailed(n,g.failureTitleOf(c,r.failure.reason)))},[r,l,c,n]),r.kind){case"opening":return x.jsxs(x.Fragment,{children:[x.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:xe.map(o=>x.jsx("span",{},o))}),x.jsx("p",{className:"aqmx-sr-only",children:c.editLoading})]});case"grant":return x.jsx("div",{className:"aqmx-edit-message",children:x.jsx(g.EditGrantNotice,{href:r.href,onRetry:h,testId:"markdown-explorer-edit-grant"})});case"failed":return x.jsx("div",{className:"aqmx-edit-message",children:x.jsx(g.FailureView,{failure:r.failure,alert:!1,onRetry:h,testId:"markdown-explorer-edit-failure"})});case"editing":return x.jsx(we,{...e})}},we=({path:e,name:t,session:n,layout:s,viewer:d,region:c,paneScroll:l})=>{const{edits:r,labels:h}=g.useExplorer(),o=p.useRef(null),a=p.useRef(null),m=p.useRef(null),i=g.usePreviewShown()&&s==="fill",[f,u]=p.useState(null),E=p.useRef({layout:s,region:c,paneScroll:l});p.useLayoutEffect(()=>{E.current={layout:s,region:c,paneScroll:l}});const k=p.useRef(n.generation);p.useLayoutEffect(()=>{k.current=n.generation});const L=p.useRef(i);p.useLayoutEffect(()=>{L.current=i});const M=p.useMemo(()=>({editor:h.editorLabel(t),useOurs:h.conflictUseOurs,useTheirs:h.conflictUseTheirs,keepBoth:h.conflictKeepBoth}),[h,t]);p.useLayoutEffect(()=>{const y=o.current,q=r.draft(e);if(y===null||q===null)return;const S=r.editorState.get(e),C=Ee(S)&&S.generation===k.current?S:null;let O=null,R=null;const _=()=>{if(O!==null&&clearTimeout(O),O=null,R===null)return;const w=R.text();r.setDraft(e,w),L.current&&u(w)},T=ae({parent:y,scroll:{scrollerOf:w=>{const{layout:Y,region:X,paneScroll:Q}=E.current,V=X();return Y==="fill"||V===null?w:Q.scrollerOf(V,w)},reveal:w=>E.current.paneScroll.reveal(w)},text:q,saved:C===null?void 0:C.state,labels:M,onChange:()=>{O??=setTimeout(_,$)},onSave:()=>{r.save(e)}});R=T,a.current=T;const J=r.bindEditor(e,{flush:_,adopt:w=>T.replaceText(w),returnPoint:()=>{const w=T.topLine();return{line:w.line,clientTop:w.clientTop}},nextConflict:()=>T.nextConflict()});return C!==null&&T.showLine(C.topLine),()=>{_(),r.editorState.set(e,{state:T.save(),generation:k.current,topLine:T.topLine().line}),J(),T.destroy(),R=null,a.current=null}},[r,e,M]);const{request:I}=n;p.useLayoutEffect(()=>{const y=a.current,q=r.draft(e);y===null||q===null||I===null||(I.anchor!==null&&y.reveal(g.positionInSource(q,I.anchor),I.anchor.clientTop),y.focus(),r.consumeRequest(e))},[r,e,I,M]),p.useEffect(()=>{i&&(r.flush(e),u(r.draft(e)))},[r,e,i]);const j=p.useCallback(()=>{const y=a.current;if(y===null)return null;const q=y.topLine();return{line:q.line,offset:q.offset}},[]);return p.useEffect(()=>{const y=a.current;if(!i||y===null)return;const q=y.scrollElement;let S=0;const C=()=>{S=0;const R=j();R!==null&&m.current?.follow(R)},O=()=>{S===0&&(S=requestAnimationFrame(C))};return q.addEventListener("scroll",O,{passive:!0}),()=>{q.removeEventListener("scroll",O),cancelAnimationFrame(S)}},[i,j,M]),x.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":s,"data-testid":"markdown-explorer-edit",onKeyDown:be,onDoubleClick:ve,children:[x.jsx("div",{ref:o,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",...g.ALLOW_KEY_REPEAT}),i&&f!==null?x.jsx(ge,{path:e,text:f,viewer:d,editorPoint:j,handleRef:m}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=$;exports.default=ye;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),X=/[\u0000-\u001f\u007f]/u,C=/\p{Cs}/u,U=e=>{const t=e.split("/").filter(n=>n!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!C.test(e)&&!X.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),H=/(?:%[0-9A-Fa-f]{2})+/gu,z=new TextDecoder("utf-8"),F=/[/\\]/u,M=e=>e.replace(H,t=>z.decode(Uint8Array.from(t.slice(1).split("%").map(n=>Number.parseInt(n,16))))),V=e=>{const t=[e];let n=e;for(let r=0;r<3&&n.includes("%");r+=1){const o=M(n);if(o===n)break;t.push(o),n=o}return t.map(x)},G=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},y=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(G),n=o=>o!==""&&t.some(i=>i.test(o)),r=o=>o!==""&&V(o).some(i=>n(i)||i.split(F).some(n));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},K=y(b),Y=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),W=e=>e===void 0?K:e===!1?Y:y(e),J=(e,t)=>y(e).deniesPath(t),m=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),Q=Object.freeze(["file","directory"]),q=Object.freeze(["video","audio","pdf"]),B=Object.freeze(["info","warning","danger"]),Z=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),ee=1e4,c=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),te=Object.freeze(["http:","https:","mailto:"]),_=1024,ne=/^[a-z0-9-]{1,64}$/u,re="https://relative.invalid/",h=64,E=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>E(m,e),oe=e=>E(Q,e),P=e=>E(q,e),se=e=>E(B,e),ie=e=>E(Z,e),A=e=>typeof e=="string"&&ne.test(e),ae=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,re).protocol)}catch{return!1}},f=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:n}=e;return T(t)?n!==void 0&&!A(n)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(n)}`:null:`unknown failure reason ${s(t)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:n,type:r,mimeType:o,modifiedAt:i,children:a,lazy:l}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof n!="string"||!R(n)?"an entry needs an acceptable path":oe(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:l!==void 0&&typeof l!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":r==="file"&&(a!==void 0||l===!0)?"a file entry cannot have children or be lazy":l===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:n,failure:r}=e;return t==="ok"?Array.isArray(n)&&n.every(N):t==="error"&&f(r)===null},le=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:n,failure:r}=e;return t==="ok"?n===null||D(n):t==="error"&&f(r)===null},D=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,ce=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:n,ancestors:r,failure:o}=e;return t==="ok"?n===null&&r===null||typeof n=="string"&&n!==""&&D(r):t==="error"&&f(o)===null},ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:n}=e;return t==="ok"&&!(Number.isSafeInteger(n)&&n>=0)?!1:L(e)},g=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:n,id:r}=e;return typeof t!="string"||typeof r!="string"?"a heading needs text and id strings":typeof n!="number"||!Number.isInteger(n)||n<O.min||n>O.max?`a heading depth must be an integer in 1..6; got ${String(n)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:n}=t;if(!ie(n))return`unknown document kind ${s(n)}`;if(n==="failure")return f(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(n){case"markdown":{const{htmlContent:r,headings:o}=t;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=g(i);if(a!==null)return a}return de(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":c(t.url)?null:"a text document needs a root-relative url";case"image":return c(t.url)?null:"an image document needs a root-relative url";case"media":return c(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"file":return c(t.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,fe=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),de=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:n}=e;return t==="inline"?n===void 0?null:"an inline edit carries no href":t!=="external"?`unknown edit kind ${s(t)}`:Ee(n)?null:`an external edit needs an absolute https: href; got ${s(n)}`},Ee=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},u=e=>typeof e=="string"&&e.length>0&&e.length<=_,pe=e=>c(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:n,size:r,author:o,kept:i,current:a}=e;return u(t)?n!==null&&(typeof n!="string"||Number.isNaN(Date.parse(n)))?`a revision's modifiedAt must be a date-time string or null; got ${s(n)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${s(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},p=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const n=e,{kind:r}=n;if(r==="failure")return f(n.failure);if(typeof r!="string"||!t.includes(r))return`unexpected answer kind ${s(r)}`;switch(r){case"grant":return pe(n);case"edit":return typeof n.text!="string"||typeof n.history!="boolean"?"an edit source needs text and history":u(n.version)?null:`an edit source needs a version; got ${s(n.version)}`;case"saved":return u(n.version)?null:`a saved answer needs a version; got ${s(n.version)}`;case"conflict":return typeof n.text!="string"?"a conflict needs the current text":u(n.version)?null:`a conflict needs the current version; got ${s(n.version)}`;case"preview":{const{htmlContent:o,headings:i}=n;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const l=g(a);if(l!==null)return l}return null}case"revisions":{if(!Array.isArray(n.revisions))return"revisions need an array";for(const o of n.revisions){const i=k(o);if(i!==null)return i}return null}case"revision":return typeof n.text!="string"?"a revision answer needs text":u(n.id)?null:`a revision answer needs an id; got ${s(n.id)}`;default:return`unexpected answer kind ${s(r)}`}},Re=Object.freeze(["edit","grant"]),ye=Object.freeze(["saved","conflict","grant"]),me=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),Ae=Object.freeze(["revision"]),ge=e=>p(e,Re)===null,Oe=e=>p(e,ye)===null,he=e=>p(e,me)===null,be=e=>p(e,_e)===null,xe=e=>p(e,Ae)===null,Te=(e,t)=>({kind:"failure",failure:I(e,t)}),I=(e,t)=>A(t)?{reason:e,code:t}:{reason:e},Pe=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),d=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Se="asset",Ne="link-card",Le=(e,t,n)=>{const r=`${e}/${Se}?${d.path}=${encodeURIComponent(t)}`;return n===null?r:`${r}&${d.version}=${encodeURIComponent(n)}`},$="text",De=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${d.display}=${$}`},ve=e=>{const t=e.getAll(d.display);return t.length===0?"file":t.length===1&&t[0]===$?"text":null},we=e=>`${e}/${Ne}`,ke="X-Markdown-Explorer-Scope",Ie="X-Markdown-Explorer",$e="refresh",je="edit",Xe="text/markdown",Ce=e=>Pe.includes(e),j=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),Ue=e=>{const[t,...n]=m.filter(r=>j[r]===e);return t!==void 0&&n.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=d;exports.EXPLORER_DRAFT_MEDIA_TYPE=Xe;exports.EXPLORER_EDIT_PROOF=je;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=m;exports.EXPLORER_FAILURE_STATUS=j;exports.EXPLORER_LINK_PROTOCOLS=te;exports.EXPLORER_MAX_HEADINGS=ee;exports.EXPLORER_PROOF_HEADER=Ie;exports.EXPLORER_REFRESH_PROOF=$e;exports.EXPLORER_SCOPE_HEADER=ke;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.entryViolation=S;exports.explorerAssetHref=Le;exports.explorerLinkCardEndpoint=we;exports.explorerPlainTextHref=De;exports.failureDocument=Te;exports.failureOf=I;exports.failureReasonOfStatus=Ue;exports.failureViolation=f;exports.headingViolation=g;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=ae;exports.isDeniedPath=J;exports.isExplorerAncestorsResult=le;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=Ce;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=ge;exports.isExplorerEditToken=u;exports.isExplorerFailureCode=A;exports.isExplorerFailureReason=T;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=se;exports.isExplorerPreviewAnswer=he;exports.isExplorerRevealResult=ce;exports.isExplorerRevisionAnswer=xe;exports.isExplorerRevisionsAnswer=be;exports.isExplorerSaveAnswer=Oe;exports.isExplorerTextAnswer=fe;exports.isExplorerTreeResult=ue;exports.isRootRelativeUrl=c;exports.lastPathSegment=U;exports.readExplorerAssetDisplay=ve;exports.resolvePathRules=W;exports.revisionViolation=k;
|