@skbkontur/react-ui 4.25.1-MaskedInput-fix.1 → 4.25.1-MaskedInput-fix.2

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 (77) hide show
  1. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.d.ts +12 -0
  2. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.js +157 -0
  3. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.js.map +1 -0
  4. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.d.ts +3 -0
  5. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.js +13 -0
  6. package/cjs/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.js.map +1 -0
  7. package/cjs/components/MaskedInput/ColorableInputElement/index.d.ts +1 -0
  8. package/cjs/components/MaskedInput/ColorableInputElement/index.js +1 -0
  9. package/cjs/components/MaskedInput/ColorableInputElement/index.js.map +1 -0
  10. package/cjs/components/MaskedInput/FixedIMaskInput.d.ts +9 -0
  11. package/cjs/components/MaskedInput/FixedIMaskInput.js +219 -0
  12. package/cjs/components/MaskedInput/FixedIMaskInput.js.map +1 -0
  13. package/cjs/components/MaskedInput/MaskedInput.d.ts +12 -11
  14. package/cjs/components/MaskedInput/MaskedInput.js +19 -44
  15. package/cjs/components/MaskedInput/MaskedInput.js.map +1 -1
  16. package/cjs/components/MaskedInput/MaskedInput.md +11 -3
  17. package/cjs/lib/events/MouseDrag.d.ts +1 -1
  18. package/cjs/lib/events/MouseDrag.js.map +1 -1
  19. package/cjs/lib/events/keyboard/identifiers.d.ts +3 -0
  20. package/cjs/lib/events/keyboard/identifiers.js +5 -1
  21. package/cjs/lib/events/keyboard/identifiers.js.map +1 -1
  22. package/cjs/lib/styles/UiFont.js +1 -6
  23. package/cjs/lib/styles/UiFont.js.map +1 -1
  24. package/cjs/lib/theming/Emotion.js +3 -2
  25. package/cjs/lib/theming/Emotion.js.map +1 -1
  26. package/{internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js → components/MaskedInput/ColorableInputElement/ColorableInputElement/ColorableInputElement.js} +50 -48
  27. package/components/MaskedInput/ColorableInputElement/ColorableInputElement/ColorableInputElement.js.map +1 -0
  28. package/components/MaskedInput/ColorableInputElement/ColorableInputElement/package.json +6 -0
  29. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.d.ts +12 -0
  30. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/ColorableInputElement.styles.js +10 -0
  31. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/ColorableInputElement.styles.js.map +1 -0
  32. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles/package.json +6 -0
  33. package/components/MaskedInput/ColorableInputElement/ColorableInputElement.styles.d.ts +3 -0
  34. package/components/MaskedInput/ColorableInputElement/index/index.js +1 -0
  35. package/components/MaskedInput/ColorableInputElement/index/index.js.map +1 -0
  36. package/components/MaskedInput/ColorableInputElement/index/package.json +6 -0
  37. package/components/MaskedInput/ColorableInputElement/index.d.ts +1 -0
  38. package/components/MaskedInput/ColorableInputElement/package.json +6 -0
  39. package/components/MaskedInput/FixedIMaskInput/FixedIMaskInput.js +241 -0
  40. package/components/MaskedInput/FixedIMaskInput/FixedIMaskInput.js.map +1 -0
  41. package/components/MaskedInput/FixedIMaskInput/package.json +6 -0
  42. package/components/MaskedInput/FixedIMaskInput.d.ts +9 -0
  43. package/components/MaskedInput/MaskedInput/MaskedInput.js +21 -44
  44. package/components/MaskedInput/MaskedInput/MaskedInput.js.map +1 -1
  45. package/components/MaskedInput/MaskedInput.d.ts +12 -11
  46. package/components/MaskedInput/MaskedInput.md +11 -3
  47. package/lib/events/MouseDrag/MouseDrag.js.map +1 -1
  48. package/lib/events/MouseDrag.d.ts +1 -1
  49. package/lib/events/keyboard/identifiers/identifiers.js +13 -0
  50. package/lib/events/keyboard/identifiers/identifiers.js.map +1 -1
  51. package/lib/events/keyboard/identifiers.d.ts +3 -0
  52. package/lib/styles/UiFont/UiFont.js +1 -6
  53. package/lib/styles/UiFont/UiFont.js.map +1 -1
  54. package/lib/theming/Emotion/Emotion.js +3 -2
  55. package/lib/theming/Emotion/Emotion.js.map +1 -1
  56. package/package.json +1 -1
  57. package/cjs/internal/MaskedInputElement/MaskedInputElement.d.ts +0 -11
  58. package/cjs/internal/MaskedInputElement/MaskedInputElement.js +0 -166
  59. package/cjs/internal/MaskedInputElement/MaskedInputElement.js.map +0 -1
  60. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.d.ts +0 -5
  61. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js +0 -19
  62. package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js.map +0 -1
  63. package/cjs/internal/MaskedInputElement/index.d.ts +0 -1
  64. package/cjs/internal/MaskedInputElement/index.js +0 -1
  65. package/cjs/internal/MaskedInputElement/index.js.map +0 -1
  66. package/internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js.map +0 -1
  67. package/internal/MaskedInputElement/MaskedInputElement/package.json +0 -6
  68. package/internal/MaskedInputElement/MaskedInputElement.d.ts +0 -11
  69. package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js +0 -13
  70. package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js.map +0 -1
  71. package/internal/MaskedInputElement/MaskedInputElement.styles/package.json +0 -6
  72. package/internal/MaskedInputElement/MaskedInputElement.styles.d.ts +0 -5
  73. package/internal/MaskedInputElement/index/index.js +0 -1
  74. package/internal/MaskedInputElement/index/index.js.map +0 -1
  75. package/internal/MaskedInputElement/index/package.json +0 -6
  76. package/internal/MaskedInputElement/index.d.ts +0 -1
  77. package/internal/MaskedInputElement/package.json +0 -6
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { InputElement, InputElementProps } from '../../Input';
3
+ export declare type ColorableInputElementProps = InputElementProps & {
4
+ active?: boolean;
5
+ showOnFocus?: boolean;
6
+ children: React.ReactElement;
7
+ };
8
+ export declare const ColorableInputElement: import("../../../lib/forwardRefAndName").ReactUIComponentWithRef<InputElement, InputElementProps & {
9
+ active?: boolean | undefined;
10
+ showOnFocus?: boolean | undefined;
11
+ children: React.ReactElement;
12
+ }> & Record<never, never>;
@@ -0,0 +1,157 @@
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.ColorableInputElement = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));var _react = _interopRequireWildcard(require("react"));
2
+ var _globalObject = require("@skbkontur/global-object");
3
+ var _lodash = _interopRequireDefault(require("lodash.debounce"));
4
+
5
+ var _ThemeContext = require("../../../lib/theming/ThemeContext");
6
+
7
+ var _forwardRefAndName = require("../../../lib/forwardRefAndName");
8
+ var _Emotion = require("../../../lib/theming/Emotion");
9
+
10
+ var _ColorableInputElement = require("./ColorableInputElement.styles");var _excluded = ["children", "onInput", "onFocus", "onBlur", "active", "showOnFocus"];
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ var dictionary = new Map();
19
+ var paintText = function paintText(entries) {
20
+ entries.forEach(function (entry) {var _dictionary$get;return (_dictionary$get = dictionary.get(entry.target)) == null ? void 0 : _dictionary$get();});
21
+ };
22
+ var resizeObserver = _globalObject.globalObject.ResizeObserver ? new _globalObject.globalObject.ResizeObserver((0, _lodash.default)(paintText)) : null;
23
+
24
+ // Возможно придётся включить.
25
+ // Иногда, на тяжёлых страницах, текст рендерится итеративно.
26
+ // Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.
27
+ // setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 10000);
28
+
29
+ var ColorableInputElement = (0, _forwardRefAndName.forwardRefAndName)(
30
+ 'ColorableInputElement',
31
+ function ColorableInputElement(props, ref) {
32
+ var inputRef = (0, _react.useRef)(null);
33
+ var spanRef = (0, _react.useRef)(null);
34
+ var focused = (0, _react.useRef)(false);
35
+ var inputStyle = _react.default.useRef();
36
+ var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
37
+
38
+ var children = props.children,onInput = props.onInput,onFocus = props.onFocus,onBlur = props.onBlur,_props$active = props.active,active = _props$active === void 0 ? true : _props$active,_props$showOnFocus = props.showOnFocus,showOnFocus = _props$showOnFocus === void 0 ? false : _props$showOnFocus,inputProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
39
+
40
+ (0, _react.useImperativeHandle)(
41
+ ref,
42
+ function () {return {
43
+ input: inputRef.current,
44
+ getRootNode: function getRootNode() {return inputRef.current;} };},
45
+
46
+ []);
47
+
48
+
49
+ (0, _react.useEffect)(function () {
50
+ if (inputRef.current) {
51
+ dictionary.set(inputRef.current, paintText);
52
+ resizeObserver == null ? void 0 : resizeObserver.observe(inputRef.current);
53
+ }
54
+
55
+ return function () {
56
+ if (inputRef.current) {
57
+ dictionary.delete(inputRef.current);
58
+ resizeObserver == null ? void 0 : resizeObserver.unobserve(inputRef.current);
59
+ }
60
+ };
61
+ }, []);
62
+
63
+ (0, _react.useEffect)(function () {
64
+ // При деактивации быстро выключаем покраску
65
+ !active ? unPaintText() : setTimeout(paintText);
66
+ }, [showOnFocus, active]);
67
+
68
+ (0, _react.useEffect)(function () {
69
+ if (inputRef.current) {
70
+ inputStyle.current = getComputedStyle(inputRef.current);
71
+ }
72
+ });
73
+
74
+ return /*#__PURE__*/(
75
+ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/
76
+ _react.default.cloneElement(children, (0, _extends2.default)({},
77
+ inputProps, {
78
+ onInput: handleInput,
79
+ onFocus: handleFocus,
80
+ onBlur: handleBlur,
81
+ inputRef: inputRef,
82
+ className: (0, _Emotion.cx)(props.className, active && _ColorableInputElement.styles.input()) })), /*#__PURE__*/
83
+
84
+ _react.default.createElement("span", { style: { visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }, ref: spanRef })));
85
+
86
+
87
+
88
+ function handleInput(e) {
89
+ // iMask может изменить value после вызова onInput
90
+ setTimeout(paintText);
91
+
92
+ onInput == null ? void 0 : onInput(e);
93
+ }
94
+
95
+ function handleFocus(e) {
96
+ focused.current = true;
97
+ setTimeout(paintText);
98
+
99
+ onFocus == null ? void 0 : onFocus(e);
100
+ }
101
+
102
+ function handleBlur(e) {
103
+ focused.current = false;
104
+ setTimeout(paintText);
105
+
106
+ onBlur == null ? void 0 : onBlur(e);
107
+ }
108
+
109
+ function unPaintText() {
110
+ inputRef.current && (inputRef.current.style.backgroundImage = '');
111
+ }
112
+
113
+ function paintText() {var _shadow;
114
+ if (!active || !spanRef.current || !inputRef.current || !inputStyle.current || !(0, _globalObject.isBrowser)(_globalObject.globalObject)) {
115
+ return;
116
+ }
117
+
118
+ var shadow = spanRef.current.shadowRoot;
119
+ var typedValueElement = (_shadow = shadow) == null ? void 0 : _shadow.getElementById('span');
120
+
121
+ if (!typedValueElement) {
122
+ shadow = spanRef.current.attachShadow({ mode: 'open' });
123
+
124
+ typedValueElement = _globalObject.globalObject.document.createElement('span');
125
+ typedValueElement.setAttribute('id', 'span');
126
+
127
+ shadow.appendChild(typedValueElement);
128
+ }
129
+
130
+ var style = inputStyle.current;
131
+
132
+ typedValueElement.textContent = inputRef.current.getAttribute('data-typed-value') || '';
133
+
134
+ var inputRect = inputRef.current.getBoundingClientRect();
135
+ var filledRect = spanRef.current.getBoundingClientRect();
136
+
137
+ var threshold = filledRect.width / (inputRect.width / 100);
138
+ var degree = style.fontStyle === 'italic' ? 100 : 90;
139
+
140
+ var typedValueColor = theme.inputTextColor;
141
+ var maskColor = theme.inputPlaceholderColor;
142
+ if (props.disabled) {
143
+ typedValueColor = theme.inputTextColorDisabled;
144
+ maskColor = theme.inputTextColorDisabled;
145
+ }
146
+ if (showOnFocus) {
147
+ maskColor = focused.current ? maskColor : 'transparent';
148
+ }
149
+
150
+ inputRef.current.style.backgroundImage = "\n linear-gradient(\n " +
151
+
152
+ degree + "deg,\n " +
153
+ typedValueColor + " " + threshold + "%,\n " +
154
+ maskColor + " " + threshold + "%\n )";
155
+
156
+ }
157
+ });exports.ColorableInputElement = ColorableInputElement;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ColorableInputElement.tsx"],"names":["dictionary","Map","paintText","entries","forEach","entry","get","target","resizeObserver","globalObject","ResizeObserver","ColorableInputElement","props","ref","inputRef","spanRef","focused","inputStyle","React","useRef","theme","ThemeContext","children","onInput","onFocus","onBlur","active","showOnFocus","inputProps","input","current","getRootNode","set","observe","delete","unobserve","unPaintText","setTimeout","getComputedStyle","cloneElement","handleInput","handleFocus","handleBlur","className","styles","visibility","position","whiteSpace","e","style","backgroundImage","shadow","shadowRoot","typedValueElement","getElementById","attachShadow","mode","document","createElement","setAttribute","appendChild","textContent","getAttribute","inputRect","getBoundingClientRect","filledRect","threshold","width","degree","fontStyle","typedValueColor","inputTextColor","maskColor","inputPlaceholderColor","disabled","inputTextColorDisabled"],"mappings":"wdAAA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA,uE;;;;;;;;AAQA,IAAMA,UAAU,GAAG,IAAIC,GAAJ,EAAnB;AACA,IAAMC,SAAiC,GAAG,SAApCA,SAAoC,CAACC,OAAD,EAAa;AACrDA,EAAAA,OAAO,CAACC,OAAR,CAAgB,UAACC,KAAD,iDAAWL,UAAU,CAACM,GAAX,CAAeD,KAAK,CAACE,MAArB,CAAX,qBAAW,iBAAX,EAAhB;AACD,CAFD;AAGA,IAAMC,cAAc,GAAGC,2BAAaC,cAAb,GAA8B,IAAID,2BAAaC,cAAjB,CAAgC,qBAASR,SAAT,CAAhC,CAA9B,GAAqF,IAA5G;;AAEA;AACA;AACA;AACA;;AAEO,IAAMS,qBAAqB,GAAG;AACnC,uBADmC;AAEnC,SAASA,qBAAT,CAA+BC,KAA/B,EAAkEC,GAAlE,EAAmG;AACjG,MA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AEA,QAAME,SAAS,GAAGD,UAAU,CAACE,KAAX,IAAoBJ,SAAS,CAACI,KAAV,GAAkB,GAAtC,CAAlB;AACA,QAAMC,MAAM,GAAGnB,KAAK,CAACoB,SAAN,KAAoB,QAApB,GAA+B,GAA/B,GAAqC,EAApD;;AAEA,QAAIC,eAAe,GAAGlD,KAAK,CAACmD,cAA5B;AACA,QAAIC,SAAS,GAAGpD,KAAK,CAACqD,qBAAtB;AACA,QAAI7D,KAAK,CAAC8D,QAAV,EAAoB;AAClBJ,MAAAA,eAAe,GAAGlD,KAAK,CAACuD,sBAAxB;AACAH,MAAAA,SAAS,GAAGpD,KAAK,CAACuD,sBAAlB;AACD;AACD,QAAIhD,WAAJ,EAAiB;AACf6C,MAAAA,SAAS,GAAGxD,OAAO,CAACc,OAAR,GAAkB0C,SAAlB,GAA8B,aAA1C;AACD;;AAED1D,IAAAA,QAAQ,CAACgB,OAAT,CAAiBmB,KAAjB,CAAuBC,eAAvB;;AAEMkB,IAAAA,MAFN;AAGME,IAAAA,eAHN,SAGyBJ,SAHzB;AAIMM,IAAAA,SAJN,SAImBN,SAJnB;;AAMD;AACF,CAhIkC,CAA9B,C","sourcesContent":["import React, { ForwardedRef, useContext, useEffect, useImperativeHandle, useRef } from 'react';\nimport { globalObject, isBrowser } from '@skbkontur/global-object';\nimport debounce from 'lodash.debounce';\n\nimport { ThemeContext } from '../../../lib/theming/ThemeContext';\nimport { InputElement, InputElementProps } from '../../Input';\nimport { forwardRefAndName } from '../../../lib/forwardRefAndName';\nimport { cx } from '../../../lib/theming/Emotion';\n\nimport { styles } from './ColorableInputElement.styles';\n\nexport type ColorableInputElementProps = InputElementProps & {\n active?: boolean;\n showOnFocus?: boolean;\n children: React.ReactElement;\n};\n\nconst dictionary = new Map<Element, () => void>();\nconst paintText: ResizeObserverCallback = (entries) => {\n entries.forEach((entry) => dictionary.get(entry.target)?.());\n};\nconst resizeObserver = globalObject.ResizeObserver ? new globalObject.ResizeObserver(debounce(paintText)) : null;\n\n// Возможно придётся включить.\n// Иногда, на тяжёлых страницах, текст рендерится итеративно.\n// Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.\n// setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 10000);\n\nexport const ColorableInputElement = forwardRefAndName(\n 'ColorableInputElement',\n function ColorableInputElement(props: ColorableInputElementProps, ref: ForwardedRef<InputElement>) {\n const inputRef = useRef<HTMLInputElement | null>(null);\n const spanRef = useRef<HTMLSpanElement | null>(null);\n const focused = useRef(false);\n const inputStyle = React.useRef<CSSStyleDeclaration>();\n const theme = useContext(ThemeContext);\n\n const { children, onInput, onFocus, onBlur, active = true, showOnFocus = false, ...inputProps } = props;\n\n useImperativeHandle(\n ref,\n () => ({\n input: inputRef.current,\n getRootNode: () => inputRef.current,\n }),\n [],\n );\n\n useEffect(() => {\n if (inputRef.current) {\n dictionary.set(inputRef.current, paintText);\n resizeObserver?.observe(inputRef.current);\n }\n\n return () => {\n if (inputRef.current) {\n dictionary.delete(inputRef.current);\n resizeObserver?.unobserve(inputRef.current);\n }\n };\n }, []);\n\n useEffect(() => {\n // При деактивации быстро выключаем покраску\n !active ? unPaintText() : setTimeout(paintText);\n }, [showOnFocus, active]);\n\n useEffect(() => {\n if (inputRef.current) {\n inputStyle.current = getComputedStyle(inputRef.current);\n }\n });\n\n return (\n <>\n {React.cloneElement(children, {\n ...inputProps,\n onInput: handleInput,\n onFocus: handleFocus,\n onBlur: handleBlur,\n inputRef,\n className: cx(props.className, active && styles.input()),\n })}\n <span style={{ visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }} ref={spanRef} />\n </>\n );\n\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n // iMask может изменить value после вызова onInput\n setTimeout(paintText);\n\n onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n focused.current = true;\n setTimeout(paintText);\n\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n focused.current = false;\n setTimeout(paintText);\n\n onBlur?.(e);\n }\n\n function unPaintText() {\n inputRef.current && (inputRef.current.style.backgroundImage = '');\n }\n\n function paintText() {\n if (!active || !spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {\n return;\n }\n\n let shadow = spanRef.current.shadowRoot;\n let typedValueElement = shadow?.getElementById('span');\n\n if (!typedValueElement) {\n shadow = spanRef.current.attachShadow({ mode: 'open' });\n\n typedValueElement = globalObject.document.createElement('span');\n typedValueElement.setAttribute('id', 'span');\n\n shadow.appendChild(typedValueElement);\n }\n\n const style = inputStyle.current;\n\n typedValueElement.textContent = inputRef.current.getAttribute('data-typed-value') || '';\n\n const inputRect = inputRef.current.getBoundingClientRect();\n const filledRect = spanRef.current.getBoundingClientRect();\n\n const threshold = filledRect.width / (inputRect.width / 100);\n const degree = style.fontStyle === 'italic' ? 100 : 90;\n\n let typedValueColor = theme.inputTextColor;\n let maskColor = theme.inputPlaceholderColor;\n if (props.disabled) {\n typedValueColor = theme.inputTextColorDisabled;\n maskColor = theme.inputTextColorDisabled;\n }\n if (showOnFocus) {\n maskColor = focused.current ? maskColor : 'transparent';\n }\n\n inputRef.current.style.backgroundImage = `\n linear-gradient(\n ${degree}deg,\n ${typedValueColor} ${threshold}%,\n ${maskColor} ${threshold}%\n )`;\n }\n },\n);\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const styles: {
2
+ input(): string;
3
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.styles = void 0;var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));var _Emotion = require("../../../lib/theming/Emotion");var _templateObject;
2
+
3
+ var styles = (0, _Emotion.memoizeStyle)({
4
+ input: function input() {
5
+ return (0, _Emotion.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2.default)(["\n display: inline-block;\n background-color: transparent;\n background-size: 100%;\n background-repeat: repeat;\n background-clip: text;\n -webkit-text-fill-color: transparent;\n "])));
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ } });exports.styles = styles;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ColorableInputElement.styles.ts"],"names":["styles","input","css"],"mappings":"oRAAA,uD;;AAEO,IAAMA,MAAM,GAAG,2BAAa;AACjCC,EAAAA,KADiC,mBACzB;AACN,eAAOC,YAAP;;;;;;;;AAQD,GAVgC,EAAb,CAAf,C","sourcesContent":["import { css, memoizeStyle } from '../../../lib/theming/Emotion';\n\nexport const styles = memoizeStyle({\n input() {\n return css`\n display: inline-block;\n background-color: transparent;\n background-size: 100%;\n background-repeat: repeat;\n background-clip: text;\n -webkit-text-fill-color: transparent;\n `;\n },\n});\n"]}
@@ -0,0 +1 @@
1
+ export * from './ColorableInputElement';
@@ -0,0 +1 @@
1
+ "use strict";exports.__esModule = true;var _ColorableInputElement = require("./ColorableInputElement");Object.keys(_ColorableInputElement).forEach(function (key) {if (key === "default" || key === "__esModule") return;if (key in exports && exports[key] === _ColorableInputElement[key]) return;exports[key] = _ColorableInputElement[key];});
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"uCAAA","sourcesContent":["export * from './ColorableInputElement';\n"]}
@@ -0,0 +1,9 @@
1
+ import { InputMask, MaskedPatternOptions } from 'imask';
2
+ import { IMaskInputProps } from 'react-imask';
3
+ export declare type FixedIMaskInputProps = IMaskInputProps<HTMLInputElement>;
4
+ interface IMaskRefType {
5
+ maskRef: InputMask<MaskedPatternOptions>;
6
+ element: HTMLInputElement;
7
+ }
8
+ export declare const FixedIMaskInput: import("../../lib/forwardRefAndName").ReactUIComponentWithRef<IMaskRefType, FixedIMaskInputProps> & Record<never, never>;
9
+ export {};
@@ -0,0 +1,219 @@
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.FixedIMaskInput = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));var _react = _interopRequireWildcard(require("react"));
2
+
3
+ var _reactImask = require("react-imask");
4
+
5
+ var _forwardRefAndName = require("../../lib/forwardRefAndName");
6
+ var _identifiers = require("../../lib/events/keyboard/identifiers");
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ var _MouseDrag = require("../../lib/events/MouseDrag");var _excluded = ["inputRef"];
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ var FixedIMaskInput = (0, _forwardRefAndName.forwardRefAndName)(
32
+ 'FixedIMaskInput',
33
+ function FixedIMaskInput(props, ref) {
34
+ var inputRef = props.inputRef,restProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
35
+ var imaskRef = (0, _react.useRef)(null);
36
+ var focused = (0, _react.useRef)(false);
37
+
38
+ (0, _react.useEffect)(function () {var _imaskRef$current;
39
+ if ((_imaskRef$current = imaskRef.current) != null && _imaskRef$current.element) {
40
+ fillTypedValue();
41
+ var mouseDrag = _MouseDrag.MouseDrag.listen(imaskRef.current.element).onMouseDragEnd(function (e) {var _imaskRef$current2, _imaskRef$current3;
42
+ var direction = 'none';
43
+
44
+ if (
45
+ mouseDrag.mouseDragStartEvent &&
46
+ ((_imaskRef$current2 = imaskRef.current) == null ? void 0 : _imaskRef$current2.element.selectionStart) !== ((_imaskRef$current3 = imaskRef.current) == null ? void 0 : _imaskRef$current3.element.selectionEnd))
47
+ {
48
+ direction = mouseDrag.mouseDragStartEvent.pageX > e.pageX ? 'backward' : 'forward';
49
+ }
50
+
51
+ var _getSelection = getSelection(),start = _getSelection[0],end = _getSelection[1];
52
+ setSelection(start, end, direction);
53
+ });
54
+ }
55
+ }, []);
56
+
57
+ (0, _react.useImperativeHandle)(ref, function () {return imaskRef.current;}, []);
58
+
59
+ return /*#__PURE__*/(
60
+ _react.default.createElement(_reactImask.IMaskInput, (0, _extends2.default)({},
61
+ restProps, {
62
+ ref: imaskRef,
63
+ inputRef: inputRef,
64
+ onKeyDown: handleKeyDown,
65
+ onFocus: handleFocus,
66
+ onBlur: handleBlur,
67
+ onMouseUp: handleMouseUp,
68
+ onAccept: handleAccept })));
69
+
70
+
71
+ function getTypedValue() {var _imaskRef$current4;
72
+ var _ref = ((_imaskRef$current4 = imaskRef.current) == null ? void 0 : _imaskRef$current4.maskRef.masked) || {},_ref$_value = _ref._value,_value = _ref$_value === void 0 ? '' : _ref$_value,_ref$displayValue = _ref.displayValue,displayValue = _ref$displayValue === void 0 ? '' : _ref$displayValue;
73
+ var end = getMaxCaretPosition();
74
+ var value = _value !== '' || focused.current === true ? displayValue : '';
75
+
76
+ return value.slice(0, end);
77
+ }
78
+
79
+ function fillTypedValue() {var _imaskRef$current5;
80
+ (_imaskRef$current5 = imaskRef.current) == null ? void 0 : _imaskRef$current5.element.setAttribute('data-typed-value', getTypedValue());
81
+ }
82
+
83
+ function getMaxCaretPosition() {
84
+ var maskChars = [];
85
+ if (imaskRef.current) {
86
+ maskChars.push(imaskRef.current.maskRef.masked.placeholderChar);
87
+ if (imaskRef.current.maskRef.masked.blocks) {
88
+ Object.values(imaskRef.current.maskRef.masked.blocks).forEach(
89
+ function (_ref2) {var placeholderChar = _ref2.placeholderChar;return placeholderChar && maskChars.push(placeholderChar);});
90
+
91
+ }
92
+ return imaskRef.current.element.value.split(new RegExp(maskChars.join('|')))[0].length;
93
+ }
94
+
95
+ return Infinity;
96
+ }
97
+
98
+ function normalizeSelection() {
99
+ var _getSelection2 = getSelection(),start = _getSelection2[0],end = _getSelection2[1];
100
+ var max = getMaxCaretPosition();
101
+ if (end > max) {
102
+ setSelection(start, max);
103
+ }
104
+ }
105
+
106
+ function getNormalizedRange(calc) {
107
+ return typeof calc === 'number' ? Math.min(getMaxCaretPosition(), Math.max(0, calc)) : 0;
108
+ }
109
+
110
+ function getSelection() {
111
+ if (imaskRef.current) {
112
+ return [
113
+ imaskRef.current.element.selectionStart || 0,
114
+ imaskRef.current.element.selectionEnd || 0,
115
+ imaskRef.current.element.selectionDirection || 'none'];
116
+
117
+ }
118
+ return [0, 0, 'none'];
119
+ }
120
+
121
+ function setSelection() {var _imaskRef$current6;for (var _len = arguments.length, _ref3 = new Array(_len), _key = 0; _key < _len; _key++) {_ref3[_key] = arguments[_key];}var start = _ref3[0],end = _ref3[1],direction = _ref3[2];
122
+ (_imaskRef$current6 = imaskRef.current) == null ? void 0 : _imaskRef$current6.element.setSelectionRange(
123
+ getNormalizedRange(start),
124
+ getNormalizedRange(end),
125
+ direction || 'none');
126
+
127
+ }
128
+
129
+ function jumpCaret(prev, headDirection) {var _imaskRef$current7, _imaskRef$current7$el;
130
+ var word = /а-яa-z0-9_/.valueOf();
131
+ var wordRegExp = new RegExp("([" + word + "])+[\\s]*|([^" + word + "])+", 'gi');
132
+ var next = headDirection === 'right' ? prev : 0;
133
+ (_imaskRef$current7 = imaskRef.current) == null ? void 0 : (_imaskRef$current7$el = _imaskRef$current7.element.value.match(wordRegExp)) == null ? void 0 : _imaskRef$current7$el.reduce(function (s, a) {
134
+ var pos = a.length + (s.slice(-1)[0] || 0);
135
+ if (headDirection === 'right' && next === prev && next < pos) {
136
+ next = getNormalizedRange(pos);
137
+ } else if (headDirection === 'left' && prev > pos) {
138
+ next = getNormalizedRange(pos);
139
+ }
140
+ return [].concat(s, [pos]);
141
+ }, []);
142
+ return next;
143
+ }
144
+
145
+ /**
146
+ * Вычислят положение каретки при управлении клавишами
147
+ * @param e
148
+ */
149
+ function calcSelection(e) {
150
+ var _getSelection3 = getSelection(),start = _getSelection3[0],end = _getSelection3[1],direction = _getSelection3[2];
151
+ var isSelectionMode = (0, _identifiers.isModShift)()(e);
152
+ var tail = start !== end && direction === 'backward' ? end : start;
153
+ var head = start !== end && direction === 'backward' ? start : end;
154
+ var headDirection = (0, _identifiers.someKeys)(_identifiers.isKeyArrowLeft, _identifiers.isKeyArrowUp, _identifiers.isKeyHome)(e) ? 'left' : 'right';
155
+ var step = (0, _identifiers.isKeyArrowHorizontal)(e) ? 1 : Infinity;
156
+ var increment = headDirection === 'left' ? -step : step;
157
+ if ((0, _identifiers.isShortcutJumpCaret)(e)) {
158
+ head = jumpCaret(head, headDirection);
159
+ } else if (head !== tail && !isSelectionMode && (0, _identifiers.isKeyArrowHorizontal)(e)) {
160
+ head = headDirection === 'right' ? Math.max(tail, head) : Math.min(tail, head);
161
+ } else {
162
+ head = head + increment;
163
+ }
164
+ if (isSelectionMode) {
165
+ var _start = Math.min(tail, head);
166
+ var _end = Math.max(tail, head);
167
+ return [getNormalizedRange(_start), getNormalizedRange(_end), _end === head ? 'forward' : 'backward'];
168
+ }
169
+ tail = head;
170
+ return [getNormalizedRange(tail), getNormalizedRange(head), 'none'];
171
+ }
172
+
173
+ function handleMouseUp(e) {
174
+ normalizeSelection();
175
+
176
+ props.onMouseUp == null ? void 0 : props.onMouseUp(e);
177
+ }
178
+
179
+ function handleFocus(e) {
180
+ focused.current = true;
181
+ fillTypedValue();
182
+ normalizeSelection();
183
+
184
+ props.onFocus == null ? void 0 : props.onFocus(e);
185
+ }
186
+
187
+ function handleBlur(e) {
188
+ focused.current = false;
189
+ fillTypedValue();
190
+
191
+ props.onBlur == null ? void 0 : props.onBlur(e);
192
+ }
193
+
194
+ function handleAccept() {
195
+ fillTypedValue();for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {args[_key2] = arguments[_key2];}
196
+
197
+ props.onAccept == null ? void 0 : props.onAccept.apply(props, args);
198
+ }
199
+
200
+ function handleKeyDown(e) {
201
+ var nearest = getMaxCaretPosition();
202
+ if ((0, _identifiers.isShortcutSelectAll)(e)) {
203
+ e.preventDefault();
204
+ setSelection(0, nearest);
205
+ } else if ((0, _identifiers.isKeyArrow)(e) || (0, _identifiers.isKeyEnd)(e) || (0, _identifiers.isKeyHome)(e)) {
206
+ e.preventDefault();
207
+ var _calcSelection = calcSelection(e),start = _calcSelection[0],end = _calcSelection[1],direction = _calcSelection[2];
208
+ setSelection(start, end, direction);
209
+ } else {
210
+ var _getSelection4 = getSelection(),_start2 = _getSelection4[0],_end2 = _getSelection4[1];
211
+ var max = getMaxCaretPosition();
212
+ if (_end2 > max) {
213
+ setSelection(_start2, max);
214
+ }
215
+ }
216
+
217
+ props.onKeyDown == null ? void 0 : props.onKeyDown(e);
218
+ }
219
+ });exports.FixedIMaskInput = FixedIMaskInput;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["FixedIMaskInput.tsx"],"names":["FixedIMaskInput","props","ref","inputRef","restProps","imaskRef","focused","current","element","fillTypedValue","mouseDrag","MouseDrag","listen","onMouseDragEnd","e","direction","mouseDragStartEvent","selectionStart","selectionEnd","pageX","getSelection","start","end","setSelection","handleKeyDown","handleFocus","handleBlur","handleMouseUp","handleAccept","getTypedValue","maskRef","masked","_value","displayValue","getMaxCaretPosition","value","slice","setAttribute","maskChars","push","placeholderChar","blocks","Object","values","forEach","split","RegExp","join","length","Infinity","normalizeSelection","max","getNormalizedRange","calc","Math","min","selectionDirection","setSelectionRange","jumpCaret","prev","headDirection","word","valueOf","wordRegExp","next","match","reduce","s","a","pos","calcSelection","isSelectionMode","tail","head","isKeyArrowLeft","isKeyArrowUp","isKeyHome","step","increment","onMouseUp","onFocus","onBlur","args","onAccept","nearest","preventDefault","onKeyDown"],"mappings":"kdAAA;;AAEA;;AAEA;AACA;;;;;;;;;;;;AAYA,uD;;;;;;;;;;;;;AAaO,IAAMA,eAAe,GAAG;AAC7B,iBAD6B;AAE7B,SAASA,eAAT,CAAyBC,KAAzB,EAAsDC,GAAtD,EAA2F;AACzF,MAAQC,QAAR,GAAmCF,KAAnC,CAAQE,QAAR,CAAqBC,SAArB,+CAAmCH,KAAnC;AACA,MAAMI,QAAQ,GAAG,mBAAqB,IAArB,CA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YAAY,EAAjC,CAAOC,OAAP,qBAAcC,KAAd;AACA,UAAM6B,GAAG,GAAGjB,mBAAmB,EAA/B;AACA,UAAIZ,KAAG,GAAG6B,GAAV,EAAe;AACb5B,QAAAA,YAAY,CAACF,OAAD,EAAQ8B,GAAR,CAAZ;AACD;AACF;;AAEDlD,IAAAA,KAAK,CAACqF,SAAN,oBAAArF,KAAK,CAACqF,SAAN,CAAkBxE,CAAlB;AACD;AACF,CA5L4B,CAAxB,C","sourcesContent":["import React, { useEffect, useImperativeHandle, useRef } from 'react';\nimport { InputMask, MaskedPatternOptions } from 'imask';\nimport { IMaskInput, IMaskInputProps } from 'react-imask';\n\nimport { forwardRefAndName } from '../../lib/forwardRefAndName';\nimport {\n isKeyArrow,\n isKeyArrowHorizontal,\n isKeyArrowLeft,\n isKeyArrowUp,\n isKeyEnd,\n isKeyHome,\n isModShift,\n isShortcutJumpCaret,\n isShortcutSelectAll,\n someKeys,\n} from '../../lib/events/keyboard/identifiers';\nimport { MouseDrag } from '../../lib/events/MouseDrag';\n\nexport type FixedIMaskInputProps = IMaskInputProps<HTMLInputElement>;\n\ntype HeadDirection = 'left' | 'right';\ntype SelectionDirection = 'forward' | 'backward' | 'none';\ntype SelectionSet = [number, number, SelectionDirection];\n\ninterface IMaskRefType {\n maskRef: InputMask<MaskedPatternOptions>;\n element: HTMLInputElement;\n}\n\nexport const FixedIMaskInput = forwardRefAndName(\n 'FixedIMaskInput',\n function FixedIMaskInput(props: FixedIMaskInputProps, ref: React.Ref<IMaskRefType | null>) {\n const { inputRef, ...restProps } = props;\n const imaskRef = useRef<IMaskRefType>(null);\n const focused = useRef(false);\n\n useEffect(() => {\n if (imaskRef.current?.element) {\n fillTypedValue();\n const mouseDrag = MouseDrag.listen(imaskRef.current.element).onMouseDragEnd((e) => {\n let direction: SelectionDirection = 'none';\n\n if (\n mouseDrag.mouseDragStartEvent &&\n imaskRef.current?.element.selectionStart !== imaskRef.current?.element.selectionEnd\n ) {\n direction = mouseDrag.mouseDragStartEvent.pageX > e.pageX ? 'backward' : 'forward';\n }\n\n const [start, end] = getSelection();\n setSelection(start, end, direction);\n });\n }\n }, []);\n\n useImperativeHandle(ref, () => imaskRef.current, []);\n\n return (\n <IMaskInput\n {...restProps}\n ref={imaskRef}\n inputRef={inputRef}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onMouseUp={handleMouseUp}\n onAccept={handleAccept}\n />\n );\n function getTypedValue() {\n const { _value = '', displayValue = '' } = imaskRef.current?.maskRef.masked || {};\n const end = getMaxCaretPosition();\n const value = _value !== '' || focused.current === true ? displayValue : '';\n\n return value.slice(0, end);\n }\n\n function fillTypedValue() {\n imaskRef.current?.element.setAttribute('data-typed-value', getTypedValue());\n }\n\n function getMaxCaretPosition(): number {\n const maskChars = [];\n if (imaskRef.current) {\n maskChars.push(imaskRef.current.maskRef.masked.placeholderChar);\n if (imaskRef.current.maskRef.masked.blocks) {\n (Object.values(imaskRef.current.maskRef.masked.blocks) as Array<{ placeholderChar?: string }>).forEach(\n ({ placeholderChar }) => placeholderChar && maskChars.push(placeholderChar),\n );\n }\n return imaskRef.current.element.value.split(new RegExp(maskChars.join('|')))[0].length;\n }\n\n return Infinity;\n }\n\n function normalizeSelection() {\n const [start, end] = getSelection();\n const max = getMaxCaretPosition();\n if (end > max) {\n setSelection(start, max);\n }\n }\n\n function getNormalizedRange(calc: number | unknown) {\n return typeof calc === 'number' ? Math.min(getMaxCaretPosition(), Math.max(0, calc)) : 0;\n }\n\n function getSelection(): SelectionSet {\n if (imaskRef.current) {\n return [\n imaskRef.current.element.selectionStart || 0,\n imaskRef.current.element.selectionEnd || 0,\n imaskRef.current.element.selectionDirection || 'none',\n ];\n }\n return [0, 0, 'none'];\n }\n\n function setSelection(...[start, end, direction]: Parameters<HTMLInputElement['setSelectionRange']>) {\n imaskRef.current?.element.setSelectionRange(\n getNormalizedRange(start),\n getNormalizedRange(end),\n direction || 'none',\n );\n }\n\n function jumpCaret(prev: number, headDirection: HeadDirection) {\n const word = /а-яa-z0-9_/.valueOf();\n const wordRegExp = new RegExp(`([${word}])+[\\\\s]*|([^${word}])+`, 'gi');\n let next = headDirection === 'right' ? prev : 0;\n imaskRef.current?.element.value.match(wordRegExp)?.reduce<number[]>((s, a) => {\n const pos = a.length + (s.slice(-1)[0] || 0);\n if (headDirection === 'right' && next === prev && next < pos) {\n next = getNormalizedRange(pos);\n } else if (headDirection === 'left' && prev > pos) {\n next = getNormalizedRange(pos);\n }\n return [...s, pos];\n }, []);\n return next;\n }\n\n /**\n * Вычислят положение каретки при управлении клавишами\n * @param e\n */\n function calcSelection(e: React.KeyboardEvent<HTMLInputElement>): SelectionSet {\n const [start, end, direction] = getSelection();\n const isSelectionMode = isModShift()(e);\n let tail = start !== end && direction === 'backward' ? end : start;\n let head = start !== end && direction === 'backward' ? start : end;\n const headDirection: HeadDirection = someKeys(isKeyArrowLeft, isKeyArrowUp, isKeyHome)(e) ? 'left' : 'right';\n const step = isKeyArrowHorizontal(e) ? 1 : Infinity;\n const increment = headDirection === 'left' ? -step : step;\n if (isShortcutJumpCaret(e)) {\n head = jumpCaret(head, headDirection);\n } else if (head !== tail && !isSelectionMode && isKeyArrowHorizontal(e)) {\n head = headDirection === 'right' ? Math.max(tail, head) : Math.min(tail, head);\n } else {\n head = head + increment;\n }\n if (isSelectionMode) {\n const start = Math.min(tail, head);\n const end = Math.max(tail, head);\n return [getNormalizedRange(start), getNormalizedRange(end), end === head ? 'forward' : 'backward'];\n }\n tail = head;\n return [getNormalizedRange(tail), getNormalizedRange(head), 'none'];\n }\n\n function handleMouseUp(e: React.MouseEvent<HTMLInputElement>) {\n normalizeSelection();\n\n props.onMouseUp?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n focused.current = true;\n fillTypedValue();\n normalizeSelection();\n\n props.onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n focused.current = false;\n fillTypedValue();\n\n props.onBlur?.(e);\n }\n\n function handleAccept(...args: Parameters<Required<IMaskInputProps<HTMLInputElement>>['onAccept']>) {\n fillTypedValue();\n\n props.onAccept?.(...args);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n const nearest = getMaxCaretPosition();\n if (isShortcutSelectAll(e)) {\n e.preventDefault();\n setSelection(0, nearest);\n } else if (isKeyArrow(e) || isKeyEnd(e) || isKeyHome(e)) {\n e.preventDefault();\n const [start, end, direction] = calcSelection(e);\n setSelection(start, end, direction);\n } else {\n const [start, end] = getSelection();\n const max = getMaxCaretPosition();\n if (end > max) {\n setSelection(start, max);\n }\n }\n\n props.onKeyDown?.(e);\n }\n },\n);\n"]}
@@ -1,25 +1,30 @@
1
- import { InputMask, MaskedPatternOptions } from 'imask';
2
1
  import { IMaskInputProps } from 'react-imask';
