pb-sxp-ui 1.0.18 → 1.0.20

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.
@@ -1,19 +1,14 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
2
  import { useSxpDataSource } from '../../../../core/hooks';
3
3
  const Picture = (props) => {
4
4
  const { src, height, width } = props;
5
5
  const [blur, setBlur] = useState(false);
6
- const imgDom = useRef(null);
7
6
  const { sxpParameter } = useSxpDataSource();
8
- const getAvifToPng = useCallback((src) => {
9
- return src.indexOf('avif') !== -1 ? `${src}?imageMogr2/format/webp` : src;
10
- }, []);
11
7
  useEffect(() => {
12
- if (imgDom.current === null || src === '') {
8
+ if (src === '' || !src)
13
9
  return;
14
- }
15
10
  const img = new Image();
16
- img.src = src;
11
+ img.src = `${src}?imageMogr2/format/jpg`;
17
12
  img.onload = () => {
18
13
  const aspectRatio = img.height / img.width;
19
14
  const targetAspectRatio = 16 / 9;
@@ -22,22 +17,31 @@ const Picture = (props) => {
22
17
  setBlur(true);
23
18
  }
24
19
  };
25
- imgDom.current.src = getAvifToPng(src);
26
- }, [src, getAvifToPng]);
20
+ }, [src]);
21
+ const getImg = useCallback((src, style) => {
22
+ if (src === '' || !src)
23
+ return;
24
+ return (src === null || src === void 0 ? void 0 : src.indexOf('.avif')) !== -1 ? (React.createElement("picture", null,
25
+ React.createElement("source", { type: 'image/avif', srcSet: src }),
26
+ React.createElement("source", { type: 'image/webp', srcSet: `${src}?imageMogr2/format/webp` }),
27
+ React.createElement("source", { type: 'image/jpeg', srcSet: `${src}?imageMogr2/format/jpg` }),
28
+ React.createElement("img", { loading: 'lazy', src: src, style: style }))) : (React.createElement("img", { loading: 'lazy', src: src, style: style }));
29
+ }, []);
27
30
  return (React.createElement("div", { style: {
28
31
  overflow: 'hidden',
29
32
  height,
30
33
  width: '100%',
31
34
  position: 'relative'
32
35
  } },
33
- React.createElement("img", { ref: imgDom, loading: 'lazy', src: src ? getAvifToPng(src) : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, style: {
34
- height: '100%',
35
- width: '100%',
36
- objectFit: 'cover',
37
- filter: blur ? 'blur(10px)' : 'none',
38
- transform: blur ? 'scale(1.2)' : 'none'
39
- } }),
40
- blur && (React.createElement("img", { ref: imgDom, src: getAvifToPng(src), loading: 'lazy', style: {
36
+ getImg(src !== null && src !== void 0 ? src : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, {
37
+ height: '100%',
38
+ width: '100%',
39
+ objectFit: 'cover',
40
+ filter: blur ? 'blur(10px)' : 'none',
41
+ transform: blur ? 'scale(1.2)' : 'none'
42
+ }),
43
+ blur &&
44
+ getImg(src, {
41
45
  width: '100%',
42
46
  objectFit: 'contain',
43
47
  position: 'absolute',
@@ -45,6 +49,6 @@ const Picture = (props) => {
45
49
  transform: 'translateY(-50%)',
46
50
  left: 0,
47
51
  right: 0
48
- } }))));
52
+ })));
49
53
  };
50
54
  export default Picture;
@@ -1,14 +1,16 @@
1
- import React, { memo, useEffect, useState } from 'react';
1
+ import React, { memo, useEffect, useRef, useState } from 'react';
2
2
  import { Autoplay, Pagination } from 'swiper/modules';
3
3
  import { Swiper, SwiperSlide, useSwiperSlide } from 'swiper/react';
4
4
  import Picture from './Picture';
5
5
  import { useSxpDataSource } from '../../../../core/hooks';
6
6
  const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
7
+ const ref = useRef();
7
8
  const { isActive } = useSwiperSlide();
8
9
  const { sxpParameter, openHashtag } = useSxpDataSource();
9
10
  const [isLoad, setIsLoad] = useState(false);
10
11
  useEffect(() => {
11
12
  if (isLoad && isActive) {
13
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.start();
12
14
  if (openHashtag) {
13
15
  onReportViewImageEnd(rec);
14
16
  }
@@ -18,9 +20,10 @@ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd
18
20
  }
19
21
  else {
20
22
  setIsLoad(true);
23
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.stop();
21
24
  }
22
25
  }, [rec, isActive, onReportViewImageEnd, openHashtag, index, onViewImageStartEvent, isLoad]);
23
- return (React.createElement(Swiper, { defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: isActive ? { delay: 3000 } : false }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
26
+ return (React.createElement(Swiper, { ref: ref, defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: { delay: 3000 } }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
24
27
  return (React.createElement(SwiperSlide, { key: url },
25
28
  React.createElement(Picture, { src: url, width: width, height: height })));
26
29
  })));
@@ -212,8 +212,7 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
212
212
  width: '100%',
213
213
  height
214
214
  } },
215
- React.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, poster: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
216
- renderPoster,
215
+ React.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
217
216
  React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })));
218
217
  };
219
218
  export default memo(VideoWidget);
