react-f0rm 0.5.1 → 0.6.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
@@ -1,6 +1,6 @@
1
- import { a as FieldPath, N as Name, F as Form$1, P as PathValueOf, b as FieldError, c as Path, O as Options } from './form-rTlcIiWH.js';
2
- export { d as FieldErrorEntry, e as FieldState, H as HandleSubmitOptions, f as PathValue, R as ReValidateMode, g as ResetFieldOptions, h as ResetOptions, S as SetFieldOptions, i as SetFocusOptions, j as SetServerErrorsOptions, V as VALIDATION_OUTCOME, k as ValidateResult, l as ValidationMode, m as ValidationOutcome, n as clearErrors, o as createForm, p as ensureValidate, q as getDirtyFields, r as getError, s as getErrorByPath, t as getErrors, u as getFieldErrors, v as getFieldErrorsByPath, w as getFieldState, x as getFirstError, y as getTouchedFields, z as getValue, A as getValueByPath, B as getValues, C as handleSubmit, D as hasErrors, E as hasTouched, G as hasTouchedByPath, I as incrementSubmitCount, J as isDirty, K as isTouched, L as removeField, M as removeFieldByPath, Q as reset, T as resetField, U as setDisabled, W as setError, X as setErrorByPath, Y as setFocus, Z as setInitialValues, _ as setIsSubmitting, $ as setServerErrors, a0 as setSubmitSuccessful, a1 as setTouched, a2 as setTouchedByPath, a3 as setValidatingByPath, a4 as setValue, a5 as setValueByPath, a6 as trigger, a7 as unsetValidatingByPath, a8 as validate } from './form-rTlcIiWH.js';
3
- import { V as Validator } from './validate-CQX7BJOD.js';
1
+ import { a as FieldPath, N as Name, F as Form$1, V as ValidationMode, P as PathValueOf, b as FieldError, c as Path, O as Options } from './form-D9COEt0-.js';
2
+ export { d as FieldErrorEntry, e as FieldState, H as HandleSubmitOptions, f as PathValue, R as ReValidateMode, g as ResetFieldOptions, h as ResetOptions, S as SetFieldOptions, i as SetFocusOptions, j as SetServerErrorsOptions, k as VALIDATION_OUTCOME, l as ValidateResult, m as ValidationOutcome, n as clearErrors, o as createForm, p as ensureValidate, q as getDirtyFields, r as getError, s as getErrorByPath, t as getErrors, u as getFieldErrors, v as getFieldErrorsByPath, w as getFieldState, x as getFirstError, y as getTouchedFields, z as getValue, A as getValueByPath, B as getValues, C as handleSubmit, D as hasErrors, E as hasTouched, G as hasTouchedByPath, I as incrementSubmitCount, J as isDirty, K as isTouched, L as removeField, M as removeFieldByPath, Q as reset, T as resetField, U as setDisabled, W as setError, X as setErrorByPath, Y as setFocus, Z as setInitialValues, _ as setIsSubmitting, $ as setServerErrors, a0 as setSubmitSuccessful, a1 as setTouched, a2 as setTouchedByPath, a3 as setValidatingByPath, a4 as setValue, a5 as setValueByPath, a6 as trigger, a7 as unsetValidatingByPath, a8 as validate } from './form-D9COEt0-.js';
3
+ import { V as Validator } from './validate-Cu43SqhV.js';
4
4
  import * as React from 'react';
5
5
  import { ReactNode } from 'react';
6
6
  import { EventEmitter } from '@for-fun/event-emitter';
@@ -78,6 +78,17 @@ interface UseFieldOptions$1<TValues extends Record<string, any> = any, TPath ext
78
78
  * `disabled`. A field cannot opt out of a disabled form.
79
79
  */
80
80
  disabled?: boolean;
81
+ /**
82
+ * Field-level validation mode override: when given, this field validates
83
+ * on its own schedule instead of `form.mode` — every other field keeps
84
+ * the form-level timing (e.g. a form that defaults to `'onSubmit'` with
85
+ * one field declared `'onBlur'` shows that field's error on blur while
86
+ * the rest wait for submit). `reValidateMode` stays form-level: once any
87
+ * field has an error (after a failed submit, say), re-validation follows
88
+ * the form's `reValidateMode` for every field, overriding this one too.
89
+ * See {@link ValidationMode}.
90
+ */
91
+ mode?: ValidationMode;
81
92
  }
82
93
  /**
83
94
  * The result of {@link useField}. Deliberately a closed shape: no index
@@ -421,6 +432,14 @@ interface UseFieldOptions<TValues extends Record<string, any> = any, TPath exten
421
432
  * changes apply immediately. Passed through to useField.
422
433
  */
423
434
  delayError?: number;
435
+ /**
436
+ * Field-level validation mode override: this field validates on its own
437
+ * schedule instead of the form's `mode` (other fields are unaffected);
438
+ * the form's `reValidateMode` still governs re-validation once the
439
+ * field has an error. Passed through to useField, never spread onto
440
+ * the DOM element.
441
+ */
442
+ mode?: ValidationMode;
424
443
  [key: string]: any;
425
444
  }
