@btst/stack 1.5.2 → 1.6.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 (201) hide show
  1. package/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.cjs +68 -0
  2. package/dist/node_modules/.pnpm/@dnd-kit_accessibility@3.1.1_react@19.2.0/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.mjs +60 -0
  3. package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.cjs +3937 -0
  4. package/dist/node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.mjs +3907 -0
  5. package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.cjs +30 -0
  6. package/dist/node_modules/.pnpm/@dnd-kit_modifiers@9.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/modifiers/dist/modifiers.esm.mjs +28 -0
  7. package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.cjs +675 -0
  8. package/dist/node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.mjs +661 -0
  9. package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.cjs +358 -0
  10. package/dist/node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@19.2.0/node_modules/@dnd-kit/utilities/dist/utilities.esm.mjs +332 -0
  11. package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.cjs +211 -0
  12. package/dist/node_modules/.pnpm/@radix-ui_react-tabs@1.1.13_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_865f042350eb43f3338b0fffb33f6246/node_modules/@radix-ui/react-tabs/dist/index.mjs +188 -0
  13. package/dist/packages/better-stack/src/plugins/cms/api/plugin.cjs +3 -2
  14. package/dist/packages/better-stack/src/plugins/cms/api/plugin.mjs +3 -2
  15. package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.cjs +15 -15
  16. package/dist/packages/better-stack/src/plugins/cms/client/components/forms/content-form.mjs +16 -16
  17. package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.cjs +588 -0
  18. package/dist/packages/better-stack/src/plugins/form-builder/api/plugin.mjs +586 -0
  19. package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.cjs +131 -0
  20. package/dist/packages/better-stack/src/plugins/form-builder/client/components/forms/form-renderer.mjs +129 -0
  21. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.cjs +32 -0
  22. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-builder-skeleton.mjs +30 -0
  23. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.cjs +21 -0
  24. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/form-list-skeleton.mjs +19 -0
  25. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.cjs +34 -0
  26. package/dist/packages/better-stack/src/plugins/form-builder/client/components/loading/submissions-skeleton.mjs +32 -0
  27. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.cjs +20 -0
  28. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/404-page.mjs +18 -0
  29. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.cjs +19 -0
  30. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.cjs +186 -0
  31. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.mjs +184 -0
  32. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-builder-page.mjs +17 -0
  33. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.cjs +19 -0
  34. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.cjs +165 -0
  35. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.mjs +163 -0
  36. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/form-list-page.mjs +17 -0
  37. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.cjs +19 -0
  38. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +177 -0
  39. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +175 -0
  40. package/dist/packages/better-stack/src/plugins/form-builder/client/components/pages/submissions-page.mjs +17 -0
  41. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.cjs +17 -0
  42. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/default-error.mjs +15 -0
  43. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.cjs +16 -0
  44. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/empty-state.mjs +14 -0
  45. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.cjs +27 -0
  46. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/page-wrapper.mjs +25 -0
  47. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.cjs +39 -0
  48. package/dist/packages/better-stack/src/plugins/form-builder/client/components/shared/pagination.mjs +37 -0
  49. package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs +551 -0
  50. package/dist/packages/better-stack/src/plugins/form-builder/client/hooks/form-builder-hooks.mjs +537 -0
  51. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.cjs +36 -0
  52. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-common.mjs +34 -0
  53. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.cjs +19 -0
  54. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-editor.mjs +17 -0
  55. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.cjs +21 -0
  56. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-list.mjs +19 -0
  57. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.cjs +19 -0
  58. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-submissions.mjs +17 -0
  59. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.cjs +14 -0
  60. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/form-builder-toasts.mjs +12 -0
  61. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.cjs +17 -0
  62. package/dist/packages/better-stack/src/plugins/form-builder/client/localization/index.mjs +15 -0
  63. package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.cjs +278 -0
  64. package/dist/packages/better-stack/src/plugins/form-builder/client/plugin.mjs +276 -0
  65. package/dist/packages/better-stack/src/plugins/form-builder/db.cjs +99 -0
  66. package/dist/packages/better-stack/src/plugins/form-builder/db.mjs +97 -0
  67. package/dist/packages/better-stack/src/plugins/form-builder/schemas.cjs +82 -0
  68. package/dist/packages/better-stack/src/plugins/form-builder/schemas.mjs +74 -0
  69. package/dist/packages/better-stack/src/plugins/form-builder/utils.cjs +37 -0
  70. package/dist/packages/better-stack/src/plugins/form-builder/utils.mjs +29 -0
  71. package/dist/packages/ui/src/components/auto-form/index.cjs +2 -12
  72. package/dist/packages/ui/src/components/auto-form/index.mjs +2 -9
  73. package/dist/packages/ui/src/components/auto-form/stepped-auto-form.cjs +377 -0
  74. package/dist/packages/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
  75. package/dist/packages/ui/src/components/auto-form/utils.cjs +1 -56
  76. package/dist/packages/ui/src/components/auto-form/utils.mjs +2 -56
  77. package/dist/packages/ui/src/components/form-builder/canvas.cjs +111 -0
  78. package/dist/packages/ui/src/components/form-builder/canvas.mjs +109 -0
  79. package/dist/packages/ui/src/components/form-builder/components/index.cjs +570 -0
  80. package/dist/packages/ui/src/components/form-builder/components/index.mjs +553 -0
  81. package/dist/packages/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
  82. package/dist/packages/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
  83. package/dist/packages/ui/src/components/form-builder/form-preview.cjs +73 -0
  84. package/dist/packages/ui/src/components/form-builder/form-preview.mjs +71 -0
  85. package/dist/packages/ui/src/components/form-builder/index.cjs +353 -0
  86. package/dist/packages/ui/src/components/form-builder/index.mjs +344 -0
  87. package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
  88. package/dist/packages/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
  89. package/dist/packages/ui/src/components/form-builder/palette.cjs +52 -0
  90. package/dist/packages/ui/src/components/form-builder/palette.mjs +49 -0
  91. package/dist/packages/ui/src/components/form-builder/schema-utils.cjs +120 -0
  92. package/dist/packages/ui/src/components/form-builder/schema-utils.mjs +114 -0
  93. package/dist/packages/ui/src/components/form-builder/sortable-field.cjs +151 -0
  94. package/dist/packages/ui/src/components/form-builder/sortable-field.mjs +148 -0
  95. package/dist/packages/ui/src/components/form-builder/step-tabs.cjs +180 -0
  96. package/dist/packages/ui/src/components/form-builder/step-tabs.mjs +178 -0
  97. package/dist/packages/ui/src/components/form-builder/types.cjs +7 -0
  98. package/dist/packages/ui/src/components/form-builder/types.mjs +5 -0
  99. package/dist/packages/ui/src/components/form-builder/validation-schemas.cjs +67 -0
  100. package/dist/packages/ui/src/components/form-builder/validation-schemas.mjs +56 -0
  101. package/dist/packages/ui/src/components/tabs.cjs +70 -0
  102. package/dist/packages/ui/src/components/tabs.mjs +65 -0
  103. package/dist/packages/ui/src/lib/schema-converter.cjs +130 -0
  104. package/dist/packages/ui/src/lib/schema-converter.mjs +124 -0
  105. package/dist/plugins/blog/api/index.d.cts +1 -1
  106. package/dist/plugins/blog/api/index.d.mts +1 -1
  107. package/dist/plugins/blog/api/index.d.ts +1 -1
  108. package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
  109. package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
  110. package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
  111. package/dist/plugins/blog/client/index.d.cts +1 -1
  112. package/dist/plugins/blog/client/index.d.mts +1 -1
  113. package/dist/plugins/blog/client/index.d.ts +1 -1
  114. package/dist/plugins/blog/query-keys.d.cts +2 -2
  115. package/dist/plugins/blog/query-keys.d.mts +2 -2
  116. package/dist/plugins/blog/query-keys.d.ts +2 -2
  117. package/dist/plugins/cms/client/index.cjs +6 -0
  118. package/dist/plugins/cms/client/index.d.cts +6 -113
  119. package/dist/plugins/cms/client/index.d.mts +6 -113
  120. package/dist/plugins/cms/client/index.d.ts +6 -113
  121. package/dist/plugins/cms/client/index.mjs +1 -0
  122. package/dist/plugins/form-builder/api/index.cjs +7 -0
  123. package/dist/plugins/form-builder/api/index.d.cts +141 -0
  124. package/dist/plugins/form-builder/api/index.d.mts +141 -0
  125. package/dist/plugins/form-builder/api/index.d.ts +141 -0
  126. package/dist/plugins/form-builder/api/index.mjs +1 -0
  127. package/dist/plugins/form-builder/client/components/index.cjs +29 -0
  128. package/dist/plugins/form-builder/client/components/index.d.cts +93 -0
  129. package/dist/plugins/form-builder/client/components/index.d.mts +93 -0
  130. package/dist/plugins/form-builder/client/components/index.d.ts +93 -0
  131. package/dist/plugins/form-builder/client/components/index.mjs +18 -0
  132. package/dist/plugins/form-builder/client/hooks/index.cjs +19 -0
  133. package/dist/plugins/form-builder/client/hooks/index.d.cts +154 -0
  134. package/dist/plugins/form-builder/client/hooks/index.d.mts +154 -0
  135. package/dist/plugins/form-builder/client/hooks/index.d.ts +154 -0
  136. package/dist/plugins/form-builder/client/hooks/index.mjs +1 -0
  137. package/dist/plugins/form-builder/client/index.cjs +13 -0
  138. package/dist/plugins/form-builder/client/index.d.cts +381 -0
  139. package/dist/plugins/form-builder/client/index.d.mts +381 -0
  140. package/dist/plugins/form-builder/client/index.d.ts +381 -0
  141. package/dist/plugins/form-builder/client/index.mjs +2 -0
  142. package/dist/plugins/form-builder/client.css +3 -0
  143. package/dist/plugins/form-builder/query-keys.cjs +143 -0
  144. package/dist/plugins/form-builder/query-keys.d.cts +74 -0
  145. package/dist/plugins/form-builder/query-keys.d.mts +74 -0
  146. package/dist/plugins/form-builder/query-keys.d.ts +74 -0
  147. package/dist/plugins/form-builder/query-keys.mjs +141 -0
  148. package/dist/plugins/form-builder/style.css +19 -0
  149. package/dist/shared/stack.AX5nZ6A3.d.cts +86 -0
  150. package/dist/shared/stack.AX5nZ6A3.d.mts +86 -0
  151. package/dist/shared/stack.AX5nZ6A3.d.ts +86 -0
  152. package/dist/shared/stack.BIh2AXaW.d.cts +123 -0
  153. package/dist/shared/stack.BIh2AXaW.d.mts +123 -0
  154. package/dist/shared/stack.BIh2AXaW.d.ts +123 -0
  155. package/dist/shared/stack.DzH_wcvr.d.cts +195 -0
  156. package/dist/shared/stack.DzH_wcvr.d.mts +195 -0
  157. package/dist/shared/stack.DzH_wcvr.d.ts +195 -0
  158. package/package.json +54 -1
  159. package/src/plugins/cms/api/plugin.ts +9 -4
  160. package/src/plugins/cms/client/components/forms/content-form.tsx +23 -25
  161. package/src/plugins/cms/client/index.ts +11 -0
  162. package/src/plugins/form-builder/api/index.ts +1 -0
  163. package/src/plugins/form-builder/api/plugin.ts +776 -0
  164. package/src/plugins/form-builder/client/components/forms/form-renderer.tsx +253 -0
  165. package/src/plugins/form-builder/client/components/index.tsx +24 -0
  166. package/src/plugins/form-builder/client/components/loading/form-builder-skeleton.tsx +42 -0
  167. package/src/plugins/form-builder/client/components/loading/form-list-skeleton.tsx +25 -0
  168. package/src/plugins/form-builder/client/components/loading/index.tsx +3 -0
  169. package/src/plugins/form-builder/client/components/loading/submissions-skeleton.tsx +40 -0
  170. package/src/plugins/form-builder/client/components/pages/404-page.tsx +28 -0
  171. package/src/plugins/form-builder/client/components/pages/form-builder-page.internal.tsx +253 -0
  172. package/src/plugins/form-builder/client/components/pages/form-builder-page.tsx +26 -0
  173. package/src/plugins/form-builder/client/components/pages/form-list-page.internal.tsx +231 -0
  174. package/src/plugins/form-builder/client/components/pages/form-list-page.tsx +22 -0
  175. package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +268 -0
  176. package/src/plugins/form-builder/client/components/pages/submissions-page.tsx +26 -0
  177. package/src/plugins/form-builder/client/components/shared/default-error.tsx +30 -0
  178. package/src/plugins/form-builder/client/components/shared/empty-state.tsx +26 -0
  179. package/src/plugins/form-builder/client/components/shared/page-wrapper.tsx +32 -0
  180. package/src/plugins/form-builder/client/components/shared/pagination.tsx +52 -0
  181. package/src/plugins/form-builder/client/hooks/form-builder-hooks.tsx +799 -0
  182. package/src/plugins/form-builder/client/hooks/index.tsx +1 -0
  183. package/src/plugins/form-builder/client/index.ts +22 -0
  184. package/src/plugins/form-builder/client/localization/form-builder-common.ts +36 -0
  185. package/src/plugins/form-builder/client/localization/form-builder-editor.ts +18 -0
  186. package/src/plugins/form-builder/client/localization/form-builder-list.ts +17 -0
  187. package/src/plugins/form-builder/client/localization/form-builder-submissions.ts +17 -0
  188. package/src/plugins/form-builder/client/localization/form-builder-toasts.ts +10 -0
  189. package/src/plugins/form-builder/client/localization/index.ts +15 -0
  190. package/src/plugins/form-builder/client/overrides.ts +146 -0
  191. package/src/plugins/form-builder/client/plugin.tsx +488 -0
  192. package/src/plugins/form-builder/client.css +3 -0
  193. package/src/plugins/form-builder/db.ts +99 -0
  194. package/src/plugins/form-builder/query-keys.ts +198 -0
  195. package/src/plugins/form-builder/schemas.ts +122 -0
  196. package/src/plugins/form-builder/style.css +19 -0
  197. package/src/plugins/form-builder/types.ts +317 -0
  198. package/src/plugins/form-builder/utils.ts +63 -0
  199. package/dist/shared/{stack.DLhzx1-D.d.cts → stack.CcI4sYJP.d.cts} +1 -1
  200. package/dist/shared/{stack.DLhzx1-D.d.mts → stack.CcI4sYJP.d.mts} +1 -1
  201. package/dist/shared/{stack.DLhzx1-D.d.ts → stack.CcI4sYJP.d.ts} +1 -1
