@micromag/element-video 0.3.112 → 0.3.119
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/es/index.js +16 -25
- package/lib/index.js +15 -24
- package/package.json +5 -5
package/es/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import PropTypes$1 from 'prop-types';
|
|
|
6
6
|
import React, { useMemo, useEffect, useRef } from 'react';
|
|
7
7
|
import { PropTypes } from '@micromag/core';
|
|
8
8
|
import { useUserInteracted } from '@micromag/core/contexts';
|
|
9
|
-
import { useMediaApi } from '@micromag/core/hooks';
|
|
9
|
+
import { useMediaThumbnail, useMediaApi } from '@micromag/core/hooks';
|
|
10
10
|
import { getMediaFilesAsArray } from '@micromag/core/utils';
|
|
11
11
|
|
|
12
12
|
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","video":"micromag-element-video-video"};
|
|
@@ -14,6 +14,7 @@ var styles = {"container":"micromag-element-video-container","withSize":"microma
|
|
|
14
14
|
var _excluded = ["ref"];
|
|
15
15
|
var propTypes = {
|
|
16
16
|
media: PropTypes.videoMedia,
|
|
17
|
+
thumbnailFile: PropTypes$1.string,
|
|
17
18
|
width: PropTypes$1.number,
|
|
18
19
|
height: PropTypes$1.number,
|
|
19
20
|
apiRef: PropTypes$1.oneOfType([PropTypes$1.func, PropTypes$1.shape({
|
|
@@ -42,6 +43,7 @@ var propTypes = {
|
|
|
42
43
|
};
|
|
43
44
|
var defaultProps = {
|
|
44
45
|
media: null,
|
|
46
|
+
thumbnailFile: null,
|
|
45
47
|
width: null,
|
|
46
48
|
height: null,
|
|
47
49
|
apiRef: null,
|
|
@@ -71,6 +73,7 @@ var Video = function Video(_ref) {
|
|
|
71
73
|
var _ref7;
|
|
72
74
|
|
|
73
75
|
var media = _ref.media,
|
|
76
|
+
thumbnailFile = _ref.thumbnailFile,
|
|
74
77
|
width = _ref.width,
|
|
75
78
|
height = _ref.height,
|
|
76
79
|
apiRef = _ref.apiRef,
|
|
@@ -100,9 +103,7 @@ var Video = function Video(_ref) {
|
|
|
100
103
|
_ref2$files = _ref2.files,
|
|
101
104
|
files = _ref2$files === void 0 ? null : _ref2$files,
|
|
102
105
|
_ref2$metadata = _ref2.metadata,
|
|
103
|
-
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata
|
|
104
|
-
_ref2$thumbnail_url = _ref2.thumbnail_url,
|
|
105
|
-
thumbnailUrl = _ref2$thumbnail_url === void 0 ? null : _ref2$thumbnail_url;
|
|
106
|
+
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata;
|
|
106
107
|
|
|
107
108
|
var _ref3 = metadata || {},
|
|
108
109
|
_ref3$description = _ref3.description,
|
|
@@ -112,7 +113,8 @@ var Video = function Video(_ref) {
|
|
|
112
113
|
|
|
113
114
|
var filesArray = useMemo(function () {
|
|
114
115
|
return getMediaFilesAsArray(files);
|
|
115
|
-
}, [files]);
|
|
116
|
+
}, [files]);
|
|
117
|
+
var thumbnailUrl = useMediaThumbnail(media, thumbnailFile); // Get source files with supported mimes
|
|
116
118
|
|
|
117
119
|
var sourceFiles = useMemo(function () {
|
|
118
120
|
if (filesArray.length === 0) {
|
|
@@ -182,8 +184,7 @@ var Video = function Video(_ref) {
|
|
|
182
184
|
apiRef.current.mediaRef = ref;
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
var
|
|
186
|
-
muted = api.muted,
|
|
187
|
+
var muted = api.muted,
|
|
187
188
|
dataReady = api.dataReady,
|
|
188
189
|
play = api.play,
|
|
189
190
|
pause = api.pause,
|
|
@@ -193,19 +194,7 @@ var Video = function Video(_ref) {
|
|
|
193
194
|
onReady();
|
|
194
195
|
}
|
|
195
196
|
}, [dataReady, onReady]);
|
|
196
|
-
var withSize = width !== null && height !== null;
|
|
197
|
-
// useEffect(() => {
|
|
198
|
-
// if (thumbnailUrl !== null) {
|
|
199
|
-
// const img = new Image();
|
|
200
|
-
// img.src = thumbnailUrl;
|
|
201
|
-
// img.onload = () => {
|
|
202
|
-
// if (onPosterLoaded) {
|
|
203
|
-
// onPosterLoaded();
|
|
204
|
-
// }
|
|
205
|
-
// };
|
|
206
|
-
// }
|
|
207
|
-
// }, [thumbnailUrl]);
|
|
208
|
-
|
|
197
|
+
var withSize = width !== null && height !== null;
|
|
209
198
|
useEffect(function () {
|
|
210
199
|
if (autoPlay) {
|
|
211
200
|
play();
|
|
@@ -219,21 +208,23 @@ var Video = function Video(_ref) {
|
|
|
219
208
|
}, [autoPlay]); // Ensure load if preload value change over time
|
|
220
209
|
|
|
221
210
|
var firstPreloadRef = useRef(preload);
|
|
222
|
-
var
|
|
211
|
+
var firstShouldLoadRef = useRef(shouldLoad);
|
|
212
|
+
var hasLoadedRef = useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
223
213
|
useEffect(function () {
|
|
224
214
|
var _ref$current = ref.current,
|
|
225
215
|
videoElement = _ref$current === void 0 ? null : _ref$current;
|
|
226
216
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
227
217
|
|
|
228
218
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
219
|
+
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
229
220
|
|
|
230
|
-
if (canLoad && preloadHasChanged && !hasLoadedRef.current && videoElement !== null && typeof videoElement.load !== 'undefined') {
|
|
221
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && videoElement !== null && typeof videoElement.load !== 'undefined') {
|
|
231
222
|
hasLoadedRef.current = true;
|
|
232
223
|
videoElement.load();
|
|
233
224
|
}
|
|
234
225
|
}, [shouldLoad, preload]);
|
|
235
226
|
return /*#__PURE__*/React.createElement("div", {
|
|
236
|
-
className: classNames([styles.container, (_ref7 = {}, _defineProperty(_ref7, className, className !== null), _defineProperty(_ref7, styles.
|
|
227
|
+
className: classNames([styles.container, (_ref7 = {}, _defineProperty(_ref7, className, className !== null), _defineProperty(_ref7, styles.withSize, withSize), _ref7)]),
|
|
237
228
|
style: withSize ? {
|
|
238
229
|
width: width,
|
|
239
230
|
height: height
|
|
@@ -245,12 +236,12 @@ var Video = function Video(_ref) {
|
|
|
245
236
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
246
237
|
key: mediaUrl,
|
|
247
238
|
ref: ref,
|
|
248
|
-
src: sourceFiles === null ? mediaUrl : null,
|
|
239
|
+
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
249
240
|
autoPlay: autoPlay,
|
|
250
241
|
loop: loop,
|
|
251
242
|
muted: muted,
|
|
252
243
|
poster: shouldLoad ? thumbnailUrl : null,
|
|
253
|
-
preload: shouldLoad ? preload : '
|
|
244
|
+
preload: shouldLoad ? preload : 'none',
|
|
254
245
|
playsInline: playsInline,
|
|
255
246
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
256
247
|
tabIndex: focusable ? '0' : '-1',
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,7 @@ var styles = {"container":"micromag-element-video-container","withSize":"microma
|
|
|
25
25
|
var _excluded = ["ref"];
|
|
26
26
|
var propTypes = {
|
|
27
27
|
media: core.PropTypes.videoMedia,
|
|
28
|
+
thumbnailFile: PropTypes__default["default"].string,
|
|
28
29
|
width: PropTypes__default["default"].number,
|
|
29
30
|
height: PropTypes__default["default"].number,
|
|
30
31
|
apiRef: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].shape({
|
|
@@ -53,6 +54,7 @@ var propTypes = {
|
|
|
53
54
|
};
|
|
54
55
|
var defaultProps = {
|
|
55
56
|
media: null,
|
|
57
|
+
thumbnailFile: null,
|
|
56
58
|
width: null,
|
|
57
59
|
height: null,
|
|
58
60
|
apiRef: null,
|
|
@@ -82,6 +84,7 @@ var Video = function Video(_ref) {
|
|
|
82
84
|
var _ref7;
|
|
83
85
|
|
|
84
86
|
var media = _ref.media,
|
|
87
|
+
thumbnailFile = _ref.thumbnailFile,
|
|
85
88
|
width = _ref.width,
|
|
86
89
|
height = _ref.height,
|
|
87
90
|
apiRef = _ref.apiRef,
|
|
@@ -111,9 +114,7 @@ var Video = function Video(_ref) {
|
|
|
111
114
|
_ref2$files = _ref2.files,
|
|
112
115
|
files = _ref2$files === void 0 ? null : _ref2$files,
|
|
113
116
|
_ref2$metadata = _ref2.metadata,
|
|
114
|
-
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata
|
|
115
|
-
_ref2$thumbnail_url = _ref2.thumbnail_url,
|
|
116
|
-
thumbnailUrl = _ref2$thumbnail_url === void 0 ? null : _ref2$thumbnail_url;
|
|
117
|
+
metadata = _ref2$metadata === void 0 ? null : _ref2$metadata;
|
|
117
118
|
|
|
118
119
|
var _ref3 = metadata || {},
|
|
119
120
|
_ref3$description = _ref3.description,
|
|
@@ -123,7 +124,8 @@ var Video = function Video(_ref) {
|
|
|
123
124
|
|
|
124
125
|
var filesArray = React.useMemo(function () {
|
|
125
126
|
return utils.getMediaFilesAsArray(files);
|
|
126
|
-
}, [files]);
|
|
127
|
+
}, [files]);
|
|
128
|
+
var thumbnailUrl = hooks.useMediaThumbnail(media, thumbnailFile); // Get source files with supported mimes
|
|
127
129
|
|
|
128
130
|
var sourceFiles = React.useMemo(function () {
|
|
129
131
|
if (filesArray.length === 0) {
|
|
@@ -193,8 +195,7 @@ var Video = function Video(_ref) {
|
|
|
193
195
|
apiRef.current.mediaRef = ref;
|
|
194
196
|
}
|
|
195
197
|
|
|
196
|
-
var
|
|
197
|
-
muted = api.muted,
|
|
198
|
+
var muted = api.muted,
|
|
198
199
|
dataReady = api.dataReady,
|
|
199
200
|
play = api.play,
|
|
200
201
|
pause = api.pause,
|
|
@@ -204,19 +205,7 @@ var Video = function Video(_ref) {
|
|
|
204
205
|
onReady();
|
|
205
206
|
}
|
|
206
207
|
}, [dataReady, onReady]);
|
|
207
|
-
var withSize = width !== null && height !== null;
|
|
208
|
-
// useEffect(() => {
|
|
209
|
-
// if (thumbnailUrl !== null) {
|
|
210
|
-
// const img = new Image();
|
|
211
|
-
// img.src = thumbnailUrl;
|
|
212
|
-
// img.onload = () => {
|
|
213
|
-
// if (onPosterLoaded) {
|
|
214
|
-
// onPosterLoaded();
|
|
215
|
-
// }
|
|
216
|
-
// };
|
|
217
|
-
// }
|
|
218
|
-
// }, [thumbnailUrl]);
|
|
219
|
-
|
|
208
|
+
var withSize = width !== null && height !== null;
|
|
220
209
|
React.useEffect(function () {
|
|
221
210
|
if (autoPlay) {
|
|
222
211
|
play();
|
|
@@ -230,21 +219,23 @@ var Video = function Video(_ref) {
|
|
|
230
219
|
}, [autoPlay]); // Ensure load if preload value change over time
|
|
231
220
|
|
|
232
221
|
var firstPreloadRef = React.useRef(preload);
|
|
233
|
-
var
|
|
222
|
+
var firstShouldLoadRef = React.useRef(shouldLoad);
|
|
223
|
+
var hasLoadedRef = React.useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
234
224
|
React.useEffect(function () {
|
|
235
225
|
var _ref$current = ref.current,
|
|
236
226
|
videoElement = _ref$current === void 0 ? null : _ref$current;
|
|
237
227
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
238
228
|
|
|
239
229
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
230
|
+
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
240
231
|
|
|
241
|
-
if (canLoad && preloadHasChanged && !hasLoadedRef.current && videoElement !== null && typeof videoElement.load !== 'undefined') {
|
|
232
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && videoElement !== null && typeof videoElement.load !== 'undefined') {
|
|
242
233
|
hasLoadedRef.current = true;
|
|
243
234
|
videoElement.load();
|
|
244
235
|
}
|
|
245
236
|
}, [shouldLoad, preload]);
|
|
246
237
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
247
|
-
className: classNames__default["default"]([styles.container, (_ref7 = {}, _defineProperty__default["default"](_ref7, className, className !== null), _defineProperty__default["default"](_ref7, styles.
|
|
238
|
+
className: classNames__default["default"]([styles.container, (_ref7 = {}, _defineProperty__default["default"](_ref7, className, className !== null), _defineProperty__default["default"](_ref7, styles.withSize, withSize), _ref7)]),
|
|
248
239
|
style: withSize ? {
|
|
249
240
|
width: width,
|
|
250
241
|
height: height
|
|
@@ -256,12 +247,12 @@ var Video = function Video(_ref) {
|
|
|
256
247
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React__default["default"].createElement("video", {
|
|
257
248
|
key: mediaUrl,
|
|
258
249
|
ref: ref,
|
|
259
|
-
src: sourceFiles === null ? mediaUrl : null,
|
|
250
|
+
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
260
251
|
autoPlay: autoPlay,
|
|
261
252
|
loop: loop,
|
|
262
253
|
muted: muted,
|
|
263
254
|
poster: shouldLoad ? thumbnailUrl : null,
|
|
264
|
-
preload: shouldLoad ? preload : '
|
|
255
|
+
preload: shouldLoad ? preload : 'none',
|
|
265
256
|
playsInline: playsInline,
|
|
266
257
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
267
258
|
tabIndex: focusable ? '0' : '-1',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.119",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
53
53
|
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
54
54
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
55
|
-
"@micromag/core": "^0.3.
|
|
56
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
57
|
-
"@micromag/element-media-controls": "^0.3.
|
|
55
|
+
"@micromag/core": "^0.3.119",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.119",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.119",
|
|
58
58
|
"classnames": "^2.2.6",
|
|
59
59
|
"prop-types": "^15.7.2",
|
|
60
60
|
"react-intl": "^5.12.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "009841dc1641be98ddce6ed56cfcddc22509f342"
|
|
67
67
|
}
|