@aiquants/markdown-explorer 0.29.0 → 0.30.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.
@@ -1,966 +0,0 @@
1
- import { jsxs as ie, jsx as M } from "react/jsx-runtime";
2
- import { createContext as Je, use as ke, useRef as q, useState as $, useLayoutEffect as F, useMemo as D, useSyncExternalStore as Xe, useCallback as R, memo as Qe, useEffect as U, useImperativeHandle as Ze } from "react";
3
- import { n as ce, e as Ae, o as en, P as nn, q as tn } from "./location-CKuabtKl.js";
4
- import { L as on, u as J, M as rn, O as ln, D as sn, i as an, f as cn, Q as V, h as Le, R as un, N as dn, S as Ie, U as mn } from "./index-awodBw8r.js";
5
- import { S as fn, a as pn, b as gn } from "./ExplorerSplit-B-fr2nlU.js";
6
- import { SCROLL_AREA_SELECTOR as Re, SCROLL_ROOT_SELECTOR as te, PANEL_ACTION_ATTRIBUTE as he, generateColumnIds as hn, sortColumnIds as De, generateColumnId as _e, NO_PANEL_DRAG_ATTRIBUTE as vn, useDragDropColumns as wn, DEFAULT_DEBUG_CONFIG as ve, DragDropLayout as yn } from "@aiquants/drag-drop-panels";
7
- import { useNavigate as Sn, useLocation as xn } from "react-router";
8
- import { s as En, r as On, w as bn } from "./storage-CmGHg7OA.js";
9
- import { H as Pn, i as Cn } from "./dataRoute-DLhQfdoW.js";
10
- import { createPortal as Tn } from "react-dom";
11
- import { HostedScrollArea as Mn } from "@aiquants/markdown";
12
- const Nn = () => {
13
- const e = /* @__PURE__ */ new Map();
14
- return {
15
- hold: (n, t) => {
16
- e.set(n, t), queueMicrotask(() => {
17
- e.get(n) === t && e.delete(n);
18
- });
19
- },
20
- take: (n) => {
21
- const t = e.get(n);
22
- return e.delete(n), t === void 0 ? null : t;
23
- }
24
- };
25
- }, ze = Je(null), ue = () => {
26
- const e = ke(ze);
27
- if (e === null) throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");
28
- return e;
29
- }, kn = (e, n) => {
30
- const t = e.pendingHashes.get(n);
31
- return t === void 0 ? null : t;
32
- }, An = 0xcbf29ce484222325n, Ln = 0x100000001b3n, In = (1n << 64n) - 1n, Rn = (1n << 53n) - 1n, Dn = new TextEncoder(), _n = (e) => {
33
- let n = An;
34
- for (const t of Dn.encode(e))
35
- n = (n ^ BigInt(t)) * Ln & In;
36
- return Number(n & Rn);
37
- }, oe = 256, zn = (e) => `aqmx-p-${_n(e).toString(36)}`, He = (e, n) => {
38
- const t = zn(e);
39
- let o = t;
40
- for (let r = 2; n.has(o); r += 1) o = `${t}-${String(r)}`;
41
- return o;
42
- }, Hn = /* @__PURE__ */ new Map(), Bn = (e, n = Hn) => {
43
- const t = new Set(e.flatMap((r) => n.get(r) ?? [])), o = /* @__PURE__ */ new Map();
44
- for (const r of e) {
45
- const l = n.get(r) ?? He(r, t);
46
- t.add(l), o.set(r, l);
47
- }
48
- return o;
49
- }, Be = (e, n, t) => {
50
- const o = e.columnOf.get(n);
51
- return o === void 0 ? void 0 : Math.min(t - 1, Math.max(0, o));
52
- }, qe = (e, n) => {
53
- const [t, ...o] = ce(n.logical, n.visible);
54
- if (t === void 0) throw new RangeError("[markdown-explorer] there must be at least one visible column");
55
- const r = ([c, m]) => e.slice(c, m).reduce((s, v) => s + v.length, 0);
56
- let l = t;
57
- for (const c of o) r(c) < r(l) && (l = c);
58
- let a = l[0];
59
- for (let c = l[0]; c < l[1]; c += 1) (e[c]?.length ?? 0) < (e[a]?.length ?? 0) && (a = c);
60
- return a;
61
- }, re = (e, n) => {
62
- const t = Array.from({ length: n.logical }, () => []), o = [];
63
- for (const r of e.docs) {
64
- const l = Be(e, r, n.logical);
65
- l === void 0 ? o.push(r) : t[l]?.push(r);
66
- }
67
- for (const r of o) t[qe(t, n)]?.push(r);
68
- return t;
69
- }, qn = (e, n) => ce(e.length, n).map(([t, o]) => e.slice(t, o).flat()), Fn = (e, n, t) => {
70
- const [o, r] = n, l = r - o, a = e.length, c = Array.from({ length: l }, (x, d) => {
71
- const h = [0];
72
- for (const f of e) h.push((h.at(-1) ?? 0) + (t(f) === o + d ? 1 : 0));
73
- return h;
74
- }), m = (x, d, h) => (c[x]?.[h] ?? 0) - (c[x]?.[d] ?? 0), s = Array.from({ length: l + 1 }, () => Array.from({ length: a + 1 }, () => Number.NEGATIVE_INFINITY)), v = Array.from({ length: l + 1 }, () => Array.from({ length: a + 1 }, () => 0)), S = s[0];
75
- S && (S[0] = 0);
76
- for (let x = 0; x < l; x += 1)
77
- for (let d = 0; d <= a; d += 1)
78
- for (let h = 0; h <= d; h += 1) {
79
- const f = (s[x]?.[h] ?? Number.NEGATIVE_INFINITY) + m(x, h, d), P = s[x + 1], T = v[x + 1];
80
- P && T && f > (P[d] ?? Number.NEGATIVE_INFINITY) && (P[d] = f, T[d] = h);
81
- }
82
- const O = Array.from({ length: l }, () => []);
83
- let N = a;
84
- for (let x = l; x > 0; x -= 1) {
85
- const d = v[x]?.[N] ?? 0;
86
- O[x - 1] = e.slice(d, N), N = d;
87
- }
88
- return O;
89
- }, Fe = (e, n) => {
90
- const t = n.flat(), o = new Map(e.columnOf);
91
- for (const [r, l] of n.entries())
92
- for (const a of l)
93
- o.delete(a), o.set(a, r);
94
- for (const r of o.keys()) {
95
- if (o.size <= oe) break;
96
- o.delete(r);
97
- }
98
- return { docs: t, columnOf: o };
99
- }, Vn = (e, n, t, o) => {
100
- if (e.docs.includes(n)) return { state: e, outcome: "existing" };
101
- if (e.docs.length >= o) return { state: e, outcome: "rejected" };
102
- const r = re(e, t), l = Be(e, n, t.logical) ?? qe(r, t);
103
- r[l]?.push(n);
104
- const a = new Map(e.panelIds);
105
- return a.set(n, He(n, new Set(a.values()))), { state: { ...e, ...Fe(e, r), panelIds: a }, outcome: "opened" };
106
- }, Ve = (e, n) => {
107
- if (!e.docs.includes(n)) return e;
108
- const t = new Set(e.hidden);
109
- t.delete(n);
110
- const o = new Set(e.markup);
111
- o.delete(n);
112
- const r = new Map(e.panelIds);
113
- return r.delete(n), { ...e, docs: e.docs.filter((l) => l !== n), hidden: t, markup: o, panelIds: r, maximized: e.maximized === n ? null : e.maximized };
114
- }, $n = (e, n, t, o) => {
115
- if (e.hidden.has(n)) return { state: $e(e, n, !1), outcome: "shown" };
116
- if (e.docs.includes(n)) return { state: Ve(e, n), outcome: "closed" };
117
- const r = Vn(e, n, t, o);
118
- return { state: r.state, outcome: r.outcome === "rejected" ? "rejected" : "opened" };
119
- }, Un = (e, n, t) => {
120
- if (n === t || !e.docs.includes(n)) return { state: e, outcome: "ignored" };
121
- if (e.docs.includes(t)) return { state: e, outcome: "existing" };
122
- const o = new Map(e.columnOf), r = o.get(n);
123
- r !== void 0 && (o.delete(t), o.set(t, r));
124
- const l = new Set(e.hidden);
125
- l.delete(n);
126
- const a = new Map(e.panelIds), c = a.get(n);
127
- if (c === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
128
- a.delete(n), a.set(t, c);
129
- const m = new Set(e.markup);
130
- return m.delete(n), {
131
- state: { docs: e.docs.map((s) => s === n ? t : s), maximized: e.maximized === n ? t : e.maximized, columnOf: o, hidden: l, markup: m, panelIds: a },
132
- outcome: "navigated"
133
- };
134
- }, $e = (e, n, t) => {
135
- if (!e.docs.includes(n) || e.hidden.has(n) === t) return e;
136
- const o = new Set(e.hidden);
137
- return t ? o.add(n) : o.delete(n), { ...e, hidden: o, maximized: t && e.maximized === n ? null : e.maximized };
138
- }, jn = (e, n, t) => {
139
- if (!e.docs.includes(n) || e.markup.has(n) === t) return e;
140
- const o = new Set(e.markup);
141
- return t ? o.add(n) : o.delete(n), { ...e, markup: o };
142
- }, Gn = (e, n) => {
143
- if (e.maximized === n || n !== null && !e.docs.includes(n)) return e;
144
- if (n === null || !e.hidden.has(n)) return { ...e, maximized: n };
145
- const t = new Set(e.hidden);
146
- return t.delete(n), { ...e, maximized: n, hidden: t };
147
- }, Yn = (e, n, t) => {
148
- const o = re(e, t), r = /* @__PURE__ */ new Map();
149
- for (const [s, v] of o.entries())
150
- for (const S of v) r.set(S, s);
151
- const l = new Set(e.docs), a = /* @__PURE__ */ new Set(), c = ce(t.logical, t.visible), m = Array.from({ length: t.logical }, () => []);
152
- for (const [s, v] of c.entries()) {
153
- const S = (n[s] ?? []).filter((O) => l.has(O) && !a.has(O));
154
- for (const O of S) a.add(O);
155
- for (const [O, N] of Fn(S, v, (x) => r.get(x)).entries())
156
- m[v[0] + O]?.push(...N);
157
- }
158
- for (const s of e.docs)
159
- a.has(s) || m[r.get(s) ?? 0]?.push(s);
160
- return m.every((s, v) => s.length === o[v]?.length && s.every((S, O) => o[v]?.[O] === S)) ? e : { ...e, ...Fe(e, m) };
161
- }, le = (e, n) => {
162
- const t = [...new Set(e.docs)].slice(0, n), o = new Set(t), r = e.maximized !== null && o.has(e.maximized) ? e.maximized : null;
163
- return {
164
- docs: t,
165
- maximized: r,
166
- columnOf: e.stored.columnOf,
167
- hidden: new Set([...e.stored.hidden].filter((l) => o.has(l) && l !== r)),
168
- markup: new Set(e.markup.filter((l) => o.has(l))),
169
- panelIds: Bn(t, e.panelIds)
170
- };
171
- }, we = (e, n) => {
172
- if (e.docs.every((o) => e.columnOf.has(o))) return e;
173
- const t = new Map(e.columnOf);
174
- for (const [o, r] of re(e, n).entries())
175
- for (const l of r)
176
- t.delete(l), t.set(l, o);
177
- for (const o of t.keys()) {
178
- if (t.size <= oe) break;
179
- t.delete(o);
180
- }
181
- return { ...e, columnOf: t };
182
- }, Ue = 1, Y = Object.freeze({ columnOf: /* @__PURE__ */ new Map(), hidden: /* @__PURE__ */ new Set() }), Wn = (e, n) => {
183
- if (e === null || e === "") return Y;
184
- let t;
185
- try {
186
- t = JSON.parse(e);
187
- } catch {
188
- return Y;
189
- }
190
- if (t === null || typeof t != "object" || Array.isArray(t)) return Y;
191
- const o = t;
192
- if (o.v !== Ue) return Y;
193
- const r = /* @__PURE__ */ new Map();
194
- if (Array.isArray(o.columnOf))
195
- for (const a of o.columnOf.slice(-oe))
196
- Array.isArray(a) && a.length === 2 && typeof a[0] == "string" && a[0] !== "" && Number.isInteger(a[1]) && a[1] >= 0 && a[1] < n && (r.delete(a[0]), r.set(a[0], a[1]));
197
- const l = new Set(Array.isArray(o.hidden) ? o.hidden.filter((a) => typeof a == "string" && a !== "") : []);
198
- return { columnOf: r, hidden: l };
199
- }, Kn = (e) => JSON.stringify({
200
- v: Ue,
201
- columnOf: [...e.columnOf.entries()].slice(-oe),
202
- hidden: e.docs.filter((n) => e.hidden.has(n))
203
- }), de = (e, n) => {
204
- const t = e.get(n);
205
- return t === void 0 ? Pn(n) : t;
206
- }, X = (e) => {
207
- const n = /* @__PURE__ */ new Map();
208
- for (const [t, o] of e.panelIds) n.set(o, t);
209
- return n;
210
- }, ye = (e) => {
211
- if (!Cn(e)) throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(e.slice(0, 80))}`);
212
- }, Jn = ({ config: e, location: n, writeUrl: t, persist: o }) => {
213
- const { maxPanels: r, columns: l } = e.multiView, a = on(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
214
- let s = {
215
- layout: le({ docs: n.docs, maximized: n.maximized, markup: n.markup, stored: Y }, r),
216
- source: n.source,
217
- visibleColumns: l,
218
- ready: !1,
219
- splitDragging: !1,
220
- titles: /* @__PURE__ */ new Map(),
221
- pendingHashes: /* @__PURE__ */ new Map()
222
- }, v = !1;
223
- const S = (i) => v ? we(i, { logical: l, visible: s.visibleColumns }) : i, O = (i, p) => Ae(e, { view: "multi", source: i, docs: p.docs, maximized: p.maximized, markup: p.markup }), N = (i) => ({ docs: i.docs, maximized: i.maximized, markup: [...i.markup] });
224
- let x = O(n.source, n), d = n.source, h = x;
225
- const f = [], P = [];
226
- let T = null;
227
- const A = () => {
228
- if (!(f.length > 0))
229
- for (const i of P.splice(0)) i();
230
- }, u = (i) => {
231
- s = { ...s, ...i }, a.emit();
232
- }, w = () => {
233
- if (!s.ready) return;
234
- const i = Kn(s.layout);
235
- i !== T && (T = i, o(i));
236
- }, g = (i, p, C) => {
237
- const I = O(i, N(p));
238
- I !== x && (x = I, d = i, f.push(I), t(I, C));
239
- }, y = (i) => {
240
- const p = new Set(i.panelIds.values());
241
- for (const b of [...c.keys()]) p.has(b) || c.delete(b);
242
- for (const b of [...m.keys()]) p.has(b) || m.delete(b);
243
- const C = new Set(i.docs), I = [...s.titles.keys()].every((b) => C.has(b)) ? s.titles : new Map([...s.titles].filter(([b]) => C.has(b))), E = [...s.pendingHashes.keys()].every((b) => p.has(b)) ? s.pendingHashes : new Map([...s.pendingHashes].filter(([b]) => p.has(b)));
244
- return { titles: I, pendingHashes: E };
245
- }, k = (i) => i === s.layout ? !1 : (u({ layout: i, ...y(i) }), g(d, i, "replace"), w(), !0), L = () => ({ logical: l, visible: s.visibleColumns });
246
- return {
247
- getSnapshot: () => s,
248
- subscribe: a.subscribe,
249
- toggle: (i) => {
250
- ye(i);
251
- const { state: p, outcome: C } = $n(s.layout, i, L(), r);
252
- return k(p), C;
253
- },
254
- close: (i) => k(Ve(s.layout, i)),
255
- navigate: (i, p) => {
256
- ye(p);
257
- const { state: C, outcome: I } = Un(s.layout, i, p);
258
- if (I !== "navigated") return I;
259
- const E = C.panelIds.get(p);
260
- return E !== void 0 && (c.delete(E), m.delete(E)), k(C), I;
261
- },
262
- setHidden: (i, p) => k($e(s.layout, i, p)),
263
- maximize: (i) => k(Gn(s.layout, i)),
264
- setMarkup: (i, p) => k(jn(s.layout, i, p)),
265
- arrange: (i) => k(Yn(s.layout, i, { logical: l, visible: i.length })),
266
- changeSource: (i) => {
267
- g(i, s.layout, "push");
268
- },
269
- revealSource: (i) => {
270
- g(i, s.layout, "replace");
271
- },
272
- observeLocation: (i) => {
273
- const p = O(i.source, i);
274
- if (p === x)
275
- return f.length = 0, h = p, i.source !== s.source && u({ source: i.source }), A(), !1;
276
- if (p === h) return !1;
277
- h = p;
278
- const C = f.indexOf(p);
279
- if (C >= 0)
280
- return f.splice(0, C + 1), i.source !== s.source && u({ source: i.source }), A(), !1;
281
- f.length = 0, x = p, d = i.source;
282
- const I = S(le({ docs: i.docs, maximized: i.maximized, markup: i.markup, stored: { columnOf: s.layout.columnOf, hidden: s.layout.hidden }, panelIds: s.layout.panelIds }, r));
283
- return u({ layout: I, source: i.source, ...y(I) }), w(), A(), !0;
284
- },
285
- whenUrlRendered: (i) => {
286
- P.push(i), A();
287
- },
288
- loadStored: (i) => {
289
- u({ layout: S(le({ docs: s.layout.docs, maximized: s.layout.maximized, markup: [...s.layout.markup], stored: i, panelIds: s.layout.panelIds }, r)), ready: !0 }), w();
290
- },
291
- setVisibleColumns: (i) => {
292
- if (!Number.isInteger(i) || i < 1 || i > l) throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(l)}; got ${String(i)}`);
293
- v = !0;
294
- const p = we(s.layout, { logical: l, visible: i });
295
- i === s.visibleColumns && p === s.layout || (u({ visibleColumns: i, layout: p }), p !== s.layout && w());
296
- },
297
- setSplitDragging: (i) => {
298
- i !== s.splitDragging && u({ splitDragging: i });
299
- },
300
- setTitle: (i, p) => {
301
- !s.layout.docs.includes(i) || s.titles.get(i) === p || u({ titles: new Map(s.titles).set(i, p) });
302
- },
303
- titleOf: (i) => de(s.titles, i),
304
- setPendingHash: (i, p) => {
305
- const C = s.pendingHashes.get(i);
306
- if (p === null || p === "") {
307
- if (C === void 0) return;
308
- const I = new Map(s.pendingHashes);
309
- I.delete(i), u({ pendingHashes: I });
310
- return;
311
- }
312
- C !== p && u({ pendingHashes: new Map(s.pendingHashes).set(i, p) });
313
- },
314
- saveReadingPosition: (i, p, C) => {
315
- s.layout.panelIds.get(p) === i && c.set(i, { doc: p, position: C });
316
- },
317
- readingPositionOf: (i, p) => {
318
- const C = c.get(i);
319
- return C === void 0 || C.doc !== p ? null : C.position;
320
- },
321
- saveImageView: (i, p, C) => {
322
- m.set(i, { url: p, state: C });
323
- },
324
- imageViewOf: (i, p) => {
325
- const C = m.get(i);
326
- return C === void 0 || C.url !== p ? null : C.state;
327
- }
328
- };
329
- }, _ = (e, n) => {
330
- const t = () => n(e.getSnapshot());
331
- return Xe(e.subscribe, t, t);
332
- }, Xn = (e) => {
333
- const { config: n, storageNamespace: t } = J(), o = Sn(), r = q(o), l = En(t).multiLayout, [a] = $(
334
- () => Jn({
335
- config: n,
336
- location: e,
337
- writeUrl: (s, v) => {
338
- r.current(s, rn(v === "replace" ? "browse" : "switch-source"));
339
- },
340
- persist: (s) => bn(l, s)
341
- })
342
- );
343
- F(() => {
344
- r.current = o;
345
- }, [o]);
346
- const c = xn(), m = D(() => ({ location: e, navigated: c }), [e, c]);
347
- return F(() => {
348
- a.observeLocation(m.location);
349
- }, [a, m]), F(() => {
350
- a.loadStored(Wn(On(l), n.multiView.columns));
351
- }, [a, l, n]), a;
352
- }, Qn = (e) => {
353
- const n = e.closest(Re);
354
- if (n === null) throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");
355
- return n;
356
- }, Zn = ({ docPath: e, panelId: n, maximized: t, title: o, onContentShown: r }) => {
357
- const { store: l, followLink: a, revealInPanel: c } = ue(), { announcer: m } = J(), s = _(l, (u) => kn(u, n)), v = _(l, (u) => u.layout.markup.has(e)), S = R((u, w) => a(n, e, u, w), [a, n, e]), O = R(() => l.setPendingHash(n, null), [l, n]), N = D(() => ({ read: (u) => l.imageViewOf(n, u), save: (u, w) => l.saveImageView(n, u, w) }), [l, n]), x = R(
358
- (u, w) => {
359
- w.kind !== "failure" && l.setTitle(u, w.name), r(u);
360
- },
361
- [l, r]
362
- ), d = R(
363
- (u) => {
364
- l.whenUrlRendered(() => m.announce(u));
365
- },
366
- [l, m]
367
- ), h = D(() => ({ scrollerOf: Qn, reveal: (u) => c(n, u) }), [c, n]), f = D(
368
- () => ({ kind: "panel", maximized: t, onDocumentLink: S, pendingHash: s, onHashConsumed: O, announceFailure: d, paneScroll: h }),
369
- [t, S, s, O, d, h]
370
- ), P = D(() => ({ kind: "panel", documentName: o, maximized: t }), [o, t]), T = R(() => l.setMarkup(e, !l.getSnapshot().layout.markup.has(e)), [l, e]), A = D(() => ({ shown: v, toggle: T }), [v, T]);
371
- return /* @__PURE__ */ ie(ln, { value: N, children: [
372
- /* @__PURE__ */ M(sn, { path: e, placement: P, markup: A }),
373
- /* @__PURE__ */ M(an, { path: e, absence: cn, markup: v, variant: f, onDocumentShown: x })
374
- ] });
375
- }, Se = () => typeof HTMLElement < "u" && typeof HTMLElement.prototype.showPopover == "function" && typeof HTMLElement.prototype.hidePopover == "function", me = "data-aqmx-column-probe", Z = "data-panel-id", ae = "--aqmx-multi-panel-chrome", et = (e) => e === "normal" ? 0 : V(e), nt = (e, n) => {
376
- const t = e.querySelector(te)?.firstElementChild, o = e.querySelector(`[${me}]`), r = o instanceof HTMLElement ? o.getBoundingClientRect().width : Number.NaN;
377
- if (!(t instanceof HTMLElement))
378
- return { plan: { trackInlineSize: Number.NaN, gap: Number.NaN, minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: Number.NaN };
379
- const l = getComputedStyle(t), a = t.clientWidth - V(l.paddingLeft) - V(l.paddingRight), c = t.clientHeight - V(l.paddingTop) - V(l.paddingBottom);
380
- return { plan: { trackInlineSize: a, gap: et(l.columnGap), minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: c };
381
- }, tt = (e, n) => {
382
- if (e.getClientRects().length === 0) return Number.NaN;
383
- const t = getComputedStyle(e);
384
- return n.getBoundingClientRect().top - e.getBoundingClientRect().top + V(t.paddingBottom) + V(t.borderBottomWidth);
385
- }, ee = "data-aqmx-panel-frame", xe = "--aqmx-multi-panel-pinned-block-size", ot = (e) => {
386
- const { docPath: n, panelId: t } = e;
387
- if (typeof n != "string" || typeof t != "string") throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");
388
- return { docPath: n, panelId: t };
389
- }, rt = (e) => {
390
- const n = getComputedStyle(e), t = Number.parseFloat(n.lineHeight);
391
- return Number.isFinite(t) ? t : Number.parseFloat(n.fontSize);
392
- }, lt = (e, n, t) => e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? e.deltaY * n.clientHeight : e.deltaMode !== WheelEvent.DOM_DELTA_LINE ? e.deltaY : e.deltaY * t(n), W = (e) => {
393
- const n = e.closest(Re);
394
- return n instanceof HTMLElement ? n : null;
395
- }, je = (e) => {
396
- const n = e.firstElementChild;
397
- return n instanceof HTMLElement && getComputedStyle(n).position === "sticky" ? n : null;
398
- }, Ge = (e, n) => {
399
- const t = n.getBoundingClientRect().top, o = je(e);
400
- return o === null ? t : Math.max(t, o.getBoundingClientRect().bottom);
401
- }, Ee = (e, n) => {
402
- let t = 0, o = e.length;
403
- for (; t < o; ) {
404
- const r = t + o >>> 1;
405
- (e[r]?.getBoundingClientRect().bottom ?? Number.NEGATIVE_INFINITY) > n ? o = r : t = r + 1;
406
- }
407
- return t < e.length ? t : -1;
408
- }, st = (e, n) => {
409
- const t = Ge(e, n), o = [];
410
- let r = e;
411
- for (let a = Ee([...r.children], t); a >= 0; a = Ee([...r.children], t)) {
412
- const c = r.children[a];
413
- if (c === void 0) break;
414
- o.push(a), r = c;
415
- }
416
- const l = r.getBoundingClientRect();
417
- return { scrollTop: n.scrollTop, anchor: o.length === 0 ? null : { path: o, offset: l.top - t, height: l.height } };
418
- }, Oe = (e, n, t) => {
419
- if (n.scrollTop = t.scrollTop, t.anchor === null) return;
420
- let o = e;
421
- for (const m of t.anchor.path) o = o?.children[m];
422
- if (o === void 0) return;
423
- const r = o.getBoundingClientRect(), { offset: l, height: a } = t.anchor, c = l < 0 && a > 0 ? l / a * r.height : l;
424
- n.scrollTop += r.top - Ge(e, n) - c;
425
- }, it = Object.freeze(["data-testid", "aria-label", "title", "href", "id", "name"]), Ye = (e) => {
426
- const n = e.getAttribute(he);
427
- return JSON.stringify(n === null ? [e.tagName, ...it.map((t) => e.getAttribute(t))] : [e.tagName, he, n]);
428
- }, at = (e, n) => {
429
- if (n === null || !e.contains(n)) return null;
430
- const t = [];
431
- for (let o = n; o !== e; ) {
432
- const r = o.parentElement;
433
- if (r === null) return null;
434
- t.unshift([...r.children].indexOf(o)), o = r;
435
- }
436
- return { path: t, signature: Ye(n) };
437
- }, ct = (e, n, t) => {
438
- let o = e;
439
- for (const r of t.path) o = o?.children[r];
440
- o instanceof HTMLElement && Ye(o) === t.signature && un(o) || n.focus({ preventScroll: !0 });
441
- }, ut = (e, n, t) => {
442
- if (e.shiftKey || Math.abs(e.deltaX) > Math.abs(e.deltaY)) return;
443
- const o = e.ctrlKey || e.metaKey, r = o ? W(n) : n.closest(te);
444
- if (!(r instanceof HTMLElement)) return;
445
- const l = lt(e, r, t);
446
- (o || dt(r, l)) && (e.preventDefault(), r.scrollTop += l);
447
- }, dt = (e, n) => n < 0 ? e.scrollTop > 0 : n > 0 ? Math.ceil(e.scrollTop + e.clientHeight) < e.scrollHeight : !1, mt = (e) => e.scrollHeight > e.clientHeight, ft = (e, n, t) => {
448
- let o = Number.NaN, r = Number.NaN;
449
- const l = je(t), a = () => {
450
- const s = tt(e, n);
451
- if (!Number.isFinite(s)) return;
452
- const v = l === null ? 0 : l.getBoundingClientRect().height;
453
- v !== r && (r = v, t.style.setProperty(xe, `${String(v)}px`));
454
- const S = s + v;
455
- S !== o && (o = S, e.style.setProperty(ae, `${String(S)}px`));
456
- };
457
- a();
458
- let c = null;
459
- const m = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
460
- c === null && (c = requestAnimationFrame(() => {
461
- c = null, a();
462
- }));
463
- });
464
- return m?.observe(e), m?.observe(n), l !== null && m?.observe(l), () => {
465
- m?.disconnect(), c !== null && cancelAnimationFrame(c), e.style.removeProperty(ae), t.style.removeProperty(xe);
466
- };
467
- }, pt = (e) => {
468
- const { docPath: n, panelId: t } = ot(e), { store: o, Body: r, maximize: l, focusCarry: a } = ue(), c = _(o, (d) => d.layout.maximized === n), m = _(o, (d) => de(d.titles, n)), s = q(null), v = q(null), S = q(null), O = q(null);
469
- U(() => {
470
- const d = s.current, h = d === null ? null : W(d);
471
- if (d === null || h === null || c) return;
472
- const f = /* @__PURE__ */ new Map(), P = (g) => {
473
- const y = f.get(g);
474
- if (y !== void 0) return y;
475
- const k = rt(g);
476
- return f.set(g, k), k;
477
- }, T = (g) => ut(g, d, P);
478
- let A = !1;
479
- const u = () => {
480
- const g = mt(h);
481
- g !== A && (A = g, g ? d.addEventListener("wheel", T, { capture: !0, passive: !1 }) : d.removeEventListener("wheel", T, { capture: !0 }));
482
- };
483
- u();
484
- const w = typeof ResizeObserver > "u" ? null : new ResizeObserver(u);
485
- return w?.observe(h), w?.observe(d), () => {
486
- w?.disconnect(), d.removeEventListener("wheel", T, { capture: !0 });
487
- };
488
- }, [c]), F(() => {
489
- const d = s.current, h = d === null ? null : W(d), f = d === null ? null : d.closest(`[${Z}]`);
490
- if (!(d === null || h === null || !(f instanceof HTMLElement)))
491
- return ft(f, h, d);
492
- }, []), F(() => {
493
- const d = s.current, h = d === null ? null : W(d);
494
- if (d === null || h === null) return;
495
- const f = (g) => {
496
- Oe(d, h, g), O.current = h.scrollTop;
497
- }, P = o.readingPositionOf(t, n);
498
- v.current = P === null ? null : { doc: n, position: P }, P !== null && f(P);
499
- let T = null, A = d.getBoundingClientRect().width;
500
- const u = () => {
501
- T === null && (T = requestAnimationFrame(() => {
502
- T = null;
503
- const g = O.current;
504
- if (O.current = null, g !== null && h.scrollTop === g || d.getBoundingClientRect().width !== A) return;
505
- const y = S.current;
506
- y !== null && o.saveReadingPosition(t, y, st(d, h));
507
- }));
508
- };
509
- h.addEventListener("scroll", u, { passive: !0 });
510
- const w = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
511
- const g = d.getBoundingClientRect().width;
512
- if (g === A) return;
513
- A = g;
514
- const y = o.readingPositionOf(t, n);
515
- y !== null && f(y);
516
- });
517
- return w?.observe(d), () => {
518
- h.removeEventListener("scroll", u), w?.disconnect(), T !== null && cancelAnimationFrame(T);
519
- };
520
- }, [o, t, n]), F(() => {
521
- const d = s.current, h = d === null ? null : d.closest(`[${Z}]`);
522
- if (d === null || h === null) return;
523
- const f = a.take(t);
524
- return f !== null && ct(h, d, f), () => {
525
- const P = at(h, h.ownerDocument.activeElement);
526
- P !== null && a.hold(t, P);
527
- };
528
- }, [a, t]);
529
- const N = R((d) => {
530
- const h = s.current, f = h === null ? null : W(h);
531
- if (h === null || f === null) return;
532
- const P = S.current;
533
- S.current = d;
534
- const T = v.current;
535
- v.current = null, T !== null && T.doc === d ? (Oe(h, f, T.position), O.current = f.scrollTop) : P !== null && P !== d && (f.scrollTop = 0);
536
- }, []), x = R(() => l(n), [l, n]);
537
- return (
538
- /* @__PURE__ */ M(
539
- "div",
540
- {
541
- ref: s,
542
- role: "group",
543
- "aria-label": m,
544
- className: "aqmx-multi-panel-frame",
545
- tabIndex: -1,
546
- "data-aqmx-panel-frame": t,
547
- "data-aqmx-maximized": c ? "true" : "false",
548
- "data-testid": "markdown-explorer-panel-frame",
549
- ...c ? Le : {},
550
- onDoubleClick: c ? void 0 : x,
551
- children: /* @__PURE__ */ M(r, { docPath: n, panelId: t, maximized: c, title: m, onContentShown: N })
552
- }
553
- )
554
- );
555
- }, gt = Qe(pt), Q = (e, n) => {
556
- const t = e.panelIds.get(n);
557
- if (t === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
558
- return t;
559
- }, be = (e) => Object.fromEntries(hn(e).map((n) => [n, []])), ht = (e, n) => {
560
- const t = qn(re(e, n), n.visible);
561
- return Object.fromEntries(t.map((o, r) => [_e(r), o.map((l) => Q(e, l))]));
562
- }, vt = (e, n) => {
563
- const t = X(e);
564
- return De(Object.keys(n)).map(
565
- (o) => (n[o] ?? []).flatMap((r) => {
566
- const l = t.get(r);
567
- return l === void 0 ? [] : [l];
568
- })
569
- );
570
- }, wt = (e) => ({
571
- switchToCustomDragMode: e.panelSwitchToCustomDrag,
572
- switchToNormalDragMode: e.panelSwitchToNormalDrag,
573
- hidePanel: e.panelHide,
574
- maximizePanel: e.panelMaximize,
575
- restorePanel: e.panelRestore,
576
- closePanel: e.panelClose,
577
- movePanel: e.panelMove,
578
- movePanelToPreviousColumn: e.panelMovePreviousColumn,
579
- movePanelToNextColumn: e.panelMoveNextColumn,
580
- movePanelUp: e.panelMoveUp,
581
- movePanelDown: e.panelMoveDown,
582
- customDragModeBadge: e.panelCustomDragBadge,
583
- panelMoved: e.panelMoved,
584
- panelMoveUnavailable: e.panelMoveUnavailable,
585
- panelDragStarted: e.panelDragStarted,
586
- panelDragCancelled: e.panelDragCancelled,
587
- hiddenPanels: e.hiddenPanelsTitle,
588
- hiddenPanelBadge: e.hiddenPanelBadge,
589
- hiddenPanelNotice: e.hiddenPanelNotice,
590
- emptyColumn: e.multiColumnEmpty,
591
- dropZone: e.multiColumnRegion,
592
- dropHere: e.panelDropHere
593
- }), yt = "--aqmx-multi-stage-bar-gutter", St = Object.freeze({ [yt]: `${String(dn)}px` }), xt = Object.freeze({ blockSize: "100%", paddingInlineEnd: `${String(mn)}px` }), Et = Object.freeze({ [vn]: "", style: Object.freeze({ display: "flex" }) }), Ot = (e) => /* @__PURE__ */ M("div", { ...Et, children: /* @__PURE__ */ M(Ie, { scroller: e, withCircle: !0 }) }), bt = ({ props: e, children: n }) => /* @__PURE__ */ M(Mn, { scrollerProps: { ...e, style: xt }, renderScrollBar: Ot, children: n }), Pt = (e) => /* @__PURE__ */ M(Ie, { scroller: e, withCircle: !1 }), fe = "--aqmx-stage-block", Ct = "--aqmx-multi-panel-body-floor", Tt = `calc(var(${fe}) * ${String(tn)})`, Mt = `max(calc(var(${fe}) * ${String(nn)}), calc(var(${ae}) + var(${Ct})))`, Nt = (e, n) => {
594
- const t = Object.entries(e);
595
- return t.length !== Object.keys(n).length ? !1 : t.every(([o, r]) => {
596
- const l = n[o];
597
- return l !== void 0 && l.length === r.length && l.every((a, c) => r[c] === a);
598
- });
599
- }, Pe = ["keydown", "pointerdown", "wheel", "touchstart"], K = /* @__PURE__ */ new WeakMap(), Ce = (e, n, t) => {
600
- for (let o = n; o !== null && o !== t; o = o.parentElement) {
601
- e.observe(o);
602
- for (let r = o.previousElementSibling; r !== null; r = r.previousElementSibling) e.observe(r);
603
- }
604
- }, kt = (e) => {
605
- const n = /* @__PURE__ */ new Map();
606
- for (let t = e.parentElement; t !== null; t = t.parentElement) n.set(t, { top: t.scrollTop, left: t.scrollLeft });
607
- return n;
608
- }, ne = (e, n, t) => {
609
- K.get(e)?.();
610
- const o = e.querySelector(`[${Z}="${n}"]`);
611
- if (!(o instanceof HTMLElement)) return;
612
- const r = t !== null && o.contains(t) ? t : null;
613
- let l = /* @__PURE__ */ new Map();
614
- const a = () => {
615
- if (!o.isConnected) return;
616
- o.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" });
617
- const S = r?.isConnected === !0 ? r : o;
618
- S !== o && S.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" }), l = kt(S);
619
- };
620
- if (a(), typeof ResizeObserver > "u") return;
621
- const c = new ResizeObserver(a);
622
- Ce(c, o, o.closest(te)), r !== null && Ce(c, r, o);
623
- const { ownerDocument: m } = e, s = (S) => {
624
- const O = S.target === m ? m.scrollingElement : S.target;
625
- if (!(O instanceof Element)) return;
626
- const N = l.get(O);
627
- N !== void 0 && (O.scrollTop !== N.top || O.scrollLeft !== N.left) && v();
628
- }, v = () => {
629
- c.disconnect();
630
- for (const S of Pe) m.removeEventListener(S, v, !0);
631
- m.removeEventListener("scroll", s, !0), K.get(e) === v && K.delete(e);
632
- };
633
- for (const S of Pe) m.addEventListener(S, v, { capture: !0, passive: !0 });
634
- m.addEventListener("scroll", s, { capture: !0, passive: !0 }), K.set(e, v);
635
- }, We = (e, n) => {
636
- const t = e.querySelector(`[${ee}="${n}"]`);
637
- return t instanceof HTMLElement ? (ne(e, n, null), t.focus({ preventScroll: !0 }), !0) : !1;
638
- }, pe = (e, n) => {
639
- const t = e.querySelector(`[${Z}="${n}"]`);
640
- return t instanceof HTMLElement && t.contains(e.ownerDocument.activeElement);
641
- }, Te = (e, n) => {
642
- if (!pe(e, n)) return null;
643
- const t = [...e.querySelectorAll(`[${ee}]`)].map((a) => a.getAttribute(ee)), o = t.indexOf(n), r = t[o + 1];
644
- if (o >= 0 && typeof r == "string") return { kind: "panel", panelId: r };
645
- const l = t[o - 1];
646
- return o > 0 && typeof l == "string" ? { kind: "panel", panelId: l } : { kind: "stage" };
647
- }, Me = (e, n) => {
648
- requestAnimationFrame(() => {
649
- const t = e.current;
650
- t !== null && (n.kind === "panel" && We(t, n.panelId) || t.focus({ preventScroll: !0 }));
651
- });
652
- }, Ke = (e, n) => {
653
- requestAnimationFrame(() => {
654
- const t = e.current;
655
- t !== null && We(t, n);
656
- });
657
- }, At = (e, n, t) => {
658
- requestAnimationFrame(() => {
659
- const o = e.current;
660
- if (o === null) return;
661
- const { activeElement: r, body: l } = o.ownerDocument;
662
- if (ne(o, n, t && pe(o, n) ? r : null), !t || r !== null && r !== l && r.isConnected) return;
663
- const a = o.querySelector(`[${ee}="${n}"]`);
664
- a instanceof HTMLElement && a.focus({ preventScroll: !0 });
665
- });
666
- }, Lt = ({ store: e, stageRef: n }) => {
667
- const { config: t, labels: o, announcer: r, edits: l } = J(), { maximize: a } = ue(), c = t.multiView.columns, m = _(e, (E) => E.layout), s = _(e, (E) => E.visibleColumns), v = _(e, (E) => E.titles), S = _(e, (E) => E.layout.maximized !== null || E.splitDragging), [O, N] = $(!1), [x] = $(() => be(s)), d = D(() => wt(o), [o]), h = R(
668
- (E) => {
669
- e.arrange(vt(e.getSnapshot().layout, E));
670
- },
671
- [e]
672
- ), f = wn({ initialColumnPanels: x, initialPanelVisibility: {}, debugConfig: ve, onColumnPanelsChange: h }), { columnPanels: P, setColumnPanels: T } = f, A = q(S), u = q(P);
673
- F(() => {
674
- A.current = S, u.current = P;
675
- }, [S, P]);
676
- const w = R(
677
- (E) => {
678
- const b = n.current;
679
- if (b === null) return;
680
- const { plan: B, stageBlockSize: z } = nt(b, c);
681
- if (Number.isFinite(z) && z > 0 && b.style.setProperty(fe, `${String(z)}px`), A.current && !E) return;
682
- const H = en(e.getSnapshot().visibleColumns, B);
683
- H !== null && e.setVisibleColumns(H);
684
- },
685
- [e, n, c]
686
- );
687
- F(() => {
688
- w(!0), N(!0);
689
- }, [w]), U(() => {
690
- const E = n.current;
691
- if (E === null || typeof ResizeObserver > "u") return;
692
- let b = null;
693
- const B = new ResizeObserver(() => {
694
- b === null && (b = requestAnimationFrame(() => {
695
- b = null, w(!1);
696
- }));
697
- }), z = E.querySelector(te)?.firstElementChild, H = E.querySelector(`[${me}]`);
698
- return z instanceof Element && B.observe(z), H instanceof Element && B.observe(H), () => {
699
- B.disconnect(), b !== null && cancelAnimationFrame(b);
700
- };
701
- }, [n, w]), U(() => {
702
- S || w(!1);
703
- }, [S, w]);
704
- const g = D(() => O ? ht(m, { logical: c, visible: s }) : be(s), [O, m, c, s]);
705
- F(() => {
706
- Nt(u.current, g) || T(g);
707
- }, [g, T]);
708
- const y = D(() => De(Object.keys(P)).map((E) => ({ id: E, key: E, className: "aqmx-multi-column" })), [P]), k = D(
709
- () => m.docs.map((E) => {
710
- const b = Q(m, E);
711
- return { id: b, component: gt, title: de(v, E), props: { docPath: E, panelId: b }, minHeight: Tt, maxHeight: Mt };
712
- }),
713
- [m, v]
714
- ), L = D(() => Object.fromEntries(m.docs.map((E) => [Q(m, E), !m.hidden.has(E)])), [m]), i = m.maximized === null ? null : Q(m, m.maximized), p = R(
715
- (E) => {
716
- const { layout: b } = e.getSnapshot();
717
- for (const [B, z] of X(b)) {
718
- const H = E[B];
719
- if (H === void 0 || H !== b.hidden.has(z)) continue;
720
- const j = e.titleOf(z);
721
- if (H) {
722
- if (!e.setHidden(z, !1)) continue;
723
- r.announce(o.panelShown(j)), Ke(n, B);
724
- continue;
725
- }
726
- const G = n.current, ge = G === null ? null : Te(G, B);
727
- e.setHidden(z, !0) && (r.announce(o.panelHidden(j)), ge !== null && Me(n, ge));
728
- }
729
- },
730
- [e, n, r, o]
731
- ), C = R(
732
- (E) => {
733
- const b = X(e.getSnapshot().layout).get(E);
734
- if (b === void 0) return;
735
- const B = () => {
736
- const H = e.titleOf(b), j = n.current, G = j === null ? null : Te(j, E);
737
- e.close(b) && (r.announce(o.panelClosed(H)), G !== null && Me(n, G));
738
- }, z = l.unsavedAmong([b]);
739
- z.length === 0 ? B() : l.askToDiscard(z).then((H) => {
740
- H && B();
741
- });
742
- },
743
- [e, n, r, o, l]
744
- ), I = R(
745
- (E) => {
746
- if (E === null) {
747
- a(null);
748
- return;
749
- }
750
- const b = X(e.getSnapshot().layout).get(E);
751
- b !== void 0 && a(b);
752
- },
753
- [e, a]
754
- );
755
- return /* @__PURE__ */ M("div", { className: "aqmx-multi-layout", "aria-busy": !O, children: /* @__PURE__ */ M(
756
- yn,
757
- {
758
- columns: y,
759
- panels: k,
760
- columnPanels: P,
761
- onColumnPanelsChange: h,
762
- panelVisibility: L,
763
- onPanelVisibilityChange: p,
764
- dragState: f.dragState,
765
- dragOverPosition: f.dragOverPosition,
766
- originalPanelPosition: f.originalPanelPosition,
767
- dragModes: f.dragModes,
768
- debugConfig: ve,
769
- panelSizes: f.panelSizes,
770
- customDrag: f.customDrag,
771
- setPanelRef: f.setPanelRef,
772
- onDragStart: f.handleDragStart,
773
- onDragEnd: f.handleDragEnd,
774
- onPlaceholderDragEnter: f.handlePlaceholderDragEnter,
775
- onPlaceholderDragLeave: f.handlePlaceholderDragLeave,
776
- onDragOverWithInsert: f.handleDragOverWithInsert,
777
- onDropWithInsert: f.handleDropWithInsert,
778
- onColumnDragLeave: f.handleColumnDragLeave,
779
- onPanelMouseDown: f.handleMouseDown,
780
- onPanelSizeInfoClick: f.handlePanelSizeInfoClick,
781
- onToggleDragMode: f.toggleDragMode,
782
- onPanelClose: C,
783
- onPanelMaximizeChange: I,
784
- maximizedPanel: i,
785
- dragHandle: "header",
786
- labels: d,
787
- panelClassName: "aqmx-multi-panel",
788
- renderPanelScrollArea: bt,
789
- renderStageScrollBar: Pt
790
- }
791
- ) });
792
- }, se = { blockStart: "--aqmx-multi-toast-block-start", inlineEnd: "--aqmx-multi-toast-inline-end", room: "--aqmx-multi-toast-room" }, It = (e, n) => {
793
- const t = n.getBoundingClientRect(), o = [t.left + 1, t.left + t.width / 2, t.right - 1], r = [t.top + 1, t.top + t.height / 2, t.bottom - 1];
794
- return o.some(
795
- (l) => r.some((a) => {
796
- const c = n.ownerDocument.elementsFromPoint(l, a), m = c.findIndex((v) => n.contains(v)), s = c.findIndex((v) => e.contains(v));
797
- return m !== -1 && s !== -1 && s < m;
798
- })
799
- );
800
- }, Rt = (e, n) => {
801
- const t = n.getBoundingClientRect(), o = n.ownerDocument.documentElement.clientWidth, r = getComputedStyle(n).direction === "rtl";
802
- return e.style.setProperty(se.blockStart, `${String(t.top)}px`), e.style.setProperty(se.inlineEnd, `${String(r ? t.left : o - t.right)}px`), e.style.setProperty(se.room, `${String(t.width)}px`), e.showPopover(), () => {
803
- e.isConnected && e.hidePopover();
804
- };
805
- }, Dt = ({ store: e, body: n, limitNotice: t, onLimitNoticeCovered: o, ref: r }) => {
806
- const { config: l, labels: a, announcer: c, edits: m } = J(), s = q(null), v = q(null), S = _(e, (u) => u.ready), O = _(e, (u) => u.layout.docs.length > 0), N = _(e, (u) => u.visibleColumns), x = ke(fn), d = R(
807
- (u) => {
808
- const { layout: w } = e.getSnapshot(), g = w.maximized, y = u === null && g !== null ? w.panelIds.get(g) : void 0, k = s.current, L = y !== void 0 && k !== null && pe(k, y);
809
- e.maximize(u) && (u !== null ? c.announce(a.panelMaximized(e.titleOf(u))) : g !== null && c.announce(a.panelRestored(e.titleOf(g))), y !== void 0 && At(s, y, L));
810
- },
811
- [e, c, a]
812
- ), h = R(
813
- (u, w, g, y) => {
814
- if (g === w) {
815
- e.setPendingHash(u, y);
816
- return;
817
- }
818
- const k = m.unsavedAmong([w]);
819
- if (k.length > 0) {
820
- m.askToDiscard(k).then((C) => {
821
- C && h(u, w, g, y);
822
- });
823
- return;
824
- }
825
- const L = e.navigate(w, g);
826
- if (L === "navigated") {
827
- e.setPendingHash(u, y);
828
- return;
829
- }
830
- if (L !== "existing") return;
831
- const { layout: i } = e.getSnapshot(), p = i.panelIds.get(g);
832
- p !== void 0 && (c.announce(a.panelAlreadyOpen(e.titleOf(g))), i.maximized === null ? e.setHidden(g, !1) : d(g), e.setPendingHash(p, y), Ke(s, p));
833
- },
834
- [e, c, a, d, m]
835
- );
836
- F(() => {
837
- if (t === null || x !== null || !Se()) return;
838
- const u = v.current, w = s.current;
839
- if (u === null || w === null) throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");
840
- return Rt(u, w);
841
- }, [t, x]), U(() => {
842
- const u = v.current;
843
- if (t === null || u === null) return;
844
- const { ownerDocument: w } = u;
845
- let g = null;
846
- const y = (k) => {
847
- const L = k.target;
848
- L instanceof Element && (g !== null && cancelAnimationFrame(g), g = requestAnimationFrame(() => {
849
- g = null, w.activeElement === L && u.isConnected && It(u, L) && o();
850
- }));
851
- };
852
- return w.addEventListener("focusin", y, !0), () => {
853
- w.removeEventListener("focusin", y, !0), g !== null && cancelAnimationFrame(g);
854
- };
855
- }, [t, x, o]), Ze(
856
- r,
857
- () => ({
858
- bringIntoView: (u) => {
859
- requestAnimationFrame(() => {
860
- const w = s.current, g = e.getSnapshot().layout.panelIds.get(u);
861
- w !== null && g !== void 0 && ne(w, g, null);
862
- });
863
- }
864
- }),
865
- [e]
866
- ), U(() => {
867
- const u = s.current;
868
- return () => {
869
- u !== null && K.get(u)?.();
870
- };
871
- }, []);
872
- const f = R((u, w) => {
873
- const g = s.current;
874
- g !== null && ne(g, u, w);
875
- }, []), [P] = $(Nn), T = D(() => ({ store: e, Body: n, followLink: h, maximize: d, revealInPanel: f, focusCarry: P }), [e, n, h, d, f, P]), A = D(() => Array.from({ length: l.multiView.columns }, (u, w) => _e(w)), [l]);
876
- return (
877
- /* @__PURE__ */ ie("section", { ref: s, className: "aqmx-multi-stage", style: St, tabIndex: -1, "aria-label": a.multiRegion, "aria-busy": O && !S, "data-testid": "markdown-explorer-stage", "data-aqmx-visible-columns": N, ...Le, children: [
878
- /* @__PURE__ */ M("span", { className: "aqmx-multi-probe", "aria-hidden": "true", [me]: "" }),
879
- O ? S ? /* @__PURE__ */ M(ze, { value: T, children: /* @__PURE__ */ M(Lt, { store: e, stageRef: s }) }) : /* @__PURE__ */ M("div", { className: "aqmx-multi-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-stage-skeleton", children: A.map((u) => /* @__PURE__ */ ie("div", { className: "aqmx-skeleton aqmx-multi-skeleton-column", children: [
880
- /* @__PURE__ */ M("span", {}),
881
- /* @__PURE__ */ M("span", {}),
882
- /* @__PURE__ */ M("span", {})
883
- ] }, u)) }) : /* @__PURE__ */ M("div", { className: "aqmx-empty", "data-testid": "markdown-explorer-multi-empty", children: /* @__PURE__ */ M("p", { className: "aqmx-empty-title", children: a.multiEmpty }) }),
884
- t === null ? null : x !== null ? Tn(
885
- /* @__PURE__ */ M("div", { ref: v, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t }),
886
- x
887
- ) : (
888
- /* @__PURE__ */ M("div", { ref: v, popover: Se() ? "manual" : void 0, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t })
889
- )
890
- ] })
891
- );
892
- }, _t = 3e3, zt = (e, n) => {
893
- if (n !== null) return n;
894
- const [t] = e;
895
- return t === void 0 ? null : t;
896
- }, Ne = (e, n, t) => {
897
- const o = new Set(e), r = n.filter((a) => !o.has(a)), l = r.length > 0 ? r.at(-1) : t !== null && n.includes(t) ? t : n.at(-1);
898
- return l === void 0 ? null : l;
899
- }, Ht = (e, n, t) => {
900
- switch (n) {
901
- case "opened":
902
- return e.panelOpened(t);
903
- case "shown":
904
- return e.panelShown(t);
905
- case "closed":
906
- return e.panelClosed(t);
907
- default: {
908
- const o = n;
909
- throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`);
910
- }
911
- }
912
- }, Jt = ({ location: e }) => {
913
- const { config: n, labels: t, announcer: o } = J(), r = Xn(e), l = _(r, (y) => y.layout.docs), a = _(r, (y) => y.layout.maximized), c = _(r, (y) => y.layout.markup), m = _(r, (y) => y.source), [s, v] = $(() => ({ docs: l, latest: Ne([], l, null) }));
914
- s.docs !== l && v({ docs: l, latest: Ne(s.docs, l, s.latest) });
915
- const S = a !== null ? a : s.latest, [O, N] = $(!1), x = q(null), [d, h] = $(0), f = q(null), P = q(null);
916
- F(() => {
917
- const y = f.current;
918
- f.current = null, y !== null && (r.whenUrlRendered(() => o.announce(y.announcement)), P.current?.bringIntoView(y.doc));
919
- }), U(
920
- () => () => {
921
- x.current !== null && clearTimeout(x.current);
922
- },
923
- []
924
- );
925
- const T = R(() => {
926
- x.current !== null && clearTimeout(x.current), N(!0), x.current = setTimeout(() => {
927
- x.current = null, N(!1);
928
- }, _t);
929
- }, []), A = R(() => {
930
- x.current !== null && clearTimeout(x.current), x.current = null, N(!1);
931
- }, []), u = R(
932
- (y) => {
933
- const k = r.titleOf(y), L = r.toggle(y);
934
- L === "rejected" && T();
935
- const i = L === "rejected" ? t.panelLimit(n.multiView.maxPanels) : Ht(t, L, k);
936
- if (L === "shown") {
937
- f.current = { doc: y, announcement: i }, h((p) => p + 1);
938
- return;
939
- }
940
- r.whenUrlRendered(() => {
941
- o.announce(i), L === "opened" && P.current?.bringIntoView(y);
942
- });
943
- },
944
- [r, T, o, t, n]
945
- ), w = D(() => new Set(l), [l]), g = D(() => {
946
- const y = zt(l, a);
947
- return { href: Ae(n, { view: "tree", source: m, doc: y, markup: y !== null && c.has(y) }), target: "tree" };
948
- }, [n, m, l, a, c]);
949
- return /* @__PURE__ */ M(
950
- pn,
951
- {
952
- view: "multi",
953
- explorer: /* @__PURE__ */ M(gn, { mode: "multi", sourceId: m, currentPath: S, openPaths: w, onOpenDocument: u, onSourceChange: r.changeSource, onRevealSource: r.revealSource, viewSwitch: g }),
954
- content: /* @__PURE__ */ M(Dt, { ref: P, store: r, body: Zn, limitNotice: O ? t.panelLimit(n.multiView.maxPanels) : null, onLimitNoticeCovered: A }),
955
- contentCoversPage: a !== null,
956
- sheetDismissals: d,
957
- onDraggingChange: r.setSplitDragging
958
- }
959
- );
960
- };
961
- export {
962
- Jt as MultiLayout,
963
- _t as PANEL_LIMIT_NOTICE_MS,
964
- Ne as latestOpenedDocument,
965
- zt as treeSwitchDocument
966
- };