|
| 1 | +import { DatabaseStudio } from "./components/DatabaseStudio.tsx"; |
| 2 | +import { TableDetail, type TableRow } from "./components/TableDetail.tsx"; |
| 3 | + |
| 4 | +export type AppProps = { |
| 5 | + title: string; |
| 6 | + children: any; |
| 7 | +} |
| 8 | + |
| 9 | +export function App({ title, children }: AppProps) { |
| 10 | + return ( |
| 11 | + <html lang="en"> |
| 12 | + <head> |
| 13 | + <meta charSet="UTF-8" /> |
| 14 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 15 | + <title>{title}</title> |
| 16 | + <style>{` |
| 17 | + * { margin: 0; padding: 0; box-sizing: border-box; } |
| 18 | + :root { |
| 19 | + --bg-dark: #0f0f0f; --bg-sidebar: #1a1a1a; --bg-main: #0f0f0f; |
| 20 | + --bg-hover: #252525; --text-primary: #e5e7eb; --text-muted: #9ca3af; |
| 21 | + --border-color: #2a2a2a; --accent: #404040; |
| 22 | + } |
| 23 | + body { |
| 24 | + font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif; |
| 25 | + background: var(--bg-main); min-height: 100vh; color: var(--text-primary); |
| 26 | + line-height: 1.6; overflow: hidden; |
| 27 | + } |
| 28 | + .app-layout { display: flex; height: 100vh; } |
| 29 | + .sidebar { |
| 30 | + width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border-color); |
| 31 | + display: flex; flex-direction: column; overflow: hidden; |
| 32 | + } |
| 33 | + .sidebar-header { |
| 34 | + padding: 1.5rem 1rem; border-bottom: 1px solid var(--border-color); |
| 35 | + display: flex; align-items: center; gap: 0.75rem; |
| 36 | + } |
| 37 | + .sidebar-header svg { |
| 38 | + width: 20px; height: 20px; flex-shrink: 0; |
| 39 | + } |
| 40 | + .sidebar-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); } |
| 41 | + .sidebar-section { padding: 1rem 0.5rem; flex: 1; overflow-y: auto; } |
| 42 | + .section-label { |
| 43 | + padding: 0.5rem 0.75rem; font-size: 0.75rem; font-weight: 600; |
| 44 | + color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; |
| 45 | + } |
| 46 | + .table-list { list-style: none; } |
| 47 | + .table-item { margin: 0.25rem 0; } |
| 48 | + .table-link { |
| 49 | + display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.75rem; |
| 50 | + color: var(--text-primary); text-decoration: none; border-radius: 6px; |
| 51 | + transition: all 0.15s ease; font-size: 0.9rem; |
| 52 | + } |
| 53 | + .table-link:hover { background: var(--bg-hover); color: white; } |
| 54 | + .table-link.active { background: var(--accent); color: white; } |
| 55 | + .table-icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; } |
| 56 | + .table-link:hover .table-icon, .table-link.active .table-icon { color: white; } |
| 57 | + .welcome-container { |
| 58 | + flex: 1; display: flex; align-items: center; justify-content: center; |
| 59 | + background: var(--bg-main); |
| 60 | + } |
| 61 | + .welcome-content { text-align: center; max-width: 500px; padding: 2rem; } |
| 62 | + .welcome-content svg { margin: 0 auto 1.5rem; width: 64px; height: 64px; } |
| 63 | + .welcome-content h1 { |
| 64 | + font-size: 2.5rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-primary); |
| 65 | + } |
| 66 | + .welcome-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem; } |
| 67 | + .welcome-stats { display: flex; justify-content: center; gap: 2rem; margin-bottom: 2rem; } |
| 68 | + .stat { text-align: center; } |
| 69 | + .stat-value { |
| 70 | + font-size: 2.5rem; font-weight: 700; color: var(--text-primary); |
| 71 | + line-height: 1; margin-bottom: 0.5rem; |
| 72 | + } |
| 73 | + .stat-label { |
| 74 | + font-size: 0.85rem; color: var(--text-muted); |
| 75 | + text-transform: uppercase; letter-spacing: 0.05em; |
| 76 | + } |
| 77 | + .db-path-display { |
| 78 | + background: var(--bg-sidebar); border: 1px solid var(--border-color); |
| 79 | + border-radius: 8px; padding: 1rem; font-family: Monaco, monospace; |
| 80 | + font-size: 0.85rem; color: var(--text-muted); word-break: break-all; |
| 81 | + display: flex; align-items: center; gap: 0.5rem; |
| 82 | + } |
| 83 | + .db-path-label { font-size: 1.25rem; flex-shrink: 0; } |
| 84 | + .db-path-value { flex: 1; } |
| 85 | + .main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; } |
| 86 | + .toolbar { |
| 87 | + background: var(--bg-sidebar); border-bottom: 1px solid var(--border-color); |
| 88 | + padding: 1rem 1.5rem; display: flex; align-items: center; justify-content: space-between; |
| 89 | + } |
| 90 | + .toolbar-left { display: flex; align-items: center; gap: 1rem; } |
| 91 | + .table-name-display { |
| 92 | + font-size: 1.25rem; font-weight: 700; color: var(--text-primary); |
| 93 | + font-family: Monaco, monospace; |
| 94 | + } |
| 95 | + .row-count { |
| 96 | + font-size: 0.85rem; color: var(--text-muted); |
| 97 | + padding: 0.25rem 0.75rem; background: var(--bg-dark); border-radius: 4px; |
| 98 | + } |
| 99 | + .table-wrapper { flex: 1; overflow: auto; background: var(--bg-main); } |
| 100 | + .data-table-container { min-width: 100%; display: inline-block; } |
| 101 | + .data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; } |
| 102 | + .data-table thead { background: var(--bg-sidebar); position: sticky; top: 0; z-index: 10; } |
| 103 | + .data-table th { |
| 104 | + padding: 0.75rem 1rem; text-align: left; font-weight: 600; color: var(--text-muted); |
| 105 | + border-bottom: 1px solid var(--border-color); font-family: Monaco, monospace; |
| 106 | + font-size: 0.8rem; letter-spacing: 0.05em; |
| 107 | + } |
| 108 | + .data-table td { |
| 109 | + padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color); |
| 110 | + color: var(--text-primary); font-family: Monaco, monospace; |
| 111 | + font-size: 0.85rem; white-space: nowrap; |
| 112 | + } |
| 113 | + .data-table tbody tr:hover { background: var(--bg-hover); } |
| 114 | + .data-table td.null { color: var(--text-muted); font-style: italic; } |
| 115 | + .empty-state { text-align: center; padding: 4rem 2rem; color: var(--text-muted); } |
| 116 | + .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; } |
| 117 | + `}</style> |
| 118 | + </head> |
| 119 | + <body> |
| 120 | + {children} |
| 121 | + </body> |
| 122 | + </html> |
| 123 | + ); |
| 124 | +} |
| 125 | + |
| 126 | +export type HomeViewProps = { |
| 127 | + dbPath: string; |
| 128 | + tables: string[]; |
| 129 | +} |
| 130 | + |
| 131 | +export function HomeView({ dbPath, tables }: HomeViewProps) { |
| 132 | + return ( |
| 133 | + <App title="Database Studio · Elide"> |
| 134 | + <DatabaseStudio dbPath={dbPath} tables={tables} /> |
| 135 | + </App> |
| 136 | + ); |
| 137 | +} |
| 138 | + |
| 139 | +export type TableViewProps = { |
| 140 | + dbPath: string; |
| 141 | + tableName: string; |
| 142 | + columns: string[]; |
| 143 | + rows: TableRow[]; |
| 144 | + totalRows: number; |
| 145 | + allTables: string[]; |
| 146 | +} |
| 147 | + |
| 148 | +export function TableView({ dbPath, tableName, columns, rows, totalRows, allTables }: TableViewProps) { |
| 149 | + return ( |
| 150 | + <App title={`${tableName} · Database Studio · Elide`}> |
| 151 | + <TableDetail |
| 152 | + dbPath={dbPath} |
| 153 | + tableName={tableName} |
| 154 | + columns={columns} |
| 155 | + rows={rows} |
| 156 | + totalRows={totalRows} |
| 157 | + allTables={allTables} |
| 158 | + /> |
| 159 | + </App> |
| 160 | + ); |
| 161 | +} |
0 commit comments