@micromag/element-video 0.3.150 → 0.3.156
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 +111 -80
- package/lib/index.js +110 -79
- package/package.json +6 -5
package/es/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
2
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
2
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
4
3
|
import classNames from 'classnames';
|
|
4
|
+
import isFunction from 'lodash/isFunction';
|
|
5
5
|
import PropTypes$1 from 'prop-types';
|
|
6
|
-
import React, { useMemo, useEffect,
|
|
6
|
+
import React, { useMemo, useRef, useEffect, useCallback } from 'react';
|
|
7
7
|
import { PropTypes } from '@micromag/core';
|
|
8
|
-
import {
|
|
9
|
-
import { useMediaThumbnail, useMediaApi } from '@micromag/core/hooks';
|
|
8
|
+
import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useMediaLoad, useProgressSteps } from '@micromag/core/hooks';
|
|
10
9
|
import { getMediaFilesAsArray } from '@micromag/core/utils';
|
|
11
10
|
|
|
12
11
|
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","video":"micromag-element-video-video"};
|
|
13
12
|
|
|
14
|
-
var _excluded = ["ref"];
|
|
15
13
|
var propTypes = {
|
|
16
14
|
media: PropTypes.videoMedia,
|
|
17
|
-
|
|
15
|
+
thumbnail: PropTypes$1.oneOf([PropTypes$1.string, PropTypes.imageMedia]),
|
|
18
16
|
width: PropTypes$1.number,
|
|
19
17
|
height: PropTypes$1.number,
|
|
20
|
-
|
|
18
|
+
mediaRef: PropTypes$1.oneOfType([PropTypes$1.func, PropTypes$1.shape({
|
|
21
19
|
current: PropTypes$1.any
|
|
22
20
|
})]),
|
|
23
|
-
|
|
21
|
+
muted: PropTypes$1.bool,
|
|
24
22
|
autoPlay: PropTypes$1.bool,
|
|
23
|
+
paused: PropTypes$1.bool,
|
|
25
24
|
loop: PropTypes$1.bool,
|
|
26
25
|
playsInline: PropTypes$1.bool,
|
|
27
26
|
preload: PropTypes$1.oneOf(['auto', 'metadata', 'none', null]),
|
|
@@ -30,15 +29,14 @@ var propTypes = {
|
|
|
30
29
|
className: PropTypes$1.string,
|
|
31
30
|
onReady: PropTypes$1.func,
|
|
32
31
|
onPlay: PropTypes$1.func,
|
|
33
|
-
onCanPlay: PropTypes$1.func,
|
|
34
32
|
onPause: PropTypes$1.func,
|
|
35
33
|
onEnded: PropTypes$1.func,
|
|
36
34
|
onSeeked: PropTypes$1.func,
|
|
37
35
|
onTimeUpdate: PropTypes$1.func,
|
|
38
36
|
onProgressStep: PropTypes$1.func,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
onDurationChange: PropTypes$1.func,
|
|
38
|
+
onVolumeChange: PropTypes$1.func,
|
|
39
|
+
onSuspend: PropTypes$1.func,
|
|
42
40
|
focusable: PropTypes$1.bool,
|
|
43
41
|
supportedMimes: PropTypes$1.arrayOf(PropTypes$1.string),
|
|
44
42
|
withPoster: PropTypes$1.bool // onPosterLoaded: PropTypes.func,
|
|
@@ -46,12 +44,13 @@ var propTypes = {
|
|
|
46
44
|
};
|
|
47
45
|
var defaultProps = {
|
|
48
46
|
media: null,
|
|
49
|
-
|
|
47
|
+
thumbnail: null,
|
|
50
48
|
width: null,
|
|
51
49
|
height: null,
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
mediaRef: null,
|
|
51
|
+
muted: false,
|
|
54
52
|
autoPlay: false,
|
|
53
|
+
paused: false,
|
|
55
54
|
loop: false,
|
|
56
55
|
playsInline: true,
|
|
57
56
|
preload: 'auto',
|
|
@@ -60,15 +59,14 @@ var defaultProps = {
|
|
|
60
59
|
className: null,
|
|
61
60
|
onReady: null,
|
|
62
61
|
onPlay: null,
|
|
63
|
-
onCanPlay: null,
|
|
64
62
|
onPause: null,
|
|
65
63
|
onEnded: null,
|
|
66
64
|
onSeeked: null,
|
|
67
65
|
onTimeUpdate: null,
|
|
68
66
|
onProgressStep: null,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
onDurationChange: null,
|
|
68
|
+
onVolumeChange: null,
|
|
69
|
+
onSuspend: null,
|
|
72
70
|
focusable: true,
|
|
73
71
|
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
74
72
|
withPoster: false
|
|
@@ -78,12 +76,13 @@ var Video = function Video(_ref) {
|
|
|
78
76
|
var _ref7;
|
|
79
77
|
|
|
80
78
|
var media = _ref.media,
|
|
81
|
-
|
|
79
|
+
thumbnail = _ref.thumbnail,
|
|
82
80
|
width = _ref.width,
|
|
83
81
|
height = _ref.height,
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
mediaRef = _ref.mediaRef,
|
|
83
|
+
muted = _ref.muted,
|
|
86
84
|
autoPlay = _ref.autoPlay,
|
|
85
|
+
paused = _ref.paused,
|
|
87
86
|
loop = _ref.loop,
|
|
88
87
|
playsInline = _ref.playsInline,
|
|
89
88
|
preload = _ref.preload,
|
|
@@ -92,15 +91,14 @@ var Video = function Video(_ref) {
|
|
|
92
91
|
className = _ref.className,
|
|
93
92
|
onReady = _ref.onReady,
|
|
94
93
|
onPlay = _ref.onPlay,
|
|
95
|
-
onCanPlay = _ref.onCanPlay,
|
|
96
94
|
onPause = _ref.onPause,
|
|
97
95
|
onEnded = _ref.onEnded,
|
|
98
96
|
onSeeked = _ref.onSeeked,
|
|
99
97
|
onTimeUpdate = _ref.onTimeUpdate,
|
|
100
98
|
onProgressStep = _ref.onProgressStep,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
customOnDurationChange = _ref.onDurationChange,
|
|
100
|
+
customOnVolumeChange = _ref.onVolumeChange,
|
|
101
|
+
onSuspend = _ref.onSuspend,
|
|
104
102
|
focusable = _ref.focusable,
|
|
105
103
|
supportedMimes = _ref.supportedMimes,
|
|
106
104
|
withPoster = _ref.withPoster;
|
|
@@ -117,12 +115,31 @@ var Video = function Video(_ref) {
|
|
|
117
115
|
_ref3$description = _ref3.description,
|
|
118
116
|
description = _ref3$description === void 0 ? null : _ref3$description,
|
|
119
117
|
_ref3$mime = _ref3.mime,
|
|
120
|
-
mediaMime = _ref3$mime === void 0 ? null : _ref3$mime
|
|
118
|
+
mediaMime = _ref3$mime === void 0 ? null : _ref3$mime,
|
|
119
|
+
_ref3$has_audio = _ref3.has_audio,
|
|
120
|
+
hasAudio = _ref3$has_audio === void 0 ? null : _ref3$has_audio;
|
|
121
121
|
|
|
122
122
|
var filesArray = useMemo(function () {
|
|
123
123
|
return getMediaFilesAsArray(files);
|
|
124
124
|
}, [files]);
|
|
125
|
-
var
|
|
125
|
+
var finalThumbnail = useMediaThumbnail(media, thumbnail);
|
|
126
|
+
|
|
127
|
+
var _ref9 = useRef(null);
|
|
128
|
+
|
|
129
|
+
var currentTime = useMediaCurrentTime(_ref9.current, {
|
|
130
|
+
id: mediaUrl,
|
|
131
|
+
disabled: paused || onProgressStep === null
|
|
132
|
+
});
|
|
133
|
+
var duration = useMediaDuration(_ref9.current, {
|
|
134
|
+
id: mediaUrl
|
|
135
|
+
});
|
|
136
|
+
var ready = useMediaReady(_ref9.current, {
|
|
137
|
+
id: mediaUrl
|
|
138
|
+
});
|
|
139
|
+
useMediaLoad(_ref9.current, {
|
|
140
|
+
preload: preload,
|
|
141
|
+
shouldLoad: shouldLoad
|
|
142
|
+
}); // Get source files with supported mimes
|
|
126
143
|
|
|
127
144
|
var sourceFiles = useMemo(function () {
|
|
128
145
|
if (filesArray.length === 0) {
|
|
@@ -169,70 +186,68 @@ var Video = function Video(_ref) {
|
|
|
169
186
|
|
|
170
187
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
171
188
|
var isImageWithoutSourceFile = originalFileIsImage && (sourceFiles === null || sourceFiles.length === 0);
|
|
172
|
-
var userInteracted = useUserInteracted();
|
|
173
|
-
var finalInitialMuted = initialMuted === true || initialMuted === 'auto' && autoPlay && !userInteracted;
|
|
174
|
-
|
|
175
|
-
var _useMediaApi = useMediaApi({
|
|
176
|
-
url: !isImageWithoutSourceFile ? mediaUrl : null,
|
|
177
|
-
initialMuted: finalInitialMuted,
|
|
178
|
-
onPlay: onPlay,
|
|
179
|
-
onCanPlay: onCanPlay,
|
|
180
|
-
onPause: onPause,
|
|
181
|
-
onEnded: onEnded,
|
|
182
|
-
onSeeked: onSeeked,
|
|
183
|
-
onTimeUpdate: onTimeUpdate,
|
|
184
|
-
onProgressStep: onProgressStep,
|
|
185
|
-
onDurationChanged: onDurationChanged,
|
|
186
|
-
onVolumeChanged: onVolumeChanged,
|
|
187
|
-
onSuspended: onSuspended
|
|
188
|
-
}),
|
|
189
|
-
ref = _useMediaApi.ref,
|
|
190
|
-
api = _objectWithoutProperties(_useMediaApi, _excluded);
|
|
191
|
-
|
|
192
|
-
if (apiRef !== null) {
|
|
193
|
-
apiRef.current = api;
|
|
194
|
-
apiRef.current.mediaRef = ref;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
var muted = api.muted,
|
|
198
|
-
dataReady = api.dataReady,
|
|
199
|
-
play = api.play,
|
|
200
|
-
pause = api.pause,
|
|
201
|
-
unMute = api.unMute;
|
|
202
|
-
useEffect(function () {
|
|
203
|
-
if (dataReady && onReady !== null) {
|
|
204
|
-
onReady();
|
|
205
|
-
}
|
|
206
|
-
}, [dataReady, onReady]);
|
|
207
189
|
var withSize = width !== null && height !== null;
|
|
208
190
|
useEffect(function () {
|
|
209
|
-
if (
|
|
210
|
-
|
|
191
|
+
if (duration > 0 && customOnDurationChange !== null) {
|
|
192
|
+
customOnDurationChange(duration);
|
|
193
|
+
}
|
|
194
|
+
}, [duration, customOnDurationChange]);
|
|
195
|
+
var onVolumeChange = useCallback(function () {
|
|
196
|
+
var _ref$current = _ref9.current,
|
|
197
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
211
198
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
199
|
+
if (element === null) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (customOnVolumeChange !== null) {
|
|
204
|
+
customOnVolumeChange(element.volume);
|
|
217
205
|
}
|
|
218
|
-
}, [
|
|
206
|
+
}, [customOnVolumeChange]); // Ensure load if preload value change over time
|
|
219
207
|
|
|
220
208
|
var firstPreloadRef = useRef(preload);
|
|
221
209
|
var firstShouldLoadRef = useRef(shouldLoad);
|
|
222
210
|
var hasLoadedRef = useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
223
211
|
useEffect(function () {
|
|
224
|
-
var _ref$
|
|
225
|
-
|
|
212
|
+
var _ref$current2 = _ref9.current,
|
|
213
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
226
214
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
227
215
|
|
|
228
216
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
229
217
|
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
230
218
|
|
|
231
|
-
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current &&
|
|
219
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
232
220
|
hasLoadedRef.current = true;
|
|
233
|
-
|
|
221
|
+
element.load();
|
|
234
222
|
}
|
|
235
223
|
}, [shouldLoad, preload]);
|
|
224
|
+
useEffect(function () {
|
|
225
|
+
if (ready && onReady !== null) {
|
|
226
|
+
onReady();
|
|
227
|
+
}
|
|
228
|
+
}, [ready, onReady]);
|
|
229
|
+
useEffect(function () {
|
|
230
|
+
var _ref$current3 = _ref9.current,
|
|
231
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
232
|
+
|
|
233
|
+
if (element === null) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
var isPaused = element.paused;
|
|
238
|
+
|
|
239
|
+
if (paused && !isPaused) {
|
|
240
|
+
element.pause();
|
|
241
|
+
} else if (!paused && isPaused) {
|
|
242
|
+
element.play();
|
|
243
|
+
}
|
|
244
|
+
}, [paused]);
|
|
245
|
+
useProgressSteps({
|
|
246
|
+
currentTime: currentTime,
|
|
247
|
+
duration: duration,
|
|
248
|
+
disabled: paused,
|
|
249
|
+
onStep: onProgressStep
|
|
250
|
+
});
|
|
236
251
|
return /*#__PURE__*/React.createElement("div", {
|
|
237
252
|
className: classNames([styles.container, (_ref7 = {}, _defineProperty(_ref7, className, className !== null), _defineProperty(_ref7, styles.withSize, withSize), _ref7)]),
|
|
238
253
|
style: withSize ? {
|
|
@@ -245,17 +260,33 @@ var Video = function Video(_ref) {
|
|
|
245
260
|
className: styles.video
|
|
246
261
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
247
262
|
key: mediaUrl,
|
|
248
|
-
ref: ref
|
|
263
|
+
ref: function ref(newRef) {
|
|
264
|
+
_ref9.current = newRef;
|
|
265
|
+
|
|
266
|
+
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
267
|
+
mediaRef(newRef);
|
|
268
|
+
} else if (mediaRef !== null) {
|
|
269
|
+
mediaRef.current = newRef;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
249
272
|
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
250
|
-
autoPlay: autoPlay,
|
|
273
|
+
autoPlay: autoPlay && !paused,
|
|
251
274
|
loop: loop,
|
|
252
275
|
muted: muted,
|
|
253
|
-
poster: shouldLoad && withPoster ?
|
|
276
|
+
poster: shouldLoad && withPoster && finalThumbnail !== null ? finalThumbnail.url || null : null,
|
|
254
277
|
preload: shouldLoad ? preload : 'none',
|
|
255
278
|
playsInline: playsInline,
|
|
256
279
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
257
280
|
tabIndex: focusable ? '0' : '-1',
|
|
258
|
-
className: classNames(styles.video)
|
|
281
|
+
className: classNames(styles.video),
|
|
282
|
+
onPlay: onPlay,
|
|
283
|
+
onPause: onPause,
|
|
284
|
+
onEnded: onEnded,
|
|
285
|
+
onSeeked: onSeeked,
|
|
286
|
+
onVolumeChange: onVolumeChange,
|
|
287
|
+
onTimeUpdate: onTimeUpdate,
|
|
288
|
+
onSuspend: onSuspend,
|
|
289
|
+
"data-has-audio": hasAudio
|
|
259
290
|
}, (sourceFiles || []).map(function (_ref8) {
|
|
260
291
|
var sourceUrl = _ref8.url,
|
|
261
292
|
sourceMime = _ref8.mime;
|
|
@@ -271,7 +302,7 @@ Video.propTypes = propTypes;
|
|
|
271
302
|
Video.defaultProps = defaultProps;
|
|
272
303
|
var Video$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
273
304
|
return /*#__PURE__*/React.createElement(Video, Object.assign({
|
|
274
|
-
|
|
305
|
+
mediaRef: ref
|
|
275
306
|
}, props));
|
|
276
307
|
});
|
|
277
308
|
|
package/lib/index.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
4
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
5
|
var classNames = require('classnames');
|
|
6
|
+
var isFunction = require('lodash/isFunction');
|
|
7
7
|
var PropTypes = require('prop-types');
|
|
8
8
|
var React = require('react');
|
|
9
9
|
var core = require('@micromag/core');
|
|
10
|
-
var contexts = require('@micromag/core/contexts');
|
|
11
10
|
var hooks = require('@micromag/core/hooks');
|
|
12
11
|
var utils = require('@micromag/core/utils');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
14
|
|
|
16
|
-
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
17
15
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
18
16
|
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
19
17
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
18
|
+
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
|
|
20
19
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
21
20
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
22
21
|
|
|
23
22
|
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","video":"micromag-element-video-video"};
|
|
24
23
|
|
|
25
|
-
var _excluded = ["ref"];
|
|
26
24
|
var propTypes = {
|
|
27
25
|
media: core.PropTypes.videoMedia,
|
|
28
|
-
|
|
26
|
+
thumbnail: PropTypes__default["default"].oneOf([PropTypes__default["default"].string, core.PropTypes.imageMedia]),
|
|
29
27
|
width: PropTypes__default["default"].number,
|
|
30
28
|
height: PropTypes__default["default"].number,
|
|
31
|
-
|
|
29
|
+
mediaRef: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].shape({
|
|
32
30
|
current: PropTypes__default["default"].any
|
|
33
31
|
})]),
|
|
34
|
-
|
|
32
|
+
muted: PropTypes__default["default"].bool,
|
|
35
33
|
autoPlay: PropTypes__default["default"].bool,
|
|
34
|
+
paused: PropTypes__default["default"].bool,
|
|
36
35
|
loop: PropTypes__default["default"].bool,
|
|
37
36
|
playsInline: PropTypes__default["default"].bool,
|
|
38
37
|
preload: PropTypes__default["default"].oneOf(['auto', 'metadata', 'none', null]),
|
|
@@ -41,15 +40,14 @@ var propTypes = {
|
|
|
41
40
|
className: PropTypes__default["default"].string,
|
|
42
41
|
onReady: PropTypes__default["default"].func,
|
|
43
42
|
onPlay: PropTypes__default["default"].func,
|
|
44
|
-
onCanPlay: PropTypes__default["default"].func,
|
|
45
43
|
onPause: PropTypes__default["default"].func,
|
|
46
44
|
onEnded: PropTypes__default["default"].func,
|
|
47
45
|
onSeeked: PropTypes__default["default"].func,
|
|
48
46
|
onTimeUpdate: PropTypes__default["default"].func,
|
|
49
47
|
onProgressStep: PropTypes__default["default"].func,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
onDurationChange: PropTypes__default["default"].func,
|
|
49
|
+
onVolumeChange: PropTypes__default["default"].func,
|
|
50
|
+
onSuspend: PropTypes__default["default"].func,
|
|
53
51
|
focusable: PropTypes__default["default"].bool,
|
|
54
52
|
supportedMimes: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
|
|
55
53
|
withPoster: PropTypes__default["default"].bool // onPosterLoaded: PropTypes.func,
|
|
@@ -57,12 +55,13 @@ var propTypes = {
|
|
|
57
55
|
};
|
|
58
56
|
var defaultProps = {
|
|
59
57
|
media: null,
|
|
60
|
-
|
|
58
|
+
thumbnail: null,
|
|
61
59
|
width: null,
|
|
62
60
|
height: null,
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
mediaRef: null,
|
|
62
|
+
muted: false,
|
|
65
63
|
autoPlay: false,
|
|
64
|
+
paused: false,
|
|
66
65
|
loop: false,
|
|
67
66
|
playsInline: true,
|
|
68
67
|
preload: 'auto',
|
|
@@ -71,15 +70,14 @@ var defaultProps = {
|
|
|
71
70
|
className: null,
|
|
72
71
|
onReady: null,
|
|
73
72
|
onPlay: null,
|
|
74
|
-
onCanPlay: null,
|
|
75
73
|
onPause: null,
|
|
76
74
|
onEnded: null,
|
|
77
75
|
onSeeked: null,
|
|
78
76
|
onTimeUpdate: null,
|
|
79
77
|
onProgressStep: null,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
onDurationChange: null,
|
|
79
|
+
onVolumeChange: null,
|
|
80
|
+
onSuspend: null,
|
|
83
81
|
focusable: true,
|
|
84
82
|
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
85
83
|
withPoster: false
|
|
@@ -89,12 +87,13 @@ var Video = function Video(_ref) {
|
|
|
89
87
|
var _ref7;
|
|
90
88
|
|
|
91
89
|
var media = _ref.media,
|
|
92
|
-
|
|
90
|
+
thumbnail = _ref.thumbnail,
|
|
93
91
|
width = _ref.width,
|
|
94
92
|
height = _ref.height,
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
mediaRef = _ref.mediaRef,
|
|
94
|
+
muted = _ref.muted,
|
|
97
95
|
autoPlay = _ref.autoPlay,
|
|
96
|
+
paused = _ref.paused,
|
|
98
97
|
loop = _ref.loop,
|
|
99
98
|
playsInline = _ref.playsInline,
|
|
100
99
|
preload = _ref.preload,
|
|
@@ -103,15 +102,14 @@ var Video = function Video(_ref) {
|
|
|
103
102
|
className = _ref.className,
|
|
104
103
|
onReady = _ref.onReady,
|
|
105
104
|
onPlay = _ref.onPlay,
|
|
106
|
-
onCanPlay = _ref.onCanPlay,
|
|
107
105
|
onPause = _ref.onPause,
|
|
108
106
|
onEnded = _ref.onEnded,
|
|
109
107
|
onSeeked = _ref.onSeeked,
|
|
110
108
|
onTimeUpdate = _ref.onTimeUpdate,
|
|
111
109
|
onProgressStep = _ref.onProgressStep,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
customOnDurationChange = _ref.onDurationChange,
|
|
111
|
+
customOnVolumeChange = _ref.onVolumeChange,
|
|
112
|
+
onSuspend = _ref.onSuspend,
|
|
115
113
|
focusable = _ref.focusable,
|
|
116
114
|
supportedMimes = _ref.supportedMimes,
|
|
117
115
|
withPoster = _ref.withPoster;
|
|
@@ -128,12 +126,31 @@ var Video = function Video(_ref) {
|
|
|
128
126
|
_ref3$description = _ref3.description,
|
|
129
127
|
description = _ref3$description === void 0 ? null : _ref3$description,
|
|
130
128
|
_ref3$mime = _ref3.mime,
|
|
131
|
-
mediaMime = _ref3$mime === void 0 ? null : _ref3$mime
|
|
129
|
+
mediaMime = _ref3$mime === void 0 ? null : _ref3$mime,
|
|
130
|
+
_ref3$has_audio = _ref3.has_audio,
|
|
131
|
+
hasAudio = _ref3$has_audio === void 0 ? null : _ref3$has_audio;
|
|
132
132
|
|
|
133
133
|
var filesArray = React.useMemo(function () {
|
|
134
134
|
return utils.getMediaFilesAsArray(files);
|
|
135
135
|
}, [files]);
|
|
136
|
-
var
|
|
136
|
+
var finalThumbnail = hooks.useMediaThumbnail(media, thumbnail);
|
|
137
|
+
|
|
138
|
+
var _ref9 = React.useRef(null);
|
|
139
|
+
|
|
140
|
+
var currentTime = hooks.useMediaCurrentTime(_ref9.current, {
|
|
141
|
+
id: mediaUrl,
|
|
142
|
+
disabled: paused || onProgressStep === null
|
|
143
|
+
});
|
|
144
|
+
var duration = hooks.useMediaDuration(_ref9.current, {
|
|
145
|
+
id: mediaUrl
|
|
146
|
+
});
|
|
147
|
+
var ready = hooks.useMediaReady(_ref9.current, {
|
|
148
|
+
id: mediaUrl
|
|
149
|
+
});
|
|
150
|
+
hooks.useMediaLoad(_ref9.current, {
|
|
151
|
+
preload: preload,
|
|
152
|
+
shouldLoad: shouldLoad
|
|
153
|
+
}); // Get source files with supported mimes
|
|
137
154
|
|
|
138
155
|
var sourceFiles = React.useMemo(function () {
|
|
139
156
|
if (filesArray.length === 0) {
|
|
@@ -180,70 +197,68 @@ var Video = function Video(_ref) {
|
|
|
180
197
|
|
|
181
198
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
182
199
|
var isImageWithoutSourceFile = originalFileIsImage && (sourceFiles === null || sourceFiles.length === 0);
|
|
183
|
-
var userInteracted = contexts.useUserInteracted();
|
|
184
|
-
var finalInitialMuted = initialMuted === true || initialMuted === 'auto' && autoPlay && !userInteracted;
|
|
185
|
-
|
|
186
|
-
var _useMediaApi = hooks.useMediaApi({
|
|
187
|
-
url: !isImageWithoutSourceFile ? mediaUrl : null,
|
|
188
|
-
initialMuted: finalInitialMuted,
|
|
189
|
-
onPlay: onPlay,
|
|
190
|
-
onCanPlay: onCanPlay,
|
|
191
|
-
onPause: onPause,
|
|
192
|
-
onEnded: onEnded,
|
|
193
|
-
onSeeked: onSeeked,
|
|
194
|
-
onTimeUpdate: onTimeUpdate,
|
|
195
|
-
onProgressStep: onProgressStep,
|
|
196
|
-
onDurationChanged: onDurationChanged,
|
|
197
|
-
onVolumeChanged: onVolumeChanged,
|
|
198
|
-
onSuspended: onSuspended
|
|
199
|
-
}),
|
|
200
|
-
ref = _useMediaApi.ref,
|
|
201
|
-
api = _objectWithoutProperties__default["default"](_useMediaApi, _excluded);
|
|
202
|
-
|
|
203
|
-
if (apiRef !== null) {
|
|
204
|
-
apiRef.current = api;
|
|
205
|
-
apiRef.current.mediaRef = ref;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
var muted = api.muted,
|
|
209
|
-
dataReady = api.dataReady,
|
|
210
|
-
play = api.play,
|
|
211
|
-
pause = api.pause,
|
|
212
|
-
unMute = api.unMute;
|
|
213
|
-
React.useEffect(function () {
|
|
214
|
-
if (dataReady && onReady !== null) {
|
|
215
|
-
onReady();
|
|
216
|
-
}
|
|
217
|
-
}, [dataReady, onReady]);
|
|
218
200
|
var withSize = width !== null && height !== null;
|
|
219
201
|
React.useEffect(function () {
|
|
220
|
-
if (
|
|
221
|
-
|
|
202
|
+
if (duration > 0 && customOnDurationChange !== null) {
|
|
203
|
+
customOnDurationChange(duration);
|
|
204
|
+
}
|
|
205
|
+
}, [duration, customOnDurationChange]);
|
|
206
|
+
var onVolumeChange = React.useCallback(function () {
|
|
207
|
+
var _ref$current = _ref9.current,
|
|
208
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
222
209
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
210
|
+
if (element === null) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (customOnVolumeChange !== null) {
|
|
215
|
+
customOnVolumeChange(element.volume);
|
|
228
216
|
}
|
|
229
|
-
}, [
|
|
217
|
+
}, [customOnVolumeChange]); // Ensure load if preload value change over time
|
|
230
218
|
|
|
231
219
|
var firstPreloadRef = React.useRef(preload);
|
|
232
220
|
var firstShouldLoadRef = React.useRef(shouldLoad);
|
|
233
221
|
var hasLoadedRef = React.useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
234
222
|
React.useEffect(function () {
|
|
235
|
-
var _ref$
|
|
236
|
-
|
|
223
|
+
var _ref$current2 = _ref9.current,
|
|
224
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
237
225
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
238
226
|
|
|
239
227
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
240
228
|
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
241
229
|
|
|
242
|
-
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current &&
|
|
230
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
243
231
|
hasLoadedRef.current = true;
|
|
244
|
-
|
|
232
|
+
element.load();
|
|
245
233
|
}
|
|
246
234
|
}, [shouldLoad, preload]);
|
|
235
|
+
React.useEffect(function () {
|
|
236
|
+
if (ready && onReady !== null) {
|
|
237
|
+
onReady();
|
|
238
|
+
}
|
|
239
|
+
}, [ready, onReady]);
|
|
240
|
+
React.useEffect(function () {
|
|
241
|
+
var _ref$current3 = _ref9.current,
|
|
242
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
243
|
+
|
|
244
|
+
if (element === null) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var isPaused = element.paused;
|
|
249
|
+
|
|
250
|
+
if (paused && !isPaused) {
|
|
251
|
+
element.pause();
|
|
252
|
+
} else if (!paused && isPaused) {
|
|
253
|
+
element.play();
|
|
254
|
+
}
|
|
255
|
+
}, [paused]);
|
|
256
|
+
hooks.useProgressSteps({
|
|
257
|
+
currentTime: currentTime,
|
|
258
|
+
duration: duration,
|
|
259
|
+
disabled: paused,
|
|
260
|
+
onStep: onProgressStep
|
|
261
|
+
});
|
|
247
262
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
248
263
|
className: classNames__default["default"]([styles.container, (_ref7 = {}, _defineProperty__default["default"](_ref7, className, className !== null), _defineProperty__default["default"](_ref7, styles.withSize, withSize), _ref7)]),
|
|
249
264
|
style: withSize ? {
|
|
@@ -256,17 +271,33 @@ var Video = function Video(_ref) {
|
|
|
256
271
|
className: styles.video
|
|
257
272
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React__default["default"].createElement("video", {
|
|
258
273
|
key: mediaUrl,
|
|
259
|
-
ref: ref
|
|
274
|
+
ref: function ref(newRef) {
|
|
275
|
+
_ref9.current = newRef;
|
|
276
|
+
|
|
277
|
+
if (mediaRef !== null && isFunction__default["default"](mediaRef)) {
|
|
278
|
+
mediaRef(newRef);
|
|
279
|
+
} else if (mediaRef !== null) {
|
|
280
|
+
mediaRef.current = newRef;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
260
283
|
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
261
|
-
autoPlay: autoPlay,
|
|
284
|
+
autoPlay: autoPlay && !paused,
|
|
262
285
|
loop: loop,
|
|
263
286
|
muted: muted,
|
|
264
|
-
poster: shouldLoad && withPoster ?
|
|
287
|
+
poster: shouldLoad && withPoster && finalThumbnail !== null ? finalThumbnail.url || null : null,
|
|
265
288
|
preload: shouldLoad ? preload : 'none',
|
|
266
289
|
playsInline: playsInline,
|
|
267
290
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
268
291
|
tabIndex: focusable ? '0' : '-1',
|
|
269
|
-
className: classNames__default["default"](styles.video)
|
|
292
|
+
className: classNames__default["default"](styles.video),
|
|
293
|
+
onPlay: onPlay,
|
|
294
|
+
onPause: onPause,
|
|
295
|
+
onEnded: onEnded,
|
|
296
|
+
onSeeked: onSeeked,
|
|
297
|
+
onVolumeChange: onVolumeChange,
|
|
298
|
+
onTimeUpdate: onTimeUpdate,
|
|
299
|
+
onSuspend: onSuspend,
|
|
300
|
+
"data-has-audio": hasAudio
|
|
270
301
|
}, (sourceFiles || []).map(function (_ref8) {
|
|
271
302
|
var sourceUrl = _ref8.url,
|
|
272
303
|
sourceMime = _ref8.mime;
|
|
@@ -282,7 +313,7 @@ Video.propTypes = propTypes;
|
|
|
282
313
|
Video.defaultProps = defaultProps;
|
|
283
314
|
var Video$1 = /*#__PURE__*/React__default["default"].forwardRef(function (props, ref) {
|
|
284
315
|
return /*#__PURE__*/React__default["default"].createElement(Video, Object.assign({
|
|
285
|
-
|
|
316
|
+
mediaRef: ref
|
|
286
317
|
}, props));
|
|
287
318
|
});
|
|
288
319
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.156",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -52,10 +52,11 @@
|
|
|
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.156",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.156",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.156",
|
|
58
58
|
"classnames": "^2.2.6",
|
|
59
|
+
"lodash": "^4.17.21",
|
|
59
60
|
"prop-types": "^15.7.2",
|
|
60
61
|
"react-intl": "^5.12.1",
|
|
61
62
|
"uuid": "^8.3.2"
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"publishConfig": {
|
|
64
65
|
"access": "public"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "026d0eb445367f824d3d07a04a0fa90cc00d49f2"
|
|
67
68
|
}
|