use-mask-input 3.10.0 → 3.10.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.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkDTC7JTZP_cjs = require('./chunk-DTC7JTZP.cjs');
3
+ var chunkPMBRAXS4_cjs = require('./chunk-PMBRAXS4.cjs');
4
4
  var react = require('react');
5
5
 
6
6
  function useMaskInput(props) {
@@ -8,25 +8,25 @@ function useMaskInput(props) {
8
8
  const ref = react.useRef(null);
9
9
  const maskRef = react.useRef(mask);
10
10
  const optionsRef = react.useRef(options);
11
- const unmaskedValue = react.useCallback(() => chunkDTC7JTZP_cjs.getUnmaskedValue(ref.current), []);
11
+ const unmaskedValue = react.useCallback(() => chunkPMBRAXS4_cjs.getUnmaskedValue(ref.current), []);
12
12
  const refCallback = react.useCallback((input) => {
13
13
  if (!input) {
14
14
  ref.current = null;
15
15
  return;
16
16
  }
17
- ref.current = chunkDTC7JTZP_cjs.resolveInputRef(input);
18
- chunkDTC7JTZP_cjs.withMask(maskRef.current, optionsRef.current)(ref.current);
17
+ ref.current = chunkPMBRAXS4_cjs.resolveInputRef(input);
18
+ chunkPMBRAXS4_cjs.withMask(maskRef.current, optionsRef.current)(ref.current);
19
19
  }, []);
20
20
  react.useEffect(() => {
21
- if (chunkDTC7JTZP_cjs.isServer_default || !ref.current || !register) return;
21
+ if (chunkPMBRAXS4_cjs.isServer_default || !ref.current || !register) return;
22
22
  register(ref.current);
23
23
  }, [register]);
24
- if (chunkDTC7JTZP_cjs.isServer_default) {
24
+ if (chunkPMBRAXS4_cjs.isServer_default) {
25
25
  const noop = (() => {
26
26
  });
27
- return chunkDTC7JTZP_cjs.setUnmaskedValue(noop, () => "");
27
+ return chunkPMBRAXS4_cjs.setUnmaskedValue(noop, () => "");
28
28
  }
29
- return chunkDTC7JTZP_cjs.setUnmaskedValue(refCallback, unmaskedValue);
29
+ return chunkPMBRAXS4_cjs.setUnmaskedValue(refCallback, unmaskedValue);
30
30
  }
31
31
  function useHookFormMask(registerFn) {
32
32
  const entryCacheRef = react.useRef(/* @__PURE__ */ new Map());
@@ -46,7 +46,7 @@ function useHookFormMask(registerFn) {
46
46
  if (!registerFn) throw new Error("registerFn is required");
47
47
  const registerReturn = registerFn(fieldName, options);
48
48
  const { ref } = registerReturn;
49
- const cacheKey = chunkDTC7JTZP_cjs.makeMaskCacheKey(fieldName, mask);
49
+ const cacheKey = chunkPMBRAXS4_cjs.makeMaskCacheKey(fieldName, mask);
50
50
  let entry = entryCacheRef.current.get(cacheKey);
51
51
  if (!entry) {
52
52
  const nextEntry = {
@@ -57,10 +57,10 @@ function useHookFormMask(registerFn) {
57
57
  };
58
58
  const applyMaskToRef = (_ref) => {
59
59
  nextEntry.element = _ref;
60
- if (_ref) chunkDTC7JTZP_cjs.applyMaskToElement(_ref, mask, options);
60
+ if (_ref) chunkPMBRAXS4_cjs.applyMaskToElement(_ref, mask, options);
61
61
  return _ref;
62
62
  };
63
- nextEntry.stableRef = nextEntry.latestRHFRef ? chunkDTC7JTZP_cjs.flow(applyMaskToRef, (_ref) => nextEntry.latestRHFRef?.(_ref)) : applyMaskToRef;
63
+ nextEntry.stableRef = nextEntry.latestRHFRef ? chunkPMBRAXS4_cjs.flow(applyMaskToRef, (_ref) => nextEntry.latestRHFRef?.(_ref)) : applyMaskToRef;
64
64
  entry = nextEntry;
65
65
  entryCacheRef.current.set(cacheKey, nextEntry);
66
66
  } else {
@@ -70,8 +70,8 @@ function useHookFormMask(registerFn) {
70
70
  ...registerReturn,
71
71
  ref: entry.stableRef
72
72
  };
73
- chunkDTC7JTZP_cjs.setUnmaskedValue(result, () => chunkDTC7JTZP_cjs.getUnmaskedValue(entry?.element ?? null));
74
- chunkDTC7JTZP_cjs.setPrevRef(result, ref);
73
+ chunkPMBRAXS4_cjs.setUnmaskedValue(result, () => chunkPMBRAXS4_cjs.getUnmaskedValue(entry?.element ?? null));
74
+ chunkPMBRAXS4_cjs.setPrevRef(result, ref);
75
75
  return result;
76
76
  };
77
77
  }, [registerFn]);
@@ -87,22 +87,22 @@ function withTanStackFormMask(inputProps, mask, options) {
87
87
  ...inputProps,
88
88
  ref: ((input) => {
89
89
  currentElement = input;
90
- if (input) chunkDTC7JTZP_cjs.applyMaskToElement(input, mask, options);
90
+ if (input) chunkPMBRAXS4_cjs.applyMaskToElement(input, mask, options);
91
91
  })
92
92
  };
93
- chunkDTC7JTZP_cjs.setUnmaskedValue(result2, () => chunkDTC7JTZP_cjs.getUnmaskedValue(currentElement));
94
- chunkDTC7JTZP_cjs.setPrevRef(result2, ref);
93
+ chunkPMBRAXS4_cjs.setUnmaskedValue(result2, () => chunkPMBRAXS4_cjs.getUnmaskedValue(currentElement));
94
+ chunkPMBRAXS4_cjs.setPrevRef(result2, ref);
95
95
  return result2;
96
96
  }
97
97
  if (!refCache.has(ref)) {
98
98
  refCache.set(ref, /* @__PURE__ */ new Map());
99
99
  }
100
100
  const maskCache = refCache.get(ref);
101
- const cacheKey = chunkDTC7JTZP_cjs.makeMaskCacheKey(inputProps.name ?? "", mask);
101
+ const cacheKey = chunkPMBRAXS4_cjs.makeMaskCacheKey(inputProps.name ?? "", mask);
102
102
  if (!maskCache?.has(cacheKey)) {
103
103
  const maskedRef2 = ((input) => {
104
104
  maskedRef2.currentElement = input;
105
- if (input) chunkDTC7JTZP_cjs.applyMaskToElement(input, mask, options);
105
+ if (input) chunkPMBRAXS4_cjs.applyMaskToElement(input, mask, options);
106
106
  ref(input);
107
107
  });
108
108
  maskCache?.set(cacheKey, maskedRef2);
@@ -112,8 +112,8 @@ function withTanStackFormMask(inputProps, mask, options) {
112
112
  ...inputProps,
113
113
  ref: maskedRef
114
114
  };
115
- chunkDTC7JTZP_cjs.setUnmaskedValue(result, () => chunkDTC7JTZP_cjs.getUnmaskedValue(maskedRef?.currentElement ?? null));
116
- chunkDTC7JTZP_cjs.setPrevRef(result, ref);
115
+ chunkPMBRAXS4_cjs.setUnmaskedValue(result, () => chunkPMBRAXS4_cjs.getUnmaskedValue(maskedRef?.currentElement ?? null));
116
+ chunkPMBRAXS4_cjs.setPrevRef(result, ref);
117
117
  return result;
118
118
  }
119
119
 
@@ -134,19 +134,19 @@ function withHookFormMask(register, mask, options) {
134
134
  ...register,
135
135
  ref: null
136
136
  };
137
- chunkDTC7JTZP_cjs.setUnmaskedValue(result2, () => "");
138
- chunkDTC7JTZP_cjs.setPrevRef(result2, ref);
137
+ chunkPMBRAXS4_cjs.setUnmaskedValue(result2, () => "");
138
+ chunkPMBRAXS4_cjs.setPrevRef(result2, ref);
139
139
  return result2;
140
140
  }
141
141
  if (!refCache2.has(ref)) {
142
142
  refCache2.set(ref, /* @__PURE__ */ new Map());
143
143
  }
144
144
  const maskCache = refCache2.get(ref);
145
- const cacheKey = chunkDTC7JTZP_cjs.makeMaskCacheKey(register.name, mask);
145
+ const cacheKey = chunkPMBRAXS4_cjs.makeMaskCacheKey(register.name, mask);
146
146
  if (!maskCache?.has(cacheKey)) {
147
147
  const maskedRef2 = ((input) => {
148
148
  maskedRef2.currentElement = input;
149
- if (input) chunkDTC7JTZP_cjs.applyMaskToElement(input, mask, options);
149
+ if (input) chunkPMBRAXS4_cjs.applyMaskToElement(input, mask, options);
150
150
  return ref(input);
151
151
  });
152
152
  maskCache?.set(cacheKey, maskedRef2);
@@ -156,14 +156,14 @@ function withHookFormMask(register, mask, options) {
156
156
  ...register,
157
157
  ref: maskedRef
158
158
  };
159
- chunkDTC7JTZP_cjs.setUnmaskedValue(result, () => chunkDTC7JTZP_cjs.getUnmaskedValue(maskedRef?.currentElement ?? null));
160
- chunkDTC7JTZP_cjs.setPrevRef(result, ref);
159
+ chunkPMBRAXS4_cjs.setUnmaskedValue(result, () => chunkPMBRAXS4_cjs.getUnmaskedValue(maskedRef?.currentElement ?? null));
160
+ chunkPMBRAXS4_cjs.setPrevRef(result, ref);
161
161
  return result;
162
162
  }
163
163
 
164
164
  Object.defineProperty(exports, "withMask", {
165
165
  enumerable: true,
166
- get: function () { return chunkDTC7JTZP_cjs.withMask; }
166
+ get: function () { return chunkPMBRAXS4_cjs.withMask; }
167
167
  });
168
168
  exports.useHookFormMask = useHookFormMask;
169
169
  exports.useMaskInput = useMaskInput;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getUnmaskedValue, resolveInputRef, withMask, isServer_default, setUnmaskedValue, makeMaskCacheKey, flow, setPrevRef, applyMaskToElement } from './chunk-TVCNC3TP.js';
