@loomcycle/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/dist/PathExplorer.d.ts +2 -1
- package/dist/components/Classification.d.ts +14 -0
- package/dist/components/Connections.d.ts +5 -1
- package/dist/components/CrossReferences.d.ts +7 -2
- package/dist/components/DocumentViewerBody.d.ts +6 -1
- package/dist/components/ProposalReview.d.ts +23 -0
- package/dist/components/Splitter.d.ts +2 -1
- package/dist/components/Statement.d.ts +9 -0
- package/dist/components/SubjectTypeModal.d.ts +9 -0
- package/dist/index.cjs +14 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +4410 -2647
- package/dist/index.js.map +1 -1
- package/dist/lib/bulkReview.d.ts +23 -0
- package/dist/lib/chunkAncestry.d.ts +2 -0
- package/dist/lib/classify.d.ts +31 -0
- package/dist/lib/createClient.d.ts +15 -0
- package/dist/lib/dataLayer.d.ts +53 -5
- package/dist/lib/edgePages.d.ts +7 -0
- package/dist/lib/navigator.d.ts +4 -0
- package/dist/lib/ruling.d.ts +114 -0
- package/dist/lib/statement.d.ts +13 -0
- package/dist/lib/subjectType.d.ts +4 -0
- package/dist/styles.css +366 -7
- package/dist/types.d.ts +130 -2
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
"use strict";var Mt=Object.create;var Ge=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var Rt=Object.getPrototypeOf,Dt=Object.prototype.hasOwnProperty;var Lt=(t,n,s,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Tt(n))!Dt.call(t,r)&&r!==s&&Ge(t,r,{get:()=>n[r],enumerable:!(a=$t(n,r))||a.enumerable});return t};var Pt=(t,n,s)=>(s=t!=null?Mt(Rt(t)):{},Lt(n||!t||!t.__esModule?Ge(s,"default",{value:t,enumerable:!0}):s,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),It=require("@loomcycle/client"),At=require("react-markdown"),Ot=require("remark-gfm"),Ft=4,Ut=5e3;function Le(t,n){return{pathLs:(s,a,r,c,i)=>t.path({op:"ls",path:s,scope:a,recursive:r,...i?.limit?{limit:i.limit}:{},...i?.cursor?{cursor:i.cursor}:{}},c),pathIsStored:(s,a,r)=>t.path({op:"stat",path:s,scope:a},r).then(()=>!0,c=>{if(c?.name==="SubstrateToolRefusedError")return!1;throw c}),documentPath:async(s,a,r)=>{let c;for(let i=0;i<Ft;i++){const l=await t.path({op:"ls",path:"/",scope:a,recursive:!0,kind_filter:"document",limit:Ut,...c?{cursor:c}:{}},r),f=(l.entries??[]).find(d=>d.resource_ref?.document_id===s);if(f)return f.full_path;if(c=l.next_cursor||void 0,!c)return}},pathMkdir:(s,a,r)=>t.path({op:"mkdir",path:s,scope:a},r),pathMv:(s,a,r,c)=>t.path({op:"mv",path:s,to:a,scope:r},c),pathRm:(s,a,r,c)=>t.path({op:"rm",path:s,scope:a,recursive:r},c),documentCreate:(s,a,r,c)=>t.document({op:"create_document",title:s,path:a,scope:r},c),documentDelete:(s,a,r)=>t.document({op:"delete_document",id:s,scope:a},r),documentGet:(s,a,r)=>t.document({op:"get_document",id:s,scope:a},r),documentsSummary:(s,a,r)=>t.document({op:"documents_summary",scope:a,...s.documentIds?{document_ids:s.documentIds}:{},...s.underPath?{under_path:s.underPath}:{}},r),documentQueryChunks:(s,a,r)=>t.document({op:"query_chunks",document_id:s,scope:a,limit:1e3},r),documentGetChunk:(s,a,r)=>t.document({op:"get_chunk",id:s,scope:a},r),documentCreateChunk:(s,a,r,c,i,l)=>t.document({op:"create_chunk",document_id:s,parent_id:a,scope:c,...l?{after_id:l}:{},...r},i),documentReorderChunk:(s,a,r,c)=>t.document({op:"reorder_chunk",id:s,direction:a,scope:r},c),documentDeleteChunk:(s,a,r)=>t.document({op:"delete_chunk",id:s,scope:a},r),documentSetAsset:(s,a,r,c,i,l)=>t.document({op:"set_asset",id:s,media_type:a,data:r,...c?{filename:c}:{},scope:i},l),documentGetEdges:(s,a,r)=>t.document({op:"get_edges",document_id:s,scope:a},r),documentUpdateChunk:(s,a,r,c,i)=>t.document({op:"update_chunk",id:s,revision:a,scope:c,...r},i),documentExportMd:(s,a,r,c)=>t.document({op:"export_md",document_id:s,scope:a,include_metadata:r},c),documentBacklinks:(s,a,r)=>t.document({op:"backlinks",id:s,scope:a},r),documentRelated:(s,a,r,c)=>t.document({op:"related",id:s,scope:a,...c?{limit:c}:{}},r),documentUnlinkedMentions:(s,a,r,c)=>t.document({op:"unlinked_mentions",id:s,scope:a,...c?{limit:c}:{}},r),documentHistory:(s,a,r,c)=>t.document({op:"history",id:s,scope:a,...c?{limit:c}:{}},r),documentGetVersion:(s,a,r,c)=>t.document({op:"get_version",id:s,revision:a,scope:r},c),documentDiff:(s,a,r,c,i)=>t.document({op:"diff",id:s,from_revision:a,to_revision:r,scope:c},i),documentExportCanvas:(s,a,r)=>t.document({op:"export_canvas",document_id:s,scope:a},r),...n?{documentAssetObjectUrl:async(s,a,r)=>{const c=new URLSearchParams({scope:a});r?.scopeId&&c.set("scope_id",r.scopeId),r?.tenant&&c.set("tenant",r.tenant);const i=await n(`/v1/_document/asset/${encodeURIComponent(s)}?${c.toString()}`);if(!i.ok)throw new Error(`asset fetch failed: ${i.status}`);const l=await i.blob();return URL.createObjectURL(l)}}:{}}}const Ke=o.createContext(null);function Bt({value:t,children:n}){return e.jsx(Ke.Provider,{value:t,children:n})}function he(){const t=o.useContext(Ke);if(!t)throw new Error("useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)");return t}const Pe=500,et=5e3;function Ie(t){return t===""?"/":t}function Gt(t){const n=t.lastIndexOf("/");return n<=0?"":t.slice(0,n)}function tt(t){const n=[""],s=t.split("/").filter(Boolean);let a="";for(let r=0;r<s.length-1;r++)a=`${a}/${s[r]}`,n.push(a);return n}function He(t){return t instanceof Error?t.message:String(t)}function We(t,n){return{entries:[...n,...t.entries??[]],nextCursor:t.next_cursor||void 0,loaded:!0,loading:!1}}class Ht{constructor(n,s,a,r=Pe){this.data=n,this.scope=s,this.browse=a,this.pageLimit=r}data;scope;browse;pageLimit;dirs=new Map;snapshot=new Map;listeners=new Set;inflight=new Map;epoch=new Map;getSnapshot=()=>this.snapshot;subscribe=n=>(this.listeners.add(n),()=>{this.listeners.delete(n)});publish(){this.snapshot=new Map(this.dirs),this.listeners.forEach(n=>n())}set(n,s){this.dirs.set(n,s),this.publish()}track(n,s){const a=s.finally(()=>{this.inflight.get(n)===a&&this.inflight.delete(n)});return this.inflight.set(n,a),a}loadDir(n){const s=this.inflight.get(n);return s||(this.dirs.get(n)?.loaded?Promise.resolve():this.fetchFirst(n,this.pageLimit))}reload(n){const s=this.dirs.get(n),a=s?.entries.length??0,r=s?.loaded&&!s.nextCursor?a+this.pageLimit:a;return this.fetchFirst(n,Math.min(et,Math.max(this.pageLimit,r)))}fetchFirst(n,s){const a=(this.epoch.get(n)??0)+1;this.epoch.set(n,a);const r=this.dirs.get(n);this.set(n,{entries:r?.entries??[],nextCursor:r?.nextCursor,loaded:r?.loaded??!1,loading:!0});const c=this.data.pathLs(Ie(n),this.scope,!1,this.browse,{limit:s}).then(i=>{this.epoch.get(n)===a&&this.set(n,We(i,[]))},i=>{throw this.epoch.get(n)===a&&this.set(n,{entries:r?.entries??[],nextCursor:r?.nextCursor,loaded:r?.loaded??!1,loading:!1,error:He(i)}),i});return this.track(n,c)}loadMore(n){const s=this.inflight.get(n);if(s)return s;const a=this.dirs.get(n);if(!a?.nextCursor)return Promise.resolve();const r=this.epoch.get(n)??0;this.set(n,{...a,loading:!0,error:void 0});const c=this.data.pathLs(Ie(n),this.scope,!1,this.browse,{limit:this.pageLimit,cursor:a.nextCursor}).then(i=>{this.epoch.get(n)===r&&this.set(n,We(i,a.entries))},i=>{throw this.epoch.get(n)===r&&this.set(n,{...a,loading:!1,error:He(i)}),i});return this.track(n,c)}async reveal(n){const s=n.split("/").filter(Boolean);let a="";for(const r of s){for(await this.loadDir(a);;){const c=this.dirs.get(a);if(!c)return!1;if(c.entries.some(f=>f.name===r))break;const i=c.entries[c.entries.length-1];if(!c.nextCursor||i&&i.name>r)return!1;const l=c.nextCursor;if(await this.loadMore(a),this.dirs.get(a)?.nextCursor===l)return!1}a=`${a}/${r}`}return!0}async invalidate(n,s){if(s?.dropSubtree){for(const r of[...this.dirs.keys()])(r===n||r.startsWith(`${n}/`))&&(this.dirs.delete(r),this.epoch.set(r,(this.epoch.get(r)??0)+1),this.inflight.delete(r));this.publish()}const a=tt(n).filter(r=>this.dirs.has(r));await Promise.all(a.map(r=>this.reload(r)))}async refresh(n){const s=new Set(n);s.add("");for(const r of[...this.dirs.keys()])s.has(r)||(this.dirs.delete(r),this.epoch.set(r,(this.epoch.get(r)??0)+1),this.inflight.delete(r));this.publish();const a=[...s].filter(r=>r===""||this.dirs.has(r));await Promise.all(a.map(r=>this.reload(r)))}}async function Wt(t,n,s,a){const r=[];let c;for(;;){const i=await t.pathLs(Ie(n),s,!0,a,{limit:et,cursor:c});r.push(...i.entries??[]);const l=i.next_cursor||void 0;if(!l||l===c)return r;c=l}}function Ve(t){const n=[];for(const s of t){if(s.kind!=="document")continue;const a=s.resource_ref?.document_id;a&&n.push(a)}return n}function nt(t){const n=t.fetch;return new It.LoomcycleClient({baseUrl:t.baseUrl,authToken:t.token||void 0,fetch:(s,a)=>n?n(s,a):fetch(s,a)})}function st(t){const n=t.fetch,s=(a,r)=>n?n(a,r):fetch(a,r);return a=>{const r={};return t.token&&(r.Authorization=`Bearer ${t.token}`),s(t.baseUrl+a,{headers:r})}}function at(t){const{dataLayer:n,client:s,connection:a}=t;return o.useMemo(()=>n||(s?Le(s):a?Le(nt(a),st(a)):null),[n,s,a?.baseUrl,a?.token,a?.fetch])}function rt({theme:t,dataLayer:n,children:s}){const a=t?{"data-theme":t}:{};return n?e.jsx("div",{className:"loomcycle-explorer",...a,children:e.jsx(Bt,{value:n,children:s})}):e.jsx("div",{className:"loomcycle-explorer",...a,children:e.jsxs("div",{className:"error-banner",children:["@loomcycle/explorer: provide a ",e.jsx("code",{children:"connection"}),", ",e.jsx("code",{children:"client"}),", or"," ",e.jsx("code",{children:"dataLayer"})," prop."]})})}function ot(t,n,s){const a=t[t.length-1];return[...a&&a.documentId===n.documentId?[...t.slice(0,-1),{...a,...it(n)}]:[...t,n],s]}function ct(t,n){return n<0||n>=t.length-1?t:t.slice(0,n+1)}function Ae(t,n,s){const a=t[t.length-1];if(!a||a.documentId!==n)return t;const r={...a,...it(s)};return r.title===a.title&&r.path===a.path?t:[...t.slice(0,-1),r]}function it(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>n!==void 0))}function oe(t){return t.title?t.title:t.path?t.path.slice(t.path.lastIndexOf("/")+1)||t.path:t.documentId.slice(0,8)}const Vt=4;function qt(t,n=Vt){const s=Array.from({length:t},(c,i)=>({kind:"crumb",index:i}));if(t<=n||n<3)return s;const a=n-1,r=Array.from({length:t-1-a},(c,i)=>i+1);return[s[0],{kind:"gap",hidden:r},...s.slice(t-a)]}function zt(t,n){for(const s of t.values()){const a=s.entries.find(r=>Jt(r)===n);if(a)return a.full_path}}function Jt(t){if(t.kind==="document")return t.resource_ref?.document_id||void 0}function Zt(t,n){return n&&t.some(s=>s.id===n)?n:t.find(s=>!s.parent_id)?.id}function lt({trail:t,onJump:n}){const[s,a]=o.useState(!1);if(t.length<2)return null;const r=t.length-1,c=t[r-1],i=qt(t.length,s?t.length:void 0);return e.jsxs("nav",{className:"doc-trail","aria-label":"Documents you came through",children:[e.jsx("button",{type:"button",className:"doc-trail-back",onClick:()=>n(r-1),title:`Back to ${oe(c)}`,children:"← Back"}),e.jsx("ol",{className:"doc-trail-list",children:i.map(l=>l.kind==="gap"?e.jsx("li",{className:"doc-trail-item",children:e.jsx("button",{type:"button",className:"doc-trail-gap",onClick:()=>a(!0),title:`Show ${l.hidden.length} more: ${l.hidden.map(f=>oe(t[f])).join(" › ")}`,"aria-label":`Show ${l.hidden.length} hidden documents`,children:"…"})},"gap"):l.index===r?e.jsx("li",{className:"doc-trail-item",children:e.jsx("span",{className:"doc-trail-current","aria-current":"page",title:oe(t[r]),children:oe(t[r])})},l.index):e.jsx("li",{className:"doc-trail-item",children:e.jsx("button",{type:"button",className:"doc-trail-crumb",onClick:()=>n(l.index),title:oe(t[l.index]),children:oe(t[l.index])})},l.index))})]})}const qe=6;function Xt({children:t,defaultLeftWidth:n=380,minLeftWidth:s=180,minRightWidth:a=240,storageKey:r,className:c}){const[i,l]=o.useState(()=>{if(r){const y=localStorage.getItem(r),x=y?parseInt(y,10):NaN;if(Number.isFinite(x)&&x>=s)return x}return n}),f=o.useRef(null),[d,h]=o.useState(!1);o.useEffect(()=>{!r||d||localStorage.setItem(r,String(Math.round(i)))},[r,i,d]);const v=o.useCallback(y=>{y.preventDefault(),h(!0),y.target.setPointerCapture(y.pointerId)},[]),w=o.useCallback(y=>{if(!d||!f.current)return;const x=f.current.getBoundingClientRect(),A=y.clientX-x.left,O=x.width-a-qe,P=Math.max(s,Math.min(A,O));l(P)},[d,s,a]),p=o.useCallback(y=>{h(!1);try{y.target.releasePointerCapture(y.pointerId)}catch{}},[]);return e.jsxs("div",{ref:f,className:`splitter ${c??""} ${d?"dragging":""}`,style:{gridTemplateColumns:`${i}px ${qe}px 1fr`},children:[e.jsx("div",{className:"splitter-pane splitter-left",children:t[0]}),e.jsx("div",{className:"splitter-handle",role:"separator","aria-orientation":"vertical","aria-valuenow":Math.round(i),onPointerDown:v,onPointerMove:w,onPointerUp:p,onPointerCancel:p}),e.jsx("div",{className:"splitter-pane splitter-right",children:t[1]})]})}const Qt=["image/png","image/jpeg","image/gif","image/webp"];function dt(t){return Qt.includes(t)}function ut(t){return new Promise((n,s)=>{if(!dt(t.type)){s(new Error(`unsupported image type "${t.type||"unknown"}" (png, jpeg, gif, webp only)`));return}const a=new FileReader;a.onerror=()=>s(a.error??new Error("failed to read file")),a.onload=()=>{const r=String(a.result??""),c=r.indexOf(",");if(c<0){s(new Error("could not decode image data"));return}n({mediaType:t.type,data:r.slice(c+1)})},a.readAsDataURL(t)})}function Yt(t){if(!t)return null;for(let n=0;n<t.length;n++){const s=t[n];if(s.kind==="file"&&dt(s.type)){const a=s.getAsFile();if(a)return a}}return null}const Ne={"doc.rfc.draft":"#c99a3a","doc.rfc.review":"#6a7bd6","doc.rfc.confirmed":"#3a9ad6","doc.rfc.done":"#3aa06a","doc.plan.draft":"#c99a3a","doc.plan.review":"#6a7bd6","doc.plan.confirmed":"#3a9ad6","doc.plan.done":"#3aa06a","doc.document.done":"#3aa06a","doc.research.done":"#8a6ad6","doc.publication.draft":"#c99a3a","chunk.draft":"#c99a3a","chunk.review":"#6a7bd6","chunk.confirmed":"#3a9ad6","chunk.done":"#3aa06a","chunk.backlog":"#8a8f98","chunk.implementation":"#d1863a","chunk.merged":"#3aa06a"},Kt=.16;function Ce(t){return t&&Object.keys(t).length>0?t:Ne}function Fe(t,n,s){const a=t??"",r=n??"";if(a&&r&&s[`doc.${a}.${r}`])return s[`doc.${a}.${r}`];if(a&&s[`doc.${a}`])return s[`doc.${a}`]}function ht(t,n){const s=t??"";return s?n[`chunk.${s}`]:void 0}function mt(t){const n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!n)return;let s=n[1];s.length===3&&(s=s[0]+s[0]+s[1]+s[1]+s[2]+s[2]);const a=parseInt(s.slice(0,2),16),r=parseInt(s.slice(2,4),16),c=parseInt(s.slice(4,6),16);return`rgba(${a}, ${r}, ${c}, ${Kt})`}function Se(t){if(!t)return;const n=mt(t);if(n)return{background:n,borderLeft:`3px solid ${t}`}}async function en(t){try{return typeof navigator>"u"||!navigator.clipboard?!1:(await navigator.clipboard.writeText(t),!0)}catch{return!1}}function Oe({value:t,label:n,compact:s,title:a}){const[r,c]=o.useState("idle"),i=async h=>{h.stopPropagation(),h.preventDefault();const v=await en(t);c(v?"copied":"error"),window.setTimeout(()=>c("idle"),v?1200:1500)},l=r==="copied"?"✓":r==="error"?"✗":"⎘",f=a??`Copy ${n??"id"}: ${t}`,d=e.jsx("button",{type:"button",className:`id-copy-btn id-copy-${r}`,onClick:i,title:f,"aria-label":f,children:l});return s?d:e.jsxs("span",{className:"id-copy",children:[n&&e.jsx("span",{className:"id-copy-label",children:n}),e.jsx("code",{className:"id-copy-value",title:t,children:t}),d]})}function tn(t){const n=new Map;t.forEach(r=>n.set(r.id,{row:r,children:[]}));const s=[];t.forEach(r=>{const c=n.get(r.id);r.parent_id&&n.has(r.parent_id)?n.get(r.parent_id).children.push(c):s.push(c)});const a=r=>{r.sort((c,i)=>c.row.position-i.row.position),r.forEach(c=>a(c.children))};return a(s),s}function ze(t){return t==="image"?"🖼":t==="mermaid"?"📊":""}function ft(t,n){for(const s of t){if(s.row.id===n)return s;const a=ft(s.children,n);if(a)return a}}function nn({tree:t,selectedId:n,onSelect:s,colorEnabled:a,scheme:r,linkedIds:c}){const[i,l]=o.useState(()=>new Map),f=o.useCallback(h=>{l(v=>{const w=new Map(v);return w.set(h,v.get(h)===!1),w})},[]);o.useEffect(()=>{if(!n)return;const h=sn(t,n);h.length!==0&&l(v=>{let w=!1;const p=new Map(v);for(const y of h)p.get(y)===!1&&(p.set(y,!0),w=!0);return w?p:v})},[t,n]);const d=a?Ce(r):null;return t.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"No chunks."})}):e.jsx("ul",{className:"tree chunk-tree",children:t.map(h=>e.jsx(pt,{node:h,expanded:i,toggle:f,selectedId:n,onSelect:s,tintScheme:d,linkedIds:c},h.row.id))})}function sn(t,n){const s=[],a=(r,c)=>{for(const i of r){if(i.row.id===n)return s.push(...c),!0;if(a(i.children,[...c,i.row.id]))return!0}return!1};return a(t,[]),s}function pt({node:t,expanded:n,toggle:s,selectedId:a,onSelect:r,tintScheme:c,linkedIds:i}){const l=t.children.length>0,f=n.get(t.row.id)!==!1,d=a===t.row.id,h=c?Se(ht(t.row.status,c)):void 0,v=i?.has(t.row.id);return e.jsxs("li",{className:`node chunk-node ${d?"selected":""}`,children:[e.jsxs("div",{className:"row chunk-row",style:h,children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":f?"collapse":"expand",disabled:!l,onClick:w=>{w.stopPropagation(),l&&s(t.row.id)},children:l?f?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"chunk-link",onClick:()=>r(t),title:t.row.title,children:[ze(t.row.type)&&e.jsx("span",{className:"chunk-type-icon","aria-hidden":!0,children:ze(t.row.type)}),e.jsx("span",{className:"chunk-title",children:t.row.title||"(untitled)"}),t.row.type&&e.jsx("span",{className:"chunk-badge",children:t.row.type}),t.row.status&&e.jsx("span",{className:"chunk-badge chunk-status",children:t.row.status}),v&&e.jsx("span",{className:"chunk-link-badge",title:"Has cross-reference links","aria-label":"linked",children:"🔗"})]}),e.jsx(Oe,{value:t.row.id,compact:!0,title:`Copy chunk id: ${t.row.id}`})]}),l&&f&&e.jsx("ul",{className:"children chunk-children",children:t.children.map(w=>e.jsx(pt,{node:w,expanded:n,toggle:s,selectedId:a,onSelect:r,tintScheme:c,linkedIds:i},w.row.id))})]})}let an=0;function rn(t){const n=t?.closest("g.node");return n?/flowchart-(.+)-\d+$/.exec(n.id)?.[1]:void 0}function _e({code:t,onNodeClick:n}){const s=o.useRef(null),[a,r]=o.useState({});return o.useEffect(()=>{let c=!1;return(async()=>{try{const i=(await import("mermaid")).default,l=s.current?.closest("[data-theme]")?.getAttribute("data-theme"),f=l?l==="dark":!0;i.initialize({startOnLoad:!1,theme:f?"dark":"default",securityLevel:"strict"});const{svg:d}=await i.render(`lc-mmd-${an++}`,t);c||r({svg:d})}catch{c||r({err:!0})}})(),()=>{c=!0}},[t]),a.err?e.jsx("pre",{className:"md-pre md-mermaid-error",title:"diagram failed to render",children:e.jsx("code",{children:t})}):a.svg?e.jsx("div",{ref:s,className:n?"md-mermaid md-mermaid-nav":"md-mermaid",onClick:n&&(c=>{const i=rn(c.target);i&&n(i)}),dangerouslySetInnerHTML:{__html:a.svg}}):e.jsx("div",{ref:s,className:"md-mermaid md-mermaid-loading",children:"rendering diagram…"})}function on({chunk:t,scope:n,browse:s,onClose:a,onSaved:r}){const c=he(),[i,l]=o.useState(t.title),[f,d]=o.useState(t.type??""),[h,v]=o.useState(t.status??""),[w,p]=o.useState(t.body??""),[y,x]=o.useState(t.fields?JSON.stringify(t.fields,null,2):""),[A,O]=o.useState((t.tags??[]).join(", ")),[P,B]=o.useState(!1),[W,D]=o.useState(null),[G,H]=o.useState(!1),V=f==="mermaid",N=f==="image"||!!t.asset,[R,C]=o.useState(w);o.useEffect(()=>{if(!V)return;const S=setTimeout(()=>C(w),400);return()=>clearTimeout(S)},[w,V]);const m=async S=>{D(null),B(!0);try{const{mediaType:I,data:T}=await ut(S),X=await c.documentSetAsset(t.id,I,T,S.name,n,s);r(X),a()}catch(I){D(I instanceof Error?I.message:String(I)),B(!1)}},g=V?"Mermaid source":N?"Caption (optional)":"Body (Markdown)",k=async S=>{S.preventDefault(),D(null),H(!1);const I={body:w,title:i,type:f,status:h,tags:A.split(",").map(T=>T.trim()).filter(T=>T!=="")};if(y.trim()!=="")try{I.fields=JSON.parse(y)}catch{D("fields must be valid JSON");return}B(!0);try{const T=await c.documentUpdateChunk(t.id,t.revision,I,n,s);r(T),a()}catch(T){const X=T instanceof Error?T.message:String(T);D(X),H(/revision conflict/i.test(X)),B(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:a,children:e.jsxs("form",{className:"modal chunk-editor",onClick:S=>S.stopPropagation(),onSubmit:k,children:[e.jsxs("div",{className:"modal-header sticky-top",children:[e.jsx("h3",{children:"Edit chunk"}),e.jsxs("div",{className:"modal-buttons modal-buttons-top",children:[e.jsx("button",{type:"button",onClick:a,disabled:P,children:"cancel"}),e.jsx("button",{type:"submit",className:"primary",disabled:P,children:P?"saving…":"save"})]})]}),W&&e.jsxs("div",{className:"modal-err",children:[W,G&&" — reopen the chunk to load the latest, then reapply your edit."]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{className:"path-modal-input",value:i,onChange:S=>l(S.target.value)})]}),e.jsxs("div",{className:"chunk-editor-row",children:[e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Type"}),e.jsx("input",{className:"path-modal-input",value:f,placeholder:"(none)",onChange:S=>d(S.target.value)})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Status"}),e.jsx("input",{className:"path-modal-input",value:h,placeholder:"(none)",onChange:S=>v(S.target.value)})]})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Tags"}),e.jsx("input",{className:"path-modal-input",value:A,placeholder:"comma-separated, nest with a slash: area/sub, priority/high",onChange:S=>O(S.target.value)})]}),N&&e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Replace image"}),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",disabled:P,onChange:S=>{const I=S.target.files?.[0];I&&m(I)}})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:g}),e.jsx("textarea",{className:"modal-textarea chunk-body-input",rows:V?8:12,value:w,onChange:S=>p(S.target.value)})]}),V&&e.jsxs("div",{className:"path-field",children:[e.jsx("span",{children:"Preview"}),e.jsx("div",{className:"chunk-mermaid-preview",children:R.trim()?e.jsx(_e,{code:R}):e.jsx("p",{className:"doc-empty-body",children:"(enter Mermaid source above)"})})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Fields (JSON, optional)"}),e.jsx("textarea",{className:"modal-textarea chunk-fields-input",rows:4,value:y,placeholder:"{}",onChange:S=>x(S.target.value)})]})]})})}function cn(t){const n=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((t??"").trim());if(!n)return"#888888";let s=n[1];return s.length===3&&(s=s[0]+s[0]+s[1]+s[1]+s[2]+s[2]),"#"+s.toLowerCase()}function ln({documentId:t,rootChunkId:n,docType:s,docStatus:a,chunkStatuses:r,scope:c,browse:i,onClose:l,onSaved:f}){const d=he(),[h,v]=o.useState(null),[w,p]=o.useState(!1),[y,x]=o.useState({}),[A,O]=o.useState(!1),[P,B]=o.useState(null),[W,D]=o.useState(null),G=o.useMemo(()=>{const g=new Set(Object.keys(Ne));s&&g.add(`doc.${s}.${a||"draft"}`);for(const k of r)k&&g.add(`chunk.${k}`);return[...g].sort()},[s,a,r]);o.useEffect(()=>{let g=!1;return d.documentGetChunk(n,c,i).then(k=>{if(g)return;v(k);const S=k.fields??{};p(S.color_enabled===!0);const I=S.color_scheme??{};x({...Ne,...I})}).catch(k=>!g&&D(k instanceof Error?k.message:String(k))),()=>{g=!0}},[d,n,c,i]);const H=(g,k)=>x(S=>({...S,[g]:k})),V=g=>({...g??{},color_enabled:w,color_scheme:y}),N=async()=>{if(h){O(!0),D(null),B(null);try{await d.documentUpdateChunk(n,h.revision,{fields:V(h.fields)},c,i),f(),l()}catch(g){D(g instanceof Error?g.message:String(g)),O(!1)}}},R=async()=>{if(!s){D("this document has no type to match");return}O(!0),D(null),B(null);try{const{documents:g}=await d.documentsSummary({underPath:"/"},c,i),k=(g??[]).filter(I=>I.type===s&&I.document_id!==t&&I.root_chunk_id);let S=0;for(const I of k)try{const T=await d.documentGetChunk(I.root_chunk_id,c,i);await d.documentUpdateChunk(I.root_chunk_id,T.revision,{fields:V(T.fields)},c,i),S++}catch{}B(`Applied to ${S} other ${s} document(s).`),f()}catch(g){D(g instanceof Error?g.message:String(g))}finally{O(!1)}},C=G.filter(g=>g.startsWith("doc.")),m=G.filter(g=>g.startsWith("chunk."));return e.jsx("div",{className:"modal-overlay",onClick:l,children:e.jsxs("div",{className:"modal scheme-editor",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"scheme-editor-head",children:[e.jsx("h3",{children:"Document colors"}),e.jsxs("div",{className:"scheme-editor-actions",children:[e.jsx("button",{type:"button",onClick:l,disabled:A,children:"cancel"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{N()},disabled:A||!h,children:A?"saving…":"save"})]})]}),W&&e.jsx("div",{className:"modal-err",children:W}),h?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"scheme-toggle",children:[e.jsx("input",{type:"checkbox",checked:w,onChange:g=>p(g.target.checked)}),e.jsx("span",{children:"Enable coloring for this document"})]}),e.jsx("p",{className:"modal-context",children:"Document rows are tinted by type + status; chunk tiles by status. Colors apply as a semi-transparent wash so text stays readable."}),e.jsxs("div",{className:"scheme-group",children:[e.jsx("h4",{children:"Document (type · status)"}),C.map(g=>e.jsx(Je,{label:g.slice(4),value:y[g],onChange:k=>H(g,k)},g))]}),e.jsxs("div",{className:"scheme-group",children:[e.jsx("h4",{children:"Chunks (status)"}),m.map(g=>e.jsx(Je,{label:g.slice(6),value:y[g],onChange:k=>H(g,k)},g))]}),e.jsxs("div",{className:"scheme-editor-foot",children:[e.jsxs("button",{type:"button",onClick:()=>{R()},disabled:A||!s,title:s?`Apply this palette to every other ${s} document`:"This document has no type",children:["copy to all ",s||"same-type"," documents"]}),P&&e.jsx("span",{className:"scheme-status",children:P})]})]}):e.jsx("p",{className:"modal-context",children:"Loading…"})]})})}function Je({label:t,value:n,onChange:s}){const a=cn(n);return e.jsxs("label",{className:"scheme-row",children:[e.jsx("input",{type:"color",value:a,onChange:r=>s(r.target.value)}),e.jsx("span",{className:"scheme-key",children:t}),e.jsx("code",{className:"scheme-hex",children:a})]})}function xt({id:t,title:n,targetDocumentId:s,documentId:a,onSelectChunk:r,onOpenDocument:c}){const i=n||t.slice(0,8);return!s||s===a?e.jsx("button",{type:"button",className:"doc-ref-target",onClick:()=>r(t),children:i}):c?e.jsxs("button",{type:"button",className:"doc-ref-target external",title:"In another document — opens it at this chunk",onClick:()=>c(s,t,n),children:[i," ↗"]}):e.jsxs("span",{className:"doc-ref-target external",title:"In another document",children:[i," ↗"]})}const dn=8,un=20;function hn(t){return/embedder|embedding|vector|semantic|not configured/i.test(t)}function mn({documentId:t,selectedId:n,scope:s,browse:a,onSelectChunk:r,onOpenDocument:c}){const i=he(),[l,f]=o.useState(!1),[d,h]=o.useState(!1),[v,w]=o.useState(void 0),[p,y]=o.useState([]),[x,A]=o.useState([]),[O,P]=o.useState(null),[B,W]=o.useState([]),[D,G]=o.useState(!1);o.useEffect(()=>{if(!l||!n)return;const N=n;let R=!1;return h(!0),Promise.allSettled([i.documentBacklinks(N,s,a),i.documentRelated(N,s,a,dn),i.documentUnlinkedMentions(N,s,a,un)]).then(([C,m,g])=>{if(!R){if(y(C.status==="fulfilled"?C.value.backlinks??[]:[]),m.status==="fulfilled")A(m.value.related??[]),P(null);else{A([]);const k=m.reason instanceof Error?m.reason.message:String(m.reason);P(hn(k)?"semantic search not configured":k)}g.status==="fulfilled"?(W(g.value.unlinked_mentions??[]),G(!!g.value.truncated)):(W([]),G(!1)),w(N),h(!1)}}),()=>{R=!0}},[i,l,n,s,a]);const H=(N,R,C)=>e.jsx(xt,{id:N,title:R,targetDocumentId:C,documentId:t,onSelectChunk:r,onOpenDocument:c}),V=!!(l&&n&&!d&&v===n);return e.jsxs("div",{className:"doc-conn",children:[e.jsxs("button",{type:"button",className:"doc-conn-toggle",onClick:()=>f(N=>!N),children:[l?"▼":"▶"," Connections"]}),l&&e.jsx("div",{className:"doc-conn-body",children:n?V?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"doc-conn-group",children:[e.jsx("h5",{children:"Backlinks"}),p.length===0?e.jsx("p",{className:"doc-conn-empty",children:"none"}):e.jsx("ul",{className:"doc-conn-list",children:p.map((N,R)=>e.jsxs("li",{className:"doc-conn-row",children:[H(N.from_id,N.from_title,N.from_document_id),e.jsx("span",{className:"doc-ref-kind",children:N.kind}),N.auto&&e.jsx("span",{className:"doc-conn-auto",title:"Auto-linked from a [[wikilink]]",children:"auto"})]},`${N.from_id}-${N.kind}-${R}`))})]}),e.jsxs("div",{className:"doc-conn-group",children:[e.jsx("h5",{children:"Related"}),O?e.jsx("p",{className:"doc-conn-empty",children:O}):x.length===0?e.jsx("p",{className:"doc-conn-empty",children:"none"}):e.jsx("ul",{className:"doc-conn-list",children:x.map((N,R)=>e.jsxs("li",{className:"doc-conn-row",children:[H(N.chunk_id,N.title,N.document_id),e.jsx("span",{className:"doc-conn-score",title:"similarity score",children:N.score.toFixed(2)})]},`${N.chunk_id}-${R}`))})]}),e.jsxs("div",{className:"doc-conn-group",children:[e.jsx("h5",{children:"Unlinked mentions"}),B.length===0?e.jsx("p",{className:"doc-conn-empty",children:"none"}):e.jsxs("ul",{className:"doc-conn-list",children:[B.map((N,R)=>e.jsx("li",{className:"doc-conn-row",children:H(N.chunk_id,N.title,N.document_id)},`${N.chunk_id}-${R}`)),D&&e.jsx("li",{className:"doc-conn-more","aria-hidden":!0,children:"(more…)"})]})]})]}):e.jsx("p",{className:"doc-conn-empty",children:"loading…"}):e.jsx("p",{className:"doc-conn-empty",children:"Select a chunk."})})]})}const De=24;function fn({edges:t,documentId:n,selectedId:s,onSelectChunk:a,onOpenDocument:r}){const[c,i]=o.useState(!1),[l,f]=o.useState(!1);if(t.length===0)return null;const d=s?t.filter(p=>p.from_id===s||p.to_id===s):[],h=l?t:t.slice(0,De),v=xn(h),w=p=>{const y=gn(h,p);y&&(!y.documentId||y.documentId===n?a(y.id):r?.(y.documentId,y.id,y.title))};return e.jsxs("div",{className:"doc-refs",children:[s&&e.jsxs("div",{className:"doc-refs-list-wrap",children:[e.jsx("h4",{children:"References"}),d.length===0?e.jsx("p",{className:"doc-refs-empty",children:"This chunk has no links."}):e.jsx("ul",{className:"doc-refs-list",children:d.map((p,y)=>e.jsx(pn,{edge:p,selectedId:s,documentId:n,onSelectChunk:a,onOpenDocument:r},`${p.from_id}-${p.to_id}-${p.kind}-${y}`))})]}),e.jsxs("div",{className:"doc-graph",children:[e.jsxs("button",{type:"button",className:"doc-graph-toggle",onClick:()=>i(p=>!p),children:[c?"▼":"▶"," relationship graph (",t.length,")"]}),c&&e.jsxs(e.Fragment,{children:[e.jsx(_e,{code:v,onNodeClick:w}),t.length>De&&e.jsx("button",{type:"button",className:"doc-graph-more",onClick:()=>f(p=>!p),children:l?`show top ${De}`:`show all ${t.length}`})]})]})]})}function pn({edge:t,selectedId:n,documentId:s,onSelectChunk:a,onOpenDocument:r}){const c=t.from_id===n,i=c?t.to_id:t.from_id,l=c?t.to_title:t.from_title,f=c?t.to_document_id:t.from_document_id;return e.jsxs("li",{className:"doc-ref",children:[e.jsx("span",{className:"doc-ref-kind",children:t.kind}),e.jsx("span",{className:"doc-ref-arrow","aria-hidden":!0,children:c?"→":"←"}),e.jsx(xt,{id:i,title:l,targetDocumentId:f,documentId:s,onSelectChunk:a,onOpenDocument:r})]})}function xn(t){const n=["graph LR"];for(const s of t){const a=`${we(s.from_id)}["${Ze(s.from_title,s.from_id)}"]`,r=`${we(s.to_id)}["${Ze(s.to_title,s.to_id)}"]`,c=(s.kind||"link").replace(/[|"]/g," ");n.push(` ${a} -->|${c}| ${r}`)}return n.join(`
|
|
2
|
-
`)}function
|
|
3
|
-
`);return
|
|
4
|
-
`]},
|
|
5
|
-
`)?
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react"),l=require("react/jsx-runtime"),u=require("@loomcycle/client"),d=require("react-markdown");d=s(d,1);let f=require("remark-gfm");f=s(f,1);var p=`loomcycle.explorer.navigator`;function m(e){try{return e?.getItem(`loomcycle.explorer.navigator`)===`stars`?`stars`:`tree`}catch{return`tree`}}function h(e,t){try{e?.setItem(p,t)}catch{}}function g(e){return!!e&&!e.parent_id&&!!e.entity?.natural_key}function _(e){let t=e?.classes;if(!Array.isArray(t))return[];let n=new Set;for(let e of t){let{name:t,kind:r}=e??{};typeof t==`string`&&t!==``&&r!==`document`&&n.add(t)}return[...n].sort((e,t)=>e.localeCompare(t))}function v(e,t){let n=t??``;return n===``||e.some(e=>e.toLowerCase()===n.toLowerCase())?e:[n,...e]}var y=4,b=5e3;function x(e,t,n){return{...S(e,n),pathLs:(t,n,r,i,a)=>e.path({op:`ls`,path:t,scope:n,recursive:r,...a?.limit?{limit:a.limit}:{},...a?.cursor?{cursor:a.cursor}:{}},i),pathIsStored:(t,n,r)=>e.path({op:`stat`,path:t,scope:n},r).then(()=>!0,e=>{if(e?.name===`SubstrateToolRefusedError`)return!1;throw e}),documentPath:async(t,n,r)=>{let i;for(let a=0;a<y;a++){let a=await e.path({op:`ls`,path:`/`,scope:n,recursive:!0,kind_filter:`document`,limit:b,...i?{cursor:i}:{}},r),o=(a.entries??[]).find(e=>e.resource_ref?.document_id===t);if(o)return o.full_path;if(i=a.next_cursor||void 0,!i)return}},pathMkdir:(t,n,r)=>e.path({op:`mkdir`,path:t,scope:n},r),pathMv:(t,n,r,i)=>e.path({op:`mv`,path:t,to:n,scope:r},i),pathRm:(t,n,r,i)=>e.path({op:`rm`,path:t,scope:n,recursive:r},i),documentCreate:(t,n,r,i)=>e.document({op:`create_document`,title:t,path:n,scope:r},i),documentDelete:(t,n,r)=>e.document({op:`delete_document`,id:t,scope:n},r),documentGet:(t,n,r)=>e.document({op:`get_document`,id:t,scope:n},r),documentsSummary:(t,n,r)=>e.document({op:`documents_summary`,scope:n,...t.documentIds?{document_ids:t.documentIds}:{},...t.underPath?{under_path:t.underPath}:{}},r),documentQueryChunks:(t,n,r)=>e.document({op:`query_chunks`,document_id:t,scope:n,limit:1e3},r),documentGetChunk:(t,n,r)=>e.document({op:`get_chunk`,id:t,scope:n},r),documentCreateChunk:(t,n,r,i,a,o)=>e.document({op:`create_chunk`,document_id:t,parent_id:n,scope:i,...o?{after_id:o}:{},...r},a),documentReorderChunk:(t,n,r,i)=>e.document({op:`reorder_chunk`,id:t,direction:n,scope:r},i),documentDeleteChunk:(t,n,r)=>e.document({op:`delete_chunk`,id:t,scope:n},r),documentSetAsset:(t,n,r,i,a,o)=>e.document({op:`set_asset`,id:t,media_type:n,data:r,...i?{filename:i}:{},scope:a},o),documentGetEdges:(t,n,r,i)=>e.document({op:`get_edges`,document_id:t,scope:n,...i?.after?{after:i.after}:{}},r),documentGetEdge:(t,n,r)=>e.document({op:`get_edge`,id:t,scope:n},r),documentAcceptStatement:(t,n,r,i)=>e.document({op:`accept_statement`,id:t,scope:n,...i?{reason:i}:{}},r),documentRejectStatement:(t,n,r,i)=>e.document({op:`reject_statement`,id:t,reason:n,scope:r},i),documentListStatements:(t,n,r)=>e.document({op:`list_statements`,scope:t,...r?.status?{status:r.status}:{},...r?.kind?{kind:r.kind}:{},...r?.limit?{limit:r.limit}:{},...r?.after?{after:r.after}:{}},n),documentClassify:(t,n,r,i)=>e.document({op:`classify`,document_id:t,write:n,scope:r},i),documentEntityTypes:(t,n)=>e.document({op:`describe_ontology`,scope:t},n).then(_),documentAcceptClassification:(t,n,r)=>e.document({op:`accept_classification`,document_id:t,scope:n},r),documentUpdateChunk:(t,n,r,i,a)=>e.document({op:`update_chunk`,id:t,revision:n,scope:i,...r},a),documentExportMd:(t,n,r,i)=>e.document({op:`export_md`,document_id:t,scope:n,include_metadata:r},i),documentBacklinks:(t,n,r)=>e.document({op:`backlinks`,id:t,scope:n},r),documentRelated:(t,n,r,i)=>e.document({op:`related`,id:t,scope:n,...i?{limit:i}:{}},r),documentUnlinkedMentions:(t,n,r,i)=>e.document({op:`unlinked_mentions`,id:t,scope:n,...i?{limit:i}:{}},r),documentHistory:(t,n,r,i)=>e.document({op:`history`,id:t,scope:n,...i?{limit:i}:{}},r),documentGetVersion:(t,n,r,i)=>e.document({op:`get_version`,id:t,revision:n,scope:r},i),documentDiff:(t,n,r,i,a)=>e.document({op:`diff`,id:t,from_revision:n,to_revision:r,scope:i},a),documentExportCanvas:(t,n,r)=>e.document({op:`export_canvas`,document_id:t,scope:n},r),...t?{documentAssetObjectUrl:async(e,n,r)=>{let i=new URLSearchParams({scope:n});r?.scopeId&&i.set(`scope_id`,r.scopeId),r?.tenant&&i.set(`tenant`,r.tenant);let a=await t(`/v1/_document/asset/${encodeURIComponent(e)}?${i.toString()}`);if(!a.ok)throw Error(`asset fetch failed: ${a.status}`);let o=await a.blob();return URL.createObjectURL(o)}}:{}}}function S(e,t){let n=e,r=e=>e?.tenant?`?tenant=${encodeURIComponent(e.tenant)}`:``,i={};typeof n.ruleStatements==`function`?i.documentRuleStatements=(e,t)=>n.ruleStatements(e.action,e.ids?{ids:e.ids}:{filter:e.filter},{reason:e.reason,dryRun:e.dry_run,expectCount:e.expect_count,max:e.max,scope:e.scope,scopeId:e.scope_id,tenant:t?.tenant}):t&&(i.documentRuleStatements=(e,n)=>t(`/v1/_statements/rule${r(n)}`,e));let a=(e,t)=>e===`user`&&t?.scopeId?t.scopeId:void 0;return typeof n.revertRuling==`function`?i.documentRevertRuling=(e,t,r)=>n.revertRuling(e,{scope:t,scopeId:a(t,r),tenant:r?.tenant}):t&&(i.documentRevertRuling=(e,n,i)=>{let o=a(n,i);return t(`/v1/_statements/revert${r(i)}`,{ruling_id:e,scope:n,...o?{scope_id:o}:{}})}),i}var C=(0,c.createContext)(null);function w({value:e,children:t}){return(0,l.jsx)(C.Provider,{value:e,children:t})}function T(){let e=(0,c.useContext)(C);if(!e)throw Error(`useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)`);return e}var E=5e3;function D(e){return e===``?`/`:e}function O(e){let t=e.lastIndexOf(`/`);return t<=0?``:e.slice(0,t)}function k(e){let t=[``],n=e.split(`/`).filter(Boolean),r=``;for(let e=0;e<n.length-1;e++)r=`${r}/${n[e]}`,t.push(r);return t}function A(e){return e instanceof Error?e.message:String(e)}function j(e,t){return{entries:[...t,...e.entries??[]],nextCursor:e.next_cursor||void 0,loaded:!0,loading:!1}}var M=class{data;scope;browse;pageLimit;dirs=new Map;snapshot=new Map;listeners=new Set;inflight=new Map;epoch=new Map;constructor(e,t,n,r=500){this.data=e,this.scope=t,this.browse=n,this.pageLimit=r}getSnapshot=()=>this.snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});publish(){this.snapshot=new Map(this.dirs),this.listeners.forEach(e=>e())}set(e,t){this.dirs.set(e,t),this.publish()}track(e,t){let n=t.finally(()=>{this.inflight.get(e)===n&&this.inflight.delete(e)});return this.inflight.set(e,n),n}loadDir(e){return this.inflight.get(e)||(this.dirs.get(e)?.loaded?Promise.resolve():this.fetchFirst(e,this.pageLimit))}reload(e){let t=this.dirs.get(e),n=t?.entries.length??0,r=t?.loaded&&!t.nextCursor?n+this.pageLimit:n;return this.fetchFirst(e,Math.min(E,Math.max(this.pageLimit,r)))}fetchFirst(e,t){let n=(this.epoch.get(e)??0)+1;this.epoch.set(e,n);let r=this.dirs.get(e);this.set(e,{entries:r?.entries??[],nextCursor:r?.nextCursor,loaded:r?.loaded??!1,loading:!0});let i=this.data.pathLs(D(e),this.scope,!1,this.browse,{limit:t}).then(t=>{this.epoch.get(e)===n&&this.set(e,j(t,[]))},t=>{throw this.epoch.get(e)===n&&this.set(e,{entries:r?.entries??[],nextCursor:r?.nextCursor,loaded:r?.loaded??!1,loading:!1,error:A(t)}),t});return this.track(e,i)}loadMore(e){let t=this.inflight.get(e);if(t)return t;let n=this.dirs.get(e);if(!n?.nextCursor)return Promise.resolve();let r=this.epoch.get(e)??0;this.set(e,{...n,loading:!0,error:void 0});let i=this.data.pathLs(D(e),this.scope,!1,this.browse,{limit:this.pageLimit,cursor:n.nextCursor}).then(t=>{this.epoch.get(e)===r&&this.set(e,j(t,n.entries))},t=>{throw this.epoch.get(e)===r&&this.set(e,{...n,loading:!1,error:A(t)}),t});return this.track(e,i)}async reveal(e){let t=e.split(`/`).filter(Boolean),n=``;for(let e of t){for(await this.loadDir(n);;){let t=this.dirs.get(n);if(!t)return!1;if(t.entries.some(t=>t.name===e))break;let r=t.entries[t.entries.length-1];if(!t.nextCursor||r&&r.name>e)return!1;let i=t.nextCursor;if(await this.loadMore(n),this.dirs.get(n)?.nextCursor===i)return!1}n=`${n}/${e}`}return!0}async invalidate(e,t){if(t?.dropSubtree){for(let t of[...this.dirs.keys()])(t===e||t.startsWith(`${e}/`))&&(this.dirs.delete(t),this.epoch.set(t,(this.epoch.get(t)??0)+1),this.inflight.delete(t));this.publish()}let n=k(e).filter(e=>this.dirs.has(e));await Promise.all(n.map(e=>this.reload(e)))}async refresh(e){let t=new Set(e);t.add(``);for(let e of[...this.dirs.keys()])t.has(e)||(this.dirs.delete(e),this.epoch.set(e,(this.epoch.get(e)??0)+1),this.inflight.delete(e));this.publish();let n=[...t].filter(e=>e===``||this.dirs.has(e));await Promise.all(n.map(e=>this.reload(e)))}};async function ee(e,t,n,r){let i=[],a;for(;;){let o=await e.pathLs(D(t),n,!0,r,{limit:E,cursor:a});i.push(...o.entries??[]);let s=o.next_cursor||void 0;if(!s||s===a)return i;a=s}}function te(e){let t=[];for(let n of e){if(n.kind!==`document`)continue;let e=n.resource_ref?.document_id;e&&t.push(e)}return t}function ne(e){let t=e.fetch;return new u.LoomcycleClient({baseUrl:e.baseUrl,authToken:e.token||void 0,fetch:(e,n)=>t?t(e,n):fetch(e,n)})}function N(e){let t=e.fetch,n=(e,n)=>t?t(e,n):fetch(e,n);return t=>{let r={};return e.token&&(r.Authorization=`Bearer ${e.token}`),n(e.baseUrl+t,{headers:r})}}var P=class extends Error{status;code;constructor(e,t,n){super(e),this.name=`RequestError`,this.status=t,this.code=n}};function F(e){let t=e.fetch,n=(e,n)=>t?t(e,n):fetch(e,n);return async(t,r)=>{let i={"Content-Type":`application/json`,Accept:`application/json`};e.token&&(i.Authorization=`Bearer ${e.token}`);let a=await n(e.baseUrl+t,{method:`POST`,headers:i,body:JSON.stringify(r)}),o=await a.text(),s;try{s=o?JSON.parse(o):void 0}catch{}if(!a.ok){let e=s&&typeof s==`object`?s:{};throw new P(typeof e.error==`string`&&e.error?e.error:`${a.status} ${a.statusText}`.trim(),a.status,typeof e.code==`string`?e.code:void 0)}return s}}function I(e){let{dataLayer:t,client:n,connection:r}=e;return(0,c.useMemo)(()=>t||(n?x(n):r?x(ne(r),N(r),F(r)):null),[t,n,r?.baseUrl,r?.token,r?.fetch])}function L({theme:e,dataLayer:t,children:n}){let r=e?{"data-theme":e}:{};return t?(0,l.jsx)(`div`,{className:`loomcycle-explorer`,...r,children:(0,l.jsx)(w,{value:t,children:n})}):(0,l.jsx)(`div`,{className:`loomcycle-explorer`,...r,children:(0,l.jsxs)(`div`,{className:`error-banner`,children:[`@loomcycle/explorer: provide a `,(0,l.jsx)(`code`,{children:`connection`}),`, `,(0,l.jsx)(`code`,{children:`client`}),`, or`,` `,(0,l.jsx)(`code`,{children:`dataLayer`}),` prop.`]})})}function R(e,t,n){let r=e[e.length-1];return[...r&&r.documentId===t.documentId?[...e.slice(0,-1),{...r,...z(t)}]:[...e,t],n]}function re(e,t){return t<0||t>=e.length-1?e:e.slice(0,t+1)}function ie(e,t,n){let r=e[e.length-1];if(!r||r.documentId!==t)return e;let i={...r,...z(n)};return i.title===r.title&&i.path===r.path?e:[...e.slice(0,-1),i]}function z(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function B(e){return e.title?e.title:e.path?e.path.slice(e.path.lastIndexOf(`/`)+1)||e.path:e.documentId.slice(0,8)}function ae(e,t=4){let n=Array.from({length:e},(e,t)=>({kind:`crumb`,index:t}));if(e<=t||t<3)return n;let r=t-1,i=Array.from({length:e-1-r},(e,t)=>t+1);return[n[0],{kind:`gap`,hidden:i},...n.slice(e-r)]}function oe(e,t){for(let n of e.values()){let e=n.entries.find(e=>V(e)===t);if(e)return e.full_path}}function V(e){if(e.kind===`document`)return e.resource_ref?.document_id||void 0}function H(e,t){return t&&e.some(e=>e.id===t)?t:e.find(e=>!e.parent_id)?.id}function se({trail:e,onJump:t}){let[n,r]=(0,c.useState)(!1);if(e.length<2)return null;let i=e.length-1,a=e[i-1],o=ae(e.length,n?e.length:void 0);return(0,l.jsxs)(`nav`,{className:`doc-trail`,"aria-label":`Documents you came through`,children:[(0,l.jsx)(`button`,{type:`button`,className:`doc-trail-back`,onClick:()=>t(i-1),title:`Back to ${B(a)}`,children:`← Back`}),(0,l.jsx)(`ol`,{className:`doc-trail-list`,children:o.map(n=>n.kind===`gap`?(0,l.jsx)(`li`,{className:`doc-trail-item`,children:(0,l.jsx)(`button`,{type:`button`,className:`doc-trail-gap`,onClick:()=>r(!0),title:`Show ${n.hidden.length} more: ${n.hidden.map(t=>B(e[t])).join(` › `)}`,"aria-label":`Show ${n.hidden.length} hidden documents`,children:`…`})},`gap`):n.index===i?(0,l.jsx)(`li`,{className:`doc-trail-item`,children:(0,l.jsx)(`span`,{className:`doc-trail-current`,"aria-current":`page`,title:B(e[i]),children:B(e[i])})},n.index):(0,l.jsx)(`li`,{className:`doc-trail-item`,children:(0,l.jsx)(`button`,{type:`button`,className:`doc-trail-crumb`,onClick:()=>t(n.index),title:B(e[n.index]),children:B(e[n.index])})},n.index))})]})}var ce=6;function le({children:e,defaultLeftWidth:t=380,minLeftWidth:n=180,minRightWidth:r=240,storageKey:i,className:a,hideRight:o=!1}){let s=()=>{if(i){let e=localStorage.getItem(i),t=e?parseInt(e,10):NaN;if(Number.isFinite(t)&&t>=n)return t}return t},[u,d]=(0,c.useState)(s),[f,p]=(0,c.useState)(i);f!==i&&(p(i),d(s()));let m=(0,c.useRef)(null),[h,g]=(0,c.useState)(!1);(0,c.useEffect)(()=>{i&&!h&&f===i&&localStorage.setItem(i,String(Math.round(u)))},[i,f,u,h]);let _=(0,c.useCallback)(e=>{e.preventDefault(),g(!0),e.target.setPointerCapture(e.pointerId)},[]),v=(0,c.useCallback)(e=>{if(!h||!m.current)return;let t=m.current.getBoundingClientRect(),i=e.clientX-t.left,a=t.width-r-ce;d(Math.max(n,Math.min(i,a)))},[h,n,r]),y=(0,c.useCallback)(e=>{g(!1);try{e.target.releasePointerCapture(e.pointerId)}catch{}},[]);return(0,l.jsxs)(`div`,{ref:m,className:`splitter ${a??``} ${h?`dragging`:``}`,style:{gridTemplateColumns:o?`1fr 0 0`:`min(${u}px, calc(100% - ${r+ce}px)) ${ce}px 1fr`},children:[(0,l.jsx)(`div`,{className:`splitter-pane splitter-left`,children:e[0]}),(0,l.jsx)(`div`,{hidden:o,className:`splitter-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-valuenow":Math.round(u),onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:y}),(0,l.jsx)(`div`,{className:`splitter-pane splitter-right`,hidden:o,children:e[1]})]})}var ue=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`];function U(e){return ue.includes(e)}function de(e){return new Promise((t,n)=>{if(!U(e.type)){n(Error(`unsupported image type "${e.type||`unknown`}" (png, jpeg, gif, webp only)`));return}let r=new FileReader;r.onerror=()=>n(r.error??Error(`failed to read file`)),r.onload=()=>{let i=String(r.result??``),a=i.indexOf(`,`);a<0?n(Error(`could not decode image data`)):t({mediaType:e.type,data:i.slice(a+1)})},r.readAsDataURL(e)})}function fe(e){if(!e)return null;for(let t=0;t<e.length;t++){let n=e[t];if(n.kind===`file`&&U(n.type)){let e=n.getAsFile();if(e)return e}}return null}var pe=20;async function me(e,t,n,r,i=20){let a=[],o;for(let s=0;s<i;s++){let i=await e.documentGetEdges(t,n,r,o?{after:o}:void 0);if(o&&i.next_cursor===o)return{edges:a,incomplete:!0};if(a.push(...i.edges??[]),!i.truncated)return{edges:a,incomplete:!1};if(!i.next_cursor)return{edges:a,incomplete:!0};o=i.next_cursor}return{edges:a,incomplete:!0}}function he(e,t){if(!t)return[];let n=new Map(e.map(e=>[e.id,e])),r=new Set([t]),i=[],a=n.get(t)?.parent_id;for(;a&&!r.has(a);){let e=n.get(a);if(!e)break;r.add(a),i.push(e),a=e.parent_id}return i.reverse()}var ge=new Set([`manual`,`wikilink`]),W=280;function _e(e){return e.status&&e.status!==`asserted`?e.status:void 0}function ve(e){return e.method&&!ge.has(e.method)?e.method:void 0}function G(e){return e.status===`proposed`&&!!e.id}function K(e){return new Date(Math.floor(e/1e6)).toISOString().slice(0,10)}function ye(e){let t=e.valid_at==null?void 0:K(e.valid_at),n=e.invalid_at==null?void 0:K(e.invalid_at);if(t&&n)return`valid ${t} → ${n}`;if(t)return`valid from ${t}`;if(n)return`valid until ${n}`}function be(e){if(e.judged_at==null)return;let t=`judged by ${e.judged_by||`a judge`} on ${K(e.judged_at)}`;return e.judge_reason?`${t}: ${e.judge_reason}`:t}function xe(e,t=3){let n=(e.evidence??[]).slice(0,t),r=Math.max(e.evidence_count??0,e.evidence?.length??0);return{rows:n,more:Math.max(0,r-n.length)}}function Se(e,t=W){let n=e.replace(/\s+/g,` `).trim();return n.length>t?n.slice(0,t-1)+`…`:n}var Ce=1e3,we=3,q=1e3;function Te(e){return!!e&&typeof e==`object`&&e.code===`queue_changed`}async function J(e,t,n={}){let r={action:t.action,...t.ids?{ids:t.ids}:{filter:t.filter??{}},...t.reason?{reason:t.reason}:{},...t.scope&&t.scope!==`tenant`?{scope:t.scope}:{},...t.scope===`user`&&t.scopeId?{scope_id:t.scopeId}:{}},i={rulingIds:[],ruled:0,failed:0,skipped:0,total:0,cancelled:!1,failures:[]},a=async()=>{let t=await e.rule({...r,dry_run:!0});return i.skipped=t.skipped,t},o=async(e,t)=>!n.confirm||await n.confirm(e,t)?(i.total=i.ruled+e.matched,!0):(i.cancelled=!0,!1),s;try{s=await a()}catch(e){return i.error=e,i}if(s.matched===0||!await o(s,`first`))return i;let c=0;for(let t=0;t<q&&s.to_rule!==0;t++){let t;try{t=await e.rule({...r,dry_run:!1,expect_count:s.matched})}catch(e){if(!Te(e)||c>=3)return i.error=e,i;c++;try{s=await a()}catch(e){return i.error=e,i}if(s.matched===0||!await o(s,`queue_changed`))return i;continue}t.ruling_id&&i.rulingIds.push(t.ruling_id),i.ruled+=t.ruled,i.failed+=t.failed;for(let e of t.items??[])e.error&&i.failures.push(e);if(n.onProgress?.({ruled:i.ruled,failed:i.failed,total:i.total,chunks:i.rulingIds.length}),t.ruled===0||t.matched<=t.selected)break;try{s=await a()}catch(e){return i.error=e,i}if(s.matched===0)break;if(s.matched>i.total-i.ruled&&!await o(s,`grew`))return i}return i}async function Ee(e,t){let n={reverted:0,changed:0,errors:[]};for(let r of[...t].reverse())try{let t=await e(r);n.reverted+=t.reverted,n.changed+=t.changed}catch(e){n.errors.push(e instanceof Error?e.message:String(e))}return n}function Y(e){return Math.max(1,Math.ceil(e/Ce))}function X(e){return e===`tenant`||e===`user`?e:void 0}function De(e,t){return e.documentRuleStatements?X(t):void 0}function Oe(e,t){return e.filter(e=>G(e)&&!!e.id&&e.from_document_id===t)}function ke(e,t,n,r){return e?{proposals:t,scope:e,incomplete:n,onChanged:r}:void 0}function Z(e,t,n){return e.documentRuleStatements?J({rule:n=>e.documentRuleStatements(n,t.browse)},{action:t.action,...t.ids&&t.ids.length>0?{ids:t.ids}:{filter:{from_document_id:t.documentId}},...t.reason?{reason:t.reason}:{},scope:t.scope,...t.scope===`user`&&t.browse?.scopeId?{scopeId:t.browse.scopeId}:{}},n):Promise.reject(Error(`this data layer cannot rule in bulk`))}function Q(e,t){let n=e=>e.toLocaleString(`en-US`),r=[`${e===`accept`?`Accepted`:`Rejected`} ${n(t.ruled)} statement${t.ruled===1?``:`s`}`];return t.failed>0&&r.push(`${n(t.failed)} did not take the ruling`),t.skipped>0&&r.push(`${n(t.skipped)} skipped: not yours to rule`),r.join(`; `)+`.`}var Ae={"doc.rfc.draft":`#c99a3a`,"doc.rfc.review":`#6a7bd6`,"doc.rfc.confirmed":`#3a9ad6`,"doc.rfc.done":`#3aa06a`,"doc.plan.draft":`#c99a3a`,"doc.plan.review":`#6a7bd6`,"doc.plan.confirmed":`#3a9ad6`,"doc.plan.done":`#3aa06a`,"doc.document.done":`#3aa06a`,"doc.research.done":`#8a6ad6`,"doc.publication.draft":`#c99a3a`,"chunk.draft":`#c99a3a`,"chunk.review":`#6a7bd6`,"chunk.confirmed":`#3a9ad6`,"chunk.done":`#3aa06a`,"chunk.backlog":`#8a8f98`,"chunk.implementation":`#d1863a`,"chunk.merged":`#3aa06a`},je=.16;function Me(e){return e&&Object.keys(e).length>0?e:Ae}function Ne(e,t,n){let r=e??``,i=t??``;if(r&&i&&n[`doc.${r}.${i}`])return n[`doc.${r}.${i}`];if(r&&n[`doc.${r}`])return n[`doc.${r}`]}function Pe(e,t){let n=e??``;return n?t[`chunk.${n}`]:void 0}function $(e){let t=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!t)return;let n=t[1];return n.length===3&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]),`rgba(${parseInt(n.slice(0,2),16)}, ${parseInt(n.slice(2,4),16)}, ${parseInt(n.slice(4,6),16)}, ${je})`}function Fe(e){if(!e)return;let t=$(e);if(t)return{background:t,borderLeft:`3px solid ${e}`}}async function Ie(e){try{return typeof navigator>`u`||!navigator.clipboard?!1:(await navigator.clipboard.writeText(e),!0)}catch{return!1}}function Le({value:e,label:t,compact:n,title:r}){let[i,a]=(0,c.useState)(`idle`),o=async t=>{t.stopPropagation(),t.preventDefault();let n=await Ie(e);a(n?`copied`:`error`),window.setTimeout(()=>a(`idle`),n?1200:1500)},s=i===`copied`?`✓`:i===`error`?`✗`:`⎘`,u=r??`Copy ${t??`id`}: ${e}`,d=(0,l.jsx)(`button`,{type:`button`,className:`id-copy-btn id-copy-${i}`,onClick:o,title:u,"aria-label":u,children:s});return n?d:(0,l.jsxs)(`span`,{className:`id-copy`,children:[t&&(0,l.jsx)(`span`,{className:`id-copy-label`,children:t}),(0,l.jsx)(`code`,{className:`id-copy-value`,title:e,children:e}),d]})}function Re(e){let t=new Map;e.forEach(e=>t.set(e.id,{row:e,children:[]}));let n=[];e.forEach(e=>{let r=t.get(e.id);e.parent_id&&t.has(e.parent_id)?t.get(e.parent_id).children.push(r):n.push(r)});let r=e=>{e.sort((e,t)=>e.row.position-t.row.position),e.forEach(e=>r(e.children))};return r(n),n}function ze(e){return e===`image`?`🖼`:e===`mermaid`?`📊`:``}function Be(e,t){for(let n of e){if(n.row.id===t)return n;let e=Be(n.children,t);if(e)return e}}function Ve({tree:e,selectedId:t,onSelect:n,colorEnabled:r,scheme:i,linkedIds:a}){let[o,s]=(0,c.useState)(()=>new Map),u=(0,c.useCallback)(e=>{s(t=>{let n=new Map(t);return n.set(e,t.get(e)===!1),n})},[]);(0,c.useEffect)(()=>{if(!t)return;let n=He(e,t);n.length!==0&&s(e=>{let t=!1,r=new Map(e);for(let e of n)r.get(e)===!1&&(r.set(e,!0),t=!0);return t?r:e})},[e,t]);let d=r?Me(i):null;return e.length===0?(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`No chunks.`})}):(0,l.jsx)(`ul`,{className:`tree chunk-tree`,children:e.map(e=>(0,l.jsx)(Ue,{node:e,expanded:o,toggle:u,selectedId:t,onSelect:n,tintScheme:d,linkedIds:a},e.row.id))})}function He(e,t){let n=[],r=(e,i)=>{for(let a of e){if(a.row.id===t)return n.push(...i),!0;if(r(a.children,[...i,a.row.id]))return!0}return!1};return r(e,[]),n}function Ue({node:e,expanded:t,toggle:n,selectedId:r,onSelect:i,tintScheme:a,linkedIds:o}){let s=e.children.length>0,c=t.get(e.row.id)!==!1,u=r===e.row.id,d=a?Fe(Pe(e.row.status,a)):void 0,f=o?.has(e.row.id);return(0,l.jsxs)(`li`,{className:`node chunk-node ${u?`selected`:``}`,children:[(0,l.jsxs)(`div`,{className:`row chunk-row`,style:d,children:[(0,l.jsx)(`button`,{type:`button`,className:`tree-caret`,"aria-label":c?`collapse`:`expand`,disabled:!s,onClick:t=>{t.stopPropagation(),s&&n(e.row.id)},children:s?c?`▼`:`▶`:`·`}),(0,l.jsxs)(`button`,{type:`button`,className:`chunk-link`,onClick:()=>i(e),title:e.row.title,children:[ze(e.row.type)&&(0,l.jsx)(`span`,{className:`chunk-type-icon`,"aria-hidden":!0,children:ze(e.row.type)}),(0,l.jsx)(`span`,{className:`chunk-title`,children:e.row.title||`(untitled)`}),e.row.type&&(0,l.jsx)(`span`,{className:`chunk-badge`,children:e.row.type}),e.row.status&&(0,l.jsx)(`span`,{className:`chunk-badge chunk-status`,children:e.row.status}),f&&(0,l.jsx)(`span`,{className:`chunk-link-badge`,title:`Has cross-reference links`,"aria-label":`linked`,children:`🔗`})]}),(0,l.jsx)(Le,{value:e.row.id,compact:!0,title:`Copy chunk id: ${e.row.id}`})]}),s&&c&&(0,l.jsx)(`ul`,{className:`children chunk-children`,children:e.children.map(e=>(0,l.jsx)(Ue,{node:e,expanded:t,toggle:n,selectedId:r,onSelect:i,tintScheme:a,linkedIds:o},e.row.id))})]})}var We=0;function Ge(e){let t=e?.closest(`g.node`);return t?/flowchart-(.+)-\d+$/.exec(t.id)?.[1]:void 0}function Ke({code:e,onNodeClick:t}){let n=(0,c.useRef)(null),[r,i]=(0,c.useState)({});return(0,c.useEffect)(()=>{let t=!1;return(async()=>{try{let r=(await import(`mermaid`)).default,a=n.current?.closest(`[data-theme]`)?.getAttribute(`data-theme`),o=!a||a===`dark`;r.initialize({startOnLoad:!1,theme:o?`dark`:`default`,securityLevel:`strict`});let{svg:s}=await r.render(`lc-mmd-${We++}`,e);t||i({svg:s})}catch{t||i({err:!0})}})(),()=>{t=!0}},[e]),r.err?(0,l.jsx)(`pre`,{className:`md-pre md-mermaid-error`,title:`diagram failed to render`,children:(0,l.jsx)(`code`,{children:e})}):r.svg?(0,l.jsx)(`div`,{ref:n,className:t?`md-mermaid md-mermaid-nav`:`md-mermaid`,onClick:t&&(e=>{let n=Ge(e.target);n&&t(n)}),dangerouslySetInnerHTML:{__html:r.svg}}):(0,l.jsx)(`div`,{ref:n,className:`md-mermaid md-mermaid-loading`,children:`rendering diagram…`})}function qe({chunk:e,scope:t,browse:n,onClose:r,onSaved:i}){let a=T(),[o,s]=(0,c.useState)(e.title),[u,d]=(0,c.useState)(e.type??``),[f,p]=(0,c.useState)(e.status??``),[m,h]=(0,c.useState)(e.body??``),[g,_]=(0,c.useState)(e.fields?JSON.stringify(e.fields,null,2):``),[v,y]=(0,c.useState)((e.tags??[]).join(`, `)),[b,x]=(0,c.useState)(!1),[S,C]=(0,c.useState)(null),[w,E]=(0,c.useState)(!1),D=u===`mermaid`,O=u===`image`||!!e.asset,[k,A]=(0,c.useState)(m);(0,c.useEffect)(()=>{if(!D)return;let e=setTimeout(()=>A(m),400);return()=>clearTimeout(e)},[m,D]);let j=async o=>{C(null),x(!0);try{let{mediaType:s,data:c}=await de(o);i(await a.documentSetAsset(e.id,s,c,o.name,t,n)),r()}catch(e){C(e instanceof Error?e.message:String(e)),x(!1)}},M=D?`Mermaid source`:O?`Caption (optional)`:`Body (Markdown)`;return(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:r,children:(0,l.jsxs)(`form`,{className:`modal chunk-editor`,onClick:e=>e.stopPropagation(),onSubmit:async s=>{s.preventDefault(),C(null),E(!1);let c={body:m,title:o,type:u,status:f,tags:v.split(`,`).map(e=>e.trim()).filter(e=>e!==``)};if(g.trim()!==``)try{c.fields=JSON.parse(g)}catch{C(`fields must be valid JSON`);return}x(!0);try{i(await a.documentUpdateChunk(e.id,e.revision,c,t,n)),r()}catch(e){let t=e instanceof Error?e.message:String(e);C(t),E(/revision conflict/i.test(t)),x(!1)}},children:[(0,l.jsxs)(`div`,{className:`modal-header sticky-top`,children:[(0,l.jsx)(`h3`,{children:`Edit chunk`}),(0,l.jsxs)(`div`,{className:`modal-buttons modal-buttons-top`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:r,disabled:b,children:`cancel`}),(0,l.jsx)(`button`,{type:`submit`,className:`primary`,disabled:b,children:b?`saving…`:`save`})]})]}),S&&(0,l.jsxs)(`div`,{className:`modal-err`,children:[S,w&&` — reopen the chunk to load the latest, then reapply your edit.`]}),(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Title`}),(0,l.jsx)(`input`,{className:`path-modal-input`,value:o,onChange:e=>s(e.target.value)})]}),(0,l.jsxs)(`div`,{className:`chunk-editor-row`,children:[(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Type`}),(0,l.jsx)(`input`,{className:`path-modal-input`,value:u,placeholder:`(none)`,onChange:e=>d(e.target.value)})]}),(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Status`}),(0,l.jsx)(`input`,{className:`path-modal-input`,value:f,placeholder:`(none)`,onChange:e=>p(e.target.value)})]})]}),(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Tags`}),(0,l.jsx)(`input`,{className:`path-modal-input`,value:v,placeholder:`comma-separated, nest with a slash: area/sub, priority/high`,onChange:e=>y(e.target.value)})]}),O&&(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Replace image`}),(0,l.jsx)(`input`,{type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&j(t)}})]}),(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:M}),(0,l.jsx)(`textarea`,{className:`modal-textarea chunk-body-input`,rows:D?8:12,value:m,onChange:e=>h(e.target.value)})]}),D&&(0,l.jsxs)(`div`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Preview`}),(0,l.jsx)(`div`,{className:`chunk-mermaid-preview`,children:k.trim()?(0,l.jsx)(Ke,{code:k}):(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`(enter Mermaid source above)`})})]}),(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Fields (JSON, optional)`}),(0,l.jsx)(`textarea`,{className:`modal-textarea chunk-fields-input`,rows:4,value:g,placeholder:`{}`,onChange:e=>_(e.target.value)})]})]})})}function Je({chunk:e,scope:t,browse:n,onClose:r,onSaved:i}){let a=T(),[o,s]=(0,c.useState)(null),[u,d]=(0,c.useState)(e.type??``),[f,p]=(0,c.useState)(!1),[m,h]=(0,c.useState)(null),[g,_]=(0,c.useState)(null);(0,c.useEffect)(()=>{let e=!1;return a.documentEntityTypes?.(t,n).then(t=>{e||s(t)}).catch(t=>{e||h(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[a,t,n]);let y=o?v(o,e.type):[],b=u.toLowerCase()===(e.type??``).toLowerCase();return(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:r,children:(0,l.jsxs)(`form`,{className:`modal`,onClick:e=>e.stopPropagation(),onSubmit:async o=>{if(o.preventDefault(),!(b||f)){h(null),p(!0);try{let o=await a.documentUpdateChunk(e.id,e.revision,{type:u},t,n);if(i(o),o.not_announced){_(o.not_announced),p(!1);return}r()}catch(e){h(e instanceof Error?e.message:String(e)),p(!1)}}},children:[(0,l.jsx)(`h3`,{children:`Change type`}),(0,l.jsxs)(`p`,{className:`modal-context`,children:[`“`,e.title||`(untitled)`,`” is a subject (`,(0,l.jsx)(`code`,{children:e.entity?.natural_key}),`). Its key stays as it is; relations about it are re-checked against the new type.`]}),m&&(0,l.jsx)(`div`,{className:`modal-err`,children:m}),g?(0,l.jsxs)(`div`,{className:`modal-err`,children:[`The type was changed, but subscribers were not told: `,g]}):(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:`Type`}),o===null?(0,l.jsx)(`span`,{className:`doc-empty-body`,children:m?``:`loading types…`}):(0,l.jsx)(`select`,{className:`path-modal-input`,value:u,disabled:f,onChange:e=>d(e.target.value),children:y.map(e=>(0,l.jsx)(`option`,{value:e,children:e},e))})]}),(0,l.jsxs)(`div`,{className:`modal-buttons`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:r,disabled:f,children:g?`close`:`cancel`}),!g&&(0,l.jsx)(`button`,{type:`submit`,className:`primary`,disabled:f||b||o===null,children:f?`saving…`:`change type`})]})]})})}function Ye(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function Xe(e){if(!e||typeof e!=`object`)return;let t=e.classification;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=t,r={};return typeof n.by==`string`&&(r.by=n.by),typeof n.at==`number`&&(r.at=n.at),typeof n.applied_type==`string`&&n.applied_type&&(r.applied_type=n.applied_type),typeof n.proposed_type==`string`&&n.proposed_type&&(r.proposed_type=n.proposed_type),n.proposed_fields&&typeof n.proposed_fields==`object`&&!Array.isArray(n.proposed_fields)&&(r.proposed_fields=n.proposed_fields),Ye(n.proposed_tags)&&(r.proposed_tags=n.proposed_tags),Ye(n.statements)&&(r.statements=n.statements),r}function Ze(e){let t=Xe(e);if(!t)return;let n=t.proposed_tags??[],r=t.statements?.length??0;if(t.proposed_type||n.length!==0||r!==0)return{proposedType:t.proposed_type,proposedTags:n,statementCount:r}}function Qe(e){let t=e.write===`report`;switch(e.result){case`classified`:return t?`would be classified`:`classified`;case`proposed`:return t?`would be proposed for review`:`proposed — waits for review`;case`kept`:return`kept — the type was set by hand`;case`unclassified`:return`unclassified — nothing decided`;default:return String(e.result)}}function $e(e){if(!e.class)return;if(e.result===`kept`)return`not applied`;let t=e.write===`report`;return e.live?t?`would be applied`:`applied`:t?`would be proposed`:`proposed`}function et(e){return e.write===`report`?e.result===`classified`||e.result===`proposed`||(e.concepts?.length??0)>0||(e.issued_by?.length??0)>0:!1}function tt(e){return e==null||!Number.isFinite(e)?``:`${Math.round(e*100)}%`}var nt={rules:`Rules`,vote:`Neighbourhood vote`,model:`Model`};function rt(e){return nt[e]??e}function it(e){let t=[];e.quote&&t.push(e.from?`“${e.quote}” (${e.from})`:`“${e.quote}”`),e.votes!=null&&t.push(`${e.votes} vote${e.votes===1?``:`s`}`);let n=tt(e.share);return n&&t.push(n),t.join(` · `)}function at(e){return{label:rt(e.step),...e.chosen?{chosen:e.chosen}:{},...e.method?{method:e.method}:{},...e.neighbours?{neighbours:e.neighbours}:{},...e.reason?{reason:e.reason}:{},candidates:(e.candidates??[]).map(e=>({class:e.class,detail:it(e)}))}}function ot(e){let t=[];e.type&&t.push(`type ${e.type}`);let n=e.accepted_statements?.length??0;n>0&&t.push(`${n} statement${n===1?``:`s`}`),e.tags&&e.tags.length>0&&t.push(`tags ${e.tags.join(`, `)}`);let r=[];e.type_pending&&r.push(`The proposed class stays pending: another document already holds its identity.`),e.skipped_type&&r.push(`Class ${e.skipped_type} was not applied: it is not a declared document class.`);let i=e.skipped_statements?.length??0;return i>0&&r.push(`${i} statement${i===1?` was`:`s were`} skipped (already ruled on, or not this document's proposal).`),e.skipped_tags&&e.skipped_tags.length>0&&r.push(`Tags not applied (not concepts of the ontology): ${e.skipped_tags.join(`, `)}.`),r.push(...e.warnings??[]),{applied:t.length>0?`Accepted ${t.join(`, `)}.`:`Nothing was accepted.`,notices:r}}function st(e){let t=e instanceof Error?e.message:String(e);return t.includes(`nothing_pending`)?`Nothing is pending for this document — it may already have been accepted.`:t}function ct({documentId:e,scope:t,browse:n,rootFields:r,requestKey:i,onClose:a,onChanged:o}){let s=T(),[u,d]=(0,c.useState)(null),[f,p]=(0,c.useState)(!1),[m,h]=(0,c.useState)(null),[g,_]=(0,c.useState)(!1),[v,y]=(0,c.useState)(null),[b,x]=(0,c.useState)(null),S=(0,c.useMemo)(()=>s.documentAcceptClassification?Ze(r):void 0,[s,r]);(0,c.useEffect)(()=>{if(i===0||!s.documentClassify)return;let r=!1;return p(!0),h(null),d(null),s.documentClassify(e,`report`,t,n).then(e=>!r&&d(e)).catch(e=>!r&&h(st(e))).finally(()=>!r&&p(!1)),()=>{r=!0}},[s,e,t,n,i]);let C=async()=>{if(s.documentClassify){p(!0),h(null);try{d(await s.documentClassify(e,`propose`,t,n)),o()}catch(e){h(st(e))}finally{p(!1)}}},w=async()=>{if(s.documentAcceptClassification){_(!0),y(null);try{x(await s.documentAcceptClassification(e,t,n)),o()}catch(e){y(st(e))}finally{_(!1)}}},E=i>0;if(!E&&!S&&!b&&!v)return null;let D=b?ot(b):void 0;return(0,l.jsxs)(`div`,{className:`doc-classify`,children:[S&&(0,l.jsxs)(`div`,{className:`doc-classify-pending`,children:[(0,l.jsx)(`span`,{className:`doc-classify-label`,children:`Pending classification`}),S.proposedType&&(0,l.jsxs)(`span`,{children:[`class `,(0,l.jsx)(`strong`,{children:S.proposedType})]}),S.proposedTags.length>0&&(0,l.jsxs)(`span`,{children:[`tags`,` `,S.proposedTags.map(e=>(0,l.jsx)(`span`,{className:`chunk-tag`,children:e},e))]}),S.statementCount>0&&(0,l.jsxs)(`span`,{children:[S.statementCount,` proposed statement`,S.statementCount===1?``:`s`]}),(0,l.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>void w(),children:g?`Accepting…`:`Accept`})]}),v&&(0,l.jsxs)(`div`,{className:`doc-classify-err`,role:`alert`,children:[v,(0,l.jsx)(`button`,{type:`button`,className:`doc-classify-dismiss`,onClick:()=>y(null),"aria-label":`Dismiss`,children:`×`})]}),D&&(0,l.jsxs)(`div`,{className:`doc-classify-notice`,role:`status`,children:[(0,l.jsx)(`span`,{children:D.applied}),D.notices.map((e,t)=>(0,l.jsx)(`span`,{className:`doc-classify-warn`,children:e},t)),(0,l.jsx)(`button`,{type:`button`,className:`doc-classify-dismiss`,onClick:()=>x(null),"aria-label":`Dismiss`,children:`×`})]}),E&&(0,l.jsxs)(`div`,{className:`doc-classify-panel`,children:[(0,l.jsxs)(`div`,{className:`doc-classify-head`,children:[(0,l.jsx)(`h4`,{children:`Classify`}),u&&(0,l.jsx)(`span`,{className:`doc-classify-result ${u.result}`,children:Qe(u)}),u?.write===`report`&&(0,l.jsx)(`span`,{className:`doc-classify-hint`,children:`report only — nothing written`}),(0,l.jsx)(`button`,{type:`button`,className:`doc-classify-dismiss`,onClick:a,"aria-label":`Close`,children:`×`})]}),!u&&!m&&(0,l.jsx)(`p`,{className:`doc-classify-hint`,children:`Classifying…`}),m&&(0,l.jsx)(`p`,{className:`doc-classify-err`,role:`alert`,children:m}),u&&(0,l.jsx)(lt,{answer:u}),u&&et(u)&&(0,l.jsx)(`div`,{className:`doc-classify-actions`,children:(0,l.jsx)(`button`,{type:`button`,disabled:f,onClick:()=>void C(),title:`Apply a unique rule match to the document; file everything else for review`,children:f?`Applying…`:`Apply`})})]})]})}function lt({answer:e}){let t=$e(e),n=Object.entries(e.fields??{}),r=e.issued_by??[],i=e.concepts??[],a=(e.steps??[]).map(at),o=e.statements?.length??0;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`dl`,{className:`doc-classify-rows`,children:[e.class&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`class`}),(0,l.jsxs)(`dd`,{children:[(0,l.jsx)(`strong`,{children:e.class}),t&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` (`,t,`)`]})]})]}),e.work_key&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`work key`}),(0,l.jsx)(`dd`,{className:`doc-classify-mono`,children:e.work_key})]}),n.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`fields`}),(0,l.jsx)(`dd`,{className:`doc-classify-mono`,children:n.map(([e,t])=>`${e}=${typeof t==`string`?t:JSON.stringify(t)}`).join(` · `)})]}),r.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`issued by`}),(0,l.jsx)(`dd`,{children:r.map((e,t)=>(0,l.jsxs)(`span`,{className:`doc-classify-item`,title:e.quote,children:[e.instance,e.quote&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` “`,e.quote,`”`]})]},`${e.instance}-${t}`))})]}),i.length>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`concepts`}),(0,l.jsx)(`dd`,{children:i.map(e=>(0,l.jsxs)(`span`,{className:`doc-classify-item`,title:e.tag,children:[e.concept,(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` `,tt(e.share)]})]},e.tag))})]}),o>0&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`statements`}),(0,l.jsxs)(`dd`,{children:[o,` written`,e.statements.some(e=>e.status===`proposed`)&&(0,l.jsx)(`span`,{className:`doc-classify-hint`,children:` (proposed ones wait for review)`})]})]})]}),a.length>0&&(0,l.jsx)(`ol`,{className:`doc-classify-steps`,children:a.map((e,t)=>(0,l.jsxs)(`li`,{children:[(0,l.jsx)(`span`,{className:`doc-classify-step`,children:e.label}),e.method&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` [`,e.method,`]`]}),e.chosen?(0,l.jsxs)(l.Fragment,{children:[` → `,(0,l.jsx)(`strong`,{children:e.chosen})]}):(0,l.jsx)(`span`,{className:`doc-classify-hint`,children:` no choice`}),e.neighbours!=null&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` · `,e.neighbours,` neighbours`]}),e.reason&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` — `,e.reason]}),e.candidates.length>0&&(0,l.jsxs)(`details`,{className:`doc-classify-candidates`,children:[(0,l.jsxs)(`summary`,{children:[e.candidates.length,` candidate`,e.candidates.length===1?``:`s`]}),(0,l.jsx)(`ul`,{children:e.candidates.map((e,t)=>(0,l.jsxs)(`li`,{children:[(0,l.jsx)(`strong`,{children:e.class}),e.detail&&(0,l.jsxs)(`span`,{className:`doc-classify-hint`,children:[` `,e.detail]})]},`${e.class}-${t}`))})]})]},`${e.label}-${t}`))}),e.warnings&&e.warnings.length>0&&(0,l.jsx)(`ul`,{className:`doc-classify-warnings`,children:e.warnings.map((e,t)=>(0,l.jsx)(`li`,{className:`doc-classify-warn`,children:e},t))})]})}function ut(e){let t=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e??``).trim());if(!t)return`#888888`;let n=t[1];return n.length===3&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]),`#`+n.toLowerCase()}function dt({documentId:e,rootChunkId:t,docType:n,docStatus:r,chunkStatuses:i,scope:a,browse:o,onClose:s,onSaved:u}){let d=T(),[f,p]=(0,c.useState)(null),[m,h]=(0,c.useState)(!1),[g,_]=(0,c.useState)({}),[v,y]=(0,c.useState)(!1),[b,x]=(0,c.useState)(null),[S,C]=(0,c.useState)(null),w=(0,c.useMemo)(()=>{let e=new Set(Object.keys(Ae));n&&e.add(`doc.${n}.${r||`draft`}`);for(let t of i)t&&e.add(`chunk.${t}`);return[...e].sort()},[n,r,i]);(0,c.useEffect)(()=>{let e=!1;return d.documentGetChunk(t,a,o).then(t=>{if(e)return;p(t);let n=t.fields??{};h(n.color_enabled===!0);let r=n.color_scheme??{};_({...Ae,...r})}).catch(t=>!e&&C(t instanceof Error?t.message:String(t))),()=>{e=!0}},[d,t,a,o]);let E=(e,t)=>_(n=>({...n,[e]:t})),D=e=>({...e??{},color_enabled:m,color_scheme:g}),O=async()=>{if(f){y(!0),C(null),x(null);try{await d.documentUpdateChunk(t,f.revision,{fields:D(f.fields)},a,o),u(),s()}catch(e){C(e instanceof Error?e.message:String(e)),y(!1)}}},k=async()=>{if(!n)C(`this document has no type to match`);else{y(!0),C(null),x(null);try{let{documents:t}=await d.documentsSummary({underPath:`/`},a,o),r=(t??[]).filter(t=>t.type===n&&t.document_id!==e&&t.root_chunk_id),i=0;for(let e of r)try{let t=await d.documentGetChunk(e.root_chunk_id,a,o);await d.documentUpdateChunk(e.root_chunk_id,t.revision,{fields:D(t.fields)},a,o),i++}catch{}x(`Applied to ${i} other ${n} document(s).`),u()}catch(e){C(e instanceof Error?e.message:String(e))}finally{y(!1)}}},A=w.filter(e=>e.startsWith(`doc.`)),j=w.filter(e=>e.startsWith(`chunk.`));return(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:s,children:(0,l.jsxs)(`div`,{className:`modal scheme-editor`,onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)(`div`,{className:`scheme-editor-head`,children:[(0,l.jsx)(`h3`,{children:`Document colors`}),(0,l.jsxs)(`div`,{className:`scheme-editor-actions`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:s,disabled:v,children:`cancel`}),(0,l.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>void O(),disabled:v||!f,children:v?`saving…`:`save`})]})]}),S&&(0,l.jsx)(`div`,{className:`modal-err`,children:S}),f?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`label`,{className:`scheme-toggle`,children:[(0,l.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked)}),(0,l.jsx)(`span`,{children:`Enable coloring for this document`})]}),(0,l.jsx)(`p`,{className:`modal-context`,children:`Document rows are tinted by type + status; chunk tiles by status. Colors apply as a semi-transparent wash so text stays readable.`}),(0,l.jsxs)(`div`,{className:`scheme-group`,children:[(0,l.jsx)(`h4`,{children:`Document (type · status)`}),A.map(e=>(0,l.jsx)(ft,{label:e.slice(4),value:g[e],onChange:t=>E(e,t)},e))]}),(0,l.jsxs)(`div`,{className:`scheme-group`,children:[(0,l.jsx)(`h4`,{children:`Chunks (status)`}),j.map(e=>(0,l.jsx)(ft,{label:e.slice(6),value:g[e],onChange:t=>E(e,t)},e))]}),(0,l.jsxs)(`div`,{className:`scheme-editor-foot`,children:[(0,l.jsxs)(`button`,{type:`button`,onClick:()=>void k(),disabled:v||!n,title:n?`Apply this palette to every other ${n} document`:`This document has no type`,children:[`copy to all `,n||`same-type`,` documents`]}),b&&(0,l.jsx)(`span`,{className:`scheme-status`,children:b})]})]}):(0,l.jsx)(`p`,{className:`modal-context`,children:`Loading…`})]})})}function ft({label:e,value:t,onChange:n}){let r=ut(t);return(0,l.jsxs)(`label`,{className:`scheme-row`,children:[(0,l.jsx)(`input`,{type:`color`,value:r,onChange:e=>n(e.target.value)}),(0,l.jsx)(`span`,{className:`scheme-key`,children:e}),(0,l.jsx)(`code`,{className:`scheme-hex`,children:r})]})}function pt({id:e,title:t,targetDocumentId:n,documentId:r,onSelectChunk:i,onOpenDocument:a}){let o=t||e.slice(0,8);return!n||n===r?(0,l.jsx)(`button`,{type:`button`,className:`doc-ref-target`,onClick:()=>i(e),children:o}):a?(0,l.jsxs)(`button`,{type:`button`,className:`doc-ref-target external`,title:`In another document — opens it at this chunk`,onClick:()=>a(n,e,t),children:[o,` ↗`]}):(0,l.jsxs)(`span`,{className:`doc-ref-target external`,title:`In another document`,children:[o,` ↗`]})}function mt({statement:e}){let t=_e(e),n=ve(e),r=be(e),i=ye(e),{rows:a,more:o}=xe(e);return(0,l.jsxs)(l.Fragment,{children:[t&&(0,l.jsx)(`span`,{className:`doc-stmt-status ${t}`,children:t}),n&&(0,l.jsx)(`span`,{className:`doc-stmt-method`,title:`how this relation was made`,children:n}),r&&(0,l.jsx)(`span`,{className:`doc-stmt-verdict`,title:r,children:`judged`}),i&&(0,l.jsx)(`span`,{className:`doc-stmt-valid`,children:i}),a.length>0&&(0,l.jsxs)(`ul`,{className:`doc-stmt-evidence`,children:[a.map(e=>(0,l.jsxs)(`li`,{title:e.quote,children:[`“`,Se(e.quote),`”`,e.stale&&(0,l.jsx)(`span`,{className:`doc-stmt-stale`,children:` (source changed)`})]},e.id)),o>0&&(0,l.jsxs)(`li`,{className:`doc-stmt-more`,children:[`+`,o,` more`]})]})]})}function ht({id:e,onRule:t}){let[n,r]=(0,c.useState)(!1),[i,a]=(0,c.useState)(``),[o,s]=(0,c.useState)(!1),[u,d]=(0,c.useState)(null),f=async n=>{s(!0),d(null);try{await t(e,n,n?void 0:i.trim()),r(!1),a(``)}catch(e){d(e instanceof Error?e.message:String(e))}finally{s(!1)}};return(0,l.jsxs)(`span`,{className:`doc-stmt-review`,children:[n?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`text`,"aria-label":`Reason for rejecting`,placeholder:`why reject?`,value:i,disabled:o,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i.trim()&&f(!1),e.key===`Escape`&&r(!1)},autoFocus:!0}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,disabled:o||!i.trim(),onClick:()=>void f(!1),children:`Reject`}),(0,l.jsx)(`button`,{type:`button`,disabled:o,onClick:()=>r(!1),children:`Cancel`})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{type:`button`,disabled:o,onClick:()=>void f(!0),children:`Accept`}),(0,l.jsx)(`button`,{type:`button`,disabled:o,onClick:()=>r(!0),children:`Reject…`})]}),u&&(0,l.jsx)(`span`,{className:`doc-stmt-err`,role:`alert`,children:u})]})}var gt=3;function _t({documentId:e,proposals:t,incomplete:n,scope:r,browse:i,onChanged:a,onSelectChunk:o,onOpenDocument:s}){let u=T(),[d,f]=(0,c.useState)(new Set),[p,m]=(0,c.useState)({kind:`idle`}),[h,g]=(0,c.useState)(``),[_,v]=(0,c.useState)(null),[y,b]=(0,c.useState)(null),x=(0,c.useRef)(null),S=new Set(t.map(e=>e.id)),C=[...d].filter(e=>S.has(e)),w=p.kind!==`idle`&&p.kind!==`reason`,E=(e,t)=>{v(null),b(null),e===`reject`?m({kind:`reason`,action:e,all:t}):D(e,t,``)},D=async(t,n,o)=>{m({kind:`counting`,action:t,all:n});let s;try{s=await Z(u,{documentId:e,action:t,ids:n?void 0:C,reason:o.trim()||void 0,scope:r,browse:i},{confirm:(e,r)=>new Promise(i=>{x.current=i,m({kind:`confirm`,action:t,all:n,dry:e,changed:r!==`first`})}),onProgress:e=>m({kind:`ruling`,action:t,ruled:e.ruled,total:e.total})})}catch(e){s={rulingIds:[],ruled:0,failed:0,skipped:0,total:0,cancelled:!1,failures:[],error:e}}x.current=null,m({kind:`idle`}),g(``),s.rulingIds.length>0?(f(new Set),b({text:Q(t,s),rulingIds:s.rulingIds}),a()):s.error===void 0&&!s.cancelled&&b({text:`Nothing to rule: no proposals match.`,rulingIds:[]}),s.error!==void 0&&v(s.error instanceof Error?s.error.message:String(s.error))},O=e=>{e&&p.kind===`confirm`&&m({kind:`ruling`,action:p.action}),x.current?.(e)},k=async()=>{if(!y||!u.documentRevertRuling)return;let e=y,t=await Ee(e=>u.documentRevertRuling(e,r,i),e.rulingIds),n=[`${t.reverted} came back to review`];t.changed>0&&n.push(`${t.changed} changed since and left as ruled`),t.errors.length>0&&n.push(`not undone: ${t.errors.join(`; `)}`),b({...e,undone:!0,text:n.join(`; `)+`.`}),a()},A=e=>f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),j=t.length>0&&C.length===t.length,M=t.length===0&&!n;return(0,l.jsxs)(`div`,{className:`doc-conn-group doc-bulk`,children:[(0,l.jsxs)(`h5`,{children:[`Proposals from this document (`,t.length,`)`]}),(0,l.jsxs)(`div`,{className:`doc-bulk-bar`,children:[(0,l.jsxs)(`label`,{children:[(0,l.jsx)(`input`,{type:`checkbox`,"aria-label":`select every proposal shown`,checked:j,disabled:w||t.length===0,onChange:()=>f(j?new Set:new Set(S))}),` `,`all shown`]}),(0,l.jsxs)(`button`,{type:`button`,disabled:w||C.length===0,onClick:()=>E(`accept`,!1),children:[`Accept selected (`,C.length,`)`]}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,disabled:w||C.length===0,onClick:()=>E(`reject`,!1),children:`Reject selected…`}),(0,l.jsx)(`button`,{type:`button`,disabled:w||M,onClick:()=>E(`accept`,!0),children:`Accept all from this document`}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,disabled:w||M,onClick:()=>E(`reject`,!0),children:`Reject all…`})]}),p.kind===`reason`&&(0,l.jsxs)(`form`,{className:`doc-bulk-step`,onSubmit:e=>{e.preventDefault(),h.trim()&&D(p.action,p.all,h)},children:[(0,l.jsx)(`input`,{type:`text`,"aria-label":`Reason for rejecting`,placeholder:`why reject?`,value:h,onChange:e=>g(e.target.value),autoFocus:!0}),(0,l.jsx)(`button`,{type:`submit`,className:`danger`,disabled:!h.trim(),children:`Count`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>m({kind:`idle`}),children:`Cancel`})]}),p.kind===`counting`&&(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`counting…`}),p.kind===`confirm`&&(0,l.jsx)(vt,{step:p,onAnswer:O}),p.kind===`ruling`&&(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:p.total?`ruled ${p.ruled??0} of ${p.total}…`:`ruling…`}),_&&(0,l.jsx)(`p`,{className:`doc-stmt-err`,role:`alert`,children:_}),y&&(0,l.jsxs)(`p`,{className:`doc-bulk-result`,role:`status`,children:[y.text,y.rulingIds.length>0&&!y.undone&&u.documentRevertRuling&&(0,l.jsx)(`button`,{type:`button`,onClick:()=>void k(),children:`Undo`})]}),t.length===0?(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`none`}):(0,l.jsx)(`ul`,{className:`doc-conn-list`,children:t.map(t=>(0,l.jsxs)(`li`,{className:`doc-conn-row`,children:[(0,l.jsx)(`input`,{type:`checkbox`,"aria-label":`select ${t.from_title??t.from_id} ${t.kind} ${t.to_title??t.to_id}`,checked:d.has(t.id),disabled:w,onChange:()=>A(t.id)}),(0,l.jsx)(pt,{id:t.from_id,title:t.from_title,targetDocumentId:t.from_document_id,documentId:e,onSelectChunk:o,onOpenDocument:s}),(0,l.jsx)(`span`,{className:`doc-ref-kind`,children:t.kind}),(0,l.jsx)(pt,{id:t.to_id,title:t.to_title,targetDocumentId:t.to_document_id,documentId:e,onSelectChunk:o,onOpenDocument:s}),(0,l.jsx)(mt,{statement:t})]},t.id))})]})}function vt({step:e,onAnswer:t}){let{dry:n}=e,r=e.action===`accept`?`Accept`:`Reject`,i=Y(n.matched);return(0,l.jsxs)(`div`,{className:`doc-bulk-step doc-bulk-confirm`,children:[e.changed&&(0,l.jsx)(`p`,{className:`doc-bulk-warn`,children:`The proposals changed since the last count; counted again.`}),(0,l.jsxs)(`p`,{children:[r,` `,n.matched,` statement`,n.matched===1?``:`s`,e.all?` filed from this document`:``,i>1?`, in ${i} rulings of up to 1,000`:``,`?`,n.skipped>0&&` ${n.skipped} of them are not yours to rule and will be skipped.`]}),(n.sample??[]).length>0&&(0,l.jsx)(`ul`,{className:`doc-bulk-sample`,children:(n.sample??[]).slice(0,gt).map(e=>(0,l.jsxs)(`li`,{children:[e.from_title||e.from_id,` `,(0,l.jsx)(`span`,{className:`doc-ref-kind`,children:e.kind}),` `,e.to_title||e.to_id]},e.id))}),(0,l.jsxs)(`button`,{type:`button`,className:e.action===`reject`?`danger`:void 0,onClick:()=>t(!0),children:[r,` `,n.matched]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>t(!1),children:`Cancel`})]})}var yt=8,bt=20;function xt(e){return/embedder|embedding|vector|semantic|not configured/i.test(e)}function St({documentId:e,selectedId:t,scope:n,browse:r,onSelectChunk:i,onOpenDocument:a,refreshKey:o,review:s}){let u=T(),[d,f]=(0,c.useState)(!1),[p,m]=(0,c.useState)(!1),[h,g]=(0,c.useState)(void 0),[_,v]=(0,c.useState)([]),[y,b]=(0,c.useState)([]),[x,S]=(0,c.useState)(null),[C,w]=(0,c.useState)([]),[E,D]=(0,c.useState)(!1);(0,c.useEffect)(()=>{if(!d||!t)return;let e=t,i=!1;return m(!0),Promise.allSettled([u.documentBacklinks(e,n,r),u.documentRelated(e,n,r,yt),u.documentUnlinkedMentions(e,n,r,bt)]).then(([t,n,r])=>{if(!i){if(v(t.status===`fulfilled`?t.value.backlinks??[]:[]),n.status===`fulfilled`)b(n.value.related??[]),S(null);else{b([]);let e=n.reason instanceof Error?n.reason.message:String(n.reason);S(xt(e)?`semantic search not configured`:e)}r.status===`fulfilled`?(w(r.value.unlinked_mentions??[]),D(!!r.value.truncated)):(w([]),D(!1)),g(e),m(!1)}}),()=>{i=!0}},[u,d,t,n,r,o]);let O=(t,n,r)=>(0,l.jsx)(pt,{id:t,title:n,targetDocumentId:r,documentId:e,onSelectChunk:i,onOpenDocument:a}),k=!!(d&&t&&!p&&h===t);return(0,l.jsxs)(`div`,{className:`doc-conn`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`doc-conn-toggle`,onClick:()=>f(e=>!e),children:[d?`▼`:`▶`,` Connections`]}),d&&(0,l.jsxs)(`div`,{className:`doc-conn-body`,children:[s&&(0,l.jsx)(_t,{documentId:e,proposals:s.proposals,incomplete:s.incomplete,scope:s.scope,browse:r,onChanged:s.onChanged,onSelectChunk:i,onOpenDocument:a}),t?k?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`doc-conn-group`,children:[(0,l.jsx)(`h5`,{children:`Backlinks`}),_.length===0?(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`none`}):(0,l.jsx)(`ul`,{className:`doc-conn-list`,children:_.map((e,t)=>(0,l.jsxs)(`li`,{className:`doc-conn-row`,children:[O(e.from_id,e.from_title,e.from_document_id),(0,l.jsx)(`span`,{className:`doc-ref-kind`,children:e.kind}),e.auto&&(0,l.jsx)(`span`,{className:`doc-conn-auto`,title:`Auto-linked from a [[wikilink]]`,children:`auto`}),(0,l.jsx)(mt,{statement:e})]},`${e.from_id}-${e.kind}-${t}`))})]}),(0,l.jsxs)(`div`,{className:`doc-conn-group`,children:[(0,l.jsx)(`h5`,{children:`Related`}),x?(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:x}):y.length===0?(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`none`}):(0,l.jsx)(`ul`,{className:`doc-conn-list`,children:y.map((e,t)=>(0,l.jsxs)(`li`,{className:`doc-conn-row`,children:[O(e.chunk_id,e.title,e.document_id),(0,l.jsx)(`span`,{className:`doc-conn-score`,title:`similarity score`,children:e.score.toFixed(2)})]},`${e.chunk_id}-${t}`))})]}),(0,l.jsxs)(`div`,{className:`doc-conn-group`,children:[(0,l.jsx)(`h5`,{children:`Unlinked mentions`}),C.length===0?(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`none`}):(0,l.jsxs)(`ul`,{className:`doc-conn-list`,children:[C.map((e,t)=>(0,l.jsx)(`li`,{className:`doc-conn-row`,children:O(e.chunk_id,e.title,e.document_id)},`${e.chunk_id}-${t}`)),E&&(0,l.jsx)(`li`,{className:`doc-conn-more`,"aria-hidden":!0,children:`(more…)`})]})]})]}):(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`loading…`}):(0,l.jsx)(`p`,{className:`doc-conn-empty`,children:`Select a chunk.`})]})]})}var Ct=24;function wt({edges:e,documentId:t,selectedId:n,onSelectChunk:r,onOpenDocument:i,onRuleStatement:a,incomplete:o}){let[s,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(!1);if(e.length===0)return null;let p=n?e.filter(e=>e.from_id===n||e.to_id===n):[],m=d?e:e.slice(0,Ct),h=Et(m);return(0,l.jsxs)(`div`,{className:`doc-refs`,children:[o&&(0,l.jsxs)(`p`,{className:`doc-refs-incomplete`,children:[`Showing the first `,e.length,` links of this document; it has more, which are not shown here or in the graph.`]}),n&&(0,l.jsxs)(`div`,{className:`doc-refs-list-wrap`,children:[(0,l.jsx)(`h4`,{children:`References`}),p.length===0?(0,l.jsx)(`p`,{className:`doc-refs-empty`,children:`This chunk has no links.`}):(0,l.jsx)(`ul`,{className:`doc-refs-list`,children:p.map((e,o)=>(0,l.jsx)(Tt,{edge:e,selectedId:n,documentId:t,onSelectChunk:r,onOpenDocument:i,onRuleStatement:a},`${e.from_id}-${e.to_id}-${e.kind}-${o}`))})]}),(0,l.jsxs)(`div`,{className:`doc-graph`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`doc-graph-toggle`,onClick:()=>u(e=>!e),children:[s?`▼`:`▶`,` relationship graph (`,e.length,`)`]}),s&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Ke,{code:h,onNodeClick:e=>{let n=Dt(m,e);n&&(!n.documentId||n.documentId===t?r(n.id):i?.(n.documentId,n.id,n.title))}}),e.length>Ct&&(0,l.jsx)(`button`,{type:`button`,className:`doc-graph-more`,onClick:()=>f(e=>!e),children:d?`show top ${Ct}`:`show all ${e.length}`})]})]})]})}function Tt({edge:e,selectedId:t,documentId:n,onSelectChunk:r,onOpenDocument:i,onRuleStatement:a}){let o=e.from_id===t,s=o?e.to_id:e.from_id,c=o?e.to_title:e.from_title,u=o?e.to_document_id:e.from_document_id;return(0,l.jsxs)(`li`,{className:`doc-ref`,children:[(0,l.jsx)(`span`,{className:`doc-ref-kind`,children:e.kind}),(0,l.jsx)(`span`,{className:`doc-ref-arrow`,"aria-hidden":!0,children:o?`→`:`←`}),(0,l.jsx)(pt,{id:s,title:c,targetDocumentId:u,documentId:n,onSelectChunk:r,onOpenDocument:i}),(0,l.jsx)(mt,{statement:e}),a&&G(e)&&(0,l.jsx)(ht,{id:e.id,onRule:a})]})}function Et(e){let t=[`graph LR`];for(let n of e){let e=`${Ot(n.from_id)}["${kt(n.from_title,n.from_id)}"]`,r=`${Ot(n.to_id)}["${kt(n.to_title,n.to_id)}"]`,i=(n.kind||`link`).replace(/[|"]/g,` `),a=n.status===`proposed`?`-.->`:`-->`;t.push(` ${e} ${a}|${i}| ${r}`)}return t.join(`
|
|
2
|
+
`)}function Dt(e,t){for(let n of e){if(Ot(n.from_id)===t)return{id:n.from_id,documentId:n.from_document_id,title:n.from_title};if(Ot(n.to_id)===t)return{id:n.to_id,documentId:n.to_document_id,title:n.to_title}}}function Ot(e){return`n`+e.replace(/[^a-zA-Z0-9]/g,``)}function kt(e,t){let n=(e??``).replace(/["[\]{}|<>]/g,` `).replace(/\s+/g,` `).trim()||t.slice(0,6);return n.length>30?n.slice(0,29)+`…`:n}function At({documentId:e,scope:t,detail:n}){return(0,l.jsxs)(`div`,{className:`doc-unavailable`,role:`alert`,children:[(0,l.jsx)(`p`,{className:`doc-unavailable-lead`,children:`This document can’t be opened.`}),(0,l.jsxs)(`p`,{children:[`It may have been deleted, live in a scope other than `,(0,l.jsx)(`code`,{children:t}),`, or not be yours to read.`]}),(0,l.jsxs)(`p`,{className:`doc-unavailable-detail`,children:[(0,l.jsx)(`code`,{children:e}),n&&(0,l.jsxs)(l.Fragment,{children:[` — `,n]})]})]})}function jt(e){let t=typeof e==`number`?e/1e6:Date.parse(String(e));return!Number.isFinite(t)||t<=0?String(e??``):new Date(t).toLocaleString()}function Mt({chunkId:e,chunkTitle:t,scope:n,browse:r,onClose:i}){let a=T(),[o,s]=(0,c.useState)([]),[u,d]=(0,c.useState)(!0),[f,p]=(0,c.useState)(null),[m,h]=(0,c.useState)(`none`),[g,_]=(0,c.useState)(null),[v,y]=(0,c.useState)(``),[b,x]=(0,c.useState)(!1),[S,C]=(0,c.useState)(null),[w,E]=(0,c.useState)(null),[D,O]=(0,c.useState)(``);(0,c.useEffect)(()=>{let t=!1;return d(!0),p(null),a.documentHistory(e,n,r).then(e=>{if(t)return;let n=e.revisions??[];if(s(n),n.length>=2){let e=n.map(e=>e.revision);C(Math.min(...e)),E(Math.max(...e))}}).catch(e=>!t&&p(e instanceof Error?e.message:String(e))).finally(()=>!t&&d(!1)),()=>{t=!0}},[a,e,n,r]);let k=async t=>{p(null),x(!0),_(t),h(`version`);try{let i=await a.documentGetVersion(e,t,n,r);y(i.body??``)}catch(e){p(e instanceof Error?e.message:String(e))}finally{x(!1)}},A=async()=>{if(S!==null&&w!==null){p(null),x(!0),h(`diff`);try{let t=await a.documentDiff(e,S,w,n,r);O(t.diff??``)}catch(e){p(e instanceof Error?e.message:String(e))}finally{x(!1)}}};return(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:i,children:(0,l.jsxs)(`div`,{className:`modal history-modal`,onClick:e=>e.stopPropagation(),children:[(0,l.jsxs)(`div`,{className:`modal-header sticky-top`,children:[(0,l.jsxs)(`h3`,{children:[`History`,t?` — ${t}`:``]}),(0,l.jsx)(`div`,{className:`modal-buttons modal-buttons-top`,children:(0,l.jsx)(`button`,{type:`button`,onClick:i,children:`close`})})]}),f&&(0,l.jsx)(`div`,{className:`modal-err`,children:f}),u?(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`loading…`}):o.length===0?(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`No history recorded for this chunk.`}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`doc-hist-revs`,children:o.map(e=>(0,l.jsxs)(`button`,{type:`button`,className:`doc-hist-rev`+(m===`version`&&g===e.revision?` active`:``),onClick:()=>void k(e.revision),children:[(0,l.jsxs)(`span`,{className:`doc-hist-rev-num`,children:[`rev `,e.revision]}),(0,l.jsx)(`span`,{className:`doc-hist-rev-time`,children:jt(e.created_at)}),(0,l.jsx)(`span`,{className:`doc-hist-rev-actor`,children:e.actor||`unknown`})]},e.revision))}),o.length>=2&&(0,l.jsxs)(`div`,{className:`doc-hist-diffbar`,children:[(0,l.jsx)(`span`,{children:`Compare`}),(0,l.jsx)(`select`,{value:S??``,onChange:e=>C(e.target.value===``?null:Number(e.target.value)),"aria-label":`diff from revision`,children:o.map(e=>(0,l.jsxs)(`option`,{value:e.revision,children:[`rev `,e.revision]},e.revision))}),(0,l.jsx)(`span`,{"aria-hidden":!0,children:`→`}),(0,l.jsx)(`select`,{value:w??``,onChange:e=>E(e.target.value===``?null:Number(e.target.value)),"aria-label":`diff to revision`,children:o.map(e=>(0,l.jsxs)(`option`,{value:e.revision,children:[`rev `,e.revision]},e.revision))}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void A(),disabled:b||S===null||w===null,children:`diff`})]}),(0,l.jsx)(`div`,{className:`doc-hist-output`,children:b?(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`loading…`}):m===`diff`?(0,l.jsx)(Nt,{text:D}):m===`version`?(0,l.jsx)(`pre`,{className:`md-pre doc-hist-version`,children:(0,l.jsx)(`code`,{children:v||`(empty)`})}):(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`Select a revision to view it, or compare two.`})})]})]})})}function Nt({text:e}){if(!e.trim())return(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`(no differences)`});let t=e.split(`
|
|
3
|
+
`);return(0,l.jsx)(`pre`,{className:`md-pre doc-hist-diff`,children:t.map((e,t)=>{let n=e.startsWith(`+`)&&!e.startsWith(`+++`)?`diff-add`:e.startsWith(`-`)&&!e.startsWith(`---`)?`diff-del`:e.startsWith(`@@`)?`diff-hunk`:``;return(0,l.jsxs)(`span`,{className:n,children:[e,`
|
|
4
|
+
`]},t)})})}function Pt({source:e}){return(0,l.jsx)(`div`,{className:`md`,children:(0,l.jsx)(d.default,{remarkPlugins:[f.default],components:Ft,children:e})})}var Ft={a({href:e,children:t}){let n=e??``,r=/^https?:\/\//i.test(n);return(0,l.jsx)(`a`,{href:n,target:r?`_blank`:void 0,rel:r?`noopener noreferrer`:void 0,children:t})},pre({children:e}){return(0,l.jsx)(l.Fragment,{children:e})},code({className:e,children:t}){let n=/language-(\w+)/.exec(e??``)?.[1],r=String(t??``);return n===`mermaid`?(0,l.jsx)(Ke,{code:r.replace(/\n$/,``)}):n||r.includes(`
|
|
5
|
+
`)?(0,l.jsx)(`pre`,{className:`md-pre`,children:(0,l.jsx)(`code`,{className:e,children:t})}):(0,l.jsx)(`code`,{children:t})}};function It(e){let t=e.fields??{};return typeof t.alt==`string`&&t.alt.trim()!==``?t.alt:e.title||`image`}function Lt({documentId:e,scope:t,titleHint:n,browse:r,principal:i,renderAssistant:a,initialChunkId:o,onOpenDocument:s,onTitle:u,onChunkSelect:d,focusChunk:f}){let p=T(),m=(0,c.useMemo)(()=>r&&(r.scopeId||r.tenant)?{scopeId:r.scopeId,tenant:r.tenant}:void 0,[r?.scopeId,r?.tenant]),[h,_]=(0,c.useState)([]),[v,y]=(0,c.useState)(void 0),[b,x]=(0,c.useState)(null),[S,C]=(0,c.useState)(`chunks`),[w,E]=(0,c.useState)(null),[D,O]=(0,c.useState)(null),[k,A]=(0,c.useState)(null),j=(0,c.useRef)(null),[M,ee]=(0,c.useState)(null),[te,ne]=(0,c.useState)(null),[N,P]=(0,c.useState)(!1),[F,I]=(0,c.useState)(!1),[L,R]=(0,c.useState)(null),[re,ie]=(0,c.useState)(!1),[z,B]=(0,c.useState)(void 0),[ae,oe]=(0,c.useState)(null),[V,se]=(0,c.useState)(0),[ce,ue]=(0,c.useState)(!1),[U,pe]=(0,c.useState)(null),[ge,W]=(0,c.useState)(!1),[_e,ve]=(0,c.useState)([]),[G,K]=(0,c.useState)(!1),[ye,be]=(0,c.useState)(0),[xe,Se]=(0,c.useState)(0),[Ce,we]=(0,c.useState)(void 0),q=(0,c.useCallback)(()=>se(e=>e+1),[]),Te=(0,c.useRef)(o);Te.current=o;let J=(0,c.useRef)(u);J.current=u;let Ee=(0,c.useMemo)(()=>Re(h),[h]),Y=(0,c.useMemo)(()=>h.find(e=>!e.parent_id)?.title||n||`document`,[h,n]),X=(0,c.useMemo)(()=>!!b&&!b.parent_id,[b]),Z=(0,c.useMemo)(()=>he(h,b?.id),[h,b]),Q=(0,c.useMemo)(()=>U?.root_chunk_id??h.find(e=>!e.parent_id)?.id,[U,h]),Ae=(0,c.useRef)(d);Ae.current=d,(0,c.useEffect)(()=>{v&&Ae.current?.(v===Q?void 0:v)},[v,Q]);let je=(0,c.useMemo)(()=>[...new Set(h.map(e=>e.status).filter(e=>!!e))],[h]),Pe=!!U?.color_enabled,$=(0,c.useMemo)(()=>{let e=new Set;for(let t of _e)e.add(t.from_id),e.add(t.to_id);return e},[_e]),Ie=(0,c.useMemo)(()=>Pe?Fe(Ne(U?.type,U?.status,Me(U?.color_scheme))):void 0,[Pe,U?.type,U?.status,U?.color_scheme]);(0,c.useEffect)(()=>{let n=!1;return ie(!0),R(null),oe(null),p.documentQueryChunks(e,t,m).then(r=>{if(n)return;let i=r.chunks??[];_(i),B(`${t}:${e}`),y(e=>e??H(i,Te.current))}).catch(e=>{n||(_([]),oe(e instanceof Error?e.message:String(e)))}).finally(()=>!n&&ie(!1)),()=>{n=!0}},[p,e,t,V,m]);let ze=!re&&(ae!==null||z===`${t}:${e}`&&h.length===0),He=(0,c.useMemo)(()=>h.find(t=>!t.parent_id&&t.document_id===e)?.title,[h,e]);(0,c.useEffect)(()=>{He&&J.current?.(e,He)},[e,He]),(0,c.useEffect)(()=>{let n=!1;return p.documentGet(e,t,m).then(e=>!n&&pe(e)).catch(()=>!n&&pe(null)),()=>{n=!0}},[p,e,t,V,m]),(0,c.useEffect)(()=>{let n=!1;return me(p,e,t,m).then(e=>{n||(ve(e.edges),K(e.incomplete))}).catch(()=>{n||(ve([]),K(!1))}),()=>{n=!0}},[p,e,t,V,m,ye]),(0,c.useEffect)(()=>{if(!Q||!p.documentAcceptClassification){we(void 0);return}let n=!1;return p.documentGetChunk(Q,t,m).then(t=>!n&&we(t.document_id===e?t.fields:void 0)).catch(()=>!n&&we(void 0)),()=>{n=!0}},[p,e,Q,t,V,m]);let Ue=(0,c.useMemo)(()=>{if(p.documentAcceptStatement&&p.documentRejectStatement)return async(e,n,r)=>{n?await p.documentAcceptStatement(e,t,m,r):await p.documentRejectStatement(e,r??``,t,m),be(e=>e+1)}},[p,t,m]),We=(0,c.useMemo)(()=>De(p,t),[p,t]),Ge=(0,c.useMemo)(()=>Oe(_e,e),[_e,e]),Ye=(0,c.useCallback)(()=>be(e=>e+1),[]),Xe=(0,c.useMemo)(()=>ke(We,Ge,G,Ye),[We,Ge,G,Ye]),Ze=f?.seq,Qe=(0,c.useRef)(f);Qe.current=f;let $e=(0,c.useRef)(Q);$e.current=Q,(0,c.useEffect)(()=>{if(Ze===void 0)return;let e=Qe.current?.chunkId??$e.current;e&&y(e)},[Ze]),(0,c.useEffect)(()=>{y(void 0),x(null),E(null),C(`chunks`),pe(null),ve([]),K(!1),Se(0),we(void 0)},[e,t]),(0,c.useEffect)(()=>{if(!v){x(null);return}let e=!1;return p.documentGetChunk(v,t,m).then(t=>!e&&x(t)).catch(t=>!e&&R(t instanceof Error?t.message:String(t))),()=>{e=!0}},[p,v,t,V,m]),(0,c.useEffect)(()=>{let e=b?.type===`image`||!!b?.asset;if(!b||!e||!p.documentAssetObjectUrl){O(null),A(null);return}let n=!1,r=null;return A(null),p.documentAssetObjectUrl(b.id,t,m).then(e=>{n?URL.revokeObjectURL(e):(r=e,O(e))}).catch(e=>!n&&A(e instanceof Error?e.message:String(e))),()=>{n=!0,r&&URL.revokeObjectURL(r)}},[p,b,t,m]),(0,c.useEffect)(()=>{if(S!==`markdown`||!v){E(null);return}let e=Be(Ee,v);if(!e)return;let n=!1,r=[],i=(e,t)=>{r.push({node:e,depth:t}),e.children.forEach(e=>i(e,t+1))};return i(e,0),Promise.all(r.map(e=>p.documentGetChunk(e.node.row.id,t,m))).then(e=>{if(n)return;let t=r.map((t,n)=>{let r=Math.min(t.depth+1,6),i=e[n],a=`#`.repeat(r)+` `+t.node.row.title;if(i.type===`mermaid`&&i.body)return a+`
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
\`\`\`mermaid
|
|
8
|
+
`+i.body+"\n```\n";if(i.type===`image`||i.asset){let e=i.body?` — `+i.body:``;return a+`
|
|
9
9
|
|
|
10
|
-
`+
|
|
10
|
+
_🖼 image chunk_`+e+`
|
|
11
|
+
`}return a+(i.body?`
|
|
12
|
+
|
|
13
|
+
`+i.body:``)+`
|
|
11
14
|
`}).join(`
|
|
12
|
-
`);
|
|
13
|
-
A[Start] --> B[End]`},n,h);F(),y(j.id),C(j)}catch(j){T(j instanceof Error?j.message:String(j))}}},[d,t,n,h,p,J,F]),Nt=o.useCallback(async()=>{if(!d.documentCreateChunk)return;const u=p&&!Y?p:void 0,j=p||J;if(j){T(null);try{const M=await d.documentCreateChunk(t,u?"":j,{title:"Text",body:""},n,h,u);F(),y(M.id),C(M)}catch(M){T(M instanceof Error?M.message:String(M))}}},[d,t,n,h,p,Y,J,F]),wt=o.useCallback(async()=>{if(!(!d.documentCreateChunk||!p)){T(null);try{const u=await d.documentCreateChunk(t,p,{title:"Text",body:""},n,h);F(),y(u.id),C(u)}catch(u){T(u instanceof Error?u.message:String(u))}}},[d,t,n,h,p,F]),Ue=o.useMemo(()=>{if(!x||Y)return{canUp:!1,canDown:!1};const u=x.parent_id??"",j=v.filter(L=>(L.parent_id??"")===u).sort((L,q)=>L.position-q.position||L.id.localeCompare(q.id)),M=j.findIndex(L=>L.id===x.id);return{canUp:M>0,canDown:M>=0&&M<j.length-1}},[v,x,Y]),Be=o.useCallback(async u=>{if(!(!d.documentReorderChunk||!p)){T(null);try{await d.documentReorderChunk(p,u,n,h),F()}catch(j){T(j instanceof Error?j.message:String(j))}}},[d,p,n,h,F]),Ct=o.useCallback(async()=>{if(!d.documentDeleteChunk||!x)return;T(null);const u=x.parent_id;try{await d.documentDeleteChunk(x.id,n,h),S(!1),y(u||J),F()}catch(j){T(j instanceof Error?j.message:String(j)),S(!1)}},[d,x,n,h,J,F]);return o.useEffect(()=>{if(!se)return;const u=j=>{if(R||ie)return;const M=document.activeElement,L=M?.tagName;if(L==="INPUT"||L==="TEXTAREA"||M?.isContentEditable)return;const q=Yt(j.clipboardData?.items);q&&(j.preventDefault(),ue(q))};return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[se,R,ie,ue]),e.jsxs("div",{className:"doc-viewer",children:[e.jsx("input",{ref:N,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",style:{display:"none"},onChange:u=>{const j=u.target.files?.[0];u.target.value="",j&&ue(j)}}),e.jsxs("div",{className:"doc-toolbar",style:$e,children:[e.jsx("strong",{className:"doc-title",title:ee,children:ee}),e.jsx(Oe,{value:t,label:"doc"}),e.jsxs("div",{className:"doc-toolbar-actions",children:[se&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{Nt()},title:"Add a text chunk AFTER the selected chunk, at the same level",children:"+ text"}),e.jsx("button",{type:"button",onClick:()=>{wt()},disabled:!p,title:p?"Add a chunk NESTED UNDER the selected chunk (in the ontology, a child is a subclass)":"Select a chunk first — this nests a new chunk under it",children:"+ child"}),e.jsx("button",{type:"button",onClick:()=>N.current?.click(),title:"Add an image chunk (upload — or paste a screenshot into the view)",children:"+ image"}),e.jsx("button",{type:"button",onClick:()=>{vt()},title:"Add a Mermaid diagram chunk",children:"+ diagram"})]}),e.jsx("button",{type:"button",className:de?"active":"",onClick:()=>be(!0),disabled:!J,title:"Colors — tint chunk tiles + the Path tree by type/status",children:"colors"}),e.jsx("button",{type:"button",onClick:()=>{U()},title:"Download the whole document as Markdown (.md)",children:"↓ .md"}),e.jsx("button",{type:"button",onClick:()=>{Q()},title:"Download the whole document as a node/edge canvas graph (.canvas)",children:"↓ .canvas"}),c&&e.jsx("button",{type:"button",className:je?"active":"",onClick:()=>E(u=>!u),title:"Document Assistant — instruct an agent to restructure/import/link chunks",children:"assistant"}),e.jsx("button",{type:"button",onClick:F,title:"Reload",children:"↻"})]})]}),I&&e.jsx("div",{className:"paths-err",children:I}),Te?e.jsx(jn,{documentId:t,scope:n,detail:ce??void 0}):e.jsxs("div",{className:"doc-split",children:[e.jsx("div",{className:"doc-chunktree",children:X&&v.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):e.jsx(nn,{tree:pe,selectedId:p,onSelect:_,colorEnabled:de,scheme:z?.color_scheme,linkedIds:Me})}),e.jsx("div",{className:"doc-content",children:x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"doc-content-head",children:[e.jsx("h3",{children:x.title||"(untitled)"}),e.jsxs("div",{className:"doc-content-meta",children:[x.type&&e.jsx("span",{className:"chunk-badge",children:x.type}),x.status&&e.jsx("span",{className:"chunk-badge chunk-status",children:x.status}),e.jsxs("span",{className:"chunk-rev",children:["rev ",x.revision]}),x.tags?.map(u=>e.jsx("span",{className:"chunk-tag",children:u},u)),e.jsx(Oe,{value:x.id,label:"chunk"})]}),e.jsxs("div",{className:"doc-content-controls",children:[e.jsxs("div",{className:"doc-mode-toggle",children:[e.jsx("button",{type:"button",className:O==="chunks"?"active":"",onClick:()=>P("chunks"),title:"This chunk's own content",children:"chunk"}),e.jsx("button",{type:"button",className:O==="markdown"?"active":"",onClick:()=>P("markdown"),title:Y?"Whole document as Markdown":"This chunk + its sub-chunks as Markdown",children:"markdown"})]}),e.jsx("button",{type:"button",onClick:()=>C(x),children:"edit"}),e.jsx("button",{type:"button",onClick:()=>g(!0),title:"View this chunk's edit history + diffs",children:"history"}),!Y&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{Be("up")},disabled:!Ue.canUp,title:"Move this chunk up within its level",children:"↑"}),e.jsx("button",{type:"button",onClick:()=>{Be("down")},disabled:!Ue.canDown,title:"Move this chunk down within its level",children:"↓"})]}),!Y&&e.jsx("button",{type:"button",className:"danger",onClick:()=>S(!0),title:"Delete this chunk and its sub-chunks",children:"delete"})]})]}),e.jsx("div",{className:"doc-content-body",children:x.type==="mermaid"?x.body?e.jsxs(e.Fragment,{children:[e.jsx(_e,{code:x.body}),O==="markdown"&&e.jsx("pre",{className:"md-pre doc-mermaid-source",children:e.jsx("code",{children:x.body})})]}):e.jsx("p",{className:"doc-empty-body",children:"(empty diagram)"}):x.type==="image"||x.asset?H?e.jsxs("p",{className:"doc-empty-body",children:["Image failed to load: ",H]}):D?e.jsxs("figure",{className:"doc-image",children:[e.jsx("img",{src:D,alt:Nn(x)}),x.body&&e.jsx("figcaption",{children:x.body})]}):e.jsx("p",{className:"doc-empty-body",children:"Loading image…"}):O==="markdown"?B!==null?e.jsx(Xe,{source:B}):e.jsx("p",{className:"doc-empty-body",children:"Assembling Markdown…"}):x.body?e.jsx(Xe,{source:x.body}):e.jsx("p",{className:"doc-empty-body",children:"(empty chunk)"})}),e.jsx(fn,{edges:le,documentId:t,selectedId:p,onSelectChunk:y,onOpenDocument:l?$:void 0}),e.jsx(mn,{documentId:t,selectedId:p,scope:n,browse:h,onSelectChunk:y,onOpenDocument:l?$:void 0})]}):e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Select a chunk on the left."})})})]}),je&&c&&e.jsx("div",{className:"doc-assistant",children:c({documentId:t,scope:n,subject:r?.subject,onChanged:F})}),R&&e.jsx(on,{chunk:R,scope:n,browse:h,onClose:()=>C(null),onSaved:F}),m&&x&&e.jsx(yn,{chunkId:x.id,chunkTitle:x.title,scope:n,browse:h,onClose:()=>g(!1)}),ie&&J&&e.jsx(ln,{documentId:t,rootChunkId:J,docType:z?.type,docStatus:z?.status,chunkStatuses:Z,scope:n,browse:h,onClose:()=>be(!1),onSaved:F}),k&&x&&e.jsx("div",{className:"modal-overlay",onClick:()=>S(!1),children:e.jsxs("div",{className:"modal chunk-delete-confirm",onClick:u=>u.stopPropagation(),children:[e.jsx("h3",{children:"Delete chunk"}),e.jsxs("p",{className:"modal-context",children:["Delete “",x.title||"(untitled)","” and all of its sub-chunks? This cannot be undone."]}),e.jsxs("div",{className:"modal-buttons",children:[e.jsx("button",{type:"button",onClick:()=>S(!1),children:"cancel"}),e.jsx("button",{type:"button",className:"danger",onClick:()=>{Ct()},children:"delete"})]})]})})]})}function jt(t,n=""){const s=t.get(n);if(!s)return[];const a=s.entries.map(r=>{const c=r.kind==="directory"&&r.full_path.startsWith(`${n}/`);return{name:r.name,fullPath:r.full_path,kind:r.kind,resourceRef:r.resource_ref,listing:c?t.get(r.full_path):void 0,children:c?jt(t,r.full_path):[]}});return a.sort((r,c)=>{const i=r.kind==="directory",l=c.kind==="directory";return i!==l?i?-1:1:r.name.localeCompare(c.name)}),a}const wn={directory:"📁",document:"📄",volume_mount:"💾",memory_entry:"🧠"};function Cn(t){const{tree:n,root:s}=t;return!s||!s.loaded&&s.loading?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):s.loaded&&n.length===0&&!s.nextCursor?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"This tree is empty. Create a folder or document to begin."})}):e.jsxs("ul",{className:"tree path-tree",children:[n.map(a=>e.jsx(yt,{node:a,...t},a.fullPath)),e.jsx(bt,{dir:"",listing:s,...t})]})}function bt({dir:t,listing:n,onLoadMore:s,onRetry:a}){const r=[];return!n||n.loading&&n.entries.length===0?r.push(e.jsx("li",{className:"node path-status",children:e.jsx("span",{className:"path-implicit",children:"loading…"})},"status")):n.error?r.push(e.jsxs("li",{className:"node path-status",children:[t!==""&&e.jsxs("span",{className:"path-err",children:["failed to load: ",n.error]})," ",e.jsx("button",{type:"button",className:"path-more",onClick:()=>a(t),children:"retry"})]},"status")):n.loaded&&n.entries.length===0&&t!==""&&r.push(e.jsx("li",{className:"node path-status",children:e.jsx("span",{className:"path-implicit",children:"empty"})},"status")),n?.nextCursor&&!n.error&&r.push(e.jsx("li",{className:"node path-status",children:e.jsx("button",{type:"button",className:"path-more",disabled:n.loading,onClick:()=>s(t),children:n.loading?"loading…":`Load more (${n.entries.length} shown)`})},"more")),e.jsx(e.Fragment,{children:r})}function Sn(t,n){if(t.kind!=="document"||!n)return;const s=t.resourceRef;return s?.document_id?n.get(s.document_id):void 0}function yt(t){const{node:n,expanded:s,onToggle:a,selectedPath:r,onSelect:c,summaries:i}=t,l=n.kind==="directory",f=l&&s.has(n.fullPath),d=r===n.fullPath,h=Sn(n,i),v=h&&h.color_enabled?Se(Fe(h.type,h.status,Ce(h.color_scheme))):void 0;return e.jsxs("li",{className:`node path-node kind-${n.kind} ${d?"selected":""}`,children:[e.jsxs("div",{className:"row path-row",style:v,children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":f?"collapse":"expand","aria-expanded":l?f:void 0,disabled:!l,onClick:w=>{w.stopPropagation(),l&&a(n.fullPath)},children:l?f?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"path-link",onClick:()=>c(n),title:n.fullPath,children:[e.jsx("span",{className:"path-kind-icon","aria-hidden":!0,children:wn[n.kind]??"•"}),e.jsx("span",{className:"path-name",children:n.name}),h?.type&&e.jsx("span",{className:"chunk-badge",children:h.type}),h?.status&&e.jsx("span",{className:"chunk-badge chunk-status",children:h.status})]})]}),f&&e.jsxs("ul",{className:"children path-children",children:[n.children.map(w=>e.jsx(yt,{...t,node:w},w.fullPath)),e.jsx(bt,{...t,dir:n.fullPath,listing:n.listing})]})]})}const Qe=/^[A-Za-z0-9._-]+$/;function Ye(t,n){return`${t}/${n}`}function kt(t,n){for(const s of t){if(s.fullPath===n)return s;const a=kt(s.children,n);if(a)return a}}function _n(t){const{theme:n,defaultScope:s,path:a,onPathChange:r,browse:c,principal:i,renderAssistant:l,onError:f}=t,d=at(t);return e.jsx(rt,{theme:n,dataLayer:d,children:e.jsx(En,{defaultScope:s,path:a,onPathChange:r,browse:c,principal:i,renderAssistant:l,onError:f})})}function En({defaultScope:t,path:n,onPathChange:s,browse:a,principal:r,renderAssistant:c,onError:i}){const l=he(),[f,d]=o.useState(t??"user"),[h,v]=o.useState(void 0),[w,p]=o.useState(null),[y,x]=o.useState(null),[A,O]=o.useState(()=>new Set),P=n!==void 0?n:h,B=o.useRef(s);o.useEffect(()=>{B.current=s},[s]);const W=o.useRef(i);o.useEffect(()=>{W.current=i},[i]);const[D,G]=o.useState([]),H=o.useRef(0),V=o.useRef(void 0),N=o.useCallback(b=>{V.current=b,B.current?.(b),v(b)},[]),R=o.useCallback(b=>{H.current++,G(_=>_.length>0?[]:_),N(b)},[N]);o.useEffect(()=>{n===void 0||n===V.current||(H.current++,G(b=>b.length>0?[]:b))},[n]);const C=o.useMemo(()=>a&&(a.scopeId||a.tenant)?{scopeId:a.scopeId,tenant:a.tenant}:void 0,[a?.scopeId,a?.tenant]),m=o.useMemo(()=>new Ht(l,f,C),[l,f,C]),g=o.useSyncExternalStore(m.subscribe,m.getSnapshot),k=o.useCallback(b=>{W.current?.(b)},[]),[S,I]=o.useState(()=>new Map),T=o.useRef(new Set),X=o.useRef(0),ae=o.useCallback(()=>{X.current++,T.current=new Set,I(new Map)},[]),xe=o.useRef(!0);o.useEffect(()=>{xe.current?xe.current=!1:(R(void 0),p(null),O(new Set),ae()),m.loadDir("").catch(k)},[m,R,ae,k]),o.useEffect(()=>{for(const b of A)g.has(b)||m.loadDir(b).catch(k)},[m,A,g,k]);const me=o.useRef(null);o.useEffect(()=>{const b=me.current!==null&&me.current!==m;if(me.current=m,!P||b)return;const _=tt(P).filter($=>$!=="");O($=>{if(_.every(Q=>$.has(Q)))return $;const U=new Set($);return _.forEach(Q=>U.add(Q)),U}),m.reveal(P).catch(k)},[m,P,k]),o.useEffect(()=>{if(f==="tenant")return;const b=[];for(const $ of g.values())for(const U of Ve($.entries))T.current.has(U)||(T.current.add(U),b.push(U));const _=X.current;for(let $=0;$<b.length;$+=Pe)l.documentsSummary({documentIds:b.slice($,$+Pe)},f,C).then(U=>{X.current===_&&I(Q=>{const se=new Map(Q);for(const ue of U.documents??[])se.set(ue.document_id,ue);return se})}).catch(()=>{})},[l,g,f,C]);const ce=o.useMemo(()=>jt(g),[g]),ge=o.useCallback(async()=>{p(null),ae(),await m.refresh(A).catch(k),P&&await m.reveal(P).catch(k)},[m,A,P,ae,k]),re=o.useCallback(b=>{O(_=>{const $=new Set(_);return $.has(b)?$.delete(b):$.add(b),$})},[]),Ee=o.useCallback(b=>m.loadMore(b).catch(k),[m,k]),je=o.useCallback(b=>{(m.getSnapshot().get(b)?.loaded?m.loadMore(b):m.loadDir(b)).catch(k)},[m,k]),E=o.useMemo(()=>P?kt(ce,P):void 0,[ce,P]),z=g.get("")?.error,ne=E?.kind==="directory"?E.fullPath:void 0,[ie,be]=o.useState(null);o.useEffect(()=>{if(!ne||!l.pathIsStored)return;let b=!1;return l.pathIsStored(ne,f,C).then(_=>{b||be({path:ne,explicit:_})},()=>{}),()=>{b=!0}},[l,ne,f,C]);const le=E?E.kind!=="directory"?"yes":ie?.path===E.fullPath?ie.explicit?"yes":"implicit (no entry)":void 0:void 0,K=o.useMemo(()=>E?E.kind==="directory"?E.fullPath:Gt(E.fullPath):"",[E]),F=K||"/",fe=f!=="tenant",ye=o.useCallback(()=>{x({title:`New folder in ${F}`,fields:[{key:"name",label:"Folder name",placeholder:"e.g. launches"}],submitLabel:"Create",onSubmit:async b=>{const _=b.name.trim();if(!Qe.test(_))throw new Error("name may contain only [A-Za-z0-9._-]");const $=Ye(K,_);await l.pathMkdir($,f,C),await m.invalidate($).catch(k),R($)}})},[l,m,K,F,f,C,k,R]),pe=o.useCallback(()=>{x({title:`New document in ${F}`,fields:[{key:"name",label:"Path name",placeholder:"e.g. launch-plan"},{key:"title",label:"Title",placeholder:"e.g. Launch Plan"}],submitLabel:"Create",onSubmit:async b=>{const _=b.name.trim();if(!Qe.test(_))throw new Error("name may contain only [A-Za-z0-9._-]");const $=b.title.trim()||_,U=Ye(K,_);await l.documentCreate($,U,f,C),await m.invalidate(U).catch(k),R(U)}})},[l,m,K,F,f,C,k,R]),ee=o.useCallback(()=>{E&&x({title:`Rename / move ${E.fullPath}`,fields:[{key:"to",label:"New path",value:E.fullPath}],submitLabel:"Move",onSubmit:async b=>{const _=b.to.trim();if(!_.startsWith("/"))throw new Error("path must start with /");await l.pathMv(E.fullPath,_,f,C),await Promise.all([m.invalidate(E.fullPath,{dropSubtree:!0}),m.invalidate(_)]).catch(k),R(_)}})},[l,m,E,f,C,k,R]),Y=o.useCallback(()=>{if(!E)return;if(E.kind==="document"){const $=E.resourceRef?.document_id;x({title:`Delete document ${E.fullPath}`,message:"This deletes the document, all its chunks, and its path entry. This cannot be undone.",fields:[],submitLabel:"Delete",danger:!0,onSubmit:async()=>{if(!$)throw new Error("this document dirent has no document_id");await l.documentDelete($,f,C),await m.invalidate(E.fullPath).catch(k),R(void 0)}});return}const b=E;p(null),(async()=>{let _;try{_=await Wt(l,b.fullPath,f,C)}catch(U){p(`could not list ${b.fullPath} for delete: ${U instanceof Error?U.message:String(U)}`);return}const $=f==="tenant"?[]:Ve(_);x({title:`Delete branch ${b.fullPath}`,message:_.length===0?"This removes the (empty) folder.":"This removes the folder and everything under it"+($.length>0?` — including ${$.length} document(s), whose chunks are deleted.`:"."),fields:[],submitLabel:"Delete",danger:!0,onSubmit:async()=>{for(const U of $)await l.documentDelete(U,f,C);await l.pathRm(b.fullPath,f,!0,C),await m.invalidate(b.fullPath,{dropSubtree:!0}).catch(k),R(void 0)}})})()},[l,m,E,f,C,k,R]),J=E&&(E.kind==="directory"||E.kind==="document"),Z=o.useMemo(()=>{if(D.length>0)return D[D.length-1];if(E?.kind==="document")return{documentId:E.resourceRef?.document_id??"",path:E.fullPath,title:E.name}},[D,E]),de=o.useCallback((b,_)=>{const $=++H.current,U=zt(m.getSnapshot(),b.documentId);G(ot(D,{..._,path:Z?.path},{...b,path:U})),N(U),!(U||!l.documentPath)&&l.documentPath(b.documentId,f,C).then(Q=>{!Q||H.current!==$||(G(se=>Ae(se,b.documentId,{path:Q})),N(Q))},()=>{})},[l,m,D,Z?.path,f,C,N]),Me=o.useCallback(b=>{const _=ct(D,b);_!==D&&(H.current++,G(_),N(_[_.length-1].path))},[D,N]),$e=o.useCallback((b,_)=>G($=>Ae($,b,{title:_})),[]),Te=!!Z?.path&&E?.kind==="document"&&E.fullPath===Z.path;return e.jsxs(e.Fragment,{children:[e.jsxs(Xt,{className:"paths-view",defaultLeftWidth:420,minLeftWidth:280,minRightWidth:300,storageKey:"loomcycle.explorer.split.paths",children:[e.jsxs("div",{className:"left",children:[e.jsxs("div",{className:"paths-toolbar",children:[e.jsxs("label",{className:"paths-scope",children:[e.jsx("span",{children:"scope"}),e.jsxs("select",{value:f,onChange:b=>d(b.target.value),children:[e.jsx("option",{value:"user",children:"user"}),e.jsx("option",{value:"agent",children:"agent"}),e.jsx("option",{value:"tenant",children:"tenant"})]})]}),e.jsxs("div",{className:"paths-toolbar-actions",children:[e.jsx("button",{type:"button",onClick:ye,title:`New folder in ${F}`,children:"+ folder"}),e.jsx("button",{type:"button",onClick:pe,disabled:!fe,title:fe?`New document in ${F}`:"Documents are agent/user scope only",children:"+ document"}),e.jsx("button",{type:"button",onClick:()=>{ge()},title:"Reload the tree",children:"↻"})]})]}),e.jsxs("p",{className:"paths-context",children:["new items → ",e.jsx("code",{children:F}),C?.scopeId&&e.jsxs(e.Fragment,{children:[" · ","subject ",e.jsx("code",{children:C.scopeId})]}),C?.tenant&&e.jsxs(e.Fragment,{children:[" · ","tenant ",e.jsx("code",{children:C.tenant})]})]}),(w||z)&&e.jsx("div",{className:"paths-err",children:w||z}),e.jsx(Cn,{tree:ce,root:g.get(""),expanded:A,onToggle:re,onLoadMore:Ee,onRetry:je,selectedPath:P,onSelect:b=>R(b.fullPath),summaries:S})]}),e.jsx("div",{className:"right",children:Z?e.jsxs("div",{className:"paths-doc",children:[e.jsx(lt,{trail:D,onJump:Me}),e.jsxs("div",{className:"paths-doc-head",children:[Z.path?e.jsx("code",{className:"paths-doc-path",children:Z.path}):e.jsxs("span",{className:"paths-doc-path paths-doc-unfiled",title:"Opened by id — no entry for this document was found in the Path tree",children:[oe(Z)," ",e.jsx("em",{children:"· opened by id, not in the tree"})]}),Te&&e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:ee,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:Y,children:"delete"})]})]}),e.jsx(gt,{documentId:Z.documentId,scope:f,titleHint:Z.title,browse:C,principal:r,renderAssistant:c,initialChunkId:Z.chunkId,onOpenDocument:de,onTitle:$e},D.length)]}):E?e.jsxs("div",{className:"paths-detail",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"paths-detail-kind",children:E.kind}),e.jsx("code",{children:E.fullPath})]}),e.jsxs("dl",{className:"paths-detail-meta",children:[e.jsx("dt",{children:"scope"}),e.jsx("dd",{children:f}),le&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"stored"}),e.jsx("dd",{children:le})]})]}),J?e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:ee,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:Y,children:"delete"})]}):e.jsxs("p",{className:"paths-readonly",children:["Read-only — ",E.kind," entries are managed by their own tool."]})]}):e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Select a path on the left, or create a folder / document."})})})]}),y&&e.jsx(Mn,{state:y,onClose:()=>x(null)})]})}function Mn({state:t,onClose:n}){const[s,a]=o.useState(()=>Object.fromEntries(t.fields.map(d=>[d.key,d.value??""]))),[r,c]=o.useState(!1),[i,l]=o.useState(null),f=async d=>{d.preventDefault(),c(!0),l(null);try{await t.onSubmit(s),n()}catch(h){l(h instanceof Error?h.message:String(h)),c(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:n,children:e.jsxs("form",{className:"modal",onClick:d=>d.stopPropagation(),onSubmit:f,children:[e.jsxs("div",{className:"modal-header sticky-top",children:[e.jsx("h3",{children:t.title}),e.jsxs("div",{className:"modal-buttons modal-buttons-top",children:[e.jsx("button",{type:"button",onClick:n,disabled:r,children:"cancel"}),e.jsx("button",{type:"submit",className:t.danger?"danger":"primary",disabled:r,children:r?"working…":t.submitLabel})]})]}),t.message&&e.jsx("p",{className:"modal-context",children:t.message}),t.fields.map((d,h)=>e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:d.label}),e.jsx("input",{className:"path-modal-input",value:s[d.key],placeholder:d.placeholder,autoFocus:h===0,onChange:v=>a(w=>({...w,[d.key]:v.target.value}))})]},d.key)),i&&e.jsx("div",{className:"modal-err",children:i})]})})}function $n(t){const{documentId:n,scope:s,browse:a,theme:r}=t,c=at(t);return e.jsx(rt,{theme:r,dataLayer:c,children:e.jsx(Tn,{...t},`${s}:${n}:${a?.scopeId??""}:${a?.tenant??""}`)})}function Tn({documentId:t,scope:n,titleHint:s,browse:a,principal:r,renderAssistant:c,onOpenDocument:i}){const[l,f]=o.useState([]),d=l[l.length-1],h=o.useCallback((p,y)=>{i?i(p,y):f(x=>ot(x,y,p))},[i]),v=o.useCallback(p=>f(y=>ct(y,p)),[]),w=o.useCallback((p,y)=>f(x=>Ae(x,p,{title:y})),[]);return e.jsxs(e.Fragment,{children:[e.jsx(lt,{trail:l,onJump:v}),e.jsx(gt,{documentId:d?.documentId??t,scope:n,titleHint:d?d.title:s,browse:a,principal:r,renderAssistant:c,initialChunkId:d?.chunkId,onOpenDocument:h,onTitle:w},l.length)]})}exports.DEFAULT_SCHEME=Ne;exports.DocumentViewer=$n;exports.PathExplorer=_n;exports.assetFetchFromConnection=st;exports.chunkColor=ht;exports.createLoomcycleClient=nt;exports.dataLayerFromClient=Le;exports.docColor=Fe;exports.effectiveScheme=Ce;exports.hexToTint=mt;exports.tintStyle=Se;
|
|
14
|
-
//# sourceMappingURL=index.cjs.map
|
|
15
|
+
`);E(t)}).catch(e=>!n&&R(e instanceof Error?e.message:String(e))),()=>{n=!0}},[p,S,v,Ee,t,V,m]);let et=(0,c.useCallback)(e=>y(e.row.id),[]),tt=(0,c.useCallback)((t,n,r)=>s?.({documentId:t,chunkId:n,title:r},{documentId:e,chunkId:v,title:Y}),[s,e,v,Y]),nt=(0,c.useCallback)(async()=>{try{let n=await p.documentExportMd(e,t,!0,m),r=new Blob([n.markdown],{type:`text/markdown`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=(n.title||`document`).replace(/[^\w.-]+/g,`_`)+`.md`,a.click(),URL.revokeObjectURL(i)}catch(e){R(e instanceof Error?e.message:String(e))}},[p,e,t,m]),rt=(0,c.useCallback)(async()=>{try{let n=await p.documentExportCanvas(e,t,m),r=new Blob([JSON.stringify(n.canvas,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=(Y||`document`).replace(/[^\w.-]+/g,`_`)+`.canvas`,a.click(),URL.revokeObjectURL(i)}catch(e){R(e instanceof Error?e.message:String(e))}},[p,e,t,m,Y]),it=!!p.documentCreateChunk&&!!Q,at=(0,c.useCallback)(async n=>{if(!p.documentCreateChunk||!p.documentSetAsset)return;let r=v||Q;if(r){R(null);try{let{mediaType:i,data:a}=await de(n),o=await p.documentCreateChunk(e,r,{title:n.name||`image`,type:`image`},t,m);await p.documentSetAsset(o.id,i,a,n.name,t,m),q(),y(o.id)}catch(e){R(e instanceof Error?e.message:String(e))}}},[p,e,t,m,v,Q,q]),ot=(0,c.useCallback)(async()=>{if(!p.documentCreateChunk)return;let n=v||Q;if(n){R(null);try{let r=await p.documentCreateChunk(e,n,{title:`Diagram`,type:`mermaid`,body:`graph TD
|
|
16
|
+
A[Start] --> B[End]`},t,m);q(),y(r.id),ee(r)}catch(e){R(e instanceof Error?e.message:String(e))}}},[p,e,t,m,v,Q,q]),st=(0,c.useCallback)(async()=>{if(!p.documentCreateChunk)return;let n=v&&!X?v:void 0,r=v||Q;if(r){R(null);try{let i=await p.documentCreateChunk(e,n?``:r,{title:`Text`,body:``},t,m,n);q(),y(i.id),ee(i)}catch(e){R(e instanceof Error?e.message:String(e))}}},[p,e,t,m,v,X,Q,q]),lt=(0,c.useCallback)(async()=>{if(p.documentCreateChunk&&v){R(null);try{let n=await p.documentCreateChunk(e,v,{title:`Text`,body:``},t,m);q(),y(n.id),ee(n)}catch(e){R(e instanceof Error?e.message:String(e))}}},[p,e,t,m,v,q]),ut=(0,c.useMemo)(()=>{if(!b||X)return{canUp:!1,canDown:!1};let e=b.parent_id??``,t=h.filter(t=>(t.parent_id??``)===e).sort((e,t)=>e.position-t.position||e.id.localeCompare(t.id)),n=t.findIndex(e=>e.id===b.id);return{canUp:n>0,canDown:n>=0&&n<t.length-1}},[h,b,X]),ft=(0,c.useCallback)(async e=>{if(p.documentReorderChunk&&v){R(null);try{await p.documentReorderChunk(v,e,t,m),q()}catch(e){R(e instanceof Error?e.message:String(e))}}},[p,v,t,m,q]),pt=(0,c.useCallback)(async()=>{if(!p.documentDeleteChunk||!b)return;R(null);let e=b.parent_id;try{await p.documentDeleteChunk(b.id,t,m),I(!1),y(e||Q),q()}catch(e){R(e instanceof Error?e.message:String(e)),I(!1)}},[p,b,t,m,Q,q]);return(0,c.useEffect)(()=>{if(!it)return;let e=e=>{if(M||ge)return;let t=document.activeElement,n=t?.tagName;if(n===`INPUT`||n===`TEXTAREA`||t?.isContentEditable)return;let r=fe(e.clipboardData?.items);r&&(e.preventDefault(),at(r))};return window.addEventListener(`paste`,e),()=>window.removeEventListener(`paste`,e)},[it,M,ge,at]),(0,l.jsxs)(`div`,{className:`doc-viewer`,children:[(0,l.jsx)(`input`,{ref:j,type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,style:{display:`none`},onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&at(t)}}),(0,l.jsxs)(`div`,{className:`doc-toolbar`,style:Ie,children:[(0,l.jsx)(`strong`,{className:`doc-title`,title:Y,children:Y}),(0,l.jsx)(Le,{value:e,label:`doc`}),(0,l.jsxs)(`div`,{className:`doc-toolbar-actions`,children:[it&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{type:`button`,onClick:()=>void st(),title:`Add a text chunk AFTER the selected chunk, at the same level`,children:`+ text`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void lt(),disabled:!v,title:v?`Add a chunk NESTED UNDER the selected chunk (in the ontology, a child is a subclass)`:`Select a chunk first — this nests a new chunk under it`,children:`+ child`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>j.current?.click(),title:`Add an image chunk (upload — or paste a screenshot into the view)`,children:`+ image`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void ot(),title:`Add a Mermaid diagram chunk`,children:`+ diagram`})]}),(0,l.jsx)(`button`,{type:`button`,className:Pe?`active`:``,onClick:()=>W(!0),disabled:!Q,title:`Colors — tint chunk tiles + the Path tree by type/status`,children:`colors`}),p.documentClassify&&(0,l.jsx)(`button`,{type:`button`,className:xe>0?`active`:``,onClick:()=>Se(e=>e>0?0:1),title:`Classify — what this document is, by the confirmed ontology (a report first; nothing is written until Apply)`,children:`classify`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void nt(),title:`Download the whole document as Markdown (.md)`,children:`↓ .md`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void rt(),title:`Download the whole document as a node/edge canvas graph (.canvas)`,children:`↓ .canvas`}),a&&(0,l.jsx)(`button`,{type:`button`,className:ce?`active`:``,onClick:()=>ue(e=>!e),title:`Document Assistant — instruct an agent to restructure/import/link chunks`,children:`assistant`}),(0,l.jsx)(`button`,{type:`button`,onClick:q,title:`Reload`,children:`↻`})]})]}),L&&(0,l.jsx)(`div`,{className:`paths-err`,children:L}),!ze&&(0,l.jsx)(ct,{documentId:e,scope:t,browse:m,rootFields:Ce,requestKey:xe,onClose:()=>Se(0),onChanged:q},`${t}:${e}`),ze?(0,l.jsx)(At,{documentId:e,scope:t,detail:ae??void 0}):(0,l.jsxs)(le,{className:`doc-split`,defaultLeftWidth:320,minLeftWidth:160,minRightWidth:320,storageKey:`loomcycle.explorer.split.doc`,children:[(0,l.jsx)(`div`,{className:`doc-chunktree`,children:re&&h.length===0?(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`Loading…`})}):(0,l.jsx)(Ve,{tree:Ee,selectedId:v,onSelect:et,colorEnabled:Pe,scheme:U?.color_scheme,linkedIds:$})}),(0,l.jsx)(`div`,{className:`doc-content`,children:b?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`doc-content-head`,children:[Z.length>0&&(0,l.jsxs)(`nav`,{className:`chunk-ancestry`,"aria-label":`Chunks above this one`,children:[(0,l.jsx)(`button`,{type:`button`,className:`chunk-ancestry-up`,onClick:()=>y(Z[Z.length-1].id),title:`Up to ${Z[Z.length-1].title||`(untitled)`}`,children:`↰ Up`}),(0,l.jsxs)(`ol`,{className:`doc-trail-list`,children:[Z.map(e=>(0,l.jsx)(`li`,{className:`doc-trail-item`,children:(0,l.jsx)(`button`,{type:`button`,className:`doc-trail-crumb`,onClick:()=>y(e.id),title:e.title||`(untitled)`,children:e.title||`(untitled)`})},e.id)),(0,l.jsx)(`li`,{className:`doc-trail-item`,children:(0,l.jsx)(`span`,{className:`doc-trail-current`,"aria-current":`location`,title:b.title||`(untitled)`,children:b.title||`(untitled)`})})]})]}),(0,l.jsx)(`h3`,{children:b.title||`(untitled)`}),(0,l.jsxs)(`div`,{className:`doc-content-meta`,children:[b.type&&(0,l.jsx)(`span`,{className:`chunk-badge`,children:b.type}),b.status&&(0,l.jsx)(`span`,{className:`chunk-badge chunk-status`,children:b.status}),(0,l.jsxs)(`span`,{className:`chunk-rev`,children:[`rev `,b.revision]}),b.tags?.map(e=>(0,l.jsx)(`span`,{className:`chunk-tag`,children:e},e)),(0,l.jsx)(Le,{value:b.id,label:`chunk`})]}),(0,l.jsxs)(`div`,{className:`doc-content-controls`,children:[(0,l.jsxs)(`div`,{className:`doc-mode-toggle`,children:[(0,l.jsx)(`button`,{type:`button`,className:S===`chunks`?`active`:``,onClick:()=>C(`chunks`),title:`This chunk's own content`,children:`chunk`}),(0,l.jsx)(`button`,{type:`button`,className:S===`markdown`?`active`:``,onClick:()=>C(`markdown`),title:X?`Whole document as Markdown`:`This chunk + its sub-chunks as Markdown`,children:`markdown`})]}),(0,l.jsx)(`button`,{type:`button`,className:`chunk-edit`,onClick:()=>ee(b),children:`edit`}),p.documentEntityTypes&&g(b)&&(0,l.jsx)(`button`,{type:`button`,onClick:()=>ne(b),title:`Change this subject's type to another type in force`,children:`change type`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>P(!0),title:`View this chunk's edit history + diffs`,children:`history`}),!X&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{type:`button`,onClick:()=>void ft(`up`),disabled:!ut.canUp,title:`Move this chunk up within its level`,children:`↑`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void ft(`down`),disabled:!ut.canDown,title:`Move this chunk down within its level`,children:`↓`})]}),!X&&(0,l.jsx)(`button`,{type:`button`,className:`danger`,onClick:()=>I(!0),title:`Delete this chunk and its sub-chunks`,children:`delete`})]})]}),(0,l.jsx)(`div`,{className:`doc-content-body`,children:b.type===`mermaid`?b.body?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Ke,{code:b.body}),S===`markdown`&&(0,l.jsx)(`pre`,{className:`md-pre doc-mermaid-source`,children:(0,l.jsx)(`code`,{children:b.body})})]}):(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`(empty diagram)`}):b.type===`image`||b.asset?k?(0,l.jsxs)(`p`,{className:`doc-empty-body`,children:[`Image failed to load: `,k]}):D?(0,l.jsxs)(`figure`,{className:`doc-image`,children:[(0,l.jsx)(`img`,{src:D,alt:It(b)}),b.body&&(0,l.jsx)(`figcaption`,{children:b.body})]}):(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`Loading image…`}):S===`markdown`?w===null?(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`Assembling Markdown…`}):(0,l.jsx)(Pt,{source:w}):b.body?(0,l.jsx)(Pt,{source:b.body}):(0,l.jsx)(`p`,{className:`doc-empty-body`,children:`(empty chunk)`})}),(0,l.jsx)(wt,{edges:_e,incomplete:G,documentId:e,selectedId:v,onSelectChunk:y,onOpenDocument:s?tt:void 0,onRuleStatement:Ue}),(0,l.jsx)(St,{documentId:e,selectedId:v,scope:t,browse:m,onSelectChunk:y,onOpenDocument:s?tt:void 0,refreshKey:ye,review:Xe})]}):(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`Select a chunk on the left.`})})})]}),ce&&a&&(0,l.jsx)(`div`,{className:`doc-assistant`,children:a({documentId:e,scope:t,subject:i?.subject,onChanged:q})}),M&&(0,l.jsx)(qe,{chunk:M,scope:t,browse:m,onClose:()=>ee(null),onSaved:q}),te&&(0,l.jsx)(Je,{chunk:te,scope:t,browse:m,onClose:()=>ne(null),onSaved:q}),N&&b&&(0,l.jsx)(Mt,{chunkId:b.id,chunkTitle:b.title,scope:t,browse:m,onClose:()=>P(!1)}),ge&&Q&&(0,l.jsx)(dt,{documentId:e,rootChunkId:Q,docType:U?.type,docStatus:U?.status,chunkStatuses:je,scope:t,browse:m,onClose:()=>W(!1),onSaved:q}),F&&b&&(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:()=>I(!1),children:(0,l.jsxs)(`div`,{className:`modal chunk-delete-confirm`,onClick:e=>e.stopPropagation(),children:[(0,l.jsx)(`h3`,{children:`Delete chunk`}),(0,l.jsxs)(`p`,{className:`modal-context`,children:[`Delete “`,b.title||`(untitled)`,`” and all of its sub-chunks? This cannot be undone.`]}),(0,l.jsxs)(`div`,{className:`modal-buttons`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:()=>I(!1),children:`cancel`}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,onClick:()=>void pt(),children:`delete`})]})]})})]})}function Rt(e,t=``){let n=e.get(t);if(!n)return[];let r=n.entries.map(n=>{let r=n.kind===`directory`&&n.full_path.startsWith(`${t}/`);return{name:n.name,fullPath:n.full_path,kind:n.kind,resourceRef:n.resource_ref,listing:r?e.get(n.full_path):void 0,children:r?Rt(e,n.full_path):[]}});return r.sort((e,t)=>{let n=e.kind===`directory`;return n===(t.kind===`directory`)?e.name.localeCompare(t.name):n?-1:1}),r}var zt={directory:`📁`,document:`📄`,volume_mount:`💾`,memory_entry:`🧠`};function Bt(e){let{tree:t,root:n}=e;return!n||!n.loaded&&n.loading?(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`Loading…`})}):n.loaded&&t.length===0&&!n.nextCursor?(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`This tree is empty. Create a folder or document to begin.`})}):(0,l.jsxs)(`ul`,{className:`tree path-tree`,children:[t.map(t=>(0,l.jsx)(Ut,{node:t,...e},t.fullPath)),(0,l.jsx)(Vt,{dir:``,listing:n,...e})]})}function Vt({dir:e,listing:t,onLoadMore:n,onRetry:r}){let i=[];return!t||t.loading&&t.entries.length===0?i.push((0,l.jsx)(`li`,{className:`node path-status`,children:(0,l.jsx)(`span`,{className:`path-implicit`,children:`loading…`})},`status`)):t.error?i.push((0,l.jsxs)(`li`,{className:`node path-status`,children:[e!==``&&(0,l.jsxs)(`span`,{className:`path-err`,children:[`failed to load: `,t.error]}),` `,(0,l.jsx)(`button`,{type:`button`,className:`path-more`,onClick:()=>r(e),children:`retry`})]},`status`)):t.loaded&&t.entries.length===0&&e!==``&&i.push((0,l.jsx)(`li`,{className:`node path-status`,children:(0,l.jsx)(`span`,{className:`path-implicit`,children:`empty`})},`status`)),t?.nextCursor&&!t.error&&i.push((0,l.jsx)(`li`,{className:`node path-status`,children:(0,l.jsx)(`button`,{type:`button`,className:`path-more`,disabled:t.loading,onClick:()=>n(e),children:t.loading?`loading…`:`Load more (${t.entries.length} shown)`})},`more`)),(0,l.jsx)(l.Fragment,{children:i})}function Ht(e,t){if(e.kind!==`document`||!t)return;let n=e.resourceRef;return n?.document_id?t.get(n.document_id):void 0}function Ut(e){let{node:t,expanded:n,onToggle:r,selectedPath:i,onSelect:a,summaries:o}=e,s=t.kind===`directory`,c=s&&n.has(t.fullPath),u=i===t.fullPath,d=Ht(t,o),f=d&&d.color_enabled?Fe(Ne(d.type,d.status,Me(d.color_scheme))):void 0;return(0,l.jsxs)(`li`,{className:`node path-node kind-${t.kind} ${u?`selected`:``}`,children:[(0,l.jsxs)(`div`,{className:`row path-row`,style:f,children:[(0,l.jsx)(`button`,{type:`button`,className:`tree-caret`,"aria-label":c?`collapse`:`expand`,"aria-expanded":s?c:void 0,disabled:!s,onClick:e=>{e.stopPropagation(),s&&r(t.fullPath)},children:s?c?`▼`:`▶`:`·`}),(0,l.jsxs)(`button`,{type:`button`,className:`path-link`,onClick:()=>a(t),title:t.fullPath,children:[(0,l.jsx)(`span`,{className:`path-kind-icon`,"aria-hidden":!0,children:zt[t.kind]??`•`}),(0,l.jsx)(`span`,{className:`path-name`,children:t.name}),d?.type&&(0,l.jsx)(`span`,{className:`chunk-badge`,children:d.type}),d?.status&&(0,l.jsx)(`span`,{className:`chunk-badge chunk-status`,children:d.status})]})]}),c&&(0,l.jsxs)(`ul`,{className:`children path-children`,children:[t.children.map(t=>(0,l.jsx)(Ut,{...e,node:t},t.fullPath)),(0,l.jsx)(Vt,{...e,dir:t.fullPath,listing:t.listing})]})]})}var Wt=/^[A-Za-z0-9._-]+$/;function Gt(e,t){return`${e}/${t}`}function Kt(e,t){for(let n of e){if(n.fullPath===t)return n;let e=Kt(n.children,t);if(e)return e}}function qt(e){let{theme:t,defaultScope:n,path:r,onPathChange:i,browse:a,principal:o,renderAssistant:s,renderNavigator:c,onError:u}=e,d=I(e);return(0,l.jsx)(L,{theme:t,dataLayer:d,children:(0,l.jsx)(Jt,{defaultScope:n,path:r,onPathChange:i,browse:a,principal:o,renderAssistant:s,renderNavigator:c,onError:u})})}function Jt({defaultScope:e,path:t,onPathChange:n,browse:r,principal:i,renderAssistant:a,renderNavigator:o,onError:s}){let u=T(),[d,f]=(0,c.useState)(e??`user`),[p,g]=(0,c.useState)(void 0),[_,v]=(0,c.useState)(null),[y,b]=(0,c.useState)(null),[x,S]=(0,c.useState)(()=>new Set),C=t===void 0?p:t,w=(0,c.useRef)(n);(0,c.useEffect)(()=>{w.current=n},[n]);let E=(0,c.useRef)(s);(0,c.useEffect)(()=>{E.current=s},[s]);let[D,A]=(0,c.useState)([]),j=(0,c.useRef)(0),ne=(0,c.useRef)(void 0),N=(0,c.useCallback)(e=>{ne.current=e,w.current?.(e),g(e)},[]),P=(0,c.useCallback)(e=>{j.current++,A(e=>e.length>0?[]:e),N(e)},[N]);(0,c.useEffect)(()=>{t!==void 0&&t!==ne.current&&(j.current++,A(e=>e.length>0?[]:e))},[t]);let F=(0,c.useMemo)(()=>r&&(r.scopeId||r.tenant)?{scopeId:r.scopeId,tenant:r.tenant}:void 0,[r?.scopeId,r?.tenant]),I=(0,c.useMemo)(()=>new M(u,d,F),[u,d,F]),L=(0,c.useSyncExternalStore)(I.subscribe,I.getSnapshot),z=(0,c.useCallback)(e=>{E.current?.(e)},[]),[ae,V]=(0,c.useState)(()=>o?m(globalThis.localStorage):`tree`),H=!!o&&ae===`stars`,ce=(0,c.useCallback)(e=>{V(e),h(globalThis.localStorage,e),e===`tree`&&U(!1)},[]),[ue,U]=(0,c.useState)(!1),[de,fe]=(0,c.useState)(0),[pe,me]=(0,c.useState)(),[he,ge]=(0,c.useState)(),W=(0,c.useCallback)((e,t)=>(fe(e=>e+1),I.invalidate(e,t)),[I]),[_e,ve]=(0,c.useState)(()=>new Map),G=(0,c.useRef)(new Set),K=(0,c.useRef)(0),ye=(0,c.useCallback)(()=>{K.current++,G.current=new Set,ve(new Map)},[]),be=(0,c.useRef)(!0);(0,c.useEffect)(()=>{be.current?be.current=!1:(P(void 0),v(null),S(new Set),ye()),I.loadDir(``).catch(z)},[I,P,ye,z]),(0,c.useEffect)(()=>{for(let e of x)L.has(e)||I.loadDir(e).catch(z)},[I,x,L,z]);let xe=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=xe.current!==null&&xe.current!==I;if(xe.current=I,!C||e)return;let t=k(C).filter(e=>e!==``);S(e=>{if(t.every(t=>e.has(t)))return e;let n=new Set(e);return t.forEach(e=>n.add(e)),n}),I.reveal(C).catch(z)},[I,C,z]),(0,c.useEffect)(()=>{if(d===`tenant`)return;let e=[];for(let t of L.values())for(let n of te(t.entries))G.current.has(n)||(G.current.add(n),e.push(n));let t=K.current;for(let n=0;n<e.length;n+=500)u.documentsSummary({documentIds:e.slice(n,n+500)},d,F).then(e=>{K.current===t&&ve(t=>{let n=new Map(t);for(let t of e.documents??[])n.set(t.document_id,t);return n})}).catch(()=>{})},[u,L,d,F]);let Se=(0,c.useMemo)(()=>Rt(L),[L]),Ce=(0,c.useCallback)(async()=>{v(null),ye(),fe(e=>e+1),await I.refresh(x).catch(z),C&&await I.reveal(C).catch(z)},[I,x,C,ye,z]),we=(0,c.useCallback)(e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),q=(0,c.useCallback)(e=>I.loadMore(e).catch(z),[I,z]),Te=(0,c.useCallback)(e=>{(I.getSnapshot().get(e)?.loaded?I.loadMore(e):I.loadDir(e)).catch(z)},[I,z]),J=(0,c.useMemo)(()=>C?Kt(Se,C):void 0,[Se,C]),Ee=L.get(``)?.error,Y=J?.kind===`directory`?J.fullPath:void 0,[X,De]=(0,c.useState)(null);(0,c.useEffect)(()=>{if(!Y||!u.pathIsStored)return;let e=!1;return u.pathIsStored(Y,d,F).then(t=>{e||De({path:Y,explicit:t})},()=>{}),()=>{e=!0}},[u,Y,d,F]);let Oe=J?J.kind===`directory`?X?.path===J.fullPath?X.explicit?`yes`:`implicit (no entry)`:void 0:`yes`:void 0,ke=(0,c.useMemo)(()=>J?J.kind===`directory`?J.fullPath:O(J.fullPath):``,[J]),Z=ke||`/`,Q=d!==`tenant`,Ae=(0,c.useCallback)(()=>{b({title:`New folder in ${Z}`,fields:[{key:`name`,label:`Folder name`,placeholder:`e.g. launches`}],submitLabel:`Create`,onSubmit:async e=>{let t=e.name.trim();if(!Wt.test(t))throw Error(`name may contain only [A-Za-z0-9._-]`);let n=Gt(ke,t);await u.pathMkdir(n,d,F),await W(n).catch(z),P(n)}})},[u,I,ke,Z,d,F,z,P]),je=(0,c.useCallback)(()=>{b({title:`New document in ${Z}`,fields:[{key:`name`,label:`Path name`,placeholder:`e.g. launch-plan`},{key:`title`,label:`Title`,placeholder:`e.g. Launch Plan`}],submitLabel:`Create`,onSubmit:async e=>{let t=e.name.trim();if(!Wt.test(t))throw Error(`name may contain only [A-Za-z0-9._-]`);let n=e.title.trim()||t,r=Gt(ke,t);await u.documentCreate(n,r,d,F),await W(r).catch(z),P(r)}})},[u,I,ke,Z,d,F,z,P]),Me=(0,c.useCallback)(()=>{J&&b({title:`Rename / move ${J.fullPath}`,fields:[{key:`to`,label:`New path`,value:J.fullPath}],submitLabel:`Move`,onSubmit:async e=>{let t=e.to.trim();if(!t.startsWith(`/`))throw Error(`path must start with /`);await u.pathMv(J.fullPath,t,d,F),await Promise.all([W(J.fullPath,{dropSubtree:!0}),W(t)]).catch(z),P(t)}})},[u,I,J,d,F,z,P]),Ne=(0,c.useCallback)(()=>{if(!J)return;if(J.kind===`document`){let e=J.resourceRef?.document_id;b({title:`Delete document ${J.fullPath}`,message:`This deletes the document, all its chunks, and its path entry. This cannot be undone.`,fields:[],submitLabel:`Delete`,danger:!0,onSubmit:async()=>{if(!e)throw Error(`this document dirent has no document_id`);await u.documentDelete(e,d,F),await W(J.fullPath).catch(z),P(void 0)}});return}let e=J;v(null),(async()=>{let t;try{t=await ee(u,e.fullPath,d,F)}catch(t){v(`could not list ${e.fullPath} for delete: ${t instanceof Error?t.message:String(t)}`);return}let n=d===`tenant`?[]:te(t);b({title:`Delete branch ${e.fullPath}`,message:t.length===0?`This removes the (empty) folder.`:`This removes the folder and everything under it`+(n.length>0?` — including ${n.length} document(s), whose chunks are deleted.`:`.`),fields:[],submitLabel:`Delete`,danger:!0,onSubmit:async()=>{for(let e of n)await u.documentDelete(e,d,F);await u.pathRm(e.fullPath,d,!0,F),await W(e.fullPath,{dropSubtree:!0}).catch(z),P(void 0)}})})()},[u,I,J,d,F,z,P]),Pe=J&&(J.kind===`directory`||J.kind===`document`),$=(0,c.useMemo)(()=>{if(D.length>0)return D[D.length-1];if(J?.kind===`document`)return{documentId:J.resourceRef?.document_id??``,path:J.fullPath,title:J.name}},[D,J]),Fe=(0,c.useCallback)((e,t)=>{let n=++j.current,r=oe(I.getSnapshot(),e.documentId);A(R(D,{...t,path:$?.path},{...e,path:r})),N(r),!r&&u.documentPath&&u.documentPath(e.documentId,d,F).then(t=>{t&&j.current===n&&(A(n=>ie(n,e.documentId,{path:t})),N(t))},()=>{})},[u,I,D,$?.path,d,F,N]),Ie=(0,c.useCallback)(e=>{let t=re(D,e);t!==D&&(j.current++,A(t),N(t[t.length-1].path))},[D,N]),Le=(0,c.useCallback)((e,t)=>A(n=>ie(n,e,{title:t})),[]),Re=(0,c.useCallback)(e=>{ge(t=>({documentId:e.documentId,chunkId:e.chunkId,seq:(t?.seq??0)+1})),$?.documentId!==e.documentId&&(e.path?P(e.path):(j.current++,A([{documentId:e.documentId,chunkId:e.chunkId}]),N(void 0)))},[$?.documentId,P,N]),ze=(0,c.useMemo)(()=>({scope:d,browse:F,selection:{documentId:$?.documentId,chunkId:pe&&pe.documentId===$?.documentId?pe.chunkId:void 0,path:$?.path},onSelect:Re,reloadToken:de,maximized:ue,onToggleMaximize:()=>U(e=>!e),subject:i?.subject}),[d,F,$?.documentId,$?.path,pe,Re,de,ue,i?.subject]),Be=he&&$&&he.documentId===$.documentId?he:void 0,Ve=!!$?.path&&J?.kind===`document`&&J.fullPath===$.path;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(le,{className:H?`paths-view paths-view--stars`:`paths-view`,defaultLeftWidth:H?720:420,minLeftWidth:280,minRightWidth:300,storageKey:H?`loomcycle.explorer.split.stars`:`loomcycle.explorer.split.paths`,hideRight:H&&ue,children:[(0,l.jsxs)(`div`,{className:`left`,children:[(0,l.jsxs)(`div`,{className:`paths-toolbar`,children:[(0,l.jsxs)(`label`,{className:`paths-scope`,children:[(0,l.jsx)(`span`,{children:`scope`}),(0,l.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),children:[(0,l.jsx)(`option`,{value:`user`,children:`user`}),(0,l.jsx)(`option`,{value:`agent`,children:`agent`}),(0,l.jsx)(`option`,{value:`tenant`,children:`tenant`})]})]}),o&&(0,l.jsxs)(`div`,{className:`paths-nav-switch`,role:`group`,"aria-label":`Navigator`,children:[(0,l.jsx)(`button`,{type:`button`,"aria-pressed":!H,className:H?void 0:`active`,onClick:()=>ce(`tree`),title:`Browse the Path tree`,children:`tree`}),(0,l.jsx)(`button`,{type:`button`,"aria-pressed":H,className:H?`active`:void 0,onClick:()=>ce(`stars`),title:`Browse the scope as a 3D star map`,children:`stars`})]}),(0,l.jsxs)(`div`,{className:`paths-toolbar-actions`,children:[!H&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{type:`button`,onClick:Ae,title:`New folder in ${Z}`,children:`+ folder`}),(0,l.jsx)(`button`,{type:`button`,onClick:je,disabled:!Q,title:Q?`New document in ${Z}`:`Documents are agent/user scope only`,children:`+ document`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>void Ce(),title:`Reload the tree`,children:`↻`})]})]}),!H&&(0,l.jsxs)(`p`,{className:`paths-context`,children:[`new items → `,(0,l.jsx)(`code`,{children:Z}),F?.scopeId&&(0,l.jsxs)(l.Fragment,{children:[` · `,`subject `,(0,l.jsx)(`code`,{children:F.scopeId})]}),F?.tenant&&(0,l.jsxs)(l.Fragment,{children:[` · `,`tenant `,(0,l.jsx)(`code`,{children:F.tenant})]})]}),(_||Ee)&&(0,l.jsx)(`div`,{className:`paths-err`,children:_||Ee}),H&&o?(0,l.jsx)(`div`,{className:`paths-navigator`,children:o(ze)}):(0,l.jsx)(Bt,{tree:Se,root:L.get(``),expanded:x,onToggle:we,onLoadMore:q,onRetry:Te,selectedPath:C,onSelect:e=>P(e.fullPath),summaries:_e})]}),(0,l.jsx)(`div`,{className:`right`,children:$?(0,l.jsxs)(`div`,{className:`paths-doc`,children:[(0,l.jsx)(se,{trail:D,onJump:Ie}),(0,l.jsxs)(`div`,{className:`paths-doc-head`,children:[$.path?(0,l.jsx)(`code`,{className:`paths-doc-path`,children:$.path}):(0,l.jsxs)(`span`,{className:`paths-doc-path paths-doc-unfiled`,title:`Opened by id — no entry for this document was found in the Path tree`,children:[B($),` `,(0,l.jsx)(`em`,{children:`· opened by id, not in the tree`})]}),Ve&&(0,l.jsxs)(`div`,{className:`paths-detail-actions`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:Me,children:`rename / move`}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,onClick:Ne,children:`delete`})]})]}),(0,l.jsx)(Lt,{documentId:$.documentId,scope:d,titleHint:$.title,browse:F,principal:i,renderAssistant:a,initialChunkId:$.chunkId??Be?.chunkId,onOpenDocument:Fe,onTitle:Le,onChunkSelect:e=>me({documentId:$.documentId,chunkId:e}),focusChunk:Be},D.length)]}):J?(0,l.jsxs)(`div`,{className:`paths-detail`,children:[(0,l.jsxs)(`h2`,{children:[(0,l.jsx)(`span`,{className:`paths-detail-kind`,children:J.kind}),(0,l.jsx)(`code`,{children:J.fullPath})]}),(0,l.jsxs)(`dl`,{className:`paths-detail-meta`,children:[(0,l.jsx)(`dt`,{children:`scope`}),(0,l.jsx)(`dd`,{children:d}),Oe&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`dt`,{children:`stored`}),(0,l.jsx)(`dd`,{children:Oe})]})]}),Pe?(0,l.jsxs)(`div`,{className:`paths-detail-actions`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:Me,children:`rename / move`}),(0,l.jsx)(`button`,{type:`button`,className:`danger`,onClick:Ne,children:`delete`})]}):(0,l.jsxs)(`p`,{className:`paths-readonly`,children:[`Read-only — `,J.kind,` entries are managed by their own tool.`]})]}):(0,l.jsx)(`div`,{className:`empty`,children:(0,l.jsx)(`p`,{children:`Select a path on the left, or create a folder / document.`})})})]}),y&&(0,l.jsx)(Yt,{state:y,onClose:()=>b(null)})]})}function Yt({state:e,onClose:t}){let[n,r]=(0,c.useState)(()=>Object.fromEntries(e.fields.map(e=>[e.key,e.value??``]))),[i,a]=(0,c.useState)(!1),[o,s]=(0,c.useState)(null);return(0,l.jsx)(`div`,{className:`modal-overlay`,onClick:t,children:(0,l.jsxs)(`form`,{className:`modal`,onClick:e=>e.stopPropagation(),onSubmit:async r=>{r.preventDefault(),a(!0),s(null);try{await e.onSubmit(n),t()}catch(e){s(e instanceof Error?e.message:String(e)),a(!1)}},children:[(0,l.jsxs)(`div`,{className:`modal-header sticky-top`,children:[(0,l.jsx)(`h3`,{children:e.title}),(0,l.jsxs)(`div`,{className:`modal-buttons modal-buttons-top`,children:[(0,l.jsx)(`button`,{type:`button`,onClick:t,disabled:i,children:`cancel`}),(0,l.jsx)(`button`,{type:`submit`,className:e.danger?`danger`:`primary`,disabled:i,children:i?`working…`:e.submitLabel})]})]}),e.message&&(0,l.jsx)(`p`,{className:`modal-context`,children:e.message}),e.fields.map((e,t)=>(0,l.jsxs)(`label`,{className:`path-field`,children:[(0,l.jsx)(`span`,{children:e.label}),(0,l.jsx)(`input`,{className:`path-modal-input`,value:n[e.key],placeholder:e.placeholder,autoFocus:t===0,onChange:t=>r(n=>({...n,[e.key]:t.target.value}))})]},e.key)),o&&(0,l.jsx)(`div`,{className:`modal-err`,children:o})]})})}function Xt(e){let{documentId:t,scope:n,browse:r,theme:i}=e,a=I(e);return(0,l.jsx)(L,{theme:i,dataLayer:a,children:(0,l.jsx)(Zt,{...e},`${n}:${t}:${r?.scopeId??``}:${r?.tenant??``}`)})}function Zt({documentId:e,scope:t,titleHint:n,browse:r,principal:i,renderAssistant:a,onOpenDocument:o}){let[s,u]=(0,c.useState)([]),d=s[s.length-1],f=(0,c.useCallback)((e,t)=>{o?o(e,t):u(n=>R(n,t,e))},[o]),p=(0,c.useCallback)(e=>u(t=>re(t,e)),[]),m=(0,c.useCallback)((e,t)=>u(n=>ie(n,e,{title:t})),[]);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(se,{trail:s,onJump:p}),(0,l.jsx)(Lt,{documentId:d?.documentId??e,scope:t,titleHint:d?d.title:n,browse:r,principal:i,renderAssistant:a,initialChunkId:d?.chunkId,onOpenDocument:f,onTitle:m},s.length)]})}exports.DEFAULT_SCHEME=Ae,exports.DocumentViewer=Xt,exports.EDGE_PAGE_CAP=pe,exports.PathExplorer=qt,exports.QUEUE_CHANGED_RETRIES=we,exports.RULING_CHUNK=Ce,exports.RequestError=P,exports.assetFetchFromConnection=N,exports.chunkColor=Pe,exports.chunkCount=Y,exports.createLoomcycleClient=ne,exports.dataLayerFromClient=x,exports.docColor=Ne,exports.effectiveScheme=Me,exports.hexToTint=$,exports.isQueueChanged=Te,exports.jsonPostFromConnection=F,exports.loadDocumentEdges=me,exports.runRuling=J,exports.tintStyle=Fe,exports.undoRulings=Ee;
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|