@kabmo-labs/kabmo 0.46.0 → 0.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +1 -1
  3. package/dist/client/static/js/{CsvGrid-br4j001k.js → CsvGrid-qdkmv8bj.js} +1 -1
  4. package/dist/client/static/js/{DocxView-kmtkbmmw.js → DocxView-k84ns803.js} +1 -1
  5. package/dist/client/static/js/{DrawioView-3df0g3jr.js → DrawioView-r1n717f7.js} +1 -1
  6. package/dist/client/static/js/{ImageView-2r8p5z3y.js → ImageView-jkrdrq8v.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-rq3d2a4e.js → LayoutWrapper-sh634350.js} +2 -2
  8. package/dist/client/static/js/{Modal-tmxhxd6q.js → Modal-xe6h99jn.js} +1 -1
  9. package/dist/client/static/js/{PdfView-p5z7c7eg.js → PdfView-ffg4mccg.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-t06h6zfx.js → SessionsView-cdcbsee9.js} +1 -1
  11. package/dist/client/static/js/{SheetView-agw459v2.js → SheetView-89sscpz6.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-b9rfy1h6.js → SvgPreview-68c0ccbv.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-wbnhzcnj.js → abnfDiagram-O67JEVCF-h3a5s259.js} +1 -1
  14. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-t2sgevea.js → architectureDiagram-NJMV4G6O-983p0jgn.js} +1 -1
  15. package/dist/client/static/js/{blockDiagram-BEXU5L5S-v2nzp54a.js → blockDiagram-BEXU5L5S-16pse5mh.js} +1 -1
  16. package/dist/client/static/js/{c4Diagram-YGBWAQC7-7h03146b.js → c4Diagram-YGBWAQC7-mvnb00zt.js} +1 -1
  17. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-m57e9kp1.js → classDiagram-v2-NBCMYWYE-kmpd91xb.js} +1 -1
  18. package/dist/client/static/js/{cose-bilkent-JH36ORCC-c4tnh4mg.js → cose-bilkent-JH36ORCC-3ek5r5se.js} +1 -1
  19. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-mjf6njey.js → cynefinDiagram-VND7K2PF-jkbh84zn.js} +1 -1
  20. package/dist/client/static/js/{dagre-6A5THRUB-6yma9ch3.js → dagre-6A5THRUB-4fdc0sgn.js} +1 -1
  21. package/dist/client/static/js/{diagram-22UHCM2B-1q4ce2gb.js → diagram-22UHCM2B-hbk61nq9.js} +1 -1
  22. package/dist/client/static/js/{diagram-3UASUU5V-0ttps29p.js → diagram-3UASUU5V-hfpbr9qh.js} +1 -1
  23. package/dist/client/static/js/{diagram-ATOU4E4O-1mzexgv1.js → diagram-ATOU4E4O-fn0nt71a.js} +1 -1
  24. package/dist/client/static/js/{diagram-CDSNMT55-4ae89t23.js → diagram-CDSNMT55-ssswxjeb.js} +1 -1
  25. package/dist/client/static/js/{diagram-MLGK6HIB-057jaqvh.js → diagram-MLGK6HIB-whnzxv6f.js} +1 -1
  26. package/dist/client/static/js/{diagram-MPIPVDR6-p6yyq5sx.js → diagram-MPIPVDR6-hk1chzxk.js} +1 -1
  27. package/dist/client/static/js/{dockerfile-00hqsk9c.js → dockerfile-zmsj8r4g.js} +1 -1
  28. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-bsk7dvm4.js → ebnfDiagram-ZINNZB2B-q1vkg5mr.js} +1 -1
  29. package/dist/client/static/js/{elk-276RUBZZ-dsq91er5.js → elk-276RUBZZ-kt98vg8j.js} +1 -1
  30. package/dist/client/static/js/{erDiagram-OPXOYQCR-p7p13mbh.js → erDiagram-OPXOYQCR-ey3avsn9.js} +1 -1
  31. package/dist/client/static/js/flowDiagram-KWPJA3E3-7gvtpn3d.js +1 -0
  32. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-bwgnttyk.js → ganttDiagram-FUAMR5RP-a9k1at43.js} +1 -1
  33. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-ca0gj5am.js → gitGraphDiagram-X574FWY7-gnekjfym.js} +1 -1
  34. package/dist/client/static/js/{index-jkay7aw7.js → index-1ax52p0q.js} +1 -1
  35. package/dist/client/static/js/{index-064vdkrs.js → index-2a6qp9y6.js} +1 -1
  36. package/dist/client/static/js/{index-j718pxb3.js → index-3x7h2eqj.js} +1 -1
  37. package/dist/client/static/js/{index-amys498v.js → index-4cag7w6k.js} +131 -131
  38. package/dist/client/static/js/{index-ta6gpcpw.js → index-5ka2tyf9.js} +2 -2
  39. package/dist/client/static/js/{index-x1fqhhpp.js → index-60v30k5h.js} +2 -2
  40. package/dist/client/static/js/{index-5gf52a6d.js → index-65afr75v.js} +1 -1
  41. package/dist/client/static/js/{index-4bqssvt6.js → index-83rkg916.js} +1 -1
  42. package/dist/client/static/js/{index-aagt3382.js → index-84fyq5a6.js} +1 -1
  43. package/dist/client/static/js/{index-dr5hca5b.js → index-8g7q8mz4.js} +1 -1
  44. package/dist/client/static/js/{index-bjv5ga2e.js → index-9vv7wr1n.js} +1 -1
  45. package/dist/client/static/js/{index-pwe6chtp.js → index-amsa0tfs.js} +1 -1
  46. package/dist/client/static/js/{index-red856x6.js → index-atq9q1s7.js} +1 -1
  47. package/dist/client/static/js/{index-f7te27n5.js → index-b2e5pwx7.js} +1 -1
  48. package/dist/client/static/js/{index-ex5dtdx2.js → index-b5dfvget.js} +1 -1
  49. package/dist/client/static/js/{index-zedt16w7.js → index-bsr7wmj2.js} +1 -1
  50. package/dist/client/static/js/{index-k5zfzgez.js → index-c9e417cs.js} +1 -1
  51. package/dist/client/static/js/{index-3bf7r7z4.js → index-dt6q3rws.js} +4 -4
  52. package/dist/client/static/js/{index-29npynva.js → index-e9cxje00.js} +1 -1
  53. package/dist/client/static/js/{index-zq0qxb17.js → index-fzngzhww.js} +1 -1
  54. package/dist/client/static/js/{index-16sd19f0.js → index-hgzntg2j.js} +1 -1
  55. package/dist/client/static/js/{index-bafe7hmd.js → index-kb14dhrx.js} +1 -1
  56. package/dist/client/static/js/{index-qn200x1b.js → index-kbhrvep8.js} +6 -6
  57. package/dist/client/static/js/{index-eqhjs1yv.js → index-m4k054wz.js} +3 -3
  58. package/dist/client/static/js/{index-8pksqzwq.js → index-pavvxrsz.js} +1 -1
  59. package/dist/client/static/js/{index-95kese1h.js → index-q9ytjey8.js} +1 -1
  60. package/dist/client/static/js/{index-3qnjdjg2.js → index-vkqb4dnt.js} +1 -1
  61. package/dist/client/static/js/{index-7055hdx1.js → index-wrcdc9vz.js} +1 -1
  62. package/dist/client/static/js/{index-ncpwteyt.js → index-x9r7zfp4.js} +1 -1
  63. package/dist/client/static/js/{index-y2z8nsvw.js → index-xq5f3nxa.js} +1 -1
  64. package/dist/client/static/js/{index-gq5w5w8x.js → index-xwjbq003.js} +1 -1
  65. package/dist/client/static/js/{index-twsbv1yn.js → index-yf93db65.js} +1 -1
  66. package/dist/client/static/js/{index-9d3n04vb.js → index-ykm7a3cp.js} +2 -2
  67. package/dist/client/static/js/{index-5h8y54t6.js → index-z25ss7xj.js} +1 -1
  68. package/dist/client/static/js/{infoDiagram-VRGFBTTK-7q58qdf1.js → infoDiagram-VRGFBTTK-r1p25738.js} +1 -1
  69. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-9jmeszag.js → ishikawaDiagram-OU5B5YK6-afgrqdrt.js} +1 -1
  70. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-0d7xe845.js → journeyDiagram-ZHPQQLJL-hepa4wk7.js} +1 -1
  71. package/dist/client/static/js/{kanban-definition-PNTS6WVX-7p83rwdn.js → kanban-definition-PNTS6WVX-jysft8ya.js} +1 -1
  72. package/dist/client/static/js/{mermaid.core-hwhzw0wv.js → mermaid.core-0m90b0s8.js} +2 -2
  73. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-hy0rtr7t.js → mindmap-definition-NLK3R4M7-x2rrzpvr.js} +1 -1
  74. package/dist/client/static/js/one-dark-pro-09d8p5vy.js +1 -0
  75. package/dist/client/static/js/one-light-g3ednt6p.js +1 -0
  76. package/dist/client/static/js/{pegDiagram-GJSIUBJH-kd8t53tx.js → pegDiagram-GJSIUBJH-z7vb7f1z.js} +1 -1
  77. package/dist/client/static/js/{pieDiagram-5QR66LMP-h3x03f80.js → pieDiagram-5QR66LMP-jqv6v4e6.js} +1 -1
  78. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-y2b1ncbg.js → quadrantDiagram-O4NWA36T-w2h8yxrv.js} +1 -1
  79. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-x188rcxf.js → railroadDiagram-XR7U4H2S-nd09yac3.js} +1 -1
  80. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-g5e9fk17.js → requirementDiagram-PLB6GJNP-t61zxh5v.js} +1 -1
  81. package/dist/client/static/js/{rust-1v8xbxn9.js → rust-avnkhh0p.js} +1 -1
  82. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-y9ht91gf.js → sankeyDiagram-IPEJSGJF-2f7h2cmw.js} +1 -1
  83. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-pp8s63rt.js → sequenceDiagram-PO4LG4MO-kfb5d7zd.js} +1 -1
  84. package/dist/client/static/js/{sizeCapture-INFHLROL-k6dhfxex.js → sizeCapture-INFHLROL-amfg19se.js} +1 -1
  85. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-y3akpsm4.js → stateDiagram-v2-GCMORJYK-k5hx7btx.js} +1 -1
  86. package/dist/client/static/js/{swimlanes-2SLR337P-89081dr3.js → swimlanes-2SLR337P-wv3rp8kk.js} +1 -1
  87. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-3q2a15wc.js → swimlanesDiagram-TC7HE7FX-6y8zdbm4.js} +1 -1
  88. package/dist/client/static/js/{timeline-definition-EJHVYXUP-tz6r8g3q.js → timeline-definition-EJHVYXUP-0re95wtn.js} +1 -1
  89. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-yq2y1b09.js → usecaseDiagram-POWQR4AR-yrje14qp.js} +1 -1
  90. package/dist/client/static/js/{vennDiagram-UO4OBE2U-qdmjf6x3.js → vennDiagram-UO4OBE2U-jxkmrfy5.js} +1 -1
  91. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-3n2sm7rj.js → wardleyDiagram-VNRHLVJA-d3v2m9b1.js} +1 -1
  92. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-d7n2av2t.js → xychartDiagram-PMCCYNJV-9a1s1rjt.js} +1 -1
  93. package/package.json +1 -1
  94. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  95. package/src/client/components/layout/desktop-layout/RightColumn.test.tsx +204 -0
  96. package/src/client/components/layout/desktop-layout/RightColumn.tsx +37 -16
  97. package/src/client/components/mobile/RightSidebar.tsx +10 -8
  98. package/src/client/components/mobile/mobile-session-sidebar/use-drawer-tabs.ts +2 -1
  99. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +11 -0
  100. package/src/client/components/workspace/chat-timeline/MessageList.tsx +29 -21
  101. package/src/client/hooks/chat/timeline/row-measure.ts +75 -0
  102. package/src/client/hooks/chat/timeline/row-window.test.ts +41 -21
  103. package/src/client/hooks/chat/timeline/row-window.ts +6 -24
  104. package/src/client/hooks/workspace/panel-tabs-reveal.test.tsx +20 -17
  105. package/src/client/hooks/workspace/panel-tabs-reveal.ts +29 -17
  106. package/src/client/hooks/workspace/panel-tabs.ts +3 -2
  107. package/src/client/hooks/workspace/session-state/index.test.tsx +145 -0
  108. package/src/client/hooks/workspace/session-state/index.ts +28 -16
  109. package/dist/client/static/js/flowDiagram-KWPJA3E3-7b4w6phx.js +0 -1
  110. package/dist/client/static/js/one-dark-pro-4b8er03c.js +0 -1
  111. package/dist/client/static/js/one-light-e6r3vsz4.js +0 -1
