@augmentd-labs/canvas-web 2.26.22 → 2.26.24
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/assets/{FileForm-DhQhVnoi.js → FileForm-CqJpRbXv.js} +1 -1
- package/dist/assets/{FiltersApplet-gbu4I1fK.js → FiltersApplet-CcYMBq-Q.js} +1 -1
- package/dist/assets/{HomeFab-CXaEEzXy.js → HomeFab-D2pLJ9oc.js} +1 -1
- package/dist/assets/{IdentityFields-OPEWPlZs.js → IdentityFields-Bti7ojF3.js} +1 -1
- package/dist/assets/{LensApplet-FifF2RUs.js → LensApplet-DibGKbKC.js} +1 -1
- package/dist/assets/LinkToCard-5dg0jvSY.js +1 -0
- package/dist/assets/{NextShell-BIYs9fCL.js → NextShell-UX4Efo0u.js} +1 -1
- package/dist/assets/{NotesApplet-D94iQKg6.js → NotesApplet-DJp9Wuwt.js} +1 -1
- package/dist/assets/{ObjectPropertiesCard-ChvWbOpZ.js → ObjectPropertiesCard-BIBMvx_i.js} +4 -4
- package/dist/assets/{PathPickerField-DBe7jykL.js → PathPickerField-fZazwxCN.js} +1 -1
- package/dist/assets/{PickDocumentsCard-Bo224P4q.js → PickDocumentsCard-DamtV7fN.js} +1 -1
- package/dist/assets/{SketchApplet-ADVOnSLI.js → SketchApplet-DDIg411i.js} +1 -1
- package/dist/assets/{SketchEditor-CkgRysCG.js → SketchEditor-CKPPuZt3.js} +1 -1
- package/dist/assets/{TerminalApplet-CkO4uaE3.js → TerminalApplet-wGJG1PPc.js} +1 -1
- package/dist/assets/{TextDocumentEditor-COvsHJXH.js → TextDocumentEditor-CRre32cj.js} +1 -1
- package/dist/assets/{TodosApplet-Bpf1OIH4.js → TodosApplet-CleBd4uU.js} +1 -1
- package/dist/assets/{TodosWidget-BIYqPXUp.js → TodosWidget-CxiqmDuJ.js} +1 -1
- package/dist/assets/{UploadProgressList-BXJr87lI.js → UploadProgressList-DRJzjy6A.js} +1 -1
- package/dist/assets/{_agentId_-wN8YJoTZ.js → _agentId_--jQP7aTv.js} +0 -0
- package/dist/assets/{_contextId_-CoJraYnP.js → _contextId_-D6nNA8hC.js} +1 -1
- package/dist/assets/_workspaceName_-DfHnlgVg.js +1 -0
- package/dist/assets/{about-CT6Ghfkb.js → about-DVlaoa-W.js} +1 -1
- package/dist/assets/{add-BzgCpo5S.js → add-Bq99uA2R.js} +1 -1
- package/dist/assets/{agents-DIJpWCkc.js → agents-CRnO7j5E.js} +1 -1
- package/dist/assets/{appearance-D1EpKWaK.js → appearance-BAH_8zeF.js} +1 -1
- package/dist/assets/{applet-target-ChiiXVdC.js → applet-target-C_gBgU-Z.js} +1 -1
- package/dist/assets/{apps-DX8oWukQ.js → apps-EwUooEtp.js} +1 -1
- package/dist/assets/backend-sync-progress-pZrhQPk3.js +7 -0
- package/dist/assets/{content-app-view-DS6Nrz6M.js → content-app-view-BF-k-5Y7.js} +1 -1
- package/dist/assets/{context-mfIOB8dN.js → context-DQoZFMDQ.js} +1 -1
- package/dist/assets/{contexts-CRWqFXzJ2.js → contexts-CvMtPd1N2.js} +1 -1
- package/dist/assets/{date-time-picker-B6mkWt-g.js → date-time-picker-DebNUTx3.js} +1 -1
- package/dist/assets/{document-CX543Kcz.js → document-DOp6AbOi.js} +1 -1
- package/dist/assets/document-list-Dsf1DVEx.js +2 -0
- package/dist/assets/embedding-B5JiUA9X.js +1 -0
- package/dist/assets/{embedding-BHnBCyUx.js → embedding-B7cWrpy0.js} +1 -1
- package/dist/assets/{home-3vhobmCu.js → home-Dc60CSIJ.js} +1 -1
- package/dist/assets/{index-CiBgHujl.js → index-D5Q9EUVc.js} +6 -6
- package/dist/assets/inferd-config-editor--MDmN_7w.js +1 -0
- package/dist/assets/{key-bindings-BNeY-GEg.js → key-bindings-Bqkl5tDH.js} +1 -1
- package/dist/assets/{offline-CsRyFUg7.js → offline-COOUcZsG.js} +1 -1
- package/dist/assets/{public-share-DXxVwHKT.js → public-share-g_wBd6BW.js} +1 -1
- package/dist/assets/{query-debug-BUUG3jpK.js → query-debug-CrPsUwT-.js} +1 -1
- package/dist/assets/{registry-DTWAywyJ.js → registry-DIfZf6LB.js} +2 -2
- package/dist/assets/{roles-BYHLwWCD.js → roles-Bo9GZdOk.js} +1 -1
- package/dist/assets/{settings-DNhy58i9.js → settings-BeN2UmZL.js} +1 -1
- package/dist/assets/{settings-DjnFAqIe.js → settings-CzxxI2yw.js} +1 -1
- package/dist/assets/{settings-jWfP7CP8.js → settings-Dl1FnW9g.js} +1 -1
- package/dist/assets/settings-DqHAUBU4.js +14 -0
- package/dist/assets/{share-target-CgHlnZLH.js → share-target-BWFFRO5O.js} +1 -1
- package/dist/assets/{shared-BMoiShd9.js → shared-B5Pvz8wr.js} +1 -1
- package/dist/assets/{shared-D2uRUNdC.js → shared-BQZGA3ph.js} +1 -1
- package/dist/assets/{sketch-lazy-pbG2cCpW.js → sketch-lazy-C4pjV1WK.js} +2 -2
- package/dist/assets/{text-documents-BvDFBVnC.js → text-documents-0P9jkIpu.js} +2 -2
- package/dist/assets/{use-applet-docs-o5NAUFBk.js → use-applet-docs-D5eXpITp.js} +1 -1
- package/dist/assets/{use-applet-target-cO-FiyPQ.js → use-applet-target-gXPvZGgx.js} +1 -1
- package/dist/assets/use-canvas-pins-CbAxLLTU.js +3 -0
- package/dist/assets/{use-workspace-identity-mgaofjsD.js → use-workspace-identity-BCrrvfeE.js} +1 -1
- package/dist/assets/{useAddTarget-DUjaZdBQ.js → useAddTarget-CqnDU0Om.js} +1 -1
- package/dist/assets/{useAgentModels-Sa4N8WFd.js → useAgentModels-CYDYTjgG.js} +1 -1
- package/dist/assets/{useDocumentThumbnail-DYLCC63L.js → useDocumentThumbnail-DunxmU1A.js} +1 -1
- package/dist/assets/{useEditNoteFields-zHEWwDfB.js → useEditNoteFields-BehI0vog.js} +1 -1
- package/dist/assets/workspace-CrSpR4xf.js +1 -0
- package/dist/assets/{workspace-area-menu-UamvRNfd.js → workspace-area-menu-CP5OWZNX.js} +1 -1
- package/dist/assets/{workspace-content-gate-Be4tLYiB.js → workspace-content-gate-9okuA7J7.js} +1 -1
- package/dist/assets/{workspace-import-form-BRwc_oVg.js → workspace-import-form-aR-DwHf6.js} +1 -1
- package/dist/assets/{workspaces-gQY1mczH.js → workspaces-B9gcHMCE.js} +1 -1
- package/dist/index.html +25 -25
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/dist/assets/LinkToCard-nR7Lal_o.js +0 -1
- package/dist/assets/_workspaceName_-CXuIfG46.js +0 -1
- package/dist/assets/backend-sync-progress-BeI9mDEX.js +0 -7
- package/dist/assets/document-list-SsF3jmuq.js +0 -2
- package/dist/assets/embedding-CEGjemkq.js +0 -1
- package/dist/assets/inferd-config-editor-BHUUFArV.js +0 -1
- package/dist/assets/settings-DH3ZiQLR.js +0 -14
- package/dist/assets/use-canvas-pins-Bth_Q--t.js +0 -3
- package/dist/assets/workspace-DvxC7pw1.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,r as i,v as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./utils-2pl1SbIp.js";import{Pt as s}from"./workspace-CrSpR4xf.js";import{p as c}from"./context-DQoZFMDQ.js";import{t as l}from"./registry-DIfZf6LB.js";import{t as u}from"./applet-target-C_gBgU-Z.js";var d=e(n(),1),f=t(),p=`universe`;function m(){let{appletId:e}=r(),[t,n]=a(),m=l.find(t=>t.id===e),h=t.get(`context`),g=t.get(`workspace`)||p,_=t.get(`path`)||`/`,v=t.get(`tree`)||`context`,y=t.get(`add`)===`1`,b=(0,d.useMemo)(()=>h?{mode:`context`,contextId:h}:{mode:`workspace`,workspaceName:g,path:_,treeName:v,treeType:v===`directory`?`directory`:`context`},[h,g,_,v]),[x,S]=(0,d.useState)([]),[C,w]=(0,d.useState)([]);(0,d.useEffect)(()=>{s().then(S).catch(()=>S([])),c().then(w).catch(()=>w([]))},[]);let[T,E]=(0,d.useState)(_),[D,O]=(0,d.useState)(_);D!==_&&(O(_),E(_));let k=e=>{let r=new URLSearchParams(t);r.delete(`add`);for(let[t,n]of Object.entries(e))n===null?r.delete(t):r.set(t,n);n(r,{replace:!0})};if(!m)return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col items-center justify-center gap-3 surface-desk`,children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Unknown app`,e?` "${e}"`:``,`.`]}),(0,f.jsx)(`div`,{className:`flex gap-2`,children:l.map(e=>(0,f.jsx)(i,{to:`/apps/${e.id}`,className:`rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted`,children:e.label},e.id))})]});let A=h?`context`:`path`;return(0,f.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col surface-desk p-shell gap-shell`,children:[(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 rounded-xl border bg-card px-3 py-2 shadow-elevation-2`,children:[(0,f.jsx)(m.icon,{className:`h-4 w-4 text-muted-foreground`}),(0,f.jsx)(`span`,{className:`text-sm font-semibold`,children:m.label}),(0,f.jsx)(`div`,{className:`ml-2 flex overflow-hidden rounded-md border border-border`,children:[`path`,`context`].map(e=>(0,f.jsx)(`button`,{type:`button`,onClick:()=>{e!==A&&k(e===`path`?{context:null}:{context:C[0]?.id??``,workspace:null,path:null,tree:null})},className:o(`px-2.5 py-1 text-xs capitalize transition-colors`,A===e?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e},e))}),A===`path`?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`select`,{value:g,onChange:e=>k({workspace:e.target.value,path:`/`}),className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Workspace`,children:[!x.some(e=>e.name===g)&&(0,f.jsx)(`option`,{value:g,children:g}),x.map(e=>(0,f.jsx)(`option`,{value:e.name,children:e.label||e.name},e.id))]}),(0,f.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),onBlur:()=>{let e=T.trim()||`/`;e!==_&&k({path:e})},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},spellCheck:!1,placeholder:`/`,className:`h-7 w-40 rounded-md border border-input bg-transparent px-2 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`,"aria-label":`Path`})]}):(0,f.jsxs)(`select`,{value:h??``,onChange:e=>k({context:e.target.value}),className:`h-7 max-w-56 rounded-md border border-input bg-transparent px-1.5 text-xs`,"aria-label":`Context`,children:[!h&&(0,f.jsx)(`option`,{value:``,children:`Pick a context…`}),C.map(e=>(0,f.jsxs)(`option`,{value:e.id,children:[e.id,e.url?` (${e.url})`:``]},e.id))]}),(0,f.jsx)(`div`,{className:`grow`})]}),(0,f.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-elevation-2`,children:A===`context`&&!h?(0,f.jsxs)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:[`Pick a context above to bind `,m.label,` to it.`]}):(0,f.jsx)(u,{target:b,children:(0,f.jsx)(m.Component,{autoAdd:y},JSON.stringify(b))})})]})}export{m as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{$r as r,Ct as i,Hr as a,Jn as o,Kn as s,L as c,Nr as l,Nt as u,Q as d,X as f,Y as p,Z as m,Zr as h,_r as g,fn as ee,jn as _,li as v,ri as y,sn as b,st as x,zn as S,zt as te}from"./ui-Byg1cZDr.js";import{t as C}from"./utils-2pl1SbIp.js";import{t as w}from"./button-SgR3GVvV.js";import{t as T}from"./input-BOtCd4HP.js";import{c as ne,t as E}from"./api-CA6WiiYM.js";import{t as D}from"./socket-CtH3EU9m.js";import{n as re}from"./use-toast-BlLDqSUO.js";import{t as ie}from"./LinkToCard-5dg0jvSY.js";import{W as ae,bt as oe,dn as se,fn as ce,gt as O}from"./workspace-CrSpR4xf.js";import{i as le}from"./MessageComposerDialog-gbD0Gu_b.js";import{n as ue}from"./LinkToSidePanel-eCy3nW4R.js";import{t as de}from"./PathPickerField-fZazwxCN.js";var k=e(n(),1);function A(e){return`/workspaces/${e}/hooks`}async function fe(e){return await E.get(A(e))||[]}async function j(e,t){return(await E.get(`${A(e)}/${t}`))?.content??``}async function M(e,t,n){await E.put(`${A(e)}/${t}`,{content:n})}async function N(e,t){await E.delete(`${A(e)}/${t}`)}var pe=[`example-`,`disabled-`,`_`];function P(e){let t=e.lastIndexOf(`/`);return{dir:t===-1?``:e.slice(0,t+1),base:t===-1?e:e.slice(t+1)}}function F(e){return pe.find(t=>e.startsWith(t))??null}function me(e){return F(P(e).base)===null}function he(e){return P(e).base.startsWith(`example-`)}function ge(e){let{dir:t,base:n}=P(e),r=F(n);return t+(r?n.slice(r.length):`disabled-${n}`)}async function _e(e,t,n){if(me(t)===n)return t;let r=ge(t);return await M(e,r,await j(e,t)),await N(e,t),r}function ve(e){let t={};for(let n of e){let e;e=n.path.includes(`/`)?n.path.split(`/`)[0]:/^(?:example-|disabled-|_)?rules\.json$/.test(n.path)?`rules`:n.path.replace(/\.js$/,``),(t[e]||=[]).push(n)}return t}function ye(e){let t=e.when?.event;return Array.isArray(t)?t.map(String):t?[String(t)]:[]}function be(e){let t=e.when?.eventPathExact??e.when?.pathExact??e.when?.path;return Array.isArray(t)?t.map(String):typeof t==`string`?[t]:[]}function xe(e){let t=String(e||``).split(`/`).filter(Boolean);return t[0]===`workspace`&&t.length>=2?{backend:`workspace:${t[1]}`,rel:t.slice(2).join(`/`)}:t[0]===`device`?t.length>=3?{backend:t[2],rel:t.slice(3).join(`/`)}:null:t.length>=2?{backend:t[1],rel:t.slice(2).join(`/`)}:null}function Se(e){let t=new URLSearchParams;return e.kind&&e.kind!==`mirror`&&t.set(`addRuleKind`,e.kind),e.path&&t.set(`addRulePath`,e.path),e.target&&t.set(`addRuleTarget`,e.target),e.storeTo&&t.set(`addRuleStoreTo`,e.storeTo),e.storeFolder&&t.set(`addRuleStoreFolder`,e.storeFolder),t}function Ce(e){return String(e||``).replace(/^[a-z]+:/i,``).split(`/`).filter(Boolean).join(`/`)}var we=`rules.json`;async function Te(e){try{let t=await j(e,we),n=JSON.parse(t||`{}`);return Array.isArray(n.rules)?n.rules:[]}catch{return[]}}async function Ee(e,t){await M(e,we,JSON.stringify({$schema:`canvas.hook-rules/v1`,rules:t},null,2)+`
|
|
2
|
+
`)}async function De(e,t={}){let n=new URLSearchParams;t.status&&n.set(`status`,t.status),t.handler&&n.set(`handler`,t.handler),t.limit&&n.set(`limit`,String(t.limit));let r=n.toString();return await E.get(`${A(e)}/pending${r?`?${r}`:``}`)||[]}async function Oe(e,t){return await E.post(`${A(e)}/pending/decisions`,t)}async function ke(e,t){return await E.get(`${A(e)}/runs/${encodeURIComponent(t)}`)}async function Ae(e,t={}){let n=new URLSearchParams;t.limit&&n.set(`limit`,String(t.limit)),t.handler&&n.set(`handler`,t.handler),t.event&&n.set(`event`,t.event),t.failed&&n.set(`failed`,`true`);let r=n.toString();return await E.get(`${A(e)}/runs${r?`?${r}`:``}`)||[]}var I=1e4,je=`canvas.hooks.backfillLimit`;function Me(e){let t=Math.floor(Number(e));return!Number.isFinite(t)||t<1?500:Math.min(t,I)}function Ne(){try{let e=localStorage.getItem(je);return e?Me(e):500}catch{return 500}}function Pe(e){let t=Me(e);try{localStorage.setItem(je,String(t))}catch{}return t}function Fe(e){if(e.includes(`/`)){let t=e.split(`/`)[0];return t===`lib`||t===`rules`?null:t}return e.endsWith(`.js`)?e.replace(/\.js$/,``).replace(/^(?:example-|disabled-|_)/,``):null}async function Ie(e,t){return await E.post(`${A(e)}/backfill`,t)}function Le(e,t){return E.post(`${A(e)}/backfill/jobs`,t)}function L(e,t){return E.get(`${A(e)}/backfill/jobs/${t}`)}function Re(e,t){return E.delete(`${A(e)}/backfill/jobs/${t}`)}function ze(e){return E.get(`${A(e)}/backfill/jobs`)}async function R(e,t){return await E.post(`${A(e)}/run`,t)}async function z(e,t){return await E.post(`${A(e)}/runs/${t}/replay`,{})}async function Be(e){return await E.get(`${A(e)}/meta`)}async function Ve(e,t){return await E.post(`${A(e)}/generate`,t)}async function He(e,t){let n=await j(e,we),r=JSON.parse(n),i=Array.isArray(r)?r:r?.rules;if(!Array.isArray(i))throw Error(`The workspace rules file is invalid. Fix it in Rules before adding a rule.`);let a=(Array.isArray(t)?t:[t]).filter(e=>!i.some(t=>t.id===e.id));if(!a.length)return;let o=Array.isArray(r)?[...i,...a]:{...r,rules:[...i,...a]};await M(e,we,JSON.stringify(o,null,2)+`
|
|
3
|
+
`)}var Ue=He;function We(e,t,n,r=new Date){let i=e=>String(e).padStart(2,`0`),a={YYYY:String(r.getFullYear()),YY:i(r.getFullYear()%100),MM:i(r.getMonth()+1),DD:i(r.getDate()),HH:i(r.getHours()),mm:i(r.getMinutes()),ss:i(r.getSeconds())},o=e=>e.replace(/\{\{\s*([A-Za-z]+)\s*\}\}/g,(e,t)=>a[t]??e),s=e=>e.split(/[\\/]+/).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),c=[e,s(o(t.trim()))].filter(Boolean).join(`/`),l=s(o(n.trim()));return{root:c,added:l,result:[c,l,`<attachment filename>`].filter(Boolean).join(`/`),date:`${a.YYYY}-${a.MM}-${a.DD}`}}var B=`Applying rules to existing documents…`,Ge=new Map;function V(e){return`${e.ruleIds.length>1?`Rule ${e.ruleIndex+1}/${e.ruleIds.length}: `:``}${e.processed}${e.total===null?``:` / ${e.total}`} documents · ${e.applied} applied`}function Ke(e,t){let n=`${t.checked} checked, ${t.applied} applied${t.skipped?`, ${t.skipped} already there`:``}`;t.status===`cancelled`?e.done({title:`Cancelled`,description:n}):t.status===`failed`?e.fail({title:`Stopped before finishing`,description:`${n}: ${t.error}. The rule stays enabled; rerun it from Rules to finish.`,variant:`destructive`}):t.failed?e.done({title:`Finished with errors`,description:`${n}, ${t.failed} failed. Details in the rule’s run log.`,variant:`destructive`}):e.done({title:`Rule applied`,description:n})}function H(e,t,n){let r=Ge.get(n.id);if(r)return r;let i=new Promise(r=>{let i={channel:`workspace:${t}`},a=e({title:B,description:V(n),action:{label:`Cancel`,onClick:()=>{a.update({title:`Cancelling…`,description:V(n)}),Re(t,n.id).catch(()=>a.update({title:B,description:`Could not cancel. Try again.`}))}}}),o=()=>{u?.(),D.off(`job.progress`,c),D.off(`job.finished`,c),r()},s=e=>{if(e.status===`running`)return a.update({title:B,description:V(e)});Ke(a,e),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`)),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`)),o()},c=e=>{let t=e?.job;t?.id===n.id&&s(t)},l=()=>{D.emit(`subscribe`,i),L(t,n.id).then(s,()=>{})},u=D.on(`connect`,l);D.on(`job.progress`,c),D.on(`job.finished`,c),l()});return Ge.set(n.id,i),i.finally(()=>Ge.delete(n.id)),i}async function qe(e,t,n){let r;try{r=await Le(t,{ruleIds:n,limit:Ne()})}catch(t){e({title:B}).fail({title:`Could not start`,description:`${t instanceof Error?t.message:String(t)}. The rule stays enabled; rerun it from Rules.`,variant:`destructive`});return}return H(e,t,r)}async function Je(e,t){let n=await ze(t).catch(()=>[]);for(let r of n)r.status===`running`&&H(e,t,r)}function U(e){return`/workspaces/${e}/scripts`}async function Ye(e){return await E.get(U(e))||[]}async function Xe(e,t){return(await E.get(`${U(e)}/${t}`))?.content??``}async function Ze(e,t,n){await E.put(`${U(e)}/${t}`,{content:n})}async function Qe(e,t){await E.delete(`${U(e)}/${t}`)}var W=t(),$e=[{value:``,label:`any item`},{value:`email`,label:`an email`},{value:`message`,label:`a message`},{value:`tab`,label:`a browser tab / link`},{value:`note`,label:`a note`},{value:`file`,label:`a file`},{value:`todo`,label:`a todo / task`}],et=[{value:`document.inserted`,label:`is added`,hint:`Fires when the item is created or uploaded.`},{value:`document.updated`,label:`is updated`,hint:`Fires on every edit of the item.`},{value:`document.linked`,label:`is filed into a folder`,hint:`Fires when the item is (re)filed into a tree path — the usual pair with "is added" for folder rules.`},{value:`document.unlinked`,label:`is removed from a folder`,hint:`Fires when the item leaves a tree path.`}],tt=[{key:`toExact`,label:`recipient (To/Cc) is`,hint:`accounting@example.com`},{key:`fromExact`,label:`email sender is`,hint:`person@example.com`},{key:`senderExact`,label:`message sender is`,hint:`Sender ID`},{key:`sender`,label:`message sender contains`,hint:`Sender ID or name`},{key:`senderRegex`,label:`message sender matches regex`,hint:`Sender ID or name pattern`},{key:`body`,label:`body / text contains`,hint:`Words in the email preview or message text`},{key:`bodyRegex`,label:`body / text matches regex`,hint:`invoice\\s+\\d+`},{key:`threadExact`,label:`thread is`,hint:`Thread ID`},{key:`channelExact`,label:`channel / conversation is`,hint:`Channel or conversation ID`},{key:`platformExact`,label:`platform is`,hint:`slack, whatsapp, teams`},{key:`pathExact`,label:`is directly in the folder`,hint:`Current folder membership`},{key:`eventPathExact`,label:`is inserted / linked directly into`,hint:`Exact event destination, e.g. ctx:/foo/bar/baz. Descendant inserts do not match.`},{key:`path`,label:`is under the folder`,hint:`/projects/canvas/UI or backends:/workspace/home/foo`},{key:`mime`,label:`file type is`,hint:`image/*, application/pdf`},{key:`from`,label:`sender contains`,hint:`boss@company.tld`},{key:`to`,label:`recipient (To/Cc) contains`,hint:`invoice@my-company.tld`},{key:`subject`,label:`subject contains`,hint:`invoice`},{key:`fromRegex`,label:`sender matches regex`,hint:`@(acme|example)\\.com$`},{key:`toRegex`,label:`recipient (To/Cc) matches regex`,hint:`^(billing|accounts)@`},{key:`subjectRegex`,label:`subject matches regex`,hint:`^invoice\\s+\\d+`},{key:`urlRegex`,label:`URL matches regex`,hint:`/(invoice|receipt)/`},{key:`urlHost`,label:`website is`,hint:`youtube.com`},{key:`urlContains`,label:`URL contains`,hint:`/watch?v=`},{key:`attachment`,label:`has an attachment of type`,hint:`application/pdf, or * for any`}],nt=new Set([`toExact`,`fromExact`,`senderExact`,`threadExact`,`channelExact`,`platformExact`]),rt=e=>nt.has(e)?e.replace(/Exact$/,``):e.replace(/Regex$/,``),it=[{key:`sendFile`,label:`Send file(s) via a channel`,icon:b,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`},{key:`extractAttachments`,label:`Extract email attachments to a folder`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`moveMessage`,label:`Move the email to a mail folder`,icon:b,tone:`text-teal-600 dark:text-teal-400 bg-teal-500/10`},{key:`store`,label:`Copy/Move file(s) to a storage backend`,icon:S,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`},{key:`download`,label:`download what the link points at`,icon:g,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`},{key:`link`,label:`file it into a folder`,icon:o,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`},{key:`unlink`,label:`remove it from a folder`,icon:o,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`tag`,label:`add tags`,icon:d,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`},{key:`unstore`,label:`delete the file from a storage backend`,icon:p,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`},{key:`notify`,label:`Send me a notification`,icon:y,tone:`text-pink-600 dark:text-pink-400 bg-pink-500/10`},{key:`agent`,label:`ask an agent`,icon:r,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`},{key:`script`,label:`run a script`,icon:m,tone:`text-slate-600 dark:text-slate-300 bg-slate-500/10`},{key:`delete`,label:`delete it from Canvas`,icon:f,tone:`text-destructive bg-destructive/10`},{key:`destroy`,label:`delete it everywhere`,icon:f,tone:`text-destructive bg-destructive/10`}],at=e=>it.find(t=>t.key===e)||it[1],ot=`{{title}}{{ext}}`,G=`{{YYYY}}/{{MM}}/{{YYYY}}{{MM}}{{DD}}_{{HH}}{{mm}}{{ss}}{{ext}}`,st=[{value:`auto`,label:`whatever it is (auto)`,hint:`arXiv → the PDF · YouTube, Vimeo, TikTok… → the video · image / video / PDF links → the file · anything else → the page.`},{value:`image`,label:`the file itself (image, PDF, …)`,hint:`Fetches the bytes the URL serves.`},{value:`video`,label:`the video (yt-dlp)`,hint:`Best video + audio, merged. Needs yt-dlp on the server.`},{value:`arxiv`,label:`the arXiv paper (PDF)`,hint:`Works for abs/ and pdf/ links.`},{value:`page`,label:`the page with its images & styles`,hint:`One page, offline-readable (wget --page-requisites).`},{value:`website`,label:`the whole website (mirror)`,hint:`Follows links on the same site up to the chosen depth.`}],ct=[{value:`keep`,label:`keep the original file name`},{value:`title`,label:`use the item title as file name`},{value:`dated`,label:`photo style: 2024/07/20240714_183012.jpg`},{value:`custom`,label:`custom template…`}],K=e=>({sendDriver:`imap`,sendSource:`document`,sendSubject:`{{file.name}}`,sendMessage:``,kind:e,a:``,b:``,recursive:!1,storeFrom:``,storeFolder:``,storeName:`keep`,storeMode:`copy`,storeConflict:`rename`,attachmentMime:`application/pdf`,attachmentName:``,attachmentPath:`{{YYYY}}/{{MM}}`,includeInline:!1,dlKind:`auto`,dlDepth:`2`,dlTags:``,keepLast:!0,notePath:``,noteTitle:``,filePath:``,fileBackend:`home`,fileInsert:``,notifyReply:!1}),q={id:null,description:``,events:[`document.inserted`],schema:``,cascade:!1,approval:!1,conditions:[],actions:[K(`link`)]},lt=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean);function ut(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`rule-${Math.random().toString(36).slice(2,7)}`}var J=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),dt=[{id:`send-invoices`,title:`Send invoice PDFs to accounting`,icon:b,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10`,blurb:`Send matching PDF attachments to your accounting firm’s ingestion email, or to a Slack / WhatsApp conversation. Keep the original email and files.`,build:()=>({...q,description:`Send invoice PDFs to accounting`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`sendFile`),sendSource:`attachments`,sendSubject:`Invoice: {{file.name}}`}]})},{id:`attachments`,title:`File PDF email attachments by month`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Choose a recipient and extract PDF attachments into Accounting / year / month, using the email date. Add a subject or filename filter to narrow it to invoices.`,build:()=>({...q,description:`File accounting PDF attachments by month`,schema:`email`,conditions:[{field:`toExact`,value:``}],actions:[{...K(`extractAttachments`),a:`workspace:home`,storeFolder:`Accounting`}]})},{id:`store`,title:`Copy/Move file(s) to a storage backend`,icon:S,tone:`text-sky-600 dark:text-sky-400 bg-sky-500/10`,blurb:`Uploads land in the managed blob store. Pick a folder in Canvas and a folder on a storage backend — copy or move matching files and optionally recreate their sub-folder paths.`,build:({backend:e})=>({...q,description:`Copy/Move file(s) to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`store`),a:e,recursive:!0}]})},{id:`photos`,title:`Sort photos by date`,icon:_,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10`,blurb:`Images filed into a folder are stored as Photos / 2024 / 07 / 20240714_183012.jpg — by the time the photo was taken (EXIF), not uploaded.`,build:({backend:e})=>({...q,description:`Sort photos by date`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``},{field:`mime`,value:`image/*`}],actions:[{...K(`store`),a:e,storeFolder:`Photos`,storeName:`dated`}]})},{id:`mirror`,title:`Mirror a storage folder`,icon:o,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10`,blurb:`Everything that appears under a folder of a storage backend shows up 1:1 in the Directory tree.`,build:()=>({...q,description:`Mirror a storage folder`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:`backends:/workspace/home/`}],actions:[{...K(`link`),a:`dir:/`,recursive:!0}]})},{id:`mail`,title:`File mail from a sender`,icon:b,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10`,blurb:`Emails from a person or domain are filed into a folder and you get a notification.`,build:()=>({...q,description:`Mail from …`,schema:`email`,conditions:[{field:`from`,value:``}],actions:[{...K(`link`),a:`/work/urgent`},{...K(`notify`),a:`New mail from {{doc.data.from}}: {{doc.data.subject}}`}]})},{id:`download`,title:`Download what links point at`,icon:g,tone:`text-rose-600 dark:text-rose-400 bg-rose-500/10`,blurb:`Bookmarks filed into a folder are fetched for real — images, videos (yt-dlp), arXiv papers, a page or a whole website — saved to a folder and filed next to the link.`,build:({backend:e})=>({...q,description:`Download what links point at`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:``}],actions:[{...K(`download`),a:e,storeFolder:`Downloads`,recursive:!0}]})},{id:`agent`,title:`Ask an agent`,icon:r,tone:`text-indigo-600 dark:text-indigo-400 bg-indigo-500/10`,blurb:`Hand new items to an agent with a prompt; save its reply as a note or get it as a notification.`,build:()=>({...q,description:`Summarize new items`,actions:[{...K(`agent`),b:`Read document #{{doc.id}} in full with canvas_doc_get_by_id, then summarize it in three bullet points.`,notifyReply:!0}]})},{id:`blank`,title:`Start from scratch`,icon:x,tone:`text-muted-foreground bg-muted`,blurb:`An empty rule: choose what it reacts to, add conditions and actions.`,build:()=>({...q})}];function Y(e){let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field));if(t.length!==1||t[0].field!==`eventPathExact`)return null;let n=lt(t[0].value);return n.length===1&&/^(ctx|context):\//.test(n[0])?n[0].replace(/^(ctx|context):/,``).replace(/\/+$/,``)||`/`:null}function ft(e){if(Y(e)!==null)return!0;let t=e.filter(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)).flatMap(e=>lt(e.value));return t.length>0&&t.every(e=>/^(dir|directory|backends):\//.test(e))}function pt(e,t,n){let r=e=>e.replace(/\\/g,`/`).split(`/`).filter(e=>e&&e!==`.`&&e!==`..`).join(`/`),i=`${n?.treePath?`backends:${n.treePath}`:e.a}/${r(e.storeFolder.trim())}`.replace(/\/+$/,``),a=Y(t),o=e.recursive?a===null?`<sub-folders>`:r(a):``;return{root:i,recreated:o,result:[i,o,e.storeName===`keep`?`<original filename>`:e.storeName===`title`?`<title>.<ext>`:e.storeName===`dated`?G:e.b||`<filename>`].filter(Boolean).join(`/`)}}function mt(e,t=[]){let n={event:e.events.length===1?e.events[0]:e.events};e.schema&&(n.schema=e.schema);let r={},i={};for(let t of e.conditions){let e=t.field.endsWith(`Regex`),n=nt.has(t.field),a=e||n?t.value.trim()?[t.value]:[]:lt(t.value);if(e&&a.length)try{new RegExp(t.value,`i`)}catch{throw Error(`Invalid regular expression for ${tt.find(e=>e.key===t.field)?.label}: ${t.value}`)}if(!a.length)throw Error(`Enter a value for ${tt.find(e=>e.key===t.field)?.label||t.field}, or remove that condition.`);if(t.field===`urlHost`||t.field===`urlContains`||t.field===`urlRegex`){let e=t.field===`urlHost`?`host`:t.field===`urlRegex`?`regex`:`contains`,n=i[e],r=[...Array.isArray(n)?n:n==null?[]:[n],...a];i[e]=r.length===1?r[0]:r}else(r[rt(t.field)]||=[]).push(...e?a.map(e=>({regex:e})):n?a.map(e=>({equals:e})):a)}for(let[e,t]of Object.entries(r))t?.length&&(n[e]=t.length===1?t[0]:t);Object.keys(i).length&&(n.url=i);let a=e=>{let t={};return e.notePath.trim()&&(t.note={path:e.notePath.trim(),...e.noteTitle.trim()?{title:e.noteTitle.trim()}:{}}),e.filePath.trim()&&(t.file={path:e.filePath.trim(),...e.fileBackend===`data`?{backend:`data`}:{},...e.fileInsert.trim()?{insert:e.fileInsert.trim()}:{}}),e.notifyReply&&(t.notify=!0),Object.keys(t).length?t:null},o=[];for(let n of e.actions){let r=n.a.trim(),i=n.b.trim(),s=n.recursive?{recursive:!0}:{};if(n.kind===`sendFile`){if(!r)throw Error(`Choose a sending account for the file.`);if(!i)throw Error(n.sendDriver===`imap`?`Enter the destination email address.`:`Enter a configured destination conversation.`);if(![`imap`,`slack`,`whatsapp`].includes(n.sendDriver))throw Error(`Choose email, Slack or WhatsApp.`);if(![`document`,`attachments`,`download`].includes(n.sendSource))throw Error(`Choose which files to send.`);if(n.sendSource===`download`&&!o.some(e=>e.action===`download`))throw Error(`Add a Download action before sending its files.`);let e=J(n.attachmentMime);if(n.sendSource===`attachments`&&(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e))))throw Error(`Enter attachment MIME types, such as application/pdf.`);if(n.sendDriver===`whatsapp`&&n.sendMessage.length>1024)throw Error(`WhatsApp file captions must be at most 1,024 characters.`);o.push({action:`sendFile`,source:n.sendSource,driver:n.sendDriver,address:r,...n.sendDriver===`imap`?{to:J(i),subject:n.sendSubject}:{target:i},...n.sendMessage?{message:n.sendMessage}:{},...n.sendSource===`attachments`?{mime:e.length===1?e[0]:e,...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{}}:{}})}if(n.kind===`link`&&r&&o.push({action:`link`,paths:J(r),...s,...i?{tags:J(i)}:{}}),n.kind===`unlink`&&r&&o.push({action:`unlink`,paths:J(r),...s}),n.kind===`tag`&&r&&o.push({action:`tag`,tags:J(r)}),n.kind===`moveMessage`){if(!r)throw Error(`Enter the mail folder to move the email to, such as INBOX/Accounting/{{YYYY}}/Expenses.`);o.push({action:`moveMessage`,folder:r})}if(n.kind===`store`&&r){if(n.storeMode===`move`&&!n.storeFrom.trim())throw Error(`Choose the source backend whose copy should be moved.`);if(n.recursive&&!ft(e.conditions))throw Error(`Choose a Directory/Backends source path, or one exact Context insertion path, to recreate the path.`);if(n.recursive&&t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`This destination has not reported support for folder paths. Choose a supported backend or turn off path recreation.`);let a=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),c=n.storeName===`title`?ot:n.storeName===`dated`?G:n.storeName===`custom`?i:``;o.push({action:`store`,to:r,...n.storeFrom.trim()?{from:n.storeFrom.trim()}:{},mode:n.storeMode,...a?{folder:a}:{},...s,...n.recursive&&Y(e.conditions)!==null?{pathMode:`full`}:{},...c?{key:c}:{},onConflict:n.storeConflict})}if(n.kind===`extractAttachments`){if(!r)throw Error(`Choose a destination backend for the attachments.`);if(t.find(e=>e.address===r)?.capabilities?.paths!==!0)throw Error(`Choose an attachment destination with support for folder paths.`);let e=J(n.attachmentMime);if(!e.length||e.some(e=>!/^(\*|[a-z0-9!#$&^_.+-]+\/(\*|[a-z0-9!#$&^_.+-]+)|\*\/\*)$/i.test(e)))throw Error(`Enter attachment MIME types, such as application/pdf or image/*. Use * for all attachments.`);if(![`rename`,`error`].includes(n.storeConflict))throw Error(`Choose rename or skip for attachment filename conflicts.`);o.push({action:`extractAttachments`,to:r,mime:e.length===1?e[0]:e,...n.storeFolder.trim()?{folder:n.storeFolder.trim()}:{},...n.attachmentPath.trim()?{subfolder:n.attachmentPath.trim()}:{},...n.attachmentName.trim()?{filename:n.attachmentName.trim()}:{},...n.includeInline?{includeInline:!0}:{},onConflict:n.storeConflict})}if(n.kind===`download`){let e=n.storeFolder.trim().replace(/^\/+|\/+$/g,``),t=Number(n.dlDepth);o.push({action:`download`,to:r||`workspace:home`,...e?{folder:e}:{},...s,...n.dlKind===`auto`?{}:{kind:n.dlKind},...i?{insert:J(i)}:{},...n.dlTags.trim()?{tags:J(n.dlTags)}:{},...n.dlKind===`website`&&Number.isFinite(t)&&t>0&&t!==2?{depth:t}:{}})}if(n.kind===`unstore`&&r&&o.push({action:`unstore`,from:r,...i?{ifOn:i}:{},...n.keepLast?{}:{keepLast:!1}}),n.kind===`notify`&&r&&o.push({action:`notify`,message:r}),n.kind===`delete`&&o.push({action:`delete`}),n.kind===`destroy`&&o.push({action:`destroy`}),n.kind===`agent`&&r&&i){let e=a(n);o.push({action:`agent`,slug:r,prompt:i,...e?{output:e}:{}})}if(n.kind===`script`&&r){let e=a(n);o.push({action:`script`,path:r,...e?{output:e}:{}})}}return{id:e.id||ut(e.description),enabled:!0,...e.description?{description:e.description}:{},...e.cascade?{cascade:!0}:{},...e.approval?{approval:!0}:{},...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},when:n,then:o}}function ht(e){let{event:t,schema:n,from:r,to:i,subject:a,body:o,sender:s,thread:c,channel:l,platform:u,path:d,pathExact:f,eventPathExact:p,mime:m,url:h,attachment:g,...ee}=e.when;if(Object.keys(ee).length>0)return null;let _=Array.isArray(t)?t:[t];if(!_.length||!_.every(e=>typeof e==`string`&&et.some(t=>t.value===e))||n!==void 0&&typeof n!=`string`)return null;let v=[],y=(e,t)=>{let n=Array.isArray(t)?t:[t];if(e.endsWith(`Regex`)){if(!n.every(e=>typeof e==`string`))return!1;for(let t of n)v.push({field:e,value:t})}else if(nt.has(e))for(let t of n){if(!t||typeof t!=`object`||Object.keys(t).length!==1||typeof t.equals!=`string`)return!1;v.push({field:e,value:t.equals})}else if([`from`,`to`,`subject`,`body`,`sender`].includes(e))for(let t of n)if(typeof t==`string`)v.push({field:e,value:t});else if([`from`,`to`,`sender`].includes(e)&&t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.equals==`string`)v.push({field:`${e}Exact`,value:t.equals});else if(t&&typeof t==`object`&&Object.keys(t).length===1&&typeof t.regex==`string`)v.push({field:`${e}Regex`,value:t.regex});else return!1;else{if(!n.every(e=>typeof e==`string`))return!1;v.push({field:e,value:n.join(` | `)})}return!0};if(d!==void 0&&!y(`path`,d)||f!==void 0&&!y(`pathExact`,f)||p!==void 0&&!y(`eventPathExact`,p)||m!==void 0&&!y(`mime`,m)||r!==void 0&&!y(`from`,r)||i!==void 0&&!y(`to`,i)||a!==void 0&&!y(`subject`,a)||o!==void 0&&!y(`body`,o)||s!==void 0&&!y(`sender`,s)||c!==void 0&&!y(`threadExact`,c)||l!==void 0&&!y(`channelExact`,l)||u!==void 0&&!y(`platformExact`,u)||g!==void 0&&!y(`attachment`,g))return null;if(h!==void 0){if(typeof h==`string`)v.push({field:`urlContains`,value:h});else if(h&&typeof h==`object`){let e=h;if(Object.keys(e).filter(e=>e!==`host`&&e!==`contains`&&e!==`regex`).length||e.host!==void 0&&!y(`urlHost`,e.host)||e.contains!==void 0&&!y(`urlContains`,e.contains)||e.regex!==void 0&&!y(`urlRegex`,e.regex))return null}else return null}let b=e=>{let t=e.output&&typeof e.output==`object`?e.output:{};if(Object.keys(t).filter(e=>e!==`note`&&e!==`file`&&e!==`notify`).length)return null;let n=t.note&&typeof t.note==`object`?t.note:{},r=t.file&&typeof t.file==`object`?t.file:{};return Object.keys(r).filter(e=>e!==`path`&&e!==`backend`&&e!==`insert`).length?null:{notePath:typeof n.path==`string`?n.path:``,noteTitle:typeof n.title==`string`?n.title:``,filePath:typeof r.path==`string`?r.path:``,fileBackend:r.backend===`data`?`data`:`home`,fileInsert:typeof r.insert==`string`?r.insert:``,notifyReply:t.notify===!0}},x=[];for(let t of e.then||[]){if(t.approval!==void 0)return null;if(t.action===`link`&&Array.isArray(t.paths))x.push({...K(`link`),a:t.paths.join(`, `),b:Array.isArray(t.tags)?t.tags.join(`, `):``,recursive:t.recursive===!0});else if(t.action===`unlink`&&Array.isArray(t.paths))x.push({...K(`unlink`),a:t.paths.join(`, `),recursive:t.recursive===!0});else if(t.action===`tag`&&Array.isArray(t.tags))x.push({...K(`tag`),a:t.tags.join(`, `)});else if(t.action===`moveMessage`){if(Object.keys(t).some(e=>e!==`action`&&e!==`folder`)||typeof t.folder!=`string`)return null;x.push({...K(`moveMessage`),a:t.folder})}else if(t.action===`notify`&&typeof t.message==`string`)x.push({...K(`notify`),a:t.message});else if(t.action===`store`&&typeof t.to==`string`){if(t.pathMode!==void 0&&(t.pathMode!==`full`||t.recursive!==!0||Y(v)===null)||t.recursive===!0&&Y(v)!==null&&t.pathMode!==`full`||t.folder!==void 0&&typeof t.folder!=`string`||t.key!==void 0&&typeof t.key!=`string`)return null;let e=typeof t.key==`string`?t.key:``;x.push({...K(`store`),a:t.to,b:e===ot||e===G?``:e,storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,storeName:e?e===ot?`title`:e===G?`dated`:`custom`:`keep`,storeFrom:typeof t.from==`string`?t.from:Array.isArray(t.from)?String(t.from[0]??``):``,storeMode:t.mode===`move`?`move`:`copy`,storeConflict:t.onConflict===`error`||t.onConflict===`overwrite`?t.onConflict:`rename`})}else if(t.action===`sendFile`){let e=new Set([`action`,`source`,`driver`,`address`,`to`,`target`,`subject`,`message`,`mime`,`filename`,`includeInline`]);if(Object.keys(t).some(t=>!e.has(t))||![`imap`,`slack`,`whatsapp`].includes(String(t.driver))||typeof t.address!=`string`||t.source!==void 0&&![`document`,`attachments`,`download`].includes(String(t.source))||[`target`,`subject`,`message`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`)return null;let n=Array.isArray(t.to)?t.to:t.to===void 0?[]:[t.to],r=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`)||!r.every(e=>typeof e==`string`)||(t.driver===`imap`?t.target!==void 0:t.to!==void 0||t.subject!==void 0))return null;x.push({...K(`sendFile`),a:t.address,b:t.driver===`imap`?n.join(`, `):String(t.target||``),sendDriver:t.driver,sendSource:t.source||`document`,sendSubject:String(t.subject??`{{file.name}}`),sendMessage:String(t.message||``),attachmentMime:r.join(`, `),attachmentName:String(t.filename||``),includeInline:t.includeInline===!0})}else if(t.action===`extractAttachments`){let e=new Set([`action`,`to`,`folder`,`subfolder`,`mime`,`filename`,`includeInline`,`onConflict`]);if(Object.keys(t).some(t=>!e.has(t))||typeof t.to!=`string`||[`folder`,`subfolder`,`filename`].some(e=>t[e]!==void 0&&typeof t[e]!=`string`)||t.includeInline!==void 0&&typeof t.includeInline!=`boolean`||t.onConflict!==void 0&&t.onConflict!==`rename`&&t.onConflict!==`error`)return null;let n=Array.isArray(t.mime)?t.mime:[t.mime??`*`];if(!n.every(e=>typeof e==`string`))return null;x.push({...K(`extractAttachments`),a:t.to,storeFolder:typeof t.folder==`string`?t.folder:``,attachmentPath:typeof t.subfolder==`string`?t.subfolder:``,attachmentMime:n.join(`, `),attachmentName:typeof t.filename==`string`?t.filename:``,includeInline:t.includeInline===!0,storeConflict:t.onConflict===`error`?`error`:`rename`})}else if(t.action===`download`){let e=new Set([`action`,`to`,`folder`,`recursive`,`kind`,`insert`,`tags`,`depth`]);if(Object.keys(t).some(t=>!e.has(t)))return null;let n=typeof t.kind==`string`?t.kind:`auto`;if(!st.some(e=>e.value===n))return null;let r=Array.isArray(t.insert)?t.insert:typeof t.insert==`string`?[t.insert]:[];if(!r.every(e=>typeof e==`string`))return null;x.push({...K(`download`),a:typeof t.to==`string`?t.to:`workspace:home`,b:r.join(`, `),storeFolder:typeof t.folder==`string`?t.folder:``,recursive:t.recursive===!0,dlKind:n,dlDepth:typeof t.depth==`number`?String(t.depth):`2`,dlTags:Array.isArray(t.tags)?t.tags.join(`, `):``})}else if(t.action===`unstore`&&(typeof t.from==`string`||Array.isArray(t.from))){let e=e=>Array.isArray(e)?String(e[0]??``):typeof e==`string`?e:``;x.push({...K(`unstore`),a:e(t.from),b:e(t.ifOn),keepLast:t.keepLast!==!1})}else if(t.action===`delete`)x.push(K(`delete`));else if(t.action===`destroy`)x.push(K(`destroy`));else if(t.action===`agent`&&typeof t.slug==`string`&&typeof t.prompt==`string`){let e=b(t);if(!e)return null;x.push({...K(`agent`),a:t.slug,b:t.prompt,...e})}else if(t.action===`script`&&typeof t.path==`string`){let e=b(t);if(!e)return null;x.push({...K(`script`),a:t.path,...e})}else return null}return{id:e.id,description:e.description||``,events:_,schema:typeof n==`string`?n:``,cascade:e.cascade===!0,approval:e.approval===!0,...e.editable?.length?{editable:e.editable}:{},...e.ttl===void 0?{}:{ttl:e.ttl},conditions:v,actions:x.length?x:[K(`link`)]}}var gt=(e,t)=>t.find(t=>t.value===e)?.label?.replace(/\s\(\d+\)$/,``)||(e?String(e).replace(/^data\/schema\//,``):`any item`);function _t(e,t=$e){let n=e.when,r=ye(e).map(e=>et.find(t=>t.value===e)?.label||e).join(` or `),i=[`When ${gt(n.schema,t)} ${r}`],a=e=>Array.isArray(e)?e.join(` or `):typeof e==`object`&&e?JSON.stringify(e):String(e),o={path:`under`,pathExact:`directly in`,eventPathExact:`inserted / linked directly into`,mime:`type`,from:`from`,to:`to`,subject:`subject`,body:`body / text`,sender:`sender`,thread:`thread`,channel:`conversation`,platform:`platform`,url:`url`,attachment:`attachment`};for(let e of Object.keys(o))n[e]!==void 0&&i.push(`${o[e]} ${a(n[e])}`);return i.join(` · `)}function vt(e){let t=e.output||{},n=t.note||{},r=t.file||{};return[n.path?`reply → note ${n.path}`:``,r.path?`reply → file ${r.backend===`data`?`data:`:`home/`}${r.path}${r.insert?` (indexed at ${r.insert})`:``}`:``,t.notify?`reply → notify`:``].filter(Boolean).join(`, `)}function yt(e){if(e.action===`link`)return`file into ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`unlink`)return`remove from ${e.paths?.join(`, `)}${e.recursive===!0?` (sub-folders kept)`:``}`;if(e.action===`tag`)return`tag ${e.tags?.join(`, `)}`;if(e.action===`store`){let t=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,n=e.key===ot?`, named by title`:e.key===G?`, by date`:typeof e.key==`string`&&e.key?`, as ${e.key}`:``;return`${e.mode===`move`?`move`:`copy`} the file to ${e.to}${t}${e.recursive===!0?e.pathMode===`full`?` (full directory path recreated)`:` (sub-folder path recreated)`:``}${n}`}if(e.action===`extractAttachments`){let t=[e.to,e.folder,e.subfolder].filter(Boolean).join(`/`);return`extract ${Array.isArray(e.mime)?e.mime.join(`, `):e.mime||`all`} attachments to ${t}${e.filename?` (filename contains ${e.filename})`:``}`}if(e.action===`moveMessage`)return`move the email to mail folder ${e.folder}`;if(e.action===`download`){let t=st.find(t=>t.value===(e.kind||`auto`)),n=typeof e.folder==`string`&&e.folder?`/${e.folder}`:``,r=Array.isArray(e.insert)&&e.insert.length?`, filed at ${e.insert.join(`, `)}`:`, filed next to the link`;return`download ${t?.value===`auto`?`the link (auto-detected)`:t?.label||e.kind} to ${e.to||`workspace:home`}${n}${e.recursive===!0?` (sub-folders kept)`:``}${r}`}if(e.action===`unstore`)return`delete the file from ${Array.isArray(e.from)?e.from.join(`, `):e.from}${e.ifOn?` once it is on ${Array.isArray(e.ifOn)?e.ifOn.join(`, `):e.ifOn}`:``}`;if(e.action===`sendFile`)return`send ${e.source===`attachments`?`matching attachments`:e.source===`download`?`downloaded files`:`the file`} via ${e.driver===`imap`?`email`:e.driver} to ${Array.isArray(e.to)?e.to.join(`, `):e.to||e.target||`…`}`;if(e.action===`notify`)return`send me a notification`;if(e.action===`delete`)return`delete from Canvas (keeps stored files/mail)`;if(e.action===`destroy`)return`⚠ delete everywhere (index + storage)`;if(e.action===`agent`){let t=vt(e);return`ask agent "${e.slug}"${t?` (${t})`:``}`}if(e.action===`script`){let t=vt(e);return`run ${e.path}${t?` (${t})`:``}`}return e.action}function bt(e){return(e.then||[]).map(yt).join(` · `)||`(no actions)`}function xt(e){return be(e).length>0&&(e.then||[]).length>0&&(e.then||[]).every(e=>e.action===`link`||e.action===`unlink`||e.action===`store`||e.action===`unstore`)}function St(e){let t={};for(let n of e){if(n.handlerType!==`rule`)continue;let e=t[n.handler]||={count:0,errors:0,last:n};e.count++,n.status===`error`&&e.errors++,n.ts>e.last.ts&&(e.last=n)}return t}function Ct(e){let t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return``;let n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<48?`${r}h ago`:`${Math.floor(r/24)}d ago`}function wt(e){return e.some(e=>e.address===`workspace:home`)?`workspace:home`:e.find(e=>e.address!==`workspace:data`)?.address||e[0]?.address||``}function Tt(e){if(e.kind===`document`&&e.rule)return{...ht(e.rule)||q,id:null};if(e.kind===`download`){let t=e.path?` filed under ${e.path.replace(/^(ctx|dir):/,``)}`:``;return{...q,description:`Download links${t}`,schema:`tab`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`download`),a:e.storeTo||``,storeFolder:e.storeFolder||`Downloads`,recursive:!0}]}}if(e.kind===`store`){let t=e.path||``,n=/^(?:(?:ctx|context):)?\//.test(t),r=[{field:n?`eventPathExact`:`path`,value:n&&t.startsWith(`/`)?`ctx:${t}`:t}],i=e.path?`${n?` inserted / linked directly into`:` filed under`} ${e.path.replace(/^(ctx|context|dir|directory):/,``)}`:``;return{...q,description:e.storeTo?`Copy files${i} to ${e.storeTo}${e.storeFolder?`/${e.storeFolder}`:``}`:`Copy files${i} to a storage backend`,schema:`file`,events:[`document.inserted`,`document.linked`],conditions:r,actions:[{...K(`store`),a:e.storeTo||``,storeFolder:e.storeFolder||``,recursive:ft(r)}]}}return{...q,description:`Mirror ${e.path} into ${e.target}`,events:[`document.inserted`,`document.linked`],conditions:[{field:`path`,value:e.path||``}],actions:[{...K(`link`),a:e.target||`dir:/`,recursive:!0}]}}var X=`h-10 w-full rounded-md border bg-background px-3 text-sm outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`,Z=`h-10 text-sm`;function Q({label:e,hint:t,children:n,className:r}){return(0,W.jsxs)(`label`,{className:C(`flex min-w-0 flex-col gap-1.5`,r),children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n,t&&(0,W.jsx)(`span`,{className:`text-xs leading-relaxed text-muted-foreground`,children:t})]})}function $({checked:e,onChange:t,label:n,hint:r,disabled:i}){return(0,W.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:i,onClick:()=>t(!e),className:C(`flex w-full items-start gap-3 rounded-lg border p-3 text-left transition-colors hover:bg-accent/40 disabled:cursor-not-allowed disabled:opacity-50`,e&&`border-primary/40 bg-primary/5`),children:[(0,W.jsx)(`span`,{className:C(`mt-0.5 inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors`,e?`bg-primary`:`bg-muted-foreground/30`),children:(0,W.jsx)(`span`,{className:C(`h-4 w-4 rounded-full bg-background shadow transition-transform`,e&&`translate-x-4`)})}),(0,W.jsxs)(`span`,{className:`min-w-0`,children:[(0,W.jsx)(`span`,{className:`block text-sm font-medium`,children:n}),r&&(0,W.jsx)(`span`,{className:`block text-xs leading-relaxed text-muted-foreground`,children:r})]})]})}function Et({value:e,options:t,onChange:n}){return(0,W.jsx)(`div`,{className:`inline-flex h-10 rounded-md border bg-background p-1`,children:t.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(t.value),className:C(`rounded px-3 text-sm transition-colors`,e===t.value?`bg-primary text-primary-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:t.label},t.value))})}function Dt({active:e,onClick:t,children:n,title:r}){return(0,W.jsx)(`button`,{type:`button`,title:r,onClick:t,"aria-pressed":e,className:C(`h-9 rounded-full border px-3.5 text-sm transition-colors`,e?`border-primary bg-primary/10 font-medium text-foreground`:`text-muted-foreground hover:bg-accent hover:text-foreground`),children:n})}function Ot({step:e,title:t,hint:n}){return(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-sm font-semibold text-primary`,children:e}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold leading-7`,children:t}),n&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n})]})]})}function kt({icon:e,tone:t,size:n=`md`}){return(0,W.jsx)(`span`,{className:C(`inline-flex shrink-0 items-center justify-center rounded-xl`,n===`lg`?`h-12 w-12`:`h-10 w-10`,t),children:(0,W.jsx)(e,{className:n===`lg`?`h-6 w-6`:`h-5 w-5`})})}function At({workspaceId:e,onOpenJson:t,onShowRuns:n,backfillLimit:r,prefill:d,onPrefillConsumed:p,createOnly:m=!1,onCreated:g,onCancel:_}){let{showToast:y,showProgress:b}=re(),[S,ne]=(0,k.useState)([]),[E,D]=(0,k.useState)({}),ae=e=>{Ae(e,{limit:500}).then(e=>D(St(e))).catch(()=>D({}))},[se,ce]=(0,k.useState)(!0),[O,A]=(0,k.useState)(null),[fe,j]=(0,k.useState)(!1),[M,N]=(0,k.useState)(!1),[pe,P]=(0,k.useState)([]),[F,me]=(0,k.useState)([]),[he,ge]=(0,k.useState)([]),[_e,ve]=(0,k.useState)(``),ye=(0,k.useRef)(null),[Se,Ce]=(0,k.useState)(e);e!==Se&&(Ce(e),ce(!0)),(0,k.useEffect)(()=>{Te(e).then(e=>ne(e)).finally(()=>ce(!1)),ae(e)},[e]);let[we,De]=(0,k.useState)(null);d!==we&&(De(d),d&&(A(Tt(d)),j(!1))),(0,k.useEffect)(()=>{d&&p?.()},[d,p]),(0,k.useEffect)(()=>{Ye(e).then(e=>P(e.map(e=>e.path))).catch(()=>P([]))},[e]),(0,k.useEffect)(()=>{let t=!1;return le(e).then(e=>{t||(ge([...new Map(e.map(e=>[`${e.driver}:${e.address}`,e])).values()]),ve(``))}).catch(()=>{t||(ge([]),ve(`Sending accounts could not be loaded.`))}),()=>{t=!0}},[e]),(0,k.useEffect)(()=>{oe(e).then(e=>{let t=e.filter(e=>e.kind===`storage`&&e.enabled!==!1&&e.config?.supported!==!1&&e.config?.readOnly!==!0&&e.capabilities?.write!==!1);me(t);let n=wt(t);n&&A(e=>e&&e.actions.some(e=>(e.kind===`store`||e.kind===`download`)&&!e.a)?{...e,actions:e.actions.map(e=>(e.kind===`store`||e.kind===`download`)&&!e.a?{...e,a:n}:e)}:e)}).catch(()=>me([]))},[e]);let[Oe,ke]=(0,k.useState)($e);(0,k.useEffect)(()=>{Be(e).then(e=>{e.schemas?.length&&ke([{value:``,label:`any item`},...e.schemas.map(e=>({value:e.id,label:`${e.name} (${e.count})`}))])}).catch(()=>{})},[e]);let I=async(t,n)=>{N(!0);try{return await Ee(e,t),ne(t),y({title:n,description:`rules.json updated (committed to workspace git)`}),!0}catch(e){return y({title:`Error`,description:e instanceof Error?e.message:`Failed to save rules`,variant:`destructive`}),!1}finally{N(!1)}},je=async()=>{if(!O||se||M)return;let t;try{t=mt(O,F)}catch(e){y({title:`Invalid rule`,description:e instanceof Error?e.message:`Check the rule conditions and actions`,variant:`destructive`});return}if(!t.then.length){y({title:`Add an action`,description:`Pick at least one "then" action and fill in its fields.`,variant:`destructive`});return}if(m){t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`,N(!0);try{await He(e,t),y({title:`Rule created`,description:`The rule will run for matching new items.`}),g?.()}catch(e){y({title:`Could not create rule`,description:e instanceof Error?e.message:`Failed to save rule`,variant:`destructive`})}finally{N(!1)}return}!O.id&&S.some(e=>e.id===t.id)&&(t.id=`${t.id}-${Math.random().toString(36).slice(2,10)}`);let n=O.id?S.map(e=>e.id===O.id?{...t,enabled:e.enabled!==!1}:e):[...S,t];await I(n,O.id?`Rule updated`:`Rule created`)&&(A(null),g?.())},Me=e=>I(S.map(t=>t.id===e?{...t,enabled:t.enabled===!1}:t),`Rule toggled`),Ne=e=>{confirm(`Delete rule "${e}"?`)&&I(S.filter(t=>t.id!==e),`Rule deleted`)},[Pe,Fe]=(0,k.useState)(null),Le=async t=>{Fe(t);try{let n=await Ie(e,{ruleId:t,dryRun:!0,limit:r}),i=n.results.filter(e=>e.matched).length;if(!i){y({title:`Apply to existing items`,description:`No matches among ${n.processed} existing documents (conditions evaluate against each document's current tree placements). Raise the batch size in the toolbar to cover more.`});return}if(!confirm(`Rule "${t}" matches ${i} of the first ${n.processed} of ${n.total??n.processed} existing documents. Run its actions on all of them now?`))return;await qe(b,e,[t])}catch(e){y({title:`Backfill failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{Fe(null),ae(e)}},L=(e,t)=>A(n=>n&&{...n,[e]:t}),Re=e=>{A(e.build({backend:wt(F)})),j(!1),requestAnimationFrame(()=>ye.current?.scrollIntoView({behavior:`smooth`,block:`start`}))},ze=e=>{let n=ht(e);n?(A(n),j(!1),requestAnimationFrame(()=>ye.current?.scrollIntoView({behavior:`smooth`,block:`start`}))):t?.()},[R,z]=(0,k.useState)(null),Ve=(e,t)=>t.treeType===`context`?e:t.treeName===`directory`?`dir:${e}`:`${t.treeName}:${e}`,Ue=(e,t)=>{if(!R||!O||!e.length){z(null);return}if(R.target===`storeFolder`){let t=xe(e[0]);L(`actions`,O.actions.map((e,n)=>n===R.index?{...e,storeFolder:t?.rel||``,...t?.backend&&F.some(e=>e.address===t.backend)?{a:t.backend}:{}}:e))}else if(R.target===`condition`){let n=e.map(e=>Ve(e,t)),r=t.treeType===`context`&&O.actions.some(e=>e.kind===`store`);L(`conditions`,O.conditions.map((e,t)=>t===R.index?{...e,...r?{field:`eventPathExact`}:{},value:n.join(` | `)}:e))}else{let n=e.map(e=>Ve(e,t));L(`actions`,O.actions.map((e,t)=>t===R.index?e.kind===`download`?{...e,b:n.join(`, `)}:{...e,a:n.join(`, `)}:e))}z(null)},B=(e,t,n=`Browse…`)=>(0,W.jsxs)(w,{type:`button`,size:`sm`,variant:`outline`,className:`h-10 shrink-0 px-3`,title:n,onClick:()=>z({target:e,index:t}),children:[(0,W.jsx)(s,{className:`h-4 w-4 sm:mr-1.5`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`Browse`})]}),Ge=ft(O?.conditions||[]),V=!!O?.conditions.some(e=>[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&e.value.trim()),Ke=e=>`${e.address}${e.address===`workspace:data`?` — managed blob store (default)`:e.address===`workspace:home`?` — workspace home folder`:e.driver?` — ${e.driver}`:``}`,H=(e,t,n,r=`workspace:home`)=>F.length?(0,W.jsxs)(`select`,{className:X,value:e,onChange:e=>t(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:n}),F.map(e=>(0,W.jsx)(`option`,{value:e.address,children:Ke(e)},e.address)),e&&!F.some(t=>t.address===e)&&(0,W.jsx)(`option`,{value:e,children:e})]}):(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:r,value:e,onChange:e=>t(e.target.value)}),Je=S.filter(xt),U=S.filter(e=>!xt(e)),Xe=({rule:e})=>{let t=e.enabled!==!1,r=ht(e)!==null,i=E[e.id],a=at(e.then?.[0]?.action||`link`),o=be(e);return(0,W.jsxs)(`div`,{className:C(`rule-card rounded-xl border bg-card p-4 transition-opacity`,!t&&`opacity-60`),children:[(0,W.jsx)(kt,{icon:a.icon,tone:a.tone}),(0,W.jsxs)(`div`,{className:`rule-card-content min-w-0 space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold leading-6`,children:e.description||e.id}),e.approval===!0&&(0,W.jsx)(`span`,{className:`rounded-full bg-warning/15 px-2 py-0.5 text-xs font-medium text-warning`,children:`needs approval`}),e.cascade===!0&&(0,W.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:`incl. automation-created`}),!r&&(0,W.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,title:`This rule uses matchers the builder cannot show; edit it as JSON.`,children:`JSON only`})]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_t(e,Oe)}),(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-sm`,children:[(0,W.jsx)(v,{className:`mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,W.jsx)(`span`,{children:bt(e)})]}),o.length>0&&(0,W.jsx)(`p`,{className:`truncate font-mono text-xs text-muted-foreground`,title:o.join(` | `),children:o.join(` | `)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?(0,W.jsxs)(`button`,{type:`button`,className:C(`text-left underline-offset-2 hover:underline`,i.last.status===`error`&&`text-destructive`,!n&&`cursor-default hover:no-underline`),title:n?`Show this rule's run log`:i.last.error||i.last.skipReason||``,onClick:()=>n?.(e.id),children:[`ran `,i.count,`×`,i.errors?` (${i.errors} failed)`:``,` · last `,i.last.status,` `,Ct(i.last.ts)]}):`not run yet`})]}),(0,W.jsxs)(`div`,{className:`rule-card-actions`,children:[(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,disabled:M,title:t?`Enabled — click to pause`:`Paused — click to enable`,onClick:()=>Me(e.id),className:C(`mr-1 inline-flex h-6 w-11 items-center rounded-full p-0.5 transition-colors`,t?`bg-primary`:`bg-muted-foreground/30`),children:(0,W.jsx)(`span`,{className:C(`h-5 w-5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-5`)})}),(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:e.when.eventPathExact===void 0?`Apply this rule to existing items (dry-run first)`:`Requires an original insert/link event. Current folder membership cannot reconstruct its destination.`,disabled:Pe!==null||e.when.eventPathExact!==void 0,onClick:()=>Le(e.id),children:[Pe===e.id?(0,W.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,W.jsx)(l,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Apply`})]}),(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5`,title:r?`Edit rule`:`Edit as JSON`,onClick:()=>ze(e),children:[r?(0,W.jsx)(te,{className:`h-4 w-4`}):(0,W.jsx)(h,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`rule-card-action-label ml-1.5`,children:`Edit`})]}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`h-9 px-2.5 text-destructive hover:text-destructive`,title:`Delete rule`,onClick:()=>Ne(e.id),children:(0,W.jsx)(f,{className:`h-4 w-4`})})]})]})},Ze=(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`h3`,{className:`text-base font-semibold`,children:`What should happen automatically?`}),fe&&(0,W.jsxs)(w,{size:`sm`,variant:`ghost`,onClick:()=>j(!1),children:[(0,W.jsx)(c,{className:`mr-1 h-4 w-4`}),` Close`]})]}),(0,W.jsx)(`div`,{className:`grid min-w-0 grid-cols-[repeat(auto-fill,minmax(min(100%,17rem),1fr))] gap-3`,children:dt.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>Re(e),className:`flex min-w-0 items-start gap-3 rounded-xl border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent/40`,children:[(0,W.jsx)(kt,{icon:e.icon,tone:e.tone,size:`lg`}),(0,W.jsxs)(`span`,{className:`min-w-0`,children:[(0,W.jsx)(`span`,{className:`block text-base font-semibold leading-6`,children:e.title}),(0,W.jsx)(`span`,{className:`mt-1 block break-words text-sm leading-relaxed text-muted-foreground`,children:e.blurb})]})]},e.id))})]});return(0,W.jsxs)(`div`,{className:`rule-builder min-w-0 space-y-5`,children:[!m&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-[1_1_20rem]`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Rules`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Rules run automatically as items arrive or get filed — no code needed. Stored in`,` `,(0,W.jsx)(`span`,{className:`font-mono`,children:`rules.json`}),` in the workspace git.`]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[t&&(0,W.jsxs)(w,{variant:`ghost`,onClick:t,title:`Edit rules.json directly`,children:[(0,W.jsx)(h,{className:`mr-1.5 h-4 w-4`}),` JSON`]}),(0,W.jsxs)(w,{onClick:()=>{A(null),j(!0)},disabled:fe,children:[(0,W.jsx)(u,{className:`mr-1.5 h-4 w-4`}),` New rule`]})]})]}),fe&&!O&&Ze,O&&(0,W.jsxs)(`div`,{ref:ye,className:`scroll-mt-4 space-y-6 rounded-xl border bg-card p-4 sm:p-6`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`h3`,{className:`text-lg font-semibold`,children:O.id?`Edit rule`:`New rule`}),(0,W.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>A(null),children:[(0,W.jsx)(c,{className:`mr-1 h-4 w-4`}),` Cancel`]})]}),(0,W.jsx)(Q,{label:`Name`,hint:`Shown in the list and the run log.`,children:(0,W.jsx)(T,{className:`h-11 text-base`,placeholder:`Keep UI designs in Projects/Canvas/UI`,value:O.description,onChange:e=>L(`description`,e.target.value)})}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsx)(Ot,{step:1,title:`When…`,hint:`What the rule reacts to. All conditions must match; repeat a condition for either/or.`}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-[minmax(0,220px)_1fr]`,children:[(0,W.jsx)(Q,{label:`Item`,children:(0,W.jsxs)(`select`,{className:X,value:O.schema,onChange:e=>L(`schema`,e.target.value),children:[Oe.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value)),O.schema&&!Oe.some(e=>e.value===O.schema)&&(0,W.jsx)(`option`,{value:O.schema,children:O.schema.replace(/^data\/schema\//,``)})]})}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Event `,(0,W.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(any of)`})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:et.map(e=>{let t=O.events.includes(e.value);return(0,W.jsx)(Dt,{active:t,title:e.hint,onClick:()=>{let n=t?O.events.filter(t=>t!==e.value):[...O.events,e.value];n.length&&L(`events`,n)},children:e.label},e.value)})})]})]}),O.conditions.length>0&&(0,W.jsx)(`div`,{className:`space-y-2`,children:O.conditions.map((e,t)=>{let n=tt.find(t=>t.key===e.field);return(0,W.jsxs)(`div`,{className:`grid grid-cols-[2.25rem_1fr_auto] items-center gap-2 sm:grid-cols-[2.25rem_minmax(0,240px)_1fr_auto]`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,title:`Same condition again = either may match (OR); different conditions must all match (AND)`,children:O.conditions.slice(0,t).some(t=>rt(t.field)===rt(e.field))?`or`:`and`}),(0,W.jsx)(`select`,{className:X,value:e.field,onChange:e=>L(`conditions`,O.conditions.map((n,r)=>r===t?{...n,field:e.target.value}:n)),children:tt.map(e=>(0,W.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,W.jsxs)(`div`,{className:`order-4 col-span-3 flex gap-2 sm:order-3 sm:col-span-1`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:n?.hint,value:e.value,onChange:e=>L(`conditions`,O.conditions.map((n,r)=>r===t?{...n,value:e.target.value}:n))}),[`path`,`pathExact`,`eventPathExact`].includes(e.field)&&B(`condition`,t,`Browse the workspace trees`)]}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`order-3 h-10 w-10 p-0 text-muted-foreground sm:order-4`,title:`Remove condition`,onClick:()=>L(`conditions`,O.conditions.filter((e,n)=>n!==t)),children:(0,W.jsx)(c,{className:`h-4 w-4`})})]},t)})}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,W.jsxs)(w,{size:`sm`,variant:`outline`,onClick:()=>L(`conditions`,[...O.conditions,{field:O.schema===`email`?`from`:`path`,value:``}]),children:[(0,W.jsx)(u,{className:`mr-1 h-4 w-4`}),` Add condition`]}),(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Contains matches literal text. Regex is case-insensitive: enter the pattern without /…/ delimiters; | stays part of the expression. For other filters, separate alternatives with `,(0,W.jsx)(`span`,{className:`font-mono`,children:`|`}),`, e.g. `,(0,W.jsx)(`span`,{className:`font-mono`,children:`image/* | video/*`}),`.`]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsx)(Ot,{step:2,title:`Then…`,hint:`Actions run in order. The item keeps its id, tags and folders unless an action says otherwise.`}),O.actions.map((t,n)=>{let r=e=>L(`actions`,O.actions.map((t,r)=>r===n?{...t,...e}:t)),i=F.find(e=>e.address===t.a),o=i?.capabilities?.paths===!0,s=Ge&&o,l=at(t.kind),u=n=>(0,W.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-dashed p-3`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium`,children:[`What to do with the `,n]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Save as a note at`,hint:`Context path by default, dir:/path for the directory tree.`,children:(0,W.jsx)(de,{inputClassName:Z,placeholder:`/notes/summaries (optional)`,value:t.notePath,onChange:e=>r({notePath:e}),fixedWorkspaceName:e,pickerTitle:`Save note under…`,onPickTarget:(e,t)=>r({notePath:t.treeType===`directory`?`dir:${e}`:e})})}),t.notePath.trim()&&(0,W.jsx)(Q,{label:`Note title`,children:(0,W.jsx)(T,{className:Z,placeholder:`Summary: {{doc.data.subject}}`,value:t.noteTitle,onChange:e=>r({noteTitle:e.target.value})})}),(0,W.jsx)(Q,{label:`Save as a file at`,hint:`Relative path under the workspace home folder or in the data blob store.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`logs/agent.log (optional)`,value:t.filePath,onChange:e=>r({filePath:e.target.value})})}),t.filePath.trim()&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Q,{label:`File lives in`,children:(0,W.jsxs)(`select`,{className:X,value:t.fileBackend,onChange:e=>r({fileBackend:e.target.value}),children:[(0,W.jsx)(`option`,{value:`home`,children:`the workspace home folder`}),(0,W.jsx)(`option`,{value:`data`,children:`the data blob store`})]})}),(0,W.jsx)(Q,{label:`Also file the saved file under`,hint:`Index it as a document at this tree path.`,children:(0,W.jsx)(de,{inputClassName:Z,placeholder:`/path (optional)`,value:t.fileInsert,onChange:e=>r({fileInsert:e}),fixedWorkspaceName:e,tabs:[`context`],pickerTitle:`File under…`,onPickTarget:e=>r({fileInsert:e})})})]})]}),(0,W.jsx)($,{checked:t.notifyReply,onChange:e=>r({notifyReply:e}),label:`Send me a notification with the result`})]}),d=Y(O.conditions),f=t.kind===`store`&&t.a&&(!t.recursive||s)?pt(t,O.conditions,i):null,p=t.kind===`extractAttachments`&&t.a?We(t.a,t.storeFolder,t.attachmentPath):null;return(0,W.jsxs)(`div`,{className:`space-y-4 rounded-xl border bg-background p-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(kt,{icon:l.icon,tone:l.tone}),(0,W.jsx)(`select`,{className:C(X,`flex-1 font-medium`),value:t.kind,onChange:e=>r(K(e.target.value)),children:it.map(e=>(0,W.jsx)(`option`,{value:e.key,children:e.label},e.key))}),(0,W.jsx)(w,{size:`sm`,variant:`ghost`,className:`h-10 w-10 shrink-0 p-0 text-muted-foreground`,title:`Remove action`,disabled:O.actions.length===1,onClick:()=>L(`actions`,O.actions.filter((e,t)=>t!==n)),children:(0,W.jsx)(c,{className:`h-4 w-4`})})]}),(t.kind===`link`||t.kind===`unlink`)&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:t.kind===`link`?`Folder(s)`:`Remove from folder(s)`,hint:`Context-tree path by default; dir:/path for the directory tree. Comma-separate several.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:t.kind===`link`?`/work/urgent or dir:/projects/x`:`/inbox or dir:/staging`,value:t.a,onChange:e=>r({a:e.target.value})}),B(`action`,n)]})}),t.kind===`link`&&(0,W.jsx)(Q,{label:`Tags`,hint:`Optional, comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`custom/design, ui`,value:t.b,onChange:e=>r({b:e.target.value})})}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:V?`The part of the item's path below the "is under the folder" prefix is appended to the target: …/foo/a/b → target/a/b.`:`Needs an "is under the folder" condition to know where sub-folders start.`,disabled:!V})]}),t.kind===`moveMessage`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(Q,{label:`Mail folder`,hint:`The folder on the email's own IMAP account, with / between levels (works for servers that use . too). {{YYYY}}, {{MM}}, {{DD}} = the email's date.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`INBOX/Accounting/{{YYYY}}/Expenses`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Moves the message on the mail server, like dragging it in a mail client. Put this after Extract attachments so the files are copied first. The folder must already exist on the server; subscribe to it in the mailbox settings to see the moved mail in Canvas.`})]}),t.kind===`tag`&&(0,W.jsx)(Q,{label:`Tags`,hint:`Comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`urgent, follow-up`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`store`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Storage backend`,hint:`Where the file's bytes should live. Only writable backends are listed.`,children:H(t.a,e=>r({a:e}),`pick a backend…`)}),(0,W.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which the path will be recreated. Leave empty to use the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Projects/Canvas/UI`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`File name`,children:(0,W.jsx)(`select`,{className:X,value:t.storeName,onChange:e=>r({storeName:e.target.value}),children:ct.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,W.jsx)(Q,{label:`Move or copy`,hint:t.storeMode===`move`?`Remove only the selected source copy after the destination is safely stored.`:`Preserve every existing copy.`,children:(0,W.jsx)(Et,{value:t.storeMode,onChange:e=>r({storeMode:e}),options:[{value:`copy`,label:`Copy`},{value:`move`,label:`Move`}]})}),t.storeMode===`move`&&(0,W.jsx)(Q,{className:`sm:col-span-2`,label:`Move bytes from (required)`,hint:`Context membership does not identify a source copy. If the file is absent here, nothing is moved. Multiple locations on this backend make the move ambiguous; use copy.`,children:H(t.storeFrom,e=>r({storeFrom:e}),`choose a source backend…`,`workspace:data`)}),t.storeName===`custom`&&(0,W.jsx)(Q,{className:`sm:col-span-2`,label:`Name template`,hint:`Tokens: {{YYYY}} {{MM}} {{DD}} {{HH}} {{mm}} {{ss}} (photo capture time when present), {{ext}} {{basename}} {{filename}} {{title}} {{id}}, plus {{doc.…}} fields. Slashes create sub-folders.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`{{YYYY}}-{{MM}}-{{DD}} {{title}}{{ext}}`,value:t.b,onChange:e=>r({b:e.target.value})})})]}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:d===null?`Recreate sub-folder path in destination`:`Recreate directory path in destination`,hint:o?Ge?d===null?`The path below the source folder is appended beneath the destination root: …/UI/mobile → Root/mobile. Missing destination folders are created.`:`Only inserts or links directly into ctx:${d} trigger this rule. Its full path is appended beneath the destination root; descendant inserts do not match.`:`For Context, choose one folder with “is inserted / linked directly into”. Directory and Backends sources can include sub-folders.`:`Choose a destination that reports support for folder paths. Content-addressed blob stores cannot recreate sub-folder paths.`,disabled:!s&&!t.recursive}),f&&(0,W.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,W.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[f.root,`/`]})]}),t.recursive&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[f.recreated||`(root)`,`/`]})]}),(0,W.jsx)(`p`,{className:`break-all font-mono`,children:f.result})]}),(0,W.jsxs)(`details`,{className:`group rounded-lg border`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer select-none items-center gap-2 px-3 py-2 text-sm font-medium`,children:[(0,W.jsx)(a,{className:`h-4 w-4 transition-transform group-open:rotate-180`}),` More options`]}),(0,W.jsxs)(`div`,{className:`grid gap-4 border-t p-3 sm:grid-cols-2`,children:[t.storeMode===`copy`&&(0,W.jsx)(Q,{label:`Copy bytes from`,hint:`Optional source restriction. Default: any readable copy outside the destination backend.`,children:H(t.storeFrom,e=>r({storeFrom:e}),`any readable source`,`workspace:data (optional)`)}),(0,W.jsx)(Q,{label:`If the name is already taken`,children:(0,W.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,W.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,W.jsx)(`option`,{value:`error`,children:`skip the file`}),(0,W.jsx)(`option`,{value:`overwrite`,children:`overwrite the existing file`})]})})]})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The item keeps its id and virtual tree memberships. A move removes the chosen physical source location from the backend tree.`})]}),t.kind===`extractAttachments`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Attachment types`,hint:`MIME types, comma-separated. application/pdf for PDFs, image/* for images, or * for all.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`application/pdf`,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,W.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional: invoice, faktura, or another literal filename fragment. Every selected attachment must also match its type.`,children:(0,W.jsx)(T,{className:Z,placeholder:`Any matching filename`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})}),(0,W.jsx)(Q,{label:`Storage backend`,hint:`Choose a writable backend that supports folder paths.`,children:H(t.a,e=>r({a:e}),`pick a backend…`)}),(0,W.jsx)(Q,{label:`Destination root folder`,hint:`Choose the folder beneath which date subfolders will be created. Leave empty to use the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Accounting`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`Sub-folder path template`,hint:`Appended beneath the root folder. {{YYYY}} = year, {{MM}} = month, {{DD}} = day of the email. Leave empty to file directly in the root folder.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`No subfolders`,value:t.attachmentPath,onChange:e=>r({attachmentPath:e.target.value})})}),(0,W.jsx)(Q,{label:`If the attachment name is already taken`,children:(0,W.jsxs)(`select`,{className:X,value:t.storeConflict,onChange:e=>r({storeConflict:e.target.value}),children:[(0,W.jsx)(`option`,{value:`rename`,children:`add -1, -2, … to the name`}),(0,W.jsx)(`option`,{value:`error`,children:`skip the file and report the conflict`})]})})]}),!o&&(0,W.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:`This destination has not reported support for folder paths. Select a supported backend before saving.`}),p&&(0,W.jsxs)(`div`,{className:`space-y-1.5 rounded-lg bg-muted/60 px-3 py-3 text-sm`,"aria-live":`polite`,children:[(0,W.jsx)(`p`,{className:`font-medium`,children:`Destination preview`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Example email dated `,p.date,`. Each email supplies its own date.`]}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Root folder: `,(0,W.jsxs)(`span`,{className:`break-all font-mono`,children:[p.root,`/`]})]}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Path added beneath it: `,(0,W.jsx)(`span`,{className:`break-all font-mono`,children:p.added?`${p.added}/`:`(none)`})]}),(0,W.jsx)(`p`,{className:`break-all font-mono`,children:p.result})]}),(0,W.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Off by default, so signature images and embedded resources are excluded.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Copies matching attachments and keeps the email and its original files. Missing folders are created on the backend. Dates use the email's sent date (received/content date, then creation date if absent), in the server's timezone. This does not read the invoice date from the PDF.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Use Apply on the saved rule to process existing mail within the selected batch size. Add a subject or attachment filename condition if you need to distinguish invoices from other PDFs.`})]}),t.kind===`download`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Download`,hint:st.find(e=>e.value===t.dlKind)?.hint,children:(0,W.jsx)(`select`,{className:X,value:t.dlKind,onChange:e=>r({dlKind:e.target.value}),children:st.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),t.dlKind===`website`?(0,W.jsx)(Q,{label:`Mirror depth`,hint:`How many link hops to follow on the same site (1–5).`,children:(0,W.jsx)(T,{type:`number`,min:1,max:5,className:C(Z,`sm:max-w-32`),value:t.dlDepth,onChange:e=>r({dlDepth:e.target.value})})}):(0,W.jsx)(`div`,{className:`hidden sm:block`}),(0,W.jsx)(Q,{label:`Storage backend`,hint:`Where the downloaded file's bytes should live.`,children:H(t.a,e=>r({a:e}),`workspace:home (default)`)}),(0,W.jsx)(Q,{label:`Folder on that backend`,hint:`Relative to the backend root.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`Downloads`,value:t.storeFolder,onChange:e=>r({storeFolder:e.target.value})}),B(`storeFolder`,n,`Browse storage backends`)]})}),(0,W.jsx)(Q,{label:`File the download under`,hint:`Leave empty to file it in the same folder(s) as the link. Comma-separate several.`,children:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`same folders as the link`,value:t.b,onChange:e=>r({b:e.target.value})}),B(`action`,n)]})}),(0,W.jsx)(Q,{label:`Tags for the download`,hint:`Optional, comma-separated.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono`),placeholder:`downloaded, custom/paper`,value:t.dlTags,onChange:e=>r({dlTags:e.target.value})})})]}),(0,W.jsx)($,{checked:t.recursive,onChange:e=>r({recursive:e}),label:`Recreate sub-folder path in destination`,hint:V?`A link filed under …/folder/a/b is downloaded into Folder/a/b.`:`Add an "is under the folder" condition to mirror sub-folders.`,disabled:!V}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`The link stays as it is; the download becomes a new file item next to it. Each link is downloaded once per rule. Videos need `,(0,W.jsx)(`span`,{className:`font-mono`,children:`yt-dlp`}),`, pages and websites `,(0,W.jsx)(`span`,{className:`font-mono`,children:`wget`}),` on the server.`]})]}),t.kind===`unstore`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Delete the file from`,children:H(t.a,e=>r({a:e}),`pick a backend…`,`workspace:data`)}),(0,W.jsx)(Q,{label:`…but only once it is also on`,hint:`Safety: the copy is dropped only after another backend holds the file.`,children:H(t.b,e=>r({b:e}),`anywhere else`,`workspace:home (optional)`)})]}),(0,W.jsx)($,{checked:t.keepLast,onChange:e=>r({keepLast:e}),label:`Never delete the last copy`,hint:`Off means the rule may delete the only remaining copy of a file. Leave it on unless you mean exactly that.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Deletes the stored bytes on that backend only — copies elsewhere and the item itself are kept.`})]}),t.kind===`sendFile`&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(Q,{label:`Files to send`,children:(0,W.jsxs)(`select`,{className:X,value:t.sendSource,onChange:e=>r({sendSource:e.target.value}),children:[(0,W.jsx)(`option`,{value:`document`,children:`The file that triggered this rule`}),(0,W.jsx)(`option`,{value:`attachments`,children:`Matching attachments from the email`}),(0,W.jsx)(`option`,{value:`download`,children:`Files from an earlier Download action`})]})}),t.sendSource===`attachments`&&(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:`Attachment types`,hint:`application/pdf for invoices; * for all files.`,children:(0,W.jsx)(T,{className:Z,value:t.attachmentMime,onChange:e=>r({attachmentMime:e.target.value})})}),(0,W.jsx)(Q,{label:`Attachment filename contains`,hint:`Optional literal filename fragment.`,children:(0,W.jsx)(T,{className:Z,placeholder:`invoice`,value:t.attachmentName,onChange:e=>r({attachmentName:e.target.value})})})]}),t.sendSource===`attachments`&&(0,W.jsx)($,{checked:t.includeInline,onChange:e=>r({includeInline:e}),label:`Include inline attachments`,hint:`Signature images are excluded by default.`}),(0,W.jsx)(Q,{label:`Sending account`,hint:`Enable sending for the account in Connected services.`,children:(0,W.jsxs)(`select`,{className:X,value:t.a?`${t.sendDriver}:${t.a}`:``,onChange:e=>{let t=he.find(t=>`${t.driver}:${t.address}`===e.target.value);t&&r({a:t.address,sendDriver:t.driver,b:``})},children:[(0,W.jsx)(`option`,{value:``,disabled:!0,children:`Choose email, WhatsApp or Slack…`}),t.a&&!he.some(e=>e.driver===t.sendDriver&&e.address===t.a)&&(0,W.jsxs)(`option`,{value:`${t.sendDriver}:${t.a}`,disabled:!0,children:[t.sendDriver,`: `,t.a,` (unavailable)`]}),he.map(e=>(0,W.jsxs)(`option`,{value:`${e.driver}:${e.address}`,disabled:!e.canSend,children:[e.driver===`imap`?`Email (SMTP)`:e.driver===`whatsapp`?`WhatsApp`:`Slack`,` · `,e.from||e.address,e.canSend?``:` — sending disabled`]},`${e.driver}:${e.address}`))]})}),_e&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,role:`status`,children:_e}),(0,W.jsx)(Q,{label:t.sendDriver===`imap`?`Destination email address`:`Destination conversation`,hint:t.sendDriver===`imap`?`The accounting ingestion address; separate multiple recipients with commas.`:t.sendDriver===`slack`?`A configured Slack channel ID or name. The account needs files:write permission.`:`A configured WhatsApp chat ID, e.g. 421…@s.whatsapp.net or …@g.us.`,children:(0,W.jsx)(T,{className:Z,value:t.b,placeholder:t.sendDriver===`imap`?`invoices@accounting-firm.example`:t.sendDriver===`slack`?`C0123456789`:`421…@s.whatsapp.net`,onChange:e=>r({b:e.target.value})})}),t.sendDriver===`imap`&&(0,W.jsx)(Q,{label:`Email subject`,hint:`{{file.name}} inserts the attachment filename.`,children:(0,W.jsx)(T,{className:Z,value:t.sendSubject,onChange:e=>r({sendSubject:e.target.value})})}),(0,W.jsx)(Q,{label:t.sendDriver===`imap`?`Email body (optional)`:`Message / caption (optional)`,hint:`Templates: {{file.name}}, {{doc.data.subject}}, {{doc.data.title}}.`,children:(0,W.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border bg-background p-3 text-sm`,value:t.sendMessage,onChange:e=>r({sendMessage:e.target.value})})}),(0,W.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-3 text-sm`,"aria-label":`File delivery preview`,children:[t.sendSource===`attachments`?`Each matching email attachment`:t.sendSource===`download`?`Each downloaded file`:`The triggering file`,` → `,t.sendDriver===`imap`?`email attachment`:t.sendDriver===`slack`?`Slack file upload`:`WhatsApp document`,` → `,t.b||`choose a destination`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sends each file in a separate message and keeps the original. Maximum 18 MB per file. Replaying this rule does not resend the same file version to the same destination. Unconfirmed deliveries are recorded for review, not retried automatically.`}),t.sendSource===`document`&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`For files created by another automation, enable this rule’s option to also run on automation events.`})]}),t.kind===`notify`&&(0,W.jsx)(Q,{label:`Notification`,hint:`Notifies you through your bound channel, or in Canvas. Templates: {{doc.data.subject}}, {{doc.data.from}}, {{doc.data.title}}…`,children:(0,W.jsx)(T,{className:Z,placeholder:`New mail from {{doc.data.from}}: {{doc.data.subject}}`,value:t.a,onChange:e=>r({a:e.target.value})})}),t.kind===`delete`&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Removes the item from the Canvas index. Files, blobs and mail on storage backends stay untouched.`}),t.kind===`destroy`&&(0,W.jsx)(`p`,{className:`rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:`⚠ Irreversible: deletes the stored bytes too (blobs, workspace files, mail on the server), then removes the item from the index.`}),t.kind===`agent`&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:`Agent`,hint:`The agent's slug.`,children:(0,W.jsx)(T,{className:C(Z,`font-mono sm:max-w-xs`),placeholder:`assistant`,value:t.a,onChange:e=>r({a:e.target.value})})}),(0,W.jsx)(Q,{label:`Prompt`,hint:`Templates use indexed fields: {{doc.id}}, {{doc.data.subject}}, {{doc.data.bodyPreview}} (emails), {{doc.data.url}}… Ask the agent to use canvas_doc_get_by_id for full email content. Objects are inserted as JSON.`,children:(0,W.jsx)(`textarea`,{className:`min-h-28 w-full rounded-md border bg-background p-3 text-sm outline-none focus:ring-2 focus:ring-ring`,placeholder:`Read email #{{doc.id}} in full with canvas_doc_get_by_id and summarize it in plain markdown.
|
|
4
|
+
|
|
5
|
+
Subject: {{doc.data.subject}}
|
|
6
|
+
Preview: {{doc.data.bodyPreview}}`,value:t.b,onChange:e=>r({b:e.target.value})})}),u(`reply`)]}),t.kind===`script`&&(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(Q,{label:`Script`,hint:`From the Scripts section of this workspace.`,children:pe.length?(0,W.jsxs)(`select`,{className:C(X,`font-mono sm:max-w-md`),value:t.a,onChange:e=>r({a:e.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`pick a script…`}),pe.map(e=>(0,W.jsx)(`option`,{value:`scripts/${e}`,children:e},e))]}):(0,W.jsx)(T,{className:C(Z,`font-mono sm:max-w-md`),placeholder:`scripts/my-script.sh`,value:t.a,onChange:e=>r({a:e.target.value})})}),u(`output`)]})]},n)}),(0,W.jsxs)(w,{size:`sm`,variant:`outline`,onClick:()=>L(`actions`,[...O.actions,K(`tag`)]),children:[(0,W.jsx)(u,{className:`mr-1 h-4 w-4`}),` Add another action`]})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsx)(Ot,{step:3,title:`Options`}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)($,{checked:O.approval,onChange:e=>L(`approval`,e),label:`Ask me before running`,hint:`Actions are held in the Pending queue for review — approve (optionally amended) or decline — instead of running automatically.`}),(0,W.jsx)($,{checked:O.cascade,onChange:e=>L(`cascade`,e),label:`Also react to items created by automation`,hint:`Off by default so rules, hooks and agents cannot trigger each other in a loop. A server-side depth limit still stops runaway chains.`})]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2 border-t pt-4`,children:[(0,W.jsxs)(w,{className:`h-10 px-5`,onClick:je,disabled:M||se,children:[M?(0,W.jsx)(ee,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,W.jsx)(i,{className:`mr-1.5 h-4 w-4`}),` `,O.id?`Save changes`:`Create rule`]}),(0,W.jsx)(w,{className:`h-10`,variant:`outline`,onClick:()=>{A(null),_?.()},children:`Cancel`})]})]}),R&&(0,W.jsx)(ue,{onClose:()=>z(null),children:(0,W.jsx)(ie,{sizeClassName:`h-full w-[380px] max-w-[90vw] max-md:w-full`,fixedWorkspaceName:e,multiple:R.target!==`storeFolder`&&!(R.target===`condition`&&O?.actions.some(e=>e.kind===`store`)),tabs:R.target===`condition`?[`context`,`directory`,`backends`]:R.target===`storeFolder`?[`backends`]:[`context`,`directory`],title:R.target===`condition`?`Choose source folder…`:R.target===`storeFolder`?`Store files under…`:`File into…`,confirmLabel:R.target===`storeFolder`?`Use folder`:`Use path`,onConfirm:Ue,onClose:()=>z(null)})}),!m&&(se?(0,W.jsx)(`p`,{className:`rounded-xl border p-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):S.length===0?!fe&&!O&&(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`rounded-xl border border-dashed p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-base font-medium`,children:`No rules yet`}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Pick a starting point below, or right-click a folder in the tree and choose “Create rule…”.`})]}),Ze]}):(0,W.jsxs)(`div`,{className:`space-y-6`,children:[Je.length>0&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-sm text-muted-foreground`,children:[(0,W.jsxs)(`h3`,{className:`flex items-center gap-2 font-semibold uppercase tracking-wide`,children:[(0,W.jsx)(o,{className:`h-4 w-4 shrink-0`}),` Folder & storage rules`]}),(0,W.jsx)(`p`,{children:`Right-click a folder in the tree to add one`})]}),(0,W.jsx)(`div`,{className:`space-y-3`,children:Je.map(e=>(0,W.jsx)(Xe,{rule:e},e.id))})]}),U.length>0&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[Je.length>0&&(0,W.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,W.jsx)(x,{className:`h-4 w-4`}),` Other rules`]}),(0,W.jsx)(`div`,{className:`space-y-3`,children:U.map(e=>(0,W.jsx)(Xe,{rule:e},e.id))})]})]}))]})}function jt(e,t){let n=t.split(`/`).filter(Boolean);if(e!==`backends`||n[0]!==`Trash`)return null;try{return{backend:n[1]?decodeURIComponent(n[1]):null,prefix:n.slice(2).join(`/`)}}catch{return null}}function Mt(e,t=``){return`/Trash${e?`/${encodeURIComponent(e)}`:``}${t?`/${t}`:``}`}function Nt(e,t=``){let n=new Map,r=[],i=t?`${t}/`:``;for(let t of e){if(!t.key.startsWith(i))continue;let e=t.key.slice(i.length);if(!e)continue;let a=e.indexOf(`/`);if(a>=0){let r=e.slice(0,a),o=i+r,s=n.get(o)??{id:`folder:${o}`,name:r,key:o,directory:!0,navigable:!0,items:[]};s.items.push(t),n.set(o,s)}else r.push({id:t.id,name:e,key:t.key,directory:t.type===`directory`,navigable:!1,items:[t]})}return[...n.values(),...r].sort((e,t)=>Number(t.directory)-Number(e.directory)||e.name.localeCompare(t.name)||t.items[0].deletedAt-e.items[0].deletedAt||e.id.localeCompare(t.id))}var Pt=(e,t)=>`${ne.workspaces}/${encodeURIComponent(e)}/backends/file/${encodeURIComponent(t)}/trash`;async function Ft(e,t){let n=[],r=new Set,i=null,a=null;do{let o=new URLSearchParams({limit:`1000`,...i?{cursor:i}:{}}),s=await E.get(`${Pt(e,t)}?${o}`);if(n.push(...s.items),a=s.retention?.days??null,i=s.cursor,i&&r.has(i))throw Error(`Trash listing returned a repeated cursor`);i&&r.add(i)}while(i);return{items:n,days:a}}function It(e,t,n){return Rt(e,t,n,`restore`)}function Lt(e,t,n){return Rt(e,t,n,`discard`)}async function Rt(e,t,n,r){let i=[...new Set(n)],a=[];try{for(let n=0;n<i.length;n+=100){let o=await E.post(`${Pt(e,t)}/${r}`,{ids:i.slice(n,n+100)});a.push(...o.results)}return a}finally{O(e,`backends`),window.dispatchEvent(new CustomEvent(`workspace:tree:refresh`,{detail:{workspaceName:e,treeName:`backends`}})),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:e}})),window.dispatchEvent(new CustomEvent(`workspace:trash:refresh`,{detail:{workspaceName:e,backend:t}}))}}async function zt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`)).sort((e,t)=>t.deletedAt-e.deletedAt),a=await It(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} restored; ${o.length} remain in Trash. Existing paths were kept.`)}function Bt(e,t){if(!t.length)return!1;let n=[...new Set(t.map(e=>e.key))],r=n.slice(0,5).join(`
|
|
7
|
+
`)+(n.length>5?`\n…and ${n.length-5} more paths`:``);return window.confirm(`Permanently delete ${t.length} Trash item(s) from ${e}?\n\n${r}\n\nDeleted folders include all their contents. This cannot be undone. Files currently at the original paths are kept.`)}async function Vt(e,t){let n=jt(`backends`,t);if(!n?.backend)return;let{items:r}=await Ft(e,n.backend),i=r.filter(e=>!n.prefix||e.key===n.prefix||e.key.startsWith(`${n.prefix}/`));if(!Bt(n.backend,i))return;let a=await Lt(e,n.backend,i.map(e=>e.id)),o=a.filter(e=>!e.ok);if(o.length)throw Error(`${a.length-o.length} deleted; ${o.length} remain in Trash. ${o[0].message||o[0].reason||`Please retry.`}`)}var Ht=new Map;function Ut(e,t,n,r,i,a){let o=JSON.stringify([t,n,r,a]),s=Ht.get(o);if(s)return s;let c=(async()=>{let o=e({title:`Resyncing…`,description:r});try{for(a?await ce(t,n,r,a):await se(t,n,r);;){let e=await ae(t,n,r);i?.(e);let s=a?e.containers?.find(e=>e.name===a):void 0;if(a?s?.status!==`syncing`:!e.resyncing&&e.status!==`syncing`){let i=s?s.lastError:e.lastError;if(i)throw Error(i);o.done({title:e.resyncCancelledAt?`Resync stopped`:`Resync complete`,description:`${r}${n!==`imap`&&e.progress?` · ${e.progress.scanned} files scanned`:``}`}),window.dispatchEvent(new CustomEvent(`workspace:documents:refresh`,{detail:{workspaceName:t,treeName:`backends`}}));return}let c=n===`imap`?void 0:e.progress;o.update({title:`Resyncing…`,description:`${r}${c?` · ${c.scanned}${c.total==null?``:` / ${c.total}`} files scanned`:``}`}),await new Promise(e=>setTimeout(e,2e3))}}catch(e){throw o.fail({title:`Resync needs attention`,description:`${r}: ${e instanceof Error?e.message:String(e)}`,variant:`destructive`}),e}})();return Ht.set(o,c),c.finally(()=>{Ht.get(o)===c&&Ht.delete(o)}).catch(()=>{}),c}export{ke as A,R as B,Ce as C,j as D,Ne as E,fe as F,Pe as H,De as I,Ae as L,Fe as M,he as N,Be as O,me as P,z as R,Oe as S,Ve as T,_e as U,M as V,xe as W,qe as _,Ft as a,Ie as b,jt as c,At as d,Qe as f,Je as g,Ze as h,Vt as i,ve as j,Te as k,Mt as l,Ye as m,Bt as n,It as o,Xe as p,Lt as r,zt as s,Ut as t,Nt as u,I as v,N as w,Me as x,Ue as y,Se as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Br as r,Ct as i,G as a,It as o,L as s,Lt as c,Nt as l,St as u,Tr as d,Ut as f,X as p,Yr as m,ct as h,it as g,mn as _,mt as v,ti as y,tt as b,vn as x,yn as S}from"./ui-Byg1cZDr.js";import{t as C}from"./utils-2pl1SbIp.js";import{Gn as w,Pn as T,q as E}from"./workspace-DvxC7pw1.js";import{t as D}from"./TodosWidget-BIYqPXUp.js";import{d as O,o as k,u as ee}from"./ObjectPropertiesCard-ChvWbOpZ.js";import{h as te,s as ne,t as re,u as ie}from"./document-list-SsF3jmuq.js";import{n as ae}from"./use-toolbox-Ck_cLGgf.js";import{t as oe}from"./useToastHelpers-CRrpIIdY.js";import{n as A}from"./color-DFEH4BfK.js";import{t as se}from"./DocumentIcon-x299QNu_.js";import{t as ce}from"./registry-DTWAywyJ.js";import{t as le}from"./FileForm-DhQhVnoi.js";import{t as ue}from"./applet-target-ChiiXVdC.js";var j=e(n(),1),M=t();function de({target:e,children:t}){let[n,r]=(0,j.useState)([]),i=(0,j.useRef)(!1),[a,o]=(0,j.useState)(!1),[s,c]=(0,j.useState)(!1),[l,u]=(0,j.useState)(null),{showErrorToast:d}=oe();return(0,M.jsxs)(`div`,{className:`relative flex flex-col h-full min-h-0 bg-background ${a?`ring-2 ring-inset ring-primary`:``}`,onDragOverCapture:t=>{s||!e||!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i.current?`none`:`copy`,o(!i.current))},onDragLeaveCapture:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDropCapture:t=>{if(s||!e||!Array.from(t.dataTransfer.types).includes(`Files`))return;if(t.preventDefault(),t.stopPropagation(),o(!1),i.current){d(`Wait for the current upload to finish`);return}let n=Array.from(t.dataTransfer.files);if(!n.length){d(`Drop files rather than folders`);return}r(n),u(e),c(!0)},children:[t,a&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-30 flex items-center justify-center bg-background/80 text-sm font-medium`,children:[`Drop files to upload to `,e?.mode===`workspace`?e.path:`this context`]}),s&&(0,M.jsxs)(ie,{label:`Import files`,onClose:()=>{i.current||c(!1)},children:[(0,M.jsx)(`h2`,{className:`border-b px-4 py-3 text-sm font-medium`,children:`Import files`}),(0,M.jsx)(le,{target:l,initialFiles:n,onClose:()=>c(!1),onBusyChange:e=>{i.current=e}})]})]})}function fe({navigationTabs:e,navigationActions:t,onBack:n,accentColor:r,frameContent:s=!0,urlType:l,urlDisplay:u,contextPath:d,treeName:f,workspaceId:m,workspaceLabel:h,workspaceIcon:g,documentSchema:_,documents:b,isLoading:x,totalCount:C,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:me,disablePurgeDocuments:he,canvasInfo:F,isCanvasPinned:I,onTogglePinCanvas:L,onSaveAsCanvas:R,onShareCanvas:z,onUnshareCanvas:B,onDeleteCanvas:V,isSharingCanvas:H,isDeletingCanvas:U,isCanvasShared:W,isCanvasLocked:ge,backendSearchQueries:_e,onBackendSearch:G,onRemoveBackendQuery:K,serverSort:ve,onServerSortChange:ye,scope:be,onScopeChange:xe,canSaveChanges:Se,isSavingChanges:q,onSaveChanges:J,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,linkTree:Ee,children:Y,contentBanner:De,folders:Oe,onOpenFolder:ke}){let Ae=l===`canvas`,X=te(),{state:je,toggleView:Me,hasActiveFilters:Ne,openAddPicker:Pe}=ae(),Z=k(),[Fe,Q]=(0,j.useState)(``),$=JSON.stringify([m,f,d,_]),[Ie,Le]=(0,j.useState)($);Ie!==$&&(Le($),Q(``));let Re=(0,M.jsxs)(M.Fragment,{children:[t,R&&(0,M.jsx)(`button`,{type:`button`,onClick:R,title:`Save as canvas`,"aria-label":`Save as canvas`,className:`flex h-control-sm w-control-sm shrink-0 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent touch-target`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]});return(0,M.jsxs)(de,{target:N&&m?{mode:`workspace`,workspaceName:m,path:d,treeName:f||`context`,treeType:f===`directory`?`directory`:`context`}:null,children:[e&&!X&&(0,M.jsx)(O,{accentColor:r,children:e}),(0,M.jsxs)(`div`,{className:`canvas-surface-body${s&&!X?` is-framed`:``}`,children:[(0,M.jsx)(ee,{workspaceIcon:g,workspace:h||m||u.split(`://`)[0]||`Workspace`,actions:X&&e?(0,M.jsxs)(`details`,{className:`relative shrink-0`,"aria-label":`Canvas views`,children:[(0,M.jsx)(`summary`,{className:`cursor-pointer rounded-md border px-2 py-1 text-xs`,title:`Choose or manage content views`,children:`Views`}),(0,M.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-2 min-w-64 max-w-[80vw] rounded-md border bg-background p-2 shadow-lg`,children:e})]}):void 0,tree:f?`${f}${l.endsWith(`-layer`)?`:layer`:``}`:l.replace(`-layer`,``),path:d,accentColor:r,onBack:Z.location?Z.location.section===`view`?Z.close:()=>Z.update?.({section:`view`}):n,section:Z.location?`document/${Z.location.documentId}/${Z.location.section}`:void 0,onSection:Z.location?()=>Z.update?.({section:`view`}):void 0,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,onFilter:()=>Me(`tools`),filtersActive:Ne,filtersOpen:je.t1Open&&je.t1View===`tools`,onAdd:e=>Pe({modal:e.shiftKey,fresh:!0}),search:G||!Y?{workspaceId:m,queries:_e||[],onSearch:G??Q,localOnly:!G,onRemoveQuery:K,scope:be,onScopeChange:xe}:void 0,onDraftChange:Y?void 0:Q}),Ae&&F?(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b bg-muted/20 shrink-0 min-w-0`,children:[F.color&&(0,M.jsx)(`div`,{className:`w-1 h-6 rounded-full shrink-0`,style:{backgroundColor:F.color}}),(0,M.jsx)(S,{className:`w-4 h-4 shrink-0 text-primary`}),(0,M.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,M.jsx)(`span`,{className:`text-lg font-semibold leading-tight truncate`,children:F.label||u.split(`://`)[1]||`Canvas`}),F.description&&(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:F.description})]}),Se&&J&&(0,M.jsxs)(`button`,{type:`button`,onClick:J,disabled:q,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:`Save filters`,children:[(0,M.jsx)(i,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:q?`Saving...`:`Save filters`})]}),L&&(0,M.jsxs)(`button`,{type:`button`,onClick:L,"aria-pressed":!!I,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground`,title:I?`Unpin from home`:`Pin to home`,children:[I?(0,M.jsx)(c,{className:`w-3 h-3`}):(0,M.jsx)(o,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:I?`Unpin`:`Pin`})]}),z&&(0,M.jsxs)(`button`,{type:`button`,onClick:z,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:W?`Copy public link`:`Share canvas`,children:[(0,M.jsx)(v,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:H?`Sharing...`:W?`Copy link`:`Share`})]}),W&&B&&(0,M.jsxs)(`button`,{type:`button`,onClick:B,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(a,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:`Unshare`})]}),V&&(0,M.jsxs)(`button`,{type:`button`,onClick:V,disabled:U||ge&&!W,title:ge&&!W?`Unlock this canvas before deleting it`:`Delete canvas`,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(p,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:U?`Deleting…`:`Delete`})]})]})}):null,Y&&(R||t)&&(0,M.jsx)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1`,children:Re}),(0,M.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[De,Y||(0,M.jsx)(re,{readingPane:!0,externalSearchQuery:Fe,toolbarActions:Re,documents:_?b.filter(e=>e.schema===_):b,isLoading:x,folders:_?void 0:Oe,onOpenFolder:ke,contextPath:d,treeName:f,workspaceId:m,totalCount:C,viewMode:_?`card`:`table`,allowViewToggle:!0,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:_?void 0:me,disablePurgeDocuments:he,backendSearchQueries:_e,onBackendSearch:G,serverSort:ve,onServerSortChange:ye,onRemoveBackendQuery:K,scope:be,onScopeChange:xe,canSaveChanges:!Ae&&Se,isSavingChanges:q,onSaveChanges:J,linkTree:Ee},_??`documents`)]})]})]})}var N=[{id:`todos`,label:`Todo list`},{id:`todo-app`,label:`Todo App`},{id:`notes`,label:`Notes list`},{id:`notes-app`,label:`Notes App`},{id:`sketch`,label:`Sketch`},{id:`terminal`,label:`Terminal`}];function pe(e){return e?.kind===`app`&&e.app===`notes`?`data/schema/note`:void 0}var P={id:`default`,name:`All`,kind:`documents`};function me(){return[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}]}function he(e){let t=e?.views;if(!Array.isArray(t))return[P];let n=t.filter(e=>{let t=e;return!t||typeof t.id!=`string`||typeof t.name!=`string`?!1:t.kind===`documents`||t.kind===`columns`||t.kind===`app`&&(N.some(e=>e.id===t.app)||t.app===`filters`||t.app===`lens`)});return n.length>0?n:[P]}var F={todos:_,"todo-app":_,notes:b,"notes-app":b,filters:h,sketch:g,Brush:m,terminal:g,lens:u};function I({views:e,activeId:t,onSelect:n,onSave:r,readOnly:i=!1,className:a,accentColor:o,onOpenToSide:c}){let[u,p]=(0,j.useState)(null),[m,h]=(0,j.useState)(``),[g,_]=(0,j.useState)(!1),[v,y]=(0,j.useState)(null),[b,S]=(0,j.useState)(null),w=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=w.current;if(!e)return;let t=t=>{if(t.ctrlKey||e.scrollWidth<=e.clientWidth)return;let n=Math.abs(t.deltaX)>Math.abs(t.deltaY)?t.deltaX:t.deltaY,r=t.deltaMode===1?16:t.deltaMode===2?e.clientWidth:1;t.preventDefault(),e.scrollLeft+=n*r};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]),(0,j.useEffect)(()=>{w.current?.querySelector(`[aria-pressed="true"], input`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,u]);let T=()=>{y(null),S(null)},E=()=>{if(v&&b&&v!==b.id){let t=e.find(e=>e.id===v),n=e.filter(e=>e.id!==v),i=n.findIndex(e=>e.id===b.id);t&&i>=0&&(n.splice(b.before?i:i+1,0,t),n.some((t,n)=>t.id!==e[n].id)&&r(n))}T()},D=()=>{if(!u)return;let t=m.trim();t&&r(e.map(e=>e.id===u?{...e,name:t}:e)),p(null)},O=(t,n)=>{_(!1);let i=`view-${Date.now().toString(36)}`,a=t===`columns`?`Board`:t===`app`?N.find(e=>e.id===n)?.label??`App`:`List`,o=t===`columns`?{id:i,name:a,kind:t,columns:me()}:t===`app`?{id:i,name:a,kind:t,app:n}:{id:i,name:a,kind:t};r([...e,o],i),p(i),h(a)},k=n=>{let i=e.filter(e=>e.id!==n);r(i.length>0?i:[P],n===t?i[0]?.id??P.id:void 0)};return(0,M.jsxs)(`div`,{className:C(`relative flex h-full min-w-0 items-end`,a),children:[(0,M.jsx)(`div`,{ref:w,className:`flex min-w-0 items-end gap-0.5 overflow-x-auto overscroll-x-contain pt-1 [scrollbar-width:none]`,children:e.map(r=>{let a=r.id===t,l=r.kind===`columns`?d:r.kind===`app`&&r.app?F[r.app]:x;return u===r.id?(0,M.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,value:m,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&p(null)},className:C(`relative h-[2.3rem] w-28 shrink-0 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs outline-none ring-0`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground`),style:{backgroundColor:a?o:void 0}},r.id):(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r.id),onDoubleClick:()=>{i||(p(r.id),h(r.name))},title:i?r.name:`${r.name}: double-click to rename, drag to reorder`,draggable:!i,onDragStart:e=>{e.dataTransfer.setData(`text/plain`,r.name),e.dataTransfer.effectAllowed=`move`,y(r.id)},onDragOver:e=>{if(!v||v===r.id)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let t=e.currentTarget.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;S(e=>e?.id===r.id&&e.before===n?e:{id:r.id,before:n})},onDrop:e=>{e.preventDefault(),E()},onDragEnd:T,className:C(`group relative flex h-[2.3rem] shrink-0 items-center gap-1.5 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs transition-colors`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground hover:bg-accent hover:text-foreground`,v===r.id&&`opacity-50`),style:{backgroundColor:a?o:void 0,boxShadow:b?.id===r.id?`inset ${b.before?`2px`:`-2px`} 0 0 var(--primary)`:void 0},children:[(0,M.jsx)(l,{className:`h-3 w-3 shrink-0`}),(0,M.jsx)(`span`,{className:`max-w-32 truncate`,children:r.name}),c&&(0,M.jsx)(f,{className:`h-3 w-3 shrink-0 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-60`,"aria-label":`Open to the side`,onClick:e=>{e.stopPropagation(),c(r.id)}}),!i&&e.length>1&&(0,M.jsx)(s,{className:C(`h-3 w-3 shrink-0 transition-opacity hover:text-destructive`,a?`opacity-60 hover:opacity-100`:`opacity-0 group-hover:opacity-100`),onClick:e=>{e.stopPropagation(),k(r.id)}})]},r.id)})}),!i&&(g?(0,M.jsxs)(`span`,{className:`absolute left-0 top-full z-30 flex w-full min-w-64 flex-wrap items-center gap-2 rounded-b-xl border bg-card p-2 shadow-lg`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`documents`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(x,{className:`h-3 w-3`}),` List`]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`columns`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(d,{className:`h-3 w-3`}),` Board`]}),N.map(e=>{let t=F[e.id];return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`app`,e.id),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(t,{className:`h-3 w-3`}),` `,e.label]},e.id)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,M.jsx)(s,{className:`h-3 w-3`})})]}):(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!0),title:`Add view`,"aria-label":`Add view`,className:`relative ml-1 flex h-[2.3rem] w-10 shrink-0 items-center justify-center rounded-md pb-1 text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}))]})}var L=[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}];function R(e,t){return t.some(t=>e.schema===t||e.schema.startsWith(`${t}/`))}function z({documents:e,workspaceId:t,columns:n,onColumnsChange:i,readOnly:a=!1}){let[o,c]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),[f,p]=(0,j.useState)({}),[m,h]=(0,j.useState)({}),g=(0,j.useRef)(null),[_,v]=(0,j.useState)(!1),y=(0,j.useCallback)(()=>{let e=g.current;e&&v(e.scrollWidth-e.clientWidth-e.scrollLeft>8)},[]);(0,j.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(()=>y());return t.observe(e),()=>t.disconnect()},[y]);let b=(e,t)=>{e.preventDefault();let r=e.currentTarget.parentElement;if(!r)return;let a=e.clientX,o=r.getBoundingClientRect().width,s=o,c=e=>{s=Math.min(900,Math.max(220,o+e.clientX-a)),h(e=>({...e,[t]:s}))},l=()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),i(n.map(e=>e.id===t?{...e,width:Math.round(s)}:e))};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},x=e=>{h(t=>{let n={...t};return delete n[e],n}),i(n.map(t=>t.id===e?{...t,width:void 0}:t))},S=e=>{let t=f[e];if(t===void 0)return;let r=n.find(t=>t.id===e);r&&(r.filter||``)!==t&&i(n.map(n=>n.id===e?{...n,filter:t||void 0}:n))},C=L.filter(e=>!n.some(t=>t.id===e.id));return(0,M.jsxs)(`div`,{className:`relative h-full`,children:[(0,M.jsx)(`div`,{ref:g,onScroll:y,className:`flex h-full snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain p-2`,"data-testid":`schema-columns-board`,children:n.map(t=>{let r=(f[t.id]??t.filter??``).toLowerCase(),o=e.filter(e=>R(e,t.schemas)).filter(e=>{if(!r)return!0;let t=T(e);return`${t.title}\n${t.preview}\n${t.subtitle}`.toLowerCase().includes(r)}),l=m[t.id]??t.width;return(0,M.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 shrink-0 grow-0 basis-full snap-start flex-col rounded-(--card-radius) border bg-muted/20 ${l?`sm:basis-[var(--col-w)]`:`sm:basis-[48%] lg:basis-[32%] xl:basis-[24%]`}`,style:l?{"--col-w":`${l}px`}:void 0,children:[!a&&(0,M.jsx)(`div`,{onPointerDown:e=>b(e,t.id),onDoubleClick:()=>x(t.id),title:`Drag to resize; double-click to reset`,className:`absolute right-0 inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-r-lg transition-colors hover:bg-primary/25 active:bg-primary/40 max-sm:hidden`}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2.5 max-sm:pr-10`,children:[(0,M.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o.length}),(0,M.jsx)(`span`,{className:`flex-1`}),!a&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>i(n.filter(e=>e.id!==t.id)),title:`Remove column`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-destructive`,children:(0,M.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`px-3 pb-2`,children:(0,M.jsx)(`input`,{value:f[t.id]??t.filter??``,onChange:e=>p(n=>({...n,[t.id]:e.target.value})),onBlur:()=>S(t.id),onKeyDown:e=>{e.key===`Enter`&&S(t.id)},placeholder:`Filter…`,readOnly:a,className:`h-7 w-full rounded-md border border-input bg-background px-2 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})}),(0,M.jsxs)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto px-2 pb-2`,children:[o.map(e=>{let t=T(e);return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`w-full min-w-0 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-accent/50`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsx)(se,{document:e,size:3.5}),(0,M.jsx)(`span`,{className:`truncate text-xs font-medium`,title:t.title,children:t.title})]}),t.preview&&(0,M.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words text-[11px] leading-snug text-muted-foreground`,children:t.preview}),(0,M.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/70`,children:new Date(e.updatedAt||e.createdAt).toLocaleDateString()})]},e.id)}),o.length===0&&(0,M.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground/60`,children:`Empty`})]})]},t.id)})}),(!a&&C.length>0||_)&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-20 flex w-7 flex-col items-end bg-gradient-to-l from-background via-background/60 to-transparent py-2`,children:[!a&&C.length>0&&(0,M.jsxs)(`div`,{className:`pointer-events-auto relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:`Add column`,"aria-label":`Add column`,className:`flex h-7 w-6 items-center justify-center rounded-l-md border border-r-0 bg-background text-muted-foreground shadow-elevation-1 hover:bg-accent hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}),u&&(0,M.jsxs)(`div`,{className:`absolute right-0 top-8 w-44 rounded-lg border bg-background p-2 shadow-elevation-2`,children:[(0,M.jsx)(`p`,{className:`px-2 pb-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Add column`}),C.map(e=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{d(!1),i([...n,{...e}])},className:`w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:e.label},e.id)),(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`mt-1 w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/60 hover:bg-accent/50`,children:`Cancel`})]})]}),_&&(0,M.jsx)(r,{className:`my-auto h-4 w-4 self-center text-muted-foreground/70`,"aria-label":`More columns`})]}),(0,M.jsx)(ne,{document:o,isOpen:o!==null,onClose:()=>c(null),workspaceId:t})]})}function B(e,t,n,r,i){let a=`${e}\0${t}\0${n}\0${r}\0${i??``}`,[o,s]=(0,j.useState)(0),[c,l]=(0,j.useState)(null);(0,j.useEffect)(()=>{let o=!1;return E(e,n,t,{limit:200,allOf:[r],...i?{sortBy:i,order:`asc`}:{}}).then(e=>{o||l({key:a,docs:e.payload||[]})}).catch(()=>{o||l({key:a,docs:[]})}),()=>{o=!0}},[a,o]);let u=c?.key===a?c.docs:[],d=c?.key!==a;return(0,j.useEffect)(()=>{let e=()=>s(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]),{docs:u,isLoading:d,refresh:(0,j.useCallback)(()=>s(e=>e+1),[])}}function V({workspaceId:e,treeName:t,path:n}){let{docs:r,isLoading:i,refresh:a}=B(e,t,n,w,`tasks`),[o,s]=(0,j.useState)(!1),c=o?r.filter(e=>e.data?.status!==`completed`):r,l=r.filter(e=>{let t=e.data?.status;return t!==`completed`&&t!==`cancelled`}).length;return(0,M.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-3xl flex-col p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex shrink-0 items-center justify-between gap-2`,children:[(0,M.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[l,` open`]}),(0,M.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`hide done`]})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto`,children:i?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading…`}):c.length===0?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No todos here.`}):c.map(t=>(0,M.jsx)(D,{doc:t,workspaceId:e,readOnly:!1,onChanged:a},t.id))})]})}function H({app:e,contextId:t,...n}){let r=t&&e!==`lens`?{mode:`context`,contextId:t}:{mode:`workspace`,workspaceName:n.workspaceId,treeName:n.treeName,path:n.path,treeType:n.treeName===`directory`||n.treeName===`backends`?`directory`:`context`},i=e===`todo-app`?`todo`:e===`notes-app`?`notes`:e,a=ce.find(e=>e.id===i);return(0,M.jsx)(ue,{target:r,children:e===`todos`?(0,M.jsx)(V,{...n}):a?(0,M.jsx)(a.Component,{}):null})}export{pe as a,P as i,z as n,he as o,I as r,fe as s,H as t};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{Br as r,Ct as i,G as a,It as o,L as s,Lt as c,Nt as l,St as u,Tr as d,Ut as f,X as p,Yr as m,ct as h,it as g,mn as _,mt as v,ti as y,tt as b,vn as x,yn as S}from"./ui-Byg1cZDr.js";import{t as C}from"./utils-2pl1SbIp.js";import{An as w,Vn as T,q as E}from"./workspace-CrSpR4xf.js";import{t as D}from"./TodosWidget-CxiqmDuJ.js";import{d as O,o as k,u as ee}from"./ObjectPropertiesCard-BIBMvx_i.js";import{h as te,s as ne,t as re,u as ie}from"./document-list-Dsf1DVEx.js";import{n as ae}from"./use-toolbox-Ck_cLGgf.js";import{t as oe}from"./useToastHelpers-CRrpIIdY.js";import{n as A}from"./color-DFEH4BfK.js";import{t as se}from"./DocumentIcon-x299QNu_.js";import{t as ce}from"./registry-DIfZf6LB.js";import{t as le}from"./FileForm-CqJpRbXv.js";import{t as ue}from"./applet-target-C_gBgU-Z.js";var j=e(n(),1),M=t();function de({target:e,children:t}){let[n,r]=(0,j.useState)([]),i=(0,j.useRef)(!1),[a,o]=(0,j.useState)(!1),[s,c]=(0,j.useState)(!1),[l,u]=(0,j.useState)(null),{showErrorToast:d}=oe();return(0,M.jsxs)(`div`,{className:`relative flex flex-col h-full min-h-0 bg-background ${a?`ring-2 ring-inset ring-primary`:``}`,onDragOverCapture:t=>{s||!e||!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i.current?`none`:`copy`,o(!i.current))},onDragLeaveCapture:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDropCapture:t=>{if(s||!e||!Array.from(t.dataTransfer.types).includes(`Files`))return;if(t.preventDefault(),t.stopPropagation(),o(!1),i.current){d(`Wait for the current upload to finish`);return}let n=Array.from(t.dataTransfer.files);if(!n.length){d(`Drop files rather than folders`);return}r(n),u(e),c(!0)},children:[t,a&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-30 flex items-center justify-center bg-background/80 text-sm font-medium`,children:[`Drop files to upload to `,e?.mode===`workspace`?e.path:`this context`]}),s&&(0,M.jsxs)(ie,{label:`Import files`,onClose:()=>{i.current||c(!1)},children:[(0,M.jsx)(`h2`,{className:`border-b px-4 py-3 text-sm font-medium`,children:`Import files`}),(0,M.jsx)(le,{target:l,initialFiles:n,onClose:()=>c(!1),onBusyChange:e=>{i.current=e}})]})]})}function fe({navigationTabs:e,navigationActions:t,onBack:n,accentColor:r,frameContent:s=!0,urlType:l,urlDisplay:u,contextPath:d,treeName:f,workspaceId:m,workspaceLabel:h,workspaceIcon:g,documentSchema:_,documents:b,isLoading:x,totalCount:C,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:me,disablePurgeDocuments:he,canvasInfo:F,isCanvasPinned:I,onTogglePinCanvas:L,onSaveAsCanvas:R,onShareCanvas:z,onUnshareCanvas:B,onDeleteCanvas:V,isSharingCanvas:H,isDeletingCanvas:U,isCanvasShared:W,isCanvasLocked:ge,backendSearchQueries:_e,onBackendSearch:G,onRemoveBackendQuery:K,serverSort:ve,onServerSortChange:ye,scope:be,onScopeChange:xe,canSaveChanges:Se,isSavingChanges:q,onSaveChanges:J,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,linkTree:Ee,children:Y,contentBanner:De,folders:Oe,onOpenFolder:ke}){let Ae=l===`canvas`,X=te(),{state:je,toggleView:Me,hasActiveFilters:Ne,openAddPicker:Pe}=ae(),Z=k(),[Fe,Q]=(0,j.useState)(``),$=JSON.stringify([m,f,d,_]),[Ie,Le]=(0,j.useState)($);Ie!==$&&(Le($),Q(``));let Re=(0,M.jsxs)(M.Fragment,{children:[t,R&&(0,M.jsx)(`button`,{type:`button`,onClick:R,title:`Save as canvas`,"aria-label":`Save as canvas`,className:`flex h-control-sm w-control-sm shrink-0 items-center justify-center rounded-md border text-muted-foreground hover:bg-accent touch-target`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]});return(0,M.jsxs)(de,{target:N&&m?{mode:`workspace`,workspaceName:m,path:d,treeName:f||`context`,treeType:f===`directory`?`directory`:`context`}:null,children:[e&&!X&&(0,M.jsx)(O,{accentColor:r,children:e}),(0,M.jsxs)(`div`,{className:`canvas-surface-body${s&&!X?` is-framed`:``}`,children:[(0,M.jsx)(ee,{workspaceIcon:g,workspace:h||m||u.split(`://`)[0]||`Workspace`,actions:X&&e?(0,M.jsxs)(`details`,{className:`relative shrink-0`,"aria-label":`Canvas views`,children:[(0,M.jsx)(`summary`,{className:`cursor-pointer rounded-md border px-2 py-1 text-xs`,title:`Choose or manage content views`,children:`Views`}),(0,M.jsx)(`div`,{className:`absolute right-0 top-full z-30 mt-2 min-w-64 max-w-[80vw] rounded-md border bg-background p-2 shadow-lg`,children:e})]}):void 0,tree:f?`${f}${l.endsWith(`-layer`)?`:layer`:``}`:l.replace(`-layer`,``),path:d,accentColor:r,onBack:Z.location?Z.location.section===`view`?Z.close:()=>Z.update?.({section:`view`}):n,section:Z.location?`document/${Z.location.documentId}/${Z.location.section}`:void 0,onSection:Z.location?()=>Z.update?.({section:`view`}):void 0,onBrowseWorkspaces:Ce,onBrowseTree:we,onNavigatePath:Te,onFilter:()=>Me(`tools`),filtersActive:Ne,filtersOpen:je.t1Open&&je.t1View===`tools`,onAdd:e=>Pe({modal:e.shiftKey,fresh:!0}),search:G||!Y?{workspaceId:m,queries:_e||[],onSearch:G??Q,localOnly:!G,onRemoveQuery:K,scope:be,onScopeChange:xe}:void 0,onDraftChange:Y?void 0:Q}),Ae&&F?(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b bg-muted/20 shrink-0 min-w-0`,children:[F.color&&(0,M.jsx)(`div`,{className:`w-1 h-6 rounded-full shrink-0`,style:{backgroundColor:F.color}}),(0,M.jsx)(S,{className:`w-4 h-4 shrink-0 text-primary`}),(0,M.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,M.jsx)(`span`,{className:`text-lg font-semibold leading-tight truncate`,children:F.label||u.split(`://`)[1]||`Canvas`}),F.description&&(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground truncate leading-tight`,children:F.description})]}),Se&&J&&(0,M.jsxs)(`button`,{type:`button`,onClick:J,disabled:q,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:`Save filters`,children:[(0,M.jsx)(i,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:q?`Saving...`:`Save filters`})]}),L&&(0,M.jsxs)(`button`,{type:`button`,onClick:L,"aria-pressed":!!I,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground`,title:I?`Unpin from home`:`Pin to home`,children:[I?(0,M.jsx)(c,{className:`w-3 h-3`}):(0,M.jsx)(o,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:I?`Unpin`:`Pin`})]}),z&&(0,M.jsxs)(`button`,{type:`button`,onClick:z,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-accent transition-colors text-muted-foreground hover:text-foreground disabled:opacity-50`,title:W?`Copy public link`:`Share canvas`,children:[(0,M.jsx)(v,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:H?`Sharing...`:W?`Copy link`:`Share`})]}),W&&B&&(0,M.jsxs)(`button`,{type:`button`,onClick:B,disabled:H||U,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(a,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:`Unshare`})]}),V&&(0,M.jsxs)(`button`,{type:`button`,onClick:V,disabled:U||ge&&!W,title:ge&&!W?`Unlock this canvas before deleting it`:`Delete canvas`,className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 text-xs border rounded-md hover:bg-destructive/10 transition-colors text-muted-foreground hover:text-destructive disabled:opacity-50`,children:[(0,M.jsx)(p,{className:`w-3 h-3`}),(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:U?`Deleting…`:`Delete`})]})]})}):null,Y&&(R||t)&&(0,M.jsx)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1`,children:Re}),(0,M.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[De,Y||(0,M.jsx)(re,{readingPane:!0,externalSearchQuery:Fe,toolbarActions:Re,documents:_?b.filter(e=>e.schema===_):b,isLoading:x,folders:_?void 0:Oe,onOpenFolder:ke,contextPath:d,treeName:f,workspaceId:m,totalCount:C,viewMode:_?`card`:`table`,allowViewToggle:!0,currentPage:w,pageSize:T,onPageChange:E,onPageSizeChange:D,onRemoveDocument:ne,onDeleteDocument:ie,onDestroyDocument:oe,onRemoveDocuments:A,onDeleteDocuments:se,onDestroyDocuments:ce,onCopyDocuments:le,onCutDocuments:ue,onPasteDocuments:fe,onImportDocuments:N,onSelectionChange:pe,pastedDocumentIds:P,onPurgeDocuments:_?void 0:me,disablePurgeDocuments:he,backendSearchQueries:_e,onBackendSearch:G,serverSort:ve,onServerSortChange:ye,onRemoveBackendQuery:K,scope:be,onScopeChange:xe,canSaveChanges:!Ae&&Se,isSavingChanges:q,onSaveChanges:J,linkTree:Ee},_??`documents`)]})]})]})}var N=[{id:`todos`,label:`Todo list`},{id:`todo-app`,label:`Todo App`},{id:`notes`,label:`Notes list`},{id:`notes-app`,label:`Notes App`},{id:`sketch`,label:`Sketch`},{id:`terminal`,label:`Terminal`}];function pe(e){return e?.kind===`app`&&e.app===`notes`?`data/schema/note`:void 0}var P={id:`default`,name:`All`,kind:`documents`};function me(){return[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}]}function he(e){let t=e?.views;if(!Array.isArray(t))return[P];let n=t.filter(e=>{let t=e;return!t||typeof t.id!=`string`||typeof t.name!=`string`?!1:t.kind===`documents`||t.kind===`columns`||t.kind===`app`&&(N.some(e=>e.id===t.app)||t.app===`filters`||t.app===`lens`)});return n.length>0?n:[P]}var F={todos:_,"todo-app":_,notes:b,"notes-app":b,filters:h,sketch:g,Brush:m,terminal:g,lens:u};function I({views:e,activeId:t,onSelect:n,onSave:r,readOnly:i=!1,className:a,accentColor:o,onOpenToSide:c}){let[u,p]=(0,j.useState)(null),[m,h]=(0,j.useState)(``),[g,_]=(0,j.useState)(!1),[v,y]=(0,j.useState)(null),[b,S]=(0,j.useState)(null),w=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=w.current;if(!e)return;let t=t=>{if(t.ctrlKey||e.scrollWidth<=e.clientWidth)return;let n=Math.abs(t.deltaX)>Math.abs(t.deltaY)?t.deltaX:t.deltaY,r=t.deltaMode===1?16:t.deltaMode===2?e.clientWidth:1;t.preventDefault(),e.scrollLeft+=n*r};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]),(0,j.useEffect)(()=>{w.current?.querySelector(`[aria-pressed="true"], input`)?.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,u]);let T=()=>{y(null),S(null)},E=()=>{if(v&&b&&v!==b.id){let t=e.find(e=>e.id===v),n=e.filter(e=>e.id!==v),i=n.findIndex(e=>e.id===b.id);t&&i>=0&&(n.splice(b.before?i:i+1,0,t),n.some((t,n)=>t.id!==e[n].id)&&r(n))}T()},D=()=>{if(!u)return;let t=m.trim();t&&r(e.map(e=>e.id===u?{...e,name:t}:e)),p(null)},O=(t,n)=>{_(!1);let i=`view-${Date.now().toString(36)}`,a=t===`columns`?`Board`:t===`app`?N.find(e=>e.id===n)?.label??`App`:`List`,o=t===`columns`?{id:i,name:a,kind:t,columns:me()}:t===`app`?{id:i,name:a,kind:t,app:n}:{id:i,name:a,kind:t};r([...e,o],i),p(i),h(a)},k=n=>{let i=e.filter(e=>e.id!==n);r(i.length>0?i:[P],n===t?i[0]?.id??P.id:void 0)};return(0,M.jsxs)(`div`,{className:C(`relative flex h-full min-w-0 items-end`,a),children:[(0,M.jsx)(`div`,{ref:w,className:`flex min-w-0 items-end gap-0.5 overflow-x-auto overscroll-x-contain pt-1 [scrollbar-width:none]`,children:e.map(r=>{let a=r.id===t,l=r.kind===`columns`?d:r.kind===`app`&&r.app?F[r.app]:x;return u===r.id?(0,M.jsx)(`input`,{autoFocus:!0,"aria-label":`Tab name`,value:m,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&D(),e.key===`Escape`&&p(null)},className:C(`relative h-[2.3rem] w-28 shrink-0 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs outline-none ring-0`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground`),style:{backgroundColor:a?o:void 0}},r.id):(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r.id),onDoubleClick:()=>{i||(p(r.id),h(r.name))},title:i?r.name:`${r.name}: double-click to rename, drag to reorder`,draggable:!i,onDragStart:e=>{e.dataTransfer.setData(`text/plain`,r.name),e.dataTransfer.effectAllowed=`move`,y(r.id)},onDragOver:e=>{if(!v||v===r.id)return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let t=e.currentTarget.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;S(e=>e?.id===r.id&&e.before===n?e:{id:r.id,before:n})},onDrop:e=>{e.preventDefault(),E()},onDragEnd:T,className:C(`group relative flex h-[2.3rem] shrink-0 items-center gap-1.5 rounded-t-[.5rem] border-0 px-3 pb-1 text-xs transition-colors`,a?C(`z-[2] bg-background font-medium`,o?A(o):`text-foreground`):`bg-muted text-muted-foreground hover:bg-accent hover:text-foreground`,v===r.id&&`opacity-50`),style:{backgroundColor:a?o:void 0,boxShadow:b?.id===r.id?`inset ${b.before?`2px`:`-2px`} 0 0 var(--primary)`:void 0},children:[(0,M.jsx)(l,{className:`h-3 w-3 shrink-0`}),(0,M.jsx)(`span`,{className:`max-w-32 truncate`,children:r.name}),c&&(0,M.jsx)(f,{className:`h-3 w-3 shrink-0 opacity-0 transition-opacity hover:opacity-100 group-hover:opacity-60`,"aria-label":`Open to the side`,onClick:e=>{e.stopPropagation(),c(r.id)}}),!i&&e.length>1&&(0,M.jsx)(s,{className:C(`h-3 w-3 shrink-0 transition-opacity hover:text-destructive`,a?`opacity-60 hover:opacity-100`:`opacity-0 group-hover:opacity-100`),onClick:e=>{e.stopPropagation(),k(r.id)}})]},r.id)})}),!i&&(g?(0,M.jsxs)(`span`,{className:`absolute left-0 top-full z-30 flex w-full min-w-64 flex-wrap items-center gap-2 rounded-b-xl border bg-card p-2 shadow-lg`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`documents`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(x,{className:`h-3 w-3`}),` List`]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`columns`),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(d,{className:`h-3 w-3`}),` Board`]}),N.map(e=>{let t=F[e.id];return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>O(`app`,e.id),className:`flex h-10 items-center gap-1.5 rounded-md border px-2 text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:[(0,M.jsx)(t,{className:`h-3 w-3`}),` `,e.label]},e.id)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`p-1 text-muted-foreground hover:text-foreground`,"aria-label":`Cancel`,children:(0,M.jsx)(s,{className:`h-3 w-3`})})]}):(0,M.jsx)(`button`,{type:`button`,onClick:()=>_(!0),title:`Add view`,"aria-label":`Add view`,className:`relative ml-1 flex h-[2.3rem] w-10 shrink-0 items-center justify-center rounded-md pb-1 text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}))]})}var L=[{id:`emails`,label:`Emails`,schemas:[`data/schema/message`]},{id:`todos`,label:`Todos`,schemas:[`data/schema/task`]},{id:`notes`,label:`Notes`,schemas:[`data/schema/note`]},{id:`links`,label:`Links`,schemas:[`data/schema/tab`,`data/schema/link`]},{id:`files`,label:`Files`,schemas:[`data/schema/file`]}];function R(e,t){return t.some(t=>e.schema===t||e.schema.startsWith(`${t}/`))}function z({documents:e,workspaceId:t,columns:n,onColumnsChange:i,readOnly:a=!1}){let[o,c]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),[f,p]=(0,j.useState)({}),[m,h]=(0,j.useState)({}),g=(0,j.useRef)(null),[_,v]=(0,j.useState)(!1),y=(0,j.useCallback)(()=>{let e=g.current;e&&v(e.scrollWidth-e.clientWidth-e.scrollLeft>8)},[]);(0,j.useEffect)(()=>{let e=g.current;if(!e)return;let t=new ResizeObserver(()=>y());return t.observe(e),()=>t.disconnect()},[y]);let b=(e,t)=>{e.preventDefault();let r=e.currentTarget.parentElement;if(!r)return;let a=e.clientX,o=r.getBoundingClientRect().width,s=o,c=e=>{s=Math.min(900,Math.max(220,o+e.clientX-a)),h(e=>({...e,[t]:s}))},l=()=>{window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l),i(n.map(e=>e.id===t?{...e,width:Math.round(s)}:e))};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},x=e=>{h(t=>{let n={...t};return delete n[e],n}),i(n.map(t=>t.id===e?{...t,width:void 0}:t))},S=e=>{let t=f[e];if(t===void 0)return;let r=n.find(t=>t.id===e);r&&(r.filter||``)!==t&&i(n.map(n=>n.id===e?{...n,filter:t||void 0}:n))},C=L.filter(e=>!n.some(t=>t.id===e.id));return(0,M.jsxs)(`div`,{className:`relative h-full`,children:[(0,M.jsx)(`div`,{ref:g,onScroll:y,className:`flex h-full snap-x snap-mandatory gap-3 overflow-x-auto overscroll-x-contain p-2`,"data-testid":`schema-columns-board`,children:n.map(t=>{let r=(f[t.id]??t.filter??``).toLowerCase(),o=e.filter(e=>R(e,t.schemas)).filter(e=>{if(!r)return!0;let t=w(e);return`${t.title}\n${t.preview}\n${t.subtitle}`.toLowerCase().includes(r)}),l=m[t.id]??t.width;return(0,M.jsxs)(`div`,{className:`relative flex h-full min-h-0 min-w-0 shrink-0 grow-0 basis-full snap-start flex-col rounded-(--card-radius) border bg-muted/20 ${l?`sm:basis-[var(--col-w)]`:`sm:basis-[48%] lg:basis-[32%] xl:basis-[24%]`}`,style:l?{"--col-w":`${l}px`}:void 0,children:[!a&&(0,M.jsx)(`div`,{onPointerDown:e=>b(e,t.id),onDoubleClick:()=>x(t.id),title:`Drag to resize; double-click to reset`,className:`absolute right-0 inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-r-lg transition-colors hover:bg-primary/25 active:bg-primary/40 max-sm:hidden`}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 px-3 pb-1 pt-2.5 max-sm:pr-10`,children:[(0,M.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),(0,M.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o.length}),(0,M.jsx)(`span`,{className:`flex-1`}),!a&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>i(n.filter(e=>e.id!==t.id)),title:`Remove column`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-destructive`,children:(0,M.jsx)(s,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`px-3 pb-2`,children:(0,M.jsx)(`input`,{value:f[t.id]??t.filter??``,onChange:e=>p(n=>({...n,[t.id]:e.target.value})),onBlur:()=>S(t.id),onKeyDown:e=>{e.key===`Enter`&&S(t.id)},placeholder:`Filter…`,readOnly:a,className:`h-7 w-full rounded-md border border-input bg-background px-2 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`})}),(0,M.jsxs)(`div`,{className:`flex-1 space-y-1.5 overflow-y-auto px-2 pb-2`,children:[o.map(e=>{let t=w(e);return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`w-full min-w-0 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-accent/50`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsx)(se,{document:e,size:3.5}),(0,M.jsx)(`span`,{className:`truncate text-xs font-medium`,title:t.title,children:t.title})]}),t.preview&&(0,M.jsx)(`p`,{className:`mt-1 line-clamp-2 break-words text-[11px] leading-snug text-muted-foreground`,children:t.preview}),(0,M.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground/70`,children:new Date(e.updatedAt||e.createdAt).toLocaleDateString()})]},e.id)}),o.length===0&&(0,M.jsx)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground/60`,children:`Empty`})]})]},t.id)})}),(!a&&C.length>0||_)&&(0,M.jsxs)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-20 flex w-7 flex-col items-end bg-gradient-to-l from-background via-background/60 to-transparent py-2`,children:[!a&&C.length>0&&(0,M.jsxs)(`div`,{className:`pointer-events-auto relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:`Add column`,"aria-label":`Add column`,className:`flex h-7 w-6 items-center justify-center rounded-l-md border border-r-0 bg-background text-muted-foreground shadow-elevation-1 hover:bg-accent hover:text-foreground`,children:(0,M.jsx)(l,{className:`h-3.5 w-3.5`})}),u&&(0,M.jsxs)(`div`,{className:`absolute right-0 top-8 w-44 rounded-lg border bg-background p-2 shadow-elevation-2`,children:[(0,M.jsx)(`p`,{className:`px-2 pb-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Add column`}),C.map(e=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{d(!1),i([...n,{...e}])},className:`w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-accent/50 hover:text-foreground`,children:e.label},e.id)),(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`mt-1 w-full rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/60 hover:bg-accent/50`,children:`Cancel`})]})]}),_&&(0,M.jsx)(r,{className:`my-auto h-4 w-4 self-center text-muted-foreground/70`,"aria-label":`More columns`})]}),(0,M.jsx)(ne,{document:o,isOpen:o!==null,onClose:()=>c(null),workspaceId:t})]})}function B(e,t,n,r,i){let a=`${e}\0${t}\0${n}\0${r}\0${i??``}`,[o,s]=(0,j.useState)(0),[c,l]=(0,j.useState)(null);(0,j.useEffect)(()=>{let o=!1;return E(e,n,t,{limit:200,allOf:[r],...i?{sortBy:i,order:`asc`}:{}}).then(e=>{o||l({key:a,docs:e.payload||[]})}).catch(()=>{o||l({key:a,docs:[]})}),()=>{o=!0}},[a,o]);let u=c?.key===a?c.docs:[],d=c?.key!==a;return(0,j.useEffect)(()=>{let e=()=>s(e=>e+1);return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[]),{docs:u,isLoading:d,refresh:(0,j.useCallback)(()=>s(e=>e+1),[])}}function V({workspaceId:e,treeName:t,path:n}){let{docs:r,isLoading:i,refresh:a}=B(e,t,n,T,`tasks`),[o,s]=(0,j.useState)(!1),c=o?r.filter(e=>e.data?.status!==`completed`):r,l=r.filter(e=>{let t=e.data?.status;return t!==`completed`&&t!==`cancelled`}).length;return(0,M.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-3xl flex-col p-4`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex shrink-0 items-center justify-between gap-2`,children:[(0,M.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[l,` open`]}),(0,M.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,M.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`hide done`]})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto`,children:i?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading…`}):c.length===0?(0,M.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`No todos here.`}):c.map(t=>(0,M.jsx)(D,{doc:t,workspaceId:e,readOnly:!1,onChanged:a},t.id))})]})}function H({app:e,contextId:t,...n}){let r=t&&e!==`lens`?{mode:`context`,contextId:t}:{mode:`workspace`,workspaceName:n.workspaceId,treeName:n.treeName,path:n.path,treeType:n.treeName===`directory`||n.treeName===`backends`?`directory`:`context`},i=e===`todo-app`?`todo`:e===`notes-app`?`notes`:e,a=ce.find(e=>e.id===i);return(0,M.jsx)(ue,{target:r,children:e===`todos`?(0,M.jsx)(V,{...n}):a?(0,M.jsx)(a.Component,{}):null})}export{pe as a,P as i,z as n,he as o,I as r,fe as s,H as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,t}from"./api-CA6WiiYM.js";import{
|
|
1
|
+
import{c as e,t}from"./api-CA6WiiYM.js";import{Dn as n,En as r}from"./workspace-CrSpR4xf.js";var i=`contexts:deleted`;function a(e,t){return e.id===t.id?t.ownerId===void 0?e.isShared!==!0&&e.type!==`shared`:e.userId===t.ownerId:!1}async function o(){try{let n=await t.get(e.contexts);return Array.isArray(n)?n:(console.warn(`listContexts: response.payload is not an array:`,n),[])}catch(e){throw console.error(`Failed to list contexts:`,e),e}}function s(e,t){return t?`${e}${e.includes(`?`)?`&`:`?`}ownerId=${encodeURIComponent(t)}`:e}async function c(n,r){try{let i=s(`${e.contexts}/${n}`,r),a=await t.get(i);if(a&&a)return a;throw Error(`Context data not found in API response`)}catch(e){throw console.error(`Failed to get context ${n}:`,e),e}}async function l(n){try{let r=await t.post(e.contexts,n);if(r&&r&&r.context)return r.context;throw Error(`Created context data not found in API response`)}catch(e){throw console.error(`Failed to create context:`,e),e}}async function u(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to patch context ${n}:`,e),e}}async function d(n,r,i){try{let a=s(`${e.contexts}/${n}`,i),o=await t.put(a,r);if(o?.context)return o.context;throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context ${n}:`,e),e}}async function f(n,r,i,a){try{let o=s(`${e.contexts}/${n}/url`,i),c=await t.post(o,{url:r,...a?{treeName:a}:{}});if(c&&c&&c.url)return{url:c.url,treeId:c.treeId};throw Error(`Updated context data not found in API response`)}catch(e){throw console.error(`Failed to update context URL for ${n}:`,e),e}}async function p(n,r){try{let a=s(`${e.contexts}/${n}`,r);await t.delete(a),window.dispatchEvent(new CustomEvent(i,{detail:{id:n,ownerId:r}}))}catch(e){throw console.error(`Failed to delete context ${n}:`,e),e}}async function m(i,a=[],o=[],s={},c){try{if(s.ids?.length===0)return Object.assign([],{count:0,totalCount:0});if(n(s.sortBy)){let e=await r(s,async e=>{let t=await m(i,a,o,{...s,...e,sortBy:void 0,order:`asc`},c);return{payload:t,count:t.count,totalCount:t.totalCount}});return Object.assign(e.payload,{count:e.count,totalCount:e.totalCount})}let l=new URLSearchParams;s.geoSelection&&(l.set(`geoSelection`,JSON.stringify(s.geoSelection)),l.set(`includeUnlocated`,String(s.includeUnlocated===!0))),s.ids?.forEach(e=>l.append(`ids`,String(e))),a.forEach(e=>l.append(`allOf`,e)),o.forEach(e=>l.append(`filters`,e)),(s.anyOf||[]).filter(Boolean).forEach(e=>l.append(`anyOf`,e)),(s.noneOf||[]).filter(Boolean).forEach(e=>l.append(`noneOf`,e)),s.sortBy&&l.append(`sortBy`,s.sortBy),s.order&&l.append(`order`,s.order),s.applyContextSpec===!1&&l.append(`applyContextSpec`,`false`),c&&l.append(`ownerId`,c),s.includeServerContext!==void 0&&l.append(`includeServerContext`,s.includeServerContext.toString()),s.includeClientContext!==void 0&&l.append(`includeClientContext`,s.includeClientContext.toString()),s.limit!==void 0&&l.append(`limit`,s.limit.toString()),s.offset!==void 0&&l.append(`offset`,s.offset.toString()),s.page!==void 0&&l.append(`page`,s.page.toString()),(s.queries&&s.queries.length?s.queries:s.q?[s.q]:[]).map(e=>e.trim()).filter(Boolean).forEach(e=>l.append(`q`,e));let u=`${e.contexts}/${i}/documents${l.toString()?`?`+l.toString():``}`,d=await t.getEnvelope(u,{signal:s.signal}),f=d.payload;if(Array.isArray(f)){let e=f;return e.count=d.count??void 0,e.totalCount=d.totalCount??void 0,e}return console.warn(`getContextDocuments: payload is not an array:`,f),[]}catch(e){throw console.error(`Failed to get context documents for ${i}:`,e),e}}async function h(n){let r=await t.get(`${e.contexts}/${n}/shares`);return Array.isArray(r)?r:[]}async function g(n,r,i){try{return{message:(await t.post(`${e.contexts}/${n}/shares`,{userEmail:r,accessLevel:i})).message||`Context access granted`}}catch(e){throw console.error(`Failed to grant context access:`,e),e}}async function _(n,r){try{return{message:(await t.delete(`${e.contexts}/${n}/shares/${encodeURIComponent(r)}`)).message||`Context access revoked`}}catch(e){throw console.error(`Failed to revoke context access:`,e),e}}async function v(n,r){try{let i=s(`${e.contexts}/${n}/tree`,r),a=await t.get(i);if(a)return a;throw Error(`Context tree data not found in API response`)}catch(e){throw console.error(`Failed to get context tree for ${n}:`,e),e}}async function y(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents/remove${o.toString()?`?${o.toString()}`:``}`;return{message:await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})||`Documents removed from context`}}catch(e){throw console.error(`Failed to remove documents from context ${n}:`,e),e}}async function b(n,r,i,a){try{let a=Array.isArray(r)?r:[r],o=new URLSearchParams,c=`${e.contexts}/${n}/documents${o.toString()?`?${o.toString()}`:``}`;return await t.delete(s(c,i),{body:JSON.stringify(a),headers:{"Content-Type":`application/json`}})}catch(e){throw console.error(`Failed to delete documents from context ${n}:`,e),e}}async function x(n,r,i,a){try{let o=Array.isArray(i)?i:[i];return await t.post(s(`${e.contexts}/${n}/documents`,a),{documentIds:o,context:r}),!0}catch(e){throw console.error(`Failed to paste documents to context path ${r}:`,e),e}}async function S(n,r,i=!0){return await t.post(`${e.contexts}/${n}/tree/paths`,{path:r,autoCreateLayers:i})??!0}async function C(n,r,i=!1){let a=new URLSearchParams({path:r,recursive:i.toString()});return await t.delete(`${e.contexts}/${n}/tree/paths?${a}`)??!0}async function w(n,r,i){return await t.patch(`${e.contexts}/${n}/tree/paths`,{path:r,...i})??!0}async function T(n,r,i,a=!1,o={}){return await t.post(`${e.contexts}/${n}/tree/paths/move`,{from:r,to:i,recursive:a,...o.mergeDown?{mergeDown:!0}:{}})??!0}async function E(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/merge-down`,{path:r})}async function D(n,r){return await t.post(`${e.contexts}/${n}/tree/paths/subtract-down`,{path:r})}async function O(n,r,i,a=!1){return await t.post(`${e.contexts}/${n}/tree/paths/copy`,{from:r,to:i,recursive:a})??!0}async function k(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/merge`,{layerId:r,targetLayers:i})}async function A(n,r,i){return await t.post(`${e.contexts}/${n}/tree/layers/subtract`,{layerId:r,targetLayers:i})}async function j(n,r,i){try{let a=Array.isArray(i)?i:[i];return await t.post(`${e.workspaces}/${n}/documents`,{documents:a,treeType:`context`,context:r}),!0}catch(e){throw console.error(`Failed to import documents to context path ${r}:`,e),e}}async function M(n,r,i=[]){try{let a=Array.isArray(r)?r:[r],o=await t.post(`${e.contexts}/${n}/documents`,{documents:a,features:i});return Array.isArray(o)?o:[]}catch(e){throw console.error(`Failed to insert documents into context ${n}:`,e),e}}export{D as C,i as D,f as E,a as O,A as S,w as T,x as _,c as a,y as b,g as c,M as d,h as f,T as g,E as h,b as i,j as l,k as m,l as n,m as o,o as p,p as r,v as s,O as t,S as u,u as v,d as w,_ as x,C as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Nt as i,Y as a,at as o,mt as s,vr as c}from"./ui-Byg1cZDr.js";import{t as l}from"./button-SgR3GVvV.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./socket-CtH3EU9m.js";import{n as ee}from"./use-toast-BlLDqSUO.js";import{Pt as te}from"./workspace-DvxC7pw1.js";import{a as ne,c as re,i as f,n as ie,o as ae,r as oe,s as se,t as ce}from"./alert-dialog-izlVMXfa.js";import{O as le,n as ue,p as de,r as p}from"./context-mfIOB8dN.js";import{t as m}from"./PathPickerField-DBe7jykL.js";import{a as h,c as g,i as fe,n as _,o as pe,r as me,s as he,t as ge}from"./use-sortable-data-BW_0sXBs.js";import{n as _e}from"./page-header-DkOHw0g-.js";import{t as ve}from"./form-panel-C34lByEH.js";import{t as ye}from"./use-create-panel-DhSNIGtr.js";var v=e(n(),1);function y(e,t=`An error occurred`){if(e instanceof Error)return e.message;if(typeof e==`object`&&e){let n=e;return n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||t}return t}function be(e,t,n=`An error occurred`){return console.error(t,e),y(e,n)}var b=t();function x(){let e=r(),[t,n]=(0,v.useState)([]),[y,x]=(0,v.useState)([]),[S,C]=(0,v.useState)(!0),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`context`),[M,N]=(0,v.useState)(`/`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(`/`),[B,V]=(0,v.useState)(``),[H,U]=(0,v.useState)(!1),[W,G]=ye(),[K,q]=(0,v.useState)(null),[J,Y]=(0,v.useState)(null),{showToast:X}=ee();(0,v.useEffect)(()=>{d.isConnected()||(console.log(`Socket not connected, attempting to connect...`),d.reconnect())},[]);let Z=(0,v.useCallback)(async()=>{try{C(!0);let[e,t]=await Promise.all([de(),te()]),r=e?.filter(e=>e&&typeof e==`object`&&e.id&&e.userId)||[];n(r);let i=t||[];if(x(i),i.length>0){let e=i.some(e=>e.id===B);(!B||!e)&&V(i[0].id)}else V(``);T(null)}catch(e){console.error(`Data fetch error:`,e),n([]),x([]);let t=`Failed to fetch data`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch data`}T(t),X({title:`Error`,description:t,variant:`destructive`})}finally{C(!1)}},[B,X]);(0,v.useEffect)(()=>{Z()},[Z]),(0,v.useEffect)(()=>{let e=()=>d.emit(`subscribe`,{channel:`context`}),t=()=>d.emit(`unsubscribe`,{channel:`context`}),r=d.on(`connect`,e);console.log(`Subscribing to context events`),e();let i=e=>{let t=e;if(console.log(`Received context created:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:created event:`,t);return}n(e=>e.some(e=>e&&e.id===t.id&&e.userId===t.userId)?(console.log(`Context ${t.id} already exists, skipping duplicate add`),e):[...e,t])},a=e=>{let t=e;if(console.log(`Received context update:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:updated event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},o=e=>{let t=e;console.log(`Received context deletion:`,t);let r=t?.contextId??t?.id;if(!r){console.error(`Invalid context deletion data received:`,t);return}n(e=>e.filter(e=>e&&e.id!==r))},s=e=>{let t=e;if(console.log(`Received context URL change:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:url:changed event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},c=[[`context:created`,i],[`context.created`,i],[`context:updated`,a],[`context.updated`,a],[`context:deleted`,o],[`context.deleted`,o],[`context:url:changed`,s],[`context.url.set`,s],[`context:url:set`,s]];return c.forEach(([e,t])=>d.on(e,t)),()=>{console.log(`Unsubscribing from context events`),t(),r?.(),c.forEach(([e,t])=>d.off(e,t))}},[]);let xe=async t=>{if(t.preventDefault(),!M.trim()||!B||!E.trim()){X({title:`Missing Fields`,description:`Context ID, Context URL and Workspace are required.`,variant:`destructive`});return}U(!0);try{let t={id:E,name:O.trim()||void 0,url:M,description:P.trim()||void 0,metadata:{ui:{color:I}},workspaceId:B,baseUrl:R||void 0,treeType:A},n=await ue(t);D(``),k(``),N(`/`),F(``),L(null),z(`/`),await Z(),X({title:`Success`,description:`Context created successfully`}),G(!1),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),e(`/contexts/${n.id}`)}catch(e){let t=be(e,`Context creation error:`,`Failed to create context`);X({title:`Error`,description:t,variant:`destructive`})}finally{U(!1)}},Se=async e=>{let n=t.find(t=>t.id===e);if(n&&n.url&&(n.url.endsWith(`/default`)||n.url.includes(`://default`))){X({title:`Error`,description:`Cannot delete the default context`,variant:`destructive`});return}Y(e)},Ce=async()=>{if(J)try{await p(J),n(e=>e.filter(e=>!le(e,{id:J}))),X({title:`Success`,description:`Context deleted successfully`})}catch(e){console.error(`Context deletion error:`,e);let t=`Failed to delete context`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to delete context`}X({title:`Error`,description:t,variant:`destructive`})}finally{Y(null)}},we=t=>{let n=t.isShared||t.type===`shared`;e(n?`/contexts/${t.id}?ownerId=${encodeURIComponent(t.userId)}`:`/contexts/${t.id}`)},Te=e=>{q(e)},Ee=async e=>{if(e.preventDefault(),K)try{n(e=>e.map(e=>e.id===K.id&&e.userId===K.userId?K:e)),X({title:`Success`,description:`Context updated successfully (mock update)`}),q(null)}catch(e){let t=e instanceof Error?e.message:`Failed to update context`;X({title:`Error`,description:t,variant:`destructive`})}},De=(0,v.useMemo)(()=>({type:e=>e.isShared||e.type===`shared`?`shared`:`owned`,id:e=>e.id??``,owner:e=>e.isShared||e.type===`shared`?e.ownerEmail||e.userId||``:`you`,url:e=>e.url??``,workspaceId:e=>e.workspaceId??``,baseUrl:e=>e.baseUrl??``,path:e=>e.path??``,locked:e=>+!!e.locked,created:e=>Date.parse(e.createdAt)||0,updated:e=>Date.parse(e.updatedAt)||0}),[]),{sorted:Oe,sort:Q,toggleSort:$}=ge(t.filter(e=>e!=null),De);return(0,b.jsxs)(`div`,{className:`space-y-6`,children:[(0,b.jsx)(_e,{title:`Contexts`,description:`Create and manage contexts in your workspaces. View contexts shared with you.`,actions:!W&&(0,b.jsxs)(l,{onClick:()=>G(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create context`,title:`Create context`,children:[(0,b.jsx)(i,{className:`h-4 w-4 sm:mr-2`}),(0,b.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Context`})]})}),W&&(0,b.jsx)(ve,{title:`Create New Context`,onClose:()=>G(!1),children:(0,b.jsxs)(`form`,{onSubmit:xe,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`workspace`,className:`block text-sm font-medium mb-1`,children:`Workspace`}),(0,b.jsxs)(`select`,{id:`workspace`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:B,onChange:e=>V(e.target.value),disabled:H||y.length===0,children:[y.length===0&&(0,b.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),y.map(e=>(0,b.jsx)(`option`,{value:e.id,children:e.label||e.name},`${e.owner}-${e.id}`))]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`newContextId`,className:`block text-sm font-medium mb-1`,children:`Context ID`}),(0,b.jsx)(u,{id:`newContextId`,value:E,onChange:e=>D(e.target.value),placeholder:`e.g., my-new-context`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`url`,value:M,onChange:N,placeholder:`e.g., /project/path/resource`,disabled:H,pickerTitle:`Context URL path…`,onPickTarget:(e,t)=>{N(e),j(t.treeType);let n=y.find(e=>e.name===t.workspaceName||e.id===t.workspaceName);n&&V(n.id)}})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`baseUrl`,className:`block text-sm font-medium mb-1`,children:`Base URL (Optional)`}),(0,b.jsx)(m,{id:`baseUrl`,value:R,onChange:z,format:`path`,placeholder:`e.g., /base/path`,disabled:H,pickerTitle:`Base path…`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`description`,className:`block text-sm font-medium mb-1`,children:`Description (Optional)`}),(0,b.jsx)(u,{id:`description`,value:P,onChange:e=>F(e.target.value),placeholder:`Description`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextColor`,className:`block text-sm font-medium mb-1`,children:`Color (Optional)`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(u,{id:`contextColor`,type:`color`,value:I||`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:H}),(0,b.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:H||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Uses the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextName`,className:`block text-sm font-medium mb-1`,children:`Name (Optional)`}),(0,b.jsx)(u,{id:`contextName`,value:O,onChange:e=>k(e.target.value),placeholder:`My Context`,disabled:H})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`treeType`,className:`block text-sm font-medium mb-1`,children:`Tree`}),(0,b.jsxs)(`select`,{id:`treeType`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:A,onChange:e=>j(e.target.value),disabled:H,children:[(0,b.jsx)(`option`,{value:`context`,children:`Context tree`}),(0,b.jsx)(`option`,{value:`directory`,children:`Directory tree`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Which workspace tree this context navigates.`})]})]}),(0,b.jsxs)(l,{type:`submit`,disabled:H||!M.trim()||!B||!E.trim(),children:[(0,b.jsx)(i,{className:`mr-2 h-4 w-4`}),`Create Context`]})]})}),(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Contexts & Shared Contexts`}),S&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading contexts...`}),w&&(0,b.jsx)(`div`,{className:`text-center text-destructive`,children:(0,b.jsx)(`p`,{children:w})}),!S&&!w&&t.length===0&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No contexts found. Create one above.`}),t.length>0&&(0,b.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,b.jsxs)(me,{children:[(0,b.jsx)(he,{children:(0,b.jsxs)(g,{children:[(0,b.jsx)(_,{label:`Type`,sortKey:`type`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`ID`,sortKey:`id`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Owner`,sortKey:`owner`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Context URL`,sortKey:`url`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Workspace ID`,sortKey:`workspaceId`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Base URL`,sortKey:`baseUrl`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Path`,sortKey:`path`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Locked`,sortKey:`locked`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Created`,sortKey:`created`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Updated`,sortKey:`updated`,sort:Q,onSort:$}),(0,b.jsx)(pe,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(fe,{children:Oe.map(e=>{if(!e)return console.warn(`Found null/undefined context in contexts array, skipping`),null;let t=e.createdAt?new Date(e.createdAt).toLocaleDateString():`-`,n=e.updatedAt?new Date(e.updatedAt).toLocaleDateString():`-`,r=e.isShared||e.type===`shared`,i=r?e.ownerEmail||e.userId||`-`:`You`,u=r&&e.sharedVia?typeof e.sharedVia==`string`?e.sharedVia:e.sharedVia.accessLevel||`-`:`-`;return(0,b.jsxs)(g,{children:[(0,b.jsx)(h,{children:r?(0,b.jsxs)(`div`,{className:`flex items-center gap-1 text-info`,title:`Shared with you (${u})`,children:[(0,b.jsx)(s,{className:`h-4 w-4`}),(0,b.jsx)(`span`,{className:`text-xs`,children:`Shared`})]}):(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Owned`})}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.id||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,title:r?`Owned by: ${i}`:`You are the owner`,children:i}),(0,b.jsx)(h,{className:`font-mono text-sm max-w-xs truncate`,title:e.url||`-`,children:e.url||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.workspaceId||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.baseUrl||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.path||`-`}),(0,b.jsx)(h,{children:e.locked?`Yes`:`No`}),(0,b.jsx)(h,{children:t}),(0,b.jsx)(h,{children:n}),(0,b.jsx)(h,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Te(e),title:`Edit Context`,children:(0,b.jsx)(o,{className:`h-4 w-4`})}),(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>we(e),title:r?`Open Shared Context`:`Open Context Details`,children:(0,b.jsx)(c,{className:`h-4 w-4`})}),!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Se(e.id),disabled:!!(e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))),className:`text-destructive hover:bg-destructive/10 hover:text-destructive disabled:opacity-50 disabled:cursor-not-allowed`,title:e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))?`Cannot delete default context`:`Delete Context`,children:(0,b.jsx)(a,{className:`h-4 w-4`})})]})})]},`${e.userId}-${e.id}`)})})]})})]}),K&&(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Edit Context`}),(0,b.jsxs)(`form`,{onSubmit:Ee,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-id`,className:`block text-sm font-medium mb-1`,children:`Context ID (read-only)`}),(0,b.jsx)(u,{id:`edit-context-id`,value:K.id,disabled:!0,className:`bg-muted`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`edit-context-url`,value:K.url,onChange:e=>q(t=>t?{...t,url:e}:null),placeholder:`workspace://path or /path`,pickerTitle:`Context URL path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Use format: workspace://path or /path for current workspace`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-base-url`,className:`block text-sm font-medium mb-1`,children:`Base URL (optional)`}),(0,b.jsx)(m,{id:`edit-base-url`,value:K.baseUrl||``,onChange:e=>q(t=>t?{...t,baseUrl:e||null}:null),format:`path`,placeholder:`/base/path`,pickerTitle:`Base path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restricts context navigation to this base path`})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(l,{type:`submit`,children:`Save Changes`}),(0,b.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>q(null),children:`Cancel`})]})]})]}),(0,b.jsx)(ce,{open:J!==null,onOpenChange:e=>!e&&Y(null),children:(0,b.jsxs)(f,{children:[(0,b.jsxs)(se,{children:[(0,b.jsx)(re,{children:`Delete Context`}),(0,b.jsx)(ne,{children:`Are you sure you want to delete this context? This action cannot be undone.`})]}),(0,b.jsxs)(ae,{children:[(0,b.jsx)(oe,{children:`Cancel`}),(0,b.jsx)(ie,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})}export{x as default};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Nt as i,Y as a,at as o,mt as s,vr as c}from"./ui-Byg1cZDr.js";import{t as l}from"./button-SgR3GVvV.js";import{t as u}from"./input-BOtCd4HP.js";import{t as d}from"./socket-CtH3EU9m.js";import{n as ee}from"./use-toast-BlLDqSUO.js";import{Pt as te}from"./workspace-CrSpR4xf.js";import{a as ne,c as re,i as f,n as ie,o as ae,r as oe,s as se,t as ce}from"./alert-dialog-izlVMXfa.js";import{O as le,n as ue,p as de,r as p}from"./context-DQoZFMDQ.js";import{t as m}from"./PathPickerField-fZazwxCN.js";import{a as h,c as g,i as fe,n as _,o as pe,r as me,s as he,t as ge}from"./use-sortable-data-BW_0sXBs.js";import{n as _e}from"./page-header-DkOHw0g-.js";import{t as ve}from"./form-panel-C34lByEH.js";import{t as ye}from"./use-create-panel-DhSNIGtr.js";var v=e(n(),1);function y(e,t=`An error occurred`){if(e instanceof Error)return e.message;if(typeof e==`object`&&e){let n=e;return n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||t}return t}function be(e,t,n=`An error occurred`){return console.error(t,e),y(e,n)}var b=t();function x(){let e=r(),[t,n]=(0,v.useState)([]),[y,x]=(0,v.useState)([]),[S,C]=(0,v.useState)(!0),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(`context`),[M,N]=(0,v.useState)(`/`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(null),[R,z]=(0,v.useState)(`/`),[B,V]=(0,v.useState)(``),[H,U]=(0,v.useState)(!1),[W,G]=ye(),[K,q]=(0,v.useState)(null),[J,Y]=(0,v.useState)(null),{showToast:X}=ee();(0,v.useEffect)(()=>{d.isConnected()||(console.log(`Socket not connected, attempting to connect...`),d.reconnect())},[]);let Z=(0,v.useCallback)(async()=>{try{C(!0);let[e,t]=await Promise.all([de(),te()]),r=e?.filter(e=>e&&typeof e==`object`&&e.id&&e.userId)||[];n(r);let i=t||[];if(x(i),i.length>0){let e=i.some(e=>e.id===B);(!B||!e)&&V(i[0].id)}else V(``);T(null)}catch(e){console.error(`Data fetch error:`,e),n([]),x([]);let t=`Failed to fetch data`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to fetch data`}T(t),X({title:`Error`,description:t,variant:`destructive`})}finally{C(!1)}},[B,X]);(0,v.useEffect)(()=>{Z()},[Z]),(0,v.useEffect)(()=>{let e=()=>d.emit(`subscribe`,{channel:`context`}),t=()=>d.emit(`unsubscribe`,{channel:`context`}),r=d.on(`connect`,e);console.log(`Subscribing to context events`),e();let i=e=>{let t=e;if(console.log(`Received context created:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:created event:`,t);return}n(e=>e.some(e=>e&&e.id===t.id&&e.userId===t.userId)?(console.log(`Context ${t.id} already exists, skipping duplicate add`),e):[...e,t])},a=e=>{let t=e;if(console.log(`Received context update:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:updated event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},o=e=>{let t=e;console.log(`Received context deletion:`,t);let r=t?.contextId??t?.id;if(!r){console.error(`Invalid context deletion data received:`,t);return}n(e=>e.filter(e=>e&&e.id!==r))},s=e=>{let t=e;if(console.log(`Received context URL change:`,t),!t||!t.id||!t.userId){console.error(`Invalid context data received in context:url:changed event:`,t);return}n(e=>e.map(e=>e&&e.id===t.id&&e.userId===t.userId?{...e,...t}:e))},c=[[`context:created`,i],[`context.created`,i],[`context:updated`,a],[`context.updated`,a],[`context:deleted`,o],[`context.deleted`,o],[`context:url:changed`,s],[`context.url.set`,s],[`context:url:set`,s]];return c.forEach(([e,t])=>d.on(e,t)),()=>{console.log(`Unsubscribing from context events`),t(),r?.(),c.forEach(([e,t])=>d.off(e,t))}},[]);let xe=async t=>{if(t.preventDefault(),!M.trim()||!B||!E.trim()){X({title:`Missing Fields`,description:`Context ID, Context URL and Workspace are required.`,variant:`destructive`});return}U(!0);try{let t={id:E,name:O.trim()||void 0,url:M,description:P.trim()||void 0,metadata:{ui:{color:I}},workspaceId:B,baseUrl:R||void 0,treeType:A},n=await ue(t);D(``),k(``),N(`/`),F(``),L(null),z(`/`),await Z(),X({title:`Success`,description:`Context created successfully`}),G(!1),window.dispatchEvent(new CustomEvent(`contexts:refresh`)),e(`/contexts/${n.id}`)}catch(e){let t=be(e,`Context creation error:`,`Failed to create context`);X({title:`Error`,description:t,variant:`destructive`})}finally{U(!1)}},Se=async e=>{let n=t.find(t=>t.id===e);if(n&&n.url&&(n.url.endsWith(`/default`)||n.url.includes(`://default`))){X({title:`Error`,description:`Cannot delete the default context`,variant:`destructive`});return}Y(e)},Ce=async()=>{if(J)try{await p(J),n(e=>e.filter(e=>!le(e,{id:J}))),X({title:`Success`,description:`Context deleted successfully`})}catch(e){console.error(`Context deletion error:`,e);let t=`Failed to delete context`;if(e instanceof Error)t=e.message;else if(typeof e==`object`&&e){let n=e;t=n.message||n.error||n.payload?.message||n.payload?.error||n.statusText||`Failed to delete context`}X({title:`Error`,description:t,variant:`destructive`})}finally{Y(null)}},we=t=>{let n=t.isShared||t.type===`shared`;e(n?`/contexts/${t.id}?ownerId=${encodeURIComponent(t.userId)}`:`/contexts/${t.id}`)},Te=e=>{q(e)},Ee=async e=>{if(e.preventDefault(),K)try{n(e=>e.map(e=>e.id===K.id&&e.userId===K.userId?K:e)),X({title:`Success`,description:`Context updated successfully (mock update)`}),q(null)}catch(e){let t=e instanceof Error?e.message:`Failed to update context`;X({title:`Error`,description:t,variant:`destructive`})}},De=(0,v.useMemo)(()=>({type:e=>e.isShared||e.type===`shared`?`shared`:`owned`,id:e=>e.id??``,owner:e=>e.isShared||e.type===`shared`?e.ownerEmail||e.userId||``:`you`,url:e=>e.url??``,workspaceId:e=>e.workspaceId??``,baseUrl:e=>e.baseUrl??``,path:e=>e.path??``,locked:e=>+!!e.locked,created:e=>Date.parse(e.createdAt)||0,updated:e=>Date.parse(e.updatedAt)||0}),[]),{sorted:Oe,sort:Q,toggleSort:$}=ge(t.filter(e=>e!=null),De);return(0,b.jsxs)(`div`,{className:`space-y-6`,children:[(0,b.jsx)(_e,{title:`Contexts`,description:`Create and manage contexts in your workspaces. View contexts shared with you.`,actions:!W&&(0,b.jsxs)(l,{onClick:()=>G(!0),className:`max-sm:h-9 max-sm:w-9 max-sm:p-0`,"aria-label":`Create context`,title:`Create context`,children:[(0,b.jsx)(i,{className:`h-4 w-4 sm:mr-2`}),(0,b.jsx)(`span`,{className:`max-sm:hidden`,children:`Create Context`})]})}),W&&(0,b.jsx)(ve,{title:`Create New Context`,onClose:()=>G(!1),children:(0,b.jsxs)(`form`,{onSubmit:xe,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`workspace`,className:`block text-sm font-medium mb-1`,children:`Workspace`}),(0,b.jsxs)(`select`,{id:`workspace`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:B,onChange:e=>V(e.target.value),disabled:H||y.length===0,children:[y.length===0&&(0,b.jsx)(`option`,{value:``,children:`No workspaces available. Create one first.`}),y.map(e=>(0,b.jsx)(`option`,{value:e.id,children:e.label||e.name},`${e.owner}-${e.id}`))]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`newContextId`,className:`block text-sm font-medium mb-1`,children:`Context ID`}),(0,b.jsx)(u,{id:`newContextId`,value:E,onChange:e=>D(e.target.value),placeholder:`e.g., my-new-context`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`url`,value:M,onChange:N,placeholder:`e.g., /project/path/resource`,disabled:H,pickerTitle:`Context URL path…`,onPickTarget:(e,t)=>{N(e),j(t.treeType);let n=y.find(e=>e.name===t.workspaceName||e.id===t.workspaceName);n&&V(n.id)}})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`baseUrl`,className:`block text-sm font-medium mb-1`,children:`Base URL (Optional)`}),(0,b.jsx)(m,{id:`baseUrl`,value:R,onChange:z,format:`path`,placeholder:`e.g., /base/path`,disabled:H,pickerTitle:`Base path…`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`description`,className:`block text-sm font-medium mb-1`,children:`Description (Optional)`}),(0,b.jsx)(u,{id:`description`,value:P,onChange:e=>F(e.target.value),placeholder:`Description`,disabled:H})]})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextColor`,className:`block text-sm font-medium mb-1`,children:`Color (Optional)`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(u,{id:`contextColor`,type:`color`,value:I||`#808080`,onChange:e=>L(e.target.value),className:`h-10 w-16 p-1`,disabled:H}),(0,b.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,disabled:H||I===null,onClick:()=>L(null),children:`Use inherited color`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:I===null?`Uses the tree folder or workspace color.`:`Applies only to this context.`})]}),(0,b.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`contextName`,className:`block text-sm font-medium mb-1`,children:`Name (Optional)`}),(0,b.jsx)(u,{id:`contextName`,value:O,onChange:e=>k(e.target.value),placeholder:`My Context`,disabled:H})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`treeType`,className:`block text-sm font-medium mb-1`,children:`Tree`}),(0,b.jsxs)(`select`,{id:`treeType`,className:`w-full px-3 py-2 border border-border rounded-md shadow-elevation-1 focus:outline-none focus:ring-primary focus:border-primary`,value:A,onChange:e=>j(e.target.value),disabled:H,children:[(0,b.jsx)(`option`,{value:`context`,children:`Context tree`}),(0,b.jsx)(`option`,{value:`directory`,children:`Directory tree`})]}),(0,b.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Which workspace tree this context navigates.`})]})]}),(0,b.jsxs)(l,{type:`submit`,disabled:H||!M.trim()||!B||!E.trim(),children:[(0,b.jsx)(i,{className:`mr-2 h-4 w-4`}),`Create Context`]})]})}),(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Your Contexts & Shared Contexts`}),S&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`Loading contexts...`}),w&&(0,b.jsx)(`div`,{className:`text-center text-destructive`,children:(0,b.jsx)(`p`,{children:w})}),!S&&!w&&t.length===0&&(0,b.jsx)(`p`,{className:`text-center text-muted-foreground`,children:`No contexts found. Create one above.`}),t.length>0&&(0,b.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,b.jsxs)(me,{children:[(0,b.jsx)(he,{children:(0,b.jsxs)(g,{children:[(0,b.jsx)(_,{label:`Type`,sortKey:`type`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`ID`,sortKey:`id`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Owner`,sortKey:`owner`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Context URL`,sortKey:`url`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Workspace ID`,sortKey:`workspaceId`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Base URL`,sortKey:`baseUrl`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Path`,sortKey:`path`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Locked`,sortKey:`locked`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Created`,sortKey:`created`,sort:Q,onSort:$}),(0,b.jsx)(_,{label:`Updated`,sortKey:`updated`,sort:Q,onSort:$}),(0,b.jsx)(pe,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(fe,{children:Oe.map(e=>{if(!e)return console.warn(`Found null/undefined context in contexts array, skipping`),null;let t=e.createdAt?new Date(e.createdAt).toLocaleDateString():`-`,n=e.updatedAt?new Date(e.updatedAt).toLocaleDateString():`-`,r=e.isShared||e.type===`shared`,i=r?e.ownerEmail||e.userId||`-`:`You`,u=r&&e.sharedVia?typeof e.sharedVia==`string`?e.sharedVia:e.sharedVia.accessLevel||`-`:`-`;return(0,b.jsxs)(g,{children:[(0,b.jsx)(h,{children:r?(0,b.jsxs)(`div`,{className:`flex items-center gap-1 text-info`,title:`Shared with you (${u})`,children:[(0,b.jsx)(s,{className:`h-4 w-4`}),(0,b.jsx)(`span`,{className:`text-xs`,children:`Shared`})]}):(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Owned`})}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.id||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,title:r?`Owned by: ${i}`:`You are the owner`,children:i}),(0,b.jsx)(h,{className:`font-mono text-sm max-w-xs truncate`,title:e.url||`-`,children:e.url||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.workspaceId||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.baseUrl||`-`}),(0,b.jsx)(h,{className:`font-mono text-sm`,children:e.path||`-`}),(0,b.jsx)(h,{children:e.locked?`Yes`:`No`}),(0,b.jsx)(h,{children:t}),(0,b.jsx)(h,{children:n}),(0,b.jsx)(h,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Te(e),title:`Edit Context`,children:(0,b.jsx)(o,{className:`h-4 w-4`})}),(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>we(e),title:r?`Open Shared Context`:`Open Context Details`,children:(0,b.jsx)(c,{className:`h-4 w-4`})}),!r&&(0,b.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>Se(e.id),disabled:!!(e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))),className:`text-destructive hover:bg-destructive/10 hover:text-destructive disabled:opacity-50 disabled:cursor-not-allowed`,title:e.url&&(e.url.endsWith(`/default`)||e.url.includes(`://default`))?`Cannot delete default context`:`Delete Context`,children:(0,b.jsx)(a,{className:`h-4 w-4`})})]})})]},`${e.userId}-${e.id}`)})})]})})]}),K&&(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Edit Context`}),(0,b.jsxs)(`form`,{onSubmit:Ee,className:`space-y-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-id`,className:`block text-sm font-medium mb-1`,children:`Context ID (read-only)`}),(0,b.jsx)(u,{id:`edit-context-id`,value:K.id,disabled:!0,className:`bg-muted`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-context-url`,className:`block text-sm font-medium mb-1`,children:`Context URL`}),(0,b.jsx)(m,{id:`edit-context-url`,value:K.url,onChange:e=>q(t=>t?{...t,url:e}:null),placeholder:`workspace://path or /path`,pickerTitle:`Context URL path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Use format: workspace://path or /path for current workspace`})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`label`,{htmlFor:`edit-base-url`,className:`block text-sm font-medium mb-1`,children:`Base URL (optional)`}),(0,b.jsx)(m,{id:`edit-base-url`,value:K.baseUrl||``,onChange:e=>q(t=>t?{...t,baseUrl:e||null}:null),format:`path`,placeholder:`/base/path`,pickerTitle:`Base path…`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Restricts context navigation to this base path`})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(l,{type:`submit`,children:`Save Changes`}),(0,b.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>q(null),children:`Cancel`})]})]})]}),(0,b.jsx)(ce,{open:J!==null,onOpenChange:e=>!e&&Y(null),children:(0,b.jsxs)(f,{children:[(0,b.jsxs)(se,{children:[(0,b.jsx)(re,{children:`Delete Context`}),(0,b.jsx)(ne,{children:`Are you sure you want to delete this context? This action cannot be undone.`})]}),(0,b.jsxs)(ae,{children:[(0,b.jsx)(oe,{children:`Cancel`}),(0,b.jsx)(ie,{onClick:Ce,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})}export{x as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{Br as i,L as a,Vr as o,qr as s}from"./ui-Byg1cZDr.js";import{t as c}from"./utils-2pl1SbIp.js";import{
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{yt as r}from"./react-BHzhHVTZ.js";import{Br as i,L as a,Vr as o,qr as s}from"./ui-Byg1cZDr.js";import{t as c}from"./utils-2pl1SbIp.js";import{Vn as l}from"./workspace-CrSpR4xf.js";import{n as u}from"./tags-YamdPoBK.js";import{o as d}from"./useAddTarget-CqnDU0Om.js";import{r as f}from"./relation-events-CKio19hE.js";var p=e(n(),1),m=`2.1`,h=[`pending`,`in-progress`,`completed`,`cancelled`],g={pending:`Pending`,"in-progress":`In progress`,completed:`Completed`,cancelled:`Cancelled`};function _(e){return String(e).padStart(2,`0`)}function v(e){return`${e.getFullYear()}-${_(e.getMonth()+1)}-${_(e.getDate())}T${_(e.getHours())}:${_(e.getMinutes())}`}function y(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:v(t)}function b(e){if(!e)return;let t=new Date(e);return Number.isNaN(t.getTime())?void 0:t.toISOString()}function x(){let e=new Date;return e.setHours(23,59,0,0),v(e)}function S(e){let t=b(e.due);return{title:e.title.trim(),...e.description.trim()?{description:e.description.trim()}:{},status:e.status,completed:e.status===`completed`,...t?{dueDate:t}:{},...e.priority===``?{}:{priority:Number(e.priority)}}}function C(){let[e,t]=(0,p.useState)(``),[n,r]=(0,p.useState)(``),[i,a]=(0,p.useState)(`pending`),[o,s]=(0,p.useState)(``),[c,h]=(0,p.useState)(x()),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)(``),[b,C]=(0,p.useState)(!1),w=f(),T=e.trim().length>0&&!b;async function E(t){C(!0);try{let r=await w.capture(),a=v.trim(),s={schema:l,schemaVersion:m,data:S({title:e,description:n,status:i,priority:o,due:c}),...a?{comment:a}:{},metadata:{features:u(g),...r?{geo:r}:{}}};return await d(t,[s])}finally{C(!1)}}return{title:e,setTitle:t,description:n,setDescription:r,status:i,setStatus:a,priority:o,setPriority:s,due:c,setDue:h,tags:g,setTags:_,comment:v,setComment:y,saving:b,canSave:T,save:E,geotag:w}}var w=e(r(),1),T=t(),E=15,D=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function O(e){return String(e).padStart(2,`0`)}function k(e){let t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e||``);return t?{date:`${t[1]}-${t[2]}-${t[3]}`,time:`${t[4]}:${t[5]}`}:null}function A(e){return`${e.getFullYear()}-${O(e.getMonth()+1)}-${O(e.getDate())}`}function j(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function M(){let e=new Date;return e.setSeconds(0,0),e.setMinutes(Math.ceil(e.getMinutes()/E)*E),`${O(e.getHours())}:${O(e.getMinutes())}`}function N(){let e=[];for(let t=0;t<1440;t+=E)e.push(`${O(Math.floor(t/60))}:${O(t%60)}`);return e}var P=N();function F(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7,r=new Date(t);return r.setDate(t.getDate()-n),Array.from({length:42},(e,t)=>{let n=new Date(r);return n.setDate(r.getDate()+t),n})}function I(e){let[t,n]=e.split(`:`).map(Number);return new Date(2e3,0,1,t,n).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function L(e){let t=k(e);if(!t)return``;let[n,r,i]=t.date.split(`-`).map(Number),[a,o]=t.time.split(`:`).map(Number);return new Date(n,r-1,i,a,o).toLocaleString(void 0,{weekday:`short`,day:`numeric`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}function R({value:e,onChange:t,id:n,placeholder:r=`Pick a date & time`,clearable:i=!0,disabled:o=!1,compact:l=!1,className:u=``}){let[d,f]=(0,p.useState)(!1),m=(0,p.useRef)(null),h=k(e),g=h?L(e):``;return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`button`,{ref:m,id:n,type:`button`,disabled:o,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,className:c(`inline-flex w-full items-center gap-2 rounded-md border border-input bg-transparent text-left shadow-elevation-1 transition-colors`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,l?`h-6 px-1.5 text-[11px]`:`h-9 px-3 py-1 text-sm`,!h&&`text-muted-foreground`,u),children:[(0,T.jsx)(s,{className:c(`shrink-0 text-muted-foreground`,l?`h-3 w-3`:`h-4 w-4`)}),(0,T.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:g||r}),i&&h&&(0,T.jsx)(`span`,{role:`button`,tabIndex:-1,"aria-label":`Clear date`,title:`Clear`,onClick:e=>{e.stopPropagation(),t(``)},className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(a,{className:l?`h-2.5 w-2.5`:`h-3.5 w-3.5`})})]}),d&&(0,T.jsx)(z,{anchorRef:m,value:e,onChange:t,onClose:()=>f(!1)})]})}function z({anchorRef:e,value:t,onChange:n,onClose:r}){let a=k(t),s=a?.date??A(new Date),l=a?.time??null,[u,d]=(0,p.useState)(()=>{let e=j(s);return new Date(e.getFullYear(),e.getMonth(),1)}),f=(0,p.useRef)(null),m=(0,p.useRef)(null),[h,g]=(0,p.useState)(null);(0,p.useLayoutEffect)(()=>{let t=f.current,n=e.current;if(!t||!n)return;let r=()=>{let e=n.getBoundingClientRect(),{width:r,height:i}=t.getBoundingClientRect(),a=e.bottom+4,o=a+i+8>window.innerHeight?Math.max(8,e.top-i-4):a,s=Math.max(8,Math.min(e.left,window.innerWidth-r-8));g({x:s,y:o})};r();let i=new ResizeObserver(r);return i.observe(t),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{i.disconnect(),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0)}},[e]),(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.stopPropagation(),r())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[r]);let _=(0,p.useMemo)(()=>!l||P.includes(l)?P:[...P,l].sort(),[l]);(0,p.useEffect)(()=>{let e=m.current,t=e?.querySelector(`[data-selected="true"]`);e&&t&&(e.scrollTop=t.offsetTop-e.clientHeight/2+t.clientHeight/2)},[]);let v=(e,t)=>n(`${e}T${t}`),y=e=>{let t=l??M();v(A(e),t),e.getMonth()!==u.getMonth()&&d(new Date(e.getFullYear(),e.getMonth(),1))},b=e=>{v(s,e),r()},x=e=>{let t=new Date;t.setDate(t.getDate()+e);let n=l??M();v(A(t),n),d(new Date(t.getFullYear(),t.getMonth(),1))},S=A(new Date),C=F(u);return(0,w.createPortal)((0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:r}),(0,T.jsxs)(`div`,{ref:f,role:`dialog`,"aria-label":`Choose date and time`,className:`fixed z-50 flex max-w-[95vw] gap-2 rounded-md border bg-popover p-2 text-popover-foreground shadow-elevation-4`,style:{left:h?.x??-9999,top:h?.y??-9999,visibility:h?`visible`:`hidden`},children:[(0,T.jsxs)(`div`,{className:`w-[236px]`,children:[(0,T.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()-1,1)),"aria-label":`Previous month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(o,{className:`h-4 w-4`})}),(0,T.jsx)(`span`,{className:`text-xs font-medium`,children:u.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>d(new Date(u.getFullYear(),u.getMonth()+1,1)),"aria-label":`Next month`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,T.jsx)(i,{className:`h-4 w-4`})})]}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5 px-0.5 pb-1 text-center text-[10px] uppercase tracking-wide text-muted-foreground/70`,children:D.map(e=>(0,T.jsx)(`span`,{children:e},e))}),(0,T.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5`,children:C.map(e=>{let t=A(e),n=e.getMonth()!==u.getMonth(),r=t===s&&!!a;return(0,T.jsx)(`button`,{type:`button`,onClick:()=>y(e),"aria-pressed":r,className:c(`h-7 rounded text-xs tabular-nums transition-colors`,n?`text-muted-foreground/40`:`text-foreground`,r?`bg-primary text-primary-foreground`:`hover:bg-muted`,!r&&t===S&&`font-semibold ring-1 ring-inset ring-border`),children:e.getDate()},t)})}),(0,T.jsx)(`div`,{className:`mt-1.5 flex gap-1`,children:[[`Today`,0],[`Tomorrow`,1],[`Next week`,7]].map(([e,t])=>(0,T.jsx)(`button`,{type:`button`,onClick:()=>x(t),className:`flex-1 rounded border border-border px-1.5 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:e},e))})]}),(0,T.jsxs)(`div`,{className:`flex w-[104px] flex-col`,children:[(0,T.jsx)(`input`,{type:`time`,step:900,value:l??``,onChange:e=>{e.target.value&&v(s,e.target.value.slice(0,5))},"aria-label":`Time`,className:`mb-1 h-7 w-full rounded border border-input bg-transparent px-1.5 text-xs tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`}),(0,T.jsx)(`div`,{ref:m,className:`max-h-[236px] flex-1 overflow-y-auto pr-0.5`,children:_.map(e=>{let t=e===l;return(0,T.jsx)(`button`,{type:`button`,"data-selected":t,onClick:()=>b(e),"aria-pressed":t,className:c(`block w-full rounded px-2 py-1 text-left text-xs tabular-nums transition-colors`,t?`bg-primary text-primary-foreground`:`hover:bg-muted`),children:I(e)},e)})})]})]})]}),document.body)}export{y as a,C as c,S as i,h as n,b as o,g as r,x as s,R as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./button-SgR3GVvV.js";import{
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{_ as r,g as i,h as a}from"./chunk-62JRHF6Z-vspAGgtK.js";import{t as o}from"./button-SgR3GVvV.js";import{An as s,nt as c,rt as l}from"./workspace-CrSpR4xf.js";import{t as u,u as d}from"./ObjectPropertiesCard-BIBMvx_i.js";import{t as f}from"./url-params-n7kU_WZ-.js";import{i as p}from"./use-menu-BiJ8N7sS.js";import{t as m}from"./workspace-content-gate-9okuA7J7.js";import{t as h}from"./use-workspace-identity-BCrrvfeE.js";var g=e(n(),1),_=t();function v(){let{workspaceName:e}=r();return e?(0,_.jsx)(m,{workspaceName:e,children:(0,_.jsx)(y,{})}):(0,_.jsx)(`p`,{role:`alert`,className:`p-6`,children:`Workspace not specified.`})}function y(){let{workspaceName:e=``,documentId:t=``,algo:n=``,checksum:m=``}=r(),v=i(),y=a(),{goBack:b,openM1Drawer:x,openM2Drawer:S}=p(),C=h(e),w=!!n&&!!m,T=w?`${n}/${m}`:t,E=JSON.stringify([e,t,n,m]),D=Number(t),O=/^\d+$/.test(t)&&Number.isSafeInteger(D)&&D>0,k=w||O,[A,j]=(0,g.useState)(0),[M,N]=(0,g.useState)(null),P=M?.identity===E?M:null,F=k&&(!P||P.revision!==A);(0,g.useEffect)(()=>{let t=!1;if(k)return(w?l(e,n,m):c(e,D)).then(e=>{t||N({identity:E,revision:A,document:e||null,missing:!e,error:``})}).catch(e=>{t||N({identity:E,revision:A,document:null,missing:e?.statusCode===404,error:e instanceof Error?e.message:`Unable to retrieve this document.`})}),()=>{t=!0}},[e,D,E,A,k,w,n,m]);let I={workspace:C?.label||e,workspaceIcon:C?.icon,path:`/`,tree:`context`,document:P?.document?s(P.document).title:`Document ${T}`,onBack:b,onBrowseWorkspaces:()=>x(`workspaces`),onBrowseTree:()=>S(`workspaces`,`detail`,e),onNavigatePath:t=>v(f(e,t,`context`))},L=y.hash.slice(1),R=[`view`,`location`,`metadata`,`json`,`synapses`,`backends`].includes(L)?L:`view`;return(0,_.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[!P?.document&&(0,_.jsx)(d,{...I}),P?.document?(0,_.jsx)(u,{document:P.document,workspaceId:e,onChanged:()=>j(e=>e+1),navigation:I,initialTab:R,onTabChange:e=>v(`${y.pathname}${y.search}#${e}`,{replace:!0}),tabActions:(0,_.jsx)(o,{variant:`ghost`,disabled:F,onClick:()=>j(e=>e+1),children:`Refresh`})},E):F?(0,_.jsx)(`p`,{role:`status`,className:`p-6 text-sm text-muted-foreground`,children:`Loading document…`}):(0,_.jsxs)(`div`,{role:`alert`,className:`space-y-2 p-6 text-sm`,children:[(0,_.jsx)(`p`,{className:`font-medium`,children:P?.missing?`Document ${T} not found`:`Unable to load document`}),k&&(0,_.jsx)(o,{variant:`outline`,onClick:()=>j(e=>e+1),children:`Retry`}),(0,_.jsx)(`p`,{className:`text-muted-foreground`,children:k?P?.missing?`This record is no longer available in this workspace. Subtree exports skip missing records and report their IDs.`:P?.error:`Document ID must be a positive integer.`})]})]})}export{v as default};
|