indicator-ui 0.0.179 → 0.0.181

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.js CHANGED
@@ -11886,10 +11886,22 @@ __webpack_require__.r(__webpack_exports__);
11886
11886
 
11887
11887
 
11888
11888
 
11889
- function MediaViewer({ media = [], initMediaIndex, nearestElementsOnly = true, onClose }) {
11890
- const [curMediaIndex, setCurMediaIndex] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(initMediaIndex != null && initMediaIndex >= 0 && initMediaIndex < media.length ? initMediaIndex : 0);
11889
+ function MediaViewer({ media = [], mediaIndex, nearestElementsOnly = true, onClose }) {
11890
+ const [curMediaIndex, setCurMediaIndex] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(0);
11891
11891
  const [muted, setMuted] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);
11892
11892
  const [play, setPlay] = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);
11893
+ const getPrevIndex = (curIndex) => {
11894
+ return curIndex > 0 ? curIndex - 1 : undefined;
11895
+ };
11896
+ const getNextIndex = (curIndex) => {
11897
+ return curIndex < media.length - 1 ? curIndex + 1 : undefined;
11898
+ };
11899
+ (0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => {
11900
+ const isValid = mediaIndex != null && mediaIndex >= 0 && mediaIndex < media.length ? mediaIndex : 0;
11901
+ if (mediaIndex !== curMediaIndex && isValid) {
11902
+ setCurMediaIndex(mediaIndex);
11903
+ }
11904
+ }, [mediaIndex]);
11893
11905
  const resetVideo = () => {
11894
11906
  setMuted(false);
11895
11907
  setPlay(false);
@@ -11911,21 +11923,21 @@ function MediaViewer({ media = [], initMediaIndex, nearestElementsOnly = true, o
11911
11923
  const isNearestElement = (curEl, el) => {
11912
11924
  const nextEl = curEl + 1 < media.length ? curEl + 1 : media.length - 1;
11913
11925
  const prevEl = curEl - 1 >= 0 ? curEl - 1 : 0;
11914
- return nextEl === el || prevEl === el;
11926
+ return nextEl === el || prevEl === el || el === curEl;
11915
11927
  };
11916
11928
  const getContent = (item, idx) => {
11917
- if (item == null || (nearestElementsOnly && !isNearestElement(idx, curMediaIndex)))
11929
+ if (item == null || (nearestElementsOnly && !isNearestElement(curMediaIndex, idx)))
11918
11930
  return undefined;
11919
11931
  switch (item.type) {
11920
11932
  case 'video':
11921
- return (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.VideoViewer, { src: item.src, muted: curMediaIndex === idx ? muted : undefined, play: curMediaIndex === idx ? play : undefined, onChangePlay: curMediaIndex === idx ? (play) => setPlay(play) : undefined }, item.src);
11933
+ return (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.VideoViewer, { src: item.src, muted: curMediaIndex === idx ? muted : undefined, play: curMediaIndex === idx ? play : undefined, onChangePlay: curMediaIndex === idx ? (play) => setPlay(play) : undefined }, idx);
11922
11934
  case 'image':
11923
- return (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.ImageViewer, { src: item.src }, item.src);
11935
+ return (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.ImageViewer, { src: item.src }, idx);
11924
11936
  default:
11925
11937
  return undefined;
11926
11938
  }
11927
11939
  };
11928
- return ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.MediaViewer, children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_4__.Carousel, { activeIndex: curMediaIndex, setActiveIndex: setCurMediaIndex, children: media.map((item, idx) => (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.content, children: getContent(item, idx) })) }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.control, children: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.ControlBar, { muted: muted, play: play, onPlay: media[curMediaIndex]?.type === 'video' ? _play : undefined, onMute: media[curMediaIndex]?.type === 'video' ? mute : undefined, onNext: next, onClose: onClose, onPrev: prev }) })] }));
11940
+ return ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.MediaViewer, children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_4__.Carousel, { activeIndex: curMediaIndex, setActiveIndex: setCurMediaIndex, children: media.map((item, idx) => (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.content, children: getContent(item, idx) }, idx)) }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { className: _ui_MediaViewer_styles__WEBPACK_IMPORTED_MODULE_3__.MediaViewerStyle.control, children: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components__WEBPACK_IMPORTED_MODULE_2__.ControlBar, { muted: muted, play: play, onPlay: media[curMediaIndex]?.type === 'video' ? _play : undefined, onMute: media[curMediaIndex]?.type === 'video' ? mute : undefined, onNext: getNextIndex(curMediaIndex) ? next : undefined, onPrev: getPrevIndex(curMediaIndex) ? prev : undefined, onClose: onClose }) })] }));
11929
11941
  }
11930
11942
 
11931
11943
 
@@ -11951,7 +11963,7 @@ __webpack_require__.r(__webpack_exports__);
11951
11963
 
11952
11964
 
11953
11965
  function ControlBar({ play, muted, onMute, onPlay, onClose, onPrev, onNext }) {
11954
- return ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: _styles__WEBPACK_IMPORTED_MODULE_3__.ControlBarStyle.controlBar, children: [onMute != null && (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: muted ? (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.VolumeXSVG, {}) : (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.VolumeMaxSVG, {}), size: 'small', hierarchy: 'secondary-gray', width: 'hug', onClick: onMute }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.ChevronLeftSVG, {}), size: 'large', hierarchy: 'secondary-gray', width: 'hug', onClick: onPrev }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.XCloseSVG, {}), size: 'ultra', hierarchy: 'secondary-gray', width: 'hug', onClick: onClose }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.ChevronRightSVG, {}), size: 'large', hierarchy: 'secondary-gray', width: 'hug', onClick: onNext }), onPlay != null && (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: play ? (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.PauseCircleSVG, {}) : (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.PlaySVG, {}), size: 'small', hierarchy: 'secondary-gray', width: 'hug', onClick: onPlay })] }));
11966
+ return ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: _styles__WEBPACK_IMPORTED_MODULE_3__.ControlBarStyle.controlBar, children: [onMute != null && (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: muted ? (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.VolumeXSVG, {}) : (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.VolumeMaxSVG, {}), size: 'small', hierarchy: 'secondary-gray', width: 'hug', onClick: onMute }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.ChevronLeftSVG, {}), size: 'large', hierarchy: 'secondary-gray', width: 'hug', disabled: onPrev == null, onClick: onPrev }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.XCloseSVG, {}), size: 'ultra', hierarchy: 'secondary-gray', width: 'hug', disabled: onClose == null, onClick: onClose }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.ChevronRightSVG, {}), size: 'large', hierarchy: 'secondary-gray', width: 'hug', disabled: onNext == null, onClick: onNext }), onPlay != null && (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_ui__WEBPACK_IMPORTED_MODULE_1__.Button, { iconLeft: play ? (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.PauseCircleSVG, {}) : (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_assets__WEBPACK_IMPORTED_MODULE_2__.PlaySVG, {}), size: 'small', hierarchy: 'secondary-gray', width: 'hug', onClick: onPlay })] }));
11955
11967
  }
11956
11968
 
11957
11969