@bombillazo/rhf-plus 7.64.0-plus.1 → 7.65.0-plus.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.
package/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export * from './useFormContext';
9
9
  export * from './useFormState';
10
10
  export * from './useWatch';
11
11
  export * from './utils';
12
+ export * from './watch';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -976,7 +976,7 @@ function markFieldsDirty(data, fields = {}) {
976
976
  fields[key] = Array.isArray(data[key]) ? [] : {};
977
977
  markFieldsDirty(data[key], fields[key]);
978
978
  }
979
- else if (!isNullOrUndefined(data[key])) {
979
+ else if (!isUndefined(data[key])) {
980
980
  fields[key] = true;
981
981
  }
982
982
  }
@@ -1258,25 +1258,13 @@ var updateFieldArrayRootError = (errors, error, name) => {
1258
1258
  return errors;
1259
1259
  };
1260
1260
 
1261
- var isMessage = (value) => {
1262
- // Support strings (existing functionality)
1263
- if (isString(value)) {
1264
- return true;
1265
- }
1266
- // Support React elements only (not primitives like null, undefined, numbers)
1267
- if (React.isValidElement(value)) {
1268
- return true;
1269
- }
1270
- return false;
1271
- };
1272
-
1273
1261
  function getValidateError(result, ref, type = 'validate') {
1274
- if (isMessage(result) ||
1275
- (Array.isArray(result) && result.every(isMessage)) ||
1262
+ if (isString(result) ||
1263
+ (Array.isArray(result) && result.every(isString)) ||
1276
1264
  (isBoolean(result) && !result)) {
1277
1265
  return {
1278
1266
  type,
1279
- message: isMessage(result) ? result : '',
1267
+ message: isString(result) ? result : '',
1280
1268
  ref,
1281
1269
  };
1282
1270
  }
@@ -1298,16 +1286,7 @@ var validateField = async (field, skippedFieldNames, formValues, validateAllFiel
1298
1286
  const inputRef = refs ? refs[0] : ref;
1299
1287
  const setCustomValidity = (message) => {
1300
1288
  if (shouldUseNativeValidation && inputRef.reportValidity) {
1301
- if (isBoolean(message)) {
1302
- inputRef.setCustomValidity('');
1303
- }
1304
- else if (typeof message === 'string') {
1305
- inputRef.setCustomValidity(message || '');
1306
- }
1307
- else {
1308
- // For ReactNode messages, convert to string or use empty string for native validation
1309
- inputRef.setCustomValidity('');
1310
- }
1289
+ inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
1311
1290
  inputRef.reportValidity();
1312
1291
  }
1313
1292
  };
@@ -1338,7 +1317,7 @@ var validateField = async (field, skippedFieldNames, formValues, validateAllFiel
1338
1317
  (isBoolean(inputValue) && !inputValue) ||
1339
1318
  (isCheckBox && !getCheckboxValue(refs).isValid) ||
1340
1319
  (isRadio && !getRadioValue(refs).isValid))) {
1341
- const { value, message } = isMessage(required)
1320
+ const { value, message } = isString(required)
1342
1321
  ? { value: !!required, message: required }
1343
1322
  : getValueAndMessage(required);
1344
1323
  if (value) {
@@ -2913,7 +2892,8 @@ function useFieldArray(props) {
2913
2892
  const _actioned = React.useRef(false);
2914
2893
  control._names.array.add(name);
2915
2894
  React.useMemo(() => rules &&
2916
- control.register(name, rules), [control, rules, name]);
2895
+ fields.length >= 0 &&
2896
+ control.register(name, rules), [control, name, fields.length, rules]);
2917
2897
  useIsomorphicLayoutEffect(() => control._subjects.array.subscribe({
2918
2898
  next: ({ values, name: fieldArrayName, }) => {
2919
2899
  if (fieldArrayName === name || !fieldArrayName) {
@@ -3276,5 +3256,29 @@ function useForm(props = {}) {
3276
3256
  return _formControl.current;
3277
3257
  }
3278
3258
 
3279
- export { Controller, Form, FormProvider, appendErrors, createFormControl, get, set, submitForm as submit, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
3259
+ /**
3260
+ * Watch component that subscribes to form field changes and re-renders when watched fields update.
3261
+ *
3262
+ * @param control - The form control object from useForm
3263
+ * @param names - Array of field names to watch for changes
3264
+ * @param render - The function that receives watched values and returns ReactNode
3265
+ * @returns The result of calling render function with watched values
3266
+ *
3267
+ * @example
3268
+ * The `Watch` component only re-render when the values of `foo`, `bar`, and `baz.qux` change.
3269
+ * The types of `foo`, `bar`, and `baz.qux` are precisely inferred.
3270
+ *
3271
+ * ```tsx
3272
+ * const { control } = useForm();
3273
+ *
3274
+ * <Watch
3275
+ * control={control}
3276
+ * names={['foo', 'bar', 'baz.qux']}
3277
+ * render={([foo, bar, baz_qux]) => <div>{foo}{bar}{baz_qux}</div>}
3278
+ * />
3279
+ * ```
3280
+ */
3281
+ const Watch = ({ control, names, render, }) => render(useWatch({ control, name: names }));
3282
+
3283
+ export { Controller, Form, FormProvider, Watch, appendErrors, createFormControl, get, set, submitForm as submit, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
3280
3284
  //# sourceMappingURL=index.esm.mjs.map