@pi-chamber/web 0.9.6 → 0.9.8-rc.1
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/README.md +1 -1
- package/dist/assets/{DiagramView-0Iq1ak1I.js → DiagramView-BMBrrFLy.js} +1 -1
- package/dist/assets/{DiffView-DD1AFRi3.js → DiffView-yVBxHkBI.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-CoKwDovb.js → FileSaveConflictDialog-D0siEm8l.js} +1 -1
- package/dist/assets/FilesView-CkcKBKkT.js +6 -0
- package/dist/assets/{GitView-LFEpCasf.js → GitView-CfuhQOfc.js} +3 -3
- package/dist/assets/{JsonTreeView-Cwjgvh4g.js → JsonTreeView-6kRdE1BO.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-_7kV1yNw.js → MarkdownRendererImpl-CRWbN_Jc.js} +2 -2
- package/dist/assets/{PatchDiff-DG43C1HW.js → PatchDiff-B0ssv8Aw.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-DCFXPY3d.js → SessionSwitcherContent-NmfI4B0Z.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-QY7FKuEQ.js → SessionSwitcherDropdown-DmE2hYTN.js} +2 -2
- package/dist/assets/SessionUnreadDot-LDTswryg.js +1 -0
- package/dist/assets/SettingsView-D0iw6y_H.js +2 -0
- package/dist/assets/SettingsWindow-BT2TzUBK.js +1 -0
- package/dist/assets/{ToolOutputDialog-IlCrS6BR.js → ToolOutputDialog-Bnl51bva.js} +4 -4
- package/dist/assets/{ToolPartDiffPreview-D68JV0rR.js → ToolPartDiffPreview-DgPtLS_h.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-Bl-rAYeh.js → VirtualizedFileDiff-D3zBpYIS.js} +4 -4
- package/dist/assets/collapsible-_urywMu5.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-FSOm2VrW.js → computeVirtualFileMetrics-y2AJzpKw.js} +2 -2
- package/dist/assets/{contextFileOpenGuard-Bxb6AIPa.js → contextFileOpenGuard-DYUFkrPT.js} +1 -1
- package/dist/assets/{gitStatusPredicates-DxolDpMd.js → gitStatusPredicates-CbFfOlbV.js} +1 -1
- package/dist/assets/index-BXgR2dKM.css +1 -0
- package/dist/assets/index-CrqlVJXp.js +8 -0
- package/dist/assets/{index-Dh58uD3I.js → index-DwJJarzh.js} +1 -1
- package/dist/assets/{isDiffPlainText-D3_04XCh.js → isDiffPlainText-kXPOivsq.js} +1 -1
- package/dist/assets/{isFilePlainText-CHouYQhH.js → isFilePlainText-BBIPqnLo.js} +1 -1
- package/dist/assets/{main-HzTrVvbB.js → main-BshSYpnV.js} +7 -7
- package/dist/assets/{main-CH3EqGJI.js → main-RrPyfmCA.js} +2 -2
- package/dist/assets/{markdownCore-DJU4KvHP.js → markdownCore-BxXmpZtB.js} +1 -1
- package/dist/assets/{miniChat-Ca3TpaaA.js → miniChat-DRNgmC-q.js} +2 -2
- package/dist/assets/{mobile-lj4gpGsO.js → mobile-CdmgVKW4.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-B80Jqq8b.js +2 -0
- package/dist/assets/renderMobileApp-CLcBvRiy.js +11 -0
- package/dist/assets/runtimeEndpointReset-DHHCemOu.js +53 -0
- package/dist/assets/{runtimeSurface-CE_VNjdH.js → runtimeSurface-C9kx2zfD.js} +1 -1
- package/dist/assets/{useAppFontEffects-BvFAP9zG.js → useAppFontEffects-Dp6vM-Zr.js} +104 -104
- package/dist/assets/{useFilesViewSearch-BD79p3A2.js → useFilesViewSearch-Bc8PTYrg.js} +2 -2
- package/dist/assets/{usePushVisibilityBeacon-CWg0j-Wg.js → usePushVisibilityBeacon-DMcKyNtE.js} +1 -1
- package/dist/assets/{useSwitcherItems-CazJ6Yox.js → useSwitcherItems-DEvsORZ_.js} +1 -1
- package/dist/assets/{vendor-base-ui-CdaWtC7e.js → vendor-base-ui-C60wdVnS.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CP3j3-xu.js → vendor-codemirror-language-data-DLimsiRH.js} +2 -2
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-Bkw82kL9.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-BZOGXAGe.js → vendor-floating-ui-react-dom-KLmnYDaG.js} +1 -1
- package/dist/assets/{web-components-DWuadqra.js → web-components-05Oa3k7a.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +17 -3
- package/server/lib/client-auth/DOCUMENTATION.md +184 -0
- package/server/lib/client-auth/live-revocation.test.js +567 -0
- package/server/lib/client-auth/principal-tracker.js +383 -0
- package/server/lib/client-auth/principal-tracker.test.js +321 -0
- package/server/lib/client-auth/remote-clients.js +31 -0
- package/server/lib/client-auth/remote-clients.test.js +44 -0
- package/server/lib/pi/event-stream.js +269 -0
- package/server/lib/pi/event-stream.test.js +776 -0
- package/server/lib/pi/routes.js +88 -31
- package/server/lib/pi/routes.test.js +92 -20
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -4
- package/server/lib/pi/session-daemon/ipc-client.js +19 -15
- package/server/lib/pi/session-daemon/ipc-client.test.js +113 -1
- package/server/lib/pi/session-daemon/prompt-preflight.test.js +5 -1
- package/server/lib/pi/session-daemon/send-operation-dedup.test.js +15 -5
- package/server/lib/pi/session-daemon/send-operation-registry.js +26 -23
- package/server/lib/pi/session-daemon/send-operation-registry.test.js +26 -20
- package/server/lib/pi/session-daemon/session-daemon-epoch.test.js +349 -0
- package/server/lib/pi/session-daemon/session-daemon.js +79 -18
- package/server/lib/pi/session-daemon/session-daemon.test.js +10 -4
- package/server/lib/pi/session-daemon/session-replay.test.js +8 -3
- package/server/lib/pi/session-daemon/supervisor.js +30 -5
- package/server/lib/pi/session-daemon/supervisor.test.js +4 -3
- package/server/lib/pi/ui-settings-store.js +7 -1
- package/server/lib/pi/ui-settings-store.test.js +19 -1
- package/server/lib/server/core-routes.js +11 -1
- package/server/lib/stt/DOCUMENTATION.md +2 -0
- package/server/lib/stt/runtime.js +39 -2
- package/server/lib/stt/runtime.test.js +53 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +48 -2
- package/server/lib/terminal/runtime.test.js +35 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +13 -4
- package/server/lib/ui-auth/ui-auth.js +98 -0
- package/server/lib/ui-auth/ui-auth.test.js +249 -0
- package/server/lib/workspace/host.js +3 -1
- package/dist/assets/FilesView-B_BF39ef.js +0 -6
- package/dist/assets/SessionUnreadDot-DGT31A3z.js +0 -1
- package/dist/assets/SettingsView-eG-wN-yY.js +0 -2
- package/dist/assets/SettingsWindow-Dvnp8YrA.js +0 -1
- package/dist/assets/collapsible-BjniCdZ5.js +0 -1
- package/dist/assets/index-BpmGBboM.css +0 -1
- package/dist/assets/index-DZnzXhTs.js +0 -8
- package/dist/assets/renderElectronMiniChatApp-rUFfaD-T.js +0 -2
- package/dist/assets/renderMobileApp-CcWQ1sCf.js +0 -11
- package/dist/assets/runtimeEndpointReset-D2MmSbDk.js +0 -53
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ tunnels, logs, pairing, and machine-readable output.
|
|
|
39
39
|
|
|
40
40
|
- Pi session state and actions are served only through `/api/pi/*`. Session detail responses carry a bounded transcript tail; older history is available from `GET /api/pi/sessions/:sessionId/messages` with the opaque before-cursor returned by the previous page.
|
|
41
41
|
- `POST /api/pi/attachments` accepts raw `application/octet-stream` bodies with bounded `X-PiChamber-Filename` and `X-PiChamber-Mime` metadata. It returns opaque attachment metadata plus `expiresAt`; filesystem paths remain private. The legacy base64 JSON body remains available for persisted clients. `DELETE /api/pi/attachments/:id` removes an unused upload. Prompt routes accept at most 20 attachment IDs and retire accepted uploads from the active 32-upload map while retaining their files until the one-hour expiry.
|
|
42
|
-
- PiChamber-owned UI settings, snippets, custom themes, and updates use `/api/pi/ui-settings`, `/api/pi/snippets`, `/api/pi/themes`, `/api/pi/update-check`, and `/api/pi/update-install`. The settings route merges portable preferences from `settings.json` with host and device values from `runtime-state.json`; writes split fields through explicit allowlists. Pi-owned resource, trust, and provider-catalog changes are saved without interrupting active sessions and report deferred runtime activation when an idle edge is required. A flat legacy file migrates on first access. A scoped portable file never contributes paths, project registrations, device values, or secrets. Removed `/api/config/*` and `/api/pichamber/*` aliases are not required. Snippets persist in the PiChamber data root (`snippets.json`) and expand through literal `#name` replacement; Pi prompt templates remain Pi-owned `/name` commands in Pi's global and trusted-project prompt directories, discovered through the active runtime's resource loader and exposed through `/api/pi/resources`, `/api/pi/resources/prompts`, and `/api/pi/commands`. Pi skills invoke as `/skill:name` (bare `/name` never invokes a skill) and extension commands use their registered `/name` (including Pi-generated suffixes); `/api/pi/commands` exposes prompts as `name`, skills as `skill:name`, and extensions under their invocation names, executed via Pi's `session.prompt()` with extension-first precedence. Snippet, prompt-template, skill, and extension-command concepts stay distinct with separate Settings pages, stores, persistence, and caches; they share only `/` autocomplete presentation. New-session starters are pinned Pi prompt templates that insert `/name ` for editing (never submit or expand in PiChamber); legacy skill starters are removed without conversion.
|
|
42
|
+
- PiChamber-owned UI settings, snippets, custom themes, and updates use `/api/pi/ui-settings`, `/api/pi/snippets`, `/api/pi/themes`, `/api/pi/update-check`, and `/api/pi/update-install`. The settings route merges portable preferences from `settings.json` with host and device values from `runtime-state.json`; writes split fields through explicit allowlists. The Electron update-channel subscription is host-local, accepts only `stable` or `rc`, and defaults to `stable`. Pi-owned resource, trust, and provider-catalog changes are saved without interrupting active sessions and report deferred runtime activation when an idle edge is required. A flat legacy file migrates on first access. A scoped portable file never contributes paths, project registrations, device values, or secrets. Removed `/api/config/*` and `/api/pichamber/*` aliases are not required. Snippets persist in the PiChamber data root (`snippets.json`) and expand through literal `#name` replacement; Pi prompt templates remain Pi-owned `/name` commands in Pi's global and trusted-project prompt directories, discovered through the active runtime's resource loader and exposed through `/api/pi/resources`, `/api/pi/resources/prompts`, and `/api/pi/commands`. Pi skills invoke as `/skill:name` (bare `/name` never invokes a skill) and extension commands use their registered `/name` (including Pi-generated suffixes); `/api/pi/commands` exposes prompts as `name`, skills as `skill:name`, and extensions under their invocation names, executed via Pi's `session.prompt()` with extension-first precedence. Snippet, prompt-template, skill, and extension-command concepts stay distinct with separate Settings pages, stores, persistence, and caches; they share only `/` autocomplete presentation. New-session starters are pinned Pi prompt templates that insert `/name ` for editing (never submit or expand in PiChamber); legacy skill starters are removed without conversion.
|
|
43
43
|
- Final-only speech-to-text uses authenticated `/api/stt/*` routes and `/api/stt/ws`. Local model inference runs in a forked worker, while remote provider credentials remain in server configuration.
|
|
44
44
|
- Browser and paired clients authenticate with UI sessions or scoped client credentials.
|
|
45
45
|
- `connect-url` creates a one-time pairing link; credentials are not written to URLs or logs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as t,j as c}from"./vendor-react-B5Z1Mdn3.js";import{
|
|
1
|
+
import{R as t,j as c}from"./vendor-react-B5Z1Mdn3.js";import{aa as $,t as m,I as V}from"./useAppFontEffects-Dp6vM-Zr.js";import{u as A,a as G,z as ee,bV as W}from"./index-CrqlVJXp.js";import{b as te,D as re,F as ie}from"./FileSaveConflictDialog-D0siEm8l.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-C60wdVnS.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-KLmnYDaG.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-C9kx2zfD.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DLimsiRH.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-react-drawio-BYDptOsj.js";const ne=l=>l.split("/").pop()||l;function Dt(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[p,F]=t.useState(!1),[U,v]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),d=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),T=A(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const o=t.useCallback((e,i,n)=>I.current&&d.current===e&&G()===i&&w.current===n,[]),z=t.useCallback(async e=>{const i=d.current+1;d.current=i;const n=G(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),v(!1),P(!1),F(!1);try{const r=await u?.(e);if(!o(i,n,e))return;if(!r){m.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!o(i,n,e))return;m.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{o(i,n,e)&&E(!1)}},[l,o]);t.useEffect(()=>ee(()=>{if(d.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),v(!1),P(!1),F(!1);const e=w.current;e&&z(e)}),[z]),t.useEffect(()=>{if(!T)return;const e=A.getState().consumePendingDiagramFile();e&&z(e)},[z,T]);const K=t.useCallback(async(e,i,n,u,r,s)=>{let a=null,f=n,B=u;try{if(B){const N=await l?.readFile?.(e);if(!o(r,s,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),B=N.exists!==!1)}}catch{if(!o(r,s,e))return}o(r,s,e)&&(h({path:e,displayPath:ne(e),exists:B,currentRevision:f,currentContent:a,dirtyContent:i,runtimeKey:s}),v(!1))},[l,o]),X=t.useCallback(async(e,i,n,u,r)=>{const s=await l?.writeFile?.(e,i,te(g.current,n?!0:void 0));return o(u,r,e)?{stale:!1,success:!!s?.success,revision:s?.revision}:{stale:!0}},[l,o]),O=t.useCallback((e,i)=>{C.current=e,typeof i<"u"&&(g.current=i),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||p)return;const i=d.current,n=G(),u=x,r=e,s=S.current+1;S.current=s,P(!0);try{const a=await X(u,r,!1,i,n);if(a.stale)return;if(!a.success){m.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!o(i,n,u))return;if(W(a)){await K(u,r,a.currentRevision??null,a.exists,i,n);return}m.error(a instanceof Error?a.message:"Save failed")}finally{S.current===s&&P(!1)}},[O,x,l,o,p,j,K,X]),Q=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),v(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!o(i,n,e.path))return;if(!r){m.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(s=>s+1),h(null),v(!1)}catch(r){if(!o(i,n,e.path))return;m.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,o,p,b]),Y=t.useCallback(async()=>{const e=b;if(!e||p||!o(d.current,e.runtimeKey,e.path))return;const i=d.current,n=e.runtimeKey;if(!l?.writeFile){m.error("Saving not supported");return}const s=D.current?.getXml()??e.dirtyContent;if(!s){m.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await X(e.path,s,!0,i,n);if(f.stale)return;if(!f.success){m.error("Failed to write file");return}O(s,f.revision),h(null),v(!1)}catch(f){if(!o(i,n,e.path))return;if(W(f)){await K(e.path,s,f.currentRevision??e.currentRevision,f.exists,i,n);return}m.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,o,p,K,X,b]),Z=t.useCallback(()=>{p||j||(h(null),v(!1))},[p,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(V,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(V,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(V,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>A.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(V,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ie,{open:!!b,conflict:b,isResolving:p||j,showCompare:U,onToggleCompare:()=>v(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{Dt as DiagramView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{
|
|
1
|
+
import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{o as te,u as J,a as Ze,B as ze}from"./index-CrqlVJXp.js";import{ds as vt,dl as Ct,dq as jt,ae as et,a0 as tt,c5 as Nt,c6 as Ne,B as Le,I as q,aa as nt,ax as re,t as st,cv as it,b$ as Lt,dt as Dt,du as kt,ab as Rt,Z as Et,at as At,ac as Tt,cp as Mt,e as It,ao as $t,aF as Pt,a2 as _t,a3 as Wt,a5 as Bt}from"./useAppFontEffects-Dp6vM-Zr.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-CbFfOlbV.js";import{p as Ht}from"./VirtualizedFileDiff-D3zBpYIS.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-DYUFkrPT.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-C60wdVnS.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-KLmnYDaG.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-C9kx2zfD.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DLimsiRH.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./web-components-05Oa3k7a.js";import"./computeVirtualFileMetrics-y2AJzpKw.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./runtimeEndpointReset-DHHCemOu.js";import"./SessionUnreadDot-LDTswryg.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-kXPOivsq.js";import"./vendor-diff-C3JhlQdm.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
|
|
2
2
|
`)){const p=l.match(vt);if(p!=null){i!=null&&(i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e)),i=void 0);const u=parseInt(p[3]),b=parseInt(p[1]),h=parseInt(p[4]??"1"),c=parseInt(p[2]??"1");isNaN(u)||isNaN(b)||isNaN(h)||isNaN(c)?e.push(l):i={additionStart:u,deletionStart:b,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(i==null){e.push(l);continue}if(l.startsWith(" "))i.contextLines.push(l);else if(l!==""){if(i.hunkLines.length>0&&i.contextLines.length>s*2){const u=i.contextLines.length-s*2,b=i.contextLines.slice(-s);Re(i,s,"trailing");const{additionCount:h,deletionCount:c}=i;Ie(i,e),i={additionStart:i.additionStart+h+u,deletionStart:i.deletionStart+c+u,deletionCount:0,additionCount:0,contextLines:b,hunkLines:[]}}Re(i,s,i.hunkLines.length===0?"leading":"before-change"),i.hunkLines.push(l),l.startsWith("+")?i.additionCount+=1:l.startsWith("-")&&(i.deletionCount+=1)}}i!=null&&i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e));const a=e.join(`
|
|
3
3
|
`);return t.endsWith(`
|
|
4
4
|
`)?`${a}
|
package/dist/assets/{FileSaveConflictDialog-CoKwDovb.js → FileSaveConflictDialog-D0siEm8l.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{R as a,j as r}from"./vendor-react-B5Z1Mdn3.js";import{D}from"./vendor-react-drawio-BYDptOsj.js";import{
|
|
1
|
+
import{R as a,j as r}from"./vendor-react-B5Z1Mdn3.js";import{D}from"./vendor-react-drawio-BYDptOsj.js";import{o as C}from"./index-CrqlVJXp.js";import{af as E,ag as S,ah as N,ai as B,aj as F,ak as H,B as h}from"./useAppFontEffects-Dp6vM-Zr.js";const A='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const P=a.forwardRef(function({xml:e,readOnly:s,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[o,j]=a.useState(w),f=a.useRef(e),p=a.useRef(e);p.current!==e&&(p.current=e,f.current=e,l.current=e);const v=a.useRef(o);v.current!==o&&(v.current=o,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>j(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const y=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),R=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||A,autosave:!0,urlParameters:{ui:s?"simple":o?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:y,onAutoSave:R},o?"dark":"light")})}),T=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},X=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},G=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
|
|
2
2
|
|
|
3
3
|
… truncated …`:t,W=({open:t,conflict:e,isResolving:s,showCompare:d,onToggleCompare:u,onReload:m,onOverwrite:l,onClose:c})=>{if(!e)return null;const i=!e.exists;return r.jsx(E,{open:t,onOpenChange:o=>{o||c()},children:r.jsxs(S,{showCloseButton:!1,className:"max-w-lg",children:[r.jsxs(N,{children:[r.jsx(B,{children:i?"File deleted on disk":"File changed on disk"}),r.jsx(F,{children:i?`“${e.displayPath}” was deleted since you opened it. Your edits are preserved. Reload to discard them, or overwrite to recreate the file.`:`“${e.displayPath}” changed since you opened it. Your edits are preserved. Reload to discard them and load the current version, or overwrite to keep your edits.`})]}),d&&!i?r.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto py-2",children:[r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Current version on disk"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.currentContent??"")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Your edits"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.dirtyContent)})]})]}):null,r.jsxs(H,{className:"flex flex-wrap gap-2",children:[i?null:r.jsx(h,{variant:"outline",onClick:u,disabled:s,"aria-label":d?"Hide version comparison":"Compare versions",title:d?"Hide version comparison":"Compare versions",children:d?"Hide compare":"Compare"}),r.jsx(h,{variant:"outline",onClick:m,disabled:s,"aria-label":i?"Discard edits and close":"Reload current version",title:i?"Discard edits and close":"Reload current version",children:i?"Discard edits":"Reload"}),r.jsx(h,{variant:"destructive",onClick:l,disabled:s,"aria-label":i?"Recreate file with my edits":"Overwrite with my edits",title:i?"Recreate file with my edits":"Overwrite with my edits",children:s?"Working…":"Overwrite"})]})]})})};export{P as D,W as F,X as b,G as i,T as s};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{j as t,R as a,b as io,r as w}from"./vendor-react-B5Z1Mdn3.js";import{o as X,F as co,h as lo,bT as uo,D as fo,bU as mo,u as Fe,bV as us,J as Re,a as po,z as ho,K as go,bW as kt,G as xo,I as vo,Z as Nn,bX as bo,aq as Sn,m as Rn,E as yr,aK as yo}from"./index-CrqlVJXp.js";import{c2 as wo,I as F,ad as Rt,c3 as ko,a0 as jt,af as ds,ag as fs,ah as ms,ai as ps,aj as hs,ak as gs,B as H,a1 as Mr,a4 as Tr,a6 as Dr,a7 as Yt,t as me,a8 as Zt,a9 as jo,c4 as Qt,ae as xs,E as Fn,aX as Co,c5 as vs,c6 as bs,c7 as ys,c8 as ws,c9 as Er,ca as No,a2 as Xe,a3 as Ye,a5 as Ze,aa as So,al as Ro,Z as Fo,ab as Eo,ac as zo,cb as En,am as zn,aF as Mo,cc as To,cd as Do,ce as Mn}from"./useAppFontEffects-Dp6vM-Zr.js";import{E as pe,D as tr,V as ks,s as Ao,d as Oo,e as Po,f as Tn,k as wr,W as Lo}from"./vendor-codemirror-view-Ct4T37Ue.js";import{H as Dn,x as Ht,y as Io,i as Bo,z as $o}from"./vendor-codemirror-language-BByA_dGF.js";import{a as c,c as Vo}from"./vendor-lezer-highlight-CDMHUZ74.js";import{i as js,S as Wo,k as Ar,E as _o,o as at,a as Ko}from"./vendor-codemirror-state-CNWM3Q8V.js";import{ensurePierreThemeRegistered as An,getResolvedShikiTheme as qo}from"./appThemeRegistry-gegrE2dq.js";import{D as Go,i as Cs,b as Ns,s as Uo,F as Ho}from"./FileSaveConflictDialog-D0siEm8l.js";import{q as Jo,t as Xo,v as Yo,w as Zo,x as Qo,J as Jt}from"./runtimeEndpointReset-DHHCemOu.js";import{j as Ss,h as zr,i as Rs}from"./SessionUnreadDot-LDTswryg.js";import{g as Ct,c as Fs,d as Es,e as Or,n as ei,f as ti,M as Nt,h as oe,j as ri,s as ni,i as si,a as ai,t as Xt,k as kr,b as oi,l as ii,u as ci,m as On,o as li,p as Pn}from"./useFilesViewSearch-Bc8PTYrg.js";import{J as ui,F as di}from"./JsonTreeView-6kRdE1BO.js";import{h as fi,k as mi,l as pi,j as hi}from"./vendor-codemirror-commands-CNlncqrr.js";import{a as Ln,g as er,b as In,c as Bn,o as gi,d as xi}from"./vendor-codemirror-search-BV44140v.js";import{v as vi,g as bi}from"./vendor-replit-codemirror-vim-DaSwPsXt.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zustand-GVb4H8HE.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-base-ui-C60wdVnS.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-Bkw82kL9.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-KLmnYDaG.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./runtimeSurface-C9kx2zfD.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DLimsiRH.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./registerCustomTheme-DmolaWWZ.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-react-drawio-BYDptOsj.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./web-components-05Oa3k7a.js";import"./computeVirtualFileMetrics-y2AJzpKw.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-BSHVMKgK.js";import"./isFilePlainText-BBIPqnLo.js";function $n(e,r){const s=e.metadata.variant==="dark",i=e.config?.fonts?.mono||"monospace",o=e.colors.syntax.highlights||{},u=e.colors.syntax.tokens||{},f=r?.fontSize?`${r.fontSize}px`:"var(--text-code)",m=pe.theme({"&":{backgroundColor:"var(--background)",color:e.colors.syntax.base.foreground,fontSize:f,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:i,backgroundColor:"var(--background)"},".cm-comment":{color:e.colors.syntax.base.comment},".cm-keyword":{color:e.colors.syntax.base.keyword},".cm-string":{color:e.colors.syntax.base.string},".cm-string-2":{color:u.stringEscape||e.colors.syntax.base.string},".cm-number":{color:e.colors.syntax.base.number},".cm-operator":{color:e.colors.syntax.base.operator},".cm-punctuation":{color:u.punctuation||e.colors.syntax.base.comment},".cm-atom":{color:u.boolean||e.colors.syntax.base.number},".cm-builtin":{color:u.functionCall||e.colors.syntax.base.function},".cm-def":{color:u.variableGlobal||e.colors.syntax.base.variable},".cm-attribute":{color:u.variableOther||u.variableProperty||e.colors.syntax.base.operator},".cm-meta":{color:e.colors.syntax.base.comment},".cm-property":{color:u.variableProperty||e.colors.syntax.base.keyword},".cm-variable":{color:e.colors.syntax.base.variable},".cm-variable-2":{color:u.variableOther||e.colors.syntax.base.function},".cm-variable-3":{color:u.variableGlobal||e.colors.syntax.base.type},".cm-tag":{color:u.tag||e.colors.syntax.base.keyword},".cm-link":{color:u.url||e.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:e.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:e.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:o.lineNumber||e.colors.syntax.base.comment,borderRight:`1px solid ${e.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:o.lineNumberActive||e.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:e.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:e.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.elevated,color:e.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${e.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${e.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${e.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:e.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.background,color:e.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:e.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:e.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:e.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:e.colors.interactive.hover,borderColor:e.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:e.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:e.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:e.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:e.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:e.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:e.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${e.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:e.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:e.colors.interactive.hover,color:e.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:e.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${e.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:e.colors.interactive.selection,color:e.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:s}),g=Dn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],class:"cm-comment"},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],class:"cm-keyword"},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],class:"cm-operator"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],class:"cm-punctuation"},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],class:"cm-string"},{tag:c.escape,class:"cm-string-2"},{tag:[c.number,c.bool,c.atom,c.null,c.self],class:"cm-number"},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],class:"cm-builtin"},{tag:c.definition(c.variableName),class:"cm-def"},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],class:"cm-variable"},{tag:c.propertyName,class:"cm-property"},{tag:c.attributeName,class:"cm-attribute"},{tag:[c.className,c.typeName,c.namespace],class:"cm-variable-3"},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],class:"cm-tag"},{tag:c.link,class:"cm-link"},{tag:[c.heading,c.heading1,c.heading2,c.heading3,c.heading4,c.heading5,c.heading6],class:"cm-keyword"}]),y=Dn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],color:e.colors.syntax.base.comment},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],color:e.colors.syntax.base.keyword},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],color:e.colors.syntax.base.operator},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],color:e.colors.syntax.base.string},{tag:c.escape,color:u.stringEscape||e.colors.syntax.base.string},{tag:[c.number,c.bool,c.atom,c.null,c.self],color:e.colors.syntax.base.number},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],color:e.colors.syntax.base.function},{tag:c.definition(c.variableName),color:u.variableGlobal||e.colors.syntax.base.variable},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],color:e.colors.syntax.base.variable},{tag:c.propertyName,color:u.variableProperty||e.colors.syntax.base.variable},{tag:c.attributeName,color:u.variableOther||e.colors.syntax.base.variable},{tag:[c.className,c.typeName,c.namespace],color:e.colors.syntax.base.type},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],color:u.tag||e.colors.syntax.base.keyword},{tag:c.link,color:u.url||e.colors.syntax.base.function,textDecoration:"underline"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],color:u.punctuation||e.colors.syntax.base.comment}]);return r?.syntaxColors===!1?[m]:[m,Ht(Io,{fallback:!0}),Ht(Vo),Ht(g),Ht(y)]}const yi=180,zs=Wo.define(),wi=1,ki=2,ji=4,Vn=new Map,Ci=(e,r)=>{const s=`${e}|${r}`,i=Vn.get(s);if(i)return i;let o="";e&&(o+=`color:${e};`),r&wi&&(o+="font-style:italic;"),r&ki&&(o+="font-weight:bold;"),r&ji&&(o+="text-decoration:underline;");const u=tr.mark({attributes:{style:o}});return Vn.set(s,u),u},Ni=(e,r)=>{const s=new Ar,i=e.state.doc,o=Math.min(r.length,i.lines);for(let u=0;u<o;u+=1){const f=r[u];if(!f||f.length===0)continue;const m=i.line(u+1);let g=m.from;for(const[y,S,x]of f){if(y<=0)continue;const b=g,j=Math.min(g+y,m.to);g+=y,!(j<=b)&&(!S&&!x||s.add(b,j,Ci(S,x)))}}return s.finish()},Si=js.define({create(){return tr.none},update(e,r){let s=e.map(r.changes);for(const i of r.effects)i.is(zs)&&(s=i.value);return s},provide:e=>pe.decorations.from(e)}),Ri=e=>ks.fromClass(class{timer;generation=0;constructor(r){this.tokenize(r)}update(r){r.docChanged&&this.schedule(r.view)}schedule(r){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(r)},yi)}async tokenize(r){const s=++this.generation,i=r.state.doc.toString(),o=await wo(i,e.language,e.themeName,e.theme);o&&s===this.generation&&r.state.doc.length===i.length&&r.dispatch({effects:zs.of(Ni(r,o))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Fi=e=>[Si,Ri(e)],Ke=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),ht=e=>{const r=Ke(e);return!r||r==="/"?r||"/":r.split("/").filter(Boolean).at(-1)??r},Ms=e=>{const r=Ke(e);if(!r||r==="/")return null;const s=r.lastIndexOf("/");if(s<0)return null;if(s===0)return"/";const i=r.slice(0,s);return/^[A-Za-z]:$/.test(i)?`${i}/`:i},Wn=(e,r)=>{const s=Ke(e),i=Ke(r);return!s||!i?!1:s===i||s.startsWith(`${i}/`)},_n=(e,r)=>{const s=Ke(e);if(!s)return Ke(r);if(s.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(s))return s;const i=Ke(r);return i?`${i}/${s}`:s},Ei=(e,r)=>{const s=Ke(e),i=Ke(r);if(!s||s===i)return!1;const o=Ms(s);return o?i&&Wn(s,i)?Wn(o,i):!0:!1},zi=e=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)return"";if(e<1024)return`${e} B`;const r=["KB","MB","GB"];let s=e/1024;for(const i of r){if(s<1024||i===r[r.length-1])return`${s.toFixed(s>=10?0:1)} ${i}`;s/=1024}return""},Mi=(e,r)=>!r||e===r?ht(e):e.startsWith(`${r}/`)?e.slice(r.length+1):e,Ti=({root:e,directory:r,entries:s,query:i,searchResults:o,isSearching:u,directoryError:f,refreshing:m,editorPath:g,editor:y,onClose:S,onQueryChange:x,onOpenDirectory:b,onOpenFile:j,onBackFromEditor:C,onRefresh:v})=>{if(!e)return t.jsx(St,{message:"Select a project to browse files."});if(g)return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:C,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"arrow-left",className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:ht(g)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:y})]});const P=r===e?"Project files":ht(r),I=Ei(r,e)?Ms(r):null,l=!!I&&!i.trim(),B=I===e?"Project files":ht(I??"");return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[S?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Close",onClick:S,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"close",className:"size-5"})}):null,l&&I?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":`Back to ${ht(I)}`,onClick:()=>b(I),style:{touchAction:"manipulation"},children:t.jsx(F,{name:"arrow-left",className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:P})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Refresh files",onClick:v,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"refresh",className:X("size-5",m&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-3 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(F,{name:"search",className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Rt,{value:i,onChange:L=>x(L.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),t.jsx(ko,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:f?t.jsx(St,{message:f}):i.trim()?t.jsx(Di,{root:e,results:o,isSearching:u,onOpenFile:j}):s===void 0?t.jsx(St,{loading:!0,message:"Loading..."}):t.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[l&&I?t.jsxs("button",{type:"button",className:Ss,"aria-label":`Up one level to ${B}`,onClick:()=>b(I),style:{touchAction:"manipulation"},children:[t.jsx(F,{name:"arrow-left",className:X(zr(!0),"text-muted-foreground")}),t.jsx("span",{className:X(Rs(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,s.length===0?t.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,s.map(L=>t.jsx(Ts,{name:L.name,path:L.path,directory:L.type==="directory",meta:L.type==="directory"?void 0:zi(L.size),onClick:()=>L.type==="directory"?b(_n(L.path,r||e)):j(_n(L.path,r||e))},L.path))]})})]})},Ts=({name:e,path:r,directory:s,meta:i,onClick:o})=>t.jsxs("button",{type:"button",className:Ss,onClick:o,style:{touchAction:"manipulation"},children:[s?t.jsx(F,{name:"folder-3-fill",className:X(zr(!0),"text-primary/80")}):t.jsx(jt,{filePath:r,className:zr(!0)}),t.jsx("span",{className:X(Rs(!0),"flex-1 text-foreground"),children:e}),i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,s?t.jsx(F,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),Di=({root:e,results:r,isSearching:s,onOpenFile:i})=>s?t.jsx(St,{loading:!0,message:"Loading..."}):r.length===0?t.jsx(St,{message:"No files found."}):t.jsx("div",{className:"flex w-full min-w-0 flex-col",children:r.map(o=>t.jsx(Ts,{name:ht(o.path),path:o.path,directory:!1,meta:o.relativePath??Mi(o.path,e),onClick:()=>i(o.path)},o.path))}),St=({message:e,loading:r=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[r?t.jsx(F,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(F,{name:"folder-open-fill",className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),Ai=({activeDialog:e,dialogData:r,dialogInputValue:s,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:u,onClose:f,inputRef:m})=>t.jsx(ds,{open:!!e,onOpenChange:g=>!g&&f(),children:t.jsxs(fs,{initialFocus:m,children:[t.jsxs(ms,{children:[t.jsxs(ps,{children:[e==="createFile"&&"Create File",e==="createFolder"&&"Create Folder",e==="rename"&&"Rename",e==="delete"&&"Delete"]}),t.jsxs(hs,{children:[e==="createFile"&&`Create a new file in ${r?.path??"root"}`,e==="createFolder"&&`Create a new folder in ${r?.path??"root"}`,e==="rename"&&`Rename ${r?.name??""}`,e==="delete"&&`Are you sure you want to delete ${r?.name??""}? This action cannot be undone.`]})]}),e!=="delete"&&t.jsx("div",{className:"py-4",children:t.jsx(Rt,{value:s,onChange:g=>i(g.target.value),placeholder:e==="rename"?"New name":"Name",onKeyDown:g=>{g.key==="Enter"&&u()},ref:m})}),t.jsxs(gs,{children:[t.jsx(H,{variant:"outline",onClick:f,disabled:o,children:"Cancel"}),t.jsx(H,{variant:e==="delete"?"destructive":"default",onClick:()=>{u()},disabled:o||e!=="delete"&&!s.trim(),children:o?t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}):e==="delete"?"Delete":"Confirm"})]})]})}),Oi=({label:e,iconDataUrl:r})=>{const[s,i]=a.useState(!1),o=e.trim().slice(0,1).toUpperCase()||"?";return r&&!s?t.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:()=>i(!0)}):t.jsx("span",{className:X("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:o})},Ds=({filePath:e,extension:r})=>t.jsx(jt,{filePath:e,extension:r}),Pi=({status:e})=>{const r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"}[e];return t.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:r}})},Kn=({name:e})=>{const r=a.useRef(null),s=a.useRef(null),[i,o]=a.useState(!1);return a.useLayoutEffect(()=>{const u=r.current,f=s.current;if(!u||!f)return;const m=()=>{o(f.scrollWidth>u.clientWidth+1)};m();const g=new ResizeObserver(m);return g.observe(u),g.observe(f),()=>{g.disconnect()}},[e]),t.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[t.jsx("span",{ref:s,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:e}),i?t.jsxs("span",{className:"open-file-name-marquee-track",children:[t.jsx("span",{className:"open-file-name-marquee-item",children:e}),t.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:e})]}):t.jsx("span",{className:"block min-w-0 truncate",children:e})]})},Li=({node:e,root:r,isExpanded:s,isActive:i,isMobile:o,isBrowserClient:u,alwaysShowActions:f,status:m,badge:g,permissions:y,downloadFile:S,contextMenuPath:x,setContextMenuPath:b,rightClickMenuPath:j,setRightClickMenuPath:C,onSelect:v,onToggle:P,onRevealPath:I,onOpenDialog:l})=>{const B=e.type==="directory",{canRename:L,canCreateFile:W,canCreateFolder:$,canDelete:G,canReveal:K}=y,J=!B&&!!S,D=K&&!u,T=L||W||$||G||J||D,k=a.useCallback(d=>{T&&(d?.preventDefault(),C(e.path))},[T,e.path,C]),V=a.useCallback(()=>{B?P(e.path):v(e)},[B,e,v,P]),E=a.useCallback(d=>{d.stopPropagation(),C(null),b(e.path)},[e.path,b,C]),R=({Item:d,Separator:A})=>t.jsxs(t.Fragment,{children:[L&&t.jsxs(d,{onClick:N=>{N.stopPropagation(),l("rename",e)},children:[t.jsx(F,{name:"edit",className:"mr-2 size-4"})," ","Rename"]}),t.jsxs(d,{onClick:N=>{N.stopPropagation(),Yt(e.path).then(O=>{if(O.ok){me.success("Path copied");return}me.error("Copy failed")})},children:[t.jsx(F,{name:"file-copy",className:"mr-2 size-4"})," ","Copy Path"]}),t.jsxs(d,{onClick:N=>{N.stopPropagation();const O=Ct(r,e.path)||e.path;Yt(O).then(Y=>{if(Y.ok){me.success("Relative path copied");return}me.error("Copy failed")})},children:[t.jsx(F,{name:"file-copy-2",className:"mr-2 size-4"})," ","Copy Relative Path"]}),!B&&S&&t.jsxs(d,{onClick:N=>{N.stopPropagation(),S(e.path).catch(O=>{console.error("Download failed:",O),me.error("Operation failed")})},children:[t.jsx(F,{name:"download",className:"mr-2 size-4"})," ",u?"Download":"Save"]}),D&&t.jsxs(d,{onClick:N=>{N.stopPropagation(),I(e.path)},children:[t.jsx(F,{name:"folder-received",className:"mr-2 size-4"})," ",co()]}),B&&(W||$)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{}),W&&t.jsxs(d,{onClick:N=>{N.stopPropagation(),l("createFile",e)},children:[t.jsx(F,{name:"file-add",className:"mr-2 size-4"})," ","New File"]}),$&&t.jsxs(d,{onClick:N=>{N.stopPropagation(),l("createFolder",e)},children:[t.jsx(F,{name:"folder-add",className:"mr-2 size-4"})," ","New Folder"]})]}),G&&t.jsxs(t.Fragment,{children:[t.jsx(A,{}),t.jsxs(d,{onClick:N=>{N.stopPropagation(),l("delete",e)},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"mr-2 size-4"})," ","Delete"]})]})]});return t.jsxs(Jo,{open:j===e.path,onOpenChange:d=>C(d?e.path:null),children:[t.jsxs(Xo,{render:t.jsx("div",{className:"group relative flex items-center",onContextMenu:o?void 0:k}),children:[t.jsxs("button",{type:"button",onClick:V,onContextMenu:o?void 0:k,className:X("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[B?s?t.jsx(F,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):t.jsx(F,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):t.jsx(Ds,{filePath:e.path,extension:e.extension}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:e.path,children:e.name}),!B&&m&&t.jsx(Pi,{status:m}),B&&g&&t.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[g.modified>0&&t.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",g.modified]}),g.added>0&&t.jsxs("span",{className:"text-[var(--status-success)]",children:["+",g.added]})]})]}),T&&t.jsx("div",{className:X("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:t.jsxs(Mr,{open:x===e.path,onOpenChange:d=>b(d?e.path:null),children:[t.jsx(Tr,{asChild:!0,children:t.jsx(H,{variant:"ghost",size:"icon",className:"size-6",onClick:E,children:t.jsx(F,{name:"more-2-fill",className:"size-4"})})}),t.jsx(Dr,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:R({Item:Zt,Separator:jo})})]})})]}),t.jsx(Yo,{className:"min-w-[180px]",children:R({Item:Zo,Separator:Qo})})]})},jr=(e,r,s)=>{const[i,o]=a.useState(""),[u,f]=a.useState(0);return a.useEffect(()=>{if(!e){o("");return}let m=!1;o("");const g=lo(),y=uo(g);fo(g).then(x=>{m||!x||(o(e),r(null))}).catch(x=>{m||(r(x instanceof Error?x.message:s),o(e))});const S=mo(()=>{m||(o(e),f(x=>x+1),r(null))});return()=>{m=!0,y(),S()}},[e,r,s]),{readyKey:i,nonce:u}},Ii=e=>e!==null&&typeof e=="object"&&"updateStatus"in e&&typeof e.updateStatus=="function",Bi=e=>{const r=document.createElement("div");r.className="cm-vim-panel";const s=bi(e);if(!s)return{top:!1,dom:r};s.state.statusbar=r;const i=s.state.vimPlugin;return Ii(i)&&i.updateStatus(),{top:!1,dom:r,destroy(){s.state.statusbar===r&&(s.state.statusbar=null)}}};function qn(e){return e?[vi(),Ao.of(Bi),Oo()]:[]}const $i={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Vi={case:"Match case",re:"Regular expression",word:"Match whole word"};function Wi(e){const r=e.querySelector(".cm-search");if(r){for(const[s,i]of Object.entries($i)){const o=r.querySelector(`button[name="${s}"]`);o&&!o.title&&(o.title=i)}for(const[s,i]of Object.entries(Vi)){const u=r.querySelector(`input[name="${s}"]`)?.parentElement;u&&!u.title&&(u.title=i)}}}const Cr=new WeakMap;function _i(e,r){const s=er(e.state);if(!s.valid)return Cr.delete(e),0;const i=Cr.get(e);if(!r&&i?.doc===e.state.doc&&i.query.eq(s))return i.total;const o=s.getCursor(e.state);let u=0;for(let f=o.next();!f.done;f=o.next())u+=1;return Cr.set(e,{query:s,doc:e.state.doc,total:u}),u}function Ki(e){const r=er(e.state);if(!r.valid)return 0;const s=e.state.selection.main,i=r.getCursor(e.state);let o=0,u=0;for(let f=i.next();!f.done;f=i.next()){const m=f.value;if(o+=1,u===0&&(u=o),s.from===m.from&&s.to===m.to||s.from<m.to&&s.to>m.from||m.from>=s.head)return o}return u}function Gn(e,r,s=!1){const i=e.querySelector(".cm-search");if(!i)return;let o=i.querySelector(".cm-search-message");if(!o){o=document.createElement("span"),o.className="cm-search-message",o.setAttribute("aria-live","polite");const m=i.querySelector('button[name="next"]'),g=m?.parentNode===i?m:i.firstChild;i.insertBefore(o,g)}const u=_i(r,s),f=u===0?0:Ki(r);o.textContent=u===0?"":`${f}/${u}`}const Un=new at,Hn=new at,Jn=new at,Xn=new at,Yn=new at,Zn=new at,Qn=new at,es=e=>e,Nr=$o,qi=gi,Gi=xi;class Ui extends Lo{constructor(r,s){super(),this.id=r,this.containerMap=s}toDOM(){let r=this.containerMap.get(this.id);return r||(r=document.createElement("div"),r.className="oc-block-widget",r.dataset.widgetId=this.id,this.containerMap.set(this.id,r)),r}eq(r){return r.id===this.id}destroy(){}}const ts=(e,r)=>!e||e.length===0?[]:js.define({create(s){const i=new Ar,o=[...e].sort((u,f)=>u.afterLine-f.afterLine);for(const u of o){const f=s.doc.lines;if(u.afterLine>f)continue;const m=s.doc.line(u.afterLine);i.add(m.to,m.to,tr.widget({widget:new Ui(u.id,r),block:!0,side:1}))}return i.finish()},update(s,i){return s.map(i.changes)},provide:s=>pe.decorations.from(s)}),rs=e=>{if(!e)return[];const r=Math.max(1,e.start),s=Math.max(r,e.end);return ks.fromClass(class{decorations;constructor(i){this.decorations=this.build(i)}update(i){(i.docChanged||i.viewportChanged)&&(this.decorations=this.build(i.view))}build(i){const o=new Ar;for(let u=r;u<=s&&u<=i.state.doc.lines;u+=1){const f=i.state.doc.line(u);o.add(f.from,f.from,tr.line({class:"oc-cm-selected-line"}))}return o.finish()}},{decorations:i=>i.decorations})};function Hi({value:e,onChange:r,extensions:s,className:i,readOnly:o,lineNumbersConfig:u,highlightLines:f,onViewReady:m,onViewDestroy:g,blockWidgets:y,enableSearch:S,searchOpen:x,onSearchOpenChange:b,vimMode:j}){const C=a.useRef(null),v=a.useRef(null),P=a.useRef(e),I=a.useRef(r),l=a.useRef(m),B=a.useRef(g),L=a.useRef(b),W=a.useRef(y),$=a.useRef(j),G=a.useRef(new Map),[K,J]=a.useState([]),D=a.useCallback(k=>{const V=(k??[]).map(E=>{const R=G.current.get(E.id);return R?{id:E.id,content:E.content,container:R}:null}).filter(E=>E!==null);J(E=>E.length===V.length&&E.every((R,d)=>{const A=V[d];return R.id===A.id&&R.content===A.content&&R.container===A.container})?E:V)},[]),T=a.useCallback(k=>{const V=C.current,E=k??v.current;if(!V||!E)return;const R=E.dom.querySelector(".cm-gutters"),d=R instanceof HTMLElement?R.getBoundingClientRect().width:0;V.style.setProperty("--oc-editor-gutter-width",`${d}px`)},[]);return a.useEffect(()=>{P.current=e},[e]),a.useEffect(()=>{I.current=r},[r]),a.useEffect(()=>{l.current=m,B.current=g},[m,g]),a.useEffect(()=>{L.current=b},[b]),a.useEffect(()=>{W.current=y,D(y)},[y,D]),a.useEffect(()=>{if(!C.current)return;const k=(()=>{if(typeof document>"u")return null;const E=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(E)return E;const R=window.__PICHAMBER_CSP_NONCE__;return typeof R=="string"&&R.length>0?R:null})(),V=_o.create({doc:P.current,extensions:[...k?[pe.cspNonce.of(k)]:[],Po({fixed:!0}),Un.of(Tn(u)),fi(),Bo.of(" "),Qn.of(qn(j)),wr.of([mi,...pi,...hi]),pe.updateListener.of(E=>{T(E.view),(E.viewportChanged||E.geometryChanged)&&D(W.current);const R=Ln(E.startState),d=Ln(E.state);R!==d&&L.current?.(d);const A=!er(E.startState).eq(er(E.state));if(d&&(R!==d||A||E.docChanged||E.selectionSet)&&Gn(E.view.dom,E.view,R!==d||A||E.docChanged),!E.docChanged)return;const N=E.state.doc.toString();P.current=N,I.current(N),D(W.current)}),Hn.of(pe.editable.of(!o)),Jn.of(s??[]),Xn.of(rs(f)),Yn.of(ts(y,G.current)),Zn.of(S?[In({top:!0}),wr.of(es(Bn))]:[])]});return v.current=new pe({state:V,parent:C.current}),Nr(v.current,v.current.state.doc.length,200),v.current.requestMeasure(),requestAnimationFrame(()=>{T(v.current),D(W.current)}),v.current&&l.current?.(v.current),()=>{B.current?.(),v.current?.destroy(),v.current=null,J([])}},[W,T,D]),a.useEffect(()=>{const k=v.current;k&&(k.dispatch({effects:[Un.reconfigure(Tn(u)),Hn.reconfigure(pe.editable.of(!o)),Jn.reconfigure(s??[]),Xn.reconfigure(rs(f)),Yn.reconfigure(ts(y,G.current)),Zn.reconfigure(S?[In({top:!0}),wr.of(es(Bn))]:[])]}),Nr(k,k.state.doc.length,200),k.requestMeasure(),requestAnimationFrame(()=>{T(k),D(W.current)}))},[s,f,u,o,y,S,T,D]),a.useEffect(()=>{const k=v.current;if(!k){$.current=j;return}$.current!==j&&($.current=j,k.dispatch({effects:Qn.reconfigure(qn(j))}))},[j]),a.useEffect(()=>{const k=v.current;!k||S===!1||(x?(qi(k),requestAnimationFrame(()=>{Wi(k.dom),Gn(k.dom,k,!0)})):Gi(k))},[x,S]),a.useEffect(()=>{const k=v.current;if(!k)return;const V=k.state.doc.toString();V!==e&&(k.dispatch({changes:{from:0,to:V.length,insert:e}}),Nr(k,k.state.doc.length,300),k.requestMeasure(),requestAnimationFrame(()=>T(k)))},[e,T]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:C,className:X("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",i)}),K.map(k=>io.createPortal(k.content,k.container,k.id))]})}const ns=({variant:e,selectedFile:r,loading:s,suppressLoadingIndicator:i,fileError:o,isSelectedImage:u,imageSrc:f,imagePreviewNonce:m,isSelectedPdf:g,pdfSrc:y,pdfPreviewNonce:S,isUnsupportedBinary:x,onDownload:b,enableRichPreviews:j,drawioViewMode:C,drawioRemountNonce:v,diagramEditorRef:P,diagramEditorXml:I,onDiagramChange:l,jsonViewMode:B,markdownViewMode:L,htmlViewMode:W,htmlLoading:$,htmlPreviewNonce:G,htmlPreviewSrc:K,fileContent:J,canUseShikiFileView:D,textViewMode:T,draftContent:k,onDraftChange:V,canEdit:E,vimMode:R,editorExtensions:d,editorWrapperRef:A,shouldMaskEditorForPendingNavigation:N,onEditorViewReady:O,onEditorViewDestroy:Y,enableSearch:ee=!1,searchOpen:ne,onSearchOpenChange:te,pierreTheme:q,shikiThemeType:Q,wrapLines:Qe})=>{const Oe=e==="fullscreen",le=Oe?"p-4":"p-3",Pe=!!(r?.path&&Qt(r.path)),Le=!!(r?.path&&Fs(r.path)),se=!!(r?.path&&Es(r.path)),ue=!!(r?.path&&Or(r.path)),we=()=>r?t.jsx("div",{className:"h-full",children:t.jsx(di,{file:{name:r.name,contents:k,lang:vs(r.path)||void 0},options:{disableFileHeader:!0,overflow:Qe?"wrap":"scroll",theme:q,themeType:Q},className:"block h-full w-full",style:{height:"100%"}})}):null;return t.jsx(xs,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:r?s?i?t.jsx("div",{className:le}):t.jsxs("div",{className:`${le} flex items-center gap-2 typography-ui text-muted-foreground`,children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),Oe?"Loading…":"Loading..."]}):o?t.jsx("div",{className:`${le} typography-ui text-[color:var(--status-error)]`,children:o}):u?t.jsx("div",{className:X("flex h-full items-center justify-center",le),children:t.jsx("img",{src:f,alt:r.name||"Image",className:X("max-w-full object-contain rounded-md border border-border/30 bg-primary/10",Oe?"max-h-full":"max-h-[70vh]")},m)}):g?t.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:t.jsx("iframe",{src:y,className:"h-full w-full border-0",title:r.name},S)}):x?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[t.jsx("div",{className:"typography-ui-header text-foreground",children:"Cannot preview binary file"}),t.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:"This file is binary and cannot be edited in PiChamber. Download it to open with another app."}),b?t.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:b,children:[t.jsx(F,{name:"download",className:"mr-2 size-4"}),"Save file"]}):null]}):j&&Pe&&C==="preview"?t.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:t.jsx(Go,{ref:P,xml:I,onChange:l},`${r.path}:${v}`)}):j&&Le&&B==="tree"?t.jsx(Fn,{fallback:t.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[t.jsx("div",{className:"mb-1 font-medium text-destructive",children:"JSON viewer unavailable"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to text mode to view raw content."})]}),children:t.jsx("div",{className:"h-full overflow-auto",children:t.jsx(ui,{jsonString:J,maxHeight:"100%",initiallyExpandedDepth:2})})}):se&&L==="preview"?t.jsxs("div",{className:X("h-full overflow-auto",le),children:[J.length>500*1024?t.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:`This file is large (${Math.round(J.length/1024)}KB). Preview may be limited.`}):null,t.jsx(Fn,{fallback:t.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[t.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:t.jsx(Co,{content:J,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):j&&ue&&W==="preview"?$?t.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:"Loading..."}):t.jsx("div",{className:"h-full overflow-hidden",children:t.jsx("iframe",{src:K,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:"HTML Preview"},G)}):D&&T==="view"?we():t.jsxs("div",{className:X("relative h-full",N&&"overflow-hidden"),ref:A,children:[t.jsx("div",{className:X("h-full",N&&"invisible"),children:t.jsx(Hi,{value:k,onChange:V,readOnly:!E,vimMode:R,extensions:d,className:"h-full",onViewReady:O,onViewDestroy:Y,...ee?{enableSearch:!0,searchOpen:ne,onSearchOpenChange:te}:{}})}),N?t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:t.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Opening file at change..."]})}):null]}):t.jsx("div",{className:`${le} typography-ui text-muted-foreground`,children:"Pick a file from the tree."})})};async function Ji(e,r,s){if(bs(e)&&!ys(e))return{kind:r?"desktop-image":"asset-image"};if(ws(e))return{kind:"pdf"};if(Er(e))return{kind:"binary",detectedFromContent:!1};const o=await s(e);if(No(o))return{kind:"binary",detectedFromContent:!0};const u=ei(o);return{kind:"text",content:u,draft:u.length>Nt?`${u.slice(0,Nt)}
|
|
2
|
+
|
|
3
|
+
… truncated …`:u,lineEnding:ti(o)}}function Xi({isDirty:e,saveDraft:r}){const s=Fe(b=>b.setMainTabGuard),[i,o]=w.useState(!1),u=w.useRef(null),f=w.useRef(!1),m=w.useCallback(b=>f.current?(f.current=!1,!1):e?(u.current=b,o(!0),!0):!1,[e]);w.useEffect(()=>{if(!e){s(null);return}const b=j=>!m({kind:"tab",tab:j});return s(b),()=>{Fe.getState().mainTabGuard===b&&s(null)}},[e,m,s]);const g=w.useCallback(()=>{const b=u.current;return u.current=null,f.current=!0,o(!1),b?.kind==="tab"&&s(null),b},[s]),y=w.useCallback(()=>g(),[g]),S=w.useCallback(async()=>await r()?g():(f.current=!1,null),[r,g]),x=w.useCallback(b=>{b||o(!0)},[]);return{confirmOpen:i,discardAndTakeIntent:y,keepModalOpen:x,requestNavigation:m,saveAndTakeIntent:S}}function Yi(e,r){if(e.state.doc.length!==r.length)return!1;if(r.length===0)return!0;const s=Math.min(128,r.length);if(e.state.sliceDoc(0,s)!==r.slice(0,s))return!1;const i=Math.max(0,r.length-s);return e.state.sliceDoc(i,r.length)===r.slice(i)}function Zi({root:e,selectedPath:r,loadedPath:s,fileLoading:i,fileError:o,isImage:u,isPdf:f,isUnsupportedBinary:m,canEdit:g,textViewMode:y,setTextViewMode:S,draftContent:x,confirmDiscardOpen:b,selectFilePath:j}){const C=Fe(D=>D.pendingFileNavigation),v=Fe(D=>D.setPendingFileNavigation),P=Fe(D=>D.pendingFileFocusPath),I=Fe(D=>D.setPendingFileFocusPath),l=w.useRef(null),[B,L]=w.useState(0),W=w.useRef(null),$=w.useRef({key:"",attempts:0}),G=w.useCallback(()=>{L(D=>D+1)},[]);w.useEffect(()=>()=>{W.current!==null&&window.cancelAnimationFrame(W.current)},[]),w.useEffect(()=>{if(!C||!e)return;const D=()=>{W.current===null&&(W.current=window.requestAnimationFrame(()=>{W.current=null,G()}))},T=()=>{v(null),$.current={key:"",attempts:0}},k=oe(C.path);if(!k){T();return}const V=`${k}:${C.line}:${C.column??1}`;if($.current.key!==V&&($.current={key:V,attempts:0}),r!==k){b||j(k);return}if(i||s!==k)return;if(o||u||f||m){T();return}if(!g)return;if(y!=="edit"){S("edit");return}const E=l.current;if(!E||!Yi(E,x)){D();return}const R=Math.max(1,Math.min(C.line,E.state.doc.lines)),d=E.state.doc.line(R),A=Math.max(1,C.column||1),N=d.from+Math.min(Math.max(0,d.to-d.from),A-1);if(!(E.state.selection.main.head===N)||$.current.attempts===0){$.current.attempts+=1,E.dispatch({selection:{anchor:N},effects:pe.scrollIntoView(N,{y:"center"})}),E.focus(),D();return}window.requestAnimationFrame(()=>{const Y=l.current;Y&&(Y.dispatch({selection:{anchor:N},effects:pe.scrollIntoView(N,{y:"center"})}),Y.focus())}),T()},[g,b,x,B,o,i,u,f,m,s,G,C,e,r,j,v,S,y]),w.useEffect(()=>{if(!P||!e)return;const D=oe(P);if(!D){I(null);return}r!==D||i||s!==D||(!o&&!u&&!f&&!m&&g&&y==="edit"&&l.current?.focus(),I(null))},[g,o,i,u,f,m,s,P,e,r,I,y]);const K=oe(C?.path??"");return{editorViewRef:l,notifyEditorViewChanged:G,shouldMaskEditor:!!(C&&K&&r===K&&!i&&!o&&!u&&!f&&!m)}}function Qi(e){return!(!e.autoSaveEnabled||!e.isDirty||!e.canWrite||e.isSaving||e.fileLoading||e.isNonEditableBinary||!e.selectedFilePath||e.loadedFilePath!==e.selectedFilePath)}function ec(e){return e.selectedFilePath?e.isDirty?!(e.fileLoading||e.loadedFilePath!==e.selectedFilePath||e.isNonEditableBinary||e.draftContent===""&&e.fileContent!==""&&e.loadedFilePath!==e.selectedFilePath):!0:!1}const tc=1500,rc=2e3;function nc({autoSaveEnabled:e,selectedPath:r,loadedPath:s,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,lineEnding:m,isNonEditableBinary:g,writeFile:y,expectedRevision:S,onSaved:x,captureSaveScope:b,currentSaveScope:j,onConflict:C}){const[v,P]=w.useState(!1),[I,l]=w.useState("idle"),[B,L]=w.useState(null),W=w.useRef(null),$=w.useRef(null),G=w.useRef(C);G.current=C;const K=w.useRef(b);K.current=b;const J=w.useRef(j);J.current=j;const D=w.useCallback(R=>R?Cs(R,J.current?.()??null):!0,[]),T=w.useCallback(()=>{W.current&&(clearTimeout(W.current),W.current=null)},[]),k=w.useCallback(()=>{l("saved"),$.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,l("idle")},rc)},[]),V=w.useCallback(async R=>{if(!r||!y)return me.error("Saving not supported"),!1;if(!ec({selectedFilePath:r,loadedFilePath:s,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,isNonEditableBinary:g}))return g?console.warn(`[saveDraft] refusing to save binary file "${r}".`):u===""&&f!==""&&s!==r&&console.warn(`[saveDraft] refusing to save empty draft for "${r}" (${f.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!o)return!0;P(!0);const d=K.current?.()??null;try{const A=ri(u,m),N=Ns(S,R?.overwrite),O=await y(r,A,N);return O?.success?D(d)?(L(null),x(r,u,O?.revision,d),!0):!1:(me.error("Failed to write file"),!1)}catch(A){if(us(A)){if(!D(d))return!1;const N={path:r,currentRevision:A.currentRevision??null,exists:A.exists};return L(N),G.current?.(N),!1}return me.error(A instanceof Error?A.message:"Save failed"),!1}finally{P(!1)}},[u,S,f,i,o,g,D,m,s,x,r,y]),E=w.useCallback(async R=>{if(T(),v)return!1;const d=await V(R);return d&&k(),d},[T,v,V,k]);return w.useEffect(()=>{e||(l("idle"),T())},[e,T]),w.useEffect(()=>{if(Qi({autoSaveEnabled:e,isDirty:o,canWrite:!!(r&&y),isSaving:v,fileLoading:i,selectedFilePath:r,loadedFilePath:s,isNonEditableBinary:g}))return W.current=setTimeout(()=>{W.current=null,V().then(R=>{R&&k()})},tc),T},[e,T,u,i,o,g,v,s,V,r,k,y]),w.useEffect(()=>{l("idle"),P(!1),L(null)},[r]),w.useEffect(()=>()=>{T(),$.current&&clearTimeout($.current)},[T]),{autoSaveStatus:I,cancelPendingAutosave:T,isSaving:v,saveConflict:B,clearSaveConflict:()=>L(null),saveDraft:V,saveNow:E}}function sc(e,r){return typeof e.revision=="string"&&typeof r.revision=="string"&&e.revision!==r.revision?!0:r.mtimeMs!==void 0&&e.mtimeMs!==void 0&&r.mtimeMs!==e.mtimeMs||r.size!==e.size}function ac({selectedPath:e,loadedPath:r,isDirty:s,readStat:i,onExternalChange:o,pollIntervalMs:u=2e3}){const f=w.useRef(null),m=w.useRef(s);m.current=s;const g=w.useCallback(y=>{f.current=y},[]);return w.useEffect(()=>{if(!e||r!==e)return;let y=!1;const S=window.setInterval(()=>{if(document.hidden)return;const x=f.current,b=x&&x.path===e&&typeof x.revision=="string"?x.revision:null;i(e,{knownRevision:b}).then(j=>{if(y||!j)return;const C=f.current;if(!C||C.path!==e){f.current=j;return}!sc(C,j)||m.current||(f.current=j,o())}).catch(()=>{})},u);return()=>{y=!0,window.clearInterval(S)}},[r,o,u,i,e]),{recordStat:g}}const ss="pichamber:files:md-viewer-mode",as="pichamber:files:html-viewer-mode",os="pichamber:files:json-viewer-mode",oc=1500,ic=1500;function Sr(e,r,s){try{const i=localStorage.getItem(e);if(i&&r.includes(i))return i}catch{}return s}function Rr(e,r){try{localStorage.setItem(e,r)}catch{}}function cc({root:e,selectedPath:r,fileContent:s,draftContent:i,setDraftContent:o,autoSaveEnabled:u,writeFile:f,expectedRevision:m,captureSaveScope:g,currentSaveScope:y,onSaved:S,onConflict:x}){const[b,j]=w.useState("edit"),[C,v]=w.useState("edit"),[P,I]=w.useState("text"),[l,B]=w.useState("edit"),[L,W]=w.useState("edit"),[$,G]=w.useState(0),[K,J]=w.useState(!1),D=w.useRef({}),T=w.useRef({}),k=w.useRef({}),V=w.useRef({}),E=w.useRef(""),R=w.useRef(""),d=w.useRef(null),A=w.useRef(null),N=w.useRef(null),O=w.useRef(m);O.current=m;const Y=w.useRef(g);Y.current=g;const ee=w.useRef(y);ee.current=y;const ne=w.useRef(S);ne.current=S;const te=w.useRef(x);te.current=x;const q=w.useCallback(()=>{d.current&&(clearTimeout(d.current),d.current=null),N.current!==null&&(cancelAnimationFrame(N.current),N.current=null)},[]),Q=w.useCallback(_=>{E.current=_,R.current=_},[]),Qe=w.useCallback(()=>Q(""),[Q]);w.useEffect(()=>{r&&(j(D.current[r]??"edit"),v(T.current[r]??Sr(ss,["preview","edit"],"edit")),B(k.current[r]??Sr(as,["preview","edit"],"edit")),W(V.current[r]??"edit"),I(Sr(os,["tree","text"],"text")))},[r]);const Oe=w.useCallback(_=>{r&&(D.current[r]=_),j(_)},[r]),le=w.useCallback(_=>{r&&(T.current[r]=_),v(_),Rr(ss,_)},[r]),Pe=w.useCallback(_=>{r&&(k.current[r]=_),B(_),Rr(as,_)},[r]),Le=w.useCallback(_=>{I(_),Rr(os,_)},[]),se=w.useCallback(_=>{if(r&&(V.current[r]=_),q(),_==="edit"){o(E.current||s),W(_);return}E.current=i;const U=r;W("edit"),N.current=requestAnimationFrame(()=>{N.current=requestAnimationFrame(()=>{N.current=null,!(e&&U&&Re.getState().byRoot[e]?.selectedPath!==U)&&(G(ae=>ae+1),W("preview"))})})},[q,i,s,e,r,o]),ue=w.useCallback(_=>_?Cs(_,ee.current?.()??null):!0,[]),we=w.useCallback(async(_,U,ae)=>{if(!f||U===R.current)return!1;const ge=Y.current?.()??null;if(ge&&ge.path!==_)return!1;try{const de=await f(_,U,Ns(O.current,ae?.overwrite));return de?.success?ue(ge)?(Q(U),o(U),ne.current?.(_,U,de?.revision,ge),!0):!1:(me.error("Failed to write file"),!1)}catch(de){return us(de)?(ue(ge)&&te.current?.({path:_,currentRevision:de.currentRevision??null,exists:de.exists,xml:U}),!1):(me.error(de instanceof Error?de.message:"Save failed"),!1)}},[ue,Q,o,f]),he=w.useCallback(()=>{J(!0),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>J(!1),ic)},[]),Ie=w.useCallback(async(_,U,ae)=>{d.current&&(clearTimeout(d.current),d.current=null);const ge=await we(_,U,ae);return ge&&he(),ge},[we,he]),gt=w.useCallback(_=>{E.current=_,!(!u||!r||L!=="preview"||!f)&&(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,we(r,_).then(U=>{U&&he()})},oc))},[u,L,we,r,he,f]);w.useEffect(()=>q,[q,L,r]),w.useEffect(()=>()=>{A.current&&clearTimeout(A.current)},[]);const Ee=Qt(r??"")&&(E.current||i)||s;return{clearDiagramContent:Qe,diagramEditorXml:Ee,diagramSaved:K,drawioRemountNonce:$,drawioViewMode:L,handleDiagramChange:gt,htmlViewMode:l,jsonViewMode:P,mdViewMode:C,recordDiagramContent:Q,saveDiagramNow:Ie,saveDiagramXml:we,saveDrawioViewMode:se,saveHtmlViewMode:Pe,saveJsonViewMode:Le,saveMdViewMode:le,saveTextViewMode:Oe,setTextViewMode:j,textViewMode:b}}function lc(e,r){return e==="mobile"?!0:r==="full"}function uc(e,r){if(e===r)return!0;if(e.length!==r.length)return!1;for(let s=0;s<e.length;s+=1){const i=e[s],o=r[s];if(i.name!==o.name||i.path!==o.path||i.type!==o.type||i.extension!==o.extension||i.relativePath!==o.relativePath||i.size!==o.size)return!1}return!0}function dc({files:e,root:r,activeDirectory:s,expandedPaths:i,chrome:o,showGitignored:u,removeExpandedPathsByPrefix:f,enabled:m=!0,visible:g=!0}){const[y,S]=a.useState({}),[x,b]=a.useState({}),j=a.useRef(new Set),C=a.useRef(new Set),v=a.useRef(new Map),P=a.useRef(new Map),I=a.useRef(0),l=a.useRef(!1),[B,L]=a.useState(()=>po());a.useEffect(()=>ho(R=>{L(R.runtimeKey)}),[]),a.useEffect(()=>(l.current=!1,()=>{l.current=!0,P.current=new Map,C.current=new Set,v.current=new Map}),[]);const W=a.useCallback((R,d)=>{const A=[];for(const N of d){if(!N?.name||o==="desktop"&&!u&&ni(N.name))continue;const O=oe(N.path||""),Y=O?si(O)?O:oe(`${R}/${O}`):oe(`${R}/${N.name}`),ee=N.isDirectory?"directory":"file";A.push({name:N.name,path:Y,type:ee,extension:ee==="file"&&N.name.includes(".")?N.name.split(".").pop()?.toLowerCase():void 0,size:N.size})}return ai(A)},[o,u]),$=`${B}|${r}|g${u?"1":"0"}|${o}`,G=a.useRef($);G.current=$;const K=a.useCallback(async R=>{if(!m)return;const d=oe(R.trim());if(!d||j.current.has(d))return;const A=v.current.get(d);if(A){await A;return}const N=G.current,O=I.current+1;I.current=O,P.current=new Map(P.current).set(d,O),C.current=new Set(C.current).add(d);const Y=()=>!l.current&&G.current===N&&P.current.get(d)===O,ee=(async()=>{try{const ne=e.listDirectory?(await e.listDirectory(d)).entries.map(q=>({name:q.name,path:q.path,isDirectory:q.isDirectory,size:q.size})):(await go(d)).map(q=>({name:q.name,path:q.path,isDirectory:q.isDirectory}));if(!Y())return;j.current=new Set(j.current).add(d),b(q=>{if(!q[d])return q;const Q={...q};return delete Q[d],Q});const te=W(d,ne);S(q=>{const Q=q[d];return Q&&uc(Q,te)?q:{...q,[d]:te}})}catch(ne){if(!Y())return;const te=ne instanceof Error?ne.message:String(ne??"");te==="Directory not found"&&r&&d!==r?(f(r,d),b(q=>{if(!q[d])return q;const Q={...q};return delete Q[d],Q})):(console.error("Failed to load files directory:",ne),b(q=>({...q,[d]:te})))}finally{P.current.get(d)===O&&(P.current=new Map(P.current),P.current.delete(d))}})();v.current.set(d,ee);try{await ee}finally{v.current.get(d)===ee&&(v.current.delete(d),C.current=new Set(C.current),C.current.delete(d))}},[m,e,W,f,r]),J=a.useCallback(()=>{j.current=new Set,C.current=new Set,v.current=new Map,P.current=new Map,b({}),S(R=>Object.keys(R).length===0?R:{})},[]),D=a.useCallback(async()=>{!m||!r||(J(),await K(r))},[m,K,J,r]),T=a.useCallback(async R=>{if(!m)return;if(!R){await D();return}const d=oe(R);j.current=new Set(j.current),j.current.delete(d),C.current=new Set(C.current),C.current.delete(d),v.current.delete(d),P.current=new Map(P.current),P.current.delete(d),await K(d)},[m,K,D]),k=a.useRef("");a.useEffect(()=>{k.current!==$&&(k.current=$,J())},[J,$]),a.useEffect(()=>{!m||!g||!r||j.current.has(oe(r))||K(r)},[m,K,r,$,g]),a.useEffect(()=>{!m||!g||!s||K(s)},[s,m,K,g]),a.useEffect(()=>{if(!m||!g||!e.listDirectory)return;const R=O=>{const Y=oe(O);return v.current.has(Y)||C.current.has(Y)},d=()=>{if(!(typeof document<"u"&&document.hidden))for(const O of i)R(O)||T(O)},A=()=>{typeof document<"u"&&document.hidden||d()};typeof document<"u"&&document.addEventListener("visibilitychange",A);const N=i.length>0?window.setInterval(d,8e3):null;return()=>{typeof document<"u"&&document.removeEventListener("visibilitychange",A),N!==null&&window.clearInterval(N)}},[m,i,e.listDirectory,T,g]);const V=a.useRef(m&&g);a.useEffect(()=>{const R=m&&g,d=V.current;if(V.current=R,!(!R||d)){if(!e.listDirectory){r&&!j.current.has(oe(r))&&K(r);return}if(i.length===0){r&&!j.current.has(oe(r))&&K(r);return}for(const A of i){const N=oe(A);v.current.has(N)||C.current.has(N)||T(A)}}},[m,i,e.listDirectory,K,T,r,g]);const E=a.useCallback(R=>j.current.has(oe(R)),[]);return{childrenByDir:y,loadErrorsByDir:x,isLoaded:E,loadDirectory:K,refreshDirectory:T,refreshRoot:D}}const fc=({showEditorTabsRow:e,isMobile:r,showMobilePageContent:s,onBackMobile:i,selectedFile:o,openFiles:u,root:f,alwaysShowActions:m,editorTabsOverflow:g,editorTabsScrollRef:y,onSelectFile:S,onCloseFile:x})=>e?t.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[r&&s&&t.jsx("button",{type:"button",onClick:i,"aria-label":"Back",className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(F,{name:"arrow-left-s",className:"size-5"})}),r?o?t.jsxs(Mr,{children:[t.jsx(Tr,{asChild:!0,children:t.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":"Open files",children:[t.jsx(jt,{filePath:o.path,extension:o.extension,className:"size-3.5 flex-shrink-0"}),t.jsx(Kn,{name:o.name}),t.jsx(F,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),t.jsx(Dr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:u.map(b=>{const j=o?.path===b.path;return t.jsxs(Zt,{onSelect:C=>{if(C.target.closest("[data-close-open-file]")){C.preventDefault();return}j||S(b)},className:X("flex min-w-0 items-center justify-between gap-2 overflow-hidden",j&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[t.jsx(jt,{filePath:b.path,extension:b.extension,className:"size-3.5 flex-shrink-0"}),t.jsx(Kn,{name:b.name})]}),t.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:C=>{C.preventDefault(),C.stopPropagation()},onClick:C=>{C.preventDefault(),C.stopPropagation(),x(b.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":`Close ${b.name}`,children:t.jsx(F,{name:"close",className:"size-3.5"})})]},b.path)})})]}):t.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"}):u.length>0?t.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.left&&t.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),g.right&&t.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),t.jsx("div",{ref:y,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},"data-no-drawer-swipe":"true",children:u.map(b=>{const j=o?.path===b.path;return t.jsxs("div",{title:Ct(f,b.path),className:X("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",j?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[t.jsx(jt,{filePath:b.path,extension:b.extension,className:"size-3.5 flex-shrink-0"}),t.jsx("button",{type:"button",onClick:()=>{j||S(b)},className:"max-w-[12rem] truncate text-left",children:b.name}),t.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),x(b.path)},className:X("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!j&&!m&&"opacity-0 group-hover:opacity-100"),"aria-label":`Close ${b.name}`,children:t.jsx(F,{name:"close",className:"size-3.5"})})]},b.path)})})]}):t.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"})]}):null,mc=(e,r)=>{if(!r)return null;const s=Number.parseInt(e.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,r.state.doc.lines)},is=(e,r)=>{const s=e.state.doc.lineAt(r.main.head);return{lineNumber:s.number,character:r.main.head-s.from+1,selection:r}},cs=(e,r,s)=>{const i=e.state.doc.line(r),o=Math.max(1,Math.min(s,i.length+1)),u=i.from+o-1;e.dispatch({selection:Ko.cursor(u),effects:pe.scrollIntoView(u,{y:"center"})})};function pc({open:e,onOpenChange:r,view:s,variant:i="overlay"}){const[o,u]=a.useState(""),f=a.useRef(null),m=a.useRef(!1),g=a.useRef(null),y=a.useRef(null),S=a.useMemo(()=>mc(o,s),[o,s]);a.useEffect(()=>{!e||!s||(m.current=!1,f.current=is(s,s.state.selection),u(""))},[e,s]),a.useEffect(()=>{e&&window.requestAnimationFrame(()=>{y.current?.focus(),y.current?.select()})},[e]),a.useEffect(()=>{if(!(!e||!s||!f.current)){if(S===null){const{selection:v}=f.current;s.dispatch({selection:v,effects:pe.scrollIntoView(v.main.from,{y:"center"})});return}cs(s,S,f.current.character)}},[S,e,s]);const x=a.useCallback(()=>{if(!s||m.current||!f.current)return;const{selection:v}=f.current;s.dispatch({selection:v,effects:pe.scrollIntoView(v.main.from,{y:"center"})})},[s]),b=a.useCallback(v=>{v||x(),r(v)},[r,x]),j=a.useCallback(()=>{!s||S===null||!f.current||(m.current=!0,cs(s,S,f.current.character),r(!1),s.focus())},[S,r,s]);a.useEffect(()=>{if(!e)return;const v=I=>{const l=g.current,B=I.target;!l||!(B instanceof Node)||l.contains(B)||b(!1)},P=I=>{I.key==="Escape"&&(I.preventDefault(),b(!1))};return document.addEventListener("pointerdown",v,!0),document.addEventListener("keydown",P,!0),()=>{document.removeEventListener("pointerdown",v,!0),document.removeEventListener("keydown",P,!0)}},[b,e,i]);const C=a.useMemo(()=>s?S===null?`Current Line: ${(f.current??is(s,s.state.selection)).lineNumber}. Type a line number between 1 and ${s.state.doc.lines} to navigate to.`:`Go to line ${S}`:"Editor unavailable.",[S,s]);return i==="inline"?e?t.jsxs("div",{ref:g,className:"ml-1 flex h-6 items-center gap-1",children:[t.jsx(Rt,{ref:y,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"Line",className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),t.jsx(H,{variant:"outline",size:"xs",onClick:j,disabled:!s||S===null,className:"h-6 px-2",children:"Go"})]}):null:t.jsx("div",{ref:g,className:X("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",e?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:t.jsxs("div",{className:"min-w-0",children:[t.jsx(Rt,{ref:y,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"Line number",className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),t.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:C})]})})}const Fr=({currentMode:e,onToggle:r})=>{const s=e==="preview",i=s?"Switch to edit mode":"Switch to preview mode",o=s?"Edit":"Preview";return t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx(H,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:s?t.jsx(F,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(F,{name:"eye-off",className:"size-4","aria-hidden":"true"})})}),t.jsx(Ze,{sideOffset:8,children:o})]})},hc=({selectedFile:e,displaySelectedPath:r,layout:s="floating",exitFullscreenOnly:i=!1,canEdit:o,isEditingFile:u,isSaving:f,autoSaveEnabled:m,autoSaveStatus:g,isDirty:y,onSaveDraft:S,onToggleAutoSave:x,openInApps:b,openInCacheStale:j,onOpenInApp:C,onRefreshOpenInApps:v,onToolbarDropdownOpenChange:P,isSelectedImage:I,isSelectedPdf:l,isUnsupportedBinary:B,wrapLines:L,onToggleWrapLines:W,textViewMode:$,onToggleSearch:G,isGoToLineOpen:K,onOpenGoToLineChange:J,editorView:D,canUseShikiFileView:T,isJson:k,isHtml:V,onToggleTextViewMode:E,isMarkdown:R,mdViewMode:d,onToggleMdViewMode:A,isDrawio:N,drawioViewMode:O,onToggleDrawioViewMode:Y,diagramSaved:ee,onSaveDiagram:ne,jsonViewMode:te,onToggleJsonViewMode:q,canCopy:Q,copiedContent:Qe,onCopyContent:Oe,canCopyPath:le,copiedPath:Pe,onCopyPath:Le,onDownloadFile:se,isMobile:ue,mode:we,isFullscreen:he,onToggleFullscreen:Ie,onExitFullscreen:gt})=>{if(!e)return null;const _=s==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",U=(ae,ge)=>t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:ge})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:ae})]});return t.jsxs("div",{className:_,children:[o&&u&&t.jsxs(t.Fragment,{children:[f?t.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[t.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}),"Saving..."]}):m&&g==="saved"&&!y?t.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[t.jsx(F,{name:"check",className:"size-3.5"}),"Saved"]}):y?U(m?`Save now (${kt()}+S) - auto-saves after 1.5s`:`Save now (${kt()}+S)`,t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{S()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:m?`Save now (${kt()}+S) - auto-saves after 1.5s`:`Save now (${kt()}+S)`,"aria-label":`Save (${kt()}+S)`,children:t.jsx(F,{name:"save-3",className:"size-4"})})):null,U(m?"Auto-save on":"Manual save",t.jsx(H,{variant:"ghost",size:"sm",onClick:x,className:X("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",m?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:m?"Auto-save on":"Manual save","aria-label":m?"Auto-save on":"Manual save",children:m?t.jsx(F,{name:"file-check-fill",className:"size-4"}):t.jsx(F,{name:"file-check",className:"size-4"})}))]}),t.jsxs(Mr,{onOpenChange:P,children:[t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(Tr,{asChild:!0,children:t.jsx(H,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Open in desktop app","aria-label":"Open in desktop app",children:t.jsx(F,{name:"file-transfer",className:"size-4"})})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Open in desktop app"})]}),t.jsxs(Dr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[b.map(ae=>t.jsxs(Zt,{className:"flex items-center gap-2",onClick:()=>{C(ae)},children:[t.jsx(Oi,{label:ae.label,iconDataUrl:ae.iconDataUrl}),t.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label})]},ae.id)),j?t.jsxs(Zt,{className:"flex items-center gap-2",onClick:()=>{v()},children:[t.jsx(F,{name:"refresh",className:"size-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]}),!I&&!l&&!B&&t.jsxs(t.Fragment,{children:[U(L?"Disable line wrap":"Enable line wrap",t.jsx(H,{variant:"ghost",size:"sm",onClick:W,className:X("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",L?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:L?"Disable line wrap":"Enable line wrap",children:t.jsx(F,{name:"text-wrap",className:"size-4"})})),$==="edit"&&t.jsxs(t.Fragment,{children:[U("Find in file",t.jsx(H,{variant:"ghost",size:"sm",onClick:ae=>{G(),ae.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Find in file",children:t.jsx(F,{name:"search",className:"size-4"})})),U("Go to line",t.jsx(H,{variant:"ghost",size:"sm",onClick:ae=>{J(!K),ae.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Go to line",children:t.jsx(F,{name:"menu-fold-2",className:"size-4"})})),t.jsx(pc,{open:K,onOpenChange:J,view:D,variant:"inline"})]})]}),T&&o&&!k&&!V&&t.jsx(Fr,{currentMode:$==="view"?"preview":"edit",onToggle:E}),R&&U(d==="preview"?"Switch to edit mode":"Switch to preview mode",t.jsx(H,{variant:"ghost",size:"sm",onClick:A,className:X("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",d==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:d==="preview"?"Switch to edit mode":"Switch to preview mode","aria-label":d==="preview"?"Switch to edit mode":"Switch to preview mode",children:t.jsx(F,{name:d==="preview"?"eye":"eye-off",className:"size-4"})})),Or(e?.path??"")&&t.jsx(Fr,{currentMode:V?"preview":"edit",onToggle:E}),N&&t.jsxs(t.Fragment,{children:[t.jsx(Fr,{currentMode:O,onToggle:Y}),O==="preview"&&t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{ne()},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save diagram",children:ee?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"save-3",className:"size-4"})})]}),k&&U(te==="tree"?"Switch to Text View":"Switch to Tree View",t.jsx(H,{variant:"ghost",size:"sm",onClick:q,className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:te==="tree"?"Switch to Text View":"Switch to Tree View",children:te==="tree"?t.jsx(F,{name:"code-sslash",className:"size-4"}):t.jsx(F,{name:"node-tree",className:"size-4"})})),Q&&U("Copy file contents",t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{Oe()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Copy file contents","aria-label":"Copy file contents",children:Qe?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"clipboard",className:"size-4"})})),le&&U(`Copy file path (${r})`,t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{Le()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:`Copy file path (${r})`,"aria-label":`Copy file path (${r})`,children:Pe?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"file-copy-2",className:"size-4"})})),se&&U("Save file",t.jsx(H,{variant:"ghost",size:"sm",onClick:se,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save file","aria-label":"Save file",children:t.jsx(F,{name:"download",className:"size-4"})})),i?U("Exit fullscreen",t.jsx(H,{variant:"ghost",size:"sm",onClick:gt,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Exit fullscreen","aria-label":"Exit fullscreen",children:t.jsx(F,{name:"fullscreen-exit",className:"size-4"})})):!ue&&we==="full"&&U(he?"Exit fullscreen":"Fullscreen",t.jsx(H,{variant:"ghost",size:"sm",onClick:Ie,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:he?"Exit fullscreen":"Fullscreen","aria-label":he?"Exit fullscreen":"Fullscreen",children:he?t.jsx(F,{name:"fullscreen-exit",className:"size-4"}):t.jsx(F,{name:"fullscreen",className:"size-4"})}))]})},gc=({open:e,onOpenChange:r,isSaving:s,onSaveAndContinue:i,onDiscardAndContinue:o})=>t.jsx(ds,{open:e,onOpenChange:r,children:t.jsxs(fs,{showCloseButton:!1,className:"max-w-md",children:[t.jsxs(ms,{children:[t.jsx(ps,{children:"Unsaved changes"}),t.jsx(hs,{children:"Save your edits before continuing?"})]}),t.jsxs(gs,{children:[t.jsx(H,{variant:"outline",onClick:i,disabled:s,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:"Save changes"}),t.jsx(H,{variant:"destructive",onClick:o,children:"Discard"})]})]})}),ls=(e,r)=>e.startsWith(`${r}/`)?e.slice(r.length+1):e,xc=e=>e.index==="A"||e.working_dir==="?"?"git-added":e.index==="D"?"git-deleted":e.index==="M"||e.working_dir==="M"?"git-modified":null,vc=({root:e,openPaths:r,gitFiles:s})=>{const i=new Set(r),o=new Map,u=new Map,f={modified:0,added:0};for(const y of s??[]){o.has(y.path)||o.set(y.path,y);const S=+(y.index==="M"||y.working_dir==="M"),x=+(y.index==="A"||y.working_dir==="?");if(S===0&&x===0)continue;f.modified+=S,f.added+=x;const b=y.path.split("/");for(let j=1;j<b.length;j+=1){const C=b.slice(0,j).join("/");if(!C)continue;let v=u.get(C);v||(v={modified:0,added:0},u.set(C,v)),v.modified+=S,v.added+=x}}return{getFileStatus:y=>{if(i.has(y))return"open";if(o.size===0)return null;const S=ls(y,e),x=o.get(S);return x?xc(x):null},getFolderBadge:y=>{if(!s)return null;const S=ls(y,e);if(!S)return f.modified+f.added>0?{...f}:null;const x=u.get(S);return x?{...x}:null}}},bc=e=>new Set(e),yc=({root:e,isMobile:r,searchQuery:s,onSearchQueryChange:i,searchInputRef:o,searching:u,searchResults:f,selectedFile:m,onSelectFile:g,onOpenDialog:y,currentDirectory:S,refreshRoot:x,childrenByDir:b,loadErrorsByDir:j,expandedPaths:C,isBrowserClient:v,alwaysShowActions:P,getFileStatus:I,getFolderBadge:l,fileRowPermissions:B,downloadFile:L,contextMenuPath:W,setContextMenuPath:$,rightClickMenuPath:G,setRightClickMenuPath:K,toggleDirectory:J,handleRevealPath:D,refreshDirectory:T})=>{const k=!!(e&&b[e]),V=e?j[e]:null,E=a.useMemo(()=>bc(C),[C]);function R(d,A){const N=b[d]??[];return N.map((O,Y)=>{const ee=O.type==="directory",ne=ee&&E.has(O.path),te=m?.path===O.path,q=Y===N.length-1;return t.jsxs("li",{className:"relative",children:[A>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),q&&t.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),t.jsx(Li,{node:O,root:e,isExpanded:ne,isActive:te,isMobile:r,isBrowserClient:v,alwaysShowActions:P,status:ee?void 0:I(O.path),badge:ee?l(O.path):void 0,permissions:B,downloadFile:L,contextMenuPath:W,setContextMenuPath:$,rightClickMenuPath:G,setRightClickMenuPath:K,onSelect:g,onToggle:J,onRevealPath:D,onOpenDialog:y}),ee&&ne&&t.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[j[O.path]?t.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:j[O.path],children:j[O.path]}),t.jsxs(H,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{T(O.path)},children:[t.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):null,R(O.path,A+1)]})]},O.path)})}return t.jsxs("section",{className:X("flex min-h-0 flex-col overflow-hidden",r?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[t.jsx("div",{className:X("flex flex-col gap-2 py-2",r?"px-3":"px-2"),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative flex-1 min-w-0",children:[t.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),t.jsx(Rt,{ref:o,value:s,onChange:d=>i(d.target.value),placeholder:"Search files...",className:"h-8 pl-8 pr-8 typography-meta"}),s.trim().length>0&&t.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{i(""),o.current?.focus()},children:t.jsx(F,{name:"close",className:"size-4"})})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>y("createFile",{path:S,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New File","aria-label":"New File",children:t.jsx(F,{name:"file-add",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"New File"})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>y("createFolder",{path:S,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New Folder","aria-label":"New Folder",children:t.jsx(F,{name:"folder-add",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"New Folder"})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{x()},className:"size-8 p-0 flex-shrink-0",title:"Refresh","aria-label":"Refresh",children:t.jsx(F,{name:"refresh",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Refresh"})]})]})}),t.jsx(xs,{outerClassName:"flex-1 min-h-0",className:X("py-2",r?"px-3":"px-2"),children:t.jsx("ul",{className:"flex flex-col",children:u?t.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Searching..."]}):f.length>0?f.map(d=>{const A=m?.path===d.path;return t.jsx("li",{children:t.jsxs("button",{type:"button",onClick:()=>{g(d)},className:X("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",A?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[t.jsx(Ds,{filePath:d.path,extension:d.extension}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:d.path,children:d.relativePath??d.path})]})},d.path)}):V?t.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx("span",{className:"text-[var(--status-error)]",children:V}),t.jsxs(H,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{x()},children:[t.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):k?R(e,0):t.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:"Loading..."})})})]})},Tu=({mode:e="full",chrome:r="desktop",onClose:s,isVisible:i=!0})=>{const{files:o,runtime:u}=So(),f=r==="mobile",{currentTheme:m,availableThemes:g,lightThemeId:y,darkThemeId:S}=Ro(),{isMobile:x,isTablet:b,screenWidth:j}=Fo(),C=xo(u.platform),v=x||b,P=vo(),I=Eo()??"",l=oe(I.trim()),B=lc(r,e),L=e!=="editor-only",W=e==="editor-only"&&!x,$=zo(I),[G,K]=a.useState(""),J=a.useRef(null),[D,T]=a.useState(!1),[k,V]=a.useState(l),[E,R]=a.useState(!1),[d,A]=a.useState(!0),[N,O]=a.useState(!1),[Y,ee]=a.useState(!1),[ne,te]=a.useState(!1),q=a.useRef(null);a.useEffect(()=>{f&&(V(l),K(""),T(!1))},[f,l]);const Q=a.useRef(0),Qe=a.useCallback(n=>{Q.current=Math.max(0,Q.current+(n?1:-1))},[]),Oe=a.useCallback(n=>n instanceof Element?n.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);a.useEffect(()=>{if(!ne)return;const n=h=>{Q.current>0||Oe(h.target)||q.current&&!q.current.contains(h.target)&&te(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[Oe,ne]);const le=a.useMemo(()=>g.find(n=>n.metadata.id===y)??Nn(!1),[g,y]),Pe=a.useMemo(()=>g.find(n=>n.metadata.id===S)??Nn(!0),[g,S]);a.useEffect(()=>{An(le),An(Pe)},[le,Pe]);const Le=a.useMemo(()=>[],[]),se=Re(n=>l?n.byRoot[l]?.openPaths??Le:Le),ue=Re(n=>l?n.byRoot[l]?.selectedPath??null:null),we=Re(n=>l?n.byRoot[l]?.expandedPaths??Le:Le),he=Re(n=>n.removeOpenPath),Ie=Re(n=>n.removeOpenPathsByPrefix),gt=Re(n=>n.removeExpandedPathsByPrefix),Ee=Re(n=>n.setSelectedPath),_=Re(n=>n.toggleExpandedPath),U=Re(n=>n.expandPaths),{childrenByDir:ae,loadErrorsByDir:ge,isLoaded:de,loadDirectory:ot,refreshDirectory:Ft,refreshRoot:As}=dc({files:o,root:l,activeDirectory:f?k:void 0,expandedPaths:we,chrome:r,showGitignored:P,removeExpandedPathsByPrefix:gt,enabled:B,visible:i}),qe=a.useCallback(n=>{const h=oe(n),z=h.split("/"),M=z[z.length-1]||h,re=M.includes(".")?M.split(".").pop()?.toLowerCase():void 0;return{name:M,path:h,type:"file",extension:re}},[]),Et=a.useMemo(()=>se.map(qe),[se,qe]),rr=a.useMemo(()=>{if(ue){const n=Xt(ue);if(se.some(h=>Xt(h)===n))return ue}return se[0]??null},[se,ue]),p=a.useMemo(()=>rr?qe(rr):null,[rr,qe]),Ve=p?.path??"";a.useEffect(()=>{if(!l||!ue)return;const n=Xt(ue);se.some(z=>Xt(z)===n)||Ee(l,se[0]??null)},[se,l,ue,Ee]);const zt=!!(l&&Ve&&!kr(Ve,l)),Pr=zt?En(Ve):void 0,ce=a.useMemo(()=>({allowOutsideWorkspace:e==="editor-only"&&zt,outsideFileGrant:Pr,directory:l||void 0}),[e,zt,Pr,l]),nr=a.useRef(null),[Os,Ps]=a.useState({left:!1,right:!1}),Lr=a.useCallback(()=>{const n=nr.current;n&&Ps({left:n.scrollLeft>2,right:n.scrollLeft+n.clientWidth<n.scrollWidth-2})},[]),Ir=a.useRef(Lr);Ir.current=Lr,a.useEffect(()=>{const n=nr.current;if(!n)return;const h=()=>Ir.current();h(),n.addEventListener("scroll",h,{passive:!0});const z=new ResizeObserver(h);return z.observe(n),()=>{n.removeEventListener("scroll",h),z.disconnect()}},[Et.length]);const[ke,Be]=a.useState(""),[sr,it]=a.useState(!1),[Br,xe]=a.useState(null),[Ls,Ge]=a.useState(""),ve=a.useRef(""),[et,je]=a.useState(null),[ct,Ce]=a.useState(void 0),[$r,Ne]=a.useState(null),be=Re(n=>n.activeRuntimeKey),[fe,$e]=a.useState(null),[ar,Vr]=a.useState(!1),[Is,ze]=a.useState(!1),[lt,Se]=a.useState(""),[Bs,$s]=a.useState(`
|
|
4
|
+
`),Wr=a.useRef(null),Me=a.useRef(0),ut=a.useRef(null),[_r,or]=a.useState(!1),Mt=Fe(n=>n.autoSaveEnabled),Vs=Fe(n=>n.setAutoSaveEnabled),Ws=a.useRef(null),[_s,Ks]=a.useState(null),[qs,Gs]=a.useState(null),{value:Us,show:Hs}=zn(!1,1200),{value:Js,show:Xs}=zn(!1,1200),[Ys,Zs]=a.useState(!1),xt=a.useCallback(()=>{l&&Ee(l,null),Be(""),xe(null),Ge(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),x&&T(!1)},[x,l,Ee]),{operation:Qs,target:ea,inputValue:ta,setInputValue:ra,submitting:na,inputRef:sa,open:aa,close:oa,submit:ia,capabilities:{canCreateFile:Kr,canCreateFolder:qr,canRename:Gr,canDelete:Ur}}=oi({files:o,root:l,selectedPath:p?.path??"",refreshDirectory:Ft,removeOpenPathsByPrefix:Ie,clearSelectedPath:xt}),Hr=!!o.revealPath,ca=Jt(n=>n.availableApps),la=Jt(n=>n.isCacheStale),Jr=Jt(n=>n.initialize),ua=Jt(n=>n.loadInstalledApps);a.useEffect(()=>{Jr()},[Jr]);const da=a.useCallback(n=>{o.revealPath&&o.revealPath(n).catch(()=>{me.error("Failed to reveal path")})},[o]),fa=a.useCallback(async n=>{if(!p?.path||await bo(p.path,n.id,n.appName)||await Sn(p.path,n.appName))return;const M=ii(p.path)||l;M&&await Sn(M,n.appName)||me.error(`Failed to open in ${n.appName}`)},[l,p?.path]),ma=Fe(n=>n.fileEditorKeymap),Xr=Fe(n=>n.expandedEditorToolbar);a.useEffect(()=>{Se("")},[p?.path]);const Yr=a.useRef("");a.useEffect(()=>{!l||Yr.current===l||(Yr.current=l,Be(""),xe(null),Ge(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),T(!1))},[l]);const Zr=a.useRef(be);a.useEffect(()=>{Zr.current!==be&&(Zr.current=be,Me.current+=1,ut.current=null,Be(""),Se(""),xe(null),it(!1),Ge(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),or(!1))},[be]);const pa=f?k:I,{results:Qr,searching:en}=ci({directory:pa,query:G,chrome:r,showGitignored:P}),Tt=a.useCallback(async(n,h)=>{if(o.readFile){const Ae=await o.readFile(n,{...h??{},directory:l||void 0});return{content:Ae.content??"",revision:Ae.revision,exists:Ae.exists}}const z=new URLSearchParams({path:n});h?.allowOutsideWorkspace&&z.set("allowOutsideWorkspace","true"),h?.outsideFileGrant&&z.set("outsideFileGrant",h.outsideFileGrant),h?.optional&&z.set("optional","true"),l&&z.set("directory",l);const M=await Rn(`/api/fs/read?${z.toString()}`,{cache:h?.optional?"no-store":"default"});if(!M.ok){const Ae=await M.json().catch(()=>({error:M.statusText}));throw new Error(Ae.error||"Failed to read file")}const re=await M.text(),Z=M.headers?.get?.("x-pichamber-file-revision"),De=M.headers?.get?.("x-pichamber-file-exists")!=="false";return{content:re,revision:typeof Z=="string"&&Z.length>0?Z:De?void 0:null,exists:De}},[o,l]),dt=a.useCallback(async(n,h)=>{if(o.statFile){const z=await o.statFile(n,{...h??{},directory:l||void 0});return{path:z.path,size:z.size,mtimeMs:z.mtimeMs,revision:z.revision}}return null},[o,l]);a.useEffect(()=>{if(!l||!o.statFile||se.length===0)return;let n=!1;const h=[...se];return Promise.all(h.map(async z=>{try{const M=await o.statFile?.(z,{directory:l||void 0});!n&&M&&!M.isFile&&Ie(l,z)}catch(M){!n&&On(M)&&Ie(l,z)}})),()=>{n=!0}},[o,se,Ie,l]);const ir=a.useMemo(()=>ke.length>Nt?`${ke.slice(0,Nt)}
|
|
5
|
+
|
|
6
|
+
… truncated …`:ke,[ke]),Dt=lt!==ir,ha=a.useCallback((n,h)=>dt(n,{...ce,...h}),[dt,ce]),ga=a.useCallback(()=>{je(null),Ce(void 0),Ne(null)},[]),{recordStat:tt}=ac({selectedPath:p?.path??null,loadedPath:et,isDirty:Dt,readStat:ha,onExternalChange:ga}),tn=a.useRef(null),rn=a.useCallback((n,h,z,M)=>{Be(h);const re=M?.generation??Me.current;if(typeof z<"u"&&(Ce(z),Ne({runtimeKey:M?.runtimeKey??be,root:M?.root??l,path:n,generation:re})),l&&kr(n,l)){const Z=Ct(l,n);Z&&Mo.requestGitRefresh({directory:l,paths:[Z]})}Qt(n)&&tn.current?.(h),dt(n).then(Z=>{Z&&Me.current===re&&tt(Z)}).catch(()=>{})},[be,dt,tt,l]),cr=a.useCallback(()=>p?.path?{runtimeKey:be,root:l,path:p.path,generation:Me.current}:null,[be,l,p?.path]),nn=cr,sn=a.useCallback(async(n,h=null)=>{const z=Me.current,M=n.path;let re=null,Z=n.currentRevision,_e=n.exists;try{if(_e){const De=await Tt(M,ce);re=De.content,typeof De.revision=="string"&&(Z=De.revision),_e=De.exists!==!1}}catch{}Me.current===z&&($e({path:M,displayPath:Ct(l,M)||M,exists:_e,currentRevision:Z,currentContent:re,diagramXml:h}),ze(!1))},[Tt,l,ce]),an=a.useMemo(()=>{if(!p?.path||et!==p.path)return;const n=$r;if(n){if(Uo({...n},{runtimeKey:be,root:l,path:p.path,generation:Me.current}))return typeof ct=="string"||ct===null?"__stale__":void 0;if(typeof ct=="string"||ct===null)return ct}},[be,et,ct,$r,l,p?.path]),{clearDiagramContent:on,diagramEditorXml:xa,diagramSaved:va,drawioRemountNonce:ba,drawioViewMode:lr,handleDiagramChange:ya,htmlViewMode:At,jsonViewMode:Ot,mdViewMode:Pt,recordDiagramContent:ur,saveDiagramNow:dr,saveDrawioViewMode:wa,saveJsonViewMode:ka,saveMdViewMode:cn,saveTextViewMode:ja,setTextViewMode:fr,textViewMode:rt}=cc({root:l,selectedPath:p?.path??null,fileContent:ke,draftContent:lt,setDraftContent:Se,autoSaveEnabled:Mt,writeFile:o.writeFile,expectedRevision:an,captureSaveScope:cr,currentSaveScope:nn,onSaved:rn,onConflict:n=>{sn(n,n.xml)}});tn.current=ur;const Ue=a.useCallback(()=>Pt,[Pt]),{autoSaveStatus:Ca,isSaving:mr,clearSaveConflict:nt,saveDraft:ln,saveNow:Lt}=nc({autoSaveEnabled:Mt,selectedPath:p?.path??null,loadedPath:et,fileLoading:sr,isDirty:Dt,draftContent:lt,fileContent:ke,lineEnding:Bs,isNonEditableBinary:!!(p?.path&&(Er(p.path)||_r)),writeFile:o.writeFile,expectedRevision:an,onSaved:rn,captureSaveScope:cr,currentSaveScope:nn,onConflict:n=>{sn(n)}}),{confirmOpen:un,discardAndTakeIntent:dn,keepModalOpen:Na,requestNavigation:It,saveAndTakeIntent:fn}=Xi({isDirty:Dt,saveDraft:ln});a.useEffect(()=>{const n=h=>{yo(h)&&(h.key.toLowerCase()==="s"?(h.preventDefault(),Lt()):h.key.toLowerCase()==="f"&&(h.preventDefault(),ee(!0)))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[Lt]);const mn=a.useCallback(async n=>{const h=Me.current+1;Me.current=h;const z=be,M=l,re=()=>{if(!l||z!==be||M!==l)return!1;const ie=Re.getState().byRoot[l],Je=ie?.selectedPath??ie?.openPaths[0]??null;return Me.current===h&&Je===n.path};xe(null),Ge(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),nt(),or(!1),x&&T(!0);const Z=En(n.path),_e={allowOutsideWorkspace:e==="editor-only"&&!!l&&!kr(n.path,l),outsideFileGrant:Z};let De=!1;it(!0);let Ae;await Ji(n.path,u.isDesktop,ie=>Tt(ie,_e).then(Je=>(Ae=Je.revision,Je.content))).then(ie=>{if(re()){if(ie.kind!=="text"){if(Be(""),Se(""),ie.kind==="desktop-image"){De=!0;return}ie.kind==="binary"&&or(ie.detectedFromContent),je(n.path);return}$s(ie.lineEnding),Be(ie.content),ur(ie.content),Se(ie.draft),je(n.path),Ce(Ae),Ne({runtimeKey:z,root:M,path:n.path,generation:h}),dt(n.path,_e).then(Je=>{Je&&re()&&tt(Je)}).catch(()=>{})}}).catch(ie=>{if(re()){if(li(ie)){if(it(!1),l&&Ee(l,null),xe(null),Be(""),Se(""),je(null),Ce(void 0),Ne(null),tt(null),G.trim().length>0&&K(""),x&&T(!1),l){const br=[...Pn(n.path,l),n.path];br.length>0&&U(l,br);for(const Cn of br)de(Cn)||ot(Cn)}return}if(On(ie)){l&&Ie(l,n.path),Be(""),Se(""),xe(null),Ce(void 0),Ne(null),tt(null),x&&T(!1);return}Be(""),Se(""),xe(ie instanceof Error?ie.message:"Failed to read file"),Ce(void 0),Ne(null),tt(null)}}).finally(()=>{re()&&!De&&it(!1)})},[be,nt,U,de,x,ot,e,Tt,dt,ur,tt,Ie,l,u.isDesktop,G,Ee]),Bt=a.useCallback(async(n,h)=>{if(!l||!B)return;const z=Pn(n,l),M=h?[...z,n]:z;M.length>0&&U(l,M);const re=M.map(Z=>{if(!de(Z))return ot(Z)}).filter(Boolean);await Promise.all(re)},[U,de,ot,B,l]),pn=a.useCallback((n,h)=>{const z=h.findIndex(M=>M.path===n);return z===-1||h.length<=1?null:h[z+1]??h[z-1]??null},[]),We=a.useCallback(async n=>{It({kind:"select",file:n})||(l&&(Ee(l,n.path),Bt(n.path,!1)),xe(null),Ge(""),Be(""),on(),Se(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),nt(),x&&T(!0))},[on,nt,Bt,x,It,l,Ee]),Sa=a.useCallback(n=>{We(qe(n))},[We,qe]),Ra=a.useCallback(n=>{const h=oe(n);h&&(K(""),V(h),T(!1))},[]),Fa=a.useCallback(n=>{const h=oe(n);h&&(T(!0),We(qe(h)))},[We,qe]),Ea=a.useCallback(async()=>{if(!(!k||E)){R(!0);try{await Ft(k)}finally{R(!1)}}},[k,E,Ft]),za=a.useCallback(()=>{const n=fe;if(n){if(!n.exists){l&&he(l,n.path),xt(),$e(null),ze(!1),nt();return}Se(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),nt()}},[nt,xt,he,l,fe]),Ma=a.useCallback(async()=>{if(!(!fe||ar)){Vr(!0);try{(fe.diagramXml!==null?await dr(fe.path,fe.diagramXml,{overwrite:!0}):await Lt({overwrite:!0}))&&($e(null),ze(!1))}finally{Vr(!1)}}},[ar,fe,dr,Lt]),Ta=a.useCallback(()=>{$e(null),ze(!1)},[]);a.useEffect(()=>{!p?.path||!B||!i||Bt(p.path,!1)},[Bt,i,B,p?.path]),a.useEffect(()=>{if(!p){Me.current+=1,ut.current=null,it(!1);return}if(et===p.path||ut.current===p.path)return;const n=p.path;ut.current=n,mn(p).finally(()=>{ut.current===n&&(ut.current=null)})},[mn,et,p]);const ft=a.useCallback(async n=>{if(n.kind==="select"){await We(n.file);return}if(n.kind==="tab"){Fe.getState().setActiveMainTab(n.tab);return}l&&he(l,n.path),p?.path===n.path&&(n.nextFile?await We(n.nextFile):xt())},[xt,We,he,l,p?.path]),Da=a.useCallback(()=>{const n=dn();Se(ir),n&&ft(n)},[ft,dn,ir]),Aa=a.useCallback(async()=>{const n=await fn();n&&await ft(n)},[ft,fn]),Oa=a.useCallback(n=>{const h=p?.path===n,z={kind:"close",path:n,nextFile:pn(n,Et)};h&&It(z)||ft(z)},[ft,pn,Et,It,p?.path]),$t=a.useMemo(()=>vc({root:l,openPaths:se,gitFiles:$?.files}),[l,se,$]),Pa=a.useCallback(n=>$t.getFileStatus(n),[$t]),La=a.useCallback(n=>$t.getFolderBadge(n),[$t]),Ia=a.useCallback(async n=>{const h=oe(n);!l||!B||(_(l,h),de(h)||await ot(h))},[de,ot,B,l,_]),Ba=a.useMemo(()=>({canRename:Gr,canCreateFile:Kr,canCreateFolder:qr,canDelete:Ur,canReveal:Hr}),[Gr,Kr,qr,Ur,Hr]),Te=!!(p?.path&&bs(p.path)),mt=!!(p?.path&&ys(p.path)),st=!!(p?.path&&ws(p.path)),pr=!!(p?.path&&(Er(p.path)||_r)),Vt=pr&&!Te&&!st,pt=a.useMemo(()=>Ct(l,Ve),[Ve,l]),$a=!!(p&&(!Te||mt)&&!st&&!Vt&&ke.length>0),Va=!!(p&&pt.length>0),vt=!!(p&&!zt&&!pr&&!Te&&o.writeFile&&ke.length<=Nt),bt=!!(p?.path&&Es(p.path)),hr=!!(p?.path&&Fs(p.path)),yt=!!(p?.path&&Or(p.path)),hn=!!(p?.path&&Qt(p.path)),Wa=!!(p&&!pr&&!Te),{editorViewRef:ye,notifyEditorViewChanged:Wt,shouldMaskEditor:_a}=Zi({root:l,selectedPath:Ve||null,loadedPath:et,fileLoading:sr,fileError:Br,isImage:Te,isPdf:st,isUnsupportedBinary:Vt,canEdit:vt,textViewMode:rt,setTextViewMode:fr,draftContent:lt,confirmDiscardOpen:un,selectFilePath:Sa}),gn=Wa&&!bt&&!hn&&!(yt&&At==="preview"),Ka=bt&&Pt==="edit"||yt&&At==="edit"||hr&&Ot==="text"||!bt&&!yt&&!hr&&rt==="edit",_t=a.useMemo(()=>Ve?To(Ve):null,[Ve]),[xn,gr]=a.useState(null);a.useEffect(()=>{let n=!1;const h=p?.path;if(!h||_t){gr(null);return}return gr(null),Do(h).then(z=>{n||gr(z)}),()=>{n=!0}},[p?.path,_t]),a.useEffect(()=>{!vt&&rt==="edit"&&fr("view")},[vt,fr,rt]);const He=a.useCallback(n=>{if(!x||!n||!n.hasFocus||typeof window>"u")return;const h=window.visualViewport;if(!h)return;const z=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,z-(h.offsetTop+h.height))<=0)return;const re=n.state.selection.main.head,Z=n.coordsAtPos(re);if(!Z)return;const _e=Math.round(h.offsetTop+h.height),Ae=Z.bottom+20-_e;Ae<=0||(n.scrollDOM.scrollTop+=Ae)},[x]);a.useEffect(()=>{if(!x||typeof window>"u")return;const n=()=>{window.requestAnimationFrame(()=>{He(ye.current)})},h=window.visualViewport;return h?.addEventListener("resize",n),h?.addEventListener("scroll",n,{passive:!0}),document.addEventListener("selectionchange",n),()=>{h?.removeEventListener("resize",n),h?.removeEventListener("scroll",n),document.removeEventListener("selectionchange",n)}},[ye,x,He]);const Kt=Fe(n=>n.editorFontSize),qa=a.useMemo(()=>{if(!p?.path)return[$n(m,{fontSize:Kt})];const n=vs(p.path),h=[$n(m,n?{syntaxColors:!1,fontSize:Kt}:{fontSize:Kt})],z=_t??xn;return z&&h.push(z),n&&h.push(Fi({language:n,themeName:m.metadata.id,theme:qo(m)})),d&&h.push(pe.lineWrapping),x&&h.push(pe.updateListener.of(M=>{M.view.hasFocus&&(M.selectionSet||M.focusChanged||M.viewportChanged||M.geometryChanged)&&window.requestAnimationFrame(()=>{He(M.view)})})),h},[m,p?.path,_t,xn,d,x,He,Kt]),Ga=a.useMemo(()=>({light:le.metadata.id,dark:Pe.metadata.id}),[le.metadata.id,Pe.metadata.id]),qt=p?.path&&Te&&!u.isDesktop&&!mt?`${p.path}|${ce.allowOutsideWorkspace?"outside":"workspace"}|${ce.outsideFileGrant??""}`:"",Gt=p?.path&&st?`${p.path}|${ce.allowOutsideWorkspace?"outside":"workspace"}|${ce.outsideFileGrant??""}`:"",wt=p?.path&&yt&&At==="preview"?p.path:"",xr="Failed to read file",{readyKey:vn,nonce:Ua}=jr(qt,xe,xr),{readyKey:bn,nonce:Ha}=jr(wt,xe,xr),{readyKey:yn,nonce:Ja}=jr(Gt,xe,xr),Xa=!!(qt&&vn!==qt),Ya=!!(wt&&bn!==wt),Za=!!(Gt&&yn!==Gt),Qa=p?.path&&Te?u.isDesktop?mt?`data:${Mn(p.path)};utf8,${encodeURIComponent(ke)}`:Ls:mt?`data:${Mn(p.path)};utf8,${encodeURIComponent(ke)}`:vn===qt?yr().authenticatedAsset("/api/fs/raw",{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}):"":"",eo=p?.path&&st&&yn===Gt?yr().authenticatedAsset("/api/fs/raw",{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}):"",to=wt&&bn===wt&&p?.path?(()=>{const n=p.path.split("/").map(h=>encodeURIComponent(h)).join("/");return yr().authenticatedAsset(`/api/fs/serve${n.startsWith("/")?n:`/${n}`}`)})():void 0;a.useEffect(()=>{let n=!1;return(async()=>{if(!u.isDesktop||!p?.path||!Te||mt){ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),Ge("");return}xe(null),ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),await(o.readFileBinary?o.readFileBinary(p.path,ce).then(M=>M.dataUrl):(async()=>{const M=await Rn("/api/fs/raw",{query:{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}});if(!M.ok)throw new Error("Failed to read file");const re=await M.blob(),Z=URL.createObjectURL(re);return n?(URL.revokeObjectURL(Z),""):(ve.current=Z,Z)})()).then(M=>{n||(Ge(M),je(p.path))}).catch(M=>{ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),n||(Ge(""),xe(M instanceof Error?M.message:"Failed to read file"),je(null))}).finally(()=>{n||it(!1)})})(),()=>{n=!0}},[o,Te,mt,l,u.isDesktop,p?.path,ce]),a.useEffect(()=>()=>{ve.current&&(URL.revokeObjectURL(ve.current),ve.current="")},[]);const wn=a.useCallback(()=>{const n=o.downloadFile,h=p?.path;!n||!h||n(h).catch(z=>{console.error("Download failed:",z),me.error("Operation failed")})},[o.downloadFile,p?.path]),vr=({exitFullscreenOnly:n=!1,layout:h="floating"}={})=>t.jsx(hc,{selectedFile:p,displaySelectedPath:pt,layout:h,exitFullscreenOnly:n,canEdit:vt,isEditingFile:Ka,isSaving:mr,autoSaveEnabled:Mt,autoSaveStatus:Ca,isDirty:Dt,onSaveDraft:ln,onToggleAutoSave:()=>Vs(!Mt),openInApps:ca,openInCacheStale:la,onOpenInApp:fa,onRefreshOpenInApps:()=>ua(!0),onToolbarDropdownOpenChange:Qe,isSelectedImage:Te,isSelectedPdf:st,isUnsupportedBinary:Vt,wrapLines:d,onToggleWrapLines:()=>A(!d),textViewMode:rt,onToggleSearch:()=>ee(!Y),isGoToLineOpen:Ys,onOpenGoToLineChange:Zs,editorView:ye.current,canUseShikiFileView:gn,isJson:hr,isHtml:yt,onToggleTextViewMode:()=>{ja(rt==="view"?"edit":"view")},isMarkdown:bt,mdViewMode:Ue(),onToggleMdViewMode:()=>cn(Ue()==="preview"?"edit":"preview"),isDrawio:hn,drawioViewMode:lr,onToggleDrawioViewMode:()=>wa(lr==="preview"?"edit":"preview"),diagramSaved:va,onSaveDiagram:async()=>{const z=Wr.current?.getXml();p?.path&&z&&await dr(p.path,z)},jsonViewMode:Ot,onToggleJsonViewMode:()=>ka(Ot==="tree"?"text":"tree"),canCopy:$a,copiedContent:Us,onCopyContent:async()=>{(await Yt(ke)).ok?Hs(!0):me.error("Copy failed")},canCopyPath:Va,copiedPath:Js,onCopyPath:async()=>{(await Yt(pt)).ok?Xs(!0):me.error("Copy failed")},onDownloadFile:o.downloadFile&&p?wn:void 0,isMobile:x,mode:e,isFullscreen:N,onToggleFullscreen:()=>O(!N),onExitFullscreen:()=>O(!1)}),ro=a.useCallback(n=>{ye.current=n,Wt(),window.requestAnimationFrame(()=>{He(n)})},[ye,Wt,He]),no=a.useCallback(()=>{ye.current&&(ye.current=null),Wt()},[ye,Wt]),so=a.useCallback(n=>{ye.current=n,window.requestAnimationFrame(()=>{He(n)})},[ye,He]),ao=a.useCallback(()=>{ye.current&&(ye.current=null)},[ye]),kn={selectedFile:p,loading:sr||Xa||Za,suppressLoadingIndicator:W,fileError:Br,isSelectedImage:Te,imageSrc:Qa,imagePreviewNonce:Ua,isSelectedPdf:st,pdfSrc:eo,pdfPreviewNonce:Ja,isUnsupportedBinary:Vt,onDownload:o.downloadFile&&p?wn:void 0,drawioViewMode:lr,drawioRemountNonce:ba,diagramEditorRef:Wr,diagramEditorXml:xa,onDiagramChange:ya,jsonViewMode:Ot,markdownViewMode:Pt,htmlViewMode:At,htmlLoading:Ya,htmlPreviewNonce:Ha,htmlPreviewSrc:to,fileContent:ke,canUseShikiFileView:gn,textViewMode:rt,draftContent:lt,onDraftChange:Se,canEdit:vt,vimMode:ma==="vim",editorExtensions:qa,shouldMaskEditorForPendingNavigation:_a,pierreTheme:Ga,shikiThemeType:m.metadata.variant==="dark"?"dark":"light",wrapLines:d},Ut=t.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[t.jsx(gc,{open:un,onOpenChange:Na,isSaving:mr,onSaveAndContinue:()=>{Aa()},onDiscardAndContinue:Da}),t.jsx(Ho,{open:!!fe,conflict:fe?{path:fe.path,displayPath:fe.displayPath,exists:fe.exists,currentRevision:fe.currentRevision,currentContent:fe.currentContent,dirtyContent:fe.diagramXml??lt}:null,isResolving:ar||mr,showCompare:Is,onToggleCompare:()=>ze(n=>!n),onReload:za,onOverwrite:()=>{Ma()},onClose:Ta}),t.jsxs("div",{className:X("flex flex-col flex-shrink-0",L&&"border-b border-border/40"),children:[t.jsx(fc,{showEditorTabsRow:L,isMobile:x,showMobilePageContent:D,onBackMobile:()=>T(!1),selectedFile:p,openFiles:Et,root:l,alwaysShowActions:v,editorTabsOverflow:Os,editorTabsScrollRef:nr,onSelectFile:We,onCloseFile:Oa}),(Xr||x)&&p?t.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[pt&&!x?t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:pt,children:pt}):null,t.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:vr({layout:"docked"})})]}):null]}),t.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[p&&!Y&&!(Xr||x)&&t.jsx("div",{ref:q,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{Q.current>0||te(!1)},children:ne?vr():t.jsxs("div",{className:"flex items-center gap-1",children:[bt?t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>cn(Ue()==="preview"?"edit":"preview"),className:X("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",Ue()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":Ue()==="preview"?"Switch to edit mode":"Switch to preview mode",title:Ue()==="preview"?"Switch to edit mode":"Switch to preview mode",children:t.jsx(F,{name:Ue()==="preview"?"eye":"eye-off",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:Ue()==="preview"?"Switch to edit mode":"Switch to preview mode"})]}):null,t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",onMouseEnter:()=>te(!0),children:t.jsx(H,{variant:"ghost",size:"sm",onClick:()=>te(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":"Show editor controls",title:"Editor controls",children:t.jsx(F,{name:"more-2-fill",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Editor controls"})]})]})}),t.jsx(ns,{variant:"embedded",...kn,enableRichPreviews:!0,editorWrapperRef:Ws,onEditorViewReady:ro,onEditorViewDestroy:no,enableSearch:!0,searchOpen:Y,onSearchOpenChange:ee})]})]}),jn=t.jsx(yc,{root:l,isMobile:x,searchQuery:G,onSearchQueryChange:K,searchInputRef:J,searching:en,searchResults:Qr,selectedFile:p,onSelectFile:We,onOpenDialog:aa,currentDirectory:I,refreshRoot:As,childrenByDir:ae,loadErrorsByDir:ge,expandedPaths:we,isBrowserClient:C,alwaysShowActions:v,getFileStatus:Pa,getFolderBadge:La,fileRowPermissions:Ba,downloadFile:o.downloadFile,contextMenuPath:_s,setContextMenuPath:Ks,rightClickMenuPath:qs,setRightClickMenuPath:Gs,toggleDirectory:Ia,handleRevealPath:da,refreshDirectory:Ft}),oo=e==="full"&&N&&p&&t.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:t.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[t.jsx("div",{className:"absolute right-4 top-4 z-30",children:vr({exitFullscreenOnly:!0})}),t.jsx(ns,{variant:"fullscreen",...kn,enableRichPreviews:!1,onEditorViewReady:so,onEditorViewDestroy:ao})]})});return f?t.jsx(Ti,{root:l,directory:k||l,entries:k||l?ae[k||l]:void 0,query:G,searchResults:Qr,isSearching:en,directoryError:k||l?ge[k||l]??null:null,refreshing:E,editorPath:D?p?.path??null:null,editor:Ut,onClose:s,onQueryChange:K,onOpenDirectory:Ra,onOpenFile:Fa,onBackFromEditor:()=>T(!1),onRefresh:()=>{Ea()}}):t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[t.jsx(Ai,{activeDialog:Qs,dialogData:ea,dialogInputValue:ta,onDialogInputChange:ra,isDialogSubmitting:na,onDialogSubmit:ia,onClose:oa,inputRef:sa}),oo,x?D?Ut:jn:e==="editor-only"?t.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Ut})}):t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[j>=700&&t.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:jn}),t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Ut})]})]})};export{Tu as FilesView};
|