remix-validated-form 4.5.0 → 4.5.3
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 -9
- package/browser/ValidatedForm.js +4 -4
- package/browser/internal/hooks.d.ts +1 -0
- package/browser/internal/hooks.js +1 -0
- package/browser/internal/logic/nestedObjectToPathObject.d.ts +0 -0
- package/browser/internal/logic/nestedObjectToPathObject.js +0 -0
- package/browser/internal/state/arrayUtil.d.ts +6 -0
- package/browser/internal/state/arrayUtil.js +236 -7
- package/browser/internal/state/createFormStore.d.ts +1 -0
- package/browser/internal/state/createFormStore.js +6 -0
- package/browser/internal/state/fieldArray.d.ts +18 -11
- package/browser/internal/state/fieldArray.js +44 -21
- package/browser/server.d.ts +2 -2
- package/browser/server.js +1 -1
- package/browser/unreleased/formStateHooks.d.ts +4 -0
- package/browser/unreleased/formStateHooks.js +4 -1
- package/browser/userFacingFormContext.d.ts +4 -0
- package/browser/userFacingFormContext.js +3 -1
- package/dist/remix-validated-form.cjs.js +12 -3
- package/dist/remix-validated-form.cjs.js.map +1 -1
- package/dist/remix-validated-form.es.js +45 -11
- package/dist/remix-validated-form.es.js.map +1 -1
- package/dist/remix-validated-form.umd.js +12 -3
- package/dist/remix-validated-form.umd.js.map +1 -1
- package/dist/types/internal/hooks.d.ts +1 -0
- package/dist/types/internal/state/createFormStore.d.ts +1 -0
- package/dist/types/server.d.ts +2 -2
- package/dist/types/unreleased/formStateHooks.d.ts +4 -0
- package/dist/types/userFacingFormContext.d.ts +4 -0
- package/package.json +2 -4
- package/src/ValidatedForm.tsx +5 -4
- package/src/internal/hooks.ts +3 -0
- package/src/internal/state/createFormStore.ts +12 -1
- package/src/server.ts +2 -2
- package/src/unreleased/formStateHooks.ts +8 -0
- package/src/userFacingFormContext.ts +7 -0
- package/src/validation/validation.test.ts +7 -7
- package/vite.config.ts +1 -1
@@ -31,7 +31,6 @@ var __objRest = (source, exclude) => {
|
|
31
31
|
};
|
32
32
|
import React, { createContext, useDebugValue, useContext, useCallback, useEffect, useMemo, useRef, useLayoutEffect, useState } from "react";
|
33
33
|
import { useActionData, useMatches, useTransition, Form, useSubmit } from "@remix-run/react";
|
34
|
-
import { json } from "@remix-run/server-runtime";
|
35
34
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
36
35
|
function listCacheClear$1() {
|
37
36
|
this.__data__ = [];
|
@@ -2001,7 +2000,8 @@ const defaultFormState = {
|
|
2001
2000
|
submit: async () => {
|
2002
2001
|
throw new Error("Submit called before form was initialized.");
|
2003
2002
|
},
|
2004
|
-
resetFormElement: noOp
|
2003
|
+
resetFormElement: noOp,
|
2004
|
+
getValues: () => new FormData()
|
2005
2005
|
};
|
2006
2006
|
const createFormState = (formId, set2, get2) => ({
|
2007
2007
|
isHydrated: false,
|
@@ -2081,6 +2081,11 @@ const createFormState = (formId, set2, get2) => ({
|
|
2081
2081
|
invariant(formElement, "Cannot find reference to form. This is probably a bug in remix-validated-form.");
|
2082
2082
|
formElement.submit();
|
2083
2083
|
},
|
2084
|
+
getValues: () => {
|
2085
|
+
const formElement = get2().formElement;
|
2086
|
+
invariant(formElement, "Cannot find reference to form. This is probably a bug in remix-validated-form.");
|
2087
|
+
return new FormData(formElement);
|
2088
|
+
},
|
2084
2089
|
resetFormElement: () => {
|
2085
2090
|
var _a;
|
2086
2091
|
return (_a = get2().formElement) == null ? void 0 : _a.reset();
|
@@ -2224,6 +2229,7 @@ const useFormSubactionProp = (formId) => useFormStore(formId, (state) => {
|
|
2224
2229
|
var _a;
|
2225
2230
|
return (_a = state.formProps) == null ? void 0 : _a.subaction;
|
2226
2231
|
});
|
2232
|
+
const useFormValues = (formId) => useFormStore(formId, (state) => state.getValues);
|
2227
2233
|
const useControlledFieldValue = (context, field) => {
|
2228
2234
|
const value = useControlledFieldStore((state) => {
|
2229
2235
|
var _a;
|
@@ -2336,6 +2342,28 @@ const useUpdateControlledField = (formId) => {
|
|
2336
2342
|
const context = useInternalFormContext(formId, "useControlField");
|
2337
2343
|
return useUpdateControllableValue(context.formId);
|
2338
2344
|
};
|
2345
|
+
/**
|
2346
|
+
* @remix-run/server-runtime v1.6.5
|
2347
|
+
*
|
2348
|
+
* Copyright (c) Remix Software Inc.
|
2349
|
+
*
|
2350
|
+
* This source code is licensed under the MIT license found in the
|
2351
|
+
* LICENSE.md file in the root directory of this source tree.
|
2352
|
+
*
|
2353
|
+
* @license MIT
|
2354
|
+
*/
|
2355
|
+
const json = (data, init = {}) => {
|
2356
|
+
let responseInit = typeof init === "number" ? {
|
2357
|
+
status: init
|
2358
|
+
} : init;
|
2359
|
+
let headers = new Headers(responseInit.headers);
|
2360
|
+
if (!headers.has("Content-Type")) {
|
2361
|
+
headers.set("Content-Type", "application/json; charset=utf-8");
|
2362
|
+
}
|
2363
|
+
return new Response(JSON.stringify(data), __spreadProps(__spreadValues({}, responseInit), {
|
2364
|
+
headers
|
2365
|
+
}));
|
2366
|
+
};
|
2339
2367
|
function validationError(error, repopulateFields, init) {
|
2340
2368
|
return json({
|
2341
2369
|
fieldErrors: error.fieldErrors,
|
@@ -2537,7 +2565,7 @@ const focusFirstInvalidInput = (fieldErrors, customFocusHandlers, formElement) =
|
|
2537
2565
|
var _a;
|
2538
2566
|
const namesInOrder = [...formElement.elements].map((el) => {
|
2539
2567
|
const input = el instanceof RadioNodeList ? el[0] : el;
|
2540
|
-
if (input instanceof
|
2568
|
+
if (input instanceof HTMLElement && "name" in input)
|
2541
2569
|
return input.name;
|
2542
2570
|
return null;
|
2543
2571
|
}).filter(nonNull).filter((name) => name in fieldErrors);
|
@@ -2559,8 +2587,8 @@ const focusFirstInvalidInput = (fieldErrors, customFocusHandlers, formElement) =
|
|
2559
2587
|
break;
|
2560
2588
|
}
|
2561
2589
|
}
|
2562
|
-
if (elem instanceof
|
2563
|
-
if (elem.type === "hidden") {
|
2590
|
+
if (elem instanceof HTMLElement) {
|
2591
|
+
if (elem instanceof HTMLInputElement && elem.type === "hidden") {
|
2564
2592
|
continue;
|
2565
2593
|
}
|
2566
2594
|
elem.focus();
|
@@ -2719,7 +2747,7 @@ function ValidatedForm(_a) {
|
|
2719
2747
|
if (fetcher)
|
2720
2748
|
fetcher.submit(submitter || e2.currentTarget);
|
2721
2749
|
else
|
2722
|
-
submit(submitter || target, {
|
2750
|
+
submit(submitter || target, { replace });
|
2723
2751
|
}
|
2724
2752
|
};
|
2725
2753
|
return /* @__PURE__ */ React.createElement(Form$1, __spreadProps(__spreadValues({
|
@@ -2840,6 +2868,7 @@ const useFormHelpers = (formId) => {
|
|
2840
2868
|
const setFieldErrors = useSetFieldErrors(formContext.formId);
|
2841
2869
|
const reset = useResetFormElement(formContext.formId);
|
2842
2870
|
const submit = useSubmitForm(formContext.formId);
|
2871
|
+
const getValues = useFormValues(formContext.formId);
|
2843
2872
|
return useMemo(() => ({
|
2844
2873
|
setTouched,
|
2845
2874
|
validateField,
|
@@ -2847,7 +2876,8 @@ const useFormHelpers = (formId) => {
|
|
2847
2876
|
validate,
|
2848
2877
|
clearAllErrors: () => setFieldErrors({}),
|
2849
2878
|
reset,
|
2850
|
-
submit
|
2879
|
+
submit,
|
2880
|
+
getValues
|
2851
2881
|
}), [
|
2852
2882
|
clearError,
|
2853
2883
|
reset,
|
@@ -2855,7 +2885,8 @@ const useFormHelpers = (formId) => {
|
|
2855
2885
|
setTouched,
|
2856
2886
|
submit,
|
2857
2887
|
validate,
|
2858
|
-
validateField
|
2888
|
+
validateField,
|
2889
|
+
getValues
|
2859
2890
|
]);
|
2860
2891
|
};
|
2861
2892
|
const useFormContext = (formId) => {
|
@@ -2868,7 +2899,8 @@ const useFormContext = (formId) => {
|
|
2868
2899
|
clearAllErrors,
|
2869
2900
|
validate,
|
2870
2901
|
reset,
|
2871
|
-
submit
|
2902
|
+
submit,
|
2903
|
+
getValues
|
2872
2904
|
} = useFormHelpers(formId);
|
2873
2905
|
const registerReceiveFocus = useRegisterReceiveFocus(context.formId);
|
2874
2906
|
const clearError = useCallback((...names) => {
|
@@ -2884,7 +2916,8 @@ const useFormContext = (formId) => {
|
|
2884
2916
|
clearAllErrors,
|
2885
2917
|
validate,
|
2886
2918
|
reset,
|
2887
|
-
submit
|
2919
|
+
submit,
|
2920
|
+
getValues
|
2888
2921
|
}), [
|
2889
2922
|
clearAllErrors,
|
2890
2923
|
clearError,
|
@@ -2894,7 +2927,8 @@ const useFormContext = (formId) => {
|
|
2894
2927
|
state,
|
2895
2928
|
submit,
|
2896
2929
|
validate,
|
2897
|
-
validateField
|
2930
|
+
validateField,
|
2931
|
+
getValues
|
2898
2932
|
]);
|
2899
2933
|
};
|
2900
2934
|
export { ValidatedForm, createValidator, setFormDefaults, useControlField, useField, useFormContext, useIsSubmitting, useIsValid, useUpdateControlledField, validationError };
|