@semcore/ellipsis 1.1.8 → 1.1.9

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
@@ -2,19 +2,17 @@
2
2
 
3
3
  CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
- ## [1.1.8] - 2023-01-20
6
-
7
- ### Changed
5
+ ## [1.1.9] - 2023-01-24
8
6
 
9
- - Version patch update due to children dependencies update (`@semcore/utils` [3.45.0 ~> 3.46.0]).
7
+ ### Fixed
10
8
 
11
- ## [1.1.6] - 2023-01-10
9
+ - Stopped showing tooltip if text is not truncated.
12
10
 
13
- ## [1.1.5] - 2023-01-09
11
+ ## [1.1.8] - 2023-01-20
14
12
 
15
13
  ### Changed
16
14
 
17
- - Version patch update due to children dependencies update (`@semcore/utils` [3.44.1 ~> 3.44.2]).
15
+ - Version patch update due to children dependencies update (`@semcore/utils` [3.45.0 ~> 3.46.0]).
18
16
 
19
17
  ## [1.1.4] - 2023-01-03
20
18
 
@@ -15,6 +15,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
15
15
 
16
16
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
17
 
18
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
+
18
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
21
 
20
22
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -50,31 +52,96 @@ var style = (
50
52
  /*__reshadow_css_start__*/
51
53
  _core.sstyled.insert(
52
54
  /*__inner_css_start__*/
53
- ".___SContainer_14o7y_gg_,.___SContainerMiddle_14o7y_gg_{display:flex;overflow:hidden}.___SBeginning_14o7y_gg_,.___SEllipsis_14o7y_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_14o7y_gg_.__maxLine_14o7y_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_14o7y);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_14o7y_gg_{white-space:nowrap}"
55
+ ".___SContainer_12kp5_gg_,.___SContainerMiddle_12kp5_gg_{display:flex;overflow:hidden}.___SBeginning_12kp5_gg_,.___SEllipsis_12kp5_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_12kp5_gg_.__maxLine_12kp5_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_12kp5);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_12kp5_gg_{white-space:nowrap}"
54
56
  /*__inner_css_end__*/
55
- , "14o7y_gg_")
57
+ , "12kp5_gg_")
56
58
  /*__reshadow_css_end__*/
57
59
  , {
58
- "__SContainer": "___SContainer_14o7y_gg_",
59
- "__SContainerMiddle": "___SContainerMiddle_14o7y_gg_",
60
- "__SBeginning": "___SBeginning_14o7y_gg_",
61
- "__SEllipsis": "___SEllipsis_14o7y_gg_",
62
- "_maxLine": "__maxLine_14o7y_gg_",
63
- "--maxLine": "--maxLine_14o7y",
64
- "__STail": "___STail_14o7y_gg_"
60
+ "__SContainer": "___SContainer_12kp5_gg_",
61
+ "__SContainerMiddle": "___SContainerMiddle_12kp5_gg_",
62
+ "__SBeginning": "___SBeginning_12kp5_gg_",
63
+ "__SEllipsis": "___SEllipsis_12kp5_gg_",
64
+ "_maxLine": "__maxLine_12kp5_gg_",
65
+ "--maxLine": "--maxLine_12kp5",
66
+ "__STail": "___STail_12kp5_gg_"
65
67
  });
66
68
 
