@semcore/ellipsis 1.1.10 → 1.2.1
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 +10 -4
- package/lib/cjs/Ellipsis.js +35 -20
- package/lib/cjs/Ellipsis.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/style/ellipsis.shadow.css +1 -0
- package/lib/es6/Ellipsis.js +34 -20
- package/lib/es6/Ellipsis.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/style/ellipsis.shadow.css +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,13 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
-
## [1.1
|
|
5
|
+
## [1.2.1] - 2023-02-16
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Ellipsis wasn't working when tooltip was disabled.
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## [1.2.0] - 2023-02-15
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Supported passing tooltip props.
|
|
16
|
+
|
|
17
|
+
## [1.1.10] - 2023-02-09
|
|
12
18
|
|
|
13
19
|
### Fixed
|
|
14
20
|
|
package/lib/cjs/Ellipsis.js
CHANGED
|
@@ -39,10 +39,16 @@ var _reactToText = _interopRequireDefault(require("@semcore/utils/lib/reactToTex
|
|
|
39
39
|
|
|
40
40
|
var _getOriginChildren = _interopRequireDefault(require("@semcore/utils/lib/getOriginChildren"));
|
|
41
41
|
|
|
42
|
+
var _pick = _interopRequireDefault(require("@semcore/utils/lib/pick"));
|
|
43
|
+
|
|
42
44
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
43
45
|
|
|
44
46
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
45
47
|
|
|
48
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
49
|
+
|
|
50
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
51
|
+
|
|
46
52
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
47
53
|
|
|
48
54
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -52,19 +58,21 @@ var style = (
|
|
|
52
58
|
/*__reshadow_css_start__*/
|
|
53
59
|
_core.sstyled.insert(
|
|
54
60
|
/*__inner_css_start__*/
|
|
55
|
-
".
|
|
61
|
+
".___SContainerMiddle_5vwdw_gg_,.___SContainer_5vwdw_gg_,.___SNoTooltipContainer_5vwdw_gg_{display:flex;overflow:hidden}.___SBeginning_5vwdw_gg_,.___SEllipsis_5vwdw_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_5vwdw_gg_.__maxLine_5vwdw_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_5vwdw);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_5vwdw_gg_{white-space:nowrap}"
|
|
56
62
|
/*__inner_css_end__*/
|
|
57
|
-
, "
|
|
63
|
+
, "5vwdw_gg_")
|
|
58
64
|
/*__reshadow_css_end__*/
|
|
59
65
|
, {
|
|
60
|
-
"__SContainer": "
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
66
|
+
"__SContainer": "___SContainer_5vwdw_gg_",
|
|
67
|
+
"__SNoTooltipContainer": "___SNoTooltipContainer_5vwdw_gg_",
|
|
68
|
+
"__SContainerMiddle": "___SContainerMiddle_5vwdw_gg_",
|
|
69
|
+
"__SBeginning": "___SBeginning_5vwdw_gg_",
|
|
70
|
+
"__SEllipsis": "___SEllipsis_5vwdw_gg_",
|
|
71
|
+
"_maxLine": "__maxLine_5vwdw_gg_",
|
|
72
|
+
"--maxLine": "--maxLine_5vwdw",
|
|
73
|
+
"__STail": "___STail_5vwdw_gg_"
|
|
67
74
|
});
|
|
75
|
+
var defaultTooltipProps = ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate'];
|
|
68
76
|
|
|
69
77
|
var createMeasurerElement = function createMeasurerElement(element) {
|
|
70
78
|
var styleElement = window.getComputedStyle(element, null);
|
|
@@ -148,6 +156,7 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
148
156
|
|
|
149
157
|
var SEllipsis = this.Root;
|
|
150
158
|
var SContainer = _tooltip["default"];
|
|
159
|
+
var SNoTooltipContainer = _flexBox.Box;
|
|
151
160
|
var _this$asProps = this.asProps,
|
|
152
161
|
styles = _this$asProps.styles,
|
|
153
162
|
Children = _this$asProps.Children,
|
|
@@ -155,9 +164,11 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
155
164
|
tooltip = _this$asProps.tooltip,
|
|
156
165
|
trim = _this$asProps.trim,
|
|
157
166
|
containerRect = _this$asProps.containerRect,
|
|
158
|
-
containerRef = _this$asProps.containerRef
|
|
167
|
+
containerRef = _this$asProps.containerRef,
|
|
168
|
+
includeTooltipProps = _this$asProps.includeTooltipProps;
|
|
159
169
|
var visible = this.state.visible;
|
|
160
170
|
var text = (0, _reactToText["default"])((0, _getOriginChildren["default"])(Children));
|
|
171
|
+
var tooltipProps = (0, _pick["default"])(this.asProps, includeTooltipProps);
|
|
161
172
|
|
|
162
173
|
if (trim === 'middle') {
|
|
163
174
|
var _ref;
|
|
@@ -167,29 +178,31 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
167
178
|
"styles": styles,
|
|
168
179
|
"tooltip": tooltip,
|
|
169
180
|
"containerRect": containerRect,
|
|
170
|
-
"containerRef": containerRef
|
|
181
|
+
"containerRef": containerRef,
|
|
182
|
+
"tooltipProps": tooltipProps
|
|
171
183
|
}));
|
|
172
184
|
}
|
|
173
185
|
|
|
174
186
|
if (tooltip) {
|
|
175
187
|
var _ref2;
|
|
176
188
|
|
|
177
|
-
return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainer, _ref2.cn("SContainer", {
|
|
178
|
-
"interaction":
|
|
189
|
+
return _ref2 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainer, _ref2.cn("SContainer", _objectSpread({
|
|
190
|
+
"interaction": "hover",
|
|
179
191
|
"title": text,
|
|
180
192
|
"visible": visible,
|
|
181
193
|
"onVisibleChange": this.handlerVisibleChange
|
|
182
|
-
}), /*#__PURE__*/_react["default"].createElement(SEllipsis, _ref2.cn("SEllipsis", {
|
|
194
|
+
}, tooltipProps)), /*#__PURE__*/_react["default"].createElement(SEllipsis, _ref2.cn("SEllipsis", {
|
|
183
195
|
"render": _flexBox.Box,
|
|
184
196
|
"ref": this.textRef,
|
|
185
197
|
"maxLine": maxLine
|
|
186
198
|
}), /*#__PURE__*/_react["default"].createElement(Children, _ref2.cn("Children", {}))));
|
|
187
199
|
}
|
|
188
200
|
|
|
189
|
-
return _ref3 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
201
|
+
return _ref3 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SNoTooltipContainer, _ref3.cn("SNoTooltipContainer", {}), /*#__PURE__*/_react["default"].createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
190
202
|
"render": _flexBox.Box,
|
|
203
|
+
"ref": this.textRef,
|
|
191
204
|
"maxLine": maxLine
|
|
192
|
-
}), /*#__PURE__*/_react["default"].createElement(Children, _ref3.cn("Children", {})));
|
|
205
|
+
}), /*#__PURE__*/_react["default"].createElement(Children, _ref3.cn("Children", {}))));
|
|
193
206
|
}
|
|
194
207
|
}]);
|
|
195
208
|
return RootEllipsis;
|
|
@@ -199,7 +212,8 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
199
212
|
(0, _defineProperty2["default"])(RootEllipsis, "style", style);
|
|
200
213
|
(0, _defineProperty2["default"])(RootEllipsis, "defaultProps", {
|
|
201
214
|
trim: 'end',
|
|
202
|
-
tooltip: true
|
|
215
|
+
tooltip: true,
|
|
216
|
+
includeTooltipProps: defaultTooltipProps
|
|
203
217
|
});
|
|
204
218
|
|
|
205
219
|
var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
@@ -207,7 +221,8 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
|
207
221
|
text = props.text,
|
|
208
222
|
tooltip = props.tooltip,
|
|
209
223
|
containerRect = props.containerRect,
|
|
210
|
-
containerRef = props.containerRef
|
|
224
|
+
containerRef = props.containerRef,
|
|
225
|
+
tooltipProps = props.tooltipProps;
|
|
211
226
|
var resizeElement = (0, _react.useRef)(null);
|
|
212
227
|
|
|
213
228
|
var _useState = (0, _react.useState)({
|
|
@@ -244,12 +259,12 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
|
244
259
|
if (tooltip) {
|
|
245
260
|
var _ref4;
|
|
246
261
|
|
|
247
|
-
return _ref4 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", {
|
|
262
|
+
return _ref4 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", _objectSpread({
|
|
248
263
|
"interaction": text.length > displayedSymbols ? 'hover' : 'none',
|
|
249
264
|
"title": text,
|
|
250
265
|
"ref": containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement,
|
|
251
266
|
"tag": _tooltip["default"]
|
|
252
|
-
}), /*#__PURE__*/_react["default"].createElement(SBeginning, _ref4.cn("SBeginning", {}), text.substring(0, text.length - displayedSymbols / 2 - 1)), /*#__PURE__*/_react["default"].createElement(STail, _ref4.cn("STail", {}), text.substring(text.length - displayedSymbols / 2 - 1)));
|
|
267
|
+
}, tooltipProps)), /*#__PURE__*/_react["default"].createElement(SBeginning, _ref4.cn("SBeginning", {}), text.substring(0, text.length - displayedSymbols / 2 - 1)), /*#__PURE__*/_react["default"].createElement(STail, _ref4.cn("STail", {}), text.substring(text.length - displayedSymbols / 2 - 1)));
|
|
253
268
|
} else {
|
|
254
269
|
var _ref5;
|
|
255
270
|
|
package/lib/cjs/Ellipsis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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,KAAjB,CAAuBK,MAAvB,GAAgC,MAAhC;EACAR,gBAAgB,CAACG,KAAjB,CAAuBM,UAAvB,GAAoC,QAApC;EACAT,gBAAgB,CAACG,KAAjB,CAAuBO,UAAvB,GAAoCb,YAAY,CAACc,gBAAb,CAA8B,aAA9B,CAAp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AAI,CAAC4B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAPF,CADF;EAWD,CAZD,MAYO;IAAA;;IACL,eAAO,IAAArB,aAAA,EAAQV,MAAR,CAAP,eACE,gCAAC,gBAAD;MAAA,OAAuBK,YAAvB,aAAuBA,YAAvB,cAAuBA,YAAvB,GAAuCW;IAAvC,iBACE,gCAAC,UAAD,8BAAaT,IAAI,CAAC6B,SAAL,CAAe,CAAf,EAAkB7B,IAAI,CAAC4B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,gCAAC,KAAD,yBAAQxB,IAAI,CAAC6B,SAAL,CAAe7B,IAAI,CAAC4B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAtDD;;AAwDA,IAAMM,QAAQ,GAAG,IAAAC,gBAAA,EAAgBpD,YAAhB,CAAjB;eAEemD,Q"}
|
|
1
|
+
{"version":3,"file":"Ellipsis.js","names":["defaultTooltipProps","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","SNoTooltipContainer","Box","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","reactToText","getOriginChildren","tooltipProps","pick","sstyled","handlerVisibleChange","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';\nimport pick from '@semcore/utils/lib/pick';\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 includeTooltipProps?: string[];\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 tooltipProps: { [propName: string]: unknown };\n};\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\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\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\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 SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps);\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 tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction=\"hover\"\n title={text}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = 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 {...tooltipProps}\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(RootEll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SAAL,CAAe,CAAf,EAAkB9B,IAAI,CAAC6B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CAPF,eAQE,gCAAC,KAAD,yBAAQzB,IAAI,CAAC8B,SAAL,CAAe9B,IAAI,CAAC6B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CARF,CADF;EAYD,CAbD,MAaO;IAAA;;IACL,eAAO,IAAApB,aAAA,EAAQb,MAAR,CAAP,eACE,gCAAC,gBAAD;MAAA,OAAuBK,YAAvB,aAAuBA,YAAvB,cAAuBA,YAAvB,GAAuCa;IAAvC,iBACE,gCAAC,UAAD,8BAAaV,IAAI,CAAC8B,SAAL,CAAe,CAAf,EAAkB9B,IAAI,CAAC6B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,gCAAC,KAAD,yBAAQzB,IAAI,CAAC8B,SAAL,CAAe9B,IAAI,CAAC6B,MAAL,GAAcJ,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAvDD;;AAyDA,IAAMM,QAAQ,GAAG,IAAAC,gBAAA,EAAgBxD,YAAhB,CAAjB;eAEeuD,Q"}
|
package/lib/cjs/index.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { CProps } from '@semcore/core';\nimport { RefObject } from 'react';\n\nexport interface IEllipsisProps {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n}\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: <T>(props: CProps<IEllipsisProps & T>) => ReturnEl;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { CProps, ReturnEl } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { IBoxProps } from '@semcore/flex-box';\nimport { ITooltipProps } from '@semcore/tooltip';\n\nexport interface IEllipsisProps extends IBoxProps, ITooltipProps {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n}\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: <T>(props: CProps<IEllipsisProps & T>) => ReturnEl;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|
package/lib/es6/Ellipsis.js
CHANGED
|
@@ -8,6 +8,10 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
|
8
8
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
9
|
import { sstyled as _sstyled } from "@semcore/core";
|
|
10
10
|
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
+
|
|
11
15
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
16
|
|
|
13
17
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -23,21 +27,24 @@ var style = (
|
|
|
23
27
|
/*__reshadow_css_start__*/
|
|
24
28
|
_sstyled.insert(
|
|
25
29
|
/*__inner_css_start__*/
|
|
26
|
-
".
|
|
30
|
+
".___SContainerMiddle_5vwdw_gg_,.___SContainer_5vwdw_gg_,.___SNoTooltipContainer_5vwdw_gg_{display:flex;overflow:hidden}.___SBeginning_5vwdw_gg_,.___SEllipsis_5vwdw_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:nowrap}.___SEllipsis_5vwdw_gg_.__maxLine_5vwdw_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_5vwdw);-webkit-box-orient:vertical;overflow:hidden;white-space:normal}.___STail_5vwdw_gg_{white-space:nowrap}"
|
|
27
31
|
/*__inner_css_end__*/
|
|
28
|
-
, "
|
|
32
|
+
, "5vwdw_gg_")
|
|
29
33
|
/*__reshadow_css_end__*/
|
|
30
34
|
, {
|
|
31
|
-
"__SContainer": "
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
35
|
+
"__SContainer": "___SContainer_5vwdw_gg_",
|
|
36
|
+
"__SNoTooltipContainer": "___SNoTooltipContainer_5vwdw_gg_",
|
|
37
|
+
"__SContainerMiddle": "___SContainerMiddle_5vwdw_gg_",
|
|
38
|
+
"__SBeginning": "___SBeginning_5vwdw_gg_",
|
|
39
|
+
"__SEllipsis": "___SEllipsis_5vwdw_gg_",
|
|
40
|
+
"_maxLine": "__maxLine_5vwdw_gg_",
|
|
41
|
+
"--maxLine": "--maxLine_5vwdw",
|
|
42
|
+
"__STail": "___STail_5vwdw_gg_"
|
|
38
43
|
});
|
|
39
44
|
import reactToText from '@semcore/utils/lib/reactToText';
|
|
40
45
|
import getOriginChildren from '@semcore/utils/lib/getOriginChildren';
|
|
46
|
+
import pick from '@semcore/utils/lib/pick';
|
|
47
|
+
var defaultTooltipProps = ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate'];
|
|
41
48
|
|
|
42
49
|
var createMeasurerElement = function createMeasurerElement(element) {
|
|
43
50
|
var styleElement = window.getComputedStyle(element, null);
|
|
@@ -125,6 +132,7 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
125
132
|
|
|
126
133
|
var SEllipsis = this.Root;
|
|
127
134
|
var SContainer = Tooltip;
|
|
135
|
+
var SNoTooltipContainer = Box;
|
|
128
136
|
var _this$asProps = this.asProps,
|
|
129
137
|
styles = _this$asProps.styles,
|
|
130
138
|
Children = _this$asProps.Children,
|
|
@@ -132,9 +140,11 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
132
140
|
tooltip = _this$asProps.tooltip,
|
|
133
141
|
trim = _this$asProps.trim,
|
|
134
142
|
containerRect = _this$asProps.containerRect,
|
|
135
|
-
containerRef = _this$asProps.containerRef
|
|
143
|
+
containerRef = _this$asProps.containerRef,
|
|
144
|
+
includeTooltipProps = _this$asProps.includeTooltipProps;
|
|
136
145
|
var visible = this.state.visible;
|
|
137
146
|
var text = reactToText(getOriginChildren(Children));
|
|
147
|
+
var tooltipProps = pick(this.asProps, includeTooltipProps);
|
|
138
148
|
|
|
139
149
|
if (trim === 'middle') {
|
|
140
150
|
var _ref;
|
|
@@ -144,29 +154,31 @@ var RootEllipsis = /*#__PURE__*/function (_Component) {
|
|
|
144
154
|
"styles": styles,
|
|
145
155
|
"tooltip": tooltip,
|
|
146
156
|
"containerRect": containerRect,
|
|
147
|
-
"containerRef": containerRef
|
|
157
|
+
"containerRef": containerRef,
|
|
158
|
+
"tooltipProps": tooltipProps
|
|
148
159
|
}));
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
if (tooltip) {
|
|
152
163
|
var _ref2;
|
|
153
164
|
|
|
154
|
-
return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(SContainer, _ref2.cn("SContainer", {
|
|
155
|
-
"interaction":
|
|
165
|
+
return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(SContainer, _ref2.cn("SContainer", _objectSpread({
|
|
166
|
+
"interaction": "hover",
|
|
156
167
|
"title": text,
|
|
157
168
|
"visible": visible,
|
|
158
169
|
"onVisibleChange": this.handlerVisibleChange
|
|
159
|
-
}), /*#__PURE__*/React.createElement(SEllipsis, _ref2.cn("SEllipsis", {
|
|
170
|
+
}, tooltipProps)), /*#__PURE__*/React.createElement(SEllipsis, _ref2.cn("SEllipsis", {
|
|
160
171
|
"render": Box,
|
|
161
172
|
"ref": this.textRef,
|
|
162
173
|
"maxLine": maxLine
|
|
163
174
|
}), /*#__PURE__*/React.createElement(Children, _ref2.cn("Children", {}))));
|
|
164
175
|
}
|
|
165
176
|
|
|
166
|
-
return _ref3 = sstyled(styles), /*#__PURE__*/React.createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
177
|
+
return _ref3 = sstyled(styles), /*#__PURE__*/React.createElement(SNoTooltipContainer, _ref3.cn("SNoTooltipContainer", {}), /*#__PURE__*/React.createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
167
178
|
"render": Box,
|
|
179
|
+
"ref": this.textRef,
|
|
168
180
|
"maxLine": maxLine
|
|
169
|
-
}), /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {})));
|
|
181
|
+
}), /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {}))));
|
|
170
182
|
}
|
|
171
183
|
}]);
|
|
172
184
|
|
|
@@ -179,7 +191,8 @@ _defineProperty(RootEllipsis, "style", style);
|
|
|
179
191
|
|
|
180
192
|
_defineProperty(RootEllipsis, "defaultProps", {
|
|
181
193
|
trim: 'end',
|
|
182
|
-
tooltip: true
|
|
194
|
+
tooltip: true,
|
|
195
|
+
includeTooltipProps: defaultTooltipProps
|
|
183
196
|
});
|
|
184
197
|
|
|
185
198
|
var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
@@ -187,7 +200,8 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
|
187
200
|
text = props.text,
|
|
188
201
|
tooltip = props.tooltip,
|
|
189
202
|
containerRect = props.containerRect,
|
|
190
|
-
containerRef = props.containerRef
|
|
203
|
+
containerRef = props.containerRef,
|
|
204
|
+
tooltipProps = props.tooltipProps;
|
|
191
205
|
var resizeElement = useRef(null);
|
|
192
206
|
|
|
193
207
|
var _useState = useState({
|
|
@@ -224,12 +238,12 @@ var EllipsisMiddle = function EllipsisMiddle(props) {
|
|
|
224
238
|
if (tooltip) {
|
|
225
239
|
var _ref4;
|
|
226
240
|
|
|
227
|
-
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", {
|
|
241
|
+
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SContainerMiddle, _ref4.cn("SContainerMiddle", _objectSpread({
|
|
228
242
|
"interaction": text.length > displayedSymbols ? 'hover' : 'none',
|
|
229
243
|
"title": text,
|
|
230
244
|
"ref": containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement,
|
|
231
245
|
"tag": Tooltip
|
|
232
|
-
}), /*#__PURE__*/React.createElement(SBeginning, _ref4.cn("SBeginning", {}), text.substring(0, text.length - displayedSymbols / 2 - 1)), /*#__PURE__*/React.createElement(STail, _ref4.cn("STail", {}), text.substring(text.length - displayedSymbols / 2 - 1)));
|
|
246
|
+
}, tooltipProps)), /*#__PURE__*/React.createElement(SBeginning, _ref4.cn("SBeginning", {}), text.substring(0, text.length - displayedSymbols / 2 - 1)), /*#__PURE__*/React.createElement(STail, _ref4.cn("STail", {}), text.substring(text.length - displayedSymbols / 2 - 1)));
|
|
233
247
|
} else {
|
|
234
248
|
var _ref5;
|
|
235
249
|
|
package/lib/es6/Ellipsis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;;;;;;;;;;;;;;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eAAe,CAAC0C,YAAD,CAAhC;AAEA,eAAeuC,QAAf"}
|
|
1
|
+
{"version":3,"file":"Ellipsis.js","names":["React","useRef","useMemo","useState","useLayoutEffect","createComponent","Component","sstyled","Tooltip","Box","useResizeObserver","reactToText","getOriginChildren","pick","defaultTooltipProps","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","SNoTooltipContainer","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","tooltipProps","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';\nimport pick from '@semcore/utils/lib/pick';\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 includeTooltipProps?: string[];\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 tooltipProps: { [propName: string]: unknown };\n};\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\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\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\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 SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps);\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 tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction=\"hover\"\n title={text}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = 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 {...tooltipProps}\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;AACA,OAAOC,IAAP,MAAiB,yBAAjB;AAuBA,IAAMC,mBAAmB,GAAG,CAC1B,OAD0B,EAE1B,OAF0B,EAG1B,UAH0B,EAI1B,WAJ0B,EAK1B,WAL0B,EAM1B,aAN0B,EAO1B,SAP0B,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uBK,YAAvB,aAAuBA,YAAvB,cAAuBA,YAAvB,GAAuCQ;IAAvC,iBACE,oBAAC,UAAD,8BAAaL,IAAI,CAACoB,SAAL,CAAe,CAAf,EAAkBpB,IAAI,CAACmB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAAvD,CAAb,CADF,eAEE,oBAAC,KAAD,yBAAQhB,IAAI,CAACoB,SAAL,CAAepB,IAAI,CAACmB,MAAL,GAAcH,gBAAgB,GAAG,CAAjC,GAAqC,CAApD,CAAR,CAFF,CADF;EAMD;AACF,CAvDD;;AAyDA,IAAMK,QAAQ,GAAGtF,eAAe,CAAC4C,YAAD,CAAhC;AAEA,eAAe0C,QAAf"}
|
package/lib/es6/index.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { CProps } from '@semcore/core';\nimport { RefObject } from 'react';\n\nexport interface IEllipsisProps {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n}\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: <T>(props: CProps<IEllipsisProps & T>) => ReturnEl;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { CProps, ReturnEl } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { IBoxProps } from '@semcore/flex-box';\nimport { ITooltipProps } from '@semcore/tooltip';\n\nexport interface IEllipsisProps extends IBoxProps, ITooltipProps {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n}\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: <T>(props: CProps<IEllipsisProps & T>) => ReturnEl;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|