@openchamber/web 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/assets/{DiagramView-1-LZVuzn.js → DiagramView-DZmf30ko.js} +1 -1
  2. package/dist/assets/{FilesView-BDRX8vU2.js → FilesView-cJPeFhDe.js} +6 -6
  3. package/dist/assets/{MarkdownRendererImpl-fZSdR7PD.js → MarkdownRendererImpl-DZezL90a.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-D81UrlA4.js → OnboardingScreen-ChYr0xqs.js} +1 -1
  5. package/dist/assets/{SessionSwitcherDropdown-cSK3t3TR.js → SessionSwitcherDropdown-BV7FfPbT.js} +1 -1
  6. package/dist/assets/{SettingsWindow-CozowJLm.js → SettingsWindow-UybkBD1p.js} +1 -1
  7. package/dist/assets/{contextPanelEmbeddedChat-CQYNvKbk.js → contextPanelEmbeddedChat-DW3atb4h.js} +1 -1
  8. package/dist/assets/{de-C2n4oo1Z.js → de-rVJ-hXrd.js} +3 -3
  9. package/dist/assets/es-D7ZyOToq.js +15 -0
  10. package/dist/assets/{fr-DDFUp5jS.js → fr-hl5i-ZI0.js} +2 -2
  11. package/dist/assets/{index-BCCcokur.css → index-CL9MYe8V.css} +1 -1
  12. package/dist/assets/{ja-B7SxobKm.js → ja-DqakdvOp.js} +2 -2
  13. package/dist/assets/{ko-CWGq93SO.js → ko-dNl8A3Xf.js} +2 -2
  14. package/dist/assets/main-B5TIsU2y.js +209 -0
  15. package/dist/assets/{main-Cts0BwVk.js → main-_m6HD9-a.js} +2 -2
  16. package/dist/assets/{markdownCore-BqzEkymd.js → markdownCore-DpT1vbbv.js} +2 -2
  17. package/dist/assets/{miniChat-ChuQD2KK.js → miniChat-wYb8p9vG.js} +2 -2
  18. package/dist/assets/{mobile-c-CRD1Cz.js → mobile-ExXAVUcv.js} +2 -2
  19. package/dist/assets/{pl-DZmyxLo7.js → pl-C5HQx1Hf.js} +3 -3
  20. package/dist/assets/pt-BR-CNCoBDAM.js +15 -0
  21. package/dist/assets/{renderElectronMiniChatApp-9uaZAJjw.js → renderElectronMiniChatApp-DPDzIT8W.js} +2 -2
  22. package/dist/assets/{renderMobileApp-Dm1tmU2a.js → renderMobileApp-CzWvxR9e.js} +3 -3
  23. package/dist/assets/runtimeEndpointReset-DKzVWH1w.js +180 -0
  24. package/dist/assets/uk-Bn-3AMpk.js +15 -0
  25. package/dist/assets/{useAppFontEffects-pyTMaGQu.js → useAppFontEffects-DdvGxoPX.js} +133 -133
  26. package/dist/assets/zh-CN-BCwvQpZm.js +15 -0
  27. package/dist/assets/zh-TW-TRHrkN9l.js +15 -0
  28. package/dist/index.html +4 -4
  29. package/dist/mini-chat.html +3 -3
  30. package/dist/mobile.html +3 -3
  31. package/package.json +2 -2
  32. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -1
  33. package/server/lib/openchamber-sessions/routes.js +117 -4
  34. package/server/lib/openchamber-sessions/routes.test.js +129 -16
  35. package/server/lib/opencode/DOCUMENTATION.md +2 -0
  36. package/server/lib/opencode/proxy.js +21 -3
  37. package/server/lib/small-model/DOCUMENTATION.md +11 -4
  38. package/server/lib/small-model/call.js +19 -3
  39. package/server/lib/small-model/call.test.js +9 -2
  40. package/server/lib/small-model/index.js +10 -1
  41. package/server/lib/small-model/index.test.js +20 -1
  42. package/server/lib/walkthrough/DOCUMENTATION.md +23 -0
  43. package/server/lib/walkthrough/index.js +17 -0
  44. package/server/lib/walkthrough/reproduce-2607.test.js +148 -0
  45. package/server/opencode-proxy.test.js +83 -0
  46. package/dist/assets/es-DP7jRKkr.js +0 -15
  47. package/dist/assets/main-Cqfcxvqq.js +0 -209
  48. package/dist/assets/pt-BR-BKR5oHQ7.js +0 -15
  49. package/dist/assets/runtimeEndpointReset-DL5z84w2.js +0 -180
  50. package/dist/assets/uk-D7oAI_Wc.js +0 -15
  51. package/dist/assets/zh-CN-Ddjz1_9w.js +0 -15
  52. package/dist/assets/zh-TW-D3X01YXj.js +0 -15
  53. /package/dist/assets/{index-ChZvuURI.js → index-DjZ4W8hy.js} +0 -0