@@ -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, SteppedAutoForm as default };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
- const z = require('zod');
4
+ require('zod');
5
5
 
6
6
  const BUILTIN_FIELD_TYPES = [
7
7
  "checkbox",
@@ -170,60 +170,6 @@ function sortFieldsByOrder(fieldConfig, keys) {
170
170
  });
171
171
  return sortedFields;
172
172
  }
173
- function fromJSONSchemaWithDates(jsonSchema) {
174
- const baseSchema = z.z.fromJSONSchema(jsonSchema);
175
- const properties = jsonSchema.properties;
176
- if (!properties) return baseSchema;
177
- const dateFieldsWithConstraints = {};
178
- for (const [key, prop] of Object.entries(properties)) {
179
- if (prop.type === "string" && prop.format === "date-time") {
180
- if (prop.formatMinimum || prop.formatMaximum) {
181
- dateFieldsWithConstraints[key] = {
182
- min: prop.formatMinimum,
183
- max: prop.formatMaximum
184
- };
185
- }
186
- }
187
- }
188
- if (Object.keys(dateFieldsWithConstraints).length === 0) {
189
- return baseSchema;
190
- }
191
- return baseSchema.superRefine((data, ctx) => {
192
- for (const [key, constraints] of Object.entries(dateFieldsWithConstraints)) {
193
- const value = data[key];
194
- if (value === void 0 || value === null || value === "") continue;
195
- const dateValue = new Date(value);
196
- if (isNaN(dateValue.getTime())) {
197
- ctx.addIssue({
198
- code: z.z.ZodIssueCode.custom,
199
- message: "Invalid date",
200
- path: [key]
201
- });
202
- continue;
203
- }
204
- if (constraints.min) {
205
- const minDate = new Date(constraints.min);
206
- if (dateValue < minDate) {
207
- ctx.addIssue({
208
- code: z.z.ZodIssueCode.custom,
209
- message: `Date must be after ${minDate.toLocaleDateString()}`,
210
- path: [key]
211
- });
212
- }
213
- }
214
- if (constraints.max) {
215
- const maxDate = new Date(constraints.max);
216
- if (dateValue > maxDate) {
217
- ctx.addIssue({
218
- code: z.z.ZodIssueCode.custom,
219
- message: `Date must be before ${maxDate.toLocaleDateString()}`,
220
- path: [key]
221
- });
222
- }
223
- }
224
- }
225
- });
226
- }
227
173
  function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
