@btst/plugin-form-builder 0.0.0-stage → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/api/getters.cjs +154 -0
  3. package/dist/api/getters.mjs +145 -0
  4. package/dist/api/index.cjs +25 -0
  5. package/dist/api/index.d.cts +119 -0
  6. package/dist/api/index.d.mts +119 -0
  7. package/dist/api/index.d.ts +119 -0
  8. package/dist/api/index.mjs +6 -0
  9. package/dist/api/lifecycle-migrations.cjs +15 -0
  10. package/dist/api/lifecycle-migrations.mjs +13 -0
  11. package/dist/api/operations.cjs +1093 -0
  12. package/dist/api/operations.mjs +1082 -0
  13. package/dist/api/plugin.cjs +201 -0
  14. package/dist/api/plugin.mjs +192 -0
  15. package/dist/api/query-key-defs.cjs +43 -0
  16. package/dist/api/query-key-defs.mjs +39 -0
  17. package/dist/client/components/forms/form-renderer.cjs +193 -0
  18. package/dist/client/components/forms/form-renderer.mjs +191 -0
  19. package/dist/client/components/index.cjs +29 -0
  20. package/dist/client/components/index.d.cts +97 -0
  21. package/dist/client/components/index.d.mts +97 -0
  22. package/dist/client/components/index.d.ts +97 -0
  23. package/dist/client/components/index.mjs +18 -0
  24. package/dist/client/components/loading/form-builder-skeleton.cjs +32 -0
  25. package/dist/client/components/loading/form-builder-skeleton.mjs +30 -0
  26. package/dist/client/components/loading/form-list-skeleton.cjs +21 -0
  27. package/dist/client/components/loading/form-list-skeleton.mjs +19 -0
  28. package/dist/client/components/loading/submissions-skeleton.cjs +34 -0
  29. package/dist/client/components/loading/submissions-skeleton.mjs +32 -0
  30. package/dist/client/components/pages/404-page.cjs +28 -0
  31. package/dist/client/components/pages/404-page.mjs +26 -0
  32. package/dist/client/components/pages/form-builder-page.cjs +77 -0
  33. package/dist/client/components/pages/form-builder-page.internal.cjs +217 -0
  34. package/dist/client/components/pages/form-builder-page.internal.mjs +215 -0
  35. package/dist/client/components/pages/form-builder-page.mjs +75 -0
  36. package/dist/client/components/pages/form-list-page.cjs +44 -0
  37. package/dist/client/components/pages/form-list-page.internal.cjs +282 -0
  38. package/dist/client/components/pages/form-list-page.internal.mjs +280 -0
  39. package/dist/client/components/pages/form-list-page.mjs +42 -0
  40. package/dist/client/components/pages/submissions-page.cjs +64 -0
  41. package/dist/client/components/pages/submissions-page.internal.cjs +255 -0
  42. package/dist/client/components/pages/submissions-page.internal.mjs +253 -0
  43. package/dist/client/components/pages/submissions-page.mjs +62 -0
  44. package/dist/client/components/shared/default-error.cjs +17 -0
  45. package/dist/client/components/shared/default-error.mjs +15 -0
  46. package/dist/client/components/shared/empty-state.cjs +16 -0
  47. package/dist/client/components/shared/empty-state.mjs +14 -0
  48. package/dist/client/components/shared/page-wrapper.cjs +29 -0
  49. package/dist/client/components/shared/page-wrapper.mjs +27 -0
  50. package/dist/client/components/shared/pagination.cjs +49 -0
  51. package/dist/client/components/shared/pagination.mjs +47 -0
  52. package/dist/client/constants.cjs +5 -0
  53. package/dist/client/constants.mjs +3 -0
  54. package/dist/client/hooks/form-builder-hooks.cjs +203 -0
  55. package/dist/client/hooks/form-builder-hooks.mjs +186 -0
  56. package/dist/client/hooks/form-builder-resource.cjs +13 -0
  57. package/dist/client/hooks/form-builder-resource.mjs +11 -0
  58. package/dist/client/hooks/index.cjs +22 -0
  59. package/dist/client/hooks/index.d.cts +378 -0
  60. package/dist/client/hooks/index.d.mts +378 -0
  61. package/dist/client/hooks/index.d.ts +378 -0
  62. package/dist/client/hooks/index.mjs +1 -0
  63. package/dist/client/index.cjs +13 -0
  64. package/dist/client/index.d.cts +410 -0
  65. package/dist/client/index.d.mts +410 -0
  66. package/dist/client/index.d.ts +410 -0
  67. package/dist/client/index.mjs +2 -0
  68. package/dist/client/plugin.cjs +311 -0
  69. package/dist/client/plugin.mjs +309 -0
  70. package/dist/client.css +3 -0
  71. package/dist/db.cjs +99 -0
  72. package/dist/db.mjs +97 -0
  73. package/dist/permissions.cjs +95 -0
  74. package/dist/permissions.d.cts +94 -0
  75. package/dist/permissions.d.mts +94 -0
  76. package/dist/permissions.d.ts +94 -0
  77. package/dist/permissions.mjs +93 -0
  78. package/dist/query-keys.cjs +140 -0
  79. package/dist/query-keys.d.cts +392 -0
  80. package/dist/query-keys.d.mts +392 -0
  81. package/dist/query-keys.d.ts +392 -0
  82. package/dist/query-keys.mjs +137 -0
  83. package/dist/schemas.cjs +91 -0
  84. package/dist/schemas.mjs +82 -0
  85. package/dist/shared/plugin-form-builder.BZYGyFgT.d.mts +351 -0
  86. package/dist/shared/plugin-form-builder.Bbl9NufB.d.cts +408 -0
  87. package/dist/shared/plugin-form-builder.CSP5HR2O.d.ts +408 -0
  88. package/dist/shared/plugin-form-builder.Cmk083dA.d.cts +351 -0
  89. package/dist/shared/plugin-form-builder.D258Qpb8.d.ts +351 -0
  90. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.cts +118 -0
  91. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.mts +118 -0
  92. package/dist/shared/plugin-form-builder.DWrQ3lRX.d.ts +118 -0
  93. package/dist/shared/plugin-form-builder.lp98rFNl.d.mts +408 -0
  94. package/dist/style.css +6 -0
  95. package/dist/types.cjs +2 -0
  96. package/dist/types.d.cts +6 -0
  97. package/dist/types.d.mts +6 -0
  98. package/dist/types.d.ts +6 -0
  99. package/dist/types.mjs +1 -0
  100. package/dist/ui/src/components/accordion.cjs +81 -0
  101. package/dist/ui/src/components/accordion.mjs +62 -0
  102. package/dist/ui/src/components/alert-dialog.cjs +157 -0
  103. package/dist/ui/src/components/alert-dialog.mjs +132 -0
  104. package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
  105. package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
  106. package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
  107. package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
  108. package/dist/ui/src/components/auto-form/config.cjs +40 -0
  109. package/dist/ui/src/components/auto-form/config.mjs +37 -0
  110. package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
  111. package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
  112. package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
  113. package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
  114. package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
  115. package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
  116. package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
  117. package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
  118. package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
  119. package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
  120. package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
  121. package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
  122. package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
  123. package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
  124. package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
  125. package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
  126. package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
  127. package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
  128. package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
  129. package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
  130. package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
  131. package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
  132. package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
  133. package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
  134. package/dist/ui/src/components/auto-form/index.cjs +92 -0
  135. package/dist/ui/src/components/auto-form/index.mjs +86 -0
  136. package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
  137. package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
  138. package/dist/ui/src/components/auto-form/types.cjs +11 -0
  139. package/dist/ui/src/components/auto-form/types.mjs +9 -0
  140. package/dist/ui/src/components/button.cjs +56 -0
  141. package/dist/ui/src/components/button.mjs +53 -0
  142. package/dist/ui/src/components/calendar.cjs +207 -0
  143. package/dist/ui/src/components/calendar.mjs +190 -0
  144. package/dist/ui/src/components/checkbox.cjs +48 -0
  145. package/dist/ui/src/components/checkbox.mjs +32 -0
  146. package/dist/ui/src/components/date-picker.cjs +41 -0
  147. package/dist/ui/src/components/date-picker.mjs +39 -0
  148. package/dist/ui/src/components/dialog.cjs +141 -0
  149. package/dist/ui/src/components/dialog.mjs +118 -0
  150. package/dist/ui/src/components/dropdown-menu.cjs +81 -0
  151. package/dist/ui/src/components/dropdown-menu.mjs +62 -0
  152. package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
  153. package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
  154. package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
  155. package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
  156. package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
  157. package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
  158. package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
  159. package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
  160. package/dist/ui/src/components/form-builder/index.cjs +350 -0
  161. package/dist/ui/src/components/form-builder/index.mjs +344 -0
  162. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
  163. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
  164. package/dist/ui/src/components/form-builder/palette.cjs +52 -0
  165. package/dist/ui/src/components/form-builder/palette.mjs +49 -0
  166. package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
  167. package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
  168. package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
  169. package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
  170. package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
  171. package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
  172. package/dist/ui/src/components/form-builder/types.cjs +7 -0
  173. package/dist/ui/src/components/form-builder/types.mjs +5 -0
  174. package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
  175. package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
  176. package/dist/ui/src/components/form.cjs +120 -0
  177. package/dist/ui/src/components/form.mjs +98 -0
  178. package/dist/ui/src/components/input.cjs +23 -0
  179. package/dist/ui/src/components/input.mjs +21 -0
  180. package/dist/ui/src/components/label.cjs +39 -0
  181. package/dist/ui/src/components/label.mjs +23 -0
  182. package/dist/ui/src/components/page-layout.cjs +25 -0
  183. package/dist/ui/src/components/page-layout.mjs +23 -0
  184. package/dist/ui/src/components/page-wrapper.cjs +20 -0
  185. package/dist/ui/src/components/page-wrapper.mjs +18 -0
  186. package/dist/ui/src/components/popover.cjs +60 -0
  187. package/dist/ui/src/components/popover.mjs +42 -0
  188. package/dist/ui/src/components/radio-group.cjs +62 -0
  189. package/dist/ui/src/components/radio-group.mjs +45 -0
  190. package/dist/ui/src/components/select.cjs +161 -0
  191. package/dist/ui/src/components/select.mjs +139 -0
  192. package/dist/ui/src/components/separator.cjs +43 -0
  193. package/dist/ui/src/components/separator.mjs +27 -0
  194. package/dist/ui/src/components/skeleton.cjs +17 -0
  195. package/dist/ui/src/components/skeleton.mjs +15 -0
  196. package/dist/ui/src/components/stack-attribution.cjs +24 -0
  197. package/dist/ui/src/components/stack-attribution.mjs +22 -0
  198. package/dist/ui/src/components/switch.cjs +48 -0
  199. package/dist/ui/src/components/switch.mjs +32 -0
  200. package/dist/ui/src/components/table.cjs +89 -0
  201. package/dist/ui/src/components/table.mjs +82 -0
  202. package/dist/ui/src/components/tabs.cjs +84 -0
  203. package/dist/ui/src/components/tabs.mjs +65 -0
  204. package/dist/ui/src/components/textarea.cjs +20 -0
  205. package/dist/ui/src/components/textarea.mjs +18 -0
  206. package/dist/ui/src/lib/schema-converter.cjs +133 -0
  207. package/dist/ui/src/lib/schema-converter.mjs +127 -0
  208. package/dist/ui/src/lib/utils.cjs +10 -0
  209. package/dist/ui/src/lib/utils.mjs +8 -0
  210. package/dist/utils.cjs +41 -0
  211. package/dist/utils.mjs +32 -0
  212. package/package.json +175 -3
  213. package/README.md +0 -3