@@ -1 +1 @@
1
- import{R as e,j as i}from"./vendor-react-BUCujlKS.js";import{u as n}from"./index-ChZvuURI.js";import{f as j,R as b,I as m}from"./useAppFontEffects-pyTMaGQu.js";import{D as y}from"./FilesView-BDRX8vU2.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BuzaMvKv.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CQYNvKbk.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-pierre-diffs-B1TeaSIY.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.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-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.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"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./runtimeEndpointReset-DL5z84w2.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-react-drawio-Ct3Q0DsD.js";function It(){const{t:p}=j(),{files:o}=b(),[r,g]=e.useState(null),[s,a]=e.useState(""),[x,l]=e.useState(!0),c=e.useRef(null),u=n(t=>t.pendingDiagramFile),f=e.useCallback(async t=>{l(!0),g(t);try{const d=await o?.readFile?.(t);d&&a(d.content)}catch{a("")}finally{l(!1)}},[o]);e.useEffect(()=>{if(!u)return;const t=n.getState().consumePendingDiagramFile();t&&f(t)},[f,u]);const h=e.useCallback(async()=>{const t=c.current?.getXml();r&&o?.writeFile&&t&&t!==s&&(await o.writeFile(r,t),a(t))},[r,o,s]),v=r?r.split("/").pop()||r:"";return r?x?i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx(m,{name:"loader-4",className:"size-4 animate-spin"})}):i.jsxs("div",{className:"flex h-full flex-col",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[i.jsx(m,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:v}),i.jsx("button",{type:"button",onClick:()=>{h()},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:p("filesView.diagram.saveDiagram"),children:i.jsx(m,{name:"save-3",className:"size-4"})}),i.jsx("button",{type:"button",onClick:()=>n.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:p("filesView.diagram.closeDiagramView"),children:i.jsx(m,{name:"close",className:"size-4"})})]}),i.jsx("div",{className:"flex-1 min-h-0",children:i.jsx(y,{ref:c,xml:s,className:"h-full"})})]}):i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx("div",{className:"typography-ui text-muted-foreground",children:p("filesView.editor.pickFileFromTree")})})}export{It as DiagramView};
1
+ import{R as e,j as i}from"./vendor-react-BUCujlKS.js";import{u as n}from"./index-DjZ4W8hy.js";import{f as j,R as b,I as m}from"./useAppFontEffects-DdvGxoPX.js";import{D as y}from"./FilesView-cJPeFhDe.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BuzaMvKv.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-DW3atb4h.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-pierre-diffs-B1TeaSIY.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.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-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.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"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./runtimeEndpointReset-DKzVWH1w.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-react-drawio-Ct3Q0DsD.js";function It(){const{t:p}=j(),{files:o}=b(),[r,g]=e.useState(null),[s,a]=e.useState(""),[x,l]=e.useState(!0),c=e.useRef(null),u=n(t=>t.pendingDiagramFile),f=e.useCallback(async t=>{l(!0),g(t);try{const d=await o?.readFile?.(t);d&&a(d.content)}catch{a("")}finally{l(!1)}},[o]);e.useEffect(()=>{if(!u)return;const t=n.getState().consumePendingDiagramFile();t&&f(t)},[f,u]);const h=e.useCallback(async()=>{const t=c.current?.getXml();r&&o?.writeFile&&t&&t!==s&&(await o.writeFile(r,t),a(t))},[r,o,s]),v=r?r.split("/").pop()||r:"";return r?x?i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx(m,{name:"loader-4",className:"size-4 animate-spin"})}):i.jsxs("div",{className:"flex h-full flex-col",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[i.jsx(m,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:v}),i.jsx("button",{type:"button",onClick:()=>{h()},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:p("filesView.diagram.saveDiagram"),children:i.jsx(m,{name:"save-3",className:"size-4"})}),i.jsx("button",{type:"button",onClick:()=>n.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:p("filesView.diagram.closeDiagramView"),children:i.jsx(m,{name:"close",className:"size-4"})})]}),i.jsx("div",{className:"flex-1 min-h-0",children:i.jsx(y,{ref:c,xml:s,className:"h-full"})})]}):i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx("div",{className:"typography-ui text-muted-foreground",children:p("filesView.editor.pickFileFromTree")})})}export{It as DiagramView};
@@ -1,14 +1,14 @@
1
- import{R as i,j as s,f as qt}from"./vendor-react-BUCujlKS.js";import{cD as bn,L as ua,w as Mr,x as Ar,O as os,cE as zr,cF as yn,cG as ii,D as Ir,Q as fa,R as ha,S as pa,T as ma,ad as Lr,l as ze,u as me,cH as ga,z as Or,q as va,r as Br,X as cn,e as xa,cI as wa,W as ba,cJ as ya}from"./index-ChZvuURI.js";import{f as zs,L as Ms,B as V,g as $,R as ja,G as Na,aO as Fa,Y as Sa,Z as ka,cl as Ca,dY as $r,fK as Wr,ea as Ta,t as L,i as Ur,a6 as dn,bo as Ds,bu as Da,fL as un,a7 as Gr,fM as _r,bp as Kr,bq as Va,ec as Ra,fN as Ea,bf as Pa,ed as Ma,fO as Hr,bg as ai,bh as li,bi as oi,bj as ci,bk as di,bl as ui,I as g,aN as jn,aK as Nn,a9 as Rs,aM as Fn,aI as Es,aQ as mt,aR as gt,aS as vt,bA as fn,a8 as hn,fP as Aa,cj as qr,bm as za,bn as Ia,fd as pn,aJ as As,aL as La,aT as Oa}from"./useAppFontEffects-pyTMaGQu.js";import{ae as Ba,af as $a,ag as Xr,ah as Wa,ai as Ua,aj as Jr,ak as mn,Y as Ga,Z as _a,_ as Ka,$ as Ha,a0 as qa}from"./runtimeEndpointReset-DL5z84w2.js";import{a as Xa}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as Vt}from"./vendor-codemirror-view-DSzLbZiS.js";import{g as Ja}from"./vendor-pierre-diffs-B1TeaSIY.js";import{D as Ya}from"./vendor-react-drawio-Ct3Q0DsD.js";import{c as Za}from"./vendor-zustand-BAGL70zf.js";const gn=()=>os.filter(d=>yn.has(d.id)).map(d=>({...ii(d)})),Qa=()=>{if(typeof window>"u")return Ir;const d=window.localStorage.getItem("openInAppId");return d&&bn(d)?d:Ir};let vn=!1,Kt=!1,xt=!1,wt=0,cs=null;const Yr=()=>{cs&&(clearTimeout(cs),cs=null)},Vs=Za()((d,e)=>({selectedAppId:Qa(),availableApps:gn(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(vn||typeof window>"u")return;vn=!0;const n=(p,x=!0)=>{if(!Array.isArray(p)||p.length===0){d({availableApps:gn(),hasLoadedApps:x});return}const m=new Set(p.map(y=>y.name)),b=new Map(p.map(y=>[y.name,y.iconDataUrl??void 0])),k=os.filter(y=>m.has(y.appName)||yn.has(y.id)).map(y=>({...ii(y),iconDataUrl:b.get(y.appName)}));d({availableApps:k,hasLoadedApps:!0})},u=async p=>{if(!Mr()||!Ar()||Kt||e().hasLoadedApps&&!p)return;const m=os.map(b=>b.appName);Yr(),Kt=!0,xt=!1,d({isScanning:!0});try{const{apps:b,success:F,hasCache:k,isCacheStale:y}=await zr(m,p),C=F&&!k&&b.length===0&&wt<3;if(d({isCacheStale:k?y:!1}),n(b,F?!C:!1),F){if(C){const R=[800,1600,3200][wt]??3200;wt+=1,xt=!0,cs=setTimeout(()=>{u()},R);return}wt=0,xt=!1;return}if(wt<3){const R=[1e3,3e3,7e3][wt]??7e3;wt+=1,xt=!0,cs=setTimeout(()=>{u()},R)}}finally{Kt=!1,xt||d({isScanning:!1})}};u();const v=p=>{const x=p.detail,m=x&&typeof x.openInAppId=="string"&&x.openInAppId.length>0&&bn(x.openInAppId)?x.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),d({selectedAppId:m}))},w=()=>{u()},N=p=>{const x=p.detail;Array.isArray(x)&&(wt=3,xt=!1,d({isScanning:!1,isCacheStale:!1}),n(x))};window.addEventListener("openchamber:settings-synced",v),window.addEventListener("openchamber:app-ready",w),window.addEventListener("openchamber:installed-apps-updated",N),window.__openchamberAppReady&&u(),window.setTimeout(()=>{e().hasLoadedApps||u()},5e3)},loadInstalledApps:async n=>{if(vn||e().initialize(),!Mr()||!Ar()||Kt||e().hasLoadedApps&&!n)return;const v=os.map(w=>w.appName);Yr(),n&&d({hasLoadedApps:!1}),Kt=!0,xt=!1,d({isScanning:!0});try{const{apps:w,hasCache:N,isCacheStale:j}=await zr(v,n),p=new Set(w.map(F=>F.name)),x=new Map(w.map(F=>[F.name,F.iconDataUrl??void 0])),b=os.filter(F=>p.has(F.appName)||yn.has(F.id)).map(F=>({...F,iconDataUrl:x.get(F.appName)}));d({availableApps:b.length>0?b:gn(),hasLoadedApps:b.length>0,isCacheStale:N?j:!1})}finally{Kt=!1,xt||d({isScanning:!1})}},selectApp:async n=>{bn(n)&&(d({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ua({openInAppId:n}))}})),el=(d,e)=>{if(!e)return null;const n=Number.parseInt(d.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},Zr=(d,e)=>{const n=d.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Qr=(d,e,n)=>{const u=d.state.doc.line(e),v=Math.max(1,Math.min(n,u.length+1)),w=u.from+v-1;d.dispatch({selection:Xa.cursor(w),effects:Vt.scrollIntoView(w,{y:"center"})})};function tl({open:d,onOpenChange:e,view:n,variant:u="overlay"}){const{t:v}=zs(),[w,N]=i.useState(""),j=i.useRef(null),p=i.useRef(!1),x=i.useRef(null),m=i.useRef(null),b=i.useMemo(()=>el(w,n),[w,n]);i.useEffect(()=>{!d||!n||(p.current=!1,j.current=Zr(n,n.state.selection),N(""))},[d,n]),i.useEffect(()=>{d&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[d]),i.useEffect(()=>{if(!(!d||!n||!j.current)){if(b===null){const{selection:a}=j.current;n.dispatch({selection:a,effects:Vt.scrollIntoView(a.main.from,{y:"center"})});return}Qr(n,b,j.current.character)}},[b,d,n]);const F=i.useCallback(()=>{if(!n||p.current||!j.current)return;const{selection:a}=j.current;n.dispatch({selection:a,effects:Vt.scrollIntoView(a.main.from,{y:"center"})})},[n]),k=i.useCallback(a=>{a||F(),e(a)},[e,F]),y=i.useCallback(()=>{!n||b===null||!j.current||(p.current=!0,Qr(n,b,j.current.character),e(!1),n.focus())},[b,e,n]);i.useEffect(()=>{if(!d)return;const a=B=>{const q=x.current,z=B.target;!q||!(z instanceof Node)||q.contains(z)||k(!1)},R=B=>{B.key==="Escape"&&(B.preventDefault(),k(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",R,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",R,!0)}},[k,d,u]);const C=i.useMemo(()=>{if(!n)return v("goToLineDialog.helper.editorUnavailable");if(b===null){const a=j.current??Zr(n,n.state.selection);return v("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:n.state.doc.lines})}return v("goToLineDialog.helper.goToLine",{line:b})},[b,v,n]);return u==="inline"?d?s.jsxs("div",{ref:x,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Ms,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:w,onChange:a=>N(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),y())},placeholder:v("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(V,{variant:"outline",size:"xs",onClick:y,disabled:!n||b===null,className:"h-6 px-2",children:v("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:x,className:$("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",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Ms,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:w,onChange:a=>N(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),y())},placeholder:v("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:C})]})})}function sl(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function nl(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const rl='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function ei(){if(typeof document>"u")return!1;const d=document.documentElement.getAttribute("data-theme");return d==="dark"||!d&&window.matchMedia("(prefers-color-scheme: dark)").matches}const il=i.forwardRef(function({xml:e,readOnly:n,className:u,onChange:v},w){const N=i.useRef(e),j=i.useRef(null),p=i.useRef(!1),[x,m]=i.useState(ei),b=i.useRef(e),F=i.useRef(e);F.current!==e&&(F.current=e,b.current=e,N.current=e);const k=i.useRef(x);k.current!==x&&(k.current=x,b.current=N.current);const y=i.useRef(null);i.useEffect(()=>{const R=()=>m(ei());R();const B=new MutationObserver(R);return B.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>B.disconnect()},[]),i.useEffect(()=>{const R=setTimeout(()=>{y.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(R)},[]),i.useImperativeHandle(w,()=>({getXml:()=>N.current}));const C=i.useCallback(()=>{!e&&!p.current&&(p.current=!0,setTimeout(()=>{j.current?.template({})},500))},[e]),a=i.useCallback(R=>{N.current=R.xml,v?.(R.xml)},[v]);return s.jsx("div",{ref:y,className:$("h-full w-full",u),children:s.jsx(Ya,{ref:j,xml:b.current||rl,autosave:!0,urlParameters:{ui:n?"simple":x?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:C,onAutoSave:a},x?"dark":"light")})}),al=d=>{const e=O(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const u=e.slice(0,n);return/^[A-Za-z]:$/.test(u)?`${u}/`:u},ll=d=>{const e=qt.c(8),{label:n,iconDataUrl:u}=d,[v,w]=i.useState(!1);let N;e[0]!==n?(N=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=N):N=e[1];const j=N;if(u&&!v){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>w(!0),e[2]=m):m=e[2];let b;return e[3]!==u?(b=s.jsx("img",{src:u,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=u,e[4]=b):b=e[4],b}let p;e[5]===Symbol.for("react.memo_cache_sentinel")?(p=$("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=p):p=e[5];let x;return e[6]!==j?(x=s.jsx("span",{className:p,children:j}),e[6]=j,e[7]=x):x=e[7],x},ol=d=>d.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),O=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),n=e.startsWith("//");let u=e.replace(/\/+/g,"/");n&&!u.startsWith("//")&&(u=`/${u}`);const v=u==="/",w=/^[A-Za-z]:\/$/.test(u);return!v&&!w&&(u=u.replace(/\/+$/,"")),u},cl=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Ht=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,ds=(d,e)=>{const n=O(e),u=O(d);if(!n||!u)return!1;const v=Ht(n),w=Ht(u);return w===v||w.startsWith(`${v}/`)},ti=(d,e)=>{const n=O(e),u=O(d);if(!ds(u,n))return[];const w=u.slice(n.length).replace(/^\//,"").split("/"),N=[];let j=n;for(let p=0;p<w.length-1;p++)j=j?`${j}/${w[p]}`:w[p],N.push(j);return N},Ps=(d,e)=>{if(!e)return"";const n=O(e);if(!d||!ds(n,d))return n;const u=n.slice(d.length);return u.startsWith("/")?u.slice(1):u},dl=new Set(["node_modules"]),ul=d=>{const e=qt.c(3),{status:n}=d;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=u):u=e[0];const v=u[n];let w;return e[1]!==v?(w=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:v}}),e[1]=v,e[2]=w):w=e[2],w},si=d=>{const e=qt.c(11),{name:n}=d,u=i.useRef(null),v=i.useRef(null),[w,N]=i.useState(!1);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const F=u.current,k=v.current;if(!F||!k)return;const y=()=>{N(k.scrollWidth>F.clientWidth+1)};y();const C=new ResizeObserver(y);return C.observe(F),C.observe(k),()=>{C.disconnect()}},e[0]=j):j=e[0];let p;e[1]!==n?(p=[n],e[1]=n,e[2]=p):p=e[2],i.useLayoutEffect(j,p);let x;e[3]!==n?(x=s.jsx("span",{ref:v,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=x):x=e[4];let m;e[5]!==n||e[6]!==w?(m=w?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=w,e[7]=m):m=e[7];let b;return e[8]!==x||e[9]!==m?(b=s.jsxs("span",{ref:u,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[x,m]}),e[8]=x,e[9]=m,e[10]=b):b=e[10],b},fl=d=>dl.has(d),hl=d=>{const e=O(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},pl=d=>{const n=(d instanceof Error?d.message:String(d??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},ni=d=>{const n=(d instanceof Error?d.message:String(d??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},ls=2e5,ml=d=>{let e=0,n=0;for(let u=0;u<d.length;u+=1)d.charCodeAt(u)===10&&(u>0&&d.charCodeAt(u-1)===13?e+=1:n+=1);return e>n?`\r
1
+ import{R as i,j as s,f as qt}from"./vendor-react-BUCujlKS.js";import{cD as bn,L as ua,w as Mr,x as Ar,O as os,cE as zr,cF as yn,cG as ii,D as Ir,Q as fa,R as ha,S as pa,T as ma,ad as Lr,l as ze,u as me,cH as ga,z as Or,q as va,r as Br,X as cn,e as xa,cI as wa,W as ba,cJ as ya}from"./index-DjZ4W8hy.js";import{f as zs,L as Ms,B as V,g as $,R as ja,G as Na,aO as Fa,Y as Sa,Z as ka,cl as Ca,dZ as $r,fL as Wr,eb as Ta,t as L,i as Ur,a6 as dn,bo as Ds,bu as Da,fM as un,a7 as Gr,fN as _r,bp as Hr,bq as Va,ed as Ra,fO as Ea,bf as Pa,ee as Ma,fP as Kr,bg as ai,bh as li,bi as oi,bj as ci,bk as di,bl as ui,I as g,aN as jn,aK as Nn,a9 as Rs,aM as Fn,aI as Es,aQ as mt,aR as gt,aS as vt,bA as fn,a8 as hn,fQ as Aa,cj as qr,bm as za,bn as Ia,fe as pn,aJ as As,aL as La,aT as Oa}from"./useAppFontEffects-DdvGxoPX.js";import{ae as Ba,af as $a,ag as Xr,ah as Wa,ai as Ua,aj as Jr,ak as mn,Y as Ga,Z as _a,_ as Ha,$ as Ka,a0 as qa}from"./runtimeEndpointReset-DKzVWH1w.js";import{a as Xa}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as Vt}from"./vendor-codemirror-view-DSzLbZiS.js";import{g as Ja}from"./vendor-pierre-diffs-B1TeaSIY.js";import{D as Ya}from"./vendor-react-drawio-Ct3Q0DsD.js";import{c as Za}from"./vendor-zustand-BAGL70zf.js";const gn=()=>os.filter(d=>yn.has(d.id)).map(d=>({...ii(d)})),Qa=()=>{if(typeof window>"u")return Ir;const d=window.localStorage.getItem("openInAppId");return d&&bn(d)?d:Ir};let vn=!1,Ht=!1,xt=!1,wt=0,cs=null;const Yr=()=>{cs&&(clearTimeout(cs),cs=null)},Vs=Za()((d,e)=>({selectedAppId:Qa(),availableApps:gn(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(vn||typeof window>"u")return;vn=!0;const n=(p,x=!0)=>{if(!Array.isArray(p)||p.length===0){d({availableApps:gn(),hasLoadedApps:x});return}const m=new Set(p.map(y=>y.name)),b=new Map(p.map(y=>[y.name,y.iconDataUrl??void 0])),k=os.filter(y=>m.has(y.appName)||yn.has(y.id)).map(y=>({...ii(y),iconDataUrl:b.get(y.appName)}));d({availableApps:k,hasLoadedApps:!0})},u=async p=>{if(!Mr()||!Ar()||Ht||e().hasLoadedApps&&!p)return;const m=os.map(b=>b.appName);Yr(),Ht=!0,xt=!1,d({isScanning:!0});try{const{apps:b,success:F,hasCache:k,isCacheStale:y}=await zr(m,p),C=F&&!k&&b.length===0&&wt<3;if(d({isCacheStale:k?y:!1}),n(b,F?!C:!1),F){if(C){const R=[800,1600,3200][wt]??3200;wt+=1,xt=!0,cs=setTimeout(()=>{u()},R);return}wt=0,xt=!1;return}if(wt<3){const R=[1e3,3e3,7e3][wt]??7e3;wt+=1,xt=!0,cs=setTimeout(()=>{u()},R)}}finally{Ht=!1,xt||d({isScanning:!1})}};u();const v=p=>{const x=p.detail,m=x&&typeof x.openInAppId=="string"&&x.openInAppId.length>0&&bn(x.openInAppId)?x.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),d({selectedAppId:m}))},w=()=>{u()},N=p=>{const x=p.detail;Array.isArray(x)&&(wt=3,xt=!1,d({isScanning:!1,isCacheStale:!1}),n(x))};window.addEventListener("openchamber:settings-synced",v),window.addEventListener("openchamber:app-ready",w),window.addEventListener("openchamber:installed-apps-updated",N),window.__openchamberAppReady&&u(),window.setTimeout(()=>{e().hasLoadedApps||u()},5e3)},loadInstalledApps:async n=>{if(vn||e().initialize(),!Mr()||!Ar()||Ht||e().hasLoadedApps&&!n)return;const v=os.map(w=>w.appName);Yr(),n&&d({hasLoadedApps:!1}),Ht=!0,xt=!1,d({isScanning:!0});try{const{apps:w,hasCache:N,isCacheStale:j}=await zr(v,n),p=new Set(w.map(F=>F.name)),x=new Map(w.map(F=>[F.name,F.iconDataUrl??void 0])),b=os.filter(F=>p.has(F.appName)||yn.has(F.id)).map(F=>({...F,iconDataUrl:x.get(F.appName)}));d({availableApps:b.length>0?b:gn(),hasLoadedApps:b.length>0,isCacheStale:N?j:!1})}finally{Ht=!1,xt||d({isScanning:!1})}},selectApp:async n=>{bn(n)&&(d({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ua({openInAppId:n}))}})),el=(d,e)=>{if(!e)return null;const n=Number.parseInt(d.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},Zr=(d,e)=>{const n=d.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Qr=(d,e,n)=>{const u=d.state.doc.line(e),v=Math.max(1,Math.min(n,u.length+1)),w=u.from+v-1;d.dispatch({selection:Xa.cursor(w),effects:Vt.scrollIntoView(w,{y:"center"})})};function tl({open:d,onOpenChange:e,view:n,variant:u="overlay"}){const{t:v}=zs(),[w,N]=i.useState(""),j=i.useRef(null),p=i.useRef(!1),x=i.useRef(null),m=i.useRef(null),b=i.useMemo(()=>el(w,n),[w,n]);i.useEffect(()=>{!d||!n||(p.current=!1,j.current=Zr(n,n.state.selection),N(""))},[d,n]),i.useEffect(()=>{d&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[d]),i.useEffect(()=>{if(!(!d||!n||!j.current)){if(b===null){const{selection:a}=j.current;n.dispatch({selection:a,effects:Vt.scrollIntoView(a.main.from,{y:"center"})});return}Qr(n,b,j.current.character)}},[b,d,n]);const F=i.useCallback(()=>{if(!n||p.current||!j.current)return;const{selection:a}=j.current;n.dispatch({selection:a,effects:Vt.scrollIntoView(a.main.from,{y:"center"})})},[n]),k=i.useCallback(a=>{a||F(),e(a)},[e,F]),y=i.useCallback(()=>{!n||b===null||!j.current||(p.current=!0,Qr(n,b,j.current.character),e(!1),n.focus())},[b,e,n]);i.useEffect(()=>{if(!d)return;const a=B=>{const q=x.current,z=B.target;!q||!(z instanceof Node)||q.contains(z)||k(!1)},R=B=>{B.key==="Escape"&&(B.preventDefault(),k(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",R,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",R,!0)}},[k,d,u]);const C=i.useMemo(()=>{if(!n)return v("goToLineDialog.helper.editorUnavailable");if(b===null){const a=j.current??Zr(n,n.state.selection);return v("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:n.state.doc.lines})}return v("goToLineDialog.helper.goToLine",{line:b})},[b,v,n]);return u==="inline"?d?s.jsxs("div",{ref:x,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Ms,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:w,onChange:a=>N(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),y())},placeholder:v("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(V,{variant:"outline",size:"xs",onClick:y,disabled:!n||b===null,className:"h-6 px-2",children:v("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:x,className:$("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",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Ms,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:w,onChange:a=>N(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),y())},placeholder:v("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:C})]})})}function sl(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function nl(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const rl='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function ei(){if(typeof document>"u")return!1;const d=document.documentElement.getAttribute("data-theme");return d==="dark"||!d&&window.matchMedia("(prefers-color-scheme: dark)").matches}const il=i.forwardRef(function({xml:e,readOnly:n,className:u,onChange:v},w){const N=i.useRef(e),j=i.useRef(null),p=i.useRef(!1),[x,m]=i.useState(ei),b=i.useRef(e),F=i.useRef(e);F.current!==e&&(F.current=e,b.current=e,N.current=e);const k=i.useRef(x);k.current!==x&&(k.current=x,b.current=N.current);const y=i.useRef(null);i.useEffect(()=>{const R=()=>m(ei());R();const B=new MutationObserver(R);return B.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>B.disconnect()},[]),i.useEffect(()=>{const R=setTimeout(()=>{y.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(R)},[]),i.useImperativeHandle(w,()=>({getXml:()=>N.current}));const C=i.useCallback(()=>{!e&&!p.current&&(p.current=!0,setTimeout(()=>{j.current?.template({})},500))},[e]),a=i.useCallback(R=>{N.current=R.xml,v?.(R.xml)},[v]);return s.jsx("div",{ref:y,className:$("h-full w-full",u),children:s.jsx(Ya,{ref:j,xml:b.current||rl,autosave:!0,urlParameters:{ui:n?"simple":x?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:C,onAutoSave:a},x?"dark":"light")})}),al=d=>{const e=O(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const u=e.slice(0,n);return/^[A-Za-z]:$/.test(u)?`${u}/`:u},ll=d=>{const e=qt.c(8),{label:n,iconDataUrl:u}=d,[v,w]=i.useState(!1);let N;e[0]!==n?(N=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=N):N=e[1];const j=N;if(u&&!v){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>w(!0),e[2]=m):m=e[2];let b;return e[3]!==u?(b=s.jsx("img",{src:u,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=u,e[4]=b):b=e[4],b}let p;e[5]===Symbol.for("react.memo_cache_sentinel")?(p=$("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=p):p=e[5];let x;return e[6]!==j?(x=s.jsx("span",{className:p,children:j}),e[6]=j,e[7]=x):x=e[7],x},ol=d=>d.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),O=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),n=e.startsWith("//");let u=e.replace(/\/+/g,"/");n&&!u.startsWith("//")&&(u=`/${u}`);const v=u==="/",w=/^[A-Za-z]:\/$/.test(u);return!v&&!w&&(u=u.replace(/\/+$/,"")),u},cl=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Kt=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,ds=(d,e)=>{const n=O(e),u=O(d);if(!n||!u)return!1;const v=Kt(n),w=Kt(u);return w===v||w.startsWith(`${v}/`)},ti=(d,e)=>{const n=O(e),u=O(d);if(!ds(u,n))return[];const w=u.slice(n.length).replace(/^\//,"").split("/"),N=[];let j=n;for(let p=0;p<w.length-1;p++)j=j?`${j}/${w[p]}`:w[p],N.push(j);return N},Ps=(d,e)=>{if(!e)return"";const n=O(e);if(!d||!ds(n,d))return n;const u=n.slice(d.length);return u.startsWith("/")?u.slice(1):u},dl=new Set(["node_modules"]),ul=d=>{const e=qt.c(3),{status:n}=d;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=u):u=e[0];const v=u[n];let w;return e[1]!==v?(w=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:v}}),e[1]=v,e[2]=w):w=e[2],w},si=d=>{const e=qt.c(11),{name:n}=d,u=i.useRef(null),v=i.useRef(null),[w,N]=i.useState(!1);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const F=u.current,k=v.current;if(!F||!k)return;const y=()=>{N(k.scrollWidth>F.clientWidth+1)};y();const C=new ResizeObserver(y);return C.observe(F),C.observe(k),()=>{C.disconnect()}},e[0]=j):j=e[0];let p;e[1]!==n?(p=[n],e[1]=n,e[2]=p):p=e[2],i.useLayoutEffect(j,p);let x;e[3]!==n?(x=s.jsx("span",{ref:v,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=x):x=e[4];let m;e[5]!==n||e[6]!==w?(m=w?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=w,e[7]=m):m=e[7];let b;return e[8]!==x||e[9]!==m?(b=s.jsxs("span",{ref:u,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[x,m]}),e[8]=x,e[9]=m,e[10]=b):b=e[10],b},fl=d=>dl.has(d),hl=d=>{const e=O(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},pl=d=>{const n=(d instanceof Error?d.message:String(d??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},ni=d=>{const n=(d instanceof Error?d.message:String(d??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},ls=2e5,ml=d=>{let e=0,n=0;for(let u=0;u<d.length;u+=1)d.charCodeAt(u)===10&&(u>0&&d.charCodeAt(u-1)===13?e+=1:n+=1);return e>n?`\r
2
2
  `:`
3
3
  `},fi=d=>d.replace(/\r\n/g,`
4
4
  `).replace(/\r/g,`
5
5
  `),gl=(d,e)=>{const n=fi(d);return e===`\r
6
6
  `?n.replace(/\n/g,`\r
7
- `):n},hi=(d,e)=>s.jsx(Rs,{filePath:d,extension:e}),ri=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},vl=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},xn=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},xl=d=>{const e=qt.c(76),{node:n,root:u,isExpanded:v,isActive:w,isMobile:N,isBrowserClient:j,alwaysShowActions:p,status:x,badge:m,permissions:b,downloadFile:F,contextMenuPath:k,setContextMenuPath:y,rightClickMenuPath:C,setRightClickMenuPath:a,onSelect:R,onToggle:B,onRevealPath:q,onOpenDialog:z}=d,{t:E}=zs(),P=n.type==="directory",{canRename:ce,canCreateFile:ee,canCreateFolder:te,canDelete:I,canReveal:de}=b,Ie=!P&&!!F,G=de&&!j,X=ce||ee||te||I||Ie||G;let se;e[0]!==X||e[1]!==n.path||e[2]!==a?(se=he=>{X&&(he?.preventDefault(),a(n.path))},e[0]=X,e[1]=n.path,e[2]=a,e[3]=se):se=e[3];const ge=se;let ne;e[4]!==P||e[5]!==n||e[6]!==R||e[7]!==B?(ne=()=>{P?B(n.path):R(n)},e[4]=P,e[5]=n,e[6]=R,e[7]=B,e[8]=ne):ne=e[8];const ve=ne;let ue;e[9]!==n.path||e[10]!==y||e[11]!==a?(ue=he=>{he.stopPropagation(),a(null),y(n.path)},e[9]=n.path,e[10]=y,e[11]=a,e[12]=ue):ue=e[12];const rt=ue;let Rt;e[13]!==ee||e[14]!==te||e[15]!==I||e[16]!==ce||e[17]!==G||e[18]!==F||e[19]!==j||e[20]!==P||e[21]!==n||e[22]!==z||e[23]!==q||e[24]!==u||e[25]!==E?(Rt=he=>{const{Item:we,Separator:jt}=he;return s.jsxs(s.Fragment,{children:[ce&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("rename",n)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(we,{onClick:T=>{T.stopPropagation(),As(n.path).then(be=>{if(be.ok){L.success(E("sidebarFilesTree.toast.pathCopied"));return}L.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(we,{onClick:T=>{T.stopPropagation();const be=Ps(u,n.path)||n.path;As(be).then(Je=>{if(Je.ok){L.success(E("filesView.toast.relativePathCopied"));return}L.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!P&&F&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),F(n.path).catch(be=>{console.error("Download failed:",be),L.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",E(j?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),G&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),q(n.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",E(Oa())]}),P&&(ee||te)&&s.jsxs(s.Fragment,{children:[s.jsx(jt,{}),ee&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("createFile",n)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),te&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("createFolder",n)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(jt,{}),s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=ee,e[14]=te,e[15]=I,e[16]=ce,e[17]=G,e[18]=F,e[19]=j,e[20]=P,e[21]=n,e[22]=z,e[23]=q,e[24]=u,e[25]=E,e[26]=Rt):Rt=e[26];const Xe=Rt,_=C===n.path;let Se;e[27]!==n.path||e[28]!==a?(Se=he=>a(he?n.path:null),e[27]=n.path,e[28]=a,e[29]=Se):Se=e[29];const bt=N?void 0:ge;let Le;e[30]!==bt?(Le=s.jsx("div",{className:"group relative flex items-center",onContextMenu:bt}),e[30]=bt,e[31]=Le):Le=e[31];const Oe=N?void 0:ge,yt=w?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let xe;e[32]!==yt?(xe=$("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",yt),e[32]=yt,e[33]=xe):xe=e[33];let Be;e[34]!==P||e[35]!==v||e[36]!==n.extension||e[37]!==n.path?(Be=P?v?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):hi(n.path,n.extension),e[34]=P,e[35]=v,e[36]=n.extension,e[37]=n.path,e[38]=Be):Be=e[38];let fe;e[39]!==n.name||e[40]!==n.path?(fe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[39]=n.name,e[40]=n.path,e[41]=fe):fe=e[41];let ke;e[42]!==P||e[43]!==x?(ke=!P&&x&&s.jsx(ul,{status:x}),e[42]=P,e[43]=x,e[44]=ke):ke=e[44];let it;e[45]!==m||e[46]!==P?(it=P&&m&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[45]=m,e[46]=P,e[47]=it):it=e[47];let at;e[48]!==ve||e[49]!==xe||e[50]!==Be||e[51]!==fe||e[52]!==ke||e[53]!==it||e[54]!==Oe?(at=s.jsxs("button",{type:"button",onClick:ve,onContextMenu:Oe,className:xe,children:[Be,fe,ke,it]}),e[48]=ve,e[49]=xe,e[50]=Be,e[51]=fe,e[52]=ke,e[53]=it,e[54]=Oe,e[55]=at):at=e[55];let $e;e[56]!==p||e[57]!==k||e[58]!==rt||e[59]!==X||e[60]!==N||e[61]!==n.path||e[62]!==Xe||e[63]!==y?($e=X&&s.jsx("div",{className:$("absolute right-1 top-1/2 -translate-y-1/2",p?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(jn,{open:k===n.path,onOpenChange:he=>y(he?n.path:null),children:[s.jsx(Nn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"icon",className:"size-6",onClick:rt,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Fn,{align:"end",side:"bottom",onCloseAutoFocus:()=>y(null),children:Xe({Item:Es,Separator:La})})]})}),e[56]=p,e[57]=k,e[58]=rt,e[59]=X,e[60]=N,e[61]=n.path,e[62]=Xe,e[63]=y,e[64]=$e):$e=e[64];let We;e[65]!==at||e[66]!==$e||e[67]!==Le?(We=s.jsxs(Ha,{render:Le,children:[at,$e]}),e[65]=at,e[66]=$e,e[67]=Le,e[68]=We):We=e[68];let Ue;e[69]!==Xe?(Ue=s.jsx(Ga,{className:"min-w-[180px]",children:Xe({Item:Ka,Separator:_a})}),e[69]=Xe,e[70]=Ue):Ue=e[70];let lt;return e[71]!==We||e[72]!==Ue||e[73]!==_||e[74]!==Se?(lt=s.jsxs(qa,{open:_,onOpenChange:Se,children:[We,Ue]}),e[71]=We,e[72]=Ue,e[73]=_,e[74]=Se,e[75]=lt):lt=e[75],lt},wl=d=>{const e=qt.c(83),{activeDialog:n,dialogData:u,dialogInputValue:v,onDialogInputChange:w,isDialogSubmitting:N,onDialogSubmit:j,onClose:p,inputRef:x}=d,{t:m}=zs(),b=!!n;let F;e[0]!==p?(F=ue=>!ue&&p(),e[0]=p,e[1]=F):F=e[1];let k;e[2]!==n||e[3]!==m?(k=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=k):k=e[4];let y;e[5]!==n||e[6]!==m?(y=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=y):y=e[7];let C;e[8]!==n||e[9]!==m?(C=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=C):C=e[10];let a;e[11]!==n||e[12]!==m?(a=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=a):a=e[13];let R;e[14]!==k||e[15]!==y||e[16]!==C||e[17]!==a?(R=s.jsxs(ci,{children:[k,y,C,a]}),e[14]=k,e[15]=y,e[16]=C,e[17]=a,e[18]=R):R=e[18];let B;e[19]!==n||e[20]!==u?.path||e[21]!==m?(B=n==="createFile"&&m("filesView.dialog.createFile.description",{path:u?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=u?.path,e[21]=m,e[22]=B):B=e[22];let q;e[23]!==n||e[24]!==u?.path||e[25]!==m?(q=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:u?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=u?.path,e[25]=m,e[26]=q):q=e[26];let z;e[27]!==n||e[28]!==u?.name||e[29]!==m?(z=n==="rename"&&m("filesView.dialog.rename.description",{name:u?.name??""}),e[27]=n,e[28]=u?.name,e[29]=m,e[30]=z):z=e[30];let E;e[31]!==n||e[32]!==u?.name||e[33]!==m?(E=n==="delete"&&m("filesView.dialog.delete.description",{name:u?.name??""}),e[31]=n,e[32]=u?.name,e[33]=m,e[34]=E):E=e[34];let P;e[35]!==z||e[36]!==E||e[37]!==B||e[38]!==q?(P=s.jsxs(di,{children:[B,q,z,E]}),e[35]=z,e[36]=E,e[37]=B,e[38]=q,e[39]=P):P=e[39];let ce;e[40]!==P||e[41]!==R?(ce=s.jsxs(oi,{children:[R,P]}),e[40]=P,e[41]=R,e[42]=ce):ce=e[42];let ee;e[43]!==n||e[44]!==v||e[45]!==x||e[46]!==w||e[47]!==j||e[48]!==m?(ee=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ms,{value:v,onChange:ue=>w(ue.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:ue=>{ue.key==="Enter"&&j()},ref:x})}),e[43]=n,e[44]=v,e[45]=x,e[46]=w,e[47]=j,e[48]=m,e[49]=ee):ee=e[49];let te;e[50]!==m?(te=m("filesView.dialog.cancel"),e[50]=m,e[51]=te):te=e[51];let I;e[52]!==N||e[53]!==p||e[54]!==te?(I=s.jsx(V,{variant:"outline",onClick:p,disabled:N,children:te}),e[52]=N,e[53]=p,e[54]=te,e[55]=I):I=e[55];const de=n==="delete"?"destructive":"default";let Ie;e[56]!==j?(Ie=()=>{j()},e[56]=j,e[57]=Ie):Ie=e[57];let G;e[58]!==n||e[59]!==v||e[60]!==N?(G=N||n!=="delete"&&!v.trim(),e[58]=n,e[59]=v,e[60]=N,e[61]=G):G=e[61];let X;e[62]!==n||e[63]!==N||e[64]!==m?(X=N?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=N,e[64]=m,e[65]=X):X=e[65];let se;e[66]!==de||e[67]!==Ie||e[68]!==G||e[69]!==X?(se=s.jsx(V,{variant:de,onClick:Ie,disabled:G,children:X}),e[66]=de,e[67]=Ie,e[68]=G,e[69]=X,e[70]=se):se=e[70];let ge;e[71]!==I||e[72]!==se?(ge=s.jsxs(ui,{children:[I,se]}),e[71]=I,e[72]=se,e[73]=ge):ge=e[73];let ne;e[74]!==x||e[75]!==ce||e[76]!==ee||e[77]!==ge?(ne=s.jsxs(li,{initialFocus:x,children:[ce,ee,ge]}),e[74]=x,e[75]=ce,e[76]=ee,e[77]=ge,e[78]=ne):ne=e[78];let ve;return e[79]!==b||e[80]!==F||e[81]!==ne?(ve=s.jsx(ai,{open:b,onOpenChange:F,children:ne}),e[79]=b,e[80]=F,e[81]=ne,e[82]=ve):ve=e[82],ve},wn=(d,e,n)=>{const u=qt.c(8),[v,w]=i.useState(""),[N,j]=i.useState(0);let p,x;u[0]!==d||u[1]!==n||u[2]!==e?(p=()=>{if(!d){w("");return}let b=!1;w("");const F=xa(),k=wa(F);ba(F).then(C=>{b||!C||(w(d),e(null))}).catch(C=>{b||(e(C instanceof Error?C.message:n),w(d))});const y=ya(()=>{b||(w(d),j(yl),e(null))});return()=>{b=!0,k(),y()}},x=[d,e,n],u[0]=d,u[1]=n,u[2]=e,u[3]=p,u[4]=x):(p=u[3],x=u[4]),i.useEffect(p,x);let m;return u[5]!==N||u[6]!==v?(m={readyKey:v,nonce:N},u[5]=N,u[6]=v,u[7]=m):m=u[7],m},bl=({mode:d="full"})=>{const{t:e}=zs(),{files:n,runtime:u}=ja(),{currentTheme:v,availableThemes:w,lightThemeId:N,darkThemeId:j}=Na(),{isMobile:p,isTablet:x,screenWidth:m}=Fa(),b=fa(u.platform),F=p||x,k=ha(),y=pa(),C=Sa()??"",a=O(C.trim()),R=d!=="editor-only",B=d==="editor-only"&&!p,q=ma(t=>t.searchFiles),z=ka(C),[E,P]=i.useState(""),ce=Ca(E,200),ee=i.useRef(null),[te,I]=i.useState(!1),[de,Ie]=i.useState(!0),[G,X]=i.useState(!1),[se,ge]=i.useState(!1),[ne,ve]=i.useState(!1),ue=i.useRef(null),rt=i.useRef(0),Rt=i.useCallback(t=>{rt.current=Math.max(0,rt.current+(t?1:-1))},[]),Xe=i.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);i.useEffect(()=>{if(!ne)return;const t=r=>{rt.current>0||Xe(r.target)||ue.current&&!ue.current.contains(r.target)&&ve(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[Xe,ne]);const[_,Se]=i.useState("edit"),[bt,Le]=i.useState("edit"),[Oe,yt]=i.useState("tree"),[xe,Be]=i.useState("edit"),[fe,ke]=i.useState("preview"),[it,at]=i.useState(0),$e=i.useRef({}),We=i.useRef({}),Ue=i.useRef({}),lt=i.useRef({}),he=i.useMemo(()=>w.find(t=>t.metadata.id===N)??Lr(!1),[w,N]),we=i.useMemo(()=>w.find(t=>t.metadata.id===j)??Lr(!0),[w,j]);i.useEffect(()=>{$r(he),$r(we)},[he,we]);const jt=i.useMemo(()=>[],[]),T=ze(t=>a?t.byRoot[a]?.openPaths??jt:jt),be=ze(t=>a?t.byRoot[a]?.selectedPath??null:null),Je=ze(t=>a?t.byRoot[a]?.expandedPaths??jt:jt),Et=ze(t=>t.removeOpenPath),ot=ze(t=>t.removeOpenPathsByPrefix),Sn=ze(t=>t.removeExpandedPathsByPrefix),re=ze(t=>t.setSelectedPath),kn=ze(t=>t.toggleExpandedPath),us=ze(t=>t.expandPaths),Pt=i.useCallback(t=>{const r=O(t),l=r.split("/"),o=l[l.length-1]||r,f=o.includes(".")?o.split(".").pop()?.toLowerCase():void 0;return{name:o,path:r,type:"file",extension:f}},[]),Mt=i.useMemo(()=>T.map(Pt),[T,Pt]),Is=i.useMemo(()=>{if(be){const t=Ht(be);if(T.some(r=>Ht(r)===t))return be}return T[0]??null},[T,be]),c=i.useMemo(()=>Is?Pt(Is):null,[Is,Pt]),Ge=c?.path??"";i.useEffect(()=>{if(!a||!be)return;const t=Ht(be);T.some(l=>Ht(l)===t)||re(a,T[0]??null)},[T,a,be,re]);const fs=!!(a&&Ge&&!ds(Ge,a)),Cn=fs?Wr(Ge):void 0,J=i.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&fs,outsideFileGrant:Cn,directory:a||void 0}),[d,fs,Cn,a]),Ls=i.useRef(null),[Tn,pi]=i.useState({left:!1,right:!1}),Dn=i.useCallback(()=>{const t=Ls.current;t&&pi({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),Vn=i.useRef(Dn);Vn.current=Dn,i.useEffect(()=>{const t=Ls.current;if(!t)return;const r=()=>Vn.current();r(),t.addEventListener("scroll",r,{passive:!0});const l=new ResizeObserver(r);return l.observe(t),()=>{t.removeEventListener("scroll",r),l.disconnect()}},[Mt.length]);const[Rn,Os]=i.useState({}),[hs,Xt]=i.useState({}),Ce=i.useRef(new Set),Te=i.useRef(new Set),Ye=i.useRef(new Map),En=i.useRef(0),[Pn,ps]=i.useState([]),[mi,ms]=i.useState(!1),[D,K]=i.useState(""),{isPlaying:gs,play:gi,stop:vi}=Ta(),[Ee,Ze]=i.useState(!1),[Qe,Y]=i.useState(null),[xi,Pe]=i.useState(""),ye=i.useRef(""),[je,H]=i.useState(null),[W,Z]=i.useState(""),[At,Bs]=i.useState(!1),[Mn,wi]=i.useState(`
8
- `),bi=i.useRef(null),_e=i.useRef(null),Ne=i.useRef(null),ct=i.useRef(""),Jt=i.useRef(""),et=i.useRef(null),An=i.useRef(null),tt=i.useRef(null),vs=i.useRef(0),Yt=i.useRef(null),[yi,zt]=i.useState("idle"),[ji,xs]=i.useState(!1),[Zt,zn]=i.useState(!1),ie=me(t=>t.autoSaveEnabled),Ni=me(t=>t.setAutoSaveEnabled),[$s,It]=i.useState(!1),Lt=i.useRef(null),Qt=i.useRef(null),es=i.useRef(null),Nt=i.useRef(!1),ts=i.useRef(null),ss=i.useRef(null),Me=i.useRef(null),Fi=i.useRef(null),[Si,Ws]=i.useState(0),Ot=i.useRef(null),Ft=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{Ot.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ot.current),Ot.current=null)},[]);const[St,Us]=i.useState(null),[kt,ki]=i.useState(null),[dt,In]=i.useState(""),[Ci,Gs]=i.useState(!1),[Ti,Di]=i.useState(null),[Vi,Ri]=i.useState(null),[Ei,Ln]=i.useState(!1),[Pi,On]=i.useState(!1),[Mi,_s]=i.useState(!1),Bn=!!n.writeFile,$n=!!n.createDirectory,Wn=!!n.rename,Un=!!n.delete,Gn=!!n.revealPath,Ai=Vs(t=>t.availableApps),zi=Vs(t=>t.isCacheStale),_n=Vs(t=>t.initialize),Ii=Vs(t=>t.loadInstalledApps);i.useEffect(()=>{_n()},[_n]);const Li=i.useCallback(t=>{n.revealPath&&n.revealPath(t).catch(()=>{L.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Oi=i.useCallback(async t=>{if(!c?.path||await ga(c.path,t.id,t.appName)||await Or(c.path,t.appName))return;const o=al(c.path)||a;o&&await Or(o,t.appName)||L.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,c?.path,e]),Ks=i.useCallback((t,r)=>{Us(t),ki(r),In(t==="rename"&&r.name||""),Gs(!1)},[]),[A,Ae]=i.useState(null),Bt=i.useRef(!1),ut=i.useRef(null),[Kn,$t]=i.useState(!1),Ke=me(t=>t.setMainTabGuard),He=me(t=>t.pendingFileNavigation),ws=me(t=>t.setPendingFileNavigation),Hs=me(t=>t.pendingFileFocusPath),qs=me(t=>t.setPendingFileFocusPath),Hn=me(t=>t.shortcutOverrides),qn=me(t=>t.fileEditorKeymap),ns=Ur(t=>t.settingsDefaultFileViewerPreview),Bi=Ur(t=>t.showMessageTTSButtons),Xn=me(t=>t.expandedEditorToolbar);i.useEffect(()=>{const t=()=>{Bt.current=!1,ut.current=null,$t(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),i.useEffect(()=>()=>{ts.current!==null&&window.clearTimeout(ts.current),ss.current!==null&&window.clearTimeout(ss.current)},[]);const $i=i.useCallback((t,r)=>{const l=t.split(`
7
+ `):n},hi=(d,e)=>s.jsx(Rs,{filePath:d,extension:e}),ri=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},vl=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},xn=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},xl=d=>{const e=qt.c(76),{node:n,root:u,isExpanded:v,isActive:w,isMobile:N,isBrowserClient:j,alwaysShowActions:p,status:x,badge:m,permissions:b,downloadFile:F,contextMenuPath:k,setContextMenuPath:y,rightClickMenuPath:C,setRightClickMenuPath:a,onSelect:R,onToggle:B,onRevealPath:q,onOpenDialog:z}=d,{t:E}=zs(),P=n.type==="directory",{canRename:ce,canCreateFile:ee,canCreateFolder:te,canDelete:I,canReveal:de}=b,Ie=!P&&!!F,G=de&&!j,X=ce||ee||te||I||Ie||G;let se;e[0]!==X||e[1]!==n.path||e[2]!==a?(se=he=>{X&&(he?.preventDefault(),a(n.path))},e[0]=X,e[1]=n.path,e[2]=a,e[3]=se):se=e[3];const ge=se;let ne;e[4]!==P||e[5]!==n||e[6]!==R||e[7]!==B?(ne=()=>{P?B(n.path):R(n)},e[4]=P,e[5]=n,e[6]=R,e[7]=B,e[8]=ne):ne=e[8];const ve=ne;let ue;e[9]!==n.path||e[10]!==y||e[11]!==a?(ue=he=>{he.stopPropagation(),a(null),y(n.path)},e[9]=n.path,e[10]=y,e[11]=a,e[12]=ue):ue=e[12];const rt=ue;let Rt;e[13]!==ee||e[14]!==te||e[15]!==I||e[16]!==ce||e[17]!==G||e[18]!==F||e[19]!==j||e[20]!==P||e[21]!==n||e[22]!==z||e[23]!==q||e[24]!==u||e[25]!==E?(Rt=he=>{const{Item:we,Separator:jt}=he;return s.jsxs(s.Fragment,{children:[ce&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("rename",n)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(we,{onClick:T=>{T.stopPropagation(),As(n.path).then(be=>{if(be.ok){L.success(E("sidebarFilesTree.toast.pathCopied"));return}L.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(we,{onClick:T=>{T.stopPropagation();const be=Ps(u,n.path)||n.path;As(be).then(Je=>{if(Je.ok){L.success(E("filesView.toast.relativePathCopied"));return}L.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!P&&F&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),F(n.path).catch(be=>{console.error("Download failed:",be),L.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",E(j?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),G&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),q(n.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",E(Oa())]}),P&&(ee||te)&&s.jsxs(s.Fragment,{children:[s.jsx(jt,{}),ee&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("createFile",n)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),te&&s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("createFolder",n)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(jt,{}),s.jsxs(we,{onClick:T=>{T.stopPropagation(),z("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=ee,e[14]=te,e[15]=I,e[16]=ce,e[17]=G,e[18]=F,e[19]=j,e[20]=P,e[21]=n,e[22]=z,e[23]=q,e[24]=u,e[25]=E,e[26]=Rt):Rt=e[26];const Xe=Rt,_=C===n.path;let Se;e[27]!==n.path||e[28]!==a?(Se=he=>a(he?n.path:null),e[27]=n.path,e[28]=a,e[29]=Se):Se=e[29];const bt=N?void 0:ge;let Le;e[30]!==bt?(Le=s.jsx("div",{className:"group relative flex items-center",onContextMenu:bt}),e[30]=bt,e[31]=Le):Le=e[31];const Oe=N?void 0:ge,yt=w?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let xe;e[32]!==yt?(xe=$("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",yt),e[32]=yt,e[33]=xe):xe=e[33];let Be;e[34]!==P||e[35]!==v||e[36]!==n.extension||e[37]!==n.path?(Be=P?v?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):hi(n.path,n.extension),e[34]=P,e[35]=v,e[36]=n.extension,e[37]=n.path,e[38]=Be):Be=e[38];let fe;e[39]!==n.name||e[40]!==n.path?(fe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[39]=n.name,e[40]=n.path,e[41]=fe):fe=e[41];let ke;e[42]!==P||e[43]!==x?(ke=!P&&x&&s.jsx(ul,{status:x}),e[42]=P,e[43]=x,e[44]=ke):ke=e[44];let it;e[45]!==m||e[46]!==P?(it=P&&m&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[45]=m,e[46]=P,e[47]=it):it=e[47];let at;e[48]!==ve||e[49]!==xe||e[50]!==Be||e[51]!==fe||e[52]!==ke||e[53]!==it||e[54]!==Oe?(at=s.jsxs("button",{type:"button",onClick:ve,onContextMenu:Oe,className:xe,children:[Be,fe,ke,it]}),e[48]=ve,e[49]=xe,e[50]=Be,e[51]=fe,e[52]=ke,e[53]=it,e[54]=Oe,e[55]=at):at=e[55];let $e;e[56]!==p||e[57]!==k||e[58]!==rt||e[59]!==X||e[60]!==N||e[61]!==n.path||e[62]!==Xe||e[63]!==y?($e=X&&s.jsx("div",{className:$("absolute right-1 top-1/2 -translate-y-1/2",p?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(jn,{open:k===n.path,onOpenChange:he=>y(he?n.path:null),children:[s.jsx(Nn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"icon",className:"size-6",onClick:rt,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Fn,{align:"end",side:"bottom",onCloseAutoFocus:()=>y(null),children:Xe({Item:Es,Separator:La})})]})}),e[56]=p,e[57]=k,e[58]=rt,e[59]=X,e[60]=N,e[61]=n.path,e[62]=Xe,e[63]=y,e[64]=$e):$e=e[64];let We;e[65]!==at||e[66]!==$e||e[67]!==Le?(We=s.jsxs(Ka,{render:Le,children:[at,$e]}),e[65]=at,e[66]=$e,e[67]=Le,e[68]=We):We=e[68];let Ue;e[69]!==Xe?(Ue=s.jsx(Ga,{className:"min-w-[180px]",children:Xe({Item:Ha,Separator:_a})}),e[69]=Xe,e[70]=Ue):Ue=e[70];let lt;return e[71]!==We||e[72]!==Ue||e[73]!==_||e[74]!==Se?(lt=s.jsxs(qa,{open:_,onOpenChange:Se,children:[We,Ue]}),e[71]=We,e[72]=Ue,e[73]=_,e[74]=Se,e[75]=lt):lt=e[75],lt},wl=d=>{const e=qt.c(83),{activeDialog:n,dialogData:u,dialogInputValue:v,onDialogInputChange:w,isDialogSubmitting:N,onDialogSubmit:j,onClose:p,inputRef:x}=d,{t:m}=zs(),b=!!n;let F;e[0]!==p?(F=ue=>!ue&&p(),e[0]=p,e[1]=F):F=e[1];let k;e[2]!==n||e[3]!==m?(k=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=k):k=e[4];let y;e[5]!==n||e[6]!==m?(y=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=y):y=e[7];let C;e[8]!==n||e[9]!==m?(C=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=C):C=e[10];let a;e[11]!==n||e[12]!==m?(a=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=a):a=e[13];let R;e[14]!==k||e[15]!==y||e[16]!==C||e[17]!==a?(R=s.jsxs(ci,{children:[k,y,C,a]}),e[14]=k,e[15]=y,e[16]=C,e[17]=a,e[18]=R):R=e[18];let B;e[19]!==n||e[20]!==u?.path||e[21]!==m?(B=n==="createFile"&&m("filesView.dialog.createFile.description",{path:u?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=u?.path,e[21]=m,e[22]=B):B=e[22];let q;e[23]!==n||e[24]!==u?.path||e[25]!==m?(q=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:u?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=u?.path,e[25]=m,e[26]=q):q=e[26];let z;e[27]!==n||e[28]!==u?.name||e[29]!==m?(z=n==="rename"&&m("filesView.dialog.rename.description",{name:u?.name??""}),e[27]=n,e[28]=u?.name,e[29]=m,e[30]=z):z=e[30];let E;e[31]!==n||e[32]!==u?.name||e[33]!==m?(E=n==="delete"&&m("filesView.dialog.delete.description",{name:u?.name??""}),e[31]=n,e[32]=u?.name,e[33]=m,e[34]=E):E=e[34];let P;e[35]!==z||e[36]!==E||e[37]!==B||e[38]!==q?(P=s.jsxs(di,{children:[B,q,z,E]}),e[35]=z,e[36]=E,e[37]=B,e[38]=q,e[39]=P):P=e[39];let ce;e[40]!==P||e[41]!==R?(ce=s.jsxs(oi,{children:[R,P]}),e[40]=P,e[41]=R,e[42]=ce):ce=e[42];let ee;e[43]!==n||e[44]!==v||e[45]!==x||e[46]!==w||e[47]!==j||e[48]!==m?(ee=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ms,{value:v,onChange:ue=>w(ue.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:ue=>{ue.key==="Enter"&&j()},ref:x})}),e[43]=n,e[44]=v,e[45]=x,e[46]=w,e[47]=j,e[48]=m,e[49]=ee):ee=e[49];let te;e[50]!==m?(te=m("filesView.dialog.cancel"),e[50]=m,e[51]=te):te=e[51];let I;e[52]!==N||e[53]!==p||e[54]!==te?(I=s.jsx(V,{variant:"outline",onClick:p,disabled:N,children:te}),e[52]=N,e[53]=p,e[54]=te,e[55]=I):I=e[55];const de=n==="delete"?"destructive":"default";let Ie;e[56]!==j?(Ie=()=>{j()},e[56]=j,e[57]=Ie):Ie=e[57];let G;e[58]!==n||e[59]!==v||e[60]!==N?(G=N||n!=="delete"&&!v.trim(),e[58]=n,e[59]=v,e[60]=N,e[61]=G):G=e[61];let X;e[62]!==n||e[63]!==N||e[64]!==m?(X=N?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=N,e[64]=m,e[65]=X):X=e[65];let se;e[66]!==de||e[67]!==Ie||e[68]!==G||e[69]!==X?(se=s.jsx(V,{variant:de,onClick:Ie,disabled:G,children:X}),e[66]=de,e[67]=Ie,e[68]=G,e[69]=X,e[70]=se):se=e[70];let ge;e[71]!==I||e[72]!==se?(ge=s.jsxs(ui,{children:[I,se]}),e[71]=I,e[72]=se,e[73]=ge):ge=e[73];let ne;e[74]!==x||e[75]!==ce||e[76]!==ee||e[77]!==ge?(ne=s.jsxs(li,{initialFocus:x,children:[ce,ee,ge]}),e[74]=x,e[75]=ce,e[76]=ee,e[77]=ge,e[78]=ne):ne=e[78];let ve;return e[79]!==b||e[80]!==F||e[81]!==ne?(ve=s.jsx(ai,{open:b,onOpenChange:F,children:ne}),e[79]=b,e[80]=F,e[81]=ne,e[82]=ve):ve=e[82],ve},wn=(d,e,n)=>{const u=qt.c(8),[v,w]=i.useState(""),[N,j]=i.useState(0);let p,x;u[0]!==d||u[1]!==n||u[2]!==e?(p=()=>{if(!d){w("");return}let b=!1;w("");const F=xa(),k=wa(F);ba(F).then(C=>{b||!C||(w(d),e(null))}).catch(C=>{b||(e(C instanceof Error?C.message:n),w(d))});const y=ya(()=>{b||(w(d),j(yl),e(null))});return()=>{b=!0,k(),y()}},x=[d,e,n],u[0]=d,u[1]=n,u[2]=e,u[3]=p,u[4]=x):(p=u[3],x=u[4]),i.useEffect(p,x);let m;return u[5]!==N||u[6]!==v?(m={readyKey:v,nonce:N},u[5]=N,u[6]=v,u[7]=m):m=u[7],m},bl=({mode:d="full"})=>{const{t:e}=zs(),{files:n,runtime:u}=ja(),{currentTheme:v,availableThemes:w,lightThemeId:N,darkThemeId:j}=Na(),{isMobile:p,isTablet:x,screenWidth:m}=Fa(),b=fa(u.platform),F=p||x,k=ha(),y=pa(),C=Sa()??"",a=O(C.trim()),R=d!=="editor-only",B=d==="editor-only"&&!p,q=ma(t=>t.searchFiles),z=ka(C),[E,P]=i.useState(""),ce=Ca(E,200),ee=i.useRef(null),[te,I]=i.useState(!1),[de,Ie]=i.useState(!0),[G,X]=i.useState(!1),[se,ge]=i.useState(!1),[ne,ve]=i.useState(!1),ue=i.useRef(null),rt=i.useRef(0),Rt=i.useCallback(t=>{rt.current=Math.max(0,rt.current+(t?1:-1))},[]),Xe=i.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);i.useEffect(()=>{if(!ne)return;const t=r=>{rt.current>0||Xe(r.target)||ue.current&&!ue.current.contains(r.target)&&ve(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[Xe,ne]);const[_,Se]=i.useState("edit"),[bt,Le]=i.useState("edit"),[Oe,yt]=i.useState("tree"),[xe,Be]=i.useState("edit"),[fe,ke]=i.useState("preview"),[it,at]=i.useState(0),$e=i.useRef({}),We=i.useRef({}),Ue=i.useRef({}),lt=i.useRef({}),he=i.useMemo(()=>w.find(t=>t.metadata.id===N)??Lr(!1),[w,N]),we=i.useMemo(()=>w.find(t=>t.metadata.id===j)??Lr(!0),[w,j]);i.useEffect(()=>{$r(he),$r(we)},[he,we]);const jt=i.useMemo(()=>[],[]),T=ze(t=>a?t.byRoot[a]?.openPaths??jt:jt),be=ze(t=>a?t.byRoot[a]?.selectedPath??null:null),Je=ze(t=>a?t.byRoot[a]?.expandedPaths??jt:jt),Et=ze(t=>t.removeOpenPath),ot=ze(t=>t.removeOpenPathsByPrefix),Sn=ze(t=>t.removeExpandedPathsByPrefix),re=ze(t=>t.setSelectedPath),kn=ze(t=>t.toggleExpandedPath),us=ze(t=>t.expandPaths),Pt=i.useCallback(t=>{const r=O(t),l=r.split("/"),o=l[l.length-1]||r,f=o.includes(".")?o.split(".").pop()?.toLowerCase():void 0;return{name:o,path:r,type:"file",extension:f}},[]),Mt=i.useMemo(()=>T.map(Pt),[T,Pt]),Is=i.useMemo(()=>{if(be){const t=Kt(be);if(T.some(r=>Kt(r)===t))return be}return T[0]??null},[T,be]),c=i.useMemo(()=>Is?Pt(Is):null,[Is,Pt]),Ge=c?.path??"";i.useEffect(()=>{if(!a||!be)return;const t=Kt(be);T.some(l=>Kt(l)===t)||re(a,T[0]??null)},[T,a,be,re]);const fs=!!(a&&Ge&&!ds(Ge,a)),Cn=fs?Wr(Ge):void 0,J=i.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&fs,outsideFileGrant:Cn,directory:a||void 0}),[d,fs,Cn,a]),Ls=i.useRef(null),[Tn,pi]=i.useState({left:!1,right:!1}),Dn=i.useCallback(()=>{const t=Ls.current;t&&pi({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),Vn=i.useRef(Dn);Vn.current=Dn,i.useEffect(()=>{const t=Ls.current;if(!t)return;const r=()=>Vn.current();r(),t.addEventListener("scroll",r,{passive:!0});const l=new ResizeObserver(r);return l.observe(t),()=>{t.removeEventListener("scroll",r),l.disconnect()}},[Mt.length]);const[Rn,Os]=i.useState({}),[hs,Xt]=i.useState({}),Ce=i.useRef(new Set),Te=i.useRef(new Set),Ye=i.useRef(new Map),En=i.useRef(0),[Pn,ps]=i.useState([]),[mi,ms]=i.useState(!1),[D,H]=i.useState(""),{isPlaying:gs,play:gi,stop:vi}=Ta(),[Ee,Ze]=i.useState(!1),[Qe,Y]=i.useState(null),[xi,Pe]=i.useState(""),ye=i.useRef(""),[je,K]=i.useState(null),[W,Z]=i.useState(""),[At,Bs]=i.useState(!1),[Mn,wi]=i.useState(`
8
+ `),bi=i.useRef(null),_e=i.useRef(null),Ne=i.useRef(null),ct=i.useRef(""),Jt=i.useRef(""),et=i.useRef(null),An=i.useRef(null),tt=i.useRef(null),vs=i.useRef(0),Yt=i.useRef(null),[yi,zt]=i.useState("idle"),[ji,xs]=i.useState(!1),[Zt,zn]=i.useState(!1),ie=me(t=>t.autoSaveEnabled),Ni=me(t=>t.setAutoSaveEnabled),[$s,It]=i.useState(!1),Lt=i.useRef(null),Qt=i.useRef(null),es=i.useRef(null),Nt=i.useRef(!1),ts=i.useRef(null),ss=i.useRef(null),Me=i.useRef(null),Fi=i.useRef(null),[Si,Ws]=i.useState(0),Ot=i.useRef(null),Ft=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{Ot.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ot.current),Ot.current=null)},[]);const[St,Us]=i.useState(null),[kt,ki]=i.useState(null),[dt,In]=i.useState(""),[Ci,Gs]=i.useState(!1),[Ti,Di]=i.useState(null),[Vi,Ri]=i.useState(null),[Ei,Ln]=i.useState(!1),[Pi,On]=i.useState(!1),[Mi,_s]=i.useState(!1),Bn=!!n.writeFile,$n=!!n.createDirectory,Wn=!!n.rename,Un=!!n.delete,Gn=!!n.revealPath,Ai=Vs(t=>t.availableApps),zi=Vs(t=>t.isCacheStale),_n=Vs(t=>t.initialize),Ii=Vs(t=>t.loadInstalledApps);i.useEffect(()=>{_n()},[_n]);const Li=i.useCallback(t=>{n.revealPath&&n.revealPath(t).catch(()=>{L.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Oi=i.useCallback(async t=>{if(!c?.path||await ga(c.path,t.id,t.appName)||await Or(c.path,t.appName))return;const o=al(c.path)||a;o&&await Or(o,t.appName)||L.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,c?.path,e]),Hs=i.useCallback((t,r)=>{Us(t),ki(r),In(t==="rename"&&r.name||""),Gs(!1)},[]),[A,Ae]=i.useState(null),Bt=i.useRef(!1),ut=i.useRef(null),[Hn,$t]=i.useState(!1),He=me(t=>t.setMainTabGuard),Ke=me(t=>t.pendingFileNavigation),ws=me(t=>t.setPendingFileNavigation),Ks=me(t=>t.pendingFileFocusPath),qs=me(t=>t.setPendingFileFocusPath),Kn=me(t=>t.shortcutOverrides),qn=me(t=>t.fileEditorKeymap),ns=Ur(t=>t.settingsDefaultFileViewerPreview),Bi=Ur(t=>t.showMessageTTSButtons),Xn=me(t=>t.expandedEditorToolbar);i.useEffect(()=>{const t=()=>{Bt.current=!1,ut.current=null,$t(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),i.useEffect(()=>()=>{ts.current!==null&&window.clearTimeout(ts.current),ss.current!==null&&window.clearTimeout(ss.current)},[]);const $i=i.useCallback((t,r)=>{const l=t.split(`
9
9
  `),o=Math.max(1,r.start),f=Math.min(l.length,r.end);return o>f?"":l.slice(o-1,f).join(`
10
- `)},[]),Wi=Ba({source:"file",fileLabel:c?.path??null,language:c?.path&&dn(c.path)||"text",getCodeForRange:t=>$i(D,$a(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Jn,commentText:bs,setCommentText:Yn,editingDraftId:ys,setSelection:Zn,saveComment:Qn,cancel:rs,reset:er,startEdit:tr,deleteDraft:sr}=Wi;i.useEffect(()=>{Ae(null),er(),Ke(null),Z(""),Bs(!1)},[c?.path,er,Ke]),i.useEffect(()=>{Zn(A)},[A,Zn]),i.useEffect(()=>{if(!A&&!ys)return;const t=l=>{const o=l.target;o.closest('[data-comment-input="true"]')||o.closest('[data-comment-card="true"]')||o.closest(".cm-gutterElement")||o.closest("[data-sonner-toast]")||o.closest("[data-sonner-toaster]")||bs.trim()||(Ae(null),rs())},r=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(r),document.removeEventListener("click",t)}},[rs,bs,ys,A]);const nr=i.useCallback((t,r)=>{const l=r??A??void 0;r&&Ae(r),Qn(t,l),Ae(null)},[A,Qn]),rr=i.useCallback((t,r)=>{const l=[];for(const o of r){if(!(o&&typeof o.name=="string"&&o.name.length>0)||!k&&o.name.startsWith(".")||!y&&fl(o.name))continue;const f=o.name,h=O(o.path||""),S=h?cl(h)?h:O(`${t}/${h}`):O(`${t}/${f}`),M=o.isDirectory?"directory":"file",U=M==="file"&&f.includes(".")?f.split(".").pop()?.toLowerCase():void 0;l.push({name:f,path:S,type:M,extension:U})}return ol(l)},[y,k]),De=i.useCallback(async t=>{const r=O(t.trim());if(!r||Ce.current.has(r)||Te.current.has(r))return;Te.current=new Set(Te.current),Te.current.add(r);const l=En.current+1;En.current=l,Ye.current=new Map(Ye.current),Ye.current.set(r,l);const o=()=>Ye.current.get(r)===l;await(n.listDirectory?n.listDirectory(r).then(h=>h.entries.map(S=>({name:S.name,path:S.path,isDirectory:S.isDirectory}))):va.listLocalDirectory(r).then(h=>h.map(S=>({name:S.name,path:S.path,isDirectory:S.isDirectory})))).then(h=>{if(!o())return;const S=rr(r,h);Ce.current=new Set(Ce.current),Ce.current.add(r),Xt(M=>{if(!M[r])return M;const U={...M};return delete U[r],U}),Os(M=>({...M,[r]:S}))}).catch(h=>{if(!o())return;const S=h instanceof Error?h.message:String(h??"");if(S==="Directory not found"&&a&&r!==a){Sn(a,r),Xt(M=>{if(!M[r])return M;const U={...M};return delete U[r],U});return}console.error("Failed to load files directory:",h),Xt(M=>({...M,[r]:S}))}).finally(()=>{o()&&(Ye.current=new Map(Ye.current),Ye.current.delete(r),Te.current=new Set(Te.current),Te.current.delete(r))})},[n,rr,Sn,a]),js=i.useCallback(async()=>{a&&(Ce.current=new Set,Te.current=new Set,Ye.current=new Map,Xt({}),Os(t=>Object.keys(t).length===0?t:{}),await De(a))},[De,a]),qe=i.useCallback(async t=>{if(!t){await js();return}const r=O(t);Ce.current=new Set(Ce.current),Ce.current.delete(r),Te.current=new Set(Te.current),Te.current.delete(r),await De(r)},[De,js]),ir=i.useRef(""),ar=i.useRef("");i.useEffect(()=>{if(!a)return;const t=`${a}|h${k?"1":"0"}|g${y?"1":"0"}`,r=ir.current!==a,l=ar.current!==t;!r&&!l||(r&&(ir.current=a,K(""),Y(null),Pe(""),H(null),I(!1)),l&&(ar.current=t,Ce.current=new Set,Te.current=new Set,Ye.current=new Map,Xt({}),Os(o=>Object.keys(o).length===0?o:{}),De(a)))},[De,a,y,k]),i.useEffect(()=>{if(!n.listDirectory)return;const t=()=>{if(!document.hidden&&Je.length>0)for(const r of Je)qe(r)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Je,n.listDirectory,qe]),i.useEffect(()=>{if(!n.listDirectory||Je.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const r of Je)qe(r)},8e3);return()=>clearInterval(t)},[Je,n.listDirectory,qe]);const Ui=i.useCallback(async t=>{if(t?.preventDefault(),!kt||!St)return;Gs(!0);const r=()=>{Us(null)},l=f=>{L.error(f)},o=()=>{Gs(!1)};if(St==="createFile"){if(!dt.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),o();return}if(!n.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),o();return}const f=kt.path,h=f?`${f}/`:"",S=O(`${h}${dt.trim()}`);await n.writeFile(S,"").then(async M=>{M.success&&(L.success(e("sidebarFilesTree.toast.fileCreated")),await qe(f)),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="createFolder"){if(!dt.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),o();return}const f=kt.path,h=f?`${f}/`:"",S=O(`${h}${dt.trim()}`);await n.createDirectory(S).then(async M=>{M.success&&(L.success(e("sidebarFilesTree.toast.folderCreated")),await qe(f)),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="rename"){if(!dt.trim()){l(e("sidebarFilesTree.toast.nameRequired")),o();return}if(!n.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),o();return}const f=kt.path,h=f.split("/").slice(0,-1).join("/"),S=h?`${h}/`:"",M=O(`${S}${dt.trim()}`);await n.rename(f,M).then(async U=>{U.success&&(L.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await qe(h),a&&ot(a,f),(c?.path===f||c?.path.startsWith(`${f}/`))&&(a&&re(a,null),K(""),Y(null),Pe(""),H(null),p&&I(!1))),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="delete"){if(!n.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),o();return}const f=kt.path,h=f.split("/").slice(0,-1).join("/");await n.delete(f).then(async S=>{S.success&&(L.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await qe(h),a&&ot(a,f),(c?.path===f||c?.path.startsWith(`${f}/`))&&(a&&re(a,null),K(""),Y(null),Pe(""),H(null),p&&I(!1))),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}o()},[St,kt,dt,n,qe,p,ot,a,c?.path,re,e]);i.useEffect(()=>{if(!C){ps([]),ms(!1);return}const t=ce.trim();if(!t){ps([]),ms(!1);return}let r=!1;return ms(!0),q(C,t,150,{includeHidden:k,respectGitignore:!y,type:"file"}).then(l=>{if(r)return;const f=l.filter(h=>y||!hl(h.path)).map(h=>({name:h.name,path:O(h.path),type:"file",extension:h.extension,relativePath:h.relativePath}));ps(f)}).catch(()=>{r||ps([])}).finally(()=>{r||ms(!1)}),()=>{r=!0}},[C,ce,q,k,y]);const lr=i.useCallback(async(t,r)=>{if(n.readFile)return(await n.readFile(t,{...r??{},directory:a||void 0})).content??"";const l=new URLSearchParams({path:t});r?.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),r?.outsideFileGrant&&l.set("outsideFileGrant",r.outsideFileGrant),r?.optional&&l.set("optional","true"),a&&l.set("directory",a);const o=await Br(`/api/fs/read?${l.toString()}`,{cache:r?.optional?"no-store":"default"});if(!o.ok){const f=await o.json().catch(()=>({error:o.statusText}));throw new Error(f.error||e("filesView.error.readFileFailed"))}return o.text()},[n,a,e]),ft=i.useCallback(async(t,r)=>{if(n.statFile){const l=await n.statFile(t,{...r??{},directory:a||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[n,a]);i.useEffect(()=>{if(!a||!n.statFile||T.length===0)return;let t=!1;const r=[...T];return Promise.all(r.map(async l=>{try{const o=await n.statFile?.(l,{directory:a||void 0});!t&&o&&!o.isFile&&ot(a,l)}catch(o){!t&&ni(o)&&ot(a,l)}})),()=>{t=!0}},[n,T,ot,a]);const Xs=i.useMemo(()=>D.length>ls?`${D.slice(0,ls)}
10
+ `)},[]),Wi=Ba({source:"file",fileLabel:c?.path??null,language:c?.path&&dn(c.path)||"text",getCodeForRange:t=>$i(D,$a(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Jn,commentText:bs,setCommentText:Yn,editingDraftId:ys,setSelection:Zn,saveComment:Qn,cancel:rs,reset:er,startEdit:tr,deleteDraft:sr}=Wi;i.useEffect(()=>{Ae(null),er(),He(null),Z(""),Bs(!1)},[c?.path,er,He]),i.useEffect(()=>{Zn(A)},[A,Zn]),i.useEffect(()=>{if(!A&&!ys)return;const t=l=>{const o=l.target;o.closest('[data-comment-input="true"]')||o.closest('[data-comment-card="true"]')||o.closest(".cm-gutterElement")||o.closest("[data-sonner-toast]")||o.closest("[data-sonner-toaster]")||bs.trim()||(Ae(null),rs())},r=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(r),document.removeEventListener("click",t)}},[rs,bs,ys,A]);const nr=i.useCallback((t,r)=>{const l=r??A??void 0;r&&Ae(r),Qn(t,l),Ae(null)},[A,Qn]),rr=i.useCallback((t,r)=>{const l=[];for(const o of r){if(!(o&&typeof o.name=="string"&&o.name.length>0)||!k&&o.name.startsWith(".")||!y&&fl(o.name))continue;const f=o.name,h=O(o.path||""),S=h?cl(h)?h:O(`${t}/${h}`):O(`${t}/${f}`),M=o.isDirectory?"directory":"file",U=M==="file"&&f.includes(".")?f.split(".").pop()?.toLowerCase():void 0;l.push({name:f,path:S,type:M,extension:U})}return ol(l)},[y,k]),De=i.useCallback(async t=>{const r=O(t.trim());if(!r||Ce.current.has(r)||Te.current.has(r))return;Te.current=new Set(Te.current),Te.current.add(r);const l=En.current+1;En.current=l,Ye.current=new Map(Ye.current),Ye.current.set(r,l);const o=()=>Ye.current.get(r)===l;await(n.listDirectory?n.listDirectory(r).then(h=>h.entries.map(S=>({name:S.name,path:S.path,isDirectory:S.isDirectory}))):va.listLocalDirectory(r).then(h=>h.map(S=>({name:S.name,path:S.path,isDirectory:S.isDirectory})))).then(h=>{if(!o())return;const S=rr(r,h);Ce.current=new Set(Ce.current),Ce.current.add(r),Xt(M=>{if(!M[r])return M;const U={...M};return delete U[r],U}),Os(M=>({...M,[r]:S}))}).catch(h=>{if(!o())return;const S=h instanceof Error?h.message:String(h??"");if(S==="Directory not found"&&a&&r!==a){Sn(a,r),Xt(M=>{if(!M[r])return M;const U={...M};return delete U[r],U});return}console.error("Failed to load files directory:",h),Xt(M=>({...M,[r]:S}))}).finally(()=>{o()&&(Ye.current=new Map(Ye.current),Ye.current.delete(r),Te.current=new Set(Te.current),Te.current.delete(r))})},[n,rr,Sn,a]),js=i.useCallback(async()=>{a&&(Ce.current=new Set,Te.current=new Set,Ye.current=new Map,Xt({}),Os(t=>Object.keys(t).length===0?t:{}),await De(a))},[De,a]),qe=i.useCallback(async t=>{if(!t){await js();return}const r=O(t);Ce.current=new Set(Ce.current),Ce.current.delete(r),Te.current=new Set(Te.current),Te.current.delete(r),await De(r)},[De,js]),ir=i.useRef(""),ar=i.useRef("");i.useEffect(()=>{if(!a)return;const t=`${a}|h${k?"1":"0"}|g${y?"1":"0"}`,r=ir.current!==a,l=ar.current!==t;!r&&!l||(r&&(ir.current=a,H(""),Y(null),Pe(""),K(null),I(!1)),l&&(ar.current=t,Ce.current=new Set,Te.current=new Set,Ye.current=new Map,Xt({}),Os(o=>Object.keys(o).length===0?o:{}),De(a)))},[De,a,y,k]),i.useEffect(()=>{if(!n.listDirectory)return;const t=()=>{if(!document.hidden&&Je.length>0)for(const r of Je)qe(r)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Je,n.listDirectory,qe]),i.useEffect(()=>{if(!n.listDirectory||Je.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const r of Je)qe(r)},8e3);return()=>clearInterval(t)},[Je,n.listDirectory,qe]);const Ui=i.useCallback(async t=>{if(t?.preventDefault(),!kt||!St)return;Gs(!0);const r=()=>{Us(null)},l=f=>{L.error(f)},o=()=>{Gs(!1)};if(St==="createFile"){if(!dt.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),o();return}if(!n.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),o();return}const f=kt.path,h=f?`${f}/`:"",S=O(`${h}${dt.trim()}`);await n.writeFile(S,"").then(async M=>{M.success&&(L.success(e("sidebarFilesTree.toast.fileCreated")),await qe(f)),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="createFolder"){if(!dt.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),o();return}const f=kt.path,h=f?`${f}/`:"",S=O(`${h}${dt.trim()}`);await n.createDirectory(S).then(async M=>{M.success&&(L.success(e("sidebarFilesTree.toast.folderCreated")),await qe(f)),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="rename"){if(!dt.trim()){l(e("sidebarFilesTree.toast.nameRequired")),o();return}if(!n.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),o();return}const f=kt.path,h=f.split("/").slice(0,-1).join("/"),S=h?`${h}/`:"",M=O(`${S}${dt.trim()}`);await n.rename(f,M).then(async U=>{U.success&&(L.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await qe(h),a&&ot(a,f),(c?.path===f||c?.path.startsWith(`${f}/`))&&(a&&re(a,null),H(""),Y(null),Pe(""),K(null),p&&I(!1))),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}if(St==="delete"){if(!n.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),o();return}const f=kt.path,h=f.split("/").slice(0,-1).join("/");await n.delete(f).then(async S=>{S.success&&(L.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await qe(h),a&&ot(a,f),(c?.path===f||c?.path.startsWith(`${f}/`))&&(a&&re(a,null),H(""),Y(null),Pe(""),K(null),p&&I(!1))),r()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(o);return}o()},[St,kt,dt,n,qe,p,ot,a,c?.path,re,e]);i.useEffect(()=>{if(!C){ps([]),ms(!1);return}const t=ce.trim();if(!t){ps([]),ms(!1);return}let r=!1;return ms(!0),q(C,t,150,{includeHidden:k,respectGitignore:!y,type:"file"}).then(l=>{if(r)return;const f=l.filter(h=>y||!hl(h.path)).map(h=>({name:h.name,path:O(h.path),type:"file",extension:h.extension,relativePath:h.relativePath}));ps(f)}).catch(()=>{r||ps([])}).finally(()=>{r||ms(!1)}),()=>{r=!0}},[C,ce,q,k,y]);const lr=i.useCallback(async(t,r)=>{if(n.readFile)return(await n.readFile(t,{...r??{},directory:a||void 0})).content??"";const l=new URLSearchParams({path:t});r?.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),r?.outsideFileGrant&&l.set("outsideFileGrant",r.outsideFileGrant),r?.optional&&l.set("optional","true"),a&&l.set("directory",a);const o=await Br(`/api/fs/read?${l.toString()}`,{cache:r?.optional?"no-store":"default"});if(!o.ok){const f=await o.json().catch(()=>({error:o.statusText}));throw new Error(f.error||e("filesView.error.readFileFailed"))}return o.text()},[n,a,e]),ft=i.useCallback(async(t,r)=>{if(n.statFile){const l=await n.statFile(t,{...r??{},directory:a||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[n,a]);i.useEffect(()=>{if(!a||!n.statFile||T.length===0)return;let t=!1;const r=[...T];return Promise.all(r.map(async l=>{try{const o=await n.statFile?.(l,{directory:a||void 0});!t&&o&&!o.isFile&&ot(a,l)}catch(o){!t&&ni(o)&&ot(a,l)}})),()=>{t=!0}},[n,T,ot,a]);const Xs=i.useMemo(()=>D.length>ls?`${D.slice(0,ls)}
11
11
 
12
- … truncated …`:D,[D]),ae=W!==Xs,Ct=i.useCallback(async()=>{if(!c||!n.writeFile)return L.error(e("filesView.toast.savingNotSupported")),!1;const t=Ds(c.path)||Zt;if(!nl({selectedFilePath:c.path,loadedFilePath:je,fileLoading:Ee,isDirty:ae,draftContent:W,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):W===""&&D!==""&&je!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${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(!ae)return!0;Bs(!0);try{const r=gl(W,Mn);if(!(await n.writeFile(c.path,r))?.success)return L.error(e("filesView.toast.writeFileFailed")),!1;if(K(W),a&&ds(c.path,a)){const o=Ps(a,c.path);o&&Da.requestGitRefresh({directory:a,paths:[o]})}return c?.path&&un(c.path)&&(ct.current=W,Jt.current=W),ft(c.path).then(o=>{o&&(tt.current=o)}).catch(()=>{}),!0}catch(r){return L.error(r instanceof Error?r.message:e("filesView.toast.saveFailed")),!1}finally{Bs(!1)}},[Zt,W,D,Ee,n,ae,Mn,je,ft,a,c,e]);i.useEffect(()=>{if(!ae){Ke(null);return}const t=r=>Nt.current?(Nt.current=!1,!0):(It(!0),Qt.current=r,!1);return Ke(t),()=>{me.getState().mainTabGuard===t&&Ke(null)}},[ae,Ke]),i.useEffect(()=>{ie||(zt("idle"),_e.current&&(clearTimeout(_e.current),_e.current=null))},[ie]);const or=1500;i.useEffect(()=>{const t=!!(c&&n.writeFile),r=!!(c?.path&&(Ds(c.path)||Zt));if(sl({autoSaveEnabled:ie,isDirty:ae,canWrite:t,isSaving:At,fileLoading:Ee,selectedFilePath:c?.path,loadedFilePath:je,isNonEditableBinary:r}))return _e.current=setTimeout(()=>{Ct().then(l=>{l&&(zt("saved"),setTimeout(()=>zt("idle"),2e3))})},or),()=>{_e.current&&(clearTimeout(_e.current),_e.current=null)}},[ie,Zt,W,Ee,ae,je,c,n.writeFile,At,Ct]),i.useEffect(()=>{zt("idle")},[c?.path]),i.useEffect(()=>{const t=r=>{za(r)&&(r.key.toLowerCase()==="s"?(r.preventDefault(),_e.current&&(clearTimeout(_e.current),_e.current=null),At||Ct().then(l=>{l&&(zt("saved"),setTimeout(()=>zt("idle"),2e3))})):r.key.toLowerCase()==="f"&&(r.preventDefault(),ge(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[At,Ct]);const cr=i.useCallback(async t=>{const r=vs.current+1;vs.current=r;const l=()=>{if(!a)return!1;const Fe=ze.getState().byRoot[a],oe=Fe?.selectedPath??Fe?.openPaths[0]??null;return vs.current===r&&oe===t.path};Y(null),Pe(""),H(null),zn(!1);const o=Gr(t.path),f=_r(t.path),h=Kr(t.path),S=Ds(t.path);if(p&&I(!0),u.isDesktop&&o&&!f){K(""),Z(""),Ze(!0);return}if(!u.isDesktop&&o&&!f){K(""),Z(""),H(t.path),Ze(!1);return}if(h){K(""),Z(""),H(t.path),Ze(!1);return}if(S){K(""),Z(""),H(t.path),Ze(!1);return}Ze(!0);const M=Wr(t.path),U={allowOutsideWorkspace:d==="editor-only"&&!!a&&!ds(t.path,a),outsideFileGrant:M};await lr(t.path,U).then(Fe=>{if(!l())return;if(Va(Fe)){zn(!0),K(""),Z(""),H(t.path);return}const oe=fi(Fe);wi(ml(Fe)),K(oe),ct.current=oe,Jt.current=oe,Z(oe.length>ls?`${oe.slice(0,ls)}
12
+ … truncated …`:D,[D]),ae=W!==Xs,Ct=i.useCallback(async()=>{if(!c||!n.writeFile)return L.error(e("filesView.toast.savingNotSupported")),!1;const t=Ds(c.path)||Zt;if(!nl({selectedFilePath:c.path,loadedFilePath:je,fileLoading:Ee,isDirty:ae,draftContent:W,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):W===""&&D!==""&&je!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${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(!ae)return!0;Bs(!0);try{const r=gl(W,Mn);if(!(await n.writeFile(c.path,r))?.success)return L.error(e("filesView.toast.writeFileFailed")),!1;if(H(W),a&&ds(c.path,a)){const o=Ps(a,c.path);o&&Da.requestGitRefresh({directory:a,paths:[o]})}return c?.path&&un(c.path)&&(ct.current=W,Jt.current=W),ft(c.path).then(o=>{o&&(tt.current=o)}).catch(()=>{}),!0}catch(r){return L.error(r instanceof Error?r.message:e("filesView.toast.saveFailed")),!1}finally{Bs(!1)}},[Zt,W,D,Ee,n,ae,Mn,je,ft,a,c,e]);i.useEffect(()=>{if(!ae){He(null);return}const t=r=>Nt.current?(Nt.current=!1,!0):(It(!0),Qt.current=r,!1);return He(t),()=>{me.getState().mainTabGuard===t&&He(null)}},[ae,He]),i.useEffect(()=>{ie||(zt("idle"),_e.current&&(clearTimeout(_e.current),_e.current=null))},[ie]);const or=1500;i.useEffect(()=>{const t=!!(c&&n.writeFile),r=!!(c?.path&&(Ds(c.path)||Zt));if(sl({autoSaveEnabled:ie,isDirty:ae,canWrite:t,isSaving:At,fileLoading:Ee,selectedFilePath:c?.path,loadedFilePath:je,isNonEditableBinary:r}))return _e.current=setTimeout(()=>{Ct().then(l=>{l&&(zt("saved"),setTimeout(()=>zt("idle"),2e3))})},or),()=>{_e.current&&(clearTimeout(_e.current),_e.current=null)}},[ie,Zt,W,Ee,ae,je,c,n.writeFile,At,Ct]),i.useEffect(()=>{zt("idle")},[c?.path]),i.useEffect(()=>{const t=r=>{za(r)&&(r.key.toLowerCase()==="s"?(r.preventDefault(),_e.current&&(clearTimeout(_e.current),_e.current=null),At||Ct().then(l=>{l&&(zt("saved"),setTimeout(()=>zt("idle"),2e3))})):r.key.toLowerCase()==="f"&&(r.preventDefault(),ge(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[At,Ct]);const cr=i.useCallback(async t=>{const r=vs.current+1;vs.current=r;const l=()=>{if(!a)return!1;const Fe=ze.getState().byRoot[a],oe=Fe?.selectedPath??Fe?.openPaths[0]??null;return vs.current===r&&oe===t.path};Y(null),Pe(""),K(null),zn(!1);const o=Gr(t.path),f=_r(t.path),h=Hr(t.path),S=Ds(t.path);if(p&&I(!0),u.isDesktop&&o&&!f){H(""),Z(""),Ze(!0);return}if(!u.isDesktop&&o&&!f){H(""),Z(""),K(t.path),Ze(!1);return}if(h){H(""),Z(""),K(t.path),Ze(!1);return}if(S){H(""),Z(""),K(t.path),Ze(!1);return}Ze(!0);const M=Wr(t.path),U={allowOutsideWorkspace:d==="editor-only"&&!!a&&!ds(t.path,a),outsideFileGrant:M};await lr(t.path,U).then(Fe=>{if(!l())return;if(Va(Fe)){zn(!0),H(""),Z(""),K(t.path);return}const oe=fi(Fe);wi(ml(Fe)),H(oe),ct.current=oe,Jt.current=oe,Z(oe.length>ls?`${oe.slice(0,ls)}
13
13
 
14
- … truncated …`:oe),H(t.path),ft(t.path,U).then(Tt=>{Tt&&l()&&(tt.current=Tt)}).catch(()=>{})}).catch(Fe=>{if(l()){if(pl(Fe)){if(Ze(!1),a&&re(a,null),Y(null),K(""),Z(""),H(null),tt.current=null,E.trim().length>0&&P(""),p&&I(!1),a){const Tt=[...ti(t.path,a),t.path];Tt.length>0&&us(a,Tt);for(const ln of Tt)Ce.current.has(ln)||De(ln)}return}if(ni(Fe)){a&&ot(a,t.path),K(""),Z(""),Y(null),tt.current=null,p&&I(!1);return}K(""),Z(""),Y(Fe instanceof Error?Fe.message:e("filesView.error.readFileFailed")),tt.current=null}}).finally(()=>{l()&&Ze(!1)})},[us,p,De,d,lr,ft,ot,a,u.isDesktop,E,re,e]),Ns=i.useCallback(async(t,r)=>{if(!a)return;const l=ti(t,a),o=r?[...l,t]:l;o.length>0&&us(a,o);const f=o.map(h=>{if(!Ce.current.has(h))return De(h)}).filter(Boolean);await Promise.all(f)},[us,De,a]),dr=i.useCallback((t,r)=>{const l=r.findIndex(o=>o.path===t);return l===-1||r.length<=1?null:r[l+1]??r[l-1]??null},[]),pe=i.useCallback(async t=>{if(Nt.current)Nt.current=!1;else if(ae){It(!0),Lt.current=t;return}a&&(re(a,t.path),Ns(t.path,!1)),Y(null),Pe(""),K(""),ct.current="",Jt.current="",Z(""),H(null),p&&I(!0)},[Ns,ae,p,a,re]);i.useEffect(()=>{c?.path&&Ns(c.path,!1)},[Ns,c?.path]),i.useEffect(()=>{if(!c){vs.current+=1,Yt.current=null,Ze(!1);return}if(je===c.path||Yt.current===c.path)return;const t=c.path;Yt.current=t,cr(c).finally(()=>{Yt.current===t&&(Yt.current=null)})},[cr,je,c]);const ur=i.useRef(ae);ur.current=ae,i.useEffect(()=>{if(!c?.path||je!==c.path)return;let t=!1;const r=window.setInterval(()=>{document.hidden||ft(c.path,J).then(l=>{if(t||!l)return;const o=tt.current;if(!o||o.path!==c.path){tt.current=l;return}const f=l.mtimeMs!==void 0&&o.mtimeMs!==void 0&&l.mtimeMs!==o.mtimeMs,h=l.size!==o.size;!f&&!h||ur.current||(tt.current=l,H(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(r)}},[je,ft,c?.path,J]);const Gi=i.useCallback(()=>{const t=Lt.current,r=Qt.current,l=es.current;if(Lt.current=null,Qt.current=null,es.current=null,Nt.current=!0,It(!1),Z(Xs),l){a&&Et(a,l),c?.path===l&&(t?pe(t):(a&&re(a,null),K(""),Y(null),Pe(""),H(null),p&&I(!1)));return}if(t){pe(t);return}r&&(Ke(null),me.getState().setActiveMainTab(r))},[Xs,pe,p,Et,a,c?.path,Ke,re]),_i=i.useCallback(async()=>{const t=Lt.current,r=Qt.current,l=es.current;if(!await Ct()){Nt.current=!1;return}if(Lt.current=null,Qt.current=null,es.current=null,Nt.current=!0,It(!1),l){a&&Et(a,l),c?.path===l&&(t?await pe(t):(a&&re(a,null),K(""),Y(null),Pe(""),H(null),p&&I(!1)));return}if(t){await pe(t);return}r&&(Ke(null),me.getState().setActiveMainTab(r))},[pe,p,Et,a,Ct,c?.path,Ke,re]),fr=i.useCallback(t=>{const r=c?.path===t,l=dr(t,Mt);if(r&&ae){It(!0),Lt.current=l,es.current=t;return}if(a&&Et(a,t),!!r){if(l){pe(l);return}a&&re(a,null),K(""),Y(null),Pe(""),H(null),p&&I(!1)}},[dr,pe,ae,p,Mt,Et,a,c?.path,re]),Ki=i.useCallback(t=>{if(T.includes(t))return"open";if(z?.files){const r=t.startsWith(a+"/")?t.slice(a.length+1):t,l=z.files.find(o=>o.path===r);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[T,z,a]),Hi=i.useCallback(t=>{if(!z?.files)return null;const r=t.startsWith(a+"/")?t.slice(a.length+1):t,l=r?`${r}/`:"";let o=0,f=0;for(const h of z.files)h.path.startsWith(l)&&((h.index==="M"||h.working_dir==="M")&&o++,(h.index==="A"||h.working_dir==="?")&&f++);return o+f>0?{modified:o,added:f}:null},[z,a]),qi=i.useCallback(async t=>{const r=O(t);a&&(kn(a,r),Ce.current.has(r)||await De(r))},[De,a,kn]),Xi=i.useMemo(()=>({canRename:Wn,canCreateFile:Bn,canCreateFolder:$n,canDelete:Un,canReveal:Gn}),[Wn,Bn,$n,Un,Gn]);function hr(t,r){const l=Rn[t]??[];return l.map((o,f)=>{const h=o.type==="directory",S=h&&Je.includes(o.path),M=c?.path===o.path,U=f===l.length-1;return s.jsxs("li",{className:"relative",children:[r>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),U&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(xl,{node:o,root:a,isExpanded:S,isActive:M,isMobile:p,isBrowserClient:b,alwaysShowActions:F,status:h?void 0:Ki(o.path),badge:h?Hi(o.path):void 0,permissions:Xi,downloadFile:n.downloadFile,contextMenuPath:Ti,setContextMenuPath:Di,rightClickMenuPath:Vi,setRightClickMenuPath:Ri,onSelect:pe,onToggle:qi,onRevealPath:Li,onOpenDialog:Ks}),h&&S&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[hs[o.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:hs[o.path],children:hs[o.path]}),s.jsxs(V,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{qe(o.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,hr(o.path,r+1)]})]},o.path)})}const Q=!!(c?.path&&Gr(c.path)),Wt=!!(c?.path&&_r(c.path)),Ve=!!(c?.path&&Kr(c.path)),Js=!!(c?.path&&(Ds(c.path)||Zt)),st=Js&&!Q&&!Ve,pr=i.useMemo(()=>O(He?.path??""),[He?.path]),Ut=!!(He&&pr&&Ge&&Ge===pr&&!Ee&&!Qe&&!Q&&!Ve&&!st),ht=i.useMemo(()=>Ps(a,Ge),[Ge,a]),Ji=!!(c&&(!Q||Wt)&&!Ve&&!st&&D.length>0),Yi=!!(c&&ht.length>0),Re=!!(c&&!fs&&!Js&&!Q&&n.writeFile&&D.length<=ls),pt=!!(c?.path&&ri(c.path)),is=!!(c?.path&&vl(c.path)),Gt=!!(c?.path&&xn(c.path)),as=!!(c?.path&&un(c.path)),Ys=!!(c&&!Js&&!Q)&&!pt&&!as&&!(Gt&&xe==="preview"),Zi=pt&&bt==="edit"||Gt&&xe==="edit"||is&&Oe==="text"||!pt&&!Gt&&!is&&_==="edit",Fs=i.useMemo(()=>Ge?Ra(Ge):null,[Ge]),[mr,Zs]=i.useState(null);i.useEffect(()=>{let t=!1;const r=c?.path;if(!r||Fs){Zs(null);return}return Zs(null),Ea(r).then(l=>{t||Zs(l)}),()=>{t=!0}},[c?.path,Fs]),i.useEffect(()=>{!Re&&_==="edit"&&Se("view")},[Re,_]);const Qs="openchamber:files:md-viewer-mode",en="openchamber:files:html-viewer-mode",tn="openchamber:files:json-viewer-mode";i.useEffect(()=>{const t=c?.path;if(!t)return;Se($e.current[t]??"edit");let r=ns?"preview":"edit";try{const f=localStorage.getItem(Qs);(f==="preview"||f==="edit")&&(r=f)}catch{}Le(We.current[t]??r);let l=ns?"preview":"edit";try{const f=localStorage.getItem(en);(f==="preview"||f==="edit")&&(l=f)}catch{}Be(Ue.current[t]??l),ke(lt.current[t]??(ns?"preview":"edit"));let o=ns?"tree":"text";try{const f=localStorage.getItem(tn);(f==="tree"||f==="text")&&(o=f)}catch{}yt(o)},[c?.path,ns]);const Qi=i.useCallback(t=>{const r=c?.path;r&&($e.current[r]=t),Se(t)},[c?.path]),gr=i.useCallback(t=>{const r=c?.path;r&&(We.current[r]=t),Le(t);try{localStorage.setItem(Qs,t)}catch{}},[c?.path]),le=i.useCallback(()=>bt,[bt]),ea=i.useCallback(t=>{yt(t);try{localStorage.setItem(tn,t)}catch{}},[]),ta=i.useCallback(t=>{const r=c?.path;r&&(Ue.current[r]=t),Be(t);try{localStorage.setItem(en,t)}catch{}},[c?.path]),sa=i.useCallback(t=>{const r=c?.path;if(r&&(lt.current[r]=t),Ne.current&&(clearTimeout(Ne.current),Ne.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null),t==="edit")Z(ct.current||D),ke(t);else{ct.current=W;const l=r;ke("edit"),et.current=requestAnimationFrame(()=>{et.current=requestAnimationFrame(()=>{et.current=null,!(a&&l&&ze.getState().byRoot[a]?.selectedPath!==l)&&(at(o=>o+1),ke("preview"))})});return}},[W,D,a,c?.path]),sn=i.useCallback(async(t,r)=>{if(!n.writeFile||r===Jt.current)return!1;if(!(await n.writeFile(t,r))?.success)return L.error(e("filesView.toast.writeFileFailed")),!1;ct.current=r,Jt.current=r,Z(r);const o=await ft(t,J).catch(()=>null);return o&&(tt.current=o),!0},[n,ft,J,e]);i.useEffect(()=>()=>{Ne.current&&(clearTimeout(Ne.current),Ne.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null)},[fe,c?.path]);const na=i.useCallback(t=>{if(ct.current=t,!ie||!c?.path||fe!=="preview"||!n.writeFile)return;Ne.current&&clearTimeout(Ne.current);const r=c.path;Ne.current=setTimeout(()=>{Ne.current=null,sn(r,t).then(l=>{l&&(xs(!0),setTimeout(()=>xs(!1),1500))}).catch(l=>{L.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},or)},[ie,fe,n.writeFile,sn,c?.path,e]),ra=i.useMemo(()=>as&&(ct.current||W)||D,[W,D,as]),vr=i.useCallback(()=>xe,[xe]);i.useEffect(()=>{const t=l=>{const o=l?"preview":"edit",f=l?"tree":"text";for(const h of T)$e.current[h]="edit",ri(h)&&(We.current[h]=o),xn(h)&&(Ue.current[h]=o),un(h)&&(lt.current[h]=o);Se("edit"),Le(o),Be(o),ke(o),yt(f);try{localStorage.setItem(Qs,o),localStorage.setItem(en,o),localStorage.setItem(tn,f)}catch{}},r=l=>{const o=!!l.detail?.enabled;t(o)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",r),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",r)}},[T]),i.useEffect(()=>{if(!He||!a)return;const t=()=>{typeof window>"u"||Ot.current===null&&(Ot.current=window.requestAnimationFrame(()=>{Ot.current=null,Ws(nt=>nt+1)}))},r=(nt,Dt)=>{if(nt.state.doc.length!==Dt.length)return!1;if(Dt.length===0)return!0;const on=Math.min(128,Dt.length);if(nt.state.sliceDoc(0,on)!==Dt.slice(0,on))return!1;const Pr=Math.max(0,Dt.length-on);return nt.state.sliceDoc(Pr,Dt.length)===Dt.slice(Pr)},l=O(He.path);if(!l){ws(null),Ft.current={key:"",attempts:0};return}const o=`${l}:${He.line}:${He.column??1}`;if(Ft.current.key!==o&&(Ft.current={key:o,attempts:0}),c?.path!==l){if($s)return;pe(Pt(l));return}if(Ee||je!==l)return;if(Qe||Q||Ve||st){ws(null),Ft.current={key:"",attempts:0};return}if(!Re)return;if(_!=="edit"){Se("edit");return}const f=Me.current;if(!f){t();return}if(!r(f,W)){t();return}const h=Math.max(1,Math.min(He.line,f.state.doc.lines)),S=f.state.doc.line(h),M=Math.max(1,He.column||1),U=Math.max(0,S.to-S.from),Fe=Math.min(U,M-1),oe=S.from+Fe;if(!(f.state.selection.main.head===oe)||Ft.current.attempts===0){Ft.current.attempts+=1,f.dispatch({selection:{anchor:oe},effects:Vt.scrollIntoView(oe,{y:"center"})}),f.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const nt=Me.current;nt&&(nt.dispatch({selection:{anchor:oe},effects:Vt.scrollIntoView(oe,{y:"center"})}),nt.focus())}),ws(null),Ft.current={key:"",attempts:0}},[Re,$s,W,Si,Qe,Ee,Q,Ve,st,je,pe,He,a,c?.path,ws,_,Pt]),i.useEffect(()=>{if(!Hs||!a)return;const t=O(Hs);if(!t){qs(null);return}c?.path===t&&(Ee||je!==t||(!Qe&&!Q&&!Ve&&!st&&Re&&_==="edit"&&Me.current?.focus(),qs(null)))},[Re,Qe,Ee,Q,Ve,st,je,Hs,a,c?.path,qs,_]);const _t=i.useCallback(t=>{if(!p||!t||!t.hasFocus||typeof window>"u")return;const r=window.visualViewport;if(!r)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(r.offsetTop+r.height))<=0)return;const f=t.state.selection.main.head,h=t.coordsAtPos(f);if(!h)return;const S=Math.round(r.offsetTop+r.height),U=h.bottom+20-S;U<=0||(t.scrollDOM.scrollTop+=U)},[p]);i.useEffect(()=>{if(!p||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{_t(Me.current)})},r=window.visualViewport;return r?.addEventListener("resize",t),r?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{r?.removeEventListener("resize",t),r?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[p,_t]),i.useEffect(()=>{if(!Re||_!=="edit"||p)return;const t=Pa("open_go_to_line",Hn),r=l=>{const o=l.target;if(o?.closest('[role="dialog"]'))return;const f=!!o?.closest(".cm-editor");o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!f||!document.activeElement?.closest(".cm-editor")||Ia(l,t)&&(l.preventDefault(),_s(!0))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Re,p,Hn,_]);const Ss=me(t=>t.editorFontSize),xr=i.useMemo(()=>{if(!c?.path)return[Xr(v,{fontSize:Ss})];const t=dn(c.path),r=[Xr(v,t?{syntaxColors:!1,fontSize:Ss}:{fontSize:Ss})],l=Fs??mr;return l&&r.push(l),t&&r.push(Wa({language:t,themeName:v.metadata.id,theme:Ma(v)})),de&&r.push(Vt.lineWrapping),p&&r.push(Vt.updateListener.of(o=>{o.view.hasFocus&&(o.selectionSet||o.focusChanged||o.viewportChanged||o.geometryChanged)&&window.requestAnimationFrame(()=>{_t(o.view)})})),r},[v,c?.path,Fs,mr,de,p,_t,Ss]),wr=i.useMemo(()=>({light:he.metadata.id,dark:we.metadata.id}),[he.metadata.id,we.metadata.id]),ks=c?.path&&Q&&!u.isDesktop&&!Wt?`${c.path}|${J.allowOutsideWorkspace?"outside":"workspace"}|${J.outsideFileGrant??""}`:"",Cs=c?.path&&Ve?`${c.path}|${J.allowOutsideWorkspace?"outside":"workspace"}|${J.outsideFileGrant??""}`:"",Ts=c?.path&&Gt&&xe==="preview"&&!u.isVSCode?c.path:"",nn=e("filesView.error.readFileFailed"),{readyKey:br,nonce:yr}=wn(ks,Y,nn),{readyKey:jr,nonce:ia}=wn(Ts,Y,nn),{readyKey:Nr,nonce:Fr}=wn(Cs,Y,nn),Sr=!!(ks&&br!==ks),aa=!!(Ts&&jr!==Ts),kr=!!(Cs&&Nr!==Cs),Cr=c?.path&&Q?u.isDesktop?Wt?`data:${Hr(c.path)};utf8,${encodeURIComponent(D)}`:xi:Wt?`data:${Hr(c.path)};utf8,${encodeURIComponent(D)}`:br===ks?cn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}):"":"",Tr=c?.path&&Ve&&Nr===Cs?cn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}):"",Dr=i.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:Tr,className:"h-full w-full border-0",title:t.name},Fr)}),[Tr,Fr]);i.useEffect(()=>{let t=!1;return(async()=>{if(!u.isDesktop||!c?.path||!Q||Wt){ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),Pe("");return}Y(null),ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),await(n.readFileBinary?n.readFileBinary(c.path,J).then(o=>o.dataUrl):(async()=>{const o=await Br("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}});if(!o.ok)throw new Error(e("filesView.error.readFileFailed"));const f=await o.blob(),h=URL.createObjectURL(f);return t?(URL.revokeObjectURL(h),""):(ye.current=h,h)})()).then(o=>{t||(Pe(o),H(c.path))}).catch(o=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),t||(Pe(""),Y(o instanceof Error?o.message:e("filesView.error.readFileFailed")),H(null))}).finally(()=>{t||Ze(!1)})})(),()=>{t=!0}},[n,Q,Wt,a,u.isDesktop,c?.path,J,e]),i.useEffect(()=>()=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current="")},[]);const la=i.useCallback(()=>Us(null),[]),oa=i.useMemo(()=>Ua({drafts:Jn,editingDraftId:ys,commentText:bs,onTextChange:Yn,selection:A,isDragging:Kn,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:nr,onCancel:()=>{Ae(null),rs()},onEdit:t=>{tr(t),Ae({start:t.startLine,end:t.endLine})},onDelete:sr}),[rs,bs,sr,ys,Jn,nr,Kn,A,c?.path,Yn,tr]),Vr=i.useCallback((t,r)=>s.jsx("div",{className:"h-full",children:s.jsx(Ja,{file:{name:t.name,contents:r,lang:dn(t.path)||void 0},options:{disableFileHeader:!0,overflow:de?"wrap":"scroll",theme:wr,themeType:v.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[v.metadata.variant,wr,de]),rn=({exitFullscreenOnly:t=!1,layout:r="floating"}={})=>{if(!c)return null;const o=r==="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",f=(h,S)=>s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:S})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:h})]});return s.jsxs("div",{className:o,children:[Re&&Zi&&s.jsxs(s.Fragment,{children:[At?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):ie&&yi==="saved"&&!ae?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ae?f(e(ie?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${pn()}+S`}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{Ct()},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:e(ie?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${pn()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${pn()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,f(e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ni(!ie),className:$("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ie?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ie?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(jn,{onOpenChange:Rt,children:[s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Nn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(Fn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ai.map(h=>s.jsxs(Es,{className:"flex items-center gap-2",onClick:()=>{Oi(h)},children:[s.jsx(ll,{label:h.label,iconDataUrl:h.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:h.label})]},h.id)),zi?s.jsxs(Es,{className:"flex items-center gap-2",onClick:()=>{Ii(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Q&&!Ve&&!st&&s.jsxs(s.Fragment,{children:[f(e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ie(!de),className:$("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",de?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),_==="edit"&&s.jsxs(s.Fragment,{children:[f(e("filesView.editor.findInFile"),s.jsx(V,{variant:"ghost",size:"sm",onClick:h=>{ge(!se),h.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),f(e("filesView.editor.goToLine"),s.jsx(V,{variant:"ghost",size:"sm",onClick:h=>{_s(S=>!S),h.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(tl,{open:Mi,onOpenChange:_s,view:Me.current,variant:"inline"})]})]}),Ys&&Re&&!is&&!Gt&&s.jsx(mn,{currentMode:_==="view"?"preview":"edit",onToggle:()=>{Qi(_==="view"?"edit":"view")}}),pt&&f(e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>gr(le()==="preview"?"edit":"preview"),className:$("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",le()==="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:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:le()==="preview"?"eye":"eye-off",className:"size-4"})})),xn(c?.path??"")&&s.jsx(mn,{currentMode:vr(),onToggle:()=>{ta(vr()==="preview"?"edit":"preview")}}),pt&&le()==="preview"&&Bi&&s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(gs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{gs?vi():D.trim()&&gi(D)},children:gs?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(vt,{sideOffset:8,children:e(gs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),as&&s.jsxs(s.Fragment,{children:[s.jsx(mn,{currentMode:fe,onToggle:()=>sa(fe==="preview"?"edit":"preview")}),fe==="preview"&&s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{const h=An.current?.getXml();if(Ne.current&&(clearTimeout(Ne.current),Ne.current=null),c?.path&&h){if(!await sn(c.path,h))return;xs(!0),setTimeout(()=>xs(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:ji?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),is&&f(e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>ea(Oe==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Oe==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Ji&&f(e("filesView.editor.copyFileContents"),s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{(await As(D)).ok?(Ln(!0),ts.current!==null&&window.clearTimeout(ts.current),ts.current=window.setTimeout(()=>{Ln(!1)},1200)):L.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Ei?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),Yi&&f(e("filesView.editor.copyFilePathTitle",{path:ht}),s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{(await As(ht)).ok?(On(!0),ss.current!==null&&window.clearTimeout(ss.current),ss.current=window.setTimeout(()=>{On(!1)},1200)):L.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ht}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ht}),children:Pi?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&f(e("filesView.editor.saveFile"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{const h=n.downloadFile;h&&h(c.path).catch(S=>{console.error("Download failed:",S),L.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?f(e("filesView.editor.exitFullscreen"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>X(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!p&&d==="full"&&f(e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>X(!G),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:G?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},an=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ai,{open:$s,onOpenChange:t=>{t||It(!0)},children:s.jsxs(li,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(oi,{children:[s.jsx(ci,{children:e("filesView.unsaved.title")}),s.jsx(di,{children:e("filesView.unsaved.description")})]}),s.jsxs(ui,{children:[s.jsx(V,{variant:"outline",onClick:()=>{_i()},disabled:At,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(V,{variant:"destructive",onClick:Gi,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:$("flex flex-col flex-shrink-0",R&&"border-b border-border/40"),children:[R?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[p&&te&&s.jsx("button",{type:"button",onClick:()=>I(!1),"aria-label":e("filesView.editor.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:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),p?c?s.jsxs(jn,{children:[s.jsx(Nn,{asChild:!0,children:s.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":e("filesView.editor.openFilesAria"),children:[s.jsx(Rs,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(si,{name:c.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Fn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Mt.map(t=>{const r=c?.path===t.path;return s.jsxs(Es,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}r||pe(t)},className:$("flex min-w-0 items-center justify-between gap-2 overflow-hidden",r&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Rs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(si,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),fr(t.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":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Mt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Tn.left&&s.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"}),Tn.right&&s.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"}),s.jsx("div",{ref:Ls,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Mt.map(t=>{const r=c?.path===t.path;return s.jsxs("div",{title:Ps(a,t.path),className:$("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:[s.jsx(Rs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{r||pe(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),fr(t.path)},className:$("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!r&&!F&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Xn||p)&&c?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ht&&!p?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ht,children:ht}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:rn({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[c&&!se&&!(Xn||p)&&s.jsx("div",{ref:ue,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{rt.current>0||ve(!1)},children:ne?rn():s.jsxs("div",{className:"flex items-center gap-1",children:[pt?s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>gr(le()==="preview"?"edit":"preview"),className:$("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",le()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:le()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>ve(!0),children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>ve(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:c?Ee||Sr||kr?B?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Qe?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Qe}):Q?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Cr,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},yr)}):Ve?Dr(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(r=>{console.error("Download failed:",r),L.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&as&&fe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(il,{ref:An,xml:ra,onChange:na},`${c.path}:${it}`)}):c&&is&&Oe==="tree"?s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Aa,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&pt&&le()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(qr,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):c&&Gt&&xe==="preview"?aa?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!u.isVSCode&&jr===Ts?(()=>{const t=c.path.split("/").map(r=>encodeURIComponent(r)).join("/");return cn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:u.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},ia)}):c&&Ys&&_==="view"?Vr(c,W):s.jsxs("div",{className:$("relative h-full",Ut&&"overflow-hidden"),ref:Fi,children:[s.jsx("div",{className:$("h-full",Ut&&"invisible"),children:s.jsx(Jr,{value:W,onChange:Z,readOnly:!Re,vimMode:qn==="vim",extensions:xr,className:"h-full",blockWidgets:oa,onViewReady:t=>{Me.current=t,Ws(r=>r+1),window.requestAnimationFrame(()=>{_t(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null),Ws(t=>t+1)},enableSearch:!0,searchOpen:se,onSearchOpenChange:ge,highlightLines:A?{start:Math.min(A.start,A.end),end:Math.max(A.start,A.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,r,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const o=t.state.doc.lineAt(r.from).number;if(A&&!l.shiftKey&&Math.min(A.start,A.end)===o&&Math.max(A.start,A.end)===o)return Ae(null),rs(),Bt.current=!1,ut.current=null,$t(!1),!0;if(p&&A&&!l.shiftKey){const f=Math.min(A.start,A.end,o),h=Math.max(A.start,A.end,o);return Ae({start:f,end:h}),Bt.current=!1,ut.current=null,$t(!1),!0}if(Bt.current=!0,ut.current=o,$t(!0),A&&l.shiftKey){const f=Math.min(A.start,o),h=Math.max(A.end,o);Ae({start:f,end:h})}else Ae({start:o,end:o});return!0},mouseover:(t,r,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Bt.current||ut.current===null)return!1;const o=t.state.doc.lineAt(r.from).number,f=Math.min(ut.current,o),h=Math.max(ut.current,o);return Ae({start:f,end:h}),$t(!0),!1},mouseup:()=>(Bt.current=!1,ut.current=null,$t(!1),!1)}}})}),Ut&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),ca=!!(a&&Rn[a]),Rr=a?hs[a]:null,Er=s.jsxs("section",{className:$("flex min-h-0 flex-col overflow-hidden",p?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:$("flex flex-col gap-2 py-2",p?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Ms,{ref:ee,value:E,onChange:t=>P(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{P(""),ee.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ks("createFile",{path:C,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ks("createFolder",{path:C,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{js()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(fn,{outerClassName:"flex-1 min-h-0",className:$("py-2",p?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:mi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Pn.length>0?Pn.map(t=>{const r=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{pe(t)},className:$("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",r?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[hi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):Rr?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:Rr}),s.jsxs(V,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{js()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):ca?hr(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),da=d==="full"&&G&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:rn({exitFullscreenOnly:!0})}),s.jsx(fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||Sr||kr?B?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Qe?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Qe}):Q?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Cr,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},yr)}):Ve?Dr(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(r=>{console.error("Download failed:",r),L.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):pt&&le()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(qr,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Ys&&_==="view"?Vr(c,W):s.jsxs("div",{className:$("relative h-full",Ut&&"overflow-hidden"),children:[s.jsx("div",{className:$("h-full",Ut&&"invisible"),children:s.jsx(Jr,{value:W,onChange:Z,readOnly:!Re,vimMode:qn==="vim",extensions:xr,className:"h-full",onViewReady:t=>{Me.current=t,window.requestAnimationFrame(()=>{_t(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null)}})}),Ut&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(wl,{activeDialog:St,dialogData:kt,dialogInputValue:dt,onDialogInputChange:In,isDialogSubmitting:Ci,onDialogSubmit:Ui,onClose:la,inputRef:bi}),da,p?te?an:Er:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:an})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Er}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:an})]})]})};function yl(d){return d+1}const Ml=Object.freeze(Object.defineProperty({__proto__:null,FilesView:bl},Symbol.toStringTag,{value:"Module"}));export{il as D,bl as F,Ml as a,Vs as u};
14
+ … truncated …`:oe),K(t.path),ft(t.path,U).then(Tt=>{Tt&&l()&&(tt.current=Tt)}).catch(()=>{})}).catch(Fe=>{if(l()){if(pl(Fe)){if(Ze(!1),a&&re(a,null),Y(null),H(""),Z(""),K(null),tt.current=null,E.trim().length>0&&P(""),p&&I(!1),a){const Tt=[...ti(t.path,a),t.path];Tt.length>0&&us(a,Tt);for(const ln of Tt)Ce.current.has(ln)||De(ln)}return}if(ni(Fe)){a&&ot(a,t.path),H(""),Z(""),Y(null),tt.current=null,p&&I(!1);return}H(""),Z(""),Y(Fe instanceof Error?Fe.message:e("filesView.error.readFileFailed")),tt.current=null}}).finally(()=>{l()&&Ze(!1)})},[us,p,De,d,lr,ft,ot,a,u.isDesktop,E,re,e]),Ns=i.useCallback(async(t,r)=>{if(!a)return;const l=ti(t,a),o=r?[...l,t]:l;o.length>0&&us(a,o);const f=o.map(h=>{if(!Ce.current.has(h))return De(h)}).filter(Boolean);await Promise.all(f)},[us,De,a]),dr=i.useCallback((t,r)=>{const l=r.findIndex(o=>o.path===t);return l===-1||r.length<=1?null:r[l+1]??r[l-1]??null},[]),pe=i.useCallback(async t=>{if(Nt.current)Nt.current=!1;else if(ae){It(!0),Lt.current=t;return}a&&(re(a,t.path),Ns(t.path,!1)),Y(null),Pe(""),H(""),ct.current="",Jt.current="",Z(""),K(null),p&&I(!0)},[Ns,ae,p,a,re]);i.useEffect(()=>{c?.path&&Ns(c.path,!1)},[Ns,c?.path]),i.useEffect(()=>{if(!c){vs.current+=1,Yt.current=null,Ze(!1);return}if(je===c.path||Yt.current===c.path)return;const t=c.path;Yt.current=t,cr(c).finally(()=>{Yt.current===t&&(Yt.current=null)})},[cr,je,c]);const ur=i.useRef(ae);ur.current=ae,i.useEffect(()=>{if(!c?.path||je!==c.path)return;let t=!1;const r=window.setInterval(()=>{document.hidden||ft(c.path,J).then(l=>{if(t||!l)return;const o=tt.current;if(!o||o.path!==c.path){tt.current=l;return}const f=l.mtimeMs!==void 0&&o.mtimeMs!==void 0&&l.mtimeMs!==o.mtimeMs,h=l.size!==o.size;!f&&!h||ur.current||(tt.current=l,K(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(r)}},[je,ft,c?.path,J]);const Gi=i.useCallback(()=>{const t=Lt.current,r=Qt.current,l=es.current;if(Lt.current=null,Qt.current=null,es.current=null,Nt.current=!0,It(!1),Z(Xs),l){a&&Et(a,l),c?.path===l&&(t?pe(t):(a&&re(a,null),H(""),Y(null),Pe(""),K(null),p&&I(!1)));return}if(t){pe(t);return}r&&(He(null),me.getState().setActiveMainTab(r))},[Xs,pe,p,Et,a,c?.path,He,re]),_i=i.useCallback(async()=>{const t=Lt.current,r=Qt.current,l=es.current;if(!await Ct()){Nt.current=!1;return}if(Lt.current=null,Qt.current=null,es.current=null,Nt.current=!0,It(!1),l){a&&Et(a,l),c?.path===l&&(t?await pe(t):(a&&re(a,null),H(""),Y(null),Pe(""),K(null),p&&I(!1)));return}if(t){await pe(t);return}r&&(He(null),me.getState().setActiveMainTab(r))},[pe,p,Et,a,Ct,c?.path,He,re]),fr=i.useCallback(t=>{const r=c?.path===t,l=dr(t,Mt);if(r&&ae){It(!0),Lt.current=l,es.current=t;return}if(a&&Et(a,t),!!r){if(l){pe(l);return}a&&re(a,null),H(""),Y(null),Pe(""),K(null),p&&I(!1)}},[dr,pe,ae,p,Mt,Et,a,c?.path,re]),Hi=i.useCallback(t=>{if(T.includes(t))return"open";if(z?.files){const r=t.startsWith(a+"/")?t.slice(a.length+1):t,l=z.files.find(o=>o.path===r);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[T,z,a]),Ki=i.useCallback(t=>{if(!z?.files)return null;const r=t.startsWith(a+"/")?t.slice(a.length+1):t,l=r?`${r}/`:"";let o=0,f=0;for(const h of z.files)h.path.startsWith(l)&&((h.index==="M"||h.working_dir==="M")&&o++,(h.index==="A"||h.working_dir==="?")&&f++);return o+f>0?{modified:o,added:f}:null},[z,a]),qi=i.useCallback(async t=>{const r=O(t);a&&(kn(a,r),Ce.current.has(r)||await De(r))},[De,a,kn]),Xi=i.useMemo(()=>({canRename:Wn,canCreateFile:Bn,canCreateFolder:$n,canDelete:Un,canReveal:Gn}),[Wn,Bn,$n,Un,Gn]);function hr(t,r){const l=Rn[t]??[];return l.map((o,f)=>{const h=o.type==="directory",S=h&&Je.includes(o.path),M=c?.path===o.path,U=f===l.length-1;return s.jsxs("li",{className:"relative",children:[r>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),U&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(xl,{node:o,root:a,isExpanded:S,isActive:M,isMobile:p,isBrowserClient:b,alwaysShowActions:F,status:h?void 0:Hi(o.path),badge:h?Ki(o.path):void 0,permissions:Xi,downloadFile:n.downloadFile,contextMenuPath:Ti,setContextMenuPath:Di,rightClickMenuPath:Vi,setRightClickMenuPath:Ri,onSelect:pe,onToggle:qi,onRevealPath:Li,onOpenDialog:Hs}),h&&S&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[hs[o.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:hs[o.path],children:hs[o.path]}),s.jsxs(V,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{qe(o.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,hr(o.path,r+1)]})]},o.path)})}const Q=!!(c?.path&&Gr(c.path)),Wt=!!(c?.path&&_r(c.path)),Ve=!!(c?.path&&Hr(c.path)),Js=!!(c?.path&&(Ds(c.path)||Zt)),st=Js&&!Q&&!Ve,pr=i.useMemo(()=>O(Ke?.path??""),[Ke?.path]),Ut=!!(Ke&&pr&&Ge&&Ge===pr&&!Ee&&!Qe&&!Q&&!Ve&&!st),ht=i.useMemo(()=>Ps(a,Ge),[Ge,a]),Ji=!!(c&&(!Q||Wt)&&!Ve&&!st&&D.length>0),Yi=!!(c&&ht.length>0),Re=!!(c&&!fs&&!Js&&!Q&&n.writeFile&&D.length<=ls),pt=!!(c?.path&&ri(c.path)),is=!!(c?.path&&vl(c.path)),Gt=!!(c?.path&&xn(c.path)),as=!!(c?.path&&un(c.path)),Ys=!!(c&&!Js&&!Q)&&!pt&&!as&&!(Gt&&xe==="preview"),Zi=pt&&bt==="edit"||Gt&&xe==="edit"||is&&Oe==="text"||!pt&&!Gt&&!is&&_==="edit",Fs=i.useMemo(()=>Ge?Ra(Ge):null,[Ge]),[mr,Zs]=i.useState(null);i.useEffect(()=>{let t=!1;const r=c?.path;if(!r||Fs){Zs(null);return}return Zs(null),Ea(r).then(l=>{t||Zs(l)}),()=>{t=!0}},[c?.path,Fs]),i.useEffect(()=>{!Re&&_==="edit"&&Se("view")},[Re,_]);const Qs="openchamber:files:md-viewer-mode",en="openchamber:files:html-viewer-mode",tn="openchamber:files:json-viewer-mode";i.useEffect(()=>{const t=c?.path;if(!t)return;Se($e.current[t]??"edit");let r=ns?"preview":"edit";try{const f=localStorage.getItem(Qs);(f==="preview"||f==="edit")&&(r=f)}catch{}Le(We.current[t]??r);let l=ns?"preview":"edit";try{const f=localStorage.getItem(en);(f==="preview"||f==="edit")&&(l=f)}catch{}Be(Ue.current[t]??l),ke(lt.current[t]??(ns?"preview":"edit"));let o=ns?"tree":"text";try{const f=localStorage.getItem(tn);(f==="tree"||f==="text")&&(o=f)}catch{}yt(o)},[c?.path,ns]);const Qi=i.useCallback(t=>{const r=c?.path;r&&($e.current[r]=t),Se(t)},[c?.path]),gr=i.useCallback(t=>{const r=c?.path;r&&(We.current[r]=t),Le(t);try{localStorage.setItem(Qs,t)}catch{}},[c?.path]),le=i.useCallback(()=>bt,[bt]),ea=i.useCallback(t=>{yt(t);try{localStorage.setItem(tn,t)}catch{}},[]),ta=i.useCallback(t=>{const r=c?.path;r&&(Ue.current[r]=t),Be(t);try{localStorage.setItem(en,t)}catch{}},[c?.path]),sa=i.useCallback(t=>{const r=c?.path;if(r&&(lt.current[r]=t),Ne.current&&(clearTimeout(Ne.current),Ne.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null),t==="edit")Z(ct.current||D),ke(t);else{ct.current=W;const l=r;ke("edit"),et.current=requestAnimationFrame(()=>{et.current=requestAnimationFrame(()=>{et.current=null,!(a&&l&&ze.getState().byRoot[a]?.selectedPath!==l)&&(at(o=>o+1),ke("preview"))})});return}},[W,D,a,c?.path]),sn=i.useCallback(async(t,r)=>{if(!n.writeFile||r===Jt.current)return!1;if(!(await n.writeFile(t,r))?.success)return L.error(e("filesView.toast.writeFileFailed")),!1;ct.current=r,Jt.current=r,Z(r);const o=await ft(t,J).catch(()=>null);return o&&(tt.current=o),!0},[n,ft,J,e]);i.useEffect(()=>()=>{Ne.current&&(clearTimeout(Ne.current),Ne.current=null),et.current!==null&&(cancelAnimationFrame(et.current),et.current=null)},[fe,c?.path]);const na=i.useCallback(t=>{if(ct.current=t,!ie||!c?.path||fe!=="preview"||!n.writeFile)return;Ne.current&&clearTimeout(Ne.current);const r=c.path;Ne.current=setTimeout(()=>{Ne.current=null,sn(r,t).then(l=>{l&&(xs(!0),setTimeout(()=>xs(!1),1500))}).catch(l=>{L.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},or)},[ie,fe,n.writeFile,sn,c?.path,e]),ra=i.useMemo(()=>as&&(ct.current||W)||D,[W,D,as]),vr=i.useCallback(()=>xe,[xe]);i.useEffect(()=>{const t=l=>{const o=l?"preview":"edit",f=l?"tree":"text";for(const h of T)$e.current[h]="edit",ri(h)&&(We.current[h]=o),xn(h)&&(Ue.current[h]=o),un(h)&&(lt.current[h]=o);Se("edit"),Le(o),Be(o),ke(o),yt(f);try{localStorage.setItem(Qs,o),localStorage.setItem(en,o),localStorage.setItem(tn,f)}catch{}},r=l=>{const o=!!l.detail?.enabled;t(o)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",r),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",r)}},[T]),i.useEffect(()=>{if(!Ke||!a)return;const t=()=>{typeof window>"u"||Ot.current===null&&(Ot.current=window.requestAnimationFrame(()=>{Ot.current=null,Ws(nt=>nt+1)}))},r=(nt,Dt)=>{if(nt.state.doc.length!==Dt.length)return!1;if(Dt.length===0)return!0;const on=Math.min(128,Dt.length);if(nt.state.sliceDoc(0,on)!==Dt.slice(0,on))return!1;const Pr=Math.max(0,Dt.length-on);return nt.state.sliceDoc(Pr,Dt.length)===Dt.slice(Pr)},l=O(Ke.path);if(!l){ws(null),Ft.current={key:"",attempts:0};return}const o=`${l}:${Ke.line}:${Ke.column??1}`;if(Ft.current.key!==o&&(Ft.current={key:o,attempts:0}),c?.path!==l){if($s)return;pe(Pt(l));return}if(Ee||je!==l)return;if(Qe||Q||Ve||st){ws(null),Ft.current={key:"",attempts:0};return}if(!Re)return;if(_!=="edit"){Se("edit");return}const f=Me.current;if(!f){t();return}if(!r(f,W)){t();return}const h=Math.max(1,Math.min(Ke.line,f.state.doc.lines)),S=f.state.doc.line(h),M=Math.max(1,Ke.column||1),U=Math.max(0,S.to-S.from),Fe=Math.min(U,M-1),oe=S.from+Fe;if(!(f.state.selection.main.head===oe)||Ft.current.attempts===0){Ft.current.attempts+=1,f.dispatch({selection:{anchor:oe},effects:Vt.scrollIntoView(oe,{y:"center"})}),f.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const nt=Me.current;nt&&(nt.dispatch({selection:{anchor:oe},effects:Vt.scrollIntoView(oe,{y:"center"})}),nt.focus())}),ws(null),Ft.current={key:"",attempts:0}},[Re,$s,W,Si,Qe,Ee,Q,Ve,st,je,pe,Ke,a,c?.path,ws,_,Pt]),i.useEffect(()=>{if(!Ks||!a)return;const t=O(Ks);if(!t){qs(null);return}c?.path===t&&(Ee||je!==t||(!Qe&&!Q&&!Ve&&!st&&Re&&_==="edit"&&Me.current?.focus(),qs(null)))},[Re,Qe,Ee,Q,Ve,st,je,Ks,a,c?.path,qs,_]);const _t=i.useCallback(t=>{if(!p||!t||!t.hasFocus||typeof window>"u")return;const r=window.visualViewport;if(!r)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(r.offsetTop+r.height))<=0)return;const f=t.state.selection.main.head,h=t.coordsAtPos(f);if(!h)return;const S=Math.round(r.offsetTop+r.height),U=h.bottom+20-S;U<=0||(t.scrollDOM.scrollTop+=U)},[p]);i.useEffect(()=>{if(!p||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{_t(Me.current)})},r=window.visualViewport;return r?.addEventListener("resize",t),r?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{r?.removeEventListener("resize",t),r?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[p,_t]),i.useEffect(()=>{if(!Re||_!=="edit"||p)return;const t=Pa("open_go_to_line",Kn),r=l=>{const o=l.target;if(o?.closest('[role="dialog"]'))return;const f=!!o?.closest(".cm-editor");o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!f||!document.activeElement?.closest(".cm-editor")||Ia(l,t)&&(l.preventDefault(),_s(!0))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Re,p,Kn,_]);const Ss=me(t=>t.editorFontSize),xr=i.useMemo(()=>{if(!c?.path)return[Xr(v,{fontSize:Ss})];const t=dn(c.path),r=[Xr(v,t?{syntaxColors:!1,fontSize:Ss}:{fontSize:Ss})],l=Fs??mr;return l&&r.push(l),t&&r.push(Wa({language:t,themeName:v.metadata.id,theme:Ma(v)})),de&&r.push(Vt.lineWrapping),p&&r.push(Vt.updateListener.of(o=>{o.view.hasFocus&&(o.selectionSet||o.focusChanged||o.viewportChanged||o.geometryChanged)&&window.requestAnimationFrame(()=>{_t(o.view)})})),r},[v,c?.path,Fs,mr,de,p,_t,Ss]),wr=i.useMemo(()=>({light:he.metadata.id,dark:we.metadata.id}),[he.metadata.id,we.metadata.id]),ks=c?.path&&Q&&!u.isDesktop&&!Wt?`${c.path}|${J.allowOutsideWorkspace?"outside":"workspace"}|${J.outsideFileGrant??""}`:"",Cs=c?.path&&Ve?`${c.path}|${J.allowOutsideWorkspace?"outside":"workspace"}|${J.outsideFileGrant??""}`:"",Ts=c?.path&&Gt&&xe==="preview"&&!u.isVSCode?c.path:"",nn=e("filesView.error.readFileFailed"),{readyKey:br,nonce:yr}=wn(ks,Y,nn),{readyKey:jr,nonce:ia}=wn(Ts,Y,nn),{readyKey:Nr,nonce:Fr}=wn(Cs,Y,nn),Sr=!!(ks&&br!==ks),aa=!!(Ts&&jr!==Ts),kr=!!(Cs&&Nr!==Cs),Cr=c?.path&&Q?u.isDesktop?Wt?`data:${Kr(c.path)};utf8,${encodeURIComponent(D)}`:xi:Wt?`data:${Kr(c.path)};utf8,${encodeURIComponent(D)}`:br===ks?cn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}):"":"",Tr=c?.path&&Ve&&Nr===Cs?cn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}):"",Dr=i.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:Tr,className:"h-full w-full border-0",title:t.name},Fr)}),[Tr,Fr]);i.useEffect(()=>{let t=!1;return(async()=>{if(!u.isDesktop||!c?.path||!Q||Wt){ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),Pe("");return}Y(null),ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),await(n.readFileBinary?n.readFileBinary(c.path,J).then(o=>o.dataUrl):(async()=>{const o=await Br("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:J.allowOutsideWorkspace?"true":void 0,outsideFileGrant:J.outsideFileGrant,directory:a||void 0}});if(!o.ok)throw new Error(e("filesView.error.readFileFailed"));const f=await o.blob(),h=URL.createObjectURL(f);return t?(URL.revokeObjectURL(h),""):(ye.current=h,h)})()).then(o=>{t||(Pe(o),K(c.path))}).catch(o=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current=""),t||(Pe(""),Y(o instanceof Error?o.message:e("filesView.error.readFileFailed")),K(null))}).finally(()=>{t||Ze(!1)})})(),()=>{t=!0}},[n,Q,Wt,a,u.isDesktop,c?.path,J,e]),i.useEffect(()=>()=>{ye.current&&(URL.revokeObjectURL(ye.current),ye.current="")},[]);const la=i.useCallback(()=>Us(null),[]),oa=i.useMemo(()=>Ua({drafts:Jn,editingDraftId:ys,commentText:bs,onTextChange:Yn,selection:A,isDragging:Hn,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:nr,onCancel:()=>{Ae(null),rs()},onEdit:t=>{tr(t),Ae({start:t.startLine,end:t.endLine})},onDelete:sr}),[rs,bs,sr,ys,Jn,nr,Hn,A,c?.path,Yn,tr]),Vr=i.useCallback((t,r)=>s.jsx("div",{className:"h-full",children:s.jsx(Ja,{file:{name:t.name,contents:r,lang:dn(t.path)||void 0},options:{disableFileHeader:!0,overflow:de?"wrap":"scroll",theme:wr,themeType:v.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[v.metadata.variant,wr,de]),rn=({exitFullscreenOnly:t=!1,layout:r="floating"}={})=>{if(!c)return null;const o=r==="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",f=(h,S)=>s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:S})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:h})]});return s.jsxs("div",{className:o,children:[Re&&Zi&&s.jsxs(s.Fragment,{children:[At?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):ie&&yi==="saved"&&!ae?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ae?f(e(ie?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${pn()}+S`}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{Ct()},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:e(ie?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${pn()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${pn()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,f(e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ni(!ie),className:$("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ie?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(ie?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ie?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(jn,{onOpenChange:Rt,children:[s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Nn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(Fn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ai.map(h=>s.jsxs(Es,{className:"flex items-center gap-2",onClick:()=>{Oi(h)},children:[s.jsx(ll,{label:h.label,iconDataUrl:h.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:h.label})]},h.id)),zi?s.jsxs(Es,{className:"flex items-center gap-2",onClick:()=>{Ii(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Q&&!Ve&&!st&&s.jsxs(s.Fragment,{children:[f(e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Ie(!de),className:$("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",de?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(de?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),_==="edit"&&s.jsxs(s.Fragment,{children:[f(e("filesView.editor.findInFile"),s.jsx(V,{variant:"ghost",size:"sm",onClick:h=>{ge(!se),h.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),f(e("filesView.editor.goToLine"),s.jsx(V,{variant:"ghost",size:"sm",onClick:h=>{_s(S=>!S),h.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(tl,{open:Mi,onOpenChange:_s,view:Me.current,variant:"inline"})]})]}),Ys&&Re&&!is&&!Gt&&s.jsx(mn,{currentMode:_==="view"?"preview":"edit",onToggle:()=>{Qi(_==="view"?"edit":"view")}}),pt&&f(e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>gr(le()==="preview"?"edit":"preview"),className:$("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",le()==="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:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:le()==="preview"?"eye":"eye-off",className:"size-4"})})),xn(c?.path??"")&&s.jsx(mn,{currentMode:vr(),onToggle:()=>{ta(vr()==="preview"?"edit":"preview")}}),pt&&le()==="preview"&&Bi&&s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(gs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{gs?vi():D.trim()&&gi(D)},children:gs?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(vt,{sideOffset:8,children:e(gs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),as&&s.jsxs(s.Fragment,{children:[s.jsx(mn,{currentMode:fe,onToggle:()=>sa(fe==="preview"?"edit":"preview")}),fe==="preview"&&s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{const h=An.current?.getXml();if(Ne.current&&(clearTimeout(Ne.current),Ne.current=null),c?.path&&h){if(!await sn(c.path,h))return;xs(!0),setTimeout(()=>xs(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:ji?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),is&&f(e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>ea(Oe==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Oe==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Oe==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Ji&&f(e("filesView.editor.copyFileContents"),s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{(await As(D)).ok?(Ln(!0),ts.current!==null&&window.clearTimeout(ts.current),ts.current=window.setTimeout(()=>{Ln(!1)},1200)):L.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Ei?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),Yi&&f(e("filesView.editor.copyFilePathTitle",{path:ht}),s.jsx(V,{variant:"ghost",size:"sm",onClick:async()=>{(await As(ht)).ok?(On(!0),ss.current!==null&&window.clearTimeout(ss.current),ss.current=window.setTimeout(()=>{On(!1)},1200)):L.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ht}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ht}),children:Pi?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&f(e("filesView.editor.saveFile"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{const h=n.downloadFile;h&&h(c.path).catch(S=>{console.error("Download failed:",S),L.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?f(e("filesView.editor.exitFullscreen"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>X(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!p&&d==="full"&&f(e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>X(!G),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(G?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:G?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},an=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ai,{open:$s,onOpenChange:t=>{t||It(!0)},children:s.jsxs(li,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(oi,{children:[s.jsx(ci,{children:e("filesView.unsaved.title")}),s.jsx(di,{children:e("filesView.unsaved.description")})]}),s.jsxs(ui,{children:[s.jsx(V,{variant:"outline",onClick:()=>{_i()},disabled:At,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(V,{variant:"destructive",onClick:Gi,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:$("flex flex-col flex-shrink-0",R&&"border-b border-border/40"),children:[R?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[p&&te&&s.jsx("button",{type:"button",onClick:()=>I(!1),"aria-label":e("filesView.editor.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:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),p?c?s.jsxs(jn,{children:[s.jsx(Nn,{asChild:!0,children:s.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":e("filesView.editor.openFilesAria"),children:[s.jsx(Rs,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(si,{name:c.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Fn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Mt.map(t=>{const r=c?.path===t.path;return s.jsxs(Es,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}r||pe(t)},className:$("flex min-w-0 items-center justify-between gap-2 overflow-hidden",r&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Rs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(si,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),fr(t.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":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Mt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Tn.left&&s.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"}),Tn.right&&s.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"}),s.jsx("div",{ref:Ls,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Mt.map(t=>{const r=c?.path===t.path;return s.jsxs("div",{title:Ps(a,t.path),className:$("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:[s.jsx(Rs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{r||pe(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),fr(t.path)},className:$("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!r&&!F&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Xn||p)&&c?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ht&&!p?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ht,children:ht}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:rn({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[c&&!se&&!(Xn||p)&&s.jsx("div",{ref:ue,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{rt.current>0||ve(!1)},children:ne?rn():s.jsxs("div",{className:"flex items-center gap-1",children:[pt?s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>gr(le()==="preview"?"edit":"preview"),className:$("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",le()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:le()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e(le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>ve(!0),children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>ve(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:c?Ee||Sr||kr?B?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Qe?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Qe}):Q?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Cr,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},yr)}):Ve?Dr(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(r=>{console.error("Download failed:",r),L.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&as&&fe==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(il,{ref:An,xml:ra,onChange:na},`${c.path}:${it}`)}):c&&is&&Oe==="tree"?s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Aa,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&pt&&le()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(qr,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):c&&Gt&&xe==="preview"?aa?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!u.isVSCode&&jr===Ts?(()=>{const t=c.path.split("/").map(r=>encodeURIComponent(r)).join("/");return cn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:u.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},ia)}):c&&Ys&&_==="view"?Vr(c,W):s.jsxs("div",{className:$("relative h-full",Ut&&"overflow-hidden"),ref:Fi,children:[s.jsx("div",{className:$("h-full",Ut&&"invisible"),children:s.jsx(Jr,{value:W,onChange:Z,readOnly:!Re,vimMode:qn==="vim",extensions:xr,className:"h-full",blockWidgets:oa,onViewReady:t=>{Me.current=t,Ws(r=>r+1),window.requestAnimationFrame(()=>{_t(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null),Ws(t=>t+1)},enableSearch:!0,searchOpen:se,onSearchOpenChange:ge,highlightLines:A?{start:Math.min(A.start,A.end),end:Math.max(A.start,A.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,r,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const o=t.state.doc.lineAt(r.from).number;if(A&&!l.shiftKey&&Math.min(A.start,A.end)===o&&Math.max(A.start,A.end)===o)return Ae(null),rs(),Bt.current=!1,ut.current=null,$t(!1),!0;if(p&&A&&!l.shiftKey){const f=Math.min(A.start,A.end,o),h=Math.max(A.start,A.end,o);return Ae({start:f,end:h}),Bt.current=!1,ut.current=null,$t(!1),!0}if(Bt.current=!0,ut.current=o,$t(!0),A&&l.shiftKey){const f=Math.min(A.start,o),h=Math.max(A.end,o);Ae({start:f,end:h})}else Ae({start:o,end:o});return!0},mouseover:(t,r,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Bt.current||ut.current===null)return!1;const o=t.state.doc.lineAt(r.from).number,f=Math.min(ut.current,o),h=Math.max(ut.current,o);return Ae({start:f,end:h}),$t(!0),!1},mouseup:()=>(Bt.current=!1,ut.current=null,$t(!1),!1)}}})}),Ut&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),ca=!!(a&&Rn[a]),Rr=a?hs[a]:null,Er=s.jsxs("section",{className:$("flex min-h-0 flex-col overflow-hidden",p?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:$("flex flex-col gap-2 py-2",p?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Ms,{ref:ee,value:E,onChange:t=>P(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{P(""),ee.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Hs("createFile",{path:C,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>Hs("createFolder",{path:C,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(mt,{children:[s.jsx(gt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>{js()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(vt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(fn,{outerClassName:"flex-1 min-h-0",className:$("py-2",p?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:mi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Pn.length>0?Pn.map(t=>{const r=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{pe(t)},className:$("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",r?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[hi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):Rr?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:Rr}),s.jsxs(V,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{js()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):ca?hr(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),da=d==="full"&&G&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:rn({exitFullscreenOnly:!0})}),s.jsx(fn,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||Sr||kr?B?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Qe?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Qe}):Q?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Cr,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},yr)}):Ve?Dr(c):st?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(r=>{console.error("Download failed:",r),L.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):pt&&le()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(hn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(qr,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Ys&&_==="view"?Vr(c,W):s.jsxs("div",{className:$("relative h-full",Ut&&"overflow-hidden"),children:[s.jsx("div",{className:$("h-full",Ut&&"invisible"),children:s.jsx(Jr,{value:W,onChange:Z,readOnly:!Re,vimMode:qn==="vim",extensions:xr,className:"h-full",onViewReady:t=>{Me.current=t,window.requestAnimationFrame(()=>{_t(t)})},onViewDestroy:()=>{Me.current&&(Me.current=null)}})}),Ut&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(wl,{activeDialog:St,dialogData:kt,dialogInputValue:dt,onDialogInputChange:In,isDialogSubmitting:Ci,onDialogSubmit:Ui,onClose:la,inputRef:bi}),da,p?te?an:Er:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:an})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Er}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:an})]})]})};function yl(d){return d+1}const Ml=Object.freeze(Object.defineProperty({__proto__:null,FilesView:bl},Symbol.toStringTag,{value:"Module"}));export{il as D,bl as F,Ml as a,Vs as u};