@panneau/core 3.0.140 → 3.0.145

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/lib/index.js DELETED
@@ -1,985 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
6
- var _createClass = require('@babel/runtime/helpers/createClass');
7
- var tslib = require('tslib');
8
- var ReactIs = require('react-is');
9
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
10
- var isArray = require('lodash/isArray');
11
- var uniqBy = require('lodash/uniqBy');
12
- var _callSuper = require('@babel/runtime/helpers/callSuper');
13
- var _inherits = require('@babel/runtime/helpers/inherits');
14
- var EventEmitter = require('wolfy87-eventemitter');
15
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
16
- var isObject = require('lodash/isObject');
17
- var uniq = require('lodash/uniq');
18
- var tracking = require('@folklore/tracking');
19
- var PropTypes$1 = require('prop-types');
20
-
21
- var message = PropTypes$1.shape({
22
- id: PropTypes$1.string.isRequired,
23
- defaultMessage: PropTypes$1.string
24
- });
25
- var label = PropTypes$1.oneOfType([message, PropTypes$1.node]);
26
- var statusCode = PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string]);
27
-
28
- /**
29
- * Core
30
- */
31
- var menuItem = PropTypes$1.shape({
32
- id: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string]),
33
- label: label,
34
- url: PropTypes$1.string,
35
- external: PropTypes$1.bool,
36
- active: PropTypes$1.bool
37
- });
38
- var menuItems = PropTypes$1.arrayOf(menuItem);
39
- var button = PropTypes$1.shape({
40
- id: PropTypes$1.string,
41
- label: label,
42
- onClick: PropTypes$1.func
43
- });
44
- var buttons = PropTypes$1.arrayOf(button);
45
- var buttonTheme = PropTypes$1.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', null]);
46
- var buttonSize = PropTypes$1.oneOf(['lg', 'sm', null]);
47
- var buttonType = PropTypes$1.oneOf(['button', 'submit']);
48
- var dropdownAlign = PropTypes$1.oneOf(['start', 'end']);
49
- var controlSize = PropTypes$1.oneOf(['lg', 'sm', null]);
50
- var formStatus = PropTypes$1.oneOf(['loading', 'success', 'error', null]);
51
- var fieldOption = PropTypes$1.shape({
52
- value: PropTypes$1.string,
53
- label: PropTypes$1.string
54
- });
55
- var fieldOptions = PropTypes$1.arrayOf(fieldOption);
56
- var toggle = PropTypes$1.shape({
57
- key: PropTypes$1.string,
58
- label: PropTypes$1.string
59
- });
60
- var toggles = PropTypes$1.arrayOf(toggle);
61
- var tableColumn = PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.shape({
62
- id: PropTypes$1.string,
63
- component: PropTypes$1.string,
64
- path: PropTypes$1.string,
65
- field: PropTypes$1.string,
66
- columnClassName: PropTypes$1.string
67
- })]);
68
- var tableColumns = PropTypes$1.arrayOf(tableColumn);
69
-
70
- /**
71
- * Panneau Definitions
72
- */
73
- var routes = PropTypes$1.shape({
74
- 'resources.index': PropTypes$1.string.isRequired,
75
- 'resources.create': PropTypes$1.string.isRequired,
76
- 'resources.store': PropTypes$1.string.isRequired,
77
- 'resources.show': PropTypes$1.string.isRequired,
78
- 'resources.edit': PropTypes$1.string.isRequired,
79
- 'resources.update': PropTypes$1.string.isRequired,
80
- 'resources.delete': PropTypes$1.string.isRequired,
81
- 'resources.destroy': PropTypes$1.string.isRequired
82
- });
83
- var intl = PropTypes$1.shape({
84
- locale: PropTypes$1.string,
85
- messages: PropTypes$1.objectOf(PropTypes$1.string),
86
- values: PropTypes$1.objectOf(PropTypes$1.string)
87
- });
88
- var page = PropTypes$1.shape({
89
- component: PropTypes$1.string.isRequired
90
- });
91
- var pages = PropTypes$1.objectOf(page);
92
- var field = PropTypes$1.shape({
93
- name: PropTypes$1.string,
94
- // Not required on localized fields
95
- type: PropTypes$1.string,
96
- component: PropTypes$1.string,
97
- label: PropTypes$1.node
98
- });
99
- var fields = PropTypes$1.arrayOf(field);
100
- var form = PropTypes$1.shape({
101
- // type: PropTypes.string.isRequired,
102
- title: PropTypes$1.isRequired,
103
- fields: fields
104
- });
105
- var forms = PropTypes$1.arrayOf(form);
106
- var resource = PropTypes$1.shape({
107
- id: PropTypes$1.string.isRequired,
108
- name: PropTypes$1.string.isRequired,
109
- intl: intl,
110
- fields: fields,
111
- forms: PropTypes$1.shape({}),
112
- shows_in_navbar: PropTypes$1.bool
113
- });
114
- var resources = PropTypes$1.arrayOf(resource);
115
- var panneauDefinition = PropTypes$1.shape({
116
- name: PropTypes$1.string,
117
- resources: resources,
118
- routes: routes,
119
- pages: pages,
120
- intl: intl
121
- // intl,
122
- });
123
- var definition = PropTypes$1.shape({
124
- name: PropTypes$1.string
125
- // resources,
126
- // routes,
127
- // intl,
128
- });
129
- var item = PropTypes$1.shape({
130
- id: PropTypes$1.string.isRequired
131
- });
132
- var items = PropTypes$1.arrayOf(item);
133
- var user = PropTypes$1.shape({
134
- id: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string])
135
- });
136
- var users = PropTypes$1.arrayOf(user);
137
- var selectOption = PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number, PropTypes$1.shape({
138
- value: PropTypes$1.any,
139
- // eslint-disable-line
140
- label: label
141
- }), PropTypes$1.object]);
142
- var selectOptions = PropTypes$1.arrayOf(selectOption);
143
- var feedback = PropTypes$1.oneOf(['valid', 'invalid', 'loading', null]);
144
- var formError = PropTypes$1.shape({
145
- message: PropTypes$1.string
146
- });
147
- var formErrors = PropTypes$1.arrayOf(formError);
148
- var uppy = PropTypes$1.shape({
149
- tus: PropTypes$1.object
150
- }); // eslint-disable-line
151
-
152
- var triggerUpdate = PropTypes$1.string;
153
- var breadcrumb = PropTypes$1.shape({
154
- url: PropTypes$1.string
155
- });
156
- var breadcrumbs = PropTypes$1.arrayOf(breadcrumb);
157
- var font = PropTypes$1.shape({
158
- // url: PropTypes.string,
159
- });
160
- var fonts = PropTypes$1.arrayOf(font);
161
- var trackingVariables = PropTypes$1.shape({});
162
- var modal = PropTypes$1.shape({
163
- name: PropTypes$1.string
164
- });
165
- var modals = PropTypes$1.arrayOf(modal);
166
- var filter = PropTypes$1.shape({
167
- id: PropTypes$1.string,
168
- component: PropTypes$1.string
169
- });
170
- var filters = PropTypes$1.arrayOf(filter);
171
- var media = PropTypes$1.shape({
172
- id: PropTypes$1.string.isRequired,
173
- name: PropTypes$1.string.isRequired,
174
- type: PropTypes$1.string.isRequired,
175
- thumbnail_url: PropTypes$1.string
176
- });
177
- var medias = PropTypes$1.arrayOf(media);
178
-
179
- var PropTypes = /*#__PURE__*/Object.freeze({
180
- __proto__: null,
181
- breadcrumb: breadcrumb,
182
- breadcrumbs: breadcrumbs,
183
- button: button,
184
- buttonSize: buttonSize,
185
- buttonTheme: buttonTheme,
186
- buttonType: buttonType,
187
- buttons: buttons,
188
- controlSize: controlSize,
189
- definition: definition,
190
- dropdownAlign: dropdownAlign,
191
- feedback: feedback,
192
- field: field,
193
- fieldOption: fieldOption,
194
- fieldOptions: fieldOptions,
195
- fields: fields,
196
- filter: filter,
197
- filters: filters,
198
- font: font,
199
- fonts: fonts,
200
- form: form,
201
- formError: formError,
202
- formErrors: formErrors,
203
- formStatus: formStatus,
204
- forms: forms,
205
- intl: intl,
206
- item: item,
207
- items: items,
208
- label: label,
209
- media: media,
210
- medias: medias,
211
- menuItem: menuItem,
212
- menuItems: menuItems,
213
- message: message,
214
- modal: modal,
215
- modals: modals,
216
- page: page,
217
- pages: pages,
218
- panneauDefinition: panneauDefinition,
219
- resource: resource,
220
- resources: resources,
221
- routes: routes,
222
- selectOption: selectOption,
223
- selectOptions: selectOptions,
224
- statusCode: statusCode,
225
- tableColumn: tableColumn,
226
- tableColumns: tableColumns,
227
- toggle: toggle,
228
- toggles: toggles,
229
- trackingVariables: trackingVariables,
230
- triggerUpdate: triggerUpdate,
231
- uppy: uppy,
232
- user: user,
233
- users: users
234
- });
235
-
236
- /**
237
- * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
238
- */
239
- /**
240
- * Lower case as a function.
241
- */
242
- function lowerCase(str) {
243
- return str.toLowerCase();
244
- }
245
-
246
- // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
247
- var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
248
- // Remove all non-word characters.
249
- var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
250
- /**
251
- * Normalize the string into something other libraries can manipulate easier.
252
- */
253
- function noCase(input, options) {
254
- if (options === void 0) {
255
- options = {};
256
- }
257
- var _a = options.splitRegexp,
258
- splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a,
259
- _b = options.stripRegexp,
260
- stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b,
261
- _c = options.transform,
262
- transform = _c === void 0 ? lowerCase : _c,
263
- _d = options.delimiter,
264
- delimiter = _d === void 0 ? " " : _d;
265
- var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
266
- var start = 0;
267
- var end = result.length;
268
- // Trim the delimiter from around the output string.
269
- while (result.charAt(start) === "\0") start++;
270
- while (result.charAt(end - 1) === "\0") end--;
271
- // Transform each token independently.
272
- return result.slice(start, end).split("\0").map(transform).join(delimiter);
273
- }
274
- /**
275
- * Replace `re` in the input string with the replacement value.
276
- */
277
- function replace(input, re, value) {
278
- if (re instanceof RegExp) return input.replace(re, value);
279
- return re.reduce(function (input, re) {
280
- return input.replace(re, value);
281
- }, input);
282
- }
283
-
284
- function pascalCaseTransform(input, index) {
285
- var firstChar = input.charAt(0);
286
- var lowerChars = input.substr(1).toLowerCase();
287
- if (index > 0 && firstChar >= "0" && firstChar <= "9") {
288
- return "_" + firstChar + lowerChars;
289
- }
290
- return "" + firstChar.toUpperCase() + lowerChars;
291
- }
292
- function pascalCase(input, options) {
293
- if (options === void 0) {
294
- options = {};
295
- }
296
- return noCase(input, tslib.__assign({
297
- delimiter: "",
298
- transform: pascalCaseTransform
299
- }, options));
300
- }
301
-
302
- var flattenComponents = function flattenComponents(components) {
303
- var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
304
- if (components === null) {
305
- return null;
306
- }
307
- return Object.keys(components).reduce(function (newMap, key) {
308
- 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));
309
- }, {});
310
- };
311
-
312
- var getComponentFromName = function getComponentFromName() {
313
- var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
314
- var components = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
315
- var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
316
- if (components === null || name === null) {
317
- return defaultComponent;
318
- }
319
- var pascalName = pascalCase(name);
320
- // console.log(name, pascalName, components);
321
- var component = components[pascalName] || components[name] || defaultComponent;
322
- if (!component) {
323
- console.warn('Could not find component from name', name, pascalName, components);
324
- }
325
- return component;
326
- };
327
-
328
- var ComponentsManager = /*#__PURE__*/function () {
329
- function ComponentsManager() {
330
- var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
331
- _classCallCheck(this, ComponentsManager);
332
- this.components = flattenComponents(components);
333
- }
334
- _createClass(ComponentsManager, [{
335
- key: "addComponent",
336
- value: function addComponent(name, component) {
337
- var namespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
338
- return this.addComponents(_defineProperty({}, name, component), namespace);
339
- }
340
- }, {
341
- key: "addComponents",
342
- value: function addComponents(components) {
343
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
344
- var newComponents = namespace !== null ? Object.keys(components).reduce(function (componentsMaps, name) {
345
- return _objectSpread(_objectSpread({}, componentsMaps), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), components[name]));
346
- }, {}) : components;
347
- this.components = _objectSpread(_objectSpread({}, this.components), newComponents);
348
- return this;
349
- }
350
- }, {
351
- key: "merge",
352
- value: function merge(manager) {
353
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
354
- return this.addComponents(manager.getComponents(), namespace);
355
- }
356
- }, {
357
- key: "addNamespace",
358
- value: function addNamespace(namespace) {
359
- var _this = this;
360
- if (namespace === null) {
361
- return this;
362
- }
363
- this.components = Object.keys(this.components).reduce(function (componentsMap, name) {
364
- return _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), _this.components[name]));
365
- }, {});
366
- return this;
367
- }
368
- }, {
369
- key: "getComponent",
370
- value: function getComponent(name) {
371
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
372
- var components = this.getComponents(namespace);
373
- return getComponentFromName(name, components);
374
- }
375
- }, {
376
- key: "getComponents",
377
- value: function getComponents() {
378
- var _this2 = this;
379
- var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
380
- return namespace !== null ? Object.keys(this.components || {}).reduce(function (componentsMap, name) {
381
- var pattern = new RegExp("^".concat(namespace, "\\.(.*)$"));
382
- var matches = pattern.exec(name);
383
- return matches !== null ? _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, matches[1], _this2.components[name])) : componentsMap;
384
- }, null) : this.components;
385
- }
386
- }, {
387
- key: "hasComponent",
388
- value: function hasComponent(name) {
389
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
390
- return this.components !== null && typeof this.components[namespace !== null ? "".concat(namespace, ".").concat(name) : name] !== 'undefined';
391
- }
392
- }]);
393
- return ComponentsManager;
394
- }();
395
- var ComponentsManager$1 = ComponentsManager;
396
-
397
- var DefinitionsManager = /*#__PURE__*/function () {
398
- function DefinitionsManager() {
399
- var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
400
- _classCallCheck(this, DefinitionsManager);
401
- this.definitions = definitions || [];
402
- }
403
- _createClass(DefinitionsManager, [{
404
- key: "addDefinition",
405
- value: function addDefinition(definition) {
406
- this.addDefinitions(isArray(definition) ? definition : [definition]);
407
- return this;
408
- }
409
- }, {
410
- key: "addDefinitions",
411
- value: function addDefinitions(definitions) {
412
- this.definitions = uniqBy([].concat(_toConsumableArray(definitions), _toConsumableArray(this.definitions)), function (it) {
413
- return it.id;
414
- });
415
- return this;
416
- }
417
- }, {
418
- key: "merge",
419
- value: function merge(manager) {
420
- return this.addDefinitions(manager.getDefinitions());
421
- }
422
- }, {
423
- key: "getDefinition",
424
- value: function getDefinition(id) {
425
- if (id === null) {
426
- return null;
427
- }
428
- return this.definitions.find(function (it) {
429
- return it.id === id;
430
- }) || null;
431
- }
432
- }, {
433
- key: "getDefinitions",
434
- value: function getDefinitions() {
435
- return this.definitions;
436
- }
437
- }, {
438
- key: "hasDefinition",
439
- value: function hasDefinition(id) {
440
- return this.getDefinition(id) !== null;
441
- }
442
- }, {
443
- key: "getComponent",
444
- value: function getComponent(id) {
445
- var _ref = this.getDefinition(id) || {},
446
- _ref$component = _ref.component,
447
- component = _ref$component === void 0 ? null : _ref$component;
448
- return component;
449
- }
450
- }, {
451
- key: "getComponents",
452
- value: function getComponents() {
453
- return this.definitions.reduce(function (allComponents, _ref2) {
454
- var id = _ref2.id,
455
- _ref2$component = _ref2.component,
456
- component = _ref2$component === void 0 ? null : _ref2$component;
457
- return component !== null ? _objectSpread(_objectSpread({}, allComponents), {}, _defineProperty({}, id, component)) : allComponents;
458
- }, {});
459
- }
460
- }]);
461
- return DefinitionsManager;
462
- }();
463
- var DefinitionsManager$1 = DefinitionsManager;
464
-
465
- var EventsManager = /*#__PURE__*/function (_EventEmitter) {
466
- _inherits(EventsManager, _EventEmitter);
467
- function EventsManager(element) {
468
- var _this;
469
- _classCallCheck(this, EventsManager);
470
- _this = _callSuper(this, EventsManager);
471
- _this.element = element;
472
- _this.events = {};
473
- _this.listeners = {};
474
- return _this;
475
- }
476
- _createClass(EventsManager, [{
477
- key: "subscribe",
478
- value: function subscribe(event, callback) {
479
- this.on(event, callback);
480
- this.events = _objectSpread(_objectSpread({}, this.events), {}, _defineProperty({}, event, [].concat(_toConsumableArray(this.events[event] || []), [callback])));
481
- if (this.events[event].length === 1) {
482
- this.addEventListener(event);
483
- }
484
- }
485
- }, {
486
- key: "unsubscribe",
487
- value: function unsubscribe(event, callback) {
488
- var _this2 = this;
489
- this.off(event, callback);
490
- this.events = Object.keys(this.events).reduce(function (newEvents, eventName) {
491
- if (eventName !== event) {
492
- return _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, _this2.events[eventName]));
493
- }
494
- var newListeners = _this2.events[eventName].filter(function (listener) {
495
- return listener !== callback;
496
- });
497
- return newListeners.length > 0 ? _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, newListeners)) : newEvents;
498
- }, {});
499
- if (typeof this.events[event] === 'undefined') {
500
- this.removeEventListener(event);
501
- }
502
- }
503
- }, {
504
- key: "addEventListener",
505
- value: function addEventListener(event) {
506
- var _this3 = this;
507
- if (typeof this.listeners[event] === 'undefined') {
508
- this.listeners[event] = function () {
509
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
510
- args[_key] = arguments[_key];
511
- }
512
- return _this3.emit.apply(_this3, [event].concat(args));
513
- };
514
- }
515
- this.element.addEventListener(event, this.listeners[event]);
516
- }
517
- }, {
518
- key: "removeEventListener",
519
- value: function removeEventListener(event) {
520
- this.element.removeEventListener(event, this.listeners[event]);
521
- }
522
- }]);
523
- return EventsManager;
524
- }(EventEmitter);
525
- var EventsManager$1 = EventsManager;
526
-
527
- var FieldsManager$2 = /*#__PURE__*/function (_DefinitionsManager) {
528
- _inherits(FieldsManager, _DefinitionsManager);
529
- function FieldsManager() {
530
- _classCallCheck(this, FieldsManager);
531
- return _callSuper(this, FieldsManager, arguments);
532
- }
533
- return _createClass(FieldsManager);
534
- }(DefinitionsManager$1);
535
- var FieldsManager$3 = FieldsManager$2;
536
-
537
- var _excluded$2 = ["fonts"];
538
- var FontsParser = /*#__PURE__*/function () {
539
- function FontsParser(_ref) {
540
- var fieldsManager = _ref.fieldsManager,
541
- screensManager = _ref.screensManager;
542
- _classCallCheck(this, FontsParser);
543
- this.fieldsManager = fieldsManager;
544
- this.screensManager = screensManager;
545
- }
546
-
547
- // Extract fonts
548
- _createClass(FontsParser, [{
549
- key: "parse",
550
- value: function parse(story) {
551
- var _this = this;
552
- if (story === null) {
553
- return story;
554
- }
555
-
556
- // Extract fonts from screen
557
- var _ref2 = story || {},
558
- _ref2$theme = _ref2.theme,
559
- theme = _ref2$theme === void 0 ? null : _ref2$theme,
560
- _ref2$components = _ref2.components,
561
- components = _ref2$components === void 0 ? [] : _ref2$components;
562
- var fonts = uniq(components.reduce(function (currentFonts, screen) {
563
- var type = screen.type;
564
- var _ref3 = _this.screensManager.getDefinition(type) || {},
565
- _ref3$fields = _ref3.fields,
566
- fields = _ref3$fields === void 0 ? [] : _ref3$fields;
567
- var fieldsPattern = _this.getFieldsPattern(fields);
568
- var newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
569
- return newFonts.length > 0 ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(newFonts)) : currentFonts;
570
- }, []), 'name');
571
-
572
- // Extract fonts from theme
573
- if (theme !== null) {
574
- var _this$parse = this.parse(theme),
575
- _this$parse$fonts = _this$parse.fonts,
576
- themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
577
- newTheme = _objectWithoutProperties(_this$parse, _excluded$2);
578
- return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
579
- theme: newTheme,
580
- fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
581
- }) : story;
582
- }
583
- return fonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
584
- fonts: fonts
585
- }) : story;
586
- }
587
- }, {
588
- key: "getFieldsPattern",
589
- value: function getFieldsPattern(fields) {
590
- var _this2 = this;
591
- var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
592
- return fields.reduce(function (patterns, field) {
593
- var _field$name = field.name,
594
- name = _field$name === void 0 ? null : _field$name,
595
- _field$type = field.type,
596
- type = _field$type === void 0 ? null : _field$type;
597
- var path = [namePrefix, name].filter(function (it) {
598
- return it !== null;
599
- }).join('\\.');
600
- var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
601
-
602
- // also check settings fields
603
- var _fieldDefinition$fiel = fieldDefinition.fields,
604
- subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
605
- _fieldDefinition$item = fieldDefinition.itemsField,
606
- itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
607
- _fieldDefinition$sett = fieldDefinition.settings,
608
- settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
609
- 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]+")) : []));
610
- }, []);
611
- }
612
- }], [{
613
- key: "fieldIsFontFamily",
614
- value: function fieldIsFontFamily(_ref4) {
615
- var _ref4$id = _ref4.id,
616
- id = _ref4$id === void 0 ? null : _ref4$id;
617
- return id === 'font-family';
618
- }
619
- }, {
620
- key: "valueIsFont",
621
- value: function valueIsFont(_ref5) {
622
- var _ref5$type = _ref5.type,
623
- type = _ref5$type === void 0 ? null : _ref5$type;
624
- return type === 'custom' || type === 'google';
625
- }
626
- }, {
627
- key: "extractFontsWithPaths",
628
- value: function extractFontsWithPaths(data, patterns) {
629
- var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
630
- var dataIsArray = isArray(data);
631
- var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
632
- return keys.reduce(function (currentFonts, key) {
633
- var path = [keyPrefix, key].filter(function (it) {
634
- return it !== null;
635
- }).join('.');
636
- var patternMatch = patterns.reduce(function (found, pattern) {
637
- return found || pattern.test(path);
638
- }, false);
639
- var value = data[key];
640
- var font = null;
641
- var subFonts = null;
642
- if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
643
- font = value;
644
- } else if (isObject(value) || isArray(value)) {
645
- subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
646
- }
647
- return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
648
- }, []);
649
- }
650
- }]);
651
- return FontsParser;
652
- }();
653
- var FontsParser$1 = FontsParser;
654
-
655
- var FieldsManager = /*#__PURE__*/function (_ComponentsManager) {
656
- _inherits(FieldsManager, _ComponentsManager);
657
- function FieldsManager() {
658
- _classCallCheck(this, FieldsManager);
659
- return _callSuper(this, FieldsManager, arguments);
660
- }
661
- return _createClass(FieldsManager);
662
- }(ComponentsManager$1);
663
- var FieldsManager$1 = FieldsManager;
664
-
665
- var _excluded$1 = ["medias"];
666
- var MediasParser = /*#__PURE__*/function () {
667
- function MediasParser(_ref) {
668
- var fieldsManager = _ref.fieldsManager,
669
- screensManager = _ref.screensManager;
670
- _classCallCheck(this, MediasParser);
671
- this.fieldsManager = fieldsManager;
672
- this.screensManager = screensManager;
673
- }
674
-
675
- // Convert medias object to path
676
- _createClass(MediasParser, [{
677
- key: "toPath",
678
- value: function toPath(story) {
679
- var _this = this;
680
- if (story === null) {
681
- return story;
682
- }
683
- var _ref2 = story || {},
684
- _ref2$theme = _ref2.theme,
685
- theme = _ref2$theme === void 0 ? null : _ref2$theme,
686
- _ref2$components = _ref2.components,
687
- components = _ref2$components === void 0 ? [] : _ref2$components;
688
- var _components$reduce = components.reduce(function (_ref3, screen) {
689
- var previousComponents = _ref3.components,
690
- currentMedias = _ref3.medias;
691
- var type = screen.type;
692
- var _ref4 = _this.screensManager.getDefinition(type) || {},
693
- _ref4$fields = _ref4.fields,
694
- fields = _ref4$fields === void 0 ? [] : _ref4$fields;
695
- var fieldsPattern = _this.getMediaFieldsPattern(fields);
696
- var _MediasParser$replace = MediasParser.replaceMediasWithPaths(screen, fieldsPattern),
697
- newScreen = _MediasParser$replace.data,
698
- newMedias = _MediasParser$replace.medias;
699
- return {
700
- components: [].concat(_toConsumableArray(previousComponents), [newScreen]),
701
- medias: _objectSpread(_objectSpread({}, currentMedias), newMedias)
702
- };
703
- }, {
704
- components: [],
705
- medias: null
706
- }),
707
- newComponents = _components$reduce.components,
708
- medias = _components$reduce.medias;
709
- if (theme !== null) {
710
- var _this$toPath = this.toPath(theme),
711
- themeMedias = _this$toPath.medias,
712
- newTheme = _objectWithoutProperties(_this$toPath, _excluded$1);
713
- return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
714
- theme: newTheme,
715
- components: newComponents,
716
- medias: _objectSpread(_objectSpread({}, themeMedias), medias)
717
- }) : story;
718
- }
719
- return medias !== null ? _objectSpread(_objectSpread({}, story), {}, {
720
- components: newComponents,
721
- medias: medias
722
- }) : story;
723
- }
724
-
725
- // Convert path to medias object
726
- }, {
727
- key: "fromPath",
728
- value: function fromPath(story) {
729
- var _this2 = this;
730
- var defaultMedias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
731
- if (story === null) {
732
- return story;
733
- }
734
- var _ref5 = story || {},
735
- _ref5$theme = _ref5.theme,
736
- theme = _ref5$theme === void 0 ? null : _ref5$theme,
737
- _ref5$components = _ref5.components,
738
- components = _ref5$components === void 0 ? [] : _ref5$components,
739
- _ref5$medias = _ref5.medias,
740
- medias = _ref5$medias === void 0 ? defaultMedias : _ref5$medias;
741
- if (medias === null && theme === null) {
742
- return story;
743
- }
744
-
745
- // Replace path with medias objects
746
- var newComponents = medias !== null ? components.map(function (screen) {
747
- var type = screen.type;
748
- var _ref6 = _this2.screensManager.getDefinition(type) || {},
749
- _ref6$fields = _ref6.fields,
750
- fields = _ref6$fields === void 0 ? [] : _ref6$fields;
751
- var fieldsPattern = _this2.getMediaFieldsPattern(fields);
752
- return MediasParser.replacePathsWithMedias(screen, medias, fieldsPattern);
753
- }) : components;
754
-
755
- // Replace path with medias object in theme
756
- if (theme !== null) {
757
- var newTheme = this.fromPath(theme, medias);
758
- return newTheme !== theme || newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
759
- theme: newTheme,
760
- components: newComponents
761
- }) : story;
762
- }
763
- return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
764
- components: newComponents
765
- }) : story;
766
- }
767
- }, {
768
- key: "getMediaFieldsPattern",
769
- value: function getMediaFieldsPattern(fields) {
770
- var _this3 = this;
771
- var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
772
- return fields.reduce(function (patterns, field) {
773
- var _field$name = field.name,
774
- name = _field$name === void 0 ? null : _field$name,
775
- _field$type = field.type,
776
- type = _field$type === void 0 ? null : _field$type;
777
- var path = [namePrefix, name].filter(function (it) {
778
- return it !== null;
779
- }).join('\\.');
780
- var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this3.fieldsManager.getDefinition(type) : null), field);
781
-
782
- // also check settings fields
783
- var _fieldDefinition$fiel = fieldDefinition.fields,
784
- subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
785
- _fieldDefinition$item = fieldDefinition.itemsField,
786
- itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
787
- _fieldDefinition$sett = fieldDefinition.settings,
788
- settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
789
- 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]+")) : []));
790
- }, []);
791
- }
792
- }], [{
793
- key: "fieldIsMedia",
794
- value: function fieldIsMedia(_ref7) {
795
- var _ref7$media = _ref7.media,
796
- media = _ref7$media === void 0 ? false : _ref7$media;
797
- return media;
798
- }
799
- }, {
800
- key: "fieldIsFontFamily",
801
- value: function fieldIsFontFamily(_ref8) {
802
- var _ref8$id = _ref8.id,
803
- id = _ref8$id === void 0 ? null : _ref8$id;
804
- return id === 'font-family';
805
- }
806
- }, {
807
- key: "replacePathsWithMedias",
808
- value: function replacePathsWithMedias(data, medias, patterns) {
809
- var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
810
- var dataIsArray = isArray(data);
811
- var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
812
- return keys.reduce(function (newData, key) {
813
- var path = [keyPrefix, key].filter(function (it) {
814
- return it !== null;
815
- }).join('.');
816
- var patternMatch = patterns.reduce(function (found, pattern) {
817
- return found || pattern.test(path);
818
- }, false);
819
- var value = data[key];
820
- var newValue;
821
- if (patternMatch) {
822
- newValue = isObject(value) ? value : medias[value] || null;
823
- } else {
824
- newValue = isObject(value) || isArray(value) ? MediasParser.replacePathsWithMedias(value, medias, patterns, path) : value;
825
- }
826
- return dataIsArray ? [].concat(_toConsumableArray(newData), [newValue]) : _objectSpread(_objectSpread({}, newData), {}, _defineProperty({}, key, newValue));
827
- }, dataIsArray ? [] : {});
828
- }
829
- }, {
830
- key: "getMediaPath",
831
- value: function getMediaPath(_ref9) {
832
- var _ref9$id = _ref9.id,
833
- id = _ref9$id === void 0 ? null : _ref9$id;
834
- return id !== null ? "media://".concat(id) : null;
835
- }
836
- }, {
837
- key: "replaceMediasWithPaths",
838
- value: function replaceMediasWithPaths(data, patterns) {
839
- var medias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
840
- var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
841
- var dataIsArray = isArray(data);
842
- var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
843
- return keys.reduce(function (_ref10, key) {
844
- var currentData = _ref10.data,
845
- currentMedias = _ref10.medias;
846
- var path = [keyPrefix, key].filter(function (it) {
847
- return it !== null;
848
- }).join('.');
849
- var patternMatch = patterns.reduce(function (found, pattern) {
850
- return found || pattern.test(path);
851
- }, false);
852
- var value = data[key];
853
- var newValue;
854
- var media = null;
855
- var subMedias = null;
856
- if (patternMatch && isObject(value)) {
857
- var mediaPath = MediasParser.getMediaPath(value);
858
- newValue = mediaPath !== null ? mediaPath : value;
859
- media = mediaPath !== null ? value : null;
860
- } else if (isObject(value) || isArray(value)) {
861
- var subReturn = MediasParser.replaceMediasWithPaths(value, patterns, medias, path);
862
- newValue = subReturn.data;
863
- subMedias = subReturn.medias;
864
- } else {
865
- newValue = value;
866
- }
867
- return {
868
- data: dataIsArray ? [].concat(_toConsumableArray(currentData || []), [newValue]) : _objectSpread(_objectSpread({}, currentData), {}, _defineProperty({}, key, newValue)),
869
- medias: media !== null ? _objectSpread(_objectSpread(_objectSpread({}, currentMedias), subMedias), {}, _defineProperty({}, newValue, media)) : _objectSpread(_objectSpread({}, currentMedias), subMedias)
870
- };
871
- }, {
872
- data: null,
873
- medias: medias
874
- });
875
- }
876
- }]);
877
- return MediasParser;
878
- }();
879
- var MediasParser$1 = MediasParser;
880
-
881
- var _excluded = ["value"],
882
- _excluded2 = ["value"];
883
- var Tracking = /*#__PURE__*/function (_BaseTracking) {
884
- _inherits(Tracking, _BaseTracking);
885
- function Tracking() {
886
- var _this;
887
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
888
- _classCallCheck(this, Tracking);
889
- _this = _callSuper(this, Tracking, [opts]);
890
- var _this$options$variabl = _this.options.variables,
891
- variables = _this$options$variabl === void 0 ? null : _this$options$variabl;
892
- _this.variables = null;
893
- if (variables !== null) {
894
- _this.setVariables(variables);
895
- }
896
- return _this;
897
- }
898
- _createClass(Tracking, [{
899
- key: "setVariables",
900
- value: function setVariables(variables) {
901
- this.variables = variables;
902
- if (variables !== null) {
903
- this.push(variables);
904
- }
905
- }
906
- }, {
907
- key: "getVariables",
908
- value: function getVariables() {
909
- return this.variables;
910
- }
911
- }, {
912
- key: "trackScreenView",
913
- value: function trackScreenView(screen, screenIndex) {
914
- var _ref = screen || {},
915
- _ref$id = _ref.id,
916
- screenId = _ref$id === void 0 ? null : _ref$id,
917
- _ref$type = _ref.type,
918
- screenType = _ref$type === void 0 ? null : _ref$type;
919
- var data = {
920
- event: 'screenView',
921
- screenId: screenId,
922
- screenType: screenType,
923
- screenIndex: screenIndex
924
- };
925
- this.push(data);
926
- }
927
- }, {
928
- key: "trackEvent",
929
- value: function trackEvent(category, action, label) {
930
- var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
931
- _ref2$value = _ref2.value,
932
- value = _ref2$value === void 0 ? null : _ref2$value,
933
- opts = _objectWithoutProperties(_ref2, _excluded);
934
- var data = _objectSpread(_objectSpread({}, opts), {}, {
935
- event: 'eventInteraction',
936
- eventCategory: category,
937
- eventAction: action,
938
- eventLabel: label,
939
- eventValue: value
940
- });
941
- this.push(data);
942
- }
943
- }, {
944
- key: "trackMedia",
945
- value: function trackMedia(type, media, action) {
946
- var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
947
- _ref3$value = _ref3.value,
948
- value = _ref3$value === void 0 ? null : _ref3$value,
949
- opts = _objectWithoutProperties(_ref3, _excluded2);
950
- var _ref4 = media || {},
951
- _ref4$id = _ref4.id,
952
- mediaId = _ref4$id === void 0 ? null : _ref4$id,
953
- _ref4$name = _ref4.name,
954
- name = _ref4$name === void 0 ? null : _ref4$name,
955
- _ref4$duration = _ref4.duration,
956
- duration = _ref4$duration === void 0 ? null : _ref4$duration,
957
- _ref4$currentTime = _ref4.currentTime,
958
- currentTime = _ref4$currentTime === void 0 ? null : _ref4$currentTime;
959
- var label = name;
960
- var data = _objectSpread(_objectSpread({}, opts), {}, {
961
- event: 'eventInteraction',
962
- eventCategory: type,
963
- eventAction: action,
964
- eventLabel: label,
965
- eventValue: value,
966
- mediaId: mediaId,
967
- mediaCurrentTime: currentTime !== null ? Math.round(currentTime) : null,
968
- mediaProgress: currentTime !== null && duration !== null && duration > 0 ? Math.round(currentTime / duration * 100) : null
969
- });
970
- this.push(data);
971
- }
972
- }]);
973
- return Tracking;
974
- }(tracking.Tracking);
975
- var Tracking$1 = Tracking;
976
-
977
- exports.ComponentsManager = ComponentsManager$1;
978
- exports.DefinitionsManager = DefinitionsManager$1;
979
- exports.EventsManager = EventsManager$1;
980
- exports.FieldsManager = FieldsManager$3;
981
- exports.FontsParser = FontsParser$1;
982
- exports.FormsManager = FieldsManager$1;
983
- exports.MediasParser = MediasParser$1;
984
- exports.PropTypes = PropTypes;
985
- exports.Tracking = Tracking$1;