@openchamber/web 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
- package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
- package/dist/assets/FilesView-B_NJFLBH.js +17 -0
- package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
- package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
- package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
- package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
- package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
- package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
- package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
- package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
- package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
- package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
- package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
- package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
- package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
- package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
- package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
- package/dist/assets/de-D4hpTCNY.js +10 -0
- package/dist/assets/es-Bw9m3H62.js +16 -0
- package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
- package/dist/assets/fr-Bhll42P0.js +14 -0
- package/dist/assets/index-Btd2mmYT.js +42 -0
- package/dist/assets/index-C-7hQnEc.css +1 -0
- package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
- package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
- package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
- package/dist/assets/ja-CsHoT43d.js +16 -0
- package/dist/assets/ko-BBNdtFa4.js +16 -0
- package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
- package/dist/assets/main-kYkr_urz.js +1000 -0
- package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
- package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
- package/dist/assets/mobile-CviaXnnU.js +2 -0
- package/dist/assets/nl-DszyktfH.js +16 -0
- package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
- package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
- package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
- package/dist/assets/pl-Bk9_mUXc.js +16 -0
- package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
- package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
- package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
- package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
- package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
- package/dist/assets/space-close-C1tL-_0t.js +1 -0
- package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
- package/dist/assets/tr-C_13w7CX.js +7 -0
- package/dist/assets/uk-BZTsG-q_.js +16 -0
- package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
- package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
- package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
- package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
- package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
- package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
- package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
- package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
- package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
- package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
- package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
- package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
- package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +4 -4
- package/server/index.js +58 -1
- package/server/lib/browser-control/DOCUMENTATION.md +8 -1
- package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
- package/server/lib/dev-tunnel/runtime.js +94 -38
- package/server/lib/dev-tunnel/tunnel.test.js +16 -2
- package/server/lib/dictation/DOCUMENTATION.md +23 -10
- package/server/lib/dictation/audio.js +28 -0
- package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
- package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
- package/server/lib/dictation/local/worker-client.js +28 -10
- package/server/lib/dictation/local/worker-process.js +25 -1
- package/server/lib/dictation/stream-manager.js +160 -53
- package/server/lib/dictation/stream-manager.test.js +108 -7
- package/server/lib/enterprise-mode.d.ts +2 -0
- package/server/lib/enterprise-mode.js +84 -9
- package/server/lib/enterprise-mode.test.js +115 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -2
- package/server/lib/fs/routes.js +28 -1
- package/server/lib/fs/routes.test.js +31 -5
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +61 -2
- package/server/lib/git/service.test.js +141 -0
- package/server/lib/github/DOCUMENTATION.md +18 -0
- package/server/lib/github/checks-summary.js +76 -0
- package/server/lib/github/pr-summaries.js +282 -0
- package/server/lib/github/pr-summaries.test.js +209 -0
- package/server/lib/github/routes.js +42 -77
- package/server/lib/github/routes.test.js +77 -0
- package/server/lib/inherited-env.js +51 -0
- package/server/lib/inherited-env.test.js +59 -0
- package/server/lib/message-search/DOCUMENTATION.md +83 -0
- package/server/lib/message-search/indexer.js +336 -0
- package/server/lib/message-search/indexer.test.js +341 -0
- package/server/lib/message-search/routes.js +92 -0
- package/server/lib/message-search/runtime.js +234 -0
- package/server/lib/message-search/runtime.test.js +108 -0
- package/server/lib/message-search/sqlite.js +74 -0
- package/server/lib/message-search/store.js +289 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +1 -1
- package/server/lib/openchamber-control/service.js +21 -2
- package/server/lib/openchamber-control/service.test.js +50 -0
- package/server/lib/openchamber-sessions/routes.js +15 -0
- package/server/lib/openchamber-sessions/routes.test.js +31 -0
- package/server/lib/opencode/DOCUMENTATION.md +43 -38
- package/server/lib/opencode/auth.d.ts +24 -0
- package/server/lib/opencode/auth.js +130 -66
- package/server/lib/opencode/auth.test.js +114 -70
- package/server/lib/opencode/compatibility.js +4 -3
- package/server/lib/opencode/compatibility.test.js +10 -10
- package/server/lib/opencode/feature-routes-runtime.js +3 -0
- package/server/lib/opencode/lifecycle.js +21 -12
- package/server/lib/opencode/lifecycle.test.js +38 -5
- package/server/lib/opencode/provider-source-route.test.js +55 -2
- package/server/lib/opencode/routes.js +17 -4
- package/server/lib/opencode/settings-helpers.js +6 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +16 -0
- package/server/lib/opencode/settings-runtime.js +9 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/v1-migration-topup.js +13 -3
- package/server/lib/opencode/v2-install.test.js +13 -13
- package/server/lib/quota/DOCUMENTATION.md +11 -5
- package/server/lib/quota/providers/claude/auth.js +19 -6
- package/server/lib/quota/providers/claude/auth.test.js +22 -9
- package/server/lib/quota/providers/claude/index.js +3 -3
- package/server/lib/quota/providers/claude/index.test.js +3 -2
- package/server/lib/quota/providers/cline-pass.js +4 -4
- package/server/lib/quota/providers/codex.js +3 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +4 -5
- package/server/lib/quota/providers/copilot.test.js +1 -1
- package/server/lib/quota/providers/deepseek.js +3 -4
- package/server/lib/quota/providers/deepseek.test.js +1 -1
- package/server/lib/quota/providers/google/auth.js +1 -3
- package/server/lib/quota/providers/google/index.js +3 -2
- package/server/lib/quota/providers/hyper.js +4 -4
- package/server/lib/quota/providers/index.js +9 -2
- package/server/lib/quota/providers/index.test.js +5 -3
- package/server/lib/quota/providers/kimi.js +16 -11
- package/server/lib/quota/providers/kimi.test.js +81 -38
- package/server/lib/quota/providers/minimax-shared.js +3 -4
- package/server/lib/quota/providers/nanogpt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.js +3 -4
- package/server/lib/quota/providers/neuralwatt.test.js +1 -1
- package/server/lib/quota/providers/openai.js +2 -8
- package/server/lib/quota/providers/opencode-go.js +5 -5
- package/server/lib/quota/providers/opencode-go.test.js +1 -1
- package/server/lib/quota/providers/openrouter.js +30 -6
- package/server/lib/quota/providers/openrouter.test.js +122 -1
- package/server/lib/quota/providers/wafer.js +3 -4
- package/server/lib/quota/providers/xai.js +12 -12
- package/server/lib/quota/providers/zai.js +3 -4
- package/server/lib/quota/providers/zai.test.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/routing/DOCUMENTATION.md +4 -0
- package/server/lib/routing/runtime.js +45 -4
- package/server/lib/routing/runtime.test.js +35 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
- package/server/lib/scheduled-tasks/chats-scope.js +50 -0
- package/server/lib/scheduled-tasks/runtime.js +57 -23
- package/server/lib/scheduled-tasks/runtime.test.js +103 -1
- package/server/lib/scheduled-tasks/service.js +37 -29
- package/server/lib/scheduled-tasks/service.test.js +39 -0
- package/server/lib/spaces/DOCUMENTATION.md +54 -9
- package/server/lib/spaces/host.js +24 -3
- package/server/lib/spaces/journey.js +111 -11
- package/server/lib/spaces/journey.test.js +189 -8
- package/server/lib/spaces/places/docker-disk.js +151 -0
- package/server/lib/spaces/places/docker-disk.test.js +167 -0
- package/server/lib/spaces/places/docker-tools.js +11 -1
- package/server/lib/spaces/places/docker.js +4 -2
- package/server/lib/spaces/places/fake-docker.js +36 -2
- package/server/lib/spaces/routes.js +21 -4
- package/server/lib/spaces/routes.test.js +6 -2
- package/server/lib/spaces/space-archive.js +275 -0
- package/server/lib/spaces/space-archive.test.js +194 -0
- package/server/lib/spaces/space-opencode.js +139 -6
- package/server/lib/spaces/space-opencode.test.js +82 -1
- package/server/lib/spaces/space-records.js +3 -0
- package/server/lib/spaces/space-setup.js +10 -5
- package/server/lib/spaces/space-setup.test.js +8 -2
- package/server/lib/terminal/DOCUMENTATION.md +1 -0
- package/server/lib/terminal/runtime.js +6 -1
- package/server/lib/terminal/runtime.test.js +19 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +8 -8
- package/dist/assets/FilesView-CN34wm_N.js +0 -17
- package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
- package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
- package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
- package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
- package/dist/assets/SettingsWindow-CofS020b.js +0 -1
- package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
- package/dist/assets/de-DlgBHUAI.js +0 -10
- package/dist/assets/es-BC8G41U8.js +0 -16
- package/dist/assets/fr-I0z3vVjy.js +0 -14
- package/dist/assets/index-CgR5rJq_.js +0 -41
- package/dist/assets/index-adyy_sEk.css +0 -1
- package/dist/assets/ja-BIElEsY8.js +0 -16
- package/dist/assets/ko-DRnnHetA.js +0 -16
- package/dist/assets/main-DVX34beR.js +0 -886
- package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
- package/dist/assets/mobile-BrlBrNfZ.js +0 -2
- package/dist/assets/nl-DzUV-kwp.js +0 -16
- package/dist/assets/pl-Bb-cb7k7.js +0 -16
- package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
- package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
- package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
- package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
- package/dist/assets/tr-DXEDSoYO.js +0 -7
- package/dist/assets/uk-C8hN--q_.js +0 -16
- package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
- package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
- package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
- package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
- package/server/lib/opencode/credential-db.js +0 -144
- package/server/lib/opencode/credential-db.test.js +0 -104
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{f as Ee,R as i,j as s,c as As,r as St}from"./vendor-react-BUCujlKS.js";import{be as ac,a as ot,h as Ls,a1 as oc,a2 as lc,a3 as cc,a4 as uc,A as st,u as at,eR as dc,N as Ra,F as fc,aa as mc,am as Ta,eO as hc,e as pc,eP as gc,b4 as xc,eQ as vc}from"./index-Btd2mmYT.js";import{f as Ge,bu as lo,z as Ma,as as co,cq as wc,I as V,h as Y,lM as bc,h0 as yc,a1 as _n,B as W,dl as Cc,dn as jc,dc as Sc,dm as Nc,dk as Fc,kF as zr,c9 as $r,iT as Ec,lN as kc,lO as Rc,aK as On,hS as Tc,hQ as Mc,a4 as Vc,T as Pc,K as Nr,au as Dc,cK as Ac,t as J,eK as Va,jz as Lc,hh as zc,l as Pa,aI as Fr,cD as zn,de as Ic,b as Oc,lP as In,cc as Bc,aJ as Er,lQ as kr,cE as Da,cF as Aa,lR as La,lS as za,lT as _c,lU as $c,lV as Wc,lW as Uc,iy as Kc,lX as Hc,lY as Ia,lZ as qc,cd as uo,ce as fo,cf as mo,cg as ho,ch as po,ci as go,aC as Ir,aD as Or,aF as Br,bs as zs,cj as Rr,aL as Rs,cy as Tr,ao as Wt,ap as Ut,aq as Kt,ca as Gc,cb as Xc,g as Os,bt as Yc,cJ as Jc}from"./useAppFontEffects-CeMgbeVa.js";import{v as Zc,b1 as Qc,b2 as eu,b0 as tu,al as nu,am as su,an as ru,ao as iu,ap as au}from"./runtimeEndpointReset-Cu6RUve4.js";import{c as Oa,s as ou,P as mn,C as lu}from"./shikiHighlight-CcVzlYit.js";import{a as xo,E as cu,i as vo,S as wo,R as _r,l as uu}from"./vendor-codemirror-state--21VQleR.js";import{E as lt,k as Wr,e as du,i as fu,j as mu,g as hu,V as pu,G as gu}from"./vendor-codemirror-view-8PpN-8l4.js";import{v as xu,A as vu,B as wu,C as bu}from"./vendor-codemirror-language-CZcLdzDM.js";import{a as yu,u as Ts,b as Cu,c as ju,G as Su}from"./fileTreeStatus-CvPnAWSi.js";import{V as Nu,J as Fu,F as Eu}from"./JsonTreeView-u4yx65zn.js";import{ensurePierreThemeRegistered as Ba,getResolvedShikiTheme as ku}from"./appThemeRegistry-DU-UKEHq.js";import{V as Ru,W as Tu}from"./Virtualizer-CZlLSacm.js";import{V as Mu}from"./Virtualizer-D_a8gKmg.js";import{D as Vu}from"./vendor-react-drawio-Ct3Q0DsD.js";import{m as Pu,P as Du}from"./PluginPane-rZvoMQSi.js";import{e as Au,h as Lu}from"./vendor-codemirror-search-BZNojiZO.js";import{a as zu,b as Iu}from"./vendor-codemirror-autocomplete-DetzHhtC.js";import{p as Ou}from"./parseDiffFromFile-DeZzEah8.js";import{I as Bu,u as _u,n as $u}from"./useInlineCommentController-U97JJifS.js";import{b as Wu}from"./CodeMirrorCommentWidgets-qlshRzAf.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-CxRSdNoV.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-opencode-client-Byb4ZSqI.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-DWgyZK2k.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.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-tanstack-react-virtual--0sBrLRh.js";import"./vendor-tanstack-virtual-core-BoA4iGMw.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-sonner-DFyL3AvE.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-lezer-highlight-CDMHUZ74.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-lang-javascript-Kgp6fZRE.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CkdBRvqj.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-DY4CGDG2.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CQnNjmg9.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CdG1RXm1.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B8HKnqZy.js";import"./vendor-codemirror-lang-python-B4MRHRva.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ConqfjLn.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./space-apply-CgJ5JYPK.js";import"./openSessionFromRoute-BIlcJIf3.js";import"./GuestAttachDialog-DO4x4vIR.js";import"./vendor-cron-parser-CjvYVigk.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-replit-codemirror-vim-EX7OnecQ.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./computeVirtualFileMetrics-BmhViPMt.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./isFilePlainText-n8k0lMTZ.js";import"./textMateThemeFromAppTheme-CAOCeVjl.js";import"./vendor-diff-C3JhlQdm.js";function _a(r){const e=Ee.c(56),{containerRef:t,filePath:a,fileContent:h}=r,{t:f}=Ge(),{isMobile:p}=lo(),m=Ma(Zu),x=Ma(Ju),C=co(),u=wc(Yu),[w,S]=i.useState(null),[j,T]=i.useState(""),[b,E]=i.useState(!1),y=i.useRef(!1),l=i.useRef(null),M=i.useRef(null),[R,D]=i.useState(null);let z;e[0]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{S(null),T(""),E(!1),y.current=!1,M.current=null,D(null)},e[0]=z):z=e[0];const k=z;let A,O;e[1]!==t?(A=()=>{const G=t.current;if(!G)return;const X=()=>{if(y.current)return;const me=window.getSelection(),xe=me?.toString().trim()??"";if(!me||!xe||me.rangeCount===0){k();return}const he=me.getRangeAt(0);if(!G.contains(he.commonAncestorContainer)){k();return}const le=he.getBoundingClientRect();M.current=he.cloneRange(),T(xe),S({x:le.left+le.width/2,y:le.top-10})},re=me=>{l.current?.contains(me.target)||y.current&&k()};return document.addEventListener("selectionchange",X),document.addEventListener("pointerdown",re),()=>{document.removeEventListener("selectionchange",X),document.removeEventListener("pointerdown",re)}},O=[t,k],e[1]=t,e[2]=A,e[3]=O):(A=e[2],O=e[3]),i.useEffect(A,O);let F;e[4]!==h?(F=G=>{const X=ue=>h.slice(0,ue).split(`
|
|
2
|
+
`).length,re=Gu,me=(ue,Ye)=>{for(const Ie of re(ue)){const we=h.indexOf(Ie,Ye);if(we>=0)return we}return-1},xe=G.length>=8?h.indexOf(G):-1;if(xe>=0){const ue=X(xe);return{start:ue,end:ue+G.split(`
|
|
3
|
+
`).length-1}}const he=G.split(`
|
|
4
|
+
`).map(qu).filter(Boolean);if(he.length===0)return null;const le=me(he[0],0);if(le<0)return null;const ye=X(le);if(he.length===1)return{start:ye,end:ye};const Ce=me(he[he.length-1],le);return Ce<0?null:{start:ye,end:Math.max(ye,X(Ce))}},e[4]=h,e[5]=F):F=e[5];const P=F;let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{const G=M.current;if(!G){D(null);return}D(bc(G))},e[6]=I):I=e[6];const K=I;let B,U;e[7]!==b?(B=()=>{if(!b)return;let G=null;const X=()=>{G===null&&(G=window.requestAnimationFrame(()=>{G=null,K()}))};return document.addEventListener("scroll",X,{capture:!0,passive:!0}),window.addEventListener("resize",X),()=>{G!==null&&window.cancelAnimationFrame(G),document.removeEventListener("scroll",X,{capture:!0}),window.removeEventListener("resize",X)}},U=[b,K],e[7]=b,e[8]=B,e[9]=U):(B=e[8],U=e[9]),i.useEffect(B,U);let ne;e[10]!==j?(ne=()=>{j&&(E(!0),y.current=!0,K(),window.getSelection()?.removeAllRanges())},e[10]=j,e[11]=ne):ne=e[11];const Q=ne;let fe;e[12]!==u||e[13]!==m||e[14]!==C||e[15]!==a||e[16]!==x||e[17]!==P||e[18]!==j?(fe=G=>{const X=m??(x?"draft":null);if(!j||!X||!C){k();return}const re=P(j);u({directory:C,sessionKey:X},{source:"file-quote",fileLabel:a,startLine:re?.start??0,endLine:re?.end??0,code:j,language:"",text:G.trim()}),k(),queueMicrotask(Hu)},e[12]=u,e[13]=m,e[14]=C,e[15]=a,e[16]=x,e[17]=P,e[18]=j,e[19]=fe):fe=e[19];const se=fe;if(!w)return null;let ce;e[20]!==b||e[21]!==P||e[22]!==j?(ce=b?P(j):null,e[20]=b,e[21]=P,e[22]=j,e[23]=ce):ce=e[23];const _=ce;let ee;e[24]!==b||e[25]!==R?(ee=b&&R&&R.length>0?s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:R.map(Ku)}):null,e[24]=b,e[25]=R,e[26]=ee):ee=e[26];const ge=ee;let Ae;e[27]!==_?(Ae=_?{start:_.start,end:_.end}:void 0,e[27]=_,e[28]=Ae):Ae=e[28];let Le;e[29]!==a||e[30]!==se||e[31]!==Ae?(Le=s.jsx(Bu,{fileLabel:a,lineRange:Ae,onSave:se,onCancel:k}),e[29]=a,e[30]=se,e[31]=Ae,e[32]=Le):Le=e[32];const ze=Le;if(p){let G;e[33]===Symbol.for("react.memo_cache_sentinel")?(G={paddingBottom:"calc(0.5rem + env(safe-area-inset-bottom, 0px))"},e[33]=G):G=e[33];let X;e[34]!==ze||e[35]!==b||e[36]!==Q||e[37]!==f?(X=s.jsx("div",{ref:l,className:"pointer-events-auto mx-auto max-w-[420px] px-3",style:G,children:b?ze:s.jsx("div",{className:Y("mx-auto w-fit","oc-glass-popover rounded-full border border-[var(--interactive-border)]","p-1 shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]"),children:s.jsxs("button",{type:"button",onMouseDown:Uu,onClick:Q,className:Y("flex min-w-0 items-center gap-2 rounded-full px-4 py-2","text-sm font-medium leading-tight text-foreground","active:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:f("chat.textSelection.title.commentOnSelection"),children:[s.jsx(V,{name:"chat-1",className:"size-4 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 whitespace-nowrap",children:f("chat.textSelection.actions.comment")})]})})}),e[34]=ze,e[35]=b,e[36]=Q,e[37]=f,e[38]=X):X=e[38];let re;return e[39]!==ge||e[40]!==X?(re=As.createPortal(s.jsxs("div",{className:"oc-keyboard-inset-surface pointer-events-none fixed inset-x-0 bottom-0 z-50",children:[ge,X]}),document.body),e[39]=ge,e[40]=X,e[41]=re):re=e[41],re}let Ne;e[42]!==w.x||e[43]!==w.y?(Ne={left:w.x,top:w.y,transform:"translate(-50%, -100%)"},e[42]=w.x,e[43]=w.y,e[44]=Ne):Ne=e[44];let Xe;e[45]!==ge?(Xe=ge?As.createPortal(ge,document.body):null,e[45]=ge,e[46]=Xe):Xe=e[46];let Z;e[47]!==ze||e[48]!==b||e[49]!==Q||e[50]!==f?(Z=b?s.jsx("div",{className:"w-[min(420px,80vw)]",children:ze}):s.jsx("div",{className:Y("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:s.jsx("button",{type:"button",onClick:Q,className:Y("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-foreground","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:f("chat.textSelection.title.commentOnSelection"),children:f("chat.textSelection.actions.comment")})}),e[47]=ze,e[48]=b,e[49]=Q,e[50]=f,e[51]=Z):Z=e[51];let ke;return e[52]!==Ne||e[53]!==Xe||e[54]!==Z?(ke=As.createPortal(s.jsxs("div",{ref:l,className:"fixed z-50",style:Ne,children:[Xe,Z]}),document.body),e[52]=Ne,e[53]=Xe,e[54]=Z,e[55]=ke):ke=e[55],ke}function Uu(r){return r.preventDefault()}function Ku(r,e){return s.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:r.left,top:r.top,width:r.width,height:r.height}},e)}function Hu(){yc()}function qu(r){return r.trim()}function Gu(r){const e=r.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(Xu)}function Xu(r){return r.length>=8}function Yu(r){return r.addDraft}function Ju(r){return r.newSessionDraft?.open}function Zu(r){return r.currentSessionId}const Qu=(r,e)=>{if(!e)return null;const t=Number.parseInt(r.trim(),10);return!Number.isFinite(t)||t<1?null:Math.min(t,e.state.doc.lines)},$a=(r,e)=>{const t=r.state.doc.lineAt(e.main.head);return{lineNumber:t.number,character:e.main.head-t.from+1,selection:e}},Wa=(r,e,t)=>{const a=r.state.doc.line(e),h=Math.max(1,Math.min(t,a.length+1)),f=a.from+h-1;r.dispatch({selection:xo.cursor(f),effects:lt.scrollIntoView(f,{y:"center"})})};function ed({open:r,onOpenChange:e,view:t,variant:a="overlay"}){const{t:h}=Ge(),[f,p]=i.useState(""),m=i.useRef(null),x=i.useRef(!1),C=i.useRef(null),u=i.useRef(null),w=i.useMemo(()=>Qu(f,t),[f,t]);i.useEffect(()=>{!r||!t||(x.current=!1,m.current=$a(t,t.state.selection),p(""))},[r,t]),i.useEffect(()=>{r&&window.requestAnimationFrame(()=>{u.current?.focus(),u.current?.select()})},[r]),i.useEffect(()=>{if(!(!r||!t||!m.current)){if(w===null){const{selection:y}=m.current;t.dispatch({selection:y,effects:lt.scrollIntoView(y.main.from,{y:"center"})});return}Wa(t,w,m.current.character)}},[w,r,t]);const S=i.useCallback(()=>{if(!t||x.current||!m.current)return;const{selection:y}=m.current;t.dispatch({selection:y,effects:lt.scrollIntoView(y.main.from,{y:"center"})})},[t]),j=i.useRef(r);i.useEffect(()=>{j.current&&!r&&S(),j.current=r},[r,S]);const T=i.useCallback(y=>{y||S(),e(y)},[e,S]),b=i.useCallback(()=>{!t||w===null||!m.current||(x.current=!0,Wa(t,w,m.current.character),e(!1),t.focus())},[w,e,t]);i.useEffect(()=>{if(!r)return;const y=M=>{const R=C.current,D=M.target;!R||!(D instanceof Element)||R.contains(D)||D.closest("[data-go-to-line-toggle]")||T(!1)},l=M=>{M.key==="Escape"&&(M.preventDefault(),T(!1))};return document.addEventListener("pointerdown",y,!0),document.addEventListener("keydown",l,!0),()=>{document.removeEventListener("pointerdown",y,!0),document.removeEventListener("keydown",l,!0)}},[T,r,a]);const E=i.useMemo(()=>{if(!t)return h("goToLineDialog.helper.editorUnavailable");if(w===null){const y=m.current??$a(t,t.state.selection);return h("goToLineDialog.helper.currentLineRange",{current:y.lineNumber,max:t.state.doc.lines})}return h("goToLineDialog.helper.goToLine",{line:w})},[w,h,t]);return a==="inline"?r?s.jsxs("div",{ref:C,"data-editor-overlay":!0,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(_n,{ref:u,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:y=>p(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),b())},placeholder:h("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(W,{variant:"outline",size:"xs",onClick:b,disabled:!t||w===null,className:"h-6 px-2",children:h("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:C,"data-editor-overlay":!0,className:Y("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",r?"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(_n,{ref:u,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:y=>p(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),b())},placeholder:h("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-surface-elevated/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:E})]})})}const td=new Map(Object.entries({FunctionDeclaration:"function",FunctionDefinition:"function",FunctionItem:"function",FunctionDecl:"function",MethodDeclaration:"method",MethodDecl:"method",ClassDeclaration:"class",ClassDefinition:"class",InterfaceDeclaration:"class",StructItem:"class",TraitItem:"class",ImplItem:"class",TypeAliasDeclaration:"type",EnumDeclaration:"type",EnumItem:"type",TypeSpec:"type",ModItem:"module"})),nd=new Map([["VariableDeclaration","function"],["PropertyDeclaration","method"]]),sd=new Set(["ArrowFunction","FunctionExpression"]),rd=new Set(["VariableDefinition","PropertyDefinition","TypeDefinition","VariableName","DefName","FieldName","BoundIdentifier","TypeIdentifier"]),bo=/^(?:ATXHeading|SetextHeading)([1-6])$/,yo=(r,e)=>{for(let t=r.firstChild;t;t=t.nextSibling)if(e.has(t.name))return t;return null},id=r=>{if(bo.test(r.name))return"heading";const e=td.get(r.name);if(e)return e;const t=nd.get(r.name);return t&&yo(r,sd)?t:null},ad=(r,e)=>r.doc.lineAt(e.from).text.replace(/^\s{0,3}#{1,6}\s*/,"").replace(/\s+#+\s*$/,"").trim(),od=(r,e=200)=>{const t=xu(r,r.doc.length,e);if(!t)return[];const a=[],h=[];return t.iterate({enter:f=>{const p=id(f.node);if(!p)return;let m,x;if(p==="heading")m=ad(r,f.node),x=f.from;else{const u=yo(f.node,rd);if(!u)return;m=r.sliceDoc(u.from,u.to),x=u.from}if(!m)return;for(;h.length>0&&h[h.length-1]<=f.from;)h.pop();const C=p==="heading"?Number(bo.exec(f.name)?.[1]??1)-1:h.length;a.push({name:m,kind:p,line:r.doc.lineAt(x).number,from:x,depth:C}),p!=="heading"&&h.push(f.to)}}),a},ld={function:"braces",method:"braces",class:"box-3",type:"code-box",module:"folder-3",heading:"text"},cd="data-document-symbols-toggle";function Ua(r){const e=Ee.c(44),{open:t,onOpenChange:a,view:h}=r,{t:f}=Ge(),p=i.useRef(null);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0];const[x,C]=i.useState(m),[u,w]=i.useState("");let S,j;e[1]!==t||e[2]!==h?(S=()=>{t&&(w(""),C(h?od(h.state):[]))},j=[t,h],e[1]=t,e[2]=h,e[3]=S,e[4]=j):(S=e[3],j=e[4]),i.useEffect(S,j);let T;e[5]!==a||e[6]!==h?(T=()=>{a(!1),h?.focus()},e[5]=a,e[6]=h,e[7]=T):T=e[7];const b=T;let E,y;e[8]!==a||e[9]!==t?(E=()=>{if(!t)return;const B=U=>{const ne=U.target;!(ne instanceof Element)||!p.current||p.current.contains(ne)||ne.closest(`[${cd}]`)||a(!1)};return document.addEventListener("pointerdown",B,!0),()=>document.removeEventListener("pointerdown",B,!0)},y=[a,t],e[8]=a,e[9]=t,e[10]=E,e[11]=y):(E=e[10],y=e[11]),i.useEffect(E,y);let l;e[12]!==b||e[13]!==h?(l=B=>{h&&h.dispatch({selection:xo.cursor(B.from),effects:lt.scrollIntoView(B.from,{y:"center"})}),b()},e[12]=b,e[13]=h,e[14]=l):l=e[14];const M=l;if(!t)return null;let R;e[15]!==b?(R=B=>{B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),b())},e[15]=b,e[16]=R):R=e[16];let D;e[17]!==f?(D=f("filesView.symbols.placeholder"),e[17]=f,e[18]=D):D=e[18];let z;e[19]!==f?(z=f("filesView.symbols.placeholder"),e[19]=f,e[20]=z):z=e[20];let k;e[21]!==u||e[22]!==z||e[23]!==D?(k=s.jsx(Cc,{autoFocus:!0,value:u,onValueChange:w,placeholder:D,"aria-label":z}),e[21]=u,e[22]=z,e[23]=D,e[24]=k):k=e[24];let A;e[25]!==x.length||e[26]!==f?(A=x.length===0?f("filesView.symbols.noneInFile"):f("filesView.symbols.noMatches"),e[25]=x.length,e[26]=f,e[27]=A):A=e[27];let O;e[28]!==A?(O=s.jsx(jc,{className:"px-3 py-4 typography-meta text-muted-foreground",children:A}),e[28]=A,e[29]=O):O=e[29];let F;if(e[30]!==M||e[31]!==x){let B;e[33]!==M?(B=U=>s.jsxs(Sc,{value:`${U.name}\0${U.from}`,onSelect:()=>M(U),className:"gap-2",children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",style:{paddingLeft:`${U.depth*12}px`},children:[s.jsx(V,{name:ld[U.kind],className:"size-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-foreground",children:U.name})]}),s.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:U.line})]},`${U.from}:${U.name}`),e[33]=M,e[34]=B):B=e[34],F=x.map(B),e[30]=M,e[31]=x,e[32]=F}else F=e[32];let P;e[35]!==O||e[36]!==F?(P=s.jsxs(Nc,{className:"max-h-[min(20rem,calc(100vh-16rem))]",children:[O,F]}),e[35]=O,e[36]=F,e[37]=P):P=e[37];let I;e[38]!==k||e[39]!==P?(I=s.jsxs(Fc,{loop:!0,filter:ud,className:"[&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1 [&_[cmdk-item]]:typography-meta",children:[k,P]}),e[38]=k,e[39]=P,e[40]=I):I=e[40];let K;return e[41]!==I||e[42]!==R?(K=s.jsx("div",{ref:p,"data-editor-overlay":!0,className:"absolute left-3 top-3 z-40 w-[min(28rem,calc(100%-1.5rem))] overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] shadow-lg",onKeyDown:R,children:I}),e[41]=I,e[42]=R,e[43]=K):K=e[43],K}function ud(r,e){return r.split("\0")[0].toLowerCase().includes(e.trim().toLowerCase())?1:0}const dd=(r,e)=>{const t=e.trim().toLowerCase(),a=[];if(!t)return a;const h=r.toLowerCase();let f=0;for(;;){const p=h.indexOf(t,f);if(p===-1)break;a.push({start:p,end:p+t.length}),f=p+t.length}return a},_s="data-md-find",Mr="data-md-find-current",Co="rounded-[2px] bg-status-warning/30 text-foreground",fd="rounded-[2px] bg-status-warning/60 text-foreground",md=120,hd=r=>r instanceof Element&&r.hasAttribute(_s),pd=r=>r.target instanceof Element&&r.target.hasAttribute(_s)?!0:[...r.addedNodes].some(e=>hd(e)),jo=r=>{const e=new Set;r.querySelectorAll(`mark[${_s}]`).forEach(t=>{const a=t.parentNode;a&&(a.replaceChild(document.createTextNode(t.textContent??""),t),e.add(a))}),e.forEach(t=>t.normalize())},gd=(r,e)=>{jo(r);const t=e.trim().toLowerCase();if(!t)return[];const a=[],h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,{acceptNode(p){const m=p.parentElement;return!m||m.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),f=[];for(;h.nextNode();){const p=h.currentNode;p instanceof Text&&f.push(p)}for(const p of f){const m=p.nodeValue??"";if(!m)continue;const x=dd(m,t);if(x.length===0)continue;const C=p.parentNode;if(!C)continue;const u=document.createDocumentFragment();let w=0;for(const S of x){S.start>w&&u.appendChild(document.createTextNode(m.slice(w,S.start)));const j=document.createElement("mark");j.setAttribute(_s,""),j.className=Co,j.textContent=m.slice(S.start,S.end),u.appendChild(j),a.push(j),w=S.end}w<m.length&&u.appendChild(document.createTextNode(m.slice(w))),C.replaceChild(u,p)}return a},Ka=({containerRef:r,open:e,onOpenChange:t,focusNonce:a,className:h})=>{const{t:f}=Ge(),[p,m]=i.useState(""),[x,C]=i.useState(0),[u,w]=i.useState(0),S=i.useRef(null),j=i.useRef([]),T=i.useRef(p);T.current=p;const b=i.useRef(null),E=i.useRef(null),y=i.useCallback((k,A=!1)=>{const O=r.current;if(!O){j.current=[],C(0),w(0);return}j.current=gd(O,k);const F=j.current.length;C(F),w(P=>!A||F===0?0:Math.min(P,F-1))},[r]),l=i.useCallback((k,A=!1)=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null,y(k,A)},md)},[y]);i.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const M=i.useCallback(()=>{t(!1);const k=E.current;E.current=null,k?.isConnected&&k.focus()},[t]);i.useEffect(()=>{const k=r.current;if(!e||!k)return;const A=new MutationObserver(O=>{!T.current.trim()||!O.some(P=>!pd(P))||l(T.current,!0)});return A.observe(k,{childList:!0,subtree:!0,characterData:!0}),()=>{A.disconnect(),jo(k)}},[r,e,l]),i.useEffect(()=>{if(!e)return;const k=document.activeElement;k instanceof HTMLElement&&!E.current&&(E.current=k),S.current?.focus()},[e]),i.useEffect(()=>{e&&a>0&&(S.current?.focus(),S.current?.select())},[e,a]),i.useEffect(()=>{const k=r.current;if(!k||(k.querySelectorAll(`mark[${Mr}]`).forEach(O=>{O.removeAttribute(Mr),O.className=Co}),x===0))return;const A=j.current[Math.min(Math.max(u,0),x-1)];A&&(A.setAttribute(Mr,""),A.className=fd,A.scrollIntoView({block:"nearest"}))},[r,u,x]);const R=i.useCallback(()=>{w(k=>x===0?0:(k+1)%x)},[x]),D=i.useCallback(()=>{w(k=>x===0?0:(k-1+x)%x)},[x]),z=i.useCallback(k=>{k.key==="Enter"?(k.preventDefault(),k.shiftKey?D():R()):k.key==="Escape"&&(k.preventDefault(),M())},[M,R,D]);return e?s.jsxs("div",{className:Y("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",h),children:[s.jsx(V,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),s.jsx(_n,{ref:S,value:p,onChange:k=>{m(k.target.value),l(k.target.value)},onKeyDown:z,placeholder:f("filesView.preview.find.placeholder"),"aria-label":f("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),s.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":x>0?f("filesView.preview.find.countAria",{current:u+1,total:x}):f("filesView.preview.find.noMatches"),children:p.trim()&&x===0?f("filesView.preview.find.noMatches"):x>0?`${u+1}/${x}`:""}),s.jsx(W,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:D,title:f("filesView.preview.find.previousAria"),"aria-label":f("filesView.preview.find.previousAria"),disabled:x===0,children:s.jsx(V,{name:"arrow-up",className:"size-3.5"})}),s.jsx(W,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:R,title:f("filesView.preview.find.nextAria"),"aria-label":f("filesView.preview.find.nextAria"),disabled:x===0,children:s.jsx(V,{name:"arrow-down",className:"size-3.5"})}),s.jsx(W,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:M,title:f("filesView.preview.find.closeAria"),"aria-label":f("filesView.preview.find.closeAria"),children:s.jsx(V,{name:"close",className:"size-3.5"})})]}):null},xd=r=>{let e=!0;return{poll:async()=>{if(!e||r.isDirty())return!1;const t=r.getLoadedContent(),a=r.getLoadedRevision();try{const h=await r.readContent();if(!e||r.isDirty()||a!==r.getLoadedRevision())return!1;if(h===t)return!0;const f=await r.readContent();return!e||r.isDirty()||f!==h||a!==r.getLoadedRevision()?!1:(r.applyContent(h),!0)}catch{return!1}},dispose:()=>{e=!1}}},vd=1,wd=(r,e)=>e.size!==r.size||e.mtimeMs!==void 0&&r.mtimeMs!==void 0&&Math.abs(e.mtimeMs-r.mtimeMs)>=vd;function Ha(){const r=Ee.c(8),[e]=St.useState(bd),t=St.useRef(!1);let a;r[0]!==e?(a=x=>{if(x==null){e.cleanUp(),t.current=!1;return}t.current||(t.current=!0,e.setup(x,x.firstElementChild??void 0))},r[0]=e,r[1]=a):a=r[1];const h=a;let f,p;r[2]!==e?(f=()=>()=>{t.current=!1,e.cleanUp()},p=[e],r[2]=e,r[3]=f,r[4]=p):(f=r[3],p=r[4]),St.useLayoutEffect(f,p);let m;return r[5]!==h||r[6]!==e?(m={virtualizer:e,setScroller:h},r[5]=h,r[6]=e,r[7]=m):m=r[7],m}function bd(){return new Mu}const hn=new Map,yd=100;function Ms(r){const[e,t]=St.useState(null),a=St.useRef(null),h=St.useRef(null),f=St.useRef(null),p=St.useCallback((m,x)=>{m&&x instanceof Nu&&(f.current={key:r,file:x,node:m});const C=a.current,u=h.current,w=()=>{a.current===C&&(C?.(),u?.())};x?queueMicrotask(w):w()},[r]);return St.useLayoutEffect(()=>{if(!e||!r)return;const m=hn.get(r)??{top:0,left:0};let x=!0;const C=()=>f.current?.key===r?f.current.file:null,u=y=>f.current?.key===r?f.current.node.shadowRoot?.querySelector(`[data-line][data-line-index="${y-1}"]`):null,w=()=>{j.disconnect(),T.disconnect()},S=()=>{if(!x)return;const y=C(),l=m.line&&y?.getLinePosition(m.line.number),M=m.line&&u(m.line.number);let R=m.top;m.line&&l&&(R=(y?.top??0)+l.top-m.line.offset),m.line&&M&&(R=e.scrollTop+M.getBoundingClientRect().top-e.getBoundingClientRect().top-m.line.offset),e.scrollTop=R,e.scrollLeft=m.left,(!m.line||M)&&Math.abs(e.scrollTop-R)<1&&Math.abs(e.scrollLeft-m.left)<1&&(x=!1,w())},j=new ResizeObserver(S),T=new MutationObserver(()=>{if(x){for(const y of e.children)j.observe(y);S()}});j.observe(e);for(const y of e.children)j.observe(y);T.observe(e,{childList:!0,subtree:!0});const b=()=>{if(x)return;const y=C(),l=y?.getNumericScrollAnchor(e.scrollTop-(y.top??0)),M=l&&u(l.lineNumber),R=M?M.getBoundingClientRect().top-e.getBoundingClientRect().top:null;if(hn.delete(r),hn.set(r,{top:e.scrollTop,left:e.scrollLeft,line:l&&R!==null&&R>=0&&R<e.clientHeight?{number:l.lineNumber,offset:R}:void 0}),hn.size>yd){const D=hn.keys().next().value;D!==void 0&&hn.delete(D)}},E=()=>{x=!1,w()};return a.current=S,h.current=b,S(),e.addEventListener("scroll",b,{passive:!0}),e.addEventListener("wheel",E,{passive:!0}),e.addEventListener("touchstart",E,{passive:!0}),e.addEventListener("pointerdown",E,{passive:!0}),e.addEventListener("keydown",E),()=>{a.current=null,h.current=null,f.current?.key===r&&(f.current=null),w(),e.removeEventListener("scroll",b),e.removeEventListener("wheel",E),e.removeEventListener("touchstart",E),e.removeEventListener("pointerdown",E),e.removeEventListener("keydown",E)}},[r,e]),{setScroller:t,restore:p}}function Cd(r){return!(!r.autoSaveEnabled||!r.isDirty||!r.canWrite||r.isSaving||r.fileLoading||r.isNonEditableBinary||r.wouldEmptyFile||!r.selectedFilePath||r.loadedFilePath!==r.selectedFilePath)}function jd(r){return r.selectedFilePath?r.isDirty?!(r.fileLoading||r.loadedFilePath!==r.selectedFilePath||r.isNonEditableBinary||r.draftContent===""&&r.fileContent!==""&&r.loadedFilePath!==r.selectedFilePath):!0:!1}const So=2e5,Sd=r=>{let e=0,t=0;for(let a=0;a<r.length;a++)r.charCodeAt(a)===10&&(a>0&&r.charCodeAt(a-1)===13?e++:t++);return e>t?`\r
|
|
5
|
+
`:`
|
|
6
|
+
`},No=r=>r.replace(/\r\n/g,`
|
|
7
|
+
`).replace(/\r/g,`
|
|
8
|
+
`),Nd=r=>({content:No(r),lineEnding:Sd(r)}),Fd=(r,e)=>{const t=No(r);return e===`\r
|
|
9
|
+
`?t.replace(/\n/g,`\r
|
|
10
|
+
`):t},Ed=(r,e)=>e??(r.length>So?"view":"edit"),kd=r=>{let e=2166136261;for(let t=0;t<r.length;t++)e^=r.charCodeAt(t),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return`${r.length}:${e.toString(16)}`},Rd='<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 qa(){if(typeof document>"u")return!1;const r=document.documentElement.getAttribute("data-theme");return r==="dark"||!r&&window.matchMedia("(prefers-color-scheme: dark)").matches}const Td=i.forwardRef(function({xml:e,readOnly:t,className:a,onChange:h},f){const p=i.useRef(e),m=i.useRef(null),x=i.useRef(!1),[C,u]=i.useState(qa),w=i.useRef(e),S=i.useRef(e);S.current!==e&&(S.current=e,w.current=e,p.current=e);const j=i.useRef(C);j.current!==C&&(j.current=C,w.current=p.current);const T=i.useRef(null);i.useEffect(()=>{const y=()=>u(qa());y();const l=new MutationObserver(y);return l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>l.disconnect()},[]),i.useEffect(()=>{const y=setTimeout(()=>{T.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(y)},[]),i.useImperativeHandle(f,()=>({getXml:()=>p.current}));const b=i.useCallback(()=>{!e&&!x.current&&(x.current=!0,setTimeout(()=>{m.current?.template({})},500))},[e]),E=i.useCallback(y=>{p.current=y.xml,h?.(y.xml)},[h]);return s.jsx("div",{ref:T,className:Y("h-full w-full",a),children:s.jsx(Vu,{ref:m,xml:w.current||Rd,autosave:!0,urlParameters:{ui:t?"simple":C?"dark":"kennedy",spin:!0,libraries:!t,chrome:t,nav:t,layers:t,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:b,onAutoSave:E},C?"dark":"light")})}),Vr={ok:!0,snapshot:null},Md=r=>r.hasCanvas&&r.viewMode==="preview"&&r.previewReady&&r.mountable,Ga=r=>r.slice(r.replace(/\\/g,"/").lastIndexOf("/")+1)||r,Vd=i.forwardRef(function(e,t){const{guestId:a,editorId:h,title:f,contentKind:p,path:m,content:x,readOnly:C}=e,{t:u}=Ge(),w=i.useRef(e);w.current=e;const S=i.useCallback(y=>Pu(y,{onChange:l=>{l.edited&&w.current.onEdit(),w.current.onDirtyChange(l.dirty)},onSave:()=>w.current.onSaveRequest(),onUnsupported:()=>w.current.onUnsupported()}),[]),[j,T]=i.useState(()=>p==="text"?S({path:m,name:Ga(m),readOnly:C,encoding:"text",content:x}):null),[b]=i.useState(()=>({contentKind:p,path:m,readOnly:C}));i.useEffect(()=>{if(b.contentKind!=="binary")return;let y=!1;return w.current.loadBytes().then(l=>{if(!y){if(l.byteLength>zr){w.current.onTooLarge();return}T(S({path:b.path,name:Ga(b.path),readOnly:b.readOnly,encoding:"binary",bytes:l}))}},()=>{y||w.current.onLoadFailed()}),()=>{y=!0}},[b,S]),i.useImperativeHandle(t,()=>({getContent:async y=>{const l={ok:!1,message:u("filesView.fileEditor.snapshotFailed",{editor:f})};if(!j)return l;try{const M=await j.requestSnapshot(y);return"bytes"in M?p==="binary"?{ok:!0,snapshot:{bytes:M.bytes,signature:M.version}}:l:p==="text"?{ok:!0,snapshot:{content:M.content,signature:M.version}}:l}catch{return l}},markSaved:y=>{j?.markSaved(y),w.current.onDirtyChange(!1)}}),[j,p,u,f]);const E=i.useMemo(()=>j?{editorId:h,channel:j}:null,[j,h]);return E?s.jsx(Du,{mode:ac(a),surface:"file",fileEditor:E}):s.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:u("common.loading")})}),Pd=r=>r.slice(r.replace(/\\/g,"/").lastIndexOf("/")+1),Fo=(r,e)=>{const t=Pd(e);if(!t)return null;for(const a of r)if(!(!a.fileEditors?.length||!Ec(a))){for(const h of a.fileEditors)if(h.match.some(f=>kc(t,f)))return{guestId:a.id,editor:h}}return null},Dd=r=>{const e=Ee.c(3),t=$r(Ad);let a;return e[0]!==r||e[1]!==t?(a=r?Fo(t,r):null,e[0]=r,e[1]=t,e[2]=a):a=e[2],a};function Ad(r){return r.guests}const Ld=wu.filter(r=>r.mac!==void 0),zd=r=>{const e=document.createElement("span");e.className="cm-fold-marker";const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true");const a=document.createElementNS("http://www.w3.org/2000/svg","use");return a.setAttribute("href",r?"#oc-arrow-down-s":"#oc-arrow-right-s"),t.appendChild(a),e.appendChild(t),e},Id=()=>[vu({markerDOM:zd}),Wr.of(Ld),lt.theme({".cm-foldGutter .cm-gutterElement":{display:"flex",alignItems:"center",justifyContent:"center"},".cm-fold-marker":{display:"inline-flex",width:"14px",height:"14px",cursor:"pointer",opacity:"0.6"},".cm-fold-marker:hover":{opacity:"1"},".cm-fold-marker svg":{width:"14px",height:"14px",fill:"currentColor"}})],Od=()=>[bu(),zu(),Wr.of(Iu)],Bd=({vimMode:r})=>[cu.allowMultipleSelections.of(!0),du(),fu(),mu(),r?[]:Wr.of([{key:"Mod-d",run:Au,preventDefault:!0}])],_d=300,$d=1e6,Wd=(r,e)=>{const t=new Map;if(r===e)return t;const a=Ou({name:"file",contents:r},{name:"file",contents:e});for(const h of a.hunks)for(const f of h.hunkContent){if(f.type!=="change")continue;if(f.additions===0){const m=f.additionLineIndex<=0,x=m?1:f.additionLineIndex;t.has(x)||t.set(x,m?"deletedAbove":"deleted");continue}const p=f.deletions===0?"added":"modified";for(let m=0;m<f.additions;m+=1)t.set(f.additionLineIndex+m+1,p)}return t};class Vs extends gu{constructor(e){super(),this.kind=e}eq(e){return e.kind===this.kind}toDOM(){const e=document.createElement("div");return e.className=`cm-git-change cm-git-change-${this.kind}`,e}}const Ud={added:new Vs("added"),modified:new Vs("modified"),deleted:new Vs("deleted"),deletedAbove:new Vs("deletedAbove")},Kd=(r,e)=>{const t=new uu;for(const a of[...e.keys()].sort((h,f)=>h-f)){if(a<1||a>r.lines)continue;const h=e.get(a);h&&t.add(r.line(a).from,r.line(a).from,Ud[h])}return t.finish()},$s=wo.define(),Eo=wo.define(),Ur=vo.define({create:()=>null,update(r,e){for(const t of e.effects)if(t.is($s))return t.value;return r}}),Xa=vo.define({create:()=>_r.empty,update(r,e){for(const t of e.effects){if(t.is(Eo))return t.value;if(t.is($s)&&t.value===null)return _r.empty}return e.docChanged?r.map(e.changes):r}}),Hd=pu.fromClass(class{constructor(r){this.view=r}timer=null;update(r){r.transactions.some(t=>t.effects.some(a=>a.is($s)))?this.schedule(0):r.docChanged&&this.schedule(_d)}schedule(r){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=null;const{state:e}=this.view,t=e.field(Ur),a=e.doc.toString(),h=t!==null&&Math.max(t.length,a.length)>$d,f=t===null||h?_r.empty:Kd(e.doc,Wd(t,a));this.view.dispatch({effects:Eo.of(f)})},r)}destroy(){this.timer&&clearTimeout(this.timer)}}),qd=r=>[Ur,Xa,Hd,hu({class:"cm-git-gutter",markers:e=>e.state.field(Xa)}),lt.theme({".cm-git-gutter":{width:"6px"},".cm-git-gutter .cm-gutterElement":{position:"relative"},".cm-git-change":{position:"absolute",left:"1px",width:"3px",top:"0",bottom:"0"},".cm-git-change-added":{backgroundColor:r.added},".cm-git-change-modified":{backgroundColor:r.modified},".cm-git-change-deleted, .cm-git-change-deletedAbove":{top:"auto",height:"6px",width:"5px",left:"0",backgroundColor:r.removed,clipPath:"polygon(0 0, 100% 50%, 0 100%)"},".cm-git-change-deleted":{bottom:"-3px"},".cm-git-change-deletedAbove":{top:"-3px",bottom:"auto"}})],Gd=(r,e)=>{r.state.field(Ur,!1)!==void 0&&r.dispatch({effects:$s.of(e)})},$n=r=>{const e=Ee.c(18),{items:t,actions:a,className:h}=r;let f,p,m,x;if(e[0]!==a||e[1]!==h||e[2]!==t){x=Symbol.for("react.early_return_sentinel");e:{const S=t.filter(Xd);if(S.length===0&&!a){x=null;break e}e[7]!==h?(m=Y("flex min-h-7 items-center gap-2 border-b border-border/40 bg-[var(--surface-subtle)] px-3 py-1",h),e[7]=h,e[8]=m):m=e[8],f="min-w-0 flex-1 truncate typography-meta text-muted-foreground",p=S.join(" · ")}e[0]=a,e[1]=h,e[2]=t,e[3]=f,e[4]=p,e[5]=m,e[6]=x}else f=e[3],p=e[4],m=e[5],x=e[6];if(x!==Symbol.for("react.early_return_sentinel"))return x;let C;e[9]!==f||e[10]!==p?(C=s.jsx("div",{className:f,children:p}),e[9]=f,e[10]=p,e[11]=C):C=e[11];let u;e[12]!==a?(u=a?s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:a}):null,e[12]=a,e[13]=u):u=e[13];let w;return e[14]!==m||e[15]!==C||e[16]!==u?(w=s.jsxs("div",{className:m,children:[C,u]}),e[14]=m,e[15]=C,e[16]=u,e[17]=w):w=e[17],w};function Xd(r){return r.length>0}const Wn=r=>{if(r===null||!Number.isFinite(r)||r<0)return"";if(r<1024)return`${r} B`;const e=["KB","MB","GB"];let t=r/1024;for(const a of e){if(t<1024||a===e[e.length-1])return`${t.toFixed(t>=10?0:1)} ${a}`;t/=1024}return""},Yd=r=>{if(r===null||!Number.isFinite(r)||r<0)return"";const e=Math.round(r),t=Math.floor(e/3600),a=Math.floor(e%3600/60),h=e%60,f=p=>String(p).padStart(2,"0");return t>0?`${t}:${f(a)}:${f(h)}`:`${a}:${f(h)}`},ko=r=>r&&r.width>0&&r.height>0?`${r.width} × ${r.height}`:"",Jd=r=>{const e=Ee.c(28),{name:t,path:a,sizeBytes:h,download:f}=r,{t:p}=Ge();let m,x,C,u,w,S,j;if(e[0]!==t||e[1]!==a||e[2]!==h||e[3]!==p){const y=Rc(a).toUpperCase();S="flex h-full min-h-0 flex-col",j=s.jsx($n,{items:[y,Wn(h)]}),C="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",e[11]!==a?(u=s.jsx(On,{filePath:a,className:"size-10"}),e[11]=a,e[12]=u):u=e[12],e[13]!==t?(w=s.jsx("div",{className:"max-w-full truncate typography-ui-header text-foreground",children:t}),e[13]=t,e[14]=w):w=e[14],m="max-w-md typography-ui text-muted-foreground",x=y?p("filesView.artifact.binary.descriptionWithType",{extension:y}):p("filesView.artifact.binary.description"),e[0]=t,e[1]=a,e[2]=h,e[3]=p,e[4]=m,e[5]=x,e[6]=C,e[7]=u,e[8]=w,e[9]=S,e[10]=j}else m=e[4],x=e[5],C=e[6],u=e[7],w=e[8],S=e[9],j=e[10];let T;e[15]!==m||e[16]!==x?(T=s.jsx("div",{className:m,children:x}),e[15]=m,e[16]=x,e[17]=T):T=e[17];let b;e[18]!==f||e[19]!==C||e[20]!==u||e[21]!==w||e[22]!==T?(b=s.jsxs("div",{className:C,children:[u,w,T,f]}),e[18]=f,e[19]=C,e[20]=u,e[21]=w,e[22]=T,e[23]=b):b=e[23];let E;return e[24]!==S||e[25]!==j||e[26]!==b?(E=s.jsxs("div",{className:S,children:[j,b]}),e[24]=S,e[25]=j,e[26]=b,e[27]=E):E=e[27],E},Zd=[48,32,24,18,14],Qd=["ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz",`0123456789 .,;:!?&@#%()[]{}<>+-=/\\*"'`];let Pr=0;const ef=r=>{const e=Ee.c(16),{src:t,name:a,sizeBytes:h}=r,{t:f}=Ge(),[p,m]=i.useState("loading"),[x]=i.useState(tf);let C,u;e[0]!==x||e[1]!==t?(C=()=>{let b=!1;m("loading");const E=new FontFace(x,`url("${t.replace(/"/g,"%22")}")`);return document.fonts.add(E),E.load().then(()=>{b||m("ready")}).catch(()=>{b||m("failed")}),()=>{b=!0,document.fonts.delete(E)}},u=[x,t],e[0]=x,e[1]=t,e[2]=C,e[3]=u):(C=e[2],u=e[3]),i.useEffect(C,u);let w;e[4]!==h?(w=Wn(h),e[4]=h,e[5]=w):w=e[5];let S;e[6]!==a||e[7]!==w?(S=s.jsx($n,{items:[a,w]}),e[6]=a,e[7]=w,e[8]=S):S=e[8];let j;e[9]!==x||e[10]!==p||e[11]!==f?(j=p==="failed"?s.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-center typography-ui text-muted-foreground",children:f("filesView.artifact.font.loadFailed")}):p==="loading"?s.jsxs("div",{className:"flex items-center gap-2 p-3 typography-ui text-muted-foreground",children:[s.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),f("common.loading")]}):s.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-4",style:{fontFamily:`"${x}"`},children:s.jsxs("div",{className:"flex flex-col gap-4",children:[Zd.map(b=>s.jsxs("div",{className:"flex items-baseline gap-3",children:[s.jsx("span",{className:"w-8 shrink-0 text-right font-sans typography-meta text-muted-foreground",children:b}),s.jsx("span",{className:"min-w-0 break-words leading-tight text-foreground",style:{fontSize:`${b}px`},children:f("filesView.artifact.font.sample")})]},b)),s.jsx("div",{className:"mt-2 flex flex-col gap-1 border-t border-border/40 pt-4 text-foreground",style:{fontSize:"20px"},children:Qd.map(nf)})]})}),e[9]=x,e[10]=p,e[11]=f,e[12]=j):j=e[12];let T;return e[13]!==S||e[14]!==j?(T=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[S,j]}),e[13]=S,e[14]=j,e[15]=T):T=e[15],T};function tf(){return Pr=Pr+1,`oc-font-preview-${Pr}`}function nf(r){return s.jsx("div",{className:"break-all leading-relaxed",children:r},r)}const Bs=12,Ro=.1,To=16,Ya=[.1,.25,.5,.75,1,1.5,2,3,4,6,8,12,16],sf=16,Ja=30,rf=(r,e)=>{const t=e.width-Bs*2,a=e.height-Bs*2;return r.width<=0||r.height<=0||t<=0||a<=0?1:Math.min(1,t/r.width,a/r.height)},af=(r,e)=>Math.min(To,Math.max(Math.min(Ro,e),r)),Za=(r,e)=>e===1?Ya.find(t=>t>r*1.001)??To:[...Ya].reverse().find(t=>t<r*.999)??Ro,of=(r,e)=>{const t=e===1?r*sf:r,a=Math.max(-Ja,Math.min(Ja,t));return Math.exp(-a/100)},Qa=(r,e)=>Math.hypot(r.clientX-e.clientX,r.clientY-e.clientY),lf=({src:r,name:e,sizeBytes:t})=>{const{t:a}=Ge(),[h,f]=i.useState(null),[p,m]=i.useState(null),[x,C]=i.useState(null),[u,w]=i.useState(!1),S=i.useRef(null),j=i.useRef(null),T=i.useRef(null),b=i.useRef(null);i.useEffect(()=>{m(null),f(null)},[r]),i.useEffect(()=>{const F=S.current;if(!F)return;const P=new ResizeObserver(()=>{C({width:F.clientWidth,height:F.clientHeight})});return P.observe(F),()=>P.disconnect()},[]);const E=p&&x?rf(p,x):1,y=h??E,l=h!==null&&p!==null&&x!==null&&(p.width*h+Bs*2>x.width||p.height*h+Bs*2>x.height),M=(F,P,I)=>{const K=j.current;if(!K||!p)return;const B=K.getBoundingClientRect(),U=K.clientWidth/p.width;U<=0||(T.current={imageX:(P-B.left-K.clientLeft)/U,imageY:(I-B.top-K.clientTop)/U,clientX:P,clientY:I},As.flushSync(()=>f(af(F,E))))},R=F=>{const P=S.current;if(!P)return;const I=P.getBoundingClientRect();M(F,I.left+I.width/2,I.top+I.height/2)};i.useLayoutEffect(()=>{const F=T.current,P=S.current,I=j.current;if(T.current=null,!F||!P||!I||h===null||I.naturalWidth<=0)return;const K=I.getBoundingClientRect(),B=I.clientWidth/I.naturalWidth;P.scrollLeft+=K.left+I.clientLeft+F.imageX*B-F.clientX,P.scrollTop+=K.top+I.clientTop+F.imageY*B-F.clientY},[h]);const D=i.useRef({zoomTo:M,shownScale:y});D.current={zoomTo:M,shownScale:y},i.useEffect(()=>{const F=S.current;if(!F)return;let P=0,I=null,K=null;const B=_=>{if(!_.ctrlKey&&!_.metaKey)return;_.preventDefault();const ee=D.current;ee.zoomTo(ee.shownScale*of(_.deltaY,_.deltaMode),_.clientX,_.clientY)},U=_=>{P=_.touches.length,_.touches.length===2&&(I={distance:Qa(_.touches[0],_.touches[1]),scale:D.current.shownScale})},ne=_=>{if(!I||_.touches.length!==2||I.distance<=0)return;_.preventDefault();const[ee,ge]=[_.touches[0],_.touches[1]];D.current.zoomTo(I.scale*(Qa(ee,ge)/I.distance),(ee.clientX+ge.clientX)/2,(ee.clientY+ge.clientY)/2)},Q=_=>{P=_.touches.length,_.touches.length<2&&(I=null)},fe=_=>{_.preventDefault(),K=P>0?null:D.current.shownScale},se=_=>{_.preventDefault(),K!==null&&D.current.zoomTo(K*_.scale,_.clientX,_.clientY)},ce=_=>{_.preventDefault(),K=null};return F.addEventListener("wheel",B,{passive:!1}),F.addEventListener("touchstart",U,{passive:!0}),F.addEventListener("touchmove",ne,{passive:!1}),F.addEventListener("touchend",Q,{passive:!0}),F.addEventListener("touchcancel",Q,{passive:!0}),F.addEventListener("gesturestart",fe),F.addEventListener("gesturechange",se),F.addEventListener("gestureend",ce),()=>{F.removeEventListener("wheel",B),F.removeEventListener("touchstart",U),F.removeEventListener("touchmove",ne),F.removeEventListener("touchend",Q),F.removeEventListener("touchcancel",Q),F.removeEventListener("gesturestart",fe),F.removeEventListener("gesturechange",se),F.removeEventListener("gestureend",ce)}},[]);const z=F=>{if(!l||F.pointerType!=="mouse"||F.button!==0)return;const P=F.currentTarget,I=P.getBoundingClientRect();F.clientX-I.left>=P.clientWidth||F.clientY-I.top>=P.clientHeight||(F.preventDefault(),P.setPointerCapture(F.pointerId),b.current={pointerId:F.pointerId,x:F.clientX,y:F.clientY,left:P.scrollLeft,top:P.scrollTop},w(!0))},k=F=>{const P=b.current;!P||P.pointerId!==F.pointerId||(F.currentTarget.scrollLeft=P.left-(F.clientX-P.x),F.currentTarget.scrollTop=P.top-(F.clientY-P.y))},A=F=>{b.current?.pointerId===F.pointerId&&(b.current=null,w(!1))},O=F=>{if(h===null){M(1,F.clientX,F.clientY);return}f(null)};return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s.jsx($n,{items:[ko(p),Wn(t)],actions:s.jsxs(s.Fragment,{children:[s.jsx(W,{variant:"ghost",size:"xs","aria-label":a("filesView.artifact.image.zoomOut"),title:a("filesView.artifact.image.zoomOut"),disabled:!p,onClick:()=>R(Za(y,-1)),children:s.jsx(V,{name:"subtract",className:"size-3.5"})}),s.jsx(W,{variant:"ghost",size:"xs",className:"min-w-11 tabular-nums",title:a("filesView.artifact.image.actualTitle"),disabled:!p,onClick:()=>R(1),children:`${Math.round(y*100)}%`}),s.jsx(W,{variant:"ghost",size:"xs","aria-label":a("filesView.artifact.image.zoomIn"),title:a("filesView.artifact.image.zoomIn"),disabled:!p,onClick:()=>R(Za(y,1)),children:s.jsx(V,{name:"add",className:"size-3.5"})}),s.jsx(W,{variant:"chip",size:"xs","aria-pressed":h===null,title:a("filesView.artifact.image.fitTitle"),onClick:()=>f(null),children:a("filesView.artifact.image.fit")})]})}),s.jsx("div",{ref:S,className:Y("min-h-0 flex-1 overflow-auto",l&&(u?"cursor-grabbing":"cursor-grab")),onPointerDown:z,onPointerMove:k,onPointerUp:A,onPointerCancel:A,onDoubleClick:O,children:s.jsx("div",{className:Y("flex items-center justify-center p-3",h===null?"h-full w-full":"min-h-full min-w-full w-max"),children:s.jsx("img",{ref:j,src:r,alt:e,draggable:!1,onLoad:F=>{const P=F.currentTarget;m({width:P.naturalWidth,height:P.naturalHeight})},style:h!==null&&p?{width:p.width*h,height:p.height*h}:void 0,className:Y("select-none rounded-md border border-border/30 bg-primary/10",h===null?"max-h-full max-w-full object-contain":"max-w-none shrink-0")},r)})})]})},cf=r=>{const e=Ee.c(24),{kind:t,src:a,name:h,sizeBytes:f,download:p}=r,{t:m}=Ge(),[x,C]=i.useState(null),[u,w]=i.useState(null),[S,j]=i.useState(!1);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{C(null),w(null),j(!1)},e[0]=T):T=e[0];let b;e[1]!==a?(b=[a],e[1]=a,e[2]=b):b=e[2],i.useEffect(T,b);let E;e[3]===Symbol.for("react.memo_cache_sentinel")?(E=A=>{const O=A.currentTarget;C(Number.isFinite(O.duration)?O.duration:null),O instanceof HTMLVideoElement&&w({width:O.videoWidth,height:O.videoHeight})},e[3]=E):E=e[3];const y=E;let l;e[4]!==x?(l=Yd(x),e[4]=x,e[5]=l):l=e[5];let M;e[6]!==u?(M=ko(u),e[6]=u,e[7]=M):M=e[7];let R;e[8]!==f?(R=Wn(f),e[8]=f,e[9]=R):R=e[9];let D;e[10]!==l||e[11]!==M||e[12]!==R?(D=s.jsx($n,{items:[l,M,R]}),e[10]=l,e[11]=M,e[12]=R,e[13]=D):D=e[13];let z;e[14]!==p||e[15]!==S||e[16]!==t||e[17]!==h||e[18]!==a||e[19]!==m?(z=S?s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:m("filesView.artifact.media.unplayable")}),p]}):t==="video"?s.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-[var(--surface-background)] p-3",children:s.jsx("video",{src:a,controls:!0,playsInline:!0,preload:"metadata",title:h,className:"max-h-full max-w-full rounded-md",onLoadedMetadata:y,onError:()=>j(!0)},a)}):s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 p-6",children:[s.jsx("div",{className:"typography-ui-label truncate text-foreground",children:h}),s.jsx("audio",{src:a,controls:!0,preload:"metadata",title:h,className:"w-full max-w-lg",onLoadedMetadata:y,onError:()=>j(!0)},a)]}),e[14]=p,e[15]=S,e[16]=t,e[17]=h,e[18]=a,e[19]=m,e[20]=z):z=e[20];let k;return e[21]!==D||e[22]!==z?(k=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[D,z]}),e[21]=D,e[22]=z,e[23]=k):k=e[23],k},uf=2e3,df=r=>r.toLowerCase().endsWith(".tsv")?" ":",",ff=(r,e,t=uf)=>{const a=[];let h=0,f="",p=[],m=!1,x=!1;const C=()=>{p.push(f),f="",p.length===1&&p[0]===""&&!x||((h===0||a.length<=t)&&a.push(p),h+=1),p=[],x=!1},u=r.charCodeAt(0)===65279?r.slice(1):r;for(let b=0;b<u.length;b+=1){const E=u[b];if(m){E==='"'?u[b+1]==='"'?(f+='"',b+=1):m=!1:f+=E;continue}if(E==='"'){m=!0,x=!0;continue}if(E===e){p.push(f),f="",x=!0;continue}if(E===`
|
|
11
|
+
`||E==="\r"){E==="\r"&&u[b+1]===`
|
|
12
|
+
`&&(b+=1),C();continue}f+=E}(f.length>0||p.length>0||m)&&C();const w=a[0]??[],S=a.slice(1),j=a.reduce((b,E)=>Math.max(b,E.length),0),T=Math.max(0,h-1);return{header:w,rows:S,totalRows:T,columnCount:j,truncated:S.length<T}},mf=r=>{const e=Ee.c(29),{path:t,content:a,sizeBytes:h}=r,{t:f}=Ge();let p;e[0]!==a||e[1]!==t?(p=ff(a,df(t)),e[0]=a,e[1]=t,e[2]=p):p=e[2];const m=p;let x;e[3]!==f||e[4]!==m.columnCount||e[5]!==m.totalRows?(x=m.totalRows===1?f("filesView.artifact.table.rowsSingle",{rows:m.totalRows,columns:m.columnCount}):f("filesView.artifact.table.rowsPlural",{rows:m.totalRows,columns:m.columnCount}),e[3]=f,e[4]=m.columnCount,e[5]=m.totalRows,e[6]=x):x=e[6];const C=x;let u;e[7]!==m.columnCount?(u=Array.from({length:m.columnCount},hf),e[7]=m.columnCount,e[8]=u):u=e[8];const w=u;let S;e[9]!==f||e[10]!==m.rows||e[11]!==m.totalRows||e[12]!==m.truncated?(S=m.truncated?f("filesView.artifact.table.truncated",{shown:m.rows.length,total:m.totalRows}):"",e[9]=f,e[10]=m.rows,e[11]=m.totalRows,e[12]=m.truncated,e[13]=S):S=e[13];let j;e[14]!==h?(j=Wn(h),e[14]=h,e[15]=j):j=e[15];let T;e[16]!==C||e[17]!==S||e[18]!==j?(T=s.jsx($n,{items:[C,S,j]}),e[16]=C,e[17]=S,e[18]=j,e[19]=T):T=e[19];let b;e[20]!==w||e[21]!==f||e[22]!==m.columnCount||e[23]!==m.header||e[24]!==m.rows?(b=m.columnCount===0?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:f("filesView.artifact.table.empty")}):s.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:s.jsxs("table",{className:"min-w-full border-separate border-spacing-0 font-mono typography-meta",children:[s.jsx("thead",{className:"sticky top-0 z-10 bg-[var(--surface-subtle)]",children:s.jsx("tr",{children:w.map(y=>s.jsx("th",{scope:"col",className:"whitespace-nowrap border-b border-r border-border/40 px-2 py-1 text-left font-medium text-foreground last:border-r-0",children:m.header[y]??""},y))})}),s.jsx("tbody",{children:m.rows.map((y,l)=>s.jsx("tr",{className:"odd:bg-[var(--surface-background)] even:bg-[var(--surface-subtle)]/40",children:w.map(M=>s.jsx("td",{className:"max-w-[32rem] truncate border-b border-r border-border/30 px-2 py-1 align-top text-foreground last:border-r-0",title:y[M]??"",children:y[M]??""},M))},l))})]})}),e[20]=w,e[21]=f,e[22]=m.columnCount,e[23]=m.header,e[24]=m.rows,e[25]=b):b=e[25];let E;return e[26]!==T||e[27]!==b?(E=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[T,b]}),e[26]=T,e[27]=b,e[28]=E):E=e[28],E};function hf(r,e){return e}const pn="data-oc-local-asset",pf=25*1024*1024,Ps=r=>{const e=r.trim();return!e||e.startsWith("#")||e.startsWith("//")?!1:!/^[a-z][a-z\d+.-]*:/i.test(e)},gf=r=>r.split(/[?#]/,1)[0]??"",xf=r=>r.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-"),vf=(r,e)=>{const t=Mo(e.replace(/^#/,"")).toLowerCase();if(!t)return!1;for(const a of Array.from(r.querySelectorAll("h1, h2, h3, h4, h5, h6")))if(a.id===t||xf(a.textContent??"")===t)return a.scrollIntoView({block:"start"}),!0;return!1},Mo=r=>{try{return decodeURIComponent(r)}catch{return r}},wf=r=>r.split(",").flatMap(e=>{const[t,...a]=e.trim().split(/\s+/);return t?[{url:t,descriptor:a.join(" ")}]:[]}),Dr="data-oc-media",bf=/\(\s*prefers-color-scheme\s*:\s*(light|dark)\s*\)/gi,eo=(r,e)=>{for(const t of Array.from(r.querySelectorAll("picture > source[media]"))){const a=t.getAttribute(Dr)??t.getAttribute("media")??"",h=a.replace(bf,(f,p)=>p.toLowerCase()===e?"(min-width: 0px)":"(max-width: -1px)");h!==a&&(t.getAttribute(Dr)!==a&&t.setAttribute(Dr,a),t.getAttribute("media")!==h&&t.setAttribute("media",h))}},to=({container:r,filePath:e,workspaceRoot:t,onOpenFile:a,enabled:h,colorScheme:f})=>{const p=i.useRef(a);p.current=a;const m=i.useRef(f);m.current=f,i.useEffect(()=>{h&&r&&eo(r,f)},[f,r,h]),i.useEffect(()=>{if(!h||!r||!e)return;const x=e.slice(0,e.lastIndexOf("/")+1)||"/",C=l=>Tc(x,Mo(gf(l))),u=l=>({path:l,allowOutsideWorkspace:t&&Mc(l,t)?void 0:"true",directory:t||void 0});let w=!1;const S=ot(),j=new Map,T=l=>{const M=j.get(l);if(M)return M;const R=(async()=>{const D=await Ls("/api/fs/raw",{query:u(l),signal:AbortSignal.timeout(3e4)});if(!D.ok)throw new Error(`Image read failed (${D.status})`);const z=await D.blob();if(z.size>pf)throw new Error("Image too large for preview");if(w||ot()!==S)throw new Error("Preview closed");return URL.createObjectURL(z)})();return j.set(l,R),R.catch(()=>j.delete(l)),R},b=()=>{for(const l of Array.from(r.querySelectorAll("img[src]"))){const M=l.getAttribute("src")??"";if(!Ps(M))continue;const R=C(M);l.setAttribute(pn,R),T(R).then(D=>{w||l.getAttribute(pn)!==R||l.getAttribute("src")!==D&&(l.src=D)}).catch(()=>{w||l.removeAttribute(pn)})}for(const l of Array.from(r.querySelectorAll("source[srcset], img[srcset]"))){const M=wf(l.getAttribute("srcset")??"");if(!M.some(z=>Ps(z.url)))continue;const R=M.map(z=>({...z,path:Ps(z.url)?C(z.url):null})),D=R.map(z=>z.path??z.url).join(",");l.setAttribute(pn,D),Promise.all(R.map(async({url:z,descriptor:k,path:A})=>{const O=A?await T(A):z;return k?`${O} ${k}`:O})).then(z=>{if(w||l.getAttribute(pn)!==D)return;const k=z.join(", ");l.getAttribute("srcset")!==k&&l.setAttribute("srcset",k)}).catch(()=>{w||l.removeAttribute(pn)})}eo(r,m.current)},E=l=>{if(l.defaultPrevented||l.button!==0||l.metaKey||l.ctrlKey||l.shiftKey||l.altKey)return;const M=l.target;if(!(M instanceof Element))return;const R=M.closest("a[href]");if(!(R instanceof HTMLAnchorElement)||!r.contains(R))return;const D=R.getAttribute("href")??"";if(D.startsWith("#")){l.preventDefault(),l.stopPropagation(),vf(r,D);return}Ps(D)&&(l.preventDefault(),l.stopPropagation(),p.current(C(D)))};b();const y=new MutationObserver(b);return y.observe(r,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src","srcset","media"]}),r.addEventListener("click",E,!0),()=>{w=!0,y.disconnect(),r.removeEventListener("click",E,!0);for(const l of j.values())l.then(M=>URL.revokeObjectURL(M)).catch(()=>{})}},[r,h,e,t])},yf=r=>{const e=ae(r);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const t=e.lastIndexOf("/");if(t<0)return e;if(t===0)return"/";const a=e.slice(0,t);return/^[A-Za-z]:$/.test(a)?`${a}/`:a},Cf=r=>{const e=Ee.c(8),{label:t,iconDataUrl:a}=r,[h,f]=i.useState(!1);let p;e[0]!==t?(p=t.trim().slice(0,1).toUpperCase()||"?",e[0]=t,e[1]=p):p=e[1];const m=p;if(a&&!h){let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=()=>f(!0),e[2]=u):u=e[2];let w;return e[3]!==a?(w=s.jsx("img",{src:a,alt:"",className:"size-4 rounded-sm",onError:u}),e[3]=a,e[4]=w):w=e[4],w}let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=Y("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=x):x=e[5];let C;return e[6]!==m?(C=s.jsx("span",{className:x,children:m}),e[6]=m,e[7]=C):C=e[7],C},jf=r=>r.slice().sort((e,t)=>e.type!==t.type?e.type==="directory"?-1:1:e.name.localeCompare(t.name)),ae=r=>{if(!r)return"";const e=r.replace(/\\/g,"/"),t=e.startsWith("//");let a=e.replace(/\/+/g,"/");t&&!a.startsWith("//")&&(a=`/${a}`);const h=a==="/",f=/^[A-Za-z]:\/$/.test(a);return!h&&!f&&(a=a.replace(/\/+$/,"")),a},Sf=r=>r.startsWith("/")||r.startsWith("//")||/^[A-Za-z]:\//.test(r),xn=r=>/^[A-Za-z]:\//.test(r)?r.toLowerCase():r,Bn=(r,e)=>{const t=ae(e),a=ae(r);if(!t||!a)return!1;const h=xn(t),f=xn(a);return f===h||f.startsWith(`${h}/`)},no=(r,e)=>{const t=ae(e),a=ae(r);if(!Bn(a,t))return[];const f=a.slice(t.length).replace(/^\//,"").split("/"),p=[];let m=t;for(let x=0;x<f.length-1;x++)m=m?`${m}/${f[x]}`:f[x],p.push(m);return p},Is=(r,e)=>{if(!e)return"";const t=ae(e);if(!r||!Bn(t,r))return t;const a=t.slice(r.length);return a.startsWith("/")?a.slice(1):a},Nf=new Set(["node_modules"]),Ff=r=>{const e=Ee.c(3),{status:t}=r;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={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]=a):a=e[0];const h=a[t];let f;return e[1]!==h?(f=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:h}}),e[1]=h,e[2]=f):f=e[2],f},so=r=>{const e=Ee.c(11),{name:t}=r,a=i.useRef(null),h=i.useRef(null),[f,p]=i.useState(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{const S=a.current,j=h.current;if(!S||!j)return;const T=()=>{p(j.scrollWidth>S.clientWidth+1)};T();const b=new ResizeObserver(T);return b.observe(S),b.observe(j),()=>{b.disconnect()}},e[0]=m):m=e[0];let x;e[1]!==t?(x=[t],e[1]=t,e[2]=x):x=e[2],i.useLayoutEffect(m,x);let C;e[3]!==t?(C=s.jsx("span",{ref:h,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:t}),e[3]=t,e[4]=C):C=e[4];let u;e[5]!==t||e[6]!==f?(u=f?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:t}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:t})]}):s.jsx("span",{className:"block min-w-0 truncate",children:t}),e[5]=t,e[6]=f,e[7]=u):u=e[7];let w;return e[8]!==C||e[9]!==u?(w=s.jsxs("span",{ref:a,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,u]}),e[8]=C,e[9]=u,e[10]=w):w=e[10],w},Ef=r=>Nf.has(r),kf=r=>{const e=ae(r);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Rf=r=>{const t=(r instanceof Error?r.message:String(r??"")).toLowerCase();return t.includes("is a directory")||t.includes("eisdir")},ro=r=>{const t=(r instanceof Error?r.message:String(r??"")).toLowerCase();return t.includes("file not found")||t.includes("enoent")||t.includes("no such file")||t.includes("does not exist")},Tf=2e5,Vo=(r,e)=>s.jsx(On,{filePath:r,extension:e}),Ar=r=>{if(!r)return!1;const e=r.toLowerCase();if(e.endsWith(".excalidraw.md"))return!1;const t=e.split(".").pop();return t==="md"||t==="markdown"},Lr=r=>!!(r&&Fo($r.getState().guests,r)),io=r=>{if(!r)return!1;const e=r.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Ds=r=>{if(!r)return!1;const e=r.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Mf=r=>{const e=Ee.c(78),{node:t,root:a,isExpanded:h,isActive:f,isMobile:p,isBrowserClient:m,alwaysShowActions:x,status:C,badge:u,permissions:w,downloadFile:S,contextMenuPath:j,setContextMenuPath:T,rightClickMenuPath:b,setRightClickMenuPath:E,onSelect:y,onToggle:l,onRevealPath:M,onOpenDialog:R,canUpload:D,onPickFiles:z}=r,{t:k}=Ge(),A=t.type==="directory",{canRename:O,canCreateFile:F,canCreateFolder:P,canDelete:I,canReveal:K}=w,B=!A&&!!S,U=K&&!m,ne=A&&D,Q=O||F||P||ne||I||B||U;let fe;e[0]!==Q||e[1]!==t.path||e[2]!==E?(fe=Ie=>{Q&&(Ie?.preventDefault(),E(t.path))},e[0]=Q,e[1]=t.path,e[2]=E,e[3]=fe):fe=e[3];const se=fe;let ce;e[4]!==A||e[5]!==t||e[6]!==y||e[7]!==l?(ce=()=>{A?l(t.path):y(t)},e[4]=A,e[5]=t,e[6]=y,e[7]=l,e[8]=ce):ce=e[8];const _=ce;let ee;e[9]!==t.path||e[10]!==T||e[11]!==E?(ee=Ie=>{Ie.stopPropagation(),E(null),T(t.path)},e[9]=t.path,e[10]=T,e[11]=E,e[12]=ee):ee=e[12];const ge=ee;let Ae;e[13]!==F||e[14]!==P||e[15]!==I||e[16]!==O||e[17]!==U||e[18]!==ne||e[19]!==S||e[20]!==m||e[21]!==A||e[22]!==t||e[23]!==R||e[24]!==z||e[25]!==M||e[26]!==a||e[27]!==k?(Ae=Ie=>{const{Item:we,Separator:vn}=Ie;return s.jsxs(s.Fragment,{children:[O&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),R("rename",t)},children:[s.jsx(V,{name:"edit",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.rename")]}),s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),Os(t.path).then(Nt=>{if(Nt.ok){J.success(k("sidebarFilesTree.toast.pathCopied"));return}J.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(V,{name:"file-copy",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.copyPath")]}),s.jsxs(we,{onClick:ie=>{ie.stopPropagation();const Nt=Is(a,t.path)||t.path;Os(Nt).then(gt=>{if(gt.ok){J.success(k("filesView.toast.relativePathCopied"));return}J.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(V,{name:"file-copy-2",className:"mr-2 size-4"})," ",k("filesView.tree.menu.copyRelativePath")]}),!A&&S&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),S(t.path).catch(Nt=>{console.error("Download failed:",Nt),J.error(k("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(V,{name:"download",className:"mr-2 size-4"})," ",k(m?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),U&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),M(t.path)},children:[s.jsx(V,{name:"folder-received",className:"mr-2 size-4"})," ",k(Jc())]}),A&&(F||P||ne)&&s.jsxs(s.Fragment,{children:[s.jsx(vn,{}),F&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),R("createFile",t)},children:[s.jsx(V,{name:"file-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFile")]}),P&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),R("createFolder",t)},children:[s.jsx(V,{name:"folder-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFolder")]}),ne&&s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),z(t.path)},children:[s.jsx(V,{name:"upload-2",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.uploadFiles")]})]}),I&&s.jsxs(s.Fragment,{children:[s.jsx(vn,{}),s.jsxs(we,{onClick:ie=>{ie.stopPropagation(),R("delete",t)},className:"text-destructive focus:text-destructive",children:[s.jsx(V,{name:"delete-bin",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.delete")]})]})]})},e[13]=F,e[14]=P,e[15]=I,e[16]=O,e[17]=U,e[18]=ne,e[19]=S,e[20]=m,e[21]=A,e[22]=t,e[23]=R,e[24]=z,e[25]=M,e[26]=a,e[27]=k,e[28]=Ae):Ae=e[28];const Le=Ae,ze=b===t.path;let Ne;e[29]!==t.path||e[30]!==E?(Ne=Ie=>E(Ie?t.path:null),e[29]=t.path,e[30]=E,e[31]=Ne):Ne=e[31];const Xe=p?void 0:se;let Z;e[32]!==Xe?(Z=s.jsx("div",{className:"group relative flex items-center",onContextMenu:Xe}),e[32]=Xe,e[33]=Z):Z=e[33];const ke=p?void 0:se,G=f?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let X;e[34]!==G?(X=Y("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",G),e[34]=G,e[35]=X):X=e[35];let re;e[36]!==A||e[37]!==h||e[38]!==t.extension||e[39]!==t.path?(re=A?h?s.jsx(V,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(V,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Vo(t.path,t.extension),e[36]=A,e[37]=h,e[38]=t.extension,e[39]=t.path,e[40]=re):re=e[40];let me;e[41]!==t.name||e[42]!==t.path?(me=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:t.path,children:t.name}),e[41]=t.name,e[42]=t.path,e[43]=me):me=e[43];let xe;e[44]!==A||e[45]!==C?(xe=!A&&C&&s.jsx(Ff,{status:C}),e[44]=A,e[45]=C,e[46]=xe):xe=e[46];let he;e[47]!==u||e[48]!==A?(he=A&&u&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[u.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",u.modified]}),u.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",u.added]})]}),e[47]=u,e[48]=A,e[49]=he):he=e[49];let le;e[50]!==_||e[51]!==X||e[52]!==re||e[53]!==me||e[54]!==xe||e[55]!==he||e[56]!==ke?(le=s.jsxs("button",{type:"button",onClick:_,onContextMenu:ke,className:X,children:[re,me,xe,he]}),e[50]=_,e[51]=X,e[52]=re,e[53]=me,e[54]=xe,e[55]=he,e[56]=ke,e[57]=le):le=e[57];let ye;e[58]!==x||e[59]!==j||e[60]!==ge||e[61]!==Q||e[62]!==p||e[63]!==t.path||e[64]!==Le||e[65]!==T?(ye=Q&&s.jsx("div",{className:Y("absolute right-1 top-1/2 -translate-y-1/2",x?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(Ir,{open:j===t.path,onOpenChange:Ie=>T(Ie?t.path:null),children:[s.jsx(Or,{asChild:!0,children:s.jsx(W,{variant:"ghost",size:"icon",className:"size-6",onClick:ge,children:s.jsx(V,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Br,{align:"end",side:"bottom",onCloseAutoFocus:()=>T(null),children:Le({Item:zs,Separator:Yc})})]})}),e[58]=x,e[59]=j,e[60]=ge,e[61]=Q,e[62]=p,e[63]=t.path,e[64]=Le,e[65]=T,e[66]=ye):ye=e[66];let Ce;e[67]!==le||e[68]!==ye||e[69]!==Z?(Ce=s.jsxs(iu,{render:Z,children:[le,ye]}),e[67]=le,e[68]=ye,e[69]=Z,e[70]=Ce):Ce=e[70];let ue;e[71]!==Le?(ue=s.jsx(nu,{className:"min-w-[180px]",children:Le({Item:ru,Separator:su})}),e[71]=Le,e[72]=ue):ue=e[72];let Ye;return e[73]!==Ce||e[74]!==ue||e[75]!==ze||e[76]!==Ne?(Ye=s.jsxs(au,{open:ze,onOpenChange:Ne,children:[Ce,ue]}),e[73]=Ce,e[74]=ue,e[75]=ze,e[76]=Ne,e[77]=Ye):Ye=e[77],Ye},Vf=r=>{const e=Ee.c(83),{activeDialog:t,dialogData:a,dialogInputValue:h,onDialogInputChange:f,isDialogSubmitting:p,onDialogSubmit:m,onClose:x,inputRef:C}=r,{t:u}=Ge(),w=!!t;let S;e[0]!==x?(S=se=>!se&&x(),e[0]=x,e[1]=S):S=e[1];let j;e[2]!==t||e[3]!==u?(j=t==="createFile"&&u("filesView.dialog.createFile.title"),e[2]=t,e[3]=u,e[4]=j):j=e[4];let T;e[5]!==t||e[6]!==u?(T=t==="createFolder"&&u("filesView.dialog.createFolder.title"),e[5]=t,e[6]=u,e[7]=T):T=e[7];let b;e[8]!==t||e[9]!==u?(b=t==="rename"&&u("filesView.dialog.rename.title"),e[8]=t,e[9]=u,e[10]=b):b=e[10];let E;e[11]!==t||e[12]!==u?(E=t==="delete"&&u("filesView.dialog.delete.title"),e[11]=t,e[12]=u,e[13]=E):E=e[13];let y;e[14]!==j||e[15]!==T||e[16]!==b||e[17]!==E?(y=s.jsxs(ho,{children:[j,T,b,E]}),e[14]=j,e[15]=T,e[16]=b,e[17]=E,e[18]=y):y=e[18];let l;e[19]!==t||e[20]!==a?.path||e[21]!==u?(l=t==="createFile"&&u("filesView.dialog.createFile.description",{path:a?.path??u("filesView.dialog.rootFallback")}),e[19]=t,e[20]=a?.path,e[21]=u,e[22]=l):l=e[22];let M;e[23]!==t||e[24]!==a?.path||e[25]!==u?(M=t==="createFolder"&&u("filesView.dialog.createFolder.description",{path:a?.path??u("filesView.dialog.rootFallback")}),e[23]=t,e[24]=a?.path,e[25]=u,e[26]=M):M=e[26];let R;e[27]!==t||e[28]!==a?.name||e[29]!==u?(R=t==="rename"&&u("filesView.dialog.rename.description",{name:a?.name??""}),e[27]=t,e[28]=a?.name,e[29]=u,e[30]=R):R=e[30];let D;e[31]!==t||e[32]!==a?.name||e[33]!==u?(D=t==="delete"&&u("filesView.dialog.delete.description",{name:a?.name??""}),e[31]=t,e[32]=a?.name,e[33]=u,e[34]=D):D=e[34];let z;e[35]!==R||e[36]!==D||e[37]!==l||e[38]!==M?(z=s.jsxs(po,{children:[l,M,R,D]}),e[35]=R,e[36]=D,e[37]=l,e[38]=M,e[39]=z):z=e[39];let k;e[40]!==z||e[41]!==y?(k=s.jsxs(mo,{children:[y,z]}),e[40]=z,e[41]=y,e[42]=k):k=e[42];let A;e[43]!==t||e[44]!==h||e[45]!==C||e[46]!==f||e[47]!==m||e[48]!==u?(A=t!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(_n,{value:h,onChange:se=>f(se.target.value),placeholder:u(t==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:se=>{se.key==="Enter"&&m()},ref:C})}),e[43]=t,e[44]=h,e[45]=C,e[46]=f,e[47]=m,e[48]=u,e[49]=A):A=e[49];let O;e[50]!==u?(O=u("filesView.dialog.cancel"),e[50]=u,e[51]=O):O=e[51];let F;e[52]!==p||e[53]!==x||e[54]!==O?(F=s.jsx(W,{variant:"outline",onClick:x,disabled:p,children:O}),e[52]=p,e[53]=x,e[54]=O,e[55]=F):F=e[55];const P=t==="delete"?"destructive":"default";let I;e[56]!==m?(I=()=>{m()},e[56]=m,e[57]=I):I=e[57];let K;e[58]!==t||e[59]!==h||e[60]!==p?(K=p||t!=="delete"&&!h.trim(),e[58]=t,e[59]=h,e[60]=p,e[61]=K):K=e[61];let B;e[62]!==t||e[63]!==p||e[64]!==u?(B=p?s.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}):u(t==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=t,e[63]=p,e[64]=u,e[65]=B):B=e[65];let U;e[66]!==P||e[67]!==I||e[68]!==K||e[69]!==B?(U=s.jsx(W,{variant:P,onClick:I,disabled:K,children:B}),e[66]=P,e[67]=I,e[68]=K,e[69]=B,e[70]=U):U=e[70];let ne;e[71]!==F||e[72]!==U?(ne=s.jsxs(go,{children:[F,U]}),e[71]=F,e[72]=U,e[73]=ne):ne=e[73];let Q;e[74]!==C||e[75]!==k||e[76]!==A||e[77]!==ne?(Q=s.jsxs(fo,{initialFocus:C,children:[k,A,ne]}),e[74]=C,e[75]=k,e[76]=A,e[77]=ne,e[78]=Q):Q=e[78];let fe;return e[79]!==w||e[80]!==S||e[81]!==Q?(fe=s.jsx(uo,{open:w,onOpenChange:S,children:Q}),e[79]=w,e[80]=S,e[81]=Q,e[82]=fe):fe=e[82],fe},gn=new Map,Pf=100,ao=r=>{const e=Ee.c(13);let t,a,h;e[0]!==r?({positionKey:a,onViewReady:t,...h}=r,e[0]=r,e[1]=t,e[2]=a,e[3]=h):(t=e[1],a=e[2],h=e[3]);const f=i.useRef(null);let p,m;e[4]!==a?(p=()=>()=>{const u=f.current;if(!u)return;const{anchor:w,head:S}=u.state.selection.main;if(gn.delete(a),gn.set(a,{scroll:u.scrollSnapshot(),anchor:w,head:S}),gn.size>Pf){const j=gn.keys().next().value;j!==void 0&&gn.delete(j)}},m=[a],e[4]=a,e[5]=p,e[6]=m):(p=e[5],m=e[6]),i.useLayoutEffect(p,m);let x;e[7]!==t||e[8]!==a?(x=u=>{f.current=u;const w=gn.get(a);w&&u.dispatch({selection:{anchor:Math.min(w.anchor,u.state.doc.length),head:Math.min(w.head,u.state.doc.length)},effects:w.scroll}),t?.(u)},e[7]=t,e[8]=a,e[9]=x):x=e[9];let C;return e[10]!==h||e[11]!==x?(C=s.jsx(lu,{...h,onViewReady:x}),e[10]=h,e[11]=x,e[12]=C):C=e[12],C},oo=(r,e,t)=>{const a=Ee.c(8),[h,f]=i.useState(""),[p,m]=i.useState(0);let x,C;a[0]!==r||a[1]!==t||a[2]!==e?(x=()=>{if(!r){f("");return}let w=!1;f("");const S=pc(),j=gc(S);xc(S).then(b=>{w||!b||(f(r),e(null))}).catch(b=>{w||(e(b instanceof Error?b.message:t),f(r))});const T=vc(()=>{w||(f(r),m(Df),e(null))});return()=>{w=!0,j(),T()}},C=[r,e,t],a[0]=r,a[1]=t,a[2]=e,a[3]=x,a[4]=C):(x=a[3],C=a[4]),i.useEffect(x,C);let u;return a[5]!==p||a[6]!==h?(u={readyKey:h,nonce:p},a[5]=p,a[6]=h,a[7]=u):u=a[7],u},ap=({mode:r="full",visible:e=!0})=>{const{t}=Ge(),{files:a,runtime:h,git:f}=Vc(),{currentTheme:p,availableThemes:m,lightThemeId:x,darkThemeId:C}=Pc(),{isMobile:u,isTablet:w,screenWidth:S}=lo(),j=oc(h.platform),T=u||w,b=lc(),E=cc(),y=co()??"",l=ae(y.trim()),M=u||r==="full",R=M&&e,D=Nr(n=>n.runtimeKey),z=JSON.stringify([D,l]),k=i.useRef(z);k.current=z;const A=JSON.stringify([D,l,b,E]),O=i.useRef(A);O.current=A;const F=r!=="editor-only",P=r==="editor-only"&&!u,I=uc(n=>n.searchFiles),K=Dc(R?y:null),[B,U]=i.useState(""),ne=Ac(B,200),Q=i.useRef(null),[fe,se]=i.useState(!1),[ce,_]=i.useState(!0),[ee,ge]=i.useState(!1),Ae=i.useCallback(n=>{if(!Js.current){ge(n);return}const o=xt.current;if(jn.current){ri.current?.().then(c=>{c&&xt.current===o&&ge(n)});return}Promise.resolve(Yt.current?.getContent("handoff")??Vr).then(c=>{if(xt.current===o){if(!c.ok){J.error(c.message);return}c.snapshot&&"content"in c.snapshot&&(Se(c.snapshot.content),ft(!1)),ge(n)}})},[]),[Le,ze]=i.useState(!1),Ne=i.useRef(0),Xe=i.useCallback(n=>{Ne.current=Math.max(0,Ne.current+(n?1:-1))},[]),[Z,ke]=i.useState("edit"),[G,X]=i.useState("edit"),[re,me]=i.useState("tree"),[xe,he]=i.useState("edit"),[le,ye]=i.useState("preview"),[Ce,ue]=i.useState("preview"),[Ye,Ie]=i.useState("preview"),[we,vn]=i.useState("preview"),[ie,Nt]=i.useState("table"),[gt,Kr]=i.useState(null),[Po,Do]=i.useState(0),[Ao,Un]=i.useState(0),Kn=i.useRef({}),Ws=i.useRef({}),Us=i.useRef({}),Hr=i.useRef({}),qr=i.useRef({}),Gr=i.useRef({}),Ks=i.useRef({}),wn=i.useRef({}),Hn=i.useMemo(()=>m.find(n=>n.metadata.id===x)??Va(!1),[m,x]),qn=i.useMemo(()=>m.find(n=>n.metadata.id===C)??Va(!0),[m,C]);i.useEffect(()=>{Ba(Hn),Ba(qn)},[Hn,qn]);const Gn=i.useMemo(()=>[],[]),Re=st(n=>l?n.byRoot[l]?.openPaths??Gn:Gn),Dt=st(n=>l?n.byRoot[l]?.selectedPath??null:null),ct=st(n=>l?n.byRoot[l]?.expandedPaths??Gn:Gn),Lo=i.useMemo(()=>new Set(ct),[ct]),Ht=st(n=>n.removeOpenPath),Ft=st(n=>n.removeOpenPathsByPrefix),Xr=st(n=>n.removeExpandedPathsByPrefix),Te=st(n=>n.setSelectedPath),Yr=st(n=>n.toggleExpandedPath),Xn=st(n=>n.expandPaths),qt=i.useCallback(n=>{const o=ae(n),c=o.split("/"),g=c[c.length-1]||o,v=g.includes(".")?g.split(".").pop()?.toLowerCase():void 0;return{name:g,path:o,type:"file",extension:v}},[]),Gt=i.useMemo(()=>Re.map(qt),[Re,qt]),Hs=i.useMemo(()=>{if(Dt){const n=xn(Dt);if(Re.some(o=>xn(o)===n))return Dt}return Re[0]??null},[Re,Dt]),d=i.useMemo(()=>Hs?qt(Hs):null,[Hs,qt]),Oe=d?.path??"",xt=i.useRef(Oe);xt.current=Oe,i.useEffect(()=>{if(!l||!Dt)return;const n=xn(Dt);Re.some(c=>xn(c)===n)||Te(l,Re[0]??null)},[Re,l,Dt,Te]);const Yn=!!(l&&Oe&&!Bn(Oe,l)),qs=i.useMemo(()=>({allowOutsideWorkspace:Yn,directory:l||void 0}),[Yn,l]),ut=i.useCallback(n=>({allowOutsideWorkspace:!!(l&&!Bn(n,l))}),[l]),Gs=i.useRef(null),[Jr,zo]=i.useState({left:!1,right:!1}),Zr=i.useCallback(()=>{const n=Gs.current;n&&zo({left:n.scrollLeft>2,right:n.scrollLeft+n.clientWidth<n.scrollWidth-2})},[]),Qr=i.useRef(Zr);Qr.current=Zr,i.useEffect(()=>{const n=Gs.current;if(!n)return;const o=()=>Qr.current();o(),n.addEventListener("scroll",o,{passive:!0});const c=new ResizeObserver(o);return c.observe(n),()=>{n.removeEventListener("scroll",o),c.disconnect()}},[Gt.length]);const[ei,Xs]=i.useState({}),[Jn,bn]=i.useState({}),Je=i.useRef(new Set),Be=i.useMemo(()=>new yu,[]);i.useEffect(()=>()=>Be.clear(),[Be]);const[ti,Zn]=i.useState([]),[Io,Qn]=i.useState(!1),[H,je]=i.useState(""),{isPlaying:es,play:Oo,stop:Bo}=Lc(),[Me,Et]=i.useState(!1),[rt,Fe]=i.useState(null),[_o,Ze]=i.useState(""),[de,ve]=i.useState(null),kt=JSON.stringify([ot(),l,de]),[oe,Se]=i.useState(""),[Xt,Ys]=i.useState(!1),[ni,$o]=i.useState(`
|
|
13
|
+
`),Wo=i.useRef(null),dt=i.useRef(null),We=i.useRef(null),Rt=i.useRef(""),yn=i.useRef(""),vt=i.useRef(null),At=i.useRef(null),si=i.useRef(null),Yt=i.useRef(null),[Cn,ft]=i.useState(!1),Js=i.useRef(!1);Js.current=Cn;const jn=i.useRef(!1),ri=i.useRef(null),Qe=i.useRef(null),Zs=i.useRef(""),Qs=i.useRef(0),Jt=i.useRef(0),Lt=i.useRef(null),[Sn,Uo]=i.useState(0),[Ko,Zt]=i.useState("idle"),[Ho,ts]=i.useState(!1),[qo,ii]=i.useState(!1),[zt,ai]=i.useState(!1),Ve=at(n=>n.autoSaveEnabled),Go=at(n=>n.setAutoSaveEnabled),[er,Nn]=i.useState(!1),Qt=i.useRef(null),Fn=i.useRef(null),En=i.useRef(!1),kn=i.useRef(null),Rn=i.useRef(null),Pe=i.useRef(null),Tn=i.useRef(null),oi=i.useRef(null),li=i.useRef(0),[Xo,tr]=i.useState(0),en=i.useRef(null),It=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{en.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(en.current),en.current=null)},[]);const[Ot,nr]=i.useState(null),[Bt,Yo]=i.useState(null),[Tt,ci]=i.useState(""),[Jo,sr]=i.useState(!1),[Zo,Qo]=i.useState(null),[el,tl]=i.useState(null),[nl,ui]=i.useState(!1),[sl,di]=i.useState(!1),[rl,rr]=i.useState(!1),[fi,ns]=i.useState(!1),[mi,ss]=i.useState(!1),[hi,pi]=i.useState(0),rs=i.useRef(null),is=i.useCallback(n=>{const o=n?.currentTarget??rs.current;if(!o)return;const c=document.activeElement;c&&c!==document.body&&c!==o&&(zc(c)||o.contains(c))||o.focus({preventScroll:!0})},[]),as=i.useRef(null),gi=!!a.writeFile,xi=!!a.createDirectory,vi=!!a.rename,wi=!!a.delete,bi=!!a.revealPath,il=Ts(n=>n.availableApps),al=Ts(n=>n.isCacheStale),yi=Ts(n=>n.initialize),ol=Ts(n=>n.loadInstalledApps);i.useEffect(()=>{yi()},[yi]);const ll=i.useCallback(n=>{a.revealPath&&a.revealPath(n).catch(()=>{J.error(t("sidebarFilesTree.toast.revealFailed"))})},[a,t]),cl=i.useCallback(async n=>{if(!d?.path||await dc(d.path,n.id,n.appName)||await Ra(d.path,n.appName))return;const g=yf(d.path)||l;g&&await Ra(g,n.appName)||J.error(t("filesView.toast.openInAppFailed",{app:n.appName}))},[l,d?.path,t]),ir=i.useCallback((n,o)=>{nr(n),Yo(o),ci(n==="rename"&&o.name||""),sr(!1)},[]),[te,it]=i.useState(null),tn=i.useRef(!1),Mt=i.useRef(null),[Ci,nn]=i.useState(!1),mt=at(n=>n.pendingFileNavigation),os=at(n=>n.setPendingFileNavigation),ar=at(n=>n.pendingFileFocusPath),or=at(n=>n.setPendingFileFocusPath),ls=at(n=>n.fileEditorKeymap),Mn=Pa(n=>n.settingsDefaultFileViewerPreview),ul=Pa(n=>n.showMessageTTSButtons);i.useEffect(()=>{const n=()=>{tn.current=!1,Mt.current=null,nn(!1)};return document.addEventListener("mouseup",n),()=>document.removeEventListener("mouseup",n)},[]),i.useEffect(()=>()=>{kn.current!==null&&window.clearTimeout(kn.current),Rn.current!==null&&window.clearTimeout(Rn.current)},[]);const dl=i.useCallback((n,o)=>{const c=n.split(`
|
|
14
|
+
`),g=Math.max(1,o.start),v=Math.min(c.length,o.end);return g>v?"":c.slice(g-1,v).join(`
|
|
15
|
+
`)},[]),ji=i.useRef(null),fl=_u({source:"file",fileLabel:d?.path??null,language:d?.path&&Fr(d.path)||"text",getCodeForRange:n=>dl(H,$u(n)),toStoreRange:n=>({startLine:n.start,endLine:n.end}),fromDraftRange:n=>({start:n.startLine,end:n.endLine})}),{drafts:Si,commentText:cs,setCommentText:Ni,editingDraftId:us,setSelection:Fi,saveComment:Ei,cancel:Vn,reset:ki,startEdit:Ri,deleteDraft:Ti}=fl;i.useEffect(()=>{it(null),ki(),Se(""),Ys(!1)},[d?.path,ki]),i.useEffect(()=>{Fi(te)},[te,Fi]),i.useEffect(()=>{if(!te&&!us)return;const n=c=>{const g=c.target;g.closest('[data-comment-input="true"]')||g.closest('[data-comment-card="true"]')||g.closest(".cm-gutterElement")||g.closest("[data-sonner-toast]")||g.closest("[data-sonner-toaster]")||cs.trim()||(it(null),Vn())},o=setTimeout(()=>{document.addEventListener("click",n)},100);return()=>{clearTimeout(o),document.removeEventListener("click",n)}},[Vn,cs,us,te]),i.useEffect(()=>{if(!u||!te)return;const n=Pe.current;if(!n)return;const o=n.state.selection.main;o.empty||n.dispatch({selection:{anchor:o.head}});const c=document.getSelection();c&&!c.isCollapsed&&c.anchorNode&&n.contentDOM.contains(c.anchorNode)&&c.removeAllRanges()},[u,te]);const Mi=i.useCallback((n,o)=>{const c=o??te??void 0;o&&it(o),Ei(n,c),it(null)},[te,Ei]),Vi=i.useCallback((n,o)=>{const c=[];for(const g of o){if(!(g&&typeof g.name=="string"&&g.name.length>0)||!b&&g.name.startsWith(".")||!E&&Ef(g.name))continue;const v=g.name,N=ae(g.path||""),L=N?Sf(N)?N:ae(`${n}/${N}`):ae(`${n}/${v}`),q=g.isDirectory?"directory":"file",be=q==="file"&&v.includes(".")?v.split(".").pop()?.toLowerCase():void 0;c.push({name:v,path:L,type:q,extension:be})}return jf(c)},[E,b]),_e=i.useCallback(async(n,o=!1)=>{if(!R)return;const c=ae(n.trim());if(!c||!o&&Je.current.has(c))return;const g=O.current,v=ot();return Be.run(c,async N=>{const L=()=>N()&&O.current===g&&ot()===v;try{const q=a.listDirectory?(await a.listDirectory(c)).entries:await fc.listLocalDirectory(c);if(!L())return;const be=Vi(c,q);Je.current=new Set(Je.current),Je.current.add(c),bn($=>{if(!$[c])return $;const pe={...$};return delete pe[c],pe}),Xs($=>$[c]&&Cu($[c],be)?$:{...$,[c]:be})}catch(q){if(!L())return;const be=q instanceof Error?q.message:String(q??"");if(be==="Directory not found"&&l&&c!==l){Xr(l,c),bn($=>{if(!$[c])return $;const pe={...$};return delete pe[c],pe});return}console.error("Failed to load files directory:",q),bn($=>({...$,[c]:be}))}},o)},[Be,a,Vi,Xr,l,R]),ds=i.useCallback(async()=>{l&&(Je.current=new Set,Be.clear(),bn({}),Xs(n=>Object.keys(n).length===0?n:{}),await _e(l))},[Be,_e,l]),Ue=i.useCallback(async n=>{if(!n){await ds();return}const o=ae(n);Je.current=new Set(Je.current),Je.current.delete(o),await _e(o,!0)},[_e,ds]),{canUpload:Pi,uploadingDirectory:ml,pickFiles:Di,uploadElements:hl}=Zc({root:l,refreshDirectory:Ue}),fs=ml!==null,Ai=i.useRef(""),Li=i.useRef("");i.useEffect(()=>{if(!l)return;const n=A,o=Ai.current!==z,c=Li.current!==n;!o&&!c||(o&&(Ai.current=z,Jt.current+=1,Lt.current=null,je(""),Fe(null),Ze(""),ve(null),se(!1)),c&&(Li.current=n,Je.current=new Set,Be.clear(),bn({}),Xs(g=>Object.keys(g).length===0?g:{}),_e(l)))},[Be,z,_e,l,A]),i.useEffect(()=>{if(!R||!a.listDirectory)return;const n=()=>{if(!document.hidden&&ct.length>0)for(const o of ct)Be.has(o)||Ue(o)};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[Be,ct,a.listDirectory,Ue,R]);const zi=i.useRef(!1);i.useEffect(()=>{const n=R&&!zi.current;if(zi.current=R,!(!R||!l)&&(_e(l),n))for(const o of ct)Be.has(o)||Ue(o)},[Be,ct,_e,Ue,l,R]),i.useEffect(()=>{if(!R||!a.listDirectory||ct.length===0)return;const n=setInterval(()=>{if(!document.hidden)for(const o of ct)Be.has(o)||Ue(o)},8e3);return()=>clearInterval(n)},[Be,ct,a.listDirectory,Ue,R]);const pl=i.useCallback(async n=>{if(n?.preventDefault(),!Bt||!Ot)return;sr(!0);const o=()=>{nr(null)},c=v=>{J.error(v)},g=()=>{sr(!1)};if(Ot==="createFile"){if(!Tt.trim()){c(t("sidebarFilesTree.toast.filenameRequired")),g();return}if(!a.writeFile){c(t("sidebarFilesTree.toast.writeNotSupported")),g();return}const v=Bt.path,N=v?`${v}/`:"",L=ae(`${N}${Tt.trim()}`);await a.writeFile(L,"").then(async q=>{q.success&&(J.success(t("sidebarFilesTree.toast.fileCreated")),await Ue(v)),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(g);return}if(Ot==="createFolder"){if(!Tt.trim()){c(t("sidebarFilesTree.toast.folderNameRequired")),g();return}const v=Bt.path,N=v?`${v}/`:"",L=ae(`${N}${Tt.trim()}`);await a.createDirectory(L).then(async q=>{q.success&&(J.success(t("sidebarFilesTree.toast.folderCreated")),await Ue(v)),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(g);return}if(Ot==="rename"){if(!Tt.trim()){c(t("sidebarFilesTree.toast.nameRequired")),g();return}if(!a.rename){c(t("sidebarFilesTree.toast.renameNotSupported")),g();return}const v=Bt.path,N=v.split("/").slice(0,-1).join("/"),L=N?`${N}/`:"",q=ae(`${L}${Tt.trim()}`);await a.rename(v,q).then(async be=>{be.success&&(J.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Ue(N),l&&Ft(l,v),(d?.path===v||d?.path.startsWith(`${v}/`))&&(l&&Te(l,null),je(""),Fe(null),Ze(""),ve(null),u&&se(!1))),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(g);return}if(Ot==="delete"){if(!a.delete){c(t("sidebarFilesTree.toast.deleteNotSupported")),g();return}const v=Bt.path,N=v.split("/").slice(0,-1).join("/");await a.delete(v).then(async L=>{L.success&&(J.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Ue(N),l&&Ft(l,v),(d?.path===v||d?.path.startsWith(`${v}/`))&&(l&&Te(l,null),je(""),Fe(null),Ze(""),ve(null),u&&se(!1))),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(g);return}g()},[Ot,Bt,Tt,a,Ue,u,Ft,l,d?.path,Te,t]);i.useEffect(()=>{if(!y){Zn([]),Qn(!1);return}const n=ne.trim();if(!n){Zn([]),Qn(!1);return}let o=!1;return Qn(!0),I(y,n,150,{includeHidden:b,respectGitignore:!E,type:"file"}).then(c=>{if(o)return;const v=c.filter(N=>E||!kf(N.path)).map(N=>({name:N.name,path:ae(N.path),type:"file",extension:N.extension,relativePath:N.relativePath}));Zn(v)}).catch(()=>{o||Zn([])}).finally(()=>{o||Qn(!1)}),()=>{o=!0}},[y,ne,I,b,E]);const ms=i.useCallback(async(n,o)=>{const c=ut(n);if(a.readFile)return(await a.readFile(n,{...c,directory:l||void 0,...o})).content??"";const g=new URLSearchParams({path:n});c.allowOutsideWorkspace&&g.set("allowOutsideWorkspace","true"),l&&g.set("directory",l);const v=await Ls(`/api/fs/read?${g.toString()}`,{cache:o?.fresh?"no-store":"default",signal:AbortSignal.timeout(3e4)});if(!v.ok){const N=await v.json().catch(()=>({error:v.statusText}));throw new Error(N.error||t("filesView.error.readFileFailed"))}return v.text()},[a,ut,l,t]),ht=i.useCallback(async n=>{if(a.statFile){const o=ut(n),c=await a.statFile(n,{...o,directory:l||void 0});return{path:c.path,size:c.size,mtimeMs:c.mtimeMs}}return null},[a,ut,l]);i.useEffect(()=>{if(!l||!a.statFile||Re.length===0)return;let n=!1;const o=[...Re];return Promise.all(o.map(async c=>{try{const g=ut(c),v=await a.statFile?.(c,{...g,directory:l||void 0});!n&&v&&!v.isFile&&Ft(l,c)}catch(g){!n&&ro(g)&&Ft(l,c)}})),()=>{n=!0}},[a,Re,Ft,ut,l]);const Ke=oe!==H||Cn,Vt=i.useCallback((n,o=!0)=>{const{content:c,lineEnding:g}=Nd(n);return o&&Lr(xt.current)&&Un(v=>v+1),Zs.current=n,Qs.current+=1,$o(g),je(c),Rt.current=c,yn.current=c,Se(c),c},[]),wt=i.useCallback(async()=>{if(!d||!a.writeFile)return J.error(t("filesView.toast.savingNotSupported")),!1;const n=(zn(d.path)||zt)&&!jn.current;if(!jd({selectedFilePath:d.path,loadedFilePath:de,fileLoading:Me,isDirty:Ke,draftContent:oe,fileContent:H,isNonEditableBinary:n}))return n?console.warn(`[saveDraft] refusing to save binary file "${d.path}".`):oe===""&&H!==""&&de!==d.path&&console.warn(`[saveDraft] refusing to save empty draft for "${d.path}" (${H.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(!Ke)return!0;Ys(!0);try{const o=Cn?Yt.current:null;Cn&&!o&&ft(!1);const c=o?await o.getContent("save"):Vr;if(!c.ok)return J.error(c.message),!1;const g=c.snapshot;if(g&&"bytes"in g){if(!a.uploadFile)return J.error(t("filesView.toast.savingNotSupported")),!1;if(Qe.current=null,!(await a.uploadFile(d.path,new Blob([g.bytes]),{overwrite:!0}))?.success)return J.error(t("filesView.toast.writeFileFailed")),!1;Yt.current?.markSaved(g.signature)}else{const v=Fd(g?g.content:oe,ni);if(!(await a.writeFile(d.path,v))?.success)return J.error(t("filesView.toast.writeFileFailed")),!1;g?(Vt(v,!1),Yt.current?.markSaved(g.signature)):(je(oe),Zs.current=v,Qs.current+=1)}if(l&&Bn(d.path,l)){const v=Is(l,d.path);v&&Ic.requestGitRefresh({directory:l,paths:[v]})}if(l&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(ae(d.path))){const v=Oc.getState().projects.find(N=>ae(N.path)===ae(l));if(v)try{await Qc(v.id)}catch{J.error(t("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return d?.path&&In(d.path)&&(Rt.current=oe,yn.current=oe),ht(d.path).then(v=>{v&&(Qe.current=v)}).catch(()=>{}),!0}catch(o){return J.error(o instanceof Error?o.message:t("filesView.toast.saveFailed")),!1}finally{Ys(!1)}},[Vt,zt,oe,Cn,H,Me,a,Ke,ni,de,ht,l,d,t]);ri.current=wt,i.useEffect(()=>{Ve||(Zt("idle"),dt.current&&(clearTimeout(dt.current),dt.current=null))},[Ve]);const hs=1500;i.useEffect(()=>{const n=!!(d&&a.writeFile),o=!!(d?.path&&(zn(d.path)||zt))&&!jn.current;if(!Cd({autoSaveEnabled:Ve,isDirty:Ke,canWrite:n,isSaving:Xt,fileLoading:Me,selectedFilePath:d?.path,loadedFilePath:de,isNonEditableBinary:o,wouldEmptyFile:oe===""&&H!==""}))return;const c=g=>{dt.current=setTimeout(()=>{const v=Date.now()-li.current;if(v<hs){c(hs-v);return}wt().then(N=>{N&&(Zt("saved"),setTimeout(()=>Zt("idle"),2e3))})},g)};return c(hs),()=>{dt.current&&(clearTimeout(dt.current),dt.current=null)}},[Ve,zt,oe,H,Me,Ke,de,d,a.writeFile,Xt,wt]),i.useEffect(()=>{Zt("idle")},[d?.path]);const Ii=i.useCallback(()=>{dt.current&&(clearTimeout(dt.current),dt.current=null),Xt||wt().then(n=>{n&&(Zt("saved"),setTimeout(()=>Zt("idle"),2e3))})},[Xt,wt]);Bc({save_file:n=>{if(!(n.target instanceof Node)||!Tn.current?.contains(n.target)&&!oi.current?.contains(n.target))return!1;Ii()},find_in_file:n=>{if(!(n.target instanceof Node))return!1;if(nt&&qe()==="preview"){if(u||!(ee?as.current:rs.current)?.contains(n.target))return!1;ss(!0),pi(c=>c+1);return}if(!Tn.current?.contains(n.target))return!1;ze(!0)}});const Oi=i.useCallback(async n=>{const o=Jt.current+1;Jt.current=o;const c=ot(),g=k.current,v=()=>{if(!l||ot()!==c||k.current!==g)return!1;const $=st.getState().byRoot[l],pe=$?.selectedPath??$?.openPaths[0]??null;return Jt.current===o&&pe===n.path};Fe(null),Ze(""),ve(null),ai(!1),Et(!0);const N=Er(n.path),L=kr(n.path),q=Da(n.path),be=zn(n.path);if(u&&se(!0),h.isDesktop&&N&&!L){je(""),Se("");return}if(!h.isDesktop&&N&&!L){je(""),Se(""),ve(n.path),Et(!1);return}if(q){je(""),Se(""),ve(n.path),Et(!1);return}if(be){je(""),Se(""),ve(n.path),Et(!1);return}await ms(n.path).then($=>{if(!v())return;if(Aa($)){ai(!0),je(""),Se(""),ve(n.path);return}const pe=Vt($),_t=Ar(n.path)||Ds(n.path)||io(n.path)||In(n.path)||kr(n.path)||La(n.path)||za(n.path)||Lr(n.path);ke(_t?"edit":Ed(pe,Kn.current[n.path])),ve(n.path),ht(n.path).then(fn=>{fn&&v()&&(Qe.current=fn)}).catch(()=>{})}).catch($=>{if(v()){if(Rf($)){if(Et(!1),l&&Te(l,null),Fe(null),je(""),Se(""),ve(null),Qe.current=null,B.trim().length>0&&U(""),u&&se(!1),l){const _t=[...no(n.path,l),n.path];_t.length>0&&Xn(l,_t);for(const fn of _t)Je.current.has(fn)||_e(fn)}return}if(ro($)){l&&Ft(l,n.path),je(""),Se(""),Fe(null),Qe.current=null,u&&se(!1);return}je(""),Se(""),Fe($ instanceof Error?$.message:t("filesView.error.readFileFailed")),Qe.current=null}}).finally(()=>{v()&&Et(!1)})},[Vt,Xn,u,_e,ms,ht,Ft,l,h.isDesktop,B,Te,t]),ps=i.useCallback(async(n,o)=>{if(!e||!l)return;const c=no(n,l),g=o?[...c,n]:c;if(g.length>0&&Xn(l,g),!R)return;const v=g.map(N=>{if(!Je.current.has(N))return _e(N)}).filter(Boolean);await Promise.all(v)},[Xn,_e,l,R,e]),Bi=i.useCallback((n,o)=>{const c=o.findIndex(g=>g.path===n);return c===-1||o.length<=1?null:o[c+1]??o[c-1]??null},[]),$e=i.useCallback(async n=>{if(En.current)En.current=!1;else if(Ke){Nn(!0),Qt.current=n;return}l&&(Te(l,n.path),ps(n.path,!1)),Fe(null),Ze(""),je(""),Rt.current="",yn.current="",ft(!1),Se(""),ve(null),u&&se(!0)},[ps,Ke,u,l,Te]);i.useEffect(()=>{d?.path&&ps(d.path,!1)},[ps,d?.path]),i.useEffect(()=>{if(!e)return;if(!d){Jt.current+=1,Lt.current=null,Et(!1);return}if(de===d.path||Lt.current===d.path)return;const n=d.path;Lt.current=n,Oi(d).finally(()=>{Lt.current===n&&(Lt.current=null)})},[Sn,Oi,de,d,e]);const gs=i.useRef(Ke);gs.current=Ke,i.useEffect(()=>eu(({runtimeKey:n,paths:o})=>{const c=d?.path;n!==ot()||!c||gs.current||!o.includes(ae(c))||(Jt.current+=1,Lt.current=null,Qe.current=null,Ze(""),Fe(null),ve(null),Uo(g=>g+1))}),[d?.path]),i.useEffect(()=>{if(!e||!d?.path||de!==d.path)return;const n=d.path,o=ot(),c=k.current,g=()=>gs.current||In(n)&&Rt.current!==yn.current,v=!zn(n)&&!Er(n)&&!zt?xd({readContent:()=>ms(n,{fresh:!0}),getLoadedContent:()=>Zs.current,getLoadedRevision:()=>Qs.current,isDirty:g,applyContent:$=>{if(!(N||ot()!==o||k.current!==c)){if(Aa($)){ve(null);return}Vt($)}}}):null;let N=!1,L=!1;const q=()=>{document.hidden||L||(L=!0,ht(n).then(async $=>{if(N||ot()!==o||k.current!==c||!$)return;const pe=Qe.current;if(!pe||pe.path!==n){Qe.current=$;return}if(wd(pe,$)){if(v&&$.size<=Tf){await v.poll()&&!N&&(Qe.current=$);return}gs.current||(Qe.current=$,ve(null))}}).catch(()=>{}).finally(()=>{L=!1}))};q();const be=window.setInterval(q,2e3);return()=>{N=!0,v?.dispose(),window.clearInterval(be)}},[Vt,zt,de,ms,ht,d?.path,e]);const gl=i.useCallback(()=>{const n=Qt.current,o=Fn.current;if(Qt.current=null,Fn.current=null,En.current=!0,Nn(!1),ft(!1),Un(c=>c+1),Se(H),o){l&&Ht(l,o),d?.path===o&&(n?$e(n):(l&&Te(l,null),je(""),Fe(null),Ze(""),ve(null),u&&se(!1)));return}if(n){$e(n);return}},[H,$e,u,Ht,l,d?.path,Te]),xl=i.useCallback(async()=>{const n=Qt.current,o=Fn.current;if(!await wt()){En.current=!1;return}if(Qt.current=null,Fn.current=null,En.current=!0,Nn(!1),o){l&&Ht(l,o),d?.path===o&&(n?await $e(n):(l&&Te(l,null),je(""),Fe(null),Ze(""),ve(null),u&&se(!1)));return}if(n){await $e(n);return}},[$e,u,Ht,l,wt,d?.path,Te]),_i=i.useCallback(n=>{const o=d?.path===n,c=Bi(n,Gt);if(o&&Ke){Nn(!0),Qt.current=c,Fn.current=n;return}if(l&&Ht(l,n),!!o){if(c){$e(c);return}l&&Te(l,null),je(""),Fe(null),Ze(""),ve(null),u&&se(!1)}},[Bi,$e,Ke,u,Gt,Ht,l,d?.path,Te]),$i=i.useMemo(()=>new Set(Re),[Re]),xs=i.useMemo(()=>ju(M?K?.files??[]:[]),[K?.files,M]),vl=i.useCallback(n=>{if($i.has(n))return"open";const o=n.startsWith(l+"/")?n.slice(l.length+1):n;return xs.statusByPath.get(o)??null},[$i,xs,l]),wl=i.useCallback(n=>{if(!K?.files)return null;const o=n.startsWith(l+"/")?n.slice(l.length+1):n;return xs.badgeByDir.get(o)??null},[K,xs,l]),bl=i.useCallback(async n=>{const o=ae(n);l&&(Yr(l,o),Je.current.has(o)||await _e(o))},[_e,l,Yr]),yl=i.useMemo(()=>({canRename:vi,canCreateFile:gi,canCreateFolder:xi,canDelete:wi,canReveal:bi}),[vi,gi,xi,wi,bi]);function Wi(n,o){const c=ei[n]??[];return c.map((g,v)=>{const N=g.type==="directory",L=N&&Lo.has(g.path),q=d?.path===g.path,be=v===c.length-1;return s.jsxs("li",{className:"relative",children:[o>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),be&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(Mf,{node:g,root:l,isExpanded:L,isActive:q,isMobile:u,isBrowserClient:j,alwaysShowActions:T,status:N?void 0:vl(g.path),badge:N?wl(g.path):void 0,permissions:yl,downloadFile:a.downloadFile,contextMenuPath:Zo,setContextMenuPath:Qo,rightClickMenuPath:el,setRightClickMenuPath:tl,onSelect:$e,onToggle:bl,onRevealPath:ll,onOpenDialog:ir,canUpload:Pi&&!fs,onPickFiles:Di}),N&&L&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Jn[g.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:Jn[g.path],children:Jn[g.path]}),s.jsxs(W,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ue(g.path)},children:[s.jsx(V,{name:"refresh",className:"size-3.5"}),t("filesView.tree.actions.refreshTitle")]})]}):null,Wi(g.path,o+1)]})]},g.path)})}const He=!!(d?.path&&Er(d.path)),et=!!(d?.path&&kr(d.path)),Ui=et&&Ye==="edit",Pt=!!(d?.path&&Da(d.path)),Ki=!!(d?.path&&_c(d.path)),lr=Ki||!!(d?.path&&$c(d.path)),cr=!!(d?.path&&Wc(d.path)),vs=!!(d?.path&&(zn(d.path)||zt)),sn=vs&&!He&&!Pt&&!lr&&!cr,Hi=vs||He&&!Ui,qi=i.useMemo(()=>ae(mt?.path??""),[mt?.path]),rn=!!(mt&&qi&&Oe&&Oe===qi&&!Me&&!rt&&!Hi),bt=i.useMemo(()=>Is(l,Oe),[Oe,l]),Cl=!!(d&&(!He||et)&&!Pt&&!sn&&H.length>0),jl=!!(d&&bt.length>0),tt=!!(d&&!Yn&&!vs&&(!He||et)&&a.writeFile),ur=!!(d&&!vs&&(!He||et)),dr=Dd(d?.path),De=dr&&(ur||dr.editor.content==="binary")?dr:null,yt=De!==null,Pn=De?.editor.content==="binary";jn.current=Pn;const nt=!yt&&!!(d?.path&&Ar(d.path)),an=!yt&&!!(d?.path&&io(d.path)),on=!yt&&!!(d?.path&&Ds(d.path)),Dn=!yt&&!!(d?.path&&In(d.path)),ln=!yt&&!!(d?.path&&La(d.path)),cn=!yt&&!!(d?.path&&za(d.path)),un=yt,An=yt&&(Pn?gt===null||gt<=zr:oe.length<=zr),Sl=$r(n=>n.status),Nl=!yt&&ur&&Sl!=="unsupported"&&!!(d?.path&&Uc(d.path)),ws=ur&&!nt&&!Dn&&!un&&!(on&&xe==="preview")&&!(et&&Ye==="preview")&&!(ln&&we==="preview")&&!(cn&&ie==="table"),Fl=nt&&G==="edit"||on&&xe==="edit"||un&&(Ce==="edit"||!An)||et&&Ye==="edit"||ln&&we==="edit"||cn&&ie==="text"||an&&re==="text"||!nt&&!on&&!an&&!un&&!et&&!ln&&!cn&&Z==="edit",bs=i.useMemo(()=>Oe?Kc(Oe):null,[Oe]),[Gi,fr]=i.useState(null);i.useEffect(()=>{let n=!1;const o=d?.path;if(!o||bs){fr(null);return}return fr(null),Hc(o).then(c=>{n||fr(c)}),()=>{n=!0}},[d?.path,bs]),i.useEffect(()=>{!tt&&Z==="edit"&&ke("view")},[tt,Z]);const mr="openchamber:files:md-viewer-mode",hr="openchamber:files:html-viewer-mode",pr="openchamber:files:json-viewer-mode";i.useEffect(()=>{const n=d?.path;if(!n)return;ke(Kn.current[n]??"edit");let o=Mn?"preview":"edit";try{const v=localStorage.getItem(mr);(v==="preview"||v==="edit")&&(o=v)}catch{}X(Ws.current[n]??o);let c=Mn?"preview":"edit";try{const v=localStorage.getItem(hr);(v==="preview"||v==="edit")&&(c=v)}catch{}he(Us.current[n]??c),ye(Ks.current[n]??(Mn?"preview":"edit")),ue(wn.current[n]??"preview"),Ie(Hr.current[n]??"preview"),vn(qr.current[n]??"preview"),Nt(Gr.current[n]??"table");let g=Mn?"tree":"text";try{const v=localStorage.getItem(pr);(v==="tree"||v==="text")&&(g=v)}catch{}me(g)},[d?.path,Mn]);const El=i.useCallback(n=>{const o=d?.path;o&&(Kn.current[o]=n),ke(n)},[d?.path]),kl=i.useCallback(n=>{const o=d?.path;o&&(Ws.current[o]=n),X(n);try{localStorage.setItem(mr,n)}catch{}},[d?.path]),qe=i.useCallback(()=>G,[G]),Rl=i.useCallback(n=>{const o=d?.path;o&&(Hr.current[o]=n),Ie(n)},[d?.path]),Tl=i.useCallback(n=>{const o=d?.path;o&&(qr.current[o]=n),vn(n)},[d?.path]),Ml=i.useCallback(n=>{const o=d?.path;o&&(Gr.current[o]=n),Nt(n)},[d?.path]);i.useEffect(()=>{const n=d?.path;if(Kr(null),!n||de!==n)return;let o=!1;return ht(n).then(c=>{!o&&c&&Kr(c.size)}).catch(()=>{}),()=>{o=!0}},[Sn,de,ht,d?.path]);const Xi=d&&nt&&qe()==="preview"&&!Me?d.path:null;i.useEffect(()=>{!Xi||u||is()},[is,ee,u,Xi]);const Vl=i.useCallback(n=>{me(n);try{localStorage.setItem(pr,n)}catch{}},[]),Pl=i.useCallback(n=>{const o=d?.path;o&&(Us.current[o]=n),he(n);try{localStorage.setItem(hr,n)}catch{}},[d?.path]),Dl=i.useCallback(n=>{const o=d?.path;if(o&&(Ks.current[o]=n),We.current&&(clearTimeout(We.current),We.current=null),vt.current!==null&&(cancelAnimationFrame(vt.current),vt.current=null),n==="edit")Se(Rt.current||H),ye(n);else{Rt.current=oe;const c=o;ye("edit"),vt.current=requestAnimationFrame(()=>{vt.current=requestAnimationFrame(()=>{vt.current=null,!(l&&c&&st.getState().byRoot[l]?.selectedPath!==c)&&(Do(g=>g+1),ye("preview"))})});return}},[oe,H,l,d?.path]),Al=i.useCallback(n=>{const o=d?.path,c=()=>{o&&(wn.current[o]=n)};if(n==="edit"){if(!Js.current){c(),ft(!1),ue(n);return}Promise.resolve(Yt.current?.getContent("handoff")??Vr).then(v=>{if(xt.current===o){if(!v.ok){J.error(v.message);return}c(),Se(v.snapshot&&"content"in v.snapshot?v.snapshot.content:H),ft(!1),ue(n)}});return}if(!An){De&&J.error(t("filesView.fileEditor.tooLarge",{editor:De.editor.title}));return}c(),ft(!1);const g=o;At.current!==null&&cancelAnimationFrame(At.current),At.current=requestAnimationFrame(()=>{At.current=null,!(l&&g&&st.getState().byRoot[l]?.selectedPath!==g)&&(Un(v=>v+1),ue("preview"))})},[An,H,De,l,d?.path,t]),gr=i.useCallback(async(n,o)=>{if(!a.writeFile||o===yn.current)return!1;if(!(await a.writeFile(n,o))?.success)return J.error(t("filesView.toast.writeFileFailed")),!1;Vt(o);const g=await ht(n).catch(()=>null);return g&&(Qe.current=g),!0},[Vt,a,ht,t]);i.useEffect(()=>()=>{We.current&&(clearTimeout(We.current),We.current=null),vt.current!==null&&(cancelAnimationFrame(vt.current),vt.current=null)},[le,d?.path]);const Ll=i.useCallback(n=>{if(Rt.current=n,!Ve||!d?.path||le!=="preview"||!a.writeFile)return;We.current&&clearTimeout(We.current);const o=d.path;We.current=setTimeout(()=>{We.current=null,gr(o,n).then(c=>{c&&(ts(!0),setTimeout(()=>ts(!1),1500))}).catch(c=>{J.error(c instanceof Error?c.message:t("filesView.toast.saveFailed"))})},hs)},[Ve,le,a.writeFile,gr,d?.path,t]),zl=i.useMemo(()=>Dn&&(Rt.current||oe)||H,[oe,H,Dn]),Il=i.useCallback(()=>{const n=xt.current;n&&(wn.current[n]="edit"),ft(!1),ue("edit"),De&&J.error(t("filesView.fileEditor.unsupported",{editor:De.editor.title}))},[De,t]);i.useEffect(()=>()=>{At.current!==null&&(cancelAnimationFrame(At.current),At.current=null)},[Ce,d?.path]);const Yi=i.useCallback(()=>xe,[xe]);i.useEffect(()=>{const n=c=>{const g=c?"preview":"edit",v=c?"tree":"text";for(const N of Re)Kn.current[N]="edit",Ar(N)&&(Ws.current[N]=g),Ds(N)&&(Us.current[N]=g),In(N)&&(Ks.current[N]=g),Lr(N)&&(wn.current[N]=g);ke("edit"),X(g),he(g),ye(g),ue(g),me(v);try{localStorage.setItem(mr,g),localStorage.setItem(hr,g),localStorage.setItem(pr,v)}catch{}},o=c=>{const g=!!c.detail?.enabled;n(g)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",o),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",o)}},[Re]),i.useEffect(()=>{if(!mt||!l)return;const n=()=>{typeof window>"u"||en.current===null&&(en.current=window.requestAnimationFrame(()=>{en.current=null,tr(jt=>jt+1)}))},o=(jt,$t)=>{if(jt.state.doc.length!==$t.length)return!1;if($t.length===0)return!0;const Sr=Math.min(128,$t.length);if(jt.state.sliceDoc(0,Sr)!==$t.slice(0,Sr))return!1;const ka=Math.max(0,$t.length-Sr);return jt.state.sliceDoc(ka,$t.length)===$t.slice(ka)},c=ae(mt.path);if(!c){os(null),It.current={key:"",attempts:0};return}const g=`${c}:${mt.line}:${mt.column??1}`;if(It.current.key!==g&&(It.current={key:g,attempts:0}),d?.path!==c){if(er)return;$e(qt(c));return}if(Me||de!==c)return;if(rt||He||Pt||sn){os(null),It.current={key:"",attempts:0};return}if(!tt)return;if(Z!=="edit"){ke("edit");return}const v=Pe.current;if(!v){n();return}if(!o(v,oe)){n();return}const N=Math.max(1,Math.min(mt.line,v.state.doc.lines)),L=v.state.doc.line(N),q=Math.max(1,mt.column||1),be=Math.max(0,L.to-L.from),$=Math.min(be,q-1),pe=L.from+$;if(!(v.state.selection.main.head===pe)||It.current.attempts===0){It.current.attempts+=1,v.dispatch({selection:{anchor:pe},effects:lt.scrollIntoView(pe,{y:"center"})}),v.focus(),n();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const jt=Pe.current;jt&&(jt.dispatch({selection:{anchor:pe},effects:lt.scrollIntoView(pe,{y:"center"})}),jt.focus())}),os(null),It.current={key:"",attempts:0}},[tt,er,oe,Xo,rt,Me,He,Pt,sn,de,$e,mt,l,d?.path,os,Z,qt]),i.useEffect(()=>{if(!ar||!l)return;const n=ae(ar);if(!n){or(null);return}d?.path===n&&(Me||de!==n||(!rt&&!He&&!Pt&&!sn&&tt&&Z==="edit"&&Pe.current?.focus(),or(null)))},[tt,rt,Me,He,Pt,sn,de,ar,l,d?.path,or,Z]);const dn=i.useCallback(n=>{if(!u||!n||typeof window>"u")return;const o=document.activeElement,c=!n.hasFocus&&o instanceof HTMLElement&&n.dom.contains(o)?o.closest('[data-comment-input="true"]'):null;if(!n.hasFocus&&!c)return;const g=window.visualViewport;if(!g)return;const v=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,v-(g.offsetTop+g.height))<=0)return;const L=c?c.getBoundingClientRect():n.coordsAtPos(n.state.selection.main.head);if(!L)return;const q=Math.round(g.offsetTop+g.height),$=L.bottom+20-q;$<=0||(n.scrollDOM.scrollTop+=$)},[u]);i.useEffect(()=>{if(!u||typeof window>"u")return;const n=()=>{window.requestAnimationFrame(()=>{dn(Pe.current)})},o=window.visualViewport;return o?.addEventListener("resize",n),o?.addEventListener("scroll",n,{passive:!0}),document.addEventListener("selectionchange",n),()=>{o?.removeEventListener("resize",n),o?.removeEventListener("scroll",n),document.removeEventListener("selectionchange",n)}},[u,dn]),Ia("open_go_to_line",n=>{if(!tt||Z!=="edit"||u)return!1;const o=n.target;if(o?.closest('[role="dialog"]')||!(o instanceof Node)||!Tn.current?.contains(o))return!1;const c=!!o?.closest(".cm-editor");if(!!o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!c)return!1;rr(!0)}),Ia("open_document_symbols",n=>{if(!tt||Z!=="edit"||u)return!1;const o=n.target;if(o?.closest('[role="dialog"]')||!(o instanceof Node)||!Tn.current?.contains(o))return!1;ns(!0)});const ys=at(n=>n.editorFontSize),pt=d?.path&&l&&d.path.startsWith(`${l}/`)?d.path.slice(l.length+1):null,Ji=Nr(n=>{if(!pt||!l)return null;const o=n.directories.get(y)?.status,c=o?.files.find(g=>g.path===pt)??null;return JSON.stringify([pt,o?.current??null,c])}),[xr,vr]=i.useState(null);i.useEffect(()=>{if(!pt||!l||!Ji){vr(null);return}let n=!1;return f.getGitFileDiff(l,{path:pt}).then(o=>{if(n)return;const c=Nr.getState().directories.get(y)?.status?.files.find(N=>N.path===pt),g=c!==void 0&&(c.index==="?"||c.index==="A"||c.working_dir==="?"),v=!o.isBinary&&!o.submodule&&(o.original!==""||g);vr({path:pt,text:v?o.original:null})}).catch(()=>{n||vr({path:pt,text:null})}),()=>{n=!0}},[y,f,Ji,l]);const Zi=i.useRef(xr);Zi.current=xr;const Cs=i.useCallback(n=>{if(!n)return;const o=Zi.current;Gd(n,o&&o.path===pt?o.text:null)},[pt]);i.useEffect(()=>{Cs(Pe.current)},[Cs,xr]);const Qi=i.useRef(()=>{});Qi.current=()=>{if(!d?.path||!l)return;const n=mc(l),o=at.getState(),c=o.contextPanelByDirectory[n]?.tabs.find(g=>g.preview&&g.targetPath===d.path);c&&o.pinContextPanelTab(n,c.id)};const ea=i.useMemo(()=>lt.updateListener.of(n=>{if(!n.docChanged)return;n.transactions.some(c=>c.isUserEvent("input")||c.isUserEvent("delete")||c.isUserEvent("undo")||c.isUserEvent("redo")||c.isUserEvent("move"))&&Qi.current()}),[]),ta=i.useMemo(()=>{if(!d?.path)return[Oa(p,{fontSize:ys})];const n=Fr(d.path),o=[Oa(p,n?{syntaxColors:!1,fontSize:ys}:{fontSize:ys})],c=bs??Gi;c&&o.push(c),n&&o.push(ou({language:n,themeName:p.metadata.id,theme:ku(p)})),ce&&o.push(lt.lineWrapping);const g=p.colors.syntax.highlights;return o.push(qd({added:g?.diffAdded??p.colors.status.success,modified:g?.diffModified??p.colors.status.info,removed:g?.diffRemoved??p.colors.status.error}),Lu({highlightWordAroundCursor:!0,minSelectionLength:2}),ea,Od()),u||o.push(Id(),Bd({vimMode:ls==="vim"})),u&&o.push(lt.updateListener.of(v=>{v.view.hasFocus&&(v.selectionSet||v.focusChanged||v.viewportChanged||v.geometryChanged)&&window.requestAnimationFrame(()=>{dn(v.view)})})),o},[p,d?.path,bs,Gi,ce,u,dn,ys,ea,ls]),na=i.useMemo(()=>({light:Hn.metadata.id,dark:qn.metadata.id}),[Hn.metadata.id,qn.metadata.id]),sa=Pt||lr||cr,Ln=d?.path&&sa?`${d.path}|${qs.allowOutsideWorkspace?"outside":"workspace"}|${Sn}`:"",js=d?.path&&on&&xe==="preview"&&!h.isVSCode?`${d.path}|${Sn}`:"",ra=t("filesView.error.readFileFailed"),{readyKey:ia,nonce:Ol}=oo(js,Fe,ra),{readyKey:aa,nonce:Ss}=oo(Ln,Fe,ra),Bl=!!(js&&ia!==js),wr=!!(Ln&&aa!==Ln),_l=d?.path&&He?et?`data:${qc(d.path)};utf8,${encodeURIComponent(H)}`:_o:"",Ns=d?.path&&sa&&Ln&&aa===Ln?Ta().authenticatedAsset(hc("/api/fs/raw",l),{path:d.path,allowOutsideWorkspace:qs.allowOutsideWorkspace?"true":void 0,directory:l||void 0}):"",$l=i.useCallback(n=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:Ns,className:"h-full w-full border-0",title:n.name},Ss)}),[Ns,Ss]),oa=d&&a.downloadFile?s.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:()=>{const n=a.downloadFile;!n||!d||n(d.path).catch(o=>{console.error("Download failed:",o),J.error(t("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(V,{name:"download",className:"mr-2 size-4"}),t("filesView.editor.saveFile")]}):null,Fs=d&&!Me&&!wr&&!rt?(n=>He&&!Ui?s.jsx(lf,{src:_l,name:n.name,sizeBytes:gt}):Pt?$l(n):lr?s.jsx(cf,{kind:Ki?"video":"audio",src:Ns,name:n.name,sizeBytes:gt,download:oa},Ss):cr?s.jsx(ef,{src:Ns,name:n.name,sizeBytes:gt},Ss):sn?s.jsx(Jd,{name:n.name,path:n.path,sizeBytes:gt,download:oa}):cn&&ie==="table"?s.jsx(mf,{path:n.path,content:H,sizeBytes:gt}):ln&&we==="preview"?s.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:s.jsx(Rs,{fallback:s.jsxs("div",{className:"m-3 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:t("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:t("filesView.error.switchToEditMode")})]}),children:s.jsx(Tr,{content:`\`\`\`mermaid
|
|
16
|
+
${H}
|
|
17
|
+
\`\`\``,className:"markdown-mermaid-fullscreen h-full",enableFileReferences:!1,allowMermaidWheelEvents:!0})})}):null)(d):null;i.useEffect(()=>{let n=!1,o="";return(async()=>{if(!d?.path||!He||et){Ze("");return}Fe(null);const g=ut(d.path);if(n)return;await(a.readFileBinary?a.readFileBinary(d.path,g).then(N=>N.dataUrl):(async()=>{const N=await Ls("/api/fs/raw",{signal:AbortSignal.timeout(3e4),query:{path:d.path,allowOutsideWorkspace:g.allowOutsideWorkspace?"true":void 0,directory:l||void 0}});if(!N.ok)throw new Error(t("filesView.error.readFileFailed"));const L=await N.blob();return o=URL.createObjectURL(L),n?(URL.revokeObjectURL(o),o="",""):o})()).then(N=>{n||(Ze(N),ve(d.path))}).catch(N=>{n||(Ze(""),Fe(N instanceof Error?N.message:t("filesView.error.readFileFailed")),ve(null))}).finally(()=>{n||Et(!1)})})(),()=>{n=!0,o&&URL.revokeObjectURL(o)}},[Sn,a,He,et,ut,l,d?.path,qs,t]);const Wl=i.useCallback(()=>nr(null),[]),Ul=i.useMemo(()=>Wu({drafts:Si,editingDraftId:us,commentText:cs,onTextChange:Ni,selection:te,isDragging:Ci,fileLabel:d?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:n=>({start:n.startLine,end:n.endLine}),onSave:Mi,onCancel:()=>{it(null),Vn()},onEdit:n=>{Ri(n),it({start:n.startLine,end:n.endLine})},onDelete:Ti}),[Vn,cs,Ti,us,Si,Mi,Ci,te,d?.path,Ni,Ri]),la=Ha(),ca=Ha(),Es=!Me&&!rt&&de===Oe,br=i.useMemo(()=>!!Oe&&Md({hasCanvas:un,viewMode:Ce,previewReady:Es,mountable:An}),[An,Ce,un,Es,Oe]),ks=Es&&ws&&Z==="view"&&!(an&&re==="tree"),ua=Es&&nt&&qe()==="preview",{setScroller:da,restore:Kl}=Ms(ks?`${kt}:code`:null),{setScroller:fa,restore:Hl}=Ms(ks?`${kt}:code:fullscreen`:null),{setScroller:ma}=Ms(ua?`${kt}:markdown`:null),{setScroller:ha}=Ms(ua?`${kt}:markdown:fullscreen`:null),{setScroller:pa}=la,{setScroller:ga}=ca,ql=i.useCallback(n=>{pa(n),da(n)},[pa,da]),Gl=i.useCallback(n=>{ga(n),fa(n)},[ga,fa]),[Xl,Yl]=i.useState(null),[Jl,Zl]=i.useState(null),Ql=i.useCallback(n=>{ji.current=n,rs.current=n,Yl(n),ma(n)},[ma]),ec=i.useCallback(n=>{as.current=n,Zl(n),ha(n)},[ha]),xa=i.useCallback(n=>{l&&at.getState().openContextFile(l,n)},[l]),va=nt&&G==="preview"&&!Me,wa=p.metadata.variant==="light"?"light":"dark";to({container:Xl,filePath:d?.path??null,workspaceRoot:l||null,onOpenFile:xa,enabled:va,colorScheme:wa}),to({container:Jl,filePath:d?.path??null,workspaceRoot:l||null,onOpenFile:xa,enabled:va,colorScheme:wa});const yr=tu("unified"),Ct=oe.length>So,Cr=i.useMemo(()=>Ct&&ks?kd(oe):void 0,[ks,oe,Ct]),ba=i.useCallback((n,o,c,g)=>{const v={name:n.name,contents:o,lang:Fr(n.path)||void 0},N=L=>s.jsx(Eu,{file:Ct&&Cr?{...v,cacheKey:`${n.path}:${Cr}`}:v,options:{disableFileHeader:!0,overflow:ce?"wrap":"scroll",theme:na,themeType:p.metadata.variant==="dark"?"dark":"light",onPostRender:g},className:Ct?"block w-full":"block h-full w-full",style:Ct?void 0:{height:"100%"}},L);return Ct?s.jsx("div",{className:"h-full",children:s.jsx(Ru.Provider,{value:c.virtualizer,children:s.jsx(Tu.Provider,{value:yr,children:N(`${n.path}:${yr?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:N(n.path)})},[p.metadata.variant,Ct,Cr,na,yr,ce]),ya=({exitFullscreenOnly:n=!1,layout:o="floating"}={})=>{if(!d)return null;const c=o==="docked",g=Gc(Xc("save_file")),v=c?"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",N=(L,q)=>s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:q})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:L})]});return s.jsxs("div",{className:v,children:[tt&&Fl&&s.jsxs(s.Fragment,{children:[Xt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(V,{name:"loader-4",className:"size-3.5 animate-spin"}),t("filesView.editor.saving")]}):Ve&&Ko==="saved"&&!Ke?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(V,{name:"check",className:"size-3.5"}),t("filesView.editor.saved")]}):Ke?N(t(Ve?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:g}),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>{wt()},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:t(Ve?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:g}),"aria-label":t("filesView.editor.saveAria",{shortcut:g}),children:s.jsx(V,{name:"save-3",className:"size-4"})})):null,N(t(Ve?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Go(!Ve),className:Y("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Ve?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:t(Ve?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":t(Ve?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Ve?s.jsx(V,{name:"file-check-fill",className:"size-4"}):s.jsx(V,{name:"file-check",className:"size-4"})}))]}),s.jsxs(Ir,{onOpenChange:Xe,children:[s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Or,{asChild:!0,children:s.jsx(W,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.openInDesktopApp"),"aria-label":t("filesView.editor.openInDesktopApp"),children:s.jsx(V,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:t("filesView.editor.openInDesktopApp")})]}),s.jsxs(Br,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[il.map(L=>s.jsxs(zs,{className:"flex items-center gap-2",onClick:()=>{cl(L)},children:[s.jsx(Cf,{label:L.label,iconDataUrl:L.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:L.label})]},L.id)),al?s.jsxs(zs,{className:"flex items-center gap-2",onClick:()=>{ol(!0)},children:[s.jsx(V,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("filesView.editor.refreshApps")})]}):null]})]}),!Hi&&s.jsxs(s.Fragment,{children:[N(t(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>_(!ce),className:Y("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ce?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:t(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(V,{name:"text-wrap",className:"size-4"})})),Z==="edit"&&s.jsxs(s.Fragment,{children:[N(t("filesView.editor.findInFile"),s.jsx(W,{variant:"ghost",size:"sm",onClick:L=>{ze(!Le),L.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.findInFile"),children:s.jsx(V,{name:"search",className:"size-4"})})),N(t("filesView.editor.goToLine"),s.jsx(W,{variant:"ghost",size:"sm",onClick:L=>{rr(q=>!q),L.currentTarget.blur()},"data-go-to-line-toggle":!0,className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.goToLine"),children:s.jsx(V,{name:"menu-fold-2",className:"size-4"})})),!u&&N(t("filesView.editor.symbols"),s.jsx(W,{variant:"ghost",size:"sm",onClick:L=>{ns(q=>!q),L.currentTarget.blur()},"data-document-symbols-toggle":!0,className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent","aria-label":t("filesView.editor.symbols"),children:s.jsx(V,{name:"list-unordered",className:"size-4"})})),s.jsx(ed,{open:rl,onOpenChange:rr,view:Pe.current,variant:"inline"})]})]}),ws&&tt&&!an&&!on&&!et&&!ln&&!cn&&s.jsx(mn,{currentMode:Z==="view"?"preview":"edit",onToggle:()=>{El(Z==="view"?"edit":"view")}}),nt&&N(t(qe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>kl(qe()==="preview"?"edit":"preview"),className:Y("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",qe()==="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:t(qe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":t(qe()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(V,{name:qe()==="preview"?"eye":"eye-off",className:"size-4"})})),Ds(d?.path??"")&&s.jsx(mn,{currentMode:Yi(),onToggle:()=>{Pl(Yi()==="preview"?"edit":"preview")}}),et&&s.jsx(mn,{currentMode:Ye,onToggle:()=>Rl(Ye==="preview"?"edit":"preview")}),ln&&s.jsx(mn,{currentMode:we,onToggle:()=>Tl(we==="preview"?"edit":"preview")}),cn&&N(t(ie==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Ml(ie==="table"?"text":"table"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:t(ie==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),"aria-label":t(ie==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),children:ie==="table"?s.jsx(V,{name:"code-sslash",className:"size-4"}):s.jsx(V,{name:"table-2",className:"size-4"})})),nt&&qe()==="preview"&&N(t("filesView.editor.findInFile"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>{ss(!0),pi(L=>L+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.findInFile"),children:s.jsx(V,{name:"search",className:"size-4"})})),nt&&qe()==="preview"&&ul&&s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx(W,{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":t(es?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{es?Bo():H.trim()&&Oo(H)},children:es?s.jsx(V,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(V,{name:"volume-up",className:"size-4"})})}),s.jsx(Kt,{sideOffset:8,children:t(es?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),un&&s.jsxs(s.Fragment,{children:[!Pn&&s.jsx(mn,{currentMode:Ce,onToggle:()=>Al(Ce==="preview"?"edit":"preview")}),Ce==="preview"&&s.jsx(W,{variant:"ghost",size:"sm",onClick:async()=>{await wt()&&(ii(!0),setTimeout(()=>ii(!1),1500))},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.fileEditor.save"),children:qo?s.jsx(V,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(V,{name:"save-3",className:"size-4"})})]}),Dn&&s.jsxs(s.Fragment,{children:[s.jsx(mn,{currentMode:le,onToggle:()=>Dl(le==="preview"?"edit":"preview")}),le==="preview"&&s.jsx(W,{variant:"ghost",size:"sm",onClick:async()=>{const L=si.current?.getXml();if(We.current&&(clearTimeout(We.current),We.current=null),d?.path&&L){if(!await gr(d.path,L))return;ts(!0),setTimeout(()=>ts(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.diagram.saveDiagram"),children:Ho?s.jsx(V,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(V,{name:"save-3",className:"size-4"})})]}),an&&N(t(re==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Vl(re==="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:t(re==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:re==="tree"?s.jsx(V,{name:"code-sslash",className:"size-4"}):s.jsx(V,{name:"node-tree",className:"size-4"})})),Cl&&N(t("filesView.editor.copyFileContents"),s.jsx(W,{variant:"ghost",size:"sm",onClick:async()=>{(await Os(H)).ok?(ui(!0),kn.current!==null&&window.clearTimeout(kn.current),kn.current=window.setTimeout(()=>{ui(!1)},1200)):J.error(t("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.copyFileContents"),"aria-label":t("filesView.editor.copyFileContents"),children:nl?s.jsx(V,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(V,{name:"clipboard",className:"size-4"})})),jl&&N(t("filesView.editor.copyFilePathTitle",{path:bt}),s.jsx(W,{variant:"ghost",size:"sm",onClick:async()=>{(await Os(bt)).ok?(di(!0),Rn.current!==null&&window.clearTimeout(Rn.current),Rn.current=window.setTimeout(()=>{di(!1)},1200)):J.error(t("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.copyFilePathTitle",{path:bt}),"aria-label":t("filesView.editor.copyFilePathTitle",{path:bt}),children:sl?s.jsx(V,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(V,{name:"file-copy-2",className:"size-4"})})),a.downloadFile&&N(t("filesView.editor.saveFile"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>{const L=a.downloadFile;L&&L(d.path).catch(q=>{console.error("Download failed:",q),J.error(t("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.saveFile"),"aria-label":t("filesView.editor.saveFile"),children:s.jsx(V,{name:"download",className:"size-4"})})),n?N(t("filesView.editor.exitFullscreen"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Ae(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t("filesView.editor.exitFullscreen"),"aria-label":t("filesView.editor.exitFullscreen"),children:s.jsx(V,{name:"fullscreen-exit",className:"size-4"})})):!u&&r==="full"&&N(t(ee?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Ae(!ee),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t(ee?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":t(ee?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:ee?s.jsx(V,{name:"fullscreen-exit",className:"size-4"}):s.jsx(V,{name:"fullscreen",className:"size-4"})}))]})},Ca=i.useRef(null);i.useEffect(()=>{de&&(jn.current&&Ca.current===de&&Un(n=>n+1),Ca.current=de)},[de]);const tc=i.useCallback(async()=>{const n=xt.current;if(!n)throw new Error("No file is open.");const o=ut(n),c=await Ls("/api/fs/raw",{signal:AbortSignal.timeout(6e4),cache:"no-store",query:{path:n,allowOutsideWorkspace:o.allowOutsideWorkspace?"true":void 0,directory:l||void 0}});if(!c.ok)throw new Error(t("filesView.error.readFileFailed"));return new Uint8Array(await c.arrayBuffer())},[ut,l,t]),ja=i.useCallback(n=>{const o=xt.current;o&&(wn.current[o]="edit"),ft(!1),ue("edit"),J.error(n)},[]),Sa=r==="full"&&ee,nc=d?`${d.path}:${Ao}:${Sa?"fullscreen":"docked"}`:"",Na=br&&d&&De?s.jsx("div",{ref:oi,className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(Vd,{ref:Yt,guestId:De.guestId,editorId:De.editor.id,title:De.editor.title,contentKind:Pn?"binary":"text",path:bt||d.path,content:oe,loadBytes:tc,readOnly:!d||Yn||!a.writeFile||Pn&&!a.uploadFile,onDirtyChange:ft,onEdit:()=>{li.current=Date.now()},onSaveRequest:Ii,onUnsupported:Il,onTooLarge:()=>ja(t("filesView.fileEditor.tooLarge",{editor:De.editor.title})),onLoadFailed:()=>ja(t("filesView.error.readFileFailed"))},`${nc}:${De.guestId}:${De.editor.id}`)}):null,sc=i.useCallback(()=>{const n=at.getState();n.requestSettingsJump("integrations","integrations.extensions.excalidraw"),n.setSettingsDialogOpen(!0)},[]),jr=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(uo,{open:er,onOpenChange:n=>{n||Nn(!0)},children:s.jsxs(fo,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(mo,{children:[s.jsx(ho,{children:t("filesView.unsaved.title")}),s.jsx(po,{children:t("filesView.unsaved.description")})]}),s.jsxs(go,{children:[s.jsx(W,{variant:"outline",onClick:()=>{xl()},disabled:Xt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:t("filesView.unsaved.saveChanges")}),s.jsx(W,{variant:"destructive",onClick:gl,children:t("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:Y("flex flex-col flex-shrink-0",F&&"border-b border-border/40"),children:[F?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[u&&fe&&s.jsx("button",{type:"button",onClick:()=>se(!1),"aria-label":t("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-ring",children:s.jsx(V,{name:"arrow-left-s",className:"size-5"})}),u?d?s.jsxs(Ir,{children:[s.jsx(Or,{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":t("filesView.editor.openFilesAria"),children:[s.jsx(On,{filePath:d.path,extension:d.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(so,{name:d.name}),s.jsx(V,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Br,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Gt.map(n=>{const o=d?.path===n.path;return s.jsxs(zs,{onSelect:c=>{if(c.target.closest("[data-close-open-file]")){c.preventDefault();return}o||$e(n)},className:Y("flex min-w-0 items-center justify-between gap-2 overflow-hidden",o&&"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(On,{filePath:n.path,extension:n.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(so,{name:n.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:c=>{c.preventDefault(),c.stopPropagation()},onClick:c=>{c.preventDefault(),c.stopPropagation(),_i(n.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":t("filesView.editor.closeFileAria",{name:n.name}),children:s.jsx(V,{name:"close",className:"size-3.5"})})]},n.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:t("filesView.editor.selectFile")}):Gt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Jr.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"}),Jr.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:Gs,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Gt.map(n=>{const o=d?.path===n.path;return s.jsxs("div",{title:Is(l,n.path),className:Y("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",o?"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(On,{filePath:n.path,extension:n.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{o||$e(n)},className:"max-w-[12rem] truncate text-left",children:n.name}),s.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),_i(n.path)},className:Y("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!o&&!T&&"opacity-0 group-hover:opacity-100"),"aria-label":t("filesView.editor.closeFileAria",{name:n.name}),children:s.jsx(V,{name:"close",className:"size-3.5"})})]},n.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:t("filesView.editor.selectFile")})]}):null,d?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:[bt&&!u?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:bt,children:bt}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:ya({layout:"docked"})})]}):null]}),Nl?s.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2 border-b border-border/40 bg-[var(--surface-muted)] px-3 py-1.5 typography-ui text-muted-foreground",children:[s.jsx(V,{name:"information",className:"size-4 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:t("filesView.excalidraw.installHint")}),s.jsx(W,{type:"button",size:"xs",variant:"outline",onClick:sc,children:t("filesView.excalidraw.installAction")})]}):null,s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Rr,{ref:ql,outerClassName:"h-full min-w-0",className:Y("h-full min-w-0",Ct&&"[overflow-anchor:none]"),children:d?Me||wr?P?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(V,{name:"loader-4",className:"size-4 animate-spin"}),t("filesView.state.loading")]}):rt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:rt}):br?Sa?s.jsx("div",{className:"h-full"}):Na:Fs||(d&&Dn&&le==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(Td,{ref:si,xml:zl,onChange:Ll},`${d.path}:${Po}`)}):d&&an&&re==="tree"?s.jsx(Rs,{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:t("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:t("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Fu,{jsonString:H,maxHeight:"100%",initiallyExpandedDepth:2})})}):d&&nt&&qe()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:is,ref:Ql,children:[s.jsx(_a,{containerRef:ji,filePath:d.path,fileContent:H}),H.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:t("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(H.length/1024)})}),s.jsx(Rs,{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:t("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:t("filesView.error.switchToEditMode")})]}),children:s.jsx(Tr,{content:H,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1,allowRawHtml:!0})})]}),!ee&&s.jsx(Ka,{containerRef:rs,open:mi,onOpenChange:ss,focusNonce:hi})]}):d&&on&&xe==="preview"?Bl?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:t("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!h.isVSCode&&ia===js?(()=>{const n=d.path.split("/").map(o=>encodeURIComponent(o)).join("/");return Ta().authenticatedAsset(`/api/fs/serve${n.startsWith("/")?n:`/${n}`}`)})():void 0,srcDoc:h.isVSCode?(()=>{const n=d.path.substring(0,d.path.lastIndexOf("/")+1);return n?H.replace(/<head([^>]*)>/i,`<head$1><base href="${n}">`):H})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:t("filesView.editor.htmlPreviewTitle")},Ol)}):d&&ws&&Z==="view"?ba(d,oe,la,Kl):s.jsxs("div",{className:Y("relative h-full",rn&&"overflow-hidden"),ref:Tn,children:[!ee&&s.jsx(Ua,{open:fi,onOpenChange:ns,view:Pe.current}),s.jsx("div",{className:Y("h-full",rn&&"invisible"),children:s.jsx(ao,{positionKey:kt,value:oe,onChange:Se,readOnly:!tt,vimMode:ls==="vim",extensions:ta,className:"h-full",blockWidgets:Ul,onViewReady:n=>{Pe.current=n,Cs(n),tr(o=>o+1),window.requestAnimationFrame(()=>{dn(n)})},onViewDestroy:()=>{Pe.current&&(Pe.current=null),tr(n=>n+1)},enableSearch:!0,searchOpen:Le,onSearchOpenChange:ze,highlightLines:te?{start:Math.min(te.start,te.end),end:Math.max(te.start,te.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(n,o,c)=>{if(!(c instanceof MouseEvent)||c.button!==0)return!1;c.preventDefault();const g=n.state.doc.lineAt(o.from).number;if(te&&!c.shiftKey&&Math.min(te.start,te.end)===g&&Math.max(te.start,te.end)===g)return it(null),Vn(),tn.current=!1,Mt.current=null,nn(!1),!0;if(u&&te&&!c.shiftKey){const v=Math.min(te.start,te.end,g),N=Math.max(te.start,te.end,g);return it({start:v,end:N}),tn.current=!1,Mt.current=null,nn(!1),!0}if(tn.current=!0,Mt.current=g,nn(!0),te&&c.shiftKey){const v=Math.min(te.start,g),N=Math.max(te.end,g);it({start:v,end:N})}else it({start:g,end:g});return!0},mouseover:(n,o,c)=>{if(!(c instanceof MouseEvent)||c.buttons!==1||!tn.current||Mt.current===null)return!1;const g=n.state.doc.lineAt(o.from).number,v=Math.min(Mt.current,g),N=Math.max(Mt.current,g);return it({start:v,end:N}),nn(!0),!1},mouseup:()=>(tn.current=!1,Mt.current=null,nn(!1),!1)}}},kt)}),rn&&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(V,{name:"loader-4",className:"size-4 animate-spin"}),t("filesView.state.openingFileAtChange")]})})]})):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:t("filesView.editor.pickFileFromTree")})})})]}),rc=!!(l&&ei[l]),Fa=l?Jn[l]:null,Ea=M?s.jsxs("section",{className:Y("flex min-h-0 flex-col overflow-hidden",u?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:Y("flex flex-col gap-2 py-2",u?"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(V,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(_n,{ref:Q,value:B,onChange:n=>U(n.target.value),placeholder:t("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),B.trim().length>0&&s.jsx("button",{type:"button","aria-label":t("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:()=>{U(""),Q.current?.focus()},children:s.jsx(V,{name:"close",className:"size-4"})})]}),s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>ir("createFile",{path:y,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:t("filesView.tree.actions.newFileTitle"),"aria-label":t("filesView.tree.actions.newFileTitle"),children:s.jsx(V,{name:"file-add",className:"size-4"})})})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.newFileTitle")})]}),s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>ir("createFolder",{path:y,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:t("filesView.tree.actions.newFolderTitle"),"aria-label":t("filesView.tree.actions.newFolderTitle"),children:s.jsx(V,{name:"folder-add",className:"size-4"})})})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.newFolderTitle")})]}),Pi&&s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>Di(l),disabled:!l||fs,className:"size-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.uploadFilesTitle"),"aria-label":t("sidebarFilesTree.actions.uploadFilesTitle"),children:s.jsx(V,{name:fs?"loader-4":"upload-2",className:Y("size-4",fs&&"animate-spin")})})})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.uploadFilesTitle")})]}),s.jsx(Su,{className:"size-8"}),s.jsxs(Wt,{children:[s.jsx(Ut,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(W,{variant:"ghost",size:"sm",onClick:()=>{ds()},className:"size-8 p-0 flex-shrink-0",title:t("filesView.tree.actions.refreshTitle"),"aria-label":t("filesView.tree.actions.refreshTitle"),children:s.jsx(V,{name:"refresh",className:"size-4"})})})}),s.jsx(Kt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(Rr,{outerClassName:"flex-1 min-h-0",className:Y("py-2",u?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Io?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),t("filesView.tree.search.searching")]}):ti.length>0?ti.map(n=>{const o=d?.path===n.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{$e(n)},className:Y("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Vo(n.path,n.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:n.path,children:n.relativePath??n.path})]})},n.path)}):Fa?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:Fa}),s.jsxs(W,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ds()},children:[s.jsx(V,{name:"refresh",className:"size-3.5"}),t("filesView.tree.actions.refreshTitle")]})]}):rc?Wi(l,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("filesView.state.loading")})})})]}):null,ic=r==="full"&&ee&&d&&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:ya({exitFullscreenOnly:!0})}),s.jsx(Rr,{ref:Gl,outerClassName:"h-full min-w-0",className:Y("h-full min-w-0",Ct&&"[overflow-anchor:none]"),children:Me||wr?P?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(V,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):rt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:rt}):br?Na:Fs||(nt&&qe()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:is,ref:ec,children:[d?s.jsx(_a,{containerRef:as,filePath:d.path,fileContent:H}):null,H.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:t("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(H.length/1024)})}),s.jsx(Rs,{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:t("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:t("filesView.error.switchToEditMode")})]}),children:s.jsx(Tr,{content:H,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1,allowRawHtml:!0})})]}),s.jsx(Ka,{containerRef:as,open:mi,onOpenChange:ss,focusNonce:hi,className:"right-4 top-16"})]}):ws&&Z==="view"?ba(d,oe,ca,Hl):s.jsxs("div",{className:Y("relative h-full",rn&&"overflow-hidden"),children:[s.jsx(Ua,{open:fi,onOpenChange:ns,view:Pe.current}),s.jsx("div",{className:Y("h-full",rn&&"invisible"),children:s.jsx(ao,{positionKey:`${kt}:fullscreen`,value:oe,onChange:Se,readOnly:!tt,vimMode:ls==="vim",extensions:ta,className:"h-full",onViewReady:n=>{Pe.current=n,Cs(n),window.requestAnimationFrame(()=>{dn(n)})},onViewDestroy:()=>{Pe.current&&(Pe.current=null)}},`${kt}:fullscreen`)}),rn&&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(V,{name:"loader-4",className:"size-4 animate-spin"}),t("filesView.state.openingFileAtChange")]})})]}))})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Vf,{activeDialog:Ot,dialogData:Bt,dialogInputValue:Tt,onDialogInputChange:ci,isDialogSubmitting:Jo,onDialogSubmit:pl,onClose:Wl,inputRef:Wo}),hl,ic,u?fe?jr:Ea:r==="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:jr})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[S>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Ea}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:jr})]})]})};function Df(r){return r+1}export{ap as FilesView};
|