@folklore/hooks 0.0.27 → 0.0.29
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/dist/cjs.js +923 -840
- package/dist/es.js +922 -838
- package/package.json +4 -2
package/dist/cjs.js
CHANGED
|
@@ -2,52 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
5
|
var raf = require('raf');
|
|
7
6
|
var react = require('react');
|
|
8
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
9
7
|
var services = require('@folklore/services');
|
|
10
8
|
var createDebug = require('debug');
|
|
11
9
|
var EventsManager = require('@folklore/events');
|
|
12
|
-
var
|
|
10
|
+
var cancelablePromise = require('cancelable-promise');
|
|
11
|
+
var isNumber = require('lodash/isNumber');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
14
|
|
|
16
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
17
15
|
var raf__default = /*#__PURE__*/_interopDefaultLegacy(raf);
|
|
18
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
19
16
|
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
20
17
|
var EventsManager__default = /*#__PURE__*/_interopDefaultLegacy(EventsManager);
|
|
21
|
-
var
|
|
18
|
+
var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
|
|
22
19
|
|
|
23
20
|
function useCounter(desiredValue, _ref) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var startTime = null;
|
|
37
|
-
var duration = 0;
|
|
38
|
-
var canceled = false;
|
|
39
|
-
var startValue = currentValue;
|
|
40
|
-
var delta = desiredValue - startValue;
|
|
21
|
+
let {
|
|
22
|
+
maxDuration = 2000,
|
|
23
|
+
speed = 1 / 10
|
|
24
|
+
} = _ref;
|
|
25
|
+
const [currentValue, setCurrentValue] = react.useState(desiredValue);
|
|
26
|
+
react.useEffect(() => {
|
|
27
|
+
let animationFrame = null;
|
|
28
|
+
let startTime = null;
|
|
29
|
+
let duration = 0;
|
|
30
|
+
let canceled = false;
|
|
31
|
+
const startValue = currentValue;
|
|
32
|
+
const delta = desiredValue - startValue;
|
|
41
33
|
|
|
42
34
|
function loop() {
|
|
43
35
|
if (canceled) {
|
|
44
36
|
return;
|
|
45
37
|
}
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
const currentTime = Date.now();
|
|
40
|
+
const elapsedTime = currentTime - startTime;
|
|
41
|
+
const progress = Math.min(elapsedTime / duration, 1);
|
|
42
|
+
const newValue = Math.round(startValue + progress * delta);
|
|
51
43
|
setCurrentValue(newValue);
|
|
52
44
|
|
|
53
45
|
if (newValue !== desiredValue) {
|
|
@@ -61,7 +53,7 @@ function useCounter(desiredValue, _ref) {
|
|
|
61
53
|
animationFrame = raf__default["default"](loop);
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
return
|
|
56
|
+
return () => {
|
|
65
57
|
canceled = true;
|
|
66
58
|
|
|
67
59
|
if (animationFrame !== null) {
|
|
@@ -73,28 +65,17 @@ function useCounter(desiredValue, _ref) {
|
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
function usePlayerCurrentTime(player) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return p.currentTime;
|
|
88
|
-
} : _ref$getCurrentTime;
|
|
89
|
-
|
|
90
|
-
var _useState = react.useState(0),
|
|
91
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
92
|
-
currentTime = _useState2[0],
|
|
93
|
-
setCurrentTime = _useState2[1];
|
|
94
|
-
|
|
95
|
-
var realCurrentTime = react.useRef(currentTime);
|
|
96
|
-
var lastIdRef = react.useRef(id);
|
|
97
|
-
var idChanged = lastIdRef.current !== id;
|
|
68
|
+
let {
|
|
69
|
+
id = null,
|
|
70
|
+
disabled = false,
|
|
71
|
+
updateInterval = 1000,
|
|
72
|
+
onUpdate: customOnUpdate = null,
|
|
73
|
+
getCurrentTime = p => p.currentTime
|
|
74
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
75
|
+
const [currentTime, setCurrentTime] = react.useState(0);
|
|
76
|
+
const realCurrentTime = react.useRef(currentTime);
|
|
77
|
+
const lastIdRef = react.useRef(id);
|
|
78
|
+
const idChanged = lastIdRef.current !== id;
|
|
98
79
|
|
|
99
80
|
if (idChanged) {
|
|
100
81
|
realCurrentTime.current = 0;
|
|
@@ -102,14 +83,14 @@ function usePlayerCurrentTime(player) {
|
|
|
102
83
|
} // Check time update
|
|
103
84
|
|
|
104
85
|
|
|
105
|
-
react.useEffect(
|
|
86
|
+
react.useEffect(() => {
|
|
106
87
|
if (disabled || player === null) {
|
|
107
|
-
return
|
|
88
|
+
return () => {};
|
|
108
89
|
}
|
|
109
90
|
|
|
110
|
-
|
|
91
|
+
let canceled = false;
|
|
111
92
|
|
|
112
|
-
|
|
93
|
+
const updateTime = time => {
|
|
113
94
|
if (canceled) {
|
|
114
95
|
return;
|
|
115
96
|
}
|
|
@@ -122,8 +103,8 @@ function usePlayerCurrentTime(player) {
|
|
|
122
103
|
}
|
|
123
104
|
};
|
|
124
105
|
|
|
125
|
-
|
|
126
|
-
|
|
106
|
+
const interval = setInterval(() => {
|
|
107
|
+
const time = getCurrentTime(player);
|
|
127
108
|
|
|
128
109
|
if (typeof time.then !== 'undefined') {
|
|
129
110
|
time.then(updateTime);
|
|
@@ -131,7 +112,7 @@ function usePlayerCurrentTime(player) {
|
|
|
131
112
|
updateTime(time);
|
|
132
113
|
}
|
|
133
114
|
}, updateInterval);
|
|
134
|
-
return
|
|
115
|
+
return () => {
|
|
135
116
|
canceled = true;
|
|
136
117
|
clearInterval(interval);
|
|
137
118
|
};
|
|
@@ -139,115 +120,67 @@ function usePlayerCurrentTime(player) {
|
|
|
139
120
|
return realCurrentTime.current;
|
|
140
121
|
}
|
|
141
122
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var match = url.match(/\/video\/([^/?]+)/);
|
|
186
|
-
return match !== null ? match[1] : null;
|
|
187
|
-
} : _params$getVideoId;
|
|
188
|
-
|
|
189
|
-
var _useState = react.useState(typeof window.DM !== 'undefined'),
|
|
190
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
191
|
-
apiLoaded = _useState2[0],
|
|
192
|
-
setApiLoaded = _useState2[1];
|
|
193
|
-
|
|
194
|
-
var _useState3 = react.useState(false),
|
|
195
|
-
_useState4 = _slicedToArray__default["default"](_useState3, 2),
|
|
196
|
-
playerReady = _useState4[0],
|
|
197
|
-
setPlayerReady = _useState4[1];
|
|
198
|
-
|
|
199
|
-
var _useState5 = react.useState(false),
|
|
200
|
-
_useState6 = _slicedToArray__default["default"](_useState5, 2),
|
|
201
|
-
loaded = _useState6[0],
|
|
202
|
-
setLoaded = _useState6[1];
|
|
203
|
-
|
|
204
|
-
var apiRef = react.useRef(typeof window.DM !== 'undefined' ? window.DM : null);
|
|
205
|
-
var ready = apiLoaded && playerReady;
|
|
206
|
-
var videoId = react.useMemo(function () {
|
|
207
|
-
return getVideoId(id);
|
|
208
|
-
}, [id]);
|
|
209
|
-
var elementRef = react.useRef(null);
|
|
210
|
-
var playerRef = react.useRef(null);
|
|
211
|
-
var playerElementRef = react.useRef(elementRef.current);
|
|
212
|
-
var elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
213
|
-
|
|
214
|
-
var _useState7 = react.useState(initialMuted),
|
|
215
|
-
_useState8 = _slicedToArray__default["default"](_useState7, 2),
|
|
216
|
-
muted = _useState8[0],
|
|
217
|
-
setMuted = _useState8[1];
|
|
218
|
-
|
|
219
|
-
var _useState9 = react.useState(initialMuted ? 0 : 1),
|
|
220
|
-
_useState10 = _slicedToArray__default["default"](_useState9, 2),
|
|
221
|
-
volume = _useState10[0],
|
|
222
|
-
setVolumeState = _useState10[1];
|
|
223
|
-
|
|
224
|
-
var _useState11 = react.useState({
|
|
123
|
+
const noPlayerError$1 = new Error('No player');
|
|
124
|
+
const debug$3 = createDebug__default["default"]('folklore:video:dailymotion');
|
|
125
|
+
|
|
126
|
+
const useDailymotionPlayer = function () {
|
|
127
|
+
let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
128
|
+
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
129
|
+
const {
|
|
130
|
+
width = 0,
|
|
131
|
+
height = 0,
|
|
132
|
+
duration = 0,
|
|
133
|
+
autoplay = false,
|
|
134
|
+
muted: initialMuted = false,
|
|
135
|
+
start = 0,
|
|
136
|
+
controls = true,
|
|
137
|
+
queueAutoplayNext = false,
|
|
138
|
+
queueEnable = false,
|
|
139
|
+
sharingEnable = false,
|
|
140
|
+
uiLogo = false,
|
|
141
|
+
uiStartScreenInfo = true,
|
|
142
|
+
timeUpdateInterval = 1000,
|
|
143
|
+
onTimeUpdate: customOnTimeUpdate = null,
|
|
144
|
+
getVideoId = url => {
|
|
145
|
+
if (url === null || url.match(/^https?:/) === null) {
|
|
146
|
+
return url;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const match = url.match(/\/video\/([^/?]+)/);
|
|
150
|
+
return match !== null ? match[1] : null;
|
|
151
|
+
}
|
|
152
|
+
} = params;
|
|
153
|
+
const [apiLoaded, setApiLoaded] = react.useState(typeof window.DM !== 'undefined');
|
|
154
|
+
const [playerReady, setPlayerReady] = react.useState(false);
|
|
155
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
156
|
+
const apiRef = react.useRef(typeof window.DM !== 'undefined' ? window.DM : null);
|
|
157
|
+
const ready = apiLoaded && playerReady;
|
|
158
|
+
const videoId = react.useMemo(() => getVideoId(id), [id]);
|
|
159
|
+
const elementRef = react.useRef(null);
|
|
160
|
+
const playerRef = react.useRef(null);
|
|
161
|
+
const playerElementRef = react.useRef(elementRef.current);
|
|
162
|
+
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
163
|
+
const [muted, setMuted] = react.useState(initialMuted);
|
|
164
|
+
const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
|
|
165
|
+
const [playState, setPlayState] = react.useState({
|
|
225
166
|
playing: false,
|
|
226
167
|
paused: false,
|
|
227
168
|
ended: false,
|
|
228
169
|
buffering: false,
|
|
229
170
|
adPlaying: false
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
width: width,
|
|
237
|
-
height: height,
|
|
238
|
-
duration: duration
|
|
239
|
-
}),
|
|
240
|
-
_useState14 = _slicedToArray__default["default"](_useState13, 2),
|
|
241
|
-
metadata = _useState14[0],
|
|
242
|
-
setMetadata = _useState14[1]; // Load SDK
|
|
243
|
-
|
|
171
|
+
});
|
|
172
|
+
const [metadata, setMetadata] = react.useState({
|
|
173
|
+
width,
|
|
174
|
+
height,
|
|
175
|
+
duration
|
|
176
|
+
}); // Load SDK
|
|
244
177
|
|
|
245
|
-
react.useEffect(
|
|
246
|
-
|
|
178
|
+
react.useEffect(() => {
|
|
179
|
+
let canceled = false;
|
|
247
180
|
|
|
248
181
|
if (!apiLoaded && videoId !== null) {
|
|
249
182
|
debug$3('Load API');
|
|
250
|
-
services.loadDailymotion().then(
|
|
183
|
+
services.loadDailymotion().then(api => {
|
|
251
184
|
if (!canceled) {
|
|
252
185
|
apiRef.current = api;
|
|
253
186
|
setApiLoaded(true);
|
|
@@ -256,35 +189,38 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
256
189
|
});
|
|
257
190
|
}
|
|
258
191
|
|
|
259
|
-
return
|
|
192
|
+
return () => {
|
|
260
193
|
canceled = true;
|
|
261
194
|
};
|
|
262
195
|
}, [videoId, apiLoaded, setApiLoaded]); // Create or update player
|
|
263
196
|
|
|
264
|
-
react.useEffect(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
197
|
+
react.useEffect(() => {
|
|
198
|
+
const {
|
|
199
|
+
current: DM = null
|
|
200
|
+
} = apiRef;
|
|
201
|
+
const {
|
|
202
|
+
current: currentPlayer = null
|
|
203
|
+
} = playerRef;
|
|
204
|
+
const {
|
|
205
|
+
current: element = null
|
|
206
|
+
} = elementRef;
|
|
271
207
|
|
|
272
208
|
if (!apiLoaded || videoId === null || element === null) {
|
|
273
209
|
return;
|
|
274
210
|
}
|
|
275
211
|
|
|
276
|
-
|
|
212
|
+
const playerParams = {
|
|
277
213
|
'autoplay-d': autoplay,
|
|
278
214
|
// muted,
|
|
279
|
-
start
|
|
280
|
-
controls
|
|
215
|
+
start,
|
|
216
|
+
controls,
|
|
281
217
|
'queue-autoplay-next': queueAutoplayNext,
|
|
282
218
|
'queue-enable': queueEnable,
|
|
283
219
|
'sharing-enable': sharingEnable,
|
|
284
220
|
'ui-logo': uiLogo,
|
|
285
221
|
'ui-start-screen-info': uiStartScreenInfo
|
|
286
222
|
};
|
|
287
|
-
|
|
223
|
+
let player = currentPlayer;
|
|
288
224
|
|
|
289
225
|
if (player !== null) {
|
|
290
226
|
player.load(videoId, {
|
|
@@ -294,8 +230,8 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
294
230
|
} else {
|
|
295
231
|
player = DM.player(element, {
|
|
296
232
|
video: videoId,
|
|
297
|
-
width
|
|
298
|
-
height
|
|
233
|
+
width,
|
|
234
|
+
height,
|
|
299
235
|
params: playerParams
|
|
300
236
|
});
|
|
301
237
|
debug$3('Create player [ID: %s]', videoId);
|
|
@@ -308,16 +244,17 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
308
244
|
playerRef.current = player;
|
|
309
245
|
playerElementRef.current = element;
|
|
310
246
|
}, [apiLoaded, elementHasChanged, videoId, width, height, autoplay, muted, start, controls, queueAutoplayNext, queueEnable, sharingEnable, uiLogo, uiStartScreenInfo]);
|
|
311
|
-
react.useEffect(
|
|
312
|
-
|
|
313
|
-
|
|
247
|
+
react.useEffect(() => {
|
|
248
|
+
const {
|
|
249
|
+
current: player = null
|
|
250
|
+
} = playerRef;
|
|
314
251
|
|
|
315
252
|
if (player === null) {
|
|
316
|
-
return
|
|
253
|
+
return () => {};
|
|
317
254
|
}
|
|
318
255
|
|
|
319
|
-
|
|
320
|
-
|
|
256
|
+
let currentPlayState = playState;
|
|
257
|
+
let currentMetadata = metadata;
|
|
321
258
|
|
|
322
259
|
function onPlaybackReady() {
|
|
323
260
|
setLoaded(true);
|
|
@@ -325,17 +262,17 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
325
262
|
}
|
|
326
263
|
|
|
327
264
|
function onLoadedMetadata() {
|
|
328
|
-
currentMetadata =
|
|
265
|
+
currentMetadata = { ...currentMetadata,
|
|
329
266
|
duration: player.duration
|
|
330
|
-
}
|
|
267
|
+
};
|
|
331
268
|
setMetadata(currentMetadata);
|
|
332
269
|
debug$3('onLoadedMetadata [ID: %s]', videoId);
|
|
333
270
|
}
|
|
334
271
|
|
|
335
272
|
function onDurationChange() {
|
|
336
|
-
currentMetadata =
|
|
273
|
+
currentMetadata = { ...currentMetadata,
|
|
337
274
|
duration: player.duration
|
|
338
|
-
}
|
|
275
|
+
};
|
|
339
276
|
setMetadata(currentMetadata);
|
|
340
277
|
debug$3('onDurationChange [ID: %s]', videoId);
|
|
341
278
|
}
|
|
@@ -347,63 +284,63 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
347
284
|
}
|
|
348
285
|
|
|
349
286
|
function onPlay() {
|
|
350
|
-
currentPlayState =
|
|
287
|
+
currentPlayState = { ...currentPlayState,
|
|
351
288
|
playing: true,
|
|
352
289
|
paused: false,
|
|
353
290
|
ended: false
|
|
354
|
-
}
|
|
291
|
+
};
|
|
355
292
|
setPlayState(currentPlayState);
|
|
356
293
|
debug$3('onPlay [ID: %s]', videoId);
|
|
357
294
|
}
|
|
358
295
|
|
|
359
296
|
function onPause() {
|
|
360
|
-
currentPlayState =
|
|
297
|
+
currentPlayState = { ...currentPlayState,
|
|
361
298
|
playing: false,
|
|
362
299
|
paused: true,
|
|
363
300
|
ended: false
|
|
364
|
-
}
|
|
301
|
+
};
|
|
365
302
|
setPlayState(currentPlayState);
|
|
366
303
|
debug$3('onPause [ID: %s]', videoId);
|
|
367
304
|
}
|
|
368
305
|
|
|
369
306
|
function onEnd() {
|
|
370
|
-
currentPlayState =
|
|
307
|
+
currentPlayState = { ...currentPlayState,
|
|
371
308
|
playing: false,
|
|
372
309
|
paused: false,
|
|
373
310
|
ended: true
|
|
374
|
-
}
|
|
311
|
+
};
|
|
375
312
|
setPlayState(currentPlayState);
|
|
376
313
|
debug$3('onEnd [ID: %s]', videoId);
|
|
377
314
|
}
|
|
378
315
|
|
|
379
316
|
function onPlaying() {
|
|
380
|
-
currentPlayState =
|
|
317
|
+
currentPlayState = { ...currentPlayState,
|
|
381
318
|
buffering: false
|
|
382
|
-
}
|
|
319
|
+
};
|
|
383
320
|
setPlayState(currentPlayState);
|
|
384
321
|
debug$3('onPlaying [ID: %s]', videoId);
|
|
385
322
|
}
|
|
386
323
|
|
|
387
324
|
function onWaiting() {
|
|
388
|
-
currentPlayState =
|
|
325
|
+
currentPlayState = { ...currentPlayState,
|
|
389
326
|
buffering: true
|
|
390
|
-
}
|
|
327
|
+
};
|
|
391
328
|
setPlayState(currentPlayState);
|
|
392
329
|
debug$3('onWaiting [ID: %s]', videoId);
|
|
393
330
|
}
|
|
394
331
|
|
|
395
332
|
function onAdStart() {
|
|
396
|
-
currentPlayState =
|
|
333
|
+
currentPlayState = { ...currentPlayState,
|
|
397
334
|
adPlaying: true
|
|
398
|
-
}
|
|
335
|
+
};
|
|
399
336
|
setPlayState(currentPlayState);
|
|
400
337
|
debug$3('onAdStart [ID: %s]', videoId);
|
|
401
338
|
}
|
|
402
339
|
|
|
403
340
|
function onAdEnd() {
|
|
404
|
-
currentPlayState =
|
|
341
|
+
currentPlayState = { ...currentPlayState,
|
|
405
342
|
adPlaying: false
|
|
406
|
-
}
|
|
343
|
+
};
|
|
407
344
|
setPlayState(currentPlayState);
|
|
408
345
|
debug$3('onAdEnd [ID: %s]', videoId);
|
|
409
346
|
}
|
|
@@ -419,7 +356,7 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
419
356
|
player.addEventListener('waiting', onWaiting);
|
|
420
357
|
player.addEventListener('ad_start', onAdStart);
|
|
421
358
|
player.addEventListener('ad_end', onAdEnd);
|
|
422
|
-
return
|
|
359
|
+
return () => {
|
|
423
360
|
player.removeEventListener('playback_ready', onPlaybackReady);
|
|
424
361
|
player.removeEventListener('loadedmetadata', onLoadedMetadata);
|
|
425
362
|
player.removeEventListener('durationchange', onDurationChange);
|
|
@@ -433,63 +370,79 @@ var useDailymotionPlayer = function useDailymotionPlayer() {
|
|
|
433
370
|
player.removeEventListener('ad_end', onAdEnd);
|
|
434
371
|
};
|
|
435
372
|
}, [playerRef.current, playerReady, videoId, setLoaded, setPlayState, setMetadata, setVolumeState, setMuted]);
|
|
436
|
-
|
|
437
|
-
|
|
373
|
+
const play = react.useCallback(() => {
|
|
374
|
+
const {
|
|
375
|
+
current: player
|
|
376
|
+
} = playerRef;
|
|
438
377
|
return player !== null ? player.play() : Promise.reject(noPlayerError$1);
|
|
439
378
|
}, []);
|
|
440
|
-
|
|
441
|
-
|
|
379
|
+
const pause = react.useCallback(() => {
|
|
380
|
+
const {
|
|
381
|
+
current: player
|
|
382
|
+
} = playerRef;
|
|
442
383
|
return player !== null ? player.pause() : Promise.reject(noPlayerError$1);
|
|
443
384
|
}, []);
|
|
444
|
-
|
|
445
|
-
|
|
385
|
+
const setVolume = react.useCallback(newVolume => {
|
|
386
|
+
const {
|
|
387
|
+
current: player
|
|
388
|
+
} = playerRef;
|
|
446
389
|
return player !== null ? player.setVolume(newVolume) : Promise.reject(noPlayerError$1);
|
|
447
390
|
}, []);
|
|
448
|
-
|
|
449
|
-
|
|
391
|
+
const mute = react.useCallback(() => {
|
|
392
|
+
const {
|
|
393
|
+
current: player
|
|
394
|
+
} = playerRef;
|
|
450
395
|
return player !== null ? player.setMute(true) : Promise.reject(noPlayerError$1);
|
|
451
396
|
}, []);
|
|
452
|
-
|
|
453
|
-
|
|
397
|
+
const unmute = react.useCallback(() => {
|
|
398
|
+
const {
|
|
399
|
+
current: player
|
|
400
|
+
} = playerRef;
|
|
454
401
|
return player !== null ? player.setMute(false) : Promise.reject(noPlayerError$1);
|
|
455
402
|
}, []);
|
|
456
|
-
|
|
457
|
-
|
|
403
|
+
const seek = react.useCallback(time => {
|
|
404
|
+
const {
|
|
405
|
+
current: player
|
|
406
|
+
} = playerRef;
|
|
458
407
|
return player !== null ? player.seek(time) : Promise.reject(noPlayerError$1);
|
|
459
408
|
}, []);
|
|
460
|
-
|
|
461
|
-
|
|
409
|
+
const {
|
|
410
|
+
playing
|
|
411
|
+
} = playState;
|
|
412
|
+
const currentTime = usePlayerCurrentTime(playerRef.current, {
|
|
462
413
|
id: videoId,
|
|
463
414
|
disabled: !playing || timeUpdateInterval === null,
|
|
464
415
|
updateInterval: timeUpdateInterval,
|
|
465
416
|
onUpdate: customOnTimeUpdate
|
|
466
417
|
});
|
|
467
|
-
return
|
|
418
|
+
return {
|
|
468
419
|
ref: elementRef,
|
|
469
420
|
player: playerRef.current,
|
|
470
|
-
ready
|
|
471
|
-
play
|
|
472
|
-
pause
|
|
473
|
-
mute
|
|
474
|
-
unmute
|
|
475
|
-
setVolume
|
|
476
|
-
seek
|
|
477
|
-
currentTime
|
|
478
|
-
loaded
|
|
479
|
-
muted
|
|
480
|
-
volume
|
|
481
|
-
|
|
421
|
+
ready,
|
|
422
|
+
play,
|
|
423
|
+
pause,
|
|
424
|
+
mute,
|
|
425
|
+
unmute,
|
|
426
|
+
setVolume,
|
|
427
|
+
seek,
|
|
428
|
+
currentTime,
|
|
429
|
+
loaded,
|
|
430
|
+
muted,
|
|
431
|
+
volume,
|
|
432
|
+
...metadata,
|
|
433
|
+
...playState
|
|
434
|
+
};
|
|
482
435
|
};
|
|
483
436
|
|
|
484
|
-
|
|
437
|
+
const eventsManager$1 = typeof document !== 'undefined' ? new EventsManager__default["default"](document) : null;
|
|
485
438
|
|
|
486
|
-
|
|
487
|
-
react.useEffect(
|
|
439
|
+
const useDocumentEvent = (event, callback) => {
|
|
440
|
+
react.useEffect(() => {
|
|
488
441
|
if (eventsManager$1 !== null && callback !== null) {
|
|
489
442
|
eventsManager$1.subscribe(event, callback);
|
|
490
443
|
}
|
|
491
444
|
|
|
492
|
-
return
|
|
445
|
+
return () => {
|
|
493
446
|
if (eventsManager$1 !== null && callback !== null) {
|
|
494
447
|
eventsManager$1.unsubscribe(event, callback);
|
|
495
448
|
}
|
|
@@ -497,15 +450,15 @@ var useDocumentEvent = function useDocumentEvent(event, callback) {
|
|
|
497
450
|
}, [event, callback]);
|
|
498
451
|
};
|
|
499
452
|
|
|
500
|
-
|
|
453
|
+
const eventsManager = typeof window !== 'undefined' ? new EventsManager__default["default"](window) : null;
|
|
501
454
|
|
|
502
|
-
|
|
503
|
-
react.useEffect(
|
|
455
|
+
const useWindowEvent = (event, callback) => {
|
|
456
|
+
react.useEffect(() => {
|
|
504
457
|
if (eventsManager !== null && callback !== null) {
|
|
505
458
|
eventsManager.subscribe(event, callback);
|
|
506
459
|
}
|
|
507
460
|
|
|
508
|
-
return
|
|
461
|
+
return () => {
|
|
509
462
|
if (eventsManager !== null && callback !== null) {
|
|
510
463
|
eventsManager.unsubscribe(event, callback);
|
|
511
464
|
}
|
|
@@ -514,10 +467,12 @@ var useWindowEvent = function useWindowEvent(event, callback) {
|
|
|
514
467
|
};
|
|
515
468
|
|
|
516
469
|
function useKeyboard() {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
470
|
+
let keyMap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
471
|
+
const onKeyDown = react.useCallback(event => {
|
|
472
|
+
const {
|
|
473
|
+
key
|
|
474
|
+
} = event;
|
|
475
|
+
let callback = null;
|
|
521
476
|
|
|
522
477
|
if (typeof keyMap === 'function') {
|
|
523
478
|
callback = keyMap;
|
|
@@ -529,9 +484,11 @@ function useKeyboard() {
|
|
|
529
484
|
callback(event);
|
|
530
485
|
}
|
|
531
486
|
}, [keyMap]);
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
487
|
+
const onKeyUp = react.useCallback(event => {
|
|
488
|
+
const {
|
|
489
|
+
key
|
|
490
|
+
} = event;
|
|
491
|
+
let callback = null;
|
|
535
492
|
|
|
536
493
|
if (typeof keyMap === 'function') {
|
|
537
494
|
callback = keyMap;
|
|
@@ -547,68 +504,274 @@ function useKeyboard() {
|
|
|
547
504
|
useWindowEvent('keyup', keyMap !== null ? onKeyUp : null);
|
|
548
505
|
}
|
|
549
506
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
507
|
+
const useItemsPaginated = function (loader) {
|
|
508
|
+
let {
|
|
509
|
+
page = null,
|
|
510
|
+
count = 10,
|
|
511
|
+
pages: initialPages = null,
|
|
512
|
+
getPageFromResponse = _ref2 => {
|
|
513
|
+
let {
|
|
514
|
+
pagination: {
|
|
515
|
+
page: currentPage,
|
|
516
|
+
last_page: lastPage,
|
|
517
|
+
total
|
|
518
|
+
},
|
|
519
|
+
data: items
|
|
520
|
+
} = _ref2;
|
|
521
|
+
return {
|
|
522
|
+
page: parseInt(currentPage, 10),
|
|
523
|
+
lastPage: parseInt(lastPage, 10),
|
|
524
|
+
total: parseInt(total, 10),
|
|
525
|
+
items
|
|
526
|
+
};
|
|
527
|
+
},
|
|
528
|
+
onLoaded = null,
|
|
529
|
+
onError = null,
|
|
530
|
+
query = null
|
|
531
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
532
|
+
const lastState = react.useRef(null);
|
|
533
|
+
const initialState = react.useMemo(() => {
|
|
534
|
+
const finalInitialPages = initialPages !== null ? initialPages.map(it => getPageFromResponse(it)) : null;
|
|
535
|
+
const finalLastPage = finalInitialPages !== null ? finalInitialPages.reduce((currentLastPage, _ref3) => {
|
|
536
|
+
let {
|
|
537
|
+
lastPage: initialLastPage
|
|
538
|
+
} = _ref3;
|
|
539
|
+
return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
|
|
540
|
+
}, -1) : -1;
|
|
541
|
+
return {
|
|
542
|
+
lastPage: finalLastPage,
|
|
543
|
+
total: finalInitialPages !== null ? finalInitialPages[0].total : 0,
|
|
544
|
+
loaded: finalLastPage !== -1 && finalInitialPages !== null && finalInitialPages.length === finalLastPage,
|
|
545
|
+
loading: false,
|
|
546
|
+
pages: finalInitialPages !== null ? finalInitialPages : null
|
|
547
|
+
};
|
|
548
|
+
}, [initialPages]);
|
|
549
|
+
const currentPagesRef = react.useRef(initialState.pages);
|
|
550
|
+
const [state, setState] = react.useState(initialState);
|
|
551
|
+
const {
|
|
552
|
+
lastPage,
|
|
553
|
+
loaded,
|
|
554
|
+
loading,
|
|
555
|
+
pages,
|
|
556
|
+
total
|
|
557
|
+
} = state;
|
|
558
|
+
const items = pages !== null ? pages.reduce((pagesItems, _ref4) => {
|
|
559
|
+
let {
|
|
560
|
+
items: pageItems
|
|
561
|
+
} = _ref4;
|
|
562
|
+
return pagesItems.concat(pageItems);
|
|
563
|
+
}, []) : null;
|
|
564
|
+
|
|
565
|
+
const updateState = update => setState({ ...state,
|
|
566
|
+
...update
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
const updateFromResponse = function (response) {
|
|
570
|
+
let error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
571
|
+
let reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
572
|
+
|
|
573
|
+
if (error !== null) {
|
|
574
|
+
updateState({
|
|
575
|
+
loaded: false,
|
|
576
|
+
loading: false
|
|
577
|
+
});
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const newPage = getPageFromResponse(response);
|
|
582
|
+
const currentPages = currentPagesRef.current || [];
|
|
583
|
+
const newPages = (reset ? [newPage] : [...currentPages.filter(it => it.page !== newPage.page), newPage]).sort((a, b) => {
|
|
584
|
+
const {
|
|
585
|
+
page: aPage = null
|
|
586
|
+
} = a;
|
|
587
|
+
const {
|
|
588
|
+
page: bPage = null
|
|
589
|
+
} = b;
|
|
590
|
+
const hasObject = aPage !== null && bPage !== null;
|
|
591
|
+
|
|
592
|
+
if (hasObject) {
|
|
593
|
+
if (aPage === bPage) {
|
|
594
|
+
return 0;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return aPage > bPage ? 1 : -1;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (isNumber__default["default"](a) && isNumber__default["default"](b)) {
|
|
601
|
+
if (a === b) {
|
|
602
|
+
return 0;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return a > b ? 1 : -1;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return 0;
|
|
609
|
+
});
|
|
610
|
+
currentPagesRef.current = newPages;
|
|
611
|
+
updateState({
|
|
612
|
+
loaded: true,
|
|
613
|
+
loading: false,
|
|
614
|
+
lastPage: newPage.lastPage,
|
|
615
|
+
total: newPage.total,
|
|
616
|
+
pages: newPages
|
|
617
|
+
});
|
|
618
|
+
return newPage;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
const getNextPage = () => {
|
|
622
|
+
const allPages = lastPage !== -1 ? Array.call(null, ...Array(lastPage)).map((it, index) => index + 1) : [];
|
|
623
|
+
const currentPages = currentPagesRef.current || [];
|
|
624
|
+
const remainingPages = allPages.filter(pageNumber => currentPages.findIndex(it => it.page === pageNumber) === -1);
|
|
625
|
+
const firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
|
|
626
|
+
return firstItem !== null ? firstItem : null;
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
const loadItems = requestPage => {
|
|
630
|
+
updateState({
|
|
631
|
+
loading: true
|
|
632
|
+
});
|
|
633
|
+
return cancelablePromise.cancelable(loader(requestPage, count)).then(response => updateFromResponse(response)).catch(error => updateFromResponse(null, error)).then(response => {
|
|
634
|
+
if (onLoaded !== null) {
|
|
635
|
+
onLoaded(response);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return response;
|
|
639
|
+
}).catch(error => {
|
|
640
|
+
if (onError !== null) {
|
|
641
|
+
onError(error);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
const loadPage = pageToLoad => {
|
|
647
|
+
if (loading) {
|
|
648
|
+
return Promise.reject();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const currentPages = currentPagesRef.current || [];
|
|
652
|
+
const foundPage = currentPages.find(it => it.page === pageToLoad) || null;
|
|
653
|
+
|
|
654
|
+
if (foundPage !== null) {
|
|
655
|
+
return Promise.resolve(foundPage);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return loadItems(pageToLoad);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
const loadNextPage = () => {
|
|
662
|
+
if (loading) {
|
|
663
|
+
return Promise.reject();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const nextPage = getNextPage();
|
|
667
|
+
return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
|
|
668
|
+
}; // Reset all on query change
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
react.useEffect(() => {
|
|
672
|
+
const hadState = lastState.current !== null;
|
|
673
|
+
|
|
674
|
+
if (hadState) {
|
|
675
|
+
currentPagesRef.current = null;
|
|
676
|
+
updateState({
|
|
677
|
+
loaded: true,
|
|
678
|
+
loading: false,
|
|
679
|
+
lastPage: null,
|
|
680
|
+
total: 0,
|
|
681
|
+
pages: []
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}, [query]);
|
|
685
|
+
react.useEffect(() => {
|
|
686
|
+
const hadState = lastState.current !== null;
|
|
687
|
+
lastState.current = initialState;
|
|
688
|
+
|
|
689
|
+
if (hadState) {
|
|
690
|
+
currentPagesRef.current = initialState.pages;
|
|
691
|
+
setState(initialState);
|
|
692
|
+
}
|
|
693
|
+
}, [initialState]);
|
|
694
|
+
react.useEffect(() => {
|
|
695
|
+
if (loader === null) {
|
|
696
|
+
return () => {};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let loadPromise = null;
|
|
700
|
+
const pageToLoad = initialPages === null && page === null ? 1 : page;
|
|
701
|
+
|
|
702
|
+
if (pageToLoad !== null) {
|
|
703
|
+
loadPromise = loadItems(pageToLoad);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
return () => {
|
|
707
|
+
if (loadPromise !== null) {
|
|
708
|
+
loadPromise.cancel();
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
}, [loader, page]);
|
|
712
|
+
const currentPage = pages !== null ? pages.find(_ref5 => {
|
|
713
|
+
let {
|
|
714
|
+
page: pageNumber
|
|
715
|
+
} = _ref5;
|
|
716
|
+
return parseInt(pageNumber, 10) === parseInt(page, 10);
|
|
717
|
+
}) || null : null;
|
|
718
|
+
return {
|
|
719
|
+
items,
|
|
720
|
+
pages,
|
|
721
|
+
currentPage,
|
|
722
|
+
pageItems: currentPage !== null ? currentPage.items : null,
|
|
723
|
+
total,
|
|
724
|
+
lastPage,
|
|
725
|
+
loaded,
|
|
726
|
+
allLoaded: lastPage !== -1 && pages.length === lastPage,
|
|
727
|
+
loading,
|
|
728
|
+
loadNextPage,
|
|
729
|
+
loadPage
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const debug$2 = createDebug__default["default"]('folklore:video:native');
|
|
734
|
+
const noPlayerError = new Error('No player');
|
|
735
|
+
|
|
736
|
+
const useNativeVideoPlayer = function (url) {
|
|
737
|
+
let {
|
|
738
|
+
width = 0,
|
|
739
|
+
height = 0,
|
|
740
|
+
duration = 0,
|
|
741
|
+
initialMuted = false,
|
|
742
|
+
timeUpdateInterval = 1000,
|
|
743
|
+
onTimeUpdate: customOnTimeUpdate = null
|
|
744
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
745
|
+
const elementRef = react.useRef(null);
|
|
746
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
747
|
+
const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
|
|
748
|
+
const [playState, setPlayState] = react.useState({
|
|
584
749
|
playing: false,
|
|
585
750
|
paused: false,
|
|
586
751
|
ended: false,
|
|
587
752
|
buffering: false
|
|
588
|
-
})
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
_useState8 = _slicedToArray__default["default"](_useState7, 2),
|
|
599
|
-
metadata = _useState8[0],
|
|
600
|
-
setMetadata = _useState8[1];
|
|
601
|
-
|
|
602
|
-
var play = react.useCallback(function () {
|
|
603
|
-
var player = elementRef.current;
|
|
753
|
+
});
|
|
754
|
+
const [metadata, setMetadata] = react.useState({
|
|
755
|
+
width,
|
|
756
|
+
height,
|
|
757
|
+
duration
|
|
758
|
+
});
|
|
759
|
+
const play = react.useCallback(() => {
|
|
760
|
+
const {
|
|
761
|
+
current: player
|
|
762
|
+
} = elementRef;
|
|
604
763
|
return player !== null ? player.play() : Promise.reject(noPlayerError);
|
|
605
764
|
}, []);
|
|
606
|
-
|
|
607
|
-
|
|
765
|
+
const pause = react.useCallback(() => {
|
|
766
|
+
const {
|
|
767
|
+
current: player
|
|
768
|
+
} = elementRef;
|
|
608
769
|
return player !== null ? player.pause() : Promise.reject(noPlayerError);
|
|
609
770
|
}, []);
|
|
610
|
-
|
|
611
|
-
|
|
771
|
+
const setVolume = react.useCallback(newVolume => {
|
|
772
|
+
const {
|
|
773
|
+
current: player
|
|
774
|
+
} = elementRef;
|
|
612
775
|
|
|
613
776
|
if (player !== null) {
|
|
614
777
|
player.volume = newVolume;
|
|
@@ -617,8 +780,10 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
617
780
|
|
|
618
781
|
return Promise.reject(noPlayerError);
|
|
619
782
|
}, []);
|
|
620
|
-
|
|
621
|
-
|
|
783
|
+
const mute = react.useCallback(() => {
|
|
784
|
+
const {
|
|
785
|
+
current: player
|
|
786
|
+
} = elementRef;
|
|
622
787
|
|
|
623
788
|
if (player !== null) {
|
|
624
789
|
player.muted = true;
|
|
@@ -627,8 +792,10 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
627
792
|
|
|
628
793
|
return Promise.reject(noPlayerError);
|
|
629
794
|
}, []);
|
|
630
|
-
|
|
631
|
-
|
|
795
|
+
const unmute = react.useCallback(() => {
|
|
796
|
+
const {
|
|
797
|
+
current: player
|
|
798
|
+
} = elementRef;
|
|
632
799
|
|
|
633
800
|
if (player !== null) {
|
|
634
801
|
player.muted = false;
|
|
@@ -637,8 +804,10 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
637
804
|
|
|
638
805
|
return Promise.reject(noPlayerError);
|
|
639
806
|
}, []);
|
|
640
|
-
|
|
641
|
-
|
|
807
|
+
const seek = react.useCallback(newTime => {
|
|
808
|
+
const {
|
|
809
|
+
current: player
|
|
810
|
+
} = elementRef;
|
|
642
811
|
|
|
643
812
|
if (player !== null) {
|
|
644
813
|
player.currentTime = newTime;
|
|
@@ -647,8 +816,10 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
647
816
|
|
|
648
817
|
return Promise.reject(noPlayerError);
|
|
649
818
|
}, []);
|
|
650
|
-
|
|
651
|
-
|
|
819
|
+
const setLoop = react.useCallback(newLoop => {
|
|
820
|
+
const {
|
|
821
|
+
current: player
|
|
822
|
+
} = elementRef;
|
|
652
823
|
|
|
653
824
|
if (player !== null) {
|
|
654
825
|
player.loop = newLoop;
|
|
@@ -658,20 +829,22 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
658
829
|
return Promise.reject(noPlayerError);
|
|
659
830
|
}, []); // Bind player events
|
|
660
831
|
|
|
661
|
-
react.useEffect(
|
|
662
|
-
|
|
832
|
+
react.useEffect(() => {
|
|
833
|
+
const {
|
|
834
|
+
current: player
|
|
835
|
+
} = elementRef;
|
|
663
836
|
|
|
664
837
|
if (player === null) {
|
|
665
|
-
return
|
|
838
|
+
return () => {};
|
|
666
839
|
}
|
|
667
840
|
|
|
668
|
-
|
|
841
|
+
const onCanPlay = () => {
|
|
669
842
|
setLoaded(true);
|
|
670
843
|
debug$2('onCanPlay [URL: %s]', url);
|
|
671
844
|
};
|
|
672
845
|
|
|
673
|
-
|
|
674
|
-
|
|
846
|
+
const onMetadataLoaded = () => {
|
|
847
|
+
const newMetadata = {
|
|
675
848
|
duration: player.duration,
|
|
676
849
|
width: player.videoWidth,
|
|
677
850
|
height: player.videoHeight
|
|
@@ -680,7 +853,7 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
680
853
|
debug$2('onMetadataLoaded [URL: %s]', url);
|
|
681
854
|
};
|
|
682
855
|
|
|
683
|
-
|
|
856
|
+
const onPlay = () => {
|
|
684
857
|
setPlayState({
|
|
685
858
|
playing: true,
|
|
686
859
|
paused: false,
|
|
@@ -690,7 +863,7 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
690
863
|
debug$2('onPlay [URL: %s]', url);
|
|
691
864
|
};
|
|
692
865
|
|
|
693
|
-
|
|
866
|
+
const onPause = () => {
|
|
694
867
|
setPlayState({
|
|
695
868
|
playing: false,
|
|
696
869
|
paused: true,
|
|
@@ -700,7 +873,7 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
700
873
|
debug$2('onPause [URL: %s]', url);
|
|
701
874
|
};
|
|
702
875
|
|
|
703
|
-
|
|
876
|
+
const onEnded = () => {
|
|
704
877
|
setPlayState({
|
|
705
878
|
playing: false,
|
|
706
879
|
paused: false,
|
|
@@ -716,7 +889,7 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
716
889
|
player.addEventListener('play', onPlay);
|
|
717
890
|
player.addEventListener('pause', onPause);
|
|
718
891
|
player.addEventListener('ended', onEnded);
|
|
719
|
-
return
|
|
892
|
+
return () => {
|
|
720
893
|
debug$2('Unbind events [URL: %s]', url);
|
|
721
894
|
player.removeEventListener('canplay', onCanPlay);
|
|
722
895
|
player.removeEventListener('metadataloaded', onMetadataLoaded);
|
|
@@ -725,90 +898,79 @@ var useNativeVideoPlayer = function useNativeVideoPlayer(url) {
|
|
|
725
898
|
player.removeEventListener('ended', onEnded);
|
|
726
899
|
};
|
|
727
900
|
}, [url, elementRef.current, setPlayState, setMetadata, setVolumeState, setLoaded]);
|
|
728
|
-
|
|
729
|
-
|
|
901
|
+
const {
|
|
902
|
+
playing
|
|
903
|
+
} = playState;
|
|
904
|
+
const currentTime = usePlayerCurrentTime(elementRef.current, {
|
|
730
905
|
id: url,
|
|
731
906
|
disabled: !playing || timeUpdateInterval === null,
|
|
732
907
|
updateInterval: timeUpdateInterval,
|
|
733
908
|
onUpdate: customOnTimeUpdate
|
|
734
909
|
});
|
|
735
|
-
return
|
|
910
|
+
return {
|
|
736
911
|
ref: elementRef,
|
|
737
912
|
player: elementRef.current,
|
|
738
|
-
play
|
|
739
|
-
pause
|
|
740
|
-
mute
|
|
741
|
-
unmute
|
|
742
|
-
setVolume
|
|
743
|
-
seek
|
|
744
|
-
setLoop
|
|
913
|
+
play,
|
|
914
|
+
pause,
|
|
915
|
+
mute,
|
|
916
|
+
unmute,
|
|
917
|
+
setVolume,
|
|
918
|
+
seek,
|
|
919
|
+
setLoop,
|
|
745
920
|
ready: true,
|
|
746
|
-
currentTime
|
|
747
|
-
loaded
|
|
921
|
+
currentTime,
|
|
922
|
+
loaded,
|
|
748
923
|
muted: volume === 0,
|
|
749
|
-
volume
|
|
750
|
-
|
|
924
|
+
volume,
|
|
925
|
+
...metadata,
|
|
926
|
+
...playState
|
|
927
|
+
};
|
|
751
928
|
};
|
|
752
929
|
|
|
753
|
-
|
|
930
|
+
const observersCache = new Map();
|
|
754
931
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
rootMargin = _ref.rootMargin,
|
|
762
|
-
_ref$threshold = _ref.threshold,
|
|
763
|
-
threshold = _ref$threshold === void 0 ? null : _ref$threshold;
|
|
932
|
+
const getOptionsKey = _ref => {
|
|
933
|
+
let {
|
|
934
|
+
root = null,
|
|
935
|
+
rootMargin,
|
|
936
|
+
threshold = null
|
|
937
|
+
} = _ref;
|
|
764
938
|
return "root_".concat(root, "_rootMargin_").concat(rootMargin || null, "_threshold_").concat(threshold);
|
|
765
939
|
};
|
|
766
940
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
941
|
+
const createObserver = function (Observer) {
|
|
942
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
943
|
+
let subscribers = [];
|
|
770
944
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
return it.element === element;
|
|
774
|
-
}) || null;
|
|
945
|
+
const addSubscriber = (element, callback) => {
|
|
946
|
+
const currentSubscriber = subscribers.find(it => it.element === element) || null;
|
|
775
947
|
|
|
776
948
|
if (currentSubscriber !== null) {
|
|
777
|
-
return subscribers.map(
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
}) : it;
|
|
781
|
-
}).filter(function (it) {
|
|
782
|
-
return it.callbacks.length > 0;
|
|
783
|
-
});
|
|
949
|
+
return subscribers.map(it => it.element === element && it.callbacks.indexOf(callback) === -1 ? { ...it,
|
|
950
|
+
callbacks: [...it.callbacks, callback]
|
|
951
|
+
} : it).filter(it => it.callbacks.length > 0);
|
|
784
952
|
}
|
|
785
953
|
|
|
786
|
-
return [
|
|
787
|
-
element
|
|
954
|
+
return [...subscribers, {
|
|
955
|
+
element,
|
|
788
956
|
callbacks: [callback]
|
|
789
|
-
}]
|
|
957
|
+
}];
|
|
790
958
|
};
|
|
791
959
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
callbacks: it.callbacks.filter(function (subCallback) {
|
|
796
|
-
return subCallback !== callback;
|
|
797
|
-
})
|
|
798
|
-
}) : it;
|
|
799
|
-
}).filter(function (it) {
|
|
800
|
-
return it.callbacks.length > 0;
|
|
801
|
-
});
|
|
802
|
-
};
|
|
960
|
+
const removeSubscriber = (element, callback) => subscribers.map(it => it.element === element ? { ...it,
|
|
961
|
+
callbacks: it.callbacks.filter(subCallback => subCallback !== callback)
|
|
962
|
+
} : it).filter(it => it.callbacks.length > 0);
|
|
803
963
|
|
|
804
|
-
|
|
805
|
-
entries.forEach(
|
|
806
|
-
subscribers.forEach(
|
|
807
|
-
|
|
808
|
-
|
|
964
|
+
const onUpdate = entries => {
|
|
965
|
+
entries.forEach(entry => {
|
|
966
|
+
subscribers.forEach(_ref2 => {
|
|
967
|
+
let {
|
|
968
|
+
element,
|
|
969
|
+
callbacks
|
|
970
|
+
} = _ref2;
|
|
809
971
|
|
|
810
972
|
if (element === entry.target) {
|
|
811
|
-
callbacks.forEach(
|
|
973
|
+
callbacks.forEach(callback => {
|
|
812
974
|
callback(entry);
|
|
813
975
|
});
|
|
814
976
|
}
|
|
@@ -816,33 +978,29 @@ var createObserver = function createObserver(Observer) {
|
|
|
816
978
|
});
|
|
817
979
|
};
|
|
818
980
|
|
|
819
|
-
|
|
981
|
+
const observer = new Observer(onUpdate, options);
|
|
820
982
|
|
|
821
|
-
|
|
822
|
-
|
|
983
|
+
const unsubscribe = function (element) {
|
|
984
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
823
985
|
subscribers = removeSubscriber(element, callback);
|
|
824
986
|
|
|
825
987
|
if (typeof observer.unobserve === 'undefined') {
|
|
826
988
|
observer.disconnect();
|
|
827
|
-
subscribers.forEach(
|
|
989
|
+
subscribers.forEach(subscriber => {
|
|
828
990
|
observer.observe(subscriber.element);
|
|
829
991
|
});
|
|
830
992
|
return;
|
|
831
993
|
}
|
|
832
994
|
|
|
833
|
-
|
|
834
|
-
return it.element === element;
|
|
835
|
-
}) || null;
|
|
995
|
+
const currentSubscriber = subscribers.find(it => it.element === element) || null;
|
|
836
996
|
|
|
837
997
|
if (currentSubscriber === null) {
|
|
838
998
|
observer.unobserve(element);
|
|
839
999
|
}
|
|
840
1000
|
};
|
|
841
1001
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
return it.element === element;
|
|
845
|
-
}) || null;
|
|
1002
|
+
const subscribe = (element, callback) => {
|
|
1003
|
+
const currentSubscriber = subscribers.find(it => it.element === element) || null;
|
|
846
1004
|
subscribers = addSubscriber(element, callback);
|
|
847
1005
|
|
|
848
1006
|
if (currentSubscriber === null) {
|
|
@@ -851,21 +1009,21 @@ var createObserver = function createObserver(Observer) {
|
|
|
851
1009
|
};
|
|
852
1010
|
|
|
853
1011
|
return {
|
|
854
|
-
subscribe
|
|
855
|
-
unsubscribe
|
|
856
|
-
observer
|
|
1012
|
+
subscribe,
|
|
1013
|
+
unsubscribe,
|
|
1014
|
+
observer
|
|
857
1015
|
};
|
|
858
1016
|
};
|
|
859
1017
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1018
|
+
const getObserver = function (Observer) {
|
|
1019
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1020
|
+
const observerKey = getOptionsKey(options);
|
|
863
1021
|
|
|
864
1022
|
if (!observersCache.has(Observer)) {
|
|
865
1023
|
observersCache.set(Observer, {});
|
|
866
1024
|
}
|
|
867
1025
|
|
|
868
|
-
|
|
1026
|
+
const observers = observersCache.get(Observer);
|
|
869
1027
|
|
|
870
1028
|
if (typeof observers[observerKey] === 'undefined') {
|
|
871
1029
|
observers[observerKey] = createObserver(Observer, options);
|
|
@@ -874,37 +1032,31 @@ var getObserver = function getObserver(Observer) {
|
|
|
874
1032
|
|
|
875
1033
|
return observers[observerKey];
|
|
876
1034
|
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
var callback = function callback(newEntry) {
|
|
901
|
-
return setEntry(newEntry);
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
var unsubscribe = null;
|
|
1035
|
+
const useObserver = function (Observer) {
|
|
1036
|
+
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1037
|
+
let initialEntry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1038
|
+
const {
|
|
1039
|
+
root = null,
|
|
1040
|
+
rootMargin = null,
|
|
1041
|
+
threshold: defaultThreshold = null,
|
|
1042
|
+
disabled = false
|
|
1043
|
+
} = opts;
|
|
1044
|
+
const [entry, setEntry] = react.useState(initialEntry);
|
|
1045
|
+
const threshold = react.useMemo(() => defaultThreshold, [defaultThreshold]);
|
|
1046
|
+
const nodeRef = react.useRef(null);
|
|
1047
|
+
const currentElement = react.useRef(null);
|
|
1048
|
+
const elementChanged = nodeRef.current !== currentElement.current;
|
|
1049
|
+
react.useEffect(() => {
|
|
1050
|
+
const {
|
|
1051
|
+
current: nodeElement
|
|
1052
|
+
} = nodeRef;
|
|
1053
|
+
|
|
1054
|
+
const callback = newEntry => setEntry(newEntry);
|
|
1055
|
+
|
|
1056
|
+
let unsubscribe = null;
|
|
905
1057
|
|
|
906
1058
|
if (nodeElement !== null) {
|
|
907
|
-
|
|
1059
|
+
const newOpts = {};
|
|
908
1060
|
|
|
909
1061
|
if (root !== null) {
|
|
910
1062
|
newOpts.root = root;
|
|
@@ -918,16 +1070,16 @@ var useObserver = function useObserver(Observer) {
|
|
|
918
1070
|
newOpts.threshold = threshold;
|
|
919
1071
|
}
|
|
920
1072
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1073
|
+
const {
|
|
1074
|
+
subscribe,
|
|
1075
|
+
unsubscribe: localUnsubscribe
|
|
1076
|
+
} = getObserver(Observer, newOpts);
|
|
925
1077
|
unsubscribe = localUnsubscribe;
|
|
926
1078
|
subscribe(nodeElement, callback);
|
|
927
1079
|
}
|
|
928
1080
|
|
|
929
1081
|
currentElement.current = nodeElement;
|
|
930
|
-
return
|
|
1082
|
+
return () => {
|
|
931
1083
|
if (unsubscribe !== null) {
|
|
932
1084
|
unsubscribe(nodeElement, callback);
|
|
933
1085
|
}
|
|
@@ -935,14 +1087,15 @@ var useObserver = function useObserver(Observer) {
|
|
|
935
1087
|
}, [Observer, elementChanged, disabled, root, rootMargin, threshold]);
|
|
936
1088
|
return {
|
|
937
1089
|
ref: nodeRef,
|
|
938
|
-
entry
|
|
1090
|
+
entry
|
|
939
1091
|
};
|
|
940
1092
|
};
|
|
941
1093
|
/**
|
|
942
1094
|
* Intersection Observer
|
|
943
1095
|
*/
|
|
944
1096
|
|
|
945
|
-
|
|
1097
|
+
const defaultThreshold = [0, 1.0];
|
|
1098
|
+
const intersectionObserverInitialEntry = {
|
|
946
1099
|
target: null,
|
|
947
1100
|
time: null,
|
|
948
1101
|
isVisible: false,
|
|
@@ -952,130 +1105,89 @@ var intersectionObserverInitialEntry = {
|
|
|
952
1105
|
boundingClientRect: null,
|
|
953
1106
|
rootBounds: null
|
|
954
1107
|
};
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
threshold = _ref3$threshold === void 0 ? [0, 1.0] : _ref3$threshold,
|
|
963
|
-
_ref3$disabled = _ref3.disabled,
|
|
964
|
-
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled;
|
|
965
|
-
|
|
1108
|
+
const useIntersectionObserver = function () {
|
|
1109
|
+
let {
|
|
1110
|
+
root = null,
|
|
1111
|
+
rootMargin = '0px',
|
|
1112
|
+
threshold = defaultThreshold,
|
|
1113
|
+
disabled = false
|
|
1114
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
966
1115
|
return useObserver(IntersectionObserver, {
|
|
967
|
-
root
|
|
968
|
-
rootMargin
|
|
969
|
-
threshold
|
|
970
|
-
disabled
|
|
1116
|
+
root,
|
|
1117
|
+
rootMargin,
|
|
1118
|
+
threshold,
|
|
1119
|
+
disabled
|
|
971
1120
|
}, intersectionObserverInitialEntry);
|
|
972
1121
|
};
|
|
973
1122
|
/**
|
|
974
1123
|
* Resize Observer
|
|
975
1124
|
*/
|
|
976
1125
|
|
|
977
|
-
|
|
1126
|
+
const resizeObserverInitialEntry = {
|
|
978
1127
|
target: null,
|
|
979
1128
|
contentRect: null,
|
|
980
1129
|
contentBoxSize: null,
|
|
981
1130
|
borderBoxSize: null
|
|
982
1131
|
};
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1132
|
+
const useResizeObserver = function () {
|
|
1133
|
+
let {
|
|
1134
|
+
disabled = false
|
|
1135
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
988
1136
|
return useObserver(ResizeObserver, {
|
|
989
|
-
disabled
|
|
1137
|
+
disabled
|
|
990
1138
|
}, resizeObserverInitialEntry);
|
|
991
1139
|
};
|
|
992
1140
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
996
|
-
var NO_PLAYER_ERROR$1 = new Error('No player');
|
|
997
|
-
var debug$1 = createDebug__default["default"]('folklore:video:youtube');
|
|
1141
|
+
const NO_PLAYER_ERROR$1 = new Error('No player');
|
|
1142
|
+
const debug$1 = createDebug__default["default"]('folklore:video:youtube');
|
|
998
1143
|
|
|
999
1144
|
function useYouTubePlayer(id) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
initialMuted = _ref$muted === void 0 ? false : _ref$muted,
|
|
1015
|
-
_ref$onVolumeChange = _ref.onVolumeChange,
|
|
1016
|
-
customOnVolumeChange = _ref$onVolumeChange === void 0 ? null : _ref$onVolumeChange,
|
|
1017
|
-
_ref$onTimeUpdate = _ref.onTimeUpdate,
|
|
1018
|
-
customOnTimeUpdate = _ref$onTimeUpdate === void 0 ? null : _ref$onTimeUpdate,
|
|
1019
|
-
_ref$getVideoId = _ref.getVideoId,
|
|
1020
|
-
getVideoId = _ref$getVideoId === void 0 ? function (url) {
|
|
1021
|
-
if (url === null || url.match(/^https?:/) === null) {
|
|
1022
|
-
return url;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
|
1026
|
-
var match = url.match(regExp);
|
|
1027
|
-
return match && match[7].length === 11 ? match[7] : null;
|
|
1028
|
-
} : _ref$getVideoId;
|
|
1029
|
-
|
|
1030
|
-
var _useState = react.useState(typeof window.YT !== 'undefined'),
|
|
1031
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
1032
|
-
apiLoaded = _useState2[0],
|
|
1033
|
-
setApiLoaded = _useState2[1];
|
|
1034
|
-
|
|
1035
|
-
var apiRef = react.useRef(typeof window.YT !== 'undefined' ? window.YT : null);
|
|
1036
|
-
var elementRef = react.useRef(null);
|
|
1037
|
-
var playerRef = react.useRef(null);
|
|
1038
|
-
var playerElementRef = react.useRef(elementRef.current);
|
|
1039
|
-
var elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
1040
|
-
var videoId = react.useMemo(function () {
|
|
1041
|
-
return getVideoId(id);
|
|
1042
|
-
}, [id]);
|
|
1043
|
-
|
|
1044
|
-
var _useState3 = react.useState(false),
|
|
1045
|
-
_useState4 = _slicedToArray__default["default"](_useState3, 2),
|
|
1046
|
-
ready = _useState4[0],
|
|
1047
|
-
setReady = _useState4[1];
|
|
1048
|
-
|
|
1049
|
-
var _useState5 = react.useState(initialMuted),
|
|
1050
|
-
_useState6 = _slicedToArray__default["default"](_useState5, 2),
|
|
1051
|
-
muted = _useState6[0],
|
|
1052
|
-
setMuted = _useState6[1];
|
|
1145
|
+
let {
|
|
1146
|
+
width = 0,
|
|
1147
|
+
height = 0,
|
|
1148
|
+
duration = 0,
|
|
1149
|
+
autoplay = false,
|
|
1150
|
+
controls = true,
|
|
1151
|
+
timeUpdateInterval = 1000,
|
|
1152
|
+
muted: initialMuted = false,
|
|
1153
|
+
onVolumeChange: customOnVolumeChange = null,
|
|
1154
|
+
onTimeUpdate: customOnTimeUpdate = null,
|
|
1155
|
+
getVideoId = url => {
|
|
1156
|
+
if (url === null || url.match(/^https?:/) === null) {
|
|
1157
|
+
return url;
|
|
1158
|
+
}
|
|
1053
1159
|
|
|
1054
|
-
|
|
1160
|
+
const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
|
|
1161
|
+
const match = url.match(regExp);
|
|
1162
|
+
return match && match[7].length === 11 ? match[7] : null;
|
|
1163
|
+
}
|
|
1164
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1165
|
+
const [apiLoaded, setApiLoaded] = react.useState(typeof window.YT !== 'undefined');
|
|
1166
|
+
const apiRef = react.useRef(typeof window.YT !== 'undefined' ? window.YT : null);
|
|
1167
|
+
const elementRef = react.useRef(null);
|
|
1168
|
+
const playerRef = react.useRef(null);
|
|
1169
|
+
const playerElementRef = react.useRef(elementRef.current);
|
|
1170
|
+
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
1171
|
+
const videoId = react.useMemo(() => getVideoId(id), [id]);
|
|
1172
|
+
const [ready, setReady] = react.useState(false);
|
|
1173
|
+
const [muted, setMuted] = react.useState(initialMuted);
|
|
1174
|
+
const [playState, setPlayState] = react.useState({
|
|
1055
1175
|
playing: false,
|
|
1056
1176
|
paused: false,
|
|
1057
1177
|
ended: false,
|
|
1058
1178
|
buffering: false
|
|
1059
|
-
})
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
duration: duration
|
|
1068
|
-
}),
|
|
1069
|
-
_useState10 = _slicedToArray__default["default"](_useState9, 2),
|
|
1070
|
-
metadata = _useState10[0],
|
|
1071
|
-
setMetadata = _useState10[1];
|
|
1072
|
-
|
|
1073
|
-
react.useEffect(function () {
|
|
1074
|
-
var canceled = false;
|
|
1179
|
+
});
|
|
1180
|
+
const [metadata, setMetadata] = react.useState({
|
|
1181
|
+
width,
|
|
1182
|
+
height,
|
|
1183
|
+
duration
|
|
1184
|
+
});
|
|
1185
|
+
react.useEffect(() => {
|
|
1186
|
+
let canceled = false;
|
|
1075
1187
|
|
|
1076
1188
|
if (!apiLoaded && videoId !== null) {
|
|
1077
1189
|
debug$1('Load API');
|
|
1078
|
-
services.loadYouTube().then(
|
|
1190
|
+
services.loadYouTube().then(api => {
|
|
1079
1191
|
if (!canceled) {
|
|
1080
1192
|
apiRef.current = api;
|
|
1081
1193
|
setApiLoaded(true);
|
|
@@ -1084,21 +1196,27 @@ function useYouTubePlayer(id) {
|
|
|
1084
1196
|
});
|
|
1085
1197
|
}
|
|
1086
1198
|
|
|
1087
|
-
return
|
|
1199
|
+
return () => {
|
|
1088
1200
|
canceled = true;
|
|
1089
1201
|
};
|
|
1090
1202
|
}, [apiLoaded, videoId, setApiLoaded]);
|
|
1091
|
-
|
|
1092
|
-
|
|
1203
|
+
const play = react.useCallback(() => {
|
|
1204
|
+
const {
|
|
1205
|
+
current: player
|
|
1206
|
+
} = playerRef;
|
|
1093
1207
|
return player !== null && typeof player.playVideo !== 'undefined' ? Promise.resolve(player.playVideo()) : Promise.reject(NO_PLAYER_ERROR$1);
|
|
1094
1208
|
}, []);
|
|
1095
|
-
|
|
1096
|
-
|
|
1209
|
+
const pause = react.useCallback(() => {
|
|
1210
|
+
const {
|
|
1211
|
+
current: player
|
|
1212
|
+
} = playerRef;
|
|
1097
1213
|
return player !== null && typeof player.pauseVideo !== 'undefined' ? Promise.resolve(player.pauseVideo()) : Promise.reject(NO_PLAYER_ERROR$1);
|
|
1098
1214
|
}, []);
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1215
|
+
const setVolume = react.useCallback(volume => {
|
|
1216
|
+
const {
|
|
1217
|
+
current: player
|
|
1218
|
+
} = playerRef;
|
|
1219
|
+
const promise = player !== null && typeof player.setVolume !== 'undefined' ? Promise.resolve(player.setVolume(volume * 100)) : Promise.reject(NO_PLAYER_ERROR$1);
|
|
1102
1220
|
|
|
1103
1221
|
if (customOnVolumeChange) {
|
|
1104
1222
|
customOnVolumeChange(volume);
|
|
@@ -1106,35 +1224,41 @@ function useYouTubePlayer(id) {
|
|
|
1106
1224
|
|
|
1107
1225
|
return promise;
|
|
1108
1226
|
}, [customOnVolumeChange]);
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1227
|
+
const mute = react.useCallback(() => {
|
|
1228
|
+
const {
|
|
1229
|
+
current: player
|
|
1230
|
+
} = playerRef;
|
|
1231
|
+
return (player !== null && typeof player.mute !== 'undefined' ? Promise.resolve(player.mute()) : Promise.reject(NO_PLAYER_ERROR$1)).then(() => setMuted(true));
|
|
1114
1232
|
}, [setMuted]);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1233
|
+
const unmute = react.useCallback(() => {
|
|
1234
|
+
const {
|
|
1235
|
+
current: player
|
|
1236
|
+
} = playerRef;
|
|
1237
|
+
return (player !== null && typeof player.unMute !== 'undefined' ? Promise.resolve(player.unMute()) : Promise.reject(NO_PLAYER_ERROR$1)).then(() => setMuted(false));
|
|
1120
1238
|
}, []);
|
|
1121
|
-
|
|
1122
|
-
|
|
1239
|
+
const seek = react.useCallback(time => {
|
|
1240
|
+
const {
|
|
1241
|
+
current: player
|
|
1242
|
+
} = playerRef;
|
|
1123
1243
|
return player !== null && typeof player.seekTo !== 'undefined' ? Promise.resolve(player.seekTo(time)) : Promise.reject(NO_PLAYER_ERROR$1);
|
|
1124
1244
|
}, []);
|
|
1125
|
-
|
|
1126
|
-
|
|
1245
|
+
const setLoop = react.useCallback(loop => {
|
|
1246
|
+
const {
|
|
1247
|
+
current: player
|
|
1248
|
+
} = playerRef;
|
|
1127
1249
|
return player !== null && typeof player.setLoop !== 'undefined' ? Promise.resolve(player.setLoop(loop)) : Promise.reject(NO_PLAYER_ERROR$1);
|
|
1128
1250
|
}, []);
|
|
1129
|
-
|
|
1251
|
+
const destroyPlayer = react.useCallback(() => {
|
|
1130
1252
|
if (playerRef.current !== null) {
|
|
1131
1253
|
debug$1('Unset player');
|
|
1132
1254
|
playerRef.current = null;
|
|
1133
1255
|
}
|
|
1134
1256
|
}, []); // Detect iframe switch and destroy player
|
|
1135
1257
|
|
|
1136
|
-
react.useEffect(
|
|
1137
|
-
|
|
1258
|
+
react.useEffect(() => {
|
|
1259
|
+
const {
|
|
1260
|
+
current: currentPlayer
|
|
1261
|
+
} = playerRef;
|
|
1138
1262
|
|
|
1139
1263
|
if (playerElementRef.current !== elementRef.current && currentPlayer !== null) {
|
|
1140
1264
|
debug$1('iFrame switched');
|
|
@@ -1142,20 +1266,23 @@ function useYouTubePlayer(id) {
|
|
|
1142
1266
|
}
|
|
1143
1267
|
}, [elementHasChanged]); // Create player
|
|
1144
1268
|
|
|
1145
|
-
react.useEffect(
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1269
|
+
react.useEffect(() => {
|
|
1270
|
+
const {
|
|
1271
|
+
current: YT = null
|
|
1272
|
+
} = apiRef;
|
|
1273
|
+
const {
|
|
1274
|
+
current: currentPlayer = null
|
|
1275
|
+
} = playerRef;
|
|
1276
|
+
const {
|
|
1277
|
+
current: element = null
|
|
1278
|
+
} = elementRef;
|
|
1152
1279
|
|
|
1153
1280
|
if (!apiLoaded || videoId === null || element === null) {
|
|
1154
1281
|
destroyPlayer();
|
|
1155
1282
|
return;
|
|
1156
1283
|
}
|
|
1157
1284
|
|
|
1158
|
-
|
|
1285
|
+
let player = currentPlayer;
|
|
1159
1286
|
|
|
1160
1287
|
if (player !== null && typeof player.loadVideoById !== 'undefined') {
|
|
1161
1288
|
debug$1('Switch video [ID: %s]', videoId);
|
|
@@ -1163,32 +1290,36 @@ function useYouTubePlayer(id) {
|
|
|
1163
1290
|
} else {
|
|
1164
1291
|
debug$1('Create player [ID: %s]', videoId);
|
|
1165
1292
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1293
|
+
const onReady = _ref => {
|
|
1294
|
+
let {
|
|
1295
|
+
target
|
|
1296
|
+
} = _ref;
|
|
1168
1297
|
player = target;
|
|
1169
1298
|
playerRef.current = target;
|
|
1170
1299
|
setReady(true);
|
|
1171
|
-
|
|
1300
|
+
const newDuration = target.getDuration();
|
|
1172
1301
|
|
|
1173
1302
|
if (newDuration !== metadata.duration) {
|
|
1174
|
-
setMetadata(
|
|
1303
|
+
setMetadata({ ...metadata,
|
|
1175
1304
|
duration: newDuration
|
|
1176
|
-
})
|
|
1305
|
+
});
|
|
1177
1306
|
}
|
|
1178
1307
|
|
|
1179
1308
|
debug$1('onReady [ID: %s]', videoId);
|
|
1180
1309
|
};
|
|
1181
1310
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1311
|
+
const onStateChange = _ref2 => {
|
|
1312
|
+
let {
|
|
1313
|
+
data: state
|
|
1314
|
+
} = _ref2;
|
|
1315
|
+
const newState = {
|
|
1185
1316
|
playing: state === YT.PlayerState.PLAYING,
|
|
1186
1317
|
paused: state === YT.PlayerState.PAUSED,
|
|
1187
1318
|
ended: state === YT.PlayerState.ENDED,
|
|
1188
1319
|
buffering: state === YT.PlayerState.BUFFERING
|
|
1189
1320
|
};
|
|
1190
1321
|
setPlayState(newState);
|
|
1191
|
-
|
|
1322
|
+
let stateLabel = null;
|
|
1192
1323
|
|
|
1193
1324
|
if (newState.playing) {
|
|
1194
1325
|
stateLabel = 'playing';
|
|
@@ -1208,9 +1339,9 @@ function useYouTubePlayer(id) {
|
|
|
1208
1339
|
};
|
|
1209
1340
|
|
|
1210
1341
|
player = new YT.Player(element, {
|
|
1211
|
-
videoId
|
|
1342
|
+
videoId,
|
|
1212
1343
|
playerVars: {
|
|
1213
|
-
controls
|
|
1344
|
+
controls,
|
|
1214
1345
|
autoplay: autoplay ? 1 : 0,
|
|
1215
1346
|
mute: initialMuted,
|
|
1216
1347
|
playsinline: true,
|
|
@@ -1219,8 +1350,8 @@ function useYouTubePlayer(id) {
|
|
|
1219
1350
|
modestbranding: 1
|
|
1220
1351
|
},
|
|
1221
1352
|
events: {
|
|
1222
|
-
onReady
|
|
1223
|
-
onStateChange
|
|
1353
|
+
onReady,
|
|
1354
|
+
onStateChange
|
|
1224
1355
|
}
|
|
1225
1356
|
});
|
|
1226
1357
|
}
|
|
@@ -1228,127 +1359,88 @@ function useYouTubePlayer(id) {
|
|
|
1228
1359
|
playerRef.current = player;
|
|
1229
1360
|
playerElementRef.current = element;
|
|
1230
1361
|
}, [apiLoaded, videoId, elementHasChanged, setPlayState, setReady, setMetadata, destroyPlayer]);
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1362
|
+
const {
|
|
1363
|
+
playing
|
|
1364
|
+
} = playState;
|
|
1365
|
+
const getCurrentTime = react.useCallback(p => p.getCurrentTime(), []);
|
|
1366
|
+
const currentTime = usePlayerCurrentTime(playerRef.current, {
|
|
1236
1367
|
id: videoId,
|
|
1237
1368
|
disabled: !playing || timeUpdateInterval === null,
|
|
1238
1369
|
updateInterval: timeUpdateInterval,
|
|
1239
1370
|
onUpdate: customOnTimeUpdate,
|
|
1240
|
-
getCurrentTime
|
|
1371
|
+
getCurrentTime
|
|
1241
1372
|
});
|
|
1242
|
-
return
|
|
1373
|
+
return {
|
|
1243
1374
|
ref: elementRef,
|
|
1244
1375
|
player: playerRef.current,
|
|
1245
|
-
play
|
|
1246
|
-
pause
|
|
1247
|
-
mute
|
|
1248
|
-
unmute
|
|
1249
|
-
setVolume
|
|
1250
|
-
seek
|
|
1251
|
-
setLoop
|
|
1252
|
-
ready
|
|
1253
|
-
currentTime
|
|
1254
|
-
muted
|
|
1255
|
-
loaded: ready
|
|
1256
|
-
|
|
1376
|
+
play,
|
|
1377
|
+
pause,
|
|
1378
|
+
mute,
|
|
1379
|
+
unmute,
|
|
1380
|
+
setVolume,
|
|
1381
|
+
seek,
|
|
1382
|
+
setLoop,
|
|
1383
|
+
ready,
|
|
1384
|
+
currentTime,
|
|
1385
|
+
muted,
|
|
1386
|
+
loaded: ready,
|
|
1387
|
+
...metadata,
|
|
1388
|
+
...playState
|
|
1389
|
+
};
|
|
1257
1390
|
}
|
|
1258
1391
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
byline = _ref$byline === void 0 ? false : _ref$byline,
|
|
1279
|
-
_ref$controls = _ref.controls,
|
|
1280
|
-
controls = _ref$controls === void 0 ? false : _ref$controls,
|
|
1281
|
-
_ref$initialMuted = _ref.initialMuted,
|
|
1282
|
-
initialMuted = _ref$initialMuted === void 0 ? false : _ref$initialMuted,
|
|
1283
|
-
_ref$timeUpdateInterv = _ref.timeUpdateInterval,
|
|
1284
|
-
timeUpdateInterval = _ref$timeUpdateInterv === void 0 ? 1000 : _ref$timeUpdateInterv,
|
|
1285
|
-
_ref$onTimeUpdate = _ref.onTimeUpdate,
|
|
1286
|
-
customOnTimeUpdate = _ref$onTimeUpdate === void 0 ? null : _ref$onTimeUpdate,
|
|
1287
|
-
_ref$getVideoId = _ref.getVideoId,
|
|
1288
|
-
getVideoId = _ref$getVideoId === void 0 ? function (url) {
|
|
1289
|
-
if (url === null || url.match(/^[0-9]+$/) !== null) {
|
|
1290
|
-
return url;
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
var match = url.match(/\/[0-9]+/);
|
|
1294
|
-
return match !== null ? match[1] : null;
|
|
1295
|
-
} : _ref$getVideoId;
|
|
1296
|
-
|
|
1297
|
-
var _useState = react.useState(false),
|
|
1298
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
1299
|
-
apiLoaded = _useState2[0],
|
|
1300
|
-
setApiLoaded = _useState2[1];
|
|
1301
|
-
|
|
1302
|
-
var apiRef = react.useRef(null);
|
|
1303
|
-
var elementRef = react.useRef(null);
|
|
1304
|
-
var playerRef = react.useRef(null);
|
|
1305
|
-
var playerElementRef = react.useRef(elementRef.current);
|
|
1306
|
-
var elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
1307
|
-
var videoId = react.useMemo(function () {
|
|
1308
|
-
return getVideoId(id);
|
|
1309
|
-
}, [id]);
|
|
1310
|
-
|
|
1311
|
-
var _useState3 = react.useState(false),
|
|
1312
|
-
_useState4 = _slicedToArray__default["default"](_useState3, 2),
|
|
1313
|
-
ready = _useState4[0],
|
|
1314
|
-
setReady = _useState4[1];
|
|
1315
|
-
|
|
1316
|
-
var _useState5 = react.useState(false),
|
|
1317
|
-
_useState6 = _slicedToArray__default["default"](_useState5, 2),
|
|
1318
|
-
loaded = _useState6[0],
|
|
1319
|
-
setLoaded = _useState6[1];
|
|
1320
|
-
|
|
1321
|
-
var _useState7 = react.useState(initialMuted ? 0 : 1),
|
|
1322
|
-
_useState8 = _slicedToArray__default["default"](_useState7, 2),
|
|
1323
|
-
volume = _useState8[0],
|
|
1324
|
-
setVolumeState = _useState8[1];
|
|
1392
|
+
const debug = createDebug__default["default"]('folklore:video:vimeo');
|
|
1393
|
+
const NO_PLAYER_ERROR = new Error('No player');
|
|
1394
|
+
|
|
1395
|
+
const useVimeoPlayer = function (id) {
|
|
1396
|
+
let {
|
|
1397
|
+
width = 0,
|
|
1398
|
+
height = 0,
|
|
1399
|
+
duration = 0,
|
|
1400
|
+
autoplay = false,
|
|
1401
|
+
autopause = true,
|
|
1402
|
+
byline = false,
|
|
1403
|
+
controls = false,
|
|
1404
|
+
initialMuted = false,
|
|
1405
|
+
timeUpdateInterval = 1000,
|
|
1406
|
+
onTimeUpdate: customOnTimeUpdate = null,
|
|
1407
|
+
getVideoId = url => {
|
|
1408
|
+
if (url === null || url.match(/^[0-9]+$/) !== null) {
|
|
1409
|
+
return url;
|
|
1410
|
+
}
|
|
1325
1411
|
|
|
1326
|
-
|
|
1412
|
+
const match = url.match(/\/[0-9]+/);
|
|
1413
|
+
return match !== null ? match[1] : null;
|
|
1414
|
+
}
|
|
1415
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1416
|
+
const [apiLoaded, setApiLoaded] = react.useState(false);
|
|
1417
|
+
const apiRef = react.useRef(null);
|
|
1418
|
+
const elementRef = react.useRef(null);
|
|
1419
|
+
const playerRef = react.useRef(null);
|
|
1420
|
+
const playerElementRef = react.useRef(elementRef.current);
|
|
1421
|
+
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
1422
|
+
const videoId = react.useMemo(() => getVideoId(id), [id]);
|
|
1423
|
+
const [ready, setReady] = react.useState(false);
|
|
1424
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
1425
|
+
const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
|
|
1426
|
+
const [playState, setPlayState] = react.useState({
|
|
1327
1427
|
playing: false,
|
|
1328
1428
|
paused: false,
|
|
1329
1429
|
ended: false,
|
|
1330
1430
|
buffering: false
|
|
1331
|
-
})
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
width: width,
|
|
1338
|
-
height: height,
|
|
1339
|
-
duration: duration
|
|
1340
|
-
}),
|
|
1341
|
-
_useState12 = _slicedToArray__default["default"](_useState11, 2),
|
|
1342
|
-
metadata = _useState12[0],
|
|
1343
|
-
setMetadata = _useState12[1]; // Load SDK
|
|
1344
|
-
|
|
1431
|
+
});
|
|
1432
|
+
const [metadata, setMetadata] = react.useState({
|
|
1433
|
+
width,
|
|
1434
|
+
height,
|
|
1435
|
+
duration
|
|
1436
|
+
}); // Load SDK
|
|
1345
1437
|
|
|
1346
|
-
react.useEffect(
|
|
1347
|
-
|
|
1438
|
+
react.useEffect(() => {
|
|
1439
|
+
let canceled = false;
|
|
1348
1440
|
|
|
1349
1441
|
if (!apiLoaded && id !== null) {
|
|
1350
1442
|
debug('Load API');
|
|
1351
|
-
services.loadVimeo().then(
|
|
1443
|
+
services.loadVimeo().then(api => {
|
|
1352
1444
|
if (!canceled) {
|
|
1353
1445
|
apiRef.current = api;
|
|
1354
1446
|
setApiLoaded(true);
|
|
@@ -1357,40 +1449,56 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1357
1449
|
});
|
|
1358
1450
|
}
|
|
1359
1451
|
|
|
1360
|
-
return
|
|
1452
|
+
return () => {
|
|
1361
1453
|
canceled = true;
|
|
1362
1454
|
};
|
|
1363
1455
|
}, [id]);
|
|
1364
|
-
|
|
1365
|
-
|
|
1456
|
+
const play = react.useCallback(() => {
|
|
1457
|
+
const {
|
|
1458
|
+
current: player
|
|
1459
|
+
} = playerRef;
|
|
1366
1460
|
return player !== null ? player.play() : Promise.reject(NO_PLAYER_ERROR);
|
|
1367
1461
|
}, []);
|
|
1368
|
-
|
|
1369
|
-
|
|
1462
|
+
const pause = react.useCallback(() => {
|
|
1463
|
+
const {
|
|
1464
|
+
current: player
|
|
1465
|
+
} = playerRef;
|
|
1370
1466
|
return player !== null ? player.pause() : Promise.reject(NO_PLAYER_ERROR);
|
|
1371
1467
|
}, []);
|
|
1372
|
-
|
|
1373
|
-
|
|
1468
|
+
const setVolume = react.useCallback(newVolume => {
|
|
1469
|
+
const {
|
|
1470
|
+
current: player
|
|
1471
|
+
} = playerRef;
|
|
1374
1472
|
return player !== null ? player.setVolume(newVolume) : Promise.reject(NO_PLAYER_ERROR);
|
|
1375
1473
|
}, []);
|
|
1376
|
-
|
|
1377
|
-
|
|
1474
|
+
const mute = react.useCallback(() => {
|
|
1475
|
+
const {
|
|
1476
|
+
current: player
|
|
1477
|
+
} = playerRef;
|
|
1378
1478
|
return player !== null ? player.setVolume(0) : Promise.reject(NO_PLAYER_ERROR);
|
|
1379
1479
|
}, []);
|
|
1380
|
-
|
|
1381
|
-
|
|
1480
|
+
const unmute = react.useCallback(() => {
|
|
1481
|
+
const {
|
|
1482
|
+
current: player
|
|
1483
|
+
} = playerRef;
|
|
1382
1484
|
return player !== null ? player.setVolume(1) : Promise.reject(NO_PLAYER_ERROR);
|
|
1383
1485
|
}, []);
|
|
1384
|
-
|
|
1385
|
-
|
|
1486
|
+
const seek = react.useCallback(time => {
|
|
1487
|
+
const {
|
|
1488
|
+
current: player
|
|
1489
|
+
} = playerRef;
|
|
1386
1490
|
return player !== null ? player.setCurrentTime(time) : Promise.reject(NO_PLAYER_ERROR);
|
|
1387
1491
|
}, []);
|
|
1388
|
-
|
|
1389
|
-
|
|
1492
|
+
const setLoop = react.useCallback(loop => {
|
|
1493
|
+
const {
|
|
1494
|
+
current: player
|
|
1495
|
+
} = playerRef;
|
|
1390
1496
|
return player !== null ? player.setLoop(loop) : Promise.reject(NO_PLAYER_ERROR);
|
|
1391
1497
|
}, []);
|
|
1392
|
-
|
|
1393
|
-
|
|
1498
|
+
const destroyVideo = react.useCallback(() => {
|
|
1499
|
+
const {
|
|
1500
|
+
current: player
|
|
1501
|
+
} = playerRef;
|
|
1394
1502
|
|
|
1395
1503
|
if (player !== null) {
|
|
1396
1504
|
debug('Unload video');
|
|
@@ -1402,8 +1510,10 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1402
1510
|
playerRef.current = null;
|
|
1403
1511
|
}
|
|
1404
1512
|
}, []);
|
|
1405
|
-
react.useEffect(
|
|
1406
|
-
|
|
1513
|
+
react.useEffect(() => {
|
|
1514
|
+
const {
|
|
1515
|
+
current: currentPlayer
|
|
1516
|
+
} = playerRef;
|
|
1407
1517
|
|
|
1408
1518
|
if (playerElementRef.current !== elementRef.current && currentPlayer !== null) {
|
|
1409
1519
|
debug('iFrame switched');
|
|
@@ -1411,40 +1521,41 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1411
1521
|
}
|
|
1412
1522
|
}, [elementHasChanged]); // Create player
|
|
1413
1523
|
|
|
1414
|
-
react.useEffect(
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1524
|
+
react.useEffect(() => {
|
|
1525
|
+
const {
|
|
1526
|
+
current: Player = null
|
|
1527
|
+
} = apiRef;
|
|
1528
|
+
const {
|
|
1529
|
+
current: currentPlayer = null
|
|
1530
|
+
} = playerRef;
|
|
1531
|
+
const {
|
|
1532
|
+
current: element = null
|
|
1533
|
+
} = elementRef;
|
|
1421
1534
|
|
|
1422
1535
|
if (!apiLoaded || videoId === null || element === null) {
|
|
1423
1536
|
destroyVideo();
|
|
1424
1537
|
return;
|
|
1425
1538
|
}
|
|
1426
1539
|
|
|
1427
|
-
|
|
1540
|
+
let player = currentPlayer;
|
|
1428
1541
|
|
|
1429
1542
|
if (player === null) {
|
|
1430
1543
|
debug('Create player [ID: %s]', videoId);
|
|
1431
1544
|
player = new Player(element, {
|
|
1432
1545
|
id: videoId,
|
|
1433
|
-
autoplay
|
|
1434
|
-
autopause
|
|
1435
|
-
byline
|
|
1436
|
-
controls
|
|
1546
|
+
autoplay,
|
|
1547
|
+
autopause,
|
|
1548
|
+
byline,
|
|
1549
|
+
controls,
|
|
1437
1550
|
muted: initialMuted,
|
|
1438
1551
|
background: !controls
|
|
1439
1552
|
});
|
|
1440
|
-
player.ready().then(
|
|
1441
|
-
return setReady(true);
|
|
1442
|
-
}).catch(function (e) {
|
|
1553
|
+
player.ready().then(() => setReady(true)).catch(e => {
|
|
1443
1554
|
debug('ERROR: %o', e);
|
|
1444
1555
|
});
|
|
1445
1556
|
} else {
|
|
1446
1557
|
debug('Load video [ID: %s]', videoId);
|
|
1447
|
-
player.loadVideo(videoId).catch(
|
|
1558
|
+
player.loadVideo(videoId).catch(e => {
|
|
1448
1559
|
debug('ERROR: %o', e);
|
|
1449
1560
|
});
|
|
1450
1561
|
}
|
|
@@ -1453,28 +1564,26 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1453
1564
|
playerElementRef.current = element;
|
|
1454
1565
|
}, [apiLoaded, videoId, elementHasChanged, setReady, destroyVideo, setLoaded]); // Bind player events
|
|
1455
1566
|
|
|
1456
|
-
react.useEffect(
|
|
1457
|
-
|
|
1567
|
+
react.useEffect(() => {
|
|
1568
|
+
const {
|
|
1569
|
+
current: player
|
|
1570
|
+
} = playerRef;
|
|
1458
1571
|
|
|
1459
1572
|
if (player === null) {
|
|
1460
|
-
return
|
|
1573
|
+
return () => {};
|
|
1461
1574
|
}
|
|
1462
1575
|
|
|
1463
|
-
|
|
1576
|
+
let canceled = false;
|
|
1464
1577
|
|
|
1465
|
-
|
|
1466
|
-
Promise.all([player.getDuration(), player.getVideoWidth(), player.getVideoHeight(), player.getMuted()]).then(
|
|
1467
|
-
|
|
1468
|
-
newDuration = _ref3[0],
|
|
1469
|
-
newWidth = _ref3[1],
|
|
1470
|
-
newHeight = _ref3[2],
|
|
1471
|
-
newMuted = _ref3[3];
|
|
1578
|
+
const onLoaded = () => {
|
|
1579
|
+
Promise.all([player.getDuration(), player.getVideoWidth(), player.getVideoHeight(), player.getMuted()]).then(_ref => {
|
|
1580
|
+
let [newDuration, newWidth, newHeight, newMuted] = _ref;
|
|
1472
1581
|
|
|
1473
1582
|
if (canceled) {
|
|
1474
1583
|
return;
|
|
1475
1584
|
}
|
|
1476
1585
|
|
|
1477
|
-
|
|
1586
|
+
const newMetadata = {
|
|
1478
1587
|
duration: newDuration,
|
|
1479
1588
|
width: newWidth,
|
|
1480
1589
|
height: newHeight
|
|
@@ -1490,7 +1599,7 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1490
1599
|
debug('onLoaded [ID: %s]', videoId);
|
|
1491
1600
|
};
|
|
1492
1601
|
|
|
1493
|
-
|
|
1602
|
+
const onPlay = () => {
|
|
1494
1603
|
setPlayState({
|
|
1495
1604
|
playing: true,
|
|
1496
1605
|
paused: false,
|
|
@@ -1498,14 +1607,14 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1498
1607
|
buffering: false
|
|
1499
1608
|
});
|
|
1500
1609
|
debug('onPlay [ID: %s]', videoId);
|
|
1501
|
-
player.getMuted().then(
|
|
1610
|
+
player.getMuted().then(newMuted => {
|
|
1502
1611
|
if (!canceled && newMuted) {
|
|
1503
1612
|
setVolumeState(0);
|
|
1504
1613
|
}
|
|
1505
|
-
}).catch(
|
|
1614
|
+
}).catch(() => {});
|
|
1506
1615
|
};
|
|
1507
1616
|
|
|
1508
|
-
|
|
1617
|
+
const onPause = () => {
|
|
1509
1618
|
setPlayState({
|
|
1510
1619
|
playing: false,
|
|
1511
1620
|
paused: true,
|
|
@@ -1515,13 +1624,15 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1515
1624
|
debug('onPause [ID: %s]', videoId);
|
|
1516
1625
|
};
|
|
1517
1626
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1627
|
+
const onVolumeChange = _ref2 => {
|
|
1628
|
+
let {
|
|
1629
|
+
volume: newVolume
|
|
1630
|
+
} = _ref2;
|
|
1520
1631
|
setVolumeState(newVolume);
|
|
1521
1632
|
debug('onVolumeChange [ID: %s]', videoId);
|
|
1522
1633
|
};
|
|
1523
1634
|
|
|
1524
|
-
|
|
1635
|
+
const onEnded = () => {
|
|
1525
1636
|
setPlayState({
|
|
1526
1637
|
playing: false,
|
|
1527
1638
|
paused: false,
|
|
@@ -1531,7 +1642,7 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1531
1642
|
debug('onEnded [ID: %s]', videoId);
|
|
1532
1643
|
};
|
|
1533
1644
|
|
|
1534
|
-
|
|
1645
|
+
const onBufferStart = () => {
|
|
1535
1646
|
setPlayState({
|
|
1536
1647
|
playing: true,
|
|
1537
1648
|
paused: false,
|
|
@@ -1541,7 +1652,7 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1541
1652
|
debug('onBufferStart [ID: %s]', videoId);
|
|
1542
1653
|
};
|
|
1543
1654
|
|
|
1544
|
-
|
|
1655
|
+
const onBufferEnded = () => {
|
|
1545
1656
|
setPlayState({
|
|
1546
1657
|
playing: true,
|
|
1547
1658
|
paused: false,
|
|
@@ -1559,7 +1670,7 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1559
1670
|
player.on('ended', onEnded);
|
|
1560
1671
|
player.on('bufferstart', onBufferStart);
|
|
1561
1672
|
player.on('bufferend', onBufferEnded);
|
|
1562
|
-
return
|
|
1673
|
+
return () => {
|
|
1563
1674
|
canceled = true;
|
|
1564
1675
|
debug('Unbind events [ID: %s]', videoId);
|
|
1565
1676
|
player.off('loaded', onLoaded);
|
|
@@ -1571,63 +1682,55 @@ var useVimeoPlayer = function useVimeoPlayer(id) {
|
|
|
1571
1682
|
player.off('bufferend', onBufferEnded);
|
|
1572
1683
|
};
|
|
1573
1684
|
}, [videoId, playerRef.current, setPlayState, setMetadata, setVolumeState, setLoaded]);
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1685
|
+
const {
|
|
1686
|
+
playing
|
|
1687
|
+
} = playState;
|
|
1688
|
+
const getCurrentTime = react.useCallback(p => p.getCurrentTime(), []);
|
|
1689
|
+
const currentTime = usePlayerCurrentTime(playerRef.current, {
|
|
1579
1690
|
id: videoId,
|
|
1580
1691
|
disabled: !playing || timeUpdateInterval === null,
|
|
1581
1692
|
updateInterval: timeUpdateInterval,
|
|
1582
1693
|
onUpdate: customOnTimeUpdate,
|
|
1583
|
-
getCurrentTime
|
|
1694
|
+
getCurrentTime
|
|
1584
1695
|
});
|
|
1585
|
-
return
|
|
1696
|
+
return {
|
|
1586
1697
|
ref: elementRef,
|
|
1587
1698
|
player: playerRef.current,
|
|
1588
|
-
play
|
|
1589
|
-
pause
|
|
1590
|
-
mute
|
|
1591
|
-
unmute
|
|
1592
|
-
setVolume
|
|
1593
|
-
seek
|
|
1594
|
-
setLoop
|
|
1595
|
-
ready
|
|
1596
|
-
currentTime
|
|
1597
|
-
loaded
|
|
1699
|
+
play,
|
|
1700
|
+
pause,
|
|
1701
|
+
mute,
|
|
1702
|
+
unmute,
|
|
1703
|
+
setVolume,
|
|
1704
|
+
seek,
|
|
1705
|
+
setLoop,
|
|
1706
|
+
ready,
|
|
1707
|
+
currentTime,
|
|
1708
|
+
loaded,
|
|
1598
1709
|
muted: volume === 0,
|
|
1599
|
-
volume
|
|
1600
|
-
|
|
1710
|
+
volume,
|
|
1711
|
+
...metadata,
|
|
1712
|
+
...playState
|
|
1713
|
+
};
|
|
1601
1714
|
};
|
|
1602
1715
|
|
|
1603
1716
|
function useVideoPlayer(params) {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
_ref$onBufferStart = _ref.onBufferStart,
|
|
1622
|
-
customOnBufferStart = _ref$onBufferStart === void 0 ? null : _ref$onBufferStart,
|
|
1623
|
-
_ref$onBufferEnded = _ref.onBufferEnded,
|
|
1624
|
-
customOnBufferEnded = _ref$onBufferEnded === void 0 ? null : _ref$onBufferEnded;
|
|
1625
|
-
|
|
1626
|
-
var dailymotionPlayer = useDailymotionPlayer(service === 'dailymotion' ? videoId || url : null, params);
|
|
1627
|
-
var youtubePlayer = useYouTubePlayer(service === 'youtube' ? videoId || url : null, params);
|
|
1628
|
-
var vimeoPlayer = useVimeoPlayer(service === 'vimeo' ? videoId || url : null, params);
|
|
1629
|
-
var nativePlayer = useNativeVideoPlayer(url, params);
|
|
1630
|
-
var player = null;
|
|
1717
|
+
const {
|
|
1718
|
+
service = null,
|
|
1719
|
+
videoId = null,
|
|
1720
|
+
url = null,
|
|
1721
|
+
onLoaded: customOnLoaded = null,
|
|
1722
|
+
onPlay: customOnPlay = null,
|
|
1723
|
+
onPause: customOnPause = null,
|
|
1724
|
+
onEnd: customOnEnd = null,
|
|
1725
|
+
onMetadataChange: customOnMetadataChange = null,
|
|
1726
|
+
onBufferStart: customOnBufferStart = null,
|
|
1727
|
+
onBufferEnded: customOnBufferEnded = null
|
|
1728
|
+
} = params || {};
|
|
1729
|
+
const dailymotionPlayer = useDailymotionPlayer(service === 'dailymotion' ? videoId || url : null, params);
|
|
1730
|
+
const youtubePlayer = useYouTubePlayer(service === 'youtube' ? videoId || url : null, params);
|
|
1731
|
+
const vimeoPlayer = useVimeoPlayer(service === 'vimeo' ? videoId || url : null, params);
|
|
1732
|
+
const nativePlayer = useNativeVideoPlayer(url, params);
|
|
1733
|
+
let player = null;
|
|
1631
1734
|
|
|
1632
1735
|
if (service === 'dailymotion') {
|
|
1633
1736
|
player = dailymotionPlayer;
|
|
@@ -1639,53 +1742,45 @@ function useVideoPlayer(params) {
|
|
|
1639
1742
|
player = nativePlayer;
|
|
1640
1743
|
}
|
|
1641
1744
|
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
_ref2$width = _ref2.width,
|
|
1654
|
-
metaWidth = _ref2$width === void 0 ? null : _ref2$width,
|
|
1655
|
-
_ref2$height = _ref2.height,
|
|
1656
|
-
metaHeight = _ref2$height === void 0 ? null : _ref2$height,
|
|
1657
|
-
_ref2$duration = _ref2.duration,
|
|
1658
|
-
metaDuration = _ref2$duration === void 0 ? null : _ref2$duration;
|
|
1659
|
-
|
|
1660
|
-
react.useEffect(function () {
|
|
1745
|
+
const {
|
|
1746
|
+
playing = false,
|
|
1747
|
+
paused = false,
|
|
1748
|
+
buffering = false,
|
|
1749
|
+
ended = false,
|
|
1750
|
+
ready = false,
|
|
1751
|
+
width: metaWidth = null,
|
|
1752
|
+
height: metaHeight = null,
|
|
1753
|
+
duration: metaDuration = null
|
|
1754
|
+
} = player || {};
|
|
1755
|
+
react.useEffect(() => {
|
|
1661
1756
|
if (ready && customOnLoaded !== null) {
|
|
1662
1757
|
customOnLoaded();
|
|
1663
1758
|
}
|
|
1664
1759
|
}, [ready, customOnLoaded]);
|
|
1665
|
-
react.useEffect(
|
|
1760
|
+
react.useEffect(() => {
|
|
1666
1761
|
if (playing && customOnPlay !== null) {
|
|
1667
1762
|
customOnPlay();
|
|
1668
1763
|
}
|
|
1669
1764
|
}, [playing, customOnPlay]);
|
|
1670
|
-
react.useEffect(
|
|
1765
|
+
react.useEffect(() => {
|
|
1671
1766
|
if (paused && customOnPause !== null) {
|
|
1672
1767
|
customOnPause();
|
|
1673
1768
|
}
|
|
1674
1769
|
}, [paused, customOnPause]);
|
|
1675
|
-
react.useEffect(
|
|
1770
|
+
react.useEffect(() => {
|
|
1676
1771
|
if (buffering && customOnBufferStart !== null) {
|
|
1677
1772
|
customOnBufferStart();
|
|
1678
1773
|
} else if (!buffering && customOnBufferEnded !== null) {
|
|
1679
1774
|
customOnBufferEnded();
|
|
1680
1775
|
}
|
|
1681
1776
|
}, [buffering, customOnBufferStart, customOnBufferEnded]);
|
|
1682
|
-
react.useEffect(
|
|
1777
|
+
react.useEffect(() => {
|
|
1683
1778
|
if (ended && customOnEnd !== null) {
|
|
1684
1779
|
customOnEnd();
|
|
1685
1780
|
}
|
|
1686
1781
|
}, [ended, customOnEnd]);
|
|
1687
|
-
react.useEffect(
|
|
1688
|
-
|
|
1782
|
+
react.useEffect(() => {
|
|
1783
|
+
const hasMetadata = metaWidth !== null || metaHeight !== null || metaDuration !== null;
|
|
1689
1784
|
|
|
1690
1785
|
if (hasMetadata && customOnMetadataChange !== null) {
|
|
1691
1786
|
customOnMetadataChange({
|
|
@@ -1698,27 +1793,21 @@ function useVideoPlayer(params) {
|
|
|
1698
1793
|
return player;
|
|
1699
1794
|
}
|
|
1700
1795
|
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
};
|
|
1706
|
-
};
|
|
1707
|
-
|
|
1708
|
-
var currentScroll = getWindowScroll();
|
|
1796
|
+
const getWindowScroll = () => ({
|
|
1797
|
+
x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
|
|
1798
|
+
y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
|
|
1799
|
+
});
|
|
1709
1800
|
|
|
1710
|
-
|
|
1711
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1712
|
-
var _opts$onChange = opts.onChange,
|
|
1713
|
-
onChange = _opts$onChange === void 0 ? null : _opts$onChange;
|
|
1801
|
+
const currentScroll = getWindowScroll();
|
|
1714
1802
|
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1803
|
+
const useWindowScroll = function () {
|
|
1804
|
+
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1805
|
+
const {
|
|
1806
|
+
onChange = null
|
|
1807
|
+
} = opts;
|
|
1808
|
+
const [scroll, setScroll] = react.useState(currentScroll);
|
|
1809
|
+
const updateScroll = react.useCallback(() => {
|
|
1810
|
+
const newScroll = getWindowScroll();
|
|
1722
1811
|
|
|
1723
1812
|
if (currentScroll.x !== newScroll.x || currentScroll.y !== newScroll.y) {
|
|
1724
1813
|
currentScroll.x = newScroll.x;
|
|
@@ -1729,40 +1818,33 @@ var useWindowScroll = function useWindowScroll() {
|
|
|
1729
1818
|
|
|
1730
1819
|
return null;
|
|
1731
1820
|
}, [setScroll]);
|
|
1732
|
-
|
|
1733
|
-
|
|
1821
|
+
const onScroll = react.useCallback(() => {
|
|
1822
|
+
const newScroll = updateScroll();
|
|
1734
1823
|
|
|
1735
1824
|
if (newScroll !== null && onChange !== null) {
|
|
1736
1825
|
onChange(newScroll);
|
|
1737
1826
|
}
|
|
1738
1827
|
}, [updateScroll, onChange]);
|
|
1739
1828
|
useWindowEvent('scroll', onScroll);
|
|
1740
|
-
react.useEffect(
|
|
1829
|
+
react.useEffect(() => {
|
|
1741
1830
|
onScroll();
|
|
1742
1831
|
}, []);
|
|
1743
1832
|
return scroll;
|
|
1744
1833
|
};
|
|
1745
1834
|
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
};
|
|
1752
|
-
var currentSize = getWindowSize();
|
|
1835
|
+
const getWindowSize = () => ({
|
|
1836
|
+
width: typeof window !== 'undefined' ? window.innerWidth || 0 : 0,
|
|
1837
|
+
height: typeof window !== 'undefined' ? window.innerHeight || 0 : 0
|
|
1838
|
+
});
|
|
1839
|
+
let currentSize = getWindowSize();
|
|
1753
1840
|
|
|
1754
1841
|
function useWindowSize() {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
size = _useState2[0],
|
|
1762
|
-
setSize = _useState2[1];
|
|
1763
|
-
|
|
1764
|
-
var updateSize = react.useCallback(function () {
|
|
1765
|
-
var newSize = getWindowSize();
|
|
1842
|
+
let {
|
|
1843
|
+
onChange = null
|
|
1844
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1845
|
+
const [size, setSize] = react.useState(currentSize);
|
|
1846
|
+
const updateSize = react.useCallback(() => {
|
|
1847
|
+
const newSize = getWindowSize();
|
|
1766
1848
|
|
|
1767
1849
|
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
|
|
1768
1850
|
currentSize = newSize;
|
|
@@ -1772,15 +1854,15 @@ function useWindowSize() {
|
|
|
1772
1854
|
|
|
1773
1855
|
return null;
|
|
1774
1856
|
}, [setSize]);
|
|
1775
|
-
|
|
1776
|
-
|
|
1857
|
+
const onResize = react.useCallback(() => {
|
|
1858
|
+
const newSize = updateSize();
|
|
1777
1859
|
|
|
1778
1860
|
if (newSize !== null && onChange !== null) {
|
|
1779
1861
|
onChange(newSize);
|
|
1780
1862
|
}
|
|
1781
1863
|
}, [onChange]);
|
|
1782
1864
|
useWindowEvent('resize', onResize);
|
|
1783
|
-
react.useEffect(
|
|
1865
|
+
react.useEffect(() => {
|
|
1784
1866
|
onResize();
|
|
1785
1867
|
}, []);
|
|
1786
1868
|
return size;
|
|
@@ -1792,6 +1874,7 @@ exports.useCounter = useCounter;
|
|
|
1792
1874
|
exports.useDailymotionPlayer = useDailymotionPlayer;
|
|
1793
1875
|
exports.useDocumentEvent = useDocumentEvent;
|
|
1794
1876
|
exports.useIntersectionObserver = useIntersectionObserver;
|
|
1877
|
+
exports.useItemsPaginated = useItemsPaginated;
|
|
1795
1878
|
exports.useKeyboard = useKeyboard;
|
|
1796
1879
|
exports.useNativeVideoPlayer = useNativeVideoPlayer;
|
|
1797
1880
|
exports.useObserver = useObserver;
|