@pi-chamber/web 1.0.6-rc.2 → 1.0.6-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/assets/{DiagramView-BdDt1SI7.js → DiagramView-BZ--w7Lh.js} +1 -1
  2. package/dist/assets/DiffView-Dtn6otnT.js +18 -0
  3. package/dist/assets/{FileSaveConflictDialog-DpyPjMH1.js → FileSaveConflictDialog-p1ik30al.js} +2 -2
  4. package/dist/assets/FilesView-D0Z0VmQm.js +6 -0
  5. package/dist/assets/{GitHubDetailScaffold-CW2ZqU0Y.js → GitHubDetailScaffold-a27RksFo.js} +4 -4
  6. package/dist/assets/{GitHubLinkPicker-BjJNQ7Ap.js → GitHubLinkPicker-B0CfzNfk.js} +1 -1
  7. package/dist/assets/GitHubListPrimitives-LFdR70l6.js +1 -0
  8. package/dist/assets/GitView-BNkoaVYl.js +9 -0
  9. package/dist/assets/{IssuesSurface-CDZENHrE.js → IssuesSurface-D4kD7_VW.js} +3 -3
  10. package/dist/assets/{JsonTreeView-DpCgOUXg.js → JsonTreeView-CEiJsFnP.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-418ChlsN.js +12 -0
  12. package/dist/assets/{PatchDiff-Dcr3EQgA.js → PatchDiff-BtOv_oLB.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-o_Edh6ny.js → PierreDiffViewer-CkuyY9ne.js} +15 -3
  14. package/dist/assets/{PullRequestsSurface-eSXl6sef.js → PullRequestsSurface-PML07zr-.js} +2 -2
  15. package/dist/assets/SessionSwitcherContent-DkfjRgwv.js +1 -0
  16. package/dist/assets/{SessionSwitcherDropdown-CFj9VWSa.js → SessionSwitcherDropdown-CEw8BEs6.js} +2 -2
  17. package/dist/assets/SessionUnreadDot-DXUn8-ss.js +1 -0
  18. package/dist/assets/SettingsView-BvUeFUqw.js +6 -0
  19. package/dist/assets/{SettingsWindow-BMzUErrM.js → SettingsWindow-D03Z9QyW.js} +1 -1
  20. package/dist/assets/{StickyHorizontalScrollbar-p7EbL2-E.js → StickyHorizontalScrollbar-CONTbZgX.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-QC8IoeBH.js → ToolOutputDialog-DibddNlz.js} +5 -5
  22. package/dist/assets/{ToolPartDiffPreview-BigGwtul.js → ToolPartDiffPreview-Bx7T1M2f.js} +1 -1
  23. package/dist/assets/{VirtualizedFileDiff-DvLCd7Qq.js → VirtualizedFileDiff-BY-mDMT8.js} +4 -4
  24. package/dist/assets/{Virtualizer-DNJrJKVb.js → Virtualizer-cIf8dSOQ.js} +1 -1
  25. package/dist/assets/{collapsible-0yfy07W2.js → collapsible-BhQdnj8G.js} +1 -1
  26. package/dist/assets/{computeVirtualFileMetrics-aX6tjjqv.js → computeVirtualFileMetrics-CzkFqhaU.js} +1 -1
  27. package/dist/assets/{contextFileOpenGuard-CZKJuHxf.js → contextFileOpenGuard-CjCOK8EB.js} +1 -1
  28. package/dist/assets/fileTreeStatus-CPTpyKOV.js +7 -0
  29. package/dist/assets/gitStatusPredicates-_GNbGCCb.js +1 -0
  30. package/dist/assets/{githubLink-BvevcNay.js → githubLink-CwIFogWd.js} +2 -2
  31. package/dist/assets/index-Cfrwo5uQ.js +11 -0
  32. package/dist/assets/index-D7k62S9M.css +1 -0
  33. package/dist/assets/{index-BMdbHCFt.js → index-DjOKW10B.js} +1 -1
  34. package/dist/assets/main-1wmEZ4Is.js +137 -0
  35. package/dist/assets/{main-BM-b2y8p.js → main-C51a3z3b.js} +2 -2
  36. package/dist/assets/{markdownCore-DbS8DkKw.js → markdownCore-Dsr6dY5C.js} +1 -1
  37. package/dist/assets/{miniChat-DO3DW6kJ.js → miniChat-DCxCx1fF.js} +2 -2
  38. package/dist/assets/{mobile-BgWLkut6.js → mobile-D6Ac2Mu3.js} +2 -2
  39. package/dist/assets/{nativeFileSave-Bhafll_7.js → nativeFileSave-P_Eg5Dgb.js} +1 -1
  40. package/dist/assets/{pi-session-focus-preference-ChYVctYk.js → pi-session-focus-preference-DjDyjZ1C.js} +1 -1
  41. package/dist/assets/{renderDiffWithHighlighter-xlvSvnTf.js → renderDiffWithHighlighter-CK_inhQE.js} +1 -1
  42. package/dist/assets/renderElectronMiniChatApp-wBNgFl0U.js +2 -0
  43. package/dist/assets/{renderFileWithHighlighter-CCoYfC-t.js → renderFileWithHighlighter-B_PFeRW5.js} +1 -1
  44. package/dist/assets/renderMobileApp-B3mhxGnb.js +11 -0
  45. package/dist/assets/runtimeEndpointReset-D8lAOCUB.js +62 -0
  46. package/dist/assets/{runtimeSurface-CJN1oo_1.js → runtimeSurface-C3YPOBlg.js} +1 -1
  47. package/dist/assets/useAppFontEffects-CoFst31H.js +215 -0
  48. package/dist/assets/{useGitHubRemoteSearch-CevR5iLf.js → useGitHubRemoteSearch-C0-6hhMJ.js} +1 -1
  49. package/dist/assets/useSwitcherItems-DHCCg4GF.js +1 -0
  50. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BLsm9T1Y.js → vendor-aparajita-capacitor-secure-storage-B9_YeZyx.js} +1 -1
  51. package/dist/assets/{vendor-base-ui-C7vVMZTg.js → vendor-base-ui-CKSCJw-4.js} +1 -1
  52. package/dist/assets/{vendor-boot-CoTxysn6.js → vendor-boot-Ciu-Edvy.js} +18 -18
  53. package/dist/assets/{vendor-capacitor-app-NX6DULfp.js → vendor-capacitor-app-Bpy_aPMq.js} +1 -1
  54. package/dist/assets/{vendor-capacitor-keyboard-DJD81I9f.js → vendor-capacitor-keyboard-DO8AIjrZ.js} +1 -1
  55. package/dist/assets/{vendor-capacitor-status-bar-DV24OoQV.js → vendor-capacitor-status-bar-SQkytwUW.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-autocomplete-qsuH4Dh-.js → vendor-codemirror-autocomplete-CInQsE8a.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-angular-ZHWyBf7j.js → vendor-codemirror-lang-angular-QbsN3LGE.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-cpp-pCTOmv-k.js → vendor-codemirror-lang-cpp-BT5U7lxV.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-css-2bFuyM70.js → vendor-codemirror-lang-css-dF-Dxbty.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-lang-go-DrG_c7D7.js → vendor-codemirror-lang-go-e4dp1bar.js} +1 -1
  61. package/dist/assets/{vendor-codemirror-lang-html-BV8lrR8v.js → vendor-codemirror-lang-html-DKcbBVQ4.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-lang-java-DrsvH6T2.js → vendor-codemirror-lang-java-CB2-FWv6.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-javascript-Dkzl3s07.js → vendor-codemirror-lang-javascript-B1zJk7xE.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-jinja-8Nn3bnoP.js → vendor-codemirror-lang-jinja-BsERjdSd.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-json-CsdmtHhi.js → vendor-codemirror-lang-json-C0pZ0NhY.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-less-DJuZ4cZe.js → vendor-codemirror-lang-less-_N9HmR4h.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-liquid-D2RO-Pzr.js → vendor-codemirror-lang-liquid-D02xJRCD.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-markdown-C0Zu3b3n.js → vendor-codemirror-lang-markdown-_6ojeUuZ.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-php-CuDtt2Zj.js → vendor-codemirror-lang-php-DguCnbJA.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-python-Cv2exx_M.js → vendor-codemirror-lang-python-Byr5gw5f.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-rust-C4TxJ6Rg.js → vendor-codemirror-lang-rust-DN6Wh0eK.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sass-BmtPz8kf.js → vendor-codemirror-lang-sass-DOlEW7q1.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-sql-BF1ZaXqJ.js → vendor-codemirror-lang-sql-BJzE9Dby.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-vue-DZgXrP2k.js → vendor-codemirror-lang-vue-DR8E-2nr.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-wast-DsnaGtL_.js → vendor-codemirror-lang-wast-n6lcDH5S.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-xml-D8DzzFat.js → vendor-codemirror-lang-xml-Cf2lmlmY.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-yaml-D5hBv7m6.js → vendor-codemirror-lang-yaml-DSR_E0yh.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-language-data-vn2RyN9T.js → vendor-codemirror-language-data-CSid5JuX.js} +2 -2
  79. package/dist/assets/{vendor-codemirror-search-BVCYIV0D.js → vendor-codemirror-search-8lY3lt6q.js} +1 -1
  80. package/dist/assets/{vendor-lezer-cpp-vqXSn3lv.js → vendor-lezer-cpp-DZYTDKiD.js} +1 -1
  81. package/dist/assets/{vendor-lezer-css-JnEzSyZR.js → vendor-lezer-css-6qV4fYNQ.js} +1 -1
  82. package/dist/assets/{vendor-lezer-go-dD2gQMIL.js → vendor-lezer-go-BDi_Iblq.js} +1 -1
  83. package/dist/assets/{vendor-lezer-html-Cr3U-1pu.js → vendor-lezer-html-BjqcY-oJ.js} +1 -1
  84. package/dist/assets/{vendor-lezer-java-CRM0IMCo.js → vendor-lezer-java-J2BXqz1h.js} +1 -1
  85. package/dist/assets/{vendor-lezer-javascript-B3s21DIS.js → vendor-lezer-javascript-CiQ9F8yX.js} +1 -1
  86. package/dist/assets/{vendor-lezer-json-DPFM6EBV.js → vendor-lezer-json-BxN83KKR.js} +1 -1
  87. package/dist/assets/{vendor-lezer-lr-Bllrq8hY.js → vendor-lezer-lr-BVsDua_K.js} +1 -1
  88. package/dist/assets/{vendor-lezer-markdown-6-3PLvXG.js → vendor-lezer-markdown-BkMtRQ3X.js} +1 -1
  89. package/dist/assets/{vendor-lezer-php-DOyzfHRl.js → vendor-lezer-php-B3XqnXdP.js} +1 -1
  90. package/dist/assets/{vendor-lezer-python-CdHdN5qt.js → vendor-lezer-python-D342CidI.js} +1 -1
  91. package/dist/assets/{vendor-lezer-rust-CqnW8EMH.js → vendor-lezer-rust-Dbfg_4LA.js} +1 -1
  92. package/dist/assets/{vendor-lezer-sass-BbcF4y6A.js → vendor-lezer-sass-ClxPaFt1.js} +1 -1
  93. package/dist/assets/{vendor-lezer-xml-C31AyWoo.js → vendor-lezer-xml-I_S6FQ1u.js} +1 -1
  94. package/dist/assets/{vendor-lezer-yaml-Cv908yC2.js → vendor-lezer-yaml-COA6HWLP.js} +1 -1
  95. package/dist/assets/{vendor-replit-codemirror-vim-Cwhyn_5f.js → vendor-replit-codemirror-vim-7IE2zVmx.js} +1 -1
  96. package/dist/assets/{web-components-6ORYp3Iv.js → web-components-CzkvK_V5.js} +1 -1
  97. package/dist/index.html +4 -4
  98. package/dist/mini-chat.html +3 -3
  99. package/dist/mobile.html +3 -3
  100. package/package.json +1 -1
  101. package/server/lib/git/DOCUMENTATION.md +1 -0
  102. package/server/lib/git/routes.js +14 -0
  103. package/server/lib/git/routes.test.js +37 -0
  104. package/server/lib/git/service.js +27 -0
  105. package/server/lib/git/service.test.js +32 -0
  106. package/server/lib/pi/routes.js +63 -1
  107. package/server/lib/pi/routes.test.js +77 -0
  108. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
  109. package/server/lib/pi/session-shelf-store.js +181 -0
  110. package/server/lib/pi/session-shelf-store.test.js +73 -0
  111. package/server/lib/pi/ui-settings-store.js +1 -0
  112. package/dist/assets/DiffView-Dk3VIX9E.js +0 -18
  113. package/dist/assets/FilesView-CumrwioK.js +0 -6
  114. package/dist/assets/GitHubListPrimitives-BcB-cCTs.js +0 -1
  115. package/dist/assets/GitView-BoCaX5AO.js +0 -9
  116. package/dist/assets/MarkdownRendererImpl-BkT5TUWF.js +0 -12
  117. package/dist/assets/SessionSwitcherContent-Dm30bfpn.js +0 -1
  118. package/dist/assets/SessionUnreadDot-CHlK2awX.js +0 -1
  119. package/dist/assets/SettingsView-CcHRUyev.js +0 -6
  120. package/dist/assets/gitStatusPredicates-3i8CcYWJ.js +0 -1
  121. package/dist/assets/index-C2ISrmRR.js +0 -11
  122. package/dist/assets/index-DgwThEwf.css +0 -1
  123. package/dist/assets/main-BXZ561E3.js +0 -137
  124. package/dist/assets/renderElectronMiniChatApp-CgVqxKDm.js +0 -2
  125. package/dist/assets/renderMobileApp-CoY1tsk5.js +0 -11
  126. package/dist/assets/runtimeEndpointReset-fozcAShH.js +0 -62
  127. package/dist/assets/useAppFontEffects-D_gtiA95.js +0 -215
  128. package/dist/assets/useFilesViewSearch-BUxcZj60.js +0 -7
  129. package/dist/assets/useSwitcherItems-kaRkXggX.js +0 -1
