@panneau/core 3.0.300 → 4.0.0
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 +85 -352
- package/es/hooks.js +77 -55
- package/es/index.js +54 -45
- package/es/types/core.d.ts +133 -0
- package/es/types/form.d.ts +58 -0
- package/es/types/index.d.ts +39 -0
- package/es/types/panneau.d.ts +50 -0
- package/es/types/resource.d.ts +93 -0
- package/es/utils.js +71 -67
- package/lib/contexts.js +1406 -0
- package/lib/hooks.js +1337 -0
- package/lib/index.js +1019 -0
- package/lib/utils.js +789 -0
- package/package.json +20 -9
package/es/hooks.js
CHANGED
|
@@ -16,7 +16,7 @@ import dayjs from 'dayjs';
|
|
|
16
16
|
import { useIntl } from 'react-intl';
|
|
17
17
|
import { match } from 'css-mediaquery';
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
function useActionProps(action, value) {
|
|
20
20
|
var labelPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
21
21
|
var values = useMemo(function () {
|
|
22
22
|
if (value === null) {
|
|
@@ -63,11 +63,11 @@ var useActionProps = function useActionProps(action, value) {
|
|
|
63
63
|
idLabels: idLabels,
|
|
64
64
|
modalKey: modalKey
|
|
65
65
|
};
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
67
|
|
|
68
68
|
// For backwards compatibility with the old actions element
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
function useActions() {
|
|
71
71
|
var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
72
72
|
var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
73
73
|
var urlGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
@@ -181,9 +181,9 @@ var useActions = function useActions() {
|
|
|
181
181
|
}).filter(function (action) {
|
|
182
182
|
return action !== null;
|
|
183
183
|
});
|
|
184
|
-
}
|
|
184
|
+
}
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
function useAnimationFrame(onFrame) {
|
|
187
187
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
188
188
|
_ref$disabled = _ref.disabled,
|
|
189
189
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
@@ -207,7 +207,7 @@ var useAnimationFrame = function useAnimationFrame(onFrame) {
|
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
}, [disabled]);
|
|
210
|
-
}
|
|
210
|
+
}
|
|
211
211
|
|
|
212
212
|
var useFormattedDate = function useFormattedDate() {
|
|
213
213
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
@@ -267,9 +267,8 @@ var eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(docume
|
|
|
267
267
|
var useDocumentEvent = createUseEvent(eventsManager$1);
|
|
268
268
|
|
|
269
269
|
var _excluded$1 = ["value", "errors", "onChange"];
|
|
270
|
-
|
|
271
270
|
// prettier-ignore
|
|
272
|
-
var
|
|
271
|
+
var _getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref) {
|
|
273
272
|
var value = _ref.value,
|
|
274
273
|
errors = _ref.errors,
|
|
275
274
|
_onChange = _ref.onChange,
|
|
@@ -279,23 +278,43 @@ var getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref) {
|
|
|
279
278
|
var _ref2 = isObject(field) ? field : {},
|
|
280
279
|
_ref2$name = _ref2.name,
|
|
281
280
|
name = _ref2$name === void 0 ? isString(field) ? field : null : _ref2$name,
|
|
281
|
+
_ref2$fields = _ref2.fields,
|
|
282
|
+
fieldFields = _ref2$fields === void 0 ? null : _ref2$fields,
|
|
282
283
|
_ref2$component = _ref2.component,
|
|
283
284
|
component = _ref2$component === void 0 ? null : _ref2$component;
|
|
284
285
|
var fieldErrors = errors !== null ? errors[name] || [] : [];
|
|
285
|
-
var
|
|
286
|
+
var finalErrors = component === 'localized' ? (locales || []).reduce(function (previousErrors, locale) {
|
|
286
287
|
var items = errors !== null ? get(errors, "".concat(name, ".").concat(locale), []) || [] : [];
|
|
287
288
|
var finalItems = isArray(items) ? items : [items];
|
|
288
289
|
var finalPrevious = isArray(previousErrors) ? previousErrors : [];
|
|
289
290
|
return [].concat(_toConsumableArray(finalPrevious), _toConsumableArray(finalItems));
|
|
290
291
|
}, fieldErrors) : fieldErrors;
|
|
292
|
+
var subfieldErrors = errors;
|
|
293
|
+
if (errors !== null && name !== null) {
|
|
294
|
+
subfieldErrors = Object.keys(errors).reduce(function (acc, key) {
|
|
295
|
+
if (key === name) {
|
|
296
|
+
acc[key] = errors[key];
|
|
297
|
+
}
|
|
298
|
+
if (key.startsWith("".concat(name, ".")) || key.startsWith("".concat(name, "["))) {
|
|
299
|
+
var finalKey = key.substring(name.length + 1);
|
|
300
|
+
acc[finalKey] = errors[key];
|
|
301
|
+
}
|
|
302
|
+
return acc;
|
|
303
|
+
}, {});
|
|
304
|
+
}
|
|
291
305
|
return [].concat(_toConsumableArray(allFields), [_objectSpread(_objectSpread({}, isObject(field) ? field : null), {}, {
|
|
292
306
|
name: name,
|
|
293
307
|
component: component,
|
|
294
|
-
value: value !== null ? value[name] || null : null,
|
|
295
|
-
errors:
|
|
308
|
+
value: value !== null && name !== null ? value[name] || null : null,
|
|
309
|
+
errors: finalErrors.length > 0 ? finalErrors : null,
|
|
296
310
|
onChange: function onChange(fieldValue) {
|
|
297
311
|
return _onChange(name, fieldValue);
|
|
298
|
-
}
|
|
312
|
+
},
|
|
313
|
+
fields: fieldFields !== null ? _getFieldsPropsFromFields(fieldFields, {
|
|
314
|
+
value: value !== null && name !== null && isObject(value[name]) ? value[name] : null,
|
|
315
|
+
errors: subfieldErrors,
|
|
316
|
+
onChange: _onChange
|
|
317
|
+
}, locales) : null
|
|
299
318
|
}, props)]);
|
|
300
319
|
}, []);
|
|
301
320
|
};
|
|
@@ -356,9 +375,9 @@ var useForm = function useForm() {
|
|
|
356
375
|
requestState = _useState8[0],
|
|
357
376
|
setRequestState = _useState8[1];
|
|
358
377
|
var _useState9 = useState(null),
|
|
359
|
-
|
|
360
|
-
response =
|
|
361
|
-
setResponse =
|
|
378
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
379
|
+
response = _useState0[0],
|
|
380
|
+
setResponse = _useState0[1];
|
|
362
381
|
var hasProvidedValue = setProvidedValue !== null;
|
|
363
382
|
var value = hasProvidedValue ? providedValue : stateValue;
|
|
364
383
|
var setValue = hasProvidedValue ? setProvidedValue : setStateValue;
|
|
@@ -368,7 +387,6 @@ var useForm = function useForm() {
|
|
|
368
387
|
var hasProvidedGeneralError = setProvidedGeneralError !== null;
|
|
369
388
|
var generalError = hasProvidedGeneralError ? providedGeneralError : stateGeneralError;
|
|
370
389
|
var setGeneralError = hasProvidedGeneralError ? setProvidedGeneralError : setStateGeneralError;
|
|
371
|
-
var fieldsKey = [value, errors, requestState, locales].concat(fields);
|
|
372
390
|
var onFieldChange = useCallback(function (fieldName, fieldValue) {
|
|
373
391
|
var _ref3 = requestState || {},
|
|
374
392
|
_ref3$loading = _ref3.loading,
|
|
@@ -376,27 +394,27 @@ var useForm = function useForm() {
|
|
|
376
394
|
_ref3$success = _ref3.success,
|
|
377
395
|
success = _ref3$success === void 0 ? false : _ref3$success,
|
|
378
396
|
_ref3$error = _ref3.error,
|
|
379
|
-
|
|
397
|
+
requestError = _ref3$error === void 0 ? false : _ref3$error;
|
|
380
398
|
var fieldErrors = errors !== null ? errors[fieldName] || null : null;
|
|
381
399
|
if (fieldErrors !== null) {
|
|
382
400
|
setErrors(_objectSpread(_objectSpread({}, errors), {}, _defineProperty({}, fieldName, null)));
|
|
383
401
|
}
|
|
384
|
-
if (!loading && (success !== false ||
|
|
402
|
+
if (!loading && (success !== false || requestError !== false)) {
|
|
385
403
|
setRequestState({
|
|
386
404
|
success: false,
|
|
387
405
|
loading: false,
|
|
388
406
|
error: false
|
|
389
407
|
});
|
|
390
408
|
}
|
|
391
|
-
setValue(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, fieldName, fieldValue)));
|
|
392
|
-
},
|
|
409
|
+
setValue(_objectSpread(_objectSpread({}, value || {}), {}, _defineProperty({}, fieldName, fieldValue)));
|
|
410
|
+
}, [value, errors, requestState, setErrors, setValue].concat(_toConsumableArray(fields)));
|
|
393
411
|
var fieldsProps = useMemo(function () {
|
|
394
|
-
return
|
|
412
|
+
return _getFieldsPropsFromFields(fields, {
|
|
395
413
|
value: value,
|
|
396
414
|
errors: errors,
|
|
397
415
|
onChange: onFieldChange
|
|
398
416
|
}, locales);
|
|
399
|
-
},
|
|
417
|
+
}, [value, errors, locales, fields, onFieldChange].concat(_toConsumableArray(fields)));
|
|
400
418
|
var csrfToken = useMemo(function () {
|
|
401
419
|
return getCsrfToken();
|
|
402
420
|
}, []);
|
|
@@ -407,10 +425,10 @@ var useForm = function useForm() {
|
|
|
407
425
|
error: true
|
|
408
426
|
});
|
|
409
427
|
if (error.name === 'ValidationError') {
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
validationErrors =
|
|
413
|
-
setErrors(validationErrors);
|
|
428
|
+
var _getResponseData = error.getResponseData(),
|
|
429
|
+
_getResponseData$erro = _getResponseData.errors,
|
|
430
|
+
validationErrors = _getResponseData$erro === void 0 ? null : _getResponseData$erro;
|
|
431
|
+
setErrors(validationErrors || null);
|
|
414
432
|
} else {
|
|
415
433
|
setGeneralError(error.message);
|
|
416
434
|
}
|
|
@@ -434,7 +452,7 @@ var useForm = function useForm() {
|
|
|
434
452
|
credentials: 'include',
|
|
435
453
|
headers: getCSRFHeaders()
|
|
436
454
|
});
|
|
437
|
-
}, [postForm
|
|
455
|
+
}, [postForm]);
|
|
438
456
|
var submit = useCallback(function () {
|
|
439
457
|
var submitValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : value;
|
|
440
458
|
setRequestState({
|
|
@@ -444,12 +462,11 @@ var useForm = function useForm() {
|
|
|
444
462
|
});
|
|
445
463
|
setGeneralError(null);
|
|
446
464
|
setErrors(null);
|
|
447
|
-
finalPostForm(action, _objectSpread(_objectSpread({}, submitValue), {}, {
|
|
465
|
+
finalPostForm(action, _objectSpread(_objectSpread({}, submitValue || {}), {}, {
|
|
448
466
|
_token: csrfToken
|
|
449
467
|
})).then(onSubmitSuccess)["catch"](onSubmitError);
|
|
450
|
-
}, [finalPostForm, action,
|
|
468
|
+
}, [value, setGeneralError, setErrors, finalPostForm, action, csrfToken, onSubmitSuccess, onSubmitError]);
|
|
451
469
|
var onSubmit = useCallback(function (e) {
|
|
452
|
-
// console.log('form submit', e); //
|
|
453
470
|
if (withoutDefault) {
|
|
454
471
|
e.preventDefault();
|
|
455
472
|
}
|
|
@@ -459,7 +476,7 @@ var useForm = function useForm() {
|
|
|
459
476
|
// This one is very important with multiple forms
|
|
460
477
|
// Nested forms (even in portals) will bubble the onSubmit event to the parent
|
|
461
478
|
submit();
|
|
462
|
-
}, [submit,
|
|
479
|
+
}, [submit, withoutDefault, withoutPropagation]);
|
|
463
480
|
var status = null;
|
|
464
481
|
if (requestState.loading) {
|
|
465
482
|
status = 'loading';
|
|
@@ -575,6 +592,9 @@ var createObserver = function createObserver(Observer) {
|
|
|
575
592
|
};
|
|
576
593
|
var getObserver = function getObserver(Observer) {
|
|
577
594
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
595
|
+
if (Observer === null) {
|
|
596
|
+
throw new Error('Observer constructor is null');
|
|
597
|
+
}
|
|
578
598
|
var observerKey = getOptionsKey(options);
|
|
579
599
|
if (!observersCache.has(Observer)) {
|
|
580
600
|
observersCache.set(Observer, {});
|
|
@@ -610,7 +630,7 @@ var useObserver = function useObserver(Observer) {
|
|
|
610
630
|
return setEntry(newEntry);
|
|
611
631
|
};
|
|
612
632
|
var unsubscribe = null;
|
|
613
|
-
if (nodeElement !== null) {
|
|
633
|
+
if (nodeElement !== null && Observer !== null) {
|
|
614
634
|
var newOpts = {};
|
|
615
635
|
if (root !== null) {
|
|
616
636
|
newOpts.root = root;
|
|
@@ -629,7 +649,7 @@ var useObserver = function useObserver(Observer) {
|
|
|
629
649
|
}
|
|
630
650
|
currentElement.current = nodeElement;
|
|
631
651
|
return function () {
|
|
632
|
-
if (unsubscribe !== null) {
|
|
652
|
+
if (unsubscribe !== null && nodeElement !== null) {
|
|
633
653
|
unsubscribe(nodeElement, callback);
|
|
634
654
|
}
|
|
635
655
|
};
|
|
@@ -675,6 +695,7 @@ var useIntersectionObserver = function useIntersectionObserver() {
|
|
|
675
695
|
/**
|
|
676
696
|
* Resize Observer
|
|
677
697
|
*/
|
|
698
|
+
|
|
678
699
|
var resizeObserverInitialEntry = {
|
|
679
700
|
target: null,
|
|
680
701
|
contentRect: null,
|
|
@@ -690,7 +711,7 @@ var useResizeObserver = function useResizeObserver() {
|
|
|
690
711
|
}, resizeObserverInitialEntry);
|
|
691
712
|
};
|
|
692
713
|
|
|
693
|
-
|
|
714
|
+
function useIsVisible() {
|
|
694
715
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
695
716
|
rootMargin = _ref.rootMargin,
|
|
696
717
|
_ref$threshold = _ref.threshold,
|
|
@@ -712,7 +733,7 @@ var useIsVisible = function useIsVisible() {
|
|
|
712
733
|
ref: ref,
|
|
713
734
|
visible: isVisible
|
|
714
735
|
};
|
|
715
|
-
}
|
|
736
|
+
}
|
|
716
737
|
|
|
717
738
|
var KEYCODES = {
|
|
718
739
|
ARROW_LEFT: 37,
|
|
@@ -722,7 +743,7 @@ var KEYCODES = {
|
|
|
722
743
|
ESCAPE: 27,
|
|
723
744
|
SPACE: 32
|
|
724
745
|
};
|
|
725
|
-
|
|
746
|
+
function useKeyboardKeys() {
|
|
726
747
|
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
727
748
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
728
749
|
_ref$eventName = _ref.eventName,
|
|
@@ -743,7 +764,7 @@ var useKeyboardKeys = function useKeyboardKeys() {
|
|
|
743
764
|
document.removeEventListener(eventName, onKeyDown);
|
|
744
765
|
};
|
|
745
766
|
}, [].concat(keysNames, _toConsumableArray(keysListeners), [eventName]));
|
|
746
|
-
}
|
|
767
|
+
}
|
|
747
768
|
|
|
748
769
|
var fontsMap = {
|
|
749
770
|
loading: [],
|
|
@@ -868,13 +889,13 @@ var useMediaApi = function useMediaApi() {
|
|
|
868
889
|
playing = _useState8[0],
|
|
869
890
|
setPlaying = _useState8[1];
|
|
870
891
|
var _useState9 = useState(false),
|
|
871
|
-
|
|
872
|
-
ready =
|
|
873
|
-
setReady =
|
|
874
|
-
var
|
|
875
|
-
|
|
876
|
-
initialPlay =
|
|
877
|
-
setInitialPlay =
|
|
892
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
893
|
+
ready = _useState0[0],
|
|
894
|
+
setReady = _useState0[1];
|
|
895
|
+
var _useState1 = useState(true),
|
|
896
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
897
|
+
initialPlay = _useState10[0],
|
|
898
|
+
setInitialPlay = _useState10[1];
|
|
878
899
|
var progressStepsReached = useRef({});
|
|
879
900
|
var paused = !playing;
|
|
880
901
|
|
|
@@ -1130,11 +1151,9 @@ var useResourceUrlGenerator = function useResourceUrlGenerator() {
|
|
|
1130
1151
|
var _ref = finalResource || {},
|
|
1131
1152
|
_ref$id = _ref.id,
|
|
1132
1153
|
id = _ref$id === void 0 ? null : _ref$id;
|
|
1133
|
-
// console.log('route name', finalRouteName, id, finalParams);
|
|
1134
1154
|
var finalRoute = id !== null ? route("resources.".concat(finalRouteName), _objectSpread(_objectSpread({}, finalParams), {}, {
|
|
1135
1155
|
resource: id
|
|
1136
1156
|
})) : null;
|
|
1137
|
-
// console.log('route', finalRoute);
|
|
1138
1157
|
return finalRoute;
|
|
1139
1158
|
};
|
|
1140
1159
|
};
|
|
@@ -1146,7 +1165,7 @@ var useQuery = function useQuery() {
|
|
|
1146
1165
|
return paginated ? _objectSpread({
|
|
1147
1166
|
page: 1,
|
|
1148
1167
|
count: 10
|
|
1149
|
-
}, initialBaseQuery) : initialBaseQuery || null;
|
|
1168
|
+
}, initialBaseQuery || {}) : initialBaseQuery || null;
|
|
1150
1169
|
}, [paginated, initialBaseQuery]);
|
|
1151
1170
|
var _useState = useState(initialQuery),
|
|
1152
1171
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -1156,16 +1175,16 @@ var useQuery = function useQuery() {
|
|
|
1156
1175
|
setQuery(initialQuery);
|
|
1157
1176
|
}, [initialQuery, setQuery]);
|
|
1158
1177
|
var onPageChange = useCallback(function (newPage) {
|
|
1159
|
-
setQuery(_objectSpread(_objectSpread({}, query), {}, {
|
|
1178
|
+
setQuery(_objectSpread(_objectSpread({}, query || {}), {}, {
|
|
1160
1179
|
page: newPage || 1
|
|
1161
1180
|
}));
|
|
1162
1181
|
}, [query, setQuery]);
|
|
1163
1182
|
var onQueryChange = useCallback(function (newQuery) {
|
|
1164
1183
|
var finalQuery = newQuery !== null ? Object.keys(newQuery).reduce(function (currentQuery, key) {
|
|
1165
1184
|
var val = newQuery[key];
|
|
1166
|
-
return val !== null ? _objectSpread(_objectSpread({}, currentQuery), {}, _defineProperty({}, key, val)) : currentQuery;
|
|
1185
|
+
return val !== null ? _objectSpread(_objectSpread({}, currentQuery || {}), {}, _defineProperty({}, key, val)) : currentQuery;
|
|
1167
1186
|
}, null) : null;
|
|
1168
|
-
setQuery(_objectSpread(_objectSpread({}, initialQuery ||
|
|
1187
|
+
setQuery(_objectSpread(_objectSpread({}, initialQuery || {}), finalQuery || {}));
|
|
1169
1188
|
}, [query, setQuery, initialQuery]);
|
|
1170
1189
|
var onQueryReset = useCallback(function () {
|
|
1171
1190
|
setQuery(initialQuery);
|
|
@@ -1178,7 +1197,8 @@ var useQuery = function useQuery() {
|
|
|
1178
1197
|
};
|
|
1179
1198
|
};
|
|
1180
1199
|
|
|
1181
|
-
var _excluded = ["width", "height"]
|
|
1200
|
+
var _excluded = ["width", "height"],
|
|
1201
|
+
_excluded2 = ["withoutMaxSize"];
|
|
1182
1202
|
var useScreenSize = function useScreenSize(_ref) {
|
|
1183
1203
|
var _ref$width = _ref.width,
|
|
1184
1204
|
width = _ref$width === void 0 ? null : _ref$width,
|
|
@@ -1239,7 +1259,8 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
1239
1259
|
var semiFinalHeight = height !== null ? height : calculatedHeight;
|
|
1240
1260
|
var landscape = semiFinalHeight > 0 && semiFinalWidth > semiFinalHeight;
|
|
1241
1261
|
var _opts$withoutMaxSize = opts.withoutMaxSize,
|
|
1242
|
-
withoutMaxSize = _opts$withoutMaxSize === void 0 ? false : _opts$withoutMaxSize
|
|
1262
|
+
withoutMaxSize = _opts$withoutMaxSize === void 0 ? false : _opts$withoutMaxSize,
|
|
1263
|
+
restOpts = _objectWithoutProperties(opts, _excluded2);
|
|
1243
1264
|
var finalWidth = landscape && !withoutMaxSize ? Math.round(Math.max(320, 0.45 * semiFinalHeight)) : semiFinalWidth;
|
|
1244
1265
|
var finalHeight = landscape && !withoutMaxSize ? Math.round(Math.max(533, 0.75 * semiFinalHeight)) : semiFinalHeight;
|
|
1245
1266
|
if (finalWidth % 2 === 1) {
|
|
@@ -1252,7 +1273,7 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
1252
1273
|
width: finalWidth,
|
|
1253
1274
|
height: finalHeight,
|
|
1254
1275
|
landscape: landscape
|
|
1255
|
-
},
|
|
1276
|
+
}, restOpts));
|
|
1256
1277
|
return {
|
|
1257
1278
|
ref: ref,
|
|
1258
1279
|
screenSize: screenSize
|
|
@@ -1261,10 +1282,11 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
1261
1282
|
var getWindowSize = function getWindowSize() {
|
|
1262
1283
|
return {
|
|
1263
1284
|
width: typeof window !== 'undefined' ? window.innerWidth : null,
|
|
1264
|
-
height: typeof window !== 'undefined' ? window.
|
|
1285
|
+
height: typeof window !== 'undefined' ? window.innerHeight : null
|
|
1265
1286
|
};
|
|
1266
1287
|
};
|
|
1267
|
-
var useScreenSizeFromWindow = function useScreenSizeFromWindow(
|
|
1288
|
+
var useScreenSizeFromWindow = function useScreenSizeFromWindow() {
|
|
1289
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1268
1290
|
var _useState = useState(getWindowSize()),
|
|
1269
1291
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1270
1292
|
windowSize = _useState2[0],
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
2
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
4
3
|
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import { pascalCase } from 'change-case';
|
|
6
6
|
import ReactIs from 'react-is';
|
|
7
7
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
@@ -258,7 +258,6 @@ var getComponentFromName = function getComponentFromName() {
|
|
|
258
258
|
return defaultComponent;
|
|
259
259
|
}
|
|
260
260
|
var pascalName = pascalCase(name);
|
|
261
|
-
// console.log(name, pascalName, components);
|
|
262
261
|
var component = components[pascalName] || components[name] || defaultComponent;
|
|
263
262
|
if (!component) {
|
|
264
263
|
console.warn('Could not find component from name', name, pascalName, components);
|
|
@@ -270,6 +269,7 @@ var ComponentsManager = /*#__PURE__*/function () {
|
|
|
270
269
|
function ComponentsManager() {
|
|
271
270
|
var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
272
271
|
_classCallCheck(this, ComponentsManager);
|
|
272
|
+
_defineProperty(this, "components", void 0);
|
|
273
273
|
this.components = _flattenComponents(components);
|
|
274
274
|
}
|
|
275
275
|
return _createClass(ComponentsManager, [{
|
|
@@ -337,6 +337,7 @@ var DefinitionsManager = /*#__PURE__*/function () {
|
|
|
337
337
|
function DefinitionsManager() {
|
|
338
338
|
var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
339
339
|
_classCallCheck(this, DefinitionsManager);
|
|
340
|
+
_defineProperty(this, "definitions", void 0);
|
|
340
341
|
this.definitions = definitions || [];
|
|
341
342
|
}
|
|
342
343
|
return _createClass(DefinitionsManager, [{
|
|
@@ -404,6 +405,9 @@ var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
404
405
|
var _this;
|
|
405
406
|
_classCallCheck(this, EventsManager);
|
|
406
407
|
_this = _callSuper(this, EventsManager);
|
|
408
|
+
_defineProperty(_this, "element", void 0);
|
|
409
|
+
_defineProperty(_this, "events", void 0);
|
|
410
|
+
_defineProperty(_this, "listeners", void 0);
|
|
407
411
|
_this.element = element;
|
|
408
412
|
_this.events = {};
|
|
409
413
|
_this.listeners = {};
|
|
@@ -459,7 +463,7 @@ var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
459
463
|
}]);
|
|
460
464
|
}(EventEmitter);
|
|
461
465
|
|
|
462
|
-
var FieldsManager
|
|
466
|
+
var FieldsManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
463
467
|
function FieldsManager() {
|
|
464
468
|
_classCallCheck(this, FieldsManager);
|
|
465
469
|
return _callSuper(this, FieldsManager, arguments);
|
|
@@ -474,6 +478,8 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
474
478
|
var fieldsManager = _ref.fieldsManager,
|
|
475
479
|
screensManager = _ref.screensManager;
|
|
476
480
|
_classCallCheck(this, FontsParser);
|
|
481
|
+
_defineProperty(this, "fieldsManager", void 0);
|
|
482
|
+
_defineProperty(this, "screensManager", void 0);
|
|
477
483
|
this.fieldsManager = fieldsManager;
|
|
478
484
|
this.screensManager = screensManager;
|
|
479
485
|
}
|
|
@@ -505,10 +511,10 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
505
511
|
|
|
506
512
|
// Extract fonts from theme
|
|
507
513
|
if (theme !== null) {
|
|
508
|
-
var
|
|
509
|
-
|
|
510
|
-
themeFonts =
|
|
511
|
-
newTheme = _objectWithoutProperties(
|
|
514
|
+
var _ref4 = this.parse(theme),
|
|
515
|
+
_ref4$fonts = _ref4.fonts,
|
|
516
|
+
themeFonts = _ref4$fonts === void 0 ? [] : _ref4$fonts,
|
|
517
|
+
newTheme = _objectWithoutProperties(_ref4, _excluded$2);
|
|
512
518
|
return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
513
519
|
theme: newTheme,
|
|
514
520
|
fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
|
|
@@ -545,16 +551,16 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
545
551
|
}
|
|
546
552
|
}], [{
|
|
547
553
|
key: "fieldIsFontFamily",
|
|
548
|
-
value: function fieldIsFontFamily(
|
|
549
|
-
var
|
|
550
|
-
id =
|
|
554
|
+
value: function fieldIsFontFamily(_ref5) {
|
|
555
|
+
var _ref5$id = _ref5.id,
|
|
556
|
+
id = _ref5$id === void 0 ? null : _ref5$id;
|
|
551
557
|
return id === 'font-family';
|
|
552
558
|
}
|
|
553
559
|
}, {
|
|
554
560
|
key: "valueIsFont",
|
|
555
|
-
value: function valueIsFont(
|
|
556
|
-
var
|
|
557
|
-
type =
|
|
561
|
+
value: function valueIsFont(_ref6) {
|
|
562
|
+
var _ref6$type = _ref6.type,
|
|
563
|
+
type = _ref6$type === void 0 ? null : _ref6$type;
|
|
558
564
|
return type === 'custom' || type === 'google';
|
|
559
565
|
}
|
|
560
566
|
}, {
|
|
@@ -584,13 +590,13 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
584
590
|
}]);
|
|
585
591
|
}();
|
|
586
592
|
|
|
587
|
-
var
|
|
588
|
-
function
|
|
589
|
-
_classCallCheck(this,
|
|
590
|
-
return _callSuper(this,
|
|
593
|
+
var FormsManager = /*#__PURE__*/function (_ComponentsManager) {
|
|
594
|
+
function FormsManager() {
|
|
595
|
+
_classCallCheck(this, FormsManager);
|
|
596
|
+
return _callSuper(this, FormsManager, arguments);
|
|
591
597
|
}
|
|
592
|
-
_inherits(
|
|
593
|
-
return _createClass(
|
|
598
|
+
_inherits(FormsManager, _ComponentsManager);
|
|
599
|
+
return _createClass(FormsManager);
|
|
594
600
|
}(ComponentsManager);
|
|
595
601
|
|
|
596
602
|
var _excluded$1 = ["medias"];
|
|
@@ -599,6 +605,8 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
599
605
|
var fieldsManager = _ref.fieldsManager,
|
|
600
606
|
screensManager = _ref.screensManager;
|
|
601
607
|
_classCallCheck(this, MediasParser);
|
|
608
|
+
_defineProperty(this, "fieldsManager", void 0);
|
|
609
|
+
_defineProperty(this, "screensManager", void 0);
|
|
602
610
|
this.fieldsManager = fieldsManager;
|
|
603
611
|
this.screensManager = screensManager;
|
|
604
612
|
}
|
|
@@ -638,9 +646,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
638
646
|
newComponents = _components$reduce.components,
|
|
639
647
|
medias = _components$reduce.medias;
|
|
640
648
|
if (theme !== null) {
|
|
641
|
-
var
|
|
642
|
-
themeMedias =
|
|
643
|
-
newTheme = _objectWithoutProperties(
|
|
649
|
+
var _ref5 = this.toPath(theme),
|
|
650
|
+
themeMedias = _ref5.medias,
|
|
651
|
+
newTheme = _objectWithoutProperties(_ref5, _excluded$1);
|
|
644
652
|
return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
645
653
|
theme: newTheme,
|
|
646
654
|
components: newComponents,
|
|
@@ -662,13 +670,13 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
662
670
|
if (story === null) {
|
|
663
671
|
return story;
|
|
664
672
|
}
|
|
665
|
-
var
|
|
666
|
-
|
|
667
|
-
theme =
|
|
668
|
-
|
|
669
|
-
components =
|
|
670
|
-
|
|
671
|
-
medias =
|
|
673
|
+
var _ref6 = story || {},
|
|
674
|
+
_ref6$theme = _ref6.theme,
|
|
675
|
+
theme = _ref6$theme === void 0 ? null : _ref6$theme,
|
|
676
|
+
_ref6$components = _ref6.components,
|
|
677
|
+
components = _ref6$components === void 0 ? [] : _ref6$components,
|
|
678
|
+
_ref6$medias = _ref6.medias,
|
|
679
|
+
medias = _ref6$medias === void 0 ? defaultMedias : _ref6$medias;
|
|
672
680
|
if (medias === null && theme === null) {
|
|
673
681
|
return story;
|
|
674
682
|
}
|
|
@@ -676,9 +684,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
676
684
|
// Replace path with medias objects
|
|
677
685
|
var newComponents = medias !== null ? components.map(function (screen) {
|
|
678
686
|
var type = screen.type;
|
|
679
|
-
var
|
|
680
|
-
|
|
681
|
-
fields =
|
|
687
|
+
var _ref7 = _this2.screensManager.getDefinition(type) || {},
|
|
688
|
+
_ref7$fields = _ref7.fields,
|
|
689
|
+
fields = _ref7$fields === void 0 ? [] : _ref7$fields;
|
|
682
690
|
var fieldsPattern = _this2.getMediaFieldsPattern(fields);
|
|
683
691
|
return MediasParser.replacePathsWithMedias(screen, medias, fieldsPattern);
|
|
684
692
|
}) : components;
|
|
@@ -722,16 +730,16 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
722
730
|
}
|
|
723
731
|
}], [{
|
|
724
732
|
key: "fieldIsMedia",
|
|
725
|
-
value: function fieldIsMedia(
|
|
726
|
-
var
|
|
727
|
-
media =
|
|
733
|
+
value: function fieldIsMedia(_ref8) {
|
|
734
|
+
var _ref8$media = _ref8.media,
|
|
735
|
+
media = _ref8$media === void 0 ? false : _ref8$media;
|
|
728
736
|
return media;
|
|
729
737
|
}
|
|
730
738
|
}, {
|
|
731
739
|
key: "fieldIsFontFamily",
|
|
732
|
-
value: function fieldIsFontFamily(
|
|
733
|
-
var
|
|
734
|
-
id =
|
|
740
|
+
value: function fieldIsFontFamily(_ref9) {
|
|
741
|
+
var _ref9$id = _ref9.id,
|
|
742
|
+
id = _ref9$id === void 0 ? null : _ref9$id;
|
|
735
743
|
return id === 'font-family';
|
|
736
744
|
}
|
|
737
745
|
}, {
|
|
@@ -759,9 +767,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
759
767
|
}
|
|
760
768
|
}, {
|
|
761
769
|
key: "getMediaPath",
|
|
762
|
-
value: function getMediaPath(
|
|
763
|
-
var
|
|
764
|
-
id =
|
|
770
|
+
value: function getMediaPath(_ref0) {
|
|
771
|
+
var _ref0$id = _ref0.id,
|
|
772
|
+
id = _ref0$id === void 0 ? null : _ref0$id;
|
|
765
773
|
return id !== null ? "media://".concat(id) : null;
|
|
766
774
|
}
|
|
767
775
|
}, {
|
|
@@ -771,9 +779,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
771
779
|
var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
772
780
|
var dataIsArray = isArray(data);
|
|
773
781
|
var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
|
|
774
|
-
return keys.reduce(function (
|
|
775
|
-
var currentData =
|
|
776
|
-
currentMedias =
|
|
782
|
+
return keys.reduce(function (_ref1, key) {
|
|
783
|
+
var currentData = _ref1.data,
|
|
784
|
+
currentMedias = _ref1.medias;
|
|
777
785
|
var path = [keyPrefix, key].filter(function (it) {
|
|
778
786
|
return it !== null;
|
|
779
787
|
}).join('.');
|
|
@@ -815,6 +823,7 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
815
823
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
816
824
|
_classCallCheck(this, Tracking);
|
|
817
825
|
_this = _callSuper(this, Tracking, [opts]);
|
|
826
|
+
_defineProperty(_this, "variables", void 0);
|
|
818
827
|
var _this$options$variabl = _this.options.variables,
|
|
819
828
|
variables = _this$options$variabl === void 0 ? null : _this$options$variabl;
|
|
820
829
|
_this.variables = null;
|
|
@@ -901,4 +910,4 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
901
910
|
}]);
|
|
902
911
|
}(Tracking$1);
|
|
903
912
|
|
|
904
|
-
export { ComponentsManager, DefinitionsManager, EventsManager, FieldsManager
|
|
913
|
+
export { ComponentsManager, DefinitionsManager, EventsManager, FieldsManager, FontsParser, FormsManager, MediasParser, PropTypes, Tracking };
|