@elliemae/ds-form-helpers-mask-hooks 3.16.0-next.2 → 3.16.0-next.21

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 (70) hide show
  1. package/dist/cjs/hooks/index.js +9 -5
  2. package/dist/cjs/hooks/index.js.map +2 -2
  3. package/dist/cjs/hooks/useNumberMask.js +20 -8
  4. package/dist/cjs/hooks/useNumberMask.js.map +2 -2
  5. package/dist/cjs/hooks/usePhoneMask.js +13 -8
  6. package/dist/cjs/hooks/usePhoneMask.js.map +2 -2
  7. package/dist/cjs/hooks/useRegExpMask.js +19 -8
  8. package/dist/cjs/hooks/useRegExpMask.js.map +2 -2
  9. package/dist/cjs/hooks/useSSNMask.js +10 -5
  10. package/dist/cjs/hooks/useSSNMask.js.map +2 -2
  11. package/dist/cjs/hooks/useZipCodeMask.js +12 -7
  12. package/dist/cjs/hooks/useZipCodeMask.js.map +2 -2
  13. package/dist/cjs/index.js +5 -1
  14. package/dist/cjs/index.js.map +2 -2
  15. package/dist/cjs/package.json +7 -0
  16. package/dist/cjs/react-desc-prop-types.js +24 -15
  17. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  18. package/dist/cjs/utils/addSpecialCharacters.js +4 -0
  19. package/dist/cjs/utils/addSpecialCharacters.js.map +1 -1
  20. package/dist/cjs/utils/flatStringArray.js +4 -0
  21. package/dist/cjs/utils/flatStringArray.js.map +1 -1
  22. package/dist/cjs/utils/getPartialMaskedPos.js +4 -0
  23. package/dist/cjs/utils/getPartialMaskedPos.js.map +1 -1
  24. package/dist/cjs/utils/index.js +9 -5
  25. package/dist/cjs/utils/index.js.map +2 -2
  26. package/dist/cjs/utils/setCursorPosition.js +4 -0
  27. package/dist/cjs/utils/setCursorPosition.js.map +1 -1
  28. package/dist/cjs/utils/sharedFilters.js +4 -0
  29. package/dist/cjs/utils/sharedFilters.js.map +1 -1
  30. package/dist/esm/hooks/index.js +5 -5
  31. package/dist/esm/hooks/index.js.map +1 -1
  32. package/dist/esm/hooks/useNumberMask.js +14 -11
  33. package/dist/esm/hooks/useNumberMask.js.map +2 -2
  34. package/dist/esm/hooks/usePhoneMask.js +7 -11
  35. package/dist/esm/hooks/usePhoneMask.js.map +2 -2
  36. package/dist/esm/hooks/useRegExpMask.js +13 -11
  37. package/dist/esm/hooks/useRegExpMask.js.map +2 -2
  38. package/dist/esm/hooks/useSSNMask.js +4 -8
  39. package/dist/esm/hooks/useSSNMask.js.map +2 -2
  40. package/dist/esm/hooks/useZipCodeMask.js +6 -10
  41. package/dist/esm/hooks/useZipCodeMask.js.map +2 -2
  42. package/dist/esm/index.js +1 -1
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/package.json +7 -0
  45. package/dist/esm/react-desc-prop-types.js +8 -3
  46. package/dist/esm/react-desc-prop-types.js.map +2 -2
  47. package/dist/esm/utils/addSpecialCharacters.js.map +1 -1
  48. package/dist/esm/utils/getPartialMaskedPos.js.map +1 -1
  49. package/dist/esm/utils/index.js +5 -5
  50. package/dist/esm/utils/index.js.map +1 -1
  51. package/package.json +9 -8
  52. package/dist/types/hooks/index.d.ts +0 -5
  53. package/dist/types/hooks/useNumberMask.d.ts +0 -4
  54. package/dist/types/hooks/usePhoneMask.d.ts +0 -4
  55. package/dist/types/hooks/useRegExpMask.d.ts +0 -3
  56. package/dist/types/hooks/useSSNMask.d.ts +0 -4
  57. package/dist/types/hooks/useZipCodeMask.d.ts +0 -4
  58. package/dist/types/index.d.ts +0 -2
  59. package/dist/types/react-desc-prop-types.d.ts +0 -46
  60. package/dist/types/tests/useNumberMask.test.d.ts +0 -1
  61. package/dist/types/tests/usePhoneMask.test.d.ts +0 -1
  62. package/dist/types/tests/useRegExpMask.test.d.ts +0 -1
  63. package/dist/types/tests/useSSNMask.test.d.ts +0 -1
  64. package/dist/types/tests/useZipCode.test.d.ts +0 -1
  65. package/dist/types/utils/addSpecialCharacters.d.ts +0 -9
  66. package/dist/types/utils/flatStringArray.d.ts +0 -1
  67. package/dist/types/utils/getPartialMaskedPos.d.ts +0 -1
  68. package/dist/types/utils/index.d.ts +0 -5
  69. package/dist/types/utils/setCursorPosition.d.ts +0 -1
  70. package/dist/types/utils/sharedFilters.d.ts +0 -6
