@hienlh/ppm 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/CLAUDE.md +1 -1
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/cli-reference.md +4 -4
- package/assets/skills/ppm/references/http-api.md +1 -1
- package/dist/web/assets/accounts-settings-section-D3BylchP.js +1 -0
- package/dist/web/assets/{ai-resource-editor-CdDpOwjh.js → ai-resource-editor-BLPcnhTM.js} +1 -1
- package/dist/web/assets/{ai-settings-section-X2UOfSaS.js → ai-settings-section-BtR7rF-T.js} +1 -1
- package/dist/web/assets/{ai-settings-section-B1hQyjAd.js → ai-settings-section-r9JctHNM.js} +1 -1
- package/dist/web/assets/{appearance-settings-section-DLoPK0LD.js → appearance-settings-section-CiMdk3sb.js} +1 -1
- package/dist/web/assets/{branch-review-tab-G84Ojzae.js → branch-review-tab-B1pFjlKM.js} +1 -1
- package/dist/web/assets/chat-tab-DZagX06m.js +15 -0
- package/dist/web/assets/{code-editor-D04iUPsZ.js → code-editor-BJhOEsnZ.js} +4 -4
- package/dist/web/assets/{codex-daily-guard-BSccLRGT.js → codex-daily-guard-CaCQJ4r_.js} +1 -1
- package/dist/web/assets/{conflict-editor-C4ay676e.js → conflict-editor-B7u_p49h.js} +3 -3
- package/dist/web/assets/{csv-preview-DbwEmG7o.js → csv-preview-CttjJU1e.js} +1 -1
- package/dist/web/assets/{database-viewer-S6LsALjX.js → database-viewer-Ca4HxIfx.js} +1 -1
- package/dist/web/assets/{diff-viewer-3oBA7vgQ.js → diff-viewer-9-XjLIwa.js} +1 -1
- package/dist/web/assets/{editor-language-service-DJmaKVY0.js → editor-language-service-D0DuEOs_.js} +1 -1
- package/dist/web/assets/{explorer-body-BQ0jyAGv.js → explorer-body-VdCBqcZu.js} +2 -2
- package/dist/web/assets/{explorer-window-content-jdkWt34J.js → explorer-window-content-BIsbl7Th.js} +1 -1
- package/dist/web/assets/extension-manager-section-HkY7geS5.js +1 -0
- package/dist/web/assets/{extension-webview-BGSDUbdK.js → extension-webview-DZG8YHX9.js} +1 -1
- package/dist/web/assets/{files-settings-section-Gnyd7han.js → files-settings-section-qnRtkX05.js} +1 -1
- package/dist/web/assets/{general-settings-section-V6Khh15V.js → general-settings-section-BAFSZmCE.js} +1 -1
- package/dist/web/assets/{git-log-panel-Bi513qjT.js → git-log-panel-2sGpfEla.js} +1 -1
- package/dist/web/assets/{glide-data-grid-DnQwYSmQ.js → glide-data-grid-f0hyITiF.js} +1 -1
- package/dist/web/assets/{group-chat-tab-DpczdwyV.js → group-chat-tab-Ck6sk7yY.js} +1 -1
- package/dist/web/assets/index-CEZVxM4G.js +52 -0
- package/dist/web/assets/{jira-watcher-section-f2HUbGDY.js → jira-watcher-section-CeLmhvu1.js} +1 -1
- package/dist/web/assets/keybindings-store-C_3ChOEf.js +1 -0
- package/dist/web/assets/{keyboard-shortcuts-section-BpvVEw_Y.js → keyboard-shortcuts-section-PVz6kuh2.js} +1 -1
- package/dist/web/assets/markdown-renderer-C140Ijk0.js +3 -0
- package/dist/web/assets/{markdown-renderer-Bcaf9_bA.js → markdown-renderer-Dz7-DYUg.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-Bol3XAO1.js → mobile-explorer-sheet-CUG_owdf.js} +1 -1
- package/dist/web/assets/notification-store-6vib1ISy.js +1 -0
- package/dist/web/assets/{ppmbot-settings-section-DKJUA3Kq.js → ppmbot-settings-section-Cji-Mil-.js} +1 -1
- package/dist/web/assets/{problems-panel-CFcoUx8h.js → problems-panel-a6_hrWvl.js} +1 -1
- package/dist/web/assets/{process-table-EKr2dqG6.js → process-table-CiIqlOIK.js} +1 -1
- package/dist/web/assets/{proxy-settings-section-B7qRVl8w.js → proxy-settings-section-BjI4IFgp.js} +1 -1
- package/dist/web/assets/{remote-desktop-clipboard-notice-0WDYsyCA.js → remote-desktop-clipboard-notice-eXYvwgx7.js} +1 -1
- package/dist/web/assets/{remote-desktop-mobile-sheet-COYDg16H.js → remote-desktop-mobile-sheet-Doh-fci-.js} +2 -2
- package/dist/web/assets/{remote-desktop-mobile-view-2DqSuS2U.js → remote-desktop-mobile-view-Dt8Akc3p.js} +1 -1
- package/dist/web/assets/{remote-desktop-readiness-gate-Dm_qMJMH.js → remote-desktop-readiness-gate-t83fqbID.js} +1 -1
- package/dist/web/assets/{remote-desktop-window-content-UodhsF7W.js → remote-desktop-window-content-CguhZMmx.js} +1 -1
- package/dist/web/assets/{schedules-settings-section-bG2lYfGv.js → schedules-settings-section-BVkpW5ms.js} +1 -1
- package/dist/web/assets/{settings-body-C06bFarv.js → settings-body-CoIxYAh6.js} +2 -2
- package/dist/web/assets/{settings-tab-34RSaASd.js → settings-tab-7DKVUTbM.js} +1 -1
- package/dist/web/assets/{settings-window-content-Dr_2lmHH.js → settings-window-content-3_39TeX-.js} +1 -1
- package/dist/web/assets/{sql-query-editor-BgRH0cHD.js → sql-query-editor-CQB7Yp7U.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DUxGslpa.js → sqlite-viewer-Bd7rjr1D.js} +1 -1
- package/dist/web/assets/{system-monitor-body-IZuLn7Qh.js → system-monitor-body-DsRXeMyU.js} +2 -2
- package/dist/web/assets/{system-monitor-tab-DiSA490Z.js → system-monitor-tab-DdSZgux3.js} +1 -1
- package/dist/web/assets/{system-monitor-window-content-CEaFISgj.js → system-monitor-window-content-ClPo4-El.js} +1 -1
- package/dist/web/assets/{tab-host-window-content-D0TN8Wrq.js → tab-host-window-content-d2TAD4PU.js} +1 -1
- package/dist/web/assets/{team-member-sheet-DDPNcCjd.js → team-member-sheet-7d2Qp-ie.js} +2 -2
- package/dist/web/assets/{team-member-window-content-DCiW_1-E.js → team-member-window-content-Bctg2gmg.js} +1 -1
- package/dist/web/assets/{terminal-tab-4ypP0NDY.js → terminal-tab-0HQic25V.js} +3 -3
- package/dist/web/assets/{tool-cards-Dd6E7Q3k.js → tool-cards-CmLLRACd.js} +2 -2
- package/dist/web/assets/{use-inline-blame-vrfFHuaR.js → use-inline-blame-sDMjcz1-.js} +3 -3
- package/dist/web/assets/{use-lsp-CsuZu49X.js → use-lsp-CBgID-EU.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-BIVYJBIn.js → use-monaco-theme-gvhJ_jZh.js} +1 -1
- package/dist/web/assets/{use-websocket-BMbufhX7.js → use-websocket-C9wlRliB.js} +1 -1
- package/dist/web/assets/{video-preview-Byj8P_jA.js → video-preview-CSDK5j6H.js} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/docs/architecture/ai-chat-and-providers.md +9 -0
- package/package.json +1 -1
- package/packages/ext-git-graph/src/webview-html.test.ts +30 -5
- package/packages/ext-git-graph/src/webview-html.ts +99 -31
- package/src/services/edge-forwarder.ts +191 -191
- package/src/services/windows-process-tree.ts +351 -351
- package/src/shared/codex-daily-guard.ts +12 -5
- package/src/web/components/extensions/extension-tree-view.tsx +4 -11
- package/src/web/components/layout/command-palette.tsx +2 -18
- package/src/web/components/settings/accounts/account-card.tsx +2 -2
- package/src/web/components/settings/accounts/codex-accounts-section.tsx +4 -4
- package/src/web/components/settings/extension-manager-section.tsx +8 -1
- package/src/web/lib/extension-icons.ts +70 -0
- package/src/web/lib/tab-type-icons.ts +14 -0
- package/dist/web/assets/accounts-settings-section-BVr9-FZJ.js +0 -1
- package/dist/web/assets/chat-tab-DQJfjm8E.js +0 -15
- package/dist/web/assets/extension-manager-section-DG1guILi.js +0 -1
- package/dist/web/assets/index-DU68xk06.js +0 -52
- package/dist/web/assets/keybindings-store-DCRsnKg5.js +0 -1
- package/dist/web/assets/markdown-renderer-DGJp8HC3.js +0 -3
- package/dist/web/assets/notification-store-BXt54VIn.js +0 -1
- package/packages/vscode-compat/node_modules/.bin/tsc.bunx +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsc.exe +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsserver.bunx +0 -0
- package/packages/vscode-compat/node_modules/.bin/tsserver.exe +0 -0
- package/src/web/hooks/use-delayed-flag.ts +0 -35
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{Br as r,Dr as i,Et as a,Gn as o,Gr as s,It as c,Mr as l,Qn as u,Wr as d,Z as f,Zn as p,_t as m,at as ee,ct as h,dr as te,dt as g,ft as _,j as v,ln as y,lt as b,nt as x,q as ne,r as re,st as S,ur as ie,vr as ae,vt as oe,w as se,yt as ce,zr as le}from"./icons-DQjqk0lJ.js";import{t as ue}from"./createLucideIcon-DoiEKeJ_.js";import{i as de,n as C}from"./api-client-C1ZwRL4Y.js";import{t as w}from"./settings-store-krC6bc79.js";import{q as T}from"./vendor-mermaid-BitiXJlL.js";import{t as fe}from"./utils-Bmf_8h7Y.js";import"./portal-container-context-BarKmT4S.js";import{t as pe}from"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{i as me}from"./project-store-B87hLRSk.js";import"./project-framework-store-B70Q3dNM.js";import{t as he}from"./tab-store-OJa1GPCq.js";import{o as E}from"./file-store-ojgMXgAw.js";import{n as ge,t as _e}from"./use-is-mobile-TkcwP1Gx.js";import"./git-repo-store-88Z8v-pF.js";import{d as ve}from"./format-file-meta-C77h04cZ.js";import{t as D}from"./button-B9CTrsEf.js";import{a as ye,i as O,n as be,o as xe,t as k}from"./dialog-B84_DJQ8.js";import"./file-icons-BXdvggK2.js";import{t as Se}from"./mobile-bottom-sheet-C3TniEP-.js";import"./use-visual-viewport-Lp878uzs.js";import{t as Ce}from"./input-C7Q8FxeL.js";import"./scroll-area-BzeiOd-B.js";import{$t as we,Ht as A,Jt as j,Rt as Te,Vt as M,X as Ee,Xt as N,Y as De,Yt as P,Z as Oe,c as ke,i as Ae,qt as je,zt as Me}from"./index-DU68xk06.js";import"./data-grid-types-C5bthITf.js";import{t as Ne}from"./use-monaco-theme-BIVYJBIn.js";import{n as Pe,t as Fe}from"./editor-font-ClTC9gaD.js";import{t as Ie}from"./use-inline-blame-vrfFHuaR.js";import{n as Le,r as Re}from"./monaco-dotenv-language-uB-wok6C.js";import{i as ze,n as Be,r as Ve,t as He}from"./can-open-in-ppm-cv5--yHX.js";import{a as Ue,i as We,o as Ge,r as Ke,t as qe}from"./glide-data-grid-DnQwYSmQ.js";var Je=ue(`file-braces`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),F=e(t(),1),I=[`completionItems`,`hovers`,`documentSymbols`,`definitions`,`references`,`documentHighlights`,`rename`,`diagnostics`,`documentRangeFormattingEdits`,`signatureHelp`,`onTypeFormattingEdits`,`codeActions`,`inlayHints`];function L(e){return Object.fromEntries(I.map(t=>[t,e]))}var Ye=L(!1),Xe=L(!0),Ze={noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0},Qe=1;function $e(e,t){for(let n of[e,t])n.setModeConfiguration({...Ye}),n.setDiagnosticsOptions({...Ze})}function et(e,t){for(let n of[e,t])n.setCompilerOptions({...n.getCompilerOptions(),jsx:Qe,allowJs:!0,allowNonTsExtensions:!0}),n.setModeConfiguration({...Xe}),n.setDiagnosticsOptions({...Ze})}function tt(e,t,n){e?$e(t,n):et(t,n)}var R=n();function nt({enabled:e,onToggle:t,status:n,diagnostics:r}){let[i,a]=(0,F.useState)(!1),o=ge();if(!e)return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),title:`Language server: off. Turn it on for completions, hover, go to definition, rename and quick fix from a real server. It runs as a process on the host.`,className:`flex items-center gap-1 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted active:scale-95 transition-colors ${o?`min-h-11`:`py-0.5`}`,children:[(0,R.jsx)(s,{className:`size-3 shrink-0`}),(0,R.jsx)(`span`,{children:`LSP off`})]});if(!n)return null;let c=r.filter(e=>e.severity===1).length,l=r.filter(e=>e.severity===2).length,u=n.state===`ready`?n.server.displayName:n.state===`opening`?`Starting…`:n.server?.displayName??`No server`,f=n.state===`unavailable`&&n.reason===`not-installed`;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>a(!0),title:n.state===`ready`?`${n.server.displayName} — rooted at ${n.server.rootPath}`:n.state===`unavailable`?n.message:`Starting the language server`,className:`flex items-center gap-1 rounded px-1.5 hover:bg-muted active:scale-95 transition-colors text-xs ${o?`min-h-11`:`py-0.5`} ${f?`text-amber-500`:`text-muted-foreground`}`,children:[n.state===`opening`?(0,R.jsx)(y,{className:`size-3 animate-spin shrink-0`}):f?(0,R.jsx)(re,{className:`size-3 shrink-0`}):(0,R.jsx)(d,{className:`size-3 shrink-0`}),(0,R.jsx)(`span`,{className:`max-w-24 truncate`,children:u}),c>0&&(0,R.jsx)(`span`,{className:`text-red-500`,children:c}),c===0&&l>0&&(0,R.jsx)(`span`,{className:`text-amber-500`,children:l})]}),i&&(0,R.jsx)(rt,{status:n,errors:c,warnings:l,isMobile:o,onToggle:t,onClose:()=>a(!1)})]})}function rt({status:e,errors:t,warnings:n,isMobile:r,onToggle:i,onClose:a}){let o=(0,R.jsx)(it,{status:e,errors:t,warnings:n,isMobile:r,onToggle:i});return r?(0,R.jsx)(Se,{open:!0,onClose:a,className:`popover-solid max-h-[85dvh] flex flex-col`,children:o}):(0,R.jsx)(k,{open:!0,onOpenChange:e=>!e&&a(),children:(0,R.jsxs)(be,{className:`sm:max-w-lg`,children:[(0,R.jsx)(xe,{children:`Language server`}),o]})})}function it({status:e,errors:t,warnings:n,isMobile:r,onToggle:i}){return(0,R.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto text-sm leading-relaxed`,children:[e.state===`ready`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(z,{label:`Server`,value:e.server.displayName}),(0,R.jsx)(z,{label:`Language`,value:e.languageId}),(0,R.jsx)(z,{label:`Project root`,value:e.server.rootPath,mono:!0}),(0,R.jsx)(z,{label:`Problems`,value:`${t} error${t===1?``:`s`}, ${n} warning${n===1?``:`s`}`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Completions, hover, go to definition (F12), find references (Shift+F12), rename (F2), quick fix (Ctrl+.) and format (Shift+Alt+F) all come from this server.`})]}),e.state===`opening`&&(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`Starting the language server. A cold start reads the project's dependencies, so the first completion in a large project can take a few seconds.`}),e.state===`unavailable`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{children:e.message}),e.server&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Install it, then reopen this file. PPM does not install it for you — that would mean fetching and running a binary because you opened a file.`}),(0,R.jsx)(B,{command:e.server.installHint,isMobile:r})]}),e.reason===`no-language`&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No language server is registered for this file type.`})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-border pt-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-xs font-medium`,children:`Language server`}),(0,R.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`On for this device. Turning it off stops the process.`})]}),(0,R.jsx)(De,{checked:!0,onCheckedChange:e=>i(e)})]})]})}function z({label:e,value:t,mono:n}){return(0,R.jsxs)(`div`,{className:`flex gap-2 items-baseline`,children:[(0,R.jsx)(`span`,{className:`text-muted-foreground shrink-0 w-24 text-xs`,children:e}),(0,R.jsx)(`span`,{className:`min-w-0 break-all ${n?`font-mono text-xs`:``}`,children:t})]})}function B({command:e,isMobile:t}){let[n,r]=(0,F.useState)(!1);return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})},className:`w-full flex items-center gap-2 rounded border border-border bg-muted/40 px-3 text-left font-mono text-xs hover:bg-muted active:scale-[0.99] transition ${t?`min-h-11 py-3`:`py-2`}`,children:[(0,R.jsx)(`span`,{className:`flex-1 break-all`,children:e}),n?(0,R.jsx)(se,{className:`size-3.5 shrink-0 text-green-500`}):(0,R.jsx)(x,{className:`size-3.5 shrink-0 opacity-60`})]})}function at(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function V(e){return(await C.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function H({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:i,openTab:a}=he(Te(e=>({updateTab:e.updateTab,openTab:e.openTab}))),o=(0,F.useRef)(null),s=(0,F.useMemo)(()=>at(e),[e]);(0,F.useEffect)(()=>{o.current&&(o.current.scrollLeft=o.current.scrollWidth)},[s]);let c=(0,F.useCallback)((e,r)=>{let o=fe(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?a({type:`editor`,title:o,metadata:s,projectId:t,closable:!0}):i(n,{title:o,metadata:s})},[t,n,a,i]);return(0,R.jsx)(`div`,{ref:o,className:r,children:s.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(U,{segment:e,isLast:t===s.length-1,onFileClick:c})]},e.absPath))})}function U({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(null);function s(t){t&&r===null&&V(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(Me,{onOpenChange:s,children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.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,R.jsx)(M,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(ot,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function ot({entry:e,activePath:t,onFileClick:n}){let r=W(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,F.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&V(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(je,{onOpenChange:s,children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(j,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(ot,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}var st={ts:_,tsx:_,js:_,jsx:_,py:_,rs:_,go:_,html:_,css:_,scss:_,json:Je,md:m,txt:m,yaml:oe,yml:oe};function W(e,t){return t?a:st[e.split(`.`).pop()?.toLowerCase()??``]??g}function ct(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 lt(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function ut({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:a,openTab:o}=he(Te(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=me(e=>e.projects.find(e=>e.name===t)?.path??``),c=(0,F.useRef)(null),{prefixParts:l,relativePath:u,isExternal:d}=(0,F.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=s.startsWith(`/`)?s.slice(1):s;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,s]),f=(0,F.useMemo)(()=>ct(i,u.split(`/`).filter(Boolean)),[i,u]);(0,F.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[f]);function p(e,r){let i=fe(e);r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):a(n,{title:i,metadata:{filePath:e,projectName:t}})}return d?(0,R.jsx)(H,{filePath:e,projectName:t,tabId:n,className:r}):(0,R.jsxs)(`div`,{ref:c,className:r,children:[l.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||l.length>0)&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(dt,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function dt({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,F.useMemo)(()=>lt(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,R.jsxs)(Me,{onOpenChange:c,children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.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,R.jsx)(M,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(G,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function G({node:e,projectName:t,activePath:n,onFileClick:r}){let i=W(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,R.jsxs)(je,{onOpenChange:u,children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(j,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):lt(c).map(e=>(0,R.jsx)(G,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function K({active:e,onClick:t,icon:n,label:r,title:i}){return(0,R.jsxs)(`button`,{type:`button`,title:i,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,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function ft({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,inlineBlame:s,onToggleInlineBlame:c,blameStale:d,onRefresh:p,refreshing:m,filePath:ee,projectName:h,className:te}){return(0,R.jsxs)(`div`,{className:te,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(K,{active:t===`edit`,onClick:()=>n(`edit`),icon:f,label:`Edit`}),(0,R.jsx)(K,{active:t===`preview`,onClick:()=>n(`preview`),icon:b,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(K,{active:r===`table`,onClick:()=>i(`table`),icon:ae,label:`Table`}),(0,R.jsx)(K,{active:r===`raw`,onClick:()=>i(`raw`),icon:f,label:`Raw`})]}),(0,R.jsx)(K,{active:a,onClick:o,icon:le,label:`Wrap`}),c&&(0,R.jsx)(K,{active:s===!0,onClick:c,icon:l,label:`Blame`,title:s&&d?`Blame is hidden until this file is saved — the line numbers have moved`:`Inline blame (Alt+B)`}),p&&(0,R.jsxs)(`button`,{type:`button`,onClick:p,disabled:m,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,R.jsx)(u,{className:`size-3 ${m?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),ee&&h&&(0,R.jsx)(K,{active:!1,onClick:()=>ve(h,ee),icon:S,label:`Download`})]})}var pt=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`},{id:`dotenv`,label:`Dotenv`}];function mt({value:e,onChange:t}){return(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(_,{className:`size-3 text-muted-foreground`}),(0,R.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:pt.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function ht({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,o]=(0,F.useState)(t),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(``),d=me(e=>e.activeProject),f=(0,F.useCallback)(()=>{let e=a.trim();if(!e){u(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){u(`Filename cannot contain / or \\`);return}u(``),c(!0)},[a]),p=(0,F.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return s?(0,R.jsx)(Oe,{open:!0,mode:`folder`,root:d?.path,title:`Save "${a.trim()}" to...`,onSelect:p,onCancel:()=>c(!1)}):(0,R.jsx)(k,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(be,{className:`sm:max-w-md`,children:[(0,R.jsx)(ye,{children:(0,R.jsx)(xe,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(Ce,{value:a,onChange:e=>{o(e.target.value),u(``)},onKeyDown:e=>{e.key===`Enter`&&f()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),l&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:l})]}),(0,R.jsxs)(O,{children:[(0,R.jsx)(D,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(D,{onClick:f,children:`Choose Folder...`})]})]})})}var q=typeof window<`u`&&window.isSecureContext,gt=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],J=`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`,_t=`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`,Y=`w-px h-5 bg-border mx-0.5 shrink-0`;function vt({editorRef:e,readOnly:t,wrapOn:n,onToggleWrap:a}){let o=(0,F.useCallback)(()=>e.current,[e]),s=(0,F.useCallback)(e=>{let t=o();if(!t)return;t.focus();let n=t.getSelection();n&&t.executeEdits(`mobile-toolbar`,[{range:n,text:e}])},[o]),[c,l]=(0,F.useState)(!1),u=(0,F.useRef)(null),d=(0,F.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&s(e)}catch{}},[s]),f=(0,F.useCallback)(()=>{l(!0),requestAnimationFrame(()=>u.current?.focus())},[]),m=(0,F.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(l(!1),s(t))},[s]),ee=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[o]),h=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[o]),te=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[o]);return t?null:(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!q&&c&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,R.jsx)(`textarea`,{ref:u,onPaste:m,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,R.jsx)(`button`,{type:`button`,onClick:()=>l(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,R.jsx)(r,{size:14})})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:q?d:f,className:J,title:`Paste`,children:(0,R.jsx)(ne,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:ee,className:J,title:`Undo`,children:(0,R.jsx)(i,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:h,className:J,title:`Redo`,children:(0,R.jsx)(p,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:a,className:`${J} ${n?`text-primary`:``}`,title:n?`Wrapping long lines — tap to scroll sideways instead`:`Wrap long lines`,children:(0,R.jsx)(le,{size:14})}),(0,R.jsx)(`div`,{className:Y}),(0,R.jsx)(`button`,{type:`button`,onClick:te,className:_t,children:`Tab`}),(0,R.jsx)(`div`,{className:Y}),gt.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>s(e),className:_t,children:e},e))]})]})}var yt=(0,F.lazy)(()=>T(()=>import(`./markdown-renderer-Bcaf9_bA.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,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38]))),bt=(0,F.lazy)(()=>T(()=>import(`./editor-language-service-DJmaKVY0.js`).then(e=>({default:e.EditorLanguageService})),__vite__mapDeps([39,2,3,4,10,40,6,1,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]))),xt=(0,F.lazy)(()=>T(()=>import(`./csv-preview-DbwEmG7o.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([41,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,42,43]))),St=(0,F.lazy)(()=>T(()=>import(`./image-preview-CzCc4_Do.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([44,3,2,4,10,45,20]))),Ct=(0,F.lazy)(()=>T(()=>import(`./pdf-preview-CmBI6E7d.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([46,2,3,4,10,20]))),wt=(0,F.lazy)(()=>T(()=>import(`./video-preview-Byj8P_jA.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([47,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,48,49]))),Tt=(0,F.lazy)(()=>T(()=>import(`./audio-preview-DsYvgKqj.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([50,2,3,4,8,10,20,49]))),Et=(0,F.lazy)(()=>T(()=>import(`./docx-preview-CXuk-emm.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([51,2,3,4,10,20])));function Dt(e){return e.split(`.`).pop()?.toLowerCase()??``}function Ot(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`}[Dt(e)]??(Le(e)?`dotenv`:`plaintext`)}var kt=(0,F.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[s,c]=(0,F.useState)(i??null),[l,u]=(0,F.useState)(`utf-8`),[d,f]=(0,F.useState)(!0),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(!1),_=(0,F.useRef)(null),v=(0,F.useRef)(``),b=(0,F.useRef)(null),[x,ne]=(0,F.useState)(null),{tabs:re,updateTab:S}=he(Te(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:ae,toggleWordWrap:oe,mobileWordWrap:se,toggleMobileWordWrap:le}=w(Te(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap,mobileWordWrap:e.mobileWordWrap,toggleMobileWordWrap:e.toggleMobileWordWrap}))),ue=w(e=>e.inlineBlame),me=w(e=>e.toggleInlineBlame),E=w(e=>e.lspEnabled),ve=w(e=>e.setLspEnabled),D=ge(),ye=Ae(),O=D?se:ae,be=D?le:oe,xe=Ne(),k=e?.isUntitled===!0,Se=e?.unsavedContent,[Ce,A]=(0,F.useState)(!1),j=re.find(e=>e.id===t),M=n?Dt(n):``,N=Be.has(M),De=M===`pdf`,P=M===`docx`,Oe=ze.has(M),je=He.has(M),Me=Ve.has(M),Le=M===`md`||M===`mdx`,qe=M===`csv`,Je=e?.language,I=a??Je??Ot(n??``),L=I===`sql`,[Ye,Xe]=(0,F.useState)(`preview`),[Ze,Qe]=(0,F.useState)(`table`),{connections:$e,cachedTables:et,refreshTables:rt,updateConnection:it}=Ee(),z=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[B,at]=(0,F.useState)(()=>{if(!z)return null;let e=localStorage.getItem(z);return e?Number(e):null}),V=(0,F.useRef)(null),H=(0,F.useRef)(null),U=(0,F.useMemo)(()=>$e.find(e=>e.id===B)??null,[$e,B]),ot=i!=null&&(a===`json`||a===`xml`),[st,W]=(0,F.useState)(!1),ct=(0,F.useCallback)(()=>{if(i)if(st)c(i),W(!1);else{let e=i.trimStart();if(a===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),W(!0)}catch{}else if(a===`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-Dz7-DYUg.js","assets/vendor-mermaid-BitiXJlL.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DmZ-Mb-H.js","assets/vendor-markdown-CuWCHIVb.js","assets/markdown-renderer-C140Ijk0.js","assets/index-CEZVxM4G.js","assets/button-B9CTrsEf.js","assets/utils-Bmf_8h7Y.js","assets/createLucideIcon-DoiEKeJ_.js","assets/api-client-C1ZwRL4Y.js","assets/react-Bghu0NUO.js","assets/settings-store-krC6bc79.js","assets/file-store-ojgMXgAw.js","assets/window-store-UC1jJeLM.js","assets/window-pip-registry-yD6esSju.js","assets/panel-store-CboGJAwh.js","assets/format-file-meta-C77h04cZ.js","assets/context-menu-C6pIsf83.js","assets/portal-container-context-BarKmT4S.js","assets/icons-DQjqk0lJ.js","assets/dialog-B84_DJQ8.js","assets/input-C7Q8FxeL.js","assets/mobile-bottom-sheet-C3TniEP-.js","assets/use-visual-viewport-Lp878uzs.js","assets/scroll-area-BzeiOd-B.js","assets/use-is-mobile-TkcwP1Gx.js","assets/file-icons-BXdvggK2.js","assets/project-framework-store-B70Q3dNM.js","assets/git-repo-store-88Z8v-pF.js","assets/project-store-B87hLRSk.js","assets/ws-auth-CEYVQ8NH.js","assets/streaming-store-BYukdB56.js","assets/tab-store-OJa1GPCq.js","assets/apply-theme-CbR31K6I.js","assets/resolve-theme-B_ukrg_8.js","assets/index-BH99TIE0.css","assets/image-gallery-CGvlv8zR.js","assets/run-in-terminal-CdefEe_R.js","assets/editor-language-service-D0DuEOs_.js","assets/use-lsp-CBgID-EU.js","assets/csv-preview-CttjJU1e.js","assets/lib-CD6pOS4u.js","assets/csv-parser-_oDBUkwQ.js","assets/image-preview-CzCc4_Do.js","assets/use-blob-url-CPtCcY3i.js","assets/pdf-preview-CmBI6E7d.js","assets/video-preview-CSDK5j6H.js","assets/can-open-in-ppm-cv5--yHX.js","assets/media-url-yfqHpPz0.js","assets/audio-preview-DsYvgKqj.js","assets/docx-preview-CXuk-emm.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{Br as r,Dr as i,Et as a,Gn as o,Gr as s,It as c,Mr as l,Qn as u,Wr as d,Z as f,Zn as p,_t as m,at as ee,ct as h,dr as te,dt as g,ft as _,j as v,ln as y,lt as b,nt as x,q as ne,r as re,st as S,ur as ie,vr as ae,vt as oe,w as se,yt as ce,zr as le}from"./icons-DQjqk0lJ.js";import{t as ue}from"./createLucideIcon-DoiEKeJ_.js";import{i as de,n as C}from"./api-client-C1ZwRL4Y.js";import{t as w}from"./settings-store-krC6bc79.js";import{q as T}from"./vendor-mermaid-BitiXJlL.js";import{t as fe}from"./utils-Bmf_8h7Y.js";import"./portal-container-context-BarKmT4S.js";import{t as pe}from"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{i as me}from"./project-store-B87hLRSk.js";import"./project-framework-store-B70Q3dNM.js";import{t as he}from"./tab-store-OJa1GPCq.js";import{o as E}from"./file-store-ojgMXgAw.js";import{n as ge,t as _e}from"./use-is-mobile-TkcwP1Gx.js";import"./git-repo-store-88Z8v-pF.js";import{d as ve}from"./format-file-meta-C77h04cZ.js";import{t as D}from"./button-B9CTrsEf.js";import{a as ye,i as O,n as be,o as xe,t as k}from"./dialog-B84_DJQ8.js";import"./file-icons-BXdvggK2.js";import{t as Se}from"./mobile-bottom-sheet-C3TniEP-.js";import"./use-visual-viewport-Lp878uzs.js";import{t as Ce}from"./input-C7Q8FxeL.js";import"./scroll-area-BzeiOd-B.js";import{Ht as A,Jt as j,Rt as we,Vt as M,X as Te,Xt as N,Y as Ee,Yt as P,Z as De,c as Oe,en as ke,i as Ae,qt as je,zt as Me}from"./index-CEZVxM4G.js";import"./data-grid-types-C5bthITf.js";import{t as Ne}from"./use-monaco-theme-gvhJ_jZh.js";import{n as Pe,t as Fe}from"./editor-font-ClTC9gaD.js";import{t as Ie}from"./use-inline-blame-sDMjcz1-.js";import{n as Le,r as Re}from"./monaco-dotenv-language-uB-wok6C.js";import{i as ze,n as Be,r as Ve,t as He}from"./can-open-in-ppm-cv5--yHX.js";import{a as Ue,i as We,o as Ge,r as Ke,t as qe}from"./glide-data-grid-f0hyITiF.js";var Je=ue(`file-braces`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),F=e(t(),1),I=[`completionItems`,`hovers`,`documentSymbols`,`definitions`,`references`,`documentHighlights`,`rename`,`diagnostics`,`documentRangeFormattingEdits`,`signatureHelp`,`onTypeFormattingEdits`,`codeActions`,`inlayHints`];function L(e){return Object.fromEntries(I.map(t=>[t,e]))}var Ye=L(!1),Xe=L(!0),Ze={noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0},Qe=1;function $e(e,t){for(let n of[e,t])n.setModeConfiguration({...Ye}),n.setDiagnosticsOptions({...Ze})}function et(e,t){for(let n of[e,t])n.setCompilerOptions({...n.getCompilerOptions(),jsx:Qe,allowJs:!0,allowNonTsExtensions:!0}),n.setModeConfiguration({...Xe}),n.setDiagnosticsOptions({...Ze})}function tt(e,t,n){e?$e(t,n):et(t,n)}var R=n();function nt({enabled:e,onToggle:t,status:n,diagnostics:r}){let[i,a]=(0,F.useState)(!1),o=ge();if(!e)return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),title:`Language server: off. Turn it on for completions, hover, go to definition, rename and quick fix from a real server. It runs as a process on the host.`,className:`flex items-center gap-1 rounded px-1.5 text-xs text-muted-foreground hover:bg-muted active:scale-95 transition-colors ${o?`min-h-11`:`py-0.5`}`,children:[(0,R.jsx)(s,{className:`size-3 shrink-0`}),(0,R.jsx)(`span`,{children:`LSP off`})]});if(!n)return null;let c=r.filter(e=>e.severity===1).length,l=r.filter(e=>e.severity===2).length,u=n.state===`ready`?n.server.displayName:n.state===`opening`?`Starting…`:n.server?.displayName??`No server`,f=n.state===`unavailable`&&n.reason===`not-installed`;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>a(!0),title:n.state===`ready`?`${n.server.displayName} — rooted at ${n.server.rootPath}`:n.state===`unavailable`?n.message:`Starting the language server`,className:`flex items-center gap-1 rounded px-1.5 hover:bg-muted active:scale-95 transition-colors text-xs ${o?`min-h-11`:`py-0.5`} ${f?`text-amber-500`:`text-muted-foreground`}`,children:[n.state===`opening`?(0,R.jsx)(y,{className:`size-3 animate-spin shrink-0`}):f?(0,R.jsx)(re,{className:`size-3 shrink-0`}):(0,R.jsx)(d,{className:`size-3 shrink-0`}),(0,R.jsx)(`span`,{className:`max-w-24 truncate`,children:u}),c>0&&(0,R.jsx)(`span`,{className:`text-red-500`,children:c}),c===0&&l>0&&(0,R.jsx)(`span`,{className:`text-amber-500`,children:l})]}),i&&(0,R.jsx)(rt,{status:n,errors:c,warnings:l,isMobile:o,onToggle:t,onClose:()=>a(!1)})]})}function rt({status:e,errors:t,warnings:n,isMobile:r,onToggle:i,onClose:a}){let o=(0,R.jsx)(it,{status:e,errors:t,warnings:n,isMobile:r,onToggle:i});return r?(0,R.jsx)(Se,{open:!0,onClose:a,className:`popover-solid max-h-[85dvh] flex flex-col`,children:o}):(0,R.jsx)(k,{open:!0,onOpenChange:e=>!e&&a(),children:(0,R.jsxs)(be,{className:`sm:max-w-lg`,children:[(0,R.jsx)(xe,{children:`Language server`}),o]})})}function it({status:e,errors:t,warnings:n,isMobile:r,onToggle:i}){return(0,R.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto text-sm leading-relaxed`,children:[e.state===`ready`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(z,{label:`Server`,value:e.server.displayName}),(0,R.jsx)(z,{label:`Language`,value:e.languageId}),(0,R.jsx)(z,{label:`Project root`,value:e.server.rootPath,mono:!0}),(0,R.jsx)(z,{label:`Problems`,value:`${t} error${t===1?``:`s`}, ${n} warning${n===1?``:`s`}`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Completions, hover, go to definition (F12), find references (Shift+F12), rename (F2), quick fix (Ctrl+.) and format (Shift+Alt+F) all come from this server.`})]}),e.state===`opening`&&(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`Starting the language server. A cold start reads the project's dependencies, so the first completion in a large project can take a few seconds.`}),e.state===`unavailable`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{children:e.message}),e.server&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Install it, then reopen this file. PPM does not install it for you — that would mean fetching and running a binary because you opened a file.`}),(0,R.jsx)(B,{command:e.server.installHint,isMobile:r})]}),e.reason===`no-language`&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No language server is registered for this file type.`})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-border pt-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-xs font-medium`,children:`Language server`}),(0,R.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`On for this device. Turning it off stops the process.`})]}),(0,R.jsx)(Ee,{checked:!0,onCheckedChange:e=>i(e)})]})]})}function z({label:e,value:t,mono:n}){return(0,R.jsxs)(`div`,{className:`flex gap-2 items-baseline`,children:[(0,R.jsx)(`span`,{className:`text-muted-foreground shrink-0 w-24 text-xs`,children:e}),(0,R.jsx)(`span`,{className:`min-w-0 break-all ${n?`font-mono text-xs`:``}`,children:t})]})}function B({command:e,isMobile:t}){let[n,r]=(0,F.useState)(!1);return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})},className:`w-full flex items-center gap-2 rounded border border-border bg-muted/40 px-3 text-left font-mono text-xs hover:bg-muted active:scale-[0.99] transition ${t?`min-h-11 py-3`:`py-2`}`,children:[(0,R.jsx)(`span`,{className:`flex-1 break-all`,children:e}),n?(0,R.jsx)(se,{className:`size-3.5 shrink-0 text-green-500`}):(0,R.jsx)(x,{className:`size-3.5 shrink-0 opacity-60`})]})}function at(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function V(e){return(await C.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function H({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:i,openTab:a}=he(we(e=>({updateTab:e.updateTab,openTab:e.openTab}))),o=(0,F.useRef)(null),s=(0,F.useMemo)(()=>at(e),[e]);(0,F.useEffect)(()=>{o.current&&(o.current.scrollLeft=o.current.scrollWidth)},[s]);let c=(0,F.useCallback)((e,r)=>{let o=fe(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?a({type:`editor`,title:o,metadata:s,projectId:t,closable:!0}):i(n,{title:o,metadata:s})},[t,n,a,i]);return(0,R.jsx)(`div`,{ref:o,className:r,children:s.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(U,{segment:e,isLast:t===s.length-1,onFileClick:c})]},e.absPath))})}function U({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(null);function s(t){t&&r===null&&V(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(Me,{onOpenChange:s,children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.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,R.jsx)(M,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(ot,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function ot({entry:e,activePath:t,onFileClick:n}){let r=W(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,F.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&V(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(je,{onOpenChange:s,children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(j,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(ot,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}var st={ts:_,tsx:_,js:_,jsx:_,py:_,rs:_,go:_,html:_,css:_,scss:_,json:Je,md:m,txt:m,yaml:oe,yml:oe};function W(e,t){return t?a:st[e.split(`.`).pop()?.toLowerCase()??``]??g}function ct(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 lt(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function ut({filePath:e,projectName:t,tabId:n,className:r}){let i=E(e=>e.tree),{updateTab:a,openTab:o}=he(we(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=me(e=>e.projects.find(e=>e.name===t)?.path??``),c=(0,F.useRef)(null),{prefixParts:l,relativePath:u,isExternal:d}=(0,F.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=s.startsWith(`/`)?s.slice(1):s;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,s]),f=(0,F.useMemo)(()=>ct(i,u.split(`/`).filter(Boolean)),[i,u]);(0,F.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[f]);function p(e,r){let i=fe(e);r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):a(n,{title:i,metadata:{filePath:e,projectName:t}})}return d?(0,R.jsx)(H,{filePath:e,projectName:t,tabId:n,className:r}):(0,R.jsxs)(`div`,{ref:c,className:r,children:[l.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),f.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||l.length>0)&&(0,R.jsx)(v,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(dt,{segment:e,isLast:n===f.length-1,projectName:t,onFileClick:p})]},e.fullPath))]})}function dt({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=E(e=>e.loadChildren),a=E(e=>e.loadedPaths),o=(0,F.useMemo)(()=>lt(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,R.jsxs)(Me,{onOpenChange:c,children:[(0,R.jsx)(N,{asChild:!0,children:(0,R.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,R.jsx)(M,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(G,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function G({node:e,projectName:t,activePath:n,onFileClick:r}){let i=W(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,R.jsxs)(je,{onOpenChange:u,children:[(0,R.jsxs)(P,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(j,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):lt(c).map(e=>(0,R.jsx)(G,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function K({active:e,onClick:t,icon:n,label:r,title:i}){return(0,R.jsxs)(`button`,{type:`button`,title:i,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,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function ft({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,inlineBlame:s,onToggleInlineBlame:c,blameStale:d,onRefresh:p,refreshing:m,filePath:ee,projectName:h,className:te}){return(0,R.jsxs)(`div`,{className:te,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(K,{active:t===`edit`,onClick:()=>n(`edit`),icon:f,label:`Edit`}),(0,R.jsx)(K,{active:t===`preview`,onClick:()=>n(`preview`),icon:b,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(K,{active:r===`table`,onClick:()=>i(`table`),icon:ae,label:`Table`}),(0,R.jsx)(K,{active:r===`raw`,onClick:()=>i(`raw`),icon:f,label:`Raw`})]}),(0,R.jsx)(K,{active:a,onClick:o,icon:le,label:`Wrap`}),c&&(0,R.jsx)(K,{active:s===!0,onClick:c,icon:l,label:`Blame`,title:s&&d?`Blame is hidden until this file is saved — the line numbers have moved`:`Inline blame (Alt+B)`}),p&&(0,R.jsxs)(`button`,{type:`button`,onClick:p,disabled:m,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,R.jsx)(u,{className:`size-3 ${m?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),ee&&h&&(0,R.jsx)(K,{active:!1,onClick:()=>ve(h,ee),icon:S,label:`Download`})]})}var pt=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`},{id:`dotenv`,label:`Dotenv`}];function mt({value:e,onChange:t}){return(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(_,{className:`size-3 text-muted-foreground`}),(0,R.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:pt.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function ht({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,o]=(0,F.useState)(t),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(``),d=me(e=>e.activeProject),f=(0,F.useCallback)(()=>{let e=a.trim();if(!e){u(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){u(`Filename cannot contain / or \\`);return}u(``),c(!0)},[a]),p=(0,F.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return s?(0,R.jsx)(De,{open:!0,mode:`folder`,root:d?.path,title:`Save "${a.trim()}" to...`,onSelect:p,onCancel:()=>c(!1)}):(0,R.jsx)(k,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(be,{className:`sm:max-w-md`,children:[(0,R.jsx)(ye,{children:(0,R.jsx)(xe,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(Ce,{value:a,onChange:e=>{o(e.target.value),u(``)},onKeyDown:e=>{e.key===`Enter`&&f()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),l&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:l})]}),(0,R.jsxs)(O,{children:[(0,R.jsx)(D,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(D,{onClick:f,children:`Choose Folder...`})]})]})})}var q=typeof window<`u`&&window.isSecureContext,gt=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],J=`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`,_t=`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`,Y=`w-px h-5 bg-border mx-0.5 shrink-0`;function vt({editorRef:e,readOnly:t,wrapOn:n,onToggleWrap:a}){let o=(0,F.useCallback)(()=>e.current,[e]),s=(0,F.useCallback)(e=>{let t=o();if(!t)return;t.focus();let n=t.getSelection();n&&t.executeEdits(`mobile-toolbar`,[{range:n,text:e}])},[o]),[c,l]=(0,F.useState)(!1),u=(0,F.useRef)(null),d=(0,F.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&s(e)}catch{}},[s]),f=(0,F.useCallback)(()=>{l(!0),requestAnimationFrame(()=>u.current?.focus())},[]),m=(0,F.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(l(!1),s(t))},[s]),ee=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[o]),h=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[o]),te=(0,F.useCallback)(()=>{let e=o();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[o]);return t?null:(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!q&&c&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,R.jsx)(`textarea`,{ref:u,onPaste:m,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,R.jsx)(`button`,{type:`button`,onClick:()=>l(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,R.jsx)(r,{size:14})})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:q?d:f,className:J,title:`Paste`,children:(0,R.jsx)(ne,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:ee,className:J,title:`Undo`,children:(0,R.jsx)(i,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:h,className:J,title:`Redo`,children:(0,R.jsx)(p,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:a,className:`${J} ${n?`text-primary`:``}`,title:n?`Wrapping long lines — tap to scroll sideways instead`:`Wrap long lines`,children:(0,R.jsx)(le,{size:14})}),(0,R.jsx)(`div`,{className:Y}),(0,R.jsx)(`button`,{type:`button`,onClick:te,className:_t,children:`Tab`}),(0,R.jsx)(`div`,{className:Y}),gt.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>s(e),className:_t,children:e},e))]})]})}var yt=(0,F.lazy)(()=>T(()=>import(`./markdown-renderer-Dz7-DYUg.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,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38]))),bt=(0,F.lazy)(()=>T(()=>import(`./editor-language-service-D0DuEOs_.js`).then(e=>({default:e.EditorLanguageService})),__vite__mapDeps([39,2,3,4,10,40,6,1,7,8,9,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]))),xt=(0,F.lazy)(()=>T(()=>import(`./csv-preview-CttjJU1e.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([41,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,42,43]))),St=(0,F.lazy)(()=>T(()=>import(`./image-preview-CzCc4_Do.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([44,3,2,4,10,45,20]))),Ct=(0,F.lazy)(()=>T(()=>import(`./pdf-preview-CmBI6E7d.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([46,2,3,4,10,20]))),wt=(0,F.lazy)(()=>T(()=>import(`./video-preview-CSDK5j6H.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([47,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,48,49]))),Tt=(0,F.lazy)(()=>T(()=>import(`./audio-preview-DsYvgKqj.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([50,2,3,4,8,10,20,49]))),Et=(0,F.lazy)(()=>T(()=>import(`./docx-preview-CXuk-emm.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([51,2,3,4,10,20])));function Dt(e){return e.split(`.`).pop()?.toLowerCase()??``}function Ot(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`}[Dt(e)]??(Le(e)?`dotenv`:`plaintext`)}var kt=(0,F.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[s,c]=(0,F.useState)(i??null),[l,u]=(0,F.useState)(`utf-8`),[d,f]=(0,F.useState)(!0),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(!1),_=(0,F.useRef)(null),v=(0,F.useRef)(``),b=(0,F.useRef)(null),[x,ne]=(0,F.useState)(null),{tabs:re,updateTab:S}=he(we(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:ae,toggleWordWrap:oe,mobileWordWrap:se,toggleMobileWordWrap:le}=w(we(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap,mobileWordWrap:e.mobileWordWrap,toggleMobileWordWrap:e.toggleMobileWordWrap}))),ue=w(e=>e.inlineBlame),me=w(e=>e.toggleInlineBlame),E=w(e=>e.lspEnabled),ve=w(e=>e.setLspEnabled),D=ge(),ye=Ae(),O=D?se:ae,be=D?le:oe,xe=Ne(),k=e?.isUntitled===!0,Se=e?.unsavedContent,[Ce,A]=(0,F.useState)(!1),j=re.find(e=>e.id===t),M=n?Dt(n):``,N=Be.has(M),Ee=M===`pdf`,P=M===`docx`,De=ze.has(M),je=He.has(M),Me=Ve.has(M),Le=M===`md`||M===`mdx`,qe=M===`csv`,Je=e?.language,I=a??Je??Ot(n??``),L=I===`sql`,[Ye,Xe]=(0,F.useState)(`preview`),[Ze,Qe]=(0,F.useState)(`table`),{connections:$e,cachedTables:et,refreshTables:rt,updateConnection:it}=Te(),z=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[B,at]=(0,F.useState)(()=>{if(!z)return null;let e=localStorage.getItem(z);return e?Number(e):null}),V=(0,F.useRef)(null),H=(0,F.useRef)(null),U=(0,F.useMemo)(()=>$e.find(e=>e.id===B)??null,[$e,B]),ot=i!=null&&(a===`json`||a===`xml`),[st,W]=(0,F.useState)(!1),ct=(0,F.useCallback)(()=>{if(i)if(st)c(i),W(!1);else{let e=i.trimStart();if(a===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),W(!0)}catch{}else if(a===`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
|
-
`)),W(!0)}}},[i,a,st]),lt=(0,F.useCallback)(e=>{at(e),z&&localStorage.setItem(z,String(e)),rt(e).catch(()=>{})},[z,rt]),dt=(0,F.useCallback)(n=>{t&&S(t,{metadata:{...e,language:n}})},[t,e,S]),G=(0,F.useMemo)(()=>{if(!L||!B)return;let e=(et.get(B)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>C.get(`/api/db/connections/${B}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[L,B,et]);(0,F.useEffect)(()=>{if(!(!V.current||!G))return H.current?.dispose(),Ke(),H.current=V.current.languages.registerCompletionItemProvider(`sql`,We(V.current,G)),()=>{H.current?.dispose()}},[G]);let K=he(e=>e.openTab),[pt,q]=(0,F.useState)(null),[gt,J]=(0,F.useState)(null),[_t,Y]=(0,F.useState)(!1),[yt,kt]=(0,F.useState)(``),X=(0,F.useCallback)(async e=>{if(U){Y(!0),J(null),kt(e);try{q(await C.post(`/api/db/connections/${U.id}/query`,{sql:e}))}catch(e){J(e.message),q(null)}finally{Y(!1)}}},[U]),Nt=(0,F.useCallback)(()=>{!U||!yt||K({type:`database`,title:`${U.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:U.id,connectionName:U.name,dbType:U.type,initialSql:yt}})},[U,K,yt]),Pt=(0,F.useCallback)(()=>{if(!b.current||!U)return;let e=b.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[U,X]),Ft=typeof window<`u`&&`ontouchstart`in window,It=(0,F.useRef)(null),[Lt,Rt]=(0,F.useState)(null);(0,F.useEffect)(()=>{if(!Ft)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=It.current;if(!t)return;let n=t.getBoundingClientRect().top;Rt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[Ft]),(0,F.useEffect)(()=>
|
|
5
|
+
`)),W(!0)}}},[i,a,st]),lt=(0,F.useCallback)(e=>{at(e),z&&localStorage.setItem(z,String(e)),rt(e).catch(()=>{})},[z,rt]),dt=(0,F.useCallback)(n=>{t&&S(t,{metadata:{...e,language:n}})},[t,e,S]),G=(0,F.useMemo)(()=>{if(!L||!B)return;let e=(et.get(B)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>C.get(`/api/db/connections/${B}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[L,B,et]);(0,F.useEffect)(()=>{if(!(!V.current||!G))return H.current?.dispose(),Ke(),H.current=V.current.languages.registerCompletionItemProvider(`sql`,We(V.current,G)),()=>{H.current?.dispose()}},[G]);let K=he(e=>e.openTab),[pt,q]=(0,F.useState)(null),[gt,J]=(0,F.useState)(null),[_t,Y]=(0,F.useState)(!1),[yt,kt]=(0,F.useState)(``),X=(0,F.useCallback)(async e=>{if(U){Y(!0),J(null),kt(e);try{q(await C.post(`/api/db/connections/${U.id}/query`,{sql:e}))}catch(e){J(e.message),q(null)}finally{Y(!1)}}},[U]),Nt=(0,F.useCallback)(()=>{!U||!yt||K({type:`database`,title:`${U.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:U.id,connectionName:U.name,dbType:U.type,initialSql:yt}})},[U,K,yt]),Pt=(0,F.useCallback)(()=>{if(!b.current||!U)return;let e=b.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[U,X]),Ft=typeof window<`u`&&`ontouchstart`in window,It=(0,F.useRef)(null),[Lt,Rt]=(0,F.useState)(null);(0,F.useEffect)(()=>{if(!Ft)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=It.current;if(!t)return;let n=t.getBoundingClientRect().top;Rt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[Ft]),(0,F.useEffect)(()=>ke(It.current,()=>b.current?.layout()),[d,p]);let Z=(0,F.useRef)([]),zt=(0,F.useRef)(X);zt.current=X,(0,F.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,F.useEffect)(()=>{Me&&t&&S(t,{type:`sqlite`})},[Me,t,S]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,F.useEffect)(()=>{if(i!=null){f(!1);return}if(k){c(Se??``),v.current=Se??``,f(!1),Se&&g(!0);return}if(!n||!Q&&!r)return;if(N||Ee||P||De||je){f(!1);return}f(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${de(r)}/files/read?path=${encodeURIComponent(n)}`;return C.get(e).then(e=>{c(e.content),e.encoding&&u(e.encoding),v.current=e.content,f(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),f(!1)}),()=>{_.current&&clearTimeout(_.current)}},[n,r,N,Ee,P,Q,k]);let[Bt,Vt]=(0,F.useState)(!1),Ht=(0,F.useCallback)(()=>{if(!n||i!=null||k||!Q&&!r)return;let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${de(r)}/files/read?path=${encodeURIComponent(n)}`;Vt(!0),C.get(e).then(e=>{c(e.content),v.current=e.content,e.encoding&&u(e.encoding),g(!1),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to reload file`)).finally(()=>Vt(!1))},[n,r,Q,i,k]),Ut=(0,F.useRef)(h);Ut.current=h,(0,F.useEffect)(()=>{if(!n||!r||i!=null||k)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||Ut.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${de(r)}/files/read?path=${encodeURIComponent(n)}`;C.get(i).then(e=>{e.content!==v.current&&(c(e.content),v.current=e.content,e.encoding&&u(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,i,k]),(0,F.useEffect)(()=>{if(!j||i!=null)return;let t=k?`Untitled-${e?.untitledNumber??1}`:n?fe(n):`Untitled`,r=h?`${t} \u25CF`:t;j.title!==r&&S(j.id,{title:r})},[h]);let Wt=!k&&i==null&&!!n&&!!r&&!D,Gt=Ie({editor:x?.editor??null,monaco:x?.monaco??null,projectName:r,filePath:Wt?n:void 0,enabled:ue&&Wt}),Kt=!k&&!Q&&i==null&&!!n&&!!r,qt=E&&!ye,Jt=qt&&Kt,[Yt,Xt]=(0,F.useState)({status:null,diagnostics:[]}),Zt=(0,F.useCallback)(e=>Xt(e),[]),Qt=(0,F.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await C.put(`/api/fs/write`,{path:n,content:e}):await C.put(`${de(r)}/files/write`,{path:n,content:e}),g(!1),Gt.refresh(),Jt&&r&&n&&T(()=>import(`./use-lsp-CBgID-EU.js`).then(t=>t.notifyLspSave(r,n,e)),__vite__mapDeps([40,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]))}catch{}},[n,r,Q,Jt,Gt.refresh]);function $t(n){let r=n??``;c(r),v.current=r,g(!0),_.current&&clearTimeout(_.current),k?_.current=setTimeout(()=>{t&&S(t,{metadata:{...e,unsavedContent:v.current}})},2e3):_.current=setTimeout(()=>Qt(v.current),1e3)}let en=(0,F.useCallback)(async(e,n)=>{try{if(_.current&&clearTimeout(_.current),await C.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=pe.getState();n(t),r({type:`editor`,title:fe(e),projectId:null,metadata:{filePath:e},closable:!0})}g(!1),A(!1)}catch{}},[t]),$=e?.lineNumber,tn=e?.endLine,nn=e?.revealAt,rn=(0,F.useCallback)(()=>{let e=b.current;if(!(!e||!$||$<=0)){if(e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),tn&&tn>=$){let t=e.getModel(),n=t?.getLineCount()??$,r=Math.min(tn,n),i=t?.getLineMaxColumn(r)??1;e.setSelection({startLineNumber:$,startColumn:1,endLineNumber:r,endColumn:i})}e.focus()}},[$,tn]);(0,F.useEffect)(()=>{nn!=null&&rn()},[nn,rn]),(0,F.useEffect)(()=>{let e=x?.monaco;e&&tt(qt,e.languages.typescript.typescriptDefaults,e.languages.typescript.javascriptDefaults)},[x,qt]);let an=(0,F.useCallback)((e,t)=>{if(b.current=e,V.current=t,ne({editor:e,monaco:t}),$&&$>0&&setTimeout(()=>rn(),100),k&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>A(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>{let e=w.getState();_e()?e.toggleMobileWordWrap():e.toggleWordWrap()}),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyB,()=>w.getState().toggleInlineBlame()),G&&(H.current?.dispose(),H.current=t.languages.registerCompletionItemProvider(`sql`,We(t,G))),L){e.addAction({id:`run-sql-at-cursor`,label:`Run Statement at Cursor`,keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.Enter],run:e=>{let t=e.getPosition();if(!t)return;let n=Ue(e.getValue(),t.lineNumber);n&&zt.current(n)}}),Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&zt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=(e,n,i=`▷ Run`)=>{let a=n.trim();a&&t.push({range:{startLineNumber:e,startColumn:1,endLineNumber:e,endColumn:1},command:{id:r,title:i,arguments:[a]}})},a=/^(BEGIN|COMMIT|ROLLBACK|END)(;|\s|$)/i,o=-1,s=[];for(let{sql:t,startLine:n}of Ge(e.getValue())){let e=/^BEGIN(;|\s|$)/i.test(t),r=/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(t);o===-1&&e?(o=n,s=[t]):o>-1?(s.push(t),!r&&!a.test(t)&&i(n,t),r&&(i(o,s.join(`
|
|
6
6
|
`),`▷ Run Transaction`),o=-1,s=[])):i(n,t)}return o>-1&&s.length>1&&i(o,s.join(`
|
|
7
|
-
`),`▷ Run Transaction`),{lenses:t,dispose:()=>{}}}});Z.current.push(e);let i=t.languages.registerFoldingRangeProvider(`sql`,{provideFoldingRanges:e=>{if(e!==n)return[];let r=[],i=e.getLineCount(),a=[];for(let n=1;n<=i;n++){let i=e.getLineContent(n).trim();if(/^BEGIN(;|\s|$)/i.test(i))a.push(n);else if(/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(i)&&a.length>0){let e=a.pop();r.push({start:e,end:n,kind:t.languages.FoldingRangeKind.Region})}}return r}});Z.current.push(i)}}},[G,L]);if(!i&&!k&&(!n||!Q&&!r))return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(d)return(0,R.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,R.jsx)(y,{className:`size-5 animate-spin`}),(0,R.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(p)return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p});if(N)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(St,{filePath:n,projectName:r})});if(
|
|
7
|
+
`),`▷ Run Transaction`),{lenses:t,dispose:()=>{}}}});Z.current.push(e);let i=t.languages.registerFoldingRangeProvider(`sql`,{provideFoldingRanges:e=>{if(e!==n)return[];let r=[],i=e.getLineCount(),a=[];for(let n=1;n<=i;n++){let i=e.getLineContent(n).trim();if(/^BEGIN(;|\s|$)/i.test(i))a.push(n);else if(/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(i)&&a.length>0){let e=a.pop();r.push({start:e,end:n,kind:t.languages.FoldingRangeKind.Region})}}return r}});Z.current.push(i)}}},[G,L]);if(!i&&!k&&(!n||!Q&&!r))return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(d)return(0,R.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,R.jsx)(y,{className:`size-5 animate-spin`}),(0,R.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(p)return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p});if(N)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(St,{filePath:n,projectName:r})});if(Ee)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(Ct,{filePath:n,projectName:r})});if(P)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(Et,{filePath:n,projectName:r})});if(De)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(wt,{filePath:n,projectName:r})});if(je)return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(jt,{}),children:(0,R.jsx)(Tt,{filePath:n,projectName:r})});if(l===`base64`)return(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,R.jsx)(ce,{className:`size-10 text-text-subtle`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,R.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]});let on=L?(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(ee,{className:`size-3 text-muted-foreground`}),(0,R.jsxs)(`select`,{value:B??``,onChange:e=>{let t=Number(e.target.value);t&<(t)},className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[140px]`,title:`Select connection for autocomplete`,children:[(0,R.jsx)(`option`,{value:``,children:`Connection…`}),$e.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,R.jsx)(`button`,{type:`button`,onClick:Pt,disabled:!U,className:`p-0.5 rounded text-muted-foreground hover:text-primary disabled:opacity-30 transition-colors`,title:`Run SQL`,children:(0,R.jsx)(o,{className:`size-3.5`})}),U&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>it(U.id,{readonly:U.readonly?0:1}),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] transition-colors ${U.readonly?`text-muted-foreground hover:text-foreground`:`bg-destructive/15 text-destructive`}`,title:U.readonly?`Readonly — click to allow writes`:`WRITE mode — click to enable readonly`,children:U.readonly?(0,R.jsx)(ie,{className:`size-3`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`size-3`}),(0,R.jsx)(`span`,{className:`font-medium`,children:`WRITE`})]})})]}):null;return(0,R.jsxs)(`div`,{ref:It,className:`flex flex-col h-full w-full overflow-hidden`,style:Lt?{height:`${Lt}px`,maxHeight:`${Lt}px`}:void 0,children:[Jt&&x&&n&&r&&(0,R.jsx)(F.Suspense,{fallback:null,children:(0,R.jsx)(bt,{editor:x.editor,monaco:x.monaco,projectName:r,filePath:n,onState:Zt})}),i!=null&&ot&&(0,R.jsx)(`div`,{className:`flex items-center h-7 border-b border-border bg-background shrink-0 px-2 gap-2`,children:(0,R.jsx)(`button`,{type:`button`,onClick:ct,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted transition-colors text-foreground`,children:st?`Raw`:`Beautify`})}),n&&r&&t&&(0,R.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,R.jsx)(ut,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),Kt&&!ye&&(0,R.jsx)(nt,{enabled:qt,onToggle:ve,status:Yt.status,diagnostics:Yt.diagnostics}),(0,R.jsx)(mt,{value:I,onChange:dt}),on,(0,R.jsx)(ft,{ext:M,mdMode:Ye,onMdModeChange:Xe,csvMode:Ze,onCsvModeChange:Qe,wordWrap:O,onToggleWordWrap:be,inlineBlame:ue,onToggleInlineBlame:Wt?me:void 0,blameStale:Gt.stale,onRefresh:Ht,refreshing:Bt,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),i==null&&t&&(k||n&&!r)&&(0,R.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0 px-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1`,children:k?`Untitled-${e?.untitledNumber??1}`:n?fe(n):`Untitled`}),(0,R.jsx)(mt,{value:I,onChange:dt}),on]}),qe&&Ze===`table`?(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(y,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,R.jsx)(xt,{content:s??``,onContentChange:$t,wordWrap:O})}):Le&&Ye===`preview`?(0,R.jsx)(Mt,{content:s??``}):(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:(0,R.jsx)(Oe,{height:`100%`,language:I,beforeMount:Re,value:s??``,onChange:i==null?$t:void 0,onMount:an,theme:xe,options:{fontSize:14,fontFamily:Fe,fontLigatures:Pe,wordWrap:O?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0},readOnly:i!=null,quickSuggestions:{other:!0,comments:!1,strings:!1},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,suggestSelection:`first`,parameterHints:{enabled:!0},inlayHints:{enabled:`on`},"semanticHighlighting.enabled":!0,stickyScroll:{enabled:!Ft},peekWidgetDefaultFocus:`editor`},loading:(0,R.jsx)(y,{className:`size-5 animate-spin text-text-subtle`})},I)}),L&&(pt||gt||_t)&&(0,R.jsx)(At,{result:pt,error:gt,loading:_t,connName:U?.name,onClose:()=>{q(null),J(null),Y(!1)},onOpenInTab:Nt}),Ft&&(0,R.jsx)(vt,{editorRef:b,readOnly:i!=null,wrapOn:O,onToggleWrap:be}),Ce&&(0,R.jsx)(ht,{open:Ce,defaultName:`Untitled-${e?.untitledNumber??1}`,content:v.current,onSave:en,onCancel:()=>A(!1)})]})}),X=()=>{};function At({result:e,error:t,loading:n,connName:i,onClose:a,onOpenInTab:o}){let s=(0,F.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),l=(0,F.useMemo)(()=>(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[e?.columns]),[u,d]=(0,F.useState)(250),f=(0,F.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=u,r=e.currentTarget.ownerDocument,i=e=>d(Math.max(80,n+(t-e.clientY))),a=()=>{r.removeEventListener(`mousemove`,i),r.removeEventListener(`mouseup`,a)};r.addEventListener(`mousemove`,i),r.addEventListener(`mouseup`,a)},[u]);return(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border flex flex-col`,style:{height:u},children:[(0,R.jsx)(`div`,{onMouseDown:f,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,R.jsx)(c,{className:`size-3 text-muted-foreground/50`})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 bg-muted/50 border-b border-border shrink-0`,children:[(0,R.jsx)(ee,{className:`size-3 text-muted-foreground`}),(0,R.jsxs)(`span`,{className:`text-xs font-medium text-foreground truncate flex-1`,children:[i?`${i} · Results`:`Query Results`,e?.executionTimeMs!=null&&(0,R.jsxs)(`span`,{className:`text-muted-foreground ml-1.5 font-normal`,children:[e.executionTimeMs,`ms`]})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:o,title:`Open in DB Viewer tab`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[(0,R.jsx)(h,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Open in Tab`})]}),(0,R.jsx)(`button`,{type:`button`,onClick:a,title:`Close results`,className:`p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,R.jsx)(r,{className:`size-3`})})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:[n&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(y,{className:`size-4 animate-spin text-muted-foreground`})}),t&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-destructive bg-destructive/5`,children:t}),e?.changeType===`modify`&&(0,R.jsxs)(`div`,{className:`px-3 py-2 text-xs text-success`,children:[e.rowsAffected,` row(s) affected`]}),s&&(0,R.jsx)(qe,{columns:s.columns,rows:s.rows,total:s.total,limit:s.limit,schema:l,loading:!1,page:1,onPageChange:X,onCellUpdate:X,readOnly:!0,orderBy:null,orderDir:`ASC`,onToggleSort:X,connectionName:i}),e?.changeType===`select`&&e.rows.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No results`})]})]})}function jt(){return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(y,{className:`size-5 animate-spin text-text-subtle`})})}function Mt({content:e}){return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded m-4`}),children:(0,R.jsx)(yt,{content:e,className:`flex-1 overflow-auto p-4`})})}export{kt as CodeEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import{Br as r,Qn as i,V as a,Xt as o,lt as s,st as c,wr as l}from"./icons-DQjqk0lJ.js";import{t as u}from"./button-B9CTrsEf.js";import{Cn as d,Sn as f,Y as p,wn as m}from"./index-DU68xk06.js";import{getAccounts as h,getActiveAccount as g,getAllAccountUsages as _,patchAccount as v}from"./api-settings-_7Q-ULxp.js";function y(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function b(e){return e>=90?`bg-error`:e>=70?`bg-warning`:`bg-success`}function x(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function S(e){if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):null}function C(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function w(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};if(e.reauthRequired)return{label:`sign in again`,tip:`Anthropic rejected this account's refresh token. Sign in again to restore it.`,color:`text-error`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-warning`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-error`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-success`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-warning`}}function T(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}var E=n();function D({label:e,pct:t,reset:n,resetsAt:r}){let i=S(r);return(0,E.jsxs)(`div`,{className:`space-y-1`,"data-testid":`account-usage-bar`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),n&&(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`text-[10px] text-text-subtle cursor-default`,children:[`↻ `,n]})}),(0,E.jsx)(d,{side:`top`,children:i?`Resets ${i}`:`Resets in`})]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:t!=null&&(0,E.jsx)(`div`,{className:`h-full rounded-full transition-all ${b(t)}`,style:{width:`${Math.min(t,100)}%`}})}),(0,E.jsx)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${t==null?`text-text-subtle`:y(t)}`,children:t==null?`—`:`${t}%`})]})]})}function O({label:e,bucket:t}){return t?(0,E.jsx)(D,{label:e,pct:Math.round(t.utilization*100),reset:x(t),resetsAt:t.resetsAt}):null}function k({hint:e,className:t,children:n}){return(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,className:[`cursor-help text-left`,t].filter(Boolean).join(` `),children:n})}),(0,E.jsx)(d,{side:`top`,className:`max-w-[260px] text-xs leading-relaxed`,children:e})]})}function A({description:e,onRefresh:t,refreshing:n,disabled:r,actions:a}){return(0,E.jsxs)(`section`,{className:`space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e}),(0,E.jsx)(u,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0 cursor-pointer`,onClick:t,disabled:r||n,title:`Refresh`,"aria-label":`Refresh accounts`,children:(0,E.jsx)(i,{className:`size-4 ${n?`animate-spin`:``}`})})]}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:a})]})}function j({message:e,onDismiss:t}){return e?(0,E.jsxs)(`div`,{className:`flex items-start gap-2 text-xs p-2 rounded bg-muted`,role:`status`,children:[(0,E.jsx)(`span`,{className:`flex-1`,children:e}),(0,E.jsx)(`button`,{onClick:t,className:`shrink-0 text-muted-foreground hover:text-foreground cursor-pointer`,"aria-label":`Dismiss message`,children:(0,E.jsx)(r,{className:`size-3.5`})})]}):null}function M({children:e}){return(0,E.jsx)(`div`,{className:`flex gap-2 overflow-x-auto pb-1 -mx-1 px-1 snap-x snap-mandatory scrollbar-thin`,children:e})}function N({active:e,flash:t,dense:n,children:r,...i}){return(0,E.jsx)(`div`,{...i,className:[`rounded-md border transition-colors duration-500`,n?`p-2.5 space-y-1.5`:`p-3 space-y-2`,t?`bg-primary/10 border-primary/40`:``,e?`border-primary/30 bg-primary/5`:`border-border/50`,i.className??``].filter(Boolean).join(` `),children:r})}var P={readOnly:`min-w-[220px]`,withActions:`min-w-[300px]`};function F({entry:e,isActive:t,accountInfo:n,onToggle:r,toggling:u,onDelete:h,onExport:g,onViewProfile:_,flash:v,onSelect:y,unselectableReason:b,selecting:x,planLabel:S,dailyGuard:D,onDailyGuardToggle:A,dailyGuardToggling:j,layout:M=`list`}){let{usage:F}=e,I=F.session||F.weekly||F.weeklyOpus||F.weeklySonnet,L=n?.status??e.accountStatus,R=!!(n&&!n.hasRefreshToken&&n.expiresAt&&n.expiresAt<Math.floor(Date.now()/1e3)),z=w(n),B=!!n?.reauthRequired,V=n?.grantExpiresAt?n.grantExpiresAt*1e3:null,H=!!V&&V-Date.now()<5*864e5,U=!!n&&(z.label===`temp`||z.label===`unknown`||z.label===`expired`&&!R&&!B),W=V?new Date(V).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):null,G=!!(r||h||g||_),K=R?`Token expired — sign in again`:B?`Sign in again to use this account`:b??null,q=M===`list`?``:M===`grid`?`flex flex-col justify-evenly overflow-hidden min-h-0`:`shrink-0 snap-start ${G?P.withActions:P.readOnly}`;return(0,E.jsxs)(N,{active:t,flash:v,dense:M!==`list`,className:[q,R||B?`opacity-50`:``].filter(Boolean).join(` `)||void 0,"data-testid":`account-card`,"data-account-id":e.accountId,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),t&&(0,E.jsx)(k,{className:`text-[10px] text-primary shrink-0 font-medium`,hint:`The next turn will run on this account.`,children:`Active`}),y&&!t&&(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>y(e.accountId),disabled:x,className:[`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors cursor-pointer disabled:cursor-wait`,K?`text-text-subtle hover:text-error hover:bg-error/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`].join(` `),children:x?`Switching…`:`Use`})}),(0,E.jsx)(d,{side:`top`,children:K??`Use this account for this chat`})]}),R&&(0,E.jsx)(k,{className:`text-[10px] text-error shrink-0 font-medium`,hint:`This token has expired and carries no refresh token, so nothing can renew it. Add the account again.`,children:`Expired`}),B&&!R&&(0,E.jsx)(k,{className:`text-[10px] text-error shrink-0 font-medium`,hint:`Anthropic rejected this account's refresh token, so no turn can run on it. Signing in again is the only thing that restores it.`,children:`Sign in again`}),!e.isOAuth&&!R&&(0,E.jsx)(k,{className:`text-[10px] text-text-subtle shrink-0`,hint:`A static API key rather than a sign-in: nothing to expire and nothing to renew.`,children:`API key`}),S&&(0,E.jsx)(k,{className:`text-[10px] uppercase tracking-wide text-text-subtle shrink-0`,hint:`The subscription this account is on. It decides which quota windows the account has — some plans have a weekly limit and no shorter one.`,children:S}),(0,E.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!R&&_&&n?.profileData&&(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>_(n.profileData,e.accountId),"aria-label":`View profile`,children:(0,E.jsx)(s,{className:`size-4`})})}),(0,E.jsx)(d,{side:`top`,children:`View profile`})]}),!R&&g&&e.isOAuth&&(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-primary hover:bg-surface-elevated transition-colors`,onClick:()=>g(e.accountId),"aria-label":`Export this account`,children:(0,E.jsx)(c,{className:`size-4`})})}),(0,E.jsx)(d,{side:`top`,children:`Export this account`})]}),!R&&r&&(0,E.jsx)(p,{checked:L!==`disabled`,onCheckedChange:()=>r(e.accountId,L),disabled:u||L===`cooldown`,"aria-label":L===`disabled`?`Enable account`:`Disable account`,className:`cursor-pointer`}),h&&(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors`,onClick:()=>h(e.accountId,e.accountLabel??e.accountId.slice(0,8)),"aria-label":`Remove account`,children:(0,E.jsx)(l,{className:`size-4`})})}),(0,E.jsx)(d,{side:`top`,children:`Remove account`})]})]})]}),I?(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(O,{label:`5-Hour Session`,bucket:F.session}),(0,E.jsx)(O,{label:`Weekly`,bucket:F.weekly}),(0,E.jsx)(O,{label:`Weekly (Opus)`,bucket:F.weeklyOpus}),(0,E.jsx)(O,{label:`Weekly (Sonnet)`,bucket:F.weeklySonnet})]}):(0,E.jsx)(`p`,{className:`text-xs text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),D&&(0,E.jsxs)(`div`,{className:`flex min-h-12 items-center justify-between gap-3 rounded-md border px-2.5 py-1.5 ${D.enabled&&D.state.blocked?`border-error/40 bg-error/5`:`border-border/50 bg-surface/40`}`,children:[(0,E.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium ${D.enabled&&D.state.blocked?`text-error`:`text-text-secondary`}`,children:[(0,E.jsx)(`span`,{children:`Daily guard`}),(0,E.jsxs)(f,{children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,"aria-label":`About Daily guard`,className:`text-text-subtle hover:text-text-primary cursor-help`,children:(0,E.jsx)(a,{className:`size-3.5`})})}),(0,E.jsx)(d,{side:`top`,className:`max-w-64 text-xs leading-relaxed`,children:`Keeps a weekly-only Codex account on pace to last until its reset. Each day adds one seventh of the weekly quota. When usage reaches that day's cap, PPM pauses new turns until the next day.`})]})]}),(0,E.jsx)(`p`,{className:`text-[10px] tabular-nums ${D.enabled&&D.state.blocked?`text-error`:`text-text-subtle`}`,children:D.enabled&&D.state.blocked?`${Math.round(D.state.used*100)}% used / ${Math.round(D.state.cap*100)}% daily cap. New turns paused.`:`Day ${D.state.day}/7, ${Math.round(D.state.cap*100)}% daily cap`})]}),A&&(0,E.jsx)(p,{checked:D.enabled,onCheckedChange:A,disabled:j,"aria-label":D.enabled?`Disable Daily guard`:`Enable Daily guard`,className:`cursor-pointer shrink-0`})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-text-subtle flex-wrap`,children:[F.lastFetchedAt&&(0,E.jsxs)(k,{className:`inline-flex items-center gap-1`,hint:`Usage last read from Anthropic on ${new Date(F.lastFetchedAt).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}. The bars above are only as current as this.`,children:[(0,E.jsx)(i,{className:`size-3 shrink-0`,"aria-hidden":!0}),T(new Date(F.lastFetchedAt).getTime())]}),V&&!B&&(0,E.jsxs)(k,{className:[`inline-flex items-center gap-1`,H?`text-warning`:``].filter(Boolean).join(` `),hint:`Sign-in stops working on ${W}. Anthropic ends every sign-in on a fixed schedule from the day it was made, whether or not the account gets used — refreshing does not extend it. After that the account fails until you sign in again.`,children:[(0,E.jsx)(o,{className:`size-3 shrink-0`,"aria-hidden":!0}),`sign-in `,C(V)]}),U&&(0,E.jsxs)(k,{className:z.color,hint:z.tip,children:[`© `,z.label]})]})]})}var I=e(t(),1);function L(e){let t=e.usage;return[t.session?.utilization,t.weekly?.utilization,t.weeklyOpus?.utilization,t.weeklySonnet?.utilization].join(`|`)}function R(e=!0){let[t,n]=(0,I.useState)([]),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(null),[s,c]=(0,I.useState)(!0),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(new Set),[p,m]=(0,I.useState)(null),y=(0,I.useRef)([]),b=(0,I.useRef)(void 0),x=(0,I.useCallback)(async()=>{let e=y.current.length>0;e?u(!0):c(!0);let[t,r,a]=await Promise.allSettled([_(),h(),g()]);if(t.status===`fulfilled`){let r=t.value;if(e){let e=new Map(y.current.map(e=>[e.accountId,L(e)])),t=new Set(r.filter(t=>e.get(t.accountId)!==L(t)).map(e=>e.accountId));t.size>0&&(f(t),clearTimeout(b.current),b.current=setTimeout(()=>f(new Set),1500))}y.current=r,n(r)}r.status===`fulfilled`&&i(r.value),a.status===`fulfilled`&&o(a.value?.id??null),c(!1),u(!1)},[]),S=(0,I.useCallback)(async(e,t)=>{m(e);let n=null;try{await v(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){n=e.message}return m(null),await x(),n},[x]);return(0,I.useEffect)(()=>(e&&x(),()=>clearTimeout(b.current)),[e,x]),{usages:t,accounts:r,activeAccountId:a,initialLoading:s,refreshing:l,flashIds:d,reload:x,toggle:S,togglingId:p}}function z(e){return e?.trim()?{free:`ChatGPT Free`,go:`ChatGPT Go`,plus:`ChatGPT Plus`,pro:`ChatGPT Pro`,team:`ChatGPT Team`,business:`ChatGPT Business`,self_serve_business_prolite:`ChatGPT Business`,enterprise:`ChatGPT Enterprise`,edu:`ChatGPT Edu`}[e.trim().toLowerCase()]??e:null}var B=1440*60*1e3,V=7;function H(e,t=Date.now()){if(!e||e.windowHours!==168)return null;let n=new Date(e.resetsAt).getTime();if(!Number.isFinite(n)||n<=t)return null;let r=n-V*B,i=Math.min(V,Math.max(1,Math.ceil((t-r)/B))),a=i/V;return{day:i,cap:a,used:e.utilization,blocked:e.utilization>=a}}export{M as a,j as c,T as d,x as f,F as i,O as l,z as n,N as o,R as r,A as s,H as t,D as u};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import{Br as r,Qn as i,V as a,Xt as o,lt as s,st as c,wr as l}from"./icons-DQjqk0lJ.js";import{t as u}from"./button-B9CTrsEf.js";import{Cn as d,Tn as f,Y as p,wn as m}from"./index-CEZVxM4G.js";import{getAccounts as h,getActiveAccount as g,getAllAccountUsages as _,patchAccount as v}from"./api-settings-_7Q-ULxp.js";function y(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function b(e){return e>=90?`bg-error`:e>=70?`bg-warning`:`bg-success`}function x(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function S(e){if(!e)return null;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):null}function C(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function w(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};if(e.reauthRequired)return{label:`sign in again`,tip:`Anthropic rejected this account's refresh token. Sign in again to restore it.`,color:`text-error`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-warning`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-error`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-success`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-warning`}}function T(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}var E=n();function D({label:e,pct:t,reset:n,resetsAt:r}){let i=S(r);return(0,E.jsxs)(`div`,{className:`space-y-1`,"data-testid":`account-usage-bar`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),n&&(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`text-[10px] text-text-subtle cursor-default`,children:[`↻ `,n]})}),(0,E.jsx)(m,{side:`top`,children:i?`Resets ${i}`:`Resets in`})]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:t!=null&&(0,E.jsx)(`div`,{className:`h-full rounded-full transition-all ${b(t)}`,style:{width:`${Math.min(t,100)}%`}})}),(0,E.jsx)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${t==null?`text-text-subtle`:y(t)}`,children:t==null?`—`:`${t}%`})]})]})}function O({label:e,bucket:t}){return t?(0,E.jsx)(D,{label:e,pct:Math.round(t.utilization*100),reset:x(t),resetsAt:t.resetsAt}):null}function k({hint:e,className:t,children:n}){return(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,className:[`cursor-help text-left`,t].filter(Boolean).join(` `),children:n})}),(0,E.jsx)(m,{side:`top`,className:`max-w-[260px] text-xs leading-relaxed`,children:e})]})}function A({description:e,onRefresh:t,refreshing:n,disabled:r,actions:a}){return(0,E.jsxs)(`section`,{className:`space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e}),(0,E.jsx)(u,{variant:`ghost`,size:`icon`,className:`size-8 shrink-0 cursor-pointer`,onClick:t,disabled:r||n,title:`Refresh`,"aria-label":`Refresh accounts`,children:(0,E.jsx)(i,{className:`size-4 ${n?`animate-spin`:``}`})})]}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:a})]})}function j({message:e,onDismiss:t}){return e?(0,E.jsxs)(`div`,{className:`flex items-start gap-2 text-xs p-2 rounded bg-muted`,role:`status`,children:[(0,E.jsx)(`span`,{className:`flex-1`,children:e}),(0,E.jsx)(`button`,{onClick:t,className:`shrink-0 text-muted-foreground hover:text-foreground cursor-pointer`,"aria-label":`Dismiss message`,children:(0,E.jsx)(r,{className:`size-3.5`})})]}):null}function M({children:e}){return(0,E.jsx)(`div`,{className:`flex gap-2 overflow-x-auto pb-1 -mx-1 px-1 snap-x snap-mandatory scrollbar-thin`,children:e})}function N({active:e,flash:t,dense:n,children:r,...i}){return(0,E.jsx)(`div`,{...i,className:[`rounded-md border transition-colors duration-500`,n?`p-2.5 space-y-1.5`:`p-3 space-y-2`,t?`bg-primary/10 border-primary/40`:``,e?`border-primary/30 bg-primary/5`:`border-border/50`,i.className??``].filter(Boolean).join(` `),children:r})}var P={readOnly:`min-w-[220px]`,withActions:`min-w-[300px]`};function F({entry:e,isActive:t,accountInfo:n,onToggle:r,toggling:u,onDelete:h,onExport:g,onViewProfile:_,flash:v,onSelect:y,unselectableReason:b,selecting:x,planLabel:S,dailyGuard:D,onDailyGuardToggle:A,dailyGuardToggling:j,layout:M=`list`}){let{usage:F}=e,I=F.session||F.weekly||F.weeklyOpus||F.weeklySonnet,L=n?.status??e.accountStatus,R=!!(n&&!n.hasRefreshToken&&n.expiresAt&&n.expiresAt<Math.floor(Date.now()/1e3)),z=w(n),B=!!n?.reauthRequired,V=n?.grantExpiresAt?n.grantExpiresAt*1e3:null,H=!!V&&V-Date.now()<5*864e5,U=!!n&&(z.label===`temp`||z.label===`unknown`||z.label===`expired`&&!R&&!B),W=V?new Date(V).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):null,G=!!(r||h||g||_),K=R?`Token expired — sign in again`:B?`Sign in again to use this account`:b??null,q=M===`list`?``:M===`grid`?`flex flex-col justify-evenly overflow-hidden min-h-0`:`shrink-0 snap-start ${G?P.withActions:P.readOnly}`;return(0,E.jsxs)(N,{active:t,flash:v,dense:M!==`list`,className:[q,R||B?`opacity-50`:``].filter(Boolean).join(` `)||void 0,"data-testid":`account-card`,"data-account-id":e.accountId,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`span`,{className:`text-sm font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),t&&(0,E.jsx)(k,{className:`text-[10px] text-primary shrink-0 font-medium`,hint:`The next turn will run on this account.`,children:`Active`}),y&&!t&&(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,onClick:()=>y(e.accountId),disabled:x,className:[`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors cursor-pointer disabled:cursor-wait`,K?`text-text-subtle hover:text-error hover:bg-error/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`].join(` `),children:x?`Switching…`:`Use`})}),(0,E.jsx)(m,{side:`top`,children:K??`Use this account for this chat`})]}),R&&(0,E.jsx)(k,{className:`text-[10px] text-error shrink-0 font-medium`,hint:`This token has expired and carries no refresh token, so nothing can renew it. Add the account again.`,children:`Expired`}),B&&!R&&(0,E.jsx)(k,{className:`text-[10px] text-error shrink-0 font-medium`,hint:`Anthropic rejected this account's refresh token, so no turn can run on it. Signing in again is the only thing that restores it.`,children:`Sign in again`}),!e.isOAuth&&!R&&(0,E.jsx)(k,{className:`text-[10px] text-text-subtle shrink-0`,hint:`A static API key rather than a sign-in: nothing to expire and nothing to renew.`,children:`API key`}),S&&(0,E.jsx)(k,{className:`text-[10px] uppercase tracking-wide text-text-subtle shrink-0`,hint:`The subscription this account is on. It decides which quota windows the account has — some plans have a weekly limit and no shorter one.`,children:S}),(0,E.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!R&&_&&n?.profileData&&(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>_(n.profileData,e.accountId),"aria-label":`View profile`,children:(0,E.jsx)(s,{className:`size-4`})})}),(0,E.jsx)(m,{side:`top`,children:`View profile`})]}),!R&&g&&e.isOAuth&&(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-primary hover:bg-surface-elevated transition-colors`,onClick:()=>g(e.accountId),"aria-label":`Export this account`,children:(0,E.jsx)(c,{className:`size-4`})})}),(0,E.jsx)(m,{side:`top`,children:`Export this account`})]}),!R&&r&&(0,E.jsx)(p,{checked:L!==`disabled`,onCheckedChange:()=>r(e.accountId,L),disabled:u||L===`cooldown`,"aria-label":L===`disabled`?`Enable account`:`Disable account`,className:`cursor-pointer`}),h&&(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{className:`p-2 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors`,onClick:()=>h(e.accountId,e.accountLabel??e.accountId.slice(0,8)),"aria-label":`Remove account`,children:(0,E.jsx)(l,{className:`size-4`})})}),(0,E.jsx)(m,{side:`top`,children:`Remove account`})]})]})]}),I?(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(O,{label:`5-Hour Session`,bucket:F.session}),(0,E.jsx)(O,{label:`Weekly`,bucket:F.weekly}),(0,E.jsx)(O,{label:`Weekly (Opus)`,bucket:F.weeklyOpus}),(0,E.jsx)(O,{label:`Weekly (Sonnet)`,bucket:F.weeklySonnet})]}):(0,E.jsx)(`p`,{className:`text-xs text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),D&&(0,E.jsxs)(`div`,{className:`flex min-h-12 items-center justify-between gap-3 rounded-md border px-2.5 py-1.5 ${D.enabled&&D.state.blocked?`border-error/40 bg-error/5`:`border-border/50 bg-surface/40`}`,children:[(0,E.jsxs)(`div`,{className:`min-w-0 space-y-0.5`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium ${D.enabled&&D.state.blocked?`text-error`:`text-text-secondary`}`,children:[(0,E.jsx)(`span`,{children:`Daily guard`}),(0,E.jsxs)(d,{children:[(0,E.jsx)(f,{asChild:!0,children:(0,E.jsx)(`button`,{type:`button`,"aria-label":`About Daily guard`,className:`text-text-subtle hover:text-text-primary cursor-help`,children:(0,E.jsx)(a,{className:`size-3.5`})})}),(0,E.jsx)(m,{side:`top`,className:`max-w-64 text-xs leading-relaxed`,children:`Spreads the weekly quota across five weekdays, adding 20% per weekday. Weekend slots keep the previous cap; unused allowance carries forward. Daily slots start at the reset time and use UTC weekdays.`})]})]}),(0,E.jsx)(`p`,{className:`text-[10px] tabular-nums ${D.enabled&&D.state.blocked?`text-error`:`text-text-subtle`}`,children:D.enabled&&D.state.blocked?`${Math.round(D.state.used*100)}% used / ${Math.round(D.state.cap*100)}% daily cap. New turns paused.`:`Weekday ${D.state.day}/5, ${Math.round(D.state.cap*100)}% daily cap`})]}),A&&(0,E.jsx)(p,{checked:D.enabled,onCheckedChange:A,disabled:j,"aria-label":D.enabled?`Disable Daily guard`:`Enable Daily guard`,className:`cursor-pointer shrink-0`})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-text-subtle flex-wrap`,children:[F.lastFetchedAt&&(0,E.jsxs)(k,{className:`inline-flex items-center gap-1`,hint:`Usage last read from Anthropic on ${new Date(F.lastFetchedAt).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}. The bars above are only as current as this.`,children:[(0,E.jsx)(i,{className:`size-3 shrink-0`,"aria-hidden":!0}),T(new Date(F.lastFetchedAt).getTime())]}),V&&!B&&(0,E.jsxs)(k,{className:[`inline-flex items-center gap-1`,H?`text-warning`:``].filter(Boolean).join(` `),hint:`Sign-in stops working on ${W}. Anthropic ends every sign-in on a fixed schedule from the day it was made, whether or not the account gets used — refreshing does not extend it. After that the account fails until you sign in again.`,children:[(0,E.jsx)(o,{className:`size-3 shrink-0`,"aria-hidden":!0}),`sign-in `,C(V)]}),U&&(0,E.jsxs)(k,{className:z.color,hint:z.tip,children:[`© `,z.label]})]})]})}var I=e(t(),1);function L(e){let t=e.usage;return[t.session?.utilization,t.weekly?.utilization,t.weeklyOpus?.utilization,t.weeklySonnet?.utilization].join(`|`)}function R(e=!0){let[t,n]=(0,I.useState)([]),[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(null),[s,c]=(0,I.useState)(!0),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(new Set),[p,m]=(0,I.useState)(null),y=(0,I.useRef)([]),b=(0,I.useRef)(void 0),x=(0,I.useCallback)(async()=>{let e=y.current.length>0;e?u(!0):c(!0);let[t,r,a]=await Promise.allSettled([_(),h(),g()]);if(t.status===`fulfilled`){let r=t.value;if(e){let e=new Map(y.current.map(e=>[e.accountId,L(e)])),t=new Set(r.filter(t=>e.get(t.accountId)!==L(t)).map(e=>e.accountId));t.size>0&&(f(t),clearTimeout(b.current),b.current=setTimeout(()=>f(new Set),1500))}y.current=r,n(r)}r.status===`fulfilled`&&i(r.value),a.status===`fulfilled`&&o(a.value?.id??null),c(!1),u(!1)},[]),S=(0,I.useCallback)(async(e,t)=>{m(e);let n=null;try{await v(e,{status:t===`disabled`?`active`:`disabled`})}catch(e){n=e.message}return m(null),await x(),n},[x]);return(0,I.useEffect)(()=>(e&&x(),()=>clearTimeout(b.current)),[e,x]),{usages:t,accounts:r,activeAccountId:a,initialLoading:s,refreshing:l,flashIds:d,reload:x,toggle:S,togglingId:p}}function z(e){return e?.trim()?{free:`ChatGPT Free`,go:`ChatGPT Go`,plus:`ChatGPT Plus`,pro:`ChatGPT Pro`,team:`ChatGPT Team`,business:`ChatGPT Business`,self_serve_business_prolite:`ChatGPT Business`,enterprise:`ChatGPT Enterprise`,edu:`ChatGPT Edu`}[e.trim().toLowerCase()]??e:null}var B=1440*60*1e3,V=7,H=5;function U(e,t=Date.now()){if(!e||e.windowHours!==168)return null;let n=new Date(e.resetsAt).getTime();if(!Number.isFinite(t)||!Number.isFinite(n)||n<=t)return null;let r=n-V*B;if(t<r)return null;let i=Math.min(V-1,Math.floor((t-r)/B)),a=0;for(let e=0;e<=i;e++){let t=new Date(r+e*B).getUTCDay();t!==0&&t!==6&&a++}let o=a/H;return{day:a,cap:o,used:e.utilization,blocked:e.utilization>=o}}export{M as a,j as c,T as d,x as f,F as i,O as l,z as n,N as o,R as r,A as s,U as t,D as u};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{ln as r}from"./icons-DQjqk0lJ.js";import{i,n as a}from"./api-client-C1ZwRL4Y.js";import{t as o}from"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import{n as s}from"./use-is-mobile-TkcwP1Gx.js";import{
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{ln as r}from"./icons-DQjqk0lJ.js";import{i,n as a}from"./api-client-C1ZwRL4Y.js";import{t as o}from"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import{n as s}from"./use-is-mobile-TkcwP1Gx.js";import{Rt as c,c as l,en as u}from"./index-CEZVxM4G.js";import{t as d}from"./use-monaco-theme-gvhJ_jZh.js";import"./editor-font-ClTC9gaD.js";import{n as f,r as p}from"./monaco-dotenv-language-uB-wok6C.js";var m=e(t(),1),h=n();function g(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()??``]??(f(e)?`dotenv`:`plaintext`)}function _(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
|
-
`),currentLabel:o,incomingLabel:u})}r++}return n}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,[f,v]=(0,m.useState)(null),[b,x]=(0,m.useState)(!0),[S,C]=(0,m.useState)(null),[w,T]=(0,m.useState)(0),E=(0,m.useRef)(null),D=(0,m.useRef)(null),O=(0,m.useRef)([]),k=(0,m.useRef)(null),{wordWrap:A,mobileWordWrap:j}=o(
|
|
4
|
+
`),currentLabel:o,incomingLabel:u})}r++}return n}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,[f,v]=(0,m.useState)(null),[b,x]=(0,m.useState)(!0),[S,C]=(0,m.useState)(null),[w,T]=(0,m.useState)(0),E=(0,m.useRef)(null),D=(0,m.useRef)(null),O=(0,m.useRef)([]),k=(0,m.useRef)(null),{wordWrap:A,mobileWordWrap:j}=o(c(e=>({wordWrap:e.wordWrap,mobileWordWrap:e.mobileWordWrap}))),M=s()?j:A,N=d(),P=(0,m.useRef)(null),[F,I]=(0,m.useState)();(0,m.useEffect)(()=>{let e=P.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&I(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[]),(0,m.useEffect)(()=>u(P.current,()=>E.current?.layout()),[b,S]),(0,m.useEffect)(()=>{!t||!n||(x(!0),a.get(`${i(n)}/files/read?path=${encodeURIComponent(t)}`).then(e=>{v(e.content),x(!1)}).catch(e=>{C(e.message||`Failed to load file`),x(!1)}))},[t,n]);let L=(0,m.useCallback)(()=>{let e=E.current,t=D.current;if(!e||!t)return;let n=_(e.getModel()?.getValue()||``);T(n.length);for(let t of O.current)e.removeContentWidget(t);if(O.current=[],k.current&&k.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`}});k.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 (${y(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`);R(r.id,n)});let a={getId:()=>n,getDomNode:()=>i,getPosition:()=>({position:{lineNumber:r.startLine,column:1},preference:[t.editor.ContentWidgetPositionPreference.ABOVE]})};e.addContentWidget(a),O.current.push(a)}},[]),R=(0,m.useCallback)((e,t)=>{let n=E.current,r=D.current;if(!n||!r)return;let i=n.getModel();if(!i)return;let a=_(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+`
|
|
5
5
|
`+a.incomingContent;break}let s=new r.Range(a.startLine,1,a.endLine+1,1);i.pushEditOperations([],[{range:s,text:o+`
|
|
6
6
|
`}],()=>null),z(i.getValue()),setTimeout(()=>L(),50)},[L]),z=(0,m.useCallback)(async e=>{if(!(!t||!n))try{await a.put(`${i(n)}/files/write`,{path:t,content:e})}catch(e){console.error(`[conflict-editor] save failed:`,e)}},[t,n]),B=(e,t)=>{E.current=e,D.current=t;let n=e.getDomNode()?.ownerDocument??document;if(!n.getElementById(`conflict-editor-styles`)){let e=n.createElement(`style`);e.id=`conflict-editor-styles`,e.textContent=`
|
|
7
7
|
.conflict-current-content { background: color-mix(in srgb, var(--color-success) 10%, transparent) !important; }
|
|
@@ -16,4 +16,4 @@ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./v
|
|
|
16
16
|
.conflict-btn-current { color: var(--color-success); background: color-mix(in srgb, var(--color-success) 15%, transparent); }
|
|
17
17
|
.conflict-btn-incoming { color: var(--color-primary); background: color-mix(in srgb, var(--color-primary) 15%, transparent); }
|
|
18
18
|
.conflict-btn-both { color: #a855f7; background: rgba(168, 85, 247, 0.15); }
|
|
19
|
-
`,n.head?.appendChild(e)}L()},V=t?.split(/[\\/]/).pop()??`unknown`,H=g(V);return b?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,h.jsx)(r,{className:`size-6 animate-spin text-primary`})}):S?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:S}):(0,h.jsxs)(`div`,{className:`h-full w-full flex flex-col`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 text-xs border-b border-border bg-muted/50 flex-shrink-0`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:V}),(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}),w>0?(0,h.jsxs)(`span`,{className:`text-destructive font-medium`,children:[w,` conflict`,w===1?``:`s`,` remaining`]}):(0,h.jsx)(`span`,{className:`text-success font-medium`,children:`All conflicts resolved`})]}),(0,h.jsx)(`div`,{ref:P,className:`flex-1 min-h-0`,children:f!==null&&F&&(0,h.jsx)(
|
|
19
|
+
`,n.head?.appendChild(e)}L()},V=t?.split(/[\\/]/).pop()??`unknown`,H=g(V);return b?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,h.jsx)(r,{className:`size-6 animate-spin text-primary`})}):S?(0,h.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive`,children:S}):(0,h.jsxs)(`div`,{className:`h-full w-full flex flex-col`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 text-xs border-b border-border bg-muted/50 flex-shrink-0`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:V}),(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}),w>0?(0,h.jsxs)(`span`,{className:`text-destructive font-medium`,children:[w,` conflict`,w===1?``:`s`,` remaining`]}):(0,h.jsx)(`span`,{className:`text-success font-medium`,children:`All conflicts resolved`})]}),(0,h.jsx)(`div`,{ref:P,className:`flex-1 min-h-0`,children:f!==null&&F&&(0,h.jsx)(l,{height:F,language:H,beforeMount:p,value:f,onMount:B,theme:N,options:{fontSize:14,fontFamily:`'Monaspace Argon', 'Monaspace Argon Var', Consolas, 'Cascadia Mono', Menlo, 'DejaVu Sans Mono', 'Courier New', monospace`,fontLigatures:`'calt', 'liga', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', 'ss09'`,wordWrap:M?`on`:`off`,glyphMargin:!0,readOnly:!1,automaticLayout:!0,scrollBeyondLastLine:!1,minimap:{enabled:!1}}})})]})}function y(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}export{v as ConflictEditor};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{a as r,d as i}from"./icons-DQjqk0lJ.js";import{Lt as a}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{a as r,d as i}from"./icons-DQjqk0lJ.js";import{Lt as a}from"./index-CEZVxM4G.js";import{n as o,t as s}from"./csv-parser-_oDBUkwQ.js";import{i as c,n as l,r as u,t as d}from"./lib-CD6pOS4u.js";var f=e(t(),1),p=n();function m({content:e,onContentChange:t,wordWrap:n}){let m=(0,f.useMemo)(()=>s(e),[e]),[g,_]=(0,f.useState)(()=>m.rows),[v,y]=(0,f.useState)([]),b=(0,f.useRef)(null),x=(0,f.useRef)(!1);(0,f.useEffect)(()=>{if(x.current){x.current=!1;return}_(m.rows)},[m.rows]);let S=m.headers,C=(0,f.useCallback)((e,n,r)=>{_(i=>{let a=i.map((t,n)=>n===e?[...t]:t);return a[e][n]=r,x.current=!0,t(o(S,a)),a})},[S,t]),w=l({data:g,columns:(0,f.useMemo)(()=>S.map((e,t)=>({id:`col-${t}`,header:e||`Column ${t+1}`,accessorFn:e=>e[t]??``,cell:({row:e,getValue:r})=>(0,p.jsx)(h,{value:r(),onSave:n=>C(e.index,t,n),wordWrap:n}),size:150,minSize:80})),[S,C,n]),state:{sorting:v},onSortingChange:y,getCoreRowModel:u(),getSortedRowModel:c(),enableColumnResizing:!0,columnResizeMode:`onChange`}),{rows:T}=w.getRowModel(),E=a({count:T.length,getScrollElement:()=>b.current,estimateSize:()=>32,overscan:20});return S.length===0?(0,p.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`Empty CSV file`}):(0,p.jsx)(`div`,{ref:b,className:`flex-1 overflow-auto`,children:(0,p.jsxs)(`table`,{className:`w-full text-xs font-mono border-collapse`,children:[(0,p.jsx)(`thead`,{className:`sticky top-0 bg-background z-10 border-b border-border block`,children:w.getHeaderGroups().map(e=>(0,p.jsx)(`tr`,{className:`flex w-full`,children:e.headers.map(e=>(0,p.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,p.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,p.jsx)(`span`,{className:`truncate`,children:d(e.column.columnDef.header,e.getContext())}),e.column.getIsSorted()===`asc`&&(0,p.jsx)(i,{className:`size-3 shrink-0`}),e.column.getIsSorted()===`desc`&&(0,p.jsx)(r,{className:`size-3 shrink-0`})]}),(0,p.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,p.jsx)(`tbody`,{style:{height:E.getTotalSize(),position:`relative`,display:`block`},children:E.getVirtualItems().map(e=>{let t=T[e.index];return(0,p.jsx)(`tr`,{"data-index":e.index,ref:e=>E.measureElement(e),style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`,display:`flex`},children:t.getVisibleCells().map(e=>(0,p.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 h({value:e,onSave:t,wordWrap:n}){let[r,i]=(0,f.useState)(!1),[a,o]=(0,f.useState)(e),s=(0,f.useRef)(null),c=(0,f.useCallback)(e=>{e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[]);return(0,f.useEffect)(()=>{r&&s.current&&(s.current.focus(),c(s.current))},[r,c]),r?(0,p.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(`
|
|
2
2
|
`)?48:20},rows:1,value:a,onChange:e=>{o(e.target.value),c(e.target)},onBlur:()=>{i(!1),a!==e&&t(a)},onKeyDown:n=>{n.key===`Enter`&&!n.shiftKey?(n.preventDefault(),i(!1),a!==e&&t(a)):n.key===`Escape`&&(i(!1),o(e))}}):(0,p.jsx)(`span`,{className:`block cursor-text ${n?`whitespace-pre-wrap break-words`:`truncate`}`,onClick:()=>{o(e),i(!0)},children:e||`\xA0`})}export{m as CsvPreview};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{It as r,Qn as i,at as a,dr as o,ln as s,ur as c}from"./icons-DQjqk0lJ.js";import{n as l,s as u}from"./api-client-C1ZwRL4Y.js";import"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{t as d}from"./tab-store-OJa1GPCq.js";import{X as f}from"./index-DU68xk06.js";import"./data-grid-types-C5bthITf.js";import"./use-monaco-theme-BIVYJBIn.js";import{n as p,t as m}from"./glide-data-grid-DnQwYSmQ.js";import{t as h}from"./sql-query-editor-BgRH0cHD.js";var g=e(t(),1);function _(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function v(e,t,n,r){try{let i=sessionStorage.getItem(_(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function y(e,t,n,r,i,a){try{sessionStorage.setItem(_(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function b(e){let t=`/api/db/connections/${e}`,[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(`public`),[o,s]=(0,g.useState)(null),[c,d]=(0,g.useState)([]),[f,p]=(0,g.useState)(!1),[m,h]=(0,g.useState)(null),[_,b]=(0,g.useState)(1),[x,S]=(0,g.useState)(null),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(!1),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(`ASC`),j=(0,g.useRef)(null),M=(0,g.useCallback)(async(r,a,o,c,u)=>{let f=r??n,m=a??i;if(!f)return;j.current=null,p(!0);let g=c===void 0?D:c,v=u??k;try{let n=g?`&orderBy=${encodeURIComponent(g)}&orderDir=${v}`:``,[r,i]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${m}&page=${o??_}&limit=100${n}`),l.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${m}`)]);s(r),d(i),y(e,f,m,o??_,r,i)}catch(e){h(e.message)}finally{p(!1)}},[t,e,n,i,_,D,k]),N=(0,g.useCallback)((t,n=`public`)=>{r(t),a(n),b(1),S(null);let i=v(e,t,n,1);i?(s(i.data),d(i.cols),p(!1),M(t,n,1)):M(t,n,1)},[e,M]),P=(0,g.useCallback)(e=>{b(e),M(void 0,void 0,e)},[M]),F=(0,g.useCallback)(async e=>{j.current={sql:e,mode:`table`},p(!0);try{let n=await l.post(`${t}/query`,{sql:e,source:`filter`});n.changeType===`select`&&s({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){h(e.message)}finally{p(!1)}},[t]),I=(0,g.useCallback)(async e=>{E(!0),w(null);try{let r=await l.post(`${t}/query`,{sql:e});S(r),r.changeType===`modify`?(j.current=null,M(n??void 0,i)):j.current={sql:e,mode:`query`}}catch(e){w(e.message)}finally{E(!1)}},[t,n,i,M]),L=(0,g.useCallback)((e,t)=>{let n=j.current;if(n?.mode===`table`){F(n.sql);return}M(e,t)},[F,M]),R=(0,g.useCallback)((e,t)=>{let n=t.message;h(n),u.error(`${e} failed`,{description:n})},[]),z=(0,g.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),L(s,c)}catch(e){R(`Update cell`,e)}},[t,n,i,L,R]),B=(0,g.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await l.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),L(a,o)}catch(e){R(`Delete row`,e)}},[t,n,i,L,R]),V=(0,g.useCallback)(e=>{let t,n=`ASC`;D===e?k===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),O(t),A(n),b(1),M(void 0,void 0,1,t,n)},[D,k,M]),H=(0,g.useCallback)(()=>{O(null),A(`ASC`),b(1),M(void 0,void 0,1,null,`ASC`)},[M]),U=(0,g.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await l.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),L(a,o)}catch(e){R(`Delete rows`,e)}},[t,n,i,L,R]),W=(0,g.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await l.post(`${t}/row`,{table:r,schema:a,values:e}),L(r,a)}catch(e){throw R(`Insert row`,e),e}},[t,n,i,L,R]),G=(0,g.useCallback)(()=>{let e=j.current;if(e?.mode===`query`){I(e.sql);return}if(e?.mode===`table`){F(e.sql);return}M()},[I,F,M]);return{selectedTable:n,selectedSchema:i,selectTable:N,tableData:o,schema:c,loading:f,error:m,page:_,setPage:P,orderBy:D,orderDir:k,toggleSort:V,clearSort:H,queryResult:x,queryError:C,queryLoading:T,executeQuery:I,updateCell:z,updateCellIn:(0,g.useCallback)(async(e,n,r,i,a,o)=>{try{await l.put(`${t}/cell`,{table:e,schema:n,pkColumn:r,pkValue:i,column:a,value:o}),G()}catch(e){R(`Update cell`,e)}},[t,G,R]),deleteRow:B,bulkDelete:U,insertRow:W,refreshData:M,queryAsTable:F,reload:G}}function x(e,t){let n=e.replace(/--[^\r\n]*/g,` `).replace(/\/\*[\s\S]*?\*\//g,` `).trim().replace(/;\s*$/,``);if(!/^select\s/i.test(n)||/\b(join|union|intersect|except|group\s+by|distinct)\b/i.test(n)||(n.match(/\bfrom\b/gi)??[]).length!==1)return null;let r=/\bfrom\s+(?:"([^"]+)"|(\w+))\s*(?:\.\s*(?:"([^"]+)"|(\w+)))?/i.exec(n);if(!r)return null;let i=r[1]??r[2],a=r[3]??r[4];return a?{schema:i,table:a}:{table:i,schema:t}}var S=n();function C(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 w({metadata:e,tabId:t}){let n=e?.connectionId,u=e?.connectionName,_=e?.tableName,v=e?.schemaName??`public`,y=e?.initialSql,w=e?.currentSql,T=d(e=>e.updateTab),D=(0,g.useRef)(e);D.current=e;let O=(0,g.useCallback)(e=>{t&&T(t,{metadata:{...D.current,currentSql:e}})},[t,T]),k=b(n),{connections:A,updateConnection:j}=f(),M=(0,g.useMemo)(()=>A.find(e=>e.id===n),[A,n]),[N,P]=(0,g.useState)([]),[F,I]=(0,g.useState)(180),L=(0,g.useRef)(null),[R,z]=(0,g.useState)({}),B=(0,g.useMemo)(()=>{if(y&&!k.selectedTable)return y;if(k.selectedTable){let e=`SELECT * FROM "${k.selectedTable}"`,t=Object.entries(R).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),k.orderBy&&(e+=` ORDER BY "${k.orderBy}" ${k.orderDir}`);let n=(k.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[y,k.selectedTable,k.orderBy,k.orderDir,k.page,R]),V=(0,g.useCallback)(e=>{z(e)},[]),H=(0,g.useRef)(void 0),U=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(!k.selectedTable)return;let e=Object.values(R).some(e=>e.trim());if(!(!e&&!U.current))return U.current=e,clearTimeout(H.current),H.current=setTimeout(()=>{e?k.queryAsTable(B):k.refreshData()},500),()=>clearTimeout(H.current)},[R]);let W=(0,g.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=F,r=e=>{let r=e.clientY-t;I(Math.max(80,Math.min(n+r,(L.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[F]);(0,g.useEffect)(()=>{l.get(`/api/db/connections/${n}/tables?cached=1`).then(e=>P(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[n]);let G=(0,g.useMemo)(()=>{if(N.length!==0)return{tables:N,getColumns:async(e,t)=>await l.get(`/api/db/connections/${n}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[n,N]),K=(0,g.useRef)(!1);(0,g.useEffect)(()=>{K.current||(K.current=!0,y?k.executeQuery(y):_&&k.selectTable(_,v))},[_,v,y]);let[q,J]=(0,g.useState)(!!y),[Y,ee]=(0,g.useState)(y??null),te=(0,g.useCallback)(e=>{let t=e.trim();if(k.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${k.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){z(C(t)),k.queryAsTable(t);return}J(!0),ee(t),k.executeQuery(e)},[k.executeQuery,k.queryAsTable,k.selectedTable]),ne=(0,g.useCallback)(e=>{J(!1),k.toggleSort(e)},[k.toggleSort]),re=(0,g.useCallback)(()=>{J(!1),k.clearSort()},[k.clearSort]),ie=(0,g.useCallback)(e=>{J(!1),k.setPage(e)},[k.setPage]),X=(0,g.useMemo)(()=>M&&!M.readonly&&Y?x(Y,k.selectedSchema):null,[M,Y,k.selectedSchema]),ae=(0,g.useCallback)((e,t,n,r)=>{X&&k.updateCellIn(X.table,X.schema,e,t,n,r)},[X,k.updateCellIn]),Z=k.queryResult,Q=q&&!!(Z||k.queryError),$=k.selectedTable&&!Q,oe=!($&&k.tableData)&&!Q&&(k.loading||k.queryLoading);return(0,S.jsx)(`div`,{ref:L,className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(a,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:u??`Database`}),k.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,k.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[k.tableData&&(0,S.jsx)(p,{columns:k.tableData.columns,rows:k.tableData.rows,filename:u?`${u}-${k.selectedTable??`data`}`:k.selectedTable??`data`,exportAllUrl:k.selectedTable?`/api/db/connections/${n}/export?table=${encodeURIComponent(k.selectedTable)}&schema=${k.selectedSchema}`:void 0}),M&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(M.id,{readonly:M.readonly?0:1}),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] transition-colors ${M.readonly?`text-muted-foreground hover:text-foreground`:`bg-destructive/15 text-destructive`}`,title:M.readonly?`Readonly — click to allow writes`:`WRITE mode — click to enable readonly`,children:M.readonly?(0,S.jsx)(c,{className:`size-3`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(o,{className:`size-3`}),(0,S.jsx)(`span`,{className:`font-medium`,children:`WRITE`})]})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>k.reload(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(i,{className:`size-3 ${k.loading||k.queryLoading?`animate-spin`:``}`})})]})]}),(0,S.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:F},children:(0,S.jsx)(h,{onExecute:te,loading:k.queryLoading,defaultValue:B,schemaInfo:G,onSqlChange:O,persistedSql:w})}),(0,S.jsx)(`div`,{onMouseDown:W,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,S.jsx)(r,{className:`size-3 text-muted-foreground/50`})}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[$&&k.tableData&&(0,S.jsx)(m,{columns:k.tableData.columns,rows:k.tableData.rows,total:k.tableData.total,limit:k.tableData.limit,schema:k.schema,loading:k.loading,page:k.page,onPageChange:ie,onCellUpdate:k.updateCell,onRowDelete:k.deleteRow,orderBy:k.orderBy,orderDir:k.orderDir,onToggleSort:ne,onClearSort:re,onBulkDelete:k.bulkDelete,onInsertRow:k.insertRow,connectionId:n,selectedTable:k.selectedTable,selectedSchema:k.selectedSchema,connectionName:u,columnFilters:R,onColumnFilter:V}),Q&&(0,S.jsx)(E,{result:Z,error:k.queryError,loading:k.queryLoading,schema:k.schema,connectionName:u,onCellUpdate:X?ae:void 0}),oe&&(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:(0,S.jsx)(s,{className:`size-4 animate-spin`})})]})]})})}var T=()=>{};function E({result:e,error:t,loading:n,schema:r,connectionName:i,onCellUpdate:a}){let o=(0,g.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),c=(0,g.useMemo)(()=>{let t=e?.columns??[],n=new Set((r??[]).map(e=>e.name));return r?.length&&t.every(e=>n.has(e))?r:t.map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null}))},[r,e?.columns]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-success shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,S.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),o&&(0,S.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,S.jsx)(m,{columns:o.columns,rows:o.rows,total:o.total,limit:o.limit,schema:c,loading:!!n,page:1,onPageChange:T,onCellUpdate:a??T,readOnly:!a,orderBy:null,orderDir:`ASC`,onToggleSort:T,connectionName:i}),e?.executionTimeMs!=null&&(0,S.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,S.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,S.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,S.jsx)(s,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{w as DatabaseViewer};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{It as r,Qn as i,at as a,dr as o,ln as s,ur as c}from"./icons-DQjqk0lJ.js";import{n as l,s as u}from"./api-client-C1ZwRL4Y.js";import"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{t as d}from"./tab-store-OJa1GPCq.js";import{X as f}from"./index-CEZVxM4G.js";import"./data-grid-types-C5bthITf.js";import"./use-monaco-theme-gvhJ_jZh.js";import{n as p,t as m}from"./glide-data-grid-f0hyITiF.js";import{t as h}from"./sql-query-editor-CQB7Yp7U.js";var g=e(t(),1);function _(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function v(e,t,n,r){try{let i=sessionStorage.getItem(_(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function y(e,t,n,r,i,a){try{sessionStorage.setItem(_(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function b(e){let t=`/api/db/connections/${e}`,[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(`public`),[o,s]=(0,g.useState)(null),[c,d]=(0,g.useState)([]),[f,p]=(0,g.useState)(!1),[m,h]=(0,g.useState)(null),[_,b]=(0,g.useState)(1),[x,S]=(0,g.useState)(null),[C,w]=(0,g.useState)(null),[T,E]=(0,g.useState)(!1),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(`ASC`),j=(0,g.useRef)(null),M=(0,g.useCallback)(async(r,a,o,c,u)=>{let f=r??n,m=a??i;if(!f)return;j.current=null,p(!0);let g=c===void 0?D:c,v=u??k;try{let n=g?`&orderBy=${encodeURIComponent(g)}&orderDir=${v}`:``,[r,i]=await Promise.all([l.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${m}&page=${o??_}&limit=100${n}`),l.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${m}`)]);s(r),d(i),y(e,f,m,o??_,r,i)}catch(e){h(e.message)}finally{p(!1)}},[t,e,n,i,_,D,k]),N=(0,g.useCallback)((t,n=`public`)=>{r(t),a(n),b(1),S(null);let i=v(e,t,n,1);i?(s(i.data),d(i.cols),p(!1),M(t,n,1)):M(t,n,1)},[e,M]),P=(0,g.useCallback)(e=>{b(e),M(void 0,void 0,e)},[M]),F=(0,g.useCallback)(async e=>{j.current={sql:e,mode:`table`},p(!0);try{let n=await l.post(`${t}/query`,{sql:e,source:`filter`});n.changeType===`select`&&s({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){h(e.message)}finally{p(!1)}},[t]),I=(0,g.useCallback)(async e=>{E(!0),w(null);try{let r=await l.post(`${t}/query`,{sql:e});S(r),r.changeType===`modify`?(j.current=null,M(n??void 0,i)):j.current={sql:e,mode:`query`}}catch(e){w(e.message)}finally{E(!1)}},[t,n,i,M]),L=(0,g.useCallback)((e,t)=>{let n=j.current;if(n?.mode===`table`){F(n.sql);return}M(e,t)},[F,M]),R=(0,g.useCallback)((e,t)=>{let n=t.message;h(n),u.error(`${e} failed`,{description:n})},[]),z=(0,g.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await l.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),L(s,c)}catch(e){R(`Update cell`,e)}},[t,n,i,L,R]),B=(0,g.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await l.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),L(a,o)}catch(e){R(`Delete row`,e)}},[t,n,i,L,R]),V=(0,g.useCallback)(e=>{let t,n=`ASC`;D===e?k===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),O(t),A(n),b(1),M(void 0,void 0,1,t,n)},[D,k,M]),H=(0,g.useCallback)(()=>{O(null),A(`ASC`),b(1),M(void 0,void 0,1,null,`ASC`)},[M]),U=(0,g.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await l.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),L(a,o)}catch(e){R(`Delete rows`,e)}},[t,n,i,L,R]),W=(0,g.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await l.post(`${t}/row`,{table:r,schema:a,values:e}),L(r,a)}catch(e){throw R(`Insert row`,e),e}},[t,n,i,L,R]),G=(0,g.useCallback)(()=>{let e=j.current;if(e?.mode===`query`){I(e.sql);return}if(e?.mode===`table`){F(e.sql);return}M()},[I,F,M]);return{selectedTable:n,selectedSchema:i,selectTable:N,tableData:o,schema:c,loading:f,error:m,page:_,setPage:P,orderBy:D,orderDir:k,toggleSort:V,clearSort:H,queryResult:x,queryError:C,queryLoading:T,executeQuery:I,updateCell:z,updateCellIn:(0,g.useCallback)(async(e,n,r,i,a,o)=>{try{await l.put(`${t}/cell`,{table:e,schema:n,pkColumn:r,pkValue:i,column:a,value:o}),G()}catch(e){R(`Update cell`,e)}},[t,G,R]),deleteRow:B,bulkDelete:U,insertRow:W,refreshData:M,queryAsTable:F,reload:G}}function x(e,t){let n=e.replace(/--[^\r\n]*/g,` `).replace(/\/\*[\s\S]*?\*\//g,` `).trim().replace(/;\s*$/,``);if(!/^select\s/i.test(n)||/\b(join|union|intersect|except|group\s+by|distinct)\b/i.test(n)||(n.match(/\bfrom\b/gi)??[]).length!==1)return null;let r=/\bfrom\s+(?:"([^"]+)"|(\w+))\s*(?:\.\s*(?:"([^"]+)"|(\w+)))?/i.exec(n);if(!r)return null;let i=r[1]??r[2],a=r[3]??r[4];return a?{schema:i,table:a}:{table:i,schema:t}}var S=n();function C(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 w({metadata:e,tabId:t}){let n=e?.connectionId,u=e?.connectionName,_=e?.tableName,v=e?.schemaName??`public`,y=e?.initialSql,w=e?.currentSql,T=d(e=>e.updateTab),D=(0,g.useRef)(e);D.current=e;let O=(0,g.useCallback)(e=>{t&&T(t,{metadata:{...D.current,currentSql:e}})},[t,T]),k=b(n),{connections:A,updateConnection:j}=f(),M=(0,g.useMemo)(()=>A.find(e=>e.id===n),[A,n]),[N,P]=(0,g.useState)([]),[F,I]=(0,g.useState)(180),L=(0,g.useRef)(null),[R,z]=(0,g.useState)({}),B=(0,g.useMemo)(()=>{if(y&&!k.selectedTable)return y;if(k.selectedTable){let e=`SELECT * FROM "${k.selectedTable}"`,t=Object.entries(R).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),k.orderBy&&(e+=` ORDER BY "${k.orderBy}" ${k.orderDir}`);let n=(k.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[y,k.selectedTable,k.orderBy,k.orderDir,k.page,R]),V=(0,g.useCallback)(e=>{z(e)},[]),H=(0,g.useRef)(void 0),U=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(!k.selectedTable)return;let e=Object.values(R).some(e=>e.trim());if(!(!e&&!U.current))return U.current=e,clearTimeout(H.current),H.current=setTimeout(()=>{e?k.queryAsTable(B):k.refreshData()},500),()=>clearTimeout(H.current)},[R]);let W=(0,g.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=F,r=e=>{let r=e.clientY-t;I(Math.max(80,Math.min(n+r,(L.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[F]);(0,g.useEffect)(()=>{l.get(`/api/db/connections/${n}/tables?cached=1`).then(e=>P(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[n]);let G=(0,g.useMemo)(()=>{if(N.length!==0)return{tables:N,getColumns:async(e,t)=>await l.get(`/api/db/connections/${n}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[n,N]),K=(0,g.useRef)(!1);(0,g.useEffect)(()=>{K.current||(K.current=!0,y?k.executeQuery(y):_&&k.selectTable(_,v))},[_,v,y]);let[q,J]=(0,g.useState)(!!y),[Y,ee]=(0,g.useState)(y??null),te=(0,g.useCallback)(e=>{let t=e.trim();if(k.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${k.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){z(C(t)),k.queryAsTable(t);return}J(!0),ee(t),k.executeQuery(e)},[k.executeQuery,k.queryAsTable,k.selectedTable]),ne=(0,g.useCallback)(e=>{J(!1),k.toggleSort(e)},[k.toggleSort]),re=(0,g.useCallback)(()=>{J(!1),k.clearSort()},[k.clearSort]),ie=(0,g.useCallback)(e=>{J(!1),k.setPage(e)},[k.setPage]),X=(0,g.useMemo)(()=>M&&!M.readonly&&Y?x(Y,k.selectedSchema):null,[M,Y,k.selectedSchema]),ae=(0,g.useCallback)((e,t,n,r)=>{X&&k.updateCellIn(X.table,X.schema,e,t,n,r)},[X,k.updateCellIn]),Z=k.queryResult,Q=q&&!!(Z||k.queryError),$=k.selectedTable&&!Q,oe=!($&&k.tableData)&&!Q&&(k.loading||k.queryLoading);return(0,S.jsx)(`div`,{ref:L,className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(a,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:u??`Database`}),k.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,k.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[k.tableData&&(0,S.jsx)(p,{columns:k.tableData.columns,rows:k.tableData.rows,filename:u?`${u}-${k.selectedTable??`data`}`:k.selectedTable??`data`,exportAllUrl:k.selectedTable?`/api/db/connections/${n}/export?table=${encodeURIComponent(k.selectedTable)}&schema=${k.selectedSchema}`:void 0}),M&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(M.id,{readonly:M.readonly?0:1}),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] transition-colors ${M.readonly?`text-muted-foreground hover:text-foreground`:`bg-destructive/15 text-destructive`}`,title:M.readonly?`Readonly — click to allow writes`:`WRITE mode — click to enable readonly`,children:M.readonly?(0,S.jsx)(c,{className:`size-3`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(o,{className:`size-3`}),(0,S.jsx)(`span`,{className:`font-medium`,children:`WRITE`})]})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>k.reload(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(i,{className:`size-3 ${k.loading||k.queryLoading?`animate-spin`:``}`})})]})]}),(0,S.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:F},children:(0,S.jsx)(h,{onExecute:te,loading:k.queryLoading,defaultValue:B,schemaInfo:G,onSqlChange:O,persistedSql:w})}),(0,S.jsx)(`div`,{onMouseDown:W,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,S.jsx)(r,{className:`size-3 text-muted-foreground/50`})}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[$&&k.tableData&&(0,S.jsx)(m,{columns:k.tableData.columns,rows:k.tableData.rows,total:k.tableData.total,limit:k.tableData.limit,schema:k.schema,loading:k.loading,page:k.page,onPageChange:ie,onCellUpdate:k.updateCell,onRowDelete:k.deleteRow,orderBy:k.orderBy,orderDir:k.orderDir,onToggleSort:ne,onClearSort:re,onBulkDelete:k.bulkDelete,onInsertRow:k.insertRow,connectionId:n,selectedTable:k.selectedTable,selectedSchema:k.selectedSchema,connectionName:u,columnFilters:R,onColumnFilter:V}),Q&&(0,S.jsx)(E,{result:Z,error:k.queryError,loading:k.queryLoading,schema:k.schema,connectionName:u,onCellUpdate:X?ae:void 0}),oe&&(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:(0,S.jsx)(s,{className:`size-4 animate-spin`})})]})]})})}var T=()=>{};function E({result:e,error:t,loading:n,schema:r,connectionName:i,onCellUpdate:a}){let o=(0,g.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),c=(0,g.useMemo)(()=>{let t=e?.columns??[],n=new Set((r??[]).map(e=>e.name));return r?.length&&t.every(e=>n.has(e))?r:t.map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null}))},[r,e?.columns]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-success shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,S.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),o&&(0,S.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,S.jsx)(m,{columns:o.columns,rows:o.rows,total:o.total,limit:o.limit,schema:c,loading:!!n,page:1,onPageChange:T,onCellUpdate:a??T,readOnly:!a,orderBy:null,orderDir:`ASC`,onToggleSort:T,connectionName:i}),e?.executionTimeMs!=null&&(0,S.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,S.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,S.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,S.jsx)(s,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{w as DatabaseViewer};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{Mr as r,ft as i,ln as a,r as o,yt as s,zr as ee}from"./icons-DQjqk0lJ.js";import{i as c,n as l,r as u}from"./api-client-C1ZwRL4Y.js";import{t as d}from"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import"./project-store-B87hLRSk.js";import"./project-framework-store-B70Q3dNM.js";import"./git-repo-store-88Z8v-pF.js";import{t as f}from"./button-B9CTrsEf.js";import{$t as te,Et as ne,Rt as re,l as ie}from"./index-DU68xk06.js";import{t as ae}from"./use-monaco-theme-BIVYJBIn.js";import{n as oe,t as se}from"./editor-font-ClTC9gaD.js";import{t as p}from"./use-inline-blame-vrfFHuaR.js";import{n as m,r as ce}from"./monaco-dotenv-language-uB-wok6C.js";import{n as h,o as g}from"./can-open-in-ppm-cv5--yHX.js";import{r as _}from"./image-preview-geometry-9lgeLYB3.js";var v=e(t(),1),y=n();function b(e){return h.has(g(e))}function x(e){return/^[0-9a-f]{40}$/i.test(e)?e.slice(0,7):e}function S({mode:e,onChange:t}){return(0,y.jsxs)(`select`,{value:e,onChange:e=>t(e.target.value),title:`Show this file as an image or as text`,"aria-label":`Reopen editor with`,className:`h-11 rounded border border-border bg-transparent px-1 text-xs text-foreground outline-none md:h-6`,children:[(0,y.jsx)(`option`,{value:`preview`,children:`Image Preview`}),(0,y.jsx)(`option`,{value:`text`,children:`Text Editor`})]})}function le({filePath:e,mode:t,original:n,modified:r,onOpenAnyway:i}){if(t===`text`||!b(e))return(0,y.jsx)(C,{onOpenAnyway:i});let a=[n,r].filter(e=>e.url!==null);if(a.length<2){let e=a[0];return e?(0,y.jsx)(w,{side:e}):(0,y.jsx)(C,{onOpenAnyway:i})}return(0,y.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col md:flex-row`,children:[(0,y.jsx)(w,{side:a[0]}),(0,y.jsx)(`div`,{className:`shrink-0 border-b border-border md:border-b-0 md:border-r`}),(0,y.jsx)(w,{side:a[1]})]})}function C({onOpenAnyway:e}){return(0,y.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 p-6 text-center`,children:[(0,y.jsx)(o,{className:`size-10 text-warning`}),(0,y.jsx)(`p`,{className:`max-w-md text-sm leading-relaxed text-text-secondary`,children:`The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding.`}),(0,y.jsx)(f,{onClick:e,className:`mt-auto h-11 w-full max-w-xs md:mt-0 md:w-auto md:px-5`,children:`Open Anyway`})]})}function w({side:e}){return(0,y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5`,children:[(0,y.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:e.label}),e.size!==null&&(0,y.jsx)(`span`,{className:`shrink-0 text-xs text-text-subtle`,children:_(e.size)})]}),(0,y.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center overflow-auto bg-surface p-4`,children:(0,y.jsx)(T,{url:e.url})})]})}function T({url:e}){let{blobUrl:t,failed:n}=E(e);return n?(0,y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-text-subtle`,children:[(0,y.jsx)(s,{className:`size-8`}),(0,y.jsx)(`p`,{className:`text-xs`,children:`Failed to load.`})]}):t?(0,y.jsx)(`img`,{src:t,alt:``,className:`max-h-full max-w-full object-contain`}):(0,y.jsx)(a,{className:`size-5 animate-spin text-text-subtle`})}function E(e){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),a=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let t=!1;i(!1);let r=u();return fetch(e,{headers:r?{Authorization:`Bearer ${r}`}:{}}).then(e=>{if(!e.ok)throw Error(String(e.status));return e.blob()}).then(e=>{if(t)return;let r=URL.createObjectURL(e);a.current&&URL.revokeObjectURL(a.current),a.current=r,n(r)}).catch(()=>{t||i(!0)}),()=>{t=!0}},[e]),(0,v.useEffect)(()=>()=>{a.current&&URL.revokeObjectURL(a.current)},[]),{blobUrl:t,failed:r}}function ue(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()??``]??(m(e)?`dotenv`:`plaintext`)}function D({metadata:e}){let t=e?.filePath,n=e?.projectName,o=e?.ref1,s=e?.ref2,u=e?.file1,f=e?.file2,m=e?.original,h=e?.modified,g=m!=null||h!=null,_=!!(u&&f),[C,w]=(0,v.useState)(null),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(`preview`),[j,M]=(0,v.useState)(!1),N=e=>{A(e),e===`preview`&&M(!1)},[P,F]=(0,v.useState)(!g),[I,L]=(0,v.useState)(null),{wordWrap:fe,toggleWordWrap:pe,mobileWordWrap:R,toggleMobileWordWrap:z}=d(re(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap,mobileWordWrap:e.mobileWordWrap,toggleMobileWordWrap:e.toggleMobileWordWrap}))),me=ae(),B=ne(n),V=(0,v.useRef)(null),H=(0,v.useRef)(null),[he,ge]=(0,v.useState)(!1),[U,_e]=(0,v.useState)(null),[W,G]=(0,v.useState)(`modified`),[K,q]=(0,v.useState)();(0,v.useEffect)(()=>{let e=V.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&q(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[P,I]),(0,v.useEffect)(()=>te(V.current,()=>H.current?.layout()),[P,I]),(0,v.useEffect)(()=>{if(g||!n)return;if(F(!0),L(null),O(null),E(null),w(null),u&&f){let e=new URLSearchParams({file1:u,file2:f});l.get(`${c(n)}/files/compare?${e}`).then(e=>{E(e),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to compare files`),F(!1)});return}if(t){let e=B.repoPath(t);if(e==null){F(!1);return}let n=new URLSearchParams({file:e});o&&n.set(`ref`,o),s&&n.set(`ref2`,s),j&&n.set(`text`,`1`),l.get(B.gitUrl(`/file-full-diff?${n}`)).then(e=>{O(e),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to load diff`),F(!1)});return}let e;if(o||s){let t=new URLSearchParams;o&&t.set(`ref1`,o),s&&t.set(`ref2`,s),e=B.gitUrl(`/diff?${t}`)}else e=B.gitUrl(`/diff`);l.get(e).then(e=>{w(e.diff),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to load diff`),F(!1)})},[t,n,o,s,u,f,g,B,j]),(0,v.useEffect)(()=>{M(!1),A(`preview`)},[t,o,s]);let{original:J,modified:Y}=(0,v.useMemo)(()=>g?{original:m??``,modified:h??``}:_&&T?T:D||(C?de(C):{original:``,modified:``}),[C,g,m,h,_,T,D]),ve=(0,v.useMemo)(()=>{let e=t??f??u;return e?ue(e):`plaintext`},[t,u,f]),X=d(e=>e.inlineBlame),ye=d(e=>e.toggleInlineBlame),Z=typeof window<`u`&&window.innerWidth<768,Q=Z?R:fe,be=Z?z:pe,$=!!(n&&t&&D)&&!Z;p({editor:U?.original??null,monaco:U?.monaco??null,projectName:n,filePath:$?t:void 0,rev:o||`HEAD`,enabled:X&&$&&W===`original`,readOnly:!0}),p({editor:U?.modified??null,monaco:U?.monaco??null,projectName:n,filePath:$?t:void 0,rev:s,enabled:X&&$&&W===`modified`,readOnly:!0});let xe=!Z;if((0,v.useEffect)(()=>{let e=H.current;if(!e)return;let t=Q?`on`:`off`;e.updateOptions({diffWordWrap:t}),e.getOriginalEditor().updateOptions({wordWrapOverride2:t}),e.getModifiedEditor().updateOptions({wordWrapOverride2:t})},[Q,he]),!n&&!g)return(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(P)return(0,y.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,y.jsx)(a,{className:`size-5 animate-spin`}),(0,y.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]});if(I)return(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:I});if(D?.binary&&!j&&t&&n){let e=B.repoPath(t),r=t=>e==null?null:B.gitUrl(`/file-blob?file=${encodeURIComponent(e)}&ref=${encodeURIComponent(t)}`);return(0,y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[b(t)&&(0,y.jsx)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:(0,y.jsx)(S,{mode:k,onChange:N})}),(0,y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,y.jsx)(le,{filePath:t,mode:k,original:{url:D.originalSize===null?null:r(o||`HEAD`),label:x(o||`HEAD`),size:D.originalSize},modified:{url:D.modifiedSize===null?null:s?r(s):`${c(n)}/files/raw?path=${encodeURIComponent(t)}`,label:s?x(s):`Working Tree`,size:D.modifiedSize},onOpenAnyway:()=>M(!0)})})]})}return!g&&!_&&!D&&!J&&!Y?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,y.jsx)(i,{className:`size-8`}),(0,y.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,y.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[D?.binary&&t&&b(t)&&(0,y.jsx)(S,{mode:`text`,onChange:N}),$&&(0,y.jsx)(`button`,{type:`button`,onClick:ye,title:`Inline blame (Alt+B) — who last touched the cursor's line. Click a pane to annotate that side.`,className:`flex items-center justify-center rounded hover:bg-muted active:scale-95 transition-colors p-1 ${X?`bg-muted text-foreground`:``}`,children:(0,y.jsx)(r,{className:`size-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:be,title:Q?`Wrapping long lines — tap to scroll sideways instead`:`Toggle word wrap`,className:`flex items-center justify-center rounded hover:bg-muted active:scale-95 transition-colors ${Z?`size-11`:`p-1`} ${Q?`bg-muted text-foreground`:``}`,children:(0,y.jsx)(ee,{className:`size-3.5`})})]}),(0,y.jsx)(`div`,{ref:V,className:`flex-1 overflow-hidden`,children:K&&K>0?(0,y.jsx)(ie,{height:K,language:ve,beforeMount:ce,original:J,modified:Y,theme:me,onMount:(e,t)=>{H.current=e,ge(!0);let n=e.getOriginalEditor(),r=e.getModifiedEditor();_e({monaco:t,original:n,modified:r}),n.onDidFocusEditorText(()=>G(`original`)),r.onDidFocusEditorText(()=>G(`modified`)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyB,()=>d.getState().toggleInlineBlame())},options:{fontSize:Z?11:14,fontFamily:se,fontLigatures:oe,diffWordWrap:Q?`on`:`off`,renderSideBySide:xe,useInlineViewWhenSpaceIsLimited:!1,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,y.jsx)(a,{className:`size-5 animate-spin text-muted-foreground`})}):(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,y.jsx)(a,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function de(e){let t=e.split(`
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{Mr as r,ft as i,ln as a,r as o,yt as s,zr as ee}from"./icons-DQjqk0lJ.js";import{i as c,n as l,r as u}from"./api-client-C1ZwRL4Y.js";import{t as d}from"./settings-store-krC6bc79.js";import"./vendor-mermaid-BitiXJlL.js";import"./project-store-B87hLRSk.js";import"./project-framework-store-B70Q3dNM.js";import"./git-repo-store-88Z8v-pF.js";import{t as f}from"./button-B9CTrsEf.js";import{Et as te,Rt as ne,en as re,l as ie}from"./index-CEZVxM4G.js";import{t as ae}from"./use-monaco-theme-gvhJ_jZh.js";import{n as oe,t as se}from"./editor-font-ClTC9gaD.js";import{t as p}from"./use-inline-blame-sDMjcz1-.js";import{n as m,r as ce}from"./monaco-dotenv-language-uB-wok6C.js";import{n as h,o as g}from"./can-open-in-ppm-cv5--yHX.js";import{r as _}from"./image-preview-geometry-9lgeLYB3.js";var v=e(t(),1),y=n();function b(e){return h.has(g(e))}function x(e){return/^[0-9a-f]{40}$/i.test(e)?e.slice(0,7):e}function S({mode:e,onChange:t}){return(0,y.jsxs)(`select`,{value:e,onChange:e=>t(e.target.value),title:`Show this file as an image or as text`,"aria-label":`Reopen editor with`,className:`h-11 rounded border border-border bg-transparent px-1 text-xs text-foreground outline-none md:h-6`,children:[(0,y.jsx)(`option`,{value:`preview`,children:`Image Preview`}),(0,y.jsx)(`option`,{value:`text`,children:`Text Editor`})]})}function le({filePath:e,mode:t,original:n,modified:r,onOpenAnyway:i}){if(t===`text`||!b(e))return(0,y.jsx)(C,{onOpenAnyway:i});let a=[n,r].filter(e=>e.url!==null);if(a.length<2){let e=a[0];return e?(0,y.jsx)(w,{side:e}):(0,y.jsx)(C,{onOpenAnyway:i})}return(0,y.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col md:flex-row`,children:[(0,y.jsx)(w,{side:a[0]}),(0,y.jsx)(`div`,{className:`shrink-0 border-b border-border md:border-b-0 md:border-r`}),(0,y.jsx)(w,{side:a[1]})]})}function C({onOpenAnyway:e}){return(0,y.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 p-6 text-center`,children:[(0,y.jsx)(o,{className:`size-10 text-warning`}),(0,y.jsx)(`p`,{className:`max-w-md text-sm leading-relaxed text-text-secondary`,children:`The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding.`}),(0,y.jsx)(f,{onClick:e,className:`mt-auto h-11 w-full max-w-xs md:mt-0 md:w-auto md:px-5`,children:`Open Anyway`})]})}function w({side:e}){return(0,y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5`,children:[(0,y.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:e.label}),e.size!==null&&(0,y.jsx)(`span`,{className:`shrink-0 text-xs text-text-subtle`,children:_(e.size)})]}),(0,y.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center overflow-auto bg-surface p-4`,children:(0,y.jsx)(T,{url:e.url})})]})}function T({url:e}){let{blobUrl:t,failed:n}=E(e);return n?(0,y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-text-subtle`,children:[(0,y.jsx)(s,{className:`size-8`}),(0,y.jsx)(`p`,{className:`text-xs`,children:`Failed to load.`})]}):t?(0,y.jsx)(`img`,{src:t,alt:``,className:`max-h-full max-w-full object-contain`}):(0,y.jsx)(a,{className:`size-5 animate-spin text-text-subtle`})}function E(e){let[t,n]=(0,v.useState)(null),[r,i]=(0,v.useState)(!1),a=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let t=!1;i(!1);let r=u();return fetch(e,{headers:r?{Authorization:`Bearer ${r}`}:{}}).then(e=>{if(!e.ok)throw Error(String(e.status));return e.blob()}).then(e=>{if(t)return;let r=URL.createObjectURL(e);a.current&&URL.revokeObjectURL(a.current),a.current=r,n(r)}).catch(()=>{t||i(!0)}),()=>{t=!0}},[e]),(0,v.useEffect)(()=>()=>{a.current&&URL.revokeObjectURL(a.current)},[]),{blobUrl:t,failed:r}}function ue(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()??``]??(m(e)?`dotenv`:`plaintext`)}function D({metadata:e}){let t=e?.filePath,n=e?.projectName,o=e?.ref1,s=e?.ref2,u=e?.file1,f=e?.file2,m=e?.original,h=e?.modified,g=m!=null||h!=null,_=!!(u&&f),[C,w]=(0,v.useState)(null),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(`preview`),[j,M]=(0,v.useState)(!1),N=e=>{A(e),e===`preview`&&M(!1)},[P,F]=(0,v.useState)(!g),[I,L]=(0,v.useState)(null),{wordWrap:fe,toggleWordWrap:pe,mobileWordWrap:R,toggleMobileWordWrap:z}=d(ne(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap,mobileWordWrap:e.mobileWordWrap,toggleMobileWordWrap:e.toggleMobileWordWrap}))),me=ae(),B=te(n),V=(0,v.useRef)(null),H=(0,v.useRef)(null),[he,ge]=(0,v.useState)(!1),[U,_e]=(0,v.useState)(null),[W,G]=(0,v.useState)(`modified`),[K,q]=(0,v.useState)();(0,v.useEffect)(()=>{let e=V.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&q(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[P,I]),(0,v.useEffect)(()=>re(V.current,()=>H.current?.layout()),[P,I]),(0,v.useEffect)(()=>{if(g||!n)return;if(F(!0),L(null),O(null),E(null),w(null),u&&f){let e=new URLSearchParams({file1:u,file2:f});l.get(`${c(n)}/files/compare?${e}`).then(e=>{E(e),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to compare files`),F(!1)});return}if(t){let e=B.repoPath(t);if(e==null){F(!1);return}let n=new URLSearchParams({file:e});o&&n.set(`ref`,o),s&&n.set(`ref2`,s),j&&n.set(`text`,`1`),l.get(B.gitUrl(`/file-full-diff?${n}`)).then(e=>{O(e),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to load diff`),F(!1)});return}let e;if(o||s){let t=new URLSearchParams;o&&t.set(`ref1`,o),s&&t.set(`ref2`,s),e=B.gitUrl(`/diff?${t}`)}else e=B.gitUrl(`/diff`);l.get(e).then(e=>{w(e.diff),F(!1)}).catch(e=>{L(e instanceof Error?e.message:`Failed to load diff`),F(!1)})},[t,n,o,s,u,f,g,B,j]),(0,v.useEffect)(()=>{M(!1),A(`preview`)},[t,o,s]);let{original:J,modified:Y}=(0,v.useMemo)(()=>g?{original:m??``,modified:h??``}:_&&T?T:D||(C?de(C):{original:``,modified:``}),[C,g,m,h,_,T,D]),ve=(0,v.useMemo)(()=>{let e=t??f??u;return e?ue(e):`plaintext`},[t,u,f]),X=d(e=>e.inlineBlame),ye=d(e=>e.toggleInlineBlame),Z=typeof window<`u`&&window.innerWidth<768,Q=Z?R:fe,be=Z?z:pe,$=!!(n&&t&&D)&&!Z;p({editor:U?.original??null,monaco:U?.monaco??null,projectName:n,filePath:$?t:void 0,rev:o||`HEAD`,enabled:X&&$&&W===`original`,readOnly:!0}),p({editor:U?.modified??null,monaco:U?.monaco??null,projectName:n,filePath:$?t:void 0,rev:s,enabled:X&&$&&W===`modified`,readOnly:!0});let xe=!Z;if((0,v.useEffect)(()=>{let e=H.current;if(!e)return;let t=Q?`on`:`off`;e.updateOptions({diffWordWrap:t}),e.getOriginalEditor().updateOptions({wordWrapOverride2:t}),e.getModifiedEditor().updateOptions({wordWrapOverride2:t})},[Q,he]),!n&&!g)return(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(P)return(0,y.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,y.jsx)(a,{className:`size-5 animate-spin`}),(0,y.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]});if(I)return(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:I});if(D?.binary&&!j&&t&&n){let e=B.repoPath(t),r=t=>e==null?null:B.gitUrl(`/file-blob?file=${encodeURIComponent(e)}&ref=${encodeURIComponent(t)}`);return(0,y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[b(t)&&(0,y.jsx)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:(0,y.jsx)(S,{mode:k,onChange:N})}),(0,y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,y.jsx)(le,{filePath:t,mode:k,original:{url:D.originalSize===null?null:r(o||`HEAD`),label:x(o||`HEAD`),size:D.originalSize},modified:{url:D.modifiedSize===null?null:s?r(s):`${c(n)}/files/raw?path=${encodeURIComponent(t)}`,label:s?x(s):`Working Tree`,size:D.modifiedSize},onOpenAnyway:()=>M(!0)})})]})}return!g&&!_&&!D&&!J&&!Y?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,y.jsx)(i,{className:`size-8`}),(0,y.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,y.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[D?.binary&&t&&b(t)&&(0,y.jsx)(S,{mode:`text`,onChange:N}),$&&(0,y.jsx)(`button`,{type:`button`,onClick:ye,title:`Inline blame (Alt+B) — who last touched the cursor's line. Click a pane to annotate that side.`,className:`flex items-center justify-center rounded hover:bg-muted active:scale-95 transition-colors p-1 ${X?`bg-muted text-foreground`:``}`,children:(0,y.jsx)(r,{className:`size-3.5`})}),(0,y.jsx)(`button`,{type:`button`,onClick:be,title:Q?`Wrapping long lines — tap to scroll sideways instead`:`Toggle word wrap`,className:`flex items-center justify-center rounded hover:bg-muted active:scale-95 transition-colors ${Z?`size-11`:`p-1`} ${Q?`bg-muted text-foreground`:``}`,children:(0,y.jsx)(ee,{className:`size-3.5`})})]}),(0,y.jsx)(`div`,{ref:V,className:`flex-1 overflow-hidden`,children:K&&K>0?(0,y.jsx)(ie,{height:K,language:ve,beforeMount:ce,original:J,modified:Y,theme:me,onMount:(e,t)=>{H.current=e,ge(!0);let n=e.getOriginalEditor(),r=e.getModifiedEditor();_e({monaco:t,original:n,modified:r}),n.onDidFocusEditorText(()=>G(`original`)),r.onDidFocusEditorText(()=>G(`modified`)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyB,()=>d.getState().toggleInlineBlame())},options:{fontSize:Z?11:14,fontFamily:se,fontLigatures:oe,diffWordWrap:Q?`on`:`off`,renderSideBySide:xe,useInlineViewWhenSpaceIsLimited:!1,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,y.jsx)(a,{className:`size-5 animate-spin text-muted-foreground`})}):(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,y.jsx)(a,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function de(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{D as DiffViewer};
|
package/dist/web/assets/{editor-language-service-DJmaKVY0.js → editor-language-service-D0DuEOs_.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import"./api-client-C1ZwRL4Y.js";import"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{t as n}from"./tab-store-OJa1GPCq.js";import"./ws-auth-CEYVQ8NH.js";import{i as r,n as i,r as a,t as o,useLsp as s}from"./use-lsp-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import"./api-client-C1ZwRL4Y.js";import"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{t as n}from"./tab-store-OJa1GPCq.js";import"./ws-auth-CEYVQ8NH.js";import{i as r,n as i,r as a,t as o,useLsp as s}from"./use-lsp-CBgID-EU.js";var c=e(t(),1);function l(e,t,n){return t.addAction({id:`ppm.lsp.goToDefinition`,label:`Go to Definition`,keybindings:[e.KeyCode.F12],contextMenuGroupId:`navigation`,contextMenuOrder:1.1,run:async t=>{let s=t.getModel(),c=t.getPosition();if(!s||!c)return;let l=r(s);if(!l)return;let d=null;try{d=await l.connection.request(l.path,`textDocument/definition`,{textDocument:{uri:s.uri.toString()},position:i(c)})}catch{return}let f=(Array.isArray(d)?d[0]:d)??null;if(!f)return;let p=`targetUri`in f?f.targetUri:f.uri,m=`targetUri`in f?f.targetSelectionRange??f.targetRange:f.range;if(!p||!m)return;let h=o(m.start);if(p===s.uri.toString()){t.setPosition(h),t.revealPositionInCenterIfOutsideViewport(h,e.editor.ScrollType.Smooth),t.setSelection({startLineNumber:h.lineNumber,startColumn:h.column,endLineNumber:m.end.line+1,endColumn:m.end.character+1});return}let g=l.connection.statusOf(l.path);if(g?.state!==`ready`||!g.projectPath)return;let _=a(p);if(!_)return;let v=u(g.projectPath,_);v&&n.openFileTab(v,l.connection.projectName,h.lineNumber)}})}function u(e,t){let n=e.replace(/\\/g,`/`).replace(/\/+$/,``),r=t.replace(/\\/g,`/`);return r.startsWith(n+`/`)?r.slice(n.length+1):null}var d={status:null,diagnostics:[]};function f({editor:e,monaco:t,projectName:r,filePath:i,onState:a}){let{status:o,diagnostics:u}=s({editor:e,monaco:t,projectName:r,filePath:i,enabled:!0});(0,c.useEffect)(()=>{let r=l(t,e,{openFileTab:(e,t,r)=>n.getState().openTab({type:`editor`,title:e.split(`/`).pop()||e,projectId:t,metadata:{filePath:e,projectName:t,lineNumber:r},closable:!0})});return()=>r.dispose()},[t,e]);let f=(0,c.useRef)(a);return f.current=a,(0,c.useEffect)(()=>{f.current({status:o,diagnostics:u})},[o,u]),(0,c.useEffect)(()=>()=>f.current(d),[]),null}export{f as EditorLanguageService,f as default};
|