@btst/components 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 (161) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/_private/ui/styles/markdown-editor.css +31 -0
  3. package/dist/auto-form/index.cjs +8 -0
  4. package/dist/auto-form/index.d.cts +26 -0
  5. package/dist/auto-form/index.d.mts +26 -0
  6. package/dist/auto-form/index.d.ts +26 -0
  7. package/dist/auto-form/index.mjs +1 -0
  8. package/dist/empty/index.cjs +12 -0
  9. package/dist/empty/index.d.cts +15 -0
  10. package/dist/empty/index.d.mts +15 -0
  11. package/dist/empty/index.d.ts +15 -0
  12. package/dist/empty/index.mjs +1 -0
  13. package/dist/form-builder/index.cjs +16 -0
  14. package/dist/form-builder/index.d.cts +395 -0
  15. package/dist/form-builder/index.d.mts +395 -0
  16. package/dist/form-builder/index.d.ts +395 -0
  17. package/dist/form-builder/index.mjs +4 -0
  18. package/dist/markdown/index.cjs +9 -0
  19. package/dist/markdown/index.d.cts +46 -0
  20. package/dist/markdown/index.d.mts +46 -0
  21. package/dist/markdown/index.d.ts +46 -0
  22. package/dist/markdown/index.mjs +2 -0
  23. package/dist/multi-select/index.cjs +7 -0
  24. package/dist/multi-select/index.d.cts +78 -0
  25. package/dist/multi-select/index.d.mts +78 -0
  26. package/dist/multi-select/index.d.ts +78 -0
  27. package/dist/multi-select/index.mjs +1 -0
  28. package/dist/search-select/index.cjs +7 -0
  29. package/dist/search-select/index.d.cts +16 -0
  30. package/dist/search-select/index.d.mts +16 -0
  31. package/dist/search-select/index.d.ts +16 -0
  32. package/dist/search-select/index.mjs +1 -0
  33. package/dist/shared/components.BdvBiegH.d.cts +291 -0
  34. package/dist/shared/components.BdvBiegH.d.mts +291 -0
  35. package/dist/shared/components.BdvBiegH.d.ts +291 -0
  36. package/dist/shared/components.CZMWR72v.d.cts +10 -0
  37. package/dist/shared/components.CZMWR72v.d.mts +10 -0
  38. package/dist/shared/components.CZMWR72v.d.ts +10 -0
  39. package/dist/stepped-auto-form/index.cjs +7 -0
  40. package/dist/stepped-auto-form/index.d.cts +37 -0
  41. package/dist/stepped-auto-form/index.d.mts +37 -0
  42. package/dist/stepped-auto-form/index.d.ts +37 -0
  43. package/dist/stepped-auto-form/index.mjs +1 -0
  44. package/dist/style.css +440 -0
  45. package/dist/ui/src/components/accordion.cjs +81 -0
  46. package/dist/ui/src/components/accordion.mjs +62 -0
  47. package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
  48. package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
  49. package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
  50. package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
  51. package/dist/ui/src/components/auto-form/config.cjs +40 -0
  52. package/dist/ui/src/components/auto-form/config.mjs +37 -0
  53. package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
  54. package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
  55. package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
  56. package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
  57. package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
  58. package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
  59. package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
  60. package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
  61. package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
  62. package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
  63. package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
  64. package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
  65. package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
  66. package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
  67. package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
  68. package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
  69. package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
  70. package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
  71. package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
  72. package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
  73. package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
  74. package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
  75. package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
  76. package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
  77. package/dist/ui/src/components/auto-form/index.cjs +102 -0
  78. package/dist/ui/src/components/auto-form/index.mjs +93 -0
  79. package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
  80. package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
  81. package/dist/ui/src/components/auto-form/types.cjs +11 -0
  82. package/dist/ui/src/components/auto-form/types.mjs +9 -0
  83. package/dist/ui/src/components/badge.cjs +42 -0
  84. package/dist/ui/src/components/badge.mjs +39 -0
  85. package/dist/ui/src/components/button.cjs +56 -0
  86. package/dist/ui/src/components/button.mjs +53 -0
  87. package/dist/ui/src/components/calendar.cjs +207 -0
  88. package/dist/ui/src/components/calendar.mjs +190 -0
  89. package/dist/ui/src/components/checkbox.cjs +48 -0
  90. package/dist/ui/src/components/checkbox.mjs +32 -0
  91. package/dist/ui/src/components/command.cjs +118 -0
  92. package/dist/ui/src/components/command.mjs +111 -0
  93. package/dist/ui/src/components/date-picker.cjs +41 -0
  94. package/dist/ui/src/components/date-picker.mjs +39 -0
  95. package/dist/ui/src/components/dialog.cjs +141 -0
  96. package/dist/ui/src/components/dialog.mjs +118 -0
  97. package/dist/ui/src/components/empty.cjs +104 -0
  98. package/dist/ui/src/components/empty.mjs +97 -0
  99. package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
  100. package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
  101. package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
  102. package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
  103. package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
  104. package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
  105. package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
  106. package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
  107. package/dist/ui/src/components/form-builder/index.cjs +350 -0
  108. package/dist/ui/src/components/form-builder/index.mjs +344 -0
  109. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
  110. package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
  111. package/dist/ui/src/components/form-builder/palette.cjs +52 -0
  112. package/dist/ui/src/components/form-builder/palette.mjs +49 -0
  113. package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
  114. package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
  115. package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
  116. package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
  117. package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
  118. package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
  119. package/dist/ui/src/components/form-builder/types.cjs +7 -0
  120. package/dist/ui/src/components/form-builder/types.mjs +5 -0
  121. package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
  122. package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
  123. package/dist/ui/src/components/form.cjs +120 -0
  124. package/dist/ui/src/components/form.mjs +98 -0
  125. package/dist/ui/src/components/input.cjs +23 -0
  126. package/dist/ui/src/components/input.mjs +21 -0
  127. package/dist/ui/src/components/label.cjs +39 -0
  128. package/dist/ui/src/components/label.mjs +23 -0
  129. package/dist/ui/src/components/markdown-content.cjs +334 -0
  130. package/dist/ui/src/components/markdown-content.mjs +325 -0
  131. package/dist/ui/src/components/markdown-editor.cjs +180 -0
  132. package/dist/ui/src/components/markdown-editor.mjs +178 -0
  133. package/dist/ui/src/components/multi-select.cjs +555 -0
  134. package/dist/ui/src/components/multi-select.mjs +540 -0
  135. package/dist/ui/src/components/popover.cjs +60 -0
  136. package/dist/ui/src/components/popover.mjs +42 -0
  137. package/dist/ui/src/components/radio-group.cjs +62 -0
  138. package/dist/ui/src/components/radio-group.mjs +45 -0
  139. package/dist/ui/src/components/search-select.cjs +99 -0
  140. package/dist/ui/src/components/search-select.mjs +83 -0
  141. package/dist/ui/src/components/select.cjs +161 -0
  142. package/dist/ui/src/components/select.mjs +139 -0
  143. package/dist/ui/src/components/separator.cjs +43 -0
  144. package/dist/ui/src/components/separator.mjs +27 -0
  145. package/dist/ui/src/components/switch.cjs +48 -0
  146. package/dist/ui/src/components/switch.mjs +32 -0
  147. package/dist/ui/src/components/tabs.cjs +84 -0
  148. package/dist/ui/src/components/tabs.mjs +65 -0
  149. package/dist/ui/src/components/textarea.cjs +20 -0
  150. package/dist/ui/src/components/textarea.mjs +18 -0
  151. package/dist/ui/src/hooks/use-debounce.cjs +16 -0
  152. package/dist/ui/src/hooks/use-debounce.mjs +14 -0
  153. package/dist/ui/src/lib/schema-converter.cjs +94 -0
  154. package/dist/ui/src/lib/schema-converter.mjs +92 -0
  155. package/dist/ui/src/lib/throttle.cjs +56 -0
  156. package/dist/ui/src/lib/throttle.mjs +54 -0
  157. package/dist/ui/src/lib/utils.cjs +10 -0
  158. package/dist/ui/src/lib/utils.mjs +8 -0
  159. package/dist/ui.css +131 -0
  160. package/package.json +176 -3
  161. package/README.md +0 -3
