@panneau/core 3.0.145 → 3.0.146
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/contexts.js +1143 -0
- package/es/hooks.js +1224 -0
- package/es/utils.js +488 -0
- package/lib/contexts.js +1593 -0
- package/lib/hooks.js +1245 -0
- package/lib/index.js +1018 -0
- package/lib/utils.js +688 -0
- package/package.json +2 -2
package/es/hooks.js
ADDED
|
@@ -0,0 +1,1224 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback, useState, useMemo } from 'react';
|
|
2
|
+
import { EventsManager, MediasParser } from '@panneau/core';
|
|
3
|
+
import { createUseEvent, loadPackage } from '@panneau/core/utils';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
7
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
8
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
9
|
+
import { getCsrfToken, postJSON, getCSRFHeaders } from '@folklore/fetch';
|
|
10
|
+
import get from 'lodash/get';
|
|
11
|
+
import isArray from 'lodash/isArray';
|
|
12
|
+
import isObject from 'lodash/isObject';
|
|
13
|
+
import isString from 'lodash/isString';
|
|
14
|
+
import { useFieldsManager, usePanneauResources, useResource, useUrlGenerator } from '@panneau/core/contexts';
|
|
15
|
+
import uniqBy from 'lodash/uniqBy';
|
|
16
|
+
import { useIntl } from 'react-intl';
|
|
17
|
+
import dayjs from 'dayjs';
|
|
18
|
+
import { match } from 'css-mediaquery';
|
|
19
|
+
|
|
20
|
+
var useAnimationFrame = function useAnimationFrame(onFrame) {
|
|
21
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
22
|
+
_ref$disabled = _ref.disabled,
|
|
23
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
24
|
+
var requestRef = useRef(null);
|
|
25
|
+
var startTimeRef = useRef(null);
|
|
26
|
+
var callback = function callback(time) {
|
|
27
|
+
if (!startTimeRef.current) {
|
|
28
|
+
startTimeRef.current = time;
|
|
29
|
+
}
|
|
30
|
+
var progress = time - startTimeRef.current;
|
|
31
|
+
onFrame(progress);
|
|
32
|
+
requestRef.current = requestAnimationFrame(callback);
|
|
33
|
+
};
|
|
34
|
+
useEffect(function () {
|
|
35
|
+
if (!disabled) {
|
|
36
|
+
requestRef.current = requestAnimationFrame(callback);
|
|
37
|
+
}
|
|
38
|
+
return function () {
|
|
39
|
+
if (requestRef.current !== null) {
|
|
40
|
+
cancelAnimationFrame(requestRef.current);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}, [disabled]);
|
|
44
|
+
};
|
|
45
|
+
var useAnimationFrame$1 = useAnimationFrame;
|
|
46
|
+
|
|
47
|
+
var useFormattedDate = function useFormattedDate() {
|
|
48
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
49
|
+
_ref$format = _ref.format,
|
|
50
|
+
format = _ref$format === void 0 ? null : _ref$format,
|
|
51
|
+
_ref$showToday = _ref.showToday,
|
|
52
|
+
showToday = _ref$showToday === void 0 ? true : _ref$showToday;
|
|
53
|
+
var intl = useIntl();
|
|
54
|
+
var today = dayjs();
|
|
55
|
+
return useCallback(function (date) {
|
|
56
|
+
var dateToFormat = isString(date) ? dayjs(date) : date;
|
|
57
|
+
if (showToday && dateToFormat.format('YYYY-MM-DD') === today.format('YYYY-MM-DD')) {
|
|
58
|
+
return intl.formatMessage({
|
|
59
|
+
"id": "v4Qtl9",
|
|
60
|
+
"defaultMessage": [{
|
|
61
|
+
"type": 0,
|
|
62
|
+
"value": "Today"
|
|
63
|
+
}]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return intl.formatDate(dayjs(date).toDate(), _objectSpread({
|
|
67
|
+
year: 'numeric',
|
|
68
|
+
month: 'long',
|
|
69
|
+
day: '2-digit'
|
|
70
|
+
}, format));
|
|
71
|
+
}, [today, showToday, format]);
|
|
72
|
+
};
|
|
73
|
+
var useFormattedTime = function useFormattedTime() {
|
|
74
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
75
|
+
_ref2$format = _ref2.format,
|
|
76
|
+
format = _ref2$format === void 0 ? null : _ref2$format,
|
|
77
|
+
_ref2$showNow = _ref2.showNow,
|
|
78
|
+
showNow = _ref2$showNow === void 0 ? true : _ref2$showNow,
|
|
79
|
+
_ref2$timeGap = _ref2.timeGap,
|
|
80
|
+
timeGap = _ref2$timeGap === void 0 ? 2 : _ref2$timeGap;
|
|
81
|
+
var intl = useIntl();
|
|
82
|
+
var now = dayjs();
|
|
83
|
+
return useCallback(function (date) {
|
|
84
|
+
var dateToFormat = isString(date) ? dayjs(date) : date;
|
|
85
|
+
if (showNow && dateToFormat.format('YYYY-MM-DD') === now.format('YYYY-MM-DD') && dateToFormat.hour() === now.hour() && dateToFormat.minute() > now.minute() - timeGap && dateToFormat.minute() < now.minute() + timeGap) {
|
|
86
|
+
return intl.formatMessage({
|
|
87
|
+
"id": "3na7F8",
|
|
88
|
+
"defaultMessage": [{
|
|
89
|
+
"type": 0,
|
|
90
|
+
"value": "Now"
|
|
91
|
+
}]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return intl.formatTime(dateToFormat.toDate(), _objectSpread({
|
|
95
|
+
hour: 'numeric',
|
|
96
|
+
minute: 'numeric'
|
|
97
|
+
}, format));
|
|
98
|
+
}, [now, showNow, timeGap, format]);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(document) : null;
|
|
102
|
+
var useDocumentEvent = createUseEvent(eventsManager$1);
|
|
103
|
+
var useDocumentEvent$1 = useDocumentEvent;
|
|
104
|
+
|
|
105
|
+
var _excluded$1 = ["value", "errors", "onChange"];
|
|
106
|
+
|
|
107
|
+
// prettier-ignore
|
|
108
|
+
var getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref) {
|
|
109
|
+
var value = _ref.value,
|
|
110
|
+
errors = _ref.errors,
|
|
111
|
+
_onChange = _ref.onChange,
|
|
112
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
113
|
+
var locales = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
114
|
+
return fields.reduce(function (allFields, field) {
|
|
115
|
+
var _ref2 = isObject(field) ? field : {},
|
|
116
|
+
_ref2$name = _ref2.name,
|
|
117
|
+
name = _ref2$name === void 0 ? isString(field) ? field : null : _ref2$name,
|
|
118
|
+
_ref2$component = _ref2.component,
|
|
119
|
+
component = _ref2$component === void 0 ? null : _ref2$component;
|
|
120
|
+
var fieldErrors = errors !== null ? errors[name] || [] : [];
|
|
121
|
+
var localizedErrors = component === 'localized' ? (locales || []).reduce(function (previousErrors, locale) {
|
|
122
|
+
var items = errors !== null ? get(errors, "".concat(name, ".").concat(locale), []) || [] : [];
|
|
123
|
+
var finalItems = isArray(items) ? items : [items];
|
|
124
|
+
var finalPrevious = isArray(previousErrors) ? previousErrors : [];
|
|
125
|
+
return [].concat(_toConsumableArray(finalPrevious), _toConsumableArray(finalItems));
|
|
126
|
+
}, fieldErrors) : fieldErrors;
|
|
127
|
+
return [].concat(_toConsumableArray(allFields), [_objectSpread(_objectSpread({}, isObject(field) ? field : null), {}, {
|
|
128
|
+
name: name,
|
|
129
|
+
component: component,
|
|
130
|
+
value: value !== null ? value[name] || null : null,
|
|
131
|
+
errors: localizedErrors.length > 0 ? localizedErrors : null,
|
|
132
|
+
onChange: function onChange(fieldValue) {
|
|
133
|
+
return _onChange(name, fieldValue);
|
|
134
|
+
}
|
|
135
|
+
}, props)]);
|
|
136
|
+
}, []);
|
|
137
|
+
};
|
|
138
|
+
var useForm = function useForm() {
|
|
139
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
140
|
+
var _opts$fields = opts.fields,
|
|
141
|
+
fields = _opts$fields === void 0 ? [] : _opts$fields,
|
|
142
|
+
_opts$action = opts.action,
|
|
143
|
+
action = _opts$action === void 0 ? null : _opts$action,
|
|
144
|
+
_opts$postForm = opts.postForm,
|
|
145
|
+
postForm = _opts$postForm === void 0 ? null : _opts$postForm,
|
|
146
|
+
_opts$initialErrors = opts.initialErrors,
|
|
147
|
+
initialErrors = _opts$initialErrors === void 0 ? null : _opts$initialErrors,
|
|
148
|
+
_opts$errors = opts.errors,
|
|
149
|
+
providedErrors = _opts$errors === void 0 ? null : _opts$errors,
|
|
150
|
+
_opts$setErrors = opts.setErrors,
|
|
151
|
+
setProvidedErrors = _opts$setErrors === void 0 ? null : _opts$setErrors,
|
|
152
|
+
_opts$initialGeneralE = opts.initialGeneralError,
|
|
153
|
+
initialGeneralError = _opts$initialGeneralE === void 0 ? null : _opts$initialGeneralE,
|
|
154
|
+
_opts$generalError = opts.generalError,
|
|
155
|
+
providedGeneralError = _opts$generalError === void 0 ? null : _opts$generalError,
|
|
156
|
+
_opts$setGeneralError = opts.setGeneralError,
|
|
157
|
+
setProvidedGeneralError = _opts$setGeneralError === void 0 ? null : _opts$setGeneralError,
|
|
158
|
+
_opts$initialValue = opts.initialValue,
|
|
159
|
+
initialValue = _opts$initialValue === void 0 ? null : _opts$initialValue,
|
|
160
|
+
_opts$value = opts.value,
|
|
161
|
+
providedValue = _opts$value === void 0 ? null : _opts$value,
|
|
162
|
+
_opts$setValue = opts.setValue,
|
|
163
|
+
setProvidedValue = _opts$setValue === void 0 ? null : _opts$setValue,
|
|
164
|
+
_opts$withoutDefault = opts.withoutDefault,
|
|
165
|
+
withoutDefault = _opts$withoutDefault === void 0 ? true : _opts$withoutDefault,
|
|
166
|
+
_opts$withoutPropagat = opts.withoutPropagation,
|
|
167
|
+
withoutPropagation = _opts$withoutPropagat === void 0 ? true : _opts$withoutPropagat,
|
|
168
|
+
_opts$onComplete = opts.onComplete,
|
|
169
|
+
onComplete = _opts$onComplete === void 0 ? null : _opts$onComplete,
|
|
170
|
+
_opts$onError = opts.onError,
|
|
171
|
+
onError = _opts$onError === void 0 ? null : _opts$onError,
|
|
172
|
+
_opts$locales = opts.locales,
|
|
173
|
+
locales = _opts$locales === void 0 ? [] : _opts$locales;
|
|
174
|
+
var _useState = useState(initialValue || providedValue),
|
|
175
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
176
|
+
stateValue = _useState2[0],
|
|
177
|
+
setStateValue = _useState2[1];
|
|
178
|
+
var _useState3 = useState(initialErrors || providedErrors),
|
|
179
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
180
|
+
stateErrors = _useState4[0],
|
|
181
|
+
setStateErrors = _useState4[1];
|
|
182
|
+
var _useState5 = useState(initialGeneralError || providedGeneralError),
|
|
183
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
184
|
+
stateGeneralError = _useState6[0],
|
|
185
|
+
setStateGeneralError = _useState6[1];
|
|
186
|
+
var _useState7 = useState({
|
|
187
|
+
success: false,
|
|
188
|
+
loading: false,
|
|
189
|
+
error: false
|
|
190
|
+
}),
|
|
191
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
192
|
+
requestState = _useState8[0],
|
|
193
|
+
setRequestState = _useState8[1];
|
|
194
|
+
var _useState9 = useState(null),
|
|
195
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
196
|
+
response = _useState10[0],
|
|
197
|
+
setResponse = _useState10[1];
|
|
198
|
+
var hasProvidedValue = setProvidedValue !== null;
|
|
199
|
+
var value = hasProvidedValue ? providedValue : stateValue;
|
|
200
|
+
var setValue = hasProvidedValue ? setProvidedValue : setStateValue;
|
|
201
|
+
var hasProvidedErrors = setProvidedErrors !== null;
|
|
202
|
+
var errors = hasProvidedErrors ? providedErrors : stateErrors;
|
|
203
|
+
var setErrors = hasProvidedErrors ? setProvidedErrors : setStateErrors;
|
|
204
|
+
var hasProvidedGeneralError = setProvidedGeneralError !== null;
|
|
205
|
+
var generalError = hasProvidedGeneralError ? providedGeneralError : stateGeneralError;
|
|
206
|
+
var setGeneralError = hasProvidedGeneralError ? setProvidedGeneralError : setStateGeneralError;
|
|
207
|
+
var fieldsKey = [value, errors, requestState, locales].concat(fields);
|
|
208
|
+
var onFieldChange = useCallback(function (fieldName, fieldValue) {
|
|
209
|
+
var _ref3 = requestState || {},
|
|
210
|
+
_ref3$loading = _ref3.loading,
|
|
211
|
+
loading = _ref3$loading === void 0 ? false : _ref3$loading,
|
|
212
|
+
_ref3$success = _ref3.success,
|
|
213
|
+
success = _ref3$success === void 0 ? false : _ref3$success,
|
|
214
|
+
_ref3$error = _ref3.error,
|
|
215
|
+
error = _ref3$error === void 0 ? false : _ref3$error;
|
|
216
|
+
var fieldErrors = errors !== null ? errors[fieldName] || null : null;
|
|
217
|
+
if (fieldErrors !== null) {
|
|
218
|
+
setErrors(_objectSpread(_objectSpread({}, errors), {}, _defineProperty({}, fieldName, null)));
|
|
219
|
+
}
|
|
220
|
+
if (!loading && (success !== false || error !== false)) {
|
|
221
|
+
setRequestState({
|
|
222
|
+
success: false,
|
|
223
|
+
loading: false,
|
|
224
|
+
error: false
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
setValue(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, fieldName, fieldValue)));
|
|
228
|
+
}, fieldsKey);
|
|
229
|
+
var fieldsProps = useMemo(function () {
|
|
230
|
+
return getFieldsPropsFromFields(fields, {
|
|
231
|
+
value: value,
|
|
232
|
+
errors: errors,
|
|
233
|
+
onChange: onFieldChange
|
|
234
|
+
}, locales);
|
|
235
|
+
}, fieldsKey);
|
|
236
|
+
var csrfToken = useMemo(function () {
|
|
237
|
+
return getCsrfToken();
|
|
238
|
+
}, []);
|
|
239
|
+
var onSubmitError = function onSubmitError(error) {
|
|
240
|
+
setRequestState({
|
|
241
|
+
success: false,
|
|
242
|
+
loading: false,
|
|
243
|
+
error: true
|
|
244
|
+
});
|
|
245
|
+
if (error.name === 'ValidationError') {
|
|
246
|
+
var _error$getResponseDat = error.getResponseData(),
|
|
247
|
+
_error$getResponseDat2 = _error$getResponseDat.errors,
|
|
248
|
+
validationErrors = _error$getResponseDat2 === void 0 ? null : _error$getResponseDat2;
|
|
249
|
+
setErrors(validationErrors);
|
|
250
|
+
} else {
|
|
251
|
+
setGeneralError(error.message);
|
|
252
|
+
}
|
|
253
|
+
if (onError !== null) {
|
|
254
|
+
onError(error);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var onSubmitSuccess = function onSubmitSuccess(resp) {
|
|
258
|
+
setRequestState({
|
|
259
|
+
success: true,
|
|
260
|
+
loading: false,
|
|
261
|
+
error: false
|
|
262
|
+
});
|
|
263
|
+
setResponse(resp);
|
|
264
|
+
if (onComplete !== null) {
|
|
265
|
+
onComplete(resp);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var finalPostForm = useCallback(function (postAction, postData) {
|
|
269
|
+
return postForm !== null ? postForm(postAction, postData) : postJSON(postAction, postData, {
|
|
270
|
+
credentials: 'include',
|
|
271
|
+
headers: getCSRFHeaders()
|
|
272
|
+
});
|
|
273
|
+
}, [postForm, postJSON, getCSRFHeaders]);
|
|
274
|
+
var submit = useCallback(function () {
|
|
275
|
+
var submitValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : value;
|
|
276
|
+
setRequestState({
|
|
277
|
+
success: false,
|
|
278
|
+
loading: true,
|
|
279
|
+
error: false
|
|
280
|
+
});
|
|
281
|
+
setGeneralError(null);
|
|
282
|
+
setErrors(null);
|
|
283
|
+
finalPostForm(action, _objectSpread(_objectSpread({}, submitValue), {}, {
|
|
284
|
+
_token: csrfToken
|
|
285
|
+
})).then(onSubmitSuccess)["catch"](onSubmitError);
|
|
286
|
+
}, [finalPostForm, action, value]);
|
|
287
|
+
var onSubmit = useCallback(function (e) {
|
|
288
|
+
// console.log('form submit', e); //
|
|
289
|
+
if (withoutDefault) {
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
}
|
|
292
|
+
if (withoutPropagation) {
|
|
293
|
+
e.stopPropagation();
|
|
294
|
+
}
|
|
295
|
+
// This one is very important with multiple forms
|
|
296
|
+
// Nested forms (even in portals) will bubble the onSubmit event to the parent
|
|
297
|
+
submit();
|
|
298
|
+
}, [submit, action, withoutDefault, withoutPropagation]);
|
|
299
|
+
var status = null;
|
|
300
|
+
if (requestState.loading) {
|
|
301
|
+
status = 'loading';
|
|
302
|
+
} else if (requestState.success) {
|
|
303
|
+
status = 'success';
|
|
304
|
+
} else if (requestState.error) {
|
|
305
|
+
status = 'error';
|
|
306
|
+
}
|
|
307
|
+
return _objectSpread(_objectSpread({
|
|
308
|
+
value: value,
|
|
309
|
+
setValue: setValue,
|
|
310
|
+
csrfToken: csrfToken,
|
|
311
|
+
submit: submit,
|
|
312
|
+
onSubmit: onSubmit
|
|
313
|
+
}, requestState), {}, {
|
|
314
|
+
status: status,
|
|
315
|
+
response: response,
|
|
316
|
+
fields: fieldsProps,
|
|
317
|
+
errors: errors,
|
|
318
|
+
generalError: generalError
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
var useForm$1 = useForm;
|
|
322
|
+
|
|
323
|
+
var buildThresholdArray = function buildThresholdArray() {
|
|
324
|
+
return [0, 1.0];
|
|
325
|
+
};
|
|
326
|
+
var observersCache = new Map();
|
|
327
|
+
var getOptionsKey = function getOptionsKey(_ref) {
|
|
328
|
+
var _ref$root = _ref.root,
|
|
329
|
+
root = _ref$root === void 0 ? null : _ref$root,
|
|
330
|
+
rootMargin = _ref.rootMargin,
|
|
331
|
+
_ref$threshold = _ref.threshold,
|
|
332
|
+
threshold = _ref$threshold === void 0 ? null : _ref$threshold;
|
|
333
|
+
return "root_".concat(root, "_rootMargin_").concat(rootMargin || null, "_threshold_").concat(threshold);
|
|
334
|
+
};
|
|
335
|
+
var createObserver = function createObserver(Observer) {
|
|
336
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
337
|
+
var subscribers = [];
|
|
338
|
+
var addSubscriber = function addSubscriber(element, callback) {
|
|
339
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
340
|
+
return it.element === element;
|
|
341
|
+
}) || null;
|
|
342
|
+
if (currentSubscriber !== null) {
|
|
343
|
+
return subscribers.map(function (it) {
|
|
344
|
+
return it.element === element && it.callbacks.indexOf(callback) === -1 ? _objectSpread(_objectSpread({}, it), {}, {
|
|
345
|
+
callbacks: [].concat(_toConsumableArray(it.callbacks), [callback])
|
|
346
|
+
}) : it;
|
|
347
|
+
}).filter(function (it) {
|
|
348
|
+
return it.callbacks.length > 0;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return [].concat(_toConsumableArray(subscribers), [{
|
|
352
|
+
element: element,
|
|
353
|
+
callbacks: [callback]
|
|
354
|
+
}]);
|
|
355
|
+
};
|
|
356
|
+
var removeSubscriber = function removeSubscriber(element, callback) {
|
|
357
|
+
return subscribers.map(function (it) {
|
|
358
|
+
return it.element === element ? _objectSpread(_objectSpread({}, it), {}, {
|
|
359
|
+
callbacks: it.callbacks.filter(function (subCallback) {
|
|
360
|
+
return subCallback !== callback;
|
|
361
|
+
})
|
|
362
|
+
}) : it;
|
|
363
|
+
}).filter(function (it) {
|
|
364
|
+
return it.callbacks.length > 0;
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
var onUpdate = function onUpdate(entries) {
|
|
368
|
+
entries.forEach(function (entry) {
|
|
369
|
+
subscribers.forEach(function (_ref2) {
|
|
370
|
+
var element = _ref2.element,
|
|
371
|
+
callbacks = _ref2.callbacks;
|
|
372
|
+
if (element === entry.target) {
|
|
373
|
+
callbacks.forEach(function (callback) {
|
|
374
|
+
callback(entry);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
var observer = new Observer(onUpdate, options);
|
|
381
|
+
var unsubscribe = function unsubscribe(element) {
|
|
382
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
383
|
+
subscribers = removeSubscriber(element, callback);
|
|
384
|
+
if (typeof observer.unobserve === 'undefined') {
|
|
385
|
+
observer.disconnect();
|
|
386
|
+
subscribers.forEach(function (subscriber) {
|
|
387
|
+
observer.observe(subscriber.element);
|
|
388
|
+
});
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
392
|
+
return it.element === element;
|
|
393
|
+
}) || null;
|
|
394
|
+
if (currentSubscriber === null) {
|
|
395
|
+
observer.unobserve(element);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
var subscribe = function subscribe(element, callback) {
|
|
399
|
+
var currentSubscriber = subscribers.find(function (it) {
|
|
400
|
+
return it.element === element;
|
|
401
|
+
}) || null;
|
|
402
|
+
subscribers = addSubscriber(element, callback);
|
|
403
|
+
if (currentSubscriber === null) {
|
|
404
|
+
observer.observe(element);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
return {
|
|
408
|
+
subscribe: subscribe,
|
|
409
|
+
unsubscribe: unsubscribe,
|
|
410
|
+
observer: observer
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
var getObserver = function getObserver(Observer) {
|
|
414
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
415
|
+
var observerKey = getOptionsKey(options);
|
|
416
|
+
if (!observersCache.has(Observer)) {
|
|
417
|
+
observersCache.set(Observer, {});
|
|
418
|
+
}
|
|
419
|
+
var observers = observersCache.get(Observer);
|
|
420
|
+
if (typeof observers[observerKey] === 'undefined') {
|
|
421
|
+
observers[observerKey] = createObserver(Observer, options);
|
|
422
|
+
observersCache.set(Observer, observers);
|
|
423
|
+
}
|
|
424
|
+
return observers[observerKey];
|
|
425
|
+
};
|
|
426
|
+
var useObserver = function useObserver(Observer) {
|
|
427
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
428
|
+
var initialEntry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
429
|
+
var _opts$root = opts.root,
|
|
430
|
+
root = _opts$root === void 0 ? null : _opts$root,
|
|
431
|
+
_opts$rootMargin = opts.rootMargin,
|
|
432
|
+
rootMargin = _opts$rootMargin === void 0 ? null : _opts$rootMargin,
|
|
433
|
+
_opts$threshold = opts.threshold,
|
|
434
|
+
threshold = _opts$threshold === void 0 ? null : _opts$threshold,
|
|
435
|
+
_opts$disabled = opts.disabled,
|
|
436
|
+
disabled = _opts$disabled === void 0 ? false : _opts$disabled;
|
|
437
|
+
var _useState = useState(initialEntry),
|
|
438
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
439
|
+
entry = _useState2[0],
|
|
440
|
+
setEntry = _useState2[1];
|
|
441
|
+
var nodeRef = useRef(null);
|
|
442
|
+
var currentElement = useRef(null);
|
|
443
|
+
var elementChanged = nodeRef.current !== currentElement.current;
|
|
444
|
+
useEffect(function () {
|
|
445
|
+
var nodeElement = nodeRef.current;
|
|
446
|
+
var callback = function callback(newEntry) {
|
|
447
|
+
return setEntry(newEntry);
|
|
448
|
+
};
|
|
449
|
+
var unsubscribe = null;
|
|
450
|
+
if (nodeElement !== null) {
|
|
451
|
+
var newOpts = {};
|
|
452
|
+
if (root !== null) {
|
|
453
|
+
newOpts.root = root;
|
|
454
|
+
}
|
|
455
|
+
if (rootMargin !== null) {
|
|
456
|
+
newOpts.rootMargin = rootMargin;
|
|
457
|
+
}
|
|
458
|
+
if (threshold !== null) {
|
|
459
|
+
newOpts.threshold = threshold;
|
|
460
|
+
}
|
|
461
|
+
var _getObserver = getObserver(Observer, newOpts),
|
|
462
|
+
subscribe = _getObserver.subscribe,
|
|
463
|
+
localUnsubscribe = _getObserver.unsubscribe;
|
|
464
|
+
unsubscribe = localUnsubscribe;
|
|
465
|
+
subscribe(nodeElement, callback);
|
|
466
|
+
}
|
|
467
|
+
currentElement.current = nodeElement;
|
|
468
|
+
return function () {
|
|
469
|
+
if (unsubscribe !== null) {
|
|
470
|
+
unsubscribe(nodeElement, callback);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}, [Observer, elementChanged, disabled, root, rootMargin, threshold]);
|
|
474
|
+
return {
|
|
475
|
+
ref: nodeRef,
|
|
476
|
+
entry: entry
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Intersection Observer
|
|
482
|
+
*/
|
|
483
|
+
var thresholdArray = buildThresholdArray();
|
|
484
|
+
var intersectionObserverInitialEntry = {
|
|
485
|
+
target: null,
|
|
486
|
+
time: null,
|
|
487
|
+
isVisible: false,
|
|
488
|
+
isIntersecting: false,
|
|
489
|
+
intersectionRatio: 0,
|
|
490
|
+
intersectionRect: null,
|
|
491
|
+
boundingClientRect: null,
|
|
492
|
+
rootBounds: null
|
|
493
|
+
};
|
|
494
|
+
var useIntersectionObserver = function useIntersectionObserver() {
|
|
495
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
496
|
+
_ref3$root = _ref3.root,
|
|
497
|
+
root = _ref3$root === void 0 ? null : _ref3$root,
|
|
498
|
+
_ref3$rootMargin = _ref3.rootMargin,
|
|
499
|
+
rootMargin = _ref3$rootMargin === void 0 ? '0px' : _ref3$rootMargin,
|
|
500
|
+
_ref3$threshold = _ref3.threshold,
|
|
501
|
+
threshold = _ref3$threshold === void 0 ? thresholdArray : _ref3$threshold,
|
|
502
|
+
_ref3$disabled = _ref3.disabled,
|
|
503
|
+
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled;
|
|
504
|
+
return useObserver(typeof window !== 'undefined' ? IntersectionObserver : null, {
|
|
505
|
+
root: root,
|
|
506
|
+
rootMargin: rootMargin,
|
|
507
|
+
threshold: threshold,
|
|
508
|
+
disabled: disabled
|
|
509
|
+
}, intersectionObserverInitialEntry);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Resize Observer
|
|
514
|
+
*/
|
|
515
|
+
var resizeObserverInitialEntry = {
|
|
516
|
+
target: null,
|
|
517
|
+
contentRect: null,
|
|
518
|
+
contentBoxSize: null,
|
|
519
|
+
borderBoxSize: null
|
|
520
|
+
};
|
|
521
|
+
var useResizeObserver = function useResizeObserver() {
|
|
522
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
523
|
+
_ref4$disabled = _ref4.disabled,
|
|
524
|
+
disabled = _ref4$disabled === void 0 ? false : _ref4$disabled;
|
|
525
|
+
return useObserver(typeof window !== 'undefined' ? ResizeObserver : null, {
|
|
526
|
+
disabled: disabled
|
|
527
|
+
}, resizeObserverInitialEntry);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
var useIsVisible = function useIsVisible() {
|
|
531
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
532
|
+
rootMargin = _ref.rootMargin,
|
|
533
|
+
_ref$threshold = _ref.threshold,
|
|
534
|
+
threshold = _ref$threshold === void 0 ? 1 : _ref$threshold,
|
|
535
|
+
_ref$persist = _ref.persist,
|
|
536
|
+
persist = _ref$persist === void 0 ? false : _ref$persist;
|
|
537
|
+
var _useIntersectionObser = useIntersectionObserver({
|
|
538
|
+
rootMargin: rootMargin,
|
|
539
|
+
threshold: threshold
|
|
540
|
+
}),
|
|
541
|
+
ref = _useIntersectionObser.ref,
|
|
542
|
+
isIntersecting = _useIntersectionObser.entry.isIntersecting;
|
|
543
|
+
var wasIntersecting = useRef(isIntersecting);
|
|
544
|
+
if (isIntersecting && !wasIntersecting.current) {
|
|
545
|
+
wasIntersecting.current = isIntersecting;
|
|
546
|
+
}
|
|
547
|
+
var isVisible = !persist && isIntersecting || persist && wasIntersecting.current;
|
|
548
|
+
return {
|
|
549
|
+
ref: ref,
|
|
550
|
+
visible: isVisible
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
var useIsVisible$1 = useIsVisible;
|
|
554
|
+
|
|
555
|
+
var fontsMap = {
|
|
556
|
+
loading: [],
|
|
557
|
+
active: []
|
|
558
|
+
};
|
|
559
|
+
var isFontLoading = function isFontLoading(name) {
|
|
560
|
+
return fontsMap.loading.indexOf(name) !== -1;
|
|
561
|
+
};
|
|
562
|
+
var isFontActive = function isFontActive(name) {
|
|
563
|
+
return fontsMap.active.indexOf(name) !== -1;
|
|
564
|
+
};
|
|
565
|
+
var addFontLoading = function addFontLoading(name) {
|
|
566
|
+
fontsMap.active = fontsMap.active.filter(function (it) {
|
|
567
|
+
return it !== name;
|
|
568
|
+
});
|
|
569
|
+
fontsMap.loading = [].concat(_toConsumableArray(fontsMap.loading), [name]);
|
|
570
|
+
};
|
|
571
|
+
var removeFontLoading = function removeFontLoading(name) {
|
|
572
|
+
fontsMap.loading = fontsMap.loading.filter(function (it) {
|
|
573
|
+
return it !== name;
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
var addFontActive = function addFontActive(name) {
|
|
577
|
+
fontsMap.loading = fontsMap.loading.filter(function (it) {
|
|
578
|
+
return it !== name;
|
|
579
|
+
});
|
|
580
|
+
fontsMap.active = [].concat(_toConsumableArray(fontsMap.active), [name]);
|
|
581
|
+
};
|
|
582
|
+
var useLoadedFonts = function useLoadedFonts(fonts) {
|
|
583
|
+
var _useState = useState(false),
|
|
584
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
585
|
+
loaded = _useState2[0],
|
|
586
|
+
setLoaded = _useState2[1];
|
|
587
|
+
useEffect(function () {
|
|
588
|
+
var config = fonts.reduce(function (newConfig, font) {
|
|
589
|
+
var _ref = isObject(font) ? font : {
|
|
590
|
+
type: 'system',
|
|
591
|
+
name: font
|
|
592
|
+
},
|
|
593
|
+
type = _ref.type,
|
|
594
|
+
name = _ref.name;
|
|
595
|
+
if ((type === 'google' || type === 'custom') && !isFontLoading(name) && !isFontActive(name)) {
|
|
596
|
+
return _objectSpread(_objectSpread({}, newConfig), {}, _defineProperty({}, type, {
|
|
597
|
+
families: [].concat(_toConsumableArray(newConfig !== null ? (newConfig[type] || {}).families || [] : []), [name])
|
|
598
|
+
}));
|
|
599
|
+
}
|
|
600
|
+
return newConfig;
|
|
601
|
+
}, null);
|
|
602
|
+
var hasConfig = config !== null;
|
|
603
|
+
if (hasConfig && typeof window !== 'undefined') {
|
|
604
|
+
loadPackage('webfontloader', function () {
|
|
605
|
+
return import('webfontloader');
|
|
606
|
+
}).then(function (_ref2) {
|
|
607
|
+
var WebFont = _ref2["default"];
|
|
608
|
+
return WebFont.load(_objectSpread(_objectSpread({}, config), {}, {
|
|
609
|
+
timeout: 3000,
|
|
610
|
+
active: function active() {
|
|
611
|
+
return setLoaded(true);
|
|
612
|
+
},
|
|
613
|
+
fontloading: function fontloading(name) {
|
|
614
|
+
return addFontLoading(name);
|
|
615
|
+
},
|
|
616
|
+
fontactive: function fontactive(name) {
|
|
617
|
+
return addFontActive(name);
|
|
618
|
+
},
|
|
619
|
+
fontinactive: function fontinactive(name) {
|
|
620
|
+
return removeFontLoading(name);
|
|
621
|
+
}
|
|
622
|
+
}));
|
|
623
|
+
});
|
|
624
|
+
} else {
|
|
625
|
+
setLoaded(true);
|
|
626
|
+
}
|
|
627
|
+
}, [fonts, setLoaded]);
|
|
628
|
+
return {
|
|
629
|
+
loaded: loaded
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var useLoadedFonts$1 = useLoadedFonts;
|
|
633
|
+
|
|
634
|
+
var progressSteps = [0.1, 0.25, 0.5, 0.75, 0.9];
|
|
635
|
+
var useMediaApi = function useMediaApi() {
|
|
636
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
637
|
+
_ref$url = _ref.url,
|
|
638
|
+
url = _ref$url === void 0 ? null : _ref$url,
|
|
639
|
+
_ref$initialMuted = _ref.initialMuted,
|
|
640
|
+
initialMuted = _ref$initialMuted === void 0 ? false : _ref$initialMuted,
|
|
641
|
+
_ref$onTimeUpdate = _ref.onTimeUpdate,
|
|
642
|
+
onTimeUpdate = _ref$onTimeUpdate === void 0 ? null : _ref$onTimeUpdate,
|
|
643
|
+
_ref$onProgressStep = _ref.onProgressStep,
|
|
644
|
+
onProgressStep = _ref$onProgressStep === void 0 ? null : _ref$onProgressStep,
|
|
645
|
+
_ref$onDurationChange = _ref.onDurationChanged,
|
|
646
|
+
onDurationChanged = _ref$onDurationChange === void 0 ? null : _ref$onDurationChange,
|
|
647
|
+
_ref$onVolumeChanged = _ref.onVolumeChanged,
|
|
648
|
+
onVolumeChanged = _ref$onVolumeChanged === void 0 ? null : _ref$onVolumeChanged,
|
|
649
|
+
_ref$onPlay = _ref.onPlay,
|
|
650
|
+
onPlay = _ref$onPlay === void 0 ? null : _ref$onPlay,
|
|
651
|
+
_ref$onPause = _ref.onPause,
|
|
652
|
+
onPause = _ref$onPause === void 0 ? null : _ref$onPause,
|
|
653
|
+
_ref$onEnded = _ref.onEnded,
|
|
654
|
+
onEnded = _ref$onEnded === void 0 ? null : _ref$onEnded,
|
|
655
|
+
_ref$onSeeked = _ref.onSeeked,
|
|
656
|
+
onSeeked = _ref$onSeeked === void 0 ? null : _ref$onSeeked,
|
|
657
|
+
_ref$onLoadStart = _ref.onLoadStart,
|
|
658
|
+
onLoadStart = _ref$onLoadStart === void 0 ? null : _ref$onLoadStart,
|
|
659
|
+
_ref$onCanPlayThough = _ref.onCanPlayThough,
|
|
660
|
+
onCanPlayThough = _ref$onCanPlayThough === void 0 ? null : _ref$onCanPlayThough;
|
|
661
|
+
var ref = useRef(null);
|
|
662
|
+
var _useState = useState(initialMuted),
|
|
663
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
664
|
+
muted = _useState2[0],
|
|
665
|
+
setMuted = _useState2[1];
|
|
666
|
+
var _useState3 = useState(null),
|
|
667
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
668
|
+
currentTime = _useState4[0],
|
|
669
|
+
setCurrentTime = _useState4[1];
|
|
670
|
+
var _useState5 = useState(null),
|
|
671
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
672
|
+
duration = _useState6[0],
|
|
673
|
+
setDuration = _useState6[1];
|
|
674
|
+
var _useState7 = useState(false),
|
|
675
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
676
|
+
playing = _useState8[0],
|
|
677
|
+
setPlaying = _useState8[1];
|
|
678
|
+
var _useState9 = useState(false),
|
|
679
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
680
|
+
ready = _useState10[0],
|
|
681
|
+
setReady = _useState10[1];
|
|
682
|
+
var _useState11 = useState(true),
|
|
683
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
684
|
+
initialPlay = _useState12[0],
|
|
685
|
+
setInitialPlay = _useState12[1];
|
|
686
|
+
var progressStepsReached = useRef({});
|
|
687
|
+
var paused = !playing;
|
|
688
|
+
|
|
689
|
+
// Exposed methods
|
|
690
|
+
|
|
691
|
+
var play = useCallback(function () {
|
|
692
|
+
var media = ref.current;
|
|
693
|
+
if (media !== null) {
|
|
694
|
+
media.play();
|
|
695
|
+
}
|
|
696
|
+
}, []);
|
|
697
|
+
var pause = useCallback(function () {
|
|
698
|
+
var media = ref.current;
|
|
699
|
+
if (media !== null) {
|
|
700
|
+
media.pause();
|
|
701
|
+
}
|
|
702
|
+
}, []);
|
|
703
|
+
var togglePlay = useCallback(function () {
|
|
704
|
+
var media = ref.current;
|
|
705
|
+
if (media !== null) {
|
|
706
|
+
if (playing) {
|
|
707
|
+
media.pause();
|
|
708
|
+
} else {
|
|
709
|
+
media.play();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}, [playing]);
|
|
713
|
+
var stop = useCallback(function () {
|
|
714
|
+
var media = ref.current;
|
|
715
|
+
if (media !== null) {
|
|
716
|
+
media.pause();
|
|
717
|
+
media.currentTime = 0;
|
|
718
|
+
}
|
|
719
|
+
}, []);
|
|
720
|
+
var seek = useCallback(function (time) {
|
|
721
|
+
var media = ref.current;
|
|
722
|
+
if (media !== null) {
|
|
723
|
+
media.currentTime = time;
|
|
724
|
+
}
|
|
725
|
+
}, []);
|
|
726
|
+
var mute = useCallback(function () {
|
|
727
|
+
var media = ref.current;
|
|
728
|
+
if (media !== null) {
|
|
729
|
+
media.muted = true;
|
|
730
|
+
}
|
|
731
|
+
}, []);
|
|
732
|
+
var unMute = useCallback(function () {
|
|
733
|
+
var media = ref.current;
|
|
734
|
+
if (media !== null) {
|
|
735
|
+
media.muted = false;
|
|
736
|
+
}
|
|
737
|
+
}, []);
|
|
738
|
+
var toggleMute = useCallback(function () {
|
|
739
|
+
var media = ref.current;
|
|
740
|
+
if (media !== null) {
|
|
741
|
+
media.muted = !muted;
|
|
742
|
+
}
|
|
743
|
+
}, [muted]);
|
|
744
|
+
|
|
745
|
+
// Media events callbacks
|
|
746
|
+
|
|
747
|
+
var onCustomPlay = useCallback(function () {
|
|
748
|
+
if (onPlay !== null) {
|
|
749
|
+
onPlay({
|
|
750
|
+
initial: initialPlay
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
if (initialPlay) {
|
|
754
|
+
setInitialPlay(false);
|
|
755
|
+
}
|
|
756
|
+
setPlaying(true);
|
|
757
|
+
}, [initialPlay, setPlaying, onPlay]);
|
|
758
|
+
var onCustomPause = useCallback(function () {
|
|
759
|
+
var media = ref.current;
|
|
760
|
+
setPlaying(false);
|
|
761
|
+
if (onPause !== null) {
|
|
762
|
+
onPause({
|
|
763
|
+
midway: media.currentTime > 0 && media.currentTime < media.duration
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}, [setPlaying, onPause]);
|
|
767
|
+
var onCustomEnded = useCallback(function () {
|
|
768
|
+
var media = ref.current;
|
|
769
|
+
media.currentTime = 0;
|
|
770
|
+
if (onEnded !== null) {
|
|
771
|
+
onEnded();
|
|
772
|
+
}
|
|
773
|
+
setInitialPlay(true);
|
|
774
|
+
}, [setInitialPlay, onEnded]);
|
|
775
|
+
var onCustomTimeUpdate = useCallback(function () {
|
|
776
|
+
var media = ref.current;
|
|
777
|
+
setCurrentTime(media.currentTime);
|
|
778
|
+
if (onTimeUpdate !== null) {
|
|
779
|
+
onTimeUpdate(media.currentTime);
|
|
780
|
+
}
|
|
781
|
+
var progress = media.currentTime / media.duration;
|
|
782
|
+
var currentSteps = progressStepsReached.current;
|
|
783
|
+
var stepsToTrack = progressSteps.filter(function (step) {
|
|
784
|
+
return progress > step && typeof currentSteps[step] === 'undefined';
|
|
785
|
+
});
|
|
786
|
+
stepsToTrack.forEach(function (step) {
|
|
787
|
+
if (onProgressStep !== null) {
|
|
788
|
+
onProgressStep(step);
|
|
789
|
+
}
|
|
790
|
+
currentSteps[step] = true;
|
|
791
|
+
});
|
|
792
|
+
}, [setCurrentTime, onTimeUpdate, onProgressStep]);
|
|
793
|
+
var onCustomDurationChange = useCallback(function () {
|
|
794
|
+
var media = ref.current;
|
|
795
|
+
setDuration(media.duration);
|
|
796
|
+
if (onDurationChanged !== null) {
|
|
797
|
+
onDurationChanged(media.duration);
|
|
798
|
+
}
|
|
799
|
+
}, [setDuration, onDurationChanged]);
|
|
800
|
+
var onCustomSeeked = useCallback(function () {
|
|
801
|
+
var media = ref.current;
|
|
802
|
+
if (onSeeked !== null) {
|
|
803
|
+
onSeeked(media.currentTime);
|
|
804
|
+
}
|
|
805
|
+
}, [onSeeked]);
|
|
806
|
+
var onCustomVolumeChange = useCallback(function () {
|
|
807
|
+
var media = ref.current;
|
|
808
|
+
setMuted(media.muted);
|
|
809
|
+
if (onVolumeChanged !== null) {
|
|
810
|
+
onVolumeChanged(media.muted, media.volume);
|
|
811
|
+
}
|
|
812
|
+
}, [setMuted, onVolumeChanged]);
|
|
813
|
+
var onCustomLoadStart = useCallback(function () {
|
|
814
|
+
setReady(false);
|
|
815
|
+
if (onLoadStart !== null) {
|
|
816
|
+
onLoadStart();
|
|
817
|
+
}
|
|
818
|
+
}, [setReady, onLoadStart]);
|
|
819
|
+
var onCustomCanPlayThrough = useCallback(function () {
|
|
820
|
+
setReady(true);
|
|
821
|
+
if (onCanPlayThough !== null) {
|
|
822
|
+
onCanPlayThough();
|
|
823
|
+
}
|
|
824
|
+
}, [setReady, onCanPlayThough]);
|
|
825
|
+
useEffect(function () {
|
|
826
|
+
var media = ref.current;
|
|
827
|
+
if (media !== null) {
|
|
828
|
+
media.addEventListener('timeupdate', onCustomTimeUpdate);
|
|
829
|
+
media.addEventListener('durationchange', onCustomDurationChange);
|
|
830
|
+
media.addEventListener('volumechange', onCustomVolumeChange);
|
|
831
|
+
media.addEventListener('play', onCustomPlay);
|
|
832
|
+
media.addEventListener('pause', onCustomPause);
|
|
833
|
+
media.addEventListener('ended', onCustomEnded);
|
|
834
|
+
media.addEventListener('seeked', onCustomSeeked);
|
|
835
|
+
media.addEventListener('loadstart', onCustomLoadStart);
|
|
836
|
+
media.addEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
837
|
+
}
|
|
838
|
+
return function () {
|
|
839
|
+
if (media !== null) {
|
|
840
|
+
media.removeEventListener('timeupdate', onCustomTimeUpdate);
|
|
841
|
+
media.removeEventListener('durationchange', onCustomDurationChange);
|
|
842
|
+
media.removeEventListener('volumechange', onCustomVolumeChange);
|
|
843
|
+
media.removeEventListener('play', onCustomPlay);
|
|
844
|
+
media.removeEventListener('pause', onCustomPause);
|
|
845
|
+
media.removeEventListener('ended', onCustomEnded);
|
|
846
|
+
media.removeEventListener('seeked', onCustomSeeked);
|
|
847
|
+
media.removeEventListener('loadstart', onCustomLoadStart);
|
|
848
|
+
media.removeEventListener('canplaythrough', onCustomCanPlayThrough);
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}, [url]);
|
|
852
|
+
return {
|
|
853
|
+
ref: ref,
|
|
854
|
+
play: play,
|
|
855
|
+
pause: pause,
|
|
856
|
+
togglePlay: togglePlay,
|
|
857
|
+
stop: stop,
|
|
858
|
+
seek: seek,
|
|
859
|
+
mute: mute,
|
|
860
|
+
unMute: unMute,
|
|
861
|
+
toggleMute: toggleMute,
|
|
862
|
+
muted: muted,
|
|
863
|
+
currentTime: currentTime,
|
|
864
|
+
duration: duration,
|
|
865
|
+
playing: playing,
|
|
866
|
+
paused: paused,
|
|
867
|
+
ready: ready
|
|
868
|
+
};
|
|
869
|
+
};
|
|
870
|
+
var useMediaApi$1 = useMediaApi;
|
|
871
|
+
|
|
872
|
+
var useMediasParser = function useMediasParser() {
|
|
873
|
+
// const screensManager = useScreensManager();
|
|
874
|
+
var fieldsManager = useFieldsManager();
|
|
875
|
+
|
|
876
|
+
// Convert medias object to path
|
|
877
|
+
var parser = useMemo(function () {
|
|
878
|
+
return new MediasParser({
|
|
879
|
+
// screensManager,
|
|
880
|
+
fieldsManager: fieldsManager
|
|
881
|
+
});
|
|
882
|
+
}, [fieldsManager]);
|
|
883
|
+
var toPath = useCallback(function (story) {
|
|
884
|
+
return parser.toPath(story);
|
|
885
|
+
}, [parser]);
|
|
886
|
+
var fromPath = useCallback(function (story) {
|
|
887
|
+
return parser.fromPath(story);
|
|
888
|
+
}, [parser]);
|
|
889
|
+
return {
|
|
890
|
+
toPath: toPath,
|
|
891
|
+
fromPath: fromPath,
|
|
892
|
+
parser: parser
|
|
893
|
+
};
|
|
894
|
+
};
|
|
895
|
+
var useMediasParser$1 = useMediasParser;
|
|
896
|
+
|
|
897
|
+
var useResourceTypeName = function useResourceTypeName(resource) {
|
|
898
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
899
|
+
var typeName = useMemo(function () {
|
|
900
|
+
var _ref = resource || {},
|
|
901
|
+
_ref$name = _ref.name,
|
|
902
|
+
resourceName = _ref$name === void 0 ? null : _ref$name,
|
|
903
|
+
_ref$types = _ref.types,
|
|
904
|
+
types = _ref$types === void 0 ? [] : _ref$types,
|
|
905
|
+
_ref$settings = _ref.settings,
|
|
906
|
+
settings = _ref$settings === void 0 ? {} : _ref$settings;
|
|
907
|
+
var _ref2 = settings || {},
|
|
908
|
+
_ref2$hideTypeNames = _ref2.hideTypeNames,
|
|
909
|
+
hideTypeNames = _ref2$hideTypeNames === void 0 ? false : _ref2$hideTypeNames;
|
|
910
|
+
if (hideTypeNames) {
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
var _ref3 = type !== null && types !== null && types.length > 1 ? (types || []).find(function (_ref4) {
|
|
914
|
+
var _ref4$id = _ref4.id,
|
|
915
|
+
id = _ref4$id === void 0 ? null : _ref4$id;
|
|
916
|
+
return id === type;
|
|
917
|
+
}) || {} : {},
|
|
918
|
+
_ref3$name = _ref3.name,
|
|
919
|
+
name = _ref3$name === void 0 ? null : _ref3$name;
|
|
920
|
+
return name === resourceName ? null : name;
|
|
921
|
+
}, [type, resource]);
|
|
922
|
+
return typeName;
|
|
923
|
+
};
|
|
924
|
+
var useResourceTypeName$1 = useResourceTypeName;
|
|
925
|
+
|
|
926
|
+
var getResource = function getResource(resources, resourceId) {
|
|
927
|
+
return resourceId !== null && !isObject(resourceId) ? resources.find(function (it) {
|
|
928
|
+
return it.id === resourceId;
|
|
929
|
+
}) || null : resourceId;
|
|
930
|
+
};
|
|
931
|
+
var useResourceUrlGenerator = function useResourceUrlGenerator() {
|
|
932
|
+
var resourceId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
933
|
+
var resources = usePanneauResources();
|
|
934
|
+
var contextResource = useResource();
|
|
935
|
+
var resource = getResource(resources, resourceId) || contextResource;
|
|
936
|
+
var route = useUrlGenerator();
|
|
937
|
+
return function (routeResourceId) {
|
|
938
|
+
var routeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
939
|
+
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
940
|
+
var finalRouteName = resourceId !== null ? routeResourceId : routeName;
|
|
941
|
+
var finalParams = resourceId !== null ? routeName : params;
|
|
942
|
+
var finalResource = getResource(resources, routeResourceId) || resource;
|
|
943
|
+
var _ref = finalResource || {},
|
|
944
|
+
_ref$id = _ref.id,
|
|
945
|
+
id = _ref$id === void 0 ? null : _ref$id;
|
|
946
|
+
// console.log('route name', finalRouteName, id, finalParams);
|
|
947
|
+
var finalRoute = id !== null ? route("resources.".concat(finalRouteName), _objectSpread(_objectSpread({}, finalParams), {}, {
|
|
948
|
+
resource: id
|
|
949
|
+
})) : null;
|
|
950
|
+
// console.log('route', finalRoute);
|
|
951
|
+
return finalRoute;
|
|
952
|
+
};
|
|
953
|
+
};
|
|
954
|
+
var useResourceUrlGenerator$1 = useResourceUrlGenerator;
|
|
955
|
+
|
|
956
|
+
var useQuery = function useQuery() {
|
|
957
|
+
var initialBaseQuery = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
958
|
+
var paginated = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
959
|
+
var initialQuery = useMemo(function () {
|
|
960
|
+
return paginated ? _objectSpread({
|
|
961
|
+
page: 1,
|
|
962
|
+
count: 10
|
|
963
|
+
}, initialBaseQuery) : initialBaseQuery || null;
|
|
964
|
+
}, [paginated, initialBaseQuery]);
|
|
965
|
+
var _useState = useState(initialQuery),
|
|
966
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
967
|
+
query = _useState2[0],
|
|
968
|
+
setQuery = _useState2[1];
|
|
969
|
+
useEffect(function () {
|
|
970
|
+
setQuery(initialQuery);
|
|
971
|
+
}, [initialQuery, setQuery]);
|
|
972
|
+
var onPageChange = useCallback(function (newPage) {
|
|
973
|
+
setQuery(_objectSpread(_objectSpread({}, query), {}, {
|
|
974
|
+
page: newPage || 1
|
|
975
|
+
}));
|
|
976
|
+
}, [query, setQuery]);
|
|
977
|
+
var onQueryChange = useCallback(function (newQuery) {
|
|
978
|
+
var finalQuery = newQuery !== null ? Object.keys(newQuery).reduce(function (currentQuery, key) {
|
|
979
|
+
var val = newQuery[key];
|
|
980
|
+
return val !== null ? _objectSpread(_objectSpread({}, currentQuery), {}, _defineProperty({}, key, val)) : currentQuery;
|
|
981
|
+
}, null) : null;
|
|
982
|
+
setQuery(_objectSpread(_objectSpread({}, initialQuery || null), finalQuery || null));
|
|
983
|
+
}, [query, setQuery, initialQuery]);
|
|
984
|
+
var onQueryReset = useCallback(function () {
|
|
985
|
+
setQuery(initialQuery);
|
|
986
|
+
}, [initialQuery, setQuery]);
|
|
987
|
+
return {
|
|
988
|
+
query: query,
|
|
989
|
+
onPageChange: onPageChange,
|
|
990
|
+
onQueryChange: onQueryChange,
|
|
991
|
+
onQueryReset: onQueryReset
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
var useQuery$1 = useQuery;
|
|
995
|
+
|
|
996
|
+
var _excluded = ["width", "height"];
|
|
997
|
+
var useScreenSize = function useScreenSize(_ref) {
|
|
998
|
+
var _ref$width = _ref.width,
|
|
999
|
+
width = _ref$width === void 0 ? null : _ref$width,
|
|
1000
|
+
_ref$height = _ref.height,
|
|
1001
|
+
height = _ref$height === void 0 ? null : _ref$height,
|
|
1002
|
+
_ref$landscape = _ref.landscape,
|
|
1003
|
+
landscape = _ref$landscape === void 0 ? false : _ref$landscape,
|
|
1004
|
+
_ref$screens = _ref.screens,
|
|
1005
|
+
screens = _ref$screens === void 0 ? [] : _ref$screens,
|
|
1006
|
+
_ref$mediaType = _ref.mediaType,
|
|
1007
|
+
mediaType = _ref$mediaType === void 0 ? 'screen' : _ref$mediaType,
|
|
1008
|
+
_ref$media = _ref.media,
|
|
1009
|
+
providedMedia = _ref$media === void 0 ? null : _ref$media;
|
|
1010
|
+
// Get media
|
|
1011
|
+
var media = useMemo(function () {
|
|
1012
|
+
return providedMedia !== null ? providedMedia : {
|
|
1013
|
+
type: mediaType,
|
|
1014
|
+
width: "".concat(width, "px"),
|
|
1015
|
+
height: "".concat(height, "px")
|
|
1016
|
+
};
|
|
1017
|
+
}, [providedMedia, mediaType, width, height]);
|
|
1018
|
+
|
|
1019
|
+
// Get matching screens
|
|
1020
|
+
var matchingScreens = useMemo(function () {
|
|
1021
|
+
return _toConsumableArray(screens).reverse().filter(function (_ref2) {
|
|
1022
|
+
var _ref2$mediaQuery = _ref2.mediaQuery,
|
|
1023
|
+
mediaQuery = _ref2$mediaQuery === void 0 ? null : _ref2$mediaQuery;
|
|
1024
|
+
return mediaQuery === null || match(mediaQuery, media);
|
|
1025
|
+
});
|
|
1026
|
+
}, [screens, media]);
|
|
1027
|
+
return {
|
|
1028
|
+
screen: matchingScreens.length > 0 ? matchingScreens[0].name : null,
|
|
1029
|
+
screens: _toConsumableArray(matchingScreens).reverse().map(function (_ref3) {
|
|
1030
|
+
var name = _ref3.name;
|
|
1031
|
+
return name;
|
|
1032
|
+
}),
|
|
1033
|
+
width: width,
|
|
1034
|
+
height: height,
|
|
1035
|
+
landscape: landscape
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
1039
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1040
|
+
_ref4$width = _ref4.width,
|
|
1041
|
+
width = _ref4$width === void 0 ? null : _ref4$width,
|
|
1042
|
+
_ref4$height = _ref4.height,
|
|
1043
|
+
height = _ref4$height === void 0 ? null : _ref4$height,
|
|
1044
|
+
opts = _objectWithoutProperties(_ref4, _excluded);
|
|
1045
|
+
var _useResizeObserver = useResizeObserver(),
|
|
1046
|
+
ref = _useResizeObserver.ref,
|
|
1047
|
+
contentRect = _useResizeObserver.entry.contentRect;
|
|
1048
|
+
var _ref5 = contentRect || {},
|
|
1049
|
+
_ref5$width = _ref5.width,
|
|
1050
|
+
calculatedWidth = _ref5$width === void 0 ? 0 : _ref5$width,
|
|
1051
|
+
_ref5$height = _ref5.height,
|
|
1052
|
+
calculatedHeight = _ref5$height === void 0 ? 0 : _ref5$height;
|
|
1053
|
+
var semiFinalWidth = width !== null ? width : calculatedWidth;
|
|
1054
|
+
var semiFinalHeight = height !== null ? height : calculatedHeight;
|
|
1055
|
+
var landscape = semiFinalHeight > 0 && semiFinalWidth > semiFinalHeight;
|
|
1056
|
+
var _opts$withoutMaxSize = opts.withoutMaxSize,
|
|
1057
|
+
withoutMaxSize = _opts$withoutMaxSize === void 0 ? false : _opts$withoutMaxSize;
|
|
1058
|
+
var finalWidth = landscape && !withoutMaxSize ? Math.round(Math.max(320, 0.45 * semiFinalHeight)) : semiFinalWidth;
|
|
1059
|
+
var finalHeight = landscape && !withoutMaxSize ? Math.round(Math.max(533, 0.75 * semiFinalHeight)) : semiFinalHeight;
|
|
1060
|
+
if (finalWidth % 2 === 1) {
|
|
1061
|
+
finalWidth -= 1;
|
|
1062
|
+
}
|
|
1063
|
+
if (finalHeight % 2 === 1) {
|
|
1064
|
+
finalHeight -= 1;
|
|
1065
|
+
}
|
|
1066
|
+
var screenSize = useScreenSize(_objectSpread({
|
|
1067
|
+
width: finalWidth,
|
|
1068
|
+
height: finalHeight,
|
|
1069
|
+
landscape: landscape
|
|
1070
|
+
}, opts));
|
|
1071
|
+
return {
|
|
1072
|
+
ref: ref,
|
|
1073
|
+
screenSize: screenSize
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
var getWindowSize = function getWindowSize() {
|
|
1077
|
+
return {
|
|
1078
|
+
width: typeof window !== 'undefined' ? window.innerWidth : null,
|
|
1079
|
+
height: typeof window !== 'undefined' ? window.innerHæeight : null
|
|
1080
|
+
};
|
|
1081
|
+
};
|
|
1082
|
+
var useScreenSizeFromWindow = function useScreenSizeFromWindow(opts) {
|
|
1083
|
+
var _useState = useState(getWindowSize()),
|
|
1084
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1085
|
+
windowSize = _useState2[0],
|
|
1086
|
+
setWindowSize = _useState2[1];
|
|
1087
|
+
useEffect(function () {
|
|
1088
|
+
var onResize = function onResize() {
|
|
1089
|
+
return setWindowSize(getWindowSize());
|
|
1090
|
+
};
|
|
1091
|
+
if (typeof window !== 'undefined') {
|
|
1092
|
+
window.addEventListener('resize', onResize);
|
|
1093
|
+
}
|
|
1094
|
+
return function () {
|
|
1095
|
+
if (typeof window !== 'undefined') {
|
|
1096
|
+
window.removeEventListener('resize', onResize);
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
}, [setWindowSize]);
|
|
1100
|
+
return useScreenSize(_objectSpread(_objectSpread({}, opts), windowSize));
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
var eventsManager = typeof window !== 'undefined' ? new EventsManager(window) : null;
|
|
1104
|
+
var useWindowEvent = createUseEvent(eventsManager);
|
|
1105
|
+
var useWindowEvent$1 = useWindowEvent;
|
|
1106
|
+
|
|
1107
|
+
var useItemSelection = function useItemSelection(_ref) {
|
|
1108
|
+
var _ref$items = _ref.items,
|
|
1109
|
+
items = _ref$items === void 0 ? null : _ref$items,
|
|
1110
|
+
_ref$selectedItems = _ref.selectedItems,
|
|
1111
|
+
initialSelectedItems = _ref$selectedItems === void 0 ? null : _ref$selectedItems,
|
|
1112
|
+
_ref$multipleSelectio = _ref.multipleSelection,
|
|
1113
|
+
multipleSelection = _ref$multipleSelectio === void 0 ? false : _ref$multipleSelectio,
|
|
1114
|
+
_ref$onSelectionChang = _ref.onSelectionChange,
|
|
1115
|
+
onSelectionChange = _ref$onSelectionChang === void 0 ? null : _ref$onSelectionChang;
|
|
1116
|
+
var initialItems = !isArray(initialSelectedItems) && initialSelectedItems !== null ? [initialSelectedItems] : initialSelectedItems;
|
|
1117
|
+
var _useState = useState(initialItems),
|
|
1118
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1119
|
+
selectedItems = _useState2[0],
|
|
1120
|
+
setSelectedItems = _useState2[1];
|
|
1121
|
+
var onSelectItem = useCallback(function (item, index) {
|
|
1122
|
+
var _ref2 = item || {},
|
|
1123
|
+
_ref2$id = _ref2.id,
|
|
1124
|
+
itemId = _ref2$id === void 0 ? null : _ref2$id;
|
|
1125
|
+
var oldItem = (selectedItems || []).find(function (_ref3) {
|
|
1126
|
+
var id = _ref3.id;
|
|
1127
|
+
return id === itemId;
|
|
1128
|
+
}) || null;
|
|
1129
|
+
var newItems = [];
|
|
1130
|
+
if (oldItem === null) {
|
|
1131
|
+
newItems = selectedItems !== null && multipleSelection ? [].concat(_toConsumableArray(selectedItems), [item]) : [item];
|
|
1132
|
+
} else {
|
|
1133
|
+
newItems = (selectedItems || []).filter(function (_ref4) {
|
|
1134
|
+
var id = _ref4.id;
|
|
1135
|
+
return id !== itemId;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
setSelectedItems(newItems);
|
|
1139
|
+
if (onSelectionChange !== null) {
|
|
1140
|
+
onSelectionChange(newItems, item, index);
|
|
1141
|
+
}
|
|
1142
|
+
}, [selectedItems, onSelectionChange, multipleSelection]);
|
|
1143
|
+
var onSelectPage = useCallback(function () {
|
|
1144
|
+
var pageSelected = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1145
|
+
var nextItems = [];
|
|
1146
|
+
if (!pageSelected) {
|
|
1147
|
+
nextItems = uniqBy([].concat(_toConsumableArray(items || []), _toConsumableArray(selectedItems || [])), function () {
|
|
1148
|
+
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1149
|
+
_ref5$id = _ref5.id,
|
|
1150
|
+
id = _ref5$id === void 0 ? null : _ref5$id;
|
|
1151
|
+
return id;
|
|
1152
|
+
});
|
|
1153
|
+
} else {
|
|
1154
|
+
var ids = (items || []).map(function () {
|
|
1155
|
+
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1156
|
+
_ref6$id = _ref6.id,
|
|
1157
|
+
id = _ref6$id === void 0 ? null : _ref6$id;
|
|
1158
|
+
return id;
|
|
1159
|
+
}).filter(function (id) {
|
|
1160
|
+
return id !== null;
|
|
1161
|
+
});
|
|
1162
|
+
nextItems = uniqBy((selectedItems || []).filter(function (it) {
|
|
1163
|
+
var _ref7 = it || {},
|
|
1164
|
+
_ref7$id = _ref7.id,
|
|
1165
|
+
id = _ref7$id === void 0 ? null : _ref7$id;
|
|
1166
|
+
return ids.indexOf(id) === -1;
|
|
1167
|
+
}), function () {
|
|
1168
|
+
var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1169
|
+
_ref8$id = _ref8.id,
|
|
1170
|
+
id = _ref8$id === void 0 ? null : _ref8$id;
|
|
1171
|
+
return id;
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
setSelectedItems(nextItems);
|
|
1175
|
+
if (onSelectionChange !== null) {
|
|
1176
|
+
onSelectionChange(nextItems);
|
|
1177
|
+
}
|
|
1178
|
+
}, [items, selectedItems, setSelectedItems, onSelectionChange]);
|
|
1179
|
+
var onClearSelected = useCallback(function () {
|
|
1180
|
+
setSelectedItems([]);
|
|
1181
|
+
if (onSelectionChange !== null) {
|
|
1182
|
+
onSelectionChange([]);
|
|
1183
|
+
}
|
|
1184
|
+
}, [setSelectedItems, onSelectionChange]);
|
|
1185
|
+
useEffect(function () {
|
|
1186
|
+
setSelectedItems(initialSelectedItems);
|
|
1187
|
+
}, [initialSelectedItems]);
|
|
1188
|
+
var pageSelected = useMemo(function () {
|
|
1189
|
+
var ids = (items || []).map(function () {
|
|
1190
|
+
var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1191
|
+
_ref9$id = _ref9.id,
|
|
1192
|
+
id = _ref9$id === void 0 ? null : _ref9$id;
|
|
1193
|
+
return id;
|
|
1194
|
+
}).filter(function (id) {
|
|
1195
|
+
return id !== null;
|
|
1196
|
+
});
|
|
1197
|
+
var currentPageItems = (selectedItems || []).filter(function (it) {
|
|
1198
|
+
var _ref10 = it || {},
|
|
1199
|
+
_ref10$id = _ref10.id,
|
|
1200
|
+
id = _ref10$id === void 0 ? null : _ref10$id;
|
|
1201
|
+
return ids.indexOf(id) !== -1;
|
|
1202
|
+
});
|
|
1203
|
+
return currentPageItems.length === (items || []).length && currentPageItems.length > 0;
|
|
1204
|
+
}, [selectedItems, items]);
|
|
1205
|
+
var allSelected = useMemo(function () {
|
|
1206
|
+
return selectedItems !== null && items !== null && selectedItems.length === items.length;
|
|
1207
|
+
}, [selectedItems, items]);
|
|
1208
|
+
var selectedCount = useMemo(function () {
|
|
1209
|
+
return selectedItems !== null && selectedItems.length > 0 ? selectedItems.length : null;
|
|
1210
|
+
}, [selectedItems]);
|
|
1211
|
+
return {
|
|
1212
|
+
onSelectItem: onSelectItem,
|
|
1213
|
+
onSelectPage: onSelectPage,
|
|
1214
|
+
onClearSelected: onClearSelected,
|
|
1215
|
+
pageSelected: pageSelected,
|
|
1216
|
+
allSelected: allSelected,
|
|
1217
|
+
selectedCount: selectedCount,
|
|
1218
|
+
selectedItems: selectedItems,
|
|
1219
|
+
setSelectedItems: setSelectedItems
|
|
1220
|
+
};
|
|
1221
|
+
};
|
|
1222
|
+
var useItemSelection$1 = useItemSelection;
|
|
1223
|
+
|
|
1224
|
+
export { getObserver, useAnimationFrame$1 as useAnimationFrame, useDocumentEvent$1 as useDocumentEvent, useForm$1 as useForm, useFormattedDate, useFormattedTime, useIntersectionObserver, useIsVisible$1 as useIsVisible, useItemSelection$1 as useItemSelection, useLoadedFonts$1 as useLoadedFonts, useMediaApi$1 as useMediaApi, useMediasParser$1 as useMediasParser, useObserver, useQuery$1 as useQuery, useResizeObserver, useResourceTypeName$1 as useResourceTypeName, useResourceUrlGenerator$1 as useResourceUrlGenerator, useScreenSizeFromElement, useScreenSizeFromWindow, useWindowEvent$1 as useWindowEvent };
|