@rolster/react-forms 18.2.9 → 18.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.
Files changed (33) hide show
  1. package/dist/cjs/index.js +230 -214
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/index.js +231 -211
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/esm/form-array/form-array-control.hook.d.ts +24 -18
  6. package/dist/esm/form-array/form-array-control.hook.js +32 -26
  7. package/dist/esm/form-array/form-array-control.hook.js.map +1 -1
  8. package/dist/esm/form-array/form-array-group.hook.d.ts +10 -9
  9. package/dist/esm/form-array/form-array-group.hook.js +33 -12
  10. package/dist/esm/form-array/form-array-group.hook.js.map +1 -1
  11. package/dist/esm/form-array/form-array.hook.d.ts +5 -11
  12. package/dist/esm/form-array/form-array.hook.js +45 -55
  13. package/dist/esm/form-array/form-array.hook.js.map +1 -1
  14. package/dist/esm/form-array/index.d.ts +2 -2
  15. package/dist/esm/form-array/index.js +2 -2
  16. package/dist/esm/form-array/index.js.map +1 -1
  17. package/dist/esm/form-control.hook.d.ts +16 -11
  18. package/dist/esm/form-control.hook.js +49 -58
  19. package/dist/esm/form-control.hook.js.map +1 -1
  20. package/dist/esm/form-group.hook.d.ts +3 -3
  21. package/dist/esm/form-group.hook.js +17 -17
  22. package/dist/esm/form-group.hook.js.map +1 -1
  23. package/dist/esm/form-ref.hook.d.ts +10 -10
  24. package/dist/esm/form-ref.hook.js +21 -17
  25. package/dist/esm/form-ref.hook.js.map +1 -1
  26. package/dist/esm/index.d.ts +2 -3
  27. package/dist/esm/index.js +2 -2
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/types.d.ts +24 -10
  30. package/package.json +7 -5
  31. package/dist/esm/form-array/types.d.ts +0 -23
  32. package/dist/esm/form-array/types.js +0 -2
  33. package/dist/esm/form-array/types.js.map +0 -1
package/dist/cjs/index.js CHANGED
@@ -2,19 +2,69 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var helpersForms = require('@rolster/helpers-forms');
6
5
  var uuid = require('uuid');
7
6
  var react = require('react');
8
- var rxjs = require('rxjs');
7
+
8
+ function itIsFormControlOptions(props) {
9
+ return (typeof props === 'object' && ('state' in props || 'validators' in props));
10
+ }
11
+ function itIsFormGroupOptions(props) {
12
+ return typeof props === 'object' && 'controls' in props;
13
+ }
14
+ function itIsFormArrayOptions(props) {
15
+ return (typeof props === 'object' && ('groups' in props || 'validators' in props));
16
+ }
17
+ function createFormControlOptions(...argsProps) {
18
+ const [props, validators] = argsProps;
19
+ if (!props) {
20
+ return { state: props, validators };
21
+ }
22
+ if (!validators && itIsFormControlOptions(props)) {
23
+ return props;
24
+ }
25
+ return {
26
+ state: props,
27
+ validators
28
+ };
29
+ }
30
+ function createFormGroupOptions(...argsProps) {
31
+ const [props, validators] = argsProps;
32
+ if (!validators && itIsFormGroupOptions(props)) {
33
+ return props;
34
+ }
35
+ return {
36
+ controls: props,
37
+ validators
38
+ };
39
+ }
40
+ function createFormArrayOptions(...argsProps) {
41
+ const [props, validators] = argsProps;
42
+ if (!props) {
43
+ return { groups: props, validators };
44
+ }
45
+ if (!validators && itIsFormArrayOptions(props)) {
46
+ return props;
47
+ }
48
+ return {
49
+ groups: props,
50
+ validators
51
+ };
52
+ }
9
53
 
10
54
  const FALSY_VALUE = ['false', 'undefined', '0', 0];
