@loomcycle/explorer 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ColorSchemeEditor.d.ts +13 -0
- package/dist/components/CrossReferences.d.ts +8 -0
- package/dist/components/DocumentChunkTree.d.ts +5 -1
- package/dist/components/Mermaid.d.ts +4 -0
- package/dist/components/PathTree.d.ts +3 -1
- package/dist/index.cjs +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1219 -639
- package/dist/index.js.map +1 -1
- package/dist/lib/colorScheme.d.ts +26 -0
- package/dist/lib/createClient.d.ts +10 -0
- package/dist/lib/dataLayer.d.ts +17 -2
- package/dist/lib/imageUpload.d.ts +7 -0
- package/dist/styles.css +294 -0
- package/dist/types.d.ts +17 -0
- package/package.json +12 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BrowseScope, DocScope } from "../types";
|
|
2
|
+
export interface ColorSchemeEditorProps {
|
|
3
|
+
documentId: string;
|
|
4
|
+
rootChunkId: string;
|
|
5
|
+
docType?: string;
|
|
6
|
+
docStatus?: string;
|
|
7
|
+
chunkStatuses: string[];
|
|
8
|
+
scope: DocScope;
|
|
9
|
+
browse?: BrowseScope;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onSaved: () => void;
|
|
12
|
+
}
|
|
13
|
+
export default function ColorSchemeEditor({ documentId, rootChunkId, docType, docStatus, chunkStatuses, scope, browse, onClose, onSaved, }: ColorSchemeEditorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocEdge } from "../types";
|
|
2
|
+
export interface CrossReferencesProps {
|
|
3
|
+
edges: DocEdge[];
|
|
4
|
+
documentId: string;
|
|
5
|
+
selectedId?: string;
|
|
6
|
+
onSelectChunk: (id: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export default function CrossReferences({ edges, documentId, selectedId, onSelectChunk, }: CrossReferencesProps): import("react").JSX.Element | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChunkRow } from "../types";
|
|
2
|
+
import { type ColorScheme } from "../lib/colorScheme";
|
|
2
3
|
export interface ChunkNode {
|
|
3
4
|
row: ChunkRow;
|
|
4
5
|
children: ChunkNode[];
|
|
@@ -9,5 +10,8 @@ export interface DocumentChunkTreeProps {
|
|
|
9
10
|
tree: ChunkNode[];
|
|
10
11
|
selectedId?: string;
|
|
11
12
|
onSelect: (node: ChunkNode) => void;
|
|
13
|
+
colorEnabled?: boolean;
|
|
14
|
+
scheme?: ColorScheme;
|
|
15
|
+
linkedIds?: Set<string>;
|
|
12
16
|
}
|
|
13
|
-
export default function DocumentChunkTree({ tree, selectedId, onSelect }: DocumentChunkTreeProps): import("react").JSX.Element;
|
|
17
|
+
export default function DocumentChunkTree({ tree, selectedId, onSelect, colorEnabled, scheme, linkedIds, }: DocumentChunkTreeProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PathEntry } from "../types";
|
|
2
|
+
import { type DocSummary } from "../lib/colorScheme";
|
|
2
3
|
export interface PathNode {
|
|
3
4
|
name: string;
|
|
4
5
|
fullPath: string;
|
|
@@ -14,5 +15,6 @@ export interface PathTreeProps {
|
|
|
14
15
|
tree: PathNode[];
|
|
15
16
|
selectedPath?: string;
|
|
16
17
|
onSelect: (node: PathNode) => void;
|
|
18
|
+
summaries?: Map<string, DocSummary>;
|
|
17
19
|
}
|
|
18
|
-
export default function PathTree({ tree, selectedPath, onSelect }: PathTreeProps): import("react").JSX.Element;
|
|
20
|
+
export default function PathTree({ tree, selectedPath, onSelect, summaries }: PathTreeProps): import("react").JSX.Element;
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),ie=require("@loomcycle/client");function V(s){return{pathLs:(t,a,n,r)=>s.path({op:"ls",path:t,scope:a,recursive:n},r),pathMkdir:(t,a,n)=>s.path({op:"mkdir",path:t,scope:a},n),pathMv:(t,a,n,r)=>s.path({op:"mv",path:t,to:a,scope:n},r),pathRm:(t,a,n,r)=>s.path({op:"rm",path:t,scope:a,recursive:n},r),documentCreate:(t,a,n,r)=>s.document({op:"create_document",title:t,path:a,scope:n},r),documentDelete:(t,a,n)=>s.document({op:"delete_document",id:t,scope:a},n),documentQueryChunks:(t,a,n)=>s.document({op:"query_chunks",document_id:t,scope:a,limit:1e3},n),documentGetChunk:(t,a,n)=>s.document({op:"get_chunk",id:t,scope:a},n),documentUpdateChunk:(t,a,n,r,o)=>s.document({op:"update_chunk",id:t,revision:a,scope:r,...n},o),documentExportMd:(t,a,n,r)=>s.document({op:"export_md",document_id:t,scope:a,include_metadata:n},r)}}const Y=i.createContext(null);function de({value:s,children:t}){return e.jsx(Y.Provider,{value:s,children:t})}function z(){const s=i.useContext(Y);if(!s)throw new Error("useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)");return s}function K(s){const t=s.fetch;return new ie.LoomcycleClient({baseUrl:s.baseUrl,authToken:s.token||void 0,fetch:(a,n)=>t?t(a,n):fetch(a,n)})}function ee(s){const{dataLayer:t,client:a,connection:n}=s;return i.useMemo(()=>t||(a?V(a):n?V(K(n)):null),[t,a,n?.baseUrl,n?.token,n?.fetch])}function te({theme:s,dataLayer:t,children:a}){const n=s?{"data-theme":s}:{};return t?e.jsx("div",{className:"loomcycle-explorer",...n,children:e.jsx(de,{value:t,children:a})}):e.jsx("div",{className:"loomcycle-explorer",...n,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."]})})}const H=6;function ue({children:s,defaultLeftWidth:t=380,minLeftWidth:a=180,minRightWidth:n=240,storageKey:r,className:o}){const[l,d]=i.useState(()=>{if(r){const b=localStorage.getItem(r),w=b?parseInt(b,10):NaN;if(Number.isFinite(w)&&w>=a)return w}return t}),c=i.useRef(null),[u,h]=i.useState(!1);i.useEffect(()=>{!r||u||localStorage.setItem(r,String(Math.round(l)))},[r,l,u]);const N=i.useCallback(b=>{b.preventDefault(),h(!0),b.target.setPointerCapture(b.pointerId)},[]),j=i.useCallback(b=>{if(!u||!c.current)return;const w=c.current.getBoundingClientRect(),L=b.clientX-w.left,M=w.width-n-H,R=Math.max(a,Math.min(L,M));d(R)},[u,a,n]),S=i.useCallback(b=>{h(!1);try{b.target.releasePointerCapture(b.pointerId)}catch{}},[]);return e.jsxs("div",{ref:c,className:`splitter ${o??""} ${u?"dragging":""}`,style:{gridTemplateColumns:`${l}px ${H}px 1fr`},children:[e.jsx("div",{className:"splitter-pane splitter-left",children:s[0]}),e.jsx("div",{className:"splitter-handle",role:"separator","aria-orientation":"vertical","aria-valuenow":Math.round(l),onPointerDown:N,onPointerMove:j,onPointerUp:S,onPointerCancel:S}),e.jsx("div",{className:"splitter-pane splitter-right",children:s[1]})]})}function he(s){const t=new Map;s.forEach(r=>t.set(r.id,{row:r,children:[]}));const a=[];s.forEach(r=>{const o=t.get(r.id);r.parent_id&&t.has(r.parent_id)?t.get(r.parent_id).children.push(o):a.push(o)});const n=r=>{r.sort((o,l)=>o.row.position-l.row.position),r.forEach(o=>n(o.children))};return n(a),a}function ne(s,t){for(const a of s){if(a.row.id===t)return a;const n=ne(a.children,t);if(n)return n}}function me({tree:s,selectedId:t,onSelect:a}){const[n,r]=i.useState(()=>new Map),o=i.useCallback(l=>{r(d=>{const c=new Map(d);return c.set(l,d.get(l)===!1),c})},[]);return i.useEffect(()=>{if(!t)return;const l=pe(s,t);l.length!==0&&r(d=>{let c=!1;const u=new Map(d);for(const h of l)u.get(h)===!1&&(u.set(h,!0),c=!0);return c?u:d})},[s,t]),s.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"No chunks."})}):e.jsx("ul",{className:"tree chunk-tree",children:s.map(l=>e.jsx(se,{node:l,expanded:n,toggle:o,selectedId:t,onSelect:a},l.row.id))})}function pe(s,t){const a=[],n=(r,o)=>{for(const l of r){if(l.row.id===t)return a.push(...o),!0;if(n(l.children,[...o,l.row.id]))return!0}return!1};return n(s,[]),a}function se({node:s,expanded:t,toggle:a,selectedId:n,onSelect:r}){const o=s.children.length>0,l=t.get(s.row.id)!==!1,d=n===s.row.id;return e.jsxs("li",{className:`node chunk-node ${d?"selected":""}`,children:[e.jsxs("div",{className:"row chunk-row",children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":l?"collapse":"expand",disabled:!o,onClick:c=>{c.stopPropagation(),o&&a(s.row.id)},children:o?l?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"chunk-link",onClick:()=>r(s),title:s.row.title,children:[e.jsx("span",{className:"chunk-title",children:s.row.title||"(untitled)"}),s.row.type&&e.jsx("span",{className:"chunk-badge",children:s.row.type}),s.row.status&&e.jsx("span",{className:"chunk-badge chunk-status",children:s.row.status})]})]}),o&&l&&e.jsx("ul",{className:"children chunk-children",children:s.children.map(c=>e.jsx(se,{node:c,expanded:t,toggle:a,selectedId:n,onSelect:r},c.row.id))})]})}function fe({chunk:s,scope:t,browse:a,onClose:n,onSaved:r}){const o=z(),[l,d]=i.useState(s.title),[c,u]=i.useState(s.type??""),[h,N]=i.useState(s.status??""),[j,S]=i.useState(s.body??""),[b,w]=i.useState(s.fields?JSON.stringify(s.fields,null,2):""),[L,M]=i.useState(!1),[R,C]=i.useState(null),[P,D]=i.useState(!1),W=async f=>{f.preventDefault(),C(null),D(!1);const g={body:j,title:l,type:c,status:h};if(b.trim()!=="")try{g.fields=JSON.parse(b)}catch{C("fields must be valid JSON");return}M(!0);try{const v=await o.documentUpdateChunk(s.id,s.revision,g,t,a);r(v),n()}catch(v){const O=v instanceof Error?v.message:String(v);C(O),D(/revision conflict/i.test(O)),M(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:n,children:e.jsxs("form",{className:"modal chunk-editor",onClick:f=>f.stopPropagation(),onSubmit:W,children:[e.jsx("h3",{children:"Edit chunk"}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Title"}),e.jsx("input",{className:"path-modal-input",value:l,onChange:f=>d(f.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:c,placeholder:"(none)",onChange:f=>u(f.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:f=>N(f.target.value)})]})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Body (Markdown)"}),e.jsx("textarea",{className:"modal-textarea chunk-body-input",rows:12,value:j,onChange:f=>S(f.target.value)})]}),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:b,placeholder:"{}",onChange:f=>w(f.target.value)})]}),R&&e.jsxs("div",{className:"modal-err",children:[R,P&&" — reopen the chunk to load the latest, then reapply your edit."]}),e.jsxs("div",{className:"modal-buttons",children:[e.jsx("button",{type:"button",onClick:n,disabled:L,children:"cancel"}),e.jsx("button",{type:"submit",className:"primary",disabled:L,children:L?"saving…":"save"})]})]})})}function Z({source:s}){return e.jsx("div",{className:"md",children:xe(s)})}function xe(s){const t=s.replace(/\r\n/g,`
|
|
2
|
-
`).
|
|
3
|
-
`),a=[]
|
|
4
|
-
`)})},r++));continue}const l=/^(#{1,6})\s+(.*)$/.exec(o);if(l){a.push(je(l[1].length,U(l[2]),r++)),n++;continue}if(/^>\s?/.test(o)){const h=[];for(;n<t.length&&/^>\s?/.test(t[n]);)h.push(t[n].replace(/^>\s?/,"")),n++;a.push(e.jsx("blockquote",{children:U(h.join(" "))},r++));continue}const d=/^[-*]\s+(.*)$/,c=/^\d+\.\s+(.*)$/;if(d.test(o)||c.test(o)){const h=c.test(o),N=h?c:d,j=[];let S=0;for(;n<t.length&&N.test(t[n]);){const b=N.exec(t[n]);j.push(e.jsx("li",{children:U(b[1])},S++)),n++}a.push(h?e.jsx("ol",{children:j},r++):e.jsx("ul",{children:j},r++));continue}const u=[];for(;n<t.length&&t[n].trim()!==""&&!t[n].startsWith("```")&&!/^(#{1,6})\s+/.test(t[n])&&!/^>\s?/.test(t[n])&&!d.test(t[n])&&!c.test(t[n]);)u.push(t[n]),n++;a.push(e.jsx("p",{children:U(u.join(" "))},r++))}return a}function je(s,t,a){switch(s){case 1:return e.jsx("h1",{children:t},a);case 2:return e.jsx("h2",{children:t},a);case 3:return e.jsx("h3",{children:t},a);case 4:return e.jsx("h4",{children:t},a);case 5:return e.jsx("h5",{children:t},a);default:return e.jsx("h6",{children:t},a)}}const be=/(`[^`]+`)|(\*\*[^*]+?\*\*)|(\*[^*]+?\*)|(\[[^\]]+\]\([^)]+\))/;function U(s){const t=[];let a=s,n=0;for(;a.length>0;){const r=be.exec(a);if(!r){t.push(a);break}r.index>0&&t.push(a.slice(0,r.index));const o=r[0];if(o.startsWith("`"))t.push(e.jsx("code",{children:o.slice(1,-1)},n++));else if(o.startsWith("**"))t.push(e.jsx("strong",{children:o.slice(2,-2)},n++));else if(o.startsWith("*"))t.push(e.jsx("em",{children:o.slice(1,-1)},n++));else{const l=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(o),d=l[1],c=l[2],u=c.startsWith("/")&&!c.startsWith("//");/^https?:\/\//i.test(c)||u?t.push(e.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:d},n++)):t.push(d)}a=a.slice(r.index+o.length)}return t}function ae({documentId:s,scope:t,titleHint:a,browse:n,principal:r,renderAssistant:o}){const l=z(),d=i.useMemo(()=>n&&(n.scopeId||n.tenant)?{scopeId:n.scopeId,tenant:n.tenant}:void 0,[n?.scopeId,n?.tenant]),[c,u]=i.useState([]),[h,N]=i.useState(void 0),[j,S]=i.useState(null),[b,w]=i.useState("chunks"),[L,M]=i.useState(null),[R,C]=i.useState(null),[P,D]=i.useState(null),[W,f]=i.useState(!1),[g,v]=i.useState(0),[O,F]=i.useState(!1),m=i.useCallback(()=>v(x=>x+1),[]),$=i.useMemo(()=>he(c),[c]),T=i.useMemo(()=>c.find(y=>!y.parent_id)?.title||a||"document",[c,a]),A=i.useMemo(()=>!!j&&!j.parent_id,[j]);i.useEffect(()=>{let x=!1;return f(!0),D(null),l.documentQueryChunks(s,t,d).then(y=>{if(x)return;const _=y.chunks??[];u(_),N(p=>p??_.find(k=>!k.parent_id)?.id)}).catch(y=>!x&&D(y instanceof Error?y.message:String(y))).finally(()=>!x&&f(!1)),()=>{x=!0}},[l,s,t,g,d]),i.useEffect(()=>{N(void 0),S(null),M(null),w("chunks")},[s,t]),i.useEffect(()=>{if(!h){S(null);return}let x=!1;return l.documentGetChunk(h,t,d).then(y=>!x&&S(y)).catch(y=>!x&&D(y instanceof Error?y.message:String(y))),()=>{x=!0}},[l,h,t,g,d]),i.useEffect(()=>{if(b!=="markdown"||!h){M(null);return}const x=ne($,h);if(!x)return;let y=!1;const _=[],p=(k,E)=>{_.push({node:k,depth:E}),k.children.forEach(I=>p(I,E+1))};return p(x,0),Promise.all(_.map(k=>l.documentGetChunk(k.node.row.id,t,d))).then(k=>{if(y)return;const E=_.map((I,ce)=>{const oe=Math.min(I.depth+1,6),G=k[ce];return"#".repeat(oe)+" "+I.node.row.title+(G.body?`
|
|
1
|
+
"use strict";var We=Object.create;var he=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Je=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var Qe=(t,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of Ve(s))!Ze.call(t,r)&&r!==n&&he(t,r,{get:()=>s[r],enumerable:!(a=ze(s,r))||a.enumerable});return t};var Xe=(t,s,n)=>(n=t!=null?We(Je(t)):{},Qe(s||!t||!t.__esModule?he(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),Ye=require("@loomcycle/client"),Ke=require("react-markdown"),et=require("remark-gfm");function de(t,s){return{pathLs:(n,a,r,l)=>t.path({op:"ls",path:n,scope:a,recursive:r},l),pathMkdir:(n,a,r)=>t.path({op:"mkdir",path:n,scope:a},r),pathMv:(n,a,r,l)=>t.path({op:"mv",path:n,to:a,scope:r},l),pathRm:(n,a,r,l)=>t.path({op:"rm",path:n,scope:a,recursive:r},l),documentCreate:(n,a,r,l)=>t.document({op:"create_document",title:n,path:a,scope:r},l),documentDelete:(n,a,r)=>t.document({op:"delete_document",id:n,scope:a},r),documentGet:(n,a,r)=>t.document({op:"get_document",id:n,scope:a},r),documentsSummary:(n,a,r)=>t.document({op:"documents_summary",scope:a,...n.documentIds?{document_ids:n.documentIds}:{},...n.underPath?{under_path:n.underPath}:{}},r),documentQueryChunks:(n,a,r)=>t.document({op:"query_chunks",document_id:n,scope:a,limit:1e3},r),documentGetChunk:(n,a,r)=>t.document({op:"get_chunk",id:n,scope:a},r),documentCreateChunk:(n,a,r,l,o)=>t.document({op:"create_chunk",document_id:n,parent_id:a,scope:l,...r},o),documentSetAsset:(n,a,r,l,o,i)=>t.document({op:"set_asset",id:n,media_type:a,data:r,...l?{filename:l}:{},scope:o},i),documentGetEdges:(n,a,r)=>t.document({op:"get_edges",document_id:n,scope:a},r),documentUpdateChunk:(n,a,r,l,o)=>t.document({op:"update_chunk",id:n,revision:a,scope:l,...r},o),documentExportMd:(n,a,r,l)=>t.document({op:"export_md",document_id:n,scope:a,include_metadata:r},l),...s?{documentAssetObjectUrl:async(n,a,r)=>{const l=new URLSearchParams({scope:a});r?.scopeId&&l.set("scope_id",r.scopeId),r?.tenant&&l.set("tenant",r.tenant);const o=await s(`/v1/_document/asset/${encodeURIComponent(n)}?${l.toString()}`);if(!o.ok)throw new Error(`asset fetch failed: ${o.status}`);const i=await o.blob();return URL.createObjectURL(i)}}:{}}}const ve=c.createContext(null);function tt({value:t,children:s}){return e.jsx(ve.Provider,{value:t,children:s})}function ne(){const t=c.useContext(ve);if(!t)throw new Error("useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)");return t}function Ne(t){const s=t.fetch;return new Ye.LoomcycleClient({baseUrl:t.baseUrl,authToken:t.token||void 0,fetch:(n,a)=>s?s(n,a):fetch(n,a)})}function we(t){const s=t.fetch,n=(a,r)=>s?s(a,r):fetch(a,r);return a=>{const r={};return t.token&&(r.Authorization=`Bearer ${t.token}`),n(t.baseUrl+a,{headers:r})}}function Ce(t){const{dataLayer:s,client:n,connection:a}=t;return c.useMemo(()=>s||(n?de(n):a?de(Ne(a),we(a)):null),[s,n,a?.baseUrl,a?.token,a?.fetch])}function Se({theme:t,dataLayer:s,children:n}){const a=t?{"data-theme":t}:{};return s?e.jsx("div",{className:"loomcycle-explorer",...a,children:e.jsx(tt,{value:s,children:n})}):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."]})})}const fe=6;function nt({children:t,defaultLeftWidth:s=380,minLeftWidth:n=180,minRightWidth:a=240,storageKey:r,className:l}){const[o,i]=c.useState(()=>{if(r){const b=localStorage.getItem(r),$=b?parseInt(b,10):NaN;if(Number.isFinite($)&&$>=n)return $}return s}),d=c.useRef(null),[h,f]=c.useState(!1);c.useEffect(()=>{!r||h||localStorage.setItem(r,String(Math.round(o)))},[r,o,h]);const g=c.useCallback(b=>{b.preventDefault(),f(!0),b.target.setPointerCapture(b.pointerId)},[]),x=c.useCallback(b=>{if(!h||!d.current)return;const $=d.current.getBoundingClientRect(),A=b.clientX-$.left,R=$.width-a-fe,F=Math.max(n,Math.min(A,R));i(F)},[h,n,a]),P=c.useCallback(b=>{f(!1);try{b.target.releasePointerCapture(b.pointerId)}catch{}},[]);return e.jsxs("div",{ref:d,className:`splitter ${l??""} ${h?"dragging":""}`,style:{gridTemplateColumns:`${o}px ${fe}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(o),onPointerDown:g,onPointerMove:x,onPointerUp:P,onPointerCancel:P}),e.jsx("div",{className:"splitter-pane splitter-right",children:t[1]})]})}const st=["image/png","image/jpeg","image/gif","image/webp"];function Ee(t){return st.includes(t)}function _e(t){return new Promise((s,n)=>{if(!Ee(t.type)){n(new Error(`unsupported image type "${t.type||"unknown"}" (png, jpeg, gif, webp only)`));return}const a=new FileReader;a.onerror=()=>n(a.error??new Error("failed to read file")),a.onload=()=>{const r=String(a.result??""),l=r.indexOf(",");if(l<0){n(new Error("could not decode image data"));return}s({mediaType:t.type,data:r.slice(l+1)})},a.readAsDataURL(t)})}function at(t){if(!t)return null;for(let s=0;s<t.length;s++){const n=t[s];if(n.kind==="file"&&Ee(n.type)){const a=n.getAsFile();if(a)return a}}return null}const te={"doc.rfc.draft":"#c99a3a","doc.rfc.review":"#6a7bd6","doc.rfc.confirmed":"#3a9ad6","doc.rfc.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"},rt=.16;function se(t){return t&&Object.keys(t).length>0?t:te}function me(t,s,n){const a=t??"",r=s??"";if(a&&r&&n[`doc.${a}.${r}`])return n[`doc.${a}.${r}`];if(a&&n[`doc.${a}`])return n[`doc.${a}`]}function Me(t,s){const n=t??"";return n?s[`chunk.${n}`]:void 0}function $e(t){const s=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(!s)return;let n=s[1];n.length===3&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]);const a=parseInt(n.slice(0,2),16),r=parseInt(n.slice(2,4),16),l=parseInt(n.slice(4,6),16);return`rgba(${a}, ${r}, ${l}, ${rt})`}function ae(t){if(!t)return;const s=$e(t);if(s)return{background:s,borderLeft:`3px solid ${t}`}}function ct(t){const s=new Map;t.forEach(r=>s.set(r.id,{row:r,children:[]}));const n=[];t.forEach(r=>{const l=s.get(r.id);r.parent_id&&s.has(r.parent_id)?s.get(r.parent_id).children.push(l):n.push(l)});const a=r=>{r.sort((l,o)=>l.row.position-o.row.position),r.forEach(l=>a(l.children))};return a(n),n}function pe(t){return t==="image"?"🖼":t==="mermaid"?"📊":""}function Re(t,s){for(const n of t){if(n.row.id===s)return n;const a=Re(n.children,s);if(a)return a}}function ot({tree:t,selectedId:s,onSelect:n,colorEnabled:a,scheme:r,linkedIds:l}){const[o,i]=c.useState(()=>new Map),d=c.useCallback(f=>{i(g=>{const x=new Map(g);return x.set(f,g.get(f)===!1),x})},[]);c.useEffect(()=>{if(!s)return;const f=lt(t,s);f.length!==0&&i(g=>{let x=!1;const P=new Map(g);for(const b of f)P.get(b)===!1&&(P.set(b,!0),x=!0);return x?P:g})},[t,s]);const h=a?se(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(f=>e.jsx(Le,{node:f,expanded:o,toggle:d,selectedId:s,onSelect:n,tintScheme:h,linkedIds:l},f.row.id))})}function lt(t,s){const n=[],a=(r,l)=>{for(const o of r){if(o.row.id===s)return n.push(...l),!0;if(a(o.children,[...l,o.row.id]))return!0}return!1};return a(t,[]),n}function Le({node:t,expanded:s,toggle:n,selectedId:a,onSelect:r,tintScheme:l,linkedIds:o}){const i=t.children.length>0,d=s.get(t.row.id)!==!1,h=a===t.row.id,f=l?ae(Me(t.row.status,l)):void 0,g=o?.has(t.row.id);return e.jsxs("li",{className:`node chunk-node ${h?"selected":""}`,children:[e.jsxs("div",{className:"row chunk-row",style:f,children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":d?"collapse":"expand",disabled:!i,onClick:x=>{x.stopPropagation(),i&&n(t.row.id)},children:i?d?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"chunk-link",onClick:()=>r(t),title:t.row.title,children:[pe(t.row.type)&&e.jsx("span",{className:"chunk-type-icon","aria-hidden":!0,children:pe(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}),g&&e.jsx("span",{className:"chunk-link-badge",title:"Has cross-reference links","aria-label":"linked",children:"🔗"})]})]}),i&&d&&e.jsx("ul",{className:"children chunk-children",children:t.children.map(x=>e.jsx(Le,{node:x,expanded:s,toggle:n,selectedId:a,onSelect:r,tintScheme:l,linkedIds:o},x.row.id))})]})}let it=0;function re({code:t}){const s=c.useRef(null),[n,a]=c.useState({});return c.useEffect(()=>{let r=!1;return(async()=>{try{const l=(await import("mermaid")).default,o=s.current?.closest("[data-theme]")?.getAttribute("data-theme"),i=o?o==="dark":!0;l.initialize({startOnLoad:!1,theme:i?"dark":"default",securityLevel:"strict"});const{svg:d}=await l.render(`lc-mmd-${it++}`,t);r||a({svg:d})}catch{r||a({err:!0})}})(),()=>{r=!0}},[t]),n.err?e.jsx("pre",{className:"md-pre md-mermaid-error",title:"diagram failed to render",children:e.jsx("code",{children:t})}):n.svg?e.jsx("div",{ref:s,className:"md-mermaid",dangerouslySetInnerHTML:{__html:n.svg}}):e.jsx("div",{ref:s,className:"md-mermaid md-mermaid-loading",children:"rendering diagram…"})}function dt({chunk:t,scope:s,browse:n,onClose:a,onSaved:r}){const l=ne(),[o,i]=c.useState(t.title),[d,h]=c.useState(t.type??""),[f,g]=c.useState(t.status??""),[x,P]=c.useState(t.body??""),[b,$]=c.useState(t.fields?JSON.stringify(t.fields,null,2):""),[A,R]=c.useState(!1),[F,_]=c.useState(null),[G,I]=c.useState(!1),U=d==="mermaid",N=d==="image"||!!t.asset,[k,M]=c.useState(x);c.useEffect(()=>{if(!U)return;const u=setTimeout(()=>M(x),400);return()=>clearTimeout(u)},[x,U]);const O=async u=>{_(null),R(!0);try{const{mediaType:m,data:v}=await _e(u),w=await l.documentSetAsset(t.id,m,v,u.name,s,n);r(w),a()}catch(m){_(m instanceof Error?m.message:String(m)),R(!1)}},q=U?"Mermaid source":N?"Caption (optional)":"Body (Markdown)",z=async u=>{u.preventDefault(),_(null),I(!1);const m={body:x,title:o,type:d,status:f};if(b.trim()!=="")try{m.fields=JSON.parse(b)}catch{_("fields must be valid JSON");return}R(!0);try{const v=await l.documentUpdateChunk(t.id,t.revision,m,s,n);r(v),a()}catch(v){const w=v instanceof Error?v.message:String(v);_(w),I(/revision conflict/i.test(w)),R(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:a,children:e.jsxs("form",{className:"modal chunk-editor",onClick:u=>u.stopPropagation(),onSubmit:z,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:A,children:"cancel"}),e.jsx("button",{type:"submit",className:"primary",disabled:A,children:A?"saving…":"save"})]})]}),F&&e.jsxs("div",{className:"modal-err",children:[F,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:o,onChange:u=>i(u.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:d,placeholder:"(none)",onChange:u=>h(u.target.value)})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:"Status"}),e.jsx("input",{className:"path-modal-input",value:f,placeholder:"(none)",onChange:u=>g(u.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:A,onChange:u=>{const m=u.target.files?.[0];m&&O(m)}})]}),e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:q}),e.jsx("textarea",{className:"modal-textarea chunk-body-input",rows:U?8:12,value:x,onChange:u=>P(u.target.value)})]}),U&&e.jsxs("div",{className:"path-field",children:[e.jsx("span",{children:"Preview"}),e.jsx("div",{className:"chunk-mermaid-preview",children:k.trim()?e.jsx(re,{code:k}):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:b,placeholder:"{}",onChange:u=>$(u.target.value)})]})]})})}function ut(t){const s=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((t??"").trim());if(!s)return"#888888";let n=s[1];return n.length===3&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]),"#"+n.toLowerCase()}function mt({documentId:t,rootChunkId:s,docType:n,docStatus:a,chunkStatuses:r,scope:l,browse:o,onClose:i,onSaved:d}){const h=ne(),[f,g]=c.useState(null),[x,P]=c.useState(!1),[b,$]=c.useState({}),[A,R]=c.useState(!1),[F,_]=c.useState(null),[G,I]=c.useState(null),U=c.useMemo(()=>{const u=new Set(Object.keys(te));n&&u.add(`doc.${n}.${a||"draft"}`);for(const m of r)m&&u.add(`chunk.${m}`);return[...u].sort()},[n,a,r]);c.useEffect(()=>{let u=!1;return h.documentGetChunk(s,l,o).then(m=>{if(u)return;g(m);const v=m.fields??{};P(v.color_enabled===!0);const w=v.color_scheme??{};$({...te,...w})}).catch(m=>!u&&I(m instanceof Error?m.message:String(m))),()=>{u=!0}},[h,s,l,o]);const N=(u,m)=>$(v=>({...v,[u]:m})),k=u=>({...u??{},color_enabled:x,color_scheme:b}),M=async()=>{if(f){R(!0),I(null),_(null);try{await h.documentUpdateChunk(s,f.revision,{fields:k(f.fields)},l,o),d(),i()}catch(u){I(u instanceof Error?u.message:String(u)),R(!1)}}},O=async()=>{if(!n){I("this document has no type to match");return}R(!0),I(null),_(null);try{const{documents:u}=await h.documentsSummary({underPath:"/"},l,o),m=(u??[]).filter(w=>w.type===n&&w.document_id!==t&&w.root_chunk_id);let v=0;for(const w of m)try{const L=await h.documentGetChunk(w.root_chunk_id,l,o);await h.documentUpdateChunk(w.root_chunk_id,L.revision,{fields:k(L.fields)},l,o),v++}catch{}_(`Applied to ${v} other ${n} document(s).`),d()}catch(u){I(u instanceof Error?u.message:String(u))}finally{R(!1)}},q=U.filter(u=>u.startsWith("doc.")),z=U.filter(u=>u.startsWith("chunk."));return e.jsx("div",{className:"modal-overlay",onClick:i,children:e.jsxs("div",{className:"modal scheme-editor",onClick:u=>u.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:i,disabled:A,children:"cancel"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{M()},disabled:A||!f,children:A?"saving…":"save"})]})]}),G&&e.jsx("div",{className:"modal-err",children:G}),f?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"scheme-toggle",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:u=>P(u.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)"}),q.map(u=>e.jsx(xe,{label:u.slice(4),value:b[u],onChange:m=>N(u,m)},u))]}),e.jsxs("div",{className:"scheme-group",children:[e.jsx("h4",{children:"Chunks (status)"}),z.map(u=>e.jsx(xe,{label:u.slice(6),value:b[u],onChange:m=>N(u,m)},u))]}),e.jsxs("div",{className:"scheme-editor-foot",children:[e.jsxs("button",{type:"button",onClick:()=>{O()},disabled:A||!n,title:n?`Apply this palette to every other ${n} document`:"This document has no type",children:["copy to all ",n||"same-type"," documents"]}),F&&e.jsx("span",{className:"scheme-status",children:F})]})]}):e.jsx("p",{className:"modal-context",children:"Loading…"})]})})}function xe({label:t,value:s,onChange:n}){const a=ut(s);return e.jsxs("label",{className:"scheme-row",children:[e.jsx("input",{type:"color",value:a,onChange:r=>n(r.target.value)}),e.jsx("span",{className:"scheme-key",children:t}),e.jsx("code",{className:"scheme-hex",children:a})]})}const ie=24;function ht({edges:t,documentId:s,selectedId:n,onSelectChunk:a}){const[r,l]=c.useState(!1),[o,i]=c.useState(!1);if(t.length===0)return null;const d=n?t.filter(g=>g.from_id===n||g.to_id===n):[],h=o?t:t.slice(0,ie),f=pt(h);return e.jsxs("div",{className:"doc-refs",children:[n&&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((g,x)=>e.jsx(ft,{edge:g,selectedId:n,documentId:s,onSelectChunk:a},`${g.from_id}-${g.to_id}-${g.kind}-${x}`))})]}),e.jsxs("div",{className:"doc-graph",children:[e.jsxs("button",{type:"button",className:"doc-graph-toggle",onClick:()=>l(g=>!g),children:[r?"▼":"▶"," relationship graph (",t.length,")"]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(re,{code:f}),t.length>ie&&e.jsx("button",{type:"button",className:"doc-graph-more",onClick:()=>i(g=>!g),children:o?`show top ${ie}`:`show all ${t.length}`})]})]})]})}function ft({edge:t,selectedId:s,documentId:n,onSelectChunk:a}){const r=t.from_id===s,l=r?t.to_id:t.from_id,o=(r?t.to_title:t.from_title)||l.slice(0,8),i=r?t.to_document_id:t.from_document_id,d=!i||i===n;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:r?"→":"←"}),d?e.jsx("button",{type:"button",className:"doc-ref-target",onClick:()=>a(l),children:o}):e.jsxs("span",{className:"doc-ref-target external",title:"In another document",children:[o," ↗"]})]})}function pt(t){const s=["graph LR"];for(const n of t){const a=`${ge(n.from_id)}["${je(n.from_title,n.from_id)}"]`,r=`${ge(n.to_id)}["${je(n.to_title,n.to_id)}"]`,l=(n.kind||"link").replace(/[|"]/g," ");s.push(` ${a} -->|${l}| ${r}`)}return s.join(`
|
|
2
|
+
`)}function ge(t){return"n"+t.replace(/[^a-zA-Z0-9]/g,"")}function je(t,s){const a=(t??"").replace(/["[\]{}|<>]/g," ").replace(/\s+/g," ").trim()||s.slice(0,6);return a.length>30?a.slice(0,29)+"…":a}function ye({source:t}){return e.jsx("div",{className:"md",children:e.jsx(Ke,{remarkPlugins:[et],components:xt,children:t})})}const xt={a({href:t,children:s}){const n=t??"",a=/^https?:\/\//i.test(n);return e.jsx("a",{href:n,target:a?"_blank":void 0,rel:a?"noopener noreferrer":void 0,children:s})},pre({children:t}){return e.jsx(e.Fragment,{children:t})},code({className:t,children:s}){const n=/language-(\w+)/.exec(t??"")?.[1],a=String(s??"");return n==="mermaid"?e.jsx(re,{code:a.replace(/\n$/,"")}):n||a.includes(`
|
|
3
|
+
`)?e.jsx("pre",{className:"md-pre",children:e.jsx("code",{className:t,children:s})}):e.jsx("code",{children:s})}};function gt(t){const s=t.fields??{};return typeof s.alt=="string"&&s.alt.trim()!==""?s.alt:t.title||"image"}function De({documentId:t,scope:s,titleHint:n,browse:a,principal:r,renderAssistant:l}){const o=ne(),i=c.useMemo(()=>a&&(a.scopeId||a.tenant)?{scopeId:a.scopeId,tenant:a.tenant}:void 0,[a?.scopeId,a?.tenant]),[d,h]=c.useState([]),[f,g]=c.useState(void 0),[x,P]=c.useState(null),[b,$]=c.useState("chunks"),[A,R]=c.useState(null),[F,_]=c.useState(null),[G,I]=c.useState(null),U=c.useRef(null),[N,k]=c.useState(null),[M,O]=c.useState(null),[q,z]=c.useState(!1),[u,m]=c.useState(0),[v,w]=c.useState(!1),[L,J]=c.useState(null),[Z,Q]=c.useState(!1),[V,X]=c.useState([]),y=c.useCallback(()=>m(p=>p+1),[]),E=c.useMemo(()=>ct(d),[d]),D=c.useMemo(()=>d.find(j=>!j.parent_id)?.title||n||"document",[d,n]),H=c.useMemo(()=>!!x&&!x.parent_id,[x]),B=c.useMemo(()=>L?.root_chunk_id??d.find(p=>!p.parent_id)?.id,[L,d]),Ae=c.useMemo(()=>[...new Set(d.map(p=>p.status).filter(p=>!!p))],[d]),Y=!!L?.color_enabled,Ie=c.useMemo(()=>{const p=new Set;for(const j of V)p.add(j.from_id),p.add(j.to_id);return p},[V]),Oe=c.useMemo(()=>Y?ae(me(L?.type,L?.status,se(L?.color_scheme))):void 0,[Y,L?.type,L?.status,L?.color_scheme]);c.useEffect(()=>{let p=!1;return z(!0),O(null),o.documentQueryChunks(t,s,i).then(j=>{if(p)return;const C=j.chunks??[];h(C),g(S=>S??C.find(T=>!T.parent_id)?.id)}).catch(j=>!p&&O(j instanceof Error?j.message:String(j))).finally(()=>!p&&z(!1)),()=>{p=!0}},[o,t,s,u,i]),c.useEffect(()=>{let p=!1;return o.documentGet(t,s,i).then(j=>!p&&J(j)).catch(()=>!p&&J(null)),()=>{p=!0}},[o,t,s,u,i]),c.useEffect(()=>{let p=!1;return o.documentGetEdges(t,s,i).then(j=>!p&&X(j.edges??[])).catch(()=>!p&&X([])),()=>{p=!0}},[o,t,s,u,i]),c.useEffect(()=>{g(void 0),P(null),R(null),$("chunks"),J(null),X([])},[t,s]),c.useEffect(()=>{if(!f){P(null);return}let p=!1;return o.documentGetChunk(f,s,i).then(j=>!p&&P(j)).catch(j=>!p&&O(j instanceof Error?j.message:String(j))),()=>{p=!0}},[o,f,s,u,i]),c.useEffect(()=>{const p=x?.type==="image"||!!x?.asset;if(!x||!p||!o.documentAssetObjectUrl){_(null),I(null);return}let j=!1,C=null;return I(null),o.documentAssetObjectUrl(x.id,s,i).then(S=>{if(j){URL.revokeObjectURL(S);return}C=S,_(S)}).catch(S=>!j&&I(S instanceof Error?S.message:String(S))),()=>{j=!0,C&&URL.revokeObjectURL(C)}},[o,x,s,i]),c.useEffect(()=>{if(b!=="markdown"||!f){R(null);return}const p=Re(E,f);if(!p)return;let j=!1;const C=[],S=(T,K)=>{C.push({node:T,depth:K}),T.children.forEach(ee=>S(ee,K+1))};return S(p,0),Promise.all(C.map(T=>o.documentGetChunk(T.node.row.id,s,i))).then(T=>{if(j)return;const K=C.map((ee,Be)=>{const He=Math.min(ee.depth+1,6),W=T[Be],le="#".repeat(He)+" "+ee.node.row.title;if(W.type==="mermaid"&&W.body)return le+"\n\n```mermaid\n"+W.body+"\n```\n";if(W.type==="image"||W.asset){const qe=W.body?" — "+W.body:"";return le+`
|
|
5
4
|
|
|
6
|
-
`+
|
|
5
|
+
_🖼 image chunk_`+qe+`
|
|
6
|
+
`}return le+(W.body?`
|
|
7
|
+
|
|
8
|
+
`+W.body:"")+`
|
|
7
9
|
`}).join(`
|
|
8
|
-
`);M(E)}).catch(k=>!y&&D(k instanceof Error?k.message:String(k))),()=>{y=!0}},[l,b,h,$,t,g,d]);const B=i.useCallback(x=>N(x.row.id),[]),q=i.useCallback(async()=>{try{const x=await l.documentExportMd(s,t,!0,d),y=new Blob([x.markdown],{type:"text/markdown"}),_=URL.createObjectURL(y),p=document.createElement("a");p.href=_,p.download=(x.title||"document").replace(/[^\w.-]+/g,"_")+".md",p.click(),URL.revokeObjectURL(_)}catch(x){D(x instanceof Error?x.message:String(x))}},[l,s,t,d]);return e.jsxs("div",{className:"doc-viewer",children:[e.jsxs("div",{className:"doc-toolbar",children:[e.jsx("strong",{className:"doc-title",title:T,children:T}),e.jsxs("div",{className:"doc-toolbar-actions",children:[e.jsx("button",{type:"button",onClick:()=>{q()},title:"Download the whole document as Markdown (.md)",children:"↓ .md"}),o&&e.jsx("button",{type:"button",className:O?"active":"",onClick:()=>F(x=>!x),title:"Document Assistant — instruct an agent to restructure/import/link chunks",children:"assistant"}),e.jsx("button",{type:"button",onClick:m,title:"Reload",children:"↻"})]})]}),P&&e.jsx("div",{className:"paths-err",children:P}),e.jsxs("div",{className:"doc-split",children:[e.jsx("div",{className:"doc-chunktree",children:W&&c.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):e.jsx(me,{tree:$,selectedId:h,onSelect:B})}),e.jsx("div",{className:"doc-content",children:j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"doc-content-head",children:[e.jsx("h3",{children:j.title||"(untitled)"}),e.jsxs("div",{className:"doc-content-meta",children:[j.type&&e.jsx("span",{className:"chunk-badge",children:j.type}),j.status&&e.jsx("span",{className:"chunk-badge chunk-status",children:j.status}),e.jsxs("span",{className:"chunk-rev",children:["rev ",j.revision]})]}),e.jsxs("div",{className:"doc-content-controls",children:[e.jsxs("div",{className:"doc-mode-toggle",children:[e.jsx("button",{type:"button",className:b==="chunks"?"active":"",onClick:()=>w("chunks"),title:"This chunk's own content",children:"chunk"}),e.jsx("button",{type:"button",className:b==="markdown"?"active":"",onClick:()=>w("markdown"),title:A?"Whole document as Markdown":"This chunk + its sub-chunks as Markdown",children:"markdown"})]}),e.jsx("button",{type:"button",onClick:()=>C(j),children:"edit"})]})]}),e.jsx("div",{className:"doc-content-body",children:b==="markdown"?L!==null?e.jsx(Z,{source:L}):e.jsx("p",{className:"doc-empty-body",children:"Assembling Markdown…"}):j.body?e.jsx(Z,{source:j.body}):e.jsx("p",{className:"doc-empty-body",children:"(empty chunk)"})})]}):e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Select a chunk on the left."})})})]}),O&&o&&e.jsx("div",{className:"doc-assistant",children:o({documentId:s,scope:t,subject:r?.subject,onChanged:m})}),R&&e.jsx(fe,{chunk:R,scope:t,browse:d,onClose:()=>C(null),onSaved:m})]})}function ke(s){const t={name:"",fullPath:"",kind:"directory",explicit:!0,children:[]},a=new Map([["",t]]),n=o=>{const l=a.get(o);if(l)return l;const d=o.lastIndexOf("/"),c=d<=0?"":o.slice(0,d),u=o.slice(d+1),h=n(c),N={name:u,fullPath:o,kind:"directory",explicit:!1,children:[]};return h.children.push(N),a.set(o,N),N};for(const o of s){const l=n(o.full_path);l.kind=o.kind,l.explicit=!0,l.resourceRef=o.resource_ref}const r=o=>{o.sort((l,d)=>{const c=l.kind==="directory",u=d.kind==="directory";return c!==u?c?-1:1:l.name.localeCompare(d.name)}),o.forEach(l=>r(l.children))};return r(t.children),t.children}function J(s){const t=s.lastIndexOf("/");return t<=0?"":s.slice(0,t)}function ge(s){const t=[],a=n=>{if(n.kind==="document"){const r=n.resourceRef;r?.document_id&&t.push(r.document_id)}n.children.forEach(a)};return a(s),t}const ye={directory:"📁",document:"📄",volume_mount:"💾",memory_entry:"🧠"};function ve({tree:s,selectedPath:t,onSelect:a}){const[n,r]=i.useState(()=>new Map),o=i.useCallback(l=>{r(d=>{const c=new Map(d);return c.set(l,d.get(l)===!1),c})},[]);return i.useEffect(()=>{t&&r(l=>{let d=!1;const c=new Map(l);let u=J(t);for(;u!=="";)c.get(u)===!1&&(c.set(u,!0),d=!0),u=J(u);return d?c:l})},[t]),s.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"This tree is empty. Create a folder or document to begin."})}):e.jsx("ul",{className:"tree path-tree",children:s.map(l=>e.jsx(le,{node:l,expanded:n,toggle:o,selectedPath:t,onSelect:a},l.fullPath))})}function le({node:s,expanded:t,toggle:a,selectedPath:n,onSelect:r}){const o=s.children.length>0,l=t.get(s.fullPath)!==!1,d=n===s.fullPath;return e.jsxs("li",{className:`node path-node kind-${s.kind} ${d?"selected":""}`,children:[e.jsxs("div",{className:"row path-row",children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":l?"collapse":"expand",disabled:!o,onClick:c=>{c.stopPropagation(),o&&a(s.fullPath)},children:o?l?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"path-link",onClick:()=>r(s),title:s.fullPath,children:[e.jsx("span",{className:"path-kind-icon","aria-hidden":!0,children:ye[s.kind]??"•"}),e.jsx("span",{className:"path-name",children:s.name}),!s.explicit&&e.jsx("span",{className:"path-implicit",title:"Implicit directory (no stored entry)",children:"implicit"})]})]}),o&&l&&e.jsx("ul",{className:"children path-children",children:s.children.map(c=>e.jsx(le,{node:c,expanded:t,toggle:a,selectedPath:n,onSelect:r},c.fullPath))})]})}const Q=/^[A-Za-z0-9._-]+$/;function X(s,t){return`${s}/${t}`}function re(s,t){for(const a of s){if(a.fullPath===t)return a;const n=re(a.children,t);if(n)return n}}function Ne(s){const{theme:t,defaultScope:a,path:n,onPathChange:r,browse:o,principal:l,renderAssistant:d,onError:c}=s,u=ee(s);return e.jsx(te,{theme:t,dataLayer:u,children:e.jsx(we,{defaultScope:a,path:n,onPathChange:r,browse:o,principal:l,renderAssistant:d,onError:c})})}function we({defaultScope:s,path:t,onPathChange:a,browse:n,principal:r,renderAssistant:o,onError:l}){const d=z(),[c,u]=i.useState(s??"user"),[h,N]=i.useState([]),[j,S]=i.useState(void 0),[b,w]=i.useState(null),[L,M]=i.useState(!1),[R,C]=i.useState(null),P=t!==void 0?t:j,D=i.useRef(a);i.useEffect(()=>{D.current=a},[a]);const W=i.useRef(l);i.useEffect(()=>{W.current=l},[l]);const f=i.useCallback(p=>{D.current?.(p),S(p)},[]),g=i.useMemo(()=>n&&(n.scopeId||n.tenant)?{scopeId:n.scopeId,tenant:n.tenant}:void 0,[n?.scopeId,n?.tenant]),v=i.useCallback(async()=>{M(!0),w(null);try{const p=await d.pathLs("/",c,!0,g);N(p.entries??[])}catch(p){w(p instanceof Error?p.message:String(p)),N([]),W.current?.(p)}finally{M(!1)}},[d,c,g]),O=i.useRef(!0);i.useEffect(()=>{O.current?O.current=!1:f(void 0),v()},[v,f]);const F=i.useMemo(()=>ke(h),[h]),m=i.useMemo(()=>P?re(F,P):void 0,[F,P]),$=i.useMemo(()=>m?m.kind==="directory"?m.fullPath:J(m.fullPath):"",[m]),T=$||"/",A=c!=="tenant",B=i.useCallback(()=>{C({title:`New folder in ${T}`,fields:[{key:"name",label:"Folder name",placeholder:"e.g. launches"}],submitLabel:"Create",onSubmit:async p=>{const k=p.name.trim();if(!Q.test(k))throw new Error("name may contain only [A-Za-z0-9._-]");const E=X($,k);await d.pathMkdir(E,c,g),await v(),f(E)}})},[d,$,T,c,g,v,f]),q=i.useCallback(()=>{C({title:`New document in ${T}`,fields:[{key:"name",label:"Path name",placeholder:"e.g. launch-plan"},{key:"title",label:"Title",placeholder:"e.g. Launch Plan"}],submitLabel:"Create",onSubmit:async p=>{const k=p.name.trim();if(!Q.test(k))throw new Error("name may contain only [A-Za-z0-9._-]");const E=p.title.trim()||k,I=X($,k);await d.documentCreate(E,I,c,g),await v(),f(I)}})},[d,$,T,c,g,v,f]),x=i.useCallback(()=>{m&&C({title:`Rename / move ${m.fullPath}`,fields:[{key:"to",label:"New path",value:m.fullPath}],submitLabel:"Move",onSubmit:async p=>{const k=p.to.trim();if(!k.startsWith("/"))throw new Error("path must start with /");await d.pathMv(m.fullPath,k,c,g),await v(),f(k)}})},[d,m,c,g,v,f]),y=i.useCallback(()=>{if(!m)return;if(m.kind==="document"){const I=m.resourceRef?.document_id;C({title:`Delete document ${m.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(!I)throw new Error("this document dirent has no document_id");await d.documentDelete(I,c,g),await v(),f(void 0)}});return}const p=c==="tenant"?[]:ge(m),k=m.children.length;C({title:`Delete branch ${m.fullPath}`,message:k===0?"This removes the (empty) folder.":"This removes the folder and everything under it"+(p.length>0?` — including ${p.length} document(s), whose chunks are deleted.`:"."),fields:[],submitLabel:"Delete",danger:!0,onSubmit:async()=>{for(const E of p)await d.documentDelete(E,c,g);await d.pathRm(m.fullPath,c,!0,g),await v(),f(void 0)}})},[d,m,c,g,v,f]),_=m&&(m.kind==="directory"||m.kind==="document");return e.jsxs(e.Fragment,{children:[e.jsxs(ue,{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:c,onChange:p=>u(p.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:B,title:`New folder in ${T}`,children:"+ folder"}),e.jsx("button",{type:"button",onClick:q,disabled:!A,title:A?`New document in ${T}`:"Documents are agent/user scope only",children:"+ document"}),e.jsx("button",{type:"button",onClick:()=>{v()},title:"Reload the tree",children:"↻"})]})]}),e.jsxs("p",{className:"paths-context",children:["new items → ",e.jsx("code",{children:T}),g?.scopeId&&e.jsxs(e.Fragment,{children:[" · ","subject ",e.jsx("code",{children:g.scopeId})]}),g?.tenant&&e.jsxs(e.Fragment,{children:[" · ","tenant ",e.jsx("code",{children:g.tenant})]})]}),b&&e.jsx("div",{className:"paths-err",children:b}),L&&h.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):e.jsx(ve,{tree:F,selectedPath:P,onSelect:p=>f(p.fullPath)})]}),e.jsx("div",{className:"right",children:m?m.kind==="document"?e.jsxs("div",{className:"paths-doc",children:[e.jsxs("div",{className:"paths-doc-head",children:[e.jsx("code",{className:"paths-doc-path",children:m.fullPath}),e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:x,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:y,children:"delete"})]})]}),e.jsx(ae,{documentId:m.resourceRef?.document_id??"",scope:c==="agent"?"agent":"user",titleHint:m.name,browse:g,principal:r,renderAssistant:o})]}):e.jsxs("div",{className:"paths-detail",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"paths-detail-kind",children:m.kind}),e.jsx("code",{children:m.fullPath})]}),e.jsxs("dl",{className:"paths-detail-meta",children:[e.jsx("dt",{children:"scope"}),e.jsx("dd",{children:c}),e.jsx("dt",{children:"stored"}),e.jsx("dd",{children:m.explicit?"yes":"implicit (no entry)"})]}),_?e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:x,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:y,children:"delete"})]}):e.jsxs("p",{className:"paths-readonly",children:["Read-only — ",m.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."})})})]}),R&&e.jsx(Ce,{state:R,onClose:()=>C(null)})]})}function Ce({state:s,onClose:t}){const[a,n]=i.useState(()=>Object.fromEntries(s.fields.map(u=>[u.key,u.value??""]))),[r,o]=i.useState(!1),[l,d]=i.useState(null),c=async u=>{u.preventDefault(),o(!0),d(null);try{await s.onSubmit(a),t()}catch(h){d(h instanceof Error?h.message:String(h)),o(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:t,children:e.jsxs("form",{className:"modal",onClick:u=>u.stopPropagation(),onSubmit:c,children:[e.jsx("h3",{children:s.title}),s.message&&e.jsx("p",{className:"modal-context",children:s.message}),s.fields.map((u,h)=>e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:u.label}),e.jsx("input",{className:"path-modal-input",value:a[u.key],placeholder:u.placeholder,autoFocus:h===0,onChange:N=>n(j=>({...j,[u.key]:N.target.value}))})]},u.key)),l&&e.jsx("div",{className:"modal-err",children:l}),e.jsxs("div",{className:"modal-buttons",children:[e.jsx("button",{type:"button",onClick:t,disabled:r,children:"cancel"}),e.jsx("button",{type:"submit",className:s.danger?"danger":"primary",disabled:r,children:r?"working…":s.submitLabel})]})]})})}function Se(s){const{documentId:t,scope:a,titleHint:n,browse:r,theme:o,principal:l,renderAssistant:d}=s,c=ee(s);return e.jsx(te,{theme:o,dataLayer:c,children:e.jsx(ae,{documentId:t,scope:a,titleHint:n,browse:r,principal:l,renderAssistant:d})})}exports.DocumentViewer=Se;exports.PathExplorer=Ne;exports.createLoomcycleClient=K;exports.dataLayerFromClient=V;
|
|
10
|
+
`);R(K)}).catch(T=>!j&&O(T instanceof Error?T.message:String(T))),()=>{j=!0}},[o,b,f,E,s,u,i]);const Ue=c.useCallback(p=>g(p.row.id),[]),Fe=c.useCallback(async()=>{try{const p=await o.documentExportMd(t,s,!0,i),j=new Blob([p.markdown],{type:"text/markdown"}),C=URL.createObjectURL(j),S=document.createElement("a");S.href=C,S.download=(p.title||"document").replace(/[^\w.-]+/g,"_")+".md",S.click(),URL.revokeObjectURL(C)}catch(p){O(p instanceof Error?p.message:String(p))}},[o,t,s,i]),ce=!!o.documentCreateChunk&&!!B,oe=c.useCallback(async p=>{if(!o.documentCreateChunk||!o.documentSetAsset)return;const j=f||B;if(j){O(null);try{const{mediaType:C,data:S}=await _e(p),T=await o.documentCreateChunk(t,j,{title:p.name||"image",type:"image"},s,i);await o.documentSetAsset(T.id,C,S,p.name,s,i),y(),g(T.id)}catch(C){O(C instanceof Error?C.message:String(C))}}},[o,t,s,i,f,B,y]),Ge=c.useCallback(async()=>{if(!o.documentCreateChunk)return;const p=f||B;if(p){O(null);try{const j=await o.documentCreateChunk(t,p,{title:"Diagram",type:"mermaid",body:`graph TD
|
|
11
|
+
A[Start] --> B[End]`},s,i);y(),g(j.id),k(j)}catch(j){O(j instanceof Error?j.message:String(j))}}},[o,t,s,i,f,B,y]);return c.useEffect(()=>{if(!ce)return;const p=j=>{if(N||Z)return;const C=document.activeElement,S=C?.tagName;if(S==="INPUT"||S==="TEXTAREA"||C?.isContentEditable)return;const T=at(j.clipboardData?.items);T&&(j.preventDefault(),oe(T))};return window.addEventListener("paste",p),()=>window.removeEventListener("paste",p)},[ce,N,Z,oe]),e.jsxs("div",{className:"doc-viewer",children:[e.jsx("input",{ref:U,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",style:{display:"none"},onChange:p=>{const j=p.target.files?.[0];p.target.value="",j&&oe(j)}}),e.jsxs("div",{className:"doc-toolbar",style:Oe,children:[e.jsx("strong",{className:"doc-title",title:D,children:D}),e.jsxs("div",{className:"doc-toolbar-actions",children:[ce&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>U.current?.click(),title:"Add an image chunk (upload — or paste a screenshot into the view)",children:"+ image"}),e.jsx("button",{type:"button",onClick:()=>{Ge()},title:"Add a Mermaid diagram chunk",children:"+ diagram"})]}),e.jsx("button",{type:"button",className:Y?"active":"",onClick:()=>Q(!0),disabled:!B,title:"Colors — tint chunk tiles + the Path tree by type/status",children:"colors"}),e.jsx("button",{type:"button",onClick:()=>{Fe()},title:"Download the whole document as Markdown (.md)",children:"↓ .md"}),l&&e.jsx("button",{type:"button",className:v?"active":"",onClick:()=>w(p=>!p),title:"Document Assistant — instruct an agent to restructure/import/link chunks",children:"assistant"}),e.jsx("button",{type:"button",onClick:y,title:"Reload",children:"↻"})]})]}),M&&e.jsx("div",{className:"paths-err",children:M}),e.jsxs("div",{className:"doc-split",children:[e.jsx("div",{className:"doc-chunktree",children:q&&d.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):e.jsx(ot,{tree:E,selectedId:f,onSelect:Ue,colorEnabled:Y,scheme:L?.color_scheme,linkedIds:Ie})}),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]})]}),e.jsxs("div",{className:"doc-content-controls",children:[e.jsxs("div",{className:"doc-mode-toggle",children:[e.jsx("button",{type:"button",className:b==="chunks"?"active":"",onClick:()=>$("chunks"),title:"This chunk's own content",children:"chunk"}),e.jsx("button",{type:"button",className:b==="markdown"?"active":"",onClick:()=>$("markdown"),title:H?"Whole document as Markdown":"This chunk + its sub-chunks as Markdown",children:"markdown"})]}),e.jsx("button",{type:"button",onClick:()=>k(x),children:"edit"})]})]}),e.jsx("div",{className:"doc-content-body",children:x.type==="mermaid"?x.body?e.jsxs(e.Fragment,{children:[e.jsx(re,{code:x.body}),b==="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?G?e.jsxs("p",{className:"doc-empty-body",children:["Image failed to load: ",G]}):F?e.jsxs("figure",{className:"doc-image",children:[e.jsx("img",{src:F,alt:gt(x)}),x.body&&e.jsx("figcaption",{children:x.body})]}):e.jsx("p",{className:"doc-empty-body",children:"Loading image…"}):b==="markdown"?A!==null?e.jsx(ye,{source:A}):e.jsx("p",{className:"doc-empty-body",children:"Assembling Markdown…"}):x.body?e.jsx(ye,{source:x.body}):e.jsx("p",{className:"doc-empty-body",children:"(empty chunk)"})}),e.jsx(ht,{edges:V,documentId:t,selectedId:f,onSelectChunk:g})]}):e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Select a chunk on the left."})})})]}),v&&l&&e.jsx("div",{className:"doc-assistant",children:l({documentId:t,scope:s,subject:r?.subject,onChanged:y})}),N&&e.jsx(dt,{chunk:N,scope:s,browse:i,onClose:()=>k(null),onSaved:y}),Z&&B&&e.jsx(mt,{documentId:t,rootChunkId:B,docType:L?.type,docStatus:L?.status,chunkStatuses:Ae,scope:s,browse:i,onClose:()=>Q(!1),onSaved:y})]})}function jt(t){const s={name:"",fullPath:"",kind:"directory",explicit:!0,children:[]},n=new Map([["",s]]),a=l=>{const o=n.get(l);if(o)return o;const i=l.lastIndexOf("/"),d=i<=0?"":l.slice(0,i),h=l.slice(i+1),f=a(d),g={name:h,fullPath:l,kind:"directory",explicit:!1,children:[]};return f.children.push(g),n.set(l,g),g};for(const l of t){const o=a(l.full_path);o.kind=l.kind,o.explicit=!0,o.resourceRef=l.resource_ref}const r=l=>{l.sort((o,i)=>{const d=o.kind==="directory",h=i.kind==="directory";return d!==h?d?-1:1:o.name.localeCompare(i.name)}),l.forEach(o=>r(o.children))};return r(s.children),s.children}function ue(t){const s=t.lastIndexOf("/");return s<=0?"":t.slice(0,s)}function yt(t){const s=[],n=a=>{if(a.kind==="document"){const r=a.resourceRef;r?.document_id&&s.push(r.document_id)}a.children.forEach(n)};return n(t),s}const bt={directory:"📁",document:"📄",volume_mount:"💾",memory_entry:"🧠"};function kt({tree:t,selectedPath:s,onSelect:n,summaries:a}){const[r,l]=c.useState(()=>new Map),o=c.useCallback(i=>{l(d=>{const h=new Map(d);return h.set(i,d.get(i)===!1),h})},[]);return c.useEffect(()=>{s&&l(i=>{let d=!1;const h=new Map(i);let f=ue(s);for(;f!=="";)h.get(f)===!1&&(h.set(f,!0),d=!0),f=ue(f);return d?h:i})},[s]),t.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"This tree is empty. Create a folder or document to begin."})}):e.jsx("ul",{className:"tree path-tree",children:t.map(i=>e.jsx(Te,{node:i,expanded:r,toggle:o,selectedPath:s,onSelect:n,summaries:a},i.fullPath))})}function vt(t,s){if(t.kind!=="document"||!s)return;const n=t.resourceRef;return n?.document_id?s.get(n.document_id):void 0}function Te({node:t,expanded:s,toggle:n,selectedPath:a,onSelect:r,summaries:l}){const o=t.children.length>0,i=s.get(t.fullPath)!==!1,d=a===t.fullPath,h=vt(t,l),f=h&&h.color_enabled?ae(me(h.type,h.status,se(h.color_scheme))):void 0;return e.jsxs("li",{className:`node path-node kind-${t.kind} ${d?"selected":""}`,children:[e.jsxs("div",{className:"row path-row",style:f,children:[e.jsx("button",{type:"button",className:"tree-caret","aria-label":i?"collapse":"expand",disabled:!o,onClick:g=>{g.stopPropagation(),o&&n(t.fullPath)},children:o?i?"▼":"▶":"·"}),e.jsxs("button",{type:"button",className:"path-link",onClick:()=>r(t),title:t.fullPath,children:[e.jsx("span",{className:"path-kind-icon","aria-hidden":!0,children:bt[t.kind]??"•"}),e.jsx("span",{className:"path-name",children:t.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}),!t.explicit&&e.jsx("span",{className:"path-implicit",title:"Implicit directory (no stored entry)",children:"implicit"})]})]}),o&&i&&e.jsx("ul",{className:"children path-children",children:t.children.map(g=>e.jsx(Te,{node:g,expanded:s,toggle:n,selectedPath:a,onSelect:r,summaries:l},g.fullPath))})]})}const be=/^[A-Za-z0-9._-]+$/;function ke(t,s){return`${t}/${s}`}function Pe(t,s){for(const n of t){if(n.fullPath===s)return n;const a=Pe(n.children,s);if(a)return a}}function Nt(t){const{theme:s,defaultScope:n,path:a,onPathChange:r,browse:l,principal:o,renderAssistant:i,onError:d}=t,h=Ce(t);return e.jsx(Se,{theme:s,dataLayer:h,children:e.jsx(wt,{defaultScope:n,path:a,onPathChange:r,browse:l,principal:o,renderAssistant:i,onError:d})})}function wt({defaultScope:t,path:s,onPathChange:n,browse:a,principal:r,renderAssistant:l,onError:o}){const i=ne(),[d,h]=c.useState(t??"user"),[f,g]=c.useState([]),[x,P]=c.useState(void 0),[b,$]=c.useState(null),[A,R]=c.useState(!1),[F,_]=c.useState(null),G=s!==void 0?s:x,I=c.useRef(n);c.useEffect(()=>{I.current=n},[n]);const U=c.useRef(o);c.useEffect(()=>{U.current=o},[o]);const N=c.useCallback(y=>{I.current?.(y),P(y)},[]),k=c.useMemo(()=>a&&(a.scopeId||a.tenant)?{scopeId:a.scopeId,tenant:a.tenant}:void 0,[a?.scopeId,a?.tenant]),M=c.useCallback(async()=>{R(!0),$(null);try{const y=await i.pathLs("/",d,!0,k);g(y.entries??[])}catch(y){$(y instanceof Error?y.message:String(y)),g([]),U.current?.(y)}finally{R(!1)}},[i,d,k]),O=c.useRef(!0);c.useEffect(()=>{O.current?O.current=!1:N(void 0),M()},[M,N]);const q=c.useMemo(()=>jt(f),[f]),[z,u]=c.useState(()=>new Map);c.useEffect(()=>{if(d==="tenant"){u(new Map);return}const y=f.filter(D=>D.kind==="document").map(D=>D.resource_ref?.document_id).filter(D=>!!D);if(y.length===0){u(new Map);return}let E=!1;return i.documentsSummary({documentIds:y},d,k).then(D=>{if(E)return;const H=new Map;for(const B of D.documents??[])H.set(B.document_id,B);u(H)}).catch(()=>{E||u(new Map)}),()=>{E=!0}},[i,f,d,k]);const m=c.useMemo(()=>G?Pe(q,G):void 0,[q,G]),v=c.useMemo(()=>m?m.kind==="directory"?m.fullPath:ue(m.fullPath):"",[m]),w=v||"/",L=d!=="tenant",J=c.useCallback(()=>{_({title:`New folder in ${w}`,fields:[{key:"name",label:"Folder name",placeholder:"e.g. launches"}],submitLabel:"Create",onSubmit:async y=>{const E=y.name.trim();if(!be.test(E))throw new Error("name may contain only [A-Za-z0-9._-]");const D=ke(v,E);await i.pathMkdir(D,d,k),await M(),N(D)}})},[i,v,w,d,k,M,N]),Z=c.useCallback(()=>{_({title:`New document in ${w}`,fields:[{key:"name",label:"Path name",placeholder:"e.g. launch-plan"},{key:"title",label:"Title",placeholder:"e.g. Launch Plan"}],submitLabel:"Create",onSubmit:async y=>{const E=y.name.trim();if(!be.test(E))throw new Error("name may contain only [A-Za-z0-9._-]");const D=y.title.trim()||E,H=ke(v,E);await i.documentCreate(D,H,d,k),await M(),N(H)}})},[i,v,w,d,k,M,N]),Q=c.useCallback(()=>{m&&_({title:`Rename / move ${m.fullPath}`,fields:[{key:"to",label:"New path",value:m.fullPath}],submitLabel:"Move",onSubmit:async y=>{const E=y.to.trim();if(!E.startsWith("/"))throw new Error("path must start with /");await i.pathMv(m.fullPath,E,d,k),await M(),N(E)}})},[i,m,d,k,M,N]),V=c.useCallback(()=>{if(!m)return;if(m.kind==="document"){const H=m.resourceRef?.document_id;_({title:`Delete document ${m.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(!H)throw new Error("this document dirent has no document_id");await i.documentDelete(H,d,k),await M(),N(void 0)}});return}const y=d==="tenant"?[]:yt(m),E=m.children.length;_({title:`Delete branch ${m.fullPath}`,message:E===0?"This removes the (empty) folder.":"This removes the folder and everything under it"+(y.length>0?` — including ${y.length} document(s), whose chunks are deleted.`:"."),fields:[],submitLabel:"Delete",danger:!0,onSubmit:async()=>{for(const D of y)await i.documentDelete(D,d,k);await i.pathRm(m.fullPath,d,!0,k),await M(),N(void 0)}})},[i,m,d,k,M,N]),X=m&&(m.kind==="directory"||m.kind==="document");return e.jsxs(e.Fragment,{children:[e.jsxs(nt,{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:d,onChange:y=>h(y.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:J,title:`New folder in ${w}`,children:"+ folder"}),e.jsx("button",{type:"button",onClick:Z,disabled:!L,title:L?`New document in ${w}`:"Documents are agent/user scope only",children:"+ document"}),e.jsx("button",{type:"button",onClick:()=>{M()},title:"Reload the tree",children:"↻"})]})]}),e.jsxs("p",{className:"paths-context",children:["new items → ",e.jsx("code",{children:w}),k?.scopeId&&e.jsxs(e.Fragment,{children:[" · ","subject ",e.jsx("code",{children:k.scopeId})]}),k?.tenant&&e.jsxs(e.Fragment,{children:[" · ","tenant ",e.jsx("code",{children:k.tenant})]})]}),b&&e.jsx("div",{className:"paths-err",children:b}),A&&f.length===0?e.jsx("div",{className:"empty",children:e.jsx("p",{children:"Loading…"})}):e.jsx(kt,{tree:q,selectedPath:G,onSelect:y=>N(y.fullPath),summaries:z})]}),e.jsx("div",{className:"right",children:m?m.kind==="document"?e.jsxs("div",{className:"paths-doc",children:[e.jsxs("div",{className:"paths-doc-head",children:[e.jsx("code",{className:"paths-doc-path",children:m.fullPath}),e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:Q,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:V,children:"delete"})]})]}),e.jsx(De,{documentId:m.resourceRef?.document_id??"",scope:d==="agent"?"agent":"user",titleHint:m.name,browse:k,principal:r,renderAssistant:l})]}):e.jsxs("div",{className:"paths-detail",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"paths-detail-kind",children:m.kind}),e.jsx("code",{children:m.fullPath})]}),e.jsxs("dl",{className:"paths-detail-meta",children:[e.jsx("dt",{children:"scope"}),e.jsx("dd",{children:d}),e.jsx("dt",{children:"stored"}),e.jsx("dd",{children:m.explicit?"yes":"implicit (no entry)"})]}),X?e.jsxs("div",{className:"paths-detail-actions",children:[e.jsx("button",{type:"button",onClick:Q,children:"rename / move"}),e.jsx("button",{type:"button",className:"danger",onClick:V,children:"delete"})]}):e.jsxs("p",{className:"paths-readonly",children:["Read-only — ",m.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."})})})]}),F&&e.jsx(Ct,{state:F,onClose:()=>_(null)})]})}function Ct({state:t,onClose:s}){const[n,a]=c.useState(()=>Object.fromEntries(t.fields.map(h=>[h.key,h.value??""]))),[r,l]=c.useState(!1),[o,i]=c.useState(null),d=async h=>{h.preventDefault(),l(!0),i(null);try{await t.onSubmit(n),s()}catch(f){i(f instanceof Error?f.message:String(f)),l(!1)}};return e.jsx("div",{className:"modal-overlay",onClick:s,children:e.jsxs("form",{className:"modal",onClick:h=>h.stopPropagation(),onSubmit:d,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:s,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((h,f)=>e.jsxs("label",{className:"path-field",children:[e.jsx("span",{children:h.label}),e.jsx("input",{className:"path-modal-input",value:n[h.key],placeholder:h.placeholder,autoFocus:f===0,onChange:g=>a(x=>({...x,[h.key]:g.target.value}))})]},h.key)),o&&e.jsx("div",{className:"modal-err",children:o})]})})}function St(t){const{documentId:s,scope:n,titleHint:a,browse:r,theme:l,principal:o,renderAssistant:i}=t,d=Ce(t);return e.jsx(Se,{theme:l,dataLayer:d,children:e.jsx(De,{documentId:s,scope:n,titleHint:a,browse:r,principal:o,renderAssistant:i})})}exports.DEFAULT_SCHEME=te;exports.DocumentViewer=St;exports.PathExplorer=Nt;exports.assetFetchFromConnection=we;exports.chunkColor=Me;exports.createLoomcycleClient=Ne;exports.dataLayerFromClient=de;exports.docColor=me;exports.effectiveScheme=se;exports.hexToTint=$e;exports.tintStyle=ae;
|
|
9
12
|
//# sourceMappingURL=index.cjs.map
|