@aiquants/markdown-explorer 0.12.1 → 0.13.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 (42) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/README.md +20 -12
  3. package/dist/EditSurface-DheIbHJi.js +705 -0
  4. package/dist/EditSurface-omuATGni.cjs +2 -0
  5. package/dist/{ExplorerSplit-CqmbUSZ7.cjs → ExplorerSplit-DMizcKaY.cjs} +1 -1
  6. package/dist/{ExplorerSplit-BjjqNRtj.js → ExplorerSplit-DvcNMIjl.js} +109 -109
  7. package/dist/{MultiLayout-BYXoD1aS.js → MultiLayout-C2R85L4x.js} +25 -25
  8. package/dist/{MultiLayout-BZbEl73E.cjs → MultiLayout-Cq4y1I1g.cjs} +1 -1
  9. package/dist/{NativeScrollBar-RP37nwmY.js → NativeScrollBar-CKfD2qpM.js} +1 -1
  10. package/dist/{NativeScrollBar-B7jTbQmn.cjs → NativeScrollBar-qvtXkNTx.cjs} +1 -1
  11. package/dist/{TreeLayout-CEp5oKly.cjs → TreeLayout-8_V4L9s6.cjs} +1 -1
  12. package/dist/{TreeLayout-Uo6RG7lq.js → TreeLayout-FCp9WPFO.js} +3 -3
  13. package/dist/core/contracts.d.cts +7 -1
  14. package/dist/core/contracts.d.ts +7 -1
  15. package/dist/core/labels.d.cts +14 -1
  16. package/dist/core/labels.d.ts +14 -1
  17. package/dist/{dataRoute-CH3yOKR0.cjs → dataRoute-BONacTPi.cjs} +1 -1
  18. package/dist/{dataRoute-Pm_0ue_4.js → dataRoute-CObbjNxG.js} +14 -12
  19. package/dist/index-CdydPdP7.js +3463 -0
  20. package/dist/index-afZWk187.cjs +13 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +21 -21
  23. package/dist/{location-BUNWJ4eB.cjs → location-D6RE3wAN.cjs} +1 -1
  24. package/dist/{location-DWd6SQhN.js → location-IRD9h42r.js} +1 -1
  25. package/dist/{merge-q-5i8qsn.js → merge-Bb7YRgn4.js} +1 -1
  26. package/dist/{merge-DRGBbLuR.cjs → merge-Dm_uFthw.cjs} +1 -1
  27. package/dist/{sanitizePolicy-djLC3fRN.js → sanitizePolicy-DlrakwA4.js} +1 -1
  28. package/dist/{sanitizePolicy-BfUlXI5E.cjs → sanitizePolicy-DrIMuYCb.cjs} +1 -1
  29. package/dist/sanitizeWorker.cjs +1 -1
  30. package/dist/sanitizeWorker.js +1 -1
  31. package/dist/server/ports.d.cts +3 -0
  32. package/dist/server/ports.d.ts +3 -0
  33. package/dist/server.cjs +1 -1
  34. package/dist/server.js +93 -83
  35. package/dist/styles/markdown-explorer.css +1 -1
  36. package/docs/behavior/dom-hooks.md +6 -5
  37. package/docs/behavior/layout.md +10 -3
  38. package/package.json +1 -1
  39. package/dist/EditSurface-By6NPcD7.js +0 -633
  40. package/dist/EditSurface-BztcpQPW.cjs +0 -2
  41. package/dist/index-CGBl3fYT.cjs +0 -13
  42. package/dist/index-CjCr8czx.js +0 -3356
@@ -1,12 +1,12 @@
1
1
  import { jsxs as ie, jsx as M } from "react/jsx-runtime";
2
2
  import { createContext as We, use as Te, useRef as q, useState as $, useLayoutEffect as F, useMemo as R, useSyncExternalStore as Ke, useCallback as I, memo as Je, useEffect as U, useImperativeHandle as Xe } from "react";
3
- import { g as ce, e as ke, h as Ze, P as Qe, j as en } from "./location-DWd6SQhN.js";
4
- import { k as nn, u as J, m as tn, I as on, D as rn, c as ln, n as sn, L as Le } from "./index-CjCr8czx.js";
5
- import { S as an, a as cn, b as un } from "./ExplorerSplit-BjjqNRtj.js";
3
+ import { g as ce, e as ke, h as Ze, P as Qe, j as en } from "./location-IRD9h42r.js";
4
+ import { z as nn, u as J, B as tn, I as on, D as rn, c as ln, G as sn, L as Le } from "./index-CdydPdP7.js";
5
+ import { S as an, a as cn, b as un } from "./ExplorerSplit-DvcNMIjl.js";
6
6
  import { SCROLL_AREA_SELECTOR as Ae, SCROLL_ROOT_SELECTOR as te, generateColumnIds as dn, sortColumnIds as Ie, generateColumnId as De, NO_PANEL_DRAG_ATTRIBUTE as mn, useDragDropColumns as fn, DEFAULT_DEBUG_CONFIG as he, DragDropLayout as pn } from "@aiquants/drag-drop-panels";
7
7
  import { useNavigate as gn, useLocation as hn } from "react-router";
8
8
  import { s as vn, r as wn, w as yn } from "./storage-BSthKLSG.js";
9
- import { F as Sn, i as xn } from "./dataRoute-Pm_0ue_4.js";
9
+ import { F as Sn, i as xn } from "./dataRoute-CObbjNxG.js";
10
10
  import { createPortal as En } from "react-dom";
11
11
  import { HostedScrollArea as On } from "@aiquants/markdown";
12
12
  import { N as bn } from "./scrollBarGeometry-DOBdGNV-.js";
@@ -180,17 +180,17 @@ const Pn = () => {
180
180
  t.delete(o);
181
181
  }
182
182
  return { ...e, columnOf: t };
183
- }, Ve = 1, G = Object.freeze({ columnOf: /* @__PURE__ */ new Map(), hidden: /* @__PURE__ */ new Set() }), Un = (e, n) => {
184
- if (e === null || e === "") return G;
183
+ }, Ve = 1, Y = Object.freeze({ columnOf: /* @__PURE__ */ new Map(), hidden: /* @__PURE__ */ new Set() }), Un = (e, n) => {
184
+ if (e === null || e === "") return Y;
185
185
  let t;
186
186
  try {
187
187
  t = JSON.parse(e);
188
188
  } catch {
189
- return G;
189
+ return Y;
190
190
  }
191
- if (t === null || typeof t != "object" || Array.isArray(t)) return G;
191
+ if (t === null || typeof t != "object" || Array.isArray(t)) return Y;
192
192
  const o = t;
193
- if (o.v !== Ve) return G;
193
+ if (o.v !== Ve) return Y;
194
194
  const r = /* @__PURE__ */ new Map();
195
195
  if (Array.isArray(o.columnOf))
196
196
  for (const a of o.columnOf.slice(-oe))
@@ -210,10 +210,10 @@ const Pn = () => {
210
210
  return n;
211
211
  }, we = (e) => {
212
212
  if (!xn(e)) throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(e.slice(0, 80))}`);
213
- }, Yn = ({ config: e, location: n, writeUrl: t, persist: o }) => {
213
+ }, Gn = ({ config: e, location: n, writeUrl: t, persist: o }) => {
214
214
  const { maxPanels: r, columns: l } = e.multiView, a = nn(), d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
215
215
  let s = {
216
- layout: le({ docs: n.docs, maximized: n.maximized, markup: n.markup, stored: G }, r),
216
+ layout: le({ docs: n.docs, maximized: n.maximized, markup: n.markup, stored: Y }, r),
217
217
  source: n.source,
218
218
  visibleColumns: l,
219
219
  ready: !1,
@@ -330,9 +330,9 @@ const Pn = () => {
330
330
  }, _ = (e, n) => {
331
331
  const t = () => n(e.getSnapshot());
332
332
  return Ke(e.subscribe, t, t);
333
- }, Gn = (e) => {
333
+ }, Yn = (e) => {
334
334
  const { config: n, storageNamespace: t } = J(), o = gn(), r = q(o), l = vn(t).multiLayout, [a] = $(
335
- () => Yn({
335
+ () => Gn({
336
336
  config: n,
337
337
  location: e,
338
338
  writeUrl: (s, v) => {
@@ -613,7 +613,7 @@ const Pn = () => {
613
613
  };
614
614
  for (const w of be) m.addEventListener(w, v, { capture: !0, passive: !0 });
615
615
  m.addEventListener("scroll", s, { capture: !0, passive: !0 }), K.set(e, v);
616
- }, Ye = (e, n) => {
616
+ }, Ge = (e, n) => {
617
617
  const t = e.querySelector(`[${ee}="${n}"]`);
618
618
  return t instanceof HTMLElement ? (ne(e, n, null), t.focus({ preventScroll: !0 }), !0) : !1;
619
619
  }, pe = (e, n) => {
@@ -628,12 +628,12 @@ const Pn = () => {
628
628
  }, Me = (e, n) => {
629
629
  requestAnimationFrame(() => {
630
630
  const t = e.current;
631
- t !== null && (n.kind === "panel" && Ye(t, n.panelId) || t.focus({ preventScroll: !0 }));
631
+ t !== null && (n.kind === "panel" && Ge(t, n.panelId) || t.focus({ preventScroll: !0 }));
632
632
  });
633
- }, Ge = (e, n) => {
633
+ }, Ye = (e, n) => {
634
634
  requestAnimationFrame(() => {
635
635
  const t = e.current;
636
- t !== null && Ye(t, n);
636
+ t !== null && Ge(t, n);
637
637
  });
638
638
  }, Mt = (e, n, t) => {
639
639
  requestAnimationFrame(() => {
@@ -701,10 +701,10 @@ const Pn = () => {
701
701
  const j = e.titleOf(z);
702
702
  if (H) {
703
703
  if (!e.setHidden(z, !1)) continue;
704
- r.announce(o.panelShown(j)), Ge(n, B);
704
+ r.announce(o.panelShown(j)), Ye(n, B);
705
705
  continue;
706
706
  }
707
- const Y = n.current, ge = Y === null ? null : Ce(Y, B);
707
+ const G = n.current, ge = G === null ? null : Ce(G, B);
708
708
  e.setHidden(z, !0) && (r.announce(o.panelHidden(j)), ge !== null && Me(n, ge));
709
709
  }
710
710
  },
@@ -714,8 +714,8 @@ const Pn = () => {
714
714
  const O = X(e.getSnapshot().layout).get(x);
715
715
  if (O === void 0) return;
716
716
  const B = () => {
717
- const H = e.titleOf(O), j = n.current, Y = j === null ? null : Ce(j, x);
718
- e.close(O) && (r.announce(o.panelClosed(H)), Y !== null && Me(n, Y));
717
+ const H = e.titleOf(O), j = n.current, G = j === null ? null : Ce(j, x);
718
+ e.close(O) && (r.announce(o.panelClosed(H)), G !== null && Me(n, G));
719
719
  }, z = l.unsavedAmong([O]);
720
720
  z.length === 0 ? B() : l.askToDiscard(z).then((H) => {
721
721
  H && B();
@@ -810,7 +810,7 @@ const Pn = () => {
810
810
  }
811
811
  if (L !== "existing") return;
812
812
  const { layout: i } = e.getSnapshot(), f = i.panelIds.get(E);
813
- f !== void 0 && (d.announce(a.panelAlreadyOpen(e.titleOf(E))), i.maximized === null ? e.setHidden(E, !1) : p(E), e.setPendingHash(f, S), Ge(s, f));
813
+ f !== void 0 && (d.announce(a.panelAlreadyOpen(e.titleOf(E))), i.maximized === null ? e.setHidden(E, !1) : p(E), e.setPendingHash(f, S), Ye(s, f));
814
814
  },
815
815
  [e, d, a, p, m]
816
816
  );
@@ -890,8 +890,8 @@ const Pn = () => {
890
890
  throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`);
891
891
  }
892
892
  }
