use-mask-input 3.5.2 → 3.6.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 (39) hide show
  1. package/CHANGELOG.md +52 -74
  2. package/README.md +2 -251
  3. package/dist/index.cjs +1067 -1146
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +52 -11
  6. package/dist/index.d.ts +52 -11
  7. package/dist/index.js +1068 -1147
  8. package/dist/index.js.map +1 -1
  9. package/package.json +22 -22
  10. package/src/api/index.ts +4 -0
  11. package/src/api/useHookFormMask.spec.ts +146 -0
  12. package/src/api/useHookFormMask.ts +56 -0
  13. package/src/api/useMaskInput-server.spec.tsx +30 -0
  14. package/src/api/useMaskInput.spec.tsx +220 -0
  15. package/src/api/useMaskInput.ts +64 -0
  16. package/src/api/withHookFormMask.spec.ts +155 -0
  17. package/src/api/withHookFormMask.ts +54 -0
  18. package/src/api/withMask.spec.ts +93 -0
  19. package/src/api/withMask.ts +25 -0
  20. package/src/core/elementResolver.spec.ts +175 -0
  21. package/src/core/elementResolver.ts +84 -0
  22. package/src/core/index.ts +3 -0
  23. package/src/core/maskConfig.spec.ts +183 -0
  24. package/src/{utils/getMaskOptions.ts → core/maskConfig.ts} +13 -4
  25. package/src/core/maskEngine.spec.ts +108 -0
  26. package/src/core/maskEngine.ts +47 -0
  27. package/src/index.tsx +12 -5
  28. package/src/{types.ts → types/index.ts} +13 -0
  29. package/src/utils/flow.spec.ts +27 -30
  30. package/src/utils/flow.ts +2 -2
  31. package/src/utils/index.ts +1 -1
  32. package/src/utils/isServer.spec.ts +15 -0
  33. package/src/utils/moduleInterop.spec.ts +37 -0
  34. package/src/useHookFormMask.ts +0 -47
  35. package/src/useMaskInput.ts +0 -41
  36. package/src/utils/getMaskOptions.spec.ts +0 -126
  37. package/src/withHookFormMask.ts +0 -34
  38. package/src/withMask.ts +0 -18
  39. /package/src/{inputmask.types.ts → types/inputmask.types.ts} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { UseFormRegisterReturn, FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
1
+ import { RefCallback } from 'react';
2
+ import { FieldValues, UseFormRegisterReturn, Path, RegisterOptions, UseFormRegister } from 'react-hook-form';
2
3
  export { UseFormRegister, UseFormRegisterReturn } from 'react-hook-form';
3
- import { RefObject } from 'react';
4
4
 
5
5
  type Range = {
6
6
  start: string;
@@ -576,18 +576,59 @@ interface CommandObject {
576
576
  type Mask = 'datetime' | 'email' | 'numeric' | 'currency' | 'decimal' | 'integer' | 'percentage' | 'url' | 'ip' | 'mac' | 'ssn' | 'brl-currency' | 'cpf' | 'cnpj' | (string & {}) | (string[] & {}) | null;
577
577
  type Options = Options$1;
578
578
  type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement;
579
+ interface UseHookFormMaskReturn<T extends FieldValues> extends UseFormRegisterReturn<Path<T>> {
580
+ ref: RefCallback<HTMLElement | null>;
581
+ prevRef: RefCallback<HTMLElement | null>;
582
+ }
579
583
 
580
- declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseFormRegisterReturn;
581
-
582
- declare function withMask(mask: Mask, options?: Options): (input: Input | null) => void;
583
-
584
- declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseFormRegisterReturn<Path<T>>;
585
-
586
- interface UseInputMaskOptions {
584
+ interface UseMaskInputOptions {
587
585
  mask: Mask;
588
586
  register?: (element: HTMLElement) => void;
589
587
  options?: Options;
590
588
  }
591
- declare function useInputMask(props: UseInputMaskOptions): RefObject<HTMLInputElement>;
589
+ /**
590
+ * React hook for applying input masks to form elements.
591
+ * Works with Ant Design and other wrapped components too.
592
+ *
593
+ * @param props - Configuration object
594
+ * @param props.mask - The mask pattern to apply
595
+ * @param props.register - Optional callback that receives the element
596
+ * @param props.options - Optional mask configuration options
597
+ * @returns A ref callback function to attach to the input element
598
+ */
599
+ declare function useMaskInput(props: UseMaskInputOptions): ((input: Input | null) => void);
600
+
601
+ /**
602
+ * Creates a masked version of React Hook Form's register function.
603
+ * Takes react-hook-form's register and adds automatic masking. Like an upgrade.
604
+ *
605
+ * @template T - The form data type
606
+ * @template D - The register options type
607
+ * @param registerFn - The register function from useForm hook
608
+ * @returns A function that registers a field with mask support
609
+ */
610
+ declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseHookFormMaskReturn<T>;
611
+
612
+ /**
613
+ * Higher-order function that creates a ref callback for applying input masks.
614
+ * Simple function to apply mask via ref. No hooks, no drama.
615
+ *
616
+ * @param mask - The mask pattern to apply
617
+ * @param options - Optional mask configuration options
618
+ * @returns A ref callback function that applies the mask
619
+ */
620
+ declare function withMask(mask: Mask, options?: Options): (input: Input | null) => void;
621
+
622
+ /**
623
+ * Enhances a React Hook Form register return object with mask support.
624
+ * Takes an already registered field and adds mask to it.
625
+ * Useful when you registered the field before.
626
+ *
627
+ * @param register - The register return object from React Hook Form
628
+ * @param mask - The mask pattern to apply
629
+ * @param options - Optional mask configuration options
630
+ * @returns A new register return object with mask applied
631
+ */
632
+ declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseHookFormMaskReturn<FieldValues>;
592
633
 
593
- export { type Mask, type Options, useHookFormMask, useInputMask as useMaskInput, withHookFormMask, withMask };
634
+ export { type Input, type Mask, type Options, useHookFormMask, useMaskInput, withHookFormMask, withMask };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { UseFormRegisterReturn, FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
1
+ import { RefCallback } from 'react';
2
+ import { FieldValues, UseFormRegisterReturn, Path, RegisterOptions, UseFormRegister } from 'react-hook-form';
2
3
  export { UseFormRegister, UseFormRegisterReturn } from 'react-hook-form';
3
- import { RefObject } from 'react';
4
4
 
5
5
  type Range = {
6
6
  start: string;
@@ -576,18 +576,59 @@ interface CommandObject {
576
576
  type Mask = 'datetime' | 'email' | 'numeric' | 'currency' | 'decimal' | 'integer' | 'percentage' | 'url' | 'ip' | 'mac' | 'ssn' | 'brl-currency' | 'cpf' | 'cnpj' | (string & {}) | (string[] & {}) | null;
577
577
  type Options = Options$1;
578
578
  type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement;
579
+ interface UseHookFormMaskReturn<T extends FieldValues> extends UseFormRegisterReturn<Path<T>> {
580
+ ref: RefCallback<HTMLElement | null>;
581
+ prevRef: RefCallback<HTMLElement | null>;
582
+ }
579
583
 
580
- declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseFormRegisterReturn;
581
-
582
- declare function withMask(mask: Mask, options?: Options): (input: Input | null) => void;
583
-
584
- declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseFormRegisterReturn<Path<T>>;
585
-
586
- interface UseInputMaskOptions {
584
+ interface UseMaskInputOptions {
587
585
  mask: Mask;
588
586
  register?: (element: HTMLElement) => void;
589
587
  options?: Options;
590
588
  }
591
- declare function useInputMask(props: UseInputMaskOptions): RefObject<HTMLInputElement>;
589
+ /**
590
+ * React hook for applying input masks to form elements.
591
+ * Works with Ant Design and other wrapped components too.
592
+ *
593
+ * @param props - Configuration object
594
+ * @param props.mask - The mask pattern to apply
595
+ * @param props.register - Optional callback that receives the element
596
+ * @param props.options - Optional mask configuration options
597
+ * @returns A ref callback function to attach to the input element
598
+ */
599
+ declare function useMaskInput(props: UseMaskInputOptions): ((input: Input | null) => void);
600
+
601
+ /**
602
+ * Creates a masked version of React Hook Form's register function.
603
+ * Takes react-hook-form's register and adds automatic masking. Like an upgrade.
604
+ *
605
+ * @template T - The form data type
606
+ * @template D - The register options type
607
+ * @param registerFn - The register function from useForm hook
608
+ * @returns A function that registers a field with mask support
609
+ */
610
+ declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseHookFormMaskReturn<T>;
611
+
612
+ /**
613
+ * Higher-order function that creates a ref callback for applying input masks.
614
+ * Simple function to apply mask via ref. No hooks, no drama.
615
+ *
616
+ * @param mask - The mask pattern to apply
617
+ * @param options - Optional mask configuration options
618
+ * @returns A ref callback function that applies the mask
619
+ */
620
+ declare function withMask(mask: Mask, options?: Options): (input: Input | null) => void;
621
+
622
+ /**
623
+ * Enhances a React Hook Form register return object with mask support.
624
+ * Takes an already registered field and adds mask to it.
625
+ * Useful when you registered the field before.
626
+ *
627
+ * @param register - The register return object from React Hook Form
628
+ * @param mask - The mask pattern to apply
629
+ * @param options - Optional mask configuration options
630
+ * @returns A new register return object with mask applied
631
+ */
632
+ declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseHookFormMaskReturn<FieldValues>;
592
633
 
593
- export { type Mask, type Options, useHookFormMask, useInputMask as useMaskInput, withHookFormMask, withMask };
634
+ export { type Input, type Mask, type Options, useHookFormMask, useMaskInput, withHookFormMask, withMask };