@verikit/react 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 +23 -0
  6. package/dist/client/use-verikit-client.d.ts.map +1 -0
  7. package/dist/client/use-verikit-client.js +22 -0
  8. package/dist/components/button.d.ts +11 -0
  9. package/dist/components/button.d.ts.map +1 -0
  10. package/dist/components/button.js +36 -0
  11. package/dist/components/checkbox.d.ts +5 -0
  12. package/dist/components/checkbox.d.ts.map +1 -0
  13. package/dist/components/checkbox.js +10 -0
  14. package/dist/components/dialog.d.ts +27 -0
  15. package/dist/components/dialog.d.ts.map +1 -0
  16. package/dist/components/dialog.js +40 -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 +8 -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 +7 -0
  23. package/dist/components/select.d.ts +26 -0
  24. package/dist/components/select.d.ts.map +1 -0
  25. package/dist/components/select.js +43 -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 +7 -0
  29. package/dist/fields/field-shell.d.ts +28 -0
  30. package/dist/fields/field-shell.d.ts.map +1 -0
  31. package/dist/fields/field-shell.js +29 -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 +22 -0
  36. package/dist/fields/inputs.d.ts.map +1 -0
  37. package/dist/fields/inputs.js +136 -0
  38. package/dist/fields/registry.d.ts +33 -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 +37 -0
  48. package/dist/form/use-verikit-form.d.ts.map +1 -0
  49. package/dist/form/use-verikit-form.js +66 -0
  50. package/dist/form/use-verikit-schema-tree-form.d.ts +46 -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 +94 -0
  53. package/dist/index.d.ts +10 -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 +143 -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 +38 -0
  72. package/dist/query/use-resource-form.d.ts.map +1 -0
  73. package/dist/query/use-resource-form.js +31 -0
  74. package/dist/query/use-resource-mutations.d.ts +30 -0
  75. package/dist/query/use-resource-mutations.d.ts.map +1 -0
  76. package/dist/query/use-resource-mutations.js +107 -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 +35 -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 +43 -0
  83. package/dist/query/use-resource-table.d.ts +46 -0
  84. package/dist/query/use-resource-table.d.ts.map +1 -0
  85. package/dist/query/use-resource-table.js +81 -0
  86. package/dist/relationships/belongs-to-field.d.ts +29 -0
  87. package/dist/relationships/belongs-to-field.d.ts.map +1 -0
  88. package/dist/relationships/belongs-to-field.js +28 -0
  89. package/dist/relationships/index.d.ts +3 -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 +28 -0
  96. package/dist/resource/resource-form.d.ts.map +1 -0
  97. package/dist/resource/resource-form.js +25 -0
  98. package/dist/resource/resource-table-filters.d.ts +26 -0
  99. package/dist/resource/resource-table-filters.d.ts.map +1 -0
  100. package/dist/resource/resource-table-filters.js +151 -0
  101. package/dist/resource/resource-table.d.ts +45 -0
  102. package/dist/resource/resource-table.d.ts.map +1 -0
  103. package/dist/resource/resource-table.js +179 -0
  104. package/package.json +89 -0
