@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 @@
1
+ {"version":3,"file":"use-verikit-schema-tree-form.d.ts","sourceRoot":"","sources":["../../src/form/use-verikit-schema-tree-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAExE,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAEhE,mEAAmE;AACnE,MAAM,WAAW,+BAA+B,CAAC,OAAO,GAAG,OAAO;IAChE,gEAAgE;IAChE,QAAQ,EAAE,uBAAuB,CAAC;IAClC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,8CAA8C;IAC9C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,iBAAiB,EACf,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,eAAe,GACf,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,mBAAmB,CACtB,CAAC;AAEF,sEAAsE;AACtE,MAAM,WAAW,8BAA8B,CAAC,OAAO,GAAG,OAAO;IAC/D,6CAA6C;IAC7C,IAAI,EAAE,UAAU,CAAC;IACjB,kCAAkC;IAClC,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,yDAAyD;IACzD,WAAW,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACrC,4CAA4C;IAC5C,cAAc,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,+BAA+B;IAC/B,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,uEAAuE;IACvE,QAAQ,EAAE,CACR,MAAM,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,6CAA6C;IAC7C,MAAM,EAAE,CACN,MAAM,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC,2BAA2B,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/D,yDAAyD;IACzD,aAAa,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM,GAAG,SAAS,CAAC;IACxD,uIAAuI;IACvI,SAAS,EAAE,WAAW,CAAC,4BAA4B,CAAC,CAAC;CACtD;AAMD,gEAAgE;AAChE,wBAAgB,wBAAwB,CAAC,OAAO,GAAG,OAAO,EAAE,EAC1D,QAAQ,EACR,OAAO,EACP,aAAkB,EAClB,QAAQ,GACT,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAoHpF"}
@@ -0,0 +1,96 @@
1
+ import { useForm } from "@tanstack/vue-form";
2
+ import { isResource } from "@verikit/ui-core/form/resolve-fields";
3
+ import { pathKey } from "@verikit/ui-core/layout/path";
4
+ import { submitVerikitSchemaTreeForm } from "@verikit/ui-core/form/schema-tree";
5
+ import { firstFieldError, firstFieldErrors, omitFieldError, } from "@verikit/ui-core/form/submission";
6
+ import { computed, ref } from "vue";
7
+ function resolveVerikitTree(source) {
8
+ return isResource(source) ? source.toSchema().tree : source.tree;
9
+ }
10
+ /** Creates a TanStack-backed form for a Verikit schema tree. */
11
+ export function useVerikitSchemaTreeForm({ resource, actions, defaultValues = {}, onSubmit, }) {
12
+ const tree = resolveVerikitTree(resource);
13
+ const fieldErrors = ref({});
14
+ // Stable per-row ids for repeater rows, keyed by the repeater's own path. Grown
15
+ // lazily (per index, as `getRepeaterRowKey` is called during render) to cover rows
16
+ // that arrived some other way than `onRepeaterAdd` (e.g. pre-populated `defaultValues`); shrunk explicitly by `onRepeaterRemove`, which is the only place that knows which index was actually removed.
17
+ const repeaterRowKeys = new Map();
18
+ const form = useForm({
19
+ defaultValues,
20
+ onSubmit: async ({ value }) => {
21
+ await submit(value);
22
+ },
23
+ });
24
+ const values = form.useSelector((state) => state.values);
25
+ const submit = async (values = form.state.values) => {
26
+ const result = await submitVerikitSchemaTreeForm({
27
+ tree,
28
+ values,
29
+ onSubmit,
30
+ });
31
+ fieldErrors.value = result.fieldErrors;
32
+ return result;
33
+ };
34
+ const validate = async (values = form.state.values) => {
35
+ const result = await submitVerikitSchemaTreeForm({ tree, values });
36
+ fieldErrors.value = result.fieldErrors;
37
+ return result;
38
+ };
39
+ const getFieldError = (path) => firstFieldError(fieldErrors.value, pathKey(path));
40
+ const onFieldChange = (path, value) => {
41
+ form.setFieldValue(pathKey(path), value);
42
+ fieldErrors.value = omitFieldError(fieldErrors.value, pathKey(path));
43
+ };
44
+ const onFieldBlur = (path) => {
45
+ void form.validateField(pathKey(path), "blur");
46
+ };
47
+ const onRepeaterAdd = (path) => {
48
+ form.setFieldValue(pathKey(path), (current) => Array.isArray(current) ? [...current, {}] : [{}]);
49
+ };
50
+ const onRepeaterRemove = (path, index) => {
51
+ form.setFieldValue(pathKey(path), (current) => Array.isArray(current)
52
+ ? current.filter((_, itemIndex) => itemIndex !== index)
53
+ : current);
54
+ // Splices the same index out of the cached ids so a row's id always
55
+ // tracks that row, not whatever now sits at its old position.
56
+ repeaterRowKeys.get(pathKey(path))?.splice(index, 1);
57
+ };
58
+ const getRepeaterRowKey = (path, index) => {
59
+ const key = pathKey(path);
60
+ let ids = repeaterRowKeys.get(key);
61
+ if (!ids) {
62
+ ids = [];
63
+ repeaterRowKeys.set(key, ids);
64
+ }
65
+ while (ids.length <= index) {
66
+ ids.push(crypto.randomUUID());
67
+ }
68
+ return ids[index];
69
+ };
70
+ const errors = computed(() => firstFieldErrors(fieldErrors.value));
71
+ const treeProps = computed(() => ({
72
+ values: values.value,
73
+ errors: errors.value,
74
+ actions,
75
+ onFieldChange,
76
+ onFieldBlur,
77
+ onRepeaterAdd,
78
+ onRepeaterRemove,
79
+ getRepeaterRowKey,
80
+ }));
81
+ return {
82
+ form: form,
83
+ tree,
84
+ fieldErrors,
85
+ setFieldErrors: (errors) => {
86
+ fieldErrors.value = errors;
87
+ },
88
+ clearFieldErrors: () => {
89
+ fieldErrors.value = {};
90
+ },
91
+ validate,
92
+ submit,
93
+ getFieldError,
94
+ treeProps,
95
+ };
96
+ }
@@ -0,0 +1,9 @@
1
+ export * from "./client/index.js";
2
+ export * from "./fields/index.js";
3
+ export * from "./form/index.js";
4
+ export * from "./layout/index.js";
5
+ export * from "./query/index.js";
6
+ export * from "./relationships/index.js";
7
+ export * from "./resource/index.js";
8
+ export { cn } from "./lib/utils.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./client/index.js";
2
+ export * from "./fields/index.js";
3
+ export * from "./form/index.js";
4
+ export * from "./layout/index.js";
5
+ export * from "./query/index.js";
6
+ export * from "./relationships/index.js";
7
+ export * from "./resource/index.js";
8
+ export { cn } from "./lib/utils.js";
@@ -0,0 +1,5 @@
1
+ export { getValueAtPath, pathKey, setValueAtPath, } from "@verikit/ui-core/layout/path";
2
+ export type { SchemaPath } from "@verikit/ui-core/layout/path";
3
+ export { RenderSchemaNode, RenderSchemaTree } from "./render-schema-node.js";
4
+ export type { RenderSchemaNodeProps, RenderSchemaTreeProps, SchemaActionRegistry, SchemaActionSource, SchemaRenderProps, } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,cAAc,GACf,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { getValueAtPath, pathKey, setValueAtPath, } from "@verikit/ui-core/layout/path";
2
+ export { RenderSchemaNode, RenderSchemaTree } from "./render-schema-node.js";
@@ -0,0 +1,9 @@
1
+ import { type VNode, type VNodeChild } from "vue";
2
+ import type { RenderSchemaNodeProps, RenderSchemaTreeProps } from "./types.js";
3
+ /**
4
+ * Renders one Verikit schema node using the built-in Vue layout components.
5
+ */
6
+ export declare function RenderSchemaNode(props: RenderSchemaNodeProps): VNodeChild;
7
+ /** Renders a list of Verikit schema nodes. */
8
+ export declare function RenderSchemaTree({ nodes, ...rest }: RenderSchemaTreeProps): VNode[];
9
+ //# sourceMappingURL=render-schema-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-schema-node.d.ts","sourceRoot":"","sources":["../../src/layout/render-schema-node.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAU/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAsW/E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,UAAU,CAsBzE;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,GAAG,IAAI,EACR,EAAE,qBAAqB,GAAG,KAAK,EAAE,CAMjC"}
@@ -0,0 +1,265 @@
1
+ import { isFieldConditionMet, } from "@verikit/core";
2
+ import { Fragment, h } from "vue";
3
+ import { Button } from "#components/button";
4
+ import { cn } from "#lib/utils";
5
+ import { RenderField } from "../fields/index.js";
6
+ import { BelongsToRelationshipField } from "../relationships/belongs-to-field.js";
7
+ import { getValueAtPath, pathKey, } from "@verikit/ui-core/layout/path";
8
+ function actionSchemaFor(node, props) {
9
+ const source = props.actions?.[node.name];
10
+ if (!source) {
11
+ return undefined;
12
+ }
13
+ return "toSchema" in source ? source.toSchema() : source;
14
+ }
15
+ function actionInputNodes(node, props) {
16
+ const actionSchema = actionSchemaFor(node, props);
17
+ if (actionSchema?.form) {
18
+ return Object.entries(actionSchema.form).map(([name, field]) => ({
19
+ ...field,
20
+ type: "field",
21
+ name,
22
+ }));
23
+ }
24
+ return node.input;
25
+ }
26
+ function schemaNodeKey(node, index) {
27
+ return "name" in node && typeof node.name === "string"
28
+ ? `${node.type}:${node.name}`
29
+ : `${node.type}:${index}`;
30
+ }
31
+ function clampIndex(index, length) {
32
+ if (length <= 0) {
33
+ return 0;
34
+ }
35
+ return Math.min(Math.max(index, 0), length - 1);
36
+ }
37
+ function schemaRenderProps(props) {
38
+ const { node: _node, className: _className, ...rest } = props;
39
+ return rest;
40
+ }
41
+ /** Sibling values at a node's own nesting level, for evaluating `condition`. */
42
+ function siblingValues(values, path) {
43
+ const container = getValueAtPath(values, path);
44
+ return typeof container === "object" &&
45
+ container !== null &&
46
+ !Array.isArray(container)
47
+ ? container
48
+ : {};
49
+ }
50
+ function renderFieldNode(node, props, path) {
51
+ if (!isFieldConditionMet(node.condition, siblingValues(props.values, path))) {
52
+ return null;
53
+ }
54
+ const fieldPath = [...path, node.name];
55
+ return RenderField({
56
+ field: node,
57
+ registry: props.registry,
58
+ className: props.className,
59
+ value: getValueAtPath(props.values, fieldPath),
60
+ error: props.errors?.[pathKey(fieldPath)],
61
+ disabled: props.disabled,
62
+ readOnly: props.readOnly,
63
+ onValueChange: (value) => props.onFieldChange?.(fieldPath, value),
64
+ onBlur: () => props.onFieldBlur?.(fieldPath),
65
+ });
66
+ }
67
+ /**
68
+ * Resolves relationships using a field reference from `.via()`.
69
+ * Adapter-specific references require a custom `renderRelationship`.
70
+ */
71
+ function resolveForeignKeyFieldName(foreignKey) {
72
+ return typeof foreignKey === "string" ? foreignKey : undefined;
73
+ }
74
+ /**
75
+ * Renders relationships using `renderRelationship` when provided.
76
+ * Otherwise, `belongsTo` uses the built-in picker when its foreign key
77
+ * is resolvable; collection relationships render nothing by default.
78
+ */
79
+ function renderRelationshipNode(node, props, path) {
80
+ if (props.renderRelationship) {
81
+ return props.renderRelationship(node, path);
82
+ }
83
+ if (node.relationshipType !== "belongsTo") {
84
+ return null;
85
+ }
86
+ const foreignKeyName = resolveForeignKeyFieldName(node.foreignKey);
87
+ if (!foreignKeyName) {
88
+ return null;
89
+ }
90
+ const foreignKeyPath = [...path, foreignKeyName];
91
+ return h(BelongsToRelationshipField, {
92
+ relationship: node,
93
+ className: props.className,
94
+ value: getValueAtPath(props.values, foreignKeyPath),
95
+ error: props.errors?.[pathKey(foreignKeyPath)],
96
+ disabled: props.disabled,
97
+ readOnly: props.readOnly,
98
+ onValueChange: (value) => props.onFieldChange?.(foreignKeyPath, value),
99
+ onBlur: () => props.onFieldBlur?.(foreignKeyPath),
100
+ });
101
+ }
102
+ function renderSectionNode(node, props, path) {
103
+ return h("section", { class: cn("grid gap-4", props.className) }, [
104
+ h("h3", { class: "text-sm font-medium text-foreground" }, node.title),
105
+ RenderSchemaTree({
106
+ ...schemaRenderProps(props),
107
+ nodes: node.children,
108
+ path,
109
+ }),
110
+ ]);
111
+ }
112
+ function renderGridNode(node, props, path) {
113
+ return h("div", {
114
+ class: cn("grid gap-4", props.className),
115
+ style: { gridTemplateColumns: `repeat(${node.columns}, minmax(0, 1fr))` },
116
+ }, [
117
+ RenderSchemaTree({
118
+ ...schemaRenderProps(props),
119
+ nodes: node.children,
120
+ path,
121
+ }),
122
+ ]);
123
+ }
124
+ function renderTabsNode(node, props, path) {
125
+ const activeTab = clampIndex(props.activeTab ?? 0, node.tabs.length);
126
+ const activeTabEntry = node.tabs[activeTab];
127
+ return h("div", { class: cn("grid gap-4", props.className) }, [
128
+ h("div", { role: "tablist", class: "flex flex-wrap gap-1 border-b border-border" }, node.tabs.map((tab, index) => h(Button, {
129
+ key: tab.title,
130
+ type: "button",
131
+ role: "tab",
132
+ "aria-selected": index === activeTab,
133
+ variant: index === activeTab ? "secondary" : "ghost",
134
+ size: "sm",
135
+ onClick: () => props.onActiveTabChange?.(index),
136
+ }, { default: () => tab.title }))),
137
+ activeTabEntry
138
+ ? h("div", { role: "tabpanel" }, [
139
+ RenderSchemaTree({
140
+ ...schemaRenderProps(props),
141
+ nodes: activeTabEntry.children,
142
+ path,
143
+ }),
144
+ ])
145
+ : null,
146
+ ]);
147
+ }
148
+ function renderWizardNode(node, props, path) {
149
+ const stepCount = node.steps.length;
150
+ const activeStep = clampIndex(props.activeStep ?? 0, stepCount);
151
+ const activeStepEntry = node.steps[activeStep];
152
+ return h("div", { class: cn("grid gap-4", props.className) }, [
153
+ h("ol", { class: "flex flex-wrap gap-3 text-sm text-muted-foreground" }, node.steps.map((step, index) => h("li", {
154
+ key: step.title,
155
+ "aria-current": index === activeStep ? "step" : undefined,
156
+ class: cn(index === activeStep && "font-medium text-foreground"),
157
+ }, step.title))),
158
+ activeStepEntry
159
+ ? RenderSchemaTree({
160
+ ...schemaRenderProps(props),
161
+ nodes: activeStepEntry.children,
162
+ path,
163
+ })
164
+ : null,
165
+ h("div", { class: "flex justify-between gap-2" }, [
166
+ h(Button, {
167
+ type: "button",
168
+ variant: "outline",
169
+ size: "sm",
170
+ disabled: activeStep <= 0,
171
+ onClick: () => props.onActiveStepChange?.(activeStep - 1),
172
+ }, { default: () => "Back" }),
173
+ h(Button, {
174
+ type: "button",
175
+ size: "sm",
176
+ disabled: activeStep >= stepCount - 1,
177
+ onClick: () => props.onActiveStepChange?.(activeStep + 1),
178
+ }, { default: () => "Next" }),
179
+ ]),
180
+ ]);
181
+ }
182
+ /**
183
+ * Renders a repeater's rows keyed by `getRepeaterRowKey` (when the caller supplies one, as `useVerikitSchemaTreeForm` does) instead of array index. Index-based keys make Vue reuse a removed row's DOM (and any focus or uncontrolled state inside it) for whatever row happens to shift into its position afterward. Falls back to `index` when no key source is given.
184
+ */
185
+ function renderRepeaterNode(node, props, path) {
186
+ const repeaterPath = [...path, node.name];
187
+ const items = getValueAtPath(props.values, repeaterPath);
188
+ const rows = Array.isArray(items) ? items : [];
189
+ return h("div", { class: cn("grid gap-4", props.className) }, [
190
+ ...rows.map((_, index) => h("div", {
191
+ key: props.getRepeaterRowKey?.(repeaterPath, index) ?? index,
192
+ class: "grid gap-3 rounded-lg border border-border p-3",
193
+ }, [
194
+ RenderSchemaTree({
195
+ ...schemaRenderProps(props),
196
+ nodes: node.children,
197
+ path: [...repeaterPath, index],
198
+ }),
199
+ h(Button, {
200
+ type: "button",
201
+ variant: "ghost",
202
+ size: "sm",
203
+ class: "justify-self-start",
204
+ onClick: () => props.onRepeaterRemove?.(repeaterPath, index),
205
+ }, { default: () => "Remove" }),
206
+ ])),
207
+ h(Button, {
208
+ type: "button",
209
+ variant: "outline",
210
+ size: "sm",
211
+ class: "justify-self-start",
212
+ onClick: () => props.onRepeaterAdd?.(repeaterPath),
213
+ }, { default: () => "Add" }),
214
+ ]);
215
+ }
216
+ function renderActionNode(node, props, path) {
217
+ const actionPath = [...path, node.name];
218
+ const actionSchema = actionSchemaFor(node, props);
219
+ const input = actionInputNodes(node, props);
220
+ return h("div", { class: cn("grid gap-4", props.className) }, [
221
+ input
222
+ ? RenderSchemaTree({
223
+ ...schemaRenderProps(props),
224
+ nodes: input,
225
+ path: actionPath,
226
+ })
227
+ : null,
228
+ h(Button, {
229
+ type: "button",
230
+ class: "justify-self-start",
231
+ onClick: () => props.onAction?.(node.name, actionPath),
232
+ }, { default: () => node.label ?? actionSchema?.label ?? node.name }),
233
+ ]);
234
+ }
235
+ /**
236
+ * Renders one Verikit schema node using the built-in Vue layout components.
237
+ */
238
+ export function RenderSchemaNode(props) {
239
+ const { node } = props;
240
+ const path = props.path ?? [];
241
+ switch (node.type) {
242
+ case "field":
243
+ return renderFieldNode(node, props, path);
244
+ case "relationship":
245
+ return renderRelationshipNode(node, props, path);
246
+ case "section":
247
+ return renderSectionNode(node, props, path);
248
+ case "grid":
249
+ return renderGridNode(node, props, path);
250
+ case "tabs":
251
+ return renderTabsNode(node, props, path);
252
+ case "wizard":
253
+ return renderWizardNode(node, props, path);
254
+ case "repeater":
255
+ return renderRepeaterNode(node, props, path);
256
+ case "action":
257
+ return renderActionNode(node, props, path);
258
+ }
259
+ }
260
+ /** Renders a list of Verikit schema nodes. */
261
+ export function RenderSchemaTree({ nodes, ...rest }) {
262
+ return nodes.map((node, index) => h(Fragment, { key: schemaNodeKey(node, index) }, [
263
+ RenderSchemaNode({ node, ...rest }),
264
+ ]));
265
+ }
@@ -0,0 +1,68 @@
1
+ import type { RelationshipNode, SchemaNode } from "@verikit/core";
2
+ import type { ActionSchema } from "@verikit/runtime";
3
+ import type { VNodeChild } from "vue";
4
+ import type { VerikitFieldRegistry } from "../fields/types.js";
5
+ import type { SchemaPath } from "@verikit/ui-core/layout/path";
6
+ /**
7
+ * Runtime action builder or serialized action schema used by schema renderers.
8
+ */
9
+ export type SchemaActionSource = ActionSchema | {
10
+ readonly name: string;
11
+ toSchema(): ActionSchema;
12
+ };
13
+ /** Runtime actions keyed by action node name. */
14
+ export type SchemaActionRegistry = Partial<Record<string, SchemaActionSource>>;
15
+ /** Shared props used while rendering Verikit schema nodes. */
16
+ export interface SchemaRenderProps {
17
+ /** Current form values. */
18
+ values: Record<string, unknown>;
19
+ /** Path prefix for nested schema nodes. */
20
+ path?: SchemaPath;
21
+ /** Error content keyed by schema path. */
22
+ errors?: Record<string, VNodeChild>;
23
+ /** Disables all rendered fields when supported. */
24
+ disabled?: boolean;
25
+ /** Marks all rendered fields as read-only when supported. */
26
+ readOnly?: boolean;
27
+ /** Optional field renderer overrides. */
28
+ registry?: Partial<VerikitFieldRegistry>;
29
+ /** Runtime actions whose forms should render for matching action nodes. */
30
+ actions?: SchemaActionRegistry;
31
+ /** Active tab index for tab nodes. */
32
+ activeTab?: number;
33
+ /** Called when a tab node changes active tab. */
34
+ onActiveTabChange?: (index: number) => void;
35
+ /** Active step index for wizard nodes. */
36
+ activeStep?: number;
37
+ /** Called when a wizard node changes active step. */
38
+ onActiveStepChange?: (index: number) => void;
39
+ /** Called when a field value changes. */
40
+ onFieldChange?: (path: SchemaPath, value: unknown) => void;
41
+ /** Called when a field loses focus. */
42
+ onFieldBlur?: (path: SchemaPath) => void;
43
+ /** Called when an action node is triggered. */
44
+ onAction?: (name: string, path: SchemaPath) => void;
45
+ /** Called when a repeater should append an item. */
46
+ onRepeaterAdd?: (path: SchemaPath) => void;
47
+ /** Called when a repeater should remove an item. */
48
+ onRepeaterRemove?: (path: SchemaPath, index: number) => void;
49
+ /**
50
+ * Returns a stable Vue key for a repeater row, given the repeater's own path and the row's current index. Falls back to `index` when omitted fine for a tree with no repeaters, but a caller that removes rows from the middle of one should supply this (`useVerikitSchemaTreeForm` does) so Vue doesn't reuse a removed row's DOM for whatever row shifts into its position.
51
+ */
52
+ getRepeaterRowKey?: (path: SchemaPath, index: number) => string;
53
+ /** Custom renderer for relationship nodes. */
54
+ renderRelationship?: (node: RelationshipNode, path: SchemaPath) => VNodeChild;
55
+ }
56
+ /** Props for rendering a single schema node. */
57
+ export interface RenderSchemaNodeProps extends SchemaRenderProps {
58
+ /** Schema node to render. */
59
+ node: SchemaNode;
60
+ /** Class name applied to the node wrapper when supported. */
61
+ className?: string;
62
+ }
63
+ /** Props for rendering a list of schema nodes. */
64
+ export interface RenderSchemaTreeProps extends SchemaRenderProps {
65
+ /** Schema nodes to render in order. */
66
+ nodes: readonly SchemaNode[];
67
+ }
68
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/layout/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,IAAI,YAAY,CAAC;CAC1B,CAAC;AAEN,iDAAiD;AACjD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE/E,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,2CAA2C;IAC3C,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,yCAAyC;IACzC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,uCAAuC;IACvC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpD,oDAAoD;IACpD,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7D;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAChE,8CAA8C;IAC9C,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC;CAC/E;AAED,gDAAgD;AAChD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,6BAA6B;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,uCAAuC;IACvC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type ClassValue } from "clsx";
2
+ /** Merges conditional class names and resolves Tailwind conflicts. */
3
+ export declare function cn(...inputs: ClassValue[]): string;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C,sEAAsE;AACtE,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAElD"}
@@ -0,0 +1,6 @@
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ /** Merges conditional class names and resolves Tailwind conflicts. */
4
+ export function cn(...inputs) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,13 @@
1
+ export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
2
+ export type { UseListResourceOptions, UseFindResourceOptions, UseResourceRelationshipOptions, } from "./use-resource-queries.js";
3
+ export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
4
+ export type { UseCreateResourceOptions, UpdateResourceVariables, UseUpdateResourceOptions, UseDeleteResourceOptions, ActionResourceVariables, UseActionResourceOptions, } from "./use-resource-mutations.js";
5
+ export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
6
+ export type { ResourceQueryKeys } from "@verikit/ui-core/query/query-keys";
7
+ export { useResourceForm } from "./use-resource-form.js";
8
+ export type { UseResourceFormOptions, UseResourceFormResult, UseResourceFormSource, } from "./use-resource-form.js";
9
+ export { useResourceSchemaTreeForm } from "./use-resource-schema-tree-form.js";
10
+ export type { UseResourceSchemaTreeFormOptions, UseResourceSchemaTreeFormResult, } from "./use-resource-schema-tree-form.js";
11
+ export { useResourceTable } from "./use-resource-table.js";
12
+ export type { ResourceTableFilters, UseResourceTableOptions, UseResourceTableResult, UseResourceTableSource, } from "./use-resource-table.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,YAAY,EACV,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
2
+ export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
3
+ export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
4
+ export { useResourceForm } from "./use-resource-form.js";
5
+ export { useResourceSchemaTreeForm } from "./use-resource-schema-tree-form.js";
6
+ export { useResourceTable } from "./use-resource-table.js";
@@ -0,0 +1,39 @@
1
+ import type { Resource, ResourceSchema } from "@verikit/core";
2
+ import { type ComputedRef } from "vue";
3
+ import type { UseVerikitFormResult } from "../form/use-verikit-form.js";
4
+ import type { VerikitFormValues } from "@verikit/ui-core/form/submission";
5
+ /** A resource builder or its finalized schema either carries its own name. */
6
+ export type UseResourceFormSource = Resource | ResourceSchema;
7
+ /** Options for creating a resource-backed form that submits over `@verikit/client`. */
8
+ export interface UseResourceFormOptions<TRecord> {
9
+ /** Updates the record with this id instead of creating a new one. */
10
+ id?: string;
11
+ /** Initial values passed to TanStack Form. */
12
+ defaultValues?: VerikitFormValues;
13
+ /** Called with the created or updated record after a successful submit. */
14
+ onSuccess?: (record: TRecord) => void;
15
+ /**
16
+ * Called when the create/update mutation itself fails (e.g. a network error
17
+ * or a permission-denied response) — not for client-side field validation
18
+ * failures, which surface via `fieldErrors`/`submitError` instead.
19
+ */
20
+ onError?: (error: Error) => void;
21
+ }
22
+ /** State and helpers returned by {@link useResourceForm}. */
23
+ export interface UseResourceFormResult<TRecord = Record<string, unknown>> extends UseVerikitFormResult<TRecord> {
24
+ /** Whether the create/update mutation is currently in flight. */
25
+ isSubmitting: ComputedRef<boolean>;
26
+ /** Error from the most recent create/update mutation, if any. */
27
+ submitError: ComputedRef<Error | null>;
28
+ }
29
+ /**
30
+ * The single resource-backed form composable: takes a `Resource` (or its
31
+ * `ResourceSchema`) and wires `useVerikitForm` straight to its create/update
32
+ * mutation composables its own name is the one source of truth for both the
33
+ * fields and which resource to submit to, so there's no separate `name`
34
+ * string or raw field map to keep in sync with it. Submitting infers,
35
+ * validates, and sends the request in one step. Creates when no `id` option
36
+ * is given, updates that record's id otherwise.
37
+ */
38
+ export declare function useResourceForm<TRecord = Record<string, unknown>>(resource: UseResourceFormSource, { id, defaultValues, onSuccess, onError, }?: UseResourceFormOptions<TRecord>): UseResourceFormResult<TRecord>;
39
+ //# sourceMappingURL=use-resource-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-resource-form.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAM1E,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE9D,uFAAuF;AACvF,MAAM,WAAW,sBAAsB,CAAC,OAAO;IAC7C,qEAAqE;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB,CACpC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjC,SAAQ,oBAAoB,CAAC,OAAO,CAAC;IACrC,iEAAiE;IACjE,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,iEAAiE;IACjE,WAAW,EAAE,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,QAAQ,EAAE,qBAAqB,EAC/B,EACE,EAAE,EACF,aAAa,EACb,SAAS,EACT,OAAO,GACR,GAAE,sBAAsB,CAAC,OAAO,CAAM,GACtC,qBAAqB,CAAC,OAAO,CAAC,CAwBhC"}
@@ -0,0 +1,32 @@
1
+ import { computed } from "vue";
2
+ import { useVerikitForm } from "../form/use-verikit-form.js";
3
+ import { useCreateResource, useUpdateResource, } from "./use-resource-mutations.js";
4
+ /**
5
+ * The single resource-backed form composable: takes a `Resource` (or its
6
+ * `ResourceSchema`) and wires `useVerikitForm` straight to its create/update
7
+ * mutation composables its own name is the one source of truth for both the
8
+ * fields and which resource to submit to, so there's no separate `name`
9
+ * string or raw field map to keep in sync with it. Submitting infers,
10
+ * validates, and sends the request in one step. Creates when no `id` option
11
+ * is given, updates that record's id otherwise.
12
+ */
13
+ export function useResourceForm(resource, { id, defaultValues, onSuccess, onError, } = {}) {
14
+ const create = useCreateResource(resource.name, { onError });
15
+ const update = useUpdateResource(resource.name, { onError });
16
+ const form = useVerikitForm({
17
+ fields: resource,
18
+ defaultValues,
19
+ onSubmit: async (values) => {
20
+ const record = id
21
+ ? await update.mutateAsync({ id, input: values })
22
+ : await create.mutateAsync(values);
23
+ onSuccess?.(record);
24
+ return record;
25
+ },
26
+ });
27
+ return {
28
+ ...form,
29
+ isSubmitting: computed(() => create.isPending.value || update.isPending.value),
30
+ submitError: computed(() => create.error.value ?? update.error.value),
31
+ };
32
+ }