@@ -1,13 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { useCallback, useRef, useState } from "react";
3
- import {
4
- describe,
5
- useMemoMergePropsWithDefault,
6
- useValidateTypescriptPropTypes,
7
- useCallbackAfterRender
8
- } from "@elliemae/ds-utilities";
9
- import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils";
10
- import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
5
+ import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils/index.js";
6
+ import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types.js";
11
7
  const ssnSpecialChars = [
12
8
  ["-", 3],
13
9
  ["-", 6]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/useSSNMask.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { useCallback, useRef, useState } from 'react';\nimport {\n describe,\n useMemoMergePropsWithDefault,\n useValidateTypescriptPropTypes,\n useCallbackAfterRender,\n} from '@elliemae/ds-utilities';\nimport { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types';\n\nconst ssnSpecialChars: [string, number][] = [\n ['-', 3],\n ['-', 6],\n];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue).split('').filter((char) => char >= '0' && char <= '9');\n\n // We can't have zeros at the start of the array\n while (maskedValue.length && maskedValue[0] === '0') maskedValue.splice(0, 1);\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, ssnSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useSSNMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useSSNMask');\n\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getSSNMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return mask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ACL,YAAM,CAAC,MAAM,SAAS,IAAI,aAAa,EAAE,OAAO,OAAO,EAAE,OAAO,gBAAgB,GAAG,YAAY,OAAO;AACtG,kBAAY,CAAC,aAAa;AAExB,YAAI,SAAS;AAAU,iBAAO,CAAC,QAAQ,MAAM,CAAC;AAE9C,eAAO;AAAA,MACT,CAAC;AACD,UAAI;AAAc,qBAAa,GAAG,IAAI;AACtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,YAAY;AAAA,EACjD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,UAAkB;AAClD,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,WAAW,cAAc;AAClB,MAAM,uBAAuB,SAAS,UAAU;AACvD,qBAAqB,YAAY;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { useCallback, useRef, useState } from 'react';\nimport { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { useCallbackAfterRender } from '@elliemae/ds-utilities';\nimport { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from '../utils/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types.js';\n\nconst ssnSpecialChars: [string, number][] = [\n ['-', 3],\n ['-', 6],\n];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue)\n .split('')\n .filter((char) => char >= '0' && char <= '9');\n\n // We can't have zeros at the start of the array\n while (maskedValue.length && maskedValue[0] === '0') maskedValue.splice(0, 1);\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, ssnSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useSSNMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useSSNMask');\n\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getSSNMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return maskedValue;\n};\n\nuseSSNMask.displayName = 'useSSNMask';\nexport const UseSSNMaskWithSchema = describe(useSSNMask);\nUseSSNMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,aAAa,QAAQ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AAC;AAE9C,eAAO;AAAA,MACT,CAAC;AACD,UAAI;AAAc,qBAAa,GAAG,IAAI;AACtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,YAAY;AAAA,EACjD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,UAAkB;AAClD,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,WAAW,cAAc;AAClB,MAAM,uBAAuB,SAAS,UAAU;AACvD,qBAAqB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -1,13 +1,9 @@
1
1
  import * as React from "react";
2
2
  import { useCallback, useRef, useState } from "react";
3
- import {
4
- describe,
5
- useMemoMergePropsWithDefault,
6
- useValidateTypescriptPropTypes,
7
- useCallbackAfterRender
8
- } from "@elliemae/ds-utilities";
9
- import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils";
10
- import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
5
+ import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils/index.js";
6
+ import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types.js";
11
7
  const zipCodeSpecialChars = [["-", 5]];
12
8
  const conformValue = (rawValue, cursorPos, lastKeyCode) => {
13
9
  let maskedValue = String(rawValue).split("").filter((char) => char >= "0" && char <= "9");
@@ -49,7 +45,7 @@ const useZipCodeMask = (props) => {
49
45
  onChange
50
46
  };
51
47
  };
52
- const getUseZipMaskedValue = (value) => {
48
+ const getZipCodeMaskedValue = (value) => {
53
49
  const [maskedValue] = conformValue(value, value.length - 1, "");
54
50
  return maskedValue;
55
51
  };
@@ -58,7 +54,7 @@ const UseZipCodeMaskWithSchema = describe(useZipCodeMask);
58
54
  UseZipCodeMaskWithSchema.propTypes = DSMaskHookPropsTypes;
59
55
  export {
60
56
  UseZipCodeMaskWithSchema,
61
- getUseZipMaskedValue,
57
+ getZipCodeMaskedValue,
62
58
  useZipCodeMask
63
59
  };
64
60
  //# sourceMappingURL=useZipCodeMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/useZipCodeMask.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { useCallback, useRef, useState } from 'react';\nimport {\n describe,\n useMemoMergePropsWithDefault,\n useValidateTypescriptPropTypes,\n useCallbackAfterRender,\n} from '@elliemae/ds-utilities';\nimport { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types';\n\nconst zipCodeSpecialChars: [string, number][] = [['-', 5]];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue).split('').filter((char) => char >= '0' && char <= '9');\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, zipCodeSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useZipCodeMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useZipCodeMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getUseZipMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return maskedValue;\n};\n\nuseZipCodeMask.displayName = 'useZipCodeMask';\nexport const UseZipCodeMaskWithSchema = describe(useZipCodeMask);\nUseZipCodeMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB,qBAAqB,yBAAyB;AAE7E,SAAS,wBAAwB,4BAA4B;AAE7D,MAAM,sBAA0C,CAAC,CAAC,KAAK,CAAC,CAAC;AAEzD,MAAM,eAAe,CAAC,UAAkB,WAAmB,gBAAwB;AAEjF,MAAI,cAAc,OAAO,QAAQ,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,SAAS,QAAQ,OAAO,QA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+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type React from 'react';\nimport { useCallback, useRef, useState } from 'react';\nimport { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { useCallbackAfterRender } from '@elliemae/ds-utilities';\nimport { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from '../utils/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types.js';\n\nconst zipCodeSpecialChars: [string, number][] = [['-', 5]];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue)\n .split('')\n .filter((char) => char >= '0' && char <= '9');\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, zipCodeSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useZipCodeMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useZipCodeMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getZipCodeMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return maskedValue;\n};\n\nuseZipCodeMask.displayName = 'useZipCodeMask';\nexport const UseZipCodeMaskWithSchema = describe(useZipCodeMask);\nUseZipCodeMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C,SAAS,UAAU,8BAA8B,sCAAsC;AACvF,SAAS,8BAA8B;AACvC,SAAS,sBAAsB,qBAAqB,yBAAyB;AAE7E,SAAS,wBAAwB,4BAA4B;AAE7D,MAAM,sBAA0C,CAAC,CAAC,KAAK,CAAC,CAAC;AAEzD,MAAM,eAAe,CAAC,UAAkB,WAAmB,gBAAwB;AAEjF,MAAI,cAAc,OAAO,QAAQ,EAC9B,MAAM,EAAE,EACR,OAAO,CAAC,SAAS,QAAQ,OAAO,QAAQ,GAAG;AAG9C,gBAAc,YAAY,MAAM,GAAG,CAAC;AAEpC,QAAM,YAAY,oBAAoB,UAAU,aAAa,SAAS;AAEtE,SAAO,qBAAqB,aAAa,qBAAqB,WAAW,WAAW;AACtF;AAEO,MAAM,iBAA+B,CAAC,UAAU;AACrD,QAAM,mBAAmB,6BAA6B,OAAO,sBAAsB;AACnF,iCAA+B,kBAAkB,sBAAsB,gBAAgB;AACvF,QAAM,EAAE,aAAa,UAAU,cAAc,WAAW,cAAc,IAAI;AAE1E,QAAM,cAAc,OAAO,cAAc;AACzC,QAAM,sBAAsB,uBAAuB,IAAI;AAOvD,QAAM,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC;AAE7B,QAAM,YAA0D;AAAA,IAC9D,CAAC,MAAM;AACL,kBAAY,UAAU,EAAE;AACxB,UAAI;AAAe,sBAAc,CAAC;AAAA,IACpC;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AAEA,QAAM,WAAuD;AAAA,IAC3D,CAAC,MAAM;AACL,YAAM,CAAC,MAAM,SAAS,IAAI,aAAa,EAAE,OAAO,OAAO,EAAE,OAAO,gBAAgB,GAAG,YAAY,OAAO;AACtG,kBAAY,CAAC,aAAa;AAExB,YAAI,SAAS;AAAU,iBAAO,CAAC,QAAQ,MAAM,CAAC;AAE9C,eAAO;AAAA,MACT,CAAC;AACD,UAAI;AAAc,qBAAa,GAAG,IAAI;AACtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,YAAY;AAAA,EACjD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,wBAAwB,CAAC,UAAkB;AACtD,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,eAAe,cAAc;AACtB,MAAM,2BAA2B,SAAS,cAAc;AAC/D,yBAAyB,YAAY;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import * as React from "react";
2
- export * from "./hooks";
2
+ export * from "./hooks/index.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './hooks';\nexport type { DSMaskT } from './react-desc-prop-types';\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './hooks/index.js';\nexport type { DSMaskT } from './react-desc-prop-types.js';\n"],
5
5
  "mappings": "AAAA,YAAY,WAAW;ACAvB,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { PropTypes } from "@elliemae/ds-utilities";
2
+ import { PropTypes } from "@elliemae/ds-props-helpers";
3
3
  const DSMaskHookDefaultProps = {
4
4
  onChange: () => null,
5
5
  onKeyDown: () => null,
@@ -11,7 +11,11 @@ const DSMaskPhoneHookDefaultProps = {
11
11
  };
12
12
  const DSMaskRegExpHookDefaultProps = {
13
13
  ...DSMaskHookDefaultProps,
14
- filledMask: false
14
+ filledMask: false,
15
+ regExp: []
16
+ };
17
+ const DSMaskSSNDefaultProps = {
18
+ ...DSMaskHookDefaultProps
15
19
  };
16
20
  const DSMaskNumberHookDefaultProps = {
17
21
  ...DSMaskHookDefaultProps,
@@ -55,6 +59,7 @@ export {
55
59
  DSMaskPhoneHookDefaultProps,
56
60
  DSMaskPhoneHookPropsTypes,
57
61
  DSMaskRegExpHookDefaultProps,
58
- DSMaskRegExpHookPropsTypes
62
+ DSMaskRegExpHookPropsTypes,
63
+ DSMaskSSNDefaultProps
59
64
  };
60
65
  //# sourceMappingURL=react-desc-prop-types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/react-desc-prop-types.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-utilities';\nimport type { WeakValidationMap } from 'react';\nimport type React from 'react';\n\nexport declare namespace DSMaskT {\n interface HookArgs {\n valueSetter: React.Dispatch<React.SetStateAction<string>>;\n onChange?: (e: React.ChangeEvent<HTMLInputElement>, mask?: string) => void;\n onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n }\n\n interface HookReturn {\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n }\n\n export interface NumberHookArgs extends HookArgs {\n suffix: string;\n prefix: string;\n decimalPlaces: number;\n allowNegative: boolean;\n includeThousandsSeparator: boolean;\n decimalRequired: boolean;\n }\n\n export interface PhoneHookArgs extends HookArgs {\n isInternational: boolean;\n }\n\n export interface RegExpHookArgs extends HookArgs {\n filledMask: boolean;\n }\n\n export type Hook = ((args: HookArgs) => HookReturn) & { displayName: string };\n export type PhoneHook = ((args: PhoneHookArgs) => HookReturn) & { displayName: string };\n export type NumberHook = ((args: NumberHookArgs) => HookReturn) & { displayName: string };\n}\n\nexport const DSMaskHookDefaultProps: Partial<DSMaskT.HookReturn> = {\n onChange: () => null,\n onKeyDown: () => null,\n onBlur: () => null,\n};\n\nexport const DSMaskPhoneHookDefaultProps: Partial<DSMaskT.PhoneHookArgs> = {\n ...DSMaskHookDefaultProps,\n isInternational: false,\n};\nexport const DSMaskRegExpHookDefaultProps: Partial<DSMaskT.RegExpHookArgs> = {\n ...DSMaskHookDefaultProps,\n filledMask: false,\n};\n\nexport const DSMaskNumberHookDefaultProps: Partial<DSMaskT.NumberHookArgs> = {\n ...DSMaskHookDefaultProps,\n suffix: '',\n prefix: '',\n decimalPlaces: 2,\n allowNegative: false,\n includeThousandsSeparator: true,\n decimalRequired: false,\n};\n\nexport const DSMaskHookPropsTypes = {\n valueSetter: PropTypes.func.description('React set state function for the value').isRequired,\n onChange: PropTypes.func.description('Callback for onChange'),\n onKeyDown: PropTypes.func.description('Callback for onKeyDown'),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskRegExpHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n regExp: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])).description(\n 'Array with regexp or special chars per character',\n ).isRequired,\n filledMask: PropTypes.bool.description('Show blank chars positions').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskPhoneHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n isInternational: PropTypes.bool.description('Use or not internaltional phone mask number').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskNumberHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n suffix: PropTypes.string.description('String will be added at the end of the input value').defaultValue(''),\n prefix: PropTypes.string.description('String will be added at the start of the input value').defaultValue(''),\n decimalPlaces: PropTypes.number.description('Number of decimals allowed').defaultValue(2),\n allowNegative: PropTypes.bool.description('Wether the input allows negative number').defaultValue(false),\n includeThousandsSeparator: PropTypes.bool\n .description('Wether the integer part will be separated by thousands')\n .defaultValue(true),\n decimalRequired: PropTypes.bool.description('Wether decimal part is mandatory').defaultValue(false),\n} as WeakValidationMap<unknown>;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iBAAiB;AAwCnB,MAAM,yBAAsD;AAAA,EACjE,UAAU,MAAM;AAAA,EAChB,WAAW,MAAM;AAAA,EACjB,QAAQ,MAAM;AAChB;AAEO,MAAM,8BAA8D;AAAA,EACzE,GAAG;AAAA,EACH,iBAAiB;AACnB;AACO,MAAM,+BAAgE;AAAA,EAC3E,GAAG;AAAA,EACH,YAAY;AACd;AAEO,MAAM,+BAAgE;AAAA,EAC3E,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,eAAe;AAAA,EACf,2BAA2B;AAAA,EAC3B,iBAAiB;AACnB;AAEO,MAAM,uBAAuB;AAAA,EAClC,aAAa,UAAU,KAAK,YAAY,wCAAwC,EAAE;AAAA,EAClF,UAAU,UAAU,KAAK,YAAY,uBAAuB;AAAA,EAC5D,WAAW,UAAU,KAAK,YAAY,wBAAwB;AAChE;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,UAAU,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,WAAW,MAAM,CAAC,CAAC,CAAC,EAAE;AAAA,IAC/F;AAAA,EACF,EAAE;AAAA,EACF,YAAY,UAAU,KAAK,YAAY,4BAA4B,EAAE,aAAa,KAAK;AACzF;AAEO,MAAM,4BAA4B;AAAA,EACvC,GAAG;AAAA,EACH,iBAAiB,UAAU,KAAK,YAAY,6CAA6C,EAAE,aAAa,KAAK;AAC/G;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,UAAU,OAAO,YAAY,oDAAoD,EAAE,aAAa,EAAE;AAAA,EAC1G,QAAQ,UAAU,OAAO,YAAY,sDAAsD,EAAE,aAAa,EAAE;AAAA,EAC5G,eAAe,UAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EACxF,eAAe,UAAU,KAAK,YAAY,yCAAyC,EAAE,aAAa,KAAK;AAAA,EACvG,2BAA2B,UAAU,KAClC,YAAY,wDAAwD,EACpE,aAAa,IAAI;AAAA,EACpB,iBAAiB,UAAU,KAAK,YAAY,kCAAkC,EAAE,aAAa,KAAK;AACpG;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from '@elliemae/ds-props-helpers';\nimport type { WeakValidationMap } from 'react';\nimport type React from 'react';\n\nexport declare namespace DSMaskT {\n interface HookArgs {\n valueSetter: React.Dispatch<React.SetStateAction<string>>;\n onChange?: (e: React.ChangeEvent<HTMLInputElement>, mask?: string) => void;\n onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n }\n\n interface HookReturn {\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n }\n\n export interface NumberHookArgs extends HookArgs {\n suffix?: string;\n prefix?: string;\n decimalPlaces?: number;\n allowNegative?: boolean;\n includeThousandsSeparator?: boolean;\n decimalRequired?: boolean;\n }\n\n export interface PhoneHookArgs extends HookArgs {\n isInternational?: boolean;\n }\n\n export interface RegExpHookArgs extends HookArgs {\n filledMask: boolean;\n regExp: string[];\n }\n\n export type Hook = ((args: HookArgs) => HookReturn) & { displayName: string };\n export type PhoneHook = ((args: PhoneHookArgs) => HookReturn) & { displayName: string };\n export type NumberHook = ((args: NumberHookArgs) => HookReturn) & { displayName: string };\n}\n\nexport const DSMaskHookDefaultProps: Partial<DSMaskT.HookArgs> = {\n onChange: () => null,\n onKeyDown: () => null,\n onBlur: () => null,\n};\n\nexport const DSMaskPhoneHookDefaultProps: Partial<DSMaskT.PhoneHookArgs> = {\n ...DSMaskHookDefaultProps,\n isInternational: false,\n};\nexport const DSMaskRegExpHookDefaultProps: Partial<DSMaskT.RegExpHookArgs> = {\n ...DSMaskHookDefaultProps,\n filledMask: false,\n regExp: [],\n};\n\nexport const DSMaskSSNDefaultProps: Partial<DSMaskT.PhoneHookArgs> = {\n ...DSMaskHookDefaultProps,\n};\n\nexport const DSMaskNumberHookDefaultProps: Partial<DSMaskT.NumberHookArgs> = {\n ...DSMaskHookDefaultProps,\n suffix: '',\n prefix: '',\n decimalPlaces: 2,\n allowNegative: false,\n includeThousandsSeparator: true,\n decimalRequired: false,\n};\n\nexport const DSMaskHookPropsTypes = {\n valueSetter: PropTypes.func.description('React set state function for the value').isRequired,\n onChange: PropTypes.func.description('Callback for onChange'),\n onKeyDown: PropTypes.func.description('Callback for onKeyDown'),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskRegExpHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n regExp: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])).description(\n 'Array with regexp or special chars per character',\n ).isRequired,\n filledMask: PropTypes.bool.description('Show blank chars positions').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskPhoneHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n isInternational: PropTypes.bool.description('Use or not internaltional phone mask number').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskNumberHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n suffix: PropTypes.string.description('String will be added at the end of the input value').defaultValue(''),\n prefix: PropTypes.string.description('String will be added at the start of the input value').defaultValue(''),\n decimalPlaces: PropTypes.number.description('Number of decimals allowed').defaultValue(2),\n allowNegative: PropTypes.bool.description('Wether the input allows negative number').defaultValue(false),\n includeThousandsSeparator: PropTypes.bool\n .description('Wether the integer part will be separated by thousands')\n .defaultValue(true),\n decimalRequired: PropTypes.bool.description('Wether decimal part is mandatory').defaultValue(false),\n} as WeakValidationMap<unknown>;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iBAAiB;AAyCnB,MAAM,yBAAoD;AAAA,EAC/D,UAAU,MAAM;AAAA,EAChB,WAAW,MAAM;AAAA,EACjB,QAAQ,MAAM;AAChB;AAEO,MAAM,8BAA8D;AAAA,EACzE,GAAG;AAAA,EACH,iBAAiB;AACnB;AACO,MAAM,+BAAgE;AAAA,EAC3E,GAAG;AAAA,EACH,YAAY;AAAA,EACZ,QAAQ,CAAC;AACX;AAEO,MAAM,wBAAwD;AAAA,EACnE,GAAG;AACL;AAEO,MAAM,+BAAgE;AAAA,EAC3E,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,eAAe;AAAA,EACf,2BAA2B;AAAA,EAC3B,iBAAiB;AACnB;AAEO,MAAM,uBAAuB;AAAA,EAClC,aAAa,UAAU,KAAK,YAAY,wCAAwC,EAAE;AAAA,EAClF,UAAU,UAAU,KAAK,YAAY,uBAAuB;AAAA,EAC5D,WAAW,UAAU,KAAK,YAAY,wBAAwB;AAChE;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,UAAU,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,WAAW,MAAM,CAAC,CAAC,CAAC,EAAE;AAAA,IAC/F;AAAA,EACF,EAAE;AAAA,EACF,YAAY,UAAU,KAAK,YAAY,4BAA4B,EAAE,aAAa,KAAK;AACzF;AAEO,MAAM,4BAA4B;AAAA,EACvC,GAAG;AAAA,EACH,iBAAiB,UAAU,KAAK,YAAY,6CAA6C,EAAE,aAAa,KAAK;AAC/G;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,UAAU,OAAO,YAAY,oDAAoD,EAAE,aAAa,EAAE;AAAA,EAC1G,QAAQ,UAAU,OAAO,YAAY,sDAAsD,EAAE,aAAa,EAAE;AAAA,EAC5G,eAAe,UAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EACxF,eAAe,UAAU,KAAK,YAAY,yCAAyC,EAAE,aAAa,KAAK;AAAA,EACvG,2BAA2B,UAAU,KAClC,YAAY,wDAAwD,EACpE,aAAa,IAAI;AAAA,EACpB,iBAAiB,UAAU,KAAK,YAAY,kCAAkC,EAAE,aAAa,KAAK;AACpG;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/addSpecialCharacters.ts"],
4
4
  "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\n/**\n *\n * @param {string[]} maskWithoutSpecialChars An array of characters with the unfinished mask\n * @param {[string, number][]} specialCharsDescr An array of tuples. Each tuple contains a string and a position (What string to add in a particular position)\n * @param {number} maskedPos Current masked position\n * @param {string} lastKeyCode Last key code of the user\n * @returns {[string, number]} A tuple containing the final mask and the final masked position\n */\nexport const addSpecialCharacters = (\n maskWithoutSpecialChars: string[],\n specialCharsDescr: [string, number][],\n maskedPos: number,\n lastKeyCode: string,\n): [string, number] => {\n const finalMask = maskWithoutSpecialChars;\n let finalMaskedPos = maskedPos;\n\n // We insert the special chars in the respective positions, tweaking the masked pos\n specialCharsDescr.forEach(([chars, pos]) => {\n if (finalMask.length > pos) {\n finalMask.splice(pos, 0, ...chars);\n if (finalMaskedPos >= pos) finalMaskedPos += chars.length;\n }\n });\n\n if (lastKeyCode !== 'Backspace' && finalMaskedPos < finalMask.length) {\n // If not erasing, move the cursor forward if we are in a special chars area\n specialCharsDescr.forEach(([chars, pos]) => {\n if (finalMaskedPos === pos) finalMaskedPos += chars.length;\n });\n } else if (lastKeyCode === 'Backspace' && finalMaskedPos) {\n // If erasing, move the cursor back if we are in a special chars area\n for (let i = specialCharsDescr.length - 1; i >= 0; i -= 1) {\n if (\n specialCharsDescr[i][1] + 1 <= finalMaskedPos &&\n finalMaskedPos <= specialCharsDescr[i][1] + specialCharsDescr[i][0].length\n )\n [, finalMaskedPos] = specialCharsDescr[i];\n }\n }\n\n return [finalMask.join(''), finalMaskedPos];\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACShB,MAAM,uBAAuB,CAClC,yBACA,mBACA,WACA,gBACqB;AACrB,QAAM,YAAY;AAClB,MAAI,iBAAiB;AAGrB,oBAAkB,QAAQ,CAAC,CAAC,OAAO,GAAG,MAAM;AAC1C,QAAI,UAAU,SAAS,KAAK;AAC1B,gBAAU,OAAO,KAAK,GAAG,GAAG,KAAK;AACjC,UAAI,kBAAkB;AAAK,0BAAkB,MAAM;AAAA,IACrD;AAAA,EACF,CAAC;AAED,MAAI,gBAAgB,eAAe,iBAAiB,UAAU,QAAQ;AAEpE,sBAAkB,QAAQ,CAAC,CAAC,OAAO,GAAG,MAAM;AAC1C,UAAI,mBAAmB;AAAK,0BAAkB,MAAM;AAAA,IACtD,CAAC;AAAA,EACH,WAAW,gBAAgB,eAAe,gBAAgB;AAExD,aAAS,IAAI,kBAAkB,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;AACzD,UACE,kBAAkB,GAAG,KAAK,KAAK,kBAC/B,kBAAkB,kBAAkB,GAAG,KAAK,kBAAkB,GAAG,GAAG;AAEpE,SAAC,EAAE,cAAc,IAAI,kBAAkB;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO,CAAC,UAAU,KAAK,EAAE,GAAG,cAAc;AAC5C;",
5
+ "mappings": "AAAA,YAAY,WAAW;ACShB,MAAM,uBAAuB,CAClC,yBACA,mBACA,WACA,gBACqB;AACrB,QAAM,YAAY;AAClB,MAAI,iBAAiB;AAGrB,oBAAkB,QAAQ,CAAC,CAAC,OAAO,GAAG,MAAM;AAC1C,QAAI,UAAU,SAAS,KAAK;AAC1B,gBAAU,OAAO,KAAK,GAAG,GAAG,KAAK;AACjC,UAAI,kBAAkB;AAAK,0BAAkB,MAAM;AAAA,IACrD;AAAA,EACF,CAAC;AAED,MAAI,gBAAgB,eAAe,iBAAiB,UAAU,QAAQ;AAEpE,sBAAkB,QAAQ,CAAC,CAAC,OAAO,GAAG,MAAM;AAC1C,UAAI,mBAAmB;AAAK,0BAAkB,MAAM;AAAA,IACtD,CAAC;AAAA,EACH,WAAW,gBAAgB,eAAe,gBAAgB;AAExD,aAAS,IAAI,kBAAkB,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;AACzD,UACE,kBAAkB,CAAC,EAAE,CAAC,IAAI,KAAK,kBAC/B,kBAAkB,kBAAkB,CAAC,EAAE,CAAC,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE;AAEpE,SAAC,EAAE,cAAc,IAAI,kBAAkB,CAAC;AAAA,IAC5C;AAAA,EACF;AAEA,SAAO,CAAC,UAAU,KAAK,EAAE,GAAG,cAAc;AAC5C;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/getPartialMaskedPos.ts"],
4
4
  "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export const getPartialMaskedPos = (rawValue: string, maskWithoutSpecialChars: string[], cursorPos: number): number => {\n let maskedPos = 0;\n for (let i = 0; i < cursorPos; i += 1) {\n if (maskWithoutSpecialChars[maskedPos] === rawValue[i]) maskedPos += 1;\n }\n return maskedPos;\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACAhB,MAAM,sBAAsB,CAAC,UAAkB,yBAAmC,cAA8B;AACrH,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,WAAW,KAAK,GAAG;AACrC,QAAI,wBAAwB,eAAe,SAAS;AAAI,mBAAa;AAAA,EACvE;AACA,SAAO;AACT;",
5
+ "mappings": "AAAA,YAAY,WAAW;ACAhB,MAAM,sBAAsB,CAAC,UAAkB,yBAAmC,cAA8B;AACrH,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,WAAW,KAAK,GAAG;AACrC,QAAI,wBAAwB,SAAS,MAAM,SAAS,CAAC;AAAG,mBAAa;AAAA,EACvE;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- export * from "./addSpecialCharacters";
3
- export * from "./getPartialMaskedPos";
4
- export * from "./setCursorPosition";
5
- export * from "./sharedFilters";
6
- export * from "./flatStringArray";
2
+ export * from "./addSpecialCharacters.js";
3
+ export * from "./getPartialMaskedPos.js";
4
+ export * from "./setCursorPosition.js";
5
+ export * from "./sharedFilters.js";
6
+ export * from "./flatStringArray.js";
7
7
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/index.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './addSpecialCharacters';\nexport * from './getPartialMaskedPos';\nexport * from './setCursorPosition';\nexport * from './sharedFilters';\nexport * from './flatStringArray';\n"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './addSpecialCharacters.js';\nexport * from './getPartialMaskedPos.js';\nexport * from './setCursorPosition.js';\nexport * from './sharedFilters.js';\nexport * from './flatStringArray.js';\n"],
5
5
  "mappings": "AAAA,YAAY,WAAW;ACAvB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-form-helpers-mask-hooks",
3
- "version": "3.16.0-next.2",
3
+ "version": "3.16.0-next.21",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Controlled Form Helpers - Text Masks Hooks",
6
6
  "files": [
@@ -35,20 +35,21 @@
35
35
  "indent": 4
36
36
  },
37
37
  "dependencies": {
38
- "@elliemae/ds-system": "3.16.0-next.2",
39
- "@elliemae/ds-utilities": "3.16.0-next.2"
38
+ "@elliemae/ds-props-helpers": "3.16.0-next.21",
39
+ "@elliemae/ds-system": "3.16.0-next.21",
40
+ "@elliemae/ds-utilities": "3.16.0-next.21"
40
41
  },
41
42
  "devDependencies": {
42
- "@elliemae/pui-theme": "~2.6.0",
43
+ "@elliemae/pui-theme": "~2.7.0",
43
44
  "@testing-library/dom": "~8.19.0",
44
45
  "@testing-library/react": "~12.1.3",
45
46
  "@testing-library/user-event": "~13.5.0",
46
- "styled-components": "~5.3.6",
47
+ "styled-components": "~5.3.9",
47
48
  "styled-system": "~5.1.5",
48
- "@elliemae/ds-form-input-text": "3.16.0-next.2"
49
+ "@elliemae/ds-form-input-text": "3.16.0-next.21"
49
50
  },
50
51
  "peerDependencies": {
51
- "@elliemae/pui-theme": "~2.6.0",
52
+ "@elliemae/pui-theme": "~2.7.0",
52
53
  "react": "^17.0.2",
53
54
  "react-dom": "^17.0.2",
54
55
  "styled-components": "~5.3.6",
@@ -65,7 +66,7 @@
65
66
  "eslint:fix": "eslint --ext='.js,.jsx,.test.js,.ts,.tsx' --fix --config='../../.eslintrc.js' src/",
66
67
  "dts": "node ../../scripts/dts.mjs",
67
68
  "build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs",
68
- "dev:build": "pnpm --filter {.}... build && pnpm --filter {.}... dts",
69
+ "dev:build": "pnpm --filter {.}... build",
69
70
  "dev:install": "pnpm --filter {.}... i --no-lockfile && pnpm run dev:build",
70
71
  "checkDeps": "npx -yes ../ds-codemods check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
71
72
  }
@@ -1,5 +0,0 @@
1
- export * from './usePhoneMask';
2
- export * from './useNumberMask';
3
- export * from './useSSNMask';
4
- export * from './useRegExpMask';
5
- export * from './useZipCodeMask';
@@ -1,4 +0,0 @@
1
- import type { DSMaskT } from '../react-desc-prop-types';
2
- export declare const useNumberMask: DSMaskT.NumberHook;
3
- export declare const getNumberMaskedValue: (value: string, opts: DSMaskT.NumberHookArgs) => string;
4
- export declare const UseNumberMaskWithSchema: import("@elliemae/ds-utilities/dist/types/props-helpers/propTypes/types").DocumentedReactComponent<DSMaskT.NumberHookArgs>;
@@ -1,4 +0,0 @@
1
- import type { DSMaskT } from '../react-desc-prop-types';
2
- export declare const usePhoneMask: DSMaskT.Hook;
3
- export declare const getPhoneMaskedValue: (value: string, opts: Partial<DSMaskT.PhoneHookArgs>) => string;
4
- export declare const UsePhoneMaskWithSchema: import("@elliemae/ds-utilities/dist/types/props-helpers/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,3 +0,0 @@
1
- import type { DSMaskT } from '../react-desc-prop-types';
2
- export declare const useRegExpMask: DSMaskT.Hook;
3
- export declare const UseRegExpMaskWithSchema: import("@elliemae/ds-utilities/dist/types/props-helpers/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,4 +0,0 @@
1
- import type { DSMaskT } from '../react-desc-prop-types';
2
- export declare const useSSNMask: DSMaskT.Hook;
3
- export declare const getSSNMaskedValue: (value: string) => string;
4
- export declare const UseSSNMaskWithSchema: import("@elliemae/ds-utilities/dist/types/props-helpers/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,4 +0,0 @@
1
- import type { DSMaskT } from '../react-desc-prop-types';
2
- export declare const useZipCodeMask: DSMaskT.Hook;
3
- export declare const getUseZipMaskedValue: (value: string) => string;
4
- export declare const UseZipCodeMaskWithSchema: import("@elliemae/ds-utilities/dist/types/props-helpers/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,2 +0,0 @@
1
- export * from './hooks';
2
- export type { DSMaskT } from './react-desc-prop-types';
@@ -1,46 +0,0 @@
1
- import type { WeakValidationMap } from 'react';
2
- import type React from 'react';
3
- export declare namespace DSMaskT {
4
- interface HookArgs {
5
- valueSetter: React.Dispatch<React.SetStateAction<string>>;
6
- onChange?: (e: React.ChangeEvent<HTMLInputElement>, mask?: string) => void;
7
- onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
8
- onBlur?: React.FocusEventHandler<HTMLInputElement>;
9
- }
10
- interface HookReturn {
11
- onChange: React.ChangeEventHandler<HTMLInputElement>;
12
- onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;
13
- onBlur?: React.FocusEventHandler<HTMLInputElement>;
14
- }
15
- interface NumberHookArgs extends HookArgs {
16
- suffix: string;
17
- prefix: string;
18
- decimalPlaces: number;
19
- allowNegative: boolean;
20
- includeThousandsSeparator: boolean;
21
- decimalRequired: boolean;
22
- }
23
- interface PhoneHookArgs extends HookArgs {
24
- isInternational: boolean;
25
- }
26
- interface RegExpHookArgs extends HookArgs {
27
- filledMask: boolean;
28
- }
29
- type Hook = ((args: HookArgs) => HookReturn) & {
30
- displayName: string;
31
- };
32
- type PhoneHook = ((args: PhoneHookArgs) => HookReturn) & {
33
- displayName: string;
34
- };
35
- type NumberHook = ((args: NumberHookArgs) => HookReturn) & {
36
- displayName: string;
37
- };
38
- }
39
- export declare const DSMaskHookDefaultProps: Partial<DSMaskT.HookReturn>;
40
- export declare const DSMaskPhoneHookDefaultProps: Partial<DSMaskT.PhoneHookArgs>;
41
- export declare const DSMaskRegExpHookDefaultProps: Partial<DSMaskT.RegExpHookArgs>;
42
- export declare const DSMaskNumberHookDefaultProps: Partial<DSMaskT.NumberHookArgs>;
43
- export declare const DSMaskHookPropsTypes: WeakValidationMap<unknown>;
44
- export declare const DSMaskRegExpHookPropsTypes: WeakValidationMap<unknown>;
45
- export declare const DSMaskPhoneHookPropsTypes: WeakValidationMap<unknown>;
46
- export declare const DSMaskNumberHookPropsTypes: WeakValidationMap<unknown>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * @param {string[]} maskWithoutSpecialChars An array of characters with the unfinished mask
4
- * @param {[string, number][]} specialCharsDescr An array of tuples. Each tuple contains a string and a position (What string to add in a particular position)
5
- * @param {number} maskedPos Current masked position
6
- * @param {string} lastKeyCode Last key code of the user
7
- * @returns {[string, number]} A tuple containing the final mask and the final masked position
8
- */
9
- export declare const addSpecialCharacters: (maskWithoutSpecialChars: string[], specialCharsDescr: [string, number][], maskedPos: number, lastKeyCode: string) => [string, number];
@@ -1 +0,0 @@
1
- export declare const flatStringArray: (stringArray: string[]) => string[];
@@ -1 +0,0 @@
1
- export declare const getPartialMaskedPos: (rawValue: string, maskWithoutSpecialChars: string[], cursorPos: number) => number;
@@ -1,5 +0,0 @@
1
- export * from './addSpecialCharacters';
2
- export * from './getPartialMaskedPos';
3
- export * from './setCursorPosition';
4
- export * from './sharedFilters';
5
- export * from './flatStringArray';
@@ -1 +0,0 @@
1
- export declare const setCursorPosition: (input: HTMLInputElement, position: number) => void;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * @param {string[]} charactersToFilter An array of characters to filter from
4
- * @returns [string] the filtered array including only 0~9 characters
5
- */
6
- export declare const filterNumbersOnly: (charactersToFilter: string[]) => string[];