@@ -0,0 +1,36 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { FormItem, FormControl } from '../../form.mjs';
3
+ import { Switch } from '../../switch.mjs';
4
+ import AutoFormLabel from '../common/label.mjs';
5
+ import AutoFormTooltip from '../common/tooltip.mjs';
6
+
7
+ function AutoFormSwitch({
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: "flex items-center gap-3", children: [
16
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
17
+ Switch,
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 { AutoFormSwitch as default };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const form = require('../../form.cjs');
5
+ const textarea = require('../../textarea.cjs');
6
+ const label = require('../common/label.cjs');
7
+ const tooltip = require('../common/tooltip.cjs');
8
+
9
+ function AutoFormTextarea({
10
+ label: label$1,
11
+ isRequired,
12
+ fieldConfigItem,
13
+ fieldProps
14
+ }) {
15
+ const { showLabel: _showLabel, ...fieldPropsWithoutShowLabel } = fieldProps;
16
+ const showLabel = _showLabel === void 0 ? true : _showLabel;
17
+ return /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { children: [
18
+ showLabel && /* @__PURE__ */ jsxRuntime.jsx(
19
+ label,
20
+ {
21
+ label: fieldConfigItem?.label || label$1,
22
+ isRequired
23
+ }
24
+ ),
25
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(textarea.Textarea, { ...fieldPropsWithoutShowLabel }) }),
26
+ /* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem }),
27
+ /* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
28
+ ] });
29
+ }
30
+
31
+ module.exports = AutoFormTextarea;
@@ -0,0 +1,29 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { FormItem, FormControl, FormMessage } from '../../form.mjs';
3
+ import { Textarea } from '../../textarea.mjs';
4
+ import AutoFormLabel from '../common/label.mjs';
5
+ import AutoFormTooltip from '../common/tooltip.mjs';
6
+
7
+ function AutoFormTextarea({
8
+ label,
9
+ isRequired,
10
+ fieldConfigItem,
11
+ fieldProps
12
+ }) {
13
+ const { showLabel: _showLabel, ...fieldPropsWithoutShowLabel } = fieldProps;
14
+ const showLabel = _showLabel === void 0 ? true : _showLabel;
15
+ return /* @__PURE__ */ jsxs(FormItem, { children: [
16
+ showLabel && /* @__PURE__ */ jsx(
17
+ AutoFormLabel,
18
+ {
19
+ label: fieldConfigItem?.label || label,
20
+ isRequired
21
+ }
22
+ ),
23
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Textarea, { ...fieldPropsWithoutShowLabel }) }),
24
+ /* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem }),
25
+ /* @__PURE__ */ jsx(FormMessage, {})
26
+ ] });
27
+ }
28
+
29
+ export { AutoFormTextarea as default };
@@ -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 };