@hienlh/ppm 0.13.42 → 0.13.44

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 (45) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/assets/skills/ppm/SKILL.md +1 -1
  3. package/assets/skills/ppm/references/http-api.md +1 -1
  4. package/dist/web/assets/{ai-settings-section-DN4egS8e.js → ai-settings-section-Btix996C.js} +1 -1
  5. package/dist/web/assets/{audio-preview-B2hc4zxi.js → audio-preview-B6a1Djtr.js} +1 -1
  6. package/dist/web/assets/{chat-tab-D9M8RvyT.js → chat-tab-Z5VNzYCz.js} +3 -3
  7. package/dist/web/assets/{code-editor-C9DFD879.js → code-editor-Clvs0e0Q.js} +2 -2
  8. package/dist/web/assets/{conflict-editor-CJKsIjVY.js → conflict-editor-B6nO1gln.js} +1 -1
  9. package/dist/web/assets/{csv-preview-BIfojSWd.js → csv-preview-CsqFmPzb.js} +1 -1
  10. package/dist/web/assets/data-grid-overlay-editor-aTzJjALy.js +1 -0
  11. package/dist/web/assets/{database-viewer-C_XSAt7c.js → database-viewer-Boup8MJ_.js} +1 -1
  12. package/dist/web/assets/{diff-viewer-C3ASlXkZ.js → diff-viewer-Je2KYGME.js} +1 -1
  13. package/dist/web/assets/dist-wf2npcsG.js +1 -0
  14. package/dist/web/assets/{extension-webview-B7g8Ypb_.js → extension-webview-T9TN70nb.js} +1 -1
  15. package/dist/web/assets/{glide-data-grid-BapAvCrK.js → glide-data-grid-CqT8WzTs.js} +3 -3
  16. package/dist/web/assets/{image-preview-gONIbRa3.js → image-preview-DeNUcGI9.js} +1 -1
  17. package/dist/web/assets/index-DJtqbPFT.js +27 -0
  18. package/dist/web/assets/{input-4ll___Gh.js → input-_LFQwhzd.js} +1 -1
  19. package/dist/web/assets/keybindings-store-DChqpL1V.js +1 -0
  20. package/dist/web/assets/{markdown-renderer-BDLn0g_z.js → markdown-renderer-CXPtICSx.js} +1 -1
  21. package/dist/web/assets/notification-store-Dn9zySnl.js +1 -0
  22. package/dist/web/assets/{pdf-preview-Xx4MhpGf.js → pdf-preview-DI2JU2Lm.js} +1 -1
  23. package/dist/web/assets/{port-forwarding-tab-BpMycSiW.js → port-forwarding-tab-Cuv_37LW.js} +1 -1
  24. package/dist/web/assets/{postgres-viewer-bcucvvk2.js → postgres-viewer-D76ygOZo.js} +1 -1
  25. package/dist/web/assets/{scroll-area-iv39O3VN.js → scroll-area-BDi_FNzr.js} +1 -1
  26. package/dist/web/assets/settings-tab-DXn2OnPA.js +1 -0
  27. package/dist/web/assets/{sql-query-editor-COxlMl16.js → sql-query-editor-lSlKMPlG.js} +1 -1
  28. package/dist/web/assets/{sqlite-viewer-BBafhOtU.js → sqlite-viewer-DwTatNwI.js} +1 -1
  29. package/dist/web/assets/{terminal-tab-CIo9vvKE.js → terminal-tab-XKe1TZiV.js} +1 -1
  30. package/dist/web/assets/{vendor-ui-B-89Uj8i.js → vendor-ui-UXCWAcmi.js} +1 -1
  31. package/dist/web/assets/{video-preview-CNk8D4Jm.js → video-preview-wHVbAYar.js} +1 -1
  32. package/dist/web/index.html +6 -6
  33. package/dist/web/manifest.webmanifest +1 -1
  34. package/dist/web/sw.js +1 -1
  35. package/package.json +1 -1
  36. package/src/web/app.tsx +1 -2
  37. package/src/web/components/chat/message-list.tsx +14 -7
  38. package/src/web/sw.ts +2 -2
  39. package/vite.config.ts +2 -2
  40. package/dist/web/assets/data-grid-overlay-editor-DZIqEOsz.js +0 -1
  41. package/dist/web/assets/dist-CaKCIxem.js +0 -1
  42. package/dist/web/assets/index-C5sX7goh.js +0 -27
  43. package/dist/web/assets/keybindings-store-BuT6nY6p.js +0 -1
  44. package/dist/web/assets/notification-store-B4ShaRp4.js +0 -1
  45. package/dist/web/assets/settings-tab-BNBJgT9x.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-BDLn0g_z.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-C5sX7goh.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-4ll___Gh.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-iv39O3VN.js","assets/ai-settings-section-DN4egS8e.js","assets/dist-CaKCIxem.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css","assets/csv-preview-BIfojSWd.js","assets/lib-Bu71-TFS.js","assets/csv-parser-Dly5nqE1.js","assets/arrow-up-Rcw6_KKu.js","assets/image-preview-gONIbRa3.js","assets/file-exclamation-point-BwzaQ50n.js","assets/use-blob-url-QX-XajU8.js","assets/pdf-preview-Xx4MhpGf.js","assets/video-preview-CNk8D4Jm.js","assets/audio-preview-B2hc4zxi.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import"./scroll-area-iv39O3VN.js";import{t as i}from"./database-DOWH9-Vv.js";import{t as a}from"./chevron-right-DnHIvvcy.js";import{a as o,l as s,n as c,o as l,r as u,s as d,t as f}from"./input-4ll___Gh.js";import{t as p}from"./code-DGBecc50.js";import{a as m,i as h,t as g}from"./x-BPReZWnP.js";import{t as _}from"./file-exclamation-point-BwzaQ50n.js";import{i as ee,r as v,t as y}from"./glide-data-grid-BapAvCrK.js";import{t as b}from"./table-BzjWcs87.js";import{t as x}from"./text-wrap-DJz9Bgpa.js";import{i as te,t as S}from"./api-client-DIhJ5qVW.js";import{n as ne}from"./settings-store-CVrIYYCB.js";import{K as C}from"./vendor-mermaid-Cl50p6TB.js";import{t as w}from"./utils-CQux7CsO.js";import{n as re,t as ie}from"./tab-store-S9w6U5gm.js";import{i as T,n as E}from"./file-store-DOxcU_7s.js";import{$ as ae,G as D,I as oe,J as O,K as k,Q as A,U as se,X as j,Y as M,Z as N,a as ce,c as P,d as F,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as I,q as he,tt as ge,u as L}from"./index-C5sX7goh.js";import"./data-grid-types-BISkUXAY.js";import{n as _e,t as ve}from"./use-monaco-theme-BePWbY58.js";var ye=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),R=e(n(),1),z=t(),B={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:j,txt:j,yaml:M,yml:M};function be(e,t){return t?he:B[e.split(`.`).pop()?.toLowerCase()??``]??O}function xe(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.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:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function V(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Se({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:o,openTab:s}=ie(de(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=T(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d}=(0,R.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e}}return{prefixParts:[],relativePath:t}},[e,c]),f=(0,R.useMemo)(()=>xe(i,d.split(`/`).filter(Boolean)),[i,d]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[f]);function p(e,r){let i=w(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.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ce,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function Ce({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,R.useMemo)(()=>V(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){t&&!s&&i(n,e.parentPath)}return(0,z.jsxs)(P,{onOpenChange:c,children:[(0,z.jsx)(pe,{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)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=be(e.name,e.type===`directory`),a=e.path===n,o=E(e=>e.loadChildren),s=E(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,z.jsxs)(F,{onOpenChange:u,children:[(0,z.jsxs)(I,{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)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):V(c).map(e=>(0,z.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(L,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{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 U({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 we({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,z.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:p,label:`Edit`}),(0,z.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:h,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:b,label:`Table`}),(0,z.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:p,label:`Raw`})]}),(0,z.jsx)(U,{active:a,onClick:o,icon:x,label:`Wrap`}),s&&c&&(0,z.jsx)(U,{active:!1,onClick:()=>ue(c,s),icon:m,label:`Download`})]})}function Te({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(!1),[g,_]=(0,R.useState)(``),ee=T(e=>e.activeProject),v=(0,R.useCallback)(()=>{let e=a.trim();if(!e){_(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){_(`Filename cannot contain / or \\`);return}_(``),h(!0)},[a]),y=(0,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return m?(0,z.jsx)(me,{open:!0,mode:`folder`,root:ee?.path,title:`Save "${a.trim()}" to...`,onSelect:y,onCancel:()=>h(!1)}):(0,z.jsx)(c,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(u,{className:`sm:max-w-md`,children:[(0,z.jsx)(l,{children:(0,z.jsx)(d,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(f,{value:a,onChange:e=>{p(e.target.value),_(``)},onKeyDown:e=>{e.key===`Enter`&&v()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),g&&(0,z.jsx)(`p`,{className:`text-xs text-destructive`,children:g})]}),(0,z.jsxs)(o,{children:[(0,z.jsx)(s,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(s,{onClick:v,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,Ee=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],G=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,K=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,De=`w-px h-5 bg-border mx-0.5 shrink-0`;function Oe({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(g,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:W?s:c,className:G,title:`Paste`,children:(0,z.jsx)(ge,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:G,title:`Undo`,children:(0,z.jsx)(oe,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:G,title:`Redo`,children:(0,z.jsx)(ye,{size:14})}),(0,z.jsx)(`div`,{className:De}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:K,children:`Tab`}),(0,z.jsx)(`div`,{className:De}),Ee.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:K,children:e},e))]})]})}var ke=(0,R.lazy)(()=>C(()=>import(`./markdown-renderer-BDLn0g_z.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]))),Ae=(0,R.lazy)(()=>C(()=>import(`./csv-preview-BIfojSWd.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([24,1,4,5,25,26,8,27]))),je=(0,R.lazy)(()=>C(()=>import(`./image-preview-gONIbRa3.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([28,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Me=(0,R.lazy)(()=>C(()=>import(`./pdf-preview-Xx4MhpGf.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Ne=(0,R.lazy)(()=>C(()=>import(`./video-preview-CNk8D4Jm.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([32,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Pe=(0,R.lazy)(()=>C(()=>import(`./audio-preview-B2hc4zxi.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([33,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Fe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ie=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),Le=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Re=new Set([`db`,`sqlite`,`sqlite3`]);function ze(e){return e.split(`.`).pop()?.toLowerCase()??``}function Be(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`,sql:`sql`}[ze(e)]??`plaintext`}var q=(0,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,a=e?.inlineContent,o=e?.inlineLanguage,[s,c]=(0,R.useState)(a??null),[l,u]=(0,R.useState)(`utf-8`),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)(``),x=(0,R.useRef)(null),{tabs:C,updateTab:T}=ie(de(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ae}=ne(de(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),oe=ve(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,R.useState)(!1),M=C.find(e=>e.id===t),N=n?ze(n):``,P=Fe.has(N),F=N===`pdf`,le=Ie.has(N),ue=Le.has(N),fe=Re.has(N),pe=N===`md`||N===`mdx`,me=N===`csv`,I=N===`sql`,[he,ge]=(0,R.useState)(`preview`),[L,ye]=(0,R.useState)(`table`),{connections:B,cachedTables:be,refreshTables:xe}=ce(),[V,Ce]=(0,R.useState)(()=>{if(!I||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),H=(0,R.useRef)(null),U=(0,R.useRef)(null),W=(0,R.useMemo)(()=>B.find(e=>e.id===V)??null,[B,V]),Ee=a!=null&&(o===`json`||o===`xml`),[G,K]=(0,R.useState)(!1),De=(0,R.useCallback)(()=>{if(a)if(G)c(a),K(!1);else{let e=a.trimStart();if(o===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),K(!0)}catch{}else if(o===`xml`){let t=0;c(e.replace(/(>)(<)(\/*)/g,`$1
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-CXPtICSx.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-DJtqbPFT.js","assets/vendor-mermaid-Cl50p6TB.js","assets/vendor-ui-UXCWAcmi.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-_LFQwhzd.js","assets/utils-CQux7CsO.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BPReZWnP.js","assets/settings-store-CVrIYYCB.js","assets/react-DMIOAtcX.js","assets/api-client-DIhJ5qVW.js","assets/scroll-area-BDi_FNzr.js","assets/ai-settings-section-Btix996C.js","assets/dist-wf2npcsG.js","assets/refresh-cw-BjrAbUJe.js","assets/api-settings-DnHv6JgF.js","assets/database-DOWH9-Vv.js","assets/chevron-right-DnHIvvcy.js","assets/search-tM8K5zWU.js","assets/file-store-DOxcU_7s.js","assets/tab-store-S9w6U5gm.js","assets/index-C9ej6g0c.css","assets/csv-preview-CsqFmPzb.js","assets/lib-Bu71-TFS.js","assets/csv-parser-Dly5nqE1.js","assets/arrow-up-Rcw6_KKu.js","assets/image-preview-DeNUcGI9.js","assets/file-exclamation-point-BwzaQ50n.js","assets/use-blob-url-QX-XajU8.js","assets/pdf-preview-DI2JU2Lm.js","assets/video-preview-wHVbAYar.js","assets/audio-preview-B6a1Djtr.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-UXCWAcmi.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import"./scroll-area-BDi_FNzr.js";import{t as i}from"./database-DOWH9-Vv.js";import{t as a}from"./chevron-right-DnHIvvcy.js";import{a as o,l as s,n as c,o as l,r as u,s as d,t as f}from"./input-_LFQwhzd.js";import{t as p}from"./code-DGBecc50.js";import{a as m,i as h,t as g}from"./x-BPReZWnP.js";import{t as _}from"./file-exclamation-point-BwzaQ50n.js";import{i as ee,r as v,t as y}from"./glide-data-grid-CqT8WzTs.js";import{t as b}from"./table-BzjWcs87.js";import{t as x}from"./text-wrap-DJz9Bgpa.js";import{i as te,t as S}from"./api-client-DIhJ5qVW.js";import{n as ne}from"./settings-store-CVrIYYCB.js";import{K as C}from"./vendor-mermaid-Cl50p6TB.js";import{t as w}from"./utils-CQux7CsO.js";import{n as re,t as ie}from"./tab-store-S9w6U5gm.js";import{i as T,n as E}from"./file-store-DOxcU_7s.js";import{$ as ae,G as D,I as oe,J as O,K as k,Q as A,U as se,X as j,Y as M,Z as N,a as ce,c as P,d as F,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as I,q as he,tt as ge,u as L}from"./index-DJtqbPFT.js";import"./data-grid-types-BISkUXAY.js";import{n as _e,t as ve}from"./use-monaco-theme-BePWbY58.js";var ye=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),R=e(n(),1),z=t(),B={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:A,md:j,txt:j,yaml:M,yml:M};function be(e,t){return t?he:B[e.split(`.`).pop()?.toLowerCase()??``]??O}function xe(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.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:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function V(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Se({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:o,openTab:s}=ie(de(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=T(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d}=(0,R.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e}}return{prefixParts:[],relativePath:t}},[e,c]),f=(0,R.useMemo)(()=>xe(i,d.split(`/`).filter(Boolean)),[i,d]);(0,R.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[f]);function p(e,r){let i=w(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.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(a,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ce,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function Ce({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,R.useMemo)(()=>V(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){t&&!s&&i(n,e.parentPath)}return(0,z.jsxs)(P,{onOpenChange:c,children:[(0,z.jsx)(pe,{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)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=be(e.name,e.type===`directory`),a=e.path===n,o=E(e=>e.loadChildren),s=E(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,z.jsxs)(F,{onOpenChange:u,children:[(0,z.jsxs)(I,{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)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(L,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):V(c).map(e=>(0,z.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(L,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{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 U({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 we({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,z.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:p,label:`Edit`}),(0,z.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:h,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:b,label:`Table`}),(0,z.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:p,label:`Raw`})]}),(0,z.jsx)(U,{active:a,onClick:o,icon:x,label:`Wrap`}),s&&c&&(0,z.jsx)(U,{active:!1,onClick:()=>ue(c,s),icon:m,label:`Download`})]})}function Te({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(!1),[g,_]=(0,R.useState)(``),ee=T(e=>e.activeProject),v=(0,R.useCallback)(()=>{let e=a.trim();if(!e){_(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){_(`Filename cannot contain / or \\`);return}_(``),h(!0)},[a]),y=(0,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return m?(0,z.jsx)(me,{open:!0,mode:`folder`,root:ee?.path,title:`Save "${a.trim()}" to...`,onSelect:y,onCancel:()=>h(!1)}):(0,z.jsx)(c,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(u,{className:`sm:max-w-md`,children:[(0,z.jsx)(l,{children:(0,z.jsx)(d,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(f,{value:a,onChange:e=>{p(e.target.value),_(``)},onKeyDown:e=>{e.key===`Enter`&&v()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),g&&(0,z.jsx)(`p`,{className:`text-xs text-destructive`,children:g})]}),(0,z.jsxs)(o,{children:[(0,z.jsx)(s,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(s,{onClick:v,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,Ee=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],G=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,K=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,De=`w-px h-5 bg-border mx-0.5 shrink-0`;function Oe({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(g,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:W?s:c,className:G,title:`Paste`,children:(0,z.jsx)(ge,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:G,title:`Undo`,children:(0,z.jsx)(oe,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:G,title:`Redo`,children:(0,z.jsx)(ye,{size:14})}),(0,z.jsx)(`div`,{className:De}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:K,children:`Tab`}),(0,z.jsx)(`div`,{className:De}),Ee.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:K,children:e},e))]})]})}var ke=(0,R.lazy)(()=>C(()=>import(`./markdown-renderer-CXPtICSx.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]))),Ae=(0,R.lazy)(()=>C(()=>import(`./csv-preview-CsqFmPzb.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([24,1,4,5,25,26,8,27]))),je=(0,R.lazy)(()=>C(()=>import(`./image-preview-DeNUcGI9.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([28,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Me=(0,R.lazy)(()=>C(()=>import(`./pdf-preview-DI2JU2Lm.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Ne=(0,R.lazy)(()=>C(()=>import(`./video-preview-wHVbAYar.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([32,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Pe=(0,R.lazy)(()=>C(()=>import(`./audio-preview-B6a1Djtr.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([33,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,29,30]))),Fe=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ie=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),Le=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Re=new Set([`db`,`sqlite`,`sqlite3`]);function ze(e){return e.split(`.`).pop()?.toLowerCase()??``}function Be(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`,sql:`sql`}[ze(e)]??`plaintext`}var q=(0,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,a=e?.inlineContent,o=e?.inlineLanguage,[s,c]=(0,R.useState)(a??null),[l,u]=(0,R.useState)(`utf-8`),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)(``),x=(0,R.useRef)(null),{tabs:C,updateTab:T}=ie(de(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ae}=ne(de(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),oe=ve(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,R.useState)(!1),M=C.find(e=>e.id===t),N=n?ze(n):``,P=Fe.has(N),F=N===`pdf`,le=Ie.has(N),ue=Le.has(N),fe=Re.has(N),pe=N===`md`||N===`mdx`,me=N===`csv`,I=N===`sql`,[he,ge]=(0,R.useState)(`preview`),[L,ye]=(0,R.useState)(`table`),{connections:B,cachedTables:be,refreshTables:xe}=ce(),[V,Ce]=(0,R.useState)(()=>{if(!I||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),H=(0,R.useRef)(null),U=(0,R.useRef)(null),W=(0,R.useMemo)(()=>B.find(e=>e.id===V)??null,[B,V]),Ee=a!=null&&(o===`json`||o===`xml`),[G,K]=(0,R.useState)(!1),De=(0,R.useCallback)(()=>{if(a)if(G)c(a),K(!1);else{let e=a.trimStart();if(o===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),K(!0)}catch{}else if(o===`xml`){let t=0;c(e.replace(/(>)(<)(\/*)/g,`$1
3
3
  $2$3`).split(`
4
4
  `).map(e=>{let n=e.trim();n.startsWith(`</`)&&(t=Math.max(0,t-1));let r=` `.repeat(t)+n;return n.startsWith(`<`)&&!n.startsWith(`</`)&&!n.endsWith(`/>`)&&!n.includes(`</`)&&t++,r}).join(`
5
5
  `)),K(!0)}}},[a,o,G]),ke=(0,R.useCallback)(e=>{Ce(e),n&&localStorage.setItem(`ppm:sql-conn:${n}`,String(e)),xe(e).catch(()=>{})},[n,xe]),q=(0,R.useMemo)(()=>{if(!I||!V)return;let e=(be.get(V)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>S.get(`/api/db/connections/${V}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[I,V,be]);(0,R.useEffect)(()=>{if(!(!H.current||!q))return U.current?.dispose(),v(),U.current=H.current.languages.registerCompletionItemProvider(`sql`,ee(H.current,q)),()=>{U.current?.dispose()}},[q]);let J=ie(e=>e.openTab),[Ue,We]=(0,R.useState)(null),[Ge,Ke]=(0,R.useState)(null),[qe,Je]=(0,R.useState)(!1),[Ye,Xe]=(0,R.useState)(``),X=(0,R.useCallback)(async e=>{if(W){Je(!0),Ke(null),Xe(e);try{We(await S.post(`/api/db/connections/${W.id}/query`,{sql:e}))}catch(e){Ke(e.message),We(null)}finally{Je(!1)}}},[W]),Ze=(0,R.useCallback)(()=>{!W||!Ye||J({type:`database`,title:`${W.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:W.id,connectionName:W.name,dbType:W.type,initialSql:Ye}})},[W,J,Ye]),Qe=(0,R.useCallback)(()=>{if(!x.current||!W)return;let e=x.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[W,X]),$e=typeof window<`u`&&`ontouchstart`in window,et=(0,R.useRef)(null),[tt,nt]=(0,R.useState)(null);(0,R.useEffect)(()=>{if(!$e)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=et.current;if(!t)return;let n=t.getBoundingClientRect().top;nt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[$e]);let Z=(0,R.useRef)([]),rt=(0,R.useRef)(X);rt.current=X,(0,R.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,R.useEffect)(()=>{fe&&t&&T(t,{type:`sqlite`})},[fe,t,T]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(a!=null){f(!1);return}if(O){c(k??``),b.current=k??``,f(!1),k&&g(!0);return}if(!n||!Q&&!r)return;if(P||F||le||ue){f(!1);return}f(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${te(r)}/files/read?path=${encodeURIComponent(n)}`;return S.get(e).then(e=>{c(e.content),e.encoding&&u(e.encoding),b.current=e.content,f(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),f(!1)}),()=>{y.current&&clearTimeout(y.current)}},[n,r,P,F,Q,O]);let it=(0,R.useRef)(h);it.current=h,(0,R.useEffect)(()=>{if(!n||!r||a!=null||O)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||it.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${te(r)}/files/read?path=${encodeURIComponent(n)}`;S.get(i).then(e=>{e.content!==b.current&&(c(e.content),b.current=e.content,e.encoding&&u(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,a,O]),(0,R.useEffect)(()=>{if(!M||a!=null)return;let t=O?`Untitled-${e?.untitledNumber??1}`:n?w(n):`Untitled`,r=h?`${t} \u25CF`:t;M.title!==r&&T(M.id,{title:r})},[h]);let at=(0,R.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await S.put(`/api/fs/write`,{path:n,content:e}):await S.put(`${te(r)}/files/write`,{path:n,content:e}),g(!1)}catch{}},[n,r,Q]);function ot(n){let r=n??``;c(r),b.current=r,g(!0),y.current&&clearTimeout(y.current),O?y.current=setTimeout(()=>{t&&T(t,{metadata:{...e,unsavedContent:b.current}})},2e3):y.current=setTimeout(()=>at(b.current),1e3)}let st=(0,R.useCallback)(async(e,n)=>{try{if(y.current&&clearTimeout(y.current),await S.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=re.getState();n(t),r({type:`editor`,title:w(e),projectId:null,metadata:{filePath:e},closable:!0})}g(!1),j(!1)}catch{}},[t]),$=e?.lineNumber,ct=(0,R.useCallback)((e,t)=>{if(x.current=e,H.current=t,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),O&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>j(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>ne.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),q&&(U.current?.dispose(),U.current=t.languages.registerCompletionItemProvider(`sql`,ee(t,q))),I){Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&rt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{i as r,t as i}from"./api-client-DIhJ5qVW.js";import{n as a}from"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import{G as o,h as s}from"./index-C5sX7goh.js";import{n as c,t as l}from"./use-monaco-theme-BePWbY58.js";var u=e(n(),1),d=t();function f(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`,go:`go`,rs:`rust`,java:`java`,rb:`ruby`,php:`php`,swift:`swift`,sql:`sql`,xml:`xml`,toml:`toml`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function p(e){let t=e.split(`
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{i as r,t as i}from"./api-client-DIhJ5qVW.js";import{n as a}from"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import{G as o,h as s}from"./index-DJtqbPFT.js";import{n as c,t as l}from"./use-monaco-theme-BePWbY58.js";var u=e(n(),1),d=t();function f(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`,go:`go`,rs:`rust`,java:`java`,rb:`ruby`,php:`php`,swift:`swift`,sql:`sql`,xml:`xml`,toml:`toml`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function p(e){let t=e.split(`
2
2
  `),n=[],r=0,i=0;for(;r<t.length;){let e=t[r];if(e.startsWith(`<<<<<<<`)){let a=r,o=e.substring(7).trim(),s=[];for(r++;r<t.length&&!t[r].startsWith(`=======`);)s.push(t[r]),r++;if(r>=t.length)break;let c=r,l=[];for(r++;r<t.length&&!t[r].startsWith(`>>>>>>>`);)l.push(t[r]),r++;if(r>=t.length)break;let u=t[r].substring(7).trim();n.push({id:i++,startLine:a+1,separatorLine:c+1,endLine:r+1,currentContent:s.join(`
3
3
  `),incomingContent:l.join(`
4
4
  `),currentLabel:o,incomingLabel:u})}r++}return n}function m({metadata:e}){let t=e?.filePath,n=e?.projectName,[m,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(!0),[y,b]=(0,u.useState)(null),[x,S]=(0,u.useState)(0),C=(0,u.useRef)(null),w=(0,u.useRef)(null),T=(0,u.useRef)([]),E=(0,u.useRef)(null),{wordWrap:D}=a(s(e=>({wordWrap:e.wordWrap}))),O=l(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)();(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&j(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[]),(0,u.useEffect)(()=>{!t||!n||(v(!0),i.get(`${r(n)}/files/read?path=${encodeURIComponent(t)}`).then(e=>{g(e.content),v(!1)}).catch(e=>{b(e.message||`Failed to load file`),v(!1)}))},[t,n]);let M=(0,u.useCallback)(()=>{let e=C.current,t=w.current;if(!e||!t)return;let n=p(e.getModel()?.getValue()||``);S(n.length);for(let t of T.current)e.removeContentWidget(t);if(T.current=[],E.current&&E.current.clear(),n.length===0)return;let r=[];for(let e of n)r.push({range:new t.Range(e.startLine,1,e.startLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-current`}}),r.push({range:new t.Range(e.separatorLine,1,e.separatorLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`}}),r.push({range:new t.Range(e.endLine,1,e.endLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-incoming`}}),e.separatorLine-e.startLine>1&&r.push({range:new t.Range(e.startLine+1,1,e.separatorLine-1,1),options:{isWholeLine:!0,className:`conflict-current-content`}}),e.endLine-e.separatorLine>1&&r.push({range:new t.Range(e.separatorLine+1,1,e.endLine-1,1),options:{isWholeLine:!0,className:`conflict-incoming-content`}});E.current=e.createDecorationsCollection(r);for(let r of n){let n=`conflict-widget-${r.id}`,i=document.createElement(`div`);i.className=`conflict-actions`,i.innerHTML=`<span class="conflict-label">Current Change (${h(r.currentLabel||`HEAD`)})</span><button class="conflict-btn conflict-btn-current" data-action="current">Accept Current</button><button class="conflict-btn conflict-btn-incoming" data-action="incoming">Accept Incoming</button><button class="conflict-btn conflict-btn-both" data-action="both">Accept Both</button>`,i.addEventListener(`click`,e=>{let t=e.target.closest(`[data-action]`);if(!t)return;let n=t.getAttribute(`data-action`);N(r.id,n)});let a={getId:()=>n,getDomNode:()=>i,getPosition:()=>({position:{lineNumber:r.startLine,column:1},preference:[t.editor.ContentWidgetPositionPreference.ABOVE]})};e.addContentWidget(a),T.current.push(a)}},[]),N=(0,u.useCallback)((e,t)=>{let n=C.current,r=w.current;if(!n||!r)return;let i=n.getModel();if(!i)return;let a=p(i.getValue()).find(t=>t.id===e);if(!a)return;let o;switch(t){case`current`:o=a.currentContent;break;case`incoming`:o=a.incomingContent;break;case`both`:o=a.currentContent+`
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{et as r}from"./vendor-ui-B-89Uj8i.js";import{n as i,r as a,t as o}from"./csv-parser-Dly5nqE1.js";import{t as s}from"./arrow-up-Rcw6_KKu.js";import{i as c,n as l,r as u,t as d}from"./lib-Bu71-TFS.js";var f=e(r(),1),p=e(n(),1);function m(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o;n.key&&n.debug?.call(n)&&(o=Date.now());let s=e();if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug?.call(n)&&(c=Date.now()),i=t(...s),n.key&&n.debug?.call(n)){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{Y as r}from"./vendor-ui-UXCWAcmi.js";import{n as i,r as a,t as o}from"./csv-parser-Dly5nqE1.js";import{t as s}from"./arrow-up-Rcw6_KKu.js";import{i as c,n as l,r as u,t as d}from"./lib-Bu71-TFS.js";var f=e(r(),1),p=e(n(),1);function m(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o;n.key&&n.debug?.call(n)&&(o=Date.now());let s=e();if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug?.call(n)&&(c=Date.now()),i=t(...s),n.key&&n.debug?.call(n)){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
2
2
  font-size: .6rem;
3
3
  font-weight: bold;
4
4
  color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i}return o.updateDeps=e=>{r=e},o}function h(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var g=(e,t)=>Math.abs(e-t)<1.01,_=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},v=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},y=e=>e,b=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),r=[];for(let e=t;e<=n;e++)r.push(e);return r},x=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(v(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(v(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},S={passive:!0},C=typeof window>`u`?!0:`onscrollend`in window,w=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=0,a=e.options.useScrollendEvent&&C?()=>void 0:_(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=r=>()=>{let{horizontal:o,isRtl:s}=e.options;i=o?n.scrollLeft*(s&&-1||1):n.scrollTop,a(),t(i,r)},s=o(!0),c=o(!1);n.addEventListener(`scroll`,s,S);let l=e.options.useScrollendEvent&&C;return l&&n.addEventListener(`scrollend`,c,S),()=>{n.removeEventListener(`scroll`,s),l&&n.removeEventListener(`scrollend`,c)}},T=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},E=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;let o=e+t;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:o,behavior:n})},D=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{n===void 0&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:y,rangeExtractor:b,onChange:()=>{},measureElement:T,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=m(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=m(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(e,t,n,r,i,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a}),{key:!1}),this.getMeasurements=m(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a},o)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let s=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);let c=this.measurementsCache.slice(0,s),l=Array(a).fill(void 0);for(let e=0;e<s;e++){let t=c[e];t&&(l[t.lane]=e)}for(let i=s;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,u;if(a!==void 0&&this.options.lanes>1){s=a;let e=l[s],r=e===void 0?void 0:c[e];u=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?c[i-1]:this.getFurthestMeasurement(c,i);u=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(i,s)}let d=o.get(e),f=typeof d==`number`?d:this.options.estimateSize(i),p=u+f;c[i]={index:i,start:u,size:f,end:p,key:e,lane:s},l[s]=i}return this.measurementsCache=c,c},{key:!1,debug:()=>this.options.debug}),this.calculateRange=m(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?k({measurements:e,outerSize:t,scrollOffset:n,lanes:r}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=m(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{let n=this.measurementsCache[e];if(!n)return;let r=t-(this.itemSizeCache.get(n.key)??n.size);r!==0&&(this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?n.start<this.getScrollOffset()+this.scrollAdjustments:this.shouldAdjustScrollPositionOnItemSizeChange(n,r,this))&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=r,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.getVirtualItems=m(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length!==0)return h(t[O(0,t.length-1,e=>h(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t);this.scrollState={index:null,align:t,behavior:n,startedAt:this.now(),lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e;this.scrollState={index:null,align:`start`,behavior:t,startedAt:this.now(),lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1)t=e[e.length-1]?.end??0;else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&g(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.scrollState=null;return}}else this.scrollState.stableFrames=0,n&&(this.scrollState.lastTargetOffset=t,this.scrollState.behavior=`auto`,this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}));this.scheduleScrollReconcile()}},O=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function k({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){let i=e.length-1,a=t=>e[t].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=O(0,i,a,n),s=o;if(r===1)for(;s<i&&e[s].end<n+t;)s++;else if(r>1){let a=Array(r).fill(0);for(;s<i&&a.some(e=>e<n+t);){let t=e[s];a[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(i,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var A=typeof document<`u`?p.useLayoutEffect:p.useEffect;function j({useFlushSync:e=!0,...t}){let n=p.useReducer(()=>({}),{})[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,f.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=p.useState(()=>new D(r));return i.setOptions(r),A(()=>i._didMount(),[]),A(()=>i._willUpdate()),i}function M(e){return j({observeElementRect:x,observeElementOffset:w,scrollToFn:E,...e})}var N=t();function P({content:e,onContentChange:t,wordWrap:n}){let r=(0,p.useMemo)(()=>o(e),[e]),[f,m]=(0,p.useState)(()=>r.rows),[h,g]=(0,p.useState)([]),_=(0,p.useRef)(null),v=(0,p.useRef)(!1);(0,p.useEffect)(()=>{if(v.current){v.current=!1;return}m(r.rows)},[r.rows]);let y=r.headers,b=(0,p.useCallback)((e,n,r)=>{m(a=>{let o=a.map((t,n)=>n===e?[...t]:t);return o[e][n]=r,v.current=!0,t(i(y,o)),o})},[y,t]),x=l({data:f,columns:(0,p.useMemo)(()=>y.map((e,t)=>({id:`col-${t}`,header:e||`Column ${t+1}`,accessorFn:e=>e[t]??``,cell:({row:e,getValue:r})=>(0,N.jsx)(F,{value:r(),onSave:n=>b(e.index,t,n),wordWrap:n}),size:150,minSize:80})),[y,b,n]),state:{sorting:h},onSortingChange:g,getCoreRowModel:u(),getSortedRowModel:c(),enableColumnResizing:!0,columnResizeMode:`onChange`}),{rows:S}=x.getRowModel(),C=M({count:S.length,getScrollElement:()=>_.current,estimateSize:()=>32,overscan:20});return y.length===0?(0,N.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`Empty CSV file`}):(0,N.jsx)(`div`,{ref:_,className:`flex-1 overflow-auto`,children:(0,N.jsxs)(`table`,{className:`w-full text-xs font-mono border-collapse`,children:[(0,N.jsx)(`thead`,{className:`sticky top-0 bg-background z-10 border-b border-border block`,children:x.getHeaderGroups().map(e=>(0,N.jsx)(`tr`,{className:`flex w-full`,children:e.headers.map(e=>(0,N.jsxs)(`th`,{className:`relative text-left px-2 py-1.5 font-medium text-muted-foreground select-none cursor-pointer hover:bg-muted/50 border-r border-border last:border-r-0`,style:{width:e.getSize(),minWidth:e.getSize()},onClick:e.column.getToggleSortingHandler(),children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:d(e.column.columnDef.header,e.getContext())}),e.column.getIsSorted()===`asc`&&(0,N.jsx)(s,{className:`size-3 shrink-0`}),e.column.getIsSorted()===`desc`&&(0,N.jsx)(a,{className:`size-3 shrink-0`})]}),(0,N.jsx)(`div`,{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),onClick:e=>e.stopPropagation(),className:`absolute right-0 top-0 h-full w-1 cursor-col-resize hover:bg-primary/50 active:bg-primary`})]},e.id))},e.id))}),(0,N.jsx)(`tbody`,{style:{height:C.getTotalSize(),position:`relative`,display:`block`},children:C.getVirtualItems().map(e=>{let t=S[e.index];return(0,N.jsx)(`tr`,{"data-index":e.index,ref:e=>C.measureElement(e),style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`,display:`flex`},children:t.getVisibleCells().map(e=>(0,N.jsx)(`td`,{className:`px-2 py-1 border-b border-border/50 border-r border-r-border/30 last:border-r-0 ${n?`whitespace-pre-wrap break-words`:`truncate`}`,style:{width:e.column.getSize(),minWidth:e.column.getSize()},children:d(e.column.columnDef.cell,e.getContext())},e.id))},t.id)})})]})})}function F({value:e,onSave:t,wordWrap:n}){let[r,i]=(0,p.useState)(!1),[a,o]=(0,p.useState)(e),s=(0,p.useRef)(null),c=(0,p.useCallback)(e=>{e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[]);return(0,p.useEffect)(()=>{r&&s.current&&(s.current.focus(),c(s.current))},[r,c]),r?(0,N.jsx)(`textarea`,{ref:s,className:`w-full bg-transparent outline-none border border-primary/50 rounded text-xs font-mono resize-none p-0.5`,style:{minHeight:a.includes(`
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{x as t}from"./vendor-markdown-0Mxgxy0L.js";import{Y as n}from"./vendor-ui-UXCWAcmi.js";import{B as r,G as i,R as a,c as o,o as s,s as c}from"./data-grid-types-BISkUXAY.js";import{t as l}from"./dist-CcDNqGjt.js";var u=e(n(),1),d=e(t(),1),f=()=>e=>e.targetX,p=()=>e=>e.targetY,m=()=>e=>e.targetWidth,h=()=>e=>e.targetHeight,g=()=>e=>e.targetY+10,_=()=>e=>Math.max(0,(e.targetHeight-28)/2),v=l(`div`)({name:`DataGridOverlayEditorStyle`,class:`gdg-d19meir1`,propsAsIs:!1,vars:{"d19meir1-0":[p(),`px`],"d19meir1-1":[f(),`px`],"d19meir1-2":[m(),`px`],"d19meir1-3":[h(),`px`],"d19meir1-4":[g(),`px`],"d19meir1-5":[_(),`px`]}});function y(){let[e,t]=d.useState();return[e??void 0,t]}function b(){let[e,t]=y(),[n,r]=d.useState(0),[i,a]=d.useState(!0);return d.useLayoutEffect(()=>{if(e===void 0||!(`IntersectionObserver`in window))return;let t=new IntersectionObserver(e=>{e.length!==0&&a(e[0].isIntersecting)},{threshold:1});return t.observe(e),()=>t.disconnect()},[e]),d.useEffect(()=>{if(i||e===void 0)return;let t,n=()=>{let{right:i}=e.getBoundingClientRect();r(e=>Math.min(e+window.innerWidth-i-10,0)),t=requestAnimationFrame(n)};return t=requestAnimationFrame(n),()=>{t!==void 0&&cancelAnimationFrame(t)}},[e,i]),{ref:t,style:d.useMemo(()=>({transform:`translateX(${n}px)`}),[n])}}var x=e=>{let{target:t,content:n,onFinishEditing:l,forceEditMode:f,initialValue:p,imageEditorOverride:m,markdownDivCreateNode:h,highlight:g,className:_,theme:y,id:x,cell:S,bloom:C,validateCell:w,getCellRenderer:T,provideEditor:E,isOutsideClick:D}=e,[O,k]=d.useState(f?n:void 0),A=d.useRef(O??n);A.current=O??n;let[j,M]=d.useState(()=>w===void 0?!0:!(s(n)&&w?.(S,n,A.current)===!1)),N=d.useCallback((e,t)=>{l(j?e:void 0,t)},[j,l]),P=d.useCallback(e=>{if(w!==void 0&&e!==void 0&&s(e)){let t=w(S,e,A.current);t===!1?M(!1):(typeof t==`object`&&(e=t),M(!0))}k(e)},[S,w]),F=d.useRef(!1),I=d.useRef(void 0),L=d.useCallback(()=>{N(O,[0,0]),F.current=!0},[O,N]),R=d.useCallback((e,t)=>{N(e,t??I.current??[0,0]),F.current=!0},[N]),z=d.useCallback(async e=>{let t=!1;e.key===`Escape`?(e.stopPropagation(),e.preventDefault(),I.current=[0,0]):e.key===`Enter`&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),I.current=[0,1],t=!0):e.key===`Tab`&&(e.stopPropagation(),e.preventDefault(),I.current=[e.shiftKey?-1:1,0],t=!0),window.setTimeout(()=>{!F.current&&I.current!==void 0&&(N(t?O:void 0,I.current),F.current=!0)},0)},[N,O]),B=O??n,[V,H]=d.useMemo(()=>{if(c(n))return[];let e=E?.(n);return e===void 0?[T(n)?.provideEditor?.(n),!1]:[e,!1]},[n,T,E]),{ref:U,style:W}=b(),G=!0,K,q=!0,J;if(V!==void 0){G=V.disablePadding!==!0,q=V.disableStyling!==!0;let e=o(V);e&&(J=V.styleOverride);let n=e?V.editor:V;K=d.createElement(n,{isHighlighted:g,onChange:P,value:B,initialValue:p,onFinishedEditing:R,validatedSelection:s(B)?B.selectionRange:void 0,forceEditMode:f,target:t,imageEditorOverride:m,markdownDivCreateNode:h,isValid:j,theme:y})}J={...J,...W};let Y=document.getElementById(`portal`);if(Y===null)return console.error('Cannot open Data Grid overlay editor, because portal not found. Please add `<div id="portal" />` as the last child of your `<body>`.'),null;let X=q?`gdg-style`:`gdg-unstyle`;j||(X+=` gdg-invalid`),G&&(X+=` gdg-pad`);let Z=C?.[0]??1,Q=C?.[1]??1;return(0,u.createPortal)(d.createElement(a.Provider,{value:y},d.createElement(i,{style:r(y),className:_,onClickOutside:L,isOutsideClick:D},d.createElement(v,{ref:U,id:x,className:X,style:J,as:H===!0?`label`:void 0,targetX:t.x-Z,targetY:t.y-Q,targetWidth:t.width+Z*2,targetHeight:t.height+Q*2},d.createElement(`div`,{className:`gdg-clip-region`,onKeyDown:z},K)))),Y)};export{x as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import{t as r}from"./database-DOWH9-Vv.js";import{n as i,t as a}from"./glide-data-grid-BapAvCrK.js";import{t as o}from"./refresh-cw-BjrAbUJe.js";import{t as s}from"./api-client-DIhJ5qVW.js";import"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import"./tab-store-S9w6U5gm.js";import{G as c,K as l}from"./index-C5sX7goh.js";import"./data-grid-types-BISkUXAY.js";import"./use-monaco-theme-BePWbY58.js";import{t as u}from"./sql-query-editor-COxlMl16.js";var d=e(n(),1);function f(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function p(e,t,n,r){try{let i=sessionStorage.getItem(f(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function m(e,t,n,r,i,a){try{sessionStorage.setItem(f(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function h(e){let t=`/api/db/connections/${e}`,[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)(`public`),[o,c]=(0,d.useState)(null),[l,u]=(0,d.useState)([]),[f,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(null),[v,y]=(0,d.useState)(1),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(!1),[E,D]=(0,d.useState)(null),[O,k]=(0,d.useState)(`ASC`),A=(0,d.useCallback)(async(r,a,o,l,d)=>{let f=r??n,p=a??i;if(!f)return;h(!0);let g=l===void 0?E:l,y=d??O;try{let n=g?`&orderBy=${encodeURIComponent(g)}&orderDir=${y}`:``,[r,i]=await Promise.all([s.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${p}&page=${o??v}&limit=100${n}`),s.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${p}`)]);c(r),u(i),m(e,f,p,o??v,r,i)}catch(e){_(e.message)}finally{h(!1)}},[t,e,n,i,v,E,O]),j=(0,d.useCallback)((t,n=`public`)=>{r(t),a(n),y(1),x(null);let i=p(e,t,n,1);i?(c(i.data),u(i.cols),h(!1),A(t,n,1)):A(t,n,1)},[e,A]),M=(0,d.useCallback)(e=>{y(e),A(void 0,void 0,e)},[A]),N=(0,d.useCallback)(async e=>{T(!0),C(null);try{let r=await s.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&A(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,A]),P=(0,d.useCallback)(async(e,r,a,o)=>{if(!n)return;let c=n,l=i;try{await s.put(`${t}/cell`,{table:c,schema:l,pkColumn:e,pkValue:r,column:a,value:o}),A(c,l)}catch(e){_(e.message)}},[t,n,i,A]),F=(0,d.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await s.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),A(a,o)}catch(e){_(e.message)}},[t,n,i,A]);return{selectedTable:n,selectedSchema:i,selectTable:j,tableData:o,schema:l,loading:f,error:g,page:v,setPage:M,orderBy:E,orderDir:O,toggleSort:(0,d.useCallback)(e=>{let t,n=`ASC`;E===e?O===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),D(t),k(n),y(1),A(void 0,void 0,1,t,n)},[E,O,A]),clearSort:(0,d.useCallback)(()=>{D(null),k(`ASC`),y(1),A(void 0,void 0,1,null,`ASC`)},[A]),queryResult:b,queryError:S,queryLoading:w,executeQuery:N,updateCell:P,deleteRow:F,bulkDelete:(0,d.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await s.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),A(a,o)}catch(e){_(e.message)}},[t,n,i,A]),insertRow:(0,d.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await s.post(`${t}/row`,{table:r,schema:a,values:e}),A(r,a)}catch(e){throw _(e.message),e}},[t,n,i,A]),refreshData:A,queryAsTable:(0,d.useCallback)(async e=>{h(!0);try{let n=await s.post(`${t}/query`,{sql:e});n.changeType===`select`&&c({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){_(e.message)}finally{h(!1)}},[t])}}var g=t();function _(e){let t={},n=/"(\w+)"\s+ILIKE\s+'%([^']*?)%'/gi,r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2].replace(/''/g,`'`);return t}function v({metadata:e}){let t=e?.connectionId,n=e?.connectionName,c=e?.tableName,f=e?.schemaName??`public`,p=e?.initialSql,m=h(t),[v,y]=(0,d.useState)([]),[x,S]=(0,d.useState)(180),C=(0,d.useRef)(null),[w,T]=(0,d.useState)({}),E=(0,d.useMemo)(()=>{if(p&&!m.selectedTable)return p;if(m.selectedTable){let e=`SELECT * FROM "${m.selectedTable}"`,t=Object.entries(w).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),m.orderBy&&(e+=` ORDER BY "${m.orderBy}" ${m.orderDir}`);let n=(m.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[p,m.selectedTable,m.orderBy,m.orderDir,m.page,w]),D=(0,d.useCallback)(e=>{T(e)},[]),O=(0,d.useRef)(void 0);(0,d.useEffect)(()=>{if(!(!m.selectedTable||Object.keys(w).length===0))return clearTimeout(O.current),O.current=setTimeout(()=>{m.queryAsTable(E)},500),()=>clearTimeout(O.current)},[w]);let k=(0,d.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=x,r=e=>{let r=e.clientY-t;S(Math.max(80,Math.min(n+r,(C.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[x]);(0,d.useEffect)(()=>{s.get(`/api/db/connections/${t}/tables?cached=1`).then(e=>y(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[t]);let A=(0,d.useMemo)(()=>{if(v.length!==0)return{tables:v,getColumns:async(e,n)=>await s.get(`/api/db/connections/${t}/schema?table=${encodeURIComponent(e)}${n?`&schema=${encodeURIComponent(n)}`:``}`)}},[t,v]),j=(0,d.useRef)(!1);(0,d.useEffect)(()=>{j.current||(j.current=!0,p?m.executeQuery(p):c&&m.selectTable(c,f))},[c,f,p]);let[M,N]=(0,d.useState)(!!p),P=(0,d.useCallback)(e=>{let t=e.trim();if(m.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${m.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){T(_(t)),m.queryAsTable(t);return}N(!0),m.executeQuery(e)},[m.executeQuery,m.queryAsTable,m.selectedTable]),F=(0,d.useCallback)(e=>{N(!1),m.toggleSort(e)},[m.toggleSort]),I=(0,d.useCallback)(()=>{N(!1),m.clearSort()},[m.clearSort]),L=(0,d.useCallback)(e=>{N(!1),m.setPage(e)},[m.setPage]),R=m.queryResult,z=M&&!!(R||m.queryError),B=m.selectedTable&&!z;return(0,g.jsx)(`div`,{ref:C,className:`flex h-full w-full overflow-hidden`,children:(0,g.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,g.jsx)(r,{className:`size-3.5 text-muted-foreground`}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),m.selectedTable&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,m.selectedTable]}),(0,g.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[m.tableData&&(0,g.jsx)(i,{columns:m.tableData.columns,rows:m.tableData.rows,filename:n?`${n}-${m.selectedTable??`data`}`:m.selectedTable??`data`,exportAllUrl:m.selectedTable?`/api/db/connections/${t}/export?table=${encodeURIComponent(m.selectedTable)}&schema=${m.selectedSchema}`:void 0}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>m.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,g.jsx)(o,{className:`size-3 ${m.loading?`animate-spin`:``}`})})]})]}),(0,g.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:x},children:(0,g.jsx)(u,{onExecute:P,loading:m.queryLoading,defaultValue:E,schemaInfo:A,cacheKey:t?String(t):void 0})}),(0,g.jsx)(`div`,{onMouseDown:k,className:`shrink-0 h-1.5 cursor-row-resize bg-border/50 hover:bg-primary/30 flex items-center justify-center transition-colors`,children:(0,g.jsx)(l,{className:`size-3 text-muted-foreground/50`})}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[B&&m.tableData&&(0,g.jsx)(a,{columns:m.tableData.columns,rows:m.tableData.rows,total:m.tableData.total,limit:m.tableData.limit,schema:m.schema,loading:m.loading,page:m.page,onPageChange:L,onCellUpdate:m.updateCell,onRowDelete:m.deleteRow,orderBy:m.orderBy,orderDir:m.orderDir,onToggleSort:F,onClearSort:I,onBulkDelete:m.bulkDelete,onInsertRow:m.insertRow,connectionId:t,selectedTable:m.selectedTable,selectedSchema:m.selectedSchema,connectionName:n,columnFilters:w,onColumnFilter:D}),z&&(0,g.jsx)(b,{result:R,error:m.queryError,loading:m.queryLoading,schema:m.schema,connectionName:n})]})]})})}var y=()=>{};function b({result:e,error:t,loading:n,schema:r,connectionName:i}){let o=(0,d.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),s=(0,d.useMemo)(()=>r?.length?r:(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[r,e?.columns]);return(0,g.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,g.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,g.jsxs)(`div`,{className:`px-3 py-2 text-green-500 shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,g.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),o&&(0,g.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,g.jsx)(a,{columns:o.columns,rows:o.rows,total:o.total,limit:o.limit,schema:s,loading:!!n,page:1,onPageChange:y,onCellUpdate:y,orderBy:null,orderDir:`ASC`,onToggleSort:y,connectionName:i}),e?.executionTimeMs!=null&&(0,g.jsxs)(`div`,{className:`px-3 py-0.5 border-t border-border text-[10px] text-muted-foreground shrink-0`,children:[e.rows.length,` rows · `,e.executionTimeMs,`ms`]})]}),e?.changeType===`select`&&e.rows.length===0&&(0,g.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,g.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,g.jsx)(c,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{v as DatabaseViewer};
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-UXCWAcmi.js";import{t as r}from"./database-DOWH9-Vv.js";import{n as i,t as a}from"./glide-data-grid-CqT8WzTs.js";import{t as o}from"./refresh-cw-BjrAbUJe.js";import{t as s}from"./api-client-DIhJ5qVW.js";import"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import"./tab-store-S9w6U5gm.js";import{G as c,K as l}from"./index-DJtqbPFT.js";import"./data-grid-types-BISkUXAY.js";import"./use-monaco-theme-BePWbY58.js";import{t as u}from"./sql-query-editor-lSlKMPlG.js";var d=e(n(),1);function f(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function p(e,t,n,r){try{let i=sessionStorage.getItem(f(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function m(e,t,n,r,i,a){try{sessionStorage.setItem(f(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function h(e){let t=`/api/db/connections/${e}`,[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)(`public`),[o,c]=(0,d.useState)(null),[l,u]=(0,d.useState)([]),[f,h]=(0,d.useState)(!1),[g,_]=(0,d.useState)(null),[v,y]=(0,d.useState)(1),[b,x]=(0,d.useState)(null),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(!1),[E,D]=(0,d.useState)(null),[O,k]=(0,d.useState)(`ASC`),A=(0,d.useCallback)(async(r,a,o,l,d)=>{let f=r??n,p=a??i;if(!f)return;h(!0);let g=l===void 0?E:l,y=d??O;try{let n=g?`&orderBy=${encodeURIComponent(g)}&orderDir=${y}`:``,[r,i]=await Promise.all([s.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${p}&page=${o??v}&limit=100${n}`),s.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${p}`)]);c(r),u(i),m(e,f,p,o??v,r,i)}catch(e){_(e.message)}finally{h(!1)}},[t,e,n,i,v,E,O]),j=(0,d.useCallback)((t,n=`public`)=>{r(t),a(n),y(1),x(null);let i=p(e,t,n,1);i?(c(i.data),u(i.cols),h(!1),A(t,n,1)):A(t,n,1)},[e,A]),M=(0,d.useCallback)(e=>{y(e),A(void 0,void 0,e)},[A]),N=(0,d.useCallback)(async e=>{T(!0),C(null);try{let r=await s.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&A(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,A]),P=(0,d.useCallback)(async(e,r,a,o)=>{if(!n)return;let c=n,l=i;try{await s.put(`${t}/cell`,{table:c,schema:l,pkColumn:e,pkValue:r,column:a,value:o}),A(c,l)}catch(e){_(e.message)}},[t,n,i,A]),F=(0,d.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await s.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),A(a,o)}catch(e){_(e.message)}},[t,n,i,A]);return{selectedTable:n,selectedSchema:i,selectTable:j,tableData:o,schema:l,loading:f,error:g,page:v,setPage:M,orderBy:E,orderDir:O,toggleSort:(0,d.useCallback)(e=>{let t,n=`ASC`;E===e?O===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),D(t),k(n),y(1),A(void 0,void 0,1,t,n)},[E,O,A]),clearSort:(0,d.useCallback)(()=>{D(null),k(`ASC`),y(1),A(void 0,void 0,1,null,`ASC`)},[A]),queryResult:b,queryError:S,queryLoading:w,executeQuery:N,updateCell:P,deleteRow:F,bulkDelete:(0,d.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await s.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),A(a,o)}catch(e){_(e.message)}},[t,n,i,A]),insertRow:(0,d.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await s.post(`${t}/row`,{table:r,schema:a,values:e}),A(r,a)}catch(e){throw _(e.message),e}},[t,n,i,A]),refreshData:A,queryAsTable:(0,d.useCallback)(async e=>{h(!0);try{let n=await s.post(`${t}/query`,{sql:e});n.changeType===`select`&&c({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){_(e.message)}finally{h(!1)}},[t])}}var g=t();function _(e){let t={},n=/"(\w+)"\s+ILIKE\s+'%([^']*?)%'/gi,r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2].replace(/''/g,`'`);return t}function v({metadata:e}){let t=e?.connectionId,n=e?.connectionName,c=e?.tableName,f=e?.schemaName??`public`,p=e?.initialSql,m=h(t),[v,y]=(0,d.useState)([]),[x,S]=(0,d.useState)(180),C=(0,d.useRef)(null),[w,T]=(0,d.useState)({}),E=(0,d.useMemo)(()=>{if(p&&!m.selectedTable)return p;if(m.selectedTable){let e=`SELECT * FROM "${m.selectedTable}"`,t=Object.entries(w).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),m.orderBy&&(e+=` ORDER BY "${m.orderBy}" ${m.orderDir}`);let n=(m.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[p,m.selectedTable,m.orderBy,m.orderDir,m.page,w]),D=(0,d.useCallback)(e=>{T(e)},[]),O=(0,d.useRef)(void 0);(0,d.useEffect)(()=>{if(!(!m.selectedTable||Object.keys(w).length===0))return clearTimeout(O.current),O.current=setTimeout(()=>{m.queryAsTable(E)},500),()=>clearTimeout(O.current)},[w]);let k=(0,d.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=x,r=e=>{let r=e.clientY-t;S(Math.max(80,Math.min(n+r,(C.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[x]);(0,d.useEffect)(()=>{s.get(`/api/db/connections/${t}/tables?cached=1`).then(e=>y(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[t]);let A=(0,d.useMemo)(()=>{if(v.length!==0)return{tables:v,getColumns:async(e,n)=>await s.get(`/api/db/connections/${t}/schema?table=${encodeURIComponent(e)}${n?`&schema=${encodeURIComponent(n)}`:``}`)}},[t,v]),j=(0,d.useRef)(!1);(0,d.useEffect)(()=>{j.current||(j.current=!0,p?m.executeQuery(p):c&&m.selectTable(c,f))},[c,f,p]);let[M,N]=(0,d.useState)(!!p),P=(0,d.useCallback)(e=>{let t=e.trim();if(m.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${m.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){T(_(t)),m.queryAsTable(t);return}N(!0),m.executeQuery(e)},[m.executeQuery,m.queryAsTable,m.selectedTable]),F=(0,d.useCallback)(e=>{N(!1),m.toggleSort(e)},[m.toggleSort]),I=(0,d.useCallback)(()=>{N(!1),m.clearSort()},[m.clearSort]),L=(0,d.useCallback)(e=>{N(!1),m.setPage(e)},[m.setPage]),R=m.queryResult,z=M&&!!(R||m.queryError),B=m.selectedTable&&!z;return(0,g.jsx)(`div`,{ref:C,className:`flex h-full w-full overflow-hidden`,children:(0,g.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,g.jsx)(r,{className:`size-3.5 text-muted-foreground`}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),m.selectedTable&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,m.selectedTable]}),(0,g.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[m.tableData&&(0,g.jsx)(i,{columns:m.tableData.columns,rows:m.tableData.rows,filename:n?`${n}-${m.selectedTable??`data`}`:m.selectedTable??`data`,exportAllUrl:m.selectedTable?`/api/db/connections/${t}/export?table=${encodeURIComponent(m.selectedTable)}&schema=${m.selectedSchema}`:void 0}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>m.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,g.jsx)(o,{className:`size-3 ${m.loading?`animate-spin`:``}`})})]})]}),(0,g.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:x},children:(0,g.jsx)(u,{onExecute:P,loading:m.queryLoading,defaultValue:E,schemaInfo:A,cacheKey:t?String(t):void 0})}),(0,g.jsx)(`div`,{onMouseDown:k,className:`shrink-0 h-1.5 cursor-row-resize bg-border/50 hover:bg-primary/30 flex items-center justify-center transition-colors`,children:(0,g.jsx)(l,{className:`size-3 text-muted-foreground/50`})}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[B&&m.tableData&&(0,g.jsx)(a,{columns:m.tableData.columns,rows:m.tableData.rows,total:m.tableData.total,limit:m.tableData.limit,schema:m.schema,loading:m.loading,page:m.page,onPageChange:L,onCellUpdate:m.updateCell,onRowDelete:m.deleteRow,orderBy:m.orderBy,orderDir:m.orderDir,onToggleSort:F,onClearSort:I,onBulkDelete:m.bulkDelete,onInsertRow:m.insertRow,connectionId:t,selectedTable:m.selectedTable,selectedSchema:m.selectedSchema,connectionName:n,columnFilters:w,onColumnFilter:D}),z&&(0,g.jsx)(b,{result:R,error:m.queryError,loading:m.queryLoading,schema:m.schema,connectionName:n})]})]})})}var y=()=>{};function b({result:e,error:t,loading:n,schema:r,connectionName:i}){let o=(0,d.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),s=(0,d.useMemo)(()=>r?.length?r:(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[r,e?.columns]);return(0,g.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,g.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,g.jsxs)(`div`,{className:`px-3 py-2 text-green-500 shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,g.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),o&&(0,g.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,g.jsx)(a,{columns:o.columns,rows:o.rows,total:o.total,limit:o.limit,schema:s,loading:!!n,page:1,onPageChange:y,onCellUpdate:y,orderBy:null,orderDir:`ASC`,onToggleSort:y,connectionName:i}),e?.executionTimeMs!=null&&(0,g.jsxs)(`div`,{className:`px-3 py-0.5 border-t border-border text-[10px] text-muted-foreground shrink-0`,children:[e.rows.length,` rows · `,e.executionTimeMs,`ms`]})]}),e?.changeType===`select`&&e.rows.length===0&&(0,g.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,g.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,g.jsx)(c,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{v as DatabaseViewer};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{t as r}from"./text-wrap-DJz9Bgpa.js";import{i,t as a}from"./api-client-DIhJ5qVW.js";import{n as o}from"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import{G as s,Z as c,h as l}from"./index-C5sX7goh.js";import{r as u,t as d}from"./use-monaco-theme-BePWbY58.js";var f=e(n(),1),p=t();function m(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 h({metadata:e}){let t=e?.filePath,n=e?.projectName,h=e?.ref1,_=e?.ref2,v=e?.file1,y=e?.file2,b=e?.original,x=e?.modified,S=b!=null||x!=null,C=!!(v&&y),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(null),[O,k]=(0,f.useState)(null),[A,j]=(0,f.useState)(!S),[M,N]=(0,f.useState)(null),{wordWrap:P,toggleWordWrap:F}=o(l(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),I=d(),L=(0,f.useRef)(null),R=(0,f.useRef)(null),[z,B]=(0,f.useState)(!1),[V,H]=(0,f.useState)();(0,f.useEffect)(()=>{let e=L.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&H(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,f.useEffect)(()=>{if(S||!n)return;if(j(!0),N(null),k(null),D(null),T(null),v&&y){let e=new URLSearchParams({file1:v,file2:y});a.get(`${i(n)}/files/compare?${e}`).then(e=>{D(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}if(t){let e=new URLSearchParams({file:t});h&&e.set(`ref`,h),a.get(`${i(n)}/git/file-full-diff?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)});return}let e;if(h||_){let t=new URLSearchParams;h&&t.set(`ref1`,h),_&&t.set(`ref2`,_),e=`${i(n)}/git/diff?${t}`}else e=`${i(n)}/git/diff`;a.get(e).then(e=>{T(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,h,_,v,y,S]);let{original:U,modified:W}=(0,f.useMemo)(()=>S?{original:b??``,modified:x??``}:C&&E?E:O||(w?g(w):{original:``,modified:``}),[w,S,b,x,C,E,O]),G=(0,f.useMemo)(()=>{let e=t??y??v;return e?m(e):`plaintext`},[t,v,y]),K=typeof window<`u`&&window.innerWidth<768,q=!K;return(0,f.useEffect)(()=>{let e=R.current;if(!e)return;let t=K||P?`on`:`off`;e.updateOptions({diffWordWrap:t}),e.getOriginalEditor().updateOptions({wordWrapOverride2:t}),e.getModifiedEditor().updateOptions({wordWrapOverride2:t})},[P,K,z]),!n&&!S?(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,p.jsx)(s,{className:`size-5 animate-spin`}),(0,p.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!S&&!C&&!O&&!U&&!W?(0,p.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,p.jsx)(c,{className:`size-8`}),(0,p.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,p.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,p.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!K&&(0,p.jsx)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:(0,p.jsx)(`button`,{type:`button`,onClick:F,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${P?`bg-muted text-foreground`:``}`,children:(0,p.jsx)(r,{className:`size-3.5`})})}),(0,p.jsx)(`div`,{ref:L,className:`flex-1 overflow-hidden`,children:V&&V>0?(0,p.jsx)(u,{height:V,language:G,original:U,modified:W,theme:I,onMount:e=>{R.current=e,B(!0)},options:{fontSize:K?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,diffWordWrap:K||P?`on`:`off`,renderSideBySide:q,useInlineViewWhenSpaceIsLimited:!1,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,p.jsx)(s,{className:`size-5 animate-spin text-muted-foreground`})}):(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsx)(s,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function g(e){let t=e.split(`
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{t as r}from"./text-wrap-DJz9Bgpa.js";import{i,t as a}from"./api-client-DIhJ5qVW.js";import{n as o}from"./settings-store-CVrIYYCB.js";import"./vendor-mermaid-Cl50p6TB.js";import{G as s,Z as c,h as l}from"./index-DJtqbPFT.js";import{r as u,t as d}from"./use-monaco-theme-BePWbY58.js";var f=e(n(),1),p=t();function m(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 h({metadata:e}){let t=e?.filePath,n=e?.projectName,h=e?.ref1,_=e?.ref2,v=e?.file1,y=e?.file2,b=e?.original,x=e?.modified,S=b!=null||x!=null,C=!!(v&&y),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(null),[O,k]=(0,f.useState)(null),[A,j]=(0,f.useState)(!S),[M,N]=(0,f.useState)(null),{wordWrap:P,toggleWordWrap:F}=o(l(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),I=d(),L=(0,f.useRef)(null),R=(0,f.useRef)(null),[z,B]=(0,f.useState)(!1),[V,H]=(0,f.useState)();(0,f.useEffect)(()=>{let e=L.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&H(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,f.useEffect)(()=>{if(S||!n)return;if(j(!0),N(null),k(null),D(null),T(null),v&&y){let e=new URLSearchParams({file1:v,file2:y});a.get(`${i(n)}/files/compare?${e}`).then(e=>{D(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}if(t){let e=new URLSearchParams({file:t});h&&e.set(`ref`,h),a.get(`${i(n)}/git/file-full-diff?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)});return}let e;if(h||_){let t=new URLSearchParams;h&&t.set(`ref1`,h),_&&t.set(`ref2`,_),e=`${i(n)}/git/diff?${t}`}else e=`${i(n)}/git/diff`;a.get(e).then(e=>{T(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,h,_,v,y,S]);let{original:U,modified:W}=(0,f.useMemo)(()=>S?{original:b??``,modified:x??``}:C&&E?E:O||(w?g(w):{original:``,modified:``}),[w,S,b,x,C,E,O]),G=(0,f.useMemo)(()=>{let e=t??y??v;return e?m(e):`plaintext`},[t,v,y]),K=typeof window<`u`&&window.innerWidth<768,q=!K;return(0,f.useEffect)(()=>{let e=R.current;if(!e)return;let t=K||P?`on`:`off`;e.updateOptions({diffWordWrap:t}),e.getOriginalEditor().updateOptions({wordWrapOverride2:t}),e.getModifiedEditor().updateOptions({wordWrapOverride2:t})},[P,K,z]),!n&&!S?(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,p.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,p.jsx)(s,{className:`size-5 animate-spin`}),(0,p.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!S&&!C&&!O&&!U&&!W?(0,p.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,p.jsx)(c,{className:`size-8`}),(0,p.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,p.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,p.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!K&&(0,p.jsx)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:(0,p.jsx)(`button`,{type:`button`,onClick:F,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${P?`bg-muted text-foreground`:``}`,children:(0,p.jsx)(r,{className:`size-3.5`})})}),(0,p.jsx)(`div`,{ref:L,className:`flex-1 overflow-hidden`,children:V&&V>0?(0,p.jsx)(u,{height:V,language:G,original:U,modified:W,theme:I,onMount:e=>{R.current=e,B(!0)},options:{fontSize:K?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,diffWordWrap:K||P?`on`:`off`,renderSideBySide:q,useInlineViewWhenSpaceIsLimited:!1,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,p.jsx)(s,{className:`size-5 animate-spin text-muted-foreground`})}):(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,p.jsx)(s,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function g(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{h as DiffViewer};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{x as t}from"./vendor-markdown-0Mxgxy0L.js";import{Y as n}from"./vendor-ui-UXCWAcmi.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";var i=r(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),a=r(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),o=e(t(),1),s=e(n(),1);function c(e){if(!e||typeof document>`u`)return;let t=document.head||document.getElementsByTagName(`head`)[0],n=document.createElement(`style`);n.type=`text/css`,t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}var ee=e=>{switch(e){case`success`:return d;case`info`:return p;case`warning`:return f;case`error`:return m;default:return null}},l=Array(12).fill(0),u=({visible:e,className:t})=>o.createElement(`div`,{className:[`sonner-loading-wrapper`,t].filter(Boolean).join(` `),"data-visible":e},o.createElement(`div`,{className:`sonner-spinner`},l.map((e,t)=>o.createElement(`div`,{className:`sonner-loading-bar`,key:`spinner-bar-${t}`})))),d=o.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},o.createElement(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z`,clipRule:`evenodd`})),f=o.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`currentColor`,height:`20`,width:`20`},o.createElement(`path`,{fillRule:`evenodd`,d:`M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z`,clipRule:`evenodd`})),p=o.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},o.createElement(`path`,{fillRule:`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z`,clipRule:`evenodd`})),m=o.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,height:`20`,width:`20`},o.createElement(`path`,{fillRule:`evenodd`,d:`M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z`,clipRule:`evenodd`})),te=o.createElement(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`},o.createElement(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),o.createElement(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})),ne=()=>{let[e,t]=o.useState(document.hidden);return o.useEffect(()=>{let e=()=>{t(document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>window.removeEventListener(`visibilitychange`,e)},[]),e},h=1,g=new class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)}),this.publish=e=>{this.subscribers.forEach(t=>t(e))},this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]},this.create=e=>{let{message:t,...n}=e,r=typeof e?.id==`number`||e.id?.length>0?e.id:h++,i=this.toasts.find(e=>e.id===r),a=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(r)&&this.dismissedToasts.delete(r),i?this.toasts=this.toasts.map(n=>n.id===r?(this.publish({...n,...e,id:r,title:t}),{...n,...e,id:r,dismissible:a,title:t}):n):this.addToast({title:t,...n,dismissible:a,id:r}),r},this.dismiss=e=>(e?(this.dismissedToasts.add(e),requestAnimationFrame(()=>this.subscribers.forEach(t=>t({id:e,dismiss:!0})))):this.toasts.forEach(e=>{this.subscribers.forEach(t=>t({id:e.id,dismiss:!0}))}),e),this.message=(e,t)=>this.create({...t,message:e}),this.error=(e,t)=>this.create({...t,message:e,type:`error`}),this.success=(e,t)=>this.create({...t,type:`success`,message:e}),this.info=(e,t)=>this.create({...t,type:`info`,message:e}),this.warning=(e,t)=>this.create({...t,type:`warning`,message:e}),this.loading=(e,t)=>this.create({...t,type:`loading`,message:e}),this.promise=(e,t)=>{if(!t)return;let n;t.loading!==void 0&&(n=this.create({...t,promise:e,type:`loading`,message:t.loading,description:typeof t.description==`function`?void 0:t.description}));let r=Promise.resolve(e instanceof Function?e():e),i=n!==void 0,a,s=r.then(async e=>{if(a=[`resolve`,e],o.isValidElement(e))i=!1,this.create({id:n,type:`default`,message:e});else if(v(e)&&!e.ok){i=!1;let r=typeof t.error==`function`?await t.error(`HTTP error! status: ${e.status}`):t.error,a=typeof t.description==`function`?await t.description(`HTTP error! status: ${e.status}`):t.description,s=typeof r==`object`&&!o.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...s})}else if(e instanceof Error){i=!1;let r=typeof t.error==`function`?await t.error(e):t.error,a=typeof t.description==`function`?await t.description(e):t.description,s=typeof r==`object`&&!o.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...s})}else if(t.success!==void 0){i=!1;let r=typeof t.success==`function`?await t.success(e):t.success,a=typeof t.description==`function`?await t.description(e):t.description,s=typeof r==`object`&&!o.isValidElement(r)?r:{message:r};this.create({id:n,type:`success`,description:a,...s})}}).catch(async e=>{if(a=[`reject`,e],t.error!==void 0){i=!1;let r=typeof t.error==`function`?await t.error(e):t.error,a=typeof t.description==`function`?await t.description(e):t.description,s=typeof r==`object`&&!o.isValidElement(r)?r:{message:r};this.create({id:n,type:`error`,description:a,...s})}}).finally(()=>{i&&(this.dismiss(n),n=void 0),t.finally==null||t.finally.call(t)}),c=()=>new Promise((e,t)=>s.then(()=>a[0]===`reject`?t(a[1]):e(a[1])).catch(t));return typeof n!=`string`&&typeof n!=`number`?{unwrap:c}:Object.assign(n,{unwrap:c})},this.custom=(e,t)=>{let n=t?.id||h++;return this.create({jsx:e(n),id:n,...t}),n},this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},_=(e,t)=>{let n=t?.id||h++;return g.addToast({title:e,...t,id:n}),n},v=e=>e&&typeof e==`object`&&`ok`in e&&typeof e.ok==`boolean`&&`status`in e&&typeof e.status==`number`,y=_,b=Object.assign(y,{success:g.success,info:g.info,warning:g.warning,error:g.error,custom:g.custom,message:g.message,promise:g.promise,dismiss:g.dismiss,loading:g.loading},{getHistory:()=>g.toasts,getToasts:()=>g.getActiveToasts()});c(`[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-rich-colors=true][data-sonner-toast][data-styled=true] [data-description]{color:inherit}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast][data-expanded=true]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}`);function x(e){return e.label!==void 0}var S=3,C=`24px`,w=`16px`,T=4e3,E=356,D=14,O=45,re=200;function k(...e){return e.filter(Boolean).join(` `)}function A(e){let[t,n]=e.split(`-`),r=[];return t&&r.push(t),n&&r.push(n),r}var j=e=>{let{invert:t,toast:n,unstyled:r,interacting:i,setHeights:a,visibleToasts:s,heights:c,index:l,toasts:d,expanded:f,removeToast:p,defaultRichColors:m,closeButton:h,style:g,cancelButtonStyle:_,actionButtonStyle:v,className:y=``,descriptionClassName:b=``,duration:S,position:C,gap:w,expandByDefault:E,classNames:D,icons:j,closeButtonAriaLabel:M=`Close toast`}=e,[N,P]=o.useState(null),[F,I]=o.useState(null),[L,R]=o.useState(!1),[z,B]=o.useState(!1),[V,H]=o.useState(!1),[ie,ae]=o.useState(!1),[oe,se]=o.useState(!1),[ce,U]=o.useState(0),[le,ue]=o.useState(0),W=o.useRef(n.duration||S||T),de=o.useRef(null),G=o.useRef(null),fe=l===0,pe=l+1<=s,K=n.type,q=n.dismissible!==!1,me=n.className||``,he=n.descriptionClassName||``,J=o.useMemo(()=>c.findIndex(e=>e.toastId===n.id)||0,[c,n.id]),ge=o.useMemo(()=>n.closeButton??h,[n.closeButton,h]),_e=o.useMemo(()=>n.duration||S||T,[n.duration,S]),Y=o.useRef(0),X=o.useRef(0),ve=o.useRef(0),Z=o.useRef(null),[ye,be]=C.split(`-`),xe=o.useMemo(()=>c.reduce((e,t,n)=>n>=J?e:e+t.height,0),[c,J]),Se=ne(),Ce=n.invert||t,Q=K===`loading`;X.current=o.useMemo(()=>J*w+xe,[J,xe]),o.useEffect(()=>{W.current=_e},[_e]),o.useEffect(()=>{R(!0)},[]),o.useEffect(()=>{let e=G.current;if(e){let t=e.getBoundingClientRect().height;return ue(t),a(e=>[{toastId:n.id,height:t,position:n.position},...e]),()=>a(e=>e.filter(e=>e.toastId!==n.id))}},[a,n.id]),o.useLayoutEffect(()=>{if(!L)return;let e=G.current,t=e.style.height;e.style.height=`auto`;let r=e.getBoundingClientRect().height;e.style.height=t,ue(r),a(e=>e.find(e=>e.toastId===n.id)?e.map(e=>e.toastId===n.id?{...e,height:r}:e):[{toastId:n.id,height:r,position:n.position},...e])},[L,n.title,n.description,a,n.id,n.jsx,n.action,n.cancel]);let $=o.useCallback(()=>{B(!0),U(X.current),a(e=>e.filter(e=>e.toastId!==n.id)),setTimeout(()=>{p(n)},re)},[n,p,a,X]);o.useEffect(()=>{if(n.promise&&K===`loading`||n.duration===1/0||n.type===`loading`)return;let e;return f||i||Se?(()=>{if(ve.current<Y.current){let e=new Date().getTime()-Y.current;W.current-=e}ve.current=new Date().getTime()})():W.current!==1/0&&(Y.current=new Date().getTime(),e=setTimeout(()=>{n.onAutoClose==null||n.onAutoClose.call(n,n),$()},W.current)),()=>clearTimeout(e)},[f,i,n,K,Se,$]),o.useEffect(()=>{n.delete&&($(),n.onDismiss==null||n.onDismiss.call(n,n))},[$,n.delete]);function we(){return j?.loading?o.createElement(`div`,{className:k(D?.loader,n?.classNames?.loader,`sonner-loader`),"data-visible":K===`loading`},j.loading):o.createElement(u,{className:k(D?.loader,n?.classNames?.loader),visible:K===`loading`})}let Te=n.icon||j?.[K]||ee(K);return o.createElement(`li`,{tabIndex:0,ref:G,className:k(y,me,D?.toast,n?.classNames?.toast,D?.default,D?.[K],n?.classNames?.[K]),"data-sonner-toast":``,"data-rich-colors":n.richColors??m,"data-styled":!(n.jsx||n.unstyled||r),"data-mounted":L,"data-promise":!!n.promise,"data-swiped":oe,"data-removed":z,"data-visible":pe,"data-y-position":ye,"data-x-position":be,"data-index":l,"data-front":fe,"data-swiping":V,"data-dismissible":q,"data-type":K,"data-invert":Ce,"data-swipe-out":ie,"data-swipe-direction":F,"data-expanded":!!(f||E&&L),"data-testid":n.testId,style:{"--index":l,"--toasts-before":l,"--z-index":d.length-l,"--offset":`${z?ce:X.current}px`,"--initial-height":E?`auto`:`${le}px`,...g,...n.style},onDragEnd:()=>{H(!1),P(null),Z.current=null},onPointerDown:e=>{e.button!==2&&(Q||!q||(de.current=new Date,U(X.current),e.target.setPointerCapture(e.pointerId),e.target.tagName!==`BUTTON`&&(H(!0),Z.current={x:e.clientX,y:e.clientY})))},onPointerUp:()=>{if(ie||!q)return;Z.current=null;let e=Number(G.current?.style.getPropertyValue(`--swipe-amount-x`).replace(`px`,``)||0),t=Number(G.current?.style.getPropertyValue(`--swipe-amount-y`).replace(`px`,``)||0),r=new Date().getTime()-de.current?.getTime(),i=N===`x`?e:t,a=Math.abs(i)/r;if(Math.abs(i)>=O||a>.11){U(X.current),n.onDismiss==null||n.onDismiss.call(n,n),I(N===`x`?e>0?`right`:`left`:t>0?`down`:`up`),$(),ae(!0);return}else{var o,s;(o=G.current)==null||o.style.setProperty(`--swipe-amount-x`,`0px`),(s=G.current)==null||s.style.setProperty(`--swipe-amount-y`,`0px`)}se(!1),H(!1),P(null)},onPointerMove:t=>{var n,r;if(!Z.current||!q||window.getSelection()?.toString().length>0)return;let i=t.clientY-Z.current.y,a=t.clientX-Z.current.x,o=e.swipeDirections??A(C);!N&&(Math.abs(a)>1||Math.abs(i)>1)&&P(Math.abs(a)>Math.abs(i)?`x`:`y`);let s={x:0,y:0},c=e=>1/(1.5+Math.abs(e)/20);if(N===`y`){if(o.includes(`top`)||o.includes(`bottom`))if(o.includes(`top`)&&i<0||o.includes(`bottom`)&&i>0)s.y=i;else{let e=i*c(i);s.y=Math.abs(e)<Math.abs(i)?e:i}}else if(N===`x`&&(o.includes(`left`)||o.includes(`right`)))if(o.includes(`left`)&&a<0||o.includes(`right`)&&a>0)s.x=a;else{let e=a*c(a);s.x=Math.abs(e)<Math.abs(a)?e:a}(Math.abs(s.x)>0||Math.abs(s.y)>0)&&se(!0),(n=G.current)==null||n.style.setProperty(`--swipe-amount-x`,`${s.x}px`),(r=G.current)==null||r.style.setProperty(`--swipe-amount-y`,`${s.y}px`)}},ge&&!n.jsx&&K!==`loading`?o.createElement(`button`,{"aria-label":M,"data-disabled":Q,"data-close-button":!0,onClick:Q||!q?()=>{}:()=>{$(),n.onDismiss==null||n.onDismiss.call(n,n)},className:k(D?.closeButton,n?.classNames?.closeButton)},j?.close??te):null,(K||n.icon||n.promise)&&n.icon!==null&&(j?.[K]!==null||n.icon)?o.createElement(`div`,{"data-icon":``,className:k(D?.icon,n?.classNames?.icon)},n.promise||n.type===`loading`&&!n.icon?n.icon||we():null,n.type===`loading`?null:Te):null,o.createElement(`div`,{"data-content":``,className:k(D?.content,n?.classNames?.content)},o.createElement(`div`,{"data-title":``,className:k(D?.title,n?.classNames?.title)},n.jsx?n.jsx:typeof n.title==`function`?n.title():n.title),n.description?o.createElement(`div`,{"data-description":``,className:k(b,he,D?.description,n?.classNames?.description)},typeof n.description==`function`?n.description():n.description):null),o.isValidElement(n.cancel)?n.cancel:n.cancel&&x(n.cancel)?o.createElement(`button`,{"data-button":!0,"data-cancel":!0,style:n.cancelButtonStyle||_,onClick:e=>{x(n.cancel)&&q&&(n.cancel.onClick==null||n.cancel.onClick.call(n.cancel,e),$())},className:k(D?.cancelButton,n?.classNames?.cancelButton)},n.cancel.label):null,o.isValidElement(n.action)?n.action:n.action&&x(n.action)?o.createElement(`button`,{"data-button":!0,"data-action":!0,style:n.actionButtonStyle||v,onClick:e=>{x(n.action)&&(n.action.onClick==null||n.action.onClick.call(n.action,e),!e.defaultPrevented&&$())},className:k(D?.actionButton,n?.classNames?.actionButton)},n.action.label):null)};function M(){if(typeof window>`u`||typeof document>`u`)return`ltr`;let e=document.documentElement.getAttribute(`dir`);return e===`auto`||!e?window.getComputedStyle(document.documentElement).direction:e}function N(e,t){let n={};return[e,t].forEach((e,t)=>{let r=t===1,i=r?`--mobile-offset`:`--offset`,a=r?w:C;function o(e){[`top`,`right`,`bottom`,`left`].forEach(t=>{n[`${i}-${t}`]=typeof e==`number`?`${e}px`:e})}typeof e==`number`||typeof e==`string`?o(e):typeof e==`object`?[`top`,`right`,`bottom`,`left`].forEach(t=>{e[t]===void 0?n[`${i}-${t}`]=a:n[`${i}-${t}`]=typeof e[t]==`number`?`${e[t]}px`:e[t]}):o(a)}),n}var P=o.forwardRef(function(e,t){let{id:n,invert:r,position:i=`bottom-right`,hotkey:a=[`altKey`,`KeyT`],expand:c,closeButton:ee,className:l,offset:u,mobileOffset:d,theme:f=`light`,richColors:p,duration:m,style:te,visibleToasts:ne=S,toastOptions:h,dir:_=M(),gap:v=D,icons:y,containerAriaLabel:b=`Notifications`}=e,[x,C]=o.useState([]),w=o.useMemo(()=>n?x.filter(e=>e.toasterId===n):x.filter(e=>!e.toasterId),[x,n]),T=o.useMemo(()=>Array.from(new Set([i].concat(w.filter(e=>e.position).map(e=>e.position)))),[w,i]),[O,re]=o.useState([]),[k,A]=o.useState(!1),[P,F]=o.useState(!1),[I,L]=o.useState(f===`system`?typeof window<`u`&&window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:f),R=o.useRef(null),z=a.join(`+`).replace(/Key/g,``).replace(/Digit/g,``),B=o.useRef(null),V=o.useRef(!1),H=o.useCallback(e=>{C(t=>(t.find(t=>t.id===e.id)?.delete||g.dismiss(e.id),t.filter(({id:t})=>t!==e.id)))},[]);return o.useEffect(()=>g.subscribe(e=>{if(e.dismiss){requestAnimationFrame(()=>{C(t=>t.map(t=>t.id===e.id?{...t,delete:!0}:t))});return}setTimeout(()=>{s.flushSync(()=>{C(t=>{let n=t.findIndex(t=>t.id===e.id);return n===-1?[e,...t]:[...t.slice(0,n),{...t[n],...e},...t.slice(n+1)]})})})}),[x]),o.useEffect(()=>{if(f!==`system`){L(f);return}if(f===`system`&&(window.matchMedia&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?L(`dark`):L(`light`)),typeof window>`u`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`);try{e.addEventListener(`change`,({matches:e})=>{L(e?`dark`:`light`)})}catch{e.addListener(({matches:e})=>{try{L(e?`dark`:`light`)}catch(e){console.error(e)}})}},[f]),o.useEffect(()=>{x.length<=1&&A(!1)},[x]),o.useEffect(()=>{let e=e=>{if(a.every(t=>e[t]||e.code===t)){var t;A(!0),(t=R.current)==null||t.focus()}e.code===`Escape`&&(document.activeElement===R.current||R.current?.contains(document.activeElement))&&A(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]),o.useEffect(()=>{if(R.current)return()=>{B.current&&(B.current.focus({preventScroll:!0}),B.current=null,V.current=!1)}},[R.current]),o.createElement(`section`,{ref:t,"aria-label":`${b} ${z}`,tabIndex:-1,"aria-live":`polite`,"aria-relevant":`additions text`,"aria-atomic":`false`,suppressHydrationWarning:!0},T.map((t,n)=>{let[i,a]=t.split(`-`);return w.length?o.createElement(`ol`,{key:t,dir:_===`auto`?M():_,tabIndex:-1,ref:R,className:l,"data-sonner-toaster":!0,"data-sonner-theme":I,"data-y-position":i,"data-x-position":a,style:{"--front-toast-height":`${O[0]?.height||0}px`,"--width":`${E}px`,"--gap":`${v}px`,...te,...N(u,d)},onBlur:e=>{V.current&&!e.currentTarget.contains(e.relatedTarget)&&(V.current=!1,B.current&&=(B.current.focus({preventScroll:!0}),null))},onFocus:e=>{e.target instanceof HTMLElement&&e.target.dataset.dismissible===`false`||V.current||(V.current=!0,B.current=e.relatedTarget)},onMouseEnter:()=>A(!0),onMouseMove:()=>A(!0),onMouseLeave:()=>{P||A(!1)},onDragEnd:()=>A(!1),onPointerDown:e=>{e.target instanceof HTMLElement&&e.target.dataset.dismissible===`false`||F(!0)},onPointerUp:()=>F(!1)},w.filter(e=>!e.position&&n===0||e.position===t).map((n,i)=>o.createElement(j,{key:n.id,icons:y,index:i,toast:n,defaultRichColors:p,duration:h?.duration??m,className:h?.className,descriptionClassName:h?.descriptionClassName,invert:r,visibleToasts:ne,closeButton:h?.closeButton??ee,interacting:P,position:t,style:h?.style,unstyled:h?.unstyled,classNames:h?.classNames,cancelButtonStyle:h?.cancelButtonStyle,actionButtonStyle:h?.actionButtonStyle,closeButtonAriaLabel:h?.closeButtonAriaLabel,removeToast:H,toasts:w.filter(e=>e.position==n.position),heights:O.filter(e=>e.position==n.position),setHeights:re,expandByDefault:c,gap:v,expanded:k,swipeDirections:e.swipeDirections}))):null}))});export{i,b as n,a as r,P as t};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{r}from"./api-client-DIhJ5qVW.js";import{G as i,w as a}from"./index-C5sX7goh.js";var o=e(n(),1),s=t(),c=`<script>
1
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{r}from"./api-client-DIhJ5qVW.js";import{G as i,w as a}from"./index-DJtqbPFT.js";var o=e(n(),1),s=t(),c=`<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 l(e){if(!e)return e;let t=e.indexOf(`<head>`);return t===-1?c+e:e.slice(0,t+6)+c+e.slice(t+6)}function u({metadata:e}){let t=e?.panelId,n=e?.viewType,c=e?.projectName||void 0,[u,d]=(0,o.useState)(!1),f=a(e=>e.contributions!==null),p=a(e=>{if(t&&e.webviewPanels[t])return e.webviewPanels[t];if(n){let t=n.includes(`.`)?n:`${n}.view`;return Object.values(e.webviewPanels).find(e=>e.viewType===n||e.viewType===t)}}),m=p?.id??t,h=(0,o.useRef)(null),g=p?.html??``,_=l(g),v=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(p||!n||!f||c&&c===v.current)return;c&&(v.current=c);let e=n.includes(`.`)?n:`${n}.view`,t=!1;async function i(){let n=[];if(c)try{let e=r(),t=(await(await fetch(`/api/projects`,e?{headers:{Authorization:`Bearer ${e}`}}:{})).json()).data?.find(e=>e.name===c);t&&(n=[t.path])}catch{}t||window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:n}}))}return i(),()=>{t=!0}},[p,n,c,f]);let y=e?.extensionId,b=a(e=>{if(y&&e.activationErrors[y])return e.activationErrors[y];if(n){for(let[t,r]of Object.entries(e.activationErrors))if(t===`ext-${n}`)return r}}),x=(0,o.useCallback)(()=>{if(d(!1),!n)return;let e=n.includes(`.`)?n:`${n}.view`;(async()=>{try{let t=r(),n=(await(await fetch(`/api/projects`,t?{headers:{Authorization:`Bearer ${t}`}}:{})).json()).data?.find(e=>e.name===c),i=n?[n.path]:[];window.dispatchEvent(new CustomEvent(`ext:command:execute`,{detail:{command:e,args:i}}))}catch{}})()},[n,c]),S=(0,o.useRef)(null),C=(0,o.useRef)(n);return(0,o.useEffect)(()=>{S.current=m??null},[m]),(0,o.useEffect)(()=>{C.current=n},[n]),(0,o.useEffect)(()=>()=>{let e=S.current;if(e){let t=C.current;a.getState().removeWebviewPanel(e),window.dispatchEvent(new CustomEvent(`ext:webview:close`,{detail:{panelId:e,viewType:t}}))}},[]),(0,o.useEffect)(()=>{if(p){d(!1);return}if(!f||!n)return;let e=0,t=setInterval(()=>{if(e++,e>3){clearInterval(t),d(!0);return}x()},2e3);return()=>clearInterval(t)},[p,f,n,x]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{h.current&&e.source===h.current.contentWindow&&window.dispatchEvent(new CustomEvent(`ext:webview:send`,{detail:{panelId:m,message:e.data}}))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[m]),(0,o.useEffect)(()=>{if(!m)return;let e=e=>{let{panelId:t,message:n}=e.detail;t===m&&h.current?.contentWindow?.postMessage(n,`*`)};return window.addEventListener(`ext:webview:message`,e),()=>window.removeEventListener(`ext:webview:message`,e)},[m]),!p||!g?(0,s.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-sm text-text-subtle`,children:u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`span`,{className:`text-destructive font-medium`,children:`Extension failed to load`}),b&&(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground max-w-md text-center`,children:b}),(0,s.jsx)(`button`,{onClick:x,className:`text-xs text-primary hover:underline`,children:`Retry`})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i,{className:`size-5 animate-spin`}),(0,s.jsx)(`span`,{children:`Loading extension...`})]})}):(0,s.jsx)(`div`,{className:`h-full w-full relative`,children:(0,s.jsx)(`iframe`,{ref:h,srcDoc:_,sandbox:`allow-scripts`,className:`w-full h-full border-0 bg-white dark:bg-zinc-900`,title:p.title},m)})}export{u as ExtensionWebview};