@hh.ru/magritte-ui-textarea 2.3.6 → 3.0.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/TextArea.d.ts CHANGED
@@ -1,3 +1,8 @@
1
- import type { ControlledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';
2
- declare const TextArea: import("react").ForwardRefExoticComponent<(ControlledTextAreaProps & Omit<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, "placeholder" | "onFocus" | "onBlur" | "description" | "errorMessage" | "disabled" | "invalid" | "invalidLimit" | "elevatePlaceholder" | "onChange" | "value" | "maxLength" | "onValidate" | "layout" | "minHeight" | "resize">) & import("react").RefAttributes<HTMLTextAreaElement>>;
1
+ import { ReactElement } from 'react';
2
+ import { type TextAreaLayout, type ControlledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';
3
+ declare const TextArea: (<Layout extends TextAreaLayout>(props: ControlledTextAreaProps<Layout> & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, keyof ControlledTextAreaProps<"fixed">> & {
4
+ ref?: React.ForwardedRef<HTMLTextAreaElement>;
5
+ }) => ReactElement | null) & {
6
+ displayName: string;
7
+ };
3
8
  export { TextArea };
package/TextArea.js CHANGED
@@ -1,37 +1,27 @@
1
1
  import './index.css';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { forwardRef, useState, useRef, useId, useContext, useEffect, useCallback, useLayoutEffect } from 'react';
3
+ import { forwardRef, useState, useRef, useId, useEffect } from 'react';
4
4
  import { CSSTransition } from 'react-transition-group';
5
5
  import classnames from 'classnames';
6
6
  import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
7
7
  import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
8
8
  import { useTranslation } from '@hh.ru/magritte-common-use-translation';
9
- import { BottomSheetContext } from '@hh.ru/magritte-ui-bottom-sheet';
10
9
  import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
11
10
  import { FormHelper } from '@hh.ru/magritte-ui-form-helper';
12
11
  import { GripSize24 } from '@hh.ru/magritte-ui-icon/private';
13
12
  import { useInputAriaProps } from '@hh.ru/magritte-ui-input/useInputAriaProps';
14
13
  import { useFocus } from './useFocus.js';
14
+ import { useLimitGrow } from './useLimitGrow.js';
15
+ import { useMinHeight } from './useMinHeight.js';
15
16
  import { Text } from '@hh.ru/magritte-ui-typography';
17
+ import './TextAreaGrowLimiter.js';
18
+ import '@hh.ru/magritte-common-func-utils';
19
+ import './types.js';
16
20
 
17
- var styles = {"textarea":"magritte-textarea___ugvor_2-3-6","textarea-focused":"magritte-textarea-focused___eiGyC_2-3-6","textareaFocused":"magritte-textarea-focused___eiGyC_2-3-6","textarea-invalid":"magritte-textarea-invalid___iKOPh_2-3-6","textareaInvalid":"magritte-textarea-invalid___iKOPh_2-3-6","textarea-disabled":"magritte-textarea-disabled___XN0cg_2-3-6","textareaDisabled":"magritte-textarea-disabled___XN0cg_2-3-6","textarea-position-container-wrapper":"magritte-textarea-position-container-wrapper___4Dsui_2-3-6","textareaPositionContainerWrapper":"magritte-textarea-position-container-wrapper___4Dsui_2-3-6","textarea-position-container":"magritte-textarea-position-container___cEpbv_2-3-6","textareaPositionContainer":"magritte-textarea-position-container___cEpbv_2-3-6","native-element":"magritte-native-element___a0RAE_2-3-6","nativeElement":"magritte-native-element___a0RAE_2-3-6","textarea-label":"magritte-textarea-label___sgTIH_2-3-6","textareaLabel":"magritte-textarea-label___sgTIH_2-3-6","textarea-label-elevated":"magritte-textarea-label-elevated___0lxOI_2-3-6","textareaLabelElevated":"magritte-textarea-label-elevated___0lxOI_2-3-6","textarea-limit":"magritte-textarea-limit___IjPJy_2-3-6","textareaLimit":"magritte-textarea-limit___IjPJy_2-3-6","textarea-limit-error":"magritte-textarea-limit-error___vLvZU_2-3-6","textareaLimitError":"magritte-textarea-limit-error___vLvZU_2-3-6","min-height-48":"magritte-min-height-48___jGf5Z_2-3-6","minHeight48":"magritte-min-height-48___jGf5Z_2-3-6","min-height-56":"magritte-min-height-56___2yI39_2-3-6","minHeight56":"magritte-min-height-56___2yI39_2-3-6","min-height-default":"magritte-min-height-default___zwRcq_2-3-6","minHeightDefault":"magritte-min-height-default___zwRcq_2-3-6","textarea-limited":"magritte-textarea-limited___cU1Rg_2-3-6","textareaLimited":"magritte-textarea-limited___cU1Rg_2-3-6","textarea-layout-fill-both":"magritte-textarea-layout-fill-both___ERS-q_2-3-6","textareaLayoutFillBoth":"magritte-textarea-layout-fill-both___ERS-q_2-3-6","textarea-layout-fill-vertical":"magritte-textarea-layout-fill-vertical___HmNtp_2-3-6","textareaLayoutFillVertical":"magritte-textarea-layout-fill-vertical___HmNtp_2-3-6","textarea-layout-fill-horizontal":"magritte-textarea-layout-fill-horizontal___imBH2_2-3-6","textareaLayoutFillHorizontal":"magritte-textarea-layout-fill-horizontal___imBH2_2-3-6","textarea-wrapper":"magritte-textarea-wrapper___yD7G6_2-3-6","textareaWrapper":"magritte-textarea-wrapper___yD7G6_2-3-6","textarea-layout-hug":"magritte-textarea-layout-hug___tdCMY_2-3-6","textareaLayoutHug":"magritte-textarea-layout-hug___tdCMY_2-3-6","textarea-elevated":"magritte-textarea-elevated___S0jk-_2-3-6","textareaElevated":"magritte-textarea-elevated___S0jk-_2-3-6","textarea-animation-timeout":"magritte-textarea-animation-timeout___zudbr_2-3-6","textareaAnimationTimeout":"magritte-textarea-animation-timeout___zudbr_2-3-6","textarea-rigging-container":"magritte-textarea-rigging-container___-1S6i_2-3-6","textareaRiggingContainer":"magritte-textarea-rigging-container___-1S6i_2-3-6","label-no-wrap":"magritte-label-no-wrap___RxZ3A_2-3-6","labelNoWrap":"magritte-label-no-wrap___RxZ3A_2-3-6","textarea-grip":"magritte-textarea-grip___iL7lq_2-3-6","textareaGrip":"magritte-textarea-grip___iL7lq_2-3-6","textarea-grip-icon":"magritte-textarea-grip-icon___YK-9w_2-3-6","textareaGripIcon":"magritte-textarea-grip-icon___YK-9w_2-3-6","textarea-limit-enter":"magritte-textarea-limit-enter___CygGz_2-3-6","textareaLimitEnter":"magritte-textarea-limit-enter___CygGz_2-3-6","textarea-limit-exit":"magritte-textarea-limit-exit___RMp-R_2-3-6","textareaLimitExit":"magritte-textarea-limit-exit___RMp-R_2-3-6","textarea-limit-enter-active":"magritte-textarea-limit-enter-active___8vN-t_2-3-6","textareaLimitEnterActive":"magritte-textarea-limit-enter-active___8vN-t_2-3-6","textarea-limit-exit-active":"magritte-textarea-limit-exit-active___a5kBr_2-3-6","textareaLimitExitActive":"magritte-textarea-limit-exit-active___a5kBr_2-3-6"};
21
+ var styles = {"textarea":"magritte-textarea___ugvor_3-0-0","textarea-elevated":"magritte-textarea-elevated___S0jk-_3-0-0","textareaElevated":"magritte-textarea-elevated___S0jk-_3-0-0","textarea-small":"magritte-textarea-small___Q-tsg_3-0-0","textareaSmall":"magritte-textarea-small___Q-tsg_3-0-0","textarea-medium":"magritte-textarea-medium___GNzAm_3-0-0","textareaMedium":"magritte-textarea-medium___GNzAm_3-0-0","textarea-large":"magritte-textarea-large___ugT-5_3-0-0","textareaLarge":"magritte-textarea-large___ugT-5_3-0-0","has-grip":"magritte-has-grip___ATMYQ_3-0-0","hasGrip":"magritte-has-grip___ATMYQ_3-0-0","textarea-limited":"magritte-textarea-limited___cU1Rg_3-0-0","textareaLimited":"magritte-textarea-limited___cU1Rg_3-0-0","maxed-height":"magritte-maxed-height___v1wYG_3-0-0","maxedHeight":"magritte-maxed-height___v1wYG_3-0-0","textarea-focused":"magritte-textarea-focused___eiGyC_3-0-0","textareaFocused":"magritte-textarea-focused___eiGyC_3-0-0","textarea-invalid":"magritte-textarea-invalid___iKOPh_3-0-0","textareaInvalid":"magritte-textarea-invalid___iKOPh_3-0-0","textarea-disabled":"magritte-textarea-disabled___XN0cg_3-0-0","textareaDisabled":"magritte-textarea-disabled___XN0cg_3-0-0","textarea-position-container-wrapper":"magritte-textarea-position-container-wrapper___4Dsui_3-0-0","textareaPositionContainerWrapper":"magritte-textarea-position-container-wrapper___4Dsui_3-0-0","textarea-position-container":"magritte-textarea-position-container___cEpbv_3-0-0","textareaPositionContainer":"magritte-textarea-position-container___cEpbv_3-0-0","native-element":"magritte-native-element___a0RAE_3-0-0","nativeElement":"magritte-native-element___a0RAE_3-0-0","textarea-label":"magritte-textarea-label___sgTIH_3-0-0","textareaLabel":"magritte-textarea-label___sgTIH_3-0-0","textarea-label-elevated":"magritte-textarea-label-elevated___0lxOI_3-0-0","textareaLabelElevated":"magritte-textarea-label-elevated___0lxOI_3-0-0","textarea-limit":"magritte-textarea-limit___IjPJy_3-0-0","textareaLimit":"magritte-textarea-limit___IjPJy_3-0-0","textarea-limit-error":"magritte-textarea-limit-error___vLvZU_3-0-0","textareaLimitError":"magritte-textarea-limit-error___vLvZU_3-0-0","textarea-layout-fill-both":"magritte-textarea-layout-fill-both___ERS-q_3-0-0","textareaLayoutFillBoth":"magritte-textarea-layout-fill-both___ERS-q_3-0-0","textarea-layout-fill-vertical":"magritte-textarea-layout-fill-vertical___HmNtp_3-0-0","textareaLayoutFillVertical":"magritte-textarea-layout-fill-vertical___HmNtp_3-0-0","textarea-layout-fill-horizontal":"magritte-textarea-layout-fill-horizontal___imBH2_3-0-0","textareaLayoutFillHorizontal":"magritte-textarea-layout-fill-horizontal___imBH2_3-0-0","textarea-layout-hug":"magritte-textarea-layout-hug___tdCMY_3-0-0","textareaLayoutHug":"magritte-textarea-layout-hug___tdCMY_3-0-0","textarea-wrapper":"magritte-textarea-wrapper___yD7G6_3-0-0","textareaWrapper":"magritte-textarea-wrapper___yD7G6_3-0-0","value-clone-wrapper":"magritte-value-clone-wrapper___2ZZvS_3-0-0","valueCloneWrapper":"magritte-value-clone-wrapper___2ZZvS_3-0-0","value-clone-container":"magritte-value-clone-container___PVM97_3-0-0","valueCloneContainer":"magritte-value-clone-container___PVM97_3-0-0","side-padding":"magritte-side-padding___O-HUP_3-0-0","sidePadding":"magritte-side-padding___O-HUP_3-0-0","textarea-animation-timeout":"magritte-textarea-animation-timeout___zudbr_3-0-0","textareaAnimationTimeout":"magritte-textarea-animation-timeout___zudbr_3-0-0","textarea-rigging-container":"magritte-textarea-rigging-container___-1S6i_3-0-0","textareaRiggingContainer":"magritte-textarea-rigging-container___-1S6i_3-0-0","label-no-wrap":"magritte-label-no-wrap___RxZ3A_3-0-0","labelNoWrap":"magritte-label-no-wrap___RxZ3A_3-0-0","textarea-grip":"magritte-textarea-grip___iL7lq_3-0-0","textareaGrip":"magritte-textarea-grip___iL7lq_3-0-0","textarea-grip-icon":"magritte-textarea-grip-icon___YK-9w_3-0-0","textareaGripIcon":"magritte-textarea-grip-icon___YK-9w_3-0-0","textarea-limit-enter":"magritte-textarea-limit-enter___CygGz_3-0-0","textareaLimitEnter":"magritte-textarea-limit-enter___CygGz_3-0-0","textarea-limit-exit":"magritte-textarea-limit-exit___RMp-R_3-0-0","textareaLimitExit":"magritte-textarea-limit-exit___RMp-R_3-0-0","textarea-limit-enter-active":"magritte-textarea-limit-enter-active___8vN-t_3-0-0","textareaLimitEnterActive":"magritte-textarea-limit-enter-active___8vN-t_3-0-0","textarea-limit-exit-active":"magritte-textarea-limit-exit-active___a5kBr_3-0-0","textareaLimitExitActive":"magritte-textarea-limit-exit-active___a5kBr_3-0-0"};
18
22
 
19
- const MIN_HEIGHT_WITH_VISIBLE_LIMIT = 112;
20
- const findFlexContainer = (element) => {
21
- if (!element) {
22
- return null;
23
- }
24
- let parentElement = element.parentElement;
25
- while (parentElement !== null) {
26
- const { display } = window.getComputedStyle(parentElement);
27
- if (display.includes('flex')) {
28
- return parentElement;
29
- }
30
- parentElement = parentElement.parentElement;
31
- }
32
- return null;
33
- };
34
- const TextAreaComponent = ({ onChange, onFocus, onBlur, onValidate, value, placeholder, disabled = false, elevatePlaceholder = false, invalid = false, invalidLimit = false, maxLength, description, errorMessage, resize = 'none', layout = 'fixed', minHeight, ...restProps }, ref) => {
23
+ const ZERO_WIDTH_SPACE = '\u200B';
24
+ const TextAreaComponent = ({ onChange, onFocus, onBlur, onValidate, value, placeholder, disabled = false, elevatePlaceholder = false, invalid = false, invalidLimit = false, maxLength, description, errorMessage, resize = 'none', layout = 'fixed', size = 'large', minHeight: _minHeight, maxHeight, ...restProps }, ref) => {
35
25
  const { isMobile } = useBreakpoint();
36
26
  const [internalInvalid, setInternalInvalid] = useState(false);
37
27
  const [isFocusVisible, setFocusVisible] = useState(false);
@@ -47,11 +37,17 @@ const TextAreaComponent = ({ onChange, onFocus, onBlur, onValidate, value, place
47
37
  const [animationTimeout, setAnimationTimeout] = useState(100);
48
38
  const currentResizeValue = isMobile ? 'none' : resize;
49
39
  const isResizable = currentResizeValue !== 'none';
50
- const [isMaxLengthDisplayed, setMaxLengthDisplayed] = useState(!!maxLength && !minHeight);
51
- const actualMinHeight = minHeight !== undefined && !value.includes('\n') ? minHeight : undefined;
52
- const [maxAllowedHeight, setMaxAllowedHeight] = useState(null);
53
- const bottomSheetContext = useContext(BottomSheetContext);
54
- const wrapperRef = useRef(null);
40
+ const contentCloneRef = useRef(null);
41
+ const contentCloneWrapperRef = useRef(null);
42
+ const { minHeight, maxedHeight } = useMinHeight(size, _minHeight, layout, contentCloneRef);
43
+ const { maxHeightRef, allowScrollRef } = useLimitGrow({
44
+ layout,
45
+ contentCloneRef,
46
+ contentCloneWrapperRef,
47
+ textAreaRef,
48
+ resizableDivRef,
49
+ minHeight,
50
+ });
55
51
  const trlOf = useTranslation('TextArea', 'of');
56
52
  const forceDisabled = useDisabled();
57
53
  const isComponentDisabled = forceDisabled || !!disabled;
@@ -101,7 +97,7 @@ const TextAreaComponent = ({ onChange, onFocus, onBlur, onValidate, value, place
101
97
  setFocusVisible(isFocused && textAreaRef.current.classList.contains('focus-visible'));
102
98
  }
103
99
  }, [isFocused]);
104
- const placeholderIsElevated = !!elevatePlaceholder && !!placeholder;
100
+ const placeholderIsElevated = !!elevatePlaceholder && !!placeholder && size === 'large';
105
101
  const showLabel = placeholderIsElevated || value === '';
106
102
  const invalidState = invalid || invalidLimit;
107
103
  const ariaProps = useInputAriaProps({
@@ -112,64 +108,37 @@ const TextAreaComponent = ({ onChange, onFocus, onBlur, onValidate, value, place
112
108
  labelId,
113
109
  });
114
110
  const hasElevatedPlaceholderClass = (isFocused || value !== '') && placeholderIsElevated;
115
- useEffect(() => {
116
- if (resizableDivRef.current !== null) {
117
- setMaxLengthDisplayed(!!maxLength && (!minHeight || resizableDivRef.current.offsetHeight >= MIN_HEIGHT_WITH_VISIBLE_LIMIT));
118
- }
119
- },
120
- // value нужен в зависимостях, чтобы проверять размер после ввода каждого символа
121
- [maxLength, minHeight, value]);
122
- const flexContainerRef = useRef(null);
123
- useEffect(() => {
124
- flexContainerRef.current = findFlexContainer(wrapperRef.current);
125
- }, [wrapperRef.current]); // eslint-disable-line disable-autofix/react-hooks/exhaustive-deps
126
- const recalcMaxAllowedHeight = useCallback(() => {
127
- if (bottomSheetContext !== null && resizableDivRef.current !== null && flexContainerRef.current !== null) {
128
- const lastFlexItem = flexContainerRef.current.childNodes[flexContainerRef.current.childNodes.length - 1];
129
- const takenFlexSpace = lastFlexItem.offsetTop + lastFlexItem.offsetHeight - resizableDivRef.current.offsetHeight;
130
- const availableFlexSpace = bottomSheetContext.visibleContentHeight - takenFlexSpace;
131
- setMaxAllowedHeight(bottomSheetContext.remainingAvailableHeight + availableFlexSpace);
132
- }
133
- }, [bottomSheetContext, setMaxAllowedHeight]);
134
- useEffect(() => {
135
- if (layout === 'hug' && bottomSheetContext !== null) {
136
- bottomSheetContext.subscribeToKeyboardResize(recalcMaxAllowedHeight);
137
- }
138
- }, [layout, bottomSheetContext, recalcMaxAllowedHeight]);
139
- useLayoutEffect(() => {
140
- if (layout === 'hug') {
141
- recalcMaxAllowedHeight();
142
- }
143
- },
144
- // value нужен в зависимостях, чтобы пересчитывать размер после ввода каждого символа
145
- [layout, recalcMaxAllowedHeight, value]);
146
- return (jsxs("div", { "data-qa": "textarea-wrapper", "data-interactive": true, className: classnames(styles.textarea, {
111
+ return (jsxs("div", { "data-qa": "textarea-wrapper", "data-interactive": true, className: classnames(styles.textarea, styles[`textarea-${size}`], {
147
112
  [styles.textareaFocused]: isFocused,
148
113
  [styles.textareaDisabled]: isComponentDisabled,
149
114
  [styles.textareaInvalid]: !!(invalidState || internalInvalid),
150
115
  [styles.textareaLimitError]: invalidLimit || internalInvalid || (maxLength ? value.length > maxLength : false),
151
- [styles.textareaLimited]: isMaxLengthDisplayed,
116
+ [styles.textareaLimited]: !!maxLength && maxedHeight,
152
117
  [styles.textareaLayoutFillBoth]: layout === 'fill-both',
153
118
  [styles.textareaLayoutFillVertical]: layout === 'fill-vertical',
154
119
  [styles.textareaLayoutFillHorizontal]: layout === 'fill-horizontal',
155
120
  [styles.textareaLayoutHug]: layout === 'hug',
156
121
  [styles.textareaElevated]: placeholderIsElevated,
157
- [styles[`minHeight${minHeight}`]]: actualMinHeight,
158
- [styles.minHeightDefault]: !minHeight,
159
- }), ref: wrapperRef, children: [jsxs("div", { className: classnames(styles.textareaPositionContainerWrapper, {
122
+ [styles.hasGrip]: isResizable,
123
+ [styles.maxedHeight]: size === 'large' && maxedHeight,
124
+ }), children: [jsxs("div", { className: classnames(styles.textareaPositionContainerWrapper, {
160
125
  'focus-visible': isFocusVisible,
161
- }), children: [jsxs("div", { className: classnames(styles.textareaPositionContainer), onClick: handleClick, onMouseDown: isResizable ? handleMouseDown : undefined, onMouseUp: isResizable ? handleMouseUp : undefined, style: {
162
- maxHeight: maxAllowedHeight !== null ? `${maxAllowedHeight}px` : undefined,
126
+ }), children: [jsx("div", { className: classnames(styles.textareaPositionContainer), onClick: handleClick, onMouseDown: isResizable ? handleMouseDown : undefined, onMouseUp: isResizable ? handleMouseUp : undefined, style: {
127
+ height: maxHeightRef.current || (maxedHeight ? 'auto' : minHeight),
128
+ minHeight,
129
+ '--magritte-textarea-max-height': maxHeight
130
+ ? `${Math.max(maxHeight, minHeight)}px`
131
+ : 'auto',
163
132
  resize: currentResizeValue,
164
- }, ref: resizableDivRef, children: [jsx("div", { className: styles.textareaWrapper, "data-qa": "textarea-native-wrapper", "data-replicated-value": layout === 'hug' && (bottomSheetContext === null || maxAllowedHeight !== null) ? value : '', children: jsx("textarea", { rows: actualMinHeight && 1, ...restProps, ...ariaProps, disabled: isComponentDisabled, suppressHydrationWarning: true, className: styles.nativeElement, value: value, onChange: onChange, onFocus: focusHandler, onBlur: blurHandler, ref: textAreaRefCallback }) }), showLabel && (jsx("div", { className: styles.textareaRiggingContainer, children: jsx("label", { className: classnames(styles.textareaLabel, {
165
- [styles.labelNoWrap]: elevatePlaceholder,
166
- [styles.textareaLabelElevated]: hasElevatedPlaceholderClass,
167
- }), id: ariaProps['aria-labelledby'], children: placeholder }) })), !!maxLength && isMaxLengthDisplayed && (jsx(CSSTransition, { in: isFocused || value.length > maxLength, timeout: animationTimeout, classNames: {
168
- enter: styles.textareaLimitEnter,
169
- enterActive: styles.textareaLimitEnterActive,
170
- exit: styles.textareaLimitExit,
171
- exitActive: styles.textareaLimitExitActive,
172
- }, unmountOnExit: true, nodeRef: limitRef, children: jsx("div", { className: styles.textareaLimit, ref: limitRef, children: jsxs(Text, { typography: "label-3-regular", children: [value.length, trlOf, maxLength] }) }) }))] }), currentResizeValue !== 'none' && (jsx("div", { className: styles.textareaGrip, children: jsx("div", { className: styles.textareaGripIcon, children: jsx(GripSize24, {}) }) }))] }), jsx(FormHelper, { description: description, errorMessage: errorMessage, descriptionId: ariaProps['aria-describedby'], disabled: isComponentDisabled, invalid: invalidState, "data-qa": "textarea-hint-container" })] }));
133
+ }, ref: resizableDivRef, children: jsxs("div", { className: styles.textareaWrapper, "data-qa": "textarea-native-wrapper", children: [jsx("textarea", { ...restProps, ...ariaProps, disabled: isComponentDisabled, suppressHydrationWarning: true, className: classnames(styles.nativeElement, styles.sidePadding), value: value, onChange: onChange, onFocus: focusHandler, onBlur: blurHandler, style: { overflowY: layout !== 'hug' || allowScrollRef.current ? 'auto' : 'hidden' }, ref: textAreaRefCallback }), layout === 'hug' && (jsx("div", { className: classnames(styles.valueCloneWrapper, styles.sidePadding), ref: contentCloneWrapperRef, children: jsx("pre", { className: styles.valueCloneContainer, ref: contentCloneRef, children: `${value}${ZERO_WIDTH_SPACE}` }) })), showLabel && (jsx("div", { className: classnames(styles.textareaRiggingContainer, styles.sidePadding), children: jsx("label", { className: classnames(styles.textareaLabel, {
134
+ [styles.labelNoWrap]: elevatePlaceholder,
135
+ [styles.textareaLabelElevated]: hasElevatedPlaceholderClass,
136
+ }), id: ariaProps['aria-labelledby'], children: placeholder }) }))] }) }), !!maxLength && maxedHeight && (jsx(CSSTransition, { in: isFocused || value.length > maxLength, timeout: animationTimeout, classNames: {
137
+ enter: styles.textareaLimitEnter,
138
+ enterActive: styles.textareaLimitEnterActive,
139
+ exit: styles.textareaLimitExit,
140
+ exitActive: styles.textareaLimitExitActive,
141
+ }, unmountOnExit: true, nodeRef: limitRef, children: jsx("div", { className: styles.textareaLimit, ref: limitRef, children: jsxs(Text, { typography: "label-3-regular", children: [value.length, trlOf, maxLength] }) }) })), isResizable && (jsx("div", { className: styles.textareaGrip, children: jsx("div", { className: styles.textareaGripIcon, children: jsx(GripSize24, {}) }) }))] }), jsx(FormHelper, { description: description, errorMessage: errorMessage, descriptionId: ariaProps['aria-describedby'], disabled: isComponentDisabled, invalid: invalidState, "data-qa": "textarea-hint-container" })] }));
173
142
  };
174
143
  const TextArea = forwardRef(TextAreaComponent);
175
144
  TextArea.displayName = 'TextArea';
package/TextArea.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.js","sources":["../src/TextArea.tsx"],"sourcesContent":["import { forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { useTranslation } from '@hh.ru/magritte-common-use-translation';\nimport { BottomSheetContext } from '@hh.ru/magritte-ui-bottom-sheet';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { FormHelper } from '@hh.ru/magritte-ui-form-helper';\nimport { GripSize24 } from '@hh.ru/magritte-ui-icon/private';\nimport { useInputAriaProps } from '@hh.ru/magritte-ui-input/useInputAriaProps';\nimport type { ControlledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';\nimport { useFocus } from '@hh.ru/magritte-ui-textarea/useFocus';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './textarea.less';\n\nconst MIN_HEIGHT_WITH_VISIBLE_LIMIT = 112;\n\nconst findFlexContainer = (element: HTMLElement | null): HTMLElement | null => {\n if (!element) {\n return null;\n }\n\n let parentElement = element.parentElement;\n while (parentElement !== null) {\n const { display } = window.getComputedStyle(parentElement);\n if (display.includes('flex')) {\n return parentElement;\n }\n parentElement = parentElement.parentElement;\n }\n\n return null;\n};\n\nconst TextAreaComponent = (\n {\n onChange,\n onFocus,\n onBlur,\n onValidate,\n value,\n placeholder,\n disabled = false,\n elevatePlaceholder = false,\n invalid = false,\n invalidLimit = false,\n maxLength,\n description,\n errorMessage,\n resize = 'none',\n layout = 'fixed',\n minHeight,\n ...restProps\n }: ControlledTextAreaProps & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, keyof ControlledTextAreaProps>,\n ref: React.ForwardedRef<HTMLTextAreaElement>\n) => {\n const { isMobile } = useBreakpoint();\n const [internalInvalid, setInternalInvalid] = useState(false);\n const [isFocusVisible, setFocusVisible] = useState(false);\n const limitRef = useRef<HTMLDivElement>(null);\n const previousInvalid = useRef(internalInvalid);\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n const resizableDivRef = useRef<HTMLDivElement>(null);\n const resizableDivSizes = useRef<{ width?: number; height?: number } | null>(null);\n const resizableDivWasResized = useRef(false);\n const textAreaRefCallback = useMultipleRefs(ref, textAreaRef);\n const descriptionId = useId();\n const labelId = useId();\n const [animationTimeout, setAnimationTimeout] = useState(100);\n const currentResizeValue = isMobile ? 'none' : resize;\n const isResizable = currentResizeValue !== 'none';\n const [isMaxLengthDisplayed, setMaxLengthDisplayed] = useState(!!maxLength && !minHeight);\n const actualMinHeight = minHeight !== undefined && !value.includes('\\n') ? minHeight : undefined;\n const [maxAllowedHeight, setMaxAllowedHeight] = useState<number | null>(null);\n const bottomSheetContext = useContext(BottomSheetContext);\n const wrapperRef = useRef(null);\n\n const trlOf = useTranslation('TextArea', 'of');\n\n const forceDisabled = useDisabled();\n const isComponentDisabled = forceDisabled || !!disabled;\n\n useEffect(() => {\n const animationTimeoutElement = document.createElement('div');\n animationTimeoutElement.classList.add(styles.textareaAnimationTimeout);\n document.body.appendChild(animationTimeoutElement);\n const style = window.getComputedStyle(animationTimeoutElement);\n const animationTimeout = parseInt(style.getPropertyValue(`--animation-duration`), 10);\n if (Number.isInteger(animationTimeout)) {\n setAnimationTimeout(animationTimeout);\n }\n document.body.removeChild(animationTimeoutElement);\n }, []);\n\n const { focusHandler, blurHandler, isFocused } = useFocus<HTMLTextAreaElement>(onFocus, onBlur);\n\n const handleClick = () => {\n if (resizableDivWasResized.current) {\n resizableDivWasResized.current = false;\n return;\n }\n textAreaRef.current?.focus();\n };\n\n const handleMouseUp = () => {\n if (\n resizableDivRef.current?.offsetWidth !== resizableDivSizes.current?.width ||\n resizableDivRef.current?.offsetHeight !== resizableDivSizes.current?.height\n ) {\n resizableDivWasResized.current = true;\n }\n };\n\n const handleMouseDown = () => {\n resizableDivSizes.current = {\n width: resizableDivRef.current?.offsetWidth,\n height: resizableDivRef.current?.offsetHeight,\n };\n };\n\n useEffect(() => {\n if (maxLength) {\n const invalid = !isFocused && value.length > maxLength;\n setInternalInvalid(invalid);\n\n if (previousInvalid.current !== invalid) {\n onValidate?.({ invalidLimit: invalid });\n }\n previousInvalid.current = invalid;\n }\n }, [onValidate, value, internalInvalid, maxLength, isFocused]);\n\n useEffect(() => {\n if (textAreaRef.current) {\n setFocusVisible(isFocused && textAreaRef.current.classList.contains('focus-visible'));\n }\n }, [isFocused]);\n\n const placeholderIsElevated = !!elevatePlaceholder && !!placeholder;\n const showLabel = placeholderIsElevated || value === '';\n\n const invalidState = invalid || invalidLimit;\n const ariaProps = useInputAriaProps({\n invalid: invalidState || internalInvalid,\n hasDescription: !!description,\n hasPlaceholder: !!placeholder,\n descriptionId,\n labelId,\n });\n\n const hasElevatedPlaceholderClass = (isFocused || value !== '') && placeholderIsElevated;\n\n useEffect(\n () => {\n if (resizableDivRef.current !== null) {\n setMaxLengthDisplayed(\n !!maxLength && (!minHeight || resizableDivRef.current.offsetHeight >= MIN_HEIGHT_WITH_VISIBLE_LIMIT)\n );\n }\n },\n // value нужен в зависимостях, чтобы проверять размер после ввода каждого символа\n [maxLength, minHeight, value]\n );\n\n const flexContainerRef = useRef<HTMLElement | null>(null);\n useEffect(() => {\n flexContainerRef.current = findFlexContainer(wrapperRef.current);\n }, [wrapperRef.current]); // eslint-disable-line disable-autofix/react-hooks/exhaustive-deps\n\n const recalcMaxAllowedHeight = useCallback(() => {\n if (bottomSheetContext !== null && resizableDivRef.current !== null && flexContainerRef.current !== null) {\n const lastFlexItem = flexContainerRef.current.childNodes[\n flexContainerRef.current.childNodes.length - 1\n ] as HTMLElement;\n const takenFlexSpace =\n lastFlexItem.offsetTop + lastFlexItem.offsetHeight - resizableDivRef.current.offsetHeight;\n const availableFlexSpace = bottomSheetContext.visibleContentHeight - takenFlexSpace;\n setMaxAllowedHeight(bottomSheetContext.remainingAvailableHeight + availableFlexSpace);\n }\n }, [bottomSheetContext, setMaxAllowedHeight]);\n\n useEffect(() => {\n if (layout === 'hug' && bottomSheetContext !== null) {\n bottomSheetContext.subscribeToKeyboardResize(recalcMaxAllowedHeight);\n }\n }, [layout, bottomSheetContext, recalcMaxAllowedHeight]);\n\n useLayoutEffect(\n () => {\n if (layout === 'hug') {\n recalcMaxAllowedHeight();\n }\n },\n // value нужен в зависимостях, чтобы пересчитывать размер после ввода каждого символа\n [layout, recalcMaxAllowedHeight, value]\n );\n\n return (\n <div\n data-qa=\"textarea-wrapper\"\n data-interactive={true}\n className={classnames(styles.textarea, {\n [styles.textareaFocused]: isFocused,\n [styles.textareaDisabled]: isComponentDisabled,\n [styles.textareaInvalid]: !!(invalidState || internalInvalid),\n [styles.textareaLimitError]:\n invalidLimit || internalInvalid || (maxLength ? value.length > maxLength : false),\n [styles.textareaLimited]: isMaxLengthDisplayed,\n [styles.textareaLayoutFillBoth]: layout === 'fill-both',\n [styles.textareaLayoutFillVertical]: layout === 'fill-vertical',\n [styles.textareaLayoutFillHorizontal]: layout === 'fill-horizontal',\n [styles.textareaLayoutHug]: layout === 'hug',\n [styles.textareaElevated]: placeholderIsElevated,\n [styles[`minHeight${minHeight}`]]: actualMinHeight,\n [styles.minHeightDefault]: !minHeight,\n })}\n ref={wrapperRef}\n >\n <div\n className={classnames(styles.textareaPositionContainerWrapper, {\n 'focus-visible': isFocusVisible,\n })}\n >\n <div\n className={classnames(styles.textareaPositionContainer)}\n onClick={handleClick}\n onMouseDown={isResizable ? handleMouseDown : undefined}\n onMouseUp={isResizable ? handleMouseUp : undefined}\n style={{\n maxHeight: maxAllowedHeight !== null ? `${maxAllowedHeight}px` : undefined,\n resize: currentResizeValue,\n }}\n ref={resizableDivRef}\n >\n <div\n className={styles.textareaWrapper}\n data-qa=\"textarea-native-wrapper\"\n data-replicated-value={\n layout === 'hug' && (bottomSheetContext === null || maxAllowedHeight !== null) ? value : ''\n }\n >\n <textarea\n rows={actualMinHeight && 1}\n {...restProps}\n {...ariaProps}\n disabled={isComponentDisabled}\n suppressHydrationWarning\n className={styles.nativeElement}\n value={value}\n onChange={onChange}\n onFocus={focusHandler}\n onBlur={blurHandler}\n ref={textAreaRefCallback}\n />\n </div>\n {showLabel && (\n <div className={styles.textareaRiggingContainer}>\n <label\n className={classnames(styles.textareaLabel, {\n [styles.labelNoWrap]: elevatePlaceholder,\n [styles.textareaLabelElevated]: hasElevatedPlaceholderClass,\n })}\n id={ariaProps['aria-labelledby']}\n >\n {placeholder}\n </label>\n </div>\n )}\n {!!maxLength && isMaxLengthDisplayed && (\n <CSSTransition\n in={isFocused || value.length > maxLength}\n timeout={animationTimeout}\n classNames={{\n enter: styles.textareaLimitEnter,\n enterActive: styles.textareaLimitEnterActive,\n exit: styles.textareaLimitExit,\n exitActive: styles.textareaLimitExitActive,\n }}\n unmountOnExit\n nodeRef={limitRef}\n >\n <div className={styles.textareaLimit} ref={limitRef}>\n <Text typography=\"label-3-regular\">\n {value.length}\n {trlOf}\n {maxLength}\n </Text>\n </div>\n </CSSTransition>\n )}\n </div>\n {currentResizeValue !== 'none' && (\n <div className={styles.textareaGrip}>\n <div className={styles.textareaGripIcon}>\n <GripSize24 />\n </div>\n </div>\n )}\n </div>\n <FormHelper\n description={description}\n errorMessage={errorMessage}\n descriptionId={ariaProps['aria-describedby']}\n disabled={isComponentDisabled}\n invalid={invalidState}\n data-qa=\"textarea-hint-container\"\n />\n </div>\n );\n};\n\nconst TextArea = forwardRef(TextAreaComponent);\n\nTextArea.displayName = 'TextArea';\n\nexport { TextArea };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAE1C,MAAM,iBAAiB,GAAG,CAAC,OAA2B,KAAwB;IAC1E,IAAI,CAAC,OAAO,EAAE;AACV,QAAA,OAAO,IAAI,CAAC;KACf;AAED,IAAA,IAAI,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC1C,IAAA,OAAO,aAAa,KAAK,IAAI,EAAE;QAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;AAC3D,QAAA,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;AAC1B,YAAA,OAAO,aAAa,CAAC;SACxB;AACD,QAAA,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC;KAC/C;AAED,IAAA,OAAO,IAAI,CAAC;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ffect,\n useId,\n useRef,\n useState,\n type TextareaHTMLAttributes,\n type ForwardedRef,\n type CSSProperties,\n} from 'react';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { useTranslation } from '@hh.ru/magritte-common-use-translation';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { FormHelper } from '@hh.ru/magritte-ui-form-helper';\nimport { GripSize24 } from '@hh.ru/magritte-ui-icon/private';\nimport { useInputAriaProps } from '@hh.ru/magritte-ui-input/useInputAriaProps';\nimport { type TextAreaLayout, type ControlledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';\nimport { useFocus } from '@hh.ru/magritte-ui-textarea/useFocus';\nimport { useLimitGrow } from '@hh.ru/magritte-ui-textarea/useLimitGrow';\nimport { useMinHeight } from '@hh.ru/magritte-ui-textarea/useMinHeight';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './textarea.less';\n\nconst ZERO_WIDTH_SPACE = '\\u200B';\n\nconst TextAreaComponent = <Layout extends TextAreaLayout>(\n {\n onChange,\n onFocus,\n onBlur,\n onValidate,\n value,\n placeholder,\n disabled = false,\n elevatePlaceholder = false,\n invalid = false,\n invalidLimit = false,\n maxLength,\n description,\n errorMessage,\n resize = 'none',\n layout = 'fixed' as Layout,\n size = 'large',\n minHeight: _minHeight,\n maxHeight,\n ...restProps\n }: ControlledTextAreaProps<Layout> &\n Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof ControlledTextAreaProps<'fixed'>>,\n ref: ForwardedRef<HTMLTextAreaElement>\n) => {\n const { isMobile } = useBreakpoint();\n const [internalInvalid, setInternalInvalid] = useState(false);\n const [isFocusVisible, setFocusVisible] = useState(false);\n const limitRef = useRef<HTMLDivElement>(null);\n const previousInvalid = useRef(internalInvalid);\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n const resizableDivRef = useRef<HTMLDivElement>(null);\n const resizableDivSizes = useRef<{ width?: number; height?: number } | null>(null);\n const resizableDivWasResized = useRef(false);\n const textAreaRefCallback = useMultipleRefs(ref, textAreaRef);\n const descriptionId = useId();\n const labelId = useId();\n const [animationTimeout, setAnimationTimeout] = useState(100);\n const currentResizeValue = isMobile ? 'none' : resize;\n const isResizable = currentResizeValue !== 'none';\n const contentCloneRef = useRef<HTMLPreElement>(null);\n const contentCloneWrapperRef = useRef<HTMLDivElement>(null);\n const { minHeight, maxedHeight } = useMinHeight(size, _minHeight, layout, contentCloneRef);\n const { maxHeightRef, allowScrollRef } = useLimitGrow({\n layout,\n contentCloneRef,\n contentCloneWrapperRef,\n textAreaRef,\n resizableDivRef,\n minHeight,\n });\n const trlOf = useTranslation('TextArea', 'of');\n\n const forceDisabled = useDisabled();\n const isComponentDisabled = forceDisabled || !!disabled;\n\n useEffect(() => {\n const animationTimeoutElement = document.createElement('div');\n animationTimeoutElement.classList.add(styles.textareaAnimationTimeout);\n document.body.appendChild(animationTimeoutElement);\n const style = window.getComputedStyle(animationTimeoutElement);\n const animationTimeout = parseInt(style.getPropertyValue(`--animation-duration`), 10);\n if (Number.isInteger(animationTimeout)) {\n setAnimationTimeout(animationTimeout);\n }\n document.body.removeChild(animationTimeoutElement);\n }, []);\n\n const { focusHandler, blurHandler, isFocused } = useFocus<HTMLTextAreaElement>(onFocus, onBlur);\n\n const handleClick = () => {\n if (resizableDivWasResized.current) {\n resizableDivWasResized.current = false;\n return;\n }\n textAreaRef.current?.focus();\n };\n\n const handleMouseUp = () => {\n if (\n resizableDivRef.current?.offsetWidth !== resizableDivSizes.current?.width ||\n resizableDivRef.current?.offsetHeight !== resizableDivSizes.current?.height\n ) {\n resizableDivWasResized.current = true;\n }\n };\n\n const handleMouseDown = () => {\n resizableDivSizes.current = {\n width: resizableDivRef.current?.offsetWidth,\n height: resizableDivRef.current?.offsetHeight,\n };\n };\n\n useEffect(() => {\n if (maxLength) {\n const invalid = !isFocused && value.length > maxLength;\n setInternalInvalid(invalid);\n\n if (previousInvalid.current !== invalid) {\n onValidate?.({ invalidLimit: invalid });\n }\n previousInvalid.current = invalid;\n }\n }, [onValidate, value, internalInvalid, maxLength, isFocused]);\n\n useEffect(() => {\n if (textAreaRef.current) {\n setFocusVisible(isFocused && textAreaRef.current.classList.contains('focus-visible'));\n }\n }, [isFocused]);\n\n const placeholderIsElevated = !!elevatePlaceholder && !!placeholder && size === 'large';\n const showLabel = placeholderIsElevated || value === '';\n\n const invalidState = invalid || invalidLimit;\n const ariaProps = useInputAriaProps({\n invalid: invalidState || internalInvalid,\n hasDescription: !!description,\n hasPlaceholder: !!placeholder,\n descriptionId,\n labelId,\n });\n\n const hasElevatedPlaceholderClass = (isFocused || value !== '') && placeholderIsElevated;\n\n return (\n <div\n data-qa=\"textarea-wrapper\"\n data-interactive={true}\n className={classnames(styles.textarea, styles[`textarea-${size}`], {\n [styles.textareaFocused]: isFocused,\n [styles.textareaDisabled]: isComponentDisabled,\n [styles.textareaInvalid]: !!(invalidState || internalInvalid),\n [styles.textareaLimitError]:\n invalidLimit || internalInvalid || (maxLength ? value.length > maxLength : false),\n [styles.textareaLimited]: !!maxLength && maxedHeight,\n [styles.textareaLayoutFillBoth]: layout === 'fill-both',\n [styles.textareaLayoutFillVertical]: layout === 'fill-vertical',\n [styles.textareaLayoutFillHorizontal]: layout === 'fill-horizontal',\n [styles.textareaLayoutHug]: layout === 'hug',\n [styles.textareaElevated]: placeholderIsElevated,\n [styles.hasGrip]: isResizable,\n [styles.maxedHeight]: size === 'large' && maxedHeight,\n })}\n >\n <div\n className={classnames(styles.textareaPositionContainerWrapper, {\n 'focus-visible': isFocusVisible,\n })}\n >\n <div\n className={classnames(styles.textareaPositionContainer)}\n onClick={handleClick}\n onMouseDown={isResizable ? handleMouseDown : undefined}\n onMouseUp={isResizable ? handleMouseUp : undefined}\n style={\n {\n height: maxHeightRef.current || (maxedHeight ? 'auto' : minHeight),\n minHeight,\n '--magritte-textarea-max-height': maxHeight\n ? `${Math.max(maxHeight, minHeight)}px`\n : 'auto',\n resize: currentResizeValue,\n } as CSSProperties\n }\n ref={resizableDivRef}\n >\n <div className={styles.textareaWrapper} data-qa=\"textarea-native-wrapper\">\n <textarea\n {...restProps}\n {...ariaProps}\n disabled={isComponentDisabled}\n suppressHydrationWarning\n className={classnames(styles.nativeElement, styles.sidePadding)}\n value={value}\n onChange={onChange}\n onFocus={focusHandler}\n onBlur={blurHandler}\n style={{ overflowY: layout !== 'hug' || allowScrollRef.current ? 'auto' : 'hidden' }}\n ref={textAreaRefCallback}\n />\n {layout === 'hug' && (\n <div\n className={classnames(styles.valueCloneWrapper, styles.sidePadding)}\n ref={contentCloneWrapperRef}\n >\n <pre className={styles.valueCloneContainer} ref={contentCloneRef}>\n {`${value}${ZERO_WIDTH_SPACE}`}\n </pre>\n </div>\n )}\n {showLabel && (\n <div className={classnames(styles.textareaRiggingContainer, styles.sidePadding)}>\n <label\n className={classnames(styles.textareaLabel, {\n [styles.labelNoWrap]: elevatePlaceholder,\n [styles.textareaLabelElevated]: hasElevatedPlaceholderClass,\n })}\n id={ariaProps['aria-labelledby']}\n >\n {placeholder}\n </label>\n </div>\n )}\n </div>\n </div>\n {!!maxLength && maxedHeight && (\n <CSSTransition\n in={isFocused || value.length > maxLength}\n timeout={animationTimeout}\n classNames={{\n enter: styles.textareaLimitEnter,\n enterActive: styles.textareaLimitEnterActive,\n exit: styles.textareaLimitExit,\n exitActive: styles.textareaLimitExitActive,\n }}\n unmountOnExit\n nodeRef={limitRef}\n >\n <div className={styles.textareaLimit} ref={limitRef}>\n <Text typography=\"label-3-regular\">\n {value.length}\n {trlOf}\n {maxLength}\n </Text>\n </div>\n </CSSTransition>\n )}\n {isResizable && (\n <div className={styles.textareaGrip}>\n <div className={styles.textareaGripIcon}>\n <GripSize24 />\n </div>\n </div>\n )}\n </div>\n <FormHelper\n description={description}\n errorMessage={errorMessage}\n descriptionId={ariaProps['aria-describedby']}\n disabled={isComponentDisabled}\n invalid={invalidState}\n data-qa=\"textarea-hint-container\"\n />\n </div>\n );\n};\n\nconst TextArea = forwardRef(TextAreaComponent) as (<Layout extends TextAreaLayout>(\n props: ControlledTextAreaProps<Layout> &\n Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, keyof ControlledTextAreaProps<'fixed'>> & {\n ref?: React.ForwardedRef<HTMLTextAreaElement>;\n }\n) => ReactElement | null) & { displayName: string };\n\nTextArea.displayName = 'TextArea';\n\nexport { TextArea };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,MAAM,iBAAiB,GAAG,CACtB,EACI,QAAQ,EACR,OAAO,EACP,MAAM,EACN,UAAU,EACV,KAAK,EACL,WAAW,EACX,QAAQ,GAAG,KAAK,EAChB,kBAAkB,GAAG,KAAK,EAC1B,OAAO,GAAG,KAAK,EACf,YAAY,GAAG,KAAK,EACpB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,MAAM,GAAG,MAAM,EACf,MAAM,GAAG,OAAiB,EAC1B,IAAI,GAAG,OAAO,EACd,SAAS,EAAE,UAAU,EACrB,SAAS,EACT,GAAG,SAAS,EAE6E,EAC7F,GAAsC,KACtC;AACA,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IACrC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9D,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1D,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AAC9C,IAAA,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAChD,IAAA,MAAM,WAAW,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;AACtD,IAAA,MAAM,eAAe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,YAC/BA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,gBAAgB,EACnC,QAAA,EAAAA,GAAA,CAAC,UAAU,EAAG,EAAA,CAAA,EAAA,CACZ,GACJ,CACT,CAAA,EAAA,CACC,EACNA,GAAC,CAAA,UAAU,IACP,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,SAAS,CAAC,kBAAkB,CAAC,EAC5C,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,YAAY,EAAA,SAAA,EACb,yBAAyB,EACnC,CAAA,CAAA,EAAA,CACA,EACR;AACN,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,UAAU,CAAC,iBAAiB,EAKO;AAEpD,QAAQ,CAAC,WAAW,GAAG,UAAU;;;;"}
@@ -0,0 +1,18 @@
1
+ export interface GrowLimiterContextValue {
2
+ getHeightDiff: () => number;
3
+ onHeightChange: (callback: VoidFunction) => void;
4
+ offHeightChange: (callback: VoidFunction) => void;
5
+ heightUpdated: VoidFunction;
6
+ hasLimit: boolean;
7
+ }
8
+ export declare const GrowLimiterContext: import("react").Context<GrowLimiterContextValue>;
9
+ export declare const TextAreaGrowLimiter: import("react").ForwardRefExoticComponent<{
10
+ containerRef?: import("react").RefObject<HTMLElement>;
11
+ debounce?: boolean;
12
+ preMeasurement?: VoidFunction;
13
+ postMeasurement?: VoidFunction;
14
+ style?: import("react").HTMLAttributes<HTMLDivElement>["style"];
15
+ className?: import("react").HTMLAttributes<HTMLDivElement>["className"];
16
+ } & {
17
+ children?: import("react").ReactNode | undefined;
18
+ } & import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,80 @@
1
+ import './index.css';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { createContext, forwardRef, useRef, useState, useMemo, useEffect } from 'react';
4
+ import { debounce } from '@hh.ru/magritte-common-func-utils';
5
+ import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
6
+
7
+ const GrowLimiterContext = createContext({
8
+ getHeightDiff: () => 0,
9
+ onHeightChange: () => void 0,
10
+ offHeightChange: () => void 0,
11
+ heightUpdated: () => void 0,
12
+ hasLimit: false,
13
+ });
14
+ const TextAreaGrowLimiter = forwardRef(({ children, containerRef, preMeasurement, postMeasurement, debounce: debounce$1 = false, ...rest }, ref) => {
15
+ const wrapperRef = useRef(null);
16
+ const refMultiplexer = useMultipleRefs(ref, wrapperRef);
17
+ const [heightChangeHandlers, _] = useState(() => new Set());
18
+ const heightDiffCache = useRef(null);
19
+ const contextValue = useMemo(() => ({
20
+ getHeightDiff: () => {
21
+ if (heightDiffCache.current === null) {
22
+ const currentContainer = containerRef?.current || wrapperRef?.current?.parentElement;
23
+ if (!wrapperRef.current || !currentContainer) {
24
+ return 0;
25
+ }
26
+ // запоминаем позицию скролла в контейнере, отключаем скролл, вызываем preMeasurement если задан
27
+ // в BottomSheet например он отключает ограничение height на внешнем контейнере, чтобы была
28
+ // возможность узнать реальный максимальный размер контейнера
29
+ const scrollTop = currentContainer.scrollTop;
30
+ const overflow = currentContainer.style.overflowY;
31
+ currentContainer.style.overflowY = 'hidden';
32
+ preMeasurement?.();
33
+ // Устанавливаем толщину нижней рамки равно 20000 пикселей, чтобы размер обертки гарантированно
34
+ // превысил размер контейнера. После этого сравниваем offsetHeight и scrollHeight контейнера
35
+ // чтобы вычислить сколько доступно свободного пространства до появления в контейнере скролла
36
+ wrapperRef.current.style.borderBottomWidth = '20000px';
37
+ heightDiffCache.current = currentContainer.clientHeight - currentContainer.scrollHeight + 20000;
38
+ // Вызываем postMeasurement если задан, в BottomSheet он возвращает ограничение height к
39
+ // изначальному значению
40
+ postMeasurement?.();
41
+ // Возвращаем настройки контейнера и обретки к изначальным значениям
42
+ currentContainer.style.overflowY = overflow;
43
+ wrapperRef.current.style.borderBottomWidth = '0';
44
+ currentContainer.scrollTop = scrollTop;
45
+ }
46
+ return heightDiffCache.current;
47
+ },
48
+ onHeightChange: (callback) => heightChangeHandlers.add(callback),
49
+ offHeightChange: (callback) => heightChangeHandlers.delete(callback),
50
+ heightUpdated: () => (heightDiffCache.current = null),
51
+ hasLimit: true,
52
+ }), [heightChangeHandlers, containerRef, wrapperRef, preMeasurement, postMeasurement]);
53
+ useEffect(() => {
54
+ const currentContainer = containerRef?.current || wrapperRef?.current?.parentElement;
55
+ if (!wrapperRef.current || !currentContainer) {
56
+ return void 0;
57
+ }
58
+ const observerCallback = () => {
59
+ heightDiffCache.current = null;
60
+ heightChangeHandlers.forEach((callback) => callback());
61
+ };
62
+ const observer = new ResizeObserver(debounce$1 ? debounce(observerCallback, 17 /* ~= 1000ms / 60fps */) : observerCallback);
63
+ observer.observe(wrapperRef.current, { box: 'content-box' });
64
+ observer.observe(currentContainer, { box: 'content-box' });
65
+ return () => observer.disconnect();
66
+ },
67
+ // eslint считает что containerRef?.current лишняя зависимость, но эффект должен реагировать если
68
+ // значение в рефе изменилось, т.к. обзервер должен переподписаться на другой элемент
69
+ // eslint-disable-next-line disable-autofix/react-hooks/exhaustive-deps
70
+ [heightChangeHandlers, containerRef, containerRef?.current, wrapperRef]);
71
+ return (jsx("div", { ref: refMultiplexer, ...rest, style: {
72
+ ...(rest.style || {}),
73
+ borderBottomStyle: 'solid',
74
+ borderBottomColor: 'transparent',
75
+ }, children: jsx(GrowLimiterContext.Provider, { value: contextValue, children: children }) }));
76
+ });
77
+ TextAreaGrowLimiter.displayName = 'TextAreaGrowLimiter';
78
+
79
+ export { GrowLimiterContext, TextAreaGrowLimiter };
80
+ //# sourceMappingURL=TextAreaGrowLimiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextAreaGrowLimiter.js","sources":["../src/TextAreaGrowLimiter.tsx"],"sourcesContent":["import { createContext, useRef, forwardRef, useEffect, useState, useMemo } from 'react';\n\nimport { debounce as debounceFunc } from '@hh.ru/magritte-common-func-utils';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport type { TextAreaGrowLimiterProps } from '@hh.ru/magritte-ui-textarea/types';\n\nexport interface GrowLimiterContextValue {\n getHeightDiff: () => number;\n onHeightChange: (callback: VoidFunction) => void;\n offHeightChange: (callback: VoidFunction) => void;\n heightUpdated: VoidFunction;\n hasLimit: boolean;\n}\n\nexport const GrowLimiterContext = createContext<GrowLimiterContextValue>({\n getHeightDiff: () => 0,\n onHeightChange: () => void 0,\n offHeightChange: () => void 0,\n heightUpdated: () => void 0,\n hasLimit: false,\n});\n\nexport const TextAreaGrowLimiter = forwardRef<HTMLDivElement, TextAreaGrowLimiterProps>(\n ({ children, containerRef, preMeasurement, postMeasurement, debounce = false, ...rest }, ref) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const refMultiplexer = useMultipleRefs(ref, wrapperRef);\n const [heightChangeHandlers, _] = useState(() => new Set<VoidFunction>());\n const heightDiffCache = useRef<number | null>(null);\n\n const contextValue = useMemo<GrowLimiterContextValue>(\n () => ({\n getHeightDiff: () => {\n if (heightDiffCache.current === null) {\n const currentContainer = containerRef?.current || wrapperRef?.current?.parentElement;\n\n if (!wrapperRef.current || !currentContainer) {\n return 0;\n }\n\n // запоминаем позицию скролла в контейнере, отключаем скролл, вызываем preMeasurement если задан\n // в BottomSheet например он отключает ограничение height на внешнем контейнере, чтобы была\n // возможность узнать реальный максимальный размер контейнера\n const scrollTop = currentContainer.scrollTop;\n const overflow = currentContainer.style.overflowY;\n currentContainer.style.overflowY = 'hidden';\n preMeasurement?.();\n\n // Устанавливаем толщину нижней рамки равно 20000 пикселей, чтобы размер обертки гарантированно\n // превысил размер контейнера. После этого сравниваем offsetHeight и scrollHeight контейнера\n // чтобы вычислить сколько доступно свободного пространства до появления в контейнере скролла\n wrapperRef.current.style.borderBottomWidth = '20000px';\n heightDiffCache.current = currentContainer.clientHeight - currentContainer.scrollHeight + 20000;\n // Вызываем postMeasurement если задан, в BottomSheet он возвращает ограничение height к\n // изначальному значению\n postMeasurement?.();\n\n // Возвращаем настройки контейнера и обретки к изначальным значениям\n currentContainer.style.overflowY = overflow;\n wrapperRef.current.style.borderBottomWidth = '0';\n currentContainer.scrollTop = scrollTop;\n }\n return heightDiffCache.current;\n },\n onHeightChange: (callback) => heightChangeHandlers.add(callback),\n offHeightChange: (callback) => heightChangeHandlers.delete(callback),\n heightUpdated: () => (heightDiffCache.current = null),\n hasLimit: true,\n }),\n [heightChangeHandlers, containerRef, wrapperRef, preMeasurement, postMeasurement]\n );\n\n useEffect(\n () => {\n const currentContainer = containerRef?.current || wrapperRef?.current?.parentElement;\n\n if (!wrapperRef.current || !currentContainer) {\n return void 0;\n }\n\n const observerCallback = () => {\n heightDiffCache.current = null;\n heightChangeHandlers.forEach((callback) => callback());\n };\n\n const observer = new ResizeObserver(\n debounce ? debounceFunc(observerCallback, 17 /* ~= 1000ms / 60fps */) : observerCallback\n );\n observer.observe(wrapperRef.current, { box: 'content-box' });\n observer.observe(currentContainer, { box: 'content-box' });\n\n return () => observer.disconnect();\n },\n // eslint считает что containerRef?.current лишняя зависимость, но эффект должен реагировать если\n // значение в рефе изменилось, т.к. обзервер должен переподписаться на другой элемент\n // eslint-disable-next-line disable-autofix/react-hooks/exhaustive-deps\n [heightChangeHandlers, containerRef, containerRef?.current, wrapperRef]\n );\n\n return (\n <div\n ref={refMultiplexer}\n {...rest}\n style={{\n ...(rest.style || {}),\n borderBottomStyle: 'solid',\n borderBottomColor: 'transparent',\n }}\n >\n <GrowLimiterContext.Provider value={contextValue}>{children}</GrowLimiterContext.Provider>\n </div>\n );\n }\n);\n\nTextAreaGrowLimiter.displayName = 'TextAreaGrowLimiter';\n"],"names":["debounce","debounceFunc","_jsx"],"mappings":";;;;;AAcO,MAAM,kBAAkB,GAAG,aAAa,CAA0B;AACrE,IAAA,aAAa,EAAE,MAAM,CAAC;AACtB,IAAA,cAAc,EAAE,MAAM,KAAK,CAAC;AAC5B,IAAA,eAAe,EAAE,MAAM,KAAK,CAAC;AAC7B,IAAA,aAAa,EAAE,MAAM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CAAC,CAAC;QAC7D,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;AAE3D,QAAA,OAAO,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;KACtC;;;;IAID,CAAC,oBAAoB,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC,CAC1E,CAAC;IAEF,QACIC,aACI,GAAG,EAAE,cAAc,EACf,GAAA,IAAI,EACR,KAAK,EAAE;AACH,YAAA,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE;AACpB,YAAA,iBAAiB,EAAE,OAAO;AAC1B,YAAA,iBAAiB,EAAE,aAAa;AACnC,SAAA,EAAA,QAAA,EAEDA,GAAC,CAAA,kBAAkB,CAAC,QAAQ,EAAC,EAAA,KAAK,EAAE,YAAY,EAAG,QAAA,EAAA,QAAQ,EAA+B,CAAA,EAAA,CACxF,EACR;AACN,CAAC,EACH;AAEF,mBAAmB,CAAC,WAAW,GAAG,qBAAqB;;;;"}
@@ -1,3 +1,7 @@
1
- import { TextareaHTMLAttributes } from 'react';
2
- import { UncontrolledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';
3
- export declare const UncontrolledTextArea: import("react").ForwardRefExoticComponent<(UncontrolledTextAreaProps & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "placeholder" | "onFocus" | "onBlur" | "description" | "errorMessage" | "disabled" | "invalid" | "invalidLimit" | "elevatePlaceholder" | "onChange" | "value" | "maxLength" | "onValidate" | "layout" | "minHeight" | "resize">) & import("react").RefAttributes<HTMLTextAreaElement>>;
1
+ import { type ReactElement } from 'react';
2
+ import type { TextAreaLayout, UncontrolledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';
3
+ export declare const UncontrolledTextArea: (<Layout extends TextAreaLayout>(props: UncontrolledTextAreaProps<Layout> & Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, keyof UncontrolledTextAreaProps<"fixed">> & {
4
+ ref?: React.ForwardedRef<HTMLTextAreaElement>;
5
+ }) => ReactElement | null) & {
6
+ displayName: string;
7
+ };
@@ -7,22 +7,27 @@ import 'classnames';
7
7
  import '@hh.ru/magritte-common-use-disabled';
8
8
  import '@hh.ru/magritte-common-use-multiple-refs';
9
9
  import '@hh.ru/magritte-common-use-translation';
10
- import '@hh.ru/magritte-ui-bottom-sheet';
11
10
  import '@hh.ru/magritte-ui-breakpoint';
12
11
  import '@hh.ru/magritte-ui-form-helper';
13
12
  import '@hh.ru/magritte-ui-icon/private';
14
13
  import '@hh.ru/magritte-ui-input/useInputAriaProps';
15
14
  import './useFocus.js';
15
+ import './useLimitGrow.js';
16
+ import './TextAreaGrowLimiter.js';
17
+ import '@hh.ru/magritte-common-func-utils';
18
+ import './useMinHeight.js';
19
+ import './types.js';
16
20
  import '@hh.ru/magritte-ui-typography';
17
21
 
18
- const UncontrolledTextArea = forwardRef(({ value = '', onChange, ...restProps }, ref) => {
22
+ const UncontrolledTextAreaComponent = ({ value = '', onChange, ...restProps }, ref) => {
19
23
  const [defaultValue, setDefaultValue] = useState(value);
20
24
  const changeHandler = useCallback((event) => {
21
25
  setDefaultValue(event.target.value);
22
26
  onChange?.(event);
23
27
  }, [onChange]);
24
28
  return jsx(TextArea, { ...restProps, value: defaultValue, onChange: changeHandler, ref: ref });
25
- });
29
+ };
30
+ const UncontrolledTextArea = forwardRef(UncontrolledTextAreaComponent);
26
31
  UncontrolledTextArea.displayName = 'UncontrolledTextArea';
27
32
 
28
33
  export { UncontrolledTextArea };
@@ -1 +1 @@
1
- {"version":3,"file":"UncontrolledTextArea.js","sources":["../src/UncontrolledTextArea.tsx"],"sourcesContent":["import { forwardRef, TextareaHTMLAttributes, useCallback, useState, type ChangeEvent } from 'react';\n\nimport { TextArea } from '@hh.ru/magritte-ui-textarea/TextArea';\nimport { UncontrolledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';\n\nexport const UncontrolledTextArea = forwardRef<\n HTMLTextAreaElement,\n UncontrolledTextAreaProps & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof UncontrolledTextAreaProps>\n>(({ value = '', onChange, ...restProps }, ref) => {\n const [defaultValue, setDefaultValue] = useState(value);\n const changeHandler = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n setDefaultValue(event.target.value);\n onChange?.(event);\n },\n [onChange]\n );\n\n return <TextArea {...restProps} value={defaultValue} onChange={changeHandler} ref={ref} />;\n});\n\nUncontrolledTextArea.displayName = 'UncontrolledTextArea';\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;MAKa,oBAAoB,GAAG,UAAU,CAG5C,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG,KAAI;IAC9C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxD,IAAA,MAAM,aAAa,GAAG,WAAW,CAC7B,CAAC,KAAuC,KAAI;AACxC,QAAA,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpC,QAAA,QAAQ,GAAG,KAAK,CAAC,CAAC;AACtB,KAAC,EACD,CAAC,QAAQ,CAAC,CACb,CAAC;AAEF,IAAA,OAAOA,IAAC,QAAQ,EAAA,EAAA,GAAK,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;AAC/F,CAAC,EAAE;AAEH,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;;;"}
1
+ {"version":3,"file":"UncontrolledTextArea.js","sources":["../src/UncontrolledTextArea.tsx"],"sourcesContent":["import { forwardRef, type ReactElement, useCallback, useState, type ChangeEvent } from 'react';\n\nimport { TextArea } from '@hh.ru/magritte-ui-textarea/TextArea';\nimport type { TextAreaLayout, UncontrolledTextAreaProps } from '@hh.ru/magritte-ui-textarea/types';\n\nconst UncontrolledTextAreaComponent = <Layout extends TextAreaLayout>(\n { value = '', onChange, ...restProps }: UncontrolledTextAreaProps<Layout>,\n ref: React.ForwardedRef<HTMLTextAreaElement>\n) => {\n const [defaultValue, setDefaultValue] = useState(value);\n const changeHandler = useCallback(\n (event: ChangeEvent<HTMLTextAreaElement>) => {\n setDefaultValue(event.target.value);\n onChange?.(event);\n },\n [onChange]\n );\n\n return <TextArea {...restProps} value={defaultValue} onChange={changeHandler} ref={ref} />;\n};\n\nexport const UncontrolledTextArea = forwardRef(UncontrolledTextAreaComponent) as (<Layout extends TextAreaLayout>(\n props: UncontrolledTextAreaProps<Layout> &\n Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, keyof UncontrolledTextAreaProps<'fixed'>> & {\n ref?: React.ForwardedRef<HTMLTextAreaElement>;\n }\n) => ReactElement | null) & { displayName: string };\nUncontrolledTextArea.displayName = 'UncontrolledTextArea';\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;AAKA,MAAM,6BAA6B,GAAG,CAClC,EAAE,KAAK,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAqC,EACzE,GAA4C,KAC5C;IACA,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxD,IAAA,MAAM,aAAa,GAAG,WAAW,CAC7B,CAAC,KAAuC,KAAI;AACxC,QAAA,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpC,QAAA,QAAQ,GAAG,KAAK,CAAC,CAAC;AACtB,KAAC,EACD,CAAC,QAAQ,CAAC,CACb,CAAC;AAEF,IAAA,OAAOA,IAAC,QAAQ,EAAA,EAAA,GAAK,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC;AAC/F,CAAC,CAAC;MAEW,oBAAoB,GAAG,UAAU,CAAC,6BAA6B,EAKxB;AACpD,oBAAoB,CAAC,WAAW,GAAG,sBAAsB;;;;"}