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