use-mask-input 3.10.1 → 3.10.3

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 (49) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/dist/antd.cjs +1 -65
  3. package/dist/antd.cjs.map +1 -1
  4. package/dist/antd.d.cts +12 -10
  5. package/dist/{antd.d.ts → antd.d.mts} +12 -10
  6. package/dist/antd.mjs +2 -0
  7. package/dist/antd.mjs.map +1 -0
  8. package/dist/index-Do9euvWK.d.cts +839 -0
  9. package/dist/index-Do9euvWK.d.mts +839 -0
  10. package/dist/index.cjs +1 -173
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +18 -15
  13. package/dist/{index.d.ts → index.d.mts} +18 -15
  14. package/dist/index.mjs +2 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/withMask-B4sSnU9K.cjs +2 -0
  17. package/dist/withMask-B4sSnU9K.cjs.map +1 -0
  18. package/dist/withMask-CKM8Ug6z.mjs +2 -0
  19. package/dist/withMask-CKM8Ug6z.mjs.map +1 -0
  20. package/package.json +42 -22
  21. package/src/@types/inputmask.d.ts +22 -0
  22. package/src/types/index.ts +8 -1
  23. package/src/utils/maskHelpers.ts +3 -0
  24. package/dist/antd.js +0 -63
  25. package/dist/antd.js.map +0 -1
  26. package/dist/chunk-PMBRAXS4.cjs +0 -5876
  27. package/dist/chunk-PMBRAXS4.cjs.map +0 -1
  28. package/dist/chunk-XSTQDKDU.js +0 -5866
  29. package/dist/chunk-XSTQDKDU.js.map +0 -1
  30. package/dist/index-D8KkaDbQ.d.cts +0 -596
  31. package/dist/index-D8KkaDbQ.d.ts +0 -596
  32. package/dist/index.js +0 -165
  33. package/dist/index.js.map +0 -1
  34. package/src/antd/useHookFormMaskAntd.spec.ts +0 -181
  35. package/src/antd/useMaskInputAntd-server.spec.tsx +0 -37
  36. package/src/antd/useMaskInputAntd.spec.tsx +0 -131
  37. package/src/api/useHookFormMask.spec.ts +0 -259
  38. package/src/api/useMaskInput-server.spec.tsx +0 -30
  39. package/src/api/useMaskInput.spec.tsx +0 -238
  40. package/src/api/withHookFormMask.spec.ts +0 -179
  41. package/src/api/withMask.spec.ts +0 -137
  42. package/src/api/withTanStackFormMask.spec.ts +0 -76
  43. package/src/core/elementResolver.spec.ts +0 -175
  44. package/src/core/inputmask.spec.ts +0 -21
  45. package/src/core/maskConfig.spec.ts +0 -208
  46. package/src/core/maskEngine.spec.ts +0 -114
  47. package/src/utils/flow.spec.ts +0 -57
  48. package/src/utils/isServer.spec.ts +0 -15
  49. package/src/utils/moduleInterop.spec.ts +0 -37
