pb-sxp-ui 1.0.13 → 1.0.14
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 +63 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +0 -1
- package/dist/index.js +63 -32
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +3 -3
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +3 -3
- package/dist/index.min.js.map +1 -1
- package/dist/pb-ui.js +63 -32
- package/dist/pb-ui.js.map +1 -1
- package/dist/pb-ui.min.js +3 -3
- package/dist/pb-ui.min.js.map +1 -1
- package/es/core/components/SxpPageRender/ExpandableText.d.ts +1 -0
- package/es/core/components/SxpPageRender/ExpandableText.js +6 -24
- package/es/core/components/SxpPageRender/index.js +34 -5
- package/es/core/utils/localStore.d.ts +1 -0
- package/es/core/utils/localStore.js +4 -0
- package/lib/core/components/SxpPageRender/ExpandableText.d.ts +1 -0
- package/lib/core/components/SxpPageRender/ExpandableText.js +6 -24
- package/lib/core/components/SxpPageRender/index.js +34 -5
- package/lib/core/utils/localStore.d.ts +1 -0
- package/lib/core/utils/localStore.js +6 -1
- package/package.json +1 -1
@@ -15,47 +15,29 @@ const limitTextLastWholeWord = (originalText = '', limit) => {
|
|
15
15
|
const _words = newWords.length > 1 && newWords.length < words.length ? newWords.slice(0, newWords.length - 1) : newWords;
|
16
16
|
return _words.join(' ') + ' ';
|
17
17
|
};
|
18
|
-
const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldText, unfoldText, isPost }) => {
|
19
|
-
const [isShowMore, setIsShowMore] = useState(
|
18
|
+
const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldText, unfoldText, isPost, onChange }) => {
|
19
|
+
const [isShowMore, setIsShowMore] = useState(false);
|
20
20
|
const [isShow, setIsShow] = useState(false);
|
21
21
|
const lineClamp = Number((style === null || style === void 0 ? void 0 : style.lineClamp) || 2);
|
22
22
|
const multiRow = useRef(null);
|
23
23
|
const handleClick = useCallback(() => {
|
24
24
|
setIsShowMore(!isShowMore);
|
25
|
-
|
25
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(!isShowMore);
|
26
|
+
}, [isShowMore, onChange]);
|
26
27
|
const renderText = useMemo(() => {
|
27
28
|
return !isShowMore && text.length > maxStr ? limitTextLastWholeWord(text, maxStr) + '...' : text;
|
28
29
|
}, [text, maxStr, isShowMore]);
|
29
30
|
useEffect(() => {
|
30
|
-
if (multiRow.current && isPost) {
|
31
|
-
setIsShowMore(true);
|
32
|
-
setTimeout(() => {
|
33
|
-
var _a;
|
34
|
-
setIsShow(false);
|
35
|
-
try {
|
36
|
-
const cs = (_a = window === null || window === void 0 ? void 0 : window.getComputedStyle) === null || _a === void 0 ? void 0 : _a.call(window, multiRow.current);
|
37
|
-
const height = parseFloat(cs === null || cs === void 0 ? void 0 : cs.height);
|
38
|
-
const lh = parseFloat(cs === null || cs === void 0 ? void 0 : cs.lineHeight);
|
39
|
-
const fs = parseFloat(cs === null || cs === void 0 ? void 0 : cs.fontSize) + 6;
|
40
|
-
const lineHeight = isNaN(lh) ? fs : lh;
|
41
|
-
if (text && height > lineHeight * lineClamp) {
|
42
|
-
setIsShowMore(false);
|
43
|
-
setIsShow(true);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
catch (_b) { }
|
47
|
-
}, 100);
|
48
|
-
}
|
49
31
|
}, [multiRow, text, lineClamp, style, isPost]);
|
50
32
|
return (React.createElement("div", { className: className, style: Object.assign({}, style), hidden: !text || text === '' },
|
51
33
|
React.createElement("div", { ref: multiRow, style: {
|
52
34
|
overflow: 'hidden',
|
53
|
-
WebkitLineClamp:
|
35
|
+
WebkitLineClamp: isShowMore ? '' : lineClamp,
|
54
36
|
textOverflow: 'ellipsis',
|
55
37
|
display: '-webkit-box',
|
56
38
|
WebkitBoxOrient: 'vertical',
|
57
39
|
wordBreak: 'break-word'
|
58
40
|
}, dangerouslySetInnerHTML: { __html: text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>') } }),
|
59
|
-
|
41
|
+
text && isPost && (React.createElement("span", { style: { textDecoration: 'underline', cursor: 'pointer' }, onClick: onClick !== null && onClick !== void 0 ? onClick : handleClick }, isShowMore ? unfoldText || 'show less' : foldText || 'show more'))));
|
60
42
|
};
|
61
43
|
export default memo(ExpandableText);
|
@@ -20,6 +20,7 @@ import { refreshFeSessionId } from '../../../core/utils/sessionStore';
|
|
20
20
|
import './index.less';
|
21
21
|
import { useEventReport } from '../../../core/hooks/useEventReport';
|
22
22
|
import withBindDataSource from '../../../core/hoc/withBindDataSource';
|
23
|
+
import { getFeUserId } from '../../../core/utils/localStore';
|
23
24
|
const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.innerHeight, containerWidth = window.innerWidth, tempMap, resolver, data = [], ctaType, tipText, nudge, _schema, hashTagStyle }) => {
|
24
25
|
var _a, _b, _c, _d, _e, _f, _g;
|
25
26
|
const { schema } = useEditor();
|
@@ -30,10 +31,11 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
|
|
30
31
|
const curTime = useRef();
|
31
32
|
const viewTime = useRef();
|
32
33
|
const [isLoadMore, setIsLoadMore] = useState(false);
|
34
|
+
const [isShowMore, setIsShowMore] = useState(false);
|
33
35
|
const { loadVideos, bffEventReport, loading, setPopupDetailData, ctaEvent, swiperRef, waterFallData, setOpenHashtag, appDomain, openHashtag, loadingImage, isFromHashtag, popupDetailData } = useSxpDataSource();
|
34
36
|
const { productView } = useEventReport();
|
35
37
|
const isShowFingerTip = useMemo(() => {
|
36
|
-
return data.length > 0 && !loading;
|
38
|
+
return data.length > 0 && !loading && !getFeUserId;
|
37
39
|
}, [data, loading]);
|
38
40
|
const handleH5EnterLink = useCallback(() => {
|
39
41
|
if (data.length <= 0) {
|
@@ -167,20 +169,47 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
|
|
167
169
|
}
|
168
170
|
return null;
|
169
171
|
}, [containerWidth, data, height, isMuted, activeIndex, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost, viewTime, tipText, resolver, schema]);
|
172
|
+
const onExpandableChange = useCallback((v) => {
|
173
|
+
setIsShowMore(v);
|
174
|
+
}, []);
|
175
|
+
const lineGradStyle = useMemo(() => {
|
176
|
+
return !isShowMore
|
177
|
+
? {
|
178
|
+
padding: '20px 0'
|
179
|
+
}
|
180
|
+
: {
|
181
|
+
background: 'linear-gradient( 180deg, rgba(129,129,129,0) 0%, rgba(121,121,121,0.5) 5%, #616161 100%)',
|
182
|
+
paddingTop: 20,
|
183
|
+
paddingBottom: 20
|
184
|
+
};
|
185
|
+
}, [isShowMore]);
|
170
186
|
const renderBottom = useCallback((rec, index) => {
|
171
187
|
var _a, _b, _c, _d, _e, _f, _g;
|
172
188
|
if (rec.video) {
|
173
189
|
return (React.createElement(React.Fragment, null,
|
174
|
-
((_a = rec.video) === null || _a === void 0 ? void 0 : _a.title) && React.createElement("div", { className: 'clc-sxp-bottom-shadow' }),
|
190
|
+
((_a = rec.video) === null || _a === void 0 ? void 0 : _a.title) && !isShowMore && React.createElement("div", { className: 'clc-sxp-bottom-shadow' }),
|
175
191
|
React.createElement("div", { className: 'clc-sxp-bottom' },
|
176
192
|
React.createElement(Nudge, { nudge: nudge }),
|
177
193
|
React.createElement("div", { className: 'clc-sxp-bottom-card' },
|
178
194
|
React.createElement(RenderCard, { rec: rec, index: index, tempMap: tempMap, resolver: resolver })),
|
179
|
-
React.createElement(
|
180
|
-
|
195
|
+
React.createElement("div", { style: lineGradStyle },
|
196
|
+
React.createElement(ExpandableText, { className: 'clc-sxp-bottom-text', isPost: true, foldText: tipText === null || tipText === void 0 ? void 0 : tipText.foldText, unfoldText: tipText === null || tipText === void 0 ? void 0 : tipText.unfoldText, text: (_c = (_b = rec.video) === null || _b === void 0 ? void 0 : _b.title) !== null && _c !== void 0 ? _c : '', style: Object.assign(Object.assign({}, descStyle), { textShadow: (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.isOpenTextShadow) ? '2px 2px 4px rgba(0, 0, 0, 0.5)' : 'none' }), onChange: onExpandableChange }),
|
197
|
+
React.createElement(Hashtag, { index: activeIndex, tags: (_e = (_d = rec === null || rec === void 0 ? void 0 : rec.video) === null || _d === void 0 ? void 0 : _d.hashTags) !== null && _e !== void 0 ? _e : [], itemId: (_f = rec === null || rec === void 0 ? void 0 : rec.video) === null || _f === void 0 ? void 0 : _f.itemId, itemType: ((_g = rec.video) === null || _g === void 0 ? void 0 : _g.url) ? 'VIDEO' : null, rec: rec, hashTagStyle: hashTagStyle })))));
|
181
198
|
}
|
182
199
|
return null;
|
183
|
-
}, [
|
200
|
+
}, [
|
201
|
+
descStyle,
|
202
|
+
activeIndex,
|
203
|
+
tempMap,
|
204
|
+
resolver,
|
205
|
+
tipText,
|
206
|
+
nudge,
|
207
|
+
hashTagStyle,
|
208
|
+
globalConfig,
|
209
|
+
onExpandableChange,
|
210
|
+
isShowMore,
|
211
|
+
lineGradStyle
|
212
|
+
]);
|
184
213
|
const renderLikeButton = useCallback((rec, index) => {
|
185
214
|
var _a, _b;
|
186
215
|
if (!(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.isShowLike))
|
@@ -12,3 +12,7 @@ export const storeAndLoadFeUserId = () => {
|
|
12
12
|
export const removeFeUserId = () => {
|
13
13
|
window.localStorage.removeItem(FAKE_USER_KEY);
|
14
14
|
};
|
15
|
+
export const getFeUserId = () => {
|
16
|
+
const fakeUserId = window.localStorage.getItem(FAKE_USER_KEY);
|
17
|
+
return isEmpty(fakeUserId);
|
18
|
+
};
|
@@ -18,47 +18,29 @@ const limitTextLastWholeWord = (originalText = '', limit) => {
|
|
18
18
|
const _words = newWords.length > 1 && newWords.length < words.length ? newWords.slice(0, newWords.length - 1) : newWords;
|
19
19
|
return _words.join(' ') + ' ';
|
20
20
|
};
|
21
|
-
const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldText, unfoldText, isPost }) => {
|
22
|
-
const [isShowMore, setIsShowMore] = (0, react_1.useState)(
|
21
|
+
const ExpandableText = ({ text, maxStr = 108, style, className, onClick, foldText, unfoldText, isPost, onChange }) => {
|
22
|
+
const [isShowMore, setIsShowMore] = (0, react_1.useState)(false);
|
23
23
|
const [isShow, setIsShow] = (0, react_1.useState)(false);
|
24
24
|
const lineClamp = Number((style === null || style === void 0 ? void 0 : style.lineClamp) || 2);
|
25
25
|
const multiRow = (0, react_1.useRef)(null);
|
26
26
|
const handleClick = (0, react_1.useCallback)(() => {
|
27
27
|
setIsShowMore(!isShowMore);
|
28
|
-
|
28
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(!isShowMore);
|
29
|
+
}, [isShowMore, onChange]);
|
29
30
|
const renderText = (0, react_1.useMemo)(() => {
|
30
31
|
return !isShowMore && text.length > maxStr ? limitTextLastWholeWord(text, maxStr) + '...' : text;
|
31
32
|
}, [text, maxStr, isShowMore]);
|
32
33
|
(0, react_1.useEffect)(() => {
|
33
|
-
if (multiRow.current && isPost) {
|
34
|
-
setIsShowMore(true);
|
35
|
-
setTimeout(() => {
|
36
|
-
var _a;
|
37
|
-
setIsShow(false);
|
38
|
-
try {
|
39
|
-
const cs = (_a = window === null || window === void 0 ? void 0 : window.getComputedStyle) === null || _a === void 0 ? void 0 : _a.call(window, multiRow.current);
|
40
|
-
const height = parseFloat(cs === null || cs === void 0 ? void 0 : cs.height);
|
41
|
-
const lh = parseFloat(cs === null || cs === void 0 ? void 0 : cs.lineHeight);
|
42
|
-
const fs = parseFloat(cs === null || cs === void 0 ? void 0 : cs.fontSize) + 6;
|
43
|
-
const lineHeight = isNaN(lh) ? fs : lh;
|
44
|
-
if (text && height > lineHeight * lineClamp) {
|
45
|
-
setIsShowMore(false);
|
46
|
-
setIsShow(true);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
catch (_b) { }
|
50
|
-
}, 100);
|
51
|
-
}
|
52
34
|
}, [multiRow, text, lineClamp, style, isPost]);
|
53
35
|
return (react_1.default.createElement("div", { className: className, style: Object.assign({}, style), hidden: !text || text === '' },
|
54
36
|
react_1.default.createElement("div", { ref: multiRow, style: {
|
55
37
|
overflow: 'hidden',
|
56
|
-
WebkitLineClamp:
|
38
|
+
WebkitLineClamp: isShowMore ? '' : lineClamp,
|
57
39
|
textOverflow: 'ellipsis',
|
58
40
|
display: '-webkit-box',
|
59
41
|
WebkitBoxOrient: 'vertical',
|
60
42
|
wordBreak: 'break-word'
|
61
43
|
}, dangerouslySetInnerHTML: { __html: text === null || text === void 0 ? void 0 : text.replace(/\n/g, '</br>') } }),
|
62
|
-
|
44
|
+
text && isPost && (react_1.default.createElement("span", { style: { textDecoration: 'underline', cursor: 'pointer' }, onClick: onClick !== null && onClick !== void 0 ? onClick : handleClick }, isShowMore ? unfoldText || 'show less' : foldText || 'show more'))));
|
63
45
|
};
|
64
46
|
exports.default = (0, react_1.memo)(ExpandableText);
|
@@ -23,6 +23,7 @@ const sessionStore_1 = require("../../../core/utils/sessionStore");
|
|
23
23
|
require("./index.less");
|
24
24
|
const useEventReport_1 = require("../../../core/hooks/useEventReport");
|
25
25
|
const withBindDataSource_1 = tslib_1.__importDefault(require("../../../core/hoc/withBindDataSource"));
|
26
|
+
const localStore_1 = require("../../../core/utils/localStore");
|
26
27
|
const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.innerHeight, containerWidth = window.innerWidth, tempMap, resolver, data = [], ctaType, tipText, nudge, _schema, hashTagStyle }) => {
|
27
28
|
var _a, _b, _c, _d, _e, _f, _g;
|
28
29
|
const { schema } = (0, hooks_1.useEditor)();
|
@@ -33,10 +34,11 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
|
|
33
34
|
const curTime = (0, react_1.useRef)();
|
34
35
|
const viewTime = (0, react_1.useRef)();
|
35
36
|
const [isLoadMore, setIsLoadMore] = (0, react_1.useState)(false);
|
37
|
+
const [isShowMore, setIsShowMore] = (0, react_1.useState)(false);
|
36
38
|
const { loadVideos, bffEventReport, loading, setPopupDetailData, ctaEvent, swiperRef, waterFallData, setOpenHashtag, appDomain, openHashtag, loadingImage, isFromHashtag, popupDetailData } = (0, hooks_1.useSxpDataSource)();
|
37
39
|
const { productView } = (0, useEventReport_1.useEventReport)();
|
38
40
|
const isShowFingerTip = (0, react_1.useMemo)(() => {
|
39
|
-
return data.length > 0 && !loading;
|
41
|
+
return data.length > 0 && !loading && !localStore_1.getFeUserId;
|
40
42
|
}, [data, loading]);
|
41
43
|
const handleH5EnterLink = (0, react_1.useCallback)(() => {
|
42
44
|
if (data.length <= 0) {
|
@@ -170,20 +172,47 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
|
|
170
172
|
}
|
171
173
|
return null;
|
172
174
|
}, [containerWidth, data, height, isMuted, activeIndex, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost, viewTime, tipText, resolver, schema]);
|
175
|
+
const onExpandableChange = (0, react_1.useCallback)((v) => {
|
176
|
+
setIsShowMore(v);
|
177
|
+
}, []);
|
178
|
+
const lineGradStyle = (0, react_1.useMemo)(() => {
|
179
|
+
return !isShowMore
|
180
|
+
? {
|
181
|
+
padding: '20px 0'
|
182
|
+
}
|
183
|
+
: {
|
184
|
+
background: 'linear-gradient( 180deg, rgba(129,129,129,0) 0%, rgba(121,121,121,0.5) 5%, #616161 100%)',
|
185
|
+
paddingTop: 20,
|
186
|
+
paddingBottom: 20
|
187
|
+
};
|
188
|
+
}, [isShowMore]);
|
173
189
|
const renderBottom = (0, react_1.useCallback)((rec, index) => {
|
174
190
|
var _a, _b, _c, _d, _e, _f, _g;
|
175
191
|
if (rec.video) {
|
176
192
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
177
|
-
((_a = rec.video) === null || _a === void 0 ? void 0 : _a.title) && react_1.default.createElement("div", { className: 'clc-sxp-bottom-shadow' }),
|
193
|
+
((_a = rec.video) === null || _a === void 0 ? void 0 : _a.title) && !isShowMore && react_1.default.createElement("div", { className: 'clc-sxp-bottom-shadow' }),
|
178
194
|
react_1.default.createElement("div", { className: 'clc-sxp-bottom' },
|
179
195
|
react_1.default.createElement(Nudge_1.default, { nudge: nudge }),
|
180
196
|
react_1.default.createElement("div", { className: 'clc-sxp-bottom-card' },
|
181
197
|
react_1.default.createElement(RenderCard_1.default, { rec: rec, index: index, tempMap: tempMap, resolver: resolver })),
|
182
|
-
react_1.default.createElement(
|
183
|
-
|
198
|
+
react_1.default.createElement("div", { style: lineGradStyle },
|
199
|
+
react_1.default.createElement(ExpandableText_1.default, { className: 'clc-sxp-bottom-text', isPost: true, foldText: tipText === null || tipText === void 0 ? void 0 : tipText.foldText, unfoldText: tipText === null || tipText === void 0 ? void 0 : tipText.unfoldText, text: (_c = (_b = rec.video) === null || _b === void 0 ? void 0 : _b.title) !== null && _c !== void 0 ? _c : '', style: Object.assign(Object.assign({}, descStyle), { textShadow: (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.isOpenTextShadow) ? '2px 2px 4px rgba(0, 0, 0, 0.5)' : 'none' }), onChange: onExpandableChange }),
|
200
|
+
react_1.default.createElement(Hashtag_1.default, { index: activeIndex, tags: (_e = (_d = rec === null || rec === void 0 ? void 0 : rec.video) === null || _d === void 0 ? void 0 : _d.hashTags) !== null && _e !== void 0 ? _e : [], itemId: (_f = rec === null || rec === void 0 ? void 0 : rec.video) === null || _f === void 0 ? void 0 : _f.itemId, itemType: ((_g = rec.video) === null || _g === void 0 ? void 0 : _g.url) ? 'VIDEO' : null, rec: rec, hashTagStyle: hashTagStyle })))));
|
184
201
|
}
|
185
202
|
return null;
|
186
|
-
}, [
|
203
|
+
}, [
|
204
|
+
descStyle,
|
205
|
+
activeIndex,
|
206
|
+
tempMap,
|
207
|
+
resolver,
|
208
|
+
tipText,
|
209
|
+
nudge,
|
210
|
+
hashTagStyle,
|
211
|
+
globalConfig,
|
212
|
+
onExpandableChange,
|
213
|
+
isShowMore,
|
214
|
+
lineGradStyle
|
215
|
+
]);
|
187
216
|
const renderLikeButton = (0, react_1.useCallback)((rec, index) => {
|
188
217
|
var _a, _b;
|
189
218
|
if (!(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.isShowLike))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.removeFeUserId = exports.storeAndLoadFeUserId = exports.FAKE_USER_KEY = void 0;
|
3
|
+
exports.getFeUserId = exports.removeFeUserId = exports.storeAndLoadFeUserId = exports.FAKE_USER_KEY = void 0;
|
4
4
|
const lodash_1 = require("lodash");
|
5
5
|
const tool_1 = require("./tool");
|
6
6
|
exports.FAKE_USER_KEY = 'SXP_FAKE_USER_ID';
|
@@ -17,3 +17,8 @@ const removeFeUserId = () => {
|
|
17
17
|
window.localStorage.removeItem(exports.FAKE_USER_KEY);
|
18
18
|
};
|
19
19
|
exports.removeFeUserId = removeFeUserId;
|
20
|
+
const getFeUserId = () => {
|
21
|
+
const fakeUserId = window.localStorage.getItem(exports.FAKE_USER_KEY);
|
22
|
+
return (0, lodash_1.isEmpty)(fakeUserId);
|
23
|
+
};
|
24
|
+
exports.getFeUserId = getFeUserId;
|