@btst/plugin-cms 0.0.0-stage → 1.0.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.DQLAoogy.d.ts +1749 -0
  99. package/dist/shared/plugin-cms.W4Le8D91.d.mts +1749 -0
  100. package/dist/shared/plugin-cms.c-GeWvTf.d.cts +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,270 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ require('zod');
5
+
6
+ const BUILTIN_FIELD_TYPES = [
7
+ "checkbox",
8
+ "date",
9
+ "select",
10
+ "radio",
11
+ "switch",
12
+ "textarea",
13
+ "number",
14
+ "fallback"
15
+ ];
16
+ function getDefTypeName(schema) {
17
+ const def = schema._zod?.def;
18
+ return def?.type || "";
19
+ }
20
+ function beautifyObjectName(string) {
21
+ let output = string.replace(/([A-Z])/g, " $1");
22
+ output = output.charAt(0).toUpperCase() + output.slice(1);
23
+ return output;
24
+ }
25
+ function getBaseSchema(schema) {
26
+ if (!schema) return null;
27
+ const def = schema._zod?.def;
28
+ if (!def) return schema;
29
+ if (def.innerType) {
30
+ return getBaseSchema(def.innerType);
31
+ }
32
+ if (def.out) {
33
+ return getBaseSchema(def.out);
34
+ }
35
+ if (def.schema) {
36
+ return getBaseSchema(def.schema);
37
+ }
38
+ return schema;
39
+ }
40
+ function getBaseType(schema) {
41
+ const baseSchema = getBaseSchema(schema);
42
+ if (!baseSchema) return "";
43
+ const typeName = getDefTypeName(baseSchema);
44
+ const typeMap = {
45
+ object: "ZodObject",
46
+ array: "ZodArray",
47
+ string: "ZodString",
48
+ number: "ZodNumber",
49
+ int: "ZodNumber",
50
+ float: "ZodNumber",
51
+ boolean: "ZodBoolean",
52
+ date: "ZodDate",
53
+ enum: "ZodEnum",
54
+ nativeEnum: "ZodNativeEnum",
55
+ literal: "ZodLiteral",
56
+ union: "ZodUnion"
57
+ };
58
+ return typeMap[typeName] || typeName;
59
+ }
60
+ function getDefaultValueInZodStack(schema) {
61
+ const def = schema._zod?.def;
62
+ if (!def) return void 0;
63
+ if (def.type === "default") {
64
+ const defaultValue = def.defaultValue;
65
+ if (typeof defaultValue === "function") {
66
+ return defaultValue();
67
+ }
68
+ return defaultValue;
69
+ }
70
+ if (def.innerType) {
71
+ return getDefaultValueInZodStack(def.innerType);
72
+ }
73
+ if (def.schema) {
74
+ return getDefaultValueInZodStack(def.schema);
75
+ }
76
+ return void 0;
77
+ }
78
+ function getDefaultValues(schema, fieldConfig) {
79
+ if (!schema) return null;
80
+ const { shape } = schema;
81
+ const defaultValues = {};
82
+ if (!shape) return defaultValues;
83
+ for (const key of Object.keys(shape)) {
84
+ const item = shape[key];
85
+ if (getBaseType(item) === "ZodObject") {
86
+ const defaultItems = getDefaultValues(
87
+ getBaseSchema(item),
88
+ fieldConfig?.[key]
89
+ );
90
+ if (defaultItems !== null) {
91
+ for (const defaultItemKey of Object.keys(defaultItems)) {
92
+ const pathKey = `${key}.${defaultItemKey}`;
93
+ defaultValues[pathKey] = defaultItems[defaultItemKey];
94
+ }
95
+ }
96
+ } else {
97
+ let defaultValue = getDefaultValueInZodStack(item);
98
+ if ((defaultValue === void 0 || defaultValue === null || defaultValue === "") && fieldConfig?.[key]?.inputProps) {
99
+ defaultValue = (fieldConfig?.[key]?.inputProps).defaultValue;
100
+ }
101
+ if (defaultValue !== void 0) {
102
+ defaultValues[key] = defaultValue;
103
+ }
104
+ }
105
+ }
106
+ return defaultValues;
107
+ }
108
+ function getObjectFormSchema(schema) {
109
+ if (!schema) return schema;
110
+ const def = schema._zod?.def;
111
+ if (!def) return schema;
112
+ if (def.type === "pipe") {
113
+ return getObjectFormSchema(def.in);
114
+ }
115
+ if (def.innerType) {
116
+ return getObjectFormSchema(def.innerType);
117
+ }
118
+ if (def.schema) {
119
+ return getObjectFormSchema(def.schema);
120
+ }
121
+ return schema;
122
+ }
123
+ function zodToHtmlInputProps(schema) {
124
+ const def = schema._zod?.def;
125
+ const defType = def?.type || "";
126
+ if (["optional", "nullable"].includes(defType)) {
127
+ return {
128
+ ...zodToHtmlInputProps(def.innerType),
129
+ required: false
130
+ };
131
+ }
132
+ if (defType === "default") {
133
+ return {
134
+ ...zodToHtmlInputProps(def.innerType),
135
+ required: false
136
+ };
137
+ }
138
+ const inputProps = {
139
+ required: true
140
+ };
141
+ const checks = def?.checks;
142
+ if (!checks || !Array.isArray(checks)) {
143
+ return inputProps;
144
+ }
145
+ const type = getBaseType(schema);
146
+ for (const check of checks) {
147
+ const checkKind = check.kind || check.type;
148
+ if (checkKind === "min" || checkKind === "min_length") {
149
+ if (type === "ZodString") {
150
+ inputProps.minLength = check.value ?? check.minimum;
151
+ } else {
152
+ inputProps.min = check.value ?? check.minimum;
153
+ }
154
+ }
155
+ if (checkKind === "max" || checkKind === "max_length") {
156
+ if (type === "ZodString") {
157
+ inputProps.maxLength = check.value ?? check.maximum;
158
+ } else {
159
+ inputProps.max = check.value ?? check.maximum;
160
+ }
161
+ }
162
+ }
163
+ return inputProps;
164
+ }
165
+ function sortFieldsByOrder(fieldConfig, keys) {
166
+ const sortedFields = keys.sort((a, b) => {
167
+ const fieldA = fieldConfig?.[a]?.order ?? 0;
168
+ const fieldB = fieldConfig?.[b]?.order ?? 0;
169
+ return fieldA - fieldB;
170
+ });
171
+ return sortedFields;
172
+ }
173
+ function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
174
+ const fieldConfig = {};
175
+ const properties = jsonSchema.properties;
176
+ if (!properties) return fieldConfig;
177
+ for (const [key, value] of Object.entries(properties)) {
178
+ const config = {};
179
+ if (value.label) {
180
+ config.label = value.label;
181
+ } else if (value.title) {
182
+ config.label = value.title;
183
+ }
184
+ if (value.description) {
185
+ config.description = value.description;
186
+ }
187
+ const inputProps = value.inputProps ? { ...value.inputProps } : {};
188
+ if (value.placeholder) {
189
+ inputProps.placeholder = value.placeholder;
190
+ }
191
+ if (value.default !== void 0) {
192
+ inputProps.defaultValue = value.default;
193
+ inputProps.required = false;
194
+ }
195
+ if (Object.keys(inputProps).length > 0) {
196
+ config.inputProps = inputProps;
197
+ }
198
+ if (value.order !== void 0) {
199
+ config.order = value.order;
200
+ }
201
+ let fieldType = value.fieldType;
202
+ if (!fieldType && value.type === "string" && value.format === "date-time") {
203
+ fieldType = "date";
204
+ }
205
+ if (fieldType) {
206
+ const CustomComponent = fieldComponents?.[fieldType];
207
+ if (CustomComponent) {
208
+ config.fieldType = (props) => /* @__PURE__ */ jsxRuntime.jsx(CustomComponent, { ...props });
209
+ } else if (BUILTIN_FIELD_TYPES.includes(
210
+ fieldType
211
+ )) {
212
+ config.fieldType = fieldType;
213
+ }
214
+ }
215
+ const reservedProps = /* @__PURE__ */ new Set([
216
+ "description",
217
+ "label",
218
+ "inputProps",
219
+ "fieldType",
220
+ "renderParent",
221
+ "order"
222
+ ]);
223
+ if (value.properties) {
224
+ const nestedConfig = buildFieldConfigFromJsonSchema(
225
+ { properties: value.properties },
226
+ fieldComponents
227
+ );
228
+ for (const [nestedKey, nestedValue] of Object.entries(nestedConfig)) {
229
+ if (!reservedProps.has(nestedKey)) {
230
+ config[nestedKey] = nestedValue;
231
+ } else {
232
+ console.warn(
233
+ `Field "${key}" has a nested field named "${nestedKey}" which conflicts with a reserved FieldConfigItem property. The nested field's config will not be accessible at the parent level.`
234
+ );
235
+ }
236
+ }
237
+ }
238
+ const items = value.items;
239
+ if (items?.properties) {
240
+ const itemConfig = buildFieldConfigFromJsonSchema(
241
+ { properties: items.properties },
242
+ fieldComponents
243
+ );
244
+ for (const [itemKey, itemValue] of Object.entries(itemConfig)) {
245
+ if (!reservedProps.has(itemKey)) {
246
+ config[itemKey] = itemValue;
247
+ } else {
248
+ console.warn(
249
+ `Array field "${key}" has an item property named "${itemKey}" which conflicts with a reserved FieldConfigItem property. The item field's config will not be accessible inside array items.`
250
+ );
251
+ }
252
+ }
253
+ }
254
+ if (Object.keys(config).length > 0) {
255
+ fieldConfig[key] = config;
256
+ }
257
+ }
258
+ return fieldConfig;
259
+ }
260
+
261
+ exports.BUILTIN_FIELD_TYPES = BUILTIN_FIELD_TYPES;
262
+ exports.beautifyObjectName = beautifyObjectName;
263
+ exports.buildFieldConfigFromJsonSchema = buildFieldConfigFromJsonSchema;
264
+ exports.getBaseSchema = getBaseSchema;
265
+ exports.getBaseType = getBaseType;
266
+ exports.getDefaultValueInZodStack = getDefaultValueInZodStack;
267
+ exports.getDefaultValues = getDefaultValues;
268
+ exports.getObjectFormSchema = getObjectFormSchema;
269
+ exports.sortFieldsByOrder = sortFieldsByOrder;
270
+ exports.zodToHtmlInputProps = zodToHtmlInputProps;
@@ -0,0 +1,259 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import 'zod';
3
+
4
+ const BUILTIN_FIELD_TYPES = [
5
+ "checkbox",
6
+ "date",
7
+ "select",
8
+ "radio",
9
+ "switch",
10
+ "textarea",
11
+ "number",
12
+ "fallback"
13
+ ];
14
+ function getDefTypeName(schema) {
15
+ const def = schema._zod?.def;
16
+ return def?.type || "";
17
+ }
18
+ function beautifyObjectName(string) {
19
+ let output = string.replace(/([A-Z])/g, " $1");
20
+ output = output.charAt(0).toUpperCase() + output.slice(1);
21
+ return output;
22
+ }
23
+ function getBaseSchema(schema) {
24
+ if (!schema) return null;
25
+ const def = schema._zod?.def;
26
+ if (!def) return schema;
27
+ if (def.innerType) {
28
+ return getBaseSchema(def.innerType);
29
+ }
30
+ if (def.out) {
31
+ return getBaseSchema(def.out);
32
+ }
33
+ if (def.schema) {
34
+ return getBaseSchema(def.schema);
35
+ }
36
+ return schema;
37
+ }
38
+ function getBaseType(schema) {
39
+ const baseSchema = getBaseSchema(schema);
40
+ if (!baseSchema) return "";
41
+ const typeName = getDefTypeName(baseSchema);
42
+ const typeMap = {
43
+ object: "ZodObject",
44
+ array: "ZodArray",
45
+ string: "ZodString",
46
+ number: "ZodNumber",
47
+ int: "ZodNumber",
48
+ float: "ZodNumber",
49
+ boolean: "ZodBoolean",
50
+ date: "ZodDate",
51
+ enum: "ZodEnum",
52
+ nativeEnum: "ZodNativeEnum",
53
+ literal: "ZodLiteral",
54
+ union: "ZodUnion"
55
+ };
56
+ return typeMap[typeName] || typeName;
57
+ }
58
+ function getDefaultValueInZodStack(schema) {
59
+ const def = schema._zod?.def;
60
+ if (!def) return void 0;
61
+ if (def.type === "default") {
62
+ const defaultValue = def.defaultValue;
63
+ if (typeof defaultValue === "function") {
64
+ return defaultValue();
65
+ }
66
+ return defaultValue;
67
+ }
68
+ if (def.innerType) {
69
+ return getDefaultValueInZodStack(def.innerType);
70
+ }
71
+ if (def.schema) {
72
+ return getDefaultValueInZodStack(def.schema);
73
+ }
74
+ return void 0;
75
+ }
76
+ function getDefaultValues(schema, fieldConfig) {
77
+ if (!schema) return null;
78
+ const { shape } = schema;
79
+ const defaultValues = {};
80
+ if (!shape) return defaultValues;
81
+ for (const key of Object.keys(shape)) {
82
+ const item = shape[key];
83
+ if (getBaseType(item) === "ZodObject") {
84
+ const defaultItems = getDefaultValues(
85
+ getBaseSchema(item),
86
+ fieldConfig?.[key]
87
+ );
88
+ if (defaultItems !== null) {
89
+ for (const defaultItemKey of Object.keys(defaultItems)) {
90
+ const pathKey = `${key}.${defaultItemKey}`;
91
+ defaultValues[pathKey] = defaultItems[defaultItemKey];
92
+ }
93
+ }
94
+ } else {
95
+ let defaultValue = getDefaultValueInZodStack(item);
96
+ if ((defaultValue === void 0 || defaultValue === null || defaultValue === "") && fieldConfig?.[key]?.inputProps) {
97
+ defaultValue = (fieldConfig?.[key]?.inputProps).defaultValue;
98
+ }
99
+ if (defaultValue !== void 0) {
100
+ defaultValues[key] = defaultValue;
101
+ }
102
+ }
103
+ }
104
+ return defaultValues;
105
+ }
106
+ function getObjectFormSchema(schema) {
107
+ if (!schema) return schema;
108
+ const def = schema._zod?.def;
109
+ if (!def) return schema;
110
+ if (def.type === "pipe") {
111
+ return getObjectFormSchema(def.in);
112
+ }
113
+ if (def.innerType) {
114
+ return getObjectFormSchema(def.innerType);
115
+ }
116
+ if (def.schema) {
117
+ return getObjectFormSchema(def.schema);
118
+ }
119
+ return schema;
120
+ }
121
+ function zodToHtmlInputProps(schema) {
122
+ const def = schema._zod?.def;
123
+ const defType = def?.type || "";
124
+ if (["optional", "nullable"].includes(defType)) {
125
+ return {
126
+ ...zodToHtmlInputProps(def.innerType),
127
+ required: false
128
+ };
129
+ }
130
+ if (defType === "default") {
131
+ return {
132
+ ...zodToHtmlInputProps(def.innerType),
133
+ required: false
134
+ };
135
+ }
136
+ const inputProps = {
137
+ required: true
138
+ };
139
+ const checks = def?.checks;
140
+ if (!checks || !Array.isArray(checks)) {
141
+ return inputProps;
142
+ }
143
+ const type = getBaseType(schema);
144
+ for (const check of checks) {
145
+ const checkKind = check.kind || check.type;
146
+ if (checkKind === "min" || checkKind === "min_length") {
147
+ if (type === "ZodString") {
148
+ inputProps.minLength = check.value ?? check.minimum;
149
+ } else {
150
+ inputProps.min = check.value ?? check.minimum;
151
+ }
152
+ }
153
+ if (checkKind === "max" || checkKind === "max_length") {
154
+ if (type === "ZodString") {
155
+ inputProps.maxLength = check.value ?? check.maximum;
156
+ } else {
157
+ inputProps.max = check.value ?? check.maximum;
158
+ }
159
+ }
160
+ }
161
+ return inputProps;
162
+ }
163
+ function sortFieldsByOrder(fieldConfig, keys) {
164
+ const sortedFields = keys.sort((a, b) => {
165
+ const fieldA = fieldConfig?.[a]?.order ?? 0;
166
+ const fieldB = fieldConfig?.[b]?.order ?? 0;
167
+ return fieldA - fieldB;
168
+ });
169
+ return sortedFields;
170
+ }
171
+ function buildFieldConfigFromJsonSchema(jsonSchema, fieldComponents) {
172
+ const fieldConfig = {};
173
+ const properties = jsonSchema.properties;
174
+ if (!properties) return fieldConfig;
175
+ for (const [key, value] of Object.entries(properties)) {
176
+ const config = {};
177
+ if (value.label) {
178
+ config.label = value.label;
179
+ } else if (value.title) {
180
+ config.label = value.title;
181
+ }
182
+ if (value.description) {
183
+ config.description = value.description;
184
+ }
185
+ const inputProps = value.inputProps ? { ...value.inputProps } : {};
186
+ if (value.placeholder) {
187
+ inputProps.placeholder = value.placeholder;
188
+ }
189
+ if (value.default !== void 0) {
190
+ inputProps.defaultValue = value.default;
191
+ inputProps.required = false;
192
+ }
193
+ if (Object.keys(inputProps).length > 0) {
194
+ config.inputProps = inputProps;
195
+ }
196
+ if (value.order !== void 0) {
197
+ config.order = value.order;
198
+ }
199
+ let fieldType = value.fieldType;
200
+ if (!fieldType && value.type === "string" && value.format === "date-time") {
201
+ fieldType = "date";
202
+ }
203
+ if (fieldType) {
204
+ const CustomComponent = fieldComponents?.[fieldType];
205
+ if (CustomComponent) {
206
+ config.fieldType = (props) => /* @__PURE__ */ jsx(CustomComponent, { ...props });
207
+ } else if (BUILTIN_FIELD_TYPES.includes(
208
+ fieldType
209
+ )) {
210
+ config.fieldType = fieldType;
211
+ }
212
+ }
213
+ const reservedProps = /* @__PURE__ */ new Set([
214
+ "description",
215
+ "label",
216
+ "inputProps",
217
+ "fieldType",
218
+ "renderParent",
219
+ "order"
220
+ ]);
221
+ if (value.properties) {
222
+ const nestedConfig = buildFieldConfigFromJsonSchema(
223
+ { properties: value.properties },
224
+ fieldComponents
225
+ );
226
+ for (const [nestedKey, nestedValue] of Object.entries(nestedConfig)) {
227
+ if (!reservedProps.has(nestedKey)) {
228
+ config[nestedKey] = nestedValue;
229
+ } else {
230
+ console.warn(
231
+ `Field "${key}" has a nested field named "${nestedKey}" which conflicts with a reserved FieldConfigItem property. The nested field's config will not be accessible at the parent level.`
232
+ );
233
+ }
234
+ }
235
+ }
236
+ const items = value.items;
237
+ if (items?.properties) {
238
+ const itemConfig = buildFieldConfigFromJsonSchema(
239
+ { properties: items.properties },
240
+ fieldComponents
241
+ );
242
+ for (const [itemKey, itemValue] of Object.entries(itemConfig)) {
243
+ if (!reservedProps.has(itemKey)) {
244
+ config[itemKey] = itemValue;
245
+ } else {
246
+ console.warn(
247
+ `Array field "${key}" has an item property named "${itemKey}" which conflicts with a reserved FieldConfigItem property. The item field's config will not be accessible inside array items.`
248
+ );
249
+ }
250
+ }
251
+ }
252
+ if (Object.keys(config).length > 0) {
253
+ fieldConfig[key] = config;
254
+ }
255
+ }
256
+ return fieldConfig;
257
+ }
258
+
259
+ export { BUILTIN_FIELD_TYPES, beautifyObjectName, buildFieldConfigFromJsonSchema, getBaseSchema, getBaseType, getDefaultValueInZodStack, getDefaultValues, getObjectFormSchema, sortFieldsByOrder, zodToHtmlInputProps };
@@ -0,0 +1,92 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const form = require('../form.cjs');
6
+ const React = require('react');
7
+ const reactHookForm = require('react-hook-form');
8
+ require('../button.cjs');
9
+ const utils = require('../../lib/utils.cjs');
10
+ const zod = require('@hookform/resolvers/zod');
11
+ const object = require('./fields/object.cjs');
12
+ const helpers = require('./helpers.cjs');
13
+
14
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
15
+
16
+ const React__default = /*#__PURE__*/_interopDefaultCompat(React);
17
+
18
+ function AutoForm({
19
+ formSchema,
20
+ values: valuesProp,
21
+ onValuesChange: onValuesChangeProp,
22
+ onParsedValuesChange,
23
+ onSubmit: onSubmitProp,
24
+ fieldConfig,
25
+ children,
26
+ className,
27
+ dependencies
28
+ }) {
29
+ const objectFormSchema = helpers.getObjectFormSchema(formSchema);
30
+ const defaultValues = helpers.getDefaultValues(objectFormSchema, fieldConfig);
31
+ const form$1 = reactHookForm.useForm({
32
+ // Cast to any to handle Zod v4 type compatibility with @hookform/resolvers
33
+ resolver: zod.zodResolver(formSchema),
34
+ defaultValues: defaultValues ?? void 0,
35
+ values: valuesProp
36
+ });
37
+ const [schemaSubmitError, setSchemaSubmitError] = React.useState(null);
38
+ function onSubmit(values) {
39
+ setSchemaSubmitError(null);
40
+ const parsedValues = formSchema.safeParse(values);
41
+ if (parsedValues.success) {
42
+ onSubmitProp?.(parsedValues.data, form$1);
43
+ } else {
44
+ const message = parsedValues.error.issues.map(
45
+ (issue) => `${issue.path.length ? `${issue.path.join(".")}: ` : ""}${issue.message}`
46
+ ).join(" \xB7 ");
47
+ setSchemaSubmitError(message);
48
+ }
49
+ }
50
+ React__default.useEffect(() => {
51
+ const subscription = form$1.watch((values) => {
52
+ onValuesChangeProp?.(values, form$1);
53
+ const parsedValues = formSchema.safeParse(values);
54
+ if (parsedValues.success) {
55
+ onParsedValuesChange?.(parsedValues.data, form$1);
56
+ }
57
+ });
58
+ return () => subscription.unsubscribe();
59
+ }, [form$1, formSchema, onValuesChangeProp, onParsedValuesChange]);
60
+ const renderChildren = typeof children === "function" ? children(form$1.formState) : children;
61
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(form.Form, { ...form$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
62
+ "form",
63
+ {
64
+ onSubmit: (e) => {
65
+ form$1.handleSubmit(onSubmit, () => setSchemaSubmitError(null))(e);
66
+ },
67
+ className: utils.cn("space-y-5", className),
68
+ children: [
69
+ /* @__PURE__ */ jsxRuntime.jsx(
70
+ object,
71
+ {
72
+ schema: objectFormSchema,
73
+ form: form$1,
74
+ dependencies,
75
+ fieldConfig
76
+ }
77
+ ),
78
+ schemaSubmitError ? /* @__PURE__ */ jsxRuntime.jsx(
79
+ "div",
80
+ {
81
+ role: "alert",
82
+ className: "rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",
83
+ children: schemaSubmitError
84
+ }
85
+ ) : null,
86
+ renderChildren
87
+ ]
88
+ }
89
+ ) }) });
90
+ }
91
+
92
+ module.exports = AutoForm;
@@ -0,0 +1,86 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { Form } from '../form.mjs';
4
+ import React__default, { useState } from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import '../button.mjs';
7
+ import { cn } from '../../lib/utils.mjs';
8
+ import { zodResolver } from '@hookform/resolvers/zod';
9
+ import AutoFormObject from './fields/object.mjs';
10
+ import { getObjectFormSchema, getDefaultValues } from './helpers.mjs';
11
+
12
+ function AutoForm({
13
+ formSchema,
14
+ values: valuesProp,
15
+ onValuesChange: onValuesChangeProp,
16
+ onParsedValuesChange,
17
+ onSubmit: onSubmitProp,
18
+ fieldConfig,
19
+ children,
20
+ className,
21
+ dependencies
22
+ }) {
23
+ const objectFormSchema = getObjectFormSchema(formSchema);
24
+ const defaultValues = getDefaultValues(objectFormSchema, fieldConfig);
25
+ const form = useForm({
26
+ // Cast to any to handle Zod v4 type compatibility with @hookform/resolvers
27
+ resolver: zodResolver(formSchema),
28
+ defaultValues: defaultValues ?? void 0,
29
+ values: valuesProp
30
+ });
31
+ const [schemaSubmitError, setSchemaSubmitError] = useState(null);
32
+ function onSubmit(values) {
33
+ setSchemaSubmitError(null);
34
+ const parsedValues = formSchema.safeParse(values);
35
+ if (parsedValues.success) {
36
+ onSubmitProp?.(parsedValues.data, form);
37
+ } else {
38
+ const message = parsedValues.error.issues.map(
39
+ (issue) => `${issue.path.length ? `${issue.path.join(".")}: ` : ""}${issue.message}`
40
+ ).join(" \xB7 ");
41
+ setSchemaSubmitError(message);
42
+ }
43
+ }
44
+ React__default.useEffect(() => {
45
+ const subscription = form.watch((values) => {
46
+ onValuesChangeProp?.(values, form);
47
+ const parsedValues = formSchema.safeParse(values);
48
+ if (parsedValues.success) {
49
+ onParsedValuesChange?.(parsedValues.data, form);
50
+ }
51
+ });
52
+ return () => subscription.unsubscribe();
53
+ }, [form, formSchema, onValuesChangeProp, onParsedValuesChange]);
54
+ const renderChildren = typeof children === "function" ? children(form.formState) : children;
55
+ return /* @__PURE__ */ jsx("div", { className: "w-full", children: /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
56
+ "form",
57
+ {
58
+ onSubmit: (e) => {
59
+ form.handleSubmit(onSubmit, () => setSchemaSubmitError(null))(e);
60
+ },
61
+ className: cn("space-y-5", className),
62
+ children: [
63
+ /* @__PURE__ */ jsx(
64
+ AutoFormObject,
65
+ {
66
+ schema: objectFormSchema,
67
+ form,
68
+ dependencies,
69
+ fieldConfig
70
+ }
71
+ ),
72
+ schemaSubmitError ? /* @__PURE__ */ jsx(
73
+ "div",
74
+ {
75
+ role: "alert",
76
+ className: "rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",
77
+ children: schemaSubmitError
78
+ }
79
+ ) : null,
80
+ renderChildren
81
+ ]
82
+ }
83
+ ) }) });
84
+ }
85
+
86
+ export { AutoForm as default };