@riligar/elysia-sqlite 1.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/LICENSE +201 -0
- package/README.md +121 -0
- package/package.json +61 -0
- package/src/core/session.js +90 -0
- package/src/index.js +553 -0
- package/src/ui/bun.lock +612 -0
- package/src/ui/index.html +18 -0
- package/src/ui/package.json +29 -0
- package/src/ui/postcss.config.cjs +14 -0
- package/src/ui/src/App.jsx +2103 -0
- package/src/ui/src/components/DataGrid.jsx +122 -0
- package/src/ui/src/components/EditableCell.jsx +166 -0
- package/src/ui/src/components/ExportButton.jsx +95 -0
- package/src/ui/src/components/FKPreview.jsx +106 -0
- package/src/ui/src/components/Filter.jsx +302 -0
- package/src/ui/src/components/HoldButton.jsx +230 -0
- package/src/ui/src/components/Login.jsx +148 -0
- package/src/ui/src/components/Onboarding.jsx +127 -0
- package/src/ui/src/components/Pagination.jsx +35 -0
- package/src/ui/src/components/SecuritySettings.jsx +273 -0
- package/src/ui/src/components/TableSelector.jsx +75 -0
- package/src/ui/src/hooks/useFilter.js +120 -0
- package/src/ui/src/index.css +123 -0
- package/src/ui/src/main.jsx +115 -0
- package/src/ui/vite.config.js +19 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Table, Checkbox, Group, Text, ScrollArea } from "@mantine/core";
|
|
2
|
+
import { EditableCell } from "./EditableCell";
|
|
3
|
+
import { ButtonDelete } from "./HoldButton";
|
|
4
|
+
|
|
5
|
+
export const DataGrid = ({
|
|
6
|
+
columns,
|
|
7
|
+
rows,
|
|
8
|
+
pk,
|
|
9
|
+
selectedRows,
|
|
10
|
+
onSelectRow,
|
|
11
|
+
onSelectAll,
|
|
12
|
+
onSort,
|
|
13
|
+
sort,
|
|
14
|
+
sortDir,
|
|
15
|
+
getColumnIcon,
|
|
16
|
+
onDeleteRecord,
|
|
17
|
+
editingCell,
|
|
18
|
+
onStartEdit,
|
|
19
|
+
onUpdateCell,
|
|
20
|
+
onCancelEdit,
|
|
21
|
+
fkMap,
|
|
22
|
+
API,
|
|
23
|
+
currentTable,
|
|
24
|
+
getTagColor,
|
|
25
|
+
isTagColumn,
|
|
26
|
+
}) => {
|
|
27
|
+
return (
|
|
28
|
+
<ScrollArea>
|
|
29
|
+
<Table
|
|
30
|
+
striped={false}
|
|
31
|
+
highlightOnHover
|
|
32
|
+
withTableBorder={false}
|
|
33
|
+
verticalSpacing="xs"
|
|
34
|
+
>
|
|
35
|
+
<Table.Thead>
|
|
36
|
+
<Table.Tr>
|
|
37
|
+
<Table.Th w={40} style={{ borderBottom: "1px solid #eee" }}>
|
|
38
|
+
<Checkbox
|
|
39
|
+
checked={selectedRows.size === rows.length && rows.length > 0}
|
|
40
|
+
indeterminate={
|
|
41
|
+
selectedRows.size > 0 && selectedRows.size < rows.length
|
|
42
|
+
}
|
|
43
|
+
onChange={(e) => onSelectAll(e.target.checked)}
|
|
44
|
+
/>
|
|
45
|
+
</Table.Th>
|
|
46
|
+
{columns.map((col) => (
|
|
47
|
+
<Table.Th
|
|
48
|
+
key={col.name}
|
|
49
|
+
onClick={() => onSort(col.name)}
|
|
50
|
+
style={{
|
|
51
|
+
cursor: "pointer",
|
|
52
|
+
borderBottom: "1px solid #eee",
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Group gap={4} wrap="nowrap">
|
|
56
|
+
{getColumnIcon(col.type, col.name)}
|
|
57
|
+
<Text size="xs" fw={500} c="dimmed">
|
|
58
|
+
{col.name}
|
|
59
|
+
</Text>
|
|
60
|
+
{sort === col.name && (
|
|
61
|
+
<Text size="xs" c="dimmed">
|
|
62
|
+
{sortDir === "ASC" ? "↑" : "↓"}
|
|
63
|
+
</Text>
|
|
64
|
+
)}
|
|
65
|
+
</Group>
|
|
66
|
+
</Table.Th>
|
|
67
|
+
))}
|
|
68
|
+
<Table.Th
|
|
69
|
+
w={50}
|
|
70
|
+
style={{ borderBottom: "1px solid #eee" }}
|
|
71
|
+
></Table.Th>
|
|
72
|
+
</Table.Tr>
|
|
73
|
+
</Table.Thead>
|
|
74
|
+
<Table.Tbody>
|
|
75
|
+
{rows.map((row) => (
|
|
76
|
+
<Table.Tr
|
|
77
|
+
key={row[pk]}
|
|
78
|
+
bg={selectedRows.has(String(row[pk])) ? "gray.0" : undefined}
|
|
79
|
+
>
|
|
80
|
+
<Table.Td>
|
|
81
|
+
<Checkbox
|
|
82
|
+
checked={selectedRows.has(String(row[pk]))}
|
|
83
|
+
onChange={(e) => onSelectRow(String(row[pk]), e.target.checked)}
|
|
84
|
+
/>
|
|
85
|
+
</Table.Td>
|
|
86
|
+
{columns.map((col) => (
|
|
87
|
+
<Table.Td key={col.name}>
|
|
88
|
+
<EditableCell
|
|
89
|
+
row={row}
|
|
90
|
+
col={col}
|
|
91
|
+
pk={pk}
|
|
92
|
+
isEditing={
|
|
93
|
+
editingCell?.rowPk === row[pk] &&
|
|
94
|
+
editingCell?.column === col.name
|
|
95
|
+
}
|
|
96
|
+
onStartEdit={onStartEdit}
|
|
97
|
+
onUpdate={onUpdateCell}
|
|
98
|
+
onCancelEdit={onCancelEdit}
|
|
99
|
+
fkMap={fkMap}
|
|
100
|
+
API={API}
|
|
101
|
+
currentTable={currentTable}
|
|
102
|
+
getTagColor={getTagColor}
|
|
103
|
+
isTagColumn={isTagColumn}
|
|
104
|
+
/>
|
|
105
|
+
</Table.Td>
|
|
106
|
+
))}
|
|
107
|
+
<Table.Td>
|
|
108
|
+
<ButtonDelete
|
|
109
|
+
type="icon"
|
|
110
|
+
onDelete={() => onDeleteRecord(row[pk])}
|
|
111
|
+
size="sm"
|
|
112
|
+
variant="subtle"
|
|
113
|
+
color="red"
|
|
114
|
+
/>
|
|
115
|
+
</Table.Td>
|
|
116
|
+
</Table.Tr>
|
|
117
|
+
))}
|
|
118
|
+
</Table.Tbody>
|
|
119
|
+
</Table>
|
|
120
|
+
</ScrollArea>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { Text, Select, TextInput, Badge, Group } from "@mantine/core";
|
|
3
|
+
import { IconKey, IconLink } from "@tabler/icons-react";
|
|
4
|
+
import { FKPreview } from "./FKPreview";
|
|
5
|
+
|
|
6
|
+
export const EditableCell = ({
|
|
7
|
+
row,
|
|
8
|
+
col,
|
|
9
|
+
pk,
|
|
10
|
+
isEditing,
|
|
11
|
+
onStartEdit,
|
|
12
|
+
onUpdate,
|
|
13
|
+
onCancelEdit,
|
|
14
|
+
fkMap,
|
|
15
|
+
API,
|
|
16
|
+
currentTable,
|
|
17
|
+
getTagColor,
|
|
18
|
+
isTagColumn
|
|
19
|
+
}) => {
|
|
20
|
+
const value = row[col.name];
|
|
21
|
+
const rowPk = row[pk];
|
|
22
|
+
const isPK = col.pk === 1;
|
|
23
|
+
const hasFK = !!col.fk;
|
|
24
|
+
|
|
25
|
+
const [fkOptions, setFkOptions] = useState([]);
|
|
26
|
+
const [fkLoading, setFkLoading] = useState(false);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (isEditing && hasFK) {
|
|
30
|
+
setFkLoading(true);
|
|
31
|
+
fetch(
|
|
32
|
+
`${API}/table/${currentTable}/fk-options?refTable=${col.fk.table}&refColumn=${col.fk.column}`
|
|
33
|
+
)
|
|
34
|
+
.then((res) => res.json())
|
|
35
|
+
.then((data) => {
|
|
36
|
+
if (data.success) {
|
|
37
|
+
setFkOptions(
|
|
38
|
+
data.options.map((o) => ({
|
|
39
|
+
value: String(o.value),
|
|
40
|
+
label: `${o.label} (ID: ${o.value})`,
|
|
41
|
+
}))
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
setFkLoading(false);
|
|
45
|
+
})
|
|
46
|
+
.catch(() => setFkLoading(false));
|
|
47
|
+
}
|
|
48
|
+
}, [isEditing, hasFK, API, currentTable, col.fk]);
|
|
49
|
+
|
|
50
|
+
if (isEditing) {
|
|
51
|
+
if (hasFK) {
|
|
52
|
+
return (
|
|
53
|
+
<Select
|
|
54
|
+
size="xs"
|
|
55
|
+
autoFocus
|
|
56
|
+
searchable
|
|
57
|
+
data={fkOptions}
|
|
58
|
+
defaultValue={value === null ? null : String(value)}
|
|
59
|
+
placeholder={
|
|
60
|
+
fkLoading ? "Loading..." : `Select ${col.fk.table}`
|
|
61
|
+
}
|
|
62
|
+
onChange={(newVal) => {
|
|
63
|
+
onUpdate(rowPk, col.name, newVal);
|
|
64
|
+
}}
|
|
65
|
+
onBlur={onCancelEdit}
|
|
66
|
+
styles={{
|
|
67
|
+
input: {
|
|
68
|
+
minHeight: "28px",
|
|
69
|
+
height: "28px",
|
|
70
|
+
},
|
|
71
|
+
}}
|
|
72
|
+
onKeyDownCapture={(e) => {
|
|
73
|
+
if (e.key === "Escape") {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
onCancelEdit();
|
|
77
|
+
}
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<TextInput
|
|
85
|
+
size="xs"
|
|
86
|
+
autoFocus
|
|
87
|
+
defaultValue={value === null ? "" : String(value)}
|
|
88
|
+
onBlur={(e) => onUpdate(rowPk, col.name, e.target.value)}
|
|
89
|
+
onKeyDown={(e) => {
|
|
90
|
+
if (e.key === "Enter") {
|
|
91
|
+
onUpdate(rowPk, col.name, e.target.value);
|
|
92
|
+
} else if (e.key === "Escape") {
|
|
93
|
+
onCancelEdit();
|
|
94
|
+
}
|
|
95
|
+
}}
|
|
96
|
+
styles={{
|
|
97
|
+
input: {
|
|
98
|
+
minHeight: "28px",
|
|
99
|
+
height: "28px",
|
|
100
|
+
padding: "0 8px",
|
|
101
|
+
},
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (value === null) {
|
|
108
|
+
return (
|
|
109
|
+
<Text
|
|
110
|
+
c="dimmed"
|
|
111
|
+
fs="italic"
|
|
112
|
+
size="sm"
|
|
113
|
+
onClick={() => !isPK && onStartEdit(rowPk, col.name)}
|
|
114
|
+
style={{ cursor: isPK ? "default" : "text" }}
|
|
115
|
+
>
|
|
116
|
+
null
|
|
117
|
+
</Text>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (hasFK) {
|
|
122
|
+
return (
|
|
123
|
+
<div
|
|
124
|
+
onClick={(e) => {
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
onStartEdit(rowPk, col.name);
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<FKPreview
|
|
130
|
+
table={col.fk.table}
|
|
131
|
+
id={value}
|
|
132
|
+
label={fkMap[`${col.fk.table}:${value}`]}
|
|
133
|
+
API={API}
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (isTagColumn(col.name)) {
|
|
140
|
+
return (
|
|
141
|
+
<Badge
|
|
142
|
+
color={getTagColor(value)}
|
|
143
|
+
variant="light"
|
|
144
|
+
onClick={() => onStartEdit(rowPk, col.name)}
|
|
145
|
+
style={{ cursor: "pointer" }}
|
|
146
|
+
>
|
|
147
|
+
{value}
|
|
148
|
+
</Badge>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Text
|
|
154
|
+
size="sm"
|
|
155
|
+
onClick={() => !isPK && onStartEdit(rowPk, col.name)}
|
|
156
|
+
style={{
|
|
157
|
+
cursor: isPK ? "default" : "text",
|
|
158
|
+
padding: "4px 0",
|
|
159
|
+
borderRadius: "4px",
|
|
160
|
+
}}
|
|
161
|
+
className={isPK ? "" : "editable-cell"}
|
|
162
|
+
>
|
|
163
|
+
{String(value)}
|
|
164
|
+
</Text>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Button, Menu } from "@mantine/core";
|
|
2
|
+
import { IconDownload, IconFileTypeCsv, IconJson } from "@tabler/icons-react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ExportButton - A reusable export component with JSON/CSV menu options
|
|
6
|
+
* @param {Object} props
|
|
7
|
+
* @param {Array} props.data - Array of objects to export
|
|
8
|
+
* @param {Array} props.columns - Array of column objects with 'name' property (optional, auto-detected if not provided)
|
|
9
|
+
* @param {string} props.filename - Base filename without extension (default: 'export')
|
|
10
|
+
* @param {string} props.size - Button size (default: 'xs')
|
|
11
|
+
* @param {string} props.variant - Button variant (default: 'default')
|
|
12
|
+
* @param {boolean} props.compact - Use compact button size (default: false)
|
|
13
|
+
*/
|
|
14
|
+
export function ExportButton({
|
|
15
|
+
data = [],
|
|
16
|
+
columns,
|
|
17
|
+
filename = "export",
|
|
18
|
+
size = "xs",
|
|
19
|
+
variant = "default",
|
|
20
|
+
compact = false,
|
|
21
|
+
}) {
|
|
22
|
+
const getColumnNames = () => {
|
|
23
|
+
if (columns?.length) {
|
|
24
|
+
return columns.map((c) => (typeof c === "string" ? c : c.name));
|
|
25
|
+
}
|
|
26
|
+
if (data.length > 0) {
|
|
27
|
+
return Object.keys(data[0]);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const exportAsCSV = () => {
|
|
33
|
+
if (data.length === 0) return;
|
|
34
|
+
|
|
35
|
+
const colNames = getColumnNames();
|
|
36
|
+
const csv = [
|
|
37
|
+
colNames.join(","),
|
|
38
|
+
...data.map((row) =>
|
|
39
|
+
colNames
|
|
40
|
+
.map((col) => `"${String(row[col] ?? "").replace(/"/g, '""')}"`)
|
|
41
|
+
.join(",")
|
|
42
|
+
),
|
|
43
|
+
].join("\n");
|
|
44
|
+
|
|
45
|
+
downloadFile(`${filename}.csv`, csv, "text/csv");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const exportAsJSON = () => {
|
|
49
|
+
if (data.length === 0) return;
|
|
50
|
+
|
|
51
|
+
const json = JSON.stringify(data, null, 2);
|
|
52
|
+
downloadFile(`${filename}.json`, json, "application/json");
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const downloadFile = (name, content, type) => {
|
|
56
|
+
const blob = new Blob([content], { type });
|
|
57
|
+
const url = URL.createObjectURL(blob);
|
|
58
|
+
const a = document.createElement("a");
|
|
59
|
+
a.href = url;
|
|
60
|
+
a.download = name;
|
|
61
|
+
a.click();
|
|
62
|
+
URL.revokeObjectURL(url);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const buttonSize = compact ? "compact-xs" : size;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Menu shadow="md" width={160}>
|
|
69
|
+
<Menu.Target>
|
|
70
|
+
<Button
|
|
71
|
+
size={buttonSize}
|
|
72
|
+
variant={variant}
|
|
73
|
+
color="dark"
|
|
74
|
+
leftSection={<IconDownload size={14} />}
|
|
75
|
+
disabled={data.length === 0}
|
|
76
|
+
>
|
|
77
|
+
Export
|
|
78
|
+
</Button>
|
|
79
|
+
</Menu.Target>
|
|
80
|
+
|
|
81
|
+
<Menu.Dropdown>
|
|
82
|
+
<Menu.Label>Export as</Menu.Label>
|
|
83
|
+
<Menu.Item
|
|
84
|
+
leftSection={<IconFileTypeCsv size={16} />}
|
|
85
|
+
onClick={exportAsCSV}
|
|
86
|
+
>
|
|
87
|
+
CSV
|
|
88
|
+
</Menu.Item>
|
|
89
|
+
<Menu.Item leftSection={<IconJson size={16} />} onClick={exportAsJSON}>
|
|
90
|
+
JSON
|
|
91
|
+
</Menu.Item>
|
|
92
|
+
</Menu.Dropdown>
|
|
93
|
+
</Menu>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { HoverCard, Group, Badge, Text, Center, Loader, Stack, Divider, Box } from "@mantine/core";
|
|
3
|
+
import { IconLink } from "@tabler/icons-react";
|
|
4
|
+
|
|
5
|
+
export const FKPreview = ({ table, id, label, API }) => {
|
|
6
|
+
const [record, setRecord] = useState(null);
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [fetched, setFetched] = useState(false);
|
|
9
|
+
|
|
10
|
+
const loadRecord = async () => {
|
|
11
|
+
if (fetched) return;
|
|
12
|
+
setLoading(true);
|
|
13
|
+
try {
|
|
14
|
+
const res = await fetch(`${API}/query`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: { "Content-Type": "application/json" },
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
sql: `SELECT * FROM ${table} WHERE rowid = ${id} LIMIT 1`,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
const data = await res.json();
|
|
22
|
+
if (data.success && data.rows && data.rows.length > 0) {
|
|
23
|
+
setRecord(data.rows[0]);
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(e);
|
|
27
|
+
}
|
|
28
|
+
setLoading(false);
|
|
29
|
+
setFetched(true);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<HoverCard width={280} shadow="md" openDelay={300} onOpen={loadRecord}>
|
|
34
|
+
<HoverCard.Target>
|
|
35
|
+
<Group gap={6} wrap="nowrap" style={{ cursor: "pointer" }}>
|
|
36
|
+
<Badge
|
|
37
|
+
variant="outline"
|
|
38
|
+
color="gray"
|
|
39
|
+
size="sm"
|
|
40
|
+
leftSection={<IconLink size={10} />}
|
|
41
|
+
styles={{ label: { fontWeight: 500 } }}
|
|
42
|
+
>
|
|
43
|
+
{id}
|
|
44
|
+
</Badge>
|
|
45
|
+
{label && (
|
|
46
|
+
<Text size="xs" c="dimmed" lineClamp={1}>
|
|
47
|
+
{label}
|
|
48
|
+
</Text>
|
|
49
|
+
)}
|
|
50
|
+
</Group>
|
|
51
|
+
</HoverCard.Target>
|
|
52
|
+
<HoverCard.Dropdown>
|
|
53
|
+
{loading ? (
|
|
54
|
+
<Center p="sm">
|
|
55
|
+
<Loader size="xs" type="dots" />
|
|
56
|
+
</Center>
|
|
57
|
+
) : record ? (
|
|
58
|
+
<Stack gap="xs">
|
|
59
|
+
<Group justify="space-between">
|
|
60
|
+
<Text size="xs" fw={700} c="dimmed" tt="uppercase">
|
|
61
|
+
{table}
|
|
62
|
+
</Text>
|
|
63
|
+
<Badge size="xs" variant="light">
|
|
64
|
+
ID: {id}
|
|
65
|
+
</Badge>
|
|
66
|
+
</Group>
|
|
67
|
+
<Text size="sm" fw={600} lineClamp={2}>
|
|
68
|
+
{label || "Record"}
|
|
69
|
+
</Text>
|
|
70
|
+
<Divider />
|
|
71
|
+
<Stack gap={4}>
|
|
72
|
+
{Object.entries(record)
|
|
73
|
+
.filter(
|
|
74
|
+
([k]) => k !== "id" && !k.toLowerCase().includes("id")
|
|
75
|
+
)
|
|
76
|
+
.slice(0, 3)
|
|
77
|
+
.map(([k, v]) => (
|
|
78
|
+
<Group
|
|
79
|
+
key={k}
|
|
80
|
+
justify="space-between"
|
|
81
|
+
align="flex-start"
|
|
82
|
+
wrap="nowrap"
|
|
83
|
+
>
|
|
84
|
+
<Text size="xs" c="dimmed" style={{ minWidth: 60 }}>
|
|
85
|
+
{k}:
|
|
86
|
+
</Text>
|
|
87
|
+
<Text
|
|
88
|
+
size="xs"
|
|
89
|
+
lineClamp={1}
|
|
90
|
+
style={{ textAlign: "right" }}
|
|
91
|
+
>
|
|
92
|
+
{String(v)}
|
|
93
|
+
</Text>
|
|
94
|
+
</Group>
|
|
95
|
+
))}
|
|
96
|
+
</Stack>
|
|
97
|
+
</Stack>
|
|
98
|
+
) : (
|
|
99
|
+
<Text size="xs" c="dimmed">
|
|
100
|
+
No preview available
|
|
101
|
+
</Text>
|
|
102
|
+
)}
|
|
103
|
+
</HoverCard.Dropdown>
|
|
104
|
+
</HoverCard>
|
|
105
|
+
);
|
|
106
|
+
};
|