69
+ var createMeasurerElement = function createMeasurerElement(element) {
70
+ var styleElement = window.getComputedStyle(element, null);
71
+ var temporaryElement = document.createElement('temporary-block');
72
+ temporaryElement.style.display = 'inline-block';
73
+ temporaryElement.style.padding = '0';
74
+ temporaryElement.style.position = 'absolute';
75
+ temporaryElement.style.right = '150%';
76
+ temporaryElement.style.bottom = '150%';
77
+ temporaryElement.style.visibility = 'hidden';
78
+ temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');
79
+ temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');
80
+ temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');
81
+ temporaryElement.innerHTML = element.innerHTML;
82
+ return temporaryElement;
83
+ };
84
+
85
+ function isTextOverflowing(element, multiline) {
86
+ if (!element) return false;
87
+
88
+ var _element$getBoundingC = element.getBoundingClientRect(),
89
+ currentHeight = _element$getBoundingC.height,
90
+ currentWidth = _element$getBoundingC.width;
91
+
92
+ var measuringElement = createMeasurerElement(element);
93
+ var currentSize, initialSize;
94
+ document.body.appendChild(measuringElement);
95
+
96
+ if (multiline) {
97
+ currentSize = currentHeight;
98
+ measuringElement.style.width = "".concat(currentWidth, "px");
99
+ initialSize = measuringElement.getBoundingClientRect().height;
100
+ } else {
101
+ currentSize = currentWidth;
102
+ measuringElement.style.whiteSpace = 'nowrap';
103
+ initialSize = measuringElement.getBoundingClientRect().width;
104
+ }
105
+
106
+ document.body.removeChild(measuringElement);
107
+ return currentSize < initialSize;
108
+ }
109
+
67
110
  var RootEllipsis = /*#__PURE__*/function (_Component) {
68
111
  (0, _inherits2["default"])(RootEllipsis, _Component);
69
112
 
70
113
  var _super = _createSuper(RootEllipsis);
71
114
 
72
115
  function RootEllipsis() {
116
+ var _this;
117
+
73
118
  (0, _classCallCheck2["default"])(this, RootEllipsis);
74
- return _super.apply(this, arguments);
119
+
120
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
121
+ args[_key] = arguments[_key];
122
+ }
123
+
124
+ _this = _super.call.apply(_super, [this].concat(args));
125
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
126
+ visible: false
127
+ });
128
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "textRef", /*#__PURE__*/_react["default"].createRef());
129
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handlerVisibleChange", function (visible) {
130
+ _this.setState({
131
+ visible: visible && _this.showTooltip()
132
+ });
133
+ });
134
+ return _this;
75
135
  }
76
136
 
