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

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 (32) hide show
  1. package/dist/cjs/hooks/useNumberMask.js +4 -3
  2. package/dist/cjs/hooks/useNumberMask.js.map +2 -2
  3. package/dist/cjs/hooks/usePhoneMask.js +4 -3
  4. package/dist/cjs/hooks/usePhoneMask.js.map +2 -2
  5. package/dist/cjs/hooks/useRegExpMask.js +4 -3
  6. package/dist/cjs/hooks/useRegExpMask.js.map +2 -2
  7. package/dist/cjs/hooks/useSSNMask.js +4 -3
  8. package/dist/cjs/hooks/useSSNMask.js.map +2 -2
  9. package/dist/cjs/hooks/useZipCodeMask.js +4 -3
  10. package/dist/cjs/hooks/useZipCodeMask.js.map +2 -2
  11. package/dist/cjs/package.json +7 -0
  12. package/dist/cjs/react-desc-prop-types.js +13 -13
  13. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  14. package/dist/esm/hooks/useNumberMask.js +2 -6
  15. package/dist/esm/hooks/useNumberMask.js.map +2 -2
  16. package/dist/esm/hooks/usePhoneMask.js +2 -6
  17. package/dist/esm/hooks/usePhoneMask.js.map +2 -2
  18. package/dist/esm/hooks/useRegExpMask.js +2 -6
  19. package/dist/esm/hooks/useRegExpMask.js.map +2 -2
  20. package/dist/esm/hooks/useSSNMask.js +2 -6
  21. package/dist/esm/hooks/useSSNMask.js.map +2 -2
  22. package/dist/esm/hooks/useZipCodeMask.js +2 -6
  23. package/dist/esm/hooks/useZipCodeMask.js.map +2 -2
  24. package/dist/esm/package.json +7 -0
  25. package/dist/esm/react-desc-prop-types.js +1 -1
  26. package/dist/esm/react-desc-prop-types.js.map +1 -1
  27. package/dist/types/hooks/useNumberMask.d.ts +1 -1
  28. package/dist/types/hooks/usePhoneMask.d.ts +1 -1
  29. package/dist/types/hooks/useRegExpMask.d.ts +1 -1
  30. package/dist/types/hooks/useSSNMask.d.ts +1 -1
  31. package/dist/types/hooks/useZipCodeMask.d.ts +1 -1
  32. package/package.json +6 -5
