@btst/plugin-form-builder 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.
- package/LICENSE.md +17 -0
- package/dist/api/getters.cjs +154 -0
- package/dist/api/getters.mjs +145 -0
- package/dist/api/index.cjs +25 -0
- package/dist/api/index.d.cts +119 -0
- package/dist/api/index.d.mts +119 -0
- package/dist/api/index.d.ts +119 -0
- package/dist/api/index.mjs +6 -0
- package/dist/api/lifecycle-migrations.cjs +15 -0
- package/dist/api/lifecycle-migrations.mjs +13 -0
- package/dist/api/operations.cjs +1093 -0
- package/dist/api/operations.mjs +1082 -0
- package/dist/api/plugin.cjs +201 -0
- package/dist/api/plugin.mjs +192 -0
- package/dist/api/query-key-defs.cjs +43 -0
- package/dist/api/query-key-defs.mjs +39 -0
- package/dist/client/components/forms/form-renderer.cjs +193 -0
- package/dist/client/components/forms/form-renderer.mjs +191 -0
- package/dist/client/components/index.cjs +29 -0
- package/dist/client/components/index.d.cts +97 -0
- package/dist/client/components/index.d.mts +97 -0
- package/dist/client/components/index.d.ts +97 -0
- package/dist/client/components/index.mjs +18 -0
- package/dist/client/components/loading/form-builder-skeleton.cjs +32 -0
- package/dist/client/components/loading/form-builder-skeleton.mjs +30 -0
- package/dist/client/components/loading/form-list-skeleton.cjs +21 -0
- package/dist/client/components/loading/form-list-skeleton.mjs +19 -0
- package/dist/client/components/loading/submissions-skeleton.cjs +34 -0
- package/dist/client/components/loading/submissions-skeleton.mjs +32 -0
- package/dist/client/components/pages/404-page.cjs +28 -0
- package/dist/client/components/pages/404-page.mjs +26 -0
- package/dist/client/components/pages/form-builder-page.cjs +77 -0
- package/dist/client/components/pages/form-builder-page.internal.cjs +217 -0
- package/dist/client/components/pages/form-builder-page.internal.mjs +215 -0
- package/dist/client/components/pages/form-builder-page.mjs +75 -0
- package/dist/client/components/pages/form-list-page.cjs +44 -0
- package/dist/client/components/pages/form-list-page.internal.cjs +282 -0
- package/dist/client/components/pages/form-list-page.internal.mjs +280 -0
- package/dist/client/components/pages/form-list-page.mjs +42 -0
- package/dist/client/components/pages/submissions-page.cjs +64 -0
- package/dist/client/components/pages/submissions-page.internal.cjs +255 -0
- package/dist/client/components/pages/submissions-page.internal.mjs +253 -0
- package/dist/client/components/pages/submissions-page.mjs +62 -0
- package/dist/client/components/shared/default-error.cjs +17 -0
- package/dist/client/components/shared/default-error.mjs +15 -0
- package/dist/client/components/shared/empty-state.cjs +16 -0
- package/dist/client/components/shared/empty-state.mjs +14 -0
- package/dist/client/components/shared/page-wrapper.cjs +29 -0
- package/dist/client/components/shared/page-wrapper.mjs +27 -0
- package/dist/client/components/shared/pagination.cjs +49 -0
- package/dist/client/components/shared/pagination.mjs +47 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/form-builder-hooks.cjs +203 -0
- package/dist/client/hooks/form-builder-hooks.mjs +186 -0
- package/dist/client/hooks/form-builder-resource.cjs +13 -0
- package/dist/client/hooks/form-builder-resource.mjs +11 -0
- package/dist/client/hooks/index.cjs +22 -0
- package/dist/client/hooks/index.d.cts +378 -0
- package/dist/client/hooks/index.d.mts +378 -0
- package/dist/client/hooks/index.d.ts +378 -0
- package/dist/client/hooks/index.mjs +1 -0
- package/dist/client/index.cjs +13 -0
- package/dist/client/index.d.cts +410 -0
- package/dist/client/index.d.mts +410 -0
- package/dist/client/index.d.ts +410 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client/plugin.cjs +311 -0
- package/dist/client/plugin.mjs +309 -0
- package/dist/client.css +3 -0
- package/dist/db.cjs +99 -0
- package/dist/db.mjs +97 -0
- package/dist/permissions.cjs +95 -0
- package/dist/permissions.d.cts +94 -0
- package/dist/permissions.d.mts +94 -0
- package/dist/permissions.d.ts +94 -0
- package/dist/permissions.mjs +93 -0
- package/dist/query-keys.cjs +140 -0
- package/dist/query-keys.d.cts +392 -0
- package/dist/query-keys.d.mts +392 -0
- package/dist/query-keys.d.ts +392 -0
- package/dist/query-keys.mjs +137 -0
- package/dist/schemas.cjs +91 -0
- package/dist/schemas.mjs +82 -0
- package/dist/shared/plugin-form-builder.BZYGyFgT.d.mts +351 -0
- package/dist/shared/plugin-form-builder.Bbl9NufB.d.cts +408 -0
- package/dist/shared/plugin-form-builder.CSP5HR2O.d.ts +408 -0
- package/dist/shared/plugin-form-builder.Cmk083dA.d.cts +351 -0
- package/dist/shared/plugin-form-builder.D258Qpb8.d.ts +351 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.cts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.mts +118 -0
- package/dist/shared/plugin-form-builder.DWrQ3lRX.d.ts +118 -0
- package/dist/shared/plugin-form-builder.lp98rFNl.d.mts +408 -0
- package/dist/style.css +6 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/accordion.cjs +81 -0
- package/dist/ui/src/components/accordion.mjs +62 -0
- package/dist/ui/src/components/alert-dialog.cjs +157 -0
- package/dist/ui/src/components/alert-dialog.mjs +132 -0
- package/dist/ui/src/components/auto-form/common/label.cjs +18 -0
- package/dist/ui/src/components/auto-form/common/label.mjs +16 -0
- package/dist/ui/src/components/auto-form/common/tooltip.cjs +9 -0
- package/dist/ui/src/components/auto-form/common/tooltip.mjs +7 -0
- package/dist/ui/src/components/auto-form/config.cjs +40 -0
- package/dist/ui/src/components/auto-form/config.mjs +37 -0
- package/dist/ui/src/components/auto-form/dependencies.cjs +48 -0
- package/dist/ui/src/components/auto-form/dependencies.mjs +46 -0
- package/dist/ui/src/components/auto-form/fields/array.cjs +266 -0
- package/dist/ui/src/components/auto-form/fields/array.mjs +264 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/checkbox.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/date.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/date.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/enum.cjs +73 -0
- package/dist/ui/src/components/auto-form/fields/enum.mjs +71 -0
- package/dist/ui/src/components/auto-form/fields/input.cjs +32 -0
- package/dist/ui/src/components/auto-form/fields/input.mjs +30 -0
- package/dist/ui/src/components/auto-form/fields/number.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/number.mjs +29 -0
- package/dist/ui/src/components/auto-form/fields/object.cjs +233 -0
- package/dist/ui/src/components/auto-form/fields/object.mjs +217 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.cjs +67 -0
- package/dist/ui/src/components/auto-form/fields/radio-group.mjs +65 -0
- package/dist/ui/src/components/auto-form/fields/switch.cjs +38 -0
- package/dist/ui/src/components/auto-form/fields/switch.mjs +36 -0
- package/dist/ui/src/components/auto-form/fields/textarea.cjs +31 -0
- package/dist/ui/src/components/auto-form/fields/textarea.mjs +29 -0
- package/dist/ui/src/components/auto-form/helpers.cjs +270 -0
- package/dist/ui/src/components/auto-form/helpers.mjs +259 -0
- package/dist/ui/src/components/auto-form/index.cjs +92 -0
- package/dist/ui/src/components/auto-form/index.mjs +86 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.cjs +374 -0
- package/dist/ui/src/components/auto-form/stepped-auto-form.mjs +368 -0
- package/dist/ui/src/components/auto-form/types.cjs +11 -0
- package/dist/ui/src/components/auto-form/types.mjs +9 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/calendar.cjs +207 -0
- package/dist/ui/src/components/calendar.mjs +190 -0
- package/dist/ui/src/components/checkbox.cjs +48 -0
- package/dist/ui/src/components/checkbox.mjs +32 -0
- package/dist/ui/src/components/date-picker.cjs +41 -0
- package/dist/ui/src/components/date-picker.mjs +39 -0
- package/dist/ui/src/components/dialog.cjs +141 -0
- package/dist/ui/src/components/dialog.mjs +118 -0
- package/dist/ui/src/components/dropdown-menu.cjs +81 -0
- package/dist/ui/src/components/dropdown-menu.mjs +62 -0
- package/dist/ui/src/components/form-builder/canvas.cjs +111 -0
- package/dist/ui/src/components/form-builder/canvas.mjs +109 -0
- package/dist/ui/src/components/form-builder/components/index.cjs +571 -0
- package/dist/ui/src/components/form-builder/components/index.mjs +554 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.cjs +131 -0
- package/dist/ui/src/components/form-builder/edit-field-dialog.mjs +129 -0
- package/dist/ui/src/components/form-builder/form-preview.cjs +73 -0
- package/dist/ui/src/components/form-builder/form-preview.mjs +71 -0
- package/dist/ui/src/components/form-builder/index.cjs +350 -0
- package/dist/ui/src/components/form-builder/index.mjs +344 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.cjs +263 -0
- package/dist/ui/src/components/form-builder/nested-field-editor-dialog.mjs +261 -0
- package/dist/ui/src/components/form-builder/palette.cjs +52 -0
- package/dist/ui/src/components/form-builder/palette.mjs +49 -0
- package/dist/ui/src/components/form-builder/schema-utils.cjs +128 -0
- package/dist/ui/src/components/form-builder/schema-utils.mjs +122 -0
- package/dist/ui/src/components/form-builder/sortable-field.cjs +151 -0
- package/dist/ui/src/components/form-builder/sortable-field.mjs +148 -0
- package/dist/ui/src/components/form-builder/step-tabs.cjs +180 -0
- package/dist/ui/src/components/form-builder/step-tabs.mjs +178 -0
- package/dist/ui/src/components/form-builder/types.cjs +7 -0
- package/dist/ui/src/components/form-builder/types.mjs +5 -0
- package/dist/ui/src/components/form-builder/validation-schemas.cjs +67 -0
- package/dist/ui/src/components/form-builder/validation-schemas.mjs +56 -0
- package/dist/ui/src/components/form.cjs +120 -0
- package/dist/ui/src/components/form.mjs +98 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/components/label.cjs +39 -0
- package/dist/ui/src/components/label.mjs +23 -0
- package/dist/ui/src/components/page-layout.cjs +25 -0
- package/dist/ui/src/components/page-layout.mjs +23 -0
- package/dist/ui/src/components/page-wrapper.cjs +20 -0
- package/dist/ui/src/components/page-wrapper.mjs +18 -0
- package/dist/ui/src/components/popover.cjs +60 -0
- package/dist/ui/src/components/popover.mjs +42 -0
- package/dist/ui/src/components/radio-group.cjs +62 -0
- package/dist/ui/src/components/radio-group.mjs +45 -0
- package/dist/ui/src/components/select.cjs +161 -0
- package/dist/ui/src/components/select.mjs +139 -0
- package/dist/ui/src/components/separator.cjs +43 -0
- package/dist/ui/src/components/separator.mjs +27 -0
- package/dist/ui/src/components/skeleton.cjs +17 -0
- package/dist/ui/src/components/skeleton.mjs +15 -0
- package/dist/ui/src/components/stack-attribution.cjs +24 -0
- package/dist/ui/src/components/stack-attribution.mjs +22 -0
- package/dist/ui/src/components/switch.cjs +48 -0
- package/dist/ui/src/components/switch.mjs +32 -0
- package/dist/ui/src/components/table.cjs +89 -0
- package/dist/ui/src/components/table.mjs +82 -0
- package/dist/ui/src/components/tabs.cjs +84 -0
- package/dist/ui/src/components/tabs.mjs +65 -0
- package/dist/ui/src/components/textarea.cjs +20 -0
- package/dist/ui/src/components/textarea.mjs +18 -0
- package/dist/ui/src/lib/schema-converter.cjs +133 -0
- package/dist/ui/src/lib/schema-converter.mjs +127 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/dist/utils.cjs +41 -0
- package/dist/utils.mjs +32 -0
- package/package.json +175 -3
- package/README.md +0 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { DatePicker } from '../../date-picker.mjs';
|
|
3
|
+
import { FormItem, FormControl, FormMessage } from '../../form.mjs';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import AutoFormLabel from '../common/label.mjs';
|
|
6
|
+
import AutoFormTooltip from '../common/tooltip.mjs';
|
|
7
|
+
import { getBaseType, getBaseSchema } from '../helpers.mjs';
|
|
8
|
+
|
|
9
|
+
function toDate(value, dateOnly) {
|
|
10
|
+
if (!value) return void 0;
|
|
11
|
+
if (value instanceof Date) return value;
|
|
12
|
+
if (typeof value === "string") {
|
|
13
|
+
const date = new Date(dateOnly && /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T00:00:00` : value);
|
|
14
|
+
return isNaN(date.getTime()) ? void 0 : date;
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
function AutoFormDate({
|
|
19
|
+
label,
|
|
20
|
+
isRequired,
|
|
21
|
+
field,
|
|
22
|
+
fieldConfigItem,
|
|
23
|
+
fieldProps,
|
|
24
|
+
zodItem
|
|
25
|
+
}) {
|
|
26
|
+
const baseType = getBaseType(zodItem);
|
|
27
|
+
const expectsDateObject = baseType === "ZodDate";
|
|
28
|
+
const baseSchema = getBaseSchema(zodItem);
|
|
29
|
+
const dateSchema = baseSchema instanceof z.ZodUnion && baseSchema.options.length === 2 && baseSchema.options.some((option) => option instanceof z.ZodNull) ? baseSchema.options.find((option) => !(option instanceof z.ZodNull)) : baseSchema;
|
|
30
|
+
const expectsDateOnly = !!dateSchema && ("format" in dateSchema && dateSchema.format === "date" || dateSchema instanceof z.ZodString && !!dateSchema._zod.def.checks?.some((check) => "format" in check._zod.def && check._zod.def.format === "date"));
|
|
31
|
+
const handleChange = (date) => {
|
|
32
|
+
if (!date) {
|
|
33
|
+
field.onChange(expectsDateOnly && zodItem.isNullable() ? null : void 0);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (expectsDateObject) {
|
|
37
|
+
field.onChange(date);
|
|
38
|
+
} else if (expectsDateOnly) {
|
|
39
|
+
field.onChange(`${String(date.getFullYear()).padStart(4, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`);
|
|
40
|
+
} else {
|
|
41
|
+
field.onChange(date.toISOString());
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
AutoFormLabel,
|
|
47
|
+
{
|
|
48
|
+
label: fieldConfigItem?.label || label,
|
|
49
|
+
isRequired
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
|
|
53
|
+
DatePicker,
|
|
54
|
+
{
|
|
55
|
+
date: toDate(field.value, expectsDateOnly),
|
|
56
|
+
setDate: handleChange,
|
|
57
|
+
...fieldProps
|
|
58
|
+
}
|
|
59
|
+
) }),
|
|
60
|
+
/* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem }),
|
|
61
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
62
|
+
] });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { AutoFormDate as default };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const form = require('../../form.cjs');
|
|
5
|
+
const select = require('../../select.cjs');
|
|
6
|
+
const label = require('../common/label.cjs');
|
|
7
|
+
const tooltip = require('../common/tooltip.cjs');
|
|
8
|
+
const helpers = require('../helpers.cjs');
|
|
9
|
+
|
|
10
|
+
function getEnumValues(schema) {
|
|
11
|
+
if (Array.isArray(schema.options)) {
|
|
12
|
+
return schema.options;
|
|
13
|
+
}
|
|
14
|
+
if (schema.enum) {
|
|
15
|
+
return Object.values(schema.enum);
|
|
16
|
+
}
|
|
17
|
+
const def = schema._zod?.def;
|
|
18
|
+
if (def?.entries) {
|
|
19
|
+
return Object.values(def.entries);
|
|
20
|
+
}
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
function AutoFormEnum({
|
|
24
|
+
label: label$1,
|
|
25
|
+
isRequired,
|
|
26
|
+
field,
|
|
27
|
+
fieldConfigItem,
|
|
28
|
+
zodItem,
|
|
29
|
+
fieldProps
|
|
30
|
+
}) {
|
|
31
|
+
const baseSchema = helpers.getBaseSchema(zodItem);
|
|
32
|
+
const baseValues = getEnumValues(baseSchema);
|
|
33
|
+
let values = [];
|
|
34
|
+
if (!baseValues || baseValues.length === 0) {
|
|
35
|
+
values = [];
|
|
36
|
+
} else {
|
|
37
|
+
values = baseValues.map((value) => [value, value]);
|
|
38
|
+
}
|
|
39
|
+
function findItem(value) {
|
|
40
|
+
return values.find((item) => item[0] === value);
|
|
41
|
+
}
|
|
42
|
+
const handleValueChange = (val) => {
|
|
43
|
+
if (val === "" && field.value && field.value !== "") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
field.onChange(val);
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { children: [
|
|
49
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
50
|
+
label,
|
|
51
|
+
{
|
|
52
|
+
label: fieldConfigItem?.label || label$1,
|
|
53
|
+
isRequired
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
57
|
+
select.Select,
|
|
58
|
+
{
|
|
59
|
+
onValueChange: handleValueChange,
|
|
60
|
+
value: field.value ?? "",
|
|
61
|
+
...fieldProps,
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectTrigger, { className: fieldProps.className, children: /* @__PURE__ */ jsxRuntime.jsx(select.SelectValue, { placeholder: fieldConfigItem.inputProps?.placeholder, children: field.value ? findItem(field.value)?.[1] : "Select an option" }) }),
|
|
64
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.SelectContent, { children: values.map(([value, label2]) => /* @__PURE__ */ jsxRuntime.jsx(select.SelectItem, { value: label2, children: label2 }, value)) })
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
) }),
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem }),
|
|
69
|
+
/* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
|
|
70
|
+
] });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = AutoFormEnum;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { FormItem, FormControl, FormMessage } from '../../form.mjs';
|
|
3
|
+
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../../select.mjs';
|
|
4
|
+
import AutoFormLabel from '../common/label.mjs';
|
|
5
|
+
import AutoFormTooltip from '../common/tooltip.mjs';
|
|
6
|
+
import { getBaseSchema } from '../helpers.mjs';
|
|
7
|
+
|
|
8
|
+
function getEnumValues(schema) {
|
|
9
|
+
if (Array.isArray(schema.options)) {
|
|
10
|
+
return schema.options;
|
|
11
|
+
}
|
|
12
|
+
if (schema.enum) {
|
|
13
|
+
return Object.values(schema.enum);
|
|
14
|
+
}
|
|
15
|
+
const def = schema._zod?.def;
|
|
16
|
+
if (def?.entries) {
|
|
17
|
+
return Object.values(def.entries);
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
function AutoFormEnum({
|
|
22
|
+
label,
|
|
23
|
+
isRequired,
|
|
24
|
+
field,
|
|
25
|
+
fieldConfigItem,
|
|
26
|
+
zodItem,
|
|
27
|
+
fieldProps
|
|
28
|
+
}) {
|
|
29
|
+
const baseSchema = getBaseSchema(zodItem);
|
|
30
|
+
const baseValues = getEnumValues(baseSchema);
|
|
31
|
+
let values = [];
|
|
32
|
+
if (!baseValues || baseValues.length === 0) {
|
|
33
|
+
values = [];
|
|
34
|
+
} else {
|
|
35
|
+
values = baseValues.map((value) => [value, value]);
|
|
36
|
+
}
|
|
37
|
+
function findItem(value) {
|
|
38
|
+
return values.find((item) => item[0] === value);
|
|
39
|
+
}
|
|
40
|
+
const handleValueChange = (val) => {
|
|
41
|
+
if (val === "" && field.value && field.value !== "") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
field.onChange(val);
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
48
|
+
AutoFormLabel,
|
|
49
|
+
{
|
|
50
|
+
label: fieldConfigItem?.label || label,
|
|
51
|
+
isRequired
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs(
|
|
55
|
+
Select,
|
|
56
|
+
{
|
|
57
|
+
onValueChange: handleValueChange,
|
|
58
|
+
value: field.value ?? "",
|
|
59
|
+
...fieldProps,
|
|
60
|
+
children: [
|
|
61
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: fieldProps.className, children: /* @__PURE__ */ jsx(SelectValue, { placeholder: fieldConfigItem.inputProps?.placeholder, children: field.value ? findItem(field.value)?.[1] : "Select an option" }) }),
|
|
62
|
+
/* @__PURE__ */ jsx(SelectContent, { children: values.map(([value, label2]) => /* @__PURE__ */ jsx(SelectItem, { value: label2, children: label2 }, value)) })
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
) }),
|
|
66
|
+
/* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem }),
|
|
67
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
68
|
+
] });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { AutoFormEnum as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const form = require('../../form.cjs');
|
|
5
|
+
const input = require('../../input.cjs');
|
|
6
|
+
const label = require('../common/label.cjs');
|
|
7
|
+
const tooltip = require('../common/tooltip.cjs');
|
|
8
|
+
|
|
9
|
+
function AutoFormInput({
|
|
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
|
+
const type = fieldProps.type || "text";
|
|
18
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center space-x-2", children: /* @__PURE__ */ jsxRuntime.jsxs(form.FormItem, { className: "flex w-full flex-col justify-start", children: [
|
|
19
|
+
showLabel && /* @__PURE__ */ jsxRuntime.jsx(
|
|
20
|
+
label,
|
|
21
|
+
{
|
|
22
|
+
label: fieldConfigItem?.label || label$1,
|
|
23
|
+
isRequired
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
/* @__PURE__ */ jsxRuntime.jsx(form.FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(input.Input, { type, ...fieldPropsWithoutShowLabel }) }),
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem }),
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
|
|
29
|
+
] }) });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = AutoFormInput;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { FormItem, FormControl, FormMessage } from '../../form.mjs';
|
|
3
|
+
import { Input } from '../../input.mjs';
|
|
4
|
+
import AutoFormLabel from '../common/label.mjs';
|
|
5
|
+
import AutoFormTooltip from '../common/tooltip.mjs';
|
|
6
|
+
|
|
7
|
+
function AutoFormInput({
|
|
8
|
+
label,
|
|
9
|
+
isRequired,
|
|
10
|
+
fieldConfigItem,
|
|
11
|
+
fieldProps
|
|
12
|
+
}) {
|
|
13
|
+
const { showLabel: _showLabel, ...fieldPropsWithoutShowLabel } = fieldProps;
|
|
14
|
+
const showLabel = _showLabel === void 0 ? true : _showLabel;
|
|
15
|
+
const type = fieldProps.type || "text";
|
|
16
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center space-x-2", children: /* @__PURE__ */ jsxs(FormItem, { className: "flex w-full flex-col justify-start", children: [
|
|
17
|
+
showLabel && /* @__PURE__ */ jsx(
|
|
18
|
+
AutoFormLabel,
|
|
19
|
+
{
|
|
20
|
+
label: fieldConfigItem?.label || label,
|
|
21
|
+
isRequired
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { type, ...fieldPropsWithoutShowLabel }) }),
|
|
25
|
+
/* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem }),
|
|
26
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
27
|
+
] }) });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { AutoFormInput 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 input = require('../../input.cjs');
|
|
6
|
+
const label = require('../common/label.cjs');
|
|
7
|
+
const tooltip = require('../common/tooltip.cjs');
|
|
8
|
+
|
|
9
|
+
function AutoFormNumber({
|
|
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(input.Input, { type: "number", ...fieldPropsWithoutShowLabel }) }),
|
|
26
|
+
/* @__PURE__ */ jsxRuntime.jsx(tooltip, { fieldConfigItem }),
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx(form.FormMessage, {})
|
|
28
|
+
] });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = AutoFormNumber;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { FormItem, FormControl, FormMessage } from '../../form.mjs';
|
|
3
|
+
import { Input } from '../../input.mjs';
|
|
4
|
+
import AutoFormLabel from '../common/label.mjs';
|
|
5
|
+
import AutoFormTooltip from '../common/tooltip.mjs';
|
|
6
|
+
|
|
7
|
+
function AutoFormNumber({
|
|
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(Input, { type: "number", ...fieldPropsWithoutShowLabel }) }),
|
|
24
|
+
/* @__PURE__ */ jsx(AutoFormTooltip, { fieldConfigItem }),
|
|
25
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
26
|
+
] });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { AutoFormNumber as default };
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const accordion = require('../../accordion.cjs');
|
|
5
|
+
const form = require('../../form.cjs');
|
|
6
|
+
const reactHookForm = require('react-hook-form');
|
|
7
|
+
const z = require('zod');
|
|
8
|
+
const config = require('../config.cjs');
|
|
9
|
+
const helpers = require('../helpers.cjs');
|
|
10
|
+
const array = require('./array.cjs');
|
|
11
|
+
const dependencies = require('../dependencies.cjs');
|
|
12
|
+
|
|
13
|
+
function _interopNamespaceCompat(e) {
|
|
14
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
15
|
+
const n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
for (const k in e) {
|
|
18
|
+
n[k] = e[k];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
|
|
26
|
+
|
|
27
|
+
function DefaultParent({ children }) {
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
29
|
+
}
|
|
30
|
+
function AutoFormObject({
|
|
31
|
+
schema,
|
|
32
|
+
form: form$1,
|
|
33
|
+
fieldConfig,
|
|
34
|
+
path = [],
|
|
35
|
+
dependencies: dependencies$1 = []
|
|
36
|
+
}) {
|
|
37
|
+
const { watch } = reactHookForm.useFormContext();
|
|
38
|
+
if (!schema) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const { shape } = helpers.getBaseSchema(schema) || {};
|
|
42
|
+
if (!shape) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const handleIfZodNumber = (item) => {
|
|
46
|
+
const def = item._zod?.def;
|
|
47
|
+
const defType = def?.type;
|
|
48
|
+
const innerDefType = def?.innerType?._zod?.def?.type;
|
|
49
|
+
const isZodNumber = defType === "number" || defType === "int" || defType === "float";
|
|
50
|
+
const isInnerZodNumber = innerDefType === "number" || innerDefType === "int" || innerDefType === "float";
|
|
51
|
+
if (isZodNumber && def) {
|
|
52
|
+
def.coerce = true;
|
|
53
|
+
} else if (isInnerZodNumber && def?.innerType?._zod?.def) {
|
|
54
|
+
def.innerType._zod.def.coerce = true;
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
};
|
|
58
|
+
const sortedFieldKeys = helpers.sortFieldsByOrder(fieldConfig, Object.keys(shape));
|
|
59
|
+
return /* @__PURE__ */ jsxRuntime.jsx(accordion.Accordion, { type: "multiple", className: "space-y-5 border-none", children: sortedFieldKeys.map((name) => {
|
|
60
|
+
let item = shape[name];
|
|
61
|
+
item = handleIfZodNumber(item);
|
|
62
|
+
const zodBaseType = helpers.getBaseType(item);
|
|
63
|
+
const itemName = helpers.beautifyObjectName(name);
|
|
64
|
+
const key = [...path, name].join(".");
|
|
65
|
+
const {
|
|
66
|
+
isHidden,
|
|
67
|
+
isDisabled,
|
|
68
|
+
isRequired: isRequiredByDependency,
|
|
69
|
+
overrideOptions
|
|
70
|
+
} = dependencies(dependencies$1, name, watch);
|
|
71
|
+
if (isHidden) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (zodBaseType === "ZodObject") {
|
|
75
|
+
const objectFieldConfig = fieldConfig?.[name] ?? {};
|
|
76
|
+
if (typeof objectFieldConfig.fieldType === "function") {
|
|
77
|
+
const zodInputProps2 = helpers.zodToHtmlInputProps(item);
|
|
78
|
+
let isRequired2 = isRequiredByDependency || zodInputProps2.required || false;
|
|
79
|
+
if (objectFieldConfig.inputProps?.required !== void 0) {
|
|
80
|
+
isRequired2 = objectFieldConfig.inputProps.required;
|
|
81
|
+
}
|
|
82
|
+
const CustomComponent = objectFieldConfig.fieldType;
|
|
83
|
+
const ParentElement = objectFieldConfig.renderParent ?? DefaultParent;
|
|
84
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
form.FormField,
|
|
86
|
+
{
|
|
87
|
+
control: form$1.control,
|
|
88
|
+
name: key,
|
|
89
|
+
render: ({ field }) => {
|
|
90
|
+
const fieldProps = {
|
|
91
|
+
...zodInputProps2,
|
|
92
|
+
...field,
|
|
93
|
+
...objectFieldConfig.inputProps,
|
|
94
|
+
disabled: objectFieldConfig.inputProps?.disabled || isDisabled,
|
|
95
|
+
ref: void 0,
|
|
96
|
+
value: field.value
|
|
97
|
+
};
|
|
98
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ParentElement, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
99
|
+
CustomComponent,
|
|
100
|
+
{
|
|
101
|
+
zodInputProps: zodInputProps2,
|
|
102
|
+
field,
|
|
103
|
+
fieldConfigItem: objectFieldConfig,
|
|
104
|
+
label: objectFieldConfig.label || itemName,
|
|
105
|
+
isRequired: isRequired2,
|
|
106
|
+
zodItem: item,
|
|
107
|
+
fieldProps
|
|
108
|
+
}
|
|
109
|
+
) }, `${key}.parent`);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
key
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(accordion.AccordionItem, { value: name, className: "border-none", children: [
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsx(accordion.AccordionTrigger, { children: itemName }),
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsx(accordion.AccordionContent, { className: "p-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
118
|
+
AutoFormObject,
|
|
119
|
+
{
|
|
120
|
+
schema: item,
|
|
121
|
+
form: form$1,
|
|
122
|
+
fieldConfig: fieldConfig?.[name] ?? {},
|
|
123
|
+
path: [...path, name]
|
|
124
|
+
}
|
|
125
|
+
) })
|
|
126
|
+
] }, key);
|
|
127
|
+
}
|
|
128
|
+
if (zodBaseType === "ZodArray") {
|
|
129
|
+
const arrayFieldConfig = fieldConfig?.[name] ?? {};
|
|
130
|
+
if (typeof arrayFieldConfig.fieldType === "function") {
|
|
131
|
+
const zodInputProps2 = helpers.zodToHtmlInputProps(item);
|
|
132
|
+
let isRequired2 = isRequiredByDependency || zodInputProps2.required || false;
|
|
133
|
+
if (arrayFieldConfig.inputProps?.required !== void 0) {
|
|
134
|
+
isRequired2 = arrayFieldConfig.inputProps.required;
|
|
135
|
+
}
|
|
136
|
+
const CustomComponent = arrayFieldConfig.fieldType;
|
|
137
|
+
const ParentElement = arrayFieldConfig.renderParent ?? DefaultParent;
|
|
138
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
139
|
+
form.FormField,
|
|
140
|
+
{
|
|
141
|
+
control: form$1.control,
|
|
142
|
+
name: key,
|
|
143
|
+
render: ({ field }) => {
|
|
144
|
+
const fieldProps = {
|
|
145
|
+
...zodInputProps2,
|
|
146
|
+
...field,
|
|
147
|
+
...arrayFieldConfig.inputProps,
|
|
148
|
+
disabled: arrayFieldConfig.inputProps?.disabled || isDisabled,
|
|
149
|
+
ref: void 0,
|
|
150
|
+
value: field.value
|
|
151
|
+
};
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ParentElement, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
153
|
+
CustomComponent,
|
|
154
|
+
{
|
|
155
|
+
zodInputProps: zodInputProps2,
|
|
156
|
+
field,
|
|
157
|
+
fieldConfigItem: arrayFieldConfig,
|
|
158
|
+
label: arrayFieldConfig.label || itemName,
|
|
159
|
+
isRequired: isRequired2,
|
|
160
|
+
zodItem: item,
|
|
161
|
+
fieldProps
|
|
162
|
+
}
|
|
163
|
+
) }, `${key}.parent`);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
key
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
170
|
+
array,
|
|
171
|
+
{
|
|
172
|
+
name,
|
|
173
|
+
item,
|
|
174
|
+
form: form$1,
|
|
175
|
+
fieldConfig: arrayFieldConfig,
|
|
176
|
+
path: [...path, name]
|
|
177
|
+
},
|
|
178
|
+
key
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const fieldConfigItem = fieldConfig?.[name] ?? {};
|
|
182
|
+
const zodInputProps = helpers.zodToHtmlInputProps(item);
|
|
183
|
+
let isRequired = isRequiredByDependency || zodInputProps.required || false;
|
|
184
|
+
if (fieldConfigItem.inputProps?.required !== void 0) {
|
|
185
|
+
isRequired = fieldConfigItem.inputProps.required;
|
|
186
|
+
}
|
|
187
|
+
if (overrideOptions) {
|
|
188
|
+
item = z__namespace.enum(overrideOptions);
|
|
189
|
+
}
|
|
190
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
191
|
+
form.FormField,
|
|
192
|
+
{
|
|
193
|
+
control: form$1.control,
|
|
194
|
+
name: key,
|
|
195
|
+
render: ({ field }) => {
|
|
196
|
+
const inputType = fieldConfigItem.fieldType ?? config.DEFAULT_ZOD_HANDLERS[zodBaseType] ?? "fallback";
|
|
197
|
+
const InputComponent = typeof inputType === "function" ? inputType : config.INPUT_COMPONENTS[inputType];
|
|
198
|
+
const ParentElement = fieldConfigItem.renderParent ?? DefaultParent;
|
|
199
|
+
const defaultValue = fieldConfigItem.inputProps?.defaultValue;
|
|
200
|
+
const value = field.value ?? defaultValue ?? "";
|
|
201
|
+
const { defaultValue: _omitDV, ...safeInputProps } = fieldConfigItem.inputProps ?? {};
|
|
202
|
+
const fieldProps = {
|
|
203
|
+
...helpers.zodToHtmlInputProps(item),
|
|
204
|
+
...field,
|
|
205
|
+
...safeInputProps,
|
|
206
|
+
disabled: safeInputProps.disabled || isDisabled,
|
|
207
|
+
ref: void 0,
|
|
208
|
+
value
|
|
209
|
+
};
|
|
210
|
+
if (InputComponent === void 0) {
|
|
211
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
212
|
+
}
|
|
213
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ParentElement, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
214
|
+
InputComponent,
|
|
215
|
+
{
|
|
216
|
+
zodInputProps,
|
|
217
|
+
field,
|
|
218
|
+
fieldConfigItem,
|
|
219
|
+
label: itemName,
|
|
220
|
+
isRequired,
|
|
221
|
+
zodItem: item,
|
|
222
|
+
fieldProps,
|
|
223
|
+
className: fieldProps.className
|
|
224
|
+
}
|
|
225
|
+
) }, `${key}.parent`);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
key
|
|
229
|
+
);
|
|
230
|
+
}) });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
module.exports = AutoFormObject;
|