pdyform 2.0.0 → 2.0.2

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.
Files changed (44) hide show
  1. package/package.json +3 -2
  2. package/packages/core/dist/chunk-TP3IHKWV.js +69 -0
  3. package/packages/core/dist/{chunk-GQASS6PM.js → chunk-WEDHXOHH.js} +22 -0
  4. package/packages/core/dist/formState.cjs +187 -0
  5. package/packages/core/dist/formState.d.cts +17 -0
  6. package/packages/core/dist/formState.d.ts +17 -0
  7. package/packages/core/dist/formState.js +15 -0
  8. package/packages/core/dist/index.cjs +92 -2
  9. package/packages/core/dist/index.d.cts +2 -1
  10. package/packages/core/dist/index.d.ts +2 -1
  11. package/packages/core/dist/index.js +21 -3
  12. package/packages/core/dist/utils.cjs +27 -2
  13. package/packages/core/dist/utils.d.cts +4 -1
  14. package/packages/core/dist/utils.d.ts +4 -1
  15. package/packages/core/dist/utils.js +9 -3
  16. package/packages/core/node_modules/.vite/vitest/results.json +1 -1
  17. package/packages/core/src/formState.ts +79 -0
  18. package/packages/core/src/index.ts +1 -0
  19. package/packages/core/src/utils.ts +24 -0
  20. package/packages/core/test/formState.test.ts +71 -0
  21. package/packages/core/test/utils.test.ts +80 -1
  22. package/packages/core/tsup.config.ts +1 -1
  23. package/packages/react/dist/index.cjs +14 -43
  24. package/packages/react/dist/index.js +20 -43
  25. package/packages/react/node_modules/.vite/vitest/results.json +1 -1
  26. package/packages/react/src/DynamicForm.tsx +20 -44
  27. package/packages/react/src/components/InputRenderer.tsx +2 -6
  28. package/packages/vue/dist/index.js +5 -5
  29. package/packages/vue/dist/index.mjs +769 -787
  30. package/packages/vue/node_modules/.vite/vitest/results.json +1 -1
  31. package/packages/vue/src/DynamicForm.vue +18 -36
  32. package/packages/vue/src/components/InputRenderer.vue +2 -6
  33. package/turbo.json +8 -0
  34. package/example/react-demo/dist/assets/index-BBU9cJqy.css +0 -1
  35. package/example/react-demo/dist/assets/index-DeJS8UcQ.js +0 -105
  36. package/example/react-demo/dist/index.html +0 -13
  37. package/example/vue-demo/dist/assets/index-BhWj3D5x.css +0 -1
  38. package/example/vue-demo/dist/assets/index-Bw3THsrD.js +0 -44
  39. package/example/vue-demo/dist/index.html +0 -13
  40. package/packages/core/dist/parser.cjs +0 -1
  41. package/packages/core/dist/parser.d.cts +0 -2
  42. package/packages/core/dist/parser.d.ts +0 -2
  43. package/packages/core/dist/parser.js +0 -0
  44. package/packages/core/src/parser.ts +0 -0
package/package.json CHANGED
@@ -48,9 +48,10 @@
48
48
  "turbo": "latest",
49
49
  "typescript": "^5.0.0",
50
50
  "typescript-eslint": "^8.56.1",
51
- "vitest": "^1.0.0"
51
+ "vitest": "^1.0.0",
52
+ "vue": "^3.5.0"
52
53
  },
