@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createElement, memo, useRef, useMemo,
|
|
1
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
2
|
+
import React, { createElement, Fragment, memo, useCallback, useRef, useMemo, useImperativeHandle } from 'react';
|
|
3
3
|
import * as n$1 from 'zod/v4/core';
|
|
4
4
|
import { c } from 'react/compiler-runtime';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -2772,52 +2772,13 @@ const r=(t,r,o)=>{if(t&&"reportValidity"in t){const s=get(o,r);t.setCustomValidi
|
|
|
2772
2772
|
|
|
2773
2773
|
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$1.parse:n$1.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$1.$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")}
|
|
2774
2774
|
|
|
2775
|
-
function
|
|
2776
|
-
return
|
|
2775
|
+
function isArrayField(field) {
|
|
2776
|
+
return field.type === 'array' && 'fields' in field;
|
|
2777
2777
|
}
|
|
2778
2778
|
|
|
2779
2779
|
const fieldRegistry = new Map();
|
|
2780
2780
|
const componentRegistry = {};
|
|
2781
|
-
const layoutRegistry = {};
|
|
2782
2781
|
const defaultFormComponents = {
|
|
2783
|
-
FormItem: ({
|
|
2784
|
-
className,
|
|
2785
|
-
children
|
|
2786
|
-
}) => /*#__PURE__*/createElement('div', {
|
|
2787
|
-
className: className !== null && className !== void 0 ? className : 'form-item'
|
|
2788
|
-
}, children),
|
|
2789
|
-
FormInputLabelWrapper: ({
|
|
2790
|
-
className,
|
|
2791
|
-
orientation,
|
|
2792
|
-
children
|
|
2793
|
-
}) => /*#__PURE__*/createElement('div', {
|
|
2794
|
-
'className': className !== null && className !== void 0 ? className : 'form-input-label-wrapper',
|
|
2795
|
-
'data-orientation': orientation !== null && orientation !== void 0 ? orientation : 'vertical'
|
|
2796
|
-
}, children),
|
|
2797
|
-
FormLabel: ({
|
|
2798
|
-
className,
|
|
2799
|
-
children,
|
|
2800
|
-
required,
|
|
2801
|
-
htmlFor
|
|
2802
|
-
}) => /*#__PURE__*/createElement('label', {
|
|
2803
|
-
className: className !== null && className !== void 0 ? className : 'form-label',
|
|
2804
|
-
htmlFor
|
|
2805
|
-
}, children, required && /*#__PURE__*/createElement('span', {
|
|
2806
|
-
className: 'required-indicator'
|
|
2807
|
-
}, ' *')),
|
|
2808
|
-
FormDescription: ({
|
|
2809
|
-
className,
|
|
2810
|
-
children
|
|
2811
|
-
}) => /*#__PURE__*/createElement('p', {
|
|
2812
|
-
className: className !== null && className !== void 0 ? className : 'form-description'
|
|
2813
|
-
}, children),
|
|
2814
|
-
FormMessage: ({
|
|
2815
|
-
className,
|
|
2816
|
-
name
|
|
2817
|
-
}) => /*#__PURE__*/createElement('p', {
|
|
2818
|
-
'className': className !== null && className !== void 0 ? className : 'form-message',
|
|
2819
|
-
'data-field': name
|
|
2820
|
-
}),
|
|
2821
2782
|
SubmitButton: ({
|
|
2822
2783
|
className,
|
|
2823
2784
|
children,
|
|
@@ -2827,7 +2788,13 @@ const defaultFormComponents = {
|
|
|
2827
2788
|
type: 'submit',
|
|
2828
2789
|
className: className !== null && className !== void 0 ? className : 'form-submit',
|
|
2829
2790
|
disabled: disabled || isSubmitting
|
|
2830
|
-
}, isSubmitting ? 'Submitting...' : children)
|
|
2791
|
+
}, isSubmitting ? 'Submitting...' : children),
|
|
2792
|
+
FieldWrapper: ({
|
|
2793
|
+
children
|
|
2794
|
+
}) => /*#__PURE__*/createElement(Fragment, null, children),
|
|
2795
|
+
FieldsWrapper: ({
|
|
2796
|
+
children
|
|
2797
|
+
}) => /*#__PURE__*/createElement(Fragment, null, children)
|
|
2831
2798
|
};
|
|
2832
2799
|
const htmlInputTypes = {
|
|
2833
2800
|
text: 'text',
|
|
@@ -3012,10 +2979,6 @@ function getFieldComponent(type) {
|
|
|
3012
2979
|
}
|
|
3013
2980
|
return createDefaultFieldComponent(type);
|
|
3014
2981
|
}
|
|
3015
|
-
function getFieldOptions(type) {
|
|
3016
|
-
var _a;
|
|
3017
|
-
return (_a = fieldRegistry.get(type)) === null || _a === void 0 ? void 0 : _a.options;
|
|
3018
|
-
}
|
|
3019
2982
|
function getFieldValidator(type) {
|
|
3020
2983
|
var _a;
|
|
3021
2984
|
return (_a = fieldRegistry.get(type)) === null || _a === void 0 ? void 0 : _a.options.validator;
|
|
@@ -3061,37 +3024,6 @@ function getFormComponents() {
|
|
|
3061
3024
|
...componentRegistry
|
|
3062
3025
|
};
|
|
3063
3026
|
}
|
|
3064
|
-
function registerLayoutComponents(components, config = {}) {
|
|
3065
|
-
const {
|
|
3066
|
-
override = true
|
|
3067
|
-
} = config;
|
|
3068
|
-
Object.keys(components).forEach(key => {
|
|
3069
|
-
const exists = key in layoutRegistry;
|
|
3070
|
-
if (override === 'only' && !exists) return;
|
|
3071
|
-
if (override === false && exists) return;
|
|
3072
|
-
layoutRegistry[key] = components[key];
|
|
3073
|
-
});
|
|
3074
|
-
}
|
|
3075
|
-
function registerLayoutComponent(name, component, config = {}) {
|
|
3076
|
-
const {
|
|
3077
|
-
override = true
|
|
3078
|
-
} = config;
|
|
3079
|
-
const exists = name in layoutRegistry;
|
|
3080
|
-
if (override === 'only' && !exists) return;
|
|
3081
|
-
if (override === false && exists) return;
|
|
3082
|
-
layoutRegistry[name] = component;
|
|
3083
|
-
}
|
|
3084
|
-
function getLayoutComponent(name) {
|
|
3085
|
-
return layoutRegistry[name];
|
|
3086
|
-
}
|
|
3087
|
-
function hasLayoutComponent(name) {
|
|
3088
|
-
return name in layoutRegistry;
|
|
3089
|
-
}
|
|
3090
|
-
function clearLayoutRegistry() {
|
|
3091
|
-
Object.keys(layoutRegistry).forEach(key => {
|
|
3092
|
-
delete layoutRegistry[key];
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
3027
|
function clearFieldRegistry() {
|
|
3096
3028
|
fieldRegistry.clear();
|
|
3097
3029
|
}
|
|
@@ -3107,106 +3039,6 @@ function resetFormComponentRegistry() {
|
|
|
3107
3039
|
function clearAllRegistries() {
|
|
3108
3040
|
clearFieldRegistry();
|
|
3109
3041
|
clearFormComponentRegistry();
|
|
3110
|
-
clearLayoutRegistry();
|
|
3111
|
-
}
|
|
3112
|
-
|
|
3113
|
-
const RESERVED_PROPS = new Set(['all', 'remaining', 'names', 'has', 'render']);
|
|
3114
|
-
function createTemplateFields(fieldEntries) {
|
|
3115
|
-
const accessedFields = new Set();
|
|
3116
|
-
const handler = {
|
|
3117
|
-
get(_, prop) {
|
|
3118
|
-
if (typeof prop === 'symbol') {
|
|
3119
|
-
return undefined;
|
|
3120
|
-
}
|
|
3121
|
-
if (prop === 'all') {
|
|
3122
|
-
return Array.from(fieldEntries.values()).map(entry => entry.element);
|
|
3123
|
-
}
|
|
3124
|
-
if (prop === 'remaining') {
|
|
3125
|
-
return Array.from(fieldEntries.entries()).filter(([name]) => !accessedFields.has(name)).map(([, entry]) => entry.element);
|
|
3126
|
-
}
|
|
3127
|
-
if (prop === 'names') {
|
|
3128
|
-
return Array.from(fieldEntries.keys());
|
|
3129
|
-
}
|
|
3130
|
-
if (prop === 'has') {
|
|
3131
|
-
return name => fieldEntries.has(name);
|
|
3132
|
-
}
|
|
3133
|
-
if (prop === 'render') {
|
|
3134
|
-
return (...names) => {
|
|
3135
|
-
return names.filter(name => fieldEntries.has(name)).map(name => {
|
|
3136
|
-
accessedFields.add(name);
|
|
3137
|
-
return fieldEntries.get(name).element;
|
|
3138
|
-
});
|
|
3139
|
-
};
|
|
3140
|
-
}
|
|
3141
|
-
if (fieldEntries.has(prop)) {
|
|
3142
|
-
accessedFields.add(prop);
|
|
3143
|
-
return fieldEntries.get(prop).element;
|
|
3144
|
-
}
|
|
3145
|
-
return undefined;
|
|
3146
|
-
},
|
|
3147
|
-
has(_, prop) {
|
|
3148
|
-
if (typeof prop === 'symbol') {
|
|
3149
|
-
return false;
|
|
3150
|
-
}
|
|
3151
|
-
return RESERVED_PROPS.has(prop) || fieldEntries.has(prop);
|
|
3152
|
-
},
|
|
3153
|
-
ownKeys() {
|
|
3154
|
-
return [...RESERVED_PROPS, ...fieldEntries.keys()];
|
|
3155
|
-
},
|
|
3156
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
3157
|
-
if (typeof prop === 'symbol') {
|
|
3158
|
-
return undefined;
|
|
3159
|
-
}
|
|
3160
|
-
if (RESERVED_PROPS.has(prop) || fieldEntries.has(prop)) {
|
|
3161
|
-
return {
|
|
3162
|
-
configurable: true,
|
|
3163
|
-
enumerable: true,
|
|
3164
|
-
value: this.get(_, prop, {})
|
|
3165
|
-
};
|
|
3166
|
-
}
|
|
3167
|
-
return undefined;
|
|
3168
|
-
}
|
|
3169
|
-
};
|
|
3170
|
-
return new Proxy({}, handler);
|
|
3171
|
-
}
|
|
3172
|
-
function createTemplateLayouts(layoutEntries) {
|
|
3173
|
-
const handler = {
|
|
3174
|
-
get(_, prop) {
|
|
3175
|
-
if (typeof prop === 'symbol') {
|
|
3176
|
-
return undefined;
|
|
3177
|
-
}
|
|
3178
|
-
if (prop === 'all') {
|
|
3179
|
-
return Array.from(layoutEntries.values()).map(entry => entry.element);
|
|
3180
|
-
}
|
|
3181
|
-
if (layoutEntries.has(prop)) {
|
|
3182
|
-
return layoutEntries.get(prop).element;
|
|
3183
|
-
}
|
|
3184
|
-
return undefined;
|
|
3185
|
-
},
|
|
3186
|
-
has(_, prop) {
|
|
3187
|
-
if (typeof prop === 'symbol') {
|
|
3188
|
-
return false;
|
|
3189
|
-
}
|
|
3190
|
-
return prop === 'all' || layoutEntries.has(prop);
|
|
3191
|
-
},
|
|
3192
|
-
ownKeys() {
|
|
3193
|
-
return ['all', ...layoutEntries.keys()];
|
|
3194
|
-
},
|
|
3195
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
3196
|
-
if (typeof prop === 'symbol') {
|
|
3197
|
-
return undefined;
|
|
3198
|
-
}
|
|
3199
|
-
if (prop === 'all' || layoutEntries.has(prop)) {
|
|
3200
|
-
return {
|
|
3201
|
-
configurable: true,
|
|
3202
|
-
enumerable: true,
|
|
3203
|
-
value: this.get(_, prop, {})
|
|
3204
|
-
};
|
|
3205
|
-
}
|
|
3206
|
-
return undefined;
|
|
3207
|
-
}
|
|
3208
|
-
};
|
|
3209
|
-
return new Proxy({}, handler);
|
|
3210
3042
|
}
|
|
3211
3043
|
|
|
3212
3044
|
const FieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
@@ -3234,18 +3066,6 @@ const FieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
|
3234
3066
|
t2 = null;
|
|
3235
3067
|
break bb0;
|
|
3236
3068
|
}
|
|
3237
|
-
const FormItemComponent = getFormComponent("FormItem");
|
|
3238
|
-
const FormLabelComponent = getFormComponent("FormLabel");
|
|
3239
|
-
const FormInputLabelWrapper = getFormComponent("FormInputLabelWrapper");
|
|
3240
|
-
const FormDescriptionComponent = getFormComponent("FormDescription");
|
|
3241
|
-
const FormMessageComponent = getFormComponent("FormMessage");
|
|
3242
|
-
if (!FormItemComponent) {
|
|
3243
|
-
console.warn("FormItem component not registered. Use registerFormComponent(\"FormItem\", Component) to register one.");
|
|
3244
|
-
t2 = null;
|
|
3245
|
-
break bb0;
|
|
3246
|
-
}
|
|
3247
|
-
const fieldOptions = getFieldOptions(field.type);
|
|
3248
|
-
const itemClassName = [`form-field-${field.type}`, fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.className, field.className].filter(Boolean).join(" ");
|
|
3249
3069
|
const fieldName = namePrefix ? `${namePrefix}.${field.name}` : field.name;
|
|
3250
3070
|
t1 = jsx(Controller, {
|
|
3251
3071
|
control: form.control,
|
|
@@ -3255,36 +3075,18 @@ const FieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
|
3255
3075
|
field: formField,
|
|
3256
3076
|
fieldState
|
|
3257
3077
|
} = t3;
|
|
3258
|
-
return
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
orientation: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.inputLabelWrapperOrientation,
|
|
3262
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.inputLabelWrapper,
|
|
3263
|
-
children: [field.label && FormLabelComponent && jsx(FormLabelComponent, {
|
|
3264
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.labelClassName,
|
|
3265
|
-
required: field.required,
|
|
3266
|
-
htmlFor: fieldName,
|
|
3267
|
-
children: field.label
|
|
3268
|
-
}), jsx(FieldComponent, {
|
|
3269
|
-
field: {
|
|
3270
|
-
...field,
|
|
3271
|
-
name: fieldName
|
|
3272
|
-
},
|
|
3273
|
-
formField,
|
|
3274
|
-
fieldState: {
|
|
3275
|
-
invalid: fieldState.invalid,
|
|
3276
|
-
error: fieldState.error,
|
|
3277
|
-
isDirty: fieldState.isDirty,
|
|
3278
|
-
isTouched: fieldState.isTouched
|
|
3279
|
-
}
|
|
3280
|
-
})]
|
|
3281
|
-
}), field.description && FormDescriptionComponent && jsx(FormDescriptionComponent, {
|
|
3282
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.descriptionClassName,
|
|
3283
|
-
children: field.description
|
|
3284
|
-
}), FormMessageComponent && jsx(FormMessageComponent, {
|
|
3285
|
-
className: fieldOptions === null || fieldOptions === void 0 ? void 0 : fieldOptions.messageClassName,
|
|
3078
|
+
return jsx(FieldComponent, {
|
|
3079
|
+
field: {
|
|
3080
|
+
...field,
|
|
3286
3081
|
name: fieldName
|
|
3287
|
-
}
|
|
3082
|
+
},
|
|
3083
|
+
formField,
|
|
3084
|
+
fieldState: {
|
|
3085
|
+
invalid: fieldState.invalid,
|
|
3086
|
+
error: fieldState.error,
|
|
3087
|
+
isDirty: fieldState.isDirty,
|
|
3088
|
+
isTouched: fieldState.isTouched
|
|
3089
|
+
}
|
|
3288
3090
|
});
|
|
3289
3091
|
}
|
|
3290
3092
|
});
|
|
@@ -3304,134 +3106,267 @@ const FieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
|
3304
3106
|
return t1;
|
|
3305
3107
|
});
|
|
3306
3108
|
FieldRenderer.displayName = 'FieldRenderer';
|
|
3307
|
-
|
|
3308
|
-
|
|
3109
|
+
|
|
3110
|
+
function useArrayField(field) {
|
|
3309
3111
|
const {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3112
|
+
control
|
|
3113
|
+
} = useFormContext();
|
|
3114
|
+
const fieldArray = useFieldArray({
|
|
3115
|
+
control,
|
|
3116
|
+
name: field.name
|
|
3117
|
+
});
|
|
3118
|
+
const {
|
|
3119
|
+
fields: items,
|
|
3120
|
+
append,
|
|
3121
|
+
prepend,
|
|
3122
|
+
remove,
|
|
3123
|
+
move,
|
|
3124
|
+
swap,
|
|
3125
|
+
insert
|
|
3126
|
+
} = fieldArray;
|
|
3127
|
+
const buildEmptyItem = useCallback(() => {
|
|
3128
|
+
const item = {};
|
|
3129
|
+
field.fields.forEach(f => {
|
|
3130
|
+
var _a;
|
|
3131
|
+
item[f.name] = (_a = f.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3132
|
+
});
|
|
3133
|
+
return item;
|
|
3134
|
+
}, [field.fields]);
|
|
3135
|
+
const handleAppend = useCallback(() => {
|
|
3136
|
+
append(buildEmptyItem());
|
|
3137
|
+
}, [append, buildEmptyItem]);
|
|
3138
|
+
const handleAppendWith = useCallback(values => {
|
|
3139
|
+
append(values);
|
|
3140
|
+
}, [append]);
|
|
3141
|
+
const handlePrepend = useCallback(() => {
|
|
3142
|
+
prepend(buildEmptyItem());
|
|
3143
|
+
}, [prepend, buildEmptyItem]);
|
|
3144
|
+
const handleInsert = useCallback((index, values_0) => {
|
|
3145
|
+
insert(index, values_0 !== null && values_0 !== void 0 ? values_0 : buildEmptyItem());
|
|
3146
|
+
}, [insert, buildEmptyItem]);
|
|
3147
|
+
const canAppend = field.maxItems === undefined || items.length < field.maxItems;
|
|
3148
|
+
const canRemove = field.minItems === undefined || items.length > field.minItems;
|
|
3149
|
+
const renderField = useCallback((index_0, fieldName) => {
|
|
3150
|
+
const childField = field.fields.find(f_0 => f_0.name === fieldName);
|
|
3151
|
+
if (!childField) {
|
|
3152
|
+
console.warn(`Field "${fieldName}" not found in array field "${field.name}"`);
|
|
3153
|
+
return jsx(Fragment$1, {});
|
|
3341
3154
|
}
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
}
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
});
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3155
|
+
return jsx(FieldRenderer, {
|
|
3156
|
+
field: childField,
|
|
3157
|
+
namePrefix: `${field.name}.${index_0}`
|
|
3158
|
+
}, `${field.name}.${index_0}.${fieldName}`);
|
|
3159
|
+
}, [field]);
|
|
3160
|
+
const renderItem = useCallback(index_1 => {
|
|
3161
|
+
const result = {};
|
|
3162
|
+
field.fields.forEach(childField_0 => {
|
|
3163
|
+
result[childField_0.name] = jsx(FieldRenderer, {
|
|
3164
|
+
field: childField_0,
|
|
3165
|
+
namePrefix: `${field.name}.${index_1}`
|
|
3166
|
+
}, `${field.name}.${index_1}.${childField_0.name}`);
|
|
3167
|
+
});
|
|
3168
|
+
return result;
|
|
3169
|
+
}, [field]);
|
|
3170
|
+
return {
|
|
3171
|
+
fieldArray,
|
|
3172
|
+
append: handleAppend,
|
|
3173
|
+
appendWith: handleAppendWith,
|
|
3174
|
+
prepend: handlePrepend,
|
|
3175
|
+
remove,
|
|
3176
|
+
move,
|
|
3177
|
+
swap,
|
|
3178
|
+
insert: handleInsert,
|
|
3179
|
+
field,
|
|
3180
|
+
items: items.map((item_0, index_2) => ({
|
|
3181
|
+
id: item_0.id,
|
|
3182
|
+
index: index_2
|
|
3183
|
+
})),
|
|
3184
|
+
canAppend,
|
|
3185
|
+
canRemove,
|
|
3186
|
+
renderField,
|
|
3187
|
+
renderItem
|
|
3188
|
+
};
|
|
3189
|
+
}
|
|
3190
|
+
const ArrayFieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
3191
|
+
const $ = c(28);
|
|
3358
3192
|
const {
|
|
3359
|
-
|
|
3360
|
-
|
|
3193
|
+
field,
|
|
3194
|
+
children
|
|
3361
3195
|
} = t0;
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3196
|
+
const {
|
|
3197
|
+
items,
|
|
3198
|
+
append,
|
|
3199
|
+
remove,
|
|
3200
|
+
move,
|
|
3201
|
+
canAppend,
|
|
3202
|
+
renderItem,
|
|
3203
|
+
field: arrayField
|
|
3204
|
+
} = useArrayField(field);
|
|
3205
|
+
if (field.hidden) {
|
|
3206
|
+
return null;
|
|
3207
|
+
}
|
|
3208
|
+
if (!children) {
|
|
3209
|
+
let t1;
|
|
3210
|
+
if ($[0] !== append || $[1] !== canAppend || $[2] !== field.className || $[3] !== field.description || $[4] !== field.label || $[5] !== items || $[6] !== renderItem) {
|
|
3211
|
+
let t2;
|
|
3212
|
+
if ($[8] !== renderItem) {
|
|
3213
|
+
t2 = t3 => {
|
|
3214
|
+
const {
|
|
3215
|
+
id,
|
|
3216
|
+
index
|
|
3217
|
+
} = t3;
|
|
3218
|
+
return jsx("div", {
|
|
3219
|
+
"data-array-item-index": index,
|
|
3220
|
+
children: Object.values(renderItem(index))
|
|
3221
|
+
}, id);
|
|
3222
|
+
};
|
|
3223
|
+
$[8] = renderItem;
|
|
3224
|
+
$[9] = t2;
|
|
3382
3225
|
} else {
|
|
3383
|
-
|
|
3226
|
+
t2 = $[9];
|
|
3384
3227
|
}
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3228
|
+
t1 = jsxs("div", {
|
|
3229
|
+
className: field.className,
|
|
3230
|
+
children: [field.label && jsx("label", {
|
|
3231
|
+
children: field.label
|
|
3232
|
+
}), field.description && jsx("p", {
|
|
3233
|
+
children: field.description
|
|
3234
|
+
}), items.map(t2), canAppend && jsx("button", {
|
|
3235
|
+
type: "button",
|
|
3236
|
+
onClick: append,
|
|
3237
|
+
children: "Add Item"
|
|
3238
|
+
})]
|
|
3389
3239
|
});
|
|
3240
|
+
$[0] = append;
|
|
3241
|
+
$[1] = canAppend;
|
|
3242
|
+
$[2] = field.className;
|
|
3243
|
+
$[3] = field.description;
|
|
3244
|
+
$[4] = field.label;
|
|
3245
|
+
$[5] = items;
|
|
3246
|
+
$[6] = renderItem;
|
|
3247
|
+
$[7] = t1;
|
|
3248
|
+
} else {
|
|
3249
|
+
t1 = $[7];
|
|
3390
3250
|
}
|
|
3391
|
-
|
|
3392
|
-
$[1] = namePrefix;
|
|
3393
|
-
$[2] = t1;
|
|
3394
|
-
$[3] = t2;
|
|
3395
|
-
} else {
|
|
3396
|
-
t1 = $[2];
|
|
3397
|
-
t2 = $[3];
|
|
3251
|
+
return t1;
|
|
3398
3252
|
}
|
|
3399
|
-
|
|
3400
|
-
|
|
3253
|
+
let t1;
|
|
3254
|
+
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) {
|
|
3255
|
+
let t2;
|
|
3256
|
+
if ($[21] !== arrayField || $[22] !== children || $[23] !== field.name || $[24] !== move || $[25] !== remove || $[26] !== renderItem) {
|
|
3257
|
+
t2 = t3 => {
|
|
3258
|
+
const {
|
|
3259
|
+
id: id_0,
|
|
3260
|
+
index: index_0
|
|
3261
|
+
} = t3;
|
|
3262
|
+
return children({
|
|
3263
|
+
index: index_0,
|
|
3264
|
+
id: id_0,
|
|
3265
|
+
remove: () => remove(index_0),
|
|
3266
|
+
move: toIndex => move(index_0, toIndex),
|
|
3267
|
+
fields: renderItem(index_0),
|
|
3268
|
+
fieldNames: arrayField.fields.map(_temp),
|
|
3269
|
+
namePrefix: `${field.name}.${index_0}`
|
|
3270
|
+
});
|
|
3271
|
+
};
|
|
3272
|
+
$[21] = arrayField;
|
|
3273
|
+
$[22] = children;
|
|
3274
|
+
$[23] = field.name;
|
|
3275
|
+
$[24] = move;
|
|
3276
|
+
$[25] = remove;
|
|
3277
|
+
$[26] = renderItem;
|
|
3278
|
+
$[27] = t2;
|
|
3279
|
+
} else {
|
|
3280
|
+
t2 = $[27];
|
|
3281
|
+
}
|
|
3282
|
+
t1 = jsxs("div", {
|
|
3283
|
+
className: field.className,
|
|
3284
|
+
children: [field.label && jsx("label", {
|
|
3285
|
+
children: field.label
|
|
3286
|
+
}), field.description && jsx("p", {
|
|
3287
|
+
children: field.description
|
|
3288
|
+
}), items.map(t2)]
|
|
3289
|
+
});
|
|
3290
|
+
$[10] = arrayField;
|
|
3291
|
+
$[11] = children;
|
|
3292
|
+
$[12] = field.className;
|
|
3293
|
+
$[13] = field.description;
|
|
3294
|
+
$[14] = field.label;
|
|
3295
|
+
$[15] = field.name;
|
|
3296
|
+
$[16] = items;
|
|
3297
|
+
$[17] = move;
|
|
3298
|
+
$[18] = remove;
|
|
3299
|
+
$[19] = renderItem;
|
|
3300
|
+
$[20] = t1;
|
|
3301
|
+
} else {
|
|
3302
|
+
t1 = $[20];
|
|
3401
3303
|
}
|
|
3402
3304
|
return t1;
|
|
3403
3305
|
});
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
return
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3306
|
+
ArrayFieldRenderer.displayName = 'ArrayFieldRenderer';
|
|
3307
|
+
function _temp(f) {
|
|
3308
|
+
return f.name;
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
const RESERVED_PROPS = new Set(['all', 'remaining', 'names', 'has', 'render']);
|
|
3312
|
+
function createTemplateFields(fieldEntries) {
|
|
3313
|
+
const accessedFields = new Set();
|
|
3314
|
+
const handler = {
|
|
3315
|
+
get(_, prop) {
|
|
3316
|
+
if (typeof prop === 'symbol') {
|
|
3317
|
+
return undefined;
|
|
3318
|
+
}
|
|
3319
|
+
if (prop === 'all') {
|
|
3320
|
+
return Array.from(fieldEntries.values()).map(entry => entry.element);
|
|
3321
|
+
}
|
|
3322
|
+
if (prop === 'remaining') {
|
|
3323
|
+
return Array.from(fieldEntries.entries()).filter(([name]) => !accessedFields.has(name)).map(([, entry]) => entry.element);
|
|
3324
|
+
}
|
|
3325
|
+
if (prop === 'names') {
|
|
3326
|
+
return Array.from(fieldEntries.keys());
|
|
3327
|
+
}
|
|
3328
|
+
if (prop === 'has') {
|
|
3329
|
+
return name => fieldEntries.has(name);
|
|
3330
|
+
}
|
|
3331
|
+
if (prop === 'render') {
|
|
3332
|
+
return (...names) => {
|
|
3333
|
+
return names.filter(name => fieldEntries.has(name)).map(name => {
|
|
3334
|
+
accessedFields.add(name);
|
|
3335
|
+
return fieldEntries.get(name).element;
|
|
3336
|
+
});
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
if (fieldEntries.has(prop)) {
|
|
3340
|
+
accessedFields.add(prop);
|
|
3341
|
+
return fieldEntries.get(prop).element;
|
|
3342
|
+
}
|
|
3343
|
+
return undefined;
|
|
3344
|
+
},
|
|
3345
|
+
has(_, prop) {
|
|
3346
|
+
if (typeof prop === 'symbol') {
|
|
3347
|
+
return false;
|
|
3348
|
+
}
|
|
3349
|
+
return RESERVED_PROPS.has(prop) || fieldEntries.has(prop);
|
|
3350
|
+
},
|
|
3351
|
+
ownKeys() {
|
|
3352
|
+
return [...RESERVED_PROPS, ...fieldEntries.keys()];
|
|
3353
|
+
},
|
|
3354
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
3355
|
+
if (typeof prop === 'symbol') {
|
|
3356
|
+
return undefined;
|
|
3357
|
+
}
|
|
3358
|
+
if (RESERVED_PROPS.has(prop) || fieldEntries.has(prop)) {
|
|
3359
|
+
return {
|
|
3360
|
+
configurable: true,
|
|
3361
|
+
enumerable: true,
|
|
3362
|
+
value: this.get(_, prop, {})
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
return undefined;
|
|
3427
3366
|
}
|
|
3428
|
-
}
|
|
3429
|
-
return
|
|
3430
|
-
|
|
3431
|
-
namePrefix: namePrefix
|
|
3432
|
-
});
|
|
3433
|
-
});
|
|
3434
|
-
FormItemRenderer.displayName = 'FormItemRenderer';
|
|
3367
|
+
};
|
|
3368
|
+
return new Proxy({}, handler);
|
|
3369
|
+
}
|
|
3435
3370
|
|
|
3436
3371
|
function deepMerge(target, source) {
|
|
3437
3372
|
const result = {
|
|
@@ -3487,96 +3422,61 @@ function getValidatorForField(field) {
|
|
|
3487
3422
|
}
|
|
3488
3423
|
return z.any();
|
|
3489
3424
|
}
|
|
3490
|
-
function
|
|
3425
|
+
function buildArrayItemSchema(arrayField) {
|
|
3426
|
+
const itemShape = {};
|
|
3427
|
+
for (const field of arrayField.fields) {
|
|
3428
|
+
const validator = getValidatorForField(field);
|
|
3429
|
+
itemShape[field.name] = field.required ? validator : validator.optional();
|
|
3430
|
+
}
|
|
3431
|
+
return z.object(itemShape);
|
|
3432
|
+
}
|
|
3433
|
+
function buildSchema(fields) {
|
|
3491
3434
|
const shape = {};
|
|
3492
|
-
for (const
|
|
3493
|
-
if (
|
|
3494
|
-
let
|
|
3495
|
-
if (
|
|
3496
|
-
|
|
3497
|
-
childItems.push(...column.children);
|
|
3498
|
-
}
|
|
3499
|
-
} else if (item.type === 'section') {
|
|
3500
|
-
childItems = item.children;
|
|
3435
|
+
for (const field of fields) {
|
|
3436
|
+
if (isArrayField(field)) {
|
|
3437
|
+
let arraySchema = z.array(buildArrayItemSchema(field));
|
|
3438
|
+
if (field.minItems !== undefined) {
|
|
3439
|
+
arraySchema = arraySchema.min(field.minItems);
|
|
3501
3440
|
}
|
|
3502
|
-
if (
|
|
3503
|
-
|
|
3504
|
-
} else {
|
|
3505
|
-
const childSchema = buildSchema(childItems);
|
|
3506
|
-
if (childSchema instanceof z.ZodObject) {
|
|
3507
|
-
Object.assign(shape, childSchema.shape);
|
|
3508
|
-
}
|
|
3441
|
+
if (field.maxItems !== undefined) {
|
|
3442
|
+
arraySchema = arraySchema.max(field.maxItems);
|
|
3509
3443
|
}
|
|
3444
|
+
shape[field.name] = arraySchema;
|
|
3510
3445
|
} else {
|
|
3511
|
-
const field = item;
|
|
3512
3446
|
const validator = getValidatorForField(field);
|
|
3513
3447
|
shape[field.name] = field.required ? validator : validator.optional();
|
|
3514
3448
|
}
|
|
3515
3449
|
}
|
|
3516
3450
|
return z.object(shape);
|
|
3517
3451
|
}
|
|
3518
|
-
function
|
|
3452
|
+
function buildArrayItemDefaults(arrayField) {
|
|
3453
|
+
var _a;
|
|
3454
|
+
const item = {};
|
|
3455
|
+
for (const field of arrayField.fields) {
|
|
3456
|
+
item[field.name] = (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3457
|
+
}
|
|
3458
|
+
return item;
|
|
3459
|
+
}
|
|
3460
|
+
function buildDefaultValues(fields) {
|
|
3519
3461
|
var _a;
|
|
3520
3462
|
const values = {};
|
|
3521
|
-
for (const
|
|
3522
|
-
if (
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
childItems = item.children;
|
|
3530
|
-
}
|
|
3531
|
-
if (item.wrapFieldNames && item.name) {
|
|
3532
|
-
values[item.name] = buildDefaultValues(childItems);
|
|
3463
|
+
for (const field of fields) {
|
|
3464
|
+
if (isArrayField(field)) {
|
|
3465
|
+
if (field.defaultValue && field.defaultValue.length > 0) {
|
|
3466
|
+
values[field.name] = field.defaultValue;
|
|
3467
|
+
} else if (field.minItems && field.minItems > 0) {
|
|
3468
|
+
values[field.name] = Array.from({
|
|
3469
|
+
length: field.minItems
|
|
3470
|
+
}, () => buildArrayItemDefaults(field));
|
|
3533
3471
|
} else {
|
|
3534
|
-
|
|
3472
|
+
values[field.name] = [];
|
|
3535
3473
|
}
|
|
3536
3474
|
} else {
|
|
3537
|
-
const field = item;
|
|
3538
3475
|
values[field.name] = (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
3539
3476
|
}
|
|
3540
3477
|
}
|
|
3541
3478
|
return values;
|
|
3542
3479
|
}
|
|
3543
|
-
function getItemKey(item, index) {
|
|
3544
|
-
if (isLayoutBlock(item)) {
|
|
3545
|
-
return `layout-${item.type}-${index}`;
|
|
3546
|
-
}
|
|
3547
|
-
return item.name;
|
|
3548
|
-
}
|
|
3549
|
-
function extractFields(items) {
|
|
3550
|
-
const fields = [];
|
|
3551
|
-
for (const item of items) {
|
|
3552
|
-
if (isLayoutBlock(item)) {
|
|
3553
|
-
let childItems = [];
|
|
3554
|
-
if (item.type === 'columns') {
|
|
3555
|
-
for (const column of item.columns) {
|
|
3556
|
-
childItems.push(...column.children);
|
|
3557
|
-
}
|
|
3558
|
-
} else if (item.type === 'section') {
|
|
3559
|
-
childItems = item.children;
|
|
3560
|
-
}
|
|
3561
|
-
fields.push(...extractFields(childItems));
|
|
3562
|
-
} else {
|
|
3563
|
-
fields.push(item);
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3566
|
-
return fields;
|
|
3567
|
-
}
|
|
3568
|
-
function extractLayouts(items) {
|
|
3569
|
-
const layouts = [];
|
|
3570
|
-
items.forEach((item, index) => {
|
|
3571
|
-
if (isLayoutBlock(item)) {
|
|
3572
|
-
layouts.push({
|
|
3573
|
-
layout: item,
|
|
3574
|
-
index
|
|
3575
|
-
});
|
|
3576
|
-
}
|
|
3577
|
-
});
|
|
3578
|
-
return layouts;
|
|
3579
|
-
}
|
|
3580
3480
|
|
|
3581
3481
|
function hasSchema(props) {
|
|
3582
3482
|
return props.schema !== undefined;
|
|
@@ -3647,47 +3547,48 @@ function FormGeneratorImpl(props) {
|
|
|
3647
3547
|
form: form
|
|
3648
3548
|
}), [form, handleSubmit, mergedDefaultValues]);
|
|
3649
3549
|
const SubmitButton = getFormComponent('SubmitButton');
|
|
3550
|
+
const FieldWrapper = getFormComponent('FieldWrapper');
|
|
3551
|
+
const FieldsWrapper = getFormComponent('FieldsWrapper');
|
|
3552
|
+
const {
|
|
3553
|
+
regularFields,
|
|
3554
|
+
arrayFields
|
|
3555
|
+
} = useMemo(() => {
|
|
3556
|
+
const regular = [];
|
|
3557
|
+
const arrays = [];
|
|
3558
|
+
fields.forEach(field => {
|
|
3559
|
+
if (isArrayField(field)) {
|
|
3560
|
+
arrays.push(field);
|
|
3561
|
+
} else {
|
|
3562
|
+
regular.push(field);
|
|
3563
|
+
}
|
|
3564
|
+
});
|
|
3565
|
+
return {
|
|
3566
|
+
regularFields: regular,
|
|
3567
|
+
arrayFields: arrays
|
|
3568
|
+
};
|
|
3569
|
+
}, [fields]);
|
|
3650
3570
|
const fieldEntries = useMemo(() => {
|
|
3651
3571
|
const entries = new Map();
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3572
|
+
regularFields.forEach((field_0, index) => {
|
|
3573
|
+
if (!field_0.hidden) {
|
|
3574
|
+
const element = jsx(FieldWrapper, {
|
|
3575
|
+
name: field_0.name,
|
|
3576
|
+
type: field_0.type,
|
|
3577
|
+
className: field_0.className,
|
|
3578
|
+
children: jsx(FieldRenderer, {
|
|
3579
|
+
field: field_0
|
|
3580
|
+
})
|
|
3581
|
+
}, field_0.name || `field-${index}`);
|
|
3582
|
+
entries.set(field_0.name, {
|
|
3583
|
+
field: field_0,
|
|
3660
3584
|
element,
|
|
3661
3585
|
accessed: false
|
|
3662
3586
|
});
|
|
3663
3587
|
}
|
|
3664
3588
|
});
|
|
3665
3589
|
return entries;
|
|
3666
|
-
}, [
|
|
3667
|
-
const layoutEntries = useMemo(() => {
|
|
3668
|
-
const entries_0 = new Map();
|
|
3669
|
-
const allLayouts = extractLayouts(fields);
|
|
3670
|
-
allLayouts.forEach(({
|
|
3671
|
-
layout,
|
|
3672
|
-
index: index_0
|
|
3673
|
-
}) => {
|
|
3674
|
-
if (!layout.hidden) {
|
|
3675
|
-
const key_0 = layout.name || `layout-${layout.type}-${index_0}`;
|
|
3676
|
-
const element_0 = jsx(FormItemRenderer, {
|
|
3677
|
-
item: layout
|
|
3678
|
-
}, key_0);
|
|
3679
|
-
if (layout.name) {
|
|
3680
|
-
entries_0.set(layout.name, {
|
|
3681
|
-
layout,
|
|
3682
|
-
element: element_0
|
|
3683
|
-
});
|
|
3684
|
-
}
|
|
3685
|
-
}
|
|
3686
|
-
});
|
|
3687
|
-
return entries_0;
|
|
3688
|
-
}, [fields]);
|
|
3590
|
+
}, [regularFields, FieldWrapper]);
|
|
3689
3591
|
const templateFields = useMemo(() => createTemplateFields(fieldEntries), [fieldEntries]);
|
|
3690
|
-
const templateLayouts = useMemo(() => createTemplateLayouts(layoutEntries), [layoutEntries]);
|
|
3691
3592
|
const buttons = useMemo(() => {
|
|
3692
3593
|
const result = {
|
|
3693
3594
|
submit: jsx(SubmitButton, {
|
|
@@ -3706,18 +3607,12 @@ function FormGeneratorImpl(props) {
|
|
|
3706
3607
|
}
|
|
3707
3608
|
return result;
|
|
3708
3609
|
}, [SubmitButton, disabled, form.formState.isSubmitting, submitText, showReset, resetText, handleReset]);
|
|
3709
|
-
const renderField = useCallback((
|
|
3610
|
+
const renderField = useCallback((field_1, options) => {
|
|
3710
3611
|
return jsx(FieldRenderer, {
|
|
3711
|
-
field:
|
|
3612
|
+
field: field_1,
|
|
3712
3613
|
namePrefix: options === null || options === void 0 ? void 0 : options.namePrefix
|
|
3713
3614
|
});
|
|
3714
3615
|
}, []);
|
|
3715
|
-
const renderLayout = useCallback((layout_0, options_0) => {
|
|
3716
|
-
return jsx(FormItemRenderer, {
|
|
3717
|
-
item: layout_0,
|
|
3718
|
-
namePrefix: options_0 === null || options_0 === void 0 ? void 0 : options_0.namePrefix
|
|
3719
|
-
});
|
|
3720
|
-
}, []);
|
|
3721
3616
|
if (!children) {
|
|
3722
3617
|
return jsx(FormProvider, {
|
|
3723
3618
|
...form,
|
|
@@ -3725,9 +3620,23 @@ function FormGeneratorImpl(props) {
|
|
|
3725
3620
|
ref: formRef,
|
|
3726
3621
|
onSubmit: handleSubmit,
|
|
3727
3622
|
className: className,
|
|
3728
|
-
children: [
|
|
3729
|
-
|
|
3730
|
-
|
|
3623
|
+
children: [jsxs(FieldsWrapper, {
|
|
3624
|
+
children: [regularFields.map((field_2, index_0) => jsx(FieldWrapper, {
|
|
3625
|
+
name: field_2.name,
|
|
3626
|
+
type: field_2.type,
|
|
3627
|
+
className: field_2.className,
|
|
3628
|
+
children: jsx(FieldRenderer, {
|
|
3629
|
+
field: field_2
|
|
3630
|
+
})
|
|
3631
|
+
}, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsx(FieldWrapper, {
|
|
3632
|
+
name: arrayField.name,
|
|
3633
|
+
type: "array",
|
|
3634
|
+
className: arrayField.className,
|
|
3635
|
+
children: jsx(ArrayFieldRenderer, {
|
|
3636
|
+
field: arrayField
|
|
3637
|
+
})
|
|
3638
|
+
}, arrayField.name))]
|
|
3639
|
+
}), jsx(SubmitButton, {
|
|
3731
3640
|
disabled: disabled || form.formState.isSubmitting,
|
|
3732
3641
|
isSubmitting: form.formState.isSubmitting,
|
|
3733
3642
|
children: submitText
|
|
@@ -3737,7 +3646,9 @@ function FormGeneratorImpl(props) {
|
|
|
3737
3646
|
}
|
|
3738
3647
|
const renderProps = {
|
|
3739
3648
|
fields: templateFields,
|
|
3740
|
-
|
|
3649
|
+
arrays: Object.fromEntries(arrayFields.map(arrayField_0 => [arrayField_0.name, {
|
|
3650
|
+
field: arrayField_0
|
|
3651
|
+
}])),
|
|
3741
3652
|
buttons,
|
|
3742
3653
|
title,
|
|
3743
3654
|
description,
|
|
@@ -3746,7 +3657,8 @@ function FormGeneratorImpl(props) {
|
|
|
3746
3657
|
isValid: form.formState.isValid,
|
|
3747
3658
|
isDirty: form.formState.isDirty,
|
|
3748
3659
|
renderField,
|
|
3749
|
-
|
|
3660
|
+
FieldWrapper,
|
|
3661
|
+
FieldsWrapper
|
|
3750
3662
|
};
|
|
3751
3663
|
const renderFn = children;
|
|
3752
3664
|
return jsx(FormProvider, {
|
|
@@ -3763,5 +3675,5 @@ function FormGenerator(props) {
|
|
|
3763
3675
|
return FormGeneratorImpl(props);
|
|
3764
3676
|
}
|
|
3765
3677
|
|
|
3766
|
-
export { Controller, FieldRenderer, FormGenerator, FormProvider, clearAllRegistries, clearFieldRegistry, clearFormComponentRegistry,
|
|
3678
|
+
export { ArrayFieldRenderer, Controller, FieldRenderer, FormGenerator, FormProvider, clearAllRegistries, clearFieldRegistry, clearFormComponentRegistry, getFieldComponent, getFormComponent, getFormComponents, getRegisteredFieldTypes, hasFieldType, hasFormComponent, isArrayField, registerField, registerFields, registerFormComponent, registerFormComponents, resetFormComponentRegistry, unregisterField, useArrayField, useFieldArray, useForm, useFormContext, useWatch };
|
|
3767
3679
|
//# sourceMappingURL=index.mjs.map
|