pb-sxp-ui 1.15.22 → 1.15.23

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/index.js CHANGED
@@ -10187,69 +10187,49 @@ const Modal = ({ visible, onClose, children, modalStyle, padding, popup, schema,
10187
10187
  };
10188
10188
  var Modal$1 = memo(Modal);
10189
10189
 
10190
- /*
10191
- * @Author: binruan@chatlabs.com
10192
- * @Date: 2023-12-26 16:11:34
10193
- * @LastEditors: binruan@chatlabs.com
10194
- * @LastEditTime: 2024-11-07 14:27:18
10195
- * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\ExpandableText.tsx
10196
- *
10197
- */
10198
- const limitTextLastWholeWord = (originalText = '', limit) => {
10199
- // 匹配到中文
10200
- const chineseRegex = /[\u4e00-\u9fa5]+/;
10201
- if (chineseRegex.test(originalText)) {
10202
- return originalText.slice(0, 54);
10203
- }
10204
- const words = originalText.split(' ');
10205
- const newWords = [];
10206
- for (let i = 0; i < words.length; i++) {
10207
- newWords.push(words[i]);
10208
- const tempText = newWords.join(' ');
10209
- if (tempText.length >= limit)
10210
- break;
10211
- }
10212
- // const _words = newWords.length === words.length ? newWords : newWords.slice(0, newWords.length - 1);
10213
- const _words = newWords.length > 1 && newWords.length < words.length ? newWords.slice(0, newWords.length - 1) : newWords;
10214
- return _words.join(' ') + ' ';
10215
- };
10216
10190
  const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldText, unfoldText, isPost, onChange }) => {
10217
10191
  const [isShowMore, setIsShowMore] = useState(false);
10218
10192
  const [isShow, setIsShow] = useState(false);
10219
- const lineClamp = Number((style === null || style === void 0 ? void 0 : style.lineClamp) || 2);
10193
+ const _a = style || {}, { lineClamp } = _a, textStyle = __rest(_a, ["lineClamp"]);
10194
+ const textLineClamp = Number(lineClamp || 2);
10220
10195
  const multiRow = useRef(null);
10221
- const multiRowCopy = useRef(null);
10222
- const handleClick = useCallback(() => {
10196
+ const observerRef = useRef();
10197
+ const handleClick = () => {
10223
10198
  setIsShowMore(!isShowMore);
10224
- // onChange?.(!isShowMore);
10225
- }, [isShowMore, onChange]);
10226
- useMemo(() => {
10227
- return !isShowMore && text.length > maxStr ? limitTextLastWholeWord(text, maxStr) + '...' : text;
10228
- }, [text, maxStr, isShowMore]);
10199
+ };
10200
+ const checkOverflow = useCallback(() => {
10201
+ if (!multiRow.current || !isPost)
10202
+ return;
10203
+ const lineHeight = parseInt(getComputedStyle(multiRow.current).lineHeight) || 20;
10204
+ const maxHeight = lineHeight * textLineClamp;
10205
+ // 添加1px容错,解决部分机型计算误差
10206
+ setIsShow(multiRow.current.scrollHeight > maxHeight + 1);
10207
+ }, [isPost, text, textLineClamp]);
10229
10208
  useEffect(() => {
10230
- var _a, _b;
10231
- if (multiRowCopy === null || multiRowCopy === void 0 ? void 0 : multiRowCopy.current)
10232
- multiRowCopy.current.style.display = 'block';
10233
- if (((_a = multiRowCopy === null || multiRowCopy === void 0 ? void 0 : multiRowCopy.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) > ((_b = multiRow === null || multiRow === void 0 ? void 0 : multiRow.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) && isPost) {
10234
- setIsShow(true);
10235
- }
10236
- else {
10237
- setIsShow(false);
10238
- }
10239
- multiRowCopy.current.style.display = 'none';
10240
- }, [isPost, text]);
10241
- return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, style), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
10242
- React.createElement("div", { ref: multiRow, style: {
10243
- overflow: 'hidden',
10244
- WebkitLineClamp: !isPost || isShowMore ? '' : lineClamp,
10209
+ if (!multiRow.current)
10210
+ return;
10211
+ // 使用ResizeObserver监听尺寸变化
10212
+ observerRef.current = new ResizeObserver(checkOverflow);
10213
+ observerRef.current.observe(multiRow.current);
10214
+ // 初始检查
10215
+ checkOverflow();
10216
+ return () => {
10217
+ var _a;
10218
+ (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
10219
+ };
10220
+ }, [checkOverflow]);
10221
+ return (React.createElement("div", { className: className, style: Object.assign(Object.assign({}, textStyle), { transform: 'translate3d(0px, 0px, 0px)' }), hidden: !text || text === '' },
10222
+ React.createElement("div", { ref: multiRow, style: Object.assign(Object.assign({}, (!isShowMore &&
10223
+ isPost && {
10224
+ WebkitLineClamp: textLineClamp,
10225
+ lineClamp: textLineClamp,
10245
10226
  textOverflow: 'ellipsis',
10227
+ overflow: 'hidden',
10246
10228
  display: '-webkit-box',
10247
- WebkitBoxOrient: 'vertical',
10248
- wordBreak: 'break-word'
10249
- }, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), style) } }),
10250
- React.createElement("div", { ref: multiRowCopy, dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), style) } }),
10229
+ WebkitBoxOrient: 'vertical'
10230
+ })), { wordBreak: 'break-word' }), dangerouslySetInnerHTML: { __html: setFontForText(text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>'), textStyle) } }),
10251
10231
  text && isPost && isShow && (React.createElement("button", { "aria-label": isShowMore ? unfoldText || 'show less' : foldText || 'show more', style: { textDecoration: 'underline', cursor: 'pointer' }, onClick: onClick !== null && onClick !== void 0 ? onClick : handleClick, dangerouslySetInnerHTML: {
10252
- __html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', style)
10232
+ __html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
10253
10233
  } }))));
10254
10234
  };
10255
10235
  var ExpandableText$1 = memo(ExpandableText);