53
- "version": "2.0.0",
54
+ "version": "2.0.2",
54
55
  "scripts": {
55
56
  "build:all": "turbo run build",
56
57
  "dev:all": "turbo run dev",
@@ -0,0 +1,69 @@
1
+ import {
2
+ getDefaultValues,
3
+ normalizeFieldValue,
4
+ validateFieldByName,
5
+ validateForm
6
+ } from "./chunk-WEDHXOHH.js";
7
+
8
+ // src/formState.ts
9
+ function createFormRuntimeState(fields) {
10
+ return {
11
+ values: getDefaultValues(fields),
12
+ errors: {},
13
+ isSubmitting: false
14
+ };
15
+ }
16
+ function setSubmitting(state, isSubmitting) {
17
+ return {
18
+ ...state,
19
+ isSubmitting
20
+ };
21
+ }
22
+ function applyFieldChange(fields, state, name, rawValue) {
23
+ const field = fields.find((f) => f.name === name);
24
+ const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
25
+ const values = {
26
+ ...state.values,
27
+ [name]: normalizedValue
28
+ };
29
+ const error = validateFieldByName(fields, name, normalizedValue);
30
+ const errors = {
31
+ ...state.errors,
32
+ [name]: error || ""
33
+ };
34
+ return {
35
+ ...state,
36
+ values,
37
+ errors
38
+ };
39
+ }
40
+ function applyFieldBlur(fields, state, name) {
41
+ const error = validateFieldByName(fields, name, state.values[name]);
42
+ return {
43
+ ...state,
44
+ errors: {
45
+ ...state.errors,
46
+ [name]: error || ""
47
+ }
48
+ };
49
+ }
50
+ function runSubmitValidation(fields, state) {
51
+ const errors = validateForm(fields, state.values);
52
+ const hasError = Object.keys(errors).length > 0;
53
+ return {
54
+ state: {
55
+ ...state,
56
+ errors,
57
+ isSubmitting: false
58
+ },
59
+ hasError
60
+ };
61
+ }
62
+
63
+ export {
64
+ createFormRuntimeState,
65
+ setSubmitting,
66
+ applyFieldChange,
67
+ applyFieldBlur,
68
+ runSubmitValidation
69
+ };
@@ -5,6 +5,12 @@ function parseNumberish(value) {
5
5
  const parsed = Number(value);
6
6
  return Number.isNaN(parsed) ? null : parsed;
7
7
  }
8
+ function normalizeFieldValue(field, value) {
9
+ if (field.type !== "number") return value;
10
+ if (value === "" || value === void 0 || value === null) return "";
11
+ const numericValue = parseNumberish(value);
12
+ return numericValue === null ? value : numericValue;
13
+ }
8
14
  function validateField(value, field) {
9
15
  if (!field.validations) return null;
10
16
  for (const rule of field.validations) {
@@ -67,6 +73,19 @@ function validateField(value, field) {
67
73
  }
68
74
  return null;
69
75
  }
76
+ function validateFieldByName(fields, name, value) {
77
+ const field = fields.find((f) => f.name === name);
78
+ if (!field) return null;
79
+ return validateField(value, field);
80
+ }
81
+ function validateForm(fields, values) {
82
+ const errors = {};
83
+ for (const field of fields) {
84
+ const error = validateField(values[field.name], field);
85
+ if (error) errors[field.name] = error;
86
+ }
87
+ return errors;
88
+ }
70
89
  function getDefaultValues(fields) {
71
90
  return fields.reduce((acc, field) => {
72
91
  acc[field.name] = field.defaultValue !== void 0 ? field.defaultValue : field.type === "checkbox" ? [] : "";
@@ -75,6 +94,9 @@ function getDefaultValues(fields) {
75
94
  }
76
95
 
77
96
  export {
97
+ normalizeFieldValue,
78
98
  validateField,
99
+ validateFieldByName,
100
+ validateForm,
79
101
  getDefaultValues
80
102
  };
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/formState.ts
21
+ var formState_exports = {};
22
+ __export(formState_exports, {
23
+ applyFieldBlur: () => applyFieldBlur,
24
+ applyFieldChange: () => applyFieldChange,
25
+ createFormRuntimeState: () => createFormRuntimeState,
26
+ runSubmitValidation: () => runSubmitValidation,
27
+ setSubmitting: () => setSubmitting
28
+ });
29
+ module.exports = __toCommonJS(formState_exports);
30
+
31
+ // src/utils.ts
32
+ function parseNumberish(value) {
33
+ if (typeof value === "number") return Number.isNaN(value) ? null : value;
34
+ if (typeof value !== "string" || value.trim() === "") return null;
35
+ const parsed = Number(value);
36
+ return Number.isNaN(parsed) ? null : parsed;
37
+ }
38
+ function normalizeFieldValue(field, value) {
39
+ if (field.type !== "number") return value;
40
+ if (value === "" || value === void 0 || value === null) return "";
41
+ const numericValue = parseNumberish(value);
42
+ return numericValue === null ? value : numericValue;
43
+ }
44
+ function validateField(value, field) {
45
+ if (!field.validations) return null;
46
+ for (const rule of field.validations) {
47
+ switch (rule.type) {
48
+ case "required":
49
+ if (value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0) {
50
+ return rule.message || `${field.label} is required`;
51
+ }
52
+ break;
53
+ case "min":
54
+ if (field.type === "number") {
55
+ const numericValue = parseNumberish(value);
56
+ if (numericValue !== null && numericValue < rule.value) {
57
+ return rule.message || `${field.label} must be at least ${rule.value}`;
58
+ }
59
+ break;
60
+ }
61
+ if (typeof value === "number" && value < rule.value) {
62
+ return rule.message || `${field.label} must be at least ${rule.value}`;
63
+ }
64
+ if (typeof value === "string" && value.length < rule.value) {
65
+ return rule.message || `${field.label} must be at least ${rule.value} characters`;
66
+ }
67
+ break;
68
+ case "max":
69
+ if (field.type === "number") {
70
+ const numericValue = parseNumberish(value);
71
+ if (numericValue !== null && numericValue > rule.value) {
72
+ return rule.message || `${field.label} must be at most ${rule.value}`;
73
+ }
74
+ break;
75
+ }
76
+ if (typeof value === "number" && value > rule.value) {
77
+ return rule.message || `${field.label} must be at most ${rule.value}`;
78
+ }
79
+ if (typeof value === "string" && value.length > rule.value) {
80
+ return rule.message || `${field.label} must be at most ${rule.value} characters`;
81
+ }
82
+ break;
83
+ case "email": {
84
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
85
+ if (value && !emailRegex.test(value)) {
86
+ return rule.message || "Invalid email address";
87
+ }
88
+ break;
89
+ }
90
+ case "pattern":
91
+ if (value && rule.value && !new RegExp(rule.value).test(value)) {
92
+ return rule.message || "Invalid format";
93
+ }
94
+ break;
95
+ case "custom":
96
+ if (rule.validator) {
97
+ const result = rule.validator(value);
98
+ if (typeof result === "string") return result;
99
+ if (!result) return rule.message || "Invalid value";
100
+ }
101
+ break;
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+ function validateFieldByName(fields, name, value) {
107
+ const field = fields.find((f) => f.name === name);
108
+ if (!field) return null;
109
+ return validateField(value, field);
110
+ }
111
+ function validateForm(fields, values) {
112
+ const errors = {};
113
+ for (const field of fields) {
114
+ const error = validateField(values[field.name], field);
115
+ if (error) errors[field.name] = error;
116
+ }
117
+ return errors;
118
+ }
119
+ function getDefaultValues(fields) {
120
+ return fields.reduce((acc, field) => {
121
+ acc[field.name] = field.defaultValue !== void 0 ? field.defaultValue : field.type === "checkbox" ? [] : "";
122
+ return acc;
123
+ }, {});
124
+ }
125
+
126
+ // src/formState.ts
127
+ function createFormRuntimeState(fields) {
128
+ return {
129
+ values: getDefaultValues(fields),
130
+ errors: {},
131
+ isSubmitting: false
132
+ };
133
+ }
134
+ function setSubmitting(state, isSubmitting) {
135
+ return {
136
+ ...state,
137
+ isSubmitting
138
+ };
139
+ }
140
+ function applyFieldChange(fields, state, name, rawValue) {
141
+ const field = fields.find((f) => f.name === name);
142
+ const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
143
+ const values = {
144
+ ...state.values,
145
+ [name]: normalizedValue
146
+ };
147
+ const error = validateFieldByName(fields, name, normalizedValue);
148
+ const errors = {
149
+ ...state.errors,
150
+ [name]: error || ""
151
+ };
152
+ return {
153
+ ...state,
154
+ values,
155
+ errors
156
+ };
157
+ }
158
+ function applyFieldBlur(fields, state, name) {
159
+ const error = validateFieldByName(fields, name, state.values[name]);
160
+ return {
161
+ ...state,
162
+ errors: {
163
+ ...state.errors,
164
+ [name]: error || ""
165
+ }
166
+ };
167
+ }
168
+ function runSubmitValidation(fields, state) {
169
+ const errors = validateForm(fields, state.values);
170
+ const hasError = Object.keys(errors).length > 0;
171
+ return {
172
+ state: {
173
+ ...state,
174
+ errors,
175
+ isSubmitting: false
176
+ },
177
+ hasError
178
+ };
179
+ }
180
+ // Annotate the CommonJS export names for ESM import in node:
181
+ 0 && (module.exports = {
182
+ applyFieldBlur,
183
+ applyFieldChange,
184
+ createFormRuntimeState,
185
+ runSubmitValidation,
186
+ setSubmitting
187
+ });
@@ -0,0 +1,17 @@
1
+ import { FormField } from './types.cjs';
2
+
3
+ interface FormRuntimeState {
4
+ values: Record<string, any>;
5
+ errors: Record<string, string>;
6
+ isSubmitting: boolean;
7
+ }
8
+ declare function createFormRuntimeState(fields: FormField[]): FormRuntimeState;
9
+ declare function setSubmitting(state: FormRuntimeState, isSubmitting: boolean): FormRuntimeState;
10
+ declare function applyFieldChange(fields: FormField[], state: FormRuntimeState, name: string, rawValue: unknown): FormRuntimeState;
11
+ declare function applyFieldBlur(fields: FormField[], state: FormRuntimeState, name: string): FormRuntimeState;
12
+ declare function runSubmitValidation(fields: FormField[], state: FormRuntimeState): {
13
+ state: FormRuntimeState;
14
+ hasError: boolean;
15
+ };
16
+
17
+ export { type FormRuntimeState, applyFieldBlur, applyFieldChange, createFormRuntimeState, runSubmitValidation, setSubmitting };
@@ -0,0 +1,17 @@
1
+ import { FormField } from './types.js';
2
+
3
+ interface FormRuntimeState {
4
+ values: Record<string, any>;
5
+ errors: Record<string, string>;
6
+ isSubmitting: boolean;
7
+ }
8
+ declare function createFormRuntimeState(fields: FormField[]): FormRuntimeState;
9
+ declare function setSubmitting(state: FormRuntimeState, isSubmitting: boolean): FormRuntimeState;
10
+ declare function applyFieldChange(fields: FormField[], state: FormRuntimeState, name: string, rawValue: unknown): FormRuntimeState;
11
+ declare function applyFieldBlur(fields: FormField[], state: FormRuntimeState, name: string): FormRuntimeState;
12
+ declare function runSubmitValidation(fields: FormField[], state: FormRuntimeState): {
13
+ state: FormRuntimeState;
14
+ hasError: boolean;
15
+ };
16
+
17
+ export { type FormRuntimeState, applyFieldBlur, applyFieldChange, createFormRuntimeState, runSubmitValidation, setSubmitting };
@@ -0,0 +1,15 @@
1
+ import {
2
+ applyFieldBlur,
3
+ applyFieldChange,
4
+ createFormRuntimeState,
5
+ runSubmitValidation,
6
+ setSubmitting
7
+ } from "./chunk-TP3IHKWV.js";
8
+ import "./chunk-WEDHXOHH.js";
9
+ export {
10
+ applyFieldBlur,
11
+ applyFieldChange,
12
+ createFormRuntimeState,
13
+ runSubmitValidation,
14
+ setSubmitting
15
+ };
@@ -20,8 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ applyFieldBlur: () => applyFieldBlur,
24
+ applyFieldChange: () => applyFieldChange,
25
+ createFormRuntimeState: () => createFormRuntimeState,
23
26
  getDefaultValues: () => getDefaultValues,
24
- validateField: () => validateField
27
+ normalizeFieldValue: () => normalizeFieldValue,
28
+ runSubmitValidation: () => runSubmitValidation,
29
+ setSubmitting: () => setSubmitting,
30
+ validateField: () => validateField,
31
+ validateFieldByName: () => validateFieldByName,
32
+ validateForm: () => validateForm
25
33
  });
26
34
  module.exports = __toCommonJS(index_exports);
27
35
 
@@ -32,6 +40,12 @@ function parseNumberish(value) {
32
40
  const parsed = Number(value);
33
41
  return Number.isNaN(parsed) ? null : parsed;
34
42
  }
43
+ function normalizeFieldValue(field, value) {
44
+ if (field.type !== "number") return value;
45
+ if (value === "" || value === void 0 || value === null) return "";
46
+ const numericValue = parseNumberish(value);
47
+ return numericValue === null ? value : numericValue;
48
+ }
35
49
  function validateField(value, field) {
36
50
  if (!field.validations) return null;
37
51
  for (const rule of field.validations) {
@@ -94,14 +108,90 @@ function validateField(value, field) {
94
108
  }
95
109
  return null;
96
110
  }
111
+ function validateFieldByName(fields, name, value) {
112
+ const field = fields.find((f) => f.name === name);
113
+ if (!field) return null;
114
+ return validateField(value, field);
115
+ }
116
+ function validateForm(fields, values) {
117
+ const errors = {};
118
+ for (const field of fields) {
119
+ const error = validateField(values[field.name], field);
120
+ if (error) errors[field.name] = error;
121
+ }
122
+ return errors;
123
+ }
97
124
  function getDefaultValues(fields) {
98
125
  return fields.reduce((acc, field) => {
99
126
  acc[field.name] = field.defaultValue !== void 0 ? field.defaultValue : field.type === "checkbox" ? [] : "";
100
127
  return acc;
101
128
  }, {});
102
129
  }
130
+
131
+ // src/formState.ts
132
+ function createFormRuntimeState(fields) {
133
+ return {
134
+ values: getDefaultValues(fields),
135
+ errors: {},
136
+ isSubmitting: false
137
+ };
138
+ }
139
+ function setSubmitting(state, isSubmitting) {
140
+ return {
141
+ ...state,
142
+ isSubmitting
143
+ };
144
+ }
145
+ function applyFieldChange(fields, state, name, rawValue) {
146
+ const field = fields.find((f) => f.name === name);
147
+ const normalizedValue = field ? normalizeFieldValue(field, rawValue) : rawValue;
148
+ const values = {
149
+ ...state.values,
150
+ [name]: normalizedValue
151
+ };
152
+ const error = validateFieldByName(fields, name, normalizedValue);
153
+ const errors = {
154
+ ...state.errors,
155
+ [name]: error || ""
156
+ };
157
+ return {
158
+ ...state,
159
+ values,
160
+ errors
161
+ };
162
+ }
163
+ function applyFieldBlur(fields, state, name) {
164
+ const error = validateFieldByName(fields, name, state.values[name]);
165
+ return {
166
+ ...state,
167
+ errors: {
168
+ ...state.errors,
169
+ [name]: error || ""
170
+ }
171
+ };
172
+ }
173
+ function runSubmitValidation(fields, state) {
174
+ const errors = validateForm(fields, state.values);
175
+ const hasError = Object.keys(errors).length > 0;
176
+ return {
177
+ state: {
178
+ ...state,
179
+ errors,
180
+ isSubmitting: false
181
+ },
182
+ hasError
183
+ };
184
+ }
103
185
  // Annotate the CommonJS export names for ESM import in node:
104
186
  0 && (module.exports = {
187
+ applyFieldBlur,
188
+ applyFieldChange,
189
+ createFormRuntimeState,
105
190
  getDefaultValues,
106
- validateField
191
+ normalizeFieldValue,
192
+ runSubmitValidation,
193
+ setSubmitting,
194
+ validateField,
195
+ validateFieldByName,
196
+ validateForm
107
197
  });
@@ -1,2 +1,3 @@
1
1
  export { FieldType, FormField, FormSchema, FormState, Option, ValidationRule } from './types.cjs';
2
- export { getDefaultValues, validateField } from './utils.cjs';
2
+ export { getDefaultValues, normalizeFieldValue, validateField, validateFieldByName, validateForm } from './utils.cjs';
3
+ export { FormRuntimeState, applyFieldBlur, applyFieldChange, createFormRuntimeState, runSubmitValidation, setSubmitting } from './formState.cjs';
@@ -1,2 +1,3 @@
1
1
  export { FieldType, FormField, FormSchema, FormState, Option, ValidationRule } from './types.js';
2
- export { getDefaultValues, validateField } from './utils.js';
2
+ export { getDefaultValues, normalizeFieldValue, validateField, validateFieldByName, validateForm } from './utils.js';
3
+ export { FormRuntimeState, applyFieldBlur, applyFieldChange, createFormRuntimeState, runSubmitValidation, setSubmitting } from './formState.js';
@@ -1,8 +1,26 @@
1
+ import {
2
+ applyFieldBlur,
3
+ applyFieldChange,
4
+ createFormRuntimeState,
5
+ runSubmitValidation,
6
+ setSubmitting
7
+ } from "./chunk-TP3IHKWV.js";
1
8
  import {
2
9
  getDefaultValues,
3
- validateField
4
- } from "./chunk-GQASS6PM.js";
10
+ normalizeFieldValue,
11
+ validateField,
12
+ validateFieldByName,
13
+ validateForm
14
+ } from "./chunk-WEDHXOHH.js";
5
15
  export {
16
+ applyFieldBlur,
17
+ applyFieldChange,
18
+ createFormRuntimeState,
6
19
  getDefaultValues,
7
- validateField
20
+ normalizeFieldValue,
21
+ runSubmitValidation,
22
+ setSubmitting,
23
+ validateField,
24
+ validateFieldByName,
25
+ validateForm
8
26
  };
@@ -21,7 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
23
  getDefaultValues: () => getDefaultValues,
24
- validateField: () => validateField
24
+ normalizeFieldValue: () => normalizeFieldValue,
25
+ validateField: () => validateField,
26
+ validateFieldByName: () => validateFieldByName,
27
+ validateForm: () => validateForm
25
28
  });
26
29
  module.exports = __toCommonJS(utils_exports);
27
30
  function parseNumberish(value) {
@@ -30,6 +33,12 @@ function parseNumberish(value) {
30
33
  const parsed = Number(value);
31
34
  return Number.isNaN(parsed) ? null : parsed;
32
35
  }
36
+ function normalizeFieldValue(field, value) {
37
+ if (field.type !== "number") return value;
38
+ if (value === "" || value === void 0 || value === null) return "";
39
+ const numericValue = parseNumberish(value);
40
+ return numericValue === null ? value : numericValue;
41
+ }
33
42
  function validateField(value, field) {
34
43
  if (!field.validations) return null;
35
44
  for (const rule of field.validations) {
@@ -92,6 +101,19 @@ function validateField(value, field) {
92
101
  }
93
102
  return null;
94
103
  }
104
+ function validateFieldByName(fields, name, value) {
105
+ const field = fields.find((f) => f.name === name);
106
+ if (!field) return null;
107
+ return validateField(value, field);
108
+ }
109
+ function validateForm(fields, values) {
110
+ const errors = {};
111
+ for (const field of fields) {
112
+ const error = validateField(values[field.name], field);
113
+ if (error) errors[field.name] = error;
114
+ }
115
+ return errors;
116
+ }
95
117
  function getDefaultValues(fields) {
96
118
  return fields.reduce((acc, field) => {
97
119
  acc[field.name] = field.defaultValue !== void 0 ? field.defaultValue : field.type === "checkbox" ? [] : "";
@@ -101,5 +123,8 @@ function getDefaultValues(fields) {
101
123
  // Annotate the CommonJS export names for ESM import in node:
102
124
  0 && (module.exports = {
103
125
  getDefaultValues,
104
- validateField
126
+ normalizeFieldValue,
127
+ validateField,
128
+ validateFieldByName,
129
+ validateForm
105
130
  });
@@ -1,6 +1,9 @@
1
1
  import { FormField } from './types.cjs';
2
2
 
3
+ declare function normalizeFieldValue(field: FormField, value: unknown): unknown;
3
4
  declare function validateField(value: any, field: FormField): string | null;
5
+ declare function validateFieldByName(fields: FormField[], name: string, value: unknown): string | null;
6
+ declare function validateForm(fields: FormField[], values: Record<string, any>): Record<string, string>;
4
7
  declare function getDefaultValues(fields: FormField[]): Record<string, any>;
5
8
 
6
- export { getDefaultValues, validateField };
9
+ export { getDefaultValues, normalizeFieldValue, validateField, validateFieldByName, validateForm };
@@ -1,6 +1,9 @@
1
1
  import { FormField } from './types.js';
2
2
 
3
+ declare function normalizeFieldValue(field: FormField, value: unknown): unknown;
3
4
  declare function validateField(value: any, field: FormField): string | null;
5
+ declare function validateFieldByName(fields: FormField[], name: string, value: unknown): string | null;
6
+ declare function validateForm(fields: FormField[], values: Record<string, any>): Record<string, string>;
4
7
  declare function getDefaultValues(fields: FormField[]): Record<string, any>;
5
8
 
6
- export { getDefaultValues, validateField };
9
+ export { getDefaultValues, normalizeFieldValue, validateField, validateFieldByName, validateForm };
@@ -1,8 +1,14 @@
1
1
  import {
2
2
  getDefaultValues,
3
- validateField
4
- } from "./chunk-GQASS6PM.js";
3
+ normalizeFieldValue,
4
+ validateField,
5
+ validateFieldByName,
6
+ validateForm
7
+ } from "./chunk-WEDHXOHH.js";
5
8
  export {
6
9
  getDefaultValues,
7
- validateField
10
+ normalizeFieldValue,
11
+ validateField,
12
+ validateFieldByName,
13
+ validateForm
8
14
  };
@@ -1 +1 @@
1
- {"version":"1.6.1","results":[[":test/utils.test.ts",{"duration":3,"failed":false}]]}
1
+ {"version":"1.6.1","results":[[":test/formState.test.ts",{"duration":2,"failed":false}],[":test/utils.test.ts",{"duration":4,"failed":false}]]}