@hienlh/ppm 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/assets/chat-tab-BjXFBrXK.js +6 -0
- package/dist/web/assets/{code-editor-R0uEZQ-h.js → code-editor-C0h2laA5.js} +1 -1
- package/dist/web/assets/{diff-viewer-DDQ2Z0sz.js → diff-viewer-zj0eYBAi.js} +1 -1
- package/dist/web/assets/{git-graph-ugBsFNaz.js → git-graph-Bk_ZOw9M.js} +1 -1
- package/dist/web/assets/{git-status-panel-UMKtdAxp.js → git-status-panel-Byeu47TQ.js} +1 -1
- package/dist/web/assets/{index-Dmu22zQo.js → index-DboiMCUU.js} +2 -2
- package/dist/web/assets/{project-list-D38uQSpC.js → project-list-DRXLczvi.js} +1 -1
- package/dist/web/assets/{settings-tab-BpyCSbii.js → settings-tab-DtXFRF3d.js} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/web/components/chat/message-input.tsx +19 -10
- package/src/web/components/chat/message-list.tsx +3 -5
- package/src/web/components/chat/tool-cards.tsx +2 -2
- package/dist/web/assets/chat-tab-FOn2nq1x.js +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./button-CvHWF07y.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./copy-B-kLwqzg.js";import{t as s}from"./external-link-Dim3NH6h.js";import{t as c}from"./refresh-cw-DJSjl6Ev.js";import{t as l}from"./trash-2-CjahwKg8.js";import{a as u,i as d,n as f,o as p,t as m}from"./dialog-f3IZM-6v.js";import{r as h,t as g}from"./api-client-B_eCZViO.js";import{_ as ee,a as _,i as v,l as te,n as ne,o as y,r as b,s as x,v as S}from"./index-Dmu22zQo.js";var re=t(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=t(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),ie=t(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),ae=t(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),w=t(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(n(),1),E=r(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,oe=5;function A({metadata:e}){let t=e?.projectName,[n,r]=(0,T.useState)(null),[a,s]=(0,T.useState)(!0),[l,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[ce,B]=(0,T.useState)(!1),{openTab:V}=te(),H=(0,T.useCallback)(async()=>{if(t)try{s(!0),r(await g.get(`${h(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{s(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await g.post(`${h(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),le=e=>U(`/git/cherry-pick`,{hash:e}),ue=e=>U(`/git/revert`,{hash:e}),de=e=>U(`/git/merge`,{source:e}),fe=e=>U(`/git/branch/delete`,{name:e}),pe=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(n?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),me=async e=>{if(t)try{let n=await g.get(`${h(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},he=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await g.get(`${h(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},ge=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:_e}=(0,T.useMemo)(()=>{let e=new Map;if(!n)return{laneMap:e,maxLane:0};let t=0,r=new Map;for(let i of n.commits){let n=r.get(i.hash);n===void 0&&(n=t++),e.set(i.hash,n),r.delete(i.hash);for(let e=0;e<i.parents.length;e++){let a=i.parents[e];r.has(a)||r.set(a,e===0?n:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[n]),Y=n?.branches.find(e=>e.current),ve=(0,T.useMemo)(()=>{let e=new Map;if(!n)return e;for(let t of n.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of n.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[n]),ye=(0,T.useMemo)(()=>{if(!n)return[];let e=[];for(let t=0;t<n.commits.length;t++){let r=n.commits[t],i=J.get(r.hash)??0,a=D[i%D.length];for(let o of r.parents){let s=n.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=i*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=r.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=r.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[n,J]);(_e+1)*k+k;let X=(n?.commits.length??0)*O,[Z,be]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;be(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),xe=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Se=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(a&&!n)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(ee,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(l&&!n)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:l}),(0,E.jsx)(i,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function Ce(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(c,{className:a?`animate-spin`:``})})]}),l&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:l}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[ye.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),n?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:oe,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:xe,onTouchStart:Se,children:(0,E.jsx)(ie,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:n?.commits.map((e,t)=>{let n=D[(J.get(e.hash)??0)%D.length],r=ve.get(e.hash)??[],i=r.filter(e=>e.type===`branch`),a=r.filter(e=>e.type===`tag`);return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>he(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),i.map(e=>(0,E.jsx)(se,{label:e,color:n,currentBranch:Y,onCheckout:W,onMerge:de,onPush:pe,onCreatePr:me,onDelete:fe},`branch-${e.name}`)),a.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:Ce(e.authorDate)})]})})}),(0,E.jsxs)(v,{children:[(0,E.jsx)(_,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(S,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{onClick:()=>le(e.hash),children:[(0,E.jsx)(re,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(_,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(_,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(y,{}),(0,E.jsx)(_,{onClick:()=>ge(e),children:`View Diff`}),(0,E.jsxs)(_,{onClick:()=>q(e.hash),children:[(0,E.jsx)(o,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:ce?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${e.path.split(`/`).pop()}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(m,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(f,{children:[(0,E.jsx)(u,{children:(0,E.jsx)(p,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(ne,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(d,{children:[(0,E.jsx)(i,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(i,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function se({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:o,onCreatePr:c,onDelete:u}){return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(S,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(v,{children:[(0,E.jsx)(_,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{onClick:()=>o(e.name),children:[(0,E.jsx)(a,{className:`size-3`}),`Push`]}),(0,E.jsxs)(_,{onClick:()=>c(e.name),children:[(0,E.jsx)(s,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{variant:`destructive`,onClick:()=>u(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(l,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};
|
|
1
|
+
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./button-CvHWF07y.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./copy-B-kLwqzg.js";import{t as s}from"./external-link-Dim3NH6h.js";import{t as c}from"./refresh-cw-DJSjl6Ev.js";import{t as l}from"./trash-2-CjahwKg8.js";import{a as u,i as d,n as f,o as p,t as m}from"./dialog-f3IZM-6v.js";import{r as h,t as g}from"./api-client-B_eCZViO.js";import{_ as ee,a as _,i as v,l as te,n as ne,o as y,r as b,s as x,v as S}from"./index-DboiMCUU.js";var re=t(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=t(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),ie=t(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),ae=t(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),w=t(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(n(),1),E=r(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,oe=5;function A({metadata:e}){let t=e?.projectName,[n,r]=(0,T.useState)(null),[a,s]=(0,T.useState)(!0),[l,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[ce,B]=(0,T.useState)(!1),{openTab:V}=te(),H=(0,T.useCallback)(async()=>{if(t)try{s(!0),r(await g.get(`${h(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{s(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await g.post(`${h(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),le=e=>U(`/git/cherry-pick`,{hash:e}),ue=e=>U(`/git/revert`,{hash:e}),de=e=>U(`/git/merge`,{source:e}),fe=e=>U(`/git/branch/delete`,{name:e}),pe=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(n?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),me=async e=>{if(t)try{let n=await g.get(`${h(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},he=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await g.get(`${h(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},ge=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:_e}=(0,T.useMemo)(()=>{let e=new Map;if(!n)return{laneMap:e,maxLane:0};let t=0,r=new Map;for(let i of n.commits){let n=r.get(i.hash);n===void 0&&(n=t++),e.set(i.hash,n),r.delete(i.hash);for(let e=0;e<i.parents.length;e++){let a=i.parents[e];r.has(a)||r.set(a,e===0?n:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[n]),Y=n?.branches.find(e=>e.current),ve=(0,T.useMemo)(()=>{let e=new Map;if(!n)return e;for(let t of n.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of n.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[n]),ye=(0,T.useMemo)(()=>{if(!n)return[];let e=[];for(let t=0;t<n.commits.length;t++){let r=n.commits[t],i=J.get(r.hash)??0,a=D[i%D.length];for(let o of r.parents){let s=n.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=i*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=r.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=r.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[n,J]);(_e+1)*k+k;let X=(n?.commits.length??0)*O,[Z,be]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;be(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),xe=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Se=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(a&&!n)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(ee,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(l&&!n)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:l}),(0,E.jsx)(i,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function Ce(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(c,{className:a?`animate-spin`:``})})]}),l&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:l}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[ye.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),n?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:oe,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:xe,onTouchStart:Se,children:(0,E.jsx)(ie,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:n?.commits.map((e,t)=>{let n=D[(J.get(e.hash)??0)%D.length],r=ve.get(e.hash)??[],i=r.filter(e=>e.type===`branch`),a=r.filter(e=>e.type===`tag`);return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>he(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),i.map(e=>(0,E.jsx)(se,{label:e,color:n,currentBranch:Y,onCheckout:W,onMerge:de,onPush:pe,onCreatePr:me,onDelete:fe},`branch-${e.name}`)),a.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:Ce(e.authorDate)})]})})}),(0,E.jsxs)(v,{children:[(0,E.jsx)(_,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(S,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{onClick:()=>le(e.hash),children:[(0,E.jsx)(re,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(_,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(_,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(y,{}),(0,E.jsx)(_,{onClick:()=>ge(e),children:`View Diff`}),(0,E.jsxs)(_,{onClick:()=>q(e.hash),children:[(0,E.jsx)(o,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:ce?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${e.path.split(`/`).pop()}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(m,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(f,{children:[(0,E.jsx)(u,{children:(0,E.jsx)(p,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(ne,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(d,{children:[(0,E.jsx)(i,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(i,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function se({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:o,onCreatePr:c,onDelete:u}){return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(S,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(v,{children:[(0,E.jsx)(_,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{onClick:()=>o(e.name),children:[(0,E.jsx)(a,{className:`size-3`}),`Push`]}),(0,E.jsxs)(_,{onClick:()=>c(e.name),children:[(0,E.jsx)(s,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(_,{variant:`destructive`,onClick:()=>u(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(l,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./button-CvHWF07y.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./refresh-cw-DJSjl6Ev.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./dialog-f3IZM-6v.js";import{r as p,t as m}from"./api-client-B_eCZViO.js";import{D as h,E as g,S as _,_ as v,h as y,l as b,u as x}from"./index-Dmu22zQo.js";var S=t(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),C=t(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),w=t(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),T=t(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=t(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),D=e(n(),1),O=r(),k={M:`text-yellow-500`,A:`text-green-500`,D:`text-red-500`,R:`text-blue-500`,C:`text-purple-500`,"?":`text-gray-400`};function A(e){let t=[];for(let n of e){let e=n.path.split(`/`),r=t;for(let t=0;t<e.length;t++){let i=e[t],a=e.slice(0,t+1).join(`/`),o=t===e.length-1,s=r.find(e=>e.name===i);s||(s={name:i,fullPath:a,file:o?n:void 0,children:[]},r.push(s)),o&&(s.file=n),r=s.children}}return t}function j(e){let t=[];e.file&&t.push(e.file);for(let n of e.children)t.push(...j(n));return t}function M({metadata:e,tabId:t}){let n=e?.projectName,[r,h]=(0,D.useState)(null),[g,_]=(0,D.useState)(!0),[E,k]=(0,D.useState)(null),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(!1),[F,I]=(0,D.useState)(null),{openTab:L,updateTab:R}=b(),z=e?.viewMode===`tree`?`tree`:`flat`,B=n=>{t&&R(t,{metadata:{...e,viewMode:n}})},V=(0,D.useCallback)(async()=>{if(n)try{_(!0),h(await m.get(`${p(n)}/git/status`)),k(null)}catch(e){k(e instanceof Error?e.message:`Failed to fetch status`)}finally{_(!1)}},[n]);(0,D.useEffect)(()=>{V();let e=setInterval(V,5e3);return()=>clearInterval(e)},[V]);let H=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/stage`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Stage failed`)}finally{N(!1)}}},U=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/unstage`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Unstage failed`)}finally{N(!1)}}},W=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/discard`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Discard failed`)}finally{N(!1)}}},G=async()=>{F&&(await W(F.files),I(null))},K=async()=>{if(!(!n||!A.trim()||!r?.staged.length)){N(!0);try{await m.post(`${p(n)}/git/commit`,{message:A.trim()}),j(``),await V()}catch(e){k(e instanceof Error?e.message:`Commit failed`)}finally{N(!1)}}},q=async()=>{if(n){N(!0);try{await m.post(`${p(n)}/git/push`,{}),await V()}catch(e){k(e instanceof Error?e.message:`Push failed`)}finally{N(!1)}}},J=async()=>{if(n){N(!0);try{await m.post(`${p(n)}/git/pull`,{}),await V()}catch(e){k(e instanceof Error?e.message:`Pull failed`)}finally{N(!1)}}},Y=e=>{L({type:`git-diff`,title:e.path.split(`/`).pop()??e.path,closable:!0,metadata:{projectName:n,filePath:e.path},projectId:n??null})},X=e=>{L({type:`editor`,title:e.path.split(`/`).pop()??e.path,closable:!0,metadata:{projectName:n,filePath:e.path},projectId:n??null})},Z=(0,D.useMemo)(()=>[...r?.unstaged??[],...r?.untracked.map(e=>({path:e,status:`?`}))??[]],[r]);return n?g&&!r?(0,O.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,O.jsx)(v,{className:`size-5 animate-spin`}),(0,O.jsx)(`span`,{className:`text-sm`,children:`Loading git status...`})]}):E&&!r?(0,O.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,O.jsx)(`p`,{children:E}),(0,O.jsx)(i,{variant:`outline`,size:`sm`,onClick:V,children:`Retry`})]}):(0,O.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b shrink-0`,children:[(0,O.jsx)(`span`,{className:`text-sm font-medium`,children:r?.current?`On: ${r.current}`:`Git Status`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(i,{variant:z===`flat`?`secondary`:`ghost`,size:`icon-xs`,onClick:()=>B(`flat`),title:`Flat view`,children:(0,O.jsx)(w,{className:`size-3.5`})}),(0,O.jsx)(i,{variant:z===`tree`?`secondary`:`ghost`,size:`icon-xs`,onClick:()=>B(`tree`),title:`Tree view`,children:(0,O.jsx)(C,{className:`size-3.5`})}),(0,O.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:V,disabled:M,children:(0,O.jsx)(o,{className:g?`animate-spin`:``})})]})]}),E&&(0,O.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0`,children:E}),(0,O.jsx)(x,{className:`flex-1 overflow-hidden`,children:(0,O.jsxs)(`div`,{className:`p-2 space-y-3 overflow-hidden`,children:[(0,O.jsx)(P,{title:`Staged Changes`,count:r?.staged.length??0,files:r?.staged??[],viewMode:z,actionIcon:(0,O.jsx)(T,{className:`size-3.5`}),actionTitle:`Unstage`,onAction:e=>U([e.path]),onActionAll:r?.staged.length?()=>U(r.staged.map(e=>e.path)):void 0,actionAllLabel:`Unstage All`,onFolderAction:e=>U(e.map(e=>e.path)),onClickFile:Y,onOpenFile:X,disabled:M}),(0,O.jsx)(P,{title:`Changes`,count:Z.length,files:Z,viewMode:z,actionIcon:(0,O.jsx)(y,{className:`size-3.5`}),actionTitle:`Stage`,onAction:e=>H([e.path]),onActionAll:Z.length?()=>H(Z.map(e=>e.path)):void 0,actionAllLabel:`Stage All`,onFolderAction:e=>H(e.map(e=>e.path)),onClickFile:Y,onOpenFile:X,disabled:M,showRevert:!0,onRevert:e=>I({label:e.path,files:[e.path]}),onFolderRevert:(e,t)=>I({label:`${t}/ (${e.length} files)`,files:e.map(e=>e.path)})})]})}),(0,O.jsxs)(`div`,{className:`border-t p-2 space-y-2 shrink-0`,children:[(0,O.jsx)(`textarea`,{className:`w-full h-16 px-3 py-2 text-base md:text-sm text-foreground bg-surface border border-border rounded-lg resize-none focus:outline-none focus:border-ring placeholder:text-muted-foreground`,placeholder:`Commit message...`,value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&K()}}),(0,O.jsx)(i,{size:`sm`,className:`w-full`,disabled:M||!A.trim()||!r?.staged.length,onClick:K,children:M?(0,O.jsx)(v,{className:`size-3 animate-spin`}):`Commit (${r?.staged.length??0})`}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(i,{variant:`outline`,size:`sm`,className:`flex-1`,disabled:M,onClick:q,children:[(0,O.jsx)(a,{className:`size-3`}),`Push`]}),(0,O.jsxs)(i,{variant:`outline`,size:`sm`,className:`flex-1`,disabled:M,onClick:J,children:[(0,O.jsx)(S,{className:`size-3`}),`Pull`]})]})]}),(0,O.jsx)(f,{open:!!F,onOpenChange:e=>!e&&I(null),children:(0,O.jsxs)(l,{showCloseButton:!1,children:[(0,O.jsxs)(s,{children:[(0,O.jsx)(u,{children:`Discard Changes`}),(0,O.jsxs)(d,{children:[`Are you sure you want to discard all changes to`,` `,(0,O.jsx)(`code`,{className:`px-1 py-0.5 rounded bg-muted text-sm font-mono`,children:F?.label}),`? This action cannot be undone.`]})]}),(0,O.jsxs)(c,{children:[(0,O.jsx)(i,{variant:`outline`,onClick:()=>I(null),children:`Cancel`}),(0,O.jsx)(i,{variant:`destructive`,onClick:G,disabled:M,children:M?(0,O.jsx)(v,{className:`size-3 animate-spin`}):`Discard`})]})]})})]}):(0,O.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`})}function N({showRevert:e,onRevert:t,onAction:n,onOpenFile:r,actionIcon:i,actionTitle:a,disabled:o}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0 ml-1`,children:[r&&(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-primary/15 hover:text-primary hover:border-primary/40 active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),r()},disabled:o,title:`Open file`,children:(0,O.jsx)(_,{className:`size-3.5`})}),e&&t&&(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-destructive/15 hover:text-destructive hover:border-destructive/40 active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),t()},disabled:o,title:`Discard changes`,children:(0,O.jsx)(E,{className:`size-3.5`})}),(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-accent hover:text-accent-foreground active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),n()},disabled:o,title:a,children:i})]})}function P({title:e,count:t,files:n,viewMode:r,actionIcon:a,actionTitle:o,onAction:s,onActionAll:c,actionAllLabel:l,onFolderAction:u,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h,onFolderRevert:g}){return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,O.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase`,children:[e,` (`,t,`)`]}),c&&t>0&&(0,O.jsx)(i,{variant:`ghost`,size:`xs`,onClick:c,disabled:p,title:l,children:l})]}),n.length===0?(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground px-1`,children:`No changes`}):r===`flat`?(0,O.jsx)(`div`,{className:`divide-y divide-border/40 w-full overflow-hidden`,children:n.map(e=>(0,O.jsx)(F,{file:e,actionIcon:a,actionTitle:o,onAction:s,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h},e.path))}):(0,O.jsx)(I,{files:n,actionIcon:a,actionTitle:o,onAction:s,onFolderAction:u,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h,onFolderRevert:g})]})}function F({file:e,actionIcon:t,actionTitle:n,onAction:r,onClickFile:i,onOpenFile:a,disabled:o,showRevert:s,onRevert:c,displayName:l}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-muted/50 rounded px-1 py-1 w-full min-w-0`,children:[(0,O.jsx)(`span`,{className:`text-xs font-mono w-4 text-center shrink-0 ${k[e.status]??``}`,children:e.status}),(0,O.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-xs font-mono truncate hover:underline min-w-0`,onClick:()=>i(e),title:e.path,children:l??e.path}),(0,O.jsx)(N,{showRevert:s,onRevert:c?()=>c(e):void 0,onOpenFile:a?()=>a(e):void 0,onAction:()=>r(e),actionIcon:t,actionTitle:n,disabled:o})]})}function I({files:e,actionIcon:t,actionTitle:n,onAction:r,onFolderAction:i,onClickFile:a,onOpenFile:o,disabled:s,showRevert:c,onRevert:l,onFolderRevert:u}){let d=(0,D.useMemo)(()=>A(e),[e]);return(0,O.jsx)(`div`,{children:d.map((e,f)=>(0,O.jsx)(L,{node:e,depth:0,isLast:f===d.length-1,actionIcon:t,actionTitle:n,onAction:r,onFolderAction:i,onClickFile:a,onOpenFile:o,disabled:s,showRevert:c,onRevert:l,onFolderRevert:u},e.fullPath))})}function L({node:e,depth:t,isLast:n,actionIcon:r,actionTitle:i,onAction:a,onFolderAction:o,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d,onFolderRevert:f}){let[p,m]=(0,D.useState)(!0),_=e.children.length>0&&!e.file;if(e.file)return(0,O.jsxs)(`div`,{className:`relative overflow-hidden border-b border-border/30`,style:{paddingLeft:t*16},children:[t>0&&(0,O.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-border/30`,style:{left:t*16-8}}),(0,O.jsx)(F,{file:e.file,displayName:e.name,actionIcon:r,actionTitle:i,onAction:a,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d})]});if(_){let _=j(e);return(0,O.jsxs)(`div`,{className:`relative overflow-hidden`,children:[t>0&&(0,O.jsx)(`div`,{className:`absolute top-0 border-l border-border/30`,style:{left:t*16-8,bottom:n?`50%`:0}}),(0,O.jsxs)(`div`,{className:`flex items-center hover:bg-muted/50 rounded py-1 pr-1 border-b border-border/30`,style:{paddingLeft:t*16+4},children:[(0,O.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 flex-1 min-w-0 text-xs font-mono text-muted-foreground`,onClick:()=>m(!p),children:[p?(0,O.jsx)(h,{className:`size-3.5 shrink-0`}):(0,O.jsx)(g,{className:`size-3.5 shrink-0`}),(0,O.jsx)(`span`,{className:`truncate font-semibold`,children:e.name}),(0,O.jsxs)(`span`,{className:`text-[10px] opacity-60 shrink-0`,children:[`(`,_.length,`)`]})]}),(0,O.jsx)(N,{showRevert:u,onRevert:f?()=>f(_,e.fullPath):void 0,onAction:()=>o?.(_),actionIcon:r,actionTitle:`${i} ${e.name}/`,disabled:l})]}),p&&(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-border/30`,style:{left:t*16+8}}),e.children.map((n,p)=>(0,O.jsx)(L,{node:n,depth:t+1,isLast:p===e.children.length-1,actionIcon:r,actionTitle:i,onAction:a,onFolderAction:o,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d,onFolderRevert:f},n.fullPath))]})]})}return null}export{M as GitStatusPanel};
|
|
1
|
+
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./button-CvHWF07y.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./refresh-cw-DJSjl6Ev.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./dialog-f3IZM-6v.js";import{r as p,t as m}from"./api-client-B_eCZViO.js";import{D as h,E as g,S as _,_ as v,h as y,l as b,u as x}from"./index-DboiMCUU.js";var S=t(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),C=t(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),w=t(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),T=t(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=t(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),D=e(n(),1),O=r(),k={M:`text-yellow-500`,A:`text-green-500`,D:`text-red-500`,R:`text-blue-500`,C:`text-purple-500`,"?":`text-gray-400`};function A(e){let t=[];for(let n of e){let e=n.path.split(`/`),r=t;for(let t=0;t<e.length;t++){let i=e[t],a=e.slice(0,t+1).join(`/`),o=t===e.length-1,s=r.find(e=>e.name===i);s||(s={name:i,fullPath:a,file:o?n:void 0,children:[]},r.push(s)),o&&(s.file=n),r=s.children}}return t}function j(e){let t=[];e.file&&t.push(e.file);for(let n of e.children)t.push(...j(n));return t}function M({metadata:e,tabId:t}){let n=e?.projectName,[r,h]=(0,D.useState)(null),[g,_]=(0,D.useState)(!0),[E,k]=(0,D.useState)(null),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(!1),[F,I]=(0,D.useState)(null),{openTab:L,updateTab:R}=b(),z=e?.viewMode===`tree`?`tree`:`flat`,B=n=>{t&&R(t,{metadata:{...e,viewMode:n}})},V=(0,D.useCallback)(async()=>{if(n)try{_(!0),h(await m.get(`${p(n)}/git/status`)),k(null)}catch(e){k(e instanceof Error?e.message:`Failed to fetch status`)}finally{_(!1)}},[n]);(0,D.useEffect)(()=>{V();let e=setInterval(V,5e3);return()=>clearInterval(e)},[V]);let H=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/stage`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Stage failed`)}finally{N(!1)}}},U=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/unstage`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Unstage failed`)}finally{N(!1)}}},W=async e=>{if(n){N(!0);try{await m.post(`${p(n)}/git/discard`,{files:e}),await V()}catch(e){k(e instanceof Error?e.message:`Discard failed`)}finally{N(!1)}}},G=async()=>{F&&(await W(F.files),I(null))},K=async()=>{if(!(!n||!A.trim()||!r?.staged.length)){N(!0);try{await m.post(`${p(n)}/git/commit`,{message:A.trim()}),j(``),await V()}catch(e){k(e instanceof Error?e.message:`Commit failed`)}finally{N(!1)}}},q=async()=>{if(n){N(!0);try{await m.post(`${p(n)}/git/push`,{}),await V()}catch(e){k(e instanceof Error?e.message:`Push failed`)}finally{N(!1)}}},J=async()=>{if(n){N(!0);try{await m.post(`${p(n)}/git/pull`,{}),await V()}catch(e){k(e instanceof Error?e.message:`Pull failed`)}finally{N(!1)}}},Y=e=>{L({type:`git-diff`,title:e.path.split(`/`).pop()??e.path,closable:!0,metadata:{projectName:n,filePath:e.path},projectId:n??null})},X=e=>{L({type:`editor`,title:e.path.split(`/`).pop()??e.path,closable:!0,metadata:{projectName:n,filePath:e.path},projectId:n??null})},Z=(0,D.useMemo)(()=>[...r?.unstaged??[],...r?.untracked.map(e=>({path:e,status:`?`}))??[]],[r]);return n?g&&!r?(0,O.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,O.jsx)(v,{className:`size-5 animate-spin`}),(0,O.jsx)(`span`,{className:`text-sm`,children:`Loading git status...`})]}):E&&!r?(0,O.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,O.jsx)(`p`,{children:E}),(0,O.jsx)(i,{variant:`outline`,size:`sm`,onClick:V,children:`Retry`})]}):(0,O.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b shrink-0`,children:[(0,O.jsx)(`span`,{className:`text-sm font-medium`,children:r?.current?`On: ${r.current}`:`Git Status`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(i,{variant:z===`flat`?`secondary`:`ghost`,size:`icon-xs`,onClick:()=>B(`flat`),title:`Flat view`,children:(0,O.jsx)(w,{className:`size-3.5`})}),(0,O.jsx)(i,{variant:z===`tree`?`secondary`:`ghost`,size:`icon-xs`,onClick:()=>B(`tree`),title:`Tree view`,children:(0,O.jsx)(C,{className:`size-3.5`})}),(0,O.jsx)(i,{variant:`ghost`,size:`icon-xs`,onClick:V,disabled:M,children:(0,O.jsx)(o,{className:g?`animate-spin`:``})})]})]}),E&&(0,O.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0`,children:E}),(0,O.jsx)(x,{className:`flex-1 overflow-hidden`,children:(0,O.jsxs)(`div`,{className:`p-2 space-y-3 overflow-hidden`,children:[(0,O.jsx)(P,{title:`Staged Changes`,count:r?.staged.length??0,files:r?.staged??[],viewMode:z,actionIcon:(0,O.jsx)(T,{className:`size-3.5`}),actionTitle:`Unstage`,onAction:e=>U([e.path]),onActionAll:r?.staged.length?()=>U(r.staged.map(e=>e.path)):void 0,actionAllLabel:`Unstage All`,onFolderAction:e=>U(e.map(e=>e.path)),onClickFile:Y,onOpenFile:X,disabled:M}),(0,O.jsx)(P,{title:`Changes`,count:Z.length,files:Z,viewMode:z,actionIcon:(0,O.jsx)(y,{className:`size-3.5`}),actionTitle:`Stage`,onAction:e=>H([e.path]),onActionAll:Z.length?()=>H(Z.map(e=>e.path)):void 0,actionAllLabel:`Stage All`,onFolderAction:e=>H(e.map(e=>e.path)),onClickFile:Y,onOpenFile:X,disabled:M,showRevert:!0,onRevert:e=>I({label:e.path,files:[e.path]}),onFolderRevert:(e,t)=>I({label:`${t}/ (${e.length} files)`,files:e.map(e=>e.path)})})]})}),(0,O.jsxs)(`div`,{className:`border-t p-2 space-y-2 shrink-0`,children:[(0,O.jsx)(`textarea`,{className:`w-full h-16 px-3 py-2 text-base md:text-sm text-foreground bg-surface border border-border rounded-lg resize-none focus:outline-none focus:border-ring placeholder:text-muted-foreground`,placeholder:`Commit message...`,value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&K()}}),(0,O.jsx)(i,{size:`sm`,className:`w-full`,disabled:M||!A.trim()||!r?.staged.length,onClick:K,children:M?(0,O.jsx)(v,{className:`size-3 animate-spin`}):`Commit (${r?.staged.length??0})`}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(i,{variant:`outline`,size:`sm`,className:`flex-1`,disabled:M,onClick:q,children:[(0,O.jsx)(a,{className:`size-3`}),`Push`]}),(0,O.jsxs)(i,{variant:`outline`,size:`sm`,className:`flex-1`,disabled:M,onClick:J,children:[(0,O.jsx)(S,{className:`size-3`}),`Pull`]})]})]}),(0,O.jsx)(f,{open:!!F,onOpenChange:e=>!e&&I(null),children:(0,O.jsxs)(l,{showCloseButton:!1,children:[(0,O.jsxs)(s,{children:[(0,O.jsx)(u,{children:`Discard Changes`}),(0,O.jsxs)(d,{children:[`Are you sure you want to discard all changes to`,` `,(0,O.jsx)(`code`,{className:`px-1 py-0.5 rounded bg-muted text-sm font-mono`,children:F?.label}),`? This action cannot be undone.`]})]}),(0,O.jsxs)(c,{children:[(0,O.jsx)(i,{variant:`outline`,onClick:()=>I(null),children:`Cancel`}),(0,O.jsx)(i,{variant:`destructive`,onClick:G,disabled:M,children:M?(0,O.jsx)(v,{className:`size-3 animate-spin`}):`Discard`})]})]})})]}):(0,O.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`})}function N({showRevert:e,onRevert:t,onAction:n,onOpenFile:r,actionIcon:i,actionTitle:a,disabled:o}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0 ml-1`,children:[r&&(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-primary/15 hover:text-primary hover:border-primary/40 active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),r()},disabled:o,title:`Open file`,children:(0,O.jsx)(_,{className:`size-3.5`})}),e&&t&&(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-destructive/15 hover:text-destructive hover:border-destructive/40 active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),t()},disabled:o,title:`Discard changes`,children:(0,O.jsx)(E,{className:`size-3.5`})}),(0,O.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-7 rounded border border-border/60 bg-muted/60 text-muted-foreground hover:bg-accent hover:text-accent-foreground active:scale-95 transition-colors`,onClick:e=>{e.stopPropagation(),n()},disabled:o,title:a,children:i})]})}function P({title:e,count:t,files:n,viewMode:r,actionIcon:a,actionTitle:o,onAction:s,onActionAll:c,actionAllLabel:l,onFolderAction:u,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h,onFolderRevert:g}){return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,O.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase`,children:[e,` (`,t,`)`]}),c&&t>0&&(0,O.jsx)(i,{variant:`ghost`,size:`xs`,onClick:c,disabled:p,title:l,children:l})]}),n.length===0?(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground px-1`,children:`No changes`}):r===`flat`?(0,O.jsx)(`div`,{className:`divide-y divide-border/40 w-full overflow-hidden`,children:n.map(e=>(0,O.jsx)(F,{file:e,actionIcon:a,actionTitle:o,onAction:s,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h},e.path))}):(0,O.jsx)(I,{files:n,actionIcon:a,actionTitle:o,onAction:s,onFolderAction:u,onClickFile:d,onOpenFile:f,disabled:p,showRevert:m,onRevert:h,onFolderRevert:g})]})}function F({file:e,actionIcon:t,actionTitle:n,onAction:r,onClickFile:i,onOpenFile:a,disabled:o,showRevert:s,onRevert:c,displayName:l}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-muted/50 rounded px-1 py-1 w-full min-w-0`,children:[(0,O.jsx)(`span`,{className:`text-xs font-mono w-4 text-center shrink-0 ${k[e.status]??``}`,children:e.status}),(0,O.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-xs font-mono truncate hover:underline min-w-0`,onClick:()=>i(e),title:e.path,children:l??e.path}),(0,O.jsx)(N,{showRevert:s,onRevert:c?()=>c(e):void 0,onOpenFile:a?()=>a(e):void 0,onAction:()=>r(e),actionIcon:t,actionTitle:n,disabled:o})]})}function I({files:e,actionIcon:t,actionTitle:n,onAction:r,onFolderAction:i,onClickFile:a,onOpenFile:o,disabled:s,showRevert:c,onRevert:l,onFolderRevert:u}){let d=(0,D.useMemo)(()=>A(e),[e]);return(0,O.jsx)(`div`,{children:d.map((e,f)=>(0,O.jsx)(L,{node:e,depth:0,isLast:f===d.length-1,actionIcon:t,actionTitle:n,onAction:r,onFolderAction:i,onClickFile:a,onOpenFile:o,disabled:s,showRevert:c,onRevert:l,onFolderRevert:u},e.fullPath))})}function L({node:e,depth:t,isLast:n,actionIcon:r,actionTitle:i,onAction:a,onFolderAction:o,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d,onFolderRevert:f}){let[p,m]=(0,D.useState)(!0),_=e.children.length>0&&!e.file;if(e.file)return(0,O.jsxs)(`div`,{className:`relative overflow-hidden border-b border-border/30`,style:{paddingLeft:t*16},children:[t>0&&(0,O.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-border/30`,style:{left:t*16-8}}),(0,O.jsx)(F,{file:e.file,displayName:e.name,actionIcon:r,actionTitle:i,onAction:a,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d})]});if(_){let _=j(e);return(0,O.jsxs)(`div`,{className:`relative overflow-hidden`,children:[t>0&&(0,O.jsx)(`div`,{className:`absolute top-0 border-l border-border/30`,style:{left:t*16-8,bottom:n?`50%`:0}}),(0,O.jsxs)(`div`,{className:`flex items-center hover:bg-muted/50 rounded py-1 pr-1 border-b border-border/30`,style:{paddingLeft:t*16+4},children:[(0,O.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 flex-1 min-w-0 text-xs font-mono text-muted-foreground`,onClick:()=>m(!p),children:[p?(0,O.jsx)(h,{className:`size-3.5 shrink-0`}):(0,O.jsx)(g,{className:`size-3.5 shrink-0`}),(0,O.jsx)(`span`,{className:`truncate font-semibold`,children:e.name}),(0,O.jsxs)(`span`,{className:`text-[10px] opacity-60 shrink-0`,children:[`(`,_.length,`)`]})]}),(0,O.jsx)(N,{showRevert:u,onRevert:f?()=>f(_,e.fullPath):void 0,onAction:()=>o?.(_),actionIcon:r,actionTitle:`${i} ${e.name}/`,disabled:l})]}),p&&(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-border/30`,style:{left:t*16+8}}),e.children.map((n,p)=>(0,O.jsx)(L,{node:n,depth:t+1,isLast:p===e.children.length-1,actionIcon:r,actionTitle:i,onAction:a,onFolderAction:o,onClickFile:s,onOpenFile:c,disabled:l,showRevert:u,onRevert:d,onFolderRevert:f},n.fullPath))]})]})}return null}export{M as GitStatusPanel};
|