@connect-soft/form-generator 1.1.0-alpha2 → 1.1.0-alpha3
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 +374 -28
- package/dist/index.js +64 -97
- package/dist/index.js.map +1 -1
- package/dist/{index.m.js → index.mjs} +66 -99
- package/dist/index.mjs.map +1 -0
- package/dist/types/components/form/form-generator.d.ts +26 -12
- package/dist/types/components/form/form-generator.d.ts.map +1 -1
- package/dist/types/components/form/index.d.ts +1 -1
- package/dist/types/components/form/index.d.ts.map +1 -1
- package/package.json +11 -25
- package/MIGRATION.md +0 -503
- package/dist/index.m.js.map +0 -1
- package/dist/styles/globals.css +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { c } from 'react/compiler-runtime';
|
|
2
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import React, { createElement, memo } from 'react';
|
|
2
|
+
import React, { createElement, memo, useRef, useMemo, useImperativeHandle } from 'react';
|
|
4
3
|
import * as n$1 from 'zod/v4/core';
|
|
5
4
|
import { z } from 'zod';
|
|
6
5
|
export { z } from 'zod';
|
|
6
|
+
import { c } from 'react/compiler-runtime';
|
|
7
7
|
|
|
8
8
|
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
|
9
9
|
|
|
@@ -3445,114 +3445,81 @@ function getItemKey(item, index) {
|
|
|
3445
3445
|
function hasSchema(props) {
|
|
3446
3446
|
return props.schema !== undefined;
|
|
3447
3447
|
}
|
|
3448
|
-
function
|
|
3449
|
-
const $ = c(20);
|
|
3448
|
+
function FormGeneratorImpl(props) {
|
|
3450
3449
|
const {
|
|
3451
3450
|
fields,
|
|
3452
3451
|
defaultValues,
|
|
3453
3452
|
className,
|
|
3454
|
-
submitText
|
|
3453
|
+
submitText = 'Submit',
|
|
3455
3454
|
disabled,
|
|
3456
|
-
mode
|
|
3455
|
+
mode = 'onChange',
|
|
3456
|
+
ref
|
|
3457
3457
|
} = props;
|
|
3458
|
-
const submitText = t0 === undefined ? "Submit" : t0;
|
|
3459
|
-
const mode = t1 === undefined ? "onChange" : t1;
|
|
3460
3458
|
const userSchema = hasSchema(props) ? props.schema : undefined;
|
|
3461
3459
|
const onSubmit = props.onSubmit;
|
|
3462
|
-
|
|
3463
|
-
|
|
3460
|
+
const formRef = useRef(null);
|
|
3461
|
+
const schema = useMemo(() => {
|
|
3464
3462
|
if (userSchema) {
|
|
3465
|
-
|
|
3466
|
-
break bb0;
|
|
3463
|
+
return userSchema;
|
|
3467
3464
|
}
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
$[0] = fields;
|
|
3472
|
-
$[1] = t3;
|
|
3473
|
-
} else {
|
|
3474
|
-
t3 = $[1];
|
|
3475
|
-
}
|
|
3476
|
-
t2 = t3;
|
|
3477
|
-
}
|
|
3478
|
-
const schema = t2;
|
|
3479
|
-
let t3;
|
|
3480
|
-
if ($[2] !== defaultValues || $[3] !== fields) {
|
|
3465
|
+
return buildSchema(fields);
|
|
3466
|
+
}, [fields, userSchema]);
|
|
3467
|
+
const mergedDefaultValues = useMemo(() => {
|
|
3481
3468
|
const builtDefaults = buildDefaultValues(fields);
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
}
|
|
3489
|
-
const
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
isSubmitting: form.formState.isSubmitting,
|
|
3535
|
-
children: submitText
|
|
3536
|
-
})]
|
|
3537
|
-
})
|
|
3538
|
-
});
|
|
3539
|
-
$[11] = className;
|
|
3540
|
-
$[12] = disabled;
|
|
3541
|
-
$[13] = fields;
|
|
3542
|
-
$[14] = form;
|
|
3543
|
-
$[15] = onSubmit;
|
|
3544
|
-
$[16] = submitText;
|
|
3545
|
-
$[17] = t6;
|
|
3546
|
-
} else {
|
|
3547
|
-
t6 = $[17];
|
|
3548
|
-
}
|
|
3549
|
-
return t6;
|
|
3550
|
-
}
|
|
3551
|
-
function _temp(item, index) {
|
|
3552
|
-
return jsx(FormItemRenderer, {
|
|
3553
|
-
item
|
|
3554
|
-
}, getItemKey(item, index));
|
|
3469
|
+
return defaultValues ? deepMerge(builtDefaults, defaultValues) : builtDefaults;
|
|
3470
|
+
}, [fields, defaultValues]);
|
|
3471
|
+
const form = useForm({
|
|
3472
|
+
resolver: a(schema),
|
|
3473
|
+
defaultValues: mergedDefaultValues,
|
|
3474
|
+
mode
|
|
3475
|
+
});
|
|
3476
|
+
const handleSubmit = form.handleSubmit(async data => {
|
|
3477
|
+
await onSubmit(data);
|
|
3478
|
+
});
|
|
3479
|
+
useImperativeHandle(ref, () => ({
|
|
3480
|
+
setValues: values => {
|
|
3481
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
3482
|
+
form.setValue(key, value, {
|
|
3483
|
+
shouldValidate: true,
|
|
3484
|
+
shouldDirty: true
|
|
3485
|
+
});
|
|
3486
|
+
});
|
|
3487
|
+
},
|
|
3488
|
+
getValues: () => form.getValues(),
|
|
3489
|
+
reset: values_0 => {
|
|
3490
|
+
if (values_0) {
|
|
3491
|
+
form.reset(deepMerge(mergedDefaultValues, values_0));
|
|
3492
|
+
} else {
|
|
3493
|
+
form.reset(mergedDefaultValues);
|
|
3494
|
+
}
|
|
3495
|
+
},
|
|
3496
|
+
submit: async () => {
|
|
3497
|
+
await handleSubmit();
|
|
3498
|
+
},
|
|
3499
|
+
clearErrors: () => form.clearErrors(),
|
|
3500
|
+
setError: (name, error) => form.setError(name, error),
|
|
3501
|
+
isValid: () => form.formState.isValid,
|
|
3502
|
+
isDirty: () => form.formState.isDirty,
|
|
3503
|
+
form
|
|
3504
|
+
}), [form, handleSubmit, mergedDefaultValues]);
|
|
3505
|
+
const SubmitButton = getFormComponent('SubmitButton');
|
|
3506
|
+
return jsx(FormProvider, {
|
|
3507
|
+
...form,
|
|
3508
|
+
children: jsxs("form", {
|
|
3509
|
+
ref: formRef,
|
|
3510
|
+
onSubmit: handleSubmit,
|
|
3511
|
+
className: className,
|
|
3512
|
+
children: [fields.map((item, index) => jsx(FormItemRenderer, {
|
|
3513
|
+
item: item
|
|
3514
|
+
}, getItemKey(item, index))), jsx(SubmitButton, {
|
|
3515
|
+
disabled: disabled || form.formState.isSubmitting,
|
|
3516
|
+
isSubmitting: form.formState.isSubmitting,
|
|
3517
|
+
children: submitText
|
|
3518
|
+
})]
|
|
3519
|
+
})
|
|
3520
|
+
});
|
|
3555
3521
|
}
|
|
3522
|
+
const FormGenerator = FormGeneratorImpl;
|
|
3556
3523
|
|
|
3557
3524
|
export { Controller, FieldRenderer, FormGenerator, FormProvider, clearAllRegistries, clearFieldRegistry, clearFormComponentRegistry, clearLayoutRegistry, getFieldComponent, getFormComponent, getFormComponents, getLayoutComponent, getRegisteredFieldTypes, hasFieldType, hasFormComponent, hasLayoutComponent, isLayoutBlock, registerField, registerFields, registerFormComponent, registerFormComponents, registerLayoutComponent, registerLayoutComponents, resetFormComponentRegistry, unregisterField, useFieldArray, useForm, useFormContext, useWatch };
|
|
3558
|
-
//# sourceMappingURL=index.
|
|
3525
|
+
//# sourceMappingURL=index.mjs.map
|