@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.
Files changed (104) hide show
  1. package/LICENSE.md +9 -0
  2. package/dist/client/index.d.ts +3 -0
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js +1 -0
  5. package/dist/client/use-verikit-client.d.ts +42 -0
  6. package/dist/client/use-verikit-client.d.ts.map +1 -0
  7. package/dist/client/use-verikit-client.js +39 -0
  8. package/dist/components/button.d.ts +36 -0
  9. package/dist/components/button.d.ts.map +1 -0
  10. package/dist/components/button.js +53 -0
  11. package/dist/components/checkbox.d.ts +45 -0
  12. package/dist/components/checkbox.d.ts.map +1 -0
  13. package/dist/components/checkbox.js +44 -0
  14. package/dist/components/dialog.d.ts +86 -0
  15. package/dist/components/dialog.d.ts.map +1 -0
  16. package/dist/components/dialog.js +157 -0
  17. package/dist/components/input.d.ts +5 -0
  18. package/dist/components/input.d.ts.map +1 -0
  19. package/dist/components/input.js +17 -0
  20. package/dist/components/label.d.ts +5 -0
  21. package/dist/components/label.d.ts.map +1 -0
  22. package/dist/components/label.js +17 -0
  23. package/dist/components/select.d.ts +164 -0
  24. package/dist/components/select.d.ts.map +1 -0
  25. package/dist/components/select.js +219 -0
  26. package/dist/components/textarea.d.ts +5 -0
  27. package/dist/components/textarea.d.ts.map +1 -0
  28. package/dist/components/textarea.js +17 -0
  29. package/dist/fields/field-shell.d.ts +64 -0
  30. package/dist/fields/field-shell.d.ts.map +1 -0
  31. package/dist/fields/field-shell.js +61 -0
  32. package/dist/fields/index.d.ts +7 -0
  33. package/dist/fields/index.d.ts.map +1 -0
  34. package/dist/fields/index.js +3 -0
  35. package/dist/fields/inputs.d.ts +372 -0
  36. package/dist/fields/inputs.d.ts.map +1 -0
  37. package/dist/fields/inputs.js +306 -0
  38. package/dist/fields/registry.d.ts +382 -0
  39. package/dist/fields/registry.d.ts.map +1 -0
  40. package/dist/fields/registry.js +31 -0
  41. package/dist/fields/types.d.ts +36 -0
  42. package/dist/fields/types.d.ts.map +1 -0
  43. package/dist/fields/types.js +1 -0
  44. package/dist/form/index.d.ts +11 -0
  45. package/dist/form/index.d.ts.map +1 -0
  46. package/dist/form/index.js +5 -0
  47. package/dist/form/use-verikit-form.d.ts +40 -0
  48. package/dist/form/use-verikit-form.d.ts.map +1 -0
  49. package/dist/form/use-verikit-form.js +72 -0
  50. package/dist/form/use-verikit-schema-tree-form.d.ts +47 -0
  51. package/dist/form/use-verikit-schema-tree-form.d.ts.map +1 -0
  52. package/dist/form/use-verikit-schema-tree-form.js +96 -0
  53. package/dist/index.d.ts +9 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +8 -0
  56. package/dist/layout/index.d.ts +5 -0
  57. package/dist/layout/index.d.ts.map +1 -0
  58. package/dist/layout/index.js +2 -0
  59. package/dist/layout/render-schema-node.d.ts +9 -0
  60. package/dist/layout/render-schema-node.d.ts.map +1 -0
  61. package/dist/layout/render-schema-node.js +265 -0
  62. package/dist/layout/types.d.ts +68 -0
  63. package/dist/layout/types.d.ts.map +1 -0
  64. package/dist/layout/types.js +1 -0
  65. package/dist/lib/utils.d.ts +4 -0
  66. package/dist/lib/utils.d.ts.map +1 -0
  67. package/dist/lib/utils.js +6 -0
  68. package/dist/query/index.d.ts +13 -0
  69. package/dist/query/index.d.ts.map +1 -0
  70. package/dist/query/index.js +6 -0
  71. package/dist/query/use-resource-form.d.ts +39 -0
  72. package/dist/query/use-resource-form.d.ts.map +1 -0
  73. package/dist/query/use-resource-form.js +32 -0
  74. package/dist/query/use-resource-mutations.d.ts +40 -0
  75. package/dist/query/use-resource-mutations.d.ts.map +1 -0
  76. package/dist/query/use-resource-mutations.js +104 -0
  77. package/dist/query/use-resource-queries.d.ts +15 -0
  78. package/dist/query/use-resource-queries.d.ts.map +1 -0
  79. package/dist/query/use-resource-queries.js +35 -0
  80. package/dist/query/use-resource-schema-tree-form.d.ts +36 -0
  81. package/dist/query/use-resource-schema-tree-form.d.ts.map +1 -0
  82. package/dist/query/use-resource-schema-tree-form.js +42 -0
  83. package/dist/query/use-resource-table.d.ts +48 -0
  84. package/dist/query/use-resource-table.d.ts.map +1 -0
  85. package/dist/query/use-resource-table.js +104 -0
  86. package/dist/relationships/belongs-to-field.d.ts +91 -0
  87. package/dist/relationships/belongs-to-field.d.ts.map +1 -0
  88. package/dist/relationships/belongs-to-field.js +107 -0
  89. package/dist/relationships/index.d.ts +2 -0
  90. package/dist/relationships/index.d.ts.map +1 -0
  91. package/dist/relationships/index.js +1 -0
  92. package/dist/resource/index.d.ts +5 -0
  93. package/dist/resource/index.d.ts.map +1 -0
  94. package/dist/resource/index.js +2 -0
  95. package/dist/resource/resource-form.d.ts +122 -0
  96. package/dist/resource/resource-form.d.ts.map +1 -0
  97. package/dist/resource/resource-form.js +83 -0
  98. package/dist/resource/resource-table-filters.d.ts +54 -0
  99. package/dist/resource/resource-table-filters.d.ts.map +1 -0
  100. package/dist/resource/resource-table-filters.js +283 -0
  101. package/dist/resource/resource-table.d.ts +93 -0
  102. package/dist/resource/resource-table.d.ts.map +1 -0
  103. package/dist/resource/resource-table.js +562 -0
  104. package/package.json +86 -0
