@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
package/src/createFormReducer.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { FormState } from './FormState'
|
|
|
5
5
|
import { initFormState } from './initFormState'
|
|
6
6
|
import { addHandlersReducer } from './reducers/addHandlers'
|
|
7
7
|
import { removeHandlersReducer } from './reducers/removeHandlers'
|
|
8
|
+
import { createSetParsedValueReducer } from './reducers/setParsedValue'
|
|
8
9
|
import { createSetValueReducer } from './reducers/setValue'
|
|
9
|
-
import { createSetRawValueReducer } from './reducers/setRawValue'
|
|
10
10
|
import { setMetaReducer } from './reducers/setMeta'
|
|
11
11
|
import { submitSucceededReducer } from './reducers/submitSucceeded'
|
|
12
12
|
import { setSubmitStatusReducer } from './reducers/setSubmitStatus'
|
|
@@ -17,22 +17,22 @@ import { arrayRemoveReducer } from './reducers/arrayRemove'
|
|
|
17
17
|
import { arrayRemoveAllReducer } from './reducers/arrayRemoveAll'
|
|
18
18
|
import { arrayShiftReducer } from './reducers/arrayShift'
|
|
19
19
|
import { arraySwapReducer } from './reducers/arraySwap'
|
|
20
|
-
import { arrayPushRawReducer } from './reducers/arrayPushRaw'
|
|
21
|
-
import { arrayInsertRawReducer } from './reducers/arrayInsertRaw'
|
|
22
|
-
import { arraySpliceRawReducer } from './reducers/arraySpliceRaw'
|
|
23
|
-
import { arrayUnshiftRawReducer } from './reducers/arrayUnshiftRaw'
|
|
24
20
|
import { arrayPushReducer } from './reducers/arrayPush'
|
|
25
|
-
import { arrayUnshiftReducer } from './reducers/arrayUnshift'
|
|
26
21
|
import { arrayInsertReducer } from './reducers/arrayInsert'
|
|
27
22
|
import { arraySpliceReducer } from './reducers/arraySplice'
|
|
23
|
+
import { arrayUnshiftReducer } from './reducers/arrayUnshift'
|
|
24
|
+
import { arrayPushParsedReducer } from './reducers/arrayPushParsed'
|
|
25
|
+
import { arrayUnshiftParsedReducer } from './reducers/arrayUnshiftParsed'
|
|
26
|
+
import { arrayInsertParsedReducer } from './reducers/arrayInsertParsed'
|
|
27
|
+
import { arraySpliceParsedReducer } from './reducers/arraySpliceParsed'
|
|
28
28
|
|
|
29
29
|
export function createFormReducer<T extends z.ZodTypeAny>(options: {
|
|
30
30
|
schema: T
|
|
31
31
|
inverseSchema: z.ZodType<z.input<T>, any, z.output<T>>
|
|
32
32
|
}): Reducer<FormState<T>, FormAction<T>> {
|
|
33
33
|
const initializeReducer = createInitializeReducer(options)
|
|
34
|
+
const setParsedValueReducer = createSetParsedValueReducer(options)
|
|
34
35
|
const setValueReducer = createSetValueReducer(options)
|
|
35
|
-
const setRawValueReducer = createSetRawValueReducer(options)
|
|
36
36
|
const formReducer = (
|
|
37
37
|
state: FormState<T> = initFormState(),
|
|
38
38
|
action: FormAction<T>
|
|
@@ -50,40 +50,40 @@ export function createFormReducer<T extends z.ZodTypeAny>(options: {
|
|
|
50
50
|
return setSubmitStatusReducer(state, action)
|
|
51
51
|
case 'submitSucceeded':
|
|
52
52
|
return submitSucceededReducer(state)
|
|
53
|
+
case 'setParsedValue':
|
|
54
|
+
return setParsedValueReducer(state, action)
|
|
53
55
|
case 'setValue':
|
|
54
56
|
return setValueReducer(state, action)
|
|
55
|
-
case 'setRawValue':
|
|
56
|
-
return setRawValueReducer(state, action)
|
|
57
57
|
case 'setMeta':
|
|
58
58
|
return setMetaReducer(state, action)
|
|
59
|
+
case 'arrayInsertParsed':
|
|
60
|
+
return arrayInsertParsedReducer(formReducer, state, action)
|
|
59
61
|
case 'arrayInsert':
|
|
60
62
|
return arrayInsertReducer(formReducer, state, action)
|
|
61
|
-
case 'arrayInsertRaw':
|
|
62
|
-
return arrayInsertRawReducer(formReducer, state, action)
|
|
63
63
|
case 'arrayMove':
|
|
64
64
|
return arrayMoveReducer(formReducer, state, action)
|
|
65
65
|
case 'arrayPop':
|
|
66
66
|
return arrayPopReducer(formReducer, state, action)
|
|
67
|
+
case 'arrayPushParsed':
|
|
68
|
+
return arrayPushParsedReducer(formReducer, state, action)
|
|
67
69
|
case 'arrayPush':
|
|
68
70
|
return arrayPushReducer(formReducer, state, action)
|
|
69
|
-
case 'arrayPushRaw':
|
|
70
|
-
return arrayPushRawReducer(formReducer, state, action)
|
|
71
71
|
case 'arrayRemove':
|
|
72
72
|
return arrayRemoveReducer(formReducer, state, action)
|
|
73
73
|
case 'arrayRemoveAll':
|
|
74
74
|
return arrayRemoveAllReducer(formReducer, state, action)
|
|
75
75
|
case 'arrayShift':
|
|
76
76
|
return arrayShiftReducer(formReducer, state, action)
|
|
77
|
+
case 'arraySpliceParsed':
|
|
78
|
+
return arraySpliceParsedReducer(formReducer, state, action)
|
|
77
79
|
case 'arraySplice':
|
|
78
80
|
return arraySpliceReducer(formReducer, state, action)
|
|
79
|
-
case 'arraySpliceRaw':
|
|
80
|
-
return arraySpliceRawReducer(formReducer, state, action)
|
|
81
81
|
case 'arraySwap':
|
|
82
82
|
return arraySwapReducer(formReducer, state, action)
|
|
83
|
+
case 'arrayUnshiftParsed':
|
|
84
|
+
return arrayUnshiftParsedReducer(formReducer, state, action)
|
|
83
85
|
case 'arrayUnshift':
|
|
84
86
|
return arrayUnshiftReducer(formReducer, state, action)
|
|
85
|
-
case 'arrayUnshiftRaw':
|
|
86
|
-
return arrayUnshiftRawReducer(formReducer, state, action)
|
|
87
87
|
}
|
|
88
88
|
return state
|
|
89
89
|
}
|
|
@@ -22,20 +22,20 @@ export function createSelectFormStatus() {
|
|
|
22
22
|
[
|
|
23
23
|
createSelector(
|
|
24
24
|
[
|
|
25
|
-
(state: FormState<any>) => state.
|
|
26
|
-
(state: FormState<any>) => state.
|
|
25
|
+
(state: FormState<any>) => state.parsedValues,
|
|
26
|
+
(state: FormState<any>) => state.initialParsedValues,
|
|
27
27
|
],
|
|
28
28
|
isEqual
|
|
29
29
|
),
|
|
30
30
|
createSelector(
|
|
31
31
|
[
|
|
32
|
-
(state: FormState<any>) => state.
|
|
33
|
-
(state: FormState<any>) => state.
|
|
32
|
+
(state: FormState<any>) => state.values,
|
|
33
|
+
(state: FormState<any>) => state.initialValues,
|
|
34
34
|
],
|
|
35
35
|
isEqual
|
|
36
36
|
),
|
|
37
37
|
],
|
|
38
|
-
(
|
|
38
|
+
(parsedPristine, pristine) => parsedPristine && pristine
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
return createStructuredSelector({
|
|
@@ -8,9 +8,9 @@ export type SelectFormValues<T extends z.ZodTypeAny> = ReturnType<
|
|
|
8
8
|
|
|
9
9
|
export function createSelectFormValues<T extends z.ZodTypeAny>() {
|
|
10
10
|
return createStructuredSelector({
|
|
11
|
+
parsedValues: (state: FormState<T>) => state.parsedValues,
|
|
11
12
|
values: (state: FormState<T>) => state.values,
|
|
12
|
-
|
|
13
|
+
initialParsedValues: (state: FormState<T>) => state.initialParsedValues,
|
|
13
14
|
initialValues: (state: FormState<T>) => state.initialValues,
|
|
14
|
-
rawInitialValues: (state: FormState<T>) => state.rawInitialValues,
|
|
15
15
|
})
|
|
16
16
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,8 +7,8 @@ export {
|
|
|
7
7
|
} from './FormState'
|
|
8
8
|
export {
|
|
9
9
|
FieldPath,
|
|
10
|
+
type FieldPathForParsedValue,
|
|
10
11
|
type FieldPathForValue,
|
|
11
|
-
type FieldPathForRawValue,
|
|
12
12
|
} from './FieldPath'
|
|
13
13
|
export { useField, type UseFieldProps, type TypedUseField } from './useField'
|
|
14
14
|
export {
|
package/src/initFormState.ts
CHANGED
|
@@ -6,8 +6,8 @@ export function initFormState<T extends z.ZodTypeAny>(): FormState<T> {
|
|
|
6
6
|
mounted: true,
|
|
7
7
|
initialized: false,
|
|
8
8
|
fieldMeta: {},
|
|
9
|
-
rawInitialValues: undefined,
|
|
10
9
|
initialValues: undefined,
|
|
10
|
+
initialParsedValues: undefined,
|
|
11
11
|
submitting: false,
|
|
12
12
|
submitFailed: false,
|
|
13
13
|
submitSucceeded: false,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { FormState } from '../FormState'
|
|
3
|
-
import {
|
|
3
|
+
import { ArrayInsertAction } from '../actions/arrayActions'
|
|
4
4
|
import { Reducer } from 'redux'
|
|
5
5
|
import { FormAction } from '../FormAction'
|
|
6
|
-
import {
|
|
6
|
+
import { updateRawArray } from './util/updateRawArray'
|
|
7
7
|
|
|
8
8
|
export function arrayInsertReducer<T extends z.ZodTypeAny>(
|
|
9
9
|
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
@@ -11,9 +11,12 @@ export function arrayInsertReducer<T extends z.ZodTypeAny>(
|
|
|
11
11
|
action: ArrayInsertAction
|
|
12
12
|
) {
|
|
13
13
|
const { field, index, value } = action
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
state,
|
|
17
|
-
arrayInsertRaw(field, index, inverseSchema.parse(value))
|
|
14
|
+
return updateRawArray(reducer, state, field, (array) =>
|
|
15
|
+
insert(array ?? [], index, value)
|
|
18
16
|
)
|
|
19
17
|
}
|
|
18
|
+
|
|
19
|
+
function insert<T>(array: T[], index: number, parsedValue: T) {
|
|
20
|
+
if (index < 0 || index > array.length) throw new Error(`index out of range`)
|
|
21
|
+
return [...array.slice(0, index), parsedValue, ...array.slice(index)]
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FormState } from '../FormState'
|
|
3
|
+
import { arrayInsert, ArrayInsertParsedAction } from '../actions/arrayActions'
|
|
4
|
+
import { Reducer } from 'redux'
|
|
5
|
+
import { FormAction } from '../FormAction'
|
|
6
|
+
import { getInverseArrayElementSchema } from './util/getInverseArrayElementSchema'
|
|
7
|
+
|
|
8
|
+
export function arrayInsertParsedReducer<T extends z.ZodTypeAny>(
|
|
9
|
+
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
10
|
+
state: FormState<T>,
|
|
11
|
+
action: ArrayInsertParsedAction
|
|
12
|
+
) {
|
|
13
|
+
const { field, index, parsedValue } = action
|
|
14
|
+
const inverseSchema = getInverseArrayElementSchema(field.schema)
|
|
15
|
+
return reducer(
|
|
16
|
+
state,
|
|
17
|
+
arrayInsert(field, index, inverseSchema.parse(parsedValue))
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -3,8 +3,7 @@ import { FormState } from '../FormState'
|
|
|
3
3
|
import { ArrayPushAction } from '../actions/arrayActions'
|
|
4
4
|
import { Reducer } from 'redux'
|
|
5
5
|
import { FormAction } from '../FormAction'
|
|
6
|
-
import {
|
|
7
|
-
import { get } from '../util/get'
|
|
6
|
+
import { updateRawArray } from './util/updateRawArray'
|
|
8
7
|
|
|
9
8
|
export function arrayPushReducer<T extends z.ZodTypeAny>(
|
|
10
9
|
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
@@ -12,9 +11,8 @@ export function arrayPushReducer<T extends z.ZodTypeAny>(
|
|
|
12
11
|
action: ArrayPushAction
|
|
13
12
|
) {
|
|
14
13
|
const { field, value } = action
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
14
|
+
return updateRawArray(reducer, state, field, (array) => [
|
|
15
|
+
...(array ?? []),
|
|
16
|
+
value,
|
|
17
|
+
])
|
|
20
18
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FormState } from '../FormState'
|
|
3
|
+
import { ArrayPushParsedAction } from '../actions/arrayActions'
|
|
4
|
+
import { Reducer } from 'redux'
|
|
5
|
+
import { FormAction } from '../FormAction'
|
|
6
|
+
import { setParsedValue } from '../actions/setParsedValue'
|
|
7
|
+
import { get } from '../util/get'
|
|
8
|
+
|
|
9
|
+
export function arrayPushParsedReducer<T extends z.ZodTypeAny>(
|
|
10
|
+
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
11
|
+
state: FormState<T>,
|
|
12
|
+
action: ArrayPushParsedAction
|
|
13
|
+
) {
|
|
14
|
+
const { field, parsedValue } = action
|
|
15
|
+
const array = get(state.values, field.path)
|
|
16
|
+
return reducer(
|
|
17
|
+
state,
|
|
18
|
+
setParsedValue(
|
|
19
|
+
field.get([Array.isArray(array) ? array.length : 0]),
|
|
20
|
+
parsedValue
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { FormState } from '../FormState'
|
|
3
|
-
import { ArraySpliceAction
|
|
3
|
+
import { ArraySpliceAction } from '../actions/arrayActions'
|
|
4
4
|
import { Reducer } from 'redux'
|
|
5
5
|
import { FormAction } from '../FormAction'
|
|
6
|
-
import {
|
|
6
|
+
import { updateRawArray } from './util/updateRawArray'
|
|
7
7
|
|
|
8
8
|
export function arraySpliceReducer<T extends z.ZodTypeAny>(
|
|
9
9
|
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
@@ -11,7 +11,20 @@ export function arraySpliceReducer<T extends z.ZodTypeAny>(
|
|
|
11
11
|
action: ArraySpliceAction
|
|
12
12
|
) {
|
|
13
13
|
const { field, index, deleteCount, values } = action
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return updateRawArray(reducer, state, field, (array) =>
|
|
15
|
+
splice(array ?? [], index, deleteCount, values)
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function splice<T>(
|
|
20
|
+
array: T[],
|
|
21
|
+
index: number,
|
|
22
|
+
deleteCount: number,
|
|
23
|
+
parsedValues: T[]
|
|
24
|
+
) {
|
|
25
|
+
if (index < 0 || index > array.length) throw new Error(`index out of range`)
|
|
26
|
+
if (!deleteCount && !parsedValues.length) return array
|
|
27
|
+
const result = [...array]
|
|
28
|
+
result.splice(index, deleteCount, ...parsedValues)
|
|
29
|
+
return result
|
|
17
30
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FormState } from '../FormState'
|
|
3
|
+
import { ArraySpliceParsedAction, arraySplice } from '../actions/arrayActions'
|
|
4
|
+
import { Reducer } from 'redux'
|
|
5
|
+
import { FormAction } from '../FormAction'
|
|
6
|
+
import { getInverseArrayElementSchema } from './util/getInverseArrayElementSchema'
|
|
7
|
+
|
|
8
|
+
export function arraySpliceParsedReducer<T extends z.ZodTypeAny>(
|
|
9
|
+
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
10
|
+
state: FormState<T>,
|
|
11
|
+
action: ArraySpliceParsedAction
|
|
12
|
+
) {
|
|
13
|
+
const { field, index, deleteCount, parsedValues } = action
|
|
14
|
+
const inverseSchema = getInverseArrayElementSchema(field.schema)
|
|
15
|
+
const values = parsedValues.map((v) => inverseSchema.parse(v))
|
|
16
|
+
return reducer(state, arraySplice(field, index, deleteCount, values))
|
|
17
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { FormState } from '../FormState'
|
|
3
|
-
import { ArrayUnshiftAction
|
|
3
|
+
import { ArrayUnshiftAction } from '../actions/arrayActions'
|
|
4
4
|
import { Reducer } from 'redux'
|
|
5
5
|
import { FormAction } from '../FormAction'
|
|
6
|
-
import {
|
|
6
|
+
import { updateRawArray } from './util/updateRawArray'
|
|
7
7
|
|
|
8
8
|
export function arrayUnshiftReducer<T extends z.ZodTypeAny>(
|
|
9
9
|
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
@@ -11,6 +11,8 @@ export function arrayUnshiftReducer<T extends z.ZodTypeAny>(
|
|
|
11
11
|
action: ArrayUnshiftAction
|
|
12
12
|
) {
|
|
13
13
|
const { field, value } = action
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
return updateRawArray(reducer, state, field, (array) => [
|
|
15
|
+
value,
|
|
16
|
+
...(array ?? []),
|
|
17
|
+
])
|
|
16
18
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FormState } from '../FormState'
|
|
3
|
+
import { ArrayUnshiftParsedAction, arrayUnshift } from '../actions/arrayActions'
|
|
4
|
+
import { Reducer } from 'redux'
|
|
5
|
+
import { FormAction } from '../FormAction'
|
|
6
|
+
import { getInverseArrayElementSchema } from './util/getInverseArrayElementSchema'
|
|
7
|
+
|
|
8
|
+
export function arrayUnshiftParsedReducer<T extends z.ZodTypeAny>(
|
|
9
|
+
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
10
|
+
state: FormState<T>,
|
|
11
|
+
action: ArrayUnshiftParsedAction
|
|
12
|
+
) {
|
|
13
|
+
const { field, parsedValue } = action
|
|
14
|
+
const inverseSchema = getInverseArrayElementSchema(field.schema)
|
|
15
|
+
return reducer(state, arrayUnshift(field, inverseSchema.parse(parsedValue)))
|
|
16
|
+
}
|
|
@@ -12,12 +12,14 @@ export const createInitializeReducer = <T extends z.ZodTypeAny>({
|
|
|
12
12
|
function initializeReducer(state: FormState<T>, action: InitializeAction<T>) {
|
|
13
13
|
const { keepSubmitSucceeded } = action
|
|
14
14
|
try {
|
|
15
|
-
const rawValues =
|
|
16
|
-
action.rawValues ??
|
|
17
|
-
(action.values ? inverseSchema.parse(action.values) : undefined)
|
|
18
15
|
const values =
|
|
19
16
|
action.values ??
|
|
20
|
-
(action.
|
|
17
|
+
(action.parsedValues
|
|
18
|
+
? inverseSchema.parse(action.parsedValues)
|
|
19
|
+
: undefined)
|
|
20
|
+
const parsedValues =
|
|
21
|
+
action.parsedValues ??
|
|
22
|
+
(action.values ? schema.parse(action.values) : undefined)
|
|
21
23
|
return {
|
|
22
24
|
...state,
|
|
23
25
|
validationError: undefined,
|
|
@@ -25,10 +27,10 @@ export const createInitializeReducer = <T extends z.ZodTypeAny>({
|
|
|
25
27
|
submitting: false,
|
|
26
28
|
submitFailed: false,
|
|
27
29
|
submitSucceeded: keepSubmitSucceeded ? state.submitSucceeded : false,
|
|
28
|
-
rawValues,
|
|
29
30
|
values,
|
|
30
|
-
|
|
31
|
+
parsedValues,
|
|
31
32
|
initialValues: values,
|
|
33
|
+
initialParsedValues: parsedValues,
|
|
32
34
|
}
|
|
33
35
|
} catch (error) {
|
|
34
36
|
return {
|
|
@@ -38,10 +40,10 @@ export const createInitializeReducer = <T extends z.ZodTypeAny>({
|
|
|
38
40
|
submitting: false,
|
|
39
41
|
submitFailed: false,
|
|
40
42
|
submitSucceeded: keepSubmitSucceeded ? state.submitSucceeded : false,
|
|
41
|
-
rawValues: action.rawValues,
|
|
42
43
|
values: action.values,
|
|
43
|
-
|
|
44
|
+
parsedValues: action.parsedValues,
|
|
44
45
|
initialValues: action.values,
|
|
46
|
+
initialParsedValues: action.parsedValues,
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { FormState } from '../FormState'
|
|
3
|
+
import { SetParsedValueAction } from '../actions/setParsedValue'
|
|
4
|
+
import { set } from '../util/set'
|
|
5
|
+
import { FieldPath } from '../FieldPath'
|
|
6
|
+
import { invert } from 'zod-invertible'
|
|
7
|
+
|
|
8
|
+
export const createSetParsedValueReducer = <T extends z.ZodTypeAny>({
|
|
9
|
+
schema,
|
|
10
|
+
inverseSchema,
|
|
11
|
+
}: {
|
|
12
|
+
schema: T
|
|
13
|
+
inverseSchema: z.ZodType<z.input<T>, any, z.output<T>>
|
|
14
|
+
}) =>
|
|
15
|
+
function setParsedValueReducer<Field extends FieldPath>(
|
|
16
|
+
state: FormState<T>,
|
|
17
|
+
action: SetParsedValueAction<Field>
|
|
18
|
+
) {
|
|
19
|
+
const newParsedValues = set(
|
|
20
|
+
state.parsedValues,
|
|
21
|
+
action.field.path,
|
|
22
|
+
action.parsedValue
|
|
23
|
+
) as (typeof state)['parsedValues']
|
|
24
|
+
try {
|
|
25
|
+
const newValues = inverseSchema.parse(newParsedValues)
|
|
26
|
+
schema.parse(newValues)
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
submitError: undefined,
|
|
30
|
+
validationError: undefined,
|
|
31
|
+
values: newValues,
|
|
32
|
+
parsedValues: newParsedValues,
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const newParsed = invert(action.field.schema).safeParse(
|
|
36
|
+
action.parsedValue
|
|
37
|
+
)
|
|
38
|
+
const values = newParsed.success
|
|
39
|
+
? (set(
|
|
40
|
+
state.values,
|
|
41
|
+
action.field.path,
|
|
42
|
+
newParsed.data
|
|
43
|
+
) as (typeof state)['values'])
|
|
44
|
+
: state.values
|
|
45
|
+
const newValidatedParsed = schema.safeParse(values)
|
|
46
|
+
const result = {
|
|
47
|
+
...state,
|
|
48
|
+
submitError: undefined,
|
|
49
|
+
validationError: !newParsed.success
|
|
50
|
+
? newParsed.error
|
|
51
|
+
: newValidatedParsed.success
|
|
52
|
+
? undefined
|
|
53
|
+
: newValidatedParsed.error,
|
|
54
|
+
values,
|
|
55
|
+
parsedValues: newValidatedParsed.success
|
|
56
|
+
? newValidatedParsed.data
|
|
57
|
+
: state.parsedValues,
|
|
58
|
+
}
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/reducers/setValue.ts
CHANGED
|
@@ -3,47 +3,38 @@ import { FormState } from '../FormState'
|
|
|
3
3
|
import { SetValueAction } from '../actions/setValue'
|
|
4
4
|
import { set } from '../util/set'
|
|
5
5
|
import { FieldPath } from '../FieldPath'
|
|
6
|
-
import { invert } from 'zod-invertible'
|
|
7
6
|
|
|
8
7
|
export const createSetValueReducer = <T extends z.ZodTypeAny>({
|
|
9
8
|
schema,
|
|
10
|
-
inverseSchema,
|
|
11
9
|
}: {
|
|
12
10
|
schema: T
|
|
13
|
-
inverseSchema: z.ZodType<z.input<T>, any, z.output<T>>
|
|
14
11
|
}) =>
|
|
15
12
|
function setValueReducer<Field extends FieldPath>(
|
|
16
13
|
state: FormState<T>,
|
|
17
14
|
action: SetValueAction<Field>
|
|
18
15
|
) {
|
|
19
|
-
const newValues = set(
|
|
16
|
+
const newValues = set(
|
|
17
|
+
state.values,
|
|
18
|
+
action.field.path,
|
|
19
|
+
action.value
|
|
20
|
+
) as (typeof state)['values']
|
|
21
|
+
if (newValues === state.values) return state
|
|
20
22
|
try {
|
|
21
|
-
const
|
|
22
|
-
schema.parse(newRawValues)
|
|
23
|
+
const newParsedValues = schema.parse(newValues)
|
|
23
24
|
return {
|
|
24
25
|
...state,
|
|
25
26
|
submitError: undefined,
|
|
26
27
|
validationError: undefined,
|
|
27
|
-
rawValues: newRawValues,
|
|
28
28
|
values: newValues,
|
|
29
|
+
parsedValues: newParsedValues,
|
|
29
30
|
}
|
|
30
31
|
} catch (error) {
|
|
31
|
-
|
|
32
|
-
const rawValues = newRawParsed.success
|
|
33
|
-
? set(state.rawValues, action.field.path, newRawParsed.data)
|
|
34
|
-
: state.rawValues
|
|
35
|
-
const newParsed = schema.safeParse(rawValues)
|
|
36
|
-
const result = {
|
|
32
|
+
return {
|
|
37
33
|
...state,
|
|
38
34
|
submitError: undefined,
|
|
39
|
-
validationError:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
? undefined
|
|
43
|
-
: newParsed.error,
|
|
44
|
-
rawValues,
|
|
45
|
-
values: newParsed.success ? newParsed.data : state.values,
|
|
35
|
+
validationError: error,
|
|
36
|
+
values: newValues,
|
|
37
|
+
parsedValues: undefined,
|
|
46
38
|
}
|
|
47
|
-
return result
|
|
48
39
|
}
|
|
49
40
|
}
|
|
@@ -11,7 +11,7 @@ export function submitSucceededReducer<T extends z.ZodTypeAny>(
|
|
|
11
11
|
submitFailed: false,
|
|
12
12
|
submitError: undefined,
|
|
13
13
|
submitPromise: undefined,
|
|
14
|
+
initialParsedValues: state.submittedParsedValues,
|
|
14
15
|
initialValues: state.submittedValues,
|
|
15
|
-
rawInitialValues: state.rawSubmittedValues,
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
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
6
|
import { get } from '../../util/get'
|
|
7
|
-
import {
|
|
7
|
+
import { setValue } from '../../actions/setValue'
|
|
8
8
|
|
|
9
9
|
export function updateRawArray<
|
|
10
10
|
T extends z.ZodTypeAny,
|
|
11
|
-
Field extends
|
|
11
|
+
Field extends FieldPathForValue<any[]>
|
|
12
12
|
>(
|
|
13
13
|
reducer: Reducer<FormState<T>, FormAction<T>>,
|
|
14
14
|
state: FormState<T>,
|
|
@@ -17,9 +17,9 @@ export function updateRawArray<
|
|
|
17
17
|
array: z.input<Field['schema']> | undefined
|
|
18
18
|
) => z.input<Field['schema']> | undefined
|
|
19
19
|
) {
|
|
20
|
-
const oldValue = get(state.
|
|
20
|
+
const oldValue = get(state.values, field.path)
|
|
21
21
|
const newValue = updater(oldValue as any)
|
|
22
22
|
return newValue === oldValue
|
|
23
23
|
? state
|
|
24
|
-
: reducer(state,
|
|
24
|
+
: reducer(state, setValue(field, newValue))
|
|
25
25
|
}
|
package/src/useArrayField.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
|
-
import { BasePath, FieldPath,
|
|
2
|
+
import { BasePath, FieldPath, FieldPathForValue } from './FieldPath'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { useFormContext } from './useFormContext'
|
|
5
5
|
import { PathInSchema, PathstringInSchema } from './util/PathInSchema'
|
|
@@ -15,10 +15,11 @@ import {
|
|
|
15
15
|
useFormSelector as untypedUseFormSelector,
|
|
16
16
|
} from './useFormSelector'
|
|
17
17
|
import { shallowEqual } from 'react-redux'
|
|
18
|
+
import { setParsedValue } from './actions/setParsedValue'
|
|
18
19
|
import { setValue } from './actions/setValue'
|
|
19
|
-
import { setRawValue } from './actions/setRawValue'
|
|
20
20
|
import { setMeta } from './actions/setMeta'
|
|
21
21
|
import { FieldMeta } from './FormState'
|
|
22
|
+
import { DeepPartial } from './util/DeepPartial'
|
|
22
23
|
|
|
23
24
|
export type UseArrayFieldProps<Field extends FieldPath> = NonNullable<
|
|
24
25
|
z.input<Field['schema']>
|
|
@@ -27,8 +28,8 @@ export type UseArrayFieldProps<Field extends FieldPath> = NonNullable<
|
|
|
27
28
|
ReturnType<
|
|
28
29
|
typeof bindActionsToField<
|
|
29
30
|
typeof arrayActions & {
|
|
31
|
+
setParsedValue: typeof setParsedValue
|
|
30
32
|
setValue: typeof setValue
|
|
31
|
-
setRawValue: typeof setRawValue
|
|
32
33
|
setMeta: typeof setMeta
|
|
33
34
|
}
|
|
34
35
|
>
|
|
@@ -43,7 +44,7 @@ export type UseArrayFieldProps<Field extends FieldPath> = NonNullable<
|
|
|
43
44
|
: { ERROR: 'not an array field' }
|
|
44
45
|
|
|
45
46
|
export interface TypedUseArrayField<T extends z.ZodTypeAny> {
|
|
46
|
-
<Field extends
|
|
47
|
+
<Field extends FieldPathForValue<any[] | null | undefined>>(
|
|
47
48
|
field: Field
|
|
48
49
|
): UseArrayFieldProps<Field>
|
|
49
50
|
<Path extends PathInSchema<T>>(path: Path): UseArrayFieldProps<
|
|
@@ -61,8 +62,8 @@ function useArrayFieldBase<Field extends FieldPath>(
|
|
|
61
62
|
|
|
62
63
|
const {
|
|
63
64
|
arrayActions,
|
|
65
|
+
setParsedValue,
|
|
64
66
|
setValue,
|
|
65
|
-
setRawValue,
|
|
66
67
|
setMeta,
|
|
67
68
|
selectFormValues,
|
|
68
69
|
selectFieldErrorMap,
|
|
@@ -77,21 +78,23 @@ function useArrayFieldBase<Field extends FieldPath>(
|
|
|
77
78
|
createSelector(
|
|
78
79
|
[
|
|
79
80
|
createStructuredSelector({
|
|
81
|
+
parsedValue: ({ parsedValues }) =>
|
|
82
|
+
get(parsedValues, field.path) as
|
|
83
|
+
| DeepPartial<z.output<T>>
|
|
84
|
+
| undefined,
|
|
80
85
|
value: ({ values }) =>
|
|
81
|
-
get(values, field.path) as z.
|
|
82
|
-
|
|
83
|
-
get(
|
|
84
|
-
initialValue: ({ initialValues }) =>
|
|
85
|
-
get(initialValues, field.path) as z.output<T> | undefined,
|
|
86
|
+
get(values, field.path) as DeepPartial<z.input<T>> | undefined,
|
|
87
|
+
initialParsedValue: ({ initialParsedValues }) =>
|
|
88
|
+
get(initialParsedValues, field.path) as z.output<T> | undefined,
|
|
86
89
|
}),
|
|
87
90
|
],
|
|
88
|
-
({
|
|
89
|
-
const dirty = !isEqual(
|
|
91
|
+
({ value, parsedValue, initialParsedValue }) => {
|
|
92
|
+
const dirty = !isEqual(parsedValue, initialParsedValue)
|
|
90
93
|
const pristine = !dirty
|
|
91
94
|
return {
|
|
92
95
|
dirty,
|
|
93
96
|
pristine,
|
|
94
|
-
length: Array.isArray(
|
|
97
|
+
length: Array.isArray(value) ? value.length : 0,
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
)
|
|
@@ -113,7 +116,7 @@ function useArrayFieldBase<Field extends FieldPath>(
|
|
|
113
116
|
const boundActions = React.useMemo(
|
|
114
117
|
() =>
|
|
115
118
|
bindActionsToField(
|
|
116
|
-
{ ...arrayActions,
|
|
119
|
+
{ ...arrayActions, setParsedValue, setValue, setMeta },
|
|
117
120
|
field
|
|
118
121
|
),
|
|
119
122
|
[field.pathstring]
|