@@ -31,6 +31,7 @@ __export(useNumberMask_exports, {
31
31
  module.exports = __toCommonJS(useNumberMask_exports);
32
32
  var React = __toESM(require("react"));
33
33
  var import_react = require("react");
34
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
34
35
  var import_ds_utilities = require("@elliemae/ds-utilities");
35
36
  var import_utils = require("../utils");
36
37
  var import_react_desc_prop_types = require("../react-desc-prop-types");
@@ -84,8 +85,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode, opts) => {
84
85
  return [maskedValueString, maskedPos];
85
86
  };
86
87
  const useNumberMask = (props) => {
87
- const propsWithDefault = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskNumberHookDefaultProps);
88
- (0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskNumberHookPropsTypes, "useNumberMask");
88
+ const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskNumberHookDefaultProps);
89
+ (0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskNumberHookPropsTypes, "useNumberMask");
89
90
  const {
90
91
  valueSetter,
91
92
  onChange: userOnChange,
@@ -160,6 +161,6 @@ const getNumberMaskedValue = (value, opts) => {
160
161
  return maskedValue;
161
162
  };
162
163
  useNumberMask.displayName = "useNumberMask";
163
- const UseNumberMaskWithSchema = (0, import_ds_utilities.describe)(useNumberMask);
164
+ const UseNumberMaskWithSchema = (0, import_ds_props_helpers.describe)(useNumberMask);
164
165
  UseNumberMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskNumberHookPropsTypes;
165
166
  //# sourceMappingURL=useNumberMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useNumberMask.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-params */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport 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 { setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from '../react-desc-prop-types';\n\nconst addThousandsSeparator = (n: string, separator: string) => n.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: DSMaskT.NumberHookArgs,\n): [string, number] => {\n const { includeThousandsSeparator, allowNegative, prefix, suffix, decimalPlaces, decimalRequired } = opts;\n const THOUSANDSSEPARATOR = ',';\n\n let dotIdx = -1;\n // allow minus sign before and after the preffix\n let finalPrefix = [prefix.length, 0].includes(rawValue.indexOf('-')) && allowNegative ? '-' : '';\n\n let maskedValue = String(rawValue).split('').filter((char, idx) => {\n // we take only the first dot\n const validChar = (char >= '0' && char <= '9') || (char === '.' && dotIdx === -1 && decimalPlaces);\n if (char === '.' && validChar) dotIdx = idx;\n return validChar;\n });\n\n if (prefix && maskedValue.length) finalPrefix += prefix;\n\n // REMOVE FOLLOWING ZEROS IN INTEGER PART AFTER LEADER ZERO NUMBER\n while (maskedValue.length >= 2 && maskedValue[0] === '0' && maskedValue[1] !== '.') {\n maskedValue = maskedValue.splice(1);\n }\n dotIdx = maskedValue.findIndex((char) => char === '.');\n\n let integer = maskedValue.slice(0, dotIdx !== -1 ? dotIdx : maskedValue.length);\n const decimal = maskedValue.slice(dotIdx, dotIdx + decimalPlaces + 1);\n // ADDING THOUSANDS SEPARATOR\n if (includeThousandsSeparator) {\n integer = addThousandsSeparator(integer.join(''), THOUSANDSSEPARATOR).split('');\n }\n\n // MERGIN INT AND DECIMAL IF NECCESSARY\n if (dotIdx !== -1 && !(lastKeyCode === 'Backspace' && decimal.length === 1)) {\n if (integer.length) {\n maskedValue = [...integer, ...decimal];\n } else {\n // if theres no integer add a zero to the left of the dot to cover .23 => 0.23 case\n maskedValue = ['0', ...decimal];\n }\n } else {\n // If decimal is required we add a dot after integer if exists\n maskedValue = decimalRequired && integer.length ? [...integer, '.'] : integer;\n }\n\n // remove orphans prefix for example \"-$\"\n if (lastKeyCode === 'Backspace' && maskedValue.length === 0) {\n finalPrefix = '';\n }\n\n // SET REAL CURSOR POSITION AFTER ADDING DOT and COMMAS SEPARATORS\n let maskedPos = 0;\n\n // 0 leading case we move the cursor to continue typing\n if (maskedValue[maskedPos] === '0' && cursorPos === 1 + prefix.length) maskedPos += 1;\n\n for (let i = 0; i < cursorPos; i += 1) {\n if (maskedValue[maskedPos] === THOUSANDSSEPARATOR) maskedPos += 1;\n if (maskedValue[maskedPos] === rawValue[i]) maskedPos += 1;\n }\n\n maskedPos += finalPrefix.length;\n\n const finalSuffix = maskedValue.length ? suffix : '';\n\n const maskedValueString = finalPrefix + maskedValue.join('') + finalSuffix;\n return [maskedValueString, maskedPos];\n};\n\nexport const useNumberMask: DSMaskT.NumberHook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskNumberHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskNumberHookPropsTypes, 'useNumberMask');\n\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n ...opts\n } = 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 onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const maskedValue = e.target.value;\n const dotIdx = maskedValue.indexOf('.');\n const minusIndex = maskedValue.indexOf('-');\n\n const { decimalRequired, decimalPlaces, suffix } = opts;\n\n const suffixIndex = suffix.length ? maskedValue.indexOf(suffix) : -1;\n\n if (decimalRequired) {\n if (dotIdx > -1) {\n const decimal = maskedValue.slice(dotIdx + 1, suffix.length ? -suffix.length : maskedValue.length);\n\n let zerosRest = '';\n while (decimal.length + zerosRest.length !== decimalPlaces) {\n zerosRest += '0';\n }\n\n valueSetter((suffix.length ? maskedValue.slice(0, suffixIndex) : maskedValue) + zerosRest + suffix);\n }\n } else if (maskedValue.length - suffix.length - 1 === dotIdx) {\n // removing orphans dots\n valueSetter(maskedValue.replace('.', ''));\n } else if (maskedValue.length - 1 === minusIndex) {\n // removing orphans minus\n valueSetter(maskedValue.replace('-', ''));\n }\n if (userOnBlur) userOnBlur(e);\n },\n [userOnBlur, valueSetter, opts],\n );\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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n opts as DSMaskT.NumberHookArgs,\n );\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, opts],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nexport const getNumberMaskedValue = (value: string, opts: DSMaskT.NumberHookArgs) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nuseNumberMask.displayName = 'useNumberMask';\nexport const UseNumberMaskWithSchema = describe(useNumberMask);\nUseNumberMaskWithSchema.propTypes = DSMaskNumberHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAA8C;AAC9C,0BAKO;AACP,mBAAkC;AAElC,mCAAyE;AAEzE,MAAM,wBAAwB,CAAC,GAAW,cAAsB,EAAE,QAAQ,yBAAyB,SAAS;AAE5G,MAAM,eAAe,CACnB,UACA,WACA,aACA,SACqB;AACrB,QAAM,EAAE,2BAA2B,eAAe,QAAQ,QAAQ,eAAe,gBAAgB,IAAI;AACrG,QAAM,qBAAqB;AAE3B,MAAI,SAAS;AAEb,MAAI,cAAc,CAAC,OAAO,QAAQ,CAAC,EAAE,SAAS,SAAS,QAAQ,GAAG,CAAC,KAAK,gBAAgB,MAAM;AAE9F,MAAI,cAAc,OAAO,QAAQ,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,MAAM,QAAQ;AAEjE,UAAM,YAAa,QAAQ,OAAO,QAAQ,OAAS,SAAS,OAAO,WAAW,MAAM;AACpF,QAAI,SAAS,OAAO;AAAW,eAAS;AACxC,WAAO;AAAA,EACT,CAAC;AAED,MAAI,UAAU,YAAY;AAAQ,mBAAe;AAGjD,SAAO,YAAY,UAAU,KAAK,YAAY,OAAO,OAAO,YAAY,OAAO,KAAK;AAClF,kBAAc,YAAY,OAAO,CAAC;AAAA,EACpC;AACA,WAAS,YAAY,UAAU,CAAC,SAAS,SAAS,GAAG;AAErD,MAAI,UAAU,YAAY,MAAM,GAAG,WAAW,KAAK,SAAS,YAAY,MAAM;AAC9E,QAAM,UAAU,YAAY,MAAM,QAAQ,SAAS,gBAAgB,CAAC;AAEpE,MAAI,2BAA2B;AAC7B,cAAU,sBAAsB,QAAQ,KAAK,EAAE,GAAG,kBA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,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,cAAc,IAAI;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,OAAe,SAAiC;AACnF,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,cAAc,cAAc;AACrB,MAAM,8BAA0B,8BAAS,aAAa;AAC7D,wBAAwB,YAAY;",
4
+ "sourcesContent": ["/* eslint-disable max-params */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport 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 { setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from '../react-desc-prop-types';\n\nconst addThousandsSeparator = (n: string, separator: string) => n.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: DSMaskT.NumberHookArgs,\n): [string, number] => {\n const { includeThousandsSeparator, allowNegative, prefix, suffix, decimalPlaces, decimalRequired } = opts;\n const THOUSANDSSEPARATOR = ',';\n\n let dotIdx = -1;\n // allow minus sign before and after the preffix\n let finalPrefix = [prefix.length, 0].includes(rawValue.indexOf('-')) && allowNegative ? '-' : '';\n\n let maskedValue = String(rawValue)\n .split('')\n .filter((char, idx) => {\n // we take only the first dot\n const validChar = (char >= '0' && char <= '9') || (char === '.' && dotIdx === -1 && decimalPlaces);\n if (char === '.' && validChar) dotIdx = idx;\n return validChar;\n });\n\n if (prefix && maskedValue.length) finalPrefix += prefix;\n\n // REMOVE FOLLOWING ZEROS IN INTEGER PART AFTER LEADER ZERO NUMBER\n while (maskedValue.length >= 2 && maskedValue[0] === '0' && maskedValue[1] !== '.') {\n maskedValue = maskedValue.splice(1);\n }\n dotIdx = maskedValue.findIndex((char) => char === '.');\n\n let integer = maskedValue.slice(0, dotIdx !== -1 ? dotIdx : maskedValue.length);\n const decimal = maskedValue.slice(dotIdx, dotIdx + decimalPlaces + 1);\n // ADDING THOUSANDS SEPARATOR\n if (includeThousandsSeparator) {\n integer = addThousandsSeparator(integer.join(''), THOUSANDSSEPARATOR).split('');\n }\n\n // MERGIN INT AND DECIMAL IF NECCESSARY\n if (dotIdx !== -1 && !(lastKeyCode === 'Backspace' && decimal.length === 1)) {\n if (integer.length) {\n maskedValue = [...integer, ...decimal];\n } else {\n // if theres no integer add a zero to the left of the dot to cover .23 => 0.23 case\n maskedValue = ['0', ...decimal];\n }\n } else {\n // If decimal is required we add a dot after integer if exists\n maskedValue = decimalRequired && integer.length ? [...integer, '.'] : integer;\n }\n\n // remove orphans prefix for example \"-$\"\n if (lastKeyCode === 'Backspace' && maskedValue.length === 0) {\n finalPrefix = '';\n }\n\n // SET REAL CURSOR POSITION AFTER ADDING DOT and COMMAS SEPARATORS\n let maskedPos = 0;\n\n // 0 leading case we move the cursor to continue typing\n if (maskedValue[maskedPos] === '0' && cursorPos === 1 + prefix.length) maskedPos += 1;\n\n for (let i = 0; i < cursorPos; i += 1) {\n if (maskedValue[maskedPos] === THOUSANDSSEPARATOR) maskedPos += 1;\n if (maskedValue[maskedPos] === rawValue[i]) maskedPos += 1;\n }\n\n maskedPos += finalPrefix.length;\n\n const finalSuffix = maskedValue.length ? suffix : '';\n\n const maskedValueString = finalPrefix + maskedValue.join('') + finalSuffix;\n return [maskedValueString, maskedPos];\n};\n\nexport const useNumberMask: DSMaskT.NumberHook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskNumberHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskNumberHookPropsTypes, 'useNumberMask');\n\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n ...opts\n } = 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 onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const maskedValue = e.target.value;\n const dotIdx = maskedValue.indexOf('.');\n const minusIndex = maskedValue.indexOf('-');\n\n const { decimalRequired, decimalPlaces, suffix } = opts;\n\n const suffixIndex = suffix.length ? maskedValue.indexOf(suffix) : -1;\n\n if (decimalRequired) {\n if (dotIdx > -1) {\n const decimal = maskedValue.slice(dotIdx + 1, suffix.length ? -suffix.length : maskedValue.length);\n\n let zerosRest = '';\n while (decimal.length + zerosRest.length !== decimalPlaces) {\n zerosRest += '0';\n }\n\n valueSetter((suffix.length ? maskedValue.slice(0, suffixIndex) : maskedValue) + zerosRest + suffix);\n }\n } else if (maskedValue.length - suffix.length - 1 === dotIdx) {\n // removing orphans dots\n valueSetter(maskedValue.replace('.', ''));\n } else if (maskedValue.length - 1 === minusIndex) {\n // removing orphans minus\n valueSetter(maskedValue.replace('-', ''));\n }\n if (userOnBlur) userOnBlur(e);\n },\n [userOnBlur, valueSetter, opts],\n );\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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n opts as DSMaskT.NumberHookArgs,\n );\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, opts],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nexport const getNumberMaskedValue = (value: string, opts: DSMaskT.NumberHookArgs) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nuseNumberMask.displayName = 'useNumberMask';\nexport const UseNumberMaskWithSchema = describe(useNumberMask);\nUseNumberMaskWithSchema.propTypes = DSMaskNumberHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAA8C;AAC9C,8BAAuF;AACvF,0BAAuC;AACvC,mBAAkC;AAElC,mCAAyE;AAEzE,MAAM,wBAAwB,CAAC,GAAW,cAAsB,EAAE,QAAQ,yBAAyB,SAAS;AAE5G,MAAM,eAAe,CACnB,UACA,WACA,aACA,SACqB;AACrB,QAAM,EAAE,2BAA2B,eAAe,QAAQ,QAAQ,eAAe,gBAAgB,IAAI;AACrG,QAAM,qBAAqB;AAE3B,MAAI,SAAS;AAEb,MAAI,cAAc,CAAC,OAAO,QAAQ,CAAC,EAAE,SAAS,SAAS,QAAQ,GAAG,CAAC,KAAK,gBAAgB,MAAM;AAE9F,MAAI,cAAc,OAAO,QAAQ,EAC9B,MAAM,EAAE,EACR,OAAO,CAAC,MAAM,QAAQ;AAErB,UAAM,YAAa,QAAQ,OAAO,QAAQ,OAAS,SAAS,OAAO,WAAW,MAAM;AACpF,QAAI,SAAS,OAAO;AAAW,eAAS;AACxC,WAAO;AAAA,EACT,CAAC;AAEH,MAAI,UAAU,YAAY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a;AAAA,EAChB;AAEA,QAAM,eAAuD;AAAA,IAC3D,CAAC,MAAM;AACL,YAAM,CAAC,MAAM,SAAS,IAAI;AAAA,QACxB,EAAE,OAAO;AAAA,QACT,EAAE,OAAO,gBAAgB;AAAA,QACzB,YAAY;AAAA,QACZ;AAAA,MACF;AACA,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,UAAM,gCAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,cAAc,IAAI;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,OAAe,SAAiC;AACnF,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,cAAc,cAAc;AACrB,MAAM,8BAA0B,kCAAS,aAAa;AAC7D,wBAAwB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -31,6 +31,7 @@ __export(usePhoneMask_exports, {
31
31
  module.exports = __toCommonJS(usePhoneMask_exports);
32
32
  var React = __toESM(require("react"));
33
33
  var import_react = require("react");
34
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
34
35
  var import_ds_utilities = require("@elliemae/ds-utilities");
35
36
  var import_utils = require("../utils");
36
37
  var import_react_desc_prop_types = require("../react-desc-prop-types");
@@ -65,8 +66,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode, opts) => {
65
66
  );
66
67
  };
67
68
  const usePhoneMask = (props) => {
68
- const propsWithDefault = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskPhoneHookDefaultProps);
69
- (0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskPhoneHookPropsTypes, "usePhoneMask");
69
+ const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskPhoneHookDefaultProps);
70
+ (0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskPhoneHookPropsTypes, "usePhoneMask");
70
71
  const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, onBlur, ...opts } = propsWithDefault;
71
72
  const lastKeyCode = (0, import_react.useRef)("Unidentified");
72
73
  const scheduleAfterRender = (0, import_ds_utilities.useCallbackAfterRender)(true);
@@ -103,6 +104,6 @@ const getPhoneMaskedValue = (value, opts) => {
103
104
  return maskedValue;
104
105
  };
105
106
  usePhoneMask.displayName = "usePhoneMask";
106
- const UsePhoneMaskWithSchema = (0, import_ds_utilities.describe)(usePhoneMask);
107
+ const UsePhoneMaskWithSchema = (0, import_ds_props_helpers.describe)(usePhoneMask);
107
108
  UsePhoneMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskPhoneHookPropsTypes;
108
109
  //# sourceMappingURL=usePhoneMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/usePhoneMask.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-params */\nimport 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 { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from '../react-desc-prop-types';\n\nconst phoneSpecialChars: [string, number][] = [\n ['(', 0],\n [') ', 4],\n [' - ', 9],\n];\n\nconst internationalPhoneSpecialChars: [string, number][] = [\n ['+1 (', 0],\n [') ', 7],\n [' - ', 12],\n];\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: Partial<DSMaskT.PhoneHookArgs>,\n) => {\n const characters = String(rawValue).split('');\n // Work with digits only\n const { isInternational } = opts;\n let maskedValue = characters.filter((char, idx, array) => {\n if (isInternational && idx === 1 && char === '1' && array[0] === '+') {\n return false;\n }\n return 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 10 digits\n maskedValue = maskedValue.slice(0, 10);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(\n maskedValue,\n isInternational ? internationalPhoneSpecialChars : phoneSpecialChars,\n maskedPos,\n lastKeyCode,\n );\n};\n\nexport const usePhoneMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskPhoneHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskPhoneHookPropsTypes, 'usePhoneMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, onBlur, ...opts } = 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, opts);\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, opts, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getPhoneMaskedValue = (value: string, opts: Partial<DSMaskT.PhoneHookArgs>) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nusePhoneMask.displayName = 'usePhoneMask';\nexport const UsePhoneMaskWithSchema = describe(usePhoneMask);\nUsePhoneMaskWithSchema.propTypes = DSMaskPhoneHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,mBAA8C;AAC9C,0BAKO;AACP,mBAA6E;AAE7E,mCAAuE;AAEvE,MAAM,oBAAwC;AAAA,EAC5C,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,MAAM,CAAC;AAAA,EACR,CAAC,OAAO,CAAC;AACX;AAEA,MAAM,iCAAqD;AAAA,EACzD,CAAC,QAAQ,CAAC;AAAA,EACV,CAAC,MAAM,CAAC;AAAA,EACR,CAAC,OAAO,EAAE;AACZ;AAEA,MAAM,eAAe,CACnB,UACA,WACA,aACA,SACG;AACH,QAAM,aAAa,OAAO,QAAQ,EAAE,MAAM,EAAE;AAE5C,QAAM,EAAE,gBAAgB,IAAI;AAC5B,MAAI,cAAc,WAAW,OAAO,CAAC,MAAM,KAAK,UAAU;AACxD,QAAI,mBAAmB,QAAQ,KAAK,SAAS,OAAO,MAAM,OAAO,KAAK;AACpE,aAAO;AAAA,IACT;AACA,WAAO,QAAQ,OAAO,QAAQ;AAAA,EAChC,CAAC;AAED,SAAO,YAAY,UAAU,YAAY,OAAO;AA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I;AACpE,SAAO;AACT;AAEA,aAAa,cAAc;AACpB,MAAM,6BAAyB,8BAAS,YAAY;AAC3D,uBAAuB,YAAY;",
4
+ "sourcesContent": ["/* eslint-disable max-params */\nimport 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';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from '../react-desc-prop-types';\n\nconst phoneSpecialChars: [string, number][] = [\n ['(', 0],\n [') ', 4],\n [' - ', 9],\n];\n\nconst internationalPhoneSpecialChars: [string, number][] = [\n ['+1 (', 0],\n [') ', 7],\n [' - ', 12],\n];\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: Partial<DSMaskT.PhoneHookArgs>,\n) => {\n const characters = String(rawValue).split('');\n // Work with digits only\n const { isInternational } = opts;\n let maskedValue = characters.filter((char, idx, array) => {\n if (isInternational && idx === 1 && char === '1' && array[0] === '+') {\n return false;\n }\n return 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 10 digits\n maskedValue = maskedValue.slice(0, 10);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(\n maskedValue,\n isInternational ? internationalPhoneSpecialChars : phoneSpecialChars,\n maskedPos,\n lastKeyCode,\n );\n};\n\nexport const usePhoneMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskPhoneHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskPhoneHookPropsTypes, 'usePhoneMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, onBlur, ...opts } = 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, opts);\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, opts, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getPhoneMaskedValue = (value: string, opts: Partial<DSMaskT.PhoneHookArgs>) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nusePhoneMask.displayName = 'usePhoneMask';\nexport const UsePhoneMaskWithSchema = describe(usePhoneMask);\nUsePhoneMaskWithSchema.propTypes = DSMaskPhoneHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,mBAA8C;AAC9C,8BAAuF;AACvF,0BAAuC;AACvC,mBAA6E;AAE7E,mCAAuE;AAEvE,MAAM,oBAAwC;AAAA,EAC5C,CAAC,KAAK,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M;AACL,YAAM,CAAC,MAAM,SAAS,IAAI,aAAa,EAAE,OAAO,OAAO,EAAE,OAAO,gBAAgB,GAAG,YAAY,SAAS,IAAI;AAE5G,kBAAY,CAAC,aAAa;AAExB,YAAI,SAAS;AAAU,iBAAO,CAAC,QAAQ,MAAM,CAAC;AAC9C,eAAO;AAAA,MACT,CAAC;AAED,UAAI;AAAc,qBAAa,GAAG,IAAI;AAEtC,0BAAoB,UAAM,gCAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,MAAM,YAAY;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,sBAAsB,CAAC,OAAe,SAAyC;AAC1F,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,aAAa,cAAc;AACpB,MAAM,6BAAyB,kCAAS,YAAY;AAC3D,uBAAuB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -30,6 +30,7 @@ __export(useRegExpMask_exports, {
30
30
  module.exports = __toCommonJS(useRegExpMask_exports);
31
31
  var React = __toESM(require("react"));
32
32
  var import_react = require("react");
33
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
33
34
  var import_ds_utilities = require("@elliemae/ds-utilities");
34
35
  var import_utils = require("../utils");
35
36
  var import_react_desc_prop_types = require("../react-desc-prop-types");
@@ -80,8 +81,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode, regExp, filledMask) => {
80
81
  return [maskWithSpecialsChars + specialCharsLeft, finalMaskedPos];
81
82
  };
82
83
  const useRegExpMask = (props) => {
83
- const propsWithDefault = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskRegExpHookDefaultProps);
84
- (0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskRegExpHookPropsTypes, "useRegExpMask");
84
+ const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskRegExpHookDefaultProps);
85
+ (0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskRegExpHookPropsTypes, "useRegExpMask");
85
86
  const {
86
87
  valueSetter,
87
88
  onChange: userOnChange,
@@ -142,6 +143,6 @@ const useRegExpMask = (props) => {
142
143
  };
143
144
  };
144
145
  useRegExpMask.displayName = "useRegExpMask";
145
- const UseRegExpMaskWithSchema = (0, import_ds_utilities.describe)(useRegExpMask);
146
+ const UseRegExpMaskWithSchema = (0, import_ds_props_helpers.describe)(useRegExpMask);
146
147
  UseRegExpMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskRegExpHookPropsTypes;
