@elliemae/ds-form-helpers-mask-hooks 3.16.0 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/index.js +9 -5
- package/dist/cjs/hooks/index.js.map +2 -2
- package/dist/cjs/hooks/useNumberMask.js +16 -5
- package/dist/cjs/hooks/useNumberMask.js.map +2 -2
- package/dist/cjs/hooks/usePhoneMask.js +9 -5
- package/dist/cjs/hooks/usePhoneMask.js.map +2 -2
- package/dist/cjs/hooks/useRegExpMask.js +15 -5
- package/dist/cjs/hooks/useRegExpMask.js.map +2 -2
- package/dist/cjs/hooks/useSSNMask.js +6 -2
- package/dist/cjs/hooks/useSSNMask.js.map +2 -2
- package/dist/cjs/hooks/useZipCodeMask.js +8 -4
- package/dist/cjs/hooks/useZipCodeMask.js.map +2 -2
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/react-desc-prop-types.js +11 -2
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/utils/addSpecialCharacters.js +4 -0
- package/dist/cjs/utils/addSpecialCharacters.js.map +1 -1
- package/dist/cjs/utils/flatStringArray.js +4 -0
- package/dist/cjs/utils/flatStringArray.js.map +1 -1
- package/dist/cjs/utils/getPartialMaskedPos.js +4 -0
- package/dist/cjs/utils/getPartialMaskedPos.js.map +1 -1
- package/dist/cjs/utils/index.js +9 -5
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/setCursorPosition.js +4 -0
- package/dist/cjs/utils/setCursorPosition.js.map +1 -1
- package/dist/cjs/utils/sharedFilters.js +4 -0
- package/dist/cjs/utils/sharedFilters.js.map +1 -1
- package/dist/esm/hooks/index.js +5 -5
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useNumberMask.js +12 -5
- package/dist/esm/hooks/useNumberMask.js.map +2 -2
- package/dist/esm/hooks/usePhoneMask.js +5 -5
- package/dist/esm/hooks/usePhoneMask.js.map +2 -2
- package/dist/esm/hooks/useRegExpMask.js +11 -5
- package/dist/esm/hooks/useRegExpMask.js.map +2 -2
- package/dist/esm/hooks/useSSNMask.js +2 -2
- package/dist/esm/hooks/useSSNMask.js.map +2 -2
- package/dist/esm/hooks/useZipCodeMask.js +4 -4
- package/dist/esm/hooks/useZipCodeMask.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +7 -0
- package/dist/esm/react-desc-prop-types.js +7 -2
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/esm/utils/addSpecialCharacters.js.map +1 -1
- package/dist/esm/utils/getPartialMaskedPos.js.map +1 -1
- package/dist/esm/utils/index.js +5 -5
- package/dist/esm/utils/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/types/hooks/index.d.ts +0 -5
- package/dist/types/hooks/useNumberMask.d.ts +0 -4
- package/dist/types/hooks/usePhoneMask.d.ts +0 -4
- package/dist/types/hooks/useRegExpMask.d.ts +0 -3
- package/dist/types/hooks/useSSNMask.d.ts +0 -4
- package/dist/types/hooks/useZipCodeMask.d.ts +0 -4
- package/dist/types/index.d.ts +0 -2
- package/dist/types/react-desc-prop-types.d.ts +0 -46
- package/dist/types/tests/useNumberMask.test.d.ts +0 -1
- package/dist/types/tests/usePhoneMask.test.d.ts +0 -1
- package/dist/types/tests/useRegExpMask.test.d.ts +0 -1
- package/dist/types/tests/useSSNMask.test.d.ts +0 -1
- package/dist/types/tests/useZipCode.test.d.ts +0 -1
- package/dist/types/utils/addSpecialCharacters.d.ts +0 -9
- package/dist/types/utils/flatStringArray.d.ts +0 -1
- package/dist/types/utils/getPartialMaskedPos.d.ts +0 -1
- package/dist/types/utils/index.d.ts +0 -5
- package/dist/types/utils/setCursorPosition.d.ts +0 -1
- package/dist/types/utils/sharedFilters.d.ts +0 -6
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -15,6 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
};
|
|
16
16
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
17
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
18
22
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
19
23
|
mod
|
|
20
24
|
));
|
|
@@ -22,9 +26,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
26
|
var hooks_exports = {};
|
|
23
27
|
module.exports = __toCommonJS(hooks_exports);
|
|
24
28
|
var React = __toESM(require("react"));
|
|
25
|
-
__reExport(hooks_exports, require("./usePhoneMask"), module.exports);
|
|
26
|
-
__reExport(hooks_exports, require("./useNumberMask"), module.exports);
|
|
27
|
-
__reExport(hooks_exports, require("./useSSNMask"), module.exports);
|
|
28
|
-
__reExport(hooks_exports, require("./useRegExpMask"), module.exports);
|
|
29
|
-
__reExport(hooks_exports, require("./useZipCodeMask"), module.exports);
|
|
29
|
+
__reExport(hooks_exports, require("./usePhoneMask.js"), module.exports);
|
|
30
|
+
__reExport(hooks_exports, require("./useNumberMask.js"), module.exports);
|
|
31
|
+
__reExport(hooks_exports, require("./useSSNMask.js"), module.exports);
|
|
32
|
+
__reExport(hooks_exports, require("./useRegExpMask.js"), module.exports);
|
|
33
|
+
__reExport(hooks_exports, require("./useZipCodeMask.js"), module.exports);
|
|
30
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["export * from './usePhoneMask';\nexport * from './useNumberMask';\nexport * from './useSSNMask';\nexport * from './useRegExpMask';\nexport * from './useZipCodeMask';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export * from './usePhoneMask.js';\nexport * from './useNumberMask.js';\nexport * from './useSSNMask.js';\nexport * from './useRegExpMask.js';\nexport * from './useZipCodeMask.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAAc,8BAAd;AACA,0BAAc,+BADd;AAEA,0BAAc,4BAFd;AAGA,0BAAc,+BAHd;AAIA,0BAAc,gCAJd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -33,14 +37,21 @@ var React = __toESM(require("react"));
|
|
|
33
37
|
var import_react = require("react");
|
|
34
38
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
35
39
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
36
|
-
var import_utils = require("../utils");
|
|
37
|
-
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types.js");
|
|
38
42
|
const addThousandsSeparator = (n, separator) => n.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
39
43
|
const conformValue = (rawValue, cursorPos, lastKeyCode, opts) => {
|
|
40
|
-
const {
|
|
44
|
+
const {
|
|
45
|
+
includeThousandsSeparator = true,
|
|
46
|
+
allowNegative = false,
|
|
47
|
+
prefix = "",
|
|
48
|
+
suffix = "",
|
|
49
|
+
decimalPlaces = 2,
|
|
50
|
+
decimalRequired = false
|
|
51
|
+
} = opts;
|
|
41
52
|
const THOUSANDSSEPARATOR = ",";
|
|
42
53
|
let dotIdx = -1;
|
|
43
|
-
let finalPrefix = [prefix
|
|
54
|
+
let finalPrefix = [prefix?.length, 0].includes(rawValue.indexOf("-")) && allowNegative ? "-" : "";
|
|
44
55
|
let maskedValue = String(rawValue).split("").filter((char, idx) => {
|
|
45
56
|
const validChar = char >= "0" && char <= "9" || char === "." && dotIdx === -1 && decimalPlaces;
|
|
46
57
|
if (char === "." && validChar)
|
|
@@ -102,7 +113,7 @@ const useNumberMask = (props) => {
|
|
|
102
113
|
const maskedValue = e.target.value;
|
|
103
114
|
const dotIdx = maskedValue.indexOf(".");
|
|
104
115
|
const minusIndex = maskedValue.indexOf("-");
|
|
105
|
-
const { decimalRequired, decimalPlaces, suffix } = opts;
|
|
116
|
+
const { decimalRequired = true, decimalPlaces = 2, suffix = "" } = opts;
|
|
106
117
|
const suffixIndex = suffix.length ? maskedValue.indexOf(suffix) : -1;
|
|
107
118
|
if (decimalRequired) {
|
|
108
119
|
if (dotIdx > -1) {
|
|
@@ -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 { 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
|
|
5
|
-
"mappings": "
|
|
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/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskNumberHookDefaultProps, DSMaskNumberHookPropsTypes } from '../react-desc-prop-types.js';\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: Partial<DSMaskT.NumberHookArgs>,\n): [string, number] => {\n const {\n includeThousandsSeparator = true,\n allowNegative = false,\n prefix = '',\n suffix = '',\n decimalPlaces = 2,\n decimalRequired = false,\n } = 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 = true, decimalPlaces = 2, 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;AAAA,IACJ,4BAA4B;AAAA,IAC5B,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,EACpB,IAAI;AACJ,QAAM,qBAAqB;AAE3B,MAAI,SAAS;AAEb,MAAI,cAAc,CAAC,QAAQ,QAAQ,CAAC,EAAE,SAAS,SAAS,QAAQ,GAAG,CAAC,K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MAC1C,WAAW,YAAY,SAAS,MAAM,YAAY;AAEhD,oBAAY,YAAY,QAAQ,KAAK,EAAE,CAAC;AAAA,MAC1C;AACA,UAAI;AAAY,mBAAW,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,YAAY,aAAa,IAAI;AAAA,EAChC;AAEA,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,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
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -33,8 +37,8 @@ var React = __toESM(require("react"));
|
|
|
33
37
|
var import_react = require("react");
|
|
34
38
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
35
39
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
36
|
-
var import_utils = require("../utils");
|
|
37
|
-
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types.js");
|
|
38
42
|
const phoneSpecialChars = [
|
|
39
43
|
["(", 0],
|
|
40
44
|
[") ", 4],
|
|
@@ -47,7 +51,7 @@ const internationalPhoneSpecialChars = [
|
|
|
47
51
|
];
|
|
48
52
|
const conformValue = (rawValue, cursorPos, lastKeyCode, opts) => {
|
|
49
53
|
const characters = String(rawValue).split("");
|
|
50
|
-
const { isInternational } = opts;
|
|
54
|
+
const { isInternational = false } = opts;
|
|
51
55
|
let maskedValue = characters.filter((char, idx, array) => {
|
|
52
56
|
if (isInternational && idx === 1 && char === "1" && array[0] === "+") {
|
|
53
57
|
return false;
|
|
@@ -68,7 +72,7 @@ const conformValue = (rawValue, cursorPos, lastKeyCode, opts) => {
|
|
|
68
72
|
const usePhoneMask = (props) => {
|
|
69
73
|
const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskPhoneHookDefaultProps);
|
|
70
74
|
(0, import_ds_props_helpers.useValidateTypescriptPropTypes)(propsWithDefault, import_react_desc_prop_types.DSMaskPhoneHookPropsTypes, "usePhoneMask");
|
|
71
|
-
const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown,
|
|
75
|
+
const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown, ...opts } = propsWithDefault;
|
|
72
76
|
const lastKeyCode = (0, import_react.useRef)("Unidentified");
|
|
73
77
|
const scheduleAfterRender = (0, import_ds_utilities.useCallbackAfterRender)(true);
|
|
74
78
|
const [, setKey] = (0, import_react.useState)(0);
|
|
@@ -99,7 +103,7 @@ const usePhoneMask = (props) => {
|
|
|
99
103
|
onChange
|
|
100
104
|
};
|
|
101
105
|
};
|
|
102
|
-
const getPhoneMaskedValue = (value, opts) => {
|
|
106
|
+
const getPhoneMaskedValue = (value, opts = {}) => {
|
|
103
107
|
const [maskedValue] = conformValue(value, value.length - 1, "", opts);
|
|
104
108
|
return maskedValue;
|
|
105
109
|
};
|
|
@@ -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 { 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,
|
|
5
|
-
"mappings": "
|
|
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/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskPhoneHookPropsTypes, DSMaskPhoneHookDefaultProps } from '../react-desc-prop-types.js';\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 = false } = 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, ...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,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,kBAAkB,MAAM,IAAI;AACpC,MAAI,cAAc,WAAW,OAAO,CAAC,MAAM,KAAK,UAAU;AACxD,QAAI,mBAAmB,QAAQ,KAAK,SAAS,OAAO,MAAM,CAAC,MAAM,KAAK;AACpE,aAAO;AAAA,IACT;AACA,WAAO,QAAQ,OAAO,QAAQ;AAAA,EAChC,CAAC;AAED,SAAO,YAAY,UAAU,YAAY,CAAC,MAAM;AAAK,gBAAY,OAAO,GAAG,CAAC;AAG5E,gBAAc,YAAY,MAAM,GAAG,EAAE;AAErC,QAAM,gBAAY,kCAAoB,UAAU,aAAa,SAAS;AAEtE,aAAO;AA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
7
7
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -25,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
29
|
var useRegExpMask_exports = {};
|
|
26
30
|
__export(useRegExpMask_exports, {
|
|
27
31
|
UseRegExpMaskWithSchema: () => UseRegExpMaskWithSchema,
|
|
32
|
+
getRegExpMaskedValue: () => getRegExpMaskedValue,
|
|
28
33
|
useRegExpMask: () => useRegExpMask
|
|
29
34
|
});
|
|
30
35
|
module.exports = __toCommonJS(useRegExpMask_exports);
|
|
@@ -32,8 +37,8 @@ var React = __toESM(require("react"));
|
|
|
32
37
|
var import_react = require("react");
|
|
33
38
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
34
39
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
35
|
-
var import_utils = require("../utils");
|
|
36
|
-
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types.js");
|
|
37
42
|
const isRegExp = (item) => typeof item === "object";
|
|
38
43
|
const conformValue = (rawValue, cursorPos, lastKeyCode, regExp, filledMask) => {
|
|
39
44
|
const specialChars = [];
|
|
@@ -78,7 +83,8 @@ const conformValue = (rawValue, cursorPos, lastKeyCode, regExp, filledMask) => {
|
|
|
78
83
|
maskedPos,
|
|
79
84
|
lastKeyCode
|
|
80
85
|
);
|
|
81
|
-
|
|
86
|
+
const maskReturn = maskWithSpecialsChars + specialCharsLeft;
|
|
87
|
+
return [maskReturn, finalMaskedPos];
|
|
82
88
|
};
|
|
83
89
|
const useRegExpMask = (props) => {
|
|
84
90
|
const propsWithDefault = (0, import_ds_props_helpers.useMemoMergePropsWithDefault)(props, import_react_desc_prop_types.DSMaskRegExpHookDefaultProps);
|
|
@@ -120,7 +126,7 @@ const useRegExpMask = (props) => {
|
|
|
120
126
|
userOnChange(e, mask);
|
|
121
127
|
scheduleAfterRender(() => (0, import_utils.setCursorPosition)(e.target, cursorPos));
|
|
122
128
|
},
|
|
123
|
-
[valueSetter,
|
|
129
|
+
[regExp, filledMask, valueSetter, userOnChange, scheduleAfterRender]
|
|
124
130
|
);
|
|
125
131
|
const onBlur = (0, import_react.useCallback)(
|
|
126
132
|
(e) => {
|
|
@@ -134,7 +140,7 @@ const useRegExpMask = (props) => {
|
|
|
134
140
|
if (userOnBlur)
|
|
135
141
|
userOnBlur(e);
|
|
136
142
|
},
|
|
137
|
-
[
|
|
143
|
+
[filledMask, userOnBlur, regExp, valueSetter]
|
|
138
144
|
);
|
|
139
145
|
return {
|
|
140
146
|
onKeyDown,
|
|
@@ -142,6 +148,10 @@ const useRegExpMask = (props) => {
|
|
|
142
148
|
onBlur
|
|
143
149
|
};
|
|
144
150
|
};
|
|
151
|
+
const getRegExpMaskedValue = (value, regExp) => {
|
|
152
|
+
const [maskedValue] = conformValue(value, value.length - 1, "", regExp, false);
|
|
153
|
+
return maskedValue;
|
|
154
|
+
};
|
|
145
155
|
useRegExpMask.displayName = "useRegExpMask";
|
|
146
156
|
const UseRegExpMaskWithSchema = (0, import_ds_props_helpers.describe)(useRegExpMask);
|
|
147
157
|
UseRegExpMaskWithSchema.propTypes = import_react_desc_prop_types.DSMaskRegExpHookPropsTypes;
|
|
@@ -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 { 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
|
|
5
|
-
"mappings": "
|
|
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 { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { useCallbackAfterRender } from '@elliemae/ds-utilities';\nimport { addSpecialCharacters, getPartialMaskedPos, setCursorPosition, flatStringArray } from '../utils/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskRegExpHookPropsTypes, DSMaskRegExpHookDefaultProps } from '../react-desc-prop-types.js';\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 const maskReturn = maskWithSpecialsChars + specialCharsLeft;\n return [maskReturn, 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 as string;\n });\n\n if (userOnChange) userOnChange(e, mask as string);\n\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos as number));\n },\n [regExp, filledMask, valueSetter, userOnChange, scheduleAfterRender],\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 [filledMask, userOnBlur, regExp, valueSetter],\n );\n\n return {\n onKeyDown,\n onChange,\n onBlur,\n };\n};\n\nexport const getRegExpMaskedValue = (value: string, regExp: string[]) => {\n const [maskedValue] = conformValue(value, value.length - 1, '', regExp, false);\n return maskedValue;\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;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,CAAC,CAAC,GAAG;AAC3B,yBAAmB;AACnB,0BAAoB;AACpB,eAAS,IAAI,aAAa,QAAQ,IAAI,cAAc,QAAQ,KAAK,GAAG;AAClE,cAAM,QAAQ,cAAc,CAAC,GAAG,MAAM,WA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!= null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -33,8 +37,8 @@ var React = __toESM(require("react"));
|
|
|
33
37
|
var import_react = require("react");
|
|
34
38
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
35
39
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
36
|
-
var import_utils = require("../utils");
|
|
37
|
-
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types.js");
|
|
38
42
|
const ssnSpecialChars = [
|
|
39
43
|
["-", 3],
|
|
40
44
|
["-", 6]
|
|
@@ -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 { 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": "
|
|
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/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types.js';\n\nconst ssnSpecialChars: [string, number][] = [\n ['-', 3],\n ['-', 6],\n];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue)\n .split('')\n .filter((char) => char >= '0' && char <= '9');\n\n // We can't have zeros at the start of the array\n while (maskedValue.length && maskedValue[0] === '0') maskedValue.splice(0, 1);\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, ssnSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useSSNMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useSSNMask');\n\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getSSNMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return maskedValue;\n};\n\nuseSSNMask.displayName = 'useSSNMask';\nexport const UseSSNMaskWithSchema = describe(useSSNMask);\nUseSSNMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n", "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,OAAO,QAAQ,EAC9B,MAAM,EAAE,EACR,OAAO,CAAC,SAAS,QAAQ,OAAO,QAAQ,GAAG;AAG9C,SAAO,YAAY,UAAU,YAAY,CAAC,MAAM;AAAK,gBAAY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B,YAAY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -25,7 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
29
|
var useZipCodeMask_exports = {};
|
|
26
30
|
__export(useZipCodeMask_exports, {
|
|
27
31
|
UseZipCodeMaskWithSchema: () => UseZipCodeMaskWithSchema,
|
|
28
|
-
|
|
32
|
+
getZipCodeMaskedValue: () => getZipCodeMaskedValue,
|
|
29
33
|
useZipCodeMask: () => useZipCodeMask
|
|
30
34
|
});
|
|
31
35
|
module.exports = __toCommonJS(useZipCodeMask_exports);
|
|
@@ -33,8 +37,8 @@ var React = __toESM(require("react"));
|
|
|
33
37
|
var import_react = require("react");
|
|
34
38
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
35
39
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
36
|
-
var import_utils = require("../utils");
|
|
37
|
-
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
40
|
+
var import_utils = require("../utils/index.js");
|
|
41
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types.js");
|
|
38
42
|
const zipCodeSpecialChars = [["-", 5]];
|
|
39
43
|
const conformValue = (rawValue, cursorPos, lastKeyCode) => {
|
|
40
44
|
let maskedValue = String(rawValue).split("").filter((char) => char >= "0" && char <= "9");
|
|
@@ -76,7 +80,7 @@ const useZipCodeMask = (props) => {
|
|
|
76
80
|
onChange
|
|
77
81
|
};
|
|
78
82
|
};
|
|
79
|
-
const
|
|
83
|
+
const getZipCodeMaskedValue = (value) => {
|
|
80
84
|
const [maskedValue] = conformValue(value, value.length - 1, "");
|
|
81
85
|
return maskedValue;
|
|
82
86
|
};
|
|
@@ -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 { 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
|
|
5
|
-
"mappings": "
|
|
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/index.js';\nimport type { DSMaskT } from '../react-desc-prop-types.js';\nimport { DSMaskHookDefaultProps, DSMaskHookPropsTypes } from '../react-desc-prop-types.js';\n\nconst zipCodeSpecialChars: [string, number][] = [['-', 5]];\n\nconst conformValue = (rawValue: string, cursorPos: number, lastKeyCode: string) => {\n // Work with digits only\n let maskedValue = String(rawValue)\n .split('')\n .filter((char) => char >= '0' && char <= '9');\n\n // We only consider first 9 digits\n maskedValue = maskedValue.slice(0, 9);\n\n const maskedPos = getPartialMaskedPos(rawValue, maskedValue, cursorPos);\n\n return addSpecialCharacters(maskedValue, zipCodeSpecialChars, maskedPos, lastKeyCode);\n};\n\nexport const useZipCodeMask: DSMaskT.Hook = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault(props, DSMaskHookDefaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSMaskHookPropsTypes, 'useZipCodeMask');\n const { valueSetter, onChange: userOnChange, onKeyDown: userOnKeyDown } = propsWithDefault;\n\n const lastKeyCode = useRef('Unidentified');\n const scheduleAfterRender = useCallbackAfterRender(true);\n\n // Some times, the value of the mask is not gonna change (user types invalid char for example)\n // This makes the input to go from \"correct\" -> \"incorrect\" -> \"correct\"\n // But since the input is controlled, the input does not re-render\n // This makes the input go mumbo-jumbo and places the cursor in the end, because we kinda changed the value async\n // Solution for this is to trigger a re-render, we do this with a set state call in the on change event\n const [, setKey] = useState(0);\n\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n lastKeyCode.current = e.code;\n if (userOnKeyDown) userOnKeyDown(e);\n },\n [userOnKeyDown],\n );\n\n const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n const [mask, cursorPos] = conformValue(e.target.value, e.target.selectionEnd ?? 0, lastKeyCode.current);\n valueSetter((prevMask) => {\n // Here we need to update the key\n if (mask === prevMask) setKey((key) => key + 1);\n\n return mask;\n });\n if (userOnChange) userOnChange(e, mask);\n scheduleAfterRender(() => setCursorPosition(e.target, cursorPos));\n },\n [valueSetter, scheduleAfterRender, userOnChange],\n );\n\n return {\n onKeyDown,\n onChange,\n };\n};\n\nexport const getZipCodeMaskedValue = (value: string) => {\n const [maskedValue] = conformValue(value, value.length - 1, '');\n return maskedValue;\n};\n\nuseZipCodeMask.displayName = 'useZipCodeMask';\nexport const UseZipCodeMaskWithSchema = describe(useZipCodeMask);\nUseZipCodeMaskWithSchema.propTypes = DSMaskHookPropsTypes;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"m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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,wBAAwB,CAAC,UAAkB;AACtD,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
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,6 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
};
|
|
16
16
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
17
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
18
22
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
19
23
|
mod
|
|
20
24
|
));
|
|
@@ -22,5 +26,5 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
26
|
var src_exports = {};
|
|
23
27
|
module.exports = __toCommonJS(src_exports);
|
|
24
28
|
var React = __toESM(require("react"));
|
|
25
|
-
__reExport(src_exports, require("./hooks"), module.exports);
|
|
29
|
+
__reExport(src_exports, require("./hooks/index.js"), module.exports);
|
|
26
30
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["export * from './hooks';\nexport type { DSMaskT } from './react-desc-prop-types';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export * from './hooks/index.js';\nexport type { DSMaskT } from './react-desc-prop-types.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;ADAvB,wBAAc,6BAAd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -31,7 +35,8 @@ __export(react_desc_prop_types_exports, {
|
|
|
31
35
|
DSMaskPhoneHookDefaultProps: () => DSMaskPhoneHookDefaultProps,
|
|
32
36
|
DSMaskPhoneHookPropsTypes: () => DSMaskPhoneHookPropsTypes,
|
|
33
37
|
DSMaskRegExpHookDefaultProps: () => DSMaskRegExpHookDefaultProps,
|
|
34
|
-
DSMaskRegExpHookPropsTypes: () => DSMaskRegExpHookPropsTypes
|
|
38
|
+
DSMaskRegExpHookPropsTypes: () => DSMaskRegExpHookPropsTypes,
|
|
39
|
+
DSMaskSSNDefaultProps: () => DSMaskSSNDefaultProps
|
|
35
40
|
});
|
|
36
41
|
module.exports = __toCommonJS(react_desc_prop_types_exports);
|
|
37
42
|
var React = __toESM(require("react"));
|
|
@@ -47,7 +52,11 @@ const DSMaskPhoneHookDefaultProps = {
|
|
|
47
52
|
};
|
|
48
53
|
const DSMaskRegExpHookDefaultProps = {
|
|
49
54
|
...DSMaskHookDefaultProps,
|
|
50
|
-
filledMask: false
|
|
55
|
+
filledMask: false,
|
|
56
|
+
regExp: []
|
|
57
|
+
};
|
|
58
|
+
const DSMaskSSNDefaultProps = {
|
|
59
|
+
...DSMaskHookDefaultProps
|
|
51
60
|
};
|
|
52
61
|
const DSMaskNumberHookDefaultProps = {
|
|
53
62
|
...DSMaskHookDefaultProps,
|
|
@@ -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-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
|
|
5
|
-
"mappings": "
|
|
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 regExp: string[];\n }\n\n export type Hook = ((args: HookArgs) => HookReturn) & { displayName: string };\n export type PhoneHook = ((args: PhoneHookArgs) => HookReturn) & { displayName: string };\n export type NumberHook = ((args: NumberHookArgs) => HookReturn) & { displayName: string };\n}\n\nexport const DSMaskHookDefaultProps: Partial<DSMaskT.HookArgs> = {\n onChange: () => null,\n onKeyDown: () => null,\n onBlur: () => null,\n};\n\nexport const DSMaskPhoneHookDefaultProps: Partial<DSMaskT.PhoneHookArgs> = {\n ...DSMaskHookDefaultProps,\n isInternational: false,\n};\nexport const DSMaskRegExpHookDefaultProps: Partial<DSMaskT.RegExpHookArgs> = {\n ...DSMaskHookDefaultProps,\n filledMask: false,\n regExp: [],\n};\n\nexport const DSMaskSSNDefaultProps: Partial<DSMaskT.PhoneHookArgs> = {\n ...DSMaskHookDefaultProps,\n};\n\nexport const DSMaskNumberHookDefaultProps: Partial<DSMaskT.NumberHookArgs> = {\n ...DSMaskHookDefaultProps,\n suffix: '',\n prefix: '',\n decimalPlaces: 2,\n allowNegative: false,\n includeThousandsSeparator: true,\n decimalRequired: false,\n};\n\nexport const DSMaskHookPropsTypes = {\n valueSetter: PropTypes.func.description('React set state function for the value').isRequired,\n onChange: PropTypes.func.description('Callback for onChange'),\n onKeyDown: PropTypes.func.description('Callback for onKeyDown'),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskRegExpHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n regExp: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])).description(\n 'Array with regexp or special chars per character',\n ).isRequired,\n filledMask: PropTypes.bool.description('Show blank chars positions').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskPhoneHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n isInternational: PropTypes.bool.description('Use or not internaltional phone mask number').defaultValue(false),\n} as WeakValidationMap<unknown>;\n\nexport const DSMaskNumberHookPropsTypes = {\n ...DSMaskHookPropsTypes,\n suffix: PropTypes.string.description('String will be added at the end of the input value').defaultValue(''),\n prefix: PropTypes.string.description('String will be added at the start of the input value').defaultValue(''),\n decimalPlaces: PropTypes.number.description('Number of decimals allowed').defaultValue(2),\n allowNegative: PropTypes.bool.description('Wether the input allows negative number').defaultValue(false),\n includeThousandsSeparator: PropTypes.bool\n .description('Wether the integer part will be separated by thousands')\n .defaultValue(true),\n decimalRequired: PropTypes.bool.description('Wether decimal part is mandatory').defaultValue(false),\n} as WeakValidationMap<unknown>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAA0B;AAyCnB,MAAM,yBAAoD;AAAA,EAC/D,UAAU,MAAM;AAAA,EAChB,WAAW,MAAM;AAAA,EACjB,QAAQ,MAAM;AAChB;AAEO,MAAM,8BAA8D;AAAA,EACzE,GAAG;AAAA,EACH,iBAAiB;AACnB;AACO,MAAM,+BAAgE;AAAA,EAC3E,GAAG;AAAA,EACH,YAAY;AAAA,EACZ,QAAQ,CAAC;AACX;AAEO,MAAM,wBAAw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
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|