@@ -1,3 +1,3 @@
1
- import{d,n,o,K,i,u,a,je,oe,e,s,E,m,rn,_,f,B,re,Xe,fe,Tt,We,si,mn,Zn,D,U,b,er,Oe,Ee,S,hr,et,ue,br,Z,ct,ll,So,cl,ul,Do,Ch,Mh,Ym,$o,kl,Le,ae,Zt,T,ve,ki,Ef,$g}from"./index-amys498v.js";import{mt,Ci,gu,Au,bu,Is,Ei,Od}from"./index-4bqssvt6.js";import{Yc,_d,Sd,qg,Hg,Jc,or,ws,Zc,Xc,eu,tu,nu,Cs,Go,Es,wi,au,Sl,Tl,ou,iu,su,lu,cu,uu,du,pu,mu}from"./index-3bf7r7z4.js";import{Ra,Fa,Wo}from"./index-zq0qxb17.js";var gn={name:"git-commit-vertical",size:24,node:[["path",{d:"M12 3v6",key:"1holv5"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"M12 15v6",key:"a9ows0"}]]},De=s(gn);var vn={name:"maximize",size:24,node:[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]},we=s(vn);var yn={name:"minimize",size:24,node:[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]},ke=s(yn);var xn={name:"panel-right-close",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]},Ve=s(xn);var wn={name:"save-all",size:24,node:[["path",{d:"M10 2v3a1 1 0 0 0 1 1h5",key:"1xspal"}],["path",{d:"M18 18v-6a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6",key:"1ra60u"}],["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"M8 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9.172a2 2 0 0 1 1.414.586l2.828 2.828A2 2 0 0 1 22 6.828V16a2 2 0 0 1-2.01 2z",key:"1yve0x"}]]},Se=s(wn);var se=new Set,Ae=new Set,Ke=new Set;function Ue(){Ke=new Set(se);for(let t of[...Ae])t()}function _e(t){let r=new Set(t);if(r.size===se.size){let l=!0;for(let c of r)if(!se.has(c)){l=!1;break}if(l)return}se.clear();for(let l of r)se.add(l);Ue()}function Ge(t){let r=new Set(t),l=!1;for(let c of[...se])if(!r.has(c))se.delete(c),l=!0;if(l)Ue()}function qe(t){return se.has(t)}function Ze(){return se.size>0}function kn(t){return Ae.add(t),()=>{Ae.delete(t)}}var Sn=kn;function Ye(){return je(Sn,()=>Ke)}function Je({x:t,y:r,rows:l,onAction:c,onClose:p}){let g=i(null),[v,h]=n({left:t,top:r});return K(()=>{let y=g.current;if(!y)return;let{width:w,height:x}=y.getBoundingClientRect();h({left:Math.min(t,Math.max(0,window.innerWidth-w-8)),top:Math.min(r,Math.max(0,window.innerHeight-x-8))})},[t,r,l.length]),oe(e("div",{className:"fixed inset-0 z-[70]",onClick:p,onContextMenu:(y)=>{y.preventDefault(),p()},children:e("div",{ref:g,role:"menu","aria-label":"Tab actions",className:"glass-popover absolute w-52 bg-paper border border-ink/15 rounded-md shadow-xl py-1 text-xs text-ink",style:{left:`${v.left}px`,top:`${v.top}px`},onClick:(y)=>y.stopPropagation(),children:l.map((y)=>e("button",{type:"button",role:"menuitem",onClick:()=>{c(y.action),p()},className:"w-full text-left px-3 py-1.5 hover:bg-ink/5 transition-colors cursor-pointer",children:y.label},y.action))})}),document.body)}var ge={rightFileId:null,fraction:0.5};function Ce(t,r,l){if(t===null)return!1;if(t===r)return!1;return l.includes(t)}function Qe(t,r){for(let l=r.length-1;l>=0;l-=1){let c=r[l];if(c!==t)return c}return null}function tt(t,r){if(t.rightFileId===null)return t;if(t.rightFileId!==r)return t;return{...t,rightFileId:null}}function pe(t){if(!Number.isFinite(t))return ge.fraction;return Math.max(0.2,Math.min(0.8,t))}function nt(t,r){if(typeof t!=="object"||t===null)return ge;let l=t,c=typeof l.fraction==="number"?pe(l.fraction):ge.fraction,p=typeof l.rightFileId==="string"||typeof l.rightFileId==="number"?l.rightFileId:null;if(p===null||!r.includes(p))return{rightFileId:null,fraction:c};return{rightFileId:p,fraction:c}}function ot({tab:t,openedFiles:r,dirtyIds:l,reopenable:c,activeFileId:p,splitRightFileId:g}){let v=r.filter((x)=>x.id!==t.id),h=r.filter((x)=>!l.has(x.id)),y=r.map((x)=>x.id);return[{action:"split-right",label:"Split right",enabled:Ce(t.id,p,y)},{action:"unsplit",label:"Unsplit",enabled:g!==null},{action:"close",label:"Close",enabled:!0},{action:"close-others",label:"Close others",enabled:v.length>0},{action:"close-all",label:"Close all",enabled:r.length>0},{action:"close-saved",label:"Close saved",enabled:h.some((x)=>x.id!==t.id)},{action:"copy-path",label:"Copy path",enabled:Boolean(t.path)},{action:"reveal-in-files",label:"Reveal in Files",enabled:Boolean(t.path)&&!t.isDiff},{action:"reopen-closed",label:"Reopen closed tab",enabled:c>0}].filter((x)=>x.enabled)}function be({onHide:t}){let r=$o("toggleEditorPanel","Hide Editor Panel");return e("button",{type:"button",onClick:t,className:"p-1.5 mx-1 rounded transition-colors cursor-pointer text-ink/60 hover:bg-ink/10 hover:text-ink flex-shrink-0",title:r,"aria-label":r,children:e(Ve,{size:14})})}function it({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,missingIds:p,onCopyPath:g,onRevealInFiles:v,onReopenClosed:h,reopenableCount:y,onSplitTo:w,onUnsplit:x,splitRightFileId:k=null,onHide:O}){let C=Ye(),M=i(null),A=i(null),[F,z]=n(5),[I,W]=n(!1),[R,L]=n(null);ue(A,()=>W(!1)),o(()=>{let N=new ResizeObserver((P)=>{for(let H of P){let J=H.contentRect.width,Q=Math.max(1,Math.floor((J-60)/150));z(Q)}});if(M.current)N.observe(M.current);return()=>N.disconnect()},[]);let G=Qe(r,t.map((N)=>N.id)),X=[],Y=[];if(t.length<=F)X=t;else{let N=t.findIndex((H)=>H.id===r),P=new Set;if(N!==-1&&r!==null)P.add(r);for(let H=t.length-1;H>=0;H--){if(P.size>=F)break;P.add(t[H].id)}X=t.filter((H)=>P.has(H.id)),Y=t.filter((H)=>!P.has(H.id))}return e("div",{className:"flex bg-ink/10 w-full relative border-b border-ink/10",ref:M,children:[e("div",{className:"flex overflow-hidden",children:X.map((N)=>{let P=N.id===r,H=Boolean(N.isDiff),J=H?er(N.diffStatus||"M",N.diffStaged):null,Q=Boolean(p?.has(N.id));return e("div",{onClick:()=>l(N.id),onContextMenu:(te)=>{te.preventDefault(),L({tab:N,x:te.clientX,y:te.clientY})},className:`flex items-center space-x-1.5 px-3 py-1.5 cursor-pointer border-r border-ink/10 min-w-[120px] max-w-[210px] group ${P?"bg-paper border-t-2 border-t-ink text-ink":"bg-transparent border-t-2 border-t-transparent text-ink/60 hover:bg-paper/50"}`,title:Q?`${N.path} — file no longer exists`:N.path,children:[H?e(si,{size:14,className:P?"text-info flex-shrink-0":"text-info/70 flex-shrink-0"}):e(ct,{name:N.name,size:14,className:`flex-shrink-0${P||Q?"":" opacity-60"}${Q?" text-error":""}`}),e("span",{className:`text-xs font-mono truncate flex-1${Q?" text-error line-through":""}`,children:N.name}),J&&e("span",{className:`px-1 text-[10px] font-mono font-bold rounded ${J.badgeBgClass}`,children:J.charStatus}),e(rt,{dirty:C.has(N.id),active:P,label:`Close ${N.name}`,onClose:()=>c(N.id)})]},N.id)})}),R?e(Je,{x:R.x,y:R.y,rows:ot({tab:R.tab,openedFiles:t,dirtyIds:C,reopenable:y?.()??0,activeFileId:r,splitRightFileId:k}),onAction:(N)=>{let P=R.tab;switch(N){case"close":c(P.id);return;case"close-others":for(let H of[...t].reverse())if(H.id!==P.id)c(H.id);l(P.id);return;case"close-all":for(let H of[...t].reverse())c(H.id);return;case"close-saved":for(let H of[...t].reverse())if(!C.has(H.id))c(H.id);return;case"copy-path":g?.(P);return;case"reveal-in-files":v?.(P);return;case"reopen-closed":h?.();return;case"split-right":w?.(P.id);return;case"unsplit":x?.();return}},onClose:()=>L(null)}):null,e("div",{className:"ml-auto flex items-center",children:[e("button",{type:"button",onClick:()=>k!==null?x?.():w?.(G),disabled:k===null&&G===null,"aria-pressed":k!==null,"aria-label":"Split editor",title:k!==null?"Close the split pane (the tab stays open)":G===null?"Open another file to split the editor":"Split the editor and show the newest other file",className:`p-1.5 mx-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-default ${k!==null?"bg-ink/10 text-ink":"text-ink/60 hover:bg-ink/10"}`,children:e(Zn,{size:14})}),O&&e(be,{onHide:O})]}),Y.length>0&&e("div",{className:"relative flex items-center bg-ink/10",ref:A,children:[e("button",{className:`p-1.5 mx-1 rounded hover:bg-ink/10 text-ink/60 ${I?"bg-ink/10 text-ink":""}`,onClick:()=>W(!I),title:"More open files",children:e(B,{size:14})}),I&&e("div",{className:"glass-popover absolute right-0 top-full mt-1 w-52 bg-paper border border-ink/10 rounded shadow-lg z-50 py-1",children:[e("div",{className:"px-3 py-1 text-[10px] uppercase font-mono text-ink/40 border-b border-ink/10 mb-1",children:"Older Tabs"}),Y.map((N)=>{let P=Boolean(p?.has(N.id));return e("div",{onClick:()=>{l(N.id),W(!1)},className:"flex items-center space-x-2 px-3 py-1.5 hover:bg-ink/5 cursor-pointer group",children:[N.isDiff?e(si,{size:14,className:"text-info/80"}):e(ct,{name:N.name,size:14,className:P?"text-error":"opacity-60"}),e("span",{className:`text-xs font-mono truncate flex-1 ${P?"text-error line-through":"text-ink/80"}`,children:N.name}),e(rt,{dirty:C.has(N.id),active:!1,label:`Close ${N.name}`,onClose:()=>{if(c(N.id),Y.length===1)W(!1)}})]},N.id)})]})]})]})}function rt({dirty:t,active:r,label:l,onClose:c}){return e("div",{role:"button",tabIndex:-1,"aria-label":l,title:t?`${l} — unsaved changes`:l,className:`p-0.5 rounded hover:bg-ink/10 touch-visible ${r||t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:(p)=>{p.stopPropagation(),c()},children:t?e("span",{className:"block w-2 h-2 rounded-full bg-current mx-0.5","data-tab-dirty":"","aria-hidden":"true"}):e(b,{size:12})})}function Cn(t){if(t===null)return null;let r=new Date(t);if(Number.isNaN(r.getTime()))return null;return r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Te({diskMtimeMs:t,fileName:r,onReload:l,onKeepMine:c}){let p=Cn(t);return e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-[11px] text-ink flex-shrink-0",role:"alert","data-conflict-strip":"",children:[e(_,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"font-medium",children:[e("span",{className:"font-mono",children:r})," changed on disk",p?e("span",{className:"text-ink/60",children:[" at ",p]}):null,"."]}),e("div",{className:"text-ink/60 mt-0.5",children:"Your save was refused so nothing was overwritten."})]}),e("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e("button",{type:"button",onClick:l,className:"px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer",title:"Discard my changes and take the file from disk",children:"Reload"}),e("button",{type:"button",onClick:c,className:"px-2 py-1 rounded border border-warning/50 text-warning hover:bg-warning/10 transition-colors cursor-pointer",title:"Write my buffer over the file on disk",children:"Keep mine"})]})]})}function at(t){if(t.byteViewer)return[];return[{id:"save",pinned:!0,actions:[{label:"Save file",icon:Se,onSelect:t.onSave,disabled:t.saveDisabled}],children:t.saveButton},{id:"save-as",actions:[{label:"Save as…",icon:Se,onSelect:t.onSaveAs}],children:e("button",{type:"button",onClick:t.onSaveAs,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Save the buffer to a new file","aria-label":"Save as",children:e(Se,{size:14})})}]}function st(t){if(!t.hasReview)return[];let r=t.isReviewing?"Exit review mode":"Review this document";return[{id:"review",actions:[{label:r,icon:mn,onSelect:t.onToggleReview,active:t.isReviewing}],children:e(ws,{label:r,pressed:t.isReviewing,title:t.isReviewing?"Review mode is on — click a block to judge it":"Review: click blocks to mark them good or needing work",onClick:t.onToggleReview,children:e(mn,{size:14})})}]}function lt(t){if(!t.hasPreview)return[];return[{id:"preview",actions:[{label:t.previewLabel,icon:t.isPreview?Tt:We,onSelect:t.onTogglePreview,active:t.isPreview}],children:e(ws,{label:t.previewLabel,pressed:t.isPreview,onClick:t.onTogglePreview,children:t.isPreview?e(Tt,{size:14}):e(We,{size:14})})}]}function dt(t){let r=[];if(r.push(...at(t),...st(t),...lt(t)),!t.byteViewer)r.push({id:"find",actions:[{label:t.findLabel,icon:U,onSelect:t.onToggleFind,active:t.findOpen}],children:e(ws,{label:t.findLabel,pressed:t.findOpen,title:`${t.findLabel} (Ctrl+F)`,onClick:t.onToggleFind,children:e(U,{size:14})})}),r.push({id:"wrap",actions:[{label:t.wordWrapLabel,icon:rn,onSelect:t.onToggleWordWrap,active:t.wordWrap}],children:e(ws,{label:t.wordWrapLabel,pressed:t.wordWrap,onClick:t.onToggleWordWrap,children:e(rn,{size:14})})}),r.push({id:"blame",actions:[{label:t.blameInline?"Hide line blame":"Show line blame",icon:De,onSelect:t.onToggleBlameInline,active:t.blameInline}],children:e(ws,{label:t.blameInline?"Hide line blame":"Show line blame",pressed:t.blameInline,title:"Who last changed each block, from git (hover a line for the commit)",onClick:t.onToggleBlameInline,children:e(De,{size:14})})}),r.push({id:"zoom",actions:[{label:"Decrease font size",icon:Fa,onSelect:t.onZoomOut},{label:"Increase font size",icon:Ra,onSelect:t.onZoomIn}],children:e(d,{children:[e("button",{type:"button",onClick:t.onZoomOut,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Decrease font size","aria-label":"Decrease font size",children:e(Fa,{size:14})}),e("button",{type:"button",onClick:t.onZoomIn,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Increase font size","aria-label":"Increase font size",children:e(Ra,{size:14})})]})}),r.push({id:"reload",actions:[{label:"Reload from disk",icon:D,onSelect:t.onReload,disabled:!t.canReload}],children:e("button",{type:"button",onClick:t.onReload,disabled:!t.canReload||t.refreshing,"aria-busy":t.refreshing,className:`${or} hover:bg-ink/5 hover:text-ink`,title:!t.canReload?"Nothing to reload — this tab has no file on disk":t.reloadDiscardsEdits?"Discard my changes and reload from disk":"Reload from disk","aria-label":"Reload from disk",children:e(D,{size:14,className:t.refreshing?"animate-spin":void 0})})});return r.push({id:"copy",actions:[{label:t.copyLabel,icon:re,onSelect:t.onCopy},{label:"Download file",icon:fe,onSelect:t.onDownload}],children:e(d,{children:[e("button",{type:"button",onClick:t.onCopy,className:`${or} hover:bg-ink/5 hover:text-ink`,title:t.copyLabel,"aria-label":t.copyLabel,children:t.copied?e(re,{size:14,className:"text-success"}):e(re,{size:14})}),e("button",{type:"button",onClick:t.onDownload,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Download file","aria-label":"Download file",children:e(fe,{size:14})})]})}),r.push({id:"view-modes",pinned:!0,actions:t.viewModeActions,children:t.viewModeButtons}),r.push({id:"maximize",pinned:!0,actions:[{label:t.maximizeLabel,icon:t.isMaximized?ke:we,onSelect:t.onToggleMaximize,active:t.isMaximized}],children:t.maximizeButton}),r}function ut({path:t,saveStatus:r,wordWrap:l,hasPreview:c,isPreview:p,hasReview:g,isReviewing:v,copied:h,byteViewer:y=!1,saveDisabled:w=!1,unsupported:x=!1,handleMissing:k=!1,readOnly:O=!1,isMaximized:C=!1,findOpen:M=!1,onToggleFind:A,onSave:F,onTogglePreview:z,onToggleReview:I,onToggleWordWrap:W,onZoomIn:R,onZoomOut:L,onCopy:G,onDownload:X,onReload:Y,canReload:N,refreshing:P=!1,reloadDiscardsEdits:H,onSaveAs:J,onToggleMaximize:Q}){let te=w?O?"Read-only — this file was opened from the phone, not from a workspace":k?"Cannot save — reopen the file from the system to restore write access":x?"Nothing to save — this file cannot be opened as a document":"Nothing to save — this file could not be read":r==="needs-permission"?"Click Save to allow writing this file":r==="saving"?"Saving…":r==="error"?"Save failed — the file on disk was not changed":"Save file (Ctrl+S)",ie=e("button",{type:"button",onClick:F,disabled:w||r==="saving",className:`${or} hover:bg-ink/5`,title:te,"aria-label":te,children:r==="saving"?e(mt,{size:14,className:"text-warning animate-pulse"}):r==="saved"?e(f,{size:14,className:"text-success"}):r==="error"?e(E,{size:14,className:"text-error"}):r==="needs-permission"?e(mt,{size:14,className:"text-warning"}):e(mt,{size:14,className:"hover:text-ink"})}),le=C?"Exit full screen":"Full screen",ee=e("button",{type:"button",onClick:Q,className:`${or} hover:bg-ink/5 hover:text-ink ${C?"text-ink":""}`,title:le,"aria-label":le,"aria-pressed":C,children:C?e(ke,{size:14}):e(we,{size:14})}),ne=Od(),de=_d(),ce=dt({byteViewer:y,hasPreview:c,isPreview:p,wordWrap:l,hasReview:g,isReviewing:v,blameInline:ne.inline,findOpen:M,copied:h,isMaximized:C,saveDisabled:w,canReload:N,refreshing:P,reloadDiscardsEdits:H,saveButton:ie,maximizeButton:ee,viewModeButtons:e(Sd,{size:14}),viewModeActions:de,previewLabel:p?"Show source":"Show preview",findLabel:"Find and replace",wordWrapLabel:l?"Word wrap on":"Word wrap off",copyLabel:h?"Copied":y?"Copy image":"Copy content",maximizeLabel:le,onTogglePreview:z,onToggleReview:I,onToggleFind:A,onToggleWordWrap:W,onToggleBlameInline:()=>{let he={...Ei(),inline:!ne.inline};hr({editorBlameInline:he.inline}),window.dispatchEvent(new CustomEvent(Is,{detail:he}))},onZoomIn:R,onZoomOut:L,onCopy:G,onDownload:X,onReload:Y,onSaveAs:J,onToggleMaximize:Q,onSave:F});return e("div",{className:"@container flex items-center justify-between gap-2 px-3 py-2 border-b border-ink/10 bg-paper flex-shrink-0",children:[e("div",{className:"hidden @[420px]:flex items-center space-x-2 text-xs font-mono text-ink/40 min-w-0",children:e("span",{className:"truncate max-w-[300px]",title:t,children:t})}),e(Wo,{clusters:ce,className:"text-ink/40 ml-auto"})]})}function pt({content:t,file:r,zoomLevel:l,reviewActive:c,onExitReview:p,scrollRef:g,onScroll:v}){return e("div",{ref:g,onScroll:v,"data-testid":"editor-scroller",className:"flex-1 overflow-auto bg-paper flex",children:e("div",{className:"p-6 max-w-4xl mx-auto font-sans flex-1",style:{fontSize:`${l}px`},children:e(Zc,{content:t,file:r,active:c,onExit:p})})})}function En(t,r){return r?`Spaces: ${t}`:"Tabs"}function ft({caret:t,eol:r,onSetEol:l,indentWidth:c,insertSpaces:p,language:g,byteViewer:v,viewerKind:h,lineCount:y,conflicts:w=0}){return e("footer",{className:"flex bg-canvas border-t border-ink/10 px-3 items-center justify-between text-[10px] text-ink/50 flex-shrink-0 font-mono h-6","data-editor-status-bar":"",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:v?e("span",{className:"uppercase",children:Go[h]}):e(d,{children:[e("span",{className:"tabular-nums",children:t?`Ln ${t.line}, Col ${t.column}`:"Ln —, Col —"}),e("span",{children:En(c,p)}),e("button",{type:"button",onClick:()=>l(r==="lf"?"crlf":"lf"),className:"uppercase hover:text-ink transition-colors cursor-pointer",title:`Line endings: ${r.toUpperCase()} — click to switch`,"aria-label":`Line endings ${r.toUpperCase()}, switch`,children:r}),e("span",{children:[y," lines"]})]})}),e("div",{className:"flex items-center gap-3 min-w-0",children:[w>0&&e("span",{className:"text-error font-semibold tabular-nums",title:`${w} unresolved conflict${w===1?"":"s"} — markers are highlighted in the file`,children:["⚠ ",w," conflict",w===1?"":"s"]}),e("span",{className:"uppercase text-ink/40",children:g})]})]})}function Tn(t){if(t===0)return 0;return Math.max(-1,Math.min(1,-Math.sign(t)))}function Mn(t,r,l=cl,c=ul){return Math.max(l,Math.min(c,t+r))}function Nn(t,r){let l=t instanceof HTMLElement?t:null;while(l&&l!==r){let c=getComputedStyle(l);if(/(auto|scroll)/.test(c.overflowY)&&l.scrollHeight>l.clientHeight)return!0;l=l.parentElement}return!1}function bt(t,r){o(()=>{if(!t)return;let l=t.closest("[data-code-surface]"),c=l instanceof HTMLElement?l:t,p=(g)=>{if(!g.ctrlKey&&!g.metaKey)return;if(g.preventDefault(),Nn(g.target,c))return;let v=Tn(g.deltaY);if(v===0)return;r((h)=>Mn(h,v))};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[t,r])}function ht(t,r){let l=t.trim();if(!/^\d+$/.test(l))return null;let c=Number(l);if(c<1)return null;return Math.min(c,Math.max(r,1))}function gt({lineCount:t,onGo:r,onClose:l}){let[c,p]=n(""),g=i(null);o(()=>{g.current?.focus(),g.current?.select()},[]);let v=()=>{let w=ht(c,t);if(w===null)return;r(w)},h=(w)=>{if(w.key==="Enter"){w.preventDefault(),v();return}if(w.key==="Escape")w.preventDefault(),l()},y=ht(c,t);return e(Z,{onClose:l,maxWidthClass:"max-w-xs",header:e("span",{className:"text-sm font-semibold text-ink",children:"Go to line"}),children:e("div",{className:"px-4 py-3 space-y-2",children:[e("div",{className:"flex items-center gap-2",children:[e("input",{ref:g,value:c,onInput:(w)=>p(w.target.value),onKeyDown:h,inputMode:"numeric",placeholder:"1","aria-label":"Line number",className:"flex-1 bg-paper border border-ink/20 rounded px-2 py-1 text-xs font-mono text-ink outline-none focus:border-ink/40"}),e("span",{className:"text-[10px] font-mono text-ink/40",children:["/ ",t]}),e("button",{type:"button",onClick:v,disabled:y===null,className:"flex items-center gap-1 px-2 py-1 rounded bg-ink text-paper text-xs disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[e(Xe,{size:12}),"Go"]})]}),c&&y!==null&&String(y)!==c.trim()?e("div",{className:"text-[10px] text-ink/50 font-mono",children:["line ",y," (the last line)"]}):null,c&&y===null?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a line number"}):null]})})}var vt={status:"idle",payload:null,message:null};function yt(t){if(!t?.path)return"";return`${t.root??""}\x00${t.repo??""}\x00${t.path}`}function xt(t,r={}){let l=r.enabled!==!1&&Boolean(t?.path)&&t?.deviceFile!==!0,c=r.dirty===!0,p=yt(t),[g,v]=n({key:"",value:vt}),h=i(t);h.current=t;let y=i(p);y.current=p;let w=i(l);w.current=l;let x=i(c);x.current=c;let k=i(g);k.current=g;let O=i(0),C=i(""),M=i(new Map),A=i(new Set),F=a(async()=>{let L=h.current;if(!L?.path)return;let G=yt(L),X=++O.current;C.current=G,v((N)=>({key:G,value:{status:"loading",payload:N.key===G?N.value.payload:null,message:null}}));let Y=new URLSearchParams({blame:"1",file:L.path,repo:L.repo||"."});if(L.root)Y.set("root",L.root);try{let N=await fetch(`/api/fs/git?${Y.toString()}`),P=await N.json().catch(()=>null);if(X!==O.current)return;if(!N.ok||!P){v({key:G,value:{status:"error",payload:null,message:P?.error??`Blame request failed (HTTP ${N.status})`}});return}v({key:G,value:P.available?{status:"ready",payload:P,message:null}:{status:"unavailable",payload:P,message:P.message??null}})}catch(N){if(X!==O.current)return;v({key:G,value:{status:"error",payload:null,message:N instanceof Error?N.message:"Blame failed"}})}finally{if(C.current===G)C.current=""}},[]),z=a(async(L)=>{let G=M.current.get(L);if(G)return G;let X=h.current;if(!X?.path)return{entries:[],truncated:!1};let Y=new URLSearchParams({blameHistory:"1",file:X.path,line:String(L),repo:X.repo||"."});if(X.root)Y.set("root",X.root);try{let P=await(await fetch(`/api/fs/git?${Y.toString()}`)).json().catch(()=>null),H={entries:Array.isArray(P?.entries)?P.entries:[],truncated:P?.truncated===!0};return M.current.set(L,H),H}catch{return{entries:[],truncated:!1}}},[]),I=i(null);if(!I.current)I.current={ensure:()=>{if(!w.current||x.current)return;let L=k.current;if(L.key===y.current&&L.value.status!=="idle")return;if(C.current===y.current)return;F()},reload:()=>{M.current.clear(),F()},history:z,snapshot:()=>{let L=k.current;return L.key===y.current?L.value:vt},stale:()=>x.current,subscribe:(L)=>(A.current.add(L),()=>{A.current.delete(L)})};o(()=>{if(!l||c||!p)return;M.current.clear(),F()},[l,c,p,F]);let W=i(c);return o(()=>{if(W.current===c)return;W.current=c;for(let L of A.current)L()},[c]),o(()=>{for(let L of A.current)L()},[g]),I.current}var Rn="0".repeat(40);function Me(t){return t===Rn}function ye(t,r=Date.now()){let l=Math.max(0,Math.floor(r/1000)-t);if(l<60)return"just now";let c=Math.floor(l/60);if(c<60)return`${c}m ago`;let p=Math.floor(c/60);if(p<24)return`${p}h ago`;let g=Math.floor(p/24);if(g<30)return`${g}d ago`;let v=Math.floor(g/30);if(v<12)return`${v}mo ago`;return`${Math.floor(g/365)}y ago`}function wt(t,r){switch(t){case"not-repo":return"This folder is not a git repository.";case"no-commit":return"This repository has no commits yet.";case"untracked":return"This file has never been committed, so it has no history.";case"too-large":return r??"This file is too large to blame.";case"empty":return"This file is empty.";default:return r??"git could not read this file."}}var Et="fixed z-50 w-[min(340px,92vw)] rounded-xl border border-ink/20 bg-paper p-3 shadow-xl font-sans text-xs text-ink",kt="flex items-baseline justify-between gap-2",St="truncate text-xs font-semibold text-ink",Pn="shrink-0 font-mono text-[10px] text-ink/40",Ln="mt-1 line-clamp-2 text-[11px] leading-snug text-ink/80",Bn="mt-2 border-t border-ink/10 pt-2",Dn="flex items-center gap-2 font-mono text-[10px] text-ink/40",Ct="mt-1 text-[10px] leading-snug text-ink/50",On="mt-2 flex w-full items-center gap-1.5 text-left text-[10px] text-ink/50 hover:text-ink cursor-pointer",An="mt-1.5 space-y-1 border-t border-ink/10 pt-1.5",Ne="flex items-center gap-1.5 font-mono text-[10px]";function q(t,r,l){let c=document.createElement(t);if(c.className=r,l!==void 0)c.textContent=l;return c}function In(t){return new Date(t*1000).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Fn(t){let r=t.payload;if(t.status==="error")return{title:"Blame failed",body:t.message??"git could not read this file."};if(t.status==="unavailable")return{title:r?.reason==="untracked"?"Not tracked":"No history",body:wt(r?.reason??"error",t.message??void 0)};if(!r)return null;if(t.stale)return{title:"Not committed yet",body:"This line changed in the editor. Save the file to see its blame."};if(t.line>r.lines)return{title:"Not committed yet",body:`Line ${t.line} is past the end of the file at HEAD (${r.lines} lines).`};let l=r.runs.length>0?Mt(r,t.line):null;if(!l)return{title:"Not committed yet",body:`git has no attribution for line ${t.line}.`};if(Me(l.sha))return{title:"Not committed yet",body:"This line differs from the last commit."};return null}function Mt(t,r){for(let l of t.runs)if(r>=l.from&&r<=l.to)return t.commits[l.sha]??null;return null}function zn(t,r){t.replaceChildren(),t.className=Et;let l=Fn(r);if(l){let w=q("div",kt);if(w.append(q("span",St,l.title)),r.status==="error"&&r.message){let x=q("button","shrink-0 cursor-pointer text-[10px] text-ink/50 hover:text-ink","Try again");x.type="button",x.setAttribute("aria-label","Read the blame again"),w.append(x)}t.append(w,q("p",Ct,l.body));return}let c=r.payload;if(!c){t.append(q("p",Ct,"Reading blame…"));return}let p=Mt(c,r.line),g=q("div",kt);if(g.append(q("span",St,p.author.trim()||"Unknown"),q("span",Pn,ye(p.time))),t.append(g),p.summary)t.append(q("p",Ln,p.summary));let v=q("div",`${Dn} ${Bn}`);if(v.append(q("code","truncate",p.sha.slice(0,7)),q("span","",In(p.time))),p.mail){let w=q("span","truncate",p.mail);w.title=p.mail,v.append(w)}t.append(v);let h=q("button",On);if(h.type="button",h.setAttribute("aria-expanded",r.historyOpen?"true":"false"),h.textContent=`${r.historyOpen?"▾":"▸"} Line history`,t.append(h),!r.historyOpen)return;let y=q("ol",An);if(r.historyLoading)y.append(q("li",`${Ne} text-ink/40`,"Reading history…"));else if(!r.history||r.history.entries.length===0)y.append(q("li",`${Ne} text-ink/40`,"No commits touched this line."));else{let w=r.history.entries;if(w.forEach((x,k)=>{let O=q("li",Ne),C=k===w.length-1?"new":"edit";O.append(q("span","text-ink/40",k===0?"●":"○"),q("code","text-ink/60",x.sha.slice(0,7)),q("span","truncate text-ink/80",x.author.trim()||"Unknown"),q("span","ml-auto shrink-0 text-ink/40",ye(x.time)),q("span","shrink-0 rounded bg-ink/5 px-1 text-[8.5px] uppercase tracking-wider text-ink/45",C)),y.append(O)}),r.history.truncated)y.append(q("li",`${Ne} text-ink/40`,"Older commits are not shown."))}t.append(y)}function Nt(t,r,l){let c=q("div",Et);c.setAttribute("role","dialog"),c.setAttribute("aria-label","Line blame"),c.addEventListener("mousedown",(x)=>x.stopPropagation());let p=null,g=!1,v=!1,h=()=>{let x=r.snapshot();return{line:t,status:x.status,payload:x.payload,message:x.message,stale:r.stale(),history:p,historyOpen:g,historyLoading:v}},y=()=>{zn(c,h());let x=c.querySelector('[aria-label="Read the blame again"]');if(x)x.addEventListener("click",(k)=>{k.stopPropagation(),l()});c.querySelector("button[aria-expanded]")?.addEventListener("click",(k)=>{if(k.stopPropagation(),g=!g,y(),!g||p||v)return;v=!0,y(),r.history(t).then((O)=>{p=O,v=!1,y()})})};y();let w=r.subscribe(y);return{element:c,place(x){let k=c.ownerDocument.defaultView,O=k?.innerWidth??1024,C=k?.innerHeight??768,M=c.offsetWidth||340,A=c.offsetHeight||120,F=8,z=Math.max(8,Math.min(x.left,O-M-8)),I=x.bottom+6,W=x.top-A-6,R=I+A>C-8&&W>8?W:I;c.style.left=`${z}px`,c.style.top=`${Math.max(8,R)}px`},destroy(){w(),c.remove()}}}function Rt(t){return ve.define((r)=>{let l=null,c=0,p,g=()=>{clearTimeout(p),p=void 0,l?.destroy(),l=null,c=0},v=(C,M)=>{let A=C.getBoundingClientRect();if(A.width>0)return{left:A.left,top:A.top,bottom:A.bottom};let F=r.state.doc.line(Math.min(M,r.state.doc.lines)),z=null;try{z=r.coordsAtPos(F.from)}catch{z=null}if(z)return z;let I=r.scrollDOM.getBoundingClientRect();return{left:I.left,top:I.top+24,bottom:I.top+24}},h=(C,M)=>{if(c===C&&l)return;g(),c=C,l=Nt(C,t,()=>{t.reload(),g()}),document.body.append(l.element),l.place(M)},y=(C)=>{let M=C.target,A=M?.closest?.(".cm-blame-label");if(A){let I=Number(A.dataset.blameLine);return Number.isInteger(I)&&I>0?{line:I,anchor:A}:null}let F=M?.closest?.(".cm-lineNumbers .cm-gutterElement");if(!F)return null;let z=Number((F.textContent??"").trim());return Number.isInteger(z)&&z>0?{line:z,anchor:F}:null},w=(C)=>{let M=y(C);if(!M)return;h(M.line,v(M.anchor,M.line))},x=(C)=>{let M=y(C);if(M){C.preventDefault(),h(M.line,v(M.anchor,M.line));return}if(l&&!l.element.contains(C.target))g()},k=(C)=>{if(C.key==="Escape"&&l)g(),C.stopPropagation()},O=(C)=>{if(!l)return;let M=C.relatedTarget;if(M&&(l.element.contains(M)||r.scrollDOM.contains(M)))return;p=setTimeout(g,200)};return r.scrollDOM.addEventListener("mouseover",w),r.scrollDOM.addEventListener("mouseleave",O),r.scrollDOM.addEventListener("mousedown",x),document.addEventListener("mousedown",x),document.addEventListener("keydown",k,!0),{update(C){if(C.docChanged&&l)g()},destroy(){g(),r.scrollDOM.removeEventListener("mouseover",w),r.scrollDOM.removeEventListener("mouseleave",O),r.scrollDOM.removeEventListener("mousedown",x),document.removeEventListener("mousedown",x),document.removeEventListener("keydown",k,!0)}}})}var Pt=40,Bt=ae.define();function Hn(t){return Le.define({create:()=>({payload:t.snapshot().payload,stale:!1}),update(r,l){let c=r;for(let p of l.effects){if(!p.is(Bt))continue;c=p.value.payload!==r.payload?{payload:p.value.payload,stale:!1}:{payload:r.payload,stale:r.stale}}if(l.docChanged&&!c.stale)c={payload:c.payload,stale:!0};return c}})}function $n(t,r,l){let c=t.commits[r];if(!c||Me(r))return null;let p=c.author.trim()||"Unknown";return l?p:`${p} · ${ye(c.time)}`}class Dt extends Zt{constructor(t,r,l){super();this.line=t;this.text=r;this.title=l}eq(t){return t.line===this.line&&t.text===this.text&&t.title===this.title}toDOM(){let t=document.createElement("span");return t.className="cm-blame-label",t.dataset.blameLine=String(this.line),t.title=this.title,t.textContent=this.text,t}}function Lt(t,r,l){let{payload:c,stale:p}=t;if(!c?.available||p)return T.none;let g=Math.min(c.lines,r.state.doc.lines);if(g<1)return T.none;let v=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.from,r.state.doc.length))).number,h=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.to,r.state.doc.length))).number,y=Math.max(1,v-Pt),w=Math.min(g,h+Pt),x=[];for(let k of c.runs){let O=Math.max(k.from,y);if(O>k.to||O>w)continue;let C=$n(c,k.sha,l);if(!C)continue;let M=c.commits[k.sha],A=r.state.doc.line(O);x.push({from:A.to,deco:T.widget({widget:new Dt(A.number,C,M.summary||M.sha),side:1})})}return T.set(x.map((k)=>k.deco.range(k.from)),!0)}function Vn(t,r){return ve.fromClass(class{constructor(l){this.view=l;this.decorations=Lt(l.state.field(t),l,r)}update(l){if(l.startState.field(t)===l.state.field(t)&&!l.docChanged&&!l.viewportChanged)return;this.decorations=Lt(l.state.field(t),l.view,r)}},{decorations:(l)=>l.decorations})}function Wn(t){return ve.define((r)=>{let l=!0,c=()=>{if(!l)return;let g=t.snapshot();r.dispatch({effects:Bt.of({payload:g.payload,stale:!1})})},p=t.subscribe(c);return{destroy(){l=!1,p()}}})}function Ot({controller:t,inline:r=!0,compact:l=!1}){let c=Hn(t);return[c,Wn(t),r?Vn(c,l):[],Rt(t)]}function At({activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:p,rootPath:g=null,repoPath:v=null,onRunCommand:h,wordWrap:y,zoomLevel:w,setZoomLevel:x,editorFontFamily:k,editorTheme:O,viewerKind:C,isPreview:M,reviewActive:A,onToggleReview:F,revealActive:z}){let I=C==="markdown",W=Au(),R=bu(),L=Od(),G=xt({name:t.name,path:t.path,root:t.root??g??void 0,repo:t.repo??v??"."},{enabled:L.enabled,dirty:r.isDirty}),X=u(()=>L.enabled?Ot({controller:G,inline:L.inline}):null,[L.enabled,L.inline,G]),[Y,N]=n(null),P=u(()=>Xc(r.content),[r.content]),[H,J]=n(!1);o(()=>{if(p>0)J(!0)},[p]);let[Q,te]=n(null),[ie,le]=n(null);bt(Q,x);let ee=kl({tabKey:String(t.id),surface:I&&M?"rendered":"code",ready:r.loaded,element:I&&M?void 0:Q}),ne=a((de)=>{ee.ref(de),le(de)},[ee.ref]);return nu({path:t.path,scroller:ie,preview:I&&M}),e("div",{className:"relative flex-1 min-h-0 flex flex-col",children:[l.open?e(tu,{find:l}):null,H?e(gt,{lineCount:r.content?r.content.split(`
1
+ import{d,n,o,K,i,u,a,je,oe,e,s,E,m,rn,_,f,B,re,Xe,fe,Tt,We,si,mn,Zn,D,U,b,er,Oe,xe,S,hr,et,ue,br,Z,ct,ll,So,cl,ul,Do,Ch,Mh,Ym,$o,kl,Le,ae,Zt,T,ve,ki,Ef,$g}from"./index-4cag7w6k.js";import{mt,Ci,gu,Au,bu,Is,Ei,Od}from"./index-83rkg916.js";import{Yc,_d,Sd,qg,Hg,Jc,or,ws,Zc,Xc,eu,tu,nu,Cs,Go,Es,wi,au,Sl,Tl,ou,iu,su,lu,cu,uu,du,pu,mu}from"./index-dt6q3rws.js";import{Ra,Fa,Wo}from"./index-fzngzhww.js";var gn={name:"git-commit-vertical",size:24,node:[["path",{d:"M12 3v6",key:"1holv5"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"M12 15v6",key:"a9ows0"}]]},De=s(gn);var vn={name:"maximize",size:24,node:[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]},ke=s(vn);var yn={name:"minimize",size:24,node:[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]},Se=s(yn);var xn={name:"panel-right-close",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]},Ve=s(xn);var wn={name:"save-all",size:24,node:[["path",{d:"M10 2v3a1 1 0 0 0 1 1h5",key:"1xspal"}],["path",{d:"M18 18v-6a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6",key:"1ra60u"}],["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"M8 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9.172a2 2 0 0 1 1.414.586l2.828 2.828A2 2 0 0 1 22 6.828V16a2 2 0 0 1-2.01 2z",key:"1yve0x"}]]},Ce=s(wn);var se=new Set,Ae=new Set,Ke=new Set;function Ue(){Ke=new Set(se);for(let t of[...Ae])t()}function _e(t){let r=new Set(t);if(r.size===se.size){let l=!0;for(let c of r)if(!se.has(c)){l=!1;break}if(l)return}se.clear();for(let l of r)se.add(l);Ue()}function Ge(t){let r=new Set(t),l=!1;for(let c of[...se])if(!r.has(c))se.delete(c),l=!0;if(l)Ue()}function qe(t){return se.has(t)}function Ze(){return se.size>0}function kn(t){return Ae.add(t),()=>{Ae.delete(t)}}var Sn=kn;function Ye(){return je(Sn,()=>Ke)}function Je({x:t,y:r,rows:l,onAction:c,onClose:p}){let g=i(null),[v,h]=n({left:t,top:r});return K(()=>{let y=g.current;if(!y)return;let{width:w,height:x}=y.getBoundingClientRect();h({left:Math.min(t,Math.max(0,window.innerWidth-w-8)),top:Math.min(r,Math.max(0,window.innerHeight-x-8))})},[t,r,l.length]),oe(e("div",{className:"fixed inset-0 z-[70]",onClick:p,onContextMenu:(y)=>{y.preventDefault(),p()},children:e("div",{ref:g,role:"menu","aria-label":"Tab actions",className:"glass-popover absolute w-52 bg-paper border border-ink/15 rounded-md shadow-xl py-1 text-xs text-ink",style:{left:`${v.left}px`,top:`${v.top}px`},onClick:(y)=>y.stopPropagation(),children:l.map((y)=>e("button",{type:"button",role:"menuitem",onClick:()=>{c(y.action),p()},className:"w-full text-left px-3 py-1.5 hover:bg-ink/5 transition-colors cursor-pointer",children:y.label},y.action))})}),document.body)}var ge={rightFileId:null,fraction:0.5};function Ee(t,r,l){if(t===null)return!1;if(t===r)return!1;return l.includes(t)}function Qe(t,r){for(let l=r.length-1;l>=0;l-=1){let c=r[l];if(c!==t)return c}return null}function tt(t,r){if(t.rightFileId===null)return t;if(t.rightFileId!==r)return t;return{...t,rightFileId:null}}function pe(t){if(!Number.isFinite(t))return ge.fraction;return Math.max(0.2,Math.min(0.8,t))}function nt(t,r){if(typeof t!=="object"||t===null)return ge;let l=t,c=typeof l.fraction==="number"?pe(l.fraction):ge.fraction,p=typeof l.rightFileId==="string"||typeof l.rightFileId==="number"?l.rightFileId:null;if(p===null||!r.includes(p))return{rightFileId:null,fraction:c};return{rightFileId:p,fraction:c}}function ot({tab:t,openedFiles:r,dirtyIds:l,reopenable:c,activeFileId:p,splitRightFileId:g}){let v=r.filter((x)=>x.id!==t.id),h=r.filter((x)=>!l.has(x.id)),y=r.map((x)=>x.id);return[{action:"split-right",label:"Split right",enabled:Ee(t.id,p,y)},{action:"unsplit",label:"Unsplit",enabled:g!==null},{action:"close",label:"Close",enabled:!0},{action:"close-others",label:"Close others",enabled:v.length>0},{action:"close-all",label:"Close all",enabled:r.length>0},{action:"close-saved",label:"Close saved",enabled:h.some((x)=>x.id!==t.id)},{action:"copy-path",label:"Copy path",enabled:Boolean(t.path)},{action:"reveal-in-files",label:"Reveal in Files",enabled:Boolean(t.path)&&!t.isDiff},{action:"reopen-closed",label:"Reopen closed tab",enabled:c>0}].filter((x)=>x.enabled)}function be({onHide:t}){let r=$o("toggleEditorPanel","Hide Editor Panel");return e("button",{type:"button",onClick:t,className:"p-1.5 mx-1 rounded transition-colors cursor-pointer text-ink/60 hover:bg-ink/10 hover:text-ink flex-shrink-0",title:r,"aria-label":r,children:e(Ve,{size:14})})}function it({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,missingIds:p,onCopyPath:g,onRevealInFiles:v,onReopenClosed:h,reopenableCount:y,onSplitTo:w,onUnsplit:x,splitRightFileId:k=null,onHide:O}){let C=Ye(),M=i(null),A=i(null),[F,z]=n(5),[I,W]=n(!1),[R,L]=n(null);ue(A,()=>W(!1)),o(()=>{let N=new ResizeObserver((P)=>{for(let H of P){let J=H.contentRect.width,Q=Math.max(1,Math.floor((J-60)/150));z(Q)}});if(M.current)N.observe(M.current);return()=>N.disconnect()},[]);let G=Qe(r,t.map((N)=>N.id)),X=[],Y=[];if(t.length<=F)X=t;else{let N=t.findIndex((H)=>H.id===r),P=new Set;if(N!==-1&&r!==null)P.add(r);for(let H=t.length-1;H>=0;H--){if(P.size>=F)break;P.add(t[H].id)}X=t.filter((H)=>P.has(H.id)),Y=t.filter((H)=>!P.has(H.id))}return e("div",{className:"flex bg-ink/10 w-full relative border-b border-ink/10",ref:M,children:[e("div",{className:"flex overflow-hidden",children:X.map((N)=>{let P=N.id===r,H=Boolean(N.isDiff),J=H?er(N.diffStatus||"M",N.diffStaged):null,Q=Boolean(p?.has(N.id));return e("div",{onClick:()=>l(N.id),onContextMenu:(te)=>{te.preventDefault(),L({tab:N,x:te.clientX,y:te.clientY})},className:`flex items-center space-x-1.5 px-3 py-1.5 cursor-pointer border-r border-ink/10 min-w-[120px] max-w-[210px] group ${P?"bg-paper border-t-2 border-t-ink text-ink":"bg-transparent border-t-2 border-t-transparent text-ink/60 hover:bg-paper/50"}`,title:Q?`${N.path} — file no longer exists`:N.path,children:[H?e(si,{size:14,className:P?"text-info flex-shrink-0":"text-info/70 flex-shrink-0"}):e(ct,{name:N.name,size:14,className:`flex-shrink-0${P||Q?"":" opacity-60"}${Q?" text-error":""}`}),e("span",{className:`text-xs font-mono truncate flex-1${Q?" text-error line-through":""}`,children:N.name}),J&&e("span",{className:`px-1 text-[10px] font-mono font-bold rounded ${J.badgeBgClass}`,children:J.charStatus}),e(rt,{dirty:C.has(N.id),active:P,label:`Close ${N.name}`,onClose:()=>c(N.id)})]},N.id)})}),R?e(Je,{x:R.x,y:R.y,rows:ot({tab:R.tab,openedFiles:t,dirtyIds:C,reopenable:y?.()??0,activeFileId:r,splitRightFileId:k}),onAction:(N)=>{let P=R.tab;switch(N){case"close":c(P.id);return;case"close-others":for(let H of[...t].reverse())if(H.id!==P.id)c(H.id);l(P.id);return;case"close-all":for(let H of[...t].reverse())c(H.id);return;case"close-saved":for(let H of[...t].reverse())if(!C.has(H.id))c(H.id);return;case"copy-path":g?.(P);return;case"reveal-in-files":v?.(P);return;case"reopen-closed":h?.();return;case"split-right":w?.(P.id);return;case"unsplit":x?.();return}},onClose:()=>L(null)}):null,e("div",{className:"ml-auto flex items-center",children:[e("button",{type:"button",onClick:()=>k!==null?x?.():w?.(G),disabled:k===null&&G===null,"aria-pressed":k!==null,"aria-label":"Split editor",title:k!==null?"Close the split pane (the tab stays open)":G===null?"Open another file to split the editor":"Split the editor and show the newest other file",className:`p-1.5 mx-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-default ${k!==null?"bg-ink/10 text-ink":"text-ink/60 hover:bg-ink/10"}`,children:e(Zn,{size:14})}),O&&e(be,{onHide:O})]}),Y.length>0&&e("div",{className:"relative flex items-center bg-ink/10",ref:A,children:[e("button",{className:`p-1.5 mx-1 rounded hover:bg-ink/10 text-ink/60 ${I?"bg-ink/10 text-ink":""}`,onClick:()=>W(!I),title:"More open files",children:e(B,{size:14})}),I&&e("div",{className:"glass-popover absolute right-0 top-full mt-1 w-52 bg-paper border border-ink/10 rounded shadow-lg z-50 py-1",children:[e("div",{className:"px-3 py-1 text-[10px] uppercase font-mono text-ink/40 border-b border-ink/10 mb-1",children:"Older Tabs"}),Y.map((N)=>{let P=Boolean(p?.has(N.id));return e("div",{onClick:()=>{l(N.id),W(!1)},className:"flex items-center space-x-2 px-3 py-1.5 hover:bg-ink/5 cursor-pointer group",children:[N.isDiff?e(si,{size:14,className:"text-info/80"}):e(ct,{name:N.name,size:14,className:P?"text-error":"opacity-60"}),e("span",{className:`text-xs font-mono truncate flex-1 ${P?"text-error line-through":"text-ink/80"}`,children:N.name}),e(rt,{dirty:C.has(N.id),active:!1,label:`Close ${N.name}`,onClose:()=>{if(c(N.id),Y.length===1)W(!1)}})]},N.id)})]})]})]})}function rt({dirty:t,active:r,label:l,onClose:c}){return e("div",{role:"button",tabIndex:-1,"aria-label":l,title:t?`${l} — unsaved changes`:l,className:`p-0.5 rounded hover:bg-ink/10 touch-visible ${r||t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:(p)=>{p.stopPropagation(),c()},children:t?e("span",{className:"block w-2 h-2 rounded-full bg-current mx-0.5","data-tab-dirty":"","aria-hidden":"true"}):e(b,{size:12})})}function Cn(t){if(t===null)return null;let r=new Date(t);if(Number.isNaN(r.getTime()))return null;return r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Te({diskMtimeMs:t,fileName:r,onReload:l,onKeepMine:c}){let p=Cn(t);return e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-[11px] text-ink flex-shrink-0",role:"alert","data-conflict-strip":"",children:[e(_,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"font-medium",children:[e("span",{className:"font-mono",children:r})," changed on disk",p?e("span",{className:"text-ink/60",children:[" at ",p]}):null,"."]}),e("div",{className:"text-ink/60 mt-0.5",children:"Your save was refused so nothing was overwritten."})]}),e("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e("button",{type:"button",onClick:l,className:"px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer",title:"Discard my changes and take the file from disk",children:"Reload"}),e("button",{type:"button",onClick:c,className:"px-2 py-1 rounded border border-warning/50 text-warning hover:bg-warning/10 transition-colors cursor-pointer",title:"Write my buffer over the file on disk",children:"Keep mine"})]})]})}function at(t){if(t.byteViewer)return[];return[{id:"save",pinned:!0,actions:[{label:"Save file",icon:Ce,onSelect:t.onSave,disabled:t.saveDisabled}],children:t.saveButton},{id:"save-as",actions:[{label:"Save as…",icon:Ce,onSelect:t.onSaveAs}],children:e("button",{type:"button",onClick:t.onSaveAs,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Save the buffer to a new file","aria-label":"Save as",children:e(Ce,{size:14})})}]}function st(t){if(!t.hasReview)return[];let r=t.isReviewing?"Exit review mode":"Review this document";return[{id:"review",actions:[{label:r,icon:mn,onSelect:t.onToggleReview,active:t.isReviewing}],children:e(ws,{label:r,pressed:t.isReviewing,title:t.isReviewing?"Review mode is on — click a block to judge it":"Review: click blocks to mark them good or needing work",onClick:t.onToggleReview,children:e(mn,{size:14})})}]}function lt(t){if(!t.hasPreview)return[];return[{id:"preview",actions:[{label:t.previewLabel,icon:t.isPreview?Tt:We,onSelect:t.onTogglePreview,active:t.isPreview}],children:e(ws,{label:t.previewLabel,pressed:t.isPreview,onClick:t.onTogglePreview,children:t.isPreview?e(Tt,{size:14}):e(We,{size:14})})}]}function dt(t){let r=[];if(r.push(...at(t),...st(t),...lt(t)),!t.byteViewer)r.push({id:"find",actions:[{label:t.findLabel,icon:U,onSelect:t.onToggleFind,active:t.findOpen}],children:e(ws,{label:t.findLabel,pressed:t.findOpen,title:`${t.findLabel} (Ctrl+F)`,onClick:t.onToggleFind,children:e(U,{size:14})})}),r.push({id:"wrap",actions:[{label:t.wordWrapLabel,icon:rn,onSelect:t.onToggleWordWrap,active:t.wordWrap}],children:e(ws,{label:t.wordWrapLabel,pressed:t.wordWrap,onClick:t.onToggleWordWrap,children:e(rn,{size:14})})}),r.push({id:"blame",actions:[{label:t.blameInline?"Hide line blame":"Show line blame",icon:De,onSelect:t.onToggleBlameInline,active:t.blameInline}],children:e(ws,{label:t.blameInline?"Hide line blame":"Show line blame",pressed:t.blameInline,title:"Who last changed each block, from git (hover a line for the commit)",onClick:t.onToggleBlameInline,children:e(De,{size:14})})}),r.push({id:"zoom",actions:[{label:"Decrease font size",icon:Fa,onSelect:t.onZoomOut},{label:"Increase font size",icon:Ra,onSelect:t.onZoomIn}],children:e(d,{children:[e("button",{type:"button",onClick:t.onZoomOut,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Decrease font size","aria-label":"Decrease font size",children:e(Fa,{size:14})}),e("button",{type:"button",onClick:t.onZoomIn,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Increase font size","aria-label":"Increase font size",children:e(Ra,{size:14})})]})}),r.push({id:"reload",actions:[{label:"Reload from disk",icon:D,onSelect:t.onReload,disabled:!t.canReload}],children:e("button",{type:"button",onClick:t.onReload,disabled:!t.canReload||t.refreshing,"aria-busy":t.refreshing,className:`${or} hover:bg-ink/5 hover:text-ink`,title:!t.canReload?"Nothing to reload — this tab has no file on disk":t.reloadDiscardsEdits?"Discard my changes and reload from disk":"Reload from disk","aria-label":"Reload from disk",children:e(D,{size:14,className:t.refreshing?"animate-spin":void 0})})});return r.push({id:"copy",actions:[{label:t.copyLabel,icon:re,onSelect:t.onCopy},{label:"Download file",icon:fe,onSelect:t.onDownload}],children:e(d,{children:[e("button",{type:"button",onClick:t.onCopy,className:`${or} hover:bg-ink/5 hover:text-ink`,title:t.copyLabel,"aria-label":t.copyLabel,children:t.copied?e(re,{size:14,className:"text-success"}):e(re,{size:14})}),e("button",{type:"button",onClick:t.onDownload,className:`${or} hover:bg-ink/5 hover:text-ink`,title:"Download file","aria-label":"Download file",children:e(fe,{size:14})})]})}),r.push({id:"view-modes",pinned:!0,actions:t.viewModeActions,children:t.viewModeButtons}),r.push({id:"maximize",pinned:!0,actions:[{label:t.maximizeLabel,icon:t.isMaximized?Se:ke,onSelect:t.onToggleMaximize,active:t.isMaximized}],children:t.maximizeButton}),r}function ut({path:t,saveStatus:r,wordWrap:l,hasPreview:c,isPreview:p,hasReview:g,isReviewing:v,copied:h,byteViewer:y=!1,saveDisabled:w=!1,unsupported:x=!1,handleMissing:k=!1,readOnly:O=!1,isMaximized:C=!1,findOpen:M=!1,onToggleFind:A,onSave:F,onTogglePreview:z,onToggleReview:I,onToggleWordWrap:W,onZoomIn:R,onZoomOut:L,onCopy:G,onDownload:X,onReload:Y,canReload:N,refreshing:P=!1,reloadDiscardsEdits:H,onSaveAs:J,onToggleMaximize:Q}){let te=w?O?"Read-only — this file was opened from the phone, not from a workspace":k?"Cannot save — reopen the file from the system to restore write access":x?"Nothing to save — this file cannot be opened as a document":"Nothing to save — this file could not be read":r==="needs-permission"?"Click Save to allow writing this file":r==="saving"?"Saving…":r==="error"?"Save failed — the file on disk was not changed":"Save file (Ctrl+S)",ie=e("button",{type:"button",onClick:F,disabled:w||r==="saving",className:`${or} hover:bg-ink/5`,title:te,"aria-label":te,children:r==="saving"?e(mt,{size:14,className:"text-warning animate-pulse"}):r==="saved"?e(f,{size:14,className:"text-success"}):r==="error"?e(E,{size:14,className:"text-error"}):r==="needs-permission"?e(mt,{size:14,className:"text-warning"}):e(mt,{size:14,className:"hover:text-ink"})}),le=C?"Exit full screen":"Full screen",ee=e("button",{type:"button",onClick:Q,className:`${or} hover:bg-ink/5 hover:text-ink ${C?"text-ink":""}`,title:le,"aria-label":le,"aria-pressed":C,children:C?e(Se,{size:14}):e(ke,{size:14})}),ne=Od(),de=_d(),ce=dt({byteViewer:y,hasPreview:c,isPreview:p,wordWrap:l,hasReview:g,isReviewing:v,blameInline:ne.inline,findOpen:M,copied:h,isMaximized:C,saveDisabled:w,canReload:N,refreshing:P,reloadDiscardsEdits:H,saveButton:ie,maximizeButton:ee,viewModeButtons:e(Sd,{size:14}),viewModeActions:de,previewLabel:p?"Show source":"Show preview",findLabel:"Find and replace",wordWrapLabel:l?"Word wrap on":"Word wrap off",copyLabel:h?"Copied":y?"Copy image":"Copy content",maximizeLabel:le,onTogglePreview:z,onToggleReview:I,onToggleFind:A,onToggleWordWrap:W,onToggleBlameInline:()=>{let he={...Ei(),inline:!ne.inline};hr({editorBlameInline:he.inline}),window.dispatchEvent(new CustomEvent(Is,{detail:he}))},onZoomIn:R,onZoomOut:L,onCopy:G,onDownload:X,onReload:Y,onSaveAs:J,onToggleMaximize:Q,onSave:F});return e("div",{className:"@container flex items-center justify-between gap-2 px-3 py-2 border-b border-ink/10 bg-paper flex-shrink-0",children:[e("div",{className:"hidden @[420px]:flex items-center space-x-2 text-xs font-mono text-ink/40 min-w-0",children:e("span",{className:"truncate max-w-[300px]",title:t,children:t})}),e(Wo,{clusters:ce,className:"text-ink/40 ml-auto"})]})}function pt({content:t,file:r,zoomLevel:l,reviewActive:c,onExitReview:p,scrollRef:g,onScroll:v}){return e("div",{ref:g,onScroll:v,"data-testid":"editor-scroller",className:"flex-1 overflow-auto bg-paper flex",children:e("div",{className:"p-6 max-w-4xl mx-auto font-sans flex-1",style:{fontSize:`${l}px`},children:e(Zc,{content:t,file:r,active:c,onExit:p})})})}function En(t,r){return r?`Spaces: ${t}`:"Tabs"}function ft({caret:t,eol:r,onSetEol:l,indentWidth:c,insertSpaces:p,language:g,byteViewer:v,viewerKind:h,lineCount:y,conflicts:w=0}){return e("footer",{className:"flex bg-canvas border-t border-ink/10 px-3 items-center justify-between text-[10px] text-ink/50 flex-shrink-0 font-mono h-6","data-editor-status-bar":"",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:v?e("span",{className:"uppercase",children:Go[h]}):e(d,{children:[e("span",{className:"tabular-nums",children:t?`Ln ${t.line}, Col ${t.column}`:"Ln —, Col —"}),e("span",{children:En(c,p)}),e("button",{type:"button",onClick:()=>l(r==="lf"?"crlf":"lf"),className:"uppercase hover:text-ink transition-colors cursor-pointer",title:`Line endings: ${r.toUpperCase()} — click to switch`,"aria-label":`Line endings ${r.toUpperCase()}, switch`,children:r}),e("span",{children:[y," lines"]})]})}),e("div",{className:"flex items-center gap-3 min-w-0",children:[w>0&&e("span",{className:"text-error font-semibold tabular-nums",title:`${w} unresolved conflict${w===1?"":"s"} — markers are highlighted in the file`,children:["⚠ ",w," conflict",w===1?"":"s"]}),e("span",{className:"uppercase text-ink/40",children:g})]})]})}function Tn(t){if(t===0)return 0;return Math.max(-1,Math.min(1,-Math.sign(t)))}function Mn(t,r,l=cl,c=ul){return Math.max(l,Math.min(c,t+r))}function Nn(t,r){let l=t instanceof HTMLElement?t:null;while(l&&l!==r){let c=getComputedStyle(l);if(/(auto|scroll)/.test(c.overflowY)&&l.scrollHeight>l.clientHeight)return!0;l=l.parentElement}return!1}function bt(t,r){o(()=>{if(!t)return;let l=t.closest("[data-code-surface]"),c=l instanceof HTMLElement?l:t,p=(g)=>{if(!g.ctrlKey&&!g.metaKey)return;if(g.preventDefault(),Nn(g.target,c))return;let v=Tn(g.deltaY);if(v===0)return;r((h)=>Mn(h,v))};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[t,r])}function ht(t,r){let l=t.trim();if(!/^\d+$/.test(l))return null;let c=Number(l);if(c<1)return null;return Math.min(c,Math.max(r,1))}function gt({lineCount:t,onGo:r,onClose:l}){let[c,p]=n(""),g=i(null);o(()=>{g.current?.focus(),g.current?.select()},[]);let v=()=>{let w=ht(c,t);if(w===null)return;r(w)},h=(w)=>{if(w.key==="Enter"){w.preventDefault(),v();return}if(w.key==="Escape")w.preventDefault(),l()},y=ht(c,t);return e(Z,{onClose:l,maxWidthClass:"max-w-xs",header:e("span",{className:"text-sm font-semibold text-ink",children:"Go to line"}),children:e("div",{className:"px-4 py-3 space-y-2",children:[e("div",{className:"flex items-center gap-2",children:[e("input",{ref:g,value:c,onInput:(w)=>p(w.target.value),onKeyDown:h,inputMode:"numeric",placeholder:"1","aria-label":"Line number",className:"flex-1 bg-paper border border-ink/20 rounded px-2 py-1 text-xs font-mono text-ink outline-none focus:border-ink/40"}),e("span",{className:"text-[10px] font-mono text-ink/40",children:["/ ",t]}),e("button",{type:"button",onClick:v,disabled:y===null,className:"flex items-center gap-1 px-2 py-1 rounded bg-ink text-paper text-xs disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[e(Xe,{size:12}),"Go"]})]}),c&&y!==null&&String(y)!==c.trim()?e("div",{className:"text-[10px] text-ink/50 font-mono",children:["line ",y," (the last line)"]}):null,c&&y===null?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a line number"}):null]})})}var vt={status:"idle",payload:null,message:null};function yt(t){if(!t?.path)return"";return`${t.root??""}\x00${t.repo??""}\x00${t.path}`}function xt(t,r={}){let l=r.enabled!==!1&&Boolean(t?.path)&&t?.deviceFile!==!0,c=r.dirty===!0,p=yt(t),[g,v]=n({key:"",value:vt}),h=i(t);h.current=t;let y=i(p);y.current=p;let w=i(l);w.current=l;let x=i(c);x.current=c;let k=i(g);k.current=g;let O=i(0),C=i(""),M=i(new Map),A=i(new Set),F=a(async()=>{let L=h.current;if(!L?.path)return;let G=yt(L),X=++O.current;C.current=G,v((N)=>({key:G,value:{status:"loading",payload:N.key===G?N.value.payload:null,message:null}}));let Y=new URLSearchParams({blame:"1",file:L.path,repo:L.repo||"."});if(L.root)Y.set("root",L.root);try{let N=await fetch(`/api/fs/git?${Y.toString()}`),P=await N.json().catch(()=>null);if(X!==O.current)return;if(!N.ok||!P){v({key:G,value:{status:"error",payload:null,message:P?.error??`Blame request failed (HTTP ${N.status})`}});return}v({key:G,value:P.available?{status:"ready",payload:P,message:null}:{status:"unavailable",payload:P,message:P.message??null}})}catch(N){if(X!==O.current)return;v({key:G,value:{status:"error",payload:null,message:N instanceof Error?N.message:"Blame failed"}})}finally{if(C.current===G)C.current=""}},[]),z=a(async(L)=>{let G=M.current.get(L);if(G)return G;let X=h.current;if(!X?.path)return{entries:[],truncated:!1};let Y=new URLSearchParams({blameHistory:"1",file:X.path,line:String(L),repo:X.repo||"."});if(X.root)Y.set("root",X.root);try{let P=await(await fetch(`/api/fs/git?${Y.toString()}`)).json().catch(()=>null),H={entries:Array.isArray(P?.entries)?P.entries:[],truncated:P?.truncated===!0};return M.current.set(L,H),H}catch{return{entries:[],truncated:!1}}},[]),I=i(null);if(!I.current)I.current={ensure:()=>{if(!w.current||x.current)return;let L=k.current;if(L.key===y.current&&L.value.status!=="idle")return;if(C.current===y.current)return;F()},reload:()=>{M.current.clear(),F()},history:z,snapshot:()=>{let L=k.current;return L.key===y.current?L.value:vt},stale:()=>x.current,subscribe:(L)=>(A.current.add(L),()=>{A.current.delete(L)})};o(()=>{if(!l||c||!p)return;M.current.clear(),F()},[l,c,p,F]);let W=i(c);return o(()=>{if(W.current===c)return;W.current=c;for(let L of A.current)L()},[c]),o(()=>{for(let L of A.current)L()},[g]),I.current}var Rn="0".repeat(40);function Me(t){return t===Rn}function ye(t,r=Date.now()){let l=Math.max(0,Math.floor(r/1000)-t);if(l<60)return"just now";let c=Math.floor(l/60);if(c<60)return`${c}m ago`;let p=Math.floor(c/60);if(p<24)return`${p}h ago`;let g=Math.floor(p/24);if(g<30)return`${g}d ago`;let v=Math.floor(g/30);if(v<12)return`${v}mo ago`;return`${Math.floor(g/365)}y ago`}function wt(t,r){switch(t){case"not-repo":return"This folder is not a git repository.";case"no-commit":return"This repository has no commits yet.";case"untracked":return"This file has never been committed, so it has no history.";case"too-large":return r??"This file is too large to blame.";case"empty":return"This file is empty.";default:return r??"git could not read this file."}}var Et="fixed z-50 w-[min(340px,92vw)] rounded-xl border border-ink/20 bg-paper p-3 shadow-xl font-sans text-xs text-ink",kt="flex items-baseline justify-between gap-2",St="truncate text-xs font-semibold text-ink",Pn="shrink-0 font-mono text-[10px] text-ink/40",Ln="mt-1 line-clamp-2 text-[11px] leading-snug text-ink/80",Bn="mt-2 border-t border-ink/10 pt-2",Dn="flex items-center gap-2 font-mono text-[10px] text-ink/40",Ct="mt-1 text-[10px] leading-snug text-ink/50",On="mt-2 flex w-full items-center gap-1.5 text-left text-[10px] text-ink/50 hover:text-ink cursor-pointer",An="mt-1.5 space-y-1 border-t border-ink/10 pt-1.5",Ne="flex items-center gap-1.5 font-mono text-[10px]";function q(t,r,l){let c=document.createElement(t);if(c.className=r,l!==void 0)c.textContent=l;return c}function In(t){return new Date(t*1000).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Fn(t){let r=t.payload;if(t.status==="error")return{title:"Blame failed",body:t.message??"git could not read this file."};if(t.status==="unavailable")return{title:r?.reason==="untracked"?"Not tracked":"No history",body:wt(r?.reason??"error",t.message??void 0)};if(!r)return null;if(t.stale)return{title:"Not committed yet",body:"This line changed in the editor. Save the file to see its blame."};if(t.line>r.lines)return{title:"Not committed yet",body:`Line ${t.line} is past the end of the file at HEAD (${r.lines} lines).`};let l=r.runs.length>0?Mt(r,t.line):null;if(!l)return{title:"Not committed yet",body:`git has no attribution for line ${t.line}.`};if(Me(l.sha))return{title:"Not committed yet",body:"This line differs from the last commit."};return null}function Mt(t,r){for(let l of t.runs)if(r>=l.from&&r<=l.to)return t.commits[l.sha]??null;return null}function zn(t,r){t.replaceChildren(),t.className=Et;let l=Fn(r);if(l){let w=q("div",kt);if(w.append(q("span",St,l.title)),r.status==="error"&&r.message){let x=q("button","shrink-0 cursor-pointer text-[10px] text-ink/50 hover:text-ink","Try again");x.type="button",x.setAttribute("aria-label","Read the blame again"),w.append(x)}t.append(w,q("p",Ct,l.body));return}let c=r.payload;if(!c){t.append(q("p",Ct,"Reading blame…"));return}let p=Mt(c,r.line),g=q("div",kt);if(g.append(q("span",St,p.author.trim()||"Unknown"),q("span",Pn,ye(p.time))),t.append(g),p.summary)t.append(q("p",Ln,p.summary));let v=q("div",`${Dn} ${Bn}`);if(v.append(q("code","truncate",p.sha.slice(0,7)),q("span","",In(p.time))),p.mail){let w=q("span","truncate",p.mail);w.title=p.mail,v.append(w)}t.append(v);let h=q("button",On);if(h.type="button",h.setAttribute("aria-expanded",r.historyOpen?"true":"false"),h.textContent=`${r.historyOpen?"▾":"▸"} Line history`,t.append(h),!r.historyOpen)return;let y=q("ol",An);if(r.historyLoading)y.append(q("li",`${Ne} text-ink/40`,"Reading history…"));else if(!r.history||r.history.entries.length===0)y.append(q("li",`${Ne} text-ink/40`,"No commits touched this line."));else{let w=r.history.entries;if(w.forEach((x,k)=>{let O=q("li",Ne),C=k===w.length-1?"new":"edit";O.append(q("span","text-ink/40",k===0?"●":"○"),q("code","text-ink/60",x.sha.slice(0,7)),q("span","truncate text-ink/80",x.author.trim()||"Unknown"),q("span","ml-auto shrink-0 text-ink/40",ye(x.time)),q("span","shrink-0 rounded bg-ink/5 px-1 text-[8.5px] uppercase tracking-wider text-ink/45",C)),y.append(O)}),r.history.truncated)y.append(q("li",`${Ne} text-ink/40`,"Older commits are not shown."))}t.append(y)}function Nt(t,r,l){let c=q("div",Et);c.setAttribute("role","dialog"),c.setAttribute("aria-label","Line blame"),c.addEventListener("mousedown",(x)=>x.stopPropagation());let p=null,g=!1,v=!1,h=()=>{let x=r.snapshot();return{line:t,status:x.status,payload:x.payload,message:x.message,stale:r.stale(),history:p,historyOpen:g,historyLoading:v}},y=()=>{zn(c,h());let x=c.querySelector('[aria-label="Read the blame again"]');if(x)x.addEventListener("click",(k)=>{k.stopPropagation(),l()});c.querySelector("button[aria-expanded]")?.addEventListener("click",(k)=>{if(k.stopPropagation(),g=!g,y(),!g||p||v)return;v=!0,y(),r.history(t).then((O)=>{p=O,v=!1,y()})})};y();let w=r.subscribe(y);return{element:c,place(x){let k=c.ownerDocument.defaultView,O=k?.innerWidth??1024,C=k?.innerHeight??768,M=c.offsetWidth||340,A=c.offsetHeight||120,F=8,z=Math.max(8,Math.min(x.left,O-M-8)),I=x.bottom+6,W=x.top-A-6,R=I+A>C-8&&W>8?W:I;c.style.left=`${z}px`,c.style.top=`${Math.max(8,R)}px`},destroy(){w(),c.remove()}}}function Rt(t){return ve.define((r)=>{let l=null,c=0,p,g=()=>{clearTimeout(p),p=void 0,l?.destroy(),l=null,c=0},v=(C,M)=>{let A=C.getBoundingClientRect();if(A.width>0)return{left:A.left,top:A.top,bottom:A.bottom};let F=r.state.doc.line(Math.min(M,r.state.doc.lines)),z=null;try{z=r.coordsAtPos(F.from)}catch{z=null}if(z)return z;let I=r.scrollDOM.getBoundingClientRect();return{left:I.left,top:I.top+24,bottom:I.top+24}},h=(C,M)=>{if(c===C&&l)return;g(),c=C,l=Nt(C,t,()=>{t.reload(),g()}),document.body.append(l.element),l.place(M)},y=(C)=>{let M=C.target,A=M?.closest?.(".cm-blame-label");if(A){let I=Number(A.dataset.blameLine);return Number.isInteger(I)&&I>0?{line:I,anchor:A}:null}let F=M?.closest?.(".cm-lineNumbers .cm-gutterElement");if(!F)return null;let z=Number((F.textContent??"").trim());return Number.isInteger(z)&&z>0?{line:z,anchor:F}:null},w=(C)=>{let M=y(C);if(!M)return;h(M.line,v(M.anchor,M.line))},x=(C)=>{let M=y(C);if(M){C.preventDefault(),h(M.line,v(M.anchor,M.line));return}if(l&&!l.element.contains(C.target))g()},k=(C)=>{if(C.key==="Escape"&&l)g(),C.stopPropagation()},O=(C)=>{if(!l)return;let M=C.relatedTarget;if(M&&(l.element.contains(M)||r.scrollDOM.contains(M)))return;p=setTimeout(g,200)};return r.scrollDOM.addEventListener("mouseover",w),r.scrollDOM.addEventListener("mouseleave",O),r.scrollDOM.addEventListener("mousedown",x),document.addEventListener("mousedown",x),document.addEventListener("keydown",k,!0),{update(C){if(C.docChanged&&l)g()},destroy(){g(),r.scrollDOM.removeEventListener("mouseover",w),r.scrollDOM.removeEventListener("mouseleave",O),r.scrollDOM.removeEventListener("mousedown",x),document.removeEventListener("mousedown",x),document.removeEventListener("keydown",k,!0)}}})}var Pt=40,Bt=ae.define();function Hn(t){return Le.define({create:()=>({payload:t.snapshot().payload,stale:!1}),update(r,l){let c=r;for(let p of l.effects){if(!p.is(Bt))continue;c=p.value.payload!==r.payload?{payload:p.value.payload,stale:!1}:{payload:r.payload,stale:r.stale}}if(l.docChanged&&!c.stale)c={payload:c.payload,stale:!0};return c}})}function $n(t,r,l){let c=t.commits[r];if(!c||Me(r))return null;let p=c.author.trim()||"Unknown";return l?p:`${p} · ${ye(c.time)}`}class Dt extends Zt{constructor(t,r,l){super();this.line=t;this.text=r;this.title=l}eq(t){return t.line===this.line&&t.text===this.text&&t.title===this.title}toDOM(){let t=document.createElement("span");return t.className="cm-blame-label",t.dataset.blameLine=String(this.line),t.title=this.title,t.textContent=this.text,t}}function Lt(t,r,l){let{payload:c,stale:p}=t;if(!c?.available||p)return T.none;let g=Math.min(c.lines,r.state.doc.lines);if(g<1)return T.none;let v=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.from,r.state.doc.length))).number,h=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.to,r.state.doc.length))).number,y=Math.max(1,v-Pt),w=Math.min(g,h+Pt),x=[];for(let k of c.runs){let O=Math.max(k.from,y);if(O>k.to||O>w)continue;let C=$n(c,k.sha,l);if(!C)continue;let M=c.commits[k.sha],A=r.state.doc.line(O);x.push({from:A.to,deco:T.widget({widget:new Dt(A.number,C,M.summary||M.sha),side:1})})}return T.set(x.map((k)=>k.deco.range(k.from)),!0)}function Vn(t,r){return ve.fromClass(class{constructor(l){this.view=l;this.decorations=Lt(l.state.field(t),l,r)}update(l){if(l.startState.field(t)===l.state.field(t)&&!l.docChanged&&!l.viewportChanged)return;this.decorations=Lt(l.state.field(t),l.view,r)}},{decorations:(l)=>l.decorations})}function Wn(t){return ve.define((r)=>{let l=!0,c=()=>{if(!l)return;let g=t.snapshot();r.dispatch({effects:Bt.of({payload:g.payload,stale:!1})})},p=t.subscribe(c);return{destroy(){l=!1,p()}}})}function Ot({controller:t,inline:r=!0,compact:l=!1}){let c=Hn(t);return[c,Wn(t),r?Vn(c,l):[],Rt(t)]}function At({activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:p,rootPath:g=null,repoPath:v=null,onRunCommand:h,wordWrap:y,zoomLevel:w,setZoomLevel:x,editorFontFamily:k,editorTheme:O,viewerKind:C,isPreview:M,reviewActive:A,onToggleReview:F,revealActive:z}){let I=C==="markdown",W=Au(),R=bu(),L=Od(),G=xt({name:t.name,path:t.path,root:t.root??g??void 0,repo:t.repo??v??"."},{enabled:L.enabled,dirty:r.isDirty}),X=u(()=>L.enabled?Ot({controller:G,inline:L.inline}):null,[L.enabled,L.inline,G]),[Y,N]=n(null),P=u(()=>Xc(r.content),[r.content]),[H,J]=n(!1);o(()=>{if(p>0)J(!0)},[p]);let[Q,te]=n(null),[ie,le]=n(null);bt(Q,x);let ee=kl({tabKey:String(t.id),surface:I&&M?"rendered":"code",ready:r.loaded,element:I&&M?void 0:Q}),ne=a((de)=>{ee.ref(de),le(de)},[ee.ref]);return nu({path:t.path,scroller:ie,preview:I&&M}),e("div",{className:"relative flex-1 min-h-0 flex flex-col",children:[l.open?e(tu,{find:l}):null,H?e(gt,{lineCount:r.content?r.content.split(`
2
2
  `).length:1,onGo:(de)=>{J(!1);let ce=br(r.content,de-1);c.current?.select(ce,ce,!0),c.current?.revealOffset(ce)},onClose:()=>J(!1)}):null,I&&M?e(pt,{content:r.content,file:{name:t.name,path:t.path,root:t.root,repo:t.repo},zoomLevel:w,reviewActive:A,onExitReview:F,scrollRef:ne,onScroll:ee.onScroll}):e(eu,{ref:c,value:r.content,onValueChange:r.onChange,language:r.language,wordWrap:y,documentKey:String(t.id),marks:l.open||z?l.matches:void 0,currentMark:l.currentIndex,onCommand:h,onScroller:te,onCaret:N,scrollTestId:"editor-scroller",className:"flex-1 min-h-0 text-ink select-text",blame:X,themeVars:O.vars,themes:O.themes,indentUnitText:gu(W),typing:R,padding:16,placeholder:"This file is empty",style:{fontFamily:k,fontSize:`${w}px`,lineHeight:ll}}),!I||!M?e(ft,{caret:Y,eol:r.eol,onSetEol:r.setEol,indentWidth:W.width,insertSpaces:W.insertSpaces,language:r.language,byteViewer:r.isBinaryViewer,viewerKind:C,lineCount:r.content?r.content.split(`
3
- `).length:0,conflicts:P}):null]})}function It({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z=null,repoPath:I=null,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y}){let N=h==="image"||h==="pdf"||h==="docx"||h==="spreadsheet",P=Cs[h]===!0,H=a(async(J)=>{let Q=await iu(t,J,{interactive:!0,baseMtimeMs:r.baseMtimeMs});if(Q.status==="written")return{ok:!0};if(Q.status==="conflict")return{ok:!1,error:"This file changed on disk since it was opened."};if(Q.status==="needs-permission")return{ok:!1,error:"Click Save again to grant write access."};return{ok:!1,error:Q.error}},[t,r.baseMtimeMs]);return e(d,{children:[e(ut,{path:t.path,saveStatus:r.saveStatus,wordWrap:g,hasPreview:P,isPreview:y,hasReview:h==="markdown"&&y,isReviewing:w,copied:r.copied,byteViewer:N,saveDisabled:Boolean(r.loadError)||r.handleMissing||r.deviceBacked,unsupported:Boolean(r.unsupported),handleMissing:r.handleMissing,readOnly:r.deviceBacked,isMaximized:k,findOpen:l.open,onToggleFind:()=>l.open?l.close():l.openFind(),onSave:r.saveNow,onTogglePreview:G,onToggleReview:x,onToggleWordWrap:()=>v(!g),onZoomIn:()=>M((J)=>Math.min(ul,J+1)),onZoomOut:()=>M((J)=>Math.max(cl,J-1)),onCopy:r.copy,onDownload:r.download,onReload:r.reloadFromDisk,onSaveAs:F,canReload:Tl(t)&&!r.loadError&&!r.unsupported,refreshing:r.isReading,reloadDiscardsEdits:r.isDirty,onToggleMaximize:()=>O(!k)}),Y&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-error/30 bg-error/10 text-error",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was deleted from disk."}),e("div",{className:"text-[11px] font-sans text-error/80",children:"The buffer is still here. Saving recreates the file — autosave is off until then."})]})]}),r.conflict&&e(Te,{diskMtimeMs:r.conflict.diskMtimeMs,fileName:t.name,onReload:r.resolveConflictByReload,onKeepMine:r.resolveConflictByKeepingMine}),r.handleMissing&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-warning",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was opened by the system, not from a workspace."}),e("div",{className:"text-[11px] font-sans text-warning/80",children:"Its write permission ended with the last page load. Reopen the file from the OS to edit it again."})]})]}),r.deviceBacked&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-ink/20 bg-ink/5 text-ink/70",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:r.deviceMissing?"The bytes for this file did not survive the reload.":"Opened from this device, so it is read-only here."}),e("div",{className:"text-[11px] font-sans text-ink/50",children:r.deviceMissing?"A phone's file lives only on the phone, so it cannot be re-read. Open it again from the app that shared it.":"The console cannot reach a file on your phone. Copy it into a workspace to edit it."})]})]}),r.isImage&&r.imageUrl?e(wi,{src:r.imageUrl,name:t.name,className:"flex-1 min-h-0"}):r.isImage?e(Sl,{kind:"image",path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision}):r.isLoading?e("div",{className:"flex-1 flex items-center justify-center gap-2 text-ink/40 text-xs font-mono",children:[e(m,{size:14,className:"animate-spin"}),e("span",{children:"Loading file content…"})]}):r.unsupported?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(Yc,{size:20,className:"text-ink/40"}),e("span",{className:"text-xs text-ink/70 font-sans",children:[t.name," cannot be opened here"]}),e("span",{className:"text-[11px] text-ink/50 font-sans max-w-[42ch]",children:r.unsupported})]}):r.loadError?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(_,{size:20,className:"text-error"}),e("span",{className:"text-xs text-error font-sans",children:["Could not read ",t.name]}),e("span",{className:"text-[11px] text-ink/50 font-mono break-all",children:r.loadError})]}):p&&!r.isImage?e(Hg,{view:p}):au(h)&&(N||y)?e(Sl,{kind:h,path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision,onContentChange:r.onChange,onSaveBytes:r.deviceBacked?void 0:H,onDirtyChange:r.setBinaryDirty}):e(At,{activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:A,rootPath:z,repoPath:I,onRunCommand:W,wordWrap:g,zoomLevel:C,setZoomLevel:M,editorFontFamily:R,editorTheme:L,isPreview:y,reviewActive:w,onToggleReview:x,viewerKind:h,revealActive:X})]})}function Ft({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z=null,repoPath:I=null,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y,onConvertDiffToEditor:N,onFileSaved:P}){if(!t)return e("div",{className:"flex-1 flex items-center justify-center text-ink/40",children:e("p",{className:"font-mono text-sm",children:"Select a tab to view content"})});if(t.isDiff)return e(Jc,{filePath:t.path,status:t.diffStatus||"M",isStaged:Boolean(t.diffStaged),root:t.root,repo:t.repo||".",journalDiff:t.journalDiff,readOnly:t.diffSource==="journal",onOpenInEditor:()=>N(t.id),onFileSaved:P,className:"flex-1",tabKey:String(t.id)});return e(It,{activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z,repoPath:I,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y})}function zt({pluginId:t,Component:r,sessionId:l,className:c="",onHide:p}){return e("div",{className:`flex flex-col h-full bg-canvas ${c}`,children:[p&&e("div",{className:"flex justify-end flex-shrink-0 border-b border-ink/10",children:e(be,{onHide:p})}),e(et,{pluginId:t,children:e(r,{sessionId:l,workspacePath:null})})]})}function Ht({className:t="",onHide:r}){return e("div",{className:`relative flex flex-col h-full bg-canvas items-center justify-center text-muted ${t}`,children:[r&&e("div",{className:"absolute top-0 right-0 flex items-center",children:e(be,{onHide:r})}),e(ct,{name:"placeholder.txt",size:48,className:"mb-4 opacity-20"}),e("p",{className:"font-mono text-sm",children:"Select a file to open"})]})}function $t({searchReveal:t,revealMatch:r}){let l=i(r);l.current=r;let c=i(null);o(()=>{if(!t||c.current===t.request)return;c.current=t.request,l.current({query:t.request.query,options:t.request.options,line:t.request.line})},[t])}function Vt({openedFiles:t,dirtyKeys:r,activeFile:l,previewReady:c,setPreviewMode:p,sessionId:g}){o(()=>{let v=new Set(t.filter((h)=>!h.isDiff&&h.content===void 0).map((h)=>h.id));_e([...r].filter((h)=>v.has(h)))},[r,t]),o(()=>{if(!c)return;let v=l?.id;if(!l||v===void 0||v===null)return;if(!Cs[Es(l.name)])return;let h=Ee(g,"editor.previewMode");if(h&&h[v]!==void 0)return;p((y)=>y[v]===void 0?{...y,[v]:!0}:y)},[c,l])}function Wt({activeFile:t,externalChange:r,conflict:l,onReload:c,onKeepMine:p}){if(!t)return null;if(l)return e(Te,{diskMtimeMs:l.diskMtimeMs,fileName:t.name,onReload:c,onKeepMine:p});if(r)return e(du,{fileName:t.name,onReload:c,onKeepMine:p});return null}async function Kt(t){let r=t.name.trim();if(!r)return{status:"failed",reason:"Enter a file name."};let l=new FormData;if(l.append("actionType","saveAs"),l.append("path",t.parent),l.append("name",r),l.append("content",t.content),l.append("eol",t.eol),t.root)l.append("root",t.root);if(t.repo&&t.repo!==".")l.append("repo",t.repo);try{let c=await fetch("/api/fs/action",{method:"POST",body:l}),p=await c.json().catch(()=>null),g=typeof p?.error==="string"?p.error:null;if(c.status===409)return{status:"exists",reason:g??`${r} already exists.`};if(c.ok&&p?.success&&typeof p.path==="string")return{status:"written",path:p.path};return{status:"failed",reason:g??"The file could not be written."}}catch{return{status:"failed",reason:"The file could not be written."}}}function Ut(t){let r=t.lastIndexOf(".");if(r<=0)return`${t} copy`;return`${t.slice(0,r)} copy${t.slice(r)}`}function _t(t){let r=t.trim();if(!r)return!1;if(r==="."||r==="..")return!1;return!r.includes("/")&&!r.includes("\\")}function Kn(t){let r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function Gt({fileName:t,filePath:r,content:l,eol:c,root:p,repo:g,onSaved:v,onClose:h}){let[y,w]=n(()=>Kn(r)),[x,k]=n(()=>Ut(t)),[O,C]=n(!1),[M,A]=n(null),F=i(null);o(()=>{F.current?.focus(),F.current?.select()},[]);let z=_t(x),I=async()=>{if(!z||O)return;C(!0),A(null);let R=await Kt({parent:y,name:x,content:l,eol:c,root:p,repo:g});if(C(!1),R.status==="written"){v({path:R.path});return}A(R.reason)},W=(R)=>{if(R.key==="Enter"){R.preventDefault(),I();return}if(R.key==="Escape")R.preventDefault(),h()};return e(Z,{onClose:h,maxWidthClass:"max-w-md",header:e("span",{className:"text-sm font-semibold text-ink",children:"Save as"}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:h,className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>void I(),disabled:!z||O,className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-ink text-paper disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[O?e(m,{size:12,className:"animate-spin"}):e(Xe,{size:12}),"Save"]})]}),children:e("div",{className:"px-4 py-3 space-y-2 text-xs",children:[e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Folder"}),e("input",{value:y,onInput:(R)=>w(R.target.value),onKeyDown:W,placeholder:"(workspace root)","aria-label":"Destination folder",className:"w-full bg-paper border border-ink/20 rounded px-2 py-1 font-mono text-ink outline-none focus:border-ink/40"})]}),e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Name"}),e("input",{ref:F,value:x,onInput:(R)=>k(R.target.value),onKeyDown:W,"aria-label":"File name","aria-invalid":!z,className:`w-full bg-paper border rounded px-2 py-1 font-mono text-ink outline-none ${z?"border-ink/20 focus:border-ink/40":"border-error text-error"}`})]}),!z?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a file name without a path separator"}):null,M?e("div",{className:"text-[10px] text-error font-mono",children:M}):null,e("div",{className:"text-[10px] text-ink/40",children:"The original file stays where it is, and its tab stays open."})]})})}function qt(){o(()=>{let t=(r)=>{if(!Ze())return;r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[])}function Xt({fileName:t,onAnswer:r}){return e(Z,{onClose:()=>r("cancel"),header:e("div",{className:"flex items-center gap-2",children:[e(_,{size:15,className:"text-warning"}),e("span",{className:"text-sm font-semibold text-ink",children:"Unsaved changes"})]}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:()=>r("cancel"),className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>r("discard"),className:"px-3 py-1.5 rounded border border-error/40 text-error hover:bg-error/10 transition-colors cursor-pointer",children:"Discard"}),e("button",{type:"button",onClick:()=>r("save"),className:"px-3 py-1.5 rounded bg-ink text-paper hover:bg-ink/90 transition-colors cursor-pointer",children:"Save & close"})]}),children:e("div",{className:"px-4 py-3 text-xs text-ink/80",children:[e("span",{className:"font-mono text-ink",children:t})," has changes that are not on disk.",e("div",{className:"mt-1 text-ink/50",children:"Discarding them cannot be undone."})]})})}function Yt({closeGuard:t,activeFile:r,saveMissingConfirm:l,onCancelSaveMissing:c,onConfirmSaveMissing:p}){if(t.pending)return e(Xt,{fileName:t.pending.name,onAnswer:t.answer});if(l&&r)return e(pu,{fileName:r.name,filePath:r.path,onClose:c,onConfirm:p});return null}function jt({className:t="",isMaximized:r,onKeyDownCapture:l,onFocusCapture:c,asSplitPane:p,tabs:g,activeFile:v,editor:h,externalChange:y,conflict:w,onReload:x,onKeepMine:k,body:O,saveAsOpen:C,onSaveAsClose:M,onSavedAs:A,closeGuard:F}){let z=r?"fixed inset-0 z-50 flex flex-col bg-canvas":`flex flex-col h-full bg-canvas ${t}`;return e("div",{className:z,onKeyDownCapture:l,onFocusCapture:c,children:[p?null:g,e(Wt,{activeFile:v,externalChange:y,conflict:w,onReload:x,onKeepMine:k}),O,C&&v?e(Gt,{fileName:v.name,filePath:v.path,content:h.content,eol:h.eol,root:v.root,repo:v.repo,onSaved:({path:I})=>A(I),onClose:M}):null,e(Yt,{closeGuard:F,activeFile:v,saveMissingConfirm:h.saveMissingConfirm,onCancelSaveMissing:h.cancelSaveMissing,onConfirmSaveMissing:h.confirmSaveMissing})]})}function Jt({fileName:t,onClose:r,children:l}){return e("div",{className:"flex flex-col h-full min-w-0","data-split-pane":"",children:[e("div",{className:"flex items-center justify-between gap-2 px-3 py-1 border-b border-ink/10 bg-canvas flex-shrink-0",children:[e("span",{className:"text-[11px] font-mono text-ink/60 truncate",title:t,children:t}),e("button",{type:"button",onClick:r,className:"p-0.5 rounded hover:bg-ink/10 text-ink/50 hover:text-ink transition-colors cursor-pointer flex-shrink-0",title:"Close this pane (the tab stays open)","aria-label":"Close split pane",children:e(b,{size:12})})]}),e("div",{className:"flex-1 min-h-0",children:l})]})}function Qt({fraction:t,onFraction:r,rightPaneName:l,onClosePane:c,rightPane:p,children:g}){let v=i(null),h=i(null),y=Ym(h),w=(x)=>{let k=x.currentTarget,O=v.current;if(!k||!O)return;k.setPointerCapture(x.pointerId);let C=(A)=>{let F=O.getBoundingClientRect();if(F.width===0)return;r(pe((A.clientX-F.left)/F.width))},M=()=>{k.releasePointerCapture(x.pointerId),k.removeEventListener("pointermove",C),k.removeEventListener("pointerup",M)};k.addEventListener("pointermove",C),k.addEventListener("pointerup",M)};return e("div",{ref:v,className:"flex w-full h-full","data-split-column":"",children:[e("div",{className:"flex flex-col min-w-0 h-full",style:{width:`${Math.round(pe(t)*100)}%`},children:g}),e("div",{ref:h,className:`w-[3px] flex-shrink-0 cursor-col-resize transition-colors active:bg-ink/40 ${y?"bg-ink/40":"bg-ink/10"}`,role:"separator","aria-orientation":"vertical","aria-label":"Resize split panes",onPointerDown:w}),e("div",{className:"flex-1 min-w-0 h-full",children:e(Jt,{fileName:l,onClose:c,children:p})})]})}function en({openedFiles:t,activeFileId:r,enabled:l}){let[c,p]=S("editor.split",ge),g=t.map((k)=>k.id),v=tt(nt(c,g),r),h=l&&v.rightFileId!==null?t.find((k)=>k.id===v.rightFileId)??null:null,y=a((k)=>{if(k!==null&&!Ce(k,r,g))return;p({...v,rightFileId:k})},[v,p,r,g]),w=a(()=>p({...v,rightFileId:null}),[v,p]),x=a((k)=>p({...v,fraction:pe(k)}),[v,p]);return{rightFile:h,fraction:v.fraction,splitTo:y,close:w,setFraction:x}}function tn({find:t,runCommand:r,reopenClosed:l}){let c=i(t);c.current=t;let p=i(r);p.current=r;let g=i(l);return g.current=l,{onKeyDownCapture:a((h)=>{let y=c.current;if(h.key==="Escape"){if(!y.open)return;h.preventDefault(),h.stopPropagation(),y.close();return}if((h.metaKey||h.ctrlKey)&&h.shiftKey&&h.code==="KeyT"){if(g.current?.())h.preventDefault(),h.stopPropagation();return}let w=Ch(ki,h);if(!w||!Ef(w))return;h.preventDefault(),h.stopPropagation(),p.current(w)},[])}}function nn(t){let r=i(t);r.current=t;let l=i(null);if(!l.current)l.current={saveNow:()=>r.current.saveNow(),runCommand:(p)=>r.current.runCommand(p)};return o(()=>{let p=l.current;if(!p)return;return $g(p)},[]),{onFocusCapture:a(()=>{if(l.current)$g(l.current)},[])}}function on({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,saveNow:p}){let[g,v]=n(null);qt();let h=a((w)=>{let x=t.find((k)=>k.id===w);if(x&&qe(w)){v(x);return}c(w)},[t,c]),y=a((w)=>{let x=g;if(!x)return;if(w==="cancel"){v(null);return}if(w==="save"){if(x.id!==r)l(x.id);p()}v(null),c(x.id)},[g,r,l,p,c]);return{requestClose:h,pending:g,answer:y}}function an(){let[t,r]=n(0),[l,c]=n(!1),p=a(()=>r((g)=>g+1),[]);return{goToLineRequest:t,openGoToLine:p,saveAsOpen:l,setSaveAsOpen:c}}function Un({className:t="",openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:g,refreshKey:v=0,onFileSaved:h,onOpenPath:y,onReopenClosed:w,reopenableCount:x,onCopyPath:k,onRevealInFiles:O,rootPath:C=null,repoPath:M=null,activeEditorPanelKey:A=null,forcedActiveFileId:F=null,asSplitPane:z=!1,onHidePanel:I}){let W=z?F:l,R=r.find((V)=>V.id===W),[L,G,X]=S("editor.previewMode",{}),Y=mu(String(W??"")),[N,P]=S("editor.zoomLevel",So),[H,J]=n(!1),[Q,te]=S("editor.wordWrap",!0),ie=an(),{sessionId:le}=Oe(),ee=en({openedFiles:r,activeFileId:W,enabled:!z}),ne=i(null),de=Do(),ce=Ci(),he=ou(r,v),Ie=Boolean(R&&he.has(R.id)),j=su(R??null,{reportSaveError:!0,onFileSaved:h,missing:Ie}),sn=qg({path:R?.path??"",content:j.content,language:j.language}),ln=j.diskChange,Fe=on({openedFiles:r,activeFileId:W,onSelectFile:c,onCloseFile:p,saveNow:j.saveNow}),xe=lu({text:j.content,documentKey:`${R?.id??""}\x00${j.language}`,readSelection:()=>ne.current?.getSelection()??null,select:(V,me,Be=!0)=>ne.current?.select(V,me,Be),reveal:(V)=>ne.current?.revealOffset(V),applyDocument:(V,me,Be)=>ne.current?.applyDocument(V,me,Be),toggleWordWrap:()=>te((V)=>!V)}),ze=cu(R?.path??null,j.content,j.loaded&&!j.loadError);$t({searchReveal:ze,revealMatch:xe.revealMatch}),uu({file:R,editor:j,surfaceRef:ne,isPreview:R?L[R.id]===!0:!1,exitPreview:()=>{let V=R?.id;if(V===void 0||V===null)return;G((me)=>({...me,[V]:!1}))}}),o(()=>{if(v>0)j.reset()},[v]),o(()=>{j.retain(r.map((V)=>V.id)),Ge(r.map((V)=>V.id))},[r]),Vt({openedFiles:r,dirtyKeys:j.dirtyKeys,activeFile:R,previewReady:X,setPreviewMode:G,sessionId:le});let dn=()=>{if(!R)return;G((V)=>({...V,[R.id]:!V[R.id]}))},Re=(V)=>{if(Ef(V)){xe.runCommand(V);return}if(V==="toggleWordWrap"){te((me)=>!me);return}if(V==="goToLine"){ie.openGoToLine();return}ne.current?.runCommand(V)},cn=tn({find:xe,runCommand:Re,reopenClosed:w}),un=nn({saveNow:j.saveNow,runCommand:Re}),Pe=Mh(A);if(Pe)return e(zt,{pluginId:Pe.pluginId,Component:Pe.Component,sessionId:le,className:t,onHide:I});if(r.length===0)return e(Ht,{className:t,onHide:I});let pn=j.viewerKind,He=R?L[R.id]:!1,fn={activeFile:R,editor:j,find:xe,surfaceRef:ne,pluginFileView:sn,wordWrap:Q,setWordWrap:te,viewerKind:pn,isPreview:Boolean(He),isReviewing:Boolean(He)&&Y.active,onToggleReview:Y.toggle,isMaximized:H,setIsMaximized:J,zoomLevel:N,setZoomLevel:P,goToLineRequest:ie.goToLineRequest,onSaveAs:()=>ie.setSaveAsOpen(!0),onOpenPath:y,rootPath:C,repoPath:M,runCommand:Re,editorFontFamily:de,editorTheme:ce,togglePreview:dn,revealActive:Boolean(ze),missing:Ie,onConvertDiffToEditor:g,onFileSaved:h},bn=(V)=>({openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:g,refreshKey:v,onFileSaved:h,onOpenPath:y,rootPath:C,repoPath:M,forcedActiveFileId:V,asSplitPane:!0}),hn=e(it,{openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:Fe.requestClose,missingIds:he,onCopyPath:k,onRevealInFiles:O,onReopenClosed:w,reopenableCount:x,onSplitTo:ee.splitTo,onUnsplit:ee.close,splitRightFileId:ee.rightFile?.id??null,onHide:I}),$e=e(jt,{className:t,isMaximized:H,onKeyDownCapture:cn.onKeyDownCapture,onFocusCapture:un.onFocusCapture,asSplitPane:z,tabs:hn,activeFile:R,editor:j,externalChange:ln,conflict:j.conflict,onReload:j.resolveConflictByReload,onKeepMine:j.keepMineAgainstDisk,body:e(Ft,{...fn}),saveAsOpen:ie.saveAsOpen,onSaveAsClose:()=>ie.setSaveAsOpen(!1),onSavedAs:(V)=>{ie.setSaveAsOpen(!1),y?.(V)},closeGuard:Fe});if(!ee.rightFile)return $e;return e(Qt,{fraction:ee.fraction,onFraction:ee.setFraction,rightPaneName:ee.rightFile.name,onClosePane:ee.close,rightPane:e(Un,{...bn(ee.rightFile.id)}),children:$e})}export{Un as Editor};
3
+ `).length:0,conflicts:P}):null]})}function It({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z=null,repoPath:I=null,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y}){let N=h==="image"||h==="pdf"||h==="docx"||h==="spreadsheet",P=Cs[h]===!0,H=a(async(J)=>{let Q=await iu(t,J,{interactive:!0,baseMtimeMs:r.baseMtimeMs});if(Q.status==="written")return{ok:!0};if(Q.status==="conflict")return{ok:!1,error:"This file changed on disk since it was opened."};if(Q.status==="needs-permission")return{ok:!1,error:"Click Save again to grant write access."};return{ok:!1,error:Q.error}},[t,r.baseMtimeMs]);return e(d,{children:[e(ut,{path:t.path,saveStatus:r.saveStatus,wordWrap:g,hasPreview:P,isPreview:y,hasReview:h==="markdown"&&y,isReviewing:w,copied:r.copied,byteViewer:N,saveDisabled:Boolean(r.loadError)||r.handleMissing||r.deviceBacked,unsupported:Boolean(r.unsupported),handleMissing:r.handleMissing,readOnly:r.deviceBacked,isMaximized:k,findOpen:l.open,onToggleFind:()=>l.open?l.close():l.openFind(),onSave:r.saveNow,onTogglePreview:G,onToggleReview:x,onToggleWordWrap:()=>v(!g),onZoomIn:()=>M((J)=>Math.min(ul,J+1)),onZoomOut:()=>M((J)=>Math.max(cl,J-1)),onCopy:r.copy,onDownload:r.download,onReload:r.reloadFromDisk,onSaveAs:F,canReload:Tl(t)&&!r.loadError&&!r.unsupported,refreshing:r.isReading,reloadDiscardsEdits:r.isDirty,onToggleMaximize:()=>O(!k)}),Y&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-error/30 bg-error/10 text-error",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was deleted from disk."}),e("div",{className:"text-[11px] font-sans text-error/80",children:"The buffer is still here. Saving recreates the file — autosave is off until then."})]})]}),r.conflict&&e(Te,{diskMtimeMs:r.conflict.diskMtimeMs,fileName:t.name,onReload:r.resolveConflictByReload,onKeepMine:r.resolveConflictByKeepingMine}),r.handleMissing&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-warning",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was opened by the system, not from a workspace."}),e("div",{className:"text-[11px] font-sans text-warning/80",children:"Its write permission ended with the last page load. Reopen the file from the OS to edit it again."})]})]}),r.deviceBacked&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-ink/20 bg-ink/5 text-ink/70",children:[e(_,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:r.deviceMissing?"The bytes for this file did not survive the reload.":"Opened from this device, so it is read-only here."}),e("div",{className:"text-[11px] font-sans text-ink/50",children:r.deviceMissing?"A phone's file lives only on the phone, so it cannot be re-read. Open it again from the app that shared it.":"The console cannot reach a file on your phone. Copy it into a workspace to edit it."})]})]}),r.isImage&&r.imageUrl?e(wi,{src:r.imageUrl,name:t.name,className:"flex-1 min-h-0"}):r.isImage?e(Sl,{kind:"image",path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision}):r.isLoading?e("div",{className:"flex-1 flex items-center justify-center gap-2 text-ink/40 text-xs font-mono",children:[e(m,{size:14,className:"animate-spin"}),e("span",{children:"Loading file content…"})]}):r.unsupported?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(Yc,{size:20,className:"text-ink/40"}),e("span",{className:"text-xs text-ink/70 font-sans",children:[t.name," cannot be opened here"]}),e("span",{className:"text-[11px] text-ink/50 font-sans max-w-[42ch]",children:r.unsupported})]}):r.loadError?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(_,{size:20,className:"text-error"}),e("span",{className:"text-xs text-error font-sans",children:["Could not read ",t.name]}),e("span",{className:"text-[11px] text-ink/50 font-mono break-all",children:r.loadError})]}):p&&!r.isImage?e(Hg,{view:p}):au(h)&&(N||y)?e(Sl,{kind:h,path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision,onContentChange:r.onChange,onSaveBytes:r.deviceBacked?void 0:H,onDirtyChange:r.setBinaryDirty}):e(At,{activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:A,rootPath:z,repoPath:I,onRunCommand:W,wordWrap:g,zoomLevel:C,setZoomLevel:M,editorFontFamily:R,editorTheme:L,isPreview:y,reviewActive:w,onToggleReview:x,viewerKind:h,revealActive:X})]})}function Ft({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z=null,repoPath:I=null,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y,onConvertDiffToEditor:N,onFileSaved:P}){if(!t)return e("div",{className:"flex-1 flex items-center justify-center text-ink/40",children:e("p",{className:"font-mono text-sm",children:"Select a tab to view content"})});if(t.isDiff)return e(Jc,{filePath:t.path,status:t.diffStatus||"M",isStaged:Boolean(t.diffStaged),root:t.root,repo:t.repo||".",journalDiff:t.journalDiff,readOnly:t.diffSource==="journal",onOpenInEditor:()=>N(t.id),onFileSaved:P,className:"flex-1",tabKey:String(t.id)});return e(It,{activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:g,setWordWrap:v,viewerKind:h,isPreview:y,isReviewing:w,onToggleReview:x,isMaximized:k,setIsMaximized:O,zoomLevel:C,setZoomLevel:M,goToLineRequest:A,onSaveAs:F,rootPath:z,repoPath:I,runCommand:W,editorFontFamily:R,editorTheme:L,togglePreview:G,revealActive:X,missing:Y})}function zt({pluginId:t,Component:r,sessionId:l,className:c="",onHide:p}){return e("div",{className:`flex flex-col h-full bg-canvas ${c}`,children:[p&&e("div",{className:"flex justify-end flex-shrink-0 border-b border-ink/10",children:e(be,{onHide:p})}),e(et,{pluginId:t,children:e(r,{sessionId:l,workspacePath:null})})]})}function Ht({className:t="",onHide:r}){return e("div",{className:`relative flex flex-col h-full bg-canvas items-center justify-center text-muted ${t}`,children:[r&&e("div",{className:"absolute top-0 right-0 flex items-center",children:e(be,{onHide:r})}),e(ct,{name:"placeholder.txt",size:48,className:"mb-4 opacity-20"}),e("p",{className:"font-mono text-sm",children:"Select a file to open"})]})}function $t({searchReveal:t,revealMatch:r}){let l=i(r);l.current=r;let c=i(null);o(()=>{if(!t||c.current===t.request)return;c.current=t.request,l.current({query:t.request.query,options:t.request.options,line:t.request.line})},[t])}function Vt({openedFiles:t,dirtyKeys:r,activeFile:l,previewReady:c,setPreviewMode:p,sessionId:g}){o(()=>{let v=new Set(t.filter((h)=>!h.isDiff&&h.content===void 0).map((h)=>h.id));_e([...r].filter((h)=>v.has(h)))},[r,t]),o(()=>{if(!c)return;let v=l?.id;if(!l||v===void 0||v===null)return;if(!Cs[Es(l.name)])return;let h=xe(g,"editor.previewMode");if(h&&h[v]!==void 0)return;p((y)=>y[v]===void 0?{...y,[v]:!0}:y)},[c,l])}function Wt({activeFile:t,externalChange:r,conflict:l,onReload:c,onKeepMine:p}){if(!t)return null;if(l)return e(Te,{diskMtimeMs:l.diskMtimeMs,fileName:t.name,onReload:c,onKeepMine:p});if(r)return e(du,{fileName:t.name,onReload:c,onKeepMine:p});return null}async function Kt(t){let r=t.name.trim();if(!r)return{status:"failed",reason:"Enter a file name."};let l=new FormData;if(l.append("actionType","saveAs"),l.append("path",t.parent),l.append("name",r),l.append("content",t.content),l.append("eol",t.eol),t.root)l.append("root",t.root);if(t.repo&&t.repo!==".")l.append("repo",t.repo);try{let c=await fetch("/api/fs/action",{method:"POST",body:l}),p=await c.json().catch(()=>null),g=typeof p?.error==="string"?p.error:null;if(c.status===409)return{status:"exists",reason:g??`${r} already exists.`};if(c.ok&&p?.success&&typeof p.path==="string")return{status:"written",path:p.path};return{status:"failed",reason:g??"The file could not be written."}}catch{return{status:"failed",reason:"The file could not be written."}}}function Ut(t){let r=t.lastIndexOf(".");if(r<=0)return`${t} copy`;return`${t.slice(0,r)} copy${t.slice(r)}`}function _t(t){let r=t.trim();if(!r)return!1;if(r==="."||r==="..")return!1;return!r.includes("/")&&!r.includes("\\")}function Kn(t){let r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function Gt({fileName:t,filePath:r,content:l,eol:c,root:p,repo:g,onSaved:v,onClose:h}){let[y,w]=n(()=>Kn(r)),[x,k]=n(()=>Ut(t)),[O,C]=n(!1),[M,A]=n(null),F=i(null);o(()=>{F.current?.focus(),F.current?.select()},[]);let z=_t(x),I=async()=>{if(!z||O)return;C(!0),A(null);let R=await Kt({parent:y,name:x,content:l,eol:c,root:p,repo:g});if(C(!1),R.status==="written"){v({path:R.path});return}A(R.reason)},W=(R)=>{if(R.key==="Enter"){R.preventDefault(),I();return}if(R.key==="Escape")R.preventDefault(),h()};return e(Z,{onClose:h,maxWidthClass:"max-w-md",header:e("span",{className:"text-sm font-semibold text-ink",children:"Save as"}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:h,className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>void I(),disabled:!z||O,className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-ink text-paper disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[O?e(m,{size:12,className:"animate-spin"}):e(Xe,{size:12}),"Save"]})]}),children:e("div",{className:"px-4 py-3 space-y-2 text-xs",children:[e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Folder"}),e("input",{value:y,onInput:(R)=>w(R.target.value),onKeyDown:W,placeholder:"(workspace root)","aria-label":"Destination folder",className:"w-full bg-paper border border-ink/20 rounded px-2 py-1 font-mono text-ink outline-none focus:border-ink/40"})]}),e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Name"}),e("input",{ref:F,value:x,onInput:(R)=>k(R.target.value),onKeyDown:W,"aria-label":"File name","aria-invalid":!z,className:`w-full bg-paper border rounded px-2 py-1 font-mono text-ink outline-none ${z?"border-ink/20 focus:border-ink/40":"border-error text-error"}`})]}),!z?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a file name without a path separator"}):null,M?e("div",{className:"text-[10px] text-error font-mono",children:M}):null,e("div",{className:"text-[10px] text-ink/40",children:"The original file stays where it is, and its tab stays open."})]})})}function qt(){o(()=>{let t=(r)=>{if(!Ze())return;r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[])}function Xt({fileName:t,onAnswer:r}){return e(Z,{onClose:()=>r("cancel"),header:e("div",{className:"flex items-center gap-2",children:[e(_,{size:15,className:"text-warning"}),e("span",{className:"text-sm font-semibold text-ink",children:"Unsaved changes"})]}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:()=>r("cancel"),className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>r("discard"),className:"px-3 py-1.5 rounded border border-error/40 text-error hover:bg-error/10 transition-colors cursor-pointer",children:"Discard"}),e("button",{type:"button",onClick:()=>r("save"),className:"px-3 py-1.5 rounded bg-ink text-paper hover:bg-ink/90 transition-colors cursor-pointer",children:"Save & close"})]}),children:e("div",{className:"px-4 py-3 text-xs text-ink/80",children:[e("span",{className:"font-mono text-ink",children:t})," has changes that are not on disk.",e("div",{className:"mt-1 text-ink/50",children:"Discarding them cannot be undone."})]})})}function Yt({closeGuard:t,activeFile:r,saveMissingConfirm:l,onCancelSaveMissing:c,onConfirmSaveMissing:p}){if(t.pending)return e(Xt,{fileName:t.pending.name,onAnswer:t.answer});if(l&&r)return e(pu,{fileName:r.name,filePath:r.path,onClose:c,onConfirm:p});return null}function jt({className:t="",isMaximized:r,onKeyDownCapture:l,onFocusCapture:c,asSplitPane:p,tabs:g,activeFile:v,editor:h,externalChange:y,conflict:w,onReload:x,onKeepMine:k,body:O,saveAsOpen:C,onSaveAsClose:M,onSavedAs:A,closeGuard:F}){let z=r?"fixed inset-0 z-50 flex flex-col bg-canvas":`flex flex-col h-full bg-canvas ${t}`;return e("div",{className:z,onKeyDownCapture:l,onFocusCapture:c,children:[p?null:g,e(Wt,{activeFile:v,externalChange:y,conflict:w,onReload:x,onKeepMine:k}),O,C&&v?e(Gt,{fileName:v.name,filePath:v.path,content:h.content,eol:h.eol,root:v.root,repo:v.repo,onSaved:({path:I})=>A(I),onClose:M}):null,e(Yt,{closeGuard:F,activeFile:v,saveMissingConfirm:h.saveMissingConfirm,onCancelSaveMissing:h.cancelSaveMissing,onConfirmSaveMissing:h.confirmSaveMissing})]})}function Jt({fileName:t,onClose:r,children:l}){return e("div",{className:"flex flex-col h-full min-w-0","data-split-pane":"",children:[e("div",{className:"flex items-center justify-between gap-2 px-3 py-1 border-b border-ink/10 bg-canvas flex-shrink-0",children:[e("span",{className:"text-[11px] font-mono text-ink/60 truncate",title:t,children:t}),e("button",{type:"button",onClick:r,className:"p-0.5 rounded hover:bg-ink/10 text-ink/50 hover:text-ink transition-colors cursor-pointer flex-shrink-0",title:"Close this pane (the tab stays open)","aria-label":"Close split pane",children:e(b,{size:12})})]}),e("div",{className:"flex-1 min-h-0",children:l})]})}function Qt({fraction:t,onFraction:r,rightPaneName:l,onClosePane:c,rightPane:p,children:g}){let v=i(null),h=i(null),y=Ym(h),w=(x)=>{let k=x.currentTarget,O=v.current;if(!k||!O)return;k.setPointerCapture(x.pointerId);let C=(A)=>{let F=O.getBoundingClientRect();if(F.width===0)return;r(pe((A.clientX-F.left)/F.width))},M=()=>{k.releasePointerCapture(x.pointerId),k.removeEventListener("pointermove",C),k.removeEventListener("pointerup",M)};k.addEventListener("pointermove",C),k.addEventListener("pointerup",M)};return e("div",{ref:v,className:"flex w-full h-full","data-split-column":"",children:[e("div",{className:"flex flex-col min-w-0 h-full",style:{width:`${Math.round(pe(t)*100)}%`},children:g}),e("div",{ref:h,className:`w-[3px] flex-shrink-0 cursor-col-resize transition-colors active:bg-ink/40 ${y?"bg-ink/40":"bg-ink/10"}`,role:"separator","aria-orientation":"vertical","aria-label":"Resize split panes",onPointerDown:w}),e("div",{className:"flex-1 min-w-0 h-full",children:e(Jt,{fileName:l,onClose:c,children:p})})]})}function en({openedFiles:t,activeFileId:r,enabled:l}){let[c,p]=S("editor.split",ge),g=t.map((k)=>k.id),v=tt(nt(c,g),r),h=l&&v.rightFileId!==null?t.find((k)=>k.id===v.rightFileId)??null:null,y=a((k)=>{if(k!==null&&!Ee(k,r,g))return;p({...v,rightFileId:k})},[v,p,r,g]),w=a(()=>p({...v,rightFileId:null}),[v,p]),x=a((k)=>p({...v,fraction:pe(k)}),[v,p]);return{rightFile:h,fraction:v.fraction,splitTo:y,close:w,setFraction:x}}function tn({find:t,runCommand:r,reopenClosed:l}){let c=i(t);c.current=t;let p=i(r);p.current=r;let g=i(l);return g.current=l,{onKeyDownCapture:a((h)=>{let y=c.current;if(h.key==="Escape"){if(!y.open)return;h.preventDefault(),h.stopPropagation(),y.close();return}if((h.metaKey||h.ctrlKey)&&h.shiftKey&&h.code==="KeyT"){if(g.current?.())h.preventDefault(),h.stopPropagation();return}let w=Ch(ki,h);if(!w||!Ef(w))return;h.preventDefault(),h.stopPropagation(),p.current(w)},[])}}function nn(t){let r=i(t);r.current=t;let l=i(null);if(!l.current)l.current={saveNow:()=>r.current.saveNow(),runCommand:(p)=>r.current.runCommand(p)};return o(()=>{let p=l.current;if(!p)return;return $g(p)},[]),{onFocusCapture:a(()=>{if(l.current)$g(l.current)},[])}}function on({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,saveNow:p}){let[g,v]=n(null);qt();let h=a((w)=>{let x=t.find((k)=>k.id===w);if(x&&qe(w)){v(x);return}c(w)},[t,c]),y=a((w)=>{let x=g;if(!x)return;if(w==="cancel"){v(null);return}if(w==="save"){if(x.id!==r)l(x.id);p()}v(null),c(x.id)},[g,r,l,p,c]);return{requestClose:h,pending:g,answer:y}}function an(){let[t,r]=n(0),[l,c]=n(!1),p=a(()=>r((g)=>g+1),[]);return{goToLineRequest:t,openGoToLine:p,saveAsOpen:l,setSaveAsOpen:c}}function Un({className:t="",openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:g,refreshKey:v=0,onFileSaved:h,onOpenPath:y,onReopenClosed:w,reopenableCount:x,onCopyPath:k,onRevealInFiles:O,rootPath:C=null,repoPath:M=null,activeEditorPanelKey:A=null,forcedActiveFileId:F=null,asSplitPane:z=!1,onHidePanel:I}){let W=z?F:l,R=r.find((V)=>V.id===W),[L,G,X]=S("editor.previewMode",{}),Y=mu(String(W??"")),[N,P]=S("editor.zoomLevel",So),[H,J]=n(!1),[Q,te]=S("editor.wordWrap",!0),ie=an(),{sessionId:le}=Oe(),ee=en({openedFiles:r,activeFileId:W,enabled:!z}),ne=i(null),de=Do(),ce=Ci(),he=ou(r,v),Ie=Boolean(R&&he.has(R.id)),j=su(R??null,{reportSaveError:!0,onFileSaved:h,missing:Ie}),sn=qg({path:R?.path??"",content:j.content,language:j.language}),ln=j.diskChange,Fe=on({openedFiles:r,activeFileId:W,onSelectFile:c,onCloseFile:p,saveNow:j.saveNow}),we=lu({text:j.content,documentKey:`${R?.id??""}\x00${j.language}`,readSelection:()=>ne.current?.getSelection()??null,select:(V,me,Be=!0)=>ne.current?.select(V,me,Be),reveal:(V)=>ne.current?.revealOffset(V),applyDocument:(V,me,Be)=>ne.current?.applyDocument(V,me,Be),toggleWordWrap:()=>te((V)=>!V)}),ze=cu(R?.path??null,j.content,j.loaded&&!j.loadError);$t({searchReveal:ze,revealMatch:we.revealMatch}),uu({file:R,editor:j,surfaceRef:ne,isPreview:R?L[R.id]===!0:!1,exitPreview:()=>{let V=R?.id;if(V===void 0||V===null)return;G((me)=>({...me,[V]:!1}))}}),o(()=>{if(v>0)j.reset()},[v]),o(()=>{j.retain(r.map((V)=>V.id)),Ge(r.map((V)=>V.id))},[r]),Vt({openedFiles:r,dirtyKeys:j.dirtyKeys,activeFile:R,previewReady:X,setPreviewMode:G,sessionId:le});let dn=()=>{if(!R)return;G((V)=>({...V,[R.id]:!V[R.id]}))},Re=(V)=>{if(Ef(V)){we.runCommand(V);return}if(V==="toggleWordWrap"){te((me)=>!me);return}if(V==="goToLine"){ie.openGoToLine();return}ne.current?.runCommand(V)},cn=tn({find:we,runCommand:Re,reopenClosed:w}),un=nn({saveNow:j.saveNow,runCommand:Re}),Pe=Mh(A);if(Pe)return e(zt,{pluginId:Pe.pluginId,Component:Pe.Component,sessionId:le,className:t,onHide:I});if(r.length===0)return e(Ht,{className:t,onHide:I});let pn=j.viewerKind,He=R?L[R.id]:!1,fn={activeFile:R,editor:j,find:we,surfaceRef:ne,pluginFileView:sn,wordWrap:Q,setWordWrap:te,viewerKind:pn,isPreview:Boolean(He),isReviewing:Boolean(He)&&Y.active,onToggleReview:Y.toggle,isMaximized:H,setIsMaximized:J,zoomLevel:N,setZoomLevel:P,goToLineRequest:ie.goToLineRequest,onSaveAs:()=>ie.setSaveAsOpen(!0),onOpenPath:y,rootPath:C,repoPath:M,runCommand:Re,editorFontFamily:de,editorTheme:ce,togglePreview:dn,revealActive:Boolean(ze),missing:Ie,onConvertDiffToEditor:g,onFileSaved:h},bn=(V)=>({openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:g,refreshKey:v,onFileSaved:h,onOpenPath:y,rootPath:C,repoPath:M,forcedActiveFileId:V,asSplitPane:!0}),hn=e(it,{openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:Fe.requestClose,missingIds:he,onCopyPath:k,onRevealInFiles:O,onReopenClosed:w,reopenableCount:x,onSplitTo:ee.splitTo,onUnsplit:ee.close,splitRightFileId:ee.rightFile?.id??null,onHide:I}),$e=e(jt,{className:t,isMaximized:H,onKeyDownCapture:cn.onKeyDownCapture,onFocusCapture:un.onFocusCapture,asSplitPane:z,tabs:hn,activeFile:R,editor:j,externalChange:ln,conflict:j.conflict,onReload:j.resolveConflictByReload,onKeepMine:j.keepMineAgainstDisk,body:e(Ft,{...fn}),saveAsOpen:ie.saveAsOpen,onSaveAsClose:()=>ie.setSaveAsOpen(!1),onSavedAs:(V)=>{ie.setSaveAsOpen(!1),y?.(V)},closeGuard:Fe});if(!ee.rightFile)return $e;return e(Qt,{fraction:ee.fraction,onFraction:ee.setFraction,rightPaneName:ee.rightFile.name,onClosePane:ee.close,rightPane:e(Un,{...bn(ee.rightFile.id)}),children:$e})}export{Un as Editor};