@@ -0,0 +1,46 @@
1
+ import { type RowData, type Table } from "@tanstack/react-table";
2
+ import type { ListParams } from "@verikit/client";
3
+ import type { FieldSchema, Resource, ResourceSchema } from "@verikit/core";
4
+ declare const resourceTableFeatures: {
5
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
6
+ rowPaginationFeature: import("@tanstack/react-table").TableFeature;
7
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
8
+ columnFilteringFeature: import("@tanstack/react-table").TableFeature;
9
+ globalFilteringFeature: import("@tanstack/react-table").TableFeature;
10
+ };
11
+ type ResourceTableFeatures = typeof resourceTableFeatures;
12
+ /** A resource builder or its finalized schema either carries its own name. */
13
+ export type UseResourceTableSource = Resource | ResourceSchema;
14
+ /** Active per-field filters, keyed by field name the same shape `ListParams.filters` sends to the server. */
15
+ export type ResourceTableFilters = NonNullable<ListParams["filters"]>;
16
+ /** Options for creating a resource-backed table. */
17
+ export interface UseResourceTableOptions {
18
+ /** Initial page size, before the user (or caller) changes it. Defaults to 25. */
19
+ pageSize?: number;
20
+ }
21
+ /** State and helpers returned by {@link useResourceTable}. */
22
+ export interface UseResourceTableResult<TRecord extends RowData = Record<string, unknown>> {
23
+ /** The TanStack Table instance headless: render your own markup from it. */
24
+ table: Table<ResourceTableFeatures, TRecord>;
25
+ /** Whether the current page's initial fetch is still in flight. */
26
+ isLoading: boolean;
27
+ /** Whether a fetch (initial or background) is currently in flight. */
28
+ isFetching: boolean;
29
+ /** Error from the underlying list request, if any. */
30
+ error: Error | null;
31
+ /**
32
+ * Resolved field schemas for table columns, including metadata used by filters.
33
+ */
34
+ fields: Record<string, FieldSchema>;
35
+ /** Active per-field filters sent with the list request. */
36
+ filters: ResourceTableFilters;
37
+ /** Replaces the active per-field filters wholesale. */
38
+ setFilters: (filters: ResourceTableFilters) => void;
39
+ }
40
+ /**
41
+ * Creates a TanStack Table from a resource's schema, with automatic columns
42
+ * and server-side pagination, sorting, and search.
43
+ */
44
+ export declare function useResourceTable<TRecord extends RowData = Record<string, unknown>>(resource: UseResourceTableSource, { pageSize }?: UseResourceTableOptions): UseResourceTableResult<TRecord>;
45
+ export {};
46
+ //# sourceMappingURL=use-resource-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-table.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-table.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO3E,QAAA,MAAM,qBAAqB;;;;;;CAMzB,CAAC;AAEH,KAAK,qBAAqB,GAAG,OAAO,qBAAqB,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE/D,8GAA8G;AAC9G,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAEtE,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,8DAA8D;AAC9D,MAAM,WAAW,sBAAsB,CACrC,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEjD,6EAA6E;IAC7E,KAAK,EAAE,KAAK,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;IAC7C,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,2DAA2D;IAC3D,OAAO,EAAE,oBAAoB,CAAC;IAC9B,uDAAuD;IACvD,UAAU,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACrD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEjD,QAAQ,EAAE,sBAAsB,EAChC,EAAE,QAAa,EAAE,GAAE,uBAA4B,GAC9C,sBAAsB,CAAC,OAAO,CAAC,CA8EjC"}
@@ -0,0 +1,81 @@
1
+ import { useMemo, useState } from "react";
2
+ import { columnFilteringFeature, functionalUpdate, globalFilteringFeature, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable, } from "@tanstack/react-table";
3
+ import { recordId } from "@verikit/ui-core/query/optimistic";
4
+ import { resolveVerikitFields } from "@verikit/ui-core/form/resolve-fields";
5
+ import { useListResource } from "./use-resource-queries.js";
6
+ // `columnFilteringFeature` is required by TanStack's global filtering feature.
7
+ // VeriKit manages field filters separately to support range operators.
8
+ const resourceTableFeatures = tableFeatures({
9
+ rowSortingFeature,
10
+ rowPaginationFeature,
11
+ rowSelectionFeature,
12
+ columnFilteringFeature,
13
+ globalFilteringFeature,
14
+ });
15
+ /**
16
+ * Creates a TanStack Table from a resource's schema, with automatic columns
17
+ * and server-side pagination, sorting, and search.
18
+ */
19
+ export function useResourceTable(resource, { pageSize = 25 } = {}) {
20
+ const fields = resolveVerikitFields(resource);
21
+ const columns = useMemo(() => Object.values(fields)
22
+ .filter((field) => !field.hidden && !field.tableHidden)
23
+ .map((field) => ({
24
+ accessorKey: field.name,
25
+ header: field.label ?? field.name,
26
+ enableSorting: field.sortable ?? false,
27
+ })), [fields]);
28
+ const [sorting, setSorting] = useState([]);
29
+ const [pagination, setPagination] = useState({
30
+ pageIndex: 0,
31
+ pageSize,
32
+ });
33
+ const [globalFilter, setGlobalFilter] = useState("");
34
+ const [filters, setFilters] = useState({});
35
+ const [rowSelection, setRowSelection] = useState({});
36
+ // Reset to page 1 when filters or search change to avoid empty stale pages.
37
+ const resetToFirstPage = () => setPagination((old) => old.pageIndex === 0 ? old : { ...old, pageIndex: 0 });
38
+ const handleGlobalFilterChange = (updater) => {
39
+ setGlobalFilter((old) => functionalUpdate(updater, old));
40
+ resetToFirstPage();
41
+ };
42
+ const handleFiltersChange = (next) => {
43
+ setFilters(next);
44
+ resetToFirstPage();
45
+ };
46
+ const activeSort = sorting[0];
47
+ const hasFilters = Object.keys(filters).length > 0;
48
+ const list = useListResource(resource.name, {
49
+ page: pagination.pageIndex + 1,
50
+ pageSize: pagination.pageSize,
51
+ search: globalFilter || undefined,
52
+ sort: activeSort
53
+ ? { field: activeSort.id, direction: activeSort.desc ? "desc" : "asc" }
54
+ : undefined,
55
+ ...(hasFilters ? { filters } : {}),
56
+ });
57
+ const table = useTable({
58
+ features: resourceTableFeatures,
59
+ columns,
60
+ data: list.data?.records ?? [],
61
+ manualSorting: true,
62
+ manualPagination: true,
63
+ rowCount: list.data?.total ?? 0,
64
+ // Use record IDs so row selection remains stable across paginated pages.
65
+ getRowId: (row, index) => recordId(row) ?? String(index),
66
+ state: { sorting, pagination, globalFilter, rowSelection },
67
+ onSortingChange: setSorting,
68
+ onPaginationChange: setPagination,
69
+ onGlobalFilterChange: handleGlobalFilterChange,
70
+ onRowSelectionChange: setRowSelection,
71
+ });
72
+ return {
73
+ table,
74
+ isLoading: list.isLoading,
75
+ isFetching: list.isFetching,
76
+ error: list.error,
77
+ fields,
78
+ filters,
79
+ setFilters: handleFiltersChange,
80
+ };
81
+ }
@@ -0,0 +1,29 @@
1
+ import type { BelongsToRelationshipSchema } from "@verikit/core";
2
+ import type { ReactElement, ReactNode } from "react";
3
+ /** Props for {@link BelongsToRelationshipField}. */
4
+ export interface BelongsToRelationshipFieldProps {
5
+ /** Finalized `belongsTo` relationship node being rendered. */
6
+ relationship: BelongsToRelationshipSchema;
7
+ /** Explicit input id. Defaults to a stable id derived from the relationship. */
8
+ id?: string;
9
+ /** Current foreign-key value (the selected record's id), if any. */
10
+ value?: unknown;
11
+ /** Error content shown below the select and linked with ARIA. */
12
+ error?: ReactNode;
13
+ /** Disables the select. */
14
+ disabled?: boolean;
15
+ /** Marks the select as read-only. */
16
+ readOnly?: boolean;
17
+ /** Class name applied to the outer wrapper. */
18
+ className?: string;
19
+ /** Called with the next foreign-key value (or `null` when cleared). */
20
+ onValueChange?: (value: string | null) => void;
21
+ /** Called when the select loses focus. */
22
+ onBlur?: () => void;
23
+ }
24
+ /**
25
+ * Renders a `belongsTo` relationship as a permission-aware combobox,
26
+ * reading and writing the related record's ID through its `.via()` field.
27
+ */
28
+ export declare function BelongsToRelationshipField({ relationship, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }: BelongsToRelationshipFieldProps): ReactElement;
29
+ //# sourceMappingURL=belongs-to-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"belongs-to-field.d.ts","sourceRoot":"","sources":["../../src/relationships/belongs-to-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAgBrD,oDAAoD;AACpD,MAAM,WAAW,+BAA+B;IAC9C,8DAA8D;IAC9D,YAAY,EAAE,2BAA2B,CAAC;IAC1C,gFAAgF;IAChF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iEAAiE;IACjE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAeD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAY,EACZ,EAAE,EACF,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,aAAa,EACb,MAAM,GACP,EAAE,+BAA+B,GAAG,YAAY,CA4DhD"}
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Label } from "#components/label";
3
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "#components/select";
4
+ import { cn } from "#lib/utils";
5
+ import { useResourceRelationship } from "../query/use-resource-queries.js";
6
+ // Matches the server's maximum list page size, so a picker is not silently
7
+ // limited to its ordinary table-page default (currently 25 records).
8
+ const RELATIONSHIP_PICKER_PAGE_SIZE = 100;
9
+ function recordId(record) {
10
+ return String(record.id);
11
+ }
12
+ function recordLabel(record, displayField) {
13
+ const raw = displayField ? record[displayField] : undefined;
14
+ return raw === null || raw === undefined ? recordId(record) : String(raw);
15
+ }
16
+ /**
17
+ * Renders a `belongsTo` relationship as a permission-aware combobox,
18
+ * reading and writing the related record's ID through its `.via()` field.
19
+ */
20
+ export function BelongsToRelationshipField({ relationship, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }) {
21
+ const relationshipName = relationship.name ?? "";
22
+ const inputId = id ?? `verikit-relationship-${relationship.resource}-${relationshipName}`;
23
+ const errorId = error ? `${inputId}-error` : undefined;
24
+ const { data, isLoading, error: fetchError, } = useResourceRelationship(relationship.resource, relationshipName, { pageSize: RELATIONSHIP_PICKER_PAGE_SIZE }, { enabled: relationshipName.length > 0 });
25
+ const records = data?.records ?? [];
26
+ const currentValue = value === null || value === undefined ? "" : String(value);
27
+ return (_jsxs("div", { className: cn("grid gap-2", className), children: [relationship.label ? (_jsx(Label, { htmlFor: inputId, children: relationship.label })) : null, _jsxs(Select, { name: relationshipName, value: currentValue, disabled: disabled === true, readOnly: readOnly === true, onValueChange: onValueChange, children: [_jsx(SelectTrigger, { id: inputId, className: "w-full", onBlur: onBlur, "aria-describedby": errorId, "aria-invalid": error ? true : undefined, children: _jsx(SelectValue, { placeholder: isLoading ? "Loading…" : "Select…" }) }), _jsx(SelectContent, { children: records.map((record) => (_jsx(SelectItem, { value: recordId(record), children: recordLabel(record, relationship.displayField) }, recordId(record)))) })] }), error ? (_jsx("p", { id: errorId, className: "text-sm text-destructive", children: error })) : null, fetchError ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: fetchError.message })) : null] }));
28
+ }
@@ -0,0 +1,3 @@
1
+ export { BelongsToRelationshipField } from "./belongs-to-field.js";
2
+ export type { BelongsToRelationshipFieldProps } from "./belongs-to-field.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACnE,YAAY,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1 @@
1
+ export { BelongsToRelationshipField } from "./belongs-to-field.js";
@@ -0,0 +1,5 @@
1
+ export { ResourceForm } from "./resource-form.js";
2
+ export type { ResourceFormProps } from "./resource-form.js";
3
+ export { ResourceTable } from "./resource-table.js";
4
+ export type { ResourceTableProps } from "./resource-table.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ResourceForm } from "./resource-form.js";
2
+ export { ResourceTable } from "./resource-table.js";
@@ -0,0 +1,28 @@
1
+ import type { RelationshipNode } from "@verikit/core";
2
+ import type { ReactElement, ReactNode } from "react";
3
+ import type { VerikitFieldRegistry } from "../fields/types.js";
4
+ import type { SchemaPath } from "@verikit/ui-core/layout/path";
5
+ import { type UseResourceSchemaTreeFormOptions } from "../query/use-resource-schema-tree-form.js";
6
+ import type { VerikitSchemaTreeSource } from "../form/use-verikit-schema-tree-form.js";
7
+ /** Props for {@link ResourceForm}. */
8
+ export interface ResourceFormProps<TRecord = Record<string, unknown>> extends UseResourceSchemaTreeFormOptions<TRecord> {
9
+ /** The resource (or its schema) whose tree drives the form and submission. */
10
+ resource: VerikitSchemaTreeSource;
11
+ /** Optional renderer overrides keyed by field type. */
12
+ registry?: Partial<VerikitFieldRegistry>;
13
+ /**
14
+ * Overrides relationship rendering. By default, `belongsTo` uses the
15
+ * built-in picker; collection relationships require a custom renderer.
16
+ */
17
+ renderRelationship?: (node: RelationshipNode, path: SchemaPath) => ReactNode;
18
+ /** Label shown on the submit button while idle. Defaults to `"Save"`. */
19
+ submitLabel?: string;
20
+ /** Class name applied to the outer `<form>`. */
21
+ className?: string;
22
+ }
23
+ /**
24
+ * Renders a responsive resource form powered by `useResourceSchemaTreeForm`,
25
+ * with layouts, relationships, conditional fields, and submission state.
26
+ */
27
+ export declare function ResourceForm<TRecord = Record<string, unknown>>({ resource, id, actions, defaultValues, onSuccess, onError, registry, renderRelationship, submitLabel, className, }: ResourceFormProps<TRecord>): ReactElement;
28
+ //# sourceMappingURL=resource-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-form.d.ts","sourceRoot":"","sources":["../../src/resource/resource-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAa,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAEvF,sCAAsC;AACtC,MAAM,WAAW,iBAAiB,CAChC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjC,SAAQ,gCAAgC,CAAC,OAAO,CAAC;IACjD,8EAA8E;IAC9E,QAAQ,EAAE,uBAAuB,CAAC;IAClC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,SAAS,CAAC;IAC7E,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC9D,QAAQ,EACR,EAAE,EACF,OAAO,EACP,aAAa,EACb,SAAS,EACT,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,WAAoB,EACpB,SAAS,GACV,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,YAAY,CAwC3C"}
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "#components/button";
3
+ import { cn } from "#lib/utils";
4
+ import { RenderSchemaTree } from "../layout/render-schema-node.js";
5
+ import { useResourceSchemaTreeForm, } from "../query/use-resource-schema-tree-form.js";
6
+ /**
7
+ * Renders a responsive resource form powered by `useResourceSchemaTreeForm`,
8
+ * with layouts, relationships, conditional fields, and submission state.
9
+ */
10
+ export function ResourceForm({ resource, id, actions, defaultValues, onSuccess, onError, registry, renderRelationship, submitLabel = "Save", className, }) {
11
+ const result = useResourceSchemaTreeForm(resource, {
12
+ id,
13
+ actions,
14
+ defaultValues,
15
+ onSuccess,
16
+ onError,
17
+ });
18
+ const handleSubmit = (event) => {
19
+ event.preventDefault();
20
+ event.stopPropagation();
21
+ // `submitError` already handles mutation failures; suppress the rejection here.
22
+ result.submit().catch(() => { });
23
+ };
24
+ return (_jsxs("form", { className: cn("grid gap-4", className), onSubmit: handleSubmit, noValidate: true, children: [_jsx(RenderSchemaTree, { nodes: result.tree, registry: registry, renderRelationship: renderRelationship, ...result.treeProps }), result.submitError ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: result.submitError.message })) : null, _jsx("div", { className: "flex justify-end", children: _jsx(Button, { type: "submit", disabled: result.isSubmitting, children: result.isSubmitting ? "Saving…" : submitLabel }) })] }));
25
+ }
@@ -0,0 +1,26 @@
1
+ import type { ReactElement } from "react";
2
+ import type { FieldSchema } from "@verikit/core";
3
+ import type { ResourceTableFilters } from "../query/use-resource-table.js";
4
+ /** Fields a filter panel should render a control for. */
5
+ export declare function filterableFields(fields: Record<string, FieldSchema>): FieldSchema[];
6
+ /** Converts a browser `datetime-local` value into the UTC ISO format adapters expect. */
7
+ export declare function dateTimeFilterValue(value: string): string | undefined;
8
+ /** Formats a stored datetime filter for a browser `datetime-local` input. */
9
+ export declare function dateTimeLocalInputValue(value: string): string;
10
+ /** Props for {@link ResourceTableFilterPanel}. */
11
+ export interface ResourceTableFilterPanelProps {
12
+ /** Field schemas to render controls for only entries with `filterable: true` produce a control. */
13
+ fields: Record<string, FieldSchema>;
14
+ /** The table's current active filters. */
15
+ filters: ResourceTableFilters;
16
+ /** Called with the full replacement filter set whenever a control changes. */
17
+ onFiltersChange: (filters: ResourceTableFilters) => void;
18
+ }
19
+ /**
20
+ * A grid of per-field filter controls one per `filterable` field, typed to
21
+ * that field's `fieldType` (boolean toggle, select dropdown, number/date
22
+ * range, or exact-match text) that read and write `ResourceTable`'s active
23
+ * filters. Renders nothing if no field is `filterable`.
24
+ */
25
+ export declare function ResourceTableFilterPanel({ fields, filters, onFiltersChange, }: ResourceTableFilterPanelProps): ReactElement | null;
26
+ //# sourceMappingURL=resource-table-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-table-filters.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table-filters.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAWjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,yDAAyD;AACzD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAClC,WAAW,EAAE,CAEf;AAID,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKrE;AAED,6EAA6E;AAC7E,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAyOD,kDAAkD;AAClD,MAAM,WAAW,6BAA6B;IAC5C,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,0CAA0C;IAC1C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,8EAA8E;IAC9E,eAAe,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,MAAM,EACN,OAAO,EACP,eAAe,GAChB,EAAE,6BAA6B,GAAG,YAAY,GAAG,IAAI,CA8CrD"}
@@ -0,0 +1,151 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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
+ /** A boolean field's tri-state filter: unset, true, or false. */
34
+ function BooleanFilterControl({ field, value, onChange, }) {
35
+ const current = value?.eq === true ? "true" : value?.eq === false ? "false" : ALL_VALUE;
36
+ return (_jsxs(Select, { value: current, onValueChange: (next) => {
37
+ if (next === "true") {
38
+ onChange({ eq: true });
39
+ }
40
+ else if (next === "false") {
41
+ onChange({ eq: false });
42
+ }
43
+ else {
44
+ onChange(undefined);
45
+ }
46
+ }, children: [_jsx(SelectTrigger, { className: "w-full", "aria-label": field.label ?? field.name, children: _jsx(SelectValue, { placeholder: "All" }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ALL_VALUE, children: "All" }), _jsx(SelectItem, { value: "true", children: "Yes" }), _jsx(SelectItem, { value: "false", children: "No" })] })] }));
47
+ }
48
+ /** A select field's filter: unset, or exact match against one of its options. */
49
+ function SelectFilterControl({ field, value, onChange, }) {
50
+ const options = field.options ?? [];
51
+ const valuesByKey = new Map(options.map((option) => [String(option.value), option.value]));
52
+ const current = value?.eq === undefined ? ALL_VALUE : String(value.eq);
53
+ return (_jsxs(Select, { value: current, onValueChange: (next) => {
54
+ if (next === null || next === ALL_VALUE) {
55
+ onChange(undefined);
56
+ return;
57
+ }
58
+ onChange({ eq: valuesByKey.get(next) ?? next });
59
+ }, children: [_jsx(SelectTrigger, { className: "w-full", "aria-label": field.label ?? field.name, children: _jsx(SelectValue, { placeholder: "All" }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ALL_VALUE, children: "All" }), options.map((option) => (_jsx(SelectItem, { value: String(option.value), children: option.label }, String(option.value))))] })] }));
60
+ }
61
+ /** A number/date/datetime field's filter: an inclusive min/max range. */
62
+ function RangeFilterControl({ field, value, onChange, }) {
63
+ const inputType = field.fieldType === "date"
64
+ ? "date"
65
+ : field.fieldType === "datetime"
66
+ ? "datetime-local"
67
+ : "number";
68
+ function apply(min, max) {
69
+ const next = {};
70
+ if (min !== "") {
71
+ const value = inputType === "number"
72
+ ? Number(min)
73
+ : inputType === "datetime-local"
74
+ ? dateTimeFilterValue(min)
75
+ : min;
76
+ if (value !== undefined)
77
+ next.gte = value;
78
+ }
79
+ if (max !== "") {
80
+ const value = inputType === "number"
81
+ ? Number(max)
82
+ : inputType === "datetime-local"
83
+ ? dateTimeFilterValue(max)
84
+ : max;
85
+ if (value !== undefined)
86
+ next.lte = value;
87
+ }
88
+ // Native `min`/`max` attributes guide browser input, but callers can
89
+ // still type or script an inverted range. Never let that reach an adapter
90
+ // as an impossible (or misleading) query.
91
+ if (!isOrderedRange(next.gte, next.lte))
92
+ return;
93
+ onChange(Object.keys(next).length > 0 ? next : undefined);
94
+ }
95
+ const minValue = value?.gte === undefined
96
+ ? ""
97
+ : inputType === "datetime-local"
98
+ ? dateTimeLocalInputValue(String(value.gte))
99
+ : String(value.gte);
100
+ const maxValue = value?.lte === undefined
101
+ ? ""
102
+ : inputType === "datetime-local"
103
+ ? dateTimeLocalInputValue(String(value.lte))
104
+ : String(value.lte);
105
+ return (_jsxs("div", { className: "flex items-center gap-1", children: [_jsx(Input, { type: inputType, "aria-label": `${field.label ?? field.name} minimum`, placeholder: "Min", value: minValue, max: maxValue || undefined, onChange: (event) => apply(event.currentTarget.value, maxValue) }), _jsx("span", { className: "text-muted-foreground", children: "\u2013" }), _jsx(Input, { type: inputType, "aria-label": `${field.label ?? field.name} maximum`, placeholder: "Max", value: maxValue, min: minValue || undefined, onChange: (event) => apply(minValue, event.currentTarget.value) })] }));
106
+ }
107
+ /** A text-like field's filter: an exact match. */
108
+ function TextFilterControl({ field, value, onChange, }) {
109
+ return (_jsx(Input, { type: "text", "aria-label": field.label ?? field.name, placeholder: "Exact match", value: value?.eq === undefined ? "" : String(value.eq), onChange: (event) => {
110
+ const next = event.currentTarget.value;
111
+ onChange(next === "" ? undefined : { eq: next });
112
+ } }));
113
+ }
114
+ function FilterControl({ field, value, onChange, }) {
115
+ if (field.fieldType === "boolean") {
116
+ return (_jsx(BooleanFilterControl, { field: field, value: value, onChange: onChange }));
117
+ }
118
+ if (field.fieldType === "select") {
119
+ return (_jsx(SelectFilterControl, { field: field, value: value, onChange: onChange }));
120
+ }
121
+ if (field.fieldType === "number" ||
122
+ field.fieldType === "date" ||
123
+ field.fieldType === "datetime") {
124
+ return (_jsx(RangeFilterControl, { field: field, value: value, onChange: onChange }));
125
+ }
126
+ return _jsx(TextFilterControl, { field: field, value: value, onChange: onChange });
127
+ }
128
+ /**
129
+ * A grid of per-field filter controls one per `filterable` field, typed to
130
+ * that field's `fieldType` (boolean toggle, select dropdown, number/date
131
+ * range, or exact-match text) that read and write `ResourceTable`'s active
132
+ * filters. Renders nothing if no field is `filterable`.
133
+ */
134
+ export function ResourceTableFilterPanel({ fields, filters, onFiltersChange, }) {
135
+ const filterFields = filterableFields(fields);
136
+ const hasActiveFilters = Object.keys(filters).length > 0;
137
+ if (filterFields.length === 0) {
138
+ return null;
139
+ }
140
+ function setFilter(name, next) {
141
+ const nextFilters = { ...filters };
142
+ if (!next) {
143
+ delete nextFilters[name];
144
+ }
145
+ else {
146
+ nextFilters[name] = next;
147
+ }
148
+ onFiltersChange(nextFilters);
149
+ }
150
+ return (_jsxs("div", { className: "grid grid-cols-1 gap-3 rounded-lg border border-border p-3 sm:grid-cols-2 md:grid-cols-3", children: [hasActiveFilters ? (_jsx("div", { className: "flex justify-end sm:col-span-2 md:col-span-3", children: _jsx(Button, { type: "button", variant: "ghost", size: "xs", onClick: () => onFiltersChange({}), children: "Clear filters" }) })) : null, filterFields.map((field) => (_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: field.label ?? field.name }), _jsx(FilterControl, { field: field, value: filters[field.name], onChange: (next) => setFilter(field.name, next) })] }, field.name)))] }));
151
+ }
@@ -0,0 +1,45 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { RowData } from "@tanstack/react-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 (Edit opens a `ResourceForm` dialog pre-filled
11
+ * from the row's own data; Delete opens a confirmation dialog backed by
12
+ * `useDeleteResource`).
13
+ *
14
+ * This component has no way to know ahead of time which of those an actor
15
+ * may use actors never reach the browser (see `ResourceAccess`), so
16
+ * permissions are only ever discovered by attempting the operation. A
17
+ * control whose attempt comes back 403 is hidden for the rest of this
18
+ * component's lifetime rather than shown as a dead end.
19
+ */
20
+ actions?: boolean;
21
+ /**
22
+ * Renders per-row actions (e.g. custom edit/delete buttons). Composed
23
+ * alongside the built-in actions when `actions` is also set, not in place
24
+ * of them.
25
+ */
26
+ renderActions?: (record: TRecord) => ReactNode;
27
+ /**
28
+ * Renders custom actions for the current row selection (e.g. a bulk
29
+ * export button), shown in the selection bar alongside the built-in
30
+ * "Delete selected" action when `actions` is also set. Setting either this
31
+ * or `actions` adds a selection checkbox column. Called with the selected
32
+ * records and a function that clears the selection.
33
+ */
34
+ renderBulkActions?: (records: TRecord[], clearSelection: () => void) => ReactNode;
35
+ /** Content shown in place of rows when the list is empty. Defaults to a plain message. */
36
+ emptyState?: ReactNode;
37
+ /** Class name applied to the outer container. */
38
+ className?: string;
39
+ }
40
+ /**
41
+ * A responsive resource table with search, sorting, pagination, and a
42
+ * mobile card layout. Standard CRUD actions and custom row actions are opt-in.
43
+ */
44
+ export declare function ResourceTable<TRecord extends RowData = Record<string, unknown>>({ resource, pageSize, actions, renderActions, renderBulkActions, emptyState, className, }: ResourceTableProps<TRecord>): ReactElement;
45
+ //# sourceMappingURL=resource-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-table.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAYpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAgBrD,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,gCAAgC,CAAC;AAwBxC,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;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC;IAC/C;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,CAClB,OAAO,EAAE,OAAO,EAAE,EAClB,cAAc,EAAE,MAAM,IAAI,KACvB,SAAS,CAAC;IACf,0FAA0F;IAC1F,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuCD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjD,EACA,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,GACV,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG,YAAY,CAiiB5C"}