@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,266 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const accordion = require('../../accordion.cjs');
5
+ const button = require('../../button.cjs');
6
+ const form = require('../../form.cjs');
7
+ const input = require('../../input.cjs');
8
+ const separator = require('../../separator.cjs');
9
+ const lucideReact = require('lucide-react');
10
+ const reactHookForm = require('react-hook-form');
11
+ const helpers = require('../helpers.cjs');
12
+ const object = require('./object.cjs');
13
+
14
+ function getDefType(schema) {
15
+ return schema._zod?.def?.type || "";
16
+ }
17
+ function getArrayElementType(item) {
18
+ const def = item._zod?.def;
19
+ const defType = getDefType(item);
20
+ if (defType === "array") {
21
+ return def?.element || null;
22
+ }
23
+ if (["default", "optional", "nullable"].includes(defType)) {
24
+ const innerType = def?.innerType;
25
+ if (innerType) {
26
+ return getArrayElementType(innerType);
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+ function getPrimitiveDefault(itemSchema) {
32
+ const base = helpers.getBaseSchema(itemSchema);
33
+ if (!base) return "";
34
+ switch (helpers.getBaseType(base)) {
35
+ case "ZodBoolean":
36
+ return false;
37
+ case "ZodNumber":
38
+ return 0;
39
+ default:
40
+ return "";
41
+ }
42
+ }
43
+ function AutoFormArray({
44
+ name,
45
+ item,
46
+ form,
47
+ path = [],
48
+ fieldConfig
49
+ }) {
50
+ const itemDefType = getArrayElementType(item);
51
+ const elementBaseSchema = itemDefType ? helpers.getBaseSchema(itemDefType) : null;
52
+ const elementPrimitiveType = elementBaseSchema ? helpers.getBaseType(elementBaseSchema) : "";
53
+ const isObjectArray = !!itemDefType && elementPrimitiveType === "ZodObject";
54
+ const title = fieldConfig?.label ?? helpers.beautifyObjectName(name);
55
+ if (isObjectArray) {
56
+ return /* @__PURE__ */ jsxRuntime.jsx(
57
+ ObjectAutoFormArray,
58
+ {
59
+ name,
60
+ item,
61
+ form,
62
+ path,
63
+ fieldConfig,
64
+ itemDefType,
65
+ title
66
+ }
67
+ );
68
+ }
69
+ return /* @__PURE__ */ jsxRuntime.jsx(
70
+ PrimitiveAutoFormArray,
71
+ {
72
+ name,
73
+ item,
74
+ form,
75
+ path,
76
+ fieldConfig,
77
+ itemDefType,
78
+ title
79
+ }
80
+ );
81
+ }
82
+ function ObjectAutoFormArray({
83
+ name,
84
+ form,
85
+ path = [],
86
+ fieldConfig,
87
+ itemDefType,
88
+ title
89
+ }) {
90
+ const fieldPath = path.join(".");
91
+ const { fields, append, remove } = reactHookForm.useFieldArray({
92
+ control: form.control,
93
+ name: fieldPath
94
+ });
95
+ return /* @__PURE__ */ jsxRuntime.jsxs(accordion.AccordionItem, { value: name, className: "border-none", children: [
96
+ /* @__PURE__ */ jsxRuntime.jsx(accordion.AccordionTrigger, { children: title }),
97
+ /* @__PURE__ */ jsxRuntime.jsxs(accordion.AccordionContent, { children: [
98
+ fields.map((_field, index) => {
99
+ const key = _field.id;
100
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 flex flex-col", children: [
101
+ /* @__PURE__ */ jsxRuntime.jsx(
102
+ object,
103
+ {
104
+ schema: itemDefType,
105
+ form,
106
+ fieldConfig,
107
+ path: [...path, index.toString()]
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-4 flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
111
+ button.Button,
112
+ {
113
+ variant: "secondary",
114
+ size: "icon",
115
+ type: "button",
116
+ className: "hover:bg-zinc-300 hover:text-black focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-white dark:text-black dark:hover:bg-zinc-300 dark:hover:text-black dark:hover:ring-0 dark:hover:ring-offset-0 dark:focus-visible:ring-0 dark:focus-visible:ring-offset-0",
117
+ onClick: () => remove(index),
118
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash, { className: "size-4" })
119
+ }
120
+ ) }),
121
+ /* @__PURE__ */ jsxRuntime.jsx(separator.Separator, {})
122
+ ] }, key);
123
+ }),
124
+ /* @__PURE__ */ jsxRuntime.jsxs(
125
+ button.Button,
126
+ {
127
+ type: "button",
128
+ variant: "secondary",
129
+ onClick: () => append({}),
130
+ className: "mt-4 flex items-center",
131
+ children: [
132
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "mr-2", size: 16 }),
133
+ "Add"
134
+ ]
135
+ }
136
+ )
137
+ ] })
138
+ ] });
139
+ }
140
+ function PrimitiveAutoFormArray({
141
+ name,
142
+ item,
143
+ form,
144
+ path = [],
145
+ fieldConfig,
146
+ itemDefType,
147
+ title
148
+ }) {
149
+ const fieldPath = path.join(".");
150
+ const rawValues = reactHookForm.useWatch({ control: form.control, name: fieldPath }) ?? [];
151
+ const values = Array.isArray(rawValues) ? rawValues : [];
152
+ const appendItem = () => {
153
+ const def = itemDefType ? getPrimitiveDefault(itemDefType) : "";
154
+ form.setValue(fieldPath, [...values, def], {
155
+ shouldDirty: true,
156
+ shouldValidate: false
157
+ });
158
+ };
159
+ const removeItem = (index) => {
160
+ const next = values.filter((_, i) => i !== index);
161
+ form.setValue(fieldPath, next, {
162
+ shouldDirty: true,
163
+ shouldValidate: false
164
+ });
165
+ };
166
+ return /* @__PURE__ */ jsxRuntime.jsxs(accordion.AccordionItem, { value: name, className: "border-none", children: [
167
+ /* @__PURE__ */ jsxRuntime.jsx(accordion.AccordionTrigger, { children: title }),
168
+ /* @__PURE__ */ jsxRuntime.jsxs(accordion.AccordionContent, { children: [
169
+ values.map((_, index) => {
170
+ const cellPath = `${fieldPath}.${index}`;
171
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 flex flex-col", children: [
172
+ itemDefType ? /* @__PURE__ */ jsxRuntime.jsx(
173
+ PrimitiveArrayRow,
174
+ {
175
+ form,
176
+ itemSchema: itemDefType,
177
+ cellPath
178
+ }
179
+ ) : null,
180
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-4 flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
181
+ button.Button,
182
+ {
183
+ variant: "secondary",
184
+ size: "icon",
185
+ type: "button",
186
+ className: "hover:bg-zinc-300 hover:text-black focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-white dark:text-black dark:hover:bg-zinc-300 dark:hover:text-black dark:hover:ring-0 dark:hover:ring-offset-0 dark:focus-visible:ring-0 dark:focus-visible:ring-offset-0",
187
+ onClick: () => removeItem(index),
188
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash, { className: "size-4" })
189
+ }
190
+ ) }),
191
+ /* @__PURE__ */ jsxRuntime.jsx(separator.Separator, {})
192
+ ] }, `${fieldPath}-${index}`);
193
+ }),
194
+ /* @__PURE__ */ jsxRuntime.jsxs(
195
+ button.Button,
196
+ {
197
+ type: "button",
198
+ variant: "secondary",
199
+ onClick: appendItem,
200
+ className: "mt-4 flex items-center",
201
+ children: [
202
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "mr-2", size: 16 }),
203
+ "Add"
204
+ ]
205
+ }
206
+ )
207
+ ] })
208
+ ] });
209
+ }
210
+ function PrimitiveArrayRow({
211
+ form: form$1,
212
+ itemSchema,
213
+ cellPath
214
+ }) {
215
+ const baseSchema = helpers.getBaseSchema(itemSchema);
216
+ const t = baseSchema ? helpers.getBaseType(baseSchema) : "";
217
+ if (t === "ZodBoolean") {
218
+ return /* @__PURE__ */ jsxRuntime.jsx(
219
+ form.FormField,
220
+ {
221
+ control: form$1.control,
222
+ name: cellPath,
223
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { className: "flex flex-row items-center gap-2 space-y-0", children: [
224
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
225
+ "input",
226
+ {
227
+ type: "checkbox",
228
+ "aria-label": "Toggle",
229
+ checked: Boolean(field.value),
230
+ onChange: (e) => field.onChange(e.target.checked)
231
+ }
232
+ ) }),
233
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormLabel, { className: "font-normal cursor-pointer", children: field.value ? "Selected" : "Not selected" }),
234
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
235
+ ] })
236
+ }
237
+ );
238
+ }
239
+ const inputType = t === "ZodNumber" ? "number" : "text";
240
+ return /* @__PURE__ */ jsxRuntime.jsx(
241
+ form.FormField,
242
+ {
243
+ control: form$1.control,
244
+ name: cellPath,
245
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { className: "space-y-2", children: [
246
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormLabel, { className: "sr-only", children: "Row value" }),
247
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
248
+ input.Input,
249
+ {
250
+ type: inputType,
251
+ name: field.name,
252
+ ref: field.ref,
253
+ onBlur: field.onBlur,
254
+ value: field.value === void 0 || field.value === null ? "" : String(field.value),
255
+ onChange: (ev) => field.onChange(
256
+ inputType === "number" ? Number.isNaN(ev.target.valueAsNumber) ? void 0 : ev.target.valueAsNumber : ev.target.value
257
+ )
258
+ }
259
+ ) }),
260
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
261
+ ] })
262
+ }
263
+ );
264
+ }
265
+
266
+ module.exports = AutoFormArray;
@@ -0,0 +1,264 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { AccordionItem, AccordionTrigger, AccordionContent } from '../../accordion.mjs';
3
+ import { Button } from '../../button.mjs';
4
+ import { FormField, FormItem, FormControl, FormLabel, FormMessage } from '../../form.mjs';
5
+ import { Input } from '../../input.mjs';
6
+ import { Separator } from '../../separator.mjs';
7
+ import { Trash, Plus } from 'lucide-react';
8
+ import { useFieldArray, useWatch } from 'react-hook-form';
9
+ import { getBaseSchema, getBaseType, beautifyObjectName } from '../helpers.mjs';
10
+ import AutoFormObject from './object.mjs';
11
+
12
+ function getDefType(schema) {
13
+ return schema._zod?.def?.type || "";
14
+ }
15
+ function getArrayElementType(item) {
16
+ const def = item._zod?.def;
17
+ const defType = getDefType(item);
18
+ if (defType === "array") {
19
+ return def?.element || null;
20
+ }
21
+ if (["default", "optional", "nullable"].includes(defType)) {
22
+ const innerType = def?.innerType;
23
+ if (innerType) {
24
+ return getArrayElementType(innerType);
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ function getPrimitiveDefault(itemSchema) {
30
+ const base = getBaseSchema(itemSchema);
31
+ if (!base) return "";
32
+ switch (getBaseType(base)) {
33
+ case "ZodBoolean":
34
+ return false;
35
+ case "ZodNumber":
36
+ return 0;
37
+ default:
38
+ return "";
39
+ }
40
+ }
41
+ function AutoFormArray({
42
+ name,
43
+ item,
44
+ form,
45
+ path = [],
46
+ fieldConfig
47
+ }) {
48
+ const itemDefType = getArrayElementType(item);
49
+ const elementBaseSchema = itemDefType ? getBaseSchema(itemDefType) : null;
50
+ const elementPrimitiveType = elementBaseSchema ? getBaseType(elementBaseSchema) : "";
51
+ const isObjectArray = !!itemDefType && elementPrimitiveType === "ZodObject";
52
+ const title = fieldConfig?.label ?? beautifyObjectName(name);
53
+ if (isObjectArray) {
54
+ return /* @__PURE__ */ jsx(
55
+ ObjectAutoFormArray,
56
+ {
57
+ name,
58
+ item,
59
+ form,
60
+ path,
61
+ fieldConfig,
62
+ itemDefType,
63
+ title
64
+ }
65
+ );
66
+ }
67
+ return /* @__PURE__ */ jsx(
68
+ PrimitiveAutoFormArray,
69
+ {
70
+ name,
71
+ item,
72
+ form,
73
+ path,
74
+ fieldConfig,
75
+ itemDefType,
76
+ title
77
+ }
78
+ );
79
+ }
80
+ function ObjectAutoFormArray({
81
+ name,
82
+ form,
83
+ path = [],
84
+ fieldConfig,
85
+ itemDefType,
86
+ title
87
+ }) {
88
+ const fieldPath = path.join(".");
89
+ const { fields, append, remove } = useFieldArray({
90
+ control: form.control,
91
+ name: fieldPath
92
+ });
93
+ return /* @__PURE__ */ jsxs(AccordionItem, { value: name, className: "border-none", children: [
94
+ /* @__PURE__ */ jsx(AccordionTrigger, { children: title }),
95
+ /* @__PURE__ */ jsxs(AccordionContent, { children: [
96
+ fields.map((_field, index) => {
97
+ const key = _field.id;
98
+ return /* @__PURE__ */ jsxs("div", { className: "mt-4 flex flex-col", children: [
99
+ /* @__PURE__ */ jsx(
100
+ AutoFormObject,
101
+ {
102
+ schema: itemDefType,
103
+ form,
104
+ fieldConfig,
105
+ path: [...path, index.toString()]
106
+ }
107
+ ),
108
+ /* @__PURE__ */ jsx("div", { className: "my-4 flex justify-end", children: /* @__PURE__ */ jsx(
109
+ Button,
110
+ {
111
+ variant: "secondary",
112
+ size: "icon",
113
+ type: "button",
114
+ className: "hover:bg-zinc-300 hover:text-black focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-white dark:text-black dark:hover:bg-zinc-300 dark:hover:text-black dark:hover:ring-0 dark:hover:ring-offset-0 dark:focus-visible:ring-0 dark:focus-visible:ring-offset-0",
115
+ onClick: () => remove(index),
116
+ children: /* @__PURE__ */ jsx(Trash, { className: "size-4" })
117
+ }
118
+ ) }),
119
+ /* @__PURE__ */ jsx(Separator, {})
120
+ ] }, key);
121
+ }),
122
+ /* @__PURE__ */ jsxs(
123
+ Button,
124
+ {
125
+ type: "button",
126
+ variant: "secondary",
127
+ onClick: () => append({}),
128
+ className: "mt-4 flex items-center",
129
+ children: [
130
+ /* @__PURE__ */ jsx(Plus, { className: "mr-2", size: 16 }),
131
+ "Add"
132
+ ]
133
+ }
134
+ )
135
+ ] })
136
+ ] });
137
+ }
138
+ function PrimitiveAutoFormArray({
139
+ name,
140
+ item,
141
+ form,
142
+ path = [],
143
+ fieldConfig,
144
+ itemDefType,
145
+ title
146
+ }) {
147
+ const fieldPath = path.join(".");
148
+ const rawValues = useWatch({ control: form.control, name: fieldPath }) ?? [];
149
+ const values = Array.isArray(rawValues) ? rawValues : [];
150
+ const appendItem = () => {
151
+ const def = itemDefType ? getPrimitiveDefault(itemDefType) : "";
152
+ form.setValue(fieldPath, [...values, def], {
153
+ shouldDirty: true,
154
+ shouldValidate: false
155
+ });
156
+ };
157
+ const removeItem = (index) => {
158
+ const next = values.filter((_, i) => i !== index);
159
+ form.setValue(fieldPath, next, {
160
+ shouldDirty: true,
161
+ shouldValidate: false
162
+ });
163
+ };
164
+ return /* @__PURE__ */ jsxs(AccordionItem, { value: name, className: "border-none", children: [
165
+ /* @__PURE__ */ jsx(AccordionTrigger, { children: title }),
166
+ /* @__PURE__ */ jsxs(AccordionContent, { children: [
167
+ values.map((_, index) => {
168
+ const cellPath = `${fieldPath}.${index}`;
169
+ return /* @__PURE__ */ jsxs("div", { className: "mt-4 flex flex-col", children: [
170
+ itemDefType ? /* @__PURE__ */ jsx(
171
+ PrimitiveArrayRow,
172
+ {
173
+ form,
174
+ itemSchema: itemDefType,
175
+ cellPath
176
+ }
177
+ ) : null,
178
+ /* @__PURE__ */ jsx("div", { className: "my-4 flex justify-end", children: /* @__PURE__ */ jsx(
179
+ Button,
180
+ {
181
+ variant: "secondary",
182
+ size: "icon",
183
+ type: "button",
184
+ className: "hover:bg-zinc-300 hover:text-black focus:ring-0 focus:ring-offset-0 focus-visible:ring-0 focus-visible:ring-offset-0 dark:bg-white dark:text-black dark:hover:bg-zinc-300 dark:hover:text-black dark:hover:ring-0 dark:hover:ring-offset-0 dark:focus-visible:ring-0 dark:focus-visible:ring-offset-0",
185
+ onClick: () => removeItem(index),
186
+ children: /* @__PURE__ */ jsx(Trash, { className: "size-4" })
187
+ }
188
+ ) }),
189
+ /* @__PURE__ */ jsx(Separator, {})
190
+ ] }, `${fieldPath}-${index}`);
191
+ }),
192
+ /* @__PURE__ */ jsxs(
193
+ Button,
194
+ {
195
+ type: "button",
196
+ variant: "secondary",
197
+ onClick: appendItem,
198
+ className: "mt-4 flex items-center",
199
+ children: [
200
+ /* @__PURE__ */ jsx(Plus, { className: "mr-2", size: 16 }),
201
+ "Add"
202
+ ]
203
+ }
204
+ )
205
+ ] })
206
+ ] });
207
+ }
208
+ function PrimitiveArrayRow({
209
+ form,
210
+ itemSchema,
211
+ cellPath
212
+ }) {
213
+ const baseSchema = getBaseSchema(itemSchema);
214
+ const t = baseSchema ? getBaseType(baseSchema) : "";
215
+ if (t === "ZodBoolean") {
216
+ return /* @__PURE__ */ jsx(
217
+ FormField,
218
+ {
219
+ control: form.control,
220
+ name: cellPath,
221
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "flex flex-row items-center gap-2 space-y-0", children: [
222
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
223
+ "input",
224
+ {
225
+ type: "checkbox",
226
+ "aria-label": "Toggle",
227
+ checked: Boolean(field.value),
228
+ onChange: (e) => field.onChange(e.target.checked)
229
+ }
230
+ ) }),
231
+ /* @__PURE__ */ jsx(FormLabel, { className: "font-normal cursor-pointer", children: field.value ? "Selected" : "Not selected" }),
232
+ /* @__PURE__ */ jsx(FormMessage, {})
233
+ ] })
234
+ }
235
+ );
236
+ }
237
+ const inputType = t === "ZodNumber" ? "number" : "text";
238
+ return /* @__PURE__ */ jsx(
239
+ FormField,
240
+ {
241
+ control: form.control,
242
+ name: cellPath,
243
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "space-y-2", children: [
244
+ /* @__PURE__ */ jsx(FormLabel, { className: "sr-only", children: "Row value" }),
245
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
246
+ Input,
247
+ {
248
+ type: inputType,
249
+ name: field.name,
250
+ ref: field.ref,
251
+ onBlur: field.onBlur,
252
+ value: field.value === void 0 || field.value === null ? "" : String(field.value),
253
+ onChange: (ev) => field.onChange(
254
+ inputType === "number" ? Number.isNaN(ev.target.valueAsNumber) ? void 0 : ev.target.valueAsNumber : ev.target.value
255
+ )
256
+ }
257
+ ) }),
258
+ /* @__PURE__ */ jsx(FormMessage, {})
259
+ ] })
260
+ }
261
+ );
262
+ }
263
+
264
+ export { AutoFormArray as default };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const checkbox = require('../../checkbox.cjs');
5
+ const form = require('../../form.cjs');
6
+ const tooltip = require('../common/tooltip.cjs');
7
+ const label = require('../common/label.cjs');
8
+
9
+ function AutoFormCheckbox({
10
+ label: label$1,
11
+ isRequired,
12
+ field,
13
+ fieldConfigItem,
14
+ fieldProps
15
+ }) {
16
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
17
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormItem, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-3 flex items-center gap-3", children: [
18
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
19
+ checkbox.Checkbox,
20
+ {
21
+ checked: field.value,
22
+ onCheckedChange: field.onChange,
23
+ ...fieldProps
24
+ }
25
+ ) }),
26
+ /* @__PURE__ */ jsxRuntime.jsx(
27
+ label,
28
+ {
29
+ label: fieldConfigItem?.label || label$1,
30
+ isRequired
31
+ }
32
+ )
33
+ ] }) }),
34
+ /* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem })
35
+ ] });
36
+ }
37
+
38
+ module.exports = AutoFormCheckbox;
@@ -0,0 +1,36 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { Checkbox } from '../../checkbox.mjs';
3
+ import { FormItem, FormControl } from '../../form.mjs';
4
+ import AutoFormTooltip from '../common/tooltip.mjs';
5
+ import AutoFormLabel from '../common/label.mjs';
6
+
7
+ function AutoFormCheckbox({
8
+ label,
9
+ isRequired,
10
+ field,
11
+ fieldConfigItem,
12
+ fieldProps
13
+ }) {
14
+ return /* @__PURE__ */ jsxs("div", { children: [
15
+ /* @__PURE__ */ jsx(FormItem, { children: /* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center gap-3", children: [
16
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
17
+ Checkbox,
18
+ {
19
+ checked: field.value,
20
+ onCheckedChange: field.onChange,
21
+ ...fieldProps
22
+ }
23
+ ) }),
24
+ /* @__PURE__ */ jsx(
25
+ AutoFormLabel,
26
+ {
27
+ label: fieldConfigItem?.label || label,
28
+ isRequired
29
+ }
30
+ )
31
+ ] }) }),
32
+ /* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem })
33
+ ] });
34
+ }
35
+
36
+ export { AutoFormCheckbox as default };
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const datePicker = require('../../date-picker.cjs');
5
+ const form = require('../../form.cjs');
6
+ const z = require('zod');
7
+ const label = require('../common/label.cjs');
8
+ const tooltip = require('../common/tooltip.cjs');
9
+ const helpers = require('../helpers.cjs');
10
+
11
+ function toDate(value, dateOnly) {
12
+ if (!value) return void 0;
13
+ if (value instanceof Date) return value;
14
+ if (typeof value === "string") {
15
+ const date = new Date(dateOnly && /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T00:00:00` : value);
16
+ return isNaN(date.getTime()) ? void 0 : date;
17
+ }
18
+ return void 0;
19
+ }
20
+ function AutoFormDate({
21
+ label: label$1,
22
+ isRequired,
23
+ field,
24
+ fieldConfigItem,
25
+ fieldProps,
26
+ zodItem
27
+ }) {
28
+ const baseType = helpers.getBaseType(zodItem);
29
+ const expectsDateObject = baseType === "ZodDate";
30
+ const baseSchema = helpers.getBaseSchema(zodItem);
31
+ const dateSchema = baseSchema instanceof z.z.ZodUnion && baseSchema.options.length === 2 && baseSchema.options.some((option) => option instanceof z.z.ZodNull) ? baseSchema.options.find((option) => !(option instanceof z.z.ZodNull)) : baseSchema;
32
+ const expectsDateOnly = !!dateSchema && ("format" in dateSchema && dateSchema.format === "date" || dateSchema instanceof z.z.ZodString && !!dateSchema._zod.def.checks?.some((check) => "format" in check._zod.def && check._zod.def.format === "date"));
33
+ const handleChange = (date) => {
34
+ if (!date) {
35
+ field.onChange(expectsDateOnly && zodItem.isNullable() ? null : void 0);
36
+ return;
37
+ }
38
+ if (expectsDateObject) {
39
+ field.onChange(date);
40
+ } else if (expectsDateOnly) {
41
+ field.onChange(`${String(date.getFullYear()).padStart(4, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`);
42
+ } else {
43
+ field.onChange(date.toISOString());
44
+ }
45
+ };
46
+ return /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { children: [
47
+ /* @__PURE__ */ jsxRuntime.jsx(
48
+ label,
49
+ {
50
+ label: fieldConfigItem?.label || label$1,
51
+ isRequired
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
55
+ datePicker.DatePicker,
56
+ {
57
+ date: toDate(field.value, expectsDateOnly),
58
+ setDate: handleChange,
59
+ ...fieldProps
60
+ }
61
+ ) }),
62
+ /* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem }),
63
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
64
+ ] });
65
+ }
66
+
67
+ module.exports = AutoFormDate;