147
148
  //# sourceMappingURL=useRegExpMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useRegExpMask.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable max-params */\nimport 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, flatStringArray } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from '../react-desc-prop-types';\n\nconst isRegExp = (item: RegExp | string): item is RegExp => typeof item === 'object';\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n regExp: string[],\n filledMask: boolean,\n) => {\n const specialChars: [string, number][] = [];\n const flatRegExp = flatStringArray(regExp);\n const rawValueArray = String(rawValue).split('');\n let offSet = 0;\n let charsFound = 0;\n let specialCharsLeft = '';\n let fullRegExpMatched = false;\n const maskedValue: string[] = [];\n for (let i = 0; i < flatRegExp.length; i += 1) {\n if (isRegExp(flatRegExp[i])) {\n specialCharsLeft = '';\n fullRegExpMatched = false;\n for (let j = charsFound + offSet; j < rawValueArray.length; j += 1) {\n const match = rawValueArray[j]?.match(flatRegExp[i]);\n if (match) {\n maskedValue.push(match[0]);\n charsFound += 1;\n fullRegExpMatched = true;\n break;\n } else {\n offSet += 1;\n }\n }\n if (filledMask && !fullRegExpMatched) {\n maskedValue.push('_');\n }\n } else {\n specialChars.push([flatRegExp[i], i]);\n if (rawValueArray[i + offSet] === flatRegExp[i]) charsFound += 1;\n specialCharsLeft += flatRegExp[i];\n }\n }\n if (!fullRegExpMatched) specialCharsLeft = '';\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n const [maskWithSpecialsChars, finalMaskedPos] = addSpecialCharacters(\n maskedValue,\n specialChars,\n maskedPos,\n lastKeyCode,\n );\n\n return [maskWithSpecialsChars + specialCharsLeft, finalMaskedPos];\n};\n\nexport const useRegExpMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskRegExpHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskRegExpHookPropsTypes, 'useRegExpMask');\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n regExp,\n filledMask,\n } = 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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n regExp,\n filledMask,\n );\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n const onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (filledMask) {\n const maskedValue = e.target.value.split('');\n\n const flatRegExp = flatStringArray(regExp);\n const firstUnderscoreIdx = maskedValue.findIndex((char, idx) => char === '_' && flatRegExp[idx] !== '_');\n if (firstUnderscoreIdx > -1) valueSetter(maskedValue.slice(0, firstUnderscoreIdx).join(''));\n }\n\n if (userOnBlur) userOnBlur(e);\n },\n [valueSetter, userOnBlur],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nuseRegExpMask.displayName = 'useRegExpMask';\nexport const UseRegExpMaskWithSchema = describe(useRegExpMask);\nUseRegExpMaskWithSchema.propTypes = DSMaskRegExpHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAA8C;AAC9C,0BAKO;AACP,mBAA8F;AAE9F,mCAAyE;AAEzE,MAAM,WAAW,CAAC,SAA0C,OAAO,SAAS;AAE5E,MAAM,eAAe,CACnB,UACA,WACA,aACA,QACA,eACG;AACH,QAAM,eAAmC,CAAC;AAC1C,QAAM,iBAAa,8BAAgB,MAAM;AACzC,QAAM,gBAAgB,OAAO,QAAQ,EAAE,MAAM,EAAE;AAC/C,MAAI,SAAS;A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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, flatStringArray } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from '../react-desc-prop-types';\n\nconst isRegExp = (item: RegExp | string): item is RegExp => typeof item === 'object';\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n regExp: string[],\n filledMask: boolean,\n) => {\n const specialChars: [string, number][] = [];\n const flatRegExp = flatStringArray(regExp);\n const rawValueArray = String(rawValue).split('');\n let offSet = 0;\n let charsFound = 0;\n let specialCharsLeft = '';\n let fullRegExpMatched = false;\n const maskedValue: string[] = [];\n for (let i = 0; i < flatRegExp.length; i += 1) {\n if (isRegExp(flatRegExp[i])) {\n specialCharsLeft = '';\n fullRegExpMatched = false;\n for (let j = charsFound + offSet; j < rawValueArray.length; j += 1) {\n const match = rawValueArray[j]?.match(flatRegExp[i]);\n if (match) {\n maskedValue.push(match[0]);\n charsFound += 1;\n fullRegExpMatched = true;\n break;\n } else {\n offSet += 1;\n }\n }\n if (filledMask && !fullRegExpMatched) {\n maskedValue.push('_');\n }\n } else {\n specialChars.push([flatRegExp[i], i]);\n if (rawValueArray[i + offSet] === flatRegExp[i]) charsFound += 1;\n specialCharsLeft += flatRegExp[i];\n }\n }\n if (!fullRegExpMatched) specialCharsLeft = '';\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n const [maskWithSpecialsChars, finalMaskedPos] = addSpecialCharacters(\n maskedValue,\n specialChars,\n maskedPos,\n lastKeyCode,\n );\n\n return [maskWithSpecialsChars + specialCharsLeft, finalMaskedPos];\n};\n\nexport const useRegExpMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskRegExpHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskRegExpHookPropsTypes, 'useRegExpMask');\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n regExp,\n filledMask,\n } = 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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n regExp,\n filledMask,\n );\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n const onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (filledMask) {\n const maskedValue = e.target.value.split('');\n\n const flatRegExp = flatStringArray(regExp);\n const firstUnderscoreIdx = maskedValue.findIndex((char, idx) => char === '_' && flatRegExp[idx] !== '_');\n if (firstUnderscoreIdx > -1) valueSetter(maskedValue.slice(0, firstUnderscoreIdx).join(''));\n }\n\n if (userOnBlur) userOnBlur(e);\n },\n [valueSetter, userOnBlur],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nuseRegExpMask.displayName = 'useRegExpMask';\nexport const UseRegExpMaskWithSchema = describe(useRegExpMask);\nUseRegExpMaskWithSchema.propTypes = DSMaskRegExpHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAA8C;AAC9C,8BAAuF;AACvF,0BAAuC;AACvC,mBAA8F;AAE9F,mCAAyE;AAEzE,MAAM,WAAW,CAAC,SAA0C,OAAO,SAAS;AAE5E,MAAM,eAAe,CACnB,UACA,WACA,aACA,QACA,eACG;AACH,QAAM,eAAmC,CAAC;AAC1C,QAAM,iBAAa,8BAAgB,MAAM;AACzC,QAAM,gBAAgB,OAAO,QAAQ,EAAE,MAAM,EAAE;AAC/C,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,mBAAmB;AACvB,MAAI,oBAAoB;AACxB,QAAM,cAAwB,CAAC;AAC/B,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK,GAAG;AAC7C,QAAI,SAAS,WAAW,EAAE,GAAG;AAC3B,yBAAmB;AACnB,0BAAoB;AACpB,eAAS,IAAI,aAAa,QAAQ,IAAI,cAAc,QAAQ,KAAK,GAAG;AAClE,cAAM,QAAQ,cAAc,IAAI,MAAM,WAAW,EAAE;AACnD,YAAI,OAAO;AACT,sBAAY,KAAK,MAAM,EAAE;AACzB,wBAAc;AACd,8BAAoB;AACpB;AAAA,QACF,OAAO;AACL,oBAAU;AAAA,QACZ;AAAA,MACF;AACA,UAAI,cAAc,CAAC,mBAAmB;AACpC,oBAAY,KAAK,GAAG;AAAA,MACtB;AAAA,IACF,OAAO;AACL,mBAAa,KAAK,CAAC,WAAW,IAAI,CAAC,CAAC;AACpC,UAAI,cAAc,IAAI,YAAY,WAAW;AAAI,sBAAc;AAC/D,0BAAoB,WAAW;AAAA,IACjC;AAAA,EACF;AACA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cAAM,cAAc,EAAE,OAAO,MAAM,MAAM,EAAE;AAE3C,cAAM,iBAAa,8BAAgB,MAAM;AACzC,cAAM,qBAAqB,YAAY,UAAU,CAAC,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,GAAG;AACvG,YAAI,qBAAqB;AAAI,sBAAY,YAAY,MAAM,GAAG,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,MAC5F;AAEA,UAAI;AAAY,mBAAW,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,aAAa,UAAU;AAAA,EAC1B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,cAAc,cAAc;AACrB,MAAM,8BAA0B,kCAAS,aAAa;AAC7D,wBAAwB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -31,6 +31,7 @@ __export(useSSNMask_exports, {
31
31
  module.exports = __toCommonJS(useSSNMask_exports);
32
32
  var React = __toESM(require("react"));
33
33
  var import_react = require("react");
34
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
34
35
  var import_ds_utilities = require("@elliemae/ds-utilities");
35
36
  var import_utils = require("../utils");
36
37
  var import_react_desc_prop_types = require("../react-desc-prop-types");
@@ -47,8 +48,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode) => {
47
48
  return (0, import_utils.addSpecialCharacters)(maskedValue, ssnSpecialChars, maskedPos, lastKeyCode);
48
49
  };
49
50
  const useSSNMask = (props) => {
50
- const propsWithDefault = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskHookDefaultProps);
51
- (0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskHookPropsTypes, "useSSNMask");
51
+ const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskHookDefaultProps);
52
+ (0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskHookPropsTypes, "useSSNMask");
52
53
  const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;
53
54
  const lastKeyCode = (0, import_react.useRef)("Unidentified");
54
55
  const scheduleAfterRender = (0, import_ds_utilities.useCallbackAfterRender)(true);
@@ -85,6 +86,6 @@ const getSSNMaskedValue = (value) => {
85
86
  return maskedValue;
86
87
  };
87
88
  useSSNMask.displayName = "useSSNMask";
88
- const UseSSNMaskWithSchema = (0, import_ds_utilities.describe)(useSSNMask);
89
+ const UseSSNMaskWithSchema = (0, import_ds_props_helpers.describe)(useSSNMask);
89
90
  UseSSNMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskHookPropsTypes;
90
91
  //# sourceMappingURL=useSSNMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useSSNMask.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["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 maskedValue;\n};\n\nuseSSNMask.displayName = 'useSSNMask';\nexport const UseSSNMaskWithSchema = describe(useSSNMask);\nUseSSNMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA8C;A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gCAAkB,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,2BAAuB,8BAAS,UAAU;AACvD,qBAAqB,YAAY;",
