@panneau/core 1.0.3-alpha.1 → 1.0.3
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 +302 -358
- package/es/hooks.js +201 -319
- package/es/index.js +114 -215
- package/es/utils.js +75 -77
- package/lib/contexts.js +303 -358
- package/lib/hooks.js +200 -318
- package/lib/index.js +114 -215
- package/lib/utils.js +76 -76
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -29,10 +29,10 @@ var message = PropTypes$1.shape({
|
|
|
29
29
|
});
|
|
30
30
|
var label = PropTypes$1.oneOfType([message, PropTypes$1.node]);
|
|
31
31
|
var statusCode = PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string]);
|
|
32
|
+
|
|
32
33
|
/**
|
|
33
34
|
* Core
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
36
|
var menuItem = PropTypes$1.shape({
|
|
37
37
|
id: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string]),
|
|
38
38
|
label: label,
|
|
@@ -71,10 +71,10 @@ var tableColumn = PropTypes$1.shape({
|
|
|
71
71
|
columnClassName: PropTypes$1.string
|
|
72
72
|
});
|
|
73
73
|
var tableColumns = PropTypes$1.arrayOf(tableColumn);
|
|
74
|
+
|
|
74
75
|
/**
|
|
75
76
|
* Panneau Definitions
|
|
76
77
|
*/
|
|
77
|
-
|
|
78
78
|
var routes = PropTypes$1.shape({
|
|
79
79
|
'resources.index': PropTypes$1.string.isRequired,
|
|
80
80
|
'resources.create': PropTypes$1.string.isRequired,
|
|
@@ -121,15 +121,17 @@ var panneauDefinition = PropTypes$1.shape({
|
|
|
121
121
|
resources: resources,
|
|
122
122
|
routes: routes,
|
|
123
123
|
pages: pages,
|
|
124
|
-
intl: intl
|
|
125
|
-
|
|
124
|
+
intl: intl
|
|
125
|
+
// intl,
|
|
126
126
|
});
|
|
127
|
+
|
|
127
128
|
var definition = PropTypes$1.shape({
|
|
128
|
-
name: PropTypes$1.string
|
|
129
|
+
name: PropTypes$1.string
|
|
130
|
+
// resources,
|
|
129
131
|
// routes,
|
|
130
132
|
// intl,
|
|
131
|
-
|
|
132
133
|
});
|
|
134
|
+
|
|
133
135
|
var item = PropTypes$1.shape({
|
|
134
136
|
id: PropTypes$1.string.isRequired
|
|
135
137
|
});
|
|
@@ -203,11 +205,9 @@ var PropTypes = /*#__PURE__*/Object.freeze({
|
|
|
203
205
|
|
|
204
206
|
var flattenComponents = function flattenComponents(components) {
|
|
205
207
|
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
206
|
-
|
|
207
208
|
if (components === null) {
|
|
208
209
|
return null;
|
|
209
210
|
}
|
|
210
|
-
|
|
211
211
|
return Object.keys(components).reduce(function (newMap, key) {
|
|
212
212
|
return ReactIs.isValidElementType(components[key]) ? _objectSpread(_objectSpread({}, newMap), {}, _defineProperty({}, prefix !== null ? "".concat(prefix, ".").concat(key) : key, components[key])) : _objectSpread(_objectSpread({}, newMap), flattenComponents(components[key], key));
|
|
213
213
|
}, {});
|
|
@@ -217,38 +217,30 @@ var getComponentFromName = function getComponentFromName() {
|
|
|
217
217
|
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
218
218
|
var components = arguments.length > 1 ? arguments[1] : undefined;
|
|
219
219
|
var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
220
|
-
|
|
221
220
|
if (components === null || name === null) {
|
|
222
221
|
return defaultComponent;
|
|
223
222
|
}
|
|
224
|
-
|
|
225
223
|
var pascalName = pascalCase(name);
|
|
226
224
|
var component = components[pascalName] || components[name] || defaultComponent;
|
|
227
|
-
|
|
228
225
|
if (!component) {
|
|
229
226
|
console.warn('Could not find component from name', name, pascalName, components);
|
|
230
227
|
}
|
|
231
|
-
|
|
232
228
|
return component;
|
|
233
229
|
};
|
|
234
230
|
|
|
231
|
+
new EventEmitter();
|
|
232
|
+
|
|
235
233
|
var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
236
234
|
_inherits(ComponentsManager, _EventEmitter);
|
|
237
|
-
|
|
238
235
|
var _super = _createSuper(ComponentsManager);
|
|
239
|
-
|
|
240
236
|
function ComponentsManager() {
|
|
241
237
|
var _this;
|
|
242
|
-
|
|
243
238
|
var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
244
|
-
|
|
245
239
|
_classCallCheck(this, ComponentsManager);
|
|
246
|
-
|
|
247
240
|
_this = _super.call(this);
|
|
248
241
|
_this.components = flattenComponents(components);
|
|
249
242
|
return _this;
|
|
250
243
|
}
|
|
251
|
-
|
|
252
244
|
_createClass(ComponentsManager, [{
|
|
253
245
|
key: "addComponent",
|
|
254
246
|
value: function addComponent(name, component) {
|
|
@@ -276,11 +268,9 @@ var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
276
268
|
key: "addNamespace",
|
|
277
269
|
value: function addNamespace(namespace) {
|
|
278
270
|
var _this2 = this;
|
|
279
|
-
|
|
280
271
|
if (namespace === null) {
|
|
281
272
|
return this;
|
|
282
273
|
}
|
|
283
|
-
|
|
284
274
|
this.components = Object.keys(this.components).reduce(function (componentsMap, name) {
|
|
285
275
|
return _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), _this2.components[name]));
|
|
286
276
|
}, {});
|
|
@@ -297,7 +287,6 @@ var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
297
287
|
key: "getComponents",
|
|
298
288
|
value: function getComponents() {
|
|
299
289
|
var _this3 = this;
|
|
300
|
-
|
|
301
290
|
var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
302
291
|
return namespace !== null ? Object.keys(this.components || {}).reduce(function (componentsMap, name) {
|
|
303
292
|
var pattern = new RegExp("^".concat(namespace, "\\.(.*)$"));
|
|
@@ -312,27 +301,20 @@ var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
312
301
|
return this.components !== null && typeof this.components[namespace !== null ? "".concat(namespace, ".").concat(name) : name] !== 'undefined';
|
|
313
302
|
}
|
|
314
303
|
}]);
|
|
315
|
-
|
|
316
304
|
return ComponentsManager;
|
|
317
305
|
}(EventEmitter);
|
|
318
306
|
|
|
319
307
|
var DefinitionsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
320
308
|
_inherits(DefinitionsManager, _EventEmitter);
|
|
321
|
-
|
|
322
309
|
var _super = _createSuper(DefinitionsManager);
|
|
323
|
-
|
|
324
310
|
function DefinitionsManager() {
|
|
325
311
|
var _this;
|
|
326
|
-
|
|
327
312
|
var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
328
|
-
|
|
329
313
|
_classCallCheck(this, DefinitionsManager);
|
|
330
|
-
|
|
331
314
|
_this = _super.call(this);
|
|
332
315
|
_this.definitions = definitions || [];
|
|
333
316
|
return _this;
|
|
334
317
|
}
|
|
335
|
-
|
|
336
318
|
_createClass(DefinitionsManager, [{
|
|
337
319
|
key: "addDefinition",
|
|
338
320
|
value: function addDefinition(definition) {
|
|
@@ -359,7 +341,6 @@ var DefinitionsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
359
341
|
if (id === null) {
|
|
360
342
|
return null;
|
|
361
343
|
}
|
|
362
|
-
|
|
363
344
|
return this.definitions.find(function (it) {
|
|
364
345
|
return it.id === id;
|
|
365
346
|
}) || null;
|
|
@@ -378,9 +359,8 @@ var DefinitionsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
378
359
|
key: "getComponent",
|
|
379
360
|
value: function getComponent(id) {
|
|
380
361
|
var _ref = this.getDefinition(id) || {},
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
362
|
+
_ref$component = _ref.component,
|
|
363
|
+
component = _ref$component === void 0 ? null : _ref$component;
|
|
384
364
|
return component;
|
|
385
365
|
}
|
|
386
366
|
}, {
|
|
@@ -388,39 +368,32 @@ var DefinitionsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
388
368
|
value: function getComponents() {
|
|
389
369
|
return this.definitions.reduce(function (allComponents, _ref2) {
|
|
390
370
|
var id = _ref2.id,
|
|
391
|
-
|
|
392
|
-
|
|
371
|
+
_ref2$component = _ref2.component,
|
|
372
|
+
component = _ref2$component === void 0 ? null : _ref2$component;
|
|
393
373
|
return component !== null ? _objectSpread(_objectSpread({}, allComponents), {}, _defineProperty({}, id, component)) : allComponents;
|
|
394
374
|
}, {});
|
|
395
375
|
}
|
|
396
376
|
}]);
|
|
397
|
-
|
|
398
377
|
return DefinitionsManager;
|
|
399
378
|
}(EventEmitter);
|
|
400
379
|
|
|
401
380
|
var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
402
381
|
_inherits(EventsManager, _EventEmitter);
|
|
403
|
-
|
|
404
382
|
var _super = _createSuper(EventsManager);
|
|
405
|
-
|
|
406
383
|
function EventsManager(element) {
|
|
407
384
|
var _this;
|
|
408
|
-
|
|
409
385
|
_classCallCheck(this, EventsManager);
|
|
410
|
-
|
|
411
386
|
_this = _super.call(this);
|
|
412
387
|
_this.element = element;
|
|
413
388
|
_this.events = {};
|
|
414
389
|
_this.listeners = {};
|
|
415
390
|
return _this;
|
|
416
391
|
}
|
|
417
|
-
|
|
418
392
|
_createClass(EventsManager, [{
|
|
419
393
|
key: "subscribe",
|
|
420
394
|
value: function subscribe(event, callback) {
|
|
421
395
|
this.on(event, callback);
|
|
422
396
|
this.events = _objectSpread(_objectSpread({}, this.events), {}, _defineProperty({}, event, [].concat(_toConsumableArray(this.events[event] || []), [callback])));
|
|
423
|
-
|
|
424
397
|
if (this.events[event].length === 1) {
|
|
425
398
|
this.addEventListener(event);
|
|
426
399
|
}
|
|
@@ -429,20 +402,16 @@ var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
429
402
|
key: "unsubscribe",
|
|
430
403
|
value: function unsubscribe(event, callback) {
|
|
431
404
|
var _this2 = this;
|
|
432
|
-
|
|
433
405
|
this.off(event, callback);
|
|
434
406
|
this.events = Object.keys(this.events).reduce(function (newEvents, eventName) {
|
|
435
407
|
if (eventName !== event) {
|
|
436
408
|
return _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, _this2.events[eventName]));
|
|
437
409
|
}
|
|
438
|
-
|
|
439
410
|
var newListeners = _this2.events[eventName].filter(function (listener) {
|
|
440
411
|
return listener !== callback;
|
|
441
412
|
});
|
|
442
|
-
|
|
443
413
|
return newListeners.length > 0 ? _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, newListeners)) : newEvents;
|
|
444
414
|
}, {});
|
|
445
|
-
|
|
446
415
|
if (typeof this.events[event] === 'undefined') {
|
|
447
416
|
this.removeEventListener(event);
|
|
448
417
|
}
|
|
@@ -451,17 +420,14 @@ var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
451
420
|
key: "addEventListener",
|
|
452
421
|
value: function addEventListener(event) {
|
|
453
422
|
var _this3 = this;
|
|
454
|
-
|
|
455
423
|
if (typeof this.listeners[event] === 'undefined') {
|
|
456
424
|
this.listeners[event] = function () {
|
|
457
425
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
458
426
|
args[_key] = arguments[_key];
|
|
459
427
|
}
|
|
460
|
-
|
|
461
428
|
return _this3.emit.apply(_this3, [event].concat(args));
|
|
462
429
|
};
|
|
463
430
|
}
|
|
464
|
-
|
|
465
431
|
this.element.addEventListener(event, this.listeners[event]);
|
|
466
432
|
}
|
|
467
433
|
}, {
|
|
@@ -470,79 +436,65 @@ var EventsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
470
436
|
this.element.removeEventListener(event, this.listeners[event]);
|
|
471
437
|
}
|
|
472
438
|
}]);
|
|
473
|
-
|
|
474
439
|
return EventsManager;
|
|
475
440
|
}(EventEmitter);
|
|
476
441
|
|
|
477
442
|
var FieldsManager$1 = /*#__PURE__*/function (_DefinitionsManager) {
|
|
478
443
|
_inherits(FieldsManager, _DefinitionsManager);
|
|
479
|
-
|
|
480
444
|
var _super = _createSuper(FieldsManager);
|
|
481
|
-
|
|
482
445
|
function FieldsManager() {
|
|
483
446
|
_classCallCheck(this, FieldsManager);
|
|
484
|
-
|
|
485
447
|
return _super.apply(this, arguments);
|
|
486
448
|
}
|
|
487
|
-
|
|
488
449
|
return _createClass(FieldsManager);
|
|
489
450
|
}(DefinitionsManager);
|
|
490
451
|
|
|
491
452
|
var _excluded$2 = ["fonts"];
|
|
492
|
-
|
|
493
453
|
var FontsParser = /*#__PURE__*/function () {
|
|
494
454
|
function FontsParser(_ref) {
|
|
495
455
|
var fieldsManager = _ref.fieldsManager,
|
|
496
|
-
|
|
497
|
-
|
|
456
|
+
screensManager = _ref.screensManager;
|
|
498
457
|
_classCallCheck(this, FontsParser);
|
|
499
|
-
|
|
500
458
|
this.fieldsManager = fieldsManager;
|
|
501
459
|
this.screensManager = screensManager;
|
|
502
|
-
}
|
|
503
|
-
|
|
460
|
+
}
|
|
504
461
|
|
|
462
|
+
// Extract fonts
|
|
505
463
|
_createClass(FontsParser, [{
|
|
506
464
|
key: "parse",
|
|
507
465
|
value: function parse(story) {
|
|
508
466
|
var _this = this;
|
|
509
|
-
|
|
510
467
|
if (story === null) {
|
|
511
468
|
return story;
|
|
512
|
-
}
|
|
513
|
-
|
|
469
|
+
}
|
|
514
470
|
|
|
471
|
+
// Extract fonts from screen
|
|
515
472
|
var _ref2 = story || {},
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
473
|
+
_ref2$theme = _ref2.theme,
|
|
474
|
+
theme = _ref2$theme === void 0 ? null : _ref2$theme,
|
|
475
|
+
_ref2$components = _ref2.components,
|
|
476
|
+
components = _ref2$components === void 0 ? [] : _ref2$components;
|
|
521
477
|
var fonts = uniq(components.reduce(function (currentFonts, screen) {
|
|
522
478
|
var type = screen.type;
|
|
523
|
-
|
|
524
479
|
var _ref3 = _this.screensManager.getDefinition(type) || {},
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
480
|
+
_ref3$fields = _ref3.fields,
|
|
481
|
+
fields = _ref3$fields === void 0 ? [] : _ref3$fields;
|
|
528
482
|
var fieldsPattern = _this.getFieldsPattern(fields);
|
|
529
|
-
|
|
530
483
|
var newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
|
|
531
484
|
return newFonts.length > 0 ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(newFonts)) : currentFonts;
|
|
532
|
-
}, []), 'name');
|
|
485
|
+
}, []), 'name');
|
|
533
486
|
|
|
487
|
+
// Extract fonts from theme
|
|
534
488
|
if (theme !== null) {
|
|
535
489
|
var _this$parse = this.parse(theme),
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
490
|
+
_this$parse$fonts = _this$parse.fonts,
|
|
491
|
+
themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
|
|
492
|
+
newTheme = _objectWithoutProperties(_this$parse, _excluded$2);
|
|
540
493
|
return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
541
494
|
theme: newTheme,
|
|
542
495
|
fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
|
|
543
496
|
}) : story;
|
|
544
497
|
}
|
|
545
|
-
|
|
546
498
|
return fonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
547
499
|
fonts: fonts
|
|
548
500
|
}) : story;
|
|
@@ -551,26 +503,24 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
551
503
|
key: "getFieldsPattern",
|
|
552
504
|
value: function getFieldsPattern(fields) {
|
|
553
505
|
var _this2 = this;
|
|
554
|
-
|
|
555
506
|
var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
556
507
|
return fields.reduce(function (patterns, field) {
|
|
557
508
|
var _field$name = field.name,
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
509
|
+
name = _field$name === void 0 ? null : _field$name,
|
|
510
|
+
_field$type = field.type,
|
|
511
|
+
type = _field$type === void 0 ? null : _field$type;
|
|
561
512
|
var path = [namePrefix, name].filter(function (it) {
|
|
562
513
|
return it !== null;
|
|
563
514
|
}).join('\\.');
|
|
515
|
+
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
|
|
564
516
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
517
|
+
// also check settings fields
|
|
568
518
|
var _fieldDefinition$fiel = fieldDefinition.fields,
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
519
|
+
subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
|
|
520
|
+
_fieldDefinition$item = fieldDefinition.itemsField,
|
|
521
|
+
itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
|
|
522
|
+
_fieldDefinition$sett = fieldDefinition.settings,
|
|
523
|
+
settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
|
|
574
524
|
return [].concat(_toConsumableArray(patterns), _toConsumableArray(FontsParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(_this2.getFieldsPattern(subFields, path)), _toConsumableArray(_this2.getFieldsPattern(settings, path)), _toConsumableArray(itemsField !== null ? _this2.getFieldsPattern([itemsField], "".concat(path, "\\.[0-9]+")) : []));
|
|
575
525
|
}, []);
|
|
576
526
|
}
|
|
@@ -578,14 +528,14 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
578
528
|
key: "fieldIsFontFamily",
|
|
579
529
|
value: function fieldIsFontFamily(_ref4) {
|
|
580
530
|
var _ref4$id = _ref4.id,
|
|
581
|
-
|
|
531
|
+
id = _ref4$id === void 0 ? null : _ref4$id;
|
|
582
532
|
return id === 'font-family';
|
|
583
533
|
}
|
|
584
534
|
}, {
|
|
585
535
|
key: "valueIsFont",
|
|
586
536
|
value: function valueIsFont(_ref5) {
|
|
587
537
|
var _ref5$type = _ref5.type,
|
|
588
|
-
|
|
538
|
+
type = _ref5$type === void 0 ? null : _ref5$type;
|
|
589
539
|
return type === 'custom' || type === 'google';
|
|
590
540
|
}
|
|
591
541
|
}, {
|
|
@@ -604,144 +554,119 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
604
554
|
var value = data[key];
|
|
605
555
|
var font = null;
|
|
606
556
|
var subFonts = null;
|
|
607
|
-
|
|
608
557
|
if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
|
|
609
558
|
font = value;
|
|
610
559
|
} else if (isObject(value) || isArray(value)) {
|
|
611
560
|
subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
|
|
612
561
|
}
|
|
613
|
-
|
|
614
562
|
return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
|
|
615
563
|
}, []);
|
|
616
564
|
}
|
|
617
565
|
}]);
|
|
618
|
-
|
|
619
566
|
return FontsParser;
|
|
620
567
|
}();
|
|
621
568
|
|
|
622
569
|
var FieldsManager = /*#__PURE__*/function (_ComponentsManager) {
|
|
623
570
|
_inherits(FieldsManager, _ComponentsManager);
|
|
624
|
-
|
|
625
571
|
var _super = _createSuper(FieldsManager);
|
|
626
|
-
|
|
627
572
|
function FieldsManager() {
|
|
628
573
|
_classCallCheck(this, FieldsManager);
|
|
629
|
-
|
|
630
574
|
return _super.apply(this, arguments);
|
|
631
575
|
}
|
|
632
|
-
|
|
633
576
|
return _createClass(FieldsManager);
|
|
634
577
|
}(ComponentsManager);
|
|
635
578
|
|
|
636
579
|
var _excluded$1 = ["medias"];
|
|
637
|
-
|
|
638
580
|
var MediasParser = /*#__PURE__*/function () {
|
|
639
581
|
function MediasParser(_ref) {
|
|
640
582
|
var fieldsManager = _ref.fieldsManager,
|
|
641
|
-
|
|
642
|
-
|
|
583
|
+
screensManager = _ref.screensManager;
|
|
643
584
|
_classCallCheck(this, MediasParser);
|
|
644
|
-
|
|
645
585
|
this.fieldsManager = fieldsManager;
|
|
646
586
|
this.screensManager = screensManager;
|
|
647
|
-
}
|
|
648
|
-
|
|
587
|
+
}
|
|
649
588
|
|
|
589
|
+
// Convert medias object to path
|
|
650
590
|
_createClass(MediasParser, [{
|
|
651
591
|
key: "toPath",
|
|
652
592
|
value: function toPath(story) {
|
|
653
593
|
var _this = this;
|
|
654
|
-
|
|
655
594
|
if (story === null) {
|
|
656
595
|
return story;
|
|
657
596
|
}
|
|
658
|
-
|
|
659
597
|
var _ref2 = story || {},
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
598
|
+
_ref2$theme = _ref2.theme,
|
|
599
|
+
theme = _ref2$theme === void 0 ? null : _ref2$theme,
|
|
600
|
+
_ref2$components = _ref2.components,
|
|
601
|
+
components = _ref2$components === void 0 ? [] : _ref2$components;
|
|
665
602
|
var _components$reduce = components.reduce(function (_ref3, screen) {
|
|
666
|
-
|
|
603
|
+
var previousComponents = _ref3.components,
|
|
667
604
|
currentMedias = _ref3.medias;
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
var _ref4 = _this.screensManager.getDefinition(type) || {},
|
|
605
|
+
var type = screen.type;
|
|
606
|
+
var _ref4 = _this.screensManager.getDefinition(type) || {},
|
|
671
607
|
_ref4$fields = _ref4.fields,
|
|
672
608
|
fields = _ref4$fields === void 0 ? [] : _ref4$fields;
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
var _MediasParser$replace = MediasParser.replaceMediasWithPaths(screen, fieldsPattern),
|
|
609
|
+
var fieldsPattern = _this.getMediaFieldsPattern(fields);
|
|
610
|
+
var _MediasParser$replace = MediasParser.replaceMediasWithPaths(screen, fieldsPattern),
|
|
677
611
|
newScreen = _MediasParser$replace.data,
|
|
678
612
|
newMedias = _MediasParser$replace.medias;
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
medias = _components$reduce.medias;
|
|
690
|
-
|
|
613
|
+
return {
|
|
614
|
+
components: [].concat(_toConsumableArray(previousComponents), [newScreen]),
|
|
615
|
+
medias: _objectSpread(_objectSpread({}, currentMedias), newMedias)
|
|
616
|
+
};
|
|
617
|
+
}, {
|
|
618
|
+
components: [],
|
|
619
|
+
medias: null
|
|
620
|
+
}),
|
|
621
|
+
newComponents = _components$reduce.components,
|
|
622
|
+
medias = _components$reduce.medias;
|
|
691
623
|
if (theme !== null) {
|
|
692
624
|
var _this$toPath = this.toPath(theme),
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
625
|
+
themeMedias = _this$toPath.medias,
|
|
626
|
+
newTheme = _objectWithoutProperties(_this$toPath, _excluded$1);
|
|
696
627
|
return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
697
628
|
theme: newTheme,
|
|
698
629
|
components: newComponents,
|
|
699
630
|
medias: _objectSpread(_objectSpread({}, themeMedias), medias)
|
|
700
631
|
}) : story;
|
|
701
632
|
}
|
|
702
|
-
|
|
703
633
|
return medias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
704
634
|
components: newComponents,
|
|
705
635
|
medias: medias
|
|
706
636
|
}) : story;
|
|
707
|
-
}
|
|
637
|
+
}
|
|
708
638
|
|
|
639
|
+
// Convert path to medias object
|
|
709
640
|
}, {
|
|
710
641
|
key: "fromPath",
|
|
711
642
|
value: function fromPath(story) {
|
|
712
643
|
var _this2 = this;
|
|
713
|
-
|
|
714
644
|
var defaultMedias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
715
|
-
|
|
716
645
|
if (story === null) {
|
|
717
646
|
return story;
|
|
718
647
|
}
|
|
719
|
-
|
|
720
648
|
var _ref5 = story || {},
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
649
|
+
_ref5$theme = _ref5.theme,
|
|
650
|
+
theme = _ref5$theme === void 0 ? null : _ref5$theme,
|
|
651
|
+
_ref5$components = _ref5.components,
|
|
652
|
+
components = _ref5$components === void 0 ? [] : _ref5$components,
|
|
653
|
+
_ref5$medias = _ref5.medias,
|
|
654
|
+
medias = _ref5$medias === void 0 ? defaultMedias : _ref5$medias;
|
|
728
655
|
if (medias === null && theme === null) {
|
|
729
656
|
return story;
|
|
730
|
-
}
|
|
731
|
-
|
|
657
|
+
}
|
|
732
658
|
|
|
659
|
+
// Replace path with medias objects
|
|
733
660
|
var newComponents = medias !== null ? components.map(function (screen) {
|
|
734
661
|
var type = screen.type;
|
|
735
|
-
|
|
736
662
|
var _ref6 = _this2.screensManager.getDefinition(type) || {},
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
663
|
+
_ref6$fields = _ref6.fields,
|
|
664
|
+
fields = _ref6$fields === void 0 ? [] : _ref6$fields;
|
|
740
665
|
var fieldsPattern = _this2.getMediaFieldsPattern(fields);
|
|
741
|
-
|
|
742
666
|
return MediasParser.replacePathsWithMedias(screen, medias, fieldsPattern);
|
|
743
|
-
}) : components;
|
|
667
|
+
}) : components;
|
|
744
668
|
|
|
669
|
+
// Replace path with medias object in theme
|
|
745
670
|
if (theme !== null) {
|
|
746
671
|
var newTheme = this.fromPath(theme, medias);
|
|
747
672
|
return newTheme !== theme || newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
|
|
@@ -749,7 +674,6 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
749
674
|
components: newComponents
|
|
750
675
|
}) : story;
|
|
751
676
|
}
|
|
752
|
-
|
|
753
677
|
return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
|
|
754
678
|
components: newComponents
|
|
755
679
|
}) : story;
|
|
@@ -758,26 +682,24 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
758
682
|
key: "getMediaFieldsPattern",
|
|
759
683
|
value: function getMediaFieldsPattern(fields) {
|
|
760
684
|
var _this3 = this;
|
|
761
|
-
|
|
762
685
|
var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
763
686
|
return fields.reduce(function (patterns, field) {
|
|
764
687
|
var _field$name = field.name,
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
688
|
+
name = _field$name === void 0 ? null : _field$name,
|
|
689
|
+
_field$type = field.type,
|
|
690
|
+
type = _field$type === void 0 ? null : _field$type;
|
|
768
691
|
var path = [namePrefix, name].filter(function (it) {
|
|
769
692
|
return it !== null;
|
|
770
693
|
}).join('\\.');
|
|
694
|
+
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this3.fieldsManager.getDefinition(type) : null), field);
|
|
771
695
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
696
|
+
// also check settings fields
|
|
775
697
|
var _fieldDefinition$fiel = fieldDefinition.fields,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
698
|
+
subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
|
|
699
|
+
_fieldDefinition$item = fieldDefinition.itemsField,
|
|
700
|
+
itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
|
|
701
|
+
_fieldDefinition$sett = fieldDefinition.settings,
|
|
702
|
+
settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
|
|
781
703
|
return [].concat(_toConsumableArray(patterns), _toConsumableArray(MediasParser.fieldIsMedia(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(MediasParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp("^".concat(path, "\\.media$"))] : []), _toConsumableArray(_this3.getMediaFieldsPattern(subFields, path)), _toConsumableArray(_this3.getMediaFieldsPattern(settings, path)), _toConsumableArray(itemsField !== null ? _this3.getMediaFieldsPattern([itemsField], "".concat(path, "\\.[0-9]+")) : []));
|
|
782
704
|
}, []);
|
|
783
705
|
}
|
|
@@ -785,14 +707,14 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
785
707
|
key: "fieldIsMedia",
|
|
786
708
|
value: function fieldIsMedia(_ref7) {
|
|
787
709
|
var _ref7$media = _ref7.media,
|
|
788
|
-
|
|
710
|
+
media = _ref7$media === void 0 ? false : _ref7$media;
|
|
789
711
|
return media;
|
|
790
712
|
}
|
|
791
713
|
}, {
|
|
792
714
|
key: "fieldIsFontFamily",
|
|
793
715
|
value: function fieldIsFontFamily(_ref8) {
|
|
794
716
|
var _ref8$id = _ref8.id,
|
|
795
|
-
|
|
717
|
+
id = _ref8$id === void 0 ? null : _ref8$id;
|
|
796
718
|
return id === 'font-family';
|
|
797
719
|
}
|
|
798
720
|
}, {
|
|
@@ -810,13 +732,11 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
810
732
|
}, false);
|
|
811
733
|
var value = data[key];
|
|
812
734
|
var newValue;
|
|
813
|
-
|
|
814
735
|
if (patternMatch) {
|
|
815
736
|
newValue = isObject(value) ? value : medias[value] || null;
|
|
816
737
|
} else {
|
|
817
738
|
newValue = isObject(value) || isArray(value) ? MediasParser.replacePathsWithMedias(value, medias, patterns, path) : value;
|
|
818
739
|
}
|
|
819
|
-
|
|
820
740
|
return dataIsArray ? [].concat(_toConsumableArray(newData), [newValue]) : _objectSpread(_objectSpread({}, newData), {}, _defineProperty({}, key, newValue));
|
|
821
741
|
}, dataIsArray ? [] : {});
|
|
822
742
|
}
|
|
@@ -824,7 +744,7 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
824
744
|
key: "getMediaPath",
|
|
825
745
|
value: function getMediaPath(_ref9) {
|
|
826
746
|
var _ref9$id = _ref9.id,
|
|
827
|
-
|
|
747
|
+
id = _ref9$id === void 0 ? null : _ref9$id;
|
|
828
748
|
return id !== null ? "media://".concat(id) : null;
|
|
829
749
|
}
|
|
830
750
|
}, {
|
|
@@ -836,7 +756,7 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
836
756
|
var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
|
|
837
757
|
return keys.reduce(function (_ref10, key) {
|
|
838
758
|
var currentData = _ref10.data,
|
|
839
|
-
|
|
759
|
+
currentMedias = _ref10.medias;
|
|
840
760
|
var path = [keyPrefix, key].filter(function (it) {
|
|
841
761
|
return it !== null;
|
|
842
762
|
}).join('.');
|
|
@@ -847,7 +767,6 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
847
767
|
var newValue;
|
|
848
768
|
var media = null;
|
|
849
769
|
var subMedias = null;
|
|
850
|
-
|
|
851
770
|
if (patternMatch && isObject(value)) {
|
|
852
771
|
var mediaPath = MediasParser.getMediaPath(value);
|
|
853
772
|
newValue = mediaPath !== null ? mediaPath : value;
|
|
@@ -859,7 +778,6 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
859
778
|
} else {
|
|
860
779
|
newValue = value;
|
|
861
780
|
}
|
|
862
|
-
|
|
863
781
|
return {
|
|
864
782
|
data: dataIsArray ? [].concat(_toConsumableArray(currentData || []), [newValue]) : _objectSpread(_objectSpread({}, currentData), {}, _defineProperty({}, key, newValue)),
|
|
865
783
|
medias: media !== null ? _objectSpread(_objectSpread(_objectSpread({}, currentMedias), subMedias), {}, _defineProperty({}, newValue, media)) : _objectSpread(_objectSpread({}, currentMedias), subMedias)
|
|
@@ -870,42 +788,31 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
870
788
|
});
|
|
871
789
|
}
|
|
872
790
|
}]);
|
|
873
|
-
|
|
874
791
|
return MediasParser;
|
|
875
792
|
}();
|
|
876
793
|
|
|
877
794
|
var _excluded = ["value"],
|
|
878
|
-
|
|
879
|
-
|
|
795
|
+
_excluded2 = ["value"];
|
|
880
796
|
var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
881
797
|
_inherits(Tracking, _BaseTracking);
|
|
882
|
-
|
|
883
798
|
var _super = _createSuper(Tracking);
|
|
884
|
-
|
|
885
799
|
function Tracking() {
|
|
886
800
|
var _this;
|
|
887
|
-
|
|
888
801
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
889
|
-
|
|
890
802
|
_classCallCheck(this, Tracking);
|
|
891
|
-
|
|
892
803
|
_this = _super.call(this, opts);
|
|
893
804
|
var _this$options$variabl = _this.options.variables,
|
|
894
|
-
|
|
805
|
+
variables = _this$options$variabl === void 0 ? null : _this$options$variabl;
|
|
895
806
|
_this.variables = null;
|
|
896
|
-
|
|
897
807
|
if (variables !== null) {
|
|
898
808
|
_this.setVariables(variables);
|
|
899
809
|
}
|
|
900
|
-
|
|
901
810
|
return _this;
|
|
902
811
|
}
|
|
903
|
-
|
|
904
812
|
_createClass(Tracking, [{
|
|
905
813
|
key: "setVariables",
|
|
906
814
|
value: function setVariables(variables) {
|
|
907
815
|
this.variables = variables;
|
|
908
|
-
|
|
909
816
|
if (variables !== null) {
|
|
910
817
|
this.push(variables);
|
|
911
818
|
}
|
|
@@ -919,11 +826,10 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
919
826
|
key: "trackScreenView",
|
|
920
827
|
value: function trackScreenView(screen, screenIndex) {
|
|
921
828
|
var _ref = screen || {},
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
829
|
+
_ref$id = _ref.id,
|
|
830
|
+
screenId = _ref$id === void 0 ? null : _ref$id,
|
|
831
|
+
_ref$type = _ref.type,
|
|
832
|
+
screenType = _ref$type === void 0 ? null : _ref$type;
|
|
927
833
|
var data = {
|
|
928
834
|
event: 'screenView',
|
|
929
835
|
screenId: screenId,
|
|
@@ -936,10 +842,9 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
936
842
|
key: "trackEvent",
|
|
937
843
|
value: function trackEvent(category, action, label) {
|
|
938
844
|
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
845
|
+
_ref2$value = _ref2.value,
|
|
846
|
+
value = _ref2$value === void 0 ? null : _ref2$value,
|
|
847
|
+
opts = _objectWithoutProperties(_ref2, _excluded);
|
|
943
848
|
var data = _objectSpread(_objectSpread({}, opts), {}, {
|
|
944
849
|
event: 'eventInteraction',
|
|
945
850
|
eventCategory: category,
|
|
@@ -947,29 +852,25 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
947
852
|
eventLabel: label,
|
|
948
853
|
eventValue: value
|
|
949
854
|
});
|
|
950
|
-
|
|
951
855
|
this.push(data);
|
|
952
856
|
}
|
|
953
857
|
}, {
|
|
954
858
|
key: "trackMedia",
|
|
955
859
|
value: function trackMedia(type, media, action) {
|
|
956
860
|
var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
861
|
+
_ref3$value = _ref3.value,
|
|
862
|
+
value = _ref3$value === void 0 ? null : _ref3$value,
|
|
863
|
+
opts = _objectWithoutProperties(_ref3, _excluded2);
|
|
961
864
|
var _ref4 = media || {},
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
865
|
+
_ref4$id = _ref4.id,
|
|
866
|
+
mediaId = _ref4$id === void 0 ? null : _ref4$id,
|
|
867
|
+
_ref4$name = _ref4.name,
|
|
868
|
+
name = _ref4$name === void 0 ? null : _ref4$name,
|
|
869
|
+
_ref4$duration = _ref4.duration,
|
|
870
|
+
duration = _ref4$duration === void 0 ? null : _ref4$duration,
|
|
871
|
+
_ref4$currentTime = _ref4.currentTime,
|
|
872
|
+
currentTime = _ref4$currentTime === void 0 ? null : _ref4$currentTime;
|
|
971
873
|
var label = name;
|
|
972
|
-
|
|
973
874
|
var data = _objectSpread(_objectSpread({}, opts), {}, {
|
|
974
875
|
event: 'eventInteraction',
|
|
975
876
|
eventCategory: type,
|
|
@@ -980,11 +881,9 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
980
881
|
mediaCurrentTime: currentTime !== null ? Math.round(currentTime) : null,
|
|
981
882
|
mediaProgress: currentTime !== null && duration !== null && duration > 0 ? Math.round(currentTime / duration * 100) : null
|
|
982
883
|
});
|
|
983
|
-
|
|
984
884
|
this.push(data);
|
|
985
885
|
}
|
|
986
886
|
}]);
|
|
987
|
-
|
|
988
887
|
return Tracking;
|
|
989
888
|
}(Tracking$1);
|
|
990
889
|
|