@uniform-ts/core 0.0.4 → 0.0.5
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 +42 -1118
- package/dist/index.d.mts +465 -319
- package/dist/index.d.ts +465 -319
- package/dist/index.js +220 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -421,6 +421,46 @@ function DefaultArrayRowLayout({
|
|
|
421
421
|
] })
|
|
422
422
|
] });
|
|
423
423
|
}
|
|
424
|
+
function DefaultArrayFieldLayout({
|
|
425
|
+
rows,
|
|
426
|
+
addButton
|
|
427
|
+
}) {
|
|
428
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
429
|
+
rows,
|
|
430
|
+
addButton
|
|
431
|
+
] });
|
|
432
|
+
}
|
|
433
|
+
function DefaultObjectWrapper({
|
|
434
|
+
children,
|
|
435
|
+
label,
|
|
436
|
+
className,
|
|
437
|
+
labelClassName
|
|
438
|
+
}) {
|
|
439
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className, children: [
|
|
440
|
+
label && /* @__PURE__ */ jsxRuntime.jsx("legend", { className: labelClassName, children: label }),
|
|
441
|
+
children
|
|
442
|
+
] });
|
|
443
|
+
}
|
|
444
|
+
function DefaultArrayWrapper({
|
|
445
|
+
children,
|
|
446
|
+
label,
|
|
447
|
+
className,
|
|
448
|
+
labelClassName
|
|
449
|
+
}) {
|
|
450
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className, children: [
|
|
451
|
+
label && /* @__PURE__ */ jsxRuntime.jsx("legend", { className: labelClassName, children: label }),
|
|
452
|
+
children
|
|
453
|
+
] });
|
|
454
|
+
}
|
|
455
|
+
function DefaultArrayButton(props) {
|
|
456
|
+
return /* @__PURE__ */ jsxRuntime.jsx("button", { ...props });
|
|
457
|
+
}
|
|
458
|
+
function DefaultArrayCollapseButton({
|
|
459
|
+
isCollapsed: _isCollapsed,
|
|
460
|
+
...props
|
|
461
|
+
}) {
|
|
462
|
+
return /* @__PURE__ */ jsxRuntime.jsx("button", { ...props });
|
|
463
|
+
}
|
|
424
464
|
|
|
425
465
|
// src/utils/resolveErrorMessage.ts
|
|
426
466
|
function resolveErrorMessage(fieldName, error, messages) {
|
|
@@ -624,6 +664,7 @@ function ObjectField({
|
|
|
624
664
|
depth = 0,
|
|
625
665
|
shouldUnregister
|
|
626
666
|
}) {
|
|
667
|
+
const { classNames, layout } = useAutoFormContext();
|
|
627
668
|
const children = field.children;
|
|
628
669
|
const content = children.map((child, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
629
670
|
FieldRenderer,
|
|
@@ -640,10 +681,16 @@ function ObjectField({
|
|
|
640
681
|
if (field.meta.section) {
|
|
641
682
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: content });
|
|
642
683
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
684
|
+
const ObjectWrapper = field.meta.wrapper ?? layout.objectWrapper;
|
|
685
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
686
|
+
ObjectWrapper,
|
|
687
|
+
{
|
|
688
|
+
label: field.label,
|
|
689
|
+
className: classNames.objectFieldset,
|
|
690
|
+
labelClassName: classNames.objectLegend,
|
|
691
|
+
children: content
|
|
692
|
+
}
|
|
693
|
+
);
|
|
647
694
|
}
|
|
648
695
|
|
|
649
696
|
// src/components/fields/getDefaultValue.ts
|
|
@@ -722,124 +769,147 @@ function ArrayField({ field, control, effectiveName }) {
|
|
|
722
769
|
...itemConfig,
|
|
723
770
|
meta: { ...itemConfig.meta, section: field.meta.section }
|
|
724
771
|
} : itemConfig;
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
onClick: () => remove(index),
|
|
794
|
-
disabled: atMin,
|
|
795
|
-
"aria-label": `Remove item ${index + 1}`,
|
|
796
|
-
children: labels.arrayRemove ?? "Remove"
|
|
797
|
-
}
|
|
798
|
-
);
|
|
799
|
-
const fieldContent = !isCollapsed ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
800
|
-
FieldRenderer,
|
|
801
|
-
{
|
|
802
|
-
field: effectiveItemConfig,
|
|
803
|
-
control,
|
|
804
|
-
namePrefix: `${effectiveName}.${index}`
|
|
805
|
-
}
|
|
806
|
-
) : null;
|
|
807
|
-
const RowLayout = layout.arrayRowLayout;
|
|
808
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
809
|
-
RowLayout,
|
|
810
|
-
{
|
|
811
|
-
buttons: {
|
|
812
|
-
moveUp: moveUpButton,
|
|
813
|
-
moveDown: moveDownButton,
|
|
814
|
-
duplicate: duplicateButton,
|
|
815
|
-
remove: removeButton,
|
|
816
|
-
collapse: collapseButton
|
|
817
|
-
},
|
|
818
|
-
index,
|
|
819
|
-
rowCount: rows.length,
|
|
820
|
-
children: fieldContent
|
|
772
|
+
const {
|
|
773
|
+
add: AddBtn,
|
|
774
|
+
remove: RemoveBtn,
|
|
775
|
+
moveUp: MoveUpBtn,
|
|
776
|
+
moveDown: MoveDownBtn,
|
|
777
|
+
duplicate: DuplicateBtn,
|
|
778
|
+
collapse: CollapseBtn
|
|
779
|
+
} = layout.arrayButtons;
|
|
780
|
+
const ArrayFieldLayout = layout.arrayFieldLayout;
|
|
781
|
+
const RowLayout = layout.arrayRowLayout;
|
|
782
|
+
const renderedRows = rows.map((row, index) => {
|
|
783
|
+
const isCollapsed = showCollapse && collapsed.has(index);
|
|
784
|
+
const collapseButton = showCollapse ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
785
|
+
CollapseBtn,
|
|
786
|
+
{
|
|
787
|
+
type: "button",
|
|
788
|
+
className: classNames.arrayCollapse,
|
|
789
|
+
onClick: () => toggleCollapse(index),
|
|
790
|
+
"aria-label": isCollapsed ? `Expand item ${index + 1}` : `Collapse item ${index + 1}`,
|
|
791
|
+
isCollapsed,
|
|
792
|
+
children: [
|
|
793
|
+
isCollapsed ? labels.arrayExpand ?? "\u25BC" : labels.arrayCollapse ?? "\u25B6",
|
|
794
|
+
" ",
|
|
795
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
796
|
+
CollapseSummary,
|
|
797
|
+
{
|
|
798
|
+
control,
|
|
799
|
+
effectiveName,
|
|
800
|
+
index,
|
|
801
|
+
itemConfig,
|
|
802
|
+
isCollapsed
|
|
803
|
+
}
|
|
804
|
+
)
|
|
805
|
+
]
|
|
806
|
+
}
|
|
807
|
+
) : null;
|
|
808
|
+
const moveUpButton = showMove && rows.length > 1 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
809
|
+
MoveUpBtn,
|
|
810
|
+
{
|
|
811
|
+
type: "button",
|
|
812
|
+
className: classNames.arrayMove,
|
|
813
|
+
onClick: () => move(index, index - 1),
|
|
814
|
+
disabled: index === 0,
|
|
815
|
+
"aria-label": `Move item ${index + 1} up`,
|
|
816
|
+
children: labels.arrayMoveUp ?? "\u2191"
|
|
817
|
+
}
|
|
818
|
+
) : null;
|
|
819
|
+
const moveDownButton = showMove && rows.length > 1 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
820
|
+
MoveDownBtn,
|
|
821
|
+
{
|
|
822
|
+
type: "button",
|
|
823
|
+
className: classNames.arrayMove,
|
|
824
|
+
onClick: () => move(index, index + 1),
|
|
825
|
+
disabled: index === rows.length - 1,
|
|
826
|
+
"aria-label": `Move item ${index + 1} down`,
|
|
827
|
+
children: labels.arrayMoveDown ?? "\u2193"
|
|
828
|
+
}
|
|
829
|
+
) : null;
|
|
830
|
+
const duplicateButton = showDuplicate && !atMax ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
831
|
+
DuplicateBtn,
|
|
832
|
+
{
|
|
833
|
+
type: "button",
|
|
834
|
+
className: classNames.arrayDuplicate,
|
|
835
|
+
onClick: () => {
|
|
836
|
+
const values = Object.fromEntries(
|
|
837
|
+
Object.entries(row).filter(([k]) => k !== "id")
|
|
838
|
+
);
|
|
839
|
+
insert(index + 1, values);
|
|
821
840
|
},
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
841
|
+
"aria-label": `Duplicate item ${index + 1}`,
|
|
842
|
+
children: labels.arrayDuplicate ?? "Duplicate"
|
|
843
|
+
}
|
|
844
|
+
) : null;
|
|
845
|
+
const removeButton = /* @__PURE__ */ jsxRuntime.jsx(
|
|
846
|
+
RemoveBtn,
|
|
827
847
|
{
|
|
828
848
|
type: "button",
|
|
829
|
-
className: classNames.
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
849
|
+
className: classNames.arrayRemove,
|
|
850
|
+
onClick: () => remove(index),
|
|
851
|
+
disabled: atMin,
|
|
852
|
+
"aria-label": `Remove item ${index + 1}`,
|
|
853
|
+
children: labels.arrayRemove ?? "Remove"
|
|
833
854
|
}
|
|
834
|
-
)
|
|
835
|
-
|
|
855
|
+
);
|
|
856
|
+
const fieldContent = !isCollapsed ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
857
|
+
FieldRenderer,
|
|
858
|
+
{
|
|
859
|
+
field: effectiveItemConfig,
|
|
860
|
+
control,
|
|
861
|
+
namePrefix: `${effectiveName}.${index}`
|
|
862
|
+
}
|
|
863
|
+
) : null;
|
|
864
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
865
|
+
RowLayout,
|
|
866
|
+
{
|
|
867
|
+
buttons: {
|
|
868
|
+
moveUp: moveUpButton,
|
|
869
|
+
moveDown: moveDownButton,
|
|
870
|
+
duplicate: duplicateButton,
|
|
871
|
+
remove: removeButton,
|
|
872
|
+
collapse: collapseButton
|
|
873
|
+
},
|
|
874
|
+
index,
|
|
875
|
+
rowCount: rows.length,
|
|
876
|
+
children: fieldContent
|
|
877
|
+
},
|
|
878
|
+
row.id
|
|
879
|
+
);
|
|
880
|
+
});
|
|
881
|
+
const addButton = /* @__PURE__ */ jsxRuntime.jsx(
|
|
882
|
+
AddBtn,
|
|
883
|
+
{
|
|
884
|
+
type: "button",
|
|
885
|
+
className: classNames.arrayAdd,
|
|
886
|
+
disabled: atMax,
|
|
887
|
+
onClick: () => append(getDefaultValue(itemConfig)),
|
|
888
|
+
children: labels.arrayAdd ?? "Add"
|
|
889
|
+
}
|
|
890
|
+
);
|
|
891
|
+
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
892
|
+
ArrayFieldLayout,
|
|
893
|
+
{
|
|
894
|
+
rows: renderedRows,
|
|
895
|
+
addButton,
|
|
896
|
+
rowCount: rows.length,
|
|
897
|
+
canAdd: !atMax
|
|
898
|
+
}
|
|
899
|
+
);
|
|
836
900
|
if (field.meta.section) {
|
|
837
901
|
return content;
|
|
838
902
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
903
|
+
const ArrayWrapper = field.meta.wrapper ?? layout.arrayWrapper;
|
|
904
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
905
|
+
ArrayWrapper,
|
|
906
|
+
{
|
|
907
|
+
label: field.label,
|
|
908
|
+
className: classNames.arrayFieldset,
|
|
909
|
+
labelClassName: classNames.arrayLegend,
|
|
910
|
+
children: content
|
|
911
|
+
}
|
|
912
|
+
);
|
|
843
913
|
}
|
|
844
914
|
function CollapseSummary({
|
|
845
915
|
control,
|
|
@@ -1406,11 +1476,7 @@ function AutoForm(props) {
|
|
|
1406
1476
|
onSubmitRef
|
|
1407
1477
|
]
|
|
1408
1478
|
);
|
|
1409
|
-
React3__namespace.useImperativeHandle(
|
|
1410
|
-
ref,
|
|
1411
|
-
() => ({ ...formMethods, isSubmitting: formState.isSubmitting }),
|
|
1412
|
-
[formMethods, formState.isSubmitting]
|
|
1413
|
-
);
|
|
1479
|
+
React3__namespace.useImperativeHandle(ref, () => formMethods, [formMethods]);
|
|
1414
1480
|
const setFieldMeta = React3__namespace.useCallback(
|
|
1415
1481
|
(field, meta) => {
|
|
1416
1482
|
if (Object.keys(meta).length) {
|
|
@@ -1451,22 +1517,39 @@ function AutoForm(props) {
|
|
|
1451
1517
|
}, [onValuesChangeRef, allValues]);
|
|
1452
1518
|
const visibleFields = useConditionalFields(fieldsWithDynamic, control);
|
|
1453
1519
|
const sections = useSectionGrouping(visibleFields);
|
|
1454
|
-
const resolvedLayout = React3__namespace.useMemo(
|
|
1455
|
-
|
|
1520
|
+
const resolvedLayout = React3__namespace.useMemo(() => {
|
|
1521
|
+
const base = layout?.arrayButtons?.base ?? DefaultArrayButton;
|
|
1522
|
+
const slots = layout?.arrayButtons;
|
|
1523
|
+
return {
|
|
1456
1524
|
formWrapper: layout?.formWrapper ?? DefaultFormWrapper,
|
|
1457
1525
|
sectionWrapper: layout?.sectionWrapper ?? DefaultSectionWrapper,
|
|
1458
1526
|
submitButton: layout?.submitButton ?? DefaultSubmitButton,
|
|
1459
1527
|
arrayRowLayout: layout?.arrayRowLayout ?? DefaultArrayRowLayout,
|
|
1528
|
+
arrayFieldLayout: layout?.arrayFieldLayout ?? DefaultArrayFieldLayout,
|
|
1529
|
+
objectWrapper: layout?.objectWrapper ?? DefaultObjectWrapper,
|
|
1530
|
+
arrayWrapper: layout?.arrayWrapper ?? DefaultArrayWrapper,
|
|
1531
|
+
arrayButtons: {
|
|
1532
|
+
base,
|
|
1533
|
+
add: slots?.add ?? base,
|
|
1534
|
+
remove: slots?.remove ?? base,
|
|
1535
|
+
moveUp: slots?.moveUp ?? base,
|
|
1536
|
+
moveDown: slots?.moveDown ?? base,
|
|
1537
|
+
duplicate: slots?.duplicate ?? base,
|
|
1538
|
+
collapse: slots?.collapse ?? DefaultArrayCollapseButton
|
|
1539
|
+
},
|
|
1460
1540
|
loadingFallback: layout?.loadingFallback ?? /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Loading\u2026" })
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1541
|
+
};
|
|
1542
|
+
}, [
|
|
1543
|
+
layout?.formWrapper,
|
|
1544
|
+
layout?.sectionWrapper,
|
|
1545
|
+
layout?.submitButton,
|
|
1546
|
+
layout?.arrayRowLayout,
|
|
1547
|
+
layout?.arrayFieldLayout,
|
|
1548
|
+
layout?.objectWrapper,
|
|
1549
|
+
layout?.arrayWrapper,
|
|
1550
|
+
layout?.arrayButtons,
|
|
1551
|
+
layout?.loadingFallback
|
|
1552
|
+
]);
|
|
1470
1553
|
const resolvedFieldWrapper = fieldWrapper ?? DefaultFieldWrapper;
|
|
1471
1554
|
const FormWrapper = resolvedLayout.formWrapper;
|
|
1472
1555
|
const SectionWrapper = resolvedLayout.sectionWrapper;
|
|
@@ -1645,9 +1728,15 @@ function createForm(schema) {
|
|
|
1645
1728
|
}
|
|
1646
1729
|
|
|
1647
1730
|
exports.AutoForm = AutoForm;
|
|
1731
|
+
exports.DefaultArrayButton = DefaultArrayButton;
|
|
1732
|
+
exports.DefaultArrayCollapseButton = DefaultArrayCollapseButton;
|
|
1733
|
+
exports.DefaultArrayFieldLayout = DefaultArrayFieldLayout;
|
|
1734
|
+
exports.DefaultArrayRowLayout = DefaultArrayRowLayout;
|
|
1735
|
+
exports.DefaultArrayWrapper = DefaultArrayWrapper;
|
|
1648
1736
|
exports.DefaultCheckbox = DefaultCheckbox;
|
|
1649
1737
|
exports.DefaultFieldWrapper = DefaultFieldWrapper;
|
|
1650
1738
|
exports.DefaultInput = DefaultInput;
|
|
1739
|
+
exports.DefaultObjectWrapper = DefaultObjectWrapper;
|
|
1651
1740
|
exports.DefaultSelect = DefaultSelect;
|
|
1652
1741
|
exports.DefaultSubmitButton = DefaultSubmitButton;
|
|
1653
1742
|
exports.FieldRenderer = FieldRenderer;
|