@rebasepro/formex 0.0.1-canary.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.
@@ -0,0 +1,486 @@
1
+ import { c } from "react-compiler-runtime";
2
+ import * as React from "react";
3
+ import React__default, { useContext, useRef, useState, useCallback, useEffect, useMemo } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { deepEqual } from "fast-equals";
6
+ const FormexContext = React__default.createContext({});
7
+ const useFormex = () => {
8
+ return useContext(FormexContext);
9
+ };
10
+ const Formex = (t0) => {
11
+ const $ = c(3);
12
+ const {
13
+ value,
14
+ children
15
+ } = t0;
16
+ let t1;
17
+ if ($[0] !== children || $[1] !== value) {
18
+ t1 = /* @__PURE__ */ jsx(FormexContext.Provider, { value, children });
19
+ $[0] = children;
20
+ $[1] = value;
21
+ $[2] = t1;
22
+ } else {
23
+ t1 = $[2];
24
+ }
25
+ return t1;
26
+ };
27
+ const isEmptyArray = (value) => Array.isArray(value) && value.length === 0;
28
+ const isFunction = (obj) => typeof obj === "function";
29
+ const isObject = (obj) => obj !== null && typeof obj === "object";
30
+ const isInteger = (obj) => String(Math.floor(Number(obj))) === obj;
31
+ const isNaN = (obj) => obj !== obj;
32
+ function getIn(obj, key, def, p = 0) {
33
+ const path = toPath(key);
34
+ while (obj && p < path.length) {
35
+ obj = obj[path[p++]];
36
+ }
37
+ if (p !== path.length && !obj) {
38
+ return def;
39
+ }
40
+ return obj === void 0 ? def : obj;
41
+ }
42
+ function setIn(obj, path, value) {
43
+ const res = clone(obj);
44
+ let resVal = res;
45
+ let i = 0;
46
+ const pathArray = toPath(path);
47
+ for (; i < pathArray.length - 1; i++) {
48
+ const currentPath = pathArray[i];
49
+ const currentObj = getIn(obj, pathArray.slice(0, i + 1));
50
+ if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {
51
+ resVal = resVal[currentPath] = clone(currentObj);
52
+ } else {
53
+ const nextPath = pathArray[i + 1];
54
+ resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
55
+ }
56
+ }
57
+ if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {
58
+ return obj;
59
+ }
60
+ if (value === void 0) {
61
+ delete resVal[pathArray[i]];
62
+ } else {
63
+ resVal[pathArray[i]] = value;
64
+ }
65
+ if (i === 0 && value === void 0) {
66
+ delete res[pathArray[i]];
67
+ }
68
+ return res;
69
+ }
70
+ function clone(value) {
71
+ if (Array.isArray(value)) {
72
+ return [...value];
73
+ } else if (typeof value === "object" && value !== null) {
74
+ if (Object.getPrototypeOf(value) !== Object.prototype) {
75
+ return value;
76
+ }
77
+ return {
78
+ ...value
79
+ };
80
+ } else {
81
+ return value;
82
+ }
83
+ }
84
+ function toPath(value) {
85
+ if (Array.isArray(value)) return value;
86
+ return value.replace(/\[(\d+)]/g, ".$1").replace(/^\./, "").replace(/\.$/, "").split(".");
87
+ }
88
+ function Field(t0) {
89
+ const $ = c(37);
90
+ let children;
91
+ let className;
92
+ let is;
93
+ let name;
94
+ let props;
95
+ if ($[0] !== t0) {
96
+ const {
97
+ validate,
98
+ name: t12,
99
+ children: t22,
100
+ as: t3,
101
+ className: t4,
102
+ ...t5
103
+ } = t0;
104
+ name = t12;
105
+ children = t22;
106
+ is = t3;
107
+ className = t4;
108
+ props = t5;
109
+ $[0] = t0;
110
+ $[1] = children;
111
+ $[2] = className;
112
+ $[3] = is;
113
+ $[4] = name;
114
+ $[5] = props;
115
+ } else {
116
+ children = $[1];
117
+ className = $[2];
118
+ is = $[3];
119
+ name = $[4];
120
+ props = $[5];
121
+ }
122
+ const formex = useFormex();
123
+ let field;
124
+ let t1;
125
+ if ($[6] !== children || $[7] !== formex || $[8] !== name || $[9] !== props) {
126
+ t1 = /* @__PURE__ */ Symbol.for("react.early_return_sentinel");
127
+ bb0: {
128
+ field = getFieldProps({
129
+ name,
130
+ ...props
131
+ }, formex);
132
+ if (isFunction(children)) {
133
+ t1 = children({
134
+ field,
135
+ form: formex
136
+ });
137
+ break bb0;
138
+ }
139
+ }
140
+ $[6] = children;
141
+ $[7] = formex;
142
+ $[8] = name;
143
+ $[9] = props;
144
+ $[10] = field;
145
+ $[11] = t1;
146
+ } else {
147
+ field = $[10];
148
+ t1 = $[11];
149
+ }
150
+ if (t1 !== /* @__PURE__ */ Symbol.for("react.early_return_sentinel")) {
151
+ return t1;
152
+ }
153
+ const asElement = is || "input";
154
+ if (typeof asElement === "string") {
155
+ let innerRef;
156
+ let rest;
157
+ if ($[12] !== props) {
158
+ ({
159
+ innerRef,
160
+ ...rest
161
+ } = props);
162
+ $[12] = props;
163
+ $[13] = innerRef;
164
+ $[14] = rest;
165
+ } else {
166
+ innerRef = $[13];
167
+ rest = $[14];
168
+ }
169
+ let t22;
170
+ if ($[15] !== asElement || $[16] !== children || $[17] !== className || $[18] !== field || $[19] !== innerRef || $[20] !== rest) {
171
+ let t3;
172
+ if ($[22] !== className || $[23] !== field || $[24] !== innerRef || $[25] !== rest) {
173
+ t3 = {
174
+ ref: innerRef,
175
+ ...field,
176
+ ...rest,
177
+ className
178
+ };
179
+ $[22] = className;
180
+ $[23] = field;
181
+ $[24] = innerRef;
182
+ $[25] = rest;
183
+ $[26] = t3;
184
+ } else {
185
+ t3 = $[26];
186
+ }
187
+ t22 = React.createElement(asElement, t3, children);
188
+ $[15] = asElement;
189
+ $[16] = children;
190
+ $[17] = className;
191
+ $[18] = field;
192
+ $[19] = innerRef;
193
+ $[20] = rest;
194
+ $[21] = t22;
195
+ } else {
196
+ t22 = $[21];
197
+ }
198
+ return t22;
199
+ }
200
+ let t2;
201
+ if ($[27] !== asElement || $[28] !== children || $[29] !== className || $[30] !== field || $[31] !== props) {
202
+ let t3;
203
+ if ($[33] !== className || $[34] !== field || $[35] !== props) {
204
+ t3 = {
205
+ ...field,
206
+ ...props,
207
+ className
208
+ };
209
+ $[33] = className;
210
+ $[34] = field;
211
+ $[35] = props;
212
+ $[36] = t3;
213
+ } else {
214
+ t3 = $[36];
215
+ }
216
+ t2 = React.createElement(asElement, t3, children);
217
+ $[27] = asElement;
218
+ $[28] = children;
219
+ $[29] = className;
220
+ $[30] = field;
221
+ $[31] = props;
222
+ $[32] = t2;
223
+ } else {
224
+ t2 = $[32];
225
+ }
226
+ return t2;
227
+ }
228
+ const getFieldProps = (nameOrOptions, formex) => {
229
+ const isAnObject = isObject(nameOrOptions);
230
+ const name = isAnObject ? nameOrOptions.name : nameOrOptions;
231
+ const valueState = getIn(formex.values, name);
232
+ const field = {
233
+ name,
234
+ value: valueState,
235
+ onChange: formex.handleChange,
236
+ onBlur: formex.handleBlur
237
+ };
238
+ if (isAnObject) {
239
+ const {
240
+ type,
241
+ value: valueProp,
242
+ // value is special for checkboxes
243
+ as: is,
244
+ multiple
245
+ } = nameOrOptions;
246
+ if (type === "checkbox") {
247
+ if (valueProp === void 0) {
248
+ field.checked = !!valueState;
249
+ } else {
250
+ field.checked = !!(Array.isArray(valueState) && ~valueState.indexOf(valueProp));
251
+ field.value = valueProp;
252
+ }
253
+ } else if (type === "radio") {
254
+ field.checked = valueState === valueProp;
255
+ field.value = valueProp;
256
+ } else if (is === "select" && multiple) {
257
+ field.value = field.value || [];
258
+ field.multiple = true;
259
+ }
260
+ }
261
+ return field;
262
+ };
263
+ function useCreateFormex({
264
+ initialValues,
265
+ initialErrors,
266
+ initialDirty,
267
+ initialTouched,
268
+ validation,
269
+ validateOnChange = false,
270
+ validateOnInitialRender = false,
271
+ onSubmit,
272
+ onReset,
273
+ onValuesChangeDeferred,
274
+ debugId
275
+ }) {
276
+ const initialValuesRef = useRef(initialValues);
277
+ const valuesRef = useRef(initialValues);
278
+ const debugIdRef = useRef(debugId);
279
+ const [values, setValuesInner] = useState(initialValues);
280
+ const [touchedState, setTouchedState] = useState(initialTouched ?? {});
281
+ const [errors, setErrors] = useState(initialErrors ?? {});
282
+ const [dirty, setDirty] = useState(initialDirty ?? false);
283
+ const [submitCount, setSubmitCount] = useState(0);
284
+ const [isSubmitting, setIsSubmitting] = useState(false);
285
+ const [isValidating, setIsValidating] = useState(false);
286
+ const [version, setVersion] = useState(0);
287
+ const onValuesChangeRef = useRef(onValuesChangeDeferred);
288
+ onValuesChangeRef.current = onValuesChangeDeferred;
289
+ const debounceTimeoutRef = useRef(void 0);
290
+ const callDebouncedOnValuesChange = useCallback((values_0) => {
291
+ if (onValuesChangeRef.current) {
292
+ if (debounceTimeoutRef.current) {
293
+ clearTimeout(debounceTimeoutRef.current);
294
+ }
295
+ debounceTimeoutRef.current = setTimeout(() => {
296
+ onValuesChangeRef.current?.(values_0, controllerRef.current);
297
+ }, 300);
298
+ }
299
+ }, []);
300
+ const historyRef = useRef([initialValues]);
301
+ const historyIndexRef = useRef(0);
302
+ useEffect(() => {
303
+ if (validateOnInitialRender) {
304
+ validate();
305
+ }
306
+ }, []);
307
+ const setValues = useCallback((newValues) => {
308
+ valuesRef.current = newValues;
309
+ setValuesInner(newValues);
310
+ setDirty(!deepEqual(initialValuesRef.current, newValues));
311
+ const newHistory = historyRef.current.slice(0, historyIndexRef.current + 1);
312
+ newHistory.push(newValues);
313
+ historyRef.current = newHistory;
314
+ historyIndexRef.current = newHistory.length - 1;
315
+ callDebouncedOnValuesChange(newValues);
316
+ }, [callDebouncedOnValuesChange]);
317
+ const validate = useCallback(async () => {
318
+ setIsValidating(true);
319
+ const validationErrors = await validation?.(valuesRef.current);
320
+ setErrors(validationErrors ?? {});
321
+ setIsValidating(false);
322
+ return validationErrors;
323
+ }, [validation]);
324
+ const setFieldValue = useCallback((key, value, shouldValidate) => {
325
+ const newValues_0 = setIn(valuesRef.current, key, value);
326
+ valuesRef.current = newValues_0;
327
+ setValuesInner(newValues_0);
328
+ if (!deepEqual(getIn(initialValuesRef.current, key), value)) {
329
+ setDirty(true);
330
+ }
331
+ if (shouldValidate) {
332
+ validate();
333
+ }
334
+ const newHistory_0 = historyRef.current.slice(0, historyIndexRef.current + 1);
335
+ newHistory_0.push(newValues_0);
336
+ historyRef.current = newHistory_0;
337
+ historyIndexRef.current = newHistory_0.length - 1;
338
+ callDebouncedOnValuesChange(newValues_0);
339
+ }, [validate, callDebouncedOnValuesChange]);
340
+ const setFieldError = useCallback((key_0, error) => {
341
+ setErrors((prevErrors) => {
342
+ const newErrors = {
343
+ ...prevErrors
344
+ };
345
+ if (error) {
346
+ newErrors[key_0] = error;
347
+ } else {
348
+ delete newErrors[key_0];
349
+ }
350
+ return newErrors;
351
+ });
352
+ }, []);
353
+ const setFieldTouched = useCallback((key_1, touched, shouldValidate_0) => {
354
+ setTouchedState((prev) => ({
355
+ ...prev,
356
+ [key_1]: touched
357
+ }));
358
+ if (shouldValidate_0) {
359
+ validate();
360
+ }
361
+ }, [validate]);
362
+ const handleChange = useCallback((event) => {
363
+ const target = event.target;
364
+ let value_0;
365
+ if (target.type === "checkbox") {
366
+ value_0 = target.checked;
367
+ } else if (target.type === "number") {
368
+ value_0 = target.valueAsNumber;
369
+ } else {
370
+ value_0 = target.value;
371
+ }
372
+ const name = target.name;
373
+ setFieldValue(name, value_0, validateOnChange);
374
+ setFieldTouched(name, true);
375
+ }, [setFieldValue, setFieldTouched, validateOnChange]);
376
+ const handleBlur = useCallback((event_0) => {
377
+ const target_0 = event_0.target;
378
+ const name_0 = target_0.name;
379
+ setFieldTouched(name_0, true);
380
+ }, [setFieldTouched]);
381
+ const submit = useCallback(async (e) => {
382
+ e?.preventDefault();
383
+ e?.stopPropagation();
384
+ setIsSubmitting(true);
385
+ setSubmitCount((prev_0) => prev_0 + 1);
386
+ const validationErrors_0 = await validation?.(valuesRef.current);
387
+ if (validationErrors_0 && Object.keys(validationErrors_0).length > 0) {
388
+ setErrors(validationErrors_0);
389
+ } else {
390
+ setErrors({});
391
+ await onSubmit?.(valuesRef.current, controllerRef.current);
392
+ }
393
+ setIsSubmitting(false);
394
+ setVersion((prev_1) => prev_1 + 1);
395
+ }, [onSubmit, validation]);
396
+ const resetForm = useCallback((props) => {
397
+ const {
398
+ submitCount: submitCountProp,
399
+ values: valuesProp,
400
+ errors: errorsProp,
401
+ touched: touchedProp
402
+ } = props ?? {};
403
+ valuesRef.current = valuesProp ?? initialValuesRef.current;
404
+ initialValuesRef.current = valuesProp ?? initialValuesRef.current;
405
+ setValuesInner(valuesProp ?? initialValuesRef.current);
406
+ setErrors(errorsProp ?? {});
407
+ setTouchedState(touchedProp ?? initialTouched ?? {});
408
+ setDirty(false);
409
+ setSubmitCount(submitCountProp ?? 0);
410
+ setVersion((prev_2) => prev_2 + 1);
411
+ onReset?.(controllerRef.current);
412
+ historyRef.current = [valuesProp ?? initialValuesRef.current];
413
+ historyIndexRef.current = 0;
414
+ }, [onReset, initialTouched]);
415
+ const undo = useCallback(() => {
416
+ if (historyIndexRef.current > 0) {
417
+ const newIndex = historyIndexRef.current - 1;
418
+ const newValues_1 = historyRef.current[newIndex];
419
+ setValuesInner(newValues_1);
420
+ valuesRef.current = newValues_1;
421
+ historyIndexRef.current = newIndex;
422
+ setDirty(!deepEqual(initialValuesRef.current, newValues_1));
423
+ callDebouncedOnValuesChange(newValues_1);
424
+ }
425
+ }, [callDebouncedOnValuesChange]);
426
+ const redo = useCallback(() => {
427
+ if (historyIndexRef.current < historyRef.current.length - 1) {
428
+ const newIndex_0 = historyIndexRef.current + 1;
429
+ const newValues_2 = historyRef.current[newIndex_0];
430
+ setValuesInner(newValues_2);
431
+ valuesRef.current = newValues_2;
432
+ historyIndexRef.current = newIndex_0;
433
+ setDirty(!deepEqual(initialValuesRef.current, newValues_2));
434
+ callDebouncedOnValuesChange(newValues_2);
435
+ }
436
+ }, [callDebouncedOnValuesChange]);
437
+ const controllerRef = useRef({});
438
+ const controller = useMemo(() => ({
439
+ values,
440
+ initialValues: initialValuesRef.current,
441
+ handleChange,
442
+ isSubmitting,
443
+ setSubmitting: setIsSubmitting,
444
+ setValues,
445
+ setFieldValue,
446
+ errors,
447
+ setFieldError,
448
+ touched: touchedState,
449
+ setFieldTouched,
450
+ setTouched: setTouchedState,
451
+ dirty,
452
+ setDirty,
453
+ handleSubmit: submit,
454
+ submitCount,
455
+ setSubmitCount,
456
+ handleBlur,
457
+ validate,
458
+ isValidating,
459
+ resetForm,
460
+ version,
461
+ debugId: debugIdRef.current,
462
+ undo,
463
+ redo,
464
+ canUndo: historyIndexRef.current > 0,
465
+ canRedo: historyIndexRef.current < historyRef.current.length - 1
466
+ }), [values, errors, touchedState, dirty, isSubmitting, submitCount, isValidating, version, handleChange, handleBlur, setValues, setFieldValue, setFieldTouched, setTouchedState, setFieldError, validate, submit, resetForm, undo, redo]);
467
+ useEffect(() => {
468
+ controllerRef.current = controller;
469
+ }, [controller]);
470
+ return controller;
471
+ }
472
+ export {
473
+ Field,
474
+ Formex,
475
+ clone,
476
+ getIn,
477
+ isEmptyArray,
478
+ isFunction,
479
+ isInteger,
480
+ isNaN,
481
+ isObject,
482
+ setIn,
483
+ useCreateFormex,
484
+ useFormex
485
+ };
486
+ //# sourceMappingURL=index.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","sources":["../src/Formex.tsx","../src/utils.ts","../src/Field.tsx","../src/useCreateFormex.tsx"],"sourcesContent":["import React, { useContext } from \"react\";\nimport { FormexController } from \"./types\";\n\nconst FormexContext = React.createContext<FormexController<any>>({} as any);\n\nexport const useFormex = <T extends object>() => useContext<FormexController<T>>(FormexContext);\n\nexport const Formex = ({ value, children }: { value: FormexController<any>, children: React.ReactNode }) => {\n return <FormexContext.Provider value={value}>{children}</FormexContext.Provider>;\n};\n","/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: any) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: any): obj is Function =>\n typeof obj === \"function\";\n\n/** @private is the given object an Object? */\nexport const isObject = (obj: any): obj is Object =>\n obj !== null && typeof obj === \"object\";\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: any): boolean =>\n String(Math.floor(Number(obj))) === obj;\n\n/** @private is the given object a NaN? */\n// eslint-disable-next-line no-self-compare\nexport const isNaN = (obj: any): boolean => obj !== obj;\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: any,\n key: string | string[],\n def?: any,\n p = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = obj[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\nexport function setIn(obj: any, path: string, value: any): any {\n const res: any = clone(obj); // this keeps inheritance when obj is a class\n let resVal: any = res;\n let i = 0;\n const pathArray = toPath(path);\n\n for (; i < pathArray.length - 1; i++) {\n const currentPath: string = pathArray[i];\n const currentObj: any = getIn(obj, pathArray.slice(0, i + 1));\n\n if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {\n resVal = resVal[currentPath] = clone(currentObj);\n } else {\n const nextPath: string = pathArray[i + 1];\n resVal = resVal[currentPath] =\n isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};\n }\n }\n\n // Return original object if new value is the same as current\n if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {\n return obj;\n }\n\n if (value === undefined) {\n delete resVal[pathArray[i]];\n } else {\n resVal[pathArray[i]] = value;\n }\n\n // If the path array has a single element, the loop did not run.\n // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.\n if (i === 0 && value === undefined) {\n delete res[pathArray[i]];\n }\n\n return res;\n}\n\nexport function clone(value: any) {\n if (Array.isArray(value)) {\n return [...value];\n } else if (typeof value === \"object\" && value !== null) {\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't spread them\n if (Object.getPrototypeOf(value) !== Object.prototype) {\n return value;\n }\n return { ...value };\n } else {\n return value; // This is for primitive types which do not need cloning.\n }\n}\n\nfunction toPath(value: string | string[]) {\n if (Array.isArray(value)) return value; // Already in path array form.\n // Replace brackets with dots, remove leading/trailing dots, then split by dot.\n return value.replace(/\\[(\\d+)]/g, \".$1\").replace(/^\\./, \"\").replace(/\\.$/, \"\").split(\".\");\n}\n","import * as React from \"react\";\nimport { useFormex } from \"./Formex\";\nimport { getIn, isFunction, isObject } from \"./utils\";\nimport { FormexController } from \"./types\";\n\nexport interface FieldInputProps<Value> {\n /** Value of the field */\n value: Value;\n /** Name of the field */\n name: string;\n /** Multiple select? */\n multiple?: boolean;\n /** Is the field checked? */\n checked?: boolean;\n /** Change event handler */\n onChange: (event: React.SyntheticEvent) => void,\n /** Blur event handler */\n onBlur: (event: React.FocusEvent) => void,\n}\n\nexport interface FormexFieldProps<Value = any, FormValues extends object = any> {\n field: FieldInputProps<Value>;\n form: FormexController<FormValues>;\n}\n\nexport interface FieldConfig<Value, C extends React.ElementType | undefined = undefined> {\n\n /**\n * Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.\n */\n as?:\n | C\n | string\n | React.ForwardRefExoticComponent<any>;\n\n /**\n * Children render function <Field name>{props => ...}</Field>)\n */\n children?: ((props: FormexFieldProps<Value>) => React.ReactNode) | React.ReactNode;\n\n /**\n * Validate a single field value independently\n */\n // validate?: FieldValidator;\n\n /**\n * Used for 'select' and related input types.\n */\n multiple?: boolean;\n\n /**\n * Field name\n */\n name: string;\n\n /** HTML input type */\n type?: string;\n\n /** Field value */\n value?: any;\n\n /** Inner ref */\n innerRef?: (instance: any) => void;\n\n}\n\nexport type FieldProps<T, C extends React.ElementType | undefined> = {\n as?: C;\n} & (C extends React.ElementType ? (React.ComponentProps<C> & FieldConfig<T, C>) : FieldConfig<T, C>);\n\nexport function Field<T, C extends React.ElementType | undefined = undefined>({\n validate,\n name,\n children,\n as: is, // `as` is reserved in typescript lol\n // component,\n className,\n ...props\n }: FieldProps<T, C>) {\n const formex = useFormex();\n\n const field = getFieldProps({ name, ...props }, formex);\n\n if (isFunction(children)) {\n return children({ field, form: formex });\n }\n\n // if (component) {\n // if (typeof component === \"string\") {\n // const { innerRef, ...rest } = props;\n // return React.createElement(\n // component,\n // { ref: innerRef, ...field, ...rest, className },\n // children\n // );\n // }\n // return React.createElement(\n // component,\n // { field, form: formex, ...props, className },\n // children\n // );\n // }\n\n // default to input here so we can check for both `as` and `children` above\n const asElement = is || \"input\";\n\n if (typeof asElement === \"string\") {\n const { innerRef, ...rest } = props;\n return React.createElement(\n asElement,\n { ref: innerRef, ...field, ...rest, className },\n children\n );\n }\n\n return React.createElement(asElement, { ...field, ...props, className }, children);\n}\n\nconst getFieldProps = (nameOrOptions: string | FieldConfig<any>, formex: FormexController<any>): FieldInputProps<any> => {\n const isAnObject = isObject(nameOrOptions);\n const name = isAnObject\n ? (nameOrOptions as FieldConfig<any>).name\n : nameOrOptions;\n const valueState = getIn(formex.values, name);\n\n const field: FieldInputProps<any> = {\n name,\n value: valueState,\n onChange: formex.handleChange,\n onBlur: formex.handleBlur,\n };\n if (isAnObject) {\n const {\n type,\n value: valueProp, // value is special for checkboxes\n as: is,\n multiple,\n } = nameOrOptions as FieldConfig<any>;\n\n if (type === \"checkbox\") {\n if (valueProp === undefined) {\n field.checked = !!valueState;\n } else {\n field.checked = !!(\n Array.isArray(valueState) && ~valueState.indexOf(valueProp)\n );\n field.value = valueProp;\n }\n } else if (type === \"radio\") {\n field.checked = valueState === valueProp;\n field.value = valueProp;\n } else if (is === \"select\" && multiple) {\n field.value = field.value || [];\n field.multiple = true;\n }\n }\n return field;\n};\n","import React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { getIn, setIn } from \"./utils\";\nimport { deepEqual as equal } from \"fast-equals\";\n\nimport { FormexController, FormexResetProps } from \"./types\";\n\nexport function useCreateFormex<T extends object>({\n initialValues,\n initialErrors,\n initialDirty,\n initialTouched,\n validation,\n validateOnChange = false,\n validateOnInitialRender = false,\n onSubmit,\n onReset,\n onValuesChangeDeferred,\n debugId,\n}: {\n initialValues: T;\n initialErrors?: Record<string, string>;\n initialDirty?: boolean;\n initialTouched?: Record<string, boolean>;\n validateOnChange?: boolean;\n validateOnInitialRender?: boolean;\n validation?: (\n values: T\n ) =>\n | Record<string, string>\n | Promise<Record<string, string>>\n | undefined\n | void;\n onValuesChangeDeferred?: (values: T, controller: FormexController<T>) => void;\n onSubmit?: (values: T, controller: FormexController<T>) => void | Promise<void>;\n onReset?: (controller: FormexController<T>) => void | Promise<void>;\n debugId?: string;\n}): FormexController<T> {\n const initialValuesRef = useRef<T>(initialValues);\n const valuesRef = useRef<T>(initialValues);\n const debugIdRef = useRef<string | undefined>(debugId);\n\n const [values, setValuesInner] = useState<T>(initialValues);\n const [touchedState, setTouchedState] = useState<Record<string, boolean>>(initialTouched ?? {});\n const [errors, setErrors] = useState<Record<string, string>>(initialErrors ?? {});\n const [dirty, setDirty] = useState(initialDirty ?? false);\n const [submitCount, setSubmitCount] = useState(0);\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [isValidating, setIsValidating] = useState(false);\n const [version, setVersion] = useState(0);\n\n const onValuesChangeRef = useRef(onValuesChangeDeferred);\n onValuesChangeRef.current = onValuesChangeDeferred;\n const debounceTimeoutRef = useRef<any>(undefined);\n\n const callDebouncedOnValuesChange = useCallback((values: T) => {\n if (onValuesChangeRef.current) {\n if (debounceTimeoutRef.current) {\n clearTimeout(debounceTimeoutRef.current);\n }\n debounceTimeoutRef.current = setTimeout(() => {\n onValuesChangeRef.current?.(values, controllerRef.current);\n }, 300);\n }\n }, []);\n\n // Replace state for history with refs\n const historyRef = useRef<T[]>([initialValues]);\n const historyIndexRef = useRef<number>(0);\n\n useEffect(() => {\n if (validateOnInitialRender) {\n validate();\n }\n }, []);\n\n const setValues = useCallback((newValues: T) => {\n valuesRef.current = newValues;\n setValuesInner(newValues);\n setDirty(!equal(initialValuesRef.current, newValues));\n // Update history using refs\n const newHistory = historyRef.current.slice(0, historyIndexRef.current + 1);\n newHistory.push(newValues);\n historyRef.current = newHistory;\n historyIndexRef.current = newHistory.length - 1;\n callDebouncedOnValuesChange(newValues);\n }, [callDebouncedOnValuesChange]);\n\n const validate = useCallback(async () => {\n setIsValidating(true);\n const validationErrors = await validation?.(valuesRef.current);\n setErrors(validationErrors ?? {});\n setIsValidating(false);\n return validationErrors;\n }, [validation]);\n\n const setFieldValue = useCallback(\n (key: string, value: any, shouldValidate?: boolean) => {\n const newValues = setIn(valuesRef.current, key, value);\n valuesRef.current = newValues;\n setValuesInner(newValues);\n if (!equal(getIn(initialValuesRef.current, key), value)) {\n setDirty(true);\n }\n if (shouldValidate) {\n validate();\n }\n // Update history using refs\n const newHistory = historyRef.current.slice(0, historyIndexRef.current + 1);\n newHistory.push(newValues);\n historyRef.current = newHistory;\n historyIndexRef.current = newHistory.length - 1;\n callDebouncedOnValuesChange(newValues);\n },\n [validate, callDebouncedOnValuesChange]\n );\n\n const setFieldError = useCallback((key: string, error: string | undefined) => {\n setErrors((prevErrors) => {\n const newErrors = { ...prevErrors };\n if (error) {\n newErrors[key] = error;\n } else {\n delete newErrors[key];\n }\n return newErrors;\n });\n }, []);\n\n const setFieldTouched = useCallback(\n (key: string, touched: boolean, shouldValidate?: boolean) => {\n setTouchedState((prev) => ({\n ...prev,\n [key]: touched,\n }));\n if (shouldValidate) {\n validate();\n }\n },\n [validate]\n );\n\n const handleChange = useCallback(\n (event: React.SyntheticEvent) => {\n const target = event.target as HTMLInputElement;\n let value;\n if (target.type === \"checkbox\") {\n value = target.checked;\n } else if (target.type === \"number\") {\n value = target.valueAsNumber;\n } else {\n value = target.value;\n }\n const name = target.name;\n setFieldValue(name, value, validateOnChange);\n setFieldTouched(name, true);\n },\n [setFieldValue, setFieldTouched, validateOnChange]\n );\n\n const handleBlur = useCallback((event: React.FocusEvent) => {\n const target = event.target as HTMLInputElement;\n const name = target.name;\n setFieldTouched(name, true);\n }, [setFieldTouched]);\n\n const submit = useCallback(\n async (e?: React.FormEvent<HTMLFormElement>) => {\n e?.preventDefault();\n e?.stopPropagation();\n setIsSubmitting(true);\n setSubmitCount((prev) => prev + 1);\n const validationErrors = await validation?.(valuesRef.current);\n if (validationErrors && Object.keys(validationErrors).length > 0) {\n setErrors(validationErrors);\n } else {\n setErrors({});\n await onSubmit?.(valuesRef.current, controllerRef.current);\n }\n setIsSubmitting(false);\n setVersion((prev) => prev + 1);\n },\n [onSubmit, validation]\n );\n\n const resetForm = useCallback((props?: FormexResetProps<T>) => {\n const {\n submitCount: submitCountProp,\n values: valuesProp,\n errors: errorsProp,\n touched: touchedProp\n } = props ?? {};\n valuesRef.current = valuesProp ?? initialValuesRef.current;\n initialValuesRef.current = valuesProp ?? initialValuesRef.current;\n setValuesInner(valuesProp ?? initialValuesRef.current);\n setErrors(errorsProp ?? {});\n setTouchedState(touchedProp ?? initialTouched ?? {});\n setDirty(false);\n setSubmitCount(submitCountProp ?? 0);\n setVersion((prev) => prev + 1);\n onReset?.(controllerRef.current);\n // Reset history with refs\n historyRef.current = [valuesProp ?? initialValuesRef.current];\n historyIndexRef.current = 0;\n }, [onReset, initialTouched]);\n\n const undo = useCallback(() => {\n if (historyIndexRef.current > 0) {\n const newIndex = historyIndexRef.current - 1;\n const newValues = historyRef.current[newIndex];\n setValuesInner(newValues);\n valuesRef.current = newValues;\n historyIndexRef.current = newIndex;\n setDirty(!equal(initialValuesRef.current, newValues));\n callDebouncedOnValuesChange(newValues);\n }\n }, [callDebouncedOnValuesChange]);\n\n const redo = useCallback(() => {\n if (historyIndexRef.current < historyRef.current.length - 1) {\n const newIndex = historyIndexRef.current + 1;\n const newValues = historyRef.current[newIndex];\n setValuesInner(newValues);\n valuesRef.current = newValues;\n historyIndexRef.current = newIndex;\n setDirty(!equal(initialValuesRef.current, newValues));\n callDebouncedOnValuesChange(newValues);\n }\n }, [callDebouncedOnValuesChange]);\n\n const controllerRef = useRef<FormexController<T>>({} as FormexController<T>);\n\n const controller = useMemo<FormexController<T>>(\n () => ({\n values,\n initialValues: initialValuesRef.current,\n handleChange,\n isSubmitting,\n setSubmitting: setIsSubmitting,\n setValues,\n setFieldValue,\n errors,\n setFieldError,\n touched: touchedState,\n setFieldTouched,\n setTouched: setTouchedState,\n dirty,\n setDirty,\n handleSubmit: submit,\n submitCount,\n setSubmitCount,\n handleBlur,\n validate,\n isValidating,\n resetForm,\n version,\n debugId: debugIdRef.current,\n undo,\n redo,\n canUndo: historyIndexRef.current > 0,\n canRedo: historyIndexRef.current < historyRef.current.length - 1,\n }),\n [\n values,\n errors,\n touchedState,\n dirty,\n isSubmitting,\n submitCount,\n isValidating,\n version,\n handleChange,\n handleBlur,\n setValues,\n setFieldValue,\n setFieldTouched,\n setTouchedState,\n setFieldError,\n validate,\n submit,\n resetForm,\n undo,\n redo,\n ]\n );\n\n useEffect(() => {\n controllerRef.current = controller;\n }, [controller]);\n\n return controller;\n}\n"],"names":["FormexContext","React","createContext","useFormex","useContext","Formex","t0","$","_c","value","children","t1","isEmptyArray","Array","isArray","length","isFunction","obj","isObject","isInteger","String","Math","floor","Number","isNaN","getIn","key","def","p","path","toPath","undefined","setIn","res","clone","resVal","i","pathArray","currentPath","currentObj","slice","nextPath","Object","getPrototypeOf","prototype","replace","split","Field","className","is","name","props","validate","t2","as","t3","t4","t5","formex","field","Symbol","for","bb0","getFieldProps","form","asElement","innerRef","rest","ref","createElement","nameOrOptions","isAnObject","valueState","values","onChange","handleChange","onBlur","handleBlur","type","valueProp","multiple","checked","indexOf","useCreateFormex","initialValues","initialErrors","initialDirty","initialTouched","validation","validateOnChange","validateOnInitialRender","onSubmit","onReset","onValuesChangeDeferred","debugId","initialValuesRef","useRef","valuesRef","debugIdRef","setValuesInner","useState","touchedState","setTouchedState","errors","setErrors","dirty","setDirty","submitCount","setSubmitCount","isSubmitting","setIsSubmitting","isValidating","setIsValidating","version","setVersion","onValuesChangeRef","current","debounceTimeoutRef","callDebouncedOnValuesChange","useCallback","clearTimeout","setTimeout","controllerRef","historyRef","historyIndexRef","useEffect","setValues","newValues","equal","newHistory","push","validationErrors","setFieldValue","shouldValidate","setFieldError","error","prevErrors","newErrors","setFieldTouched","touched","prev","event","target","valueAsNumber","submit","e","preventDefault","stopPropagation","keys","resetForm","submitCountProp","valuesProp","errorsProp","touchedProp","undo","newIndex","redo","controller","useMemo","setSubmitting","setTouched","handleSubmit","canUndo","canRedo"],"mappings":";;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