@constructive-io/schema-builder 0.2.0 → 0.4.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/CHANGELOG.md +23 -0
- package/README.md +12 -4
- package/dist/card-widths-CmIxkRfh.cjs +28 -0
- package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
- package/dist/card-widths-pI4Kw4Xz.js +22 -0
- package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
- package/dist/core-CVxnNLs7.cjs +66 -0
- package/dist/core-CVxnNLs7.cjs.map +1 -0
- package/dist/core-DJ5kA4r-.js +49 -0
- package/dist/core-DJ5kA4r-.js.map +1 -0
- package/dist/core.cjs +14 -212
- package/dist/core.d.cts +3 -54
- package/dist/core.d.ts +3 -54
- package/dist/core.js +3 -200
- package/dist/create-table-card-B6SMrt_g.js +7691 -0
- package/dist/create-table-card-B6SMrt_g.js.map +1 -0
- package/dist/create-table-card-BrQ7pB_U.cjs +7732 -0
- package/dist/create-table-card-BrQ7pB_U.cjs.map +1 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
- package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
- package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
- package/dist/empty-state-card-5t7LygTB.cjs +62 -0
- package/dist/empty-state-card-5t7LygTB.cjs.map +1 -0
- package/dist/empty-state-card-C-Nylatg.js +57 -0
- package/dist/empty-state-card-C-Nylatg.js.map +1 -0
- package/dist/fields.cjs +8 -7763
- package/dist/fields.d.cts +38 -39
- package/dist/fields.d.ts +38 -39
- package/dist/fields.js +2 -7735
- package/dist/generated-types-DZMUyNBH.d.cts +27 -0
- package/dist/generated-types-DZMUyNBH.d.ts +27 -0
- package/dist/index--9KTz1LB.d.cts +56 -0
- package/dist/index-10idAfdb.d.cts +7 -0
- package/dist/index-BcdFaKFS.d.ts +7 -0
- package/dist/index-euaSKMQK.d.ts +56 -0
- package/dist/index.cjs +392 -13730
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +381 -13698
- package/dist/index.js.map +1 -1
- package/dist/indexes-view-CBzYpKcd.js +736 -0
- package/dist/indexes-view-CBzYpKcd.js.map +1 -0
- package/dist/indexes-view-D1K24ts1.cjs +759 -0
- package/dist/indexes-view-D1K24ts1.cjs.map +1 -0
- package/dist/indexes.cjs +6 -1041
- package/dist/indexes.d.cts +27 -27
- package/dist/indexes.d.ts +27 -27
- package/dist/indexes.js +2 -1016
- package/dist/invalidate-database-entities-BFCWf5Zf.js +2561 -0
- package/dist/invalidate-database-entities-BFCWf5Zf.js.map +1 -0
- package/dist/invalidate-database-entities-Gs5k8A-M.cjs +2864 -0
- package/dist/invalidate-database-entities-Gs5k8A-M.cjs.map +1 -0
- package/dist/keyboard-activation-BQiV0scm.js +13 -0
- package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
- package/dist/policies-view-CkvGpJBo.cjs +1023 -0
- package/dist/policies-view-CkvGpJBo.cjs.map +1 -0
- package/dist/policies-view-DTfAhX7G.js +1018 -0
- package/dist/policies-view-DTfAhX7G.js.map +1 -0
- package/dist/policies.cjs +10 -5939
- package/dist/policies.d.cts +55 -50
- package/dist/policies.d.ts +55 -50
- package/dist/policies.js +4 -5911
- package/dist/policy-config-form-EEcQ9ywL.js +2502 -0
- package/dist/policy-config-form-EEcQ9ywL.js.map +1 -0
- package/dist/policy-config-form-RP9010zj.cjs +2629 -0
- package/dist/policy-config-form-RP9010zj.cjs.map +1 -0
- package/dist/policy-types-D_sYWb-b.d.cts +81 -0
- package/dist/policy-types-D_sYWb-b.d.ts +81 -0
- package/dist/query-BGtzUV7Y.cjs +233 -0
- package/dist/query-BGtzUV7Y.cjs.map +1 -0
- package/dist/query-r6j8IjQB.js +192 -0
- package/dist/query-r6j8IjQB.js.map +1 -0
- package/dist/relationships-view-C884EvGj.js +2417 -0
- package/dist/relationships-view-C884EvGj.js.map +1 -0
- package/dist/relationships-view-DlBs-gCF.cjs +2452 -0
- package/dist/relationships-view-DlBs-gCF.cjs.map +1 -0
- package/dist/relationships.cjs +9 -4328
- package/dist/relationships.d.cts +92 -92
- package/dist/relationships.d.ts +92 -92
- package/dist/relationships.js +2 -4300
- package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
- package/dist/schema-builder-sidebar-DAgK7ZTu.js +654 -0
- package/dist/schema-builder-sidebar-DAgK7ZTu.js.map +1 -0
- package/dist/schema-builder-sidebar-L3TcQeQr.cjs +671 -0
- package/dist/schema-builder-sidebar-L3TcQeQr.cjs.map +1 -0
- package/dist/table-editor-B-5i1M79.js +1906 -0
- package/dist/table-editor-B-5i1M79.js.map +1 -0
- package/dist/table-editor-BdLdVZfh.cjs +1935 -0
- package/dist/table-editor-BdLdVZfh.cjs.map +1 -0
- package/dist/tables.cjs +6 -5643
- package/dist/tables.d.cts +22 -21
- package/dist/tables.d.ts +22 -21
- package/dist/tables.js +3 -5618
- package/dist/testing.cjs +63 -62
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +62 -61
- package/dist/testing.js.map +1 -1
- package/dist/types-CXNRA22N.d.cts +450 -0
- package/dist/types-CXNRA22N.d.ts +450 -0
- package/dist/use-update-table-DlLX9fdE.js +244 -0
- package/dist/use-update-table-DlLX9fdE.js.map +1 -0
- package/dist/use-update-table-vcoHVolI.cjs +291 -0
- package/dist/use-update-table-vcoHVolI.cjs.map +1 -0
- package/package.json +8 -6
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/fields.cjs.map +0 -1
- package/dist/fields.js.map +0 -1
- package/dist/generated-types-CnAlqHU_.d.cts +0 -25
- package/dist/generated-types-CnAlqHU_.d.ts +0 -25
- package/dist/indexes.cjs.map +0 -1
- package/dist/indexes.js.map +0 -1
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.js.map +0 -1
- package/dist/policy-types-CEYAR5TN.d.cts +0 -79
- package/dist/policy-types-CEYAR5TN.d.ts +0 -79
- package/dist/relationships.cjs.map +0 -1
- package/dist/relationships.js.map +0 -1
- package/dist/tables.cjs.map +0 -1
- package/dist/tables.js.map +0 -1
- package/dist/types-Du86atZ8.d.cts +0 -199
- package/dist/types-Du86atZ8.d.ts +0 -199
- package/dist/types-bX2dCrdl.d.cts +0 -52
- package/dist/types-bX2dCrdl.d.ts +0 -52
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
const require_invalidate_database_entities = require('./invalidate-database-entities-Gs5k8A-M.cjs');
|
|
3
|
+
const require_use_update_table = require('./use-update-table-vcoHVolI.cjs');
|
|
4
|
+
const require_card_widths = require('./card-widths-CmIxkRfh.cjs');
|
|
5
|
+
const require_keyboard_activation = require('./keyboard-activation-D-L0IU6Y.cjs');
|
|
6
|
+
const require_create_table_card = require('./create-table-card-BrQ7pB_U.cjs');
|
|
7
|
+
let _constructive_io_ui_stack = require("@constructive-io/ui/stack");
|
|
8
|
+
let motion_react = require("motion/react");
|
|
9
|
+
let react = require("react");
|
|
10
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
+
let _constructive_io_ui_tooltip = require("@constructive-io/ui/tooltip");
|
|
12
|
+
let _remixicon_react = require("@remixicon/react");
|
|
13
|
+
let lucide_react = require("lucide-react");
|
|
14
|
+
let _tanstack_react_query = require("@tanstack/react-query");
|
|
15
|
+
let _constructive_io_ui_button = require("@constructive-io/ui/button");
|
|
16
|
+
let _constructive_io_ui_toast = require("@constructive-io/ui/toast");
|
|
17
|
+
let _constructive_io_ui_alert_dialog = require("@constructive-io/ui/alert-dialog");
|
|
18
|
+
let _constructive_io_ui_select = require("@constructive-io/ui/select");
|
|
19
|
+
let _constructive_io_ui_collapsible = require("@constructive-io/ui/collapsible");
|
|
20
|
+
let _constructive_io_ui_dropdown_menu = require("@constructive-io/ui/dropdown-menu");
|
|
21
|
+
let _constructive_io_ui_progressive_blur = require("@constructive-io/ui/progressive-blur");
|
|
22
|
+
|
|
23
|
+
//#region src/schema/schema-builder-tables/lib/gql/hooks/schema-builder/use-delete-table.ts
|
|
24
|
+
/**
|
|
25
|
+
* Hook for deleting a table
|
|
26
|
+
* Tier 4 wrapper: adds table selection handling after deletion
|
|
27
|
+
*/
|
|
28
|
+
function useDeleteTable() {
|
|
29
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
30
|
+
const { currentSchema, selectedTableId, selectTable, selectedSchemaKey, currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
31
|
+
const deleteTableMutation = require_invalidate_database_entities.useDeleteTableMutation({ selection: { fields: { id: true } } });
|
|
32
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
33
|
+
mutationFn: async (input) => {
|
|
34
|
+
await deleteTableMutation.mutateAsync({ id: input.id });
|
|
35
|
+
return input.id;
|
|
36
|
+
},
|
|
37
|
+
onSuccess: async (deletedId, variables) => {
|
|
38
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId);
|
|
39
|
+
const isSelectedTable = selectedTableId === deletedId;
|
|
40
|
+
let newSelectedTable = null;
|
|
41
|
+
if (isSelectedTable && selectedSchemaKey) {
|
|
42
|
+
const currentTables = currentSchema?.tables || [];
|
|
43
|
+
if (currentTables.length > 1) {
|
|
44
|
+
const deletedTableIndex = currentTables.findIndex((table) => table.id === deletedId);
|
|
45
|
+
const remainingTables = currentTables.filter((table) => table.id !== deletedId);
|
|
46
|
+
if (deletedTableIndex < remainingTables.length) newSelectedTable = remainingTables[deletedTableIndex];
|
|
47
|
+
else newSelectedTable = remainingTables[remainingTables.length - 1];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (newSelectedTable) selectTable(newSelectedTable.id, newSelectedTable.name);
|
|
51
|
+
else if (isSelectedTable) selectTable(null);
|
|
52
|
+
},
|
|
53
|
+
onError: (error) => {
|
|
54
|
+
console.error("Failed to delete table:", error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/schema/schema-builder-tables/components/tables/delete-table-dialog.tsx
|
|
61
|
+
function DeleteTableDialog({ isOpen, onOpenChange, tableId, tableName, onTableDeleted }) {
|
|
62
|
+
const deleteTableMutation = useDeleteTable();
|
|
63
|
+
const handleConfirmDelete = async () => {
|
|
64
|
+
if (!tableId || !tableName) return;
|
|
65
|
+
try {
|
|
66
|
+
await deleteTableMutation.mutateAsync({ id: tableId });
|
|
67
|
+
onOpenChange(false);
|
|
68
|
+
(0, _constructive_io_ui_toast.showSuccessToast)({
|
|
69
|
+
message: "Table deleted successfully!",
|
|
70
|
+
description: `Table "${tableName}" has been removed.`
|
|
71
|
+
});
|
|
72
|
+
if (onTableDeleted) onTableDeleted(tableId);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error("Failed to delete table:", error);
|
|
75
|
+
(0, _constructive_io_ui_toast.showErrorToast)({
|
|
76
|
+
message: "Failed to delete table",
|
|
77
|
+
description: error instanceof Error ? error.message : "An unexpected error occurred."
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const handleCancel = () => {
|
|
82
|
+
onOpenChange(false);
|
|
83
|
+
};
|
|
84
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_alert_dialog.AlertDialog, {
|
|
85
|
+
open: isOpen,
|
|
86
|
+
onOpenChange,
|
|
87
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_alert_dialog.AlertDialogContent, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_alert_dialog.AlertDialogHeader, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_alert_dialog.AlertDialogTitle, { children: "Delete Table" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_alert_dialog.AlertDialogDescription, { children: [
|
|
88
|
+
"Are you sure you want to delete table ",
|
|
89
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: [
|
|
90
|
+
"\"",
|
|
91
|
+
tableName,
|
|
92
|
+
"\""
|
|
93
|
+
] }),
|
|
94
|
+
"? This action cannot be undone and will permanently remove the table and all its data."
|
|
95
|
+
] })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_alert_dialog.AlertDialogFooter, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_alert_dialog.AlertDialogCancel, {
|
|
96
|
+
onClick: handleCancel,
|
|
97
|
+
disabled: deleteTableMutation.isPending,
|
|
98
|
+
children: "Cancel"
|
|
99
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
100
|
+
variant: "destructive",
|
|
101
|
+
onClick: handleConfirmDelete,
|
|
102
|
+
disabled: deleteTableMutation.isPending || !tableId,
|
|
103
|
+
children: [deleteTableMutation.isPending && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2Icon, { className: "mr-2 h-4 w-4 animate-spin" }), deleteTableMutation.isPending ? "Deleting..." : "Delete Table"]
|
|
104
|
+
})] })] })
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/schema/schema-builder-tables/components/schemas/schema-builder-sidebar.tsx
|
|
110
|
+
const TABLE_ITEM_HEIGHT = 32;
|
|
111
|
+
const SECTION_HEADER_HEIGHT = 32;
|
|
112
|
+
const EMPTY_STATE_HEIGHT = 100;
|
|
113
|
+
const TABLE_NAME_ELLIPSIS = "...";
|
|
114
|
+
const SCROLL_AFFORDANCE_THRESHOLD_PX = 8;
|
|
115
|
+
function truncateMiddleToWidth(text, maxWidth, measure) {
|
|
116
|
+
if (!text) return "";
|
|
117
|
+
if (maxWidth <= 0) return text;
|
|
118
|
+
if (measure(text) <= maxWidth) return text;
|
|
119
|
+
if (measure(TABLE_NAME_ELLIPSIS) >= maxWidth) return TABLE_NAME_ELLIPSIS;
|
|
120
|
+
let low = 2;
|
|
121
|
+
let high = text.length;
|
|
122
|
+
let best = 0;
|
|
123
|
+
while (low <= high) {
|
|
124
|
+
const keptChars = Math.floor((low + high) / 2);
|
|
125
|
+
const leftChars = Math.ceil(keptChars / 2);
|
|
126
|
+
const rightChars = Math.floor(keptChars / 2);
|
|
127
|
+
if (measure(`${text.slice(0, leftChars)}${TABLE_NAME_ELLIPSIS}${text.slice(text.length - rightChars)}`) <= maxWidth) {
|
|
128
|
+
best = keptChars;
|
|
129
|
+
low = keptChars + 1;
|
|
130
|
+
} else high = keptChars - 1;
|
|
131
|
+
}
|
|
132
|
+
if (best > 0) {
|
|
133
|
+
const leftChars = Math.ceil(best / 2);
|
|
134
|
+
const rightChars = Math.floor(best / 2);
|
|
135
|
+
return `${text.slice(0, leftChars)}${TABLE_NAME_ELLIPSIS}${text.slice(text.length - rightChars)}`;
|
|
136
|
+
}
|
|
137
|
+
const oneSideCandidate = `${text.slice(0, 1)}${TABLE_NAME_ELLIPSIS}`;
|
|
138
|
+
return measure(oneSideCandidate) <= maxWidth ? oneSideCandidate : TABLE_NAME_ELLIPSIS;
|
|
139
|
+
}
|
|
140
|
+
function getTableNameDisplayState(name, maxWidth, measure) {
|
|
141
|
+
const displayName = truncateMiddleToWidth(name, maxWidth, measure);
|
|
142
|
+
return {
|
|
143
|
+
displayName,
|
|
144
|
+
isOverflowing: displayName !== name
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function getScrollAffordanceState({ scrollTop, scrollHeight, clientHeight, threshold = SCROLL_AFFORDANCE_THRESHOLD_PX }) {
|
|
148
|
+
if (!(scrollHeight - clientHeight > threshold)) return {
|
|
149
|
+
hasOverflow: false,
|
|
150
|
+
showTopBlur: false,
|
|
151
|
+
showBottomBlur: false
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
hasOverflow: true,
|
|
155
|
+
showTopBlur: scrollTop > threshold,
|
|
156
|
+
showBottomBlur: scrollTop + clientHeight < scrollHeight - threshold
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function openCreateTableCard(stack, onTableCreated) {
|
|
160
|
+
stack.push({
|
|
161
|
+
id: "create-table-select-model",
|
|
162
|
+
title: "Create Table",
|
|
163
|
+
description: "Securely create a new table based on its access model",
|
|
164
|
+
Component: require_create_table_card.CreateTableCard,
|
|
165
|
+
props: { onTableCreated },
|
|
166
|
+
width: require_card_widths.CARD_WIDTHS.extraWide
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function SchemaBuilderMobileNavigation({ hasSystemTables = false, onShowSystemTablesChange, showSystemTables = false }) {
|
|
170
|
+
const stack = (0, _constructive_io_ui_stack.useCardStack)();
|
|
171
|
+
const { currentSchema, selectedTableId, selectTable } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
172
|
+
const tables = currentSchema?.tables ?? [];
|
|
173
|
+
const selectedTable = tables.find((table) => table.id === selectedTableId) ?? null;
|
|
174
|
+
const tableOptions = tables.filter((table) => showSystemTables || table.category === "APP" || table.id === selectedTableId).map((table) => ({
|
|
175
|
+
label: table.label ?? table.name,
|
|
176
|
+
value: table.id
|
|
177
|
+
}));
|
|
178
|
+
function handleTableSelect(tableId) {
|
|
179
|
+
const table = tables.find((candidate) => candidate.id === tableId);
|
|
180
|
+
if (table) selectTable(table.id, table.name);
|
|
181
|
+
}
|
|
182
|
+
function handleCreateTable() {
|
|
183
|
+
openCreateTableCard(stack, (table) => {
|
|
184
|
+
selectTable(table.id, table.name);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
188
|
+
className: "bg-card flex items-center gap-2 border-b p-2 sm:hidden",
|
|
189
|
+
"data-chat-component": "schema-builder-mobile-navigation",
|
|
190
|
+
children: [
|
|
191
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
|
|
192
|
+
items: tableOptions,
|
|
193
|
+
onValueChange: handleTableSelect,
|
|
194
|
+
value: selectedTableId ?? "",
|
|
195
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, {
|
|
196
|
+
"aria-label": "Select table",
|
|
197
|
+
className: "min-w-0 flex-1",
|
|
198
|
+
size: "sm",
|
|
199
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, {
|
|
200
|
+
placeholder: "Select a table",
|
|
201
|
+
children: selectedTable ? selectedTable.label ?? selectedTable.name : "Select a table"
|
|
202
|
+
})
|
|
203
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectGroup, { children: tableOptions.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectItem, {
|
|
204
|
+
value: option.value,
|
|
205
|
+
children: option.label
|
|
206
|
+
}, option.value)) }) })]
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
209
|
+
"aria-label": "Create table",
|
|
210
|
+
onClick: handleCreateTable,
|
|
211
|
+
size: "icon-sm",
|
|
212
|
+
variant: "outline",
|
|
213
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { "aria-hidden": true })
|
|
214
|
+
}),
|
|
215
|
+
hasSystemTables && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
216
|
+
"aria-label": showSystemTables ? "Hide system tables" : "Show system tables",
|
|
217
|
+
"aria-pressed": showSystemTables,
|
|
218
|
+
onClick: () => onShowSystemTablesChange(!showSystemTables),
|
|
219
|
+
size: "icon-sm",
|
|
220
|
+
variant: "ghost",
|
|
221
|
+
children: showSystemTables ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Eye, { "aria-hidden": true }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.EyeOff, { "aria-hidden": true })
|
|
222
|
+
})
|
|
223
|
+
]
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function SchemaBuilderSidebar({ onTableSelect, showSystemTables = false }) {
|
|
227
|
+
const containerRef = (0, react.useRef)(null);
|
|
228
|
+
const [containerHeight, setContainerHeight] = (0, react.useState)(0);
|
|
229
|
+
const stack = (0, _constructive_io_ui_stack.useCardStack)();
|
|
230
|
+
const [deleteDialog, setDeleteDialog] = (0, react.useState)({
|
|
231
|
+
isOpen: false,
|
|
232
|
+
tableId: null,
|
|
233
|
+
tableName: null
|
|
234
|
+
});
|
|
235
|
+
const { currentSchema, selectedTableId, selectTable } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
236
|
+
const sidebarSections = require_use_update_table.useSidebarSections();
|
|
237
|
+
const { toggleSidebarSection } = require_use_update_table.useSidebarSectionActions();
|
|
238
|
+
const tables = (0, react.useMemo)(() => currentSchema?.tables || [], [currentSchema?.tables]);
|
|
239
|
+
const hasCategoryData = (0, react.useMemo)(() => {
|
|
240
|
+
return tables.some((table) => table.category !== void 0);
|
|
241
|
+
}, [tables]);
|
|
242
|
+
const { appTables, systemTables } = (0, react.useMemo)(() => {
|
|
243
|
+
const app = [];
|
|
244
|
+
const system = [];
|
|
245
|
+
tables.forEach((table) => {
|
|
246
|
+
if (table.category === "APP") app.push(table);
|
|
247
|
+
else system.push(table);
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
appTables: app,
|
|
251
|
+
systemTables: system
|
|
252
|
+
};
|
|
253
|
+
}, [tables]);
|
|
254
|
+
(0, react.useEffect)(() => {
|
|
255
|
+
const container = containerRef.current;
|
|
256
|
+
if (!container) return;
|
|
257
|
+
const updateHeight = () => {
|
|
258
|
+
setContainerHeight(container.clientHeight);
|
|
259
|
+
};
|
|
260
|
+
updateHeight();
|
|
261
|
+
const resizeObserver = new ResizeObserver(updateHeight);
|
|
262
|
+
resizeObserver.observe(container);
|
|
263
|
+
return () => resizeObserver.disconnect();
|
|
264
|
+
}, []);
|
|
265
|
+
const showSystemSection = systemTables.length > 0 && hasCategoryData && showSystemTables;
|
|
266
|
+
const { topMaxHeight, bottomMaxHeight } = (0, react.useMemo)(() => {
|
|
267
|
+
if (containerHeight === 0) return {
|
|
268
|
+
topMaxHeight: void 0,
|
|
269
|
+
bottomMaxHeight: void 0
|
|
270
|
+
};
|
|
271
|
+
const availableHeight = containerHeight - (SECTION_HEADER_HEIGHT + (showSystemSection ? 40 : 0));
|
|
272
|
+
const halfAvailable = availableHeight / 2;
|
|
273
|
+
const topContentHeight = appTables.length > 0 ? appTables.length * TABLE_ITEM_HEIGHT : EMPTY_STATE_HEIGHT;
|
|
274
|
+
const bottomContentHeight = showSystemSection ? systemTables.length > 0 ? systemTables.length * TABLE_ITEM_HEIGHT : EMPTY_STATE_HEIGHT : 0;
|
|
275
|
+
let topMax;
|
|
276
|
+
let bottomMax;
|
|
277
|
+
if (!showSystemSection) {
|
|
278
|
+
topMax = availableHeight;
|
|
279
|
+
bottomMax = 0;
|
|
280
|
+
} else if (!sidebarSections.system) {
|
|
281
|
+
topMax = availableHeight;
|
|
282
|
+
bottomMax = 0;
|
|
283
|
+
} else if (!sidebarSections.app) {
|
|
284
|
+
topMax = 0;
|
|
285
|
+
bottomMax = availableHeight;
|
|
286
|
+
} else if (topContentHeight <= halfAvailable && bottomContentHeight <= halfAvailable) {
|
|
287
|
+
topMax = topContentHeight;
|
|
288
|
+
bottomMax = bottomContentHeight;
|
|
289
|
+
} else if (topContentHeight <= halfAvailable) {
|
|
290
|
+
topMax = topContentHeight;
|
|
291
|
+
bottomMax = availableHeight - topContentHeight;
|
|
292
|
+
} else {
|
|
293
|
+
topMax = halfAvailable;
|
|
294
|
+
bottomMax = halfAvailable;
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
topMaxHeight: Math.max(topMax, 0),
|
|
298
|
+
bottomMaxHeight: Math.max(bottomMax, 0)
|
|
299
|
+
};
|
|
300
|
+
}, [
|
|
301
|
+
containerHeight,
|
|
302
|
+
appTables.length,
|
|
303
|
+
systemTables.length,
|
|
304
|
+
showSystemSection,
|
|
305
|
+
sidebarSections.app,
|
|
306
|
+
sidebarSections.system
|
|
307
|
+
]);
|
|
308
|
+
const handleTableSelect = (tableId) => {
|
|
309
|
+
const table = tables.find((t) => t.id === tableId);
|
|
310
|
+
if (table) selectTable(table.id, table.name);
|
|
311
|
+
onTableSelect?.(tableId);
|
|
312
|
+
};
|
|
313
|
+
const handleCreateTable = () => {
|
|
314
|
+
openCreateTableCard(stack, (table) => {
|
|
315
|
+
handleTableSelect(table.id);
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
const handleDeleteTable = (tableId, tableName) => {
|
|
319
|
+
setDeleteDialog({
|
|
320
|
+
isOpen: true,
|
|
321
|
+
tableId,
|
|
322
|
+
tableName
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
const handleTableDeleted = (_tableId) => {
|
|
326
|
+
setDeleteDialog({
|
|
327
|
+
isOpen: false,
|
|
328
|
+
tableId: null,
|
|
329
|
+
tableName: null
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipProvider, {
|
|
333
|
+
delayDuration: 150,
|
|
334
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
335
|
+
"data-chat-component": "schema-builder-sidebar",
|
|
336
|
+
"data-chat-table-count": String(tables.length),
|
|
337
|
+
className: require_invalidate_database_entities.cn("border-sidebar-border hidden h-full w-64 flex-col overflow-hidden border-r bg-transparent sm:flex", "px-2 pt-2 2xl:w-72"),
|
|
338
|
+
children: [
|
|
339
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
|
|
340
|
+
className: "sr-only",
|
|
341
|
+
children: "Schema Builder"
|
|
342
|
+
}),
|
|
343
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
344
|
+
className: "shrink-0 p-1",
|
|
345
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
346
|
+
variant: "outline",
|
|
347
|
+
size: "sm",
|
|
348
|
+
className: "w-full",
|
|
349
|
+
onClick: handleCreateTable,
|
|
350
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { className: "h-4 w-4" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
351
|
+
className: "text-xs font-medium",
|
|
352
|
+
children: "Create Table"
|
|
353
|
+
})]
|
|
354
|
+
})
|
|
355
|
+
}),
|
|
356
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
357
|
+
ref: containerRef,
|
|
358
|
+
className: "mt-4 flex min-h-0 flex-1 flex-col gap-2 overflow-hidden",
|
|
359
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableListByCategory, {
|
|
360
|
+
title: "Your Tables",
|
|
361
|
+
tables: appTables,
|
|
362
|
+
selectedTableId,
|
|
363
|
+
isExpanded: sidebarSections.app,
|
|
364
|
+
onToggleExpand: () => toggleSidebarSection("app"),
|
|
365
|
+
onTableSelect: handleTableSelect,
|
|
366
|
+
onTableDelete: handleDeleteTable,
|
|
367
|
+
emptyMessage: "No tables yet",
|
|
368
|
+
maxContentHeight: topMaxHeight
|
|
369
|
+
}), showSystemSection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableListByCategory, {
|
|
370
|
+
title: "System Tables",
|
|
371
|
+
tables: systemTables,
|
|
372
|
+
selectedTableId,
|
|
373
|
+
isExpanded: sidebarSections.system,
|
|
374
|
+
onToggleExpand: () => toggleSidebarSection("system"),
|
|
375
|
+
onTableSelect: handleTableSelect,
|
|
376
|
+
onTableDelete: handleDeleteTable,
|
|
377
|
+
emptyMessage: "No system tables",
|
|
378
|
+
maxContentHeight: bottomMaxHeight
|
|
379
|
+
})]
|
|
380
|
+
}),
|
|
381
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeleteTableDialog, {
|
|
382
|
+
isOpen: deleteDialog.isOpen,
|
|
383
|
+
onOpenChange: (open) => !open && setDeleteDialog({
|
|
384
|
+
isOpen: false,
|
|
385
|
+
tableId: null,
|
|
386
|
+
tableName: null
|
|
387
|
+
}),
|
|
388
|
+
tableId: deleteDialog.tableId,
|
|
389
|
+
tableName: deleteDialog.tableName,
|
|
390
|
+
onTableDeleted: handleTableDeleted
|
|
391
|
+
})
|
|
392
|
+
]
|
|
393
|
+
})
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function TableListByCategory({ title, tables, selectedTableId, isExpanded, onToggleExpand, onTableSelect, onTableDelete, emptyMessage = "No tables", maxContentHeight }) {
|
|
397
|
+
const hasSelectedItem = selectedTableId ? tables.some((t) => t.id === selectedTableId) : false;
|
|
398
|
+
const scrollViewportRef = (0, react.useRef)(null);
|
|
399
|
+
const [affordanceState, setAffordanceState] = (0, react.useState)({
|
|
400
|
+
hasOverflow: false,
|
|
401
|
+
showTopBlur: false,
|
|
402
|
+
showBottomBlur: false
|
|
403
|
+
});
|
|
404
|
+
const scrollViewportStyle = maxContentHeight !== void 0 ? { maxHeight: `${maxContentHeight}px` } : void 0;
|
|
405
|
+
const recomputeAffordanceState = (0, react.useCallback)(() => {
|
|
406
|
+
const viewport = scrollViewportRef.current;
|
|
407
|
+
if (!viewport) return;
|
|
408
|
+
const nextState = getScrollAffordanceState({
|
|
409
|
+
scrollTop: viewport.scrollTop,
|
|
410
|
+
scrollHeight: viewport.scrollHeight,
|
|
411
|
+
clientHeight: viewport.clientHeight
|
|
412
|
+
});
|
|
413
|
+
setAffordanceState((prevState) => prevState.hasOverflow === nextState.hasOverflow && prevState.showTopBlur === nextState.showTopBlur && prevState.showBottomBlur === nextState.showBottomBlur ? prevState : nextState);
|
|
414
|
+
}, []);
|
|
415
|
+
(0, react.useEffect)(() => {
|
|
416
|
+
if (!isExpanded || tables.length === 0) return;
|
|
417
|
+
const viewport = scrollViewportRef.current;
|
|
418
|
+
if (!viewport) return;
|
|
419
|
+
const handleScroll = () => {
|
|
420
|
+
recomputeAffordanceState();
|
|
421
|
+
};
|
|
422
|
+
viewport.addEventListener("scroll", handleScroll, { passive: true });
|
|
423
|
+
const resizeObserver = typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => {
|
|
424
|
+
recomputeAffordanceState();
|
|
425
|
+
}) : null;
|
|
426
|
+
resizeObserver?.observe(viewport);
|
|
427
|
+
const rafId = requestAnimationFrame(() => {
|
|
428
|
+
recomputeAffordanceState();
|
|
429
|
+
});
|
|
430
|
+
const timeoutId = window.setTimeout(() => {
|
|
431
|
+
recomputeAffordanceState();
|
|
432
|
+
}, 220);
|
|
433
|
+
return () => {
|
|
434
|
+
viewport.removeEventListener("scroll", handleScroll);
|
|
435
|
+
resizeObserver?.disconnect();
|
|
436
|
+
cancelAnimationFrame(rafId);
|
|
437
|
+
window.clearTimeout(timeoutId);
|
|
438
|
+
};
|
|
439
|
+
}, [
|
|
440
|
+
isExpanded,
|
|
441
|
+
tables.length,
|
|
442
|
+
maxContentHeight,
|
|
443
|
+
recomputeAffordanceState
|
|
444
|
+
]);
|
|
445
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_collapsible.Collapsible, {
|
|
446
|
+
open: isExpanded,
|
|
447
|
+
onOpenChange: onToggleExpand,
|
|
448
|
+
className: "flex min-h-0 shrink-0 flex-col",
|
|
449
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_collapsible.CollapsibleTrigger, {
|
|
450
|
+
className: require_invalidate_database_entities.cn("group flex w-full items-center gap-2 rounded-lg py-1.5 pr-2 pl-1 transition-colors duration-150", "bg-card hover:bg-muted/50", isExpanded && "bg-muted/50"),
|
|
451
|
+
children: [
|
|
452
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.motion.div, {
|
|
453
|
+
animate: { rotate: isExpanded ? 90 : 0 },
|
|
454
|
+
transition: {
|
|
455
|
+
type: "spring",
|
|
456
|
+
stiffness: 400,
|
|
457
|
+
damping: 25
|
|
458
|
+
},
|
|
459
|
+
className: "flex shrink-0 items-center justify-center",
|
|
460
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: "text-muted-foreground/60 h-3.5 w-3.5" })
|
|
461
|
+
}),
|
|
462
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
463
|
+
className: "text-muted-foreground text-xs font-medium",
|
|
464
|
+
children: title
|
|
465
|
+
}),
|
|
466
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
467
|
+
className: "ml-auto flex items-center gap-1.5",
|
|
468
|
+
children: [!isExpanded && hasSelectedItem && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
469
|
+
className: "bg-primary/50 h-1.5 w-1.5 rounded-full",
|
|
470
|
+
"aria-label": "Contains selected item"
|
|
471
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
472
|
+
className: "text-muted-foreground/70 text-[10px] tabular-nums",
|
|
473
|
+
children: tables.length
|
|
474
|
+
})]
|
|
475
|
+
})
|
|
476
|
+
]
|
|
477
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.AnimatePresence, {
|
|
478
|
+
initial: false,
|
|
479
|
+
children: isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.motion.div, {
|
|
480
|
+
"data-testid": `collapsible-content-${title}`,
|
|
481
|
+
initial: {
|
|
482
|
+
opacity: 0,
|
|
483
|
+
y: -4
|
|
484
|
+
},
|
|
485
|
+
animate: {
|
|
486
|
+
opacity: 1,
|
|
487
|
+
y: 0
|
|
488
|
+
},
|
|
489
|
+
exit: {
|
|
490
|
+
opacity: 0,
|
|
491
|
+
y: -4
|
|
492
|
+
},
|
|
493
|
+
transition: {
|
|
494
|
+
...require_use_update_table.springs.stiff,
|
|
495
|
+
opacity: {
|
|
496
|
+
duration: require_use_update_table.durations.fast,
|
|
497
|
+
ease: require_use_update_table.easings.easeOut
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
className: "min-h-0 overflow-hidden",
|
|
501
|
+
children: tables.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
502
|
+
className: "relative mt-2 min-h-0",
|
|
503
|
+
children: [
|
|
504
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
505
|
+
ref: scrollViewportRef,
|
|
506
|
+
style: scrollViewportStyle,
|
|
507
|
+
className: "scrollbar-neutral-thin min-h-0 overflow-x-hidden overflow-y-auto",
|
|
508
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
509
|
+
className: "space-y-0.5 px-1 py-2",
|
|
510
|
+
children: tables.map((table) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableItem, {
|
|
511
|
+
table,
|
|
512
|
+
isSelected: selectedTableId === table.id,
|
|
513
|
+
onSelect: onTableSelect,
|
|
514
|
+
onDelete: onTableDelete
|
|
515
|
+
}, table.id))
|
|
516
|
+
})
|
|
517
|
+
}),
|
|
518
|
+
affordanceState.showTopBlur && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_progressive_blur.ProgressiveBlur, {
|
|
519
|
+
position: "top",
|
|
520
|
+
height: "14%",
|
|
521
|
+
blurPx: 4,
|
|
522
|
+
surface: "background",
|
|
523
|
+
intensity: .1
|
|
524
|
+
}),
|
|
525
|
+
affordanceState.showBottomBlur && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_progressive_blur.ProgressiveBlur, {
|
|
526
|
+
position: "bottom",
|
|
527
|
+
height: "16%",
|
|
528
|
+
blurPx: 4,
|
|
529
|
+
surface: "background",
|
|
530
|
+
intensity: .12
|
|
531
|
+
})
|
|
532
|
+
]
|
|
533
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
534
|
+
className: "flex flex-col items-center justify-center py-6 text-center",
|
|
535
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
536
|
+
className: "bg-muted mb-2 flex h-10 w-10 items-center justify-center rounded-full",
|
|
537
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_remixicon_react.RiDatabaseLine, { className: "text-muted-foreground h-5 w-5" })
|
|
538
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
539
|
+
className: "text-muted-foreground text-xs",
|
|
540
|
+
children: emptyMessage
|
|
541
|
+
})]
|
|
542
|
+
})
|
|
543
|
+
})
|
|
544
|
+
})]
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
function TableItem({ table, isSelected, onSelect, onDelete }) {
|
|
548
|
+
const [isMenuOpen, setIsMenuOpen] = (0, react.useState)(false);
|
|
549
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
550
|
+
"data-testid": "table-item",
|
|
551
|
+
role: "button",
|
|
552
|
+
tabIndex: 0,
|
|
553
|
+
className: require_invalidate_database_entities.cn(`group relative my-1 flex min-h-10 cursor-pointer items-center justify-between rounded-lg px-2
|
|
554
|
+
transition-[background-color,color,box-shadow,scale] duration-150 ease-out motion-safe:active:scale-[0.96]`, isSelected ? "bg-primary/10 text-foreground ring-primary/30 dark:bg-primary/15 dark:ring-primary/40 ring-1" : "text-muted-foreground hover:text-foreground"),
|
|
555
|
+
onClick: () => onSelect(table.id),
|
|
556
|
+
onKeyDown: (event) => {
|
|
557
|
+
require_keyboard_activation.handleActivationKeyDown(event, () => onSelect(table.id));
|
|
558
|
+
},
|
|
559
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
560
|
+
className: "flex min-w-0 flex-1 items-center",
|
|
561
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OverflowAwareTableName, { name: table.name })
|
|
562
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_dropdown_menu.DropdownMenu, {
|
|
563
|
+
open: isMenuOpen,
|
|
564
|
+
onOpenChange: setIsMenuOpen,
|
|
565
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_dropdown_menu.DropdownMenuTrigger, {
|
|
566
|
+
asChild: true,
|
|
567
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
568
|
+
variant: "ghost",
|
|
569
|
+
size: "sm",
|
|
570
|
+
"aria-label": `Actions for ${table.name}`,
|
|
571
|
+
className: require_invalidate_database_entities.cn(`size-8 rounded-md p-0 transition-[background-color,opacity,scale] duration-150 ease-out
|
|
572
|
+
motion-safe:active:scale-[0.96]`, "opacity-0 group-hover:opacity-100", "hover:bg-muted-foreground/10", isMenuOpen && "bg-muted-foreground/10 opacity-100"),
|
|
573
|
+
onClick: (e) => e.stopPropagation(),
|
|
574
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.MoreVertical, { className: "h-3 w-3" })
|
|
575
|
+
})
|
|
576
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_dropdown_menu.DropdownMenuContent, {
|
|
577
|
+
align: "end",
|
|
578
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_dropdown_menu.DropdownMenuItem, {
|
|
579
|
+
className: "text-destructive hover:bg-destructive/10 focus:bg-destructive/10 hover:text-destructive\n focus:text-destructive data-[disabled=true]:text-muted-foreground",
|
|
580
|
+
onClick: (e) => {
|
|
581
|
+
e.stopPropagation();
|
|
582
|
+
onDelete(table.id, table.name);
|
|
583
|
+
},
|
|
584
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "mr-2 h-4 w-4" }), "Delete"]
|
|
585
|
+
})
|
|
586
|
+
})]
|
|
587
|
+
})]
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
function OverflowAwareTableName({ name }) {
|
|
591
|
+
const containerRef = (0, react.useRef)(null);
|
|
592
|
+
const measureRef = (0, react.useRef)(null);
|
|
593
|
+
const [displayName, setDisplayName] = (0, react.useState)(name);
|
|
594
|
+
const [isOverflowing, setIsOverflowing] = (0, react.useState)(false);
|
|
595
|
+
const recompute = (0, react.useCallback)(() => {
|
|
596
|
+
const container = containerRef.current;
|
|
597
|
+
const measureElement = measureRef.current;
|
|
598
|
+
if (!container || !measureElement) return;
|
|
599
|
+
const maxWidth = container.clientWidth;
|
|
600
|
+
if (maxWidth <= 0) {
|
|
601
|
+
setDisplayName(name);
|
|
602
|
+
setIsOverflowing(false);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const measure = (value) => {
|
|
606
|
+
measureElement.textContent = value;
|
|
607
|
+
return measureElement.scrollWidth;
|
|
608
|
+
};
|
|
609
|
+
const next = getTableNameDisplayState(name, maxWidth, measure);
|
|
610
|
+
setDisplayName((prev) => prev === next.displayName ? prev : next.displayName);
|
|
611
|
+
setIsOverflowing((prev) => prev === next.isOverflowing ? prev : next.isOverflowing);
|
|
612
|
+
}, [name]);
|
|
613
|
+
(0, react.useLayoutEffect)(() => {
|
|
614
|
+
recompute();
|
|
615
|
+
}, [recompute]);
|
|
616
|
+
(0, react.useEffect)(() => {
|
|
617
|
+
const element = containerRef.current;
|
|
618
|
+
if (!element || typeof ResizeObserver === "undefined") return;
|
|
619
|
+
const observer = new ResizeObserver(() => {
|
|
620
|
+
recompute();
|
|
621
|
+
});
|
|
622
|
+
observer.observe(element);
|
|
623
|
+
return () => observer.disconnect();
|
|
624
|
+
}, [recompute]);
|
|
625
|
+
const triggerLabel = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
626
|
+
ref: containerRef,
|
|
627
|
+
className: "relative block max-w-full min-w-0 text-xs",
|
|
628
|
+
"aria-label": isOverflowing ? name : void 0,
|
|
629
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
630
|
+
className: "block max-w-full min-w-0 truncate",
|
|
631
|
+
children: displayName
|
|
632
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
633
|
+
ref: measureRef,
|
|
634
|
+
"aria-hidden": "true",
|
|
635
|
+
className: "pointer-events-none invisible absolute top-0 left-0 text-xs whitespace-nowrap"
|
|
636
|
+
})]
|
|
637
|
+
});
|
|
638
|
+
if (!isOverflowing) return triggerLabel;
|
|
639
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
|
|
640
|
+
asChild: true,
|
|
641
|
+
children: triggerLabel
|
|
642
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, {
|
|
643
|
+
side: "right",
|
|
644
|
+
align: "start",
|
|
645
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
646
|
+
className: "text-xs font-medium",
|
|
647
|
+
children: name
|
|
648
|
+
})
|
|
649
|
+
})] });
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
//#endregion
|
|
653
|
+
Object.defineProperty(exports, 'SchemaBuilderMobileNavigation', {
|
|
654
|
+
enumerable: true,
|
|
655
|
+
get: function () {
|
|
656
|
+
return SchemaBuilderMobileNavigation;
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
Object.defineProperty(exports, 'SchemaBuilderSidebar', {
|
|
660
|
+
enumerable: true,
|
|
661
|
+
get: function () {
|
|
662
|
+
return SchemaBuilderSidebar;
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
Object.defineProperty(exports, 'useDeleteTable', {
|
|
666
|
+
enumerable: true,
|
|
667
|
+
get: function () {
|
|
668
|
+
return useDeleteTable;
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
//# sourceMappingURL=schema-builder-sidebar-L3TcQeQr.cjs.map
|