@skbkontur/react-ui 5.0.11-ZIndex-several-roots.2 → 5.0.12

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 CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.0.12](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@5.0.11...@skbkontur/react-ui@5.0.12) (2025-03-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **Loader,ZIndex:** fix overlap of dropdowns in widgets ([#3612](https://github.com/skbkontur/retail-ui/issues/3612)) ([7990c6d](https://github.com/skbkontur/retail-ui/commit/7990c6d4b661e49e5fec8707f4f06a9655bce25e))
12
+ * **MaskedInput:** rerender after theme change ([#3614](https://github.com/skbkontur/retail-ui/issues/3614)) ([840443f](https://github.com/skbkontur/retail-ui/commit/840443fff46bc6037b92e3da6151312075c25fc7))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [5.0.11](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@5.0.10...@skbkontur/react-ui@5.0.11) (2025-03-03)
7
19
 
8
20
 
@@ -1,4 +1,5 @@
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"));
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"));
2
+ var _react = _interopRequireWildcard(require("react"));
2
3
  var _globalObject = require("@skbkontur/global-object");
3
4
  var _lodash = _interopRequireDefault(require("lodash.debounce"));
4
5
 
@@ -7,8 +8,7 @@ var _ThemeContext = require("../../../lib/theming/ThemeContext");
7
8
  var _forwardRefAndName = require("../../../lib/forwardRefAndName");
8
9
  var _Emotion = require("../../../lib/theming/Emotion");
9
10
 
10
-
11
- var _ColorableInputElement = require("./ColorableInputElement.styles");var _excluded = ["children", "onInput", "onFocus", "onBlur", "showOnFocus"];
11
+ var _ColorableInputElement = require("./ColorableInputElement.styles");var _excluded = ["children", "onInput", "onFocus", "onBlur", "showOnFocus"]; /* eslint react-hooks/exhaustive-deps: 2 */
12
12
 
13
13
 
14
14
 
@@ -28,7 +28,6 @@ var ColorableInputElement = exports.ColorableInputElement = (0, _forwardRefAndNa
28
28
  var focused = (0, _react.useRef)(false);
29
29
  var inputStyle = _react.default.useRef();
30
30
  var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
31
- var debouncedPaintText = (0, _react.useCallback)((0, _lodash.default)(paintText), []);
32
31
  var _useState = (0, _react.useState)(true),active = _useState[0],setActive = _useState[1];
33
32
 
34
33
  var children = props.children,onInput = props.onInput,onFocus = props.onFocus,onBlur = props.onBlur,showOnFocus = props.showOnFocus,inputProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
@@ -44,10 +43,78 @@ var ColorableInputElement = exports.ColorableInputElement = (0, _forwardRefAndNa
44
43
 
45
44
  (0, _react.useEffect)(updateActive, []);
46
45
 
46
+ var paintText = (0, _react.useCallback)(function () {var _inputRef$current, _shadow;
47
+ if (!spanRef.current || !inputRef.current || !inputStyle.current || !(0, _globalObject.isBrowser)(_globalObject.globalObject)) {
48
+ return;
49
+ }
50
+
51
+ (_inputRef$current = inputRef.current) == null || _inputRef$current.classList.add(_ColorableInputElement.globalClasses.input);
52
+
53
+ var shadow = spanRef.current.shadowRoot;
54
+ var typedValueElement = (_shadow = shadow) == null ? void 0 : _shadow.getElementById('span');
55
+
56
+ if (!typedValueElement) {
57
+ shadow = spanRef.current.attachShadow({ mode: 'open' });
58
+
59
+ typedValueElement = _globalObject.globalObject.document.createElement('span');
60
+ typedValueElement.setAttribute('id', 'span');
61
+
62
+ shadow.appendChild(typedValueElement);
63
+ }
64
+
65
+ var style = inputStyle.current;
66
+
67
+ typedValueElement.textContent =
68
+ (inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&
69
+ inputRef.current.getAttribute('data-typed-value') ||
70
+ '';
71
+
72
+ var inputRect = inputRef.current.getBoundingClientRect();
73
+ var filledRect = spanRef.current.getBoundingClientRect();
74
+
75
+ var threshold = filledRect.width / (inputRect.width / 100);
76
+ var degree = style.fontStyle === 'italic' ? 100 : 90;
77
+
78
+ var typedValueColor = theme.inputTextColor;
79
+ var maskColor = theme.inputPlaceholderColor;
80
+ if (props.disabled) {
81
+ typedValueColor = theme.inputTextColorDisabled;
82
+ maskColor = theme.inputTextColorDisabled;
83
+ }
84
+ if (props.showOnFocus) {
85
+ maskColor = focused.current ? maskColor : 'transparent';
86
+ }
87
+
88
+ inputRef.current.style.backgroundImage = "\n linear-gradient(\n " +
89
+
90
+ degree + "deg,\n " +
91
+ typedValueColor + " " + threshold + "%,\n " +
92
+ maskColor + " " + threshold + "%\n )";
93
+
94
+ }, [
95
+ props.showOnFocus,
96
+ props.disabled,
97
+ theme.inputTextColor,
98
+ theme.inputPlaceholderColor,
99
+ theme.inputTextColorDisabled]
100
+ );
101
+
102
+ var debouncedPaintText = (0, _react.useCallback)(function () {return (0, _lodash.default)(paintText);}, [paintText])();
103
+
104
+ var activation = (0, _react.useCallback)(function () {
105
+ if (active) {
106
+ debouncedPaintText();
107
+ } else {var _inputRef$current2;
108
+ debouncedPaintText.cancel();
109
+ inputRef.current && (inputRef.current.style.backgroundImage = '');
110
+ (_inputRef$current2 = inputRef.current) == null || _inputRef$current2.classList.remove(_ColorableInputElement.globalClasses.input);
111
+ }
112
+ }, [debouncedPaintText, active]);
113
+
47
114
  (0, _react.useEffect)(function () {
48
- activation(props, theme);
115
+ activation();
49
116
  updateActive();
50
- }, [active, showOnFocus, props.value, props.defaultValue, props.disabled, focused.current, theme]);
117
+ }, [props.value, props.defaultValue, theme, activation]);
51
118
 
52
119
  (0, _react.useEffect)(function () {
53
120
  if (inputRef.current) {
@@ -69,11 +136,11 @@ var ColorableInputElement = exports.ColorableInputElement = (0, _forwardRefAndNa
69
136
  ));
70
137
 
71
138
 
72
- function handleInput(e) {var _inputRef$current;
73
- var isActive = !((_inputRef$current = inputRef.current) != null && (_inputRef$current = _inputRef$current.parentElement) != null && _inputRef$current.querySelector(':placeholder-shown'));
139
+ function handleInput(e) {var _inputRef$current3;
140
+ var isActive = !((_inputRef$current3 = inputRef.current) != null && (_inputRef$current3 = _inputRef$current3.parentElement) != null && _inputRef$current3.querySelector(':placeholder-shown'));
74
141
  setActive(isActive);
75
142
 
76
- activation(props, theme);
143
+ activation();
77
144
 
78
145
  onInput == null || onInput(e);
79
146
  }
@@ -95,69 +162,9 @@ var ColorableInputElement = exports.ColorableInputElement = (0, _forwardRefAndNa
95
162
  }
96
163
 
97
164
  function updateActive() {
98
- setTimeout(function () {var _inputRef$current2;
99
- setActive(!((_inputRef$current2 = inputRef.current) != null && (_inputRef$current2 = _inputRef$current2.parentElement) != null && _inputRef$current2.querySelector(':placeholder-shown')));
165
+ setTimeout(function () {var _inputRef$current4;
166
+ setActive(!((_inputRef$current4 = inputRef.current) != null && (_inputRef$current4 = _inputRef$current4.parentElement) != null && _inputRef$current4.querySelector(':placeholder-shown')));
100
167
  });
101
168
  }
102
-
103
- function activation(props, theme) {
104
- if (active) {
105
- debouncedPaintText(props, theme);
106
- } else {var _inputRef$current3;
107
- debouncedPaintText.cancel();
108
- inputRef.current && (inputRef.current.style.backgroundImage = '');
109
- (_inputRef$current3 = inputRef.current) == null || _inputRef$current3.classList.remove(_ColorableInputElement.globalClasses.input);
110
- }
111
- }
112
-
113
- function paintText(_props, _theme) {var _inputRef$current4, _shadow;if (_props === void 0) {_props = props;}if (_theme === void 0) {_theme = theme;}
114
- if (!spanRef.current || !inputRef.current || !inputStyle.current || !(0, _globalObject.isBrowser)(_globalObject.globalObject)) {
115
- return;
116
- }
117
-
118
- (_inputRef$current4 = inputRef.current) == null || _inputRef$current4.classList.add(_ColorableInputElement.globalClasses.input);
119
-
120
- var shadow = spanRef.current.shadowRoot;
121
- var typedValueElement = (_shadow = shadow) == null ? void 0 : _shadow.getElementById('span');
122
-
123
- if (!typedValueElement) {
124
- shadow = spanRef.current.attachShadow({ mode: 'open' });
125
-
126
- typedValueElement = _globalObject.globalObject.document.createElement('span');
127
- typedValueElement.setAttribute('id', 'span');
128
-
129
- shadow.appendChild(typedValueElement);
130
- }
131
-
132
- var style = inputStyle.current;
133
-
134
- typedValueElement.textContent =
135
- (inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&
136
- inputRef.current.getAttribute('data-typed-value') ||
137
- '';
138
-
139
- var inputRect = inputRef.current.getBoundingClientRect();
140
- var filledRect = spanRef.current.getBoundingClientRect();
141
-
142
- var threshold = filledRect.width / (inputRect.width / 100);
143
- var degree = style.fontStyle === 'italic' ? 100 : 90;
144
-
145
- var typedValueColor = _theme.inputTextColor;
146
- var maskColor = _theme.inputPlaceholderColor;
147
- if (_props.disabled) {
148
- typedValueColor = _theme.inputTextColorDisabled;
149
- maskColor = _theme.inputTextColorDisabled;
150
- }
151
- if (_props.showOnFocus) {
152
- maskColor = focused.current ? maskColor : 'transparent';
153
- }
154
-
155
- inputRef.current.style.backgroundImage = "\n linear-gradient(\n " +
156
-
157
- degree + "deg,\n " +
158
- typedValueColor + " " + threshold + "%,\n " +
159
- maskColor + " " + threshold + "%\n )";
160
-
161
- }
162
169
  }
163
170
  );
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_globalObject","_lodash","_interopRequireDefault","_ThemeContext","_forwardRefAndName","_Emotion","_ColorableInputElement","_excluded","ColorableInputElement","exports","forwardRefAndName","props","ref","inputRef","useRef","spanRef","focused","inputStyle","React","theme","useContext","ThemeContext","debouncedPaintText","useCallback","debounce","paintText","_useState","useState","active","setActive","children","onInput","onFocus","onBlur","showOnFocus","inputProps","_objectWithoutPropertiesLoose2","default","useImperativeHandle","input","current","getRootNode","useEffect","updateActive","activation","value","defaultValue","disabled","getComputedStyle","createElement","Fragment","cloneElement","_extends2","handleInput","handleFocus","handleBlur","className","cx","globalClasses","style","visibility","position","whiteSpace","e","_inputRef$current","isActive","parentElement","querySelector","setTimeout","_inputRef$current2","_inputRef$current3","cancel","backgroundImage","classList","remove","_props","_theme","_inputRef$current4","_shadow","isBrowser","globalObject","add","shadow","shadowRoot","typedValueElement","getElementById","attachShadow","mode","document","setAttribute","appendChild","textContent","getAttribute","inputRect","getBoundingClientRect","filledRect","threshold","width","degree","fontStyle","typedValueColor","inputTextColor","maskColor","inputPlaceholderColor","inputTextColorDisabled"],"sources":["ColorableInputElement.tsx"],"sourcesContent":["import React, { ForwardedRef, useContext, useEffect, useImperativeHandle, useRef, useCallback, useState } 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';\nimport { Theme } from '../../../lib/theming/Theme';\n\nimport { globalClasses } from './ColorableInputElement.styles';\n\nexport type ColorableInputElementProps = InputElementProps & {\n showOnFocus?: boolean;\n children: React.ReactElement;\n};\n\n// Возможно придётся включить.\n// Иногда, на тяжёлых страницах, текст рендерится итеративно.\n// Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.\n// setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 1000);\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 const debouncedPaintText = useCallback(debounce(paintText), []);\n const [active, setActive] = useState(true);\n\n const { children, onInput, onFocus, onBlur, showOnFocus, ...inputProps } = props;\n\n useImperativeHandle(\n ref,\n () => ({\n input: inputRef.current,\n getRootNode: () => inputRef.current,\n }),\n [],\n );\n\n useEffect(updateActive, []);\n\n useEffect(() => {\n activation(props, theme);\n updateActive();\n }, [active, showOnFocus, props.value, props.defaultValue, props.disabled, focused.current, theme]);\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 && globalClasses.input),\n })}\n {active && <span style={{ visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }} ref={spanRef} />}\n </>\n );\n\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n const isActive = !inputRef.current?.parentElement?.querySelector(':placeholder-shown');\n setActive(isActive);\n\n activation(props, theme);\n\n onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setTimeout(updateActive);\n\n focused.current = true;\n\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n updateActive();\n\n focused.current = false;\n\n onBlur?.(e);\n }\n\n function updateActive() {\n setTimeout(() => {\n setActive(!inputRef.current?.parentElement?.querySelector(':placeholder-shown'));\n });\n }\n\n function activation(props: ColorableInputElementProps, theme: Theme) {\n if (active) {\n debouncedPaintText(props, theme);\n } else {\n debouncedPaintText.cancel();\n inputRef.current && (inputRef.current.style.backgroundImage = '');\n inputRef.current?.classList.remove(globalClasses.input);\n }\n }\n\n function paintText(_props: Partial<ColorableInputElementProps> = props, _theme: Theme = theme) {\n if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {\n return;\n }\n\n inputRef.current?.classList.add(globalClasses.input);\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 =\n ((inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&\n inputRef.current.getAttribute('data-typed-value')) ||\n '';\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 (_props.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"],"mappings":"wdAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;;AAEA,IAAAI,aAAA,GAAAJ,OAAA;;AAEA,IAAAK,kBAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;;;AAGA,IAAAO,sBAAA,GAAAP,OAAA,mCAA+D,IAAAQ,SAAA;;;;;;;AAO/D;AACA;AACA;AACA;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AQ,CAAC2B,OAAO,CAACsD,qBAAqB,CAAC,CAAC;MAC1D,IAAMC,UAAU,GAAGhF,OAAO,CAACyB,OAAO,CAACsD,qBAAqB,CAAC,CAAC;;MAE1D,IAAME,SAAS,GAAGD,UAAU,CAACE,KAAK,IAAIJ,SAAS,CAACI,KAAK,GAAG,GAAG,CAAC;MAC5D,IAAMC,MAAM,GAAGvC,KAAK,CAACwC,SAAS,KAAK,QAAQ,GAAG,GAAG,GAAG,EAAE;;MAEtD,IAAIC,eAAe,GAAGxB,MAAM,CAACyB,cAAc;MAC3C,IAAIC,SAAS,GAAG1B,MAAM,CAAC2B,qBAAqB;MAC5C,IAAI5B,MAAM,CAAC5B,QAAQ,EAAE;QACnBqD,eAAe,GAAGxB,MAAM,CAAC4B,sBAAsB;QAC/CF,SAAS,GAAG1B,MAAM,CAAC4B,sBAAsB;MAC3C;MACA,IAAI7B,MAAM,CAACzC,WAAW,EAAE;QACtBoE,SAAS,GAAGtF,OAAO,CAACwB,OAAO,GAAG8D,SAAS,GAAG,aAAa;MACzD;;MAEAzF,QAAQ,CAAC2B,OAAO,CAACmB,KAAK,CAACa,eAAe;;MAEhC0B,MAAM;MACNE,eAAe,SAAIJ,SAAS;MAC5BM,SAAS,SAAIN,SAAS,eAC1B;;IACJ;EACF;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_globalObject","_lodash","_interopRequireDefault","_ThemeContext","_forwardRefAndName","_Emotion","_ColorableInputElement","_excluded","ColorableInputElement","exports","forwardRefAndName","props","ref","inputRef","useRef","spanRef","focused","inputStyle","React","theme","useContext","ThemeContext","_useState","useState","active","setActive","children","onInput","onFocus","onBlur","showOnFocus","inputProps","_objectWithoutPropertiesLoose2","default","useImperativeHandle","input","current","getRootNode","useEffect","updateActive","paintText","useCallback","_inputRef$current","_shadow","isBrowser","globalObject","classList","add","globalClasses","shadow","shadowRoot","typedValueElement","getElementById","attachShadow","mode","document","createElement","setAttribute","appendChild","style","textContent","getAttribute","inputRect","getBoundingClientRect","filledRect","threshold","width","degree","fontStyle","typedValueColor","inputTextColor","maskColor","inputPlaceholderColor","disabled","inputTextColorDisabled","backgroundImage","debouncedPaintText","debounce","activation","_inputRef$current2","cancel","remove","value","defaultValue","getComputedStyle","Fragment","cloneElement","_extends2","handleInput","handleFocus","handleBlur","className","cx","visibility","position","whiteSpace","e","_inputRef$current3","isActive","parentElement","querySelector","setTimeout","_inputRef$current4"],"sources":["ColorableInputElement.tsx"],"sourcesContent":["/* eslint react-hooks/exhaustive-deps: 2 */\nimport React, { ForwardedRef, useContext, useEffect, useImperativeHandle, useRef, useCallback, useState } 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 { globalClasses } from './ColorableInputElement.styles';\n\nexport type ColorableInputElementProps = InputElementProps & {\n showOnFocus?: boolean;\n children: React.ReactElement;\n};\n\n// Возможно придётся включить.\n// Иногда, на тяжёлых страницах, текст рендерится итеративно.\n// Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.\n// setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 1000);\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 const [active, setActive] = useState(true);\n\n const { children, onInput, onFocus, onBlur, showOnFocus, ...inputProps } = props;\n\n useImperativeHandle(\n ref,\n () => ({\n input: inputRef.current,\n getRootNode: () => inputRef.current,\n }),\n [],\n );\n\n useEffect(updateActive, []);\n\n const paintText = useCallback(() => {\n if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {\n return;\n }\n\n inputRef.current?.classList.add(globalClasses.input);\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 =\n ((inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&\n inputRef.current.getAttribute('data-typed-value')) ||\n '';\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 (props.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 props.showOnFocus,\n props.disabled,\n theme.inputTextColor,\n theme.inputPlaceholderColor,\n theme.inputTextColorDisabled,\n ]);\n\n const debouncedPaintText = useCallback(() => debounce(paintText), [paintText])();\n\n const activation = useCallback(() => {\n if (active) {\n debouncedPaintText();\n } else {\n debouncedPaintText.cancel();\n inputRef.current && (inputRef.current.style.backgroundImage = '');\n inputRef.current?.classList.remove(globalClasses.input);\n }\n }, [debouncedPaintText, active]);\n\n useEffect(() => {\n activation();\n updateActive();\n }, [props.value, props.defaultValue, theme, activation]);\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 && globalClasses.input),\n })}\n {active && <span style={{ visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }} ref={spanRef} />}\n </>\n );\n\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n const isActive = !inputRef.current?.parentElement?.querySelector(':placeholder-shown');\n setActive(isActive);\n\n activation();\n\n onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setTimeout(updateActive);\n\n focused.current = true;\n\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n updateActive();\n\n focused.current = false;\n\n onBlur?.(e);\n }\n\n function updateActive() {\n setTimeout(() => {\n setActive(!inputRef.current?.parentElement?.querySelector(':placeholder-shown'));\n });\n }\n },\n);\n"],"mappings":";AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;;AAEA,IAAAI,aAAA,GAAAJ,OAAA;;AAEA,IAAAK,kBAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;;AAEA,IAAAO,sBAAA,GAAAP,OAAA,mCAA+D,IAAAQ,SAAA,gEAV/D;;;;;;;AAiBA;AACA;AACA;AACA;;AAEO,IAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG,IAAAE,oCAAiB;EACpD,uBAAuB;EACvB,SAASF,qBAAqBA,CAACG,KAAiC,EAAEC,GAA+B,EAAE;IACjG,IAAMC,QAAQ,GAAG,IAAAC,aAAM,EAA0B,IAAI,CAAC;IACtD,IAAMC,OAAO,GAAG,IAAAD,aAAM,EAAyB,IAAI,CAAC;IACpD,IAAME,OAAO,GAAG,IAAAF,aAAM,EAAC,KAAK,CAAC;IAC7B,IAAMG,UAAU,GAAG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AAPA,OAAO,CAAGoE,CAAC,CAAC;IACd;;IAEA,SAASN,UAAUA,CAACM,CAAqC,EAAE;MACzDzD,YAAY,CAAC,CAAC;;MAEdvB,OAAO,CAACoB,OAAO,GAAG,KAAK;;MAEvBP,MAAM,YAANA,MAAM,CAAGmE,CAAC,CAAC;IACb;;IAEA,SAASzD,YAAYA,CAAA,EAAG;MACtB8D,UAAU,CAAC,YAAM,KAAAC,kBAAA;QACf7E,SAAS,CAAC,GAAA6E,kBAAA,GAACzF,QAAQ,CAACuB,OAAO,cAAAkE,kBAAA,GAAhBA,kBAAA,CAAkBH,aAAa,aAA/BG,kBAAA,CAAiCF,aAAa,CAAC,oBAAoB,CAAC,EAAC;MAClF,CAAC,CAAC;IACJ;EACF;AACF,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- var _excluded = ["children", "onInput", "onFocus", "onBlur", "showOnFocus"];
3
+ var _excluded = ["children", "onInput", "onFocus", "onBlur", "showOnFocus"]; /* eslint react-hooks/exhaustive-deps: 2 */
4
4
  import React, { useContext, useEffect, useImperativeHandle, useRef, useCallback, useState } from 'react';
5
5
  import { globalObject, isBrowser } from '@skbkontur/global-object';
6
6
  import debounce from 'lodash.debounce';
@@ -20,7 +20,6 @@ export var ColorableInputElement = forwardRefAndName('ColorableInputElement', fu
20
20
  var focused = useRef(false);
21
21
  var inputStyle = React.useRef();
22
22
  var theme = useContext(ThemeContext);
23
- var debouncedPaintText = useCallback(debounce(paintText), []);
24
23
  var _useState = useState(true),
25
24
  active = _useState[0],
26
25
  setActive = _useState[1];
@@ -39,10 +38,56 @@ export var ColorableInputElement = forwardRefAndName('ColorableInputElement', fu
39
38
  };
40
39
  }, []);
41
40
  useEffect(updateActive, []);
41
+ var paintText = useCallback(function () {
42
+ var _inputRef$current, _shadow;
43
+ if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {
44
+ return;
45
+ }
46
+ (_inputRef$current = inputRef.current) == null || _inputRef$current.classList.add(globalClasses.input);
47
+ var shadow = spanRef.current.shadowRoot;
48
+ var typedValueElement = (_shadow = shadow) == null ? void 0 : _shadow.getElementById('span');
49
+ if (!typedValueElement) {
50
+ shadow = spanRef.current.attachShadow({
51
+ mode: 'open'
52
+ });
53
+ typedValueElement = globalObject.document.createElement('span');
54
+ typedValueElement.setAttribute('id', 'span');
55
+ shadow.appendChild(typedValueElement);
56
+ }
57
+ var style = inputStyle.current;
58
+ typedValueElement.textContent = (inputRef.current.getAttribute('data-unmasked-value') || focused.current) && inputRef.current.getAttribute('data-typed-value') || '';
59
+ var inputRect = inputRef.current.getBoundingClientRect();
60
+ var filledRect = spanRef.current.getBoundingClientRect();
61
+ var threshold = filledRect.width / (inputRect.width / 100);
62
+ var degree = style.fontStyle === 'italic' ? 100 : 90;
63
+ var typedValueColor = theme.inputTextColor;
64
+ var maskColor = theme.inputPlaceholderColor;
65
+ if (props.disabled) {
66
+ typedValueColor = theme.inputTextColorDisabled;
67
+ maskColor = theme.inputTextColorDisabled;
68
+ }
69
+ if (props.showOnFocus) {
70
+ maskColor = focused.current ? maskColor : 'transparent';
71
+ }
72
+ inputRef.current.style.backgroundImage = "\n linear-gradient(\n " + degree + "deg,\n " + typedValueColor + " " + threshold + "%,\n " + maskColor + " " + threshold + "%\n )";
73
+ }, [props.showOnFocus, props.disabled, theme.inputTextColor, theme.inputPlaceholderColor, theme.inputTextColorDisabled]);
74
+ var debouncedPaintText = useCallback(function () {
75
+ return debounce(paintText);
76
+ }, [paintText])();
77
+ var activation = useCallback(function () {
78
+ if (active) {
79
+ debouncedPaintText();
80
+ } else {
81
+ var _inputRef$current2;
82
+ debouncedPaintText.cancel();
83
+ inputRef.current && (inputRef.current.style.backgroundImage = '');
84
+ (_inputRef$current2 = inputRef.current) == null || _inputRef$current2.classList.remove(globalClasses.input);
85
+ }
86
+ }, [debouncedPaintText, active]);
42
87
  useEffect(function () {
43
- activation(props, theme);
88
+ activation();
44
89
  updateActive();
45
- }, [active, showOnFocus, props.value, props.defaultValue, props.disabled, focused.current, theme]);
90
+ }, [props.value, props.defaultValue, theme, activation]);
46
91
  useEffect(function () {
47
92
  if (inputRef.current) {
48
93
  inputStyle.current = getComputedStyle(inputRef.current);
@@ -66,10 +111,10 @@ export var ColorableInputElement = forwardRefAndName('ColorableInputElement', fu
66
111
  }))
67
112
  );
68
113
  function handleInput(e) {
69
- var _inputRef$current;
70
- var isActive = !((_inputRef$current = inputRef.current) != null && (_inputRef$current = _inputRef$current.parentElement) != null && _inputRef$current.querySelector(':placeholder-shown'));
114
+ var _inputRef$current3;
115
+ var isActive = !((_inputRef$current3 = inputRef.current) != null && (_inputRef$current3 = _inputRef$current3.parentElement) != null && _inputRef$current3.querySelector(':placeholder-shown'));
71
116
  setActive(isActive);
72
- activation(props, theme);
117
+ activation();
73
118
  onInput == null || onInput(e);
74
119
  }
75
120
  function handleFocus(e) {
@@ -84,57 +129,8 @@ export var ColorableInputElement = forwardRefAndName('ColorableInputElement', fu
84
129
  }
85
130
  function updateActive() {
86
131
  setTimeout(function () {
87
- var _inputRef$current2;
88
- setActive(!((_inputRef$current2 = inputRef.current) != null && (_inputRef$current2 = _inputRef$current2.parentElement) != null && _inputRef$current2.querySelector(':placeholder-shown')));
132
+ var _inputRef$current4;
133
+ setActive(!((_inputRef$current4 = inputRef.current) != null && (_inputRef$current4 = _inputRef$current4.parentElement) != null && _inputRef$current4.querySelector(':placeholder-shown')));
89
134
  });
90
135
  }
91
- function activation(props, theme) {
92
- if (active) {
93
- debouncedPaintText(props, theme);
94
- } else {
95
- var _inputRef$current3;
96
- debouncedPaintText.cancel();
97
- inputRef.current && (inputRef.current.style.backgroundImage = '');
98
- (_inputRef$current3 = inputRef.current) == null || _inputRef$current3.classList.remove(globalClasses.input);
99
- }
100
- }
101
- function paintText(_props, _theme) {
102
- var _inputRef$current4, _shadow;
103
- if (_props === void 0) {
104
- _props = props;
105
- }
106
- if (_theme === void 0) {
107
- _theme = theme;
108
- }
109
- if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {
110
- return;
111
- }
112
- (_inputRef$current4 = inputRef.current) == null || _inputRef$current4.classList.add(globalClasses.input);
113
- var shadow = spanRef.current.shadowRoot;
114
- var typedValueElement = (_shadow = shadow) == null ? void 0 : _shadow.getElementById('span');
115
- if (!typedValueElement) {
116
- shadow = spanRef.current.attachShadow({
117
- mode: 'open'
118
- });
119
- typedValueElement = globalObject.document.createElement('span');
120
- typedValueElement.setAttribute('id', 'span');
121
- shadow.appendChild(typedValueElement);
122
- }
123
- var style = inputStyle.current;
124
- typedValueElement.textContent = (inputRef.current.getAttribute('data-unmasked-value') || focused.current) && inputRef.current.getAttribute('data-typed-value') || '';
125
- var inputRect = inputRef.current.getBoundingClientRect();
126
- var filledRect = spanRef.current.getBoundingClientRect();
127
- var threshold = filledRect.width / (inputRect.width / 100);
128
- var degree = style.fontStyle === 'italic' ? 100 : 90;
129
- var typedValueColor = _theme.inputTextColor;
130
- var maskColor = _theme.inputPlaceholderColor;
131
- if (_props.disabled) {
132
- typedValueColor = _theme.inputTextColorDisabled;
133
- maskColor = _theme.inputTextColorDisabled;
134
- }
135
- if (_props.showOnFocus) {
136
- maskColor = focused.current ? maskColor : 'transparent';
137
- }
138
- inputRef.current.style.backgroundImage = "\n linear-gradient(\n " + degree + "deg,\n " + typedValueColor + " " + threshold + "%,\n " + maskColor + " " + threshold + "%\n )";
139
- }
140
136
  });
@@ -1 +1 @@
1
- {"version":3,"names":["React","useContext","useEffect","useImperativeHandle","useRef","useCallback","useState","globalObject","isBrowser","debounce","ThemeContext","forwardRefAndName","cx","globalClasses","ColorableInputElement","props","ref","inputRef","spanRef","focused","inputStyle","theme","debouncedPaintText","paintText","_useState","active","setActive","children","onInput","onFocus","onBlur","showOnFocus","inputProps","_objectWithoutPropertiesLoose","_excluded","input","current","getRootNode","updateActive","activation","value","defaultValue","disabled","getComputedStyle","createElement","Fragment","cloneElement","_extends","handleInput","handleFocus","handleBlur","className","style","visibility","position","whiteSpace","e","_inputRef$current","isActive","parentElement","querySelector","setTimeout","_inputRef$current2","_inputRef$current3","cancel","backgroundImage","classList","remove","_props","_theme","_inputRef$current4","_shadow","add","shadow","shadowRoot","typedValueElement","getElementById","attachShadow","mode","document","setAttribute","appendChild","textContent","getAttribute","inputRect","getBoundingClientRect","filledRect","threshold","width","degree","fontStyle","typedValueColor","inputTextColor","maskColor","inputPlaceholderColor","inputTextColorDisabled"],"sources":["ColorableInputElement.tsx"],"sourcesContent":["import React, { ForwardedRef, useContext, useEffect, useImperativeHandle, useRef, useCallback, useState } 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';\nimport { Theme } from '../../../lib/theming/Theme';\n\nimport { globalClasses } from './ColorableInputElement.styles';\n\nexport type ColorableInputElementProps = InputElementProps & {\n showOnFocus?: boolean;\n children: React.ReactElement;\n};\n\n// Возможно придётся включить.\n// Иногда, на тяжёлых страницах, текст рендерится итеративно.\n// Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.\n// setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 1000);\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 const debouncedPaintText = useCallback(debounce(paintText), []);\n const [active, setActive] = useState(true);\n\n const { children, onInput, onFocus, onBlur, showOnFocus, ...inputProps } = props;\n\n useImperativeHandle(\n ref,\n () => ({\n input: inputRef.current,\n getRootNode: () => inputRef.current,\n }),\n [],\n );\n\n useEffect(updateActive, []);\n\n useEffect(() => {\n activation(props, theme);\n updateActive();\n }, [active, showOnFocus, props.value, props.defaultValue, props.disabled, focused.current, theme]);\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 && globalClasses.input),\n })}\n {active && <span style={{ visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }} ref={spanRef} />}\n </>\n );\n\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n const isActive = !inputRef.current?.parentElement?.querySelector(':placeholder-shown');\n setActive(isActive);\n\n activation(props, theme);\n\n onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setTimeout(updateActive);\n\n focused.current = true;\n\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n updateActive();\n\n focused.current = false;\n\n onBlur?.(e);\n }\n\n function updateActive() {\n setTimeout(() => {\n setActive(!inputRef.current?.parentElement?.querySelector(':placeholder-shown'));\n });\n }\n\n function activation(props: ColorableInputElementProps, theme: Theme) {\n if (active) {\n debouncedPaintText(props, theme);\n } else {\n debouncedPaintText.cancel();\n inputRef.current && (inputRef.current.style.backgroundImage = '');\n inputRef.current?.classList.remove(globalClasses.input);\n }\n }\n\n function paintText(_props: Partial<ColorableInputElementProps> = props, _theme: Theme = theme) {\n if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {\n return;\n }\n\n inputRef.current?.classList.add(globalClasses.input);\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 =\n ((inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&\n inputRef.current.getAttribute('data-typed-value')) ||\n '';\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 (_props.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"],"mappings":"0OAAA,OAAOA,KAAK,IAAkBC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AACtH,SAASC,YAAY,EAAEC,SAAS,QAAQ,0BAA0B;AAClE,OAAOC,QAAQ,MAAM,iBAAiB;;AAEtC,SAASC,YAAY,QAAQ,mCAAmC;;AAEhE,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,EAAE,QAAQ,8BAA8B;;;AAGjD,SAASC,aAAa,QAAQ,gCAAgC;;;;;;;AAO9D;AACA;AACA;AACA;;AAEA,OAAO,IAAMC,qBAAqB,GAAGH,iBAAiB;EACpD,uBAAuB;EACvB,SAASG,qBAAqBA,CAACC,KAAiC,EAAEC,GAA+B,EAAE;IACjG,IAAMC,QAAQ,GAAGb,MAAM,CAA0B,IAAI,CAAC;IACtD,IAAMc,OAAO,GAAGd,MAAM,CAAyB,IAAI,CAAC;IACpD,IA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B,QAAQ,EAAE;QACnBiD,eAAe,GAAGtB,MAAM,CAAC0B,sBAAsB;QAC/CF,SAAS,GAAGxB,MAAM,CAAC0B,sBAAsB;MAC3C;MACA,IAAI3B,MAAM,CAACrC,WAAW,EAAE;QACtB8D,SAAS,GAAG1E,OAAO,CAACiB,OAAO,GAAGyD,SAAS,GAAG,aAAa;MACzD;;MAEA5E,QAAQ,CAACmB,OAAO,CAACgB,KAAK,CAACa,eAAe;;MAEhCwB,MAAM;MACNE,eAAe,SAAIJ,SAAS;MAC5BM,SAAS,SAAIN,SAAS,eAC1B;;IACJ;EACF;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useContext","useEffect","useImperativeHandle","useRef","useCallback","useState","globalObject","isBrowser","debounce","ThemeContext","forwardRefAndName","cx","globalClasses","ColorableInputElement","props","ref","inputRef","spanRef","focused","inputStyle","theme","_useState","active","setActive","children","onInput","onFocus","onBlur","showOnFocus","inputProps","_objectWithoutPropertiesLoose","_excluded","input","current","getRootNode","updateActive","paintText","_inputRef$current","_shadow","classList","add","shadow","shadowRoot","typedValueElement","getElementById","attachShadow","mode","document","createElement","setAttribute","appendChild","style","textContent","getAttribute","inputRect","getBoundingClientRect","filledRect","threshold","width","degree","fontStyle","typedValueColor","inputTextColor","maskColor","inputPlaceholderColor","disabled","inputTextColorDisabled","backgroundImage","debouncedPaintText","activation","_inputRef$current2","cancel","remove","value","defaultValue","getComputedStyle","Fragment","cloneElement","_extends","handleInput","handleFocus","handleBlur","className","visibility","position","whiteSpace","e","_inputRef$current3","isActive","parentElement","querySelector","setTimeout","_inputRef$current4"],"sources":["ColorableInputElement.tsx"],"sourcesContent":["/* eslint react-hooks/exhaustive-deps: 2 */\nimport React, { ForwardedRef, useContext, useEffect, useImperativeHandle, useRef, useCallback, useState } 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 { globalClasses } from './ColorableInputElement.styles';\n\nexport type ColorableInputElementProps = InputElementProps & {\n showOnFocus?: boolean;\n children: React.ReactElement;\n};\n\n// Возможно придётся включить.\n// Иногда, на тяжёлых страницах, текст рендерится итеративно.\n// Из-за этого могут оставаться артефакты при покраске компонента, которые пропадут только после фокуса.\n// setInterval(() => window.requestAnimationFrame(() => dictionary.forEach((paint) => paint())), 1000);\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 const [active, setActive] = useState(true);\n\n const { children, onInput, onFocus, onBlur, showOnFocus, ...inputProps } = props;\n\n useImperativeHandle(\n ref,\n () => ({\n input: inputRef.current,\n getRootNode: () => inputRef.current,\n }),\n [],\n );\n\n useEffect(updateActive, []);\n\n const paintText = useCallback(() => {\n if (!spanRef.current || !inputRef.current || !inputStyle.current || !isBrowser(globalObject)) {\n return;\n }\n\n inputRef.current?.classList.add(globalClasses.input);\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 =\n ((inputRef.current.getAttribute('data-unmasked-value') || focused.current) &&\n inputRef.current.getAttribute('data-typed-value')) ||\n '';\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 (props.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 props.showOnFocus,\n props.disabled,\n theme.inputTextColor,\n theme.inputPlaceholderColor,\n theme.inputTextColorDisabled,\n ]);\n\n const debouncedPaintText = useCallback(() => debounce(paintText), [paintText])();\n\n const activation = useCallback(() => {\n if (active) {\n debouncedPaintText();\n } else {\n debouncedPaintText.cancel();\n inputRef.current && (inputRef.current.style.backgroundImage = '');\n inputRef.current?.classList.remove(globalClasses.input);\n }\n }, [debouncedPaintText, active]);\n\n useEffect(() => {\n activation();\n updateActive();\n }, [props.value, props.defaultValue, theme, activation]);\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 && globalClasses.input),\n })}\n {active && <span style={{ visibility: 'hidden', position: 'absolute', whiteSpace: 'pre' }} ref={spanRef} />}\n </>\n );\n\n function handleInput(e: React.ChangeEvent<HTMLInputElement>) {\n const isActive = !inputRef.current?.parentElement?.querySelector(':placeholder-shown');\n setActive(isActive);\n\n activation();\n\n onInput?.(e);\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n setTimeout(updateActive);\n\n focused.current = true;\n\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n updateActive();\n\n focused.current = false;\n\n onBlur?.(e);\n }\n\n function updateActive() {\n setTimeout(() => {\n setActive(!inputRef.current?.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AAE,UAAU,EAAEC,UAAU,EAAE,KAAK,CAAC,CAAE,EAACtE,GAAG,EAAEE,OAAQ,EAAE;MAC1G,CAAC;;;IAGL,SAAS8D,WAAWA,CAACO,CAAsC,EAAE,KAAAC,kBAAA;MAC3D,IAAMC,QAAQ,GAAG,GAAAD,kBAAA,GAACvE,QAAQ,CAACiB,OAAO,cAAAsD,kBAAA,GAAhBA,kBAAA,CAAkBE,aAAa,aAA/BF,kBAAA,CAAiCG,aAAa,CAAC,oBAAoB,CAAC;MACtFnE,SAAS,CAACiE,QAAQ,CAAC;;MAEnBnB,UAAU,CAAC,CAAC;;MAEZ5C,OAAO,YAAPA,OAAO,CAAG6D,CAAC,CAAC;IACd;;IAEA,SAASN,WAAWA,CAACM,CAAqC,EAAE;MAC1DK,UAAU,CAACxD,YAAY,CAAC;;MAExBjB,OAAO,CAACe,OAAO,GAAG,IAAI;;MAEtBP,OAAO,YAAPA,OAAO,CAAG4D,CAAC,CAAC;IACd;;IAEA,SAASL,UAAUA,CAACK,CAAqC,EAAE;MACzDnD,YAAY,CAAC,CAAC;;MAEdjB,OAAO,CAACe,OAAO,GAAG,KAAK;;MAEvBN,MAAM,YAANA,MAAM,CAAG2D,CAAC,CAAC;IACb;;IAEA,SAASnD,YAAYA,CAAA,EAAG;MACtBwD,UAAU,CAAC,YAAM,KAAAC,kBAAA;QACfrE,SAAS,CAAC,GAAAqE,kBAAA,GAAC5E,QAAQ,CAACiB,OAAO,cAAA2D,kBAAA,GAAhBA,kBAAA,CAAkBH,aAAa,aAA/BG,kBAAA,CAAiCF,aAAa,CAAC,oBAAoB,CAAC,EAAC;MAClF,CAAC,CAAC;IACJ;EACF;AACF,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui",
3
- "version": "5.0.11-ZIndex-several-roots.2",
3
+ "version": "5.0.12",
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",
8
+ "homepage": "https://tech.skbkontur.ru/react-ui/5.0.12/",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git@github.com:skbkontur/retail-ui.git"
@@ -158,5 +158,8 @@
158
158
  "peerDependencies": {
159
159
  "react": ">=16.9",
160
160
  "react-dom": ">=16.9"
161
+ },
162
+ "publishConfig": {
163
+ "tag": "latest"
161
164
  }
162
165
  }