@@ -1 +1 @@
1
- import{j as c}from"./vendor-boot-CoTxysn6.js";import{R as t}from"./vendor-react-Bz1tRBxM.js";import{z as $,t as d,I as B}from"./useAppFontEffects-D_gtiA95.js";import{h as A,b as G,o as ee,cF as W}from"./index-C2ISrmRR.js";import{b as te,D as re,F as ne}from"./FileSaveConflictDialog-DpyPjMH1.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-CJN1oo_1.js";import"./nativeFileSave-Bhafll_7.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./vendor-react-drawio-IYnLUY5N.js";const se=l=>l.split("/").pop()||l;function xe(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[m,F]=t.useState(!1),[U,p]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),v=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),T=A(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const i=t.useCallback((e,n,s)=>I.current&&v.current===e&&G()===n&&w.current===s,[]),z=t.useCallback(async e=>{const n=v.current+1;v.current=n;const s=G(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),p(!1),P(!1),F(!1);try{const r=await u?.(e);if(!i(n,s,e))return;if(!r){d.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!i(n,s,e))return;d.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{i(n,s,e)&&E(!1)}},[l,i]);t.useEffect(()=>ee(()=>{if(v.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),p(!1),P(!1),F(!1);const e=w.current;e&&z(e)}),[z]),t.useEffect(()=>{if(!T)return;const e=A.getState().consumePendingDiagramFile();e&&z(e)},[z,T]);const K=t.useCallback(async(e,n,s,u,r,o)=>{let a=null,f=s,V=u;try{if(V){const N=await l?.readFile?.(e);if(!i(r,o,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),V=N.exists!==!1)}}catch{if(!i(r,o,e))return}i(r,o,e)&&(h({path:e,displayPath:se(e),exists:V,currentRevision:f,currentContent:a,dirtyContent:n,runtimeKey:o}),p(!1))},[l,i]),X=t.useCallback(async(e,n,s,u,r)=>{const o=await l?.writeFile?.(e,n,te(g.current,s?!0:void 0));return i(u,r,e)?{stale:!1,success:!!o?.success,revision:o?.revision}:{stale:!0}},[l,i]),O=t.useCallback((e,n)=>{C.current=e,typeof n<"u"&&(g.current=n),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||m)return;const n=v.current,s=G(),u=x,r=e,o=S.current+1;S.current=o,P(!0);try{const a=await X(u,r,!1,n,s);if(a.stale)return;if(!a.success){d.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!i(n,s,u))return;if(W(a)){await K(u,r,a.currentRevision??null,a.exists,n,s);return}d.error(a instanceof Error?a.message:"Save failed")}finally{S.current===o&&P(!1)}},[O,x,l,i,m,j,K,X]),Q=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),p(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!i(n,s,e.path))return;if(!r){d.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(o=>o+1),h(null),p(!1)}catch(r){if(!i(n,s,e.path))return;d.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,i,m,b]),Y=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!l?.writeFile){d.error("Saving not supported");return}const o=D.current?.getXml()??e.dirtyContent;if(!o){d.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await X(e.path,o,!0,n,s);if(f.stale)return;if(!f.success){d.error("Failed to write file");return}O(o,f.revision),h(null),p(!1)}catch(f){if(!i(n,s,e.path))return;if(W(f)){await K(e.path,o,f.currentRevision??e.currentRevision,f.exists,n,s);return}d.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,i,m,K,X,b]),Z=t.useCallback(()=>{m||j||(h(null),p(!1))},[m,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(B,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(B,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(B,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>A.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(B,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ne,{open:!!b,conflict:b,isResolving:m||j,showCompare:U,onToggleCompare:()=>p(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{xe as DiagramView};
1
+ import{j as c}from"./vendor-boot-Ciu-Edvy.js";import{R as t}from"./vendor-react-Bz1tRBxM.js";import{z as $,t as d,I as B}from"./useAppFontEffects-CoFst31H.js";import{h as A,b as G,o as ee,cR as W}from"./index-Cfrwo5uQ.js";import{b as te,D as re,F as ne}from"./FileSaveConflictDialog-p1ik30al.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-C3YPOBlg.js";import"./nativeFileSave-P_Eg5Dgb.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./vendor-react-drawio-IYnLUY5N.js";const se=l=>l.split("/").pop()||l;function xe(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[m,F]=t.useState(!1),[U,p]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),v=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),T=A(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const i=t.useCallback((e,n,s)=>I.current&&v.current===e&&G()===n&&w.current===s,[]),z=t.useCallback(async e=>{const n=v.current+1;v.current=n;const s=G(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),p(!1),P(!1),F(!1);try{const r=await u?.(e);if(!i(n,s,e))return;if(!r){d.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!i(n,s,e))return;d.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{i(n,s,e)&&E(!1)}},[l,i]);t.useEffect(()=>ee(()=>{if(v.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),p(!1),P(!1),F(!1);const e=w.current;e&&z(e)}),[z]),t.useEffect(()=>{if(!T)return;const e=A.getState().consumePendingDiagramFile();e&&z(e)},[z,T]);const K=t.useCallback(async(e,n,s,u,r,o)=>{let a=null,f=s,V=u;try{if(V){const N=await l?.readFile?.(e);if(!i(r,o,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),V=N.exists!==!1)}}catch{if(!i(r,o,e))return}i(r,o,e)&&(h({path:e,displayPath:se(e),exists:V,currentRevision:f,currentContent:a,dirtyContent:n,runtimeKey:o}),p(!1))},[l,i]),X=t.useCallback(async(e,n,s,u,r)=>{const o=await l?.writeFile?.(e,n,te(g.current,s?!0:void 0));return i(u,r,e)?{stale:!1,success:!!o?.success,revision:o?.revision}:{stale:!0}},[l,i]),O=t.useCallback((e,n)=>{C.current=e,typeof n<"u"&&(g.current=n),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||m)return;const n=v.current,s=G(),u=x,r=e,o=S.current+1;S.current=o,P(!0);try{const a=await X(u,r,!1,n,s);if(a.stale)return;if(!a.success){d.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!i(n,s,u))return;if(W(a)){await K(u,r,a.currentRevision??null,a.exists,n,s);return}d.error(a instanceof Error?a.message:"Save failed")}finally{S.current===o&&P(!1)}},[O,x,l,i,m,j,K,X]),Q=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),p(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!i(n,s,e.path))return;if(!r){d.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(o=>o+1),h(null),p(!1)}catch(r){if(!i(n,s,e.path))return;d.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,i,m,b]),Y=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!l?.writeFile){d.error("Saving not supported");return}const o=D.current?.getXml()??e.dirtyContent;if(!o){d.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await X(e.path,o,!0,n,s);if(f.stale)return;if(!f.success){d.error("Failed to write file");return}O(o,f.revision),h(null),p(!1)}catch(f){if(!i(n,s,e.path))return;if(W(f)){await K(e.path,o,f.currentRevision??e.currentRevision,f.exists,n,s);return}d.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,i,m,K,X,b]),Z=t.useCallback(()=>{m||j||(h(null),p(!1))},[m,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(B,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(B,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(B,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>A.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(B,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ne,{open:!!b,conflict:b,isResolving:m||j,showCompare:U,onToggleCompare:()=>p(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{xe as DiagramView};
@@ -0,0 +1,18 @@
1
+ import{j as t,aP as Rt}from"./vendor-boot-Ciu-Edvy.js";import{R as r}from"./vendor-react-Bz1tRBxM.js";import{f as se,h as J,b as ot,q as Ye}from"./index-Cfrwo5uQ.js";import{ek as Et,e0 as At,ei as Tt,aP as lt,cJ as ct,dy as Mt,d3 as Re,B as Le,I as G,z as ut,bi as ce,t as dt,ea as ft,a$ as It,b0 as Pt,b1 as $t,bu as Qe,dp as Wt,el as _t,em as Bt,y as zt,as as Ot,bz as Gt,cK as Ht,dZ as Ut,h as Vt,ba as qt,az as Kt,aR as Xt,aS as Jt,aT as Yt}from"./useAppFontEffects-CoFst31H.js";import{d as pt,b as ht,i as Ge,a as He,c as Qt,C as Zt}from"./gitStatusPredicates-_GNbGCCb.js";import{p as en}from"./VirtualizedFileDiff-BY-mDMT8.js";import{P as tn}from"./PierreDiffViewer-CkuyY9ne.js";import{v as nn,g as sn}from"./contextFileOpenGuard-CjCOK8EB.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./runtimeSurface-C3YPOBlg.js";import"./nativeFileSave-P_Eg5Dgb.js";import"./web-components-CzkvK_V5.js";import"./computeVirtualFileMetrics-CzkFqhaU.js";import"./vendor-shiki-BEwTOAFg.js";import"./vendor-shikijs-core-Ck_OPM_T.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-DPFxvYtK.js";import"./vendor-hast-util-to-html-O3stl53j.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-C40bX6nM.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-DrfmQi8i.js";import"./vendor-pierre-theming-BO6EPniU.js";import"./vendor-shikijs-engine-javascript-DL394yyj.js";import"./vendor-oniguruma-to-es-DgwFOwdE.js";import"./vendor-oniguruma-parser-BrbMHgHx.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"./renderDiffWithHighlighter-CK_inhQE.js";import"./vendor-diff-C3JhlQdm.js";import"./StickyHorizontalScrollbar-CONTbZgX.js";import"./runtimeEndpointReset-D8lAOCUB.js";import"./SessionUnreadDot-DXUn8-ss.js";/* empty css */import"./permissionStore-zIpxq9Pq.js";import"./appThemeRegistry-Ca8eGRB9.js";import"./registerCustomTheme-C-h6lsYW.js";function rn(s,n=10){const e=[];let i;for(const l of s.split(`
2
+ `)){const f=l.match(Et);if(f!=null){i!=null&&(i.hunkLines.length>0&&(Pe(i,n,"trailing"),ze(i,e)),i=void 0);const d=parseInt(f[3]),b=parseInt(f[1]),g=parseInt(f[4]??"1"),c=parseInt(f[2]??"1");isNaN(d)||isNaN(b)||isNaN(g)||isNaN(c)?e.push(l):i={additionStart:d,deletionStart:b,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(i==null){e.push(l);continue}if(l.startsWith(" "))i.contextLines.push(l);else if(l!==""){if(i.hunkLines.length>0&&i.contextLines.length>n*2){const d=i.contextLines.length-n*2,b=i.contextLines.slice(-n);Pe(i,n,"trailing");const{additionCount:g,deletionCount:c}=i;ze(i,e),i={additionStart:i.additionStart+g+d,deletionStart:i.deletionStart+c+d,deletionCount:0,additionCount:0,contextLines:b,hunkLines:[]}}Pe(i,n,i.hunkLines.length===0?"leading":"before-change"),i.hunkLines.push(l),l.startsWith("+")?i.additionCount+=1:l.startsWith("-")&&(i.deletionCount+=1)}}i!=null&&i.hunkLines.length>0&&(Pe(i,n,"trailing"),ze(i,e));const o=e.join(`
3
+ `);return s.endsWith(`
4
+ `)?`${o}
5
+ `:o}function Pe(s,n,e){if(e==="leading"&&s.contextLines.length>n){const i=s.contextLines.length-n;s.contextLines.splice(0,i),s.additionStart+=i,s.deletionStart+=i}return e==="trailing"&&s.contextLines.length>n&&(s.contextLines.length=n),s.contextLines.length>0&&(s.hunkLines.push(...s.contextLines),s.additionCount+=s.contextLines.length,s.deletionCount+=s.contextLines.length,s.contextLines.length=0),s}function ze(s,n){n.push(`@@ -${Ze(s.deletionStart,s.deletionCount)} +${Ze(s.additionStart,s.additionCount)} @@`),n.push(...s.hunkLines)}function Ze(s,n){return n===1?`${s}`:`${s},${n}`}const an=64,on=3,he=new Map,ln=(s,n,e=on)=>{const i=`${s}\0${e}\0${n}`,o=he.get(i);if(o)return he.delete(i),he.set(i,o),o;const l=un(n),f=l?At(rn(n,e),{oldFile:{name:s,contents:l.before},newFile:{name:s,contents:l.after}})??tt(s):Tt(cn(s,n))[0]?.files[0]??tt(s);for(he.set(i,f);he.size>an;){const d=he.keys().next().value;if(!d)break;he.delete(d)}return f},cn=(s,n)=>!n.trim()||n.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(n)?n:`Index: ${s}
6
+ ===================================================================
7
+ --- ${s}
8
+ +++ ${s}
9
+ ${n}`,un=s=>{if(!s.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(s))return;const n=[...s.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(n.length!==1)return;const e=n[0],i=Number.parseInt(e[1]??"",10),o=Number.parseInt(e[2]??"",10);if(i>1||o>1||!Number.isFinite(i)||!Number.isFinite(o))return;const l=(e.index??0)+e[0].length,f=s.slice(l),d=[],b=[];let g;for(const c of f.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(g==="-"||g===" "){const p=d.at(-1);p&&(p.newline=!1)}if(g==="+"||g===" "){const p=b.at(-1);p&&(p.newline=!1)}continue}if(c.startsWith("-")){d.push({text:c.slice(1),newline:!0}),g="-";continue}if(c.startsWith("+")){b.push({text:c.slice(1),newline:!0}),g="+";continue}c.startsWith(" ")&&(d.push({text:c.slice(1),newline:!0}),b.push({text:c.slice(1),newline:!0}),g=" ")}return{before:et(d),after:et(b)}},et=s=>s.map(n=>n.text+(n.newline?`
10
+ `:"")).join(""),tt=s=>en({name:s,contents:""},{name:s,contents:""}),dn=s=>/^Binary files .+ differ$/m.test(s)||/^GIT binary patch$/m.test(s),Ue=(s,n,e)=>dn(n)?{original:"",modified:"",isBinary:!0,patch:n,contextMode:e}:{original:"",modified:"",patch:n,fileDiff:ln(s,n),contextMode:e},gt=(s,n,e)=>{const i=s??0,o=n??0;return!i&&!o?null:t.jsxs("span",{className:se("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,o?t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o]}):null]})},fn=r.memo(function({changedFiles:n,selectedFile:e,onSelectFile:i}){return n.length===0?null:t.jsx(lt,{outerClassName:"flex-1 min-h-0",className:"px-1 py-2",children:t.jsx("ul",{className:"flex flex-col gap-1",children:n.map(o=>{const l=pt(o),f=e===o.path;return t.jsx("li",{children:t.jsxs("button",{type:"button",onClick:()=>i(o.path),className:se("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",f?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(ct,{filePath:o.path,className:"h-3.5 w-3.5 flex-shrink-0"}),t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:o.path,children:o.path}),gt(o.insertions,o.deletions)]})},o.path)})})})});function pn(s,n,e){return s==="staged"?{source:"staged",staged:!0}:s==="working"?{source:"unstaged",staged:!1}:{source:"head",staged:e.staged&&n.path===e.path||ht(n)}}function hn(s,n){return s!=="all"?null:ht(n)?"Staged":mt(s,n)?"Partly staged":"Not staged"}function mt(s,n){return s==="all"&&Ge(n)&&He(n)}const gn=r.memo(function(){return t.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:t.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),mn=r.memo(function({filePath:n,diff:e,renderSideBySide:i}){const o=e.original.length>0,l=e.modified.length>0,f=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",d=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return t.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:t.jsxs("div",{className:f,children:[o&&t.jsxs("div",{className:d,children:[t.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),t.jsx("img",{src:e.original,alt:`Original: ${n}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&t.jsxs("div",{className:d,children:[t.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o?"Modified":"New"}),t.jsx("img",{src:e.modified,alt:`Modified: ${n}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),xn=r.memo(function({filePath:n,diff:e,renderSideBySide:i,wrapLines:o}){const l=r.useMemo(()=>Mt(n)||"text",[n]);return e.isBinary?t.jsx(gn,{}):Re(n)?t.jsx(mn,{filePath:n,diff:e,renderSideBySide:i}):t.jsx("div",{className:"w-full",style:{contain:"layout"},children:t.jsx(tn,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})})}),Oe=({label:s,text:n,icon:e,loading:i,disabled:o,tone:l,onClick:f})=>t.jsxs(Le,{variant:"ghost",size:"sm",className:se("h-6 gap-1 rounded-md bg-transparent px-2 typography-micro font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground",l==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",l==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:o,title:s,"aria-label":s,onClick:d=>{d.stopPropagation(),f()},children:[i?t.jsx(G,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(G,{name:e,className:"size-3.5"}),n]}),bn=r.memo(function({filePath:n,staged:e,partlyStaged:i=!1,busyAction:o,disabled:l,onAction:f}){return t.jsx("div",{className:"flex items-center gap-1",children:e?t.jsx(Oe,{label:`Unstage ${n}`,text:"Unstage",icon:"arrow-go-back",loading:o==="unstage",disabled:l,onClick:()=>f("unstage")}):t.jsxs(t.Fragment,{children:[t.jsx(Oe,{label:i?`Revert unstaged changes in ${n}`:`Revert changes in ${n}`,text:i?"Revert unstaged":"Revert",icon:"arrow-go-back",loading:o==="discard",disabled:l,tone:"failure",onClick:()=>f("discard")}),t.jsx(Oe,{label:i?`Stage the rest of ${n}`:`Stage ${n}`,text:i?"Stage the rest":"Stage",icon:"add",loading:o==="stage",disabled:l,tone:"success",onClick:()=>f("stage")})]})})}),xt=3,yn=1e6,wn=15e3,nt=500,Fn=r.memo(function({directory:n,file:e,layout:i,wrapLines:o,isSelected:l,isExpanded:f,isMounted:d,onSelect:b,onExpandedChange:g,registerSectionRef:c,showOpenInEditorAction:p=!1,isOpeningInEditor:F=!1,onOpenInEditor:k,diffSource:x,staged:S=!1,stageLabel:h=null,partlyStaged:$=!1,showFileActions:m=!0,loadFullFiles:V=!1,initialDiffData:R=null}){const{git:C}=ut(),E=ce(r.useCallback(u=>u.directories.get(n)?.diffCache.get(e.path)??null,[n,e.path])),w=ce(u=>u.setDiff),y=ce(u=>u.fetchStatus),L=J(u=>u.setDiffFileLayout),M=J(u=>u.setDiffWrapLines),[A,_]=r.useState(0),[N,z]=r.useState(null),[q,K]=r.useState(!1),[ie,ge]=r.useState(null),[T,W]=r.useState(!1),[Y,ae]=r.useState(null),B=r.useRef(null),me=r.useRef(null),Q=r.useMemo(()=>pt(e),[e]),H=i==="side-by-side",re=V?"full":"patch",ue=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,Z=r.useMemo(()=>R||(Y?.source===x?Y.data:x!=="head"||!E?null:{original:E.original,modified:E.modified,isBinary:E.isBinary,contextMode:"full"}),[E,x,R,Y]),oe=Z?.contextMode===re,De=r.useCallback(u=>{me.current=u,c(e.path,u)},[e.path,c]),xe=r.useCallback(u=>{g(e.path,u)},[e.path,g]),le=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{ae(null),z(null),B.current=null},[x,ue]),r.useEffect(()=>{if(!f||!d)return;if(!n||R||Z&&oe){B.current=null,K(!1);return}const u=`${n}::${e.path}::${x}::${ue}::${re}::${A}`;if(B.current===u)return;B.current=u,z(null),K(!0);let P=!1;const ne=ot(),de=V?yn:xt,ee=Re(e.path)?C.getGitFileDiff(n,{path:e.path,staged:x==="staged"}):C.getGitDiff(n,{path:e.path,source:x,contextLines:de}),ye=wn,we=new Promise((O,te)=>{setTimeout(()=>te(new Error(`Timed out after ${ye}ms`)),ye)});return Promise.race([ee,we]).then(O=>{if(!P){if("diff"in O){const te=Ue(e.path,O.diff,re);ae({source:x,data:te})}else{const te={original:O.original??"",modified:O.modified??"",isBinary:O.isBinary,contextMode:"full"};x==="head"?w(n,e.path,te,ne):ae({source:x,data:te})}K(!1)}}).catch(O=>{if(P)return;const te=O instanceof Error?O.message:String(O);z(te),K(!1)}),()=>{P=!0,B.current===u&&(B.current=null)}},[re,Z,oe,A,x,n,e.path,ue,C,R,f,d,V,w]);const be=r.useCallback(()=>{xe(!f),le()},[xe,le,f]),Ee=r.useCallback(async u=>{if(!(!n||ie!==null)){ge(u);try{u==="stage"?await C.stageGitFile(n,e.path):u==="unstage"?await C.unstageGitFile(n,e.path):await C.revertGitFile(n,e.path,{scope:"working"}),_(P=>P+1),await y(n,C)}catch(P){const ne=u==="unstage"?"Failed to unstage changes":u==="stage"?"Failed to stage changes":"Failed to revert changes";dt.error(P instanceof Error?P.message:ne)}finally{ge(P=>P===u?null:P)}}},[n,y,e.path,ie,C]);return t.jsxs("div",{ref:De,className:se("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[t.jsx("div",{className:se("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:t.jsxs("div",{role:"button",tabIndex:0,onClick:be,onKeyDown:u=>{u.target===u.currentTarget&&(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),be())},className:se("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[t.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),t.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:f?t.jsx(G,{name:"arrow-down-s",className:"size-4"}):t.jsx(G,{name:"arrow-right-s",className:"size-4"})}),t.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:Q.color},title:Q.description,"aria-label":Q.description,children:Q.code}),t.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(ct,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const u=e.path.lastIndexOf("/");if(u===-1)return t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,u),ne=e.path.slice(u+1);return t.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[t.jsx("span",{className:"text-muted-foreground",children:"/"}),t.jsx("span",{className:"text-foreground",children:ne})]})]})})()]})})]}),t.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[h&&m?t.jsx("span",{className:"typography-micro text-muted-foreground",children:h}):null,gt(e.insertions,e.deletions),p&&k?t.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:u=>{u.stopPropagation(),k(e.path,Z)},disabled:F,children:F?t.jsx(G,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(G,{name:"edit",className:"size-3.5"})}):null,t.jsx(ft,{mode:H?"side-by-side":"unified",onModeChange:u=>{const P=u==="side-by-side"?"side-by-side":"inline";L(e.path,P)},className:"opacity-70"}),t.jsxs(It,{children:[t.jsx(Pt,{asChild:!0,children:t.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"File view options","aria-label":"File view options",onClick:u=>{u.stopPropagation()},onPointerDown:u=>{u.stopPropagation()},children:t.jsx(G,{name:"more-2-fill",className:"size-3.5"})})}),t.jsxs($t,{align:"end",onClick:u=>{u.stopPropagation()},onPointerDown:u=>{u.stopPropagation()},children:[t.jsxs(Qe,{onSelect:()=>{M(!o)},children:[t.jsx(G,{name:"text-wrap",className:"size-4"}),t.jsx("span",{className:"flex-1",children:"Wrap lines"}),o?t.jsx(G,{name:"check",className:"size-4"}):null]}),t.jsxs(Qe,{onSelect:()=>{L(e.path,H?"inline":"side-by-side")},children:[t.jsx(G,{name:H?"align-justify":"layout-column",className:"size-4"}),H?"Switch to unified view":"Switch to side-by-side view"]})]})]})]})]})}),f&&t.jsxs("div",{className:"relative overflow-clip bg-background",children:[!d&&!N?t.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,N?t.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),t.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),t.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>_(u=>u+1),children:"Retry"})]}):null,d&&q&&!Z&&!N?t.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx(G,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,d&&Z&&!T&&e.insertions+e.deletions>nt?t.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),t.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>W(!0),children:"Render anyway"})]}):null,d&&Z&&(T||e.insertions+e.deletions<=nt)?t.jsxs(t.Fragment,{children:[t.jsx(xn,{filePath:e.path,diff:Z,renderSideBySide:H,wrapLines:o}),m?t.jsx("div",{className:"flex justify-end border-t border-border/40 px-2 py-1",children:t.jsx(bn,{filePath:e.path,staged:S,partlyStaged:$,busyAction:ie,disabled:ie!==null,onAction:Ee})}):null]}):null]})]})}),jn=1100,st=300,vn=s=>s<=6?s:s<=12?6:s<=25?4:2,Sn=(s,n)=>Wt(s,n),it=(s,n)=>{const e=s.split(`
11
+ `),i=n.split(`
12
+ `),o=Math.min(e.length,i.length);for(let l=0;l<o;l+=1)if(e[l]!==i[l])return l+1;return i.length>e.length?e.length+1:e.length>i.length?Math.max(1,i.length):1},Nn=s=>Array.isArray(s)?s.filter(n=>!n||typeof n!="object"?!1:typeof n.file=="string"):[],Cn=s=>s.split(/^diff --git /m).slice(1).flatMap(e=>{const[i=""]=e.split(`
13
+ `,1),o=i.lastIndexOf(" b/");if(o<=2)return[];const l=i.slice(2,o),f=i.slice(o+3).trim(),d=`diff --git ${e}`,b=d.includes(`
14
+ new file mode `)?"added":d.includes(`
15
+ deleted file mode `)?"deleted":d.includes(`
16
+ rename from `)?"renamed":"modified";let g=0,c=0;for(const p of d.split(`
17
+ `))p.startsWith("+")&&!p.startsWith("+++")&&(g+=1),p.startsWith("-")&&!p.startsWith("---")&&(c+=1);return[{file:b==="deleted"?l:f,status:b,additions:g,deletions:c,patch:d}]}),Ln=s=>s==="added"?"A":s==="deleted"?"D":"M";function Dn({activeDiffScope:s,effectiveDirectory:n,branchBase:e,branchHead:i,git:o,sessionMessageRecords:l}){const[f,d]=r.useState([]),[b,g]=r.useState(null),[c,p]=r.useState(!1),F=r.useMemo(()=>{const S=_t(l,{showTextJustificationActivity:!1,mergeHiddenUserTurns:!0});for(let h=S.turns.length-1;h>=0;h-=1){const $=S.turns[h];if(!$)continue;const m=$.activityParts.map(C=>C.part).filter(C=>C.type==="tool"),V=Bt(m);if(V.length>0)return V.map(C=>({file:C.path,status:"modified",additions:C.additions,deletions:C.deletions,patch:C.patch}));const R=Nn($.userMessage.info?.summary?.diffs);if(R.length>0)return R}return[]},[l]);r.useEffect(()=>{if(s!=="branch"||!n||!e||!i||!o.getGitRangeDiff){d([]),g(null),p(!1);return}let S=!1;return p(!0),g(null),o.getGitRangeDiff(n,{base:e,head:i,contextLines:xt}).then(h=>{S||(d(Cn(h.diff??"")),p(!1))}).catch(h=>{S||(d([]),p(!1),g(h instanceof Error?h.message:String(h)))}),()=>{S=!0}},[s,e,i,n,o]);const k=r.useMemo(()=>{const S=new Map;for(const h of F)if(h.file){if(typeof h.patch=="string"){S.set(h.file,Ue(h.file,h.patch,"patch"));continue}typeof h.before!="string"&&typeof h.after!="string"||S.set(h.file,{original:h.before??"",modified:h.after??"",contextMode:"full"})}return S},[F]),x=r.useMemo(()=>{const S=new Map;for(const h of f)!h.file||typeof h.patch!="string"||S.set(h.file,Ue(h.file,h.patch,"patch"));return S},[f]);return{branchDiffs:f,branchDiffError:b,branchDiffLoading:c,lastTurnDiffs:F,lastTurnDiffData:k,branchDiffData:x}}const rt=(s,n)=>{if(n.length===0)return null;let e=null,i=null;for(const l of n)l.top<=s?(!e||l.top>e.top)&&(e=l):(!i||l.top<i.top)&&(i=l);const o=e??i;return o?{path:o.path,topOffset:o.top-s}:null},kn=(s,n,e,i)=>Math.min(Math.max(0,i),Math.max(0,s+e-n));function Rn({pinSelectedFileHeaderToTopOnNavigate:s,scrollRequestNonce:n,changedFiles:e,expandedFiles:i,setMountedStackedFiles:o,fileDiffRefreshNonce:l}){const f=r.useRef(null),d=r.useRef(new Map),[b,g]=r.useState(null),c=r.useRef(null),p=r.useRef(null),F=r.useRef(!1),k=r.useRef(null),x=r.useRef(i),S=r.useRef(null);r.useLayoutEffect(()=>{x.current=i},[i]);const h=r.useRef(null),$=r.useCallback(()=>{const w=f.current;if(!w)return null;const y=w.getBoundingClientRect().top,L=[];for(const[M,A]of d.current)A&&L.push({path:M,top:A.getBoundingClientRect().top});return rt(y,L)},[]),m=r.useCallback(()=>{c.current=null,F.current=!1,g(null),p.current!==null&&(window.cancelAnimationFrame(p.current),p.current=null)},[]),V=r.useCallback(()=>{k.current=null;const w=f.current;if(!w)return;const y=w.getBoundingClientRect(),L=y.top-st,M=y.bottom+st,A={},_=[];for(const[N,z]of d.current){if(!z)continue;const q=z.getBoundingClientRect();_.push({path:N,top:q.top}),x.current.has(N)&&(q.bottom<L||q.top>M||(A[N]=!0))}S.current=rt(y.top,_),o(N=>{let z=!1;const q=new Set(N);for(const K of Object.keys(A))q.has(K)||(q.add(K),z=!0);return z?q:N})},[o]),R=r.useCallback(()=>{typeof window>"u"||k.current===null&&(k.current=window.requestAnimationFrame(V))},[V]);r.useEffect(()=>{const w=f.current;if(w)return R(),w.addEventListener("scroll",R,{passive:!0}),window.addEventListener("resize",R),()=>{w.removeEventListener("scroll",R),window.removeEventListener("resize",R),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)}},[e,i,R]),r.useLayoutEffect(()=>{const w=h.current;if(!w)return;h.current=null;const y=f.current,L=d.current.get(w.path);if(!y||!L)return;const M=y.getBoundingClientRect().top,A=L.getBoundingClientRect().top-M;y.scrollTop=kn(y.scrollTop,w.topOffset,A,y.scrollHeight-y.clientHeight),S.current=w},[l]);const C=r.useCallback((w,y)=>{const L=d.current;y?L.set(w,y):L.delete(w),R()},[R]),E=r.useCallback(w=>{const y=d.current.get(w),L=f.current;if(!y||!L)return!1;const M=y.getBoundingClientRect().top-L.getBoundingClientRect().top;return L.scrollTo({top:L.scrollTop+M,behavior:"auto"}),!0},[]);return r.useEffect(()=>{if(!c.current)return;let y=0;const L=20;let M=!1;const A=(N=!0)=>{M||(M=!0,c.current=null,F.current=!1,N&&g(null),p.current!==null&&(window.cancelAnimationFrame(p.current),p.current=null))},_=()=>{if(M){p.current=null;return}const N=c.current;if(!N){A(),p.current=null;return}if(!E(N)){y+=1,y<L?p.current=window.requestAnimationFrame(_):(A(),p.current=null);return}if(s&&F.current){g(N),A(!1);return}A()};return p.current=window.requestAnimationFrame(_),()=>{M=!0,p.current!==null&&(window.cancelAnimationFrame(p.current),p.current=null)}},[s,n,E]),{diffScrollRef:f,fileSectionRefs:d,pinnedStackedTarget:b,pendingScrollTargetRef:c,shouldPinAfterAlignRef:F,pendingScrollAnchorRestoreRef:h,lastScrollAnchorRef:S,captureScrollAnchor:$,cancelPendingScrollAlignment:m,queueVisibleStackedFilesSync:R,registerSectionRef:C,scrollToFile:E}}const at=s=>{if(!s)return null;const n=s.split(`
18
+ `);let e=null;for(const i of n){const o=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(o){const l=Number.parseInt(o[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function En({effectiveDirectory:s,activeDiffStaged:n,git:e,files:i,setDiff:o,openContextFileAtLine:l}){const[f,d]=r.useState(null),b=r.useCallback(async(g,c)=>{if(!s||!g)return;d(g);const p=ot();try{let F=null;if(c?.patch&&!c.isBinary&&!Re(g)?F=at(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Re(g)&&(F=it(c.original,c.modified)),F===null)try{const $=await e.getGitDiff(s,{path:g,staged:n,contextLines:3});F=at($.diff)}catch{F=null}let k=c;if(F===null||!k){const $=await e.getGitFileDiff(s,{path:g,staged:n});k={original:$.original??"",modified:$.modified??"",isBinary:$.isBinary},n||o(s,g,k,p??void 0)}const x=F??(k.isBinary||Re(g)?1:it(k.original,k.modified)),S=Sn(s,g),h=await nn(i,S,{directory:s});if(!h.ok){dt.error(sn(h.reason));return}l(s,S,x,1)}finally{d(F=>F===g?null:F)}},[n,s,i,e,l,o]);return{openingEditorFilePath:f,openFileInEditorAtChange:b}}function An(s){const{hideStackedFileSidebar:n=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:o="all",branchBase:l=null,branchHead:f=null,targetFilePath:d=null}=s,{git:b,files:g}=ut(),c=zt(),{screenWidth:p,isMobile:F}=Ot(),k=Gt(c??null),x=Ht(c??null),S=Ut(c??null),h=ce(a=>a.setActiveDirectory),$=ce(a=>a.ensureStatus),m=ce(a=>a.fetchStatus),V=ce(a=>a.clearDiffCache),R=ce(a=>a.setDiff),[C,E]=r.useState(null),[w,y]=r.useState(!1),[L,M]=r.useState(()=>new Set),[A,_]=r.useState(()=>new Set),[N,z]=r.useState(!1),[q,K]=r.useState(0),[ie,ge]=r.useState(()=>new Map),[T,W]=r.useState(o);r.useEffect(()=>{W(o)},[o]);const Y=J(a=>a.pendingDiffFile),ae=J(a=>a.pendingDiffStaged),B=J(a=>a.pendingDiffScope),me=J(a=>a.setPendingDiffFile),Q=J(a=>a.diffLayoutPreference),H=J(a=>a.diffFileLayout),re=J(a=>a.setDiffFileLayout),ue=J(a=>a.diffWrapLinesOverride),Z=J(a=>a.wrapLinesByDefault),oe=J(a=>a.setDiffWrapLines),De=J(a=>a.openContextFileAtLine),xe=Vt(a=>a.currentSessionId),le=qt(xe??""),be=ue??Z,u=(T==="staged"?!0:T==="working"?!1:null)??w,P=F||p<=768,ne=!n&&!P&&p>=1024,de=r.useRef(null),{branchDiffs:ee,branchDiffError:ye,branchDiffLoading:we,lastTurnDiffs:O,lastTurnDiffData:te,branchDiffData:Ae}=Dn({activeDiffScope:T,effectiveDirectory:c,branchBase:l,branchHead:f,git:b,sessionMessageRecords:le}),D=r.useMemo(()=>{if(T==="turn"||T==="branch")return(T==="branch"?ee:O).map(I=>({path:I.file??"",index:"",working_dir:Ln(I.status),insertions:I.additions??0,deletions:I.deletions??0,isNew:I.status==="added"})).filter(I=>I.path).sort((I,X)=>I.path.localeCompare(X.path));if(!x?.files)return[];const a=x.diffStats??{},j=T==="staged"?Ge:T==="working"?He:()=>!0;return x.files.filter(j).map(v=>({...v,insertions:a[v.path]?.insertions??0,deletions:a[v.path]?.deletions??0,isNew:Qt(v)})).sort((v,I)=>v.path.localeCompare(I.path))},[T,ee,O,x]),U=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Te=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),$e=O.length,We=x?.files?.length??0,bt=ee.length,{diffScrollRef:yt,pinnedStackedTarget:wt,pendingScrollTargetRef:Fe,shouldPinAfterAlignRef:je,pendingScrollAnchorRestoreRef:Ve,lastScrollAnchorRef:qe,captureScrollAnchor:Ke,cancelPendingScrollAlignment:ve,queueVisibleStackedFilesSync:Me,registerSectionRef:Ft,scrollToFile:Xe}=Rn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:q,changedFiles:D,expandedFiles:L,setMountedStackedFiles:_,fileDiffRefreshNonce:ie}),Se=r.useCallback(a=>{M(j=>{if(j.has(a))return j;const v=new Set(j);return v.add(a),v})},[]),Ie=r.useRef(null),_e=r.useMemo(()=>D.map(a=>a.path).join("\0"),[D]);r.useEffect(()=>{const a=_e?_e.split("\0"):[],j=new Set(a),v=`${c??""}:${T}:${e?"collapsed":"default"}`,I=de.current!==v;de.current=v;const X=Ie.current,Ne=X&&j.has(X)?X:null;Ne&&(Ie.current=null),M(ke=>{if(I){const pe=e?0:vn(a.length),Je=new Set(a.slice(0,pe));return Ne&&Je.add(Ne),Je}let Ce=!1;const fe=new Set;for(const pe of ke){if(!j.has(pe)){Ce=!0;continue}fe.add(pe)}return Ne&&!fe.has(Ne)&&(fe.add(Ne),Ce=!0),Ce?fe:ke}),_(ke=>{if(I)return new Set;let Ce=!1;const fe=new Set;for(const pe of ke){if(!j.has(pe)){Ce=!0;continue}fe.add(pe)}return Ce?fe:ke})},[T,_e,c,_,e]);const Be=r.useCallback(a=>{const j=H[a.path];if(j)return j;if(Q==="inline")return"inline";if(Q==="side-by-side")return"side-by-side";const v=p<jn;return a.isNew||v?"inline":"side-by-side"},[H,Q,p]),jt=r.useMemo(()=>D.length===0?null:D.every(a=>Be(a)==="side-by-side")?"side-by-side":"inline",[D,Be]);r.useEffect(()=>{c&&(h(c),$(c,b))},[c,h,$,b]),r.useEffect(()=>{if(c)return Kt.onGitRefreshHint(a=>{Ye(a.directory)===Ye(c)&&(a.paths?.length&&(Ve.current=Ke()??qe.current,V(c,a.paths),ge(j=>{const v=new Map(j);for(const I of a.paths??[])v.set(I,(v.get(I)??0)+1);return v})),m(c,b,{silent:!0}))})},[Ke,V,c,m,b,qe,Ve]),r.useEffect(()=>{T!=="all"&&!B||Y&&(B&&W(B),E(Y),y(B==="staged"||!B&&ae),me(null),je.current=!0,Fe.current=Y,Ie.current=Y,Se(Y),K(a=>a+1))},[T,Se,Y,B,ae,Fe,me,je]),r.useEffect(()=>{if(T==="all")return;const a=d?.trim();a&&(E(a),y(T==="staged"),je.current=!0,Fe.current=a,Ie.current=a,Se(a),K(j=>j+1))},[T,Se,Fe,je,d]),r.useEffect(()=>{if(!C)return;D.some(j=>j.path===C)||(E(null),y(!1))},[D,C]);const vt=r.useCallback((a,j)=>{ve(),M(v=>{const I=v.has(a);if(j===I)return v;const X=new Set(v);return j?X.add(a):X.delete(a),X}),_(v=>{const I=v.has(a);if(j===I)return v;const X=new Set(v);return j?X.add(a):X.delete(a),X}),Me()},[ve,Me,_]),St=r.useCallback(()=>{ve(),M(a=>a.size>0?new Set:new Set(D.map(j=>j.path))),_(new Set),Me()},[ve,D,Me,_]),Nt=r.useCallback(a=>{},[]),Ct=r.useCallback(a=>{ve(),E(a),y(!1),je.current=!0,Fe.current=a,Se(a),K(j=>j+1),Xe(a)},[ve,Se,Fe,Xe,je]),Lt=r.useCallback(a=>{const j=a==="side-by-side"?"side-by-side":"inline";D.forEach(v=>{re(v.path,j)})},[D,re]),{openingEditorFilePath:Dt,openFileInEditorAtChange:kt}=En({effectiveDirectory:c,activeDiffStaged:u,git:b,files:g,setDiff:R,openContextFileAtLine:De});return{git:b,files:g,effectiveDirectory:c,screenWidth:p,isMobile:F,isGitRepo:k,status:x,isLoadingStatus:S,activeDiffScope:T,setActiveDiffScope:W,branchDiffs:ee,branchDiffError:ye,branchDiffLoading:we,diffWrapLines:be,setDiffWrapLines:oe,displayFileStaged:w,displayFile:C,pinnedStackedTarget:wt,expandedFiles:L,mountedStackedFiles:A,loadFullFiles:N,setLoadFullFiles:z,fileDiffRefreshNonce:ie,showFileSidebar:ne,diffScrollRef:yt,lastTurnDiffData:te,branchDiffData:Ae,changedFiles:D,workingFileCount:U,stagedFileCount:Te,turnFileCount:$e,allFileCount:We,branchFileCount:bt,currentLayoutForAllFiles:jt,openingEditorFilePath:Dt,registerSectionRef:Ft,handleStackedEntryExpandedChange:vt,handleExpandOrCollapseAll:St,handleSelectFile:Nt,handleSelectFileAndScroll:Ct,handleHeaderLayoutChange:Lt,openFileInEditorAtChange:kt,getLayoutForFile:Be}}const Rs=({hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:n=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:o="all",onDiffScopeChange:l,branchBase:f=null,branchHead:d=null,targetFilePath:b=null,flushContent:g=!1,hideToolbar:c=!1,onHeaderControlsStateChange:p,toolbarSlot:F=null,onlyFilePath:k=null})=>{const{effectiveDirectory:x,isGitRepo:S,status:h,isLoadingStatus:$,activeDiffScope:m,setActiveDiffScope:V,branchDiffError:R,branchDiffLoading:C,diffWrapLines:E,setDiffWrapLines:w,displayFileStaged:y,displayFile:L,pinnedStackedTarget:M,expandedFiles:A,mountedStackedFiles:_,loadFullFiles:N,setLoadFullFiles:z,fileDiffRefreshNonce:q,showFileSidebar:K,diffScrollRef:ie,lastTurnDiffData:ge,branchDiffData:T,changedFiles:W,workingFileCount:Y,stagedFileCount:ae,turnFileCount:B,allFileCount:me,branchFileCount:Q,currentLayoutForAllFiles:H,openingEditorFilePath:re,registerSectionRef:ue,handleStackedEntryExpandedChange:Z,handleExpandOrCollapseAll:oe,handleSelectFile:De,handleSelectFileAndScroll:xe,handleHeaderLayoutChange:le,openFileInEditorAtChange:be,getLayoutForFile:Ee}=An({hideStackedFileSidebar:s,stackedDefaultCollapsedAll:n,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:o,branchBase:f,branchHead:d,targetFilePath:b});r.useEffect(()=>{c&&l?.(m)},[m,c,l]);const u=r.useCallback(()=>{z(D=>!D)},[z]),P=r.useCallback(()=>{w(!E)},[E,w]),ne=r.useCallback(()=>{le(H==="side-by-side"?"unified":"side-by-side")},[H,le]),de=A.size,ee=k&&m!=="turn"&&m!=="branch"?W.find(D=>D.path===k)??null:null,ye=ee?[ee]:W,we=r.useMemo(()=>({turnCount:B,branchCount:Q,focusedFilePath:ee?.path??null,expandedCount:de,totalCount:W.length,loadFullFiles:N,wrapLines:E,layoutMode:H,onExpandOrCollapseAll:oe,onToggleLoadFullFiles:u,onToggleWrapLines:P,onToggleLayout:ne}),[B,Q,ee,de,W.length,N,E,H,oe,u,P,ne]);r.useEffect(()=>{c&&p?.(we)},[c,we,p]);const O=()=>{if(!x)return null;const D={path:L,staged:y};return t.jsxs("div",{className:se("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[K&&t.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[t.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:W.length})]}),t.jsx(fn,{changedFiles:W,selectedFile:null,onSelectFile:xe})]}),t.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:t.jsxs(lt,{ref:ie,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none]",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:[t.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:ye.map(U=>{const Te=pn(m,U,D);return t.jsx(Fn,{directory:x,file:U,layout:Ee(U),wrapLines:E,isSelected:!1,isExpanded:A.has(U.path),isMounted:_.has(U.path)||U.path===M,onSelect:De,onExpandedChange:Z,registerSectionRef:ue,showOpenInEditorAction:i&&m!=="turn"&&m!=="branch",isOpeningInEditor:re===U.path,onOpenInEditor:($e,We)=>{be($e,We)},diffSource:Te.source,staged:Te.staged,stageLabel:hn(m,U),partlyStaged:mt(m,U),showFileActions:m!=="turn"&&m!=="branch",loadFullFiles:N,initialDiffData:m==="turn"?ge.get(U.path)??null:m==="branch"?T.get(U.path)??null:null},`${U.path}:${q.get(U.path)??0}`)})}),t.jsx("div",{"aria-hidden":"true",className:"h-16 shrink-0"})]})})]})},te=()=>x?m!=="turn"&&$&&!h?t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(G,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):m!=="turn"&&m!=="branch"&&S===!1?t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):m==="branch"&&C?t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(G,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):m==="branch"&&R?t.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${R}`}):W.length===0?t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:m==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):O():t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),Ae=t.jsxs("div",{className:F?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(S!==!1||m==="turn")&&(m==="all"||m==="working"||m==="staged"||m==="turn"||m==="branch")?t.jsx(Zt,{scope:m,isGitRepo:S,branchAvailable:!!(f&&d),allCount:me,workingCount:Y,stagedCount:ae,turnCount:B,branchCount:Q,focusedFilePath:ee?.path??null,onScopeChange:D=>{V(D),l?.(D)}}):t.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:t.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:$&&!h?"Loading changes...":W.length===1?`${W.length} file changed`:`${W.length} files changed`})}),W.length>0&&t.jsxs(Le,{variant:"ghost",size:"sm",onClick:oe,className:se("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:A.size>0?"Collapse all":"Expand all",children:[t.jsx(G,{name:"expand-up-down",className:"size-4"}),t.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:A.size>0?"Collapse all":"Expand all"})]}),W.length>0&&m!=="turn"&&m!=="branch"&&t.jsxs(Xt,{children:[t.jsx(Jt,{asChild:!0,children:t.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>z(D=>!D),"aria-pressed":N,"aria-label":N?"Unload full files":"Load full files",className:se("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",N&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(G,{name:"file-download",className:"size-4"})})}),t.jsx(Yt,{children:t.jsx("p",{children:N?"Unload full files":"Load full files"})})]}),W.length>0&&t.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>w(!E),className:se("h-5 w-5 p-0 transition-opacity",E?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:E?"Disable line wrap":"Enable line wrap",children:t.jsx(G,{name:"text-wrap",className:"size-4"})}),H&&t.jsx(ft,{mode:H==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[F?Rt.createPortal(Ae,F):c?null:Ae,te()]})};export{Rs as DiffView};
@@ -1,3 +1,3 @@
1
- import{j as r}from"./vendor-boot-CoTxysn6.js";import{R as a}from"./vendor-react-Bz1tRBxM.js";import{D}from"./vendor-react-drawio-IYnLUY5N.js";import{f as C}from"./index-C2ISrmRR.js";import{av as E,aw as S,ax as N,ay as B,az as A,aA as F,B as p}from"./useAppFontEffects-D_gtiA95.js";const H='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const T=a.forwardRef(function({xml:e,readOnly:s,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[o,y]=a.useState(w),f=a.useRef(e),h=a.useRef(e);h.current!==e&&(h.current=e,f.current=e,l.current=e);const v=a.useRef(o);v.current!==o&&(v.current=o,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>y(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const R=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),j=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||H,autosave:!0,urlParameters:{ui:s?"simple":o?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:R,onAutoSave:j},o?"dark":"light")})}),X=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},G=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},W=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
1
+ import{j as r}from"./vendor-boot-Ciu-Edvy.js";import{R as a}from"./vendor-react-Bz1tRBxM.js";import{D}from"./vendor-react-drawio-IYnLUY5N.js";import{f as C}from"./index-Cfrwo5uQ.js";import{av as E,aw as S,aB as N,ax as B,ay as F,aC as H,B as p}from"./useAppFontEffects-CoFst31H.js";const A='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const T=a.forwardRef(function({xml:e,readOnly:s,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[o,y]=a.useState(w),f=a.useRef(e),h=a.useRef(e);h.current!==e&&(h.current=e,f.current=e,l.current=e);const v=a.useRef(o);v.current!==o&&(v.current=o,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>y(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const R=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),j=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||A,autosave:!0,urlParameters:{ui:s?"simple":o?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:R,onAutoSave:j},o?"dark":"light")})}),X=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},G=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},W=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
2
2
 
3
- … truncated …`:t,Y=({open:t,conflict:e,isResolving:s,showCompare:d,onToggleCompare:u,onReload:m,onOverwrite:l,onClose:c})=>{if(!e)return null;const i=!e.exists;return r.jsx(E,{open:t,onOpenChange:o=>{o||c()},children:r.jsxs(S,{showCloseButton:!1,className:"max-w-lg",children:[r.jsxs(N,{children:[r.jsx(B,{children:i?"File deleted on disk":"File changed on disk"}),r.jsx(A,{children:i?`“${e.displayPath}” was deleted since you opened it. Your edits are preserved. Reload to discard them, or overwrite to recreate the file.`:`“${e.displayPath}” changed since you opened it. Your edits are preserved. Reload to discard them and load the current version, or overwrite to keep your edits.`})]}),d&&!i?r.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto py-2",children:[r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Current version on disk"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.currentContent??"")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Your edits"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.dirtyContent)})]})]}):null,r.jsxs(F,{className:"flex flex-wrap gap-2",children:[i?null:r.jsx(p,{variant:"outline",onClick:u,disabled:s,"aria-label":d?"Hide version comparison":"Compare versions",title:d?"Hide version comparison":"Compare versions",children:d?"Hide compare":"Compare"}),r.jsx(p,{variant:"outline",onClick:m,disabled:s,"aria-label":i?"Discard edits and close":"Reload current version",title:i?"Discard edits and close":"Reload current version",children:i?"Discard edits":"Reload"}),r.jsx(p,{variant:"destructive",onClick:l,disabled:s,"aria-label":i?"Recreate file with my edits":"Overwrite with my edits",title:i?"Recreate file with my edits":"Overwrite with my edits",children:s?"Working…":"Overwrite"})]})]})})};export{T as D,Y as F,G as b,W as i,X as s};
3
+ … truncated …`:t,Y=({open:t,conflict:e,isResolving:s,showCompare:d,onToggleCompare:u,onReload:m,onOverwrite:l,onClose:c})=>{if(!e)return null;const i=!e.exists;return r.jsx(E,{open:t,onOpenChange:o=>{o||c()},children:r.jsxs(S,{showCloseButton:!1,className:"max-w-lg",children:[r.jsxs(N,{children:[r.jsx(B,{children:i?"File deleted on disk":"File changed on disk"}),r.jsx(F,{children:i?`“${e.displayPath}” was deleted since you opened it. Your edits are preserved. Reload to discard them, or overwrite to recreate the file.`:`“${e.displayPath}” changed since you opened it. Your edits are preserved. Reload to discard them and load the current version, or overwrite to keep your edits.`})]}),d&&!i?r.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto py-2",children:[r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Current version on disk"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.currentContent??"")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Your edits"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.dirtyContent)})]})]}):null,r.jsxs(H,{className:"flex flex-wrap gap-2",children:[i?null:r.jsx(p,{variant:"outline",onClick:u,disabled:s,"aria-label":d?"Hide version comparison":"Compare versions",title:d?"Hide version comparison":"Compare versions",children:d?"Hide compare":"Compare"}),r.jsx(p,{variant:"outline",onClick:m,disabled:s,"aria-label":i?"Discard edits and close":"Reload current version",title:i?"Discard edits and close":"Reload current version",children:i?"Discard edits":"Reload"}),r.jsx(p,{variant:"destructive",onClick:l,disabled:s,"aria-label":i?"Recreate file with my edits":"Overwrite with my edits",title:i?"Recreate file with my edits":"Overwrite with my edits",children:s?"Working…":"Overwrite"})]})]})})};export{T as D,Y as F,G as b,W as i,X as s};
@@ -0,0 +1,6 @@
1
+ import{aj as Lo,cg as zt,ch as $n,E as c,ah as Fs,Q as we,ci as Io,cj as $o,O as Es,M as Tt,ap as qn,S as Bo,aq as an,j as e,ak as Vo,c7 as Wo,af as _o,ck as Ko,ca as ut,cl as Vr,c6 as qo,J as Ho,U as zn,cm as Go,cn as Uo,c9 as Xo,aP as Jo,co as Yo,X as Qo,L as Zo}from"./vendor-boot-Ciu-Edvy.js";import{R as a,a as w}from"./vendor-react-Bz1tRBxM.js";import{f as X,a as zs,ai as Ms,a5 as ei,j as ti,cP as ni,M as ri,cQ as si,h as ye,cR as Ds,aC as Oe,b as ai,o as oi,H as ii,cI as bt,cK as ci,bV as li,A as Wr,cS as ui,a4 as _r,z as Kr,O as Mn,av as di}from"./index-Cfrwo5uQ.js";import{dv as fi,cJ as jt,B as U,I as F,b2 as Dt,dw as mi,av as Ts,aw as As,aB as Os,ax as Ps,ay as Ls,aC as Is,a$ as on,b0 as cn,b1 as ln,ah as nn,t as he,bu as fe,bM as Bn,dx as rn,aP as $s,E as qr,aQ as pi,dy as Bs,d3 as Vs,dz as Ws,d2 as _s,d1 as Vn,d4 as hi,aR as it,aS as ct,aT as lt,dA as gi,dB as xi,dC as vi,z as bi,bN as yi,as as wi,y as ji,cK as ki,dD as Hr,cL as Gr,az as Ci,dE as Ur,a as Ni,bP as Si}from"./useAppFontEffects-CoFst31H.js";import{javascript as yt}from"./vendor-codemirror-lang-javascript-B1zJk7xE.js";import{json as Ks}from"./vendor-codemirror-lang-json-C0pZ0NhY.js";import{css as qs}from"./vendor-codemirror-lang-css-dF-Dxbty.js";import{html as Wn}from"./vendor-codemirror-lang-html-DKcbBVQ4.js";import{markdown as Hs}from"./vendor-codemirror-lang-markdown-_6ojeUuZ.js";import{l as Gs}from"./vendor-codemirror-language-data-CSid5JuX.js";import{python as Us}from"./vendor-codemirror-lang-python-Byr5gw5f.js";import{shell as Ri}from"./shell-CjFT_Tl9.js";import{ensurePierreThemeRegistered as Xr,getResolvedShikiTheme as Fi}from"./appThemeRegistry-Ca8eGRB9.js";import{D as Ei,i as Xs,b as Js,s as zi,F as Mi}from"./FileSaveConflictDialog-p1ik30al.js";import{h as Jr,aG as Di,aH as Ti,aI as Ai,aJ as Oi,aK as Pi,aQ as en}from"./runtimeEndpointReset-D8lAOCUB.js";import{e as _n,h as Ys,i as Qs}from"./SessionUnreadDot-DXUn8-ss.js";import{F as Zs,a as Li,g as kt,j as ea,k as ta,l as un,n as Ii,m as $i,M as Mt,o as ce,p as Bi,i as Vi,s as Wi,b as _i,c as Ki,q as qi,f as Hi,t as tn,r as Dn,d as Gi,v as Ui,u as Xi,w as Yr,x as Ji,e as Qr,y as Yi,h as Qi}from"./fileTreeStatus-CPTpyKOV.js";import{J as Zi,F as ec}from"./JsonTreeView-CEiJsFnP.js";import{a as Zr,g as sn,b as es,c as ts,o as tc,d as nc}from"./vendor-codemirror-search-8lY3lt6q.js";import{v as rc,g as sc}from"./vendor-replit-codemirror-vim-7IE2zVmx.js";import{P as ac,S as oc}from"./StickyHorizontalScrollbar-CONTbZgX.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CXhN0IMY.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-BKkUfl9q.js";import"./vendor-fuse.js-t_7AcMTv.js";import"./runtimeSurface-C3YPOBlg.js";import"./nativeFileSave-P_Eg5Dgb.js";import"./vendor-lezer-javascript-CiQ9F8yX.js";import"./vendor-lezer-lr-BVsDua_K.js";import"./vendor-codemirror-autocomplete-CInQsE8a.js";import"./vendor-lezer-json-BxN83KKR.js";import"./vendor-lezer-css-6qV4fYNQ.js";import"./vendor-lezer-html-BjqcY-oJ.js";import"./vendor-lezer-markdown-BkMtRQ3X.js";import"./vendor-lezer-python-D342CidI.js";import"./registerCustomTheme-C-h6lsYW.js";import"./themeResolver-DrfmQi8i.js";import"./vendor-pierre-theming-BO6EPniU.js";import"./vendor-shikijs-core-Ck_OPM_T.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-DPFxvYtK.js";import"./vendor-hast-util-to-html-O3stl53j.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-C40bX6nM.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-react-drawio-IYnLUY5N.js";/* empty css */import"./permissionStore-zIpxq9Pq.js";import"./web-components-CzkvK_V5.js";import"./computeVirtualFileMetrics-CzkFqhaU.js";import"./vendor-shiki-BEwTOAFg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-DL394yyj.js";import"./vendor-oniguruma-to-es-DgwFOwdE.js";import"./vendor-oniguruma-parser-BrbMHgHx.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-cIf8dSOQ.js";import"./renderFileWithHighlighter-B_PFeRW5.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";const Kn=Lo.define(Ri);function ic(t){const n=t.trim().toLowerCase();switch(n){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return Kn;case"json":case"jsonc":case"json5":return Ks().language;case"js":case"javascript":return yt().language;case"jsx":return yt({jsx:!0}).language;case"ts":case"typescript":return yt({typescript:!0}).language;case"tsx":return yt({typescript:!0,jsx:!0}).language;case"html":return Wn().language;case"css":return qs().language;case"py":case"python":return Us().language;case"md":case"markdown":case"mdown":case"mkd":return Hs().language;case"heex":case"eex":case"leex":return Wn().language;default:return Fs.matchLanguageName(Gs,n,!0)}}const na=t=>t.split("/").pop()?.toLowerCase()??"",cc=t=>{const n=na(t);return n?Fs.matchFilename(Gs,n):null},lc=()=>zt($n.define([{tag:[c.heading1,c.heading2,c.heading3,c.heading4,c.heading5,c.heading6],fontWeight:"600"},{tag:c.strong,fontWeight:"600"},{tag:c.emphasis,fontStyle:"italic"},{tag:c.strikethrough,textDecoration:"line-through"},{tag:[c.link,c.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:c.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:c.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:c.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:c.heading,color:"var(--markdown-heading1, currentColor)"}]));function uc(t){const n=t.toLowerCase();switch(na(n)){case"makefile":case"gnumakefile":return Kn}const i=n.lastIndexOf("."),o=i>=0?n.slice(i+1):"";switch(o){case"ts":case"tsx":case"mts":case"cts":return yt({typescript:!0,jsx:o==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return yt({typescript:!1,jsx:o==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Ks();case"css":case"scss":case"sass":case"less":return qs();case"html":case"htm":case"xml":case"drawio":case"dio":return Wn();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Hs({codeLanguages:ic}),lc()];case"sh":case"bash":case"zsh":case"fish":case"env":return Kn;case"py":case"pyw":case"pyi":return Us();default:return null}}async function dc(t){const n=cc(t);if(!n)return null;if(n.support)return n.support;try{return await n.load()}catch{return null}}function ns(t,n){const s=t.metadata.variant==="dark",i=t.config?.fonts?.mono||"monospace",o=t.colors.syntax.highlights||{},u=t.colors.syntax.tokens||{},f=n?.fontSize?`${n.fontSize}px`:"var(--text-code)",d=we.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:f,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:i,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:u.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:u.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:u.boolean||t.colors.syntax.base.number},".cm-builtin":{color:u.functionCall||t.colors.syntax.base.function},".cm-def":{color:u.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:u.variableOther||u.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:u.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:u.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:u.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:u.tag||t.colors.syntax.base.keyword},".cm-link":{color:u.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:o.lineNumber||"var(--subtle-foreground)",borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"10px",minWidth:"2ch",boxSizing:"content-box"},".cm-activeLineGutter":{color:o.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.elevated,color:t.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:s}),h=$n.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],class:"cm-comment"},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],class:"cm-keyword"},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],class:"cm-operator"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],class:"cm-punctuation"},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],class:"cm-string"},{tag:c.escape,class:"cm-string-2"},{tag:[c.number,c.bool,c.atom,c.null,c.self],class:"cm-number"},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],class:"cm-builtin"},{tag:c.definition(c.variableName),class:"cm-def"},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],class:"cm-variable"},{tag:c.propertyName,class:"cm-property"},{tag:c.attributeName,class:"cm-attribute"},{tag:[c.className,c.typeName,c.namespace],class:"cm-variable-3"},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],class:"cm-tag"},{tag:c.link,class:"cm-link"},{tag:[c.heading,c.heading1,c.heading2,c.heading3,c.heading4,c.heading5,c.heading6],class:"cm-keyword"}]),C=$n.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],color:t.colors.syntax.base.comment},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],color:t.colors.syntax.base.keyword},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],color:t.colors.syntax.base.operator},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],color:t.colors.syntax.base.string},{tag:c.escape,color:u.stringEscape||t.colors.syntax.base.string},{tag:[c.number,c.bool,c.atom,c.null,c.self],color:t.colors.syntax.base.number},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],color:t.colors.syntax.base.function},{tag:c.definition(c.variableName),color:u.variableGlobal||t.colors.syntax.base.variable},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],color:t.colors.syntax.base.variable},{tag:c.propertyName,color:u.variableProperty||t.colors.syntax.base.variable},{tag:c.attributeName,color:u.variableOther||t.colors.syntax.base.variable},{tag:[c.className,c.typeName,c.namespace],color:t.colors.syntax.base.type},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],color:u.tag||t.colors.syntax.base.keyword},{tag:c.link,color:u.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],color:u.punctuation||t.colors.syntax.base.comment}]);return n?.syntaxColors===!1?[d]:[d,zt(Io,{fallback:!0}),zt($o),zt(h),zt(C)]}const fc=180,ra=Bo.define(),mc=1,pc=2,hc=4,rs=new Map,gc=(t,n)=>{const s=`${t}|${n}`,i=rs.get(s);if(i)return i;let o="";t&&(o+=`color:${t};`),n&mc&&(o+="font-style:italic;"),n&pc&&(o+="font-weight:bold;"),n&hc&&(o+="text-decoration:underline;");const u=Tt.mark({attributes:{style:o}});return rs.set(s,u),u},xc=(t,n)=>{const s=new an,i=t.state.doc,o=Math.min(n.length,i.lines);for(let u=0;u<o;u+=1){const f=n[u];if(!f||f.length===0)continue;const d=i.line(u+1);let h=d.from;for(const[C,z,b]of f){if(C<=0)continue;const v=h,k=Math.min(h+C,d.to);h+=C,!(k<=v)&&(!z&&!b||s.add(v,k,gc(z,b)))}}return s.finish()},vc=Es.define({create(){return Tt.none},update(t,n){let s=t.map(n.changes);for(const i of n.effects)i.is(ra)&&(s=i.value);return s},provide:t=>we.decorations.from(t)}),bc=t=>qn.fromClass(class{timer;generation=0;constructor(n){this.tokenize(n)}update(n){n.docChanged&&this.schedule(n.view)}schedule(n){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(n)},fc)}async tokenize(n){const s=++this.generation,i=n.state.doc.toString(),o=await fi(i,t.language,t.themeName,t.theme);o&&s===this.generation&&n.state.doc.length===i.length&&n.dispatch({effects:ra.of(xc(n,o))})}destroy(){this.timer&&clearTimeout(this.timer)}}),yc=t=>[vc,bc(t)],Ue=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/g,""),wt=t=>{const n=Ue(t);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},sa=t=>{const n=Ue(t);if(!n||n==="/")return null;const s=n.lastIndexOf("/");if(s<0)return null;if(s===0)return"/";const i=n.slice(0,s);return/^[A-Za-z]:$/.test(i)?`${i}/`:i},ss=(t,n)=>{const s=Ue(t),i=Ue(n);return!s||!i?!1:s===i||s.startsWith(`${i}/`)},as=(t,n)=>{const s=Ue(t);if(!s)return Ue(n);if(s.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(s))return s;const i=Ue(n);return i?`${i}/${s}`:s},wc=(t,n)=>{const s=Ue(t),i=Ue(n);if(!s||s===i)return!1;const o=sa(s);return o?i&&ss(s,i)?ss(o,i):!0:!1},jc=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const n=["KB","MB","GB"];let s=t/1024;for(const i of n){if(s<1024||i===n[n.length-1])return`${s.toFixed(s>=10?0:1)} ${i}`;s/=1024}return""},kc=(t,n)=>!n||t===n?wt(t):t.startsWith(`${n}/`)?t.slice(n.length+1):t,Cc=({root:t,directory:n,entries:s,query:i,searchResults:o,isSearching:u,searchFailed:f,directoryError:d,refreshing:h,editorPath:C,editor:z,onClose:b,onQueryChange:v,onOpenDirectory:k,onOpenFile:j,onBackFromEditor:y,onRefresh:L})=>{if(!t)return e.jsx(Ct,{message:"Select a project to browse files."});if(C)return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[e.jsx(Jr,{leading:e.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":"Back",onClick:y,style:{touchAction:"manipulation"},children:e.jsx(F,{name:"arrow-left",className:"size-4"})}),icon:e.jsx(jt,{filePath:C,className:"size-4 shrink-0"}),title:wt(C)}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:z})]});const K=n===t?"Project files":wt(n),l=wc(n,t)?sa(n):null,$=!!l&&!i.trim(),q=l===t?"Project files":wt(l??""),I=b||$&&l?e.jsxs(e.Fragment,{children:[b?e.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":"Close",onClick:b,style:{touchAction:"manipulation"},children:e.jsx(F,{name:"close",className:"size-4"})}):null,$&&l?e.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":`Back to ${wt(l)}`,onClick:()=>k(l),style:{touchAction:"manipulation"},children:e.jsx(F,{name:"arrow-left",className:"size-4"})}):null]}):void 0;return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[e.jsx(Jr,{leading:I,icon:n===t?"file-text":"folder",title:K,actions:e.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":"Refresh files",onClick:L,style:{touchAction:"manipulation"},children:e.jsx(F,{name:"refresh",className:X("size-4",h&&"animate-spin")})})}),e.jsx("div",{className:"shrink-0 px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Dt,{value:i,onChange:M=>v(M.target.value),placeholder:"Search files",className:"h-8 pl-7"})]})}),e.jsx(mi,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:d?e.jsx(Ct,{message:d}):i.trim()?e.jsx(Nc,{root:t,results:o,isSearching:u,failed:f,onOpenFile:j}):s===void 0?e.jsx(Ct,{loading:!0,message:"Loading..."}):e.jsxs("div",{className:"flex w-full min-w-0 flex-col px-1",children:[$&&l?e.jsxs("button",{type:"button",className:X(Qs,"px-2"),"aria-label":`Up one level to ${q}`,onClick:()=>k(l),style:{touchAction:"manipulation"},children:[e.jsx(F,{name:"arrow-left",className:X(_n(!0),"text-muted-foreground")}),e.jsx("span",{className:X(Ys(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,s.length===0?e.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,s.map(M=>e.jsx(aa,{name:M.name,path:M.path,directory:M.type==="directory",meta:M.type==="directory"?void 0:jc(M.size),onClick:()=>M.type==="directory"?k(as(M.path,n||t)):j(as(M.path,n||t))},M.path))]})})]})},aa=({name:t,path:n,directory:s,meta:i,onClick:o})=>e.jsxs("button",{type:"button",className:X(Qs,"px-2"),onClick:o,style:{touchAction:"manipulation"},children:[s?e.jsx(F,{name:"folder-3-fill",className:X(_n(!0),"text-primary/80")}):e.jsx(jt,{filePath:n,className:_n(!0)}),e.jsx("span",{className:X(Ys(!0),"flex-1 text-foreground"),children:t}),i?e.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,s?e.jsx(F,{name:"arrow-right-s",className:"size-4 shrink-0 text-subtle-foreground"}):null]}),Nc=({root:t,results:n,isSearching:s,failed:i,onOpenFile:o})=>s?e.jsx(Ct,{loading:!0,message:"Loading..."}):i?e.jsx(Ct,{message:"Search failed. Edit the search to try again."}):n.length===0?e.jsx(Ct,{message:"No files found."}):e.jsx("div",{className:"flex w-full min-w-0 flex-col px-1",children:n.map(u=>e.jsx(aa,{name:wt(u.path),path:u.path,directory:!1,meta:u.relativePath??kc(u.path,t),onClick:()=>o(u.path)},u.path))}),Ct=({message:t,loading:n=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[n?e.jsx(F,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):e.jsx(F,{name:"folder-open-fill",className:"size-6 text-muted-foreground"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t})]})}),Sc=({activeDialog:t,dialogData:n,dialogInputValue:s,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:u,onClose:f,inputRef:d})=>e.jsx(Ts,{open:!!t,onOpenChange:h=>!h&&f(),children:e.jsxs(As,{initialFocus:d,children:[e.jsxs(Os,{children:[e.jsxs(Ps,{children:[t==="createFile"&&"Create file",t==="createFolder"&&"Create folder",t==="rename"&&"Rename",t==="delete"&&"Delete"]}),e.jsxs(Ls,{children:[t==="createFile"&&`Create a new file in ${n?.path??"root"}`,t==="createFolder"&&`Create a new folder in ${n?.path??"root"}`,t==="rename"&&`Rename ${n?.name??""}`,t==="delete"&&`Are you sure you want to delete ${n?.name??""}? This action cannot be undone.`]})]}),t!=="delete"&&e.jsx("div",{className:"py-4",children:e.jsx(Dt,{value:s,onChange:h=>i(h.target.value),placeholder:t==="rename"?"New name":"Name",onKeyDown:h=>{h.key==="Enter"&&u()},ref:d})}),e.jsxs(Is,{children:[e.jsx(U,{variant:"outline",onClick:f,disabled:o,children:"Cancel"}),e.jsx(U,{variant:t==="delete"?"destructive":"default",onClick:()=>{u()},disabled:o||t!=="delete"&&!s.trim(),children:o?e.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}):t==="delete"?"Delete":"Confirm"})]})]})}),oa=({label:t,iconDataUrl:n})=>{const[s,i]=a.useState(!1),o=t.trim().slice(0,1).toUpperCase()||"?";return n&&!s?e.jsx("img",{src:n,alt:"",className:"size-4 rounded-sm",onError:()=>i(!0)}):e.jsx("span",{className:X("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:o})},Rc=({filePath:t,extension:n})=>e.jsx(jt,{filePath:t,extension:n}),os=({name:t})=>{const n=a.useRef(null),s=a.useRef(null),[i,o]=a.useState(!1);return a.useLayoutEffect(()=>{const u=n.current,f=s.current;if(!u||!f)return;const d=()=>{o(f.scrollWidth>u.clientWidth+1)};d();const h=new ResizeObserver(d);return h.observe(u),h.observe(f),()=>{h.disconnect()}},[t]),e.jsxs("span",{ref:n,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{ref:s,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:t}),i?e.jsxs("span",{className:"open-file-name-marquee-track",children:[e.jsx("span",{className:"open-file-name-marquee-item",children:t}),e.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:t})]}):e.jsx("span",{className:"block min-w-0 truncate",children:t})]})},Fc=({node:t,root:n,isExpanded:s,isActive:i,isMobile:o,isBrowserClient:u,alwaysShowActions:f,status:d,badge:h,permissions:C,downloadFile:z,contextMenuPath:b,setContextMenuPath:v,rightClickMenuPath:k,setRightClickMenuPath:j,onSelect:y,onToggle:L,onRevealPath:K,onOpenDialog:l})=>{const $=t.type==="directory",{canRename:q,canCreateFile:I,canCreateFolder:M,canDelete:H,canReveal:_}=C,J=!$&&!!z,A=zs()&&Ms(),D=_&&!u&&A,x=q||I||M||H||J||D,V=a.useCallback(R=>{x&&(R?.preventDefault(),j(t.path))},[x,t.path,j]),N=a.useCallback(()=>{$?L(t.path):y(t)},[$,t,y,L]),S=a.useCallback(R=>{R.stopPropagation(),j(null),v(t.path)},[t.path,v,j]),g=({Item:R,Separator:E})=>e.jsxs(e.Fragment,{children:[q&&e.jsxs(R,{onClick:P=>{P.stopPropagation(),l("rename",t)},children:[e.jsx(F,{name:"edit",className:"mr-2 size-4"})," ","Rename"]}),e.jsxs(R,{onClick:P=>{P.stopPropagation(),nn(t.path).then(Y=>{if(Y.ok){he.success("Path copied");return}he.error("Copy failed")})},children:[e.jsx(F,{name:"file-copy",className:"mr-2 size-4"})," ","Copy path"]}),e.jsxs(R,{onClick:P=>{P.stopPropagation();const Y=kt(n,t.path)||t.path;nn(Y).then(G=>{if(G.ok){he.success("Relative path copied");return}he.error("Copy failed")})},children:[e.jsx(F,{name:"file-copy-2",className:"mr-2 size-4"})," ","Copy relative path"]}),!$&&z&&e.jsxs(R,{onClick:P=>{P.stopPropagation(),z(t.path).catch(Y=>{console.error("Download failed:",Y),he.error("Operation failed")})},children:[e.jsx(F,{name:"download",className:"mr-2 size-4"})," ",u?"Download":"Save"]}),D&&e.jsxs(R,{onClick:P=>{P.stopPropagation(),K(t.path)},children:[e.jsx(F,{name:"folder-received",className:"mr-2 size-4"})," ",ei()]}),$&&(I||M)&&e.jsxs(e.Fragment,{children:[e.jsx(E,{}),I&&e.jsxs(R,{onClick:P=>{P.stopPropagation(),l("createFile",t)},children:[e.jsx(F,{name:"file-add",className:"mr-2 size-4"})," ","New file"]}),M&&e.jsxs(R,{onClick:P=>{P.stopPropagation(),l("createFolder",t)},children:[e.jsx(F,{name:"folder-add",className:"mr-2 size-4"})," ","New folder"]})]}),H&&e.jsxs(e.Fragment,{children:[e.jsx(E,{}),e.jsxs(R,{onClick:P=>{P.stopPropagation(),l("delete",t)},className:"text-destructive focus:text-destructive",children:[e.jsx(F,{name:"delete-bin",className:"mr-2 size-4"})," ","Delete"]})]})]});return e.jsxs(Di,{open:k===t.path,onOpenChange:R=>j(R?t.path:null),children:[e.jsxs(Ti,{render:e.jsx("div",{className:"group relative flex items-center",onContextMenu:o?void 0:V}),children:[e.jsxs("button",{type:"button",onClick:N,onContextMenu:o?void 0:V,className:X("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors select-none",x&&f&&"pr-8",x&&!f&&"group-hover:pr-8 group-focus-within:pr-8",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[$?s?e.jsx(F,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(F,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):e.jsx(Rc,{filePath:t.path,extension:t.extension}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:t.path,children:t.name}),!$&&d&&e.jsx(Zs,{status:d,className:x&&!f?"group-hover:invisible group-focus-within:invisible":void 0}),$&&h&&e.jsx(Li,{badge:h,className:x&&!f?"group-hover:invisible group-focus-within:invisible":void 0})]}),x&&e.jsx("div",{className:X("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:e.jsxs(on,{open:b===t.path,onOpenChange:R=>v(R?t.path:null),children:[e.jsx(cn,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon",className:"size-6",onClick:S,children:e.jsx(F,{name:"more-2-fill",className:"size-4"})})}),e.jsx(ln,{align:"end",side:"bottom",onCloseAutoFocus:()=>v(null),children:g({Item:fe,Separator:Bn})})]})})]}),e.jsx(Ai,{className:"min-w-[180px]",children:g({Item:Oi,Separator:Pi})})]})},Tn=(t,n,s)=>{const[i,o]=a.useState(""),[u,f]=a.useState(0);return a.useEffect(()=>{if(!t){o("");return}let d=!1;o("");const h=ti(),C=ni(h);ri(h).then(b=>{d||!b||(o(t),n(null))}).catch(b=>{d||(n(b instanceof Error?b.message:s),o(t))});const z=si(()=>{d||(o(t),f(b=>b+1),n(null))});return()=>{d=!0,C(),z()}},[t,n,s]),{readyKey:i,nonce:u}},Ec=t=>t!==null&&typeof t=="object"&&"updateStatus"in t&&typeof t.updateStatus=="function",zc=t=>{const n=document.createElement("div");n.className="cm-vim-panel";const s=sc(t);if(!s)return{top:!1,dom:n};s.state.statusbar=n;const i=s.state.vimPlugin;return Ec(i)&&i.updateStatus(),{top:!1,dom:n,destroy(){s.state.statusbar===n&&(s.state.statusbar=null)}}};function is(t){return t?[rc(),Vo.of(zc),Wo()]:[]}const Mc={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},Dc={case:"Match case",re:"Regular expression",word:"Match whole word"};function Tc(t){const n=t.querySelector(".cm-search");if(n){for(const[s,i]of Object.entries(Mc)){const o=n.querySelector(`button[name="${s}"]`);o&&!o.title&&(o.title=i)}for(const[s,i]of Object.entries(Dc)){const u=n.querySelector(`input[name="${s}"]`)?.parentElement;u&&!u.title&&(u.title=i)}}}const An=new WeakMap;function Ac(t,n){const s=sn(t.state);if(!s.valid)return An.delete(t),0;const i=An.get(t);if(!n&&i?.doc===t.state.doc&&i.query.eq(s))return i.total;const o=s.getCursor(t.state);let u=0;for(let f=o.next();!f.done;f=o.next())u+=1;return An.set(t,{query:s,doc:t.state.doc,total:u}),u}function Oc(t){const n=sn(t.state);if(!n.valid)return 0;const s=t.state.selection.main,i=n.getCursor(t.state);let o=0,u=0;for(let f=i.next();!f.done;f=i.next()){const d=f.value;if(o+=1,u===0&&(u=o),s.from===d.from&&s.to===d.to||s.from<d.to&&s.to>d.from||d.from>=s.head)return o}return u}function cs(t,n,s=!1){const i=t.querySelector(".cm-search");if(!i)return;let o=i.querySelector(".cm-search-message");if(!o){o=document.createElement("span"),o.className="cm-search-message",o.setAttribute("aria-live","polite");const d=i.querySelector('button[name="next"]'),h=d?.parentNode===i?d:i.firstChild;i.insertBefore(o,h)}const u=Ac(n,s),f=u===0?0:Oc(n);o.textContent=u===0?"":`${f}/${u}`}const ls=new ut,us=new ut,ds=new ut,fs=new ut,ms=new ut,ps=new ut,hs=new ut,gs=t=>t,On=Yo,Pc=tc,Lc=nc;class Ic extends Qo{constructor(n,s){super(),this.id=n,this.containerMap=s}id;containerMap;toDOM(){let n=this.containerMap.get(this.id);return n||(n=document.createElement("div"),n.className="oc-block-widget",n.dataset.widgetId=this.id,this.containerMap.set(this.id,n)),n}eq(n){return n.id===this.id}destroy(){}}const xs=(t,n)=>!t||t.length===0?[]:Es.define({create(s){const i=new an,o=[...t].sort((u,f)=>u.afterLine-f.afterLine);for(const u of o){const f=s.doc.lines;if(u.afterLine>f)continue;const d=s.doc.line(u.afterLine);i.add(d.to,d.to,Tt.widget({widget:new Ic(u.id,n),block:!0,side:1}))}return i.finish()},update(s,i){return s.map(i.changes)},provide:s=>we.decorations.from(s)}),vs=t=>{if(!t)return[];const n=Math.max(1,t.start),s=Math.max(n,t.end);return qn.fromClass(class{decorations;constructor(i){this.decorations=this.build(i)}update(i){(i.docChanged||i.viewportChanged)&&(this.decorations=this.build(i.view))}build(i){const o=new an;for(let u=n;u<=s&&u<=i.state.doc.lines;u+=1){const f=i.state.doc.line(u);o.add(f.from,f.from,Tt.line({class:"oc-cm-selected-line"}))}return o.finish()}},{decorations:i=>i.decorations})};function $c({value:t,onChange:n,extensions:s,className:i,readOnly:o,lineNumbersConfig:u,highlightLines:f,onViewReady:d,onViewDestroy:h,blockWidgets:C,enableSearch:z,searchOpen:b,onSearchOpenChange:v,vimMode:k}){const j=a.useRef(null),y=a.useRef(null),L=a.useRef(t),K=a.useRef(n),l=a.useRef(d),$=a.useRef(h),q=a.useRef(v),I=a.useRef(C),M=a.useRef(k),H=a.useRef(new Map),[_,J]=a.useState([]),A=a.useCallback(x=>{const V=(x??[]).map(N=>{const S=H.current.get(N.id);return S?{id:N.id,content:N.content,container:S}:null}).filter(N=>N!==null);J(N=>N.length===V.length&&N.every((S,g)=>{const R=V[g];return S.id===R.id&&S.content===R.content&&S.container===R.container})?N:V)},[]),D=a.useCallback(x=>{const V=j.current,N=x??y.current;if(!V||!N)return;const S=N.dom.querySelector(".cm-gutters"),g=S instanceof HTMLElement?S.getBoundingClientRect().width:0;V.style.setProperty("--oc-editor-gutter-width",`${g}px`)},[]);return a.useEffect(()=>{L.current=t},[t]),a.useEffect(()=>{K.current=n},[n]),a.useEffect(()=>{l.current=d,$.current=h},[d,h]),a.useEffect(()=>{q.current=v},[v]),a.useEffect(()=>{I.current=C,A(C)},[C,A]),a.useEffect(()=>{if(!j.current)return;const x=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const S=window.__PICHAMBER_CSP_NONCE__;return typeof S=="string"&&S.length>0?S:null})(),V=_o.create({doc:L.current,extensions:[...x?[we.cspNonce.of(x)]:[],Ko({fixed:!0}),ls.of(Vr(u)),qo(),Ho.of(" "),hs.of(is(k)),zn.of([Go,...Uo,...Xo]),we.updateListener.of(N=>{D(N.view),(N.viewportChanged||N.geometryChanged)&&A(I.current);const S=Zr(N.startState),g=Zr(N.state);S!==g&&q.current?.(g);const R=!sn(N.startState).eq(sn(N.state));if(g&&(S!==g||R||N.docChanged||N.selectionSet)&&cs(N.view.dom,N.view,S!==g||R||N.docChanged),!N.docChanged)return;const E=N.state.doc.toString();L.current=E,K.current(E),A(I.current)}),us.of(we.editable.of(!o)),ds.of(s??[]),fs.of(vs(f)),ms.of(xs(C,H.current)),ps.of(z?[es({top:!0}),zn.of(gs(ts))]:[])]});return y.current=new we({state:V,parent:j.current}),On(y.current,y.current.state.doc.length,200),y.current.requestMeasure(),requestAnimationFrame(()=>{D(y.current),A(I.current)}),y.current&&l.current?.(y.current),()=>{$.current?.(),y.current?.destroy(),y.current=null,J([])}},[I,D,A]),a.useEffect(()=>{const x=y.current;x&&(x.dispatch({effects:[ls.reconfigure(Vr(u)),us.reconfigure(we.editable.of(!o)),ds.reconfigure(s??[]),fs.reconfigure(vs(f)),ms.reconfigure(xs(C,H.current)),ps.reconfigure(z?[es({top:!0}),zn.of(gs(ts))]:[])]}),On(x,x.state.doc.length,200),x.requestMeasure(),requestAnimationFrame(()=>{D(x),A(I.current)}))},[s,f,u,o,C,z,D,A]),a.useEffect(()=>{const x=y.current;if(!x){M.current=k;return}M.current!==k&&(M.current=k,x.dispatch({effects:hs.reconfigure(is(k))}))},[k]),a.useEffect(()=>{const x=y.current;!x||z===!1||(b?(Pc(x),requestAnimationFrame(()=>{Tc(x.dom),cs(x.dom,x,!0)})):Lc(x))},[b,z]),a.useEffect(()=>{const x=y.current;if(!x)return;const V=x.state.doc.toString();V!==t&&(x.dispatch({changes:{from:0,to:V.length,insert:t}}),On(x,x.state.doc.length,300),x.requestMeasure(),requestAnimationFrame(()=>D(x)))},[t,D]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:j,className:X("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",i)}),_.map(x=>Jo.createPortal(x.content,x.container,x.id))]})}const bs=({variant:t,selectedFile:n,loading:s,suppressLoadingIndicator:i,fileError:o,isSelectedImage:u,imageSrc:f,imagePreviewNonce:d,isSelectedPdf:h,pdfSrc:C,pdfPreviewNonce:z,isUnsupportedBinary:b,onDownload:v,enableRichPreviews:k,drawioViewMode:j,drawioRemountNonce:y,diagramEditorRef:L,diagramEditorXml:K,onDiagramChange:l,jsonViewMode:$,markdownViewMode:q,htmlViewMode:I,htmlLoading:M,htmlPreviewNonce:H,htmlPreviewSrc:_,fileContent:J,canUseShikiFileView:A,textViewMode:D,draftContent:x,onDraftChange:V,canEdit:N,vimMode:S,editorExtensions:g,editorWrapperRef:R,shouldMaskEditorForPendingNavigation:E,onEditorViewReady:P,onEditorViewDestroy:Y,enableSearch:G=!1,searchOpen:Z,onSearchOpenChange:ie,pierreTheme:W,shikiThemeType:te,wrapLines:Pe})=>{const xe=t==="fullscreen",le=xe?"p-4":"p-3",Fe=!!(n?.path&&rn(n.path)),se=!!(n?.path&&ea(n.path)),me=!!(n?.path&&ta(n.path)),Ce=!!(n?.path&&un(n.path)),ne=a.useRef(null),re=()=>n?e.jsxs("div",{className:"relative h-full",ref:ne,children:[e.jsx(ec,{file:{name:n.name,contents:x,lang:Bs(n.path)||void 0},options:{disableFileHeader:!0,overflow:Pe?"wrap":"scroll",theme:W,themeType:te,...Pe?{}:{unsafeCSS:ac}},className:"block h-full w-full",style:{height:"100%"}}),e.jsx(oc,{hostRef:ne,enabled:!Pe})]}):null;return e.jsx($s,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:n?s?i?e.jsx("div",{className:le}):e.jsxs("div",{className:`${le} flex items-center gap-2 typography-ui text-muted-foreground`,children:[e.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),xe?"Loading…":"Loading..."]}):o?e.jsx("div",{className:`${le} typography-ui text-[color:var(--status-error)]`,children:o}):u?e.jsx("div",{className:X("flex h-full items-center justify-center",le),children:e.jsx("img",{src:f,alt:n.name||"Image",className:X("max-w-full object-contain rounded-md border border-border/30 bg-primary/10",xe?"max-h-full":"max-h-[70vh]")},d)}):h?e.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:e.jsx("iframe",{src:C,className:"h-full w-full border-0",title:n.name},z)}):b?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx("div",{className:"typography-ui-header text-foreground",children:"Cannot preview binary file"}),e.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:"This file is binary and cannot be edited in PiChamber. Download it to open with another app."}),v?e.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:v,children:[e.jsx(F,{name:"download",className:"mr-2 size-4"}),"Save file"]}):null]}):k&&Fe&&j==="preview"?e.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:e.jsx(Ei,{ref:L,xml:K,onChange:l},`${n.path}:${y}`)}):k&&se&&$==="tree"?e.jsx(qr,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"JSON viewer unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to text mode to view raw content."})]}),children:e.jsx("div",{className:"h-full overflow-auto",children:e.jsx(Zi,{jsonString:J,maxHeight:"100%",initiallyExpandedDepth:2})})}):me&&q==="preview"?e.jsxs("div",{className:X("h-full overflow-auto",le),children:[J.length>500*1024?e.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:`This file is large (${Math.round(J.length/1024)}KB). Preview may be limited.`}):null,e.jsx(qr,{fallback:e.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[e.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:e.jsx(pi,{content:J,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):k&&Ce&&I==="preview"?M?e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:"Loading..."}):e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx("iframe",{src:_,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:"HTML preview"},H)}):A&&D==="view"?re():e.jsxs("div",{className:X("relative h-full",E&&"overflow-hidden"),ref:R,children:[e.jsx("div",{className:X("h-full",E&&"invisible"),children:e.jsx($c,{value:x,onChange:V,readOnly:!N,vimMode:S,extensions:g,className:"h-full",onViewReady:P,onViewDestroy:Y,...G?{enableSearch:!0,searchOpen:Z,onSearchOpenChange:ie}:{}})}),E?e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[e.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Opening file at change..."]})}):null]}):e.jsx("div",{className:`${le} typography-ui text-muted-foreground`,children:"Pick a file from the tree."})})};async function Bc(t,n,s){if(Vs(t)&&!Ws(t))return{kind:n?"desktop-image":"asset-image"};if(_s(t))return{kind:"pdf"};if(Vn(t))return{kind:"binary",detectedFromContent:!1};const o=await s(t);if(hi(o))return{kind:"binary",detectedFromContent:!0};const u=Ii(o);return{kind:"text",content:u,draft:u.length>Mt?`${u.slice(0,Mt)}
2
+
3
+ … truncated …`:u,lineEnding:$i(o)}}function Vc({isDirty:t,saveDraft:n}){const s=ye(v=>v.setMainTabGuard),[i,o]=w.useState(!1),u=w.useRef(null),f=w.useRef(!1),d=w.useCallback(v=>f.current?(f.current=!1,!1):t?(u.current=v,o(!0),!0):!1,[t]);w.useEffect(()=>{if(!t){s(null);return}const v=k=>!d({kind:"tab",tab:k});return s(v),()=>{ye.getState().mainTabGuard===v&&s(null)}},[t,d,s]);const h=w.useCallback(()=>{const v=u.current;return u.current=null,f.current=!0,o(!1),v?.kind==="tab"&&s(null),v},[s]),C=w.useCallback(()=>h(),[h]),z=w.useCallback(async()=>await n()?h():(f.current=!1,null),[n,h]),b=w.useCallback(v=>{v||o(!0)},[]);return{confirmOpen:i,discardAndTakeIntent:C,keepModalOpen:b,requestNavigation:d,saveAndTakeIntent:z}}function Wc(t,n){if(t.state.doc.length!==n.length)return!1;if(n.length===0)return!0;const s=Math.min(128,n.length);if(t.state.sliceDoc(0,s)!==n.slice(0,s))return!1;const i=Math.max(0,n.length-s);return t.state.sliceDoc(i,n.length)===n.slice(i)}function _c({root:t,selectedPath:n,loadedPath:s,fileLoading:i,fileError:o,isImage:u,isPdf:f,isUnsupportedBinary:d,canEdit:h,textViewMode:C,setTextViewMode:z,draftContent:b,confirmDiscardOpen:v,selectFilePath:k}){const j=ye(A=>A.pendingFileNavigation),y=ye(A=>A.setPendingFileNavigation),L=ye(A=>A.pendingFileFocusPath),K=ye(A=>A.setPendingFileFocusPath),l=w.useRef(null),[$,q]=w.useState(0),I=w.useRef(null),M=w.useRef({key:"",attempts:0}),H=w.useCallback(()=>{q(A=>A+1)},[]);w.useEffect(()=>()=>{I.current!==null&&window.cancelAnimationFrame(I.current)},[]),w.useEffect(()=>{if(!j||!t)return;const A=()=>{I.current===null&&(I.current=window.requestAnimationFrame(()=>{I.current=null,H()}))},D=()=>{y(null),M.current={key:"",attempts:0}},x=ce(j.path);if(!x){D();return}const V=`${x}:${j.line}:${j.column??1}`;if(M.current.key!==V&&(M.current={key:V,attempts:0}),n!==x){v||k(x);return}if(i||s!==x)return;if(o||u||f||d){D();return}if(!h)return;if(C!=="edit"){z("edit");return}const N=l.current;if(!N||!Wc(N,b)){A();return}const S=Math.max(1,Math.min(j.line,N.state.doc.lines)),g=N.state.doc.line(S),R=Math.max(1,j.column||1),E=g.from+Math.min(Math.max(0,g.to-g.from),R-1);if(!(N.state.selection.main.head===E)||M.current.attempts===0){M.current.attempts+=1,N.dispatch({selection:{anchor:E},effects:we.scrollIntoView(E,{y:"center"})}),N.focus(),A();return}window.requestAnimationFrame(()=>{const Y=l.current;Y&&(Y.dispatch({selection:{anchor:E},effects:we.scrollIntoView(E,{y:"center"})}),Y.focus())}),D()},[h,v,b,$,o,i,u,f,d,s,H,j,t,n,k,y,z,C]),w.useEffect(()=>{if(!L||!t)return;const A=ce(L);if(!A){K(null);return}n!==A||i||s!==A||(!o&&!u&&!f&&!d&&h&&C==="edit"&&l.current?.focus(),K(null))},[h,o,i,u,f,d,s,L,t,n,K,C]);const _=ce(j?.path??"");return{editorViewRef:l,notifyEditorViewChanged:H,shouldMaskEditor:!!(j&&_&&n===_&&!i&&!o&&!u&&!f&&!d)}}function Kc(t){return!(!t.autoSaveEnabled||!t.isDirty||!t.canWrite||t.isSaving||t.fileLoading||t.isNonEditableBinary||!t.selectedFilePath||t.loadedFilePath!==t.selectedFilePath)}function qc(t){return t.selectedFilePath?t.isDirty?!(t.fileLoading||t.loadedFilePath!==t.selectedFilePath||t.isNonEditableBinary||t.draftContent===""&&t.fileContent!==""&&t.loadedFilePath!==t.selectedFilePath):!0:!1}const Hc=1500,Gc=2e3;function Uc({autoSaveEnabled:t,selectedPath:n,loadedPath:s,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,lineEnding:d,isNonEditableBinary:h,writeFile:C,expectedRevision:z,onSaved:b,captureSaveScope:v,currentSaveScope:k,onConflict:j}){const[y,L]=w.useState(!1),[K,l]=w.useState("idle"),[$,q]=w.useState(null),I=w.useRef(null),M=w.useRef(null),H=w.useRef(j);H.current=j;const _=w.useRef(v);_.current=v;const J=w.useRef(k);J.current=k;const A=w.useCallback(S=>S?Xs(S,J.current?.()??null):!0,[]),D=w.useCallback(()=>{I.current&&(clearTimeout(I.current),I.current=null)},[]),x=w.useCallback(()=>{l("saved"),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{M.current=null,l("idle")},Gc)},[]),V=w.useCallback(async S=>{if(!n||!C)return he.error("Saving not supported"),!1;if(!qc({selectedFilePath:n,loadedFilePath:s,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,isNonEditableBinary:h}))return h?console.warn(`[saveDraft] refusing to save binary file "${n}".`):u===""&&f!==""&&s!==n&&console.warn(`[saveDraft] refusing to save empty draft for "${n}" (${f.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!o)return!0;L(!0);const g=_.current?.()??null;try{const R=Bi(u,d),E=Js(z,S?.overwrite),P=await C(n,R,E);return P?.success?A(g)?(q(null),b(n,u,P?.revision,g),!0):!1:(he.error("Failed to write file"),!1)}catch(R){if(Ds(R)){if(!A(g))return!1;const E={path:n,currentRevision:R.currentRevision??null,exists:R.exists};return q(E),H.current?.(E),!1}return he.error(R instanceof Error?R.message:"Save failed"),!1}finally{L(!1)}},[u,z,f,i,o,h,A,d,s,b,n,C]),N=w.useCallback(async S=>{if(D(),y)return!1;const g=await V(S);return g&&x(),g},[D,y,V,x]);return w.useEffect(()=>{t||(l("idle"),D())},[t,D]),w.useEffect(()=>{if(Kc({autoSaveEnabled:t,isDirty:o,canWrite:!!(n&&C),isSaving:y,fileLoading:i,selectedFilePath:n,loadedFilePath:s,isNonEditableBinary:h}))return I.current=setTimeout(()=>{I.current=null,V().then(S=>{S&&x()})},Hc),D},[t,D,u,i,o,h,y,s,V,n,x,C]),w.useEffect(()=>{l("idle"),L(!1),q(null)},[n]),w.useEffect(()=>()=>{D(),M.current&&clearTimeout(M.current)},[D]),{autoSaveStatus:K,cancelPendingAutosave:D,isSaving:y,saveConflict:$,clearSaveConflict:()=>q(null),saveDraft:V,saveNow:N}}function Xc(t,n){return typeof t.revision=="string"&&typeof n.revision=="string"&&t.revision!==n.revision?!0:n.mtimeMs!==void 0&&t.mtimeMs!==void 0&&n.mtimeMs!==t.mtimeMs||n.size!==t.size}function Jc({selectedPath:t,loadedPath:n,isDirty:s,readStat:i,onExternalChange:o,pollIntervalMs:u=2e3}){const f=w.useRef(null),d=w.useRef(s);d.current=s;const h=w.useCallback(C=>{f.current=C},[]);return w.useEffect(()=>{if(!t||n!==t)return;let C=!1;const z=window.setInterval(()=>{if(document.hidden)return;const b=f.current,v=b&&b.path===t&&typeof b.revision=="string"?b.revision:null;i(t,{knownRevision:v}).then(k=>{if(C||!k)return;const j=f.current;if(!j||j.path!==t){f.current=k;return}!Xc(j,k)||d.current||(f.current=k,o())}).catch(()=>{})},u);return()=>{C=!0,window.clearInterval(z)}},[n,o,u,i,t]),{recordStat:h}}const ys="pichamber:files:md-viewer-mode",ws="pichamber:files:html-viewer-mode",js="pichamber:files:json-viewer-mode",Yc=1500,Qc=1500;function Pn(t,n,s){try{const i=localStorage.getItem(t);if(i&&n.includes(i))return i}catch{}return s}function Ln(t,n){try{localStorage.setItem(t,n)}catch{}}function Zc({root:t,selectedPath:n,fileContent:s,draftContent:i,setDraftContent:o,autoSaveEnabled:u,writeFile:f,expectedRevision:d,captureSaveScope:h,currentSaveScope:C,onSaved:z,onConflict:b}){const[v,k]=w.useState("edit"),[j,y]=w.useState("edit"),[L,K]=w.useState("text"),[l,$]=w.useState("edit"),[q,I]=w.useState("edit"),[M,H]=w.useState(0),[_,J]=w.useState(!1),A=w.useRef({}),D=w.useRef({}),x=w.useRef({}),V=w.useRef({}),N=w.useRef(""),S=w.useRef(""),g=w.useRef(null),R=w.useRef(null),E=w.useRef(null),P=w.useRef(d);P.current=d;const Y=w.useRef(h);Y.current=h;const G=w.useRef(C);G.current=C;const Z=w.useRef(z);Z.current=z;const ie=w.useRef(b);ie.current=b;const W=w.useCallback(()=>{g.current&&(clearTimeout(g.current),g.current=null),E.current!==null&&(cancelAnimationFrame(E.current),E.current=null)},[]),te=w.useCallback(B=>{N.current=B,S.current=B},[]),Pe=w.useCallback(()=>te(""),[te]);w.useEffect(()=>{n&&(k(A.current[n]??"edit"),y(D.current[n]??Pn(ys,["preview","edit"],"edit")),$(x.current[n]??Pn(ws,["preview","edit"],"edit")),I(V.current[n]??"edit"),K(Pn(js,["tree","text"],"text")))},[n]);const xe=w.useCallback(B=>{n&&(A.current[n]=B),k(B)},[n]),le=w.useCallback(B=>{n&&(D.current[n]=B),y(B),Ln(ys,B)},[n]),Fe=w.useCallback(B=>{n&&(x.current[n]=B),$(B),Ln(ws,B)},[n]),se=w.useCallback(B=>{K(B),Ln(js,B)},[]),me=w.useCallback(B=>{if(n&&(V.current[n]=B),W(),B==="edit"){o(N.current||s),I(B);return}N.current=i;const ue=n;I("edit"),E.current=requestAnimationFrame(()=>{E.current=requestAnimationFrame(()=>{E.current=null,!(t&&ue&&Oe.getState().byRoot[t]?.selectedPath!==ue)&&(H(ae=>ae+1),I("preview"))})})},[W,i,s,t,n,o]),Ce=w.useCallback(B=>B?Xs(B,G.current?.()??null):!0,[]),ne=w.useCallback(async(B,ue,ae)=>{if(!f||ue===S.current)return!1;const Q=Y.current?.()??null;if(Q&&Q.path!==B)return!1;try{const pe=await f(B,ue,Js(P.current,ae?.overwrite));return pe?.success?Ce(Q)?(te(ue),o(ue),Z.current?.(B,ue,pe?.revision,Q),!0):!1:(he.error("Failed to write file"),!1)}catch(pe){return Ds(pe)?(Ce(Q)&&ie.current?.({path:B,currentRevision:pe.currentRevision??null,exists:pe.exists,xml:ue}),!1):(he.error(pe instanceof Error?pe.message:"Save failed"),!1)}},[Ce,te,o,f]),re=w.useCallback(()=>{J(!0),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>J(!1),Qc)},[]),We=w.useCallback(async(B,ue,ae)=>{g.current&&(clearTimeout(g.current),g.current=null);const Q=await ne(B,ue,ae);return Q&&re(),Q},[ne,re]),ve=w.useCallback(B=>{N.current=B,!(!u||!n||q!=="preview"||!f)&&(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{g.current=null,ne(n,B).then(ue=>{ue&&re()})},Yc))},[u,q,ne,n,re,f]);w.useEffect(()=>W,[W,q,n]),w.useEffect(()=>()=>{R.current&&clearTimeout(R.current)},[]);const je=rn(n??"")&&(N.current||i)||s;return{clearDiagramContent:Pe,diagramEditorXml:je,diagramSaved:_,drawioRemountNonce:M,drawioViewMode:q,handleDiagramChange:ve,htmlViewMode:l,jsonViewMode:L,mdViewMode:j,recordDiagramContent:te,saveDiagramNow:We,saveDiagramXml:ne,saveDrawioViewMode:me,saveHtmlViewMode:Fe,saveJsonViewMode:se,saveMdViewMode:le,saveTextViewMode:xe,setTextViewMode:k,textViewMode:v}}function el(t,n){return t==="mobile"?!0:n==="full"}function tl(t,n){if(t===n)return!0;if(t.length!==n.length)return!1;for(let s=0;s<t.length;s+=1){const i=t[s],o=n[s];if(i.name!==o.name||i.path!==o.path||i.type!==o.type||i.extension!==o.extension||i.relativePath!==o.relativePath||i.size!==o.size)return!1}return!0}function nl({files:t,root:n,activeDirectory:s,expandedPaths:i,chrome:o,showGitignored:u,removeExpandedPathsByPrefix:f,enabled:d=!0,visible:h=!0}){const[C,z]=a.useState({}),[b,v]=a.useState({}),k=a.useRef(new Set),j=a.useRef(new Set),y=a.useRef(new Map),L=a.useRef(new Map),K=a.useRef(0),l=a.useRef(!1),[$,q]=a.useState(()=>ai());a.useEffect(()=>oi(S=>{q(S.runtimeKey)}),[]),a.useEffect(()=>(l.current=!1,()=>{l.current=!0,L.current=new Map,j.current=new Set,y.current=new Map}),[]);const I=a.useCallback((S,g)=>{const R=[];for(const E of g){if(!E?.name||Vi(E.name)||o==="desktop"&&!u&&Wi(E.name))continue;const P=ce(E.path||""),Y=P?_i(P)?P:ce(`${S}/${P}`):ce(`${S}/${E.name}`),G=E.isDirectory?"directory":"file";R.push({name:E.name,path:Y,type:G,extension:G==="file"&&E.name.includes(".")?E.name.split(".").pop()?.toLowerCase():void 0,size:E.size})}return Ki(R)},[o,u]),M=`${$}|${n}|g${u?"1":"0"}|${o}`,H=a.useRef(M);H.current=M;const _=a.useCallback(async S=>{if(!d)return;const g=ce(S.trim());if(!g||k.current.has(g))return;const R=y.current.get(g);if(R){await R;return}const E=H.current,P=K.current+1;K.current=P,L.current=new Map(L.current).set(g,P),j.current=new Set(j.current).add(g);const Y=()=>!l.current&&H.current===E&&L.current.get(g)===P,G=(async()=>{try{const Z=t.listDirectory?(await t.listDirectory(g)).entries.map(W=>({name:W.name,path:W.path,isDirectory:W.isDirectory,size:W.size})):(await ii(g)).map(W=>({name:W.name,path:W.path,isDirectory:W.isDirectory}));if(!Y())return;k.current=new Set(k.current).add(g),v(W=>{if(!W[g])return W;const te={...W};return delete te[g],te});const ie=I(g,Z);z(W=>{const te=W[g];return te&&tl(te,ie)?W:{...W,[g]:ie}})}catch(Z){if(!Y())return;const ie=Z instanceof Error?Z.message:String(Z??"");ie==="Directory not found"&&n&&g!==n?(f(n,g),v(W=>{if(!W[g])return W;const te={...W};return delete te[g],te})):(console.error("Failed to load files directory:",Z),v(W=>({...W,[g]:ie})))}finally{L.current.get(g)===P&&(L.current=new Map(L.current),L.current.delete(g))}})();y.current.set(g,G);try{await G}finally{y.current.get(g)===G&&(y.current.delete(g),j.current=new Set(j.current),j.current.delete(g))}},[d,t,I,f,n]),J=a.useCallback(()=>{k.current=new Set,j.current=new Set,y.current=new Map,L.current=new Map,v({}),z(S=>Object.keys(S).length===0?S:{})},[]),A=a.useCallback(async()=>{!d||!n||(J(),await _(n))},[d,_,J,n]),D=a.useCallback(async S=>{if(!d)return;if(!S){await A();return}const g=ce(S);k.current=new Set(k.current),k.current.delete(g),j.current=new Set(j.current),j.current.delete(g),y.current.delete(g),L.current=new Map(L.current),L.current.delete(g),await _(g)},[d,_,A]),x=a.useRef("");a.useEffect(()=>{x.current!==M&&(x.current=M,J())},[J,M]),a.useEffect(()=>{!d||!h||!n||k.current.has(ce(n))||_(n)},[d,_,n,M,h]),a.useEffect(()=>{!d||!h||!s||_(s)},[s,d,_,h]),a.useEffect(()=>{if(!d||!h||!t.listDirectory)return;const S=P=>{const Y=ce(P);return y.current.has(Y)||j.current.has(Y)},g=()=>{if(!(typeof document<"u"&&document.hidden))for(const P of i)S(P)||D(P)},R=()=>{typeof document<"u"&&document.hidden||g()};typeof document<"u"&&document.addEventListener("visibilitychange",R);const E=i.length>0?window.setInterval(g,8e3):null;return()=>{typeof document<"u"&&document.removeEventListener("visibilitychange",R),E!==null&&window.clearInterval(E)}},[d,i,t.listDirectory,D,h]);const V=a.useRef(d&&h);a.useEffect(()=>{const S=d&&h,g=V.current;if(V.current=S,!(!S||g)){if(!t.listDirectory){n&&!k.current.has(ce(n))&&_(n);return}if(i.length===0){n&&!k.current.has(ce(n))&&_(n);return}for(const R of i){const E=ce(R);y.current.has(E)||j.current.has(E)||D(R)}}},[d,i,t.listDirectory,_,D,n,h]);const N=a.useCallback(S=>k.current.has(ce(S)),[]);return{childrenByDir:C,loadErrorsByDir:b,isLoaded:N,loadDirectory:_,refreshDirectory:D,refreshRoot:A}}const rl=({showEditorTabsRow:t,isMobile:n,showMobilePageContent:s,onBackMobile:i,selectedFile:o,openFiles:u,root:f,alwaysShowActions:d,editorTabsOverflow:h,editorTabsScrollRef:C,onSelectFile:z,onCloseFile:b})=>t?e.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[n&&s&&e.jsx("button",{type:"button",onClick:i,"aria-label":"Back",className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:e.jsx(F,{name:"arrow-left-s",className:"size-5"})}),n?o?e.jsxs(on,{children:[e.jsx(cn,{asChild:!0,children:e.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":"Open files",children:[e.jsx(jt,{filePath:o.path,extension:o.extension,className:"size-3.5 flex-shrink-0"}),e.jsx(os,{name:o.name}),e.jsx(F,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),e.jsx(ln,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:u.map(v=>{const k=o?.path===v.path;return e.jsxs(fe,{onSelect:j=>{if(j.target.closest("[data-close-open-file]")){j.preventDefault();return}k||z(v)},className:X("flex min-w-0 items-center justify-between gap-2 overflow-hidden",k&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[e.jsx(jt,{filePath:v.path,extension:v.extension,className:"size-3.5 flex-shrink-0"}),e.jsx(os,{name:v.name})]}),e.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:j=>{j.preventDefault(),j.stopPropagation()},onClick:j=>{j.preventDefault(),j.stopPropagation(),b(v.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":`Close ${v.name}`,children:e.jsx(F,{name:"close",className:"size-3.5"})})]},v.path)})})]}):e.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"}):u.length>0?e.jsxs("div",{className:"relative min-w-0 flex-1",children:[h.left&&e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),h.right&&e.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),e.jsx("div",{ref:C,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},"data-no-drawer-swipe":"true",children:u.map(v=>{const k=o?.path===v.path;return e.jsxs("div",{title:kt(f,v.path),className:X("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",k?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[e.jsx(jt,{filePath:v.path,extension:v.extension,className:"size-3.5 flex-shrink-0"}),e.jsx("button",{type:"button",onClick:()=>{k||z(v)},className:"max-w-[12rem] truncate text-left",children:v.name}),e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),b(v.path)},className:X("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!k&&!d&&"opacity-0 group-hover:opacity-100"),"aria-label":`Close ${v.name}`,children:e.jsx(F,{name:"close",className:"size-3.5"})})]},v.path)})})]}):e.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"})]}):null,sl=(t,n)=>{if(!n)return null;const s=Number.parseInt(t.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,n.state.doc.lines)},ks=(t,n)=>{const s=t.state.doc.lineAt(n.main.head);return{lineNumber:s.number,character:n.main.head-s.from+1,selection:n}},Cs=(t,n,s)=>{const i=t.state.doc.line(n),o=Math.max(1,Math.min(s,i.length+1)),u=i.from+o-1;t.dispatch({selection:Zo.cursor(u),effects:we.scrollIntoView(u,{y:"center"})})};function ia({open:t,onOpenChange:n,view:s,variant:i="overlay"}){const[o,u]=a.useState(""),f=a.useRef(null),d=a.useRef(!1),h=a.useRef(null),C=a.useRef(null),z=a.useMemo(()=>sl(o,s),[o,s]);a.useEffect(()=>{!t||!s||(d.current=!1,f.current=ks(s,s.state.selection),u(""))},[t,s]),a.useEffect(()=>{t&&window.requestAnimationFrame(()=>{C.current?.focus(),C.current?.select()})},[t]),a.useEffect(()=>{if(!(!t||!s||!f.current)){if(z===null){const{selection:y}=f.current;s.dispatch({selection:y,effects:we.scrollIntoView(y.main.from,{y:"center"})});return}Cs(s,z,f.current.character)}},[z,t,s]);const b=a.useCallback(()=>{if(!s||d.current||!f.current)return;const{selection:y}=f.current;s.dispatch({selection:y,effects:we.scrollIntoView(y.main.from,{y:"center"})})},[s]),v=a.useCallback(y=>{y||b(),n(y)},[n,b]),k=a.useCallback(()=>{!s||z===null||!f.current||(d.current=!0,Cs(s,z,f.current.character),n(!1),s.focus())},[z,n,s]);a.useEffect(()=>{if(!t)return;const y=K=>{const l=h.current,$=K.target;!l||!($ instanceof Node)||l.contains($)||v(!1)},L=K=>{K.key==="Escape"&&(K.preventDefault(),v(!1))};return document.addEventListener("pointerdown",y,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",y,!0),document.removeEventListener("keydown",L,!0)}},[v,t,i]);const j=a.useMemo(()=>s?z===null?`Current Line: ${(f.current??ks(s,s.state.selection)).lineNumber}. Type a line number between 1 and ${s.state.doc.lines} to navigate to.`:`Go to line ${z}`:"Editor unavailable.",[z,s]);return i==="inline"?t?e.jsxs("div",{ref:h,className:"ml-1 flex h-6 items-center gap-1",children:[e.jsx(Dt,{ref:C,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:y=>u(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),k())},placeholder:"Line",className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),e.jsx(U,{variant:"outline",size:"xs",onClick:k,disabled:!s||z===null,className:"h-6 px-2",children:"Go"})]}):null:e.jsx("div",{ref:h,className:X("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx(Dt,{ref:C,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:y=>u(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),k())},placeholder:"Line number",className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),e.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground",children:j})]})})}const In=({currentMode:t,onToggle:n})=>{const s=t==="preview",i=s?"Switch to edit mode":"Switch to preview mode",o=s?"Edit":"Preview";return e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"sm",onClick:n,"aria-label":i,className:"h-5 w-5 p-0",children:s?e.jsx(F,{name:"eye",className:"size-4","aria-hidden":"true"}):e.jsx(F,{name:"eye-off",className:"size-4","aria-hidden":"true"})})}),e.jsx(lt,{sideOffset:8,children:o})]})},al=({selectedFile:t,displaySelectedPath:n,layout:s="floating",exitFullscreenOnly:i=!1,canEdit:o,isEditingFile:u,isSaving:f,autoSaveEnabled:d,autoSaveStatus:h,isDirty:C,onSaveDraft:z,onToggleAutoSave:b,canOpenInDesktopApp:v=!0,openInApps:k,openInCacheStale:j,onOpenInApp:y,onRefreshOpenInApps:L,onToolbarDropdownOpenChange:K,isSelectedImage:l,isSelectedPdf:$,isUnsupportedBinary:q,wrapLines:I,onToggleWrapLines:M,textViewMode:H,onToggleSearch:_,isGoToLineOpen:J,onOpenGoToLineChange:A,editorView:D,canUseShikiFileView:x,isJson:V,isHtml:N,onToggleTextViewMode:S,isMarkdown:g,mdViewMode:R,onToggleMdViewMode:E,isDrawio:P,drawioViewMode:Y,onToggleDrawioViewMode:G,diagramSaved:Z,onSaveDiagram:ie,jsonViewMode:W,onToggleJsonViewMode:te,canCopy:Pe,copiedContent:xe,onCopyContent:le,canCopyPath:Fe,copiedPath:se,onCopyPath:me,onDownloadFile:Ce,isMobile:ne,mode:re,isFullscreen:We,onToggleFullscreen:ve,onExitFullscreen:je})=>{if(!t)return null;const ue=s==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",ae=(Q,pe)=>e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:pe})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:Q})]});return e.jsxs("div",{className:ue,children:[o&&u&&e.jsxs(e.Fragment,{children:[f?e.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[e.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}),"Saving..."]}):d&&h==="saved"&&!C?e.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[e.jsx(F,{name:"check",className:"size-3.5"}),"Saved"]}):C?ae(d?`Save now (${bt()}+S) - auto-saves after 1.5s`:`Save now (${bt()}+S)`,e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{z()},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:d?`Save now (${bt()}+S) - auto-saves after 1.5s`:`Save now (${bt()}+S)`,"aria-label":`Save (${bt()}+S)`,children:e.jsx(F,{name:"save-3",className:"size-4"})})):null,ae(d?"Auto-save on":"Manual save",e.jsx(U,{variant:"ghost",size:"sm",onClick:b,className:X("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",d?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:d?"Auto-save on":"Manual save","aria-label":d?"Auto-save on":"Manual save",children:d?e.jsx(F,{name:"file-check-fill",className:"size-4"}):e.jsx(F,{name:"file-check",className:"size-4"})}))]}),v?e.jsxs(on,{onOpenChange:K,children:[e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:e.jsx(cn,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Open in desktop app","aria-label":"Open in desktop app",children:e.jsx(F,{name:"file-transfer",className:"size-4"})})})})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:"Open in desktop app"})]}),e.jsxs(ln,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[k.map(Q=>e.jsxs(fe,{className:"flex items-center gap-2",onClick:()=>{y(Q)},children:[e.jsx(oa,{label:Q.label,iconDataUrl:Q.iconDataUrl}),e.jsx("span",{className:"typography-ui-label text-foreground",children:Q.label})]},Q.id)),j?e.jsxs(fe,{className:"flex items-center gap-2",onClick:()=>{L()},children:[e.jsx(F,{name:"refresh",className:"size-4"}),e.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh apps"})]}):null]})]}):null,!l&&!$&&!q&&e.jsxs(e.Fragment,{children:[ae(I?"Disable line wrap":"Enable line wrap",e.jsx(U,{variant:"ghost",size:"sm",onClick:M,className:X("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",I?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:I?"Disable line wrap":"Enable line wrap",children:e.jsx(F,{name:"text-wrap",className:"size-4"})})),H==="edit"&&e.jsxs(e.Fragment,{children:[ae("Find in file",e.jsx(U,{variant:"ghost",size:"sm",onClick:Q=>{_(),Q.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Find in file",children:e.jsx(F,{name:"search",className:"size-4"})})),ae("Go to line",e.jsx(U,{variant:"ghost",size:"sm",onClick:Q=>{A(!J),Q.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Go to line",children:e.jsx(F,{name:"menu-fold-2",className:"size-4"})})),e.jsx(ia,{open:J,onOpenChange:A,view:D,variant:"inline"})]})]}),x&&o&&!V&&!N&&e.jsx(In,{currentMode:H==="view"?"preview":"edit",onToggle:S}),g&&ae(R==="preview"?"Switch to edit mode":"Switch to preview mode",e.jsx(U,{variant:"ghost",size:"sm",onClick:E,className:X("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",R==="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:R==="preview"?"Switch to edit mode":"Switch to preview mode","aria-label":R==="preview"?"Switch to edit mode":"Switch to preview mode",children:e.jsx(F,{name:R==="preview"?"eye":"eye-off",className:"size-4"})})),un(t?.path??"")&&e.jsx(In,{currentMode:N?"preview":"edit",onToggle:S}),P&&e.jsxs(e.Fragment,{children:[e.jsx(In,{currentMode:Y,onToggle:G}),Y==="preview"&&e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{ie()},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save diagram",children:Z?e.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(F,{name:"save-3",className:"size-4"})})]}),V&&ae(W==="tree"?"Switch to text view":"Switch to tree view",e.jsx(U,{variant:"ghost",size:"sm",onClick:te,className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:W==="tree"?"Switch to text view":"Switch to tree view",children:W==="tree"?e.jsx(F,{name:"code-sslash",className:"size-4"}):e.jsx(F,{name:"node-tree",className:"size-4"})})),Pe&&ae("Copy file contents",e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{le()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Copy file contents","aria-label":"Copy file contents",children:xe?e.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(F,{name:"clipboard",className:"size-4"})})),Fe&&ae(`Copy file path (${n})`,e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{me()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:`Copy file path (${n})`,"aria-label":`Copy file path (${n})`,children:se?e.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):e.jsx(F,{name:"file-copy-2",className:"size-4"})})),Ce&&ae("Save file",e.jsx(U,{variant:"ghost",size:"sm",onClick:Ce,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save file","aria-label":"Save file",children:e.jsx(F,{name:"download",className:"size-4"})})),i?ae("Exit fullscreen",e.jsx(U,{variant:"ghost",size:"sm",onClick:je,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Exit fullscreen","aria-label":"Exit fullscreen",children:e.jsx(F,{name:"fullscreen-exit",className:"size-4"})})):!ne&&re==="full"&&ae(We?"Exit fullscreen":"Fullscreen",e.jsx(U,{variant:"ghost",size:"sm",onClick:ve,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:We?"Exit fullscreen":"Fullscreen","aria-label":We?"Exit fullscreen":"Fullscreen",children:We?e.jsx(F,{name:"fullscreen-exit",className:"size-4"}):e.jsx(F,{name:"fullscreen",className:"size-4"})}))]})},ol=({open:t,onOpenChange:n,isSaving:s,onSaveAndContinue:i,onDiscardAndContinue:o})=>e.jsx(Ts,{open:t,onOpenChange:n,children:e.jsxs(As,{showCloseButton:!1,className:"max-w-md",children:[e.jsxs(Os,{children:[e.jsx(Ps,{children:"Unsaved changes"}),e.jsx(Ls,{children:"Save your edits before continuing?"})]}),e.jsxs(Is,{children:[e.jsx(U,{variant:"outline",onClick:i,disabled:s,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:"Save changes"}),e.jsx(U,{variant:"destructive",onClick:o,children:"Discard"})]})]})}),il=({root:t,isMobile:n,searchQuery:s,onSearchQueryChange:i,searchInputRef:o,searching:u,searchFailed:f,searchResults:d,selectedFile:h,onSelectFile:C,onOpenDialog:z,currentDirectory:b,refreshRoot:v,childrenByDir:k,loadErrorsByDir:j,expandedPaths:y,isBrowserClient:L,alwaysShowActions:K,getFileStatus:l,getFolderBadge:$,fileRowPermissions:q,downloadFile:I,contextMenuPath:M,setContextMenuPath:H,rightClickMenuPath:_,setRightClickMenuPath:J,toggleDirectory:A,handleRevealPath:D,refreshDirectory:x})=>{const V=!!(t&&k[t]),N=s.trim().length>0,S=t?j[t]:null,g=a.useMemo(()=>qi(y),[y]);function R(E,P){return(k[E]??[]).map(G=>{const Z=G.type==="directory",ie=Z&&g.has(G.path),W=h?.path===G.path;return e.jsxs("li",{className:"relative",children:[e.jsx(Fc,{node:G,root:t,isExpanded:ie,isActive:W,isMobile:n,isBrowserClient:L,alwaysShowActions:K,status:Z?void 0:l(G.path),badge:Z?$(G.path):void 0,permissions:q,downloadFile:I,contextMenuPath:M,setContextMenuPath:H,rightClickMenuPath:_,setRightClickMenuPath:J,onSelect:C,onToggle:A,onRevealPath:D,onOpenDialog:z}),Z&&ie&&e.jsxs("ul",{className:"relative ml-[15px] flex flex-col border-l border-border/50 pl-1.5",children:[j[G.path]?e.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:j[G.path],children:j[G.path]}),e.jsxs(U,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{x(G.path)},children:[e.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):null,R(G.path)]})]},G.path)})}return e.jsxs("section",{className:X("flex min-h-0 flex-col overflow-hidden",n?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[e.jsx("div",{className:X("flex flex-col gap-2 py-2",n?"px-3":"px-2"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),e.jsx(Dt,{ref:o,value:s,onChange:E=>i(E.target.value),placeholder:"Search files...",className:"h-8 pl-8 pr-8 typography-meta"}),s.trim().length>0&&e.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{i(""),o.current?.focus()},children:e.jsx(F,{name:"close",className:"size-4"})})]}),e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>z("createFile",{path:b,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New file","aria-label":"New file",children:e.jsx(F,{name:"file-add",className:"size-4"})})})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:"New File"})]}),e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>z("createFolder",{path:b,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New folder","aria-label":"New folder",children:e.jsx(F,{name:"folder-add",className:"size-4"})})})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:"New Folder"})]}),e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex flex-shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>{v()},className:"size-8 p-0 flex-shrink-0",title:"Refresh","aria-label":"Refresh",children:e.jsx(F,{name:"refresh",className:"size-4"})})})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:"Refresh"})]})]})}),e.jsx($s,{outerClassName:"flex-1 min-h-0",className:X("py-2",n?"px-3":"px-2"),children:e.jsx("ul",{className:"flex flex-col",children:N&&u?e.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Searching..."]}):N&&f?e.jsx("li",{className:"px-2 py-1 typography-meta text-[var(--status-error)]",children:"Search failed. Edit the search to try again."}):N&&d.length===0?e.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground text-pretty",children:`No files match “${s.trim()}”.`}):N?d.map(E=>e.jsx("li",{children:e.jsx(Hi,{path:E.relativePath||kt(t,E.path)||E.path,status:l(E.path),active:h?.path===E.path,match:s,onClick:()=>{C(E)}})},E.path)):S?e.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[e.jsx("span",{className:"text-[var(--status-error)]",children:S}),e.jsxs(U,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{v()},children:[e.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):V?R(t):e.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:"Loading..."})})})]})},Ns="min-w-0 truncate rounded px-1 py-0.5 text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",cl=({path:t,status:n,className:s,rootLabel:i,onRevealFolder:o,onShowChanges:u,children:f})=>{const d=t.split("/").filter(Boolean),h=d.pop()??t,C=e.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-subtle-foreground",children:"/"});return e.jsxs("div",{className:X("flex h-9 min-w-0 shrink-0 items-center gap-2 pl-2 pr-1",s),children:[e.jsxs("nav",{"aria-label":"File path",className:"flex min-w-0 flex-1 items-center gap-1.5 typography-meta",title:t,children:[e.jsxs("span",{className:"flex min-w-0 items-center",children:[o?e.jsxs(e.Fragment,{children:[i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:X(Ns,"max-w-[10rem] shrink"),onClick:()=>o(""),title:`Show ${i} in the tree`,children:i}),C]}):null,d.map((z,b)=>{const v=d.slice(0,b+1).join("/");return e.jsxs(a.Fragment,{children:[e.jsx("button",{type:"button",className:X(Ns,"shrink-[100]"),onClick:()=>o(v),title:`Show ${v} in the tree`,children:z}),C]},v)})]}):d.length>0?e.jsx("span",{className:"min-w-0 shrink-[100] truncate pl-1 text-muted-foreground [direction:rtl] [text-align:left]",children:e.jsx("bdi",{children:`${d.join("/")}/`})}):null,e.jsx("span",{"aria-current":"page",className:X("min-w-0 truncate font-medium text-foreground",o?"px-1":d.length===0&&"pl-1"),children:h})]}),n&&n!=="open"?e.jsx(Zs,{status:n}):null]}),u&&n&&n!=="open"?e.jsx(U,{type:"button",variant:"outline",size:"xs",onClick:u,className:"shrink-0",title:"Show this file's changes",children:"Changes"}):null,f?e.jsx("div",{className:"flex shrink-0 items-center gap-0.5",children:f}):null]})},Ae=({label:t,hint:n,checked:s})=>e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1",children:t}),n?e.jsx("span",{className:"ml-4 typography-micro text-muted-foreground",children:n}):null,s?e.jsx(F,{name:"check",className:"ml-4 size-4 text-foreground"}):null]}),ll=({selectedFile:t,displaySelectedPath:n,canEdit:s,isEditingFile:i,isSaving:o,autoSaveEnabled:u,isDirty:f,onSaveDraft:d,onToggleAutoSave:h,canOpenInDesktopApp:C=!0,openInApps:z,openInCacheStale:b,onOpenInApp:v,onRefreshOpenInApps:k,onToolbarDropdownOpenChange:j,isSelectedImage:y,isSelectedPdf:L,isUnsupportedBinary:K,wrapLines:l,onToggleWrapLines:$,textViewMode:q,onToggleSearch:I,onOpenGoToLineChange:M,canUseShikiFileView:H,isJson:_,isHtml:J,onToggleTextViewMode:A,isDrawio:D,drawioViewMode:x,onToggleDrawioViewMode:V,diagramSaved:N,onSaveDiagram:S,jsonViewMode:g,onToggleJsonViewMode:R,canCopy:E,onCopyContent:P,canCopyPath:Y,onCopyPath:G,onDownloadFile:Z,isMobile:ie,mode:W,isFullscreen:te,onToggleFullscreen:Pe})=>{if(!t)return null;const xe=bt(),le=!y&&!L&&!K,Fe=s&&i,se=le&&q==="edit",me=D?{label:x==="preview"?"Edit diagram source":"Show diagram",onSelect:V}:un(t.path)?{label:J?"Show source":"Show page preview",onSelect:A}:H&&s&&!_&&!J?{label:q==="view"?"Edit file":"Read only",onSelect:A}:null,Ce=Fe?e.jsxs(e.Fragment,{children:[f&&!o?e.jsx(fe,{onSelect:()=>{d()},children:e.jsx(Ae,{label:"Save now",hint:`${xe}+S`})}):null,e.jsx(fe,{onSelect:h,children:e.jsx(Ae,{label:"Save automatically",checked:u})})]}):null,ne=[];me&&ne.push(e.jsx(fe,{onSelect:me.onSelect,children:e.jsx(Ae,{label:me.label})},"view")),_&&ne.push(e.jsx(fe,{onSelect:R,children:e.jsx(Ae,{label:g==="tree"?"Show as text":"Show as tree"})},"json")),D&&x==="preview"&&ne.push(e.jsx(fe,{onSelect:()=>{S()},children:e.jsx(Ae,{label:N?"Diagram saved":"Save diagram"})},"diagram")),le&&ne.push(e.jsx(fe,{onSelect:$,children:e.jsx(Ae,{label:"Wrap long lines",checked:l})},"wrap")),se&&ne.push(e.jsx(fe,{onSelect:I,children:e.jsx(Ae,{label:"Find in file",hint:`${xe}+F`})},"find"),e.jsx(fe,{onSelect:()=>M(!0),children:e.jsx(Ae,{label:"Go to line"})},"line"));const re=[];E&&re.push(e.jsx(fe,{onSelect:()=>{P()},children:e.jsx(Ae,{label:"Copy contents"})},"copy")),Y&&re.push(e.jsx(fe,{onSelect:()=>{G()},children:e.jsx(Ae,{label:"Copy path"})},"path")),Z&&re.push(e.jsx(fe,{onSelect:Z,children:e.jsx(Ae,{label:"Download"})},"download")),C&&z.length>0&&re.push(e.jsxs(gi,{children:[e.jsx(xi,{children:"Open in"}),e.jsxs(vi,{className:"w-56 max-h-[70vh] overflow-y-auto",children:[z.map(je=>e.jsxs(fe,{className:"flex items-center gap-2",onSelect:()=>{v(je)},children:[e.jsx(oa,{label:je.label,iconDataUrl:je.iconDataUrl}),e.jsx("span",{className:"typography-ui-label text-foreground",children:je.label})]},je.id)),b?e.jsx(fe,{onSelect:()=>{k()},children:"Refresh apps"}):null]})]},"open-in"));const We=!ie&&W==="full",ve=[Ce,ne.length?ne:null,re.length?re:null].filter(Boolean);return e.jsxs(on,{onOpenChange:j,children:[e.jsx(cn,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"sm",className:X("size-7 p-0 text-muted-foreground hover:text-foreground data-[popup-open]:bg-interactive-active data-[popup-open]:text-foreground"),"aria-label":"File actions",title:"File actions",children:e.jsx(F,{name:"more-fill",className:"size-4"})})}),e.jsxs(ln,{align:"end",className:"min-w-[13rem]","aria-label":`Actions for ${n}`,children:[ve.map((je,B)=>e.jsxs(a.Fragment,{children:[B>0?e.jsx(Bn,{}):null,je]},B)),We?e.jsxs(e.Fragment,{children:[ve.length>0?e.jsx(Bn,{}):null,e.jsx(fe,{onSelect:Pe,children:e.jsx(Ae,{label:te?"Exit full screen":"Full screen"})})]}):null]})]})},ul=2,dl=24,fl=6,ml=(t,n)=>{let s=0;for(const i of t)if(i===" ")s+=1;else if(i===" ")s+=n-s%n;else break;return s},Ss=new Map,pl=t=>{let n=Ss.get(t);if(!n){const s=t+ul;n=Tt.line({attributes:{style:`padding-left: calc(${fl}px + ${s}ch); text-indent: -${s}ch`}}),Ss.set(t,n)}return n},Rs=t=>{const n=new an,{doc:s,tabSize:i}=t.state;for(const{from:o,to:u}of t.visibleRanges){let f=o;for(;f<=u;){const d=s.lineAt(f),h=Math.min(ml(d.text,i),dl);n.add(d.from,d.from,pl(h)),f=d.to+1}}return n.finish()},hl=qn.fromClass(class{decorations;constructor(t){this.decorations=Rs(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=Rs(t.view))}},{decorations:t=>t.decorations}),Du=({mode:t="full",chrome:n="desktop",onClose:s,isVisible:i=!0})=>{const{files:o,runtime:u}=bi(),f=n==="mobile",{currentTheme:d,availableThemes:h,lightThemeId:C,darkThemeId:z}=yi(),{isMobile:b,isTablet:v,screenWidth:k}=wi(),j=ci(u.platform),y=b||v,L=li(),K=ji()??"",l=ce(K.trim()),$=el(n,t),q=t!=="editor-only",I=t==="editor-only"&&!b,M=ki(K),[H,_]=a.useState(""),J=a.useRef(null),[A,D]=a.useState(!1),[x,V]=a.useState(l),[N,S]=a.useState(!1),[g,R]=a.useState(null),E=ye(r=>r.wrapLinesByDefault),P=g??E,Y=a.useCallback(r=>{R(r)},[]),[G,Z]=a.useState(!1),[ie,W]=a.useState(!1);a.useEffect(()=>{f&&(V(l),_(""),D(!1))},[f,l]);const te=a.useRef(0),Pe=a.useCallback(r=>{te.current=Math.max(0,te.current+(r?1:-1))},[]),xe=a.useMemo(()=>h.find(r=>r.metadata.id===C)??Wr(!1),[h,C]),le=a.useMemo(()=>h.find(r=>r.metadata.id===z)??Wr(!0),[h,z]);a.useEffect(()=>{Xr(xe),Xr(le)},[xe,le]);const Fe=a.useMemo(()=>[],[]),se=Oe(r=>l?r.byRoot[l]?.openPaths??Fe:Fe),me=Oe(r=>l?r.byRoot[l]?.selectedPath??null:null),Ce=Oe(r=>l?r.byRoot[l]?.expandedPaths??Fe:Fe),ne=Oe(r=>r.removeOpenPath),re=Oe(r=>r.removeOpenPathsByPrefix),We=Oe(r=>r.removeExpandedPathsByPrefix),ve=Oe(r=>r.setSelectedPath),je=Oe(r=>r.toggleExpandedPath),B=Oe(r=>r.expandPaths),{childrenByDir:ue,loadErrorsByDir:ae,isLoaded:Q,loadDirectory:pe,refreshDirectory:At,refreshRoot:ca}=nl({files:o,root:l,activeDirectory:f?x:void 0,expandedPaths:Ce,chrome:n,showGitignored:L,removeExpandedPathsByPrefix:We,enabled:$,visible:i}),Xe=a.useCallback(r=>{const p=ce(r),O=p.split("/"),T=O[O.length-1]||p,oe=T.includes(".")?T.split(".").pop()?.toLowerCase():void 0;return{name:T,path:p,type:"file",extension:oe}},[]),Ot=a.useMemo(()=>se.map(Xe),[se,Xe]),dn=a.useMemo(()=>{if(me){const r=tn(me);if(se.some(p=>tn(p)===r))return me}return se[0]??null},[se,me]),m=a.useMemo(()=>dn?Xe(dn):null,[dn,Xe]),qe=m?.path??"";a.useEffect(()=>{if(!l||!me)return;const r=tn(me);se.some(O=>tn(O)===r)||ve(l,se[0]??null)},[se,l,me,ve]);const Pt=!!(l&&qe&&!Dn(qe,l)),Hn=Pt?Hr(qe):void 0,ge=a.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Pt,outsideFileGrant:Hn,directory:l||void 0}),[t,Pt,Hn,l]),fn=a.useRef(null),[la,ua]=a.useState({left:!1,right:!1}),Gn=a.useCallback(()=>{const r=fn.current;r&&ua({left:r.scrollLeft>2,right:r.scrollLeft+r.clientWidth<r.scrollWidth-2})},[]),Un=a.useRef(Gn);Un.current=Gn,a.useEffect(()=>{const r=fn.current;if(!r)return;const p=()=>Un.current();p(),r.addEventListener("scroll",p,{passive:!0});const O=new ResizeObserver(p);return O.observe(r),()=>{r.removeEventListener("scroll",p),O.disconnect()}},[Ot.length]);const[Ee,_e]=a.useState(""),[mn,dt]=a.useState(!1),[Xn,Ne]=a.useState(null),[da,Je]=a.useState(""),Se=a.useRef(""),[et,ze]=a.useState(null),[ft,Me]=a.useState(void 0),[Jn,De]=a.useState(null),Re=Oe(r=>r.activeRuntimeKey),[be,Ke]=a.useState(null),[pn,Yn]=a.useState(!1),[fa,Le]=a.useState(!1),[mt,Te]=a.useState(""),[ma,pa]=a.useState(`
4
+ `),Qn=a.useRef(null),Ie=a.useRef(0),pt=a.useRef(null),[Zn,hn]=a.useState(!1),Lt=ye(r=>r.autoSaveEnabled),ha=ye(r=>r.setAutoSaveEnabled),ga=a.useRef(null),[xa,va]=a.useState(null),[ba,ya]=a.useState(null),{value:wa,show:ja}=Gr(!1,1200),{value:ka,show:Ca}=Gr(!1,1200),[er,tr]=a.useState(!1),Nt=a.useCallback(()=>{l&&ve(l,null),_e(""),Ne(null),Je(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),b&&D(!1)},[b,l,ve]),{operation:Na,target:Sa,inputValue:Ra,setInputValue:Fa,submitting:Ea,inputRef:za,open:Ma,close:Da,submit:Ta,capabilities:{canCreateFile:nr,canCreateFolder:rr,canRename:sr,canDelete:ar}}=Gi({files:o,root:l,selectedPath:m?.path??"",refreshDirectory:At,removeOpenPathsByPrefix:re,clearSelectedPath:Nt}),or=!!o.revealPath,gn=zs()&&Ms(),Aa=en(r=>r.availableApps),Oa=en(r=>r.isCacheStale),ir=en(r=>r.initialize),Pa=en(r=>r.loadInstalledApps);a.useEffect(()=>{gn&&ir()},[gn,ir]);const La=a.useCallback(r=>{o.revealPath&&o.revealPath(r).catch(()=>{he.error("Failed to reveal path")})},[o]),Ia=a.useCallback(async r=>{if(!m?.path||await ui(m.path,r.id,r.appName)||await _r(m.path,r.appName))return;const T=Ui(m.path)||l;T&&await _r(T,r.appName)||he.error(`Failed to open in ${r.appName}`)},[l,m?.path]),$a=ye(r=>r.fileEditorKeymap),cr=ye(r=>r.expandedEditorToolbar);a.useEffect(()=>{Te("")},[m?.path]);const lr=a.useRef("");a.useEffect(()=>{!l||lr.current===l||(lr.current=l,_e(""),Ne(null),Je(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),D(!1))},[l]);const ur=a.useRef(Re);a.useEffect(()=>{ur.current!==Re&&(ur.current=Re,Ie.current+=1,pt.current=null,_e(""),Te(""),Ne(null),dt(!1),Je(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),hn(!1))},[Re]);const Ba=f?x:K,{results:dr,searching:fr,failed:mr}=Xi({directory:Ba,query:H,chrome:n,showGitignored:L}),It=a.useCallback(async(r,p)=>{if(o.readFile){const Ve=await o.readFile(r,{...p??{},directory:l||void 0});return{content:Ve.content??"",revision:Ve.revision,exists:Ve.exists}}const O=new URLSearchParams({path:r});p?.allowOutsideWorkspace&&O.set("allowOutsideWorkspace","true"),p?.outsideFileGrant&&O.set("outsideFileGrant",p.outsideFileGrant),p?.optional&&O.set("optional","true"),l&&O.set("directory",l);const T=await Kr(`/api/fs/read?${O.toString()}`,{cache:p?.optional?"no-store":"default"});if(!T.ok){const Ve=await T.json().catch(()=>({error:T.statusText}));throw new Error(Ve.error||"Failed to read file")}const oe=await T.text(),ee=T.headers?.get?.("x-pichamber-file-revision"),Be=T.headers?.get?.("x-pichamber-file-exists")!=="false";return{content:oe,revision:typeof ee=="string"&&ee.length>0?ee:Be?void 0:null,exists:Be}},[o,l]),ht=a.useCallback(async(r,p)=>{if(o.statFile){const O=await o.statFile(r,{...p??{},directory:l||void 0});return{path:O.path,size:O.size,mtimeMs:O.mtimeMs,revision:O.revision}}return null},[o,l]);a.useEffect(()=>{if(!l||!o.statFile||se.length===0)return;let r=!1;const p=[...se];return Promise.all(p.map(async O=>{try{const T=await o.statFile?.(O,{directory:l||void 0});!r&&T&&!T.isFile&&re(l,O)}catch(T){!r&&Yr(T)&&re(l,O)}})),()=>{r=!0}},[o,se,re,l]);const xn=a.useMemo(()=>Ee.length>Mt?`${Ee.slice(0,Mt)}
5
+
6
+ … truncated …`:Ee,[Ee]),$t=mt!==xn,Va=a.useCallback((r,p)=>ht(r,{...ge,...p}),[ht,ge]),Wa=a.useCallback(()=>{ze(null),Me(void 0),De(null)},[]),{recordStat:tt}=Jc({selectedPath:m?.path??null,loadedPath:et,isDirty:$t,readStat:Va,onExternalChange:Wa}),pr=a.useRef(null),hr=a.useCallback((r,p,O,T)=>{_e(p);const oe=T?.generation??Ie.current;if(typeof O<"u"&&(Me(O),De({runtimeKey:T?.runtimeKey??Re,root:T?.root??l,path:r,generation:oe})),l&&Dn(r,l)){const ee=kt(l,r);ee&&Ci.requestGitRefresh({directory:l,paths:[ee]})}rn(r)&&pr.current?.(p),ht(r).then(ee=>{ee&&Ie.current===oe&&tt(ee)}).catch(()=>{})},[Re,ht,tt,l]),vn=a.useCallback(()=>m?.path?{runtimeKey:Re,root:l,path:m.path,generation:Ie.current}:null,[Re,l,m?.path]),gr=vn,xr=a.useCallback(async(r,p=null)=>{const O=Ie.current,T=r.path;let oe=null,ee=r.currentRevision,Ge=r.exists;try{if(Ge){const Be=await It(T,ge);oe=Be.content,typeof Be.revision=="string"&&(ee=Be.revision),Ge=Be.exists!==!1}}catch{}Ie.current===O&&(Ke({path:T,displayPath:kt(l,T)||T,exists:Ge,currentRevision:ee,currentContent:oe,diagramXml:p}),Le(!1))},[It,l,ge]),vr=a.useMemo(()=>{if(!m?.path||et!==m.path)return;const r=Jn;if(r){if(zi({...r},{runtimeKey:Re,root:l,path:m.path,generation:Ie.current}))return typeof ft=="string"||ft===null?"__stale__":void 0;if(typeof ft=="string"||ft===null)return ft}},[Re,et,ft,Jn,l,m?.path]),{clearDiagramContent:br,diagramEditorXml:_a,diagramSaved:Ka,drawioRemountNonce:qa,drawioViewMode:bn,handleDiagramChange:Ha,htmlViewMode:Bt,jsonViewMode:Vt,mdViewMode:Wt,recordDiagramContent:yn,saveDiagramNow:wn,saveDrawioViewMode:Ga,saveJsonViewMode:Ua,saveMdViewMode:yr,saveTextViewMode:Xa,setTextViewMode:jn,textViewMode:nt}=Zc({root:l,selectedPath:m?.path??null,fileContent:Ee,draftContent:mt,setDraftContent:Te,autoSaveEnabled:Lt,writeFile:o.writeFile,expectedRevision:vr,captureSaveScope:vn,currentSaveScope:gr,onSaved:hr,onConflict:r=>{xr(r,r.xml)}});pr.current=yn;const rt=a.useCallback(()=>Wt,[Wt]),{autoSaveStatus:Ja,isSaving:_t,clearSaveConflict:st,saveDraft:wr,saveNow:Kt}=Uc({autoSaveEnabled:Lt,selectedPath:m?.path??null,loadedPath:et,fileLoading:mn,isDirty:$t,draftContent:mt,fileContent:Ee,lineEnding:ma,isNonEditableBinary:!!(m?.path&&(Vn(m.path)||Zn)),writeFile:o.writeFile,expectedRevision:vr,onSaved:hr,captureSaveScope:vn,currentSaveScope:gr,onConflict:r=>{xr(r)}}),{confirmOpen:jr,discardAndTakeIntent:kr,keepModalOpen:Ya,requestNavigation:qt,saveAndTakeIntent:Cr}=Vc({isDirty:$t,saveDraft:wr});a.useEffect(()=>{const r=p=>{di(p)&&(p.key.toLowerCase()==="s"?(p.preventDefault(),Kt()):p.key.toLowerCase()==="f"&&(p.preventDefault(),W(!0)))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Kt]);const Nr=a.useCallback(async r=>{const p=Ie.current+1;Ie.current=p;const O=Re,T=l,oe=()=>{if(!l||O!==Re||T!==l)return!1;const de=Oe.getState().byRoot[l],Ze=de?.selectedPath??de?.openPaths[0]??null;return Ie.current===p&&Ze===r.path};Ne(null),Je(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),st(),hn(!1),b&&D(!0);const ee=Hr(r.path),Ge={allowOutsideWorkspace:t==="editor-only"&&!!l&&!Dn(r.path,l),outsideFileGrant:ee};let Be=!1;dt(!0);let Ve;await Bc(r.path,u.isDesktop,de=>It(de,Ge).then(Ze=>(Ve=Ze.revision,Ze.content))).then(de=>{if(oe()){if(de.kind!=="text"){if(_e(""),Te(""),de.kind==="desktop-image"){Be=!0;return}de.kind==="binary"&&hn(de.detectedFromContent),ze(r.path);return}pa(de.lineEnding),_e(de.content),yn(de.content),Te(de.draft),ze(r.path),Me(Ve),De({runtimeKey:O,root:T,path:r.path,generation:p}),ht(r.path,Ge).then(Ze=>{Ze&&oe()&&tt(Ze)}).catch(()=>{})}}).catch(de=>{if(oe()){if(Ji(de)){if(dt(!1),l&&ve(l,null),Ne(null),_e(""),Te(""),ze(null),Me(void 0),De(null),tt(null),H.trim().length>0&&_(""),b&&D(!1),l){const En=[...Qr(r.path,l),r.path];En.length>0&&B(l,En);for(const Br of En)Q(Br)||pe(Br)}return}if(Yr(de)){l&&re(l,r.path),_e(""),Te(""),Ne(null),Me(void 0),De(null),tt(null),b&&D(!1);return}_e(""),Te(""),Ne(de instanceof Error?de.message:"Failed to read file"),Me(void 0),De(null),tt(null)}}).finally(()=>{oe()&&!Be&&dt(!1)})},[Re,st,B,Q,b,pe,t,It,ht,yn,tt,re,l,u.isDesktop,H,ve]),gt=a.useCallback(async(r,p)=>{if(!l||!$)return;const O=Qr(r,l),T=p?[...O,r]:O;T.length>0&&B(l,T);const oe=T.map(ee=>{if(!Q(ee))return pe(ee)}).filter(Boolean);await Promise.all(oe)},[B,Q,pe,$,l]),Sr=a.useCallback((r,p)=>{const O=p.findIndex(T=>T.path===r);return O===-1||p.length<=1?null:p[O+1]??p[O-1]??null},[]),He=a.useCallback(async r=>{qt({kind:"select",file:r})||(l&&(ve(l,r.path),gt(r.path,!1)),Ne(null),Je(""),_e(""),br(),Te(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),st(),b&&D(!0))},[br,st,gt,b,qt,l,ve]),Qa=a.useCallback(r=>{He(Xe(r))},[He,Xe]),Za=a.useCallback(r=>{const p=ce(r);p&&(_(""),V(p),D(!1))},[]),eo=a.useCallback(r=>{const p=ce(r);p&&(D(!0),He(Xe(p)))},[He,Xe]),to=a.useCallback(async()=>{if(!(!x||N)){S(!0);try{await At(x)}finally{S(!1)}}},[x,N,At]),no=a.useCallback(()=>{const r=be;if(r){if(!r.exists){l&&ne(l,r.path),Nt(),Ke(null),Le(!1),st();return}Te(""),ze(null),Me(void 0),De(null),Ke(null),Le(!1),st()}},[st,Nt,ne,l,be]),ro=a.useCallback(async()=>{if(!(!be||pn)){Yn(!0);try{(be.diagramXml!==null?await wn(be.path,be.diagramXml,{overwrite:!0}):await Kt({overwrite:!0}))&&(Ke(null),Le(!1))}finally{Yn(!1)}}},[pn,be,wn,Kt]),so=a.useCallback(()=>{Ke(null),Le(!1)},[]);a.useEffect(()=>{!m?.path||!$||!i||gt(m.path,!1)},[gt,i,$,m?.path]),a.useEffect(()=>{if(!m){Ie.current+=1,pt.current=null,dt(!1);return}if(et===m.path||pt.current===m.path)return;const r=m.path;pt.current=r,Nr(m).finally(()=>{pt.current===r&&(pt.current=null)})},[Nr,et,m]);const xt=a.useCallback(async r=>{if(r.kind==="select"){await He(r.file);return}if(r.kind==="tab"){ye.getState().setActiveMainTab(r.tab);return}l&&ne(l,r.path),m?.path===r.path&&(r.nextFile?await He(r.nextFile):Nt())},[Nt,He,ne,l,m?.path]),ao=a.useCallback(()=>{const r=kr();Te(xn),r&&xt(r)},[xt,kr,xn]),oo=a.useCallback(async()=>{const r=await Cr();r&&await xt(r)},[xt,Cr]),io=a.useCallback(r=>{const p=m?.path===r,O={kind:"close",path:r,nextFile:Sr(r,Ot)};p&&qt(O)||xt(O)},[xt,Sr,Ot,qt,m?.path]),Ht=a.useMemo(()=>Yi({root:l,openPaths:se,gitFiles:M?.files}),[l,se,M]),co=a.useCallback(r=>Ht.getFileStatus(r),[Ht]),lo=a.useCallback(r=>Ht.getFolderBadge(r),[Ht]),uo=a.useCallback(async r=>{const p=ce(r);!l||!$||(je(l,p),Q(p)||await pe(p))},[Q,pe,$,l,je]),fo=a.useMemo(()=>({canRename:sr,canCreateFile:nr,canCreateFolder:rr,canDelete:ar,canReveal:or}),[sr,nr,rr,ar,or]),$e=!!(m?.path&&Vs(m.path)),vt=!!(m?.path&&Ws(m.path)),at=!!(m?.path&&_s(m.path)),kn=!!(m?.path&&(Vn(m.path)||Zn)),Gt=kn&&!$e&&!at,ot=a.useMemo(()=>kt(l,qe),[qe,l]),Ye=a.useMemo(()=>ot&&M?.files?.find(r=>r.path===ot)||null,[ot,M?.files]),Rr=Ye?Qi(Ye):null,mo=a.useCallback(()=>{if(!Ye||!l)return;const r=Ye.index!==" "&&Ye.index!=="?"&&Ye.working_dir===" ";ye.getState().openContextDiff(l,Ye.path,r)},[l,Ye]),po=!!(m&&(!$e||vt)&&!at&&!Gt&&Ee.length>0),ho=!!(m&&ot.length>0),St=!!(m&&!Pt&&!kn&&!$e&&o.writeFile&&Ee.length<=Mt),Rt=!!(m?.path&&ta(m.path)),Cn=!!(m?.path&&ea(m.path)),Ft=!!(m?.path&&un(m.path)),Fr=!!(m?.path&&rn(m.path)),go=!!(m&&!kn&&!$e),{editorViewRef:ke,notifyEditorViewChanged:Ut,shouldMaskEditor:xo}=_c({root:l,selectedPath:qe||null,loadedPath:et,fileLoading:mn,fileError:Xn,isImage:$e,isPdf:at,isUnsupportedBinary:Gt,canEdit:St,textViewMode:nt,setTextViewMode:jn,draftContent:mt,confirmDiscardOpen:jr,selectFilePath:Qa}),Er=go&&!Rt&&!Fr&&!(Ft&&Bt==="preview"),vo=Rt&&Wt==="edit"||Ft&&Bt==="edit"||Cn&&Vt==="text"||!Rt&&!Ft&&!Cn&&nt==="edit",Xt=a.useMemo(()=>qe?uc(qe):null,[qe]),[zr,Nn]=a.useState(null);a.useEffect(()=>{let r=!1;const p=m?.path;if(!p||Xt){Nn(null);return}return Nn(null),dc(p).then(O=>{r||Nn(O)}),()=>{r=!0}},[m?.path,Xt]),a.useEffect(()=>{!St&&nt==="edit"&&jn("view")},[St,jn,nt]);const Qe=a.useCallback(r=>{if(!b||!r||!r.hasFocus||typeof window>"u")return;const p=window.visualViewport;if(!p)return;const O=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,O-(p.offsetTop+p.height))<=0)return;const oe=r.state.selection.main.head,ee=r.coordsAtPos(oe);if(!ee)return;const Ge=Math.round(p.offsetTop+p.height),Ve=ee.bottom+20-Ge;Ve<=0||(r.scrollDOM.scrollTop+=Ve)},[b]);a.useEffect(()=>{if(!b||typeof window>"u")return;const r=()=>{window.requestAnimationFrame(()=>{Qe(ke.current)})},p=window.visualViewport;return p?.addEventListener("resize",r),p?.addEventListener("scroll",r,{passive:!0}),document.addEventListener("selectionchange",r),()=>{p?.removeEventListener("resize",r),p?.removeEventListener("scroll",r),document.removeEventListener("selectionchange",r)}},[ke,b,Qe]);const Jt=ye(r=>r.editorFontSize),bo=a.useMemo(()=>{if(!m?.path)return[ns(d,{fontSize:Jt})];const r=Bs(m.path),p=[ns(d,r?{syntaxColors:!1,fontSize:Jt}:{fontSize:Jt})],O=Xt??zr;return O&&p.push(O),r&&p.push(yc({language:r,themeName:d.metadata.id,theme:Fi(d)})),P&&p.push(we.lineWrapping,hl),b&&p.push(we.updateListener.of(T=>{T.view.hasFocus&&(T.selectionSet||T.focusChanged||T.viewportChanged||T.geometryChanged)&&window.requestAnimationFrame(()=>{Qe(T.view)})})),p},[d,m?.path,Xt,zr,P,b,Qe,Jt]),yo=a.useMemo(()=>({light:xe.metadata.id,dark:le.metadata.id}),[xe.metadata.id,le.metadata.id]),Yt=m?.path&&$e&&!u.isDesktop&&!vt?`${m.path}|${ge.allowOutsideWorkspace?"outside":"workspace"}|${ge.outsideFileGrant??""}`:"",Qt=m?.path&&at?`${m.path}|${ge.allowOutsideWorkspace?"outside":"workspace"}|${ge.outsideFileGrant??""}`:"",Et=m?.path&&Ft&&Bt==="preview"?m.path:"",Sn="Failed to read file",{readyKey:Mr,nonce:wo}=Tn(Yt,Ne,Sn),{readyKey:Dr,nonce:jo}=Tn(Et,Ne,Sn),{readyKey:Tr,nonce:ko}=Tn(Qt,Ne,Sn),Co=!!(Yt&&Mr!==Yt),No=!!(Et&&Dr!==Et),So=!!(Qt&&Tr!==Qt),Ro=m?.path&&$e?u.isDesktop?vt?`data:${Ur(m.path)};utf8,${encodeURIComponent(Ee)}`:da:vt?`data:${Ur(m.path)};utf8,${encodeURIComponent(Ee)}`:Mr===Yt?Mn().authenticatedAsset("/api/fs/raw",{path:m.path,allowOutsideWorkspace:ge.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ge.outsideFileGrant,directory:l||void 0}):"":"",Fo=m?.path&&at&&Tr===Qt?Mn().authenticatedAsset("/api/fs/raw",{path:m.path,allowOutsideWorkspace:ge.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ge.outsideFileGrant,directory:l||void 0}):"",Eo=Et&&Dr===Et&&m?.path?(()=>{const r=m.path.split("/").map(p=>encodeURIComponent(p)).join("/");return Mn().authenticatedAsset(`/api/fs/serve${r.startsWith("/")?r:`/${r}`}`)})():void 0;a.useEffect(()=>{let r=!1;return(async()=>{if(!u.isDesktop||!m?.path||!$e||vt){Se.current&&(URL.revokeObjectURL(Se.current),Se.current=""),Je("");return}Ne(null),Se.current&&(URL.revokeObjectURL(Se.current),Se.current=""),await(o.readFileBinary?o.readFileBinary(m.path,ge).then(T=>T.dataUrl):(async()=>{const T=await Kr("/api/fs/raw",{query:{path:m.path,allowOutsideWorkspace:ge.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ge.outsideFileGrant,directory:l||void 0}});if(!T.ok)throw new Error("Failed to read file");const oe=await T.blob(),ee=URL.createObjectURL(oe);return r?(URL.revokeObjectURL(ee),""):(Se.current=ee,ee)})()).then(T=>{r||(Je(T),ze(m.path))}).catch(T=>{Se.current&&(URL.revokeObjectURL(Se.current),Se.current=""),r||(Je(""),Ne(T instanceof Error?T.message:"Failed to read file"),ze(null))}).finally(()=>{r||dt(!1)})})(),()=>{r=!0}},[o,$e,vt,l,u.isDesktop,m?.path,ge]),a.useEffect(()=>()=>{Se.current&&(URL.revokeObjectURL(Se.current),Se.current="")},[]);const Ar=a.useCallback(()=>{const r=o.downloadFile,p=m?.path;!r||!p||r(p).catch(O=>{console.error("Download failed:",O),he.error("Operation failed")})},[o.downloadFile,m?.path]),Rn=!b&&!cr,Or=Ni(a.useCallback(r=>r.projects.find(p=>ce(p.path)===l)??null,[l])),zo=Or?Si(Or):l?l.split("/").filter(Boolean).pop()??l:void 0,Pr=ye(r=>r.revealInFileTree),Mo=a.useCallback(r=>{if(!l)return;const p=r?`${l.replace(/\/+$/,"")}/${r}`:l;if(t==="editor-only"){Pr(p);return}r&&gt(p,!0)},[gt,t,Pr,l]),Lr={selectedFile:m,displaySelectedPath:ot,canEdit:St,isEditingFile:vo,isSaving:_t,autoSaveEnabled:Lt,autoSaveStatus:Ja,isDirty:$t,onSaveDraft:wr,onToggleAutoSave:()=>ha(!Lt),canOpenInDesktopApp:gn,openInApps:Aa,openInCacheStale:Oa,onOpenInApp:Ia,onRefreshOpenInApps:()=>Pa(!0),onToolbarDropdownOpenChange:Pe,isSelectedImage:$e,isSelectedPdf:at,isUnsupportedBinary:Gt,wrapLines:P,onToggleWrapLines:()=>Y(!P),textViewMode:nt,onToggleSearch:()=>W(!ie),isGoToLineOpen:er,onOpenGoToLineChange:tr,editorView:ke.current,canUseShikiFileView:Er,isJson:Cn,isHtml:Ft,onToggleTextViewMode:()=>{Xa(nt==="view"?"edit":"view")},isMarkdown:Rt,mdViewMode:rt(),onToggleMdViewMode:()=>yr(rt()==="preview"?"edit":"preview"),isDrawio:Fr,drawioViewMode:bn,onToggleDrawioViewMode:()=>Ga(bn==="preview"?"edit":"preview"),diagramSaved:Ka,onSaveDiagram:async()=>{const r=Qn.current?.getXml();m?.path&&r&&await wn(m.path,r)},jsonViewMode:Vt,onToggleJsonViewMode:()=>Ua(Vt==="tree"?"text":"tree"),canCopy:po,copiedContent:wa,onCopyContent:async()=>{(await nn(Ee)).ok?(ja(!0),Rn&&he.success("Contents copied")):he.error("Copy failed")},canCopyPath:ho,copiedPath:ka,onCopyPath:async()=>{(await nn(ot)).ok?(Ca(!0),Rn&&he.success("Path copied")):he.error("Copy failed")},onDownloadFile:o.downloadFile&&m?Ar:void 0,isMobile:b,mode:t,isFullscreen:G,onToggleFullscreen:()=>Z(!G),onExitFullscreen:()=>Z(!1)},Fn=({exitFullscreenOnly:r=!1,layout:p="floating"}={})=>e.jsx(al,{...Lr,layout:p,exitFullscreenOnly:r}),Do=a.useCallback(r=>{ke.current=r,Ut(),window.requestAnimationFrame(()=>{Qe(r)})},[ke,Ut,Qe]),To=a.useCallback(()=>{ke.current&&(ke.current=null),Ut()},[ke,Ut]),Ao=a.useCallback(r=>{ke.current=r,window.requestAnimationFrame(()=>{Qe(r)})},[ke,Qe]),Oo=a.useCallback(()=>{ke.current&&(ke.current=null)},[ke]),Ir={selectedFile:m,loading:mn||Co||So,suppressLoadingIndicator:I,fileError:Xn,isSelectedImage:$e,imageSrc:Ro,imagePreviewNonce:wo,isSelectedPdf:at,pdfSrc:Fo,pdfPreviewNonce:ko,isUnsupportedBinary:Gt,onDownload:o.downloadFile&&m?Ar:void 0,drawioViewMode:bn,drawioRemountNonce:qa,diagramEditorRef:Qn,diagramEditorXml:_a,onDiagramChange:Ha,jsonViewMode:Vt,markdownViewMode:Wt,htmlViewMode:Bt,htmlLoading:No,htmlPreviewNonce:jo,htmlPreviewSrc:Eo,fileContent:Ee,canUseShikiFileView:Er,textViewMode:nt,draftContent:mt,onDraftChange:Te,canEdit:St,vimMode:$a==="vim",editorExtensions:bo,shouldMaskEditorForPendingNavigation:xo,pierreTheme:yo,shikiThemeType:d.metadata.variant==="dark"?"dark":"light",wrapLines:P},Zt=e.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[e.jsx(ol,{open:jr,onOpenChange:Ya,isSaving:_t,onSaveAndContinue:()=>{oo()},onDiscardAndContinue:ao}),e.jsx(Mi,{open:!!be,conflict:be?{path:be.path,displayPath:be.displayPath,exists:be.exists,currentRevision:be.currentRevision,currentContent:be.currentContent,dirtyContent:be.diagramXml??mt}:null,isResolving:pn||_t,showCompare:fa,onToggleCompare:()=>Le(r=>!r),onReload:no,onOverwrite:()=>{ro()},onClose:so}),e.jsxs("div",{className:X("flex flex-col flex-shrink-0",(q||!b&&m)&&"border-b border-border/60"),children:[e.jsx(rl,{showEditorTabsRow:q,isMobile:b,showMobilePageContent:A,onBackMobile:()=>D(!1),selectedFile:m,openFiles:Ot,root:l,alwaysShowActions:y,editorTabsOverflow:la,editorTabsScrollRef:fn,onSelectFile:He,onCloseFile:io}),b&&m?e.jsx("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:e.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Fn({layout:"docked"})})}):null,!b&&m?e.jsx(cl,{path:ot,status:Rr,rootLabel:zo,onRevealFolder:Mo,onShowChanges:t==="editor-only"&&Rr!=="git-deleted"?mo:void 0,className:X(q&&"border-t border-border/40"),children:cr?e.jsx("div",{className:"min-w-0 overflow-x-auto",children:Fn({layout:"docked"})}):e.jsxs("div",{className:"flex items-center gap-0.5",children:[_t?e.jsx("span",{className:"px-1 typography-micro text-muted-foreground",children:"Saving…"}):null,Rt?e.jsxs(it,{children:[e.jsx(ct,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>yr(rt()==="preview"?"edit":"preview"),className:X("size-7 p-0",rt()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":rt()==="preview"?"Switch to edit mode":"Switch to preview mode",children:e.jsx(F,{name:rt()==="preview"?"eye":"eye-off",className:"size-4"})})})}),e.jsx(lt,{side:"bottom",sideOffset:6,children:rt()==="preview"?"Switch to edit mode":"Switch to preview mode"})]}):null,e.jsx(ll,{...Lr})]})}):null]}),e.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[Rn&&m?e.jsx(ia,{open:er,onOpenChange:tr,view:ke.current}):null,e.jsx(bs,{variant:"embedded",...Ir,enableRichPreviews:!0,editorWrapperRef:ga,onEditorViewReady:Do,onEditorViewDestroy:To,enableSearch:!0,searchOpen:ie,onSearchOpenChange:W})]})]}),$r=e.jsx(il,{root:l,isMobile:b,searchQuery:H,onSearchQueryChange:_,searchInputRef:J,searching:fr,searchFailed:mr,searchResults:dr,selectedFile:m,onSelectFile:He,onOpenDialog:Ma,currentDirectory:K,refreshRoot:ca,childrenByDir:ue,loadErrorsByDir:ae,expandedPaths:Ce,isBrowserClient:j,alwaysShowActions:y,getFileStatus:co,getFolderBadge:lo,fileRowPermissions:fo,downloadFile:o.downloadFile,contextMenuPath:xa,setContextMenuPath:va,rightClickMenuPath:ba,setRightClickMenuPath:ya,toggleDirectory:uo,handleRevealPath:La,refreshDirectory:At}),Po=t==="full"&&G&&m&&e.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:e.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[e.jsx("div",{className:"absolute right-4 top-4 z-30",children:Fn({exitFullscreenOnly:!0})}),e.jsx(bs,{variant:"fullscreen",...Ir,enableRichPreviews:!1,onEditorViewReady:Ao,onEditorViewDestroy:Oo})]})});return f?e.jsx(Cc,{root:l,directory:x||l,entries:x||l?ue[x||l]:void 0,query:H,searchResults:dr,isSearching:fr,searchFailed:mr,directoryError:x||l?ae[x||l]??null:null,refreshing:N,editorPath:A?m?.path??null:null,editor:Zt,onClose:s,onQueryChange:_,onOpenDirectory:Za,onOpenFile:eo,onBackFromEditor:()=>D(!1),onRefresh:()=>{to()}}):e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[e.jsx(Sc,{activeDialog:Na,dialogData:Sa,dialogInputValue:Ra,onDialogInputChange:Fa,isDialogSubmitting:Ea,onDialogSubmit:Ta,onClose:Da,inputRef:za}),Po,b?A?Zt:$r:t==="editor-only"?e.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Zt})}):e.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[k>=700&&e.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:$r}),e.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Zt})]})]})};export{Du as FilesView};