remix-validated-form 4.5.4 → 4.5.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/.turbo/turbo-build.log +8 -8
- package/browser/internal/logic/requestSubmit.d.ts +5 -0
- package/browser/internal/logic/requestSubmit.js +41 -0
- package/browser/internal/state/createFormStore.js +2 -1
- package/dist/remix-validated-form.cjs.js +4 -4
- package/dist/remix-validated-form.cjs.js.map +1 -1
- package/dist/remix-validated-form.es.js +447 -345
- package/dist/remix-validated-form.es.js.map +1 -1
- package/dist/remix-validated-form.umd.js +4 -4
- package/dist/remix-validated-form.umd.js.map +1 -1
- package/dist/types/internal/logic/requestSubmit.d.ts +5 -0
- package/package.json +2 -1
- package/src/internal/logic/requestSubmit.test.tsx +24 -0
- package/src/internal/logic/requestSubmit.ts +103 -0
- package/src/internal/state/createFormStore.ts +2 -1
@@ -1,34 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a2, b2) => {
|
9
|
-
for (var prop in b2 || (b2 = {}))
|
10
|
-
if (__hasOwnProp.call(b2, prop))
|
11
|
-
__defNormalProp(a2, prop, b2[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b2)) {
|
14
|
-
if (__propIsEnum.call(b2, prop))
|
15
|
-
__defNormalProp(a2, prop, b2[prop]);
|
16
|
-
}
|
17
|
-
return a2;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
|
20
|
-
var __objRest = (source, exclude) => {
|
21
|
-
var target = {};
|
22
|
-
for (var prop in source)
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
24
|
-
target[prop] = source[prop];
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
28
|
-
target[prop] = source[prop];
|
29
|
-
}
|
30
|
-
return target;
|
31
|
-
};
|
32
1
|
import React, { createContext, useDebugValue, useContext, useCallback, useEffect, useMemo, useRef, useLayoutEffect, useState } from "react";
|
33
2
|
import { useActionData, useMatches, useTransition, Form, useSubmit } from "@remix-run/react";
|
34
3
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
@@ -225,7 +194,9 @@ var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
225
194
|
var funcProto = Function.prototype, objectProto$b = Object.prototype;
|
226
195
|
var funcToString = funcProto.toString;
|
227
196
|
var hasOwnProperty$9 = objectProto$b.hasOwnProperty;
|
228
|
-
var reIsNative = RegExp(
|
197
|
+
var reIsNative = RegExp(
|
198
|
+
"^" + funcToString.call(hasOwnProperty$9).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
199
|
+
);
|
229
200
|
function baseIsNative$1(value) {
|
230
201
|
if (!isObject$3(value) || isMasked(value)) {
|
231
202
|
return false;
|
@@ -497,7 +468,7 @@ function setToArray$3(set2) {
|
|
497
468
|
return result;
|
498
469
|
}
|
499
470
|
var _setToArray = setToArray$3;
|
500
|
-
var Symbol$2 = _Symbol,
|
471
|
+
var Symbol$2 = _Symbol, Uint8Array = _Uint8Array, eq$1 = eq_1, equalArrays$1 = _equalArrays, mapToArray = _mapToArray, setToArray$2 = _setToArray;
|
501
472
|
var COMPARE_PARTIAL_FLAG$4 = 1, COMPARE_UNORDERED_FLAG$2 = 2;
|
502
473
|
var boolTag$1 = "[object Boolean]", dateTag$1 = "[object Date]", errorTag$1 = "[object Error]", mapTag$2 = "[object Map]", numberTag$1 = "[object Number]", regexpTag$1 = "[object RegExp]", setTag$2 = "[object Set]", stringTag$1 = "[object String]", symbolTag$1 = "[object Symbol]";
|
503
474
|
var arrayBufferTag$1 = "[object ArrayBuffer]", dataViewTag$2 = "[object DataView]";
|
@@ -511,7 +482,7 @@ function equalByTag$1(object, other, tag, bitmask, customizer, equalFunc, stack)
|
|
511
482
|
object = object.buffer;
|
512
483
|
other = other.buffer;
|
513
484
|
case arrayBufferTag$1:
|
514
|
-
if (object.byteLength != other.byteLength || !equalFunc(new
|
485
|
+
if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
515
486
|
return false;
|
516
487
|
}
|
517
488
|
return true;
|
@@ -632,8 +603,8 @@ var stubFalse_1 = stubFalse;
|
|
632
603
|
var freeExports = exports && !exports.nodeType && exports;
|
633
604
|
var freeModule = freeExports && true && module && !module.nodeType && module;
|
634
605
|
var moduleExports = freeModule && freeModule.exports === freeExports;
|
635
|
-
var
|
636
|
-
var nativeIsBuffer =
|
606
|
+
var Buffer = moduleExports ? root2.Buffer : void 0;
|
607
|
+
var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0;
|
637
608
|
var isBuffer2 = nativeIsBuffer || stubFalse2;
|
638
609
|
module.exports = isBuffer2;
|
639
610
|
})(isBuffer$2, isBuffer$2.exports);
|
@@ -1345,10 +1316,14 @@ const createGetInputProps = ({
|
|
1345
1316
|
validationBehavior,
|
1346
1317
|
name
|
1347
1318
|
}) => {
|
1348
|
-
const validationBehaviors =
|
1319
|
+
const validationBehaviors = {
|
1320
|
+
...defaultValidationBehavior,
|
1321
|
+
...validationBehavior
|
1322
|
+
};
|
1349
1323
|
return (props = {}) => {
|
1350
1324
|
const behavior = hasBeenSubmitted ? validationBehaviors.whenSubmitted : touched ? validationBehaviors.whenTouched : validationBehaviors.initial;
|
1351
|
-
const inputProps =
|
1325
|
+
const inputProps = {
|
1326
|
+
...props,
|
1352
1327
|
onChange: (...args) => {
|
1353
1328
|
var _a;
|
1354
1329
|
if (behavior === "onChange")
|
@@ -1365,7 +1340,7 @@ const createGetInputProps = ({
|
|
1365
1340
|
return (_a = props == null ? void 0 : props.onBlur) == null ? void 0 : _a.call(props, ...args);
|
1366
1341
|
},
|
1367
1342
|
name
|
1368
|
-
}
|
1343
|
+
};
|
1369
1344
|
if (props.type === "checkbox") {
|
1370
1345
|
inputProps.defaultChecked = getCheckboxChecked(props.value, defaultValue);
|
1371
1346
|
} else if (props.type === "radio") {
|
@@ -1444,9 +1419,9 @@ var useSyncExternalStoreShim_production_min = {};
|
|
1444
1419
|
*/
|
1445
1420
|
var e = React;
|
1446
1421
|
function h$2(a2, b2) {
|
1447
|
-
return a2 === b2 && (
|
1422
|
+
return a2 === b2 && (0 !== a2 || 1 / a2 === 1 / b2) || a2 !== a2 && b2 !== b2;
|
1448
1423
|
}
|
1449
|
-
var k$1 = typeof Object.is
|
1424
|
+
var k$1 = "function" === typeof Object.is ? Object.is : h$2, l$1 = e.useState, m = e.useEffect, n$2 = e.useLayoutEffect, p$2 = e.useDebugValue;
|
1450
1425
|
function q$2(a2, b2) {
|
1451
1426
|
var d2 = b2(), f2 = l$1({ inst: { value: d2, getSnapshot: b2 } }), c2 = f2[0].inst, g2 = f2[1];
|
1452
1427
|
n$2(function() {
|
@@ -1476,8 +1451,8 @@ function r$2(a2) {
|
|
1476
1451
|
function t$2(a2, b2) {
|
1477
1452
|
return b2();
|
1478
1453
|
}
|
1479
|
-
var u$2 = typeof window
|
1480
|
-
useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore
|
1454
|
+
var u$2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t$2 : q$2;
|
1455
|
+
useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u$2;
|
1481
1456
|
{
|
1482
1457
|
shim.exports = useSyncExternalStoreShim_production_min;
|
1483
1458
|
}
|
@@ -1492,12 +1467,12 @@ useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternal
|
|
1492
1467
|
*/
|
1493
1468
|
var h$1 = React, n$1 = shim.exports;
|
1494
1469
|
function p$1(a2, b2) {
|
1495
|
-
return a2 === b2 && (
|
1470
|
+
return a2 === b2 && (0 !== a2 || 1 / a2 === 1 / b2) || a2 !== a2 && b2 !== b2;
|
1496
1471
|
}
|
1497
|
-
var q$1 = typeof Object.is
|
1472
|
+
var q$1 = "function" === typeof Object.is ? Object.is : p$1, r$1 = n$1.useSyncExternalStore, t$1 = h$1.useRef, u$1 = h$1.useEffect, v$1 = h$1.useMemo, w$1 = h$1.useDebugValue;
|
1498
1473
|
withSelector_production_min.useSyncExternalStoreWithSelector = function(a2, b2, e2, l2, g2) {
|
1499
1474
|
var c2 = t$1(null);
|
1500
|
-
if (c2.current
|
1475
|
+
if (null === c2.current) {
|
1501
1476
|
var f2 = { hasValue: false, value: null };
|
1502
1477
|
c2.current = f2;
|
1503
1478
|
} else
|
@@ -1508,7 +1483,7 @@ withSelector_production_min.useSyncExternalStoreWithSelector = function(a2, b2,
|
|
1508
1483
|
c3 = true;
|
1509
1484
|
d3 = a4;
|
1510
1485
|
a4 = l2(a4);
|
1511
|
-
if (
|
1486
|
+
if (void 0 !== g2 && f2.hasValue) {
|
1512
1487
|
var b3 = f2.value;
|
1513
1488
|
if (g2(b3, a4))
|
1514
1489
|
return k2 = b3;
|
@@ -1519,15 +1494,15 @@ withSelector_production_min.useSyncExternalStoreWithSelector = function(a2, b2,
|
|
1519
1494
|
if (q$1(d3, a4))
|
1520
1495
|
return b3;
|
1521
1496
|
var e3 = l2(a4);
|
1522
|
-
if (
|
1497
|
+
if (void 0 !== g2 && g2(b3, e3))
|
1523
1498
|
return b3;
|
1524
1499
|
d3 = a4;
|
1525
1500
|
return k2 = e3;
|
1526
1501
|
}
|
1527
|
-
var c3 = false, d3, k2, m2 =
|
1502
|
+
var c3 = false, d3, k2, m2 = void 0 === e2 ? null : e2;
|
1528
1503
|
return [function() {
|
1529
1504
|
return a3(b2());
|
1530
|
-
},
|
1505
|
+
}, null === m2 ? void 0 : function() {
|
1531
1506
|
return a3(m2());
|
1532
1507
|
}];
|
1533
1508
|
}, [b2, e2, l2, g2]);
|
@@ -1567,18 +1542,18 @@ function r(n2) {
|
|
1567
1542
|
}
|
1568
1543
|
function t(n2) {
|
1569
1544
|
return !!n2 && (function(n3) {
|
1570
|
-
if (!n3 || typeof n3
|
1545
|
+
if (!n3 || "object" != typeof n3)
|
1571
1546
|
return false;
|
1572
1547
|
var r2 = Object.getPrototypeOf(n3);
|
1573
|
-
if (
|
1548
|
+
if (null === r2)
|
1574
1549
|
return true;
|
1575
1550
|
var t2 = Object.hasOwnProperty.call(r2, "constructor") && r2.constructor;
|
1576
|
-
return t2 === Object || typeof t2
|
1551
|
+
return t2 === Object || "function" == typeof t2 && Function.toString.call(t2) === Z;
|
1577
1552
|
}(n2) || Array.isArray(n2) || !!n2[L] || !!n2.constructor[L] || s(n2) || v(n2));
|
1578
1553
|
}
|
1579
1554
|
function i(n2, r2, t2) {
|
1580
|
-
|
1581
|
-
t2 && typeof e2
|
1555
|
+
void 0 === t2 && (t2 = false), 0 === o(n2) ? (t2 ? Object.keys : nn)(n2).forEach(function(e2) {
|
1556
|
+
t2 && "symbol" == typeof e2 || r2(e2, n2[e2], n2);
|
1582
1557
|
}) : n2.forEach(function(t3, e2) {
|
1583
1558
|
return r2(e2, t3, n2);
|
1584
1559
|
});
|
@@ -1588,17 +1563,17 @@ function o(n2) {
|
|
1588
1563
|
return r2 ? r2.i > 3 ? r2.i - 4 : r2.i : Array.isArray(n2) ? 1 : s(n2) ? 2 : v(n2) ? 3 : 0;
|
1589
1564
|
}
|
1590
1565
|
function u(n2, r2) {
|
1591
|
-
return o(n2)
|
1566
|
+
return 2 === o(n2) ? n2.has(r2) : Object.prototype.hasOwnProperty.call(n2, r2);
|
1592
1567
|
}
|
1593
1568
|
function a(n2, r2) {
|
1594
|
-
return o(n2)
|
1569
|
+
return 2 === o(n2) ? n2.get(r2) : n2[r2];
|
1595
1570
|
}
|
1596
1571
|
function f(n2, r2, t2) {
|
1597
1572
|
var e2 = o(n2);
|
1598
|
-
|
1573
|
+
2 === e2 ? n2.set(r2, t2) : 3 === e2 ? (n2.delete(r2), n2.add(t2)) : n2[r2] = t2;
|
1599
1574
|
}
|
1600
1575
|
function c(n2, r2) {
|
1601
|
-
return n2 === r2 ?
|
1576
|
+
return n2 === r2 ? 0 !== n2 || 1 / n2 == 1 / r2 : n2 != n2 && r2 != r2;
|
1602
1577
|
}
|
1603
1578
|
function s(n2) {
|
1604
1579
|
return X && n2 instanceof Map;
|
@@ -1616,12 +1591,12 @@ function l(n2) {
|
|
1616
1591
|
delete r2[Q];
|
1617
1592
|
for (var t2 = nn(r2), e2 = 0; e2 < t2.length; e2++) {
|
1618
1593
|
var i2 = t2[e2], o2 = r2[i2];
|
1619
|
-
o2.writable
|
1594
|
+
false === o2.writable && (o2.writable = true, o2.configurable = true), (o2.get || o2.set) && (r2[i2] = { configurable: true, writable: true, enumerable: o2.enumerable, value: n2[i2] });
|
1620
1595
|
}
|
1621
1596
|
return Object.create(Object.getPrototypeOf(n2), r2);
|
1622
1597
|
}
|
1623
1598
|
function d(n2, e2) {
|
1624
|
-
return
|
1599
|
+
return void 0 === e2 && (e2 = false), y(n2) || r(n2) || !t(n2) ? n2 : (o(n2) > 1 && (n2.set = n2.add = n2.clear = n2.delete = h), Object.freeze(n2), e2 && i(n2, function(n3, r2) {
|
1625
1600
|
return d(r2, true);
|
1626
1601
|
}, true), n2);
|
1627
1602
|
}
|
@@ -1629,7 +1604,7 @@ function h() {
|
|
1629
1604
|
n(2);
|
1630
1605
|
}
|
1631
1606
|
function y(n2) {
|
1632
|
-
return
|
1607
|
+
return null == n2 || "object" != typeof n2 || Object.isFrozen(n2);
|
1633
1608
|
}
|
1634
1609
|
function b(r2) {
|
1635
1610
|
var t2 = tn[r2];
|
@@ -1652,11 +1627,11 @@ function w(n2) {
|
|
1652
1627
|
}
|
1653
1628
|
function S(n2) {
|
1654
1629
|
var r2 = n2[Q];
|
1655
|
-
r2.i
|
1630
|
+
0 === r2.i || 1 === r2.i ? r2.j() : r2.O = true;
|
1656
1631
|
}
|
1657
1632
|
function P(r2, e2) {
|
1658
1633
|
e2._ = e2.p.length;
|
1659
|
-
var i2 = e2.p[0], o2 =
|
1634
|
+
var i2 = e2.p[0], o2 = void 0 !== r2 && r2 !== i2;
|
1660
1635
|
return e2.h.g || b("ES5").S(e2, r2, o2), o2 ? (i2[Q].P && (O(e2), n(4)), t(r2) && (r2 = M(e2, r2), e2.l || x(e2, r2)), e2.u && b("Patches").M(i2[Q].t, r2, e2.u, e2.s)) : r2 = M(e2, i2, []), O(e2), e2.u && e2.v(e2.u, e2.s), r2 !== H ? r2 : void 0;
|
1661
1636
|
}
|
1662
1637
|
function M(n2, r2, t2) {
|
@@ -1673,8 +1648,8 @@ function M(n2, r2, t2) {
|
|
1673
1648
|
return x(n2, e2.t, true), e2.t;
|
1674
1649
|
if (!e2.I) {
|
1675
1650
|
e2.I = true, e2.A._--;
|
1676
|
-
var o2 = e2.i
|
1677
|
-
i(e2.i
|
1651
|
+
var o2 = 4 === e2.i || 5 === e2.i ? e2.o = l(e2.k) : e2.o;
|
1652
|
+
i(3 === e2.i ? new Set(o2) : o2, function(r3, i2) {
|
1678
1653
|
return A(n2, e2, o2, r3, i2, t2);
|
1679
1654
|
}), x(n2, o2, false), t2 && n2.u && b("Patches").R(e2, t2, n2.u, n2.s);
|
1680
1655
|
}
|
@@ -1682,7 +1657,7 @@ function M(n2, r2, t2) {
|
|
1682
1657
|
}
|
1683
1658
|
function A(e2, i2, o2, a2, c2, s2) {
|
1684
1659
|
if (r(c2)) {
|
1685
|
-
var v2 = M(e2, c2, s2 && i2 && i2.i
|
1660
|
+
var v2 = M(e2, c2, s2 && i2 && 3 !== i2.i && !u(i2.D, a2) ? s2.concat(a2) : void 0);
|
1686
1661
|
if (f(o2, a2, v2), !r(v2))
|
1687
1662
|
return;
|
1688
1663
|
e2.m = false;
|
@@ -1694,7 +1669,7 @@ function A(e2, i2, o2, a2, c2, s2) {
|
|
1694
1669
|
}
|
1695
1670
|
}
|
1696
1671
|
function x(n2, r2, t2) {
|
1697
|
-
|
1672
|
+
void 0 === t2 && (t2 = false), n2.h.F && n2.m && d(r2, t2);
|
1698
1673
|
}
|
1699
1674
|
function z(n2, r2) {
|
1700
1675
|
var t2 = n2[Q];
|
@@ -1737,7 +1712,7 @@ function D(e2) {
|
|
1737
1712
|
e3 = F(r2, c2);
|
1738
1713
|
return i(e3, function(r3, t2) {
|
1739
1714
|
u2 && a(u2.t, r3) === t2 || f(e3, r3, n2(t2));
|
1740
|
-
}),
|
1715
|
+
}), 3 === c2 ? new Set(e3) : e3;
|
1741
1716
|
}(e2);
|
1742
1717
|
}
|
1743
1718
|
function F(n2, r2) {
|
@@ -1749,7 +1724,7 @@ function F(n2, r2) {
|
|
1749
1724
|
}
|
1750
1725
|
return l(n2);
|
1751
1726
|
}
|
1752
|
-
var G, U, W = typeof Symbol
|
1727
|
+
var G, U, W = "undefined" != typeof Symbol && "symbol" == typeof Symbol("x"), X = "undefined" != typeof Map, q = "undefined" != typeof Set, B = "undefined" != typeof Proxy && void 0 !== Proxy.revocable && "undefined" != typeof Reflect, H = W ? Symbol.for("immer-nothing") : ((G = {})["immer-nothing"] = true, G), L = W ? Symbol.for("immer-draftable") : "__$immer_draftable", Q = W ? Symbol.for("immer-state") : "__$immer_state", Z = "" + Object.prototype.constructor, nn = "undefined" != typeof Reflect && Reflect.ownKeys ? Reflect.ownKeys : void 0 !== Object.getOwnPropertySymbols ? function(n2) {
|
1753
1728
|
return Object.getOwnPropertyNames(n2).concat(Object.getOwnPropertySymbols(n2));
|
1754
1729
|
} : Object.getOwnPropertyNames, rn = Object.getOwnPropertyDescriptors || function(n2) {
|
1755
1730
|
var r2 = {};
|
@@ -1763,7 +1738,7 @@ var G, U, W = typeof Symbol != "undefined" && typeof Symbol("x") == "symbol", X
|
|
1763
1738
|
if (!u(e2, r2))
|
1764
1739
|
return function(n3, r3, t2) {
|
1765
1740
|
var e3, i3 = I(r3, t2);
|
1766
|
-
return i3 ? "value" in i3 ? i3.value : (e3 = i3.get)
|
1741
|
+
return i3 ? "value" in i3 ? i3.value : null === (e3 = i3.get) || void 0 === e3 ? void 0 : e3.call(n3.k) : void 0;
|
1767
1742
|
}(n2, e2, r2);
|
1768
1743
|
var i2 = e2[r2];
|
1769
1744
|
return n2.I || !t(i2) ? i2 : i2 === z(n2.t, r2) ? (E(n2), n2.o[r2] = R(n2.A.h, i2, n2)) : i2;
|
@@ -1773,22 +1748,22 @@ var G, U, W = typeof Symbol != "undefined" && typeof Symbol("x") == "symbol", X
|
|
1773
1748
|
return Reflect.ownKeys(p(n2));
|
1774
1749
|
}, set: function(n2, r2, t2) {
|
1775
1750
|
var e2 = I(p(n2), r2);
|
1776
|
-
if (
|
1751
|
+
if (null == e2 ? void 0 : e2.set)
|
1777
1752
|
return e2.set.call(n2.k, t2), true;
|
1778
1753
|
if (!n2.P) {
|
1779
|
-
var i2 = z(p(n2), r2), o2 =
|
1754
|
+
var i2 = z(p(n2), r2), o2 = null == i2 ? void 0 : i2[Q];
|
1780
1755
|
if (o2 && o2.t === t2)
|
1781
1756
|
return n2.o[r2] = t2, n2.D[r2] = false, true;
|
1782
|
-
if (c(t2, i2) && (
|
1757
|
+
if (c(t2, i2) && (void 0 !== t2 || u(n2.t, r2)))
|
1783
1758
|
return true;
|
1784
1759
|
E(n2), k(n2);
|
1785
1760
|
}
|
1786
|
-
return n2.o[r2] === t2 &&
|
1761
|
+
return n2.o[r2] === t2 && "number" != typeof t2 && (void 0 !== t2 || r2 in n2.o) || (n2.o[r2] = t2, n2.D[r2] = true, true);
|
1787
1762
|
}, deleteProperty: function(n2, r2) {
|
1788
|
-
return z(n2.t, r2)
|
1763
|
+
return void 0 !== z(n2.t, r2) || r2 in n2.t ? (n2.D[r2] = false, E(n2), k(n2)) : delete n2.D[r2], n2.o && delete n2.o[r2], true;
|
1789
1764
|
}, getOwnPropertyDescriptor: function(n2, r2) {
|
1790
1765
|
var t2 = p(n2), e2 = Reflect.getOwnPropertyDescriptor(t2, r2);
|
1791
|
-
return e2 ? { writable: true, configurable: n2.i
|
1766
|
+
return e2 ? { writable: true, configurable: 1 !== n2.i || "length" !== r2, enumerable: e2.enumerable, value: t2[r2] } : e2;
|
1792
1767
|
}, defineProperty: function() {
|
1793
1768
|
n(11);
|
1794
1769
|
}, getPrototypeOf: function(n2) {
|
@@ -1809,13 +1784,13 @@ var un = function() {
|
|
1809
1784
|
function e2(r2) {
|
1810
1785
|
var e3 = this;
|
1811
1786
|
this.g = B, this.F = true, this.produce = function(r3, i3, o2) {
|
1812
|
-
if (typeof r3
|
1787
|
+
if ("function" == typeof r3 && "function" != typeof i3) {
|
1813
1788
|
var u2 = i3;
|
1814
1789
|
i3 = r3;
|
1815
1790
|
var a2 = e3;
|
1816
1791
|
return function(n2) {
|
1817
1792
|
var r4 = this;
|
1818
|
-
|
1793
|
+
void 0 === n2 && (n2 = u2);
|
1819
1794
|
for (var t2 = arguments.length, e4 = Array(t2 > 1 ? t2 - 1 : 0), o3 = 1; o3 < t2; o3++)
|
1820
1795
|
e4[o3 - 1] = arguments[o3];
|
1821
1796
|
return a2.produce(n2, function(n3) {
|
@@ -1825,21 +1800,21 @@ var un = function() {
|
|
1825
1800
|
};
|
1826
1801
|
}
|
1827
1802
|
var f2;
|
1828
|
-
if (typeof i3
|
1803
|
+
if ("function" != typeof i3 && n(6), void 0 !== o2 && "function" != typeof o2 && n(7), t(r3)) {
|
1829
1804
|
var c2 = w(e3), s2 = R(e3, r3, void 0), v2 = true;
|
1830
1805
|
try {
|
1831
1806
|
f2 = i3(s2), v2 = false;
|
1832
1807
|
} finally {
|
1833
1808
|
v2 ? O(c2) : g(c2);
|
1834
1809
|
}
|
1835
|
-
return typeof Promise
|
1810
|
+
return "undefined" != typeof Promise && f2 instanceof Promise ? f2.then(function(n2) {
|
1836
1811
|
return j(c2, o2), P(n2, c2);
|
1837
1812
|
}, function(n2) {
|
1838
1813
|
throw O(c2), n2;
|
1839
1814
|
}) : (j(c2, o2), P(f2, c2));
|
1840
1815
|
}
|
1841
|
-
if (!r3 || typeof r3
|
1842
|
-
if ((f2 = i3(r3))
|
1816
|
+
if (!r3 || "object" != typeof r3) {
|
1817
|
+
if (void 0 === (f2 = i3(r3)) && (f2 = r3), f2 === H && (f2 = void 0), e3.F && d(f2, true), o2) {
|
1843
1818
|
var p2 = [], l2 = [];
|
1844
1819
|
b("Patches").M(r3, f2, p2, l2), o2(p2, l2);
|
1845
1820
|
}
|
@@ -1847,7 +1822,7 @@ var un = function() {
|
|
1847
1822
|
}
|
1848
1823
|
n(21, r3);
|
1849
1824
|
}, this.produceWithPatches = function(n2, r3) {
|
1850
|
-
if (typeof n2
|
1825
|
+
if ("function" == typeof n2)
|
1851
1826
|
return function(r4) {
|
1852
1827
|
for (var t3 = arguments.length, i4 = Array(t3 > 1 ? t3 - 1 : 0), o3 = 1; o3 < t3; o3++)
|
1853
1828
|
i4[o3 - 1] = arguments[o3];
|
@@ -1858,10 +1833,10 @@ var un = function() {
|
|
1858
1833
|
var t2, i3, o2 = e3.produce(n2, r3, function(n3, r4) {
|
1859
1834
|
t2 = n3, i3 = r4;
|
1860
1835
|
});
|
1861
|
-
return typeof Promise
|
1836
|
+
return "undefined" != typeof Promise && o2 instanceof Promise ? o2.then(function(n3) {
|
1862
1837
|
return [n3, t2, i3];
|
1863
1838
|
}) : [o2, t2, i3];
|
1864
|
-
}, typeof (
|
1839
|
+
}, "boolean" == typeof (null == r2 ? void 0 : r2.useProxies) && this.setUseProxies(r2.useProxies), "boolean" == typeof (null == r2 ? void 0 : r2.autoFreeze) && this.setAutoFreeze(r2.autoFreeze);
|
1865
1840
|
}
|
1866
1841
|
var i2 = e2.prototype;
|
1867
1842
|
return i2.createDraft = function(e3) {
|
@@ -1880,7 +1855,7 @@ var un = function() {
|
|
1880
1855
|
var e3;
|
1881
1856
|
for (e3 = t2.length - 1; e3 >= 0; e3--) {
|
1882
1857
|
var i3 = t2[e3];
|
1883
|
-
if (i3.path.length
|
1858
|
+
if (0 === i3.path.length && "replace" === i3.op) {
|
1884
1859
|
n2 = i3.value;
|
1885
1860
|
break;
|
1886
1861
|
}
|
@@ -1906,73 +1881,114 @@ const immerImpl = (initializer) => (set2, get2, store) => {
|
|
1906
1881
|
return initializer(store.setState, get2, store);
|
1907
1882
|
};
|
1908
1883
|
const immer = immerImpl;
|
1909
|
-
const
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1884
|
+
const requestSubmit = (element, submitter) => {
|
1885
|
+
if (typeof Object.getPrototypeOf(element).requestSubmit === "function" && true) {
|
1886
|
+
element.requestSubmit(submitter);
|
1887
|
+
return;
|
1888
|
+
}
|
1889
|
+
if (submitter) {
|
1890
|
+
validateSubmitter(element, submitter);
|
1891
|
+
submitter.click();
|
1892
|
+
return;
|
1893
|
+
}
|
1894
|
+
const dummySubmitter = document.createElement("input");
|
1895
|
+
dummySubmitter.type = "submit";
|
1896
|
+
dummySubmitter.hidden = true;
|
1897
|
+
element.appendChild(dummySubmitter);
|
1898
|
+
dummySubmitter.click();
|
1899
|
+
element.removeChild(dummySubmitter);
|
1900
|
+
};
|
1901
|
+
function validateSubmitter(element, submitter) {
|
1902
|
+
const isHtmlElement = submitter instanceof HTMLElement;
|
1903
|
+
if (!isHtmlElement) {
|
1904
|
+
raise(TypeError, "parameter 1 is not of type 'HTMLElement'");
|
1905
|
+
}
|
1906
|
+
const hasSubmitType = "type" in submitter && submitter.type === "submit";
|
1907
|
+
if (!hasSubmitType)
|
1908
|
+
raise(TypeError, "The specified element is not a submit button");
|
1909
|
+
const isForCorrectForm = "form" in submitter && submitter.form === element;
|
1910
|
+
if (!isForCorrectForm)
|
1911
|
+
raise(
|
1912
|
+
DOMException,
|
1913
|
+
"The specified element is not owned by this form element",
|
1914
|
+
"NotFoundError"
|
1915
|
+
);
|
1916
|
+
}
|
1917
|
+
function raise(errorConstructor, message, name) {
|
1918
|
+
throw new errorConstructor(
|
1919
|
+
"Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".",
|
1920
|
+
name
|
1921
|
+
);
|
1922
|
+
}
|
1923
|
+
const useControlledFieldStore = create$1()(
|
1924
|
+
immer((set2, get2) => ({
|
1925
|
+
forms: {},
|
1926
|
+
register: (formId, field) => set2((state) => {
|
1927
|
+
if (!state.forms[formId]) {
|
1928
|
+
state.forms[formId] = {};
|
1929
|
+
}
|
1930
|
+
if (state.forms[formId][field]) {
|
1931
|
+
state.forms[formId][field].refCount++;
|
1932
|
+
} else {
|
1933
|
+
state.forms[formId][field] = {
|
1934
|
+
refCount: 1,
|
1935
|
+
value: void 0,
|
1936
|
+
hydrated: false,
|
1937
|
+
valueUpdatePromise: void 0,
|
1938
|
+
resolveValueUpdate: void 0
|
1939
|
+
};
|
1940
|
+
}
|
1941
|
+
}),
|
1942
|
+
unregister: (formId, field) => set2((state) => {
|
1943
|
+
var _a;
|
1944
|
+
const formState = (_a = state.forms) == null ? void 0 : _a[formId];
|
1945
|
+
const fieldState = formState == null ? void 0 : formState[field];
|
1946
|
+
if (!fieldState)
|
1971
1947
|
return;
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
})
|
1948
|
+
fieldState.refCount--;
|
1949
|
+
if (fieldState.refCount === 0)
|
1950
|
+
delete formState[field];
|
1951
|
+
}),
|
1952
|
+
getField: (formId, field) => {
|
1953
|
+
var _a, _b;
|
1954
|
+
return (_b = (_a = get2().forms) == null ? void 0 : _a[formId]) == null ? void 0 : _b[field];
|
1955
|
+
},
|
1956
|
+
setValue: (formId, field, value) => set2((state) => {
|
1957
|
+
var _a, _b;
|
1958
|
+
const fieldState = (_b = (_a = state.forms) == null ? void 0 : _a[formId]) == null ? void 0 : _b[field];
|
1959
|
+
if (!fieldState)
|
1960
|
+
return;
|
1961
|
+
fieldState.value = value;
|
1962
|
+
const promise = new Promise((resolve) => {
|
1963
|
+
fieldState.resolveValueUpdate = resolve;
|
1964
|
+
});
|
1965
|
+
fieldState.valueUpdatePromise = promise;
|
1966
|
+
}),
|
1967
|
+
hydrateWithDefault: (formId, field, defaultValue) => set2((state) => {
|
1968
|
+
var _a;
|
1969
|
+
const fieldState = (_a = state.forms[formId]) == null ? void 0 : _a[field];
|
1970
|
+
if (!fieldState)
|
1971
|
+
return;
|
1972
|
+
fieldState.value = defaultValue;
|
1973
|
+
fieldState.defaultValue = defaultValue;
|
1974
|
+
fieldState.hydrated = true;
|
1975
|
+
}),
|
1976
|
+
awaitValueUpdate: async (formId, field) => {
|
1977
|
+
var _a;
|
1978
|
+
await ((_a = get2().getField(formId, field)) == null ? void 0 : _a.valueUpdatePromise);
|
1979
|
+
},
|
1980
|
+
reset: (formId) => set2((state) => {
|
1981
|
+
const formState = state.forms[formId];
|
1982
|
+
if (!formState)
|
1983
|
+
return;
|
1984
|
+
Object.values(formState).forEach((field) => {
|
1985
|
+
if (!field)
|
1986
|
+
return;
|
1987
|
+
field.value = field.defaultValue;
|
1988
|
+
});
|
1989
|
+
})
|
1990
|
+
}))
|
1991
|
+
);
|
1976
1992
|
const noOp = () => {
|
1977
1993
|
};
|
1978
1994
|
const defaultFormState = {
|
@@ -2052,11 +2068,20 @@ const createFormState = (formId, set2, get2) => ({
|
|
2052
2068
|
validateField: async (field) => {
|
2053
2069
|
var _a, _b, _c;
|
2054
2070
|
const formElement = get2().formElement;
|
2055
|
-
invariant(
|
2071
|
+
invariant(
|
2072
|
+
formElement,
|
2073
|
+
"Cannot find reference to form. This is probably a bug in remix-validated-form."
|
2074
|
+
);
|
2056
2075
|
const validator = (_a = get2().formProps) == null ? void 0 : _a.validator;
|
2057
|
-
invariant(
|
2076
|
+
invariant(
|
2077
|
+
validator,
|
2078
|
+
"Cannot validator. This is probably a bug in remix-validated-form."
|
2079
|
+
);
|
2058
2080
|
await ((_c = (_b = useControlledFieldStore.getState()).awaitValueUpdate) == null ? void 0 : _c.call(_b, formId, field));
|
2059
|
-
const { error } = await validator.validateField(
|
2081
|
+
const { error } = await validator.validateField(
|
2082
|
+
new FormData(formElement),
|
2083
|
+
field
|
2084
|
+
);
|
2060
2085
|
if (error) {
|
2061
2086
|
get2().setFieldError(field, error);
|
2062
2087
|
return error;
|
@@ -2068,9 +2093,15 @@ const createFormState = (formId, set2, get2) => ({
|
|
2068
2093
|
validate: async () => {
|
2069
2094
|
var _a;
|
2070
2095
|
const formElement = get2().formElement;
|
2071
|
-
invariant(
|
2096
|
+
invariant(
|
2097
|
+
formElement,
|
2098
|
+
"Cannot find reference to form. This is probably a bug in remix-validated-form."
|
2099
|
+
);
|
2072
2100
|
const validator = (_a = get2().formProps) == null ? void 0 : _a.validator;
|
2073
|
-
invariant(
|
2101
|
+
invariant(
|
2102
|
+
validator,
|
2103
|
+
"Cannot validator. This is probably a bug in remix-validated-form."
|
2104
|
+
);
|
2074
2105
|
const result = await validator.validate(new FormData(formElement));
|
2075
2106
|
if (result.error)
|
2076
2107
|
get2().setFieldErrors(result.error.fieldErrors);
|
@@ -2078,8 +2109,11 @@ const createFormState = (formId, set2, get2) => ({
|
|
2078
2109
|
},
|
2079
2110
|
submit: () => {
|
2080
2111
|
const formElement = get2().formElement;
|
2081
|
-
invariant(
|
2082
|
-
|
2112
|
+
invariant(
|
2113
|
+
formElement,
|
2114
|
+
"Cannot find reference to form. This is probably a bug in remix-validated-form."
|
2115
|
+
);
|
2116
|
+
requestSubmit(formElement);
|
2083
2117
|
},
|
2084
2118
|
getValues: () => {
|
2085
2119
|
var _a;
|
@@ -2090,25 +2124,31 @@ const createFormState = (formId, set2, get2) => ({
|
|
2090
2124
|
return (_a = get2().formElement) == null ? void 0 : _a.reset();
|
2091
2125
|
}
|
2092
2126
|
});
|
2093
|
-
const useRootFormStore = create$1()(
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2127
|
+
const useRootFormStore = create$1()(
|
2128
|
+
immer((set2, get2) => ({
|
2129
|
+
forms: {},
|
2130
|
+
form: (formId) => {
|
2131
|
+
var _a;
|
2132
|
+
return (_a = get2().forms[formId]) != null ? _a : defaultFormState;
|
2133
|
+
},
|
2134
|
+
cleanupForm: (formId) => {
|
2135
|
+
set2((state) => {
|
2136
|
+
delete state.forms[formId];
|
2137
|
+
});
|
2138
|
+
},
|
2139
|
+
registerForm: (formId) => {
|
2140
|
+
if (get2().forms[formId])
|
2141
|
+
return;
|
2142
|
+
set2((state) => {
|
2143
|
+
state.forms[formId] = createFormState(
|
2144
|
+
formId,
|
2145
|
+
(setter) => set2((state2) => setter(state2.forms[formId])),
|
2146
|
+
() => get2().forms[formId]
|
2147
|
+
);
|
2148
|
+
});
|
2149
|
+
}
|
2150
|
+
}))
|
2151
|
+
);
|
2112
2152
|
const useFormStore = (formId, selector) => {
|
2113
2153
|
return useRootFormStore((state) => selector(state.form(formId)));
|
2114
2154
|
};
|
@@ -2118,7 +2158,9 @@ const useInternalFormContext = (formId, hookName) => {
|
|
2118
2158
|
return { formId };
|
2119
2159
|
if (formContext)
|
2120
2160
|
return formContext;
|
2121
|
-
throw new Error(
|
2161
|
+
throw new Error(
|
2162
|
+
`Unable to determine form for ${hookName}. Please use it inside a ValidatedForm or pass a 'formId'.`
|
2163
|
+
);
|
2122
2164
|
};
|
2123
2165
|
function useErrorResponseForForm({
|
2124
2166
|
fetcher,
|
@@ -2164,7 +2206,10 @@ const useDefaultValuesForForm = (context) => {
|
|
2164
2206
|
if (hydrated)
|
2165
2207
|
return hydratable.hydratedData();
|
2166
2208
|
if (errorResponse == null ? void 0 : errorResponse.repopulateFields) {
|
2167
|
-
invariant(
|
2209
|
+
invariant(
|
2210
|
+
typeof errorResponse.repopulateFields === "object",
|
2211
|
+
"repopulateFields returned something other than an object"
|
2212
|
+
);
|
2168
2213
|
return hydratable.serverData(errorResponse.repopulateFields);
|
2169
2214
|
}
|
2170
2215
|
if (defaultValuesProp)
|
@@ -2181,12 +2226,18 @@ const useHasActiveFormSubmit = ({
|
|
2181
2226
|
const useFieldTouched = (field, { formId }) => {
|
2182
2227
|
const touched = useFormStore(formId, (state) => state.touchedFields[field]);
|
2183
2228
|
const setFieldTouched = useFormStore(formId, (state) => state.setTouched);
|
2184
|
-
const setTouched = useCallback(
|
2229
|
+
const setTouched = useCallback(
|
2230
|
+
(touched2) => setFieldTouched(field, touched2),
|
2231
|
+
[field, setFieldTouched]
|
2232
|
+
);
|
2185
2233
|
return [touched, setTouched];
|
2186
2234
|
};
|
2187
2235
|
const useFieldError = (name, context) => {
|
2188
2236
|
const fieldErrors = useFieldErrorsForForm(context);
|
2189
|
-
const state = useFormStore(
|
2237
|
+
const state = useFormStore(
|
2238
|
+
context.formId,
|
2239
|
+
(state2) => state2.fieldErrors[name]
|
2240
|
+
);
|
2190
2241
|
return fieldErrors.map((fieldErrors2) => fieldErrors2 == null ? void 0 : fieldErrors2[name]).hydrateTo(state);
|
2191
2242
|
};
|
2192
2243
|
const useClearError = (context) => {
|
@@ -2205,15 +2256,21 @@ const useValidateField = (formId) => useFormStore(formId, (state) => state.valid
|
|
2205
2256
|
const useValidate = (formId) => useFormStore(formId, (state) => state.validate);
|
2206
2257
|
const noOpReceiver = () => () => {
|
2207
2258
|
};
|
2208
|
-
const useRegisterReceiveFocus = (formId) => useFormStore(
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2259
|
+
const useRegisterReceiveFocus = (formId) => useFormStore(
|
2260
|
+
formId,
|
2261
|
+
(state) => {
|
2262
|
+
var _a, _b;
|
2263
|
+
return (_b = (_a = state.formProps) == null ? void 0 : _a.registerReceiveFocus) != null ? _b : noOpReceiver;
|
2264
|
+
}
|
2265
|
+
);
|
2212
2266
|
const defaultDefaultValues = {};
|
2213
|
-
const useSyncedDefaultValues = (formId) => useFormStore(
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2267
|
+
const useSyncedDefaultValues = (formId) => useFormStore(
|
2268
|
+
formId,
|
2269
|
+
(state) => {
|
2270
|
+
var _a, _b;
|
2271
|
+
return (_b = (_a = state.formProps) == null ? void 0 : _a.defaultValues) != null ? _b : defaultDefaultValues;
|
2272
|
+
}
|
2273
|
+
);
|
2217
2274
|
const useSetTouched = ({ formId }) => useFormStore(formId, (state) => state.setTouched);
|
2218
2275
|
const useTouchedFields = (formId) => useFormStore(formId, (state) => state.touchedFields);
|
2219
2276
|
const useFieldErrors = (formId) => useFormStore(formId, (state) => state.fieldErrors);
|
@@ -2230,17 +2287,26 @@ const useFormSubactionProp = (formId) => useFormStore(formId, (state) => {
|
|
2230
2287
|
});
|
2231
2288
|
const useFormValues = (formId) => useFormStore(formId, (state) => state.getValues);
|
2232
2289
|
const useControlledFieldValue = (context, field) => {
|
2233
|
-
const value = useControlledFieldStore(
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2290
|
+
const value = useControlledFieldStore(
|
2291
|
+
(state) => {
|
2292
|
+
var _a;
|
2293
|
+
return (_a = state.getField(context.formId, field)) == null ? void 0 : _a.value;
|
2294
|
+
}
|
2295
|
+
);
|
2296
|
+
const isFormHydrated = useFormStore(
|
2297
|
+
context.formId,
|
2298
|
+
(state) => state.isHydrated
|
2299
|
+
);
|
2238
2300
|
const defaultValue = useFieldDefaultValue(field, context);
|
2239
|
-
const isFieldHydrated = useControlledFieldStore(
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2301
|
+
const isFieldHydrated = useControlledFieldStore(
|
2302
|
+
(state) => {
|
2303
|
+
var _a, _b;
|
2304
|
+
return (_b = (_a = state.getField(context.formId, field)) == null ? void 0 : _a.hydrated) != null ? _b : false;
|
2305
|
+
}
|
2306
|
+
);
|
2307
|
+
const hydrateWithDefault = useControlledFieldStore(
|
2308
|
+
(state) => state.hydrateWithDefault
|
2309
|
+
);
|
2244
2310
|
useEffect(() => {
|
2245
2311
|
if (isFormHydrated && !isFieldHydrated) {
|
2246
2312
|
hydrateWithDefault(context.formId, field, defaultValue);
|
@@ -2256,10 +2322,12 @@ const useControlledFieldValue = (context, field) => {
|
|
2256
2322
|
return isFieldHydrated ? value : defaultValue;
|
2257
2323
|
};
|
2258
2324
|
const useControllableValue = (context, field) => {
|
2259
|
-
const resolveUpdate = useControlledFieldStore(
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2325
|
+
const resolveUpdate = useControlledFieldStore(
|
2326
|
+
(state) => {
|
2327
|
+
var _a;
|
2328
|
+
return (_a = state.getField(context.formId, field)) == null ? void 0 : _a.resolveValueUpdate;
|
2329
|
+
}
|
2330
|
+
);
|
2263
2331
|
useEffect(() => {
|
2264
2332
|
resolveUpdate == null ? void 0 : resolveUpdate();
|
2265
2333
|
}, [resolveUpdate]);
|
@@ -2269,14 +2337,22 @@ const useControllableValue = (context, field) => {
|
|
2269
2337
|
register(context.formId, field);
|
2270
2338
|
return () => unregister(context.formId, field);
|
2271
2339
|
}, [context.formId, field, register, unregister]);
|
2272
|
-
const setControlledFieldValue = useControlledFieldStore(
|
2273
|
-
|
2340
|
+
const setControlledFieldValue = useControlledFieldStore(
|
2341
|
+
(state) => state.setValue
|
2342
|
+
);
|
2343
|
+
const setValue = useCallback(
|
2344
|
+
(value2) => setControlledFieldValue(context.formId, field, value2),
|
2345
|
+
[context.formId, field, setControlledFieldValue]
|
2346
|
+
);
|
2274
2347
|
const value = useControlledFieldValue(context, field);
|
2275
2348
|
return [value, setValue];
|
2276
2349
|
};
|
2277
2350
|
const useUpdateControllableValue = (formId) => {
|
2278
2351
|
const setValue = useControlledFieldStore((state) => state.setValue);
|
2279
|
-
return useCallback(
|
2352
|
+
return useCallback(
|
2353
|
+
(field, value) => setValue(formId, field, value),
|
2354
|
+
[formId, setValue]
|
2355
|
+
);
|
2280
2356
|
};
|
2281
2357
|
const useIsSubmitting = (formId) => {
|
2282
2358
|
const formContext = useInternalFormContext(formId, "useIsSubmitting");
|
@@ -2311,14 +2387,16 @@ const useField = (name, options) => {
|
|
2311
2387
|
touched,
|
2312
2388
|
setTouched
|
2313
2389
|
};
|
2314
|
-
const getInputProps = createGetInputProps(
|
2390
|
+
const getInputProps = createGetInputProps({
|
2391
|
+
...helpers,
|
2315
2392
|
name,
|
2316
2393
|
hasBeenSubmitted,
|
2317
2394
|
validationBehavior: options == null ? void 0 : options.validationBehavior
|
2318
|
-
}));
|
2319
|
-
return __spreadProps(__spreadValues({}, helpers), {
|
2320
|
-
getInputProps
|
2321
2395
|
});
|
2396
|
+
return {
|
2397
|
+
...helpers,
|
2398
|
+
getInputProps
|
2399
|
+
};
|
2322
2400
|
}, [
|
2323
2401
|
error,
|
2324
2402
|
clearError,
|
@@ -2359,17 +2437,21 @@ const json = (data, init = {}) => {
|
|
2359
2437
|
if (!headers.has("Content-Type")) {
|
2360
2438
|
headers.set("Content-Type", "application/json; charset=utf-8");
|
2361
2439
|
}
|
2362
|
-
return new Response(JSON.stringify(data),
|
2440
|
+
return new Response(JSON.stringify(data), {
|
2441
|
+
...responseInit,
|
2363
2442
|
headers
|
2364
|
-
})
|
2443
|
+
});
|
2365
2444
|
};
|
2366
2445
|
function validationError(error, repopulateFields, init) {
|
2367
|
-
return json(
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2446
|
+
return json(
|
2447
|
+
{
|
2448
|
+
fieldErrors: error.fieldErrors,
|
2449
|
+
subaction: error.subaction,
|
2450
|
+
repopulateFields,
|
2451
|
+
formId: error.formId
|
2452
|
+
},
|
2453
|
+
{ status: 422, ...init }
|
2454
|
+
);
|
2373
2455
|
}
|
2374
2456
|
const setFormDefaults = (formId, defaultValues) => ({
|
2375
2457
|
[formDefaultValuesKey(formId)]: defaultValues
|
@@ -2580,7 +2662,9 @@ const focusFirstInvalidInput = (fieldErrors, customFocusHandlers, formElement) =
|
|
2580
2662
|
if (!elem)
|
2581
2663
|
continue;
|
2582
2664
|
if (elem instanceof RadioNodeList) {
|
2583
|
-
const selectedRadio = (_a = [...elem].filter(
|
2665
|
+
const selectedRadio = (_a = [...elem].filter(
|
2666
|
+
(item) => item instanceof HTMLInputElement
|
2667
|
+
).find((item) => item.value === elem.value)) != null ? _a : elem[0];
|
2584
2668
|
if (selectedRadio && selectedRadio instanceof HTMLInputElement) {
|
2585
2669
|
selectedRadio.focus();
|
2586
2670
|
break;
|
@@ -2629,53 +2713,41 @@ function formEventProxy(event) {
|
|
2629
2713
|
}
|
2630
2714
|
});
|
2631
2715
|
}
|
2632
|
-
function ValidatedForm(
|
2633
|
-
|
2634
|
-
|
2635
|
-
|
2636
|
-
|
2637
|
-
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2649
|
-
|
2650
|
-
"onSubmit",
|
2651
|
-
"children",
|
2652
|
-
"fetcher",
|
2653
|
-
"action",
|
2654
|
-
"defaultValues",
|
2655
|
-
"formRef",
|
2656
|
-
"onReset",
|
2657
|
-
"subaction",
|
2658
|
-
"resetAfterSubmit",
|
2659
|
-
"disableFocusOnError",
|
2660
|
-
"method",
|
2661
|
-
"replace",
|
2662
|
-
"id"
|
2663
|
-
]);
|
2664
|
-
var _a2;
|
2716
|
+
function ValidatedForm({
|
2717
|
+
validator,
|
2718
|
+
onSubmit,
|
2719
|
+
children,
|
2720
|
+
fetcher,
|
2721
|
+
action,
|
2722
|
+
defaultValues: unMemoizedDefaults,
|
2723
|
+
formRef: formRefProp,
|
2724
|
+
onReset,
|
2725
|
+
subaction,
|
2726
|
+
resetAfterSubmit = false,
|
2727
|
+
disableFocusOnError,
|
2728
|
+
method,
|
2729
|
+
replace,
|
2730
|
+
id,
|
2731
|
+
...rest
|
2732
|
+
}) {
|
2733
|
+
var _a;
|
2665
2734
|
const formId = useFormId(id);
|
2666
2735
|
const providedDefaultValues = useDeepEqualsMemo(unMemoizedDefaults);
|
2667
|
-
const contextValue = useMemo(
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2736
|
+
const contextValue = useMemo(
|
2737
|
+
() => ({
|
2738
|
+
formId,
|
2739
|
+
action,
|
2740
|
+
subaction,
|
2741
|
+
defaultValuesProp: providedDefaultValues,
|
2742
|
+
fetcher
|
2743
|
+
}),
|
2744
|
+
[action, fetcher, formId, providedDefaultValues, subaction]
|
2745
|
+
);
|
2674
2746
|
const backendError = useErrorResponseForForm(contextValue);
|
2675
2747
|
const backendDefaultValues = useDefaultValuesFromLoader(contextValue);
|
2676
2748
|
const hasActiveSubmission = useHasActiveFormSubmit(contextValue);
|
2677
2749
|
const formRef = useRef(null);
|
2678
|
-
const Form$1 = (
|
2750
|
+
const Form$1 = (_a = fetcher == null ? void 0 : fetcher.Form) != null ? _a : Form;
|
2679
2751
|
const submit = useSubmit();
|
2680
2752
|
const setFieldErrors = useSetFieldErrors(formId);
|
2681
2753
|
const setFieldError = useFormStore(formId, (state) => state.setFieldError);
|
@@ -2684,25 +2756,31 @@ function ValidatedForm(_a) {
|
|
2684
2756
|
const startSubmit = useFormStore(formId, (state) => state.startSubmit);
|
2685
2757
|
const endSubmit = useFormStore(formId, (state) => state.endSubmit);
|
2686
2758
|
const syncFormProps = useFormStore(formId, (state) => state.syncFormProps);
|
2687
|
-
const setFormElementInState = useFormStore(
|
2759
|
+
const setFormElementInState = useFormStore(
|
2760
|
+
formId,
|
2761
|
+
(state) => state.setFormElement
|
2762
|
+
);
|
2688
2763
|
const cleanupForm = useRootFormStore((state) => state.cleanupForm);
|
2689
2764
|
const registerForm = useRootFormStore((state) => state.registerForm);
|
2690
2765
|
const customFocusHandlers = useMultiValueMap();
|
2691
|
-
const registerReceiveFocus = useCallback(
|
2692
|
-
|
2693
|
-
|
2694
|
-
|
2695
|
-
|
2696
|
-
|
2766
|
+
const registerReceiveFocus = useCallback(
|
2767
|
+
(fieldName, handler) => {
|
2768
|
+
customFocusHandlers().add(fieldName, handler);
|
2769
|
+
return () => {
|
2770
|
+
customFocusHandlers().remove(fieldName, handler);
|
2771
|
+
};
|
2772
|
+
},
|
2773
|
+
[customFocusHandlers]
|
2774
|
+
);
|
2697
2775
|
useIsomorphicLayoutEffect(() => {
|
2698
2776
|
registerForm(formId);
|
2699
2777
|
return () => cleanupForm(formId);
|
2700
2778
|
}, [cleanupForm, formId, registerForm]);
|
2701
2779
|
useIsomorphicLayoutEffect(() => {
|
2702
|
-
var
|
2780
|
+
var _a2;
|
2703
2781
|
syncFormProps({
|
2704
2782
|
action,
|
2705
|
-
defaultValues: (
|
2783
|
+
defaultValues: (_a2 = providedDefaultValues != null ? providedDefaultValues : backendDefaultValues) != null ? _a2 : {},
|
2706
2784
|
subaction,
|
2707
2785
|
registerReceiveFocus,
|
2708
2786
|
validator
|
@@ -2720,8 +2798,8 @@ function ValidatedForm(_a) {
|
|
2720
2798
|
setFormElementInState(formRef.current);
|
2721
2799
|
}, [setFormElementInState]);
|
2722
2800
|
useEffect(() => {
|
2723
|
-
var
|
2724
|
-
setFieldErrors((
|
2801
|
+
var _a2;
|
2802
|
+
setFieldErrors((_a2 = backendError == null ? void 0 : backendError.fieldErrors) != null ? _a2 : {});
|
2725
2803
|
}, [backendError == null ? void 0 : backendError.fieldErrors, setFieldErrors, setFieldError]);
|
2726
2804
|
useSubmitComplete(hasActiveSubmission, () => {
|
2727
2805
|
endSubmit();
|
@@ -2733,7 +2811,11 @@ function ValidatedForm(_a) {
|
|
2733
2811
|
endSubmit();
|
2734
2812
|
setFieldErrors(result.error.fieldErrors);
|
2735
2813
|
if (!disableFocusOnError) {
|
2736
|
-
focusFirstInvalidInput(
|
2814
|
+
focusFirstInvalidInput(
|
2815
|
+
result.error.fieldErrors,
|
2816
|
+
customFocusHandlers(),
|
2817
|
+
formRef.current
|
2818
|
+
);
|
2737
2819
|
}
|
2738
2820
|
} else {
|
2739
2821
|
const eventProxy = formEventProxy(e2);
|
@@ -2749,16 +2831,20 @@ function ValidatedForm(_a) {
|
|
2749
2831
|
submit(submitter || target, { replace });
|
2750
2832
|
}
|
2751
2833
|
};
|
2752
|
-
return /* @__PURE__ */ React.createElement(Form$1,
|
2753
|
-
ref: mergeRefs([formRef, formRefProp])
|
2754
|
-
|
2834
|
+
return /* @__PURE__ */ React.createElement(Form$1, {
|
2835
|
+
ref: mergeRefs([formRef, formRefProp]),
|
2836
|
+
...rest,
|
2755
2837
|
id,
|
2756
2838
|
action,
|
2757
2839
|
method,
|
2758
2840
|
replace,
|
2759
2841
|
onSubmit: (e2) => {
|
2760
2842
|
e2.preventDefault();
|
2761
|
-
handleSubmit(
|
2843
|
+
handleSubmit(
|
2844
|
+
e2,
|
2845
|
+
e2.currentTarget,
|
2846
|
+
e2.nativeEvent
|
2847
|
+
);
|
2762
2848
|
},
|
2763
2849
|
onReset: (event) => {
|
2764
2850
|
onReset == null ? void 0 : onReset(event);
|
@@ -2767,7 +2853,7 @@ function ValidatedForm(_a) {
|
|
2767
2853
|
reset();
|
2768
2854
|
resetControlledFields(formId);
|
2769
2855
|
}
|
2770
|
-
}
|
2856
|
+
}, /* @__PURE__ */ React.createElement(InternalFormContext.Provider, {
|
2771
2857
|
value: contextValue
|
2772
2858
|
}, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(FormResetter, {
|
2773
2859
|
formRef,
|
@@ -2790,7 +2876,10 @@ var set_1 = set;
|
|
2790
2876
|
const objectFromPathEntries = (entries) => {
|
2791
2877
|
const map = new MultiValueMap();
|
2792
2878
|
entries.forEach(([key, value]) => map.add(key, value));
|
2793
|
-
return [...map.entries()].reduce(
|
2879
|
+
return [...map.entries()].reduce(
|
2880
|
+
(acc, [key, value]) => set_1(acc, key, value.length === 1 ? value[0] : value),
|
2881
|
+
{}
|
2882
|
+
);
|
2794
2883
|
};
|
2795
2884
|
const preprocessFormData = (data) => {
|
2796
2885
|
if ("entries" in data && typeof data.entries === "function")
|
@@ -2838,25 +2927,28 @@ const useFormState = (formId) => {
|
|
2838
2927
|
const fieldErrorsFromState = useFieldErrors(formContext.formId);
|
2839
2928
|
const fieldErrorsToUse = useFieldErrorsForForm(formContext);
|
2840
2929
|
const hydratedFieldErrors = fieldErrorsToUse.hydrateTo(fieldErrorsFromState);
|
2841
|
-
return useMemo(
|
2842
|
-
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2848
|
-
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2930
|
+
return useMemo(
|
2931
|
+
() => ({
|
2932
|
+
action,
|
2933
|
+
subaction,
|
2934
|
+
defaultValues: hydratedDefaultValues,
|
2935
|
+
fieldErrors: hydratedFieldErrors != null ? hydratedFieldErrors : {},
|
2936
|
+
hasBeenSubmitted,
|
2937
|
+
isSubmitting,
|
2938
|
+
touchedFields,
|
2939
|
+
isValid
|
2940
|
+
}),
|
2941
|
+
[
|
2942
|
+
action,
|
2943
|
+
hasBeenSubmitted,
|
2944
|
+
hydratedDefaultValues,
|
2945
|
+
hydratedFieldErrors,
|
2946
|
+
isSubmitting,
|
2947
|
+
isValid,
|
2948
|
+
subaction,
|
2949
|
+
touchedFields
|
2950
|
+
]
|
2951
|
+
);
|
2860
2952
|
};
|
2861
2953
|
const useFormHelpers = (formId) => {
|
2862
2954
|
const formContext = useInternalFormContext(formId, "useFormHelpers");
|
@@ -2868,25 +2960,28 @@ const useFormHelpers = (formId) => {
|
|
2868
2960
|
const reset = useResetFormElement(formContext.formId);
|
2869
2961
|
const submit = useSubmitForm(formContext.formId);
|
2870
2962
|
const getValues = useFormValues(formContext.formId);
|
2871
|
-
return useMemo(
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2963
|
+
return useMemo(
|
2964
|
+
() => ({
|
2965
|
+
setTouched,
|
2966
|
+
validateField,
|
2967
|
+
clearError,
|
2968
|
+
validate,
|
2969
|
+
clearAllErrors: () => setFieldErrors({}),
|
2970
|
+
reset,
|
2971
|
+
submit,
|
2972
|
+
getValues
|
2973
|
+
}),
|
2974
|
+
[
|
2975
|
+
clearError,
|
2976
|
+
reset,
|
2977
|
+
setFieldErrors,
|
2978
|
+
setTouched,
|
2979
|
+
submit,
|
2980
|
+
validate,
|
2981
|
+
validateField,
|
2982
|
+
getValues
|
2983
|
+
]
|
2984
|
+
);
|
2890
2985
|
};
|
2891
2986
|
const useFormContext = (formId) => {
|
2892
2987
|
const context = useInternalFormContext(formId, "useFormContext");
|
@@ -2902,33 +2997,40 @@ const useFormContext = (formId) => {
|
|
2902
2997
|
getValues
|
2903
2998
|
} = useFormHelpers(formId);
|
2904
2999
|
const registerReceiveFocus = useRegisterReceiveFocus(context.formId);
|
2905
|
-
const clearError = useCallback(
|
2906
|
-
names
|
2907
|
-
|
2908
|
-
|
2909
|
-
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2930
|
-
|
2931
|
-
|
3000
|
+
const clearError = useCallback(
|
3001
|
+
(...names) => {
|
3002
|
+
names.forEach((name) => {
|
3003
|
+
internalClearError(name);
|
3004
|
+
});
|
3005
|
+
},
|
3006
|
+
[internalClearError]
|
3007
|
+
);
|
3008
|
+
return useMemo(
|
3009
|
+
() => ({
|
3010
|
+
...state,
|
3011
|
+
setFieldTouched: setTouched,
|
3012
|
+
validateField,
|
3013
|
+
clearError,
|
3014
|
+
registerReceiveFocus,
|
3015
|
+
clearAllErrors,
|
3016
|
+
validate,
|
3017
|
+
reset,
|
3018
|
+
submit,
|
3019
|
+
getValues
|
3020
|
+
}),
|
3021
|
+
[
|
3022
|
+
clearAllErrors,
|
3023
|
+
clearError,
|
3024
|
+
registerReceiveFocus,
|
3025
|
+
reset,
|
3026
|
+
setTouched,
|
3027
|
+
state,
|
3028
|
+
submit,
|
3029
|
+
validate,
|
3030
|
+
validateField,
|
3031
|
+
getValues
|
3032
|
+
]
|
3033
|
+
);
|
2932
3034
|
};
|
2933
3035
|
export { ValidatedForm, createValidator, setFormDefaults, useControlField, useField, useFormContext, useIsSubmitting, useIsValid, useUpdateControlledField, validationError };
|
2934
3036
|
//# sourceMappingURL=remix-validated-form.es.js.map
|