@aiquants/markdown-explorer 0.34.0 → 0.36.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.
Files changed (146) hide show
  1. package/CHANGELOG.md +608 -0
  2. package/README.md +121 -41
  3. package/dist/EditSurface-B70iRFkG.cjs +6 -0
  4. package/dist/EditSurface-BCFJRyIM.js +990 -0
  5. package/dist/ExplorerSplit-BNrHrIus.cjs +2 -0
  6. package/dist/ExplorerSplit-Bgccz2nm.js +1589 -0
  7. package/dist/MultiLayout-Bo9LAXiY.cjs +1 -0
  8. package/dist/{MultiLayout-kcZyVnvK.js → MultiLayout-Dy5TIC2t.js} +249 -248
  9. package/dist/{NativeScrollBar-pUbA4Zq3.cjs → NativeScrollBar-Bj-LKej0.cjs} +1 -1
  10. package/dist/{NativeScrollBar-UNed10Na.js → NativeScrollBar-DpZMYhmf.js} +2 -2
  11. package/dist/TreeLayout-DsSKW_Qj.js +103 -0
  12. package/dist/TreeLayout-T8sc_wg7.cjs +1 -0
  13. package/dist/client/MarkdownExplorer.d.cts +14 -1
  14. package/dist/client/MarkdownExplorer.d.ts +14 -1
  15. package/dist/client/edit/lineEndings.d.cts +4 -0
  16. package/dist/client/edit/lineEndings.d.ts +4 -0
  17. package/dist/client/hostContract.d.cts +67 -0
  18. package/dist/client/hostContract.d.ts +67 -0
  19. package/dist/core/config.d.cts +13 -0
  20. package/dist/core/config.d.ts +13 -0
  21. package/dist/core/contracts.d.cts +31 -4
  22. package/dist/core/contracts.d.ts +31 -4
  23. package/dist/core/dataRoute.d.cts +5 -1
  24. package/dist/core/dataRoute.d.ts +5 -1
  25. package/dist/core/documentId.d.cts +6 -0
  26. package/dist/core/documentId.d.ts +6 -0
  27. package/dist/core/draftAnswer.d.cts +23 -0
  28. package/dist/core/draftAnswer.d.ts +23 -0
  29. package/dist/core/labels.d.cts +78 -0
  30. package/dist/core/labels.d.ts +78 -0
  31. package/dist/core/location.d.cts +22 -2
  32. package/dist/core/location.d.ts +22 -2
  33. package/dist/core/ownUrls.d.cts +15 -0
  34. package/dist/core/ownUrls.d.ts +15 -0
  35. package/dist/core/treeSettings.d.cts +3 -2
  36. package/dist/core/treeSettings.d.ts +3 -2
  37. package/dist/core/viewSettings.d.cts +3 -1
  38. package/dist/core/viewSettings.d.ts +3 -1
  39. package/dist/describeValue-CLlVRO8d.js +17 -0
  40. package/dist/describeValue-Ccvhbt36.cjs +1 -0
  41. package/dist/explorerCore-B3RGmMG6.js +1083 -0
  42. package/dist/explorerCore-CUkyKtm8.cjs +1 -0
  43. package/dist/index-D0l_BJqb.js +5980 -0
  44. package/dist/index-lpL7GltU.cjs +18 -0
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.d.cts +8 -4
  47. package/dist/index.d.ts +8 -4
  48. package/dist/index.js +53 -43
  49. package/dist/licenses/@heroicons/react/LICENSE +21 -0
  50. package/dist/licenses/entities/LICENSE +11 -0
  51. package/dist/licenses/parse5/LICENSE +19 -0
  52. package/dist/location-Dh6K-y7w.js +761 -0
  53. package/dist/location-DrOP6t1F.cjs +1 -0
  54. package/dist/lru-DC8GBmkX.js +39 -0
  55. package/dist/lru-SGmUyBQU.cjs +1 -0
  56. package/dist/{merge-C1MWvhCS.js → merge-BwcqBd4c.js} +1 -1
  57. package/dist/{merge-BziXxZkE.cjs → merge-Dckw7r9T.cjs} +1 -1
  58. package/dist/nestingGuardWorker.js +5511 -0
  59. package/dist/ownUrls-BTPGNhBt.cjs +1 -0
  60. package/dist/ownUrls-DD0cSCsF.js +409 -0
  61. package/dist/sanitizeJob-BYqzjFJC.js +21 -0
  62. package/dist/sanitizeJob-CudE1RUP.cjs +1 -0
  63. package/dist/sanitizePolicy-C-ehd0J_.cjs +2 -0
  64. package/dist/sanitizePolicy-DAPnUUVm.js +139 -0
  65. package/dist/sanitizeWorker.cjs +1 -1
  66. package/dist/sanitizeWorker.js +134 -139
  67. package/dist/sanitizerService-B8v4ap9t.js +240 -0
  68. package/dist/sanitizerService-DomN7lwC.cjs +1 -0
  69. package/dist/server/assetResponse.d.cts +60 -0
  70. package/dist/server/assetResponse.d.ts +60 -0
  71. package/dist/server/browser/browserPlatform.d.cts +12 -0
  72. package/dist/server/browser/browserPlatform.d.ts +12 -0
  73. package/dist/server/createMarkdownExplorer.d.cts +0 -10
  74. package/dist/server/createMarkdownExplorer.d.ts +0 -10
  75. package/dist/server/errors.d.cts +1 -1
  76. package/dist/server/errors.d.ts +1 -1
  77. package/dist/server/explorerCore.d.cts +12 -0
  78. package/dist/server/explorerCore.d.ts +12 -0
  79. package/dist/server/fileSystemSource.d.cts +1 -0
  80. package/dist/server/fileSystemSource.d.ts +1 -0
  81. package/dist/server/inProcessFetch.d.cts +5 -0
  82. package/dist/server/inProcessFetch.d.ts +5 -0
  83. package/dist/server/platform.d.cts +18 -0
  84. package/dist/server/platform.d.ts +18 -0
  85. package/dist/server/ports.d.cts +55 -5
  86. package/dist/server/ports.d.ts +55 -5
  87. package/dist/server/sanitizeProtocol.d.cts +3 -0
  88. package/dist/server/sanitizeProtocol.d.ts +3 -0
  89. package/dist/server/sanitizer.d.cts +5 -40
  90. package/dist/server/sanitizer.d.ts +5 -40
  91. package/dist/server/sanitizerOptions.d.cts +24 -0
  92. package/dist/server/sanitizerOptions.d.ts +24 -0
  93. package/dist/server/sanitizerService.d.cts +41 -0
  94. package/dist/server/sanitizerService.d.ts +41 -0
  95. package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
  96. package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
  97. package/dist/server.cjs +1 -1
  98. package/dist/server.d.cts +3 -1
  99. package/dist/server.d.ts +3 -1
  100. package/dist/server.js +270 -1343
  101. package/dist/serverBrowser.cjs +1 -0
  102. package/dist/serverBrowser.d.cts +1 -0
  103. package/dist/serverBrowser.d.ts +1 -0
  104. package/dist/serverBrowser.js +120 -0
  105. package/dist/serverCore.cjs +1 -0
  106. package/dist/serverCore.d.cts +14 -0
  107. package/dist/serverCore.d.ts +14 -0
  108. package/dist/serverCore.js +46 -0
  109. package/dist/storage-BpYsprog.cjs +1 -0
  110. package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
  111. package/dist/storage.cjs +1 -1
  112. package/dist/storage.js +1 -1
  113. package/dist/styles/markdown-explorer.css +1 -1
  114. package/dist/{tapScrollCircle-DigcJCsu.cjs → tapScrollCircle-DyLInGck.cjs} +1 -1
  115. package/dist/{tapScrollCircle-D_BpaLwY.js → tapScrollCircle-smKLgRa2.js} +1 -1
  116. package/dist/testing.cjs +1 -0
  117. package/dist/testing.d.cts +11 -0
  118. package/dist/testing.d.ts +11 -0
  119. package/dist/testing.js +82 -0
  120. package/dist/useSplitPersistence-BUa_KMsV.cjs +1 -0
  121. package/dist/useSplitPersistence-pnb21dsr.js +44 -0
  122. package/docs/behavior/dom-hooks.md +5 -1
  123. package/docs/behavior/hosting.md +123 -0
  124. package/docs/behavior/layout.md +5 -3
  125. package/docs/behavior/localization.md +25 -8
  126. package/docs/behavior/security.md +55 -15
  127. package/docs/behavior/url-contract.md +30 -3
  128. package/package.json +48 -10
  129. package/dist/EditSurface-CF82jZQg.cjs +0 -6
  130. package/dist/EditSurface-CqHk2R3k.js +0 -982
  131. package/dist/ExplorerSplit-D325YGEf.cjs +0 -1
  132. package/dist/ExplorerSplit-DGH9bckm.js +0 -1500
  133. package/dist/MultiLayout-CzR7yJ0m.cjs +0 -1
  134. package/dist/TreeLayout-BnIU87HX.js +0 -96
  135. package/dist/TreeLayout-DtvIpuOe.cjs +0 -1
  136. package/dist/dataRoute-D6KiSHIc.js +0 -298
  137. package/dist/dataRoute-DwYtgyt6.cjs +0 -1
  138. package/dist/index-BDCbvHDs.cjs +0 -15
  139. package/dist/index-DR31S_-4.js +0 -5012
  140. package/dist/location-C44b9H1S.js +0 -676
  141. package/dist/location-hGLhCCg4.cjs +0 -1
  142. package/dist/sanitizePolicy-CwvyPpp5.js +0 -98
  143. package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
  144. package/dist/storage-DM0EvkVf.cjs +0 -1
  145. package/dist/useSplitPersistence-DCeYbJMx.js +0 -38
  146. package/dist/useSplitPersistence-QGcvyMAa.cjs +0 -1
