@micromag/element-video 0.3.148 → 0.3.153
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 +107 -79
- package/lib/index.js +106 -78
- 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;
|
|
@@ -122,7 +120,24 @@ var Video = function Video(_ref) {
|
|
|
122
120
|
var filesArray = useMemo(function () {
|
|
123
121
|
return getMediaFilesAsArray(files);
|
|
124
122
|
}, [files]);
|
|
125
|
-
var
|
|
123
|
+
var finalThumbnail = useMediaThumbnail(media, thumbnail);
|
|
124
|
+
|
|
125
|
+
var _ref9 = useRef(null);
|
|
126
|
+
|
|
127
|
+
var currentTime = useMediaCurrentTime(_ref9.current, {
|
|
128
|
+
id: mediaUrl,
|
|
129
|
+
disabled: paused || onProgressStep === null
|
|
130
|
+
});
|
|
131
|
+
var duration = useMediaDuration(_ref9.current, {
|
|
132
|
+
id: mediaUrl
|
|
133
|
+
});
|
|
134
|
+
var ready = useMediaReady(_ref9.current, {
|
|
135
|
+
id: mediaUrl
|
|
136
|
+
});
|
|
137
|
+
useMediaLoad(_ref9.current, {
|
|
138
|
+
preload: preload,
|
|
139
|
+
shouldLoad: shouldLoad
|
|
140
|
+
}); // Get source files with supported mimes
|
|
126
141
|
|
|
127
142
|
var sourceFiles = useMemo(function () {
|
|
128
143
|
if (filesArray.length === 0) {
|
|
@@ -169,70 +184,68 @@ var Video = function Video(_ref) {
|
|
|
169
184
|
|
|
170
185
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
171
186
|
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
187
|
var withSize = width !== null && height !== null;
|
|
208
188
|
useEffect(function () {
|
|
209
|
-
if (
|
|
210
|
-
|
|
189
|
+
if (duration > 0 && customOnDurationChange !== null) {
|
|
190
|
+
customOnDurationChange(duration);
|
|
191
|
+
}
|
|
192
|
+
}, [duration, customOnDurationChange]);
|
|
193
|
+
var onVolumeChange = useCallback(function () {
|
|
194
|
+
var _ref$current = _ref9.current,
|
|
195
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
211
196
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
197
|
+
if (element === null) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (customOnVolumeChange !== null) {
|
|
202
|
+
customOnVolumeChange(element.volume);
|
|
217
203
|
}
|
|
218
|
-
}, [
|
|
204
|
+
}, [customOnVolumeChange]); // Ensure load if preload value change over time
|
|
219
205
|
|
|
220
206
|
var firstPreloadRef = useRef(preload);
|
|
221
207
|
var firstShouldLoadRef = useRef(shouldLoad);
|
|
222
208
|
var hasLoadedRef = useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
223
209
|
useEffect(function () {
|
|
224
|
-
var _ref$
|
|
225
|
-
|
|
210
|
+
var _ref$current2 = _ref9.current,
|
|
211
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
226
212
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
227
213
|
|
|
228
214
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
229
215
|
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
230
216
|
|
|
231
|
-
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current &&
|
|
217
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
232
218
|
hasLoadedRef.current = true;
|
|
233
|
-
|
|
219
|
+
element.load();
|
|
234
220
|
}
|
|
235
221
|
}, [shouldLoad, preload]);
|
|
222
|
+
useEffect(function () {
|
|
223
|
+
if (ready && onReady !== null) {
|
|
224
|
+
onReady();
|
|
225
|
+
}
|
|
226
|
+
}, [ready, onReady]);
|
|
227
|
+
useEffect(function () {
|
|
228
|
+
var _ref$current3 = _ref9.current,
|
|
229
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
230
|
+
|
|
231
|
+
if (element === null) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
var isPaused = element.paused;
|
|
236
|
+
|
|
237
|
+
if (paused && !isPaused) {
|
|
238
|
+
element.pause();
|
|
239
|
+
} else if (!paused && isPaused) {
|
|
240
|
+
element.play();
|
|
241
|
+
}
|
|
242
|
+
}, [paused]);
|
|
243
|
+
useProgressSteps({
|
|
244
|
+
currentTime: currentTime,
|
|
245
|
+
duration: duration,
|
|
246
|
+
disabled: paused,
|
|
247
|
+
onStep: onProgressStep
|
|
248
|
+
});
|
|
236
249
|
return /*#__PURE__*/React.createElement("div", {
|
|
237
250
|
className: classNames([styles.container, (_ref7 = {}, _defineProperty(_ref7, className, className !== null), _defineProperty(_ref7, styles.withSize, withSize), _ref7)]),
|
|
238
251
|
style: withSize ? {
|
|
@@ -245,17 +258,32 @@ var Video = function Video(_ref) {
|
|
|
245
258
|
className: styles.video
|
|
246
259
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
247
260
|
key: mediaUrl,
|
|
248
|
-
ref: ref
|
|
261
|
+
ref: function ref(newRef) {
|
|
262
|
+
_ref9.current = newRef;
|
|
263
|
+
|
|
264
|
+
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
265
|
+
mediaRef(newRef);
|
|
266
|
+
} else if (mediaRef !== null) {
|
|
267
|
+
mediaRef.current = newRef;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
249
270
|
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
250
|
-
autoPlay: autoPlay,
|
|
271
|
+
autoPlay: autoPlay && !paused,
|
|
251
272
|
loop: loop,
|
|
252
273
|
muted: muted,
|
|
253
|
-
poster: shouldLoad && withPoster ?
|
|
274
|
+
poster: shouldLoad && withPoster && finalThumbnail !== null ? finalThumbnail.url || null : null,
|
|
254
275
|
preload: shouldLoad ? preload : 'none',
|
|
255
276
|
playsInline: playsInline,
|
|
256
277
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
257
278
|
tabIndex: focusable ? '0' : '-1',
|
|
258
|
-
className: classNames(styles.video)
|
|
279
|
+
className: classNames(styles.video),
|
|
280
|
+
onPlay: onPlay,
|
|
281
|
+
onPause: onPause,
|
|
282
|
+
onEnded: onEnded,
|
|
283
|
+
onSeeked: onSeeked,
|
|
284
|
+
onVolumeChange: onVolumeChange,
|
|
285
|
+
onTimeUpdate: onTimeUpdate,
|
|
286
|
+
onSuspend: onSuspend
|
|
259
287
|
}, (sourceFiles || []).map(function (_ref8) {
|
|
260
288
|
var sourceUrl = _ref8.url,
|
|
261
289
|
sourceMime = _ref8.mime;
|
|
@@ -271,7 +299,7 @@ Video.propTypes = propTypes;
|
|
|
271
299
|
Video.defaultProps = defaultProps;
|
|
272
300
|
var Video$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
273
301
|
return /*#__PURE__*/React.createElement(Video, Object.assign({
|
|
274
|
-
|
|
302
|
+
mediaRef: ref
|
|
275
303
|
}, props));
|
|
276
304
|
});
|
|
277
305
|
|
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;
|
|
@@ -133,7 +131,24 @@ var Video = function Video(_ref) {
|
|
|
133
131
|
var filesArray = React.useMemo(function () {
|
|
134
132
|
return utils.getMediaFilesAsArray(files);
|
|
135
133
|
}, [files]);
|
|
136
|
-
var
|
|
134
|
+
var finalThumbnail = hooks.useMediaThumbnail(media, thumbnail);
|
|
135
|
+
|
|
136
|
+
var _ref9 = React.useRef(null);
|
|
137
|
+
|
|
138
|
+
var currentTime = hooks.useMediaCurrentTime(_ref9.current, {
|
|
139
|
+
id: mediaUrl,
|
|
140
|
+
disabled: paused || onProgressStep === null
|
|
141
|
+
});
|
|
142
|
+
var duration = hooks.useMediaDuration(_ref9.current, {
|
|
143
|
+
id: mediaUrl
|
|
144
|
+
});
|
|
145
|
+
var ready = hooks.useMediaReady(_ref9.current, {
|
|
146
|
+
id: mediaUrl
|
|
147
|
+
});
|
|
148
|
+
hooks.useMediaLoad(_ref9.current, {
|
|
149
|
+
preload: preload,
|
|
150
|
+
shouldLoad: shouldLoad
|
|
151
|
+
}); // Get source files with supported mimes
|
|
137
152
|
|
|
138
153
|
var sourceFiles = React.useMemo(function () {
|
|
139
154
|
if (filesArray.length === 0) {
|
|
@@ -180,70 +195,68 @@ var Video = function Video(_ref) {
|
|
|
180
195
|
|
|
181
196
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
182
197
|
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
198
|
var withSize = width !== null && height !== null;
|
|
219
199
|
React.useEffect(function () {
|
|
220
|
-
if (
|
|
221
|
-
|
|
200
|
+
if (duration > 0 && customOnDurationChange !== null) {
|
|
201
|
+
customOnDurationChange(duration);
|
|
202
|
+
}
|
|
203
|
+
}, [duration, customOnDurationChange]);
|
|
204
|
+
var onVolumeChange = React.useCallback(function () {
|
|
205
|
+
var _ref$current = _ref9.current,
|
|
206
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
222
207
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
208
|
+
if (element === null) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (customOnVolumeChange !== null) {
|
|
213
|
+
customOnVolumeChange(element.volume);
|
|
228
214
|
}
|
|
229
|
-
}, [
|
|
215
|
+
}, [customOnVolumeChange]); // Ensure load if preload value change over time
|
|
230
216
|
|
|
231
217
|
var firstPreloadRef = React.useRef(preload);
|
|
232
218
|
var firstShouldLoadRef = React.useRef(shouldLoad);
|
|
233
219
|
var hasLoadedRef = React.useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
234
220
|
React.useEffect(function () {
|
|
235
|
-
var _ref$
|
|
236
|
-
|
|
221
|
+
var _ref$current2 = _ref9.current,
|
|
222
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
237
223
|
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad; // @todo
|
|
238
224
|
|
|
239
225
|
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
240
226
|
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
241
227
|
|
|
242
|
-
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current &&
|
|
228
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
243
229
|
hasLoadedRef.current = true;
|
|
244
|
-
|
|
230
|
+
element.load();
|
|
245
231
|
}
|
|
246
232
|
}, [shouldLoad, preload]);
|
|
233
|
+
React.useEffect(function () {
|
|
234
|
+
if (ready && onReady !== null) {
|
|
235
|
+
onReady();
|
|
236
|
+
}
|
|
237
|
+
}, [ready, onReady]);
|
|
238
|
+
React.useEffect(function () {
|
|
239
|
+
var _ref$current3 = _ref9.current,
|
|
240
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
241
|
+
|
|
242
|
+
if (element === null) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
var isPaused = element.paused;
|
|
247
|
+
|
|
248
|
+
if (paused && !isPaused) {
|
|
249
|
+
element.pause();
|
|
250
|
+
} else if (!paused && isPaused) {
|
|
251
|
+
element.play();
|
|
252
|
+
}
|
|
253
|
+
}, [paused]);
|
|
254
|
+
hooks.useProgressSteps({
|
|
255
|
+
currentTime: currentTime,
|
|
256
|
+
duration: duration,
|
|
257
|
+
disabled: paused,
|
|
258
|
+
onStep: onProgressStep
|
|
259
|
+
});
|
|
247
260
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
248
261
|
className: classNames__default["default"]([styles.container, (_ref7 = {}, _defineProperty__default["default"](_ref7, className, className !== null), _defineProperty__default["default"](_ref7, styles.withSize, withSize), _ref7)]),
|
|
249
262
|
style: withSize ? {
|
|
@@ -256,17 +269,32 @@ var Video = function Video(_ref) {
|
|
|
256
269
|
className: styles.video
|
|
257
270
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React__default["default"].createElement("video", {
|
|
258
271
|
key: mediaUrl,
|
|
259
|
-
ref: ref
|
|
272
|
+
ref: function ref(newRef) {
|
|
273
|
+
_ref9.current = newRef;
|
|
274
|
+
|
|
275
|
+
if (mediaRef !== null && isFunction__default["default"](mediaRef)) {
|
|
276
|
+
mediaRef(newRef);
|
|
277
|
+
} else if (mediaRef !== null) {
|
|
278
|
+
mediaRef.current = newRef;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
260
281
|
src: sourceFiles === null || sourceFiles.length === 0 ? mediaUrl : null,
|
|
261
|
-
autoPlay: autoPlay,
|
|
282
|
+
autoPlay: autoPlay && !paused,
|
|
262
283
|
loop: loop,
|
|
263
284
|
muted: muted,
|
|
264
|
-
poster: shouldLoad && withPoster ?
|
|
285
|
+
poster: shouldLoad && withPoster && finalThumbnail !== null ? finalThumbnail.url || null : null,
|
|
265
286
|
preload: shouldLoad ? preload : 'none',
|
|
266
287
|
playsInline: playsInline,
|
|
267
288
|
crossOrigin: withoutCors ? 'anonymous' : null,
|
|
268
289
|
tabIndex: focusable ? '0' : '-1',
|
|
269
|
-
className: classNames__default["default"](styles.video)
|
|
290
|
+
className: classNames__default["default"](styles.video),
|
|
291
|
+
onPlay: onPlay,
|
|
292
|
+
onPause: onPause,
|
|
293
|
+
onEnded: onEnded,
|
|
294
|
+
onSeeked: onSeeked,
|
|
295
|
+
onVolumeChange: onVolumeChange,
|
|
296
|
+
onTimeUpdate: onTimeUpdate,
|
|
297
|
+
onSuspend: onSuspend
|
|
270
298
|
}, (sourceFiles || []).map(function (_ref8) {
|
|
271
299
|
var sourceUrl = _ref8.url,
|
|
272
300
|
sourceMime = _ref8.mime;
|
|
@@ -282,7 +310,7 @@ Video.propTypes = propTypes;
|
|
|
282
310
|
Video.defaultProps = defaultProps;
|
|
283
311
|
var Video$1 = /*#__PURE__*/React__default["default"].forwardRef(function (props, ref) {
|
|
284
312
|
return /*#__PURE__*/React__default["default"].createElement(Video, Object.assign({
|
|
285
|
-
|
|
313
|
+
mediaRef: ref
|
|
286
314
|
}, props));
|
|
287
315
|
});
|
|
288
316
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.153",
|
|
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.153",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.153",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.153",
|
|
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": "3832de24bc306639b162f9778b3250ce1d05b2aa"
|
|
67
68
|
}
|