@firecms/formex 3.0.0-canary.23 → 3.0.0-canary.231
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 +2 -2
- package/dist/Field.d.ts +0 -1
- package/dist/index.es.js +456 -148
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +496 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/useCreateFormex.d.ts +4 -1
- package/dist/utils.d.ts +2 -1
- package/package.json +29 -24
- package/src/Field.tsx +0 -4
- package/src/types.ts +13 -0
- package/src/useCreateFormex.tsx +219 -105
- package/src/utils.ts +1 -1
package/README.md
CHANGED
@@ -14,11 +14,11 @@ Formex is a lightweight, flexible library designed to simplify form handling wit
|
|
14
14
|
To install Formex, you can use either npm or yarn:
|
15
15
|
|
16
16
|
```sh
|
17
|
-
npm install
|
17
|
+
npm install @firecms/formex
|
18
18
|
|
19
19
|
# or if you're using yarn
|
20
20
|
|
21
|
-
yarn add
|
21
|
+
yarn add @firecms/formex
|
22
22
|
```
|
23
23
|
|
24
24
|
## Quick Start
|
package/dist/Field.d.ts
CHANGED
@@ -18,7 +18,6 @@ export interface FormexFieldProps<Value = any, FormValues extends object = any>
|
|
18
18
|
field: FieldInputProps<Value>;
|
19
19
|
form: FormexController<FormValues>;
|
20
20
|
}
|
21
|
-
export type FieldValidator = (value: any) => string | void | Promise<string | void>;
|
22
21
|
export interface FieldConfig<Value, C extends React.ElementType | undefined = undefined> {
|
23
22
|
/**
|
24
23
|
* Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
|
package/dist/index.es.js
CHANGED
@@ -1,172 +1,480 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import { c } from "react-compiler-runtime";
|
2
|
+
import * as React from "react";
|
3
|
+
import React__default, { useContext, useRef, useState, useEffect, useCallback, useMemo } from "react";
|
4
|
+
import equal from "react-fast-compare";
|
5
|
+
const FormexContext = React__default.createContext({});
|
6
|
+
const useFormex = () => {
|
7
|
+
return useContext(FormexContext);
|
8
|
+
};
|
9
|
+
const Formex = FormexContext.Provider;
|
10
|
+
const isEmptyArray = (value) => Array.isArray(value) && value.length === 0;
|
11
|
+
const isFunction = (obj) => typeof obj === "function";
|
12
|
+
const isObject = (obj) => obj !== null && typeof obj === "object";
|
13
|
+
const isInteger = (obj) => String(Math.floor(Number(obj))) === obj;
|
14
|
+
const isString = (obj) => Object.prototype.toString.call(obj) === "[object String]";
|
15
|
+
const isNaN = (obj) => obj !== obj;
|
16
|
+
const isEmptyChildren = (children) => React.Children.count(children) === 0;
|
17
|
+
const isPromise = (value) => isObject(value) && isFunction(value.then);
|
18
|
+
const isInputEvent = (value) => value && isObject(value) && isObject(value.target);
|
19
|
+
function getActiveElement(doc) {
|
20
|
+
doc = doc || (typeof document !== "undefined" ? document : void 0);
|
21
|
+
if (typeof doc === "undefined") {
|
7
22
|
return null;
|
23
|
+
}
|
8
24
|
try {
|
9
|
-
return
|
10
|
-
} catch {
|
11
|
-
return
|
25
|
+
return doc.activeElement || doc.body;
|
26
|
+
} catch (e) {
|
27
|
+
return doc.body;
|
12
28
|
}
|
13
29
|
}
|
14
|
-
function
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
|
30
|
+
function getIn(obj, key, def, p = 0) {
|
31
|
+
const path = toPath(key);
|
32
|
+
while (obj && p < path.length) {
|
33
|
+
obj = obj[path[p++]];
|
34
|
+
}
|
35
|
+
if (p !== path.length && !obj) {
|
36
|
+
return def;
|
37
|
+
}
|
38
|
+
return obj === void 0 ? def : obj;
|
19
39
|
}
|
20
|
-
function
|
21
|
-
const
|
22
|
-
let
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
function setIn(obj, path, value) {
|
41
|
+
const res = clone(obj);
|
42
|
+
let resVal = res;
|
43
|
+
let i = 0;
|
44
|
+
const pathArray = toPath(path);
|
45
|
+
for (; i < pathArray.length - 1; i++) {
|
46
|
+
const currentPath = pathArray[i];
|
47
|
+
const currentObj = getIn(obj, pathArray.slice(0, i + 1));
|
48
|
+
if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {
|
49
|
+
resVal = resVal[currentPath] = clone(currentObj);
|
50
|
+
} else {
|
51
|
+
const nextPath = pathArray[i + 1];
|
52
|
+
resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
|
31
53
|
}
|
32
54
|
}
|
33
|
-
|
55
|
+
if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {
|
56
|
+
return obj;
|
57
|
+
}
|
58
|
+
if (value === void 0) {
|
59
|
+
delete resVal[pathArray[i]];
|
60
|
+
} else {
|
61
|
+
resVal[pathArray[i]] = value;
|
62
|
+
}
|
63
|
+
if (i === 0 && value === void 0) {
|
64
|
+
delete res[pathArray[i]];
|
65
|
+
}
|
66
|
+
return res;
|
34
67
|
}
|
35
|
-
function
|
36
|
-
for (const
|
37
|
-
const
|
38
|
-
|
68
|
+
function setNestedObjectValues(object, value, visited = /* @__PURE__ */ new WeakMap(), response = {}) {
|
69
|
+
for (const k of Object.keys(object)) {
|
70
|
+
const val = object[k];
|
71
|
+
if (isObject(val)) {
|
72
|
+
if (!visited.get(val)) {
|
73
|
+
visited.set(val, true);
|
74
|
+
response[k] = Array.isArray(val) ? [] : {};
|
75
|
+
setNestedObjectValues(val, value, visited, response[k]);
|
76
|
+
}
|
77
|
+
} else {
|
78
|
+
response[k] = value;
|
79
|
+
}
|
39
80
|
}
|
40
|
-
return
|
81
|
+
return response;
|
41
82
|
}
|
42
|
-
function
|
43
|
-
|
83
|
+
function clone(value) {
|
84
|
+
if (Array.isArray(value)) {
|
85
|
+
return [...value];
|
86
|
+
} else if (typeof value === "object" && value !== null) {
|
87
|
+
return {
|
88
|
+
...value
|
89
|
+
};
|
90
|
+
} else {
|
91
|
+
return value;
|
92
|
+
}
|
44
93
|
}
|
45
|
-
function
|
46
|
-
|
94
|
+
function toPath(value) {
|
95
|
+
if (Array.isArray(value)) return value;
|
96
|
+
return value.replace(/\[(\d+)]/g, ".$1").replace(/^\./, "").replace(/\.$/, "").split(".");
|
47
97
|
}
|
48
|
-
function
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
98
|
+
function Field(t0) {
|
99
|
+
const $ = c(37);
|
100
|
+
let children;
|
101
|
+
let className;
|
102
|
+
let is;
|
103
|
+
let name;
|
104
|
+
let props;
|
105
|
+
if ($[0] !== t0) {
|
106
|
+
const {
|
107
|
+
validate,
|
108
|
+
name: t12,
|
109
|
+
children: t22,
|
110
|
+
as: t3,
|
111
|
+
className: t4,
|
112
|
+
...t5
|
113
|
+
} = t0;
|
114
|
+
name = t12;
|
115
|
+
children = t22;
|
116
|
+
is = t3;
|
117
|
+
className = t4;
|
118
|
+
props = t5;
|
119
|
+
$[0] = t0;
|
120
|
+
$[1] = children;
|
121
|
+
$[2] = className;
|
122
|
+
$[3] = is;
|
123
|
+
$[4] = name;
|
124
|
+
$[5] = props;
|
125
|
+
} else {
|
126
|
+
children = $[1];
|
127
|
+
className = $[2];
|
128
|
+
is = $[3];
|
129
|
+
name = $[4];
|
130
|
+
props = $[5];
|
131
|
+
}
|
132
|
+
const formex = useFormex();
|
133
|
+
let field;
|
134
|
+
let t1;
|
135
|
+
if ($[6] !== children || $[7] !== formex || $[8] !== name || $[9] !== props) {
|
136
|
+
t1 = Symbol.for("react.early_return_sentinel");
|
137
|
+
bb0: {
|
138
|
+
field = getFieldProps({
|
139
|
+
name,
|
140
|
+
...props
|
141
|
+
}, formex);
|
142
|
+
if (isFunction(children)) {
|
143
|
+
t1 = children({
|
144
|
+
field,
|
145
|
+
form: formex
|
146
|
+
});
|
147
|
+
break bb0;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
$[6] = children;
|
151
|
+
$[7] = formex;
|
152
|
+
$[8] = name;
|
153
|
+
$[9] = props;
|
154
|
+
$[10] = field;
|
155
|
+
$[11] = t1;
|
156
|
+
} else {
|
157
|
+
field = $[10];
|
158
|
+
t1 = $[11];
|
159
|
+
}
|
160
|
+
if (t1 !== Symbol.for("react.early_return_sentinel")) {
|
161
|
+
return t1;
|
162
|
+
}
|
163
|
+
const asElement = is || "input";
|
164
|
+
if (typeof asElement === "string") {
|
165
|
+
let innerRef;
|
166
|
+
let rest;
|
167
|
+
if ($[12] !== props) {
|
168
|
+
({
|
169
|
+
innerRef,
|
170
|
+
...rest
|
171
|
+
} = props);
|
172
|
+
$[12] = props;
|
173
|
+
$[13] = innerRef;
|
174
|
+
$[14] = rest;
|
175
|
+
} else {
|
176
|
+
innerRef = $[13];
|
177
|
+
rest = $[14];
|
178
|
+
}
|
179
|
+
let t22;
|
180
|
+
if ($[15] !== asElement || $[16] !== children || $[17] !== className || $[18] !== field || $[19] !== innerRef || $[20] !== rest) {
|
181
|
+
let t3;
|
182
|
+
if ($[22] !== className || $[23] !== field || $[24] !== innerRef || $[25] !== rest) {
|
183
|
+
t3 = {
|
184
|
+
ref: innerRef,
|
185
|
+
...field,
|
186
|
+
...rest,
|
187
|
+
className
|
188
|
+
};
|
189
|
+
$[22] = className;
|
190
|
+
$[23] = field;
|
191
|
+
$[24] = innerRef;
|
192
|
+
$[25] = rest;
|
193
|
+
$[26] = t3;
|
194
|
+
} else {
|
195
|
+
t3 = $[26];
|
196
|
+
}
|
197
|
+
t22 = React.createElement(asElement, t3, children);
|
198
|
+
$[15] = asElement;
|
199
|
+
$[16] = children;
|
200
|
+
$[17] = className;
|
201
|
+
$[18] = field;
|
202
|
+
$[19] = innerRef;
|
203
|
+
$[20] = rest;
|
204
|
+
$[21] = t22;
|
205
|
+
} else {
|
206
|
+
t22 = $[21];
|
207
|
+
}
|
208
|
+
return t22;
|
209
|
+
}
|
210
|
+
let t2;
|
211
|
+
if ($[27] !== asElement || $[28] !== children || $[29] !== className || $[30] !== field || $[31] !== props) {
|
212
|
+
let t3;
|
213
|
+
if ($[33] !== className || $[34] !== field || $[35] !== props) {
|
214
|
+
t3 = {
|
215
|
+
...field,
|
216
|
+
...props,
|
217
|
+
className
|
218
|
+
};
|
219
|
+
$[33] = className;
|
220
|
+
$[34] = field;
|
221
|
+
$[35] = props;
|
222
|
+
$[36] = t3;
|
223
|
+
} else {
|
224
|
+
t3 = $[36];
|
225
|
+
}
|
226
|
+
t2 = React.createElement(asElement, t3, children);
|
227
|
+
$[27] = asElement;
|
228
|
+
$[28] = children;
|
229
|
+
$[29] = className;
|
230
|
+
$[30] = field;
|
231
|
+
$[31] = props;
|
232
|
+
$[32] = t2;
|
233
|
+
} else {
|
234
|
+
t2 = $[32];
|
235
|
+
}
|
236
|
+
return t2;
|
71
237
|
}
|
72
|
-
const
|
73
|
-
const
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
238
|
+
const getFieldProps = (nameOrOptions, formex) => {
|
239
|
+
const isAnObject = isObject(nameOrOptions);
|
240
|
+
const name = isAnObject ? nameOrOptions.name : nameOrOptions;
|
241
|
+
const valueState = getIn(formex.values, name);
|
242
|
+
const field = {
|
243
|
+
name,
|
244
|
+
value: valueState,
|
245
|
+
onChange: formex.handleChange,
|
246
|
+
onBlur: formex.handleBlur
|
78
247
|
};
|
79
|
-
if (
|
248
|
+
if (isAnObject) {
|
80
249
|
const {
|
81
|
-
type
|
82
|
-
value:
|
250
|
+
type,
|
251
|
+
value: valueProp,
|
83
252
|
// value is special for checkboxes
|
84
|
-
as:
|
85
|
-
multiple
|
86
|
-
} =
|
87
|
-
|
253
|
+
as: is,
|
254
|
+
multiple
|
255
|
+
} = nameOrOptions;
|
256
|
+
if (type === "checkbox") {
|
257
|
+
if (valueProp === void 0) {
|
258
|
+
field.checked = !!valueState;
|
259
|
+
} else {
|
260
|
+
field.checked = !!(Array.isArray(valueState) && ~valueState.indexOf(valueProp));
|
261
|
+
field.value = valueProp;
|
262
|
+
}
|
263
|
+
} else if (type === "radio") {
|
264
|
+
field.checked = valueState === valueProp;
|
265
|
+
field.value = valueProp;
|
266
|
+
} else if (is === "select" && multiple) {
|
267
|
+
field.value = field.value || [];
|
268
|
+
field.multiple = true;
|
269
|
+
}
|
88
270
|
}
|
89
|
-
return
|
271
|
+
return field;
|
90
272
|
};
|
91
|
-
function
|
92
|
-
|
93
|
-
|
94
|
-
|
273
|
+
function useCreateFormex({
|
274
|
+
initialValues,
|
275
|
+
initialErrors,
|
276
|
+
initialDirty,
|
277
|
+
validation,
|
278
|
+
validateOnChange = false,
|
279
|
+
validateOnInitialRender = false,
|
280
|
+
onSubmit,
|
281
|
+
onReset,
|
282
|
+
debugId
|
283
|
+
}) {
|
284
|
+
const initialValuesRef = useRef(initialValues);
|
285
|
+
const valuesRef = useRef(initialValues);
|
286
|
+
const debugIdRef = useRef(debugId);
|
287
|
+
const [values, setValuesInner] = useState(initialValues);
|
288
|
+
const [touchedState, setTouchedState] = useState({});
|
289
|
+
const [errors, setErrors] = useState(initialErrors ?? {});
|
290
|
+
const [dirty, setDirty] = useState(initialDirty ?? false);
|
291
|
+
const [submitCount, setSubmitCount] = useState(0);
|
292
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
293
|
+
const [isValidating, setIsValidating] = useState(false);
|
294
|
+
const [version, setVersion] = useState(0);
|
295
|
+
const historyRef = useRef([initialValues]);
|
296
|
+
const historyIndexRef = useRef(0);
|
297
|
+
useEffect(() => {
|
298
|
+
if (validateOnInitialRender) {
|
299
|
+
validate();
|
300
|
+
}
|
301
|
+
}, []);
|
302
|
+
const setValues = useCallback((newValues) => {
|
303
|
+
valuesRef.current = newValues;
|
304
|
+
setValuesInner(newValues);
|
305
|
+
setDirty(!equal(initialValuesRef.current, newValues));
|
306
|
+
const newHistory = historyRef.current.slice(0, historyIndexRef.current + 1);
|
307
|
+
newHistory.push(newValues);
|
308
|
+
historyRef.current = newHistory;
|
309
|
+
historyIndexRef.current = newHistory.length - 1;
|
95
310
|
}, []);
|
96
|
-
const
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
return
|
102
|
-
},
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
},
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
311
|
+
const validate = useCallback(async () => {
|
312
|
+
setIsValidating(true);
|
313
|
+
const validationErrors = await validation?.(valuesRef.current);
|
314
|
+
setErrors(validationErrors ?? {});
|
315
|
+
setIsValidating(false);
|
316
|
+
return validationErrors;
|
317
|
+
}, [validation]);
|
318
|
+
const setFieldValue = useCallback((key, value, shouldValidate) => {
|
319
|
+
const newValues_0 = setIn(valuesRef.current, key, value);
|
320
|
+
valuesRef.current = newValues_0;
|
321
|
+
setValuesInner(newValues_0);
|
322
|
+
if (!equal(getIn(initialValuesRef.current, key), value)) {
|
323
|
+
setDirty(true);
|
324
|
+
}
|
325
|
+
if (shouldValidate) {
|
326
|
+
validate();
|
327
|
+
}
|
328
|
+
const newHistory_0 = historyRef.current.slice(0, historyIndexRef.current + 1);
|
329
|
+
newHistory_0.push(newValues_0);
|
330
|
+
historyRef.current = newHistory_0;
|
331
|
+
historyIndexRef.current = newHistory_0.length - 1;
|
332
|
+
}, [validate]);
|
333
|
+
const setFieldError = useCallback((key_0, error) => {
|
334
|
+
setErrors((prevErrors) => {
|
335
|
+
const newErrors = {
|
336
|
+
...prevErrors
|
337
|
+
};
|
338
|
+
if (error) {
|
339
|
+
newErrors[key_0] = error;
|
340
|
+
} else {
|
341
|
+
delete newErrors[key_0];
|
342
|
+
}
|
343
|
+
return newErrors;
|
344
|
+
});
|
345
|
+
}, []);
|
346
|
+
const setFieldTouched = useCallback((key_1, touched, shouldValidate_0) => {
|
347
|
+
setTouchedState((prev) => ({
|
348
|
+
...prev,
|
349
|
+
[key_1]: touched
|
350
|
+
}));
|
351
|
+
if (shouldValidate_0) {
|
352
|
+
validate();
|
353
|
+
}
|
354
|
+
}, [validate]);
|
355
|
+
const handleChange = useCallback((event) => {
|
356
|
+
const target = event.target;
|
357
|
+
let value_0;
|
358
|
+
if (target.type === "checkbox") {
|
359
|
+
value_0 = target.checked;
|
360
|
+
} else if (target.type === "number") {
|
361
|
+
value_0 = target.valueAsNumber;
|
362
|
+
} else {
|
363
|
+
value_0 = target.value;
|
364
|
+
}
|
365
|
+
const name = target.name;
|
366
|
+
setFieldValue(name, value_0, validateOnChange);
|
367
|
+
setFieldTouched(name, true);
|
368
|
+
}, [setFieldValue, setFieldTouched, validateOnChange]);
|
369
|
+
const handleBlur = useCallback((event_0) => {
|
370
|
+
const target_0 = event_0.target;
|
371
|
+
const name_0 = target_0.name;
|
372
|
+
setFieldTouched(name_0, true);
|
373
|
+
}, [setFieldTouched]);
|
374
|
+
const submit = useCallback(async (e) => {
|
375
|
+
e?.preventDefault();
|
376
|
+
e?.stopPropagation();
|
377
|
+
setIsSubmitting(true);
|
378
|
+
setSubmitCount((prev_0) => prev_0 + 1);
|
379
|
+
const validationErrors_0 = await validation?.(valuesRef.current);
|
380
|
+
if (validationErrors_0 && Object.keys(validationErrors_0).length > 0) {
|
381
|
+
setErrors(validationErrors_0);
|
382
|
+
} else {
|
383
|
+
setErrors({});
|
384
|
+
await onSubmit?.(valuesRef.current, controllerRef.current);
|
385
|
+
}
|
386
|
+
setIsSubmitting(false);
|
387
|
+
setVersion((prev_1) => prev_1 + 1);
|
388
|
+
}, [onSubmit, validation]);
|
389
|
+
const resetForm = useCallback((props) => {
|
122
390
|
const {
|
123
|
-
submitCount:
|
124
|
-
values:
|
125
|
-
errors:
|
126
|
-
touched:
|
127
|
-
} =
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
391
|
+
submitCount: submitCountProp,
|
392
|
+
values: valuesProp,
|
393
|
+
errors: errorsProp,
|
394
|
+
touched: touchedProp
|
395
|
+
} = props ?? {};
|
396
|
+
valuesRef.current = valuesProp ?? initialValuesRef.current;
|
397
|
+
initialValuesRef.current = valuesProp ?? initialValuesRef.current;
|
398
|
+
setValuesInner(valuesProp ?? initialValuesRef.current);
|
399
|
+
setErrors(errorsProp ?? {});
|
400
|
+
setTouchedState(touchedProp ?? {});
|
401
|
+
setDirty(false);
|
402
|
+
setSubmitCount(submitCountProp ?? 0);
|
403
|
+
setVersion((prev_2) => prev_2 + 1);
|
404
|
+
onReset?.(controllerRef.current);
|
405
|
+
historyRef.current = [valuesProp ?? initialValuesRef.current];
|
406
|
+
historyIndexRef.current = 0;
|
407
|
+
}, [onReset]);
|
408
|
+
const undo = useCallback(() => {
|
409
|
+
if (historyIndexRef.current > 0) {
|
410
|
+
const newIndex = historyIndexRef.current - 1;
|
411
|
+
const newValues_1 = historyRef.current[newIndex];
|
412
|
+
setValuesInner(newValues_1);
|
413
|
+
valuesRef.current = newValues_1;
|
414
|
+
historyIndexRef.current = newIndex;
|
415
|
+
}
|
416
|
+
}, []);
|
417
|
+
const redo = useCallback(() => {
|
418
|
+
if (historyIndexRef.current < historyRef.current.length - 1) {
|
419
|
+
const newIndex_0 = historyIndexRef.current + 1;
|
420
|
+
const newValues_2 = historyRef.current[newIndex_0];
|
421
|
+
setValuesInner(newValues_2);
|
422
|
+
valuesRef.current = newValues_2;
|
423
|
+
historyIndexRef.current = newIndex_0;
|
424
|
+
}
|
425
|
+
}, []);
|
426
|
+
const controllerRef = useRef({});
|
427
|
+
const controller = useMemo(() => ({
|
428
|
+
values,
|
429
|
+
initialValues: initialValuesRef.current,
|
430
|
+
handleChange,
|
431
|
+
isSubmitting,
|
432
|
+
setSubmitting: setIsSubmitting,
|
433
|
+
setValues,
|
434
|
+
setFieldValue,
|
435
|
+
errors,
|
436
|
+
setFieldError,
|
437
|
+
touched: touchedState,
|
438
|
+
setFieldTouched,
|
439
|
+
dirty,
|
440
|
+
setDirty,
|
441
|
+
handleSubmit: submit,
|
442
|
+
submitCount,
|
443
|
+
setSubmitCount,
|
444
|
+
handleBlur,
|
445
|
+
validate,
|
446
|
+
isValidating,
|
447
|
+
resetForm,
|
448
|
+
version,
|
449
|
+
debugId: debugIdRef.current,
|
450
|
+
undo,
|
451
|
+
redo,
|
452
|
+
canUndo: historyIndexRef.current > 0,
|
453
|
+
canRedo: historyIndexRef.current < historyRef.current.length - 1
|
454
|
+
}), [values, errors, touchedState, dirty, isSubmitting, submitCount, isValidating, version, handleChange, handleBlur, setValues, setFieldValue, setFieldTouched, setFieldError, validate, submit, resetForm, undo, redo]);
|
455
|
+
useEffect(() => {
|
456
|
+
controllerRef.current = controller;
|
457
|
+
}, [controller]);
|
458
|
+
return controller;
|
152
459
|
}
|
153
460
|
export {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
461
|
+
Field,
|
462
|
+
Formex,
|
463
|
+
clone,
|
464
|
+
getActiveElement,
|
465
|
+
getIn,
|
466
|
+
isEmptyArray,
|
467
|
+
isEmptyChildren,
|
468
|
+
isFunction,
|
469
|
+
isInputEvent,
|
470
|
+
isInteger,
|
471
|
+
isNaN,
|
472
|
+
isObject,
|
473
|
+
isPromise,
|
474
|
+
isString,
|
475
|
+
setIn,
|
476
|
+
setNestedObjectValues,
|
477
|
+
useCreateFormex,
|
478
|
+
useFormex
|
171
479
|
};
|
172
480
|
//# sourceMappingURL=index.es.js.map
|