@verikit/vue 0.23.1
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.md +9 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/use-verikit-client.d.ts +42 -0
- package/dist/client/use-verikit-client.d.ts.map +1 -0
- package/dist/client/use-verikit-client.js +39 -0
- package/dist/components/button.d.ts +36 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +53 -0
- package/dist/components/checkbox.d.ts +45 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +44 -0
- package/dist/components/dialog.d.ts +86 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +157 -0
- package/dist/components/input.d.ts +5 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +17 -0
- package/dist/components/label.d.ts +5 -0
- package/dist/components/label.d.ts.map +1 -0
- package/dist/components/label.js +17 -0
- package/dist/components/select.d.ts +164 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +219 -0
- package/dist/components/textarea.d.ts +5 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +17 -0
- package/dist/fields/field-shell.d.ts +64 -0
- package/dist/fields/field-shell.d.ts.map +1 -0
- package/dist/fields/field-shell.js +61 -0
- package/dist/fields/index.d.ts +7 -0
- package/dist/fields/index.d.ts.map +1 -0
- package/dist/fields/index.js +3 -0
- package/dist/fields/inputs.d.ts +372 -0
- package/dist/fields/inputs.d.ts.map +1 -0
- package/dist/fields/inputs.js +306 -0
- package/dist/fields/registry.d.ts +382 -0
- package/dist/fields/registry.d.ts.map +1 -0
- package/dist/fields/registry.js +31 -0
- package/dist/fields/types.d.ts +36 -0
- package/dist/fields/types.d.ts.map +1 -0
- package/dist/fields/types.js +1 -0
- package/dist/form/index.d.ts +11 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +5 -0
- package/dist/form/use-verikit-form.d.ts +40 -0
- package/dist/form/use-verikit-form.d.ts.map +1 -0
- package/dist/form/use-verikit-form.js +72 -0
- package/dist/form/use-verikit-schema-tree-form.d.ts +47 -0
- package/dist/form/use-verikit-schema-tree-form.d.ts.map +1 -0
- package/dist/form/use-verikit-schema-tree-form.js +96 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +2 -0
- package/dist/layout/render-schema-node.d.ts +9 -0
- package/dist/layout/render-schema-node.d.ts.map +1 -0
- package/dist/layout/render-schema-node.js +265 -0
- package/dist/layout/types.d.ts +68 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/types.js +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/query/index.d.ts +13 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +6 -0
- package/dist/query/use-resource-form.d.ts +39 -0
- package/dist/query/use-resource-form.d.ts.map +1 -0
- package/dist/query/use-resource-form.js +32 -0
- package/dist/query/use-resource-mutations.d.ts +40 -0
- package/dist/query/use-resource-mutations.d.ts.map +1 -0
- package/dist/query/use-resource-mutations.js +104 -0
- package/dist/query/use-resource-queries.d.ts +15 -0
- package/dist/query/use-resource-queries.d.ts.map +1 -0
- package/dist/query/use-resource-queries.js +35 -0
- package/dist/query/use-resource-schema-tree-form.d.ts +36 -0
- package/dist/query/use-resource-schema-tree-form.d.ts.map +1 -0
- package/dist/query/use-resource-schema-tree-form.js +42 -0
- package/dist/query/use-resource-table.d.ts +48 -0
- package/dist/query/use-resource-table.d.ts.map +1 -0
- package/dist/query/use-resource-table.js +104 -0
- package/dist/relationships/belongs-to-field.d.ts +91 -0
- package/dist/relationships/belongs-to-field.d.ts.map +1 -0
- package/dist/relationships/belongs-to-field.js +107 -0
- package/dist/relationships/index.d.ts +2 -0
- package/dist/relationships/index.d.ts.map +1 -0
- package/dist/relationships/index.js +1 -0
- package/dist/resource/index.d.ts +5 -0
- package/dist/resource/index.d.ts.map +1 -0
- package/dist/resource/index.js +2 -0
- package/dist/resource/resource-form.d.ts +122 -0
- package/dist/resource/resource-form.d.ts.map +1 -0
- package/dist/resource/resource-form.js +83 -0
- package/dist/resource/resource-table-filters.d.ts +54 -0
- package/dist/resource/resource-table-filters.d.ts.map +1 -0
- package/dist/resource/resource-table-filters.js +283 -0
- package/dist/resource/resource-table.d.ts +93 -0
- package/dist/resource/resource-table.d.ts.map +1 -0
- package/dist/resource/resource-table.js +562 -0
- package/package.json +86 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { defineComponent, h, ref } from "vue";
|
|
2
|
+
import { ArrowDownIcon, ArrowUpIcon, ChevronLeftIcon, ChevronRightIcon, ChevronsUpDownIcon, PencilIcon, PlusIcon, SlidersHorizontalIcon, Trash2Icon, } from "lucide-vue-next";
|
|
3
|
+
import { Button } from "#components/button";
|
|
4
|
+
import { Checkbox } from "#components/checkbox";
|
|
5
|
+
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
|
|
6
|
+
import { Input } from "#components/input";
|
|
7
|
+
import { cn } from "#lib/utils";
|
|
8
|
+
import { recordId } from "@verikit/ui-core/query/optimistic";
|
|
9
|
+
import { useDeleteResource } from "../query/use-resource-mutations.js";
|
|
10
|
+
import { useResourceTable, } from "../query/use-resource-table.js";
|
|
11
|
+
import { ResourceForm } from "./resource-form.js";
|
|
12
|
+
import { filterableFields, ResourceTableFilterPanel, } from "./resource-table-filters.js";
|
|
13
|
+
/**
|
|
14
|
+
* True for an error whose `status` is 403 (permission denied). Duck-typed on
|
|
15
|
+
* `status`, not `instanceof VerikitClientError`.
|
|
16
|
+
*/
|
|
17
|
+
function isPermissionDenied(error) {
|
|
18
|
+
return (typeof error === "object" &&
|
|
19
|
+
error !== null &&
|
|
20
|
+
"status" in error &&
|
|
21
|
+
error.status === 403);
|
|
22
|
+
}
|
|
23
|
+
// `useResourceTable` always sets `header` to `field.label` (a required,
|
|
24
|
+
// non-empty string field on every `FieldSchema`), so this always reads a
|
|
25
|
+
// plain string back — no function-header or missing-header case to guard.
|
|
26
|
+
function headerText(header) {
|
|
27
|
+
return header.column.columnDef.header;
|
|
28
|
+
}
|
|
29
|
+
function cellText(value) {
|
|
30
|
+
if (value === null || value === undefined) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof Date) {
|
|
34
|
+
return value.toLocaleString();
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === "boolean") {
|
|
37
|
+
return value ? "Yes" : "No";
|
|
38
|
+
}
|
|
39
|
+
return String(value);
|
|
40
|
+
}
|
|
41
|
+
function sortIcon(direction) {
|
|
42
|
+
if (direction === "asc") {
|
|
43
|
+
return h(ArrowUpIcon, { class: "size-3.5" });
|
|
44
|
+
}
|
|
45
|
+
if (direction === "desc") {
|
|
46
|
+
return h(ArrowDownIcon, { class: "size-3.5" });
|
|
47
|
+
}
|
|
48
|
+
return h(ChevronsUpDownIcon, { class: "size-3.5 opacity-50" });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A responsive resource table with search, sorting, pagination, and a
|
|
52
|
+
* mobile card layout. Standard CRUD actions and custom row actions are opt-in.
|
|
53
|
+
*/
|
|
54
|
+
export const ResourceTable = defineComponent({
|
|
55
|
+
name: "ResourceTable",
|
|
56
|
+
props: {
|
|
57
|
+
resource: {
|
|
58
|
+
type: Object,
|
|
59
|
+
required: true,
|
|
60
|
+
},
|
|
61
|
+
pageSize: {
|
|
62
|
+
type: Number,
|
|
63
|
+
default: undefined,
|
|
64
|
+
},
|
|
65
|
+
actions: { type: Boolean, default: false },
|
|
66
|
+
renderActions: {
|
|
67
|
+
type: Function,
|
|
68
|
+
default: undefined,
|
|
69
|
+
},
|
|
70
|
+
renderBulkActions: {
|
|
71
|
+
type: Function,
|
|
72
|
+
default: undefined,
|
|
73
|
+
},
|
|
74
|
+
emptyState: {
|
|
75
|
+
type: null,
|
|
76
|
+
required: false,
|
|
77
|
+
},
|
|
78
|
+
className: {
|
|
79
|
+
type: String,
|
|
80
|
+
default: undefined,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
setup(props) {
|
|
84
|
+
const { table, isLoading, error, fields, filters, setFilters } = useResourceTable(props.resource, { pageSize: props.pageSize });
|
|
85
|
+
const createOpen = ref(false);
|
|
86
|
+
const createDenied = ref(false);
|
|
87
|
+
const editRecord = ref(null);
|
|
88
|
+
const deleteRecord = ref(null);
|
|
89
|
+
const deniedRows = ref({});
|
|
90
|
+
const filtersOpen = ref(false);
|
|
91
|
+
const bulkDeleteOpen = ref(false);
|
|
92
|
+
const bulkDeleteError = ref(null);
|
|
93
|
+
const bulkDeleting = ref(false);
|
|
94
|
+
const deleteMutation = useDeleteResource(props.resource.name, {
|
|
95
|
+
onError: (mutationError, id) => {
|
|
96
|
+
if (isPermissionDenied(mutationError)) {
|
|
97
|
+
deniedRows.value = {
|
|
98
|
+
...deniedRows.value,
|
|
99
|
+
[id]: { ...deniedRows.value[id], delete: true },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onSuccess: () => {
|
|
104
|
+
deleteRecord.value = null;
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
function openDeleteDialog(record) {
|
|
108
|
+
deleteMutation.reset();
|
|
109
|
+
deleteRecord.value = record;
|
|
110
|
+
}
|
|
111
|
+
function clearSelection() {
|
|
112
|
+
table.toggleAllRowsSelected(false);
|
|
113
|
+
}
|
|
114
|
+
function openBulkDeleteDialog() {
|
|
115
|
+
bulkDeleteError.value = null;
|
|
116
|
+
bulkDeleteOpen.value = true;
|
|
117
|
+
}
|
|
118
|
+
async function confirmBulkDelete() {
|
|
119
|
+
bulkDeleting.value = true;
|
|
120
|
+
bulkDeleteError.value = null;
|
|
121
|
+
const selectedRecords = table
|
|
122
|
+
.getSelectedRowModel()
|
|
123
|
+
.rows.map((row) => row.original);
|
|
124
|
+
const ids = selectedRecords
|
|
125
|
+
.map((record) => recordId(record))
|
|
126
|
+
.filter((id) => id !== undefined);
|
|
127
|
+
const results = await Promise.allSettled(ids.map((id) => deleteMutation.mutateAsync(id)));
|
|
128
|
+
const failedCount = results.filter((result) => result.status === "rejected").length;
|
|
129
|
+
bulkDeleting.value = false;
|
|
130
|
+
if (failedCount > 0) {
|
|
131
|
+
bulkDeleteError.value = `${failedCount} of ${ids.length} couldn't be deleted.`;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
bulkDeleteOpen.value = false;
|
|
135
|
+
clearSelection();
|
|
136
|
+
}
|
|
137
|
+
function handleEditError(id) {
|
|
138
|
+
return (mutationError) => {
|
|
139
|
+
if (isPermissionDenied(mutationError)) {
|
|
140
|
+
deniedRows.value = {
|
|
141
|
+
...deniedRows.value,
|
|
142
|
+
[id]: { ...deniedRows.value[id], update: true },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function handleCreateError(mutationError) {
|
|
148
|
+
if (isPermissionDenied(mutationError)) {
|
|
149
|
+
createDenied.value = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function builtInRowActions(record) {
|
|
153
|
+
const id = recordId(record);
|
|
154
|
+
const denied = deniedRows.value[id];
|
|
155
|
+
return [
|
|
156
|
+
denied?.update
|
|
157
|
+
? null
|
|
158
|
+
: h(Button, {
|
|
159
|
+
type: "button",
|
|
160
|
+
variant: "ghost",
|
|
161
|
+
size: "icon-sm",
|
|
162
|
+
"aria-label": "Edit",
|
|
163
|
+
onClick: () => {
|
|
164
|
+
editRecord.value = record;
|
|
165
|
+
},
|
|
166
|
+
}, { default: () => h(PencilIcon) }),
|
|
167
|
+
denied?.delete
|
|
168
|
+
? null
|
|
169
|
+
: h(Button, {
|
|
170
|
+
type: "button",
|
|
171
|
+
variant: "ghost",
|
|
172
|
+
size: "icon-sm",
|
|
173
|
+
"aria-label": "Delete",
|
|
174
|
+
onClick: () => openDeleteDialog(record),
|
|
175
|
+
}, { default: () => h(Trash2Icon) }),
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
function rowActions(record) {
|
|
179
|
+
return h("div", { class: "flex items-center justify-end gap-1" }, [
|
|
180
|
+
props.actions ? builtInRowActions(record) : null,
|
|
181
|
+
props.renderActions ? props.renderActions(record) : null,
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
return () => {
|
|
185
|
+
const selectedRows = table.getSelectedRowModel().rows;
|
|
186
|
+
const selectedRecords = selectedRows.map((row) => row.original);
|
|
187
|
+
const selectedCount = selectedRows.length;
|
|
188
|
+
const editId = editRecord.value ? recordId(editRecord.value) : undefined;
|
|
189
|
+
const deleteId = deleteRecord.value
|
|
190
|
+
? recordId(deleteRecord.value)
|
|
191
|
+
: undefined;
|
|
192
|
+
const hasActionsColumn = props.actions || Boolean(props.renderActions);
|
|
193
|
+
const hasSelectionColumn = props.actions || Boolean(props.renderBulkActions);
|
|
194
|
+
const hasFilterableFields = filterableFields(fields).length > 0;
|
|
195
|
+
const activeFilterCount = Object.keys(filters.value).length;
|
|
196
|
+
// TanStack always returns at least one header group for a mounted table
|
|
197
|
+
// (even with zero registered columns, its `headers` array is just empty).
|
|
198
|
+
const headerGroup = table.getHeaderGroups()[0];
|
|
199
|
+
const rows = table.getRowModel().rows;
|
|
200
|
+
const columnCount = headerGroup.headers.length +
|
|
201
|
+
(hasActionsColumn ? 1 : 0) +
|
|
202
|
+
(hasSelectionColumn ? 1 : 0);
|
|
203
|
+
const resolvedEmptyState = props.emptyState ?? "No records found.";
|
|
204
|
+
return h("div", { class: cn("w-full", props.className) }, [
|
|
205
|
+
h("div", { class: "flex items-center justify-between gap-2 pb-3" }, [
|
|
206
|
+
h("div", { class: "flex items-center gap-2" }, [
|
|
207
|
+
h(Input, {
|
|
208
|
+
type: "search",
|
|
209
|
+
placeholder: "Search...",
|
|
210
|
+
value: table.store.state.globalFilter,
|
|
211
|
+
onInput: (event) => table.setGlobalFilter(event.target.value),
|
|
212
|
+
class: "max-w-xs",
|
|
213
|
+
}),
|
|
214
|
+
hasFilterableFields
|
|
215
|
+
? h(Button, {
|
|
216
|
+
type: "button",
|
|
217
|
+
variant: activeFilterCount > 0 ? "secondary" : "outline",
|
|
218
|
+
size: "sm",
|
|
219
|
+
onClick: () => {
|
|
220
|
+
filtersOpen.value = !filtersOpen.value;
|
|
221
|
+
},
|
|
222
|
+
"aria-expanded": filtersOpen.value,
|
|
223
|
+
}, {
|
|
224
|
+
default: () => [
|
|
225
|
+
h(SlidersHorizontalIcon),
|
|
226
|
+
"Filters",
|
|
227
|
+
activeFilterCount > 0 ? ` (${activeFilterCount})` : "",
|
|
228
|
+
],
|
|
229
|
+
})
|
|
230
|
+
: null,
|
|
231
|
+
activeFilterCount > 0
|
|
232
|
+
? h(Button, {
|
|
233
|
+
type: "button",
|
|
234
|
+
variant: "ghost",
|
|
235
|
+
size: "sm",
|
|
236
|
+
onClick: () => setFilters({}),
|
|
237
|
+
}, { default: () => "Clear filters" })
|
|
238
|
+
: null,
|
|
239
|
+
]),
|
|
240
|
+
props.actions && !createDenied.value
|
|
241
|
+
? h(Button, {
|
|
242
|
+
type: "button",
|
|
243
|
+
size: "sm",
|
|
244
|
+
onClick: () => {
|
|
245
|
+
createOpen.value = true;
|
|
246
|
+
},
|
|
247
|
+
}, { default: () => [h(PlusIcon), "New"] })
|
|
248
|
+
: null,
|
|
249
|
+
]),
|
|
250
|
+
filtersOpen.value && hasFilterableFields
|
|
251
|
+
? h("div", { class: "pb-3" }, [
|
|
252
|
+
h(ResourceTableFilterPanel, {
|
|
253
|
+
fields,
|
|
254
|
+
filters: filters.value,
|
|
255
|
+
onFiltersChange: setFilters,
|
|
256
|
+
}),
|
|
257
|
+
])
|
|
258
|
+
: null,
|
|
259
|
+
selectedCount > 0
|
|
260
|
+
? h("div", {
|
|
261
|
+
class: "mb-3 flex items-center justify-between gap-2 rounded-lg border border-border bg-muted/50 px-3 py-2",
|
|
262
|
+
}, [
|
|
263
|
+
h("span", { class: "text-sm text-muted-foreground" }, `${selectedCount} selected`),
|
|
264
|
+
h("div", { class: "flex items-center gap-2" }, [
|
|
265
|
+
props.renderBulkActions
|
|
266
|
+
? props.renderBulkActions(selectedRecords, clearSelection)
|
|
267
|
+
: null,
|
|
268
|
+
props.actions
|
|
269
|
+
? h(Button, {
|
|
270
|
+
type: "button",
|
|
271
|
+
variant: "destructive",
|
|
272
|
+
size: "sm",
|
|
273
|
+
onClick: openBulkDeleteDialog,
|
|
274
|
+
}, { default: () => [h(Trash2Icon), "Delete selected"] })
|
|
275
|
+
: null,
|
|
276
|
+
h(Button, {
|
|
277
|
+
type: "button",
|
|
278
|
+
variant: "outline",
|
|
279
|
+
size: "sm",
|
|
280
|
+
onClick: clearSelection,
|
|
281
|
+
}, { default: () => "Clear" }),
|
|
282
|
+
]),
|
|
283
|
+
])
|
|
284
|
+
: null,
|
|
285
|
+
error.value
|
|
286
|
+
? h("p", { role: "alert", class: "pb-3 text-sm text-destructive" }, error.value.message)
|
|
287
|
+
: null,
|
|
288
|
+
h("div", {
|
|
289
|
+
class: "hidden overflow-x-auto rounded-lg border border-border md:block",
|
|
290
|
+
}, [
|
|
291
|
+
h("table", { class: "w-full text-left text-sm" }, [
|
|
292
|
+
h("thead", { class: "bg-muted/50 text-muted-foreground" }, [
|
|
293
|
+
h("tr", {}, [
|
|
294
|
+
hasSelectionColumn
|
|
295
|
+
? h("th", { class: "w-8 px-3 py-2" }, [
|
|
296
|
+
h(Checkbox, {
|
|
297
|
+
"aria-label": "Select all rows",
|
|
298
|
+
checked: rows.length > 0 && table.getIsAllPageRowsSelected(),
|
|
299
|
+
indeterminate: !table.getIsAllPageRowsSelected() &&
|
|
300
|
+
table.getIsSomePageRowsSelected(),
|
|
301
|
+
onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked === true),
|
|
302
|
+
}),
|
|
303
|
+
])
|
|
304
|
+
: null,
|
|
305
|
+
...headerGroup.headers.map((header) => h("th", { key: header.id, class: "px-3 py-2 font-medium" }, [
|
|
306
|
+
header.column.getCanSort()
|
|
307
|
+
? h("button", {
|
|
308
|
+
type: "button",
|
|
309
|
+
class: "inline-flex items-center gap-1 hover:text-foreground",
|
|
310
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
311
|
+
}, [
|
|
312
|
+
headerText(header),
|
|
313
|
+
sortIcon(header.column.getIsSorted()),
|
|
314
|
+
])
|
|
315
|
+
: headerText(header),
|
|
316
|
+
])),
|
|
317
|
+
hasActionsColumn ? h("th", { class: "px-3 py-2" }) : null,
|
|
318
|
+
]),
|
|
319
|
+
]),
|
|
320
|
+
h("tbody", {}, [
|
|
321
|
+
isLoading.value
|
|
322
|
+
? h("tr", {}, [
|
|
323
|
+
h("td", {
|
|
324
|
+
colspan: columnCount,
|
|
325
|
+
class: "px-3 py-6 text-center text-muted-foreground",
|
|
326
|
+
}, "Loading…"),
|
|
327
|
+
])
|
|
328
|
+
: rows.length === 0
|
|
329
|
+
? h("tr", {}, [
|
|
330
|
+
h("td", {
|
|
331
|
+
colspan: columnCount,
|
|
332
|
+
class: "px-3 py-6 text-center text-muted-foreground",
|
|
333
|
+
}, resolvedEmptyState),
|
|
334
|
+
])
|
|
335
|
+
: rows.map((row) => h("tr", { key: row.id, class: "border-t border-border" }, [
|
|
336
|
+
hasSelectionColumn
|
|
337
|
+
? h("td", { class: "px-3 py-2" }, [
|
|
338
|
+
h(Checkbox, {
|
|
339
|
+
"aria-label": "Select row",
|
|
340
|
+
checked: row.getIsSelected(),
|
|
341
|
+
onCheckedChange: (checked) => row.toggleSelected(checked === true),
|
|
342
|
+
}),
|
|
343
|
+
])
|
|
344
|
+
: null,
|
|
345
|
+
...row
|
|
346
|
+
.getAllCells()
|
|
347
|
+
.map((cell) => h("td", { key: cell.id, class: "px-3 py-2" }, cellText(cell.getValue()))),
|
|
348
|
+
hasActionsColumn
|
|
349
|
+
? h("td", { class: "px-3 py-2 text-right" }, [
|
|
350
|
+
rowActions(row.original),
|
|
351
|
+
])
|
|
352
|
+
: null,
|
|
353
|
+
])),
|
|
354
|
+
]),
|
|
355
|
+
]),
|
|
356
|
+
]),
|
|
357
|
+
h("div", { class: "grid gap-2 md:hidden" }, [
|
|
358
|
+
isLoading.value
|
|
359
|
+
? h("p", { class: "py-6 text-center text-sm text-muted-foreground" }, "Loading…")
|
|
360
|
+
: rows.length === 0
|
|
361
|
+
? h("p", { class: "py-6 text-center text-sm text-muted-foreground" }, resolvedEmptyState)
|
|
362
|
+
: rows.map((row) => h("div", {
|
|
363
|
+
key: row.id,
|
|
364
|
+
class: "rounded-lg border border-border p-3",
|
|
365
|
+
}, [
|
|
366
|
+
hasSelectionColumn
|
|
367
|
+
? h("div", { class: "flex justify-end pb-2" }, [
|
|
368
|
+
h(Checkbox, {
|
|
369
|
+
"aria-label": "Select row",
|
|
370
|
+
checked: row.getIsSelected(),
|
|
371
|
+
onCheckedChange: (checked) => row.toggleSelected(checked === true),
|
|
372
|
+
}),
|
|
373
|
+
])
|
|
374
|
+
: null,
|
|
375
|
+
...row.getAllCells().map((cell) => h("div", {
|
|
376
|
+
key: cell.id,
|
|
377
|
+
class: "flex items-center justify-between gap-2 py-1 text-sm",
|
|
378
|
+
}, [
|
|
379
|
+
h("span", { class: "text-muted-foreground" }, headerText({ column: cell.column })),
|
|
380
|
+
h("span", { class: "text-right" }, cellText(cell.getValue())),
|
|
381
|
+
])),
|
|
382
|
+
hasActionsColumn
|
|
383
|
+
? h("div", { class: "flex justify-end gap-2 pt-2" }, [
|
|
384
|
+
rowActions(row.original),
|
|
385
|
+
])
|
|
386
|
+
: null,
|
|
387
|
+
])),
|
|
388
|
+
]),
|
|
389
|
+
h("div", {
|
|
390
|
+
class: "flex items-center justify-between pt-3 text-sm text-muted-foreground",
|
|
391
|
+
}, [
|
|
392
|
+
h("span", {}, `Page ${table.store.state.pagination.pageIndex + 1} of ${Math.max(1, table.getPageCount())} · ${table.getRowCount()} total`),
|
|
393
|
+
h("div", { class: "flex gap-1" }, [
|
|
394
|
+
h(Button, {
|
|
395
|
+
type: "button",
|
|
396
|
+
variant: "outline",
|
|
397
|
+
size: "icon-sm",
|
|
398
|
+
disabled: !table.getCanPreviousPage(),
|
|
399
|
+
onClick: () => table.previousPage(),
|
|
400
|
+
"aria-label": "Previous page",
|
|
401
|
+
}, { default: () => h(ChevronLeftIcon) }),
|
|
402
|
+
h(Button, {
|
|
403
|
+
type: "button",
|
|
404
|
+
variant: "outline",
|
|
405
|
+
size: "icon-sm",
|
|
406
|
+
disabled: !table.getCanNextPage(),
|
|
407
|
+
onClick: () => table.nextPage(),
|
|
408
|
+
"aria-label": "Next page",
|
|
409
|
+
}, { default: () => h(ChevronRightIcon) }),
|
|
410
|
+
]),
|
|
411
|
+
]),
|
|
412
|
+
props.actions
|
|
413
|
+
? h(Dialog, {
|
|
414
|
+
open: createOpen.value,
|
|
415
|
+
onOpenChange: (open) => {
|
|
416
|
+
createOpen.value = open;
|
|
417
|
+
},
|
|
418
|
+
}, {
|
|
419
|
+
default: () => h(DialogContent, {}, {
|
|
420
|
+
default: () => [
|
|
421
|
+
h(DialogHeader, {}, {
|
|
422
|
+
default: () => h(DialogTitle, {}, { default: () => `New ${props.resource.name}` }),
|
|
423
|
+
}),
|
|
424
|
+
h(ResourceForm, {
|
|
425
|
+
resource: props.resource,
|
|
426
|
+
onSuccess: () => {
|
|
427
|
+
createOpen.value = false;
|
|
428
|
+
},
|
|
429
|
+
onError: handleCreateError,
|
|
430
|
+
submitLabel: "Create",
|
|
431
|
+
}),
|
|
432
|
+
],
|
|
433
|
+
}),
|
|
434
|
+
})
|
|
435
|
+
: null,
|
|
436
|
+
props.actions
|
|
437
|
+
? h(Dialog, {
|
|
438
|
+
open: editRecord.value !== null,
|
|
439
|
+
onOpenChange: (open) => {
|
|
440
|
+
if (!open) {
|
|
441
|
+
editRecord.value = null;
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
}, {
|
|
445
|
+
default: () => h(DialogContent, {}, {
|
|
446
|
+
default: () => [
|
|
447
|
+
h(DialogHeader, {}, {
|
|
448
|
+
default: () => h(DialogTitle, {}, {
|
|
449
|
+
default: () => `Edit ${props.resource.name}`,
|
|
450
|
+
}),
|
|
451
|
+
}),
|
|
452
|
+
editRecord.value
|
|
453
|
+
? h(ResourceForm, {
|
|
454
|
+
resource: props.resource,
|
|
455
|
+
id: editId,
|
|
456
|
+
defaultValues: editRecord.value,
|
|
457
|
+
onSuccess: () => {
|
|
458
|
+
editRecord.value = null;
|
|
459
|
+
},
|
|
460
|
+
onError: handleEditError(editId),
|
|
461
|
+
submitLabel: "Save changes",
|
|
462
|
+
})
|
|
463
|
+
: null,
|
|
464
|
+
],
|
|
465
|
+
}),
|
|
466
|
+
})
|
|
467
|
+
: null,
|
|
468
|
+
props.actions
|
|
469
|
+
? h(Dialog, {
|
|
470
|
+
open: deleteRecord.value !== null,
|
|
471
|
+
onOpenChange: (open) => {
|
|
472
|
+
if (!open) {
|
|
473
|
+
deleteRecord.value = null;
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
}, {
|
|
477
|
+
default: () => h(DialogContent, {}, {
|
|
478
|
+
default: () => [
|
|
479
|
+
h(DialogHeader, {}, {
|
|
480
|
+
default: () => [
|
|
481
|
+
h(DialogTitle, {}, {
|
|
482
|
+
default: () => `Delete this ${props.resource.name}?`,
|
|
483
|
+
}),
|
|
484
|
+
h(DialogDescription, {}, { default: () => "This can't be undone." }),
|
|
485
|
+
],
|
|
486
|
+
}),
|
|
487
|
+
deleteMutation.error.value &&
|
|
488
|
+
!isPermissionDenied(deleteMutation.error.value)
|
|
489
|
+
? h("p", {
|
|
490
|
+
role: "alert",
|
|
491
|
+
class: "text-sm text-destructive",
|
|
492
|
+
}, deleteMutation.error.value.message)
|
|
493
|
+
: null,
|
|
494
|
+
h(DialogFooter, {}, {
|
|
495
|
+
default: () => [
|
|
496
|
+
h(DialogClose, { asChild: true }, {
|
|
497
|
+
default: () => h(Button, { type: "button", variant: "outline" }, { default: () => "Cancel" }),
|
|
498
|
+
}),
|
|
499
|
+
h(Button, {
|
|
500
|
+
type: "button",
|
|
501
|
+
variant: "destructive",
|
|
502
|
+
disabled: deleteMutation.isPending.value,
|
|
503
|
+
onClick: () => deleteMutation.mutate(deleteId),
|
|
504
|
+
}, {
|
|
505
|
+
default: () => deleteMutation.isPending.value
|
|
506
|
+
? "Deleting…"
|
|
507
|
+
: "Delete",
|
|
508
|
+
}),
|
|
509
|
+
],
|
|
510
|
+
}),
|
|
511
|
+
],
|
|
512
|
+
}),
|
|
513
|
+
})
|
|
514
|
+
: null,
|
|
515
|
+
props.actions
|
|
516
|
+
? h(Dialog, {
|
|
517
|
+
open: bulkDeleteOpen.value,
|
|
518
|
+
onOpenChange: (open) => {
|
|
519
|
+
if (!open) {
|
|
520
|
+
bulkDeleteOpen.value = false;
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
}, {
|
|
524
|
+
default: () => h(DialogContent, {}, {
|
|
525
|
+
default: () => [
|
|
526
|
+
h(DialogHeader, {}, {
|
|
527
|
+
default: () => [
|
|
528
|
+
h(DialogTitle, {}, {
|
|
529
|
+
default: () => `Delete ${selectedCount} ${props.resource.name}?`,
|
|
530
|
+
}),
|
|
531
|
+
h(DialogDescription, {}, { default: () => "This can't be undone." }),
|
|
532
|
+
],
|
|
533
|
+
}),
|
|
534
|
+
bulkDeleteError.value
|
|
535
|
+
? h("p", {
|
|
536
|
+
role: "alert",
|
|
537
|
+
class: "text-sm text-destructive",
|
|
538
|
+
}, bulkDeleteError.value)
|
|
539
|
+
: null,
|
|
540
|
+
h(DialogFooter, {}, {
|
|
541
|
+
default: () => [
|
|
542
|
+
h(DialogClose, { asChild: true }, {
|
|
543
|
+
default: () => h(Button, { type: "button", variant: "outline" }, { default: () => "Cancel" }),
|
|
544
|
+
}),
|
|
545
|
+
h(Button, {
|
|
546
|
+
type: "button",
|
|
547
|
+
variant: "destructive",
|
|
548
|
+
disabled: bulkDeleting.value,
|
|
549
|
+
onClick: () => void confirmBulkDelete(),
|
|
550
|
+
}, {
|
|
551
|
+
default: () => bulkDeleting.value ? "Deleting…" : "Delete",
|
|
552
|
+
}),
|
|
553
|
+
],
|
|
554
|
+
}),
|
|
555
|
+
],
|
|
556
|
+
}),
|
|
557
|
+
})
|
|
558
|
+
: null,
|
|
559
|
+
]);
|
|
560
|
+
};
|
|
561
|
+
},
|
|
562
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@verikit/vue",
|
|
3
|
+
"version": "0.23.1",
|
|
4
|
+
"description": "Vue UI bindings for Verikit resource workflows.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"typescript",
|
|
9
|
+
"resource",
|
|
10
|
+
"schema",
|
|
11
|
+
"resource-model",
|
|
12
|
+
"metadata",
|
|
13
|
+
"builder",
|
|
14
|
+
"validation",
|
|
15
|
+
"framework"
|
|
16
|
+
],
|
|
17
|
+
"author": "Chidi E <hi@ceeso.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=24"
|
|
21
|
+
},
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./components/*": {
|
|
29
|
+
"types": "./dist/components/*.d.ts",
|
|
30
|
+
"default": "./dist/components/*.js"
|
|
31
|
+
},
|
|
32
|
+
"./lib/*": {
|
|
33
|
+
"types": "./dist/lib/*.d.ts",
|
|
34
|
+
"default": "./dist/lib/*.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"imports": {
|
|
38
|
+
"#components/*": {
|
|
39
|
+
"types": "./src/components/*.ts",
|
|
40
|
+
"default": "./dist/components/*.js"
|
|
41
|
+
},
|
|
42
|
+
"#lib/*": {
|
|
43
|
+
"types": "./src/lib/*.ts",
|
|
44
|
+
"default": "./dist/lib/*.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@tanstack/vue-form": "^1.33.5",
|
|
52
|
+
"@tanstack/vue-query": "^5.101.4",
|
|
53
|
+
"@tanstack/vue-table": "^9.1.2",
|
|
54
|
+
"class-variance-authority": "^0.7.1",
|
|
55
|
+
"clsx": "^2.1.1",
|
|
56
|
+
"lucide-vue-next": "^1.0.0",
|
|
57
|
+
"reka-ui": "^2.10.3",
|
|
58
|
+
"tailwind-merge": "^3.6.0",
|
|
59
|
+
"@verikit/client": "0.23.1",
|
|
60
|
+
"@verikit/core": "0.23.1",
|
|
61
|
+
"@verikit/runtime": "0.23.1",
|
|
62
|
+
"@verikit/ui-core": "0.23.1",
|
|
63
|
+
"@verikit/theme": "0.23.1"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/jsdom": "^28.0.3",
|
|
67
|
+
"@types/node": "^26.1.1",
|
|
68
|
+
"@vue/test-utils": "^2.4.11",
|
|
69
|
+
"jsdom": "^30.0.1",
|
|
70
|
+
"typescript": "^6.0.3",
|
|
71
|
+
"vue": "^3.5.41"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@tanstack/vue-form": "^1.33.5",
|
|
75
|
+
"@tanstack/vue-query": "^5.101.4",
|
|
76
|
+
"@tanstack/vue-table": "^9.1.2",
|
|
77
|
+
"reka-ui": "^2.10.3",
|
|
78
|
+
"vue": "^3.5.0"
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
82
|
+
"build": "pnpm clean && tsc -b",
|
|
83
|
+
"test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node --import ./.test-dist/test/register.js --test $(find ./.test-dist/test -name '*.test.js' -type f | sort)",
|
|
84
|
+
"test:coverage": "rm -rf .test-dist coverage && tsc -p tsconfig.test.json && node --import ./.test-dist/test/register.js --test --experimental-test-coverage --test-coverage-include='.test-dist/src/**/*.js' --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 $(find ./.test-dist/test -name '*.test.js' -type f | sort)"
|
|
85
|
+
}
|
|
86
|
+
}
|