@aiquants/markdown-explorer 0.13.0 → 0.14.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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/dist/{EditSurface-omuATGni.cjs → EditSurface-BLlu5zEt.cjs} +1 -1
- package/dist/{EditSurface-DheIbHJi.js → EditSurface-CF2io496.js} +1 -1
- package/dist/{ExplorerSplit-DvcNMIjl.js → ExplorerSplit-BPLECNpv.js} +1 -1
- package/dist/{ExplorerSplit-DMizcKaY.cjs → ExplorerSplit-Cjvy0JHP.cjs} +1 -1
- package/dist/{MultiLayout-Cq4y1I1g.cjs → MultiLayout-BjA0k-5n.cjs} +1 -1
- package/dist/{MultiLayout-C2R85L4x.js → MultiLayout-D8F0BfxA.js} +2 -2
- package/dist/{NativeScrollBar-CKfD2qpM.js → NativeScrollBar-BFF12oEd.js} +1 -1
- package/dist/{NativeScrollBar-qvtXkNTx.cjs → NativeScrollBar-BUWXPvTV.cjs} +1 -1
- package/dist/{TreeLayout-8_V4L9s6.cjs → TreeLayout-CQUpgsxz.cjs} +1 -1
- package/dist/{TreeLayout-FCp9WPFO.js → TreeLayout-rhyVTfrI.js} +2 -2
- package/dist/core/revalidation.d.cts +1 -2
- package/dist/core/revalidation.d.ts +1 -2
- package/dist/{index-afZWk187.cjs → index-Dn7cYy-4.cjs} +6 -6
- package/dist/{index-CdydPdP7.js → index-v997iKxe.js} +343 -342
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{merge-Dm_uFthw.cjs → merge-BFk7nT59.cjs} +1 -1
- package/dist/{merge-Bb7YRgn4.js → merge-Bi2VedIr.js} +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.14.0 (2026-10-16)
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- **The peer floors of `@aiquants/markdown` and `@aiquants/virtualscroll` rise to `^6.4.1` and `^3.18.0`**, the versions this release is built and tested with (0.13.0: `^6.4.0` and `^3.17.0`). The other peers are unchanged.
|
|
8
|
+
Migration: upgrade both packages to those versions or later.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **`shouldRevalidateExplorer` is built with `@aiquants/route-revalidation`** (a new dependency), the rule every route of the host can share. It decides as before: a submission, another path under the splat, another query and a navigation that drops the hash never run the page loader, and the unchanged URL keeps React Router's decision.
|
|
13
|
+
Its type is that package's `RouteShouldRevalidate`, which takes React Router's `ShouldRevalidateFunctionArgs` as they are and the same arguments the previous type took.
|
|
14
|
+
|
|
3
15
|
## 0.13.0 (2026-10-15)
|
|
4
16
|
|
|
5
17
|
### Breaking
|
package/README.md
CHANGED
|
@@ -184,6 +184,7 @@ export const action = explorer.dataAction
|
|
|
184
184
|
- Take the content folder from configuration (an environment variable here), not from `import.meta.url`: after `react-router build` the server module runs from `build/server/index.js`, so a path relative to the module would point into `build/`.
|
|
185
185
|
- The page route needs its own `ErrorBoundary`: React Router stops carrying `headers` at the boundary that renders an error, so without one the default 403 answer loses its `Cache-Control: private, no-store`.
|
|
186
186
|
- The data route module must not have a default export; with one it becomes a UI route and the JSON answers are rendered as a page.
|
|
187
|
+
- `shouldRevalidateExplorer` keeps React Router from running the page loader again on a submission, a move to another document, view or source (another path under the splat, another query) and a navigation that drops the hash; the unchanged URL (a `revalidate()` call, a link to the current page) keeps React Router's decision. It is built with `@aiquants/route-revalidation`.
|
|
187
188
|
- The explorer adds no `main` landmark in any view (its own landmarks — the explorer `nav`, the document region, the multi view's columns — sit inside yours), so the page places it in its own `<main>`.
|
|
188
189
|
|
|
189
190
|
### 5. Load the styles
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react/jsx-runtime"),E=require("react"),y=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react/jsx-runtime"),E=require("react"),y=require("./index-Dn7cYy-4.cjs"),J=require("@codemirror/commands"),ne=require("@codemirror/lang-markdown"),fe=require("@codemirror/language"),oe=require("@codemirror/search"),U=require("@codemirror/state"),A=require("@codemirror/view"),C=require("@lezer/highlight"),ye=require("@aiquants/markdown"),Q=require("@aiquants/markdown/source-lines"),G=require("./dataRoute-BONacTPi.cjs"),Z=require("./sanitizePolicy-DrIMuYCb.cjs"),Se=require("isomorphic-dompurify"),pe={history:J.historyField},ke=fe.HighlightStyle.define([{tag:[C.tags.heading1,C.tags.heading2,C.tags.heading3,C.tags.heading4,C.tags.heading5,C.tags.heading6,C.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:C.tags.strong,fontWeight:"700"},{tag:C.tags.emphasis,fontStyle:"italic"},{tag:C.tags.strikethrough,textDecoration:"line-through"},{tag:C.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:C.tags.url,color:"var(--aqmx-syntax-url)"},{tag:C.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:C.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[C.tags.processingInstruction,C.tags.contentSeparator,C.tags.labelName,C.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Te=A.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),me="data-aqmx-conflict-actions",Le=A.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),Me=A.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),qe=A.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class Oe extends A.WidgetType{constructor(t,r){super(),this.index=t,this.labels=r}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const r=document.createElement("div");r.setAttribute(me,String(this.index));for(const[o,s]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const l=document.createElement("button");l.type="button",l.textContent=s,l.setAttribute("data-aqmx-conflict-choice",o),l.addEventListener("mousedown",a=>a.preventDefault()),l.addEventListener("click",()=>{const a=X(t.state.doc)[this.index];a!==void 0&&(he(t,a,o),t.focus())}),r.append(l)}return r}ignoreEvent(){return!0}}const X=e=>y.findConflictsInLines(e.iterLines()),ie=(e,t)=>{const r=new U.RangeSetBuilder;return X(e).forEach((o,s)=>{const l=e.line(o.start);r.add(l.from,l.from,A.Decoration.widget({widget:new Oe(s,t),block:!0,side:-1}));for(let a=o.start;a<=o.end;a+=1){const n=e.line(a).from,w=a===o.start||a===o.separator||a===o.end?Le:a<o.separator?Me:qe;r.add(n,n,w)}}),r.finish()},Ae=e=>U.StateField.define({create:t=>ie(t.doc,e),update:(t,r)=>r.docChanged?ie(r.state.doc,e):t,provide:t=>A.EditorView.decorations.from(t)}),he=(e,t,r)=>{const{doc:o}=e.state,s=(d,u)=>{const v=[];for(let m=d;m<=u;m+=1)v.push(o.line(m).text);return v},l=s(t.start+1,t.separator-1),a=s(t.separator+1,t.end-1),n=r==="ours"?l:r==="theirs"?a:[...l,...a];let w=o.line(t.start).from,f=o.line(t.end).to;n.length===0&&(t.end<o.lines?f+=1:t.start>1&&(w-=1));const i=n.join(`
|
|
2
2
|
`);e.dispatch({changes:{from:w,to:f,insert:i},selection:U.EditorSelection.cursor(w),scrollIntoView:!0,userEvent:"input.resolve"})},Ce=({parent:e,scroll:t,text:r,saved:o,labels:s,onChange:l,onGeometry:a,onSave:n})=>{const w=[A.EditorView.scrollHandler.of((d,u,v)=>(Re(d,u.head,v,t),!0)),A.lineNumbers(),A.highlightActiveLineGutter(),J.history(),A.drawSelection(),A.highlightActiveLine(),oe.highlightSelectionMatches(),A.EditorView.lineWrapping,ne.markdown({base:ne.markdownLanguage}),fe.syntaxHighlighting(ke),Ae(s),A.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(n(),!0)},...oe.searchKeymap,...J.historyKeymap,...J.defaultKeymap]),A.EditorView.contentAttributes.of({"aria-label":s.editor,"aria-multiline":"true"}),A.EditorView.updateListener.of(d=>{d.docChanged&&l(),(d.docChanged||d.heightChanged||d.geometryChanged)&&a(d.docChanged)}),Te],f=De(o,w)??U.EditorState.create({doc:r,extensions:w}),i=new A.EditorView({state:f,parent:e});return{text:()=>i.state.doc.toString(),replaceText:d=>{const u=i.state.doc.toString();if(u===d)return;let v=0;const m=Math.min(u.length,d.length);for(;v<m&&u.charCodeAt(v)===d.charCodeAt(v);)v+=1;let h=0;for(;h<m-v&&u.charCodeAt(u.length-1-h)===d.charCodeAt(d.length-1-h);)h+=1;i.dispatch({changes:{from:v,to:u.length-h,insert:d.slice(v,d.length-h)},userEvent:"input.replace"})},reveal:({line:d,column:u},v)=>{const{doc:m}=i.state,h=m.line(Math.min(Math.max(d,1),m.lines)),S=Math.min(h.from+u,h.to);i.dispatch({selection:U.EditorSelection.cursor(S),effects:se(i,S,v,t)})},showLine:d=>{const{doc:u}=i.state,v=u.line(Math.min(Math.max(d,1),u.lines)).from;i.dispatch({effects:se(i,v,null,t)})},topLine:()=>{const d=t.scrollerOf(i.scrollDOM),u=y.visibleTopOf(d,i.contentDOM),v=y.frameTopOf(d)+d.clientHeight,{documentTop:m}=i,{doc:h}=i.state;let S=i.lineBlockAtHeight(Math.max(u-m,0));for(;h.lineAt(S.from).text.trim()===""&&S.to<h.length;){const N=i.lineBlockAt(S.to+1);if(m+N.top>=v)break;S=N}const M=i.coordsAtPos(S.from),T=M===null?m+S.top:M.top;return{line:i.state.doc.lineAt(S.from).number,clientTop:T,offset:T-u}},lineSpans:d=>{const u=i.scrollDOM,v=u.scrollTop+i.documentTop-y.visibleTopOf(u,i.contentDOM),{doc:m}=i.state,h=S=>m.line(Math.min(Math.max(S,1),m.lines)).from;return d.map(({first:S,last:M})=>({top:v+i.lineBlockAt(h(S)).top,bottom:v+i.lineBlockAt(h(M)).bottom}))},scrollElement:i.scrollDOM,focus:()=>i.focus(),conflicts:()=>X(i.state.doc),resolveAtCursor:d=>{const u=X(i.state.doc),v=i.state.doc.lineAt(i.state.selection.main.head).number,m=u.find(h=>h.end>=v);return m===void 0?!1:(he(i,m,d),!0)},nextConflict:()=>{const d=X(i.state.doc);if(d[0]===void 0)return!1;const v=i.state.doc.lineAt(i.state.selection.main.head).number,m=d.findIndex(T=>T.start>v),h=m<0?0:m,S=i.state.doc.line(d[h].start).from;i.dispatch({selection:U.EditorSelection.cursor(S),effects:A.EditorView.scrollIntoView(S,{y:"center"})});const M=i.contentDOM.querySelector(`[${me}="${String(h)}"] button`);return M instanceof HTMLElement?M.focus({preventScroll:!0}):i.focus(),!0},save:()=>i.state.toJSON(pe),destroy:()=>i.destroy()}},se=(e,t,r,o)=>{const s=o.scrollerOf(e.scrollDOM),l=(r===null?y.visibleTopOf(s,e.contentDOM):r)-y.frameTopOf(s);return A.EditorView.scrollIntoView(t,{y:"start",yMargin:l})},Re=(e,t,r,o)=>{const s=Ie(e,t),l=o.scrollerOf(e.scrollDOM),a=y.frameTopOf(l),n=y.visibleTopOf(l,e.contentDOM),w=a+l.clientHeight;let f=0;switch(r.y){case"start":f=s.top-(a+r.yMargin);break;case"center":f=(s.top+s.bottom)/2-(n+w)/2;break;case"end":f=s.bottom-(w-r.yMargin);break;default:s.top<n+r.yMargin?f=s.top-(n+r.yMargin):s.bottom>w-r.yMargin&&(f=Math.min(s.bottom-(w-r.yMargin),s.top-(n+r.yMargin)))}if(f!==0&&(l.scrollTop+=f),r.y==="start")return;const i=Ne(e,t);i!==null&&o.reveal(i)},Ie=(e,t)=>{const{node:r,offset:o}=e.domAtPos(t);if(r.nodeType===Node.TEXT_NODE){const a=r.ownerDocument?.createRange();if(a!==void 0){a.setStart(r,o),a.setEnd(r,o);const[n]=a.getClientRects();if(n!==void 0&&n.height>0)return{top:n.top,bottom:n.bottom}}}const s=e.lineBlockAt(t),l=e.documentTop+s.top;return{top:l,bottom:l+s.height}},Ne=(e,t)=>{const{node:r}=e.domAtPos(t);for(let o=r instanceof Element?r:r.parentElement;o!==null;o=o.parentElement)if(o.parentElement===e.contentDOM)return o;return null},De=(e,t)=>{if(e==null)return null;try{return U.EditorState.fromJSON(e,{extensions:t},pe)}catch{return null}},_e=610,Ve=987,le=Object.freeze({kind:"unavailable"}),Pe="true",je="false",He=e=>e===Pe?!0:e===je?!1:null,Be=e=>{const t=new DOMParser().parseFromString(e,"text/html"),r=[];for(const o of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const s=o.localName==="img",l=o.getAttribute(s?"data-asset-src":"data-doc-path");l!==null&&r.push({target:{kind:s?"asset":"doc",path:l},exists:He(o.getAttribute(s?"data-asset-exists":"data-doc-exists"))})}return r},Fe=({path:e,instant:t,preview:r,initial:o,onView:s})=>{const l=new AbortController,a={asset:new Map,doc:new Map};let n=o,w=null,f=!1,i=!1,d=null,u=null,v=[],m,h=!1,S,M=null;const T=c=>{c.parsed===n.parsed&&c.failure===n.failure&&c.busy===n.busy&&c.tier===n.tier||(n=c,s(c))},N=(c,p)=>{f||(f=!0,console.error(`[markdown-explorer] ${c}`,...p===void 0?[]:[p]))},D=c=>{if(t!==null)for(const{target:p,exists:b}of t.marksOf(c))a[p.kind].set(p.path,b)},_=()=>{clearTimeout(S),S=void 0,M?.abort(),M=null},V=()=>{u=null,v=[],clearTimeout(m),m=void 0},P=(c,p)=>{T({parsed:n.parsed,failure:c,busy:!1,tier:p})},x=()=>{clearTimeout(m),m=v.length===0?void 0:setTimeout(L,Ve)},k=()=>{if(t===null||u===null)return;const c=u,p=[],b={asset:new Set,doc:new Set};let q;try{q=t.sanitize(c.html,R=>{const W=a[R.kind].get(R.path);return W===void 0&&!b[R.kind].has(R.path)&&(b[R.kind].add(R.path),p.push(R)),W??void 0})}catch(R){V(),R instanceof Z.HtmlNestingLimitError?P(G.failureOf("too-large"),"instant"):(N("the draft sanitizer failed",R),P(G.failureOf("failed"),"instant"));return}v=p;const B=n.parsed!==null&&n.parsed.htmlContent===q&&n.parsed.headings===c.headings?n.parsed:{htmlContent:q,headings:c.headings};T({parsed:B,failure:null,busy:!1,tier:"instant"}),x()},L=()=>{if(m=void 0,h||u===null||v.length===0)return;h=!0;const c=v;r(e,u.text,l.signal).then(p=>{if(h=!1,!(l.signal.aborted||!("kind"in p))){p.kind==="preview"&&D(p.htmlContent);for(const b of c)a[b.kind].has(b.path)||a[b.kind].set(b.path,null);k()}})},j=c=>{_(),V(),T({...n,busy:!0,tier:"server"});const p=new AbortController;M=p,S=setTimeout(()=>{S=void 0,r(e,c,p.signal).then(b=>{if(!(p.signal.aborted||!("kind"in b))){if(M=null,b.kind==="failure"){P(b.failure,"server");return}D(b.htmlContent),T({parsed:{htmlContent:b.htmlContent,headings:b.headings},failure:null,busy:!1,tier:"server"})}})},_e)},g=async(c,p)=>{let b;try{b=await c.convert({path:e,text:p},l.signal)}catch(B){return l.signal.aborted||N("the draft converter rejected a conversion, which its contract allows only once the signal aborted",B),le}const q=G.draftAnswerViolation(b);return q===null?b:(N(`the draft converter answered outside its contract: ${q}`),le)},H=(c,p)=>{switch(p.kind){case"preview":if(_(),p.headings.length>G.EXPLORER_MAX_HEADINGS){V(),P(G.failureOf("too-large"),"instant");return}u={text:c,html:p.htmlContent,headings:p.headings.map(({text:b,depth:q,id:B})=>({text:b,depth:q,id:B}))},k();return;case"failure":_(),V(),P(G.failureOf(p.failure.reason,p.failure.code),"instant");return;case"unavailable":j(c);return}},F=async c=>{i=!0;try{for(;d!==null&&!l.signal.aborted;){const p=d;d=null;const b=await g(c,p);if(l.signal.aborted)return;H(p,b)}}finally{i=!1}};return t!==null&&t.seed!==null&&D(t.seed),{update:c=>{if(!(l.signal.aborted||c===w)){if(w=c,clearTimeout(m),m=void 0,t===null){j(c);return}d=c,i||F(t.converter)}},dispose:()=>{l.abort(),d=null,clearTimeout(m),m=void 0,_()}}},ze=(e,t)=>Z.createHtmlSanitizer(Se(window),e,t,Z.MAX_HTML_NESTING_DEPTH),Ke=(e,t)=>e.flatMap((r,o)=>{const s=t[o];return s===void 0?[]:[{editor:s.top,preview:r.top},{editor:s.bottom,preview:r.bottom}]}),K=(e,t)=>{const r=e[t];if(r===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return r},Ue=e=>{const t=[];for(const o of e){let s=0,l=t.length;for(;s<l;){const a=s+l>>1;K(t,a).pair.preview<=o.preview?s=a+1:l=a}t[s]={pair:o,before:s===0?void 0:K(t,s-1)}}const r=[];for(let o=t.at(-1);o!==void 0;o=o.before)r.push(o.pair);return r.reverse()},We=(e,t)=>{const r=Math.max(t.editorMax,0),o=Math.max(t.previewMax,0),s=r-t.editorViewport,l=o-t.previewViewport,a=e.filter(f=>f.editor>0&&f.editor<s&&f.preview>0&&f.preview<l).sort((f,i)=>f.editor-i.editor||f.preview-i.preview);let n={editor:0,preview:0};const w=[n];for(const f of Ue(a))f.editor>n.editor&&f.preview>n.preview&&(w.push(f),n=f);return w.push({editor:r,preview:o}),{toPreview:f=>ce(w,"editor","preview",f),toEditor:f=>ce(w,"preview","editor",f)}},ce=(e,t,r,o)=>{const s=K(e,0),l=K(e,e.length-1);if(Number.isNaN(o)||o<=s[t])return s[r];if(o>=l[t])return l[r];let a=0,n=e.length-1;for(;n-a>1;){const i=a+n>>1;K(e,i)[t]<=o?a=i:n=i}const w=K(e,a),f=K(e,n);return w[r]+(f[r]-w[r])*(o-w[t])/(f[t]-w[t])},Ge=610,ae=89,ue=.5,$e=({editor:e,preview:t,previewBlocks:r,editorSpans:o,requestFrame:s,cancelFrame:l,now:a})=>{let n="editor",w=0,f=null,i=null,d=!1,u=null,v=null;const m={editor:0,preview:0},h={editor:null,preview:null};let S=null,M=()=>{};const T=g=>{f!==null&&g!==f||(n=g,w=a()+Ge)},N=(g,H)=>{g!==n&&f===null&&a()>=w&&!D(g,H)&&(n=g),k()},D=(g,H)=>{const F=h[g];return a()<m[g]||F!==null&&Math.abs(H.position()-F)<ue},_=e.onScroll(()=>N("editor",e)),V=e.onIntent(()=>T("editor")),P=()=>{const g=t();return g!==S&&(M(),S=g,M=g===null?()=>{}:x(g)),g},x=g=>{const H=g.onScroll(()=>N("preview",g)),F=g.onIntent(()=>T("preview"));return()=>{H(),F()}},k=()=>{!d&&i===null&&(i=s(L))},L=()=>{i=null;const g=P();g!==null&&(u??=r(),v??=We(Ke(u,o(u)),{editorMax:e.max(),previewMax:g.max(),editorViewport:e.viewport(),previewViewport:g.viewport()}),n==="editor"?j(g,"preview",v.toPreview(e.position())):j(e,"editor",v.toEditor(g.position())))},j=(g,H,F)=>{if(Math.abs(g.position()-F)<ue){h[H]=g.position();return}m[H]=a()+ae,h[H]=g.scrollTo(F)};return k(),{editorChanged:g=>{v=null,g&&T("editor"),k()},previewChanged:()=>{u=null,v=null,m.preview=a()+ae,k()},showAlone:g=>{f=g,!(g===null||g===n)&&(n=g,w=0,k())},dispose:()=>{d=!0,i!==null&&l(i),i=null,_(),V(),M()}}},de=Object.freeze(["wheel","pointerdown","keydown","focusin"]),ve=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const r of de)e.addEventListener(r,t,{capture:!0,passive:!0});return()=>{for(const r of de)e.removeEventListener(r,t,{capture:!0})}}}),$="[data-aqmd-scroll-container]",Xe="[data-aqmd-content]",Ye=`[${Q.SOURCE_LINES_ATTRIBUTE}]`,Je=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),ge=(e,t)=>{const r=y.loadedOf(e.peek(t));return r!==null&&r.document.kind==="markdown"?{htmlContent:r.document.htmlContent,headings:r.document.headings}:null},Qe=(e,t,r,o,s)=>{if(r===void 0)return null;let l;try{l=ze(e,t)}catch(a){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",a),null}return{converter:r,sanitize:l,marksOf:Be,seed:ge(o,s)?.htmlContent??null}},Ze=e=>{const t=[];let r=null;for(const o of e.querySelectorAll(Ye)){const s=Q.parseSourceLines(o.getAttribute(Q.SOURCE_LINES_ATTRIBUTE));if(s===null||o.getClientRects().length===0)continue;r??=e.scrollTop-y.visibleTopOf(e,o);const{top:l,bottom:a}=o.getBoundingClientRect();t.push({first:s.first,last:s.last,top:r+l,bottom:r+a})}return t},et=({path:e,readDraft:t,viewer:r,concealed:o,onEditAt:s,onLayout:l,handleRef:a})=>{const{config:n,data:w,documents:f,draftConverter:i,labels:d}=y.useExplorer(),[u,v]=E.useState(()=>({parsed:ge(f,e),failure:null,busy:!0,tier:i===void 0?"server":"instant"})),m=E.useRef(null),h=E.useRef(null),S=E.useRef(u);E.useLayoutEffect(()=>{S.current=u});const M=E.useEffectEvent(()=>t());E.useEffect(()=>{const x=Qe(n.iframeHosts,n.dataPath,i,f,e),k=Fe({path:e,instant:x,preview:w.preview,initial:S.current,onView:L=>E.startTransition(()=>v(L))});return h.current=k,k.update(M()),()=>{k.dispose(),h.current=null}},[n,w,f,i,e]);const T=E.useEffectEvent(()=>l());E.useLayoutEffect(()=>{u.parsed!==null&&T()},[u.parsed]);const N=u.parsed!==null;E.useLayoutEffect(()=>{const x=N?m.current?.querySelector($):null;if(!(x instanceof HTMLElement))return;x.tabIndex=0;const k=new ResizeObserver(()=>T());k.observe(x);const L=x.querySelector(Xe);return L!==null&&k.observe(L),()=>k.disconnect()},[N]);const D=E.useRef(null);E.useImperativeHandle(a,()=>({draft:x=>{h.current?.update(x)},scrollPort:()=>{const x=m.current?.querySelector($);return x instanceof HTMLElement?(D.current?.scroller!==x&&(D.current={scroller:x,port:ve(x)}),D.current.port):null},blocks:()=>{const x=m.current?.querySelector($);return x instanceof HTMLElement?Ze(x):[]},focus:()=>{const x=m.current?.querySelector($);x instanceof HTMLElement&&x.focus({preventScroll:!0})},anchor:x=>{const k=m.current,L=k?.querySelector($);return k===null||!(L instanceof HTMLElement)?null:y.anchorOfView(k,x(L))},place:({line:x,clientTop:k},L)=>{const j=m.current,g=j===null?null:y.blockAtLine(j,x);g!==null&&(L(g).scrollTop+=y.lineTopIn(g,x)-k)}}),[]);const _=x=>{const k=m.current,{target:L}=x;if(s===void 0||k===null||!(L instanceof Element)||!y.isEditingDoubleClick(L))return;const j=y.anchorOfDoubleClick(L,k,k.ownerDocument.getSelection());j!==null&&s(j)},V=E.useMemo(()=>({...r,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0}),[r]),P=E.useMemo(()=>u.parsed===null?null:O.jsx("div",{className:"aqmx-document-viewer",children:O.jsx(ye.MarkdownViewer,{...V,parseResult:u.parsed,content:null})}),[V,u.parsed]);return O.jsxs("section",{ref:m,className:"aqmx-edit-preview","aria-label":d.previewRegion,"aria-busy":u.busy,inert:o!==null,hidden:o==="removed","data-aqmx-preview-tier":u.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:s===void 0?void 0:_,children:[u.failure===null?null:O.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:d.previewFailed(y.failureTitleOf(d,u.failure.reason))}),P??(u.failure===null?O.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:Je.map(x=>O.jsx("span",{},x))}):null),u.busy?O.jsx("p",{className:"aqmx-sr-only",children:d.previewUpdating}):null]})},we=144,tt=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),rt=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:r}=e;return"state"in e&&typeof t=="number"&&typeof r=="number"},nt=e=>{e.stopPropagation()},ot=e=>{const{path:t,name:r,session:o}=e,{edits:s,labels:l,announcer:a}=y.useExplorer(),{phase:n}=o,w=E.useCallback(()=>s.retry(t),[s,t]);switch(E.useEffect(()=>{n.kind==="failed"&&a.announce(l.documentFailed(r,y.failureTitleOf(l,n.failure.reason)))},[n,a,l,r]),n.kind){case"opening":return O.jsxs(O.Fragment,{children:[O.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:tt.map(f=>O.jsx("span",{},f))}),O.jsx("p",{className:"aqmx-sr-only",children:l.editLoading})]});case"grant":return O.jsx("div",{className:"aqmx-edit-message",children:O.jsx(y.EditGrantNotice,{href:n.href,onRetry:w,testId:"markdown-explorer-edit-grant"})});case"failed":return O.jsx("div",{className:"aqmx-edit-message",children:O.jsx(y.FailureView,{failure:n.failure,alert:!1,onRetry:w,testId:"markdown-explorer-edit-failure"})});case"editing":return O.jsx(it,{...e})}},it=({path:e,name:t,session:r,layout:o,viewer:s,region:l,paneScroll:a})=>{const{edits:n,labels:w}=y.useExplorer(),f=E.useRef(null),i=E.useRef(null),d=E.useRef(null),u=E.useRef(null),v=o==="fill",m=y.useSideBySide(),h=y.editViewOf(r,m,v),S=h!=="editor"||r.previewPrepared,M=S&&v,T=E.useRef({layout:o,region:l,paneScroll:a});E.useLayoutEffect(()=>{T.current={layout:o,region:l,paneScroll:a}});const N=E.useRef(r.generation);E.useLayoutEffect(()=>{N.current=r.generation});const D=E.useRef({view:h,previewMounted:S});E.useLayoutEffect(()=>{D.current={view:h,previewMounted:S}});const _=E.useRef(null),V=E.useRef(null),P=E.useRef(!1),x=E.useMemo(()=>({editor:w.editorLabel(t),useOurs:w.conflictUseOurs,useTheirs:w.conflictUseTheirs,keepBoth:w.conflictKeepBoth}),[w,t]),k=E.useCallback(c=>{const{region:p,paneScroll:b}=T.current,q=p();return q===null?c:b.scrollerOf(q,c)},[]);E.useLayoutEffect(()=>{const c=f.current,p=n.draft(e);if(c===null||p===null)return;const b=n.editorState.get(e),q=rt(b)&&b.generation===N.current?b:null;let B=null,R=null;const W=()=>{B!==null&&clearTimeout(B),B=null,R!==null&&n.setDraft(e,R.text())},z=Ce({parent:c,scroll:{scrollerOf:I=>{const{layout:Y,region:be,paneScroll:xe}=T.current,re=be();return Y==="fill"||re===null?I:xe.scrollerOf(re,I)},reveal:I=>T.current.paneScroll.reveal(I)},text:p,saved:q===null?void 0:q.state,labels:x,onGeometry:I=>u.current?.editorChanged(I),onChange:()=>{B??=setTimeout(W,we),D.current.previewMounted&&R!==null&&d.current?.draft(R.text())},onSave:()=>{n.save(e)}});R=z,i.current=z;const ee=()=>{const I=z.topLine();return{line:I.line,clientTop:I.clientTop}},te=()=>d.current?.anchor(k)??null,Ee=n.bindEditor(e,{flush:W,adopt:I=>z.replaceText(I),returnPoint:()=>{const I=D.current.view==="preview"&&T.current.layout==="content"?te():null;return I===null?ee():{line:I.lines.first,clientTop:I.clientTop}},nextConflict:()=>D.current.view!=="preview"?z.nextConflict():z.conflicts().length===0?!1:(P.current=!0,n.setView(e,"editor"),!0),beforeView:I=>{if(T.current.layout==="fill")return;if(I==="preview"){_.current={to:"preview",point:ee()};return}const Y=te();_.current=Y===null?null:{to:"editor",anchor:Y}}});return q!==null&&z.showLine(q.topLine),()=>{W(),n.editorState.set(e,{state:z.save(),generation:N.current,topLine:z.topLine().line}),Ee(),z.destroy(),R=null,i.current=null}},[n,e,x,k]);const{request:L}=r;E.useLayoutEffect(()=>{const c=i.current,p=n.draft(e);c===null||p===null||L===null||(L.anchor!==null&&c.reveal(y.positionInSource(p,L.anchor),L.anchor.clientTop),c.focus(),n.consumeRequest(e))},[n,e,L,x]),E.useLayoutEffect(()=>{h!=="editor"&&!r.previewPrepared&&n.preparePreview(e)},[n,e,h,r.previewPrepared]),E.useLayoutEffect(()=>{const c=_.current,p=V.current,b=P.current;_.current=null,V.current=null,P.current=!1;const q=i.current;if(c?.to==="preview")d.current?.place(c.point,k);else if(c?.to==="editor"&&q!==null){const B=n.draft(e);B!==null&&q.reveal(y.positionInSource(B,c.anchor),c.anchor.clientTop)}b?q?.nextConflict():p==="editor"?q?.focus():p==="preview"&&d.current?.focus()},[n,e,h,k]);const j=E.useCallback(()=>{const c=i.current;if(c===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return c.text()},[]);E.useLayoutEffect(()=>{const c=i.current;if(!M||c===null)return;const p=$e({editor:ve(c.scrollElement),preview:()=>d.current?.scrollPort()??null,previewBlocks:()=>d.current?.blocks()??[],editorSpans:b=>c.lineSpans(b),requestFrame:b=>requestAnimationFrame(b),cancelFrame:b=>cancelAnimationFrame(b),now:()=>performance.now()});return p.showAlone(y.paneShownAlone(D.current.view)),u.current=p,()=>{p.dispose(),u.current=null}},[M,n,e,x]),E.useLayoutEffect(()=>{u.current?.showAlone(y.paneShownAlone(h))},[h]);const g=E.useCallback(()=>u.current?.previewChanged(),[]),H=E.useCallback(c=>n.start(e,c),[n,e]),F=c=>{if(c.key==="Escape"){y.consumeKey(c);return}if(!y.isEditViewShortcut(c.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(c);const p=y.toggledEditView(h);V.current=p,y.chooseEditView(n,e,p,v)};return O.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":o,"data-aqmx-edit-view":h,"data-testid":"markdown-explorer-edit",onKeyDown:F,onDoubleClick:nt,children:[O.jsx("div",{ref:f,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:h==="preview",hidden:h==="preview"&&!v,...y.ALLOW_KEY_REPEAT}),S?O.jsx(et,{path:e,readDraft:j,viewer:s,concealed:h!=="editor"?null:v?"overlay":"removed",onEditAt:h==="preview"?H:void 0,onLayout:g,handleRef:d}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=we;exports.default=ot;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as O, jsxs as te, Fragment as qe } from "react/jsx-runtime";
|
|
2
2
|
import { useState as Oe, useRef as N, useLayoutEffect as B, useEffectEvent as se, useEffect as we, useImperativeHandle as Ie, useMemo as Z, startTransition as Ne, useCallback as U } from "react";
|
|
3
|
-
import { v as X, f as re, g as Re, u as ne, h as De, l as _e, i as Pe, j as be, k as Ve, m as He, n as Be, F as Fe, E as ze, o as Ke, p as Ge, q as ce, r as ae, A as We, s as ue, t as je, w as Ue, x as $e, y as Xe } from "./index-
|
|
3
|
+
import { v as X, f as re, g as Re, u as ne, h as De, l as _e, i as Pe, j as be, k as Ve, m as He, n as Be, F as Fe, E as ze, o as Ke, p as Ge, q as ce, r as ae, A as We, s as ue, t as je, w as Ue, x as $e, y as Xe } from "./index-v997iKxe.js";
|
|
4
4
|
import { history as Ye, historyKeymap as Je, defaultKeymap as Qe, historyField as Ze } from "@codemirror/commands";
|
|
5
5
|
import { markdown as et, markdownLanguage as tt } from "@codemirror/lang-markdown";
|
|
6
6
|
import { syntaxHighlighting as rt, HighlightStyle as nt } from "@codemirror/language";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as m, jsxs as O, Fragment as Xe } from "react/jsx-runtime";
|
|
2
|
-
import { u as D, F as Nt, H as Oe, G as Ye, J as Lt, s as Ae, K as kt, M as Ot, j as At, N as Pt, O as qt, Q as Ct } from "./index-
|
|
2
|
+
import { u as D, F as Nt, H as Oe, G as Ye, J as Lt, s as Ae, K as kt, M as Ot, j as At, N as Pt, O as qt, Q as Ct } from "./index-v997iKxe.js";
|
|
3
3
|
import * as p from "react";
|
|
4
4
|
import { use as be, createContext as Pe, useState as q, useCallback as w, useMemo as F, useRef as g, useLayoutEffect as I, useEffect as _, useSyncExternalStore as Ee, Suspense as Qe, useId as ye } from "react";
|
|
5
5
|
import { C as Ft, k as Mt, l as Je, v as _t, m as It, n as Dt, E as Ht, o as Be, q as $t, s as Zt, S as ve, t as Bt, F as zt, A as Vt } from "./location-IRD9h42r.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const c=require("react/jsx-runtime"),R=require("./index-afZWk187.cjs"),r=require("react"),O=require("./location-D6RE3wAN.cjs"),_e=require("@aiquants/directory-tree"),dt=require("./tapScrollCircle-C5DGI-0H.cjs"),ft=require("./storage-Dgi4JXaB.cjs"),pe=require("@aiquants/resize-panels"),mt=require("react-router");function pt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const h=pt(r);function ht({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15ZM9 12.75a.75.75 0 0 0 0 1.5h6a.75.75 0 0 0 0-1.5H9Z",clipRule:"evenodd"}))}const xt=h.forwardRef(ht);function wt({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15Zm-6.75-10.5a.75.75 0 0 0-1.5 0v2.25H9a.75.75 0 0 0 0 1.5h2.25v2.25a.75.75 0 0 0 1.5 0v-2.25H15a.75.75 0 0 0 0-1.5h-2.25V10.5Z",clipRule:"evenodd"}))}const gt=h.forwardRef(wt);function Et({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M16.5 6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v7.5a3 3 0 0 0 3 3v-6A4.5 4.5 0 0 1 10.5 6h6Z"}),h.createElement("path",{d:"M18 7.5a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-7.5a3 3 0 0 1-3-3v-7.5a3 3 0 0 1 3-3H18Z"}))}const bt=h.forwardRef(Et);function vt({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3V6ZM3 15.75a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-2.25Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3v-2.25Z",clipRule:"evenodd"}))}const Rt=h.forwardRef(vt),yt=()=>{const{notices:e}=R.useExplorer(),t=r.use(e);return t.length===0?null:c.jsx("div",{className:"aqmx-explorer-notices",children:t.map(n=>c.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":n.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":n.id,children:[c.jsx("p",{className:"aqmx-callout-title",children:n.title}),n.body===void 0?null:c.jsx("p",{className:"aqmx-callout-body",children:n.body}),n.action===void 0?null:c.jsx("a",{className:"aqmx-callout-action",href:n.action.href,children:n.action.label})]},n.id))})};function St({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.912 3a3 3 0 0 0-2.868 2.118l-2.411 7.838a3 3 0 0 0-.133.882V18a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3v-4.162c0-.299-.045-.596-.133-.882l-2.412-7.838A3 3 0 0 0 17.088 3H6.912Zm13.823 9.75-2.213-7.191A1.5 1.5 0 0 0 17.088 4.5H6.912a1.5 1.5 0 0 0-1.434 1.059L3.265 12.75H6.11a3 3 0 0 1 2.684 1.658l.256.513a1.5 1.5 0 0 0 1.342.829h3.218a1.5 1.5 0 0 0 1.342-.83l.256-.512a3 3 0 0 1 2.684-1.658h2.844Z",clipRule:"evenodd"}))}const kt=h.forwardRef(St),ve=r.createContext(!0),Ie="\0loop\0",De="\0",Ct=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=o=>{const l=e.get(o);if(l!==void 0)return l;const i=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,i),i},s=(o,l,i)=>{let f=!1;const m=o.map(p=>{const x=u(p,l,i);return x!==p&&(f=!0),x});if(!f)return o;const d=n.get(o);return d!==void 0&&d.length===m.length&&d.every((p,x)=>p===m[x])?d:(n.set(o,m),m)},u=(o,l,i)=>{if(o.type!=="directory")return o;if(i.has(o.path))return a(o);const f=o.lazy===!0?l(o.path):void 0,m=f?.status==="loaded",d=m?f.entries:o.children;if(d===void 0)return o;i.add(o.path);const p=s(d,l,i);if(i.delete(o.path),!m&&p===o.children)return o;const x=t.get(o);if(x!==void 0&&x.state===f&&x.children===p)return x.grafted;const g={...o,children:p,lazy:m?!1:o.lazy};return t.set(o,{state:f,children:p,grafted:g}),g};return(o,l)=>s(o,l,new Set)},Tt=(e,t)=>`${Ie}${e}${De}${t}`,ie=e=>e.startsWith(Ie),Lt=e=>e.slice(e.lastIndexOf(De)+1),ne="data-aqmx-path",jt=(e,t,n,a,s)=>{const u={aqmxPath:e.path};return e.modifiedAt!==void 0&&(u.aqmxModifiedAt=e.modifiedAt),n&&(u.aqmxOpen=!0),(a==="loading"||a==="failed")&&(u.aqmxChildren=a),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:s,data:u}},Nt=(e,t,n,a)=>{const s=Tt(t,e.path);return{name:n,type:"directory",absolutePath:s,relativePath:s,children:a,data:{aqmxLoop:e.path}}},Pt=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=[],s=(l,i,f)=>{const m=l.map(p=>p.type==="loop"?u(p,i,f):o(p,i)),d=n.get(l);return d!==void 0&&d.length===m.length&&d.every((p,x)=>p===m[x])?d:(n.set(l,m),m)},u=(l,i,f)=>{const m=t.get(l);if(m!==void 0&&m.parentKey===f&&m.loopFolderName===i.loopFolderName)return m.row;const d=Nt(l,f,i.loopFolderName(l.name),a);return t.set(l,{row:d,parentKey:f,loopFolderName:i.loopFolderName}),d},o=(l,i)=>{const f=l.type==="directory"?l.children===void 0?a:s(l.children,i,l.path):void 0,m=i.openPaths.has(l.path),d=l.type==="directory"&&l.lazy===!0?i.childrenOf(l.path)?.status:void 0,p=d==="failed"?i.renderFailedFolder:void 0,x=e.get(l);if(x!==void 0&&x.open===m&&x.childrenStatus===d&&x.children===f&&x.renderFailedFolder===p)return x.row;const g=jt(l,f,m,d,p===void 0?void 0:p(l));return e.set(l,{row:g,open:m,childrenStatus:d,children:f,renderFailedFolder:p}),g};return(l,i)=>s(l,i,"")},Ot=e=>{if(e===void 0)return;const t=n=>{const a=n.data?.aqmxModifiedAt;return typeof a=="number"?{name:n.name,path:n.absolutePath,type:n.type,modifiedAt:a}:{name:n.name,path:n.absolutePath,type:n.type}};return(n,a)=>e(t(n),t(a))},be=(e,t)=>{const n=e.filter(a=>a.type==="directory");return t===void 0?n:n.sort(t)},qt=(e,t)=>{const n=new Map;let a=0;const s=u=>{for(const o of be(u,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&s(o.children);continue}n.has(o.path)||(n.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(a+=1))}};return s(e),{folders:n,waiting:a}},At=e=>{const t=new Set,n=a=>{for(const s of a)s.type==="directory"&&(s.lazy===!0&&t.add(s.path),s.children!==void 0&&n(s.children))};return n(e),t},He=(e,t)=>{for(const n of e){if(n.type!=="directory")continue;if(n.path===t)return n;const a=n.children===void 0?null:He(n.children,t);if(a!==null)return a}return null},Mt=(e,t,n,a)=>{let s=e;for(const u of t){const o=s.find(l=>l.type==="directory"&&l.path===u);if(o===void 0)return"missing";if(o.lazy===!0)return a.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!a.isShownExpanded(o.path))return"loading";s=o.children??[]}return s.some(u=>u.type==="file"&&u.path===n)?"ready":"missing"},Pe=new Set,Ft=(e,t)=>e.has(t)?e:new Set(e).add(t),_t=(e,t)=>{if(!t.some(a=>e.has(a)))return e;const n=new Set(t);return new Set([...e].filter(a=>!n.has(a)))},It=(e,t)=>[...e].every(n=>t.has(n))?e:new Set([...e].filter(n=>t.has(n))),Dt=()=>{const[e,t]=r.useState(Pe),n=r.useCallback(o=>t(l=>Ft(l,o)),[]),a=r.useCallback(o=>t(l=>_t(l,o)),[]),s=r.useCallback(o=>t(l=>It(l,o)),[]),u=r.useCallback(()=>t(Pe),[]);return r.useMemo(()=>({direct:e,markDirect:n,unmarkDirect:a,pruneDirect:s,clearDirect:u}),[e,n,a,s,u])},Ht=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),Zt=(e,t)=>{const n=[];let a=be(t.entries,t.compare);for(let s=1;a.length>0;s+=1){const u=[];for(const o of a){const{path:l}=o;if(t.isShownExpanded(l))e.handled.add(l);else{if(e.handled.has(l))continue;if(e.handled.add(l),o.lazy===!0&&t.childrenOf(l)===void 0){if(s>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(l)}n.push(l),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&u.push(...be(o.children,t.compare))}a=u}return n},Ze=(e,t)=>e.every(n=>n.type!=="directory"||t(n.path)&&(n.lazy===!0||n.children===void 0||Ze(n.children,t))),$t=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let n=0;for(const a of e.loads)t.childrenOf(a)?.status==="failed"&&(n+=1);return{kind:"done",opened:e.opened,failed:n,complete:Ze(t.entries,t.isShownExpanded)}},Ee=Object.freeze({state:"idle"}),Bt=e=>{const t=r.useRef(null),n=r.useRef(e),[a,s]=r.useState(Ee);r.useLayoutEffect(()=>{n.current=e});const u=r.useCallback(()=>{t.current===null&&(t.current=Ht(n.current.budget),s({state:"running",opened:0}))},[]),o=r.useCallback(()=>{t.current=null,s(Ee)},[]),l=r.useCallback(i=>{const f=t.current;if(f===null)return;const m=Zt(f,i);if(m.length>0&&(f.issuedAgainst=i.expanded,n.current.expandMultiple([...m])),!f.announcedStart&&(f.loads.size>0||i.waiting>0)&&(f.announcedStart=!0,n.current.onStart()),m.length===0&&!i.expansionPending&&i.expanded!==f.issuedAgainst&&i.waiting===0){t.current=null;const p=$t(f,i);s(p.kind==="done"?Ee:{state:"stopped",stop:p.kind,opened:p.opened}),n.current.onFinish(p);return}const{opened:d}=f;s(p=>p.state==="running"&&p.opened===d?p:{state:"running",opened:d})},[]);return r.useMemo(()=>({status:a,start:u,end:o,advance:l}),[a,u,o,l])},Oe=["pointerdown","wheel","touchstart","keydown","focusin"],zt=8,qe={least:Number.POSITIVE_INFINITY,stalled:0},Vt=({tree:e,container:t,path:n,chain:a,rows:s,cancel:u,displayed:o,placement:l})=>{const i=r.useRef(null),f=r.useRef(!0),m=r.useRef(qe),d=r.useRef(null),p=r.useRef(null),x=r.useRef(a),g=r.useRef(l);r.useLayoutEffect(()=>{x.current=a,g.current=l},[a,l]);const b=r.useCallback(()=>{const L=d.current;L!==null&&(d.current=null,L.phase==="asking"?L.controller.abort():x.current?.open(null))},[]),S=r.useCallback(()=>{i.current=null,b()},[b]),P=r.useCallback(()=>{const L=t.current;i.current===null||p.current!==null||L===null||L.getClientRects().length===0||(p.current=requestAnimationFrame(()=>{p.current=null;const E=i.current;if(E===null)return;const y=g.current(E);if(y===0){f.current=!0,d.current?.phase==="opening"&&b();return}if(e.current?.scrollToPath(E,{align:"nearest"})===!0){d.current?.phase==="opening"&&b();const{least:j,stalled:A}=m.current;m.current=y<j?{least:y,stalled:0}:{least:j,stalled:A+1},m.current.stalled<zt&&P();return}const v=d.current;if(v===null){i.current=null;return}v.phase==="opening"&&x.current?.progress(v.folders,E)!=="loading"&&S()}))},[e,t,b,S]),k=r.useCallback(()=>{f.current=!1,m.current=qe,P()},[P]);r.useEffect(()=>{const L=t.current;if(L===null)return;const E=typeof ResizeObserver>"u"?null:new ResizeObserver(k);E?.observe(L);for(const y of Oe)L.addEventListener(y,S,{passive:!0});return()=>{E?.disconnect();for(const y of Oe)L.removeEventListener(y,S);p.current!==null&&cancelAnimationFrame(p.current),p.current=null,b()}},[t,k,S,b]);const T=a!==null;r.useEffect(()=>{const L=t.current;if(S(),n===null||L===null||L.contains(L.ownerDocument.activeElement))return;i.current=n;const E=x.current;if(T&&E!==null){const y=new AbortController,v={phase:"asking",controller:y};d.current=v,E.ancestors(n,y.signal).then(j=>{d.current===v&&(j===null?d.current=null:(d.current={phase:"opening",folders:j},x.current?.open(j)),k())})}k()},[n,T,t,S,k]),r.useEffect(()=>{(d.current?.phase==="opening"||i.current!==null&&!f.current)&&k()},[s,k]);const F=r.useRef(u);r.useEffect(()=>{F.current!==u&&(F.current=u,S())},[u,S]);const q=r.useRef(o);r.useEffect(()=>{q.current&&!o&&b(),q.current=o},[o,b])},Kt="--aqmx-tree-line",Xt=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Wt="data-aqmx-tree-probe",Ut=Object.freeze({rowHeight:O.CONTROL_BLOCK_PIXELS,lineColor:null}),Gt=/^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/u,Yt=e=>{const t=Gt.exec(e);return t===null?e:`#${t.slice(1).map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`},Qt=(e,t)=>{const[n,a]=r.useState(Ut);return r.useLayoutEffect(()=>{const s=e.current;if(s===null)return;const u=()=>{const i=Math.round(s.getBoundingClientRect().height),f=getComputedStyle(s),m=f.getPropertyValue(Kt).trim()===""?null:Yt(f.color);a(d=>{const p=Number.isFinite(i)&&i>0?i:d.rowHeight;return d.rowHeight===p&&d.lineColor===m?d:{rowHeight:p,lineColor:m}})};u();const o=Xt.map(i=>window.matchMedia(i));for(const i of o)i.addEventListener("change",u);const l=typeof ResizeObserver>"u"?null:new ResizeObserver(u);return l?.observe(s),()=>{for(const i of o)i.removeEventListener("change",u);l?.disconnect()}},[e,t]),n},$e="markdown-explorer-tree-scroll",Jt=.5,Be=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${ne}]`)].find(n=>n.getAttribute(ne)===t),en=(e,t)=>{const n=Be(e,t),a=n?.closest(`[data-testid="${$e}"]`);if(n===void 0||a===null||a===void 0)return Number.POSITIVE_INFINITY;const s=a.getBoundingClientRect(),u=n.getBoundingClientRect(),o=s.top-u.top,l=u.height>s.height?Math.abs(o):Math.max(0,o)+Math.max(0,u.bottom-s.bottom);return l<=Jt?0:l},tn={testId:$e,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:{width:8,enableTrackClick:!0,enableThumbDrag:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:dt.TAP_SCROLL_CIRCLE},behaviorOptions:{enablePointerDrag:!0}},nn={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},rn={color:"inherit"},an={paddingBlock:0},ln=new Set,on=new Map,sn={color:"var(--aqmx-tree-line)"},cn=e=>{const t=e instanceof Element?e.closest(`[${ne}]`):null;return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(ne)},ze=(e,t,n,a)=>n==="folder-limit"?e.expandAllFolderLimit(a,t.maxFolders,e.expandAll):e.expandAllDepthLimit(a,t.maxDepth),un=(e,t,n)=>n.kind==="done"?e.expandAllDone(n.opened,n.failed,n.complete):ze(e,t,n.kind,n.opened),Ve=()=>{const{labels:e}=R.useExplorer();return c.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[c.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),c.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{})]})]})},dn=()=>{const{labels:e}=R.useExplorer();return c.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[c.jsx(kt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),c.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),c.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},fn=({name:e,onRetry:t})=>{const{labels:n}=R.useExplorer(),a=r.useId();return c.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[c.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),c.jsx("span",{id:a,className:"aqmx-explorer-folder-error",children:n.folderLoadFailed}),c.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":a,"data-testid":"markdown-explorer-folder-retry",onClick:s=>{s.stopPropagation();const u=s.currentTarget,o=u.ownerDocument.activeElement===u?u.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&R.focusWithoutScroll(o),t()},onKeyDown:s=>{s.key!=="Escape"&&s.stopPropagation()},children:[c.jsx(R.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:n.retry})]})]})},mn=({entries:e,version:t,mode:n,sourceId:a,settings:s,reveal:u,openPaths:o,selection:l,onOpenDocument:i,onRevealSource:f,expansion:m,onShown:d,marks:p,claimsHeld:x,expandAll:g,revealCancel:b})=>{const{trees:S,documents:P,labels:k,locale:T,theme:F,data:q,config:L,sources:E,reveals:y}=R.useExplorer(),v=r.use(ve),[j]=r.useState(Pt),A=r.useRef(null),{rowHeight:le,lineColor:z}=Qt(A,F),{isExpanded:_,toggle:U,expandMultiple:Z,collapseMultiple:J,expanded:D,isPending:ee}=m,{alwaysExpanded:V,sortMode:M,folderPlacement:$}=s,{direct:oe,markDirect:B,unmarkDirect:re,pruneDirect:se}=p,{running:te,advance:ue}=g,ce=r.useRef(null),G=r.useRef(null),C=r.useMemo(()=>O.createEntryComparator({sortMode:M,folderPlacement:$}),[M,$]),K=r.useMemo(()=>Ot(C),[C]),I=r.useCallback(w=>S.children(a,w),[S,a]),Y=r.useMemo(()=>At(e),[e]),Q=r.useCallback(w=>!ie(w)&&(_(w)||V&&!Y.has(w)),[_,V,Y]),X=r.useRef({shownExpanded:Q,isExpanded:_,unloadedFolders:Y,entries:e,childrenOf:I});r.useLayoutEffect(()=>{X.current={shownExpanded:Q,isExpanded:_,unloadedFolders:Y,entries:e,childrenOf:I}},[Q,_,Y,e,I]);const Se=r.useCallback(w=>{ce.current?.scrollToPath(w,{align:"nearest"}),requestAnimationFrame(()=>{const N=G.current,H=N===null?void 0:Be(N,w);H!==void 0&&R.focusWithoutScroll(H)})},[]),Je=r.useCallback(w=>{if(ie(w)){Se(Lt(w));return}X.current.isExpanded(w)?re([w]):X.current.unloadedFolders.has(w)&&B(w),U(w)},[Se,B,re,U]),xe=r.useCallback(w=>{const N=w.filter(H=>!ie(H));N.length!==0&&(re(N),J(N))},[re,J]),et=r.useCallback(w=>{const N=w.filter(H=>!ie(H));N.length!==0&&(N.length<w.length&&N.every(H=>X.current.shownExpanded(H))?xe(N):Z(N))},[Z,xe]),ke=r.useCallback(w=>c.jsx(fn,{name:w.name,onRetry:()=>{B(w.path),S.retryChildren(a,w.path),X.current.shownExpanded(w.path)||Z([w.path])}}),[S,a,B,Z]),Ce=n==="multi"?o:ln,{loopFolderName:Te}=k,tt=r.useMemo(()=>j(e,{openPaths:Ce,childrenOf:I,renderFailedFolder:ke,loopFolderName:Te}),[j,e,Ce,I,ke,Te,t]),nt=R.useIntentPrefetch(P,cn),Le=r.useRef([]),de=r.useCallback(()=>{for(const w of Le.current)X.current.unloadedFolders.has(w)&&B(w)},[B]),{maxDepth:we}=L.revealDocument,je=r.useRef(f);r.useLayoutEffect(()=>{je.current=f},[f]);const rt=r.useMemo(()=>({ancestors:async(w,N)=>{const H=y.take(a,w);if(H!==null)return H;if(!y.mayMove(w)){const ae=await q.ancestors(a,w,N);return ae.status!=="ok"||ae.ancestors===null||ae.ancestors.length>we?null:ae.ancestors}const W=await q.reveal(a,w,N);return W.status!=="ok"||W.source===null||W.ancestors.length>we?null:W.source===a?W.ancestors:(N.aborted||!E.some(ae=>ae.id===W.source)||(y.move(W.source,w,W.ancestors),je.current(W.source)),null)},open:w=>{Le.current=w??[],w!==null&&(de(),Z([...w]))},progress:(w,N)=>Mt(X.current.entries,w,N,{isShownExpanded:X.current.shownExpanded,childrenOf:X.current.childrenOf})}),[q,a,E,y,we,de,Z]);r.useEffect(()=>de(),[de,Y]);const at=r.useMemo(()=>[e,t,D],[e,t,D]),lt=r.useCallback(w=>G.current===null?Number.POSITIVE_INFINITY:en(G.current,w),[]);Vt({tree:ce,container:G,path:u.path,chain:u.openFolders?rt:null,rows:at,cancel:b,displayed:v,placement:lt});const Ne=r.useCallback(w=>oe.has(w),[oe]),fe=r.useMemo(()=>qt(e,{isShownExpanded:Q,childrenOf:I,compare:C,isDirect:Ne}),[e,Q,I,C,Ne,t]),me=v&&x;r.useLayoutEffect(()=>{d(e)},[e,d]),r.useLayoutEffect(()=>()=>d(null),[d]),r.useEffect(()=>S.claimChildren(a,me?fe.folders:on),[S,a,me,fe]),r.useEffect(()=>se(Y),[se,Y]),r.useEffect(()=>{me&&te&&ue({entries:e,isShownExpanded:Q,childrenOf:I,compare:C,expanded:D,waiting:fe.waiting,expansionPending:ee})},[me,te,ue,e,Q,I,C,D,fe,ee]);const ot=r.useCallback(w=>{w.isDirectory||(y.settle(w.entry.absolutePath),i(w.entry.absolutePath))},[y,i]),{onChange:ge}=l,st=r.useMemo(()=>ge===null?void 0:(w,N)=>{ie(w.absolutePath)||ge({path:w.absolutePath,name:w.name,selected:N})},[ge]),ct=r.useMemo(()=>new Set(l.items),[l.items]),it=r.useMemo(()=>({entryKindDirectory:k.treeEntryKindDirectory,entryKindFile:k.treeEntryKindFile,scrollUp:k.treeScrollUp,scrollDown:k.treeScrollDown,scrollToTop:k.treeScrollToTop,scrollToBottom:k.treeScrollToBottom}),[k]),ut=z===null?{showTreeLines:!1}:{showTreeLines:s.lines,lineColor:z};return c.jsxs("div",{ref:G,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",...nt,children:[c.jsx("span",{ref:A,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Wt]:""}),c.jsx(_e.DirectoryTree,{ref:ce,entries:tt,expansion:{toggle:Je,isExpanded:Q,expandMultiple:et,collapseMultiple:xe,isPending:ee&&!te,doubleClickAction:s.doubleClickAction},selection:{mode:l.mode,selectedPath:l.shownPath,currentPath:l.shownPath,selectedItems:ct,onEntryClick:ot,onSelectionChange:st},visual:{className:"aqmx-explorer-tree-view",ariaLabel:k.treeRegion,...ut,showExpandIcons:s.expandIcons,expandIconStyle:sn,showDirectoryIcons:s.directoryIcons,showFileIcons:s.fileIcons,expandIconSize:s.expandIconSize,itemHeight:le,removeRootIndent:s.removeRootIndent,highlightStyles:nn,entryStyle:an,nameStyle:rn},virtualScroll:tn,sort:K,locale:T,labels:it})]})},pn=({pending:e,status:t})=>{const{labels:n}=R.useExplorer(),a=t.state!=="running",[s,u]=r.useState(0),o=r.useRef(!0);r.useLayoutEffect(()=>{const i=o.current;if(o.current=a,!a||e>0&&!i){u(0);return}if(e>0){u(e);return}if(s===0)return;const f=setTimeout(()=>u(0),0);return()=>clearTimeout(f)},[a,e,s]);const l=a&&e===0?s:e;return l===0&&a?null:c.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(l),"data-aqmx-expand-all":t.state,children:[l>0?c.jsx(R.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,c.jsx("span",{children:t.state==="running"?n.expandAllProgress(t.opened,l):n.foldersLoading(l)})]})},hn=({stop:e,opened:t,budget:n})=>{const{labels:a}=R.useExplorer();return c.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:ze(a,n,e,t)})},xn=({entries:e,...t})=>{const{trees:n}=R.useExplorer(),a=r.useSyncExternalStore(n.subscribe,n.version,n.version),{sourceId:s}=t,[u]=r.useState(Ct),o=r.useMemo(()=>u(e,l=>n.children(s,l)),[u,e,n,s,a]);return o.length===0?c.jsx(dn,{}):c.jsx(mn,{entries:o,version:a,...t})},wn=({result:e,onRetry:t,...n})=>{const{renderTreeFailure:a}=R.useExplorer(),s=r.use(e);if(s.status==="deferred")return c.jsx(Ve,{});if(s.status==="ok")return c.jsx(xn,{entries:s.entries,...n});const u=a?.(s.failure);return c.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":s.failure.reason,children:u!==void 0?u:c.jsx(R.FailureView,{failure:s.failure,alert:!0,onRetry:t,testId:null})})},gn=({onControls:e,...t})=>{const{trees:n,storageNamespace:a,labels:s,announcer:u,config:o}=R.useExplorer(),{sourceId:l}=t,i=_e.useDirectoryTreeState({storageKey:ft.storageKeys(a).treeExpansion(l)});r.useSyncExternalStore(n.subscribe,n.version,n.version);const f=n.read(l),m=r.useCallback(()=>n.retry(l),[n,l]);r.useLayoutEffect(()=>n.open(l),[n,l]);const d=Dt(),{expanded:p,expandMultiple:x,collapseAll:g}=i,[b,S]=r.useState(null),P=b!==p,k=r.useRef(p);r.useLayoutEffect(()=>{k.current=p},[p]);const T=o.expandAll,F=r.useCallback(()=>u.announce(s.expandAllStarted),[u,s]),q=r.useCallback(M=>u.announce(un(s,T,M)),[u,s,T]),L=Bt({budget:T,expandMultiple:x,onStart:F,onFinish:q}),{status:E,start:y,end:v,advance:j}=L,A=E.state==="running",le=r.useMemo(()=>({running:A,advance:j}),[A,j]),z=r.useRef(null),[_,U]=r.useState(!1),Z=r.useCallback(M=>{z.current=M,U(M!==null)},[]);r.useEffect(()=>n.subscribeChildrenFailures(M=>{const $=M.sourceId===l&&z.current!==null?He(z.current,M.path):null;$!==null&&u.announce({list:s.foldersLoadFailedNamed,item:$.name})}),[n,l,u,s]);const{clearDirect:J}=d,[D,ee]=r.useState(0),V=r.useCallback(()=>{ee(M=>M+1),v(),J(),S(k.current),g()},[v,J,g]);return r.useEffect(()=>{e({collapseAll:V,expandAll:_?y:null,expanding:A})},[e,V,y,_,A]),r.useEffect(()=>()=>e(null),[e]),r.useEffect(()=>{_||v()},[_,v]),c.jsxs(c.Fragment,{children:[E.state==="stopped"?c.jsx(hn,{stop:E.stop,opened:E.opened,budget:T}):null,c.jsxs("div",{className:"aqmx-explorer-tree-area",children:[c.jsx(r.Suspense,{fallback:c.jsx(Ve,{}),children:c.jsx(wn,{result:f,onRetry:m,expansion:i,onShown:Z,marks:d,claimsHeld:P,expandAll:le,revealCancel:D,...t})}),c.jsx(pn,{pending:n.pendingChildren(l),status:E})]})]})};function En({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.47 5.47a.75.75 0 0 1 1.06 0L12 10.94l5.47-5.47a.75.75 0 1 1 1.06 1.06L13.06 12l5.47 5.47a.75.75 0 1 1-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 0 1-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const Ke=h.forwardRef(En),Ae="markdown-explorer-selection-remove",bn=({selection:e,onRemove:t,onClear:n,onOpenSelection:a,onLeave:s})=>{const{labels:u}=R.useExplorer(),o=r.useId(),l=r.useRef(null),i=[...e],f=(d,p)=>{if(p.ownerDocument.activeElement===p){const x=l.current===null?[]:[...l.current.querySelectorAll(`[data-testid="${Ae}"]`)],g=x.indexOf(p),b=[x[g+1],x[g-1]].find(S=>S!==void 0);b===void 0?s():b.focus()}t(d)},m=()=>{const d=l.current;d!==null&&d.contains(d.ownerDocument.activeElement)&&s(),n()};return c.jsxs("section",{ref:l,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[c.jsxs("div",{className:"aqmx-explorer-tray-header",children:[c.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:u.selectionTitle(i.length)}),c.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:m,children:u.clearSelection})]}),c.jsx("ul",{className:"aqmx-explorer-tray-list",children:i.map(([d,p])=>c.jsxs("li",{className:"aqmx-explorer-tray-item",children:[c.jsx("span",{className:"aqmx-explorer-tray-name",title:d,children:p}),c.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":u.removeFromSelection(p),title:u.removeFromSelection(p),"data-testid":Ae,"data-aqmx-path":d,onClick:x=>f(d,x.currentTarget),children:c.jsx(Ke,{"aria-hidden":"true"})})]},d))}),a===void 0?null:c.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>a(i.map(([d])=>d)),children:u.openSelectionInMulti(i.length)})]})},he=new Map,vn=(e,t)=>{if(t.selected===e.has(t.path))return e;const n=new Map(e);return t.selected?n.set(t.path,t.name):n.delete(t.path),n},Rn=(e,t)=>{if(!e.has(t))return e;const n=new Map(e);return n.delete(t),n},Xe=r.createContext(null),yn=e=>{const t=r.use(Xe);r.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Sn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M15 3.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0V5.56l-3.97 3.97a.75.75 0 1 1-1.06-1.06l3.97-3.97h-2.69a.75.75 0 0 1-.75-.75Zm-12 0A.75.75 0 0 1 3.75 3h4.5a.75.75 0 0 1 0 1.5H5.56l3.97 3.97a.75.75 0 0 1-1.06 1.06L4.5 5.56v2.69a.75.75 0 0 1-1.5 0v-4.5Zm11.47 11.78a.75.75 0 1 1 1.06-1.06l3.97 3.97v-2.69a.75.75 0 0 1 1.5 0v4.5a.75.75 0 0 1-.75.75h-4.5a.75.75 0 0 1 0-1.5h2.69l-3.97-3.97Zm-4.94-1.06a.75.75 0 0 1 0 1.06L5.56 19.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75v-4.5a.75.75 0 0 1 1.5 0v2.69l3.97-3.97a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const kn=h.forwardRef(Sn);function Cn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.97 2.47a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.25 4.81V16.5a.75.75 0 0 1-1.5 0V4.81L3.53 8.03a.75.75 0 0 1-1.06-1.06l4.5-4.5Zm9.53 4.28a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Tn=h.forwardRef(Cn);function Ln({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"}))}const jn=h.forwardRef(Ln);function Nn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M7.72 12.53a.75.75 0 0 1 0-1.06l7.5-7.5a.75.75 0 1 1 1.06 1.06L9.31 12l6.97 6.97a.75.75 0 1 1-1.06 1.06l-7.5-7.5Z",clipRule:"evenodd"}))}const Pn=h.forwardRef(Nn);function On({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.47 4.72a.75.75 0 0 1 1.06 0l3.75 3.75a.75.75 0 0 1-1.06 1.06L12 6.31 8.78 9.53a.75.75 0 0 1-1.06-1.06l3.75-3.75Zm-3.75 9.75a.75.75 0 0 1 1.06 0L12 17.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-3.75 3.75a.75.75 0 0 1-1.06 0l-3.75-3.75a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const qn=h.forwardRef(On);function An({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.078 2.25c-.917 0-1.699.663-1.85 1.567L9.05 4.889c-.02.12-.115.26-.297.348a7.493 7.493 0 0 0-.986.57c-.166.115-.334.126-.45.083L6.3 5.508a1.875 1.875 0 0 0-2.282.819l-.922 1.597a1.875 1.875 0 0 0 .432 2.385l.84.692c.095.078.17.229.154.43a7.598 7.598 0 0 0 0 1.139c.015.2-.059.352-.153.43l-.841.692a1.875 1.875 0 0 0-.432 2.385l.922 1.597a1.875 1.875 0 0 0 2.282.818l1.019-.382c.115-.043.283-.031.45.082.312.214.641.405.985.57.182.088.277.228.297.35l.178 1.071c.151.904.933 1.567 1.85 1.567h1.844c.916 0 1.699-.663 1.85-1.567l.178-1.072c.02-.12.114-.26.297-.349.344-.165.673-.356.985-.57.167-.114.335-.125.45-.082l1.02.382a1.875 1.875 0 0 0 2.28-.819l.923-1.597a1.875 1.875 0 0 0-.432-2.385l-.84-.692c-.095-.078-.17-.229-.154-.43a7.614 7.614 0 0 0 0-1.139c-.016-.2.059-.352.153-.43l.84-.692c.708-.582.891-1.59.433-2.385l-.922-1.597a1.875 1.875 0 0 0-2.282-.818l-1.02.382c-.114.043-.282.031-.449-.083a7.49 7.49 0 0 0-.985-.57c-.183-.087-.277-.227-.297-.348l-.179-1.072a1.875 1.875 0 0 0-1.85-1.567h-1.843ZM12 15.75a3.75 3.75 0 1 0 0-7.5 3.75 3.75 0 0 0 0 7.5Z",clipRule:"evenodd"}))}const Mn=h.forwardRef(An);function Fn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M12 1.5a.75.75 0 0 1 .75.75V4.5a.75.75 0 0 1-1.5 0V2.25A.75.75 0 0 1 12 1.5ZM5.636 4.136a.75.75 0 0 1 1.06 0l1.592 1.591a.75.75 0 0 1-1.061 1.06l-1.591-1.59a.75.75 0 0 1 0-1.061Zm12.728 0a.75.75 0 0 1 0 1.06l-1.591 1.592a.75.75 0 0 1-1.06-1.061l1.59-1.591a.75.75 0 0 1 1.061 0Zm-6.816 4.496a.75.75 0 0 1 .82.311l5.228 7.917a.75.75 0 0 1-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 0 1-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 0 1-1.247-.606l.569-9.47a.75.75 0 0 1 .554-.68ZM3 10.5a.75.75 0 0 1 .75-.75H6a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 10.5Zm14.25 0a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5H18a.75.75 0 0 1-.75-.75Zm-8.962 3.712a.75.75 0 0 1 0 1.061l-1.591 1.591a.75.75 0 1 1-1.061-1.06l1.591-1.592a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const _n=h.forwardRef(Fn);function In({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z",clipRule:"evenodd"}),h.createElement("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"}))}const Dn=h.forwardRef(In);function Hn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z"}))}const Zn=h.forwardRef(Hn);function $n({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.906 9c.382 0 .749.057 1.094.162V9a3 3 0 0 0-3-3h-3.879a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H6a3 3 0 0 0-3 3v3.162A3.756 3.756 0 0 1 4.094 9h15.812ZM4.094 10.5a2.25 2.25 0 0 0-2.227 2.568l.857 6A2.25 2.25 0 0 0 4.951 21H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-2.227-2.568H4.094Z"}))}const Bn=h.forwardRef($n);function zn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M10.5 3.75a6.75 6.75 0 1 0 0 13.5 6.75 6.75 0 0 0 0-13.5ZM2.25 10.5a8.25 8.25 0 1 1 14.59 5.28l4.69 4.69a.75.75 0 1 1-1.06 1.06l-4.69-4.69A8.25 8.25 0 0 1 2.25 10.5Zm8.25-3.75a.75.75 0 0 1 .75.75v2.25h2.25a.75.75 0 0 1 0 1.5h-2.25v2.25a.75.75 0 0 1-1.5 0v-2.25H7.5a.75.75 0 0 1 0-1.5h2.25V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Vn=h.forwardRef(zn);function Kn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M5.625 3.75a2.625 2.625 0 1 0 0 5.25h12.75a2.625 2.625 0 0 0 0-5.25H5.625ZM3.75 11.25a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75ZM3 15.75a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75ZM3.75 18.75a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75Z"}))}const Xn=h.forwardRef(Kn),Wn=Object.freeze({sortMode:Tn,folderPlacement:Zn,selectionMode:jn,doubleClickAction:_n,expandIconSize:Vn,alwaysExpanded:kn,revealDocument:R.ForwardRef$1,removeRootIndent:Pn,lines:Xn,expandIcons:qn,directoryIcons:Bn,fileIcons:Dn}),We=(e,t)=>{const n=e[t.labelKey];if(typeof n!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is a ${typeof n}`);return n},Un=({id:e,settings:t,descriptors:n,onAdvance:a,onClose:s,ref:u})=>{const{labels:o}=R.useExplorer(),l=r.useRef([]);r.useEffect(()=>{l.current[0]?.focus()},[]);const i=r.useCallback(m=>{const d=n.length;l.current[(m%d+d)%d]?.focus()},[n.length]),f=r.useCallback((m,d)=>{switch(m.key){case"ArrowDown":m.preventDefault(),i(d+1);break;case"ArrowUp":m.preventDefault(),i(d-1);break;case"Home":m.preventDefault(),i(0);break;case"End":m.preventDefault(),i(n.length-1);break;case"Escape":R.consumeKey(m),s();break;case"Tab":s();break}},[n.length,i,s]);return c.jsx("div",{ref:u,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:n.map((m,d)=>{const p=Wn[m.key],x=We(o,m),g=O.formatTreeSettingValue(o,t,m.key),b=t[m.key],S=typeof b=="boolean"?{role:"menuitemcheckbox","aria-checked":b,"aria-label":x}:{role:"menuitem","aria-label":`${x}: ${g}`};return c.jsxs("button",{ref:P=>{l.current[d]=P},type:"button",tabIndex:-1,...S,title:`${x}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":m.key,onClick:()=>a(m),onKeyDown:P=>f(P,d),children:[c.jsx(p,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-menu-name",children:x}),c.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},m.key)})})},Gn=({settings:e,descriptors:t,onAdvance:n})=>{const{labels:a,announcer:s}=R.useExplorer(),[u,o]=r.useState(!1),l=r.useRef(null),i=r.useRef(null),f=r.useRef(null),m=r.useId(),d=r.useCallback(()=>{l.current?.focus(),o(!1)},[]);r.useEffect(()=>{if(!u)return;const g=b=>{b.target instanceof Node&&(l.current?.contains(b.target)===!0||i.current?.contains(b.target)===!0)||(o(!1),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{f.current=null,(document.activeElement===null||document.activeElement===document.body)&&l.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[u]),r.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const p=r.useCallback(g=>{g.key!=="Escape"||!u||(R.consumeKey(g),d())},[u,d]),x=r.useCallback(g=>{const b=n(g.key);s.announce(a.settingAnnouncement(We(a,g),O.formatTreeSettingValue(a,b,g.key)))},[s,a,n]);return{trigger:c.jsx("button",{ref:l,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":u,"aria-controls":u?m:void 0,"aria-label":a.treeSettings,title:a.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:p,children:c.jsx(Mn,{"aria-hidden":"true"})}),menu:u?c.jsx(Un,{ref:i,id:m,settings:e,descriptors:t,onAdvance:x,onClose:d}):null}},Yn=()=>{const{treeSettings:e}=R.useExplorer();return{settings:r.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},Me=new Set,Qn='[role="tree"] [role="treeitem"][tabindex="0"]',Jn="[data-directory-tree-tab-stop]",er=e=>{const{mode:t,sourceId:n,currentPath:a,openPaths:s,onOpenDocument:u,onSourceChange:o,onRevealSource:l,viewSwitch:i}=e,{labels:f,sources:m,trees:d,documents:p,announcer:x,reveals:g}=R.useExplorer(),{settings:b,advance:S}=Yn(),P=r.useMemo(()=>O.visibleTreeSettingDescriptors(t==="tree"),[t]),k=t==="tree"&&b.selectionMode==="multiple";yn(k);const T=e.mode==="tree"?e.tray.onGatheredChange:null,F=e.mode==="tree"?e.onOpenSelection:void 0,q=e.mode==="tree"&&k?e.tray.gathered:he,L=r.useCallback(C=>{const K=S(C);return K.selectionMode!=="multiple"&&T?.(he),K},[S,T]),E=Gn({settings:b,descriptors:P,onAdvance:L}),y=r.useCallback(C=>T?.(K=>vn(K,C)),[T]),v=r.useCallback(C=>T?.(K=>Rn(K,C)),[T]),j=r.useCallback(()=>T?.(he),[T]),A=r.useRef(null),le=r.useCallback(()=>{const C=A.current;if(C===null)return;[Qn,Jn,'[data-testid="markdown-explorer-tree-settings"]'].map(I=>C.querySelector(I)).find(I=>I!==null)?.focus()},[]),z=r.useMemo(()=>new Set(q.keys()),[q]),_=r.useMemo(()=>a===null?Me:new Set([a]),[a]),U=r.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:s,shownPath:null,onChange:null};switch(b.selectionMode){case"single":return{mode:"single",items:_,shownPath:a,onChange:null};case"multiple":return{mode:"multiple",items:z,shownPath:a,onChange:y};case"none":return{mode:"none",items:Me,shownPath:null,onChange:null}}},[t,s,b.selectionMode,_,a,z,y]),Z=r.useMemo(()=>b.revealDocument?{path:a,openFolders:!0}:{path:U.shownPath,openFolders:!1},[b.revealDocument,a,U.shownPath]),J=r.useCallback(C=>{a!==null&&g.settle(a),o(C)},[a,g,o]),[D,ee]=r.useState(null),[V,M]=r.useState(!1),[$,oe]=r.useState(null),B=r.useRef(!1),re=r.useCallback(async()=>{if(!B.current){B.current=!0,M(!0),oe(null);try{const C=await d.refresh(n);if(C.status==="superseded")return;p.invalidate(),C.status==="failed"?oe({sourceId:n,failure:C.failure}):x.announce(f.treeRefreshed)}finally{B.current=!1,M(!1)}}},[d,p,n,x,f]),se=D===null?null:D.expandAll,te=D?.expanding===!0,ue=m.find(C=>C.id===n),ce=i.target==="multi"?Rt:bt,G=i.target==="multi"?f.switchToMulti:f.switchToTree;return c.jsxs("nav",{ref:A,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[c.jsxs("div",{className:"aqmx-explorer-header",children:[m.length>1?c.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:ue?.label,value:n,onChange:C=>J(C.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:m.map(C=>c.jsx("option",{value:C.id,children:C.label},C.id))}):null,c.jsxs("div",{className:"aqmx-explorer-actions",children:[c.jsx(R.ExplorerLink,{to:i.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":G,title:G,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":i.target,children:c.jsx(ce,{"aria-hidden":"true"})}),c.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":V,"aria-busy":V,"data-aqmx-busy":V?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{re()},children:[c.jsx(R.ForwardRef,{"aria-hidden":"true"}),c.jsx("span",{children:f.refreshTreeLabel})]}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":se===null||te,"aria-busy":te,"data-aqmx-busy":te?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>se?.(),children:c.jsx(gt,{"aria-hidden":"true"})}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":D===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>D?.collapseAll(),children:c.jsx(xt,{"aria-hidden":"true"})}),E.trigger]})]}),c.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[$!==null&&$.sourceId===n?c.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":$.failure.reason,children:f.treeRefreshFailed(R.failureTitleOf(f,$.failure.reason))}):null,c.jsx(r.Suspense,{fallback:null,children:c.jsx(yt,{})}),c.jsx(gn,{mode:t,sourceId:n,settings:b,reveal:Z,openPaths:s,selection:U,onOpenDocument:u,onRevealSource:l,onControls:ee},n),k&&q.size>0?c.jsx(bn,{selection:q,onRemove:v,onClear:j,onOpenSelection:F,onLeave:le}):null,E.menu]})]})},Ue="(pointer: coarse)",tr=e=>{const t=window.matchMedia(Ue);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},nr=()=>window.matchMedia(Ue).matches,rr=()=>!1,ar=()=>r.useSyncExternalStore(tr,nr,rr);function lr({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z",clipRule:"evenodd"}))}const or=h.forwardRef(lr),sr=({explorer:e,toggleRef:t,covered:n,onNoticeSlotChange:a,dismissals:s})=>{const{labels:u}=R.useExplorer(),o=mt.useLocation(),{location:l}=R.useExplorerLocation(),[i,f]=r.useState(!1),[m,d]=r.useState({navigated:o,source:l.source}),[p,x]=r.useState(!1);m.navigated!==o&&(d({navigated:o,source:l.source}),m.source===l.source&&!p&&f(!1));const[g,b]=r.useState(s);g!==s&&(b(s),f(!1));const S=r.useRef(null),P=r.useRef(null),k=r.useRef(null),T=r.useRef(!1),F=r.useId();r.useLayoutEffect(()=>{const v=S.current;v!==null&&(i&&!v.open?(v.showModal(),P.current?.focus()):!i&&v.open&&(v.close(),t.current?.focus()),a(i?k.current:null))},[i,t,a]),r.useLayoutEffect(()=>()=>a(null),[a]);const q=r.useCallback(v=>{v.key!=="Escape"||v.defaultPrevented||(R.consumeKey(v),f(!1))},[]),L=r.useCallback(v=>{T.current=v.target===v.currentTarget},[]),E=r.useCallback(v=>{const j=T.current;T.current=!1,j&&v.target===v.currentTarget&&f(!1)},[]),y=r.useCallback(()=>{f(!1)},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"aqmx-sheet-bar",inert:n,children:c.jsxs("button",{ref:t,type:"button",className:"aqmx-sheet-toggle","aria-haspopup":"dialog","aria-expanded":i,"aria-controls":F,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>f(!0),children:[c.jsx(or,{"aria-hidden":"true"}),c.jsx("span",{children:u.showExplorer})]})}),c.jsx("dialog",{ref:S,id:F,className:"aqmx-sheet","aria-label":u.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:q,onPointerDown:L,onClick:E,onClose:y,children:c.jsxs("div",{className:"aqmx-sheet-panel",children:[c.jsxs("div",{className:"aqmx-sheet-header",children:[c.jsx("div",{ref:k,className:"aqmx-sheet-notice-slot"}),c.jsx("button",{ref:P,type:"button",className:"aqmx-sheet-close","aria-label":u.hideExplorer,title:u.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>f(!1),children:c.jsx(Ke,{"aria-hidden":"true"})})]}),c.jsx("div",{className:"aqmx-sheet-body",children:c.jsx(ve,{value:i,children:c.jsx(Xe,{value:x,children:e})})}),c.jsx(R.LiveRegion,{holds:i,testId:"markdown-explorer-sheet-announcer"})]})})]})},Ge=r.createContext(null),Re="aqmx-explorer",Ye="aqmx-content",ye='[role="tree"] [role="treeitem"]',cr=`${ye}[tabindex="0"]`,ir="[data-directory-tree-tab-stop]",ur=(e,t)=>{for(const n of e.querySelectorAll(`[data-panel-id="${Re}"] ${ye}`))if(n.getAttribute(ne)===t)return n;return null},Fe=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:O.ASSUMED_ROOT_FONT_PIXELS}),dr=(e,t)=>{const[n,a]=r.useState(()=>Fe(0,0));return r.useLayoutEffect(()=>{const s=e.current,u=t.current;if(s===null||u===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:s.getBoundingClientRect().width,rem:u.getBoundingClientRect().width},l=()=>{const f=Fe(o.frame,o.rem);a(m=>m.inlineSize===f.inlineSize&&m.rootFontPixels===f.rootFontPixels?m:f)};l();const i=new ResizeObserver(f=>{for(const m of f){const[d]=m.borderBoxSize;d!==void 0&&(m.target===s&&(o.frame=d.inlineSize),m.target===u&&(o.rem=d.inlineSize))}l()});return i.observe(s),i.observe(u),()=>i.disconnect()},[e,t]),n},Qe=e=>`aqmx-split-handle-${e}`,fr=(e,{frameRef:t,sheetToggleRef:n,handleId:a})=>{const s=r.useRef(!1),u=r.useRef(null),o=r.useRef(!1);r.useLayoutEffect(()=>{const i=t.current;if(i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const f=d=>{const p=d.target instanceof Element?d.target:null;s.current=p!==null&&p.closest(`[data-panel-id="${Ye}"]`)===null,!o.current&&(u.current=p?.closest(`${ye}[${ne}]`)?.getAttribute(ne)??null)},m=d=>{d.relatedTarget instanceof Node&&!i.contains(d.relatedTarget)&&(s.current=!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",m),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",m)}},[t]);const l=r.useRef(e);r.useLayoutEffect(()=>{if(l.current===e)return;l.current=e;const i=t.current;if(i===null||!s.current)return;const f=m=>{const{activeElement:d,body:p}=i.ownerDocument;if(d!==null&&d!==p)return;const x=m.find(g=>g!==null);if(x!=null){o.current=!0;try{x.focus()}finally{o.current=!1}}};if(e){f([n.current]);return}queueMicrotask(()=>{if(l.current!==e||!s.current)return;const m=u.current,d=`[data-panel-id="${Re}"]`;f([m===null?null:ur(i,m),i.querySelector(`${d} ${cr}`),i.querySelector(`${d} ${ir}`),i.querySelector(`[data-resize-handle-id="${a}"]`)])})},[e,t,n,a])},mr=({view:e,explorer:t,content:n,contentCoversPage:a=!1,sheetDismissals:s=0,onDraggingChange:u})=>{const o=r.useRef(null),[l,i]=r.useState(null),f=r.useRef(null),m=r.useRef(null),{inlineSize:d,rootFontPixels:p}=dr(o,f),x=d!==null&&d<O.explorerSheetBelowPixels(p);return fr(x,{frameRef:o,sheetToggleRef:m,handleId:Qe(e)}),c.jsxs("div",{ref:o,className:"aqmx-split-frame","data-aqmx-explorer-mode":x?"sheet":"split",children:[c.jsx("span",{ref:f,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),x?c.jsx(sr,{explorer:t,toggleRef:m,covered:a,onNoticeSlotChange:i,dismissals:s}):null,c.jsx(Ge,{value:x?l:null,children:c.jsx(pr,{view:e,sheet:x,explorer:t,content:n,contentCoversPage:a,onDraggingChange:u,explorerMinPixels:O.explorerMinPixels(p)})})]})},pr=({view:e,sheet:t,explorer:n,content:a,contentCoversPage:s,onDraggingChange:u,explorerMinPixels:o})=>{const{viewSettings:l,labels:i}=R.useExplorer(),m=R.useViewSetting(E=>e==="tree"?E.treeExplorer:E.multiExplorer)??(e==="tree"?O.EXPLORER_DEFAULT_PERCENT:O.EXPLORER_MULTI_DEFAULT_PERCENT),d=r.useRef(null),p=r.useRef(null),x=r.useRef(!1),g=r.useRef(!1),[b,S]=r.useState(!1),P=r.useRef(u);r.useLayoutEffect(()=>{P.current=u},[u]);const k=r.useCallback(()=>{const E=d.current;if(E===null||E.length!==2)return;const[y=0,v=0]=E,j=y+v;if(j<=0||y<=0)return;const A=Math.min(O.EXPLORER_MAX_PERCENT,y/j*100);l.update(e==="tree"?{treeExplorer:A}:{multiExplorer:A})},[l,e]),T=r.useCallback(()=>{p.current!==null&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,k()},O.EXPLORER_WIDTH_PERSIST_DELAY_MS)},[k]);r.useEffect(()=>()=>{p.current!==null&&clearTimeout(p.current),g.current&&P.current?.(!1)},[]);const F=ar(),q=r.useCallback((E,y)=>{d.current=E;const[v=0,j=0]=E;E.length===2&&j>0&&S(v<=0),y.source==="keyboard"?T():y.source==="pointer"&&(x.current=!0)},[T]),L=r.useCallback(E=>{if(g.current=E,u?.(E),E){x.current=!1;return}x.current&&(x.current=!1,T())},[u,T]);return c.jsxs(pe.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:q,className:"aqmx-split","data-aqmx-split":e,children:[t?null:c.jsx(pe.Panel,{id:Re,defaultSize:{value:m,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:O.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:s,className:"aqmx-split-explorer",children:c.jsx(ve,{value:!b,children:n})}),t?null:c.jsx(pe.PanelResizeHandle,{id:Qe(e),thickness:F?O.COARSE_TARGET_PIXELS:O.FINE_TARGET_PIXELS,indicator:{visible:!0,thickness:O.SPLIT_HANDLE_PIXELS.gripThickness,length:O.SPLIT_HANDLE_PIXELS.gripLength,barThickness:O.SPLIT_HANDLE_PIXELS.barThickness,barLength:O.SPLIT_HANDLE_PIXELS.barLength},title:i.resizeExplorer,"aria-label":i.resizeExplorer,onDragging:L,inert:s,className:"aqmx-split-handle"}),c.jsx(pe.Panel,{id:Ye,defaultSize:{value:100-m,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...s?{style:{isolation:"auto"}}:{},children:a})]})};exports.EMPTY_SELECTION=he;exports.ExplorerPane=er;exports.ExplorerSplit=mr;exports.SheetNoticeSlotContext=Ge;
|
|
1
|
+
"use strict";const c=require("react/jsx-runtime"),R=require("./index-Dn7cYy-4.cjs"),r=require("react"),O=require("./location-D6RE3wAN.cjs"),_e=require("@aiquants/directory-tree"),dt=require("./tapScrollCircle-C5DGI-0H.cjs"),ft=require("./storage-Dgi4JXaB.cjs"),pe=require("@aiquants/resize-panels"),mt=require("react-router");function pt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const h=pt(r);function ht({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15ZM9 12.75a.75.75 0 0 0 0 1.5h6a.75.75 0 0 0 0-1.5H9Z",clipRule:"evenodd"}))}const xt=h.forwardRef(ht);function wt({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15Zm-6.75-10.5a.75.75 0 0 0-1.5 0v2.25H9a.75.75 0 0 0 0 1.5h2.25v2.25a.75.75 0 0 0 1.5 0v-2.25H15a.75.75 0 0 0 0-1.5h-2.25V10.5Z",clipRule:"evenodd"}))}const gt=h.forwardRef(wt);function Et({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M16.5 6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v7.5a3 3 0 0 0 3 3v-6A4.5 4.5 0 0 1 10.5 6h6Z"}),h.createElement("path",{d:"M18 7.5a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-7.5a3 3 0 0 1-3-3v-7.5a3 3 0 0 1 3-3H18Z"}))}const bt=h.forwardRef(Et);function vt({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3V6ZM3 15.75a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-2.25Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3v-2.25Z",clipRule:"evenodd"}))}const Rt=h.forwardRef(vt),yt=()=>{const{notices:e}=R.useExplorer(),t=r.use(e);return t.length===0?null:c.jsx("div",{className:"aqmx-explorer-notices",children:t.map(n=>c.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":n.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":n.id,children:[c.jsx("p",{className:"aqmx-callout-title",children:n.title}),n.body===void 0?null:c.jsx("p",{className:"aqmx-callout-body",children:n.body}),n.action===void 0?null:c.jsx("a",{className:"aqmx-callout-action",href:n.action.href,children:n.action.label})]},n.id))})};function St({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.912 3a3 3 0 0 0-2.868 2.118l-2.411 7.838a3 3 0 0 0-.133.882V18a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3v-4.162c0-.299-.045-.596-.133-.882l-2.412-7.838A3 3 0 0 0 17.088 3H6.912Zm13.823 9.75-2.213-7.191A1.5 1.5 0 0 0 17.088 4.5H6.912a1.5 1.5 0 0 0-1.434 1.059L3.265 12.75H6.11a3 3 0 0 1 2.684 1.658l.256.513a1.5 1.5 0 0 0 1.342.829h3.218a1.5 1.5 0 0 0 1.342-.83l.256-.512a3 3 0 0 1 2.684-1.658h2.844Z",clipRule:"evenodd"}))}const kt=h.forwardRef(St),ve=r.createContext(!0),Ie="\0loop\0",De="\0",Ct=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=o=>{const l=e.get(o);if(l!==void 0)return l;const i=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,i),i},s=(o,l,i)=>{let f=!1;const m=o.map(p=>{const x=u(p,l,i);return x!==p&&(f=!0),x});if(!f)return o;const d=n.get(o);return d!==void 0&&d.length===m.length&&d.every((p,x)=>p===m[x])?d:(n.set(o,m),m)},u=(o,l,i)=>{if(o.type!=="directory")return o;if(i.has(o.path))return a(o);const f=o.lazy===!0?l(o.path):void 0,m=f?.status==="loaded",d=m?f.entries:o.children;if(d===void 0)return o;i.add(o.path);const p=s(d,l,i);if(i.delete(o.path),!m&&p===o.children)return o;const x=t.get(o);if(x!==void 0&&x.state===f&&x.children===p)return x.grafted;const g={...o,children:p,lazy:m?!1:o.lazy};return t.set(o,{state:f,children:p,grafted:g}),g};return(o,l)=>s(o,l,new Set)},Tt=(e,t)=>`${Ie}${e}${De}${t}`,ie=e=>e.startsWith(Ie),Lt=e=>e.slice(e.lastIndexOf(De)+1),ne="data-aqmx-path",jt=(e,t,n,a,s)=>{const u={aqmxPath:e.path};return e.modifiedAt!==void 0&&(u.aqmxModifiedAt=e.modifiedAt),n&&(u.aqmxOpen=!0),(a==="loading"||a==="failed")&&(u.aqmxChildren=a),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:s,data:u}},Nt=(e,t,n,a)=>{const s=Tt(t,e.path);return{name:n,type:"directory",absolutePath:s,relativePath:s,children:a,data:{aqmxLoop:e.path}}},Pt=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=[],s=(l,i,f)=>{const m=l.map(p=>p.type==="loop"?u(p,i,f):o(p,i)),d=n.get(l);return d!==void 0&&d.length===m.length&&d.every((p,x)=>p===m[x])?d:(n.set(l,m),m)},u=(l,i,f)=>{const m=t.get(l);if(m!==void 0&&m.parentKey===f&&m.loopFolderName===i.loopFolderName)return m.row;const d=Nt(l,f,i.loopFolderName(l.name),a);return t.set(l,{row:d,parentKey:f,loopFolderName:i.loopFolderName}),d},o=(l,i)=>{const f=l.type==="directory"?l.children===void 0?a:s(l.children,i,l.path):void 0,m=i.openPaths.has(l.path),d=l.type==="directory"&&l.lazy===!0?i.childrenOf(l.path)?.status:void 0,p=d==="failed"?i.renderFailedFolder:void 0,x=e.get(l);if(x!==void 0&&x.open===m&&x.childrenStatus===d&&x.children===f&&x.renderFailedFolder===p)return x.row;const g=jt(l,f,m,d,p===void 0?void 0:p(l));return e.set(l,{row:g,open:m,childrenStatus:d,children:f,renderFailedFolder:p}),g};return(l,i)=>s(l,i,"")},Ot=e=>{if(e===void 0)return;const t=n=>{const a=n.data?.aqmxModifiedAt;return typeof a=="number"?{name:n.name,path:n.absolutePath,type:n.type,modifiedAt:a}:{name:n.name,path:n.absolutePath,type:n.type}};return(n,a)=>e(t(n),t(a))},be=(e,t)=>{const n=e.filter(a=>a.type==="directory");return t===void 0?n:n.sort(t)},qt=(e,t)=>{const n=new Map;let a=0;const s=u=>{for(const o of be(u,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&s(o.children);continue}n.has(o.path)||(n.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(a+=1))}};return s(e),{folders:n,waiting:a}},At=e=>{const t=new Set,n=a=>{for(const s of a)s.type==="directory"&&(s.lazy===!0&&t.add(s.path),s.children!==void 0&&n(s.children))};return n(e),t},He=(e,t)=>{for(const n of e){if(n.type!=="directory")continue;if(n.path===t)return n;const a=n.children===void 0?null:He(n.children,t);if(a!==null)return a}return null},Mt=(e,t,n,a)=>{let s=e;for(const u of t){const o=s.find(l=>l.type==="directory"&&l.path===u);if(o===void 0)return"missing";if(o.lazy===!0)return a.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!a.isShownExpanded(o.path))return"loading";s=o.children??[]}return s.some(u=>u.type==="file"&&u.path===n)?"ready":"missing"},Pe=new Set,Ft=(e,t)=>e.has(t)?e:new Set(e).add(t),_t=(e,t)=>{if(!t.some(a=>e.has(a)))return e;const n=new Set(t);return new Set([...e].filter(a=>!n.has(a)))},It=(e,t)=>[...e].every(n=>t.has(n))?e:new Set([...e].filter(n=>t.has(n))),Dt=()=>{const[e,t]=r.useState(Pe),n=r.useCallback(o=>t(l=>Ft(l,o)),[]),a=r.useCallback(o=>t(l=>_t(l,o)),[]),s=r.useCallback(o=>t(l=>It(l,o)),[]),u=r.useCallback(()=>t(Pe),[]);return r.useMemo(()=>({direct:e,markDirect:n,unmarkDirect:a,pruneDirect:s,clearDirect:u}),[e,n,a,s,u])},Ht=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),Zt=(e,t)=>{const n=[];let a=be(t.entries,t.compare);for(let s=1;a.length>0;s+=1){const u=[];for(const o of a){const{path:l}=o;if(t.isShownExpanded(l))e.handled.add(l);else{if(e.handled.has(l))continue;if(e.handled.add(l),o.lazy===!0&&t.childrenOf(l)===void 0){if(s>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(l)}n.push(l),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&u.push(...be(o.children,t.compare))}a=u}return n},Ze=(e,t)=>e.every(n=>n.type!=="directory"||t(n.path)&&(n.lazy===!0||n.children===void 0||Ze(n.children,t))),$t=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let n=0;for(const a of e.loads)t.childrenOf(a)?.status==="failed"&&(n+=1);return{kind:"done",opened:e.opened,failed:n,complete:Ze(t.entries,t.isShownExpanded)}},Ee=Object.freeze({state:"idle"}),Bt=e=>{const t=r.useRef(null),n=r.useRef(e),[a,s]=r.useState(Ee);r.useLayoutEffect(()=>{n.current=e});const u=r.useCallback(()=>{t.current===null&&(t.current=Ht(n.current.budget),s({state:"running",opened:0}))},[]),o=r.useCallback(()=>{t.current=null,s(Ee)},[]),l=r.useCallback(i=>{const f=t.current;if(f===null)return;const m=Zt(f,i);if(m.length>0&&(f.issuedAgainst=i.expanded,n.current.expandMultiple([...m])),!f.announcedStart&&(f.loads.size>0||i.waiting>0)&&(f.announcedStart=!0,n.current.onStart()),m.length===0&&!i.expansionPending&&i.expanded!==f.issuedAgainst&&i.waiting===0){t.current=null;const p=$t(f,i);s(p.kind==="done"?Ee:{state:"stopped",stop:p.kind,opened:p.opened}),n.current.onFinish(p);return}const{opened:d}=f;s(p=>p.state==="running"&&p.opened===d?p:{state:"running",opened:d})},[]);return r.useMemo(()=>({status:a,start:u,end:o,advance:l}),[a,u,o,l])},Oe=["pointerdown","wheel","touchstart","keydown","focusin"],zt=8,qe={least:Number.POSITIVE_INFINITY,stalled:0},Vt=({tree:e,container:t,path:n,chain:a,rows:s,cancel:u,displayed:o,placement:l})=>{const i=r.useRef(null),f=r.useRef(!0),m=r.useRef(qe),d=r.useRef(null),p=r.useRef(null),x=r.useRef(a),g=r.useRef(l);r.useLayoutEffect(()=>{x.current=a,g.current=l},[a,l]);const b=r.useCallback(()=>{const L=d.current;L!==null&&(d.current=null,L.phase==="asking"?L.controller.abort():x.current?.open(null))},[]),S=r.useCallback(()=>{i.current=null,b()},[b]),P=r.useCallback(()=>{const L=t.current;i.current===null||p.current!==null||L===null||L.getClientRects().length===0||(p.current=requestAnimationFrame(()=>{p.current=null;const E=i.current;if(E===null)return;const y=g.current(E);if(y===0){f.current=!0,d.current?.phase==="opening"&&b();return}if(e.current?.scrollToPath(E,{align:"nearest"})===!0){d.current?.phase==="opening"&&b();const{least:j,stalled:A}=m.current;m.current=y<j?{least:y,stalled:0}:{least:j,stalled:A+1},m.current.stalled<zt&&P();return}const v=d.current;if(v===null){i.current=null;return}v.phase==="opening"&&x.current?.progress(v.folders,E)!=="loading"&&S()}))},[e,t,b,S]),k=r.useCallback(()=>{f.current=!1,m.current=qe,P()},[P]);r.useEffect(()=>{const L=t.current;if(L===null)return;const E=typeof ResizeObserver>"u"?null:new ResizeObserver(k);E?.observe(L);for(const y of Oe)L.addEventListener(y,S,{passive:!0});return()=>{E?.disconnect();for(const y of Oe)L.removeEventListener(y,S);p.current!==null&&cancelAnimationFrame(p.current),p.current=null,b()}},[t,k,S,b]);const T=a!==null;r.useEffect(()=>{const L=t.current;if(S(),n===null||L===null||L.contains(L.ownerDocument.activeElement))return;i.current=n;const E=x.current;if(T&&E!==null){const y=new AbortController,v={phase:"asking",controller:y};d.current=v,E.ancestors(n,y.signal).then(j=>{d.current===v&&(j===null?d.current=null:(d.current={phase:"opening",folders:j},x.current?.open(j)),k())})}k()},[n,T,t,S,k]),r.useEffect(()=>{(d.current?.phase==="opening"||i.current!==null&&!f.current)&&k()},[s,k]);const F=r.useRef(u);r.useEffect(()=>{F.current!==u&&(F.current=u,S())},[u,S]);const q=r.useRef(o);r.useEffect(()=>{q.current&&!o&&b(),q.current=o},[o,b])},Kt="--aqmx-tree-line",Xt=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Wt="data-aqmx-tree-probe",Ut=Object.freeze({rowHeight:O.CONTROL_BLOCK_PIXELS,lineColor:null}),Gt=/^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/u,Yt=e=>{const t=Gt.exec(e);return t===null?e:`#${t.slice(1).map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`},Qt=(e,t)=>{const[n,a]=r.useState(Ut);return r.useLayoutEffect(()=>{const s=e.current;if(s===null)return;const u=()=>{const i=Math.round(s.getBoundingClientRect().height),f=getComputedStyle(s),m=f.getPropertyValue(Kt).trim()===""?null:Yt(f.color);a(d=>{const p=Number.isFinite(i)&&i>0?i:d.rowHeight;return d.rowHeight===p&&d.lineColor===m?d:{rowHeight:p,lineColor:m}})};u();const o=Xt.map(i=>window.matchMedia(i));for(const i of o)i.addEventListener("change",u);const l=typeof ResizeObserver>"u"?null:new ResizeObserver(u);return l?.observe(s),()=>{for(const i of o)i.removeEventListener("change",u);l?.disconnect()}},[e,t]),n},$e="markdown-explorer-tree-scroll",Jt=.5,Be=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${ne}]`)].find(n=>n.getAttribute(ne)===t),en=(e,t)=>{const n=Be(e,t),a=n?.closest(`[data-testid="${$e}"]`);if(n===void 0||a===null||a===void 0)return Number.POSITIVE_INFINITY;const s=a.getBoundingClientRect(),u=n.getBoundingClientRect(),o=s.top-u.top,l=u.height>s.height?Math.abs(o):Math.max(0,o)+Math.max(0,u.bottom-s.bottom);return l<=Jt?0:l},tn={testId:$e,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:{width:8,enableTrackClick:!0,enableThumbDrag:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:dt.TAP_SCROLL_CIRCLE},behaviorOptions:{enablePointerDrag:!0}},nn={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},rn={color:"inherit"},an={paddingBlock:0},ln=new Set,on=new Map,sn={color:"var(--aqmx-tree-line)"},cn=e=>{const t=e instanceof Element?e.closest(`[${ne}]`):null;return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(ne)},ze=(e,t,n,a)=>n==="folder-limit"?e.expandAllFolderLimit(a,t.maxFolders,e.expandAll):e.expandAllDepthLimit(a,t.maxDepth),un=(e,t,n)=>n.kind==="done"?e.expandAllDone(n.opened,n.failed,n.complete):ze(e,t,n.kind,n.opened),Ve=()=>{const{labels:e}=R.useExplorer();return c.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[c.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),c.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{})]})]})},dn=()=>{const{labels:e}=R.useExplorer();return c.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[c.jsx(kt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),c.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),c.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},fn=({name:e,onRetry:t})=>{const{labels:n}=R.useExplorer(),a=r.useId();return c.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[c.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),c.jsx("span",{id:a,className:"aqmx-explorer-folder-error",children:n.folderLoadFailed}),c.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":a,"data-testid":"markdown-explorer-folder-retry",onClick:s=>{s.stopPropagation();const u=s.currentTarget,o=u.ownerDocument.activeElement===u?u.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&R.focusWithoutScroll(o),t()},onKeyDown:s=>{s.key!=="Escape"&&s.stopPropagation()},children:[c.jsx(R.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:n.retry})]})]})},mn=({entries:e,version:t,mode:n,sourceId:a,settings:s,reveal:u,openPaths:o,selection:l,onOpenDocument:i,onRevealSource:f,expansion:m,onShown:d,marks:p,claimsHeld:x,expandAll:g,revealCancel:b})=>{const{trees:S,documents:P,labels:k,locale:T,theme:F,data:q,config:L,sources:E,reveals:y}=R.useExplorer(),v=r.use(ve),[j]=r.useState(Pt),A=r.useRef(null),{rowHeight:le,lineColor:z}=Qt(A,F),{isExpanded:_,toggle:U,expandMultiple:Z,collapseMultiple:J,expanded:D,isPending:ee}=m,{alwaysExpanded:V,sortMode:M,folderPlacement:$}=s,{direct:oe,markDirect:B,unmarkDirect:re,pruneDirect:se}=p,{running:te,advance:ue}=g,ce=r.useRef(null),G=r.useRef(null),C=r.useMemo(()=>O.createEntryComparator({sortMode:M,folderPlacement:$}),[M,$]),K=r.useMemo(()=>Ot(C),[C]),I=r.useCallback(w=>S.children(a,w),[S,a]),Y=r.useMemo(()=>At(e),[e]),Q=r.useCallback(w=>!ie(w)&&(_(w)||V&&!Y.has(w)),[_,V,Y]),X=r.useRef({shownExpanded:Q,isExpanded:_,unloadedFolders:Y,entries:e,childrenOf:I});r.useLayoutEffect(()=>{X.current={shownExpanded:Q,isExpanded:_,unloadedFolders:Y,entries:e,childrenOf:I}},[Q,_,Y,e,I]);const Se=r.useCallback(w=>{ce.current?.scrollToPath(w,{align:"nearest"}),requestAnimationFrame(()=>{const N=G.current,H=N===null?void 0:Be(N,w);H!==void 0&&R.focusWithoutScroll(H)})},[]),Je=r.useCallback(w=>{if(ie(w)){Se(Lt(w));return}X.current.isExpanded(w)?re([w]):X.current.unloadedFolders.has(w)&&B(w),U(w)},[Se,B,re,U]),xe=r.useCallback(w=>{const N=w.filter(H=>!ie(H));N.length!==0&&(re(N),J(N))},[re,J]),et=r.useCallback(w=>{const N=w.filter(H=>!ie(H));N.length!==0&&(N.length<w.length&&N.every(H=>X.current.shownExpanded(H))?xe(N):Z(N))},[Z,xe]),ke=r.useCallback(w=>c.jsx(fn,{name:w.name,onRetry:()=>{B(w.path),S.retryChildren(a,w.path),X.current.shownExpanded(w.path)||Z([w.path])}}),[S,a,B,Z]),Ce=n==="multi"?o:ln,{loopFolderName:Te}=k,tt=r.useMemo(()=>j(e,{openPaths:Ce,childrenOf:I,renderFailedFolder:ke,loopFolderName:Te}),[j,e,Ce,I,ke,Te,t]),nt=R.useIntentPrefetch(P,cn),Le=r.useRef([]),de=r.useCallback(()=>{for(const w of Le.current)X.current.unloadedFolders.has(w)&&B(w)},[B]),{maxDepth:we}=L.revealDocument,je=r.useRef(f);r.useLayoutEffect(()=>{je.current=f},[f]);const rt=r.useMemo(()=>({ancestors:async(w,N)=>{const H=y.take(a,w);if(H!==null)return H;if(!y.mayMove(w)){const ae=await q.ancestors(a,w,N);return ae.status!=="ok"||ae.ancestors===null||ae.ancestors.length>we?null:ae.ancestors}const W=await q.reveal(a,w,N);return W.status!=="ok"||W.source===null||W.ancestors.length>we?null:W.source===a?W.ancestors:(N.aborted||!E.some(ae=>ae.id===W.source)||(y.move(W.source,w,W.ancestors),je.current(W.source)),null)},open:w=>{Le.current=w??[],w!==null&&(de(),Z([...w]))},progress:(w,N)=>Mt(X.current.entries,w,N,{isShownExpanded:X.current.shownExpanded,childrenOf:X.current.childrenOf})}),[q,a,E,y,we,de,Z]);r.useEffect(()=>de(),[de,Y]);const at=r.useMemo(()=>[e,t,D],[e,t,D]),lt=r.useCallback(w=>G.current===null?Number.POSITIVE_INFINITY:en(G.current,w),[]);Vt({tree:ce,container:G,path:u.path,chain:u.openFolders?rt:null,rows:at,cancel:b,displayed:v,placement:lt});const Ne=r.useCallback(w=>oe.has(w),[oe]),fe=r.useMemo(()=>qt(e,{isShownExpanded:Q,childrenOf:I,compare:C,isDirect:Ne}),[e,Q,I,C,Ne,t]),me=v&&x;r.useLayoutEffect(()=>{d(e)},[e,d]),r.useLayoutEffect(()=>()=>d(null),[d]),r.useEffect(()=>S.claimChildren(a,me?fe.folders:on),[S,a,me,fe]),r.useEffect(()=>se(Y),[se,Y]),r.useEffect(()=>{me&&te&&ue({entries:e,isShownExpanded:Q,childrenOf:I,compare:C,expanded:D,waiting:fe.waiting,expansionPending:ee})},[me,te,ue,e,Q,I,C,D,fe,ee]);const ot=r.useCallback(w=>{w.isDirectory||(y.settle(w.entry.absolutePath),i(w.entry.absolutePath))},[y,i]),{onChange:ge}=l,st=r.useMemo(()=>ge===null?void 0:(w,N)=>{ie(w.absolutePath)||ge({path:w.absolutePath,name:w.name,selected:N})},[ge]),ct=r.useMemo(()=>new Set(l.items),[l.items]),it=r.useMemo(()=>({entryKindDirectory:k.treeEntryKindDirectory,entryKindFile:k.treeEntryKindFile,scrollUp:k.treeScrollUp,scrollDown:k.treeScrollDown,scrollToTop:k.treeScrollToTop,scrollToBottom:k.treeScrollToBottom}),[k]),ut=z===null?{showTreeLines:!1}:{showTreeLines:s.lines,lineColor:z};return c.jsxs("div",{ref:G,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",...nt,children:[c.jsx("span",{ref:A,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Wt]:""}),c.jsx(_e.DirectoryTree,{ref:ce,entries:tt,expansion:{toggle:Je,isExpanded:Q,expandMultiple:et,collapseMultiple:xe,isPending:ee&&!te,doubleClickAction:s.doubleClickAction},selection:{mode:l.mode,selectedPath:l.shownPath,currentPath:l.shownPath,selectedItems:ct,onEntryClick:ot,onSelectionChange:st},visual:{className:"aqmx-explorer-tree-view",ariaLabel:k.treeRegion,...ut,showExpandIcons:s.expandIcons,expandIconStyle:sn,showDirectoryIcons:s.directoryIcons,showFileIcons:s.fileIcons,expandIconSize:s.expandIconSize,itemHeight:le,removeRootIndent:s.removeRootIndent,highlightStyles:nn,entryStyle:an,nameStyle:rn},virtualScroll:tn,sort:K,locale:T,labels:it})]})},pn=({pending:e,status:t})=>{const{labels:n}=R.useExplorer(),a=t.state!=="running",[s,u]=r.useState(0),o=r.useRef(!0);r.useLayoutEffect(()=>{const i=o.current;if(o.current=a,!a||e>0&&!i){u(0);return}if(e>0){u(e);return}if(s===0)return;const f=setTimeout(()=>u(0),0);return()=>clearTimeout(f)},[a,e,s]);const l=a&&e===0?s:e;return l===0&&a?null:c.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(l),"data-aqmx-expand-all":t.state,children:[l>0?c.jsx(R.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,c.jsx("span",{children:t.state==="running"?n.expandAllProgress(t.opened,l):n.foldersLoading(l)})]})},hn=({stop:e,opened:t,budget:n})=>{const{labels:a}=R.useExplorer();return c.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:ze(a,n,e,t)})},xn=({entries:e,...t})=>{const{trees:n}=R.useExplorer(),a=r.useSyncExternalStore(n.subscribe,n.version,n.version),{sourceId:s}=t,[u]=r.useState(Ct),o=r.useMemo(()=>u(e,l=>n.children(s,l)),[u,e,n,s,a]);return o.length===0?c.jsx(dn,{}):c.jsx(mn,{entries:o,version:a,...t})},wn=({result:e,onRetry:t,...n})=>{const{renderTreeFailure:a}=R.useExplorer(),s=r.use(e);if(s.status==="deferred")return c.jsx(Ve,{});if(s.status==="ok")return c.jsx(xn,{entries:s.entries,...n});const u=a?.(s.failure);return c.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":s.failure.reason,children:u!==void 0?u:c.jsx(R.FailureView,{failure:s.failure,alert:!0,onRetry:t,testId:null})})},gn=({onControls:e,...t})=>{const{trees:n,storageNamespace:a,labels:s,announcer:u,config:o}=R.useExplorer(),{sourceId:l}=t,i=_e.useDirectoryTreeState({storageKey:ft.storageKeys(a).treeExpansion(l)});r.useSyncExternalStore(n.subscribe,n.version,n.version);const f=n.read(l),m=r.useCallback(()=>n.retry(l),[n,l]);r.useLayoutEffect(()=>n.open(l),[n,l]);const d=Dt(),{expanded:p,expandMultiple:x,collapseAll:g}=i,[b,S]=r.useState(null),P=b!==p,k=r.useRef(p);r.useLayoutEffect(()=>{k.current=p},[p]);const T=o.expandAll,F=r.useCallback(()=>u.announce(s.expandAllStarted),[u,s]),q=r.useCallback(M=>u.announce(un(s,T,M)),[u,s,T]),L=Bt({budget:T,expandMultiple:x,onStart:F,onFinish:q}),{status:E,start:y,end:v,advance:j}=L,A=E.state==="running",le=r.useMemo(()=>({running:A,advance:j}),[A,j]),z=r.useRef(null),[_,U]=r.useState(!1),Z=r.useCallback(M=>{z.current=M,U(M!==null)},[]);r.useEffect(()=>n.subscribeChildrenFailures(M=>{const $=M.sourceId===l&&z.current!==null?He(z.current,M.path):null;$!==null&&u.announce({list:s.foldersLoadFailedNamed,item:$.name})}),[n,l,u,s]);const{clearDirect:J}=d,[D,ee]=r.useState(0),V=r.useCallback(()=>{ee(M=>M+1),v(),J(),S(k.current),g()},[v,J,g]);return r.useEffect(()=>{e({collapseAll:V,expandAll:_?y:null,expanding:A})},[e,V,y,_,A]),r.useEffect(()=>()=>e(null),[e]),r.useEffect(()=>{_||v()},[_,v]),c.jsxs(c.Fragment,{children:[E.state==="stopped"?c.jsx(hn,{stop:E.stop,opened:E.opened,budget:T}):null,c.jsxs("div",{className:"aqmx-explorer-tree-area",children:[c.jsx(r.Suspense,{fallback:c.jsx(Ve,{}),children:c.jsx(wn,{result:f,onRetry:m,expansion:i,onShown:Z,marks:d,claimsHeld:P,expandAll:le,revealCancel:D,...t})}),c.jsx(pn,{pending:n.pendingChildren(l),status:E})]})]})};function En({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.47 5.47a.75.75 0 0 1 1.06 0L12 10.94l5.47-5.47a.75.75 0 1 1 1.06 1.06L13.06 12l5.47 5.47a.75.75 0 1 1-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 0 1-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const Ke=h.forwardRef(En),Ae="markdown-explorer-selection-remove",bn=({selection:e,onRemove:t,onClear:n,onOpenSelection:a,onLeave:s})=>{const{labels:u}=R.useExplorer(),o=r.useId(),l=r.useRef(null),i=[...e],f=(d,p)=>{if(p.ownerDocument.activeElement===p){const x=l.current===null?[]:[...l.current.querySelectorAll(`[data-testid="${Ae}"]`)],g=x.indexOf(p),b=[x[g+1],x[g-1]].find(S=>S!==void 0);b===void 0?s():b.focus()}t(d)},m=()=>{const d=l.current;d!==null&&d.contains(d.ownerDocument.activeElement)&&s(),n()};return c.jsxs("section",{ref:l,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[c.jsxs("div",{className:"aqmx-explorer-tray-header",children:[c.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:u.selectionTitle(i.length)}),c.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:m,children:u.clearSelection})]}),c.jsx("ul",{className:"aqmx-explorer-tray-list",children:i.map(([d,p])=>c.jsxs("li",{className:"aqmx-explorer-tray-item",children:[c.jsx("span",{className:"aqmx-explorer-tray-name",title:d,children:p}),c.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":u.removeFromSelection(p),title:u.removeFromSelection(p),"data-testid":Ae,"data-aqmx-path":d,onClick:x=>f(d,x.currentTarget),children:c.jsx(Ke,{"aria-hidden":"true"})})]},d))}),a===void 0?null:c.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>a(i.map(([d])=>d)),children:u.openSelectionInMulti(i.length)})]})},he=new Map,vn=(e,t)=>{if(t.selected===e.has(t.path))return e;const n=new Map(e);return t.selected?n.set(t.path,t.name):n.delete(t.path),n},Rn=(e,t)=>{if(!e.has(t))return e;const n=new Map(e);return n.delete(t),n},Xe=r.createContext(null),yn=e=>{const t=r.use(Xe);r.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Sn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M15 3.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0V5.56l-3.97 3.97a.75.75 0 1 1-1.06-1.06l3.97-3.97h-2.69a.75.75 0 0 1-.75-.75Zm-12 0A.75.75 0 0 1 3.75 3h4.5a.75.75 0 0 1 0 1.5H5.56l3.97 3.97a.75.75 0 0 1-1.06 1.06L4.5 5.56v2.69a.75.75 0 0 1-1.5 0v-4.5Zm11.47 11.78a.75.75 0 1 1 1.06-1.06l3.97 3.97v-2.69a.75.75 0 0 1 1.5 0v4.5a.75.75 0 0 1-.75.75h-4.5a.75.75 0 0 1 0-1.5h2.69l-3.97-3.97Zm-4.94-1.06a.75.75 0 0 1 0 1.06L5.56 19.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75v-4.5a.75.75 0 0 1 1.5 0v2.69l3.97-3.97a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const kn=h.forwardRef(Sn);function Cn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.97 2.47a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.25 4.81V16.5a.75.75 0 0 1-1.5 0V4.81L3.53 8.03a.75.75 0 0 1-1.06-1.06l4.5-4.5Zm9.53 4.28a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Tn=h.forwardRef(Cn);function Ln({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"}))}const jn=h.forwardRef(Ln);function Nn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M7.72 12.53a.75.75 0 0 1 0-1.06l7.5-7.5a.75.75 0 1 1 1.06 1.06L9.31 12l6.97 6.97a.75.75 0 1 1-1.06 1.06l-7.5-7.5Z",clipRule:"evenodd"}))}const Pn=h.forwardRef(Nn);function On({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.47 4.72a.75.75 0 0 1 1.06 0l3.75 3.75a.75.75 0 0 1-1.06 1.06L12 6.31 8.78 9.53a.75.75 0 0 1-1.06-1.06l3.75-3.75Zm-3.75 9.75a.75.75 0 0 1 1.06 0L12 17.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-3.75 3.75a.75.75 0 0 1-1.06 0l-3.75-3.75a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const qn=h.forwardRef(On);function An({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.078 2.25c-.917 0-1.699.663-1.85 1.567L9.05 4.889c-.02.12-.115.26-.297.348a7.493 7.493 0 0 0-.986.57c-.166.115-.334.126-.45.083L6.3 5.508a1.875 1.875 0 0 0-2.282.819l-.922 1.597a1.875 1.875 0 0 0 .432 2.385l.84.692c.095.078.17.229.154.43a7.598 7.598 0 0 0 0 1.139c.015.2-.059.352-.153.43l-.841.692a1.875 1.875 0 0 0-.432 2.385l.922 1.597a1.875 1.875 0 0 0 2.282.818l1.019-.382c.115-.043.283-.031.45.082.312.214.641.405.985.57.182.088.277.228.297.35l.178 1.071c.151.904.933 1.567 1.85 1.567h1.844c.916 0 1.699-.663 1.85-1.567l.178-1.072c.02-.12.114-.26.297-.349.344-.165.673-.356.985-.57.167-.114.335-.125.45-.082l1.02.382a1.875 1.875 0 0 0 2.28-.819l.923-1.597a1.875 1.875 0 0 0-.432-2.385l-.84-.692c-.095-.078-.17-.229-.154-.43a7.614 7.614 0 0 0 0-1.139c-.016-.2.059-.352.153-.43l.84-.692c.708-.582.891-1.59.433-2.385l-.922-1.597a1.875 1.875 0 0 0-2.282-.818l-1.02.382c-.114.043-.282.031-.449-.083a7.49 7.49 0 0 0-.985-.57c-.183-.087-.277-.227-.297-.348l-.179-1.072a1.875 1.875 0 0 0-1.85-1.567h-1.843ZM12 15.75a3.75 3.75 0 1 0 0-7.5 3.75 3.75 0 0 0 0 7.5Z",clipRule:"evenodd"}))}const Mn=h.forwardRef(An);function Fn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M12 1.5a.75.75 0 0 1 .75.75V4.5a.75.75 0 0 1-1.5 0V2.25A.75.75 0 0 1 12 1.5ZM5.636 4.136a.75.75 0 0 1 1.06 0l1.592 1.591a.75.75 0 0 1-1.061 1.06l-1.591-1.59a.75.75 0 0 1 0-1.061Zm12.728 0a.75.75 0 0 1 0 1.06l-1.591 1.592a.75.75 0 0 1-1.06-1.061l1.59-1.591a.75.75 0 0 1 1.061 0Zm-6.816 4.496a.75.75 0 0 1 .82.311l5.228 7.917a.75.75 0 0 1-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 0 1-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 0 1-1.247-.606l.569-9.47a.75.75 0 0 1 .554-.68ZM3 10.5a.75.75 0 0 1 .75-.75H6a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 10.5Zm14.25 0a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5H18a.75.75 0 0 1-.75-.75Zm-8.962 3.712a.75.75 0 0 1 0 1.061l-1.591 1.591a.75.75 0 1 1-1.061-1.06l1.591-1.592a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const _n=h.forwardRef(Fn);function In({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z",clipRule:"evenodd"}),h.createElement("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"}))}const Dn=h.forwardRef(In);function Hn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z"}))}const Zn=h.forwardRef(Hn);function $n({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.906 9c.382 0 .749.057 1.094.162V9a3 3 0 0 0-3-3h-3.879a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H6a3 3 0 0 0-3 3v3.162A3.756 3.756 0 0 1 4.094 9h15.812ZM4.094 10.5a2.25 2.25 0 0 0-2.227 2.568l.857 6A2.25 2.25 0 0 0 4.951 21H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-2.227-2.568H4.094Z"}))}const Bn=h.forwardRef($n);function zn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M10.5 3.75a6.75 6.75 0 1 0 0 13.5 6.75 6.75 0 0 0 0-13.5ZM2.25 10.5a8.25 8.25 0 1 1 14.59 5.28l4.69 4.69a.75.75 0 1 1-1.06 1.06l-4.69-4.69A8.25 8.25 0 0 1 2.25 10.5Zm8.25-3.75a.75.75 0 0 1 .75.75v2.25h2.25a.75.75 0 0 1 0 1.5h-2.25v2.25a.75.75 0 0 1-1.5 0v-2.25H7.5a.75.75 0 0 1 0-1.5h2.25V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Vn=h.forwardRef(zn);function Kn({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M5.625 3.75a2.625 2.625 0 1 0 0 5.25h12.75a2.625 2.625 0 0 0 0-5.25H5.625ZM3.75 11.25a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75ZM3 15.75a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75ZM3.75 18.75a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75Z"}))}const Xn=h.forwardRef(Kn),Wn=Object.freeze({sortMode:Tn,folderPlacement:Zn,selectionMode:jn,doubleClickAction:_n,expandIconSize:Vn,alwaysExpanded:kn,revealDocument:R.ForwardRef$1,removeRootIndent:Pn,lines:Xn,expandIcons:qn,directoryIcons:Bn,fileIcons:Dn}),We=(e,t)=>{const n=e[t.labelKey];if(typeof n!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is a ${typeof n}`);return n},Un=({id:e,settings:t,descriptors:n,onAdvance:a,onClose:s,ref:u})=>{const{labels:o}=R.useExplorer(),l=r.useRef([]);r.useEffect(()=>{l.current[0]?.focus()},[]);const i=r.useCallback(m=>{const d=n.length;l.current[(m%d+d)%d]?.focus()},[n.length]),f=r.useCallback((m,d)=>{switch(m.key){case"ArrowDown":m.preventDefault(),i(d+1);break;case"ArrowUp":m.preventDefault(),i(d-1);break;case"Home":m.preventDefault(),i(0);break;case"End":m.preventDefault(),i(n.length-1);break;case"Escape":R.consumeKey(m),s();break;case"Tab":s();break}},[n.length,i,s]);return c.jsx("div",{ref:u,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:n.map((m,d)=>{const p=Wn[m.key],x=We(o,m),g=O.formatTreeSettingValue(o,t,m.key),b=t[m.key],S=typeof b=="boolean"?{role:"menuitemcheckbox","aria-checked":b,"aria-label":x}:{role:"menuitem","aria-label":`${x}: ${g}`};return c.jsxs("button",{ref:P=>{l.current[d]=P},type:"button",tabIndex:-1,...S,title:`${x}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":m.key,onClick:()=>a(m),onKeyDown:P=>f(P,d),children:[c.jsx(p,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-menu-name",children:x}),c.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},m.key)})})},Gn=({settings:e,descriptors:t,onAdvance:n})=>{const{labels:a,announcer:s}=R.useExplorer(),[u,o]=r.useState(!1),l=r.useRef(null),i=r.useRef(null),f=r.useRef(null),m=r.useId(),d=r.useCallback(()=>{l.current?.focus(),o(!1)},[]);r.useEffect(()=>{if(!u)return;const g=b=>{b.target instanceof Node&&(l.current?.contains(b.target)===!0||i.current?.contains(b.target)===!0)||(o(!1),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{f.current=null,(document.activeElement===null||document.activeElement===document.body)&&l.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[u]),r.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const p=r.useCallback(g=>{g.key!=="Escape"||!u||(R.consumeKey(g),d())},[u,d]),x=r.useCallback(g=>{const b=n(g.key);s.announce(a.settingAnnouncement(We(a,g),O.formatTreeSettingValue(a,b,g.key)))},[s,a,n]);return{trigger:c.jsx("button",{ref:l,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":u,"aria-controls":u?m:void 0,"aria-label":a.treeSettings,title:a.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:p,children:c.jsx(Mn,{"aria-hidden":"true"})}),menu:u?c.jsx(Un,{ref:i,id:m,settings:e,descriptors:t,onAdvance:x,onClose:d}):null}},Yn=()=>{const{treeSettings:e}=R.useExplorer();return{settings:r.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},Me=new Set,Qn='[role="tree"] [role="treeitem"][tabindex="0"]',Jn="[data-directory-tree-tab-stop]",er=e=>{const{mode:t,sourceId:n,currentPath:a,openPaths:s,onOpenDocument:u,onSourceChange:o,onRevealSource:l,viewSwitch:i}=e,{labels:f,sources:m,trees:d,documents:p,announcer:x,reveals:g}=R.useExplorer(),{settings:b,advance:S}=Yn(),P=r.useMemo(()=>O.visibleTreeSettingDescriptors(t==="tree"),[t]),k=t==="tree"&&b.selectionMode==="multiple";yn(k);const T=e.mode==="tree"?e.tray.onGatheredChange:null,F=e.mode==="tree"?e.onOpenSelection:void 0,q=e.mode==="tree"&&k?e.tray.gathered:he,L=r.useCallback(C=>{const K=S(C);return K.selectionMode!=="multiple"&&T?.(he),K},[S,T]),E=Gn({settings:b,descriptors:P,onAdvance:L}),y=r.useCallback(C=>T?.(K=>vn(K,C)),[T]),v=r.useCallback(C=>T?.(K=>Rn(K,C)),[T]),j=r.useCallback(()=>T?.(he),[T]),A=r.useRef(null),le=r.useCallback(()=>{const C=A.current;if(C===null)return;[Qn,Jn,'[data-testid="markdown-explorer-tree-settings"]'].map(I=>C.querySelector(I)).find(I=>I!==null)?.focus()},[]),z=r.useMemo(()=>new Set(q.keys()),[q]),_=r.useMemo(()=>a===null?Me:new Set([a]),[a]),U=r.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:s,shownPath:null,onChange:null};switch(b.selectionMode){case"single":return{mode:"single",items:_,shownPath:a,onChange:null};case"multiple":return{mode:"multiple",items:z,shownPath:a,onChange:y};case"none":return{mode:"none",items:Me,shownPath:null,onChange:null}}},[t,s,b.selectionMode,_,a,z,y]),Z=r.useMemo(()=>b.revealDocument?{path:a,openFolders:!0}:{path:U.shownPath,openFolders:!1},[b.revealDocument,a,U.shownPath]),J=r.useCallback(C=>{a!==null&&g.settle(a),o(C)},[a,g,o]),[D,ee]=r.useState(null),[V,M]=r.useState(!1),[$,oe]=r.useState(null),B=r.useRef(!1),re=r.useCallback(async()=>{if(!B.current){B.current=!0,M(!0),oe(null);try{const C=await d.refresh(n);if(C.status==="superseded")return;p.invalidate(),C.status==="failed"?oe({sourceId:n,failure:C.failure}):x.announce(f.treeRefreshed)}finally{B.current=!1,M(!1)}}},[d,p,n,x,f]),se=D===null?null:D.expandAll,te=D?.expanding===!0,ue=m.find(C=>C.id===n),ce=i.target==="multi"?Rt:bt,G=i.target==="multi"?f.switchToMulti:f.switchToTree;return c.jsxs("nav",{ref:A,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[c.jsxs("div",{className:"aqmx-explorer-header",children:[m.length>1?c.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:ue?.label,value:n,onChange:C=>J(C.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:m.map(C=>c.jsx("option",{value:C.id,children:C.label},C.id))}):null,c.jsxs("div",{className:"aqmx-explorer-actions",children:[c.jsx(R.ExplorerLink,{to:i.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":G,title:G,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":i.target,children:c.jsx(ce,{"aria-hidden":"true"})}),c.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":V,"aria-busy":V,"data-aqmx-busy":V?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{re()},children:[c.jsx(R.ForwardRef,{"aria-hidden":"true"}),c.jsx("span",{children:f.refreshTreeLabel})]}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":se===null||te,"aria-busy":te,"data-aqmx-busy":te?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>se?.(),children:c.jsx(gt,{"aria-hidden":"true"})}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":D===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>D?.collapseAll(),children:c.jsx(xt,{"aria-hidden":"true"})}),E.trigger]})]}),c.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[$!==null&&$.sourceId===n?c.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":$.failure.reason,children:f.treeRefreshFailed(R.failureTitleOf(f,$.failure.reason))}):null,c.jsx(r.Suspense,{fallback:null,children:c.jsx(yt,{})}),c.jsx(gn,{mode:t,sourceId:n,settings:b,reveal:Z,openPaths:s,selection:U,onOpenDocument:u,onRevealSource:l,onControls:ee},n),k&&q.size>0?c.jsx(bn,{selection:q,onRemove:v,onClear:j,onOpenSelection:F,onLeave:le}):null,E.menu]})]})},Ue="(pointer: coarse)",tr=e=>{const t=window.matchMedia(Ue);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},nr=()=>window.matchMedia(Ue).matches,rr=()=>!1,ar=()=>r.useSyncExternalStore(tr,nr,rr);function lr({title:e,titleId:t,...n},a){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":t},n),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z",clipRule:"evenodd"}))}const or=h.forwardRef(lr),sr=({explorer:e,toggleRef:t,covered:n,onNoticeSlotChange:a,dismissals:s})=>{const{labels:u}=R.useExplorer(),o=mt.useLocation(),{location:l}=R.useExplorerLocation(),[i,f]=r.useState(!1),[m,d]=r.useState({navigated:o,source:l.source}),[p,x]=r.useState(!1);m.navigated!==o&&(d({navigated:o,source:l.source}),m.source===l.source&&!p&&f(!1));const[g,b]=r.useState(s);g!==s&&(b(s),f(!1));const S=r.useRef(null),P=r.useRef(null),k=r.useRef(null),T=r.useRef(!1),F=r.useId();r.useLayoutEffect(()=>{const v=S.current;v!==null&&(i&&!v.open?(v.showModal(),P.current?.focus()):!i&&v.open&&(v.close(),t.current?.focus()),a(i?k.current:null))},[i,t,a]),r.useLayoutEffect(()=>()=>a(null),[a]);const q=r.useCallback(v=>{v.key!=="Escape"||v.defaultPrevented||(R.consumeKey(v),f(!1))},[]),L=r.useCallback(v=>{T.current=v.target===v.currentTarget},[]),E=r.useCallback(v=>{const j=T.current;T.current=!1,j&&v.target===v.currentTarget&&f(!1)},[]),y=r.useCallback(()=>{f(!1)},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"aqmx-sheet-bar",inert:n,children:c.jsxs("button",{ref:t,type:"button",className:"aqmx-sheet-toggle","aria-haspopup":"dialog","aria-expanded":i,"aria-controls":F,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>f(!0),children:[c.jsx(or,{"aria-hidden":"true"}),c.jsx("span",{children:u.showExplorer})]})}),c.jsx("dialog",{ref:S,id:F,className:"aqmx-sheet","aria-label":u.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:q,onPointerDown:L,onClick:E,onClose:y,children:c.jsxs("div",{className:"aqmx-sheet-panel",children:[c.jsxs("div",{className:"aqmx-sheet-header",children:[c.jsx("div",{ref:k,className:"aqmx-sheet-notice-slot"}),c.jsx("button",{ref:P,type:"button",className:"aqmx-sheet-close","aria-label":u.hideExplorer,title:u.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>f(!1),children:c.jsx(Ke,{"aria-hidden":"true"})})]}),c.jsx("div",{className:"aqmx-sheet-body",children:c.jsx(ve,{value:i,children:c.jsx(Xe,{value:x,children:e})})}),c.jsx(R.LiveRegion,{holds:i,testId:"markdown-explorer-sheet-announcer"})]})})]})},Ge=r.createContext(null),Re="aqmx-explorer",Ye="aqmx-content",ye='[role="tree"] [role="treeitem"]',cr=`${ye}[tabindex="0"]`,ir="[data-directory-tree-tab-stop]",ur=(e,t)=>{for(const n of e.querySelectorAll(`[data-panel-id="${Re}"] ${ye}`))if(n.getAttribute(ne)===t)return n;return null},Fe=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:O.ASSUMED_ROOT_FONT_PIXELS}),dr=(e,t)=>{const[n,a]=r.useState(()=>Fe(0,0));return r.useLayoutEffect(()=>{const s=e.current,u=t.current;if(s===null||u===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:s.getBoundingClientRect().width,rem:u.getBoundingClientRect().width},l=()=>{const f=Fe(o.frame,o.rem);a(m=>m.inlineSize===f.inlineSize&&m.rootFontPixels===f.rootFontPixels?m:f)};l();const i=new ResizeObserver(f=>{for(const m of f){const[d]=m.borderBoxSize;d!==void 0&&(m.target===s&&(o.frame=d.inlineSize),m.target===u&&(o.rem=d.inlineSize))}l()});return i.observe(s),i.observe(u),()=>i.disconnect()},[e,t]),n},Qe=e=>`aqmx-split-handle-${e}`,fr=(e,{frameRef:t,sheetToggleRef:n,handleId:a})=>{const s=r.useRef(!1),u=r.useRef(null),o=r.useRef(!1);r.useLayoutEffect(()=>{const i=t.current;if(i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const f=d=>{const p=d.target instanceof Element?d.target:null;s.current=p!==null&&p.closest(`[data-panel-id="${Ye}"]`)===null,!o.current&&(u.current=p?.closest(`${ye}[${ne}]`)?.getAttribute(ne)??null)},m=d=>{d.relatedTarget instanceof Node&&!i.contains(d.relatedTarget)&&(s.current=!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",m),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",m)}},[t]);const l=r.useRef(e);r.useLayoutEffect(()=>{if(l.current===e)return;l.current=e;const i=t.current;if(i===null||!s.current)return;const f=m=>{const{activeElement:d,body:p}=i.ownerDocument;if(d!==null&&d!==p)return;const x=m.find(g=>g!==null);if(x!=null){o.current=!0;try{x.focus()}finally{o.current=!1}}};if(e){f([n.current]);return}queueMicrotask(()=>{if(l.current!==e||!s.current)return;const m=u.current,d=`[data-panel-id="${Re}"]`;f([m===null?null:ur(i,m),i.querySelector(`${d} ${cr}`),i.querySelector(`${d} ${ir}`),i.querySelector(`[data-resize-handle-id="${a}"]`)])})},[e,t,n,a])},mr=({view:e,explorer:t,content:n,contentCoversPage:a=!1,sheetDismissals:s=0,onDraggingChange:u})=>{const o=r.useRef(null),[l,i]=r.useState(null),f=r.useRef(null),m=r.useRef(null),{inlineSize:d,rootFontPixels:p}=dr(o,f),x=d!==null&&d<O.explorerSheetBelowPixels(p);return fr(x,{frameRef:o,sheetToggleRef:m,handleId:Qe(e)}),c.jsxs("div",{ref:o,className:"aqmx-split-frame","data-aqmx-explorer-mode":x?"sheet":"split",children:[c.jsx("span",{ref:f,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),x?c.jsx(sr,{explorer:t,toggleRef:m,covered:a,onNoticeSlotChange:i,dismissals:s}):null,c.jsx(Ge,{value:x?l:null,children:c.jsx(pr,{view:e,sheet:x,explorer:t,content:n,contentCoversPage:a,onDraggingChange:u,explorerMinPixels:O.explorerMinPixels(p)})})]})},pr=({view:e,sheet:t,explorer:n,content:a,contentCoversPage:s,onDraggingChange:u,explorerMinPixels:o})=>{const{viewSettings:l,labels:i}=R.useExplorer(),m=R.useViewSetting(E=>e==="tree"?E.treeExplorer:E.multiExplorer)??(e==="tree"?O.EXPLORER_DEFAULT_PERCENT:O.EXPLORER_MULTI_DEFAULT_PERCENT),d=r.useRef(null),p=r.useRef(null),x=r.useRef(!1),g=r.useRef(!1),[b,S]=r.useState(!1),P=r.useRef(u);r.useLayoutEffect(()=>{P.current=u},[u]);const k=r.useCallback(()=>{const E=d.current;if(E===null||E.length!==2)return;const[y=0,v=0]=E,j=y+v;if(j<=0||y<=0)return;const A=Math.min(O.EXPLORER_MAX_PERCENT,y/j*100);l.update(e==="tree"?{treeExplorer:A}:{multiExplorer:A})},[l,e]),T=r.useCallback(()=>{p.current!==null&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,k()},O.EXPLORER_WIDTH_PERSIST_DELAY_MS)},[k]);r.useEffect(()=>()=>{p.current!==null&&clearTimeout(p.current),g.current&&P.current?.(!1)},[]);const F=ar(),q=r.useCallback((E,y)=>{d.current=E;const[v=0,j=0]=E;E.length===2&&j>0&&S(v<=0),y.source==="keyboard"?T():y.source==="pointer"&&(x.current=!0)},[T]),L=r.useCallback(E=>{if(g.current=E,u?.(E),E){x.current=!1;return}x.current&&(x.current=!1,T())},[u,T]);return c.jsxs(pe.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:q,className:"aqmx-split","data-aqmx-split":e,children:[t?null:c.jsx(pe.Panel,{id:Re,defaultSize:{value:m,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:O.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:s,className:"aqmx-split-explorer",children:c.jsx(ve,{value:!b,children:n})}),t?null:c.jsx(pe.PanelResizeHandle,{id:Qe(e),thickness:F?O.COARSE_TARGET_PIXELS:O.FINE_TARGET_PIXELS,indicator:{visible:!0,thickness:O.SPLIT_HANDLE_PIXELS.gripThickness,length:O.SPLIT_HANDLE_PIXELS.gripLength,barThickness:O.SPLIT_HANDLE_PIXELS.barThickness,barLength:O.SPLIT_HANDLE_PIXELS.barLength},title:i.resizeExplorer,"aria-label":i.resizeExplorer,onDragging:L,inert:s,className:"aqmx-split-handle"}),c.jsx(pe.Panel,{id:Ye,defaultSize:{value:100-m,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...s?{style:{isolation:"auto"}}:{},children:a})]})};exports.EMPTY_SELECTION=he;exports.ExplorerPane=er;exports.ExplorerSplit=mr;exports.SheetNoticeSlotContext=Ge;
|
|
@@ -1 +1 @@
|
|
|
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
|
+
"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-Dn7cYy-4.cjs"),re=require("./ExplorerSplit-Cjvy0JHP.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;
|