@app-studio/web 0.3.51 → 0.3.53

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
- content = _useState[0],
2677
- setContent = _useState[1];
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
- var contentHeight = textNode.offsetHeight;
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 = Math.ceil(lineHeight * maxLines);
2686
- if (contentHeight > maxHeight) {
2687
- textContent = textContent.slice(0, -1);
2688
- } else if (contentHeight === maxHeight) {
2689
- if (content.length !== text.length) {
2690
- textContent = textContent.slice(0, -3) + '...';
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
- setContent(textContent);
2694
- }
2695
- }, [maxLines, text, containerRef, content]);
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
- }, content);
2705
+ }, displayText);
2699
2706
  };
2700
2707
  var TextView = function TextView(_ref3) {
2701
2708
  var children = _ref3.children,