77
137
  (0, _createClass2["default"])(RootEllipsis, [{
138
+ key: "showTooltip",
139
+ value: function showTooltip() {
140
+ var _this$asProps$maxLine = this.asProps.maxLine,
141
+ maxLine = _this$asProps$maxLine === void 0 ? 1 : _this$asProps$maxLine;
142
+ return isTextOverflowing(this.textRef.current, maxLine > 1);
143
+ }
144
+ }, {
78
145
  key: "render",
79
146
  value: function render() {
80
147
  var _ref3;
@@ -89,6 +156,7 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
89
156
  trim = _this$asProps.trim,
90
157
  containerRect = _this$asProps.containerRect,
91
158
  containerRef = _this$asProps.containerRef;
159
+ var visible = this.state.visible;
92
160
  var text = (0, _reactToText["default"])((0, _getOriginChildren["default"])(Children));
93
161
 
94
162
  if (trim === 'middle') {
@@ -107,10 +175,13 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
107
175
  var _ref2;
108
176
 
109
177
  return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainer, _ref2.cn("SContainer", {
110
- "interaction": "hover",
111
- "title": text
178
+ "interaction": 'hover',
179
+ "title": text,
180
+ "visible": visible,
181
+ "onVisibleChange": this.handlerVisibleChange
112
182
  }), /*#__PURE__*/_react["default"].createElement(SEllipsis, _ref2.cn("SEllipsis", {
113
183
  "render": _flexBox.Box,
184
+ "ref": this.textRef,
114
185
  "maxLine": maxLine
115
186
  }), /*#__PURE__*/_react["default"].createElement(Children, _ref2.cn("Children", {}))));
116
187
  }
@@ -156,12 +227,12 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
156
227
  dateSpan.innerHTML = 'a';
157
228
  document.body.appendChild(dateSpan);
158
229
  var rect = dateSpan.getBoundingClientRect();
159
- dateSpan.remove();
160
230
  setDimension({
161
231
  fontSize: window // @ts-ignore
162
232
  .getComputedStyle((_containerRef$current = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : resizeElement.current, null).getPropertyValue('font-size'),
163
233
  symbolWidth: rect.width
164
234
  });
235
+ document.body.removeChild(dateSpan);
165
236
  }, []);
166
237
  var STail = 'span';
167
238
  var SBeginning = 'span';
@@ -174,7 +245,7 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
174
245
  var _ref4;
175
246
 
176
247
  return _ref4 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", {
177
- "interaction": "hover",
248
+ "interaction": text.length > displayedSymbols ? 'hover' : 'none',
178
249
  "title": text,
179
250
  "ref": containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement,
180
251
  "tag": _tooltip["default"]
@@ -1 +1 @@
1
- {"version":3,"file":"Ellipsis.js","names":["RootEllipsis","SEllipsis","Root","SContainer","Tooltip","asProps","styles","Children","maxLine","tooltip","trim","containerRect","containerRef","text","reactToText","getOriginChildren","sstyled","Box","Component","style","EllipsisMiddle","props","resizeElement","useRef","useState","fontSize","symbolWidth","dimension","setDimension","blockWidth","useResizeObserver","width","useLayoutEffect","dateSpan","document","createElement","setAttribute","innerHTML","body","appendChild","rect","getBoundingClientRect","remove","window","getComputedStyle","current","getPropertyValue","STail","SBeginning","SContainerMiddle","displayedSymbols","useMemo","Math","round","substring","length","Ellipsis","createComponent"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState, useLayoutEffect } from 'react';\nimport createComponent, { Component, sstyled } from '@semcore/core';\nimport Tooltip from '@semcore/tooltip';\nimport { Box } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const { styles, Children, maxLine, tooltip, trim, containerRect, containerRef } = this.asProps;\n const text = reactToText(getOriginChildren(Children));\n\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer interaction=\"hover\" title={text}>\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef } = props;\n const resizeElement = useRef<HTMLElement | null>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useLayoutEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n dateSpan.remove();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction=\"hover\"\n title={text}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis);\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AADA;;AAEA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqBMA,Y;;;;;;;;;;;;WAQJ,kBAAS;MAAA;;MACP,IAAMC,SAAS,GAAG,KAAKC,IAAvB;MACA,IAAMC,UAAU,GAAGC,mBAAnB;MACA,oBAAkF,KAAKC,OAAvF;MAAA,IAAQC,MAAR,iBAAQA,MAAR;MAAA,IAAgBC,QAAhB,iBAAgBA,QAAhB;MAAA,IAA0BC,OAA1B,iBAA0BA,OAA1B;MAAA,IAAmCC,OAAnC,iBAAmCA,OAAnC;MAAA,IAA4CC,IAA5C,iBAA4CA,IAA5C;MAAA,IAAkDC,aAAlD,iBAAkDA,aAAlD;MAAA,IAAiEC,YAAjE,iBAAiEA,YAAjE;MACA,IAAMC,IAAI,GAAG,IAAAC,uBAAA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MAAA,SAESO,IAFT;MAAA,OAGOD,YAHP,aAGOA,YAHP,cAGOA,YAHP,GAGuBU,aAHvB;MAAA,OAIOlB;IAJP,iBAME,gCAAC,UAAD,8BAAaS,IAAI,CAACyC,SAAL,CAAe,CAAf,EAAkBzC,IAAI,CAAC0C,MAAL,GAAcL,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CANF,eAOE,gCAAC,KAAD,yBAAQrC,IAAI,CAACyC,SAAL,CAAezC,IAAI,CAAC0C,MAAL,GAAcL,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAPF,CADF;EAWD,CAZD,MAYO;IAAA;;IACL,eAAO,IAAAlC,aAAA,EAAQV,MAAR,CAAP,eACE,gCAAC,gBAAD;MAAA,OAAuBM,YAAvB,aAAuBA,YAAvB,cAAuBA,YAAvB,GAAuCU;IAAvC,iBACE,gCAAC,UAAD,8BAAaT,IAAI,CAACyC,SAAL,CAAe,CAAf,EAAkBzC,IAAI,CAAC0C,MAAL,GAAcL,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,gCAAC,KAAD,yBAAQrC,IAAI,CAACyC,SAAL,CAAezC,IAAI,CAAC0C,MAAL,GAAcL,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAtDD;;AAwDA,IAAMM,QAAQ,GAAG,IAAAC,gBAAA,EAAgBzD,YAAhB,CAAjB;eAEewD,Q"}
1
+ {"version":3,"file":"Ellipsis.js","names":["createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","style","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","whiteSpace","removeChild","RootEllipsis","visible","React","createRef","setState","showTooltip","asProps","maxLine","textRef","current","SEllipsis","Root","SContainer","Tooltip","styles","Children","tooltip","trim","containerRect","containerRef","state","text","reactToText","getOriginChildren","sstyled","handlerVisibleChange","Box","Component","EllipsisMiddle","props","resizeElement","useRef","useState","symbolWidth","dimension","setDimension","blockWidth","useResizeObserver","useLayoutEffect","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","useMemo","Math","round","length","substring","Ellipsis","createComponent"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState, useLayoutEffect } from 'react';\nimport createComponent, { Component, sstyled } from '@semcore/core';\nimport Tooltip from '@semcore/tooltip';\nimport { Box } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\nconst createMeasurerElement = (element: HTMLElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLElement | null, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize, initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current, maxLine > 1)\n };\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const { styles, Children, maxLine, tooltip, trim, containerRect, containerRef } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer interaction='hover' title={text} visible={visible} onVisibleChange={this.handlerVisibleChange}>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef } = props;\n const resizeElement = useRef<HTMLElement | null>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useLayoutEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis);\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AADA;;AAEA;;AACA;;AACA;;AAGA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,OAAD,EAA0B;EACtD,IAAMC,YAAY,GAAGC,MAAM,CAACC,gBAAP,CAAwBH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@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
5
  import _inherits from "@babel/runtime/helpers/inherits";
