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