use-mask-input 3.7.4 → 3.9.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/CHANGELOG.md +34 -0
- package/README.md +105 -29
- package/dist/antd.cjs +9 -9
- package/dist/antd.d.cts +1 -1
- package/dist/antd.d.ts +1 -1
- package/dist/antd.js +1 -1
- package/dist/{chunk-QCWLMMDI.js → chunk-ICLWBMH4.js} +21 -2
- package/dist/{chunk-QCWLMMDI.js.map → chunk-ICLWBMH4.js.map} +1 -1
- package/dist/{chunk-VK6LQ75W.cjs → chunk-X5SEJVSB.cjs} +21 -2
- package/dist/{chunk-VK6LQ75W.cjs.map → chunk-X5SEJVSB.cjs.map} +1 -1
- package/dist/{index-F3rlTTTe.d.cts → index-BoaVtWUr.d.cts} +13 -4
- package/dist/{index-F3rlTTTe.d.ts → index-BoaVtWUr.d.ts} +13 -4
- package/dist/index.cjs +92 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +80 -15
- package/dist/index.js.map +1 -1
- package/package.json +15 -25
- package/src/antd/useHookFormMaskAntd.spec.ts +2 -0
- package/src/antd/useMaskInputAntd.spec.tsx +3 -3
- package/src/api/index.ts +2 -0
- package/src/api/useHookFormMask.spec.ts +52 -5
- package/src/api/useHookFormMask.ts +49 -9
- package/src/api/useMaskInput.spec.tsx +11 -11
- package/src/api/useTanStackFormMask.ts +24 -0
- package/src/api/withHookFormMask.spec.ts +7 -7
- package/src/api/withMask.spec.ts +6 -6
- package/src/api/withTanStackFormMask.spec.ts +76 -0
- package/src/api/withTanStackFormMask.ts +64 -0
- package/src/core/maskConfig.spec.ts +24 -0
- package/src/core/maskConfig.ts +14 -0
- package/src/core/maskEngine.spec.ts +12 -6
- package/src/index.tsx +4 -0
- package/src/types/index.ts +14 -0
- package/src/types/inputmask.types.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
## [3.6.0](https://github.com/eduardoborges/use-mask-input/compare/3.5.2...3.6.0) (2026-01-13)
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 99e7a0a: Add TanStack Form integration: `useTanStackFormMask` and `withTanStackFormMask`, with types `TanStackFormInputProps` and `UseTanStackFormMaskReturn`. Documentation and a `tanstack-form-project` demo app were added; examples favor international-friendly masks (phone, email, postal).
|
|
8
|
+
|
|
9
|
+
## 3.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- eacce0f: feat: add Brazilian banking masks (br-bank-account and br-bank-agency)
|
|
14
|
+
|
|
15
|
+
Added two new mask aliases for Brazilian banking information:
|
|
16
|
+
|
|
17
|
+
- `br-bank-account`: Supports multiple Brazilian bank account formats including Bradesco, Itaú, Banco do Brasil, Caixa Econômica, Nubank, and more
|
|
18
|
+
- `br-bank-agency`: Handles Brazilian bank agency numbers with optional check digits
|
|
19
|
+
|
|
20
|
+
These masks automatically adapt to different account number formats used by major Brazilian banks, making it easier to handle banking data in forms.
|
|
21
|
+
|
|
22
|
+
Example usage:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
const accountMask = useMaskInput({ mask: "br-bank-account" });
|
|
26
|
+
const agencyMask = useMaskInput({ mask: "br-bank-agency" });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- a614d93: fix: sync DOM value after react-hook-form `reset()` in `useHookFormMask`
|
|
32
|
+
|
|
33
|
+
`reset()` in react-hook-form clears its internal field registry before re-rendering. On the subsequent render it returns a new ref callback that, when called, syncs the DOM to the reset value. Because `useHookFormMask` caches a stable ref, React never calls that new callback — leaving masked inputs stale after `reset()`.
|
|
34
|
+
|
|
35
|
+
Fixed by using a `useLayoutEffect` queue that replays the latest RHF ref callback against the stored element after each render. RHF's own guard makes this a no-op on normal re-renders; it only does real work after `reset()` clears the registry.
|
|
36
|
+
|
|
3
37
|
## 3.7.4
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,62 +1,138 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h1>🥸 use-mask-input</h1>
|
|
3
|
-
<
|
|
3
|
+
<p>Input masks for React. Works with React Hook Form, <strong>TanStack Form</strong>, Ant Design, and plain inputs.</p>
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/use-mask-input)
|
|
6
6
|
[](https://www.npmjs.com/package/use-mask-input)
|
|
7
|
-
[](https://bundlejs.com/?q=use-mask-input)
|
|
8
8
|
[](https://codecov.io/gh/eduardoborges/use-mask-input)
|
|
9
|
+
|
|
10
|
+
[](https://ko-fi.com/E1E71VQENQ)
|
|
9
11
|
</div>
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
**[Documentation](http://use-mask-input.eduardoborges.dev)** · **[API Reference](http://use-mask-input.eduardoborges.dev/api-reference)** · **[TanStack Form](http://use-mask-input.eduardoborges.dev/tanstack-form)** · **[Sponsor](https://ko-fi.com/E1E71VQENQ)**
|
|
12
16
|
|
|
13
|
-
## Features
|
|
14
|
-
- 🎯 Simple API
|
|
15
|
-
- 💎 Works like a charm with *Next.js*
|
|
16
|
-
- ✨ Compatible with [React Hook Form](https://github.com/react-hook-form/react-hook-form)
|
|
17
|
-
- 🏁 Compatible with [React Final Form](https://github.com/final-form/react-final-form)
|
|
18
17
|
## Install
|
|
19
18
|
|
|
20
19
|
```sh
|
|
21
|
-
npm
|
|
20
|
+
npm install use-mask-input
|
|
22
21
|
```
|
|
23
22
|
|
|
24
|
-
##
|
|
23
|
+
## Usage
|
|
25
24
|
|
|
26
|
-
```
|
|
27
|
-
import React from 'react'
|
|
25
|
+
```tsx
|
|
28
26
|
import { useMaskInput } from 'use-mask-input';
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
)
|
|
28
|
+
function PhoneInput() {
|
|
29
|
+
const ref = useMaskInput({ mask: '(99) 99999-9999' });
|
|
30
|
+
return <input ref={ref} />;
|
|
34
31
|
}
|
|
35
32
|
```
|
|
36
33
|
|
|
37
|
-
###
|
|
34
|
+
### With React Hook Form
|
|
38
35
|
|
|
39
|
-
```
|
|
40
|
-
import React from 'react';
|
|
36
|
+
```tsx
|
|
41
37
|
import { useForm } from 'react-hook-form';
|
|
42
38
|
import { useHookFormMask } from 'use-mask-input';
|
|
43
39
|
|
|
44
|
-
function
|
|
40
|
+
function MyForm() {
|
|
45
41
|
const { register, handleSubmit } = useForm();
|
|
46
42
|
const registerWithMask = useHookFormMask(register);
|
|
47
43
|
|
|
48
|
-
...
|
|
49
|
-
|
|
50
44
|
return (
|
|
51
|
-
<form onSubmit={
|
|
52
|
-
<input
|
|
53
|
-
|
|
54
|
-
required: true
|
|
55
|
-
})}
|
|
56
|
-
type="text"
|
|
57
|
-
/>
|
|
45
|
+
<form onSubmit={handleSubmit(console.log)}>
|
|
46
|
+
<input {...registerWithMask('phone', '(99) 99999-9999')} />
|
|
47
|
+
<input {...registerWithMask('email', 'email')} />
|
|
58
48
|
<button type="submit">Submit</button>
|
|
59
49
|
</form>
|
|
60
50
|
);
|
|
61
51
|
}
|
|
62
52
|
```
|
|
53
|
+
|
|
54
|
+
### With TanStack Form
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useForm } from '@tanstack/react-form';
|
|
58
|
+
import { useTanStackFormMask } from 'use-mask-input';
|
|
59
|
+
|
|
60
|
+
function MyForm() {
|
|
61
|
+
const maskField = useTanStackFormMask();
|
|
62
|
+
const form = useForm({
|
|
63
|
+
defaultValues: {
|
|
64
|
+
phone: '',
|
|
65
|
+
},
|
|
66
|
+
onSubmit: async ({ value }) => {
|
|
67
|
+
console.log(value);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<form
|
|
73
|
+
onSubmit={(event) => {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
event.stopPropagation();
|
|
76
|
+
void form.handleSubmit();
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<form.Field name="phone">
|
|
80
|
+
{(field) => {
|
|
81
|
+
const inputProps = maskField(
|
|
82
|
+
'(99) 99999-9999',
|
|
83
|
+
{
|
|
84
|
+
name: field.name,
|
|
85
|
+
value: field.state.value,
|
|
86
|
+
onBlur: field.handleBlur,
|
|
87
|
+
onChange: (event) => field.handleChange(event.target.value),
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return <input {...inputProps} placeholder="(00) 00000-0000" />;
|
|
92
|
+
}}
|
|
93
|
+
</form.Field>
|
|
94
|
+
</form>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### With Ant Design
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { Input } from 'antd';
|
|
103
|
+
import { useMaskInputAntd } from 'use-mask-input/antd';
|
|
104
|
+
|
|
105
|
+
function EmailInput() {
|
|
106
|
+
const ref = useMaskInputAntd({ mask: 'email' });
|
|
107
|
+
return <Input ref={ref} />;
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## APIs
|
|
112
|
+
|
|
113
|
+
| API | Description |
|
|
114
|
+
|-----|-------------|
|
|
115
|
+
| `useMaskInput` | Hook. Returns a ref callback. Default choice. |
|
|
116
|
+
| `useHookFormMask` | Hook. Wraps React Hook Form's `register`. |
|
|
117
|
+
| `useTanStackFormMask` | Hook. Adds mask to TanStack Form field input props. |
|
|
118
|
+
| `withMask` | Function. Ref callback. Requires `React.memo`. |
|
|
119
|
+
| `withHookFormMask` | Function. Mask for registered fields. Requires `React.memo`. |
|
|
120
|
+
| `withTanStackFormMask` | Function. Mask for TanStack input props. Requires `React.memo`. |
|
|
121
|
+
| `useMaskInputAntd` | Hook. `useMaskInput` for Ant Design. |
|
|
122
|
+
| `useHookFormMaskAntd` | Hook. `useHookFormMask` for Ant Design. |
|
|
123
|
+
|
|
124
|
+
## Built-in Aliases
|
|
125
|
+
|
|
126
|
+
`cpf` · `cnpj` · `br-bank-account` · `br-bank-agency` · `currency` · `brl-currency` · `datetime` · `email` · `numeric` · `decimal` · `integer` · `percentage` · `url` · `ip` · `mac` · `ssn`
|
|
127
|
+
|
|
128
|
+
## Works With
|
|
129
|
+
|
|
130
|
+
- **TanStack Form** (`useTanStackFormMask`, `withTanStackFormMask`). See the [TanStack Form guide](http://use-mask-input.eduardoborges.dev/tanstack-form).
|
|
131
|
+
- React Hook Form
|
|
132
|
+
- Ant Design (`use-mask-input/antd`)
|
|
133
|
+
- React Final Form
|
|
134
|
+
- Next.js / SSR
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
package/dist/antd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkX5SEJVSB_cjs = require('./chunk-X5SEJVSB.cjs');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
|
|
6
6
|
function useHookFormMaskAntd(registerFn) {
|
|
@@ -10,11 +10,11 @@ function useHookFormMaskAntd(registerFn) {
|
|
|
10
10
|
if (!registerFn) throw new Error("registerFn is required");
|
|
11
11
|
const registerReturn = registerFn(fieldName, options);
|
|
12
12
|
const { ref } = registerReturn;
|
|
13
|
-
const cacheKey =
|
|
13
|
+
const cacheKey = chunkX5SEJVSB_cjs.makeMaskCacheKey(fieldName, mask);
|
|
14
14
|
if (!refCache.has(cacheKey)) {
|
|
15
15
|
const refWithMask = (inputRef) => {
|
|
16
|
-
const element = inputRef ?
|
|
17
|
-
if (element)
|
|
16
|
+
const element = inputRef ? chunkX5SEJVSB_cjs.resolveInputRef(inputRef.input) : null;
|
|
17
|
+
if (element) chunkX5SEJVSB_cjs.applyMaskToElement(element, mask, options);
|
|
18
18
|
if (ref) ref(element);
|
|
19
19
|
};
|
|
20
20
|
refCache.set(cacheKey, refWithMask);
|
|
@@ -23,7 +23,7 @@ function useHookFormMaskAntd(registerFn) {
|
|
|
23
23
|
...registerReturn,
|
|
24
24
|
ref: refCache.get(cacheKey)
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
chunkX5SEJVSB_cjs.setPrevRef(result, ref);
|
|
27
27
|
return result;
|
|
28
28
|
};
|
|
29
29
|
}, [registerFn]);
|
|
@@ -41,17 +41,17 @@ function useMaskInputAntd(props) {
|
|
|
41
41
|
ref.current = null;
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
ref.current =
|
|
44
|
+
ref.current = chunkX5SEJVSB_cjs.resolveInputRef(input.input);
|
|
45
45
|
if (ref.current && ref.current !== maskedElementRef.current) {
|
|
46
|
-
|
|
46
|
+
chunkX5SEJVSB_cjs.withMask(maskRef.current, optionsRef.current)(ref.current);
|
|
47
47
|
maskedElementRef.current = ref.current;
|
|
48
48
|
}
|
|
49
49
|
}, []);
|
|
50
50
|
react.useEffect(() => {
|
|
51
|
-
if (
|
|
51
|
+
if (chunkX5SEJVSB_cjs.isServer_default || !ref.current || !register) return;
|
|
52
52
|
register(ref.current);
|
|
53
53
|
}, [register]);
|
|
54
|
-
if (
|
|
54
|
+
if (chunkX5SEJVSB_cjs.isServer_default) {
|
|
55
55
|
return () => {
|
|
56
56
|
};
|
|
57
57
|
}
|
package/dist/antd.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InputRef } from 'antd';
|
|
2
2
|
import { RefCallback } from 'react';
|
|
3
3
|
import { FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
|
|
4
|
-
import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-
|
|
4
|
+
import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-BoaVtWUr.cjs';
|
|
5
5
|
|
|
6
6
|
type UseHookFormMaskAntdReturn<T extends FieldValues> = Omit<UseHookFormMaskReturn<T>, 'ref'> & {
|
|
7
7
|
ref: RefCallback<InputRef | null>;
|
package/dist/antd.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InputRef } from 'antd';
|
|
2
2
|
import { RefCallback } from 'react';
|
|
3
3
|
import { FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
|
|
4
|
-
import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-
|
|
4
|
+
import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-BoaVtWUr.js';
|
|
5
5
|
|
|
6
6
|
type UseHookFormMaskAntdReturn<T extends FieldValues> = Omit<UseHookFormMaskReturn<T>, 'ref'> & {
|
|
7
7
|
ref: RefCallback<InputRef | null>;
|
package/dist/antd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { makeMaskCacheKey, setPrevRef, resolveInputRef, withMask, isServer_default, applyMaskToElement } from './chunk-
|
|
1
|
+
import { makeMaskCacheKey, setPrevRef, resolveInputRef, withMask, isServer_default, applyMaskToElement } from './chunk-ICLWBMH4.js';
|
|
2
2
|
import { useMemo, useRef, useCallback, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
function useHookFormMaskAntd(registerFn) {
|
|
@@ -3704,6 +3704,25 @@ var ALIAS_MASKS = {
|
|
|
3704
3704
|
cnpj: {
|
|
3705
3705
|
mask: ["A|9{2}.A|9{3}.A|9{3}/A|9{4}-9{2}"],
|
|
3706
3706
|
placeholder: "__.___.___/____-__"
|
|
3707
|
+
},
|
|
3708
|
+
"br-bank-account": {
|
|
3709
|
+
mask: [
|
|
3710
|
+
"9{4,10}[-]9",
|
|
3711
|
+
// Most common formats: 1234567-9, 12345678-9, 123456789-9, 1234567890-1
|
|
3712
|
+
"999999[-][9]",
|
|
3713
|
+
// Optional separator: 123456-7 or 1234567
|
|
3714
|
+
"[999]9{7,8}[-]9",
|
|
3715
|
+
// Caixa and Nu Pagamentos: (001)12345678-9 or (001)1234567-9
|
|
3716
|
+
"[9999]9{8}[-]9"
|
|
3717
|
+
// Caixa longer: (0001)12345678-9
|
|
3718
|
+
],
|
|
3719
|
+
placeholder: "",
|
|
3720
|
+
greedy: false
|
|
3721
|
+
},
|
|
3722
|
+
"br-bank-agency": {
|
|
3723
|
+
mask: "9{1,5}[-][9]",
|
|
3724
|
+
// Agency numbers: 1234, 12345, 1234-5
|
|
3725
|
+
placeholder: ""
|
|
3707
3726
|
}
|
|
3708
3727
|
};
|
|
3709
3728
|
function getMaskOptions(mask, _options) {
|
|
@@ -3842,5 +3861,5 @@ inputmask/dist/inputmask.js:
|
|
|
3842
3861
|
*/
|
|
3843
3862
|
|
|
3844
3863
|
export { applyMaskToElement, flow, isServer_default, makeMaskCacheKey, resolveInputRef, setPrevRef, withMask };
|
|
3845
|
-
//# sourceMappingURL=chunk-
|
|
3846
|
-
//# sourceMappingURL=chunk-
|
|
3864
|
+
//# sourceMappingURL=chunk-ICLWBMH4.js.map
|
|
3865
|
+
//# sourceMappingURL=chunk-ICLWBMH4.js.map
|