@@ -0,0 +1,283 @@
1
+ import { defineComponent, h } from "vue";
2
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "#components/select";
3
+ import { Button } from "#components/button";
4
+ import { Input } from "#components/input";
5
+ import { Label } from "#components/label";
6
+ /** Fields a filter panel should render a control for. */
7
+ export function filterableFields(fields) {
8
+ return Object.values(fields).filter((field) => field.filterable);
9
+ }
10
+ const ALL_VALUE = "__all__";
11
+ /** Converts a browser `datetime-local` value into the UTC ISO format adapters expect. */
12
+ export function dateTimeFilterValue(value) {
13
+ if (value === "")
14
+ return undefined;
15
+ const date = new Date(value);
16
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
17
+ }
18
+ /** Formats a stored datetime filter for a browser `datetime-local` input. */
19
+ export function dateTimeLocalInputValue(value) {
20
+ const date = new Date(value);
21
+ if (Number.isNaN(date.getTime()))
22
+ return value;
23
+ const local = new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
24
+ return local.toISOString().slice(0, 16);
25
+ }
26
+ function isOrderedRange(min, max) {
27
+ if (min === undefined || max === undefined)
28
+ return true;
29
+ return typeof min === "number" && typeof max === "number"
30
+ ? min <= max
31
+ : String(min) <= String(max);
32
+ }
33
+ function filterControlProps() {
34
+ return {
35
+ field: { type: Object, required: true },
36
+ value: {
37
+ type: Object,
38
+ required: false,
39
+ },
40
+ onChange: {
41
+ type: Function,
42
+ required: true,
43
+ },
44
+ };
45
+ }
46
+ /** A boolean field's tri-state filter: unset, true, or false. */
47
+ const BooleanFilterControl = defineComponent({
48
+ name: "BooleanFilterControl",
49
+ props: filterControlProps(),
50
+ setup(props) {
51
+ return () => {
52
+ const current = props.value?.eq === true
53
+ ? "true"
54
+ : props.value?.eq === false
55
+ ? "false"
56
+ : ALL_VALUE;
57
+ return h(Select, {
58
+ value: current,
59
+ onValueChange: (next) => {
60
+ if (next === "true") {
61
+ props.onChange({ eq: true });
62
+ }
63
+ else if (next === "false") {
64
+ props.onChange({ eq: false });
65
+ }
66
+ else {
67
+ props.onChange(undefined);
68
+ }
69
+ },
70
+ }, {
71
+ default: () => [
72
+ h(SelectTrigger, {
73
+ class: "w-full",
74
+ "aria-label": props.field.label ?? props.field.name,
75
+ }, { default: () => h(SelectValue, { placeholder: "All" }) }),
76
+ h(SelectContent, {}, {
77
+ default: () => [
78
+ h(SelectItem, { value: ALL_VALUE }, { default: () => "All" }),
79
+ h(SelectItem, { value: "true" }, { default: () => "Yes" }),
80
+ h(SelectItem, { value: "false" }, { default: () => "No" }),
81
+ ],
82
+ }),
83
+ ],
84
+ });
85
+ };
86
+ },
87
+ });
88
+ /** A select field's filter: unset, or exact match against one of its options. */
89
+ const SelectFilterControl = defineComponent({
90
+ name: "SelectFilterControl",
91
+ props: filterControlProps(),
92
+ setup(props) {
93
+ return () => {
94
+ const options = props.field.options ?? [];
95
+ const valuesByKey = new Map(options.map((option) => [String(option.value), option.value]));
96
+ const current = props.value?.eq === undefined ? ALL_VALUE : String(props.value.eq);
97
+ return h(Select, {
98
+ value: current,
99
+ onValueChange: (next) => {
100
+ if (next === null || next === ALL_VALUE) {
101
+ props.onChange(undefined);
102
+ return;
103
+ }
104
+ props.onChange({ eq: valuesByKey.get(next) ?? next });
105
+ },
106
+ }, {
107
+ default: () => [
108
+ h(SelectTrigger, {
109
+ class: "w-full",
110
+ "aria-label": props.field.label ?? props.field.name,
111
+ }, { default: () => h(SelectValue, { placeholder: "All" }) }),
112
+ h(SelectContent, {}, {
113
+ default: () => [
114
+ h(SelectItem, { value: ALL_VALUE }, { default: () => "All" }),
115
+ ...options.map((option) => h(SelectItem, {
116
+ key: String(option.value),
117
+ value: String(option.value),
118
+ }, { default: () => option.label })),
119
+ ],
120
+ }),
121
+ ],
122
+ });
123
+ };
124
+ },
125
+ });
126
+ /** A number/date/datetime field's filter: an inclusive min/max range. */
127
+ const RangeFilterControl = defineComponent({
128
+ name: "RangeFilterControl",
129
+ props: filterControlProps(),
130
+ setup(props) {
131
+ return () => {
132
+ const inputType = props.field.fieldType === "date"
133
+ ? "date"
134
+ : props.field.fieldType === "datetime"
135
+ ? "datetime-local"
136
+ : "number";
137
+ function apply(min, max) {
138
+ const next = {};
139
+ if (min !== "") {
140
+ const value = inputType === "number"
141
+ ? Number(min)
142
+ : inputType === "datetime-local"
143
+ ? dateTimeFilterValue(min)
144
+ : min;
145
+ if (value !== undefined)
146
+ next.gte = value;
147
+ }
148
+ if (max !== "") {
149
+ const value = inputType === "number"
150
+ ? Number(max)
151
+ : inputType === "datetime-local"
152
+ ? dateTimeFilterValue(max)
153
+ : max;
154
+ if (value !== undefined)
155
+ next.lte = value;
156
+ }
157
+ // Native `min`/`max` attributes guide browser input, but callers can
158
+ // still type or script an inverted range. Never let that reach an
159
+ // adapter as an impossible (or misleading) query.
160
+ if (!isOrderedRange(next.gte, next.lte))
161
+ return;
162
+ props.onChange(Object.keys(next).length > 0 ? next : undefined);
163
+ }
164
+ const minValue = props.value?.gte === undefined
165
+ ? ""
166
+ : inputType === "datetime-local"
167
+ ? dateTimeLocalInputValue(String(props.value.gte))
168
+ : String(props.value.gte);
169
+ const maxValue = props.value?.lte === undefined
170
+ ? ""
171
+ : inputType === "datetime-local"
172
+ ? dateTimeLocalInputValue(String(props.value.lte))
173
+ : String(props.value.lte);
174
+ return h("div", { class: "flex items-center gap-1" }, [
175
+ h(Input, {
176
+ type: inputType,
177
+ "aria-label": `${props.field.label ?? props.field.name} minimum`,
178
+ placeholder: "Min",
179
+ value: minValue,
180
+ max: maxValue || undefined,
181
+ onInput: (event) => apply(event.target.value, maxValue),
182
+ }),
183
+ h("span", { class: "text-muted-foreground" }, "–"),
184
+ h(Input, {
185
+ type: inputType,
186
+ "aria-label": `${props.field.label ?? props.field.name} maximum`,
187
+ placeholder: "Max",
188
+ value: maxValue,
189
+ min: minValue || undefined,
190
+ onInput: (event) => apply(minValue, event.target.value),
191
+ }),
192
+ ]);
193
+ };
194
+ },
195
+ });
196
+ /** A text-like field's filter: an exact match. */
197
+ const TextFilterControl = defineComponent({
198
+ name: "TextFilterControl",
199
+ props: filterControlProps(),
200
+ setup(props) {
201
+ return () => h(Input, {
202
+ type: "text",
203
+ "aria-label": props.field.label ?? props.field.name,
204
+ placeholder: "Exact match",
205
+ value: props.value?.eq === undefined ? "" : String(props.value.eq),
206
+ onInput: (event) => {
207
+ const next = event.target.value;
208
+ props.onChange(next === "" ? undefined : { eq: next });
209
+ },
210
+ });
211
+ },
212
+ });
213
+ function filterControl(field, value, onChange) {
214
+ if (field.fieldType === "boolean") {
215
+ return h(BooleanFilterControl, { field, value, onChange });
216
+ }
217
+ if (field.fieldType === "select") {
218
+ return h(SelectFilterControl, { field, value, onChange });
219
+ }
220
+ if (field.fieldType === "number" ||
221
+ field.fieldType === "date" ||
222
+ field.fieldType === "datetime") {
223
+ return h(RangeFilterControl, { field, value, onChange });
224
+ }
225
+ return h(TextFilterControl, { field, value, onChange });
226
+ }
227
+ /**
228
+ * A grid of per-field filter controls — one per `filterable` field, typed to
229
+ * that field's `fieldType` (boolean toggle, select dropdown, number/date
230
+ * range, or exact-match text) — that read and write `ResourceTable`'s active
231
+ * filters. Renders nothing if no field is `filterable`.
232
+ */
233
+ export const ResourceTableFilterPanel = defineComponent({
234
+ name: "ResourceTableFilterPanel",
235
+ props: {
236
+ fields: {
237
+ type: Object,
238
+ required: true,
239
+ },
240
+ filters: { type: Object, required: true },
241
+ onFiltersChange: {
242
+ type: Function,
243
+ required: true,
244
+ },
245
+ },
246
+ setup(props) {
247
+ return () => {
248
+ const filterFields = filterableFields(props.fields);
249
+ const hasActiveFilters = Object.keys(props.filters).length > 0;
250
+ if (filterFields.length === 0) {
251
+ return null;
252
+ }
253
+ function setFilter(name, next) {
254
+ const nextFilters = { ...props.filters };
255
+ if (!next) {
256
+ delete nextFilters[name];
257
+ }
258
+ else {
259
+ nextFilters[name] = next;
260
+ }
261
+ props.onFiltersChange(nextFilters);
262
+ }
263
+ return h("div", {
264
+ class: "grid grid-cols-1 gap-3 rounded-lg border border-border p-3 sm:grid-cols-2 md:grid-cols-3",
265
+ }, [
266
+ hasActiveFilters
267
+ ? h("div", { class: "flex justify-end sm:col-span-2 md:col-span-3" }, [
268
+ h(Button, {
269
+ type: "button",
270
+ variant: "ghost",
271
+ size: "xs",
272
+ onClick: () => props.onFiltersChange({}),
273
+ }, { default: () => "Clear filters" }),
274
+ ])
275
+ : null,
276
+ ...filterFields.map((field) => h("div", { key: field.name, class: "grid gap-1" }, [
277
+ h(Label, {}, { default: () => field.label ?? field.name }),
278
+ filterControl(field, props.filters[field.name], (next) => setFilter(field.name, next)),
279
+ ])),
280
+ ]);
281
+ };
282
+ },
283
+ });
@@ -0,0 +1,93 @@
1
+ import { type PropType, type VNodeChild } from "vue";
2
+ import type { RowData } from "@tanstack/vue-table";
3
+ import { type UseResourceTableOptions, type UseResourceTableSource } from "../query/use-resource-table.js";
4
+ /** Props for {@link ResourceTable}. */
5
+ export interface ResourceTableProps<TRecord extends RowData = Record<string, unknown>> extends UseResourceTableOptions {
6
+ /** The resource (or its schema) whose fields drive columns, sorting, and paging. */
7
+ resource: UseResourceTableSource;
8
+ /**
9
+ * Renders the built-in Create button (opens a `ResourceForm` dialog) and
10
+ * Edit/Delete row actions.
11
+ */
12
+ actions?: boolean;
13
+ /** Renders per-row actions (e.g. custom edit/delete buttons). */
14
+ renderActions?: (record: TRecord) => VNodeChild;
15
+ /** Renders custom actions for the current row selection. */
16
+ renderBulkActions?: (records: TRecord[], clearSelection: () => void) => VNodeChild;
17
+ /** Content shown in place of rows when the list is empty. Defaults to a plain message. */
18
+ emptyState?: VNodeChild;
19
+ /** Class name applied to the outer container. */
20
+ className?: string;
21
+ }
22
+ /**
23
+ * A responsive resource table with search, sorting, pagination, and a
24
+ * mobile card layout. Standard CRUD actions and custom row actions are opt-in.
25
+ */
26
+ export declare const ResourceTable: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
27
+ resource: {
28
+ type: PropType<UseResourceTableSource>;
29
+ required: true;
30
+ };
31
+ pageSize: {
32
+ type: PropType<number | undefined>;
33
+ default: undefined;
34
+ };
35
+ actions: {
36
+ type: BooleanConstructor;
37
+ default: boolean;
38
+ };
39
+ renderActions: {
40
+ type: PropType<ResourceTableProps["renderActions"]>;
41
+ default: undefined;
42
+ };
43
+ renderBulkActions: {
44
+ type: PropType<ResourceTableProps["renderBulkActions"]>;
45
+ default: undefined;
46
+ };
47
+ emptyState: {
48
+ type: PropType<VNodeChild>;
49
+ required: false;
50
+ };
51
+ className: {
52
+ type: PropType<string | undefined>;
53
+ default: undefined;
54
+ };
55
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
56
+ [key: string]: any;
57
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
58
+ resource: {
59
+ type: PropType<UseResourceTableSource>;
60
+ required: true;
61
+ };
62
+ pageSize: {
63
+ type: PropType<number | undefined>;
64
+ default: undefined;
65
+ };
66
+ actions: {
67
+ type: BooleanConstructor;
68
+ default: boolean;
69
+ };
70
+ renderActions: {
71
+ type: PropType<ResourceTableProps["renderActions"]>;
72
+ default: undefined;
73
+ };
74
+ renderBulkActions: {
75
+ type: PropType<ResourceTableProps["renderBulkActions"]>;
76
+ default: undefined;
77
+ };
78
+ emptyState: {
79
+ type: PropType<VNodeChild>;
80
+ required: false;
81
+ };
82
+ className: {
83
+ type: PropType<string | undefined>;
84
+ default: undefined;
85
+ };
86
+ }>> & Readonly<{}>, {
87
+ className: string | undefined;
88
+ actions: boolean;
89
+ pageSize: number | undefined;
90
+ renderActions: ((record: Record<string, unknown>) => VNodeChild) | undefined;
91
+ renderBulkActions: ((records: Record<string, unknown>[], clearSelection: () => void) => VNodeChild) | undefined;
92
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
93
+ //# sourceMappingURL=resource-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-table.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAY9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAgBnD,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,gCAAgC,CAAC;AAuBxC,uCAAuC;AACvC,MAAM,WAAW,kBAAkB,CACjC,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjD,SAAQ,uBAAuB;IAC/B,oFAAoF;IACpF,QAAQ,EAAE,sBAAsB,CAAC;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iEAAiE;IACjE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,UAAU,CAAC;IAChD,4DAA4D;IAC5D,iBAAiB,CAAC,EAAE,CAClB,OAAO,EAAE,OAAO,EAAE,EAClB,cAAc,EAAE,MAAM,IAAI,KACvB,UAAU,CAAC;IAChB,0FAA0F;IAC1F,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuCD;;;GAGG;AACH,eAAO,MAAM,aAAa;;cAIJ,QAAQ,CAAC,sBAAsB,CAAC;;;;cAIhC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,UAAU,CAAC;;;;cAI7B,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;cArB5B,QAAQ,CAAC,sBAAsB,CAAC;;;;cAIhC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,UAAU,CAAC;;;;cAI7B,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;yDA9EX,UAAU;6EAI7B,MAAM,IAAI,KACvB,UAAU;4EAi1Bf,CAAC"}