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