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