dbdiff-app 0.1.0
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/README.md +73 -0
- package/bin/cli.js +83 -0
- package/bin/install-local.js +57 -0
- package/electron/generate-icon.mjs +54 -0
- package/electron/icon.icns +0 -0
- package/electron/icon.png +0 -0
- package/electron/icon.svg +21 -0
- package/electron/main.js +169 -0
- package/electron/patch-dev-plist.js +31 -0
- package/electron/preload.cjs +18 -0
- package/electron/wait-for-vite.js +43 -0
- package/index.html +13 -0
- package/package.json +91 -0
- package/public/favicon.svg +15 -0
- package/public/vite.svg +1 -0
- package/server/export.ts +57 -0
- package/server/index.ts +392 -0
- package/src/App.css +1 -0
- package/src/App.tsx +543 -0
- package/src/assets/react.svg +1 -0
- package/src/components/CommandPalette.tsx +243 -0
- package/src/components/ConnectedView.tsx +78 -0
- package/src/components/ConnectionPicker.tsx +381 -0
- package/src/components/ConsoleView.tsx +360 -0
- package/src/components/CsvExportModal.tsx +144 -0
- package/src/components/DataGrid/DataGrid.tsx +262 -0
- package/src/components/DataGrid/DataGridCell.tsx +73 -0
- package/src/components/DataGrid/DataGridHeader.tsx +89 -0
- package/src/components/DataGrid/index.ts +20 -0
- package/src/components/DataGrid/types.ts +63 -0
- package/src/components/DataGrid/useColumnResize.ts +153 -0
- package/src/components/DataGrid/useDataGridSelection.ts +340 -0
- package/src/components/DataGrid/utils.ts +184 -0
- package/src/components/DatabaseMenu.tsx +93 -0
- package/src/components/DatabaseSwitcher.tsx +208 -0
- package/src/components/DiffView.tsx +215 -0
- package/src/components/EditConnectionModal.tsx +417 -0
- package/src/components/ErrorBoundary.tsx +69 -0
- package/src/components/GlobalShortcuts.tsx +201 -0
- package/src/components/InnerTabBar.tsx +129 -0
- package/src/components/JsonTreeViewer.tsx +387 -0
- package/src/components/MemberAccessEditor.tsx +443 -0
- package/src/components/MembersModal.tsx +446 -0
- package/src/components/NewConnectionModal.tsx +274 -0
- package/src/components/Resizer.tsx +66 -0
- package/src/components/ScanSuccessModal.tsx +113 -0
- package/src/components/ShortcutSettingsModal.tsx +318 -0
- package/src/components/Sidebar.tsx +532 -0
- package/src/components/TabBar.tsx +188 -0
- package/src/components/TableView.tsx +2147 -0
- package/src/components/ThemeToggle.tsx +44 -0
- package/src/components/index.ts +17 -0
- package/src/constants.ts +12 -0
- package/src/electron.d.ts +12 -0
- package/src/index.css +44 -0
- package/src/main.tsx +13 -0
- package/src/stores/hooks.ts +1146 -0
- package/src/stores/index.ts +12 -0
- package/src/stores/store.ts +1514 -0
- package/src/stores/useCloudSync.ts +274 -0
- package/src/stores/useSyncDatabase.ts +422 -0
- package/src/types.ts +277 -0
- package/src/utils/csv.ts +27 -0
- package/src/vite-env.d.ts +2 -0
- package/tsconfig.app.json +28 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +26 -0
- package/tsconfig.server.json +14 -0
- package/vite.config.ts +14 -0
package/src/App.tsx
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState, useRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
useStore,
|
|
4
|
+
useActiveDatabaseConfig,
|
|
5
|
+
useOpenTableTab,
|
|
6
|
+
useNewConsoleTab,
|
|
7
|
+
useSyncDatabase,
|
|
8
|
+
useCloudSync,
|
|
9
|
+
} from "./stores";
|
|
10
|
+
|
|
11
|
+
import { CLOUD_URL, LOCALHOST_SCANNING_ENABLED } from "./constants";
|
|
12
|
+
import {
|
|
13
|
+
TabBar,
|
|
14
|
+
InnerTabBar,
|
|
15
|
+
Sidebar,
|
|
16
|
+
ConnectionPicker,
|
|
17
|
+
ConnectedView,
|
|
18
|
+
NewConnectionModal,
|
|
19
|
+
EditConnectionModal,
|
|
20
|
+
MembersModal,
|
|
21
|
+
ShortcutSettingsModal,
|
|
22
|
+
Resizer,
|
|
23
|
+
GlobalShortcuts,
|
|
24
|
+
CommandPalette,
|
|
25
|
+
DatabaseSwitcher,
|
|
26
|
+
ScanSuccessModal,
|
|
27
|
+
} from "./components";
|
|
28
|
+
import type {
|
|
29
|
+
DatabaseConfig,
|
|
30
|
+
ScanLocalhostResponse,
|
|
31
|
+
ExportType,
|
|
32
|
+
} from "./types";
|
|
33
|
+
import "./App.css";
|
|
34
|
+
|
|
35
|
+
const isElectronMac =
|
|
36
|
+
navigator.userAgent.includes("Electron") &&
|
|
37
|
+
navigator.userAgent.includes("Macintosh");
|
|
38
|
+
|
|
39
|
+
function App() {
|
|
40
|
+
const connectionTabs = useStore((s) => s.connectionTabs);
|
|
41
|
+
const activeTabId = useStore((s) => s.activeTabId);
|
|
42
|
+
const draggedTabId = useStore((s) => s.draggedTabId);
|
|
43
|
+
const draggedInnerTabId = useStore((s) => s.draggedInnerTabId);
|
|
44
|
+
const databaseConfigs = useStore((s) => s.databaseConfigs);
|
|
45
|
+
const darkMode = useStore((s) => s.darkMode);
|
|
46
|
+
const cloudApiKey = useStore((s) => s.cloudApiKey);
|
|
47
|
+
const setCloudApiKey = useStore((s) => s.setCloudApiKey);
|
|
48
|
+
const clearCloudApiKey = useStore((s) => s.clearCloudApiKey);
|
|
49
|
+
|
|
50
|
+
const createConnectionTab = useStore((s) => s.createConnectionTab);
|
|
51
|
+
const closeConnectionTab = useStore((s) => s.closeConnectionTab);
|
|
52
|
+
const selectConnectionTab = useStore((s) => s.selectConnectionTab);
|
|
53
|
+
const connectToDatabase = useStore((s) => s.connectToDatabase);
|
|
54
|
+
const reorderConnectionTabs = useStore((s) => s.reorderConnectionTabs);
|
|
55
|
+
const setDraggedTabId = useStore((s) => s.setDraggedTabId);
|
|
56
|
+
const setDraggedInnerTabId = useStore((s) => s.setDraggedInnerTabId);
|
|
57
|
+
const selectInnerTab = useStore((s) => s.selectInnerTab);
|
|
58
|
+
const closeInnerTab = useStore((s) => s.closeInnerTab);
|
|
59
|
+
const reorderInnerTabs = useStore((s) => s.reorderInnerTabs);
|
|
60
|
+
const toggleDarkMode = useStore((s) => s.toggleDarkMode);
|
|
61
|
+
const resetUIState = useStore((s) => s.resetUIState);
|
|
62
|
+
const addConfig = useStore((s) => s.addConfig);
|
|
63
|
+
const updateConfig = useStore((s) => s.updateConfig);
|
|
64
|
+
const deleteConfig = useStore((s) => s.deleteConfig);
|
|
65
|
+
|
|
66
|
+
const [showNewConnectionModal, setShowNewConnectionModal] = useState(false);
|
|
67
|
+
const [editingConfig, setEditingConfig] = useState<DatabaseConfig | null>(
|
|
68
|
+
null,
|
|
69
|
+
);
|
|
70
|
+
const [managingMembersConfig, setManagingMembersConfig] =
|
|
71
|
+
useState<DatabaseConfig | null>(null);
|
|
72
|
+
const [sidebarWidth, setSidebarWidth] = useState(220);
|
|
73
|
+
const [showShortcutSettings, setShowShortcutSettings] = useState(false);
|
|
74
|
+
const [isScanning, setIsScanning] = useState(false);
|
|
75
|
+
const [showCommandPalette, setShowCommandPalette] = useState(false);
|
|
76
|
+
const [showDatabaseSwitcher, setShowDatabaseSwitcher] = useState(false);
|
|
77
|
+
const [scanResultCount, setScanResultCount] = useState<number | null>(null);
|
|
78
|
+
|
|
79
|
+
const handleSidebarResize = useCallback((delta: number) => {
|
|
80
|
+
setSidebarWidth((w) => Math.max(150, Math.min(w + delta, 500)));
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const activeDatabaseConfig = useActiveDatabaseConfig();
|
|
84
|
+
const openTableTab = useOpenTableTab();
|
|
85
|
+
const newConsoleTab = useNewConsoleTab();
|
|
86
|
+
const { sync: syncDatabase, isSyncing } = useSyncDatabase(
|
|
87
|
+
activeDatabaseConfig?.id,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Auto-sync schema on first connection (when cache is empty)
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (
|
|
93
|
+
activeDatabaseConfig &&
|
|
94
|
+
!activeDatabaseConfig.cache.schemas?.length &&
|
|
95
|
+
!isSyncing
|
|
96
|
+
) {
|
|
97
|
+
syncDatabase();
|
|
98
|
+
}
|
|
99
|
+
}, [activeDatabaseConfig?.id]);
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
sync: syncCloud,
|
|
103
|
+
isSyncing: isCloudSyncing,
|
|
104
|
+
error: cloudSyncError,
|
|
105
|
+
transferToCloud,
|
|
106
|
+
transferringId,
|
|
107
|
+
updateCloudConnection,
|
|
108
|
+
isUpdating: isCloudUpdating,
|
|
109
|
+
updateError: cloudUpdateError,
|
|
110
|
+
deleteCloudConnection,
|
|
111
|
+
isDeleting: isCloudDeleting,
|
|
112
|
+
deleteError: cloudDeleteError,
|
|
113
|
+
} = useCloudSync();
|
|
114
|
+
|
|
115
|
+
const activeTab = connectionTabs.find((t) => t.id === activeTabId);
|
|
116
|
+
const activeInnerTab = activeTab?.activeInnerTabId
|
|
117
|
+
? activeTab.innerTabs.find((t) => t.id === activeTab.activeInnerTabId)
|
|
118
|
+
: null;
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
document.documentElement.classList.toggle("dark", darkMode);
|
|
122
|
+
}, [darkMode]);
|
|
123
|
+
|
|
124
|
+
// Handle cloud API key from URL query param (after redirect from cloud.dbdiff.app)
|
|
125
|
+
// This path is used in the browser; in Electron the IPC callback below handles it.
|
|
126
|
+
const hasProcessedCloudKey = useRef(false);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (hasProcessedCloudKey.current) return;
|
|
129
|
+
|
|
130
|
+
const params = new URLSearchParams(window.location.search);
|
|
131
|
+
const key = params.get("key");
|
|
132
|
+
const state = params.get("state");
|
|
133
|
+
|
|
134
|
+
if (key && state) {
|
|
135
|
+
hasProcessedCloudKey.current = true;
|
|
136
|
+
|
|
137
|
+
// Verify state matches what we stored (CSRF protection)
|
|
138
|
+
const expectedState = sessionStorage.getItem("cloud_link_state");
|
|
139
|
+
if (state === expectedState) {
|
|
140
|
+
setCloudApiKey(key);
|
|
141
|
+
sessionStorage.removeItem("cloud_link_state");
|
|
142
|
+
} else {
|
|
143
|
+
console.warn("Cloud link state mismatch - ignoring key");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Clear the query params from URL
|
|
147
|
+
window.history.replaceState(null, "", window.location.pathname);
|
|
148
|
+
}
|
|
149
|
+
}, [setCloudApiKey]);
|
|
150
|
+
|
|
151
|
+
// In Electron, the main process intercepts the auth popup redirect and sends
|
|
152
|
+
// the key+state via IPC, so the main window updates without a manual refresh.
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!window.electronAPI?.onCloudAuthCallback) return;
|
|
155
|
+
return window.electronAPI.onCloudAuthCallback(({ key, state }) => {
|
|
156
|
+
const expectedState = sessionStorage.getItem("cloud_link_state");
|
|
157
|
+
if (state === expectedState) {
|
|
158
|
+
setCloudApiKey(key);
|
|
159
|
+
sessionStorage.removeItem("cloud_link_state");
|
|
160
|
+
} else {
|
|
161
|
+
console.warn("Cloud link state mismatch - ignoring key");
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}, [setCloudApiKey]);
|
|
165
|
+
|
|
166
|
+
// Auto-scan localhost on mount when there are no database configs
|
|
167
|
+
const hasAutoScanned = useRef(false);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (
|
|
170
|
+
LOCALHOST_SCANNING_ENABLED &&
|
|
171
|
+
databaseConfigs.length === 0 &&
|
|
172
|
+
!hasAutoScanned.current
|
|
173
|
+
) {
|
|
174
|
+
hasAutoScanned.current = true;
|
|
175
|
+
handleScanLocalhost();
|
|
176
|
+
}
|
|
177
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
|
+
}, []);
|
|
179
|
+
|
|
180
|
+
// Sync cloud connections on mount and when cloudApiKey changes
|
|
181
|
+
const hasSyncedOnMount = useRef(false);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (cloudApiKey && !hasSyncedOnMount.current) {
|
|
184
|
+
hasSyncedOnMount.current = true;
|
|
185
|
+
syncCloud();
|
|
186
|
+
}
|
|
187
|
+
// Reset the flag if cloudApiKey is cleared
|
|
188
|
+
if (!cloudApiKey) {
|
|
189
|
+
hasSyncedOnMount.current = false;
|
|
190
|
+
}
|
|
191
|
+
}, [cloudApiKey, syncCloud]);
|
|
192
|
+
|
|
193
|
+
// --- Electron native menu bridge (macOS only) ---
|
|
194
|
+
async function handleExportFromMenu(exportType: ExportType) {
|
|
195
|
+
if (!activeDatabaseConfig) return;
|
|
196
|
+
try {
|
|
197
|
+
const res = await fetch("/api/export", {
|
|
198
|
+
method: "POST",
|
|
199
|
+
headers: { "Content-Type": "application/json" },
|
|
200
|
+
body: JSON.stringify({
|
|
201
|
+
connection: activeDatabaseConfig.connection,
|
|
202
|
+
exportType,
|
|
203
|
+
}),
|
|
204
|
+
});
|
|
205
|
+
if (!res.ok) return;
|
|
206
|
+
const blob = await res.blob();
|
|
207
|
+
const disposition = res.headers.get("Content-Disposition") ?? "";
|
|
208
|
+
const match = disposition.match(/filename="(.+)"/);
|
|
209
|
+
const filename =
|
|
210
|
+
match?.[1] ?? `${activeDatabaseConfig.connection.database}.sql`;
|
|
211
|
+
const url = URL.createObjectURL(blob);
|
|
212
|
+
const a = document.createElement("a");
|
|
213
|
+
a.href = url;
|
|
214
|
+
a.download = filename;
|
|
215
|
+
document.body.appendChild(a);
|
|
216
|
+
a.click();
|
|
217
|
+
a.remove();
|
|
218
|
+
URL.revokeObjectURL(url);
|
|
219
|
+
} catch {
|
|
220
|
+
// silently fail
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Use a ref so the IPC listener always calls the latest handlers
|
|
225
|
+
const menuHandlersRef = useRef<Record<string, () => void>>({});
|
|
226
|
+
menuHandlersRef.current = {
|
|
227
|
+
"shortcut-settings": () => setShowShortcutSettings(true),
|
|
228
|
+
"scan-localhost": () => {
|
|
229
|
+
if (LOCALHOST_SCANNING_ENABLED) handleScanLocalhost();
|
|
230
|
+
},
|
|
231
|
+
"reset-ui-state": resetUIState,
|
|
232
|
+
"export-schema": () => handleExportFromMenu("schema"),
|
|
233
|
+
"export-schema-and-data": () => handleExportFromMenu("schema-and-data"),
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
useEffect(() => {
|
|
237
|
+
if (!window.electronAPI) return;
|
|
238
|
+
return window.electronAPI.onMenuAction((action) => {
|
|
239
|
+
menuHandlersRef.current[action]?.();
|
|
240
|
+
});
|
|
241
|
+
}, []);
|
|
242
|
+
|
|
243
|
+
// Keep native Database menu enabled state in sync
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
window.electronAPI?.setDatabaseMenuEnabled(!!activeDatabaseConfig);
|
|
246
|
+
}, [activeDatabaseConfig]);
|
|
247
|
+
|
|
248
|
+
function handleDragStart(e: React.DragEvent, tabId: string) {
|
|
249
|
+
setDraggedTabId(tabId);
|
|
250
|
+
e.dataTransfer.effectAllowed = "move";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function handleDragOver(e: React.DragEvent, tabId: string) {
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
if (!draggedTabId || draggedTabId === tabId) return;
|
|
256
|
+
|
|
257
|
+
const draggedIndex = connectionTabs.findIndex((t) => t.id === draggedTabId);
|
|
258
|
+
const targetIndex = connectionTabs.findIndex((t) => t.id === tabId);
|
|
259
|
+
if (draggedIndex === targetIndex) return;
|
|
260
|
+
|
|
261
|
+
reorderConnectionTabs(draggedIndex, targetIndex);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function handleDragEnd() {
|
|
265
|
+
setDraggedTabId(null);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function handleInnerDragStart(e: React.DragEvent, tabId: string) {
|
|
269
|
+
setDraggedInnerTabId(tabId);
|
|
270
|
+
e.dataTransfer.effectAllowed = "move";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function handleInnerDragOver(e: React.DragEvent, tabId: string) {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
if (!draggedInnerTabId || draggedInnerTabId === tabId || !activeTab) return;
|
|
276
|
+
|
|
277
|
+
const draggedIndex = activeTab.innerTabs.findIndex(
|
|
278
|
+
(t) => t.id === draggedInnerTabId,
|
|
279
|
+
);
|
|
280
|
+
const targetIndex = activeTab.innerTabs.findIndex((t) => t.id === tabId);
|
|
281
|
+
if (
|
|
282
|
+
draggedIndex === -1 ||
|
|
283
|
+
targetIndex === -1 ||
|
|
284
|
+
draggedIndex === targetIndex
|
|
285
|
+
)
|
|
286
|
+
return;
|
|
287
|
+
|
|
288
|
+
reorderInnerTabs(draggedIndex, targetIndex);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function handleInnerDragEnd() {
|
|
292
|
+
setDraggedInnerTabId(null);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function handleAddNewConnection() {
|
|
296
|
+
setShowNewConnectionModal(true);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function handleSaveNewConnection(config: DatabaseConfig) {
|
|
300
|
+
addConfig(config);
|
|
301
|
+
setShowNewConnectionModal(false);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function handleEditConnection(config: DatabaseConfig) {
|
|
305
|
+
setEditingConfig(config);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function handleManageMembers(config: DatabaseConfig) {
|
|
309
|
+
setManagingMembersConfig(config);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function handleSaveEditedConnection(config: DatabaseConfig) {
|
|
313
|
+
if (config.source === "cloud") {
|
|
314
|
+
const result = await updateCloudConnection(config);
|
|
315
|
+
if (!result.success) return; // don't close modal on error
|
|
316
|
+
}
|
|
317
|
+
updateConfig(config.id, config);
|
|
318
|
+
setEditingConfig(null);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function handleDeleteConnection(id: string) {
|
|
322
|
+
// If it's a cloud connection, delete from cloud first
|
|
323
|
+
if (editingConfig?.source === "cloud" && editingConfig.cloud?.id) {
|
|
324
|
+
const result = await deleteCloudConnection(editingConfig.cloud.id);
|
|
325
|
+
if (!result.success) return; // don't close modal on error
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Close any tabs using this connection
|
|
329
|
+
connectionTabs
|
|
330
|
+
.filter((tab) => tab.databaseConfigId === id)
|
|
331
|
+
.forEach((tab) => closeConnectionTab(tab.id));
|
|
332
|
+
deleteConfig(id);
|
|
333
|
+
setEditingConfig(null);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const SCAN_COLORS = [
|
|
337
|
+
"#ef4444",
|
|
338
|
+
"#f59e0b",
|
|
339
|
+
"#22c55e",
|
|
340
|
+
"#3b82f6",
|
|
341
|
+
"#8b5cf6",
|
|
342
|
+
"#ec4899",
|
|
343
|
+
"#14b8a6",
|
|
344
|
+
"#f97316",
|
|
345
|
+
];
|
|
346
|
+
|
|
347
|
+
async function handleScanLocalhost() {
|
|
348
|
+
setIsScanning(true);
|
|
349
|
+
try {
|
|
350
|
+
const res = await fetch("/api/scan-localhost");
|
|
351
|
+
const data: ScanLocalhostResponse = await res.json();
|
|
352
|
+
const existing = new Set(
|
|
353
|
+
databaseConfigs.map(
|
|
354
|
+
(c) =>
|
|
355
|
+
`${c.connection.host}:${c.connection.port}:${c.connection.database}:${c.connection.username}`,
|
|
356
|
+
),
|
|
357
|
+
);
|
|
358
|
+
let added = 0;
|
|
359
|
+
data.databases.forEach((db, i) => {
|
|
360
|
+
const key = `${db.host}:${db.port}:${db.database}:${db.username}`;
|
|
361
|
+
if (!existing.has(key)) {
|
|
362
|
+
existing.add(key);
|
|
363
|
+
addConfig({
|
|
364
|
+
id: (Date.now() + i).toString(),
|
|
365
|
+
display: {
|
|
366
|
+
name: `${db.database} (localhost)`,
|
|
367
|
+
color: SCAN_COLORS[added % SCAN_COLORS.length],
|
|
368
|
+
},
|
|
369
|
+
connection: {
|
|
370
|
+
type: "postgres",
|
|
371
|
+
host: db.host,
|
|
372
|
+
port: db.port,
|
|
373
|
+
database: db.database,
|
|
374
|
+
username: db.username,
|
|
375
|
+
password: db.password,
|
|
376
|
+
},
|
|
377
|
+
cache: {},
|
|
378
|
+
source: "local",
|
|
379
|
+
});
|
|
380
|
+
added++;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
if (added > 0) {
|
|
384
|
+
setScanResultCount(added);
|
|
385
|
+
}
|
|
386
|
+
} catch {
|
|
387
|
+
// silently fail — nothing running on 5432
|
|
388
|
+
} finally {
|
|
389
|
+
setIsScanning(false);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function handleLinkCloud() {
|
|
394
|
+
// Generate random state for CSRF protection
|
|
395
|
+
const state = crypto.randomUUID();
|
|
396
|
+
sessionStorage.setItem("cloud_link_state", state);
|
|
397
|
+
|
|
398
|
+
const redirectUrl = `${window.location.origin}?state=${state}`;
|
|
399
|
+
const linkUrl = `${CLOUD_URL}/link?redirect=${encodeURIComponent(redirectUrl)}`;
|
|
400
|
+
window.open(linkUrl, "_blank");
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return (
|
|
404
|
+
<div className="flex flex-col h-screen bg-stone-50 dark:bg-[#0a0a0a] text-primary antialiased transition-colors duration-200">
|
|
405
|
+
<GlobalShortcuts
|
|
406
|
+
onOpenTableSwitcher={() => setShowCommandPalette(true)}
|
|
407
|
+
onOpenDatabaseSwitcher={() => setShowDatabaseSwitcher(true)}
|
|
408
|
+
/>
|
|
409
|
+
<TabBar
|
|
410
|
+
tabs={connectionTabs}
|
|
411
|
+
activeTabId={activeTabId}
|
|
412
|
+
draggedTabId={draggedTabId}
|
|
413
|
+
databaseConfigs={databaseConfigs}
|
|
414
|
+
darkMode={darkMode}
|
|
415
|
+
onTabSelect={selectConnectionTab}
|
|
416
|
+
onTabClose={closeConnectionTab}
|
|
417
|
+
onNewTab={createConnectionTab}
|
|
418
|
+
onDragStart={handleDragStart}
|
|
419
|
+
onDragOver={handleDragOver}
|
|
420
|
+
onDragEnd={handleDragEnd}
|
|
421
|
+
onThemeToggle={toggleDarkMode}
|
|
422
|
+
onOpenShortcutSettings={() => setShowShortcutSettings(true)}
|
|
423
|
+
onScanLocalhost={
|
|
424
|
+
LOCALHOST_SCANNING_ENABLED ? handleScanLocalhost : undefined
|
|
425
|
+
}
|
|
426
|
+
isScanning={isScanning}
|
|
427
|
+
onResetUIState={resetUIState}
|
|
428
|
+
activeDatabaseConfig={activeDatabaseConfig}
|
|
429
|
+
hideMenus={isElectronMac}
|
|
430
|
+
/>
|
|
431
|
+
|
|
432
|
+
{activeTab?.databaseConfigId && (
|
|
433
|
+
<InnerTabBar
|
|
434
|
+
innerTabs={activeTab.innerTabs}
|
|
435
|
+
activeInnerTabId={activeTab.activeInnerTabId}
|
|
436
|
+
draggedInnerTabId={draggedInnerTabId}
|
|
437
|
+
onTabSelect={selectInnerTab}
|
|
438
|
+
onTabClose={closeInnerTab}
|
|
439
|
+
onNewConsole={newConsoleTab}
|
|
440
|
+
onDragStart={handleInnerDragStart}
|
|
441
|
+
onDragOver={handleInnerDragOver}
|
|
442
|
+
onDragEnd={handleInnerDragEnd}
|
|
443
|
+
/>
|
|
444
|
+
)}
|
|
445
|
+
|
|
446
|
+
<div className="flex flex-1 overflow-hidden">
|
|
447
|
+
{activeTab?.databaseConfigId && (
|
|
448
|
+
<>
|
|
449
|
+
<Sidebar
|
|
450
|
+
schemas={activeDatabaseConfig?.cache.schemas ?? []}
|
|
451
|
+
databaseConfig={activeDatabaseConfig ?? null}
|
|
452
|
+
onTableClick={openTableTab}
|
|
453
|
+
onTableOpenNewTab={(tableName) =>
|
|
454
|
+
openTableTab(tableName, { forceNew: true })
|
|
455
|
+
}
|
|
456
|
+
onRefresh={syncDatabase}
|
|
457
|
+
isRefreshing={isSyncing}
|
|
458
|
+
width={sidebarWidth}
|
|
459
|
+
activeTableName={
|
|
460
|
+
activeInnerTab?.type === "table" ? activeInnerTab.name : null
|
|
461
|
+
}
|
|
462
|
+
/>
|
|
463
|
+
<Resizer direction="horizontal" onResize={handleSidebarResize} />
|
|
464
|
+
</>
|
|
465
|
+
)}
|
|
466
|
+
|
|
467
|
+
<div className="flex-1 overflow-auto bg-white dark:bg-[#0f0f0f]">
|
|
468
|
+
{activeTab?.databaseConfigId ? (
|
|
469
|
+
<ConnectedView
|
|
470
|
+
name={activeTab.name}
|
|
471
|
+
databaseConfig={activeDatabaseConfig ?? null}
|
|
472
|
+
activeInnerTab={activeInnerTab ?? null}
|
|
473
|
+
/>
|
|
474
|
+
) : (
|
|
475
|
+
<ConnectionPicker
|
|
476
|
+
databaseConfigs={databaseConfigs}
|
|
477
|
+
onConnect={connectToDatabase}
|
|
478
|
+
onAddNew={handleAddNewConnection}
|
|
479
|
+
onEdit={handleEditConnection}
|
|
480
|
+
cloudApiKey={cloudApiKey}
|
|
481
|
+
onLinkCloud={handleLinkCloud}
|
|
482
|
+
onUnlinkCloud={clearCloudApiKey}
|
|
483
|
+
onRefreshCloud={syncCloud}
|
|
484
|
+
isCloudSyncing={isCloudSyncing}
|
|
485
|
+
cloudSyncError={cloudSyncError}
|
|
486
|
+
onTransferToCloud={transferToCloud}
|
|
487
|
+
transferringId={transferringId}
|
|
488
|
+
onManageMembers={handleManageMembers}
|
|
489
|
+
/>
|
|
490
|
+
)}
|
|
491
|
+
</div>
|
|
492
|
+
</div>
|
|
493
|
+
|
|
494
|
+
{showNewConnectionModal && (
|
|
495
|
+
<NewConnectionModal
|
|
496
|
+
onClose={() => setShowNewConnectionModal(false)}
|
|
497
|
+
onSave={handleSaveNewConnection}
|
|
498
|
+
/>
|
|
499
|
+
)}
|
|
500
|
+
|
|
501
|
+
{editingConfig && (
|
|
502
|
+
<EditConnectionModal
|
|
503
|
+
config={editingConfig}
|
|
504
|
+
onClose={() => setEditingConfig(null)}
|
|
505
|
+
onSave={handleSaveEditedConnection}
|
|
506
|
+
onDelete={handleDeleteConnection}
|
|
507
|
+
isSaving={isCloudUpdating}
|
|
508
|
+
saveError={cloudUpdateError}
|
|
509
|
+
isDeleting={isCloudDeleting}
|
|
510
|
+
deleteError={cloudDeleteError}
|
|
511
|
+
/>
|
|
512
|
+
)}
|
|
513
|
+
|
|
514
|
+
{managingMembersConfig && (
|
|
515
|
+
<MembersModal
|
|
516
|
+
config={managingMembersConfig}
|
|
517
|
+
onClose={() => setManagingMembersConfig(null)}
|
|
518
|
+
/>
|
|
519
|
+
)}
|
|
520
|
+
|
|
521
|
+
{showShortcutSettings && (
|
|
522
|
+
<ShortcutSettingsModal onClose={() => setShowShortcutSettings(false)} />
|
|
523
|
+
)}
|
|
524
|
+
|
|
525
|
+
{showCommandPalette && activeTab?.databaseConfigId && (
|
|
526
|
+
<CommandPalette onClose={() => setShowCommandPalette(false)} />
|
|
527
|
+
)}
|
|
528
|
+
|
|
529
|
+
{showDatabaseSwitcher && (
|
|
530
|
+
<DatabaseSwitcher onClose={() => setShowDatabaseSwitcher(false)} />
|
|
531
|
+
)}
|
|
532
|
+
|
|
533
|
+
{scanResultCount !== null && (
|
|
534
|
+
<ScanSuccessModal
|
|
535
|
+
count={scanResultCount}
|
|
536
|
+
onClose={() => setScanResultCount(null)}
|
|
537
|
+
/>
|
|
538
|
+
)}
|
|
539
|
+
</div>
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|