5
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
7
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
@@ -22,34 +23,102 @@ var style = (
22
23
  /*__reshadow_css_start__*/
23
24
  _sstyled.insert(
24
25
  /*__inner_css_start__*/
25
- ".___SContainer_14o7y_gg_,.___SContainerMiddle_14o7y_gg_{display:flex;overflow:hidden}.___SBeginning_14o7y_gg_,.___SEllipsis_14o7y_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_14o7y_gg_.__maxLine_14o7y_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_14o7y);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_14o7y_gg_{white-space:nowrap}"
26
+ ".___SContainer_12kp5_gg_,.___SContainerMiddle_12kp5_gg_{display:flex;overflow:hidden}.___SBeginning_12kp5_gg_,.___SEllipsis_12kp5_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_12kp5_gg_.__maxLine_12kp5_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_12kp5);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_12kp5_gg_{white-space:nowrap}"
26
27
  /*__inner_css_end__*/
27
- , "14o7y_gg_")
28
+ , "12kp5_gg_")
28
29
  /*__reshadow_css_end__*/
29
30
  , {
30
- "__SContainer": "___SContainer_14o7y_gg_",
31
- "__SContainerMiddle": "___SContainerMiddle_14o7y_gg_",
32
- "__SBeginning": "___SBeginning_14o7y_gg_",
33
- "__SEllipsis": "___SEllipsis_14o7y_gg_",
34
- "_maxLine": "__maxLine_14o7y_gg_",
35
- "--maxLine": "--maxLine_14o7y",
36
- "__STail": "___STail_14o7y_gg_"
31
+ "__SContainer": "___SContainer_12kp5_gg_",
32
+ "__SContainerMiddle": "___SContainerMiddle_12kp5_gg_",
33
+ "__SBeginning": "___SBeginning_12kp5_gg_",
34
+ "__SEllipsis": "___SEllipsis_12kp5_gg_",
35
+ "_maxLine": "__maxLine_12kp5_gg_",
36
+ "--maxLine": "--maxLine_12kp5",
37
+ "__STail": "___STail_12kp5_gg_"
37
38
  });