893
- }, Gt = ({ location: e }) => {
894
- const { config: n, labels: t, announcer: o } = J(), r = Gn(e), l = _(r, (S) => S.layout.docs), a = _(r, (S) => S.layout.maximized), d = _(r, (S) => S.layout.markup), m = _(r, (S) => S.source), [s, v] = $(() => ({ docs: l, latest: Ne([], l, null) }));
893
+ }, Yt = ({ location: e }) => {
894
+ const { config: n, labels: t, announcer: o } = J(), r = Yn(e), l = _(r, (S) => S.layout.docs), a = _(r, (S) => S.layout.maximized), d = _(r, (S) => S.layout.markup), m = _(r, (S) => S.source), [s, v] = $(() => ({ docs: l, latest: Ne([], l, null) }));
895
895
  s.docs !== l && v({ docs: l, latest: Ne(s.docs, l, s.latest) });
896
896
  const w = a !== null ? a : s.latest, [b, N] = $(!1), c = q(null), [p, y] = $(0), g = q(null), P = q(null);
897
897
  F(() => {
@@ -940,7 +940,7 @@ const Pn = () => {
940
940
  );
941
941
  };
942
942
  export {
943
- Gt as MultiLayout,
943
+ Yt as MultiLayout,
944
944
  At as PANEL_LIMIT_NOTICE_MS,
945
945
  Ne as latestOpenedDocument,
946
946
  It as treeSwitchDocument
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),u=require("react"),j=require("./location-BUNWJ4eB.cjs"),q=require("./index-CGBl3fYT.cjs"),re=require("./ExplorerSplit-CqmbUSZ7.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-Dgi4JXaB.cjs"),Ce=require("./dataRoute-CH3yOKR0.cjs"),je=require("react-dom"),Fe=require("@aiquants/markdown"),Ve=require("./scrollBarGeometry-C46jBtmM.cjs"),Ue=()=>{const e=new Map;return{hold:(n,t)=>{e.set(n,t),queueMicrotask(()=>{e.get(n)===t&&e.delete(n)})},take:n=>{const t=e.get(n);return e.delete(n),t===void 0?null:t}}},Pe=u.createContext(null),ie=()=>{const e=u.use(Pe);if(e===null)throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");return e},$e=(e,n)=>{const t=e.pendingHashes.get(n);return t===void 0?null:t},Ge=0xcbf29ce484222325n,Ye=0x100000001b3n,We=(1n<<64n)-1n,Ke=(1n<<53n)-1n,Je=new TextEncoder,Xe=e=>{let n=Ge;for(const t of Je.encode(e))n=(n^BigInt(t))*Ye&We;return Number(n&Ke)},Q=256,Ze=e=>`aqmx-p-${Xe(e).toString(36)}`,Me=(e,n)=>{const t=Ze(e);let o=t;for(let r=2;n.has(o);r+=1)o=`${t}-${String(r)}`;return o},Qe=new Map,en=(e,n=Qe)=>{const t=new Set(e.flatMap(r=>n.get(r)??[])),o=new Map;for(const r of e){const s=n.get(r)??Me(r,t);t.add(s),o.set(r,s)}return o},Le=(e,n,t)=>{const o=e.columnOf.get(n);return o===void 0?void 0:Math.min(t-1,Math.max(0,o))},ke=(e,n)=>{const[t,...o]=j.columnGroups(n.logical,n.visible);if(t===void 0)throw new RangeError("[markdown-explorer] there must be at least one visible column");const r=([m,f])=>e.slice(m,f).reduce((l,y)=>l+y.length,0);let s=t;for(const m of o)r(m)<r(s)&&(s=m);let a=s[0];for(let m=s[0];m<s[1];m+=1)(e[m]?.length??0)<(e[a]?.length??0)&&(a=m);return a},ee=(e,n)=>{const t=Array.from({length:n.logical},()=>[]),o=[];for(const r of e.docs){const s=Le(e,r,n.logical);s===void 0?o.push(r):t[s]?.push(r)}for(const r of o)t[ke(t,n)]?.push(r);return t},nn=(e,n)=>j.columnGroups(e.length,n).map(([t,o])=>e.slice(t,o).flat()),tn=(e,n,t)=>{const[o,r]=n,s=r-o,a=e.length,m=Array.from({length:s},(c,g)=>{const w=[0];for(const h of e)w.push((w.at(-1)??0)+(t(h)===o+g?1:0));return w}),f=(c,g,w)=>(m[c]?.[w]??0)-(m[c]?.[g]??0),l=Array.from({length:s+1},()=>Array.from({length:a+1},()=>Number.NEGATIVE_INFINITY)),y=Array.from({length:s+1},()=>Array.from({length:a+1},()=>0)),S=l[0];S&&(S[0]=0);for(let c=0;c<s;c+=1)for(let g=0;g<=a;g+=1)for(let w=0;w<=g;w+=1){const h=(l[c]?.[w]??Number.NEGATIVE_INFINITY)+f(c,w,g),P=l[c+1],T=y[c+1];P&&T&&h>(P[g]??Number.NEGATIVE_INFINITY)&&(P[g]=h,T[g]=w)}const C=Array.from({length:s},()=>[]);let k=a;for(let c=s;c>0;c-=1){const g=y[c]?.[k]??0;C[c-1]=e.slice(g,k),k=g}return C},Te=(e,n)=>{const t=n.flat(),o=new Map(e.columnOf);for(const[r,s]of n.entries())for(const a of s)o.delete(a),o.set(a,r);for(const r of o.keys()){if(o.size<=Q)break;o.delete(r)}return{docs:t,columnOf:o}},on=(e,n,t,o)=>{if(e.docs.includes(n))return{state:e,outcome:"existing"};if(e.docs.length>=o)return{state:e,outcome:"rejected"};const r=ee(e,t),s=Le(e,n,t.logical)??ke(r,t);r[s]?.push(n);const a=new Map(e.panelIds);return a.set(n,Me(n,new Set(a.values()))),{state:{...e,...Te(e,r),panelIds:a},outcome:"opened"}},Re=(e,n)=>{if(!e.docs.includes(n))return e;const t=new Set(e.hidden);t.delete(n);const o=new Set(e.markup);o.delete(n);const r=new Map(e.panelIds);return r.delete(n),{...e,docs:e.docs.filter(s=>s!==n),hidden:t,markup:o,panelIds:r,maximized:e.maximized===n?null:e.maximized}},rn=(e,n,t,o)=>{if(e.hidden.has(n))return{state:Ne(e,n,!1),outcome:"shown"};if(e.docs.includes(n))return{state:Re(e,n),outcome:"closed"};const r=on(e,n,t,o);return{state:r.state,outcome:r.outcome==="rejected"?"rejected":"opened"}},sn=(e,n,t)=>{if(n===t||!e.docs.includes(n))return{state:e,outcome:"ignored"};if(e.docs.includes(t))return{state:e,outcome:"existing"};const o=new Map(e.columnOf),r=o.get(n);r!==void 0&&(o.delete(t),o.set(t,r));const s=new Set(e.hidden);s.delete(n);const a=new Map(e.panelIds),m=a.get(n);if(m===void 0)throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);a.delete(n),a.set(t,m);const f=new Set(e.markup);return f.delete(n),{state:{docs:e.docs.map(l=>l===n?t:l),maximized:e.maximized===n?t:e.maximized,columnOf:o,hidden:s,markup:f,panelIds:a},outcome:"navigated"}},Ne=(e,n,t)=>{if(!e.docs.includes(n)||e.hidden.has(n)===t)return e;const o=new Set(e.hidden);return t?o.add(n):o.delete(n),{...e,hidden:o,maximized:t&&e.maximized===n?null:e.maximized}},ln=(e,n,t)=>{if(!e.docs.includes(n)||e.markup.has(n)===t)return e;const o=new Set(e.markup);return t?o.add(n):o.delete(n),{...e,markup:o}},an=(e,n)=>{if(e.maximized===n||n!==null&&!e.docs.includes(n))return e;if(n===null||!e.hidden.has(n))return{...e,maximized:n};const t=new Set(e.hidden);return t.delete(n),{...e,maximized:n,hidden:t}},cn=(e,n,t)=>{const o=ee(e,t),r=new Map;for(const[l,y]of o.entries())for(const S of y)r.set(S,l);const s=new Set(e.docs),a=new Set,m=j.columnGroups(t.logical,t.visible),f=Array.from({length:t.logical},()=>[]);for(const[l,y]of m.entries()){const S=(n[l]??[]).filter(C=>s.has(C)&&!a.has(C));for(const C of S)a.add(C);for(const[C,k]of tn(S,y,c=>r.get(c)).entries())f[y[0]+C]?.push(...k)}for(const l of e.docs)a.has(l)||f[r.get(l)??0]?.push(l);return f.every((l,y)=>l.length===o[y]?.length&&l.every((S,C)=>o[y]?.[C]===S))?e:{...e,...Te(e,f)}},te=(e,n)=>{const t=[...new Set(e.docs)].slice(0,n),o=new Set(t),r=e.maximized!==null&&o.has(e.maximized)?e.maximized:null;return{docs:t,maximized:r,columnOf:e.stored.columnOf,hidden:new Set([...e.stored.hidden].filter(s=>o.has(s)&&s!==r)),markup:new Set(e.markup.filter(s=>o.has(s))),panelIds:en(t,e.panelIds)}},pe=(e,n)=>{if(e.docs.every(o=>e.columnOf.has(o)))return e;const t=new Map(e.columnOf);for(const[o,r]of ee(e,n).entries())for(const s of r)t.delete(s),t.set(s,o);for(const o of t.keys()){if(t.size<=Q)break;t.delete(o)}return{...e,columnOf:t}},Ie=1,$=Object.freeze({columnOf:new Map,hidden:new Set}),un=(e,n)=>{if(e===null||e==="")return $;let t;try{t=JSON.parse(e)}catch{return $}if(t===null||typeof t!="object"||Array.isArray(t))return $;const o=t;if(o.v!==Ie)return $;const r=new Map;if(Array.isArray(o.columnOf))for(const a of o.columnOf.slice(-Q))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]));const s=new Set(Array.isArray(o.hidden)?o.hidden.filter(a=>typeof a=="string"&&a!==""):[]);return{columnOf:r,hidden:s}},dn=e=>JSON.stringify({v:Ie,columnOf:[...e.columnOf.entries()].slice(-Q),hidden:e.docs.filter(n=>e.hidden.has(n))}),ae=(e,n)=>{const t=e.get(n);return t===void 0?Ce.lastPathSegment(n):t},W=e=>{const n=new Map;for(const[t,o]of e.panelIds)n.set(o,t);return n},ge=e=>{if(!Ce.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(e.slice(0,80))}`)},mn=({config:e,location:n,writeUrl:t,persist:o})=>{const{maxPanels:r,columns:s}=e.multiView,a=q.createEmitter(),m=new Map,f=new Map;let l={layout:te({docs:n.docs,maximized:n.maximized,markup:n.markup,stored:$},r),source:n.source,visibleColumns:s,ready:!1,splitDragging:!1,titles:new Map,pendingHashes:new Map},y=!1;const S=i=>y?pe(i,{logical:s,visible:l.visibleColumns}):i,C=(i,p)=>j.explorerHref(e,{view:"multi",source:i,docs:p.docs,maximized:p.maximized,markup:p.markup}),k=i=>({docs:i.docs,maximized:i.maximized,markup:[...i.markup]});let c=C(n.source,n),g=n.source,w=c;const h=[],P=[];let T=null;const A=()=>{if(!(h.length>0))for(const i of P.splice(0))i()},d=i=>{l={...l,...i},a.emit()},v=()=>{if(!l.ready)return;const i=dn(l.layout);i!==T&&(T=i,o(i))},O=(i,p,M)=>{const I=C(i,k(p));I!==c&&(c=I,g=i,h.push(I),t(I,M))},x=i=>{const p=new Set(i.panelIds.values());for(const b of[...m.keys()])p.has(b)||m.delete(b);for(const b of[...f.keys()])p.has(b)||f.delete(b);const M=new Set(i.docs),I=[...l.titles.keys()].every(b=>M.has(b))?l.titles:new Map([...l.titles].filter(([b])=>M.has(b))),E=[...l.pendingHashes.keys()].every(b=>p.has(b))?l.pendingHashes:new Map([...l.pendingHashes].filter(([b])=>p.has(b)));return{titles:I,pendingHashes:E}},R=i=>i===l.layout?!1:(d({layout:i,...x(i)}),O(g,i,"replace"),v(),!0),N=()=>({logical:s,visible:l.visibleColumns});return{getSnapshot:()=>l,subscribe:a.subscribe,toggle:i=>{ge(i);const{state:p,outcome:M}=rn(l.layout,i,N(),r);return R(p),M},close:i=>R(Re(l.layout,i)),navigate:(i,p)=>{ge(p);const{state:M,outcome:I}=sn(l.layout,i,p);if(I!=="navigated")return I;const E=M.panelIds.get(p);return E!==void 0&&(m.delete(E),f.delete(E)),R(M),I},setHidden:(i,p)=>R(Ne(l.layout,i,p)),maximize:i=>R(an(l.layout,i)),setMarkup:(i,p)=>R(ln(l.layout,i,p)),arrange:i=>R(cn(l.layout,i,{logical:s,visible:i.length})),changeSource:i=>{O(i,l.layout,"push")},revealSource:i=>{O(i,l.layout,"replace")},observeLocation:i=>{const p=C(i.source,i);if(p===c)return h.length=0,w=p,i.source!==l.source&&d({source:i.source}),A(),!1;if(p===w)return!1;w=p;const M=h.indexOf(p);if(M>=0)return h.splice(0,M+1),i.source!==l.source&&d({source:i.source}),A(),!1;h.length=0,c=p,g=i.source;const I=S(te({docs:i.docs,maximized:i.maximized,markup:i.markup,stored:{columnOf:l.layout.columnOf,hidden:l.layout.hidden},panelIds:l.layout.panelIds},r));return d({layout:I,source:i.source,...x(I)}),v(),A(),!0},whenUrlRendered:i=>{P.push(i),A()},loadStored:i=>{d({layout:S(te({docs:l.layout.docs,maximized:l.layout.maximized,markup:[...l.layout.markup],stored:i,panelIds:l.layout.panelIds},r)),ready:!0}),v()},setVisibleColumns:i=>{if(!Number.isInteger(i)||i<1||i>s)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(s)}; got ${String(i)}`);y=!0;const p=pe(l.layout,{logical:s,visible:i});i===l.visibleColumns&&p===l.layout||(d({visibleColumns:i,layout:p}),p!==l.layout&&v())},setSplitDragging:i=>{i!==l.splitDragging&&d({splitDragging:i})},setTitle:(i,p)=>{!l.layout.docs.includes(i)||l.titles.get(i)===p||d({titles:new Map(l.titles).set(i,p)})},titleOf:i=>ae(l.titles,i),setPendingHash:(i,p)=>{const M=l.pendingHashes.get(i);if(p===null||p===""){if(M===void 0)return;const I=new Map(l.pendingHashes);I.delete(i),d({pendingHashes:I});return}M!==p&&d({pendingHashes:new Map(l.pendingHashes).set(i,p)})},saveReadingPosition:(i,p,M)=>{l.layout.panelIds.get(p)===i&&m.set(i,{doc:p,position:M})},readingPositionOf:(i,p)=>{const M=m.get(i);return M===void 0||M.doc!==p?null:M.position},saveImageView:(i,p,M)=>{f.set(i,{url:p,state:M})},imageViewOf:(i,p)=>{const M=f.get(i);return M===void 0||M.url!==p?null:M.state}}},_=(e,n)=>{const t=()=>n(e.getSnapshot());return u.useSyncExternalStore(e.subscribe,t,t)},fn=e=>{const{config:n,storageNamespace:t}=q.useExplorer(),o=fe.useNavigate(),r=u.useRef(o),s=ne.storageKeys(t).multiLayout,[a]=u.useState(()=>mn({config:n,location:e,writeUrl:(l,y)=>{r.current(l,q.explorerNavigationOptions(y==="replace"?"browse":"switch-source"))},persist:l=>ne.writeStorage(s,l)}));u.useLayoutEffect(()=>{r.current=o},[o]);const m=fe.useLocation(),f=u.useMemo(()=>({location:e,navigated:m}),[e,m]);return u.useLayoutEffect(()=>{a.observeLocation(f.location)},[a,f]),u.useLayoutEffect(()=>{a.loadStored(un(ne.readStorage(s),n.multiView.columns))},[a,s,n]),a},pn=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);if(n===null)throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");return n},gn=({docPath:e,panelId:n,maximized:t,title:o,onContentShown:r})=>{const{store:s,followLink:a,revealInPanel:m}=ie(),{announcer:f}=q.useExplorer(),l=_(s,d=>$e(d,n)),y=_(s,d=>d.layout.markup.has(e)),S=u.useCallback((d,v)=>a(n,e,d,v),[a,n,e]),C=u.useCallback(()=>s.setPendingHash(n,null),[s,n]),k=u.useMemo(()=>({read:d=>s.imageViewOf(n,d),save:(d,v)=>s.saveImageView(n,d,v)}),[s,n]),c=u.useCallback((d,v)=>{v.kind!=="failure"&&s.setTitle(d,v.name),r(d)},[s,r]),g=u.useCallback(d=>{s.whenUrlRendered(()=>f.announce(d))},[s,f]),w=u.useMemo(()=>({scrollerOf:pn,reveal:d=>m(n,d)}),[m,n]),h=u.useMemo(()=>({kind:"panel",maximized:t,onDocumentLink:S,pendingHash:l,onHashConsumed:C,announceFailure:g,paneScroll:w}),[t,S,l,C,g,w]),P=u.useMemo(()=>({kind:"panel",documentName:o,maximized:t}),[o,t]),T=u.useCallback(()=>s.setMarkup(e,!s.getSnapshot().layout.markup.has(e)),[s,e]),A=u.useMemo(()=>({shown:y,toggle:T}),[y,T]);return L.jsxs(q.ImageViewMemoryContext,{value:k,children:[L.jsx(q.DocumentRefreshBar,{path:e,placement:P,markup:A}),L.jsx(q.DocumentPane,{path:e,markup:y,variant:h,onDocumentShown:c})]})},he=()=>typeof HTMLElement<"u"&&typeof HTMLElement.prototype.showPopover=="function"&&typeof HTMLElement.prototype.hidePopover=="function",ce="data-aqmx-column-probe",J="data-panel-id",se="--aqmx-multi-panel-chrome",F=e=>e.endsWith("px")?Number.parseFloat(e):Number.NaN,hn=e=>e==="normal"?0:F(e),vn=(e,n)=>{const t=e.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,o=e.querySelector(`[${ce}]`),r=o instanceof HTMLElement?o.getBoundingClientRect().width:Number.NaN;if(!(t instanceof HTMLElement))return{plan:{trackInlineSize:Number.NaN,gap:Number.NaN,minColumnInlineSize:r,logicalColumns:n},stageBlockSize:Number.NaN};const s=getComputedStyle(t),a=t.clientWidth-F(s.paddingLeft)-F(s.paddingRight),m=t.clientHeight-F(s.paddingTop)-F(s.paddingBottom);return{plan:{trackInlineSize:a,gap:hn(s.columnGap),minColumnInlineSize:r,logicalColumns:n},stageBlockSize:m}},yn=(e,n)=>{if(e.getClientRects().length===0)return Number.NaN;const t=getComputedStyle(e);return n.getBoundingClientRect().top-e.getBoundingClientRect().top+F(t.paddingBottom)+F(t.borderBottomWidth)},X="data-aqmx-panel-frame",ve="--aqmx-multi-panel-pinned-block-size",Sn=e=>{const{docPath:n,panelId:t}=e;if(typeof n!="string"||typeof t!="string")throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");return{docPath:n,panelId:t}},wn=e=>{const n=getComputedStyle(e),t=Number.parseFloat(n.lineHeight);return Number.isFinite(t)?t:Number.parseFloat(n.fontSize)},xn=(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),G=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);return n instanceof HTMLElement?n:null},Ae=e=>{const n=e.firstElementChild;return n instanceof HTMLElement&&getComputedStyle(n).position==="sticky"?n:null},De=(e,n)=>{const t=n.getBoundingClientRect().top,o=Ae(e);return o===null?t:Math.max(t,o.getBoundingClientRect().bottom)},ye=(e,n)=>{let t=0,o=e.length;for(;t<o;){const r=t+o>>>1;(e[r]?.getBoundingClientRect().bottom??Number.NEGATIVE_INFINITY)>n?o=r:t=r+1}return t<e.length?t:-1},En=(e,n)=>{const t=De(e,n),o=[];let r=e;for(let s=ye([...r.children],t);s>=0;s=ye([...r.children],t)){const a=r.children[s];if(a===void 0)break;o.push(s),r=a}return{scrollTop:n.scrollTop,anchor:o.length===0?null:{path:o,offset:r.getBoundingClientRect().top-t}}},Se=(e,n,t)=>{if(n.scrollTop=t.scrollTop,t.anchor===null)return;let o=e;for(const r of t.anchor.path)o=o?.children[r];o!==void 0&&(n.scrollTop+=o.getBoundingClientRect().top-De(e,n)-t.anchor.offset)},On=Object.freeze(["data-testid","aria-label","title","href","id","name"]),_e=e=>JSON.stringify([e.tagName,...On.map(n=>e.getAttribute(n))]),bn=(e,n)=>{if(n===null||!e.contains(n))return null;const t=[];for(let o=n;o!==e;){const r=o.parentElement;if(r===null)return null;t.unshift([...r.children].indexOf(o)),o=r}return{path:t,signature:_e(n)}},Cn=(e,n,t)=>{let o=e;for(const r of t.path)o=o?.children[r];o instanceof HTMLElement&&_e(o)===t.signature&&q.focusWithoutScroll(o)||n.focus({preventScroll:!0})},Pn=(e,n,t)=>{if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY))return;const o=e.ctrlKey||e.metaKey,r=o?G(n):n.closest(D.SCROLL_ROOT_SELECTOR);if(!(r instanceof HTMLElement))return;const s=xn(e,r,t);(o||Mn(r,s))&&(e.preventDefault(),r.scrollTop+=s)},Mn=(e,n)=>n<0?e.scrollTop>0:n>0?Math.ceil(e.scrollTop+e.clientHeight)<e.scrollHeight:!1,Ln=e=>e.scrollHeight>e.clientHeight,kn=(e,n,t)=>{let o=Number.NaN,r=Number.NaN;const s=Ae(t),a=()=>{const l=yn(e,n);if(!Number.isFinite(l))return;const y=s===null?0:s.getBoundingClientRect().height;y!==r&&(r=y,t.style.setProperty(ve,`${String(y)}px`));const S=l+y;S!==o&&(o=S,e.style.setProperty(se,`${String(S)}px`))};a();let m=null;const f=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{m===null&&(m=requestAnimationFrame(()=>{m=null,a()}))});return f?.observe(e),f?.observe(n),s!==null&&f?.observe(s),()=>{f?.disconnect(),m!==null&&cancelAnimationFrame(m),e.style.removeProperty(se),t.style.removeProperty(ve)}},Tn=e=>{const{docPath:n,panelId:t}=Sn(e),{store:o,Body:r,maximize:s,focusCarry:a}=ie(),m=_(o,c=>c.layout.maximized===n),f=_(o,c=>ae(c.titles,n)),l=u.useRef(null),y=u.useRef(null),S=u.useRef(null);u.useEffect(()=>{const c=l.current,g=c===null?null:G(c);if(c===null||g===null||m)return;const w=new Map,h=v=>{const O=w.get(v);if(O!==void 0)return O;const x=wn(v);return w.set(v,x),x},P=v=>Pn(v,c,h);let T=!1;const A=()=>{const v=Ln(g);v!==T&&(T=v,v?c.addEventListener("wheel",P,{capture:!0,passive:!1}):c.removeEventListener("wheel",P,{capture:!0}))};A();const d=typeof ResizeObserver>"u"?null:new ResizeObserver(A);return d?.observe(g),d?.observe(c),()=>{d?.disconnect(),c.removeEventListener("wheel",P,{capture:!0})}},[m]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:G(c),w=c===null?null:c.closest(`[${J}]`);if(!(c===null||g===null||!(w instanceof HTMLElement)))return kn(w,g,c)},[]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:G(c);if(c===null||g===null)return;const w=o.readingPositionOf(t,n);y.current=w===null?null:{doc:n,position:w},w!==null&&Se(c,g,w);let h=null;const P=()=>{h===null&&(h=requestAnimationFrame(()=>{h=null;const T=S.current;T!==null&&o.saveReadingPosition(t,T,En(c,g))}))};return g.addEventListener("scroll",P,{passive:!0}),()=>{g.removeEventListener("scroll",P),h!==null&&cancelAnimationFrame(h)}},[o,t,n]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:c.closest(`[${J}]`);if(c===null||g===null)return;const w=a.take(t);return w!==null&&Cn(g,c,w),()=>{const h=bn(g,g.ownerDocument.activeElement);h!==null&&a.hold(t,h)}},[a,t]);const C=u.useCallback(c=>{const g=l.current,w=g===null?null:G(g);if(g===null||w===null)return;const h=S.current;S.current=c;const P=y.current;y.current=null,P!==null&&P.doc===c?Se(g,w,P.position):h!==null&&h!==c&&(w.scrollTop=0)},[]),k=u.useCallback(()=>s(n),[s,n]);return L.jsx("div",{ref:l,role:"group","aria-label":f,className:"aqmx-multi-panel-frame",tabIndex:-1,"data-aqmx-panel-frame":t,"data-aqmx-maximized":m?"true":"false","data-testid":"markdown-explorer-panel-frame",onDoubleClick:m?void 0:k,children:L.jsx(r,{docPath:n,panelId:t,maximized:m,title:f,onContentShown:C})})},Rn=u.memo(Tn),K=(e,n)=>{const t=e.panelIds.get(n);if(t===void 0)throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);return t},we=e=>Object.fromEntries(D.generateColumnIds(e).map(n=>[n,[]])),Nn=(e,n)=>{const t=nn(ee(e,n),n.visible);return Object.fromEntries(t.map((o,r)=>[D.generateColumnId(r),o.map(s=>K(e,s))]))},In=(e,n)=>{const t=W(e);return D.sortColumnIds(Object.keys(n)).map(o=>(n[o]??[]).flatMap(r=>{const s=t.get(r);return s===void 0?[]:[s]}))},An=e=>({switchToCustomDragMode:e.panelSwitchToCustomDrag,switchToNormalDragMode:e.panelSwitchToNormalDrag,hidePanel:e.panelHide,maximizePanel:e.panelMaximize,restorePanel:e.panelRestore,closePanel:e.panelClose,movePanelToPreviousColumn:e.panelMovePreviousColumn,movePanelToNextColumn:e.panelMoveNextColumn,movePanelUp:e.panelMoveUp,movePanelDown:e.panelMoveDown,customDragModeBadge:e.panelCustomDragBadge,panelMoved:e.panelMoved,panelMoveUnavailable:e.panelMoveUnavailable,panelDragStarted:e.panelDragStarted,panelDragCancelled:e.panelDragCancelled,hiddenPanels:e.hiddenPanelsTitle,hiddenPanelBadge:e.hiddenPanelBadge,hiddenPanelNotice:e.hiddenPanelNotice,emptyColumn:e.multiColumnEmpty,dropZone:e.multiColumnRegion,dropHere:e.panelDropHere}),Dn="--aqmx-multi-stage-bar-gutter",_n=Object.freeze({[Dn]:`${String(Ve.NATIVE_SCROLL_BAR_WIDTH)}px`}),zn=Object.freeze({blockSize:"100%"}),Hn=Object.freeze({[D.NO_PANEL_DRAG_ATTRIBUTE]:"",style:Object.freeze({display:"flex"})}),qn=e=>L.jsx("div",{...Hn,children:L.jsx(q.LazyNativeScrollBar,{scroller:e,withCircle:!0})}),Bn=({props:e,children:n})=>L.jsx(Fe.HostedScrollArea,{scrollerProps:{...e,style:zn},renderScrollBar:qn,children:n}),jn=e=>L.jsx(q.LazyNativeScrollBar,{scroller:e,withCircle:!1}),ue="--aqmx-stage-block",Fn="--aqmx-multi-panel-body-floor",Vn=`calc(var(${ue}) * ${String(j.PANEL_MIN_BLOCK_RATIO)})`,Un=`max(calc(var(${ue}) * ${String(j.PANEL_MAX_BLOCK_RATIO)}), calc(var(${se}) + var(${Fn})))`,$n=(e,n)=>{const t=Object.entries(e);return t.length!==Object.keys(n).length?!1:t.every(([o,r])=>{const s=n[o];return s!==void 0&&s.length===r.length&&s.every((a,m)=>r[m]===a)})},xe=["keydown","pointerdown","wheel","touchstart"],Y=new WeakMap,Ee=(e,n,t)=>{for(let o=n;o!==null&&o!==t;o=o.parentElement){e.observe(o);for(let r=o.previousElementSibling;r!==null;r=r.previousElementSibling)e.observe(r)}},Gn=e=>{const n=new Map;for(let t=e.parentElement;t!==null;t=t.parentElement)n.set(t,{top:t.scrollTop,left:t.scrollLeft});return n},Z=(e,n,t)=>{Y.get(e)?.();const o=e.querySelector(`[${J}="${n}"]`);if(!(o instanceof HTMLElement))return;const r=t!==null&&o.contains(t)?t:null;let s=new Map;const a=()=>{if(!o.isConnected)return;o.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"});const S=r?.isConnected===!0?r:o;S!==o&&S.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"}),s=Gn(S)};if(a(),typeof ResizeObserver>"u")return;const m=new ResizeObserver(a);Ee(m,o,o.closest(D.SCROLL_ROOT_SELECTOR)),r!==null&&Ee(m,r,o);const{ownerDocument:f}=e,l=S=>{const C=S.target===f?f.scrollingElement:S.target;if(!(C instanceof Element))return;const k=s.get(C);k!==void 0&&(C.scrollTop!==k.top||C.scrollLeft!==k.left)&&y()},y=()=>{m.disconnect();for(const S of xe)f.removeEventListener(S,y,!0);f.removeEventListener("scroll",l,!0),Y.get(e)===y&&Y.delete(e)};for(const S of xe)f.addEventListener(S,y,{capture:!0,passive:!0});f.addEventListener("scroll",l,{capture:!0,passive:!0}),Y.set(e,y)},ze=(e,n)=>{const t=e.querySelector(`[${X}="${n}"]`);return t instanceof HTMLElement?(Z(e,n,null),t.focus({preventScroll:!0}),!0):!1},de=(e,n)=>{const t=e.querySelector(`[${J}="${n}"]`);return t instanceof HTMLElement&&t.contains(e.ownerDocument.activeElement)},Oe=(e,n)=>{if(!de(e,n))return null;const t=[...e.querySelectorAll(`[${X}]`)].map(a=>a.getAttribute(X)),o=t.indexOf(n),r=t[o+1];if(o>=0&&typeof r=="string")return{kind:"panel",panelId:r};const s=t[o-1];return o>0&&typeof s=="string"?{kind:"panel",panelId:s}:{kind:"stage"}},be=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&(n.kind==="panel"&&ze(t,n.panelId)||t.focus({preventScroll:!0}))})},He=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&ze(t,n)})},Yn=(e,n,t)=>{requestAnimationFrame(()=>{const o=e.current;if(o===null)return;const{activeElement:r,body:s}=o.ownerDocument;if(Z(o,n,t&&de(o,n)?r:null),!t||r!==null&&r!==s&&r.isConnected)return;const a=o.querySelector(`[${X}="${n}"]`);a instanceof HTMLElement&&a.focus({preventScroll:!0})})},Wn=({store:e,stageRef:n})=>{const{config:t,labels:o,announcer:r,edits:s}=q.useExplorer(),{maximize:a}=ie(),m=t.multiView.columns,f=_(e,E=>E.layout),l=_(e,E=>E.visibleColumns),y=_(e,E=>E.titles),S=_(e,E=>E.layout.maximized!==null||E.splitDragging),[C,k]=u.useState(!1),[c]=u.useState(()=>we(l)),g=u.useMemo(()=>An(o),[o]),w=u.useCallback(E=>{e.arrange(In(e.getSnapshot().layout,E))},[e]),h=D.useDragDropColumns({initialColumnPanels:c,initialPanelVisibility:{},debugConfig:D.DEFAULT_DEBUG_CONFIG,onColumnPanelsChange:w}),{columnPanels:P,setColumnPanels:T}=h,A=u.useRef(S),d=u.useRef(P);u.useLayoutEffect(()=>{A.current=S,d.current=P},[S,P]);const v=u.useCallback(E=>{const b=n.current;if(b===null)return;const{plan:B,stageBlockSize:z}=vn(b,m);if(Number.isFinite(z)&&z>0&&b.style.setProperty(ue,`${String(z)}px`),A.current&&!E)return;const H=j.replanVisibleColumns(e.getSnapshot().visibleColumns,B);H!==null&&e.setVisibleColumns(H)},[e,n,m]);u.useLayoutEffect(()=>{v(!0),k(!0)},[v]),u.useEffect(()=>{const E=n.current;if(E===null||typeof ResizeObserver>"u")return;let b=null;const B=new ResizeObserver(()=>{b===null&&(b=requestAnimationFrame(()=>{b=null,v(!1)}))}),z=E.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,H=E.querySelector(`[${ce}]`);return z instanceof Element&&B.observe(z),H instanceof Element&&B.observe(H),()=>{B.disconnect(),b!==null&&cancelAnimationFrame(b)}},[n,v]),u.useEffect(()=>{S||v(!1)},[S,v]);const O=u.useMemo(()=>C?Nn(f,{logical:m,visible:l}):we(l),[C,f,m,l]);u.useLayoutEffect(()=>{$n(d.current,O)||T(O)},[O,T]);const x=u.useMemo(()=>D.sortColumnIds(Object.keys(P)).map(E=>({id:E,key:E,className:"aqmx-multi-column"})),[P]),R=u.useMemo(()=>f.docs.map(E=>{const b=K(f,E);return{id:b,component:Rn,title:ae(y,E),props:{docPath:E,panelId:b},minHeight:Vn,maxHeight:Un}}),[f,y]),N=u.useMemo(()=>Object.fromEntries(f.docs.map(E=>[K(f,E),!f.hidden.has(E)])),[f]),i=f.maximized===null?null:K(f,f.maximized),p=u.useCallback(E=>{const{layout:b}=e.getSnapshot();for(const[B,z]of W(b)){const H=E[B];if(H===void 0||H!==b.hidden.has(z))continue;const V=e.titleOf(z);if(H){if(!e.setHidden(z,!1))continue;r.announce(o.panelShown(V)),He(n,B);continue}const U=n.current,me=U===null?null:Oe(U,B);e.setHidden(z,!0)&&(r.announce(o.panelHidden(V)),me!==null&&be(n,me))}},[e,n,r,o]),M=u.useCallback(E=>{const b=W(e.getSnapshot().layout).get(E);if(b===void 0)return;const B=()=>{const H=e.titleOf(b),V=n.current,U=V===null?null:Oe(V,E);e.close(b)&&(r.announce(o.panelClosed(H)),U!==null&&be(n,U))},z=s.unsavedAmong([b]);z.length===0?B():s.askToDiscard(z).then(H=>{H&&B()})},[e,n,r,o,s]),I=u.useCallback(E=>{if(E===null){a(null);return}const b=W(e.getSnapshot().layout).get(E);b!==void 0&&a(b)},[e,a]);return L.jsx("div",{className:"aqmx-multi-layout","aria-busy":!C,children:L.jsx(D.DragDropLayout,{columns:x,panels:R,columnPanels:P,onColumnPanelsChange:w,panelVisibility:N,onPanelVisibilityChange:p,dragState:h.dragState,dragOverPosition:h.dragOverPosition,originalPanelPosition:h.originalPanelPosition,dragModes:h.dragModes,debugConfig:D.DEFAULT_DEBUG_CONFIG,panelSizes:h.panelSizes,customDrag:h.customDrag,setPanelRef:h.setPanelRef,onDragStart:h.handleDragStart,onDragEnd:h.handleDragEnd,onPlaceholderDragEnter:h.handlePlaceholderDragEnter,onPlaceholderDragLeave:h.handlePlaceholderDragLeave,onDragOverWithInsert:h.handleDragOverWithInsert,onDropWithInsert:h.handleDropWithInsert,onColumnDragLeave:h.handleColumnDragLeave,onPanelMouseDown:h.handleMouseDown,onPanelSizeInfoClick:h.handlePanelSizeInfoClick,onToggleDragMode:h.toggleDragMode,onPanelClose:M,onPanelMaximizeChange:I,maximizedPanel:i,dragHandle:"header",labels:g,panelClassName:"aqmx-multi-panel",renderPanelScrollArea:Bn,renderStageScrollBar:jn})})},oe={blockStart:"--aqmx-multi-toast-block-start",inlineEnd:"--aqmx-multi-toast-inline-end",room:"--aqmx-multi-toast-room"},Kn=(e,n)=>{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];return o.some(s=>r.some(a=>{const m=n.ownerDocument.elementsFromPoint(s,a),f=m.findIndex(y=>n.contains(y)),l=m.findIndex(y=>e.contains(y));return f!==-1&&l!==-1&&l<f}))},Jn=(e,n)=>{const t=n.getBoundingClientRect(),o=n.ownerDocument.documentElement.clientWidth,r=getComputedStyle(n).direction==="rtl";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(),()=>{e.isConnected&&e.hidePopover()}},Xn=({store:e,body:n,limitNotice:t,onLimitNoticeCovered:o,ref:r})=>{const{config:s,labels:a,announcer:m,edits:f}=q.useExplorer(),l=u.useRef(null),y=u.useRef(null),S=_(e,d=>d.ready),C=_(e,d=>d.layout.docs.length>0),k=_(e,d=>d.visibleColumns),c=u.use(re.SheetNoticeSlotContext),g=u.useCallback(d=>{const{layout:v}=e.getSnapshot(),O=v.maximized,x=d===null&&O!==null?v.panelIds.get(O):void 0,R=l.current,N=x!==void 0&&R!==null&&de(R,x);e.maximize(d)&&(d!==null?m.announce(a.panelMaximized(e.titleOf(d))):O!==null&&m.announce(a.panelRestored(e.titleOf(O))),x!==void 0&&Yn(l,x,N))},[e,m,a]),w=u.useCallback((d,v,O,x)=>{if(O===v){e.setPendingHash(d,x);return}const R=f.unsavedAmong([v]);if(R.length>0){f.askToDiscard(R).then(M=>{M&&w(d,v,O,x)});return}const N=e.navigate(v,O);if(N==="navigated"){e.setPendingHash(d,x);return}if(N!=="existing")return;const{layout:i}=e.getSnapshot(),p=i.panelIds.get(O);p!==void 0&&(m.announce(a.panelAlreadyOpen(e.titleOf(O))),i.maximized===null?e.setHidden(O,!1):g(O),e.setPendingHash(p,x),He(l,p))},[e,m,a,g,f]);u.useLayoutEffect(()=>{if(t===null||c!==null||!he())return;const d=y.current,v=l.current;if(d===null||v===null)throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");return Jn(d,v)},[t,c]),u.useEffect(()=>{const d=y.current;if(t===null||d===null)return;const{ownerDocument:v}=d;let O=null;const x=R=>{const N=R.target;N instanceof Element&&(O!==null&&cancelAnimationFrame(O),O=requestAnimationFrame(()=>{O=null,v.activeElement===N&&d.isConnected&&Kn(d,N)&&o()}))};return v.addEventListener("focusin",x,!0),()=>{v.removeEventListener("focusin",x,!0),O!==null&&cancelAnimationFrame(O)}},[t,c,o]),u.useImperativeHandle(r,()=>({bringIntoView:d=>{requestAnimationFrame(()=>{const v=l.current,O=e.getSnapshot().layout.panelIds.get(d);v!==null&&O!==void 0&&Z(v,O,null)})}}),[e]),u.useEffect(()=>{const d=l.current;return()=>{d!==null&&Y.get(d)?.()}},[]);const h=u.useCallback((d,v)=>{const O=l.current;O!==null&&Z(O,d,v)},[]),[P]=u.useState(Ue),T=u.useMemo(()=>({store:e,Body:n,followLink:w,maximize:g,revealInPanel:h,focusCarry:P}),[e,n,w,g,h,P]),A=u.useMemo(()=>Array.from({length:s.multiView.columns},(d,v)=>D.generateColumnId(v)),[s]);return L.jsxs("section",{ref:l,className:"aqmx-multi-stage",style:_n,tabIndex:-1,"aria-label":a.multiRegion,"aria-busy":C&&!S,"data-testid":"markdown-explorer-stage","data-aqmx-visible-columns":k,children:[L.jsx("span",{className:"aqmx-multi-probe","aria-hidden":"true",[ce]:""}),C?S?L.jsx(Pe,{value:T,children:L.jsx(Wn,{store:e,stageRef:l})}):L.jsx("div",{className:"aqmx-multi-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-stage-skeleton",children:A.map(d=>L.jsxs("div",{className:"aqmx-skeleton aqmx-multi-skeleton-column",children:[L.jsx("span",{}),L.jsx("span",{}),L.jsx("span",{})]},d))}):L.jsx("div",{className:"aqmx-empty","data-testid":"markdown-explorer-multi-empty",children:L.jsx("p",{className:"aqmx-empty-title",children:a.multiEmpty})}),t===null?null:c!==null?je.createPortal(L.jsx("div",{ref:y,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t}),c):L.jsx("div",{ref:y,popover:he()?"manual":void 0,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t})]})},qe=3e3,Be=(e,n)=>{if(n!==null)return n;const[t]=e;return t===void 0?null:t},le=(e,n,t)=>{const o=new Set(e),r=n.filter(a=>!o.has(a)),s=r.length>0?r.at(-1):t!==null&&n.includes(t)?t:n.at(-1);return s===void 0?null:s},Zn=(e,n,t)=>{switch(n){case"opened":return e.panelOpened(t);case"shown":return e.panelShown(t);case"closed":return e.panelClosed(t);default:{const o=n;throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`)}}},Qn=({location:e})=>{const{config:n,labels:t,announcer:o}=q.useExplorer(),r=fn(e),s=_(r,x=>x.layout.docs),a=_(r,x=>x.layout.maximized),m=_(r,x=>x.layout.markup),f=_(r,x=>x.source),[l,y]=u.useState(()=>({docs:s,latest:le([],s,null)}));l.docs!==s&&y({docs:s,latest:le(l.docs,s,l.latest)});const S=a!==null?a:l.latest,[C,k]=u.useState(!1),c=u.useRef(null),[g,w]=u.useState(0),h=u.useRef(null),P=u.useRef(null);u.useLayoutEffect(()=>{const x=h.current;h.current=null,x!==null&&(r.whenUrlRendered(()=>o.announce(x.announcement)),P.current?.bringIntoView(x.doc))}),u.useEffect(()=>()=>{c.current!==null&&clearTimeout(c.current)},[]);const T=u.useCallback(()=>{c.current!==null&&clearTimeout(c.current),k(!0),c.current=setTimeout(()=>{c.current=null,k(!1)},qe)},[]),A=u.useCallback(()=>{c.current!==null&&clearTimeout(c.current),c.current=null,k(!1)},[]),d=u.useCallback(x=>{const R=r.titleOf(x),N=r.toggle(x);N==="rejected"&&T();const i=N==="rejected"?t.panelLimit(n.multiView.maxPanels):Zn(t,N,R);if(N==="shown"){h.current={doc:x,announcement:i},w(p=>p+1);return}r.whenUrlRendered(()=>{o.announce(i),N==="opened"&&P.current?.bringIntoView(x)})},[r,T,o,t,n]),v=u.useMemo(()=>new Set(s),[s]),O=u.useMemo(()=>{const x=Be(s,a);return{href:j.explorerHref(n,{view:"tree",source:f,doc:x,markup:x!==null&&m.has(x)}),target:"tree"}},[n,f,s,a,m]);return L.jsx(re.ExplorerSplit,{view:"multi",explorer:L.jsx(re.ExplorerPane,{mode:"multi",sourceId:f,currentPath:S,openPaths:v,onOpenDocument:d,onSourceChange:r.changeSource,onRevealSource:r.revealSource,viewSwitch:O}),content:L.jsx(Xn,{ref:P,store:r,body:gn,limitNotice:C?t.panelLimit(n.multiView.maxPanels):null,onLimitNoticeCovered:A}),contentCoversPage:a!==null,sheetDismissals:g,onDraggingChange:r.setSplitDragging})};exports.MultiLayout=Qn;exports.PANEL_LIMIT_NOTICE_MS=qe;exports.latestOpenedDocument=le;exports.treeSwitchDocument=Be;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),u=require("react"),j=require("./location-D6RE3wAN.cjs"),q=require("./index-afZWk187.cjs"),re=require("./ExplorerSplit-DMizcKaY.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-Dgi4JXaB.cjs"),Ce=require("./dataRoute-BONacTPi.cjs"),je=require("react-dom"),Fe=require("@aiquants/markdown"),Ve=require("./scrollBarGeometry-C46jBtmM.cjs"),Ue=()=>{const e=new Map;return{hold:(n,t)=>{e.set(n,t),queueMicrotask(()=>{e.get(n)===t&&e.delete(n)})},take:n=>{const t=e.get(n);return e.delete(n),t===void 0?null:t}}},Pe=u.createContext(null),ie=()=>{const e=u.use(Pe);if(e===null)throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");return e},$e=(e,n)=>{const t=e.pendingHashes.get(n);return t===void 0?null:t},Ge=0xcbf29ce484222325n,Ye=0x100000001b3n,We=(1n<<64n)-1n,Ke=(1n<<53n)-1n,Je=new TextEncoder,Xe=e=>{let n=Ge;for(const t of Je.encode(e))n=(n^BigInt(t))*Ye&We;return Number(n&Ke)},Q=256,Ze=e=>`aqmx-p-${Xe(e).toString(36)}`,Me=(e,n)=>{const t=Ze(e);let o=t;for(let r=2;n.has(o);r+=1)o=`${t}-${String(r)}`;return o},Qe=new Map,en=(e,n=Qe)=>{const t=new Set(e.flatMap(r=>n.get(r)??[])),o=new Map;for(const r of e){const s=n.get(r)??Me(r,t);t.add(s),o.set(r,s)}return o},Le=(e,n,t)=>{const o=e.columnOf.get(n);return o===void 0?void 0:Math.min(t-1,Math.max(0,o))},ke=(e,n)=>{const[t,...o]=j.columnGroups(n.logical,n.visible);if(t===void 0)throw new RangeError("[markdown-explorer] there must be at least one visible column");const r=([m,f])=>e.slice(m,f).reduce((l,y)=>l+y.length,0);let s=t;for(const m of o)r(m)<r(s)&&(s=m);let a=s[0];for(let m=s[0];m<s[1];m+=1)(e[m]?.length??0)<(e[a]?.length??0)&&(a=m);return a},ee=(e,n)=>{const t=Array.from({length:n.logical},()=>[]),o=[];for(const r of e.docs){const s=Le(e,r,n.logical);s===void 0?o.push(r):t[s]?.push(r)}for(const r of o)t[ke(t,n)]?.push(r);return t},nn=(e,n)=>j.columnGroups(e.length,n).map(([t,o])=>e.slice(t,o).flat()),tn=(e,n,t)=>{const[o,r]=n,s=r-o,a=e.length,m=Array.from({length:s},(c,g)=>{const w=[0];for(const h of e)w.push((w.at(-1)??0)+(t(h)===o+g?1:0));return w}),f=(c,g,w)=>(m[c]?.[w]??0)-(m[c]?.[g]??0),l=Array.from({length:s+1},()=>Array.from({length:a+1},()=>Number.NEGATIVE_INFINITY)),y=Array.from({length:s+1},()=>Array.from({length:a+1},()=>0)),S=l[0];S&&(S[0]=0);for(let c=0;c<s;c+=1)for(let g=0;g<=a;g+=1)for(let w=0;w<=g;w+=1){const h=(l[c]?.[w]??Number.NEGATIVE_INFINITY)+f(c,w,g),P=l[c+1],T=y[c+1];P&&T&&h>(P[g]??Number.NEGATIVE_INFINITY)&&(P[g]=h,T[g]=w)}const C=Array.from({length:s},()=>[]);let k=a;for(let c=s;c>0;c-=1){const g=y[c]?.[k]??0;C[c-1]=e.slice(g,k),k=g}return C},Te=(e,n)=>{const t=n.flat(),o=new Map(e.columnOf);for(const[r,s]of n.entries())for(const a of s)o.delete(a),o.set(a,r);for(const r of o.keys()){if(o.size<=Q)break;o.delete(r)}return{docs:t,columnOf:o}},on=(e,n,t,o)=>{if(e.docs.includes(n))return{state:e,outcome:"existing"};if(e.docs.length>=o)return{state:e,outcome:"rejected"};const r=ee(e,t),s=Le(e,n,t.logical)??ke(r,t);r[s]?.push(n);const a=new Map(e.panelIds);return a.set(n,Me(n,new Set(a.values()))),{state:{...e,...Te(e,r),panelIds:a},outcome:"opened"}},Re=(e,n)=>{if(!e.docs.includes(n))return e;const t=new Set(e.hidden);t.delete(n);const o=new Set(e.markup);o.delete(n);const r=new Map(e.panelIds);return r.delete(n),{...e,docs:e.docs.filter(s=>s!==n),hidden:t,markup:o,panelIds:r,maximized:e.maximized===n?null:e.maximized}},rn=(e,n,t,o)=>{if(e.hidden.has(n))return{state:Ne(e,n,!1),outcome:"shown"};if(e.docs.includes(n))return{state:Re(e,n),outcome:"closed"};const r=on(e,n,t,o);return{state:r.state,outcome:r.outcome==="rejected"?"rejected":"opened"}},sn=(e,n,t)=>{if(n===t||!e.docs.includes(n))return{state:e,outcome:"ignored"};if(e.docs.includes(t))return{state:e,outcome:"existing"};const o=new Map(e.columnOf),r=o.get(n);r!==void 0&&(o.delete(t),o.set(t,r));const s=new Set(e.hidden);s.delete(n);const a=new Map(e.panelIds),m=a.get(n);if(m===void 0)throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);a.delete(n),a.set(t,m);const f=new Set(e.markup);return f.delete(n),{state:{docs:e.docs.map(l=>l===n?t:l),maximized:e.maximized===n?t:e.maximized,columnOf:o,hidden:s,markup:f,panelIds:a},outcome:"navigated"}},Ne=(e,n,t)=>{if(!e.docs.includes(n)||e.hidden.has(n)===t)return e;const o=new Set(e.hidden);return t?o.add(n):o.delete(n),{...e,hidden:o,maximized:t&&e.maximized===n?null:e.maximized}},ln=(e,n,t)=>{if(!e.docs.includes(n)||e.markup.has(n)===t)return e;const o=new Set(e.markup);return t?o.add(n):o.delete(n),{...e,markup:o}},an=(e,n)=>{if(e.maximized===n||n!==null&&!e.docs.includes(n))return e;if(n===null||!e.hidden.has(n))return{...e,maximized:n};const t=new Set(e.hidden);return t.delete(n),{...e,maximized:n,hidden:t}},cn=(e,n,t)=>{const o=ee(e,t),r=new Map;for(const[l,y]of o.entries())for(const S of y)r.set(S,l);const s=new Set(e.docs),a=new Set,m=j.columnGroups(t.logical,t.visible),f=Array.from({length:t.logical},()=>[]);for(const[l,y]of m.entries()){const S=(n[l]??[]).filter(C=>s.has(C)&&!a.has(C));for(const C of S)a.add(C);for(const[C,k]of tn(S,y,c=>r.get(c)).entries())f[y[0]+C]?.push(...k)}for(const l of e.docs)a.has(l)||f[r.get(l)??0]?.push(l);return f.every((l,y)=>l.length===o[y]?.length&&l.every((S,C)=>o[y]?.[C]===S))?e:{...e,...Te(e,f)}},te=(e,n)=>{const t=[...new Set(e.docs)].slice(0,n),o=new Set(t),r=e.maximized!==null&&o.has(e.maximized)?e.maximized:null;return{docs:t,maximized:r,columnOf:e.stored.columnOf,hidden:new Set([...e.stored.hidden].filter(s=>o.has(s)&&s!==r)),markup:new Set(e.markup.filter(s=>o.has(s))),panelIds:en(t,e.panelIds)}},pe=(e,n)=>{if(e.docs.every(o=>e.columnOf.has(o)))return e;const t=new Map(e.columnOf);for(const[o,r]of ee(e,n).entries())for(const s of r)t.delete(s),t.set(s,o);for(const o of t.keys()){if(t.size<=Q)break;t.delete(o)}return{...e,columnOf:t}},Ie=1,$=Object.freeze({columnOf:new Map,hidden:new Set}),un=(e,n)=>{if(e===null||e==="")return $;let t;try{t=JSON.parse(e)}catch{return $}if(t===null||typeof t!="object"||Array.isArray(t))return $;const o=t;if(o.v!==Ie)return $;const r=new Map;if(Array.isArray(o.columnOf))for(const a of o.columnOf.slice(-Q))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]));const s=new Set(Array.isArray(o.hidden)?o.hidden.filter(a=>typeof a=="string"&&a!==""):[]);return{columnOf:r,hidden:s}},dn=e=>JSON.stringify({v:Ie,columnOf:[...e.columnOf.entries()].slice(-Q),hidden:e.docs.filter(n=>e.hidden.has(n))}),ae=(e,n)=>{const t=e.get(n);return t===void 0?Ce.lastPathSegment(n):t},W=e=>{const n=new Map;for(const[t,o]of e.panelIds)n.set(o,t);return n},ge=e=>{if(!Ce.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(e.slice(0,80))}`)},mn=({config:e,location:n,writeUrl:t,persist:o})=>{const{maxPanels:r,columns:s}=e.multiView,a=q.createEmitter(),m=new Map,f=new Map;let l={layout:te({docs:n.docs,maximized:n.maximized,markup:n.markup,stored:$},r),source:n.source,visibleColumns:s,ready:!1,splitDragging:!1,titles:new Map,pendingHashes:new Map},y=!1;const S=i=>y?pe(i,{logical:s,visible:l.visibleColumns}):i,C=(i,p)=>j.explorerHref(e,{view:"multi",source:i,docs:p.docs,maximized:p.maximized,markup:p.markup}),k=i=>({docs:i.docs,maximized:i.maximized,markup:[...i.markup]});let c=C(n.source,n),g=n.source,w=c;const h=[],P=[];let T=null;const A=()=>{if(!(h.length>0))for(const i of P.splice(0))i()},d=i=>{l={...l,...i},a.emit()},v=()=>{if(!l.ready)return;const i=dn(l.layout);i!==T&&(T=i,o(i))},O=(i,p,M)=>{const I=C(i,k(p));I!==c&&(c=I,g=i,h.push(I),t(I,M))},x=i=>{const p=new Set(i.panelIds.values());for(const b of[...m.keys()])p.has(b)||m.delete(b);for(const b of[...f.keys()])p.has(b)||f.delete(b);const M=new Set(i.docs),I=[...l.titles.keys()].every(b=>M.has(b))?l.titles:new Map([...l.titles].filter(([b])=>M.has(b))),E=[...l.pendingHashes.keys()].every(b=>p.has(b))?l.pendingHashes:new Map([...l.pendingHashes].filter(([b])=>p.has(b)));return{titles:I,pendingHashes:E}},R=i=>i===l.layout?!1:(d({layout:i,...x(i)}),O(g,i,"replace"),v(),!0),N=()=>({logical:s,visible:l.visibleColumns});return{getSnapshot:()=>l,subscribe:a.subscribe,toggle:i=>{ge(i);const{state:p,outcome:M}=rn(l.layout,i,N(),r);return R(p),M},close:i=>R(Re(l.layout,i)),navigate:(i,p)=>{ge(p);const{state:M,outcome:I}=sn(l.layout,i,p);if(I!=="navigated")return I;const E=M.panelIds.get(p);return E!==void 0&&(m.delete(E),f.delete(E)),R(M),I},setHidden:(i,p)=>R(Ne(l.layout,i,p)),maximize:i=>R(an(l.layout,i)),setMarkup:(i,p)=>R(ln(l.layout,i,p)),arrange:i=>R(cn(l.layout,i,{logical:s,visible:i.length})),changeSource:i=>{O(i,l.layout,"push")},revealSource:i=>{O(i,l.layout,"replace")},observeLocation:i=>{const p=C(i.source,i);if(p===c)return h.length=0,w=p,i.source!==l.source&&d({source:i.source}),A(),!1;if(p===w)return!1;w=p;const M=h.indexOf(p);if(M>=0)return h.splice(0,M+1),i.source!==l.source&&d({source:i.source}),A(),!1;h.length=0,c=p,g=i.source;const I=S(te({docs:i.docs,maximized:i.maximized,markup:i.markup,stored:{columnOf:l.layout.columnOf,hidden:l.layout.hidden},panelIds:l.layout.panelIds},r));return d({layout:I,source:i.source,...x(I)}),v(),A(),!0},whenUrlRendered:i=>{P.push(i),A()},loadStored:i=>{d({layout:S(te({docs:l.layout.docs,maximized:l.layout.maximized,markup:[...l.layout.markup],stored:i,panelIds:l.layout.panelIds},r)),ready:!0}),v()},setVisibleColumns:i=>{if(!Number.isInteger(i)||i<1||i>s)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(s)}; got ${String(i)}`);y=!0;const p=pe(l.layout,{logical:s,visible:i});i===l.visibleColumns&&p===l.layout||(d({visibleColumns:i,layout:p}),p!==l.layout&&v())},setSplitDragging:i=>{i!==l.splitDragging&&d({splitDragging:i})},setTitle:(i,p)=>{!l.layout.docs.includes(i)||l.titles.get(i)===p||d({titles:new Map(l.titles).set(i,p)})},titleOf:i=>ae(l.titles,i),setPendingHash:(i,p)=>{const M=l.pendingHashes.get(i);if(p===null||p===""){if(M===void 0)return;const I=new Map(l.pendingHashes);I.delete(i),d({pendingHashes:I});return}M!==p&&d({pendingHashes:new Map(l.pendingHashes).set(i,p)})},saveReadingPosition:(i,p,M)=>{l.layout.panelIds.get(p)===i&&m.set(i,{doc:p,position:M})},readingPositionOf:(i,p)=>{const M=m.get(i);return M===void 0||M.doc!==p?null:M.position},saveImageView:(i,p,M)=>{f.set(i,{url:p,state:M})},imageViewOf:(i,p)=>{const M=f.get(i);return M===void 0||M.url!==p?null:M.state}}},_=(e,n)=>{const t=()=>n(e.getSnapshot());return u.useSyncExternalStore(e.subscribe,t,t)},fn=e=>{const{config:n,storageNamespace:t}=q.useExplorer(),o=fe.useNavigate(),r=u.useRef(o),s=ne.storageKeys(t).multiLayout,[a]=u.useState(()=>mn({config:n,location:e,writeUrl:(l,y)=>{r.current(l,q.explorerNavigationOptions(y==="replace"?"browse":"switch-source"))},persist:l=>ne.writeStorage(s,l)}));u.useLayoutEffect(()=>{r.current=o},[o]);const m=fe.useLocation(),f=u.useMemo(()=>({location:e,navigated:m}),[e,m]);return u.useLayoutEffect(()=>{a.observeLocation(f.location)},[a,f]),u.useLayoutEffect(()=>{a.loadStored(un(ne.readStorage(s),n.multiView.columns))},[a,s,n]),a},pn=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);if(n===null)throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");return n},gn=({docPath:e,panelId:n,maximized:t,title:o,onContentShown:r})=>{const{store:s,followLink:a,revealInPanel:m}=ie(),{announcer:f}=q.useExplorer(),l=_(s,d=>$e(d,n)),y=_(s,d=>d.layout.markup.has(e)),S=u.useCallback((d,v)=>a(n,e,d,v),[a,n,e]),C=u.useCallback(()=>s.setPendingHash(n,null),[s,n]),k=u.useMemo(()=>({read:d=>s.imageViewOf(n,d),save:(d,v)=>s.saveImageView(n,d,v)}),[s,n]),c=u.useCallback((d,v)=>{v.kind!=="failure"&&s.setTitle(d,v.name),r(d)},[s,r]),g=u.useCallback(d=>{s.whenUrlRendered(()=>f.announce(d))},[s,f]),w=u.useMemo(()=>({scrollerOf:pn,reveal:d=>m(n,d)}),[m,n]),h=u.useMemo(()=>({kind:"panel",maximized:t,onDocumentLink:S,pendingHash:l,onHashConsumed:C,announceFailure:g,paneScroll:w}),[t,S,l,C,g,w]),P=u.useMemo(()=>({kind:"panel",documentName:o,maximized:t}),[o,t]),T=u.useCallback(()=>s.setMarkup(e,!s.getSnapshot().layout.markup.has(e)),[s,e]),A=u.useMemo(()=>({shown:y,toggle:T}),[y,T]);return L.jsxs(q.ImageViewMemoryContext,{value:k,children:[L.jsx(q.DocumentRefreshBar,{path:e,placement:P,markup:A}),L.jsx(q.DocumentPane,{path:e,markup:y,variant:h,onDocumentShown:c})]})},he=()=>typeof HTMLElement<"u"&&typeof HTMLElement.prototype.showPopover=="function"&&typeof HTMLElement.prototype.hidePopover=="function",ce="data-aqmx-column-probe",J="data-panel-id",se="--aqmx-multi-panel-chrome",F=e=>e.endsWith("px")?Number.parseFloat(e):Number.NaN,hn=e=>e==="normal"?0:F(e),vn=(e,n)=>{const t=e.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,o=e.querySelector(`[${ce}]`),r=o instanceof HTMLElement?o.getBoundingClientRect().width:Number.NaN;if(!(t instanceof HTMLElement))return{plan:{trackInlineSize:Number.NaN,gap:Number.NaN,minColumnInlineSize:r,logicalColumns:n},stageBlockSize:Number.NaN};const s=getComputedStyle(t),a=t.clientWidth-F(s.paddingLeft)-F(s.paddingRight),m=t.clientHeight-F(s.paddingTop)-F(s.paddingBottom);return{plan:{trackInlineSize:a,gap:hn(s.columnGap),minColumnInlineSize:r,logicalColumns:n},stageBlockSize:m}},yn=(e,n)=>{if(e.getClientRects().length===0)return Number.NaN;const t=getComputedStyle(e);return n.getBoundingClientRect().top-e.getBoundingClientRect().top+F(t.paddingBottom)+F(t.borderBottomWidth)},X="data-aqmx-panel-frame",ve="--aqmx-multi-panel-pinned-block-size",Sn=e=>{const{docPath:n,panelId:t}=e;if(typeof n!="string"||typeof t!="string")throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");return{docPath:n,panelId:t}},wn=e=>{const n=getComputedStyle(e),t=Number.parseFloat(n.lineHeight);return Number.isFinite(t)?t:Number.parseFloat(n.fontSize)},xn=(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),G=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);return n instanceof HTMLElement?n:null},Ae=e=>{const n=e.firstElementChild;return n instanceof HTMLElement&&getComputedStyle(n).position==="sticky"?n:null},De=(e,n)=>{const t=n.getBoundingClientRect().top,o=Ae(e);return o===null?t:Math.max(t,o.getBoundingClientRect().bottom)},ye=(e,n)=>{let t=0,o=e.length;for(;t<o;){const r=t+o>>>1;(e[r]?.getBoundingClientRect().bottom??Number.NEGATIVE_INFINITY)>n?o=r:t=r+1}return t<e.length?t:-1},En=(e,n)=>{const t=De(e,n),o=[];let r=e;for(let s=ye([...r.children],t);s>=0;s=ye([...r.children],t)){const a=r.children[s];if(a===void 0)break;o.push(s),r=a}return{scrollTop:n.scrollTop,anchor:o.length===0?null:{path:o,offset:r.getBoundingClientRect().top-t}}},Se=(e,n,t)=>{if(n.scrollTop=t.scrollTop,t.anchor===null)return;let o=e;for(const r of t.anchor.path)o=o?.children[r];o!==void 0&&(n.scrollTop+=o.getBoundingClientRect().top-De(e,n)-t.anchor.offset)},On=Object.freeze(["data-testid","aria-label","title","href","id","name"]),_e=e=>JSON.stringify([e.tagName,...On.map(n=>e.getAttribute(n))]),bn=(e,n)=>{if(n===null||!e.contains(n))return null;const t=[];for(let o=n;o!==e;){const r=o.parentElement;if(r===null)return null;t.unshift([...r.children].indexOf(o)),o=r}return{path:t,signature:_e(n)}},Cn=(e,n,t)=>{let o=e;for(const r of t.path)o=o?.children[r];o instanceof HTMLElement&&_e(o)===t.signature&&q.focusWithoutScroll(o)||n.focus({preventScroll:!0})},Pn=(e,n,t)=>{if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY))return;const o=e.ctrlKey||e.metaKey,r=o?G(n):n.closest(D.SCROLL_ROOT_SELECTOR);if(!(r instanceof HTMLElement))return;const s=xn(e,r,t);(o||Mn(r,s))&&(e.preventDefault(),r.scrollTop+=s)},Mn=(e,n)=>n<0?e.scrollTop>0:n>0?Math.ceil(e.scrollTop+e.clientHeight)<e.scrollHeight:!1,Ln=e=>e.scrollHeight>e.clientHeight,kn=(e,n,t)=>{let o=Number.NaN,r=Number.NaN;const s=Ae(t),a=()=>{const l=yn(e,n);if(!Number.isFinite(l))return;const y=s===null?0:s.getBoundingClientRect().height;y!==r&&(r=y,t.style.setProperty(ve,`${String(y)}px`));const S=l+y;S!==o&&(o=S,e.style.setProperty(se,`${String(S)}px`))};a();let m=null;const f=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{m===null&&(m=requestAnimationFrame(()=>{m=null,a()}))});return f?.observe(e),f?.observe(n),s!==null&&f?.observe(s),()=>{f?.disconnect(),m!==null&&cancelAnimationFrame(m),e.style.removeProperty(se),t.style.removeProperty(ve)}},Tn=e=>{const{docPath:n,panelId:t}=Sn(e),{store:o,Body:r,maximize:s,focusCarry:a}=ie(),m=_(o,c=>c.layout.maximized===n),f=_(o,c=>ae(c.titles,n)),l=u.useRef(null),y=u.useRef(null),S=u.useRef(null);u.useEffect(()=>{const c=l.current,g=c===null?null:G(c);if(c===null||g===null||m)return;const w=new Map,h=v=>{const O=w.get(v);if(O!==void 0)return O;const x=wn(v);return w.set(v,x),x},P=v=>Pn(v,c,h);let T=!1;const A=()=>{const v=Ln(g);v!==T&&(T=v,v?c.addEventListener("wheel",P,{capture:!0,passive:!1}):c.removeEventListener("wheel",P,{capture:!0}))};A();const d=typeof ResizeObserver>"u"?null:new ResizeObserver(A);return d?.observe(g),d?.observe(c),()=>{d?.disconnect(),c.removeEventListener("wheel",P,{capture:!0})}},[m]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:G(c),w=c===null?null:c.closest(`[${J}]`);if(!(c===null||g===null||!(w instanceof HTMLElement)))return kn(w,g,c)},[]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:G(c);if(c===null||g===null)return;const w=o.readingPositionOf(t,n);y.current=w===null?null:{doc:n,position:w},w!==null&&Se(c,g,w);let h=null;const P=()=>{h===null&&(h=requestAnimationFrame(()=>{h=null;const T=S.current;T!==null&&o.saveReadingPosition(t,T,En(c,g))}))};return g.addEventListener("scroll",P,{passive:!0}),()=>{g.removeEventListener("scroll",P),h!==null&&cancelAnimationFrame(h)}},[o,t,n]),u.useLayoutEffect(()=>{const c=l.current,g=c===null?null:c.closest(`[${J}]`);if(c===null||g===null)return;const w=a.take(t);return w!==null&&Cn(g,c,w),()=>{const h=bn(g,g.ownerDocument.activeElement);h!==null&&a.hold(t,h)}},[a,t]);const C=u.useCallback(c=>{const g=l.current,w=g===null?null:G(g);if(g===null||w===null)return;const h=S.current;S.current=c;const P=y.current;y.current=null,P!==null&&P.doc===c?Se(g,w,P.position):h!==null&&h!==c&&(w.scrollTop=0)},[]),k=u.useCallback(()=>s(n),[s,n]);return L.jsx("div",{ref:l,role:"group","aria-label":f,className:"aqmx-multi-panel-frame",tabIndex:-1,"data-aqmx-panel-frame":t,"data-aqmx-maximized":m?"true":"false","data-testid":"markdown-explorer-panel-frame",onDoubleClick:m?void 0:k,children:L.jsx(r,{docPath:n,panelId:t,maximized:m,title:f,onContentShown:C})})},Rn=u.memo(Tn),K=(e,n)=>{const t=e.panelIds.get(n);if(t===void 0)throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);return t},we=e=>Object.fromEntries(D.generateColumnIds(e).map(n=>[n,[]])),Nn=(e,n)=>{const t=nn(ee(e,n),n.visible);return Object.fromEntries(t.map((o,r)=>[D.generateColumnId(r),o.map(s=>K(e,s))]))},In=(e,n)=>{const t=W(e);return D.sortColumnIds(Object.keys(n)).map(o=>(n[o]??[]).flatMap(r=>{const s=t.get(r);return s===void 0?[]:[s]}))},An=e=>({switchToCustomDragMode:e.panelSwitchToCustomDrag,switchToNormalDragMode:e.panelSwitchToNormalDrag,hidePanel:e.panelHide,maximizePanel:e.panelMaximize,restorePanel:e.panelRestore,closePanel:e.panelClose,movePanelToPreviousColumn:e.panelMovePreviousColumn,movePanelToNextColumn:e.panelMoveNextColumn,movePanelUp:e.panelMoveUp,movePanelDown:e.panelMoveDown,customDragModeBadge:e.panelCustomDragBadge,panelMoved:e.panelMoved,panelMoveUnavailable:e.panelMoveUnavailable,panelDragStarted:e.panelDragStarted,panelDragCancelled:e.panelDragCancelled,hiddenPanels:e.hiddenPanelsTitle,hiddenPanelBadge:e.hiddenPanelBadge,hiddenPanelNotice:e.hiddenPanelNotice,emptyColumn:e.multiColumnEmpty,dropZone:e.multiColumnRegion,dropHere:e.panelDropHere}),Dn="--aqmx-multi-stage-bar-gutter",_n=Object.freeze({[Dn]:`${String(Ve.NATIVE_SCROLL_BAR_WIDTH)}px`}),zn=Object.freeze({blockSize:"100%"}),Hn=Object.freeze({[D.NO_PANEL_DRAG_ATTRIBUTE]:"",style:Object.freeze({display:"flex"})}),qn=e=>L.jsx("div",{...Hn,children:L.jsx(q.LazyNativeScrollBar,{scroller:e,withCircle:!0})}),Bn=({props:e,children:n})=>L.jsx(Fe.HostedScrollArea,{scrollerProps:{...e,style:zn},renderScrollBar:qn,children:n}),jn=e=>L.jsx(q.LazyNativeScrollBar,{scroller:e,withCircle:!1}),ue="--aqmx-stage-block",Fn="--aqmx-multi-panel-body-floor",Vn=`calc(var(${ue}) * ${String(j.PANEL_MIN_BLOCK_RATIO)})`,Un=`max(calc(var(${ue}) * ${String(j.PANEL_MAX_BLOCK_RATIO)}), calc(var(${se}) + var(${Fn})))`,$n=(e,n)=>{const t=Object.entries(e);return t.length!==Object.keys(n).length?!1:t.every(([o,r])=>{const s=n[o];return s!==void 0&&s.length===r.length&&s.every((a,m)=>r[m]===a)})},xe=["keydown","pointerdown","wheel","touchstart"],Y=new WeakMap,Ee=(e,n,t)=>{for(let o=n;o!==null&&o!==t;o=o.parentElement){e.observe(o);for(let r=o.previousElementSibling;r!==null;r=r.previousElementSibling)e.observe(r)}},Gn=e=>{const n=new Map;for(let t=e.parentElement;t!==null;t=t.parentElement)n.set(t,{top:t.scrollTop,left:t.scrollLeft});return n},Z=(e,n,t)=>{Y.get(e)?.();const o=e.querySelector(`[${J}="${n}"]`);if(!(o instanceof HTMLElement))return;const r=t!==null&&o.contains(t)?t:null;let s=new Map;const a=()=>{if(!o.isConnected)return;o.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"});const S=r?.isConnected===!0?r:o;S!==o&&S.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"}),s=Gn(S)};if(a(),typeof ResizeObserver>"u")return;const m=new ResizeObserver(a);Ee(m,o,o.closest(D.SCROLL_ROOT_SELECTOR)),r!==null&&Ee(m,r,o);const{ownerDocument:f}=e,l=S=>{const C=S.target===f?f.scrollingElement:S.target;if(!(C instanceof Element))return;const k=s.get(C);k!==void 0&&(C.scrollTop!==k.top||C.scrollLeft!==k.left)&&y()},y=()=>{m.disconnect();for(const S of xe)f.removeEventListener(S,y,!0);f.removeEventListener("scroll",l,!0),Y.get(e)===y&&Y.delete(e)};for(const S of xe)f.addEventListener(S,y,{capture:!0,passive:!0});f.addEventListener("scroll",l,{capture:!0,passive:!0}),Y.set(e,y)},ze=(e,n)=>{const t=e.querySelector(`[${X}="${n}"]`);return t instanceof HTMLElement?(Z(e,n,null),t.focus({preventScroll:!0}),!0):!1},de=(e,n)=>{const t=e.querySelector(`[${J}="${n}"]`);return t instanceof HTMLElement&&t.contains(e.ownerDocument.activeElement)},Oe=(e,n)=>{if(!de(e,n))return null;const t=[...e.querySelectorAll(`[${X}]`)].map(a=>a.getAttribute(X)),o=t.indexOf(n),r=t[o+1];if(o>=0&&typeof r=="string")return{kind:"panel",panelId:r};const s=t[o-1];return o>0&&typeof s=="string"?{kind:"panel",panelId:s}:{kind:"stage"}},be=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&(n.kind==="panel"&&ze(t,n.panelId)||t.focus({preventScroll:!0}))})},He=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&ze(t,n)})},Yn=(e,n,t)=>{requestAnimationFrame(()=>{const o=e.current;if(o===null)return;const{activeElement:r,body:s}=o.ownerDocument;if(Z(o,n,t&&de(o,n)?r:null),!t||r!==null&&r!==s&&r.isConnected)return;const a=o.querySelector(`[${X}="${n}"]`);a instanceof HTMLElement&&a.focus({preventScroll:!0})})},Wn=({store:e,stageRef:n})=>{const{config:t,labels:o,announcer:r,edits:s}=q.useExplorer(),{maximize:a}=ie(),m=t.multiView.columns,f=_(e,E=>E.layout),l=_(e,E=>E.visibleColumns),y=_(e,E=>E.titles),S=_(e,E=>E.layout.maximized!==null||E.splitDragging),[C,k]=u.useState(!1),[c]=u.useState(()=>we(l)),g=u.useMemo(()=>An(o),[o]),w=u.useCallback(E=>{e.arrange(In(e.getSnapshot().layout,E))},[e]),h=D.useDragDropColumns({initialColumnPanels:c,initialPanelVisibility:{},debugConfig:D.DEFAULT_DEBUG_CONFIG,onColumnPanelsChange:w}),{columnPanels:P,setColumnPanels:T}=h,A=u.useRef(S),d=u.useRef(P);u.useLayoutEffect(()=>{A.current=S,d.current=P},[S,P]);const v=u.useCallback(E=>{const b=n.current;if(b===null)return;const{plan:B,stageBlockSize:z}=vn(b,m);if(Number.isFinite(z)&&z>0&&b.style.setProperty(ue,`${String(z)}px`),A.current&&!E)return;const H=j.replanVisibleColumns(e.getSnapshot().visibleColumns,B);H!==null&&e.setVisibleColumns(H)},[e,n,m]);u.useLayoutEffect(()=>{v(!0),k(!0)},[v]),u.useEffect(()=>{const E=n.current;if(E===null||typeof ResizeObserver>"u")return;let b=null;const B=new ResizeObserver(()=>{b===null&&(b=requestAnimationFrame(()=>{b=null,v(!1)}))}),z=E.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,H=E.querySelector(`[${ce}]`);return z instanceof Element&&B.observe(z),H instanceof Element&&B.observe(H),()=>{B.disconnect(),b!==null&&cancelAnimationFrame(b)}},[n,v]),u.useEffect(()=>{S||v(!1)},[S,v]);const O=u.useMemo(()=>C?Nn(f,{logical:m,visible:l}):we(l),[C,f,m,l]);u.useLayoutEffect(()=>{$n(d.current,O)||T(O)},[O,T]);const x=u.useMemo(()=>D.sortColumnIds(Object.keys(P)).map(E=>({id:E,key:E,className:"aqmx-multi-column"})),[P]),R=u.useMemo(()=>f.docs.map(E=>{const b=K(f,E);return{id:b,component:Rn,title:ae(y,E),props:{docPath:E,panelId:b},minHeight:Vn,maxHeight:Un}}),[f,y]),N=u.useMemo(()=>Object.fromEntries(f.docs.map(E=>[K(f,E),!f.hidden.has(E)])),[f]),i=f.maximized===null?null:K(f,f.maximized),p=u.useCallback(E=>{const{layout:b}=e.getSnapshot();for(const[B,z]of W(b)){const H=E[B];if(H===void 0||H!==b.hidden.has(z))continue;const V=e.titleOf(z);if(H){if(!e.setHidden(z,!1))continue;r.announce(o.panelShown(V)),He(n,B);continue}const U=n.current,me=U===null?null:Oe(U,B);e.setHidden(z,!0)&&(r.announce(o.panelHidden(V)),me!==null&&be(n,me))}},[e,n,r,o]),M=u.useCallback(E=>{const b=W(e.getSnapshot().layout).get(E);if(b===void 0)return;const B=()=>{const H=e.titleOf(b),V=n.current,U=V===null?null:Oe(V,E);e.close(b)&&(r.announce(o.panelClosed(H)),U!==null&&be(n,U))},z=s.unsavedAmong([b]);z.length===0?B():s.askToDiscard(z).then(H=>{H&&B()})},[e,n,r,o,s]),I=u.useCallback(E=>{if(E===null){a(null);return}const b=W(e.getSnapshot().layout).get(E);b!==void 0&&a(b)},[e,a]);return L.jsx("div",{className:"aqmx-multi-layout","aria-busy":!C,children:L.jsx(D.DragDropLayout,{columns:x,panels:R,columnPanels:P,onColumnPanelsChange:w,panelVisibility:N,onPanelVisibilityChange:p,dragState:h.dragState,dragOverPosition:h.dragOverPosition,originalPanelPosition:h.originalPanelPosition,dragModes:h.dragModes,debugConfig:D.DEFAULT_DEBUG_CONFIG,panelSizes:h.panelSizes,customDrag:h.customDrag,setPanelRef:h.setPanelRef,onDragStart:h.handleDragStart,onDragEnd:h.handleDragEnd,onPlaceholderDragEnter:h.handlePlaceholderDragEnter,onPlaceholderDragLeave:h.handlePlaceholderDragLeave,onDragOverWithInsert:h.handleDragOverWithInsert,onDropWithInsert:h.handleDropWithInsert,onColumnDragLeave:h.handleColumnDragLeave,onPanelMouseDown:h.handleMouseDown,onPanelSizeInfoClick:h.handlePanelSizeInfoClick,onToggleDragMode:h.toggleDragMode,onPanelClose:M,onPanelMaximizeChange:I,maximizedPanel:i,dragHandle:"header",labels:g,panelClassName:"aqmx-multi-panel",renderPanelScrollArea:Bn,renderStageScrollBar:jn})})},oe={blockStart:"--aqmx-multi-toast-block-start",inlineEnd:"--aqmx-multi-toast-inline-end",room:"--aqmx-multi-toast-room"},Kn=(e,n)=>{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];return o.some(s=>r.some(a=>{const m=n.ownerDocument.elementsFromPoint(s,a),f=m.findIndex(y=>n.contains(y)),l=m.findIndex(y=>e.contains(y));return f!==-1&&l!==-1&&l<f}))},Jn=(e,n)=>{const t=n.getBoundingClientRect(),o=n.ownerDocument.documentElement.clientWidth,r=getComputedStyle(n).direction==="rtl";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(),()=>{e.isConnected&&e.hidePopover()}},Xn=({store:e,body:n,limitNotice:t,onLimitNoticeCovered:o,ref:r})=>{const{config:s,labels:a,announcer:m,edits:f}=q.useExplorer(),l=u.useRef(null),y=u.useRef(null),S=_(e,d=>d.ready),C=_(e,d=>d.layout.docs.length>0),k=_(e,d=>d.visibleColumns),c=u.use(re.SheetNoticeSlotContext),g=u.useCallback(d=>{const{layout:v}=e.getSnapshot(),O=v.maximized,x=d===null&&O!==null?v.panelIds.get(O):void 0,R=l.current,N=x!==void 0&&R!==null&&de(R,x);e.maximize(d)&&(d!==null?m.announce(a.panelMaximized(e.titleOf(d))):O!==null&&m.announce(a.panelRestored(e.titleOf(O))),x!==void 0&&Yn(l,x,N))},[e,m,a]),w=u.useCallback((d,v,O,x)=>{if(O===v){e.setPendingHash(d,x);return}const R=f.unsavedAmong([v]);if(R.length>0){f.askToDiscard(R).then(M=>{M&&w(d,v,O,x)});return}const N=e.navigate(v,O);if(N==="navigated"){e.setPendingHash(d,x);return}if(N!=="existing")return;const{layout:i}=e.getSnapshot(),p=i.panelIds.get(O);p!==void 0&&(m.announce(a.panelAlreadyOpen(e.titleOf(O))),i.maximized===null?e.setHidden(O,!1):g(O),e.setPendingHash(p,x),He(l,p))},[e,m,a,g,f]);u.useLayoutEffect(()=>{if(t===null||c!==null||!he())return;const d=y.current,v=l.current;if(d===null||v===null)throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");return Jn(d,v)},[t,c]),u.useEffect(()=>{const d=y.current;if(t===null||d===null)return;const{ownerDocument:v}=d;let O=null;const x=R=>{const N=R.target;N instanceof Element&&(O!==null&&cancelAnimationFrame(O),O=requestAnimationFrame(()=>{O=null,v.activeElement===N&&d.isConnected&&Kn(d,N)&&o()}))};return v.addEventListener("focusin",x,!0),()=>{v.removeEventListener("focusin",x,!0),O!==null&&cancelAnimationFrame(O)}},[t,c,o]),u.useImperativeHandle(r,()=>({bringIntoView:d=>{requestAnimationFrame(()=>{const v=l.current,O=e.getSnapshot().layout.panelIds.get(d);v!==null&&O!==void 0&&Z(v,O,null)})}}),[e]),u.useEffect(()=>{const d=l.current;return()=>{d!==null&&Y.get(d)?.()}},[]);const h=u.useCallback((d,v)=>{const O=l.current;O!==null&&Z(O,d,v)},[]),[P]=u.useState(Ue),T=u.useMemo(()=>({store:e,Body:n,followLink:w,maximize:g,revealInPanel:h,focusCarry:P}),[e,n,w,g,h,P]),A=u.useMemo(()=>Array.from({length:s.multiView.columns},(d,v)=>D.generateColumnId(v)),[s]);return L.jsxs("section",{ref:l,className:"aqmx-multi-stage",style:_n,tabIndex:-1,"aria-label":a.multiRegion,"aria-busy":C&&!S,"data-testid":"markdown-explorer-stage","data-aqmx-visible-columns":k,children:[L.jsx("span",{className:"aqmx-multi-probe","aria-hidden":"true",[ce]:""}),C?S?L.jsx(Pe,{value:T,children:L.jsx(Wn,{store:e,stageRef:l})}):L.jsx("div",{className:"aqmx-multi-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-stage-skeleton",children:A.map(d=>L.jsxs("div",{className:"aqmx-skeleton aqmx-multi-skeleton-column",children:[L.jsx("span",{}),L.jsx("span",{}),L.jsx("span",{})]},d))}):L.jsx("div",{className:"aqmx-empty","data-testid":"markdown-explorer-multi-empty",children:L.jsx("p",{className:"aqmx-empty-title",children:a.multiEmpty})}),t===null?null:c!==null?je.createPortal(L.jsx("div",{ref:y,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t}),c):L.jsx("div",{ref:y,popover:he()?"manual":void 0,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t})]})},qe=3e3,Be=(e,n)=>{if(n!==null)return n;const[t]=e;return t===void 0?null:t},le=(e,n,t)=>{const o=new Set(e),r=n.filter(a=>!o.has(a)),s=r.length>0?r.at(-1):t!==null&&n.includes(t)?t:n.at(-1);return s===void 0?null:s},Zn=(e,n,t)=>{switch(n){case"opened":return e.panelOpened(t);case"shown":return e.panelShown(t);case"closed":return e.panelClosed(t);default:{const o=n;throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`)}}},Qn=({location:e})=>{const{config:n,labels:t,announcer:o}=q.useExplorer(),r=fn(e),s=_(r,x=>x.layout.docs),a=_(r,x=>x.layout.maximized),m=_(r,x=>x.layout.markup),f=_(r,x=>x.source),[l,y]=u.useState(()=>({docs:s,latest:le([],s,null)}));l.docs!==s&&y({docs:s,latest:le(l.docs,s,l.latest)});const S=a!==null?a:l.latest,[C,k]=u.useState(!1),c=u.useRef(null),[g,w]=u.useState(0),h=u.useRef(null),P=u.useRef(null);u.useLayoutEffect(()=>{const x=h.current;h.current=null,x!==null&&(r.whenUrlRendered(()=>o.announce(x.announcement)),P.current?.bringIntoView(x.doc))}),u.useEffect(()=>()=>{c.current!==null&&clearTimeout(c.current)},[]);const T=u.useCallback(()=>{c.current!==null&&clearTimeout(c.current),k(!0),c.current=setTimeout(()=>{c.current=null,k(!1)},qe)},[]),A=u.useCallback(()=>{c.current!==null&&clearTimeout(c.current),c.current=null,k(!1)},[]),d=u.useCallback(x=>{const R=r.titleOf(x),N=r.toggle(x);N==="rejected"&&T();const i=N==="rejected"?t.panelLimit(n.multiView.maxPanels):Zn(t,N,R);if(N==="shown"){h.current={doc:x,announcement:i},w(p=>p+1);return}r.whenUrlRendered(()=>{o.announce(i),N==="opened"&&P.current?.bringIntoView(x)})},[r,T,o,t,n]),v=u.useMemo(()=>new Set(s),[s]),O=u.useMemo(()=>{const x=Be(s,a);return{href:j.explorerHref(n,{view:"tree",source:f,doc:x,markup:x!==null&&m.has(x)}),target:"tree"}},[n,f,s,a,m]);return L.jsx(re.ExplorerSplit,{view:"multi",explorer:L.jsx(re.ExplorerPane,{mode:"multi",sourceId:f,currentPath:S,openPaths:v,onOpenDocument:d,onSourceChange:r.changeSource,onRevealSource:r.revealSource,viewSwitch:O}),content:L.jsx(Xn,{ref:P,store:r,body:gn,limitNotice:C?t.panelLimit(n.multiView.maxPanels):null,onLimitNoticeCovered:A}),contentCoversPage:a!==null,sheetDismissals:g,onDraggingChange:r.setSplitDragging})};exports.MultiLayout=Qn;exports.PANEL_LIMIT_NOTICE_MS=qe;exports.latestOpenedDocument=le;exports.treeSwitchDocument=Be;
@@ -1,7 +1,7 @@
1
1
  import { jsx as a } from "react/jsx-runtime";