4
+ "sourcesContent": ["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';\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)\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", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA8C;AAC9C,8BAAuF;AACvF,0BAAuC;AACvC,mBAA6E;AAE7E,mCAA6D;AAE7D,MAAM,kBAAsC;AAAA,EAC1C,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AACT;AAEA,MAAM,eAAe,CAAC,UAAkB,WAAmB,gBAAwB;AAEjF,MAAI,cAAc,OAA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AW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,WAAW,cAAc;AAClB,MAAM,2BAAuB,kCAAS,UAAU;AACvD,qBAAqB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -31,6 +31,7 @@ __export(useZipCodeMask_exports, {
31
31
  module.exports = __toCommonJS(useZipCodeMask_exports);
32
32
  var React = __toESM(require("react"));
33
33
  var import_react = require("react");
34
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
34
35
  var import_ds_utilities = require("@elliemae/ds-utilities");
35
36
  var import_utils = require("../utils");
36
37
  var import_react_desc_prop_types = require("../react-desc-prop-types");
@@ -42,8 +43,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode) => {
42
43
  return (0, import_utils.addSpecialCharacters)(maskedValue, zipCodeSpecialChars, maskedPos, lastKeyCode);
43
44
  };
44
45
  const useZipCodeMask = (props) => {
45
- const propsWithDefault = (0, import_ds_utilities.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskHookDefaultProps);
46
- (0, import_ds_utilities.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskHookPropsTypes, "useZipCodeMask");
46
+ const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskHookDefaultProps);
47
+ (0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskHookPropsTypes, "useZipCodeMask");
47
48
  const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;
48
49
  const lastKeyCode = (0, import_react.useRef)("Unidentified");
49
50
  const scheduleAfterRender = (0, import_ds_utilities.useCallbackAfterRender)(true);
@@ -80,6 +81,6 @@ const getUseZipMaskedValue = (value) => {
80
81
  return maskedValue;
81
82
  };
82
83
  useZipCodeMask.displayName = "useZipCodeMask";
83
- const UseZipCodeMaskWithSchema = (0, import_ds_utilities.describe)(useZipCodeMask);
84
+ const UseZipCodeMaskWithSchema = (0, import_ds_props_helpers.describe)(useZipCodeMask);
84
85
  UseZipCodeMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskHookPropsTypes;
85
86
  //# sourceMappingURL=useZipCodeMask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useZipCodeMask.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA8C;AAC9C,0BAKO;AACP,mBAA6E;AAE7E,mCAA6D;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,QAAQ,GAAG;AAGxF,gBAAc,YAAY,MAAM,GAAG,CAAC;AAEpC,QAAM,gBAAY,kCAAoB,UAAU,aAAa,SAAS;AAEtE,aAAO,mCAAqB,aAAa,qBAAqB,WAAW,WAAW;AACtF;AAEO,MAAM,iBAA+B,CAAC,UAAU;AACrD,QAAM,uBAAmB,kDAA6B,OAAO,mDAAsB;AACnF,0DAA+B,kBAAkB,mDAAsB,gBAAgB;AACvF,QAAM,EAAE,aAAa,UAAU,cAAc,WAAW,cAAc,IAAI;AAE1E,QAAM,kBAAc,qBAAO,cAAc;AACzC,QAAM,0BAAsB,4CAAuB,IAAI;AAOvD,QAAM,CAAC,EAAE,MAAM,QAAI,uBAAS,CAAC;AAE7B,QAAM,gBAA0D;AAAA,IAC9D,CAAC,MAAM;AACL,kBAAY,UAAU,EAAE;AACxB,UAAI;AAAe,sBAAc,CAAC;AAAA,IACpC;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AAEA,QAAM,eAAuD;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,UAAM,gCAAkB,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,uBAAuB,CAAC,UAAkB;AACrD,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,eAAe,cAAc;AACtB,MAAM,+BAA2B,8BAAS,cAAc;AAC/D,yBAAyB,YAAY;",
4
+ "sourcesContent": ["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';\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)\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 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", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAA8C;AAC9C,8BAAuF;AACvF,0BAAuC;AACvC,mBAA6E;AAE7E,mCAA6D;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,gBAAY,kCAAoB,UAAU,aAAa,SAAS;AAEtE,aAAO,mCAAqB,aAAa,qBAAqB,WAAW,WAAW;AACtF;AAEO,MAAM,iBAA+B,CAAC,UAAU;AACrD,QAAM,uBAAmB,sDAA6B,OAAO,mDAAsB;AACnF,8DAA+B,kBAAkB,mDAAsB,gBAAgB;AACvF,QAAM,EAAE,aAAa,UAAU,cAAc,WAAW,cAAc,IAAI;AAE1E,QAAM,kBAAc,qBAAO,cAAc;AACzC,QAAM,0BAAsB,4CAAuB,IAAI;AAOvD,QAAM,CAAC,EAAE,MAAM,QAAI,uBAAS,CAAC;AAE7B,QAAM,gBAA0D;AAAA,IAC9D,CAAC,MAAM;AACL,kBAAY,UAAU,EAAE;AACxB,UAAI;AAAe,sBAAc,CAAC;AAAA,IACpC;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AAEA,QAAM,eAAuD;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,UAAM,gCAAkB,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,uBAAuB,CAAC,UAAkB;AACrD,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,EAAE;AAC9D,SAAO;AACT;AAEA,eAAe,cAAc;AACtB,MAAM,+BAA2B,kCAAS,cAAc;AAC/D,yBAAyB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "commonjs",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -35,7 +35,7 @@ __export(react_desc_prop_types_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(react_desc_prop_types_exports);
37
37
  var React = __toESM(require("react"));
38
- var import_ds_utilities = require("@elliemae/ds-utilities");
38
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
39
39
  const DSMaskHookDefaultProps = {
40
40
  onChange: () => null,
41
41
  onKeyDown: () => null,
@@ -59,28 +59,28 @@ const DSMaskNumberHookDefaultProps = {
59
59
  decimalRequired: false
60
60
  };
61
61
  const DSMaskHookPropsTypes = {
62
- valueSetter: import_ds_utilities.PropTypes.func.description("React set state function for the value").isRequired,
63
- onChange: import_ds_utilities.PropTypes.func.description("Callback for onChange"),
64
- onKeyDown: import_ds_utilities.PropTypes.func.description("Callback for onKeyDown")
62
+ valueSetter: import_ds_props_helpers.PropTypes.func.description("React set state function for the value").isRequired,
63
+ onChange: import_ds_props_helpers.PropTypes.func.description("Callback for onChange"),
64
+ onKeyDown: import_ds_props_helpers.PropTypes.func.description("Callback for onKeyDown")
65
65
  };
66
66
  const DSMaskRegExpHookPropsTypes = {
67
67
  ...DSMaskHookPropsTypes,
68
- regExp: import_ds_utilities.PropTypes.arrayOf(import_ds_utilities.PropTypes.oneOfType([import_ds_utilities.PropTypes.string, import_ds_utilities.PropTypes.instanceOf(RegExp)])).description(
68
+ regExp: import_ds_props_helpers.PropTypes.arrayOf(import_ds_props_helpers.PropTypes.oneOfType([import_ds_props_helpers.PropTypes.string, import_ds_props_helpers.PropTypes.instanceOf(RegExp)])).description(
69
69
  "Array with regexp or special chars per character"
70
70
  ).isRequired,
71
- filledMask: import_ds_utilities.PropTypes.bool.description("Show blank chars positions").defaultValue(false)
71
+ filledMask: import_ds_props_helpers.PropTypes.bool.description("Show blank chars positions").defaultValue(false)
72
72
  };
73
73
  const DSMaskPhoneHookPropsTypes = {
74
74
  ...DSMaskHookPropsTypes,
75
- isInternational: import_ds_utilities.PropTypes.bool.description("Use or not internaltional phone mask number").defaultValue(false)
75
+ isInternational: import_ds_props_helpers.PropTypes.bool.description("Use or not internaltional phone mask number").defaultValue(false)
76
76
  };
77
77
  const DSMaskNumberHookPropsTypes = {
78
78
  ...DSMaskHookPropsTypes,
79
- suffix: import_ds_utilities.PropTypes.string.description("String will be added at the end of the input value").defaultValue(""),
80
- prefix: import_ds_utilities.PropTypes.string.description("String will be added at the start of the input value").defaultValue(""),
81
- decimalPlaces: import_ds_utilities.PropTypes.number.description("Number of decimals allowed").defaultValue(2),
82
- allowNegative: import_ds_utilities.PropTypes.bool.description("Wether the input allows negative number").defaultValue(false),
83
- includeThousandsSeparator: import_ds_utilities.PropTypes.bool.description("Wether the integer part will be separated by thousands").defaultValue(true),
84
- decimalRequired: import_ds_utilities.PropTypes.bool.description("Wether decimal part is mandatory").defaultValue(false)
79
+ suffix: import_ds_props_helpers.PropTypes.string.description("String will be added at the end of the input value").defaultValue(""),
80
+ prefix: import_ds_props_helpers.PropTypes.string.description("String will be added at the start of the input value").defaultValue(""),
81
+ decimalPlaces: import_ds_props_helpers.PropTypes.number.description("Number of decimals allowed").defaultValue(2),
82
+ allowNegative: import_ds_props_helpers.PropTypes.bool.description("Wether the input allows negative number").defaultValue(false),
83
+ includeThousandsSeparator: import_ds_props_helpers.PropTypes.bool.description("Wether the integer part will be separated by thousands").defaultValue(true),
84
+ decimalRequired: import_ds_props_helpers.PropTypes.bool.description("Wether decimal part is mandatory").defaultValue(false)
85
85
  };
86
86
  //# sourceMappingURL=react-desc-prop-types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react-desc-prop-types.ts", "../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAA0B;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,8BAAU,KAAK,YAAY,wCAAwC,EAAE;AAAA,EAClF,UAAU,8BAAU,KAAK,YAAY,uBAAuB;AAAA,EAC5D,WAAW,8BAAU,KAAK,YAAY,wBAAwB;AAChE;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,8BAAU,QAAQ,8BAAU,UAAU,CAAC,8BAAU,QAAQ,8BAAU,WAAW,MAAM,CAAC,CAAC,CAAC,EAAE;AAAA,IAC/F;AAAA,EACF,EAAE;AAAA,EACF,YAAY,8BAAU,KAAK,YAAY,4BAA4B,EAAE,aAAa,KAAK;AACzF;AAEO,MAAM,4BAA4B;AAAA,EACvC,GAAG;AAAA,EACH,iBAAiB,8BAAU,KAAK,YAAY,6CAA6C,EAAE,aAAa,KAAK;AAC/G;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,8BAAU,OAAO,YAAY,oDAAoD,EAAE,aAAa,EAAE;AAAA,EAC1G,QAAQ,8BAAU,OAAO,YAAY,sDAAsD,EAAE,aAAa,EAAE;AAAA,EAC5G,eAAe,8BAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EACxF,eAAe,8BAAU,KAAK,YAAY,yCAAyC,EAAE,aAAa,KAAK;AAAA,EACvG,2BAA2B,8BAAU,KAClC,YAAY,wDAAwD,EACpE,aAAa,IAAI;AAAA,EACpB,iBAAiB,8BAAU,KAAK,YAAY,kCAAkC,EAAE,aAAa,KAAK;AACpG;",
4
+ "sourcesContent": ["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 }\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", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAA0B;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,kCAAU,KAAK,YAAY,wCAAwC,EAAE;AAAA,EAClF,UAAU,kCAAU,KAAK,YAAY,uBAAuB;AAAA,EAC5D,WAAW,kCAAU,KAAK,YAAY,wBAAwB;AAChE;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,kCAAU,QAAQ,kCAAU,UAAU,CAAC,kCAAU,QAAQ,kCAAU,WAAW,MAAM,CAAC,CAAC,CAAC,EAAE;AAAA,IAC/F;AAAA,EACF,EAAE;AAAA,EACF,YAAY,kCAAU,KAAK,YAAY,4BAA4B,EAAE,aAAa,KAAK;AACzF;AAEO,MAAM,4BAA4B;AAAA,EACvC,GAAG;AAAA,EACH,iBAAiB,kCAAU,KAAK,YAAY,6CAA6C,EAAE,aAAa,KAAK;AAC/G;AAEO,MAAM,6BAA6B;AAAA,EACxC,GAAG;AAAA,EACH,QAAQ,kCAAU,OAAO,YAAY,oDAAoD,EAAE,aAAa,EAAE;AAAA,EAC1G,QAAQ,kCAAU,OAAO,YAAY,sDAAsD,EAAE,aAAa,EAAE;AAAA,EAC5G,eAAe,kCAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EACxF,eAAe,kCAAU,KAAK,YAAY,yCAAyC,EAAE,aAAa,KAAK;AAAA,EACvG,2BAA2B,kCAAU,KAClC,YAAY,wDAAwD,EACpE,aAAa,IAAI;AAAA,EACpB,iBAAiB,kCAAU,KAAK,YAAY,kCAAkC,EAAE,aAAa,KAAK;AACpG;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,7 @@
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";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
9
5
  import { setCursorPosition } from "../utils";
10
6
  import { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from "../react-desc-prop-types";
11
7
  const addThousandsSeparator = (n, separator) => n.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/useNumberMask.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport 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 { setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from '../react-desc-prop-types';\n\nconst addThousandsSeparator = (n: string, separator: string) => n.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: DSMaskT.NumberHookArgs,\n): [string, number] => {\n const { includeThousandsSeparator, allowNegative, prefix, suffix, decimalPlaces, decimalRequired } = opts;\n const THOUSANDSSEPARATOR = ',';\n\n let dotIdx = -1;\n // allow minus sign before and after the preffix\n let finalPrefix = [prefix.length, 0].includes(rawValue.indexOf('-')) && allowNegative ? '-' : '';\n\n let maskedValue = String(rawValue).split('').filter((char, idx) => {\n // we take only the first dot\n const validChar = (char >= '0' && char <= '9') || (char === '.' && dotIdx === -1 && decimalPlaces);\n if (char === '.' && validChar) dotIdx = idx;\n return validChar;\n });\n\n if (prefix && maskedValue.length) finalPrefix += prefix;\n\n // REMOVE FOLLOWING ZEROS IN INTEGER PART AFTER LEADER ZERO NUMBER\n while (maskedValue.length >= 2 && maskedValue[0] === '0' && maskedValue[1] !== '.') {\n maskedValue = maskedValue.splice(1);\n }\n dotIdx = maskedValue.findIndex((char) => char === '.');\n\n let integer = maskedValue.slice(0, dotIdx !== -1 ? dotIdx : maskedValue.length);\n const decimal = maskedValue.slice(dotIdx, dotIdx + decimalPlaces + 1);\n // ADDING THOUSANDS SEPARATOR\n if (includeThousandsSeparator) {\n integer = addThousandsSeparator(integer.join(''), THOUSANDSSEPARATOR).split('');\n }\n\n // MERGIN INT AND DECIMAL IF NECCESSARY\n if (dotIdx !== -1 && !(lastKeyCode === 'Backspace' && decimal.length === 1)) {\n if (integer.length) {\n maskedValue = [...integer, ...decimal];\n } else {\n // if theres no integer add a zero to the left of the dot to cover .23 => 0.23 case\n maskedValue = ['0', ...decimal];\n }\n } else {\n // If decimal is required we add a dot after integer if exists\n maskedValue = decimalRequired && integer.length ? [...integer, '.'] : integer;\n }\n\n // remove orphans prefix for example \"-$\"\n if (lastKeyCode === 'Backspace' && maskedValue.length === 0) {\n finalPrefix = '';\n }\n\n // SET REAL CURSOR POSITION AFTER ADDING DOT and COMMAS SEPARATORS\n let maskedPos = 0;\n\n // 0 leading case we move the cursor to continue typing\n if (maskedValue[maskedPos] === '0' && cursorPos === 1 + prefix.length) maskedPos += 1;\n\n for (let i = 0; i < cursorPos; i += 1) {\n if (maskedValue[maskedPos] === THOUSANDSSEPARATOR) maskedPos += 1;\n if (maskedValue[maskedPos] === rawValue[i]) maskedPos += 1;\n }\n\n maskedPos += finalPrefix.length;\n\n const finalSuffix = maskedValue.length ? suffix : '';\n\n const maskedValueString = finalPrefix + maskedValue.join('') + finalSuffix;\n return [maskedValueString, maskedPos];\n};\n\nexport const useNumberMask: DSMaskT.NumberHook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskNumberHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskNumberHookPropsTypes, 'useNumberMask');\n\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n ...opts\n } = 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 onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const maskedValue = e.target.value;\n const dotIdx = maskedValue.indexOf('.');\n const minusIndex = maskedValue.indexOf('-');\n\n const { decimalRequired, decimalPlaces, suffix } = opts;\n\n const suffixIndex = suffix.length ? maskedValue.indexOf(suffix) : -1;\n\n if (decimalRequired) {\n if (dotIdx > -1) {\n const decimal = maskedValue.slice(dotIdx + 1, suffix.length ? -suffix.length : maskedValue.length);\n\n let zerosRest = '';\n while (decimal.length + zerosRest.length !== decimalPlaces) {\n zerosRest += '0';\n }\n\n valueSetter((suffix.length ? maskedValue.slice(0, suffixIndex) : maskedValue) + zerosRest + suffix);\n }\n } else if (maskedValue.length - suffix.length - 1 === dotIdx) {\n // removing orphans dots\n valueSetter(maskedValue.replace('.', ''));\n } else if (maskedValue.length - 1 === minusIndex) {\n // removing orphans minus\n valueSetter(maskedValue.replace('-', ''));\n }\n if (userOnBlur) userOnBlur(e);\n },\n [userOnBlur, valueSetter, opts],\n );\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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n opts as DSMaskT.NumberHookArgs,\n );\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, opts],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nexport const getNumberMaskedValue = (value: string, opts: DSMaskT.NumberHookArgs) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nuseNumberMask.displayName = 'useNumberMask';\nexport const UseNumberMaskWithSchema = describe(useNumberMask);\nUseNumberMaskWithSchema.propTypes = DSMaskNumberHookPropsTypes;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAElC,SA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Ac,cAAc;AACrB,MAAM,0BAA0B,SAAS,aAAa;AAC7D,wBAAwB,YAAY;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport 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 { setCursorPosition } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from '../react-desc-prop-types';\n\nconst addThousandsSeparator = (n: string, separator: string) => n.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: DSMaskT.NumberHookArgs,\n): [string, number] => {\n const { includeThousandsSeparator, allowNegative, prefix, suffix, decimalPlaces, decimalRequired } = opts;\n const THOUSANDSSEPARATOR = ',';\n\n let dotIdx = -1;\n // allow minus sign before and after the preffix\n let finalPrefix = [prefix.length, 0].includes(rawValue.indexOf('-')) && allowNegative ? '-' : '';\n\n let maskedValue = String(rawValue)\n .split('')\n .filter((char, idx) => {\n // we take only the first dot\n const validChar = (char >= '0' && char <= '9') || (char === '.' && dotIdx === -1 && decimalPlaces);\n if (char === '.' && validChar) dotIdx = idx;\n return validChar;\n });\n\n if (prefix && maskedValue.length) finalPrefix += prefix;\n\n // REMOVE FOLLOWING ZEROS IN INTEGER PART AFTER LEADER ZERO NUMBER\n while (maskedValue.length >= 2 && maskedValue[0] === '0' && maskedValue[1] !== '.') {\n maskedValue = maskedValue.splice(1);\n }\n dotIdx = maskedValue.findIndex((char) => char === '.');\n\n let integer = maskedValue.slice(0, dotIdx !== -1 ? dotIdx : maskedValue.length);\n const decimal = maskedValue.slice(dotIdx, dotIdx + decimalPlaces + 1);\n // ADDING THOUSANDS SEPARATOR\n if (includeThousandsSeparator) {\n integer = addThousandsSeparator(integer.join(''), THOUSANDSSEPARATOR).split('');\n }\n\n // MERGIN INT AND DECIMAL IF NECCESSARY\n if (dotIdx !== -1 && !(lastKeyCode === 'Backspace' && decimal.length === 1)) {\n if (integer.length) {\n maskedValue = [...integer, ...decimal];\n } else {\n // if theres no integer add a zero to the left of the dot to cover .23 => 0.23 case\n maskedValue = ['0', ...decimal];\n }\n } else {\n // If decimal is required we add a dot after integer if exists\n maskedValue = decimalRequired && integer.length ? [...integer, '.'] : integer;\n }\n\n // remove orphans prefix for example \"-$\"\n if (lastKeyCode === 'Backspace' && maskedValue.length === 0) {\n finalPrefix = '';\n }\n\n // SET REAL CURSOR POSITION AFTER ADDING DOT and COMMAS SEPARATORS\n let maskedPos = 0;\n\n // 0 leading case we move the cursor to continue typing\n if (maskedValue[maskedPos] === '0' && cursorPos === 1 + prefix.length) maskedPos += 1;\n\n for (let i = 0; i < cursorPos; i += 1) {\n if (maskedValue[maskedPos] === THOUSANDSSEPARATOR) maskedPos += 1;\n if (maskedValue[maskedPos] === rawValue[i]) maskedPos += 1;\n }\n\n maskedPos += finalPrefix.length;\n\n const finalSuffix = maskedValue.length ? suffix : '';\n\n const maskedValueString = finalPrefix + maskedValue.join('') + finalSuffix;\n return [maskedValueString, maskedPos];\n};\n\nexport const useNumberMask: DSMaskT.NumberHook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskNumberHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskNumberHookPropsTypes, 'useNumberMask');\n\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n ...opts\n } = 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 onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const maskedValue = e.target.value;\n const dotIdx = maskedValue.indexOf('.');\n const minusIndex = maskedValue.indexOf('-');\n\n const { decimalRequired, decimalPlaces, suffix } = opts;\n\n const suffixIndex = suffix.length ? maskedValue.indexOf(suffix) : -1;\n\n if (decimalRequired) {\n if (dotIdx > -1) {\n const decimal = maskedValue.slice(dotIdx + 1, suffix.length ? -suffix.length : maskedValue.length);\n\n let zerosRest = '';\n while (decimal.length + zerosRest.length !== decimalPlaces) {\n zerosRest += '0';\n }\n\n valueSetter((suffix.length ? maskedValue.slice(0, suffixIndex) : maskedValue) + zerosRest + suffix);\n }\n } else if (maskedValue.length - suffix.length - 1 === dotIdx) {\n // removing orphans dots\n valueSetter(maskedValue.replace('.', ''));\n } else if (maskedValue.length - 1 === minusIndex) {\n // removing orphans minus\n valueSetter(maskedValue.replace('-', ''));\n }\n if (userOnBlur) userOnBlur(e);\n },\n [userOnBlur, valueSetter, opts],\n );\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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n opts as DSMaskT.NumberHookArgs,\n );\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, opts],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nexport const getNumberMaskedValue = (value: string, opts: DSMaskT.NumberHookArgs) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nuseNumberMask.displayName = 'useNumberMask';\nexport const UseNumberMaskWithSchema = describe(useNumberMask);\nUseNumberMaskWithSchema.propTypes = DSMaskNumberHookPropsTypes;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C,SAAS,UAAU,8BAA8B,sCAAsC;AACvF,SAAS,8BAA8B;AACvC,SAAS,yBAAyB;AAElC,SAAS,8BAA8B,kCAAkC;AAEzE,MAAM,wBAAwB,CAAC,GAAW,cAAsB,EAAE,QAAQ,yBAAyB,SAAS;AAE5G,MAAM,eAAe,CACnB,UACA,WACA,aACA,SACqB;AACrB,QAAM,EAAE,2BAA2B,eAAe,QAAQ,QAAQ,eAAe,gBAAgB,IAAI;AACrG,QAAM,qBAAqB;AAE3B,MAAI,SAAS;AAEb,MAAI,cAAc,CAAC,OAAO,QAAQ,CAAC,EAAE,SAAS,SAAS,QAAQ,GAAG,CAAC,KAAK,gBAAgB,MAAM;AAE9F,MAAI,cAAc,OAAO,QAAQ,EAC9B,MAAM,EAAE,EACR,OAAO,CAAC,MAAM,QAAQ;AAErB,UAAM,YAAa,QAAQ,OAAO,QAAQ,OAAS,SAAS,OAAO,WAAW,MAAM;AACpF,QAAI,SAAS,OAAO;AAAW,eAAS;AACxC,WAAO;AAAA,EACT,CAAC;AAEH,MAAI,UAAU,YAAY;AAAQ,mBAAe;AAGjD,SAAO,YAAY,UAAU,KAAK,YAAY,OAAO,OAAO,YAAY,OAAO,KAAK;AAClF,kBAAc,YAAY,OAAO,CAAC;AAAA,EACpC;AACA,WAAS,YAAY,UAAU,CAAC,SAAS,SAAS,GAAG;AAErD,MAAI,UAAU,YAAY,MAAM,GAAG,WAAW,KAAK,SAAS,YAAY,MAAM;AAC9E,QAAM,UAAU,YAAY,MAAM,QAAQ,SAAS,gB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ACT,CAAC;AACD,UAAI;AAAc,qBAAa,GAAG,IAAI;AACtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,cAAc,IAAI;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,OAAe,SAAiC;AACnF,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,cAAc,cAAc;AACrB,MAAM,0BAA0B,SAAS,aAAa;AAC7D,wBAAwB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,7 @@
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";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
9
5
  import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils";
10
6
  import { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from "../react-desc-prop-types";
11
7
  const phoneSpecialChars = [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/usePhoneMask.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\nimport 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 { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from '../react-desc-prop-types';\n\nconst phoneSpecialChars: [string, number][] = [\n ['(', 0],\n [') ', 4],\n [' - ', 9],\n];\n\nconst internationalPhoneSpecialChars: [string, number][] = [\n ['+1 (', 0],\n [') ', 7],\n [' - ', 12],\n];\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: Partial<DSMaskT.PhoneHookArgs>,\n) => {\n const characters = String(rawValue).split('');\n // Work with digits only\n const { isInternational } = opts;\n let maskedValue = characters.filter((char, idx, array) => {\n if (isInternational && idx === 1 && char === '1' && array[0] === '+') {\n return false;\n }\n return 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 10 digits\n maskedValue = maskedValue.slice(0, 10);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(\n maskedValue,\n isInternational ? internationalPhoneSpecialChars : phoneSpecialChars,\n maskedPos,\n lastKeyCode,\n );\n};\n\nexport const usePhoneMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskPhoneHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskPhoneHookPropsTypes, 'usePhoneMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, onBlur, ...opts } = 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, opts);\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, opts, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getPhoneMaskedValue = (value: string, opts: Partial<DSMaskT.PhoneHookArgs>) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nusePhoneMask.displayName = 'usePhoneMask';\nexport const UsePhoneMaskWithSchema = describe(usePhoneMask);\nUsePhoneMaskWithSchema.propTypes = DSMaskPhoneHookPropsTypes;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB,qBAAqB,yBAAyB;AAE7E,SAAS,2BAA2B,mCAAmC;AAEvE,MAAM,oBAAwC;AAAA,EAC5C,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,MAAM,CAAC;AAAA,EACR,CAAC,OAAO,CAAC;AACX;AAEA,MAAM,iCAAqD;AAAA,EACzD,CAAC,QAAQ,CAAC;AAAA,EACV,CAAC,MAAM,CAAC;AAAA,EACR,CAAC,OAAO,EAAE;AACZ;AAEA,MAAM,eAAe,CACnB,UACA,WACA,aACA,SACG;AACH,QAAM,aAAa,OAAO,QAAQ,EAAE,MAAM,EAAE;AAE5C,QAAM,EAAE,gBAAgB,IAAI;AAC5B,MAAI,cAAc,WAAW,OAAO,CAA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qB,MAAM,YAAY;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,sBAAsB,CAAC,OAAe,SAAyC;AAC1F,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,aAAa,cAAc;AACpB,MAAM,yBAAyB,SAAS,YAAY;AAC3D,uBAAuB,YAAY;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\nimport 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';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from '../react-desc-prop-types';\n\nconst phoneSpecialChars: [string, number][] = [\n ['(', 0],\n [') ', 4],\n [' - ', 9],\n];\n\nconst internationalPhoneSpecialChars: [string, number][] = [\n ['+1 (', 0],\n [') ', 7],\n [' - ', 12],\n];\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n opts: Partial<DSMaskT.PhoneHookArgs>,\n) => {\n const characters = String(rawValue).split('');\n // Work with digits only\n const { isInternational } = opts;\n let maskedValue = characters.filter((char, idx, array) => {\n if (isInternational && idx === 1 && char === '1' && array[0] === '+') {\n return false;\n }\n return 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 10 digits\n maskedValue = maskedValue.slice(0, 10);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(\n maskedValue,\n isInternational ? internationalPhoneSpecialChars : phoneSpecialChars,\n maskedPos,\n lastKeyCode,\n );\n};\n\nexport const usePhoneMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskPhoneHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskPhoneHookPropsTypes, 'usePhoneMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, onBlur, ...opts } = 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, opts);\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, opts, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getPhoneMaskedValue = (value: string, opts: Partial<DSMaskT.PhoneHookArgs>) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', opts);\n return maskedValue;\n};\n\nusePhoneMask.displayName = 'usePhoneMask';\nexport const UsePhoneMaskWithSchema = describe(usePhoneMask);\nUsePhoneMaskWithSchema.propTypes = DSMaskPhoneHookPropsTypes;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;AC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,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,SAAS,IAAI;AAE5G,kBAAY,CAAC,aAAa;AAExB,YAAI,SAAS;AAAU,iBAAO,CAAC,QAAQ,MAAM,CAAC;AAC9C,eAAO;AAAA,MACT,CAAC;AAED,UAAI;AAAc,qBAAa,GAAG,IAAI;AAEtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,MAAM,YAAY;AAAA,EACvD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,sBAAsB,CAAC,OAAe,SAAyC;AAC1F,QAAM,CAAC,WAAW,IAAI,aAAa,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI;AACpE,SAAO;AACT;AAEA,aAAa,cAAc;AACpB,MAAM,yBAAyB,SAAS,YAAY;AAC3D,uBAAuB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,7 @@
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";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
9
5
  import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition, flatStringArray } from "../utils";
10
6
  import { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from "../react-desc-prop-types";
11
7
  const isRegExp = (item) => typeof item === "object";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/useRegExpMask.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable max-params */\nimport 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, flatStringArray } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from '../react-desc-prop-types';\n\nconst isRegExp = (item: RegExp | string): item is RegExp => typeof item === 'object';\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n regExp: string[],\n filledMask: boolean,\n) => {\n const specialChars: [string, number][] = [];\n const flatRegExp = flatStringArray(regExp);\n const rawValueArray = String(rawValue).split('');\n let offSet = 0;\n let charsFound = 0;\n let specialCharsLeft = '';\n let fullRegExpMatched = false;\n const maskedValue: string[] = [];\n for (let i = 0; i < flatRegExp.length; i += 1) {\n if (isRegExp(flatRegExp[i])) {\n specialCharsLeft = '';\n fullRegExpMatched = false;\n for (let j = charsFound + offSet; j < rawValueArray.length; j += 1) {\n const match = rawValueArray[j]?.match(flatRegExp[i]);\n if (match) {\n maskedValue.push(match[0]);\n charsFound += 1;\n fullRegExpMatched = true;\n break;\n } else {\n offSet += 1;\n }\n }\n if (filledMask && !fullRegExpMatched) {\n maskedValue.push('_');\n }\n } else {\n specialChars.push([flatRegExp[i], i]);\n if (rawValueArray[i + offSet] === flatRegExp[i]) charsFound += 1;\n specialCharsLeft += flatRegExp[i];\n }\n }\n if (!fullRegExpMatched) specialCharsLeft = '';\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n const [maskWithSpecialsChars, finalMaskedPos] = addSpecialCharacters(\n maskedValue,\n specialChars,\n maskedPos,\n lastKeyCode,\n );\n\n return [maskWithSpecialsChars + specialCharsLeft, finalMaskedPos];\n};\n\nexport const useRegExpMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskRegExpHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskRegExpHookPropsTypes, 'useRegExpMask');\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n regExp,\n filledMask,\n } = 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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n regExp,\n filledMask,\n );\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n const onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (filledMask) {\n const maskedValue = e.target.value.split('');\n\n const flatRegExp = flatStringArray(regExp);\n const firstUnderscoreIdx = maskedValue.findIndex((char, idx) => char === '_' && flatRegExp[idx] !== '_');\n if (firstUnderscoreIdx > -1) valueSetter(maskedValue.slice(0, firstUnderscoreIdx).join(''));\n }\n\n if (userOnBlur) userOnBlur(e);\n },\n [valueSetter, userOnBlur],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nuseRegExpMask.displayName = 'useRegExpMask';\nexport const UseRegExpMaskWithSchema = describe(useRegExpMask);\nUseRegExpMaskWithSchema.propTypes = DSMaskRegExpHookPropsTypes;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB,qBAAqB,mBAAmB,uBAAuB;AAE9F,SAAS,4BAA4B,oCAAoC;AAEzE,MAAM,WAAW,CAAC,SAA0C,OAAO,SAAS;AAE5E,MAAM,eAAe,CACnB,UACA,WACA,aACA,QACA,eACG;AACH,QAAM,eAAmC,CAAC;AAC1C,QAAM,aAAa,gBAAgB,MAAM;AACzC,QAAM,gBAAgB,OAAO,QAAQ,EAAE,MAAM,EAAE;AAC/C,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,mBAAmB;AACvB,MAAI,oBAAoB;AACxB,QAAM,cAAwB,CAAC;AAC/B,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK,GAAG;AAC7C,QAAI,SAAS,WAAW,EAAE,GAAG;AAC3B,yBAAmB;AACnB,0BAAoB;AACpB,eAAS,IAAI,aAAa,QAAQ,IAAI,cAAc,QAAQ,KAAK,GAAG;AAClE,cAAM,QAAQ,cAAc,IAAI,MAAM,WAAW,EAAE;AACnD,YAAI,OAAO;AACT,sBAAY,KAAK,MAAM,EAAE;AACzB,wBAAc;AACd,8BAAoB;AACpB;AAAA,QACF,OAAO;AACL,oBAAU;AA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AC9C,eAAO;AAAA,MACT,CAAC;AAED,UAAI;AAAc,qBAAa,GAAG,IAAI;AAEtC,0BAAoB,MAAM,kBAAkB,EAAE,QAAQ,SAAS,CAAC;AAAA,IAClE;AAAA,IACA,CAAC,aAAa,qBAAqB,YAAY;AAAA,EACjD;AACA,QAAM,SAAoD;AAAA,IACxD,CAAC,MAAM;AACL,UAAI,YAAY;AACd,cAAM,cAAc,EAAE,OAAO,MAAM,MAAM,EAAE;AAE3C,cAAM,aAAa,gBAAgB,MAAM;AACzC,cAAM,qBAAqB,YAAY,UAAU,CAAC,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,GAAG;AACvG,YAAI,qBAAqB;AAAI,sBAAY,YAAY,MAAM,GAAG,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,MAC5F;AAEA,UAAI;AAAY,mBAAW,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,aAAa,UAAU;AAAA,EAC1B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,cAAc,cAAc;AACrB,MAAM,0BAA0B,SAAS,aAAa;AAC7D,wBAAwB,YAAY;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable max-params */\nimport 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, flatStringArray } from '../utils';\nimport type { DSMaskT } from '../react-desc-prop-types';\nimport { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from '../react-desc-prop-types';\n\nconst isRegExp = (item: RegExp | string): item is RegExp => typeof item === 'object';\n\nconst conformValue = (\n rawValue: string,\n cursorPos: number,\n lastKeyCode: string,\n regExp: string[],\n filledMask: boolean,\n) => {\n const specialChars: [string, number][] = [];\n const flatRegExp = flatStringArray(regExp);\n const rawValueArray = String(rawValue).split('');\n let offSet = 0;\n let charsFound = 0;\n let specialCharsLeft = '';\n let fullRegExpMatched = false;\n const maskedValue: string[] = [];\n for (let i = 0; i < flatRegExp.length; i += 1) {\n if (isRegExp(flatRegExp[i])) {\n specialCharsLeft = '';\n fullRegExpMatched = false;\n for (let j = charsFound + offSet; j < rawValueArray.length; j += 1) {\n const match = rawValueArray[j]?.match(flatRegExp[i]);\n if (match) {\n maskedValue.push(match[0]);\n charsFound += 1;\n fullRegExpMatched = true;\n break;\n } else {\n offSet += 1;\n }\n }\n if (filledMask && !fullRegExpMatched) {\n maskedValue.push('_');\n }\n } else {\n specialChars.push([flatRegExp[i], i]);\n if (rawValueArray[i + offSet] === flatRegExp[i]) charsFound += 1;\n specialCharsLeft += flatRegExp[i];\n }\n }\n if (!fullRegExpMatched) specialCharsLeft = '';\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n const [maskWithSpecialsChars, finalMaskedPos] = addSpecialCharacters(\n maskedValue,\n specialChars,\n maskedPos,\n lastKeyCode,\n );\n\n return [maskWithSpecialsChars + specialCharsLeft, finalMaskedPos];\n};\n\nexport const useRegExpMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskRegExpHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskRegExpHookPropsTypes, 'useRegExpMask');\n const {\n valueSetter,\n onChange: userOnChange,\n onKeyDown: userOnKeyDown,\n onBlur: userOnBlur,\n regExp,\n filledMask,\n } = 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(\n e.target.value,\n e.target.selectionEnd ?? 0,\n lastKeyCode.current,\n regExp,\n filledMask,\n );\n\n valueSetter((prevMask) => {\n // Here we need to update the key\n\n if (mask === prevMask) setKey((key) => key + 1);\n return mask;\n });\n\n if (userOnChange) userOnChange(e, mask);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n const onBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (filledMask) {\n const maskedValue = e.target.value.split('');\n\n const flatRegExp = flatStringArray(regExp);\n const firstUnderscoreIdx = maskedValue.findIndex((char, idx) => char === '_' && flatRegExp[idx] !== '_');\n if (firstUnderscoreIdx > -1) valueSetter(maskedValue.slice(0, firstUnderscoreIdx).join(''));\n }\n\n if (userOnBlur) userOnBlur(e);\n },\n [valueSetter, userOnBlur],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nuseRegExpMask.displayName = 'useRegExpMask';\nexport const UseRegExpMaskWithSchema = describe(useRegExpMask);\nUseRegExpMaskWithSchema.propTypes = DSMaskRegExpHookPropsTypes;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C,SAAS,UAAU,8BAA8B,sCAAsC;AACvF,SAAS,8BAA8B;AACvC,SAAS,sBAAsB,qBAAqB,mBAAmB,uBAAuB;AAE9F,SAAS,4BAA4B,oCAAoC;AAEzE,MAAM,WAAW,CAAC,SAA0C,OAAO,SAAS;AAE5E,MAAM,eAAe,CACnB,UACA,WACA,a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cAAc;AACrB,MAAM,0BAA0B,SAAS,aAAa;AAC7D,wBAAwB,YAAY;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,7 @@
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";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
9
5
  import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils";
10
6
  import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types";
11
7
  const ssnSpecialChars = [
@@ -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 maskedValue;\n};\n\nuseSSNMask.displayName = 'useSSNMask';\nexport const UseSSNMaskWithSchema = describe(useSSNMask);\nUseSSNMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,aAAa,QAAQ,gBAAgB;AAC9C;AAAA,EACE;AAAA,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ACD,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';\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)\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,gBAAgB;AAC9C,SAAS,UAAU,8BAA8B,sCAAsC;AACvF,SAAS,8BAA8B;AACvC,SAAS,sBAAsB,qBAAqB,yBAAyB;AAE7E,SAAS,wBAAwB,4BAA4B;AAE7D,MAAM,kBAAsC;AAAA,EAC1C,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AACT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,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,11 +1,7 @@
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";
3
+ import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
4
+ import { useCallbackAfterRender } from "@elliemae/ds-utilities";
9
5
  import { addSpecialCharacters, getPartialMaskedPos, setCursorPosition } from "../utils";
10
6
  import { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from "../react-desc-prop-types";
11
7
  const zipCodeSpecialChars = [["-", 5]];
@@ -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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,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,uBAAuB,CAAC,UAAkB;AACrD,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;",
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';\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)\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 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,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,CA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AC/D,yBAAyB,YAAY;",
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,
@@ -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"],
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 }\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
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;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
1
  import type { DSMaskT } from '../react-desc-prop-types';
2
2
  export declare const useNumberMask: DSMaskT.NumberHook;
3
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>;
4
+ export declare const UseNumberMaskWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").DocumentedReactComponent<DSMaskT.NumberHookArgs>;
@@ -1,4 +1,4 @@
1
1
  import type { DSMaskT } from '../react-desc-prop-types';
2
2
  export declare const usePhoneMask: DSMaskT.Hook;
3
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>;
4
+ export declare const UsePhoneMaskWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,3 +1,3 @@
1
1
  import type { DSMaskT } from '../react-desc-prop-types';
2
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>;
3
+ export declare const UseRegExpMaskWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,4 +1,4 @@
1
1
  import type { DSMaskT } from '../react-desc-prop-types';
2
2
  export declare const useSSNMask: DSMaskT.Hook;
3
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>;
4
+ export declare const UseSSNMaskWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
@@ -1,4 +1,4 @@
1
1
  import type { DSMaskT } from '../react-desc-prop-types';
2
2
  export declare const useZipCodeMask: DSMaskT.Hook;
3
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>;
4
+ export declare const UseZipCodeMaskWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types").DocumentedReactComponent<DSMaskT.HookArgs>;
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.4",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Controlled Form Helpers - Text Masks Hooks",
6
6
  "files": [
@@ -35,8 +35,9 @@
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.4",
39
+ "@elliemae/ds-system": "3.16.0-next.4",
40
+ "@elliemae/ds-utilities": "3.16.0-next.4"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@elliemae/pui-theme": "~2.6.0",
@@ -45,7 +46,7 @@
45
46
  "@testing-library/user-event": "~13.5.0",
46
47
  "styled-components": "~5.3.6",
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.4"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "@elliemae/pui-theme": "~2.6.0",
@@ -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
  }