package/package.json CHANGED
@@ -1,27 +1,38 @@
1
1
  {
2
2
  "name": "use-mask-input",
3
- "version": "3.10.1",
3
+ "version": "3.10.3",
4
4
  "private": false,
5
5
  "description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
6
+ "license": "MIT",
6
7
  "author": "Eduardo Borges<euduardoborges@gmail.com>",
7
8
  "type": "module",
8
9
  "repository": {
9
10
  "url": "https://github.com/eduardoborges/use-mask-input"
10
11
  },
11
12
  "main": "./dist/index.cjs",
12
- "module": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
13
+ "module": "./dist/index.mjs",
14
+ "types": "./dist/index.d.mts",
14
15
  "source": "./src/index.tsx",
15
16
  "exports": {
16
17
  ".": {
17
- "types": "./dist/index.d.ts",
18
- "import": "./dist/index.js",
19
- "require": "./dist/index.cjs"
18
+ "import": {
19
+ "types": "./dist/index.d.mts",
20
+ "default": "./dist/index.mjs"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
20
26
  },
21
27
  "./antd": {
22
- "types": "./dist/antd.d.ts",
23
- "import": "./dist/antd.js",
24
- "require": "./dist/antd.cjs"
28
+ "import": {
29
+ "types": "./dist/antd.d.mts",
30
+ "default": "./dist/antd.mjs"
31
+ },
32
+ "require": {
33
+ "types": "./dist/antd.d.cts",
34
+ "default": "./dist/antd.cjs"
35
+ }
25
36
  }
26
37
  },
27
38
  "engines": {
@@ -31,33 +42,42 @@
31
42
  "files": [
32
43
  "dist",
33
44
  "src",
45
+ "!src/**/*.spec.*",
46
+ "!dist/*-stats.json",
34
47
  "README.md",
35
48
  "CHANGELOG.md"
36
49
  ],
37
50
  "peerDependencies": {
51
+ "antd": ">=5",
38
52
  "react": ">=17",
39
53
  "react-dom": ">=17"
40
54
  },
55
+ "peerDependenciesMeta": {
56
+ "antd": {
57
+ "optional": true
58
+ }
59
+ },
41
60
  "devDependencies": {
61
+ "@codecov/rollup-plugin": "^2.0.1",
42
62
  "@testing-library/dom": "^10.4.1",
43
63
  "@testing-library/react": "^16.3.2",
44
64
  "@types/inputmask": "5.0.7",
45
- "@types/node": "^25.5.0",
46
- "@types/react": ">=19",
47
- "@types/react-dom": ">=19",
48
- "@vitest/coverage-v8": "4.1.1",
49
- "antd": "^6.3.4",
50
- "oxlint": "1.57.0",
65
+ "@types/node": "^25.9.3",
66
+ "@types/react": "^19.2.17",
67
+ "@types/react-dom": "^19.2.3",
68
+ "@vitest/coverage-v8": "4.1.7",
69
+ "antd": "^6.4.4",
51
70
  "inputmask": "5.0.10-beta.61",
52
- "jsdom": "^28.1.0",
53
- "react-hook-form": "7.72.0",
54
- "tsup": "8.5.1",
55
- "typescript": "5.9",
56
- "vitest": "4.1.1"
71
+ "jsdom": "^29.1.1",
72
+ "oxlint": "1.66.0",
73
+ "react-hook-form": "7.75.0",
74
+ "tsdown": "^0.22.2",
75
+ "typescript": "~6.0.3",
76
+ "vitest": "4.1.7"
57
77
  },
58
78
  "scripts": {
59
- "build": "tsup",
60
- "dev": "tsup --watch",
79
+ "build": "tsdown",
80
+ "dev": "tsdown --watch",
61
81
  "lint": "oxlint ./src",
62
82
  "test": "vitest --dir ./src --run --coverage",
63
83
  "type-check": "tsc --noEmit",
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Inputmask attaches its instance to the masked DOM element under the
3
+ * `inputmask` property. The upstream `@types/inputmask` package only augments
4
+ * the global `HTMLElement` from inside a module-scoped `declare global`, so the
5
+ * augmentation is not picked up unless that module is imported by its bare name
6
+ * (this project imports `inputmask/lib/inputmask.js` instead).
7
+ *
8
+ * Declaring it here, in an ambient script file included by tsconfig, makes the
9
+ * property visible on the input elements we mask.
10
+ */
11
+
12
+ interface InputmaskInstance {
13
+ unmaskedvalue?: () => string;
14
+ }
15
+
16
+ interface HTMLInputElement {
17
+ inputmask?: InputmaskInstance;
18
+ }
19
+
20
+ interface HTMLTextAreaElement {
21
+ inputmask?: InputmaskInstance;
22
+ }
@@ -1,4 +1,4 @@
1
- import type { RefCallback } from 'react';
1
+ import type { ChangeEvent, FocusEvent, RefCallback } from 'react';
2
2
  import type {
3
3
  FieldValues, Path,
4
4
  UseFormRegisterReturn,
@@ -45,7 +45,14 @@ export interface UseHookFormMaskReturn<
45
45
 
46
46
  export interface TanStackFormInputProps {
47
47
  name?: string;
48
+ value?: string | number | readonly string[];
48
49
  ref?: RefCallback<HTMLElement | null>;
50
+ // Method shorthand (not an arrow-typed property) so the parameter is checked
51
+ // bivariantly: handlers explicitly typed for just HTMLInputElement (e.g. using
52
+ // `event.target.files`) or just HTMLTextAreaElement (e.g. `event.target.cols`)
53
+ // both remain assignable, alongside the common inline, unannotated handler.
54
+ onChange?(event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void;
55
+ onBlur?(event: FocusEvent<HTMLInputElement | HTMLTextAreaElement>): void;
49
56
  [key: string]: unknown;
50
57
  }
51
58
 
@@ -2,6 +2,9 @@ import { findInputElement, resolveInputRef } from '../core/elementResolver';
2
2
 
3
3
  import type { Input, Mask, UnmaskedValueApi } from '../types';
4
4
 
5
+ // Kept self-contained (not relying on the ambient src/@types augmentation) so
6
+ // this module type-checks when consumers compile the package source directly,
7
+ // e.g. the example apps that alias `use-mask-input` to `src` and build with `tsc`.
5
8
  type MaskedElement = (HTMLInputElement | HTMLTextAreaElement) & {
6
9
  inputmask?: { unmaskedvalue?: () => string };
7
10
  };
package/dist/antd.js DELETED
@@ -1,63 +0,0 @@
1
- import { makeMaskCacheKey, setPrevRef, getUnmaskedValue, resolveInputRef, withMask, isServer_default, setUnmaskedValue, applyMaskToElement } from './chunk-XSTQDKDU.js';
2
- import { useMemo, useRef, useCallback, useEffect } from 'react';
3
-
4
- function useHookFormMaskAntd(registerFn) {
5
- return useMemo(() => {
6
- const refCache = /* @__PURE__ */ new Map();
7
- return (fieldName, mask, options) => {
8
- if (!registerFn) throw new Error("registerFn is required");
9
- const registerReturn = registerFn(fieldName, options);
10
- const { ref } = registerReturn;
11
- const cacheKey = makeMaskCacheKey(fieldName, mask);
12
- if (!refCache.has(cacheKey)) {
13
- const refWithMask = (inputRef) => {
14
- const element = inputRef ? resolveInputRef(inputRef.input) : null;
15
- if (element) applyMaskToElement(element, mask, options);
16
- if (ref) ref(element);
17
- };
18
- refCache.set(cacheKey, refWithMask);
19
- }
20
- const result = {
21
- ...registerReturn,
22
- ref: refCache.get(cacheKey)
23
- };
24
- setPrevRef(result, ref);
25
- return result;
26
- };
27
- }, [registerFn]);
28
- }
29
- function useMaskInputAntd(props) {
30
- const { mask, register, options } = props;
31
- const ref = useRef(null);
32
- const maskRef = useRef(mask);
33
- const optionsRef = useRef(options);
34
- const maskedElementRef = useRef(null);
35
- const unmaskedValue = useCallback(() => getUnmaskedValue(ref.current), []);
36
- maskRef.current = mask;
37
- optionsRef.current = options;
38
- const refCallback = useCallback((input) => {
39
- if (!input) {
40
- ref.current = null;
41
- return;
42
- }
43
- ref.current = resolveInputRef(input.input);
44
- if (ref.current && ref.current !== maskedElementRef.current) {
45
- withMask(maskRef.current, optionsRef.current)(ref.current);
46
- maskedElementRef.current = ref.current;
47
- }
48
- }, []);
49
- useEffect(() => {
50
- if (isServer_default || !ref.current || !register) return;
51
- register(ref.current);
52
- }, [register]);
53
- if (isServer_default) {
54
- const noop = (() => {
55
- });
56
- return setUnmaskedValue(noop, () => "");
57
- }
58
- return setUnmaskedValue(refCallback, unmaskedValue);
59
- }
60
-
61
- export { useHookFormMaskAntd, useMaskInputAntd };
62
- //# sourceMappingURL=antd.js.map
63
- //# sourceMappingURL=antd.js.map
package/dist/antd.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/antd/useHookFormMaskAntd.ts","../src/antd/useMaskInputAntd.ts"],"names":[],"mappings":";;;AA6Be,SAAR,oBAEL,UAAA,EAC6D;AAE7D,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,MAAM,QAAA,uBAAe,GAAA,EAA0C;AAE/D,IAAA,OAAO,CAAC,SAAA,EAAoB,IAAA,EAAY,OAAA,KACuB;AAC7D,MAAA,IAAI,CAAC,UAAA,EAAY,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAEzD,MAAA,MAAM,cAAA,GAAiB,UAAA,CAAW,SAAA,EAAW,OAAkB,CAAA;AAC/D,MAAA,MAAM,EAAE,KAAI,GAAI,cAAA;AAEhB,MAAA,MAAM,QAAA,GAAW,gBAAA,CAAiB,SAAA,EAAW,IAAI,CAAA;AAEjD,MAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,QAAQ,CAAA,EAAG;AAC3B,QAAA,MAAM,WAAA,GAA4C,CAAC,QAAA,KAAa;AAC9D,UAAA,MAAM,OAAA,GAAU,QAAA,GAAW,eAAA,CAAgB,QAAA,CAAS,KAAK,CAAA,GAAI,IAAA;AAC7D,UAAA,IAAI,OAAA,EAAS,kBAAA,CAAmB,OAAA,EAAS,IAAA,EAAM,OAAkB,CAAA;AACjE,UAAA,IAAI,GAAA,MAAS,OAAO,CAAA;AAAA,QACtB,CAAA;AACA,QAAA,QAAA,CAAS,GAAA,CAAI,UAAU,WAAW,CAAA;AAAA,MACpC;AAEA,MAAA,MAAM,MAAA,GAAS;AAAA,QACb,GAAG,cAAA;AAAA,QACH,GAAA,EAAK,QAAA,CAAS,GAAA,CAAI,QAAQ;AAAA,OAC5B;AAEA,MAAA,UAAA,CAAW,QAAQ,G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A,CAAS,IAAI,OAAO,CAAA;AAAA,EACtB,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAEb,EAAA,IAAI,gBAAA,EAAU;AACZ,IAAA,MAAM,QAAQ,MAAM;AAAA,IAEpB,CAAA,CAAA;AAEA,IAAA,OAAO,gBAAA,CAAiB,IAAA,EAAM,MAAM,EAAE,CAAA;AAAA,EACxC;AAEA,EAAA,OAAO,gBAAA,CAAiB,aAAuC,aAAa,CAAA;AAC9E","file":"antd.js","sourcesContent":["import { useMemo } from 'react';\n\nimport { applyMaskToElement, resolveInputRef } from '../core';\nimport { makeMaskCacheKey, setPrevRef } from '../utils';\n\nimport type { InputRef } from 'antd';\nimport type { RefCallback } from 'react';\nimport type {\n FieldValues, Path,\n RegisterOptions,\n UseFormRegister,\n} from 'react-hook-form';\n\nimport type { Mask, Options, UseHookFormMaskReturn } from '../types';\n\nexport type UseHookFormMaskAntdReturn<T extends FieldValues> = Omit<\n UseHookFormMaskReturn<T>,\n 'ref'\n> & { ref: RefCallback<InputRef | null> };\n\n/**\n * Ant Design version of useHookFormMask.\n * Creates a masked register that works with Ant Design Input (ref receives InputRef).\n *\n * @template T - The form data type\n * @template D - The register options type\n * @param registerFn - The register function from useForm hook\n * @returns A function that registers a field with mask support for Ant Design Input\n */\nexport default function useHookFormMaskAntd<\n T extends FieldValues, D extends RegisterOptions,\n>(registerFn: UseFormRegister<T>): ((fieldName: Path<T>, mask: Mask, options?: (\n D & Options) | Options | D) => UseHookFormMaskAntdReturn<T>) {\n //\n return useMemo(() => {\n const refCache = new Map<string, RefCallback<InputRef | null>>();\n\n return (fieldName: Path<T>, mask: Mask, options?: (\n D & Options) | Options | D): UseHookFormMaskAntdReturn<T> => {\n if (!registerFn) throw new Error('registerFn is required');\n\n const registerReturn = registerFn(fieldName, options as Options);\n const { ref } = registerReturn as UseHookFormMaskReturn<T>;\n\n const cacheKey = makeMaskCacheKey(fieldName, mask);\n\n if (!refCache.has(cacheKey)) {\n const refWithMask: RefCallback<InputRef | null> = (inputRef) => {\n const element = inputRef ? resolveInputRef(inputRef.input) : null;\n if (element) applyMaskToElement(element, mask, options as Options);\n if (ref) ref(element);\n };\n refCache.set(cacheKey, refWithMask);\n }\n\n const result = {\n ...registerReturn,\n ref: refCache.get(cacheKey),\n } as UseHookFormMaskAntdReturn<T>;\n\n setPrevRef(result, ref);\n\n return result;\n };\n }, [registerFn]);\n}\n","import { useCallback, useEffect, useRef } from 'react';\n\nimport withMask from '../api/withMask';\nimport { resolveInputRef } from '../core';\nimport isServer from '../utils/isServer';\nimport { getUnmaskedValue, setUnmaskedValue } from '../utils';\n\nimport type { InputRef } from 'antd';\n\nimport type { Mask, Options, UnmaskedValueApi } from '../types';\n\ntype UseMaskInputAntdReturn = ((input: InputRef | null) => void) & UnmaskedValueApi;\n\ninterface UseMaskInputOptions {\n mask: Mask;\n register?: (element: HTMLElement) => void;\n options?: Options;\n}\n\n/**\n * React hook for applying input masks to Ant Design form elements.\n *\n * @param props - Configuration object\n * @param props.mask - The mask pattern to apply\n * @param props.register - Optional callback that receives the element\n * @param props.options - Optional mask configuration options\n * @returns A ref callback function to attach to the Ant Design Input element\n */\nexport default function useMaskInputAntd(props: UseMaskInputOptions): UseMaskInputAntdReturn {\n const { mask, register, options } = props;\n const ref = useRef<HTMLInputElement | null>(null);\n const maskRef = useRef(mask);\n const optionsRef = useRef(options);\n const maskedElementRef = useRef<HTMLInputElement | null>(null);\n const unmaskedValue = useCallback(() => getUnmaskedValue(ref.current), []);\n\n maskRef.current = mask;\n optionsRef.current = options;\n\n const refCallback = useCallback((input: InputRef | null): void => {\n if (!input) {\n ref.current = null;\n return;\n }\n\n ref.current = resolveInputRef(input.input);\n\n if (ref.current && ref.current !== maskedElementRef.current) {\n withMask(maskRef.current, optionsRef.current)(ref.current);\n maskedElementRef.current = ref.current;\n }\n }, []);\n\n useEffect(() => {\n if (isServer || !ref.current || !register) return;\n register(ref.current);\n }, [register]);\n\n if (isServer) {\n const noop = (() => {\n // server doesn't have dom, so just do nothing\n }) as unknown as UseMaskInputAntdReturn;\n\n return setUnmaskedValue(noop, () => '');\n }\n\n return setUnmaskedValue(refCallback as UseMaskInputAntdReturn, unmaskedValue);\n}\n"]}