2
2
  import { ScrollBar as u } from "@aiquants/virtualscroll";
3
3
  import { useCallback as p, useMemo as b, useSyncExternalStore as S } from "react";
4
- import { u as h } from "./index-CjCr8czx.js";
4
+ import { u as h } from "./index-CdydPdP7.js";
5
5
  import { N as m } from "./scrollBarGeometry-DOBdGNV-.js";
6
6
  import { T, N as d } from "./tapScrollCircle-u4EXeLhx.js";
7
7
  const l = (e) => ({ scrollTop: e.scrollTop, scrollHeight: e.scrollHeight, clientHeight: e.clientHeight }), f = (e, t) => e.scrollTop === t.scrollTop && e.scrollHeight === t.scrollHeight && e.clientHeight === t.clientHeight, v = (e) => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),i=require("react"),d=require("./index-CGBl3fYT.cjs"),h=require("./scrollBarGeometry-C46jBtmM.cjs"),u=require("./tapScrollCircle-C5DGI-0H.cjs"),a=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),v=(e,t)=>e.scrollTop===t.scrollTop&&e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight,g=e=>{let t=a(e);return{getSnapshot:()=>t,subscribe:s=>{const o=()=>{const n=a(e);v(t,n)||(t=n,s())},r=typeof ResizeObserver>"u"?null:new ResizeObserver(o),c=()=>{if(r!==null){r.disconnect(),r.observe(e);for(const n of e.children)r.observe(n)}};c();const l=typeof MutationObserver>"u"?null:new MutationObserver(()=>{c(),o()});return l?.observe(e,{childList:!0}),e.addEventListener("scroll",o,{passive:!0}),o(),()=>{e.removeEventListener("scroll",o),l?.disconnect(),r?.disconnect()}}}},S=e=>{const t=i.useMemo(()=>g(e),[e]);return i.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)},p=(e,t)=>{const s=typeof t=="function"?t(e.scrollTop):t;return e.scrollTo({top:s,behavior:"instant"}),e.scrollTop},C=({scroller:e,withCircle:t})=>{const{locale:s}=d.useExplorer(),{scrollTop:o,scrollHeight:r,clientHeight:c}=S(e),l=i.useCallback(n=>p(e,n),[e]);return b.jsx(T.ScrollBar,{contentSize:r,viewportSize:c,scrollPosition:o,onScroll:l,scrollBarWidth:h.NATIVE_SCROLL_BAR_WIDTH,enableThumbDrag:!0,enableTrackClick:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,tapScrollCircleOptions:t?u.TAP_SCROLL_CIRCLE:u.NO_TAP_SCROLL_CIRCLE,locale:s})};exports.NativeScrollBar=C;exports.scrollScrollerTo=p;exports.useScrollerMetrics=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),i=require("react"),d=require("./index-afZWk187.cjs"),h=require("./scrollBarGeometry-C46jBtmM.cjs"),u=require("./tapScrollCircle-C5DGI-0H.cjs"),a=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),v=(e,t)=>e.scrollTop===t.scrollTop&&e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight,g=e=>{let t=a(e);return{getSnapshot:()=>t,subscribe:s=>{const o=()=>{const n=a(e);v(t,n)||(t=n,s())},r=typeof ResizeObserver>"u"?null:new ResizeObserver(o),c=()=>{if(r!==null){r.disconnect(),r.observe(e);for(const n of e.children)r.observe(n)}};c();const l=typeof MutationObserver>"u"?null:new MutationObserver(()=>{c(),o()});return l?.observe(e,{childList:!0}),e.addEventListener("scroll",o,{passive:!0}),o(),()=>{e.removeEventListener("scroll",o),l?.disconnect(),r?.disconnect()}}}},S=e=>{const t=i.useMemo(()=>g(e),[e]);return i.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)},p=(e,t)=>{const s=typeof t=="function"?t(e.scrollTop):t;return e.scrollTo({top:s,behavior:"instant"}),e.scrollTop},C=({scroller:e,withCircle:t})=>{const{locale:s}=d.useExplorer(),{scrollTop:o,scrollHeight:r,clientHeight:c}=S(e),l=i.useCallback(n=>p(e,n),[e]);return b.jsx(T.ScrollBar,{contentSize:r,viewportSize:c,scrollPosition:o,onScroll:l,scrollBarWidth:h.NATIVE_SCROLL_BAR_WIDTH,enableThumbDrag:!0,enableTrackClick:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,tapScrollCircleOptions:t?u.TAP_SCROLL_CIRCLE:u.NO_TAP_SCROLL_CIRCLE,locale:s})};exports.NativeScrollBar=C;exports.scrollScrollerTo=p;exports.useScrollerMetrics=S;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),s=require("react"),T=require("react-router"),a=require("./location-BUNWJ4eB.cjs"),l=require("./index-CGBl3fYT.cjs"),p=require("./ExplorerSplit-CqmbUSZ7.cjs"),q=new Set,C=({location:m})=>{const{config:r}=l.useExplorer(),t=l.useExplorerNavigate(),{hash:d}=T.useLocation(),{source:n,doc:e,overrides:c,markup:o}=m,[x,v]=s.useState(p.EMPTY_SELECTION),g=s.useMemo(()=>({gathered:x,onGatheredChange:v}),[x]),w=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:n,doc:u,overrides:c}),"browse"),[t,r,n,c]),S=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o}),"switch-source"),[t,r,e,c,o]),E=s.useCallback(u=>t(`${a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o})}${d}`,"browse"),[t,r,e,c,o,d]),k=s.useCallback(u=>{const h=a.canonicalMultiDocuments(r,u);t(a.explorerHref(r,{view:"multi",source:n,docs:h,markup:o&&e!==null&&h.includes(e)?[e]:[]}),"switch-view")},[t,r,n,e,o]),b=s.useMemo(()=>({href:a.explorerHref(r,e===null?{view:"multi",source:n}:{view:"multi",source:n,docs:[e],markup:o?[e]:[]}),target:"multi"}),[r,n,e,o]),f=s.useMemo(()=>({kind:"page",view:"tree",overrides:c,embed:{}}),[c]),P=l.usePageMarkupToggle(m);return i.jsx(p.ExplorerSplit,{view:"tree",explorer:i.jsx(p.ExplorerPane,{mode:"tree",sourceId:n,currentPath:e,openPaths:q,onOpenDocument:w,onSourceChange:S,onRevealSource:E,viewSwitch:b,tray:g,onOpenSelection:k}),content:i.jsxs("div",{className:"aqmx-document-column aqmx-tree-document",children:[e===null?null:i.jsx(l.DocumentRefreshBar,{path:e,placement:l.PAGE_DOCUMENT_REFRESH,markup:P}),i.jsx(l.DocumentPane,{path:e,markup:o,variant:f})]})})};exports.TreeLayout=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),s=require("react"),T=require("react-router"),a=require("./location-D6RE3wAN.cjs"),l=require("./index-afZWk187.cjs"),p=require("./ExplorerSplit-DMizcKaY.cjs"),q=new Set,C=({location:m})=>{const{config:r}=l.useExplorer(),t=l.useExplorerNavigate(),{hash:d}=T.useLocation(),{source:n,doc:e,overrides:c,markup:o}=m,[x,v]=s.useState(p.EMPTY_SELECTION),g=s.useMemo(()=>({gathered:x,onGatheredChange:v}),[x]),w=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:n,doc:u,overrides:c}),"browse"),[t,r,n,c]),S=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o}),"switch-source"),[t,r,e,c,o]),E=s.useCallback(u=>t(`${a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o})}${d}`,"browse"),[t,r,e,c,o,d]),k=s.useCallback(u=>{const h=a.canonicalMultiDocuments(r,u);t(a.explorerHref(r,{view:"multi",source:n,docs:h,markup:o&&e!==null&&h.includes(e)?[e]:[]}),"switch-view")},[t,r,n,e,o]),b=s.useMemo(()=>({href:a.explorerHref(r,e===null?{view:"multi",source:n}:{view:"multi",source:n,docs:[e],markup:o?[e]:[]}),target:"multi"}),[r,n,e,o]),f=s.useMemo(()=>({kind:"page",view:"tree",overrides:c,embed:{}}),[c]),P=l.usePageMarkupToggle(m);return i.jsx(p.ExplorerSplit,{view:"tree",explorer:i.jsx(p.ExplorerPane,{mode:"tree",sourceId:n,currentPath:e,openPaths:q,onOpenDocument:w,onSourceChange:S,onRevealSource:E,viewSwitch:b,tray:g,onOpenSelection:k}),content:i.jsxs("div",{className:"aqmx-document-column aqmx-tree-document",children:[e===null?null:i.jsx(l.DocumentRefreshBar,{path:e,placement:l.PAGE_DOCUMENT_REFRESH,markup:P}),i.jsx(l.DocumentPane,{path:e,markup:o,variant:f})]})})};exports.TreeLayout=C;
