@hienlh/ppm 0.2.14 → 0.2.16
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-Cpj7_-mS.js +6 -0
- package/dist/web/assets/{code-editor-By4DdmcK.js → code-editor-BauDrXcB.js} +2 -2
- package/dist/web/assets/{diff-viewer-DYT0hdt6.js → diff-viewer-CGIQRv_l.js} +1 -1
- package/dist/web/assets/{git-graph-DAkezMN2.js → git-graph-D4IUX9-7.js} +1 -1
- package/dist/web/assets/{git-status-panel-B16U4gnS.js → git-status-panel-B_iCL1Ge.js} +1 -1
- package/dist/web/assets/{index-BCr_P7dc.js → index-DOHQ7GlD.js} +4 -4
- package/dist/web/assets/index-Jhl6F2vS.css +2 -0
- package/dist/web/assets/project-list-7ReggIMy.js +1 -0
- package/dist/web/assets/settings-tab-Ceuow24i.js +1 -0
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/providers/claude-agent-sdk.ts +2 -2
- package/src/web/components/chat/chat-tab.tsx +49 -3
- package/src/web/lib/report-bug.ts +26 -4
- package/dist/web/assets/chat-tab-7VPMitNF.js +0 -6
- package/dist/web/assets/index-VXI-SRG0.css +0 -2
- package/dist/web/assets/project-list-DyqilVEl.js +0 -1
- package/dist/web/assets/settings-tab-B7-ur4hu.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./columns-2-DsiY76NQ.js";import{r as a,t as o}from"./api-client-tgjN9Mx8.js";import{v as s,w as c}from"./index-BCr_P7dc.js";import{A as l,E as u,H as d,I as f,O as p,Q as m,Y as h,a as g,at as _,ct as v,et as ee,i as y,it as b,j as x,k as S,n as C,nt as te,o as w,ot as T,r as E,rt as D,s as ne,st as O,t as k}from"./dist-BeHIxUn0.js";var re=t(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),ie=t(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),A=e(n(),1),j=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}offset(t,n=t){return new e(this.fromA+t,this.toA+t,this.fromB+n,this.toB+n)}};function M(e,t,n,r,i,a){if(e==r)return[];let o=R(e,t,n,r,i,a),s=z(e,t+o,n,r,i+o,a);t+=o,n-=s,i+=o,a-=s;let c=n-t,l=a-i;if(!c||!l)return[new j(t,n,i,a)];if(c>l){let o=e.slice(t,n).indexOf(r.slice(i,a));if(o>-1)return[new j(t,t+o,i,i),new j(t+o+l,n,a,a)]}else if(l>c){let o=r.slice(i,a).indexOf(e.slice(t,n));if(o>-1)return[new j(t,t,i,i+o),new j(n,n,i+o+c,a)]}if(c==1||l==1)return[new j(t,n,i,a)];let u=le(e,t,n,r,i,a);if(u){let[o,s,c]=u;return M(e,t,o,r,i,s).concat(M(e,o+c,n,r,s+c,a))}return ae(e,t,n,r,i,a)}var N=1e9,P=0,F=!1;function ae(e,t,n,r,i,a){let o=n-t,s=a-i;if(N<1e9&&Math.min(o,s)>N*16||P>0&&Date.now()>P)return Math.min(o,s)>N*64?[new j(t,n,i,a)]:ue(e,t,n,r,i,a);let c=Math.ceil((o+s)/2);I.reset(c),L.reset(c);let l=(n,a)=>e.charCodeAt(t+n)==r.charCodeAt(i+a),u=(t,i)=>e.charCodeAt(n-t-1)==r.charCodeAt(a-i-1),d=(o-s)%2==0?null:L,f=d?null:I;for(let p=0;p<c;p++){if(p>N||P>0&&!(p&63)&&Date.now()>P)return ue(e,t,n,r,i,a);let m=I.advance(p,o,s,c,d,!1,l)||L.advance(p,o,s,c,f,!0,u);if(m)return se(e,t,n,t+m[0],r,i,a,i+m[1])}return[new j(t,n,i,a)]}var oe=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let e=0;e<this.len;e++)this.vec[e]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,n,r,i,a,o){for(let s=-e+this.start;s<=e-this.end;s+=2){let c=r+s,l=s==-e||s!=e&&this.vec[c-1]<this.vec[c+1]?this.vec[c+1]:this.vec[c-1]+1,u=l-s;for(;l<t&&u<n&&o(l,u);)l++,u++;if(this.vec[c]=l,l>t)this.end+=2;else if(u>n)this.start+=2;else if(i){let e=r+(t-n)-s;if(e>=0&&e<this.len&&i.vec[e]!=-1)if(a){let n=i.vec[e];if(n>=t-l)return[n,r+n-e]}else{let n=t-i.vec[e];if(l>=n)return[l,u]}}}return null}},I=new oe,L=new oe;function se(e,t,n,r,i,a,o,s){let c=!1;return!H(e,r)&&++r==n&&(c=!0),!H(i,s)&&++s==o&&(c=!0),c?[new j(t,n,a,o)]:M(e,t,r,i,a,s).concat(M(e,r,n,i,s,o))}function ce(e,t){let n=1,r=Math.min(e,t);for(;n<r;)n<<=1;return n}function R(e,t,n,r,i,a){if(t==n||t==a||e.charCodeAt(t)!=r.charCodeAt(i))return 0;let o=ce(n-t,a-i);for(let s=t,c=i;;){let i=s+o,l=c+o;if(i>n||l>a||e.slice(s,i)!=r.slice(c,l)){if(o==1)return s-t-(H(e,s)?0:1);o>>=1}else if(i==n||l==a)return i-t;else s=i,c=l}}function z(e,t,n,r,i,a){if(t==n||i==a||e.charCodeAt(n-1)!=r.charCodeAt(a-1))return 0;let o=ce(n-t,a-i);for(let s=n,c=a;;){let a=s-o,l=c-o;if(a<t||l<i||e.slice(a,s)!=r.slice(l,c)){if(o==1)return n-s-(H(e,s)?0:1);o>>=1}else if(a==t||l==i)return n-a;else s=a,c=l}}function B(e,t,n,r,i,a,o,s){let c=r.slice(i,a),l=null;for(;;){if(l||o<s)return l;for(let s=t+o;;){H(e,s)||s++;let u=s+o;if(H(e,u)||(u+=u==s+1?1:-1),u>=n)break;let d=e.slice(s,u),f=-1;for(;(f=c.indexOf(d,f+1))!=-1;){let o=R(e,u,n,r,i+f+d.length,a),c=z(e,t,s,r,i,i+f),p=d.length+o+c;(!l||l[2]<p)&&(l=[s-c,i+f-c,p])}s=u}if(s<0)return l;o>>=1}}function le(e,t,n,r,i,a){let o=n-t,s=a-i;if(o<s){let o=le(r,i,a,e,t,n);return o&&[o[1],o[0],o[2]]}return o<4||s*2<o?null:B(e,t,n,r,i,a,Math.floor(o/4),-1)}function ue(e,t,n,r,i,a){F=!0;let o=n-t,s=a-i,c;if(o<s){let s=B(r,i,a,e,t,n,Math.floor(o/6),50);c=s&&[s[1],s[0],s[2]]}else c=B(e,t,n,r,i,a,Math.floor(s/6),50);if(!c)return[new j(t,n,i,a)];let[l,u,d]=c;return M(e,t,l,r,i,u).concat(M(e,l+d,n,r,u+d,a))}function de(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n];r.toA>i.fromA-t&&r.toB>i.fromB-t&&(e[n-1]=new j(r.fromA,i.toA,r.fromB,i.toB),e.splice(n--,1))}}function fe(e,t,n){for(;;){de(n,1);let r=!1;for(let i=0;i<n.length;i++){let a=n[i],o,s;(o=R(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new j(a.fromA+o,a.toA,a.fromB+o,a.toB)),(s=z(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new j(a.fromA,a.toA-s,a.fromB,a.toB-s));let c=a.toA-a.fromA,l=a.toB-a.fromB;if(c&&l)continue;let u=a.fromA-(i?n[i-1].toA:0),d=(i<n.length-1?n[i+1].fromA:e.length)-a.toA;if(!u||!d)continue;let f=c?e.slice(a.fromA,a.toA):t.slice(a.fromB,a.toB);u<=f.length&&e.slice(a.fromA-u,a.fromA)==f.slice(f.length-u)?(n[i]=new j(a.fromA-u,a.toA-u,a.fromB-u,a.toB-u),r=!0):d<=f.length&&e.slice(a.toA,a.toA+d)==f.slice(0,d)&&(n[i]=new j(a.fromA+d,a.toA+d,a.fromB+d,a.toB+d),r=!0)}if(!r)break}return n}function pe(e,t,n){for(let r=0,i=0;i<e.length;i++){let a=e[i],o=a.toA-a.fromA,s=a.toB-a.fromB;if(o&&s||o>3||s>3){let c=i==e.length-1?t.length:e[i+1].fromA,l=a.fromA-r,u=c-a.toA,d=ye(t,a.fromA,l),f=ve(t,a.toA,u),p=a.fromA-d,m=f-a.toA;if((!o||!s)&&p&&m){let l=Math.max(o,s),[u,h,g]=o?[t,a.fromA,a.toA]:[n,a.fromB,a.toB];l>p&&t.slice(d,a.fromA)==u.slice(g-p,g)?(a=e[i]=new j(d,d+o,a.fromB-p,a.toB-p),d=a.fromA,f=ve(t,a.toA,c-a.toA)):l>m&&t.slice(a.toA,f)==u.slice(h,h+m)&&(a=e[i]=new j(f-o,f,a.fromB+m,a.toB+m),f=a.toA,d=ye(t,a.fromA,a.fromA-r)),p=a.fromA-d,m=f-a.toA}if(p||m)a=e[i]=new j(a.fromA-p,a.toA+m,a.fromB-p,a.toB+m);else if(!o){let t=xe(n,a.fromB,a.toB),r,o=t<0?-1:be(n,a.toB,a.fromB);t>-1&&(r=t-a.fromB)<=u&&n.slice(a.fromB,t)==n.slice(a.toB,a.toB+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toB-o)<=l&&n.slice(a.fromB-r,a.fromB)==n.slice(o,a.toB)&&(a=e[i]=a.offset(-r))}else if(!s){let n=xe(t,a.fromA,a.toA),r,o=n<0?-1:be(t,a.toA,a.fromA);n>-1&&(r=n-a.fromA)<=u&&t.slice(a.fromA,n)==t.slice(a.toA,a.toA+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toA-o)<=l&&t.slice(a.fromA-r,a.fromA)==t.slice(o,a.toA)&&(a=e[i]=a.offset(-r))}}r=a.toA}return de(e,3),e}var V;try{V=RegExp(`[\\p{Alphabetic}\\p{Number}]`,`u`)}catch{}function me(e){return e>48&&e<58||e>64&&e<91||e>96&&e<123}function he(e,t){if(t==e.length)return 0;let n=e.charCodeAt(t);return n<192?me(n)?1:0:V?!Se(n)||t==e.length-1?V.test(String.fromCharCode(n))?1:0:V.test(e.slice(t,t+2))?2:0:0}function ge(e,t){if(!t)return 0;let n=e.charCodeAt(t-1);return n<192?me(n)?1:0:V?!Ce(n)||t==1?V.test(String.fromCharCode(n))?1:0:V.test(e.slice(t-2,t))?2:0:0}var _e=8;function ve(e,t,n){if(t==e.length||!ge(e,t))return t;for(let r=t,i=t+n,a=0;a<_e;a++){let t=he(e,r);if(!t||r+t>i)return r;r+=t}return t}function ye(e,t,n){if(!t||!he(e,t))return t;for(let r=t,i=t-n,a=0;a<_e;a++){let t=ge(e,r);if(!t||r-t<i)return r;r-=t}return t}function be(e,t,n){for(;t!=n;t--)if(e.charCodeAt(t-1)==10)return t;return-1}function xe(e,t,n){for(;t!=n;t++)if(e.charCodeAt(t)==10)return t;return-1}var Se=e=>e>=55296&&e<=56319,Ce=e=>e>=56320&&e<=57343;function H(e,t){return!t||t==e.length||!Se(e.charCodeAt(t-1))||!Ce(e.charCodeAt(t))}function we(e,t,n){let r=n?.override;return r?r(e,t):(N=(n?.scanLimit??1e9)>>1,P=n?.timeout?Date.now()+n.timeout:0,F=!1,fe(e,t,M(e,0,e.length,t,0,t.length)))}function Te(){return!F}function Ee(e,t,n){return pe(we(e,t,n),e,t)}var U=D.define({combine:e=>e[0]}),De=O.define(),Oe=D.define(),W=v.define({create(e){return null},update(e,t){for(let n of t.effects)n.is(De)&&(e=n.value);for(let n of t.state.facet(Oe))e=n(e,t);return e}}),G=class e{constructor(e,t,n,r,i,a=!0){this.changes=e,this.fromA=t,this.toA=n,this.fromB=r,this.toB=i,this.precise=a}offset(t,n){return t||n?new e(this.changes,this.fromA+t,this.toA+t,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,n){return je(Ee(e.toString(),t.toString(),n),e,t,0,0,Te())}static updateA(e,t,n,r,i){return Pe(Ne(e,r,!0,n.length),e,t,n,i)}static updateB(e,t,n,r,i){return Pe(Ne(e,r,!1,t.length),e,t,n,i)}};function ke(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.to==e&&a.to==t&&e<n.length&&t<r.length?[e+1,t+1]:[i.from,a.from]}function Ae(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.from==e&&a.from==t?[e,t]:[i.to+1,a.to+1]}function je(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=e[s],[l,u]=ke(c.fromA+r,c.fromB+i,t,n),[d,f]=Ae(c.toA+r,c.toB+i,t,n),p=[c.offset(-l+r,-u+i)];for(;s<e.length-1;){let a=e[s+1],[o,c]=ke(a.fromA+r,a.fromB+i,t,n);if(o>d+1&&c>f+1)break;p.push(a.offset(-l+r,-u+i)),[d,f]=Ae(a.toA+r,a.toB+i,t,n),s++}o.push(new G(p,l,Math.max(l,d),u,Math.max(u,f),a))}return o}var K=1e3;function Me(e,t,n,r){let i=0,a=e.length;for(;;){if(i==a){let r=0,a=0;i&&({toA:r,toB:a}=e[i-1]);let o=t-(n?r:a);return[r+o,a+o]}let o=i+a>>1,s=e[o],[c,l]=n?[s.fromA,s.toA]:[s.fromB,s.toB];if(c>t)a=o;else if(l<=t)i=o+1;else return r?[s.fromA,s.fromB]:[s.toA,s.toB]}}function Ne(e,t,n,r){let i=[];return t.iterChangedRanges((a,o,s,c)=>{let l=0,u=n?t.length:r,d=0,f=n?r:t.length;a>K&&([l,d]=Me(e,a-K,n,!0)),o<t.length-K&&([u,f]=Me(e,o+K,n,!1));let p=c-s-(o-a),m,[h,g]=n?[p,0]:[0,p];i.length&&(m=i[i.length-1]).toA>=l?i[i.length-1]={fromA:m.fromA,fromB:m.fromB,toA:u,toB:f,diffA:m.diffA+h,diffB:m.diffB+g}:i.push({fromA:l,toA:u,fromB:d,toB:f,diffA:h,diffB:g})}),i}function Pe(e,t,n,r,i){if(!e.length)return t;let a=[];for(let o=0,s=0,c=0,l=0;;o++){let u=o==e.length?null:e[o],d=u?u.fromA+s:n.length,f=u?u.fromB+c:r.length;for(;l<t.length;){let e=t[l];if(u&&(e.toA+s>d||e.toB+c>f))break;a.push(e.offset(s,c)),l++}if(!u)break;let p=u.toA+s+u.diffA,m=u.toB+c+u.diffB,h=Ee(n.sliceString(d,p),r.sliceString(f,m),i);for(let e of je(h,n,r,d,f,Te()))a.push(e);for(s+=u.diffA,c+=u.diffB;l<t.length;){let e=t[l];if(e.fromA+s>p&&e.fromB+c>m)break;l++}}return a}var Fe={scanLimit:500},Ie=l.fromClass(class{constructor(e){({deco:this.deco,gutter:this.gutter}=Ge(e))}update(e){(e.docChanged||e.viewportChanged||Le(e.startState,e.state)||Re(e.startState,e.state))&&({deco:this.deco,gutter:this.gutter}=Ge(e.view))}},{decorations:e=>e.deco}),q=b.low(f({class:`cm-changeGutter`,markers:e=>e.plugin(Ie)?.gutter||_.empty}));function Le(e,t){return e.field(W,!1)!=t.field(W,!1)}function Re(e,t){return e.facet(U)!=t.facet(U)}var ze=u.line({class:`cm-changedLine`}),Be=u.mark({class:`cm-changedText`}),Ve=u.mark({tagName:`ins`,class:`cm-insertedLine`}),He=u.mark({tagName:`del`,class:`cm-deletedLine`}),Ue=new class extends S{constructor(){super(...arguments),this.elementClass=`cm-changedLineGutter`}};function We(e,t,n,r,i,a){let o=n?e.fromA:e.fromB,s=n?e.toA:e.toB,c=0;if(o!=s){i.add(o,o,ze),i.add(o,s,n?He:Ve),a&&a.add(o,o,Ue);for(let l=t.iterRange(o,s-1),u=o;!l.next().done;){if(l.lineBreak){u++,i.add(u,u,ze),a&&a.add(u,u,Ue);continue}let t=u+l.value.length;if(r)for(;c<e.changes.length;){let r=e.changes[c],a=o+(n?r.fromA:r.fromB),s=o+(n?r.toA:r.toB),l=Math.max(u,a),d=Math.min(t,s);if(l<d&&i.add(l,d,Be),s<t)c++;else break}u=t}}}function Ge(e){let t=e.state.field(W),{side:n,highlightChanges:r,markGutter:i,overrideChunk:a}=e.state.facet(U),o=n==`a`,s=new T,c=i?new T:null,{from:l,to:u}=e.viewport;for(let n of t){if((o?n.fromA:n.fromB)>=u)break;(o?n.toA:n.toB)>l&&(!a||!a(e.state,n,s,c))&&We(n,e.state.doc,o,r,s,c)}return{deco:s.finish(),gutter:c&&c.finish()}}var J=class extends x{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement(`div`);return e.className=`cm-mergeSpacer`,e.style.height=this.height+`px`,e}updateDOM(e){return e.style.height=this.height+`px`,!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},Y=O.define({map:(e,t)=>e.map(t)}),X=v.define({create:()=>u.none,update:(e,t)=>{for(let e of t.effects)if(e.is(Y))return e.value;return e.map(t.changes)},provide:e=>p.decorations.from(e)}),Z=.01;function Ke(e,t){if(e.size!=t.size)return!1;let n=e.iter(),r=t.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function qe(e,t,n){let r=new T,i=new T,a=e.state.field(X).iter(),o=t.state.field(X).iter(),s=0,c=0,l=0,d=0,f=e.viewport,p=t.viewport;for(let m=0;;m++){let h=m<n.length?n[m]:null,g=h?h.fromA:e.state.doc.length,_=h?h.fromB:t.state.doc.length;if(s<g){let n=e.lineBlockAt(s).top+l-(t.lineBlockAt(c).top+d);n<-Z?(l-=n,r.add(s,s,u.widget({widget:new J(-n),block:!0,side:-1}))):n>Z&&(d+=n,i.add(c,c,u.widget({widget:new J(n),block:!0,side:-1})))}if(g>s+1e3&&s<f.from&&g>f.from&&c<p.from&&_>p.from){let e=Math.min(f.from-s,p.from-c);s+=e,c+=e,m--}else if(h)s=h.toA,c=h.toB;else break;for(;a.value&&a.from<s;)l-=a.value.spec.widget.height,a.next();for(;o.value&&o.from<c;)d-=o.value.spec.widget.height,o.next()}for(;a.value;)l-=a.value.spec.widget.height,a.next();for(;o.value;)d-=o.value.spec.widget.height,o.next();let m=e.contentHeight+l-(t.contentHeight+d);m<Z?r.add(e.state.doc.length,e.state.doc.length,u.widget({widget:new J(-m),block:!0,side:1})):m>Z&&i.add(t.state.doc.length,t.state.doc.length,u.widget({widget:new J(m),block:!0,side:1}));let h=r.finish(),g=i.finish();Ke(h,e.state.field(X))||e.dispatch({effects:Y.of(h)}),Ke(g,t.state.field(X))||t.dispatch({effects:Y.of(g)})}var Je=O.define({map:(e,t)=>t.mapPos(e)}),Ye=class extends x{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement(`div`);return t.className=`cm-collapsedLines`,t.textContent=e.state.phrase(`$ unchanged lines`,this.lines),t.addEventListener(`click`,t=>{let n=e.posAtDOM(t.target);e.dispatch({effects:Je.of(n)});let{side:r,sibling:i}=e.state.facet(U);i&&i().dispatch({effects:Je.of(Xe(n,e.state.field(W),r==`a`))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return`collapsed-unchanged-code`}};function Xe(e,t,n){let r=0,i=0;for(let a=0;;a++){let o=a<t.length?t[a]:null;if(!o||(n?o.fromA:o.fromB)>=e)return i+(e-r);[r,i]=n?[o.toA,o.toB]:[o.toB,o.toA]}}var Ze=v.define({create(e){return u.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Je)&&(e=e.update({filter:e=>e!=n.value}));return e},provide:e=>p.decorations.from(e)});function Qe({margin:e=3,minSize:t=4}){return Ze.init(n=>$e(n,e,t))}function $e(e,t,n){let r=new T,i=e.facet(U).side==`a`,a=e.field(W),o=1;for(let s=0;;s++){let c=s<a.length?a[s]:null,l=s?o+t:1,d=c?e.doc.lineAt(i?c.fromA:c.fromB).number-1-t:e.doc.lines,f=d-l+1;if(f>=n&&r.add(e.doc.line(l).from,e.doc.line(d).to,u.replace({widget:new Ye(f),block:!0})),!c)break;o=e.doc.lineAt(Math.min(e.doc.length,i?c.toA:c.toB)).number}return r.finish()}var et=p.styleModule.of(new h({".cm-mergeView":{overflowY:`auto`},".cm-mergeViewEditors":{display:`flex`,alignItems:`stretch`},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:`hidden`},".cm-merge-revert":{width:`1.6em`,flexGrow:0,flexShrink:0,position:`relative`},".cm-merge-revert button":{position:`absolute`,display:`block`,width:`100%`,boxSizing:`border-box`,textAlign:`center`,background:`none`,border:`none`,font:`inherit`,cursor:`pointer`}})),tt=p.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:`auto !important`,overflowY:`visible !important`},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:`rgba(160, 128, 100, .08)`},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:`rgba(100, 160, 128, .08)`},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat`},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat`},"&light.cm-merge-b .cm-changedText":{background:`linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat`},"&dark.cm-merge-b .cm-changedText":{background:`linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat`},"&.cm-merge-b .cm-deletedText":{background:`#ff000033`},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:`none`},".cm-deletedChunk":{paddingLeft:`6px`,"& .cm-chunkButtons":{position:`absolute`,insetInlineEnd:`5px`},"& button":{border:`none`,cursor:`pointer`,color:`white`,margin:`0 2px`,borderRadius:`3px`,"&[name=accept]":{background:`#2a2`},"&[name=reject]":{background:`#d43`}}},".cm-collapsedLines":{padding:`5px 5px 5px 10px`,cursor:`pointer`,"&:before":{content:`"⦚"`,marginInlineEnd:`7px`},"&:after":{content:`"⦚"`,marginInlineStart:`7px`}},"&light .cm-collapsedLines":{color:`#444`,background:`linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)`},"&dark .cm-collapsedLines":{color:`#ddd`,background:`linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)`},".cm-changeGutter":{width:`3px`,paddingLeft:`1px`},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:`#e43`},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:`#fa9`},"&light.cm-merge-b .cm-changedLineGutter":{background:`#2b2`},"&dark.cm-merge-b .cm-changedLineGutter":{background:`#8f8`},".cm-inlineChangedLineGutter":{background:`#75d`}}),nt=new ee,Q=new ee,rt=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||Fe;let t=[b.low(Ie),tt,et,X,p.updateListener.of(e=>{this.measuring<0&&(e.heightChanged||e.viewportChanged)&&!e.transactions.some(e=>e.effects.some(e=>e.is(Y)))&&this.measure()})],n=[U.of({side:`a`,sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&n.push(q);let r=te.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],p.editorAttributes.of({class:`cm-merge-a`}),Q.of(n),t]}),i=[U.of({side:`b`,sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&i.push(q);let a=te.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],p.editorAttributes.of({class:`cm-merge-b`}),Q.of(i),t]});this.chunks=G.build(r.doc,a.doc,this.diffConf);let o=[W.init(()=>this.chunks),nt.of(e.collapseUnchanged?Qe(e.collapseUnchanged):[])];r=r.update({effects:O.appendConfig.of(o)}).state,a=a.update({effects:O.appendConfig.of(o)}).state,this.dom=document.createElement(`div`),this.dom.className=`cm-mergeView`,this.editorDOM=this.dom.appendChild(document.createElement(`div`)),this.editorDOM.className=`cm-mergeViewEditors`;let s=e.orientation||`a-b`,c=document.createElement(`div`);c.className=`cm-mergeViewEditor`;let l=document.createElement(`div`);l.className=`cm-mergeViewEditor`,this.editorDOM.appendChild(s==`a-b`?c:l),this.editorDOM.appendChild(s==`a-b`?l:c),this.a=new p({state:r,parent:c,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.a)}),this.b=new p({state:a,parent:l,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls==`b-to-a`,e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(e=>e.docChanged)){let n=e[e.length-1],r=e.reduce((e,t)=>e.compose(t.changes),m.empty(e[0].startState.doc.length));this.chunks=t==this.a?G.updateA(this.chunks,n.newDoc,this.b.state.doc,r,this.diffConf):G.updateB(this.chunks,this.a.state.doc,n.newDoc,r,this.diffConf),t.update([...e,n.state.update({effects:De.of(this.chunks)})]);let i=t==this.a?this.b:this.a;i.update([i.state.update({effects:De.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if(`diffConfig`in e&&(this.diffConf=e.diffConfig),`orientation`in e){let t=e.orientation!=`b-a`;if(t!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let e=this.a.dom.parentNode,n=this.b.dom.parentNode;e.remove(),n.remove(),this.editorDOM.insertBefore(t?e:n,this.editorDOM.firstChild),this.editorDOM.appendChild(t?n:e),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent=``)}}if(`revertControls`in e||`renderRevertControl`in e){let t=!!this.revertDOM,n=this.revertToA,r=this.renderRevert;`revertControls`in e&&(t=!!e.revertControls,n=e.revertControls==`b-to-a`),`renderRevertControl`in e&&(r=e.renderRevertControl),this.setupRevertControls(t,n,r)}let t=`highlightChanges`in e,n=`gutter`in e,r=`collapseUnchanged`in e;if(t||n||r){let i=[],a=[];if(t||n){let r=this.a.state.facet(U),o=n?e.gutter!==!1:r.markGutter,s=t?e.highlightChanges!==!1:r.highlightChanges;i.push(Q.reconfigure([U.of({side:`a`,sibling:()=>this.b,highlightChanges:s,markGutter:o}),o?q:[]])),a.push(Q.reconfigure([U.of({side:`b`,sibling:()=>this.a,highlightChanges:s,markGutter:o}),o?q:[]]))}if(r){let t=nt.reconfigure(e.collapseUnchanged?Qe(e.collapseUnchanged):[]);i.push(t),a.push(t)}this.a.dispatch({effects:i}),this.b.dispatch({effects:a})}this.scheduleMeasure()}setupRevertControls(e,t,n){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=n,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement(`div`),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener(`mousedown`,e=>this.revertClicked(e)),this.revertDOM.className=`cm-merge-revert`):this.revertDOM&&(this.revertDOM.textContent=``)}scheduleMeasure(){this.measuring<0&&(this.measuring=(this.dom.ownerDocument.defaultView||window).requestAnimationFrame(()=>{this.measuring=-1,this.measure()}))}measure(){qe(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,n=this.a.viewport,r=this.b.viewport;for(let i=0;i<this.chunks.length;i++){let a=this.chunks[i];if(a.fromA>n.to||a.fromB>r.to)break;if(a.fromA<n.from||a.fromB<r.from)continue;let o=this.a.lineBlockAt(a.fromA).top+`px`;for(;t&&+t.dataset.chunk<i;)t=it(t);t&&t.dataset.chunk==String(i)?(t.style.top!=o&&(t.style.top=o),t=t.nextSibling):e.insertBefore(this.renderRevertButton(o,i),t)}for(;t;)t=it(t)}renderRevertButton(e,t){let n;if(this.renderRevert)n=this.renderRevert();else{n=document.createElement(`button`);let e=this.a.state.phrase(`Revert this chunk`);n.setAttribute(`aria-label`,e),n.setAttribute(`title`,e),n.textContent=this.revertToLeft?`⇜`:`⇝`}return n.style.top=e,n.setAttribute(`data-chunk`,String(t)),n}revertClicked(e){let t=e.target,n;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(n=this.chunks[t.dataset.chunk])){let[t,r,i,a,o,s]=this.revertToA?[this.b,this.a,n.fromB,n.toB,n.fromA,n.toA]:[this.a,this.b,n.fromA,n.toA,n.fromB,n.toB],c=t.state.sliceDoc(i,Math.max(i,a-1));i!=a&&s<=r.state.doc.length&&(c+=t.state.lineBreak),r.dispatch({changes:{from:o,to:Math.min(r.state.doc.length,s),insert:c},userEvent:`revert`}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function it(e){let t=e.nextSibling;return e.remove(),t}var $=r();function at(e){switch(e.split(`.`).pop()?.toLowerCase()??``){case`js`:case`jsx`:return w({jsx:!0});case`ts`:case`tsx`:return w({jsx:!0,typescript:!0});case`py`:return g();case`html`:return E();case`css`:case`scss`:return y();case`json`:return C();case`md`:case`mdx`:return k();default:return null}}function ot({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,l=e?.ref2,u=e?.file1,f=e?.file2,m=e?.original,h=e?.modified,g=m!=null||h!=null,_=!!(u&&f),[v,ee]=(0,A.useState)(null),[y,b]=(0,A.useState)(null),[x,S]=(0,A.useState)(!g),[C,w]=(0,A.useState)(null),[T,E]=(0,A.useState)(`both`),D=(0,A.useRef)(null),O=(0,A.useRef)(null);(0,A.useEffect)(()=>{if(g||!n)return;if(S(!0),w(null),u&&f){let e=new URLSearchParams;e.set(`file1`,u),e.set(`file2`,f),o.get(`${a(n)}/files/compare?${e.toString()}`).then(e=>{b(e),S(!1)}).catch(e=>{w(e instanceof Error?e.message:`Failed to compare files`),S(!1)});return}let e;if(t){let i=new URLSearchParams;i.set(`file`,t),r&&i.set(`ref`,r),e=`${a(n)}/git/file-diff?${i.toString()}`}else if(r||l){let t=new URLSearchParams;r&&t.set(`ref1`,r),l&&t.set(`ref2`,l),e=`${a(n)}/git/diff?${t.toString()}`}else e=`${a(n)}/git/diff`;o.get(e).then(e=>{ee(e.diff),S(!1)}).catch(e=>{w(e instanceof Error?e.message:`Failed to load diff`),S(!1)})},[t,n,r,l,u,f]);let{original:k,modified:j}=(0,A.useMemo)(()=>g?{original:m??``,modified:h??``}:_&&y?y:v?st(v):{original:``,modified:``},[v,g,m,h,_,y]),M=(0,A.useMemo)(()=>{let e=t??f??u;if(!e)return[];let n=at(e);return n?[n]:[]},[t,u,f]);if((0,A.useEffect)(()=>{let e=D.current;if(!e||x||C||!k&&!j)return;O.current&&=(O.current.destroy(),null),window.innerWidth;let t=[...M,ne,p.editable.of(!1),te.readOnly.of(!0),d(),p.theme({"&":{fontSize:`13px`,fontFamily:`var(--font-mono)`},"& .cm-changedText":{textDecoration:`none !important`,borderBottom:`none !important`,textDecorationLine:`none !important`,backgroundColor:`rgba(16, 185, 129, 0.4) !important`,borderRadius:`2px`},"& .cm-deletedChunk .cm-changedText":{backgroundColor:`rgba(239, 68, 68, 0.4) !important`}})],n=new rt({parent:e,a:{doc:k,extensions:t},b:{doc:j,extensions:t},orientation:`a-b`,revertControls:void 0,highlightChanges:!0,gutter:!0});O.current=n;let r=n.a.dom.querySelector(`.cm-scroller`),i=n.b.dom.querySelector(`.cm-scroller`),a=!1,o=(e,t)=>{a||=(a=!0,t.scrollLeft=e.scrollLeft,!1)},s=()=>r&&i&&o(r,i),c=()=>r&&i&&o(i,r);return r?.addEventListener(`scroll`,s),i?.addEventListener(`scroll`,c),()=>{r?.removeEventListener(`scroll`,s),i?.removeEventListener(`scroll`,c),n.destroy(),O.current=null}},[k,j,M,x,C]),(0,A.useEffect)(()=>{let e=O.current;if(!e)return;let t=e.a.dom.closest(`.cm-mergeViewEditor`)??e.a.dom.parentElement,n=e.b.dom.closest(`.cm-mergeViewEditor`)??e.b.dom.parentElement,r=D.current?.querySelector(`.cm-mergeViewGutter`);t&&(t.style.display=T===`right`?`none`:``,t.style.flex=T===`left`?`1`:``),n&&(n.style.display=T===`left`?`none`:``,n.style.flex=T===`right`?`1`:``),r&&(r.style.display=T===`both`?``:`none`)},[T,k,j]),!n&&!g)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(x)return(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,$.jsx)(s,{className:`size-5 animate-spin`}),(0,$.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]});if(C)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:C});if(!g&&!_&&(!v||v.trim()===``)&&!k&&!j)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,$.jsx)(c,{className:`size-8`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`No changes detected`}),t&&(0,$.jsx)(`p`,{className:`text-xs font-mono`,children:t})]});let N=(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(T===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,$.jsx)(re,{className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,$.jsx)(i,{className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(T===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,$.jsx)(ie,{className:`size-3.5`})})]});return(0,$.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b text-xs text-muted-foreground`,children:[(0,$.jsx)(c,{className:`size-3.5`}),_?(0,$.jsxs)(`span`,{className:`font-mono truncate flex-1`,children:[u,` vs `,f]}):(0,$.jsxs)(`span`,{className:`flex-1 truncate`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:t??`Working tree changes`}),(r||l)&&(0,$.jsxs)(`span`,{children:[` (`,r?.slice(0,7)??`HEAD`,` vs `,l?.slice(0,7)??`working tree`,`)`]})]}),(0,$.jsx)(`div`,{className:`hidden md:block`,children:N})]}),(0,$.jsx)(`div`,{ref:D,className:`flex-1 overflow-auto touch-pinch-zoom [&_.cm-mergeView]:h-full`,style:{WebkitOverflowScrolling:`touch`}}),(0,$.jsx)(`div`,{className:`md:hidden flex justify-center border-t py-1 bg-background shrink-0`,children:N})]})}function st(e){let t=e.split(`
|
|
1
|
+
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./columns-2-DsiY76NQ.js";import{r as a,t as o}from"./api-client-tgjN9Mx8.js";import{E as s,b as c}from"./index-DOHQ7GlD.js";import{A as l,E as u,H as d,I as f,O as p,Q as m,Y as h,a as g,at as _,ct as v,et as ee,i as y,it as b,j as x,k as S,n as C,nt as te,o as w,ot as T,r as E,rt as D,s as ne,st as O,t as k}from"./dist-BeHIxUn0.js";var re=t(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),ie=t(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),A=e(n(),1),j=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}offset(t,n=t){return new e(this.fromA+t,this.toA+t,this.fromB+n,this.toB+n)}};function M(e,t,n,r,i,a){if(e==r)return[];let o=R(e,t,n,r,i,a),s=z(e,t+o,n,r,i+o,a);t+=o,n-=s,i+=o,a-=s;let c=n-t,l=a-i;if(!c||!l)return[new j(t,n,i,a)];if(c>l){let o=e.slice(t,n).indexOf(r.slice(i,a));if(o>-1)return[new j(t,t+o,i,i),new j(t+o+l,n,a,a)]}else if(l>c){let o=r.slice(i,a).indexOf(e.slice(t,n));if(o>-1)return[new j(t,t,i,i+o),new j(n,n,i+o+c,a)]}if(c==1||l==1)return[new j(t,n,i,a)];let u=le(e,t,n,r,i,a);if(u){let[o,s,c]=u;return M(e,t,o,r,i,s).concat(M(e,o+c,n,r,s+c,a))}return ae(e,t,n,r,i,a)}var N=1e9,P=0,F=!1;function ae(e,t,n,r,i,a){let o=n-t,s=a-i;if(N<1e9&&Math.min(o,s)>N*16||P>0&&Date.now()>P)return Math.min(o,s)>N*64?[new j(t,n,i,a)]:ue(e,t,n,r,i,a);let c=Math.ceil((o+s)/2);I.reset(c),L.reset(c);let l=(n,a)=>e.charCodeAt(t+n)==r.charCodeAt(i+a),u=(t,i)=>e.charCodeAt(n-t-1)==r.charCodeAt(a-i-1),d=(o-s)%2==0?null:L,f=d?null:I;for(let p=0;p<c;p++){if(p>N||P>0&&!(p&63)&&Date.now()>P)return ue(e,t,n,r,i,a);let m=I.advance(p,o,s,c,d,!1,l)||L.advance(p,o,s,c,f,!0,u);if(m)return se(e,t,n,t+m[0],r,i,a,i+m[1])}return[new j(t,n,i,a)]}var oe=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let e=0;e<this.len;e++)this.vec[e]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,n,r,i,a,o){for(let s=-e+this.start;s<=e-this.end;s+=2){let c=r+s,l=s==-e||s!=e&&this.vec[c-1]<this.vec[c+1]?this.vec[c+1]:this.vec[c-1]+1,u=l-s;for(;l<t&&u<n&&o(l,u);)l++,u++;if(this.vec[c]=l,l>t)this.end+=2;else if(u>n)this.start+=2;else if(i){let e=r+(t-n)-s;if(e>=0&&e<this.len&&i.vec[e]!=-1)if(a){let n=i.vec[e];if(n>=t-l)return[n,r+n-e]}else{let n=t-i.vec[e];if(l>=n)return[l,u]}}}return null}},I=new oe,L=new oe;function se(e,t,n,r,i,a,o,s){let c=!1;return!H(e,r)&&++r==n&&(c=!0),!H(i,s)&&++s==o&&(c=!0),c?[new j(t,n,a,o)]:M(e,t,r,i,a,s).concat(M(e,r,n,i,s,o))}function ce(e,t){let n=1,r=Math.min(e,t);for(;n<r;)n<<=1;return n}function R(e,t,n,r,i,a){if(t==n||t==a||e.charCodeAt(t)!=r.charCodeAt(i))return 0;let o=ce(n-t,a-i);for(let s=t,c=i;;){let i=s+o,l=c+o;if(i>n||l>a||e.slice(s,i)!=r.slice(c,l)){if(o==1)return s-t-(H(e,s)?0:1);o>>=1}else if(i==n||l==a)return i-t;else s=i,c=l}}function z(e,t,n,r,i,a){if(t==n||i==a||e.charCodeAt(n-1)!=r.charCodeAt(a-1))return 0;let o=ce(n-t,a-i);for(let s=n,c=a;;){let a=s-o,l=c-o;if(a<t||l<i||e.slice(a,s)!=r.slice(l,c)){if(o==1)return n-s-(H(e,s)?0:1);o>>=1}else if(a==t||l==i)return n-a;else s=a,c=l}}function B(e,t,n,r,i,a,o,s){let c=r.slice(i,a),l=null;for(;;){if(l||o<s)return l;for(let s=t+o;;){H(e,s)||s++;let u=s+o;if(H(e,u)||(u+=u==s+1?1:-1),u>=n)break;let d=e.slice(s,u),f=-1;for(;(f=c.indexOf(d,f+1))!=-1;){let o=R(e,u,n,r,i+f+d.length,a),c=z(e,t,s,r,i,i+f),p=d.length+o+c;(!l||l[2]<p)&&(l=[s-c,i+f-c,p])}s=u}if(s<0)return l;o>>=1}}function le(e,t,n,r,i,a){let o=n-t,s=a-i;if(o<s){let o=le(r,i,a,e,t,n);return o&&[o[1],o[0],o[2]]}return o<4||s*2<o?null:B(e,t,n,r,i,a,Math.floor(o/4),-1)}function ue(e,t,n,r,i,a){F=!0;let o=n-t,s=a-i,c;if(o<s){let s=B(r,i,a,e,t,n,Math.floor(o/6),50);c=s&&[s[1],s[0],s[2]]}else c=B(e,t,n,r,i,a,Math.floor(s/6),50);if(!c)return[new j(t,n,i,a)];let[l,u,d]=c;return M(e,t,l,r,i,u).concat(M(e,l+d,n,r,u+d,a))}function de(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n];r.toA>i.fromA-t&&r.toB>i.fromB-t&&(e[n-1]=new j(r.fromA,i.toA,r.fromB,i.toB),e.splice(n--,1))}}function fe(e,t,n){for(;;){de(n,1);let r=!1;for(let i=0;i<n.length;i++){let a=n[i],o,s;(o=R(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new j(a.fromA+o,a.toA,a.fromB+o,a.toB)),(s=z(e,a.fromA,a.toA,t,a.fromB,a.toB))&&(a=n[i]=new j(a.fromA,a.toA-s,a.fromB,a.toB-s));let c=a.toA-a.fromA,l=a.toB-a.fromB;if(c&&l)continue;let u=a.fromA-(i?n[i-1].toA:0),d=(i<n.length-1?n[i+1].fromA:e.length)-a.toA;if(!u||!d)continue;let f=c?e.slice(a.fromA,a.toA):t.slice(a.fromB,a.toB);u<=f.length&&e.slice(a.fromA-u,a.fromA)==f.slice(f.length-u)?(n[i]=new j(a.fromA-u,a.toA-u,a.fromB-u,a.toB-u),r=!0):d<=f.length&&e.slice(a.toA,a.toA+d)==f.slice(0,d)&&(n[i]=new j(a.fromA+d,a.toA+d,a.fromB+d,a.toB+d),r=!0)}if(!r)break}return n}function pe(e,t,n){for(let r=0,i=0;i<e.length;i++){let a=e[i],o=a.toA-a.fromA,s=a.toB-a.fromB;if(o&&s||o>3||s>3){let c=i==e.length-1?t.length:e[i+1].fromA,l=a.fromA-r,u=c-a.toA,d=ye(t,a.fromA,l),f=ve(t,a.toA,u),p=a.fromA-d,m=f-a.toA;if((!o||!s)&&p&&m){let l=Math.max(o,s),[u,h,g]=o?[t,a.fromA,a.toA]:[n,a.fromB,a.toB];l>p&&t.slice(d,a.fromA)==u.slice(g-p,g)?(a=e[i]=new j(d,d+o,a.fromB-p,a.toB-p),d=a.fromA,f=ve(t,a.toA,c-a.toA)):l>m&&t.slice(a.toA,f)==u.slice(h,h+m)&&(a=e[i]=new j(f-o,f,a.fromB+m,a.toB+m),f=a.toA,d=ye(t,a.fromA,a.fromA-r)),p=a.fromA-d,m=f-a.toA}if(p||m)a=e[i]=new j(a.fromA-p,a.toA+m,a.fromB-p,a.toB+m);else if(!o){let t=xe(n,a.fromB,a.toB),r,o=t<0?-1:be(n,a.toB,a.fromB);t>-1&&(r=t-a.fromB)<=u&&n.slice(a.fromB,t)==n.slice(a.toB,a.toB+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toB-o)<=l&&n.slice(a.fromB-r,a.fromB)==n.slice(o,a.toB)&&(a=e[i]=a.offset(-r))}else if(!s){let n=xe(t,a.fromA,a.toA),r,o=n<0?-1:be(t,a.toA,a.fromA);n>-1&&(r=n-a.fromA)<=u&&t.slice(a.fromA,n)==t.slice(a.toA,a.toA+r)?a=e[i]=a.offset(r):o>-1&&(r=a.toA-o)<=l&&t.slice(a.fromA-r,a.fromA)==t.slice(o,a.toA)&&(a=e[i]=a.offset(-r))}}r=a.toA}return de(e,3),e}var V;try{V=RegExp(`[\\p{Alphabetic}\\p{Number}]`,`u`)}catch{}function me(e){return e>48&&e<58||e>64&&e<91||e>96&&e<123}function he(e,t){if(t==e.length)return 0;let n=e.charCodeAt(t);return n<192?me(n)?1:0:V?!Se(n)||t==e.length-1?V.test(String.fromCharCode(n))?1:0:V.test(e.slice(t,t+2))?2:0:0}function ge(e,t){if(!t)return 0;let n=e.charCodeAt(t-1);return n<192?me(n)?1:0:V?!Ce(n)||t==1?V.test(String.fromCharCode(n))?1:0:V.test(e.slice(t-2,t))?2:0:0}var _e=8;function ve(e,t,n){if(t==e.length||!ge(e,t))return t;for(let r=t,i=t+n,a=0;a<_e;a++){let t=he(e,r);if(!t||r+t>i)return r;r+=t}return t}function ye(e,t,n){if(!t||!he(e,t))return t;for(let r=t,i=t-n,a=0;a<_e;a++){let t=ge(e,r);if(!t||r-t<i)return r;r-=t}return t}function be(e,t,n){for(;t!=n;t--)if(e.charCodeAt(t-1)==10)return t;return-1}function xe(e,t,n){for(;t!=n;t++)if(e.charCodeAt(t)==10)return t;return-1}var Se=e=>e>=55296&&e<=56319,Ce=e=>e>=56320&&e<=57343;function H(e,t){return!t||t==e.length||!Se(e.charCodeAt(t-1))||!Ce(e.charCodeAt(t))}function we(e,t,n){let r=n?.override;return r?r(e,t):(N=(n?.scanLimit??1e9)>>1,P=n?.timeout?Date.now()+n.timeout:0,F=!1,fe(e,t,M(e,0,e.length,t,0,t.length)))}function Te(){return!F}function Ee(e,t,n){return pe(we(e,t,n),e,t)}var U=D.define({combine:e=>e[0]}),De=O.define(),Oe=D.define(),W=v.define({create(e){return null},update(e,t){for(let n of t.effects)n.is(De)&&(e=n.value);for(let n of t.state.facet(Oe))e=n(e,t);return e}}),G=class e{constructor(e,t,n,r,i,a=!0){this.changes=e,this.fromA=t,this.toA=n,this.fromB=r,this.toB=i,this.precise=a}offset(t,n){return t||n?new e(this.changes,this.fromA+t,this.toA+t,this.fromB+n,this.toB+n,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,n){return je(Ee(e.toString(),t.toString(),n),e,t,0,0,Te())}static updateA(e,t,n,r,i){return Pe(Ne(e,r,!0,n.length),e,t,n,i)}static updateB(e,t,n,r,i){return Pe(Ne(e,r,!1,t.length),e,t,n,i)}};function ke(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.to==e&&a.to==t&&e<n.length&&t<r.length?[e+1,t+1]:[i.from,a.from]}function Ae(e,t,n,r){let i=n.lineAt(e),a=r.lineAt(t);return i.from==e&&a.from==t?[e,t]:[i.to+1,a.to+1]}function je(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length;s++){let c=e[s],[l,u]=ke(c.fromA+r,c.fromB+i,t,n),[d,f]=Ae(c.toA+r,c.toB+i,t,n),p=[c.offset(-l+r,-u+i)];for(;s<e.length-1;){let a=e[s+1],[o,c]=ke(a.fromA+r,a.fromB+i,t,n);if(o>d+1&&c>f+1)break;p.push(a.offset(-l+r,-u+i)),[d,f]=Ae(a.toA+r,a.toB+i,t,n),s++}o.push(new G(p,l,Math.max(l,d),u,Math.max(u,f),a))}return o}var K=1e3;function Me(e,t,n,r){let i=0,a=e.length;for(;;){if(i==a){let r=0,a=0;i&&({toA:r,toB:a}=e[i-1]);let o=t-(n?r:a);return[r+o,a+o]}let o=i+a>>1,s=e[o],[c,l]=n?[s.fromA,s.toA]:[s.fromB,s.toB];if(c>t)a=o;else if(l<=t)i=o+1;else return r?[s.fromA,s.fromB]:[s.toA,s.toB]}}function Ne(e,t,n,r){let i=[];return t.iterChangedRanges((a,o,s,c)=>{let l=0,u=n?t.length:r,d=0,f=n?r:t.length;a>K&&([l,d]=Me(e,a-K,n,!0)),o<t.length-K&&([u,f]=Me(e,o+K,n,!1));let p=c-s-(o-a),m,[h,g]=n?[p,0]:[0,p];i.length&&(m=i[i.length-1]).toA>=l?i[i.length-1]={fromA:m.fromA,fromB:m.fromB,toA:u,toB:f,diffA:m.diffA+h,diffB:m.diffB+g}:i.push({fromA:l,toA:u,fromB:d,toB:f,diffA:h,diffB:g})}),i}function Pe(e,t,n,r,i){if(!e.length)return t;let a=[];for(let o=0,s=0,c=0,l=0;;o++){let u=o==e.length?null:e[o],d=u?u.fromA+s:n.length,f=u?u.fromB+c:r.length;for(;l<t.length;){let e=t[l];if(u&&(e.toA+s>d||e.toB+c>f))break;a.push(e.offset(s,c)),l++}if(!u)break;let p=u.toA+s+u.diffA,m=u.toB+c+u.diffB,h=Ee(n.sliceString(d,p),r.sliceString(f,m),i);for(let e of je(h,n,r,d,f,Te()))a.push(e);for(s+=u.diffA,c+=u.diffB;l<t.length;){let e=t[l];if(e.fromA+s>p&&e.fromB+c>m)break;l++}}return a}var Fe={scanLimit:500},Ie=l.fromClass(class{constructor(e){({deco:this.deco,gutter:this.gutter}=Ge(e))}update(e){(e.docChanged||e.viewportChanged||Le(e.startState,e.state)||Re(e.startState,e.state))&&({deco:this.deco,gutter:this.gutter}=Ge(e.view))}},{decorations:e=>e.deco}),q=b.low(f({class:`cm-changeGutter`,markers:e=>e.plugin(Ie)?.gutter||_.empty}));function Le(e,t){return e.field(W,!1)!=t.field(W,!1)}function Re(e,t){return e.facet(U)!=t.facet(U)}var ze=u.line({class:`cm-changedLine`}),Be=u.mark({class:`cm-changedText`}),Ve=u.mark({tagName:`ins`,class:`cm-insertedLine`}),He=u.mark({tagName:`del`,class:`cm-deletedLine`}),Ue=new class extends S{constructor(){super(...arguments),this.elementClass=`cm-changedLineGutter`}};function We(e,t,n,r,i,a){let o=n?e.fromA:e.fromB,s=n?e.toA:e.toB,c=0;if(o!=s){i.add(o,o,ze),i.add(o,s,n?He:Ve),a&&a.add(o,o,Ue);for(let l=t.iterRange(o,s-1),u=o;!l.next().done;){if(l.lineBreak){u++,i.add(u,u,ze),a&&a.add(u,u,Ue);continue}let t=u+l.value.length;if(r)for(;c<e.changes.length;){let r=e.changes[c],a=o+(n?r.fromA:r.fromB),s=o+(n?r.toA:r.toB),l=Math.max(u,a),d=Math.min(t,s);if(l<d&&i.add(l,d,Be),s<t)c++;else break}u=t}}}function Ge(e){let t=e.state.field(W),{side:n,highlightChanges:r,markGutter:i,overrideChunk:a}=e.state.facet(U),o=n==`a`,s=new T,c=i?new T:null,{from:l,to:u}=e.viewport;for(let n of t){if((o?n.fromA:n.fromB)>=u)break;(o?n.toA:n.toB)>l&&(!a||!a(e.state,n,s,c))&&We(n,e.state.doc,o,r,s,c)}return{deco:s.finish(),gutter:c&&c.finish()}}var J=class extends x{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement(`div`);return e.className=`cm-mergeSpacer`,e.style.height=this.height+`px`,e}updateDOM(e){return e.style.height=this.height+`px`,!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},Y=O.define({map:(e,t)=>e.map(t)}),X=v.define({create:()=>u.none,update:(e,t)=>{for(let e of t.effects)if(e.is(Y))return e.value;return e.map(t.changes)},provide:e=>p.decorations.from(e)}),Z=.01;function Ke(e,t){if(e.size!=t.size)return!1;let n=e.iter(),r=t.iter();for(;n.value;){if(n.from!=r.from||Math.abs(n.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;n.next(),r.next()}return!0}function qe(e,t,n){let r=new T,i=new T,a=e.state.field(X).iter(),o=t.state.field(X).iter(),s=0,c=0,l=0,d=0,f=e.viewport,p=t.viewport;for(let m=0;;m++){let h=m<n.length?n[m]:null,g=h?h.fromA:e.state.doc.length,_=h?h.fromB:t.state.doc.length;if(s<g){let n=e.lineBlockAt(s).top+l-(t.lineBlockAt(c).top+d);n<-Z?(l-=n,r.add(s,s,u.widget({widget:new J(-n),block:!0,side:-1}))):n>Z&&(d+=n,i.add(c,c,u.widget({widget:new J(n),block:!0,side:-1})))}if(g>s+1e3&&s<f.from&&g>f.from&&c<p.from&&_>p.from){let e=Math.min(f.from-s,p.from-c);s+=e,c+=e,m--}else if(h)s=h.toA,c=h.toB;else break;for(;a.value&&a.from<s;)l-=a.value.spec.widget.height,a.next();for(;o.value&&o.from<c;)d-=o.value.spec.widget.height,o.next()}for(;a.value;)l-=a.value.spec.widget.height,a.next();for(;o.value;)d-=o.value.spec.widget.height,o.next();let m=e.contentHeight+l-(t.contentHeight+d);m<Z?r.add(e.state.doc.length,e.state.doc.length,u.widget({widget:new J(-m),block:!0,side:1})):m>Z&&i.add(t.state.doc.length,t.state.doc.length,u.widget({widget:new J(m),block:!0,side:1}));let h=r.finish(),g=i.finish();Ke(h,e.state.field(X))||e.dispatch({effects:Y.of(h)}),Ke(g,t.state.field(X))||t.dispatch({effects:Y.of(g)})}var Je=O.define({map:(e,t)=>t.mapPos(e)}),Ye=class extends x{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement(`div`);return t.className=`cm-collapsedLines`,t.textContent=e.state.phrase(`$ unchanged lines`,this.lines),t.addEventListener(`click`,t=>{let n=e.posAtDOM(t.target);e.dispatch({effects:Je.of(n)});let{side:r,sibling:i}=e.state.facet(U);i&&i().dispatch({effects:Je.of(Xe(n,e.state.field(W),r==`a`))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return`collapsed-unchanged-code`}};function Xe(e,t,n){let r=0,i=0;for(let a=0;;a++){let o=a<t.length?t[a]:null;if(!o||(n?o.fromA:o.fromB)>=e)return i+(e-r);[r,i]=n?[o.toA,o.toB]:[o.toB,o.toA]}}var Ze=v.define({create(e){return u.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)n.is(Je)&&(e=e.update({filter:e=>e!=n.value}));return e},provide:e=>p.decorations.from(e)});function Qe({margin:e=3,minSize:t=4}){return Ze.init(n=>$e(n,e,t))}function $e(e,t,n){let r=new T,i=e.facet(U).side==`a`,a=e.field(W),o=1;for(let s=0;;s++){let c=s<a.length?a[s]:null,l=s?o+t:1,d=c?e.doc.lineAt(i?c.fromA:c.fromB).number-1-t:e.doc.lines,f=d-l+1;if(f>=n&&r.add(e.doc.line(l).from,e.doc.line(d).to,u.replace({widget:new Ye(f),block:!0})),!c)break;o=e.doc.lineAt(Math.min(e.doc.length,i?c.toA:c.toB)).number}return r.finish()}var et=p.styleModule.of(new h({".cm-mergeView":{overflowY:`auto`},".cm-mergeViewEditors":{display:`flex`,alignItems:`stretch`},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:`hidden`},".cm-merge-revert":{width:`1.6em`,flexGrow:0,flexShrink:0,position:`relative`},".cm-merge-revert button":{position:`absolute`,display:`block`,width:`100%`,boxSizing:`border-box`,textAlign:`center`,background:`none`,border:`none`,font:`inherit`,cursor:`pointer`}})),tt=p.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:`auto !important`,overflowY:`visible !important`},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:`rgba(160, 128, 100, .08)`},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:`rgba(100, 160, 128, .08)`},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat`},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:`linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat`},"&light.cm-merge-b .cm-changedText":{background:`linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat`},"&dark.cm-merge-b .cm-changedText":{background:`linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat`},"&.cm-merge-b .cm-deletedText":{background:`#ff000033`},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:`none`},".cm-deletedChunk":{paddingLeft:`6px`,"& .cm-chunkButtons":{position:`absolute`,insetInlineEnd:`5px`},"& button":{border:`none`,cursor:`pointer`,color:`white`,margin:`0 2px`,borderRadius:`3px`,"&[name=accept]":{background:`#2a2`},"&[name=reject]":{background:`#d43`}}},".cm-collapsedLines":{padding:`5px 5px 5px 10px`,cursor:`pointer`,"&:before":{content:`"⦚"`,marginInlineEnd:`7px`},"&:after":{content:`"⦚"`,marginInlineStart:`7px`}},"&light .cm-collapsedLines":{color:`#444`,background:`linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)`},"&dark .cm-collapsedLines":{color:`#ddd`,background:`linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)`},".cm-changeGutter":{width:`3px`,paddingLeft:`1px`},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:`#e43`},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:`#fa9`},"&light.cm-merge-b .cm-changedLineGutter":{background:`#2b2`},"&dark.cm-merge-b .cm-changedLineGutter":{background:`#8f8`},".cm-inlineChangedLineGutter":{background:`#75d`}}),nt=new ee,Q=new ee,rt=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||Fe;let t=[b.low(Ie),tt,et,X,p.updateListener.of(e=>{this.measuring<0&&(e.heightChanged||e.viewportChanged)&&!e.transactions.some(e=>e.effects.some(e=>e.is(Y)))&&this.measure()})],n=[U.of({side:`a`,sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&n.push(q);let r=te.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],p.editorAttributes.of({class:`cm-merge-a`}),Q.of(n),t]}),i=[U.of({side:`b`,sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&i.push(q);let a=te.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],p.editorAttributes.of({class:`cm-merge-b`}),Q.of(i),t]});this.chunks=G.build(r.doc,a.doc,this.diffConf);let o=[W.init(()=>this.chunks),nt.of(e.collapseUnchanged?Qe(e.collapseUnchanged):[])];r=r.update({effects:O.appendConfig.of(o)}).state,a=a.update({effects:O.appendConfig.of(o)}).state,this.dom=document.createElement(`div`),this.dom.className=`cm-mergeView`,this.editorDOM=this.dom.appendChild(document.createElement(`div`)),this.editorDOM.className=`cm-mergeViewEditors`;let s=e.orientation||`a-b`,c=document.createElement(`div`);c.className=`cm-mergeViewEditor`;let l=document.createElement(`div`);l.className=`cm-mergeViewEditor`,this.editorDOM.appendChild(s==`a-b`?c:l),this.editorDOM.appendChild(s==`a-b`?l:c),this.a=new p({state:r,parent:c,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.a)}),this.b=new p({state:a,parent:l,root:e.root,dispatchTransactions:e=>this.dispatch(e,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls==`b-to-a`,e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(e=>e.docChanged)){let n=e[e.length-1],r=e.reduce((e,t)=>e.compose(t.changes),m.empty(e[0].startState.doc.length));this.chunks=t==this.a?G.updateA(this.chunks,n.newDoc,this.b.state.doc,r,this.diffConf):G.updateB(this.chunks,this.a.state.doc,n.newDoc,r,this.diffConf),t.update([...e,n.state.update({effects:De.of(this.chunks)})]);let i=t==this.a?this.b:this.a;i.update([i.state.update({effects:De.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if(`diffConfig`in e&&(this.diffConf=e.diffConfig),`orientation`in e){let t=e.orientation!=`b-a`;if(t!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let e=this.a.dom.parentNode,n=this.b.dom.parentNode;e.remove(),n.remove(),this.editorDOM.insertBefore(t?e:n,this.editorDOM.firstChild),this.editorDOM.appendChild(t?n:e),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent=``)}}if(`revertControls`in e||`renderRevertControl`in e){let t=!!this.revertDOM,n=this.revertToA,r=this.renderRevert;`revertControls`in e&&(t=!!e.revertControls,n=e.revertControls==`b-to-a`),`renderRevertControl`in e&&(r=e.renderRevertControl),this.setupRevertControls(t,n,r)}let t=`highlightChanges`in e,n=`gutter`in e,r=`collapseUnchanged`in e;if(t||n||r){let i=[],a=[];if(t||n){let r=this.a.state.facet(U),o=n?e.gutter!==!1:r.markGutter,s=t?e.highlightChanges!==!1:r.highlightChanges;i.push(Q.reconfigure([U.of({side:`a`,sibling:()=>this.b,highlightChanges:s,markGutter:o}),o?q:[]])),a.push(Q.reconfigure([U.of({side:`b`,sibling:()=>this.a,highlightChanges:s,markGutter:o}),o?q:[]]))}if(r){let t=nt.reconfigure(e.collapseUnchanged?Qe(e.collapseUnchanged):[]);i.push(t),a.push(t)}this.a.dispatch({effects:i}),this.b.dispatch({effects:a})}this.scheduleMeasure()}setupRevertControls(e,t,n){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=n,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement(`div`),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener(`mousedown`,e=>this.revertClicked(e)),this.revertDOM.className=`cm-merge-revert`):this.revertDOM&&(this.revertDOM.textContent=``)}scheduleMeasure(){this.measuring<0&&(this.measuring=(this.dom.ownerDocument.defaultView||window).requestAnimationFrame(()=>{this.measuring=-1,this.measure()}))}measure(){qe(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,n=this.a.viewport,r=this.b.viewport;for(let i=0;i<this.chunks.length;i++){let a=this.chunks[i];if(a.fromA>n.to||a.fromB>r.to)break;if(a.fromA<n.from||a.fromB<r.from)continue;let o=this.a.lineBlockAt(a.fromA).top+`px`;for(;t&&+t.dataset.chunk<i;)t=it(t);t&&t.dataset.chunk==String(i)?(t.style.top!=o&&(t.style.top=o),t=t.nextSibling):e.insertBefore(this.renderRevertButton(o,i),t)}for(;t;)t=it(t)}renderRevertButton(e,t){let n;if(this.renderRevert)n=this.renderRevert();else{n=document.createElement(`button`);let e=this.a.state.phrase(`Revert this chunk`);n.setAttribute(`aria-label`,e),n.setAttribute(`title`,e),n.textContent=this.revertToLeft?`⇜`:`⇝`}return n.style.top=e,n.setAttribute(`data-chunk`,String(t)),n}revertClicked(e){let t=e.target,n;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(n=this.chunks[t.dataset.chunk])){let[t,r,i,a,o,s]=this.revertToA?[this.b,this.a,n.fromB,n.toB,n.fromA,n.toA]:[this.a,this.b,n.fromA,n.toA,n.fromB,n.toB],c=t.state.sliceDoc(i,Math.max(i,a-1));i!=a&&s<=r.state.doc.length&&(c+=t.state.lineBreak),r.dispatch({changes:{from:o,to:Math.min(r.state.doc.length,s),insert:c},userEvent:`revert`}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function it(e){let t=e.nextSibling;return e.remove(),t}var $=r();function at(e){switch(e.split(`.`).pop()?.toLowerCase()??``){case`js`:case`jsx`:return w({jsx:!0});case`ts`:case`tsx`:return w({jsx:!0,typescript:!0});case`py`:return g();case`html`:return E();case`css`:case`scss`:return y();case`json`:return C();case`md`:case`mdx`:return k();default:return null}}function ot({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,l=e?.ref2,u=e?.file1,f=e?.file2,m=e?.original,h=e?.modified,g=m!=null||h!=null,_=!!(u&&f),[v,ee]=(0,A.useState)(null),[y,b]=(0,A.useState)(null),[x,S]=(0,A.useState)(!g),[C,w]=(0,A.useState)(null),[T,E]=(0,A.useState)(`both`),D=(0,A.useRef)(null),O=(0,A.useRef)(null);(0,A.useEffect)(()=>{if(g||!n)return;if(S(!0),w(null),u&&f){let e=new URLSearchParams;e.set(`file1`,u),e.set(`file2`,f),o.get(`${a(n)}/files/compare?${e.toString()}`).then(e=>{b(e),S(!1)}).catch(e=>{w(e instanceof Error?e.message:`Failed to compare files`),S(!1)});return}let e;if(t){let i=new URLSearchParams;i.set(`file`,t),r&&i.set(`ref`,r),e=`${a(n)}/git/file-diff?${i.toString()}`}else if(r||l){let t=new URLSearchParams;r&&t.set(`ref1`,r),l&&t.set(`ref2`,l),e=`${a(n)}/git/diff?${t.toString()}`}else e=`${a(n)}/git/diff`;o.get(e).then(e=>{ee(e.diff),S(!1)}).catch(e=>{w(e instanceof Error?e.message:`Failed to load diff`),S(!1)})},[t,n,r,l,u,f]);let{original:k,modified:j}=(0,A.useMemo)(()=>g?{original:m??``,modified:h??``}:_&&y?y:v?st(v):{original:``,modified:``},[v,g,m,h,_,y]),M=(0,A.useMemo)(()=>{let e=t??f??u;if(!e)return[];let n=at(e);return n?[n]:[]},[t,u,f]);if((0,A.useEffect)(()=>{let e=D.current;if(!e||x||C||!k&&!j)return;O.current&&=(O.current.destroy(),null),window.innerWidth;let t=[...M,ne,p.editable.of(!1),te.readOnly.of(!0),d(),p.theme({"&":{fontSize:`13px`,fontFamily:`var(--font-mono)`},"& .cm-changedText":{textDecoration:`none !important`,borderBottom:`none !important`,textDecorationLine:`none !important`,backgroundColor:`rgba(16, 185, 129, 0.4) !important`,borderRadius:`2px`},"& .cm-deletedChunk .cm-changedText":{backgroundColor:`rgba(239, 68, 68, 0.4) !important`}})],n=new rt({parent:e,a:{doc:k,extensions:t},b:{doc:j,extensions:t},orientation:`a-b`,revertControls:void 0,highlightChanges:!0,gutter:!0});O.current=n;let r=n.a.dom.querySelector(`.cm-scroller`),i=n.b.dom.querySelector(`.cm-scroller`),a=!1,o=(e,t)=>{a||=(a=!0,t.scrollLeft=e.scrollLeft,!1)},s=()=>r&&i&&o(r,i),c=()=>r&&i&&o(i,r);return r?.addEventListener(`scroll`,s),i?.addEventListener(`scroll`,c),()=>{r?.removeEventListener(`scroll`,s),i?.removeEventListener(`scroll`,c),n.destroy(),O.current=null}},[k,j,M,x,C]),(0,A.useEffect)(()=>{let e=O.current;if(!e)return;let t=e.a.dom.closest(`.cm-mergeViewEditor`)??e.a.dom.parentElement,n=e.b.dom.closest(`.cm-mergeViewEditor`)??e.b.dom.parentElement,r=D.current?.querySelector(`.cm-mergeViewGutter`);t&&(t.style.display=T===`right`?`none`:``,t.style.flex=T===`left`?`1`:``),n&&(n.style.display=T===`left`?`none`:``,n.style.flex=T===`right`?`1`:``),r&&(r.style.display=T===`both`?``:`none`)},[T,k,j]),!n&&!g)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(x)return(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,$.jsx)(c,{className:`size-5 animate-spin`}),(0,$.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]});if(C)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:C});if(!g&&!_&&(!v||v.trim()===``)&&!k&&!j)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,$.jsx)(s,{className:`size-8`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`No changes detected`}),t&&(0,$.jsx)(`p`,{className:`text-xs font-mono`,children:t})]});let N=(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(T===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,$.jsx)(re,{className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,$.jsx)(i,{className:`size-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(T===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${T===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,$.jsx)(ie,{className:`size-3.5`})})]});return(0,$.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b text-xs text-muted-foreground`,children:[(0,$.jsx)(s,{className:`size-3.5`}),_?(0,$.jsxs)(`span`,{className:`font-mono truncate flex-1`,children:[u,` vs `,f]}):(0,$.jsxs)(`span`,{className:`flex-1 truncate`,children:[(0,$.jsx)(`span`,{className:`font-mono`,children:t??`Working tree changes`}),(r||l)&&(0,$.jsxs)(`span`,{children:[` (`,r?.slice(0,7)??`HEAD`,` vs `,l?.slice(0,7)??`working tree`,`)`]})]}),(0,$.jsx)(`div`,{className:`hidden md:block`,children:N})]}),(0,$.jsx)(`div`,{ref:D,className:`flex-1 overflow-auto touch-pinch-zoom [&_.cm-mergeView]:h-full`,style:{WebkitOverflowScrolling:`touch`}}),(0,$.jsx)(`div`,{className:`md:hidden flex justify-center border-t py-1 bg-background shrink-0`,children:N})]})}function st(e){let t=e.split(`
|
|
2
2
|
`),n=[],r=[],i=!1;for(let e of t)if(!(e.startsWith(`diff --git`)||e.startsWith(`diff --no-index`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`---`)||e.startsWith(`+++`)||e.startsWith(`Binary files`)||e.startsWith(`\\ No newline`))){if(e.startsWith(`@@`)){i=!0;continue}if(i){if(e.startsWith(`-`))n.push(e.slice(1));else if(e.startsWith(`+`))r.push(e.slice(1));else if(e.startsWith(` `)||e===``){let t=e.startsWith(` `)?e.slice(1):e;n.push(t),r.push(t)}}}return{original:n.join(`
|
|
3
3
|
`),modified:r.join(`
|
|
4
4
|
`)}}export{ot as DiffViewer};
|
|
@@ -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-CQ5h5gxS.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./copy-D_Q54D-v.js";import{t as s}from"./external-link-C6Y-D528.js";import{t as c}from"./refresh-cw-S6I91MHO.js";import{t as l}from"./trash-2-Dc17nbCE.js";import{a as u,i as d,n as f,o as p,t as m}from"./dialog-CCBmXo6-.js";import{r as h,t as g}from"./api-client-tgjN9Mx8.js";import{a as _,c as v,i as y,o as b,r as ee,s as x,u as te,v as ne,y as S}from"./index-BCr_P7dc.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)(ne,{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)(y,{children:[(0,E.jsx)(v,{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)(_,{children:[(0,E.jsx)(b,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(b,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(S,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(b,{onClick:()=>le(e.hash),children:[(0,E.jsx)(re,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(b,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(b,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(x,{}),(0,E.jsx)(b,{onClick:()=>ge(e),children:`View Diff`}),(0,E.jsxs)(b,{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)(ee,{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)(y,{children:[(0,E.jsx)(v,{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)(_,{children:[(0,E.jsx)(b,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(b,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(b,{onClick:()=>o(e.name),children:[(0,E.jsx)(a,{className:`size-3`}),`Push`]}),(0,E.jsxs)(b,{onClick:()=>c(e.name),children:[(0,E.jsx)(s,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(b,{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-CQ5h5gxS.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./copy-D_Q54D-v.js";import{t as s}from"./external-link-C6Y-D528.js";import{t as c}from"./refresh-cw-S6I91MHO.js";import{t as l}from"./trash-2-Dc17nbCE.js";import{a as u,i as d,n as f,o as p,t as m}from"./dialog-CCBmXo6-.js";import{r as h,t as g}from"./api-client-tgjN9Mx8.js";import{a as ee,b as te,c as _,f as ne,l as v,o as y,s as b,u as x,x as S}from"./index-DOHQ7GlD.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}=ne(),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)(te,{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)(y,{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)(b,{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)(v,{}),(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)(v,{}),(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)(ee,{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)(y,{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)(b,{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)(v,{}),(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)(v,{}),(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-CQ5h5gxS.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./refresh-cw-S6I91MHO.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./dialog-CCBmXo6-.js";import{r as p,t as m}from"./api-client-tgjN9Mx8.js";import{C as h,D as g,O as _,d as v,g as y,u as b,v as x}from"./index-BCr_P7dc.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)(x,{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)(v,{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)(x,{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)(x,{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)(h,{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),h=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(h){let h=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)(_,{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:[`(`,h.length,`)`]})]}),(0,O.jsx)(N,{showRevert:u,onRevert:f?()=>f(h,e.fullPath):void 0,onAction:()=>o?.(h),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-CQ5h5gxS.js";import{t as a}from"./arrow-up-from-line-DjfWTP75.js";import{t as o}from"./refresh-cw-S6I91MHO.js";import{a as s,i as c,n as l,o as u,r as d,t as f}from"./dialog-CCBmXo6-.js";import{r as p,t as m}from"./api-client-tgjN9Mx8.js";import{A as h,T as g,b as _,f as v,k as y,p as b,v as x}from"./index-DOHQ7GlD.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,y]=(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}=v(),z=e?.viewMode===`tree`?`tree`:`flat`,B=n=>{t&&R(t,{metadata:{...e,viewMode:n}})},V=(0,D.useCallback)(async()=>{if(n)try{y(!0),h(await m.get(`${p(n)}/git/status`)),k(null)}catch(e){k(e instanceof Error?e.message:`Failed to fetch status`)}finally{y(!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)(_,{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)(b,{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)(x,{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)(_,{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)(_,{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)(g,{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),g=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(g){let g=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)(y,{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:[`(`,g.length,`)`]})]}),(0,O.jsx)(N,{showRevert:u,onRevert:f?()=>f(g,e.fullPath):void 0,onAction:()=>o?.(g),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};
|