@semcore/ellipsis 16.0.12 → 17.0.0-prerelease.17
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 +6 -0
- package/README.md +4 -4
- package/lib/cjs/Ellipsis.js +181 -233
- 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 +170 -222
- 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 +172 -194
- 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
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import canUseDOM from '@semcore/core/lib/utils/canUseDOM';
|
|
3
2
|
import useEnhancedEffect from '@semcore/core/lib/utils/use/useEnhancedEffect';
|
|
4
3
|
import React from 'react';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
width = _React$useState2[0],
|
|
9
|
-
setWidth = _React$useState2[1];
|
|
10
|
-
var handleResize = React.useCallback(function (entries) {
|
|
4
|
+
export const useResizeObserver = (ref, hookOverride) => {
|
|
5
|
+
const [width, setWidth] = React.useState(0);
|
|
6
|
+
const handleResize = React.useCallback(entries => {
|
|
11
7
|
setWidth(entries[0].contentRect.width);
|
|
12
8
|
}, []);
|
|
13
|
-
useEnhancedEffect(
|
|
9
|
+
useEnhancedEffect(() => {
|
|
14
10
|
if (!ref.current) {
|
|
15
11
|
return;
|
|
16
12
|
}
|
|
@@ -18,11 +14,11 @@ export var useResizeObserver = function useResizeObserver(ref, hookOverride) {
|
|
|
18
14
|
return;
|
|
19
15
|
}
|
|
20
16
|
if (canUseDOM()) {
|
|
21
|
-
|
|
17
|
+
const ro = new ResizeObserver(entries => {
|
|
22
18
|
handleResize(entries);
|
|
23
19
|
});
|
|
24
20
|
ro.observe(ref.current);
|
|
25
|
-
return
|
|
21
|
+
return () => {
|
|
26
22
|
ro.disconnect();
|
|
27
23
|
};
|
|
28
24
|
}
|
|
@@ -31,7 +27,7 @@ export var useResizeObserver = function useResizeObserver(ref, hookOverride) {
|
|
|
31
27
|
return hookOverride;
|
|
32
28
|
}
|
|
33
29
|
return {
|
|
34
|
-
width
|
|
30
|
+
width
|
|
35
31
|
};
|
|
36
32
|
};
|
|
37
33
|
//# sourceMappingURL=useResizeObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.js","names":["canUseDOM","useEnhancedEffect","React","useResizeObserver","ref","hookOverride","
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","names":["canUseDOM","useEnhancedEffect","React","useResizeObserver","ref","hookOverride","width","setWidth","useState","handleResize","useCallback","entries","contentRect","current","ro","ResizeObserver","observe","disconnect"],"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,OAAOA,SAAS,MAAM,mCAAmC;AACzD,OAAOC,iBAAiB,MAAM,+CAA+C;AAC7E,OAAOC,KAAK,MAA0B,OAAO;AAE7C,OAAO,MAAMC,iBAAiB,GAAGA,CAC/BC,GAA2B,EAC3BC,YAAgC,KAC7B;EACH,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGL,KAAK,CAACM,QAAQ,CAAS,CAAC,CAAC;EAEnD,MAAMC,YAAY,GAAGP,KAAK,CAACQ,WAAW,CAAEC,OAA8B,IAAK;IACzEJ,QAAQ,CAACI,OAAO,CAAC,CAAC,CAAC,CAACC,WAAW,CAACN,KAAK,CAAC;EACxC,CAAC,EAAE,EAAE,CAAC;EAENL,iBAAiB,CAAC,MAAM;IACtB,IAAI,CAACG,GAAG,CAACS,OAAO,EAAE;MAChB;IACF;IAEA,IAAIR,YAAY,EAAE;MAChB;IACF;IACA,IAAIL,SAAS,CAAC,CAAC,EAAE;MACf,MAAMc,EAAE,GAAG,IAAIC,cAAc,CAAEJ,OAA8B,IAAK;QAChEF,YAAY,CAACE,OAAO,CAAC;MACvB,CAAC,CAAC;MAEFG,EAAE,CAACE,OAAO,CAACZ,GAAG,CAACS,OAAO,CAAC;MAEvB,OAAO,MAAM;QACXC,EAAE,CAACG,UAAU,CAAC,CAAC;MACjB,CAAC;IACH;EACF,CAAC,EAAE,CAACZ,YAAY,CAAC,CAAC;EAElB,IAAIA,YAAY,EAAE;IAChB,OAAOA,YAAY;EACrB;EACA,OAAO;IAAEC;EAAM,CAAC;AAClB,CAAC","ignoreList":[]}
|
package/lib/es6/utils.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const setFontSettings = (element, styleElement) => {
|
|
2
|
+
element.style.fontFamily = styleElement.getPropertyValue('font-family');
|
|
3
|
+
element.style.fontSize = styleElement.getPropertyValue('font-size');
|
|
4
|
+
element.style.fontWeight = styleElement.getPropertyValue('font-weight');
|
|
5
|
+
element.style.lineHeight = styleElement.getPropertyValue('line-height');
|
|
6
|
+
element.style.fontFeatureSettings = styleElement.getPropertyValue('font-feature-settings');
|
|
7
|
+
element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');
|
|
8
|
+
};
|
|
9
|
+
export function isTextOverflowing(element, multiline, text) {
|
|
10
|
+
if (!element) return false;
|
|
11
|
+
const {
|
|
12
|
+
height: currentHeight,
|
|
13
|
+
width: currentWidth
|
|
14
|
+
} = element.getBoundingClientRect();
|
|
15
|
+
const measuringElement = createMeasurerElement(element, text);
|
|
16
|
+
let isOverflowing = false;
|
|
17
|
+
document.body.appendChild(measuringElement);
|
|
18
|
+
if (multiline) {
|
|
19
|
+
measuringElement.style.width = `${currentWidth}px`;
|
|
20
|
+
const width = measuringElement.scrollWidth;
|
|
21
|
+
const height = measuringElement.getBoundingClientRect().height;
|
|
22
|
+
if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
|
|
23
|
+
isOverflowing = true;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
measuringElement.style.whiteSpace = 'nowrap';
|
|
27
|
+
isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
|
|
28
|
+
}
|
|
29
|
+
document.body.removeChild(measuringElement);
|
|
30
|
+
return isOverflowing;
|
|
31
|
+
}
|
|
32
|
+
function createMeasurerElement(element, text) {
|
|
33
|
+
const styleElement = window.getComputedStyle(element, null);
|
|
34
|
+
const temporaryElement = document.createElement('temporary-block');
|
|
35
|
+
temporaryElement.style.display = styleElement.getPropertyValue('display');
|
|
36
|
+
temporaryElement.style.padding = styleElement.getPropertyValue('padding');
|
|
37
|
+
temporaryElement.style.position = 'absolute';
|
|
38
|
+
temporaryElement.style.right = '0%';
|
|
39
|
+
temporaryElement.style.bottom = '0%';
|
|
40
|
+
temporaryElement.style.visibility = 'hidden';
|
|
41
|
+
temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');
|
|
42
|
+
temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');
|
|
43
|
+
setFontSettings(temporaryElement, styleElement);
|
|
44
|
+
temporaryElement.textContent = text ?? element.textContent;
|
|
45
|
+
return temporaryElement;
|
|
46
|
+
}
|
|
47
|
+
//# 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","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/esm/Ellipsis.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
5
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
6
|
-
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
7
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
8
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
|
-
import { createComponent,
|
|
2
|
+
import { createComponent, Component, sstyled, assignProps } from "@semcore/core";
|
|
3
|
+
import { Box } from "@semcore/base-components";
|
|
10
4
|
import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
|
|
11
5
|
import findComponent, { isAdvanceMode } from "@semcore/core/lib/utils/findComponent";
|
|
12
6
|
import getOriginChildren from "@semcore/core/lib/utils/getOriginChildren";
|
|
@@ -14,165 +8,127 @@ import pick from "@semcore/core/lib/utils/pick";
|
|
|
14
8
|
import reactToText from "@semcore/core/lib/utils/reactToText";
|
|
15
9
|
import { forkRef } from "@semcore/core/lib/utils/ref";
|
|
16
10
|
import useEnhancedEffect from "@semcore/core/lib/utils/use/useEnhancedEffect";
|
|
17
|
-
import { Box } from "@semcore/flex-box";
|
|
18
11
|
import Tooltip from "@semcore/tooltip";
|
|
19
12
|
import React from "react";
|
|
20
13
|
import { useResizeObserver } from "./useResizeObserver.mjs";
|
|
21
|
-
|
|
14
|
+
import { isTextOverflowing, setFontSettings } from "./utils.mjs";
|
|
22
15
|
/*!__reshadow-styles__:"./style/ellipsis.shadow.css"*/
|
|
23
|
-
|
|
16
|
+
const style = (
|
|
24
17
|
/*__reshadow_css_start__*/
|
|
25
18
|
(sstyled.insert(
|
|
26
19
|
/*__inner_css_start__*/
|
|
27
|
-
".
|
|
20
|
+
".___SBeginning_1x34o_gg_,.___SEllipsis_1x34o_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:pre}.___SEllipsis_1x34o_gg_.__maxLine_1x34o_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_1x34o);-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-wrap:break-word}.___SContainerMiddle_1x34o_gg_,.___SContainer_1x34o_gg_,.___SEllipsis_1x34o_gg_.__middle-mod_1x34o_gg_,.___SNoTooltipContainer_1x34o_gg_{display:flex;overflow:hidden}.___SContainerMiddle_1x34o_gg_>:has(.___SBeginning_1x34o_gg_),.___SContainerMiddle_1x34o_gg_>:has(.___STail_1x34o_gg_){display:flex;width:100%}.___STail_1x34o_gg_{white-space:pre}",
|
|
28
21
|
/*__inner_css_end__*/
|
|
29
|
-
"
|
|
22
|
+
"1x34o_gg_"
|
|
30
23
|
), /*__reshadow_css_end__*/
|
|
31
24
|
{
|
|
32
|
-
"__SBeginning": "
|
|
33
|
-
"__SEllipsis": "
|
|
34
|
-
"__SContainer": "
|
|
35
|
-
"__SNoTooltipContainer": "
|
|
36
|
-
"__SContainerMiddle": "
|
|
37
|
-
"_maxLine": "
|
|
38
|
-
"--maxLine": "--
|
|
39
|
-
"_middle-mod": "__middle-
|
|
40
|
-
"__STail": "
|
|
25
|
+
"__SBeginning": "___SBeginning_1x34o_gg_",
|
|
26
|
+
"__SEllipsis": "___SEllipsis_1x34o_gg_",
|
|
27
|
+
"__SContainer": "___SContainer_1x34o_gg_",
|
|
28
|
+
"__SNoTooltipContainer": "___SNoTooltipContainer_1x34o_gg_",
|
|
29
|
+
"__SContainerMiddle": "___SContainerMiddle_1x34o_gg_",
|
|
30
|
+
"_maxLine": "__maxLine_1x34o_gg_",
|
|
31
|
+
"--maxLine": "--maxLine_1x34o",
|
|
32
|
+
"_middle-mod": "__middle-mod_1x34o_gg_",
|
|
33
|
+
"__STail": "___STail_1x34o_gg_"
|
|
41
34
|
})
|
|
42
35
|
);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
element.style.fontFamily = styleElement.getPropertyValue("font-family");
|
|
46
|
-
element.style.fontSize = styleElement.getPropertyValue("font-size");
|
|
47
|
-
element.style.fontWeight = styleElement.getPropertyValue("font-weight");
|
|
48
|
-
element.style.lineHeight = styleElement.getPropertyValue("line-height");
|
|
49
|
-
element.style.fontFeatureSettings = styleElement.getPropertyValue("font-feature-settings");
|
|
50
|
-
element.style.fontVariantNumeric = styleElement.getPropertyValue("font-variant-numeric");
|
|
51
|
-
};
|
|
52
|
-
var createMeasurerElement = function createMeasurerElement2(element, text) {
|
|
53
|
-
var styleElement = window.getComputedStyle(element, null);
|
|
54
|
-
var temporaryElement = document.createElement("temporary-block");
|
|
55
|
-
temporaryElement.style.display = styleElement.getPropertyValue("display");
|
|
56
|
-
temporaryElement.style.padding = styleElement.getPropertyValue("padding");
|
|
57
|
-
temporaryElement.style.position = "absolute";
|
|
58
|
-
temporaryElement.style.right = "0%";
|
|
59
|
-
temporaryElement.style.bottom = "0%";
|
|
60
|
-
temporaryElement.style.visibility = "hidden";
|
|
61
|
-
temporaryElement.style.whiteSpace = styleElement.getPropertyValue("white-space");
|
|
62
|
-
temporaryElement.style.wordWrap = styleElement.getPropertyValue("word-wrap");
|
|
63
|
-
setFontSettings(temporaryElement, styleElement);
|
|
64
|
-
temporaryElement.textContent = text !== null && text !== void 0 ? text : element.textContent;
|
|
65
|
-
return temporaryElement;
|
|
66
|
-
};
|
|
67
|
-
function isTextOverflowing(element, multiline, text) {
|
|
68
|
-
if (!element) return false;
|
|
69
|
-
var _element$getBoundingC = element.getBoundingClientRect(), currentHeight = _element$getBoundingC.height, currentWidth = _element$getBoundingC.width;
|
|
70
|
-
var measuringElement = createMeasurerElement(element, text);
|
|
71
|
-
var isOverflowing = false;
|
|
72
|
-
document.body.appendChild(measuringElement);
|
|
73
|
-
if (multiline) {
|
|
74
|
-
measuringElement.style.width = "".concat(currentWidth, "px");
|
|
75
|
-
var width = measuringElement.scrollWidth;
|
|
76
|
-
var height = measuringElement.getBoundingClientRect().height;
|
|
77
|
-
if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
|
|
78
|
-
isOverflowing = true;
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
measuringElement.style.whiteSpace = "nowrap";
|
|
82
|
-
isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
|
|
83
|
-
}
|
|
84
|
-
document.body.removeChild(measuringElement);
|
|
85
|
-
return isOverflowing;
|
|
86
|
-
}
|
|
87
|
-
var forcedAdvancedMode = {
|
|
36
|
+
const defaultTooltipProps = ["title", "theme", "strategy", "modifiers", "placement", "interaction", "timeout", "visible", "defaultVisible", "onVisibleChange", "offset", "preventOverflow", "arrow", "flip", "computeStyles", "eventListeners", "onFirstUpdate", "cursorAnchoring"];
|
|
37
|
+
const forcedAdvancedMode = {
|
|
88
38
|
forcedAdvancedMode: true
|
|
89
39
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
96
|
-
args[_key] = arguments[_key];
|
|
97
|
-
}
|
|
98
|
-
_this = _callSuper(this, RootEllipsis2, [].concat(args));
|
|
99
|
-
_defineProperty(_this, "state", {
|
|
40
|
+
const noAdvancedMode = {};
|
|
41
|
+
class RootEllipsis extends Component {
|
|
42
|
+
constructor(...args) {
|
|
43
|
+
super(...args);
|
|
44
|
+
_defineProperty(this, "state", {
|
|
100
45
|
visible: false
|
|
101
46
|
});
|
|
102
|
-
_defineProperty(
|
|
103
|
-
_defineProperty(
|
|
104
|
-
|
|
105
|
-
visible: visible &&
|
|
47
|
+
_defineProperty(this, "textRef", /* @__PURE__ */ React.createRef());
|
|
48
|
+
_defineProperty(this, "handlerVisibleChange", (visible) => {
|
|
49
|
+
this.setState({
|
|
50
|
+
visible: visible && this.showTooltip()
|
|
106
51
|
});
|
|
107
52
|
});
|
|
108
|
-
return _this;
|
|
109
53
|
}
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
|
|
54
|
+
showTooltip() {
|
|
55
|
+
const {
|
|
56
|
+
maxLine = 1,
|
|
57
|
+
Children
|
|
58
|
+
} = this.asProps;
|
|
59
|
+
const text = reactToText(getOriginChildren(Children));
|
|
60
|
+
return isTextOverflowing(this.textRef.current, maxLine > 1, text);
|
|
61
|
+
}
|
|
62
|
+
getContentProps() {
|
|
63
|
+
return {
|
|
64
|
+
ref: this.textRef,
|
|
65
|
+
maxLine: this.asProps.maxLine
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
getPopperProps() {
|
|
69
|
+
const {
|
|
70
|
+
Children,
|
|
71
|
+
includeTooltipProps
|
|
72
|
+
} = this.asProps;
|
|
73
|
+
const text = reactToText(getOriginChildren(Children));
|
|
74
|
+
const tooltipProps = pick(this.asProps, includeTooltipProps);
|
|
75
|
+
return {
|
|
76
|
+
children: text,
|
|
77
|
+
...tooltipProps
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
var _ref3;
|
|
82
|
+
const SEllipsis = this.Root;
|
|
83
|
+
const SContainer = Tooltip;
|
|
84
|
+
const {
|
|
85
|
+
styles,
|
|
86
|
+
Children,
|
|
87
|
+
maxLine,
|
|
88
|
+
tooltip,
|
|
89
|
+
trim,
|
|
90
|
+
containerRect,
|
|
91
|
+
containerRef,
|
|
92
|
+
includeTooltipProps,
|
|
93
|
+
children: _children,
|
|
94
|
+
...other
|
|
95
|
+
} = this.asProps;
|
|
96
|
+
const {
|
|
97
|
+
visible
|
|
98
|
+
} = this.state;
|
|
99
|
+
const advancedContent = findComponent(Children, [Ellipsis.Content.displayName]);
|
|
100
|
+
const text = reactToText(advancedContent || getOriginChildren(Children));
|
|
101
|
+
const advanceMode = isAdvanceMode(Children, [Ellipsis.Content.displayName, Ellipsis.Popper.displayName]);
|
|
102
|
+
const tooltipProps = pick(this.asProps, includeTooltipProps);
|
|
103
|
+
tooltipProps.visible = tooltipProps.visible ?? visible;
|
|
104
|
+
tooltipProps.onVisibleChange = tooltipProps.onVisibleChange ? callAllEventHandlers(tooltipProps.onVisibleChange, this.handlerVisibleChange) : this.handlerVisibleChange;
|
|
105
|
+
if (trim === "middle") {
|
|
106
|
+
var _ref2;
|
|
107
|
+
return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(EllipsisMiddle, _ref2.cn("EllipsisMiddle", {
|
|
108
|
+
"text": text,
|
|
109
|
+
"styles": styles,
|
|
110
|
+
"tooltip": tooltip,
|
|
111
|
+
"containerRect": containerRect,
|
|
112
|
+
"containerRef": containerRef,
|
|
113
|
+
"textRef": this.textRef,
|
|
114
|
+
"tooltipProps": tooltipProps,
|
|
115
|
+
"advanceMode": advanceMode,
|
|
116
|
+
...other
|
|
117
|
+
}), /* @__PURE__ */ React.createElement(Children, _ref2.cn("Children", {})));
|
|
173
118
|
}
|
|
174
|
-
|
|
175
|
-
|
|
119
|
+
return _ref3 = sstyled(styles), /* @__PURE__ */ React.createElement(SContainer, _ref3.cn("SContainer", {
|
|
120
|
+
"interaction": tooltip ? "hover" : "none",
|
|
121
|
+
"title": !advanceMode ? text : void 0,
|
|
122
|
+
...tooltipProps,
|
|
123
|
+
...advanceMode ? forcedAdvancedMode : noAdvancedMode
|
|
124
|
+
}), advanceMode ? /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {})) : /* @__PURE__ */ React.createElement(SEllipsis, _ref3.cn("SEllipsis", {
|
|
125
|
+
"render": Box,
|
|
126
|
+
"ref": this.textRef,
|
|
127
|
+
"maxLine": maxLine,
|
|
128
|
+
...other
|
|
129
|
+
}), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
176
132
|
_defineProperty(RootEllipsis, "displayName", "Ellipsis");
|
|
177
133
|
_defineProperty(RootEllipsis, "style", style);
|
|
178
134
|
_defineProperty(RootEllipsis, "defaultProps", {
|
|
@@ -181,75 +137,97 @@ _defineProperty(RootEllipsis, "defaultProps", {
|
|
|
181
137
|
includeTooltipProps: defaultTooltipProps,
|
|
182
138
|
__excludeProps: ["title"]
|
|
183
139
|
});
|
|
184
|
-
|
|
185
|
-
|
|
140
|
+
const EllipsisMiddleContext = /* @__PURE__ */ React.createContext(null);
|
|
141
|
+
function EllipsisMiddle(props) {
|
|
186
142
|
var _ref5;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
143
|
+
const {
|
|
144
|
+
styles,
|
|
145
|
+
text,
|
|
146
|
+
tooltip,
|
|
147
|
+
containerRect,
|
|
148
|
+
containerRef,
|
|
149
|
+
textRef,
|
|
150
|
+
tooltipProps,
|
|
151
|
+
children,
|
|
152
|
+
advanceMode,
|
|
153
|
+
tag
|
|
154
|
+
} = props;
|
|
155
|
+
const resizeElement = React.useRef(null);
|
|
156
|
+
const [symbolWidth, setSymbolWidth] = React.useState(0);
|
|
157
|
+
const blockWidth = useResizeObserver(resizeElement, containerRect).width;
|
|
158
|
+
useEnhancedEffect(() => {
|
|
159
|
+
const node = (containerRef == null ? void 0 : containerRef.current) || (resizeElement == null ? void 0 : resizeElement.current);
|
|
193
160
|
if (!node) return;
|
|
194
|
-
|
|
195
|
-
|
|
161
|
+
const styleElement = window.getComputedStyle(node);
|
|
162
|
+
const dateSpan = document.createElement("temporary-block");
|
|
196
163
|
setFontSettings(dateSpan, styleElement);
|
|
197
164
|
dateSpan.textContent = "a";
|
|
198
165
|
document.body.appendChild(dateSpan);
|
|
199
|
-
|
|
166
|
+
const rect = dateSpan.getBoundingClientRect();
|
|
200
167
|
setSymbolWidth(rect.width);
|
|
201
168
|
document.body.removeChild(dateSpan);
|
|
202
169
|
}, []);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
170
|
+
const STail = "span";
|
|
171
|
+
const SBeginning = "span";
|
|
172
|
+
const SContainerMiddle = Tooltip;
|
|
173
|
+
const SAdvancedModeContainerMiddle = Tooltip;
|
|
174
|
+
const displayedSymbols = React.useMemo(() => {
|
|
175
|
+
const displayedSymbols2 = Math.round(blockWidth / symbolWidth);
|
|
209
176
|
return displayedSymbols2 % 2 === 0 ? displayedSymbols2 : displayedSymbols2 - 1;
|
|
210
177
|
}, [blockWidth, symbolWidth]);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
};
|
|
219
|
-
}, [text, displayedSymbols]);
|
|
178
|
+
const interaction = text.length > displayedSymbols ? "hover" : "none";
|
|
179
|
+
const ref = containerRef ?? resizeElement;
|
|
180
|
+
const contextValue = React.useMemo(() => ({
|
|
181
|
+
begining: text.substring(0, text.length - displayedSymbols / 2 - 1),
|
|
182
|
+
tail: text.substring(text.length - displayedSymbols / 2 - 1),
|
|
183
|
+
ref
|
|
184
|
+
}), [text, displayedSymbols]);
|
|
220
185
|
if (advanceMode) {
|
|
221
186
|
var _ref4;
|
|
222
|
-
return _ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(SAdvancedModeContainerMiddle, _ref4.cn("SAdvancedModeContainerMiddle",
|
|
223
|
-
"interaction": tooltip ? interaction : "none"
|
|
224
|
-
|
|
187
|
+
return _ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(SAdvancedModeContainerMiddle, _ref4.cn("SAdvancedModeContainerMiddle", {
|
|
188
|
+
"interaction": tooltip ? interaction : "none",
|
|
189
|
+
...tooltipProps,
|
|
190
|
+
...forcedAdvancedMode
|
|
191
|
+
}), /* @__PURE__ */ React.createElement(EllipsisMiddleContext.Provider, {
|
|
225
192
|
value: contextValue
|
|
226
193
|
}, children));
|
|
227
194
|
}
|
|
228
|
-
return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(SContainerMiddle, _ref5.cn("SContainerMiddle",
|
|
195
|
+
return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(SContainerMiddle, _ref5.cn("SContainerMiddle", {
|
|
229
196
|
"interaction": tooltip ? interaction : "none",
|
|
230
197
|
"title": text,
|
|
231
198
|
"ref": forkRef(ref, textRef),
|
|
232
|
-
"tag": tag
|
|
233
|
-
|
|
234
|
-
};
|
|
235
|
-
|
|
199
|
+
"tag": tag,
|
|
200
|
+
...tooltipProps
|
|
201
|
+
}), /* @__PURE__ */ React.createElement(SBeginning, _ref5.cn("SBeginning", {}), contextValue.begining), /* @__PURE__ */ React.createElement(STail, _ref5.cn("STail", {}), contextValue.tail));
|
|
202
|
+
}
|
|
203
|
+
function Content({
|
|
204
|
+
styles,
|
|
205
|
+
Children
|
|
206
|
+
}) {
|
|
236
207
|
var _ref = arguments[0], _ref7;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var SBeginning = "span";
|
|
208
|
+
const SEllipsis = Tooltip.Trigger;
|
|
209
|
+
const ellipsisMiddleContext = React.useContext(EllipsisMiddleContext);
|
|
210
|
+
const STail = "span";
|
|
211
|
+
const SBeginning = "span";
|
|
242
212
|
if (ellipsisMiddleContext) {
|
|
243
213
|
var _ref6;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
214
|
+
const {
|
|
215
|
+
begining,
|
|
216
|
+
tail,
|
|
217
|
+
ref
|
|
218
|
+
} = ellipsisMiddleContext;
|
|
219
|
+
return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref6.cn("SEllipsis", {
|
|
220
|
+
...assignProps({
|
|
221
|
+
"middle-mod": true,
|
|
222
|
+
"ref": ref
|
|
223
|
+
}, _ref)
|
|
224
|
+
}), /* @__PURE__ */ React.createElement(SBeginning, _ref6.cn("SBeginning", {}), begining), /* @__PURE__ */ React.createElement(STail, _ref6.cn("STail", {}), tail));
|
|
249
225
|
}
|
|
250
|
-
return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref7.cn("SEllipsis",
|
|
251
|
-
}
|
|
252
|
-
|
|
226
|
+
return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref7.cn("SEllipsis", {
|
|
227
|
+
...assignProps({}, _ref)
|
|
228
|
+
}), /* @__PURE__ */ React.createElement(Children, _ref7.cn("Children", {})));
|
|
229
|
+
}
|
|
230
|
+
const Ellipsis = createComponent(RootEllipsis, {
|
|
253
231
|
Content,
|
|
254
232
|
Popper: Tooltip.Popper
|
|
255
233
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
import canUseDOM from "@semcore/core/lib/utils/canUseDOM";
|
|
3
2
|
import useEnhancedEffect from "@semcore/core/lib/utils/use/useEnhancedEffect";
|
|
4
3
|
import React from "react";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const useResizeObserver = (ref, hookOverride) => {
|
|
5
|
+
const [width, setWidth] = React.useState(0);
|
|
6
|
+
const handleResize = React.useCallback((entries) => {
|
|
8
7
|
setWidth(entries[0].contentRect.width);
|
|
9
8
|
}, []);
|
|
10
|
-
useEnhancedEffect(
|
|
9
|
+
useEnhancedEffect(() => {
|
|
11
10
|
if (!ref.current) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
@@ -15,11 +14,11 @@ var useResizeObserver = function useResizeObserver2(ref, hookOverride) {
|
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
16
|
if (canUseDOM()) {
|
|
18
|
-
|
|
17
|
+
const ro = new ResizeObserver((entries) => {
|
|
19
18
|
handleResize(entries);
|
|
20
19
|
});
|
|
21
20
|
ro.observe(ref.current);
|
|
22
|
-
return
|
|
21
|
+
return () => {
|
|
23
22
|
ro.disconnect();
|
|
24
23
|
};
|
|
25
24
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const setFontSettings = (element, styleElement) => {
|
|
2
|
+
element.style.fontFamily = styleElement.getPropertyValue("font-family");
|
|
3
|
+
element.style.fontSize = styleElement.getPropertyValue("font-size");
|
|
4
|
+
element.style.fontWeight = styleElement.getPropertyValue("font-weight");
|
|
5
|
+
element.style.lineHeight = styleElement.getPropertyValue("line-height");
|
|
6
|
+
element.style.fontFeatureSettings = styleElement.getPropertyValue("font-feature-settings");
|
|
7
|
+
element.style.fontVariantNumeric = styleElement.getPropertyValue("font-variant-numeric");
|
|
8
|
+
};
|
|
9
|
+
function isTextOverflowing(element, multiline, text) {
|
|
10
|
+
if (!element) return false;
|
|
11
|
+
const {
|
|
12
|
+
height: currentHeight,
|
|
13
|
+
width: currentWidth
|
|
14
|
+
} = element.getBoundingClientRect();
|
|
15
|
+
const measuringElement = createMeasurerElement(element, text);
|
|
16
|
+
let isOverflowing = false;
|
|
17
|
+
document.body.appendChild(measuringElement);
|
|
18
|
+
if (multiline) {
|
|
19
|
+
measuringElement.style.width = `${currentWidth}px`;
|
|
20
|
+
const width = measuringElement.scrollWidth;
|
|
21
|
+
const height = measuringElement.getBoundingClientRect().height;
|
|
22
|
+
if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
|
|
23
|
+
isOverflowing = true;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
measuringElement.style.whiteSpace = "nowrap";
|
|
27
|
+
isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
|
|
28
|
+
}
|
|
29
|
+
document.body.removeChild(measuringElement);
|
|
30
|
+
return isOverflowing;
|
|
31
|
+
}
|
|
32
|
+
function createMeasurerElement(element, text) {
|
|
33
|
+
const styleElement = window.getComputedStyle(element, null);
|
|
34
|
+
const temporaryElement = document.createElement("temporary-block");
|
|
35
|
+
temporaryElement.style.display = styleElement.getPropertyValue("display");
|
|
36
|
+
temporaryElement.style.padding = styleElement.getPropertyValue("padding");
|
|
37
|
+
temporaryElement.style.position = "absolute";
|
|
38
|
+
temporaryElement.style.right = "0%";
|
|
39
|
+
temporaryElement.style.bottom = "0%";
|
|
40
|
+
temporaryElement.style.visibility = "hidden";
|
|
41
|
+
temporaryElement.style.whiteSpace = styleElement.getPropertyValue("white-space");
|
|
42
|
+
temporaryElement.style.wordWrap = styleElement.getPropertyValue("word-wrap");
|
|
43
|
+
setFontSettings(temporaryElement, styleElement);
|
|
44
|
+
temporaryElement.textContent = text ?? element.textContent;
|
|
45
|
+
return temporaryElement;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
isTextOverflowing,
|
|
49
|
+
setFontSettings
|
|
50
|
+
};
|