gform-react 2.7.5 → 2.8.1

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 (45) hide show
  1. package/README.md +30 -30
  2. package/dist/cjs/gform-react.development.js +165 -140
  3. package/dist/cjs/gform-react.development.js.map +1 -1
  4. package/dist/cjs/gform-react.production.js +1 -1
  5. package/dist/cjs/gform-react.production.js.map +1 -1
  6. package/dist/esm/GForm.development.js +13 -10
  7. package/dist/esm/GForm.development.js.map +1 -1
  8. package/dist/esm/GForm.production.js +1 -1
  9. package/dist/esm/GForm.production.js.map +1 -1
  10. package/dist/esm/GInput.development.js +23 -22
  11. package/dist/esm/GInput.development.js.map +1 -1
  12. package/dist/esm/GInput.production.js +1 -1
  13. package/dist/esm/GInput.production.js.map +1 -1
  14. package/dist/esm/GValidator.development.js +1 -111
  15. package/dist/esm/GValidator.development.js.map +1 -1
  16. package/dist/esm/GValidator.production.js +1 -1
  17. package/dist/esm/GValidator.production.js.map +1 -1
  18. package/dist/esm/shared.development.js +134 -113
  19. package/dist/esm/shared.development.js.map +1 -1
  20. package/dist/esm/shared.development2.js +116 -0
  21. package/dist/esm/shared.development2.js.map +1 -0
  22. package/dist/esm/shared.production.js +1 -1
  23. package/dist/esm/shared.production.js.map +1 -1
  24. package/dist/esm/useFormSelector.development.js +4 -3
  25. package/dist/esm/useFormSelector.development.js.map +1 -1
  26. package/dist/esm/useFormSelector.production.js +1 -1
  27. package/dist/index.d.ts +7 -7
  28. package/native/dist/cjs/gform-react.development.js +151 -133
  29. package/native/dist/cjs/gform-react.development.js.map +1 -1
  30. package/native/dist/cjs/gform-react.production.js +1 -1
  31. package/native/dist/cjs/gform-react.production.js.map +1 -1
  32. package/native/dist/esm/RNGForm.development.js +4 -4
  33. package/native/dist/esm/RNGForm.development.js.map +1 -1
  34. package/native/dist/esm/RNGForm.production.js +1 -1
  35. package/native/dist/esm/RNGForm.production.js.map +1 -1
  36. package/native/dist/esm/RNGInput.development.js +23 -21
  37. package/native/dist/esm/RNGInput.development.js.map +1 -1
  38. package/native/dist/esm/RNGInput.production.js +1 -1
  39. package/native/dist/esm/RNGInput.production.js.map +1 -1
  40. package/native/dist/esm/shared.development.js +133 -112
  41. package/native/dist/esm/shared.development.js.map +1 -1
  42. package/native/dist/esm/shared.production.js +1 -1
  43. package/native/dist/esm/shared.production.js.map +1 -1
  44. package/native/dist/index.d.ts +7 -7
  45. package/package.json +3 -3
@@ -1,8 +1,9 @@
1
- import React, { Children, isValidElement, useContext, createContext, useSyncExternalStore, useRef, useCallback, useMemo } from 'react';
1
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
2
2
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
+ import React, { useContext, useSyncExternalStore, useRef, useCallback, useMemo, createContext } from 'react';
3
4
 
4
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
7
  const isObject = o => o && typeof o === 'object' && !Array.isArray(o);