@@ -0,0 +1,990 @@
1
+ import { jsx as q, jsxs as re, Fragment as Ze } from "react/jsx-runtime";
2
+ import { useState as oe, useRef as N, useLayoutEffect as D, useEffectEvent as Ee, useEffect as Ve, useImperativeHandle as et, useMemo as Y, startTransition as tt, useCallback as J, useId as nt } from "react";
3
+ import { v as ie, k as ge, l as rt, u as ae, m as ot, n as it, o as st, p as He, q as lt, t as ct, w as at, c as ut, x as dt, E as ft, y as mt, z as pt, A as ht, B as gt, G as xe, H as Se, I as vt, J as wt, K as ye, L as bt, M as Et, O as xt, Q as St } from "./index-D0l_BJqb.js";
4
+ import { fencedBodyAsRead as yt, planFencedBodyEdit as kt, fencedCodeLanguageOf as Tt, SPREADSHEETS_LANGUAGE as At, readFencedLine as It, listItemWidthOn as Ot, openingFenceOn as Ct } from "@aiquants/markdown/code-blocks";
5
+ import { history as Lt, historyKeymap as Mt, defaultKeymap as qt, historyField as Rt, redo as _t, undo as Pt, isolateHistory as Nt } from "@codemirror/commands";
6
+ import { markdown as Dt, markdownLanguage as Bt } from "@codemirror/lang-markdown";
7
+ import { syntaxHighlighting as Vt, syntaxTreeAvailable as Ht, HighlightStyle as zt, ensureSyntaxTree as ze } from "@codemirror/language";
8
+ import { highlightSelectionMatches as Ft, searchKeymap as Gt } from "@codemirror/search";
9
+ import { EditorState as Fe, EditorSelection as he, StateField as Ut, RangeSetBuilder as Wt, MapMode as Kt } from "@codemirror/state";
10
+ import { EditorView as $, lineNumbers as $t, highlightActiveLineGutter as Xt, drawSelection as jt, highlightActiveLine as Yt, keymap as Jt, ViewPlugin as Qt, Decoration as ue, WidgetType as Zt } from "@codemirror/view";
11
+ import { tags as _ } from "@lezer/highlight";
12
+ import { MarkdownViewer as en } from "@aiquants/markdown";
13
+ import { SOURCE_LINES_ATTRIBUTE as Ge, parseSourceLines as tn } from "@aiquants/markdown/source-lines";
14
+ import { U as nn, k as se, E as rn } from "./ownUrls-DD0cSCsF.js";
15
+ import { H as on, c as sn, M as ln } from "./sanitizePolicy-DAPnUUVm.js";
16
+ import cn from "isomorphic-dompurify";
17
+ import { o as an, C as un, F as dn, E as fn, m as mn, n as le, q as pn } from "./location-Dh6K-y7w.js";
18
+ import { d as hn } from "./describeValue-CLlVRO8d.js";
19
+ import { PanelGroup as gn, Panel as ke, PanelResizeHandle as vn } from "@aiquants/resize-panels";
20
+ import { t as wn, u as bn } from "./useSplitPersistence-pnb21dsr.js";
21
+ const Ue = { history: Rt }, En = zt.define([
22
+ { tag: [_.heading1, _.heading2, _.heading3, _.heading4, _.heading5, _.heading6, _.heading], color: "var(--aqmx-syntax-heading)", fontWeight: "700" },
23
+ { tag: _.strong, fontWeight: "700" },
24
+ { tag: _.emphasis, fontStyle: "italic" },
25
+ { tag: _.strikethrough, textDecoration: "line-through" },
26
+ { tag: _.link, color: "var(--aqmx-syntax-link)", textDecoration: "underline" },
27
+ { tag: _.url, color: "var(--aqmx-syntax-url)" },
28
+ { tag: _.monospace, color: "var(--aqmx-syntax-code)" },
29
+ { tag: _.quote, color: "var(--aqmx-syntax-quote)" },
30
+ { tag: [_.processingInstruction, _.contentSeparator, _.labelName, _.meta], color: "var(--aqmx-syntax-mark)" }
31
+ ]), xn = $.theme({
32
+ "&": { height: "100%", color: "var(--aqmx-text)", backgroundColor: "var(--aqmx-surface)", fontSize: "var(--aqmx-font-size-title)" },
33
+ "&.cm-focused": { outline: "none" },
34
+ ".cm-scroller": { fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', lineHeight: "var(--aqmx-line-height-prose)" },
35
+ ".cm-content": { caretColor: "var(--aqmx-text)", paddingBlock: "var(--aqmx-space-6)" },
36
+ ".cm-line": { paddingInline: "var(--aqmx-space-6)" },
37
+ "&.cm-focused .cm-cursor": { borderLeftColor: "var(--aqmx-text)" },
38
+ "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: "var(--aqmx-editor-selection)" },
39
+ ".cm-activeLine": { backgroundColor: "var(--aqmx-editor-active-line)" },
40
+ ".cm-gutters": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-editor-gutter)", borderInlineEnd: "var(--aqmx-space-1) solid var(--aqmx-border)" },
41
+ ".cm-activeLineGutter": { backgroundColor: "var(--aqmx-editor-active-line)" },
42
+ ".cm-searchMatch": { outline: "var(--aqmx-space-1) solid var(--aqmx-border-strong)" },
43
+ ".cm-panels": { backgroundColor: "var(--aqmx-surface-raised)", color: "var(--aqmx-text)" }
44
+ }), We = "data-aqmx-conflict-actions", Sn = ue.line({ attributes: { "data-aqmx-conflict-line": "marker" } }), yn = ue.line({ attributes: { "data-aqmx-conflict-line": "ours" } }), kn = ue.line({ attributes: { "data-aqmx-conflict-line": "theirs" } });
45
+ class Tn extends Zt {
46
+ constructor(t, n) {
47
+ super(), this.index = t, this.labels = n;
48
+ }
49
+ index;
50
+ labels;
51
+ eq(t) {
52
+ return t.index === this.index && t.labels === this.labels;
53
+ }
54
+ toDOM(t) {
55
+ const n = document.createElement("div");
56
+ n.setAttribute(We, String(this.index));
57
+ for (const [o, i] of [
58
+ ["ours", this.labels.useOurs],
59
+ ["theirs", this.labels.useTheirs],
60
+ ["both", this.labels.keepBoth]
61
+ ]) {
62
+ const r = document.createElement("button");
63
+ r.type = "button", r.textContent = i, r.setAttribute("data-aqmx-conflict-choice", o), r.addEventListener("mousedown", (l) => l.preventDefault()), r.addEventListener("click", () => {
64
+ const l = ne(t.state.doc)[this.index];
65
+ l !== void 0 && (Ke(t, l, o), t.focus());
66
+ }), n.append(r);
67
+ }
68
+ return n;
69
+ }
70
+ ignoreEvent() {
71
+ return !0;
72
+ }
73
+ }
74
+ const ne = (e) => rt(e.iterLines()), Te = (e, t) => {
75
+ const n = new Wt();
76
+ return ne(e).forEach((o, i) => {
77
+ const r = e.line(o.start);
78
+ n.add(r.from, r.from, ue.widget({ widget: new Tn(i, t), block: !0, side: -1 }));
79
+ for (let l = o.start; l <= o.end; l += 1) {
80
+ const s = e.line(l).from, f = l === o.start || l === o.separator || l === o.end ? Sn : l < o.separator ? yn : kn;
81
+ n.add(s, s, f);
82
+ }
83
+ }), n.finish();
84
+ }, An = (e) => Ut.define({
85
+ create: (t) => Te(t.doc, e),
86
+ update: (t, n) => n.docChanged ? Te(n.state.doc, e) : t,
87
+ provide: (t) => $.decorations.from(t)
88
+ }), Ke = (e, t, n) => {
89
+ const { doc: o } = e.state, i = (w, c) => {
90
+ const v = [];
91
+ for (let u = w; u <= c; u += 1) v.push(o.line(u).text);
92
+ return v;
93
+ }, r = i(t.start + 1, t.separator - 1), l = i(t.separator + 1, t.end - 1), s = n === "ours" ? r : n === "theirs" ? l : [...r, ...l];
94
+ let f = o.line(t.start).from, d = o.line(t.end).to;
95
+ s.length === 0 && (t.end < o.lines ? d += 1 : t.start > 1 && (f -= 1));
96
+ const b = s.join(`
97
+ `);
98
+ e.dispatch({ changes: { from: f, to: d, insert: b }, selection: he.cursor(f), scrollIntoView: !0, userEvent: "input.resolve" });
99
+ }, Ae = "input.preview", In = 20, On = Qt.fromClass(
100
+ class {
101
+ constructor(e) {
102
+ this.view = e, this.schedule();
103
+ }
104
+ view;
105
+ cancel = null;
106
+ update(e) {
107
+ e.docChanged && this.schedule();
108
+ }
109
+ schedule() {
110
+ if (this.cancel !== null || Ht(this.view.state)) return;
111
+ const e = this.view.dom.ownerDocument.defaultView;
112
+ if (e === null) return;
113
+ const t = () => {
114
+ this.cancel = null, ze(this.view.state, this.view.state.doc.length, In), this.schedule();
115
+ };
116
+ if (typeof e.requestIdleCallback == "function") {
117
+ const n = e.requestIdleCallback(t);
118
+ this.cancel = () => e.cancelIdleCallback(n);
119
+ } else {
120
+ const n = e.setTimeout(t, 0);
121
+ this.cancel = () => e.clearTimeout(n);
122
+ }
123
+ }
124
+ destroy() {
125
+ this.cancel?.(), this.cancel = null;
126
+ }
127
+ }
128
+ ), Cn = /`{3,}|~{3,}/u, ee = Object.freeze({ kind: "absent" }), me = Object.freeze({ kind: "unreadable" }), Ln = (e, t, n) => {
129
+ const o = [];
130
+ for (let f = t.parent; f !== null; f = f.parent)
131
+ (f.name === "Blockquote" || f.name === "ListItem") && o.unshift(f);
132
+ const i = [], r = [], l = (f) => {
133
+ const d = r.indexOf(f);
134
+ return d === -1 ? r.length : d;
135
+ };
136
+ for (const f of o) {
137
+ const d = e.lineAt(f.from).number;
138
+ if (f.name === "ListItem") {
139
+ const b = Ot(e.line(d).text, i, l(d));
140
+ if (b === null) return null;
141
+ i.push({ kind: "listItem", width: b });
142
+ } else
143
+ i.push({ kind: "quote" });
144
+ r.push(d);
145
+ }
146
+ const s = Ct(n.text, i, l(n.number));
147
+ return s === null ? null : { containers: i, ...s };
148
+ }, Mn = (e, t) => {
149
+ const { doc: n } = e;
150
+ let o = n.lineAt(t).to;
151
+ for (; ; ) {
152
+ const i = ze(e, o, Number.POSITIVE_INFINITY);
153
+ if (i === null) return null;
154
+ const r = i.resolveInner(t, 1), l = r.parent;
155
+ if (r.name !== "CodeMark" || l === null || l.name !== "FencedCode" || l.from !== r.from) return null;
156
+ if (l.to < o || o >= n.length) return l;
157
+ o = Math.min(n.length, l.to + Math.max(l.to - t, 1));
158
+ }
159
+ }, Ie = (e, t) => {
160
+ const { doc: n } = e;
161
+ if (!Number.isInteger(t) || t < 1 || t > n.lines) return ee;
162
+ const o = n.line(t), i = Cn.exec(o.text);
163
+ if (i === null) return ee;
164
+ const r = Mn(e, o.from + i.index);
165
+ if (r === null) return ee;
166
+ const l = r.getChild("CodeInfo");
167
+ if (l === null) return ee;
168
+ const s = Tt(n.sliceString(l.from, l.to));
169
+ if (s === null) return me;
170
+ if (s !== At) return ee;
171
+ const f = Ln(n, r, o);
172
+ if (f === null) return me;
173
+ const [, ...d] = r.getChildren("CodeMark"), b = d.at(-1), w = b === void 0 ? n.lineAt(r.to).number : n.lineAt(b.from).number - 1, c = [];
174
+ let v = "";
175
+ for (let u = t + 1; u <= w; u += 1) {
176
+ const m = n.line(u).text, h = It(m, f);
177
+ if (h === null) return me;
178
+ c.push(m), v += u < n.lines ? `${h.content}
179
+ ` : h.content;
180
+ }
181
+ return { kind: "found", firstLine: t + 1, lines: c, layout: f, body: v };
182
+ }, qn = ({ parent: e, scroll: t, text: n, saved: o, labels: i, revisions: r, onChange: l, onGeometry: s, onSave: f }) => {
183
+ let d = !1;
184
+ const b = [
185
+ $.scrollHandler.of((u, m, h) => (Rn(u, m.head, h, t), !0)),
186
+ $t(),
187
+ Xt(),
188
+ Lt(),
189
+ jt(),
190
+ Yt(),
191
+ Ft(),
192
+ $.lineWrapping,
193
+ Dt({ base: Bt }),
194
+ On,
195
+ Vt(En),
196
+ An(i),
197
+ Jt.of([
198
+ {
199
+ key: "Mod-s",
200
+ preventDefault: !0,
201
+ run: () => (f(), !0)
202
+ },
203
+ ...Gt,
204
+ ...Mt,
205
+ ...qt
206
+ ]),
207
+ $.contentAttributes.of({ "aria-label": i.editor, "aria-multiline": "true" }),
208
+ $.updateListener.of((u) => {
209
+ for (const m of u.transactions) m.docChanged && r.record(m.changes, m.newDoc);
210
+ u.docChanged && l(u.transactions.every((m) => !m.docChanged || m.isUserEvent(Ae))), (u.docChanged || u.heightChanged || u.geometryChanged) && s(u.docChanged && !d);
211
+ }),
212
+ xn
213
+ ], w = Nn(o, b) ?? Fe.create({ doc: n, extensions: b }), c = new $({ state: w, parent: e });
214
+ r.mount(c.state.doc);
215
+ const v = (u) => {
216
+ d = !0;
217
+ try {
218
+ u();
219
+ } finally {
220
+ d = !1;
221
+ }
222
+ };
223
+ return {
224
+ text: () => c.state.doc.toString(),
225
+ replaceText: (u) => {
226
+ const m = c.state.doc.toString();
227
+ if (m === u) return;
228
+ let h = 0;
229
+ const x = Math.min(m.length, u.length);
230
+ for (; h < x && m.charCodeAt(h) === u.charCodeAt(h); ) h += 1;
231
+ let p = 0;
232
+ for (; p < x - h && m.charCodeAt(m.length - 1 - p) === u.charCodeAt(u.length - 1 - p); ) p += 1;
233
+ c.dispatch({ changes: { from: h, to: m.length - p, insert: u.slice(h, u.length - p) }, userEvent: "input.replace" });
234
+ },
235
+ replaceBody: (u, m, h, x) => {
236
+ const { doc: p } = c.state, S = r.lineOf(x, u);
237
+ if (S === null) return "changed";
238
+ const I = Ie(c.state, S);
239
+ if (I.kind === "absent") return "changed";
240
+ if (I.kind === "unreadable") return "unwritable";
241
+ if (I.body !== yt(m, I.layout)) return "changed";
242
+ const k = kt(I.lines, I.layout, h);
243
+ if (k.kind !== "edit") return k.kind;
244
+ if (k.from === k.to && k.lines.length === 0) return "written";
245
+ const R = (z) => {
246
+ const V = I.firstLine + z;
247
+ return V <= p.lines ? p.line(V).from : p.length;
248
+ }, L = R(k.from), B = `${L === p.length && p.sliceString(p.length - 1) !== `
249
+ ` ? `
250
+ ` : ""}${k.lines.map((z) => `${z}
251
+ `).join("")}`;
252
+ return v(() => c.dispatch({ changes: { from: L, to: R(k.to), insert: B }, userEvent: Ae, annotations: Nt.of("full") })), "written";
253
+ },
254
+ readBody: (u, m) => {
255
+ const h = r.lineOf(m, u);
256
+ if (h === null) return null;
257
+ const x = Ie(c.state, h);
258
+ return x.kind === "found" ? x.body : null;
259
+ },
260
+ undo: () => v(() => Pt(c)),
261
+ redo: () => v(() => _t(c)),
262
+ reveal: ({ line: u, column: m }, h) => {
263
+ const { doc: x } = c.state, p = x.line(Math.min(Math.max(u, 1), x.lines)), S = Math.min(p.from + m, p.to);
264
+ c.dispatch({ selection: he.cursor(S), effects: Oe(c, S, h, t) });
265
+ },
266
+ showLine: (u) => {
267
+ const { doc: m } = c.state, h = m.line(Math.min(Math.max(u, 1), m.lines)).from;
268
+ c.dispatch({ effects: Oe(c, h, null, t) });
269
+ },
270
+ topLine: () => {
271
+ const u = t.scrollerOf(c.scrollDOM), m = ie(u, c.contentDOM), h = ge(u) + u.clientHeight, { documentTop: x } = c, { doc: p } = c.state;
272
+ let S = c.lineBlockAtHeight(Math.max(m - x, 0));
273
+ for (; p.lineAt(S.from).text.trim() === "" && S.to < p.length; ) {
274
+ const R = c.lineBlockAt(S.to + 1);
275
+ if (x + R.top >= h) break;
276
+ S = R;
277
+ }
278
+ const I = c.coordsAtPos(S.from), k = I === null ? x + S.top : I.top;
279
+ return { line: c.state.doc.lineAt(S.from).number, clientTop: k, offset: k - m };
280
+ },
281
+ lineSpans: (u) => {
282
+ const m = c.scrollDOM, h = m.scrollTop + c.documentTop - ie(m, c.contentDOM), { doc: x } = c.state, p = (S) => x.line(Math.min(Math.max(S, 1), x.lines)).from;
283
+ return u.map(({ first: S, last: I }) => ({ top: h + c.lineBlockAt(p(S)).top, bottom: h + c.lineBlockAt(p(I)).bottom }));
284
+ },
285
+ scrollElement: c.scrollDOM,
286
+ focus: () => c.focus(),
287
+ conflicts: () => ne(c.state.doc),
288
+ resolveAtCursor: (u) => {
289
+ const m = ne(c.state.doc), h = c.state.doc.lineAt(c.state.selection.main.head).number, x = m.find((p) => p.end >= h);
290
+ return x === void 0 ? !1 : (Ke(c, x, u), !0);
291
+ },
292
+ nextConflict: () => {
293
+ const u = ne(c.state.doc);
294
+ if (u[0] === void 0) return !1;
295
+ const h = c.state.doc.lineAt(c.state.selection.main.head).number, x = u.findIndex((k) => k.start > h), p = x < 0 ? 0 : x, S = c.state.doc.line(u[p].start).from;
296
+ c.dispatch({ selection: he.cursor(S), effects: $.scrollIntoView(S, { y: "center" }) });
297
+ const I = c.contentDOM.querySelector(`[${We}="${String(p)}"] button`);
298
+ return I instanceof HTMLElement ? I.focus({ preventScroll: !0 }) : c.focus(), !0;
299
+ },
300
+ save: () => c.state.toJSON(Ue),
301
+ destroy: () => c.destroy()
302
+ };
303
+ }, Oe = (e, t, n, o) => {
304
+ const i = o.scrollerOf(e.scrollDOM), r = (n === null ? ie(i, e.contentDOM) : n) - ge(i);
305
+ return $.scrollIntoView(t, { y: "start", yMargin: r });
306
+ }, Rn = (e, t, n, o) => {
307
+ const i = _n(e, t), r = o.scrollerOf(e.scrollDOM), l = ge(r), s = ie(r, e.contentDOM), f = l + r.clientHeight;
308
+ let d = 0;
309
+ switch (n.y) {
310
+ case "start":
311
+ d = i.top - (l + n.yMargin);
312
+ break;
313
+ case "center":
314
+ d = (i.top + i.bottom) / 2 - (s + f) / 2;
315
+ break;
316
+ case "end":
317
+ d = i.bottom - (f - n.yMargin);
318
+ break;
319
+ default:
320
+ i.top < s + n.yMargin ? d = i.top - (s + n.yMargin) : i.bottom > f - n.yMargin && (d = Math.min(i.bottom - (f - n.yMargin), i.top - (s + n.yMargin)));
321
+ }
322
+ if (d !== 0 && (r.scrollTop += d), n.y === "start") return;
323
+ const b = Pn(e, t);
324
+ b !== null && o.reveal(b);
325
+ }, _n = (e, t) => {
326
+ const { node: n, offset: o } = e.domAtPos(t);
327
+ if (n.nodeType === Node.TEXT_NODE) {
328
+ const l = n.ownerDocument?.createRange();
329
+ if (l !== void 0) {
330
+ l.setStart(n, o), l.setEnd(n, o);
331
+ const [s] = l.getClientRects();
332
+ if (s !== void 0 && s.height > 0) return { top: s.top, bottom: s.bottom };
333
+ }
334
+ }
335
+ const i = e.lineBlockAt(t), r = e.documentTop + i.top;
336
+ return { top: r, bottom: r + i.height };
337
+ }, Pn = (e, t) => {
338
+ const { node: n } = e.domAtPos(t);
339
+ for (let o = n instanceof Element ? n : n.parentElement; o !== null; o = o.parentElement)
340
+ if (o.parentElement === e.contentDOM) return o;
341
+ return null;
342
+ }, Nn = (e, t) => {
343
+ if (e == null) return null;
344
+ try {
345
+ return Fe.fromJSON(e, { extensions: t }, Ue);
346
+ } catch {
347
+ return null;
348
+ }
349
+ }, Dn = 610, Bn = 987, Ce = Object.freeze({ kind: "unavailable" }), Vn = "true", Hn = "false", zn = (e) => e === Vn ? !0 : e === Hn ? !1 : null, Fn = (e) => {
350
+ const t = new DOMParser().parseFromString(e, "text/html"), n = [];
351
+ for (const o of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")) {
352
+ const i = o.localName === "img", r = o.getAttribute(i ? "data-asset-src" : "data-doc-path");
353
+ r !== null && n.push({ target: { kind: i ? "asset" : "doc", path: r }, exists: zn(o.getAttribute(i ? "data-asset-exists" : "data-doc-exists")) });
354
+ }
355
+ return n;
356
+ }, Gn = ({ path: e, instant: t, preview: n, initial: o, onView: i }) => {
357
+ const r = new AbortController(), l = { asset: /* @__PURE__ */ new Map(), doc: /* @__PURE__ */ new Map() };
358
+ let s = o, f = null, d = !1, b = !1, w = null, c = null, v = [], u, m = !1, h, x = null;
359
+ const p = (g) => {
360
+ g.parsed === s.parsed && g.source === s.source && g.failure === s.failure && g.busy === s.busy && g.tier === s.tier || (s = g, i(g));
361
+ }, S = (g, E) => {
362
+ d || (d = !0, console.error(`[markdown-explorer] ${g}`, ...E === void 0 ? [] : [E]));
363
+ }, I = (g) => {
364
+ if (t !== null)
365
+ for (const { target: E, exists: C } of t.marksOf(g)) l[E.kind].set(E.path, C);
366
+ }, k = () => {
367
+ clearTimeout(h), h = void 0, x?.abort(), x = null;
368
+ }, R = () => {
369
+ c = null, v = [], clearTimeout(u), u = void 0;
370
+ }, L = (g, E) => {
371
+ p({ ...s, failure: g, busy: !1, tier: E });
372
+ }, G = () => {
373
+ clearTimeout(u), u = v.length === 0 ? void 0 : setTimeout(z, Bn);
374
+ }, B = () => {
375
+ if (t === null || c === null) return;
376
+ const g = c, E = [], C = { asset: /* @__PURE__ */ new Set(), doc: /* @__PURE__ */ new Set() };
377
+ let U;
378
+ try {
379
+ U = t.sanitize(g.html, (F) => {
380
+ const de = l[F.kind].get(F.path);
381
+ return de === void 0 && !C[F.kind].has(F.path) && (C[F.kind].add(F.path), E.push(F)), de ?? void 0;
382
+ });
383
+ } catch (F) {
384
+ R(), F instanceof on ? L(se("too-large"), "instant") : (S("the draft sanitizer failed", F), L(se("failed"), "instant"));
385
+ return;
386
+ }
387
+ v = E;
388
+ const X = s.parsed !== null && s.parsed.htmlContent === U && s.parsed.headings === g.headings ? s.parsed : { htmlContent: U, headings: g.headings };
389
+ p({ parsed: X, source: g.draft, failure: null, busy: !1, tier: "instant" }), G();
390
+ }, z = () => {
391
+ if (u = void 0, m || c === null || v.length === 0) return;
392
+ m = !0;
393
+ const g = v;
394
+ n(e, c.draft.text, r.signal).then((E) => {
395
+ if (m = !1, !(r.signal.aborted || !("kind" in E))) {
396
+ E.kind === "preview" && I(E.htmlContent);
397
+ for (const C of g) l[C.kind].has(C.path) || l[C.kind].set(C.path, null);
398
+ B();
399
+ }
400
+ });
401
+ }, V = (g) => {
402
+ k(), R(), p({ ...s, busy: !0, tier: "server" });
403
+ const E = new AbortController();
404
+ x = E, h = setTimeout(() => {
405
+ h = void 0, n(e, g.text, E.signal).then((C) => {
406
+ if (!(E.signal.aborted || !("kind" in C))) {
407
+ if (x = null, C.kind === "failure") {
408
+ L(C.failure, "server");
409
+ return;
410
+ }
411
+ I(C.htmlContent), p({ parsed: { htmlContent: C.htmlContent, headings: C.headings }, source: g, failure: null, busy: !1, tier: "server" });
412
+ }
413
+ });
414
+ }, Dn);
415
+ }, a = async (g, E) => {
416
+ let C;
417
+ try {
418
+ C = await g.convert({ path: e, text: E }, r.signal);
419
+ } catch (X) {
420
+ return r.signal.aborted || S("the draft converter rejected a conversion, which its contract allows only once the signal aborted", X), Ce;
421
+ }
422
+ const U = nn(C);
423
+ return U === null ? C : (S(`the draft converter answered outside its contract: ${U}`), Ce);
424
+ }, T = (g, E) => {
425
+ switch (E.kind) {
426
+ case "preview":
427
+ if (k(), E.headings.length > rn) {
428
+ R(), L(se("too-large"), "instant");
429
+ return;
430
+ }
431
+ c = { draft: g, html: E.htmlContent, headings: E.headings.map(({ text: C, depth: U, id: X }) => ({ text: C, depth: U, id: X })) }, B();
432
+ return;
433
+ case "failure":
434
+ k(), R(), L(se(E.failure.reason, E.failure.code), "instant");
435
+ return;
436
+ case "unavailable":
437
+ V(g);
438
+ return;
439
+ }
440
+ }, A = async (g) => {
441
+ b = !0;
442
+ try {
443
+ for (; w !== null && !r.signal.aborted; ) {
444
+ const E = w;
445
+ w = null;
446
+ const C = await a(g, E.text);
447
+ if (r.signal.aborted) return;
448
+ T(E, C);
449
+ }
450
+ } finally {
451
+ b = !1;
452
+ }
453
+ };
454
+ return t !== null && t.seed !== null && I(t.seed), {
455
+ update: (g) => {
456
+ if (!(r.signal.aborted || g.text === f?.text)) {
457
+ if (f = g, clearTimeout(u), u = void 0, t === null) {
458
+ V(g);
459
+ return;
460
+ }
461
+ w = g, b || A(t.converter);
462
+ }
463
+ },
464
+ dispose: () => {
465
+ r.abort(), w = null, clearTimeout(u), u = void 0, k();
466
+ }
467
+ };
468
+ }, Un = (e) => sn(cn(window), e.iframeHosts, e.dataPath, ln, an(e)), Wn = (e, t) => e.flatMap((n, o) => {
469
+ const i = t[o];
470
+ return i === void 0 ? [] : [
471
+ { editor: i.top, preview: n.top },
472
+ { editor: i.bottom, preview: n.bottom }
473
+ ];
474
+ }), j = (e, t) => {
475
+ const n = e[t];
476
+ if (n === void 0) throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length - 1)}; got ${hn(t)}`);
477
+ return n;
478
+ }, Kn = (e) => {
479
+ const t = [];
480
+ for (const o of e) {
481
+ let i = 0, r = t.length;
482
+ for (; i < r; ) {
483
+ const l = i + r >> 1;
484
+ j(t, l).pair.preview <= o.preview ? i = l + 1 : r = l;
485
+ }
486
+ t[i] = { pair: o, before: i === 0 ? void 0 : j(t, i - 1) };
487
+ }
488
+ const n = [];
489
+ for (let o = t.at(-1); o !== void 0; o = o.before) n.push(o.pair);
490
+ return n.reverse();
491
+ }, $n = (e, t) => {
492
+ const n = Math.max(t.editorMax, 0), o = Math.max(t.previewMax, 0), i = n - t.editorViewport, r = o - t.previewViewport, l = e.filter((d) => d.editor > 0 && d.editor < i && d.preview > 0 && d.preview < r).sort((d, b) => d.editor - b.editor || d.preview - b.preview);
493
+ let s = { editor: 0, preview: 0 };
494
+ const f = [s];
495
+ for (const d of Kn(l))
496
+ d.editor > s.editor && d.preview > s.preview && (f.push(d), s = d);
497
+ return f.push({ editor: n, preview: o }), {
498
+ toPreview: (d) => Le(f, "editor", "preview", d),
499
+ toEditor: (d) => Le(f, "preview", "editor", d)
500
+ };
501
+ }, Le = (e, t, n, o) => {
502
+ const i = j(e, 0), r = j(e, e.length - 1);
503
+ if (Number.isNaN(o) || o <= i[t]) return i[n];
504
+ if (o >= r[t]) return r[n];
505
+ let l = 0, s = e.length - 1;
506
+ for (; s - l > 1; ) {
507
+ const b = l + s >> 1;
508
+ j(e, b)[t] <= o ? l = b : s = b;
509
+ }
510
+ const f = j(e, l), d = j(e, s);
511
+ return f[n] + (d[n] - f[n]) * (o - f[t]) / (d[t] - f[t]);
512
+ }, Xn = 610, Me = 89, qe = 0.5, jn = ({ editor: e, preview: t, previewBlocks: n, editorSpans: o, requestFrame: i, cancelFrame: r, now: l }) => {
513
+ let s = "editor", f = 0, d = null, b = null, w = !1, c = null, v = null;
514
+ const u = { editor: 0, preview: 0 }, m = { editor: null, preview: null };
515
+ let h = null, x = () => {
516
+ };
517
+ const p = (a) => {
518
+ d !== null && a !== d || (s = a, f = l() + Xn);
519
+ }, S = (a, T) => {
520
+ a !== s && d === null && l() >= f && !I(a, T) && (s = a), B();
521
+ }, I = (a, T) => {
522
+ const A = m[a];
523
+ return l() < u[a] || A !== null && Math.abs(T.position() - A) < qe;
524
+ }, k = e.onScroll(() => S("editor", e)), R = e.onIntent(() => p("editor")), L = () => {
525
+ const a = t();
526
+ return a !== h && (x(), h = a, x = a === null ? () => {
527
+ } : G(a)), a;
528
+ }, G = (a) => {
529
+ const T = a.onScroll(() => S("preview", a)), A = a.onIntent(() => p("preview"));
530
+ return () => {
531
+ T(), A();
532
+ };
533
+ }, B = () => {
534
+ !w && b === null && (b = i(z));
535
+ }, z = () => {
536
+ b = null;
537
+ const a = L();
538
+ a !== null && (c ??= n(), v ??= $n(Wn(c, o(c)), { editorMax: e.max(), previewMax: a.max(), editorViewport: e.viewport(), previewViewport: a.viewport() }), s === "editor" ? V(a, "preview", v.toPreview(e.position())) : V(e, "editor", v.toEditor(a.position())));
539
+ }, V = (a, T, A) => {
540
+ if (Math.abs(a.position() - A) < qe) {
541
+ m[T] = a.position();
542
+ return;
543
+ }
544
+ u[T] = l() + Me, m[T] = a.scrollTo(A);
545
+ };
546
+ return B(), {
547
+ editorChanged: (a) => {
548
+ v = null, a && p("editor"), B();
549
+ },
550
+ previewChanged: () => {
551
+ c = null, v = null, u.preview = l() + Me, B();
552
+ },
553
+ showAlone: (a) => {
554
+ d = a, !(a === null || a === s) && (s = a, f = 0, B());
555
+ },
556
+ dispose: () => {
557
+ w = !0, b !== null && r(b), b = null, k(), R(), x();
558
+ }
559
+ };
560
+ }, Re = Object.freeze(["wheel", "pointerdown", "keydown", "focusin"]), $e = (e) => ({
561
+ position: () => e.scrollTop,
562
+ max: () => Math.max(e.scrollHeight - e.clientHeight, 0),
563
+ viewport: () => e.clientHeight,
564
+ scrollTo: (t) => (e.scrollTo({ top: t, behavior: "instant" }), e.scrollTop),
565
+ onScroll: (t) => (e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t)),
566
+ onIntent: (t) => {
567
+ for (const n of Re) e.addEventListener(n, t, { capture: !0, passive: !0 });
568
+ return () => {
569
+ for (const n of Re) e.removeEventListener(n, t, { capture: !0 });
570
+ };
571
+ }
572
+ }), te = "[data-aqmd-scroll-container]", Yn = "[data-aqmd-content]", Jn = `[${Ge}]`, Qn = Object.freeze(["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"]), Xe = (e, t) => {
573
+ const n = lt(e.peek(t));
574
+ return n !== null && n.document.kind === "markdown" ? { htmlContent: n.document.htmlContent, headings: n.document.headings } : null;
575
+ }, Zn = (e, t, n, o) => {
576
+ if (t === void 0) return null;
577
+ let i;
578
+ try {
579
+ i = Un(e);
580
+ } catch (r) {
581
+ return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview", r), null;
582
+ }
583
+ return { converter: t, sanitize: i, marksOf: Fn, seed: Xe(n, o)?.htmlContent ?? null };
584
+ }, er = (e) => {
585
+ const t = [];
586
+ let n = null;
587
+ for (const o of e.querySelectorAll(Jn)) {
588
+ const i = tn(o.getAttribute(Ge));
589
+ if (i === null || o.getClientRects().length === 0) continue;
590
+ n ??= e.scrollTop - ie(e, o);
591
+ const { top: r, bottom: l } = o.getBoundingClientRect();
592
+ t.push({ first: i.first, last: i.last, top: n + r, bottom: n + l });
593
+ }
594
+ return t;
595
+ }, tr = ({ path: e, readDraft: t, viewer: n, tables: o, concealed: i, onEditAt: r, onLayout: l, handleRef: s }) => {
596
+ const { config: f, data: d, documents: b, draftConverter: w, labels: c } = ae(), [v, u] = oe(() => ({ parsed: Xe(b, e), source: null, failure: null, busy: !0, tier: w === void 0 ? "server" : "instant" })), m = N(null), h = N(null), x = N(v);
597
+ D(() => {
598
+ x.current = v;
599
+ });
600
+ const p = Ee(() => t());
601
+ Ve(() => {
602
+ const a = Zn(f, w, b, e), T = p(), A = Gn({ path: e, instant: a, preview: d.preview, initial: x.current, onView: (g) => tt(() => u(g)) });
603
+ return h.current = A, A.update(T), () => {
604
+ A.dispose(), h.current = null;
605
+ };
606
+ }, [f, d, b, w, e]);
607
+ const S = Ee(() => l());
608
+ D(() => {
609
+ v.parsed !== null && S();
610
+ }, [v.parsed]);
611
+ const I = v.parsed !== null;
612
+ D(() => {
613
+ const a = I ? m.current?.querySelector(te) : null;
614
+ if (!(a instanceof HTMLElement)) return;
615
+ a.tabIndex = 0;
616
+ const T = new ResizeObserver(() => S());
617
+ T.observe(a);
618
+ const A = a.querySelector(Yn);
619
+ return A !== null && T.observe(A), () => T.disconnect();
620
+ }, [I]);
621
+ const k = N(null);
622
+ et(
623
+ s,
624
+ () => ({
625
+ draft: (a) => {
626
+ h.current?.update(a);
627
+ },
628
+ scrollPort: () => {
629
+ const a = m.current?.querySelector(te);
630
+ return a instanceof HTMLElement ? (k.current?.scroller !== a && (k.current = { scroller: a, port: $e(a) }), k.current.port) : null;
631
+ },
632
+ blocks: () => {
633
+ const a = m.current?.querySelector(te);
634
+ return a instanceof HTMLElement ? er(a) : [];
635
+ },
636
+ focus: () => {
637
+ const a = m.current?.querySelector(te);
638
+ a instanceof HTMLElement && a.focus({ preventScroll: !0 });
639
+ },
640
+ anchor: (a) => {
641
+ const T = m.current, A = T?.querySelector(te);
642
+ return T === null || !(A instanceof HTMLElement) ? null : st(T, a(A));
643
+ },
644
+ place: ({ line: a, clientTop: T }, A) => {
645
+ const g = m.current, E = g === null ? null : ot(g, a);
646
+ E !== null && (A(E).scrollTop += it(E, a) - T);
647
+ }
648
+ }),
649
+ []
650
+ );
651
+ const R = (a) => {
652
+ const T = m.current, { target: A } = a;
653
+ if (r === void 0 || T === null || !(A instanceof Element) || !ct(A)) return;
654
+ const g = at(A, T, T.ownerDocument.getSelection());
655
+ g !== null && r(g);
656
+ }, L = v.source === null ? null : v.source.revision, G = Y(
657
+ () => L === null ? void 0 : {
658
+ write: (a) => o.write(L, a),
659
+ read: (a) => o.read(L, a),
660
+ undo: o.undo,
661
+ redo: o.redo,
662
+ subscribe: o.subscribe
663
+ },
664
+ [o, L]
665
+ ), B = Y(() => ({ ...n.labels, spreadsheetReadOnly: c.previewTablePending }), [n.labels, c.previewTablePending]), z = Y(
666
+ () => ({
667
+ ...n,
668
+ labels: G === void 0 ? B : n.labels,
669
+ showToc: !1,
670
+ showStyle: !1,
671
+ showAlign: !1,
672
+ showMeasure: !1,
673
+ showContentColors: !1,
674
+ renderScrollBar: void 0,
675
+ scrollBarGutter: void 0,
676
+ scrollBarInlineSize: void 0,
677
+ spreadsheetEditor: G
678
+ }),
679
+ [n, B, G]
680
+ ), V = Y(
681
+ () => v.parsed === null ? null : /* @__PURE__ */ q("div", { className: "aqmx-document-viewer", children: /* @__PURE__ */ q(en, { ...z, parseResult: v.parsed, content: null }) }),
682
+ [z, v.parsed]
683
+ );
684
+ return /* @__PURE__ */ re(
685
+ "section",
686
+ {
687
+ ref: m,
688
+ className: "aqmx-edit-preview",
689
+ "aria-label": c.previewRegion,
690
+ "aria-busy": v.busy,
691
+ inert: i !== null,
692
+ hidden: i === "removed",
693
+ "data-aqmx-preview-tier": v.tier,
694
+ "data-testid": "markdown-explorer-edit-preview",
695
+ onDoubleClick: r === void 0 ? void 0 : R,
696
+ children: [
697
+ v.failure === null ? null : /* @__PURE__ */ q("p", { className: "aqmx-callout aqmx-document-notice", "data-aqmx-tone": "warning", "data-testid": "markdown-explorer-edit-preview-failure", children: c.previewFailed(He(c, v.failure.reason)) }),
698
+ V ?? (v.failure === null ? /* @__PURE__ */ q("div", { className: "aqmx-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-edit-preview-skeleton", children: Qn.map((a) => /* @__PURE__ */ q("span", {}, a)) }) : null),
699
+ v.busy ? /* @__PURE__ */ q("p", { className: "aqmx-sr-only", children: c.previewUpdating }) : null
700
+ ]
701
+ }
702
+ );
703
+ }, _e = "data-aqmx-edit-split", pe = "--aqmx-edit-share", Pe = "--aqmx-edit-gutter", nr = "data-aqmx-edit-split-probe", rr = "aqmx-edit-split", or = "aqmx-edit-editor", ir = "aqmx-edit-preview", Ne = { value: mn, unit: "percentage" }, De = { value: fn, unit: "percentage" }, Be = (e) => {
704
+ if (e.length !== 2) return null;
705
+ const [t = 0, n = 0] = e, o = t + n;
706
+ return o > 0 ? t / o * 100 : null;
707
+ }, ce = (e) => {
708
+ const t = e.current?.parentElement;
709
+ if (t == null) throw new Error("[markdown-explorer] the edit split is not mounted in its surface");
710
+ return t;
711
+ }, sr = (e, t, n) => {
712
+ const [o, i] = oe(null);
713
+ return D(() => {
714
+ const r = e.current, l = t.current;
715
+ if (r === null || l === null) throw new Error("[markdown-explorer] the edit split is not mounted");
716
+ const s = { frame: r.getBoundingClientRect().width, measure: l.getBoundingClientRect().width }, f = () => {
717
+ s.frame > 0 && s.measure > 0 && i(pn(s.frame, s.measure, n));
718
+ };
719
+ f();
720
+ const d = new ResizeObserver((b) => {
721
+ for (const w of b) {
722
+ const [c] = w.borderBoxSize;
723
+ c !== void 0 && (w.target === r && (s.frame = c.inlineSize), w.target === l && (s.measure = c.inlineSize));
724
+ }
725
+ f();
726
+ });
727
+ return d.observe(r), d.observe(l), () => d.disconnect();
728
+ }, [e, t, n]), o;
729
+ }, lr = ({ editorId: e }) => {
730
+ const { edits: t, labels: n } = ae(), o = Y(() => wn(n), [n]), i = N(null), r = N(null), l = ut() ? un : dn, s = sr(i, r, l), [f] = oe(() => t.editorShare());
731
+ D(() => {
732
+ const w = ce(i);
733
+ return w.style.setProperty(Pe, `${String(l)}px`), () => {
734
+ w.style.removeProperty(Pe);
735
+ };
736
+ }, [l]), D(() => {
737
+ const w = ce(i);
738
+ return w.style.setProperty(pe, `${String(f)}%`), () => {
739
+ w.style.removeProperty(pe);
740
+ };
741
+ }, [f]), D(() => {
742
+ if (s === null) return;
743
+ const w = ce(i);
744
+ return w.setAttribute(_e, s), () => w.removeAttribute(_e);
745
+ }, [s]);
746
+ const d = bn(
747
+ J(
748
+ (w) => {
749
+ const c = Be(w);
750
+ c !== null && t.setEditorShare(c);
751
+ },
752
+ [t]
753
+ )
754
+ ), b = J(
755
+ (w, c) => {
756
+ const v = Be(w);
757
+ v !== null && ce(i).style.setProperty(pe, `${String(v)}%`), d.layoutChanged(w, c);
758
+ },
759
+ [d]
760
+ );
761
+ return /* @__PURE__ */ re("div", { ref: i, className: "aqmx-edit-split", "data-testid": "markdown-explorer-edit-split", children: [
762
+ /* @__PURE__ */ q("span", { ref: r, className: "aqmx-edit-split-probe", "aria-hidden": "true", [nr]: "" }),
763
+ s === null ? null : /* @__PURE__ */ re(gn, { id: rr, direction: s === "beside" ? "horizontal" : "vertical", onLayout: b, labels: o, className: "aqmx-edit-split-group", children: [
764
+ /* @__PURE__ */ q(ke, { id: or, defaultSize: { value: f, unit: "percentage" }, minSize: Ne, maxSize: De, contentOverflow: "hidden" }),
765
+ /* @__PURE__ */ q(
766
+ vn,
767
+ {
768
+ thickness: l,
769
+ indicator: { visible: !0, thickness: le.gripThickness, length: le.gripLength, barThickness: le.barThickness, barLength: le.barLength },
770
+ title: n.editViewSplitResize,
771
+ "aria-label": n.editViewSplitResize,
772
+ "aria-controls": e,
773
+ onDragging: d.draggingChanged,
774
+ className: "aqmx-split-handle aqmx-edit-split-handle"
775
+ }
776
+ ),
777
+ /* @__PURE__ */ q(ke, { id: ir, defaultSize: { value: 100 - f, unit: "percentage" }, minSize: Ne, maxSize: De, contentOverflow: "hidden" })
778
+ ] })
779
+ ] });
780
+ }, cr = 512, ar = () => {
781
+ const e = [];
782
+ let t = 0, n = null;
783
+ const o = (i) => {
784
+ if (n === null || !Number.isInteger(i) || i < t) return null;
785
+ if (i === t + e.length) return n;
786
+ const r = e[i - t];
787
+ return r === void 0 ? null : r.before;
788
+ };
789
+ return {
790
+ revision: () => t + e.length,
791
+ mount: (i) => {
792
+ if (n !== null && (n === i || n.eq(i))) {
793
+ n = i;
794
+ return;
795
+ }
796
+ const r = t + e.length;
797
+ e.length = 0, t = n === null ? r : r + 1, n = i;
798
+ },
799
+ record: (i, r) => {
800
+ if (n === null) throw new Error("[markdown-explorer] a change of the editor's text was recorded before an editor mounted");
801
+ e.push({ before: n, changes: i }), n = r, e.length > cr && (e.shift(), t += 1);
802
+ },
803
+ lineOf: (i, r) => {
804
+ const l = o(i);
805
+ if (l === null || n === null || !Number.isInteger(r) || r < 1 || r > l.lines) return null;
806
+ let s = l.line(r).from;
807
+ for (const f of e.slice(i - t)) {
808
+ const d = f.changes.mapPos(s, 1, Kt.TrackAfter);
809
+ if (d === null) return null;
810
+ s = d;
811
+ }
812
+ return n.lineAt(s).number;
813
+ }
814
+ };
815
+ }, ur = 144, dr = (e) => {
816
+ if (typeof e != "object" || e === null) return !1;
817
+ const { generation: t, topLine: n } = e;
818
+ return "state" in e && typeof t == "number" && typeof n == "number";
819
+ }, fr = (e) => {
820
+ e.stopPropagation();
821
+ }, _r = (e) => {
822
+ const { path: t, name: n, session: o } = e, { edits: i, labels: r, announcer: l } = ae(), { phase: s } = o, f = J(() => i.retry(t), [i, t]);
823
+ switch (Ve(() => {
824
+ s.kind === "failed" && l.announce(r.documentFailed(n, He(r, s.failure.reason)));
825
+ }, [s, l, r, n]), s.kind) {
826
+ case "opening":
827
+ return /* @__PURE__ */ q(mt, { label: r.editLoading, testId: "markdown-explorer-edit-skeleton" });
828
+ case "grant":
829
+ return /* @__PURE__ */ q("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ q(ft, { href: s.href, onRetry: f, testId: "markdown-explorer-edit-grant" }) });
830
+ case "failed":
831
+ return /* @__PURE__ */ q("div", { className: "aqmx-edit-message", children: /* @__PURE__ */ q(dt, { failure: s.failure, alert: !1, onRetry: f, testId: "markdown-explorer-edit-failure" }) });
832
+ case "editing":
833
+ return /* @__PURE__ */ q(mr, { ...e });
834
+ }
835
+ }, mr = ({ path: e, name: t, session: n, layout: o, viewer: i, region: r, paneScroll: l }) => {
836
+ const { edits: s, labels: f } = ae(), d = N(null), b = nt(), w = N(null), [c] = oe(() => /* @__PURE__ */ new Set()), [v] = oe(ar), u = N(null), m = N(null), h = o === "fill", x = pt(), p = ht(n, x, h), S = p !== "editor" || n.previewPrepared, I = S && h, k = N({ layout: o, region: r, paneScroll: l });
837
+ D(() => {
838
+ k.current = { layout: o, region: r, paneScroll: l };
839
+ });
840
+ const R = N(n.generation);
841
+ D(() => {
842
+ R.current = n.generation;
843
+ });
844
+ const L = N({ view: p, previewMounted: S });
845
+ D(() => {
846
+ L.current = { view: p, previewMounted: S };
847
+ });
848
+ const { requestSave: G, confirmation: B } = gt(e), z = N(G);
849
+ D(() => {
850
+ z.current = G;
851
+ });
852
+ const V = N(null), a = N(null), T = N(!1), A = Y(() => ({ editor: f.editorLabel(t), useOurs: f.conflictUseOurs, useTheirs: f.conflictUseTheirs, keepBoth: f.conflictKeepBoth }), [f, t]), g = J((y) => {
853
+ const { region: O, paneScroll: P } = k.current, H = O();
854
+ return H === null ? y : P.scrollerOf(H, y);
855
+ }, []);
856
+ D(() => {
857
+ const y = d.current, O = s.draft(e);
858
+ if (y === null || O === null) return;
859
+ const P = s.editorState.get(e), H = dr(P) && P.generation === R.current ? P : null;
860
+ let K = null, Q = null;
861
+ const fe = () => {
862
+ K !== null && clearTimeout(K), K = null, Q !== null && s.setDraft(e, Q.text());
863
+ }, W = qn({
864
+ parent: y,
865
+ scroll: {
866
+ scrollerOf: (M) => {
867
+ const { layout: Z, region: Je, paneScroll: Qe } = k.current, be = Je();
868
+ return Z === "fill" || be === null ? M : Qe.scrollerOf(be, M);
869
+ },
870
+ reveal: (M) => k.current.paneScroll.reveal(M)
871
+ },
872
+ text: O,
873
+ saved: H === null ? void 0 : H.state,
874
+ labels: A,
875
+ revisions: v,
876
+ onGeometry: (M) => m.current?.editorChanged(M),
877
+ onChange: (M) => {
878
+ if (K ??= setTimeout(fe, ur), !M)
879
+ for (const Z of [...c]) Z();
880
+ L.current.previewMounted && Q !== null && u.current?.draft({ text: Q.text(), revision: v.revision() });
881
+ },
882
+ onSave: () => z.current()
883
+ });
884
+ Q = W, w.current = W;
885
+ const ve = () => {
886
+ const M = W.topLine();
887
+ return { line: M.line, clientTop: M.clientTop };
888
+ }, we = () => u.current?.anchor(g) ?? null, Ye = s.bindEditor(e, {
889
+ flush: fe,
890
+ adopt: (M) => W.replaceText(M),
891
+ returnPoint: () => {
892
+ const M = L.current.view === "preview" && k.current.layout === "content" ? we() : null;
893
+ return M === null ? ve() : { line: M.lines.first, clientTop: M.clientTop };
894
+ },
895
+ nextConflict: () => L.current.view !== "preview" ? W.nextConflict() : W.conflicts().length === 0 ? !1 : (T.current = !0, s.setView(e, "editor"), !0),
896
+ beforeView: (M) => {
897
+ if (k.current.layout === "fill") return;
898
+ if (M === "preview") {
899
+ V.current = { to: "preview", point: ve() };
900
+ return;
901
+ }
902
+ const Z = we();
903
+ V.current = Z === null ? null : { to: "editor", anchor: Z };
904
+ }
905
+ });
906
+ return H !== null && W.showLine(H.topLine), () => {
907
+ fe(), s.editorState.set(e, { state: W.save(), generation: R.current, topLine: W.topLine().line }), Ye(), W.destroy(), Q = null, w.current = null;
908
+ };
909
+ }, [s, e, A, g, c, v]);
910
+ const { request: E } = n;
911
+ D(() => {
912
+ const y = w.current, O = s.draft(e);
913
+ y === null || O === null || E === null || (E.anchor !== null && y.reveal(xe(O, E.anchor), E.anchor.clientTop), y.focus(), s.consumeRequest(e));
914
+ }, [s, e, E, A]), D(() => {
915
+ p !== "editor" && !n.previewPrepared && s.preparePreview(e);
916
+ }, [s, e, p, n.previewPrepared]), D(() => {
917
+ const y = V.current, O = a.current, P = T.current;
918
+ V.current = null, a.current = null, T.current = !1;
919
+ const H = w.current;
920
+ if (y?.to === "preview") u.current?.place(y.point, g);
921
+ else if (y?.to === "editor" && H !== null) {
922
+ const K = s.draft(e);
923
+ K !== null && H.reveal(xe(K, y.anchor), y.anchor.clientTop);
924
+ }
925
+ P ? H?.nextConflict() : O === "editor" ? H?.focus() : O === "preview" && u.current?.focus();
926
+ }, [s, e, p, g]);
927
+ const C = Y(() => {
928
+ const y = () => {
929
+ const O = w.current;
930
+ if (O === null) throw new Error("[markdown-explorer] a table of the preview wrote back while no editor was mounted");
931
+ return O;
932
+ };
933
+ return {
934
+ write: (O, { fenceLine: P, expected: H, text: K }) => y().replaceBody(P, H, K, O),
935
+ read: (O, P) => y().readBody(P, O),
936
+ undo: () => y().undo(),
937
+ redo: () => y().redo(),
938
+ subscribe: (O) => (c.add(O), () => {
939
+ c.delete(O);
940
+ })
941
+ };
942
+ }, [c]), U = J(() => {
943
+ const y = w.current;
944
+ if (y === null) throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");
945
+ return { text: y.text(), revision: v.revision() };
946
+ }, [v]);
947
+ D(() => {
948
+ const y = w.current;
949
+ if (!I || y === null) return;
950
+ const O = jn({
951
+ editor: $e(y.scrollElement),
952
+ preview: () => u.current?.scrollPort() ?? null,
953
+ previewBlocks: () => u.current?.blocks() ?? [],
954
+ editorSpans: (P) => y.lineSpans(P),
955
+ requestFrame: (P) => requestAnimationFrame(P),
956
+ cancelFrame: (P) => cancelAnimationFrame(P),
957
+ now: () => performance.now()
958
+ });
959
+ return O.showAlone(Se(L.current.view)), m.current = O, () => {
960
+ O.dispose(), m.current = null;
961
+ };
962
+ }, [I, s, e, A]), D(() => {
963
+ m.current?.showAlone(Se(p));
964
+ }, [p]);
965
+ const X = J(() => m.current?.previewChanged(), []), F = J((y) => s.start(e, y), [s, e]), je = (
966
+ /* @__PURE__ */ re("div", { className: "aqmx-edit", "data-aqmx-edit-layout": o, "data-aqmx-edit-view": p, "data-testid": "markdown-explorer-edit", onKeyDown: (y) => {
967
+ if (wt(y.target)) return;
968
+ if (y.key === "Escape") {
969
+ ye(y);
970
+ return;
971
+ }
972
+ if (!bt(y.nativeEvent, Et(navigator.platform))) return;
973
+ ye(y);
974
+ const O = St(p);
975
+ a.current = O, xt(s, e, O, h);
976
+ }, onDoubleClick: fr, children: [
977
+ /* @__PURE__ */ q("div", { ref: d, id: b, className: "aqmx-edit-editor", "data-testid": "markdown-explorer-editor", inert: p === "preview", hidden: p === "preview" && !h, ...vt }),
978
+ p === "split" ? /* @__PURE__ */ q(lr, { editorId: b }) : null,
979
+ S ? /* @__PURE__ */ q(tr, { path: e, readDraft: U, viewer: i, tables: C, concealed: p !== "editor" ? null : h ? "overlay" : "removed", onEditAt: p === "preview" ? F : void 0, onLayout: X, handleRef: u }) : null
980
+ ] })
981
+ );
982
+ return /* @__PURE__ */ re(Ze, { children: [
983
+ je,
984
+ B
985
+ ] });
986
+ };
987
+ export {
988
+ ur as DRAFT_WRITE_INTERVAL_MS,
989
+ _r as default
990
+ };