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.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
|
10193
|
+
const _a = style || {}, { lineClamp } = _a, textStyle = __rest(_a, ["lineClamp"]);
|
10194
|
+
const textLineClamp = Number(lineClamp || 2);
|
10220
10195
|
const multiRow = useRef(null);
|
10221
|
-
const
|
10222
|
-
const handleClick =
|
10196
|
+
const observerRef = useRef();
|
10197
|
+
const handleClick = () => {
|
10223
10198
|
setIsShowMore(!isShowMore);
|
10224
|
-
|
10225
|
-
|
10226
|
-
|
10227
|
-
|
10228
|
-
|
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
|
-
|
10231
|
-
|
10232
|
-
|
10233
|
-
|
10234
|
-
|
10235
|
-
|
10236
|
-
|
10237
|
-
|
10238
|
-
|
10239
|
-
|
10240
|
-
|
10241
|
-
|
10242
|
-
|
10243
|
-
|
10244
|
-
|
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
|
-
|
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',
|
10232
|
+
__html: setFontForText(isShowMore ? unfoldText || 'show less' : foldText || 'show more', textStyle)
|
10253
10233
|
} }))));
|
10254
10234
|
};
|
10255
10235
|
var ExpandableText$1 = memo(ExpandableText);
|