3
2
  import { Nullable } from '../../typings/utility-types';
4
3
  import { Input, InputProps, InputType } from '../Input';
5
4
  export interface MaskedProps {
6
5
  /** Паттерн маски */
7
6
  mask: string;
8
- /** Символ маски */
7
+ /**
8
+ * Символ маски
9
+ *
10
+ * @see См. `imaskProps.placeholderChar`
11
+ * @default _
12
+ */
9
13
  maskChar?: Nullable<string>;
10
14
  /**
11
15
  * Словарь символов-регулярок для маски
16
+ *
17
+ * @see См. `imaskProps.definitions`
12
18
  * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' }
13
19
  */
14
20
  formatChars?: Record<string, string>;
15
21
  /**
16
- * Показывать символы маски
22
+ * Всегда показывать символы маски
17
23
  *
18
- * null - не показывать
19
- * true - показывать всегда
20
- * false - показывать по фокусу
24
+ * @see См. `imaskProps.lazy`
25
+ * @default false
21
26
  */
22
- alwaysShowMask?: boolean | null;
27
+ alwaysShowMask?: boolean;
23
28
  /**
24
29
  * Пропы для компонента `IMaskInput`
25
30
  *
@@ -28,10 +33,6 @@ export interface MaskedProps {
28
33
  imaskProps?: IMaskInputProps<HTMLInputElement>;
29
34
  }
30
35
  export declare type MaskInputType = Exclude<InputType, 'number' | 'date' | 'time' | 'password'>;
31
- export interface IMaskRefType {
32
- maskRef: InputMask<MaskedPatternOptions>;
33
- element: HTMLInputElement;
34
- }
35
36
  export interface MaskedInputProps extends MaskedProps, Omit<InputProps, 'mask' | 'maxLength' | 'type' | 'alwaysShowMask'> {
36
37
  type?: MaskInputType;
37
38
  }