228
174
  const fieldConfig = {};
229
175
  const properties = jsonSchema.properties;
@@ -296,7 +242,6 @@ function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
296
242
  exports.BUILTIN_FIELD_TYPES = BUILTIN_FIELD_TYPES;
297
243
  exports.beautifyObjectName = beautifyObjectName;
298
244
  exports.buildFieldConfigFromJsonSchema = buildFieldConfigFromJsonSchema;
299
- exports.fromJSONSchemaWithDates = fromJSONSchemaWithDates;
300
245
  exports.getBaseSchema = getBaseSchema;
301
246
  exports.getBaseType = getBaseType;
302
247
  exports.getDefaultValueInZodStack = getDefaultValueInZodStack;
@@ -1,5 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { z } from 'zod';
2
+ import 'zod';
3
3
 
4
4
  const BUILTIN_FIELD_TYPES = [
5
5
  "checkbox",
@@ -168,60 +168,6 @@ function sortFieldsByOrder(fieldConfig, keys) {
168
168
  });
169
169
  return sortedFields;
170
170
  }
171
- function fromJSONSchemaWithDates(jsonSchema) {
172
- const baseSchema = z.fromJSONSchema(jsonSchema);
173
- const properties = jsonSchema.properties;
174
- if (!properties) return baseSchema;
175
- const dateFieldsWithConstraints = {};
176
- for (const [key, prop] of Object.entries(properties)) {
177
- if (prop.type === "string" && prop.format === "date-time") {
178
- if (prop.formatMinimum || prop.formatMaximum) {
179
- dateFieldsWithConstraints[key] = {
180
- min: prop.formatMinimum,
181
- max: prop.formatMaximum
182
- };
183
- }
184
- }
185
- }
186
- if (Object.keys(dateFieldsWithConstraints).length === 0) {
187
- return baseSchema;
188
- }
189
- return baseSchema.superRefine((data, ctx) => {
190
- for (const [key, constraints] of Object.entries(dateFieldsWithConstraints)) {
191
- const value = data[key];
192
- if (value === void 0 || value === null || value === "") continue;
193
- const dateValue = new Date(value);
194
- if (isNaN(dateValue.getTime())) {
195
- ctx.addIssue({
196
- code: z.ZodIssueCode.custom,
197
- message: "Invalid date",
198
- path: [key]
199
- });
200
- continue;
201
- }
202
- if (constraints.min) {
203
- const minDate = new Date(constraints.min);
204
- if (dateValue < minDate) {
205
- ctx.addIssue({
206
- code: z.ZodIssueCode.custom,
207
- message: `Date must be after ${minDate.toLocaleDateString()}`,
208
- path: [key]
209
- });
210
- }
211
- }
212
- if (constraints.max) {
213
- const maxDate = new Date(constraints.max);
214
- if (dateValue > maxDate) {
215
- ctx.addIssue({
216
- code: z.ZodIssueCode.custom,
217
- message: `Date must be before ${maxDate.toLocaleDateString()}`,
218
- path: [key]
219
- });
220
- }
221
- }
222
- }
223
- });
224
- }
225
171
  function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
