@app-studio/web 0.3.51 → 0.3.52
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.
|
@@ -2672,30 +2672,37 @@ var TruncateText = function TruncateText(_ref2) {
|
|
|
2672
2672
|
_ref2$maxLines = _ref2.maxLines,
|
|
2673
2673
|
maxLines = _ref2$maxLines === void 0 ? 1 : _ref2$maxLines;
|
|
2674
2674
|
var containerRef = React.useRef(null);
|
|
2675
|
-
var _useState = React.useState(text),
|
|
2676
|
-
|
|
2677
|
-
|
|
2675
|
+
var _useState = React.useState(text.length),
|
|
2676
|
+
truncatedLength = _useState[0],
|
|
2677
|
+
setTruncatedLength = _useState[1];
|
|
2678
2678
|
React.useEffect(function () {
|
|
2679
|
-
var textContent = content;
|
|
2680
2679
|
var textNode = containerRef.current;
|
|
2681
|
-
if (textNode)
|
|
2682
|
-
|
|
2680
|
+
if (!textNode) return;
|
|
2681
|
+
var updateTruncatedText = function updateTruncatedText() {
|
|
2683
2682
|
var comLineHeight = getComputedStyle(textNode).lineHeight;
|
|
2684
2683
|
var lineHeight = comLineHeight !== 'normal' ? parseFloat(comLineHeight) : 20;
|
|
2685
|
-
var maxHeight =
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2684
|
+
var maxHeight = lineHeight * maxLines;
|
|
2685
|
+
var start = 0;
|
|
2686
|
+
var end = text.length;
|
|
2687
|
+
var middle;
|
|
2688
|
+
while (start <= end) {
|
|
2689
|
+
middle = Math.floor((start + end) / 2);
|
|
2690
|
+
textNode.innerText = text.substring(0, middle) + '...';
|
|
2691
|
+
var currentHeight = textNode.offsetHeight;
|
|
2692
|
+
if (currentHeight > maxHeight) {
|
|
2693
|
+
end = middle - 1;
|
|
2694
|
+
} else {
|
|
2695
|
+
start = middle + 1;
|
|
2691
2696
|
}
|
|
2692
2697
|
}
|
|
2693
|
-
|
|
2694
|
-
}
|
|
2695
|
-
|
|
2698
|
+
setTruncatedLength(end);
|
|
2699
|
+
};
|
|
2700
|
+
updateTruncatedText();
|
|
2701
|
+
}, [text, maxLines]);
|
|
2702
|
+
var displayText = text.length > truncatedLength ? text.substring(0, truncatedLength) + '...' : text;
|
|
2696
2703
|
return React__default.createElement("div", {
|
|
2697
2704
|
ref: containerRef
|
|
2698
|
-
},
|
|
2705
|
+
}, displayText);
|
|
2699
2706
|
};
|
|
2700
2707
|
var TextView = function TextView(_ref3) {
|
|
2701
2708
|
var children = _ref3.children,
|