38
39
  import reactToText from '@semcore/utils/lib/reactToText';
39
40
  import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
40
41
 
42
+ var createMeasurerElement = function createMeasurerElement(element) {
43
+ var styleElement = window.getComputedStyle(element, null);
44
+ var temporaryElement = document.createElement('temporary-block');
45
+ temporaryElement.style.display = 'inline-block';
46
+ temporaryElement.style.padding = '0';
47
+ temporaryElement.style.position = 'absolute';
48
+ temporaryElement.style.right = '150%';
49
+ temporaryElement.style.bottom = '150%';
50
+ temporaryElement.style.visibility = 'hidden';
51
+ temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');
52
+ temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');
53
+ temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');
54
+ temporaryElement.innerHTML = element.innerHTML;
55
+ return temporaryElement;
56
+ };
57
+
58
+ function isTextOverflowing(element, multiline) {
59
+ if (!element) return false;
60
+
61
+ var _element$getBoundingC = element.getBoundingClientRect(),
62
+ currentHeight = _element$getBoundingC.height,
63
+ currentWidth = _element$getBoundingC.width;
64
+
65
+ var measuringElement = createMeasurerElement(element);
66
+ var currentSize, initialSize;
67
+ document.body.appendChild(measuringElement);
68
+
69
+ if (multiline) {
70
+ currentSize = currentHeight;
71
+ measuringElement.style.width = "".concat(currentWidth, "px");
72
+ initialSize = measuringElement.getBoundingClientRect().height;
73
+ } else {
74
+ currentSize = currentWidth;
75
+ measuringElement.style.whiteSpace = 'nowrap';
76
+ initialSize = measuringElement.getBoundingClientRect().width;
77
+ }
78
+
79
+ document.body.removeChild(measuringElement);
80
+ return currentSize < initialSize;
81
+ }
82
+
41
83
  var RootEllipsis = /*#__PURE__*/function (_Component) {
42
84
  _inherits(RootEllipsis, _Component);
43
85
 
44
86
  var _super = _createSuper(RootEllipsis);
45
87
 
46
88
  function RootEllipsis() {
89
+ var _this;
90
+
47
91
  _classCallCheck(this, RootEllipsis);
48
92
 
49
- return _super.apply(this, arguments);
93
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
94
+ args[_key] = arguments[_key];
95
+ }
96
+
97
+ _this = _super.call.apply(_super, [this].concat(args));
98
+
99
+ _defineProperty(_assertThisInitialized(_this), "state", {
100
+ visible: false
101
+ });
102
+
103
+ _defineProperty(_assertThisInitialized(_this), "textRef", /*#__PURE__*/React.createRef());
104
+
105
+ _defineProperty(_assertThisInitialized(_this), "handlerVisibleChange", function (visible) {
106
+ _this.setState({
107
+ visible: visible && _this.showTooltip()
108
+ });
109
+ });
110
+
111
+ return _this;
50
112
  }
51
113
 
