@websolutespa/bom-mixer-ui 1.8.6 → 1.8.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @websolutespa/bom-mixer-ui
2
2
 
3
+ ## 1.8.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: MediaVideo & SvgAnimation src change issue
8
+
3
9
  ## 1.8.6
4
10
 
5
11
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -4701,36 +4701,59 @@ const MediaVideo_ = _a => {
4701
4701
  var {
4702
4702
  className,
4703
4703
  onLoaded,
4704
- canLoad = true,
4705
- src
4704
+ canLoad = true
4706
4705
  } = _a,
4707
- props = __rest(_a, ["className", "onLoaded", "canLoad", "src"]);
4706
+ props = __rest(_a, ["className", "onLoaded", "canLoad"]);
4708
4707
  const videoRef = React.useRef(null);
4709
4708
  const {
4710
4709
  locale
4711
4710
  } = bomMixerHooks.useLayout();
4712
- const classNames = bomCore.getClassNames(className, 'video', 'video--muted');
4713
- const onLoad = () => {
4714
- if (typeof onLoaded === 'function' && videoRef.current && videoRef.current.readyState && videoRef.current.readyState >= 2) {
4715
- onLoaded(videoRef);
4716
- }
4717
- };
4711
+ const [src, setSrc] = React.useState();
4718
4712
  React.useEffect(() => {
4719
- if (videoRef.current && canLoad) {
4713
+ if (videoRef.current && src) {
4720
4714
  const video = videoRef.current;
4721
- if (video.readyState && video.readyState >= 2) {
4722
- if (typeof onLoaded === 'function') {
4715
+ const onReadyState = () => {
4716
+ if (typeof onLoaded === 'function' && videoRef.current && videoRef.current.readyState && videoRef.current.readyState >= 2) {
4723
4717
  onLoaded(videoRef);
4724
4718
  }
4719
+ };
4720
+ if (video.readyState && video.readyState >= 2) {
4721
+ onReadyState();
4725
4722
  } else {
4726
- video.addEventListener('loadeddata', onLoad);
4723
+ video.addEventListener('loadeddata', onReadyState);
4727
4724
  return () => {
4728
- video.removeEventListener('loadeddata', onLoad);
4725
+ video.removeEventListener('loadeddata', onReadyState);
4729
4726
  };
4730
4727
  }
4731
4728
  }
4732
4729
  return () => {};
4733
- }, [videoRef, canLoad]);
4730
+ }, [videoRef, onLoaded, src]);
4731
+ const isIntersecting = bomMixerHooks.useIntersectionObserver(videoRef, {
4732
+ threshold: 0,
4733
+ root: null,
4734
+ rootMargin: '0px'
4735
+ });
4736
+ // handle intersection
4737
+ React.useEffect(() => {
4738
+ if (isIntersecting && canLoad) {
4739
+ // on enter
4740
+ if (src !== props.src) {
4741
+ setSrc(props.src);
4742
+ } else {
4743
+ if (!videoRef.current) {
4744
+ return;
4745
+ }
4746
+ videoRef.current.play();
4747
+ }
4748
+ } else {
4749
+ // on exit
4750
+ if (!videoRef.current) {
4751
+ return;
4752
+ }
4753
+ videoRef.current.pause();
4754
+ }
4755
+ }, [isIntersecting, canLoad, videoRef, src, props.src]);
4756
+ const classNames = bomCore.getClassNames(className, 'video', 'video--muted');
4734
4757
  return jsxRuntime.jsx(StyledMediaVideo, Object.assign({
4735
4758
  ref: videoRef,
4736
4759
  className: classNames,
@@ -4739,7 +4762,7 @@ const MediaVideo_ = _a => {
4739
4762
  muted: true,
4740
4763
  loop: true
4741
4764
  }, props, {
4742
- children: canLoad && jsxRuntime.jsxs(jsxRuntime.Fragment, {
4765
+ children: src && jsxRuntime.jsxs(jsxRuntime.Fragment, {
4743
4766
  children: [jsxRuntime.jsx("source", {
4744
4767
  src: src,
4745
4768
  type: "video/mp4"
@@ -6998,7 +7021,7 @@ const SvgAnimation = /*#__PURE__*/React.forwardRef((_a, forwardedRef) => {
6998
7021
  }
6999
7022
  }
7000
7023
  // eslint-disable-next-line react-hooks/exhaustive-deps
7001
- }, [shouldLoad]);
7024
+ }, [shouldLoad, href]);
7002
7025
  // handle intersection
7003
7026
  React.useEffect(() => {
7004
7027
  if (isIntersecting) {
@@ -7036,7 +7059,7 @@ const SvgAnimation = /*#__PURE__*/React.forwardRef((_a, forwardedRef) => {
7036
7059
  playerRef.current.stop();
7037
7060
  }
7038
7061
  }
7039
- }, [isIntersecting, mode, shouldLoad]);
7062
+ }, [isIntersecting, mode, shouldLoad, href]);
7040
7063
  // handle scroll
7041
7064
  React.useEffect(() => {
7042
7065
  const scrollElement = mode === SvgAnimationStrategy.Scroll ? scrollableRef ? scrollableRef.current : window : undefined;