@aiquants/markdown-explorer 0.9.0 → 0.11.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 +17 -0
- package/README.md +6 -3
- package/dist/{EditSurface-DJ9pJlDd.js → EditSurface-BK_Pz_LF.js} +1 -1
- package/dist/{EditSurface-BQ5QAdDd.cjs → EditSurface-CfbYYXrc.cjs} +1 -1
- package/dist/ExplorerSplit-51frK8xf.cjs +1 -0
- package/dist/{ExplorerSplit-BwUurHbM.js → ExplorerSplit-DwlWWfRv.js} +216 -213
- package/dist/{MultiLayout-xWd9nYaD.cjs → MultiLayout-B4PtS45V.cjs} +1 -1
- package/dist/{MultiLayout-DPE2GP2T.js → MultiLayout-CeR_l6Rb.js} +4 -4
- package/dist/{NativeScrollBar-CwgalDjg.js → NativeScrollBar-CVWeTlHC.js} +1 -1
- package/dist/{NativeScrollBar-PBnODPEM.cjs → NativeScrollBar-Dp4YWBp7.cjs} +1 -1
- package/dist/{TreeLayout-DilrAILF.cjs → TreeLayout-D-NyhuVM.cjs} +1 -1
- package/dist/{TreeLayout-B3i_63hs.js → TreeLayout-min5AOhr.js} +3 -3
- package/dist/core/contracts.d.cts +1 -0
- package/dist/core/contracts.d.ts +1 -0
- package/dist/core/labels.d.cts +2 -0
- package/dist/core/labels.d.ts +2 -0
- package/dist/core/treeSettings.d.cts +2 -1
- package/dist/core/treeSettings.d.ts +2 -1
- package/dist/dataRoute-CIFFX5bd.cjs +1 -0
- package/dist/dataRoute-CU9CKP44.js +278 -0
- package/dist/{index-CPoNWk1T.js → index-BPj19kIo.js} +388 -384
- package/dist/index-DJ_FUtYM.cjs +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +14 -14
- package/dist/{location-Q4sgRrUm.js → location-BT23fKeh.js} +123 -112
- package/dist/location-LNl0QOXI.cjs +1 -0
- package/dist/{merge-DgAmnpnO.cjs → merge-AnqxGn__.cjs} +1 -1
- package/dist/{merge-D_qmtwWR.js → merge-hyUGPGbJ.js} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +717 -698
- package/docs/behavior/dom-hooks.md +2 -2
- package/docs/behavior/layout.md +2 -2
- package/docs/behavior/localization.md +1 -0
- package/docs/behavior/security.md +2 -1
- package/docs/behavior/url-contract.md +1 -0
- package/package.json +1 -1
- package/dist/ExplorerSplit-Brdh9fCW.cjs +0 -1
- package/dist/dataRoute-CcZ8PK00.cjs +0 -1
- package/dist/dataRoute-D1vE1wFW.js +0 -270
- package/dist/index-BBtIYTXJ.cjs +0 -13
- package/dist/location-DmzVAFvo.cjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),u=require("react"),j=require("./location-DmzVAFvo.cjs"),q=require("./index-BBtIYTXJ.cjs"),re=require("./ExplorerSplit-Brdh9fCW.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-Dgi4JXaB.cjs"),Ce=require("./dataRoute-CcZ8PK00.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-LNl0QOXI.cjs"),q=require("./index-DJ_FUtYM.cjs"),re=require("./ExplorerSplit-51frK8xf.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-Dgi4JXaB.cjs"),Ce=require("./dataRoute-CIFFX5bd.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,12 +1,12 @@
|
|
|
1
1
|
import { jsxs as ie, jsx as M } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as We, use as Te, useRef as q, useState as $, useLayoutEffect as F, useMemo as R, useSyncExternalStore as Ke, useCallback as I, memo as Je, useEffect as U, useImperativeHandle as Xe } from "react";
|
|
3
|
-
import { g as ce, e as ke, h as Ze, P as Qe, j as en } from "./location-
|
|
4
|
-
import { m as nn, u as J, n as tn, I as on, D as rn, c as ln, o as sn, L as Le } from "./index-
|
|
5
|
-
import { S as an, a as cn, b as un } from "./ExplorerSplit-
|
|
3
|
+
import { g as ce, e as ke, h as Ze, P as Qe, j as en } from "./location-BT23fKeh.js";
|
|
4
|
+
import { m as nn, u as J, n as tn, I as on, D as rn, c as ln, o as sn, L as Le } from "./index-BPj19kIo.js";
|
|
5
|
+
import { S as an, a as cn, b as un } from "./ExplorerSplit-DwlWWfRv.js";
|
|
6
6
|
import { SCROLL_AREA_SELECTOR as Ae, SCROLL_ROOT_SELECTOR as te, generateColumnIds as dn, sortColumnIds as Ie, generateColumnId as De, NO_PANEL_DRAG_ATTRIBUTE as mn, useDragDropColumns as fn, DEFAULT_DEBUG_CONFIG as he, DragDropLayout as pn } from "@aiquants/drag-drop-panels";
|
|
7
7
|
import { useNavigate as gn, useLocation as hn } from "react-router";
|
|
8
8
|
import { s as vn, r as wn, w as yn } from "./storage-BSthKLSG.js";
|
|
9
|
-
import {
|
|
9
|
+
import { C as Sn, i as xn } from "./dataRoute-CU9CKP44.js";
|
|
10
10
|
import { createPortal as En } from "react-dom";
|
|
11
11
|
import { HostedScrollArea as On } from "@aiquants/markdown";
|
|
12
12
|
import { N as bn } from "./scrollBarGeometry-DOBdGNV-.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import { ScrollBar as u } from "@aiquants/virtualscroll";
|
|
3
3
|
import { useCallback as p, useMemo as b, useSyncExternalStore as S } from "react";
|
|
4
|
-
import { u as h } from "./index-
|
|
4
|
+
import { u as h } from "./index-BPj19kIo.js";
|
|
5
5
|
import { N as m } from "./scrollBarGeometry-DOBdGNV-.js";
|
|
6
6
|
import { T, N as d } from "./tapScrollCircle-u4EXeLhx.js";
|
|
7
7
|
const l = (e) => ({ scrollTop: e.scrollTop, scrollHeight: e.scrollHeight, clientHeight: e.clientHeight }), f = (e, t) => e.scrollTop === t.scrollTop && e.scrollHeight === t.scrollHeight && e.clientHeight === t.clientHeight, v = (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),i=require("react"),d=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),i=require("react"),d=require("./index-DJ_FUtYM.cjs"),h=require("./scrollBarGeometry-C46jBtmM.cjs"),u=require("./tapScrollCircle-C5DGI-0H.cjs"),a=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),v=(e,t)=>e.scrollTop===t.scrollTop&&e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight,g=e=>{let t=a(e);return{getSnapshot:()=>t,subscribe:s=>{const o=()=>{const n=a(e);v(t,n)||(t=n,s())},r=typeof ResizeObserver>"u"?null:new ResizeObserver(o),c=()=>{if(r!==null){r.disconnect(),r.observe(e);for(const n of e.children)r.observe(n)}};c();const l=typeof MutationObserver>"u"?null:new MutationObserver(()=>{c(),o()});return l?.observe(e,{childList:!0}),e.addEventListener("scroll",o,{passive:!0}),o(),()=>{e.removeEventListener("scroll",o),l?.disconnect(),r?.disconnect()}}}},S=e=>{const t=i.useMemo(()=>g(e),[e]);return i.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)},p=(e,t)=>{const s=typeof t=="function"?t(e.scrollTop):t;return e.scrollTo({top:s,behavior:"instant"}),e.scrollTop},C=({scroller:e,withCircle:t})=>{const{locale:s}=d.useExplorer(),{scrollTop:o,scrollHeight:r,clientHeight:c}=S(e),l=i.useCallback(n=>p(e,n),[e]);return b.jsx(T.ScrollBar,{contentSize:r,viewportSize:c,scrollPosition:o,onScroll:l,scrollBarWidth:h.NATIVE_SCROLL_BAR_WIDTH,enableThumbDrag:!0,enableTrackClick:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,tapScrollCircleOptions:t?u.TAP_SCROLL_CIRCLE:u.NO_TAP_SCROLL_CIRCLE,locale:s})};exports.NativeScrollBar=C;exports.scrollScrollerTo=p;exports.useScrollerMetrics=S;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),s=require("react"),T=require("react-router"),a=require("./location-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),s=require("react"),T=require("react-router"),a=require("./location-LNl0QOXI.cjs"),l=require("./index-DJ_FUtYM.cjs"),p=require("./ExplorerSplit-51frK8xf.cjs"),q=new Set,C=({location:m})=>{const{config:r}=l.useExplorer(),t=l.useExplorerNavigate(),{hash:d}=T.useLocation(),{source:n,doc:e,overrides:c,markup:o}=m,[x,v]=s.useState(p.EMPTY_SELECTION),g=s.useMemo(()=>({gathered:x,onGatheredChange:v}),[x]),w=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:n,doc:u,overrides:c}),"browse"),[t,r,n,c]),S=s.useCallback(u=>t(a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o}),"switch-source"),[t,r,e,c,o]),E=s.useCallback(u=>t(`${a.explorerHref(r,{view:"tree",source:u,doc:e,overrides:c,markup:o})}${d}`,"browse"),[t,r,e,c,o,d]),k=s.useCallback(u=>{const h=a.canonicalMultiDocuments(r,u);t(a.explorerHref(r,{view:"multi",source:n,docs:h,markup:o&&e!==null&&h.includes(e)?[e]:[]}),"switch-view")},[t,r,n,e,o]),b=s.useMemo(()=>({href:a.explorerHref(r,e===null?{view:"multi",source:n}:{view:"multi",source:n,docs:[e],markup:o?[e]:[]}),target:"multi"}),[r,n,e,o]),f=s.useMemo(()=>({kind:"page",view:"tree",overrides:c,embed:{}}),[c]),P=l.usePageMarkupToggle(m);return i.jsx(p.ExplorerSplit,{view:"tree",explorer:i.jsx(p.ExplorerPane,{mode:"tree",sourceId:n,currentPath:e,openPaths:q,onOpenDocument:w,onSourceChange:S,onRevealSource:E,viewSwitch:b,tray:g,onOpenSelection:k}),content:i.jsxs("div",{className:"aqmx-document-column aqmx-tree-document",children:[e===null?null:i.jsx(l.DocumentRefreshBar,{path:e,placement:l.PAGE_DOCUMENT_REFRESH,markup:P}),i.jsx(l.DocumentPane,{path:e,markup:o,variant:f})]})})};exports.TreeLayout=C;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as u, jsxs as D } from "react/jsx-runtime";
|
|
2
2
|
import { useState as T, useMemo as m, useCallback as i } from "react";
|
|
3
3
|
import { useLocation as b } from "react-router";
|
|
4
|
-
import { e as c, c as C } from "./location-
|
|
5
|
-
import { u as M, a as N, b as O, D as R, P as _, c as G } from "./index-
|
|
6
|
-
import { E as H, a as L, b as j } from "./ExplorerSplit-
|
|
4
|
+
import { e as c, c as C } from "./location-BT23fKeh.js";
|
|
5
|
+
import { u as M, a as N, b as O, D as R, P as _, c as G } from "./index-BPj19kIo.js";
|
|
6
|
+
import { E as H, a as L, b as j } from "./ExplorerSplit-DwlWWfRv.js";
|
|
7
7
|
const q = /* @__PURE__ */ new Set(), U = ({ location: l }) => {
|
|
8
8
|
const { config: o } = M(), r = N(), { hash: p } = b(), { source: n, doc: e, overrides: s, markup: t } = l, [h, v] = T(H), w = m(() => ({ gathered: h, onGatheredChange: v }), [h]), g = i((a) => r(c(o, { view: "tree", source: n, doc: a, overrides: s }), "browse"), [r, o, n, s]), S = i((a) => r(c(o, { view: "tree", source: a, doc: e, overrides: s, markup: t }), "switch-source"), [r, o, e, s, t]), E = i((a) => r(`${c(o, { view: "tree", source: a, doc: e, overrides: s, markup: t })}${p}`, "browse"), [r, o, e, s, t, p]), x = i(
|
|
9
9
|
(a) => {
|
package/dist/core/contracts.d.ts
CHANGED
package/dist/core/labels.d.cts
CHANGED
|
@@ -103,6 +103,8 @@ export type MarkdownExplorerLabels = {
|
|
|
103
103
|
readonly sortNative: string;
|
|
104
104
|
readonly sortAscending: string;
|
|
105
105
|
readonly sortDescending: string;
|
|
106
|
+
readonly sortOldest: string;
|
|
107
|
+
readonly sortNewest: string;
|
|
106
108
|
readonly settingFolderPlacement: string;
|
|
107
109
|
readonly folderPlacementMixed: string;
|
|
108
110
|
readonly folderPlacementFirst: string;
|
package/dist/core/labels.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ export type MarkdownExplorerLabels = {
|
|
|
103
103
|
readonly sortNative: string;
|
|
104
104
|
readonly sortAscending: string;
|
|
105
105
|
readonly sortDescending: string;
|
|
106
|
+
readonly sortOldest: string;
|
|
107
|
+
readonly sortNewest: string;
|
|
106
108
|
readonly settingFolderPlacement: string;
|
|
107
109
|
readonly folderPlacementMixed: string;
|
|
108
110
|
readonly folderPlacementFirst: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarkdownExplorerLabels } from "./labels.cjs";
|
|
2
|
-
export type TreeSortMode = "native" | "asc" | "desc";
|
|
2
|
+
export type TreeSortMode = "native" | "asc" | "desc" | "oldest" | "newest";
|
|
3
3
|
export type TreeFolderPlacement = "mixed" | "first" | "last";
|
|
4
4
|
export type TreeDoubleClickAction = "recursive" | "toggle";
|
|
5
5
|
export type TreeSelectionMode = "single" | "multiple" | "none";
|
|
@@ -44,6 +44,7 @@ export type SortableEntry = {
|
|
|
44
44
|
readonly name: string;
|
|
45
45
|
readonly path: string;
|
|
46
46
|
readonly type: "file" | "directory";
|
|
47
|
+
readonly modifiedAt?: number;
|
|
47
48
|
};
|
|
48
49
|
export type EntryComparator = (left: SortableEntry, right: SortableEntry) => number;
|
|
49
50
|
export declare const createEntryComparator: (settings: Pick<TreeSettings, "sortMode" | "folderPlacement">) => EntryComparator | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarkdownExplorerLabels } from "./labels.js";
|
|
2
|
-
export type TreeSortMode = "native" | "asc" | "desc";
|
|
2
|
+
export type TreeSortMode = "native" | "asc" | "desc" | "oldest" | "newest";
|
|
3
3
|
export type TreeFolderPlacement = "mixed" | "first" | "last";
|
|
4
4
|
export type TreeDoubleClickAction = "recursive" | "toggle";
|
|
5
5
|
export type TreeSelectionMode = "single" | "multiple" | "none";
|
|
@@ -44,6 +44,7 @@ export type SortableEntry = {
|
|
|
44
44
|
readonly name: string;
|
|
45
45
|
readonly path: string;
|
|
46
46
|
readonly type: "file" | "directory";
|
|
47
|
+
readonly modifiedAt?: number;
|
|
47
48
|
};
|
|
48
49
|
export type EntryComparator = (left: SortableEntry, right: SortableEntry) => number;
|
|
49
50
|
export declare const createEntryComparator: (settings: Pick<TreeSettings, "sortMode" | "folderPlacement">) => EntryComparator | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),X=/[\u0000-\u001f\u007f]/u,C=/\p{Cs}/u,U=e=>{const t=e.split("/").filter(n=>n!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!C.test(e)&&!X.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),H=/(?:%[0-9A-Fa-f]{2})+/gu,z=new TextDecoder("utf-8"),F=/[/\\]/u,M=e=>e.replace(H,t=>z.decode(Uint8Array.from(t.slice(1).split("%").map(n=>Number.parseInt(n,16))))),V=e=>{const t=[e];let n=e;for(let r=0;r<3&&n.includes("%");r+=1){const o=M(n);if(o===n)break;t.push(o),n=o}return t.map(x)},G=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},y=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(G),n=o=>o!==""&&t.some(i=>i.test(o)),r=o=>o!==""&&V(o).some(i=>n(i)||i.split(F).some(n));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},K=y(b),Y=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),W=e=>e===void 0?K:e===!1?Y:y(e),J=(e,t)=>y(e).deniesPath(t),m=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),Q=Object.freeze(["file","directory"]),q=Object.freeze(["video","audio","pdf"]),B=Object.freeze(["info","warning","danger"]),Z=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),ee=1e4,c=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),te=Object.freeze(["http:","https:","mailto:"]),_=1024,ne=/^[a-z0-9-]{1,64}$/u,re="https://relative.invalid/",h=64,E=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>E(m,e),oe=e=>E(Q,e),P=e=>E(q,e),se=e=>E(B,e),ie=e=>E(Z,e),A=e=>typeof e=="string"&&ne.test(e),ae=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,re).protocol)}catch{return!1}},f=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:n}=e;return T(t)?n!==void 0&&!A(n)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(n)}`:null:`unknown failure reason ${s(t)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:n,type:r,mimeType:o,modifiedAt:i,children:a,lazy:l}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof n!="string"||!R(n)?"an entry needs an acceptable path":oe(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:l!==void 0&&typeof l!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":r==="file"&&(a!==void 0||l===!0)?"a file entry cannot have children or be lazy":l===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:n,failure:r}=e;return t==="ok"?Array.isArray(n)&&n.every(N):t==="error"&&f(r)===null},le=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:n,failure:r}=e;return t==="ok"?n===null||D(n):t==="error"&&f(r)===null},D=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,ce=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:n,ancestors:r,failure:o}=e;return t==="ok"?n===null&&r===null||typeof n=="string"&&n!==""&&D(r):t==="error"&&f(o)===null},ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:n}=e;return t==="ok"&&!(Number.isSafeInteger(n)&&n>=0)?!1:L(e)},g=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:n,id:r}=e;return typeof t!="string"||typeof r!="string"?"a heading needs text and id strings":typeof n!="number"||!Number.isInteger(n)||n<O.min||n>O.max?`a heading depth must be an integer in 1..6; got ${String(n)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:n}=t;if(!ie(n))return`unknown document kind ${s(n)}`;if(n==="failure")return f(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(n){case"markdown":{const{htmlContent:r,headings:o}=t;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=g(i);if(a!==null)return a}return de(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":c(t.url)?null:"a text document needs a root-relative url";case"image":return c(t.url)?null:"an image document needs a root-relative url";case"media":return c(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"file":return c(t.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,fe=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),de=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:n}=e;return t==="inline"?n===void 0?null:"an inline edit carries no href":t!=="external"?`unknown edit kind ${s(t)}`:Ee(n)?null:`an external edit needs an absolute https: href; got ${s(n)}`},Ee=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},u=e=>typeof e=="string"&&e.length>0&&e.length<=_,pe=e=>c(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:n,size:r,author:o,kept:i,current:a}=e;return u(t)?n!==null&&(typeof n!="string"||Number.isNaN(Date.parse(n)))?`a revision's modifiedAt must be a date-time string or null; got ${s(n)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${s(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},p=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const n=e,{kind:r}=n;if(r==="failure")return f(n.failure);if(typeof r!="string"||!t.includes(r))return`unexpected answer kind ${s(r)}`;switch(r){case"grant":return pe(n);case"edit":return typeof n.text!="string"||typeof n.history!="boolean"?"an edit source needs text and history":u(n.version)?null:`an edit source needs a version; got ${s(n.version)}`;case"saved":return u(n.version)?null:`a saved answer needs a version; got ${s(n.version)}`;case"conflict":return typeof n.text!="string"?"a conflict needs the current text":u(n.version)?null:`a conflict needs the current version; got ${s(n.version)}`;case"preview":{const{htmlContent:o,headings:i}=n;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const l=g(a);if(l!==null)return l}return null}case"revisions":{if(!Array.isArray(n.revisions))return"revisions need an array";for(const o of n.revisions){const i=k(o);if(i!==null)return i}return null}case"revision":return typeof n.text!="string"?"a revision answer needs text":u(n.id)?null:`a revision answer needs an id; got ${s(n.id)}`;default:return`unexpected answer kind ${s(r)}`}},Re=Object.freeze(["edit","grant"]),ye=Object.freeze(["saved","conflict","grant"]),me=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),Ae=Object.freeze(["revision"]),ge=e=>p(e,Re)===null,Oe=e=>p(e,ye)===null,he=e=>p(e,me)===null,be=e=>p(e,_e)===null,xe=e=>p(e,Ae)===null,Te=(e,t)=>({kind:"failure",failure:I(e,t)}),I=(e,t)=>A(t)?{reason:e,code:t}:{reason:e},Pe=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),d=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Se="asset",Ne="link-card",Le=(e,t,n)=>{const r=`${e}/${Se}?${d.path}=${encodeURIComponent(t)}`;return n===null?r:`${r}&${d.version}=${encodeURIComponent(n)}`},$="text",De=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${d.display}=${$}`},ve=e=>{const t=e.getAll(d.display);return t.length===0?"file":t.length===1&&t[0]===$?"text":null},we=e=>`${e}/${Ne}`,ke="X-Markdown-Explorer-Scope",Ie="X-Markdown-Explorer",$e="refresh",je="edit",Xe="text/markdown",Ce=e=>Pe.includes(e),j=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),Ue=e=>{const[t,...n]=m.filter(r=>j[r]===e);return t!==void 0&&n.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=d;exports.EXPLORER_DRAFT_MEDIA_TYPE=Xe;exports.EXPLORER_EDIT_PROOF=je;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=m;exports.EXPLORER_FAILURE_STATUS=j;exports.EXPLORER_LINK_PROTOCOLS=te;exports.EXPLORER_MAX_HEADINGS=ee;exports.EXPLORER_PROOF_HEADER=Ie;exports.EXPLORER_REFRESH_PROOF=$e;exports.EXPLORER_SCOPE_HEADER=ke;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.entryViolation=S;exports.explorerAssetHref=Le;exports.explorerLinkCardEndpoint=we;exports.explorerPlainTextHref=De;exports.failureDocument=Te;exports.failureOf=I;exports.failureReasonOfStatus=Ue;exports.failureViolation=f;exports.headingViolation=g;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=ae;exports.isDeniedPath=J;exports.isExplorerAncestorsResult=le;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=Ce;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=ge;exports.isExplorerEditToken=u;exports.isExplorerFailureCode=A;exports.isExplorerFailureReason=T;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=se;exports.isExplorerPreviewAnswer=he;exports.isExplorerRevealResult=ce;exports.isExplorerRevisionAnswer=xe;exports.isExplorerRevisionsAnswer=be;exports.isExplorerSaveAnswer=Oe;exports.isExplorerTextAnswer=fe;exports.isExplorerTreeResult=ue;exports.isRootRelativeUrl=c;exports.lastPathSegment=U;exports.readExplorerAssetDisplay=ve;exports.resolvePathRules=W;exports.revisionViolation=k;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const de = 4096;
|
|
2
|
+
const N = Object.freeze([
|
|
3
|
+
".env*",
|
|
4
|
+
"*.env",
|
|
5
|
+
"*.env.*",
|
|
6
|
+
"*.env~*",
|
|
7
|
+
"*.env-*",
|
|
8
|
+
"*.env_*",
|
|
9
|
+
"*.env#*",
|
|
10
|
+
".git",
|
|
11
|
+
".git-credentials",
|
|
12
|
+
".svn",
|
|
13
|
+
".hg",
|
|
14
|
+
"node_modules",
|
|
15
|
+
"secrets",
|
|
16
|
+
".secrets",
|
|
17
|
+
"secrets.json",
|
|
18
|
+
"secrets.yml",
|
|
19
|
+
"secrets.yaml",
|
|
20
|
+
"secrets.toml",
|
|
21
|
+
"secrets.ini",
|
|
22
|
+
"secrets.txt",
|
|
23
|
+
".ssh",
|
|
24
|
+
".aws",
|
|
25
|
+
".gnupg",
|
|
26
|
+
".docker",
|
|
27
|
+
".kube",
|
|
28
|
+
".terraform",
|
|
29
|
+
".npmrc",
|
|
30
|
+
".yarnrc",
|
|
31
|
+
".yarnrc.yml",
|
|
32
|
+
".netrc",
|
|
33
|
+
"_netrc",
|
|
34
|
+
".pypirc",
|
|
35
|
+
".pgpass",
|
|
36
|
+
".my.cnf",
|
|
37
|
+
".htpasswd",
|
|
38
|
+
".vault-token",
|
|
39
|
+
"id_rsa*",
|
|
40
|
+
"id_dsa*",
|
|
41
|
+
"id_ecdsa*",
|
|
42
|
+
"id_ed25519*",
|
|
43
|
+
"*.pem",
|
|
44
|
+
"*.key",
|
|
45
|
+
"*.p8",
|
|
46
|
+
"*.p12",
|
|
47
|
+
"*.pfx",
|
|
48
|
+
"*.ppk",
|
|
49
|
+
"*.jks",
|
|
50
|
+
"*.keystore",
|
|
51
|
+
"*.kdbx",
|
|
52
|
+
"*credentials*.json",
|
|
53
|
+
"service-account*.json",
|
|
54
|
+
"*.tfstate",
|
|
55
|
+
"*.tfstate.*",
|
|
56
|
+
"*.tfvars",
|
|
57
|
+
"*.tfvars.json",
|
|
58
|
+
".*_history",
|
|
59
|
+
"fish_history"
|
|
60
|
+
]), v = /[\u0000-\u001f\u007f]/u, w = /\p{Cs}/u, pe = (e) => {
|
|
61
|
+
const t = e.split("/").filter((n) => n !== "").at(-1);
|
|
62
|
+
return t === void 0 ? e : t;
|
|
63
|
+
}, R = (e) => e.length > 0 && e.length <= 4096 && !w.test(e) && !v.test(e) && !e.includes("\\"), A = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), P = /(?:%[0-9A-Fa-f]{2})+/gu, L = new TextDecoder("utf-8"), D = /[/\\]/u, k = (e) => e.replace(
|
|
64
|
+
P,
|
|
65
|
+
(t) => L.decode(
|
|
66
|
+
Uint8Array.from(
|
|
67
|
+
t.slice(1).split("%").map((n) => Number.parseInt(n, 16))
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
), j = (e) => {
|
|
71
|
+
const t = [e];
|
|
72
|
+
let n = e;
|
|
73
|
+
for (let r = 0; r < 3 && n.includes("%"); r += 1) {
|
|
74
|
+
const s = k(n);
|
|
75
|
+
if (s === n) break;
|
|
76
|
+
t.push(s), n = s;
|
|
77
|
+
}
|
|
78
|
+
return t.map(A);
|
|
79
|
+
}, $ = (e) => {
|
|
80
|
+
if (typeof e != "string" || e.trim() === "" || e.includes("/") || e.includes("\\"))
|
|
81
|
+
throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);
|
|
82
|
+
const t = A(e).split("*").map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
|
|
83
|
+
return new RegExp(`^${t}$`, "su");
|
|
84
|
+
}, y = (e) => {
|
|
85
|
+
if (!Array.isArray(e)) throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");
|
|
86
|
+
const t = e.map($), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => s !== "" && j(s).some((i) => n(i) || i.split(D).some(n));
|
|
87
|
+
return {
|
|
88
|
+
deniesPath: (s) => s.split("/").some(r),
|
|
89
|
+
deniesName: r
|
|
90
|
+
};
|
|
91
|
+
}, I = y(N), C = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Ee = (e) => e === void 0 ? I : e === !1 ? C : y(e), ye = (e, t) => y(e).deniesPath(t), h = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), z = Object.freeze(["file", "directory"]), U = Object.freeze(["video", "audio", "pdf"]), X = Object.freeze(["info", "warning", "danger"]), H = Object.freeze(["markdown", "text", "image", "media", "file", "failure"]), m = Object.freeze({ min: 1, max: 6 }), me = 1e4, l = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), ge = Object.freeze(["http:", "https:", "mailto:"]), _ = 1024, F = /^[a-z0-9-]{1,64}$/u, V = "https://relative.invalid/", g = 64, f = (e, t) => typeof t == "string" && e.includes(t), o = (e) => typeof e == "string" ? JSON.stringify(e.length > g ? `${e.slice(0, g)}…` : e) : typeof e, M = (e) => f(h, e), K = (e) => f(z, e), G = (e) => f(U, e), Re = (e) => f(X, e), Y = (e) => f(H, e), b = (e) => typeof e == "string" && F.test(e), Ae = (e, t) => {
|
|
92
|
+
if (typeof e != "string") return !1;
|
|
93
|
+
try {
|
|
94
|
+
return t.includes(new URL(e, V).protocol);
|
|
95
|
+
} catch {
|
|
96
|
+
return !1;
|
|
97
|
+
}
|
|
98
|
+
}, d = (e) => {
|
|
99
|
+
if (e === null || typeof e != "object") return "a failure must be an object";
|
|
100
|
+
const { reason: t, code: n } = e;
|
|
101
|
+
return M(t) ? n !== void 0 && !b(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
|
|
102
|
+
}, W = (e) => {
|
|
103
|
+
if (e === null || typeof e != "object") return "an entry must be an object";
|
|
104
|
+
const { name: t, path: n, type: r, mimeType: s, modifiedAt: i, children: a, lazy: c } = e;
|
|
105
|
+
return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !R(n) ? "an entry needs an acceptable path" : K(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : i !== void 0 && !Number.isSafeInteger(i) ? `an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o(i)}` : c !== void 0 && typeof c != "boolean" ? "an entry lazy flag must be a boolean" : a !== void 0 && !Array.isArray(a) ? "entry children must be an array" : r === "file" && (a !== void 0 || c === !0) ? "a file entry cannot have children or be lazy" : c === !0 && Array.isArray(a) && a.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
|
|
106
|
+
}, O = (e) => {
|
|
107
|
+
if (W(e) !== null) return !1;
|
|
108
|
+
const { children: t } = e;
|
|
109
|
+
return t === void 0 || t.every(O);
|
|
110
|
+
}, J = (e) => {
|
|
111
|
+
if (e === null || typeof e != "object") return !1;
|
|
112
|
+
const { status: t, entries: n, failure: r } = e;
|
|
113
|
+
return t === "ok" ? Array.isArray(n) && n.every(O) : t === "error" && d(r) === null;
|
|
114
|
+
}, he = (e) => {
|
|
115
|
+
if (e === null || typeof e != "object") return !1;
|
|
116
|
+
const { status: t, ancestors: n, failure: r } = e;
|
|
117
|
+
return t === "ok" ? n === null || x(n) : t === "error" && d(r) === null;
|
|
118
|
+
}, x = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && R(t)) && new Set(e).size === e.length, _e = (e) => {
|
|
119
|
+
if (e === null || typeof e != "object") return !1;
|
|
120
|
+
const { status: t, source: n, ancestors: r, failure: s } = e;
|
|
121
|
+
return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && x(r) : t === "error" && d(s) === null;
|
|
122
|
+
}, be = (e) => {
|
|
123
|
+
if (e === null || typeof e != "object") return !1;
|
|
124
|
+
const { status: t, loadedAt: n } = e;
|
|
125
|
+
return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : J(e);
|
|
126
|
+
}, T = (e) => {
|
|
127
|
+
if (e === null || typeof e != "object") return "a heading must be an object";
|
|
128
|
+
const { text: t, depth: n, id: r } = e;
|
|
129
|
+
return typeof t != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof n != "number" || !Number.isInteger(n) || n < m.min || n > m.max ? `a heading depth must be an integer in 1..6; got ${String(n)}` : null;
|
|
130
|
+
}, q = (e) => {
|
|
131
|
+
if (e === null || typeof e != "object") return "a document must be an object";
|
|
132
|
+
const t = e, { kind: n } = t;
|
|
133
|
+
if (!Y(n)) return `unknown document kind ${o(n)}`;
|
|
134
|
+
if (n === "failure") return d(t.failure);
|
|
135
|
+
if (typeof t.name != "string") return "a document needs a name string";
|
|
136
|
+
switch (n) {
|
|
137
|
+
case "markdown": {
|
|
138
|
+
const { htmlContent: r, headings: s } = t;
|
|
139
|
+
if (typeof r != "string" || !Array.isArray(s)) return "a markdown document needs htmlContent and headings";
|
|
140
|
+
for (const i of s) {
|
|
141
|
+
const a = T(i);
|
|
142
|
+
if (a !== null) return a;
|
|
143
|
+
}
|
|
144
|
+
return Q(t.edit);
|
|
145
|
+
}
|
|
146
|
+
case "text":
|
|
147
|
+
return typeof t.text != "string" || typeof t.truncated != "boolean" ? "a text document needs text and truncated" : l(t.url) ? null : "a text document needs a root-relative url";
|
|
148
|
+
case "image":
|
|
149
|
+
return l(t.url) ? null : "an image document needs a root-relative url";
|
|
150
|
+
case "media":
|
|
151
|
+
return l(t.url) ? G(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
|
|
152
|
+
case "file":
|
|
153
|
+
return l(t.url) ? null : "a file document needs a root-relative url";
|
|
154
|
+
}
|
|
155
|
+
}, B = (e) => q(e) === null, Oe = (e) => B(e) && (e.kind === "text" || e.kind === "failure"), Q = (e) => {
|
|
156
|
+
if (e === null) return null;
|
|
157
|
+
if (typeof e != "object") return "a markdown document's edit must be null or an object";
|
|
158
|
+
const { kind: t, href: n } = e;
|
|
159
|
+
return t === "inline" ? n === void 0 ? null : "an inline edit carries no href" : t !== "external" ? `unknown edit kind ${o(t)}` : Z(n) ? null : `an external edit needs an absolute https: href; got ${o(n)}`;
|
|
160
|
+
}, Z = (e) => {
|
|
161
|
+
if (typeof e != "string") return !1;
|
|
162
|
+
try {
|
|
163
|
+
return new URL(e).protocol === "https:";
|
|
164
|
+
} catch {
|
|
165
|
+
return !1;
|
|
166
|
+
}
|
|
167
|
+
}, u = (e) => typeof e == "string" && e.length > 0 && e.length <= _, ee = (e) => l(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, te = (e) => {
|
|
168
|
+
if (e === null || typeof e != "object") return "a revision must be an object";
|
|
169
|
+
const { id: t, modifiedAt: n, size: r, author: s, kept: i, current: a } = e;
|
|
170
|
+
return u(t) ? n !== null && (typeof n != "string" || Number.isNaN(Date.parse(n))) ? `a revision's modifiedAt must be a date-time string or null; got ${o(n)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${o(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${o(s)}` : typeof i != "boolean" || typeof a != "boolean" ? "a revision needs kept and current booleans" : null : `a revision id must be a non-empty string of at most ${_} characters; got ${o(t)}`;
|
|
171
|
+
}, p = (e, t) => {
|
|
172
|
+
if (e === null || typeof e != "object") return "an answer must be an object";
|
|
173
|
+
const n = e, { kind: r } = n;
|
|
174
|
+
if (r === "failure") return d(n.failure);
|
|
175
|
+
if (typeof r != "string" || !t.includes(r)) return `unexpected answer kind ${o(r)}`;
|
|
176
|
+
switch (r) {
|
|
177
|
+
case "grant":
|
|
178
|
+
return ee(n);
|
|
179
|
+
case "edit":
|
|
180
|
+
return typeof n.text != "string" || typeof n.history != "boolean" ? "an edit source needs text and history" : u(n.version) ? null : `an edit source needs a version; got ${o(n.version)}`;
|
|
181
|
+
case "saved":
|
|
182
|
+
return u(n.version) ? null : `a saved answer needs a version; got ${o(n.version)}`;
|
|
183
|
+
case "conflict":
|
|
184
|
+
return typeof n.text != "string" ? "a conflict needs the current text" : u(n.version) ? null : `a conflict needs the current version; got ${o(n.version)}`;
|
|
185
|
+
case "preview": {
|
|
186
|
+
const { htmlContent: s, headings: i } = n;
|
|
187
|
+
if (typeof s != "string" || !Array.isArray(i)) return "a preview needs htmlContent and headings";
|
|
188
|
+
for (const a of i) {
|
|
189
|
+
const c = T(a);
|
|
190
|
+
if (c !== null) return c;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
case "revisions": {
|
|
195
|
+
if (!Array.isArray(n.revisions)) return "revisions need an array";
|
|
196
|
+
for (const s of n.revisions) {
|
|
197
|
+
const i = te(s);
|
|
198
|
+
if (i !== null) return i;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
case "revision":
|
|
203
|
+
return typeof n.text != "string" ? "a revision answer needs text" : u(n.id) ? null : `a revision answer needs an id; got ${o(n.id)}`;
|
|
204
|
+
default:
|
|
205
|
+
return `unexpected answer kind ${o(r)}`;
|
|
206
|
+
}
|
|
207
|
+
}, ne = Object.freeze(["edit", "grant"]), re = Object.freeze(["saved", "conflict", "grant"]), se = Object.freeze(["preview"]), oe = Object.freeze(["revisions"]), ie = Object.freeze(["revision"]), xe = (e) => p(e, ne) === null, Te = (e) => p(e, re) === null, Se = (e) => p(e, se) === null, Ne = (e) => p(e, oe) === null, ve = (e) => p(e, ie) === null, we = (e, t) => ({ kind: "failure", failure: ae(e, t) }), ae = (e, t) => b(t) ? { reason: e, code: t } : { reason: e }, ce = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), E = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), le = "asset", ue = "link-card", Pe = (e, t, n) => {
|
|
208
|
+
const r = `${e}/${le}?${E.path}=${encodeURIComponent(t)}`;
|
|
209
|
+
return n === null ? r : `${r}&${E.version}=${encodeURIComponent(n)}`;
|
|
210
|
+
}, S = "text", Le = (e) => {
|
|
211
|
+
if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);
|
|
212
|
+
return `${e}&${E.display}=${S}`;
|
|
213
|
+
}, De = (e) => {
|
|
214
|
+
const t = e.getAll(E.display);
|
|
215
|
+
return t.length === 0 ? "file" : t.length === 1 && t[0] === S ? "text" : null;
|
|
216
|
+
}, ke = (e) => `${e}/${ue}`, je = "X-Markdown-Explorer-Scope", $e = "X-Markdown-Explorer", Ie = "refresh", Ce = "edit", ze = "text/markdown", Ue = (e) => ce.includes(e), fe = Object.freeze({
|
|
217
|
+
invalid: 400,
|
|
218
|
+
unauthorized: 401,
|
|
219
|
+
forbidden: 403,
|
|
220
|
+
"not-found": 404,
|
|
221
|
+
"too-large": 413,
|
|
222
|
+
"not-configured": 500,
|
|
223
|
+
unsupported: 500,
|
|
224
|
+
failed: 500
|
|
225
|
+
}), Xe = (e) => {
|
|
226
|
+
const [t, ...n] = h.filter((r) => fe[r] === e);
|
|
227
|
+
return t !== void 0 && n.length === 0 ? t : "failed";
|
|
228
|
+
};
|
|
229
|
+
export {
|
|
230
|
+
ze as A,
|
|
231
|
+
ye as B,
|
|
232
|
+
pe as C,
|
|
233
|
+
N as D,
|
|
234
|
+
me as E,
|
|
235
|
+
Le as F,
|
|
236
|
+
Xe as G,
|
|
237
|
+
Oe as H,
|
|
238
|
+
_e as I,
|
|
239
|
+
he as J,
|
|
240
|
+
J as K,
|
|
241
|
+
d as L,
|
|
242
|
+
de as M,
|
|
243
|
+
be as N,
|
|
244
|
+
ve as O,
|
|
245
|
+
Ne as P,
|
|
246
|
+
Se as Q,
|
|
247
|
+
Te as R,
|
|
248
|
+
xe as S,
|
|
249
|
+
B as T,
|
|
250
|
+
_ as U,
|
|
251
|
+
h as V,
|
|
252
|
+
ke as a,
|
|
253
|
+
M as b,
|
|
254
|
+
b as c,
|
|
255
|
+
Re as d,
|
|
256
|
+
Pe as e,
|
|
257
|
+
ae as f,
|
|
258
|
+
Ae as g,
|
|
259
|
+
G as h,
|
|
260
|
+
R as i,
|
|
261
|
+
q as j,
|
|
262
|
+
u as k,
|
|
263
|
+
T as l,
|
|
264
|
+
l as m,
|
|
265
|
+
W as n,
|
|
266
|
+
ge as o,
|
|
267
|
+
Ee as p,
|
|
268
|
+
Ue as q,
|
|
269
|
+
te as r,
|
|
270
|
+
fe as s,
|
|
271
|
+
$e as t,
|
|
272
|
+
Ie as u,
|
|
273
|
+
Ce as v,
|
|
274
|
+
je as w,
|
|
275
|
+
E as x,
|
|
276
|
+
we as y,
|
|
277
|
+
De as z
|
|
278
|
+
};
|