426
445
  interface FieldProps<TValues extends Record<string, any> = any, TPath extends FieldPath<TValues> | Name = Name> extends UseFieldOptions<TValues, TPath> {
@@ -484,5 +503,5 @@ interface SelectComponent {
484
503
  }
485
504
  declare const Select: SelectComponent;
486
505
 
487
- export { Checkbox, CheckboxGroupContext, CheckboxGroupProvider, Field, FieldError, FieldPath, Form, FormContext, Form$1 as FormInstance, FormProvider, Name, Options, Path, PathValueOf, Select, Validator, createFormContext, fieldErrorId, subscribe, useCheckboxGroupContext, useDirtyFields, useError, useErrorByPath, useField, useFieldArray, useFieldErrors, useFieldErrorsByPath, useForm, useFormContext, useHasErrors, useIsDirty, useIsSubmitting, useSubmitCount, useTouched, useTouchedByPath, useTouchedFields, useValue, useValueByPath, useWatch };
506
+ export { Checkbox, CheckboxGroupContext, CheckboxGroupProvider, Field, FieldError, FieldPath, Form, FormContext, Form$1 as FormInstance, FormProvider, Name, Options, Path, PathValueOf, Select, ValidationMode, Validator, createFormContext, fieldErrorId, subscribe, useCheckboxGroupContext, useDirtyFields, useError, useErrorByPath, useField, useFieldArray, useFieldErrors, useFieldErrorsByPath, useForm, useFormContext, useHasErrors, useIsDirty, useIsSubmitting, useSubmitCount, useTouched, useTouchedByPath, useTouchedFields, useValue, useValueByPath, useWatch };
488
507
  export type { FieldRules, SubscribeEvent, SubscribeOptions, WatchScope };
package/dist/index.mjs CHANGED
@@ -1260,7 +1260,8 @@ function useFieldCore({
1260
1260
  rules,
1261
1261
  validateDebounce,
1262
1262
  delayError,
1263
- disabled
1263
+ disabled,
1264
+ mode: modeOption
1264
1265
  }, Context) {
1265
1266
  const contextForm = useContext(Context);
1266
1267
  const form = f1 || contextForm;
@@ -1280,6 +1281,7 @@ function useFieldCore({
1280
1281
  const error = errorObject?.message;
1281
1282
  const value = useValueByPath(form, path);
1282
1283
  const formDisabled = useWatch(form.emitter, "disabled", () => form.disabled);
1284
+ const mode = modeOption ?? form.mode;
1283
1285
  useEffect(() => {
1284
1286
  if (initialValue === void 0) return;
1285
1287
  if (getValueByPath(form, path) === void 0) {
@@ -1288,12 +1290,12 @@ function useFieldCore({
1288
1290
  }, [form, path, initialValue]);
1289
1291
  const onChange = useStageFn((v) => {
1290
1292
  setValueByPath(form, path, v);
1291
- if (form.mode === "onChange" || form.mode === "all" || form.mode === "onTouched" && hasTouchedByPath(form, path) || liveErrors.length > 0 && form.reValidateMode === "onChange")
1293
+ if (mode === "onChange" || mode === "all" || mode === "onTouched" && hasTouchedByPath(form, path) || liveErrors.length > 0 && form.reValidateMode === "onChange")
1292
1294
  validator();
1293
1295
  });
1294
1296
  const onBlur = useStageFn(() => {
1295
1297
  setTouchedByPath(form, path);
1296
- if (form.mode === "onBlur" || form.mode === "onTouched" || form.mode === "all" || liveErrors.length > 0 && form.reValidateMode === "onBlur")
1298
+ if (mode === "onBlur" || mode === "onTouched" || mode === "all" || liveErrors.length > 0 && form.reValidateMode === "onBlur")
1297
1299
  validator();
1298
1300
  });
1299
1301
  useEffect(
@@ -1512,6 +1514,7 @@ const Field = React.forwardRef(
1512
1514
  validateDebounce,
1513
1515
  disabled,
1514
1516
  delayError,
1517
+ mode,
1515
1518
  ...props
1516
1519
  }, ref) => {
1517
1520
  const innerRef = React.useRef(null);
@@ -1540,6 +1543,7 @@ const Field = React.forwardRef(
1540
1543
  validateDebounce,
1541
1544
  delayError,
1542
1545
  disabled,
1546
+ mode,
1543
1547
  validate: (...params) => {
1544
1548
  const el = innerRef.current;
1545
1549
  if (el && typeof el.checkValidity === "function") {
@@ -1613,6 +1617,7 @@ const Checkbox = React.forwardRef(
1613
1617
  validateDebounce,
1614
1618
  disabled,
1615
1619
  delayError,
1620
+ mode,
1616
1621
  ...props
1617
1622
  }, ref) => {
1618
1623
  const {
@@ -1631,7 +1636,8 @@ const Checkbox = React.forwardRef(
1631
1636
  rules,
1632
1637
  validateDebounce,
1633
1638
  delayError,
1634
- disabled
1639
+ disabled,
1640
+ mode
1635
1641
  });
1636
1642
  return /* @__PURE__ */ React.createElement(
1637
1643
  "input",
@@ -1667,6 +1673,7 @@ const Select = React.forwardRef(
1667
1673
  validateDebounce,
1668
1674
  disabled,
1669
1675
  delayError,
1676
+ mode,
1670
1677
  ...props
1671
1678
  }, ref) => {
1672
1679
  const {
@@ -1685,7 +1692,8 @@ const Select = React.forwardRef(
1685
1692
  rules,
1686
1693
  validateDebounce,
1687
1694
  delayError,
1688
- disabled
1695
+ disabled,
1696
+ mode
1689
1697
  });
1690
1698
  return /* @__PURE__ */ React.createElement(
1691
1699
  "select",