@hienlh/ppm 0.9.12 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. package/dist/web/assets/{browser-tab-CWkYQN8G.js → browser-tab-BSyNzK_i.js} +1 -1
  2. package/dist/web/assets/{chat-tab-BVf4q-TX.js → chat-tab-CjT2fBUu.js} +7 -5
  3. package/dist/web/assets/{code-editor-r5T7wq0I.js → code-editor-BFvgjJI8.js} +1 -1
  4. package/dist/web/assets/{database-viewer-DIKCOXIJ.js → database-viewer-BscXiGVk.js} +1 -1
  5. package/dist/web/assets/{diff-viewer-Cs2knua9.js → diff-viewer-BPuXkTgo.js} +1 -1
  6. package/dist/web/assets/{extension-webview-BbDesnaR.js → extension-webview-Bc-T7rBy.js} +1 -1
  7. package/dist/web/assets/{git-graph-BWQm8I8V.js → git-graph-DHbLxuvX.js} +1 -1
  8. package/dist/web/assets/{index-E0N-qark.js → index-B--rhmx5.js} +3 -3
  9. package/dist/web/assets/keybindings-store-DxcPzGOr.js +1 -0
  10. package/dist/web/assets/{markdown-renderer-DgeFkhU6.js → markdown-renderer-BIt8Rv3R.js} +1 -1
  11. package/dist/web/assets/{postgres-viewer-hQ47YDO5.js → postgres-viewer-DhoKvynT.js} +1 -1
  12. package/dist/web/assets/{settings-tab-BZ_CLZDj.js → settings-tab-DujHTiPc.js} +1 -1
  13. package/dist/web/assets/{sqlite-viewer-B8vs7svK.js → sqlite-viewer-C05lv-Wf.js} +1 -1
  14. package/dist/web/assets/{terminal-tab-DjE8lCXj.js → terminal-tab-DmL_PPlt.js} +1 -1
  15. package/dist/web/assets/{use-monaco-theme-BNtfLGmz.js → use-monaco-theme-DCA0VEfi.js} +1 -1
  16. package/dist/web/index.html +1 -1
  17. package/dist/web/sw.js +1 -1
  18. package/package.json +1 -1
  19. package/src/web/components/chat/message-list.tsx +9 -1
  20. package/dist/web/assets/keybindings-store-DXucgQSx.js +0 -1
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/csv-preview-Doo6XsK0.js","assets/chunk-CFjPhJqf.js","assets/lib-BQ34Db2e.js","assets/react-nm2Ru1Pt.js","assets/createLucideIcon-PuMiQgHl.js","assets/arrow-up-BYhx9ckd.js","assets/react-dom-Bpkvzu3U.js","assets/jsx-runtime-O3jQaKZd.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./chevron-right-5HgK6l7K.js";import{n as i,t as a}from"./markdown-renderer-DgeFkhU6.js";import{A as o}from"./dist-C4urk5JP.js";import{l as s,t as c}from"./tab-store-CeOacjuH.js";import{t as l}from"./table-CWv1Oy39.js";import{i as u,n as d,t as f}from"./use-monaco-theme-BNtfLGmz.js";import{t as p}from"./preload-helper-uTix4PVD.js";import{t as m}from"./jsx-runtime-O3jQaKZd.js";import{t as h}from"./utils-BNytJOb1.js";import{i as g,r as _,t as v}from"./api-client-BfBM3I7n.js";import{C as y,K as b,L as x,_ as S,_t as C,b as w,ft as T,g as E,gt as D,h as O,ht as k,lt as A,mt as j,pt as M,v as N,vt as P,x as F,y as I}from"./index-E0N-qark.js";import"./chunk-GEFDOKGD-BbQkJu8C.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-BbIFzsIv.js";import"./chunk-HHEYEP7N-HRhYy3kG.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-Dw8ClWch.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-CeU4Q-xC.js";import"./chunk-PQ6SQG4A-D6BTbCQw.js";import"./chunk-KYZI473N-BcUZNnwd.js";import"./chunk-O4XLMI2P-JC6EGoUz.js";import"./chunk-GLR3WWYH-CzYx4w-r.js";import"./chunk-XPW4576I-BPQQBakK.js";var L=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),R=e(t(),1),z=m(),B={ts:D,tsx:D,js:D,jsx:D,py:D,rs:D,go:D,html:D,css:D,scss:D,json:C,md:k,txt:k,yaml:j,yml:j};function V(e,t){return t?T:B[e.split(`.`).pop()?.toLowerCase()??``]??M}function H(e,t){let n=[],r=e;for(let e=0;e<t.length;e++){let i=t[e],a=t.slice(0,e+1).join(`/`),o=r.find(e=>e.name===i);if(n.push({name:i,fullPath:a,node:o??null,siblings:r}),o?.children)r=o.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[]});break}}return n}function U(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function W({filePath:e,projectName:t,tabId:n,className:i}){let a=x(e=>e.tree),{updateTab:o,openTab:s}=c(),l=(0,R.useRef)(null),u=(0,R.useMemo)(()=>H(a,e.split(`/`).filter(Boolean)),[a,e]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[u]);function d(e,r){let i=h(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsx)(`div`,{ref:l,className:i,children:u.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,z.jsx)(r,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,z.jsx)(G,{segment:e,isLast:n===u.length-1,projectName:t,onFileClick:d}):(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function G({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,R.useMemo)(()=>U(e.siblings),[e.siblings]);return(0,z.jsxs)(O,{children:[(0,z.jsx)(F,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(E,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,z.jsx)(K,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function K({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,z.jsxs)(N,{children:[(0,z.jsxs)(w,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(I,{className:`max-h-[300px] overflow-y-auto p-1`,children:U(e.children).map(e=>(0,z.jsx)(K,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,z.jsxs)(S,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function q({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function J({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:a,wordWrap:s,onToggleWordWrap:c,filePath:d,projectName:f,className:p}){return(0,z.jsxs)(`div`,{className:p,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:t===`edit`,onClick:()=>n(`edit`),icon:i,label:`Edit`}),(0,z.jsx)(q,{active:t===`preview`,onClick:()=>n(`preview`),icon:P,label:`Preview`})]}),e===`csv`&&a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:r===`table`,onClick:()=>a(`table`),icon:l,label:`Table`}),(0,z.jsx)(q,{active:r===`raw`,onClick:()=>a(`raw`),icon:i,label:`Raw`})]}),(0,z.jsx)(q,{active:s,onClick:c,icon:u,label:`Wrap`}),d&&f&&(0,z.jsx)(q,{active:!1,onClick:()=>y(f,d),icon:o,label:`Download`})]})}var Y=(0,R.lazy)(()=>p(()=>import(`./csv-preview-Doo6XsK0.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),X=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Z=new Set([`db`,`sqlite`,`sqlite3`]);function Q(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[Q(e)]??`plaintext`}function $({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(`utf-8`),[l,u]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[_,y]=(0,R.useState)(!1),x=(0,R.useRef)(null),S=(0,R.useRef)(``),C=(0,R.useRef)(null),{tabs:w,updateTab:T}=c(),{wordWrap:E,toggleWordWrap:D}=b(),O=f(),k=w.find(e=>e.id===t),j=n?Q(n):``,M=X.has(j),N=j===`pdf`,P=Z.has(j),F=j===`md`||j===`mdx`,I=j===`csv`,[B,V]=(0,R.useState)(`preview`),[H,U]=(0,R.useState)(`table`);(0,R.useEffect)(()=>{P&&t&&T(t,{type:`sqlite`})},[P,t,T]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){u(!1);return}u(!0),m(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${g(r)}/files/read?path=${encodeURIComponent(n)}`;return v.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),S.current=e.content,u(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{x.current&&clearTimeout(x.current)}},[n,r,M,N,G]),(0,R.useEffect)(()=>{if(!k)return;let e=n?h(n):`Untitled`,t=_?`${e} \u25CF`:e;k.title!==t&&T(k.id,{title:t})},[_]);let K=(0,R.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await v.put(`/api/fs/write`,{path:n,content:e}):await v.put(`${g(r)}/files/write`,{path:n,content:e}),y(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;a(t),S.current=t,y(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>K(S.current),1e3)}let $=e?.lineNumber,ie=(0,R.useCallback)((e,t)=>{C.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>b.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):l?(0,z.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,z.jsx)(A,{className:`size-5 animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):p?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p}):M?(0,z.jsx)(ne,{filePath:n,projectName:r}):N?(0,z.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,z.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,z.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(W,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,z.jsx)(J,{ext:j,mdMode:B,onMdModeChange:V,csvMode:H,onCsvModeChange:U,wordWrap:E,onToggleWordWrap:D,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),I&&H===`table`?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,z.jsx)(Y,{content:i??``,onContentChange:q,wordWrap:E})}):F&&B===`preview`?(0,z.jsx)(te,{content:i??``}):(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,z.jsx)(d,{height:`100%`,language:ee(n),value:i??``,onChange:q,onMount:ie,theme:O,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:E?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,z.jsx)(a,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);return(0,R.useEffect)(()=>{let n,i=`${g(t)}/files/raw?path=${encodeURIComponent(e)}`,o=_();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,z.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);(0,R.useEffect)(()=>{let n,i=`${g(t)}/files/raw?path=${encodeURIComponent(e)}`,o=_();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,R.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,z.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,z.jsx)(s,{className:`size-3`}),` Open in new tab`]})]}),(0,z.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}export{$ as CodeEditor};
2
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./chevron-right-5HgK6l7K.js";import{n as i,t as a}from"./markdown-renderer-BIt8Rv3R.js";import{A as o}from"./dist-C4urk5JP.js";import{l as s,t as c}from"./tab-store-CeOacjuH.js";import{t as l}from"./table-CWv1Oy39.js";import{i as u,n as d,t as f}from"./use-monaco-theme-DCA0VEfi.js";import{t as p}from"./preload-helper-uTix4PVD.js";import{t as m}from"./jsx-runtime-O3jQaKZd.js";import{t as h}from"./utils-BNytJOb1.js";import{i as g,r as _,t as v}from"./api-client-BfBM3I7n.js";import{C as y,K as b,L as x,_ as S,_t as C,b as w,ft as T,g as E,gt as D,h as O,ht as k,lt as A,mt as j,pt as M,v as N,vt as P,x as F,y as I}from"./index-B--rhmx5.js";import"./chunk-GEFDOKGD-BbQkJu8C.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-BbIFzsIv.js";import"./chunk-HHEYEP7N-HRhYy3kG.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-Dw8ClWch.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-CeU4Q-xC.js";import"./chunk-PQ6SQG4A-D6BTbCQw.js";import"./chunk-KYZI473N-BcUZNnwd.js";import"./chunk-O4XLMI2P-JC6EGoUz.js";import"./chunk-GLR3WWYH-CzYx4w-r.js";import"./chunk-XPW4576I-BPQQBakK.js";var L=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),R=e(t(),1),z=m(),B={ts:D,tsx:D,js:D,jsx:D,py:D,rs:D,go:D,html:D,css:D,scss:D,json:C,md:k,txt:k,yaml:j,yml:j};function V(e,t){return t?T:B[e.split(`.`).pop()?.toLowerCase()??``]??M}function H(e,t){let n=[],r=e;for(let e=0;e<t.length;e++){let i=t[e],a=t.slice(0,e+1).join(`/`),o=r.find(e=>e.name===i);if(n.push({name:i,fullPath:a,node:o??null,siblings:r}),o?.children)r=o.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[]});break}}return n}function U(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function W({filePath:e,projectName:t,tabId:n,className:i}){let a=x(e=>e.tree),{updateTab:o,openTab:s}=c(),l=(0,R.useRef)(null),u=(0,R.useMemo)(()=>H(a,e.split(`/`).filter(Boolean)),[a,e]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[u]);function d(e,r){let i=h(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,z.jsx)(`div`,{ref:l,className:i,children:u.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,z.jsx)(r,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,z.jsx)(G,{segment:e,isLast:n===u.length-1,projectName:t,onFileClick:d}):(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function G({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,R.useMemo)(()=>U(e.siblings),[e.siblings]);return(0,z.jsxs)(O,{children:[(0,z.jsx)(F,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,z.jsx)(E,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,z.jsx)(K,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function K({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,z.jsxs)(N,{children:[(0,z.jsxs)(w,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(I,{className:`max-h-[300px] overflow-y-auto p-1`,children:U(e.children).map(e=>(0,z.jsx)(K,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,z.jsxs)(S,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function q({active:e,onClick:t,icon:n,label:r}){return(0,z.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function J({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:a,wordWrap:s,onToggleWordWrap:c,filePath:d,projectName:f,className:p}){return(0,z.jsxs)(`div`,{className:p,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:t===`edit`,onClick:()=>n(`edit`),icon:i,label:`Edit`}),(0,z.jsx)(q,{active:t===`preview`,onClick:()=>n(`preview`),icon:P,label:`Preview`})]}),e===`csv`&&a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(q,{active:r===`table`,onClick:()=>a(`table`),icon:l,label:`Table`}),(0,z.jsx)(q,{active:r===`raw`,onClick:()=>a(`raw`),icon:i,label:`Raw`})]}),(0,z.jsx)(q,{active:s,onClick:c,icon:u,label:`Wrap`}),d&&f&&(0,z.jsx)(q,{active:!1,onClick:()=>y(f,d),icon:o,label:`Download`})]})}var Y=(0,R.lazy)(()=>p(()=>import(`./csv-preview-Doo6XsK0.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([0,1,2,3,4,5,6,7]))),X=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Z=new Set([`db`,`sqlite`,`sqlite3`]);function Q(e){return e.split(`.`).pop()?.toLowerCase()??``}function ee(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[Q(e)]??`plaintext`}function $({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,a]=(0,R.useState)(null),[o,s]=(0,R.useState)(`utf-8`),[l,u]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[_,y]=(0,R.useState)(!1),x=(0,R.useRef)(null),S=(0,R.useRef)(``),C=(0,R.useRef)(null),{tabs:w,updateTab:T}=c(),{wordWrap:E,toggleWordWrap:D}=b(),O=f(),k=w.find(e=>e.id===t),j=n?Q(n):``,M=X.has(j),N=j===`pdf`,P=Z.has(j),F=j===`md`||j===`mdx`,I=j===`csv`,[B,V]=(0,R.useState)(`preview`),[H,U]=(0,R.useState)(`table`);(0,R.useEffect)(()=>{P&&t&&T(t,{type:`sqlite`})},[P,t,T]);let G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(!n||!G&&!r)return;if(M||N){u(!1);return}u(!0),m(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${g(r)}/files/read?path=${encodeURIComponent(n)}`;return v.get(e).then(e=>{a(e.content),e.encoding&&s(e.encoding),S.current=e.content,u(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{x.current&&clearTimeout(x.current)}},[n,r,M,N,G]),(0,R.useEffect)(()=>{if(!k)return;let e=n?h(n):`Untitled`,t=_?`${e} \u25CF`:e;k.title!==t&&T(k.id,{title:t})},[_]);let K=(0,R.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await v.put(`/api/fs/write`,{path:n,content:e}):await v.put(`${g(r)}/files/write`,{path:n,content:e}),y(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;a(t),S.current=t,y(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>K(S.current),1e3)}let $=e?.lineNumber,ie=(0,R.useCallback)((e,t)=>{C.current=e,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>b.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):l?(0,z.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,z.jsx)(A,{className:`size-5 animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):p?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p}):M?(0,z.jsx)(ne,{filePath:n,projectName:r}):N?(0,z.jsx)(re,{filePath:n,projectName:r}):o===`base64`?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,z.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[n&&r&&t&&(0,z.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(W,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,z.jsx)(J,{ext:j,mdMode:B,onMdModeChange:V,csvMode:H,onCsvModeChange:U,wordWrap:E,onToggleWordWrap:D,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),I&&H===`table`?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,z.jsx)(Y,{content:i??``,onContentChange:q,wordWrap:E})}):F&&B===`preview`?(0,z.jsx)(te,{content:i??``}):(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,z.jsx)(d,{height:`100%`,language:ee(n),value:i??``,onChange:q,onMount:ie,theme:O,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:E?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})})]})}function te({content:e}){return(0,z.jsx)(a,{content:e,className:`flex-1 overflow-auto p-4`})}function ne({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);return(0,R.useEffect)(()=>{let n,i=`${g(t)}/files/raw?path=${encodeURIComponent(e)}`,o=_();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,z.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}function re({filePath:e,projectName:t}){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1);(0,R.useEffect)(()=>{let n,i=`${g(t)}/files/raw?path=${encodeURIComponent(e)}`,o=_();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let o=(0,R.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,z.jsx)(L,{className:`size-10 text-text-subtle`}),(0,z.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,z.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,z.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,z.jsx)(s,{className:`size-3`}),` Open in new tab`]})]}),(0,z.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(A,{className:`size-5 animate-spin text-text-subtle`})})}export{$ as CodeEditor};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./chevron-right-5HgK6l7K.js";import{a as r,i,n as a,r as o,t as s}from"./dist-wVfsYfHS.js";import{t as c}from"./jsx-runtime-O3jQaKZd.js";import{t as l}from"./api-client-BfBM3I7n.js";import{Et as u,et as d,lt as f,yt as p}from"./index-E0N-qark.js";import{n as m,r as h,t as g}from"./lib-BQ34Db2e.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,d=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${d}&page=${o??h}&limit=100`),l.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${d}`)]);s(n),u(r),b(e,c,d,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),u(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:d,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await l.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=c(),C={postgres:s,sqlite:a};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||u.current||(u.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(p,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(d,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${c?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${c?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),c&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??s,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:r,page:i,onPageChange:a,onCellUpdate:o}){let[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(``),p=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{c({rowIdx:e,col:t}),d(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!s||!e||!p)return;let t=e.rows[s.rowIdx];if(!t)return;let n=t[s.col];String(n??``)!==l&&o(p,t[p],s.col,l===``?null:l),c(null)},[s,l,e,p,o]),b=(0,_.useCallback)(()=>c(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=s?.rowIdx===t.index&&s?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:l,onChange:e=>d(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>p&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,s,l,y,b,v,p]),C=m({data:e?.rows??[],columns:x,getCoreRowModel:h()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:r?(0,S.jsx)(f,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:g(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:g(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(u,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(n,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:a,loading:s}){let[c,l]=(0,_.useState)(`SELECT * FROM `),u=(0,_.useCallback)(()=>{let e=c.trim();e&&t(e)},[c,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),u())},[u]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(i,{value:c,onChange:l,extensions:[o({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:u,disabled:s,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:s?(0,S.jsx)(f,{className:`size-3.5 animate-spin`}):(0,S.jsx)(r,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[a&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:a}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./chevron-right-5HgK6l7K.js";import{a as r,i,n as a,r as o,t as s}from"./dist-wVfsYfHS.js";import{t as c}from"./jsx-runtime-O3jQaKZd.js";import{t as l}from"./api-client-BfBM3I7n.js";import{Et as u,et as d,lt as f,yt as p}from"./index-B--rhmx5.js";import{n as m,r as h,t as g}from"./lib-BQ34Db2e.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,d=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${d}&page=${o??h}&limit=100`),l.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${d}`)]);s(n),u(r),b(e,c,d,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),u(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:d,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await l.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=c(),C={postgres:s,sqlite:a};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||u.current||(u.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(p,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(d,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${c?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${c?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),c&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??s,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:r,page:i,onPageChange:a,onCellUpdate:o}){let[s,c]=(0,_.useState)(null),[l,d]=(0,_.useState)(``),p=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{c({rowIdx:e,col:t}),d(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!s||!e||!p)return;let t=e.rows[s.rowIdx];if(!t)return;let n=t[s.col];String(n??``)!==l&&o(p,t[p],s.col,l===``?null:l),c(null)},[s,l,e,p,o]),b=(0,_.useCallback)(()=>c(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=s?.rowIdx===t.index&&s?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:l,onChange:e=>d(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>p&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,s,l,y,b,v,p]),C=m({data:e?.rows??[],columns:x,getCoreRowModel:h()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:r?(0,S.jsx)(f,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:g(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:g(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(u,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(n,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:a,loading:s}){let[c,l]=(0,_.useState)(`SELECT * FROM `),u=(0,_.useCallback)(()=>{let e=c.trim();e&&t(e)},[c,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),u())},[u]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(i,{value:c,onChange:l,extensions:[o({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:u,disabled:s,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:s?(0,S.jsx)(f,{className:`size-3.5 animate-spin`}):(0,S.jsx)(r,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[a&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:a}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./columns-2-cEVJHYd7.js";import{i,r as a,t as o}from"./use-monaco-theme-BNtfLGmz.js";import{t as s}from"./jsx-runtime-O3jQaKZd.js";import{i as c,t as l}from"./api-client-BfBM3I7n.js";import{K as u,at as d,gt as f,lt as p}from"./index-E0N-qark.js";var m=n(`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`}]]),h=e(t(),1),g=s();function _(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,s=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=u(),R=o(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});l.get(`${c(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let r=new URLSearchParams({file:t});s&&r.set(`ref`,s),e=`${c(n)}/git/file-diff?${r}`}else if(s||v){let t=new URLSearchParams;s&&t.set(`ref1`,s),v&&t.set(`ref2`,v),e=`${c(n)}/git/diff?${t}`}else e=`${c(n)}/git/diff`;l.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,s,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(p,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(f,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(d,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(r,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(m,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(i,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(a,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(p,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(p,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./columns-2-cEVJHYd7.js";import{i,r as a,t as o}from"./use-monaco-theme-DCA0VEfi.js";import{t as s}from"./jsx-runtime-O3jQaKZd.js";import{i as c,t as l}from"./api-client-BfBM3I7n.js";import{K as u,at as d,gt as f,lt as p}from"./index-B--rhmx5.js";var m=n(`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`}]]),h=e(t(),1),g=s();function _(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,s=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=u(),R=o(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});l.get(`${c(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let r=new URLSearchParams({file:t});s&&r.set(`ref`,s),e=`${c(n)}/git/file-diff?${r}`}else if(s||v){let t=new URLSearchParams;s&&t.set(`ref1`,s),v&&t.set(`ref2`,v),e=`${c(n)}/git/diff?${t}`}else e=`${c(n)}/git/diff`;l.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,s,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(p,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(f,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(d,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(r,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(m,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(i,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(a,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(p,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(p,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(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{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{v as DiffViewer};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-O3jQaKZd.js";import{R as r}from"./index-E0N-qark.js";var i=e(t(),1),a=n(),o=`<script>
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-O3jQaKZd.js";import{R as r}from"./index-B--rhmx5.js";var i=e(t(),1),a=n(),o=`<script>
2
2
  function acquireVsCodeApi(){return{postMessage:function(m){window.parent.postMessage(m,"*")},getState:function(){try{return JSON.parse(sessionStorage.getItem("vscode-state")||"null")}catch{return null}},setState:function(s){sessionStorage.setItem("vscode-state",JSON.stringify(s));return s}}}
3
3
  <\/script>`;function s(e){if(!e)return e;let t=e.indexOf(`<head>`);return t===-1?o+e:e.slice(0,t+6)+o+e.slice(t+6)}function c({metadata:e}){let t=e?.panelId,n=r(e=>t?e.webviewPanels[t]:void 0),o=(0,i.useRef)(null),c=s(n?.html??``);return(0,i.useEffect)(()=>{let e=e=>{o.current&&e.source===o.current.contentWindow&&window.dispatchEvent(new CustomEvent(`ext:webview:send`,{detail:{panelId:t,message:e.data}}))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[t]),(0,i.useEffect)(()=>{let e=e=>{let{panelId:n,message:r}=e.detail;n===t&&o.current?.contentWindow?.postMessage(r,`*`)};return window.addEventListener(`ext:webview:message`,e),()=>window.removeEventListener(`ext:webview:message`,e)},[t]),n?(0,a.jsx)(`div`,{className:`h-full w-full relative`,children:(0,a.jsx)(`iframe`,{ref:o,srcDoc:c,sandbox:`allow-scripts`,className:`w-full h-full border-0 bg-white dark:bg-zinc-900`,title:n.title})}):(0,a.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm text-text-subtle`,children:`Webview panel not found`})}export{c as ExtensionWebview};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{A as r}from"./dist-C4urk5JP.js";import{l as i,t as a}from"./tab-store-CeOacjuH.js";import{t as o}from"./tag-CFrhsWuM.js";import{t as s}from"./jsx-runtime-O3jQaKZd.js";import{t as c}from"./utils-BNytJOb1.js";import{i as l,t as u}from"./api-client-BfBM3I7n.js";import{$ as d,A as f,Dt as p,E as m,F as h,I as g,M as _,Mt as v,N as y,O as b,Ot as x,P as S,Q as C,T as w,Y as T,Z as E,bt as D,dt as O,et as k,j as A,k as j,lt as M,q as N,w as P}from"./index-E0N-qark.js";var F=n(`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`}]]),ee=n(`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`}]]),I=e(t(),1),L=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function te(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function ne(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function re(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=L[c%L.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=L[e%L.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=L[e%L.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function R(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`}var z=200;function B(e){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(!0),[o,s]=(0,I.useState)(!1),[c,d]=(0,I.useState)(!0),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)([]),[b,x]=(0,I.useState)(!1),[S,C]=(0,I.useState)(`__all__`),[w,T]=(0,I.useState)(``),[E,D]=(0,I.useState)(!1),{openTab:O}=a(),k=(0,I.useRef)(0),A=(0,I.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(z,k.current),r=await u.get(`${l(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,d(r.commits.length>=t),p(null)}catch(e){p(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,I.useCallback)(async()=>{if(!(!e||o||!c))try{s(!0);let t=k.current,r=await u.get(`${l(e)}/git/graph?max=${z}&skip=${t}`);if(r.commits.length===0){d(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,d(r.commits.length>=z)}catch(e){p(e instanceof Error?e.message:`Failed to load more`)}finally{s(!1)}},[e,o,c]);(0,I.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await u.post(`${l(e)}${t}`,n),await A()}catch(e){p(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),ee=e=>M(`/git/revert`,{hash:e}),L=e=>M(`/git/merge`,{source:e}),R=e=>M(`/git/branch/delete`,{name:e}),B=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await u.get(`${l(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await u.get(`${l(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,I.useMemo)(()=>te(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,I.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,I.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,I.useMemo)(()=>ne(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:o,hasMore:c,error:f,acting:m,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:ee,handleMerge:L,handleDeleteBranch:R,handlePushBranch:B,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,I.useMemo)(()=>re(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,I.useState)(e),r=(0,I.useRef)(e);r.current=t;let i=(0,I.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=s();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:i,onSearchQueryChange:a,showSearch:o,onToggleSearch:s,onFetch:c,onRefresh:l,onOpenSettings:u,loading:d,acting:f,projectName:m}){let h=e.filter(e=>!e.remote),[g,_]=(0,I.useState)(!1),[v,y]=(0,I.useState)(``),b=(0,I.useRef)(null);(0,I.useEffect)(()=>{if(!g)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(_(!1),y(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let x=v?h.filter(e=>e.name.toLowerCase().includes(v.toLowerCase())):h,S=t===`__all__`?`Show All`:h.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:m??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:b,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{_(e=>!e),y(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:S}),(0,H.jsx)(p,{className:`size-3 opacity-50`})]}),g&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(P,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),_(!1)}}),x.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),_(!1)}},e.name)),x.length===0&&v&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),o&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(P,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:i,onChange:e=>a(e.target.value),autoFocus:!0}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:s,children:(0,H.jsx)(N,{className:`size-3`})})]}),!o&&(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:s,title:`Find`,children:(0,H.jsx)(C,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:u,title:`Settings`,children:(0,H.jsx)(E,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:c,disabled:f,title:`Fetch`,children:(0,H.jsx)(r,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:l,disabled:f,title:`Refresh`,children:(0,H.jsx)(k,{className:`size-3.5 ${d?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(x,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=L[r%L.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:a,currentBranch:s,onCheckout:c,onMerge:l,onPush:u,onCreatePr:d,onDelete:f}){return t===`tag`?(0,H.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,H.jsx)(o,{className:`size-2.5`}),e]}):(0,H.jsxs)(_,{children:[(0,H.jsx)(g,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${a}`:`1px solid ${a}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?a:`${a}30`,color:r?`#fff`:a},children:[(0,H.jsx)(O,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${a}40`,color:a,backgroundColor:`${a}15`},children:e},e))]})}),(0,H.jsxs)(y,{children:[(0,H.jsx)(S,{onClick:()=>c(e),children:`Checkout`}),(0,H.jsxs)(S,{onClick:()=>l(e),disabled:e===s?.name,children:[(0,H.jsx)(ee,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{onClick:()=>u(e),children:[(0,H.jsx)(v,{className:`size-3`}),`Push`]}),(0,H.jsxs)(S,{onClick:()=>d(e),children:[(0,H.jsx)(i,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{variant:`destructive`,onClick:()=>f(e),disabled:e===s?.name,children:[(0,H.jsx)(T,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:i,currentBranch:a,onSelect:s,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:f,onDeleteBranch:p,onPushBranch:m,onCreatePr:v,onOpenCreateBranch:b,onOpenCreateTag:x,onOpenDiff:C,onCopyHash:w}){let T=L[t%L.length],E=i.filter(e=>e.type===`branch`),k=i.filter(e=>e.type===`tag`);return(0,H.jsxs)(_,{children:[(0,H.jsx)(g,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:s,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[E.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:T,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:v,onDelete:p},`branch-${e.name}`)),k.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:T,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:v,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:R(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(y,{children:[(0,H.jsx)(S,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(S,{onClick:()=>b(e.hash),children:[(0,H.jsx)(O,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(S,{onClick:()=>u(e.hash),children:[(0,H.jsx)(d,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(S,{onClick:()=>x(e.hash),children:[(0,H.jsx)(o,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(h,{}),(0,H.jsx)(S,{onClick:C,children:`View Diff`}),(0,H.jsxs)(S,{onClick:w,children:[(0,H.jsx)(D,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:o}){let{openTab:s}=a();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>o(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${c(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,o]=(0,I.useState)(``),s=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(w,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(m,{children:[(0,H.jsx)(j,{children:(0,H.jsx)(f,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(P,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s()},autoFocus:!0}),(0,H.jsxs)(b,{children:[(0,H.jsx)(A,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(A,{disabled:!a.trim(),onClick:s,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(w,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(m,{className:`max-w-md`,children:[(0,H.jsx)(j,{children:(0,H.jsx)(f,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=B(t),[r,i]=(0,I.useState)({type:null}),[a,o]=(0,I.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,I.useState)(s),u=(0,I.useRef)(s);u.current=c;let d=(0,I.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.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)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,I.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,I.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(M,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(M,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(A,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{A as r}from"./dist-C4urk5JP.js";import{l as i,t as a}from"./tab-store-CeOacjuH.js";import{t as o}from"./tag-CFrhsWuM.js";import{t as s}from"./jsx-runtime-O3jQaKZd.js";import{t as c}from"./utils-BNytJOb1.js";import{i as l,t as u}from"./api-client-BfBM3I7n.js";import{$ as d,A as f,Dt as p,E as m,F as h,I as g,M as _,Mt as v,N as y,O as b,Ot as x,P as S,Q as C,T as w,Y as T,Z as E,bt as D,dt as O,et as k,j as A,k as j,lt as M,q as N,w as P}from"./index-B--rhmx5.js";var F=n(`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`}]]),ee=n(`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`}]]),I=e(t(),1),L=[`#0085d9`,`#d73a49`,`#6f42c1`,`#2cbe4e`,`#e36209`,`#005cc5`,`#b31d28`,`#5a32a3`,`#22863a`,`#cb2431`];function te(e){let t=new Map;if(!e)return t;let n=new Set;for(let t of e.branches)if(!t.remote)for(let e of t.remotes)n.add(`remotes/${e}/${t.name}`);for(let r of e.branches)if(r.remote){if(n.has(r.name))continue;let e=t.get(r.commitHash)??[],i=r.name.replace(/^remotes\//,``);e.push({name:i,type:`branch`,remotes:[],current:!1}),t.set(r.commitHash,e)}else{let e=t.get(r.commitHash)??[];e.push({name:r.name,type:`branch`,remotes:r.remotes,current:r.current}),t.set(r.commitHash,e)}for(let n of e.commits)for(let e of n.refs)if(e.startsWith(`tag: `)){let r=e.replace(`tag: `,``),i=t.get(n.hash)??[];i.push({name:r,type:`tag`,remotes:[],current:!1}),t.set(n.hash,i)}return t}function ne(e){let t=new Map;if(!e)return{laneMap:t,maxLane:0,unloadedParentLanes:new Map};let n=0,r=0,i=new Map,a=new Set(e.commits.map(e=>e.hash)),o=[],s=()=>o.length>0?(o.sort((e,t)=>e-t),o.shift()):n++;for(let n of e.commits){let e=i.get(n.hash);e===void 0&&(e=s()),t.set(n.hash,e),e>r&&(r=e),i.delete(n.hash);let a=!1;for(let t=0;t<n.parents.length;t++){let o=n.parents[t];if(!i.has(o))if(t===0)i.set(o,e),a=!0;else{let e=s();i.set(o,e),e>r&&(r=e)}}a||o.push(e)}let c=new Map;for(let[e,t]of i)a.has(e)||c.set(e,t);return{laneMap:t,maxLane:r,unloadedParentLanes:c}}function re(e,t,n,r){if(!e)return[];let i=[],a=new Set(e.commits.map(e=>e.hash));for(let o=0;o<e.commits.length;o++){let s=e.commits[o],c=t.get(s.hash)??0,l=L[c%L.length];for(let u of s.parents){let d=e.commits.findIndex(e=>e.hash===u);if(d>=0){let e=t.get(u)??0,n=L[e%L.length],r=c*16+16/2,a=o*24+24/2,f=e*16+16/2,p=d*24+24/2,m,h=s.parents.indexOf(u)>0;if(r===f)m=`M ${r} ${a} L ${f} ${p}`;else if(h){let e=a+24;m=`M ${r} ${a} C ${r} ${e} ${f} ${a} ${f} ${e} L ${f} ${p}`}else{let e=p-24;m=`M ${r} ${a} L ${r} ${e} C ${r} ${p} ${f} ${e} ${f} ${p}`}let g=s.parents.indexOf(u)===0?l:n;i.push({d:m,color:g})}else if(!a.has(u)){let e=n.get(u)??c,t=L[e%L.length],a=c*16+16/2,s=o*24+24/2,d=e*16+16/2;if(a===d)i.push({d:`M ${a} ${s} L ${a} ${r}`,color:l});else{let e=s+24,n=`M ${a} ${s} C ${a} ${e} ${d} ${s} ${d} ${e} L ${d} ${r}`;i.push({d:n,color:t})}}}}return i}function R(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`}var z=200;function B(e){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(!0),[o,s]=(0,I.useState)(!1),[c,d]=(0,I.useState)(!0),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)([]),[b,x]=(0,I.useState)(!1),[S,C]=(0,I.useState)(`__all__`),[w,T]=(0,I.useState)(``),[E,D]=(0,I.useState)(!1),{openTab:O}=a(),k=(0,I.useRef)(0),A=(0,I.useCallback)(async()=>{if(e)try{i(!0);let t=Math.max(z,k.current),r=await u.get(`${l(e)}/git/graph?max=${t}`);n(r),k.current=r.commits.length,d(r.commits.length>=t),p(null)}catch(e){p(e instanceof Error?e.message:`Failed to fetch graph`)}finally{i(!1)}},[e]),j=(0,I.useCallback)(async()=>{if(!(!e||o||!c))try{s(!0);let t=k.current,r=await u.get(`${l(e)}/git/graph?max=${z}&skip=${t}`);if(r.commits.length===0){d(!1);return}n(e=>{if(!e)return r;let t=new Set(e.commits.map(e=>e.hash)),n=r.commits.filter(e=>!t.has(e.hash)),i=new Set(e.branches.map(e=>e.name)),a=r.branches.filter(e=>!i.has(e.name));return{commits:[...e.commits,...n],branches:[...e.branches,...a],head:e.head}}),k.current=t+r.commits.length,d(r.commits.length>=z)}catch(e){p(e instanceof Error?e.message:`Failed to load more`)}finally{s(!1)}},[e,o,c]);(0,I.useEffect)(()=>{A();let e=setInterval(A,1e4);return()=>clearInterval(e)},[A]);let M=async(t,n)=>{if(e){h(!0);try{await u.post(`${l(e)}${t}`,n),await A()}catch(e){p(e instanceof Error?e.message:`Action failed`)}finally{h(!1)}}},N=()=>M(`/git/fetch`,{}),P=e=>M(`/git/checkout`,{ref:e}),F=e=>M(`/git/cherry-pick`,{hash:e}),ee=e=>M(`/git/revert`,{hash:e}),L=e=>M(`/git/merge`,{source:e}),R=e=>M(`/git/branch/delete`,{name:e}),B=e=>M(`/git/push`,{branch:e}),V=(e,t)=>M(`/git/tag`,{name:e,hash:t}),H=e=>navigator.clipboard.writeText(e),U=async(e,n)=>{if(t?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete and recreate from this commit?`))return;await M(`/git/branch/delete`,{name:e})}await M(`/git/branch/create`,{name:e,from:n})},W=async t=>{if(e)try{let n=await u.get(`${l(e)}/git/pr-url?branch=${encodeURIComponent(t)}`);n.url&&window.open(n.url,`_blank`)}catch{}},G=async t=>{if(g?.hash===t.hash){_(null);return}_(t),x(!0);try{let n=t.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await u.get(`${l(e)}/git/diff-stat?${r}ref2=${encodeURIComponent(t.hash)}`);y(Array.isArray(i)?i:[])}catch{y([])}finally{x(!1)}},K=t=>O({type:`git-diff`,title:`Diff ${t.abbreviatedHash}`,closable:!0,metadata:{projectName:e,ref1:t.parents[0]??void 0,ref2:t.hash},projectId:e??null}),q=(0,I.useMemo)(()=>te(t),[t]),J=t?.branches.find(e=>e.current),Y=t?.head??``,X=(0,I.useMemo)(()=>{if(!t)return[];let e=t.commits;if(S!==`__all__`){let n=t.branches.find(e=>e.name===S);if(n){let r=new Set,i=[n.commitHash];for(;i.length>0;){let e=i.pop();if(r.has(e))continue;r.add(e);let n=t.commits.find(t=>t.hash===e);n&&i.push(...n.parents)}e=e.filter(e=>r.has(e.hash))}}if(w.trim()){let t=w.toLowerCase();e=e.filter(e=>e.subject.toLowerCase().includes(t)||e.authorName.toLowerCase().includes(t)||e.abbreviatedHash.includes(t)||e.hash.includes(t))}return e},[t,S,w]),Z=(0,I.useMemo)(()=>t?{...t,commits:X}:null,[t,X]),Q=(0,I.useMemo)(()=>ne(Z),[Z]),$=X.length*24+48;return{data:t,loading:r,loadingMore:o,hasMore:c,error:f,acting:m,selectedCommit:g,setSelectedCommit:_,commitFiles:v,loadingDetail:b,branchFilter:S,setBranchFilter:C,searchQuery:w,setSearchQuery:T,showSearch:E,setShowSearch:D,fetchGraph:A,fetchFromRemotes:N,loadMore:j,handleCheckout:P,handleCherryPick:F,handleRevert:ee,handleMerge:L,handleDeleteBranch:R,handlePushBranch:B,handleCreateBranch:U,handleCreateTag:V,handleCreatePr:W,copyHash:H,selectCommit:G,openDiffForCommit:K,commitLabels:q,currentBranch:J,headHash:Y,filteredCommits:X,filteredLanes:Q,svgHeight:$,svgPaths:(0,I.useMemo)(()=>re(Z,Q.laneMap,Q.unloadedParentLanes,$),[Z,Q.laneMap,Q.unloadedParentLanes,$])}}function V(e){let[t,n]=(0,I.useState)(e),r=(0,I.useRef)(e);r.current=t;let i=(0,I.useRef)(!1);return{widths:t,startResize:(e,t)=>{i.current=!0;let a=r.current[e]??80,o=r=>{if(!i.current)return;let o=`touches`in r?r.touches[0].clientX:r.clientX,s=Math.max(40,a+o-t);n(t=>({...t,[e]:s}))},s=()=>{i.current=!1,window.removeEventListener(`mousemove`,o),window.removeEventListener(`mouseup`,s),window.removeEventListener(`touchmove`,o),window.removeEventListener(`touchend`,s)};window.addEventListener(`mousemove`,o),window.addEventListener(`mouseup`,s),window.addEventListener(`touchmove`,o,{passive:!1}),window.addEventListener(`touchend`,s)}}}var H=s();function U({branches:e,branchFilter:t,onBranchFilterChange:n,searchQuery:i,onSearchQueryChange:a,showSearch:o,onToggleSearch:s,onFetch:c,onRefresh:l,onOpenSettings:u,loading:d,acting:f,projectName:m}){let h=e.filter(e=>!e.remote),[g,_]=(0,I.useState)(!1),[v,y]=(0,I.useState)(``),b=(0,I.useRef)(null);(0,I.useEffect)(()=>{if(!g)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(_(!1),y(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let x=v?h.filter(e=>e.name.toLowerCase().includes(v.toLowerCase())):h,S=t===`__all__`?`Show All`:h.find(e=>e.name===t)?.name??`Show All`;return(0,H.jsx)(`div`,{className:`border-b bg-background`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground shrink-0`,children:[(0,H.jsx)(`span`,{className:`font-semibold`,children:`Repo:`}),(0,H.jsx)(`span`,{className:`font-medium text-foreground truncate max-w-[120px]`,children:m??`—`})]}),(0,H.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,ref:b,children:[(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 h-6 px-2 text-xs border rounded-md bg-transparent hover:bg-muted/50`,onClick:()=>{_(e=>!e),y(``)},children:[(0,H.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:`Branches:`}),(0,H.jsx)(`span`,{className:`max-w-[100px] truncate`,children:S}),(0,H.jsx)(p,{className:`size-3 opacity-50`})]}),g&&(0,H.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 z-50 w-[220px] rounded-md border bg-popover shadow-md`,children:[(0,H.jsx)(`div`,{className:`p-1.5`,children:(0,H.jsx)(P,{className:`h-6 text-xs px-2`,placeholder:`Filter branches...`,value:v,onChange:e=>y(e.target.value),autoFocus:!0})}),(0,H.jsxs)(`div`,{className:`max-h-[200px] overflow-y-auto p-1`,children:[(0,H.jsx)(W,{label:`Show All`,selected:t===`__all__`,onClick:()=>{n(`__all__`),_(!1)}}),x.map(e=>(0,H.jsx)(W,{label:e.name,current:e.current,selected:t===e.name,onClick:()=>{n(e.name),_(!1)}},e.name)),x.length===0&&v&&(0,H.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-muted-foreground`,children:`No branches found`})]})]})]}),(0,H.jsx)(`div`,{className:`flex-1`}),o&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(P,{className:`h-6 text-xs w-[160px] px-2`,placeholder:`Search commits...`,value:i,onChange:e=>a(e.target.value),autoFocus:!0}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:s,children:(0,H.jsx)(N,{className:`size-3`})})]}),!o&&(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:s,title:`Find`,children:(0,H.jsx)(C,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:u,title:`Settings`,children:(0,H.jsx)(E,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:c,disabled:f,title:`Fetch`,children:(0,H.jsx)(r,{className:`size-3.5`})}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:l,disabled:f,title:`Refresh`,children:(0,H.jsx)(k,{className:`size-3.5 ${d?`animate-spin`:``}`})})]})})}function W({label:e,selected:t,current:n,onClick:r}){return(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 w-full px-2 py-1 text-xs rounded-sm hover:bg-accent hover:text-accent-foreground text-left`,onClick:r,children:[(0,H.jsx)(x,{className:`size-3 shrink-0 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate flex-1`,children:e}),n&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`current`})]})}function G({commits:e,laneMap:t,svgPaths:n,width:r,height:i,headHash:a}){return(0,H.jsxs)(`svg`,{width:r,height:i,children:[n.map((e,t)=>(0,H.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),e.map((e,n)=>{let r=t.get(e.hash)??0,i=r*16+16/2,o=n*24+24/2,s=L[r%L.length],c=e.hash===a;return(0,H.jsx)(`circle`,{cx:i,cy:o,r:c?5:4,fill:s,stroke:c?`#000`:`none`,strokeWidth:c?2:0},e.hash)})]})}function K({name:e,type:t,remotes:n,isCurrent:r,color:a,currentBranch:s,onCheckout:c,onMerge:l,onPush:u,onCreatePr:d,onDelete:f}){return t===`tag`?(0,H.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,H.jsx)(o,{className:`size-2.5`}),e]}):(0,H.jsxs)(_,{children:[(0,H.jsx)(g,{asChild:!0,children:(0,H.jsxs)(`span`,{className:`inline-flex items-center rounded text-[10px] font-medium shrink-0 cursor-context-menu overflow-hidden`,style:{border:r?`1.5px solid ${a}`:`1px solid ${a}50`},children:[(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5`,style:{backgroundColor:r?a:`${a}30`,color:r?`#fff`:a},children:[(0,H.jsx)(O,{className:`size-2.5`}),e]}),n.map(e=>(0,H.jsx)(`span`,{className:`px-1.5 py-0.5 italic opacity-70`,style:{borderLeft:`1px solid ${a}40`,color:a,backgroundColor:`${a}15`},children:e},e))]})}),(0,H.jsxs)(y,{children:[(0,H.jsx)(S,{onClick:()=>c(e),children:`Checkout`}),(0,H.jsxs)(S,{onClick:()=>l(e),disabled:e===s?.name,children:[(0,H.jsx)(ee,{className:`size-3`}),`Merge into current`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{onClick:()=>u(e),children:[(0,H.jsx)(v,{className:`size-3`}),`Push`]}),(0,H.jsxs)(S,{onClick:()=>d(e),children:[(0,H.jsx)(i,{className:`size-3`}),`Create PR`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{variant:`destructive`,onClick:()=>f(e),disabled:e===s?.name,children:[(0,H.jsx)(T,{className:`size-3`}),`Delete`]})]})]})}function q({commit:e,lane:t,isSelected:n,isHead:r,labels:i,currentBranch:a,onSelect:s,onCheckout:c,onCherryPick:l,onRevert:u,onMerge:f,onDeleteBranch:p,onPushBranch:m,onCreatePr:v,onOpenCreateBranch:b,onOpenCreateTag:x,onOpenDiff:C,onCopyHash:w}){let T=L[t%L.length],E=i.filter(e=>e.type===`branch`),k=i.filter(e=>e.type===`tag`);return(0,H.jsxs)(_,{children:[(0,H.jsx)(g,{asChild:!0,children:(0,H.jsxs)(`tr`,{className:`hover:bg-muted/50 cursor-pointer border-b border-border/20 ${n?`bg-primary/10`:``} ${r?`font-medium`:``}`,style:{height:`24px`},onClick:s,children:[(0,H.jsx)(`td`,{className:`px-2 truncate max-w-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[E.map(e=>(0,H.jsx)(K,{name:e.name,type:`branch`,remotes:e.remotes,isCurrent:e.current,color:T,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:v,onDelete:p},`branch-${e.name}`)),k.map(e=>(0,H.jsx)(K,{name:e.name,type:`tag`,remotes:[],isCurrent:!1,color:T,currentBranch:a,onCheckout:c,onMerge:f,onPush:m,onCreatePr:v,onDelete:p},`tag-${e.name}`)),(0,H.jsx)(`span`,{className:`truncate text-xs`,children:e.subject})]})}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground whitespace-nowrap shrink-0`,children:R(e.authorDate)}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground truncate max-w-[120px]`,children:e.authorName}),(0,H.jsx)(`td`,{className:`px-2 text-xs text-muted-foreground font-mono whitespace-nowrap`,children:e.abbreviatedHash})]})}),(0,H.jsxs)(y,{children:[(0,H.jsx)(S,{onClick:()=>c(e.hash),children:`Checkout`}),(0,H.jsxs)(S,{onClick:()=>b(e.hash),children:[(0,H.jsx)(O,{className:`size-3`}),`Create Branch...`]}),(0,H.jsx)(h,{}),(0,H.jsxs)(S,{onClick:()=>l(e.hash),children:[(0,H.jsx)(F,{className:`size-3`}),`Cherry Pick`]}),(0,H.jsxs)(S,{onClick:()=>u(e.hash),children:[(0,H.jsx)(d,{className:`size-3`}),`Revert`]}),(0,H.jsxs)(S,{onClick:()=>x(e.hash),children:[(0,H.jsx)(o,{className:`size-3`}),`Create Tag...`]}),(0,H.jsx)(h,{}),(0,H.jsx)(S,{onClick:C,children:`View Diff`}),(0,H.jsxs)(S,{onClick:w,children:[(0,H.jsx)(D,{className:`size-3`}),`Copy Hash`]})]})]})}function J({commit:e,files:t,loadingDetail:n,projectName:r,onClose:i,copyHash:o}){let{openTab:s}=a();return(0,H.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,H.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e.abbreviatedHash,` — `,e.subject]}),(0,H.jsx)(A,{variant:`ghost`,size:`icon-xs`,onClick:i,children:`✕`})]}),(0,H.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Author`}),(0,H.jsxs)(`span`,{children:[e.authorName,` <`,e.authorEmail,`>`]})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Date`}),(0,H.jsx)(`span`,{children:new Date(e.authorDate).toLocaleString()})]}),(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Hash`}),(0,H.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>o(e.hash),children:e.hash})]}),e.parents.length>0&&(0,H.jsxs)(`div`,{className:`flex gap-4`,children:[(0,H.jsx)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:`Parents`}),(0,H.jsx)(`span`,{className:`font-mono`,children:e.parents.map(e=>e.slice(0,7)).join(`, `)})]}),e.body&&(0,H.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:e.body})]}),(0,H.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:n?`Loading files...`:`${t.length} file${t.length===1?``:`s`} changed`}),t.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>s({type:`git-diff`,title:`Diff ${c(t.path)}`,closable:!0,metadata:{projectName:r,ref1:e.parents[0]??void 0,ref2:e.hash,filePath:t.path},projectId:r}),children:[(0,H.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.path}),t.additions>0&&(0,H.jsxs)(`span`,{className:`text-green-500`,children:[`+`,t.additions]}),t.deletions>0&&(0,H.jsxs)(`span`,{className:`text-red-500`,children:[`-`,t.deletions]})]},t.path))]})]})}function Y({type:e,hash:t,onClose:n,onCreateBranch:r,onCreateTag:i}){let[a,o]=(0,I.useState)(``),s=()=>{a.trim()&&(e===`branch`?r(a.trim(),t):i(a.trim(),t),n())};return(0,H.jsx)(w,{open:e!==null,onOpenChange:e=>{e||n()},children:(0,H.jsxs)(m,{children:[(0,H.jsx)(j,{children:(0,H.jsx)(f,{children:e===`branch`?`Create Branch`:`Create Tag`})}),(0,H.jsx)(P,{placeholder:e===`branch`?`Branch name`:`Tag name`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s()},autoFocus:!0}),(0,H.jsxs)(b,{children:[(0,H.jsx)(A,{variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(A,{disabled:!a.trim(),onClick:s,children:`Create`})]})]})})}function X({open:e,onClose:t,projectName:n,branches:r}){let i=r.filter(e=>!e.remote),a=r.filter(e=>e.remote),o=new Map;for(let e of a){let t=e.name.replace(/^remotes\//,``),n=t.indexOf(`/`);if(n<0)continue;let r=t.slice(0,n),i=t.slice(n+1),a=o.get(r)??[];a.push(i),o.set(r,a)}return(0,H.jsx)(w,{open:e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(m,{className:`max-w-md`,children:[(0,H.jsx)(j,{children:(0,H.jsx)(f,{children:`Repository Settings`})}),(0,H.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,H.jsxs)(Z,{title:`General`,children:[(0,H.jsx)(Q,{label:`Name`,value:n}),(0,H.jsx)(Q,{label:`Branches`,value:`${i.length} local, ${a.length} remote`})]}),(0,H.jsx)(Z,{title:`Local Branches`,children:i.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs ${e.current?`font-semibold text-primary`:`text-foreground`}`,children:e.name}),e.current&&(0,H.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`HEAD`}),e.remotes.length>0&&(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,e.remotes.join(`, `),`)`]})]},e.name))}),(0,H.jsxs)(Z,{title:`Remotes`,children:[[...o.entries()].map(([e,t])=>(0,H.jsxs)(`div`,{className:`py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,H.jsxs)(`span`,{className:`text-[10px] text-muted-foreground ml-2`,children:[t.length,` branch`,t.length===1?``:`es`]})]},e)),o.size===0&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No remotes configured`})]})]})]})})}function Z({title:e,children:t}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5`,children:e}),(0,H.jsx)(`div`,{className:`pl-1`,children:t})]})}function Q({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-3 py-0.5`,children:[(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground w-16 shrink-0`,children:e}),(0,H.jsx)(`span`,{className:`text-xs`,children:t})]})}function $({metadata:e}){let t=e?.projectName,n=B(t),[r,i]=(0,I.useState)({type:null}),[a,o]=(0,I.useState)(!1),s=(typeof window<`u`&&window.innerWidth<768?6:10)*16+16,[c,l]=(0,I.useState)(s),u=(0,I.useRef)(s);u.current=c;let d=(0,I.useRef)(!1),f=e=>{d.current=!0;let t=u.current,n=n=>{if(!d.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;l(Math.max(40,t+r-e))},r=()=>{d.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)},{widths:p,startResize:m}=V({date:80,author:120,commit:70}),h=(0,I.useRef)(n.loadMore);h.current=n.loadMore;let g=(0,I.useCallback)(e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<200&&h.current()},[]);return t?n.loading&&!n.data?(0,H.jsx)(oe,{}):n.error&&!n.data?(0,H.jsx)(se,{error:n.error,onRetry:n.fetchGraph}):(0,H.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,H.jsx)(U,{branches:n.data?.branches??[],branchFilter:n.branchFilter,onBranchFilterChange:n.setBranchFilter,searchQuery:n.searchQuery,onSearchQueryChange:n.setSearchQuery,showSearch:n.showSearch,onToggleSearch:()=>n.setShowSearch(!n.showSearch),onFetch:n.fetchFromRemotes,onRefresh:n.fetchGraph,onOpenSettings:()=>o(!0),loading:n.loading,acting:n.acting,projectName:t}),n.error&&(0,H.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:n.error}),(0,H.jsx)(`div`,{className:`flex-1 overflow-auto`,onScroll:g,children:(0,H.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,children:[(0,H.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background relative overflow-hidden`,style:{width:`${c}px`},children:[(0,H.jsx)(`div`,{className:`text-[11px] font-semibold text-muted-foreground px-2 border-b bg-background sticky top-0 z-20`,style:{height:`24px`,lineHeight:`24px`},children:`Graph`}),(0,H.jsx)(G,{commits:n.filteredCommits,laneMap:n.filteredLanes.laneMap,svgPaths:n.svgPaths,width:(n.filteredLanes.maxLane+2)*16,height:n.svgHeight,headHash:n.headHash}),(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),f(e.clientX)},onTouchStart:e=>f(e.touches[0].clientX)})]}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-[400px]`,children:[(0,H.jsxs)(`table`,{className:`w-full border-collapse text-xs`,style:{tableLayout:`fixed`},children:[(0,H.jsxs)(`colgroup`,{children:[(0,H.jsx)(`col`,{}),(0,H.jsx)(`col`,{style:{width:`${p.date}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.author}px`}}),(0,H.jsx)(`col`,{style:{width:`${p.commit}px`}})]}),(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-background`,children:(0,H.jsxs)(`tr`,{className:`border-b text-[11px] font-semibold text-muted-foreground`,style:{height:`24px`},children:[(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Description`}),(0,H.jsx)(ie,{label:`Date`,colKey:`date`,onStartResize:m}),(0,H.jsx)(ie,{label:`Author`,colKey:`author`,onStartResize:m}),(0,H.jsx)(`th`,{className:`text-left px-2 font-semibold`,children:`Commit`})]})}),(0,H.jsx)(`tbody`,{children:n.filteredCommits.map(e=>(0,H.jsx)(q,{commit:e,lane:n.filteredLanes.laneMap.get(e.hash)??0,isSelected:n.selectedCommit?.hash===e.hash,isHead:e.hash===n.headHash,labels:n.commitLabels.get(e.hash)??[],currentBranch:n.currentBranch,onSelect:()=>n.selectCommit(e),onCheckout:n.handleCheckout,onCherryPick:n.handleCherryPick,onRevert:n.handleRevert,onMerge:n.handleMerge,onDeleteBranch:n.handleDeleteBranch,onPushBranch:n.handlePushBranch,onCreatePr:n.handleCreatePr,onOpenCreateBranch:e=>i({type:`branch`,hash:e}),onOpenCreateTag:e=>i({type:`tag`,hash:e}),onOpenDiff:()=>n.openDiffForCommit(e),onCopyHash:()=>n.copyHash(e.hash)},e.hash))})]}),n.loadingMore&&(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-3 text-xs text-muted-foreground`,children:[(0,H.jsx)(M,{className:`size-3.5 animate-spin`}),` Loading more commits...`]}),!n.hasMore&&n.data&&n.data.commits.length>0&&(0,H.jsxs)(`div`,{className:`text-center py-2 text-xs text-muted-foreground`,children:[n.data.commits.length,` commits loaded`]})]})]})}),n.selectedCommit&&t&&(0,H.jsx)(J,{commit:n.selectedCommit,files:n.commitFiles,loadingDetail:n.loadingDetail,projectName:t,onClose:()=>n.setSelectedCommit(null),copyHash:n.copyHash}),(0,H.jsx)(Y,{type:r.type,hash:r.hash,onClose:()=>i({type:null}),onCreateBranch:n.handleCreateBranch,onCreateTag:n.handleCreateTag}),(0,H.jsx)(X,{open:a,onClose:()=>o(!1),projectName:t,branches:n.data?.branches??[]})]}):(0,H.jsx)(ae,{msg:`No project selected.`})}function ie({label:e,colKey:t,onStartResize:n}){return(0,H.jsxs)(`th`,{className:`text-left px-2 font-semibold relative`,children:[e,(0,H.jsx)(`div`,{className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize hover:bg-primary/30`,onMouseDown:e=>{e.preventDefault(),n(t,e.clientX)},onTouchStart:e=>n(t,e.touches[0].clientX)})]})}function ae({msg:e}){return(0,H.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:e})}function oe(){return(0,H.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,H.jsx)(M,{className:`size-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]})}function se({error:e,onRetry:t}){return(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,H.jsx)(`p`,{children:e}),(0,H.jsx)(A,{variant:`outline`,size:`sm`,onClick:t,children:`Retry`})]})}export{$ as GitGraph};