@skbkontur/react-ui 4.21.0-next.2 → 4.21.0
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/CHANGELOG.md +22 -0
- package/cjs/components/Input/Input.d.ts +22 -5
- package/cjs/components/Input/Input.js +33 -14
- package/cjs/components/Input/Input.js.map +1 -1
- package/cjs/components/Input/Input.typings.d.ts +7 -0
- package/cjs/components/Input/Input.typings.js +1 -0
- package/cjs/components/Input/Input.typings.js.map +1 -0
- package/cjs/components/Input/index.d.ts +1 -0
- package/cjs/components/Input/index.js +2 -1
- package/cjs/components/Input/index.js.map +1 -1
- package/cjs/components/MaskedInput/MaskedInput.d.ts +24 -0
- package/cjs/components/MaskedInput/MaskedInput.js +78 -0
- package/cjs/components/MaskedInput/MaskedInput.js.map +1 -0
- package/cjs/components/MaskedInput/MaskedInput.md +21 -0
- package/cjs/components/MaskedInput/index.js.map +1 -0
- package/cjs/components/Token/Token.js +1 -1
- package/cjs/components/Token/Token.js.map +1 -1
- package/cjs/internal/{MaskedInput/MaskedInput.d.ts → InternalMaskedInput/InternalMaskedInput.d.ts} +8 -5
- package/cjs/internal/{MaskedInput/MaskedInput.js → InternalMaskedInput/InternalMaskedInput.js} +11 -8
- package/cjs/internal/InternalMaskedInput/InternalMaskedInput.js.map +1 -0
- package/cjs/internal/InternalMaskedInput/InternalMaskedInput.styles.js.map +1 -0
- package/cjs/internal/InternalMaskedInput/index.d.ts +1 -0
- package/cjs/internal/InternalMaskedInput/index.js +1 -0
- package/cjs/internal/InternalMaskedInput/index.js.map +1 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.d.ts +14 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.d.ts +16 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.js +52 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.helpers.js.map +1 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.js +196 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.js.map +1 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js +29 -0
- package/cjs/internal/MaskedInputElement/MaskedInputElement.styles.js.map +1 -0
- package/cjs/internal/MaskedInputElement/index.d.ts +1 -0
- package/cjs/internal/MaskedInputElement/index.js +1 -0
- package/cjs/internal/MaskedInputElement/index.js.map +1 -0
- package/cjs/lib/utils.d.ts +7 -0
- package/cjs/lib/utils.js +25 -2
- package/cjs/lib/utils.js.map +1 -1
- package/components/Input/Input/Input.js +14 -5
- package/components/Input/Input/Input.js.map +1 -1
- package/components/Input/Input.d.ts +22 -5
- package/components/Input/Input.typings/Input.typings.js +1 -0
- package/components/Input/Input.typings/Input.typings.js.map +1 -0
- package/components/Input/Input.typings/package.json +6 -0
- package/components/Input/Input.typings.d.ts +7 -0
- package/components/Input/index/index.js +2 -1
- package/components/Input/index/index.js.map +1 -1
- package/components/Input/index.d.ts +1 -0
- package/components/MaskedInput/MaskedInput/MaskedInput.js +62 -0
- package/components/MaskedInput/MaskedInput/MaskedInput.js.map +1 -0
- package/{internal → components}/MaskedInput/MaskedInput/package.json +1 -1
- package/components/MaskedInput/MaskedInput.d.ts +24 -0
- package/components/MaskedInput/MaskedInput.md +21 -0
- package/components/MaskedInput/index/index.js.map +1 -0
- package/{internal → components}/MaskedInput/index/package.json +1 -1
- package/{internal → components}/MaskedInput/package.json +1 -1
- package/components/Token/Token/Token.js +4 -3
- package/components/Token/Token/Token.js.map +1 -1
- package/internal/{MaskedInput/MaskedInput/MaskedInput.js → InternalMaskedInput/InternalMaskedInput/InternalMaskedInput.js} +13 -9
- package/internal/InternalMaskedInput/InternalMaskedInput/InternalMaskedInput.js.map +1 -0
- package/internal/InternalMaskedInput/InternalMaskedInput/package.json +6 -0
- package/internal/{MaskedInput/MaskedInput.d.ts → InternalMaskedInput/InternalMaskedInput.d.ts} +8 -5
- package/{cjs/internal/MaskedInput/MaskedInput.styles.js.map → internal/InternalMaskedInput/InternalMaskedInput.styles/InternalMaskedInput.styles.js.map} +1 -1
- package/internal/InternalMaskedInput/InternalMaskedInput.styles/package.json +6 -0
- package/internal/InternalMaskedInput/InternalMaskedInput.styles.d.ts +6 -0
- package/internal/InternalMaskedInput/index/index.js +1 -0
- package/internal/InternalMaskedInput/index/index.js.map +1 -0
- package/internal/InternalMaskedInput/index/package.json +6 -0
- package/internal/InternalMaskedInput/index.d.ts +1 -0
- package/internal/InternalMaskedInput/package.json +6 -0
- package/internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js +206 -0
- package/internal/MaskedInputElement/MaskedInputElement/MaskedInputElement.js.map +1 -0
- package/internal/MaskedInputElement/MaskedInputElement/package.json +6 -0
- package/internal/MaskedInputElement/MaskedInputElement.d.ts +14 -0
- package/internal/MaskedInputElement/MaskedInputElement.helpers/MaskedInputElement.helpers.js +43 -0
- package/internal/MaskedInputElement/MaskedInputElement.helpers/MaskedInputElement.helpers.js.map +1 -0
- package/internal/MaskedInputElement/MaskedInputElement.helpers/package.json +6 -0
- package/internal/MaskedInputElement/MaskedInputElement.helpers.d.ts +16 -0
- package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js +16 -0
- package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js.map +1 -0
- package/internal/MaskedInputElement/MaskedInputElement.styles/package.json +6 -0
- package/internal/MaskedInputElement/MaskedInputElement.styles.d.ts +6 -0
- package/internal/MaskedInputElement/index/index.js +1 -0
- package/internal/MaskedInputElement/index/index.js.map +1 -0
- package/internal/MaskedInputElement/index/package.json +6 -0
- package/internal/MaskedInputElement/index.d.ts +1 -0
- package/internal/MaskedInputElement/package.json +6 -0
- package/lib/utils/utils.js +27 -1
- package/lib/utils/utils.js.map +1 -1
- package/lib/utils.d.ts +7 -0
- package/package.json +4 -3
- package/cjs/internal/MaskedInput/MaskedInput.js.map +0 -1
- package/cjs/internal/MaskedInput/index.js.map +0 -1
- package/internal/MaskedInput/MaskedInput/MaskedInput.js.map +0 -1
- package/internal/MaskedInput/MaskedInput.styles/MaskedInput.styles.js.map +0 -1
- package/internal/MaskedInput/MaskedInput.styles/package.json +0 -6
- package/internal/MaskedInput/index/index.js.map +0 -1
- /package/cjs/{internal → components}/MaskedInput/index.d.ts +0 -0
- /package/cjs/{internal → components}/MaskedInput/index.js +0 -0
- /package/cjs/internal/{MaskedInput/MaskedInput.styles.d.ts → InternalMaskedInput/InternalMaskedInput.styles.d.ts} +0 -0
- /package/cjs/internal/{MaskedInput/MaskedInput.styles.js → InternalMaskedInput/InternalMaskedInput.styles.js} +0 -0
- /package/{internal/MaskedInput/MaskedInput.styles.d.ts → cjs/internal/MaskedInputElement/MaskedInputElement.styles.d.ts} +0 -0
- /package/{internal → components}/MaskedInput/index/index.js +0 -0
- /package/{internal → components}/MaskedInput/index.d.ts +0 -0
- /package/internal/{MaskedInput/MaskedInput.styles/MaskedInput.styles.js → InternalMaskedInput/InternalMaskedInput.styles/InternalMaskedInput.styles.js} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DEFAULT_MASK_CHAR = "_";
|
|
2
|
+
export declare const DEFINITIONS: {
|
|
3
|
+
'9': RegExp;
|
|
4
|
+
a: RegExp;
|
|
5
|
+
'*': RegExp;
|
|
6
|
+
};
|
|
7
|
+
export declare function getDefinitions(formatChars: Record<string, string> | undefined): Record<string, RegExp>;
|
|
8
|
+
export declare function getMaskChar(maskChar: string | null | undefined): string;
|
|
9
|
+
interface MaskedInputValues {
|
|
10
|
+
originValue: string;
|
|
11
|
+
value: string;
|
|
12
|
+
emptyValue: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function getFocusPrefix(emptyValue: string, maskChar: string | null | undefined): string;
|
|
15
|
+
export declare function getCurrentValue(values: MaskedInputValues, focused: boolean, maskChar: string | null | undefined): [currentValue: string, left: string, right: string];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
|
|
2
|
+
|
|
3
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
4
|
+
|
|
5
|
+
import { css, memoizeStyle } from "../../../lib/theming/Emotion";
|
|
6
|
+
export var styles = memoizeStyle({
|
|
7
|
+
container: function container() {
|
|
8
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n display: inline-flex;\n position: relative;\n font-size: inherit;\n flex: 100% 1 1;\n "])));
|
|
9
|
+
},
|
|
10
|
+
inputMask: function inputMask(t) {
|
|
11
|
+
return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n color: ", ";\n pointer-events: none;\n font-size: inherit;\n z-index: 5;\n user-select: none;\n "])), t.placeholderColor);
|
|
12
|
+
},
|
|
13
|
+
inputMaskLeft: function inputMaskLeft() {
|
|
14
|
+
return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n "])));
|
|
15
|
+
}
|
|
16
|
+
});
|
package/internal/MaskedInputElement/MaskedInputElement.styles/MaskedInputElement.styles.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["MaskedInputElement.styles.ts"],"names":["css","memoizeStyle","styles","container","inputMask","t","placeholderColor","inputMaskLeft"],"mappings":"wJAAA,SAASA,GAAT,EAAcC,YAAd,QAAkC,2BAAlC;;;AAGA,OAAO,IAAMC,MAAM,GAAGD,YAAY,CAAC;AACjCE,EAAAA,SADiC,uBACrB;AACV,WAAOH,GAAP;;;;;;AAMD,GARgC;AASjCI,EAAAA,SATiC,qBASvBC,CATuB,EASb;AAClB,WAAOL,GAAP;AACWK,IAAAA,CAAC,CAACC,gBADb;;;;;;AAOD,GAjBgC;AAkBjCC,EAAAA,aAlBiC,2BAkBjB;AACd,WAAOP,GAAP;;;;;;AAMD,GAzBgC,EAAD,CAA3B","sourcesContent":["import { css, memoizeStyle } from '../../lib/theming/Emotion';\nimport { Theme } from '../../lib/theming/Theme';\n\nexport const styles = memoizeStyle({\n container() {\n return css`\n display: inline-flex;\n position: relative;\n font-size: inherit;\n flex: 100% 1 1;\n `;\n },\n inputMask(t: Theme) {\n return css`\n color: ${t.placeholderColor};\n pointer-events: none;\n font-size: inherit;\n z-index: 5;\n user-select: none;\n `;\n },\n inputMaskLeft() {\n return css`\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n `;\n },\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../MaskedInputElement";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAd","sourcesContent":["export * from './MaskedInputElement';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MaskedInputElement';
|
package/lib/utils/utils.js
CHANGED
|
@@ -209,4 +209,30 @@ export var startsWithOneOf = function startsWithOneOf(searchKeys, inputString) {
|
|
|
209
209
|
export var isInputLike = isReactUIComponent('Input') || isReactUIComponent('FxInput') || isReactUIComponent('Autocomplete') || isReactUIComponent('PasswordInput') || isReactUIComponent('CurrencyInput');
|
|
210
210
|
export var isKonturIcon = function isKonturIcon(icon) {
|
|
211
211
|
return Object.prototype.hasOwnProperty.call(icon == null ? void 0 : icon.type, '__KONTUR_ICON__');
|
|
212
|
-
};
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Allows to get text of all nested children as a string
|
|
215
|
+
*
|
|
216
|
+
* @param children React's children
|
|
217
|
+
* @returns Nested child text or an empty string
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
export function getChildrenText(children) {
|
|
221
|
+
if (typeof children === 'string' || typeof children === 'number') {
|
|
222
|
+
return children.toString();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (Array.isArray(children)) {
|
|
226
|
+
return children.map(function (entry) {
|
|
227
|
+
return getChildrenText(entry);
|
|
228
|
+
}).join('');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var nextChild = children == null ? void 0 : children.props.children;
|
|
232
|
+
|
|
233
|
+
if (!nextChild) {
|
|
234
|
+
return '';
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return getChildrenText(nextChild);
|
|
238
|
+
}
|
package/lib/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":["React","isForwardRef","globalObject","isBrowser","delay","ms","Promise","resolve","setTimeout","emptyHandler","CancelationError","code","Error","taskWithDelay","task","cancelationToken","reject","then","isFunction","x","isFunctionalComponent","Component","Boolean","prototype","isReactComponent","isClassComponent","isIntrinsicElement","element","type","isRefableElement","escapeRegExpSpecChars","s","replace","getRandomID","Math","random","toString","slice","isExternalLink","link","RegExp","location","host","test","isReactUINode","componentName","node","isValidElement","Object","hasOwnProperty","call","__KONTUR_REACT_UI__","KB","UNITS","calculateDecimals","decimals","formatBytes","bytes","calculatedDecimals","i","floor","log2","formattedBytes","parseFloat","pow","toFixed","isNonNullable","value","undefined","isNullable","isReactUIComponent","name","child","mergeRefs","refs","forEach","ref","current","extractDataProps","props","dataProps","restWithoutDataProps","entries","map","startsWith","startsWithOneOf","searchKeys","inputString","keyIndex","findIndex","key","isInputLike","isKonturIcon","icon"],"mappings":"gJAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,YAAT,QAA6B,UAA7B;AACA,SAASC,YAAT,EAAuBC,SAAvB,QAAwC,0BAAxC;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAACC,EAAD,UAAgB,IAAIC,OAAJ,CAAY,UAACC,OAAD,UAAaL,YAAY,CAACM,UAAb,CAAwBD,OAAxB,EAAiCF,EAAjC,CAAb,EAAZ,CAAhB,EAAd;;AAEP,OAAO,IAAMI,YAAY,GAAG,SAAfA,YAAe,GAAM;AAChC;AACD,CAFM;;AAIP,WAAaC,gBAAb;AACSC,IAAAA,IADT,GACg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QP,OAAO,IAAMG,WAAW;AACtBrB,kBAAkB,CAAa,OAAb,CAAlB;AACAA,kBAAkB,CAAe,SAAf,CADlB;AAEAA,kBAAkB,CAAoB,cAApB,CAFlB;AAGAA,kBAAkB,CAAqB,eAArB,CAHlB;AAIAA,kBAAkB,CAAqB,eAArB,CALb;;AAOP,OAAO,IAAMsB,YAAY,GAAG,SAAfA,YAAe,CAACC,IAAD,EAA8B;AACxD,SAAO7C,MAAM,CAACzB,SAAP,CAAiB0B,cAAjB,CAAgCC,IAAhC,CAAqC2C,IAArC,oBAAqCA,IAAI,CAAEjE,IAA3C,EAAiD,iBAAjD,CAAP;AACD,CAFM","sourcesContent":["import React from 'react';\nimport { isForwardRef } from 'react-is';\nimport { globalObject, isBrowser } from '@skbkontur/global-object';\n\nimport { CurrencyInputProps } from '../components/CurrencyInput';\nimport { PasswordInputProps } from '../components/PasswordInput';\nimport { InputProps } from '../components/Input';\nimport { AutocompleteProps } from '../components/Autocomplete';\nimport { FxInputProps } from '../components/FxInput';\n\n// NOTE: Copy-paste from @types/react\nexport type Defaultize<P, D> = P extends any\n ? string extends keyof P\n ? P\n : Pick<P, Exclude<keyof P, keyof D>> &\n Partial<Pick<P, Extract<keyof P, keyof D>>> &\n Partial<Pick<D, Exclude<keyof D, keyof P>>>\n : never;\n\nexport type DefaultizeProps<C, P> = C extends { defaultProps: infer D } ? Defaultize<P, D> : P;\n\nexport type AnyObject = Record<string, unknown>;\n\nexport const delay = (ms: number) => new Promise((resolve) => globalObject.setTimeout(resolve, ms));\n\nexport const emptyHandler = () => {\n /* noop */\n};\n\nexport class CancelationError extends Error {\n public code = 'CancelationError';\n}\n\nexport function taskWithDelay(task: () => void, ms: number) {\n let cancelationToken: () => void = () => null;\n\n new Promise((resolve, reject) => {\n cancelationToken = reject;\n globalObject.setTimeout(resolve, ms);\n })\n .then(task)\n .catch(() => null);\n\n return cancelationToken;\n}\n\nexport type FunctionWithParams<R = any> = (...args: any[]) => R;\nexport function isFunction<T>(x: T | FunctionWithParams): x is FunctionWithParams {\n return typeof x === 'function';\n}\n\nexport function isFunctionalComponent(Component: unknown): Component is React.ComponentType {\n return Boolean(typeof Component === 'function' && !(Component.prototype && Component.prototype.isReactComponent));\n}\n\nexport function isClassComponent(Component: unknown): Component is React.ComponentType {\n return Boolean(typeof Component === 'function' && Component.prototype && Component.prototype.isReactComponent);\n}\n\nexport function isIntrinsicElement(element: React.ReactElement): boolean {\n return typeof element.type === 'string';\n}\n\nexport function isRefableElement(element: React.ReactElement): boolean {\n return Boolean(isIntrinsicElement(element) || isClassComponent(element.type) || isForwardRef(element));\n}\n\nexport function escapeRegExpSpecChars(s: string): string {\n return s.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n\nexport const getRandomID = (): string => Math.random().toString(16).slice(2);\n\nexport const isExternalLink = (link: string): boolean => {\n return isBrowser(globalObject) && new RegExp(`^(https?:)?//(?!${globalObject.location.host})\\\\S+`, 'gi').test(link);\n};\n\n/**\n * Check if the given ReactNode is an element of the specified ReactUI component\n */\nexport const isReactUINode = (componentName: string, node: React.ReactNode): boolean => {\n if (React.isValidElement(node)) {\n return (\n Object.prototype.hasOwnProperty.call(node.type, '__KONTUR_REACT_UI__') &&\n // @ts-expect-error: React doesn't know about existence of __KONTUR_REACT_UI__.\n node.type.__KONTUR_REACT_UI__ === componentName\n );\n }\n\n return false;\n};\n\nconst KB = 1024;\nconst UNITS = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\nconst calculateDecimals = (decimals: number) => {\n if (decimals < 0) {\n return 0;\n }\n\n return 0;\n};\n\nexport const formatBytes = (bytes: number, decimals = 2): string | null => {\n if (bytes === 0) {\n return '0 Bytes';\n }\n\n if (!bytes) {\n return null;\n }\n\n const calculatedDecimals = calculateDecimals(decimals);\n\n const i = Math.floor(Math.log2(bytes) / Math.log2(KB));\n const formattedBytes = parseFloat((bytes / Math.pow(KB, i)).toFixed(calculatedDecimals));\n\n return `${formattedBytes} ${UNITS[i]}`;\n};\n\n/**\n * Проверяет, не является ли переданный аргумент null или undefined и исключает типы null и undefined из типа аргумента\n *\n * @param value Значение, которое нужно проверить и исключить из него типы\n * @returns Возвращает true, если переданный аргумент не является null или undefined иначе false\n */\nexport const isNonNullable = <T>(value: T): value is NonNullable<T> => {\n return value !== null && value !== undefined;\n};\n\n/**\n * Checks if the value `null` or `undefined`.\n *\n * @param value Value to check for `null` and `undefined`.\n * @returns Returns `true` if `value` is `null` or `undefined`, else `false`.\n */\nexport const isNullable = (value: unknown): value is null | undefined => {\n return value === null || value === undefined;\n};\n\n/**\n * Creates a function that checks if the given `child`\n * is an instance of some component specified by `name`.\n *\n * @param name Component name for which function will be created.\n * @returns A function that checks if the given `child` is an instance of the component specified by `name`.\n */\nexport const isReactUIComponent = <P = any>(name: string) => {\n return (child: React.ReactNode): child is React.ReactElement<P> => {\n // @ts-expect-error: Property `type` doesn't exist on type `React.ReactNode`, but exists on type `React.ReactElement` meanwhile `React.ReactElement` is not compatible with `React` `children` type.\n return child?.type?.__KONTUR_REACT_UI__ === name;\n };\n};\n\n/**\n * Merges two or more refs into one.\n *\n * @param refs Array of refs.\n * @returns A single ref composing all the refs passed.\n *\n * @example\n * const SomeComponent = forwardRef((props, ref) => {\n * const localRef = useRef();\n *\n * return <div ref={mergeRefs([localRef, ref])} />;\n * });\n */\nexport function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (isNonNullable(ref)) {\n return ((ref as React.MutableRefObject<T | null>).current = value);\n }\n });\n };\n}\n\n/**\n * Extracts all data attributes from props and returns them as well as props.\n *\n * @param props Props object to extract data attributes from.\n * @returns Separated data attributes and all other props.\n */\nexport const extractDataProps = <T>(props: T) => {\n const dataProps: Record<string, any> = {};\n const restWithoutDataProps: Record<string, any> = {};\n\n Object.entries(props).map(([name, value]) => {\n if (name.startsWith('data-')) {\n return (dataProps[name] = value);\n }\n\n return (restWithoutDataProps[name] = value);\n });\n\n return { dataProps, restWithoutDataProps };\n};\n\n/**\n * Basically `.startsWith` for arrays.\n *\n * @param searchKeys Array of strings to test against `inputString`.\n * @param inputString String on which search will be performed.\n * @returns `true` if `inputString` starts with one of keys, else `false`.\n */\nexport const startsWithOneOf = (searchKeys: string[], inputString: string) => {\n const keyIndex = searchKeys.findIndex((key) => {\n return inputString.startsWith(key);\n });\n\n return keyIndex >= 0;\n};\n\nexport const isInputLike =\n isReactUIComponent<InputProps>('Input') ||\n isReactUIComponent<FxInputProps>('FxInput') ||\n isReactUIComponent<AutocompleteProps>('Autocomplete') ||\n isReactUIComponent<PasswordInputProps>('PasswordInput') ||\n isReactUIComponent<CurrencyInputProps>('CurrencyInput');\n\nexport const isKonturIcon = (icon: React.ReactElement) => {\n return Object.prototype.hasOwnProperty.call(icon?.type, '__KONTUR_ICON__');\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["utils.ts"],"names":["React","isForwardRef","globalObject","isBrowser","delay","ms","Promise","resolve","setTimeout","emptyHandler","CancelationError","code","Error","taskWithDelay","task","cancelationToken","reject","then","isFunction","x","isFunctionalComponent","Component","Boolean","prototype","isReactComponent","isClassComponent","isIntrinsicElement","element","type","isRefableElement","escapeRegExpSpecChars","s","replace","getRandomID","Math","random","toString","slice","isExternalLink","link","RegExp","location","host","test","isReactUINode","componentName","node","isValidElement","Object","hasOwnProperty","call","__KONTUR_REACT_UI__","KB","UNITS","calculateDecimals","decimals","formatBytes","bytes","calculatedDecimals","i","floor","log2","formattedBytes","parseFloat","pow","toFixed","isNonNullable","value","undefined","isNullable","isReactUIComponent","name","child","mergeRefs","refs","forEach","ref","current","extractDataProps","props","dataProps","restWithoutDataProps","entries","map","startsWith","startsWithOneOf","searchKeys","inputString","keyIndex","findIndex","key","isInputLike","isKonturIcon","icon","getChildrenText","children","Array","isArray","entry","join","nextChild"],"mappings":"gJAAA,OAAO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AAMC,SAAS,GAAIL,QAAJ,oBAAIA,QAAD,CAAkChB,KAAlC,CAAwCgB,QAA1D;AACA,MAAI,CAACK,SAAL,EAAgB;AACd,WAAO,EAAP;AACD;;AAED,SAAON,eAAe,CAACM,SAAD,CAAtB;AACD","sourcesContent":["import React from 'react';\nimport { isForwardRef } from 'react-is';\nimport { globalObject, isBrowser } from '@skbkontur/global-object';\n\nimport { CurrencyInputProps } from '../components/CurrencyInput';\nimport { PasswordInputProps } from '../components/PasswordInput';\nimport { InputProps } from '../components/Input';\nimport { AutocompleteProps } from '../components/Autocomplete';\nimport { FxInputProps } from '../components/FxInput';\n\n// NOTE: Copy-paste from @types/react\nexport type Defaultize<P, D> = P extends any\n ? string extends keyof P\n ? P\n : Pick<P, Exclude<keyof P, keyof D>> &\n Partial<Pick<P, Extract<keyof P, keyof D>>> &\n Partial<Pick<D, Exclude<keyof D, keyof P>>>\n : never;\n\nexport type DefaultizeProps<C, P> = C extends { defaultProps: infer D } ? Defaultize<P, D> : P;\n\nexport type AnyObject = Record<string, unknown>;\n\nexport const delay = (ms: number) => new Promise((resolve) => globalObject.setTimeout(resolve, ms));\n\nexport const emptyHandler = () => {\n /* noop */\n};\n\nexport class CancelationError extends Error {\n public code = 'CancelationError';\n}\n\nexport function taskWithDelay(task: () => void, ms: number) {\n let cancelationToken: () => void = () => null;\n\n new Promise((resolve, reject) => {\n cancelationToken = reject;\n globalObject.setTimeout(resolve, ms);\n })\n .then(task)\n .catch(() => null);\n\n return cancelationToken;\n}\n\nexport type FunctionWithParams<R = any> = (...args: any[]) => R;\nexport function isFunction<T>(x: T | FunctionWithParams): x is FunctionWithParams {\n return typeof x === 'function';\n}\n\nexport function isFunctionalComponent(Component: unknown): Component is React.ComponentType {\n return Boolean(typeof Component === 'function' && !(Component.prototype && Component.prototype.isReactComponent));\n}\n\nexport function isClassComponent(Component: unknown): Component is React.ComponentType {\n return Boolean(typeof Component === 'function' && Component.prototype && Component.prototype.isReactComponent);\n}\n\nexport function isIntrinsicElement(element: React.ReactElement): boolean {\n return typeof element.type === 'string';\n}\n\nexport function isRefableElement(element: React.ReactElement): boolean {\n return Boolean(isIntrinsicElement(element) || isClassComponent(element.type) || isForwardRef(element));\n}\n\nexport function escapeRegExpSpecChars(s: string): string {\n return s.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n\nexport const getRandomID = (): string => Math.random().toString(16).slice(2);\n\nexport const isExternalLink = (link: string): boolean => {\n return isBrowser(globalObject) && new RegExp(`^(https?:)?//(?!${globalObject.location.host})\\\\S+`, 'gi').test(link);\n};\n\n/**\n * Check if the given ReactNode is an element of the specified ReactUI component\n */\nexport const isReactUINode = (componentName: string, node: React.ReactNode): boolean => {\n if (React.isValidElement(node)) {\n return (\n Object.prototype.hasOwnProperty.call(node.type, '__KONTUR_REACT_UI__') &&\n // @ts-expect-error: React doesn't know about existence of __KONTUR_REACT_UI__.\n node.type.__KONTUR_REACT_UI__ === componentName\n );\n }\n\n return false;\n};\n\nconst KB = 1024;\nconst UNITS = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\nconst calculateDecimals = (decimals: number) => {\n if (decimals < 0) {\n return 0;\n }\n\n return 0;\n};\n\nexport const formatBytes = (bytes: number, decimals = 2): string | null => {\n if (bytes === 0) {\n return '0 Bytes';\n }\n\n if (!bytes) {\n return null;\n }\n\n const calculatedDecimals = calculateDecimals(decimals);\n\n const i = Math.floor(Math.log2(bytes) / Math.log2(KB));\n const formattedBytes = parseFloat((bytes / Math.pow(KB, i)).toFixed(calculatedDecimals));\n\n return `${formattedBytes} ${UNITS[i]}`;\n};\n\n/**\n * Проверяет, не является ли переданный аргумент null или undefined и исключает типы null и undefined из типа аргумента\n *\n * @param value Значение, которое нужно проверить и исключить из него типы\n * @returns Возвращает true, если переданный аргумент не является null или undefined иначе false\n */\nexport const isNonNullable = <T>(value: T): value is NonNullable<T> => {\n return value !== null && value !== undefined;\n};\n\n/**\n * Checks if the value `null` or `undefined`.\n *\n * @param value Value to check for `null` and `undefined`.\n * @returns Returns `true` if `value` is `null` or `undefined`, else `false`.\n */\nexport const isNullable = (value: unknown): value is null | undefined => {\n return value === null || value === undefined;\n};\n\n/**\n * Creates a function that checks if the given `child`\n * is an instance of some component specified by `name`.\n *\n * @param name Component name for which function will be created.\n * @returns A function that checks if the given `child` is an instance of the component specified by `name`.\n */\nexport const isReactUIComponent = <P = any>(name: string) => {\n return (child: React.ReactNode): child is React.ReactElement<P> => {\n // @ts-expect-error: Property `type` doesn't exist on type `React.ReactNode`, but exists on type `React.ReactElement` meanwhile `React.ReactElement` is not compatible with `React` `children` type.\n return child?.type?.__KONTUR_REACT_UI__ === name;\n };\n};\n\n/**\n * Merges two or more refs into one.\n *\n * @param refs Array of refs.\n * @returns A single ref composing all the refs passed.\n *\n * @example\n * const SomeComponent = forwardRef((props, ref) => {\n * const localRef = useRef();\n *\n * return <div ref={mergeRefs([localRef, ref])} />;\n * });\n */\nexport function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (isNonNullable(ref)) {\n return ((ref as React.MutableRefObject<T | null>).current = value);\n }\n });\n };\n}\n\n/**\n * Extracts all data attributes from props and returns them as well as props.\n *\n * @param props Props object to extract data attributes from.\n * @returns Separated data attributes and all other props.\n */\nexport const extractDataProps = <T>(props: T) => {\n const dataProps: Record<string, any> = {};\n const restWithoutDataProps: Record<string, any> = {};\n\n Object.entries(props).map(([name, value]) => {\n if (name.startsWith('data-')) {\n return (dataProps[name] = value);\n }\n\n return (restWithoutDataProps[name] = value);\n });\n\n return { dataProps, restWithoutDataProps };\n};\n\n/**\n * Basically `.startsWith` for arrays.\n *\n * @param searchKeys Array of strings to test against `inputString`.\n * @param inputString String on which search will be performed.\n * @returns `true` if `inputString` starts with one of keys, else `false`.\n */\nexport const startsWithOneOf = (searchKeys: string[], inputString: string) => {\n const keyIndex = searchKeys.findIndex((key) => {\n return inputString.startsWith(key);\n });\n\n return keyIndex >= 0;\n};\n\nexport const isInputLike =\n isReactUIComponent<InputProps>('Input') ||\n isReactUIComponent<FxInputProps>('FxInput') ||\n isReactUIComponent<AutocompleteProps>('Autocomplete') ||\n isReactUIComponent<PasswordInputProps>('PasswordInput') ||\n isReactUIComponent<CurrencyInputProps>('CurrencyInput');\n\nexport const isKonturIcon = (icon: React.ReactElement) => {\n return Object.prototype.hasOwnProperty.call(icon?.type, '__KONTUR_ICON__');\n};\n\n/**\n * Allows to get text of all nested children as a string\n *\n * @param children React's children\n * @returns Nested child text or an empty string\n */\nexport function getChildrenText(children: React.ReactNode): string {\n if (typeof children === 'string' || typeof children === 'number') {\n return children.toString();\n }\n\n if (Array.isArray(children)) {\n return children.map((entry) => getChildrenText(entry)).join('');\n }\n\n const nextChild = (children as React.ReactElement)?.props.children;\n if (!nextChild) {\n return '';\n }\n\n return getChildrenText(nextChild);\n}\n"]}
|
package/lib/utils.d.ts
CHANGED
|
@@ -81,3 +81,10 @@ export declare const extractDataProps: <T>(props: T) => {
|
|
|
81
81
|
export declare const startsWithOneOf: (searchKeys: string[], inputString: string) => boolean;
|
|
82
82
|
export declare const isInputLike: (child: React.ReactNode) => child is React.ReactElement<InputProps, string | React.JSXElementConstructor<any>>;
|
|
83
83
|
export declare const isKonturIcon: (icon: React.ReactElement) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Allows to get text of all nested children as a string
|
|
86
|
+
*
|
|
87
|
+
* @param children React's children
|
|
88
|
+
* @returns Nested child text or an empty string
|
|
89
|
+
*/
|
|
90
|
+
export declare function getChildrenText(children: React.ReactNode): string;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skbkontur/react-ui",
|
|
3
|
-
"version": "4.21.0
|
|
3
|
+
"version": "4.21.0",
|
|
4
4
|
"description": "UI Components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
"homepage": "https://tech.skbkontur.ru/react-ui/4.21.0
|
|
8
|
+
"homepage": "https://tech.skbkontur.ru/react-ui/4.21.0/",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git@github.com:skbkontur/retail-ui.git"
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"normalize-wheel": "^1.0.1",
|
|
59
59
|
"prop-types": "^15.8.0",
|
|
60
60
|
"react-focus-lock": "^2.7.1",
|
|
61
|
+
"react-imask": "^7.4.0",
|
|
61
62
|
"react-input-mask": "2.0.4",
|
|
62
63
|
"react-is": "^17.0.2",
|
|
63
64
|
"react-transition-group": "^4.4.2",
|
|
@@ -153,6 +154,6 @@
|
|
|
153
154
|
"react-dom": ">=16.9"
|
|
154
155
|
},
|
|
155
156
|
"publishConfig": {
|
|
156
|
-
"tag": "
|
|
157
|
+
"tag": "latest"
|
|
157
158
|
}
|
|
158
159
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["MaskedInput.tsx"],"names":["MaskedInputDataTids","root","MaskedInput","props","getProps","defaultProps","input","reactInputMask","getValue","value","toString","defaultValue","refInput","refMaskedInput","handleChange","event","target","state","handleUnexpectedInput","setState","originValue","onValueChange","onChange","handleFocus","focused","onFocus","handleBlur","onBlur","preprocess","newState","oldState","userInput","options","visibleMaskChars","Array","mask","length","fill","maskChar","split","forEach","char","index","permanents","includes","emptyValue","join","isMaskVisible","alwaysShowMask","onUnexpectedInput","componentDidMount","forceUpdate","componentDidUpdate","prevProps","render","theme","renderMain","hasLeftIcon","hasRightIcon","maxLength","style","inputProps","leftHelper","textAlign","color","slice","leftClass","styles","inputMaskLeft","rightHelper","map","_char","i","container","inputMask","React","PureComponent","__KONTUR_REACT_UI__"],"mappings":";;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA,mD;;;;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CI,oBAAOC,aAAP,EAAlD,CAEA,IAAMC,WAAW,GAAGxB,UAAU,CAC3BoB,KADiB,CACX7C,WAAW,CAACgB,MADD,EAEjBG,KAFiB,CAEX,EAFW,EAGjB+B,GAHiB,CAGb,UAACC,KAAD,EAAQC,CAAR,UAAeD,KAAK,KAAK,GAAV,gBAAgB,6BAAC,gCAAD,IAAiB,GAAG,EAAEC,CAAtB,GAAhB,GAA8CD,KAA7D,EAHa,CAApB,CAKA,oBACE,uCAAM,YAAUvE,mBAAmB,CAACC,IAApC,EAA0C,SAAS,EAAEkE,oBAAOM,SAAP,EAArD,EAAyE,yBAAsB,MAA/F,iBACE,6BAAC,uBAAD,6BACMZ,UADN,IAEE,QAAQ,EAAE,IAFZ,EAGE,uBAAuB,EAAE,KAAKjC,UAHhC,EAIE,cAAc,EAAE,KAJlB,EAKE,QAAQ,EAAE,KAAKd,YALjB,EAME,OAAO,EAAE,KAAKS,WANhB,EAOE,MAAM,EAAE,KAAKG,UAPf,EAQE,KAAK,EAAEjB,KART,EASE,QAAQ,EAAE,KAAKG,QATjB,EAUE,GAAG,EAAE,KAAKC,cAVZ,EAWE,KAAK,6BAAO+C,KAAP,CAXP,IADF,EAcG,KAAKb,aAAL,mBACC,uCAAM,SAAS,EAAE,iBAAGoB,oBAAOO,SAAP,CAAiB,KAAKnB,KAAtB,CAAH,EAAiCW,SAAjC,CAAjB,IACGJ,UADH,EAEGO,WAFH,CAfJ,CADF,CAuBD,C,sBAlG8BM,eAAMC,a,oCAA1B1E,W,CACG2E,mB,GAAsB,a,CADzB3E,W,CAGGG,Y,GAA6B,EACzCiC,QAAQ,EAAE,GAD+B,E","sourcesContent":["// TODO: Enable this rule in functional components.\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport React from 'react';\nimport ReactInputMask, { InputState, MaskOptions } from 'react-input-mask';\n\nimport { isNonNullable } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { MaskCharLowLine } from '../MaskCharLowLine';\nimport { cx } from '../../lib/theming/Emotion';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { styles } from './MaskedInput.styles';\n\nexport interface MaskedInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n mask: string;\n maskChar?: string | null;\n formatChars?: { [key: string]: string };\n alwaysShowMask?: boolean;\n hasLeftIcon?: boolean;\n hasRightIcon?: boolean;\n onUnexpectedInput?: (value: string) => void;\n onValueChange?: (value: string) => void;\n}\n\ninterface MaskedInputState {\n value: string;\n\n // Users can unmask value themselves. In these cases we take origin value length\n originValue: string;\n\n emptyValue: string;\n focused: boolean;\n}\n\ntype DefaultProps = Required<Pick<MaskedInputProps, 'maskChar'>>;\n\nexport const MaskedInputDataTids = {\n root: 'MaskedInput__root',\n} as const;\n\nexport class MaskedInput extends React.PureComponent<MaskedInputProps, MaskedInputState> {\n public static __KONTUR_REACT_UI__ = 'MaskedInput';\n\n public static defaultProps: DefaultProps = {\n maskChar: '_',\n };\n\n private getProps = createPropsGetter(MaskedInput.defaultProps);\n\n public input: HTMLInputElement | null = null;\n private theme!: Theme;\n private reactInputMask: ReactInputMask | null = null;\n\n public constructor(props: MaskedInputProps) {\n super(props);\n\n this.state = {\n value: this.getValue(props),\n originValue: this.getValue(props),\n emptyValue: '',\n focused: false,\n };\n }\n\n public componentDidMount() {\n if (this.reactInputMask) {\n // FIXME: принудительно вызываем beforeMaskedValueChange, чтобы получить emptyValue\n this.reactInputMask.forceUpdate();\n }\n }\n\n public componentDidUpdate(prevProps: MaskedInputProps) {\n if (this.props.value !== prevProps.value) {\n this.setState({\n value: this.props.value ? this.props.value.toString() : '',\n });\n }\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const {\n maskChar,\n alwaysShowMask,\n hasLeftIcon,\n hasRightIcon,\n maxLength,\n onValueChange,\n onUnexpectedInput,\n defaultValue,\n style,\n ...inputProps\n } = this.props;\n const { emptyValue, value, originValue } = this.state;\n\n const leftHelper = style?.textAlign !== 'right' && (\n <span style={{ color: 'transparent' }}>{emptyValue.slice(0, originValue.length)}</span>\n );\n const leftClass = style?.textAlign !== 'right' && styles.inputMaskLeft();\n\n const rightHelper = emptyValue\n .slice(originValue.length)\n .split('')\n .map((_char, i) => (_char === '_' ? <MaskCharLowLine key={i} /> : _char));\n\n return (\n <span data-tid={MaskedInputDataTids.root} className={styles.container()} x-ms-format-detection=\"none\">\n <ReactInputMask\n {...inputProps}\n maskChar={null}\n beforeMaskedValueChange={this.preprocess}\n alwaysShowMask={false}\n onChange={this.handleChange}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n value={value}\n inputRef={this.refInput}\n ref={this.refMaskedInput}\n style={{ ...style }}\n />\n {this.isMaskVisible() && (\n <span className={cx(styles.inputMask(this.theme), leftClass)}>\n {leftHelper}\n {rightHelper}\n </span>\n )}\n </span>\n );\n }\n\n private getValue = (props: MaskedInputProps): string => {\n if (isNonNullable(props.value)) {\n return props.value.toString();\n }\n\n if (isNonNullable(props.defaultValue)) {\n return props.defaultValue.toString();\n }\n\n return '';\n };\n\n private refInput = (input: HTMLInputElement | null) => {\n this.input = input;\n };\n\n private refMaskedInput = (reactInputMask: ReactInputMask) => {\n this.reactInputMask = reactInputMask;\n };\n\n private handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n if (event.target.value === this.state.value) {\n this.handleUnexpectedInput();\n } else {\n this.setState({ value: event.target.value, originValue: event.target.value });\n if (this.props.onValueChange) {\n this.props.onValueChange(event.target.value);\n }\n if (this.props.onChange) {\n this.props.onChange(event);\n }\n }\n };\n\n private handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {\n this.setState({ focused: true });\n\n if (this.props.onFocus) {\n this.props.onFocus(event);\n }\n };\n\n private handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n this.setState({ focused: false });\n\n if (this.props.onBlur) {\n this.props.onBlur(event);\n }\n };\n\n private preprocess = (\n newState: InputState,\n oldState: InputState,\n userInput: string,\n options: MaskOptions & Pick<MaskedInputProps, 'mask'>,\n ) => {\n const visibleMaskChars = new Array(options.mask.length).fill(this.getProps().maskChar);\n\n if (newState.value !== oldState.value && userInput === null) {\n this.setState({\n value: newState.value,\n originValue: newState.value,\n });\n }\n\n options.mask.split('').forEach((char: string, index: number) => {\n if (options.permanents.includes(index)) {\n visibleMaskChars[index] = char;\n }\n\n if (newState.value[index]) {\n visibleMaskChars[index] = newState.value[index];\n }\n });\n\n const emptyValue = visibleMaskChars.join('');\n\n if (this.state.emptyValue !== emptyValue) {\n this.setState({\n emptyValue,\n });\n }\n\n return newState;\n };\n\n private isMaskVisible = () => this.props.alwaysShowMask || this.state.focused;\n\n private handleUnexpectedInput = () => {\n if (this.props.onUnexpectedInput) {\n this.props.onUnexpectedInput(this.state.value);\n }\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":"uCAAA","sourcesContent":["export * from './MaskedInput';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["MaskedInput.tsx"],"names":["React","ReactInputMask","isNonNullable","ThemeContext","MaskCharLowLine","cx","createPropsGetter","styles","MaskedInputDataTids","root","MaskedInput","props","getProps","defaultProps","input","reactInputMask","getValue","value","toString","defaultValue","refInput","refMaskedInput","handleChange","event","target","state","handleUnexpectedInput","setState","originValue","onValueChange","onChange","handleFocus","focused","onFocus","handleBlur","onBlur","preprocess","newState","oldState","userInput","options","visibleMaskChars","Array","mask","length","fill","maskChar","split","forEach","char","index","permanents","includes","emptyValue","join","isMaskVisible","alwaysShowMask","onUnexpectedInput","componentDidMount","forceUpdate","componentDidUpdate","prevProps","render","theme","renderMain","hasLeftIcon","hasRightIcon","maxLength","style","inputProps","leftHelper","textAlign","color","slice","leftClass","inputMaskLeft","rightHelper","map","_char","i","container","inputMask","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AAtB,CAAD,EAA+BW,SAA/B,CAAnB,IACGJ,UADH,EAEGM,WAFH,CAfJ,CADF,CAuBD,CAlGH,sBAAiC5E,KAAK,CAACkF,aAAvC,EAAaxE,W,CACGyE,mB,GAAsB,a,CADzBzE,W,CAGGG,Y,GAA6B,EACzCiC,QAAQ,EAAE,GAD+B,E","sourcesContent":["// TODO: Enable this rule in functional components.\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport React from 'react';\nimport ReactInputMask, { InputState, MaskOptions } from 'react-input-mask';\n\nimport { isNonNullable } from '../../lib/utils';\nimport { ThemeContext } from '../../lib/theming/ThemeContext';\nimport { Theme } from '../../lib/theming/Theme';\nimport { MaskCharLowLine } from '../MaskCharLowLine';\nimport { cx } from '../../lib/theming/Emotion';\nimport { createPropsGetter } from '../../lib/createPropsGetter';\n\nimport { styles } from './MaskedInput.styles';\n\nexport interface MaskedInputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n mask: string;\n maskChar?: string | null;\n formatChars?: { [key: string]: string };\n alwaysShowMask?: boolean;\n hasLeftIcon?: boolean;\n hasRightIcon?: boolean;\n onUnexpectedInput?: (value: string) => void;\n onValueChange?: (value: string) => void;\n}\n\ninterface MaskedInputState {\n value: string;\n\n // Users can unmask value themselves. In these cases we take origin value length\n originValue: string;\n\n emptyValue: string;\n focused: boolean;\n}\n\ntype DefaultProps = Required<Pick<MaskedInputProps, 'maskChar'>>;\n\nexport const MaskedInputDataTids = {\n root: 'MaskedInput__root',\n} as const;\n\nexport class MaskedInput extends React.PureComponent<MaskedInputProps, MaskedInputState> {\n public static __KONTUR_REACT_UI__ = 'MaskedInput';\n\n public static defaultProps: DefaultProps = {\n maskChar: '_',\n };\n\n private getProps = createPropsGetter(MaskedInput.defaultProps);\n\n public input: HTMLInputElement | null = null;\n private theme!: Theme;\n private reactInputMask: ReactInputMask | null = null;\n\n public constructor(props: MaskedInputProps) {\n super(props);\n\n this.state = {\n value: this.getValue(props),\n originValue: this.getValue(props),\n emptyValue: '',\n focused: false,\n };\n }\n\n public componentDidMount() {\n if (this.reactInputMask) {\n // FIXME: принудительно вызываем beforeMaskedValueChange, чтобы получить emptyValue\n this.reactInputMask.forceUpdate();\n }\n }\n\n public componentDidUpdate(prevProps: MaskedInputProps) {\n if (this.props.value !== prevProps.value) {\n this.setState({\n value: this.props.value ? this.props.value.toString() : '',\n });\n }\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderMain();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const {\n maskChar,\n alwaysShowMask,\n hasLeftIcon,\n hasRightIcon,\n maxLength,\n onValueChange,\n onUnexpectedInput,\n defaultValue,\n style,\n ...inputProps\n } = this.props;\n const { emptyValue, value, originValue } = this.state;\n\n const leftHelper = style?.textAlign !== 'right' && (\n <span style={{ color: 'transparent' }}>{emptyValue.slice(0, originValue.length)}</span>\n );\n const leftClass = style?.textAlign !== 'right' && styles.inputMaskLeft();\n\n const rightHelper = emptyValue\n .slice(originValue.length)\n .split('')\n .map((_char, i) => (_char === '_' ? <MaskCharLowLine key={i} /> : _char));\n\n return (\n <span data-tid={MaskedInputDataTids.root} className={styles.container()} x-ms-format-detection=\"none\">\n <ReactInputMask\n {...inputProps}\n maskChar={null}\n beforeMaskedValueChange={this.preprocess}\n alwaysShowMask={false}\n onChange={this.handleChange}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n value={value}\n inputRef={this.refInput}\n ref={this.refMaskedInput}\n style={{ ...style }}\n />\n {this.isMaskVisible() && (\n <span className={cx(styles.inputMask(this.theme), leftClass)}>\n {leftHelper}\n {rightHelper}\n </span>\n )}\n </span>\n );\n }\n\n private getValue = (props: MaskedInputProps): string => {\n if (isNonNullable(props.value)) {\n return props.value.toString();\n }\n\n if (isNonNullable(props.defaultValue)) {\n return props.defaultValue.toString();\n }\n\n return '';\n };\n\n private refInput = (input: HTMLInputElement | null) => {\n this.input = input;\n };\n\n private refMaskedInput = (reactInputMask: ReactInputMask) => {\n this.reactInputMask = reactInputMask;\n };\n\n private handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n if (event.target.value === this.state.value) {\n this.handleUnexpectedInput();\n } else {\n this.setState({ value: event.target.value, originValue: event.target.value });\n if (this.props.onValueChange) {\n this.props.onValueChange(event.target.value);\n }\n if (this.props.onChange) {\n this.props.onChange(event);\n }\n }\n };\n\n private handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {\n this.setState({ focused: true });\n\n if (this.props.onFocus) {\n this.props.onFocus(event);\n }\n };\n\n private handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n this.setState({ focused: false });\n\n if (this.props.onBlur) {\n this.props.onBlur(event);\n }\n };\n\n private preprocess = (\n newState: InputState,\n oldState: InputState,\n userInput: string,\n options: MaskOptions & Pick<MaskedInputProps, 'mask'>,\n ) => {\n const visibleMaskChars = new Array(options.mask.length).fill(this.getProps().maskChar);\n\n if (newState.value !== oldState.value && userInput === null) {\n this.setState({\n value: newState.value,\n originValue: newState.value,\n });\n }\n\n options.mask.split('').forEach((char: string, index: number) => {\n if (options.permanents.includes(index)) {\n visibleMaskChars[index] = char;\n }\n\n if (newState.value[index]) {\n visibleMaskChars[index] = newState.value[index];\n }\n });\n\n const emptyValue = visibleMaskChars.join('');\n\n if (this.state.emptyValue !== emptyValue) {\n this.setState({\n emptyValue,\n });\n }\n\n return newState;\n };\n\n private isMaskVisible = () => this.props.alwaysShowMask || this.state.focused;\n\n private handleUnexpectedInput = () => {\n if (this.props.onUnexpectedInput) {\n this.props.onUnexpectedInput(this.state.value);\n }\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["MaskedInput.styles.ts"],"names":["css","memoizeStyle","styles","container","inputMask","t","placeholderColor","inputMaskLeft"],"mappings":"wJAAA,SAASA,GAAT,EAAcC,YAAd,QAAkC,2BAAlC;;;AAGA,OAAO,IAAMC,MAAM,GAAGD,YAAY,CAAC;AACjCE,EAAAA,SADiC,uBACrB;AACV,WAAOH,GAAP;;;;;;AAMD,GARgC;AASjCI,EAAAA,SATiC,qBASvBC,CATuB,EASb;AAClB,WAAOL,GAAP;AACWK,IAAAA,CAAC,CAACC,gBADb;;;;;;AAOD,GAjBgC;AAkBjCC,EAAAA,aAlBiC,2BAkBjB;AACd,WAAOP,GAAP;;;;;;AAMD,GAzBgC,EAAD,CAA3B","sourcesContent":["import { css, memoizeStyle } from '../../lib/theming/Emotion';\nimport { Theme } from '../../lib/theming/Theme';\n\nexport const styles = memoizeStyle({\n container() {\n return css`\n display: inline-flex;\n position: relative;\n font-size: inherit;\n flex: 100% 1 1;\n `;\n },\n inputMask(t: Theme) {\n return css`\n color: ${t.placeholderColor};\n pointer-events: none;\n font-size: inherit;\n z-index: 5;\n user-select: none;\n `;\n },\n inputMaskLeft() {\n return css`\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n `;\n },\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAd","sourcesContent":["export * from './MaskedInput';\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|