7
8
  const defaultFieldProps = {
8
9
  text: {
@@ -20,84 +21,52 @@ const typeValueDict = {
20
21
  number: 'valueAsNumber'
21
22
  };
22
23
  const _generateIdUnsafe = () => (+new Date()).toString(36) + (1 - Math.random()).toString(36).substring(2, 16);
23
- const _copyStateFields = (source, destination) => {
24
- for (const key in destination.fields) {
25
- const sourceField = source.fields[key];
26
- const destField = destination.fields[key];
27
- if (!sourceField || sourceField.type !== destField.type) continue;
28
- destination.fields[key] = _objectSpread$1(_objectSpread$1({}, destField), sourceField);
29
- }
30
- };
31
- const _buildFormInitialValues = (rows = []) => {
32
- const fields = {};
33
- const inputs = _findInputs(rows);
34
- inputs.forEach(config => {
35
- if (fields[config.formKey]) {
36
- console.warn(`DEV ONLY - [Duplicate Keys] - field with key '${config.formKey}' already defined.`);
37
- }
38
- const {
39
- required = false,
40
- max,
41
- maxLength,
42
- min,
43
- minLength,
44
- step,
45
- pattern,
46
- type = "text",
47
- defaultValue,
48
- value,
49
- checked,
50
- defaultChecked,
51
- formKey,
52
- debounce,
53
- validatorKey
54
- } = config;
55
- const defaultProps = defaultFieldProps[type] || defaultFieldProps.text;
56
- const inputValue = value || defaultValue || checked || defaultChecked || defaultProps.value;
57
- fields[formKey] = {
58
- formKey,
59
- type,
60
- required,
61
- max,
62
- maxLength,
63
- min,
64
- minLength,
65
- step,
66
- pattern,
67
- value: inputValue,
68
- validatorKey,
69
- debounce,
70
- dirty: false,
71
- touched: false,
72
- gid: _generateIdUnsafe()
73
- };
74
- });
24
+ const _buildInputInitialValues = input => {
25
+ const {
26
+ required = false,
27
+ max,
28
+ maxLength,
29
+ min,
30
+ minLength,
31
+ step,
32
+ pattern,
33
+ type = "text",
34
+ defaultValue,
35
+ value,
36
+ checked,
37
+ defaultChecked,
38
+ formKey,
39
+ debounce,
40
+ validatorKey
41
+ } = input;
42
+ const defaultProps = defaultFieldProps[type] || defaultFieldProps.text;
43
+ const inputValue = value || defaultValue || checked || defaultChecked || defaultProps.value;
75
44
  return {
76
- fields: fields
77
- };
78
- };
79
- const _findInputs = (root, total = []) => {
80
- if (!root) return total;
81
- Children.forEach(root, child => {
82
- if (!isValidElement(child)) return;
83
- if (child.props) {
84
- const {
85
- formKey,
86
- children
87
- } = child.props;
88
- if (formKey) {
89
- total.push(child.props);
90
- }
91
- if (children) {
92
- _findInputs(children, total);
93
- }
45
+ formKey,
46
+ type,
47
+ required,
48
+ max,
49
+ maxLength,
50
+ min,
51
+ minLength,
52
+ step,
53
+ pattern,
54
+ value: inputValue,
55
+ validatorKey,
56
+ debounce,
57
+ dirty: false,
58
+ touched: false,
59
+ gid: _generateIdUnsafe(),
60
+ error: false,
61
+ errorText: '',
62
+ dispatchChanges(changes) {},
63
+ checkValidity() {
64
+ return false;
94
65
  }
95
- });
96
- return total;
66
+ };
97
67
  };
98
- const _findValidityKey = (validity, exclude = []) => {
68
+ const _findValidityKey = validity => {
99
69
  for (const key in validity) {
100
- if (exclude.includes(key)) continue;
101
70
  if (key !== 'valid' && validity[key]) {
102
71
  return key;
103
72
  }
@@ -210,14 +179,14 @@ const _merge = (target = {}, ...nodes) => {
210
179
  const next = nodes.shift();
211
180
  if (isObject(next)) {
212
181
  for (const key in next) {
213
- target[key] = target[key] ? _objectSpread$1(_objectSpread$1({}, target[key]), next[key]) : next[key];
182
+ target[key] = target[key] ? _objectSpread$2(_objectSpread$2({}, target[key]), next[key]) : next[key];
214
183
  }
215
184
  }
216
185
  return _merge(target, ...nodes);
217
186
  };
218
187
  const _buildRNFormState = (fields, dispatchChanges) => {
219
188
  const isFormValid = _checkIfFormIsValid(fields);
220
- const formState = _objectSpread$1(_objectSpread$1({}, fields), {}, {
189
+ const formState = _objectSpread$2(_objectSpread$2({}, fields), {}, {
221
190
  isValid: isFormValid,
222
191
  isInvalid: !isFormValid,
223
192
  toRawData: options => _toRawData(fields, options),
@@ -263,36 +232,38 @@ let validityMap;
263
232
  };
264
233
  }
265
234
 
266
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
267
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
235
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
236
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
268
237
  const useFormHandlers = (getState, setState, validators = {}, optimized = false) => {
269
238
  const _viHandler = (input, e) => {
270
239
  if (!input) return;
271
240
  const element = e && e.target;
241
+ input.touched = true;
272
242
  if (typeof document !== 'undefined' && (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement)) {
273
243
  if (!input.checkValidity) input.checkValidity = () => element.checkValidity();
274
- const hasInitialValue = !input.dirty && input.value && !input.touched;
244
+ const hasInitialValue = !input.dirty && input.value;
275
245
  if (hasInitialValue) {
276
- _checkInputManually(input);
246
+ const {
247
+ validityKey: _validityKey = 'custom'
248
+ } = _checkInputManually(input);
249
+ element.setCustomValidity(_validityKey);
277
250
  _dispatchChanges(input, input.formKey);
278
251
  return;
279
252
  }
280
253
  element.setCustomValidity('');
281
- const exclude = input.type && (input.pattern || hasCustomValidation(input)) ? ['typeMismatch'] : [];
282
- const validityKey = _findValidityKey(element.validity, exclude);
254
+ const validityKey = _findValidityKey(element.validity);
283
255
  _validateInput(input, validityKey, v => element.setCustomValidity(v));
284
256
  if (!validityKey && input.error) {
285
257
  element.setCustomValidity(input.errorText || 'error');
286
258
  }
287
259
  _dispatchChanges(input, input.formKey);
288
260
  } else {
289
- input.checkValidity = () => _checkInputManually(input);
261
+ input.checkValidity = () => _checkInputManually(input).isValid;
290
262
  input.checkValidity();
291
263
  _dispatchChanges(input, input.formKey);
292
264
  }
293
265
  };
294
266
  const _checkInputManually = input => {
295
- const exclude = input.type && (input.pattern || hasCustomValidation(input)) ? ['typeMismatch'] : [];
296
267
  let validityKey = _findValidityKey({
297
268
  valueMissing: input.required && !input.value || false,
298
269
  typeMismatch: _checkTypeMismatch(input),
@@ -301,48 +272,56 @@ const useFormHandlers = (getState, setState, validators = {}, optimized = false)
301
272
  patternMismatch: input.pattern && _checkResult(input.pattern, input.value) || false,
302
273
  rangeUnderflow: input.min && Number(input.value) < Number(input.min) || false,
303
274
  rangeOverflow: input.max && Number(input.value) > Number(input.max) || false
304
- }, exclude);
275
+ });
305
276
  if (!validityKey && input.error) {
306
277
  validityKey = 'customError';
307
278
  }
308
279
  _validateInput(input, validityKey);
309
- return !input.error;
280
+ return {
281
+ isValid: !input.error,
282
+ validityKey
283
+ };
310
284
  };
311
285
  const _updateInputHandler = (input, e, unknown) => {
312
286
  input.value = _extractValue(e, unknown);
287
+ input.dirty = true;
313
288
  _viHandler(input, e);
314
289
  };
315
290
  const _validateInput = (input, validityKey, setValidity) => {
316
291
  const inputValidator = validators[input.validatorKey || input.formKey] || validators['*'];
317
292
  {
318
293
  if (validityKey && !(inputValidator !== null && inputValidator !== void 0 && inputValidator.hasConstraint(validityKey))) {
319
- if (validityKey === 'typeMismatch') console.warn(`DEV ONLY - [Missing Validator] - the input '${input.formKey}' has described the constraint '${validityMap[validityKey]}' however, a correspond validator/custom validation/pattern validator is missing.\nadd '${handlersMap[validityMap[validityKey]]}' or 'withCustomValidation' or '${handlersMap[validityMap.patternMismatch]}' to the input validator.\nexample:\nconst validators: GValidators = {\n\temail: new GValidator().withPatternMismatchMessage('pattern mismatch'),\n\t...\n}\n\nor either remove the constraint '${validityMap[validityKey]}' from the input props`);else console.warn(`DEV ONLY - [Missing Validator] - the input '${input.formKey}' has described the constraint '${validityMap[validityKey]}' however, a correspond validator is missing.\nadd '${handlersMap[validityMap[validityKey]]}' to the input validator.\nexample:\nconst validators: GValidators = {\n\temail: new GValidator().withPatternMismatchMessage('pattern mismatch'),\n\t...\n}\n\nor either remove the constraint '${validityMap[validityKey]}' from the input props`);
294
+ if (validityKey === 'typeMismatch') {
295
+ if (!(inputValidator !== null && inputValidator !== void 0 && inputValidator.handlers.length)) console.warn(`DEV ONLY - [Missing Validator] - the input '${input.formKey}' has described the constraint '${validityMap[validityKey]}' however, a correspond validator is missing.\nadd '${handlersMap[validityMap[validityKey]]}' or 'withCustomValidation' or '${handlersMap[validityMap.patternMismatch]}' to the input validator.\nexample:\nconst validators: GValidators = {\n\temail: new GValidator().withTypeMismatchMessage('pattern mismatch'),\n\t...\n}\nif you added on of these validators then the input is still suffering from '${validityKey}' violation.\n\nor either remove the constraint '${validityMap[validityKey]}' from the input props.\n`);else console.warn(`DEV ONLY - [Missing Validator] - the input '${input.formKey}' has described the constraint '${validityMap[validityKey]}' however, a correspond validator is missing or not satisfies the native constraint.\nadd '${handlersMap[validityMap[validityKey]]}' or 'withCustomValidation' to the input validator.\nexample:\nconst validators: GValidators = {\n\temail: new GValidator().withTypeMismatchMessage('pattern mismatch'),\n\t...\n}\n\nif you already have a Custom Validation then the input is still not satisfies the native type pattern.\neither enforce it or remove the constraint '${validityMap[validityKey]}' from the input props`);
296
+ } else console.warn(`DEV ONLY - [Missing Validator] - the input '${input.formKey}' has described the constraint '${validityMap[validityKey]}' however, a correspond validator is missing.\nadd '${handlersMap[validityMap[validityKey]]}' to the input validator.\nexample:\nconst validators: GValidators = {\n\temail: new GValidator().withPatternMismatchMessage('pattern mismatch'),\n\t...\n}\n\nor either remove the constraint '${validityMap[validityKey]}' from the input props`);
297
+ console.warn(`form submition is prevented due to violation(s) of input '${input.formKey}': violation '${validityKey}' caused by '${validityMap[validityKey]}' property (<Ginput ${validityMap[validityKey]}={...} />)`);
320
298
  }
321
299
  }
322
300
  if (inputValidator) {
323
301
  __validateInput(input, inputValidator, validityKey, setValidity);
324
302
  }
325
- input.touched = true;
326
303
  };
327
304
  const _dispatchChanges = (changes, key) => setState(prev => {
328
305
  if (key) {
329
- return _objectSpread(_objectSpread({}, prev), {}, {
330
- fields: _objectSpread(_objectSpread({}, prev.fields), {}, {
331
- [key]: _objectSpread(_objectSpread({}, prev.fields[key]), changes)
306
+ return _objectSpread$1(_objectSpread$1({}, prev), {}, {
307
+ fields: _objectSpread$1(_objectSpread$1({}, prev.fields), {}, {
308
+ [key]: _objectSpread$1(_objectSpread$1({}, prev.fields[key]), changes)
332
309
  })
333
310
  });
334
311
  }
335
- return _objectSpread(_objectSpread({}, prev), changes);
312
+ return _objectSpread$1(_objectSpread$1({}, prev), changes);
336
313
  });
337
314
  const __validateInput = (input, inputValidator, validityKey, setValidity) => {
338
315
  const fields = getState().fields;
339
316
  for (const index in inputValidator.constraintHandlers) {
340
- const result = inputValidator.constraintHandlers[index](input, validityKey);
317
+ const handler = inputValidator.constraintHandlers[index];
318
+ const result = handler(input, validityKey);
341
319
  input.error = _checkResult(result, input.value);
342
320
  if (input.error) return;
343
321
  }
344
322
  for (const index in inputValidator.handlers) {
345
- const result = inputValidator.handlers[index](input, fields);
323
+ const handler = inputValidator.handlers[index];
324
+ const result = handler(input, fields);
346
325
  input.error = _checkResult(result, input.value);
347
326
  if (input.error) return;
348
327
  }
@@ -352,7 +331,8 @@ const useFormHandlers = (getState, setState, validators = {}, optimized = false)
352
331
  _debounce(input.debounce || 300, `${input.gid}-async`).then(() => {
353
332
  const validateAsync = async () => {
354
333
  for (const index in inputValidator.asyncHandlers) {
355
- const result = await inputValidator.asyncHandlers[index](input, fields);
334
+ const handler = inputValidator.asyncHandlers[index];
335
+ const result = await handler(input, fields);
356
336
  input.error = _checkResult(result, input.value);
357
337
  if (input.error) break;
358
338
  }
@@ -369,10 +349,6 @@ const useFormHandlers = (getState, setState, validators = {}, optimized = false)
369
349
  });
370
350
  }
371
351
  };
372
- const hasCustomValidation = input => {
373
- const validator = validators[input.validatorKey || input.formKey] || validators['*'];
374
- return validator && (validator.asyncHandlers.length > 0 || validator.handlers.length > 0);
375
- };
376
352
  return {
377
353
  _updateInputHandler,
378
354
  _viHandler,
@@ -382,12 +358,17 @@ const useFormHandlers = (getState, setState, validators = {}, optimized = false)
382
358
  };
383
359
  };
384
360
 
361
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
362
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return (String )(t); }
363
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
364
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
385
365
  const GFormContext = createContext({});
386
366
  const GFormContextProvider = ({
387
367
  children,
388
368
  initialState,
389
369
  validators,
390
- optimized
370
+ optimized,
371
+ formRef
391
372
  }) => {
392
373
  const stateRef = useRef(initialState);
393
374
  const listeners = useRef(null);
@@ -398,19 +379,56 @@ const GFormContextProvider = ({
398
379
  return;
399
380
  }
400
381
  stateRef.current = nextState;
401
- listeners.current.forEach(l => l());
382
+ listeners.current.forEach(listener => listener());
402
383
  }, []);
403
384
  const handlers = useFormHandlers(() => stateRef.current, setState, validators, optimized);
385
+ const getInputElement = useCallback(formKey => {
386
+ if (formRef && formRef.current) {
387
+ return formRef.current[formKey];
388
+ }
389
+ }, []);
390
+ const registerField = useCallback(config => {
391
+ const prev = stateRef.current;
392
+ if (prev.fields[config.formKey]) {
393
+ {
394
+ console.warn(`DEV ONLY - [Duplicate Keys] - field with key '${config.formKey}' already defined.`);
395
+ }
396
+ return;
397
+ }
398
+ const inputState = _buildInputInitialValues(config);
399
+ stateRef.current = _objectSpread(_objectSpread({}, prev), {}, {
400
+ fields: _objectSpread(_objectSpread({}, prev.fields), {}, {
401
+ [config.formKey]: _objectSpread(_objectSpread({}, inputState), {}, {
402
+ dispatchChanges: changes => handlers._dispatchChanges(changes, config.formKey)
403
+ })
404
+ })
405
+ });
406
+ }, [handlers]);
407
+ const unregisterField = useCallback(formKey => {
408
+ const prev = stateRef.current;
409
+ if (!prev.fields[formKey]) return;
410
+ const _prev$fields = prev.fields,
411
+ {
412
+ [formKey]: _
413
+ } = _prev$fields,
414
+ remainingFields = _objectWithoutProperties(_prev$fields, [formKey].map(_toPropertyKey));
415
+ stateRef.current = _objectSpread(_objectSpread({}, prev), {}, {
416
+ fields: remainingFields
417
+ });
418
+ listeners.current.forEach(listener => listener());
419
+ }, []);
404
420
  const store = useMemo(() => {
405
421
  if (!listeners.current) {
406
422
  listeners.current = new Set();
423
+ stateRef.current = initialState;
424
+ for (const fieldKey in initialState.fields) {
425
+ initialState.fields[fieldKey].dispatchChanges = changes => handlers._dispatchChanges(changes, fieldKey);
426
+ }
407
427
  } else {
408
428
  listeners.current.clear();
409
- _copyStateFields(stateRef.current, initialState);
410
- }
411
- stateRef.current = initialState;
412
- for (const fieldKey in initialState.fields) {
413
- initialState.fields[fieldKey].dispatchChanges = changes => handlers._dispatchChanges(changes, fieldKey);
429
+ for (const fieldKey in stateRef.current.fields) {
430
+ stateRef.current.fields[fieldKey].dispatchChanges = changes => handlers._dispatchChanges(changes, fieldKey);
431
+ }
414
432
  }
415
433
  return {
416
434
  getState: () => stateRef.current,
@@ -419,7 +437,10 @@ const GFormContextProvider = ({
419
437
  listeners.current.add(listener);
420
438
  return () => listeners.current.delete(listener);
421
439
  },
422
- handlers
440
+ handlers,
441
+ registerField,
442
+ unregisterField,
443
+ getInputElement
423
444
  };
424
445
  }, [initialState]);
425
446
  return React.createElement(GFormContext.Provider, {
@@ -428,7 +449,7 @@ const GFormContextProvider = ({
428
449
  };
429
450
  const useFormStore = () => {
430
451
  const store = useContext(GFormContext);
431
- if (!store.getState) throw new Error('useGFormStore must be used within `GForm` component');
452
+ if (!store.getState) throw new Error('useFormStore must be used within `GForm` component');
432
453
  return store;
433
454
  };
434
455
  const useFormSelector = selector => {
@@ -449,5 +470,5 @@ function createSelector(selectors, combiner) {
449
470
  };
450
471
  }
451
472
 
452
- export { GFormContextProvider as G, _buildRNFormState as _, useFormSelector as a, _buildFormInitialValues as b, _merge as c, createSelector as d, _debounce as e, useFormStore as u };
473
+ export { GFormContextProvider as G, _buildRNFormState as _, useFormSelector as a, _merge as b, createSelector as c, _debounce as d, useFormStore as u };
453
474
  //# sourceMappingURL=shared.development.js.map