@micromag/element-visual 0.3.803 → 0.3.811

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.
Files changed (2) hide show
  1. package/es/index.js +20 -4
  2. package/package.json +5 -5
package/es/index.js CHANGED
@@ -6,12 +6,13 @@ import classNames from 'classnames';
6
6
  import PropTypes from 'prop-types';
7
7
  import React, { useMemo, useCallback } from 'react';
8
8
  import { PropTypes as PropTypes$1 } from '@micromag/core';
9
+ import { useIsVisible } from '@micromag/core/hooks';
9
10
  import Image from '@micromag/element-image';
10
11
  import Video from '@micromag/element-video';
11
12
 
12
13
  var styles = {"container":"micromag-element-visual-container","videoContainer":"micromag-element-visual-videoContainer","videoTag":"micromag-element-visual-videoTag","videoTouchOverlay":"micromag-element-visual-videoTouchOverlay"};
13
14
 
14
- var _excluded = ["media", "mediaRef", "width", "height", "resolution", "objectFit", "playing", "muted", "shouldLoad", "videoLoop", "videoInitialMuted", "onLoaded", "className", "imageClassName", "videoClassName", "withoutVideo", "qualityStartLevel", "onQualityLevelChange"];
15
+ var _excluded = ["media", "mediaRef", "width", "height", "resolution", "objectFit", "playing", "muted", "loadingMode", "shouldLoad", "videoLoop", "videoInitialMuted", "onLoaded", "className", "imageClassName", "videoClassName", "withoutVideo", "qualityStartLevel", "onQualityLevelChange"];
15
16
  var propTypes = {
16
17
  media: PropTypes$1.media,
17
18
  mediaRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
@@ -25,6 +26,7 @@ var propTypes = {
25
26
  playing: PropTypes.bool,
26
27
  muted: PropTypes.bool,
27
28
  shouldLoad: PropTypes.bool,
29
+ loadingMode: PropTypes.string,
28
30
  videoLoop: PropTypes.bool,
29
31
  withoutVideo: PropTypes.bool,
30
32
  videoInitialMuted: PropTypes.bool,
@@ -44,6 +46,7 @@ var defaultProps = {
44
46
  objectFit: null,
45
47
  playing: true,
46
48
  muted: true,
49
+ loadingMode: null,
47
50
  shouldLoad: true,
48
51
  videoLoop: true,
49
52
  withoutVideo: false,
@@ -64,6 +67,7 @@ var Visual = function Visual(_ref) {
64
67
  objectFit = _ref.objectFit,
65
68
  playing = _ref.playing,
66
69
  muted = _ref.muted,
70
+ loadingMode = _ref.loadingMode,
67
71
  shouldLoad = _ref.shouldLoad,
68
72
  videoLoop = _ref.videoLoop;
69
73
  _ref.videoInitialMuted;
@@ -88,6 +92,15 @@ var Visual = function Visual(_ref) {
88
92
  media: media
89
93
  });
90
94
  }, [props, media]);
95
+ var isLazyLoading = loadingMode === 'lazy';
96
+ var _useIsVisible = useIsVisible({
97
+ rootMargin: '200px',
98
+ persist: true,
99
+ disabled: !isLazyLoading
100
+ }),
101
+ refVisible = _useIsVisible.ref,
102
+ isVisible = _useIsVisible.visible;
103
+ var finalShouldLoad = (!isLazyLoading || isVisible) && shouldLoad;
91
104
  var imageElProps = useMemo(function () {
92
105
  var tmpProps = (!shouldLoad || withoutVideo) && isVideo ? _objectSpread(_objectSpread({}, elProps), {}, {
93
106
  media: {
@@ -133,11 +146,13 @@ var Visual = function Visual(_ref) {
133
146
  }
134
147
  }, []);
135
148
  return type !== null ? /*#__PURE__*/React.createElement(React.Fragment, null, type === 'image' || !shouldLoad || withoutVideo ? /*#__PURE__*/React.createElement(Image, Object.assign({}, imageElProps, {
149
+ ref: refVisible,
150
+ loadingMode: loadingMode !== 'lazy' ? 'lazy' : null,
136
151
  objectFit: objectFit,
137
152
  width: width,
138
153
  height: height,
139
154
  resolution: resolution,
140
- shouldLoad: shouldLoad,
155
+ shouldLoad: finalShouldLoad,
141
156
  onLoaded: onLoaded,
142
157
  className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
143
158
  imageClassName: imageClassName
@@ -146,7 +161,8 @@ var Visual = function Visual(_ref) {
146
161
  style: {
147
162
  width: width,
148
163
  height: height
149
- }
164
+ },
165
+ ref: refVisible
150
166
  }, /*#__PURE__*/React.createElement("div", {
151
167
  className: classNames([styles.videoContainer, _defineProperty({}, videoClassName, videoClassName !== null)]),
152
168
  style: videoContainerStyle
@@ -158,7 +174,7 @@ var Visual = function Visual(_ref) {
158
174
  paused: !playing,
159
175
  muted: muted,
160
176
  loop: videoLoop,
161
- shouldLoad: shouldLoad,
177
+ shouldLoad: finalShouldLoad,
162
178
  onReady: onLoaded,
163
179
  autoPlay: true,
164
180
  qualityStartLevel: qualityStartLevel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-visual",
3
- "version": "0.3.803",
3
+ "version": "0.3.811",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -60,9 +60,9 @@
60
60
  "dependencies": {
61
61
  "@babel/runtime": "^7.13.10",
62
62
  "@folklore/size": "^0.1.20",
63
- "@micromag/core": "^0.3.803",
64
- "@micromag/element-image": "^0.3.803",
65
- "@micromag/element-video": "^0.3.803",
63
+ "@micromag/core": "^0.3.811",
64
+ "@micromag/element-image": "^0.3.811",
65
+ "@micromag/element-video": "^0.3.811",
66
66
  "classnames": "^2.2.6",
67
67
  "prop-types": "^15.7.2",
68
68
  "uuid": "^9.0.0"
@@ -71,5 +71,5 @@
71
71
  "access": "public",
72
72
  "registry": "https://registry.npmjs.org/"
73
73
  },
74
- "gitHead": "b8d7486367da5144fa0824e48527c44aa4123ddf"
74
+ "gitHead": "80a754e5a50e86fa1e195015112ea0ff39008da8"
75
75
  }