@@ -0,0 +1,368 @@
1
+ 'use client';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React__default, { useMemo, useState, useRef, useEffect, useCallback } from 'react';
4
+ import { z } from 'zod';
5
+ import AutoForm from './index.mjs';
6
+ import { Button } from '../button.mjs';
7
+ import { Separator } from '../separator.mjs';
8
+ import { cn } from '../../lib/utils.mjs';
9
+
10
+ function extractStepsFromSchema(schema) {
11
+ try {
12
+ const jsonSchema = schema.toJSONSchema();
13
+ if (jsonSchema.steps && Array.isArray(jsonSchema.steps)) {
14
+ return jsonSchema.steps;
15
+ }
16
+ } catch {
17
+ }
18
+ return [];
19
+ }
20
+ function getFieldStepAssignments(schema) {
21
+ const assignments = /* @__PURE__ */ new Map();
22
+ try {
23
+ const jsonSchema = schema.toJSONSchema();
24
+ const stepGroupMap = jsonSchema.stepGroupMap;
25
+ if (stepGroupMap) {
26
+ for (const [fieldName, stepGroup] of Object.entries(stepGroupMap)) {
27
+ assignments.set(fieldName, stepGroup);
28
+ }
29
+ return assignments;
30
+ }
31
+ const properties = jsonSchema.properties;
32
+ if (properties) {
33
+ for (const [fieldName, fieldSchema] of Object.entries(properties)) {
34
+ const stepGroup = fieldSchema.stepGroup;
35
+ if (typeof stepGroup === "number") {
36
+ assignments.set(fieldName, stepGroup);
37
+ } else {
38
+ assignments.set(fieldName, 0);
39
+ }
40
+ }
41
+ }
42
+ } catch {
43
+ }
44
+ return assignments;
45
+ }
46
+ function createStepSchema(fullSchema, stepIndex, fieldAssignments) {
47
+ const fieldsForStep = Array.from(fieldAssignments.entries()).filter(([, step]) => step === stepIndex).map(([field]) => field);
48
+ if (fieldsForStep.length === 0) {
49
+ return z.object({});
50
+ }
51
+ const pickObject = {};
52
+ for (const field of fieldsForStep) {
53
+ pickObject[field] = true;
54
+ }
55
+ return fullSchema.pick(pickObject);
56
+ }
57
+ function getObjectSchema(schema) {
58
+ if (schema instanceof z.ZodObject) {
59
+ return schema;
60
+ }
61
+ const schemaDef = schema._zod?.def ?? schema._def;
62
+ if (schemaDef) {
63
+ if (schemaDef.schema) {
64
+ return getObjectSchema(schemaDef.schema);
65
+ }
66
+ if (schemaDef.innerType) {
67
+ return getObjectSchema(schemaDef.innerType);
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ function DefaultStepper({
73
+ steps,
74
+ currentStepIndex,
75
+ onStepClick
76
+ }) {
77
+ return /* @__PURE__ */ jsx("nav", { "aria-label": "Form Steps", className: "mb-6", children: /* @__PURE__ */ jsx("ol", { className: "flex items-center justify-between gap-2", children: steps.map((step, index) => /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
78
+ /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 shrink-0", children: [
79
+ /* @__PURE__ */ jsx(
80
+ Button,
81
+ {
82
+ type: "button",
83
+ variant: index <= currentStepIndex ? "default" : "secondary",
84
+ "aria-current": currentStepIndex === index ? "step" : void 0,
85
+ "aria-posinset": index + 1,
86
+ "aria-setsize": steps.length,
87
+ className: "size-10 rounded-full p-0",
88
+ onClick: () => onStepClick?.(step.id),
89
+ children: index + 1
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium hidden sm:inline", children: step.label })
93
+ ] }),
94
+ index < steps.length - 1 && /* @__PURE__ */ jsx(
95
+ Separator,
96
+ {
97
+ className: cn(
98
+ "flex-1 min-w-4",
99
+ index < currentStepIndex ? "bg-primary" : "bg-muted"
100
+ )
101
+ }
102
+ )
103
+ ] }, step.id)) }) });
104
+ }
105
+ function SteppedAutoForm({
106
+ formSchema,
107
+ values: initialValues,
108
+ onValuesChange,
109
+ onSubmit,
110
+ fieldConfig,
111
+ children,
112
+ className,
113
+ nextButtonText = "Next",
114
+ backButtonText = "Back",
115
+ submitButtonText = "Submit",
116
+ StepperComponent = DefaultStepper,
117
+ isSubmitting = false
118
+ }) {
119
+ const steps = useMemo(() => extractStepsFromSchema(formSchema), [formSchema]);
120
+ const hasMultipleSteps = steps.length > 1;
121
+ const fieldAssignments = useMemo(
122
+ () => getFieldStepAssignments(formSchema),
123
+ [formSchema]
124
+ );
125
+ const [currentStepIndex, setCurrentStepIndex] = useState(0);
126
+ const [accumulatedValues, setAccumulatedValues] = useState(
127
+ initialValues ?? {}
128
+ );
129
+ const [completedSteps, setCompletedSteps] = useState(/* @__PURE__ */ new Set());
130
+ const [schemaErrors, setSchemaErrors] = useState(null);
131
+ const accumulatedValuesRef = useRef(accumulatedValues);
132
+ const onValuesChangeRef = useRef(onValuesChange);
133
+ useEffect(() => {
134
+ accumulatedValuesRef.current = accumulatedValues;
135
+ }, [accumulatedValues]);
136
+ useEffect(() => {
137
+ onValuesChangeRef.current = onValuesChange;
138
+ }, [onValuesChange]);
139
+ useEffect(() => {
140
+ if (initialValues) {
141
+ const newValues = {
142
+ ...accumulatedValuesRef.current,
143
+ ...initialValues
144
+ };
145
+ accumulatedValuesRef.current = newValues;
146
+ setAccumulatedValues(newValues);
147
+ }
148
+ }, [initialValues]);
149
+ const objectSchema = useMemo(() => getObjectSchema(formSchema), [formSchema]);
150
+ const stepSchemas = useMemo(() => {
151
+ if (!hasMultipleSteps || !objectSchema) return [];
152
+ return steps.map(
153
+ (_, index) => createStepSchema(objectSchema, index, fieldAssignments)
154
+ );
155
+ }, [hasMultipleSteps, objectSchema, steps, fieldAssignments]);
156
+ const currentStep = steps[currentStepIndex];
157
+ const currentStepSchema = stepSchemas[currentStepIndex];
158
+ const isFirst = currentStepIndex === 0;
159
+ const isLast = currentStepIndex === steps.length - 1;
160
+ const currentStepFieldConfig = useMemo(() => {
161
+ if (!fieldConfig) return void 0;
162
+ const stepFields = Array.from(fieldAssignments.entries()).filter(([, step]) => step === currentStepIndex).map(([field]) => field);
163
+ const filtered = {};
164
+ for (const field of stepFields) {
165
+ if (field in fieldConfig) {
166
+ filtered[field] = fieldConfig[field];
167
+ }
168
+ }
169
+ return filtered;
170
+ }, [fieldConfig, fieldAssignments, currentStepIndex]);
171
+ const currentStepValues = useMemo(() => {
172
+ const stepFields = Array.from(fieldAssignments.entries()).filter(([, step]) => step === currentStepIndex).map(([field]) => field);
173
+ const values = {};
174
+ for (const field of stepFields) {
175
+ if (field in accumulatedValues) {
176
+ values[field] = accumulatedValues[field];
177
+ }
178
+ }
179
+ return values;
180
+ }, [fieldAssignments, currentStepIndex, accumulatedValues]);
181
+ const handleStepClick = useCallback(
182
+ (stepId) => {
183
+ const stepIndex = steps.findIndex((s) => s.id === stepId);
184
+ if (stepIndex === -1) return;
185
+ const canNavigate = stepIndex === currentStepIndex || completedSteps.has(stepIndex) || stepIndex === currentStepIndex + 1 && completedSteps.has(currentStepIndex);
186
+ if (canNavigate) {
187
+ setCurrentStepIndex(stepIndex);
188
+ setSchemaErrors(null);
189
+ }
190
+ },
191
+ [steps, currentStepIndex, completedSteps]
192
+ );
193
+ const handleStepValuesChange = useCallback(
194
+ (stepValues, form) => {
195
+ const newAccumulated = { ...accumulatedValuesRef.current, ...stepValues };
196
+ accumulatedValuesRef.current = newAccumulated;
197
+ setAccumulatedValues(newAccumulated);
198
+ onValuesChangeRef.current?.(newAccumulated, form);
199
+ },
200
+ []
201
+ );
202
+ const handleStepSubmit = useCallback(
203
+ (stepValues) => {
204
+ const newAccumulated = { ...accumulatedValuesRef.current, ...stepValues };
205
+ accumulatedValuesRef.current = newAccumulated;
206
+ setAccumulatedValues(newAccumulated);
207
+ onValuesChangeRef.current?.(newAccumulated, void 0);
208
+ setCompletedSteps((prev) => /* @__PURE__ */ new Set([...prev, currentStepIndex]));
209
+ if (isLast) {
210
+ const allStepsCompleted = steps.every(
211
+ (_, index) => index === currentStepIndex || completedSteps.has(index)
212
+ );
213
+ if (!allStepsCompleted) {
214
+ const firstIncompleteStep = steps.findIndex(
215
+ (_, index) => index !== currentStepIndex && !completedSteps.has(index)
216
+ );
217
+ if (firstIncompleteStep !== -1) {
218
+ setCurrentStepIndex(firstIncompleteStep);
219
+ return;
220
+ }
221
+ }
222
+ const parseResult = formSchema.safeParse(newAccumulated);
223
+ if (parseResult.success) {
224
+ setSchemaErrors(null);
225
+ onSubmit?.(parseResult.data);
226
+ } else {
227
+ setSchemaErrors(parseResult.error);
228
+ const firstErrorPath = parseResult.error.issues[0]?.path[0];
229
+ if (typeof firstErrorPath === "string") {
230
+ const errorFieldStep = fieldAssignments.get(firstErrorPath);
231
+ if (errorFieldStep !== void 0 && errorFieldStep !== currentStepIndex) {
232
+ setCurrentStepIndex(errorFieldStep);
233
+ }
234
+ }
235
+ }
236
+ } else {
237
+ setCurrentStepIndex((prev) => prev + 1);
238
+ }
239
+ },
240
+ [isLast, onSubmit, currentStepIndex, steps, completedSteps, formSchema, fieldAssignments]
241
+ );
242
+ const handleBack = useCallback(() => {
243
+ if (!isFirst) {
244
+ setCurrentStepIndex((prev) => prev - 1);
245
+ setSchemaErrors(null);
246
+ }
247
+ }, [isFirst]);
248
+ if (!hasMultipleSteps) {
249
+ return /* @__PURE__ */ jsxs(
250
+ AutoForm,
251
+ {
252
+ formSchema,
253
+ values: initialValues,
254
+ onValuesChange,
255
+ onSubmit,
256
+ fieldConfig,
257
+ className,
258
+ children: [
259
+ /* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSubmitting, className: "w-full mt-4", children: submitButtonText }),
260
+ children
261
+ ]
262
+ }
263
+ );
264
+ }
265
+ if (!currentStepSchema || !currentStep) {
266
+ return null;
267
+ }
268
+ return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
269
+ /* @__PURE__ */ jsx(
270
+ StepperComponent,
271
+ {
272
+ steps: steps.map((s) => ({ id: s.id, label: s.title })),
273
+ currentStepIndex,
274
+ currentStepId: currentStep.id,
275
+ onStepClick: handleStepClick,
276
+ isFirst,
277
+ isLast
278
+ }
279
+ ),
280
+ /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
281
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: currentStep.title }),
282
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
283
+ "Step ",
284
+ currentStepIndex + 1,
285
+ " of ",
286
+ steps.length
287
+ ] })
288
+ ] }),
289
+ schemaErrors && schemaErrors.issues.length > 0 && /* @__PURE__ */ jsx(
290
+ "div",
291
+ {
292
+ role: "alert",
293
+ "aria-live": "assertive",
294
+ className: "rounded-md border border-destructive/50 bg-destructive/10 p-4 mb-4",
295
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
296
+ /* @__PURE__ */ jsx(
297
+ "svg",
298
+ {
299
+ className: "h-5 w-5 text-destructive shrink-0 mt-0.5",
300
+ fill: "none",
301
+ viewBox: "0 0 24 24",
302
+ stroke: "currentColor",
303
+ strokeWidth: 2,
304
+ children: /* @__PURE__ */ jsx(
305
+ "path",
306
+ {
307
+ strokeLinecap: "round",
308
+ strokeLinejoin: "round",
309
+ d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
310
+ }
311
+ )
312
+ }
313
+ ),
314
+ /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
315
+ /* @__PURE__ */ jsx("h4", { className: "text-sm font-medium text-destructive", children: "Validation Failed" }),
316
+ /* @__PURE__ */ jsx("ul", { className: "mt-2 text-sm text-destructive/90 list-disc list-inside space-y-1", children: schemaErrors.issues.map((issue, index) => /* @__PURE__ */ jsxs("li", { children: [
317
+ issue.path.length > 0 && /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
318
+ issue.path.join("."),
319
+ ": "
320
+ ] }),
321
+ issue.message
322
+ ] }, index)) })
323
+ ] }),
324
+ /* @__PURE__ */ jsx(
325
+ "button",
326
+ {
327
+ type: "button",
328
+ onClick: () => setSchemaErrors(null),
329
+ className: "text-destructive/70 hover:text-destructive shrink-0",
330
+ "aria-label": "Dismiss errors",
331
+ children: /* @__PURE__ */ jsx("svg", { className: "h-4 w-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) })
332
+ }
333
+ )
334
+ ] })
335
+ }
336
+ ),
337
+ /* @__PURE__ */ jsxs(
338
+ AutoForm,
339
+ {
340
+ formSchema: currentStepSchema,
341
+ values: currentStepValues,
342
+ onValuesChange: handleStepValuesChange,
343
+ onSubmit: handleStepSubmit,
344
+ fieldConfig: currentStepFieldConfig,
345
+ className: "space-y-4",
346
+ children: [
347
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-between pt-4", children: [
348
+ /* @__PURE__ */ jsx(
349
+ Button,
350
+ {
351
+ type: "button",
352
+ variant: "outline",
353
+ onClick: handleBack,
354
+ disabled: isFirst || isSubmitting,
355
+ children: backButtonText
356
+ }
357
+ ),
358
+ /* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSubmitting, children: isLast ? submitButtonText : nextButtonText })
359
+ ] }),
360
+ children
361
+ ]
362
+ },
363
+ currentStep.id
364
+ )
365
+ ] });
366
+ }
367
+
368
+ export { SteppedAutoForm };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var DependencyType = /* @__PURE__ */ ((DependencyType2) => {
4
+ DependencyType2[DependencyType2["DISABLES"] = 0] = "DISABLES";
5
+ DependencyType2[DependencyType2["REQUIRES"] = 1] = "REQUIRES";
6
+ DependencyType2[DependencyType2["HIDES"] = 2] = "HIDES";
7
+ DependencyType2[DependencyType2["SETS_OPTIONS"] = 3] = "SETS_OPTIONS";
8
+ return DependencyType2;
9
+ })(DependencyType || {});
10
+
11
+ exports.DependencyType = DependencyType;
@@ -0,0 +1,9 @@
1
+ var DependencyType = /* @__PURE__ */ ((DependencyType2) => {
2
+ DependencyType2[DependencyType2["DISABLES"] = 0] = "DISABLES";
3
+ DependencyType2[DependencyType2["REQUIRES"] = 1] = "REQUIRES";
4
+ DependencyType2[DependencyType2["HIDES"] = 2] = "HIDES";
5
+ DependencyType2[DependencyType2["SETS_OPTIONS"] = 3] = "SETS_OPTIONS";
6
+ return DependencyType2;
7
+ })(DependencyType || {});
8
+
9
+ export { DependencyType };
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const reactSlot = require('@radix-ui/react-slot');
5
+ const classVarianceAuthority = require('class-variance-authority');
6
+ const utils = require('../lib/utils.cjs');
7
+
8
+ const buttonVariants = classVarianceAuthority.cva(
9
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
10
+ {
11
+ variants: {
12
+ variant: {
13
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
14
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
15
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
16
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
17
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
18
+ link: "text-primary underline-offset-4 hover:underline"
19
+ },
20
+ size: {
21
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
22
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
23
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
24
+ icon: "size-9",
25
+ "icon-sm": "size-8",
26
+ "icon-lg": "size-10"
27
+ }
28
+ },
29
+ defaultVariants: {
30
+ variant: "default",
31
+ size: "default"
32
+ }
33
+ }
34
+ );
35
+ function Button({
36
+ className,
37
+ variant = "default",
38
+ size = "default",
39
+ asChild = false,
40
+ ...props
41
+ }) {
42
+ const Comp = asChild ? reactSlot.Slot : "button";
43
+ return /* @__PURE__ */ jsxRuntime.jsx(
44
+ Comp,
45
+ {
46
+ "data-slot": "button",
47
+ "data-variant": variant,
48
+ "data-size": size,
49
+ className: utils.cn(buttonVariants({ variant, size, className })),
50
+ ...props
51
+ }
52
+ );
53
+ }
54
+
55
+ exports.Button = Button;
56
+ exports.buttonVariants = buttonVariants;
@@ -0,0 +1,53 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Slot } from '@radix-ui/react-slot';
3
+ import { cva } from 'class-variance-authority';
4
+ import { cn } from '../lib/utils.mjs';
5
+
6
+ const buttonVariants = cva(
7
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
12
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
13
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
14
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
15
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
16
+ link: "text-primary underline-offset-4 hover:underline"
17
+ },
18
+ size: {
19
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
20
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
21
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
22
+ icon: "size-9",
23
+ "icon-sm": "size-8",
24
+ "icon-lg": "size-10"
25
+ }
26
+ },
27
+ defaultVariants: {
28
+ variant: "default",
29
+ size: "default"
30
+ }
31
+ }
32
+ );
33
+ function Button({
34
+ className,
35
+ variant = "default",
36
+ size = "default",
37
+ asChild = false,
38
+ ...props
39
+ }) {
40
+ const Comp = asChild ? Slot : "button";
41
+ return /* @__PURE__ */ jsx(
42
+ Comp,
43
+ {
44
+ "data-slot": "button",
45
+ "data-variant": variant,
46
+ "data-size": size,
47
+ className: cn(buttonVariants({ variant, size, className })),
48
+ ...props
49
+ }
50
+ );
51
+ }
52
+
53
+ export { Button, buttonVariants };