react-f0rm 0.4.0 → 0.5.0
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 +52 -3
- package/dist/devtools/index.cjs.js +20 -13
- package/dist/devtools/index.cjs.js.map +1 -1
- package/dist/devtools/index.d.ts +1 -1
- package/dist/devtools/index.mjs +20 -13
- package/dist/devtools/index.mjs.map +1 -1
- package/dist/{form-b9441d8c.cjs.js → form-B4r7INJ0.cjs.js} +10 -39
- package/dist/form-B4r7INJ0.cjs.js.map +1 -0
- package/dist/{form-94c70b4b.mjs → form-R1hDKjBm.mjs} +11 -40
- package/dist/form-R1hDKjBm.mjs.map +1 -0
- package/dist/{form-61297bc0.d.ts → form-rTlcIiWH.d.ts} +31 -2
- package/dist/index.cjs.js +73 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +27 -11
- package/dist/index.mjs +73 -45
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +73 -43
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/dist/resolvers/standard-schema.cjs.js +1 -1
- package/dist/resolvers/standard-schema.cjs.js.map +1 -1
- package/dist/resolvers/standard-schema.d.ts +2 -2
- package/dist/resolvers/standard-schema.mjs +1 -1
- package/dist/resolvers/standard-schema.mjs.map +1 -1
- package/dist/resolvers/yup.cjs.js +5 -7
- package/dist/resolvers/yup.cjs.js.map +1 -1
- package/dist/resolvers/yup.d.ts +2 -2
- package/dist/resolvers/yup.mjs +5 -7
- package/dist/resolvers/yup.mjs.map +1 -1
- package/dist/resolvers/zod.cjs.js +5 -7
- package/dist/resolvers/zod.cjs.js.map +1 -1
- package/dist/resolvers/zod.d.ts +2 -2
- package/dist/resolvers/zod.mjs +5 -7
- package/dist/resolvers/zod.mjs.map +1 -1
- package/dist/{validate-148fe167.d.ts → validate-CQX7BJOD.d.ts} +1 -1
- package/package.json +52 -51
- package/dist/form-94c70b4b.mjs.map +0 -1
- package/dist/form-b9441d8c.cjs.js.map +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
function create$2() {
|
|
34
34
|
return new Map();
|
|
35
35
|
}
|
|
36
|
-
function emit
|
|
36
|
+
function emit(ee, key) {
|
|
37
37
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
38
38
|
args[_key - 2] = arguments[_key];
|
|
39
39
|
}
|
|
@@ -166,6 +166,31 @@
|
|
|
166
166
|
function isPromise(value) {
|
|
167
167
|
return value && typeof value.then === "function";
|
|
168
168
|
}
|
|
169
|
+
function isEqual(a, b) {
|
|
170
|
+
if (Object.is(a, b)) return true;
|
|
171
|
+
if (a instanceof Date && b instanceof Date)
|
|
172
|
+
return a.getTime() === b.getTime();
|
|
173
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
174
|
+
const isArray = Array.isArray(a);
|
|
175
|
+
if (isArray !== Array.isArray(b)) return false;
|
|
176
|
+
if (isArray) {
|
|
177
|
+
if (a.length !== b.length) return false;
|
|
178
|
+
for (let i = 0; i < a.length; i++) {
|
|
179
|
+
if (!isEqual(a[i], b[i])) return false;
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
const proto = Object.getPrototypeOf(a);
|
|
184
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
185
|
+
if (Object.getPrototypeOf(b) !== proto) return false;
|
|
186
|
+
const keysA = Object.keys(a);
|
|
187
|
+
const keysB = Object.keys(b);
|
|
188
|
+
if (keysA.length !== keysB.length) return false;
|
|
189
|
+
for (const key of keysA) {
|
|
190
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
169
194
|
function waitUntil(emitter, event, isResolve, isReject) {
|
|
170
195
|
return new Promise((resolve, reject) => {
|
|
171
196
|
if (isReject()) return void reject();
|
|
@@ -188,7 +213,6 @@
|
|
|
188
213
|
return { value, key: JSON.stringify(value) };
|
|
189
214
|
}
|
|
190
215
|
|
|
191
|
-
const emit = emit$1;
|
|
192
216
|
const VALIDATION_OUTCOME = /* @__PURE__ */ Symbol("validation-outcome");
|
|
193
217
|
function create(options) {
|
|
194
218
|
const emitter = create$2();
|
|
@@ -324,6 +348,19 @@
|
|
|
324
348
|
for (const { key } of paths) errors.delete(key);
|
|
325
349
|
for (const path of paths) emit(emitter, "errors", path);
|
|
326
350
|
}
|
|
351
|
+
function setServerErrors(form, errors, options) {
|
|
352
|
+
if (!options?.keepExisting) clearErrors(form);
|
|
353
|
+
for (const [name, error] of Object.entries(errors)) {
|
|
354
|
+
setError(
|
|
355
|
+
form,
|
|
356
|
+
name,
|
|
357
|
+
(Array.isArray(error) ? error : [error]).map((message) => ({
|
|
358
|
+
type: "server",
|
|
359
|
+
message
|
|
360
|
+
}))
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
327
364
|
function setTouched(form, name) {
|
|
328
365
|
setTouchedByPath(form, create$1(name));
|
|
329
366
|
}
|
|
@@ -424,7 +461,9 @@
|
|
|
424
461
|
}
|
|
425
462
|
}
|
|
426
463
|
function setInitialValues(form, initialValues) {
|
|
427
|
-
if (form.initialValues === initialValues)
|
|
464
|
+
if (form.initialValues === initialValues || isEqual(form.initialValues, initialValues)) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
428
467
|
form.initialValues = initialValues;
|
|
429
468
|
form.parsedValues = void 0;
|
|
430
469
|
form.values.clear();
|
|
@@ -783,7 +822,7 @@
|
|
|
783
822
|
var nextValue = latestGetSnapshot();
|
|
784
823
|
return !objectIs(inst, nextValue);
|
|
785
824
|
} catch (error) {
|
|
786
|
-
return
|
|
825
|
+
return true;
|
|
787
826
|
}
|
|
788
827
|
}
|
|
789
828
|
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
@@ -825,7 +864,7 @@
|
|
|
825
864
|
function useSyncExternalStore$2(subscribe, getSnapshot) {
|
|
826
865
|
didWarnOld18Alpha ||
|
|
827
866
|
void 0 === React$1.startTransition ||
|
|
828
|
-
((didWarnOld18Alpha =
|
|
867
|
+
((didWarnOld18Alpha = true),
|
|
829
868
|
console.error(
|
|
830
869
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
831
870
|
));
|
|
@@ -836,7 +875,7 @@
|
|
|
836
875
|
(console.error(
|
|
837
876
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
838
877
|
),
|
|
839
|
-
(didWarnUncachedGetSnapshot =
|
|
878
|
+
(didWarnUncachedGetSnapshot = true));
|
|
840
879
|
}
|
|
841
880
|
cachedValue = useState({
|
|
842
881
|
inst: { value: value, getSnapshot: getSnapshot }
|
|
@@ -870,7 +909,7 @@
|
|
|
870
909
|
var nextValue = latestGetSnapshot();
|
|
871
910
|
return !objectIs(inst, nextValue);
|
|
872
911
|
} catch (error) {
|
|
873
|
-
return
|
|
912
|
+
return true;
|
|
874
913
|
}
|
|
875
914
|
}
|
|
876
915
|
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
@@ -886,8 +925,8 @@
|
|
|
886
925
|
useEffect = React$1.useEffect,
|
|
887
926
|
useLayoutEffect = React$1.useLayoutEffect,
|
|
888
927
|
useDebugValue = React$1.useDebugValue,
|
|
889
|
-
didWarnOld18Alpha =
|
|
890
|
-
didWarnUncachedGetSnapshot =
|
|
928
|
+
didWarnOld18Alpha = false,
|
|
929
|
+
didWarnUncachedGetSnapshot = false,
|
|
891
930
|
shim =
|
|
892
931
|
"undefined" === typeof window ||
|
|
893
932
|
"undefined" === typeof window.document ||
|
|
@@ -904,13 +943,21 @@
|
|
|
904
943
|
return useSyncExternalStoreShim_development;
|
|
905
944
|
}
|
|
906
945
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
946
|
+
var hasRequiredShim;
|
|
947
|
+
|
|
948
|
+
function requireShim () {
|
|
949
|
+
if (hasRequiredShim) return shim.exports;
|
|
950
|
+
hasRequiredShim = 1;
|
|
951
|
+
|
|
952
|
+
if (process.env.NODE_ENV === 'production') {
|
|
953
|
+
shim.exports = requireUseSyncExternalStoreShim_production();
|
|
954
|
+
} else {
|
|
955
|
+
shim.exports = requireUseSyncExternalStoreShim_development();
|
|
956
|
+
}
|
|
957
|
+
return shim.exports;
|
|
911
958
|
}
|
|
912
959
|
|
|
913
|
-
var shimExports =
|
|
960
|
+
var shimExports = requireShim();
|
|
914
961
|
|
|
915
962
|
function isDescendant(key, ancestorKey) {
|
|
916
963
|
return key.startsWith(`${ancestorKey.slice(0, -1)},`);
|
|
@@ -1086,31 +1133,6 @@
|
|
|
1086
1133
|
function useSubmitCount(form) {
|
|
1087
1134
|
return useWatch(form.emitter, "submitCount", () => form.submitCount);
|
|
1088
1135
|
}
|
|
1089
|
-
function isEqual(a, b) {
|
|
1090
|
-
if (Object.is(a, b)) return true;
|
|
1091
|
-
if (a instanceof Date && b instanceof Date)
|
|
1092
|
-
return a.getTime() === b.getTime();
|
|
1093
|
-
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
1094
|
-
const isArray = Array.isArray(a);
|
|
1095
|
-
if (isArray !== Array.isArray(b)) return false;
|
|
1096
|
-
if (isArray) {
|
|
1097
|
-
if (a.length !== b.length) return false;
|
|
1098
|
-
for (let i = 0; i < a.length; i++) {
|
|
1099
|
-
if (!isEqual(a[i], b[i])) return false;
|
|
1100
|
-
}
|
|
1101
|
-
return true;
|
|
1102
|
-
}
|
|
1103
|
-
const proto = Object.getPrototypeOf(a);
|
|
1104
|
-
if (proto !== Object.prototype && proto !== null) return false;
|
|
1105
|
-
if (Object.getPrototypeOf(b) !== proto) return false;
|
|
1106
|
-
const keysA = Object.keys(a);
|
|
1107
|
-
const keysB = Object.keys(b);
|
|
1108
|
-
if (keysA.length !== keysB.length) return false;
|
|
1109
|
-
for (const key of keysA) {
|
|
1110
|
-
if (!isEqual(a[key], b[key])) return false;
|
|
1111
|
-
}
|
|
1112
|
-
return true;
|
|
1113
|
-
}
|
|
1114
1136
|
|
|
1115
1137
|
function usePath(name) {
|
|
1116
1138
|
const path = React.useMemo(() => create$1(normalizePath(name)), [name]);
|
|
@@ -1493,6 +1515,9 @@
|
|
|
1493
1515
|
const id = key.replace(/["'[\],\s]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1494
1516
|
return id || "field";
|
|
1495
1517
|
}
|
|
1518
|
+
function fieldErrorId(name) {
|
|
1519
|
+
return errorIdFromKey(create$1(name).key);
|
|
1520
|
+
}
|
|
1496
1521
|
const Field = React__namespace.forwardRef(
|
|
1497
1522
|
({
|
|
1498
1523
|
validate,
|
|
@@ -1581,16 +1606,17 @@
|
|
|
1581
1606
|
);
|
|
1582
1607
|
const toValue = eventToValue ?? ((e) => e.target.value);
|
|
1583
1608
|
const errorId = errorIdFromKey(fieldKey);
|
|
1609
|
+
const describedBy = error ? [props["aria-describedby"], errorId].filter(Boolean).join(" ") : props["aria-describedby"];
|
|
1584
1610
|
return /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, /* @__PURE__ */ React__namespace.createElement(
|
|
1585
1611
|
Component,
|
|
1586
1612
|
{
|
|
1587
|
-
"aria-invalid": error ? true : void 0,
|
|
1588
|
-
"aria-describedby": error && renderError ? errorId : void 0,
|
|
1589
1613
|
...props,
|
|
1590
1614
|
name: fieldKey,
|
|
1591
1615
|
onBlur,
|
|
1592
1616
|
...asProps,
|
|
1593
1617
|
...valueToProps ? valueToProps(value) : { value },
|
|
1618
|
+
"aria-invalid": error ? true : props["aria-invalid"],
|
|
1619
|
+
"aria-describedby": describedBy,
|
|
1594
1620
|
disabled: isDisabled,
|
|
1595
1621
|
onChange: (e) => onChange(toValue(e)),
|
|
1596
1622
|
ref: mergedRef
|
|
@@ -1632,12 +1658,13 @@
|
|
|
1632
1658
|
return /* @__PURE__ */ React__namespace.createElement(
|
|
1633
1659
|
"input",
|
|
1634
1660
|
{
|
|
1635
|
-
"aria-invalid": error ? true : void 0,
|
|
1636
1661
|
...props,
|
|
1637
1662
|
name: fieldKey,
|
|
1638
1663
|
onBlur,
|
|
1639
1664
|
type: "checkbox",
|
|
1640
1665
|
checked: !!value,
|
|
1666
|
+
"aria-invalid": error ? true : props["aria-invalid"],
|
|
1667
|
+
"aria-describedby": error ? [props["aria-describedby"], errorIdFromKey(fieldKey)].filter(Boolean).join(" ") : props["aria-describedby"],
|
|
1641
1668
|
disabled: isDisabled,
|
|
1642
1669
|
onChange: (e) => onChange(e.target.checked),
|
|
1643
1670
|
ref
|
|
@@ -1685,12 +1712,13 @@
|
|
|
1685
1712
|
return /* @__PURE__ */ React__namespace.createElement(
|
|
1686
1713
|
"select",
|
|
1687
1714
|
{
|
|
1688
|
-
"aria-invalid": error ? true : void 0,
|
|
1689
1715
|
...props,
|
|
1690
1716
|
name: fieldKey,
|
|
1691
1717
|
onBlur,
|
|
1692
1718
|
multiple,
|
|
1693
1719
|
value: toSelectValue(multiple, value),
|
|
1720
|
+
"aria-invalid": error ? true : props["aria-invalid"],
|
|
1721
|
+
"aria-describedby": error ? [props["aria-describedby"], errorIdFromKey(fieldKey)].filter(Boolean).join(" ") : props["aria-describedby"],
|
|
1694
1722
|
disabled: isDisabled,
|
|
1695
1723
|
onChange: (e) => onChange(
|
|
1696
1724
|
multiple ? Array.from(e.target.selectedOptions, (option) => option.value) : e.target.value
|
|
@@ -1715,6 +1743,7 @@
|
|
|
1715
1743
|
exports.createForm = create;
|
|
1716
1744
|
exports.createFormContext = createFormContext;
|
|
1717
1745
|
exports.ensureValidate = ensureValidate;
|
|
1746
|
+
exports.fieldErrorId = fieldErrorId;
|
|
1718
1747
|
exports.getDirtyFields = getDirtyFields;
|
|
1719
1748
|
exports.getError = getError;
|
|
1720
1749
|
exports.getErrorByPath = getErrorByPath;
|
|
@@ -1744,6 +1773,7 @@
|
|
|
1744
1773
|
exports.setFocus = setFocus;
|
|
1745
1774
|
exports.setInitialValues = setInitialValues;
|
|
1746
1775
|
exports.setIsSubmitting = setIsSubmitting;
|
|
1776
|
+
exports.setServerErrors = setServerErrors;
|
|
1747
1777
|
exports.setSubmitSuccessful = setSubmitSuccessful;
|
|
1748
1778
|
exports.setTouched = setTouched;
|
|
1749
1779
|
exports.setTouchedByPath = setTouchedByPath;
|