11
- function toBoolean(value) {
12
- return !(!(typeof value !== 'undefined' && value !== null) ||
55
+ function itIsDefined(object) {
56
+ return typeof object !== 'undefined' && object !== null;
57
+ }
58
+ function itIsUndefined(object) {
59
+ return !itIsDefined(object);
60
+ }
61
+ function parseBoolean(value) {
62
+ return !(itIsUndefined(value) ||
13
63
  value === false ||
14
64
  FALSY_VALUE.includes(value));
15
- }
16
- const controlIsValid = (props) => {
17
- const { state, validators } = props;
65
+ }
66
+
67
+ const controlIsValid = ({ state, validators }) => {
18
68
  return validators.reduce((errors, validator) => {
19
69
  const error = validator(state);
20
70
  if (error) {
@@ -23,22 +73,16 @@ const controlIsValid = (props) => {
23
73
  return errors;
24
74
  }, []);
25
75
  };
26
- const controlsAllChecked = (controls, props) => {
27
- return Object.values(controls).reduce((value, control) => value && toBoolean(control[props]), true);
76
+ const controlsAllChecked = (controls, key) => {
77
+ return Object.values(controls).reduce((value, control) => value && parseBoolean(control[key]), true);
28
78
  };
29
- const controlsPartialChecked = (controls, props) => {
30
- return Object.values(controls).reduce((value, control) => value || toBoolean(control[props]), false);
79
+ const controlsPartialChecked = (controls, key) => {
80
+ return Object.values(controls).reduce((value, control) => value || parseBoolean(control[key]), false);
31
81
  };
32
82
  const controlsToState = (controls) => {
33
- return Object.entries(controls).reduce((json, [key, { state }]) => {
34
- json[key] = state;
35
- return json;
36
- }, {});
37
- };
38
- const controlsToValue = (controls) => {
39
- return Object.entries(controls).reduce((json, [key, { value }]) => {
40
- json[key] = value;
41
- return json;
83
+ return Object.entries(controls).reduce((result, [key, { state }]) => {
84
+ result[key] = state;
85
+ return result;
42
86
  }, {});
43
87
  };
44
88
  const groupIsValid = ({ controls, validators }) => {
@@ -51,10 +95,10 @@ const groupIsValid = ({ controls, validators }) => {
51
95
  }, []);
52
96
  };
53
97
  function groupAllChecked(groups, key) {
54
- return groups.reduce((value, group) => value && toBoolean(group[key]), true);
98
+ return groups.reduce((value, group) => value && parseBoolean(group[key]), true);
55
99
  }
56
100
  function groupPartialChecked(groups, key) {
57
- return groups.reduce((value, group) => value || toBoolean(group[key]), false);
101
+ return groups.reduce((value, group) => value || parseBoolean(group[key]), false);
58
102
  }
59
103
  const arrayIsValid = ({ groups, validators }) => {
60
104
  return validators.reduce((errors, validator) => {
@@ -67,26 +111,25 @@ const arrayIsValid = ({ groups, validators }) => {
67
111
  };
68
112
 
69
113
  class RolsterArrayControl {
70
- constructor(props) {
71
- const { uuid, focused, dirty, disabled, initialState, state, touched, validators } = props;
72
- this.uuid = uuid;
73
- this.focused = focused || false;
114
+ constructor(options) {
115
+ this.initialState = options.initialState;
116
+ this.uuid = options.uuid;
117
+ this.focused = !!options.focused;
74
118
  this.unfocused = !this.focused;
75
- this.touched = touched || false;
119
+ this.touched = !!options.touched;
76
120
  this.untouched = !this.touched;
77
- this.dirty = dirty || false;
121
+ this.dirty = !!options.dirty;
78
122
  this.pristine = !this.dirty;
79
- this.disabled = disabled || false;
123
+ this.disabled = !!options.disabled;
80
124
  this.enabled = !this.disabled;
125
+ const { state, validators } = options;
81
126
  this.state = state;
82
127
  this.validators = validators;
83
- this.initialState = initialState;
84
128
  this.errors = validators ? controlIsValid({ state, validators }) : [];
85
129
  this.error = this.errors[0];
86
130
  this.valid = this.errors.length === 0;
87
131
  this.invalid = !this.valid;
88
132
  this.wrong = this.touched && this.invalid;
89
- this.value = state;
90
133
  }
91
134
  focus() {
92
135
  if (!this.focused) {
@@ -124,37 +167,43 @@ class RolsterArrayControl {
124
167
  setValidators(validators) {
125
168
  this.update({ validators });
126
169
  }
170
+ subscribe(listener) {
171
+ this.subscriber = listener;
172
+ }
127
173
  reset() {
128
174
  this.update({ state: this.initialState });
129
175
  }
130
176
  update(changes) {
131
- this.group?.parent?.refreshControl(this, {
132
- ...changes,
133
- initialState: this.initialState
134
- });
177
+ if (this.subscriber) {
178
+ this.subscriber({
179
+ ...this,
180
+ ...changes,
181
+ initialState: this.initialState
182
+ });
183
+ }
135
184
  }
136
185
  }
137
- function useFormArrayControl(controlProps, controlValidators) {
138
- const props = helpersForms.createFormControlProps(controlProps, controlValidators);
186
+ function useArrayControl(options, validators) {
187
+ const controlOptions = createFormControlOptions(options, validators);
139
188
  return new RolsterArrayControl({
140
- ...props,
189
+ ...controlOptions,
141
190
  uuid: uuid.v4(),
142
- initialState: props.state
191
+ initialState: controlOptions.state
143
192
  });
144
193
  }
145
- function useInputArrayControl(controlProps, controlValidators) {
146
- const props = helpersForms.createFormControlProps(controlProps, controlValidators);
147
- return new RolsterArrayControl({
148
- ...props,
149
- uuid: uuid.v4(),
150
- initialState: props.state
151
- });
194
+ function useReactArrayControl(options, validators) {
195
+ return useArrayControl(options, validators);
196
+ }
197
+ function useFormArrayControl(options, validators) {
198
+ return useArrayControl(options, validators);
199
+ }
200
+ function useInputArrayControl(options, validators) {
201
+ return useArrayControl(options, validators);
152
202
  }
153
203
 
154
204
  class RolsterArrayGroup {
155
- constructor(props) {
156
- const { controls, resource, uuid, validators } = props;
157
- Object.values(controls).forEach((control) => (control.group = this));
205
+ constructor(options) {
206
+ const { controls, resource, uuid, validators } = options;
158
207
  this.uuid = uuid;
159
208
  this.controls = controls;
160
209
  this.validators = validators;
@@ -164,53 +213,72 @@ class RolsterArrayGroup {
164
213
  this.valid =
165
214
  this.errors.length === 0 && controlsAllChecked(controls, 'valid');
166
215
  this.invalid = !this.valid;
167
- this.touched = controlsPartialChecked(controls, 'touched');
168
- this.toucheds = controlsAllChecked(controls, 'touched');
169
216
  this.dirty = controlsPartialChecked(controls, 'dirty');
170
217
  this.dirties = controlsAllChecked(controls, 'dirty');
218
+ this.touched = controlsPartialChecked(controls, 'touched');
219
+ this.toucheds = controlsAllChecked(controls, 'touched');
171
220
  this.untouched = !this.touched;
172
221
  this.untoucheds = !this.toucheds;
173
222
  this.pristine = !this.dirty;
174
223
  this.pristines = !this.dirties;
175
224
  this.wrong = this.touched && this.invalid;
176
225
  this.state = controlsToState(controls);
177
- this.value = controlsToValue(controls);
226
+ const subscriber = (options) => {
227
+ this.update({
228
+ controls: Object.entries(this.controls).reduce((controls, [key, control]) => {
229
+ controls[key] =
230
+ control.uuid === options.uuid
231
+ ? new RolsterArrayControl(options)
232
+ : control;
233
+ return controls;
234
+ }, {})
235
+ });
236
+ };
237
+ Object.values(controls).forEach((control) => {
238
+ control.subscribe(subscriber);
239
+ });
178
240
  }
179
241
  setValidators(validators) {
180
- this.parent?.refreshGroup(this, { validators });
242
+ this.update({ validators });
243
+ }
244
+ subscribe(listener) {
245
+ this.subscriber = listener;
246
+ }
247
+ update(changes) {
248
+ if (this.subscriber) {
249
+ this.subscriber({ ...this, ...changes });
250
+ }
181
251
  }
182
252
  }
183
- function useFormArrayGroup(groupProps, groupValidators) {
184
- const props = helpersForms.createFormGroupProps(groupProps, groupValidators);
185
- return new RolsterArrayGroup({ ...props, uuid: uuid.v4() });
253
+ function useFormArrayGroup(options, validators) {
254
+ const groupOptions = createFormGroupOptions(options, validators);
255
+ return new RolsterArrayGroup({ ...groupOptions, uuid: uuid.v4() });
186
256
  }
187
257
 
188
- function cloneFormArrayControl(control, changes) {
189
- return new RolsterArrayControl({ ...control, ...changes });
190
- }
191
- function cloneFormArrayGroup(group, changes) {
192
- return new RolsterArrayGroup({ ...group, ...changes });
193
- }
194
- function cloneFormControlForArrayGroup(group, control, changes) {
195
- const newControl = cloneFormArrayControl(control, changes);
196
- const { uuid } = newControl;
197
- const controls = Object.entries(group.controls).reduce((controls, [key, control]) => {
198
- controls[key] = control.uuid === uuid ? newControl : control;
199
- return controls;
200
- }, {});
201
- return new RolsterArrayGroup({ ...group, controls });
202
- }
203
- function useFormArray(arrayProps, arrayValidators) {
204
- const props = helpersForms.createFormArrayProps(arrayProps, arrayValidators);
205
- const [currentState] = react.useState(props.groups);
206
- const [state, setState] = react.useState([]);
207
- const [validators, setValidators] = react.useState(props.validators);
208
- const [controls, setControls] = react.useState([]);
209
- const [groups, setGroups] = react.useState(props.groups || []);
258
+ function useFormArray(options, arrayValidators) {
259
+ const arrayOptions = createFormArrayOptions(options, arrayValidators);
260
+ const { validators } = arrayOptions;
261
+ const groups = arrayOptions.groups || [];
262
+ const [arrayState, setArrayState] = react.useState({
263
+ controls: groups.map(({ controls }) => controls),
264
+ groups,
265
+ state: groups.map(({ controls }) => controlsToState(controls)),
266
+ validators
267
+ });
268
+ const currentState = react.useRef(groups);
210
269
  react.useEffect(() => {
211
- setControls(groups.map(({ controls }) => controls));
212
- setState(groups.map(({ controls }) => controlsToState(controls)));
213
- }, [groups]);
270
+ const subscriber = (options) => {
271
+ setArrayState((state) => ({
272
+ ...state,
273
+ groups: arrayState.groups.map((group) => group.uuid === options.uuid
274
+ ? new RolsterArrayGroup(options)
275
+ : group)
276
+ }));
277
+ };
278
+ arrayState.groups.forEach((group) => {
279
+ group.subscribe(subscriber);
280
+ });
281
+ }, [arrayState]);
214
282
  const errors = validators ? arrayIsValid({ groups, validators }) : [];
215
283
  const error = errors[0];
216
284
  const valid = errors.length === 0 && groupAllChecked(groups, 'valid');
@@ -218,168 +286,154 @@ function useFormArray(arrayProps, arrayValidators) {
218
286
  const toucheds = groupAllChecked(groups, 'touched');
219
287
  const dirties = groupAllChecked(groups, 'dirty');
220
288
  const dirty = groupPartialChecked(groups, 'dirty');
289
+ function setGroups(groups) {
290
+ setArrayState((currentState) => ({
291
+ ...currentState,
292
+ groups,
293
+ controls: groups.map(({ controls }) => controls),
294
+ state: groups.map(({ controls }) => controlsToState(controls))
295
+ }));
296
+ }
221
297
  function push(group) {
222
- setGroups([...groups, group]);
298
+ setGroups([...arrayState.groups, group]);
223
299
  }
224
- function merge(newGroups) {
225
- setGroups([...groups, ...newGroups]);
300
+ function merge(groups) {
301
+ setGroups([...arrayState.groups, ...groups]);
226
302
  }
227
303
  function set(groups) {
228
304
  setGroups(groups);
229
305
  }
230
- function refreshControl(control, changes) {
231
- if (control.group) {
232
- const group = cloneFormControlForArrayGroup(control.group, control, changes);
233
- setGroups(groups.map((currentGroup) => currentGroup.uuid === group.uuid ? group : currentGroup));
234
- }
235
- }
236
- function refreshGroup(group, changes) {
237
- const newGroup = cloneFormArrayGroup(group, changes);
238
- const { uuid } = newGroup;
239
- setGroups(groups.map((currentGroup) => currentGroup.uuid === uuid ? newGroup : currentGroup));
240
- }
241
- function remove(group) {
242
- setGroups(groups.filter(({ uuid }) => group.uuid !== uuid));
306
+ function remove({ uuid }) {
307
+ setGroups(arrayState.groups.filter((group) => group.uuid !== uuid));
243
308
  }
244
309
  function reset() {
245
- setGroups(currentState || []);
310
+ setGroups(currentState.current);
246
311
  }
247
- const formArray = {
248
- controls,
312
+ function setValidators(validators) {
313
+ setArrayState((state) => ({ ...state, validators }));
314
+ }
315
+ return {
316
+ ...arrayState,
249
317
  dirty,
250
318
  dirties,
251
319
  error,
252
320
  errors,
253
- groups,
254
321
  invalid: !valid,
255
322
  merge,
256
323
  pristine: !dirty,
257
324
  pristines: !dirties,
258
325
  push,
259
- refreshControl,
260
- refreshGroup,
261
326
  remove,
262
327
  reset,
263
328
  set,
264
329
  setValidators,
265
- state,
266
330
  touched,
267
331
  toucheds,
268
332
  untouched: !touched,
269
333
  untoucheds: !toucheds,
270
334
  valid,
271
- value: state,
272
335
  wrong: touched && !valid
273
336
  };
274
- groups.forEach((group) => (group.parent = formArray));
275
- return formArray;
276
337
  }
277
338
 
278
- function useControl(controlProps, controlValidators) {
279
- const props = helpersForms.createFormControlProps(controlProps, controlValidators);
280
- const [state, setCurrentState] = react.useState(props.state);
281
- const [value, setValue] = react.useState(props.state);
282
- const [touched, setTouched] = react.useState(props.touched || false);
283
- const [dirty, setDirty] = react.useState(false);
284
- const [focused, setFocused] = react.useState(false);
285
- const [disabled, setDisabled] = react.useState(false);
286
- const [initialValue] = react.useState(props.state);
287
- const [validators, setValidators] = react.useState(props.validators);
288
- const [subscribers] = react.useState(new rxjs.BehaviorSubject(props.state));
339
+ function useControl(controlOptions, controlValidators) {
340
+ const { state, touched, validators } = createFormControlOptions(controlOptions, controlValidators);
341
+ const [controlState, setControlState] = react.useState({
342
+ dirty: false,
343
+ disabled: false,
344
+ focused: false,
345
+ state: state,
346
+ touched: !!touched,
347
+ validators: validators
348
+ });
349
+ const initialState = react.useRef(state);
289
350
  const elementRef = react.useRef(null);
290
- const errors = (() => validators ? controlIsValid({ state, validators }) : [])();
291
- const error = (() => errors[0])();
292
- const valid = (() => errors.length === 0)();
293
- react.useEffect(() => {
294
- if (state !== null && state !== undefined) {
295
- setValue(state);
296
- }
297
- subscribers.next(state);
298
- }, [state]);
351
+ const errors = validators ? controlIsValid({ state, validators }) : [];
352
+ const valid = errors.length === 0;
299
353
  function focus() {
300
- setFocused(true);
354
+ setControlState((state) => ({ ...state, focused: true }));
301
355
  }
302
356
  function blur() {
303
- setFocused(false);
357
+ setControlState((state) => ({ ...state, focused: false }));
304
358
  }
305
359
  function disable() {
306
- setDisabled(true);
360
+ setControlState((state) => ({ ...state, disabled: true }));
307
361
  }
308
362
  function enable() {
309
- setDisabled(false);
363
+ setControlState((state) => ({ ...state, disabled: false }));
310
364
  }
311
365
  function touch() {
312
- setTouched(true);
366
+ setControlState((state) => ({ ...state, touched: true }));
313
367
  }
314
368
  function untouch() {
315
- setTouched(false);
369
+ setControlState((state) => ({ ...state, touched: false }));
316
370
  }
317
371
  function setState(state) {
318
- setDirty(true);
319
- setCurrentState(state);
372
+ setControlState((currentState) => ({
373
+ ...currentState,
374
+ dirty: true,
375
+ state
376
+ }));
320
377
  }
321
- function reset() {
322
- setTouched(false);
323
- setDirty(false);
324
- setCurrentState(initialValue);
378
+ function setValidators(validators) {
379
+ setControlState((state) => ({ ...state, validators }));
325
380
  }
326
- function subscribe(subscriber) {
327
- const subscription = subscribers.subscribe(subscriber);
328
- return () => subscription.unsubscribe();
381
+ function reset() {
382
+ setControlState((currentState) => ({
383
+ ...currentState,
384
+ dirty: false,
385
+ state: initialState.current,
386
+ touched: false
387
+ }));
329
388
  }
330
389
  return {
390
+ ...controlState,
331
391
  blur,
332
- dirty,
333
392
  disable,
334
- disabled,
335
393
  elementRef,
336
394
  enable,
337
- enabled: !disabled,
338
- error,
395
+ enabled: !controlState.disabled,
396
+ error: errors[0],
339
397
  errors,
340
398
  focus,
341
- focused,
342
399
  invalid: !valid,
343
- pristine: !dirty,
400
+ pristine: !controlState.dirty,
344
401
  reset,
345
402
  setState,
346
403
  setValidators,
347
- state,
348
- subscribe,
349
404
  touch,
350
- touched,
351
- unfocused: !focused,
405
+ unfocused: !controlState.focused,
352
406
  untouch,
353
- untouched: !touched,
407
+ untouched: !controlState.touched,
354
408
  valid,
355
- value,
356
- wrong: touched && !valid
409
+ wrong: controlState.touched && !valid
357
410
  };
358
411
  }
359
- function useReactControl(controlProps, controlValidators) {
360
- return useControl(controlProps, controlValidators);
412
+ function useReactControl(options, validators) {
413
+ return useControl(options, validators);
361
414
  }
362
- function useFormControl(controlProps, controlValidators) {
363
- return useControl(controlProps, controlValidators);
415
+ function useFormControl(options, validators) {
416
+ return useControl(options, validators);
364
417
  }
365
- function useInputControl(controlProps, controlValidators) {
366
- return useControl(controlProps, controlValidators);
418
+ function useInputControl(options, validators) {
419
+ return useControl(options, validators);
367
420
  }
368
421
 
369
- function useFormGroup(groupProps, groupValidators) {
370
- const props = helpersForms.createFormGroupProps(groupProps, groupValidators);
371
- const [validators, setValidators] = react.useState(props.validators);
372
- const { controls } = props;
373
- const errors = (() => validators ? groupIsValid({ controls, validators }) : [])();
374
- const valid = (() => errors.length === 0 && controlsAllChecked(controls, 'valid'))();
375
- const touched = (() => controlsPartialChecked(controls, 'touched'))();
376
- const toucheds = (() => controlsAllChecked(controls, 'touched'))();
377
- const dirty = (() => controlsPartialChecked(controls, 'dirty'))();
378
- const dirties = (() => controlsAllChecked(controls, 'dirty'))();
379
- const state = (() => controlsToState(controls))();
380
- const value = (() => controlsToValue(controls))();
422
+ function useFormGroup(options, groupValidators) {
423
+ const groupOptions = createFormGroupOptions(options, groupValidators);
424
+ const [validators, setValidators] = react.useState(groupOptions.validators);
425
+ const { controls } = groupOptions;
426
+ const errors = validators ? groupIsValid({ controls, validators }) : [];
427
+ const valid = errors.length === 0 && controlsAllChecked(controls, 'valid');
428
+ const state = controlsToState(controls);
429
+ const dirty = controlsPartialChecked(controls, 'dirty');
430
+ const dirties = controlsAllChecked(controls, 'dirty');
431
+ const touched = controlsPartialChecked(controls, 'touched');
432
+ const toucheds = controlsAllChecked(controls, 'touched');
381
433
  function reset() {
382
- Object.values(controls).forEach((control) => control.reset());
434
+ Object.values(controls).forEach((control) => {
435
+ control.reset();
436
+ });
383
437
  }
384
438
  return {
385
439
  controls,
@@ -391,54 +445,17 @@ function useFormGroup(groupProps, groupValidators) {
391
445
  pristine: !dirty,
392
446
  pristines: !dirties,
393
447
  reset,
394
- state,
395
448
  setValidators,
449
+ state,
396
450
  touched,
397
451
  toucheds,
398
452
  untouched: !touched,
399
453
  untoucheds: !toucheds,
400
454
  valid,
401
- value,
402
455
  wrong: touched && !valid
403
456
  };
404
457
  }
405
458
 
406
- function useInputRefControl(props) {
407
- const { setValue, state, validators } = props;
408
- const inputControl = useInputControl(state, validators);
409
- react.useEffect(() => {
410
- const { elementRef } = inputControl;
411
- elementRef?.current?.addEventListener('focus', () => {
412
- inputControl.focus();
413
- });
414
- elementRef?.current?.addEventListener('blur', () => {
415
- inputControl.blur();
416
- if (!inputControl.touched) {
417
- inputControl.touch();
418
- }
419
- });
420
- elementRef?.current?.addEventListener('change', ({ target }) => {
421
- setValue(inputControl, target.value);
422
- });
423
- }, []);
424
- return inputControl;
425
- }
426
- function useTextRefControl(controlProps, controlValidators) {
427
- return useInputRefControl({
428
- ...helpersForms.createFormControlProps(controlProps, controlValidators),
429
- setValue: (inputControl, value) => inputControl.setState(value)
430
- });
431
- }
432
- function useNumberRefControl(controlProps, controlValidators) {
433
- return useInputRefControl({
434
- ...helpersForms.createFormControlProps(controlProps, controlValidators),
435
- setValue: (inputControl, value) => inputControl.setState(+value)
436
- });
437
- }
438
-
439
- exports.cloneFormArrayControl = cloneFormArrayControl;
440
- exports.cloneFormArrayGroup = cloneFormArrayGroup;
441
- exports.cloneFormControlForArrayGroup = cloneFormControlForArrayGroup;
442
459
  exports.useFormArray = useFormArray;
443
460
  exports.useFormArrayControl = useFormArrayControl;
444
461
  exports.useFormArrayGroup = useFormArrayGroup;
@@ -446,7 +463,6 @@ exports.useFormControl = useFormControl;
446
463
  exports.useFormGroup = useFormGroup;
447
464
  exports.useInputArrayControl = useInputArrayControl;
448
465
  exports.useInputControl = useInputControl;
449
- exports.useNumberRefControl = useNumberRefControl;
466
+ exports.useReactArrayControl = useReactArrayControl;
450
467
  exports.useReactControl = useReactControl;
451
- exports.useTextRefControl = useTextRefControl;
452
468
  //# sourceMappingURL=index.js.map