@semcore/ellipsis 16.0.12-prerelease.0 → 16.0.12-prerelease.20
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/README.md +4 -4
- package/lib/cjs/Ellipsis.js +172 -224
- package/lib/cjs/Ellipsis.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +4 -4
- package/lib/cjs/useResizeObserver.js +10 -13
- package/lib/cjs/useResizeObserver.js.map +1 -1
- package/lib/cjs/utils.js +55 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/es6/Ellipsis.js +161 -213
- package/lib/es6/Ellipsis.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/useResizeObserver.js +7 -11
- package/lib/es6/useResizeObserver.js.map +1 -1
- package/lib/es6/utils.js +47 -0
- package/lib/es6/utils.js.map +1 -0
- package/lib/esm/Ellipsis.mjs +161 -183
- package/lib/esm/useResizeObserver.mjs +6 -7
- package/lib/esm/utils.mjs +50 -0
- package/lib/types/index.d.ts +6 -5
- package/package.json +5 -5
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 type {
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import type { Box, BoxProps } from '@semcore/base-components';\nimport type { UnknownProperties, Intergalactic } from '@semcore/core';\nimport type { TooltipProps } from '@semcore/tooltip';\nimport type Tooltip from '@semcore/tooltip';\nimport type { RefObject } from 'react';\n\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis.\n * Applies only for `trim = end`\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 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/**\n * @deprecated. Use Text with ellipsis property for @semcore/typography.\n */\ndeclare const Ellipsis: Intergalactic.Component<'div', EllipsisProps> & {\n Content: typeof Box;\n Popper: typeof Tooltip.Popper;\n};\n\nexport default Ellipsis;\n\nexport { useResizeObserver };\n"],"mappings":"","ignoreList":[]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
Object.defineProperty(exports, "default", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function
|
|
10
|
-
return _Ellipsis
|
|
9
|
+
get: function () {
|
|
10
|
+
return _Ellipsis.default;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "useResizeObserver", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function
|
|
15
|
+
get: function () {
|
|
16
16
|
return _useResizeObserver.useResizeObserver;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.useResizeObserver = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
8
|
var _canUseDOM = _interopRequireDefault(require("@semcore/core/lib/utils/canUseDOM"));
|
|
10
9
|
var _useEnhancedEffect = _interopRequireDefault(require("@semcore/core/lib/utils/use/useEnhancedEffect"));
|
|
11
10
|
var _react = _interopRequireDefault(require("react"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
width = _React$useState2[0],
|
|
16
|
-
setWidth = _React$useState2[1];
|
|
17
|
-
var handleResize = _react["default"].useCallback(function (entries) {
|
|
11
|
+
const useResizeObserver = (ref, hookOverride) => {
|
|
12
|
+
const [width, setWidth] = _react.default.useState(0);
|
|
13
|
+
const handleResize = _react.default.useCallback(entries => {
|
|
18
14
|
setWidth(entries[0].contentRect.width);
|
|
19
15
|
}, []);
|
|
20
|
-
(0, _useEnhancedEffect
|
|
16
|
+
(0, _useEnhancedEffect.default)(() => {
|
|
21
17
|
if (!ref.current) {
|
|
22
18
|
return;
|
|
23
19
|
}
|
|
24
20
|
if (hookOverride) {
|
|
25
21
|
return;
|
|
26
22
|
}
|
|
27
|
-
if ((0, _canUseDOM
|
|
28
|
-
|
|
23
|
+
if ((0, _canUseDOM.default)()) {
|
|
24
|
+
const ro = new ResizeObserver(entries => {
|
|
29
25
|
handleResize(entries);
|
|
30
26
|
});
|
|
31
27
|
ro.observe(ref.current);
|
|
32
|
-
return
|
|
28
|
+
return () => {
|
|
33
29
|
ro.disconnect();
|
|
34
30
|
};
|
|
35
31
|
}
|
|
@@ -38,7 +34,8 @@ var useResizeObserver = exports.useResizeObserver = function useResizeObserver(r
|
|
|
38
34
|
return hookOverride;
|
|
39
35
|
}
|
|
40
36
|
return {
|
|
41
|
-
width
|
|
37
|
+
width
|
|
42
38
|
};
|
|
43
39
|
};
|
|
40
|
+
exports.useResizeObserver = useResizeObserver;
|
|
44
41
|
//# sourceMappingURL=useResizeObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.js","names":["_canUseDOM","_interopRequireDefault","require","_useEnhancedEffect","_react","useResizeObserver","
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","names":["_canUseDOM","_interopRequireDefault","require","_useEnhancedEffect","_react","useResizeObserver","ref","hookOverride","width","setWidth","React","useState","handleResize","useCallback","entries","contentRect","useEnhancedEffect","current","canUseDOM","ro","ResizeObserver","observe","disconnect","exports"],"sources":["../../src/useResizeObserver.tsx"],"sourcesContent":["import canUseDOM from '@semcore/core/lib/utils/canUseDOM';\nimport useEnhancedEffect from '@semcore/core/lib/utils/use/useEnhancedEffect';\nimport React, { type RefObject } from 'react';\n\nexport const useResizeObserver = (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => {\n const [width, setWidth] = React.useState<number>(0);\n\n const handleResize = React.useCallback((entries: ResizeObserverEntry[]) => {\n setWidth(entries[0].contentRect.width);\n }, []);\n\n useEnhancedEffect(() => {\n if (!ref.current) {\n return;\n }\n\n if (hookOverride) {\n return;\n }\n if (canUseDOM()) {\n const ro = new ResizeObserver((entries: ResizeObserverEntry[]) => {\n handleResize(entries);\n });\n\n ro.observe(ref.current);\n\n return () => {\n ro.disconnect();\n };\n }\n }, [hookOverride]);\n\n if (hookOverride) {\n return hookOverride;\n }\n return { width };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEO,MAAMG,iBAAiB,GAAGA,CAC/BC,GAA2B,EAC3BC,YAAgC,KAC7B;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAS,CAAC,CAAC;EAEnD,MAAMC,YAAY,GAAGF,cAAK,CAACG,WAAW,CAAEC,OAA8B,IAAK;IACzEL,QAAQ,CAACK,OAAO,CAAC,CAAC,CAAC,CAACC,WAAW,CAACP,KAAK,CAAC;EACxC,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAQ,0BAAiB,EAAC,MAAM;IACtB,IAAI,CAACV,GAAG,CAACW,OAAO,EAAE;MAChB;IACF;IAEA,IAAIV,YAAY,EAAE;MAChB;IACF;IACA,IAAI,IAAAW,kBAAS,EAAC,CAAC,EAAE;MACf,MAAMC,EAAE,GAAG,IAAIC,cAAc,CAAEN,OAA8B,IAAK;QAChEF,YAAY,CAACE,OAAO,CAAC;MACvB,CAAC,CAAC;MAEFK,EAAE,CAACE,OAAO,CAACf,GAAG,CAACW,OAAO,CAAC;MAEvB,OAAO,MAAM;QACXE,EAAE,CAACG,UAAU,CAAC,CAAC;MACjB,CAAC;IACH;EACF,CAAC,EAAE,CAACf,YAAY,CAAC,CAAC;EAElB,IAAIA,YAAY,EAAE;IAChB,OAAOA,YAAY;EACrB;EACA,OAAO;IAAEC;EAAM,CAAC;AAClB,CAAC;AAACe,OAAA,CAAAlB,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/lib/cjs/utils.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isTextOverflowing = isTextOverflowing;
|
|
7
|
+
exports.setFontSettings = void 0;
|
|
8
|
+
const setFontSettings = (element, styleElement) => {
|
|
9
|
+
element.style.fontFamily = styleElement.getPropertyValue('font-family');
|
|
10
|
+
element.style.fontSize = styleElement.getPropertyValue('font-size');
|
|
11
|
+
element.style.fontWeight = styleElement.getPropertyValue('font-weight');
|
|
12
|
+
element.style.lineHeight = styleElement.getPropertyValue('line-height');
|
|
13
|
+
element.style.fontFeatureSettings = styleElement.getPropertyValue('font-feature-settings');
|
|
14
|
+
element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');
|
|
15
|
+
};
|
|
16
|
+
exports.setFontSettings = setFontSettings;
|
|
17
|
+
function isTextOverflowing(element, multiline, text) {
|
|
18
|
+
if (!element) return false;
|
|
19
|
+
const {
|
|
20
|
+
height: currentHeight,
|
|
21
|
+
width: currentWidth
|
|
22
|
+
} = element.getBoundingClientRect();
|
|
23
|
+
const measuringElement = createMeasurerElement(element, text);
|
|
24
|
+
let isOverflowing = false;
|
|
25
|
+
document.body.appendChild(measuringElement);
|
|
26
|
+
if (multiline) {
|
|
27
|
+
measuringElement.style.width = `${currentWidth}px`;
|
|
28
|
+
const width = measuringElement.scrollWidth;
|
|
29
|
+
const height = measuringElement.getBoundingClientRect().height;
|
|
30
|
+
if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
|
|
31
|
+
isOverflowing = true;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
measuringElement.style.whiteSpace = 'nowrap';
|
|
35
|
+
isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
|
|
36
|
+
}
|
|
37
|
+
document.body.removeChild(measuringElement);
|
|
38
|
+
return isOverflowing;
|
|
39
|
+
}
|
|
40
|
+
function createMeasurerElement(element, text) {
|
|
41
|
+
const styleElement = window.getComputedStyle(element, null);
|
|
42
|
+
const temporaryElement = document.createElement('temporary-block');
|
|
43
|
+
temporaryElement.style.display = styleElement.getPropertyValue('display');
|
|
44
|
+
temporaryElement.style.padding = styleElement.getPropertyValue('padding');
|
|
45
|
+
temporaryElement.style.position = 'absolute';
|
|
46
|
+
temporaryElement.style.right = '0%';
|
|
47
|
+
temporaryElement.style.bottom = '0%';
|
|
48
|
+
temporaryElement.style.visibility = 'hidden';
|
|
49
|
+
temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');
|
|
50
|
+
temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');
|
|
51
|
+
setFontSettings(temporaryElement, styleElement);
|
|
52
|
+
temporaryElement.textContent = text ?? element.textContent;
|
|
53
|
+
return temporaryElement;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["setFontSettings","element","styleElement","style","fontFamily","getPropertyValue","fontSize","fontWeight","lineHeight","fontFeatureSettings","fontVariantNumeric","exports","isTextOverflowing","multiline","text","height","currentHeight","width","currentWidth","getBoundingClientRect","measuringElement","createMeasurerElement","isOverflowing","document","body","appendChild","scrollWidth","Math","ceil","whiteSpace","removeChild","window","getComputedStyle","temporaryElement","createElement","display","padding","position","right","bottom","visibility","wordWrap","textContent"],"sources":["../../src/utils.ts"],"sourcesContent":["export const setFontSettings = (element: HTMLElement, styleElement: CSSStyleDeclaration): void => {\n element.style.fontFamily = styleElement.getPropertyValue('font-family');\n element.style.fontSize = styleElement.getPropertyValue('font-size');\n element.style.fontWeight = styleElement.getPropertyValue('font-weight');\n element.style.lineHeight = styleElement.getPropertyValue('line-height');\n element.style.fontFeatureSettings =\n styleElement.getPropertyValue('font-feature-settings');\n element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');\n};\n\nexport function isTextOverflowing(element: HTMLElement | null, multiline: boolean, text: string): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element, text);\n let isOverflowing = false;\n\n document.body.appendChild(measuringElement);\n if (multiline) {\n measuringElement.style.width = `${currentWidth}px`;\n\n const width = measuringElement.scrollWidth;\n const height = measuringElement.getBoundingClientRect().height;\n\n if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {\n isOverflowing = true;\n }\n } else {\n measuringElement.style.whiteSpace = 'nowrap';\n isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;\n }\n\n document.body.removeChild(measuringElement);\n\n return isOverflowing;\n}\n\nfunction createMeasurerElement(element: HTMLElement, text?: string) {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = styleElement.getPropertyValue('display');\n temporaryElement.style.padding = styleElement.getPropertyValue('padding');\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '0%';\n temporaryElement.style.bottom = '0%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');\n temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');\n\n setFontSettings(temporaryElement, styleElement);\n\n temporaryElement.textContent = text ?? element.textContent;\n return temporaryElement;\n}\n"],"mappings":"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","ignoreList":[]}
|
package/lib/es6/Ellipsis.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
-
import _callSuper from "@babel/runtime/helpers/callSuper";
|
|
7
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
2
|
import { sstyled as _sstyled } from "@semcore/core";
|
|
10
3
|
import { assignProps as _assignProps2 } from "@semcore/core";
|
|
11
4
|
import { assignProps as _assignProps } from "@semcore/core";
|
|
12
|
-
|
|
5
|
+
import { Box } from '@semcore/base-components';
|
|
13
6
|
import { createComponent, Component, Root, sstyled } from '@semcore/core';
|
|
14
7
|
import { callAllEventHandlers } from '@semcore/core/lib/utils/assignProps';
|
|
15
8
|
import findComponent, { isAdvanceMode } from '@semcore/core/lib/utils/findComponent';
|
|
@@ -18,11 +11,10 @@ import pick from '@semcore/core/lib/utils/pick';
|
|
|
18
11
|
import reactToText from '@semcore/core/lib/utils/reactToText';
|
|
19
12
|
import { forkRef } from '@semcore/core/lib/utils/ref';
|
|
20
13
|
import useEnhancedEffect from '@semcore/core/lib/utils/use/useEnhancedEffect';
|
|
21
|
-
import { Box } from '@semcore/flex-box';
|
|
22
14
|
import Tooltip from '@semcore/tooltip';
|
|
23
15
|
import React from 'react';
|
|
24
16
|
/*!__reshadow-styles__:"./style/ellipsis.shadow.css"*/
|
|
25
|
-
|
|
17
|
+
const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SBeginning_4aonj_gg_,.___SEllipsis_4aonj_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:pre}.___SEllipsis_4aonj_gg_.__maxLine_4aonj_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_4aonj);-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-wrap:break-word}.___SContainerMiddle_4aonj_gg_,.___SContainer_4aonj_gg_,.___SEllipsis_4aonj_gg_.__middle-mod_4aonj_gg_,.___SNoTooltipContainer_4aonj_gg_{display:flex;overflow:hidden}.___SContainerMiddle_4aonj_gg_>:has(.___SBeginning_4aonj_gg_),.___SContainerMiddle_4aonj_gg_>:has(.___STail_4aonj_gg_){display:flex;width:100%}.___STail_4aonj_gg_{white-space:pre}", /*__inner_css_end__*/"4aonj_gg_"),
|
|
26
18
|
/*__reshadow_css_end__*/
|
|
27
19
|
{
|
|
28
20
|
"__SBeginning": "___SBeginning_4aonj_gg_",
|
|
@@ -36,154 +28,103 @@ var style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".
|
|
|
36
28
|
"__STail": "___STail_4aonj_gg_"
|
|
37
29
|
});
|
|
38
30
|
import { useResizeObserver } from './useResizeObserver';
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
element.style.fontSize = styleElement.getPropertyValue('font-size');
|
|
43
|
-
element.style.fontWeight = styleElement.getPropertyValue('font-weight');
|
|
44
|
-
element.style.lineHeight = styleElement.getPropertyValue('line-height');
|
|
45
|
-
element.style.fontFeatureSettings = styleElement.getPropertyValue('font-feature-settings');
|
|
46
|
-
element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');
|
|
47
|
-
};
|
|
48
|
-
var createMeasurerElement = function createMeasurerElement(element, text) {
|
|
49
|
-
var styleElement = window.getComputedStyle(element, null);
|
|
50
|
-
var temporaryElement = document.createElement('temporary-block');
|
|
51
|
-
temporaryElement.style.display = styleElement.getPropertyValue('display');
|
|
52
|
-
temporaryElement.style.padding = styleElement.getPropertyValue('padding');
|
|
53
|
-
temporaryElement.style.position = 'absolute';
|
|
54
|
-
temporaryElement.style.right = '0%';
|
|
55
|
-
temporaryElement.style.bottom = '0%';
|
|
56
|
-
temporaryElement.style.visibility = 'hidden';
|
|
57
|
-
temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');
|
|
58
|
-
temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');
|
|
59
|
-
setFontSettings(temporaryElement, styleElement);
|
|
60
|
-
temporaryElement.textContent = text !== null && text !== void 0 ? text : element.textContent;
|
|
61
|
-
return temporaryElement;
|
|
62
|
-
};
|
|
63
|
-
function isTextOverflowing(element, multiline, text) {
|
|
64
|
-
if (!element) return false;
|
|
65
|
-
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
66
|
-
currentHeight = _element$getBoundingC.height,
|
|
67
|
-
currentWidth = _element$getBoundingC.width;
|
|
68
|
-
var measuringElement = createMeasurerElement(element, text);
|
|
69
|
-
var isOverflowing = false;
|
|
70
|
-
document.body.appendChild(measuringElement);
|
|
71
|
-
if (multiline) {
|
|
72
|
-
measuringElement.style.width = "".concat(currentWidth, "px");
|
|
73
|
-
var width = measuringElement.scrollWidth;
|
|
74
|
-
var height = measuringElement.getBoundingClientRect().height;
|
|
75
|
-
if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
|
|
76
|
-
isOverflowing = true;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
measuringElement.style.whiteSpace = 'nowrap';
|
|
80
|
-
isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
|
|
81
|
-
}
|
|
82
|
-
document.body.removeChild(measuringElement);
|
|
83
|
-
return isOverflowing;
|
|
84
|
-
}
|
|
85
|
-
var forcedAdvancedMode = {
|
|
31
|
+
import { isTextOverflowing, setFontSettings } from './utils';
|
|
32
|
+
const defaultTooltipProps = ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate', 'cursorAnchoring'];
|
|
33
|
+
const forcedAdvancedMode = {
|
|
86
34
|
forcedAdvancedMode: true
|
|
87
35
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
94
|
-
args[_key] = arguments[_key];
|
|
95
|
-
}
|
|
96
|
-
_this = _callSuper(this, RootEllipsis, [].concat(args));
|
|
97
|
-
_defineProperty(_this, "state", {
|
|
36
|
+
const noAdvancedMode = {};
|
|
37
|
+
class RootEllipsis extends Component {
|
|
38
|
+
constructor(...args) {
|
|
39
|
+
super(...args);
|
|
40
|
+
_defineProperty(this, "state", {
|
|
98
41
|
visible: false
|
|
99
42
|
});
|
|
100
|
-
_defineProperty(
|
|
101
|
-
_defineProperty(
|
|
102
|
-
|
|
103
|
-
visible: visible &&
|
|
43
|
+
_defineProperty(this, "textRef", /*#__PURE__*/React.createRef());
|
|
44
|
+
_defineProperty(this, "handlerVisibleChange", visible => {
|
|
45
|
+
this.setState({
|
|
46
|
+
visible: visible && this.showTooltip()
|
|
104
47
|
});
|
|
105
48
|
});
|
|
106
|
-
return _this;
|
|
107
49
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"tooltipProps": tooltipProps,
|
|
173
|
-
"advanceMode": advanceMode
|
|
174
|
-
}, other)), /*#__PURE__*/React.createElement(Children, _ref2.cn("Children", {})));
|
|
175
|
-
}
|
|
176
|
-
return _ref3 = sstyled(styles), /*#__PURE__*/React.createElement(SContainer, _ref3.cn("SContainer", _objectSpread(_objectSpread({
|
|
177
|
-
"interaction": tooltip ? 'hover' : 'none',
|
|
178
|
-
"title": !advanceMode ? text : undefined
|
|
179
|
-
}, tooltipProps), advanceMode ? forcedAdvancedMode : noAdvancedMode)), advanceMode ? /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {})) : /*#__PURE__*/React.createElement(SEllipsis, _ref3.cn("SEllipsis", _objectSpread({
|
|
180
|
-
"render": Box,
|
|
181
|
-
"ref": this.textRef,
|
|
182
|
-
"maxLine": maxLine
|
|
183
|
-
}, other)), /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {}))));
|
|
50
|
+
showTooltip() {
|
|
51
|
+
const {
|
|
52
|
+
maxLine = 1,
|
|
53
|
+
Children
|
|
54
|
+
} = this.asProps;
|
|
55
|
+
const text = reactToText(getOriginChildren(Children));
|
|
56
|
+
return isTextOverflowing(this.textRef.current, maxLine > 1, text);
|
|
57
|
+
}
|
|
58
|
+
getContentProps() {
|
|
59
|
+
return {
|
|
60
|
+
ref: this.textRef,
|
|
61
|
+
maxLine: this.asProps.maxLine
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getPopperProps() {
|
|
65
|
+
const {
|
|
66
|
+
Children,
|
|
67
|
+
includeTooltipProps
|
|
68
|
+
} = this.asProps;
|
|
69
|
+
const text = reactToText(getOriginChildren(Children));
|
|
70
|
+
const tooltipProps = pick(this.asProps, includeTooltipProps);
|
|
71
|
+
return {
|
|
72
|
+
children: text,
|
|
73
|
+
...tooltipProps
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
var _ref3;
|
|
78
|
+
const SEllipsis = this.Root;
|
|
79
|
+
const SContainer = Tooltip;
|
|
80
|
+
const {
|
|
81
|
+
styles,
|
|
82
|
+
Children,
|
|
83
|
+
maxLine,
|
|
84
|
+
tooltip,
|
|
85
|
+
trim,
|
|
86
|
+
containerRect,
|
|
87
|
+
containerRef,
|
|
88
|
+
includeTooltipProps,
|
|
89
|
+
children: _children,
|
|
90
|
+
...other
|
|
91
|
+
} = this.asProps;
|
|
92
|
+
const {
|
|
93
|
+
visible
|
|
94
|
+
} = this.state;
|
|
95
|
+
const advancedContent = findComponent(Children, [Ellipsis.Content.displayName]);
|
|
96
|
+
const text = reactToText(advancedContent || getOriginChildren(Children));
|
|
97
|
+
const advanceMode = isAdvanceMode(Children, [Ellipsis.Content.displayName, Ellipsis.Popper.displayName]);
|
|
98
|
+
const tooltipProps = pick(this.asProps, includeTooltipProps);
|
|
99
|
+
tooltipProps.visible = tooltipProps.visible ?? visible;
|
|
100
|
+
tooltipProps.onVisibleChange = tooltipProps.onVisibleChange ? callAllEventHandlers(tooltipProps.onVisibleChange, this.handlerVisibleChange) : this.handlerVisibleChange;
|
|
101
|
+
if (trim === 'middle') {
|
|
102
|
+
var _ref2;
|
|
103
|
+
return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(EllipsisMiddle, _ref2.cn("EllipsisMiddle", {
|
|
104
|
+
"text": text,
|
|
105
|
+
"styles": styles,
|
|
106
|
+
"tooltip": tooltip,
|
|
107
|
+
"containerRect": containerRect,
|
|
108
|
+
"containerRef": containerRef,
|
|
109
|
+
"textRef": this.textRef,
|
|
110
|
+
"tooltipProps": tooltipProps,
|
|
111
|
+
"advanceMode": advanceMode,
|
|
112
|
+
...other
|
|
113
|
+
}), /*#__PURE__*/React.createElement(Children, _ref2.cn("Children", {})));
|
|
184
114
|
}
|
|
185
|
-
|
|
186
|
-
|
|
115
|
+
return _ref3 = sstyled(styles), /*#__PURE__*/React.createElement(SContainer, _ref3.cn("SContainer", {
|
|
116
|
+
"interaction": tooltip ? 'hover' : 'none',
|
|
117
|
+
"title": !advanceMode ? text : undefined,
|
|
118
|
+
...tooltipProps,
|
|
119
|
+
...(advanceMode ? forcedAdvancedMode : noAdvancedMode)
|
|
120
|
+
}), advanceMode ? /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {})) : /*#__PURE__*/React.createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
121
|
+
"render": Box,
|
|
122
|
+
"ref": this.textRef,
|
|
123
|
+
"maxLine": maxLine,
|
|
124
|
+
...other
|
|
125
|
+
}), /*#__PURE__*/React.createElement(Children, _ref3.cn("Children", {}))));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
187
128
|
_defineProperty(RootEllipsis, "displayName", 'Ellipsis');
|
|
188
129
|
_defineProperty(RootEllipsis, "style", style);
|
|
189
130
|
_defineProperty(RootEllipsis, "defaultProps", {
|
|
@@ -192,92 +133,99 @@ _defineProperty(RootEllipsis, "defaultProps", {
|
|
|
192
133
|
includeTooltipProps: defaultTooltipProps,
|
|
193
134
|
__excludeProps: ['title']
|
|
194
135
|
});
|
|
195
|
-
|
|
196
|
-
|
|
136
|
+
const EllipsisMiddleContext = /*#__PURE__*/React.createContext(null);
|
|
137
|
+
function EllipsisMiddle(props) {
|
|
197
138
|
var _ref5;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var node = (containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) || (resizeElement === null || resizeElement === void 0 ? void 0 : resizeElement.current);
|
|
139
|
+
const {
|
|
140
|
+
styles,
|
|
141
|
+
text,
|
|
142
|
+
tooltip,
|
|
143
|
+
containerRect,
|
|
144
|
+
containerRef,
|
|
145
|
+
textRef,
|
|
146
|
+
tooltipProps,
|
|
147
|
+
children,
|
|
148
|
+
advanceMode,
|
|
149
|
+
tag
|
|
150
|
+
} = props;
|
|
151
|
+
const resizeElement = React.useRef(null);
|
|
152
|
+
const [symbolWidth, setSymbolWidth] = React.useState(0);
|
|
153
|
+
const blockWidth = useResizeObserver(resizeElement, containerRect).width;
|
|
154
|
+
useEnhancedEffect(() => {
|
|
155
|
+
const node = containerRef?.current || resizeElement?.current;
|
|
216
156
|
if (!node) return;
|
|
217
|
-
|
|
218
|
-
|
|
157
|
+
const styleElement = window.getComputedStyle(node);
|
|
158
|
+
const dateSpan = document.createElement('temporary-block');
|
|
219
159
|
setFontSettings(dateSpan, styleElement);
|
|
220
160
|
dateSpan.textContent = 'a';
|
|
221
161
|
document.body.appendChild(dateSpan);
|
|
222
|
-
|
|
162
|
+
const rect = dateSpan.getBoundingClientRect();
|
|
223
163
|
setSymbolWidth(rect.width);
|
|
224
164
|
document.body.removeChild(dateSpan);
|
|
225
165
|
}, []);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
166
|
+
const STail = 'span';
|
|
167
|
+
const SBeginning = 'span';
|
|
168
|
+
const SContainerMiddle = Tooltip;
|
|
169
|
+
const SAdvancedModeContainerMiddle = Tooltip;
|
|
170
|
+
const displayedSymbols = React.useMemo(() => {
|
|
171
|
+
const displayedSymbols = Math.round(blockWidth / symbolWidth);
|
|
232
172
|
return displayedSymbols % 2 === 0 ? displayedSymbols : displayedSymbols - 1;
|
|
233
173
|
}, [blockWidth, symbolWidth]);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
242
|
-
}, [text, displayedSymbols]);
|
|
174
|
+
const interaction = text.length > displayedSymbols ? 'hover' : 'none';
|
|
175
|
+
const ref = containerRef ?? resizeElement;
|
|
176
|
+
const contextValue = React.useMemo(() => ({
|
|
177
|
+
begining: text.substring(0, text.length - displayedSymbols / 2 - 1),
|
|
178
|
+
tail: text.substring(text.length - displayedSymbols / 2 - 1),
|
|
179
|
+
ref
|
|
180
|
+
}), [text, displayedSymbols]);
|
|
243
181
|
if (advanceMode) {
|
|
244
182
|
var _ref4;
|
|
245
|
-
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SAdvancedModeContainerMiddle, _ref4.cn("SAdvancedModeContainerMiddle",
|
|
246
|
-
"interaction": tooltip ? interaction : 'none'
|
|
247
|
-
|
|
183
|
+
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(SAdvancedModeContainerMiddle, _ref4.cn("SAdvancedModeContainerMiddle", {
|
|
184
|
+
"interaction": tooltip ? interaction : 'none',
|
|
185
|
+
...tooltipProps,
|
|
186
|
+
...forcedAdvancedMode
|
|
187
|
+
}), /*#__PURE__*/React.createElement(EllipsisMiddleContext.Provider, {
|
|
248
188
|
value: contextValue
|
|
249
189
|
}, children));
|
|
250
190
|
}
|
|
251
|
-
return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(SContainerMiddle, _ref5.cn("SContainerMiddle",
|
|
191
|
+
return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(SContainerMiddle, _ref5.cn("SContainerMiddle", {
|
|
252
192
|
"interaction": tooltip ? interaction : 'none',
|
|
253
193
|
"title": text,
|
|
254
194
|
"ref": forkRef(ref, textRef),
|
|
255
|
-
"tag": tag
|
|
256
|
-
|
|
257
|
-
};
|
|
258
|
-
|
|
195
|
+
"tag": tag,
|
|
196
|
+
...tooltipProps
|
|
197
|
+
}), /*#__PURE__*/React.createElement(SBeginning, _ref5.cn("SBeginning", {}), contextValue.begining), /*#__PURE__*/React.createElement(STail, _ref5.cn("STail", {}), contextValue.tail));
|
|
198
|
+
}
|
|
199
|
+
function Content({
|
|
200
|
+
styles,
|
|
201
|
+
Children
|
|
202
|
+
}) {
|
|
259
203
|
var _ref = arguments[0],
|
|
260
204
|
_ref7;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
var STail = 'span';
|
|
266
|
-
var SBeginning = 'span';
|
|
205
|
+
const SEllipsis = Tooltip.Trigger;
|
|
206
|
+
const ellipsisMiddleContext = React.useContext(EllipsisMiddleContext);
|
|
207
|
+
const STail = 'span';
|
|
208
|
+
const SBeginning = 'span';
|
|
267
209
|
if (ellipsisMiddleContext) {
|
|
268
210
|
var _ref6;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
211
|
+
const {
|
|
212
|
+
begining,
|
|
213
|
+
tail,
|
|
214
|
+
ref
|
|
215
|
+
} = ellipsisMiddleContext;
|
|
216
|
+
return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(SEllipsis, _ref6.cn("SEllipsis", {
|
|
217
|
+
..._assignProps({
|
|
218
|
+
"middle-mod": true,
|
|
219
|
+
"ref": ref
|
|
220
|
+
}, _ref)
|
|
221
|
+
}), /*#__PURE__*/React.createElement(SBeginning, _ref6.cn("SBeginning", {}), begining), /*#__PURE__*/React.createElement(STail, _ref6.cn("STail", {}), tail));
|
|
276
222
|
}
|
|
277
|
-
return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SEllipsis, _ref7.cn("SEllipsis",
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
223
|
+
return _ref7 = sstyled(styles), /*#__PURE__*/React.createElement(SEllipsis, _ref7.cn("SEllipsis", {
|
|
224
|
+
..._assignProps2({}, _ref)
|
|
225
|
+
}), /*#__PURE__*/React.createElement(Children, _ref7.cn("Children", {})));
|
|
226
|
+
}
|
|
227
|
+
const Ellipsis = createComponent(RootEllipsis, {
|
|
228
|
+
Content,
|
|
281
229
|
Popper: Tooltip.Popper
|
|
282
230
|
});
|
|
283
231
|
export default Ellipsis;
|