@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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This bypasses mobile Safari's audio context restrictions.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { readOpenCodeCredentials } from '../opencode/auth.js';
|
|
9
9
|
import { loadOpenAI } from './openai-sdk.js';
|
|
10
10
|
import { normalizeCustomOpenAIBaseURL } from './base-url.js';
|
|
11
11
|
|
|
@@ -15,16 +15,16 @@ export const TTS_VOICES = [
|
|
|
15
15
|
'nova', 'onyx', 'sage', 'shimmer', 'verse', 'marin', 'cedar'
|
|
16
16
|
];
|
|
17
17
|
|
|
18
|
-
function getOpenAIApiKey() {
|
|
18
|
+
async function getOpenAIApiKey() {
|
|
19
19
|
// First check environment variable
|
|
20
20
|
const envKey = process.env.OPENAI_API_KEY;
|
|
21
21
|
if (envKey) {
|
|
22
22
|
return envKey;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// Then
|
|
25
|
+
// Then the OpenAI credential stored in OpenCode (same as usage tracker)
|
|
26
26
|
try {
|
|
27
|
-
const auth =
|
|
27
|
+
const auth = await readOpenCodeCredentials();
|
|
28
28
|
// Check for openai, codex, or chatgpt aliases
|
|
29
29
|
const openaiAuth = auth.openai || auth.codex || auth.chatgpt;
|
|
30
30
|
if (openaiAuth) {
|
|
@@ -41,7 +41,7 @@ function getOpenAIApiKey() {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
} catch (error) {
|
|
44
|
-
console.warn('[TTSService] Failed to read
|
|
44
|
+
console.warn('[TTSService] Failed to read OpenCode credentials:', error.message);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return null;
|
|
@@ -54,7 +54,7 @@ class TTSService {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async _getClient() {
|
|
57
|
-
const apiKey = getOpenAIApiKey();
|
|
57
|
+
const apiKey = await getOpenAIApiKey();
|
|
58
58
|
|
|
59
59
|
// If API key changed or client doesn't exist, create new client
|
|
60
60
|
if (apiKey && (!this._client || this._lastApiKey !== apiKey)) {
|
|
@@ -66,8 +66,8 @@ class TTSService {
|
|
|
66
66
|
return this._client;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
isAvailable() {
|
|
70
|
-
return Boolean(getOpenAIApiKey());
|
|
69
|
+
async isAvailable() {
|
|
70
|
+
return Boolean(await getOpenAIApiKey());
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import{f as De,R as i,j as s,c as Ts,r as Ct}from"./vendor-react-BUCujlKS.js";import{b7 as Dl,a as ot,h as Ms,_ as Ll,$ as zl,a0 as Al,a1 as Il,y as tt,u as ht,ew as Ol,K as fa,D as Bl,a5 as ma,et as $l,e as _l,eu as Wl,a4 as Ul,ev as Hl}from"./index-CgR5rJq_.js";import{f as nt,bt as _a,z as ha,as as Wa,cp as Kl,I as M,h as q,ls as ql,gN as Gl,a1 as In,B as $,km as Er,c8 as Vr,iD as Xl,lt as Yl,lu as Jl,aK as zn,hB as Zl,hz as Ql,a4 as ec,T as tc,K as nc,au as sc,cK as rc,t as X,eF as pa,jh as ic,h1 as ac,l as ga,aI as vr,cD as Dn,dl as oc,b as lc,lv as Ln,cb as cc,aJ as xr,lw as wr,cE as va,cF as xa,lx as wa,ly as ba,lz as uc,lA as dc,lB as fc,lC as mc,ih as hc,lD as pc,lE as gc,lF as vc,cc as Ua,cd as Ha,ce as Ka,cf as qa,cg as Ga,ch as Xa,aC as kr,aD as Tr,aF as Mr,br as Vs,ci as br,aL as Ns,cz as yr,ao as $t,ap as _t,aq as Wt,c9 as xc,ca as wc,g as Ds,bs as bc,cJ as yc}from"./useAppFontEffects-Dsl_sLrj.js";import{t as jc,aL as Cc,aK as Sc,ab as Nc,ac as Fc,ad as Rc,ae as Ec,af as kc}from"./runtimeEndpointReset-uu1DBwLL.js";import{c as ya,s as Tc,P as fn,C as Mc}from"./shikiHighlight-BWGrY5YU.js";import{a as Vc}from"./vendor-codemirror-state-C9awkmn-.js";import{E as Ut}from"./vendor-codemirror-view-CiLROUVV.js";import{V as Pc,J as Dc,F as Lc}from"./JsonTreeView-B1Xq-k2t.js";import{ensurePierreThemeRegistered as ja,getResolvedShikiTheme as zc}from"./appThemeRegistry-BdEHBA4s.js";import{V as Ac,W as Ic}from"./Virtualizer-CZlLSacm.js";import{V as Oc}from"./Virtualizer-D_a8gKmg.js";import{D as Bc}from"./vendor-react-drawio-Ct3Q0DsD.js";import{m as $c,P as _c}from"./PluginPane-2C71F8uF.js";import{a as Wc,u as Fs,b as Uc,g as Hc,h as Kc}from"./scheduledTasksApi-BuzWT445.js";import{I as qc,u as Gc,n as Xc}from"./useInlineCommentController-d5vntsQ_.js";import{b as Yc}from"./CodeMirrorCommentWidgets-C_zL-eri.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-DSZl7jSi.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-DnNniUWp.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-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.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-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B1EetJur.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-C0xe_Lyy.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-ngpHPEDU.js";import"./computeVirtualFileMetrics-6V1xNpO9.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-CBAppvy1.js";import"./textMateThemeFromAppTheme-BSUFChBY.js";function Ca(r){const e=De.c(56),{containerRef:t,filePath:a,fileContent:p}=r,{t:d}=nt(),{isMobile:v}=_a(),f=ha(iu),x=ha(ru),g=Wa(),h=Kl(su),[w,F]=i.useState(null),[C,k]=i.useState(""),[y,j]=i.useState(!1),l=i.useRef(!1),S=i.useRef(null),T=i.useRef(null),[V,L]=i.useState(null);let I;e[0]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{F(null),k(""),j(!1),l.current=!1,T.current=null,L(null)},e[0]=I):I=e[0];const E=I;let z,_;e[1]!==t?(z=()=>{const G=t.current;if(!G)return;const W=()=>{if(l.current)return;const le=window.getSelection(),Se=le?.toString().trim()??"";if(!le||!Se||le.rangeCount===0){E();return}const re=le.getRangeAt(0);if(!G.contains(re.commonAncestorContainer)){E();return}const fe=re.getBoundingClientRect();T.current=re.cloneRange(),k(Se),F({x:fe.left+fe.width/2,y:fe.top-10})},oe=le=>{S.current?.contains(le.target)||l.current&&E()};return document.addEventListener("selectionchange",W),document.addEventListener("pointerdown",oe),()=>{document.removeEventListener("selectionchange",W),document.removeEventListener("pointerdown",oe)}},_=[t,E],e[1]=t,e[2]=z,e[3]=_):(z=e[2],_=e[3]),i.useEffect(z,_);let R;e[4]!==p?(R=G=>{const W=ge=>p.slice(0,ge).split(`
|
|
2
|
-
`).length,oe=tu,le=(ge,pt)=>{for(const ye of oe(ge)){const Ee=p.indexOf(ye,pt);if(Ee>=0)return Ee}return-1},Se=G.length>=8?p.indexOf(G):-1;if(Se>=0){const ge=W(Se);return{start:ge,end:ge+G.split(`
|
|
3
|
-
`).length-1}}const re=G.split(`
|
|
4
|
-
`).map(eu).filter(Boolean);if(re.length===0)return null;const fe=le(re[0],0);if(fe<0)return null;const pe=W(fe);if(re.length===1)return{start:pe,end:pe};const be=le(re[re.length-1],fe);return be<0?null:{start:pe,end:Math.max(pe,W(be))}},e[4]=p,e[5]=R):R=e[5];const P=R;let O;e[6]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{const G=T.current;if(!G){L(null);return}L(ql(G))},e[6]=O):O=e[6];const K=O;let Q,ee;e[7]!==y?(Q=()=>{if(!y)return;let G=null;const W=()=>{G===null&&(G=window.requestAnimationFrame(()=>{G=null,K()}))};return document.addEventListener("scroll",W,{capture:!0,passive:!0}),window.addEventListener("resize",W),()=>{G!==null&&window.cancelAnimationFrame(G),document.removeEventListener("scroll",W,{capture:!0}),window.removeEventListener("resize",W)}},ee=[y,K],e[7]=y,e[8]=Q,e[9]=ee):(Q=e[8],ee=e[9]),i.useEffect(Q,ee);let ae;e[10]!==C?(ae=()=>{C&&(j(!0),l.current=!0,K(),window.getSelection()?.removeAllRanges())},e[10]=C,e[11]=ae):ae=e[11];const J=ae;let Y;e[12]!==h||e[13]!==f||e[14]!==g||e[15]!==a||e[16]!==x||e[17]!==P||e[18]!==C?(Y=G=>{const W=f??(x?"draft":null);if(!C||!W||!g){E();return}const oe=P(C);h({directory:g,sessionKey:W},{source:"file-quote",fileLabel:a,startLine:oe?.start??0,endLine:oe?.end??0,code:C,language:"",text:G.trim()}),E(),queueMicrotask(Qc)},e[12]=h,e[13]=f,e[14]=g,e[15]=a,e[16]=x,e[17]=P,e[18]=C,e[19]=Y):Y=e[19];const se=Y;if(!w)return null;let Le;e[20]!==y||e[21]!==P||e[22]!==C?(Le=y?P(C):null,e[20]=y,e[21]=P,e[22]=C,e[23]=Le):Le=e[23];const A=Le;let ue;e[24]!==y||e[25]!==V?(ue=y&&V&&V.length>0?s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:V.map(Zc)}):null,e[24]=y,e[25]=V,e[26]=ue):ue=e[26];const xe=ue;let ze;e[27]!==A?(ze=A?{start:A.start,end:A.end}:void 0,e[27]=A,e[28]=ze):ze=e[28];let Fe;e[29]!==a||e[30]!==se||e[31]!==ze?(Fe=s.jsx(qc,{fileLabel:a,lineRange:ze,onSave:se,onCancel:E}),e[29]=a,e[30]=se,e[31]=ze,e[32]=Fe):Fe=e[32];const $e=Fe;if(v){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 W;e[34]!==$e||e[35]!==y||e[36]!==J||e[37]!==d?(W=s.jsx("div",{ref:S,className:"pointer-events-auto mx-auto max-w-[420px] px-3",style:G,children:y?$e:s.jsx("div",{className:q("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:Jc,onClick:J,className:q("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:d("chat.textSelection.title.commentOnSelection"),children:[s.jsx(M,{name:"chat-1",className:"size-4 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 whitespace-nowrap",children:d("chat.textSelection.actions.comment")})]})})}),e[34]=$e,e[35]=y,e[36]=J,e[37]=d,e[38]=W):W=e[38];let oe;return e[39]!==xe||e[40]!==W?(oe=Ts.createPortal(s.jsxs("div",{className:"oc-keyboard-inset-surface pointer-events-none fixed inset-x-0 bottom-0 z-50",children:[xe,W]}),document.body),e[39]=xe,e[40]=W,e[41]=oe):oe=e[41],oe}let Re;e[42]!==w.x||e[43]!==w.y?(Re={left:w.x,top:w.y,transform:"translate(-50%, -100%)"},e[42]=w.x,e[43]=w.y,e[44]=Re):Re=e[44];let ne;e[45]!==xe?(ne=xe?Ts.createPortal(xe,document.body):null,e[45]=xe,e[46]=ne):ne=e[46];let de;e[47]!==$e||e[48]!==y||e[49]!==J||e[50]!==d?(de=y?s.jsx("div",{className:"w-[min(420px,80vw)]",children:$e}):s.jsx("div",{className:q("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:J,className:q("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-foreground","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:d("chat.textSelection.title.commentOnSelection"),children:d("chat.textSelection.actions.comment")})}),e[47]=$e,e[48]=y,e[49]=J,e[50]=d,e[51]=de):de=e[51];let _e;return e[52]!==Re||e[53]!==ne||e[54]!==de?(_e=Ts.createPortal(s.jsxs("div",{ref:S,className:"fixed z-50",style:Re,children:[ne,de]}),document.body),e[52]=Re,e[53]=ne,e[54]=de,e[55]=_e):_e=e[55],_e}function Jc(r){return r.preventDefault()}function Zc(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 Qc(){Gl()}function eu(r){return r.trim()}function tu(r){const e=r.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(nu)}function nu(r){return r.length>=8}function su(r){return r.addDraft}function ru(r){return r.newSessionDraft?.open}function iu(r){return r.currentSessionId}const au=(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)},Sa=(r,e)=>{const t=r.state.doc.lineAt(e.main.head);return{lineNumber:t.number,character:e.main.head-t.from+1,selection:e}},Na=(r,e,t)=>{const a=r.state.doc.line(e),p=Math.max(1,Math.min(t,a.length+1)),d=a.from+p-1;r.dispatch({selection:Vc.cursor(d),effects:Ut.scrollIntoView(d,{y:"center"})})};function ou({open:r,onOpenChange:e,view:t,variant:a="overlay"}){const{t:p}=nt(),[d,v]=i.useState(""),f=i.useRef(null),x=i.useRef(!1),g=i.useRef(null),h=i.useRef(null),w=i.useMemo(()=>au(d,t),[d,t]);i.useEffect(()=>{!r||!t||(x.current=!1,f.current=Sa(t,t.state.selection),v(""))},[r,t]),i.useEffect(()=>{r&&window.requestAnimationFrame(()=>{h.current?.focus(),h.current?.select()})},[r]),i.useEffect(()=>{if(!(!r||!t||!f.current)){if(w===null){const{selection:j}=f.current;t.dispatch({selection:j,effects:Ut.scrollIntoView(j.main.from,{y:"center"})});return}Na(t,w,f.current.character)}},[w,r,t]);const F=i.useCallback(()=>{if(!t||x.current||!f.current)return;const{selection:j}=f.current;t.dispatch({selection:j,effects:Ut.scrollIntoView(j.main.from,{y:"center"})})},[t]),C=i.useCallback(j=>{j||F(),e(j)},[e,F]),k=i.useCallback(()=>{!t||w===null||!f.current||(x.current=!0,Na(t,w,f.current.character),e(!1),t.focus())},[w,e,t]);i.useEffect(()=>{if(!r)return;const j=S=>{const T=g.current,V=S.target;!T||!(V instanceof Node)||T.contains(V)||C(!1)},l=S=>{S.key==="Escape"&&(S.preventDefault(),C(!1))};return document.addEventListener("pointerdown",j,!0),document.addEventListener("keydown",l,!0),()=>{document.removeEventListener("pointerdown",j,!0),document.removeEventListener("keydown",l,!0)}},[C,r,a]);const y=i.useMemo(()=>{if(!t)return p("goToLineDialog.helper.editorUnavailable");if(w===null){const j=f.current??Sa(t,t.state.selection);return p("goToLineDialog.helper.currentLineRange",{current:j.lineNumber,max:t.state.doc.lines})}return p("goToLineDialog.helper.goToLine",{line:w})},[w,p,t]);return a==="inline"?r?s.jsxs("div",{ref:g,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(In,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:d,onChange:j=>v(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),k())},placeholder:p("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx($,{variant:"outline",size:"xs",onClick:k,disabled:!t||w===null,className:"h-6 px-2",children:p("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:g,className:q("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(In,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:d,onChange:j=>v(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),k())},placeholder:p("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:y})]})})}const lu=(r,e)=>{const t=e.trim().toLowerCase(),a=[];if(!t)return a;const p=r.toLowerCase();let d=0;for(;;){const v=p.indexOf(t,d);if(v===-1)break;a.push({start:v,end:v+t.length}),d=v+t.length}return a},zs="data-md-find",jr="data-md-find-current",Ya="rounded-[2px] bg-status-warning/30 text-foreground",cu="rounded-[2px] bg-status-warning/60 text-foreground",uu=120,du=r=>r instanceof Element&&r.hasAttribute(zs),fu=r=>r.target instanceof Element&&r.target.hasAttribute(zs)?!0:[...r.addedNodes].some(e=>du(e)),Ja=r=>{const e=new Set;r.querySelectorAll(`mark[${zs}]`).forEach(t=>{const a=t.parentNode;a&&(a.replaceChild(document.createTextNode(t.textContent??""),t),e.add(a))}),e.forEach(t=>t.normalize())},mu=(r,e)=>{Ja(r);const t=e.trim().toLowerCase();if(!t)return[];const a=[],p=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,{acceptNode(v){const f=v.parentElement;return!f||f.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),d=[];for(;p.nextNode();){const v=p.currentNode;v instanceof Text&&d.push(v)}for(const v of d){const f=v.nodeValue??"";if(!f)continue;const x=lu(f,t);if(x.length===0)continue;const g=v.parentNode;if(!g)continue;const h=document.createDocumentFragment();let w=0;for(const F of x){F.start>w&&h.appendChild(document.createTextNode(f.slice(w,F.start)));const C=document.createElement("mark");C.setAttribute(zs,""),C.className=Ya,C.textContent=f.slice(F.start,F.end),h.appendChild(C),a.push(C),w=F.end}w<f.length&&h.appendChild(document.createTextNode(f.slice(w))),g.replaceChild(h,v)}return a},Fa=({containerRef:r,open:e,onOpenChange:t,focusNonce:a,className:p})=>{const{t:d}=nt(),[v,f]=i.useState(""),[x,g]=i.useState(0),[h,w]=i.useState(0),F=i.useRef(null),C=i.useRef([]),k=i.useRef(v);k.current=v;const y=i.useRef(null),j=i.useRef(null),l=i.useCallback((E,z=!1)=>{const _=r.current;if(!_){C.current=[],g(0),w(0);return}C.current=mu(_,E);const R=C.current.length;g(R),w(P=>!z||R===0?0:Math.min(P,R-1))},[r]),S=i.useCallback((E,z=!1)=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{y.current=null,l(E,z)},uu)},[l]);i.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]);const T=i.useCallback(()=>{t(!1);const E=j.current;j.current=null,E?.isConnected&&E.focus()},[t]);i.useEffect(()=>{const E=r.current;if(!e||!E)return;const z=new MutationObserver(_=>{!k.current.trim()||!_.some(P=>!fu(P))||S(k.current,!0)});return z.observe(E,{childList:!0,subtree:!0,characterData:!0}),()=>{z.disconnect(),Ja(E)}},[r,e,S]),i.useEffect(()=>{if(!e)return;const E=document.activeElement;E instanceof HTMLElement&&!j.current&&(j.current=E),F.current?.focus()},[e]),i.useEffect(()=>{e&&a>0&&(F.current?.focus(),F.current?.select())},[e,a]),i.useEffect(()=>{const E=r.current;if(!E||(E.querySelectorAll(`mark[${jr}]`).forEach(_=>{_.removeAttribute(jr),_.className=Ya}),x===0))return;const z=C.current[Math.min(Math.max(h,0),x-1)];z&&(z.setAttribute(jr,""),z.className=cu,z.scrollIntoView({block:"nearest"}))},[r,h,x]);const V=i.useCallback(()=>{w(E=>x===0?0:(E+1)%x)},[x]),L=i.useCallback(()=>{w(E=>x===0?0:(E-1+x)%x)},[x]),I=i.useCallback(E=>{E.key==="Enter"?(E.preventDefault(),E.shiftKey?L():V()):E.key==="Escape"&&(E.preventDefault(),T())},[T,V,L]);return e?s.jsxs("div",{className:q("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",p),children:[s.jsx(M,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),s.jsx(In,{ref:F,value:v,onChange:E=>{f(E.target.value),S(E.target.value)},onKeyDown:I,placeholder:d("filesView.preview.find.placeholder"),"aria-label":d("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?d("filesView.preview.find.countAria",{current:h+1,total:x}):d("filesView.preview.find.noMatches"),children:v.trim()&&x===0?d("filesView.preview.find.noMatches"):x>0?`${h+1}/${x}`:""}),s.jsx($,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:L,title:d("filesView.preview.find.previousAria"),"aria-label":d("filesView.preview.find.previousAria"),disabled:x===0,children:s.jsx(M,{name:"arrow-up",className:"size-3.5"})}),s.jsx($,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:V,title:d("filesView.preview.find.nextAria"),"aria-label":d("filesView.preview.find.nextAria"),disabled:x===0,children:s.jsx(M,{name:"arrow-down",className:"size-3.5"})}),s.jsx($,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:T,title:d("filesView.preview.find.closeAria"),"aria-label":d("filesView.preview.find.closeAria"),children:s.jsx(M,{name:"close",className:"size-3.5"})})]}):null},hu=r=>{let e=!0;return{poll:async()=>{if(!e||r.isDirty())return!1;const t=r.getLoadedContent(),a=r.getLoadedRevision();try{const p=await r.readContent();if(!e||r.isDirty()||a!==r.getLoadedRevision())return!1;if(p===t)return!0;const d=await r.readContent();return!e||r.isDirty()||d!==p||a!==r.getLoadedRevision()?!1:(r.applyContent(p),!0)}catch{return!1}},dispose:()=>{e=!1}}},pu=1,gu=(r,e)=>e.size!==r.size||e.mtimeMs!==void 0&&r.mtimeMs!==void 0&&Math.abs(e.mtimeMs-r.mtimeMs)>=pu;function Ra(){const r=De.c(8),[e]=Ct.useState(vu),t=Ct.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 p=a;let d,v;r[2]!==e?(d=()=>()=>{t.current=!1,e.cleanUp()},v=[e],r[2]=e,r[3]=d,r[4]=v):(d=r[3],v=r[4]),Ct.useLayoutEffect(d,v);let f;return r[5]!==p||r[6]!==e?(f={virtualizer:e,setScroller:p},r[5]=p,r[6]=e,r[7]=f):f=r[7],f}function vu(){return new Oc}const mn=new Map,xu=100;function Rs(r){const[e,t]=Ct.useState(null),a=Ct.useRef(null),p=Ct.useRef(null),d=Ct.useRef(null),v=Ct.useCallback((f,x)=>{f&&x instanceof Pc&&(d.current={key:r,file:x,node:f});const g=a.current,h=p.current,w=()=>{a.current===g&&(g?.(),h?.())};x?queueMicrotask(w):w()},[r]);return Ct.useLayoutEffect(()=>{if(!e||!r)return;const f=mn.get(r)??{top:0,left:0};let x=!0;const g=()=>d.current?.key===r?d.current.file:null,h=l=>d.current?.key===r?d.current.node.shadowRoot?.querySelector(`[data-line][data-line-index="${l-1}"]`):null,w=()=>{C.disconnect(),k.disconnect()},F=()=>{if(!x)return;const l=g(),S=f.line&&l?.getLinePosition(f.line.number),T=f.line&&h(f.line.number);let V=f.top;f.line&&S&&(V=(l?.top??0)+S.top-f.line.offset),f.line&&T&&(V=e.scrollTop+T.getBoundingClientRect().top-e.getBoundingClientRect().top-f.line.offset),e.scrollTop=V,e.scrollLeft=f.left,(!f.line||T)&&Math.abs(e.scrollTop-V)<1&&Math.abs(e.scrollLeft-f.left)<1&&(x=!1,w())},C=new ResizeObserver(F),k=new MutationObserver(()=>{if(x){for(const l of e.children)C.observe(l);F()}});C.observe(e);for(const l of e.children)C.observe(l);k.observe(e,{childList:!0,subtree:!0});const y=()=>{if(x)return;const l=g(),S=l?.getNumericScrollAnchor(e.scrollTop-(l.top??0)),T=S&&h(S.lineNumber),V=T?T.getBoundingClientRect().top-e.getBoundingClientRect().top:null;if(mn.delete(r),mn.set(r,{top:e.scrollTop,left:e.scrollLeft,line:S&&V!==null&&V>=0&&V<e.clientHeight?{number:S.lineNumber,offset:V}:void 0}),mn.size>xu){const L=mn.keys().next().value;L!==void 0&&mn.delete(L)}},j=()=>{x=!1,w()};return a.current=F,p.current=y,F(),e.addEventListener("scroll",y,{passive:!0}),e.addEventListener("wheel",j,{passive:!0}),e.addEventListener("touchstart",j,{passive:!0}),e.addEventListener("pointerdown",j,{passive:!0}),e.addEventListener("keydown",j),()=>{a.current=null,p.current=null,d.current?.key===r&&(d.current=null),w(),e.removeEventListener("scroll",y),e.removeEventListener("wheel",j),e.removeEventListener("touchstart",j),e.removeEventListener("pointerdown",j),e.removeEventListener("keydown",j)}},[r,e]),{setScroller:t,restore:v}}function wu(r){return!(!r.autoSaveEnabled||!r.isDirty||!r.canWrite||r.isSaving||r.fileLoading||r.isNonEditableBinary||!r.selectedFilePath||r.loadedFilePath!==r.selectedFilePath)}function bu(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 Za=2e5,yu=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
|
-
`},Qa=r=>r.replace(/\r\n/g,`
|
|
7
|
-
`).replace(/\r/g,`
|
|
8
|
-
`),ju=r=>({content:Qa(r),lineEnding:yu(r)}),Cu=(r,e)=>{const t=Qa(r);return e===`\r
|
|
9
|
-
`?t.replace(/\n/g,`\r
|
|
10
|
-
`):t},Su=(r,e)=>e??(r.length>Za?"view":"edit"),Nu=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)}`},Fu='<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 Ea(){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 Ru=i.forwardRef(function({xml:e,readOnly:t,className:a,onChange:p},d){const v=i.useRef(e),f=i.useRef(null),x=i.useRef(!1),[g,h]=i.useState(Ea),w=i.useRef(e),F=i.useRef(e);F.current!==e&&(F.current=e,w.current=e,v.current=e);const C=i.useRef(g);C.current!==g&&(C.current=g,w.current=v.current);const k=i.useRef(null);i.useEffect(()=>{const l=()=>h(Ea());l();const S=new MutationObserver(l);return S.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>S.disconnect()},[]),i.useEffect(()=>{const l=setTimeout(()=>{k.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(l)},[]),i.useImperativeHandle(d,()=>({getXml:()=>v.current}));const y=i.useCallback(()=>{!e&&!x.current&&(x.current=!0,setTimeout(()=>{f.current?.template({})},500))},[e]),j=i.useCallback(l=>{v.current=l.xml,p?.(l.xml)},[p]);return s.jsx("div",{ref:k,className:q("h-full w-full",a),children:s.jsx(Bc,{ref:f,xml:w.current||Fu,autosave:!0,urlParameters:{ui:t?"simple":g?"dark":"kennedy",spin:!0,libraries:!t,chrome:t,nav:t,layers:t,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:y,onAutoSave:j},g?"dark":"light")})}),Cr={ok:!0,snapshot:null},Eu=r=>r.hasCanvas&&r.viewMode==="preview"&&r.previewReady&&r.mountable,ka=r=>r.slice(r.replace(/\\/g,"/").lastIndexOf("/")+1)||r,ku=i.forwardRef(function(e,t){const{guestId:a,editorId:p,title:d,contentKind:v,path:f,content:x,readOnly:g}=e,{t:h}=nt(),w=i.useRef(e);w.current=e;const F=i.useCallback(l=>$c(l,{onChange:S=>{S.edited&&w.current.onEdit(),w.current.onDirtyChange(S.dirty)},onSave:()=>w.current.onSaveRequest(),onUnsupported:()=>w.current.onUnsupported()}),[]),[C,k]=i.useState(()=>v==="text"?F({path:f,name:ka(f),readOnly:g,encoding:"text",content:x}):null),[y]=i.useState(()=>({contentKind:v,path:f,readOnly:g}));i.useEffect(()=>{if(y.contentKind!=="binary")return;let l=!1;return w.current.loadBytes().then(S=>{if(!l){if(S.byteLength>Er){w.current.onTooLarge();return}k(F({path:y.path,name:ka(y.path),readOnly:y.readOnly,encoding:"binary",bytes:S}))}},()=>{l||w.current.onLoadFailed()}),()=>{l=!0}},[y,F]),i.useImperativeHandle(t,()=>({getContent:async l=>{const S={ok:!1,message:h("filesView.fileEditor.snapshotFailed",{editor:d})};if(!C)return S;try{const T=await C.requestSnapshot(l);return"bytes"in T?v==="binary"?{ok:!0,snapshot:{bytes:T.bytes,signature:T.version}}:S:v==="text"?{ok:!0,snapshot:{content:T.content,signature:T.version}}:S}catch{return S}},markSaved:l=>{C?.markSaved(l),w.current.onDirtyChange(!1)}}),[C,v,h,d]);const j=i.useMemo(()=>C?{editorId:p,channel:C}:null,[C,p]);return j?s.jsx(_c,{mode:Dl(a),surface:"file",fileEditor:j}):s.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:h("common.loading")})}),Tu=r=>r.slice(r.replace(/\\/g,"/").lastIndexOf("/")+1),eo=(r,e)=>{const t=Tu(e);if(!t)return null;for(const a of r)if(!(!a.fileEditors?.length||!Xl(a))){for(const p of a.fileEditors)if(p.match.some(d=>Yl(t,d)))return{guestId:a.id,editor:p}}return null},Mu=r=>{const e=De.c(3),t=Vr(Vu);let a;return e[0]!==r||e[1]!==t?(a=r?eo(t,r):null,e[0]=r,e[1]=t,e[2]=a):a=e[2],a};function Vu(r){return r.guests}const On=r=>{const e=De.c(18),{items:t,actions:a,className:p}=r;let d,v,f,x;if(e[0]!==a||e[1]!==p||e[2]!==t){x=Symbol.for("react.early_return_sentinel");e:{const F=t.filter(Pu);if(F.length===0&&!a){x=null;break e}e[7]!==p?(f=q("flex min-h-7 items-center gap-2 border-b border-border/40 bg-[var(--surface-subtle)] px-3 py-1",p),e[7]=p,e[8]=f):f=e[8],d="min-w-0 flex-1 truncate typography-meta text-muted-foreground",v=F.join(" · ")}e[0]=a,e[1]=p,e[2]=t,e[3]=d,e[4]=v,e[5]=f,e[6]=x}else d=e[3],v=e[4],f=e[5],x=e[6];if(x!==Symbol.for("react.early_return_sentinel"))return x;let g;e[9]!==d||e[10]!==v?(g=s.jsx("div",{className:d,children:v}),e[9]=d,e[10]=v,e[11]=g):g=e[11];let h;e[12]!==a?(h=a?s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:a}):null,e[12]=a,e[13]=h):h=e[13];let w;return e[14]!==f||e[15]!==g||e[16]!==h?(w=s.jsxs("div",{className:f,children:[g,h]}),e[14]=f,e[15]=g,e[16]=h,e[17]=w):w=e[17],w};function Pu(r){return r.length>0}const Bn=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""},Du=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),p=e%60,d=v=>String(v).padStart(2,"0");return t>0?`${t}:${d(a)}:${d(p)}`:`${a}:${d(p)}`},to=r=>r&&r.width>0&&r.height>0?`${r.width} × ${r.height}`:"",Lu=r=>{const e=De.c(28),{name:t,path:a,sizeBytes:p,download:d}=r,{t:v}=nt();let f,x,g,h,w,F,C;if(e[0]!==t||e[1]!==a||e[2]!==p||e[3]!==v){const l=Jl(a).toUpperCase();F="flex h-full min-h-0 flex-col",C=s.jsx(On,{items:[l,Bn(p)]}),g="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",e[11]!==a?(h=s.jsx(zn,{filePath:a,className:"size-10"}),e[11]=a,e[12]=h):h=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],f="max-w-md typography-ui text-muted-foreground",x=l?v("filesView.artifact.binary.descriptionWithType",{extension:l}):v("filesView.artifact.binary.description"),e[0]=t,e[1]=a,e[2]=p,e[3]=v,e[4]=f,e[5]=x,e[6]=g,e[7]=h,e[8]=w,e[9]=F,e[10]=C}else f=e[4],x=e[5],g=e[6],h=e[7],w=e[8],F=e[9],C=e[10];let k;e[15]!==f||e[16]!==x?(k=s.jsx("div",{className:f,children:x}),e[15]=f,e[16]=x,e[17]=k):k=e[17];let y;e[18]!==d||e[19]!==g||e[20]!==h||e[21]!==w||e[22]!==k?(y=s.jsxs("div",{className:g,children:[h,w,k,d]}),e[18]=d,e[19]=g,e[20]=h,e[21]=w,e[22]=k,e[23]=y):y=e[23];let j;return e[24]!==F||e[25]!==C||e[26]!==y?(j=s.jsxs("div",{className:F,children:[C,y]}),e[24]=F,e[25]=C,e[26]=y,e[27]=j):j=e[27],j},zu=[48,32,24,18,14],Au=["ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz",`0123456789 .,;:!?&@#%()[]{}<>+-=/\\*"'`];let Sr=0;const Iu=r=>{const e=De.c(16),{src:t,name:a,sizeBytes:p}=r,{t:d}=nt(),[v,f]=i.useState("loading"),[x]=i.useState(Ou);let g,h;e[0]!==x||e[1]!==t?(g=()=>{let y=!1;f("loading");const j=new FontFace(x,`url("${t.replace(/"/g,"%22")}")`);return document.fonts.add(j),j.load().then(()=>{y||f("ready")}).catch(()=>{y||f("failed")}),()=>{y=!0,document.fonts.delete(j)}},h=[x,t],e[0]=x,e[1]=t,e[2]=g,e[3]=h):(g=e[2],h=e[3]),i.useEffect(g,h);let w;e[4]!==p?(w=Bn(p),e[4]=p,e[5]=w):w=e[5];let F;e[6]!==a||e[7]!==w?(F=s.jsx(On,{items:[a,w]}),e[6]=a,e[7]=w,e[8]=F):F=e[8];let C;e[9]!==x||e[10]!==v||e[11]!==d?(C=v==="failed"?s.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-center typography-ui text-muted-foreground",children:d("filesView.artifact.font.loadFailed")}):v==="loading"?s.jsxs("div",{className:"flex items-center gap-2 p-3 typography-ui text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}),d("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:[zu.map(y=>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:y}),s.jsx("span",{className:"min-w-0 break-words leading-tight text-foreground",style:{fontSize:`${y}px`},children:d("filesView.artifact.font.sample")})]},y)),s.jsx("div",{className:"mt-2 flex flex-col gap-1 border-t border-border/40 pt-4 text-foreground",style:{fontSize:"20px"},children:Au.map(Bu)})]})}),e[9]=x,e[10]=v,e[11]=d,e[12]=C):C=e[12];let k;return e[13]!==F||e[14]!==C?(k=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[F,C]}),e[13]=F,e[14]=C,e[15]=k):k=e[15],k};function Ou(){return Sr=Sr+1,`oc-font-preview-${Sr}`}function Bu(r){return s.jsx("div",{className:"break-all leading-relaxed",children:r},r)}const Ls=12,no=.1,so=16,Ta=[.1,.25,.5,.75,1,1.5,2,3,4,6,8,12,16],$u=16,Ma=30,_u=(r,e)=>{const t=e.width-Ls*2,a=e.height-Ls*2;return r.width<=0||r.height<=0||t<=0||a<=0?1:Math.min(1,t/r.width,a/r.height)},Wu=(r,e)=>Math.min(so,Math.max(Math.min(no,e),r)),Va=(r,e)=>e===1?Ta.find(t=>t>r*1.001)??so:[...Ta].reverse().find(t=>t<r*.999)??no,Uu=(r,e)=>{const t=e===1?r*$u:r,a=Math.max(-Ma,Math.min(Ma,t));return Math.exp(-a/100)},Pa=(r,e)=>Math.hypot(r.clientX-e.clientX,r.clientY-e.clientY),Hu=({src:r,name:e,sizeBytes:t})=>{const{t:a}=nt(),[p,d]=i.useState(null),[v,f]=i.useState(null),[x,g]=i.useState(null),[h,w]=i.useState(!1),F=i.useRef(null),C=i.useRef(null),k=i.useRef(null),y=i.useRef(null);i.useEffect(()=>{f(null),d(null)},[r]),i.useEffect(()=>{const R=F.current;if(!R)return;const P=new ResizeObserver(()=>{g({width:R.clientWidth,height:R.clientHeight})});return P.observe(R),()=>P.disconnect()},[]);const j=v&&x?_u(v,x):1,l=p??j,S=p!==null&&v!==null&&x!==null&&(v.width*p+Ls*2>x.width||v.height*p+Ls*2>x.height),T=(R,P,O)=>{const K=C.current;if(!K||!v)return;const Q=K.getBoundingClientRect(),ee=K.clientWidth/v.width;ee<=0||(k.current={imageX:(P-Q.left-K.clientLeft)/ee,imageY:(O-Q.top-K.clientTop)/ee,clientX:P,clientY:O},Ts.flushSync(()=>d(Wu(R,j))))},V=R=>{const P=F.current;if(!P)return;const O=P.getBoundingClientRect();T(R,O.left+O.width/2,O.top+O.height/2)};i.useLayoutEffect(()=>{const R=k.current,P=F.current,O=C.current;if(k.current=null,!R||!P||!O||p===null||O.naturalWidth<=0)return;const K=O.getBoundingClientRect(),Q=O.clientWidth/O.naturalWidth;P.scrollLeft+=K.left+O.clientLeft+R.imageX*Q-R.clientX,P.scrollTop+=K.top+O.clientTop+R.imageY*Q-R.clientY},[p]);const L=i.useRef({zoomTo:T,shownScale:l});L.current={zoomTo:T,shownScale:l},i.useEffect(()=>{const R=F.current;if(!R)return;let P=0,O=null,K=null;const Q=A=>{if(!A.ctrlKey&&!A.metaKey)return;A.preventDefault();const ue=L.current;ue.zoomTo(ue.shownScale*Uu(A.deltaY,A.deltaMode),A.clientX,A.clientY)},ee=A=>{P=A.touches.length,A.touches.length===2&&(O={distance:Pa(A.touches[0],A.touches[1]),scale:L.current.shownScale})},ae=A=>{if(!O||A.touches.length!==2||O.distance<=0)return;A.preventDefault();const[ue,xe]=[A.touches[0],A.touches[1]];L.current.zoomTo(O.scale*(Pa(ue,xe)/O.distance),(ue.clientX+xe.clientX)/2,(ue.clientY+xe.clientY)/2)},J=A=>{P=A.touches.length,A.touches.length<2&&(O=null)},Y=A=>{A.preventDefault(),K=P>0?null:L.current.shownScale},se=A=>{A.preventDefault(),K!==null&&L.current.zoomTo(K*A.scale,A.clientX,A.clientY)},Le=A=>{A.preventDefault(),K=null};return R.addEventListener("wheel",Q,{passive:!1}),R.addEventListener("touchstart",ee,{passive:!0}),R.addEventListener("touchmove",ae,{passive:!1}),R.addEventListener("touchend",J,{passive:!0}),R.addEventListener("touchcancel",J,{passive:!0}),R.addEventListener("gesturestart",Y),R.addEventListener("gesturechange",se),R.addEventListener("gestureend",Le),()=>{R.removeEventListener("wheel",Q),R.removeEventListener("touchstart",ee),R.removeEventListener("touchmove",ae),R.removeEventListener("touchend",J),R.removeEventListener("touchcancel",J),R.removeEventListener("gesturestart",Y),R.removeEventListener("gesturechange",se),R.removeEventListener("gestureend",Le)}},[]);const I=R=>{if(!S||R.pointerType!=="mouse"||R.button!==0)return;const P=R.currentTarget,O=P.getBoundingClientRect();R.clientX-O.left>=P.clientWidth||R.clientY-O.top>=P.clientHeight||(R.preventDefault(),P.setPointerCapture(R.pointerId),y.current={pointerId:R.pointerId,x:R.clientX,y:R.clientY,left:P.scrollLeft,top:P.scrollTop},w(!0))},E=R=>{const P=y.current;!P||P.pointerId!==R.pointerId||(R.currentTarget.scrollLeft=P.left-(R.clientX-P.x),R.currentTarget.scrollTop=P.top-(R.clientY-P.y))},z=R=>{y.current?.pointerId===R.pointerId&&(y.current=null,w(!1))},_=R=>{if(p===null){T(1,R.clientX,R.clientY);return}d(null)};return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s.jsx(On,{items:[to(v),Bn(t)],actions:s.jsxs(s.Fragment,{children:[s.jsx($,{variant:"ghost",size:"xs","aria-label":a("filesView.artifact.image.zoomOut"),title:a("filesView.artifact.image.zoomOut"),disabled:!v,onClick:()=>V(Va(l,-1)),children:s.jsx(M,{name:"subtract",className:"size-3.5"})}),s.jsx($,{variant:"ghost",size:"xs",className:"min-w-11 tabular-nums",title:a("filesView.artifact.image.actualTitle"),disabled:!v,onClick:()=>V(1),children:`${Math.round(l*100)}%`}),s.jsx($,{variant:"ghost",size:"xs","aria-label":a("filesView.artifact.image.zoomIn"),title:a("filesView.artifact.image.zoomIn"),disabled:!v,onClick:()=>V(Va(l,1)),children:s.jsx(M,{name:"add",className:"size-3.5"})}),s.jsx($,{variant:"chip",size:"xs","aria-pressed":p===null,title:a("filesView.artifact.image.fitTitle"),onClick:()=>d(null),children:a("filesView.artifact.image.fit")})]})}),s.jsx("div",{ref:F,className:q("min-h-0 flex-1 overflow-auto",S&&(h?"cursor-grabbing":"cursor-grab")),onPointerDown:I,onPointerMove:E,onPointerUp:z,onPointerCancel:z,onDoubleClick:_,children:s.jsx("div",{className:q("flex items-center justify-center p-3",p===null?"h-full w-full":"min-h-full min-w-full w-max"),children:s.jsx("img",{ref:C,src:r,alt:e,draggable:!1,onLoad:R=>{const P=R.currentTarget;f({width:P.naturalWidth,height:P.naturalHeight})},style:p!==null&&v?{width:v.width*p,height:v.height*p}:void 0,className:q("select-none rounded-md border border-border/30 bg-primary/10",p===null?"max-h-full max-w-full object-contain":"max-w-none shrink-0")},r)})})]})},Ku=r=>{const e=De.c(24),{kind:t,src:a,name:p,sizeBytes:d,download:v}=r,{t:f}=nt(),[x,g]=i.useState(null),[h,w]=i.useState(null),[F,C]=i.useState(!1);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{g(null),w(null),C(!1)},e[0]=k):k=e[0];let y;e[1]!==a?(y=[a],e[1]=a,e[2]=y):y=e[2],i.useEffect(k,y);let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=z=>{const _=z.currentTarget;g(Number.isFinite(_.duration)?_.duration:null),_ instanceof HTMLVideoElement&&w({width:_.videoWidth,height:_.videoHeight})},e[3]=j):j=e[3];const l=j;let S;e[4]!==x?(S=Du(x),e[4]=x,e[5]=S):S=e[5];let T;e[6]!==h?(T=to(h),e[6]=h,e[7]=T):T=e[7];let V;e[8]!==d?(V=Bn(d),e[8]=d,e[9]=V):V=e[9];let L;e[10]!==S||e[11]!==T||e[12]!==V?(L=s.jsx(On,{items:[S,T,V]}),e[10]=S,e[11]=T,e[12]=V,e[13]=L):L=e[13];let I;e[14]!==v||e[15]!==F||e[16]!==t||e[17]!==p||e[18]!==a||e[19]!==f?(I=F?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:f("filesView.artifact.media.unplayable")}),v]}):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:p,className:"max-h-full max-w-full rounded-md",onLoadedMetadata:l,onError:()=>C(!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:p}),s.jsx("audio",{src:a,controls:!0,preload:"metadata",title:p,className:"w-full max-w-lg",onLoadedMetadata:l,onError:()=>C(!0)},a)]}),e[14]=v,e[15]=F,e[16]=t,e[17]=p,e[18]=a,e[19]=f,e[20]=I):I=e[20];let E;return e[21]!==L||e[22]!==I?(E=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[L,I]}),e[21]=L,e[22]=I,e[23]=E):E=e[23],E},qu=2e3,Gu=r=>r.toLowerCase().endsWith(".tsv")?" ":",",Xu=(r,e,t=qu)=>{const a=[];let p=0,d="",v=[],f=!1,x=!1;const g=()=>{v.push(d),d="",v.length===1&&v[0]===""&&!x||((p===0||a.length<=t)&&a.push(v),p+=1),v=[],x=!1},h=r.charCodeAt(0)===65279?r.slice(1):r;for(let y=0;y<h.length;y+=1){const j=h[y];if(f){j==='"'?h[y+1]==='"'?(d+='"',y+=1):f=!1:d+=j;continue}if(j==='"'){f=!0,x=!0;continue}if(j===e){v.push(d),d="",x=!0;continue}if(j===`
|
|
11
|
-
`||j==="\r"){j==="\r"&&h[y+1]===`
|
|
12
|
-
`&&(y+=1),g();continue}d+=j}(d.length>0||v.length>0||f)&&g();const w=a[0]??[],F=a.slice(1),C=a.reduce((y,j)=>Math.max(y,j.length),0),k=Math.max(0,p-1);return{header:w,rows:F,totalRows:k,columnCount:C,truncated:F.length<k}},Yu=r=>{const e=De.c(29),{path:t,content:a,sizeBytes:p}=r,{t:d}=nt();let v;e[0]!==a||e[1]!==t?(v=Xu(a,Gu(t)),e[0]=a,e[1]=t,e[2]=v):v=e[2];const f=v;let x;e[3]!==d||e[4]!==f.columnCount||e[5]!==f.totalRows?(x=f.totalRows===1?d("filesView.artifact.table.rowsSingle",{rows:f.totalRows,columns:f.columnCount}):d("filesView.artifact.table.rowsPlural",{rows:f.totalRows,columns:f.columnCount}),e[3]=d,e[4]=f.columnCount,e[5]=f.totalRows,e[6]=x):x=e[6];const g=x;let h;e[7]!==f.columnCount?(h=Array.from({length:f.columnCount},Ju),e[7]=f.columnCount,e[8]=h):h=e[8];const w=h;let F;e[9]!==d||e[10]!==f.rows||e[11]!==f.totalRows||e[12]!==f.truncated?(F=f.truncated?d("filesView.artifact.table.truncated",{shown:f.rows.length,total:f.totalRows}):"",e[9]=d,e[10]=f.rows,e[11]=f.totalRows,e[12]=f.truncated,e[13]=F):F=e[13];let C;e[14]!==p?(C=Bn(p),e[14]=p,e[15]=C):C=e[15];let k;e[16]!==g||e[17]!==F||e[18]!==C?(k=s.jsx(On,{items:[g,F,C]}),e[16]=g,e[17]=F,e[18]=C,e[19]=k):k=e[19];let y;e[20]!==w||e[21]!==d||e[22]!==f.columnCount||e[23]!==f.header||e[24]!==f.rows?(y=f.columnCount===0?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:d("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(l=>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:f.header[l]??""},l))})}),s.jsx("tbody",{children:f.rows.map((l,S)=>s.jsx("tr",{className:"odd:bg-[var(--surface-background)] even:bg-[var(--surface-subtle)]/40",children:w.map(T=>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:l[T]??"",children:l[T]??""},T))},S))})]})}),e[20]=w,e[21]=d,e[22]=f.columnCount,e[23]=f.header,e[24]=f.rows,e[25]=y):y=e[25];let j;return e[26]!==k||e[27]!==y?(j=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[k,y]}),e[26]=k,e[27]=y,e[28]=j):j=e[28],j};function Ju(r,e){return e}const hn="data-oc-local-asset",Zu=25*1024*1024,Es=r=>{const e=r.trim();return!e||e.startsWith("#")||e.startsWith("//")?!1:!/^[a-z][a-z\d+.-]*:/i.test(e)},Qu=r=>r.split(/[?#]/,1)[0]??"",ed=r=>r.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-"),td=(r,e)=>{const t=ro(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||ed(a.textContent??"")===t)return a.scrollIntoView({block:"start"}),!0;return!1},ro=r=>{try{return decodeURIComponent(r)}catch{return r}},nd=r=>r.split(",").flatMap(e=>{const[t,...a]=e.trim().split(/\s+/);return t?[{url:t,descriptor:a.join(" ")}]:[]}),Nr="data-oc-media",sd=/\(\s*prefers-color-scheme\s*:\s*(light|dark)\s*\)/gi,Da=(r,e)=>{for(const t of Array.from(r.querySelectorAll("picture > source[media]"))){const a=t.getAttribute(Nr)??t.getAttribute("media")??"",p=a.replace(sd,(d,v)=>v.toLowerCase()===e?"(min-width: 0px)":"(max-width: -1px)");p!==a&&(t.getAttribute(Nr)!==a&&t.setAttribute(Nr,a),t.getAttribute("media")!==p&&t.setAttribute("media",p))}},La=({container:r,filePath:e,workspaceRoot:t,onOpenFile:a,enabled:p,colorScheme:d})=>{const v=i.useRef(a);v.current=a;const f=i.useRef(d);f.current=d,i.useEffect(()=>{p&&r&&Da(r,d)},[d,r,p]),i.useEffect(()=>{if(!p||!r||!e)return;const x=e.slice(0,e.lastIndexOf("/")+1)||"/",g=S=>Zl(x,ro(Qu(S))),h=S=>({path:S,allowOutsideWorkspace:t&&Ql(S,t)?void 0:"true",directory:t||void 0});let w=!1;const F=ot(),C=new Map,k=S=>{const T=C.get(S);if(T)return T;const V=(async()=>{const L=await Ms("/api/fs/raw",{query:h(S),signal:AbortSignal.timeout(3e4)});if(!L.ok)throw new Error(`Image read failed (${L.status})`);const I=await L.blob();if(I.size>Zu)throw new Error("Image too large for preview");if(w||ot()!==F)throw new Error("Preview closed");return URL.createObjectURL(I)})();return C.set(S,V),V.catch(()=>C.delete(S)),V},y=()=>{for(const S of Array.from(r.querySelectorAll("img[src]"))){const T=S.getAttribute("src")??"";if(!Es(T))continue;const V=g(T);S.setAttribute(hn,V),k(V).then(L=>{w||S.getAttribute(hn)!==V||S.getAttribute("src")!==L&&(S.src=L)}).catch(()=>{w||S.removeAttribute(hn)})}for(const S of Array.from(r.querySelectorAll("source[srcset], img[srcset]"))){const T=nd(S.getAttribute("srcset")??"");if(!T.some(I=>Es(I.url)))continue;const V=T.map(I=>({...I,path:Es(I.url)?g(I.url):null})),L=V.map(I=>I.path??I.url).join(",");S.setAttribute(hn,L),Promise.all(V.map(async({url:I,descriptor:E,path:z})=>{const _=z?await k(z):I;return E?`${_} ${E}`:_})).then(I=>{if(w||S.getAttribute(hn)!==L)return;const E=I.join(", ");S.getAttribute("srcset")!==E&&S.setAttribute("srcset",E)}).catch(()=>{w||S.removeAttribute(hn)})}Da(r,f.current)},j=S=>{if(S.defaultPrevented||S.button!==0||S.metaKey||S.ctrlKey||S.shiftKey||S.altKey)return;const T=S.target;if(!(T instanceof Element))return;const V=T.closest("a[href]");if(!(V instanceof HTMLAnchorElement)||!r.contains(V))return;const L=V.getAttribute("href")??"";if(L.startsWith("#")){S.preventDefault(),S.stopPropagation(),td(r,L);return}Es(L)&&(S.preventDefault(),S.stopPropagation(),v.current(g(L)))};y();const l=new MutationObserver(y);return l.observe(r,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src","srcset","media"]}),r.addEventListener("click",j,!0),()=>{w=!0,l.disconnect(),r.removeEventListener("click",j,!0);for(const S of C.values())S.then(T=>URL.revokeObjectURL(T)).catch(()=>{})}},[r,p,e,t])},rd=r=>{const e=te(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},id=r=>{const e=De.c(8),{label:t,iconDataUrl:a}=r,[p,d]=i.useState(!1);let v;e[0]!==t?(v=t.trim().slice(0,1).toUpperCase()||"?",e[0]=t,e[1]=v):v=e[1];const f=v;if(a&&!p){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>d(!0),e[2]=h):h=e[2];let w;return e[3]!==a?(w=s.jsx("img",{src:a,alt:"",className:"size-4 rounded-sm",onError:h}),e[3]=a,e[4]=w):w=e[4],w}let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=q("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 g;return e[6]!==f?(g=s.jsx("span",{className:x,children:f}),e[6]=f,e[7]=g):g=e[7],g},ad=r=>r.slice().sort((e,t)=>e.type!==t.type?e.type==="directory"?-1:1:e.name.localeCompare(t.name)),te=r=>{if(!r)return"";const e=r.replace(/\\/g,"/"),t=e.startsWith("//");let a=e.replace(/\/+/g,"/");t&&!a.startsWith("//")&&(a=`/${a}`);const p=a==="/",d=/^[A-Za-z]:\/$/.test(a);return!p&&!d&&(a=a.replace(/\/+$/,"")),a},od=r=>r.startsWith("/")||r.startsWith("//")||/^[A-Za-z]:\//.test(r),gn=r=>/^[A-Za-z]:\//.test(r)?r.toLowerCase():r,An=(r,e)=>{const t=te(e),a=te(r);if(!t||!a)return!1;const p=gn(t),d=gn(a);return d===p||d.startsWith(`${p}/`)},za=(r,e)=>{const t=te(e),a=te(r);if(!An(a,t))return[];const d=a.slice(t.length).replace(/^\//,"").split("/"),v=[];let f=t;for(let x=0;x<d.length-1;x++)f=f?`${f}/${d[x]}`:d[x],v.push(f);return v},Ps=(r,e)=>{if(!e)return"";const t=te(e);if(!r||!An(t,r))return t;const a=t.slice(r.length);return a.startsWith("/")?a.slice(1):a},ld=new Set(["node_modules"]),cd=r=>{const e=De.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 p=a[t];let d;return e[1]!==p?(d=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:p}}),e[1]=p,e[2]=d):d=e[2],d},Aa=r=>{const e=De.c(11),{name:t}=r,a=i.useRef(null),p=i.useRef(null),[d,v]=i.useState(!1);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const F=a.current,C=p.current;if(!F||!C)return;const k=()=>{v(C.scrollWidth>F.clientWidth+1)};k();const y=new ResizeObserver(k);return y.observe(F),y.observe(C),()=>{y.disconnect()}},e[0]=f):f=e[0];let x;e[1]!==t?(x=[t],e[1]=t,e[2]=x):x=e[2],i.useLayoutEffect(f,x);let g;e[3]!==t?(g=s.jsx("span",{ref:p,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:t}),e[3]=t,e[4]=g):g=e[4];let h;e[5]!==t||e[6]!==d?(h=d?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]=d,e[7]=h):h=e[7];let w;return e[8]!==g||e[9]!==h?(w=s.jsxs("span",{ref:a,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[g,h]}),e[8]=g,e[9]=h,e[10]=w):w=e[10],w},ud=r=>ld.has(r),dd=r=>{const e=te(r);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},fd=r=>{const t=(r instanceof Error?r.message:String(r??"")).toLowerCase();return t.includes("is a directory")||t.includes("eisdir")},Ia=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")},md=2e5,io=(r,e)=>s.jsx(zn,{filePath:r,extension:e}),Fr=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"},Rr=r=>!!(r&&eo(Vr.getState().guests,r)),Oa=r=>{if(!r)return!1;const e=r.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},ks=r=>{if(!r)return!1;const e=r.toLowerCase().split(".").pop();return e==="html"||e==="htm"},hd=r=>{const e=De.c(78),{node:t,root:a,isExpanded:p,isActive:d,isMobile:v,isBrowserClient:f,alwaysShowActions:x,status:g,badge:h,permissions:w,downloadFile:F,contextMenuPath:C,setContextMenuPath:k,rightClickMenuPath:y,setRightClickMenuPath:j,onSelect:l,onToggle:S,onRevealPath:T,onOpenDialog:V,canUpload:L,onPickFiles:I}=r,{t:E}=nt(),z=t.type==="directory",{canRename:_,canCreateFile:R,canCreateFolder:P,canDelete:O,canReveal:K}=w,Q=!z&&!!F,ee=K&&!f,ae=z&&L,J=_||R||P||ae||O||Q||ee;let Y;e[0]!==J||e[1]!==t.path||e[2]!==j?(Y=ye=>{J&&(ye?.preventDefault(),j(t.path))},e[0]=J,e[1]=t.path,e[2]=j,e[3]=Y):Y=e[3];const se=Y;let Le;e[4]!==z||e[5]!==t||e[6]!==l||e[7]!==S?(Le=()=>{z?S(t.path):l(t)},e[4]=z,e[5]=t,e[6]=l,e[7]=S,e[8]=Le):Le=e[8];const A=Le;let ue;e[9]!==t.path||e[10]!==k||e[11]!==j?(ue=ye=>{ye.stopPropagation(),j(null),k(t.path)},e[9]=t.path,e[10]=k,e[11]=j,e[12]=ue):ue=e[12];const xe=ue;let ze;e[13]!==R||e[14]!==P||e[15]!==O||e[16]!==_||e[17]!==ee||e[18]!==ae||e[19]!==F||e[20]!==f||e[21]!==z||e[22]!==t||e[23]!==V||e[24]!==I||e[25]!==T||e[26]!==a||e[27]!==E?(ze=ye=>{const{Item:Ee,Separator:st}=ye;return s.jsxs(s.Fragment,{children:[_&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),V("rename",t)},children:[s.jsx(M,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),Ds(t.path).then(We=>{if(We.ok){X.success(E("sidebarFilesTree.toast.pathCopied"));return}X.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(M,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Ee,{onClick:me=>{me.stopPropagation();const We=Ps(a,t.path)||t.path;Ds(We).then($n=>{if($n.ok){X.success(E("filesView.toast.relativePathCopied"));return}X.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(M,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!z&&F&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),F(t.path).catch(We=>{console.error("Download failed:",We),X.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(M,{name:"download",className:"mr-2 size-4"})," ",E(f?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),ee&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),T(t.path)},children:[s.jsx(M,{name:"folder-received",className:"mr-2 size-4"})," ",E(yc())]}),z&&(R||P||ae)&&s.jsxs(s.Fragment,{children:[s.jsx(st,{}),R&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),V("createFile",t)},children:[s.jsx(M,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),P&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),V("createFolder",t)},children:[s.jsx(M,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]}),ae&&s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),I(t.path)},children:[s.jsx(M,{name:"upload-2",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.uploadFiles")]})]}),O&&s.jsxs(s.Fragment,{children:[s.jsx(st,{}),s.jsxs(Ee,{onClick:me=>{me.stopPropagation(),V("delete",t)},className:"text-destructive focus:text-destructive",children:[s.jsx(M,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=R,e[14]=P,e[15]=O,e[16]=_,e[17]=ee,e[18]=ae,e[19]=F,e[20]=f,e[21]=z,e[22]=t,e[23]=V,e[24]=I,e[25]=T,e[26]=a,e[27]=E,e[28]=ze):ze=e[28];const Fe=ze,$e=y===t.path;let Re;e[29]!==t.path||e[30]!==j?(Re=ye=>j(ye?t.path:null),e[29]=t.path,e[30]=j,e[31]=Re):Re=e[31];const ne=v?void 0:se;let de;e[32]!==ne?(de=s.jsx("div",{className:"group relative flex items-center",onContextMenu:ne}),e[32]=ne,e[33]=de):de=e[33];const _e=v?void 0:se,G=d?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let W;e[34]!==G?(W=q("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]=W):W=e[35];let oe;e[36]!==z||e[37]!==p||e[38]!==t.extension||e[39]!==t.path?(oe=z?p?s.jsx(M,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(M,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):io(t.path,t.extension),e[36]=z,e[37]=p,e[38]=t.extension,e[39]=t.path,e[40]=oe):oe=e[40];let le;e[41]!==t.name||e[42]!==t.path?(le=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]=le):le=e[43];let Se;e[44]!==z||e[45]!==g?(Se=!z&&g&&s.jsx(cd,{status:g}),e[44]=z,e[45]=g,e[46]=Se):Se=e[46];let re;e[47]!==h||e[48]!==z?(re=z&&h&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[h.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",h.modified]}),h.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",h.added]})]}),e[47]=h,e[48]=z,e[49]=re):re=e[49];let fe;e[50]!==A||e[51]!==W||e[52]!==oe||e[53]!==le||e[54]!==Se||e[55]!==re||e[56]!==_e?(fe=s.jsxs("button",{type:"button",onClick:A,onContextMenu:_e,className:W,children:[oe,le,Se,re]}),e[50]=A,e[51]=W,e[52]=oe,e[53]=le,e[54]=Se,e[55]=re,e[56]=_e,e[57]=fe):fe=e[57];let pe;e[58]!==x||e[59]!==C||e[60]!==xe||e[61]!==J||e[62]!==v||e[63]!==t.path||e[64]!==Fe||e[65]!==k?(pe=J&&s.jsx("div",{className:q("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(kr,{open:C===t.path,onOpenChange:ye=>k(ye?t.path:null),children:[s.jsx(Tr,{asChild:!0,children:s.jsx($,{variant:"ghost",size:"icon",className:"size-6",onClick:xe,children:s.jsx(M,{name:"more-2-fill",className:"size-4"})})}),s.jsx(Mr,{align:"end",side:"bottom",onCloseAutoFocus:()=>k(null),children:Fe({Item:Vs,Separator:bc})})]})}),e[58]=x,e[59]=C,e[60]=xe,e[61]=J,e[62]=v,e[63]=t.path,e[64]=Fe,e[65]=k,e[66]=pe):pe=e[66];let be;e[67]!==fe||e[68]!==pe||e[69]!==de?(be=s.jsxs(Ec,{render:de,children:[fe,pe]}),e[67]=fe,e[68]=pe,e[69]=de,e[70]=be):be=e[70];let ge;e[71]!==Fe?(ge=s.jsx(Nc,{className:"min-w-[180px]",children:Fe({Item:Rc,Separator:Fc})}),e[71]=Fe,e[72]=ge):ge=e[72];let pt;return e[73]!==be||e[74]!==ge||e[75]!==$e||e[76]!==Re?(pt=s.jsxs(kc,{open:$e,onOpenChange:Re,children:[be,ge]}),e[73]=be,e[74]=ge,e[75]=$e,e[76]=Re,e[77]=pt):pt=e[77],pt},pd=r=>{const e=De.c(83),{activeDialog:t,dialogData:a,dialogInputValue:p,onDialogInputChange:d,isDialogSubmitting:v,onDialogSubmit:f,onClose:x,inputRef:g}=r,{t:h}=nt(),w=!!t;let F;e[0]!==x?(F=se=>!se&&x(),e[0]=x,e[1]=F):F=e[1];let C;e[2]!==t||e[3]!==h?(C=t==="createFile"&&h("filesView.dialog.createFile.title"),e[2]=t,e[3]=h,e[4]=C):C=e[4];let k;e[5]!==t||e[6]!==h?(k=t==="createFolder"&&h("filesView.dialog.createFolder.title"),e[5]=t,e[6]=h,e[7]=k):k=e[7];let y;e[8]!==t||e[9]!==h?(y=t==="rename"&&h("filesView.dialog.rename.title"),e[8]=t,e[9]=h,e[10]=y):y=e[10];let j;e[11]!==t||e[12]!==h?(j=t==="delete"&&h("filesView.dialog.delete.title"),e[11]=t,e[12]=h,e[13]=j):j=e[13];let l;e[14]!==C||e[15]!==k||e[16]!==y||e[17]!==j?(l=s.jsxs(qa,{children:[C,k,y,j]}),e[14]=C,e[15]=k,e[16]=y,e[17]=j,e[18]=l):l=e[18];let S;e[19]!==t||e[20]!==a?.path||e[21]!==h?(S=t==="createFile"&&h("filesView.dialog.createFile.description",{path:a?.path??h("filesView.dialog.rootFallback")}),e[19]=t,e[20]=a?.path,e[21]=h,e[22]=S):S=e[22];let T;e[23]!==t||e[24]!==a?.path||e[25]!==h?(T=t==="createFolder"&&h("filesView.dialog.createFolder.description",{path:a?.path??h("filesView.dialog.rootFallback")}),e[23]=t,e[24]=a?.path,e[25]=h,e[26]=T):T=e[26];let V;e[27]!==t||e[28]!==a?.name||e[29]!==h?(V=t==="rename"&&h("filesView.dialog.rename.description",{name:a?.name??""}),e[27]=t,e[28]=a?.name,e[29]=h,e[30]=V):V=e[30];let L;e[31]!==t||e[32]!==a?.name||e[33]!==h?(L=t==="delete"&&h("filesView.dialog.delete.description",{name:a?.name??""}),e[31]=t,e[32]=a?.name,e[33]=h,e[34]=L):L=e[34];let I;e[35]!==V||e[36]!==L||e[37]!==S||e[38]!==T?(I=s.jsxs(Ga,{children:[S,T,V,L]}),e[35]=V,e[36]=L,e[37]=S,e[38]=T,e[39]=I):I=e[39];let E;e[40]!==I||e[41]!==l?(E=s.jsxs(Ka,{children:[l,I]}),e[40]=I,e[41]=l,e[42]=E):E=e[42];let z;e[43]!==t||e[44]!==p||e[45]!==g||e[46]!==d||e[47]!==f||e[48]!==h?(z=t!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(In,{value:p,onChange:se=>d(se.target.value),placeholder:h(t==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:se=>{se.key==="Enter"&&f()},ref:g})}),e[43]=t,e[44]=p,e[45]=g,e[46]=d,e[47]=f,e[48]=h,e[49]=z):z=e[49];let _;e[50]!==h?(_=h("filesView.dialog.cancel"),e[50]=h,e[51]=_):_=e[51];let R;e[52]!==v||e[53]!==x||e[54]!==_?(R=s.jsx($,{variant:"outline",onClick:x,disabled:v,children:_}),e[52]=v,e[53]=x,e[54]=_,e[55]=R):R=e[55];const P=t==="delete"?"destructive":"default";let O;e[56]!==f?(O=()=>{f()},e[56]=f,e[57]=O):O=e[57];let K;e[58]!==t||e[59]!==p||e[60]!==v?(K=v||t!=="delete"&&!p.trim(),e[58]=t,e[59]=p,e[60]=v,e[61]=K):K=e[61];let Q;e[62]!==t||e[63]!==v||e[64]!==h?(Q=v?s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}):h(t==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=t,e[63]=v,e[64]=h,e[65]=Q):Q=e[65];let ee;e[66]!==P||e[67]!==O||e[68]!==K||e[69]!==Q?(ee=s.jsx($,{variant:P,onClick:O,disabled:K,children:Q}),e[66]=P,e[67]=O,e[68]=K,e[69]=Q,e[70]=ee):ee=e[70];let ae;e[71]!==R||e[72]!==ee?(ae=s.jsxs(Xa,{children:[R,ee]}),e[71]=R,e[72]=ee,e[73]=ae):ae=e[73];let J;e[74]!==g||e[75]!==E||e[76]!==z||e[77]!==ae?(J=s.jsxs(Ha,{initialFocus:g,children:[E,z,ae]}),e[74]=g,e[75]=E,e[76]=z,e[77]=ae,e[78]=J):J=e[78];let Y;return e[79]!==w||e[80]!==F||e[81]!==J?(Y=s.jsx(Ua,{open:w,onOpenChange:F,children:J}),e[79]=w,e[80]=F,e[81]=J,e[82]=Y):Y=e[82],Y},pn=new Map,gd=100,Ba=r=>{const e=De.c(13);let t,a,p;e[0]!==r?({positionKey:a,onViewReady:t,...p}=r,e[0]=r,e[1]=t,e[2]=a,e[3]=p):(t=e[1],a=e[2],p=e[3]);const d=i.useRef(null);let v,f;e[4]!==a?(v=()=>()=>{const h=d.current;if(!h)return;const{anchor:w,head:F}=h.state.selection.main;if(pn.delete(a),pn.set(a,{scroll:h.scrollSnapshot(),anchor:w,head:F}),pn.size>gd){const C=pn.keys().next().value;C!==void 0&&pn.delete(C)}},f=[a],e[4]=a,e[5]=v,e[6]=f):(v=e[5],f=e[6]),i.useLayoutEffect(v,f);let x;e[7]!==t||e[8]!==a?(x=h=>{d.current=h;const w=pn.get(a);w&&h.dispatch({selection:{anchor:Math.min(w.anchor,h.state.doc.length),head:Math.min(w.head,h.state.doc.length)},effects:w.scroll}),t?.(h)},e[7]=t,e[8]=a,e[9]=x):x=e[9];let g;return e[10]!==p||e[11]!==x?(g=s.jsx(Mc,{...p,onViewReady:x}),e[10]=p,e[11]=x,e[12]=g):g=e[12],g},$a=(r,e,t)=>{const a=De.c(8),[p,d]=i.useState(""),[v,f]=i.useState(0);let x,g;a[0]!==r||a[1]!==t||a[2]!==e?(x=()=>{if(!r){d("");return}let w=!1;d("");const F=_l(),C=Wl(F);Ul(F).then(y=>{w||!y||(d(r),e(null))}).catch(y=>{w||(e(y instanceof Error?y.message:t),d(r))});const k=Hl(()=>{w||(d(r),f(vd),e(null))});return()=>{w=!0,C(),k()}},g=[r,e,t],a[0]=r,a[1]=t,a[2]=e,a[3]=x,a[4]=g):(x=a[3],g=a[4]),i.useEffect(x,g);let h;return a[5]!==v||a[6]!==p?(h={readyKey:p,nonce:v},a[5]=v,a[6]=p,a[7]=h):h=a[7],h},Om=({mode:r="full",visible:e=!0})=>{const{t}=nt(),{files:a,runtime:p}=ec(),{currentTheme:d,availableThemes:v,lightThemeId:f,darkThemeId:x}=tc(),{isMobile:g,isTablet:h,screenWidth:w}=_a(),F=Ll(p.platform),C=g||h,k=zl(),y=Al(),j=Wa()??"",l=te(j.trim()),S=g||r==="full",T=S&&e,V=nc(n=>n.runtimeKey),L=JSON.stringify([V,l]),I=i.useRef(L);I.current=L;const E=JSON.stringify([V,l,k,y]),z=i.useRef(E);z.current=E;const _=r!=="editor-only",R=r==="editor-only"&&!g,P=Il(n=>n.searchFiles),O=sc(T?j:null),[K,Q]=i.useState(""),ee=rc(K,200),ae=i.useRef(null),[J,Y]=i.useState(!1),[se,Le]=i.useState(!0),[A,ue]=i.useState(!1),xe=i.useCallback(n=>{if(!Hs.current){ue(n);return}const o=gt.current;if(yn.current){Hr.current?.().then(c=>{c&>.current===o&&ue(n)});return}Promise.resolve(Xt.current?.getContent("handoff")??Cr).then(c=>{if(gt.current===o){if(!c.ok){X.error(c.message);return}c.snapshot&&"content"in c.snapshot&&(Ce(c.snapshot.content),dt(!1)),ue(n)}})},[]),[ze,Fe]=i.useState(!1),$e=i.useRef(0),Re=i.useCallback(n=>{$e.current=Math.max(0,$e.current+(n?1:-1))},[]),[ne,de]=i.useState("edit"),[_e,G]=i.useState("edit"),[W,oe]=i.useState("tree"),[le,Se]=i.useState("edit"),[re,fe]=i.useState("preview"),[pe,be]=i.useState("preview"),[ge,pt]=i.useState("preview"),[ye,Ee]=i.useState("preview"),[st,me]=i.useState("table"),[We,$n]=i.useState(null),[ao,oo]=i.useState(0),[lo,_n]=i.useState(0),Wn=i.useRef({}),As=i.useRef({}),Is=i.useRef({}),Pr=i.useRef({}),Dr=i.useRef({}),Lr=i.useRef({}),Os=i.useRef({}),vn=i.useRef({}),Un=i.useMemo(()=>v.find(n=>n.metadata.id===f)??pa(!1),[v,f]),Hn=i.useMemo(()=>v.find(n=>n.metadata.id===x)??pa(!0),[v,x]);i.useEffect(()=>{ja(Un),ja(Hn)},[Un,Hn]);const Kn=i.useMemo(()=>[],[]),ke=tt(n=>l?n.byRoot[l]?.openPaths??Kn:Kn),Vt=tt(n=>l?n.byRoot[l]?.selectedPath??null:null),lt=tt(n=>l?n.byRoot[l]?.expandedPaths??Kn:Kn),co=i.useMemo(()=>new Set(lt),[lt]),Ht=tt(n=>n.removeOpenPath),St=tt(n=>n.removeOpenPathsByPrefix),zr=tt(n=>n.removeExpandedPathsByPrefix),Te=tt(n=>n.setSelectedPath),Ar=tt(n=>n.toggleExpandedPath),qn=tt(n=>n.expandPaths),Kt=i.useCallback(n=>{const o=te(n),c=o.split("/"),m=c[c.length-1]||o,b=m.includes(".")?m.split(".").pop()?.toLowerCase():void 0;return{name:m,path:o,type:"file",extension:b}},[]),qt=i.useMemo(()=>ke.map(Kt),[ke,Kt]),Bs=i.useMemo(()=>{if(Vt){const n=gn(Vt);if(ke.some(o=>gn(o)===n))return Vt}return ke[0]??null},[ke,Vt]),u=i.useMemo(()=>Bs?Kt(Bs):null,[Bs,Kt]),Ae=u?.path??"",gt=i.useRef(Ae);gt.current=Ae,i.useEffect(()=>{if(!l||!Vt)return;const n=gn(Vt);ke.some(c=>gn(c)===n)||Te(l,ke[0]??null)},[ke,l,Vt,Te]);const Gn=!!(l&&Ae&&!An(Ae,l)),$s=i.useMemo(()=>({allowOutsideWorkspace:Gn,directory:l||void 0}),[Gn,l]),ct=i.useCallback(n=>({allowOutsideWorkspace:!!(l&&!An(n,l))}),[l]),_s=i.useRef(null),[Ir,uo]=i.useState({left:!1,right:!1}),Or=i.useCallback(()=>{const n=_s.current;n&&uo({left:n.scrollLeft>2,right:n.scrollLeft+n.clientWidth<n.scrollWidth-2})},[]),Br=i.useRef(Or);Br.current=Or,i.useEffect(()=>{const n=_s.current;if(!n)return;const o=()=>Br.current();o(),n.addEventListener("scroll",o,{passive:!0});const c=new ResizeObserver(o);return c.observe(n),()=>{n.removeEventListener("scroll",o),c.disconnect()}},[qt.length]);const[$r,Ws]=i.useState({}),[Xn,xn]=i.useState({}),Xe=i.useRef(new Set),Ie=i.useMemo(()=>new Wc,[]);i.useEffect(()=>()=>Ie.clear(),[Ie]);const[_r,Yn]=i.useState([]),[fo,Jn]=i.useState(!1),[U,je]=i.useState(""),{isPlaying:Zn,play:mo,stop:ho}=ic(),[Me,Nt]=i.useState(!1),[rt,Ne]=i.useState(null),[po,Ye]=i.useState(""),[ce,ve]=i.useState(null),Ft=JSON.stringify([ot(),l,ce]),[ie,Ce]=i.useState(""),[Gt,Us]=i.useState(!1),[Wr,go]=i.useState(`
|
|
13
|
-
`),vo=i.useRef(null),ut=i.useRef(null),Ue=i.useRef(null),Rt=i.useRef(""),wn=i.useRef(""),vt=i.useRef(null),Pt=i.useRef(null),Ur=i.useRef(null),Xt=i.useRef(null),[bn,dt]=i.useState(!1),Hs=i.useRef(!1);Hs.current=bn;const yn=i.useRef(!1),Hr=i.useRef(null),Je=i.useRef(null),Ks=i.useRef(""),qs=i.useRef(0),Yt=i.useRef(0),Dt=i.useRef(null),[jn,xo]=i.useState(0),[wo,Jt]=i.useState("idle"),[bo,Qn]=i.useState(!1),[yo,Kr]=i.useState(!1),[Lt,qr]=i.useState(!1),Ve=ht(n=>n.autoSaveEnabled),jo=ht(n=>n.setAutoSaveEnabled),[Gs,Cn]=i.useState(!1),Zt=i.useRef(null),Sn=i.useRef(null),Nn=i.useRef(!1),Fn=i.useRef(null),Rn=i.useRef(null),Ze=i.useRef(null),es=i.useRef(null),Gr=i.useRef(null),Xr=i.useRef(0),[Co,Xs]=i.useState(0),Qt=i.useRef(null),zt=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{Qt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Qt.current),Qt.current=null)},[]);const[At,Ys]=i.useState(null),[It,So]=i.useState(null),[Et,Yr]=i.useState(""),[No,Js]=i.useState(!1),[Fo,Ro]=i.useState(null),[Eo,ko]=i.useState(null),[To,Jr]=i.useState(!1),[Mo,Zr]=i.useState(!1),[Vo,Zs]=i.useState(!1),[Qr,ts]=i.useState(!1),[ei,ti]=i.useState(0),ns=i.useRef(null),ss=i.useCallback(n=>{const o=n?.currentTarget??ns.current;if(!o)return;const c=document.activeElement;c&&c!==document.body&&c!==o&&(ac(c)||o.contains(c))||o.focus({preventScroll:!0})},[]),rs=i.useRef(null),ni=!!a.writeFile,si=!!a.createDirectory,ri=!!a.rename,ii=!!a.delete,ai=!!a.revealPath,Po=Fs(n=>n.availableApps),Do=Fs(n=>n.isCacheStale),oi=Fs(n=>n.initialize),Lo=Fs(n=>n.loadInstalledApps);i.useEffect(()=>{oi()},[oi]);const zo=i.useCallback(n=>{a.revealPath&&a.revealPath(n).catch(()=>{X.error(t("sidebarFilesTree.toast.revealFailed"))})},[a,t]),Ao=i.useCallback(async n=>{if(!u?.path||await Ol(u.path,n.id,n.appName)||await fa(u.path,n.appName))return;const m=rd(u.path)||l;m&&await fa(m,n.appName)||X.error(t("filesView.toast.openInAppFailed",{app:n.appName}))},[l,u?.path,t]),Qs=i.useCallback((n,o)=>{Ys(n),So(o),Yr(n==="rename"&&o.name||""),Js(!1)},[]),[Z,it]=i.useState(null),en=i.useRef(!1),kt=i.useRef(null),[li,tn]=i.useState(!1),ft=ht(n=>n.pendingFileNavigation),is=ht(n=>n.setPendingFileNavigation),er=ht(n=>n.pendingFileFocusPath),tr=ht(n=>n.setPendingFileFocusPath),ci=ht(n=>n.fileEditorKeymap),En=ga(n=>n.settingsDefaultFileViewerPreview),Io=ga(n=>n.showMessageTTSButtons);i.useEffect(()=>{const n=()=>{en.current=!1,kt.current=null,tn(!1)};return document.addEventListener("mouseup",n),()=>document.removeEventListener("mouseup",n)},[]),i.useEffect(()=>()=>{Fn.current!==null&&window.clearTimeout(Fn.current),Rn.current!==null&&window.clearTimeout(Rn.current)},[]);const Oo=i.useCallback((n,o)=>{const c=n.split(`
|
|
14
|
-
`),m=Math.max(1,o.start),b=Math.min(c.length,o.end);return m>b?"":c.slice(m-1,b).join(`
|
|
15
|
-
`)},[]),ui=i.useRef(null),Bo=Gc({source:"file",fileLabel:u?.path??null,language:u?.path&&vr(u.path)||"text",getCodeForRange:n=>Oo(U,Xc(n)),toStoreRange:n=>({startLine:n.start,endLine:n.end}),fromDraftRange:n=>({start:n.startLine,end:n.endLine})}),{drafts:di,commentText:as,setCommentText:fi,editingDraftId:os,setSelection:mi,saveComment:hi,cancel:kn,reset:pi,startEdit:gi,deleteDraft:vi}=Bo;i.useEffect(()=>{it(null),pi(),Ce(""),Us(!1)},[u?.path,pi]),i.useEffect(()=>{mi(Z)},[Z,mi]),i.useEffect(()=>{if(!Z&&!os)return;const n=c=>{const m=c.target;m.closest('[data-comment-input="true"]')||m.closest('[data-comment-card="true"]')||m.closest(".cm-gutterElement")||m.closest("[data-sonner-toast]")||m.closest("[data-sonner-toaster]")||as.trim()||(it(null),kn())},o=setTimeout(()=>{document.addEventListener("click",n)},100);return()=>{clearTimeout(o),document.removeEventListener("click",n)}},[kn,as,os,Z]),i.useEffect(()=>{if(!g||!Z)return;const n=Ze.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()},[g,Z]);const xi=i.useCallback((n,o)=>{const c=o??Z??void 0;o&&it(o),hi(n,c),it(null)},[Z,hi]),wi=i.useCallback((n,o)=>{const c=[];for(const m of o){if(!(m&&typeof m.name=="string"&&m.name.length>0)||!k&&m.name.startsWith(".")||!y&&ud(m.name))continue;const b=m.name,N=te(m.path||""),D=N?od(N)?N:te(`${n}/${N}`):te(`${n}/${b}`),H=m.isDirectory?"directory":"file",we=H==="file"&&b.includes(".")?b.split(".").pop()?.toLowerCase():void 0;c.push({name:b,path:D,type:H,extension:we})}return ad(c)},[y,k]),Oe=i.useCallback(async(n,o=!1)=>{if(!T)return;const c=te(n.trim());if(!c||!o&&Xe.current.has(c))return;const m=z.current,b=ot();return Ie.run(c,async N=>{const D=()=>N()&&z.current===m&&ot()===b;try{const H=a.listDirectory?(await a.listDirectory(c)).entries:await Bl.listLocalDirectory(c);if(!D())return;const we=wi(c,H);Xe.current=new Set(Xe.current),Xe.current.add(c),xn(B=>{if(!B[c])return B;const he={...B};return delete he[c],he}),Ws(B=>B[c]&&Uc(B[c],we)?B:{...B,[c]:we})}catch(H){if(!D())return;const we=H instanceof Error?H.message:String(H??"");if(we==="Directory not found"&&l&&c!==l){zr(l,c),xn(B=>{if(!B[c])return B;const he={...B};return delete he[c],he});return}console.error("Failed to load files directory:",H),xn(B=>({...B,[c]:we}))}},o)},[Ie,a,wi,zr,l,T]),ls=i.useCallback(async()=>{l&&(Xe.current=new Set,Ie.clear(),xn({}),Ws(n=>Object.keys(n).length===0?n:{}),await Oe(l))},[Ie,Oe,l]),He=i.useCallback(async n=>{if(!n){await ls();return}const o=te(n);Xe.current=new Set(Xe.current),Xe.current.delete(o),await Oe(o,!0)},[Oe,ls]),{canUpload:bi,uploadingDirectory:$o,pickFiles:yi,uploadElements:_o}=jc({root:l,refreshDirectory:He}),cs=$o!==null,ji=i.useRef(""),Ci=i.useRef("");i.useEffect(()=>{if(!l)return;const n=E,o=ji.current!==L,c=Ci.current!==n;!o&&!c||(o&&(ji.current=L,Yt.current+=1,Dt.current=null,je(""),Ne(null),Ye(""),ve(null),Y(!1)),c&&(Ci.current=n,Xe.current=new Set,Ie.clear(),xn({}),Ws(m=>Object.keys(m).length===0?m:{}),Oe(l)))},[Ie,L,Oe,l,E]),i.useEffect(()=>{if(!T||!a.listDirectory)return;const n=()=>{if(!document.hidden&<.length>0)for(const o of lt)Ie.has(o)||He(o)};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[Ie,lt,a.listDirectory,He,T]);const Si=i.useRef(!1);i.useEffect(()=>{const n=T&&!Si.current;if(Si.current=T,!(!T||!l)&&(Oe(l),n))for(const o of lt)Ie.has(o)||He(o)},[Ie,lt,Oe,He,l,T]),i.useEffect(()=>{if(!T||!a.listDirectory||lt.length===0)return;const n=setInterval(()=>{if(!document.hidden)for(const o of lt)Ie.has(o)||He(o)},8e3);return()=>clearInterval(n)},[Ie,lt,a.listDirectory,He,T]);const Wo=i.useCallback(async n=>{if(n?.preventDefault(),!It||!At)return;Js(!0);const o=()=>{Ys(null)},c=b=>{X.error(b)},m=()=>{Js(!1)};if(At==="createFile"){if(!Et.trim()){c(t("sidebarFilesTree.toast.filenameRequired")),m();return}if(!a.writeFile){c(t("sidebarFilesTree.toast.writeNotSupported")),m();return}const b=It.path,N=b?`${b}/`:"",D=te(`${N}${Et.trim()}`);await a.writeFile(D,"").then(async H=>{H.success&&(X.success(t("sidebarFilesTree.toast.fileCreated")),await He(b)),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(m);return}if(At==="createFolder"){if(!Et.trim()){c(t("sidebarFilesTree.toast.folderNameRequired")),m();return}const b=It.path,N=b?`${b}/`:"",D=te(`${N}${Et.trim()}`);await a.createDirectory(D).then(async H=>{H.success&&(X.success(t("sidebarFilesTree.toast.folderCreated")),await He(b)),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(m);return}if(At==="rename"){if(!Et.trim()){c(t("sidebarFilesTree.toast.nameRequired")),m();return}if(!a.rename){c(t("sidebarFilesTree.toast.renameNotSupported")),m();return}const b=It.path,N=b.split("/").slice(0,-1).join("/"),D=N?`${N}/`:"",H=te(`${D}${Et.trim()}`);await a.rename(b,H).then(async we=>{we.success&&(X.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await He(N),l&&St(l,b),(u?.path===b||u?.path.startsWith(`${b}/`))&&(l&&Te(l,null),je(""),Ne(null),Ye(""),ve(null),g&&Y(!1))),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(m);return}if(At==="delete"){if(!a.delete){c(t("sidebarFilesTree.toast.deleteNotSupported")),m();return}const b=It.path,N=b.split("/").slice(0,-1).join("/");await a.delete(b).then(async D=>{D.success&&(X.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await He(N),l&&St(l,b),(u?.path===b||u?.path.startsWith(`${b}/`))&&(l&&Te(l,null),je(""),Ne(null),Ye(""),ve(null),g&&Y(!1))),o()}).catch(()=>c(t("sidebarFilesTree.toast.operationFailed"))).finally(m);return}m()},[At,It,Et,a,He,g,St,l,u?.path,Te,t]);i.useEffect(()=>{if(!j){Yn([]),Jn(!1);return}const n=ee.trim();if(!n){Yn([]),Jn(!1);return}let o=!1;return Jn(!0),P(j,n,150,{includeHidden:k,respectGitignore:!y,type:"file"}).then(c=>{if(o)return;const b=c.filter(N=>y||!dd(N.path)).map(N=>({name:N.name,path:te(N.path),type:"file",extension:N.extension,relativePath:N.relativePath}));Yn(b)}).catch(()=>{o||Yn([])}).finally(()=>{o||Jn(!1)}),()=>{o=!0}},[j,ee,P,k,y]);const us=i.useCallback(async(n,o)=>{const c=ct(n);if(a.readFile)return(await a.readFile(n,{...c,directory:l||void 0,...o})).content??"";const m=new URLSearchParams({path:n});c.allowOutsideWorkspace&&m.set("allowOutsideWorkspace","true"),l&&m.set("directory",l);const b=await Ms(`/api/fs/read?${m.toString()}`,{cache:o?.fresh?"no-store":"default",signal:AbortSignal.timeout(3e4)});if(!b.ok){const N=await b.json().catch(()=>({error:b.statusText}));throw new Error(N.error||t("filesView.error.readFileFailed"))}return b.text()},[a,ct,l,t]),mt=i.useCallback(async n=>{if(a.statFile){const o=ct(n),c=await a.statFile(n,{...o,directory:l||void 0});return{path:c.path,size:c.size,mtimeMs:c.mtimeMs}}return null},[a,ct,l]);i.useEffect(()=>{if(!l||!a.statFile||ke.length===0)return;let n=!1;const o=[...ke];return Promise.all(o.map(async c=>{try{const m=ct(c),b=await a.statFile?.(c,{...m,directory:l||void 0});!n&&b&&!b.isFile&&St(l,c)}catch(m){!n&&Ia(m)&&St(l,c)}})),()=>{n=!0}},[a,ke,St,ct,l]);const Ke=ie!==U||bn,Tt=i.useCallback((n,o=!0)=>{const{content:c,lineEnding:m}=ju(n);return o&&Rr(gt.current)&&_n(b=>b+1),Ks.current=n,qs.current+=1,go(m),je(c),Rt.current=c,wn.current=c,Ce(c),c},[]),xt=i.useCallback(async()=>{if(!u||!a.writeFile)return X.error(t("filesView.toast.savingNotSupported")),!1;const n=(Dn(u.path)||Lt)&&!yn.current;if(!bu({selectedFilePath:u.path,loadedFilePath:ce,fileLoading:Me,isDirty:Ke,draftContent:ie,fileContent:U,isNonEditableBinary:n}))return n?console.warn(`[saveDraft] refusing to save binary file "${u.path}".`):ie===""&&U!==""&&ce!==u.path&&console.warn(`[saveDraft] refusing to save empty draft for "${u.path}" (${U.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;Us(!0);try{const o=bn?Xt.current:null;bn&&!o&&dt(!1);const c=o?await o.getContent("save"):Cr;if(!c.ok)return X.error(c.message),!1;const m=c.snapshot;if(m&&"bytes"in m){if(!a.uploadFile)return X.error(t("filesView.toast.savingNotSupported")),!1;if(Je.current=null,!(await a.uploadFile(u.path,new Blob([m.bytes]),{overwrite:!0}))?.success)return X.error(t("filesView.toast.writeFileFailed")),!1;Xt.current?.markSaved(m.signature)}else{const b=Cu(m?m.content:ie,Wr);if(!(await a.writeFile(u.path,b))?.success)return X.error(t("filesView.toast.writeFileFailed")),!1;m?(Tt(b,!1),Xt.current?.markSaved(m.signature)):(je(ie),Ks.current=b,qs.current+=1)}if(l&&An(u.path,l)){const b=Ps(l,u.path);b&&oc.requestGitRefresh({directory:l,paths:[b]})}if(l&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(te(u.path))){const b=lc.getState().projects.find(N=>te(N.path)===te(l));if(b)try{await Hc(b.id)}catch{X.error(t("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return u?.path&&Ln(u.path)&&(Rt.current=ie,wn.current=ie),mt(u.path).then(b=>{b&&(Je.current=b)}).catch(()=>{}),!0}catch(o){return X.error(o instanceof Error?o.message:t("filesView.toast.saveFailed")),!1}finally{Us(!1)}},[Tt,Lt,ie,bn,U,Me,a,Ke,Wr,ce,mt,l,u,t]);Hr.current=xt,i.useEffect(()=>{Ve||(Jt("idle"),ut.current&&(clearTimeout(ut.current),ut.current=null))},[Ve]);const ds=1500;i.useEffect(()=>{const n=!!(u&&a.writeFile),o=!!(u?.path&&(Dn(u.path)||Lt))&&!yn.current;if(!wu({autoSaveEnabled:Ve,isDirty:Ke,canWrite:n,isSaving:Gt,fileLoading:Me,selectedFilePath:u?.path,loadedFilePath:ce,isNonEditableBinary:o}))return;const c=m=>{ut.current=setTimeout(()=>{const b=Date.now()-Xr.current;if(b<ds){c(ds-b);return}xt().then(N=>{N&&(Jt("saved"),setTimeout(()=>Jt("idle"),2e3))})},m)};return c(ds),()=>{ut.current&&(clearTimeout(ut.current),ut.current=null)}},[Ve,Lt,ie,Me,Ke,ce,u,a.writeFile,Gt,xt]),i.useEffect(()=>{Jt("idle")},[u?.path]);const Ni=i.useCallback(()=>{ut.current&&(clearTimeout(ut.current),ut.current=null),Gt||xt().then(n=>{n&&(Jt("saved"),setTimeout(()=>Jt("idle"),2e3))})},[Gt,xt]);cc({save_file:n=>{if(!(n.target instanceof Node)||!es.current?.contains(n.target)&&!Gr.current?.contains(n.target))return!1;Ni()},find_in_file:n=>{if(!(n.target instanceof Node))return!1;if(et&&Ge()==="preview"){if(g||!(A?rs.current:ns.current)?.contains(n.target))return!1;ts(!0),ti(c=>c+1);return}if(!es.current?.contains(n.target))return!1;Fe(!0)}});const Fi=i.useCallback(async n=>{const o=Yt.current+1;Yt.current=o;const c=ot(),m=I.current,b=()=>{if(!l||ot()!==c||I.current!==m)return!1;const B=tt.getState().byRoot[l],he=B?.selectedPath??B?.openPaths[0]??null;return Yt.current===o&&he===n.path};Ne(null),Ye(""),ve(null),qr(!1),Nt(!0);const N=xr(n.path),D=wr(n.path),H=va(n.path),we=Dn(n.path);if(g&&Y(!0),p.isDesktop&&N&&!D){je(""),Ce("");return}if(!p.isDesktop&&N&&!D){je(""),Ce(""),ve(n.path),Nt(!1);return}if(H){je(""),Ce(""),ve(n.path),Nt(!1);return}if(we){je(""),Ce(""),ve(n.path),Nt(!1);return}await us(n.path).then(B=>{if(!b())return;if(xa(B)){qr(!0),je(""),Ce(""),ve(n.path);return}const he=Tt(B),Ot=Fr(n.path)||ks(n.path)||Oa(n.path)||Ln(n.path)||wr(n.path)||wa(n.path)||ba(n.path)||Rr(n.path);de(Ot?"edit":Su(he,Wn.current[n.path])),ve(n.path),mt(n.path).then(dn=>{dn&&b()&&(Je.current=dn)}).catch(()=>{})}).catch(B=>{if(b()){if(fd(B)){if(Nt(!1),l&&Te(l,null),Ne(null),je(""),Ce(""),ve(null),Je.current=null,K.trim().length>0&&Q(""),g&&Y(!1),l){const Ot=[...za(n.path,l),n.path];Ot.length>0&&qn(l,Ot);for(const dn of Ot)Xe.current.has(dn)||Oe(dn)}return}if(Ia(B)){l&&St(l,n.path),je(""),Ce(""),Ne(null),Je.current=null,g&&Y(!1);return}je(""),Ce(""),Ne(B instanceof Error?B.message:t("filesView.error.readFileFailed")),Je.current=null}}).finally(()=>{b()&&Nt(!1)})},[Tt,qn,g,Oe,us,mt,St,l,p.isDesktop,K,Te,t]),fs=i.useCallback(async(n,o)=>{if(!e||!l)return;const c=za(n,l),m=o?[...c,n]:c;if(m.length>0&&qn(l,m),!T)return;const b=m.map(N=>{if(!Xe.current.has(N))return Oe(N)}).filter(Boolean);await Promise.all(b)},[qn,Oe,l,T,e]),Ri=i.useCallback((n,o)=>{const c=o.findIndex(m=>m.path===n);return c===-1||o.length<=1?null:o[c+1]??o[c-1]??null},[]),Be=i.useCallback(async n=>{if(Nn.current)Nn.current=!1;else if(Ke){Cn(!0),Zt.current=n;return}l&&(Te(l,n.path),fs(n.path,!1)),Ne(null),Ye(""),je(""),Rt.current="",wn.current="",dt(!1),Ce(""),ve(null),g&&Y(!0)},[fs,Ke,g,l,Te]);i.useEffect(()=>{u?.path&&fs(u.path,!1)},[fs,u?.path]),i.useEffect(()=>{if(!e)return;if(!u){Yt.current+=1,Dt.current=null,Nt(!1);return}if(ce===u.path||Dt.current===u.path)return;const n=u.path;Dt.current=n,Fi(u).finally(()=>{Dt.current===n&&(Dt.current=null)})},[jn,Fi,ce,u,e]);const ms=i.useRef(Ke);ms.current=Ke,i.useEffect(()=>Cc(({runtimeKey:n,paths:o})=>{const c=u?.path;n!==ot()||!c||ms.current||!o.includes(te(c))||(Yt.current+=1,Dt.current=null,Je.current=null,Ye(""),Ne(null),ve(null),xo(m=>m+1))}),[u?.path]),i.useEffect(()=>{if(!e||!u?.path||ce!==u.path)return;const n=u.path,o=ot(),c=I.current,m=()=>ms.current||Ln(n)&&Rt.current!==wn.current,b=!Dn(n)&&!xr(n)&&!Lt?hu({readContent:()=>us(n,{fresh:!0}),getLoadedContent:()=>Ks.current,getLoadedRevision:()=>qs.current,isDirty:m,applyContent:B=>{if(!(N||ot()!==o||I.current!==c)){if(xa(B)){ve(null);return}Tt(B)}}}):null;let N=!1,D=!1;const H=()=>{document.hidden||D||(D=!0,mt(n).then(async B=>{if(N||ot()!==o||I.current!==c||!B)return;const he=Je.current;if(!he||he.path!==n){Je.current=B;return}if(gu(he,B)){if(b&&B.size<=md){await b.poll()&&!N&&(Je.current=B);return}ms.current||(Je.current=B,ve(null))}}).catch(()=>{}).finally(()=>{D=!1}))};H();const we=window.setInterval(H,2e3);return()=>{N=!0,b?.dispose(),window.clearInterval(we)}},[Tt,Lt,ce,us,mt,u?.path,e]);const Uo=i.useCallback(()=>{const n=Zt.current,o=Sn.current;if(Zt.current=null,Sn.current=null,Nn.current=!0,Cn(!1),dt(!1),_n(c=>c+1),Ce(U),o){l&&Ht(l,o),u?.path===o&&(n?Be(n):(l&&Te(l,null),je(""),Ne(null),Ye(""),ve(null),g&&Y(!1)));return}if(n){Be(n);return}},[U,Be,g,Ht,l,u?.path,Te]),Ho=i.useCallback(async()=>{const n=Zt.current,o=Sn.current;if(!await xt()){Nn.current=!1;return}if(Zt.current=null,Sn.current=null,Nn.current=!0,Cn(!1),o){l&&Ht(l,o),u?.path===o&&(n?await Be(n):(l&&Te(l,null),je(""),Ne(null),Ye(""),ve(null),g&&Y(!1)));return}if(n){await Be(n);return}},[Be,g,Ht,l,xt,u?.path,Te]),Ei=i.useCallback(n=>{const o=u?.path===n,c=Ri(n,qt);if(o&&Ke){Cn(!0),Zt.current=c,Sn.current=n;return}if(l&&Ht(l,n),!!o){if(c){Be(c);return}l&&Te(l,null),je(""),Ne(null),Ye(""),ve(null),g&&Y(!1)}},[Ri,Be,Ke,g,qt,Ht,l,u?.path,Te]),ki=i.useMemo(()=>new Set(ke),[ke]),hs=i.useMemo(()=>Kc(S?O?.files??[]:[]),[O?.files,S]),Ko=i.useCallback(n=>{if(ki.has(n))return"open";const o=n.startsWith(l+"/")?n.slice(l.length+1):n;return hs.statusByPath.get(o)??null},[ki,hs,l]),qo=i.useCallback(n=>{if(!O?.files)return null;const o=n.startsWith(l+"/")?n.slice(l.length+1):n;return hs.badgeByDir.get(o)??null},[O,hs,l]),Go=i.useCallback(async n=>{const o=te(n);l&&(Ar(l,o),Xe.current.has(o)||await Oe(o))},[Oe,l,Ar]),Xo=i.useMemo(()=>({canRename:ri,canCreateFile:ni,canCreateFolder:si,canDelete:ii,canReveal:ai}),[ri,ni,si,ii,ai]);function Ti(n,o){const c=$r[n]??[];return c.map((m,b)=>{const N=m.type==="directory",D=N&&co.has(m.path),H=u?.path===m.path,we=b===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"}),we&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(hd,{node:m,root:l,isExpanded:D,isActive:H,isMobile:g,isBrowserClient:F,alwaysShowActions:C,status:N?void 0:Ko(m.path),badge:N?qo(m.path):void 0,permissions:Xo,downloadFile:a.downloadFile,contextMenuPath:Fo,setContextMenuPath:Ro,rightClickMenuPath:Eo,setRightClickMenuPath:ko,onSelect:Be,onToggle:Go,onRevealPath:zo,onOpenDialog:Qs,canUpload:bi&&!cs,onPickFiles:yi}),N&&D&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Xn[m.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:Xn[m.path],children:Xn[m.path]}),s.jsxs($,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{He(m.path)},children:[s.jsx(M,{name:"refresh",className:"size-3.5"}),t("filesView.tree.actions.refreshTitle")]})]}):null,Ti(m.path,o+1)]})]},m.path)})}const qe=!!(u?.path&&xr(u.path)),Qe=!!(u?.path&&wr(u.path)),Mi=Qe&&ge==="edit",Mt=!!(u?.path&&va(u.path)),Vi=!!(u?.path&&uc(u.path)),nr=Vi||!!(u?.path&&dc(u.path)),sr=!!(u?.path&&fc(u.path)),ps=!!(u?.path&&(Dn(u.path)||Lt)),nn=ps&&!qe&&!Mt&&!nr&&!sr,Pi=ps||qe&&!Mi,Di=i.useMemo(()=>te(ft?.path??""),[ft?.path]),sn=!!(ft&&Di&&Ae&&Ae===Di&&!Me&&!rt&&!Pi),wt=i.useMemo(()=>Ps(l,Ae),[Ae,l]),Yo=!!(u&&(!qe||Qe)&&!Mt&&!nn&&U.length>0),Jo=!!(u&&wt.length>0),at=!!(u&&!Gn&&!ps&&(!qe||Qe)&&a.writeFile),rr=!!(u&&!ps&&(!qe||Qe)),ir=Mu(u?.path),Pe=ir&&(rr||ir.editor.content==="binary")?ir:null,bt=Pe!==null,Tn=Pe?.editor.content==="binary";yn.current=Tn;const et=!bt&&!!(u?.path&&Fr(u.path)),rn=!bt&&!!(u?.path&&Oa(u.path)),an=!bt&&!!(u?.path&&ks(u.path)),Mn=!bt&&!!(u?.path&&Ln(u.path)),on=!bt&&!!(u?.path&&wa(u.path)),ln=!bt&&!!(u?.path&&ba(u.path)),cn=bt,Vn=bt&&(Tn?We===null||We<=Er:ie.length<=Er),Zo=Vr(n=>n.status),Qo=!bt&&rr&&Zo!=="unsupported"&&!!(u?.path&&mc(u.path)),gs=rr&&!et&&!Mn&&!cn&&!(an&&le==="preview")&&!(Qe&&ge==="preview")&&!(on&&ye==="preview")&&!(ln&&st==="table"),el=et&&_e==="edit"||an&&le==="edit"||cn&&(pe==="edit"||!Vn)||Qe&&ge==="edit"||on&&ye==="edit"||ln&&st==="text"||rn&&W==="text"||!et&&!an&&!rn&&!cn&&!Qe&&!on&&!ln&&ne==="edit",vs=i.useMemo(()=>Ae?hc(Ae):null,[Ae]),[Li,ar]=i.useState(null);i.useEffect(()=>{let n=!1;const o=u?.path;if(!o||vs){ar(null);return}return ar(null),pc(o).then(c=>{n||ar(c)}),()=>{n=!0}},[u?.path,vs]),i.useEffect(()=>{!at&&ne==="edit"&&de("view")},[at,ne]);const or="openchamber:files:md-viewer-mode",lr="openchamber:files:html-viewer-mode",cr="openchamber:files:json-viewer-mode";i.useEffect(()=>{const n=u?.path;if(!n)return;de(Wn.current[n]??"edit");let o=En?"preview":"edit";try{const b=localStorage.getItem(or);(b==="preview"||b==="edit")&&(o=b)}catch{}G(As.current[n]??o);let c=En?"preview":"edit";try{const b=localStorage.getItem(lr);(b==="preview"||b==="edit")&&(c=b)}catch{}Se(Is.current[n]??c),fe(Os.current[n]??(En?"preview":"edit")),be(vn.current[n]??"preview"),pt(Pr.current[n]??"preview"),Ee(Dr.current[n]??"preview"),me(Lr.current[n]??"table");let m=En?"tree":"text";try{const b=localStorage.getItem(cr);(b==="tree"||b==="text")&&(m=b)}catch{}oe(m)},[u?.path,En]);const tl=i.useCallback(n=>{const o=u?.path;o&&(Wn.current[o]=n),de(n)},[u?.path]),nl=i.useCallback(n=>{const o=u?.path;o&&(As.current[o]=n),G(n);try{localStorage.setItem(or,n)}catch{}},[u?.path]),Ge=i.useCallback(()=>_e,[_e]),sl=i.useCallback(n=>{const o=u?.path;o&&(Pr.current[o]=n),pt(n)},[u?.path]),rl=i.useCallback(n=>{const o=u?.path;o&&(Dr.current[o]=n),Ee(n)},[u?.path]),il=i.useCallback(n=>{const o=u?.path;o&&(Lr.current[o]=n),me(n)},[u?.path]);i.useEffect(()=>{const n=u?.path;if($n(null),!n||ce!==n)return;let o=!1;return mt(n).then(c=>{!o&&c&&$n(c.size)}).catch(()=>{}),()=>{o=!0}},[jn,ce,mt,u?.path]);const zi=u&&et&&Ge()==="preview"&&!Me?u.path:null;i.useEffect(()=>{!zi||g||ss()},[ss,A,g,zi]);const al=i.useCallback(n=>{oe(n);try{localStorage.setItem(cr,n)}catch{}},[]),ol=i.useCallback(n=>{const o=u?.path;o&&(Is.current[o]=n),Se(n);try{localStorage.setItem(lr,n)}catch{}},[u?.path]),ll=i.useCallback(n=>{const o=u?.path;if(o&&(Os.current[o]=n),Ue.current&&(clearTimeout(Ue.current),Ue.current=null),vt.current!==null&&(cancelAnimationFrame(vt.current),vt.current=null),n==="edit")Ce(Rt.current||U),fe(n);else{Rt.current=ie;const c=o;fe("edit"),vt.current=requestAnimationFrame(()=>{vt.current=requestAnimationFrame(()=>{vt.current=null,!(l&&c&&tt.getState().byRoot[l]?.selectedPath!==c)&&(oo(m=>m+1),fe("preview"))})});return}},[ie,U,l,u?.path]),cl=i.useCallback(n=>{const o=u?.path,c=()=>{o&&(vn.current[o]=n)};if(n==="edit"){if(!Hs.current){c(),dt(!1),be(n);return}Promise.resolve(Xt.current?.getContent("handoff")??Cr).then(b=>{if(gt.current===o){if(!b.ok){X.error(b.message);return}c(),Ce(b.snapshot&&"content"in b.snapshot?b.snapshot.content:U),dt(!1),be(n)}});return}if(!Vn){Pe&&X.error(t("filesView.fileEditor.tooLarge",{editor:Pe.editor.title}));return}c(),dt(!1);const m=o;Pt.current!==null&&cancelAnimationFrame(Pt.current),Pt.current=requestAnimationFrame(()=>{Pt.current=null,!(l&&m&&tt.getState().byRoot[l]?.selectedPath!==m)&&(_n(b=>b+1),be("preview"))})},[Vn,U,Pe,l,u?.path,t]),ur=i.useCallback(async(n,o)=>{if(!a.writeFile||o===wn.current)return!1;if(!(await a.writeFile(n,o))?.success)return X.error(t("filesView.toast.writeFileFailed")),!1;Tt(o);const m=await mt(n).catch(()=>null);return m&&(Je.current=m),!0},[Tt,a,mt,t]);i.useEffect(()=>()=>{Ue.current&&(clearTimeout(Ue.current),Ue.current=null),vt.current!==null&&(cancelAnimationFrame(vt.current),vt.current=null)},[re,u?.path]);const ul=i.useCallback(n=>{if(Rt.current=n,!Ve||!u?.path||re!=="preview"||!a.writeFile)return;Ue.current&&clearTimeout(Ue.current);const o=u.path;Ue.current=setTimeout(()=>{Ue.current=null,ur(o,n).then(c=>{c&&(Qn(!0),setTimeout(()=>Qn(!1),1500))}).catch(c=>{X.error(c instanceof Error?c.message:t("filesView.toast.saveFailed"))})},ds)},[Ve,re,a.writeFile,ur,u?.path,t]),dl=i.useMemo(()=>Mn&&(Rt.current||ie)||U,[ie,U,Mn]),fl=i.useCallback(()=>{const n=gt.current;n&&(vn.current[n]="edit"),dt(!1),be("edit"),Pe&&X.error(t("filesView.fileEditor.unsupported",{editor:Pe.editor.title}))},[Pe,t]);i.useEffect(()=>()=>{Pt.current!==null&&(cancelAnimationFrame(Pt.current),Pt.current=null)},[pe,u?.path]);const Ai=i.useCallback(()=>le,[le]);i.useEffect(()=>{const n=c=>{const m=c?"preview":"edit",b=c?"tree":"text";for(const N of ke)Wn.current[N]="edit",Fr(N)&&(As.current[N]=m),ks(N)&&(Is.current[N]=m),Ln(N)&&(Os.current[N]=m),Rr(N)&&(vn.current[N]=m);de("edit"),G(m),Se(m),fe(m),be(m),oe(b);try{localStorage.setItem(or,m),localStorage.setItem(lr,m),localStorage.setItem(cr,b)}catch{}},o=c=>{const m=!!c.detail?.enabled;n(m)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",o),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",o)}},[ke]),i.useEffect(()=>{if(!ft||!l)return;const n=()=>{typeof window>"u"||Qt.current===null&&(Qt.current=window.requestAnimationFrame(()=>{Qt.current=null,Xs(jt=>jt+1)}))},o=(jt,Bt)=>{if(jt.state.doc.length!==Bt.length)return!1;if(Bt.length===0)return!0;const gr=Math.min(128,Bt.length);if(jt.state.sliceDoc(0,gr)!==Bt.slice(0,gr))return!1;const da=Math.max(0,Bt.length-gr);return jt.state.sliceDoc(da,Bt.length)===Bt.slice(da)},c=te(ft.path);if(!c){is(null),zt.current={key:"",attempts:0};return}const m=`${c}:${ft.line}:${ft.column??1}`;if(zt.current.key!==m&&(zt.current={key:m,attempts:0}),u?.path!==c){if(Gs)return;Be(Kt(c));return}if(Me||ce!==c)return;if(rt||qe||Mt||nn){is(null),zt.current={key:"",attempts:0};return}if(!at)return;if(ne!=="edit"){de("edit");return}const b=Ze.current;if(!b){n();return}if(!o(b,ie)){n();return}const N=Math.max(1,Math.min(ft.line,b.state.doc.lines)),D=b.state.doc.line(N),H=Math.max(1,ft.column||1),we=Math.max(0,D.to-D.from),B=Math.min(we,H-1),he=D.from+B;if(!(b.state.selection.main.head===he)||zt.current.attempts===0){zt.current.attempts+=1,b.dispatch({selection:{anchor:he},effects:Ut.scrollIntoView(he,{y:"center"})}),b.focus(),n();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const jt=Ze.current;jt&&(jt.dispatch({selection:{anchor:he},effects:Ut.scrollIntoView(he,{y:"center"})}),jt.focus())}),is(null),zt.current={key:"",attempts:0}},[at,Gs,ie,Co,rt,Me,qe,Mt,nn,ce,Be,ft,l,u?.path,is,ne,Kt]),i.useEffect(()=>{if(!er||!l)return;const n=te(er);if(!n){tr(null);return}u?.path===n&&(Me||ce!==n||(!rt&&!qe&&!Mt&&!nn&&at&&ne==="edit"&&Ze.current?.focus(),tr(null)))},[at,rt,Me,qe,Mt,nn,ce,er,l,u?.path,tr,ne]);const un=i.useCallback(n=>{if(!g||!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 m=window.visualViewport;if(!m)return;const b=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,b-(m.offsetTop+m.height))<=0)return;const D=c?c.getBoundingClientRect():n.coordsAtPos(n.state.selection.main.head);if(!D)return;const H=Math.round(m.offsetTop+m.height),B=D.bottom+20-H;B<=0||(n.scrollDOM.scrollTop+=B)},[g]);i.useEffect(()=>{if(!g||typeof window>"u")return;const n=()=>{window.requestAnimationFrame(()=>{un(Ze.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)}},[g,un]),gc("open_go_to_line",n=>{if(!at||ne!=="edit"||g)return!1;const o=n.target;if(o?.closest('[role="dialog"]')||!(o instanceof Node)||!es.current?.contains(o))return!1;const c=!!o?.closest(".cm-editor");if(!!o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!c)return!1;Zs(!0)});const xs=ht(n=>n.editorFontSize),Ii=i.useMemo(()=>{if(!u?.path)return[ya(d,{fontSize:xs})];const n=vr(u.path),o=[ya(d,n?{syntaxColors:!1,fontSize:xs}:{fontSize:xs})],c=vs??Li;return c&&o.push(c),n&&o.push(Tc({language:n,themeName:d.metadata.id,theme:zc(d)})),se&&o.push(Ut.lineWrapping),g&&o.push(Ut.updateListener.of(m=>{m.view.hasFocus&&(m.selectionSet||m.focusChanged||m.viewportChanged||m.geometryChanged)&&window.requestAnimationFrame(()=>{un(m.view)})})),o},[d,u?.path,vs,Li,se,g,un,xs]),Oi=i.useMemo(()=>({light:Un.metadata.id,dark:Hn.metadata.id}),[Un.metadata.id,Hn.metadata.id]),Bi=Mt||nr||sr,Pn=u?.path&&Bi?`${u.path}|${$s.allowOutsideWorkspace?"outside":"workspace"}|${jn}`:"",ws=u?.path&&an&&le==="preview"&&!p.isVSCode?`${u.path}|${jn}`:"",$i=t("filesView.error.readFileFailed"),{readyKey:_i,nonce:ml}=$a(ws,Ne,$i),{readyKey:Wi,nonce:bs}=$a(Pn,Ne,$i),hl=!!(ws&&_i!==ws),dr=!!(Pn&&Wi!==Pn),pl=u?.path&&qe?Qe?`data:${vc(u.path)};utf8,${encodeURIComponent(U)}`:po:"",ys=u?.path&&Bi&&Pn&&Wi===Pn?ma().authenticatedAsset($l("/api/fs/raw",l),{path:u.path,allowOutsideWorkspace:$s.allowOutsideWorkspace?"true":void 0,directory:l||void 0}):"",gl=i.useCallback(n=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:ys,className:"h-full w-full border-0",title:n.name},bs)}),[ys,bs]),Ui=u&&a.downloadFile?s.jsxs($,{type:"button",variant:"outline",size:"sm",onClick:()=>{const n=a.downloadFile;!n||!u||n(u.path).catch(o=>{console.error("Download failed:",o),X.error(t("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(M,{name:"download",className:"mr-2 size-4"}),t("filesView.editor.saveFile")]}):null,js=u&&!Me&&!dr&&!rt?(n=>qe&&!Mi?s.jsx(Hu,{src:pl,name:n.name,sizeBytes:We}):Mt?gl(n):nr?s.jsx(Ku,{kind:Vi?"video":"audio",src:ys,name:n.name,sizeBytes:We,download:Ui},bs):sr?s.jsx(Iu,{src:ys,name:n.name,sizeBytes:We},bs):nn?s.jsx(Lu,{name:n.name,path:n.path,sizeBytes:We,download:Ui}):ln&&st==="table"?s.jsx(Yu,{path:n.path,content:U,sizeBytes:We}):on&&ye==="preview"?s.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:s.jsx(Ns,{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(yr,{content:`\`\`\`mermaid
|
|
16
|
-
${U}
|
|
17
|
-
\`\`\``,className:"markdown-mermaid-fullscreen h-full",enableFileReferences:!1,allowMermaidWheelEvents:!0})})}):null)(u):null;i.useEffect(()=>{let n=!1,o="";return(async()=>{if(!u?.path||!qe||Qe){Ye("");return}Ne(null);const m=ct(u.path);if(n)return;await(a.readFileBinary?a.readFileBinary(u.path,m).then(N=>N.dataUrl):(async()=>{const N=await Ms("/api/fs/raw",{signal:AbortSignal.timeout(3e4),query:{path:u.path,allowOutsideWorkspace:m.allowOutsideWorkspace?"true":void 0,directory:l||void 0}});if(!N.ok)throw new Error(t("filesView.error.readFileFailed"));const D=await N.blob();return o=URL.createObjectURL(D),n?(URL.revokeObjectURL(o),o="",""):o})()).then(N=>{n||(Ye(N),ve(u.path))}).catch(N=>{n||(Ye(""),Ne(N instanceof Error?N.message:t("filesView.error.readFileFailed")),ve(null))}).finally(()=>{n||Nt(!1)})})(),()=>{n=!0,o&&URL.revokeObjectURL(o)}},[jn,a,qe,Qe,ct,l,u?.path,$s,t]);const vl=i.useCallback(()=>Ys(null),[]),xl=i.useMemo(()=>Yc({drafts:di,editingDraftId:os,commentText:as,onTextChange:fi,selection:Z,isDragging:li,fileLabel:u?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:n=>({start:n.startLine,end:n.endLine}),onSave:xi,onCancel:()=>{it(null),kn()},onEdit:n=>{gi(n),it({start:n.startLine,end:n.endLine})},onDelete:vi}),[kn,as,vi,os,di,xi,li,Z,u?.path,fi,gi]),Hi=Ra(),Ki=Ra(),Cs=!Me&&!rt&&ce===Ae,fr=i.useMemo(()=>!!Ae&&Eu({hasCanvas:cn,viewMode:pe,previewReady:Cs,mountable:Vn}),[Vn,pe,cn,Cs,Ae]),Ss=Cs&&gs&&ne==="view"&&!(rn&&W==="tree"),qi=Cs&&et&&Ge()==="preview",{setScroller:Gi,restore:wl}=Rs(Ss?`${Ft}:code`:null),{setScroller:Xi,restore:bl}=Rs(Ss?`${Ft}:code:fullscreen`:null),{setScroller:Yi}=Rs(qi?`${Ft}:markdown`:null),{setScroller:Ji}=Rs(qi?`${Ft}:markdown:fullscreen`:null),{setScroller:Zi}=Hi,{setScroller:Qi}=Ki,yl=i.useCallback(n=>{Zi(n),Gi(n)},[Zi,Gi]),jl=i.useCallback(n=>{Qi(n),Xi(n)},[Qi,Xi]),[Cl,Sl]=i.useState(null),[Nl,Fl]=i.useState(null),Rl=i.useCallback(n=>{ui.current=n,ns.current=n,Sl(n),Yi(n)},[Yi]),El=i.useCallback(n=>{rs.current=n,Fl(n),Ji(n)},[Ji]),ea=i.useCallback(n=>{l&&ht.getState().openContextFile(l,n)},[l]),ta=et&&_e==="preview"&&!Me,na=d.metadata.variant==="light"?"light":"dark";La({container:Cl,filePath:u?.path??null,workspaceRoot:l||null,onOpenFile:ea,enabled:ta,colorScheme:na}),La({container:Nl,filePath:u?.path??null,workspaceRoot:l||null,onOpenFile:ea,enabled:ta,colorScheme:na});const mr=Sc("unified"),yt=ie.length>Za,hr=i.useMemo(()=>yt&&Ss?Nu(ie):void 0,[Ss,ie,yt]),sa=i.useCallback((n,o,c,m)=>{const b={name:n.name,contents:o,lang:vr(n.path)||void 0},N=D=>s.jsx(Lc,{file:yt&&hr?{...b,cacheKey:`${n.path}:${hr}`}:b,options:{disableFileHeader:!0,overflow:se?"wrap":"scroll",theme:Oi,themeType:d.metadata.variant==="dark"?"dark":"light",onPostRender:m},className:yt?"block w-full":"block h-full w-full",style:yt?void 0:{height:"100%"}},D);return yt?s.jsx("div",{className:"h-full",children:s.jsx(Ac.Provider,{value:c.virtualizer,children:s.jsx(Ic.Provider,{value:mr,children:N(`${n.path}:${mr?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:N(n.path)})},[d.metadata.variant,yt,hr,Oi,mr,se]),ra=({exitFullscreenOnly:n=!1,layout:o="floating"}={})=>{if(!u)return null;const c=o==="docked",m=xc(wc("save_file")),b=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=(D,H)=>s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:H})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:D})]});return s.jsxs("div",{className:b,children:[at&&el&&s.jsxs(s.Fragment,{children:[Gt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(M,{name:"loader-4",className:"size-3.5 animate-spin"}),t("filesView.editor.saving")]}):Ve&&wo==="saved"&&!Ke?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(M,{name:"check",className:"size-3.5"}),t("filesView.editor.saved")]}):Ke?N(t(Ve?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:m}),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>{xt()},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:m}),"aria-label":t("filesView.editor.saveAria",{shortcut:m}),children:s.jsx(M,{name:"save-3",className:"size-4"})})):null,N(t(Ve?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>jo(!Ve),className:q("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(M,{name:"file-check-fill",className:"size-4"}):s.jsx(M,{name:"file-check",className:"size-4"})}))]}),s.jsxs(kr,{onOpenChange:Re,children:[s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(Tr,{asChild:!0,children:s.jsx($,{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(M,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:t("filesView.editor.openInDesktopApp")})]}),s.jsxs(Mr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Po.map(D=>s.jsxs(Vs,{className:"flex items-center gap-2",onClick:()=>{Ao(D)},children:[s.jsx(id,{label:D.label,iconDataUrl:D.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:D.label})]},D.id)),Do?s.jsxs(Vs,{className:"flex items-center gap-2",onClick:()=>{Lo(!0)},children:[s.jsx(M,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("filesView.editor.refreshApps")})]}):null]})]}),!Pi&&s.jsxs(s.Fragment,{children:[N(t(se?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>Le(!se),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",se?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:t(se?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(M,{name:"text-wrap",className:"size-4"})})),ne==="edit"&&s.jsxs(s.Fragment,{children:[N(t("filesView.editor.findInFile"),s.jsx($,{variant:"ghost",size:"sm",onClick:D=>{Fe(!ze),D.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(M,{name:"search",className:"size-4"})})),N(t("filesView.editor.goToLine"),s.jsx($,{variant:"ghost",size:"sm",onClick:D=>{Zs(H=>!H),D.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.goToLine"),children:s.jsx(M,{name:"menu-fold-2",className:"size-4"})})),s.jsx(ou,{open:Vo,onOpenChange:Zs,view:Ze.current,variant:"inline"})]})]}),gs&&at&&!rn&&!an&&!Qe&&!on&&!ln&&s.jsx(fn,{currentMode:ne==="view"?"preview":"edit",onToggle:()=>{tl(ne==="view"?"edit":"view")}}),et&&N(t(Ge()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>nl(Ge()==="preview"?"edit":"preview"),className:q("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",Ge()==="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(Ge()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":t(Ge()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(M,{name:Ge()==="preview"?"eye":"eye-off",className:"size-4"})})),ks(u?.path??"")&&s.jsx(fn,{currentMode:Ai(),onToggle:()=>{ol(Ai()==="preview"?"edit":"preview")}}),Qe&&s.jsx(fn,{currentMode:ge,onToggle:()=>sl(ge==="preview"?"edit":"preview")}),on&&s.jsx(fn,{currentMode:ye,onToggle:()=>rl(ye==="preview"?"edit":"preview")}),ln&&N(t(st==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>il(st==="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(st==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),"aria-label":t(st==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),children:st==="table"?s.jsx(M,{name:"code-sslash",className:"size-4"}):s.jsx(M,{name:"table-2",className:"size-4"})})),et&&Ge()==="preview"&&N(t("filesView.editor.findInFile"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>{ts(!0),ti(D=>D+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(M,{name:"search",className:"size-4"})})),et&&Ge()==="preview"&&Io&&s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx($,{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(Zn?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{Zn?ho():U.trim()&&mo(U)},children:Zn?s.jsx(M,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(M,{name:"volume-up",className:"size-4"})})}),s.jsx(Wt,{sideOffset:8,children:t(Zn?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),cn&&s.jsxs(s.Fragment,{children:[!Tn&&s.jsx(fn,{currentMode:pe,onToggle:()=>cl(pe==="preview"?"edit":"preview")}),pe==="preview"&&s.jsx($,{variant:"ghost",size:"sm",onClick:async()=>{await xt()&&(Kr(!0),setTimeout(()=>Kr(!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:yo?s.jsx(M,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(M,{name:"save-3",className:"size-4"})})]}),Mn&&s.jsxs(s.Fragment,{children:[s.jsx(fn,{currentMode:re,onToggle:()=>ll(re==="preview"?"edit":"preview")}),re==="preview"&&s.jsx($,{variant:"ghost",size:"sm",onClick:async()=>{const D=Ur.current?.getXml();if(Ue.current&&(clearTimeout(Ue.current),Ue.current=null),u?.path&&D){if(!await ur(u.path,D))return;Qn(!0),setTimeout(()=>Qn(!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:bo?s.jsx(M,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(M,{name:"save-3",className:"size-4"})})]}),rn&&N(t(W==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>al(W==="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(W==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:W==="tree"?s.jsx(M,{name:"code-sslash",className:"size-4"}):s.jsx(M,{name:"node-tree",className:"size-4"})})),Yo&&N(t("filesView.editor.copyFileContents"),s.jsx($,{variant:"ghost",size:"sm",onClick:async()=>{(await Ds(U)).ok?(Jr(!0),Fn.current!==null&&window.clearTimeout(Fn.current),Fn.current=window.setTimeout(()=>{Jr(!1)},1200)):X.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:To?s.jsx(M,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(M,{name:"clipboard",className:"size-4"})})),Jo&&N(t("filesView.editor.copyFilePathTitle",{path:wt}),s.jsx($,{variant:"ghost",size:"sm",onClick:async()=>{(await Ds(wt)).ok?(Zr(!0),Rn.current!==null&&window.clearTimeout(Rn.current),Rn.current=window.setTimeout(()=>{Zr(!1)},1200)):X.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:wt}),"aria-label":t("filesView.editor.copyFilePathTitle",{path:wt}),children:Mo?s.jsx(M,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(M,{name:"file-copy-2",className:"size-4"})})),a.downloadFile&&N(t("filesView.editor.saveFile"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>{const D=a.downloadFile;D&&D(u.path).catch(H=>{console.error("Download failed:",H),X.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(M,{name:"download",className:"size-4"})})),n?N(t("filesView.editor.exitFullscreen"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>xe(!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(M,{name:"fullscreen-exit",className:"size-4"})})):!g&&r==="full"&&N(t(A?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx($,{variant:"ghost",size:"sm",onClick:()=>xe(!A),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:t(A?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":t(A?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:A?s.jsx(M,{name:"fullscreen-exit",className:"size-4"}):s.jsx(M,{name:"fullscreen",className:"size-4"})}))]})},ia=i.useRef(null);i.useEffect(()=>{ce&&(yn.current&&ia.current===ce&&_n(n=>n+1),ia.current=ce)},[ce]);const kl=i.useCallback(async()=>{const n=gt.current;if(!n)throw new Error("No file is open.");const o=ct(n),c=await Ms("/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())},[ct,l,t]),aa=i.useCallback(n=>{const o=gt.current;o&&(vn.current[o]="edit"),dt(!1),be("edit"),X.error(n)},[]),oa=r==="full"&&A,Tl=u?`${u.path}:${lo}:${oa?"fullscreen":"docked"}`:"",la=fr&&u&&Pe?s.jsx("div",{ref:Gr,className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ku,{ref:Xt,guestId:Pe.guestId,editorId:Pe.editor.id,title:Pe.editor.title,contentKind:Tn?"binary":"text",path:wt||u.path,content:ie,loadBytes:kl,readOnly:!u||Gn||!a.writeFile||Tn&&!a.uploadFile,onDirtyChange:dt,onEdit:()=>{Xr.current=Date.now()},onSaveRequest:Ni,onUnsupported:fl,onTooLarge:()=>aa(t("filesView.fileEditor.tooLarge",{editor:Pe.editor.title})),onLoadFailed:()=>aa(t("filesView.error.readFileFailed"))},`${Tl}:${Pe.guestId}:${Pe.editor.id}`)}):null,Ml=i.useCallback(()=>{const n=ht.getState();n.requestSettingsJump("integrations","integrations.extensions.excalidraw"),n.setSettingsDialogOpen(!0)},[]),pr=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ua,{open:Gs,onOpenChange:n=>{n||Cn(!0)},children:s.jsxs(Ha,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Ka,{children:[s.jsx(qa,{children:t("filesView.unsaved.title")}),s.jsx(Ga,{children:t("filesView.unsaved.description")})]}),s.jsxs(Xa,{children:[s.jsx($,{variant:"outline",onClick:()=>{Ho()},disabled:Gt,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($,{variant:"destructive",onClick:Uo,children:t("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:q("flex flex-col flex-shrink-0",_&&"border-b border-border/40"),children:[_?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[g&&J&&s.jsx("button",{type:"button",onClick:()=>Y(!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(M,{name:"arrow-left-s",className:"size-5"})}),g?u?s.jsxs(kr,{children:[s.jsx(Tr,{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(zn,{filePath:u.path,extension:u.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Aa,{name:u.name}),s.jsx(M,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Mr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:qt.map(n=>{const o=u?.path===n.path;return s.jsxs(Vs,{onSelect:c=>{if(c.target.closest("[data-close-open-file]")){c.preventDefault();return}o||Be(n)},className:q("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(zn,{filePath:n.path,extension:n.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Aa,{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(),Ei(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(M,{name:"close",className:"size-3.5"})})]},n.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:t("filesView.editor.selectFile")}):qt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ir.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"}),Ir.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:_s,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:qt.map(n=>{const o=u?.path===n.path;return s.jsxs("div",{title:Ps(l,n.path),className:q("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(zn,{filePath:n.path,extension:n.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{o||Be(n)},className:"max-w-[12rem] truncate text-left",children:n.name}),s.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),Ei(n.path)},className:q("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!o&&!C&&"opacity-0 group-hover:opacity-100"),"aria-label":t("filesView.editor.closeFileAria",{name:n.name}),children:s.jsx(M,{name:"close",className:"size-3.5"})})]},n.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:t("filesView.editor.selectFile")})]}):null,u?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:[wt&&!g?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:wt,children:wt}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:ra({layout:"docked"})})]}):null]}),Qo?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(M,{name:"information",className:"size-4 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:t("filesView.excalidraw.installHint")}),s.jsx($,{type:"button",size:"xs",variant:"outline",onClick:Ml,children:t("filesView.excalidraw.installAction")})]}):null,s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(br,{ref:yl,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",yt&&"[overflow-anchor:none]"),children:u?Me||dr?R?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(M,{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}):fr?oa?s.jsx("div",{className:"h-full"}):la:js||(u&&Mn&&re==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(Ru,{ref:Ur,xml:dl,onChange:ul},`${u.path}:${ao}`)}):u&&rn&&W==="tree"?s.jsx(Ns,{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(Dc,{jsonString:U,maxHeight:"100%",initiallyExpandedDepth:2})})}):u&&et&&Ge()==="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:ss,ref:Rl,children:[s.jsx(Ca,{containerRef:ui,filePath:u.path,fileContent:U}),U.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(U.length/1024)})}),s.jsx(Ns,{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(yr,{content:U,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1,allowRawHtml:!0})})]}),!A&&s.jsx(Fa,{containerRef:ns,open:Qr,onOpenChange:ts,focusNonce:ei})]}):u&&an&&le==="preview"?hl?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:!p.isVSCode&&_i===ws?(()=>{const n=u.path.split("/").map(o=>encodeURIComponent(o)).join("/");return ma().authenticatedAsset(`/api/fs/serve${n.startsWith("/")?n:`/${n}`}`)})():void 0,srcDoc:p.isVSCode?(()=>{const n=u.path.substring(0,u.path.lastIndexOf("/")+1);return n?U.replace(/<head([^>]*)>/i,`<head$1><base href="${n}">`):U})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:t("filesView.editor.htmlPreviewTitle")},ml)}):u&&gs&&ne==="view"?sa(u,ie,Hi,wl):s.jsxs("div",{className:q("relative h-full",sn&&"overflow-hidden"),ref:es,children:[s.jsx("div",{className:q("h-full",sn&&"invisible"),children:s.jsx(Ba,{positionKey:Ft,value:ie,onChange:Ce,readOnly:!at,vimMode:ci==="vim",extensions:Ii,className:"h-full",blockWidgets:xl,onViewReady:n=>{Ze.current=n,Xs(o=>o+1),window.requestAnimationFrame(()=>{un(n)})},onViewDestroy:()=>{Ze.current&&(Ze.current=null),Xs(n=>n+1)},enableSearch:!0,searchOpen:ze,onSearchOpenChange:Fe,highlightLines:Z?{start:Math.min(Z.start,Z.end),end:Math.max(Z.start,Z.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(n,o,c)=>{if(!(c instanceof MouseEvent)||c.button!==0)return!1;c.preventDefault();const m=n.state.doc.lineAt(o.from).number;if(Z&&!c.shiftKey&&Math.min(Z.start,Z.end)===m&&Math.max(Z.start,Z.end)===m)return it(null),kn(),en.current=!1,kt.current=null,tn(!1),!0;if(g&&Z&&!c.shiftKey){const b=Math.min(Z.start,Z.end,m),N=Math.max(Z.start,Z.end,m);return it({start:b,end:N}),en.current=!1,kt.current=null,tn(!1),!0}if(en.current=!0,kt.current=m,tn(!0),Z&&c.shiftKey){const b=Math.min(Z.start,m),N=Math.max(Z.end,m);it({start:b,end:N})}else it({start:m,end:m});return!0},mouseover:(n,o,c)=>{if(!(c instanceof MouseEvent)||c.buttons!==1||!en.current||kt.current===null)return!1;const m=n.state.doc.lineAt(o.from).number,b=Math.min(kt.current,m),N=Math.max(kt.current,m);return it({start:b,end:N}),tn(!0),!1},mouseup:()=>(en.current=!1,kt.current=null,tn(!1),!1)}}},Ft)}),sn&&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(M,{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")})})})]}),Vl=!!(l&&$r[l]),ca=l?Xn[l]:null,ua=S?s.jsxs("section",{className:q("flex min-h-0 flex-col overflow-hidden",g?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:q("flex flex-col gap-2 py-2",g?"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(M,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(In,{ref:ae,value:K,onChange:n=>Q(n.target.value),placeholder:t("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),K.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:()=>{Q(""),ae.current?.focus()},children:s.jsx(M,{name:"close",className:"size-4"})})]}),s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($,{variant:"ghost",size:"sm",onClick:()=>Qs("createFile",{path:j,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(M,{name:"file-add",className:"size-4"})})})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.newFileTitle")})]}),s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($,{variant:"ghost",size:"sm",onClick:()=>Qs("createFolder",{path:j,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(M,{name:"folder-add",className:"size-4"})})})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.newFolderTitle")})]}),bi&&s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($,{variant:"ghost",size:"sm",onClick:()=>yi(l),disabled:!l||cs,className:"size-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.uploadFilesTitle"),"aria-label":t("sidebarFilesTree.actions.uploadFilesTitle"),children:s.jsx(M,{name:cs?"loader-4":"upload-2",className:q("size-4",cs&&"animate-spin")})})})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.uploadFilesTitle")})]}),s.jsxs($t,{children:[s.jsx(_t,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx($,{variant:"ghost",size:"sm",onClick:()=>{ls()},className:"size-8 p-0 flex-shrink-0",title:t("filesView.tree.actions.refreshTitle"),"aria-label":t("filesView.tree.actions.refreshTitle"),children:s.jsx(M,{name:"refresh",className:"size-4"})})})}),s.jsx(Wt,{side:"bottom",sideOffset:6,children:t("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(br,{outerClassName:"flex-1 min-h-0",className:q("py-2",g?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:fo?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(M,{name:"loader-4",className:"size-4 animate-spin"}),t("filesView.tree.search.searching")]}):_r.length>0?_r.map(n=>{const o=u?.path===n.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Be(n)},className:q("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:[io(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)}):ca?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:ca}),s.jsxs($,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ls()},children:[s.jsx(M,{name:"refresh",className:"size-3.5"}),t("filesView.tree.actions.refreshTitle")]})]}):Vl?Ti(l,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("filesView.state.loading")})})})]}):null,Pl=r==="full"&&A&&u&&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:ra({exitFullscreenOnly:!0})}),s.jsx(br,{ref:jl,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",yt&&"[overflow-anchor:none]"),children:Me||dr?R?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(M,{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}):fr?la:js||(et&&Ge()==="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:ss,ref:El,children:[u?s.jsx(Ca,{containerRef:rs,filePath:u.path,fileContent:U}):null,U.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(U.length/1024)})}),s.jsx(Ns,{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(yr,{content:U,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1,allowRawHtml:!0})})]}),s.jsx(Fa,{containerRef:rs,open:Qr,onOpenChange:ts,focusNonce:ei,className:"right-4 top-16"})]}):gs&&ne==="view"?sa(u,ie,Ki,bl):s.jsxs("div",{className:q("relative h-full",sn&&"overflow-hidden"),children:[s.jsx("div",{className:q("h-full",sn&&"invisible"),children:s.jsx(Ba,{positionKey:`${Ft}:fullscreen`,value:ie,onChange:Ce,readOnly:!at,vimMode:ci==="vim",extensions:Ii,className:"h-full",onViewReady:n=>{Ze.current=n,window.requestAnimationFrame(()=>{un(n)})},onViewDestroy:()=>{Ze.current&&(Ze.current=null)}},`${Ft}:fullscreen`)}),sn&&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(M,{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(pd,{activeDialog:At,dialogData:It,dialogInputValue:Et,onDialogInputChange:Yr,isDialogSubmitting:No,onDialogSubmit:Wo,onClose:vl,inputRef:vo}),_o,Pl,g?J?pr:ua: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:pr})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[w>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:ua}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:pr})]})]})};function vd(r){return r+1}export{Om as FilesView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h7 as M,li as Z,lj as Fe,l4 as Ce,l5 as ke,l6 as Ie,l7 as ze,ld as Ne,lc as Ve,f as Oe,B as ee,I as te,lG as Pe}from"./useAppFontEffects-Dsl_sLrj.js";import{b as ie,s as Be,d as Se,e as ne,i as ve,j as De,c as re,k as I,l as Ue,h as _e,g as We,f as je,R as Ge,I as $e,p as se,m as qe,n as Ke,o as Je,r as Ye,w as Xe,t as ae,u as Qe,A as Ze,v as et,x as tt,q as oe,S as it,y as nt,z as rt,B as st,a as ye,C as he,F as at}from"./web-components-ngpHPEDU.js";import{G as ot,u as ht,W as lt,a as dt,b as ct,n as le,t as ut}from"./Virtualizer-CZlLSacm.js";import{j as C,r as k,R as L}from"./vendor-react-BUCujlKS.js";import{n as ft,i as G,f as A,a as pt,o as de,s as gt,j as ce,d as mt,q as ue,b as Ct,t as B,u as fe}from"./computeVirtualFileMetrics-6V1xNpO9.js";import{a as F,i as K,l as pe,h as St,r as vt}from"./isFilePlainText-CBAppvy1.js";import{t as H}from"./vendor-hast-util-to-html-BKBhbTDb.js";let yt=-1;var Tt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++yt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:M},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??M)?ft():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!F(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!K(i),result:t?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??G(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=M,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Be(this.options),tokenizeMaxLineLength:r}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!A(i,t.file)||!F(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){if(i.cacheKey==null)return this.lineCache=void 0,pe(i.contents);let{lineCache:e}=this;return(e==null||e.cacheKey!==i.cacheKey)&&(e={cacheKey:i.cacheKey,lines:pe(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){return this.textDoucmentCache.get(i)?.lineCount??this.getOrCreateLineCache(i).length}updateRenderCache(i,e){if(this.renderCache==null)return;const{result:t}=this.renderCache;if(t!=null){for(const[n,r]of i)t.code[n]={type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:r.map(([s,a,o])=>s===0&&a===""?o===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:o}:{type:"element",tagName:"span",properties:{"data-char":s,style:`--diffs-token-${e}:${a};`},children:[{type:"text",value:o}]})};t.baseThemeType=e,this.renderCache.isDirty=!0}}applyDocumentChange(i){if(this.renderCache==null)return;const{file:e,result:t}=this.renderCache;if(t!=null&&t.code.length!==i.lineCount){t.code.length=Math.min(t.code.length,i.lineCount);for(let n=t.code.length;n<i.lineCount;n++)t.code.push({type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(n)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(e,i)}renderFile(i=this.renderCache?.file,e=Z){if(i==null)return;let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),a=i.contents.length>0,o=!a||K(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),l=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||l))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||l||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!o&&a&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??G(i.name);const d=this.highlighter!=null&&ie(t.theme),u=this.highlighter!=null&&ne(this.computedLang),c=!o&&u;if(this.highlighter!=null&&d&&(n||o||!this.renderCache.highlighted&&c||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!u);this.renderCache={file:i,options:f,highlighted:c,result:p,renderRange:void 0}}(!d||!o&&!u)&&this.asyncHighlight(i).then(({result:p,options:f})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(i,p,f,!o)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=Z){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??G(i.name);const t=this.highlighter!=null&&St(pt(this.options.theme)),n=e||this.highlighter!=null&&ne(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:vt(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:a=!1}=this.options,o=[],h=ue(),l=Math.min(e.startingLine+e.totalLines,s);let d=0;const u=ve(e)?De(this.lineAnnotations):void 0;u!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:u.map(c=>I(c))})),d++);for(let c=e.startingLine;c<l;c++){const p=c+1,f=t[c];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:c,lineNumber:p}),new Error(g)}h.children.push(gt("context",p,`${c}`)),o.push(f),d++;const S=this.lineAnnotations[p];S!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:0,lineIndex:p,annotations:S.map(g=>I(g))})),d++)}return h.properties.style=`grid-row: span ${d}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:d,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return Ue({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return H(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ue();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,_e(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?H(ce({tagName:"code",children:i,properties:{"data-code":""}})):H(i)}async initializeHighlighter(){return this.highlighter=await mt(We(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(i,e,t,n=!0){if(this.renderCache==null)return;const r=!A(i,this.renderCache.file)||!this.renderCache.highlighted||!F(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!F(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&A(i,t.file)&&F(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return je({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function bt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ge(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:i?.useTokenTransformer,tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const Rt=[""];let Lt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Lt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:M},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Tt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new $e("file",se(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(se(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Ct(this.appliedThemeCSS.theme,this.options.theme??M)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e==="wrap"),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:a}=e;this.hydrateElements(t,n),At(this.pre,s,this.options.collapsed)||Mt(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),qe(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):Rt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:a=!1,lineAnnotations:o,renderRange:h}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:l=!1,themeType:d="system"}=this.options,u=l?void 0:h,c=this.renderRange,p=this.hasThemeChanged(),f=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,S=!A(this.file,e);if(!l&&!n&&Se(u,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(d);this.renderRange=u,S&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:g=!1,disableFileHeader:y=!1}=this.options;if(y&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(d),l){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,d,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t),this.injectUnsafeCSS()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,f,S||p)||!this.applyPartialRender(c,u)){const v=this.fileRenderer.renderFile(e,u);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,d,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,u),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||K(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${I(r)}`;let a=this.annotationCache.get(s);if(a==null||!bt(r,a.annotation)){a?.element.remove();const o=t(r);if(o==null)continue;a={element:Ke(I(r)),annotation:r},a.element.appendChild(o),this.fileContainer.appendChild(a.element),this.annotationCache.set(s,a)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=Je();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=Ye(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Xe(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??M,h=typeof o=="string"?o:{...o},l=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===l){this.appliedThemeCSS.theme=h;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l};return}this.themeCSSStyle=Qe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Ze(t,a,l)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:l}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=et(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=tt({code:this.code});const n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let r=0;r<2;r++){const s=this.code.children[r],a=n[r];s.innerHTML=H(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=H(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const a=e.startingLine,o=t.startingLine,h=e.totalLines===1/0?Number.POSITIVE_INFINITY:a+e.totalLines,l=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,d=Math.max(a,o),u=Math.min(h,l);if(u<=d||!this.trimDOMToOverlap(s.gutter,d,u)||!this.trimDOMToOverlap(s.content,d,u))return!1;let{length:c}=s.content.children;const p=(y,m)=>{if(!(m<=0))return this.fileRenderer.renderFile(n,{startingLine:y,totalLines:m,bufferBefore:0,bufferAfter:0})},f=o<d?p(o,d-o):void 0;if(f===void 0&&o<d)return!1;const S=l===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,l-u),g=l>u?p(u,S):void 0;return g===void 0&&l>u?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),c+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),c+=g.rowCount),this.lastRowCount!==c&&(s.gutter.style.setProperty("grid-row",`span ${c}`),s.content.style.setProperty("grid-row",`span ${c}`),this.lastRowCount=c),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(s>a)return!1;for(let o=e.children.length-1;o>=a;o-=1)e.children[o]?.remove();for(let o=s-1;o>=0;o-=1)e.children[o]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((h,l)=>h-l),r=new Map;if(n.length===0)return r;let s=0,a=n[s];const{children:o}=e;a===0&&(r.set(0,0),s+=1,a=n[s]);for(let h=0;h<o.length;h+=1){const l=o[h];if(!(l instanceof HTMLElement))continue;const d=this.getLineIndexFromDOMNode(l);if(d!=null){for(;a!=null&&d>=a;)r.set(a,h),s+=1,a=n[s];if(s>=n.length)break}}for(const h of n)r.has(h)||r.set(h,o.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??H(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const l=document.createElement("div");l.innerHTML=r;const d=l.firstElementChild;if(!(d instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(d,this.headerElement):t.shadowRoot?.prepend(d),this.headerElement=d,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const l=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,l),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const l=s?.(n)??void 0,d=a?.(n)??void 0,u=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,l),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,d),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,u),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:oe(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):oe(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=it;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};nt(s,this.appliedPreAttributes)||(rt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function At(i,e,t=!1){return!t&&i==null&&e!=null}function Mt(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let xt=-1;function wt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var Et=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++xt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ne,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){!e&&st(this.metrics,i)||(this.metrics=i,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!ye(e,i),n=wt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=he(this.lineAnnotations);if(this.renderRange!=null&&n&&ve(this.renderRange)){const r=Ft(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const a=Number(s);let o=r.getBoundingClientRect().height,h=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(h=!0),o+=r.nextElementSibling.getBoundingClientRect().height);const l=this.getLineHeight(a,h);o!==l&&(i=!0,o===this.metrics.lineHeight*(h?2:1)?this.cache.heights.delete(a):this.cache.heights.set(a,o))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n);let s=t?.resetFileLayoutCache===!0||r;t?.metrics!=null&&(this.metrics=t.metrics,s=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,s=!0),s&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=B(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:a="scroll"}=this.options,{lineHeight:o}=this.metrics;if(r+=this.cache.fileAnnotationHeight,a==="scroll"&&!this.hasLineAnnotations())return{top:r+s*o,height:o};const h=this.getLayoutCheckpointBeforeLineIndex(s);r=h?.top??r;for(let l=h?.lineIndex??0;l<s;l++)r+=this.getLineHeight(l,!1);return{top:r,height:this.getLineHeight(s,!1)}}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=B(this.metrics,e),a=Math.min(this.renderRange.startingLine,r),o=Math.min(a+this.renderRange.totalLines-1,r);if(o<a)return;const{fileAnnotationHeight:h}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:d}=this.metrics,u=s+(a===0?h:this.renderRange.bufferBefore),c=a+Math.max(Math.ceil((i-u)/d),0);return c>o?void 0:{lineNumber:c+1,top:s+h+c*d}}let l=s+(a===0?h:this.renderRange.bufferBefore);for(let d=a;d<=o;d++){if(l>=i)return{lineNumber:d+1,top:l};l+=this.getLineHeight(d)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1){const e=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!e)return;const t=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:r=!1,overflow:s="scroll"}=this.options,{lineHeight:a}=this.metrics,o=this.fileRenderer.getLineCount(this.file),h=B(this.metrics,n),l=fe(this.metrics);if(this.height+=h,r){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,s==="scroll"&&!this.hasLineAnnotations())this.height+=o*a;else for(let d=0;d<o;d++)this.addLayoutCheckpoint(d,this.height),this.height+=this.getLineHeight(d,!1);if(o>0&&(this.height+=l),this.fileContainer!=null&&e&&!t){const d=this.fileContainer.getBoundingClientRect();d.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:d.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{heights:n,checkpoints:r}=this.cache,s=this.renderRange;if(super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,n.size>0&&n.clear(),r.length>0&&(r.length=0),this.isSimpleMode()&&this.computeApproximateSize(),t&&s!==void 0&&this.file!==void 0){const a=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(this.file,this.top??0,a);o.bufferAfter!==s.bufferAfter&&this.updateBuffers(o)}}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!A(this.file,e),{forceRenderOverride:a,isSetup:o}=this;this.forceRenderOverride=void 0;const h=this.syncLineAnnotations(n);if(h&&this.resetLayoutCache(),this.file=e,i=this.getOrCreateFileContainerNode(i),this.file==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(o)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();const c=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(c==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");c.connect(i,this),this.isVisible=c.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const l=this.virtualizer.getWindowSpecs(),d=this.top??0,u=this.computeRenderRangeFromWindow(this.file,d,l);return super.render({file:this.file,fileContainer:i,renderRange:u,lineAnnotations:n,forceRender:(a??t)||h,...r})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Ht===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");a.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(a.lineIndex%e===0)return a}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:a,lineHeight:o}=this.metrics,h=this.fileRenderer.getLineCount(i),l=this.height,d=B(this.metrics,r),u=h>0?fe(this.metrics):0,{fileAnnotationHeight:c}=this.cache,p=d+c,f=Math.max(0,l-d-c-u),S=he(this.lineAnnotations),g=e+d,y=c>0&&S&&g<n&&g+c>t;if(e<t-l||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};if(h<=a)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};const m=Math.ceil(Math.max(n-t,0)/o),v=Math.ceil(m/a)*a+a*2,z=v/a,D=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const R=e+p,P=R+f;if(!y&&!(R<n&&P>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};const w=Math.floor(y&&D<e+p?0:(D-(e+p))/o),b=Math.floor(w/a)-Math.floor(z/2),xe=Math.ceil(h/a),E=Math.max(0,Math.min(b,xe))*a,Q=b<0?v+b*a:v,we=E===0?0:c+E*o,Ee=Math.min(Q,h-E);return{startingLine:E,totalLines:Q,bufferBefore:we,bufferAfter:Math.max(0,(h-E-Ee)*o)}}const be=z,N=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*o*2),a);let T=e+(U?.top??p),_=U?.lineIndex??0,V,O,x;const Re=U?.lineIndex??0;for(let R=Re;R<h;R++){const P=_%a===0,w=Math.floor(_/a);if(P&&(N[w]=T-(e+p),x!=null)){if(x<=0)break;x--}const b=this.getLineHeight(R,!1);T>t-b&&T<n&&(V??=w),T+b>D&&(O??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(V==null)if(y)V=0,O=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:l-d-u};O??=V;const W=Math.round(O-z/2),Le=Math.max(0,Math.ceil(h/a)-z),j=Math.max(0,Math.min(W,Le)),J=j*a,Y=W<0?v+W*a:v,Ae=N[j]??0,Me=J===0?0:c+Ae,X=j+Y/a,He=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:Me,bufferAfter:Math.max(0,He)}}};function Ft(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===at&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function kt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const l=e?.(i),d=t?.(i),u=n?.(i),c=r?.(i);return C.jsxs(C.Fragment,{children:[l!=null?C.jsx("div",{slot:Ce,children:l}):C.jsxs(C.Fragment,{children:[d!=null&&C.jsx("div",{slot:"header-prefix",children:d}),u!=null&&C.jsx("div",{slot:"header-filename-suffix",children:u}),c!=null&&C.jsx("div",{slot:"header-metadata",children:c})]}),s!=null&&a?.map((p,f)=>C.jsx("div",{slot:I(p),children:s(p)},f)),o!=null&&C.jsx("div",{slot:"gutter-utility-slot",style:ot,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function It({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:l}){const d=ht(),u=n!==void 0,c=k.useContext(lt),p=dt(),f=k.useRef(null),S=ct(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");d!=null?f.current=new Et(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),d,s,h?void 0:c,!0):f.current=new Te(q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:c,!0),f.current.hydrate({file:i,fileContainer:g,lineAnnotations:t,prerenderedHTML:r})}else{if(f.current==null)throw new Error("File: A File instance should exist when unmounting");f.current.cleanUp(),f.current=null}});return me(()=>{if(f.current==null)return;const g=q({controlledSelection:u,contentEditable:l,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),y=!ye(f.current.options,g);f.current.setOptions(g),f.current.render({file:i,lineAnnotations:t,forceRender:y}),n!==void 0&&f.current.setSelectedLines(n)}),me(()=>{if(l&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[l,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function q({options:i,controlledSelection:e,contentEditable:t,hasCustomHeader:n,hasEditor:r,hasGutterRenderUtility:s}){const a=t&&r,o=e||s||n;if(!o&&!a)return i;let h={...i};return o&&(h={...h,controlledSelection:e,renderCustomHeader:n?le:i?.renderCustomHeader,renderGutterUtility:s?le:i?.renderGutterUtility}),a&&(h={...h,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,lineHoverHighlight:"disabled"}),h}function _t({file:i,lineAnnotations:e,selectedLines:t,options:n,metrics:r,className:s,style:a,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,prerenderedHTML:c,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=It({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:c,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Ve,{ref:g,className:s,style:a,children:ut(kt({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:l,renderHeaderFilenameSuffix:d,renderHeaderMetadata:u,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),c)})}const Wt=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const{t:s}=Oe(),a=L.useRef(null),[o,h]=L.useState(null),l=L.useMemo(()=>{try{const c=e.trim();if(!c)return h(s("jsonTreeView.error.emptyJson")),null;const p=JSON.parse(c);return h(null),p}catch(c){return h(c instanceof Error?c.message:s("jsonTreeView.error.invalidJson")),null}},[e,s]),d=L.useCallback(()=>{a.current?.expandAll()},[]),u=L.useCallback(()=>{a.current?.collapseAll()},[]);return o?C.jsx("div",{className:t,children:C.jsxs("div",{className:"oc-surface-code rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-background)] p-4",children:[C.jsx("div",{className:"mb-1 font-medium text-foreground",children:s("jsonTreeView.error.invalidJsonTitle")}),C.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:o})]})}):l===null?null:C.jsxs("div",{className:t,children:[C.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[C.jsxs(ee,{variant:"ghost",size:"xs",onClick:d,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-down-s",className:"h-3 w-3"}),s("jsonTreeView.actions.expandAll")]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:u,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),s("jsonTreeView.actions.collapseAll")]})]}),C.jsx("div",{className:"oc-surface-code bg-[var(--syntax-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Pe,{ref:a,data:l,maxHeight:n,initiallyExpandedDepth:r})})]})});export{_t as F,Wt as J,Et as V};
|