pdyform 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/package.json +38 -2
- package/packages/core/dist/{chunk-KA6QUMVR.js → chunk-T3LQTNYY.js} +3 -0
- package/packages/core/dist/chunk-V4VK2GZU.js +108 -0
- package/packages/core/dist/formState.cjs +88 -52
- package/packages/core/dist/formState.d.cts +12 -5
- package/packages/core/dist/formState.d.ts +12 -5
- package/packages/core/dist/formState.js +6 -4
- package/packages/core/dist/index.cjs +88 -52
- package/packages/core/dist/index.d.cts +1 -2
- package/packages/core/dist/index.d.ts +1 -2
- package/packages/core/dist/index.js +6 -4
- package/packages/core/dist/types.d.cts +7 -7
- package/packages/core/dist/types.d.ts +7 -7
- package/packages/core/dist/utils.cjs +3 -0
- package/packages/core/dist/utils.d.cts +6 -6
- package/packages/core/dist/utils.d.ts +6 -6
- package/packages/core/dist/utils.js +1 -1
- package/packages/react/dist/index.cjs +1 -1
- package/packages/react/dist/index.d.cts +6 -7
- package/packages/react/dist/index.d.ts +6 -7
- package/packages/react/dist/index.js +1 -1
- package/packages/vue/dist/index.d.ts +7 -22
- package/packages/vue/dist/index.js +1 -1
- package/packages/vue/dist/index.mjs +388 -380
- package/packages/core/dist/chunk-REHKL5VH.js +0 -76
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
get,
|
|
3
|
-
getDefaultValues,
|
|
4
|
-
normalizeFieldValue,
|
|
5
|
-
set,
|
|
6
|
-
validateFieldByName,
|
|
7
|
-
validateForm
|
|
8
|
-
} from "./chunk-KA6QUMVR.js";
|
|
9
|
-
|
|
10
|
-
// src/formState.ts
|
|
11
|
-
import { createStore } from "zustand/vanilla";
|
|
12
|
-
function createFormStore(fields, resolver, errorMessages) {
|
|
13
|
-
return createStore()((set2, getStore) => ({
|
|
14
|
-
values: getDefaultValues(fields),
|
|
15
|
-
errors: {},
|
|
16
|
-
validatingFields: [],
|
|
17
|
-
isSubmitting: false,
|
|
18
|
-
setFieldValue: async (name, rawValue) => {
|
|
19
|
-
const field = fields.find((f) => f.name === name);
|
|
20
|
-
const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
|
|
21
|
-
set2((state) => ({
|
|
22
|
-
values: set(state.values, name, normalizedValue),
|
|
23
|
-
validatingFields: [...state.validatingFields, name]
|
|
24
|
-
}));
|
|
25
|
-
try {
|
|
26
|
-
const currentValues = getStore().values;
|
|
27
|
-
const error = await validateFieldByName(fields, name, normalizedValue, resolver, currentValues, errorMessages);
|
|
28
|
-
set2((state) => ({
|
|
29
|
-
errors: { ...state.errors, [name]: error || "" },
|
|
30
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
31
|
-
}));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
set2((state) => ({
|
|
34
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
setFieldBlur: async (name) => {
|
|
39
|
-
set2((state) => ({
|
|
40
|
-
validatingFields: [...state.validatingFields, name]
|
|
41
|
-
}));
|
|
42
|
-
try {
|
|
43
|
-
const currentValues = getStore().values;
|
|
44
|
-
const value = get(currentValues, name);
|
|
45
|
-
const error = await validateFieldByName(fields, name, value, resolver, currentValues, errorMessages);
|
|
46
|
-
set2((state) => ({
|
|
47
|
-
errors: { ...state.errors, [name]: error || "" },
|
|
48
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
49
|
-
}));
|
|
50
|
-
} catch (err) {
|
|
51
|
-
set2((state) => ({
|
|
52
|
-
validatingFields: state.validatingFields.filter((f) => f !== name)
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
setSubmitting: (isSubmitting) => set2({ isSubmitting }),
|
|
57
|
-
runSubmitValidation: async () => {
|
|
58
|
-
set2({ isSubmitting: true });
|
|
59
|
-
const state = getStore();
|
|
60
|
-
const errors = await validateForm(fields, state.values, resolver, errorMessages);
|
|
61
|
-
const hasError = Object.keys(errors).length > 0;
|
|
62
|
-
set2({
|
|
63
|
-
errors,
|
|
64
|
-
isSubmitting: false
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
state: getStore(),
|
|
68
|
-
hasError
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export {
|
|
75
|
-
createFormStore
|
|
76
|
-
};
|