@alfalab/core-components-masked-input 4.2.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/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Component = require('./Component.js');
6
+ require('react');
7
+ require('classnames');
8
+ require('react-merge-refs');
9
+ require('text-mask-core');
10
+ require('@alfalab/core-components-input');
11
+
12
+
13
+
14
+ exports.MaskedInput = Component.MaskedInput;
15
+ exports.PLACEHOLDER_CHAR = Component.PLACEHOLDER_CHAR;
@@ -0,0 +1,86 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { InputProps } from "@alfalab/core-components-input";
4
+ type Mask = Array<string | RegExp>;
5
+ type TextMaskConfig = {
6
+ currentCaretPosition: number;
7
+ rawValue: string;
8
+ previousConformedValue: string;
9
+ mask?: Mask | ((rawValue: string) => Mask);
10
+ guide?: boolean;
11
+ showMask?: boolean;
12
+ placeholderChar?: string;
13
+ keepCharPositions?: boolean;
14
+ pipe?: (conformedValue: string, config: TextMaskConfig) => false | string | {
15
+ value: string;
16
+ indexesOfPipedChars: number[];
17
+ };
18
+ };
19
+ type MaskedInputProps = InputProps & {
20
+ /**
21
+ * Маска для поля ввода
22
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
23
+ */
24
+ mask?: TextMaskConfig['mask'];
25
+ /**
26
+ * Управляет поведением компонента при удалении символов
27
+ */
28
+ keepCharPositions?: TextMaskConfig['keepCharPositions'];
29
+ /**
30
+ * Дает возможность изменить значение поля перед рендером
31
+ */
32
+ onBeforeDisplay?: TextMaskConfig['pipe'];
33
+ };
34
+ declare const PLACEHOLDER_CHAR = "\u2000";
35
+ declare const MaskedInput: React.ForwardRefExoticComponent<Pick<React.InputHTMLAttributes<HTMLInputElement>, "className" | "form" | "slot" | "style" | "title" | "pattern" | "children" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width"> & {
36
+ value?: string | undefined;
37
+ defaultValue?: string | undefined;
38
+ block?: boolean | undefined;
39
+ clear?: boolean | undefined; /**
40
+ * Управляет поведением компонента при удалении символов
41
+ */
42
+ size?: "s" | "m" | "l" | "xl" | undefined;
43
+ colors?: "default" | "inverted" | undefined;
44
+ error?: React.ReactNode;
45
+ success?: boolean | undefined;
46
+ hint?: React.ReactNode;
47
+ label?: React.ReactNode;
48
+ type?: "number" | "text" | "tel" | "email" | "card" | "money" | "password" | undefined;
49
+ wrapperRef?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
50
+ leftAddons?: React.ReactNode;
51
+ rightAddons?: React.ReactNode;
52
+ bottomAddons?: React.ReactNode;
53
+ className?: string | undefined;
54
+ fieldClassName?: string | undefined;
55
+ inputClassName?: string | undefined;
56
+ labelClassName?: string | undefined;
57
+ addonsClassName?: string | undefined;
58
+ focusedClassName?: string | undefined;
59
+ filledClassName?: string | undefined;
60
+ onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
61
+ value: string;
62
+ }) => void) | undefined;
63
+ onClear?: ((event: React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>) => void) | undefined;
64
+ onClick?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
65
+ onMouseDown?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
66
+ onMouseUp?: ((event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => void) | undefined;
67
+ dataTestId?: string | undefined;
68
+ } & {
69
+ /**
70
+ * Маска для поля ввода
71
+ * https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#mask-array
72
+ */
73
+ mask?: Mask | ((rawValue: string) => Mask) | undefined;
74
+ /**
75
+ * Управляет поведением компонента при удалении символов
76
+ */
77
+ keepCharPositions?: boolean | undefined;
78
+ /**
79
+ * Дает возможность изменить значение поля перед рендером
80
+ */
81
+ onBeforeDisplay?: ((conformedValue: string, config: TextMaskConfig) => string | false | {
82
+ value: string;
83
+ indexesOfPipedChars: number[];
84
+ }) | undefined;
85
+ } & React.RefAttributes<HTMLInputElement>>;
86
+ export { MaskedInputProps, PLACEHOLDER_CHAR, MaskedInput };
@@ -0,0 +1,67 @@
1
+ import React, { useRef, useState, useCallback, useEffect } from 'react';
2
+ import cn from 'classnames';
3
+ import mergeRefs from 'react-merge-refs';
4
+ import { createTextMaskInputElement } from 'text-mask-core';
5
+ import { Input } from '@alfalab/core-components-input/dist/modern';
6
+
7
+ var styles = {"textHidden":"masked-input__textHidden_2no40"};
8
+ require('./index.css')
9
+
10
+ // Символ плейсхолдера не может входить в маску, поэтому вместо пробела используется \u2000
11
+ const PLACEHOLDER_CHAR = '\u2000';
12
+ const MaskedInput = React.forwardRef(({ mask, keepCharPositions = false, value, defaultValue, className, onBeforeDisplay, onChange, onClear, ...restProps }, ref) => {
13
+ const inputRef = useRef(null);
14
+ const textMask = useRef(null);
15
+ const [inputValue, setInputValue] = useState(value || defaultValue || '');
16
+ // Не показываем сырое значение до применения маски
17
+ const [textHidden, setTextHidden] = useState(true);
18
+ const update = useCallback((newValue = '') => {
19
+ if (textMask.current && inputRef.current) {
20
+ try {
21
+ textMask.current.update(newValue);
22
+ }
23
+ catch (e) {
24
+ // ignore masking errors
25
+ }
26
+ setInputValue(inputRef.current.value);
27
+ }
28
+ }, []);
29
+ const handleInputChange = useCallback((event) => {
30
+ update(event.target.value);
31
+ if (onChange) {
32
+ onChange(event, {
33
+ value: event.target.value,
34
+ });
35
+ }
36
+ }, [onChange, update]);
37
+ const handleClear = useCallback((event) => {
38
+ update('');
39
+ if (onClear)
40
+ onClear(event);
41
+ }, [onClear, update]);
42
+ useEffect(() => {
43
+ if (inputRef.current) {
44
+ textMask.current = createTextMaskInputElement({
45
+ mask,
46
+ inputElement: inputRef.current,
47
+ pipe: onBeforeDisplay,
48
+ guide: false,
49
+ keepCharPositions,
50
+ showMask: false,
51
+ placeholderChar: PLACEHOLDER_CHAR,
52
+ rawValue: '',
53
+ currentCaretPosition: 0,
54
+ previousConformedValue: '',
55
+ });
56
+ }
57
+ }, [onBeforeDisplay, mask, keepCharPositions]);
58
+ useEffect(() => {
59
+ update(value || defaultValue);
60
+ }, [value, update, defaultValue]);
61
+ useEffect(() => {
62
+ setTextHidden(false);
63
+ }, []);
64
+ return (React.createElement(Input, Object.assign({}, restProps, { className: cn(className, { [styles.textHidden]: textHidden }), value: inputValue, onChange: handleInputChange, onClear: handleClear, ref: mergeRefs([ref, inputRef]) })));
65
+ });
66
+
67
+ export { MaskedInput, PLACEHOLDER_CHAR };
@@ -0,0 +1 @@
1
+ /* hash: 2no40 */
@@ -0,0 +1 @@
1
+ export * from "./Component";
@@ -0,0 +1,6 @@
1
+ import 'react';
2
+ import 'classnames';
3
+ import 'react-merge-refs';
4
+ import 'text-mask-core';
5
+ import '@alfalab/core-components-input/dist/modern';
6
+ export { MaskedInput, PLACEHOLDER_CHAR } from './Component.js';
@@ -0,0 +1,82 @@
1
+ const http = require('http');
2
+ const fs = require('fs');
3
+ const { promisify } = require('util');
4
+ const path = require('path');
5
+
6
+ const readFile = promisify(fs.readFile);
7
+
8
+ async function main() {
9
+ const remoteHost = process.env.NIS_HOST || 'digital';
10
+ const remotePort = process.env.NIS_PORT || 80;
11
+ const remotePath = process.env.NIS_PATH || '/npm-install-stats/api/install-stats';
12
+
13
+ try {
14
+ const [_, node, os, arch] =
15
+ /node\/v(\d+\.\d+\.\d+) (\w+) (\w+)/.exec(process.env.npm_config_user_agent) || [];
16
+ const [__, npm] = /npm\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
17
+ const [___, yarn] = /yarn\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
18
+
19
+ let ownPackageJson, packageJson;
20
+
21
+ try {
22
+ const result = await Promise.all([
23
+ readFile(path.join(process.cwd(), 'package.json'), 'utf-8'),
24
+ readFile(path.join(process.cwd(), '../../../package.json'), 'utf-8'),
25
+ ]);
26
+
27
+ ownPackageJson = JSON.parse(result[0]);
28
+ packageJson = JSON.parse(result[1]);
29
+ } catch (err) {
30
+ ownPackageJson = '';
31
+ packageJson = '';
32
+ }
33
+
34
+ const data = {
35
+ node,
36
+ npm,
37
+ yarn,
38
+ os,
39
+ arch,
40
+ ownPackageJson: JSON.stringify(ownPackageJson),
41
+ packageJson: JSON.stringify(packageJson),
42
+ };
43
+
44
+ const body = JSON.stringify(data);
45
+
46
+ const options = {
47
+ host: remoteHost,
48
+ port: remotePort,
49
+ path: remotePath,
50
+ method: 'POST',
51
+ headers: {
52
+ 'Content-Type': 'application/json',
53
+ 'Content-Length': body.length,
54
+ },
55
+ };
56
+
57
+ return new Promise((resolve, reject) => {
58
+ const req = http.request(options, res => {
59
+ res.on('end', () => {
60
+ resolve();
61
+ });
62
+ });
63
+
64
+ req.on('error', () => {
65
+ reject();
66
+ });
67
+
68
+ req.write(body);
69
+ req.end();
70
+ });
71
+ } catch (error) {
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ main()
77
+ .then(() => {
78
+ process.exit(0);
79
+ })
80
+ .catch(() => {
81
+ process.exit(0);
82
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@alfalab/core-components-masked-input",
3
+ "version": "4.2.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "postinstall": "node ./dist/send-stats.js > /dev/null 2>&1 || exit 0"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "peerDependencies": {
19
+ "react": "^16.9.0 || ^17.0.1"
20
+ },
21
+ "dependencies": {
22
+ "@alfalab/core-components-input": "^7.3.0",
23
+ "classnames": "^2.2.6",
24
+ "react-merge-refs": "^1.1.0",
25
+ "text-mask-core": "^5.1.2"
26
+ },
27
+ "gitHead": "a80a4377703da0cb8fd257612117ef3eb2d9bc42"
28
+ }