@bombillazo/rhf-plus 7.56.3-plus.0 → 7.56.3-plus.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { FieldValues, UseFormProps, UseFormReturn } from '../types';
2
- export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>(props?: UseFormProps<TFieldValues, TContext, TTransformedValues>): Omit<UseFormReturn<TFieldValues, TContext, TTransformedValues>, 'formState'> & {
3
- formControl: Omit<UseFormReturn<TFieldValues, TContext, TTransformedValues>, 'formState'>;
1
+ import { FieldValues, FormMetadata, UseFormProps, UseFormReturn } from '../types';
2
+ export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues, TMetadata extends FormMetadata = any>(props?: UseFormProps<TFieldValues, TContext, TTransformedValues, TMetadata>): Omit<UseFormReturn<TFieldValues, TContext, TTransformedValues, TMetadata>, 'formState'> & {
3
+ formControl: Omit<UseFormReturn<TFieldValues, TContext, TTransformedValues, TMetadata>, 'formState'>;
4
4
  };
5
5
  //# sourceMappingURL=createFormControl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,EAaL,WAAW,EAgBX,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAsDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAi6CA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,EAaL,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAuDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,CAo9CA"}
@@ -154,6 +154,25 @@ function deepEqual(object1, object2) {
154
154
  return true;
155
155
  }
156
156
 
157
+ function deepMerge(target, source) {
158
+ if (isPrimitive(target) || isPrimitive(source)) {
159
+ return source;
160
+ }
161
+ for (const key in source) {
162
+ const targetValue = target[key];
163
+ const sourceValue = source[key];
164
+ try {
165
+ target[key] =
166
+ (isObject(targetValue) && isObject(sourceValue)) ||
167
+ (Array.isArray(targetValue) && Array.isArray(sourceValue))
168
+ ? deepMerge(targetValue, sourceValue)
169
+ : sourceValue;
170
+ }
171
+ catch (_a) { }
172
+ }
173
+ return target;
174
+ }
175
+
157
176
  var isUndefined = (val) => val === undefined;
158
177
 
159
178
  var get = (object, path, defaultValue) => {
@@ -783,11 +802,12 @@ function createFormControl(props = {}) {
783
802
  ...defaultOptions,
784
803
  ...props,
785
804
  };
805
+ let _internalLoading = _options.isLoading || isFunction(_options.defaultValues);
786
806
  let _formState = {
787
807
  submitCount: 0,
788
808
  isDirty: false,
789
809
  isReady: false,
790
- isLoading: isFunction(_options.defaultValues),
810
+ isLoading: _internalLoading,
791
811
  isValidating: false,
792
812
  isSubmitted: false,
793
813
  isSubmitting: false,
@@ -798,6 +818,7 @@ function createFormControl(props = {}) {
798
818
  validatingFields: {},
799
819
  errors: _options.errors || {},
800
820
  disabled: _options.disabled || false,
821
+ metadata: _options.defaultMetadata || {},
801
822
  };
802
823
  const _fields = {};
803
824
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
@@ -839,6 +860,7 @@ function createFormControl(props = {}) {
839
860
  const validationModeBeforeSubmit = getValidationModes(_options.mode);
840
861
  const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
841
862
  const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
863
+ const id = createId(props.id);
842
864
  const debounce = (callback) => (wait) => {
843
865
  clearTimeout(timer);
844
866
  timer = setTimeout(callback, wait);
@@ -1728,11 +1750,50 @@ function createFormControl(props = {}) {
1728
1750
  _subjects.state.next({
1729
1751
  isLoading: false,
1730
1752
  });
1753
+ _internalLoading = false;
1731
1754
  });
1732
- const id = createId(props.id);
1733
1755
  const submit = () => {
1734
1756
  submitForm(id);
1735
1757
  };
1758
+ const _updateIsLoading = (isLoading) => {
1759
+ if (!isUndefined(isLoading)) {
1760
+ const _loading = isLoading || _internalLoading;
1761
+ if (_formState.isLoading !== _loading) {
1762
+ _formState.isLoading = _loading;
1763
+ _subjects.state.next({
1764
+ isLoading: _loading,
1765
+ });
1766
+ }
1767
+ }
1768
+ else if (!!isLoading !== _formState.isLoading) {
1769
+ _formState.isLoading = _internalLoading;
1770
+ _subjects.state.next({
1771
+ isLoading: _internalLoading,
1772
+ });
1773
+ }
1774
+ };
1775
+ const setMetadata = (metadata) => {
1776
+ let _metadata;
1777
+ if (!metadata) {
1778
+ _metadata = _options.defaultMetadata
1779
+ ? cloneObject(_options.defaultMetadata)
1780
+ : {};
1781
+ }
1782
+ else {
1783
+ _metadata = metadata;
1784
+ }
1785
+ _formState.metadata = _metadata;
1786
+ _subjects.state.next({
1787
+ metadata: _metadata,
1788
+ });
1789
+ };
1790
+ const updateMetadata = (metadata) => {
1791
+ const _metadata = deepMerge(_formState.metadata, metadata);
1792
+ _formState.metadata = _metadata;
1793
+ _subjects.state.next({
1794
+ metadata: _metadata,
1795
+ });
1796
+ };
1736
1797
  const methods = {
1737
1798
  control: {
1738
1799
  register,
@@ -1753,6 +1814,7 @@ function createFormControl(props = {}) {
1753
1814
  _resetDefaultValues,
1754
1815
  _removeUnmounted,
1755
1816
  _disableForm,
1817
+ _updateIsLoading,
1756
1818
  _subjects,
1757
1819
  _proxyFormState,
1758
1820
  get _fields() {
@@ -1805,6 +1867,8 @@ function createFormControl(props = {}) {
1805
1867
  getFieldState,
1806
1868
  id,
1807
1869
  submit,
1870
+ setMetadata,
1871
+ updateMetadata,
1808
1872
  };
1809
1873
  return {
1810
1874
  ...methods,