@fabiofiorita/porcelain 0.63.2 → 0.63.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{u as o,a as t,j as i,P as r,Q as n}from"./index-BG75F5tP.js";function a(){const f=o(e=>e.diffMode),l=o(e=>e.setDiffMode);return t()?null:i.jsxs(r,{value:[f],onValueChange:e=>{const s=e[0];(s==="unified"||s==="split")&&l(s)},children:[i.jsx(n,{value:"unified",size:"sm",children:"Unified"}),i.jsx(n,{value:"split",size:"sm",children:"Split"})]})}export{a as D};
1
+ import{u as o,a as t,j as i,P as r,Q as n}from"./index-CuWbxCsX.js";function a(){const f=o(e=>e.diffMode),l=o(e=>e.setDiffMode);return t()?null:i.jsxs(r,{value:[f],onValueChange:e=>{const s=e[0];(s==="unified"||s==="split")&&l(s)},children:[i.jsx(n,{value:"unified",size:"sm",children:"Unified"}),i.jsx(n,{value:"split",size:"sm",children:"Split"})]})}export{a as D};
@@ -1 +1 @@
1
- import{u as Q,a as Y,b as Z,c as P,d as ee,e as se,f as te,r,g as ne,h as oe,i as ae,j as e,v as re,T as E,k as c,l as x,B as u,S as ie,m as le,n as I,o as m,M as D,F as de,p as ce,C as xe,q as ue,s as me,t as U,w as pe,x as fe,D as he,y as je,z as ge,A as ve,E as Ce,G as we,H as be,I as Ne}from"./index-BG75F5tP.js";import{l as ke}from"./line-selection-CDQurM1g.js";import{D as Te}from"./diff-mode-toggle-D41-9y4s.js";import{H as Me}from"./hunks-view-DW93fMKk.js";import{U as Se,F as Fe}from"./unfold-vertical-C146gwHO.js";import"./virtual-rows-BdkQ29uq.js";function Ue({filePath:t,base:p,paneIndex:v=0}){const z=Q(s=>s.diffMode),O=Y()?"unified":z,R=Z(),V=P(s=>s.openTab),{hunks:C,status:w,image:f,binary:b,error:A}=ee(t,p),N=p===void 0?{type:"working"}:{type:"branch",base:p},H=se(N),{mark:q,unmark:$}=te(N),h=N,i=H.has(t),[l,k]=r.useState(null),[n,j]=r.useState(null),B=ne(t,h),T=oe(s=>s.setPath);r.useEffect(()=>(T(v,t),()=>T(v,null)),[t,v,T]);const[M,g]=r.useState([]),S=`${t}\0${p??""}`,[W,_]=r.useState(S);W!==S&&(_(S),g([]));const F=r.useMemo(()=>ae(C??[],{context:he,revealed:M}),[C,M]),G=(s,a)=>{const o=a==="up"?Ce(s):a==="down"?we(s):be(s);g(d=>Ne(d,o))},K=F.gaps.some(s=>s.expandable),X=r.useMemo(()=>{if(!n||n.path!==t||n.startLine===void 0)return;const s=new Set,a=n.endLine??n.startLine;for(let o=n.startLine;o<=a;o++)s.add(o);return s},[n,t]),J=()=>{if(R===null)return;const s=`${R}/${t}`;V(je("file",s,{title:ve(t),preview:!0},ge()))};if(A)return e.jsx("p",{className:"p-4 text-sm text-destructive",children:A.message});if(C===void 0&&f===void 0&&!b)return e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"});const L=f!==void 0||b;return e.jsxs("div",{"data-testid":E.codeWell,className:re,children:[e.jsxs("div",{"data-testid":E.codeCard,className:I(pe,"flex h-full min-h-0 flex-col"),children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b px-3 py-1",children:[e.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:I(i?"text-success":"text-muted-foreground hover:text-foreground"),onClick:()=>{i?$(t):q(t)},"aria-label":i?"Unmark reviewed":"Mark reviewed","data-testid":E.diffReviewed(t),children:i?e.jsx(ie,{}):e.jsx(le,{})})}),e.jsx(m,{children:i?"Unmark reviewed":"Mark reviewed"})]}),e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>j({path:t,scope:h}),"aria-label":"Comment on file",children:e.jsx(D,{})})}),e.jsx(m,{children:"Comment on file"})]}),w!=="deleted"&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:J,"aria-label":"Open file",children:e.jsx(de,{})})}),e.jsx(m,{children:"Open file"})]}),!L&&K&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>g(ce()),"aria-label":"Expand all context",children:e.jsx(Se,{})})}),e.jsx(m,{children:"Expand all context"})]}),!L&&M.length>0&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>g([]),"aria-label":"Collapse context",children:e.jsx(Fe,{})})}),e.jsx(m,{children:"Collapse context"})]}),!L&&e.jsx(Te,{})]})]}),f!==void 0?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 overflow-auto p-8",children:[e.jsx("img",{src:f.dataUrl,alt:t,className:"max-h-full max-w-full object-contain"}),e.jsxs("p",{className:"text-2xs text-muted-foreground",children:[w==="untracked"||w==="added"?"New image":"Image changed"," · binary diff"]})]}):b?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Binary file"}):e.jsxs(xe,{onOpenChange:s=>{s||k(null)},children:[e.jsx(ue,{className:"block min-h-0 flex-1 select-text",onContextMenu:s=>{const a=ke();if(a){k(a);return}const o=s.target.closest("[data-line]"),d=o?Number.parseInt(o.getAttribute("data-line")??"",10):Number.NaN,y=o?.getAttribute("data-side");k(Number.isFinite(d)?{startLine:d,endLine:d,text:"",...y==="old"||y==="new"?{side:y}:{}}:null)},children:e.jsx(Me,{hunks:F.hunks,gaps:F.gaps,onExpand:G,filePath:t,diffMode:O,commentIndex:B,pendingLines:X})}),e.jsx(me,{className:"w-52",children:l?e.jsxs(U,{onClick:()=>j({path:t,startLine:l.startLine,endLine:l.endLine,anchorText:l.text.slice(0,2e3),scope:h,side:l.side}),children:[e.jsx(D,{})," Add comment"]}):e.jsxs(U,{onClick:()=>j({path:t,scope:h}),children:[e.jsx(D,{})," Comment on file"]})})]})]}),e.jsx(fe,{anchor:n,open:n!==null,onOpenChange:s=>{s||j(null)}})]})}export{Ue as DiffView};
1
+ import{u as Q,a as Y,b as Z,c as P,d as ee,e as se,f as te,r,g as ne,h as oe,i as ae,j as e,v as re,T as E,k as c,l as x,B as u,S as ie,m as le,n as I,o as m,M as D,F as de,p as ce,C as xe,q as ue,s as me,t as U,w as pe,x as fe,D as he,y as je,z as ge,A as ve,E as Ce,G as we,H as be,I as Ne}from"./index-CuWbxCsX.js";import{l as ke}from"./line-selection-CDQurM1g.js";import{D as Te}from"./diff-mode-toggle-DTeqhuLC.js";import{H as Me}from"./hunks-view-CXQMQon9.js";import{U as Se,F as Fe}from"./unfold-vertical-CIpACs4g.js";import"./virtual-rows-CsZNdhfp.js";function Ue({filePath:t,base:p,paneIndex:v=0}){const z=Q(s=>s.diffMode),O=Y()?"unified":z,R=Z(),V=P(s=>s.openTab),{hunks:C,status:w,image:f,binary:b,error:A}=ee(t,p),N=p===void 0?{type:"working"}:{type:"branch",base:p},H=se(N),{mark:q,unmark:$}=te(N),h=N,i=H.has(t),[l,k]=r.useState(null),[n,j]=r.useState(null),B=ne(t,h),T=oe(s=>s.setPath);r.useEffect(()=>(T(v,t),()=>T(v,null)),[t,v,T]);const[M,g]=r.useState([]),S=`${t}\0${p??""}`,[W,_]=r.useState(S);W!==S&&(_(S),g([]));const F=r.useMemo(()=>ae(C??[],{context:he,revealed:M}),[C,M]),G=(s,a)=>{const o=a==="up"?Ce(s):a==="down"?we(s):be(s);g(d=>Ne(d,o))},K=F.gaps.some(s=>s.expandable),X=r.useMemo(()=>{if(!n||n.path!==t||n.startLine===void 0)return;const s=new Set,a=n.endLine??n.startLine;for(let o=n.startLine;o<=a;o++)s.add(o);return s},[n,t]),J=()=>{if(R===null)return;const s=`${R}/${t}`;V(je("file",s,{title:ve(t),preview:!0},ge()))};if(A)return e.jsx("p",{className:"p-4 text-sm text-destructive",children:A.message});if(C===void 0&&f===void 0&&!b)return e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"});const L=f!==void 0||b;return e.jsxs("div",{"data-testid":E.codeWell,className:re,children:[e.jsxs("div",{"data-testid":E.codeCard,className:I(pe,"flex h-full min-h-0 flex-col"),children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b px-3 py-1",children:[e.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:I(i?"text-success":"text-muted-foreground hover:text-foreground"),onClick:()=>{i?$(t):q(t)},"aria-label":i?"Unmark reviewed":"Mark reviewed","data-testid":E.diffReviewed(t),children:i?e.jsx(ie,{}):e.jsx(le,{})})}),e.jsx(m,{children:i?"Unmark reviewed":"Mark reviewed"})]}),e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>j({path:t,scope:h}),"aria-label":"Comment on file",children:e.jsx(D,{})})}),e.jsx(m,{children:"Comment on file"})]}),w!=="deleted"&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:J,"aria-label":"Open file",children:e.jsx(de,{})})}),e.jsx(m,{children:"Open file"})]}),!L&&K&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>g(ce()),"aria-label":"Expand all context",children:e.jsx(Se,{})})}),e.jsx(m,{children:"Expand all context"})]}),!L&&M.length>0&&e.jsxs(c,{children:[e.jsx(x,{render:e.jsx(u,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>g([]),"aria-label":"Collapse context",children:e.jsx(Fe,{})})}),e.jsx(m,{children:"Collapse context"})]}),!L&&e.jsx(Te,{})]})]}),f!==void 0?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 overflow-auto p-8",children:[e.jsx("img",{src:f.dataUrl,alt:t,className:"max-h-full max-w-full object-contain"}),e.jsxs("p",{className:"text-2xs text-muted-foreground",children:[w==="untracked"||w==="added"?"New image":"Image changed"," · binary diff"]})]}):b?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Binary file"}):e.jsxs(xe,{onOpenChange:s=>{s||k(null)},children:[e.jsx(ue,{className:"block min-h-0 flex-1 select-text",onContextMenu:s=>{const a=ke();if(a){k(a);return}const o=s.target.closest("[data-line]"),d=o?Number.parseInt(o.getAttribute("data-line")??"",10):Number.NaN,y=o?.getAttribute("data-side");k(Number.isFinite(d)?{startLine:d,endLine:d,text:"",...y==="old"||y==="new"?{side:y}:{}}:null)},children:e.jsx(Me,{hunks:F.hunks,gaps:F.gaps,onExpand:G,filePath:t,diffMode:O,commentIndex:B,pendingLines:X})}),e.jsx(me,{className:"w-52",children:l?e.jsxs(U,{onClick:()=>j({path:t,startLine:l.startLine,endLine:l.endLine,anchorText:l.text.slice(0,2e3),scope:h,side:l.side}),children:[e.jsx(D,{})," Add comment"]}):e.jsxs(U,{onClick:()=>j({path:t,scope:h}),children:[e.jsx(D,{})," Comment on file"]})})]})]}),e.jsx(fe,{anchor:n,open:n!==null,onOpenChange:s=>{s||j(null)}})]})}export{Ue as DiffView};
@@ -0,0 +1,5 @@
1
+ import{$ as Pe,r,a1 as ue,ad as xe,ae as me,af as Ae,ag as ze,ah as Ie,ai as fe,b as te,aj as ne,j as e,C as he,q as je,a6 as pe,n as F,ak as He,T as J,al as Q,am as D,s as ge,t as v,an as B,ao as U,ap as Z,aq as ve,ar as De,as as re,M as E,at as ee,au as Ce,av as we,aw as ke,x as oe,a8 as be,c as se,ax as Oe,ay as q,az as Ke,B as O,ab as Ve,_ as _e,aA as Be,a7 as Ue,u as R,g as qe,aB as Ge,aC as We,v as $e,k as Xe,l as Qe,o as Ye,w as Je,P as ye,Q as G,aD as Ze,aE as es}from"./index-CuWbxCsX.js";import{i as ss,a as ts,M as ns,H as rs}from"./html-view-BPOrX4do.js";import{b as os,l as as,c as is}from"./line-selection-CDQurM1g.js";import{R as ls,V as cs}from"./virtual-rows-CsZNdhfp.js";const ds=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],us=Pe("scissors",ds);function Se(t,o){return!o||o.length===0?!1:o.some(n=>t>=n.start&&t<=n.end)}const xs=5e3,ms=800,Y="pointer-events-none absolute bottom-2 right-3 rounded-md border-transparent bg-muted/80 text-2xs",fs=r.memo(be),hs=8;function js({path:t,initialContent:o,highlightLine:n,highlightRanges:i,commentsByLine:a}){const[c,p]=r.useState(o),[m,x]=r.useState(o),[u,C]=r.useState(""),[d,w]=r.useState(!1),[f,k]=r.useState(null),[h,N]=r.useState(null),b=r.useRef(null),L=r.useRef(null),S=r.useRef(null),T=ue(t),M=r.useDeferredValue(c),P=xe(M,T),{findReferences:K,copyPath:V,copyRelativePath:_,reveal:W}=me(t),{save:A,isSaving:z,error:I}=Ae(t),g=ze();r.useEffect(()=>{if(!(c===m&&!z))return Ie(b,g,t)},[c,m,z,g,t]);const y=fe(),Ne=te()??void 0,ae=ne(Ne,t),Le=r.useMemo(()=>{if(!f||f.startLine===void 0)return null;const s=new Set,l=f.endLine??f.startLine;for(let j=f.startLine;j<=l;j++)s.add(j);return s},[f]),Me=r.useMemo(()=>{if(!d||u===""||!h)return null;const s=new Set;for(let l=h.startLine;l<=h.endLine;l++)s.add(l);return s},[d,u,h]),$=r.useEffectEvent(()=>{if(S.current&&clearTimeout(S.current),c===m)return;const s=c;A(s,()=>x(s))}),ie=s=>{p(s);const l=se.getState().panes.flatMap(j=>j.tabs).find(j=>j.kind==="file"&&j.path===t);se.getState().pinTab(l?.id??Oe("file",t)),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>$(),ms)};r.useEffect(()=>()=>{S.current&&clearTimeout(S.current),$()},[]);const le=r.useRef(o);r.useEffect(()=>{o!==le.current&&c===m&&(le.current=o,p(o),x(o))},[o,c,m]),r.useEffect(()=>{const s=L.current;!s||n===void 0||(s.scrollTop=Math.max(0,(n-1)*20-s.clientHeight/2+10))},[n]);const ce=s=>{const l=b.current;if(!l)return;const{selectionStart:j,selectionEnd:X,value:H}=l;ie(H.slice(0,j)+s+H.slice(X)),requestAnimationFrame(()=>{l.focus(),l.selectionStart=l.selectionEnd=j+s.length})},Te=()=>{const s=b.current;return s?s.value.slice(s.selectionStart,s.selectionEnd):""},Ee=()=>{navigator.clipboard?.readText&&U(async()=>{ce(await navigator.clipboard.readText())},s=>{q("Paste",s)})},Fe=c!==m;return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onOpenChange:s=>{if(w(s),s){C(Te());const l=b.current;N(l?os(l.value,l.selectionStart,l.selectionEnd):null)}},children:[e.jsxs(je,{className:"relative block h-full select-text overflow-hidden",children:[e.jsx("div",{ref:L,className:"h-full overflow-auto",children:e.jsxs("div",{className:"relative min-h-full w-max min-w-full",children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-0 px-4 py-2 font-mono text-xs leading-5",children:e.jsx("div",{className:"w-max min-w-full",children:c.split(`
2
+ `).map((s,l)=>{const j=l+1,X=(Le?.has(j)??!1)||(Me?.has(j)??!1),H=pe(a?.get(j),X)??(j===n?"bg-primary/15":void 0),Re=!H&&Se(j,i);return e.jsxs("div",{className:F("flex",H,Re&&"border-l-2 border-l-diff-add bg-diff-add/10"),children:[e.jsx("span",{className:"w-10 shrink-0 select-none pr-3 text-right text-muted-foreground/50",children:j}),e.jsx(fs,{tokens:P?.[l]??null,text:s})]},l)})})}),a&&a.size>0&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-20 font-mono text-xs leading-5",children:[...a.entries()].map(([s,l])=>e.jsx("div",{className:"pointer-events-auto absolute left-1 flex h-5 items-center",style:{top:hs+(s-1)*ls},children:e.jsx(He,{comments:l})},s))}),e.jsx("textarea",{ref:b,value:c,onChange:s=>ie(s.target.value),onKeyDown:s=>{s.key==="s"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),$())},spellCheck:!1,wrap:"off","aria-label":`Edit ${t}`,"data-testid":J.fileEditor,className:"relative z-10 block min-h-full min-w-full resize-none whitespace-pre bg-transparent py-2 pl-14 pr-4 font-mono text-xs leading-5 text-transparent caret-foreground outline-none field-sizing-content"})]})}),I?e.jsx(Q,{variant:"outline",className:F(Y,"text-destructive"),children:I.message}):z?e.jsx(Q,{variant:"outline",className:F(Y,"text-muted-foreground"),children:"Saving…"}):Fe?e.jsxs(Q,{variant:"outline",className:F(Y,"text-muted-foreground"),children:["Unsaved ",e.jsx(D,{className:"[@media(hover:none)]:hidden",tokens:["mod","S"]})]}):null]}),e.jsxs(ge,{className:"w-60",children:[e.jsxs(v,{disabled:u==="",onClick:()=>{U(async()=>{await Z(u),ce("")},s=>{q("Cut",s)})},children:[e.jsx(us,{})," Cut",e.jsx(B,{children:e.jsx(D,{tokens:["mod","X"]})})]}),e.jsxs(v,{disabled:u==="",onClick:()=>{U(()=>Z(u),s=>{q("Copy",s)})},children:[e.jsx(ve,{})," Copy",e.jsx(B,{children:e.jsx(D,{tokens:["mod","C"]})})]}),e.jsxs(v,{onClick:()=>Ee(),children:[e.jsx(De,{})," Paste",e.jsx(B,{children:e.jsx(D,{tokens:["mod","V"]})})]}),e.jsxs(v,{disabled:u.trim()==="",onClick:()=>K(u),children:[e.jsx(re,{})," Find references"]}),e.jsxs(v,{disabled:u==="",onClick:()=>{h&&k({path:ae,startLine:h.startLine,endLine:h.endLine,anchorText:u.slice(0,2e3)})},children:[e.jsx(E,{})," Add comment"]}),e.jsx(ee,{}),e.jsxs(v,{onClick:()=>k({path:ae}),children:[e.jsx(E,{})," Comment on file"]}),e.jsxs(v,{onClick:()=>{V()},children:[e.jsx(Ce,{})," Copy path"]}),e.jsxs(v,{onClick:()=>{_()},children:[e.jsx(we,{})," Copy relative path"]}),y&&e.jsxs(v,{onClick:()=>{W()},children:[e.jsx(ke,{})," Reveal in Finder"]})]})]}),e.jsx(oe,{anchor:f,open:f!==null,onOpenChange:s=>{s||k(null)}})]})}function ps({content:t,onClose:o,onMatchLine:n}){const[i,a]=r.useState(""),[c,p]=r.useState(0),m=r.useRef(null),x=r.useMemo(()=>{const d=i.toLowerCase();if(d==="")return[];const w=[];return t.split(`
3
+ `).forEach((f,k)=>{f.toLowerCase().includes(d)&&w.push(k+1)}),w},[t,i]),u=x.length===0?0:(c%x.length+x.length)%x.length,C=x.length===0?void 0:x[u];return r.useEffect(()=>{n(C)},[C,n]),r.useEffect(()=>{m.current?.focus()},[]),e.jsxs("div",{className:"absolute right-3 top-3 z-30 flex items-center gap-1 rounded-lg border bg-popover px-2 py-1 shadow-lg",children:[e.jsx(re,{className:"size-3.5 shrink-0 text-muted-foreground"}),e.jsx(Ke,{ref:m,value:i,onChange:d=>{a(d.target.value),p(0)},onKeyDown:d=>{d.key==="Escape"&&o(),d.key==="Enter"&&p(w=>w+(d.shiftKey?-1:1))},placeholder:"Find in file…","aria-label":"Find in file",className:"h-6 max-w-64 border-none bg-transparent text-xs shadow-none focus-visible:ring-0"}),e.jsx("span",{className:"shrink-0 text-2xs text-muted-foreground tabular-nums",children:i===""?"":x.length===0?"No results":`${u+1}/${x.length}`}),e.jsx(O,{variant:"ghost",size:"icon-xs",disabled:x.length===0,onClick:()=>p(d=>d-1),"aria-label":"Previous match",children:e.jsx(Ve,{})}),e.jsx(O,{variant:"ghost",size:"icon-xs",disabled:x.length===0,onClick:()=>p(d=>d+1),"aria-label":"Next match",children:e.jsx(_e,{})}),e.jsx(O,{variant:"ghost",size:"icon-xs",onClick:o,"aria-label":"Close find bar",children:e.jsx(Be,{})})]})}function de({path:t,children:o}){const[n,i]=r.useState(""),[a,c]=r.useState(null),[p,m]=r.useState(null),x=te()??void 0,{copyPath:u,copyRelativePath:C,reveal:d,findReferences:w}=me(t),f=fe(),k=ne(x,t);return e.jsxs(e.Fragment,{children:[e.jsxs(he,{onOpenChange:h=>{if(!h){c(null);return}i(window.getSelection()?.toString()??"")},children:[e.jsx(je,{className:"block h-full select-text",onContextMenu:h=>{const N=as();if(N){c(N);return}const b=h.target.closest("[data-line]"),L=b?Number.parseInt(b.getAttribute("data-line")??"",10):Number.NaN;c(Number.isFinite(L)?{startLine:L,endLine:L,text:""}:null)},children:o}),e.jsx(ge,{className:"w-56",children:n!==""?e.jsxs(e.Fragment,{children:[e.jsxs(v,{onClick:()=>{U(()=>Z(n),h=>{q("Copy",h)})},children:[e.jsx(ve,{})," Copy",e.jsx(B,{children:e.jsx(D,{tokens:["mod","C"]})})]}),e.jsxs(v,{disabled:n.trim()==="",onClick:()=>w(n),children:[e.jsx(re,{})," Find references"]}),a&&e.jsxs(v,{onClick:()=>m({path:k,startLine:a.startLine,endLine:a.endLine,anchorText:a.text.slice(0,2e3)}),children:[e.jsx(E,{})," Add comment"]})]}):e.jsxs(e.Fragment,{children:[a?e.jsxs(v,{onClick:()=>m({path:k,startLine:a.startLine,endLine:a.endLine}),children:[e.jsx(E,{})," Add comment"]}):e.jsxs(v,{onClick:()=>m({path:k}),children:[e.jsx(E,{})," Comment on file"]}),e.jsx(ee,{}),e.jsxs(v,{onClick:()=>{u()},children:[e.jsx(Ce,{})," Copy path"]}),e.jsxs(v,{onClick:()=>{C()},children:[e.jsx(we,{})," Copy relative path"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{}),e.jsxs(v,{onClick:()=>{d()},children:[e.jsx(ke,{})," Reveal in Finder"]})]})]})})]}),e.jsx(oe,{anchor:p,open:p!==null,onOpenChange:h=>{h||m(null)}})]})}function gs({path:t,content:o,highlightLine:n,highlightRanges:i,commentsByLine:a}){const c=ue(t),p=o.split(`
4
+ `),m=xe(o,c);return e.jsx(cs,{rows:p,className:"px-4 py-2 leading-5",scrollToLine:n,renderRow:(x,u)=>{const C=u+1,d=a?.get(C),w=pe(d),f=!w&&Se(C,i);return e.jsxs("div",{"data-line":C,className:F("relative flex",!w&&C===n&&"bg-primary/15",w,f&&"border-l-2 border-l-diff-add bg-diff-add/10"),children:[e.jsx(Ue,{comments:d}),e.jsx("span",{className:"w-10 shrink-0 select-none pr-3 text-right text-muted-foreground/50",children:C}),e.jsx(be,{tokens:m?.[u]??null,text:x})]})}})}function vs(){const t=R(n=>n.markdownMode),o=R(n=>n.setMarkdownMode);return e.jsxs(ye,{value:[t],onValueChange:n=>{const i=n[0];(i==="reader"||i==="source")&&o(i)},children:[e.jsx(G,{value:"reader",size:"sm",children:"Reader"}),e.jsx(G,{value:"source",size:"sm",children:"Source"})]})}function Cs(){const t=R(n=>n.htmlMode)??"preview",o=R(n=>n.setHtmlMode);return e.jsxs(ye,{value:[t],onValueChange:n=>{const i=n[0];(i==="preview"||i==="source")&&o(i)},children:[e.jsx(G,{value:"preview",size:"sm",children:"Preview"}),e.jsx(G,{value:"source",size:"sm",children:"Source"})]})}function ws({path:t,content:o,line:n,highlightRanges:i,paneIndex:a}){const c=te()??void 0,p=R(g=>g.markdownMode),m=R(g=>g.htmlMode)??"preview",[x,u]=r.useState(!1),[C,d]=r.useState(void 0),[w,f]=r.useState(null),[k,h]=r.useState(null),N=ne(c,t),b=qe(N),L=ss(t),S=ts(t),T=L&&p==="reader",M=S&&m==="preview",{html:P,error:K}=Ge(t,M),V=We(t,M&&P!==null),_=o.split(`
5
+ `).length,W=!T&&!M&&_<=xs,A=i&&i.reduce((g,y)=>g+(y.end-y.start+1),0)/_>=.9?void 0:i,z=n??A?.[0]?.start,I=x&&C!==void 0?C:z;return r.useEffect(()=>{const g=y=>{if(se.getState().activePaneIndex===a&&y.key==="f"&&(y.metaKey||y.ctrlKey)&&!y.shiftKey&&!y.altKey){if(T||M)return;y.preventDefault(),u(!0)}};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[a,T,M]),e.jsxs("div",{"data-testid":J.codeWell,className:$e,children:[e.jsxs("div",{"data-testid":J.codeCard,className:F(Je,"flex h-full min-h-0 flex-col"),children:[e.jsxs("div",{className:"flex h-9 shrink-0 items-center justify-between gap-2 border-b px-3",children:[e.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:N}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Xe,{children:[e.jsx(Qe,{render:e.jsx(O,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground hover:text-foreground",onClick:()=>f({path:N}),"aria-label":"Comment on file",children:e.jsx(E,{})})}),e.jsx(Ye,{children:"Comment on file"})]}),L&&e.jsx(vs,{}),S&&e.jsx(Cs,{})]})]}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[x&&!T&&!M&&e.jsx(ps,{content:o,onClose:()=>u(!1),onMatchLine:d}),T?e.jsx(de,{path:t,children:e.jsx(ns,{content:o,commentsByLine:b.byLine})}):M?K?e.jsx("p",{className:"p-4 text-sm text-destructive",children:K.message}):P===void 0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):P===null?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"HTML preview unavailable (missing or too large). Switch to Source to edit the raw file."}):V===null?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):e.jsxs("div",{className:"relative h-full",children:[e.jsx(rs,{src:V,title:t.split("/").at(-1)??"HTML preview",onSelection:h}),k!==null&&e.jsx("div",{className:"absolute bottom-4 left-1/2 z-20 -translate-x-1/2 rounded-lg border bg-popover p-1 shadow-lg",children:e.jsxs(O,{size:"sm",onClick:()=>{const g=is(o,k);f({path:N,anchorText:k,...g?{startLine:g.startLine,endLine:g.endLine}:{}}),h(null)},children:[e.jsx(E,{})," Add comment"]})})]}):W?e.jsx(js,{path:t,initialContent:o,highlightLine:I,highlightRanges:A,commentsByLine:b.byLine}):e.jsx(de,{path:t,children:e.jsx(gs,{path:t,content:o,highlightLine:I,highlightRanges:A,commentsByLine:b.byLine})})]})]}),e.jsx(oe,{anchor:w,open:w!==null,onOpenChange:g=>{g||f(null)}})]})}function Ns({path:t,line:o,highlight:n,paneIndex:i}){const{view:a,error:c}=Ze(t),p=es();return r.useEffect(()=>{a?.type==="not-found"&&p()},[a,p]),c?e.jsx("p",{className:"p-4 text-sm text-destructive",children:c.message}):a===void 0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Loading…"}):a.type==="not-found"?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"This file no longer exists."}):a.type==="image"?e.jsx("div",{className:"flex h-full items-center justify-center p-8",children:e.jsx("img",{src:a.dataUrl,alt:t,className:"max-h-full max-w-full object-contain"})}):a.type==="binary"?e.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:["Binary file · ",(a.size/1024).toFixed(1)," KB"]}):a.type==="too-large"?e.jsxs("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:["File too large to preview · ",(a.size/(1024*1024)).toFixed(1)," MB"]}):e.jsx(ws,{path:t,content:a.content,line:o,highlightRanges:n,paneIndex:i})}export{Ns as FileContent};