@aiquants/markdown-explorer 0.6.0 → 0.7.1

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +58 -8
  3. package/dist/EditSurface-5nbW7NTP.cjs +2 -0
  4. package/dist/EditSurface-CaS1O6Nt.js +371 -0
  5. package/dist/{ExplorerSplit-CN5TvRj6.js → ExplorerSplit-C9Y02nvj.js} +391 -417
  6. package/dist/ExplorerSplit-D60N3_X7.cjs +1 -0
  7. package/dist/MultiLayout-CqTyFZ_i.cjs +1 -0
  8. package/dist/MultiLayout-DBpUTcCQ.js +947 -0
  9. package/dist/{NativeScrollBar-DYEv2GLV.js → NativeScrollBar-CiVlg2ob.js} +1 -1
  10. package/dist/{NativeScrollBar-CHEQgaVx.cjs → NativeScrollBar-QlOtnddZ.cjs} +1 -1
  11. package/dist/TreeLayout-bk-Ziybl.js +29 -0
  12. package/dist/TreeLayout-uwvAgr-t.cjs +1 -0
  13. package/dist/client/MarkdownExplorer.d.cts +2 -1
  14. package/dist/client/MarkdownExplorer.d.ts +2 -1
  15. package/dist/client/storage.d.cts +1 -0
  16. package/dist/client/storage.d.ts +1 -0
  17. package/dist/core/contracts.d.cts +58 -0
  18. package/dist/core/contracts.d.ts +58 -0
  19. package/dist/core/labels.d.cts +49 -0
  20. package/dist/core/labels.d.ts +49 -0
  21. package/dist/core/location.d.cts +7 -0
  22. package/dist/core/location.d.ts +7 -0
  23. package/dist/dataRoute-CcZ8PK00.cjs +1 -0
  24. package/dist/dataRoute-D1vE1wFW.js +270 -0
  25. package/dist/index-Dlkzr6Zn.cjs +13 -0
  26. package/dist/index-etFEpIE_.js +3199 -0
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.cts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +31 -30
  31. package/dist/location-DmzVAFvo.cjs +1 -0
  32. package/dist/{location-CtM94G0O.js → location-Q4sgRrUm.js} +202 -193
  33. package/dist/merge-BR4jKpIc.cjs +5 -0
  34. package/dist/merge-DfI0ro2L.js +20 -0
  35. package/dist/sanitizeWorker.cjs +1 -1
  36. package/dist/sanitizeWorker.js +173 -172
  37. package/dist/server/errors.d.cts +1 -1
  38. package/dist/server/errors.d.ts +1 -1
  39. package/dist/server/ports.d.cts +33 -1
  40. package/dist/server/ports.d.ts +33 -1
  41. package/dist/server.cjs +1 -1
  42. package/dist/server.d.cts +1 -1
  43. package/dist/server.d.ts +1 -1
  44. package/dist/server.js +882 -751
  45. package/dist/{storage-DA4ItHzl.js → storage-BSthKLSG.js} +14 -13
  46. package/dist/storage-Dgi4JXaB.cjs +1 -0
  47. package/dist/storage.cjs +1 -1
  48. package/dist/storage.js +1 -1
  49. package/dist/styles/markdown-explorer.css +1 -1
  50. package/docs/behavior/dom-hooks.md +17 -3
  51. package/docs/behavior/layout.md +6 -1
  52. package/docs/behavior/security.md +11 -1
  53. package/docs/behavior/url-contract.md +13 -4
  54. package/package.json +11 -3
  55. package/dist/ExplorerSplit-CUIbSLQm.cjs +0 -1
  56. package/dist/MultiLayout-BDcQSpa6.cjs +0 -1
  57. package/dist/MultiLayout-hPmV-bae.js +0 -922
  58. package/dist/TreeLayout-BDaIyoGT.cjs +0 -1
  59. package/dist/TreeLayout-CqzxLpoM.js +0 -23
  60. package/dist/dataRoute-CUXlMhUJ.cjs +0 -1
  61. package/dist/dataRoute-Ce6EIuu4.js +0 -206
  62. package/dist/index-B3nShkkt.cjs +0 -3
  63. package/dist/index-gJp1iXTc.js +0 -2238
  64. package/dist/location-FavgY_gB.cjs +0 -1
  65. package/dist/storage-Bkb2Axdi.cjs +0 -1
@@ -0,0 +1,371 @@
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-etFEpIE_.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
+ };