@connect-soft/form-generator 1.1.0-alpha8 → 1.1.1
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 +490 -2
- package/dist/index.js +800 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +783 -56
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/form/create-template-fields.d.ts +5 -1
- package/dist/types/components/form/create-template-fields.d.ts.map +1 -1
- package/dist/types/components/form/fields-context.d.ts +26 -0
- package/dist/types/components/form/fields-context.d.ts.map +1 -0
- package/dist/types/components/form/form-generator-typed.d.ts +47 -0
- package/dist/types/components/form/form-generator-typed.d.ts.map +1 -0
- package/dist/types/components/form/form-generator.d.ts +24 -21
- package/dist/types/components/form/form-generator.d.ts.map +1 -1
- package/dist/types/components/form/form-utils.d.ts +42 -2
- package/dist/types/components/form/form-utils.d.ts.map +1 -1
- package/dist/types/components/form/index.d.ts +3 -1
- package/dist/types/components/form/index.d.ts.map +1 -1
- package/dist/types/components/form/template-field-context.d.ts +14 -0
- package/dist/types/components/form/template-field-context.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/field-types.d.ts +8 -3
- package/dist/types/lib/field-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createElement, Fragment, memo, useCallback,
|
|
2
|
+
import React, { createElement, Fragment, memo, useCallback, useContext, createContext, 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';
|
|
@@ -3284,7 +3284,7 @@ const ArrayFieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
|
3284
3284
|
remove: () => remove(index_0),
|
|
3285
3285
|
move: toIndex => move(index_0, toIndex),
|
|
3286
3286
|
fields: renderItem(index_0),
|
|
3287
|
-
fieldNames: arrayField.fields.map(_temp),
|
|
3287
|
+
fieldNames: arrayField.fields.map(_temp$1),
|
|
3288
3288
|
namePrefix: `${field.name}.${index_0}`
|
|
3289
3289
|
});
|
|
3290
3290
|
};
|
|
@@ -3323,7 +3323,7 @@ const ArrayFieldRenderer = /*#__PURE__*/memo(t0 => {
|
|
|
3323
3323
|
return t1;
|
|
3324
3324
|
});
|
|
3325
3325
|
ArrayFieldRenderer.displayName = 'ArrayFieldRenderer';
|
|
3326
|
-
function _temp(f) {
|
|
3326
|
+
function _temp$1(f) {
|
|
3327
3327
|
return f.name;
|
|
3328
3328
|
}
|
|
3329
3329
|
|
|
@@ -3384,9 +3384,399 @@ function createTemplateFields(fieldEntries) {
|
|
|
3384
3384
|
return undefined;
|
|
3385
3385
|
}
|
|
3386
3386
|
};
|
|
3387
|
-
return
|
|
3387
|
+
return {
|
|
3388
|
+
templateFields: new Proxy({}, handler),
|
|
3389
|
+
accessedFields
|
|
3390
|
+
};
|
|
3388
3391
|
}
|
|
3389
3392
|
|
|
3393
|
+
const FieldsContext = /*#__PURE__*/createContext(null);
|
|
3394
|
+
function FieldsProvider(t0) {
|
|
3395
|
+
const $ = c(9);
|
|
3396
|
+
const {
|
|
3397
|
+
children,
|
|
3398
|
+
fields,
|
|
3399
|
+
namePrefix
|
|
3400
|
+
} = t0;
|
|
3401
|
+
let map;
|
|
3402
|
+
if ($[0] !== fields || $[1] !== namePrefix) {
|
|
3403
|
+
map = new Map();
|
|
3404
|
+
const addFields = (items, prefix) => {
|
|
3405
|
+
items.forEach(item => {
|
|
3406
|
+
if ("fields" in item && Array.isArray(item.fields)) {
|
|
3407
|
+
const arrayPrefix = prefix ? `${prefix}.${item.name}` : item.name;
|
|
3408
|
+
addFields(item.fields, arrayPrefix);
|
|
3409
|
+
} else {
|
|
3410
|
+
const fieldName = prefix ? `${prefix}.${item.name}` : item.name;
|
|
3411
|
+
map.set(fieldName, item);
|
|
3412
|
+
if (prefix) {
|
|
3413
|
+
map.set(item.name, item);
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
});
|
|
3417
|
+
};
|
|
3418
|
+
addFields(fields, namePrefix);
|
|
3419
|
+
$[0] = fields;
|
|
3420
|
+
$[1] = namePrefix;
|
|
3421
|
+
$[2] = map;
|
|
3422
|
+
} else {
|
|
3423
|
+
map = $[2];
|
|
3424
|
+
}
|
|
3425
|
+
const fieldsMap = map;
|
|
3426
|
+
let t1;
|
|
3427
|
+
if ($[3] !== fieldsMap || $[4] !== namePrefix) {
|
|
3428
|
+
t1 = {
|
|
3429
|
+
fields: fieldsMap,
|
|
3430
|
+
namePrefix
|
|
3431
|
+
};
|
|
3432
|
+
$[3] = fieldsMap;
|
|
3433
|
+
$[4] = namePrefix;
|
|
3434
|
+
$[5] = t1;
|
|
3435
|
+
} else {
|
|
3436
|
+
t1 = $[5];
|
|
3437
|
+
}
|
|
3438
|
+
const value = t1;
|
|
3439
|
+
let t2;
|
|
3440
|
+
if ($[6] !== children || $[7] !== value) {
|
|
3441
|
+
t2 = jsx(FieldsContext.Provider, {
|
|
3442
|
+
value,
|
|
3443
|
+
children
|
|
3444
|
+
});
|
|
3445
|
+
$[6] = children;
|
|
3446
|
+
$[7] = value;
|
|
3447
|
+
$[8] = t2;
|
|
3448
|
+
} else {
|
|
3449
|
+
t2 = $[8];
|
|
3450
|
+
}
|
|
3451
|
+
return t2;
|
|
3452
|
+
}
|
|
3453
|
+
function useFieldProps(name) {
|
|
3454
|
+
const $ = c(23);
|
|
3455
|
+
const context = useContext(FieldsContext);
|
|
3456
|
+
const form = useFormContext();
|
|
3457
|
+
if (!context) {
|
|
3458
|
+
throw new Error("useFieldProps must be used within FormGenerator or FieldsProvider");
|
|
3459
|
+
}
|
|
3460
|
+
if (!form) {
|
|
3461
|
+
throw new Error("useFieldProps must be used within a FormProvider context");
|
|
3462
|
+
}
|
|
3463
|
+
const {
|
|
3464
|
+
fields,
|
|
3465
|
+
namePrefix
|
|
3466
|
+
} = context;
|
|
3467
|
+
const fullName = namePrefix ? `${namePrefix}.${name}` : name;
|
|
3468
|
+
let t0;
|
|
3469
|
+
if ($[0] !== fields || $[1] !== fullName || $[2] !== name) {
|
|
3470
|
+
t0 = fields.get(fullName) || fields.get(name);
|
|
3471
|
+
$[0] = fields;
|
|
3472
|
+
$[1] = fullName;
|
|
3473
|
+
$[2] = name;
|
|
3474
|
+
$[3] = t0;
|
|
3475
|
+
} else {
|
|
3476
|
+
t0 = $[3];
|
|
3477
|
+
}
|
|
3478
|
+
const field = t0;
|
|
3479
|
+
if (!field) {
|
|
3480
|
+
throw new Error(`Field "${name}" not found in form fields. ` + `Available fields: ${Array.from(fields.keys()).join(", ")}`);
|
|
3481
|
+
}
|
|
3482
|
+
let t1;
|
|
3483
|
+
if ($[4] !== form.control || $[5] !== fullName) {
|
|
3484
|
+
t1 = {
|
|
3485
|
+
control: form.control,
|
|
3486
|
+
name: fullName
|
|
3487
|
+
};
|
|
3488
|
+
$[4] = form.control;
|
|
3489
|
+
$[5] = fullName;
|
|
3490
|
+
$[6] = t1;
|
|
3491
|
+
} else {
|
|
3492
|
+
t1 = $[6];
|
|
3493
|
+
}
|
|
3494
|
+
const {
|
|
3495
|
+
field: controllerField,
|
|
3496
|
+
fieldState
|
|
3497
|
+
} = useController(t1);
|
|
3498
|
+
let t2;
|
|
3499
|
+
if ($[7] !== field || $[8] !== fullName) {
|
|
3500
|
+
t2 = {
|
|
3501
|
+
...field,
|
|
3502
|
+
name: fullName
|
|
3503
|
+
};
|
|
3504
|
+
$[7] = field;
|
|
3505
|
+
$[8] = fullName;
|
|
3506
|
+
$[9] = t2;
|
|
3507
|
+
} else {
|
|
3508
|
+
t2 = $[9];
|
|
3509
|
+
}
|
|
3510
|
+
let t3;
|
|
3511
|
+
if ($[10] !== fieldState.error || $[11] !== fieldState.invalid || $[12] !== fieldState.isDirty || $[13] !== fieldState.isTouched) {
|
|
3512
|
+
t3 = {
|
|
3513
|
+
invalid: fieldState.invalid,
|
|
3514
|
+
error: fieldState.error,
|
|
3515
|
+
isDirty: fieldState.isDirty,
|
|
3516
|
+
isTouched: fieldState.isTouched
|
|
3517
|
+
};
|
|
3518
|
+
$[10] = fieldState.error;
|
|
3519
|
+
$[11] = fieldState.invalid;
|
|
3520
|
+
$[12] = fieldState.isDirty;
|
|
3521
|
+
$[13] = fieldState.isTouched;
|
|
3522
|
+
$[14] = t3;
|
|
3523
|
+
} else {
|
|
3524
|
+
t3 = $[14];
|
|
3525
|
+
}
|
|
3526
|
+
let t4;
|
|
3527
|
+
if ($[15] !== controllerField.name || $[16] !== controllerField.onBlur || $[17] !== controllerField.onChange || $[18] !== controllerField.ref || $[19] !== controllerField.value || $[20] !== t2 || $[21] !== t3) {
|
|
3528
|
+
t4 = {
|
|
3529
|
+
name: controllerField.name,
|
|
3530
|
+
value: controllerField.value,
|
|
3531
|
+
onChange: controllerField.onChange,
|
|
3532
|
+
onBlur: controllerField.onBlur,
|
|
3533
|
+
ref: controllerField.ref,
|
|
3534
|
+
field: t2,
|
|
3535
|
+
fieldState: t3
|
|
3536
|
+
};
|
|
3537
|
+
$[15] = controllerField.name;
|
|
3538
|
+
$[16] = controllerField.onBlur;
|
|
3539
|
+
$[17] = controllerField.onChange;
|
|
3540
|
+
$[18] = controllerField.ref;
|
|
3541
|
+
$[19] = controllerField.value;
|
|
3542
|
+
$[20] = t2;
|
|
3543
|
+
$[21] = t3;
|
|
3544
|
+
$[22] = t4;
|
|
3545
|
+
} else {
|
|
3546
|
+
t4 = $[22];
|
|
3547
|
+
}
|
|
3548
|
+
return t4;
|
|
3549
|
+
}
|
|
3550
|
+
function useFieldsContext() {
|
|
3551
|
+
return useContext(FieldsContext);
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
function isSchemaRequired(schema) {
|
|
3555
|
+
return !schema.isOptional() && !schema.isNullable();
|
|
3556
|
+
}
|
|
3557
|
+
function unwrapSchema(schema) {
|
|
3558
|
+
let current = schema;
|
|
3559
|
+
while (current instanceof z.ZodOptional || current instanceof z.ZodNullable) {
|
|
3560
|
+
current = current.unwrap();
|
|
3561
|
+
}
|
|
3562
|
+
if (current instanceof z.ZodDefault) {
|
|
3563
|
+
current = current._def.innerType;
|
|
3564
|
+
}
|
|
3565
|
+
return current;
|
|
3566
|
+
}
|
|
3567
|
+
function getSchemaTypeName(schema) {
|
|
3568
|
+
const unwrapped = unwrapSchema(schema);
|
|
3569
|
+
if (unwrapped instanceof z.ZodString) return 'string';
|
|
3570
|
+
if (unwrapped instanceof z.ZodNumber) return 'number';
|
|
3571
|
+
if (unwrapped instanceof z.ZodBoolean) return 'boolean';
|
|
3572
|
+
if (unwrapped instanceof z.ZodDate) return 'date';
|
|
3573
|
+
if (unwrapped instanceof z.ZodArray) return 'array';
|
|
3574
|
+
if (unwrapped instanceof z.ZodObject) return 'object';
|
|
3575
|
+
if (unwrapped instanceof z.ZodEnum) return 'enum';
|
|
3576
|
+
return 'unknown';
|
|
3577
|
+
}
|
|
3578
|
+
function getCheckDef(check) {
|
|
3579
|
+
var _a;
|
|
3580
|
+
if ((_a = check._zod) === null || _a === void 0 ? void 0 : _a.def) {
|
|
3581
|
+
const def = check._zod.def;
|
|
3582
|
+
return {
|
|
3583
|
+
type: def.check,
|
|
3584
|
+
value: def.value,
|
|
3585
|
+
minimum: def.minimum,
|
|
3586
|
+
maximum: def.maximum,
|
|
3587
|
+
length: def.length,
|
|
3588
|
+
regex: def.pattern || def.regex,
|
|
3589
|
+
format: def.format,
|
|
3590
|
+
inclusive: def.inclusive
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
if (check.kind) {
|
|
3594
|
+
return {
|
|
3595
|
+
type: check.kind,
|
|
3596
|
+
value: check.value,
|
|
3597
|
+
regex: check.regex
|
|
3598
|
+
};
|
|
3599
|
+
}
|
|
3600
|
+
return null;
|
|
3601
|
+
}
|
|
3602
|
+
function getNumberConstraints(schema) {
|
|
3603
|
+
const unwrapped = unwrapSchema(schema);
|
|
3604
|
+
if (!(unwrapped instanceof z.ZodNumber)) {
|
|
3605
|
+
return {};
|
|
3606
|
+
}
|
|
3607
|
+
const constraints = {};
|
|
3608
|
+
const checks = unwrapped._def.checks;
|
|
3609
|
+
if (checks) {
|
|
3610
|
+
for (const check of checks) {
|
|
3611
|
+
const def = getCheckDef(check);
|
|
3612
|
+
if (!def) continue;
|
|
3613
|
+
if (def.type === 'greater_than' || def.type === 'min') {
|
|
3614
|
+
constraints.min = def.value;
|
|
3615
|
+
} else if (def.type === 'less_than' || def.type === 'max') {
|
|
3616
|
+
constraints.max = def.value;
|
|
3617
|
+
} else if (def.type === 'multiple_of' || def.type === 'multipleOf') {
|
|
3618
|
+
constraints.step = def.value;
|
|
3619
|
+
} else if (def.type === 'number_format' && (def.format === 'safeint' || def.format === 'int')) {
|
|
3620
|
+
constraints.step = 1;
|
|
3621
|
+
} else if (def.type === 'int' || def.type === 'integer') {
|
|
3622
|
+
constraints.step = 1;
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
return constraints;
|
|
3627
|
+
}
|
|
3628
|
+
function getStringConstraints(schema) {
|
|
3629
|
+
const unwrapped = unwrapSchema(schema);
|
|
3630
|
+
if (!(unwrapped instanceof z.ZodString)) {
|
|
3631
|
+
return {};
|
|
3632
|
+
}
|
|
3633
|
+
const constraints = {};
|
|
3634
|
+
const checks = unwrapped._def.checks;
|
|
3635
|
+
if (checks) {
|
|
3636
|
+
for (const check of checks) {
|
|
3637
|
+
const def = getCheckDef(check);
|
|
3638
|
+
if (!def) continue;
|
|
3639
|
+
if (def.type === 'min_length' && def.minimum !== undefined) {
|
|
3640
|
+
constraints.minLength = def.minimum;
|
|
3641
|
+
} else if (def.type === 'min' && def.value !== undefined) {
|
|
3642
|
+
constraints.minLength = def.value;
|
|
3643
|
+
} else if (def.type === 'max_length' && def.maximum !== undefined) {
|
|
3644
|
+
constraints.maxLength = def.maximum;
|
|
3645
|
+
} else if (def.type === 'max' && def.value !== undefined) {
|
|
3646
|
+
constraints.maxLength = def.value;
|
|
3647
|
+
} else if (def.type === 'length_equals' && def.length !== undefined) {
|
|
3648
|
+
constraints.minLength = def.length;
|
|
3649
|
+
constraints.maxLength = def.length;
|
|
3650
|
+
} else if (def.type === 'length' && def.value !== undefined) {
|
|
3651
|
+
constraints.minLength = def.value;
|
|
3652
|
+
constraints.maxLength = def.value;
|
|
3653
|
+
} else if (def.type === 'string_format' && def.regex) {
|
|
3654
|
+
constraints.pattern = def.regex.source;
|
|
3655
|
+
} else if (def.type === 'regex' && def.regex) {
|
|
3656
|
+
constraints.pattern = def.regex.source;
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
return constraints;
|
|
3661
|
+
}
|
|
3662
|
+
function getDateConstraints(schema) {
|
|
3663
|
+
const unwrapped = unwrapSchema(schema);
|
|
3664
|
+
if (!(unwrapped instanceof z.ZodDate)) {
|
|
3665
|
+
return {};
|
|
3666
|
+
}
|
|
3667
|
+
const constraints = {};
|
|
3668
|
+
const checks = unwrapped._def.checks;
|
|
3669
|
+
if (checks) {
|
|
3670
|
+
for (const check of checks) {
|
|
3671
|
+
const def = getCheckDef(check);
|
|
3672
|
+
if (!def) continue;
|
|
3673
|
+
if (def.type === 'greater_than' || def.type === 'min') {
|
|
3674
|
+
const value = def.value;
|
|
3675
|
+
constraints.min = value instanceof Date ? value : new Date(value);
|
|
3676
|
+
} else if (def.type === 'less_than' || def.type === 'max') {
|
|
3677
|
+
const value = def.value;
|
|
3678
|
+
constraints.max = value instanceof Date ? value : new Date(value);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
return constraints;
|
|
3683
|
+
}
|
|
3684
|
+
function getSchemaRequirements(schema) {
|
|
3685
|
+
const result = {};
|
|
3686
|
+
const shape = schema.shape;
|
|
3687
|
+
for (const key in shape) {
|
|
3688
|
+
result[key] = isSchemaRequired(shape[key]);
|
|
3689
|
+
}
|
|
3690
|
+
return result;
|
|
3691
|
+
}
|
|
3692
|
+
function analyzeSchema(schema) {
|
|
3693
|
+
const shape = schema.shape;
|
|
3694
|
+
return Object.entries(shape).map(([name, fieldSchema]) => {
|
|
3695
|
+
const type = getSchemaTypeName(fieldSchema);
|
|
3696
|
+
const info = {
|
|
3697
|
+
name,
|
|
3698
|
+
required: isSchemaRequired(fieldSchema),
|
|
3699
|
+
type,
|
|
3700
|
+
schema: fieldSchema
|
|
3701
|
+
};
|
|
3702
|
+
if (type === 'number') {
|
|
3703
|
+
const constraints = getNumberConstraints(fieldSchema);
|
|
3704
|
+
if (constraints.min !== undefined) info.min = constraints.min;
|
|
3705
|
+
if (constraints.max !== undefined) info.max = constraints.max;
|
|
3706
|
+
if (constraints.step !== undefined) info.step = constraints.step;
|
|
3707
|
+
} else if (type === 'string') {
|
|
3708
|
+
const constraints = getStringConstraints(fieldSchema);
|
|
3709
|
+
if (constraints.minLength !== undefined) info.minLength = constraints.minLength;
|
|
3710
|
+
if (constraints.maxLength !== undefined) info.maxLength = constraints.maxLength;
|
|
3711
|
+
if (constraints.pattern !== undefined) info.pattern = constraints.pattern;
|
|
3712
|
+
} else if (type === 'date') {
|
|
3713
|
+
const constraints = getDateConstraints(fieldSchema);
|
|
3714
|
+
if (constraints.min !== undefined) info.minDate = constraints.min;
|
|
3715
|
+
if (constraints.max !== undefined) info.maxDate = constraints.max;
|
|
3716
|
+
}
|
|
3717
|
+
return info;
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
function mergeSchemaRequirements(schema, fields) {
|
|
3721
|
+
const requirements = getSchemaRequirements(schema);
|
|
3722
|
+
return fields.map(field => {
|
|
3723
|
+
const schemaRequired = requirements[field.name];
|
|
3724
|
+
if (schemaRequired !== undefined) {
|
|
3725
|
+
return {
|
|
3726
|
+
...field,
|
|
3727
|
+
required: schemaRequired
|
|
3728
|
+
};
|
|
3729
|
+
}
|
|
3730
|
+
return field;
|
|
3731
|
+
});
|
|
3732
|
+
}
|
|
3733
|
+
function mergeSchemaConstraints(schema, fields) {
|
|
3734
|
+
const fieldInfoMap = new Map();
|
|
3735
|
+
analyzeSchema(schema).forEach(info => {
|
|
3736
|
+
fieldInfoMap.set(info.name, info);
|
|
3737
|
+
});
|
|
3738
|
+
return fields.map(field => {
|
|
3739
|
+
const schemaInfo = fieldInfoMap.get(field.name);
|
|
3740
|
+
if (!schemaInfo) {
|
|
3741
|
+
return field;
|
|
3742
|
+
}
|
|
3743
|
+
const merged = {
|
|
3744
|
+
...field,
|
|
3745
|
+
required: schemaInfo.required
|
|
3746
|
+
};
|
|
3747
|
+
if (schemaInfo.type === 'number') {
|
|
3748
|
+
if (schemaInfo.min !== undefined) {
|
|
3749
|
+
merged.min = schemaInfo.min;
|
|
3750
|
+
}
|
|
3751
|
+
if (schemaInfo.max !== undefined) {
|
|
3752
|
+
merged.max = schemaInfo.max;
|
|
3753
|
+
}
|
|
3754
|
+
if (schemaInfo.step !== undefined) {
|
|
3755
|
+
merged.step = schemaInfo.step;
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
if (schemaInfo.type === 'string') {
|
|
3759
|
+
if (schemaInfo.minLength !== undefined) {
|
|
3760
|
+
merged.minLength = schemaInfo.minLength;
|
|
3761
|
+
}
|
|
3762
|
+
if (schemaInfo.maxLength !== undefined) {
|
|
3763
|
+
merged.maxLength = schemaInfo.maxLength;
|
|
3764
|
+
}
|
|
3765
|
+
if (schemaInfo.pattern !== undefined) {
|
|
3766
|
+
merged.pattern = schemaInfo.pattern;
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
if (schemaInfo.type === 'date') {
|
|
3770
|
+
if (schemaInfo.minDate !== undefined) {
|
|
3771
|
+
merged.min = schemaInfo.minDate.toISOString().split('T')[0];
|
|
3772
|
+
}
|
|
3773
|
+
if (schemaInfo.maxDate !== undefined) {
|
|
3774
|
+
merged.max = schemaInfo.maxDate.toISOString().split('T')[0];
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
return merged;
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3390
3780
|
function deepMerge(target, source) {
|
|
3391
3781
|
const result = {
|
|
3392
3782
|
...target
|
|
@@ -3497,10 +3887,79 @@ function buildDefaultValues(fields) {
|
|
|
3497
3887
|
return values;
|
|
3498
3888
|
}
|
|
3499
3889
|
|
|
3500
|
-
|
|
3501
|
-
|
|
3890
|
+
const TemplateFieldContext = /*#__PURE__*/createContext(null);
|
|
3891
|
+
function TemplateFieldProvider({
|
|
3892
|
+
children,
|
|
3893
|
+
fieldEntries,
|
|
3894
|
+
accessedFields
|
|
3895
|
+
}) {
|
|
3896
|
+
return jsx(TemplateFieldContext.Provider, {
|
|
3897
|
+
value: {
|
|
3898
|
+
fieldEntries,
|
|
3899
|
+
accessedFields
|
|
3900
|
+
},
|
|
3901
|
+
children: children
|
|
3902
|
+
});
|
|
3903
|
+
}
|
|
3904
|
+
function useTemplateField(name) {
|
|
3905
|
+
const $ = c(3);
|
|
3906
|
+
const context = useContext(TemplateFieldContext);
|
|
3907
|
+
if (!context) {
|
|
3908
|
+
throw new Error("useTemplateField must be used within FormGenerator with a custom layout (children render function).");
|
|
3909
|
+
}
|
|
3910
|
+
const {
|
|
3911
|
+
fieldEntries,
|
|
3912
|
+
accessedFields
|
|
3913
|
+
} = context;
|
|
3914
|
+
let t0;
|
|
3915
|
+
if ($[0] !== fieldEntries || $[1] !== name) {
|
|
3916
|
+
t0 = fieldEntries.get(name);
|
|
3917
|
+
$[0] = fieldEntries;
|
|
3918
|
+
$[1] = name;
|
|
3919
|
+
$[2] = t0;
|
|
3920
|
+
} else {
|
|
3921
|
+
t0 = $[2];
|
|
3922
|
+
}
|
|
3923
|
+
const entry = t0;
|
|
3924
|
+
if (entry) {
|
|
3925
|
+
accessedFields.add(name);
|
|
3926
|
+
return entry.element;
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
function RemainingFields() {
|
|
3930
|
+
const $ = c(3);
|
|
3931
|
+
const context = useContext(TemplateFieldContext);
|
|
3932
|
+
if (!context) {
|
|
3933
|
+
throw new Error("RemainingFields must be used within FormGenerator with a custom layout (children render function).");
|
|
3934
|
+
}
|
|
3935
|
+
const {
|
|
3936
|
+
fieldEntries,
|
|
3937
|
+
accessedFields
|
|
3938
|
+
} = context;
|
|
3939
|
+
let t0;
|
|
3940
|
+
if ($[0] !== accessedFields || $[1] !== fieldEntries) {
|
|
3941
|
+
const remaining = Array.from(fieldEntries.entries()).filter(t1 => {
|
|
3942
|
+
const [name] = t1;
|
|
3943
|
+
return !accessedFields.has(name);
|
|
3944
|
+
}).map(_temp);
|
|
3945
|
+
t0 = jsx(Fragment$1, {
|
|
3946
|
+
children: remaining
|
|
3947
|
+
});
|
|
3948
|
+
$[0] = accessedFields;
|
|
3949
|
+
$[1] = fieldEntries;
|
|
3950
|
+
$[2] = t0;
|
|
3951
|
+
} else {
|
|
3952
|
+
t0 = $[2];
|
|
3953
|
+
}
|
|
3954
|
+
return t0;
|
|
3502
3955
|
}
|
|
3503
|
-
function
|
|
3956
|
+
function _temp(t0) {
|
|
3957
|
+
const [, entry] = t0;
|
|
3958
|
+
return entry.element;
|
|
3959
|
+
}
|
|
3960
|
+
RemainingFields.displayName = 'RemainingFields';
|
|
3961
|
+
|
|
3962
|
+
function FormGenerator(props) {
|
|
3504
3963
|
const {
|
|
3505
3964
|
fields,
|
|
3506
3965
|
defaultValues,
|
|
@@ -3516,6 +3975,8 @@ function FormGeneratorImpl(props) {
|
|
|
3516
3975
|
ref,
|
|
3517
3976
|
validateTypes
|
|
3518
3977
|
} = props;
|
|
3978
|
+
const onSubmit = props.onSubmit;
|
|
3979
|
+
const formRef = useRef(null);
|
|
3519
3980
|
useMemo(() => {
|
|
3520
3981
|
if (validateTypes) {
|
|
3521
3982
|
const registeredTypes = getRegisteredFieldTypes();
|
|
@@ -3526,15 +3987,7 @@ function FormGeneratorImpl(props) {
|
|
|
3526
3987
|
validateFieldTypes(fields, registeredTypes, options);
|
|
3527
3988
|
}
|
|
3528
3989
|
}, [fields, validateTypes]);
|
|
3529
|
-
const
|
|
3530
|
-
const onSubmit = props.onSubmit;
|
|
3531
|
-
const formRef = useRef(null);
|
|
3532
|
-
const schema = useMemo(() => {
|
|
3533
|
-
if (userSchema) {
|
|
3534
|
-
return userSchema;
|
|
3535
|
-
}
|
|
3536
|
-
return buildSchema(fields);
|
|
3537
|
-
}, [fields, userSchema]);
|
|
3990
|
+
const schema = useMemo(() => buildSchema(fields), [fields]);
|
|
3538
3991
|
const mergedDefaultValues = useMemo(() => {
|
|
3539
3992
|
const builtDefaults = buildDefaultValues(fields);
|
|
3540
3993
|
return defaultValues ? deepMerge(builtDefaults, defaultValues) : builtDefaults;
|
|
@@ -3545,17 +3998,31 @@ function FormGeneratorImpl(props) {
|
|
|
3545
3998
|
mode
|
|
3546
3999
|
});
|
|
3547
4000
|
const handleSubmit = form.handleSubmit(async data => {
|
|
3548
|
-
|
|
4001
|
+
const context = {
|
|
4002
|
+
isDirty: form.formState.isDirty,
|
|
4003
|
+
dirtyFields: form.formState.dirtyFields,
|
|
4004
|
+
isValid: form.formState.isValid,
|
|
4005
|
+
errors: form.formState.errors,
|
|
4006
|
+
touchedFields: form.formState.touchedFields,
|
|
4007
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4008
|
+
submitCount: form.formState.submitCount,
|
|
4009
|
+
defaultValues: mergedDefaultValues,
|
|
4010
|
+
form: form
|
|
4011
|
+
};
|
|
4012
|
+
await onSubmit(data, context);
|
|
3549
4013
|
});
|
|
3550
4014
|
const handleReset = useCallback(() => {
|
|
3551
4015
|
form.reset(mergedDefaultValues);
|
|
3552
4016
|
}, [form, mergedDefaultValues]);
|
|
3553
4017
|
useImperativeHandle(ref, () => ({
|
|
3554
|
-
setValues: values => {
|
|
4018
|
+
setValues: (values, options_0) => {
|
|
4019
|
+
var _a, _b;
|
|
4020
|
+
const shouldDirty = (_a = options_0 === null || options_0 === void 0 ? void 0 : options_0.shouldDirty) !== null && _a !== void 0 ? _a : true;
|
|
4021
|
+
const shouldValidate = (_b = options_0 === null || options_0 === void 0 ? void 0 : options_0.shouldValidate) !== null && _b !== void 0 ? _b : true;
|
|
3555
4022
|
Object.entries(values).forEach(([key, value]) => {
|
|
3556
4023
|
form.setValue(key, value, {
|
|
3557
|
-
shouldValidate
|
|
3558
|
-
shouldDirty
|
|
4024
|
+
shouldValidate,
|
|
4025
|
+
shouldDirty
|
|
3559
4026
|
});
|
|
3560
4027
|
});
|
|
3561
4028
|
},
|
|
@@ -3567,6 +4034,12 @@ function FormGeneratorImpl(props) {
|
|
|
3567
4034
|
form.reset(mergedDefaultValues);
|
|
3568
4035
|
}
|
|
3569
4036
|
},
|
|
4037
|
+
setDefaultValues: values_1 => {
|
|
4038
|
+
const newDefaults = deepMerge(mergedDefaultValues, values_1);
|
|
4039
|
+
form.reset(newDefaults, {
|
|
4040
|
+
keepDirtyValues: false
|
|
4041
|
+
});
|
|
4042
|
+
},
|
|
3570
4043
|
submit: async () => {
|
|
3571
4044
|
await handleSubmit();
|
|
3572
4045
|
},
|
|
@@ -3618,7 +4091,10 @@ function FormGeneratorImpl(props) {
|
|
|
3618
4091
|
});
|
|
3619
4092
|
return entries;
|
|
3620
4093
|
}, [regularFields, FieldWrapper]);
|
|
3621
|
-
const
|
|
4094
|
+
const {
|
|
4095
|
+
templateFields,
|
|
4096
|
+
accessedFields
|
|
4097
|
+
} = useMemo(() => createTemplateFields(fieldEntries), [fieldEntries]);
|
|
3622
4098
|
const buttons = useMemo(() => {
|
|
3623
4099
|
const result = {
|
|
3624
4100
|
submit: jsx(SubmitButton, {
|
|
@@ -3637,40 +4113,43 @@ function FormGeneratorImpl(props) {
|
|
|
3637
4113
|
}
|
|
3638
4114
|
return result;
|
|
3639
4115
|
}, [SubmitButton, disabled, form.formState.isSubmitting, submitText, showReset, resetText, handleReset]);
|
|
3640
|
-
const renderField = useCallback((field_1,
|
|
4116
|
+
const renderField = useCallback((field_1, options_1) => {
|
|
3641
4117
|
return jsx(FieldRenderer, {
|
|
3642
4118
|
field: field_1,
|
|
3643
|
-
namePrefix:
|
|
4119
|
+
namePrefix: options_1 === null || options_1 === void 0 ? void 0 : options_1.namePrefix
|
|
3644
4120
|
});
|
|
3645
4121
|
}, []);
|
|
3646
4122
|
if (!children) {
|
|
3647
4123
|
return jsx(FormProvider, {
|
|
3648
4124
|
...form,
|
|
3649
|
-
children:
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
4125
|
+
children: jsx(FieldsProvider, {
|
|
4126
|
+
fields: fields,
|
|
4127
|
+
children: jsxs("form", {
|
|
4128
|
+
ref: formRef,
|
|
4129
|
+
onSubmit: handleSubmit,
|
|
4130
|
+
className: className,
|
|
4131
|
+
children: [jsxs(FieldsWrapper, {
|
|
4132
|
+
children: [regularFields.map((field_2, index_0) => jsx(FieldWrapper, {
|
|
4133
|
+
name: field_2.name,
|
|
4134
|
+
type: field_2.type,
|
|
4135
|
+
className: field_2.className,
|
|
4136
|
+
children: jsx(FieldRenderer, {
|
|
4137
|
+
field: field_2
|
|
4138
|
+
})
|
|
4139
|
+
}, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsx(FieldWrapper, {
|
|
4140
|
+
name: arrayField.name,
|
|
4141
|
+
type: "array",
|
|
4142
|
+
className: arrayField.className,
|
|
4143
|
+
children: jsx(ArrayFieldRenderer, {
|
|
4144
|
+
field: arrayField
|
|
4145
|
+
})
|
|
4146
|
+
}, arrayField.name))]
|
|
4147
|
+
}), jsx(SubmitButton, {
|
|
4148
|
+
disabled: disabled || form.formState.isSubmitting,
|
|
4149
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4150
|
+
children: submitText
|
|
4151
|
+
})]
|
|
4152
|
+
})
|
|
3674
4153
|
})
|
|
3675
4154
|
});
|
|
3676
4155
|
}
|
|
@@ -3693,17 +4172,265 @@ function FormGeneratorImpl(props) {
|
|
|
3693
4172
|
const renderFn = children;
|
|
3694
4173
|
return jsx(FormProvider, {
|
|
3695
4174
|
...form,
|
|
3696
|
-
children: jsx(
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
4175
|
+
children: jsx(FieldsProvider, {
|
|
4176
|
+
fields: fields,
|
|
4177
|
+
children: jsx(TemplateFieldProvider, {
|
|
4178
|
+
fieldEntries: fieldEntries,
|
|
4179
|
+
accessedFields: accessedFields,
|
|
4180
|
+
children: jsx("form", {
|
|
4181
|
+
ref: formRef,
|
|
4182
|
+
onSubmit: handleSubmit,
|
|
4183
|
+
className: className,
|
|
4184
|
+
children: renderFn(renderProps)
|
|
4185
|
+
})
|
|
4186
|
+
})
|
|
3701
4187
|
})
|
|
3702
4188
|
});
|
|
3703
4189
|
}
|
|
3704
|
-
|
|
3705
|
-
|
|
4190
|
+
|
|
4191
|
+
function typedField() {
|
|
4192
|
+
return field => field;
|
|
4193
|
+
}
|
|
4194
|
+
function typedFields(fields) {
|
|
4195
|
+
return fields;
|
|
4196
|
+
}
|
|
4197
|
+
function StrictFormGenerator(props) {
|
|
4198
|
+
const {
|
|
4199
|
+
schema,
|
|
4200
|
+
fields,
|
|
4201
|
+
onSubmit,
|
|
4202
|
+
defaultValues,
|
|
4203
|
+
className,
|
|
4204
|
+
submitText = 'Submit',
|
|
4205
|
+
disabled,
|
|
4206
|
+
mode = 'onChange',
|
|
4207
|
+
title,
|
|
4208
|
+
description,
|
|
4209
|
+
showReset = false,
|
|
4210
|
+
resetText = 'Reset',
|
|
4211
|
+
children,
|
|
4212
|
+
ref,
|
|
4213
|
+
validateTypes
|
|
4214
|
+
} = props;
|
|
4215
|
+
const formRef = useRef(null);
|
|
4216
|
+
const fieldsWithRequirements = useMemo(() => {
|
|
4217
|
+
if (schema && typeof schema === 'object' && 'shape' in schema) {
|
|
4218
|
+
return mergeSchemaConstraints(schema, fields);
|
|
4219
|
+
}
|
|
4220
|
+
return fields;
|
|
4221
|
+
}, [schema, fields]);
|
|
4222
|
+
useMemo(() => {
|
|
4223
|
+
if (validateTypes) {
|
|
4224
|
+
const registeredTypes = getRegisteredFieldTypes();
|
|
4225
|
+
const options = typeof validateTypes === 'object' ? validateTypes : {
|
|
4226
|
+
throwOnError: false,
|
|
4227
|
+
warn: true
|
|
4228
|
+
};
|
|
4229
|
+
validateFieldTypes(fieldsWithRequirements, registeredTypes, options);
|
|
4230
|
+
}
|
|
4231
|
+
}, [fieldsWithRequirements, validateTypes]);
|
|
4232
|
+
const mergedDefaultValues = useMemo(() => {
|
|
4233
|
+
const builtDefaults = buildDefaultValues(fieldsWithRequirements);
|
|
4234
|
+
return defaultValues ? deepMerge(builtDefaults, defaultValues) : builtDefaults;
|
|
4235
|
+
}, [fieldsWithRequirements, defaultValues]);
|
|
4236
|
+
const form = useForm({
|
|
4237
|
+
resolver: a(schema),
|
|
4238
|
+
defaultValues: mergedDefaultValues,
|
|
4239
|
+
mode
|
|
4240
|
+
});
|
|
4241
|
+
const handleSubmit = form.handleSubmit(async data => {
|
|
4242
|
+
const context = {
|
|
4243
|
+
isDirty: form.formState.isDirty,
|
|
4244
|
+
dirtyFields: form.formState.dirtyFields,
|
|
4245
|
+
isValid: form.formState.isValid,
|
|
4246
|
+
errors: form.formState.errors,
|
|
4247
|
+
touchedFields: form.formState.touchedFields,
|
|
4248
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4249
|
+
submitCount: form.formState.submitCount,
|
|
4250
|
+
defaultValues: mergedDefaultValues,
|
|
4251
|
+
form: form
|
|
4252
|
+
};
|
|
4253
|
+
await onSubmit(data, context);
|
|
4254
|
+
});
|
|
4255
|
+
const handleReset = useCallback(() => {
|
|
4256
|
+
form.reset(mergedDefaultValues);
|
|
4257
|
+
}, [form, mergedDefaultValues]);
|
|
4258
|
+
useImperativeHandle(ref, () => ({
|
|
4259
|
+
setValues: (values, options_0) => {
|
|
4260
|
+
var _a, _b;
|
|
4261
|
+
const shouldDirty = (_a = options_0 === null || options_0 === void 0 ? void 0 : options_0.shouldDirty) !== null && _a !== void 0 ? _a : true;
|
|
4262
|
+
const shouldValidate = (_b = options_0 === null || options_0 === void 0 ? void 0 : options_0.shouldValidate) !== null && _b !== void 0 ? _b : true;
|
|
4263
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
4264
|
+
form.setValue(key, value, {
|
|
4265
|
+
shouldValidate,
|
|
4266
|
+
shouldDirty
|
|
4267
|
+
});
|
|
4268
|
+
});
|
|
4269
|
+
},
|
|
4270
|
+
getValues: () => form.getValues(),
|
|
4271
|
+
reset: values_0 => {
|
|
4272
|
+
if (values_0) {
|
|
4273
|
+
form.reset(deepMerge(mergedDefaultValues, values_0));
|
|
4274
|
+
} else {
|
|
4275
|
+
form.reset(mergedDefaultValues);
|
|
4276
|
+
}
|
|
4277
|
+
},
|
|
4278
|
+
setDefaultValues: values_1 => {
|
|
4279
|
+
const newDefaults = deepMerge(mergedDefaultValues, values_1);
|
|
4280
|
+
form.reset(newDefaults, {
|
|
4281
|
+
keepDirtyValues: false
|
|
4282
|
+
});
|
|
4283
|
+
},
|
|
4284
|
+
submit: async () => {
|
|
4285
|
+
await handleSubmit();
|
|
4286
|
+
},
|
|
4287
|
+
clearErrors: () => form.clearErrors(),
|
|
4288
|
+
setError: (name, error) => form.setError(name, error),
|
|
4289
|
+
isValid: () => form.formState.isValid,
|
|
4290
|
+
isDirty: () => form.formState.isDirty,
|
|
4291
|
+
form: form
|
|
4292
|
+
}), [form, handleSubmit, mergedDefaultValues]);
|
|
4293
|
+
const SubmitButton = getFormComponent('SubmitButton');
|
|
4294
|
+
const FieldWrapper = getFormComponent('FieldWrapper');
|
|
4295
|
+
const FieldsWrapper = getFormComponent('FieldsWrapper');
|
|
4296
|
+
const {
|
|
4297
|
+
regularFields,
|
|
4298
|
+
arrayFields
|
|
4299
|
+
} = useMemo(() => {
|
|
4300
|
+
const regular = [];
|
|
4301
|
+
const arrays = [];
|
|
4302
|
+
fieldsWithRequirements.forEach(field => {
|
|
4303
|
+
if (isArrayField(field)) {
|
|
4304
|
+
arrays.push(field);
|
|
4305
|
+
} else {
|
|
4306
|
+
regular.push(field);
|
|
4307
|
+
}
|
|
4308
|
+
});
|
|
4309
|
+
return {
|
|
4310
|
+
regularFields: regular,
|
|
4311
|
+
arrayFields: arrays
|
|
4312
|
+
};
|
|
4313
|
+
}, [fieldsWithRequirements]);
|
|
4314
|
+
const fieldEntries = useMemo(() => {
|
|
4315
|
+
const entries = new Map();
|
|
4316
|
+
regularFields.forEach((field_0, index) => {
|
|
4317
|
+
if (!field_0.hidden) {
|
|
4318
|
+
const element = jsx(FieldWrapper, {
|
|
4319
|
+
name: field_0.name,
|
|
4320
|
+
type: field_0.type,
|
|
4321
|
+
className: field_0.className,
|
|
4322
|
+
children: jsx(FieldRenderer, {
|
|
4323
|
+
field: field_0
|
|
4324
|
+
})
|
|
4325
|
+
}, field_0.name || `field-${index}`);
|
|
4326
|
+
entries.set(field_0.name, {
|
|
4327
|
+
field: field_0,
|
|
4328
|
+
element,
|
|
4329
|
+
accessed: false
|
|
4330
|
+
});
|
|
4331
|
+
}
|
|
4332
|
+
});
|
|
4333
|
+
return entries;
|
|
4334
|
+
}, [regularFields, FieldWrapper]);
|
|
4335
|
+
const {
|
|
4336
|
+
templateFields,
|
|
4337
|
+
accessedFields
|
|
4338
|
+
} = useMemo(() => createTemplateFields(fieldEntries), [fieldEntries]);
|
|
4339
|
+
const buttons = useMemo(() => {
|
|
4340
|
+
const result = {
|
|
4341
|
+
submit: jsx(SubmitButton, {
|
|
4342
|
+
disabled: disabled || form.formState.isSubmitting,
|
|
4343
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4344
|
+
children: submitText
|
|
4345
|
+
}, "submit")
|
|
4346
|
+
};
|
|
4347
|
+
if (showReset) {
|
|
4348
|
+
result.reset = jsx("button", {
|
|
4349
|
+
type: "button",
|
|
4350
|
+
onClick: handleReset,
|
|
4351
|
+
disabled: disabled,
|
|
4352
|
+
children: resetText
|
|
4353
|
+
}, "reset");
|
|
4354
|
+
}
|
|
4355
|
+
return result;
|
|
4356
|
+
}, [SubmitButton, disabled, form.formState.isSubmitting, submitText, showReset, resetText, handleReset]);
|
|
4357
|
+
const renderField = useCallback((field_1, options_1) => {
|
|
4358
|
+
return jsx(FieldRenderer, {
|
|
4359
|
+
field: field_1,
|
|
4360
|
+
namePrefix: options_1 === null || options_1 === void 0 ? void 0 : options_1.namePrefix
|
|
4361
|
+
});
|
|
4362
|
+
}, []);
|
|
4363
|
+
if (!children) {
|
|
4364
|
+
return jsx(FormProvider, {
|
|
4365
|
+
...form,
|
|
4366
|
+
children: jsx(FieldsProvider, {
|
|
4367
|
+
fields: fieldsWithRequirements,
|
|
4368
|
+
children: jsxs("form", {
|
|
4369
|
+
ref: formRef,
|
|
4370
|
+
onSubmit: handleSubmit,
|
|
4371
|
+
className: className,
|
|
4372
|
+
children: [jsxs(FieldsWrapper, {
|
|
4373
|
+
children: [regularFields.map((field_2, index_0) => jsx(FieldWrapper, {
|
|
4374
|
+
name: field_2.name,
|
|
4375
|
+
type: field_2.type,
|
|
4376
|
+
className: field_2.className,
|
|
4377
|
+
children: jsx(FieldRenderer, {
|
|
4378
|
+
field: field_2
|
|
4379
|
+
})
|
|
4380
|
+
}, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsx(FieldWrapper, {
|
|
4381
|
+
name: arrayField.name,
|
|
4382
|
+
type: "array",
|
|
4383
|
+
className: arrayField.className,
|
|
4384
|
+
children: jsx(ArrayFieldRenderer, {
|
|
4385
|
+
field: arrayField
|
|
4386
|
+
})
|
|
4387
|
+
}, arrayField.name))]
|
|
4388
|
+
}), jsx(SubmitButton, {
|
|
4389
|
+
disabled: disabled || form.formState.isSubmitting,
|
|
4390
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4391
|
+
children: submitText
|
|
4392
|
+
})]
|
|
4393
|
+
})
|
|
4394
|
+
})
|
|
4395
|
+
});
|
|
4396
|
+
}
|
|
4397
|
+
const renderProps = {
|
|
4398
|
+
fields: templateFields,
|
|
4399
|
+
arrays: Object.fromEntries(arrayFields.map(arrayField_0 => [arrayField_0.name, {
|
|
4400
|
+
field: arrayField_0
|
|
4401
|
+
}])),
|
|
4402
|
+
buttons,
|
|
4403
|
+
title,
|
|
4404
|
+
description,
|
|
4405
|
+
form: form,
|
|
4406
|
+
isSubmitting: form.formState.isSubmitting,
|
|
4407
|
+
isValid: form.formState.isValid,
|
|
4408
|
+
isDirty: form.formState.isDirty,
|
|
4409
|
+
renderField,
|
|
4410
|
+
FieldWrapper,
|
|
4411
|
+
FieldsWrapper
|
|
4412
|
+
};
|
|
4413
|
+
const renderFn = children;
|
|
4414
|
+
return jsx(FormProvider, {
|
|
4415
|
+
...form,
|
|
4416
|
+
children: jsx(FieldsProvider, {
|
|
4417
|
+
fields: fieldsWithRequirements,
|
|
4418
|
+
children: jsx(TemplateFieldProvider, {
|
|
4419
|
+
fieldEntries: fieldEntries,
|
|
4420
|
+
accessedFields: accessedFields,
|
|
4421
|
+
children: jsx("form", {
|
|
4422
|
+
ref: formRef,
|
|
4423
|
+
onSubmit: handleSubmit,
|
|
4424
|
+
className: className,
|
|
4425
|
+
children: renderFn(renderProps)
|
|
4426
|
+
})
|
|
4427
|
+
})
|
|
4428
|
+
})
|
|
4429
|
+
});
|
|
4430
|
+
}
|
|
4431
|
+
function createFieldFactory(_schema) {
|
|
4432
|
+
return field => field;
|
|
3706
4433
|
}
|
|
3707
4434
|
|
|
3708
|
-
export { ArrayFieldRenderer, Controller, FieldRenderer, FormGenerator, FormProvider, clearAllRegistries, clearFieldRegistry, clearFormComponentRegistry, createArrayField, createField, getFieldComponent, getFormComponent, getFormComponents, getRegisteredFieldTypes, hasFieldType, hasFormComponent, isArrayField, registerField, registerFields, registerFormComponent, registerFormComponents, resetFormComponentRegistry, strictFields, unregisterField, useArrayField, useFieldArray, useForm, useFormContext, useWatch, validateFieldType, validateFieldTypes };
|
|
4435
|
+
export { ArrayFieldRenderer, Controller, FieldRenderer, FieldsProvider, FormGenerator, FormProvider, RemainingFields, StrictFormGenerator, analyzeSchema, clearAllRegistries, clearFieldRegistry, clearFormComponentRegistry, createArrayField, createField, createFieldFactory, getDateConstraints, getFieldComponent, getFormComponent, getFormComponents, getNumberConstraints, getRegisteredFieldTypes, getSchemaRequirements, getSchemaTypeName, getStringConstraints, hasFieldType, hasFormComponent, isArrayField, isSchemaRequired, mergeSchemaConstraints, mergeSchemaRequirements, registerField, registerFields, registerFormComponent, registerFormComponents, resetFormComponentRegistry, strictFields, typedField, typedFields, unregisterField, unwrapSchema, useArrayField, useFieldArray, useFieldProps, useFieldsContext, useForm, useFormContext, useTemplateField, useWatch, validateFieldType, validateFieldTypes };
|
|
3709
4436
|
//# sourceMappingURL=index.mjs.map
|