52
114
  _createClass(RootEllipsis, [{
115
+ key: "showTooltip",
116
+ value: function showTooltip() {
117
+ var _this$asProps$maxLine = this.asProps.maxLine,
118
+ maxLine = _this$asProps$maxLine === void 0 ? 1 : _this$asProps$maxLine;
119
+ return isTextOverflowing(this.textRef.current, maxLine > 1);
120
+ }
121
+ }, {
53
122
  key: "render",
54
123
  value: function render() {
55
124
  var _ref3;
@@ -64,6 +133,7 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
64
133
  trim = _this$asProps.trim,
65
134
  containerRect = _this$asProps.containerRect,
66
135
  containerRef = _this$asProps.containerRef;
136
+ var visible = this.state.visible;
67
137
  var text = reactToText(getOriginChildren(Children));
68
138
 
69
139
  if (trim === 'middle') {
@@ -82,10 +152,13 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
82
152
  var _ref2;
83
153
 
84
154
  return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(SContainer, _ref2.cn("SContainer", {
85
- "interaction": "hover",
86
- "title": text
155
+ "interaction": 'hover',
156
+ "title": text,
157
+ "visible": visible,
158
+ "onVisibleChange": this.handlerVisibleChange
87
159
  }), /*#__PURE__*/React.createElement(SEllipsis, _ref2.cn("SEllipsis", {
88
160
  "render": Box,
161
+ "ref": this.textRef,
89
162
  "maxLine": maxLine
90
163
  }), /*#__PURE__*/React.createElement(Children, _ref2.cn("Children", {}))));
91
164
  }
@@ -134,12 +207,12 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
134
207
  dateSpan.innerHTML = 'a';
135
208
  document.body.appendChild(dateSpan);
136
209
  var rect = dateSpan.getBoundingClientRect();
137
- dateSpan.remove();
138
210
  setDimension({
139
211
  fontSize: window // @ts-ignore
140
212
  .getComputedStyle((_containerRef$current = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : resizeElement.current, null).getPropertyValue('font-size'),
141
213
  symbolWidth: rect.width
142
214
  });
215
+ document.body.removeChild(dateSpan);
143
216
  }, []);
144
217
  var STail = 'span';
145
218
  var SBeginning = 'span';
@@ -152,7 +225,7 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
152
225
  var _ref4;
153
226
 
154
227
  return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", {
155
- "interaction": "hover",
228
+ "interaction": text.length > displayedSymbols ? 'hover' : 'none',
156
229
  "title": text,
157
230
  "ref": containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement,
158
231
  "tag": Tooltip
@@ -1 +1 @@
1
- {"version":3,"file":"Ellipsis.js","names":["React","useRef","useMemo","useState","useLayoutEffect","createComponent","Component","sstyled","Tooltip","Box","useResizeObserver","reactToText","getOriginChildren","RootEllipsis","SEllipsis","Root","SContainer","asProps","styles","Children","maxLine","tooltip","trim","containerRect","containerRef","text","style","EllipsisMiddle","props","resizeElement","fontSize","symbolWidth","dimension","setDimension","blockWidth","width","dateSpan","document","createElement","setAttribute","innerHTML","body","appendChild","rect","getBoundingClientRect","remove","window","getComputedStyle","current","getPropertyValue","STail","SBeginning","SContainerMiddle","displayedSymbols","Math","round","substring","length","Ellipsis"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState, useLayoutEffect } from 'react';\nimport createComponent, { Component, sstyled } from '@semcore/core';\nimport Tooltip from '@semcore/tooltip';\nimport { Box } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const { styles, Children, maxLine, tooltip, trim, containerRect, containerRef } = this.asProps;\n const text = reactToText(getOriginChildren(Children));\n\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer interaction=\"hover\" title={text}>\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef } = props;\n const resizeElement = useRef<HTMLElement | null>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useLayoutEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n dateSpan.remove();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction=\"hover\"\n title={text}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis);\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,KAAP,IAA2BC,MAA3B,EAAmCC,OAAnC,EAA4CC,QAA5C,EAAsDC,eAAtD,QAA6E,OAA7E;AACA,OAAOC,eAAP,IAA0BC,SAA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C,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,oBAAC,KAAD,yBAAQ5B,IAAI,CAAC+B,SAAL,CAAe/B,IAAI,CAACgC,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAtDD;;AAwDA,IAAMK,QAAQ,GAAGrD,eAAe,CAACQ,YAAD,CAAhC;AAEA,eAAe6C,QAAf"}
1
+ {"version":3,"file":"Ellipsis.js","names":["React","useRef","useMemo","useState","useLayoutEffect","createComponent","Component","sstyled","Tooltip","Box","useResizeObserver","reactToText","getOriginChildren","createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","style","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","whiteSpace","removeChild","RootEllipsis","visible","createRef","setState","showTooltip","asProps","maxLine","textRef","current","SEllipsis","Root","SContainer","styles","Children","tooltip","trim","containerRect","containerRef","state","text","handlerVisibleChange","EllipsisMiddle","props","resizeElement","symbolWidth","dimension","setDimension","blockWidth","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","Math","round","length","substring","Ellipsis"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState, useLayoutEffect } from 'react';\nimport createComponent, { Component, sstyled } from '@semcore/core';\nimport Tooltip from '@semcore/tooltip';\nimport { Box } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n};\n\nconst createMeasurerElement = (element: HTMLElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLElement | null, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize, initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current, maxLine > 1)\n };\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const { styles, Children, maxLine, tooltip, trim, containerRect, containerRef } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer interaction='hover' title={text} visible={visible} onVisibleChange={this.handlerVisibleChange}>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SEllipsis render={Box} maxLine={maxLine}>\n <Children />\n </SEllipsis>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef } = props;\n const resizeElement = useRef<HTMLElement | null>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useLayoutEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis);\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;;AAAA,OAAOA,KAAP,IAA2BC,MAA3B,EAAmCC,OAAnC,EAA4CC,QAA5C,EAAsDC,eAAtD,QAA6E,OAA7E;AACA,OAAOC,eAAP,IAA0BC,SAA1B,EAAqCC,OAArC,QAAoD,eAApD;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,SAASC,GAAT,QAAoB,mBAApB;AACA,SAASC,iBAAT,QAAkC,qBAAlC;;;;;;;;;;;;;;;;;;;;AAGA,OAAOC,WAAP,MAAwB,gCAAxB;AACA,OAAOC,iBAAP,MAA8B,sCAA9B;;AAqBA,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,OAAD,EAA0B;EACtD,IAAMC,YAAY,GAAGC,MAAM,CAACC,gBAAP,CAAwBH,OAAxB,EAAiC,IAAjC,CAArB;EACA,IAAMI,gBAAgB,GAAGC,QAAQ,CAACC,aAAT,CAAuB,iBAAvB,CAAzB;EACAF,gBAAgB,CAACG,KAAjB,CAAuBC,OAAvB,GAAiC,cAAjC;EACAJ,gBAAgB,CAACG,KAAjB,CAAuBE,OAAvB,GAAiC,GAAjC;EACAL,gBAAgB,CAACG,KAAjB,CAAuBG,QAAvB,GAAkC,UAAlC;EACAN,gBAAgB,CAACG,KAAjB,CAAuBI,KAAvB,GAA+B,MAA/B;EACAP,gBAAgB,CAACG,KAA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,IAAI,CAACkB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CANF,eAOE,oBAAC,KAAD,yBAAQf,IAAI,CAACmB,SAAL,CAAenB,IAAI,CAACkB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAPF,CADF;EAWD,CAZD,MAYO;IAAA;;IACL,eAAO1E,OAAO,CAACoD,MAAD,CAAd,eACE,oBAAC,gBAAD;MAAA,OAAuBK,YAAvB,aAAuBA,YAAvB,cAAuBA,YAAvB,GAAuCM;IAAvC,iBACE,oBAAC,UAAD,8BAAaJ,IAAI,CAACmB,SAAL,CAAe,CAAf,EAAkBnB,IAAI,CAACkB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,oBAAC,KAAD,yBAAQf,IAAI,CAACmB,SAAL,CAAenB,IAAI,CAACkB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAtDD;;AAwDA,IAAMK,QAAQ,GAAGjF,eAAe,CAAC0C,YAAD,CAAhC;AAEA,eAAeuC,QAAf"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/ellipsis",
3
3
  "description": "Semrush Ellipsis Component",
4
- "version": "1.1.8",
4
+ "version": "1.1.9",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",