226
172
  const fieldConfig = {};
227
173
  const properties = jsonSchema.properties;
@@ -291,4 +237,4 @@ function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
291
237
  return fieldConfig;
292
238
  }
293
239
 
294
- export { BUILTIN_FIELD_TYPES, beautifyObjectName, buildFieldConfigFromJsonSchema, fromJSONSchemaWithDates, getBaseSchema, getBaseType, getDefaultValueInZodStack, getDefaultValues, getObjectFormSchema, sortFieldsByOrder, zodToHtmlInputProps };
240
+ export { BUILTIN_FIELD_TYPES, beautifyObjectName, buildFieldConfigFromJsonSchema, getBaseSchema, getBaseType, getDefaultValueInZodStack, getDefaultValues, getObjectFormSchema, sortFieldsByOrder, zodToHtmlInputProps };
@@ -0,0 +1,111 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const React = require('react');
6
+ const core_esm = require('../../../../../node_modules/.pnpm/@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0/node_modules/@dnd-kit/core/dist/core.esm.cjs');
7
+ const sortable_esm = require('../../../../../node_modules/.pnpm/@dnd-kit_sortable@10.0.0_@dnd-kit_core@6.3.1_react-dom@19.2.0_react@19.2.0__react@19.2.0__react@19.2.0/node_modules/@dnd-kit/sortable/dist/sortable.esm.cjs');
8
+ const utils = require('../../lib/utils.cjs');
9
+ const sortableField = require('./sortable-field.cjs');
10
+ const stepTabs = require('./step-tabs.cjs');
11
+
12
+ function DropZone({ id, isDraggingFromPalette }) {
13
+ const { setNodeRef, isOver } = core_esm.useDroppable({
14
+ id
15
+ });
16
+ if (!isDraggingFromPalette) {
17
+ return null;
18
+ }
19
+ return /* @__PURE__ */ jsxRuntime.jsx(
20
+ "div",
21
+ {
22
+ ref: setNodeRef,
23
+ className: utils.cn(
24
+ "h-2 rounded-full transition-all duration-200",
25
+ isOver ? "h-3 bg-primary animate-pulse" : "bg-muted-foreground/20"
26
+ )
27
+ }
28
+ );
29
+ }
30
+ function Canvas({
31
+ fields,
32
+ components,
33
+ onEditField,
34
+ onDeleteField,
35
+ onConfigureNested,
36
+ isDraggingFromPalette,
37
+ className,
38
+ steps,
39
+ activeStepIndex,
40
+ onActiveStepChange,
41
+ onAddStep,
42
+ onDeleteStep,
43
+ onRenameStep,
44
+ hideStepControls
45
+ }) {
46
+ const { setNodeRef, isOver } = core_esm.useDroppable({
47
+ id: "canvas"
48
+ });
49
+ const getComponent = (type) => components.find((c) => c.type === type);
50
+ const visibleFields = React.useMemo(() => {
51
+ if (steps.length <= 1) {
52
+ return fields;
53
+ }
54
+ return fields.filter((f) => (f.stepGroup ?? 0) === activeStepIndex);
55
+ }, [fields, steps.length, activeStepIndex]);
56
+ const sortableItems = React.useMemo(() => visibleFields.map((f) => f.id), [visibleFields]);
57
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils.cn("flex flex-col h-full", className), children: [
58
+ /* @__PURE__ */ jsxRuntime.jsx(
59
+ stepTabs.StepTabs,
60
+ {
61
+ steps,
62
+ activeStepIndex,
63
+ onActiveStepChange,
64
+ onAddStep,
65
+ onDeleteStep,
66
+ onRenameStep,
67
+ hideStepControls
68
+ }
69
+ ),
70
+ /* @__PURE__ */ jsxRuntime.jsx(
71
+ "div",
72
+ {
73
+ ref: setNodeRef,
74
+ "data-testid": "form-builder-canvas",
75
+ className: utils.cn(
76
+ "flex-1 p-4 rounded-lg border-2 border-dashed min-h-[400px] transition-colors",
77
+ isOver && isDraggingFromPalette ? "border-primary bg-primary/5" : "border-muted-foreground/20"
78
+ ),
79
+ children: visibleFields.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center h-full text-muted-foreground", "data-testid": "canvas-drop-zone", children: [
80
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-lg font-medium", children: "Drop components here" }),
81
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm", children: steps.length > 1 ? `Drag components from the palette to add to ${steps[activeStepIndex]?.title || "this step"}` : "Drag components from the palette to build your form" })
82
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
83
+ sortable_esm.SortableContext,
84
+ {
85
+ items: sortableItems,
86
+ strategy: sortable_esm.verticalListSortingStrategy,
87
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
88
+ /* @__PURE__ */ jsxRuntime.jsx(DropZone, { id: "drop-zone-start", isDraggingFromPalette }),
89
+ visibleFields.map((field, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
90
+ /* @__PURE__ */ jsxRuntime.jsx(
91
+ sortableField.SortableField,
92
+ {
93
+ field,
94
+ index,
95
+ component: getComponent(field.type),
96
+ onEdit: () => onEditField(field.id),
97
+ onDelete: () => onDeleteField(field.id),
98
+ onConfigureNested: onConfigureNested ? () => onConfigureNested(field.id) : void 0
99
+ }
100
+ ),
101
+ /* @__PURE__ */ jsxRuntime.jsx(DropZone, { id: `drop-zone-${field.id}`, isDraggingFromPalette })
102
+ ] }, field.id))
103
+ ] })
104
+ }
105
+ )
106
+ }
107
+ )
108
+ ] });
109
+ }
110
+
111
+ exports.Canvas = Canvas;