@@ -6,17 +6,12 @@ const hooks_1 = require("../../../../core/hooks");
6
6
  const Picture = (props) => {
7
7
  const { src, height, width } = props;
8
8
  const [blur, setBlur] = (0, react_1.useState)(false);
9
- const imgDom = (0, react_1.useRef)(null);
10
9
  const { sxpParameter } = (0, hooks_1.useSxpDataSource)();
11
- const getAvifToPng = (0, react_1.useCallback)((src) => {
12
- return src.indexOf('avif') !== -1 ? `${src}?imageMogr2/format/webp` : src;
13
- }, []);
14
10
  (0, react_1.useEffect)(() => {
15
- if (imgDom.current === null || src === '') {
11
+ if (src === '' || !src)
16
12
  return;
17
- }
18
13
  const img = new Image();
19
- img.src = src;
14
+ img.src = `${src}?imageMogr2/format/jpg`;
20
15
  img.onload = () => {
21
16
  const aspectRatio = img.height / img.width;
22
17
  const targetAspectRatio = 16 / 9;
@@ -25,22 +20,31 @@ const Picture = (props) => {
25
20
  setBlur(true);
26
21
  }
27
22
  };
28
- imgDom.current.src = getAvifToPng(src);
29
- }, [src, getAvifToPng]);
23
+ }, [src]);
24
+ const getImg = (0, react_1.useCallback)((src, style) => {
25
+ if (src === '' || !src)
26
+ return;
27
+ return (src === null || src === void 0 ? void 0 : src.indexOf('.avif')) !== -1 ? (react_1.default.createElement("picture", null,
28
+ react_1.default.createElement("source", { type: 'image/avif', srcSet: src }),
29
+ react_1.default.createElement("source", { type: 'image/webp', srcSet: `${src}?imageMogr2/format/webp` }),
30
+ react_1.default.createElement("source", { type: 'image/jpeg', srcSet: `${src}?imageMogr2/format/jpg` }),
31
+ react_1.default.createElement("img", { loading: 'lazy', src: src, style: style }))) : (react_1.default.createElement("img", { loading: 'lazy', src: src, style: style }));
32
+ }, []);
30
33
  return (react_1.default.createElement("div", { style: {
31
34
  overflow: 'hidden',
32
35
  height,
33
36
  width: '100%',
34
37
  position: 'relative'
35
38
  } },
36
- react_1.default.createElement("img", { ref: imgDom, loading: 'lazy', src: src ? getAvifToPng(src) : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, style: {
37
- height: '100%',
38
- width: '100%',
39
- objectFit: 'cover',
40
- filter: blur ? 'blur(10px)' : 'none',
41
- transform: blur ? 'scale(1.2)' : 'none'
42
- } }),
43
- blur && (react_1.default.createElement("img", { ref: imgDom, src: getAvifToPng(src), loading: 'lazy', style: {
39
+ getImg(src !== null && src !== void 0 ? src : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, {
40
+ height: '100%',
41
+ width: '100%',
42
+ objectFit: 'cover',
43
+ filter: blur ? 'blur(10px)' : 'none',
44
+ transform: blur ? 'scale(1.2)' : 'none'
45
+ }),
46
+ blur &&
47
+ getImg(src, {
44
48
  width: '100%',
45
49
  objectFit: 'contain',
46
50
  position: 'absolute',
@@ -48,6 +52,6 @@ const Picture = (props) => {
48
52
  transform: 'translateY(-50%)',
49
53
  left: 0,
50
54
  right: 0
51
- } }))));
55
+ })));
52
56
  };
53
57
  exports.default = Picture;
@@ -7,11 +7,13 @@ const react_2 = require("swiper/react");
7
7
  const Picture_1 = tslib_1.__importDefault(require("./Picture"));
8
8
  const hooks_1 = require("../../../../core/hooks");
9
9
  const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
10
+ const ref = (0, react_1.useRef)();
10
11
  const { isActive } = (0, react_2.useSwiperSlide)();
11
12
  const { sxpParameter, openHashtag } = (0, hooks_1.useSxpDataSource)();
12
13
  const [isLoad, setIsLoad] = (0, react_1.useState)(false);
13
14
  (0, react_1.useEffect)(() => {
14
15
  if (isLoad && isActive) {
16
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.start();
15
17
  if (openHashtag) {
16
18
  onReportViewImageEnd(rec);
17
19
  }
@@ -21,9 +23,10 @@ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd
21
23
  }
22
24
  else {
23
25
  setIsLoad(true);
26
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.stop();
24
27
  }
25
28
  }, [rec, isActive, onReportViewImageEnd, openHashtag, index, onViewImageStartEvent, isLoad]);
26
- return (react_1.default.createElement(react_2.Swiper, { defaultValue: 0, direction: 'horizontal', modules: [modules_1.Pagination, modules_1.Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: isActive ? { delay: 3000 } : false }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
29
+ return (react_1.default.createElement(react_2.Swiper, { ref: ref, defaultValue: 0, direction: 'horizontal', modules: [modules_1.Pagination, modules_1.Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: { delay: 3000 } }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
27
30
  return (react_1.default.createElement(react_2.SwiperSlide, { key: url },
28
31
  react_1.default.createElement(Picture_1.default, { src: url, width: width, height: height })));
29
32
  })));
@@ -215,8 +215,7 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
215
215
  width: '100%',
216
216
  height
217
217
  } },
218
- react_1.default.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, poster: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
219
- renderPoster,
218
+ react_1.default.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
220
219
  react_1.default.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })));
221
220
  };
222
221
  exports.default = (0, react_1.memo)(VideoWidget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pb-sxp-ui",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "React enterprise-class UI components",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",