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