@@ -1,9 +1,9 @@
1
1
  import { jsx as u, jsxs as D } from "react/jsx-runtime";
2
2
  import { useState as T, useMemo as m, useCallback as i } from "react";
3
3
  import { useLocation as b } from "react-router";
4
- import { e as c, c as C } from "./location-DWd6SQhN.js";
5
- import { u as M, a as N, b as O, D as R, P as _, c as G } from "./index-CjCr8czx.js";
6
- import { E as H, a as L, b as j } from "./ExplorerSplit-BjjqNRtj.js";
4
+ import { e as c, c as C } from "./location-IRD9h42r.js";
5
+ import { u as M, a as N, b as O, D as R, P as _, c as G } from "./index-CdydPdP7.js";
6
+ import { E as H, a as L, b as j } from "./ExplorerSplit-DvcNMIjl.js";
7
7
  const q = /* @__PURE__ */ new Set(), U = ({ location: l }) => {
8
8
  const { config: o } = M(), r = N(), { hash: p } = b(), { source: n, doc: e, overrides: s, markup: t } = l, [h, v] = T(H), w = m(() => ({ gathered: h, onGatheredChange: v }), [h]), g = i((a) => r(c(o, { view: "tree", source: n, doc: a, overrides: s }), "browse"), [r, o, n, s]), S = i((a) => r(c(o, { view: "tree", source: a, doc: e, overrides: s, markup: t }), "switch-source"), [r, o, e, s, t]), E = i((a) => r(`${c(o, { view: "tree", source: a, doc: e, overrides: s, markup: t })}${p}`, "browse"), [r, o, e, s, t, p]), x = i(
9
9
  (a) => {
@@ -112,6 +112,8 @@ export type ExplorerTextDocument = {
112
112
  };
113
113
  export type ExplorerDocumentEdit = {
114
114
  readonly kind: "inline";
115
+ } | {
116
+ readonly kind: "draft";
115
117
  } | {
116
118
  readonly kind: "external";
117
119
  readonly href: string;
@@ -147,7 +149,11 @@ export type ExplorerEditSource = {
147
149
  readonly version: string;
148
150
  readonly history: boolean;
149
151
  };
150
- export type ExplorerEditAnswer = ExplorerEditSource | ExplorerGrantRequired | ExplorerFailureDocument;
152
+ export type ExplorerDraftSource = {
153
+ readonly kind: "draft";
154
+ readonly text: string;
155
+ };
156
+ export type ExplorerEditAnswer = ExplorerEditSource | ExplorerDraftSource | ExplorerGrantRequired | ExplorerFailureDocument;
151
157
  export type ExplorerSaveAnswer = {
152
158
  readonly kind: "saved";
153
159
  readonly version: string;
@@ -112,6 +112,8 @@ export type ExplorerTextDocument = {
112
112
  };
113
113
  export type ExplorerDocumentEdit = {
114
114
  readonly kind: "inline";
115
+ } | {
116
+ readonly kind: "draft";
115
117
  } | {
116
118
  readonly kind: "external";
117
119
  readonly href: string;
@@ -147,7 +149,11 @@ export type ExplorerEditSource = {
147
149
  readonly version: string;
148
150
  readonly history: boolean;
149
151
  };
150
- export type ExplorerEditAnswer = ExplorerEditSource | ExplorerGrantRequired | ExplorerFailureDocument;
152
+ export type ExplorerDraftSource = {
153
+ readonly kind: "draft";
154
+ readonly text: string;
155
+ };
156
+ export type ExplorerEditAnswer = ExplorerEditSource | ExplorerDraftSource | ExplorerGrantRequired | ExplorerFailureDocument;
151
157
  export type ExplorerSaveAnswer = {
152
158
  readonly kind: "saved";
153
159
  readonly version: string;
@@ -22,6 +22,8 @@ export type MarkdownExplorerLabels = {
22
22
  readonly editDocumentLabel: string;
23
23
  readonly editDocument: string;
24
24
  readonly editDocumentNamed: (name: string) => string;
25
+ readonly editDraftDocument: string;
26
+ readonly editDraftDocumentNamed: (name: string) => string;
25
27
  readonly editExternallyLabel: string;
26
28
  readonly editExternally: string;
27
29
  readonly editExternallyNamed: (name: string) => string;
@@ -32,9 +34,18 @@ export type MarkdownExplorerLabels = {
32
34
  readonly saveDraft: string;
33
35
  readonly saveDraftTooltip: string;
34
36
  readonly closeEditor: string;
35
- readonly previewToggle: string;
37
+ readonly editView: string;
38
+ readonly editViewNamed: (name: string) => string;
39
+ readonly editViewEditor: string;
40
+ readonly editViewEditorTooltip: string;
41
+ readonly editViewSplit: string;
42
+ readonly editViewSplitTooltip: string;
43
+ readonly editViewPreview: string;
44
+ readonly editViewPreviewTooltip: string;
36
45
  readonly historyOpen: string;
37
46
  readonly draftUnsaved: string;
47
+ readonly draftStatus: string;
48
+ readonly draftNotSaved: string;
38
49
  readonly draftSaving: string;
39
50
  readonly draftSaved: string;
40
51
  readonly draftSavedMerged: string;
@@ -55,6 +66,8 @@ export type MarkdownExplorerLabels = {
55
66
  readonly unsavedTitle: string;
56
67
  readonly unsavedBody: (names: string) => string;
57
68
  readonly unsavedDiscard: string;
69
+ readonly draftDiscardTitle: string;
70
+ readonly draftDiscardBody: (names: string) => string;
58
71
  readonly unsavedStay: string;
59
72
  readonly historyTitle: (name: string) => string;
60
73
  readonly historyLoading: string;
@@ -22,6 +22,8 @@ export type MarkdownExplorerLabels = {
22
22
  readonly editDocumentLabel: string;
23
23
  readonly editDocument: string;
24
24
  readonly editDocumentNamed: (name: string) => string;
25
+ readonly editDraftDocument: string;
26
+ readonly editDraftDocumentNamed: (name: string) => string;
25
27
  readonly editExternallyLabel: string;
26
28
  readonly editExternally: string;
27
29
  readonly editExternallyNamed: (name: string) => string;
@@ -32,9 +34,18 @@ export type MarkdownExplorerLabels = {
32
34
  readonly saveDraft: string;
33
35
  readonly saveDraftTooltip: string;
34
36
  readonly closeEditor: string;
35
- readonly previewToggle: string;
37
+ readonly editView: string;
38
+ readonly editViewNamed: (name: string) => string;
39
+ readonly editViewEditor: string;
40
+ readonly editViewEditorTooltip: string;
41
+ readonly editViewSplit: string;
42
+ readonly editViewSplitTooltip: string;
43
+ readonly editViewPreview: string;
44
+ readonly editViewPreviewTooltip: string;
36
45
  readonly historyOpen: string;
37
46
  readonly draftUnsaved: string;
47
+ readonly draftStatus: string;
48
+ readonly draftNotSaved: string;
38
49
  readonly draftSaving: string;
39
50
  readonly draftSaved: string;
40
51
  readonly draftSavedMerged: string;
@@ -55,6 +66,8 @@ export type MarkdownExplorerLabels = {
55
66
  readonly unsavedTitle: string;
56
67
  readonly unsavedBody: (names: string) => string;
57
68
  readonly unsavedDiscard: string;
69
+ readonly draftDiscardTitle: string;
70
+ readonly draftDiscardBody: (names: string) => string;
58
71
  readonly unsavedStay: string;
59
72
  readonly historyTitle: (name: string) => string;
60
73
  readonly historyLoading: string;
@@ -1 +1 @@
1
- "use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),C=/[\u0000-\u001f\u007f]/u,U=/\p{Cs}/u,H=e=>{const t=e.split("/").filter(n=>n!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!U.test(e)&&!C.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),z=/(?:%[0-9A-Fa-f]{2})+/gu,F=new TextDecoder("utf-8"),V=/[/\\]/u,M=e=>e.replace(z,t=>F.decode(Uint8Array.from(t.slice(1).split("%").map(n=>Number.parseInt(n,16))))),G=e=>{const t=[e];let n=e;for(let r=0;r<3&&n.includes("%");r+=1){const o=M(n);if(o===n)break;t.push(o),n=o}return t.map(x)},K=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},y=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(K),n=o=>o!==""&&t.some(i=>i.test(o)),r=o=>o!==""&&G(o).some(i=>n(i)||i.split(V).some(n));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},Y=y(b),W=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),J=e=>e===void 0?Y:e===!1?W:y(e),Q=(e,t)=>y(e).deniesPath(t),m=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),q=Object.freeze(["file","directory"]),B=Object.freeze(["video","audio","pdf"]),Z=Object.freeze(["info","warning","danger"]),ee=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),te=1e4,c=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),ne=Object.freeze(["http:","https:","mailto:"]),_=1024,re=/^[a-z0-9-]{1,64}$/u,oe="https://relative.invalid/",h=64,p=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>p(m,e),se=e=>p(q,e),P=e=>p(B,e),ie=e=>p(Z,e),ae=e=>p(ee,e),A=e=>typeof e=="string"&&re.test(e),le=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,oe).protocol)}catch{return!1}},f=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:n}=e;return T(t)?n!==void 0&&!A(n)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(n)}`:null:`unknown failure reason ${s(t)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:n,type:r,mimeType:o,modifiedAt:i,children:a,lazy:l}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof n!="string"||!R(n)?"an entry needs an acceptable path":se(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:l!==void 0&&typeof l!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":r==="file"&&(a!==void 0||l===!0)?"a file entry cannot have children or be lazy":l===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:n,failure:r}=e;return t==="ok"?Array.isArray(n)&&n.every(N):t==="error"&&f(r)===null},ce=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:n,failure:r}=e;return t==="ok"?n===null||D(n):t==="error"&&f(r)===null},D=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:n,ancestors:r,failure:o}=e;return t==="ok"?n===null&&r===null||typeof n=="string"&&n!==""&&D(r):t==="error"&&f(o)===null},fe=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:n}=e;return t==="ok"&&!(Number.isSafeInteger(n)&&n>=0)?!1:L(e)},g=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:n,id:r}=e;return typeof t!="string"||typeof r!="string"?"a heading needs text and id strings":typeof n!="number"||!Number.isInteger(n)||n<O.min||n>O.max?`a heading depth must be an integer in 1..6; got ${String(n)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:n}=t;if(!ae(n))return`unknown document kind ${s(n)}`;if(n==="failure")return f(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(n){case"markdown":{const{htmlContent:r,headings:o}=t;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=g(i);if(a!==null)return a}return Ee(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":c(t.url)?null:"a text document needs a root-relative url";case"image":return c(t.url)?null:"an image document needs a root-relative url";case"media":return c(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"file":return c(t.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,de=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),Ee=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:n}=e;return t==="inline"?n===void 0?null:"an inline edit carries no href":t!=="external"?`unknown edit kind ${s(t)}`:pe(n)?null:`an external edit needs an absolute https: href; got ${s(n)}`},pe=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},u=e=>typeof e=="string"&&e.length>0&&e.length<=_,Re=e=>c(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:n,size:r,author:o,kept:i,current:a}=e;return u(t)?n!==null&&(typeof n!="string"||Number.isNaN(Date.parse(n)))?`a revision's modifiedAt must be a date-time string or null; got ${s(n)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${s(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},d=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const n=e,{kind:r}=n;if(r==="failure")return f(n.failure);if(typeof r!="string"||!t.includes(r))return`unexpected answer kind ${s(r)}`;switch(r){case"grant":return Re(n);case"edit":return typeof n.text!="string"||typeof n.history!="boolean"?"an edit source needs text and history":u(n.version)?null:`an edit source needs a version; got ${s(n.version)}`;case"saved":return u(n.version)?null:`a saved answer needs a version; got ${s(n.version)}`;case"conflict":return typeof n.text!="string"?"a conflict needs the current text":u(n.version)?null:`a conflict needs the current version; got ${s(n.version)}`;case"preview":{const{htmlContent:o,headings:i}=n;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const l=g(a);if(l!==null)return l}return null}case"revisions":{if(!Array.isArray(n.revisions))return"revisions need an array";for(const o of n.revisions){const i=k(o);if(i!==null)return i}return null}case"revision":return typeof n.text!="string"?"a revision answer needs text":u(n.id)?null:`a revision answer needs an id; got ${s(n.id)}`;default:return`unexpected answer kind ${s(r)}`}},ye=Object.freeze(["edit","grant"]),me=Object.freeze(["saved","conflict","grant"]),I=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),Ae=Object.freeze(["revision"]),ge=e=>d(e,ye)===null,Oe=e=>d(e,me)===null,he=e=>d(e,I)===null,be=e=>d(e,_e)===null,xe=e=>d(e,Ae)===null,Te=e=>e!==null&&typeof e=="object"&&e.kind==="unavailable"?null:d(e,I),Pe=(e,t)=>({kind:"failure",failure:j(e,t)}),j=(e,t)=>A(t)?{reason:e,code:t}:{reason:e},Se=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),E=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Ne="asset",Le="link-card",De=(e,t,n)=>{const r=`${e}/${Ne}?${E.path}=${encodeURIComponent(t)}`;return n===null?r:`${r}&${E.version}=${encodeURIComponent(n)}`},$="text",ve=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${E.display}=${$}`},we=e=>{const t=e.getAll(E.display);return t.length===0?"file":t.length===1&&t[0]===$?"text":null},ke=e=>`${e}/${Le}`,Ie="X-Markdown-Explorer-Scope",je="X-Markdown-Explorer",$e="refresh",Xe="edit",Ce="text/markdown",Ue=e=>Se.includes(e),X=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),He=e=>{const[t,...n]=m.filter(r=>X[r]===e);return t!==void 0&&n.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=E;exports.EXPLORER_DRAFT_MEDIA_TYPE=Ce;exports.EXPLORER_EDIT_PROOF=Xe;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=m;exports.EXPLORER_FAILURE_STATUS=X;exports.EXPLORER_LINK_PROTOCOLS=ne;exports.EXPLORER_MAX_HEADINGS=te;exports.EXPLORER_PROOF_HEADER=je;exports.EXPLORER_REFRESH_PROOF=$e;exports.EXPLORER_SCOPE_HEADER=Ie;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.draftAnswerViolation=Te;exports.entryViolation=S;exports.explorerAssetHref=De;exports.explorerLinkCardEndpoint=ke;exports.explorerPlainTextHref=ve;exports.failureDocument=Pe;exports.failureOf=j;exports.failureReasonOfStatus=He;exports.failureViolation=f;exports.headingViolation=g;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=le;exports.isDeniedPath=Q;exports.isExplorerAncestorsResult=ce;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=Ue;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=ge;exports.isExplorerEditToken=u;exports.isExplorerFailureCode=A;exports.isExplorerFailureReason=T;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=ie;exports.isExplorerPreviewAnswer=he;exports.isExplorerRevealResult=ue;exports.isExplorerRevisionAnswer=xe;exports.isExplorerRevisionsAnswer=be;exports.isExplorerSaveAnswer=Oe;exports.isExplorerTextAnswer=de;exports.isExplorerTreeResult=fe;exports.isRootRelativeUrl=c;exports.lastPathSegment=H;exports.readExplorerAssetDisplay=we;exports.resolvePathRules=J;exports.revisionViolation=k;
1
+ "use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),C=/[\u0000-\u001f\u007f]/u,U=/\p{Cs}/u,H=e=>{const t=e.split("/").filter(n=>n!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!U.test(e)&&!C.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),z=/(?:%[0-9A-Fa-f]{2})+/gu,F=new TextDecoder("utf-8"),V=/[/\\]/u,M=e=>e.replace(z,t=>F.decode(Uint8Array.from(t.slice(1).split("%").map(n=>Number.parseInt(n,16))))),G=e=>{const t=[e];let n=e;for(let r=0;r<3&&n.includes("%");r+=1){const o=M(n);if(o===n)break;t.push(o),n=o}return t.map(x)},K=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},y=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(K),n=o=>o!==""&&t.some(i=>i.test(o)),r=o=>o!==""&&G(o).some(i=>n(i)||i.split(V).some(n));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},Y=y(b),W=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),J=e=>e===void 0?Y:e===!1?W:y(e),Q=(e,t)=>y(e).deniesPath(t),m=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),q=Object.freeze(["file","directory"]),B=Object.freeze(["video","audio","pdf"]),Z=Object.freeze(["info","warning","danger"]),ee=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),te=1e4,c=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),ne=Object.freeze(["http:","https:","mailto:"]),_=1024,re=/^[a-z0-9-]{1,64}$/u,oe="https://relative.invalid/",h=64,p=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>p(m,e),se=e=>p(q,e),P=e=>p(B,e),ie=e=>p(Z,e),ae=e=>p(ee,e),A=e=>typeof e=="string"&&re.test(e),le=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,oe).protocol)}catch{return!1}},f=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:n}=e;return T(t)?n!==void 0&&!A(n)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(n)}`:null:`unknown failure reason ${s(t)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:n,type:r,mimeType:o,modifiedAt:i,children:a,lazy:l}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof n!="string"||!R(n)?"an entry needs an acceptable path":se(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:l!==void 0&&typeof l!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":r==="file"&&(a!==void 0||l===!0)?"a file entry cannot have children or be lazy":l===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:n,failure:r}=e;return t==="ok"?Array.isArray(n)&&n.every(N):t==="error"&&f(r)===null},ce=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:n,failure:r}=e;return t==="ok"?n===null||D(n):t==="error"&&f(r)===null},D=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:n,ancestors:r,failure:o}=e;return t==="ok"?n===null&&r===null||typeof n=="string"&&n!==""&&D(r):t==="error"&&f(o)===null},fe=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:n}=e;return t==="ok"&&!(Number.isSafeInteger(n)&&n>=0)?!1:L(e)},g=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:n,id:r}=e;return typeof t!="string"||typeof r!="string"?"a heading needs text and id strings":typeof n!="number"||!Number.isInteger(n)||n<O.min||n>O.max?`a heading depth must be an integer in 1..6; got ${String(n)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:n}=t;if(!ae(n))return`unknown document kind ${s(n)}`;if(n==="failure")return f(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(n){case"markdown":{const{htmlContent:r,headings:o}=t;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=g(i);if(a!==null)return a}return Ee(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":c(t.url)?null:"a text document needs a root-relative url";case"image":return c(t.url)?null:"an image document needs a root-relative url";case"media":return c(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"file":return c(t.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,de=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),Ee=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:n}=e;return t==="inline"?n===void 0?null:"an inline edit carries no href":t==="draft"?n===void 0?null:"a draft edit carries no href":t!=="external"?`unknown edit kind ${s(t)}`:pe(n)?null:`an external edit needs an absolute https: href; got ${s(n)}`},pe=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},u=e=>typeof e=="string"&&e.length>0&&e.length<=_,Re=e=>c(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:n,size:r,author:o,kept:i,current:a}=e;return u(t)?n!==null&&(typeof n!="string"||Number.isNaN(Date.parse(n)))?`a revision's modifiedAt must be a date-time string or null; got ${s(n)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${s(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},d=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const n=e,{kind:r}=n;if(r==="failure")return f(n.failure);if(typeof r!="string"||!t.includes(r))return`unexpected answer kind ${s(r)}`;switch(r){case"grant":return Re(n);case"edit":return typeof n.text!="string"||typeof n.history!="boolean"?"an edit source needs text and history":u(n.version)?null:`an edit source needs a version; got ${s(n.version)}`;case"draft":return typeof n.text=="string"?null:"a draft source needs text";case"saved":return u(n.version)?null:`a saved answer needs a version; got ${s(n.version)}`;case"conflict":return typeof n.text!="string"?"a conflict needs the current text":u(n.version)?null:`a conflict needs the current version; got ${s(n.version)}`;case"preview":{const{htmlContent:o,headings:i}=n;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const l=g(a);if(l!==null)return l}return null}case"revisions":{if(!Array.isArray(n.revisions))return"revisions need an array";for(const o of n.revisions){const i=k(o);if(i!==null)return i}return null}case"revision":return typeof n.text!="string"?"a revision answer needs text":u(n.id)?null:`a revision answer needs an id; got ${s(n.id)}`;default:return`unexpected answer kind ${s(r)}`}},ye=Object.freeze(["edit","draft","grant"]),me=Object.freeze(["saved","conflict","grant"]),I=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),Ae=Object.freeze(["revision"]),ge=e=>d(e,ye)===null,Oe=e=>d(e,me)===null,he=e=>d(e,I)===null,be=e=>d(e,_e)===null,xe=e=>d(e,Ae)===null,Te=e=>e!==null&&typeof e=="object"&&e.kind==="unavailable"?null:d(e,I),Pe=(e,t)=>({kind:"failure",failure:j(e,t)}),j=(e,t)=>A(t)?{reason:e,code:t}:{reason:e},Se=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),E=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Ne="asset",Le="link-card",De=(e,t,n)=>{const r=`${e}/${Ne}?${E.path}=${encodeURIComponent(t)}`;return n===null?r:`${r}&${E.version}=${encodeURIComponent(n)}`},$="text",ve=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${E.display}=${$}`},we=e=>{const t=e.getAll(E.display);return t.length===0?"file":t.length===1&&t[0]===$?"text":null},ke=e=>`${e}/${Le}`,Ie="X-Markdown-Explorer-Scope",je="X-Markdown-Explorer",$e="refresh",Xe="edit",Ce="text/markdown",Ue=e=>Se.includes(e),X=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),He=e=>{const[t,...n]=m.filter(r=>X[r]===e);return t!==void 0&&n.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=E;exports.EXPLORER_DRAFT_MEDIA_TYPE=Ce;exports.EXPLORER_EDIT_PROOF=Xe;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=m;exports.EXPLORER_FAILURE_STATUS=X;exports.EXPLORER_LINK_PROTOCOLS=ne;exports.EXPLORER_MAX_HEADINGS=te;exports.EXPLORER_PROOF_HEADER=je;exports.EXPLORER_REFRESH_PROOF=$e;exports.EXPLORER_SCOPE_HEADER=Ie;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.draftAnswerViolation=Te;exports.entryViolation=S;exports.explorerAssetHref=De;exports.explorerLinkCardEndpoint=ke;exports.explorerPlainTextHref=ve;exports.failureDocument=Pe;exports.failureOf=j;exports.failureReasonOfStatus=He;exports.failureViolation=f;exports.headingViolation=g;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=le;exports.isDeniedPath=Q;exports.isExplorerAncestorsResult=ce;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=Ue;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=ge;exports.isExplorerEditToken=u;exports.isExplorerFailureCode=A;exports.isExplorerFailureReason=T;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=ie;exports.isExplorerPreviewAnswer=he;exports.isExplorerRevealResult=ue;exports.isExplorerRevisionAnswer=xe;exports.isExplorerRevisionsAnswer=be;exports.isExplorerSaveAnswer=Oe;exports.isExplorerTextAnswer=de;exports.isExplorerTreeResult=fe;exports.isRootRelativeUrl=c;exports.lastPathSegment=H;exports.readExplorerAssetDisplay=we;exports.resolvePathRules=J;exports.revisionViolation=k;