@jcoreio/zod-forms 1.2.0 → 2.0.0-beta.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/ConditionalValidator.d.ts +2 -0
- package/ConditionalValidator.d.ts.map +1 -1
- package/ConditionalValidator.js +6 -2
- package/ConditionalValidator.js.map +1 -1
- package/ConditionalValidator.mjs +2 -0
- package/ConditionalValidator.mjs.map +1 -1
- package/FieldPath.d.ts +2 -2
- package/FieldPath.d.ts.map +1 -1
- package/FieldPath.js.map +1 -1
- package/FieldPath.mjs.map +1 -1
- package/FormAction.d.ts +2 -2
- package/FormAction.d.ts.map +1 -1
- package/FormAction.js.map +1 -1
- package/FormAction.mjs.map +1 -1
- package/FormContext.d.ts +7 -6
- package/FormContext.d.ts.map +1 -1
- package/FormContext.js.map +1 -1
- package/FormContext.mjs.map +1 -1
- package/FormState.d.ts +10 -8
- package/FormState.d.ts.map +1 -1
- package/FormState.js.map +1 -1
- package/FormState.mjs.map +1 -1
- package/README.md +2 -2
- package/actions/arrayActions.d.ts +40 -39
- package/actions/arrayActions.d.ts.map +1 -1
- package/actions/arrayActions.js +37 -37
- package/actions/arrayActions.js.map +1 -1
- package/actions/arrayActions.mjs +29 -29
- package/actions/arrayActions.mjs.map +1 -1
- package/actions/initialize.d.ts +5 -4
- package/actions/initialize.d.ts.map +1 -1
- package/actions/initialize.js.map +1 -1
- package/actions/initialize.mjs.map +1 -1
- package/actions/setParsedValue.d.ts +12 -0
- package/actions/setParsedValue.d.ts.map +1 -0
- package/{reducers/setRawValue.js → actions/setParsedValue.js} +9 -26
- package/actions/setParsedValue.js.map +1 -0
- package/actions/setParsedValue.mjs +9 -0
- package/actions/setParsedValue.mjs.map +1 -0
- package/actions/setSubmitStatus.d.ts +3 -3
- package/actions/setSubmitStatus.d.ts.map +1 -1
- package/actions/setSubmitStatus.js.map +1 -1
- package/actions/setSubmitStatus.mjs.map +1 -1
- package/actions/setValue.d.ts +3 -5
- package/actions/setValue.d.ts.map +1 -1
- package/actions/setValue.js +3 -7
- package/actions/setValue.js.map +1 -1
- package/actions/setValue.mjs +2 -3
- package/actions/setValue.mjs.map +1 -1
- package/createFormMiddleware.d.ts.map +1 -1
- package/createFormMiddleware.js +7 -5
- package/createFormMiddleware.js.map +1 -1
- package/createFormMiddleware.mjs +7 -5
- package/createFormMiddleware.mjs.map +1 -1
- package/createFormProvider.d.ts.map +1 -1
- package/createFormProvider.js +10 -10
- package/createFormProvider.js.map +1 -1
- package/createFormProvider.mjs +7 -7
- package/createFormProvider.mjs.map +1 -1
- package/createFormReducer.js +17 -17
- package/createFormReducer.js.map +1 -1
- package/createFormReducer.mjs +17 -17
- package/createFormReducer.mjs.map +1 -1
- package/createSelectFormStatus.d.ts +1 -1
- package/createSelectFormStatus.d.ts.map +1 -1
- package/createSelectFormStatus.js +6 -6
- package/createSelectFormStatus.js.map +1 -1
- package/createSelectFormStatus.mjs +1 -1
- package/createSelectFormStatus.mjs.map +1 -1
- package/createSelectFormValues.d.ts +19 -19
- package/createSelectFormValues.d.ts.map +1 -1
- package/createSelectFormValues.js +5 -5
- package/createSelectFormValues.js.map +1 -1
- package/createSelectFormValues.mjs +3 -3
- package/createSelectFormValues.mjs.map +1 -1
- package/createZodForm.d.ts +4 -4
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/initFormState.js +1 -1
- package/initFormState.js.map +1 -1
- package/initFormState.mjs +1 -1
- package/initFormState.mjs.map +1 -1
- package/package.json +5 -2
- package/reducers/addHandlers.d.ts +6 -6
- package/reducers/arrayInsert.d.ts.map +1 -1
- package/reducers/arrayInsert.js +10 -4
- package/reducers/arrayInsert.js.map +1 -1
- package/reducers/arrayInsert.mjs +6 -4
- package/reducers/arrayInsert.mjs.map +1 -1
- package/reducers/arrayInsertParsed.d.ts +7 -0
- package/reducers/arrayInsertParsed.d.ts.map +1 -0
- package/reducers/arrayInsertParsed.js +16 -0
- package/reducers/arrayInsertParsed.js.map +1 -0
- package/reducers/arrayInsertParsed.mjs +12 -0
- package/reducers/arrayInsertParsed.mjs.map +1 -0
- package/reducers/arrayPush.d.ts.map +1 -1
- package/reducers/arrayPush.js +6 -4
- package/reducers/arrayPush.js.map +1 -1
- package/reducers/arrayPush.mjs +2 -4
- package/reducers/arrayPush.mjs.map +1 -1
- package/reducers/arrayPushParsed.d.ts +7 -0
- package/reducers/{arrayUnshiftRaw.d.ts.map → arrayPushParsed.d.ts.map} +1 -1
- package/reducers/arrayPushParsed.js +15 -0
- package/reducers/arrayPushParsed.js.map +1 -0
- package/reducers/arrayPushParsed.mjs +11 -0
- package/reducers/arrayPushParsed.mjs.map +1 -0
- package/reducers/arraySplice.d.ts.map +1 -1
- package/reducers/arraySplice.js +12 -6
- package/reducers/arraySplice.js.map +1 -1
- package/reducers/arraySplice.mjs +9 -5
- package/reducers/arraySplice.mjs.map +1 -1
- package/reducers/arraySpliceParsed.d.ts +7 -0
- package/reducers/arraySpliceParsed.d.ts.map +1 -0
- package/reducers/arraySpliceParsed.js +20 -0
- package/reducers/arraySpliceParsed.js.map +1 -0
- package/reducers/arraySpliceParsed.mjs +14 -0
- package/reducers/arraySpliceParsed.mjs.map +1 -0
- package/reducers/arrayUnshift.d.ts.map +1 -1
- package/reducers/arrayUnshift.js +6 -4
- package/reducers/arrayUnshift.js.map +1 -1
- package/reducers/arrayUnshift.mjs +2 -4
- package/reducers/arrayUnshift.mjs.map +1 -1
- package/reducers/arrayUnshiftParsed.d.ts +7 -0
- package/reducers/arrayUnshiftParsed.d.ts.map +1 -0
- package/reducers/arrayUnshiftParsed.js +15 -0
- package/reducers/arrayUnshiftParsed.js.map +1 -0
- package/reducers/arrayUnshiftParsed.mjs +11 -0
- package/reducers/arrayUnshiftParsed.mjs.map +1 -0
- package/reducers/initialize.d.ts +12 -12
- package/reducers/initialize.d.ts.map +1 -1
- package/reducers/initialize.js +9 -9
- package/reducers/initialize.js.map +1 -1
- package/reducers/initialize.mjs +8 -8
- package/reducers/initialize.mjs.map +1 -1
- package/reducers/removeHandlers.d.ts +6 -6
- package/reducers/setParsedValue.d.ts +47 -0
- package/reducers/setParsedValue.d.ts.map +1 -0
- package/reducers/setParsedValue.js +41 -0
- package/reducers/setParsedValue.js.map +1 -0
- package/reducers/setParsedValue.mjs +32 -0
- package/reducers/setParsedValue.mjs.map +1 -0
- package/reducers/setSubmitStatus.d.ts +6 -6
- package/reducers/setValue.d.ts +9 -10
- package/reducers/setValue.d.ts.map +1 -1
- package/reducers/setValue.js +9 -15
- package/reducers/setValue.js.map +1 -1
- package/reducers/setValue.mjs +9 -15
- package/reducers/setValue.mjs.map +1 -1
- package/reducers/submitSucceeded.d.ts +6 -6
- package/reducers/submitSucceeded.js +2 -2
- package/reducers/submitSucceeded.js.map +1 -1
- package/reducers/submitSucceeded.mjs +2 -2
- package/reducers/submitSucceeded.mjs.map +1 -1
- package/reducers/util/updateRawArray.d.ts +2 -2
- package/reducers/util/updateRawArray.d.ts.map +1 -1
- package/reducers/util/updateRawArray.js +3 -3
- package/reducers/util/updateRawArray.js.map +1 -1
- package/reducers/util/updateRawArray.mjs +3 -3
- package/reducers/util/updateRawArray.mjs.map +1 -1
- package/src/ConditionalValidator.ts +4 -1
- package/src/FieldPath.ts +3 -5
- package/src/FormAction.ts +2 -2
- package/src/FormContext.ts +7 -6
- package/src/FormState.ts +12 -8
- package/src/actions/arrayActions.ts +66 -58
- package/src/actions/initialize.ts +3 -2
- package/src/actions/setParsedValue.ts +21 -0
- package/src/actions/setSubmitStatus.ts +1 -1
- package/src/actions/setValue.ts +2 -5
- package/src/createFormMiddleware.ts +5 -3
- package/src/createFormProvider.tsx +12 -9
- package/src/createFormReducer.ts +17 -17
- package/src/createSelectFormStatus.ts +5 -5
- package/src/createSelectFormValues.ts +2 -2
- package/src/index.ts +1 -1
- package/src/initFormState.ts +1 -1
- package/src/reducers/arrayInsert.ts +9 -6
- package/src/reducers/arrayInsertParsed.ts +19 -0
- package/src/reducers/arrayPush.ts +5 -7
- package/src/reducers/arrayPushParsed.ts +23 -0
- package/src/reducers/arraySplice.ts +18 -5
- package/src/reducers/arraySpliceParsed.ts +17 -0
- package/src/reducers/arrayUnshift.ts +6 -4
- package/src/reducers/arrayUnshiftParsed.ts +16 -0
- package/src/reducers/initialize.ts +10 -8
- package/src/reducers/setParsedValue.ts +61 -0
- package/src/reducers/setValue.ts +12 -21
- package/src/reducers/submitSucceeded.ts +1 -1
- package/src/reducers/util/updateRawArray.ts +5 -5
- package/src/useArrayField.ts +17 -14
- package/src/useField.ts +27 -25
- package/src/useHtmlField.ts +42 -42
- package/src/useInitialize.ts +1 -1
- package/src/util/maybeParse.ts +2 -2
- package/useArrayField.d.ts +4 -4
- package/useArrayField.d.ts.map +1 -1
- package/useArrayField.js +16 -16
- package/useArrayField.js.map +1 -1
- package/useArrayField.mjs +12 -12
- package/useArrayField.mjs.map +1 -1
- package/useField.d.ts +7 -6
- package/useField.d.ts.map +1 -1
- package/useField.js +25 -25
- package/useField.js.map +1 -1
- package/useField.mjs +19 -19
- package/useField.mjs.map +1 -1
- package/useFormValues.d.ts +4 -4
- package/useHtmlField.js +40 -40
- package/useHtmlField.js.map +1 -1
- package/useHtmlField.mjs +36 -36
- package/useHtmlField.mjs.map +1 -1
- package/useInitialize.d.ts.map +1 -1
- package/useInitialize.js +1 -1
- package/useInitialize.js.map +1 -1
- package/useInitialize.mjs +1 -1
- package/useInitialize.mjs.map +1 -1
- package/util/maybeParse.d.ts +1 -1
- package/util/maybeParse.d.ts.map +1 -1
- package/util/maybeParse.js +2 -2
- package/util/maybeParse.js.map +1 -1
- package/util/maybeParse.mjs +2 -2
- package/util/maybeParse.mjs.map +1 -1
- package/actions/setRawValue.d.ts +0 -9
- package/actions/setRawValue.d.ts.map +0 -1
- package/actions/setRawValue.js +0 -14
- package/actions/setRawValue.js.map +0 -1
- package/actions/setRawValue.mjs +0 -8
- package/actions/setRawValue.mjs.map +0 -1
- package/reducers/arrayInsertRaw.d.ts +0 -7
- package/reducers/arrayInsertRaw.d.ts.map +0 -1
- package/reducers/arrayInsertRaw.js +0 -22
- package/reducers/arrayInsertRaw.js.map +0 -1
- package/reducers/arrayInsertRaw.mjs +0 -14
- package/reducers/arrayInsertRaw.mjs.map +0 -1
- package/reducers/arrayPushRaw.d.ts +0 -7
- package/reducers/arrayPushRaw.d.ts.map +0 -1
- package/reducers/arrayPushRaw.js +0 -17
- package/reducers/arrayPushRaw.js.map +0 -1
- package/reducers/arrayPushRaw.mjs +0 -9
- package/reducers/arrayPushRaw.mjs.map +0 -1
- package/reducers/arraySpliceRaw.d.ts +0 -7
- package/reducers/arraySpliceRaw.d.ts.map +0 -1
- package/reducers/arraySpliceRaw.js +0 -26
- package/reducers/arraySpliceRaw.js.map +0 -1
- package/reducers/arraySpliceRaw.mjs +0 -18
- package/reducers/arraySpliceRaw.mjs.map +0 -1
- package/reducers/arrayUnshiftRaw.d.ts +0 -7
- package/reducers/arrayUnshiftRaw.js +0 -17
- package/reducers/arrayUnshiftRaw.js.map +0 -1
- package/reducers/arrayUnshiftRaw.mjs +0 -9
- package/reducers/arrayUnshiftRaw.mjs.map +0 -1
- package/reducers/setRawValue.d.ts +0 -27
- package/reducers/setRawValue.d.ts.map +0 -1
- package/reducers/setRawValue.js.map +0 -1
- package/reducers/setRawValue.mjs +0 -26
- package/reducers/setRawValue.mjs.map +0 -1
- package/src/actions/setRawValue.ts +0 -17
- package/src/reducers/arrayInsertRaw.ts +0 -22
- package/src/reducers/arrayPushRaw.ts +0 -18
- package/src/reducers/arraySpliceRaw.ts +0 -30
- package/src/reducers/arrayUnshiftRaw.ts +0 -18
- package/src/reducers/setRawValue.ts +0 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submitSucceeded.js","names":["submitSucceededReducer","state","_objectSpread","submitting","submitSucceeded","submitFailed","submitError","undefined","submitPromise","
|
|
1
|
+
{"version":3,"file":"submitSucceeded.js","names":["submitSucceededReducer","state","_objectSpread","submitting","submitSucceeded","submitFailed","submitError","undefined","submitPromise","initialParsedValues","submittedParsedValues","initialValues","submittedValues"],"sources":["../../src/reducers/submitSucceeded.ts"],"sourcesContent":["import z from 'zod'\nimport { FormState } from '../FormState'\n\nexport function submitSucceededReducer<T extends z.ZodTypeAny>(\n state: FormState<T>\n) {\n return {\n ...state,\n submitting: false,\n submitSucceeded: true,\n submitFailed: false,\n submitError: undefined,\n submitPromise: undefined,\n initialParsedValues: state.submittedParsedValues,\n initialValues: state.submittedValues,\n }\n}\n"],"mappings":";;;;;;;;;;AAGO,SAASA,sBAAsBA,CACpCC,KAAmB,EACnB;EACA,OAAAC,aAAA,CAAAA,aAAA,KACKD,KAAK;IACRE,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,YAAY,EAAE,KAAK;IACnBC,WAAW,EAAEC,SAAS;IACtBC,aAAa,EAAED,SAAS;IACxBE,mBAAmB,EAAER,KAAK,CAACS,qBAAqB;IAChDC,aAAa,EAAEV,KAAK,CAACW;EAAe;AAExC","ignoreList":[]}
|
|
@@ -6,8 +6,8 @@ export function submitSucceededReducer(state) {
|
|
|
6
6
|
submitFailed: false,
|
|
7
7
|
submitError: undefined,
|
|
8
8
|
submitPromise: undefined,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
initialParsedValues: state.submittedParsedValues,
|
|
10
|
+
initialValues: state.submittedValues
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=submitSucceeded.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submitSucceeded.mjs","names":["submitSucceededReducer","state","submitting","submitSucceeded","submitFailed","submitError","undefined","submitPromise","
|
|
1
|
+
{"version":3,"file":"submitSucceeded.mjs","names":["submitSucceededReducer","state","submitting","submitSucceeded","submitFailed","submitError","undefined","submitPromise","initialParsedValues","submittedParsedValues","initialValues","submittedValues"],"sources":["../../src/reducers/submitSucceeded.ts"],"sourcesContent":["import z from 'zod'\nimport { FormState } from '../FormState'\n\nexport function submitSucceededReducer<T extends z.ZodTypeAny>(\n state: FormState<T>\n) {\n return {\n ...state,\n submitting: false,\n submitSucceeded: true,\n submitFailed: false,\n submitError: undefined,\n submitPromise: undefined,\n initialParsedValues: state.submittedParsedValues,\n initialValues: state.submittedValues,\n }\n}\n"],"mappings":"AAGA,OAAO,SAASA,sBAAsBA,CACpCC,KAAmB,EACnB;EACA,OAAO;IACL,GAAGA,KAAK;IACRC,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,YAAY,EAAE,KAAK;IACnBC,WAAW,EAAEC,SAAS;IACtBC,aAAa,EAAED,SAAS;IACxBE,mBAAmB,EAAEP,KAAK,CAACQ,qBAAqB;IAChDC,aAAa,EAAET,KAAK,CAACU;EACvB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import { Reducer } from 'react';
|
|
3
|
-
import { FieldPath,
|
|
3
|
+
import { FieldPath, FieldPathForValue } from '../../FieldPath';
|
|
4
4
|
import { FormState } from '../../FormState';
|
|
5
5
|
import { FormAction } from '../../FormAction';
|
|
6
|
-
export declare function updateRawArray<T extends z.ZodTypeAny, Field extends
|
|
6
|
+
export declare function updateRawArray<T extends z.ZodTypeAny, Field extends FieldPathForValue<any[]>>(reducer: Reducer<FormState<T>, FormAction<T>>, state: FormState<T>, field: FieldPath, updater: (array: z.input<Field['schema']> | undefined) => z.input<Field['schema']> | undefined): FormState<T>;
|
|
7
7
|
//# sourceMappingURL=updateRawArray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateRawArray.d.ts","sourceRoot":"","sources":["../../../src/reducers/util/updateRawArray.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"updateRawArray.d.ts","sourceRoot":"","sources":["../../../src/reducers/util/updateRawArray.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAI7C,wBAAgB,cAAc,CAC5B,CAAC,SAAS,CAAC,CAAC,UAAU,EACtB,KAAK,SAAS,iBAAiB,CAAC,GAAG,EAAE,CAAC,EAEtC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAC7C,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,CACP,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,KACxC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,gBAO1C"}
|
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.updateRawArray = updateRawArray;
|
|
7
7
|
var _get = require("../../util/get.js");
|
|
8
|
-
var
|
|
8
|
+
var _setValue = require("../../actions/setValue.js");
|
|
9
9
|
function updateRawArray(reducer, state, field, updater) {
|
|
10
|
-
var oldValue = (0, _get.get)(state.
|
|
10
|
+
var oldValue = (0, _get.get)(state.values, field.path);
|
|
11
11
|
var newValue = updater(oldValue);
|
|
12
|
-
return newValue === oldValue ? state : reducer(state, (0,
|
|
12
|
+
return newValue === oldValue ? state : reducer(state, (0, _setValue.setValue)(field, newValue));
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=updateRawArray.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateRawArray.js","names":["_get","require","
|
|
1
|
+
{"version":3,"file":"updateRawArray.js","names":["_get","require","_setValue","updateRawArray","reducer","state","field","updater","oldValue","get","values","path","newValue","setValue"],"sources":["../../../src/reducers/util/updateRawArray.ts"],"sourcesContent":["import z from 'zod'\nimport { Reducer } from 'react'\nimport { FieldPath, FieldPathForValue } from '../../FieldPath'\nimport { FormState } from '../../FormState'\nimport { FormAction } from '../../FormAction'\nimport { get } from '../../util/get'\nimport { setValue } from '../../actions/setValue'\n\nexport function updateRawArray<\n T extends z.ZodTypeAny,\n Field extends FieldPathForValue<any[]>\n>(\n reducer: Reducer<FormState<T>, FormAction<T>>,\n state: FormState<T>,\n field: FieldPath,\n updater: (\n array: z.input<Field['schema']> | undefined\n ) => z.input<Field['schema']> | undefined\n) {\n const oldValue = get(state.values, field.path)\n const newValue = updater(oldValue as any)\n return newValue === oldValue\n ? state\n : reducer(state, setValue(field, newValue))\n}\n"],"mappings":";;;;;;AAKA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEO,SAASE,cAAcA,CAI5BC,OAA6C,EAC7CC,KAAmB,EACnBC,KAAgB,EAChBC,OAEyC,EACzC;EACA,IAAMC,QAAQ,GAAG,IAAAC,QAAG,EAACJ,KAAK,CAACK,MAAM,EAAEJ,KAAK,CAACK,IAAI,CAAC;EAC9C,IAAMC,QAAQ,GAAGL,OAAO,CAACC,QAAe,CAAC;EACzC,OAAOI,QAAQ,KAAKJ,QAAQ,GACxBH,KAAK,GACLD,OAAO,CAACC,KAAK,EAAE,IAAAQ,kBAAQ,EAACP,KAAK,EAAEM,QAAQ,CAAC,CAAC;AAC/C","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { get } from "../../util/get.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { setValue } from "../../actions/setValue.mjs";
|
|
3
3
|
export function updateRawArray(reducer, state, field, updater) {
|
|
4
|
-
const oldValue = get(state.
|
|
4
|
+
const oldValue = get(state.values, field.path);
|
|
5
5
|
const newValue = updater(oldValue);
|
|
6
|
-
return newValue === oldValue ? state : reducer(state,
|
|
6
|
+
return newValue === oldValue ? state : reducer(state, setValue(field, newValue));
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=updateRawArray.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateRawArray.mjs","names":["get","
|
|
1
|
+
{"version":3,"file":"updateRawArray.mjs","names":["get","setValue","updateRawArray","reducer","state","field","updater","oldValue","values","path","newValue"],"sources":["../../../src/reducers/util/updateRawArray.ts"],"sourcesContent":["import z from 'zod'\nimport { Reducer } from 'react'\nimport { FieldPath, FieldPathForValue } from '../../FieldPath'\nimport { FormState } from '../../FormState'\nimport { FormAction } from '../../FormAction'\nimport { get } from '../../util/get'\nimport { setValue } from '../../actions/setValue'\n\nexport function updateRawArray<\n T extends z.ZodTypeAny,\n Field extends FieldPathForValue<any[]>\n>(\n reducer: Reducer<FormState<T>, FormAction<T>>,\n state: FormState<T>,\n field: FieldPath,\n updater: (\n array: z.input<Field['schema']> | undefined\n ) => z.input<Field['schema']> | undefined\n) {\n const oldValue = get(state.values, field.path)\n const newValue = updater(oldValue as any)\n return newValue === oldValue\n ? state\n : reducer(state, setValue(field, newValue))\n}\n"],"mappings":"AAKA,SAASA,GAAG;AACZ,SAASC,QAAQ;AAEjB,OAAO,SAASC,cAAcA,CAI5BC,OAA6C,EAC7CC,KAAmB,EACnBC,KAAgB,EAChBC,OAEyC,EACzC;EACA,MAAMC,QAAQ,GAAGP,GAAG,CAACI,KAAK,CAACI,MAAM,EAAEH,KAAK,CAACI,IAAI,CAAC;EAC9C,MAAMC,QAAQ,GAAGJ,OAAO,CAACC,QAAe,CAAC;EACzC,OAAOG,QAAQ,KAAKH,QAAQ,GACxBH,KAAK,GACLD,OAAO,CAACC,KAAK,EAAEH,QAAQ,CAACI,KAAK,EAAEK,QAAQ,CAAC,CAAC;AAC/C","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
|
+
import { IgnoreEffect } from 'zod-invertible'
|
|
2
3
|
import { DeepPartial } from './util/DeepPartial'
|
|
3
4
|
|
|
4
5
|
type ConditionalCheck<T extends z.ZodTypeAny> = {
|
|
@@ -38,7 +39,9 @@ export class ConditionalValidator<
|
|
|
38
39
|
Output = z.output<T>,
|
|
39
40
|
Input = z.input<T>
|
|
40
41
|
> extends z.ZodEffects<T, Output, Input> {
|
|
41
|
-
declare _def: ConditionalValidatorDef<T
|
|
42
|
+
declare _def: ConditionalValidatorDef<T>;
|
|
43
|
+
|
|
44
|
+
[IgnoreEffect] = true
|
|
42
45
|
|
|
43
46
|
constructor(schema: T, checks: ConditionalCheck<any>[]) {
|
|
44
47
|
super({
|
package/src/FieldPath.ts
CHANGED
|
@@ -4,12 +4,10 @@ import { SchemaAt } from './util/SchemaAt'
|
|
|
4
4
|
import { PathInSchema, PathstringInSchema } from './util/PathInSchema'
|
|
5
5
|
import { parsePathstring } from './util/parsePathstring'
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
z.ZodType<
|
|
9
|
-
>
|
|
10
|
-
export type FieldPathForRawValue<RawValue> = FieldPath<
|
|
11
|
-
z.ZodType<any, any, RawValue>
|
|
7
|
+
export type FieldPathForParsedValue<ParsedValue, Value = any> = FieldPath<
|
|
8
|
+
z.ZodType<ParsedValue, any, Value>
|
|
12
9
|
>
|
|
10
|
+
export type FieldPathForValue<Value> = FieldPath<z.ZodType<any, any, Value>>
|
|
13
11
|
|
|
14
12
|
export class FieldPath<T extends z.ZodTypeAny = z.ZodTypeAny> {
|
|
15
13
|
readonly path: BasePath
|
package/src/FormAction.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { SetMountedAction } from './actions/setMounted'
|
|
3
3
|
import { InitializeAction } from './actions/initialize'
|
|
4
|
+
import { SetParsedValueAction } from './actions/setParsedValue'
|
|
4
5
|
import { SetValueAction } from './actions/setValue'
|
|
5
|
-
import { SetRawValueAction } from './actions/setRawValue'
|
|
6
6
|
import { SetMetaAction } from './actions/setMeta'
|
|
7
7
|
import { FieldPath } from './FieldPath'
|
|
8
8
|
import { SubmitAction } from './actions/submit'
|
|
@@ -15,8 +15,8 @@ import { ArrayAction } from './actions/arrayActions'
|
|
|
15
15
|
export type FormAction<T extends z.ZodTypeAny> =
|
|
16
16
|
| SetMountedAction
|
|
17
17
|
| InitializeAction<T>
|
|
18
|
+
| SetParsedValueAction<FieldPath>
|
|
18
19
|
| SetValueAction<FieldPath>
|
|
19
|
-
| SetRawValueAction<FieldPath>
|
|
20
20
|
| SetMetaAction<FieldPath>
|
|
21
21
|
| AddHandlersAction<T>
|
|
22
22
|
| RemoveHandlersAction<T>
|
package/src/FormContext.ts
CHANGED
|
@@ -2,8 +2,8 @@ import React from 'react'
|
|
|
2
2
|
import z from 'zod'
|
|
3
3
|
import { FieldPath } from './FieldPath'
|
|
4
4
|
import { initialize } from './actions/initialize'
|
|
5
|
-
import { setRawValue } from './actions/setRawValue'
|
|
6
5
|
import { setValue } from './actions/setValue'
|
|
6
|
+
import { setParsedValue } from './actions/setParsedValue'
|
|
7
7
|
import { submit } from './actions/submit'
|
|
8
8
|
import { setSubmitStatus } from './actions/setSubmitStatus'
|
|
9
9
|
import { SelectFormValues } from './createSelectFormValues'
|
|
@@ -16,6 +16,7 @@ import { setMeta } from './actions/setMeta'
|
|
|
16
16
|
import { addHandlers } from './actions/addHandlers'
|
|
17
17
|
import { removeHandlers } from './actions/removeHandlers'
|
|
18
18
|
import { arrayActions } from './actions/arrayActions'
|
|
19
|
+
import { DeepPartial } from './util/DeepPartial'
|
|
19
20
|
|
|
20
21
|
export const FormContext =
|
|
21
22
|
React.createContext<FormContextProps<z.ZodTypeAny> | null>(null)
|
|
@@ -28,17 +29,17 @@ export type FormContextProps<T extends z.ZodTypeAny> = {
|
|
|
28
29
|
addHandlers: typeof addHandlers<T>
|
|
29
30
|
removeHandlers: typeof removeHandlers<T>
|
|
30
31
|
setMeta: typeof setMeta
|
|
31
|
-
setRawValue: typeof setRawValue
|
|
32
32
|
setValue: typeof setValue
|
|
33
|
+
setParsedValue: typeof setParsedValue
|
|
33
34
|
submit: typeof submit
|
|
34
35
|
setSubmitStatus: typeof setSubmitStatus<T>
|
|
35
36
|
arrayActions: typeof arrayActions
|
|
36
37
|
selectFormStatus: SelectFormStatus
|
|
37
38
|
selectFieldErrorMap: SelectFieldErrorMap
|
|
38
39
|
selectFormValues: SelectFormValues<T>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
getParsedValues: () => DeepPartial<z.output<T>> | undefined
|
|
41
|
+
getValues: () => DeepPartial<z.input<T>> | undefined
|
|
42
|
+
getInitialParsedValues: () => DeepPartial<z.output<T>> | undefined
|
|
43
|
+
getInitialValues: () => DeepPartial<z.input<T>> | undefined
|
|
43
44
|
getStatus: () => ReturnType<ReturnType<typeof createSelectFormStatus>>
|
|
44
45
|
}
|
package/src/FormState.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
|
+
import { DeepPartial } from './util/DeepPartial'
|
|
2
3
|
|
|
3
4
|
export type FieldMeta = {
|
|
4
5
|
touched: boolean
|
|
@@ -6,8 +7,11 @@ export type FieldMeta = {
|
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export type SubmitHandler<T extends z.ZodTypeAny> = (
|
|
9
|
-
|
|
10
|
-
options: {
|
|
10
|
+
parsedValues: z.output<T>,
|
|
11
|
+
options: {
|
|
12
|
+
initialValues?: DeepPartial<z.input<T>>
|
|
13
|
+
initialParsedValues?: DeepPartial<z.output<T>>
|
|
14
|
+
}
|
|
11
15
|
) => void | Promise<void>
|
|
12
16
|
|
|
13
17
|
export type SubmitSuccededHandler = () => void
|
|
@@ -18,12 +22,12 @@ export type FormState<T extends z.ZodTypeAny> = {
|
|
|
18
22
|
mounted: boolean
|
|
19
23
|
initialized: boolean
|
|
20
24
|
fieldMeta: Record<string, FieldMeta>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
values?: DeepPartial<z.input<T>>
|
|
26
|
+
parsedValues?: DeepPartial<z.output<T>>
|
|
27
|
+
submittedParsedValues?: z.output<T>
|
|
28
|
+
submittedValues?: z.input<T>
|
|
29
|
+
initialValues?: DeepPartial<z.input<T>>
|
|
30
|
+
initialParsedValues?: DeepPartial<z.output<T>>
|
|
27
31
|
validationError?: any
|
|
28
32
|
submitPromise?: Promise<void>
|
|
29
33
|
onSubmit: Set<SubmitHandler<T>>
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldPathForParsedValue } from '../FieldPath'
|
|
2
2
|
import z from 'zod'
|
|
3
|
+
import { DeepPartial } from '../util/DeepPartial'
|
|
3
4
|
|
|
4
|
-
export type ArrayFieldPath<V = any, R = any> =
|
|
5
|
+
export type ArrayFieldPath<V = any, R = any> = FieldPathForParsedValue<
|
|
5
6
|
V[] | null | undefined,
|
|
6
7
|
R[] | null | undefined
|
|
7
8
|
>
|
|
8
9
|
|
|
9
|
-
type
|
|
10
|
+
type ParsedValueFor<Field extends ArrayFieldPath> = NonNullable<
|
|
10
11
|
z.output<Field['schema']>
|
|
11
12
|
>[number]
|
|
12
13
|
|
|
13
|
-
type
|
|
14
|
-
z.input<Field['schema']
|
|
15
|
-
>
|
|
14
|
+
type ValueFor<Field extends ArrayFieldPath> = DeepPartial<
|
|
15
|
+
NonNullable<z.input<Field['schema']>>[number]
|
|
16
|
+
>
|
|
16
17
|
|
|
17
|
-
export type
|
|
18
|
-
|
|
18
|
+
export type ArrayInsertParsedAction<
|
|
19
|
+
Field extends ArrayFieldPath = ArrayFieldPath
|
|
20
|
+
> = ReturnType<typeof arrayInsertParsed<Field>>
|
|
19
21
|
|
|
20
|
-
export function
|
|
22
|
+
export function arrayInsertParsed<Field extends ArrayFieldPath>(
|
|
21
23
|
field: Field,
|
|
22
24
|
index: number,
|
|
23
|
-
|
|
25
|
+
parsedValue: ParsedValueFor<Field>
|
|
24
26
|
) {
|
|
25
|
-
return { type: '
|
|
27
|
+
return { type: 'arrayInsertParsed', field, index, parsedValue } as const
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export type
|
|
29
|
-
Field
|
|
30
|
-
> = ReturnType<typeof arrayInsertRaw<Field>>
|
|
30
|
+
export type ArrayInsertAction<Field extends ArrayFieldPath = ArrayFieldPath> =
|
|
31
|
+
ReturnType<typeof arrayInsert<Field>>
|
|
31
32
|
|
|
32
|
-
export function
|
|
33
|
+
export function arrayInsert<Field extends ArrayFieldPath>(
|
|
33
34
|
field: Field,
|
|
34
35
|
index: number,
|
|
35
|
-
|
|
36
|
+
value: ValueFor<Field>
|
|
36
37
|
) {
|
|
37
|
-
return { type: '
|
|
38
|
+
return { type: 'arrayInsert', field, index, value } as const
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export type ArrayMoveAction = ReturnType<typeof arrayMove>
|
|
@@ -49,24 +50,25 @@ export function arrayPop(field: ArrayFieldPath) {
|
|
|
49
50
|
return { type: 'arrayPop', field } as const
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
export type
|
|
53
|
-
|
|
53
|
+
export type ArrayPushParsedAction<
|
|
54
|
+
Field extends ArrayFieldPath = ArrayFieldPath
|
|
55
|
+
> = ReturnType<typeof arrayPushParsed<Field>>
|
|
54
56
|
|
|
55
|
-
export function
|
|
57
|
+
export function arrayPushParsed<Field extends ArrayFieldPath>(
|
|
56
58
|
field: Field,
|
|
57
|
-
|
|
59
|
+
parsedValue: ParsedValueFor<Field>
|
|
58
60
|
) {
|
|
59
|
-
return { type: '
|
|
61
|
+
return { type: 'arrayPushParsed', field, parsedValue } as const
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
export type
|
|
63
|
-
ReturnType<typeof
|
|
64
|
+
export type ArrayPushAction<Field extends ArrayFieldPath = ArrayFieldPath> =
|
|
65
|
+
ReturnType<typeof arrayPush<Field>>
|
|
64
66
|
|
|
65
|
-
export function
|
|
67
|
+
export function arrayPush<Field extends ArrayFieldPath>(
|
|
66
68
|
field: Field,
|
|
67
|
-
|
|
69
|
+
value: ValueFor<Field>
|
|
68
70
|
) {
|
|
69
|
-
return { type: '
|
|
71
|
+
return { type: 'arrayPush', field, value } as const
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export type ArrayRemoveAction = ReturnType<typeof arrayRemove>
|
|
@@ -87,34 +89,40 @@ export function arrayShift(field: ArrayFieldPath) {
|
|
|
87
89
|
return { type: 'arrayShift', field } as const
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
export type
|
|
91
|
-
|
|
92
|
+
export type ArraySpliceParsedAction<
|
|
93
|
+
Field extends ArrayFieldPath = ArrayFieldPath
|
|
94
|
+
> = ReturnType<typeof arraySpliceParsed<Field>>
|
|
92
95
|
|
|
93
|
-
export function
|
|
96
|
+
export function arraySpliceParsed<Field extends ArrayFieldPath>(
|
|
94
97
|
field: Field,
|
|
95
98
|
index: number,
|
|
96
99
|
deleteCount: number,
|
|
97
|
-
...
|
|
100
|
+
...parsedValues: ParsedValueFor<Field>[]
|
|
98
101
|
) {
|
|
99
|
-
return {
|
|
102
|
+
return {
|
|
103
|
+
type: 'arraySpliceParsed',
|
|
104
|
+
field,
|
|
105
|
+
index,
|
|
106
|
+
deleteCount,
|
|
107
|
+
parsedValues,
|
|
108
|
+
} as const
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
export type
|
|
103
|
-
Field
|
|
104
|
-
> = ReturnType<typeof arraySpliceRaw<Field>>
|
|
111
|
+
export type ArraySpliceAction<Field extends ArrayFieldPath = ArrayFieldPath> =
|
|
112
|
+
ReturnType<typeof arraySplice<Field>>
|
|
105
113
|
|
|
106
|
-
export function
|
|
114
|
+
export function arraySplice<Field extends ArrayFieldPath>(
|
|
107
115
|
field: Field,
|
|
108
116
|
index: number,
|
|
109
117
|
deleteCount: number,
|
|
110
|
-
...
|
|
118
|
+
...values: ValueFor<Field>[]
|
|
111
119
|
) {
|
|
112
120
|
return {
|
|
113
|
-
type: '
|
|
121
|
+
type: 'arraySplice',
|
|
114
122
|
field,
|
|
115
123
|
index,
|
|
116
124
|
deleteCount,
|
|
117
|
-
|
|
125
|
+
values,
|
|
118
126
|
} as const
|
|
119
127
|
}
|
|
120
128
|
|
|
@@ -128,56 +136,56 @@ export function arraySwap(
|
|
|
128
136
|
return { type: 'arraySwap', field, indexA, indexB } as const
|
|
129
137
|
}
|
|
130
138
|
|
|
131
|
-
export type
|
|
132
|
-
|
|
139
|
+
export type ArrayUnshiftParsedAction<
|
|
140
|
+
Field extends ArrayFieldPath = ArrayFieldPath
|
|
141
|
+
> = ReturnType<typeof arrayUnshiftParsed<Field>>
|
|
133
142
|
|
|
134
|
-
export function
|
|
143
|
+
export function arrayUnshiftParsed<Field extends ArrayFieldPath>(
|
|
135
144
|
field: Field,
|
|
136
|
-
|
|
145
|
+
parsedValue: ParsedValueFor<Field>
|
|
137
146
|
) {
|
|
138
|
-
return { type: '
|
|
147
|
+
return { type: 'arrayUnshiftParsed', field, parsedValue } as const
|
|
139
148
|
}
|
|
140
149
|
|
|
141
|
-
export type
|
|
142
|
-
Field
|
|
143
|
-
> = ReturnType<typeof arrayUnshiftRaw<Field>>
|
|
150
|
+
export type ArrayUnshiftAction<Field extends ArrayFieldPath = ArrayFieldPath> =
|
|
151
|
+
ReturnType<typeof arrayUnshift<Field>>
|
|
144
152
|
|
|
145
|
-
export function
|
|
153
|
+
export function arrayUnshift<Field extends ArrayFieldPath>(
|
|
146
154
|
field: Field,
|
|
147
|
-
|
|
155
|
+
value: ValueFor<Field>
|
|
148
156
|
) {
|
|
149
|
-
return { type: '
|
|
157
|
+
return { type: 'arrayUnshift', field, value } as const
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
export type ArrayAction<Field extends ArrayFieldPath = ArrayFieldPath> =
|
|
161
|
+
| ArrayInsertParsedAction<Field>
|
|
153
162
|
| ArrayInsertAction<Field>
|
|
154
|
-
| ArrayInsertRawAction<Field>
|
|
155
163
|
| ArrayMoveAction
|
|
156
164
|
| ArrayPopAction
|
|
165
|
+
| ArrayPushParsedAction<Field>
|
|
157
166
|
| ArrayPushAction<Field>
|
|
158
|
-
| ArrayPushRawAction<Field>
|
|
159
167
|
| ArrayRemoveAction
|
|
160
168
|
| ArrayRemoveAllAction
|
|
161
169
|
| ArrayShiftAction
|
|
170
|
+
| ArraySpliceParsedAction<Field>
|
|
162
171
|
| ArraySpliceAction<Field>
|
|
163
|
-
| ArraySpliceRawAction<Field>
|
|
164
172
|
| ArraySwapAction
|
|
173
|
+
| ArrayUnshiftParsedAction<Field>
|
|
165
174
|
| ArrayUnshiftAction<Field>
|
|
166
|
-
| ArrayUnshiftRawAction<Field>
|
|
167
175
|
|
|
168
176
|
export const arrayActions = {
|
|
177
|
+
insertParsed: arrayInsertParsed,
|
|
169
178
|
insert: arrayInsert,
|
|
170
|
-
insertRaw: arrayInsertRaw,
|
|
171
179
|
move: arrayMove,
|
|
172
180
|
pop: arrayPop,
|
|
181
|
+
pushParsed: arrayPushParsed,
|
|
173
182
|
push: arrayPush,
|
|
174
|
-
pushRaw: arrayPushRaw,
|
|
175
183
|
remove: arrayRemove,
|
|
176
184
|
removeAll: arrayRemoveAll,
|
|
177
185
|
shift: arrayShift,
|
|
186
|
+
spliceParsed: arraySpliceParsed,
|
|
178
187
|
splice: arraySplice,
|
|
179
|
-
spliceRaw: arraySpliceRaw,
|
|
180
188
|
swap: arraySwap,
|
|
189
|
+
unshiftParsed: arrayUnshiftParsed,
|
|
181
190
|
unshift: arrayUnshift,
|
|
182
|
-
unshiftRaw: arrayUnshiftRaw,
|
|
183
191
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
|
+
import { DeepPartial } from '../util/DeepPartial'
|
|
2
3
|
|
|
3
4
|
export type InitializeAction<T extends z.ZodTypeAny> = ReturnType<
|
|
4
5
|
typeof initialize<T>
|
|
5
6
|
>
|
|
6
7
|
|
|
7
8
|
export function initialize<T extends z.ZodTypeAny>(props: {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
values?: DeepPartial<z.input<T>>
|
|
10
|
+
parsedValues?: z.output<T>
|
|
10
11
|
keepSubmitSucceeded?: boolean
|
|
11
12
|
}) {
|
|
12
13
|
return {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FieldPath } from '../FieldPath'
|
|
3
|
+
|
|
4
|
+
export type SetParsedValueAction<Field extends FieldPath> = ReturnType<
|
|
5
|
+
typeof setParsedValue<Field>
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
export function setParsedValue<Field extends FieldPath>(
|
|
9
|
+
field: Field,
|
|
10
|
+
parsedValue: z.output<Field['schema']>,
|
|
11
|
+
options?: {
|
|
12
|
+
normalize?: boolean
|
|
13
|
+
}
|
|
14
|
+
) {
|
|
15
|
+
return {
|
|
16
|
+
type: 'setParsedValue',
|
|
17
|
+
field,
|
|
18
|
+
parsedValue,
|
|
19
|
+
...options,
|
|
20
|
+
} as const
|
|
21
|
+
}
|
package/src/actions/setValue.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { FieldPath } from '../FieldPath'
|
|
3
|
+
import { DeepPartial } from '../util/DeepPartial'
|
|
3
4
|
|
|
4
5
|
export type SetValueAction<Field extends FieldPath> = ReturnType<
|
|
5
6
|
typeof setValue<Field>
|
|
@@ -7,15 +8,11 @@ export type SetValueAction<Field extends FieldPath> = ReturnType<
|
|
|
7
8
|
|
|
8
9
|
export function setValue<Field extends FieldPath>(
|
|
9
10
|
field: Field,
|
|
10
|
-
value: z.
|
|
11
|
-
options?: {
|
|
12
|
-
normalize?: boolean
|
|
13
|
-
}
|
|
11
|
+
value: DeepPartial<z.input<Field['schema']>>
|
|
14
12
|
) {
|
|
15
13
|
return {
|
|
16
14
|
type: 'setValue',
|
|
17
15
|
field,
|
|
18
16
|
value,
|
|
19
|
-
...options,
|
|
20
17
|
} as const
|
|
21
18
|
}
|
|
@@ -22,19 +22,21 @@ export function createFormMiddleware<T extends z.ZodTypeAny>(): Middleware<
|
|
|
22
22
|
onSubmit,
|
|
23
23
|
onSubmitSucceeded,
|
|
24
24
|
onSubmitFailed,
|
|
25
|
+
parsedValues,
|
|
25
26
|
values,
|
|
26
|
-
rawValues,
|
|
27
27
|
initialValues,
|
|
28
|
+
initialParsedValues,
|
|
28
29
|
} = nextState
|
|
29
30
|
const submitPromise = (async () => {
|
|
30
31
|
if (nextState.validationError) throw nextState.validationError
|
|
31
|
-
for (const fn of onSubmit)
|
|
32
|
+
for (const fn of onSubmit)
|
|
33
|
+
await fn(parsedValues, { initialValues, initialParsedValues })
|
|
32
34
|
})()
|
|
33
35
|
store.dispatch(
|
|
34
36
|
setSubmitStatus({
|
|
35
37
|
submitting: true,
|
|
38
|
+
submittedParsedValues: parsedValues,
|
|
36
39
|
submittedValues: values,
|
|
37
|
-
rawSubmittedValues: rawValues,
|
|
38
40
|
submitError: undefined,
|
|
39
41
|
submitSucceeded: false,
|
|
40
42
|
submitFailed: false,
|
|
@@ -7,8 +7,8 @@ import { FormAction } from './FormAction'
|
|
|
7
7
|
import { FormState } from './FormState'
|
|
8
8
|
import { Provider } from 'react-redux'
|
|
9
9
|
import { initialize } from './actions/initialize'
|
|
10
|
-
import { setRawValue } from './actions/setRawValue'
|
|
11
10
|
import { setValue } from './actions/setValue'
|
|
11
|
+
import { setParsedValue } from './actions/setParsedValue'
|
|
12
12
|
import { FormContext, FormContextProps } from './FormContext'
|
|
13
13
|
import { FormStateContext } from './FormStateContext'
|
|
14
14
|
import { createFormMiddleware } from './createFormMiddleware'
|
|
@@ -41,14 +41,17 @@ export const createFormProvider = <T extends z.ZodTypeAny>(
|
|
|
41
41
|
const store = storeRef.current
|
|
42
42
|
const { dispatch } = store
|
|
43
43
|
|
|
44
|
+
const getParsedValues = React.useCallback(
|
|
45
|
+
() => store.getState().parsedValues,
|
|
46
|
+
[]
|
|
47
|
+
)
|
|
44
48
|
const getValues = React.useCallback(() => store.getState().values, [])
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
() => store.getState().initialValues,
|
|
49
|
+
const getInitialParsedValues = React.useCallback(
|
|
50
|
+
() => store.getState().initialParsedValues,
|
|
48
51
|
[]
|
|
49
52
|
)
|
|
50
|
-
const
|
|
51
|
-
() => store.getState().
|
|
53
|
+
const getInitialValues = React.useCallback(
|
|
54
|
+
() => store.getState().initialValues,
|
|
52
55
|
[]
|
|
53
56
|
)
|
|
54
57
|
const getStatus = React.useCallback(
|
|
@@ -65,10 +68,10 @@ export const createFormProvider = <T extends z.ZodTypeAny>(
|
|
|
65
68
|
const formContext = React.useMemo(
|
|
66
69
|
(): FormContextProps<T> => ({
|
|
67
70
|
...props,
|
|
71
|
+
getParsedValues,
|
|
68
72
|
getValues,
|
|
69
|
-
|
|
73
|
+
getInitialParsedValues,
|
|
70
74
|
getInitialValues,
|
|
71
|
-
getRawInitialValues,
|
|
72
75
|
getStatus,
|
|
73
76
|
...bindActionCreators(
|
|
74
77
|
{
|
|
@@ -78,8 +81,8 @@ export const createFormProvider = <T extends z.ZodTypeAny>(
|
|
|
78
81
|
submit,
|
|
79
82
|
setSubmitStatus: setSubmitStatus<T>,
|
|
80
83
|
setMeta: setMeta as any,
|
|
81
|
-
setRawValue: setRawValue as any,
|
|
82
84
|
setValue: setValue as any,
|
|
85
|
+
setParsedValue: setParsedValue as any,
|
|
83
86
|
},
|
|
84
87
|
dispatch
|
|
85
88
|
),
|