@connect-soft/form-generator 1.1.0-alpha5 → 1.1.0-alpha7
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/README.md +164 -59
- package/dist/index.js +363 -454
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +363 -451
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/form/array-field-renderer.d.ts +39 -0
- package/dist/types/components/form/array-field-renderer.d.ts.map +1 -0
- package/dist/types/components/form/create-template-fields.d.ts +1 -2
- package/dist/types/components/form/create-template-fields.d.ts.map +1 -1
- package/dist/types/components/form/field-renderer.d.ts +1 -6
- package/dist/types/components/form/field-renderer.d.ts.map +1 -1
- package/dist/types/components/form/form-generator.d.ts.map +1 -1
- package/dist/types/components/form/form-utils.d.ts +3 -9
- package/dist/types/components/form/form-utils.d.ts.map +1 -1
- package/dist/types/components/form/index.d.ts +4 -2
- package/dist/types/components/form/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/field-registry.d.ts +10 -50
- package/dist/types/lib/field-registry.d.ts.map +1 -1
- package/dist/types/lib/field-types.d.ts +18 -30
- package/dist/types/lib/field-types.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +3 -5
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/template-types.d.ts +18 -17
- package/dist/types/lib/template-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2792,52 +2792,13 @@ const r=(t,r,o)=>{if(t&&"reportValidity"in t){const s=get(o,r);t.setCustomValidi
|
|
|
2792
2792
|
|
|
2793
2793
|
function t(r,e){try{var o=r();}catch(r){return e(r)}return o&&o.then?o.then(void 0,e):o}function s(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code};}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=appendErrors(a,e,n,s,f?[].concat(f,t.message):t.message);}r.shift();}return n}function i(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("invalid_union"===t.code&&t.errors.length>0){var u=t.errors[0][0];n[a]={message:u.message,type:u.code};}else n[a]={message:i,type:s};if("invalid_union"===t.code&&t.errors.forEach(function(e){return e.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=appendErrors(a,e,n,s,f?[].concat(f,t.message):t.message);}r.shift();}return n}function a(o$1,a,u){if(void 0===u&&(u={}),function(r){return "_def"in r&&"object"==typeof r._def&&"typeName"in r._def}(o$1))return function(n,i,c){try{return Promise.resolve(t(function(){return Promise.resolve(o$1["sync"===u.mode?"parse":"parseAsync"](n,a)).then(function(e){return c.shouldUseNativeValidation&&o({},c),{errors:{},values:u.raw?Object.assign({},n):e}})},function(r){if(function(r){return Array.isArray(null==r?void 0:r.issues)}(r))return {values:{},errors:s$1(s(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}))}catch(r){return Promise.reject(r)}};if(function(r){return "_zod"in r&&"object"==typeof r._zod}(o$1))return function(s,c,f){try{return Promise.resolve(t(function(){return Promise.resolve(("sync"===u.mode?n__namespace.parse:n__namespace.parseAsync)(o$1,s,a)).then(function(e){return f.shouldUseNativeValidation&&o({},f),{errors:{},values:u.raw?Object.assign({},s):e}})},function(r){if(function(r){return r instanceof n__namespace.$ZodError}(r))return {values:{},errors:s$1(i(r.issues,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw r}))}catch(r){return Promise.reject(r)}};throw new Error("Invalid input: not a Zod schema")}
|
|
2794
2794
|
|
|
2795
|
-
function
|
|
2796
|
-
return
|
|
2795
|
+
function isArrayField(field) {
|
|
2796
|
+
return field.type === 'array' && 'fields' in field;
|
|
2797
2797
|
}
|
|
2798
2798
|
|
|
2799
2799
|
const fieldRegistry = new Map();
|
|
2800
2800
|
const componentRegistry = {};
|
|
2801
|
-
const layoutRegistry = {};
|
|
2802
2801
|
const defaultFormComponents = {
|
|
2803
|
-
FormItem: ({
|
|
2804
|
-
className,
|
|
2805
|
-
children
|
|
2806
|
-
}) => /*#__PURE__*/React.createElement('div', {
|
|
2807
|
-
className: className !== null && className !== void 0 ? className : 'form-item'
|
|
2808
|
-
}, children),
|
|
2809
|
-
FormInputLabelWrapper: ({
|
|
2810
|
-
className,
|
|
2811
|
-
orientation,
|
|
2812
|
-
children
|
|
2813
|
-
}) => /*#__PURE__*/React.createElement('div', {
|
|
2814
|
-
'className': className !== null && className !== void 0 ? className : 'form-input-label-wrapper',
|
|
2815
|
-
'data-orientation': orientation !== null && orientation !== void 0 ? orientation : 'vertical'
|
|
2816
|
-
}, children),
|
|
2817
|
-
FormLabel: ({
|
|
2818
|
-
className,
|
|
2819
|
-
children,
|
|
2820
|
-
required,
|
|
2821
|
-
htmlFor
|
|
2822
|
-
}) => /*#__PURE__*/React.createElement('label', {
|
|
2823
|
-
className: className !== null && className !== void 0 ? className : 'form-label',
|
|
2824
|
-
htmlFor
|
|
2825
|
-
}, children, required && /*#__PURE__*/React.createElement('span', {
|
|
2826
|
-
className: 'required-indicator'
|
|
2827
|
-
}, ' *')),
|
|
2828
|
-
FormDescription: ({
|
|
2829
|
-
className,
|
|
2830
|
-
children
|
|
2831
|
-
}) => /*#__PURE__*/React.createElement('p', {
|
|
2832
|
-
className: className !== null && className !== void 0 ? className : 'form-description'
|
|
2833
|
-
}, children),
|
|
2834
|
-
FormMessage: ({
|
|
2835
|
-
className,
|
|
2836
|
-
name
|
|
2837
|
-
}) => /*#__PURE__*/React.createElement('p', {
|
|
2838
|
-
'className': className !== null && className !== void 0 ? className : 'form-message',
|
|
2839
|
-
'data-field': name
|
|
2840
|
-
}),
|
|
2841
2802
|
SubmitButton: ({
|
|
2842
2803
|
className,
|
|
2843
2804
|
children,
|
|
@@ -2847,7 +2808,13 @@ const defaultFormComponents = {
|
|
|
2847
2808
|
type: 'submit',
|
|
2848
2809
|
className: className !== null && className !== void 0 ? className : 'form-submit',
|
|
2849
2810
|
disabled: disabled || isSubmitting
|
|
2850
|
-
}, isSubmitting ? 'Submitting...' : children)
|
|
2811
|
+
}, isSubmitting ? 'Submitting...' : children),
|
|
2812
|
+
FieldWrapper: ({
|
|
2813
|
+
children
|
|
2814
|
+
}) => /*#__PURE__*/React.createElement(React.Fragment, null, children),
|
|
2815
|
+
FieldsWrapper: ({
|
|
2816
|
+
children
|
|
2817
|
+
}) => /*#__PURE__*/React.createElement(React.Fragment, null, children)
|
|
2851
2818
|
};
|
|
2852
2819
|
const htmlInputTypes = {
|
|
2853
2820
|
text: 'text',
|
|
@@ -3032,10 +2999,6 @@ function getFieldComponent(type) {
|
|
|
3032
2999
|
}
|
|
3033
3000
|
return createDefaultFieldComponent(type);
|
|
3034
3001
|
}
|
|
3035
|
-
function getFieldOptions(type) {
|
|
3036
|
-
var _a;
|
|
3037
|
-
return (_a = fieldRegistry.get(type)) === null || _a === void 0 ? void 0 : _a.options;
|
|
3038
|
-
}
|
|
3039
3002
|
function getFieldValidator(type) {
|
|
3040
3003
|
var _a;
|
|
3041
3004
|
return (_a = fieldRegistry.get(type)) === null || _a === void 0 ? void 0 : _a.options.validator;
|
|
@@ -3081,37 +3044,6 @@ function getFormComponents() {
|
|
|
3081
3044
|
...componentRegistry
|
|
3082
3045
|
};
|
|
3083
3046
|
}
|
|
3084
|
-
function registerLayoutComponents(components, config = {}) {
|
|
3085
|
-
const {
|
|
3086
|
-
override = true
|
|
3087
|
-
} = config;
|
|
3088
|
-
Object.keys(components).forEach(key => {
|
|
3089
|
-
const exists = key in layoutRegistry;
|
|
3090
|
-
if (override === 'only' && !exists) return;
|
|
3091
|
-
if (override === false && exists) return;
|
|
3092
|
-
layoutRegistry[key] = components[key];
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
|
-
function registerLayoutComponent(name, component, config = {}) {
|
|
3096
|
-
const {
|
|
3097
|
-
override = true
|
|
3098
|
-
} = config;
|
|
3099
|
-
const exists = name in layoutRegistry;
|
|
3100
|
-
if (override === 'only' && !exists) return;
|
|
3101
|
-
if (override === false && exists) return;
|
|
3102
|
-
layoutRegistry[name] = component;
|
|
3103
|
-
}
|
|
3104
|
-
function getLayoutComponent(name) {
|
|
3105
|
-
return layoutRegistry[name];
|
|
3106
|
-
}
|
|
3107
|
-
function hasLayoutComponent(name) {
|
|
3108
|
-
return name in layoutRegistry;
|
|
3109
|
-
}
|
|
3110
|
-
function clearLayoutRegistry() {
|
|
3111
|
-
Object.keys(layoutRegistry).forEach(key => {
|
|
3112
|
-
delete layoutRegistry[key];
|
|
3113
|
-
});
|
|
3114
|
-
}
|
|
3115
3047
|
function clearFieldRegistry() {
|
|
3116
3048
|
fieldRegistry.clear();
|
|
3117
3049
|
}
|
|
@@ -3127,106 +3059,6 @@ function resetFormComponentRegistry() {
|
|
|
3127
3059
|
function clearAllRegistries() {
|
|
3128
3060
|
clearFieldRegistry();
|
|
3129
3061
|
clearFormComponentRegistry();
|
|
3130
|
-
clearLayoutRegistry();
|
|
3131
|
-
}
|
|
3132
|
-
|
|
3133
|
-
const RESERVED_PROPS = new Set(['all', 'remaining', 'names', 'has', 'render']);
|
|
3134
|
-
function createTemplateFields(fieldEntries) {
|
|
3135
|
-
const accessedFields = new Set();
|
|
3136
|
-
const handler = {
|
|
3137
|
-
get(_, prop) {
|
|
3138
|
-
if (typeof prop === 'symbol') {
|
|
3139
|
-
return undefined;
|
|
3140
|
-
}
|
|
3141
|
-
if (prop === 'all') {
|
|
3142
|
-
return Array.from(fieldEntries.values()).map(entry => entry.element);
|
|
3143
|
-
}
|
|
3144
|
-
if (prop === 'remaining') {
|
|
3145
|
-
return Array.from(fieldEntries.entries()).filter(([name]) => !accessedFields.has(name)).map(([, entry]) => entry.element);
|
|
3146
|
-
}
|
|
3147
|
-
if (prop === 'names') {
|
|
3148
|
-
return Array.from(fieldEntries.keys());
|
|
3149
|
-
}
|
|
3150
|
-
if (prop === 'has') {
|
|
3151
|
-
return name => fieldEntries.has(name);
|
|
3152
|
-
}
|
|
3153
|
-
if (prop === 'render') {
|
|
3154
|
-
return (...names) => {
|
|
3155
|
-
return names.filter(name => fieldEntries.has(name)).map(name => {
|
|
3156
|
-
accessedFields.add(name);
|
|
3157
|
-
return fieldEntries.get(name).element;
|
|
3158
|
-
});
|
|
3159
|
-
};
|
|
3160
|
-
}
|
|
3161
|
-
if (fieldEntries.has(prop)) {
|
|
3162
|
-
accessedFields.add(prop);
|
|
3163
|
-
return fieldEntries.get(prop).element;
|
|
3164
|
-
}
|
|
3165
|
-
return undefined;
|
|
3166
|
-
},
|
|
3167
|
-
has(_, prop) {
|
|
3168
|
-
if (typeof prop === 'symbol') {
|
|
3169
|
-
return false;
|
|
3170
|
-
}
|
|
3171
|
-
return RESERVED_PROPS.has(prop) || fieldEntries.has(prop);
|
|
3172
|
-
},
|
|
3173
|
-
ownKeys() {
|
|
3174
|
-
return [...RESERVED_PROPS, ...fieldEntries.keys()];
|
|
3175
|
-
},
|
|
3176
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
3177
|
-
if (typeof prop === 'symbol') {
|
|
3178
|
-
return undefined;
|
|
3179
|
-
}
|
|
3180
|
-
if (RESERVED_PROPS.has(prop) || fieldEntries.has(prop)) {
|
|
3181
|
-
return {
|
|
3182
|
-
configurable: true,
|
|
3183
|
-
enumerable: true,
|
|
3184
|
-
value: this.get(_, prop, {})
|
|
3185
|
-
};
|
|
3186
|
-
}
|
|
3187
|
-
return undefined;
|
|
3188
|
-
}
|
|
3189
|
-
};
|
|
3190
|
-
return new Proxy({}, handler);
|
|
3191
|
-
}
|
|
3192
|
-
function createTemplateLayouts(layoutEntries) {
|
|
3193
|
-
const handler = {
|
|
3194
|
-
get(_, prop) {
|
|
3195
|
-
if (typeof prop === 'symbol') {
|
|
3196
|
-
return undefined;
|
|
3197
|
-
}
|
|
3198
|
-
if (prop === 'all') {
|
|
3199
|
-
return Array.from(layoutEntries.values()).map(entry => entry.element);
|
|
3200
|
-
}
|
|
3201
|
-
if (layoutEntries.has(prop)) {
|
|
3202
|
-
return layoutEntries.get(prop).element;
|
|
3203
|
-
}
|
|
3204
|
-
return undefined;
|
|
3205
|
-
},
|
|
3206
|
-
has(_, prop) {
|
|
3207
|
-
if (typeof prop === 'symbol') {
|
|
3208
|
-
return false;
|
|
3209
|
-
}
|
|
3210
|
-
return prop === 'all' || layoutEntries.has(prop);
|
|
3211
|
-
},
|
|
3212
|
-
ownKeys() {
|
|
3213
|
-
return ['all', ...layoutEntries.keys()];
|
|
3214
|
-
},
|
|
3215
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
3216
|
-
if (typeof prop === 'symbol') {
|
|
3217
|
-
return undefined;
|
|
3218
|
-
}
|
|
3219
|
-
if (prop === 'all' || layoutEntries.has(prop)) {
|
|
3220
|
-
return {
|
|
3221
|
-
configurable: true,
|
|
3222
|
-
enumerable: true,
|
|
3223
|
-
value: this.get(_, prop, {})
|
|
3224
|
-
};
|
|
3225
|
-
}
|
|
3226
|
-
return undefined;
|
|
3227
|
-
}
|
|
3228
|
-
};
|
|
3229
|
-
return new Proxy({}, handler);
|
|
3230
3062
|
}
|
|
3231
3063
|
|
|
3232
3064
|
const FieldRenderer = /*#__PURE__*/React.memo(t0 => {
|
|
@@ -3254,18 +3086,6 @@ const FieldRenderer = /*#__PURE__*/React.memo(t0 => {
|
|
|
3254
3086
|
t2 = null;
|
|
3255
3087
|
break bb0;
|
|
3256
3088
|
}
|
|
3257
|
-
const FormItemComponent = getFormComponent("FormItem");
|
|
3258
|
-
const FormLabelComponent = getFormComponent("FormLabel");
|
|
3259
|
-
const FormInputLabelWrapper = getFormComponent("FormInputLabelWrapper");
|
|
3260
|
-
const FormDescriptionComponent = getFormComponent("FormDescription");
|
|
3261
|
-
const FormMessageComponent = getFormComponent("FormMessage");
|
|
3262
|
-
if (!FormItemComponent) {
|
|
3263
|
-
console.warn("FormItem component not registered. Use registerFormComponent(\"FormItem\", Component) to register one.");
|
|
3264
|
-
t2 = null;
|
|
3265
|
-
break bb0;
|
|
3266
|
-
}
|
|
3267
|
-
const fieldOptions = getFieldOptions(field.type);
|
|
3268
|
-
const itemClassName = [`form-field-${field.type}`, fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.className, field.className].filter(Boolean).join(" ");
|
|
3269
3089
|
const fieldName = namePrefix ? `${namePrefix}.${field.name}` : field.name;
|
|
3270
3090
|
t1 = jsxRuntime.jsx(Controller, {
|
|
3271
3091
|
control: form.control,
|
|
@@ -3275,36 +3095,18 @@ const FieldRenderer = /*#__PURE__*/React.memo(t0 => {
|
|
|
3275
3095
|
field: formField,
|
|
3276
3096
|
fieldState
|
|
3277
3097
|
} = t3;
|
|
3278
|
-
return jsxRuntime.
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
orientation: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.inputLabelWrapperOrientation,
|
|
3282
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.inputLabelWrapper,
|
|
3283
|
-
children: [field.label && FormLabelComponent && jsxRuntime.jsx(FormLabelComponent, {
|
|
3284
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.labelClassName,
|
|
3285
|
-
required: field.required,
|
|
3286
|
-
htmlFor: fieldName,
|
|
3287
|
-
children: field.label
|
|
3288
|
-
}), jsxRuntime.jsx(FieldComponent, {
|
|
3289
|
-
field: {
|
|
3290
|
-
...field,
|
|
3291
|
-
name: fieldName
|
|
3292
|
-
},
|
|
3293
|
-
formField,
|
|
3294
|
-
fieldState: {
|
|
3295
|
-
invalid: fieldState.invalid,
|
|
3296
|
-
error: fieldState.error,
|
|
3297
|
-
isDirty: fieldState.isDirty,
|
|
3298
|
-
isTouched: fieldState.isTouched
|
|
3299
|
-
}
|
|
3300
|
-
})]
|
|
3301
|
-
}), field.description && FormDescriptionComponent && jsxRuntime.jsx(FormDescriptionComponent, {
|
|
3302
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.descriptionClassName,
|
|
3303
|
-
children: field.description
|
|
3304
|
-
}), FormMessageComponent && jsxRuntime.jsx(FormMessageComponent, {
|
|
3305
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.messageClassName,
|
|
3098
|
+
return jsxRuntime.jsx(FieldComponent, {
|
|
3099
|
+
field: {
|
|
3100
|
+
...field,
|
|
3306
3101
|
name: fieldName
|
|
3307
|
-
}
|
|
3102
|
+
},
|
|
3103
|
+
formField,
|
|
3104
|
+
fieldState: {
|
|
3105
|
+
invalid: fieldState.invalid,
|
|
3106
|
+
error: fieldState.error,
|
|
3107
|
+
isDirty: fieldState.isDirty,
|
|
3108
|
+
isTouched: fieldState.isTouched
|
|
3109
|
+
}
|
|
3308
3110
|
});
|
|
3309
3111
|
}
|
|
3310
3112
|
});
|
|
@@ -3324,134 +3126,267 @@ const FieldRenderer = /*#__PURE__*/React.memo(t0 => {
|
|
|
3324
3126
|
return t1;
|
|
3325
3127
|
});
|
|
3326
3128
|
FieldRenderer.displayName = 'FieldRenderer';
|
|
3327
|
-
|
|
3328
|
-
|
|
3129
|
+
|
|
3130
|
+
function useArrayField(field) {
|
|
3329
3131
|
const {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3132
|
+
control
|
|
3133
|
+
} = useFormContext();
|
|
3134
|
+
const fieldArray = useFieldArray({
|
|
3135
|
+
control,
|
|
3136
|
+
name: field.name
|
|
3137
|
+
});
|
|
3138
|
+
const {
|
|
3139
|
+
fields: items,
|
|
3140
|
+
append,
|
|
3141
|
+
prepend,
|
|
3142
|
+
remove,
|
|
3143
|
+
move,
|
|
3144
|
+
swap,
|
|
3145
|
+
insert
|
|
3146
|
+
} = fieldArray;
|
|
3147
|
+
const buildEmptyItem = React.useCallback(() => {
|
|
3148
|
+
const item = {};
|
|
3149
|
+
field.fields.forEach(f => {
|
|
3150
|
+
var _a;
|
|
3151
|
+
item[f.name] = (_a = f.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3152
|
+
});
|
|
3153
|
+
return item;
|
|
3154
|
+
}, [field.fields]);
|
|
3155
|
+
const handleAppend = React.useCallback(() => {
|
|
3156
|
+
append(buildEmptyItem());
|
|
3157
|
+
}, [append, buildEmptyItem]);
|
|
3158
|
+
const handleAppendWith = React.useCallback(values => {
|
|
3159
|
+
append(values);
|
|
3160
|
+
}, [append]);
|
|
3161
|
+
const handlePrepend = React.useCallback(() => {
|
|
3162
|
+
prepend(buildEmptyItem());
|
|
3163
|
+
}, [prepend, buildEmptyItem]);
|
|
3164
|
+
const handleInsert = React.useCallback((index, values_0) => {
|
|
3165
|
+
insert(index, values_0 !== null && values_0 !== void 0 ? values_0 : buildEmptyItem());
|
|
3166
|
+
}, [insert, buildEmptyItem]);
|
|
3167
|
+
const canAppend = field.maxItems === undefined || items.length < field.maxItems;
|
|
3168
|
+
const canRemove = field.minItems === undefined || items.length > field.minItems;
|
|
3169
|
+
const renderField = React.useCallback((index_0, fieldName) => {
|
|
3170
|
+
const childField = field.fields.find(f_0 => f_0.name === fieldName);
|
|
3171
|
+
if (!childField) {
|
|
3172
|
+
console.warn(`Field "${fieldName}" not found in array field "${field.name}"`);
|
|
3173
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
3361
3174
|
}
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
});
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3175
|
+
return jsxRuntime.jsx(FieldRenderer, {
|
|
3176
|
+
field: childField,
|
|
3177
|
+
namePrefix: `${field.name}.${index_0}`
|
|
3178
|
+
}, `${field.name}.${index_0}.${fieldName}`);
|
|
3179
|
+
}, [field]);
|
|
3180
|
+
const renderItem = React.useCallback(index_1 => {
|
|
3181
|
+
const result = {};
|
|
3182
|
+
field.fields.forEach(childField_0 => {
|
|
3183
|
+
result[childField_0.name] = jsxRuntime.jsx(FieldRenderer, {
|
|
3184
|
+
field: childField_0,
|
|
3185
|
+
namePrefix: `${field.name}.${index_1}`
|
|
3186
|
+
}, `${field.name}.${index_1}.${childField_0.name}`);
|
|
3187
|
+
});
|
|
3188
|
+
return result;
|
|
3189
|
+
}, [field]);
|
|
3190
|
+
return {
|
|
3191
|
+
fieldArray,
|
|
3192
|
+
append: handleAppend,
|
|
3193
|
+
appendWith: handleAppendWith,
|
|
3194
|
+
prepend: handlePrepend,
|
|
3195
|
+
remove,
|
|
3196
|
+
move,
|
|
3197
|
+
swap,
|
|
3198
|
+
insert: handleInsert,
|
|
3199
|
+
field,
|
|
3200
|
+
items: items.map((item_0, index_2) => ({
|
|
3201
|
+
id: item_0.id,
|
|
3202
|
+
index: index_2
|
|
3203
|
+
})),
|
|
3204
|
+
canAppend,
|
|
3205
|
+
canRemove,
|
|
3206
|
+
renderField,
|
|
3207
|
+
renderItem
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3210
|
+
const ArrayFieldRenderer = /*#__PURE__*/React.memo(t0 => {
|
|
3211
|
+
const $ = compilerRuntime.c(28);
|
|
3378
3212
|
const {
|
|
3379
|
-
|
|
3380
|
-
|
|
3213
|
+
field,
|
|
3214
|
+
children
|
|
3381
3215
|
} = t0;
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3216
|
+
const {
|
|
3217
|
+
items,
|
|
3218
|
+
append,
|
|
3219
|
+
remove,
|
|
3220
|
+
move,
|
|
3221
|
+
canAppend,
|
|
3222
|
+
renderItem,
|
|
3223
|
+
field: arrayField
|
|
3224
|
+
} = useArrayField(field);
|
|
3225
|
+
if (field.hidden) {
|
|
3226
|
+
return null;
|
|
3227
|
+
}
|
|
3228
|
+
if (!children) {
|
|
3229
|
+
let t1;
|
|
3230
|
+
if ($[0] !== append || $[1] !== canAppend || $[2] !== field.className || $[3] !== field.description || $[4] !== field.label || $[5] !== items || $[6] !== renderItem) {
|
|
3231
|
+
let t2;
|
|
3232
|
+
if ($[8] !== renderItem) {
|
|
3233
|
+
t2 = t3 => {
|
|
3234
|
+
const {
|
|
3235
|
+
id,
|
|
3236
|
+
index
|
|
3237
|
+
} = t3;
|
|
3238
|
+
return jsxRuntime.jsx("div", {
|
|
3239
|
+
"data-array-item-index": index,
|
|
3240
|
+
children: Object.values(renderItem(index))
|
|
3241
|
+
}, id);
|
|
3242
|
+
};
|
|
3243
|
+
$[8] = renderItem;
|
|
3244
|
+
$[9] = t2;
|
|
3402
3245
|
} else {
|
|
3403
|
-
|
|
3246
|
+
t2 = $[9];
|
|
3404
3247
|
}
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3248
|
+
t1 = jsxRuntime.jsxs("div", {
|
|
3249
|
+
className: field.className,
|
|
3250
|
+
children: [field.label && jsxRuntime.jsx("label", {
|
|
3251
|
+
children: field.label
|
|
3252
|
+
}), field.description && jsxRuntime.jsx("p", {
|
|
3253
|
+
children: field.description
|
|
3254
|
+
}), items.map(t2), canAppend && jsxRuntime.jsx("button", {
|
|
3255
|
+
type: "button",
|
|
3256
|
+
onClick: append,
|
|
3257
|
+
children: "Add Item"
|
|
3258
|
+
})]
|
|
3409
3259
|
});
|
|
3260
|
+
$[0] = append;
|
|
3261
|
+
$[1] = canAppend;
|
|
3262
|
+
$[2] = field.className;
|
|
3263
|
+
$[3] = field.description;
|
|
3264
|
+
$[4] = field.label;
|
|
3265
|
+
$[5] = items;
|
|
3266
|
+
$[6] = renderItem;
|
|
3267
|
+
$[7] = t1;
|
|
3268
|
+
} else {
|
|
3269
|
+
t1 = $[7];
|
|
3410
3270
|
}
|
|
3411
|
-
|
|
3412
|
-
$[1] = namePrefix;
|
|
3413
|
-
$[2] = t1;
|
|
3414
|
-
$[3] = t2;
|
|
3415
|
-
} else {
|
|
3416
|
-
t1 = $[2];
|
|
3417
|
-
t2 = $[3];
|
|
3271
|
+
return t1;
|
|
3418
3272
|
}
|
|
3419
|
-
|
|
3420
|
-
|
|
3273
|
+
let t1;
|
|
3274
|
+
if ($[10] !== arrayField || $[11] !== children || $[12] !== field.className || $[13] !== field.description || $[14] !== field.label || $[15] !== field.name || $[16] !== items || $[17] !== move || $[18] !== remove || $[19] !== renderItem) {
|
|
3275
|
+
let t2;
|
|
3276
|
+
if ($[21] !== arrayField || $[22] !== children || $[23] !== field.name || $[24] !== move || $[25] !== remove || $[26] !== renderItem) {
|
|
3277
|
+
t2 = t3 => {
|
|
3278
|
+
const {
|
|
3279
|
+
id: id_0,
|
|
3280
|
+
index: index_0
|
|
3281
|
+
} = t3;
|
|
3282
|
+
return children({
|
|
3283
|
+
index: index_0,
|
|
3284
|
+
id: id_0,
|
|
3285
|
+
remove: () => remove(index_0),
|
|
3286
|
+
move: toIndex => move(index_0, toIndex),
|
|
3287
|
+
fields: renderItem(index_0),
|
|
3288
|
+
fieldNames: arrayField.fields.map(_temp),
|
|
3289
|
+
namePrefix: `${field.name}.${index_0}`
|
|
3290
|
+
});
|
|
3291
|
+
};
|
|
3292
|
+
$[21] = arrayField;
|
|
3293
|
+
$[22] = children;
|
|
3294
|
+
$[23] = field.name;
|
|
3295
|
+
$[24] = move;
|
|
3296
|
+
$[25] = remove;
|
|
3297
|
+
$[26] = renderItem;
|
|
3298
|
+
$[27] = t2;
|
|
3299
|
+
} else {
|
|
3300
|
+
t2 = $[27];
|
|
3301
|
+
}
|
|
3302
|
+
t1 = jsxRuntime.jsxs("div", {
|
|
3303
|
+
className: field.className,
|
|
3304
|
+
children: [field.label && jsxRuntime.jsx("label", {
|
|
3305
|
+
children: field.label
|
|
3306
|
+
}), field.description && jsxRuntime.jsx("p", {
|
|
3307
|
+
children: field.description
|
|
3308
|
+
}), items.map(t2)]
|
|
3309
|
+
});
|
|
3310
|
+
$[10] = arrayField;
|
|
3311
|
+
$[11] = children;
|
|
3312
|
+
$[12] = field.className;
|
|
3313
|
+
$[13] = field.description;
|
|
3314
|
+
$[14] = field.label;
|
|
3315
|
+
$[15] = field.name;
|
|
3316
|
+
$[16] = items;
|
|
3317
|
+
$[17] = move;
|
|
3318
|
+
$[18] = remove;
|
|
3319
|
+
$[19] = renderItem;
|
|
3320
|
+
$[20] = t1;
|
|
3321
|
+
} else {
|
|
3322
|
+
t1 = $[20];
|
|
3421
3323
|
}
|
|
3422
3324
|
return t1;
|
|
3423
3325
|
});
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
return
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3326
|
+
ArrayFieldRenderer.displayName = 'ArrayFieldRenderer';
|
|
3327
|
+
function _temp(f) {
|
|
3328
|
+
return f.name;
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
const RESERVED_PROPS = new Set(['all', 'remaining', 'names', 'has', 'render']);
|
|
3332
|
+
function createTemplateFields(fieldEntries) {
|
|
3333
|
+
const accessedFields = new Set();
|
|
3334
|
+
const handler = {
|
|
3335
|
+
get(_, prop) {
|
|
3336
|
+
if (typeof prop === 'symbol') {
|
|
3337
|
+
return undefined;
|
|
3338
|
+
}
|
|
3339
|
+
if (prop === 'all') {
|
|
3340
|
+
return Array.from(fieldEntries.values()).map(entry => entry.element);
|
|
3341
|
+
}
|
|
3342
|
+
if (prop === 'remaining') {
|
|
3343
|
+
return Array.from(fieldEntries.entries()).filter(([name]) => !accessedFields.has(name)).map(([, entry]) => entry.element);
|
|
3344
|
+
}
|
|
3345
|
+
if (prop === 'names') {
|
|
3346
|
+
return Array.from(fieldEntries.keys());
|
|
3347
|
+
}
|
|
3348
|
+
if (prop === 'has') {
|
|
3349
|
+
return name => fieldEntries.has(name);
|
|
3350
|
+
}
|
|
3351
|
+
if (prop === 'render') {
|
|
3352
|
+
return (...names) => {
|
|
3353
|
+
return names.filter(name => fieldEntries.has(name)).map(name => {
|
|
3354
|
+
accessedFields.add(name);
|
|
3355
|
+
return fieldEntries.get(name).element;
|
|
3356
|
+
});
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3359
|
+
if (fieldEntries.has(prop)) {
|
|
3360
|
+
accessedFields.add(prop);
|
|
3361
|
+
return fieldEntries.get(prop).element;
|
|
3362
|
+
}
|
|
3363
|
+
return undefined;
|
|
3364
|
+
},
|
|
3365
|
+
has(_, prop) {
|
|
3366
|
+
if (typeof prop === 'symbol') {
|
|
3367
|
+
return false;
|
|
3368
|
+
}
|
|
3369
|
+
return RESERVED_PROPS.has(prop) || fieldEntries.has(prop);
|
|
3370
|
+
},
|
|
3371
|
+
ownKeys() {
|
|
3372
|
+
return [...RESERVED_PROPS, ...fieldEntries.keys()];
|
|
3373
|
+
},
|
|
3374
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
3375
|
+
if (typeof prop === 'symbol') {
|
|
3376
|
+
return undefined;
|
|
3377
|
+
}
|
|
3378
|
+
if (RESERVED_PROPS.has(prop) || fieldEntries.has(prop)) {
|
|
3379
|
+
return {
|
|
3380
|
+
configurable: true,
|
|
3381
|
+
enumerable: true,
|
|
3382
|
+
value: this.get(_, prop, {})
|
|
3383
|
+
};
|
|
3384
|
+
}
|
|
3385
|
+
return undefined;
|
|
3447
3386
|
}
|
|
3448
|
-
}
|
|
3449
|
-
return
|
|
3450
|
-
|
|
3451
|
-
namePrefix: namePrefix
|
|
3452
|
-
});
|
|
3453
|
-
});
|
|
3454
|
-
FormItemRenderer.displayName = 'FormItemRenderer';
|
|
3387
|
+
};
|
|
3388
|
+
return new Proxy({}, handler);
|
|
3389
|
+
}
|
|
3455
3390
|
|
|
3456
3391
|
function deepMerge(target, source) {
|
|
3457
3392
|
const result = {
|
|
@@ -3507,96 +3442,61 @@ function getValidatorForField(field) {
|
|
|
3507
3442
|
}
|
|
3508
3443
|
return zod.z.any();
|
|
3509
3444
|
}
|
|
3510
|
-
function
|
|
3445
|
+
function buildArrayItemSchema(arrayField) {
|
|
3446
|
+
const itemShape = {};
|
|
3447
|
+
for (const field of arrayField.fields) {
|
|
3448
|
+
const validator = getValidatorForField(field);
|
|
3449
|
+
itemShape[field.name] = field.required ? validator : validator.optional();
|
|
3450
|
+
}
|
|
3451
|
+
return zod.z.object(itemShape);
|
|
3452
|
+
}
|
|
3453
|
+
function buildSchema(fields) {
|
|
3511
3454
|
const shape = {};
|
|
3512
|
-
for (const
|
|
3513
|
-
if (
|
|
3514
|
-
let
|
|
3515
|
-
if (
|
|
3516
|
-
|
|
3517
|
-
childItems.push(...column.children);
|
|
3518
|
-
}
|
|
3519
|
-
} else if (item.type === 'section') {
|
|
3520
|
-
childItems = item.children;
|
|
3455
|
+
for (const field of fields) {
|
|
3456
|
+
if (isArrayField(field)) {
|
|
3457
|
+
let arraySchema = zod.z.array(buildArrayItemSchema(field));
|
|
3458
|
+
if (field.minItems !== undefined) {
|
|
3459
|
+
arraySchema = arraySchema.min(field.minItems);
|
|
3521
3460
|
}
|
|
3522
|
-
if (
|
|
3523
|
-
|
|
3524
|
-
} else {
|
|
3525
|
-
const childSchema = buildSchema(childItems);
|
|
3526
|
-
if (childSchema instanceof zod.z.ZodObject) {
|
|
3527
|
-
Object.assign(shape, childSchema.shape);
|
|
3528
|
-
}
|
|
3461
|
+
if (field.maxItems !== undefined) {
|
|
3462
|
+
arraySchema = arraySchema.max(field.maxItems);
|
|
3529
3463
|
}
|
|
3464
|
+
shape[field.name] = arraySchema;
|
|
3530
3465
|
} else {
|
|
3531
|
-
const field = item;
|
|
3532
3466
|
const validator = getValidatorForField(field);
|
|
3533
3467
|
shape[field.name] = field.required ? validator : validator.optional();
|
|
3534
3468
|
}
|
|
3535
3469
|
}
|
|
3536
3470
|
return zod.z.object(shape);
|
|
3537
3471
|
}
|
|
3538
|
-
function
|
|
3472
|
+
function buildArrayItemDefaults(arrayField) {
|
|
3473
|
+
var _a;
|
|
3474
|
+
const item = {};
|
|
3475
|
+
for (const field of arrayField.fields) {
|
|
3476
|
+
item[field.name] = (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3477
|
+
}
|
|
3478
|
+
return item;
|
|
3479
|
+
}
|
|
3480
|
+
function buildDefaultValues(fields) {
|
|
3539
3481
|
var _a;
|
|
3540
3482
|
const values = {};
|
|
3541
|
-
for (const
|
|
3542
|
-
if (
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
childItems = item.children;
|
|
3550
|
-
}
|
|
3551
|
-
if (item.wrapFieldNames && item.name) {
|
|
3552
|
-
values[item.name] = buildDefaultValues(childItems);
|
|
3483
|
+
for (const field of fields) {
|
|
3484
|
+
if (isArrayField(field)) {
|
|
3485
|
+
if (field.defaultValue && field.defaultValue.length > 0) {
|
|
3486
|
+
values[field.name] = field.defaultValue;
|
|
3487
|
+
} else if (field.minItems && field.minItems > 0) {
|
|
3488
|
+
values[field.name] = Array.from({
|
|
3489
|
+
length: field.minItems
|
|
3490
|
+
}, () => buildArrayItemDefaults(field));
|
|
3553
3491
|
} else {
|
|
3554
|
-
|
|
3492
|
+
values[field.name] = [];
|
|
3555
3493
|
}
|
|
3556
3494
|
} else {
|
|
3557
|
-
const field = item;
|
|
3558
3495
|
values[field.name] = (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3559
3496
|
}
|
|
3560
3497
|
}
|
|
3561
3498
|
return values;
|
|
3562
3499
|
}
|
|
3563
|
-
function getItemKey(item, index) {
|
|
3564
|
-
if (isLayoutBlock(item)) {
|
|
3565
|
-
return `layout-${item.type}-${index}`;
|
|
3566
|
-
}
|
|
3567
|
-
return item.name;
|
|
3568
|
-
}
|
|
3569
|
-
function extractFields(items) {
|
|
3570
|
-
const fields = [];
|
|
3571
|
-
for (const item of items) {
|
|
3572
|
-
if (isLayoutBlock(item)) {
|
|
3573
|
-
let childItems = [];
|
|
3574
|
-
if (item.type === 'columns') {
|
|
3575
|
-
for (const column of item.columns) {
|
|
3576
|
-
childItems.push(...column.children);
|
|
3577
|
-
}
|
|
3578
|
-
} else if (item.type === 'section') {
|
|
3579
|
-
childItems = item.children;
|
|
3580
|
-
}
|
|
3581
|
-
fields.push(...extractFields(childItems));
|
|
3582
|
-
} else {
|
|
3583
|
-
fields.push(item);
|
|
3584
|
-
}
|
|
3585
|
-
}
|
|
3586
|
-
return fields;
|
|
3587
|
-
}
|
|
3588
|
-
function extractLayouts(items) {
|
|
3589
|
-
const layouts = [];
|
|
3590
|
-
items.forEach((item, index) => {
|
|
3591
|
-
if (isLayoutBlock(item)) {
|
|
3592
|
-
layouts.push({
|
|
3593
|
-
layout: item,
|
|
3594
|
-
index
|
|
3595
|
-
});
|
|
3596
|
-
}
|
|
3597
|
-
});
|
|
3598
|
-
return layouts;
|
|
3599
|
-
}
|
|
3600
3500
|
|
|
3601
3501
|
function hasSchema(props) {
|
|
3602
3502
|
return props.schema !== undefined;
|
|
@@ -3667,47 +3567,48 @@ function FormGeneratorImpl(props) {
|
|
|
3667
3567
|
form: form
|
|
3668
3568
|
}), [form, handleSubmit, mergedDefaultValues]);
|
|
3669
3569
|
const SubmitButton = getFormComponent('SubmitButton');
|
|
3570
|
+
const FieldWrapper = getFormComponent('FieldWrapper');
|
|
3571
|
+
const FieldsWrapper = getFormComponent('FieldsWrapper');
|
|
3572
|
+
const {
|
|
3573
|
+
regularFields,
|
|
3574
|
+
arrayFields
|
|
3575
|
+
} = React.useMemo(() => {
|
|
3576
|
+
const regular = [];
|
|
3577
|
+
const arrays = [];
|
|
3578
|
+
fields.forEach(field => {
|
|
3579
|
+
if (isArrayField(field)) {
|
|
3580
|
+
arrays.push(field);
|
|
3581
|
+
} else {
|
|
3582
|
+
regular.push(field);
|
|
3583
|
+
}
|
|
3584
|
+
});
|
|
3585
|
+
return {
|
|
3586
|
+
regularFields: regular,
|
|
3587
|
+
arrayFields: arrays
|
|
3588
|
+
};
|
|
3589
|
+
}, [fields]);
|
|
3670
3590
|
const fieldEntries = React.useMemo(() => {
|
|
3671
3591
|
const entries = new Map();
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3592
|
+
regularFields.forEach((field_0, index) => {
|
|
3593
|
+
if (!field_0.hidden) {
|
|
3594
|
+
const element = jsxRuntime.jsx(FieldWrapper, {
|
|
3595
|
+
name: field_0.name,
|
|
3596
|
+
type: field_0.type,
|
|
3597
|
+
className: field_0.className,
|
|
3598
|
+
children: jsxRuntime.jsx(FieldRenderer, {
|
|
3599
|
+
field: field_0
|
|
3600
|
+
})
|
|
3601
|
+
}, field_0.name || `field-${index}`);
|
|
3602
|
+
entries.set(field_0.name, {
|
|
3603
|
+
field: field_0,
|
|
3680
3604
|
element,
|
|
3681
3605
|
accessed: false
|
|
3682
3606
|
});
|
|
3683
3607
|
}
|
|
3684
3608
|
});
|
|
3685
3609
|
return entries;
|
|
3686
|
-
}, [
|
|
3687
|
-
const layoutEntries = React.useMemo(() => {
|
|
3688
|
-
const entries_0 = new Map();
|
|
3689
|
-
const allLayouts = extractLayouts(fields);
|
|
3690
|
-
allLayouts.forEach(({
|
|
3691
|
-
layout,
|
|
3692
|
-
index: index_0
|
|
3693
|
-
}) => {
|
|
3694
|
-
if (!layout.hidden) {
|
|
3695
|
-
const key_0 = layout.name || `layout-${layout.type}-${index_0}`;
|
|
3696
|
-
const element_0 = jsxRuntime.jsx(FormItemRenderer, {
|
|
3697
|
-
item: layout
|
|
3698
|
-
}, key_0);
|
|
3699
|
-
if (layout.name) {
|
|
3700
|
-
entries_0.set(layout.name, {
|
|
3701
|
-
layout,
|
|
3702
|
-
element: element_0
|
|
3703
|
-
});
|
|
3704
|
-
}
|
|
3705
|
-
}
|
|
3706
|
-
});
|
|
3707
|
-
return entries_0;
|
|
3708
|
-
}, [fields]);
|
|
3610
|
+
}, [regularFields, FieldWrapper]);
|
|
3709
3611
|
const templateFields = React.useMemo(() => createTemplateFields(fieldEntries), [fieldEntries]);
|
|
3710
|
-
const templateLayouts = React.useMemo(() => createTemplateLayouts(layoutEntries), [layoutEntries]);
|
|
3711
3612
|
const buttons = React.useMemo(() => {
|
|
3712
3613
|
const result = {
|
|
3713
3614
|
submit: jsxRuntime.jsx(SubmitButton, {
|
|
@@ -3726,18 +3627,12 @@ function FormGeneratorImpl(props) {
|
|
|
3726
3627
|
}
|
|
3727
3628
|
return result;
|
|
3728
3629
|
}, [SubmitButton, disabled, form.formState.isSubmitting, submitText, showReset, resetText, handleReset]);
|
|
3729
|
-
const renderField = React.useCallback((
|
|
3630
|
+
const renderField = React.useCallback((field_1, options) => {
|
|
3730
3631
|
return jsxRuntime.jsx(FieldRenderer, {
|
|
3731
|
-
field:
|
|
3632
|
+
field: field_1,
|
|
3732
3633
|
namePrefix: options === null || options === void 0 ? void 0 : options.namePrefix
|
|
3733
3634
|
});
|
|
3734
3635
|
}, []);
|
|
3735
|
-
const renderLayout = React.useCallback((layout_0, options_0) => {
|
|
3736
|
-
return jsxRuntime.jsx(FormItemRenderer, {
|
|
3737
|
-
item: layout_0,
|
|
3738
|
-
namePrefix: options_0 === null || options_0 === void 0 ? void 0 : options_0.namePrefix
|
|
3739
|
-
});
|
|
3740
|
-
}, []);
|
|
3741
3636
|
if (!children) {
|
|
3742
3637
|
return jsxRuntime.jsx(FormProvider, {
|
|
3743
3638
|
...form,
|
|
@@ -3745,9 +3640,23 @@ function FormGeneratorImpl(props) {
|
|
|
3745
3640
|
ref: formRef,
|
|
3746
3641
|
onSubmit: handleSubmit,
|
|
3747
3642
|
className: className,
|
|
3748
|
-
children: [
|
|
3749
|
-
|
|
3750
|
-
|
|
3643
|
+
children: [jsxRuntime.jsxs(FieldsWrapper, {
|
|
3644
|
+
children: [regularFields.map((field_2, index_0) => jsxRuntime.jsx(FieldWrapper, {
|
|
3645
|
+
name: field_2.name,
|
|
3646
|
+
type: field_2.type,
|
|
3647
|
+
className: field_2.className,
|
|
3648
|
+
children: jsxRuntime.jsx(FieldRenderer, {
|
|
3649
|
+
field: field_2
|
|
3650
|
+
})
|
|
3651
|
+
}, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsxRuntime.jsx(FieldWrapper, {
|
|
3652
|
+
name: arrayField.name,
|
|
3653
|
+
type: "array",
|
|
3654
|
+
className: arrayField.className,
|
|
3655
|
+
children: jsxRuntime.jsx(ArrayFieldRenderer, {
|
|
3656
|
+
field: arrayField
|
|
3657
|
+
})
|
|
3658
|
+
}, arrayField.name))]
|
|
3659
|
+
}), jsxRuntime.jsx(SubmitButton, {
|
|
3751
3660
|
disabled: disabled || form.formState.isSubmitting,
|
|
3752
3661
|
isSubmitting: form.formState.isSubmitting,
|
|
3753
3662
|
children: submitText
|
|
@@ -3757,7 +3666,9 @@ function FormGeneratorImpl(props) {
|
|
|
3757
3666
|
}
|
|
3758
3667
|
const renderProps = {
|
|
3759
3668
|
fields: templateFields,
|
|
3760
|
-
|
|
3669
|
+
arrays: Object.fromEntries(arrayFields.map(arrayField_0 => [arrayField_0.name, {
|
|
3670
|
+
field: arrayField_0
|
|
3671
|
+
}])),
|
|
3761
3672
|
buttons,
|
|
3762
3673
|
title,
|
|
3763
3674
|
description,
|
|
@@ -3766,7 +3677,8 @@ function FormGeneratorImpl(props) {
|
|
|
3766
3677
|
isValid: form.formState.isValid,
|
|
3767
3678
|
isDirty: form.formState.isDirty,
|
|
3768
3679
|
renderField,
|
|
3769
|
-
|
|
3680
|
+
FieldWrapper,
|
|
3681
|
+
FieldsWrapper
|
|
3770
3682
|
};
|
|
3771
3683
|
const renderFn = children;
|
|
3772
3684
|
return jsxRuntime.jsx(FormProvider, {
|
|
@@ -3787,6 +3699,7 @@ Object.defineProperty(exports, "z", {
|
|
|
3787
3699
|
enumerable: true,
|
|
3788
3700
|
get: function () { return zod.z; }
|
|
3789
3701
|
});
|
|
3702
|
+
exports.ArrayFieldRenderer = ArrayFieldRenderer;
|
|
3790
3703
|
exports.Controller = Controller;
|
|
3791
3704
|
exports.FieldRenderer = FieldRenderer;
|
|
3792
3705
|
exports.FormGenerator = FormGenerator;
|
|
@@ -3794,24 +3707,20 @@ exports.FormProvider = FormProvider;
|
|
|
3794
3707
|
exports.clearAllRegistries = clearAllRegistries;
|
|
3795
3708
|
exports.clearFieldRegistry = clearFieldRegistry;
|
|
3796
3709
|
exports.clearFormComponentRegistry = clearFormComponentRegistry;
|
|
3797
|
-
exports.clearLayoutRegistry = clearLayoutRegistry;
|
|
3798
3710
|
exports.getFieldComponent = getFieldComponent;
|
|
3799
3711
|
exports.getFormComponent = getFormComponent;
|
|
3800
3712
|
exports.getFormComponents = getFormComponents;
|
|
3801
|
-
exports.getLayoutComponent = getLayoutComponent;
|
|
3802
3713
|
exports.getRegisteredFieldTypes = getRegisteredFieldTypes;
|
|
3803
3714
|
exports.hasFieldType = hasFieldType;
|
|
3804
3715
|
exports.hasFormComponent = hasFormComponent;
|
|
3805
|
-
exports.
|
|
3806
|
-
exports.isLayoutBlock = isLayoutBlock;
|
|
3716
|
+
exports.isArrayField = isArrayField;
|
|
3807
3717
|
exports.registerField = registerField;
|
|
3808
3718
|
exports.registerFields = registerFields;
|
|
3809
3719
|
exports.registerFormComponent = registerFormComponent;
|
|
3810
3720
|
exports.registerFormComponents = registerFormComponents;
|
|
3811
|
-
exports.registerLayoutComponent = registerLayoutComponent;
|
|
3812
|
-
exports.registerLayoutComponents = registerLayoutComponents;
|
|
3813
3721
|
exports.resetFormComponentRegistry = resetFormComponentRegistry;
|
|
3814
3722
|
exports.unregisterField = unregisterField;
|
|
3723
|
+
exports.useArrayField = useArrayField;
|
|
3815
3724
|
exports.useFieldArray = useFieldArray;
|
|
3816
3725
|
exports.useForm = useForm;
|
|
3817
3726
|
exports.useFormContext = useFormContext;
|