@hienlh/ppm 0.13.6 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/http-api.md +1 -1
- package/dist/web/assets/ai-settings-section-CHgpQ_OP.js +1 -0
- package/dist/web/assets/{api-settings-t7Leca7J.js → api-settings-D0_eiIYv.js} +1 -1
- package/dist/web/assets/architecture-PBZL5I3N-WMbLpD5Y.js +1 -0
- package/dist/web/assets/{audio-preview-DEJiSXcO.js → audio-preview-DQbX8gfL.js} +1 -1
- package/dist/web/assets/{chat-tab-DQBl8oq4.js → chat-tab-BJQT9kie.js} +9 -9
- package/dist/web/assets/code-editor-CeKTvfyz.js +8 -0
- package/dist/web/assets/{conflict-editor-BZ4mdQJX.js → conflict-editor-BKwJLX0D.js} +1 -1
- package/dist/web/assets/{csv-preview-C9qGhDlb.js → csv-preview-D5lmgVEy.js} +1 -1
- package/dist/web/assets/database-viewer-DixWWvjx.js +5 -0
- package/dist/web/assets/diff-viewer-SAtaBwNI.js +4 -0
- package/dist/web/assets/{esm-B3je8j5P.js → esm-nXReYVnB.js} +1 -1
- package/dist/web/assets/{extension-webview-DEOG3sef.js → extension-webview-PiV4bKJ1.js} +1 -1
- package/dist/web/assets/{file-store-BgZggznw.js → file-store-BrbCNyLm.js} +1 -1
- package/dist/web/assets/gitGraph-HDMCJU4V-BdPTuzO3.js +1 -0
- package/dist/web/assets/{image-preview-YNpn3xj7.js → image-preview-CbFFD9BS.js} +1 -1
- package/dist/web/assets/{index-BJ76xcQz.css → index-C1RBJe0a.css} +1 -1
- package/dist/web/assets/index-ZFyltHwi.js +27 -0
- package/dist/web/assets/info-3K5VOQVL-MHX_1JfR.js +1 -0
- package/dist/web/assets/{input-bGJExpJZ.js → input-BMvRUOr7.js} +1 -1
- package/dist/web/assets/keybindings-store-D0C-Pq2o.js +1 -0
- package/dist/web/assets/{markdown-renderer-B7yiCjpQ.js → markdown-renderer-CHWA0KAo.js} +3 -3
- package/dist/web/assets/packet-RMMSAZCW-CreFbf9A.js +1 -0
- package/dist/web/assets/{pdf-preview-D3u3Hr2R.js → pdf-preview-DQMdjqa2.js} +1 -1
- package/dist/web/assets/pie-UPGHQEXC-CnaHXUh8.js +1 -0
- package/dist/web/assets/port-forwarding-tab-9BpNC9_7.js +1 -0
- package/dist/web/assets/{postgres-viewer-Cf4sjXxY.js → postgres-viewer-Bm5T51n6.js} +3 -3
- package/dist/web/assets/radar-KQ55EAFF-UxsdRHvt.js +1 -0
- package/dist/web/assets/{scroll-area-D0EQpAH2.js → scroll-area-BEllam7_.js} +1 -1
- package/dist/web/assets/{settings-store-CdcSAgEZ.js → settings-store-BHBb62gq.js} +2 -2
- package/dist/web/assets/settings-tab-BUstSDLR.js +1 -0
- package/dist/web/assets/sparkles-B0mRBy_j.js +1 -0
- package/dist/web/assets/{sql-query-editor-vpD0I0KG.js → sql-query-editor-CMQpaOjA.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-WAA8mf_X.js → sqlite-viewer-C7rhO4bn.js} +1 -1
- package/dist/web/assets/tab-store-0rGchMXr.js +1 -0
- package/dist/web/assets/terminal-tab-Xtj6RN0d.js +1 -0
- package/dist/web/assets/treemap-KZPCXAKY-CBVPi4NV.js +1 -0
- package/dist/web/assets/{use-blob-url-BgxxT-n_.js → use-blob-url-Hn6n1730.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-dtPsv6sh.js → use-monaco-theme-CP-vyTF8.js} +1 -1
- package/dist/web/assets/{vendor-mermaid-DCxaaPi4.js → vendor-mermaid-CMiurk2b.js} +2 -2
- package/dist/web/assets/{video-preview-CRDjNIVX.js → video-preview-BLI_RruT.js} +1 -1
- package/dist/web/index.html +14 -14
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/server/ws/terminal.ts +4 -0
- package/src/services/terminal.service.ts +4 -1
- package/src/web/components/database/data-grid.tsx +117 -17
- package/src/web/components/editor/code-editor.tsx +36 -3
- package/src/web/components/editor/editor-mobile-toolbar.tsx +144 -0
- package/src/web/components/layout/draggable-tab.tsx +1 -0
- package/src/web/components/terminal/terminal-tab.tsx +19 -8
- package/src/web/hooks/use-terminal.ts +22 -2
- package/src/web/stores/panel-utils.ts +1 -0
- package/dist/web/assets/ai-settings-section-DeW4WN43.js +0 -1
- package/dist/web/assets/architecture-PBZL5I3N-Dy3PgD6O.js +0 -1
- package/dist/web/assets/code-editor-JxVGEgWY.js +0 -8
- package/dist/web/assets/database-viewer-CBfw4hkk.js +0 -2
- package/dist/web/assets/diff-viewer-4hobWs-B.js +0 -4
- package/dist/web/assets/gitGraph-HDMCJU4V-Bu1SIFFq.js +0 -1
- package/dist/web/assets/index-C7gvr4Xo.js +0 -27
- package/dist/web/assets/info-3K5VOQVL-DzfAxmVd.js +0 -1
- package/dist/web/assets/keybindings-store-BhvgfX51.js +0 -1
- package/dist/web/assets/packet-RMMSAZCW-DpzHf4xp.js +0 -1
- package/dist/web/assets/pie-UPGHQEXC-BpzFCKJ8.js +0 -1
- package/dist/web/assets/port-forwarding-tab-CSGpa5Bk.js +0 -1
- package/dist/web/assets/radar-KQ55EAFF-DAxWKxM4.js +0 -1
- package/dist/web/assets/settings-tab-BLlfwRRc.js +0 -1
- package/dist/web/assets/tab-store-Jvy1eZGM.js +0 -1
- package/dist/web/assets/terminal-tab-Bn8wLy9d.js +0 -1
- package/dist/web/assets/treemap-KZPCXAKY-D6dgXbAe.js +0 -1
- /package/dist/web/assets/{api-client-r4nyVy7H.js → api-client-Dvzcc_EO.js} +0 -0
- /package/dist/web/assets/{csv-parser-DxVplKKB.js → csv-parser-DO0dz4x_.js} +0 -0
- /package/dist/web/assets/{dist-BqoEabX7.js → dist-CGvx1c8C.js} +0 -0
- /package/dist/web/assets/{katex-bpagxk3Z.js → katex-BFE6i_OH.js} +0 -0
- /package/dist/web/assets/{lib-BqkcKGFq.js → lib-D_kRA9p6.js} +0 -0
- /package/dist/web/assets/{react-BkWDCPD7.js → react-GqWghJ-L.js} +0 -0
- /package/dist/web/assets/{sql-completion-provider-EzHOQLfo.js → sql-completion-provider-tCzZfqWs.js} +0 -0
- /package/dist/web/assets/{table-DbSviOmw.js → table-Dq575bPF.js} +0 -0
- /package/dist/web/assets/{text-wrap-DzvCTq_i.js → text-wrap-Cn6BNQfq.js} +0 -0
- /package/dist/web/assets/{trash-2-BgDIBl6f.js → trash-2-CJYoLw7Q.js} +0 -0
- /package/dist/web/assets/{utils-ChWX7pZv.js → utils-CTg5uAYR.js} +0 -0
- /package/dist/web/assets/{vendor-xterm-D7SePDJp.js → vendor-xterm-u3AZMvTx.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRef, useEffect, useState, useCallback, memo } from "react";
|
|
2
2
|
import { useTerminal } from "@/hooks/use-terminal";
|
|
3
3
|
import { cn } from "@/lib/utils";
|
|
4
|
-
import { Copy, ClipboardPaste } from "lucide-react";
|
|
4
|
+
import { Copy, ClipboardPaste, RotateCcw } from "lucide-react";
|
|
5
5
|
import "@xterm/xterm/css/xterm.css";
|
|
6
6
|
|
|
7
7
|
interface TerminalTabProps {
|
|
@@ -22,7 +22,7 @@ export const TerminalTab = memo(function TerminalTab({ metadata }: TerminalTabPr
|
|
|
22
22
|
const sessionId = (metadata?.sessionId as string) ?? "new";
|
|
23
23
|
const projectName = metadata?.projectName as string | undefined;
|
|
24
24
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
25
|
-
const { connected, reconnecting, sendData, getSelection } = useTerminal({ sessionId, projectName, containerRef });
|
|
25
|
+
const { connected, reconnecting, exited, sendData, getSelection, restart } = useTerminal({ sessionId, projectName, containerRef });
|
|
26
26
|
const [ctrlMode, setCtrlMode] = useState(false);
|
|
27
27
|
const [viewportHeight, setViewportHeight] = useState<number | null>(null);
|
|
28
28
|
|
|
@@ -97,16 +97,27 @@ export const TerminalTab = memo(function TerminalTab({ metadata }: TerminalTabPr
|
|
|
97
97
|
<span
|
|
98
98
|
className={cn(
|
|
99
99
|
"size-2 rounded-full",
|
|
100
|
-
connected ? "bg-success" : reconnecting ? "bg-warning" : "bg-error",
|
|
100
|
+
exited ? "bg-error" : connected ? "bg-success" : reconnecting ? "bg-warning" : "bg-error",
|
|
101
101
|
)}
|
|
102
102
|
/>
|
|
103
103
|
<span className="text-text-secondary">
|
|
104
|
-
{
|
|
105
|
-
? "
|
|
106
|
-
:
|
|
107
|
-
? "
|
|
108
|
-
:
|
|
104
|
+
{exited
|
|
105
|
+
? "Process exited"
|
|
106
|
+
: connected
|
|
107
|
+
? "Connected"
|
|
108
|
+
: reconnecting
|
|
109
|
+
? "Reconnecting..."
|
|
110
|
+
: "Disconnected"}
|
|
109
111
|
</span>
|
|
112
|
+
{exited && (
|
|
113
|
+
<button
|
|
114
|
+
onClick={restart}
|
|
115
|
+
className="flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-surface-elevated text-text-primary hover:bg-primary hover:text-primary-foreground active:bg-primary active:text-primary-foreground transition-colors"
|
|
116
|
+
>
|
|
117
|
+
<RotateCcw size={10} />
|
|
118
|
+
Restart
|
|
119
|
+
</button>
|
|
120
|
+
)}
|
|
110
121
|
<span className="text-text-subtle ml-auto font-mono">{sessionId}</span>
|
|
111
122
|
</div>
|
|
112
123
|
|
|
@@ -66,8 +66,10 @@ interface UseTerminalOptions {
|
|
|
66
66
|
interface UseTerminalReturn {
|
|
67
67
|
connected: boolean;
|
|
68
68
|
reconnecting: boolean;
|
|
69
|
+
exited: boolean;
|
|
69
70
|
sendData: (data: string) => void;
|
|
70
71
|
getSelection: () => string;
|
|
72
|
+
restart: () => void;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
const RESIZE_PREFIX = "\x01RESIZE:";
|
|
@@ -83,6 +85,7 @@ export function useTerminal(
|
|
|
83
85
|
const reconnectAttempts = useRef(0);
|
|
84
86
|
const [connected, setConnected] = useState(false);
|
|
85
87
|
const [reconnecting, setReconnecting] = useState(false);
|
|
88
|
+
const [exited, setExited] = useState(false);
|
|
86
89
|
const actualSessionId = useRef(sessionId); // Track server-assigned session ID
|
|
87
90
|
|
|
88
91
|
const sendData = useCallback((data: string) => {
|
|
@@ -104,6 +107,20 @@ export function useTerminal(
|
|
|
104
107
|
}
|
|
105
108
|
}, []);
|
|
106
109
|
|
|
110
|
+
const restart = useCallback(() => {
|
|
111
|
+
// Close existing WS, reset to "new" session, reconnect
|
|
112
|
+
if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
|
|
113
|
+
wsRef.current?.close();
|
|
114
|
+
wsRef.current = null;
|
|
115
|
+
actualSessionId.current = "new";
|
|
116
|
+
reconnectAttempts.current = 0;
|
|
117
|
+
setExited(false);
|
|
118
|
+
setConnected(false);
|
|
119
|
+
setReconnecting(false);
|
|
120
|
+
// connectWs will be called after this via setTimeout to allow state to settle
|
|
121
|
+
setTimeout(() => connectWs(), 0);
|
|
122
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
123
|
+
|
|
107
124
|
const connectWs = useCallback(() => {
|
|
108
125
|
const term = termRef.current;
|
|
109
126
|
if (!term) return;
|
|
@@ -130,13 +147,16 @@ export function useTerminal(
|
|
|
130
147
|
if (event.data.startsWith("{")) {
|
|
131
148
|
try {
|
|
132
149
|
const msg = JSON.parse(event.data);
|
|
133
|
-
if (msg.type === "session" || msg.type === "error") {
|
|
150
|
+
if (msg.type === "session" || msg.type === "error" || msg.type === "exited") {
|
|
134
151
|
if (msg.type === "session" && msg.id) {
|
|
135
152
|
actualSessionId.current = msg.id; // Save for reconnect
|
|
136
153
|
}
|
|
137
154
|
if (msg.type === "error") {
|
|
138
155
|
term.write(`\r\n\x1b[31mError: ${msg.message}\x1b[0m\r\n`);
|
|
139
156
|
}
|
|
157
|
+
if (msg.type === "exited") {
|
|
158
|
+
setExited(true);
|
|
159
|
+
}
|
|
140
160
|
return; // Don't write raw JSON to terminal
|
|
141
161
|
}
|
|
142
162
|
} catch {
|
|
@@ -234,5 +254,5 @@ export function useTerminal(
|
|
|
234
254
|
};
|
|
235
255
|
}, [sessionId]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
236
256
|
|
|
237
|
-
return { connected, reconnecting, sendData, getSelection };
|
|
257
|
+
return { connected, reconnecting, exited, sendData, getSelection, restart };
|
|
238
258
|
}
|
|
@@ -89,6 +89,7 @@ export function getNextUntitledNumber(panels: Record<string, Panel>): number {
|
|
|
89
89
|
export function deriveTabId(type: TabType, metadata?: Record<string, unknown>): string {
|
|
90
90
|
switch (type) {
|
|
91
91
|
case "editor":
|
|
92
|
+
if (metadata?.viewerKey) return `editor:viewer:${metadata.viewerKey}`;
|
|
92
93
|
if (metadata?.isUntitled) return `editor:untitled-${metadata.untitledNumber ?? 1}`;
|
|
93
94
|
return `editor:${metadata?.filePath ?? "untitled"}`;
|
|
94
95
|
case "chat": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{D as r,_ as i,b as a,c as o,d as s,f as c,g as l,h as u,m as d,p as f,s as p,u as m,v as h,x as g,y as _}from"./vendor-ui-B-89Uj8i.js";import{t as v}from"./createLucideIcon-BjHrJDVb.js";import{i as y}from"./dist-D7KGU7Vl.js";import{n as b,r as x}from"./plus-51UQ45rf.js";import{t as S}from"./input-bGJExpJZ.js";import{t as C}from"./refresh-cw-CSFrDtiu.js";import{t as w}from"./trash-2-BgDIBl6f.js";import{i as T,t as E}from"./api-client-r4nyVy7H.js";import{n as D}from"./utils-ChWX7pZv.js";import{a as O,h as k}from"./api-settings-t7Leca7J.js";var A=v(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),j=v(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),M=v(`bug`,[[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z`,key:`uouzyp`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M21 21a4 4 0 0 0-3.81-4`,key:`1b0z45`}],[`path`,{d:`M21 5a4 4 0 0 1-3.55 3.97`,key:`5cxbf6`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M3 21a4 4 0 0 1 3.81-4`,key:`1fjd4g`}],[`path`,{d:`M3 5a4 4 0 0 0 3.55 3.97`,key:`1d7oge`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M9 7.13V6a3 3 0 1 1 6 0v1.13`,key:`1vgav8`}]]),N=v(`lock`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]),P=v(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),F=v(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),I=e(n(),1),L=t();function R({className:e,...t}){return(0,L.jsx)(r,{"data-slot":`label`,className:D(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}var z=I.forwardRef(({className:e,...t},n)=>(0,L.jsx)(p,{className:D(`peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input`,e),...t,ref:n,children:(0,L.jsx)(o,{className:D(`pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0`)})}));z.displayName=p.displayName;function B({...e}){return(0,L.jsx)(l,{"data-slot":`select`,...e})}function V({...e}){return(0,L.jsx)(a,{"data-slot":`select-value`,...e})}function H({className:e,size:t=`default`,children:n,...r}){return(0,L.jsxs)(_,{"data-slot":`select-trigger`,"data-size":t,className:D(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,L.jsx)(s,{asChild:!0,children:(0,L.jsx)(x,{className:`size-4 opacity-50`})})]})}function U({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,L.jsx)(u,{children:(0,L.jsxs)(m,{"data-slot":`select-content`,className:D(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,L.jsx)(G,{}),(0,L.jsx)(g,{className:D(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,L.jsx)(K,{})]})})}function W({className:e,children:t,...n}){return(0,L.jsxs)(c,{"data-slot":`select-item`,className:D(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,L.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,L.jsx)(f,{children:(0,L.jsx)(y,{className:`size-4`})})}),(0,L.jsx)(d,{children:t})]})}function G({className:e,...t}){return(0,L.jsx)(h,{"data-slot":`select-scroll-up-button`,className:D(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,L.jsx)(b,{className:`size-4`})})}function K({className:e,...t}){return(0,L.jsx)(i,{"data-slot":`select-scroll-down-button`,className:D(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,L.jsx)(x,{className:`size-4`})})}var q={claude:`C`,cursor:`▶`,codex:`◆`,gemini:`G`};function J({value:e,onChange:t,projectName:n}){let[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)(!1),s=(0,I.useRef)(null),c=(0,I.useRef)(0);(0,I.useEffect)(()=>{n&&E.get(`${T(n)}/chat/providers`).then(i).catch(()=>{})},[n]),(0,I.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,I.useEffect)(()=>{a&&(c.current=Math.max(0,r.findIndex(t=>t.id===e)))},[a,e,r]);let l=(0,I.useCallback)(e=>{if(e.key===`Escape`){o(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;c.current=(c.current+t+r.length)%r.length,(s.current?.querySelector(`[data-idx="${c.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=r[c.current];n&&(t(n.id),o(!1))}},[t,r]);if(r.length<=1)return null;let u=r.find(t=>t.id===e),d=q[e]||`?`;return(0,L.jsxs)(`div`,{className:`relative`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(e=>!e)},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`AI Provider: ${u?.name??e}`,children:[(0,L.jsx)(`span`,{className:`inline-flex h-3.5 w-3.5 items-center justify-center rounded text-[9px] font-bold bg-surface-elevated shrink-0`,children:d}),(0,L.jsx)(`span`,{className:`max-w-[80px] truncate capitalize`,children:u?.name??e})]}),a&&(0,L.jsxs)(`div`,{ref:s,role:`listbox`,"aria-label":`AI Providers`,onKeyDown:l,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-56 rounded-lg border border-border bg-surface shadow-lg`,children:[(0,L.jsx)(`div`,{className:`px-3 py-2 border-b border-border`,children:(0,L.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Provider`})}),(0,L.jsx)(`div`,{className:`py-1`,children:r.map((n,r)=>{let i=q[n.id]||`?`,a=n.id===e;return(0,L.jsxs)(`button`,{"data-idx":r,role:`option`,"aria-selected":a,tabIndex:0,onClick:()=>{t(n.id),o(!1)},className:`w-full flex items-center gap-3 px-3 py-2 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${a?`bg-surface-elevated`:``}`,children:[(0,L.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded text-[11px] font-bold bg-surface-elevated text-text-subtle shrink-0`,children:i}),(0,L.jsx)(`span`,{className:`flex-1 text-sm font-medium text-text-primary capitalize`,children:n.name}),a&&(0,L.jsx)(y,{className:`size-4 shrink-0 text-primary`})]},n.id)})})]})]})}function Y({providerId:e}){return(0,L.jsx)(`span`,{className:`inline-flex h-4 w-4 items-center justify-center rounded text-[10px] font-bold bg-surface-elevated text-text-subtle shrink-0`,title:e,children:q[e]||`?`})}var X=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`}],Z=[{value:`bypassPermissions`,label:`Bypass permissions (default)`},{value:`default`,label:`Ask before edits`},{value:`acceptEdits`,label:`Edit automatically`},{value:`plan`,label:`Plan mode`}],Q={claude:`Claude`,cursor:`Cursor`,codex:`Codex`,gemini:`Gemini`};function $({compact:e}={}){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(``),[a,o]=(0,I.useState)([]),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(null),[p,m]=(0,I.useState)(0);(0,I.useEffect)(()=>{O().then(e=>{n(e),i(e.default_provider??`claude`)}).catch(e=>f(e.message))},[]),(0,I.useEffect)(()=>{r&&(c(!0),E.get(`/api/settings/ai/providers/${r}/models`).then(o).catch(()=>o([])).finally(()=>c(!1)))},[r]);let h=t?Object.keys(t.providers).filter(e=>e!==`mock`).map(e=>({id:e,name:Q[e]??e})):[],g=t?.providers[r],_=g?.type===`agent-sdk`||!g?.type&&r===`claude`,v=async(e,i)=>{if(t){u(!0),f(null);try{n(await k({providers:{[r]:{[e]:i}}})),m(e=>e+1)}catch(e){f(e.message)}finally{u(!1)}}},y=e?`text-[11px]`:`text-sm`,b=e?`text-xs`:`text-sm`,x=e?`space-y-2`:`space-y-4`,C=e?`space-y-1.5`:`space-y-3`,w=e?`space-y-1`:`space-y-1.5`;if(!t)return(0,L.jsxs)(`div`,{className:C,children:[(0,L.jsx)(`h3`,{className:`${b} font-medium text-text-secondary`,children:`AI Settings`}),(0,L.jsx)(`p`,{className:`${y} text-text-subtle`,children:d?`Error: ${d}`:`Loading...`})]});let T=_?a:[{value:`__default__`,label:`Auto (default)`},...a];return(0,L.jsxs)(`div`,{className:x,children:[(0,L.jsx)(`h3`,{className:`${b} font-medium text-text-secondary`,children:`AI Settings`}),h.length>1&&(0,L.jsx)(`div`,{className:`flex gap-0.5 border-b border-border/50 -mx-1 px-1`,children:h.map(e=>(0,L.jsxs)(`button`,{onClick:()=>i(e.id),className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-t transition-colors ${r===e.id?`text-primary border-b-2 border-primary font-medium`:`text-text-subtle hover:text-text-secondary`}`,children:[(0,L.jsx)(Y,{providerId:e.id}),(0,L.jsx)(`span`,{className:`capitalize`,children:e.name})]},e.id))}),(0,L.jsxs)(`div`,{className:C,children:[a.length>0&&(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-model`,className:e?y:void 0,children:`Model`}),(0,L.jsxs)(B,{value:_?g?.model??a[0]?.value:g?.model||`__default__`,onValueChange:e=>v(`model`,e===`__default__`?void 0:e),disabled:s,children:[(0,L.jsx)(H,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,L.jsx)(V,{placeholder:s?`Loading models...`:`Select model`})}),(0,L.jsx)(U,{className:`max-h-[300px]`,children:T.map(e=>(0,L.jsx)(W,{value:e.value,children:e.label},e.value))})]})]}),_&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-base-url`,className:e?y:void 0,children:`Base URL`}),(0,L.jsx)(S,{id:`ai-base-url`,type:`url`,defaultValue:g?.base_url??``,placeholder:`https://api.anthropic.com (default)`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{v(`base_url`,e.target.value.trim()||void 0)}},`baseurl-${r}-${p}`)]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-api-key`,className:e?y:void 0,children:`API Key / Token`}),(0,L.jsx)(S,{id:`ai-api-key`,type:`password`,defaultValue:g?.api_key??``,placeholder:`sk-ant-... (optional, overrides accounts)`,className:e?`h-7 text-[11px] font-mono`:`font-mono`,onBlur:e=>{let t=e.target.value.trim();t.startsWith(`••••`)||v(`api_key`,t||void 0)}},`apikey-${r}-${p}`),(0,L.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Direct API key or OAuth token. Leave empty to use connected accounts.`})]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-effort`,className:e?y:void 0,children:`Effort`}),(0,L.jsxs)(B,{value:g?.effort??`high`,onValueChange:e=>v(`effort`,e),children:[(0,L.jsx)(H,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,L.jsx)(V,{})}),(0,L.jsx)(U,{children:X.map(e=>(0,L.jsx)(W,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-max-turns`,className:e?y:void 0,children:`Max Turns (1-500)`}),(0,L.jsx)(S,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:g?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||v(`max_turns`,t)}},`turns-${r}-${p}`)]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-budget`,className:e?y:void 0,children:`Max Budget (USD)`}),(0,L.jsx)(S,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:g?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);v(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${r}-${p}`)]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-thinking`,className:e?y:void 0,children:`Thinking Budget (tokens)`}),(0,L.jsx)(S,{id:`ai-thinking`,type:`number`,min:0,defaultValue:g?.thinking_budget_tokens??``,placeholder:`Disabled`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);v(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${r}-${p}`)]}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{htmlFor:`ai-agent-teams`,className:e?y:void 0,children:`Agent Teams`}),(0,L.jsx)(`p`,{className:`${e?`text-[9px]`:`text-[11px]`} text-muted-foreground`,children:`Experimental. Enables multi-agent collaboration with shared tasks and messaging. Uses ~7x more tokens.`})]}),(0,L.jsx)(z,{id:`ai-agent-teams`,checked:g?.agent_teams??!1,onCheckedChange:e=>v(`agent_teams`,e)})]}),g?.agent_teams&&(0,L.jsx)(ee,{compact:e})]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-permission-mode`,className:e?y:void 0,children:`Default Permission Mode`}),(0,L.jsxs)(B,{value:g?.permission_mode??`bypassPermissions`,onValueChange:e=>v(`permission_mode`,e),children:[(0,L.jsx)(H,{id:`ai-permission-mode`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,L.jsx)(V,{})}),(0,L.jsx)(U,{children:Z.map(e=>(0,L.jsx)(W,{value:e.value,children:e.label},e.value))})]})]}),(0,L.jsxs)(`div`,{className:w,children:[(0,L.jsx)(R,{htmlFor:`ai-system-prompt`,className:e?y:void 0,children:`Additional Instructions`}),(0,L.jsx)(`textarea`,{id:`ai-system-prompt`,rows:e?3:4,defaultValue:g?.system_prompt??``,placeholder:`Enter additional instructions for ${r}...`,className:`w-full rounded-md border border-input bg-background px-3 py-2 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${e?`text-[11px]`:`text-sm`}`,onBlur:e=>{v(`system_prompt`,e.target.value.trim()||void 0)}},`sysprompt-${r}-${p}`)]})]}),l&&(0,L.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),d&&(0,L.jsx)(`p`,{className:`text-xs text-red-500`,children:d})]})}function ee({compact:e}){let[t,n]=(0,I.useState)([]),[r,i]=(0,I.useState)(!1),[a,o]=(0,I.useState)(null),s=(0,I.useCallback)(async()=>{i(!0);try{n(await E.get(`/api/teams`)??[])}catch{}i(!1)},[]);(0,I.useEffect)(()=>{s()},[s]);let c=async e=>{try{await E.del(`/api/teams/${encodeURIComponent(e)}`),n(t=>t.filter(t=>t.name!==e)),o(null)}catch{}};return t.length===0&&!r?null:(0,L.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(R,{className:e?`text-[11px]`:void 0,children:[`Teams (`,t.length,`)`]}),(0,L.jsx)(`button`,{onClick:s,className:`text-text-subtle hover:text-foreground p-1`,"aria-label":`Refresh teams`,children:(0,L.jsx)(C,{className:`size-3 ${r?`animate-spin`:``}`})})]}),t.map(e=>(0,L.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-surface-elevated text-xs`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),e.description&&(0,L.jsx)(`div`,{className:`text-text-subtle truncate`,children:e.description}),(0,L.jsxs)(`div`,{className:`text-text-subtle`,children:[e.members?.length??e.memberCount??0,` members`,e.createdAt?` · ${new Date(e.createdAt).toLocaleDateString()}`:``]})]}),a===e.name?(0,L.jsxs)(`div`,{className:`flex gap-1 shrink-0 ml-2`,children:[(0,L.jsx)(`button`,{onClick:()=>c(e.name),className:`px-2 py-1 bg-red-600 text-white rounded text-[10px]`,children:`Delete`}),(0,L.jsx)(`button`,{onClick:()=>o(null),className:`px-2 py-1 bg-zinc-600 text-white rounded text-[10px]`,children:`Cancel`})]}):(0,L.jsx)(`button`,{onClick:()=>o(e.name),className:`shrink-0 text-text-subtle hover:text-red-500 p-1 ml-2`,"aria-label":`Delete team ${e.name}`,children:(0,L.jsx)(w,{className:`size-3.5`})})]},e.name))]})}export{U as a,V as c,F as d,P as f,A as g,j as h,B as i,z as l,M as m,Y as n,W as o,N as p,J as r,H as s,$ as t,R as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{W as e}from"./vendor-mermaid-DCxaaPi4.js";export{e as createArchitectureServices};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-B7yiCjpQ.js","assets/rolldown-runtime-FhOqtrmT.js","assets/index-C7gvr4Xo.js","assets/vendor-mermaid-DCxaaPi4.js","assets/vendor-ui-B-89Uj8i.js","assets/vendor-markdown-0Mxgxy0L.js","assets/input-bGJExpJZ.js","assets/utils-ChWX7pZv.js","assets/createLucideIcon-BjHrJDVb.js","assets/x-BtqbfkR7.js","assets/settings-store-CdcSAgEZ.js","assets/react-BkWDCPD7.js","assets/api-client-r4nyVy7H.js","assets/scroll-area-D0EQpAH2.js","assets/ai-settings-section-DeW4WN43.js","assets/dist-D7KGU7Vl.js","assets/plus-51UQ45rf.js","assets/refresh-cw-CSFrDtiu.js","assets/trash-2-BgDIBl6f.js","assets/api-settings-t7Leca7J.js","assets/chevron-right-BzAdxJRG.js","assets/database-DCT0OjgQ.js","assets/file-store-BgZggznw.js","assets/tab-store-Jvy1eZGM.js","assets/index-BJ76xcQz.css","assets/csv-preview-C9qGhDlb.js","assets/lib-BqkcKGFq.js","assets/arrow-up-Dtrfv490.js","assets/csv-parser-DxVplKKB.js","assets/image-preview-YNpn3xj7.js","assets/file-exclamation-point-Baz81y5z.js","assets/use-blob-url-BgxxT-n_.js","assets/pdf-preview-D3u3Hr2R.js","assets/video-preview-CRDjNIVX.js","assets/audio-preview-DEJiSXcO.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import"./vendor-ui-B-89Uj8i.js";import"./scroll-area-D0EQpAH2.js";import{t as r}from"./chevron-right-BzAdxJRG.js";import{a as i,l as a,n as o,o as s,r as c,s as l,t as u}from"./input-bGJExpJZ.js";import{t as d}from"./code-CuravVys.js";import{t as f}from"./database-DCT0OjgQ.js";import{n as p,r as m}from"./x-BtqbfkR7.js";import{t as ee}from"./file-exclamation-point-Baz81y5z.js";import{t as h}from"./table-DbSviOmw.js";import{t as g}from"./text-wrap-DzvCTq_i.js";import{i as _,t as v}from"./api-client-r4nyVy7H.js";import{n as te}from"./settings-store-CdcSAgEZ.js";import{G as y}from"./vendor-mermaid-DCxaaPi4.js";import{t as b}from"./utils-ChWX7pZv.js";import{n as ne,t as re}from"./tab-store-Jvy1eZGM.js";import{r as x,t as S}from"./file-store-BgZggznw.js";import{G as ie,J as C,K as w,L as ae,U as T,X as oe,Y as E,a as se,c as D,d as O,f as k,g as A,h as ce,l as j,m as M,o as N,p as P,q as F,u as le}from"./index-C7gvr4Xo.js";import{n as ue,t as de}from"./use-monaco-theme-dtPsv6sh.js";import{n as fe,t as pe}from"./sql-completion-provider-EzHOQLfo.js";var I=e(n(),1),L=t(),R={ts:E,tsx:E,js:E,jsx:E,py:E,rs:E,go:E,html:E,css:E,scss:E,json:oe,md:C,txt:C,yaml:F,yml:F};function me(e,t){return t?ie:R[e.split(`.`).pop()?.toLowerCase()??``]??w}function he(e,t){let n=[],r=e;for(let e=0;e<t.length;e++){let i=t[e],a=t.slice(0,e+1).join(`/`),o=r.find(e=>e.name===i);if(n.push({name:i,fullPath:a,node:o??null,siblings:r}),o?.children)r=o.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[]});break}}return n}function z(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function ge({filePath:e,projectName:t,tabId:n,className:i}){let a=S(e=>e.tree),{updateTab:o,openTab:s}=re(ce(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=(0,I.useRef)(null),l=(0,I.useMemo)(()=>he(a,e.split(`/`).filter(Boolean)),[a,e]);(0,I.useEffect)(()=>{c.current&&(c.current.scrollLeft=c.current.scrollWidth)},[l]);function u(e,r){let i=b(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return(0,L.jsx)(`div`,{ref:c,className:i,children:l.map((e,n)=>(0,L.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[n>0&&(0,L.jsx)(r,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),e.siblings.length>0?(0,L.jsx)(B,{segment:e,isLast:n===l.length-1,projectName:t,onFileClick:u}):(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e.name})]},e.fullPath))})}function B({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=(0,I.useMemo)(()=>z(e.siblings),[e.siblings]);return(0,L.jsxs)(D,{children:[(0,L.jsx)(M,{asChild:!0,children:(0,L.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,L.jsx)(j,{align:`start`,className:`max-h-[300px] p-1`,children:i.map(t=>(0,L.jsx)(V,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function V({node:e,projectName:t,activePath:n,onFileClick:r}){let i=me(e.name,e.type===`directory`),a=e.path===n;return e.type===`directory`&&e.children&&e.children.length>0?(0,L.jsxs)(O,{children:[(0,L.jsxs)(P,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,L.jsx)(k,{className:`max-h-[300px] overflow-y-auto p-1`,children:z(e.children).map(e=>(0,L.jsx)(V,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]}):(0,L.jsxs)(le,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{e.type!==`directory`&&r(e.path,t)},children:[(0,L.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.name})]})}function H({active:e,onClick:t,icon:n,label:r}){return(0,L.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,L.jsx)(n,{className:`size-3`}),(0,L.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function _e({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,filePath:s,projectName:c,className:l}){return(0,L.jsxs)(`div`,{className:l,children:[(e===`md`||e===`mdx`)&&n&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(H,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,L.jsx)(H,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(H,{active:r===`table`,onClick:()=>i(`table`),icon:h,label:`Table`}),(0,L.jsx)(H,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,L.jsx)(H,{active:a,onClick:o,icon:g,label:`Wrap`}),s&&c&&(0,L.jsx)(H,{active:!1,onClick:()=>A(c,s),icon:m,label:`Download`})]})}function ve({open:e,defaultName:t,content:n,onSave:r,onCancel:d}){let[f,p]=(0,I.useState)(t),[m,ee]=(0,I.useState)(!1),[h,g]=(0,I.useState)(``),_=x(e=>e.activeProject),v=(0,I.useCallback)(()=>{let e=f.trim();if(!e){g(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){g(`Filename cannot contain / or \\`);return}g(``),ee(!0)},[f]),te=(0,I.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${f.trim()}`:`${e}${t}${f.trim()}`,n)},[f,n,r]);return m?(0,L.jsx)(N,{open:!0,mode:`folder`,root:_?.path,title:`Save "${f.trim()}" to...`,onSelect:te,onCancel:()=>ee(!1)}):(0,L.jsx)(o,{open:e,onOpenChange:e=>{e||d()},children:(0,L.jsxs)(c,{className:`sm:max-w-md`,children:[(0,L.jsx)(s,{children:(0,L.jsx)(l,{children:`Save As`})}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,L.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,L.jsx)(u,{value:f,onChange:e=>{p(e.target.value),g(``)},onKeyDown:e=>{e.key===`Enter`&&v()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),h&&(0,L.jsx)(`p`,{className:`text-xs text-destructive`,children:h})]}),(0,L.jsxs)(i,{children:[(0,L.jsx)(a,{variant:`outline`,onClick:d,children:`Cancel`}),(0,L.jsx)(a,{onClick:v,children:`Choose Folder...`})]})]})})}var ye=(0,I.lazy)(()=>y(()=>import(`./markdown-renderer-B7yiCjpQ.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]))),be=(0,I.lazy)(()=>y(()=>import(`./csv-preview-C9qGhDlb.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([25,1,4,5,26,8,27,28]))),xe=(0,I.lazy)(()=>y(()=>import(`./image-preview-YNpn3xj7.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([29,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,31]))),Se=(0,I.lazy)(()=>y(()=>import(`./pdf-preview-D3u3Hr2R.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,31]))),Ce=(0,I.lazy)(()=>y(()=>import(`./video-preview-CRDjNIVX.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([33,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,31]))),we=(0,I.lazy)(()=>y(()=>import(`./audio-preview-DEJiSXcO.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([34,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,31]))),Te=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ee=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),De=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Oe=new Set([`db`,`sqlite`,`sqlite3`]);function ke(e){return e.split(`.`).pop()?.toLowerCase()??``}function Ae(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`}[ke(e)]??`plaintext`}var U=(0,I.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,I.useState)(i??null),[c,l]=(0,I.useState)(`utf-8`),[u,d]=(0,I.useState)(!0),[p,m]=(0,I.useState)(null),[h,g]=(0,I.useState)(!1),y=(0,I.useRef)(null),x=(0,I.useRef)(``),S=(0,I.useRef)(null),{tabs:ie,updateTab:C}=re(ce(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:w,toggleWordWrap:oe}=te(ce(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),E=de(),D=e?.isUntitled===!0,O=e?.unsavedContent,[k,A]=(0,I.useState)(!1),j=ie.find(e=>e.id===t),M=n?ke(n):``,N=Te.has(M),P=M===`pdf`,F=Ee.has(M),le=De.has(M),R=Oe.has(M),me=M===`md`||M===`mdx`,he=M===`csv`,z=M===`sql`,[B,V]=(0,I.useState)(`preview`),[H,ye]=(0,I.useState)(`table`),{connections:U,cachedTables:Me,refreshTables:Ne}=se(),[G,Pe]=(0,I.useState)(()=>{if(!z||!n)return null;let e=localStorage.getItem(`ppm:sql-conn:${n}`);return e?Number(e):null}),K=(0,I.useRef)(null),q=(0,I.useRef)(null),J=(0,I.useMemo)(()=>U.find(e=>e.id===G)??null,[U,G]),Fe=i!=null&&(a===`json`||a===`xml`),[Ie,Le]=(0,I.useState)(!1),Re=(0,I.useCallback)(()=>{if(i)if(Ie)s(i),Le(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),Le(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
3
|
-
$2$3`).split(`
|
|
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
|
-
`)),Le(!0)}}},[i,a,Ie]),ze=(0,I.useCallback)(e=>{Pe(e),n&&localStorage.setItem(`ppm:sql-conn:${n}`,String(e)),Ne(e).catch(()=>{})},[n,Ne]),Y=(0,I.useMemo)(()=>{if(!z||!G)return;let e=(Me.get(G)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>v.get(`/api/db/connections/${G}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[z,G,Me]);(0,I.useEffect)(()=>{if(!(!K.current||!Y))return q.current?.dispose(),pe(),q.current=K.current.languages.registerCompletionItemProvider(`sql`,fe(K.current,Y)),()=>{q.current?.dispose()}},[Y]);let Be=re(e=>e.openTab),X=(0,I.useCallback)(e=>{J&&Be({type:`database`,title:`${J.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:J.id,connectionName:J.name,dbType:J.type,initialSql:e}})},[J,Be]),Ve=(0,I.useCallback)(()=>{if(!S.current||!J)return;let e=S.current,t=e.getSelection();X(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[J,X]),Z=(0,I.useRef)([]),He=(0,I.useRef)(X);He.current=X,(0,I.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,I.useEffect)(()=>{R&&t&&C(t,{type:`sqlite`})},[R,t,C]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,I.useEffect)(()=>{if(i!=null){d(!1);return}if(D){s(O??``),x.current=O??``,d(!1),O&&g(!0);return}if(!n||!Q&&!r)return;if(N||P||F||le){d(!1);return}d(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${_(r)}/files/read?path=${encodeURIComponent(n)}`;return v.get(e).then(e=>{s(e.content),e.encoding&&l(e.encoding),x.current=e.content,d(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),d(!1)}),()=>{y.current&&clearTimeout(y.current)}},[n,r,N,P,Q,D]);let Ue=(0,I.useRef)(h);Ue.current=h,(0,I.useEffect)(()=>{if(!n||!r||i!=null||D)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||Ue.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${_(r)}/files/read?path=${encodeURIComponent(n)}`;v.get(i).then(e=>{e.content!==x.current&&(s(e.content),x.current=e.content,e.encoding&&l(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,i,D]),(0,I.useEffect)(()=>{if(!j)return;let t=D?`Untitled-${e?.untitledNumber??1}`:n?b(n):`Untitled`,r=h?`${t} \u25CF`:t;j.title!==r&&C(j.id,{title:r})},[h]);let We=(0,I.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await v.put(`/api/fs/write`,{path:n,content:e}):await v.put(`${_(r)}/files/write`,{path:n,content:e}),g(!1)}catch{}},[n,r,Q]);function Ge(n){let r=n??``;s(r),x.current=r,g(!0),y.current&&clearTimeout(y.current),D?y.current=setTimeout(()=>{t&&C(t,{metadata:{...e,unsavedContent:x.current}})},2e3):y.current=setTimeout(()=>We(x.current),1e3)}let Ke=(0,I.useCallback)(async(e,n)=>{try{if(y.current&&clearTimeout(y.current),await v.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=ne.getState();n(t),r({type:`editor`,title:b(e),projectId:null,metadata:{filePath:e},closable:!0})}g(!1),A(!1)}catch{}},[t]),$=e?.lineNumber,qe=(0,I.useCallback)((e,t)=>{if(S.current=e,K.current=t,$&&$>0&&setTimeout(()=>{e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),e.focus()},100),D&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>A(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>te.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),Y&&(q.current?.dispose(),q.current=t.languages.registerCompletionItemProvider(`sql`,fe(t,Y))),z){Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&He.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`
|
|
6
|
-
`),a=-1,o=[],s=!1,c=(e,n)=>{let i=n.trim();!i||i.startsWith(`--`)||t.push({range:{startLineNumber:e,startColumn:1,endLineNumber:e,endColumn:1},command:{id:r,title:`▷ Run`,arguments:[i]}})};for(let e=0;e<i.length;e++){let t=i[e].trim();if(a===-1){if(!t||t.startsWith(`--`))continue;a=e+1,o=[]}o.push(i[e]),(t.match(/\$\$/g)||[]).length%2==1&&(s=!s),!s&&t.endsWith(`;`)&&(c(a,o.join(`
|
|
7
|
-
`)),a=-1,o=[])}return a>0&&o.join(``).trim()&&c(a,o.join(`
|
|
8
|
-
`)),{lenses:t,dispose:()=>{}}}});Z.current.push(e)}}},[Y]);if(!i&&!D&&(!n||!Q&&!r))return(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(u)return(0,L.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,L.jsx)(T,{className:`size-5 animate-spin`}),(0,L.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(p)return(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p});if(N)return(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(W,{}),children:(0,L.jsx)(xe,{filePath:n,projectName:r})});if(P)return(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(W,{}),children:(0,L.jsx)(Se,{filePath:n,projectName:r})});if(F)return(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(W,{}),children:(0,L.jsx)(Ce,{filePath:n,projectName:r})});if(le)return(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(W,{}),children:(0,L.jsx)(we,{filePath:n,projectName:r})});if(c===`base64`)return(0,L.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,L.jsx)(ee,{className:`size-10 text-text-subtle`}),(0,L.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,L.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]});let Je=z?(0,L.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,L.jsx)(f,{className:`size-3 text-muted-foreground`}),(0,L.jsxs)(`select`,{value:G??``,onChange:e=>{let t=Number(e.target.value);t&&ze(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,L.jsx)(`option`,{value:``,children:`Connection…`}),U.map(e=>(0,L.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,L.jsx)(`button`,{type:`button`,onClick:Ve,disabled:!J,className:`p-0.5 rounded text-muted-foreground hover:text-primary disabled:opacity-30 transition-colors`,title:`Run all in DB Viewer`,children:(0,L.jsx)(ae,{className:`size-3.5`})})]}):null;return(0,L.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[i!=null&&Fe&&(0,L.jsx)(`div`,{className:`flex items-center h-7 border-b border-border bg-background shrink-0 px-2 gap-2`,children:(0,L.jsx)(`button`,{type:`button`,onClick:Re,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted transition-colors text-foreground`,children:Ie?`Raw`:`Beautify`})}),n&&r&&t&&(0,L.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,L.jsx)(ge,{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`}),Je,(0,L.jsx)(_e,{ext:M,mdMode:B,onMdModeChange:V,csvMode:H,onCsvModeChange:ye,wordWrap:w,onToggleWordWrap:oe,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),z&&(!r||!t)&&(0,L.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0 px-2`,children:[(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1`,children:n?b(n):`SQL`}),Je]}),he&&H===`table`?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(T,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,L.jsx)(be,{content:o??``,onContentChange:Ge,wordWrap:w})}):me&&B===`preview`?(0,L.jsx)(je,{content:o??``}):(0,L.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,L.jsx)(ue,{height:`100%`,language:a??Ae(n??``),value:o??``,onChange:i==null?Ge:void 0,onMount:qe,theme:E,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:w?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0},readOnly:i!=null},loading:(0,L.jsx)(T,{className:`size-5 animate-spin text-text-subtle`})})}),k&&(0,L.jsx)(ve,{open:k,defaultName:`Untitled-${e?.untitledNumber??1}`,content:x.current,onSave:Ke,onCancel:()=>A(!1)})]})});function W(){return(0,L.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,L.jsx)(T,{className:`size-5 animate-spin text-text-subtle`})})}function je({content:e}){return(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded m-4`}),children:(0,L.jsx)(ye,{content:e,className:`flex-1 overflow-auto p-4`})})}export{U as CodeEditor};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import{n as i,r as a,t as o}from"./plus-51UQ45rf.js";import{t as s}from"./chevron-right-BzAdxJRG.js";import{t as c}from"./database-DCT0OjgQ.js";import{n as l,r as u,t as d}from"./x-BtqbfkR7.js";import{t as f}from"./refresh-cw-CSFrDtiu.js";import{t as p}from"./trash-2-BgDIBl6f.js";import{t as m}from"./api-client-r4nyVy7H.js";import"./settings-store-CdcSAgEZ.js";import"./vendor-mermaid-DCxaaPi4.js";import{t as h}from"./tab-store-Jvy1eZGM.js";import{I as g,R as _,U as v,W as y,h as b,rt as x,z as S}from"./index-C7gvr4Xo.js";import"./use-monaco-theme-dtPsv6sh.js";import{t as C}from"./sql-query-editor-vpD0I0KG.js";import{n as w}from"./csv-parser-DxVplKKB.js";var T=r(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),E=r(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),D=e(n(),1);function O(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function ee(e,t,n,r){try{let i=sessionStorage.getItem(O(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function te(e,t,n,r,i,a){try{sessionStorage.setItem(O(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function ne(e){let t=`/api/db/connections/${e}`,[n,r]=(0,D.useState)(null),[i,a]=(0,D.useState)(`public`),[o,s]=(0,D.useState)(null),[c,l]=(0,D.useState)([]),[u,d]=(0,D.useState)(!1),[f,p]=(0,D.useState)(null),[h,g]=(0,D.useState)(1),[_,v]=(0,D.useState)(null),[y,b]=(0,D.useState)(null),[x,S]=(0,D.useState)(!1),[C,w]=(0,D.useState)(null),[T,E]=(0,D.useState)(`ASC`),O=(0,D.useCallback)(async(r,a,o,c,u)=>{let f=r??n,g=a??i;if(!f)return;d(!0);let _=c===void 0?C:c,v=u??T;try{let n=_?`&orderBy=${encodeURIComponent(_)}&orderDir=${v}`:``,[r,i]=await Promise.all([m.get(`${t}/data?table=${encodeURIComponent(f)}&schema=${g}&page=${o??h}&limit=100${n}`),m.get(`${t}/schema?table=${encodeURIComponent(f)}&schema=${g}`)]);s(r),l(i),te(e,f,g,o??h,r,i)}catch(e){p(e.message)}finally{d(!1)}},[t,e,n,i,h,C,T]),ne=(0,D.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),v(null);let i=ee(e,t,n,1);i?(s(i.data),l(i.cols),d(!1),O(t,n,1)):O(t,n,1)},[e,O]),k=(0,D.useCallback)(e=>{g(e),O(void 0,void 0,e)},[O]),A=(0,D.useCallback)(async e=>{S(!0),b(null);try{let r=await m.post(`${t}/query`,{sql:e});v(r),r.changeType===`modify`&&O(n??void 0,i)}catch(e){b(e.message)}finally{S(!1)}},[t,n,i,O]),re=(0,D.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await m.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),O(s,c)}catch(e){p(e.message)}},[t,n,i,O]),j=(0,D.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.del(`${t}/row`,{table:a,schema:o,pkColumn:e,pkValue:r}),O(a,o)}catch(e){p(e.message)}},[t,n,i,O]);return{selectedTable:n,selectedSchema:i,selectTable:ne,tableData:o,schema:c,loading:u,error:f,page:h,setPage:k,orderBy:C,orderDir:T,toggleSort:(0,D.useCallback)(e=>{let t,n=`ASC`;C===e?T===`ASC`?(t=e,n=`DESC`):(t=null,n=`ASC`):(t=e,n=`ASC`),w(t),E(n),g(1),O(void 0,void 0,1,t,n)},[C,T,O]),queryResult:_,queryError:y,queryLoading:x,executeQuery:A,updateCell:re,deleteRow:j,bulkDelete:(0,D.useCallback)(async(e,r)=>{if(!n)return;let a=n,o=i;try{await m.post(`${t}/rows/delete`,{table:a,schema:o,pkColumn:e,pkValues:r}),O(a,o)}catch(e){p(e.message)}},[t,n,i,O]),insertRow:(0,D.useCallback)(async e=>{if(!n)return;let r=n,a=i;try{await m.post(`${t}/row`,{table:r,schema:a,values:e}),O(r,a)}catch(e){throw p(e.message),e}},[t,n,i,O]),refreshData:O,queryAsTable:(0,D.useCallback)(async e=>{d(!0);try{let n=await m.post(`${t}/query`,{sql:e});n.changeType===`select`&&s({columns:n.columns,rows:n.rows,total:n.rows.length,page:1,limit:n.rows.length})}catch(e){p(e.message)}finally{d(!1)}},[t])}}var k=t();function A(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.click(),URL.revokeObjectURL(i)}function re({columns:e,rows:t,filename:n=`export`,exportAllUrl:r}){let[i,a]=(0,D.useState)(!1),[o,s]=(0,D.useState)(!1),c=(0,D.useRef)(null);(0,D.useEffect)(()=>{if(!i)return;let e=e=>{c.current&&!c.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let l=()=>{let r=w(e,t.map(t=>e.map(e=>String(t[e]??``))));A(`${n}.csv`,r,`text/csv`),a(!1)},d=()=>{let e=JSON.stringify(t,null,2);A(`${n}.json`,e,`application/json`),a(!1)},f=async e=>{if(r){s(!0);try{let t=await(await fetch(`${r}&format=${e}&limit=10000`)).text(),i=e===`csv`?`text/csv`:`application/json`;A(`${n}-all.${e}`,t,i)}catch{}s(!1),a(!1)}};return e.length===0||t.length===0?null:(0,k.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,k.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,title:`Export`,children:(0,k.jsx)(u,{className:`size-3.5`})}),i&&(0,k.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 bg-popover border border-border rounded-md shadow-md py-1 min-w-[160px] text-xs`,children:[(0,k.jsx)(`button`,{onClick:l,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (CSV)`}),(0,k.jsx)(`button`,{onClick:d,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors`,children:`Export Page (JSON)`}),r&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`border-t border-border my-1`}),(0,k.jsx)(`button`,{onClick:()=>f(`csv`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (CSV)`}),(0,k.jsx)(`button`,{onClick:()=>f(`json`),disabled:o,className:`w-full text-left px-3 py-1.5 hover:bg-muted transition-colors disabled:opacity-50`,children:o?`Exporting…`:`Export All (JSON)`})]})]})]})}function j({tableData:e,schema:t,loading:n,page:r,onPageChange:c,onCellUpdate:l,onRowDelete:u,orderBy:f,orderDir:m,onToggleSort:y,onBulkDelete:C,onInsertRow:w,connectionId:O,selectedTable:ee,selectedSchema:te,connectionName:ne,columnFilters:A={},onColumnFilter:j}){let[M,N]=(0,D.useState)(null),[P,F]=(0,D.useState)(``),[I,L]=(0,D.useState)(null),[R,se]=(0,D.useState)(``),[z,B]=(0,D.useState)(new Set),[ce,le]=(0,D.useState)(!1),[ue,de]=(0,D.useState)({}),[fe,V]=(0,D.useState)(null),[pe,me]=(0,D.useState)(!1),{openTab:H}=h(b(e=>({openTab:e.openTab}))),he=(0,D.useCallback)(e=>{H({type:`editor`,title:e.col,projectId:null,closable:!0,metadata:{inlineContent:e.value,inlineLanguage:ie(e.value)}})},[H]),[U,ge]=(0,D.useState)(new Set),[_e,ve]=(0,D.useState)(new Set),[ye,be]=(0,D.useState)(null),[xe,W]=(0,D.useState)(!1),Se=(0,D.useRef)(null),G=(0,D.useMemo)(()=>t.find(e=>e.pk)?.name||(t.find(e=>e.name.toLowerCase()===`id`)?.name??null),[t]),Ce=(0,D.useCallback)(e=>{let t=JSON.stringify(e,null,2),n=G?String(e[G]??``):``;H({type:`editor`,title:n?`Row ${n}`:`Row`,projectId:null,closable:!0,metadata:{inlineContent:t,inlineLanguage:`json`}})},[H,G]),we=(0,D.useRef)(M);we.current=M;let K=(0,D.useRef)(P);K.current=P;let Te=(0,D.useRef)(z);Te.current=z;let Ee=(0,D.useRef)(I);Ee.current=I;let De=(0,D.useCallback)((e,t,n)=>{N({rowIdx:e,col:t}),F(n==null?``:typeof n==`object`?JSON.stringify(n):String(n))},[]),Oe=(0,D.useCallback)(()=>{let t=we.current;if(!t||!e||!G)return;let n=e.rows[t.rowIdx];if(!n)return;let r=n[t.col];String(r??``)!==K.current&&l(G,n[G],t.col,K.current===``?null:K.current),N(null)},[e,G,l]),ke=(0,D.useCallback)(()=>N(null),[]),Ae=(0,D.useCallback)(t=>{if(!e||!G||!u)return;let n=e.rows[t];n&&(u(G,n[G]),L(null))},[e,G,u]),je=(0,D.useCallback)(e=>{ge(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,D.useCallback)(e=>{ve(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ne=(0,D.useCallback)((e,t)=>{let n={...A};t?n[e]=t:delete n[e],j?.(n)},[A,j]),Pe=(0,D.useCallback)(e=>{B(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Fe=(0,D.useCallback)(()=>{e&&B(t=>t.size===e.rows.length?new Set:new Set(e.rows.map((e,t)=>t)))},[e]),Ie=(0,D.useCallback)(()=>{!e||!G||!C||(C(G,Array.from(z).map(t=>e.rows[t]?.[G]).filter(e=>e!=null)),B(new Set),me(!1))},[e,G,C,z]),Le=(0,D.useCallback)(async()=>{if(w){V(null);try{let e={};for(let[t,n]of Object.entries(ue))n!==``&&(e[t]=n);await w(e),le(!1),de({})}catch(e){V(e.message)}}},[w,ue]),q=(0,D.useMemo)(()=>{if(!e||!R)return e?.rows??[];let t=R.toLowerCase();return e.rows.filter(n=>e.columns.some(e=>String(n[e]??``).toLowerCase().includes(t)))},[e,R]),Re=(0,D.useRef)(null);(0,D.useEffect)(()=>{let t=Re.current;if(!t)return;let n=t=>{if(t.key===`Escape`){W(!1);return}let n=t.target?.tagName;if(!(n===`INPUT`||n===`TEXTAREA`)){if(t.key===`/`){t.preventDefault(),W(!0);return}if(!(!(t.metaKey||t.ctrlKey)||!e)&&(t.key===`a`&&(t.preventDefault(),B(new Set(e.rows.map((e,t)=>t)))),t.key===`c`&&z.size>0)){t.preventDefault();let n=e.columns,r=n.join(` `),i=Array.from(z).sort((e,t)=>e-t).map(t=>n.map(n=>{let r=e.rows[t]?.[n];return r==null?``:typeof r==`object`?JSON.stringify(r):String(r)}).join(` `));navigator.clipboard.writeText([r,...i].join(`
|
|
2
|
-
`))}}};return t.addEventListener(`keydown`,n),()=>t.removeEventListener(`keydown`,n)},[e,z]);let J=(0,D.useMemo)(()=>{if(!e)return[];let t=e.columns.filter(e=>U.has(e)),n=e.columns.filter(e=>!U.has(e));return[...t,...n]},[e?.columns,U]),ze=(0,D.useRef)(null),[Be,Ve]=(0,D.useState)(0),[Y,He]=(0,D.useState)(new Map);(0,D.useEffect)(()=>{let e=ze.current;if(!e)return;let t=()=>{Ve(e.offsetHeight);let t=new Map;e.querySelectorAll(`th[data-col]`).forEach(e=>{t.set(e.dataset.col,e.offsetWidth)});let n=e.querySelector(`th[data-col='_cb']`);n&&t.set(`_cb`,n.offsetWidth),He(t)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e?.columns,U]);let X=(0,D.useMemo)(()=>{let e=new Map,t=Y.get(`_cb`)??(G?40:0);for(let n of J){if(!U.has(n))break;e.set(n,t),t+=Y.get(n)??100}return e},[J,U,G,Y]),Z=(0,D.useMemo)(()=>Array.from(_e).sort((e,t)=>e-t).map(e=>({idx:e,row:q[e]})).filter(e=>e.row),[_e,q]),Q=(0,D.useRef)(new Map),[$,Ue]=(0,D.useState)(new Map),We=(0,D.useCallback)((e,t)=>{t?Q.current.set(e,t):Q.current.delete(e)},[]);(0,D.useEffect)(()=>{if(Z.length===0){$.size>0&&Ue(new Map);return}let e=requestAnimationFrame(()=>{let e=new Map;for(let{idx:t}of Z){let n=Q.current.get(t);n&&e.set(t,n.offsetHeight)}Ue(e)});return()=>cancelAnimationFrame(e)},[Z,e]);let Ge=(0,D.useMemo)(()=>{let e=new Map,t=Be;for(let{idx:n}of Z)e.set(n,t),t+=$.get(n)??28;return e},[Be,Z,$]),Ke=(0,D.useCallback)(e=>{let t=Se.current,n=t?.querySelector(`th[data-col="${e}"]`);if(!t||!n)return;let r=0,i=t.querySelector(`th[data-col="_cb"]`);i&&(r+=i.offsetWidth);for(let[t,n]of X)t!==e&&(r=Math.max(r,n+(Y.get(t)??0)));let a=n.offsetLeft-r;t.scrollTo({left:a,behavior:`instant`}),W(!1)},[X,Y]);if(!e)return(0,k.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,k.jsx)(v,{className:`size-4 animate-spin`}):`Select a table`});let qe=Math.ceil(e.total/e.limit)||1,Je=z.size>0,Ye=z.size===e.rows.length&&e.rows.length>0;return(0,k.jsxs)(`div`,{ref:Re,tabIndex:0,className:`flex flex-col h-full overflow-hidden outline-none`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 border-b border-border bg-background shrink-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1 flex-1`,children:[(0,k.jsx)(g,{className:`size-3 text-muted-foreground`}),(0,k.jsx)(`input`,{type:`text`,value:R,onChange:e=>se(e.target.value),placeholder:`Search current page…`,className:`flex-1 text-xs bg-transparent outline-none text-foreground placeholder:text-muted-foreground`}),R&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>se(``),className:`text-muted-foreground hover:text-foreground`,children:(0,k.jsx)(d,{className:`size-3`})})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:()=>W(!xe),className:`p-0.5 rounded transition-colors ${xe?`text-primary`:`text-muted-foreground hover:text-foreground`}`,title:`Jump to column ( / )`,children:(0,k.jsx)(T,{className:`size-3.5`})}),xe&&(0,k.jsx)(ae,{columns:e.columns,onSelect:Ke,onClose:()=>W(!1)})]}),Je&&(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,k.jsxs)(`span`,{className:`text-muted-foreground`,children:[z.size,` selected`]}),C&&G&&(pe?(0,k.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:Ie,className:`text-destructive text-[10px] font-medium hover:underline`,children:[`Delete `,z.size,`?`]}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>me(!1),className:`text-muted-foreground text-[10px] hover:underline`,children:`Cancel`})]}):(0,k.jsx)(`button`,{type:`button`,onClick:()=>me(!0),className:`p-0.5 text-muted-foreground hover:text-destructive`,children:(0,k.jsx)(p,{className:`size-3`})})),(0,k.jsx)(re,{columns:e.columns,rows:Array.from(z).map(t=>e.rows[t]).filter(Boolean),filename:`${ne??`db`}-selected`})]}),w&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>{le(!0),de({}),V(null)},className:`p-0.5 rounded text-muted-foreground hover:text-primary transition-colors`,title:`Insert row`,children:(0,k.jsx)(o,{className:`size-3.5`})})]}),ce&&(0,k.jsxs)(`div`,{className:`px-2 py-1.5 border-b border-border bg-muted/30 text-xs space-y-1`,children:[(0,k.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(e=>!e.pk).map(e=>(0,k.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(`label`,{className:`text-muted-foreground text-[10px] w-16 truncate`,title:e.name,children:e.name}),(0,k.jsx)(`input`,{value:ue[e.name]??``,onChange:t=>de(n=>({...n,[e.name]:t.target.value})),placeholder:e.defaultValue??(e.nullable?`NULL`:``),className:`h-5 w-24 text-[11px] px-1 rounded border border-border bg-background outline-none focus:border-primary`})]},e.name))}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:Le,className:`text-[10px] px-2 py-0.5 rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:`Save`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>le(!1),className:`text-[10px] text-muted-foreground hover:underline`,children:`Cancel`}),fe&&(0,k.jsx)(`span`,{className:`text-[10px] text-destructive`,children:fe})]})]}),(0,k.jsxs)(`div`,{ref:Se,className:`flex-1 overflow-auto relative`,children:[n&&(0,k.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-background/60`,children:(0,k.jsx)(v,{className:`size-5 animate-spin text-primary`})}),(0,k.jsxs)(`table`,{className:`w-full text-xs`,style:{borderCollapse:`separate`,borderSpacing:0},children:[(0,k.jsx)(`thead`,{ref:ze,className:`sticky top-0 z-20 bg-muted`,children:(0,k.jsxs)(`tr`,{children:[G&&(0,k.jsx)(`th`,{"data-col":`_cb`,className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border w-10 bg-muted`,style:{position:`sticky`,left:0,zIndex:30},children:(0,k.jsx)(`input`,{type:`checkbox`,checked:Ye,onChange:Fe,className:`size-3 accent-primary`})}),J.map(e=>{let n=t.find(t=>t.name===e)?.pk,r=f===e,o=U.has(e),s=!!A[e],c=ye===e,l=X.get(e);return(0,k.jsxs)(`th`,{"data-col":e,className:`group/th px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap bg-muted ${o?`border-r border-r-primary/20`:``}`,style:l==null?void 0:{position:`sticky`,left:l,zIndex:25},children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>y(e),className:`flex items-center gap-0.5 ${n?`font-bold`:``} hover:text-foreground transition-colors`,children:[e,r&&m===`ASC`&&(0,k.jsx)(i,{className:`size-3`}),r&&m===`DESC`&&(0,k.jsx)(a,{className:`size-3`})]}),j&&(0,k.jsx)(`button`,{type:`button`,title:`Filter column`,onClick:()=>be(c?null:e),className:`p-0.5 rounded transition-colors ${s||c?`text-primary`:`text-muted-foreground/40 md:opacity-0 md:group-hover/th:opacity-100 hover:text-foreground`}`,children:(0,k.jsx)(E,{className:`size-2.5`})}),(0,k.jsx)(`button`,{type:`button`,title:o?`Unpin column`:`Pin column`,onClick:()=>je(e),className:`p-0.5 rounded transition-colors ${o?`text-primary`:`text-muted-foreground/40 md:opacity-0 md:group-hover/th:opacity-100 hover:text-foreground`}`,children:o?(0,k.jsx)(S,{className:`size-2.5`}):(0,k.jsx)(_,{className:`size-2.5`})})]}),c&&(0,k.jsxs)(`div`,{className:`mt-1 flex items-center gap-1`,children:[(0,k.jsx)(`input`,{autoFocus:!0,type:`text`,value:A[e]??``,placeholder:`ILIKE filter…`,onChange:t=>Ne(e,t.target.value),onKeyDown:e=>{e.key===`Escape`&&be(null)},className:`w-full h-5 text-[10px] px-1 rounded border border-border bg-background outline-none focus:border-primary`}),s&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>Ne(e,``),className:`text-muted-foreground hover:text-foreground`,children:(0,k.jsx)(d,{className:`size-2.5`})})]})]},e)}),u&&G&&(0,k.jsx)(`th`,{className:`px-2 py-1.5 border-b border-border w-14 bg-muted`})]})}),(0,k.jsxs)(`tbody`,{children:[Z.map(({idx:e,row:t})=>(0,k.jsx)(oe,{row:t,rowIdx:e,columns:J,selected:z.has(e),onToggleSelect:Pe,pkCol:G,editingCell:M,editValue:P,onStartEdit:De,onCommitEdit:Oe,onCancelEdit:ke,onSetEditValue:F,showDelete:!!u,confirmingDelete:I===e,onDelete:Ae,onConfirmDelete:L,onViewCell:he,onViewRow:Ce,pinned:!0,onTogglePin:Me,pinnedCols:U,pinnedColOffsets:X,stickyTop:Ge.get(e)??Be,trRef:t=>We(e,t)},`pin-${e}`)),q.map((e,t)=>_e.has(t)?null:(0,k.jsx)(oe,{row:e,rowIdx:t,columns:J,selected:z.has(t),onToggleSelect:Pe,pkCol:G,editingCell:M,editValue:P,onStartEdit:De,onCommitEdit:Oe,onCancelEdit:ke,onSetEditValue:F,showDelete:!!u,confirmingDelete:I===t,onDelete:Ae,onConfirmDelete:L,onViewCell:he,onViewRow:Ce,pinned:!1,onTogglePin:Me,pinnedCols:U,pinnedColOffsets:X},t)),q.length===0&&(0,k.jsx)(`tr`,{children:(0,k.jsx)(`td`,{colSpan:J.length+2,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,k.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,k.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 text-[10px] text-muted-foreground/50`,children:[(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:`/`}),` columns`]}),(0,k.jsxs)(`span`,{children:[(0,k.jsxs)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:[`⌘`,`A`]}),` select all`]}),(0,k.jsxs)(`span`,{children:[(0,k.jsxs)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted text-[9px]`,children:[`⌘`,`C`]}),` copy`]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,disabled:r<=1,onClick:()=>c(r-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,k.jsx)(x,{className:`size-3.5`})}),(0,k.jsxs)(`span`,{children:[r,` / `,qe]}),(0,k.jsx)(`button`,{type:`button`,disabled:r>=qe,onClick:()=>c(r+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,k.jsx)(s,{className:`size-3.5`})})]})]})]})}function M(e){return e==null?`NULL`:typeof e==`object`?JSON.stringify(e):String(e)}var N=200;function P(e){if(e==null)return!1;if(typeof e==`object`)return!0;let t=String(e);if(t.length>=N)return!0;let n=t.trimStart();return!!((n[0]===`{`||n[0]===`[`)&&(n.endsWith(`}`)||n.endsWith(`]`))||n.startsWith(`<?xml`)||n.startsWith(`<`)&&n.endsWith(`>`))}function ie(e){let t=e.trimStart();if(t[0]===`{`||t[0]===`[`)try{return JSON.parse(t),`json`}catch{}return t.startsWith(`<?xml`)||t.startsWith(`<`)&&/<\/\w+>/.test(t)?`xml`:t.startsWith(`---`)||/^\w+:\s/m.test(t)?`yaml`:`plaintext`}function ae({columns:e,onSelect:t,onClose:n}){let[r,i]=(0,D.useState)(``),[a,o]=(0,D.useState)(0),s=(0,D.useMemo)(()=>{if(!r)return e;let t=r.toLowerCase();return e.filter(e=>e.toLowerCase().includes(t))},[e,r]),c=(0,D.useRef)(null);return(0,D.useEffect)(()=>{c.current?.scrollIntoView({block:`nearest`})},[a]),(0,k.jsxs)(`div`,{className:`absolute top-full right-0 mt-1 z-50 w-52 max-h-56 bg-popover border border-border rounded-md shadow-lg overflow-hidden flex flex-col`,children:[(0,k.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>{i(e.target.value),o(0)},onKeyDown:e=>{e.key===`Escape`?n():e.key===`ArrowDown`?(e.preventDefault(),o(e=>Math.min(e+1,s.length-1))):e.key===`ArrowUp`?(e.preventDefault(),o(e=>Math.max(e-1,0))):e.key===`Enter`&&s[a]&&t(s[a])},placeholder:`Search columns…`,className:`px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border text-foreground placeholder:text-muted-foreground`}),(0,k.jsx)(`div`,{className:`overflow-auto flex-1`,children:s.map((e,n)=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>t(e),ref:n===a?c:void 0,className:`w-full text-left px-2 py-1 text-xs truncate ${n===a?`bg-primary/10 text-primary`:`text-foreground hover:bg-muted`}`,children:e},e))})]})}var oe=(0,D.memo)(function({row:e,rowIdx:t,columns:n,selected:r,onToggleSelect:i,pkCol:a,editingCell:o,editValue:s,onStartEdit:c,onCommitEdit:u,onCancelEdit:d,onSetEditValue:f,showDelete:m,confirmingDelete:h,onDelete:g,onConfirmDelete:v,onViewCell:y,onViewRow:b,pinned:x,onTogglePin:C,pinnedCols:w,pinnedColOffsets:T,stickyTop:E,trRef:D}){let O=x?`bg-muted`:r?`bg-primary/5`:`bg-background`;return(0,k.jsxs)(`tr`,{ref:D,className:`group ${x?``:`hover:bg-muted/30`}`,style:x?{position:`sticky`,top:E,zIndex:15}:void 0,children:[a&&(0,k.jsx)(`td`,{className:`px-2 py-1 border-b border-border/50 ${O}`,style:{position:`sticky`,left:0,zIndex:12},children:(0,k.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>i(t),className:`size-3 accent-primary`}),(0,k.jsx)(`button`,{type:`button`,title:`View row as JSON`,onClick:()=>b(e),className:`p-0.5 rounded transition-colors text-muted-foreground/30 md:opacity-0 md:group-hover:opacity-100 hover:text-foreground`,children:(0,k.jsx)(l,{className:`size-2.5`})}),(0,k.jsx)(`button`,{type:`button`,title:x?`Unpin row`:`Pin row`,onClick:()=>C(t),className:`p-0.5 rounded transition-colors ${x?`text-primary`:`text-muted-foreground/30 md:opacity-0 md:group-hover:opacity-100 hover:text-foreground`}`,children:x?(0,k.jsx)(S,{className:`size-2.5`}):(0,k.jsx)(_,{className:`size-2.5`})})]})}),n.map(n=>{let r=o?.rowIdx===t&&o?.col===n,i=e[n],p=!r&&P(i),m=w.has(n),h=T.get(n);return(0,k.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] border-b border-border/50 ${m?`border-r border-r-primary/20`:``} ${m||x?O:``}`,style:h==null?void 0:{position:`sticky`,left:h,zIndex:10},children:r?(0,k.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:s,onChange:e=>f(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u(),e.key===`Escape`&&d()}}):(0,k.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,k.jsx)(`span`,{className:`cursor-pointer truncate flex-1 ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>a&&c(t,n,i),title:M(i),children:M(i)}),p&&(0,k.jsx)(`button`,{type:`button`,title:`View full content`,onClick:()=>y({col:n,value:M(i)}),className:`shrink-0 p-0.5 rounded text-muted-foreground/50 hover:text-foreground transition-colors`,children:(0,k.jsx)(l,{className:`size-3`})})]})},n)}),m&&a&&(0,k.jsx)(`td`,{className:`px-2 py-1 border-b border-border/50 ${x?O:``}`,children:h?(0,k.jsxs)(`span`,{className:`flex items-center gap-1 whitespace-nowrap`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:()=>g(t),className:`text-destructive text-[10px] font-medium hover:underline`,children:`Confirm`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>v(null),className:`text-muted-foreground text-[10px] hover:underline`,children:`Cancel`})]}):(0,k.jsx)(`button`,{type:`button`,onClick:()=>v(t),className:`p-0.5 rounded md:opacity-0 md:group-hover:opacity-100 hover:bg-destructive/10 hover:text-destructive transition-opacity`,title:`Delete row`,children:(0,k.jsx)(p,{className:`size-3`})})})]})});function F(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 I({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.tableName,i=e?.schemaName??`public`,a=e?.initialSql,o=ne(t),[s,l]=(0,D.useState)([]),[u,d]=(0,D.useState)(180),p=(0,D.useRef)(null),[h,g]=(0,D.useState)({}),_=(0,D.useMemo)(()=>{if(a&&!o.selectedTable)return a;if(o.selectedTable){let e=`SELECT * FROM "${o.selectedTable}"`,t=Object.entries(h).filter(([,e])=>e.trim()).map(([e,t])=>`"${e}" ILIKE '%${t.replace(/'/g,`''`)}%'`);t.length>0&&(e+=` WHERE ${t.join(` AND `)}`),o.orderBy&&(e+=` ORDER BY "${o.orderBy}" ${o.orderDir}`);let n=(o.page-1)*100;return e+=` LIMIT 100`,n>0&&(e+=` OFFSET ${n}`),e}return`SELECT * FROM `},[a,o.selectedTable,o.orderBy,o.orderDir,o.page,h]),v=(0,D.useCallback)(e=>{g(e)},[]),b=(0,D.useRef)(void 0);(0,D.useEffect)(()=>{if(!(!o.selectedTable||Object.keys(h).length===0))return clearTimeout(b.current),b.current=setTimeout(()=>{o.queryAsTable(_)},500),()=>clearTimeout(b.current)},[h]);let x=(0,D.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=u,r=e=>{let r=e.clientY-t;d(Math.max(80,Math.min(n+r,(p.current?.clientHeight??600)-100)))},i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[u]);(0,D.useEffect)(()=>{m.get(`/api/db/connections/${t}/tables?cached=1`).then(e=>l(e.map(e=>({name:e.name,schema:e.schema})))).catch(()=>{})},[t]);let S=(0,D.useMemo)(()=>{if(s.length!==0)return{tables:s,getColumns:async(e,n)=>await m.get(`/api/db/connections/${t}/schema?table=${encodeURIComponent(e)}${n?`&schema=${encodeURIComponent(n)}`:``}`)}},[t,s]),w=(0,D.useRef)(!1);(0,D.useEffect)(()=>{w.current||(w.current=!0,a?o.executeQuery(a):r&&o.selectTable(r,i))},[r,i,a]);let[T,E]=(0,D.useState)(!!a),O=(0,D.useCallback)(e=>{let t=e.trim();if(o.selectedTable&&RegExp(`^SELECT\\s+\\*\\s+FROM\\s+"?${o.selectedTable.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}"?\\b`,`i`).test(t)){g(F(t)),o.queryAsTable(t);return}E(!0),o.executeQuery(e)},[o.executeQuery,o.queryAsTable,o.selectedTable]),ee=(0,D.useCallback)(e=>{E(!1),o.toggleSort(e)},[o.toggleSort]),te=(0,D.useCallback)(e=>{E(!1),o.setPage(e)},[o.setPage]),A=o.queryResult,M=T&&!!(A||o.queryError),N=o.selectedTable&&!M;return(0,k.jsx)(`div`,{ref:p,className:`flex h-full w-full overflow-hidden`,children:(0,k.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,k.jsx)(c,{className:`size-3.5 text-muted-foreground`}),(0,k.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,k.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,k.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[o.tableData&&(0,k.jsx)(re,{columns:o.tableData.columns,rows:o.tableData.rows,filename:n?`${n}-${o.selectedTable??`data`}`:o.selectedTable??`data`,exportAllUrl:o.selectedTable?`/api/db/connections/${t}/export?table=${encodeURIComponent(o.selectedTable)}&schema=${o.selectedSchema}`:void 0}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,k.jsx)(f,{className:`size-3 ${o.loading?`animate-spin`:``}`})})]})]}),(0,k.jsx)(`div`,{className:`shrink-0 border-b border-border`,style:{height:u},children:(0,k.jsx)(C,{onExecute:O,loading:o.queryLoading,defaultValue:_,schemaInfo:S})}),(0,k.jsx)(`div`,{onMouseDown:x,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,k.jsx)(y,{className:`size-3 text-muted-foreground/50`})}),(0,k.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[N&&(0,k.jsx)(j,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:te,onCellUpdate:o.updateCell,onRowDelete:o.deleteRow,orderBy:o.orderBy,orderDir:o.orderDir,onToggleSort:ee,onBulkDelete:o.bulkDelete,onInsertRow:o.insertRow,connectionId:t,selectedTable:o.selectedTable,selectedSchema:o.selectedSchema,connectionName:n,columnFilters:h,onColumnFilter:v}),M&&(0,k.jsx)(R,{result:A,error:o.queryError,loading:o.queryLoading,schema:o.schema,connectionName:n})]})]})})}var L=()=>{};function R({result:e,error:t,loading:n,schema:r,connectionName:i}){let a=(0,D.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),o=(0,D.useMemo)(()=>r?.length?r:(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[r,e?.columns]);return(0,k.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden text-xs`,children:[t&&(0,k.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5 shrink-0`,children:t}),e?.changeType===`modify`&&(0,k.jsxs)(`div`,{className:`px-3 py-2 text-green-500 shrink-0`,children:[e.rowsAffected,` row(s) affected`,e.executionTimeMs!=null&&(0,k.jsxs)(`span`,{className:`text-muted-foreground ml-2`,children:[e.executionTimeMs,`ms`]})]}),a&&(0,k.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,k.jsx)(j,{tableData:a,schema:o,loading:!!n,page:1,onPageChange:L,onCellUpdate:L,orderBy:null,orderDir:`ASC`,onToggleSort:L,connectionName:i}),e?.executionTimeMs!=null&&(0,k.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,k.jsxs)(`div`,{className:`px-3 py-2 text-muted-foreground shrink-0`,children:[`No results`,e.executionTimeMs!=null&&(0,k.jsxs)(`span`,{className:`ml-2 text-muted-foreground/60`,children:[e.executionTimeMs,`ms`]})]}),!e&&!t&&(0,k.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground`,children:n?(0,k.jsx)(v,{className:`size-4 animate-spin`}):`Run a query to see results`})]})}export{I as DatabaseViewer};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{t as r}from"./createLucideIcon-BjHrJDVb.js";import{t as i}from"./text-wrap-DzvCTq_i.js";import{i as a,t as o}from"./api-client-r4nyVy7H.js";import{n as s}from"./settings-store-CdcSAgEZ.js";import"./vendor-mermaid-DCxaaPi4.js";import{$ as c,B as l,U as u,Y as d,h as f}from"./index-C7gvr4Xo.js";import{r as p,t as m}from"./use-monaco-theme-dtPsv6sh.js";var h=r(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),g=e(n(),1),_=t();function v(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function y({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,y=e?.ref2,x=e?.file1,S=e?.file2,C=e?.original,w=e?.modified,T=C!=null||w!=null,E=!!(x&&S),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(null),[j,M]=(0,g.useState)(null),[N,P]=(0,g.useState)(!T),[F,I]=(0,g.useState)(null),[L,R]=(0,g.useState)(`both`),{wordWrap:z,toggleWordWrap:B}=s(f(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),V=m(),H=(0,g.useRef)(null),[U,W]=(0,g.useState)();(0,g.useEffect)(()=>{let e=H.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&W(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[N,F]),(0,g.useEffect)(()=>{if(T||!n)return;if(P(!0),I(null),M(null),A(null),O(null),x&&S){let e=new URLSearchParams({file1:x,file2:S});o.get(`${a(n)}/files/compare?${e}`).then(e=>{A(e),P(!1)}).catch(e=>{I(e instanceof Error?e.message:`Failed to compare files`),P(!1)});return}if(t){let e=new URLSearchParams({file:t});r&&e.set(`ref`,r),o.get(`${a(n)}/git/file-full-diff?${e}`).then(e=>{M(e),P(!1)}).catch(e=>{I(e instanceof Error?e.message:`Failed to load diff`),P(!1)});return}let e;if(r||y){let t=new URLSearchParams;r&&t.set(`ref1`,r),y&&t.set(`ref2`,y),e=`${a(n)}/git/diff?${t}`}else e=`${a(n)}/git/diff`;o.get(e).then(e=>{O(e.diff),P(!1)}).catch(e=>{I(e instanceof Error?e.message:`Failed to load diff`),P(!1)})},[t,n,r,y,x,S,T]);let{original:G,modified:K}=(0,g.useMemo)(()=>T?{original:C??``,modified:w??``}:E&&k?k:j||(D?b(D):{original:``,modified:``}),[D,T,C,w,E,k,j]),q=(0,g.useMemo)(()=>{let e=t??S??x;return e?v(e):`plaintext`},[t,x,S]),J=typeof window<`u`&&window.innerWidth<768,Y=!J&&L===`both`;return!n&&!T?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):N?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,_.jsx)(u,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):F?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:F}):!T&&!E&&!j&&!G&&!K?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,_.jsx)(d,{className:`size-8`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,_.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!J&&(0,_.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,_.jsx)(`button`,{type:`button`,onClick:()=>R(L===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${L===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,_.jsx)(l,{className:`size-3.5`})}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>R(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${L===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,_.jsx)(c,{className:`size-3.5`})}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>R(L===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${L===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,_.jsx)(h,{className:`size-3.5`})}),(0,_.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,_.jsx)(`button`,{type:`button`,onClick:B,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${z?`bg-muted text-foreground`:``}`,children:(0,_.jsx)(i,{className:`size-3.5`})})]}),(0,_.jsx)(`div`,{ref:H,className:`flex-1 overflow-hidden`,children:U&&U>0?(0,_.jsx)(p,{height:U,language:q,original:G,modified:K,theme:V,options:{fontSize:J?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:J||z?`on`:`off`,renderSideBySide:Y,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,_.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(u,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function b(e){let t=e.split(`
|
|
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
|
-
`),modified:r.join(`
|
|
4
|
-
`)}}export{y as DiffViewer};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{H as e}from"./vendor-mermaid-DCxaaPi4.js";export{e as createGitGraphServices};
|