@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.
package/dist/web.esm.js CHANGED
@@ -2665,30 +2665,37 @@ var TruncateText = function TruncateText(_ref2) {
2665
2665
  _ref2$maxLines = _ref2.maxLines,
2666
2666
  maxLines = _ref2$maxLines === void 0 ? 1 : _ref2$maxLines;
2667
2667
  var containerRef = useRef(null);
2668
- var _useState = useState(text),
2669
- content = _useState[0],
2670
- setContent = _useState[1];
2668
+ var _useState = useState(text.length),
2669
+ truncatedLength = _useState[0],
2670
+ setTruncatedLength = _useState[1];
2671
2671
  useEffect(function () {
2672
- var textContent = content;
2673
2672
  var textNode = containerRef.current;
2674
- if (textNode) {
2675
- var contentHeight = textNode.offsetHeight;
2673
+ if (!textNode) return;
2674
+ var updateTruncatedText = function updateTruncatedText() {
2676
2675
  var comLineHeight = getComputedStyle(textNode).lineHeight;
2677
2676
  var lineHeight = comLineHeight !== 'normal' ? parseFloat(comLineHeight) : 20;
2678
- var maxHeight = Math.ceil(lineHeight * maxLines);
2679
- if (contentHeight > maxHeight) {
2680
- textContent = textContent.slice(0, -1);
2681
- } else if (contentHeight === maxHeight) {
2682
- if (content.length !== text.length) {
2683
- textContent = textContent.slice(0, -3) + '...';
2677
+ var maxHeight = lineHeight * maxLines;
2678
+ var start = 0;
2679
+ var end = text.length;
2680
+ var middle;
2681
+ while (start <= end) {
2682
+ middle = Math.floor((start + end) / 2);
2683
+ textNode.innerText = text.substring(0, middle) + '...';
2684
+ var currentHeight = textNode.offsetHeight;
2685
+ if (currentHeight > maxHeight) {
2686
+ end = middle - 1;
2687
+ } else {
2688
+ start = middle + 1;
2684
2689
  }
2685
2690
  }
2686
- setContent(textContent);
2687
- }
2688
- }, [maxLines, text, containerRef, content]);
2691
+ setTruncatedLength(end);
2692
+ };
2693
+ updateTruncatedText();
2694
+ }, [text, maxLines]);
2695
+ var displayText = text.length > truncatedLength ? text.substring(0, truncatedLength) + '...' : text;
2689
2696
  return React.createElement("div", {
2690
2697
  ref: containerRef
2691
- }, content);
2698
+ }, displayText);
2692
2699
  };
2693
2700
  var TextView = function TextView(_ref3) {
2694
2701
  var children = _ref3.children,