2
- export { withMask } from './chunk-TVCNC3TP.js';
1
+ import { getUnmaskedValue, resolveInputRef, withMask, isServer_default, setUnmaskedValue, makeMaskCacheKey, flow, setPrevRef, applyMaskToElement } from './chunk-XSTQDKDU.js';
2
+ export { withMask } from './chunk-XSTQDKDU.js';
3
3
  import { useRef, useCallback, useEffect, useLayoutEffect, useMemo } from 'react';
4
4
 
5
5
  function useMaskInput(props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-mask-input",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
4
4
  "private": false,
5
5
  "description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
6
6
  "author": "Eduardo Borges<euduardoborges@gmail.com>",
@@ -1,5 +1,5 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
- import inputmask from 'inputmask';
2
+ import inputmask from '../core/inputmask';
3
3
  import {
4
4
  beforeEach,
5
5
  describe,
@@ -12,7 +12,7 @@ import useMaskInputAntd from './useMaskInputAntd';
12
12
 
13
13
  import type { InputRef } from 'antd';
14
14
 
15
- vi.mock('inputmask', () => ({
15
+ vi.mock('../core/inputmask', () => ({
16
16
  default: vi.fn((options) => ({
17
17
  mask: vi.fn(),
18
18
  options,
@@ -1,5 +1,5 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
- import inputmask from 'inputmask';
2
+ import inputmask from '../core/inputmask';
3
3
  import {
4
4
  beforeEach,
5
5
  describe, expect, it, vi,
@@ -9,7 +9,7 @@ import useHookFormMask from './useHookFormMask';
9
9
 
10
10
  import type { FieldValues, UseFormRegister } from 'react-hook-form';
11
11
 
12
- vi.mock('inputmask', () => ({
12
+ vi.mock('../core/inputmask', () => ({
13
13
  default: vi.fn((options) => ({
14
14
  mask: vi.fn(),
15
15
  options,
@@ -1,5 +1,5 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
- import inputmask from 'inputmask';
2
+ import inputmask from '../core/inputmask';
3
3
  import {
4
4
  beforeEach,
5
5
  describe, expect, it, vi,
@@ -10,7 +10,7 @@ import * as core from '../core';
10
10
 
11
11
  import type { Input } from '../types';
12
12
 
13
- vi.mock('inputmask', () => ({
13
+ vi.mock('../core/inputmask', () => ({
14
14
  default: vi.fn((options) => ({
15
15
  mask: vi.fn(),
16
16
  options,
@@ -1,4 +1,4 @@
1
- import inputmask from 'inputmask';
1
+ import inputmask from '../core/inputmask';
2
2
  import {
3
3
  beforeEach,
4
4
  describe, expect, it, vi,
@@ -11,7 +11,7 @@ import type { FieldValues } from 'react-hook-form';
11
11
 
12
12
  import type { UseHookFormMaskReturn } from '../types';
13
13
 
14
- vi.mock('inputmask', () => ({
14
+ vi.mock('../core/inputmask', () => ({
15
15
  default: vi.fn((options) => ({
16
16
  mask: vi.fn(),
17
17
  options,
@@ -1,11 +1,11 @@
1
- import inputmask from 'inputmask';
1
+ import inputmask from '../core/inputmask';
2
2
  import {
3
3
  beforeEach, describe, expect, it, vi,
4
4
  } from 'vitest';
5
5
 
6
6
  import withMask from './withMask';
7
7
 
8
- vi.mock('inputmask', () => ({
8
+ vi.mock('../core/inputmask', () => ({
9
9
  default: vi.fn((options) => ({
10
10
  mask: vi.fn(),
11
11
  options,
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable import-x/no-extraneous-dependencies */
2
- import inputmask from 'inputmask';
2
+ import inputmask from '../core/inputmask';
3
3
 
4
4
  import { getMaskOptions } from '../core/maskConfig';
5
5
  import { getUnmaskedValue, makeMaskCacheKey, setUnmaskedValue } from '../utils';
@@ -1,4 +1,4 @@
1
- import inputmask from 'inputmask';
1
+ import inputmask from '../core/inputmask';
2
2
  import {
3
3
  beforeEach,
4
4
  describe, expect, it, vi,
@@ -8,7 +8,7 @@ import withTanStackFormMask from './withTanStackFormMask';
8
8
 
9
9
  import type { TanStackFormInputProps } from '../types';
10
10
 
11
- vi.mock('inputmask', () => ({
11
+ vi.mock('../core/inputmask', () => ({
12
12
  default: vi.fn((options) => ({
13
13
  mask: vi.fn(),
14
14
  options,
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import inputmask from './inputmask';
4
+
5
+ describe('inputmask wrapper', () => {
6
+ it('loads the aliases used by built-in masks', () => {
7
+ const aliases = (inputmask as unknown as { prototype: { aliases: Record<string, unknown> } }).prototype.aliases;
8
+
9
+ expect(aliases.datetime).toBeDefined();
10
+ expect(aliases.email).toBeDefined();
11
+ expect(aliases.numeric).toBeDefined();
12
+ expect(aliases.currency).toBeDefined();
13
+ expect(aliases.decimal).toBeDefined();
14
+ expect(aliases.integer).toBeDefined();
15
+ expect(aliases.percentage).toBeDefined();
16
+ expect(aliases.url).toBeDefined();
17
+ expect(aliases.ip).toBeDefined();
18
+ expect(aliases.mac).toBeDefined();
19
+ expect(aliases.ssn).toBeDefined();
20
+ });
21
+ });
@@ -0,0 +1,10 @@
1
+ /* eslint-disable import-x/no-extraneous-dependencies, import/no-unassigned-import */
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore Inputmask exposes this ESM file but not its subpath types in app builds.
4
+ import Inputmask from 'inputmask/lib/inputmask.js';
5
+
6
+ import 'inputmask/lib/extensions/inputmask.extensions.js';
7
+ import 'inputmask/lib/extensions/inputmask.date.extensions.js';
8
+ import 'inputmask/lib/extensions/inputmask.numeric.extensions.js';
9
+
10
+ export default Inputmask;
@@ -1,4 +1,4 @@
1
- import inputmask from 'inputmask';
1
+ import inputmask from './inputmask';
2
2
  import {
3
3
  beforeEach, describe, expect, it, vi,
4
4
  } from 'vitest';
@@ -11,7 +11,7 @@ function stubMaskInstance(maskFn: ReturnType<typeof vi.fn>): MaskInstance {
11
11
  return { mask: maskFn } as unknown as MaskInstance;
12
12
  }
13
13
 
14
- vi.mock('inputmask', () => ({
14
+ vi.mock('./inputmask', () => ({
15
15
  default: vi.fn((options) => ({
16
16
  mask: vi.fn(),
17
17
  options,
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable import-x/no-extraneous-dependencies */
2
- import inputmask from 'inputmask';
2
+ import inputmask from './inputmask';
3
3
 
4
4
  import { getMaskOptions } from './maskConfig';
5
5
  import { moduleInterop } from '../utils';
@@ -14,7 +14,7 @@ import type { Mask, Options } from '../types';
14
14
  * @param options - Optional configuration options
15
15
  * @returns A mask instance
16
16
  */
17
- export function createMaskInstance(mask: Mask, options?: Options): Inputmask.Instance {
17
+ export function createMaskInstance(mask: Mask, options?: Options): ReturnType<typeof inputmask> {
18
18
  const inputmaskInstance = moduleInterop(inputmask);
19
19
  return inputmaskInstance(getMaskOptions(mask, options));
20
20
  }
@@ -2,6 +2,10 @@ import { findInputElement, resolveInputRef } from '../core/elementResolver';
2
2
 
3
3
  import type { Input, Mask, UnmaskedValueApi } from '../types';
4
4
 
5
+ type MaskedElement = (HTMLInputElement | HTMLTextAreaElement) & {
6
+ inputmask?: { unmaskedvalue?: () => string };
7
+ };
8
+
5
9
  /**
6
10
  * Builds a stable string key from a field name and mask, used to cache ref
7
11
  * callbacks so their identity stays stable across renders.
@@ -39,9 +43,7 @@ export function getUnmaskedValue(input: Input | null): string {
39
43
  const element = resolveUnmaskedInput(input);
40
44
  if (!element) return '';
41
45
 
42
- const inputmask = (element as HTMLInputElement).inputmask as
43
- | { unmaskedvalue?: () => string }
44
- | undefined;
46
+ const { inputmask } = element as MaskedElement;
45
47
 
46
48
  if (inputmask && typeof inputmask.unmaskedvalue === 'function') {
47
49
  return inputmask.unmaskedvalue();