@pi-chamber/web 0.9.3 → 0.9.4
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-CV-iReyY.js → DiagramView-CHy1Glsl.js} +1 -1
- package/dist/assets/{DiffView-DVd1MLPB.js → DiffView-CBOrV4hS.js} +1 -1
- package/dist/assets/{FilesView-CPnW4I90.js → FilesView-CK2YVs_W.js} +1 -1
- package/dist/assets/{GitView-Dj_7hgX_.js → GitView-BEFLOv_7.js} +3 -3
- package/dist/assets/{JsonTreeView-Cyy0lEZR.js → JsonTreeView-CKWGm5MS.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BXN78Wu_.js → MarkdownRendererImpl-hE_nmSqe.js} +1 -1
- package/dist/assets/{PatchDiff-C7dA3U29.js → PatchDiff-BagRxMON.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-dr3g9DR7.js → SessionSwitcherContent-z9VYCXrT.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-C3zdd82V.js → SessionSwitcherDropdown-icxJk_lT.js} +2 -2
- package/dist/assets/{SessionUnreadDot-qeik5qtT.js → SessionUnreadDot-Bv-5KguB.js} +1 -1
- package/dist/assets/SettingsView-Ck0qxtKP.js +2 -0
- package/dist/assets/{SettingsWindow-Bbay2W76.js → SettingsWindow-GQRL2CdD.js} +1 -1
- package/dist/assets/{ToolOutputDialog-CRTiN1CH.js → ToolOutputDialog-CxJUXVZW.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-CqnNcLPk.js → ToolPartDiffPreview-BXuLRWHT.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-iqwryMNU.js → VirtualizedFileDiff-DfaXovGB.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-Bbugxxtp.js → computeVirtualFileMetrics-DG_E6iaN.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BC3ie230.js → contextFileOpenGuard-DPBE3ELv.js} +1 -1
- package/dist/assets/{gitStatusPredicates-DbThKVSf.js → gitStatusPredicates-OljV4Bb2.js} +1 -1
- package/dist/assets/{index-v6K3L94m.js → index-DmexVlTQ.js} +1 -1
- package/dist/assets/{isDiffPlainText-Dl0RBjPZ.js → isDiffPlainText-aikgiqLb.js} +1 -1
- package/dist/assets/{isFilePlainText-CbrmvrM6.js → isFilePlainText-D-Dl6LqX.js} +1 -1
- package/dist/assets/{main-4PkIvzf4.js → main-BXdraZTZ.js} +3 -3
- package/dist/assets/{main-DMyWi0qs.js → main-DG1oZ0Wj.js} +2 -2
- package/dist/assets/{markdownCore-BD5WkOKU.js → markdownCore-DUjQU2i0.js} +1 -1
- package/dist/assets/{miniChat-CLMNhna4.js → miniChat-BEAtOkr9.js} +2 -2
- package/dist/assets/{mobile-rWMDwhtQ.js → mobile-DOFBBQg2.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-BRhGNRJ8.js → renderElectronMiniChatApp-B0K72YnS.js} +2 -2
- package/dist/assets/{renderMobileApp-DLy2YoQg.js → renderMobileApp-Ca_BO_s4.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-Z9YtcHxZ.js → runtimeEndpointReset-Cx2tsgTo.js} +3 -3
- package/dist/assets/{useAppFontEffects-DfuJVB15.js → useAppFontEffects-C4JL1x7k.js} +84 -84
- package/dist/assets/{useFilesViewSearch-BZBHrZ90.js → useFilesViewSearch-Du0DnmKs.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-BxTkEajM.js → usePushVisibilityBeacon-BnHxIv4r.js} +1 -1
- package/dist/assets/{useSwitcherItems-jITqE8PV.js → useSwitcherItems-C91mwPJD.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CDdfwzlS.js → vendor-codemirror-language-data-C493X_9w.js} +2 -2
- package/dist/assets/{web-components-C9wXMuCp.js → web-components-B2Rw__yK.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/mini-chat.html +1 -1
- package/dist/mobile.html +1 -1
- package/package.json +1 -1
- package/server/lib/pi/routes.js +13 -3
- package/server/lib/pi/routes.test.js +55 -1
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -2
- package/server/lib/pi/session-daemon/prompt-operations.test.js +51 -0
- package/server/lib/pi/session-daemon/session-daemon.js +189 -54
- package/server/lib/pi/session-daemon/session-daemon.test.js +186 -0
- package/dist/assets/SettingsView-C57uV1YS.js +0 -2
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. 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. 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 r,j as t}from"./vendor-react-B5Z1Mdn3.js";import{u as a}from"./index-KIdiBFJs.js";import{j as v,I as m}from"./useAppFontEffects-
|
|
1
|
+
import{R as r,j as t}from"./vendor-react-B5Z1Mdn3.js";import{u as a}from"./index-KIdiBFJs.js";import{j as v,I as m}from"./useAppFontEffects-C4JL1x7k.js";import{D as j}from"./DiagramEditor-DuGmiPZ5.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-CySRuLbN.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-C493X_9w.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.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-react-drawio-BYDptOsj.js";function Kt(){const{files:o}=v(),[e,d]=r.useState(null),[s,p]=r.useState(""),[x,n]=r.useState(!0),l=r.useRef(null),c=a(i=>i.pendingDiagramFile),u=r.useCallback(async i=>{n(!0),d(i);try{const f=await o?.readFile?.(i);f&&p(f.content)}catch{p("")}finally{n(!1)}},[o]);r.useEffect(()=>{if(!c)return;const i=a.getState().consumePendingDiagramFile();i&&u(i)},[u,c]);const g=r.useCallback(async()=>{const i=l.current?.getXml();e&&o?.writeFile&&i&&i!==s&&(await o.writeFile(e,i),p(i))},[e,o,s]),h=e?e.split("/").pop()||e:"";return e?x?t.jsx("div",{className:"flex h-full items-center justify-center p-3",children:t.jsx(m,{name:"loader-4",className:"size-4 animate-spin"})}):t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[t.jsx(m,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:h}),t.jsx("button",{type:"button",onClick:()=>{g()},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:t.jsx(m,{name:"save-3",className:"size-4"})}),t.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:t.jsx(m,{name:"close",className:"size-4"})})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(j,{ref:l,xml:s,className:"h-full"})})]}):t.jsx("div",{className:"flex h-full items-center justify-center p-3",children:t.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{Kt as DiagramView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{c as te,u as J,h as Ze,n as ze}from"./index-KIdiBFJs.js";import{b3 as vt,b4 as Ct,am as jt,as as et,b5 as tt,aT as Nt,p as Ne,a4 as Le,I as q,j as nt,a0 as re,t as st,aW as it,aE as Lt,b6 as Dt,b7 as kt,aF as Rt,b8 as Et,b9 as At,ba as Tt,bb as Mt,k as It,bc as $t,bd as Pt,S as _t,U as Wt,V as Bt}from"./useAppFontEffects-
|
|
1
|
+
import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{c as te,u as J,h as Ze,n as ze}from"./index-KIdiBFJs.js";import{b3 as vt,b4 as Ct,am as jt,as as et,b5 as tt,aT as Nt,p as Ne,a4 as Le,I as q,j as nt,a0 as re,t as st,aW as it,aE as Lt,b6 as Dt,b7 as kt,aF as Rt,b8 as Et,b9 as At,ba as Tt,bb as Mt,k as It,bc as $t,bd as Pt,S as _t,U as Wt,V as Bt}from"./useAppFontEffects-C4JL1x7k.js";import{d as rt,P as Ot,i as Ge,a as He,b as zt,C as Gt}from"./gitStatusPredicates-OljV4Bb2.js";import{p as Ht}from"./VirtualizedFileDiff-DfaXovGB.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-DPBE3ELv.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-CySRuLbN.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-C493X_9w.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.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-B2Rw__yK.js";import"./computeVirtualFileMetrics-DG_E6iaN.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-Cx2tsgTo.js";import"./SessionUnreadDot-Bv-5KguB.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";import"./isDiffPlainText-aikgiqLb.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}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e,R as o,b as Ts,r as k}from"./vendor-react-B5Z1Mdn3.js";import{c as H,E as Ds,F as As,G as Os,H as Ps,I as Ls,u as we,J as ke,K as Is,L as lt,M as Vs,N as $s,O as Bs,g as sn,P as Ws,Q as on,r as cn,R as rr,T as _s}from"./index-KIdiBFJs.js";import{bh as qs,I as j,bi as mt,bj as Us,b5 as ut,aU as Bn,aV as Wn,bk as _n,bl as qn,bm as Un,bn as Hn,a4 as U,D as hr,a as gr,b as xr,A as Lt,t as ie,bo as It,bp as Hs,bq as pt,as as Kn,a9 as ln,aP as Ks,aT as Gn,p as Jn,br as Yn,o as Xn,n as mr,q as Gs,S as Pe,U as Le,V as Ie,j as Js,aR as Ys,b8 as Xs,aF as Qs,ba as Zs,bs as un,bt as dn,Z as eo,bd as to,bu as ro,bv as no,bw as fn}from"./useAppFontEffects-DfuJVB15.js";import{E as ce,D as Bt,V as Qn,s as ao,d as so,e as oo,f as mn,k as nr,W as io}from"./vendor-codemirror-view-Ct4T37Ue.js";import{H as pn,x as At,y as co,i as lo,z as uo}from"./vendor-codemirror-language-BByA_dGF.js";import{a as c,c as fo}from"./vendor-lezer-highlight-CDMHUZ74.js";import{i as Zn,S as mo,k as br,E as po,o as _e,a as ho}from"./vendor-codemirror-state-CNWM3Q8V.js";import{ensurePierreThemeRegistered as hn,getResolvedShikiTheme as go}from"./appThemeRegistry-gegrE2dq.js";import{D as xo}from"./DiagramEditor-DuGmiPZ5.js";import{C as bo,a as vo,b as wo,c as yo,d as ko,e as Ot}from"./runtimeEndpointReset-Z9YtcHxZ.js";import{s as ea,b as pr,c as ta}from"./SessionUnreadDot-qeik5qtT.js";import{g as Vt,i as ra,a as vr,b as Wt,n as jo,d as No,M as dt,c as de,s as Co,e as So,f as Ro,h as Fo,t as Pt,j as ar,u as Eo,k as zo,l as Mo,m as gn,o as To,p as xn}from"./useFilesViewSearch-BZBHrZ90.js";import{J as Do,F as Ao}from"./JsonTreeView-Cyy0lEZR.js";import{h as Oo,j as Po,k as Lo,l as Io}from"./vendor-codemirror-commands-DYppkHEk.js";import{a as bn,g as $t,b as vn,c as wn,o as Vo,d as $o}from"./vendor-codemirror-search-BV44140v.js";import{v as Bo,g as Wo}from"./vendor-replit-codemirror-vim-CGHHNQxC.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-CySRuLbN.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-CDdfwzlS.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-C9wXMuCp.js";import"./computeVirtualFileMetrics-Bbugxxtp.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-CbrmvrM6.js";function yn(t,r){const n=t.metadata.variant==="dark",s=t.config?.fonts?.mono||"monospace",i=t.colors.syntax.highlights||{},u=t.colors.syntax.tokens||{},d=r?.fontSize?`${r.fontSize}px`:"var(--text-code)",p=ce.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:d,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:s,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:u.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:u.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:u.boolean||t.colors.syntax.base.number},".cm-builtin":{color:u.functionCall||t.colors.syntax.base.function},".cm-def":{color:u.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:u.variableOther||u.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:u.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:u.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:u.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:u.tag||t.colors.syntax.base.keyword},".cm-link":{color:u.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:i.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.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:i.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.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 ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.elevated,color:t.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, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.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 ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.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:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.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:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.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:t.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:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.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:t.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:t.colors.interactive.hover,color:t.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:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),x=pn.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"}]),N=pn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],color:t.colors.syntax.base.comment},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],color:t.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:t.colors.syntax.base.operator},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],color:t.colors.syntax.base.string},{tag:c.escape,color:u.stringEscape||t.colors.syntax.base.string},{tag:[c.number,c.bool,c.atom,c.null,c.self],color:t.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:t.colors.syntax.base.function},{tag:c.definition(c.variableName),color:u.variableGlobal||t.colors.syntax.base.variable},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],color:t.colors.syntax.base.variable},{tag:c.propertyName,color:u.variableProperty||t.colors.syntax.base.variable},{tag:c.attributeName,color:u.variableOther||t.colors.syntax.base.variable},{tag:[c.className,c.typeName,c.namespace],color:t.colors.syntax.base.type},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],color:u.tag||t.colors.syntax.base.keyword},{tag:c.link,color:u.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],color:u.punctuation||t.colors.syntax.base.comment}]);return r?.syntaxColors===!1?[p]:[p,At(co,{fallback:!0}),At(fo),At(x),At(N)]}const _o=180,na=mo.define(),qo=1,Uo=2,Ho=4,kn=new Map,Ko=(t,r)=>{const n=`${t}|${r}`,s=kn.get(n);if(s)return s;let i="";t&&(i+=`color:${t};`),r&qo&&(i+="font-style:italic;"),r&Uo&&(i+="font-weight:bold;"),r&Ho&&(i+="text-decoration:underline;");const u=Bt.mark({attributes:{style:i}});return kn.set(n,u),u},Go=(t,r)=>{const n=new br,s=t.state.doc,i=Math.min(r.length,s.lines);for(let u=0;u<i;u+=1){const d=r[u];if(!d||d.length===0)continue;const p=s.line(u+1);let x=p.from;for(const[N,g,z]of d){if(N<=0)continue;const m=x,R=Math.min(x+N,p.to);x+=N,!(R<=m)&&(!g&&!z||n.add(m,R,Ko(g,z)))}}return n.finish()},Jo=Zn.define({create(){return Bt.none},update(t,r){let n=t.map(r.changes);for(const s of r.effects)s.is(na)&&(n=s.value);return n},provide:t=>ce.decorations.from(t)}),Yo=t=>Qn.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)},_o)}async tokenize(r){const n=++this.generation,s=r.state.doc.toString(),i=await qs(s,t.language,t.themeName,t.theme);i&&n===this.generation&&r.state.doc.length===s.length&&r.dispatch({effects:na.of(Go(r,i))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Xo=t=>[Jo,Yo(t)],ze=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/g,""),et=t=>{const r=ze(t);return!r||r==="/"?r||"/":r.split("/").filter(Boolean).at(-1)??r},aa=t=>{const r=ze(t);if(!r||r==="/")return null;const n=r.lastIndexOf("/");if(n<0)return null;if(n===0)return"/";const s=r.slice(0,n);return/^[A-Za-z]:$/.test(s)?`${s}/`:s},jn=(t,r)=>{const n=ze(t),s=ze(r);return!n||!s?!1:n===s||n.startsWith(`${s}/`)},Nn=(t,r)=>{const n=ze(t);if(!n)return ze(r);if(n.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(n))return n;const s=ze(r);return s?`${s}/${n}`:n},Qo=(t,r)=>{const n=ze(t),s=ze(r);if(!n||n===s)return!1;const i=aa(n);return i?s&&jn(n,s)?jn(i,s):!0:!1},Zo=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const r=["KB","MB","GB"];let n=t/1024;for(const s of r){if(n<1024||s===r[r.length-1])return`${n.toFixed(n>=10?0:1)} ${s}`;n/=1024}return""},ei=(t,r)=>!r||t===r?et(t):t.startsWith(`${r}/`)?t.slice(r.length+1):t,ti=({root:t,directory:r,entries:n,query:s,searchResults:i,isSearching:u,directoryError:d,refreshing:p,editorPath:x,editor:N,onClose:g,onQueryChange:z,onOpenDirectory:m,onOpenFile:R,onBackFromEditor:C,onRefresh:w})=>{if(!t)return e.jsx(ft,{message:"Select a project to browse files."});if(x)return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e.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:e.jsx(j,{name:"arrow-left",className:"size-5"})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:et(x)})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:N})]});const B=r===t?"Project files":et(r),E=Qo(r,t)?aa(r):null,l=!!E&&!s.trim(),V=E===t?"Project files":et(E??"");return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[g?e.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:g,style:{touchAction:"manipulation"},children:e.jsx(j,{name:"close",className:"size-5"})}):null,l&&E?e.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 ${et(E)}`,onClick:()=>m(E),style:{touchAction:"manipulation"},children:e.jsx(j,{name:"arrow-left",className:"size-5"})}):null,e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:B})}),e.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:w,style:{touchAction:"manipulation"},children:e.jsx(j,{name:"refresh",className:H("size-5",p&&"animate-spin")})})]}),e.jsx("div",{className:"shrink-0 px-3 pb-2 pt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(j,{name:"search",className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(mt,{value:s,onChange:$=>z($.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),e.jsx(Us,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:d?e.jsx(ft,{message:d}):s.trim()?e.jsx(ri,{root:t,results:i,isSearching:u,onOpenFile:R}):n===void 0?e.jsx(ft,{loading:!0,message:"Loading..."}):e.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[l&&E?e.jsxs("button",{type:"button",className:ea,"aria-label":`Up one level to ${V}`,onClick:()=>m(E),style:{touchAction:"manipulation"},children:[e.jsx(j,{name:"arrow-left",className:H(pr(!0),"text-muted-foreground")}),e.jsx("span",{className:H(ta(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,n.length===0?e.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,n.map($=>e.jsx(sa,{name:$.name,path:$.path,directory:$.type==="directory",meta:$.type==="directory"?void 0:Zo($.size),onClick:()=>$.type==="directory"?m(Nn($.path,r||t)):R(Nn($.path,r||t))},$.path))]})})]})},sa=({name:t,path:r,directory:n,meta:s,onClick:i})=>e.jsxs("button",{type:"button",className:ea,onClick:i,style:{touchAction:"manipulation"},children:[n?e.jsx(j,{name:"folder-3-fill",className:H(pr(!0),"text-primary/80")}):e.jsx(ut,{filePath:r,className:pr(!0)}),e.jsx("span",{className:H(ta(!0),"flex-1 text-foreground"),children:t}),s?e.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:s}):null,n?e.jsx(j,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),ri=({root:t,results:r,isSearching:n,onOpenFile:s})=>n?e.jsx(ft,{loading:!0,message:"Loading..."}):r.length===0?e.jsx(ft,{message:"No files found."}):e.jsx("div",{className:"flex w-full min-w-0 flex-col",children:r.map(i=>e.jsx(sa,{name:et(i.path),path:i.path,directory:!1,meta:i.relativePath??ei(i.path,t),onClick:()=>s(i.path)},i.path))}),ft=({message:t,loading:r=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[r?e.jsx(j,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):e.jsx(j,{name:"folder-open-fill",className:"size-6 text-muted-foreground"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t})]})}),ni=({activeDialog:t,dialogData:r,dialogInputValue:n,onDialogInputChange:s,isDialogSubmitting:i,onDialogSubmit:u,onClose:d,inputRef:p})=>e.jsx(Bn,{open:!!t,onOpenChange:x=>!x&&d(),children:e.jsxs(Wn,{initialFocus:p,children:[e.jsxs(_n,{children:[e.jsxs(qn,{children:[t==="createFile"&&"Create File",t==="createFolder"&&"Create Folder",t==="rename"&&"Rename",t==="delete"&&"Delete"]}),e.jsxs(Un,{children:[t==="createFile"&&`Create a new file in ${r?.path??"root"}`,t==="createFolder"&&`Create a new folder in ${r?.path??"root"}`,t==="rename"&&`Rename ${r?.name??""}`,t==="delete"&&`Are you sure you want to delete ${r?.name??""}? This action cannot be undone.`]})]}),t!=="delete"&&e.jsx("div",{className:"py-4",children:e.jsx(mt,{value:n,onChange:x=>s(x.target.value),placeholder:t==="rename"?"New name":"Name",onKeyDown:x=>{x.key==="Enter"&&u()},ref:p})}),e.jsxs(Hn,{children:[e.jsx(U,{variant:"outline",onClick:d,disabled:i,children:"Cancel"}),e.jsx(U,{variant:t==="delete"?"destructive":"default",onClick:()=>{u()},disabled:i||t!=="delete"&&!n.trim(),children:i?e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}):t==="delete"?"Delete":"Confirm"})]})]})}),ai=({label:t,iconDataUrl:r})=>{const[n,s]=o.useState(!1),i=t.trim().slice(0,1).toUpperCase()||"?";return r&&!n?e.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:()=>s(!0)}):e.jsx("span",{className:H("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:i})},oa=({filePath:t,extension:r})=>e.jsx(ut,{filePath:t,extension:r}),si=({status:t})=>{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)"}[t];return e.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:r}})},Cn=({name:t})=>{const r=o.useRef(null),n=o.useRef(null),[s,i]=o.useState(!1);return o.useLayoutEffect(()=>{const u=r.current,d=n.current;if(!u||!d)return;const p=()=>{i(d.scrollWidth>u.clientWidth+1)};p();const x=new ResizeObserver(p);return x.observe(u),x.observe(d),()=>{x.disconnect()}},[t]),e.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{ref:n,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:t}),s?e.jsxs("span",{className:"open-file-name-marquee-track",children:[e.jsx("span",{className:"open-file-name-marquee-item",children:t}),e.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:t})]}):e.jsx("span",{className:"block min-w-0 truncate",children:t})]})},oi=({node:t,root:r,isExpanded:n,isActive:s,isMobile:i,isBrowserClient:u,alwaysShowActions:d,status:p,badge:x,permissions:N,downloadFile:g,contextMenuPath:z,setContextMenuPath:m,rightClickMenuPath:R,setRightClickMenuPath:C,onSelect:w,onToggle:B,onRevealPath:E,onOpenDialog:l})=>{const V=t.type==="directory",{canRename:$,canCreateFile:I,canCreateFolder:_,canDelete:K,canReveal:W}=N,T=!V&&!!g,S=W&&!u,D=$||I||_||K||T||S,b=o.useCallback(A=>{D&&(A?.preventDefault(),C(t.path))},[D,t.path,C]),M=o.useCallback(()=>{V?B(t.path):w(t)},[V,t,w,B]),y=o.useCallback(A=>{A.stopPropagation(),C(null),m(t.path)},[t.path,m,C]),F=({Item:A,Separator:q})=>e.jsxs(e.Fragment,{children:[$&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("rename",t)},children:[e.jsx(j,{name:"edit",className:"mr-2 size-4"})," ","Rename"]}),e.jsxs(A,{onClick:O=>{O.stopPropagation(),Lt(t.path).then(J=>{if(J.ok){ie.success("Path copied");return}ie.error("Copy failed")})},children:[e.jsx(j,{name:"file-copy",className:"mr-2 size-4"})," ","Copy Path"]}),e.jsxs(A,{onClick:O=>{O.stopPropagation();const J=Vt(r,t.path)||t.path;Lt(J).then(X=>{if(X.ok){ie.success("Relative path copied");return}ie.error("Copy failed")})},children:[e.jsx(j,{name:"file-copy-2",className:"mr-2 size-4"})," ","Copy Relative Path"]}),!V&&g&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),g(t.path).catch(J=>{console.error("Download failed:",J),ie.error("Operation failed")})},children:[e.jsx(j,{name:"download",className:"mr-2 size-4"})," ",u?"Download":"Save"]}),S&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),E(t.path)},children:[e.jsx(j,{name:"folder-received",className:"mr-2 size-4"})," ",Ds()]}),V&&(I||_)&&e.jsxs(e.Fragment,{children:[e.jsx(q,{}),I&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("createFile",t)},children:[e.jsx(j,{name:"file-add",className:"mr-2 size-4"})," ","New File"]}),_&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("createFolder",t)},children:[e.jsx(j,{name:"folder-add",className:"mr-2 size-4"})," ","New Folder"]})]}),K&&e.jsxs(e.Fragment,{children:[e.jsx(q,{}),e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("delete",t)},className:"text-destructive focus:text-destructive",children:[e.jsx(j,{name:"delete-bin",className:"mr-2 size-4"})," ","Delete"]})]})]});return e.jsxs(bo,{open:R===t.path,onOpenChange:A=>C(A?t.path:null),children:[e.jsxs(vo,{render:e.jsx("div",{className:"group relative flex items-center",onContextMenu:i?void 0:b}),children:[e.jsxs("button",{type:"button",onClick:M,onContextMenu:i?void 0:b,className:H("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",s?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[V?n?e.jsx(j,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(j,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(oa,{filePath:t.path,extension:t.extension}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:t.path,children:t.name}),!V&&p&&e.jsx(si,{status:p}),V&&x&&e.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[x.modified>0&&e.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",x.modified]}),x.added>0&&e.jsxs("span",{className:"text-[var(--status-success)]",children:["+",x.added]})]})]}),D&&e.jsx("div",{className:H("absolute right-1 top-1/2 -translate-y-1/2",d?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:e.jsxs(hr,{open:z===t.path,onOpenChange:A=>m(A?t.path:null),children:[e.jsx(gr,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-6",onClick:y,children:e.jsx(j,{name:"more-2-fill",className:"size-4"})})}),e.jsx(xr,{align:"end",side:"bottom",onCloseAutoFocus:()=>m(null),children:F({Item:It,Separator:Hs})})]})})]}),e.jsx(wo,{className:"min-w-[180px]",children:F({Item:yo,Separator:ko})})]})},sr=(t,r,n)=>{const[s,i]=o.useState(""),[u,d]=o.useState(0);return o.useEffect(()=>{if(!t){i("");return}let p=!1;i("");const x=As(),N=Os(x);Ps(x).then(z=>{p||!z||(i(t),r(null))}).catch(z=>{p||(r(z instanceof Error?z.message:n),i(t))});const g=Ls(()=>{p||(i(t),d(z=>z+1),r(null))});return()=>{p=!0,N(),g()}},[t,r,n]),{readyKey:s,nonce:u}},ii=t=>t!==null&&typeof t=="object"&&"updateStatus"in t&&typeof t.updateStatus=="function",ci=t=>{const r=document.createElement("div");r.className="cm-vim-panel";const n=Wo(t);if(!n)return{top:!1,dom:r};n.state.statusbar=r;const s=n.state.vimPlugin;return ii(s)&&s.updateStatus(),{top:!1,dom:r,destroy(){n.state.statusbar===r&&(n.state.statusbar=null)}}};function Sn(t){return t?[Bo(),ao.of(ci),so()]:[]}const li={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},ui={case:"Match case",re:"Regular expression",word:"Match whole word"};function di(t){const r=t.querySelector(".cm-search");if(r){for(const[n,s]of Object.entries(li)){const i=r.querySelector(`button[name="${n}"]`);i&&!i.title&&(i.title=s)}for(const[n,s]of Object.entries(ui)){const u=r.querySelector(`input[name="${n}"]`)?.parentElement;u&&!u.title&&(u.title=s)}}}const or=new WeakMap;function fi(t,r){const n=$t(t.state);if(!n.valid)return or.delete(t),0;const s=or.get(t);if(!r&&s?.doc===t.state.doc&&s.query.eq(n))return s.total;const i=n.getCursor(t.state);let u=0;for(let d=i.next();!d.done;d=i.next())u+=1;return or.set(t,{query:n,doc:t.state.doc,total:u}),u}function mi(t){const r=$t(t.state);if(!r.valid)return 0;const n=t.state.selection.main,s=r.getCursor(t.state);let i=0,u=0;for(let d=s.next();!d.done;d=s.next()){const p=d.value;if(i+=1,u===0&&(u=i),n.from===p.from&&n.to===p.to||n.from<p.to&&n.to>p.from||p.from>=n.head)return i}return u}function Rn(t,r,n=!1){const s=t.querySelector(".cm-search");if(!s)return;let i=s.querySelector(".cm-search-message");if(!i){i=document.createElement("span"),i.className="cm-search-message",i.setAttribute("aria-live","polite");const p=s.querySelector('button[name="next"]'),x=p?.parentNode===s?p:s.firstChild;s.insertBefore(i,x)}const u=fi(r,n),d=u===0?0:mi(r);i.textContent=u===0?"":`${d}/${u}`}const Fn=new _e,En=new _e,zn=new _e,Mn=new _e,Tn=new _e,Dn=new _e,An=new _e,On=t=>t,ir=uo,pi=Vo,hi=$o;class gi extends io{constructor(r,n){super(),this.id=r,this.containerMap=n}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 Pn=(t,r)=>!t||t.length===0?[]:Zn.define({create(n){const s=new br,i=[...t].sort((u,d)=>u.afterLine-d.afterLine);for(const u of i){const d=n.doc.lines;if(u.afterLine>d)continue;const p=n.doc.line(u.afterLine);s.add(p.to,p.to,Bt.widget({widget:new gi(u.id,r),block:!0,side:1}))}return s.finish()},update(n,s){return n.map(s.changes)},provide:n=>ce.decorations.from(n)}),Ln=t=>{if(!t)return[];const r=Math.max(1,t.start),n=Math.max(r,t.end);return Qn.fromClass(class{decorations;constructor(s){this.decorations=this.build(s)}update(s){(s.docChanged||s.viewportChanged)&&(this.decorations=this.build(s.view))}build(s){const i=new br;for(let u=r;u<=n&&u<=s.state.doc.lines;u+=1){const d=s.state.doc.line(u);i.add(d.from,d.from,Bt.line({class:"oc-cm-selected-line"}))}return i.finish()}},{decorations:s=>s.decorations})};function xi({value:t,onChange:r,extensions:n,className:s,readOnly:i,lineNumbersConfig:u,highlightLines:d,onViewReady:p,onViewDestroy:x,blockWidgets:N,enableSearch:g,searchOpen:z,onSearchOpenChange:m,vimMode:R}){const C=o.useRef(null),w=o.useRef(null),B=o.useRef(t),E=o.useRef(r),l=o.useRef(p),V=o.useRef(x),$=o.useRef(m),I=o.useRef(N),_=o.useRef(R),K=o.useRef(new Map),[W,T]=o.useState([]),S=o.useCallback(b=>{const M=(b??[]).map(y=>{const F=K.current.get(y.id);return F?{id:y.id,content:y.content,container:F}:null}).filter(y=>y!==null);T(y=>y.length===M.length&&y.every((F,A)=>{const q=M[A];return F.id===q.id&&F.content===q.content&&F.container===q.container})?y:M)},[]),D=o.useCallback(b=>{const M=C.current,y=b??w.current;if(!M||!y)return;const F=y.dom.querySelector(".cm-gutters"),A=F instanceof HTMLElement?F.getBoundingClientRect().width:0;M.style.setProperty("--oc-editor-gutter-width",`${A}px`)},[]);return o.useEffect(()=>{B.current=t},[t]),o.useEffect(()=>{E.current=r},[r]),o.useEffect(()=>{l.current=p,V.current=x},[p,x]),o.useEffect(()=>{$.current=m},[m]),o.useEffect(()=>{I.current=N,S(N)},[N,S]),o.useEffect(()=>{if(!C.current)return;const b=(()=>{if(typeof document>"u")return null;const y=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(y)return y;const F=window.__PICHAMBER_CSP_NONCE__;return typeof F=="string"&&F.length>0?F:null})(),M=po.create({doc:B.current,extensions:[...b?[ce.cspNonce.of(b)]:[],oo({fixed:!0}),Fn.of(mn(u)),Oo(),lo.of(" "),An.of(Sn(R)),nr.of([Po,...Lo,...Io]),ce.updateListener.of(y=>{D(y.view),(y.viewportChanged||y.geometryChanged)&&S(I.current);const F=bn(y.startState),A=bn(y.state);F!==A&&$.current?.(A);const q=!$t(y.startState).eq($t(y.state));if(A&&(F!==A||q||y.docChanged||y.selectionSet)&&Rn(y.view.dom,y.view,F!==A||q||y.docChanged),!y.docChanged)return;const O=y.state.doc.toString();B.current=O,E.current(O),S(I.current)}),En.of(ce.editable.of(!i)),zn.of(n??[]),Mn.of(Ln(d)),Tn.of(Pn(N,K.current)),Dn.of(g?[vn({top:!0}),nr.of(On(wn))]:[])]});return w.current=new ce({state:M,parent:C.current}),ir(w.current,w.current.state.doc.length,200),w.current.requestMeasure(),requestAnimationFrame(()=>{D(w.current),S(I.current)}),w.current&&l.current?.(w.current),()=>{V.current?.(),w.current?.destroy(),w.current=null,T([])}},[I,D,S]),o.useEffect(()=>{const b=w.current;b&&(b.dispatch({effects:[Fn.reconfigure(mn(u)),En.reconfigure(ce.editable.of(!i)),zn.reconfigure(n??[]),Mn.reconfigure(Ln(d)),Tn.reconfigure(Pn(N,K.current)),Dn.reconfigure(g?[vn({top:!0}),nr.of(On(wn))]:[])]}),ir(b,b.state.doc.length,200),b.requestMeasure(),requestAnimationFrame(()=>{D(b),S(I.current)}))},[n,d,u,i,N,g,D,S]),o.useEffect(()=>{const b=w.current;if(!b){_.current=R;return}_.current!==R&&(_.current=R,b.dispatch({effects:An.reconfigure(Sn(R))}))},[R]),o.useEffect(()=>{const b=w.current;!b||g===!1||(z?(pi(b),requestAnimationFrame(()=>{di(b.dom),Rn(b.dom,b,!0)})):hi(b))},[z,g]),o.useEffect(()=>{const b=w.current;if(!b)return;const M=b.state.doc.toString();M!==t&&(b.dispatch({changes:{from:0,to:M.length,insert:t}}),ir(b,b.state.doc.length,300),b.requestMeasure(),requestAnimationFrame(()=>D(b)))},[t,D]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:C,className:H("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)]",s)}),W.map(b=>Ts.createPortal(b.content,b.container,b.id))]})}const In=({variant:t,selectedFile:r,loading:n,suppressLoadingIndicator:s,fileError:i,isSelectedImage:u,imageSrc:d,imagePreviewNonce:p,isSelectedPdf:x,pdfSrc:N,pdfPreviewNonce:g,isUnsupportedBinary:z,onDownload:m,enableRichPreviews:R,drawioViewMode:C,drawioRemountNonce:w,diagramEditorRef:B,diagramEditorXml:E,onDiagramChange:l,jsonViewMode:V,markdownViewMode:$,htmlViewMode:I,htmlLoading:_,htmlPreviewNonce:K,htmlPreviewSrc:W,fileContent:T,canUseShikiFileView:S,textViewMode:D,draftContent:b,onDraftChange:M,canEdit:y,vimMode:F,editorExtensions:A,editorWrapperRef:q,shouldMaskEditorForPendingNavigation:O,onEditorViewReady:J,onEditorViewDestroy:X,enableSearch:he=!1,searchOpen:ge,onSearchOpenChange:fe,pierreTheme:je,shikiThemeType:Ve,wrapLines:xe})=>{const ae=t==="fullscreen",se=ae?"p-4":"p-3",Ne=!!(r?.path&&pt(r.path)),Q=!!(r?.path&&ra(r.path)),L=!!(r?.path&&vr(r.path)),G=!!(r?.path&&Wt(r.path)),ne=()=>r?e.jsx("div",{className:"h-full",children:e.jsx(Ao,{file:{name:r.name,contents:b,lang:Gn(r.path)||void 0},options:{disableFileHeader:!0,overflow:xe?"wrap":"scroll",theme:je,themeType:Ve},className:"block h-full w-full",style:{height:"100%"}})}):null;return e.jsx(Kn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:r?n?s?e.jsx("div",{className:se}):e.jsxs("div",{className:`${se} flex items-center gap-2 typography-ui text-muted-foreground`,children:[e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}),ae?"Loading…":"Loading..."]}):i?e.jsx("div",{className:`${se} typography-ui text-[color:var(--status-error)]`,children:i}):u?e.jsx("div",{className:H("flex h-full items-center justify-center",se),children:e.jsx("img",{src:d,alt:r.name||"Image",className:H("max-w-full object-contain rounded-md border border-border/30 bg-primary/10",ae?"max-h-full":"max-h-[70vh]")},p)}):x?e.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:e.jsx("iframe",{src:N,className:"h-full w-full border-0",title:r.name},g)}):z?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx("div",{className:"typography-ui-header text-foreground",children:"Cannot preview binary file"}),e.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."}),m?e.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:m,children:[e.jsx(j,{name:"download",className:"mr-2 size-4"}),"Save file"]}):null]}):R&&Ne&&C==="preview"?e.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:e.jsx(xo,{ref:B,xml:E,onChange:l},`${r.path}:${w}`)}):R&&Q&&V==="tree"?e.jsx(ln,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"JSON viewer unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to text mode to view raw content."})]}),children:e.jsx("div",{className:"h-full overflow-auto",children:e.jsx(Do,{jsonString:T,maxHeight:"100%",initiallyExpandedDepth:2})})}):L&&$==="preview"?e.jsxs("div",{className:H("h-full overflow-auto",se),children:[T.length>500*1024?e.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(T.length/1024)}KB). Preview may be limited.`}):null,e.jsx(ln,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:e.jsx(Ks,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):R&&G&&I==="preview"?_?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:"Loading..."}):e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx("iframe",{src:W,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:"HTML Preview"},K)}):S&&D==="view"?ne():e.jsxs("div",{className:H("relative h-full",O&&"overflow-hidden"),ref:q,children:[e.jsx("div",{className:H("h-full",O&&"invisible"),children:e.jsx(xi,{value:b,onChange:M,readOnly:!y,vimMode:F,extensions:A,className:"h-full",onViewReady:J,onViewDestroy:X,...he?{enableSearch:!0,searchOpen:ge,onSearchOpenChange:fe}:{}})}),O?e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}),"Opening file at change..."]})}):null]}):e.jsx("div",{className:`${se} typography-ui text-muted-foreground`,children:"Pick a file from the tree."})})};async function bi(t,r,n){if(Jn(t)&&!Yn(t))return{kind:r?"desktop-image":"asset-image"};if(Xn(t))return{kind:"pdf"};if(mr(t))return{kind:"binary",detectedFromContent:!1};const i=await n(t);if(Gs(i))return{kind:"binary",detectedFromContent:!0};const u=jo(i);return{kind:"text",content:u,draft:u.length>dt?`${u.slice(0,dt)}
|
|
1
|
+
import{j as e,R as o,b as Ts,r as k}from"./vendor-react-B5Z1Mdn3.js";import{c as H,E as Ds,F as As,G as Os,H as Ps,I as Ls,u as we,J as ke,K as Is,L as lt,M as Vs,N as $s,O as Bs,g as sn,P as Ws,Q as on,r as cn,R as rr,T as _s}from"./index-KIdiBFJs.js";import{bh as qs,I as j,bi as mt,bj as Us,b5 as ut,aU as Bn,aV as Wn,bk as _n,bl as qn,bm as Un,bn as Hn,a4 as U,D as hr,a as gr,b as xr,A as Lt,t as ie,bo as It,bp as Hs,bq as pt,as as Kn,a9 as ln,aP as Ks,aT as Gn,p as Jn,br as Yn,o as Xn,n as mr,q as Gs,S as Pe,U as Le,V as Ie,j as Js,aR as Ys,b8 as Xs,aF as Qs,ba as Zs,bs as un,bt as dn,Z as eo,bd as to,bu as ro,bv as no,bw as fn}from"./useAppFontEffects-C4JL1x7k.js";import{E as ce,D as Bt,V as Qn,s as ao,d as so,e as oo,f as mn,k as nr,W as io}from"./vendor-codemirror-view-Ct4T37Ue.js";import{H as pn,x as At,y as co,i as lo,z as uo}from"./vendor-codemirror-language-BByA_dGF.js";import{a as c,c as fo}from"./vendor-lezer-highlight-CDMHUZ74.js";import{i as Zn,S as mo,k as br,E as po,o as _e,a as ho}from"./vendor-codemirror-state-CNWM3Q8V.js";import{ensurePierreThemeRegistered as hn,getResolvedShikiTheme as go}from"./appThemeRegistry-gegrE2dq.js";import{D as xo}from"./DiagramEditor-DuGmiPZ5.js";import{C as bo,a as vo,b as wo,c as yo,d as ko,e as Ot}from"./runtimeEndpointReset-Cx2tsgTo.js";import{s as ea,b as pr,c as ta}from"./SessionUnreadDot-Bv-5KguB.js";import{g as Vt,i as ra,a as vr,b as Wt,n as jo,d as No,M as dt,c as de,s as Co,e as So,f as Ro,h as Fo,t as Pt,j as ar,u as Eo,k as zo,l as Mo,m as gn,o as To,p as xn}from"./useFilesViewSearch-Du0DnmKs.js";import{J as Do,F as Ao}from"./JsonTreeView-CKWGm5MS.js";import{h as Oo,j as Po,k as Lo,l as Io}from"./vendor-codemirror-commands-DYppkHEk.js";import{a as bn,g as $t,b as vn,c as wn,o as Vo,d as $o}from"./vendor-codemirror-search-BV44140v.js";import{v as Bo,g as Wo}from"./vendor-replit-codemirror-vim-CGHHNQxC.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-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.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-CySRuLbN.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-C493X_9w.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-B2Rw__yK.js";import"./computeVirtualFileMetrics-DG_E6iaN.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-D-Dl6LqX.js";function yn(t,r){const n=t.metadata.variant==="dark",s=t.config?.fonts?.mono||"monospace",i=t.colors.syntax.highlights||{},u=t.colors.syntax.tokens||{},d=r?.fontSize?`${r.fontSize}px`:"var(--text-code)",p=ce.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:d,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:s,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:u.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:u.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:u.boolean||t.colors.syntax.base.number},".cm-builtin":{color:u.functionCall||t.colors.syntax.base.function},".cm-def":{color:u.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:u.variableOther||u.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:u.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:u.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:u.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:u.tag||t.colors.syntax.base.keyword},".cm-link":{color:u.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:i.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.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:i.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.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 ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.elevated,color:t.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, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.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 ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.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:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.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:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.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:t.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:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.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:t.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:t.colors.interactive.hover,color:t.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:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:n}),x=pn.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"}]),N=pn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],color:t.colors.syntax.base.comment},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],color:t.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:t.colors.syntax.base.operator},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],color:t.colors.syntax.base.string},{tag:c.escape,color:u.stringEscape||t.colors.syntax.base.string},{tag:[c.number,c.bool,c.atom,c.null,c.self],color:t.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:t.colors.syntax.base.function},{tag:c.definition(c.variableName),color:u.variableGlobal||t.colors.syntax.base.variable},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],color:t.colors.syntax.base.variable},{tag:c.propertyName,color:u.variableProperty||t.colors.syntax.base.variable},{tag:c.attributeName,color:u.variableOther||t.colors.syntax.base.variable},{tag:[c.className,c.typeName,c.namespace],color:t.colors.syntax.base.type},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],color:u.tag||t.colors.syntax.base.keyword},{tag:c.link,color:u.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],color:u.punctuation||t.colors.syntax.base.comment}]);return r?.syntaxColors===!1?[p]:[p,At(co,{fallback:!0}),At(fo),At(x),At(N)]}const _o=180,na=mo.define(),qo=1,Uo=2,Ho=4,kn=new Map,Ko=(t,r)=>{const n=`${t}|${r}`,s=kn.get(n);if(s)return s;let i="";t&&(i+=`color:${t};`),r&qo&&(i+="font-style:italic;"),r&Uo&&(i+="font-weight:bold;"),r&Ho&&(i+="text-decoration:underline;");const u=Bt.mark({attributes:{style:i}});return kn.set(n,u),u},Go=(t,r)=>{const n=new br,s=t.state.doc,i=Math.min(r.length,s.lines);for(let u=0;u<i;u+=1){const d=r[u];if(!d||d.length===0)continue;const p=s.line(u+1);let x=p.from;for(const[N,g,z]of d){if(N<=0)continue;const m=x,R=Math.min(x+N,p.to);x+=N,!(R<=m)&&(!g&&!z||n.add(m,R,Ko(g,z)))}}return n.finish()},Jo=Zn.define({create(){return Bt.none},update(t,r){let n=t.map(r.changes);for(const s of r.effects)s.is(na)&&(n=s.value);return n},provide:t=>ce.decorations.from(t)}),Yo=t=>Qn.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)},_o)}async tokenize(r){const n=++this.generation,s=r.state.doc.toString(),i=await qs(s,t.language,t.themeName,t.theme);i&&n===this.generation&&r.state.doc.length===s.length&&r.dispatch({effects:na.of(Go(r,i))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Xo=t=>[Jo,Yo(t)],ze=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/g,""),et=t=>{const r=ze(t);return!r||r==="/"?r||"/":r.split("/").filter(Boolean).at(-1)??r},aa=t=>{const r=ze(t);if(!r||r==="/")return null;const n=r.lastIndexOf("/");if(n<0)return null;if(n===0)return"/";const s=r.slice(0,n);return/^[A-Za-z]:$/.test(s)?`${s}/`:s},jn=(t,r)=>{const n=ze(t),s=ze(r);return!n||!s?!1:n===s||n.startsWith(`${s}/`)},Nn=(t,r)=>{const n=ze(t);if(!n)return ze(r);if(n.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(n))return n;const s=ze(r);return s?`${s}/${n}`:n},Qo=(t,r)=>{const n=ze(t),s=ze(r);if(!n||n===s)return!1;const i=aa(n);return i?s&&jn(n,s)?jn(i,s):!0:!1},Zo=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const r=["KB","MB","GB"];let n=t/1024;for(const s of r){if(n<1024||s===r[r.length-1])return`${n.toFixed(n>=10?0:1)} ${s}`;n/=1024}return""},ei=(t,r)=>!r||t===r?et(t):t.startsWith(`${r}/`)?t.slice(r.length+1):t,ti=({root:t,directory:r,entries:n,query:s,searchResults:i,isSearching:u,directoryError:d,refreshing:p,editorPath:x,editor:N,onClose:g,onQueryChange:z,onOpenDirectory:m,onOpenFile:R,onBackFromEditor:C,onRefresh:w})=>{if(!t)return e.jsx(ft,{message:"Select a project to browse files."});if(x)return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e.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:e.jsx(j,{name:"arrow-left",className:"size-5"})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:et(x)})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:N})]});const B=r===t?"Project files":et(r),E=Qo(r,t)?aa(r):null,l=!!E&&!s.trim(),V=E===t?"Project files":et(E??"");return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[g?e.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:g,style:{touchAction:"manipulation"},children:e.jsx(j,{name:"close",className:"size-5"})}):null,l&&E?e.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 ${et(E)}`,onClick:()=>m(E),style:{touchAction:"manipulation"},children:e.jsx(j,{name:"arrow-left",className:"size-5"})}):null,e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:B})}),e.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:w,style:{touchAction:"manipulation"},children:e.jsx(j,{name:"refresh",className:H("size-5",p&&"animate-spin")})})]}),e.jsx("div",{className:"shrink-0 px-3 pb-2 pt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(j,{name:"search",className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(mt,{value:s,onChange:$=>z($.target.value),placeholder:"Search files",className:"h-11 pl-9"})]})}),e.jsx(Us,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:d?e.jsx(ft,{message:d}):s.trim()?e.jsx(ri,{root:t,results:i,isSearching:u,onOpenFile:R}):n===void 0?e.jsx(ft,{loading:!0,message:"Loading..."}):e.jsxs("div",{className:"flex w-full min-w-0 flex-col",children:[l&&E?e.jsxs("button",{type:"button",className:ea,"aria-label":`Up one level to ${V}`,onClick:()=>m(E),style:{touchAction:"manipulation"},children:[e.jsx(j,{name:"arrow-left",className:H(pr(!0),"text-muted-foreground")}),e.jsx("span",{className:H(ta(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,n.length===0?e.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,n.map($=>e.jsx(sa,{name:$.name,path:$.path,directory:$.type==="directory",meta:$.type==="directory"?void 0:Zo($.size),onClick:()=>$.type==="directory"?m(Nn($.path,r||t)):R(Nn($.path,r||t))},$.path))]})})]})},sa=({name:t,path:r,directory:n,meta:s,onClick:i})=>e.jsxs("button",{type:"button",className:ea,onClick:i,style:{touchAction:"manipulation"},children:[n?e.jsx(j,{name:"folder-3-fill",className:H(pr(!0),"text-primary/80")}):e.jsx(ut,{filePath:r,className:pr(!0)}),e.jsx("span",{className:H(ta(!0),"flex-1 text-foreground"),children:t}),s?e.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:s}):null,n?e.jsx(j,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),ri=({root:t,results:r,isSearching:n,onOpenFile:s})=>n?e.jsx(ft,{loading:!0,message:"Loading..."}):r.length===0?e.jsx(ft,{message:"No files found."}):e.jsx("div",{className:"flex w-full min-w-0 flex-col",children:r.map(i=>e.jsx(sa,{name:et(i.path),path:i.path,directory:!1,meta:i.relativePath??ei(i.path,t),onClick:()=>s(i.path)},i.path))}),ft=({message:t,loading:r=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[r?e.jsx(j,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):e.jsx(j,{name:"folder-open-fill",className:"size-6 text-muted-foreground"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t})]})}),ni=({activeDialog:t,dialogData:r,dialogInputValue:n,onDialogInputChange:s,isDialogSubmitting:i,onDialogSubmit:u,onClose:d,inputRef:p})=>e.jsx(Bn,{open:!!t,onOpenChange:x=>!x&&d(),children:e.jsxs(Wn,{initialFocus:p,children:[e.jsxs(_n,{children:[e.jsxs(qn,{children:[t==="createFile"&&"Create File",t==="createFolder"&&"Create Folder",t==="rename"&&"Rename",t==="delete"&&"Delete"]}),e.jsxs(Un,{children:[t==="createFile"&&`Create a new file in ${r?.path??"root"}`,t==="createFolder"&&`Create a new folder in ${r?.path??"root"}`,t==="rename"&&`Rename ${r?.name??""}`,t==="delete"&&`Are you sure you want to delete ${r?.name??""}? This action cannot be undone.`]})]}),t!=="delete"&&e.jsx("div",{className:"py-4",children:e.jsx(mt,{value:n,onChange:x=>s(x.target.value),placeholder:t==="rename"?"New name":"Name",onKeyDown:x=>{x.key==="Enter"&&u()},ref:p})}),e.jsxs(Hn,{children:[e.jsx(U,{variant:"outline",onClick:d,disabled:i,children:"Cancel"}),e.jsx(U,{variant:t==="delete"?"destructive":"default",onClick:()=>{u()},disabled:i||t!=="delete"&&!n.trim(),children:i?e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}):t==="delete"?"Delete":"Confirm"})]})]})}),ai=({label:t,iconDataUrl:r})=>{const[n,s]=o.useState(!1),i=t.trim().slice(0,1).toUpperCase()||"?";return r&&!n?e.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:()=>s(!0)}):e.jsx("span",{className:H("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:i})},oa=({filePath:t,extension:r})=>e.jsx(ut,{filePath:t,extension:r}),si=({status:t})=>{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)"}[t];return e.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:r}})},Cn=({name:t})=>{const r=o.useRef(null),n=o.useRef(null),[s,i]=o.useState(!1);return o.useLayoutEffect(()=>{const u=r.current,d=n.current;if(!u||!d)return;const p=()=>{i(d.scrollWidth>u.clientWidth+1)};p();const x=new ResizeObserver(p);return x.observe(u),x.observe(d),()=>{x.disconnect()}},[t]),e.jsxs("span",{ref:r,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{ref:n,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:t}),s?e.jsxs("span",{className:"open-file-name-marquee-track",children:[e.jsx("span",{className:"open-file-name-marquee-item",children:t}),e.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:t})]}):e.jsx("span",{className:"block min-w-0 truncate",children:t})]})},oi=({node:t,root:r,isExpanded:n,isActive:s,isMobile:i,isBrowserClient:u,alwaysShowActions:d,status:p,badge:x,permissions:N,downloadFile:g,contextMenuPath:z,setContextMenuPath:m,rightClickMenuPath:R,setRightClickMenuPath:C,onSelect:w,onToggle:B,onRevealPath:E,onOpenDialog:l})=>{const V=t.type==="directory",{canRename:$,canCreateFile:I,canCreateFolder:_,canDelete:K,canReveal:W}=N,T=!V&&!!g,S=W&&!u,D=$||I||_||K||T||S,b=o.useCallback(A=>{D&&(A?.preventDefault(),C(t.path))},[D,t.path,C]),M=o.useCallback(()=>{V?B(t.path):w(t)},[V,t,w,B]),y=o.useCallback(A=>{A.stopPropagation(),C(null),m(t.path)},[t.path,m,C]),F=({Item:A,Separator:q})=>e.jsxs(e.Fragment,{children:[$&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("rename",t)},children:[e.jsx(j,{name:"edit",className:"mr-2 size-4"})," ","Rename"]}),e.jsxs(A,{onClick:O=>{O.stopPropagation(),Lt(t.path).then(J=>{if(J.ok){ie.success("Path copied");return}ie.error("Copy failed")})},children:[e.jsx(j,{name:"file-copy",className:"mr-2 size-4"})," ","Copy Path"]}),e.jsxs(A,{onClick:O=>{O.stopPropagation();const J=Vt(r,t.path)||t.path;Lt(J).then(X=>{if(X.ok){ie.success("Relative path copied");return}ie.error("Copy failed")})},children:[e.jsx(j,{name:"file-copy-2",className:"mr-2 size-4"})," ","Copy Relative Path"]}),!V&&g&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),g(t.path).catch(J=>{console.error("Download failed:",J),ie.error("Operation failed")})},children:[e.jsx(j,{name:"download",className:"mr-2 size-4"})," ",u?"Download":"Save"]}),S&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),E(t.path)},children:[e.jsx(j,{name:"folder-received",className:"mr-2 size-4"})," ",Ds()]}),V&&(I||_)&&e.jsxs(e.Fragment,{children:[e.jsx(q,{}),I&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("createFile",t)},children:[e.jsx(j,{name:"file-add",className:"mr-2 size-4"})," ","New File"]}),_&&e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("createFolder",t)},children:[e.jsx(j,{name:"folder-add",className:"mr-2 size-4"})," ","New Folder"]})]}),K&&e.jsxs(e.Fragment,{children:[e.jsx(q,{}),e.jsxs(A,{onClick:O=>{O.stopPropagation(),l("delete",t)},className:"text-destructive focus:text-destructive",children:[e.jsx(j,{name:"delete-bin",className:"mr-2 size-4"})," ","Delete"]})]})]});return e.jsxs(bo,{open:R===t.path,onOpenChange:A=>C(A?t.path:null),children:[e.jsxs(vo,{render:e.jsx("div",{className:"group relative flex items-center",onContextMenu:i?void 0:b}),children:[e.jsxs("button",{type:"button",onClick:M,onContextMenu:i?void 0:b,className:H("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",s?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[V?n?e.jsx(j,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(j,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(oa,{filePath:t.path,extension:t.extension}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:t.path,children:t.name}),!V&&p&&e.jsx(si,{status:p}),V&&x&&e.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[x.modified>0&&e.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",x.modified]}),x.added>0&&e.jsxs("span",{className:"text-[var(--status-success)]",children:["+",x.added]})]})]}),D&&e.jsx("div",{className:H("absolute right-1 top-1/2 -translate-y-1/2",d?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:e.jsxs(hr,{open:z===t.path,onOpenChange:A=>m(A?t.path:null),children:[e.jsx(gr,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-6",onClick:y,children:e.jsx(j,{name:"more-2-fill",className:"size-4"})})}),e.jsx(xr,{align:"end",side:"bottom",onCloseAutoFocus:()=>m(null),children:F({Item:It,Separator:Hs})})]})})]}),e.jsx(wo,{className:"min-w-[180px]",children:F({Item:yo,Separator:ko})})]})},sr=(t,r,n)=>{const[s,i]=o.useState(""),[u,d]=o.useState(0);return o.useEffect(()=>{if(!t){i("");return}let p=!1;i("");const x=As(),N=Os(x);Ps(x).then(z=>{p||!z||(i(t),r(null))}).catch(z=>{p||(r(z instanceof Error?z.message:n),i(t))});const g=Ls(()=>{p||(i(t),d(z=>z+1),r(null))});return()=>{p=!0,N(),g()}},[t,r,n]),{readyKey:s,nonce:u}},ii=t=>t!==null&&typeof t=="object"&&"updateStatus"in t&&typeof t.updateStatus=="function",ci=t=>{const r=document.createElement("div");r.className="cm-vim-panel";const n=Wo(t);if(!n)return{top:!1,dom:r};n.state.statusbar=r;const s=n.state.vimPlugin;return ii(s)&&s.updateStatus(),{top:!1,dom:r,destroy(){n.state.statusbar===r&&(n.state.statusbar=null)}}};function Sn(t){return t?[Bo(),ao.of(ci),so()]:[]}const li={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},ui={case:"Match case",re:"Regular expression",word:"Match whole word"};function di(t){const r=t.querySelector(".cm-search");if(r){for(const[n,s]of Object.entries(li)){const i=r.querySelector(`button[name="${n}"]`);i&&!i.title&&(i.title=s)}for(const[n,s]of Object.entries(ui)){const u=r.querySelector(`input[name="${n}"]`)?.parentElement;u&&!u.title&&(u.title=s)}}}const or=new WeakMap;function fi(t,r){const n=$t(t.state);if(!n.valid)return or.delete(t),0;const s=or.get(t);if(!r&&s?.doc===t.state.doc&&s.query.eq(n))return s.total;const i=n.getCursor(t.state);let u=0;for(let d=i.next();!d.done;d=i.next())u+=1;return or.set(t,{query:n,doc:t.state.doc,total:u}),u}function mi(t){const r=$t(t.state);if(!r.valid)return 0;const n=t.state.selection.main,s=r.getCursor(t.state);let i=0,u=0;for(let d=s.next();!d.done;d=s.next()){const p=d.value;if(i+=1,u===0&&(u=i),n.from===p.from&&n.to===p.to||n.from<p.to&&n.to>p.from||p.from>=n.head)return i}return u}function Rn(t,r,n=!1){const s=t.querySelector(".cm-search");if(!s)return;let i=s.querySelector(".cm-search-message");if(!i){i=document.createElement("span"),i.className="cm-search-message",i.setAttribute("aria-live","polite");const p=s.querySelector('button[name="next"]'),x=p?.parentNode===s?p:s.firstChild;s.insertBefore(i,x)}const u=fi(r,n),d=u===0?0:mi(r);i.textContent=u===0?"":`${d}/${u}`}const Fn=new _e,En=new _e,zn=new _e,Mn=new _e,Tn=new _e,Dn=new _e,An=new _e,On=t=>t,ir=uo,pi=Vo,hi=$o;class gi extends io{constructor(r,n){super(),this.id=r,this.containerMap=n}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 Pn=(t,r)=>!t||t.length===0?[]:Zn.define({create(n){const s=new br,i=[...t].sort((u,d)=>u.afterLine-d.afterLine);for(const u of i){const d=n.doc.lines;if(u.afterLine>d)continue;const p=n.doc.line(u.afterLine);s.add(p.to,p.to,Bt.widget({widget:new gi(u.id,r),block:!0,side:1}))}return s.finish()},update(n,s){return n.map(s.changes)},provide:n=>ce.decorations.from(n)}),Ln=t=>{if(!t)return[];const r=Math.max(1,t.start),n=Math.max(r,t.end);return Qn.fromClass(class{decorations;constructor(s){this.decorations=this.build(s)}update(s){(s.docChanged||s.viewportChanged)&&(this.decorations=this.build(s.view))}build(s){const i=new br;for(let u=r;u<=n&&u<=s.state.doc.lines;u+=1){const d=s.state.doc.line(u);i.add(d.from,d.from,Bt.line({class:"oc-cm-selected-line"}))}return i.finish()}},{decorations:s=>s.decorations})};function xi({value:t,onChange:r,extensions:n,className:s,readOnly:i,lineNumbersConfig:u,highlightLines:d,onViewReady:p,onViewDestroy:x,blockWidgets:N,enableSearch:g,searchOpen:z,onSearchOpenChange:m,vimMode:R}){const C=o.useRef(null),w=o.useRef(null),B=o.useRef(t),E=o.useRef(r),l=o.useRef(p),V=o.useRef(x),$=o.useRef(m),I=o.useRef(N),_=o.useRef(R),K=o.useRef(new Map),[W,T]=o.useState([]),S=o.useCallback(b=>{const M=(b??[]).map(y=>{const F=K.current.get(y.id);return F?{id:y.id,content:y.content,container:F}:null}).filter(y=>y!==null);T(y=>y.length===M.length&&y.every((F,A)=>{const q=M[A];return F.id===q.id&&F.content===q.content&&F.container===q.container})?y:M)},[]),D=o.useCallback(b=>{const M=C.current,y=b??w.current;if(!M||!y)return;const F=y.dom.querySelector(".cm-gutters"),A=F instanceof HTMLElement?F.getBoundingClientRect().width:0;M.style.setProperty("--oc-editor-gutter-width",`${A}px`)},[]);return o.useEffect(()=>{B.current=t},[t]),o.useEffect(()=>{E.current=r},[r]),o.useEffect(()=>{l.current=p,V.current=x},[p,x]),o.useEffect(()=>{$.current=m},[m]),o.useEffect(()=>{I.current=N,S(N)},[N,S]),o.useEffect(()=>{if(!C.current)return;const b=(()=>{if(typeof document>"u")return null;const y=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(y)return y;const F=window.__PICHAMBER_CSP_NONCE__;return typeof F=="string"&&F.length>0?F:null})(),M=po.create({doc:B.current,extensions:[...b?[ce.cspNonce.of(b)]:[],oo({fixed:!0}),Fn.of(mn(u)),Oo(),lo.of(" "),An.of(Sn(R)),nr.of([Po,...Lo,...Io]),ce.updateListener.of(y=>{D(y.view),(y.viewportChanged||y.geometryChanged)&&S(I.current);const F=bn(y.startState),A=bn(y.state);F!==A&&$.current?.(A);const q=!$t(y.startState).eq($t(y.state));if(A&&(F!==A||q||y.docChanged||y.selectionSet)&&Rn(y.view.dom,y.view,F!==A||q||y.docChanged),!y.docChanged)return;const O=y.state.doc.toString();B.current=O,E.current(O),S(I.current)}),En.of(ce.editable.of(!i)),zn.of(n??[]),Mn.of(Ln(d)),Tn.of(Pn(N,K.current)),Dn.of(g?[vn({top:!0}),nr.of(On(wn))]:[])]});return w.current=new ce({state:M,parent:C.current}),ir(w.current,w.current.state.doc.length,200),w.current.requestMeasure(),requestAnimationFrame(()=>{D(w.current),S(I.current)}),w.current&&l.current?.(w.current),()=>{V.current?.(),w.current?.destroy(),w.current=null,T([])}},[I,D,S]),o.useEffect(()=>{const b=w.current;b&&(b.dispatch({effects:[Fn.reconfigure(mn(u)),En.reconfigure(ce.editable.of(!i)),zn.reconfigure(n??[]),Mn.reconfigure(Ln(d)),Tn.reconfigure(Pn(N,K.current)),Dn.reconfigure(g?[vn({top:!0}),nr.of(On(wn))]:[])]}),ir(b,b.state.doc.length,200),b.requestMeasure(),requestAnimationFrame(()=>{D(b),S(I.current)}))},[n,d,u,i,N,g,D,S]),o.useEffect(()=>{const b=w.current;if(!b){_.current=R;return}_.current!==R&&(_.current=R,b.dispatch({effects:An.reconfigure(Sn(R))}))},[R]),o.useEffect(()=>{const b=w.current;!b||g===!1||(z?(pi(b),requestAnimationFrame(()=>{di(b.dom),Rn(b.dom,b,!0)})):hi(b))},[z,g]),o.useEffect(()=>{const b=w.current;if(!b)return;const M=b.state.doc.toString();M!==t&&(b.dispatch({changes:{from:0,to:M.length,insert:t}}),ir(b,b.state.doc.length,300),b.requestMeasure(),requestAnimationFrame(()=>D(b)))},[t,D]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:C,className:H("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)]",s)}),W.map(b=>Ts.createPortal(b.content,b.container,b.id))]})}const In=({variant:t,selectedFile:r,loading:n,suppressLoadingIndicator:s,fileError:i,isSelectedImage:u,imageSrc:d,imagePreviewNonce:p,isSelectedPdf:x,pdfSrc:N,pdfPreviewNonce:g,isUnsupportedBinary:z,onDownload:m,enableRichPreviews:R,drawioViewMode:C,drawioRemountNonce:w,diagramEditorRef:B,diagramEditorXml:E,onDiagramChange:l,jsonViewMode:V,markdownViewMode:$,htmlViewMode:I,htmlLoading:_,htmlPreviewNonce:K,htmlPreviewSrc:W,fileContent:T,canUseShikiFileView:S,textViewMode:D,draftContent:b,onDraftChange:M,canEdit:y,vimMode:F,editorExtensions:A,editorWrapperRef:q,shouldMaskEditorForPendingNavigation:O,onEditorViewReady:J,onEditorViewDestroy:X,enableSearch:he=!1,searchOpen:ge,onSearchOpenChange:fe,pierreTheme:je,shikiThemeType:Ve,wrapLines:xe})=>{const ae=t==="fullscreen",se=ae?"p-4":"p-3",Ne=!!(r?.path&&pt(r.path)),Q=!!(r?.path&&ra(r.path)),L=!!(r?.path&&vr(r.path)),G=!!(r?.path&&Wt(r.path)),ne=()=>r?e.jsx("div",{className:"h-full",children:e.jsx(Ao,{file:{name:r.name,contents:b,lang:Gn(r.path)||void 0},options:{disableFileHeader:!0,overflow:xe?"wrap":"scroll",theme:je,themeType:Ve},className:"block h-full w-full",style:{height:"100%"}})}):null;return e.jsx(Kn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:r?n?s?e.jsx("div",{className:se}):e.jsxs("div",{className:`${se} flex items-center gap-2 typography-ui text-muted-foreground`,children:[e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}),ae?"Loading…":"Loading..."]}):i?e.jsx("div",{className:`${se} typography-ui text-[color:var(--status-error)]`,children:i}):u?e.jsx("div",{className:H("flex h-full items-center justify-center",se),children:e.jsx("img",{src:d,alt:r.name||"Image",className:H("max-w-full object-contain rounded-md border border-border/30 bg-primary/10",ae?"max-h-full":"max-h-[70vh]")},p)}):x?e.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:e.jsx("iframe",{src:N,className:"h-full w-full border-0",title:r.name},g)}):z?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx("div",{className:"typography-ui-header text-foreground",children:"Cannot preview binary file"}),e.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."}),m?e.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:m,children:[e.jsx(j,{name:"download",className:"mr-2 size-4"}),"Save file"]}):null]}):R&&Ne&&C==="preview"?e.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:e.jsx(xo,{ref:B,xml:E,onChange:l},`${r.path}:${w}`)}):R&&Q&&V==="tree"?e.jsx(ln,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"JSON viewer unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to text mode to view raw content."})]}),children:e.jsx("div",{className:"h-full overflow-auto",children:e.jsx(Do,{jsonString:T,maxHeight:"100%",initiallyExpandedDepth:2})})}):L&&$==="preview"?e.jsxs("div",{className:H("h-full overflow-auto",se),children:[T.length>500*1024?e.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(T.length/1024)}KB). Preview may be limited.`}):null,e.jsx(ln,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:e.jsx(Ks,{content:T,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):R&&G&&I==="preview"?_?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:"Loading..."}):e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx("iframe",{src:W,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:"HTML Preview"},K)}):S&&D==="view"?ne():e.jsxs("div",{className:H("relative h-full",O&&"overflow-hidden"),ref:q,children:[e.jsx("div",{className:H("h-full",O&&"invisible"),children:e.jsx(xi,{value:b,onChange:M,readOnly:!y,vimMode:F,extensions:A,className:"h-full",onViewReady:J,onViewDestroy:X,...he?{enableSearch:!0,searchOpen:ge,onSearchOpenChange:fe}:{}})}),O?e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}),"Opening file at change..."]})}):null]}):e.jsx("div",{className:`${se} typography-ui text-muted-foreground`,children:"Pick a file from the tree."})})};async function bi(t,r,n){if(Jn(t)&&!Yn(t))return{kind:r?"desktop-image":"asset-image"};if(Xn(t))return{kind:"pdf"};if(mr(t))return{kind:"binary",detectedFromContent:!1};const i=await n(t);if(Gs(i))return{kind:"binary",detectedFromContent:!0};const u=jo(i);return{kind:"text",content:u,draft:u.length>dt?`${u.slice(0,dt)}
|
|
2
2
|
|
|
3
3
|
… truncated …`:u,lineEnding:No(i)}}function vi({isDirty:t,saveDraft:r}){const n=we(m=>m.setMainTabGuard),[s,i]=k.useState(!1),u=k.useRef(null),d=k.useRef(!1),p=k.useCallback(m=>d.current?(d.current=!1,!1):t?(u.current=m,i(!0),!0):!1,[t]);k.useEffect(()=>{if(!t){n(null);return}const m=R=>!p({kind:"tab",tab:R});return n(m),()=>{we.getState().mainTabGuard===m&&n(null)}},[t,p,n]);const x=k.useCallback(()=>{const m=u.current;return u.current=null,d.current=!0,i(!1),m?.kind==="tab"&&n(null),m},[n]),N=k.useCallback(()=>x(),[x]),g=k.useCallback(async()=>await r()?x():(d.current=!1,null),[r,x]),z=k.useCallback(m=>{m||i(!0)},[]);return{confirmOpen:s,discardAndTakeIntent:N,keepModalOpen:z,requestNavigation:p,saveAndTakeIntent:g}}function wi(t,r){if(t.state.doc.length!==r.length)return!1;if(r.length===0)return!0;const n=Math.min(128,r.length);if(t.state.sliceDoc(0,n)!==r.slice(0,n))return!1;const s=Math.max(0,r.length-n);return t.state.sliceDoc(s,r.length)===r.slice(s)}function yi({root:t,selectedPath:r,loadedPath:n,fileLoading:s,fileError:i,isImage:u,isPdf:d,isUnsupportedBinary:p,canEdit:x,textViewMode:N,setTextViewMode:g,draftContent:z,confirmDiscardOpen:m,selectFilePath:R}){const C=we(S=>S.pendingFileNavigation),w=we(S=>S.setPendingFileNavigation),B=we(S=>S.pendingFileFocusPath),E=we(S=>S.setPendingFileFocusPath),l=k.useRef(null),[V,$]=k.useState(0),I=k.useRef(null),_=k.useRef({key:"",attempts:0}),K=k.useCallback(()=>{$(S=>S+1)},[]);k.useEffect(()=>()=>{I.current!==null&&window.cancelAnimationFrame(I.current)},[]),k.useEffect(()=>{if(!C||!t)return;const S=()=>{I.current===null&&(I.current=window.requestAnimationFrame(()=>{I.current=null,K()}))},D=()=>{w(null),_.current={key:"",attempts:0}},b=de(C.path);if(!b){D();return}const M=`${b}:${C.line}:${C.column??1}`;if(_.current.key!==M&&(_.current={key:M,attempts:0}),r!==b){m||R(b);return}if(s||n!==b)return;if(i||u||d||p){D();return}if(!x)return;if(N!=="edit"){g("edit");return}const y=l.current;if(!y||!wi(y,z)){S();return}const F=Math.max(1,Math.min(C.line,y.state.doc.lines)),A=y.state.doc.line(F),q=Math.max(1,C.column||1),O=A.from+Math.min(Math.max(0,A.to-A.from),q-1);if(!(y.state.selection.main.head===O)||_.current.attempts===0){_.current.attempts+=1,y.dispatch({selection:{anchor:O},effects:ce.scrollIntoView(O,{y:"center"})}),y.focus(),S();return}window.requestAnimationFrame(()=>{const X=l.current;X&&(X.dispatch({selection:{anchor:O},effects:ce.scrollIntoView(O,{y:"center"})}),X.focus())}),D()},[x,m,z,V,i,s,u,d,p,n,K,C,t,r,R,w,g,N]),k.useEffect(()=>{if(!B||!t)return;const S=de(B);if(!S){E(null);return}r!==S||s||n!==S||(!i&&!u&&!d&&!p&&x&&N==="edit"&&l.current?.focus(),E(null))},[x,i,s,u,d,p,n,B,t,r,E,N]);const W=de(C?.path??"");return{editorViewRef:l,notifyEditorViewChanged:K,shouldMaskEditor:!!(C&&W&&r===W&&!s&&!i&&!u&&!d&&!p)}}function ki(t){return!(!t.autoSaveEnabled||!t.isDirty||!t.canWrite||t.isSaving||t.fileLoading||t.isNonEditableBinary||!t.selectedFilePath||t.loadedFilePath!==t.selectedFilePath)}function ji(t){return t.selectedFilePath?t.isDirty?!(t.fileLoading||t.loadedFilePath!==t.selectedFilePath||t.isNonEditableBinary||t.draftContent===""&&t.fileContent!==""&&t.loadedFilePath!==t.selectedFilePath):!0:!1}const Ni=1500,Ci=2e3;function Si({autoSaveEnabled:t,selectedPath:r,loadedPath:n,fileLoading:s,isDirty:i,draftContent:u,fileContent:d,lineEnding:p,isNonEditableBinary:x,writeFile:N,onSaved:g}){const[z,m]=k.useState(!1),[R,C]=k.useState("idle"),w=k.useRef(null),B=k.useRef(null),E=k.useCallback(()=>{w.current&&(clearTimeout(w.current),w.current=null)},[]),l=k.useCallback(()=>{C("saved"),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{B.current=null,C("idle")},Ci)},[]),V=k.useCallback(async()=>{if(!r||!N)return ie.error("Saving not supported"),!1;if(!ji({selectedFilePath:r,loadedFilePath:n,fileLoading:s,isDirty:i,draftContent:u,fileContent:d,isNonEditableBinary:x}))return x?console.warn(`[saveDraft] refusing to save binary file "${r}".`):u===""&&d!==""&&n!==r&&console.warn(`[saveDraft] refusing to save empty draft for "${r}" (${d.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(!i)return!0;m(!0);try{const I=Co(u,p);return(await N(r,I))?.success?(g(r,u),!0):(ie.error("Failed to write file"),!1)}catch(I){return ie.error(I instanceof Error?I.message:"Save failed"),!1}finally{m(!1)}},[u,d,s,i,x,p,n,g,r,N]),$=k.useCallback(async()=>{if(E(),z)return!1;const I=await V();return I&&l(),I},[E,z,V,l]);return k.useEffect(()=>{t||(C("idle"),E())},[t,E]),k.useEffect(()=>{if(ki({autoSaveEnabled:t,isDirty:i,canWrite:!!(r&&N),isSaving:z,fileLoading:s,selectedFilePath:r,loadedFilePath:n,isNonEditableBinary:x}))return w.current=setTimeout(()=>{w.current=null,V().then(I=>{I&&l()})},Ni),E},[t,E,u,s,i,x,z,n,V,r,l,N]),k.useEffect(()=>{C("idle"),m(!1)},[r]),k.useEffect(()=>()=>{E(),B.current&&clearTimeout(B.current)},[E]),{autoSaveStatus:R,cancelPendingAutosave:E,isSaving:z,saveDraft:V,saveNow:$}}function Ri(t,r){return r.mtimeMs!==void 0&&t.mtimeMs!==void 0&&r.mtimeMs!==t.mtimeMs||r.size!==t.size}function Fi({selectedPath:t,loadedPath:r,isDirty:n,readStat:s,onExternalChange:i,pollIntervalMs:u=2e3}){const d=k.useRef(null),p=k.useRef(n);p.current=n;const x=k.useCallback(N=>{d.current=N},[]);return k.useEffect(()=>{if(!t||r!==t)return;let N=!1;const g=window.setInterval(()=>{document.hidden||s(t).then(z=>{if(N||!z)return;const m=d.current;if(!m||m.path!==t){d.current=z;return}!Ri(m,z)||p.current||(d.current=z,i())}).catch(()=>{})},u);return()=>{N=!0,window.clearInterval(g)}},[r,i,u,s,t]),{recordStat:x}}const cr="pichamber:files:md-viewer-mode",lr="pichamber:files:html-viewer-mode",ur="pichamber:files:json-viewer-mode",Ei=1500,zi=1500;function dr(t,r,n){try{const s=localStorage.getItem(t);if(s&&r.includes(s))return s}catch{}return n}function Ze(t,r){try{localStorage.setItem(t,r)}catch{}}function Mi({root:t,openPaths:r,selectedPath:n,defaultPreview:s,fileContent:i,draftContent:u,setDraftContent:d,autoSaveEnabled:p,writeFile:x,readStat:N,recordStat:g}){const[z,m]=k.useState("edit"),[R,C]=k.useState("edit"),[w,B]=k.useState("tree"),[E,l]=k.useState("edit"),[V,$]=k.useState("preview"),[I,_]=k.useState(0),[K,W]=k.useState(!1),T=k.useRef({}),S=k.useRef({}),D=k.useRef({}),b=k.useRef({}),M=k.useRef(""),y=k.useRef(""),F=k.useRef(null),A=k.useRef(null),q=k.useRef(null),O=k.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null),q.current!==null&&(cancelAnimationFrame(q.current),q.current=null)},[]),J=k.useCallback(L=>{M.current=L,y.current=L},[]),X=k.useCallback(()=>J(""),[J]);k.useEffect(()=>{if(!n)return;const L=s?"preview":"edit";m(T.current[n]??"edit"),C(S.current[n]??dr(cr,["preview","edit"],L)),l(D.current[n]??dr(lr,["preview","edit"],L)),$(b.current[n]??L),B(dr(ur,["tree","text"],s?"tree":"text"))},[s,n]);const he=k.useCallback(L=>{n&&(T.current[n]=L),m(L)},[n]),ge=k.useCallback(L=>{n&&(S.current[n]=L),C(L),Ze(cr,L)},[n]),fe=k.useCallback(L=>{n&&(D.current[n]=L),l(L),Ze(lr,L)},[n]),je=k.useCallback(L=>{B(L),Ze(ur,L)},[]),Ve=k.useCallback(L=>{if(n&&(b.current[n]=L),O(),L==="edit"){d(M.current||i),$(L);return}M.current=u;const G=n;$("edit"),q.current=requestAnimationFrame(()=>{q.current=requestAnimationFrame(()=>{q.current=null,!(t&&G&&ke.getState().byRoot[t]?.selectedPath!==G)&&(_(ne=>ne+1),$("preview"))})})},[O,u,i,t,n,d]),xe=k.useCallback(async(L,G)=>{if(!x||G===y.current)return!1;if(!(await x(L,G))?.success)return ie.error("Failed to write file"),!1;J(G),d(G);const Y=await N(L).catch(()=>null);return Y&&g(Y),!0},[N,J,g,d,x]),ae=k.useCallback(()=>{W(!0),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>W(!1),zi)},[]),se=k.useCallback(async(L,G)=>{F.current&&(clearTimeout(F.current),F.current=null);const ne=await xe(L,G);return ne&&ae(),ne},[xe,ae]),Ne=k.useCallback(L=>{M.current=L,!(!p||!n||V!=="preview"||!x)&&(F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{F.current=null,xe(n,L).then(G=>{G&&ae()}).catch(G=>{ie.error(G instanceof Error?G.message:"Save failed")})},Ei))},[p,V,xe,n,ae,x]);k.useEffect(()=>O,[O,V,n]),k.useEffect(()=>()=>{A.current&&clearTimeout(A.current)},[]),k.useEffect(()=>{const L=ne=>{const Y=ne?"preview":"edit",qe=ne?"tree":"text";for(const ee of r)T.current[ee]="edit",vr(ee)&&(S.current[ee]=Y),Wt(ee)&&(D.current[ee]=Y),pt(ee)&&(b.current[ee]=Y);m("edit"),C(Y),l(Y),$(Y),B(qe),Ze(cr,Y),Ze(lr,Y),Ze(ur,qe)},G=ne=>{L(!!ne.detail?.enabled)};return window.addEventListener("pichamber:file-viewer-preview-mode-changed",G),()=>window.removeEventListener("pichamber:file-viewer-preview-mode-changed",G)},[r]);const Q=pt(n??"")&&(M.current||u)||i;return{clearDiagramContent:X,diagramEditorXml:Q,diagramSaved:K,drawioRemountNonce:I,drawioViewMode:V,handleDiagramChange:Ne,htmlViewMode:E,jsonViewMode:w,mdViewMode:R,recordDiagramContent:J,saveDiagramNow:se,saveDiagramXml:xe,saveDrawioViewMode:Ve,saveHtmlViewMode:fe,saveJsonViewMode:je,saveMdViewMode:ge,saveTextViewMode:he,setTextViewMode:m,textViewMode:z}}function Ti({files:t,root:r,activeDirectory:n,expandedPaths:s,chrome:i,showHidden:u,showGitignored:d,removeExpandedPathsByPrefix:p}){const[x,N]=o.useState({}),[g,z]=o.useState({}),m=o.useRef(new Set),R=o.useRef(new Set),C=o.useRef(new Map),w=o.useRef(0),B=o.useCallback((W,T)=>{const S=[];for(const D of T){if(!D?.name||i==="desktop"&&!u&&D.name.startsWith(".")||i==="desktop"&&!d&&So(D.name))continue;const b=de(D.path||""),M=b?Ro(b)?b:de(`${W}/${b}`):de(`${W}/${D.name}`),y=D.isDirectory?"directory":"file";S.push({name:D.name,path:M,type:y,extension:y==="file"&&D.name.includes(".")?D.name.split(".").pop()?.toLowerCase():void 0,size:D.size})}return Fo(S)},[i,d,u]),E=o.useCallback(async W=>{const T=de(W.trim());if(!T||m.current.has(T)||R.current.has(T))return;R.current=new Set(R.current).add(T);const S=w.current+1;w.current=S,C.current=new Map(C.current).set(T,S);const D=()=>C.current.get(T)===S;try{const b=t.listDirectory?(await t.listDirectory(T)).entries.map(M=>({name:M.name,path:M.path,isDirectory:M.isDirectory,size:M.size})):(await Is(T)).map(M=>({name:M.name,path:M.path,isDirectory:M.isDirectory}));if(!D())return;m.current=new Set(m.current).add(T),z(M=>{if(!M[T])return M;const y={...M};return delete y[T],y}),N(M=>({...M,[T]:B(T,b)}))}catch(b){if(!D())return;const M=b instanceof Error?b.message:String(b??"");M==="Directory not found"&&r&&T!==r?(p(r,T),z(y=>{if(!y[T])return y;const F={...y};return delete F[T],F})):(console.error("Failed to load files directory:",b),z(y=>({...y,[T]:M})))}finally{D()&&(C.current=new Map(C.current),C.current.delete(T),R.current=new Set(R.current),R.current.delete(T))}},[t,B,p,r]),l=o.useCallback(()=>{m.current=new Set,R.current=new Set,C.current=new Map,z({}),N(W=>Object.keys(W).length===0?W:{})},[]),V=o.useCallback(async()=>{r&&(l(),await E(r))},[E,l,r]),$=o.useCallback(async W=>{if(!W){await V();return}const T=de(W);m.current=new Set(m.current),m.current.delete(T),R.current=new Set(R.current),R.current.delete(T),await E(T)},[E,V]),I=`${r}|h${u?"1":"0"}|g${d?"1":"0"}|${i}`,_=o.useRef("");o.useEffect(()=>{!r||_.current===I||(_.current=I,l(),E(r))},[E,l,r,I]),o.useEffect(()=>{n&&E(n)},[n,E]),o.useEffect(()=>{if(!t.listDirectory)return;const W=()=>{if(!document.hidden)for(const D of s)$(D)},T=()=>W();document.addEventListener("visibilitychange",T);const S=s.length>0?window.setInterval(W,8e3):null;return()=>{document.removeEventListener("visibilitychange",T),S!==null&&window.clearInterval(S)}},[s,t.listDirectory,$]);const K=o.useCallback(W=>m.current.has(de(W)),[]);return{childrenByDir:x,loadErrorsByDir:g,isLoaded:K,loadDirectory:E,refreshDirectory:$,refreshRoot:V}}const Di=({showEditorTabsRow:t,isMobile:r,showMobilePageContent:n,onBackMobile:s,selectedFile:i,openFiles:u,root:d,alwaysShowActions:p,editorTabsOverflow:x,editorTabsScrollRef:N,onSelectFile:g,onCloseFile:z})=>t?e.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[r&&n&&e.jsx("button",{type:"button",onClick:s,"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:e.jsx(j,{name:"arrow-left-s",className:"size-5"})}),r?i?e.jsxs(hr,{children:[e.jsx(gr,{asChild:!0,children:e.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:[e.jsx(ut,{filePath:i.path,extension:i.extension,className:"size-3.5 flex-shrink-0"}),e.jsx(Cn,{name:i.name}),e.jsx(j,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),e.jsx(xr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:u.map(m=>{const R=i?.path===m.path;return e.jsxs(It,{onSelect:C=>{if(C.target.closest("[data-close-open-file]")){C.preventDefault();return}R||g(m)},className:H("flex min-w-0 items-center justify-between gap-2 overflow-hidden",R&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[e.jsx(ut,{filePath:m.path,extension:m.extension,className:"size-3.5 flex-shrink-0"}),e.jsx(Cn,{name:m.name})]}),e.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:C=>{C.preventDefault(),C.stopPropagation()},onClick:C=>{C.preventDefault(),C.stopPropagation(),z(m.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 ${m.name}`,children:e.jsx(j,{name:"close",className:"size-3.5"})})]},m.path)})})]}):e.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"}):u.length>0?e.jsxs("div",{className:"relative min-w-0 flex-1",children:[x.left&&e.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"}),x.right&&e.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"}),e.jsx("div",{ref:N,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(m=>{const R=i?.path===m.path;return e.jsxs("div",{title:Vt(d,m.path),className:H("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",R?"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:[e.jsx(ut,{filePath:m.path,extension:m.extension,className:"size-3.5 flex-shrink-0"}),e.jsx("button",{type:"button",onClick:()=>{R||g(m)},className:"max-w-[12rem] truncate text-left",children:m.name}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),z(m.path)},className:H("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!R&&!p&&"opacity-0 group-hover:opacity-100"),"aria-label":`Close ${m.name}`,children:e.jsx(j,{name:"close",className:"size-3.5"})})]},m.path)})})]}):e.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"})]}):null,Ai=(t,r)=>{if(!r)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,r.state.doc.lines)},Vn=(t,r)=>{const n=t.state.doc.lineAt(r.main.head);return{lineNumber:n.number,character:r.main.head-n.from+1,selection:r}},$n=(t,r,n)=>{const s=t.state.doc.line(r),i=Math.max(1,Math.min(n,s.length+1)),u=s.from+i-1;t.dispatch({selection:ho.cursor(u),effects:ce.scrollIntoView(u,{y:"center"})})};function Oi({open:t,onOpenChange:r,view:n,variant:s="overlay"}){const[i,u]=o.useState(""),d=o.useRef(null),p=o.useRef(!1),x=o.useRef(null),N=o.useRef(null),g=o.useMemo(()=>Ai(i,n),[i,n]);o.useEffect(()=>{!t||!n||(p.current=!1,d.current=Vn(n,n.state.selection),u(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{N.current?.focus(),N.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!d.current)){if(g===null){const{selection:w}=d.current;n.dispatch({selection:w,effects:ce.scrollIntoView(w.main.from,{y:"center"})});return}$n(n,g,d.current.character)}},[g,t,n]);const z=o.useCallback(()=>{if(!n||p.current||!d.current)return;const{selection:w}=d.current;n.dispatch({selection:w,effects:ce.scrollIntoView(w.main.from,{y:"center"})})},[n]),m=o.useCallback(w=>{w||z(),r(w)},[r,z]),R=o.useCallback(()=>{!n||g===null||!d.current||(p.current=!0,$n(n,g,d.current.character),r(!1),n.focus())},[g,r,n]);o.useEffect(()=>{if(!t)return;const w=E=>{const l=x.current,V=E.target;!l||!(V instanceof Node)||l.contains(V)||m(!1)},B=E=>{E.key==="Escape"&&(E.preventDefault(),m(!1))};return document.addEventListener("pointerdown",w,!0),document.addEventListener("keydown",B,!0),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("keydown",B,!0)}},[m,t,s]);const C=o.useMemo(()=>n?g===null?`Current Line: ${(d.current??Vn(n,n.state.selection)).lineNumber}. Type a line number between 1 and ${n.state.doc.lines} to navigate to.`:`Go to line ${g}`:"Editor unavailable.",[g,n]);return s==="inline"?t?e.jsxs("div",{ref:x,className:"ml-1 flex h-6 items-center gap-1",children:[e.jsx(mt,{ref:N,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>u(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),R())},placeholder:"Line",className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),e.jsx(U,{variant:"outline",size:"xs",onClick:R,disabled:!n||g===null,className:"h-6 px-2",children:"Go"})]}):null:e.jsx("div",{ref:x,className:H("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",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx(mt,{ref:N,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:w=>u(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),R())},placeholder:"Line number",className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),e.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:t,onToggle:r})=>{const n=t==="preview",s=n?"Switch to edit mode":"Switch to preview mode",i=n?"Edit":"Preview";return e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"sm",onClick:r,"aria-label":s,className:"h-5 w-5 p-0",children:n?e.jsx(j,{name:"eye",className:"size-4","aria-hidden":"true"}):e.jsx(j,{name:"eye-off",className:"size-4","aria-hidden":"true"})})}),e.jsx(Ie,{sideOffset:8,children:i})]})},Pi=({selectedFile:t,displaySelectedPath:r,layout:n="floating",exitFullscreenOnly:s=!1,canEdit:i,isEditingFile:u,isSaving:d,autoSaveEnabled:p,autoSaveStatus:x,isDirty:N,onSaveDraft:g,onToggleAutoSave:z,openInApps:m,openInCacheStale:R,onOpenInApp:C,onRefreshOpenInApps:w,onToolbarDropdownOpenChange:B,isSelectedImage:E,isSelectedPdf:l,isUnsupportedBinary:V,wrapLines:$,onToggleWrapLines:I,textViewMode:_,onToggleSearch:K,isGoToLineOpen:W,onOpenGoToLineChange:T,editorView:S,canUseShikiFileView:D,isJson:b,isHtml:M,onToggleTextViewMode:y,isMarkdown:F,mdViewMode:A,onToggleMdViewMode:q,isDrawio:O,drawioViewMode:J,onToggleDrawioViewMode:X,diagramSaved:he,onSaveDiagram:ge,jsonViewMode:fe,onToggleJsonViewMode:je,canCopy:Ve,copiedContent:xe,onCopyContent:ae,canCopyPath:se,copiedPath:Ne,onCopyPath:Q,onDownloadFile:L,isMobile:G,mode:ne,isFullscreen:Y,onToggleFullscreen:qe,onExitFullscreen:ee})=>{if(!t)return null;const Ue=n==="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",oe=(le,Me)=>e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:Me})}),e.jsx(Ie,{side:"bottom",sideOffset:6,children:le})]});return e.jsxs("div",{className:Ue,children:[i&&u&&e.jsxs(e.Fragment,{children:[d?e.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[e.jsx(j,{name:"loader-4",className:"size-3.5 animate-spin"}),"Saving..."]}):p&&x==="saved"&&!N?e.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[e.jsx(j,{name:"check",className:"size-3.5"}),"Saved"]}):N?oe(p?`Save now (${lt()}+S) - auto-saves after 1.5s`:`Save now (${lt()}+S)`,e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{g()},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:p?`Save now (${lt()}+S) - auto-saves after 1.5s`:`Save now (${lt()}+S)`,"aria-label":`Save (${lt()}+S)`,children:e.jsx(j,{name:"save-3",className:"size-4"})})):null,oe(p?"Auto-save on":"Manual save",e.jsx(U,{variant:"ghost",size:"sm",onClick:z,className:H("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",p?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:p?"Auto-save on":"Manual save","aria-label":p?"Auto-save on":"Manual save",children:p?e.jsx(j,{name:"file-check-fill",className:"size-4"}):e.jsx(j,{name:"file-check",className:"size-4"})}))]}),e.jsxs(hr,{onOpenChange:B,children:[e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:e.jsx(gr,{asChild:!0,children:e.jsx(U,{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:e.jsx(j,{name:"file-transfer",className:"size-4"})})})})}),e.jsx(Ie,{side:"bottom",sideOffset:6,children:"Open in desktop app"})]}),e.jsxs(xr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[m.map(le=>e.jsxs(It,{className:"flex items-center gap-2",onClick:()=>{C(le)},children:[e.jsx(ai,{label:le.label,iconDataUrl:le.iconDataUrl}),e.jsx("span",{className:"typography-ui-label text-foreground",children:le.label})]},le.id)),R?e.jsxs(It,{className:"flex items-center gap-2",onClick:()=>{w()},children:[e.jsx(j,{name:"refresh",className:"size-4"}),e.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]}),!E&&!l&&!V&&e.jsxs(e.Fragment,{children:[oe($?"Disable line wrap":"Enable line wrap",e.jsx(U,{variant:"ghost",size:"sm",onClick:I,className:H("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",$?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:$?"Disable line wrap":"Enable line wrap",children:e.jsx(j,{name:"text-wrap",className:"size-4"})})),_==="edit"&&e.jsxs(e.Fragment,{children:[oe("Find in file",e.jsx(U,{variant:"ghost",size:"sm",onClick:le=>{K(),le.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:e.jsx(j,{name:"search",className:"size-4"})})),oe("Go to line",e.jsx(U,{variant:"ghost",size:"sm",onClick:le=>{T(!W),le.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:e.jsx(j,{name:"menu-fold-2",className:"size-4"})})),e.jsx(Oi,{open:W,onOpenChange:T,view:S,variant:"inline"})]})]}),D&&i&&!b&&!M&&e.jsx(fr,{currentMode:_==="view"?"preview":"edit",onToggle:y}),F&&oe(A==="preview"?"Switch to edit mode":"Switch to preview mode",e.jsx(U,{variant:"ghost",size:"sm",onClick:q,className:H("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",A==="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:A==="preview"?"Switch to edit mode":"Switch to preview mode","aria-label":A==="preview"?"Switch to edit mode":"Switch to preview mode",children:e.jsx(j,{name:A==="preview"?"eye":"eye-off",className:"size-4"})})),Wt(t?.path??"")&&e.jsx(fr,{currentMode:M?"preview":"edit",onToggle:y}),O&&e.jsxs(e.Fragment,{children:[e.jsx(fr,{currentMode:J,onToggle:X}),J==="preview"&&e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{ge()},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save diagram",children:he?e.jsx(j,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(j,{name:"save-3",className:"size-4"})})]}),b&&oe(fe==="tree"?"Switch to Text View":"Switch to Tree View",e.jsx(U,{variant:"ghost",size:"sm",onClick:je,className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:fe==="tree"?"Switch to Text View":"Switch to Tree View",children:fe==="tree"?e.jsx(j,{name:"code-sslash",className:"size-4"}):e.jsx(j,{name:"node-tree",className:"size-4"})})),Ve&&oe("Copy file contents",e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{ae()},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:xe?e.jsx(j,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(j,{name:"clipboard",className:"size-4"})})),se&&oe(`Copy file path (${r})`,e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{Q()},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:Ne?e.jsx(j,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(j,{name:"file-copy-2",className:"size-4"})})),L&&oe("Save file",e.jsx(U,{variant:"ghost",size:"sm",onClick:L,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save file","aria-label":"Save file",children:e.jsx(j,{name:"download",className:"size-4"})})),s?oe("Exit fullscreen",e.jsx(U,{variant:"ghost",size:"sm",onClick:ee,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Exit fullscreen","aria-label":"Exit fullscreen",children:e.jsx(j,{name:"fullscreen-exit",className:"size-4"})})):!G&&ne==="full"&&oe(Y?"Exit fullscreen":"Fullscreen",e.jsx(U,{variant:"ghost",size:"sm",onClick:qe,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:Y?"Exit fullscreen":"Fullscreen","aria-label":Y?"Exit fullscreen":"Fullscreen",children:Y?e.jsx(j,{name:"fullscreen-exit",className:"size-4"}):e.jsx(j,{name:"fullscreen",className:"size-4"})}))]})},Li=({open:t,onOpenChange:r,isSaving:n,onSaveAndContinue:s,onDiscardAndContinue:i})=>e.jsx(Bn,{open:t,onOpenChange:r,children:e.jsxs(Wn,{showCloseButton:!1,className:"max-w-md",children:[e.jsxs(_n,{children:[e.jsx(qn,{children:"Unsaved changes"}),e.jsx(Un,{children:"Save your edits before continuing?"})]}),e.jsxs(Hn,{children:[e.jsx(U,{variant:"outline",onClick:s,disabled:n,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"}),e.jsx(U,{variant:"destructive",onClick:i,children:"Discard"})]})]})}),Ii=({root:t,isMobile:r,searchQuery:n,onSearchQueryChange:s,searchInputRef:i,searching:u,searchResults:d,selectedFile:p,onSelectFile:x,onOpenDialog:N,currentDirectory:g,refreshRoot:z,childrenByDir:m,loadErrorsByDir:R,expandedPaths:C,isBrowserClient:w,alwaysShowActions:B,getFileStatus:E,getFolderBadge:l,fileRowPermissions:V,downloadFile:$,contextMenuPath:I,setContextMenuPath:_,rightClickMenuPath:K,setRightClickMenuPath:W,toggleDirectory:T,handleRevealPath:S,refreshDirectory:D})=>{const b=!!(t&&m[t]),M=t?R[t]:null;function y(F,A){const q=m[F]??[];return q.map((O,J)=>{const X=O.type==="directory",he=X&&C.includes(O.path),ge=p?.path===O.path,fe=J===q.length-1;return e.jsxs("li",{className:"relative",children:[A>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),fe&&e.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),e.jsx(oi,{node:O,root:t,isExpanded:he,isActive:ge,isMobile:r,isBrowserClient:w,alwaysShowActions:B,status:X?void 0:E(O.path),badge:X?l(O.path):void 0,permissions:V,downloadFile:$,contextMenuPath:I,setContextMenuPath:_,rightClickMenuPath:K,setRightClickMenuPath:W,onSelect:x,onToggle:T,onRevealPath:S,onOpenDialog:N}),X&&he&&e.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[R[O.path]?e.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:R[O.path],children:R[O.path]}),e.jsxs(U,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{D(O.path)},children:[e.jsx(j,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):null,y(O.path,A+1)]})]},O.path)})}return e.jsxs("section",{className:H("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:[e.jsx("div",{className:H("flex flex-col gap-2 py-2",r?"px-3":"px-2"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(j,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),e.jsx(mt,{ref:i,value:n,onChange:F=>s(F.target.value),placeholder:"Search files...",className:"h-8 pl-8 pr-8 typography-meta"}),n.trim().length>0&&e.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:()=>{s(""),i.current?.focus()},children:e.jsx(j,{name:"close",className:"size-4"})})]}),e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>N("createFile",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New File","aria-label":"New File",children:e.jsx(j,{name:"file-add",className:"size-4"})})})}),e.jsx(Ie,{side:"bottom",sideOffset:6,children:"New File"})]}),e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>N("createFolder",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New Folder","aria-label":"New Folder",children:e.jsx(j,{name:"folder-add",className:"size-4"})})})}),e.jsx(Ie,{side:"bottom",sideOffset:6,children:"New Folder"})]}),e.jsxs(Pe,{children:[e.jsx(Le,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{z()},className:"size-8 p-0 flex-shrink-0",title:"Refresh","aria-label":"Refresh",children:e.jsx(j,{name:"refresh",className:"size-4"})})})}),e.jsx(Ie,{side:"bottom",sideOffset:6,children:"Refresh"})]})]})}),e.jsx(Kn,{outerClassName:"flex-1 min-h-0",className:H("py-2",r?"px-3":"px-2"),children:e.jsx("ul",{className:"flex flex-col",children:u?e.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx(j,{name:"loader-4",className:"size-4 animate-spin"}),"Searching..."]}):d.length>0?d.map(F=>{const A=p?.path===F.path;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{x(F)},className:H("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:[e.jsx(oa,{filePath:F.path,extension:F.extension}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:F.path,children:F.relativePath??F.path})]})},F.path)}):M?e.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{className:"text-[var(--status-error)]",children:M}),e.jsxs(U,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{z()},children:[e.jsx(j,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):b?y(t,0):e.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:"Loading..."})})})]})},Yl=({mode:t="full",chrome:r="desktop",onClose:n})=>{const{files:s,runtime:i}=Js(),u=r==="mobile",{currentTheme:d,availableThemes:p,lightThemeId:x,darkThemeId:N}=Ys(),{isMobile:g,isTablet:z,screenWidth:m}=Xs(),R=Vs(i.platform),C=g||z,w=$s(),B=Bs(),E=Qs()??"",l=de(E.trim()),V=t!=="editor-only",$=t==="editor-only"&&!g,I=Zs(E),[_,K]=o.useState(""),W=o.useRef(null),[T,S]=o.useState(!1),[D,b]=o.useState(l),[M,y]=o.useState(!1),[F,A]=o.useState(!0),[q,O]=o.useState(!1),[J,X]=o.useState(!1),[he,ge]=o.useState(!1),fe=o.useRef(null);o.useEffect(()=>{u&&(b(l),K(""),S(!1))},[u,l]);const je=o.useRef(0),Ve=o.useCallback(a=>{je.current=Math.max(0,je.current+(a?1:-1))},[]),xe=o.useCallback(a=>a instanceof Element?a.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!he)return;const a=f=>{je.current>0||xe(f.target)||fe.current&&!fe.current.contains(f.target)&&ge(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[xe,he]);const ae=o.useMemo(()=>p.find(a=>a.metadata.id===x)??sn(!1),[p,x]),se=o.useMemo(()=>p.find(a=>a.metadata.id===N)??sn(!0),[p,N]);o.useEffect(()=>{hn(ae),hn(se)},[ae,se]);const Ne=o.useMemo(()=>[],[]),Q=ke(a=>l?a.byRoot[l]?.openPaths??Ne:Ne),L=ke(a=>l?a.byRoot[l]?.selectedPath??null:null),G=ke(a=>l?a.byRoot[l]?.expandedPaths??Ne:Ne),ne=ke(a=>a.removeOpenPath),Y=ke(a=>a.removeOpenPathsByPrefix),qe=ke(a=>a.removeExpandedPathsByPrefix),ee=ke(a=>a.setSelectedPath),_t=ke(a=>a.toggleExpandedPath),Ue=ke(a=>a.expandPaths),{childrenByDir:oe,loadErrorsByDir:le,isLoaded:Me,loadDirectory:He,refreshDirectory:ht,refreshRoot:ia}=Ti({files:s,root:l,activeDirectory:u?D:void 0,expandedPaths:G,chrome:r,showHidden:w,showGitignored:B,removeExpandedPathsByPrefix:qe}),Te=o.useCallback(a=>{const f=de(a),v=f.split("/"),P=v[v.length-1]||f,te=P.includes(".")?P.split(".").pop()?.toLowerCase():void 0;return{name:P,path:f,type:"file",extension:te}},[]),gt=o.useMemo(()=>Q.map(Te),[Q,Te]),qt=o.useMemo(()=>{if(L){const a=Pt(L);if(Q.some(f=>Pt(f)===a))return L}return Q[0]??null},[Q,L]),h=o.useMemo(()=>qt?Te(qt):null,[qt,Te]),Re=h?.path??"";o.useEffect(()=>{if(!l||!L)return;const a=Pt(L);Q.some(v=>Pt(v)===a)||ee(l,Q[0]??null)},[Q,l,L,ee]);const xt=!!(l&&Re&&!ar(Re,l)),wr=xt?un(Re):void 0,ue=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&xt,outsideFileGrant:wr,directory:l||void 0}),[t,xt,wr,l]),Ut=o.useRef(null),[ca,la]=o.useState({left:!1,right:!1}),yr=o.useCallback(()=>{const a=Ut.current;a&&la({left:a.scrollLeft>2,right:a.scrollLeft+a.clientWidth<a.scrollWidth-2})},[]),kr=o.useRef(yr);kr.current=yr,o.useEffect(()=>{const a=Ut.current;if(!a)return;const f=()=>kr.current();f(),a.addEventListener("scroll",f,{passive:!0});const v=new ResizeObserver(f);return v.observe(a),()=>{a.removeEventListener("scroll",f),v.disconnect()}},[gt.length]);const[be,Fe]=o.useState(""),[Ht,tt]=o.useState(!1),[jr,ve]=o.useState(null),[ua,$e]=o.useState(""),me=o.useRef(""),[rt,Ce]=o.useState(null),[nt,Se]=o.useState(""),[da,fa]=o.useState(`
|
|
4
4
|
`),Nr=o.useRef(null),bt=o.useRef(0),at=o.useRef(null),[Cr,Sr]=o.useState(!1),vt=we(a=>a.autoSaveEnabled),ma=we(a=>a.setAutoSaveEnabled),pa=o.useRef(null),[ha,ga]=o.useState(null),[xa,ba]=o.useState(null),{value:va,show:wa}=dn(!1,1200),{value:ya,show:ka}=dn(!1,1200),[ja,Na]=o.useState(!1),Kt=o.useCallback(()=>{l&&ee(l,null),Fe(""),ve(null),$e(""),Ce(null),g&&S(!1)},[g,l,ee]),{operation:Ca,target:Sa,inputValue:Ra,setInputValue:Fa,submitting:Ea,inputRef:za,open:Ma,close:Ta,submit:Da,capabilities:{canCreateFile:Rr,canCreateFolder:Fr,canRename:Er,canDelete:zr}}=Eo({files:s,root:l,selectedPath:h?.path??"",refreshDirectory:ht,removeOpenPathsByPrefix:Y,clearSelectedPath:Kt}),Mr=!!s.revealPath,Aa=Ot(a=>a.availableApps),Oa=Ot(a=>a.isCacheStale),Tr=Ot(a=>a.initialize),Pa=Ot(a=>a.loadInstalledApps);o.useEffect(()=>{Tr()},[Tr]);const La=o.useCallback(a=>{s.revealPath&&s.revealPath(a).catch(()=>{ie.error("Failed to reveal path")})},[s]),Ia=o.useCallback(async a=>{if(!h?.path||await Ws(h.path,a.id,a.appName)||await on(h.path,a.appName))return;const P=zo(h.path)||l;P&&await on(P,a.appName)||ie.error(`Failed to open in ${a.appName}`)},[l,h?.path]),Va=we(a=>a.fileEditorKeymap),$a=eo(a=>a.settingsDefaultFileViewerPreview),Dr=we(a=>a.expandedEditorToolbar);o.useEffect(()=>{Se("")},[h?.path]);const Ar=o.useRef("");o.useEffect(()=>{!l||Ar.current===l||(Ar.current=l,Fe(""),ve(null),$e(""),Ce(null),S(!1))},[l]);const Ba=u?D:E,{results:Or,searching:Pr}=Mo({directory:Ba,query:_,chrome:r,showHidden:w,showGitignored:B}),Lr=o.useCallback(async(a,f)=>{if(s.readFile)return(await s.readFile(a,{...f??{},directory:l||void 0})).content??"";const v=new URLSearchParams({path:a});f?.allowOutsideWorkspace&&v.set("allowOutsideWorkspace","true"),f?.outsideFileGrant&&v.set("outsideFileGrant",f.outsideFileGrant),f?.optional&&v.set("optional","true"),l&&v.set("directory",l);const P=await cn(`/api/fs/read?${v.toString()}`,{cache:f?.optional?"no-store":"default"});if(!P.ok){const te=await P.json().catch(()=>({error:P.statusText}));throw new Error(te.error||"Failed to read file")}return P.text()},[s,l]),Ke=o.useCallback(async(a,f)=>{if(s.statFile){const v=await s.statFile(a,{...f??{},directory:l||void 0});return{path:v.path,size:v.size,mtimeMs:v.mtimeMs}}return null},[s,l]);o.useEffect(()=>{if(!l||!s.statFile||Q.length===0)return;let a=!1;const f=[...Q];return Promise.all(f.map(async v=>{try{const P=await s.statFile?.(v,{directory:l||void 0});!a&&P&&!P.isFile&&Y(l,v)}catch(P){!a&&gn(P)&&Y(l,v)}})),()=>{a=!0}},[s,Q,Y,l]);const Gt=o.useMemo(()=>be.length>dt?`${be.slice(0,dt)}
|