@micromag/core 0.3.541 → 0.3.569

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,2387 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
5
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
6
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
7
- var _createClass = require('@babel/runtime/helpers/createClass');
8
- var isArray = require('lodash/isArray');
9
- var isObject = require('lodash/isObject');
10
- var uniqWith = require('lodash/uniqWith');
11
- var sortBy = require('lodash/sortBy');
12
- var _callSuper = require('@babel/runtime/helpers/callSuper');
13
- var _inherits = require('@babel/runtime/helpers/inherits');
14
- var EventEmitter = require('wolfy87-eventemitter');
15
- var uniqBy = require('lodash/uniqBy');
16
- var _typeof = require('@babel/runtime/helpers/typeof');
17
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
18
- var isString = require('lodash/isString');
19
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
20
- var uniq = require('lodash/uniq');
21
- var isEmpty = require('lodash/isEmpty');
22
- var tracking = require('@folklore/tracking');
23
- var PropTypes$1 = require('prop-types');
24
-
25
- // Regexps involved with splitting words in various case formats.
26
- const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
27
- const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
28
- // Used to iterate over the initial split result and separate numbers.
29
- const SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
30
- // Regexp involved with stripping non-word characters from the result.
31
- const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
32
- // The replacement value for splits.
33
- const SPLIT_REPLACE_VALUE = "$1\0$2";
34
- // The default characters to keep after transforming case.
35
- const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
36
- /**
37
- * Split any cased input strings into an array of words.
38
- */
39
- function split(value) {
40
- let result = value.trim();
41
- result = result
42
- .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
43
- .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
44
- result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
45
- let start = 0;
46
- let end = result.length;
47
- // Trim the delimiter from around the output string.
48
- while (result.charAt(start) === "\0")
49
- start++;
50
- if (start === end)
51
- return [];
52
- while (result.charAt(end - 1) === "\0")
53
- end--;
54
- return result.slice(start, end).split(/\0/g);
55
- }
56
- /**
57
- * Split the input string into an array of words, separating numbers.
58
- */
59
- function splitSeparateNumbers(value) {
60
- const words = split(value);
61
- for (let i = 0; i < words.length; i++) {
62
- const word = words[i];
63
- const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
64
- if (match) {
65
- const offset = match.index + (match[1] ?? match[2]).length;
66
- words.splice(i, 1, word.slice(0, offset), word.slice(offset));
67
- }
68
- }
69
- return words;
70
- }
71
- /**
72
- * Convert a string to space separated lower case (`foo bar`).
73
- */
74
- function noCase(input, options) {
75
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
76
- return (prefix +
77
- words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") +
78
- suffix);
79
- }
80
- /**
81
- * Convert a string to pascal case (`FooBar`).
82
- */
83
- function pascalCase(input, options) {
84
- const [prefix, words, suffix] = splitPrefixSuffix(input, options);
85
- const lower = lowerFactory(options?.locale);
86
- const upper = upperFactory(options?.locale);
87
- const transform = options?.mergeAmbiguousCharacters
88
- ? capitalCaseTransformFactory(lower, upper)
89
- : pascalCaseTransformFactory(lower, upper);
90
- return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
91
- }
92
- /**
93
- * Convert a string to snake case (`foo_bar`).
94
- */
95
- function snakeCase(input, options) {
96
- return noCase(input, { delimiter: "_", ...options });
97
- }
98
- function lowerFactory(locale) {
99
- return locale === false
100
- ? (input) => input.toLowerCase()
101
- : (input) => input.toLocaleLowerCase(locale);
102
- }
103
- function upperFactory(locale) {
104
- return locale === false
105
- ? (input) => input.toUpperCase()
106
- : (input) => input.toLocaleUpperCase(locale);
107
- }
108
- function capitalCaseTransformFactory(lower, upper) {
109
- return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
110
- }
111
- function pascalCaseTransformFactory(lower, upper) {
112
- return (word, index) => {
113
- const char0 = word[0];
114
- const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
115
- return initial + lower(word.slice(1));
116
- };
117
- }
118
- function splitPrefixSuffix(input, options = {}) {
119
- const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
120
- const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
121
- const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
122
- let prefixIndex = 0;
123
- let suffixIndex = input.length;
124
- while (prefixIndex < input.length) {
125
- const char = input.charAt(prefixIndex);
126
- if (!prefixCharacters.includes(char))
127
- break;
128
- prefixIndex++;
129
- }
130
- while (suffixIndex > prefixIndex) {
131
- const index = suffixIndex - 1;
132
- const char = input.charAt(index);
133
- if (!suffixCharacters.includes(char))
134
- break;
135
- suffixIndex = index;
136
- }
137
- return [
138
- input.slice(0, prefixIndex),
139
- splitFn(input.slice(prefixIndex, suffixIndex)),
140
- input.slice(suffixIndex),
141
- ];
142
- }
143
-
144
- /**
145
- * Core
146
- */
147
- var history = PropTypes$1.shape({
148
- listen: PropTypes$1.func.isRequired,
149
- push: PropTypes$1.func.isRequired
150
- });
151
- var location = PropTypes$1.shape({
152
- pathname: PropTypes$1.string,
153
- search: PropTypes$1.string
154
- });
155
- var intl = PropTypes$1.shape({
156
- locale: PropTypes$1.string.isRequired,
157
- formatMessage: PropTypes$1.func.isRequired
158
- });
159
- var defaultMessageContent = PropTypes$1.shape({
160
- type: PropTypes$1.number,
161
- value: PropTypes$1.string
162
- });
163
- var defaultMessage = PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.arrayOf(defaultMessageContent)]);
164
- var message = PropTypes$1.shape({
165
- id: PropTypes$1.string,
166
- defaultMessage: defaultMessage.isRequired,
167
- description: PropTypes$1.string
168
- });
169
- var text = PropTypes$1.oneOfType([message, PropTypes$1.string]);
170
- var label = PropTypes$1.oneOfType([message, PropTypes$1.node]);
171
- var statusCode = PropTypes$1.oneOf([401, 403, 404, 500]);
172
- var ref = PropTypes$1.oneOfType([PropTypes$1.shape({
173
- current: PropTypes$1.any // eslint-disable-line react/forbid-prop-types
174
- }), PropTypes$1.func]);
175
- var target = PropTypes$1.oneOf(['_blank', '_self', '_parent']);
176
- var interaction = PropTypes$1.oneOf(['tap', 'swipe']);
177
- var interactions = PropTypes$1.arrayOf(interaction);
178
- var trackingVariables = PropTypes$1.objectOf(PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number, PropTypes$1.array]));
179
- var progress = PropTypes$1.shape({
180
- currentTime: PropTypes$1.number,
181
- duration: PropTypes$1.number
182
- });
183
-
184
- /**
185
- * Site
186
- */
187
- var user = PropTypes$1.shape({
188
- id: PropTypes$1.number,
189
- firstname: PropTypes$1.string,
190
- lastname: PropTypes$1.string,
191
- email: PropTypes$1.string,
192
- gender: PropTypes$1.string,
193
- birthdate: PropTypes$1.string
194
- });
195
- var menuItem = PropTypes$1.shape({
196
- id: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string]),
197
- label: label,
198
- url: PropTypes$1.string,
199
- external: PropTypes$1.bool,
200
- active: PropTypes$1.bool
201
- });
202
- var menuItems = PropTypes$1.arrayOf(menuItem);
203
- var breadcrumb = PropTypes$1.shape({
204
- label: label,
205
- url: PropTypes$1.string
206
- });
207
- var breadcrumbs = PropTypes$1.arrayOf(breadcrumb);
208
- var device = PropTypes$1.shape({
209
- id: PropTypes$1.string.isRequired
210
- });
211
- var devices = PropTypes$1.arrayOf(device);
212
- var modal = PropTypes$1.shape({
213
- id: PropTypes$1.string.isRequired
214
- });
215
- var modals = PropTypes$1.arrayOf(modal);
216
- var panel = PropTypes$1.shape({
217
- id: PropTypes$1.string.isRequired
218
- });
219
- var panels = PropTypes$1.arrayOf(panel);
220
- var button = PropTypes$1.shape({
221
- label: label,
222
- onClick: PropTypes$1.func
223
- });
224
- var buttons = PropTypes$1.arrayOf(button);
225
- var bootstrapThemeStrings = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'];
226
- var bootstrapThemes = PropTypes$1.oneOf(bootstrapThemeStrings);
227
- var buttonTheme = PropTypes$1.oneOf([].concat(bootstrapThemeStrings, ['outline-primary', 'outline-secondary', 'outline-success', 'outline-danger', 'outline-warning', 'outline-info', 'outline-light', 'outline-dark', 'outline-link', null]));
228
- var buttonSize = PropTypes$1.oneOf(['lg', 'sm', null]);
229
- var formControlSize = PropTypes$1.oneOf(['lg', 'sm', null]);
230
- var dropdownAlign = PropTypes$1.oneOf(['start', 'end']);
231
- var componentNames = function componentNames(Components) {
232
- return PropTypes$1.oneOf(Object.keys(Components).map(function (it) {
233
- return snakeCase(it);
234
- }));
235
- };
236
- var component = PropTypes$1.oneOfType([PropTypes$1.object, PropTypes$1.func]);
237
- var components = PropTypes$1.objectOf(component);
238
-
239
- /**
240
- * Forms
241
- */
242
- var errors = PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.arrayOf(PropTypes$1.string)]);
243
- var formErrors = PropTypes$1.objectOf(errors);
244
- var selectOption = PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.shape({
245
- value: PropTypes$1.any,
246
- // eslint-disable-line
247
- label: label
248
- })]);
249
- var selectOptions = PropTypes$1.arrayOf(selectOption);
250
- var formField = PropTypes$1.shape({
251
- name: PropTypes$1.string,
252
- component: component
253
- });
254
- var formFields = PropTypes$1.arrayOf(formField);
255
-
256
- /**
257
- * Medias
258
- */
259
- var mediaMetadataShape = {
260
- filename: PropTypes$1.string,
261
- size: PropTypes$1.number,
262
- mime: PropTypes$1.string
263
- };
264
- var mediaFile = PropTypes$1.shape({
265
- id: PropTypes$1.string,
266
- handle: PropTypes$1.string,
267
- type: PropTypes$1.string,
268
- mime: PropTypes$1.string,
269
- url: PropTypes$1.string
270
- });
271
- var mediaShape = {
272
- id: PropTypes$1.string,
273
- type: PropTypes$1.string.isRequired,
274
- url: PropTypes$1.string,
275
- // .isRequired,
276
- thumbnail_url: PropTypes$1.string,
277
- name: PropTypes$1.string,
278
- metadata: PropTypes$1.shape(_objectSpread({}, mediaMetadataShape)),
279
- files: PropTypes$1.objectOf(mediaFile)
280
- };
281
- var media = PropTypes$1.shape(mediaShape);
282
- var medias = PropTypes$1.arrayOf(media);
283
- var mediaTypes = PropTypes$1.oneOf(['image', 'video', 'audio', 'closed-captions', 'font']);
284
- var imageMedia = PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaShape), {}, {
285
- type: PropTypes$1.oneOf(['image', 'video']),
286
- metadata: PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaMetadataShape), {}, {
287
- width: PropTypes$1.number,
288
- height: PropTypes$1.number
289
- }))
290
- }));
291
- var imageMedias = PropTypes$1.arrayOf(imageMedia);
292
- var fontMedia = PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaShape), {}, {
293
- type: PropTypes$1.oneOf(['font']),
294
- metadata: PropTypes$1.shape(_objectSpread({}, mediaMetadataShape))
295
- }));
296
- var fontMedias = PropTypes$1.arrayOf(fontMedia);
297
- var videoMedia = PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaShape), {}, {
298
- type: PropTypes$1.oneOf(['video']),
299
- metadata: PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaMetadataShape), {}, {
300
- width: PropTypes$1.number,
301
- height: PropTypes$1.number,
302
- duration: PropTypes$1.number
303
- }))
304
- }));
305
- var videoMedias = PropTypes$1.arrayOf(videoMedia);
306
- var audioMedia = PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaShape), {}, {
307
- type: PropTypes$1.oneOf(['audio']),
308
- metadata: PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaMetadataShape), {}, {
309
- duration: PropTypes$1.number
310
- }))
311
- }));
312
- var audioMedias = PropTypes$1.arrayOf(audioMedia);
313
- var closedCaptionsMedia = PropTypes$1.shape(_objectSpread(_objectSpread({}, mediaShape), {}, {
314
- type: PropTypes$1.oneOf(['closed-captions'])
315
- }));
316
-
317
- /**
318
- * Style
319
- */
320
-
321
- var customFont = PropTypes$1.shape({
322
- type: PropTypes$1.oneOf(['system', 'google', 'custom']),
323
- name: PropTypes$1.string,
324
- media: fontMedia
325
- });
326
- var font = PropTypes$1.oneOfType([PropTypes$1.object, PropTypes$1.string]);
327
- var fonts = PropTypes$1.arrayOf(font);
328
- var textAlign = PropTypes$1.oneOf(['left', 'right', 'center']);
329
- var colorObject = PropTypes$1.shape({
330
- color: PropTypes$1.string,
331
- alpha: PropTypes$1.number
332
- });
333
- var color = PropTypes$1.oneOfType([colorObject, PropTypes$1.string]);
334
- var textStyle = PropTypes$1.shape({
335
- fontFamily: font,
336
- fontSize: PropTypes$1.number,
337
- fontStyle: PropTypes$1.shape({
338
- bold: PropTypes$1.bool,
339
- italic: PropTypes$1.bool,
340
- underline: PropTypes$1.bool,
341
- upperCase: PropTypes$1.bool
342
- }),
343
- align: textAlign,
344
- color: color,
345
- letterSpacing: PropTypes$1.number,
346
- lineHeight: PropTypes$1.number
347
- });
348
- var borderTypes = PropTypes$1.oneOf(['dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset', 'hidden']);
349
- var shadowType = PropTypes$1.shape({
350
- shadowDistance: PropTypes$1.number,
351
- shadowBlur: PropTypes$1.number,
352
- shadowColor: color
353
- });
354
- var borderStyle = PropTypes$1.shape({
355
- width: PropTypes$1.number,
356
- style: borderTypes,
357
- radius: PropTypes$1.number,
358
- color: color
359
- });
360
- var boxStyle = PropTypes$1.shape({
361
- backgroundColor: color,
362
- borderRadius: PropTypes$1.number,
363
- borderWidth: PropTypes$1.number,
364
- borderColor: color,
365
- borderStyle: borderTypes,
366
- shadow: shadowType
367
- });
368
- var margin = PropTypes$1.shape({
369
- top: PropTypes$1.number,
370
- bottom: PropTypes$1.number
371
- });
372
- var gridLayout = PropTypes$1.arrayOf(PropTypes$1.shape({
373
- rows: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.arrayOf(PropTypes$1.number)]),
374
- columns: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.arrayOf(PropTypes$1.number)])
375
- }));
376
- var objectFitSize = PropTypes$1.oneOf(['cover', 'contain', null]);
377
- var objectFit = PropTypes$1.shape({
378
- fit: objectFitSize,
379
- horizontalPosition: PropTypes$1.oneOf(['left', 'center', 'right']),
380
- verticalPosition: PropTypes$1.oneOf(['top', 'center', 'bottom'])
381
- });
382
-
383
- /**
384
- * Elements
385
- */
386
-
387
- var textElement = PropTypes$1.shape({
388
- body: PropTypes$1.string,
389
- textStyle: textStyle
390
- });
391
- var headingElement = textElement;
392
- var inputElement = PropTypes$1.shape({
393
- label: PropTypes$1.string,
394
- textStyle: textStyle
395
- });
396
- var imageElement = PropTypes$1.shape({
397
- media: imageMedia
398
- });
399
- var imageElements = PropTypes$1.arrayOf(imageElement);
400
- var videoElement = PropTypes$1.shape({
401
- media: videoMedia,
402
- autoPlay: PropTypes$1.bool,
403
- loop: PropTypes$1.bool,
404
- closedCaptions: closedCaptionsMedia,
405
- withSeekBar: PropTypes$1.bool,
406
- withControls: PropTypes$1.bool
407
- });
408
- var visualElement = PropTypes$1.shape({
409
- media: imageMedia
410
- });
411
- var visualElements = PropTypes$1.arrayOf(visualElement);
412
- var audioElement = PropTypes$1.shape({
413
- media: audioMedia,
414
- autoPlay: PropTypes$1.bool,
415
- loop: PropTypes$1.bool,
416
- closedCaptions: closedCaptionsMedia,
417
- withPlayPause: PropTypes$1.bool
418
- });
419
- var closedCaptionsElement = PropTypes$1.shape({
420
- media: closedCaptionsMedia
421
- });
422
- var backgroundElement = PropTypes$1.shape({
423
- color: color,
424
- image: imageMedia,
425
- video: videoMedia
426
- });
427
- var imageElementWithCaption = PropTypes$1.shape({
428
- image: imageMedia,
429
- caption: textElement
430
- });
431
- var imageElementsWithCaption = PropTypes$1.arrayOf(imageElementWithCaption);
432
- var stackDirection = PropTypes$1.oneOf(['horizontal', 'vertical']);
433
- var stackAlign = PropTypes$1.oneOf(['start', 'center', 'end']);
434
- var stackSpacing = PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.oneOf(['between', 'evenly', 'around'])]);
435
- var stackElement = PropTypes$1.shape({
436
- direction: stackDirection,
437
- align: stackAlign,
438
- width: PropTypes$1.number,
439
- height: PropTypes$1.number,
440
- spacing: stackSpacing,
441
- reverse: PropTypes$1.bool
442
- });
443
- var gridElement = PropTypes$1.shape({
444
- layout: PropTypes$1.arrayOf(PropTypes$1.string),
445
- spacing: PropTypes$1.number
446
- });
447
- var geoPosition = PropTypes$1.shape({
448
- lat: PropTypes$1.number,
449
- lng: PropTypes$1.number
450
- });
451
- var markerShape = {
452
- id: PropTypes$1.number,
453
- geoPosition: geoPosition,
454
- title: headingElement,
455
- subtitle: headingElement,
456
- description: textElement
457
- };
458
- var marker = PropTypes$1.shape(_objectSpread({}, markerShape));
459
- var markers = PropTypes$1.arrayOf(marker);
460
- var markerWithImage = PropTypes$1.shape(_objectSpread(_objectSpread({}, markerShape), {}, {
461
- image: imageMedia
462
- }));
463
- var markersWithImage = PropTypes$1.arrayOf(markerWithImage);
464
- var answerShape = {
465
- id: PropTypes$1.string,
466
- label: textElement
467
- };
468
- var answer = PropTypes$1.shape(_objectSpread({}, answerShape));
469
- var quizAnswer = PropTypes$1.shape(_objectSpread(_objectSpread({}, answerShape), {}, {
470
- good: PropTypes$1.bool
471
- }));
472
- var answers = PropTypes$1.arrayOf(answer);
473
- var quizAnswers = PropTypes$1.arrayOf(quizAnswer);
474
- var callToActionTypes = PropTypes$1.oneOf(['swipe-up', 'button']);
475
- var callToAction = PropTypes$1.shape({
476
- active: PropTypes$1.bool,
477
- type: callToActionTypes,
478
- url: PropTypes$1.string,
479
- label: textElement,
480
- buttonStyle: boxStyle
481
- });
482
- var shareIncentive = PropTypes$1.shape({
483
- active: PropTypes$1.bool,
484
- label: textElement,
485
- boxStyle: boxStyle
486
- });
487
- var activeForm = PropTypes$1.shape({
488
- active: PropTypes$1.bool
489
- });
490
- var speaker = PropTypes$1.shape({
491
- id: PropTypes$1.string,
492
- name: PropTypes$1.string,
493
- avatar: imageMedia,
494
- side: PropTypes$1.oneOf(['left', 'right']),
495
- color: color
496
- });
497
- var speakers = PropTypes$1.arrayOf(speaker);
498
- var conversationMessage = PropTypes$1.shape({
499
- speaker: PropTypes$1.string,
500
- message: PropTypes$1.string,
501
- image: imageMedia,
502
- audio: audioMedia,
503
- timingOverrides: PropTypes$1.shape({
504
- enabled: PropTypes$1.bool,
505
- appearDelay: PropTypes$1.number,
506
- writingStateDuration: PropTypes$1.number
507
- })
508
- });
509
- var conversationMessages = PropTypes$1.arrayOf(conversationMessage);
510
- var conversation = PropTypes$1.shape({
511
- speakers: speakers,
512
- textStyle: textStyle,
513
- messages: conversationMessages
514
- });
515
-
516
- /**
517
- * Definitions
518
- */
519
-
520
- var fieldShape = {
521
- name: PropTypes$1.string,
522
- type: PropTypes$1.string.isRequired,
523
- label: text
524
- };
525
- var field = PropTypes$1.shape(_objectSpread(_objectSpread({}, fieldShape), {}, {
526
- isSection: PropTypes$1.bool,
527
- fields: PropTypes$1.arrayOf(PropTypes$1.shape(fieldShape))
528
- }));
529
- var fields = PropTypes$1.arrayOf(field);
530
- var screenDefinition = PropTypes$1.shape({
531
- id: PropTypes$1.string.isRequired,
532
- type: PropTypes$1.oneOf(['screen']).isRequired,
533
- title: text.isRequired,
534
- layouts: PropTypes$1.arrayOf(PropTypes$1.string),
535
- fields: fields
536
- });
537
- var screenDefinitions = PropTypes$1.arrayOf(screenDefinition);
538
- var fieldDefinition = PropTypes$1.shape({
539
- id: PropTypes$1.string.isRequired,
540
- type: PropTypes$1.oneOf(['field']).isRequired,
541
- title: text.isRequired,
542
- fields: fields
543
- });
544
- var fieldDefinitions = PropTypes$1.arrayOf(fieldDefinition);
545
-
546
- /**
547
- * Components
548
- */
549
- var storyComponentShape = {
550
- type: PropTypes$1.string.isRequired
551
- };
552
- var storyComponent = PropTypes$1.shape(_objectSpread({}, storyComponentShape));
553
- var storyComponents = PropTypes$1.arrayOf(storyComponent);
554
- var screenComponent = PropTypes$1.shape(_objectSpread({}, storyComponentShape));
555
- var screenComponents = PropTypes$1.arrayOf(screenComponent);
556
- var screen = screenComponent; // @NOTE should be removed
557
-
558
- /**
559
- * Theme
560
- */
561
- var theme = PropTypes$1.shape({
562
- id: PropTypes$1.string,
563
- textStyles: PropTypes$1.objectOf(textStyle),
564
- // renamed to textstyles
565
- background: backgroundElement,
566
- colors: PropTypes$1.objectOf(color),
567
- components: screenComponents
568
- });
569
- var viewerTheme = PropTypes$1.shape(_objectSpread({
570
- logo: imageMedia
571
- }, theme));
572
-
573
- /**
574
- * Branding
575
- */
576
-
577
- // export const branding = PropTypes.shape({
578
- // logo: imageMedia,
579
- // primaryColor: color,
580
- // secondaryColor: color,
581
- // backgroundColor: color,
582
- // textStyle,
583
- // });
584
-
585
- /**
586
- * Metadata
587
- */
588
- var metadata = PropTypes$1.shape({
589
- description: PropTypes$1.string,
590
- shareUrl: PropTypes$1.string,
591
- shareImage: imageMedia,
592
- favIcon: imageMedia
593
- });
594
- var tag = PropTypes$1.shape({
595
- label: PropTypes$1.string,
596
- value: PropTypes$1.oneOfType([PropTypes$1.number, PropTypes$1.string])
597
- });
598
- var tags = PropTypes$1.arrayOf(tag);
599
-
600
- /**
601
- * Story
602
- */
603
- var story = PropTypes$1.shape({
604
- id: PropTypes$1.string,
605
- theme: theme,
606
- components: screenComponents,
607
- metadata: metadata
608
- });
609
-
610
- /**
611
- * Render
612
- */
613
- var deviceScreen = PropTypes$1.shape({
614
- name: PropTypes$1.string.isRequired,
615
- mediaQuery: PropTypes$1.string
616
- });
617
- var deviceScreens = PropTypes$1.arrayOf(deviceScreen);
618
- var screenSize = PropTypes$1.shape({
619
- screen: PropTypes$1.string,
620
- screens: PropTypes$1.arrayOf(PropTypes$1.string),
621
- width: PropTypes$1.number,
622
- height: PropTypes$1.number,
623
- landscape: PropTypes$1.bool
624
- });
625
- var renderContext = PropTypes$1.oneOf(['view', 'placeholder', 'edit', 'preview', 'static', 'capture']);
626
-
627
- /**
628
- * Screens
629
- */
630
-
631
- var adFormats = PropTypes$1.shape({
632
- width: PropTypes$1.number,
633
- height: PropTypes$1.number
634
- });
635
- var adFormat = PropTypes$1.shape({
636
- width: PropTypes$1.number,
637
- height: PropTypes$1.number,
638
- url: PropTypes$1.string,
639
- target: target,
640
- iframe: PropTypes$1.string,
641
- image: imageMedia
642
- });
643
- var audioComponent = PropTypes$1.shape({
644
- src: PropTypes$1.string,
645
- track: PropTypes$1.string,
646
- trackLng: PropTypes$1.number,
647
- controls: PropTypes$1.bool
648
- });
649
- var slide = PropTypes$1.shape({
650
- image: imageMedia,
651
- text: PropTypes$1.string
652
- });
653
- var slides = PropTypes$1.arrayOf(slide);
654
-
655
- // export const imageStyle = PropTypes.shape({
656
- // alt: PropTypes.string,
657
- // fit: PropTypes.object,
658
- // });
659
-
660
- var containerStyle = PropTypes$1.shape({});
661
-
662
- /**
663
- * Transitions
664
- */
665
-
666
- var transitionName = PropTypes$1.oneOf(['fade', 'scale', 'slide']);
667
- var transitionParams = {
668
- duration: PropTypes$1.number,
669
- easing: PropTypes$1.oneOf(['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear'])
670
- };
671
- var transition = PropTypes$1.oneOfType([transitionName.isRequired, PropTypes$1.shape(_objectSpread({
672
- name: transitionName.isRequired
673
- }, transitionParams))]);
674
- var transitions = PropTypes$1.shape({
675
- "in": transition,
676
- out: transition
677
- });
678
-
679
- /**
680
- * Search
681
- */
682
-
683
- var searchFilter = PropTypes$1.shape({
684
- type: PropTypes$1.string,
685
- value: PropTypes$1.oneOf([PropTypes$1.string, PropTypes$1.number])
686
- });
687
- var searchFilters = PropTypes$1.arrayOf(searchFilter);
688
-
689
- /**
690
- * Payments
691
- */
692
-
693
- var paymentItem = PropTypes$1.shape({
694
- id: PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number]),
695
- date: PropTypes$1.string,
696
- type: PropTypes$1.string,
697
- invoice_link: PropTypes$1.string,
698
- amount: PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number])
699
- });
700
- var paymentItems = PropTypes$1.arrayOf(paymentItem);
701
-
702
- /**
703
- * Page Metadada
704
- */
705
-
706
- var pageMetadata = PropTypes$1.shape({
707
- canonical: PropTypes$1.string,
708
- description: PropTypes$1.string,
709
- keywords: PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.array]),
710
- image: PropTypes$1.shape({
711
- url: PropTypes$1.string
712
- }),
713
- favicon: PropTypes$1.shape({
714
- url: PropTypes$1.string
715
- }),
716
- rssUrl: PropTypes$1.string,
717
- atomUrl: PropTypes$1.string,
718
- microformats: PropTypes$1.arrayOf(PropTypes$1.shape({}))
719
- });
720
- var authorElement = PropTypes$1.shape({
721
- name: textElement,
722
- avatar: PropTypes$1.shape({
723
- url: PropTypes$1.string
724
- })
725
- });
726
- var visitor = PropTypes$1.shape({
727
- id: PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number]),
728
- name: PropTypes$1.string
729
- });
730
- var badge = PropTypes$1.shape({
731
- label: textElement,
732
- buttonStyle: boxStyle
733
- });
734
- var header = PropTypes$1.shape({
735
- badge: badge
736
- });
737
- var footer = PropTypes$1.shape({
738
- callToAction: callToAction
739
- });
740
- var reload = PropTypes$1.shape();
741
- var closedCaptions = PropTypes$1.shape({
742
- file: closedCaptionsMedia,
743
- textStyle: textStyle,
744
- boxStyle: boxStyle
745
- });
746
-
747
- var PropTypes = /*#__PURE__*/Object.freeze({
748
- __proto__: null,
749
- activeForm: activeForm,
750
- adFormat: adFormat,
751
- adFormats: adFormats,
752
- answer: answer,
753
- answerShape: answerShape,
754
- answers: answers,
755
- audioComponent: audioComponent,
756
- audioElement: audioElement,
757
- audioMedia: audioMedia,
758
- audioMedias: audioMedias,
759
- authorElement: authorElement,
760
- backgroundElement: backgroundElement,
761
- badge: badge,
762
- bootstrapThemes: bootstrapThemes,
763
- borderStyle: borderStyle,
764
- borderTypes: borderTypes,
765
- boxStyle: boxStyle,
766
- breadcrumb: breadcrumb,
767
- breadcrumbs: breadcrumbs,
768
- button: button,
769
- buttonSize: buttonSize,
770
- buttonTheme: buttonTheme,
771
- buttons: buttons,
772
- callToAction: callToAction,
773
- callToActionTypes: callToActionTypes,
774
- closedCaptions: closedCaptions,
775
- closedCaptionsElement: closedCaptionsElement,
776
- closedCaptionsMedia: closedCaptionsMedia,
777
- colorObject: colorObject,
778
- component: component,
779
- componentNames: componentNames,
780
- components: components,
781
- containerStyle: containerStyle,
782
- conversation: conversation,
783
- conversationMessage: conversationMessage,
784
- conversationMessages: conversationMessages,
785
- customFont: customFont,
786
- defaultMessage: defaultMessage,
787
- defaultMessageContent: defaultMessageContent,
788
- device: device,
789
- deviceScreen: deviceScreen,
790
- deviceScreens: deviceScreens,
791
- devices: devices,
792
- dropdownAlign: dropdownAlign,
793
- errors: errors,
794
- field: field,
795
- fieldDefinition: fieldDefinition,
796
- fieldDefinitions: fieldDefinitions,
797
- fields: fields,
798
- font: font,
799
- fontMedia: fontMedia,
800
- fontMedias: fontMedias,
801
- fonts: fonts,
802
- footer: footer,
803
- formControlSize: formControlSize,
804
- formErrors: formErrors,
805
- formField: formField,
806
- formFields: formFields,
807
- geoPosition: geoPosition,
808
- gridElement: gridElement,
809
- gridLayout: gridLayout,
810
- header: header,
811
- headingElement: headingElement,
812
- history: history,
813
- imageElement: imageElement,
814
- imageElementWithCaption: imageElementWithCaption,
815
- imageElements: imageElements,
816
- imageElementsWithCaption: imageElementsWithCaption,
817
- imageMedia: imageMedia,
818
- imageMedias: imageMedias,
819
- inputElement: inputElement,
820
- interaction: interaction,
821
- interactions: interactions,
822
- intl: intl,
823
- label: label,
824
- location: location,
825
- margin: margin,
826
- marker: marker,
827
- markerWithImage: markerWithImage,
828
- markers: markers,
829
- markersWithImage: markersWithImage,
830
- media: media,
831
- mediaFile: mediaFile,
832
- mediaTypes: mediaTypes,
833
- medias: medias,
834
- menuItem: menuItem,
835
- menuItems: menuItems,
836
- message: message,
837
- metadata: metadata,
838
- modal: modal,
839
- modals: modals,
840
- objectFit: objectFit,
841
- objectFitSize: objectFitSize,
842
- pageMetadata: pageMetadata,
843
- panel: panel,
844
- panels: panels,
845
- paymentItem: paymentItem,
846
- paymentItems: paymentItems,
847
- progress: progress,
848
- quizAnswer: quizAnswer,
849
- quizAnswers: quizAnswers,
850
- ref: ref,
851
- reload: reload,
852
- renderContext: renderContext,
853
- screen: screen,
854
- screenComponent: screenComponent,
855
- screenComponents: screenComponents,
856
- screenDefinition: screenDefinition,
857
- screenDefinitions: screenDefinitions,
858
- screenSize: screenSize,
859
- searchFilter: searchFilter,
860
- searchFilters: searchFilters,
861
- selectOption: selectOption,
862
- selectOptions: selectOptions,
863
- shadowType: shadowType,
864
- shareIncentive: shareIncentive,
865
- slide: slide,
866
- slides: slides,
867
- speaker: speaker,
868
- speakers: speakers,
869
- stackAlign: stackAlign,
870
- stackDirection: stackDirection,
871
- stackElement: stackElement,
872
- stackSpacing: stackSpacing,
873
- statusCode: statusCode,
874
- story: story,
875
- storyComponent: storyComponent,
876
- storyComponents: storyComponents,
877
- tag: tag,
878
- tags: tags,
879
- target: target,
880
- text: text,
881
- textAlign: textAlign,
882
- textElement: textElement,
883
- textStyle: textStyle,
884
- theme: theme,
885
- trackingVariables: trackingVariables,
886
- transition: transition,
887
- transitionName: transitionName,
888
- transitions: transitions,
889
- user: user,
890
- videoElement: videoElement,
891
- videoMedia: videoMedia,
892
- videoMedias: videoMedias,
893
- viewerTheme: viewerTheme,
894
- visitor: visitor,
895
- visualElement: visualElement,
896
- visualElements: visualElements
897
- });
898
-
899
- var sortedColors = function sortedColors(colors) {
900
- return sortBy(colors, ['color', 'alpha']);
901
- };
902
- var uniqueColors = function uniqueColors(colors) {
903
- return uniqWith(colors, function (colorA, colorB) {
904
- return colorA.alpha === colorB.alpha && colorA.color === colorB.color;
905
- });
906
- };
907
- var ColorsParser = /*#__PURE__*/function () {
908
- function ColorsParser(_ref) {
909
- var fieldsManager = _ref.fieldsManager,
910
- screensManager = _ref.screensManager;
911
- _classCallCheck(this, ColorsParser);
912
- this.fieldsManager = fieldsManager;
913
- this.screensManager = screensManager;
914
- }
915
-
916
- // Convert medias object to path
917
- return _createClass(ColorsParser, [{
918
- key: "parse",
919
- value: function parse(story) {
920
- var _this = this;
921
- if (story === null) {
922
- return story;
923
- }
924
- var _ref2 = story || {},
925
- _ref2$theme = _ref2.theme,
926
- theme = _ref2$theme === void 0 ? null : _ref2$theme,
927
- _ref2$components = _ref2.components,
928
- components = _ref2$components === void 0 ? [] : _ref2$components;
929
- var _components$reduce = components.reduce(function (_ref3, screen) {
930
- var _ref3$colors = _ref3.colors,
931
- currentColors = _ref3$colors === void 0 ? null : _ref3$colors;
932
- var type = screen.type;
933
- var _ref4 = _this.screensManager.getDefinition(type) || {},
934
- _ref4$fields = _ref4.fields,
935
- fields = _ref4$fields === void 0 ? [] : _ref4$fields;
936
- var fieldsPattern = _this.getColorFieldPatterns(fields);
937
- var _ColorsParser$getColo = ColorsParser.getColorsFromPath(screen, fieldsPattern),
938
- newColors = _ColorsParser$getColo.colors;
939
- return {
940
- colors: [].concat(_toConsumableArray(currentColors), _toConsumableArray(newColors))
941
- };
942
- }, {
943
- colors: []
944
- }),
945
- colors = _components$reduce.colors;
946
- if (theme !== null) {
947
- var themeColors = this.parse(theme);
948
- return colors !== null || themeColors !== null ? uniqueColors([].concat(_toConsumableArray(sortedColors(themeColors || [])), _toConsumableArray(sortedColors(colors || [])))) : [];
949
- }
950
- return colors !== null ? sortedColors(uniqueColors(colors || [])) : [];
951
- }
952
- }, {
953
- key: "getColorFieldPatterns",
954
- value: function getColorFieldPatterns(fields) {
955
- var _this2 = this;
956
- var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
957
- return fields.reduce(function (patterns, field) {
958
- var _field$name = field.name,
959
- name = _field$name === void 0 ? null : _field$name,
960
- _field$type = field.type,
961
- type = _field$type === void 0 ? null : _field$type;
962
- var path = [namePrefix, name].filter(function (it) {
963
- return it !== null;
964
- }).join('\\.');
965
- var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
966
- // also check settings fields
967
- var _fieldDefinition$fiel = fieldDefinition.fields,
968
- subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
969
- _fieldDefinition$item = fieldDefinition.itemsField,
970
- itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
971
- _fieldDefinition$sett = fieldDefinition.settings,
972
- settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
973
- return [].concat(_toConsumableArray(patterns), _toConsumableArray(ColorsParser.fieldIsColor(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(_this2.getColorFieldPatterns(subFields, path)), _toConsumableArray(_this2.getColorFieldPatterns(settings, path)), _toConsumableArray(itemsField !== null ? _this2.getColorFieldPatterns([itemsField], "".concat(path, "\\.[0-9]+")) : []));
974
- }, []);
975
- }
976
- }], [{
977
- key: "fieldIsColor",
978
- value: function fieldIsColor(_ref5) {
979
- var _ref5$id = _ref5.id,
980
- id = _ref5$id === void 0 ? null : _ref5$id;
981
- return id === 'color';
982
- }
983
- }, {
984
- key: "getColorsFromPath",
985
- value: function getColorsFromPath(data, patterns) {
986
- var colors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
987
- var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
988
- var dataIsArray = isArray(data);
989
- var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
990
- return keys.reduce(function (_ref6, key) {
991
- var currentData = _ref6.data,
992
- _ref6$colors = _ref6.colors,
993
- currentColors = _ref6$colors === void 0 ? null : _ref6$colors;
994
- var path = [keyPrefix, key].filter(function (it) {
995
- return it !== null;
996
- }).join('.');
997
- var patternMatch = patterns.reduce(function (found, pattern) {
998
- return found || pattern.test(path);
999
- }, false);
1000
- var value = data[key];
1001
- var color = null;
1002
- var newValue = null;
1003
- var subColors = null;
1004
- if (patternMatch && isObject(value)) {
1005
- if (value.color && value.color.length === 4) {
1006
- var innerColor = value.color.split('').map(function (hex, i) {
1007
- return i > 0 ? hex + hex : hex;
1008
- }).join('').toUpperCase();
1009
- color = {
1010
- alpha: value.alpha || 1,
1011
- color: innerColor
1012
- };
1013
- } else if (value.color) {
1014
- color = {
1015
- alpha: value.alpha,
1016
- color: value.color.toUpperCase()
1017
- };
1018
- }
1019
- } else if (isObject(value) || isArray(value)) {
1020
- var subReturn = ColorsParser.getColorsFromPath(value, patterns, colors, path);
1021
- newValue = subReturn.data;
1022
- subColors = subReturn.colors;
1023
- } else {
1024
- newValue = value;
1025
- }
1026
- return {
1027
- data: dataIsArray ? [].concat(_toConsumableArray(currentData || []), [newValue]) : _objectSpread(_objectSpread({}, currentData), {}, _defineProperty({}, key, newValue)),
1028
- colors: color !== null ? [].concat(_toConsumableArray(currentColors || []), _toConsumableArray(subColors || []), [color]) : [].concat(_toConsumableArray(currentColors || []), _toConsumableArray(subColors || []))
1029
- };
1030
- }, {
1031
- data: keys.length === 0 ? data : null,
1032
- colors: colors
1033
- });
1034
- }
1035
- }]);
1036
- }();
1037
- var ColorsParser$1 = ColorsParser;
1038
-
1039
- var getComponentFromName = function getComponentFromName() {
1040
- var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1041
- var components = arguments.length > 1 ? arguments[1] : undefined;
1042
- var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1043
- if (components === null || name === null) {
1044
- return defaultComponent;
1045
- }
1046
- var pascalName = pascalCase(name);
1047
- return components[pascalName] || components[name] || defaultComponent;
1048
- };
1049
-
1050
- function getScreenFieldsWithStates(definition) {
1051
- var _ref = definition || {},
1052
- _ref$fields = _ref.fields,
1053
- screenFields = _ref$fields === void 0 ? null : _ref$fields,
1054
- _ref$states = _ref.states,
1055
- states = _ref$states === void 0 ? null : _ref$states;
1056
- if (states === null) {
1057
- return screenFields;
1058
- }
1059
- var extraFields = states.reduce(function (statesFields, current) {
1060
- var _ref2 = current || {},
1061
- id = _ref2.id,
1062
- _ref2$fields = _ref2.fields,
1063
- fields = _ref2$fields === void 0 ? [] : _ref2$fields,
1064
- _ref2$repeatable = _ref2.repeatable,
1065
- repeatable = _ref2$repeatable === void 0 ? false : _ref2$repeatable,
1066
- _ref2$fieldName = _ref2.fieldName,
1067
- fieldName = _ref2$fieldName === void 0 ? null : _ref2$fieldName,
1068
- label = _ref2.label,
1069
- _ref2$defaultValue = _ref2.defaultValue,
1070
- defaultValue = _ref2$defaultValue === void 0 ? null : _ref2$defaultValue;
1071
- return [].concat(_toConsumableArray(statesFields), _toConsumableArray(repeatable ? [{
1072
- type: 'items',
1073
- name: fieldName || id,
1074
- label: label,
1075
- defaultValue: defaultValue,
1076
- stateId: id,
1077
- itemsField: {
1078
- label: label,
1079
- type: 'fields',
1080
- fields: fields
1081
- }
1082
- }] : []), _toConsumableArray(!repeatable && fieldName !== null ? [{
1083
- type: 'fields',
1084
- name: fieldName,
1085
- stateId: id,
1086
- fields: fields
1087
- }] : []), _toConsumableArray(!repeatable && fieldName === null ? fields.map(function (it) {
1088
- return _objectSpread(_objectSpread({}, it), {}, {
1089
- stateId: id
1090
- });
1091
- }) : []));
1092
- }, []);
1093
- return [].concat(_toConsumableArray(extraFields), _toConsumableArray(screenFields));
1094
- }
1095
-
1096
- var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
1097
- function ComponentsManager() {
1098
- var _this;
1099
- var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1100
- _classCallCheck(this, ComponentsManager);
1101
- _this = _callSuper(this, ComponentsManager);
1102
- _this.components = components;
1103
- return _this;
1104
- }
1105
- _inherits(ComponentsManager, _EventEmitter);
1106
- return _createClass(ComponentsManager, [{
1107
- key: "addComponent",
1108
- value: function addComponent(name, component) {
1109
- var namespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1110
- return this.addComponents(_defineProperty({}, name, component), namespace);
1111
- }
1112
- }, {
1113
- key: "addComponents",
1114
- value: function addComponents(components) {
1115
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1116
- var newComponents = namespace !== null ? Object.keys(components).reduce(function (componentsMaps, name) {
1117
- return _objectSpread(_objectSpread({}, componentsMaps), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), components[name]));
1118
- }, {}) : components;
1119
- this.components = _objectSpread(_objectSpread({}, this.components), newComponents);
1120
- this.emit('change');
1121
- return this;
1122
- }
1123
- }, {
1124
- key: "merge",
1125
- value: function merge(manager) {
1126
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1127
- return this.addComponents(manager.getComponents(), namespace);
1128
- }
1129
- }, {
1130
- key: "addNamespace",
1131
- value: function addNamespace(namespace) {
1132
- var _this2 = this;
1133
- if (namespace === null) {
1134
- return this;
1135
- }
1136
- this.components = Object.keys(this.components).reduce(function (componentsMap, name) {
1137
- return _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), _this2.components[name]));
1138
- }, {});
1139
- return this;
1140
- }
1141
- }, {
1142
- key: "getComponent",
1143
- value: function getComponent(name) {
1144
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1145
- var components = this.getComponents(namespace);
1146
- return getComponentFromName(name, components);
1147
- }
1148
- }, {
1149
- key: "getComponents",
1150
- value: function getComponents() {
1151
- var _this3 = this;
1152
- var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1153
- return namespace !== null ? Object.keys(this.components || {}).reduce(function (componentsMap, name) {
1154
- var pattern = new RegExp("^".concat(namespace, "\\.(.*)$"));
1155
- var matches = pattern.exec(name);
1156
- return matches !== null ? _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, matches[1], _this3.components[name])) : componentsMap;
1157
- }, null) : this.components;
1158
- }
1159
- }, {
1160
- key: "hasComponent",
1161
- value: function hasComponent(name) {
1162
- var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1163
- return this.components !== null && typeof this.components[namespace !== null ? "".concat(namespace, ".").concat(name) : name] !== 'undefined';
1164
- }
1165
- }]);
1166
- }(EventEmitter);
1167
- var ComponentsManager$1 = ComponentsManager;
1168
-
1169
- var DefinitionsManager = /*#__PURE__*/function (_EventEmitter) {
1170
- function DefinitionsManager() {
1171
- var _this;
1172
- var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1173
- _classCallCheck(this, DefinitionsManager);
1174
- _this = _callSuper(this, DefinitionsManager);
1175
- _this.definitions = definitions || [];
1176
- return _this;
1177
- }
1178
- _inherits(DefinitionsManager, _EventEmitter);
1179
- return _createClass(DefinitionsManager, [{
1180
- key: "addDefinition",
1181
- value: function addDefinition(definition) {
1182
- this.addDefinitions(isArray(definition) ? definition : [definition]);
1183
- return this;
1184
- }
1185
- }, {
1186
- key: "addDefinitions",
1187
- value: function addDefinitions(definitions) {
1188
- this.definitions = uniqBy([].concat(_toConsumableArray(definitions), _toConsumableArray(this.definitions)), function (it) {
1189
- return it.id;
1190
- });
1191
- this.emit('change');
1192
- return this;
1193
- }
1194
- }, {
1195
- key: "merge",
1196
- value: function merge(manager) {
1197
- return this.addDefinitions(manager.getDefinitions());
1198
- }
1199
- }, {
1200
- key: "filter",
1201
- value: function filter(_filter) {
1202
- // this.definitions = this.definitions.filter(filter);
1203
- // return this;
1204
- return new DefinitionsManager(this.definitions.filter(_filter));
1205
- }
1206
- }, {
1207
- key: "getDefinition",
1208
- value: function getDefinition(id) {
1209
- if (id === null) {
1210
- return null;
1211
- }
1212
- return this.definitions.find(function (it) {
1213
- return it.id === id;
1214
- }) || null;
1215
- }
1216
- }, {
1217
- key: "getDefinitions",
1218
- value: function getDefinitions() {
1219
- return this.definitions;
1220
- }
1221
- }, {
1222
- key: "hasDefinition",
1223
- value: function hasDefinition(id) {
1224
- return this.getDefinition(id) !== null;
1225
- }
1226
- }, {
1227
- key: "getComponent",
1228
- value: function getComponent(id) {
1229
- var _ref = this.getDefinition(id) || {},
1230
- _ref$component = _ref.component,
1231
- component = _ref$component === void 0 ? null : _ref$component;
1232
- return component;
1233
- }
1234
- }, {
1235
- key: "getComponents",
1236
- value: function getComponents() {
1237
- return this.definitions.reduce(function (allComponents, _ref2) {
1238
- var id = _ref2.id,
1239
- _ref2$component = _ref2.component,
1240
- component = _ref2$component === void 0 ? null : _ref2$component;
1241
- return component !== null ? _objectSpread(_objectSpread({}, allComponents), {}, _defineProperty({}, id, component)) : allComponents;
1242
- }, {});
1243
- }
1244
- }]);
1245
- }(EventEmitter);
1246
- var DefinitionsManager$1 = DefinitionsManager;
1247
-
1248
- var EventsManager = /*#__PURE__*/function (_EventEmitter) {
1249
- function EventsManager(element) {
1250
- var _this;
1251
- _classCallCheck(this, EventsManager);
1252
- _this = _callSuper(this, EventsManager);
1253
- _this.element = element;
1254
- _this.events = {};
1255
- _this.listeners = {};
1256
- return _this;
1257
- }
1258
- _inherits(EventsManager, _EventEmitter);
1259
- return _createClass(EventsManager, [{
1260
- key: "subscribe",
1261
- value: function subscribe(event, callback) {
1262
- this.on(event, callback);
1263
- this.events = _objectSpread(_objectSpread({}, this.events), {}, _defineProperty({}, event, [].concat(_toConsumableArray(this.events[event] || []), [callback])));
1264
- if (this.events[event].length === 1) {
1265
- this.addEventListener(event);
1266
- }
1267
- }
1268
- }, {
1269
- key: "unsubscribe",
1270
- value: function unsubscribe(event, callback) {
1271
- var _this2 = this;
1272
- this.off(event, callback);
1273
- this.events = Object.keys(this.events).reduce(function (newEvents, eventName) {
1274
- if (eventName !== event) {
1275
- return _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, _this2.events[eventName]));
1276
- }
1277
- var newListeners = _this2.events[eventName].filter(function (listener) {
1278
- return listener !== callback;
1279
- });
1280
- return newListeners.length > 0 ? _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, newListeners)) : newEvents;
1281
- }, {});
1282
- if (typeof this.events[event] === 'undefined') {
1283
- this.removeEventListener(event);
1284
- }
1285
- }
1286
- }, {
1287
- key: "addEventListener",
1288
- value: function addEventListener(event) {
1289
- var _this3 = this;
1290
- if (typeof this.listeners[event] === 'undefined') {
1291
- this.listeners[event] = function () {
1292
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1293
- args[_key] = arguments[_key];
1294
- }
1295
- return _this3.emit.apply(_this3, [event].concat(args));
1296
- };
1297
- }
1298
- this.element.addEventListener(event, this.listeners[event]);
1299
- }
1300
- }, {
1301
- key: "removeEventListener",
1302
- value: function removeEventListener(event) {
1303
- this.element.removeEventListener(event, this.listeners[event]);
1304
- }
1305
- }]);
1306
- }(EventEmitter);
1307
- var EventsManager$1 = EventsManager;
1308
-
1309
- var FieldsManager = /*#__PURE__*/function (_DefinitionsManager) {
1310
- function FieldsManager() {
1311
- _classCallCheck(this, FieldsManager);
1312
- return _callSuper(this, FieldsManager, arguments);
1313
- }
1314
- _inherits(FieldsManager, _DefinitionsManager);
1315
- return _createClass(FieldsManager, [{
1316
- key: "filter",
1317
- value: function filter(_filter) {
1318
- return new FieldsManager(this.definitions.filter(_filter));
1319
- // this.definitions = this.definitions.filter(filter);
1320
- // return this;
1321
- }
1322
- }]);
1323
- }(DefinitionsManager$1);
1324
- var FieldsManager$1 = FieldsManager;
1325
-
1326
- var _excluded$4 = ["medias"],
1327
- _excluded2$2 = ["medias"];
1328
- var MediasParser = /*#__PURE__*/function () {
1329
- function MediasParser(_ref) {
1330
- var fieldsManager = _ref.fieldsManager,
1331
- screensManager = _ref.screensManager,
1332
- _ref$fieldsPattern = _ref.fieldsPattern,
1333
- fieldsPattern = _ref$fieldsPattern === void 0 ? {} : _ref$fieldsPattern;
1334
- _classCallCheck(this, MediasParser);
1335
- this.fieldsManager = fieldsManager;
1336
- this.screensManager = screensManager;
1337
- this.fieldsPatternCache = fieldsPattern || {};
1338
- this.parsedThemesCache = {};
1339
- }
1340
- return _createClass(MediasParser, [{
1341
- key: "getParsedStoryTheme",
1342
- value: function getParsedStoryTheme(storyId, theme) {
1343
- if (typeof this.parsedThemesCache[storyId] === 'undefined') {
1344
- var _this$toPath = this.toPath(theme),
1345
- themeMedias = _this$toPath.medias,
1346
- newTheme = _objectWithoutProperties(_this$toPath, _excluded$4);
1347
- this.parsedThemesCache[storyId] = {
1348
- themeMedias: themeMedias,
1349
- newTheme: newTheme
1350
- };
1351
- }
1352
- return this.parsedThemesCache[storyId];
1353
- }
1354
- }, {
1355
- key: "getFieldsPatternByScreen",
1356
- value: function getFieldsPatternByScreen(type) {
1357
- if (typeof this.fieldsPatternCache[type] === 'undefined') {
1358
- var fields = getScreenFieldsWithStates(this.screensManager.getDefinition(type) || {});
1359
- this.fieldsPatternCache[type] = this.getFieldsPattern(fields || []);
1360
- }
1361
- return this.fieldsPatternCache[type];
1362
- }
1363
-
1364
- // Convert medias object to path
1365
- }, {
1366
- key: "toPath",
1367
- value: function toPath(story) {
1368
- var _this = this;
1369
- if (story === null) {
1370
- return story;
1371
- }
1372
- var _ref2 = story || {},
1373
- _ref2$id = _ref2.id,
1374
- storyId = _ref2$id === void 0 ? null : _ref2$id,
1375
- _ref2$theme = _ref2.theme,
1376
- theme = _ref2$theme === void 0 ? null : _ref2$theme,
1377
- _ref2$components = _ref2.components,
1378
- components = _ref2$components === void 0 ? [] : _ref2$components;
1379
- var _components$reduce = components.reduce(function (_ref3, screen) {
1380
- var previousComponents = _ref3.components,
1381
- currentMedias = _ref3.medias;
1382
- var type = screen.type;
1383
- var fieldsPattern = _this.getFieldsPatternByScreen(type);
1384
- var _MediasParser$replace = MediasParser.replaceMediasWithPaths(screen, fieldsPattern),
1385
- newScreen = _MediasParser$replace.data,
1386
- newMedias = _MediasParser$replace.medias;
1387
- return {
1388
- components: [].concat(_toConsumableArray(previousComponents), [newScreen]),
1389
- medias: _objectSpread(_objectSpread({}, currentMedias), newMedias)
1390
- };
1391
- }, {
1392
- components: [],
1393
- medias: null
1394
- }),
1395
- newComponents = _components$reduce.components,
1396
- medias = _components$reduce.medias;
1397
- if (theme !== null) {
1398
- var _this$getParsedStoryT = this.getParsedStoryTheme(storyId, theme),
1399
- themeMedias = _this$getParsedStoryT.medias,
1400
- newTheme = _objectWithoutProperties(_this$getParsedStoryT, _excluded2$2);
1401
- return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
1402
- theme: newTheme,
1403
- components: newComponents,
1404
- medias: _objectSpread(_objectSpread({}, themeMedias), medias)
1405
- }) : story;
1406
- }
1407
- return medias !== null ? _objectSpread(_objectSpread({}, story), {}, {
1408
- components: newComponents,
1409
- medias: medias
1410
- }) : story;
1411
- }
1412
-
1413
- // Convert path to medias object
1414
- }, {
1415
- key: "fromPath",
1416
- value: function fromPath(story) {
1417
- var defaultMedias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1418
- if (story === null) {
1419
- return story;
1420
- }
1421
- var _ref4 = story || {},
1422
- _ref4$theme = _ref4.theme,
1423
- theme = _ref4$theme === void 0 ? null : _ref4$theme,
1424
- _ref4$components = _ref4.components,
1425
- components = _ref4$components === void 0 ? [] : _ref4$components,
1426
- _ref4$medias = _ref4.medias,
1427
- medias = _ref4$medias === void 0 ? defaultMedias : _ref4$medias;
1428
- if (medias === null && theme === null) {
1429
- return story;
1430
- }
1431
-
1432
- // Replace path with medias objects
1433
- // const newComponents =
1434
- // medias !== null
1435
- // ? components.map((screen) => {
1436
- // const { type } = screen;
1437
- // const fieldsPattern = this.getFieldsPatternByScreen(type);
1438
- // return MediasParser.replacePathsWithMedias(screen, medias, fieldsPattern);
1439
- // })
1440
- // : components;
1441
-
1442
- // Faster parsing with data only
1443
- var componentsPattern = MediasParser.getMediaPatternsFromData(components);
1444
- var newComponents = medias !== null && componentsPattern.length > 0 ? MediasParser.replacePathsWithMedias(components, medias, componentsPattern) : components;
1445
-
1446
- // Replace path with medias object in theme
1447
- if (theme !== null) {
1448
- var newTheme = this.fromPath(theme, medias);
1449
- return newTheme !== theme || newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
1450
- theme: newTheme,
1451
- components: newComponents
1452
- }) : story;
1453
- }
1454
- return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
1455
- components: newComponents
1456
- }) : story;
1457
- }
1458
- }, {
1459
- key: "getFieldsPattern",
1460
- value: function getFieldsPattern(fields) {
1461
- var _this2 = this;
1462
- var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1463
- return (fields || []).reduce(function (patterns, field) {
1464
- var _field$name = field.name,
1465
- name = _field$name === void 0 ? null : _field$name,
1466
- _field$type = field.type,
1467
- type = _field$type === void 0 ? null : _field$type;
1468
- var path = [namePrefix, name].filter(function (it) {
1469
- return it !== null && it !== '';
1470
- }).join('\\.');
1471
- var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
1472
-
1473
- // also check settings fields
1474
- var _fieldDefinition$fiel = fieldDefinition.fields,
1475
- subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
1476
- _fieldDefinition$item = fieldDefinition.itemsField,
1477
- itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
1478
- _fieldDefinition$sett = fieldDefinition.settings,
1479
- settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
1480
- return [].concat(_toConsumableArray(patterns), _toConsumableArray(MediasParser.fieldIsMedia(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(MediasParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp("^".concat(path, "\\.media$")), new RegExp("^".concat(path, "\\.variants\\.[0-9]+\\.media$"))] : []), _toConsumableArray(_this2.getFieldsPattern(subFields, path)), _toConsumableArray(_this2.getFieldsPattern(settings, path)), _toConsumableArray(itemsField !== null ? _this2.getFieldsPattern([itemsField], "".concat(path, "\\.[0-9]+")) : []));
1481
- }, []);
1482
- }
1483
- }], [{
1484
- key: "fieldIsMedia",
1485
- value: function fieldIsMedia(_ref5) {
1486
- var _ref5$media = _ref5.media,
1487
- media = _ref5$media === void 0 ? false : _ref5$media;
1488
- return media;
1489
- }
1490
- }, {
1491
- key: "fieldIsFontFamily",
1492
- value: function fieldIsFontFamily(_ref6) {
1493
- var _ref6$id = _ref6.id,
1494
- id = _ref6$id === void 0 ? null : _ref6$id;
1495
- return id === 'font-family';
1496
- }
1497
- }, {
1498
- key: "replacePathsWithMedias",
1499
- value: function replacePathsWithMedias(data, medias, patterns) {
1500
- var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1501
- var dataIsArray = isArray(data);
1502
- return MediasParser.keys(data).reduce(function (newData, key) {
1503
- var path = [keyPrefix, key].filter(function (it) {
1504
- return it !== null;
1505
- }).join('.');
1506
- var patternMatch = patterns.reduce(function (found, pattern) {
1507
- return found || pattern.test(path);
1508
- }, false);
1509
- var value = data[key];
1510
- var newValue;
1511
- if (patternMatch) {
1512
- newValue = isObject(value) ? value : medias[value] || value;
1513
- } else {
1514
- newValue = isObject(value) || isArray(value) ? MediasParser.replacePathsWithMedias(value, medias, patterns, path) : value;
1515
- }
1516
- return dataIsArray ? [].concat(_toConsumableArray(newData), [newValue]) : _objectSpread(_objectSpread({}, newData), {}, _defineProperty({}, key, newValue));
1517
- }, dataIsArray ? [] : {});
1518
- }
1519
- }, {
1520
- key: "getMediaPath",
1521
- value: function getMediaPath(_ref7) {
1522
- var _ref7$id = _ref7.id,
1523
- id = _ref7$id === void 0 ? null : _ref7$id;
1524
- return id !== null ? "media://".concat(id) : null;
1525
- }
1526
- }, {
1527
- key: "replaceMediasWithPaths",
1528
- value: function replaceMediasWithPaths(data, patterns) {
1529
- var medias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1530
- var keyPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1531
- var dataIsArray = isArray(data);
1532
- var dataKeys = MediasParser.keys(data);
1533
- return dataKeys.reduce(function (_ref8, key) {
1534
- var currentData = _ref8.data,
1535
- currentMedias = _ref8.medias;
1536
- var path = [keyPrefix, key].filter(function (it) {
1537
- return it !== null;
1538
- }).join('.');
1539
- var patternMatch = patterns.reduce(function (found, pattern) {
1540
- return found || pattern.test(path);
1541
- }, false);
1542
- var value = data[key];
1543
- var newValue;
1544
- var media = null;
1545
- var subMedias = null;
1546
- if (patternMatch && isObject(value)) {
1547
- var mediaPath = MediasParser.getMediaPath(value);
1548
- newValue = mediaPath !== null ? mediaPath : value;
1549
- media = mediaPath !== null ? value : null;
1550
- } else if (isObject(value) || isArray(value)) {
1551
- var subReturn = MediasParser.replaceMediasWithPaths(value, patterns, medias, path);
1552
- newValue = subReturn.data;
1553
- subMedias = subReturn.medias;
1554
- } else {
1555
- newValue = value;
1556
- }
1557
- return {
1558
- data: dataIsArray ? [].concat(_toConsumableArray(currentData || []), [newValue]) : _objectSpread(_objectSpread({}, currentData), {}, _defineProperty({}, key, newValue)),
1559
- medias: media !== null ? _objectSpread(_objectSpread(_objectSpread({}, currentMedias), subMedias), {}, _defineProperty({}, newValue, media)) : _objectSpread(_objectSpread({}, currentMedias), subMedias)
1560
- };
1561
- }, {
1562
- data: dataKeys.length === 0 ? data : null,
1563
- medias: medias
1564
- });
1565
- }
1566
- }, {
1567
- key: "getMediaPatternsFromData",
1568
- value: function getMediaPatternsFromData(obj) {
1569
- var dotObj = MediasParser.dot(obj);
1570
- return Object.keys(dotObj).filter(function (key) {
1571
- return isString(dotObj[key]) && dotObj[key].match(/^media:\/\/([^/]+)$/) !== null;
1572
- }).map(function (it) {
1573
- return new RegExp("^".concat(it, "$"));
1574
- });
1575
- }
1576
- }, {
1577
- key: "dot",
1578
- value: function dot(obj) {
1579
- return MediasParser.keys(obj).reduce(function (acc, key) {
1580
- if (_typeof(obj[key]) !== 'object' || !obj[key]) {
1581
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, obj[key]));
1582
- }
1583
- var flattenedChild = MediasParser.dot(obj[key]);
1584
- return _objectSpread(_objectSpread({}, acc), MediasParser.keys(flattenedChild).reduce(function (childAcc, childKey) {
1585
- return _objectSpread(_objectSpread({}, childAcc), {}, _defineProperty({}, "".concat(key, ".").concat(childKey), flattenedChild[childKey]));
1586
- }, {}));
1587
- }, {});
1588
- }
1589
- }, {
1590
- key: "keys",
1591
- value: function keys(obj) {
1592
- return isArray(obj) ? _toConsumableArray(obj.keys()) : Object.keys(obj);
1593
- }
1594
- }]);
1595
- }();
1596
- var MediasParser$1 = MediasParser;
1597
-
1598
- var ScreensManager = /*#__PURE__*/function (_DefinitionsManager) {
1599
- function ScreensManager() {
1600
- var _this;
1601
- var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1602
- _classCallCheck(this, ScreensManager);
1603
- _this = _callSuper(this, ScreensManager, [definitions]);
1604
- _this.fieldsPattern = null;
1605
- return _this;
1606
- }
1607
- _inherits(ScreensManager, _DefinitionsManager);
1608
- return _createClass(ScreensManager, [{
1609
- key: "getFields",
1610
- value: function getFields(id) {
1611
- var _ref = this.getDefinition(id) || {},
1612
- _ref$fields = _ref.fields,
1613
- fields = _ref$fields === void 0 ? null : _ref$fields;
1614
- return fields;
1615
- }
1616
- }, {
1617
- key: "getLayouts",
1618
- value: function getLayouts(id) {
1619
- var _ref2 = this.getDefinition(id) || {},
1620
- _ref2$layouts = _ref2.layouts,
1621
- layouts = _ref2$layouts === void 0 ? null : _ref2$layouts;
1622
- return layouts;
1623
- }
1624
- }, {
1625
- key: "getFieldsPattern",
1626
- value: function getFieldsPattern() {
1627
- return this.fieldsPattern;
1628
- }
1629
- }, {
1630
- key: "setFieldsPattern",
1631
- value: function setFieldsPattern(fieldsPattern) {
1632
- this.fieldsPattern = fieldsPattern;
1633
- }
1634
- }, {
1635
- key: "filter",
1636
- value: function filter(_filter) {
1637
- return new ScreensManager(this.definitions.filter(_filter));
1638
- // this.definitions = this.definitions.filter(filter);
1639
- // return this;
1640
- }
1641
- }, {
1642
- key: "merge",
1643
- value: function merge(manager) {
1644
- var newFieldsPattern = manager.getFieldsPattern();
1645
- if (newFieldsPattern !== null && this.fieldsPattern === null) {
1646
- this.fieldsPattern = newFieldsPattern;
1647
- }
1648
- return this.addDefinitions(manager.getDefinitions());
1649
- }
1650
- }]);
1651
- }(DefinitionsManager$1);
1652
- var ScreensManager$1 = ScreensManager;
1653
-
1654
- var _excluded$3 = ["fonts"];
1655
- var FontsParser = /*#__PURE__*/function () {
1656
- function FontsParser(_ref) {
1657
- var fieldsManager = _ref.fieldsManager,
1658
- screensManager = _ref.screensManager,
1659
- _ref$fieldsPattern = _ref.fieldsPattern,
1660
- fieldsPattern = _ref$fieldsPattern === void 0 ? {} : _ref$fieldsPattern;
1661
- _classCallCheck(this, FontsParser);
1662
- this.fieldsManager = fieldsManager;
1663
- this.screensManager = screensManager;
1664
- this.fieldsPatternCache = fieldsPattern || {};
1665
- }
1666
- return _createClass(FontsParser, [{
1667
- key: "getFieldsPatternByScreen",
1668
- value: function getFieldsPatternByScreen(type) {
1669
- if (typeof this.fieldsPatternCache[type] === 'undefined') {
1670
- var fields = getScreenFieldsWithStates(this.screensManager.getDefinition(type) || {});
1671
- this.fieldsPatternCache[type] = this.getFieldsPattern(fields || []);
1672
- }
1673
- return this.fieldsPatternCache[type];
1674
- }
1675
-
1676
- // Extract fonts
1677
- }, {
1678
- key: "parse",
1679
- value: function parse(story) {
1680
- var _this = this;
1681
- if (story === null) {
1682
- return story;
1683
- }
1684
-
1685
- // Extract fonts from screen
1686
- var _ref2 = story || {},
1687
- _ref2$theme = _ref2.theme,
1688
- theme = _ref2$theme === void 0 ? null : _ref2$theme,
1689
- _ref2$components = _ref2.components,
1690
- components = _ref2$components === void 0 ? [] : _ref2$components;
1691
- var fonts = uniq(components.reduce(function (currentFonts, screen) {
1692
- var type = screen.type;
1693
- var fieldsPattern = _this.getFieldsPatternByScreen(type);
1694
- var newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
1695
- return newFonts.length > 0 ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(newFonts)) : currentFonts;
1696
- }, []), 'name');
1697
-
1698
- // Extract fonts from theme
1699
- if (theme !== null) {
1700
- var _this$parse = this.parse(theme),
1701
- _this$parse$fonts = _this$parse.fonts,
1702
- themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
1703
- newTheme = _objectWithoutProperties(_this$parse, _excluded$3);
1704
- return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
1705
- theme: newTheme,
1706
- fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
1707
- }) : story;
1708
- }
1709
- return fonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
1710
- fonts: fonts
1711
- }) : story;
1712
- }
1713
- }, {
1714
- key: "getFieldsPattern",
1715
- value: function getFieldsPattern(fields) {
1716
- var _this2 = this;
1717
- var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1718
- return (fields || []).reduce(function (patterns, field) {
1719
- var _field$name = field.name,
1720
- name = _field$name === void 0 ? null : _field$name,
1721
- _field$type = field.type,
1722
- type = _field$type === void 0 ? null : _field$type;
1723
- var path = [namePrefix, name].filter(function (it) {
1724
- return it !== null && it !== '';
1725
- }).join('\\.');
1726
- var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
1727
-
1728
- // also check settings fields
1729
- var _fieldDefinition$fiel = fieldDefinition.fields,
1730
- subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
1731
- _fieldDefinition$item = fieldDefinition.itemsField,
1732
- itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
1733
- _fieldDefinition$sett = fieldDefinition.settings,
1734
- settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
1735
- 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]+")) : []));
1736
- }, []);
1737
- }
1738
- }], [{
1739
- key: "fieldIsFontFamily",
1740
- value: function fieldIsFontFamily(_ref3) {
1741
- var _ref3$id = _ref3.id,
1742
- id = _ref3$id === void 0 ? null : _ref3$id;
1743
- return id === 'font-family';
1744
- }
1745
- }, {
1746
- key: "valueIsFont",
1747
- value: function valueIsFont(_ref4) {
1748
- var _ref4$type = _ref4.type,
1749
- type = _ref4$type === void 0 ? null : _ref4$type;
1750
- return type === 'custom' || type === 'google';
1751
- }
1752
- }, {
1753
- key: "extractFontsWithPaths",
1754
- value: function extractFontsWithPaths(data, patterns) {
1755
- var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1756
- var dataIsArray = isArray(data);
1757
- var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
1758
- return keys.reduce(function (currentFonts, key) {
1759
- var path = [keyPrefix, key].filter(function (it) {
1760
- return it !== null;
1761
- }).join('.');
1762
- var patternMatch = patterns.reduce(function (found, pattern) {
1763
- return found || pattern.test(path);
1764
- }, false);
1765
- var value = data[key];
1766
- var font = null;
1767
- var subFonts = null;
1768
- if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
1769
- font = value;
1770
- } else if (isObject(value) || isArray(value)) {
1771
- subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
1772
- }
1773
- return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
1774
- }, []);
1775
- }
1776
- }]);
1777
- }();
1778
- var FontsParser$1 = FontsParser;
1779
-
1780
- var _excluded$2 = ["components"],
1781
- _excluded2$1 = ["shareIncentive", "callToAction"];
1782
- var MigrationsParser = /*#__PURE__*/function () {
1783
- function MigrationsParser(_ref) {
1784
- var screensManager = _ref.screensManager;
1785
- _classCallCheck(this, MigrationsParser);
1786
- this.screensManager = screensManager;
1787
- }
1788
-
1789
- // eslint-disable-next-line class-methods-use-this
1790
- return _createClass(MigrationsParser, [{
1791
- key: "parse",
1792
- value: function parse(story) {
1793
- if (story === null) {
1794
- return story;
1795
- }
1796
- var _ref2 = story || {},
1797
- _ref2$components = _ref2.components,
1798
- components = _ref2$components === void 0 ? [] : _ref2$components,
1799
- restStory = _objectWithoutProperties(_ref2, _excluded$2);
1800
- var finalComponents = components.reduce(function (currentComponents, screen) {
1801
- var _ref3 = screen || {},
1802
- _ref3$shareIncentive = _ref3.shareIncentive,
1803
- shareIncentive = _ref3$shareIncentive === void 0 ? null : _ref3$shareIncentive,
1804
- _ref3$callToAction = _ref3.callToAction,
1805
- callToAction = _ref3$callToAction === void 0 ? null : _ref3$callToAction,
1806
- restScreen = _objectWithoutProperties(_ref3, _excluded2$1);
1807
- if (shareIncentive === null && callToAction === null) {
1808
- return [].concat(_toConsumableArray(currentComponents), [restScreen]);
1809
- }
1810
- var _ref4 = screen || {},
1811
- _ref4$header = _ref4.header,
1812
- header = _ref4$header === void 0 ? null : _ref4$header,
1813
- _ref4$footer = _ref4.footer,
1814
- footer = _ref4$footer === void 0 ? null : _ref4$footer;
1815
-
1816
- // Carful for recursivity here cause same key name
1817
- var newHeader = shareIncentive !== null ? _objectSpread(_objectSpread({}, shareIncentive !== null ? {
1818
- shareIncentive: shareIncentive
1819
- } : null), header !== null ? {
1820
- header: header
1821
- } : null) : header;
1822
- var newFooter = callToAction !== null ? _objectSpread(_objectSpread({}, callToAction !== null ? {
1823
- callToAction: callToAction
1824
- } : null), footer !== null ? {
1825
- footer: footer
1826
- } : null) : footer;
1827
- var newScreen = _objectSpread(_objectSpread(_objectSpread({}, restScreen), newHeader !== null ? {
1828
- header: newHeader
1829
- } : null), newFooter !== null ? {
1830
- footer: newFooter
1831
- } : null);
1832
- return [].concat(_toConsumableArray(currentComponents), [newScreen]);
1833
- }, []);
1834
- return _objectSpread(_objectSpread({}, restStory), {}, {
1835
- components: finalComponents
1836
- });
1837
- }
1838
- }]);
1839
- }();
1840
-
1841
- var _excluded$1 = ["textStyle", "color", "boxStyle"];
1842
- var ThemeParser = /*#__PURE__*/function () {
1843
- function ThemeParser(_ref) {
1844
- var screensManager = _ref.screensManager;
1845
- _classCallCheck(this, ThemeParser);
1846
- this.screensManager = screensManager;
1847
- this.definitionCache = {};
1848
- this.fieldsCache = {};
1849
- }
1850
- return _createClass(ThemeParser, [{
1851
- key: "getDefinitionByScreen",
1852
- value: function getDefinitionByScreen(type, themeComponents) {
1853
- if (typeof this.definitionCache[type] === 'undefined') {
1854
- var definition = this.screensManager.getDefinition(type) || {};
1855
- var themeScreen = themeComponents.find(function (it) {
1856
- return it.type === type;
1857
- }) || null;
1858
- this.definitionCache[type] = {
1859
- definition: definition,
1860
- themeScreen: themeScreen
1861
- };
1862
- }
1863
- return this.definitionCache[type];
1864
- }
1865
- }, {
1866
- key: "getFieldsForDefinition",
1867
- value: function getFieldsForDefinition(definition) {
1868
- var _ref2 = definition || {},
1869
- _ref2$id = _ref2.id,
1870
- definitionId = _ref2$id === void 0 ? null : _ref2$id,
1871
- _ref2$fields = _ref2.fields,
1872
- fields = _ref2$fields === void 0 ? [] : _ref2$fields,
1873
- _ref2$states = _ref2.states,
1874
- states = _ref2$states === void 0 ? [] : _ref2$states;
1875
- if (typeof this.fieldsCache[definitionId] === 'undefined') {
1876
- if (states === null || states.length === 0) {
1877
- this.fieldsCache[definitionId] = {
1878
- fields: fields
1879
- };
1880
- } else {
1881
- // TODO: test this
1882
- var finalFields = fields;
1883
- var repetableStates = [];
1884
- if (states !== null && states.length > 0) {
1885
- var nonRepetableStates = states.filter(function (_ref3) {
1886
- var _ref3$repeatable = _ref3.repeatable,
1887
- repeatable = _ref3$repeatable === void 0 ? false : _ref3$repeatable;
1888
- return repeatable === false;
1889
- });
1890
- repetableStates = states.filter(function (_ref4) {
1891
- var _ref4$repeatable = _ref4.repeatable,
1892
- repeatable = _ref4$repeatable === void 0 ? false : _ref4$repeatable;
1893
- return repeatable === true;
1894
- });
1895
- finalFields = nonRepetableStates.reduce(function (acc, it) {
1896
- var _ref5 = it || {},
1897
- _ref5$fields = _ref5.fields,
1898
- itemFields = _ref5$fields === void 0 ? [] : _ref5$fields;
1899
- if (itemFields !== null && itemFields.length > 0) {
1900
- return acc.concat(itemFields);
1901
- }
1902
- return acc;
1903
- }, finalFields);
1904
- }
1905
- this.fieldsCache[definitionId] = {
1906
- fields: finalFields,
1907
- repetableStates: repetableStates
1908
- };
1909
- }
1910
- }
1911
- return this.fieldsCache[definitionId];
1912
- }
1913
- }, {
1914
- key: "parse",
1915
- value: function parse(story) {
1916
- var _this = this;
1917
- if (story === null) {
1918
- return story;
1919
- }
1920
- var _ref6 = story || {},
1921
- _ref6$theme = _ref6.theme,
1922
- theme = _ref6$theme === void 0 ? null : _ref6$theme,
1923
- _ref6$components = _ref6.components,
1924
- components = _ref6$components === void 0 ? null : _ref6$components;
1925
- if (theme === null || components === null) {
1926
- return story;
1927
- }
1928
- var _theme$components = theme.components,
1929
- themeComponents = _theme$components === void 0 ? [] : _theme$components,
1930
- _theme$background = theme.background,
1931
- themeBackground = _theme$background === void 0 ? null : _theme$background,
1932
- _theme$colors = theme.colors,
1933
- themeColors = _theme$colors === void 0 ? {} : _theme$colors,
1934
- _theme$textStyles = theme.textStyles,
1935
- themeTextStyles = _theme$textStyles === void 0 ? null : _theme$textStyles,
1936
- _theme$boxStyles = theme.boxStyles,
1937
- themeBoxStyles = _theme$boxStyles === void 0 ? null : _theme$boxStyles;
1938
-
1939
- // Speed test
1940
- // const newComponents = [...components];
1941
- // for (let index = 0; index < components.length; index += 1) {
1942
- // const screen = components[index] || {};
1943
- // const { type } = screen;
1944
- // const { definition, themeScreen } = this.getDefinitionByScreen(type, themeComponents);
1945
- // const newScreen = this.parseScreen(
1946
- // definition,
1947
- // screen,
1948
- // themeScreen,
1949
- // themeBackground,
1950
- // themeColors,
1951
- // themeTextStyles,
1952
- // themeBoxStyles,
1953
- // );
1954
-
1955
- // if (newScreen !== screen || themeScreen !== null) {
1956
- // newComponents[index] = {
1957
- // ...themeScreen,
1958
- // ...newScreen,
1959
- // };
1960
- // }
1961
- // }
1962
- // story.components = newComponents;
1963
- // return story;
1964
-
1965
- var newComponents = components.reduce(function (currentComponents, screen, index) {
1966
- var type = screen.type;
1967
- var _this$getDefinitionBy = _this.getDefinitionByScreen(type, themeComponents),
1968
- definition = _this$getDefinitionBy.definition,
1969
- themeScreen = _this$getDefinitionBy.themeScreen;
1970
- var newScreen = _this.parseScreen(definition, screen, themeScreen, themeBackground, themeColors, themeTextStyles, themeBoxStyles);
1971
-
1972
- // Only switch screen if it has changed
1973
- return newScreen !== screen || themeScreen !== null ? [].concat(_toConsumableArray(currentComponents.slice(0, index)), [_objectSpread(_objectSpread({}, themeScreen), newScreen)], _toConsumableArray(currentComponents.slice(index + 1))) : currentComponents;
1974
- }, components);
1975
- return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
1976
- components: newComponents
1977
- }) : story;
1978
- }
1979
- }, {
1980
- key: "parseScreen",
1981
- value: function parseScreen(definition, value, themeValue, themeBackground, themeColors, themeTextStyles, themeBoxStyles) {
1982
- var _this2 = this;
1983
- var _this$getFieldsForDef = this.getFieldsForDefinition(definition),
1984
- _this$getFieldsForDef2 = _this$getFieldsForDef.fields,
1985
- fields = _this$getFieldsForDef2 === void 0 ? null : _this$getFieldsForDef2,
1986
- _this$getFieldsForDef3 = _this$getFieldsForDef.repetableStates,
1987
- repetableStates = _this$getFieldsForDef3 === void 0 ? null : _this$getFieldsForDef3;
1988
- var newThemeValue = themeValue === null && themeBackground !== null ? {} : themeValue;
1989
- if (themeBackground !== null && typeof newThemeValue.background !== 'undefined') {
1990
- newThemeValue.background = _objectSpread(_objectSpread({}, themeBackground), newThemeValue.background);
1991
- } else if (themeBackground !== null) {
1992
- newThemeValue.background = themeBackground;
1993
- }
1994
- var newScreenValue = Object.keys(value).reduce(function (currentValue, key) {
1995
- var repetableState = null;
1996
- if (repetableStates !== null && repetableStates.length > 0) {
1997
- repetableState = repetableStates.find(function (_ref7) {
1998
- var _ref7$id = _ref7.id,
1999
- stateId = _ref7$id === void 0 ? null : _ref7$id;
2000
- return stateId !== null && stateId === key;
2001
- }) || null;
2002
- }
2003
- var fieldDefinition = (fields || null).find(function (it) {
2004
- return it.name === key;
2005
- }) || repetableState || {};
2006
- var fieldValue = value[key];
2007
- var fieldThemeValue = newThemeValue !== null ? newThemeValue[key] || null : null;
2008
-
2009
- // Try for early return
2010
- var _ref8 = fieldDefinition || {},
2011
- _ref8$theme = _ref8.theme,
2012
- theme = _ref8$theme === void 0 ? null : _ref8$theme;
2013
- if ((theme === null || !isObject(theme)) && fields === null) {
2014
- return _objectSpread(_objectSpread({}, currentValue), {}, _defineProperty({}, key, fieldValue));
2015
- }
2016
-
2017
- // console.log('start', key, fieldValue);
2018
- var newFieldValue = _this2.parseField(fieldValue, fieldDefinition, fieldThemeValue, themeColors, themeTextStyles, themeBoxStyles);
2019
- // console.log('result', newFieldValue);
2020
-
2021
- // const newFieldValue = fieldValue;
2022
-
2023
- // Only switch field if it has changed
2024
- return newFieldValue !== fieldValue ? _objectSpread(_objectSpread({}, currentValue), {}, _defineProperty({}, key, newFieldValue)) : currentValue;
2025
- }, value);
2026
- return newThemeValue !== null ? _objectSpread(_objectSpread({}, newThemeValue), newScreenValue) : newScreenValue;
2027
- }
2028
-
2029
- // eslint-disable-next-line class-methods-use-this
2030
- }, {
2031
- key: "parseField",
2032
- value: function parseField(value, fieldDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
2033
- var _this3 = this;
2034
- var _fieldDefinition$them = fieldDefinition.theme,
2035
- fieldTheme = _fieldDefinition$them === void 0 ? null : _fieldDefinition$them,
2036
- _fieldDefinition$fiel = fieldDefinition.fields,
2037
- definitionFields = _fieldDefinition$fiel === void 0 ? null : _fieldDefinition$fiel;
2038
-
2039
- // There are sub-fields in this definition
2040
- if (definitionFields !== null && value !== null) {
2041
- return isArray(value) ? value.map(function (innerFieldValue) {
2042
- if (innerFieldValue === null) {
2043
- return innerFieldValue;
2044
- }
2045
- return _this3.parseInnerFields(innerFieldValue, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
2046
- }) : this.parseInnerFields(value, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
2047
- }
2048
-
2049
- // Early return
2050
- if (fieldTheme === null || !isObject(fieldTheme)) {
2051
- return value;
2052
- }
2053
-
2054
- // @TODO very slooow...
2055
- if (isArray(value)) {
2056
- var newFieldValue = value.map(function (innerField) {
2057
- return innerField !== null ? Object.keys(innerField).reduce(function (newInnerField, innerFieldName) {
2058
- // Early return
2059
- if (!isObject(innerField[innerFieldName])) {
2060
- return newInnerField;
2061
- }
2062
- var _ref9 = fieldTheme[innerFieldName] || {},
2063
- _ref9$textStyle = _ref9.textStyle,
2064
- innerFieldTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle,
2065
- _ref9$color = _ref9.color,
2066
- innerFieldColor = _ref9$color === void 0 ? null : _ref9$color,
2067
- _ref9$boxStyle = _ref9.boxStyle,
2068
- innerFieldBoxStyle = _ref9$boxStyle === void 0 ? null : _ref9$boxStyle;
2069
-
2070
- // Early return, no theme
2071
- if (innerFieldTextStyle === null && innerFieldColor === null && innerFieldBoxStyle === null) {
2072
- return newInnerField;
2073
- }
2074
-
2075
- // Color
2076
- var colorValue = innerFieldColor !== null ? {
2077
- color: innerFieldColor !== null && themeColors !== null ? themeColors[innerFieldColor] || null : null
2078
- } : null;
2079
-
2080
- // Text style
2081
- var textStyleValue = innerFieldTextStyle !== null ? {
2082
- textStyle: _objectSpread(_objectSpread({}, innerFieldTextStyle !== null && themeTextStyles !== null ? themeTextStyles[innerFieldTextStyle] || null : null), innerField[innerFieldName].textStyle || null)
2083
- } : null;
2084
- var boxStyleValue = innerFieldBoxStyle !== null ? {
2085
- boxStyle: _objectSpread(_objectSpread({}, innerFieldBoxStyle !== null && themeBoxStyles !== null ? themeBoxStyles[innerFieldBoxStyle] || null : null), innerField[innerFieldName].boxStyle || null)
2086
- } : null;
2087
- if (colorValue === null && textStyleValue === null && boxStyleValue === null) {
2088
- return newInnerField;
2089
- }
2090
- return _objectSpread(_objectSpread({}, newInnerField), {}, _defineProperty({}, innerFieldName, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colorValue), innerField[innerFieldName]), textStyleValue), boxStyleValue)));
2091
- }, innerField) : innerField;
2092
- });
2093
- return newFieldValue;
2094
- }
2095
- if (isObject(value)) {
2096
- return this.parseValue(value, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
2097
- }
2098
- return value;
2099
- }
2100
- }, {
2101
- key: "parseInnerFields",
2102
- value: function parseInnerFields(value, fieldsOrDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
2103
- var _this4 = this;
2104
- var newValue = Object.keys(value).reduce(function (finalValue, innerFieldName) {
2105
- var innerDefinition = isArray(fieldsOrDefinition) ? fieldsOrDefinition.find(function (it) {
2106
- return it.name === innerFieldName;
2107
- }) || null : fieldsOrDefinition;
2108
- var _ref10 = innerDefinition || {},
2109
- _ref10$theme = _ref10.theme,
2110
- idfTheme = _ref10$theme === void 0 ? null : _ref10$theme;
2111
- var innerValue = value[innerFieldName];
2112
-
2113
- // For items fields
2114
- if (innerValue !== null && innerDefinition !== null && isArray(innerValue)) {
2115
- // eslint-disable-next-line no-param-reassign
2116
- finalValue[innerFieldName] = _this4.parseField(innerValue, innerDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles);
2117
- return finalValue;
2118
- }
2119
-
2120
- // For fields with fields
2121
- if (innerValue !== null && idfTheme !== null && isObject(idfTheme) && isObject(innerValue)) {
2122
- // eslint-disable-next-line no-param-reassign
2123
- finalValue[innerFieldName] = _this4.parseValue(innerValue, idfTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
2124
- return finalValue;
2125
- }
2126
-
2127
- // eslint-disable-next-line no-param-reassign
2128
- finalValue[innerFieldName] = value[innerFieldName];
2129
- return finalValue;
2130
- }, {});
2131
- return newValue;
2132
- }
2133
-
2134
- // eslint-disable-next-line class-methods-use-this
2135
- }, {
2136
- key: "parseValue",
2137
- value: function parseValue(initialValue, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
2138
- var _this5 = this;
2139
- if (isObject(initialValue) || isObject(fieldTheme)) {
2140
- var value = initialValue || null;
2141
- var _ref11 = fieldTheme || {},
2142
- _ref11$textStyle = _ref11.textStyle,
2143
- fieldTextStyleName = _ref11$textStyle === void 0 ? null : _ref11$textStyle,
2144
- _ref11$color = _ref11.color,
2145
- fieldColorName = _ref11$color === void 0 ? null : _ref11$color,
2146
- _ref11$boxStyle = _ref11.boxStyle,
2147
- fieldBoxStyleName = _ref11$boxStyle === void 0 ? null : _ref11$boxStyle,
2148
- otherProps = _objectWithoutProperties(_ref11, _excluded$1);
2149
- if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty(otherProps) && !isObject(fieldTheme)) {
2150
- return value;
2151
- }
2152
- var complexValue = null;
2153
- if (!isEmpty(otherProps)) {
2154
- complexValue = Object.keys(otherProps).reduce(function (newObject, key) {
2155
- var innerValue = value !== null ? value[key] || null : null;
2156
- var newValue = _this5.parseValue(innerValue, otherProps[key], themeValue, themeColors, themeTextStyles, themeBoxStyles);
2157
- return _objectSpread(_objectSpread({}, newObject), newValue !== null ? _defineProperty({}, key, newValue) : null);
2158
- }, {});
2159
- }
2160
- var _ref13 = value || {},
2161
- _ref13$textStyle = _ref13.textStyle,
2162
- valueTextStyle = _ref13$textStyle === void 0 ? null : _ref13$textStyle,
2163
- _ref13$boxStyle = _ref13.boxStyle,
2164
- valueBoxStyle = _ref13$boxStyle === void 0 ? null : _ref13$boxStyle;
2165
-
2166
- // Color
2167
- var fieldColor = fieldColorName !== null && themeColors !== null ? themeColors[fieldColorName] || null : null;
2168
- var colorValue = fieldColor !== null ? {
2169
- color: fieldColor
2170
- } : null;
2171
-
2172
- // Text style
2173
- var fieldTextStyle = fieldTextStyleName !== null && themeTextStyles !== null ? themeTextStyles[fieldTextStyleName] || null : null;
2174
- var fieldThemeComponentTextStyle = themeValue !== null ? themeValue.textStyle || null : null;
2175
- var textStyleValue = fieldTextStyle !== null || fieldThemeComponentTextStyle !== null ? {
2176
- textStyle: _objectSpread(_objectSpread(_objectSpread({}, fieldTextStyle), fieldThemeComponentTextStyle), valueTextStyle || null)
2177
- } : null;
2178
-
2179
- // Box style
2180
- var fieldBoxStyle = fieldBoxStyleName !== null && themeBoxStyles !== null ? themeBoxStyles[fieldBoxStyleName] || null : null;
2181
- var fieldThemeComponentBoxStyle = themeValue !== null ? themeValue.boxStyle || null : null;
2182
- var boxStyleValue = fieldBoxStyle !== null || fieldThemeComponentBoxStyle !== null ? {
2183
- boxStyle: _objectSpread(_objectSpread(_objectSpread({}, fieldBoxStyle), fieldThemeComponentBoxStyle), valueBoxStyle || null)
2184
- } : null;
2185
-
2186
- // Only change value if something is overrided
2187
- return colorValue !== null || themeValue !== null || textStyleValue !== null || boxStyleValue !== null || complexValue !== null ? _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colorValue), themeValue), value), boxStyleValue), textStyleValue), complexValue) : value;
2188
- }
2189
- return initialValue;
2190
- }
2191
- }]);
2192
- }();
2193
- var ThemeParser$1 = ThemeParser;
2194
-
2195
- var StoryParser = /*#__PURE__*/function () {
2196
- function StoryParser(_ref) {
2197
- var screensManager = _ref.screensManager,
2198
- fieldsManager = _ref.fieldsManager,
2199
- fieldsPattern = _ref.fieldsPattern;
2200
- _classCallCheck(this, StoryParser);
2201
- var _ref2 = fieldsPattern || {},
2202
- _ref2$medias = _ref2.medias,
2203
- mediasPattern = _ref2$medias === void 0 ? null : _ref2$medias,
2204
- _ref2$fonts = _ref2.fonts,
2205
- fontsPattern = _ref2$fonts === void 0 ? null : _ref2$fonts;
2206
- this.themeParser = new ThemeParser$1({
2207
- screensManager: screensManager
2208
- });
2209
- this.mediasParser = new MediasParser$1({
2210
- screensManager: screensManager,
2211
- fieldsManager: fieldsManager,
2212
- fieldsPattern: mediasPattern
2213
- });
2214
- this.fontsParser = new FontsParser$1({
2215
- screensManager: screensManager,
2216
- fieldsManager: fieldsManager,
2217
- fieldsPattern: fontsPattern
2218
- });
2219
- this.migrationsParser = new MigrationsParser({
2220
- screensManager: screensManager
2221
- });
2222
- }
2223
- return _createClass(StoryParser, [{
2224
- key: "parse",
2225
- value: function parse(story) {
2226
- var _this = this;
2227
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2228
- _ref3$withTheme = _ref3.withTheme,
2229
- withTheme = _ref3$withTheme === void 0 ? true : _ref3$withTheme,
2230
- _ref3$withMedias = _ref3.withMedias,
2231
- withMedias = _ref3$withMedias === void 0 ? true : _ref3$withMedias,
2232
- _ref3$withFonts = _ref3.withFonts,
2233
- withFonts = _ref3$withFonts === void 0 ? true : _ref3$withFonts,
2234
- _ref3$withMigrations = _ref3.withMigrations,
2235
- withMigrations = _ref3$withMigrations === void 0 ? true : _ref3$withMigrations;
2236
- if (story === null) {
2237
- return story;
2238
- }
2239
- var parsers = [[withMedias, function (newStory) {
2240
- return _this.mediasParser.fromPath(newStory);
2241
- }], [withTheme, function (newStory) {
2242
- return _this.themeParser.parse(newStory);
2243
- }], [withFonts, function (newStory) {
2244
- return _this.fontsParser.parse(newStory);
2245
- }], [withMigrations, function (newStory) {
2246
- return _this.migrationsParser.parse(newStory);
2247
- }]];
2248
- return parsers.reduce(function (parsedStory, _ref4) {
2249
- var _ref5 = _slicedToArray(_ref4, 2),
2250
- enabled = _ref5[0],
2251
- parse = _ref5[1];
2252
- return enabled ? parse(parsedStory) : parsedStory;
2253
- }, story);
2254
- }
2255
- }]);
2256
- }();
2257
- var StoryParser$1 = StoryParser;
2258
-
2259
- var _excluded = ["value"],
2260
- _excluded2 = ["value", "currentTime"];
2261
- var Tracking = /*#__PURE__*/function (_BaseTracking) {
2262
- function Tracking() {
2263
- var _this;
2264
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2265
- _classCallCheck(this, Tracking);
2266
- _this = _callSuper(this, Tracking, [opts]);
2267
- var _this$options$variabl = _this.options.variables,
2268
- variables = _this$options$variabl === void 0 ? null : _this$options$variabl;
2269
- _this.variables = null;
2270
- _this.screensViewed = [];
2271
- if (variables !== null) {
2272
- _this.setVariables(variables);
2273
- }
2274
- return _this;
2275
- }
2276
- _inherits(Tracking, _BaseTracking);
2277
- return _createClass(Tracking, [{
2278
- key: "setVariables",
2279
- value: function setVariables(variables) {
2280
- this.variables = variables;
2281
- if (variables !== null) {
2282
- this.push(variables);
2283
- }
2284
- }
2285
- }, {
2286
- key: "getVariables",
2287
- value: function getVariables() {
2288
- return this.variables;
2289
- }
2290
- }, {
2291
- key: "trackScreenView",
2292
- value: function trackScreenView(screen, screenIndex) {
2293
- var _ref = this.variables || {},
2294
- _ref$screensCount = _ref.screensCount,
2295
- screensCount = _ref$screensCount === void 0 ? null : _ref$screensCount;
2296
- var _ref2 = screen || {},
2297
- _ref2$id = _ref2.id,
2298
- screenId = _ref2$id === void 0 ? null : _ref2$id,
2299
- _ref2$type = _ref2.type,
2300
- screenType = _ref2$type === void 0 ? null : _ref2$type,
2301
- _ref2$metadata = _ref2.metadata,
2302
- metadata = _ref2$metadata === void 0 ? {} : _ref2$metadata;
2303
- var _ref3 = metadata || {},
2304
- screenTitle = _ref3.title;
2305
- if (this.screensViewed.indexOf(screenId || screenIndex) !== -1) {
2306
- this.screensViewed = [].concat(_toConsumableArray(this.screensViewed), [screenId || screenIndex]);
2307
- }
2308
- var data = {
2309
- event: 'screenView',
2310
- screenId: screenId,
2311
- screenType: screenType,
2312
- screenIndex: screenIndex,
2313
- screenTitle: screenTitle,
2314
- screenProgress: screensCount !== null && screenIndex !== null ? (screenIndex + 1) / screensCount : null,
2315
- screensViewed: this.screensViewed,
2316
- screensViewedProgress: screensCount !== null ? this.screensViewed.length / screensCount : null
2317
- };
2318
- this.push(data);
2319
- }
2320
- }, {
2321
- key: "trackEvent",
2322
- value: function trackEvent(category, action, label) {
2323
- var _ref4 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
2324
- _ref4$value = _ref4.value,
2325
- value = _ref4$value === void 0 ? null : _ref4$value,
2326
- opts = _objectWithoutProperties(_ref4, _excluded);
2327
- var data = _objectSpread(_objectSpread({}, opts), {}, {
2328
- event: 'eventInteraction',
2329
- eventCategory: category,
2330
- eventAction: action,
2331
- eventLabel: label,
2332
- eventValue: value
2333
- });
2334
- this.push(data);
2335
- }
2336
- }, {
2337
- key: "trackMedia",
2338
- value: function trackMedia(type, media, action) {
2339
- var _ref5 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
2340
- _ref5$value = _ref5.value,
2341
- value = _ref5$value === void 0 ? null : _ref5$value,
2342
- _ref5$currentTime = _ref5.currentTime,
2343
- optsCurrentTime = _ref5$currentTime === void 0 ? null : _ref5$currentTime,
2344
- opts = _objectWithoutProperties(_ref5, _excluded2);
2345
- var _ref6 = media || {},
2346
- _ref6$id = _ref6.id,
2347
- mediaId = _ref6$id === void 0 ? null : _ref6$id,
2348
- _ref6$name = _ref6.name,
2349
- name = _ref6$name === void 0 ? null : _ref6$name,
2350
- _ref6$duration = _ref6.duration,
2351
- rootDuration = _ref6$duration === void 0 ? null : _ref6$duration,
2352
- _ref6$currentTime = _ref6.currentTime,
2353
- currentTime = _ref6$currentTime === void 0 ? optsCurrentTime : _ref6$currentTime,
2354
- _ref6$metadata = _ref6.metadata,
2355
- metadata = _ref6$metadata === void 0 ? {} : _ref6$metadata;
2356
- var _ref7 = metadata || {},
2357
- _ref7$duration = _ref7.duration,
2358
- duration = _ref7$duration === void 0 ? rootDuration : _ref7$duration;
2359
- var label = name;
2360
- var data = _objectSpread(_objectSpread({}, opts), {}, {
2361
- event: 'eventInteraction',
2362
- eventCategory: type,
2363
- eventAction: action,
2364
- eventLabel: label,
2365
- eventValue: value,
2366
- mediaId: mediaId,
2367
- mediaCurrentTime: currentTime !== null ? Math.round(currentTime) : null,
2368
- mediaProgress: currentTime !== null && duration !== null && duration > 0 ? Math.round(currentTime / duration * 100) : null
2369
- });
2370
- this.push(data);
2371
- }
2372
- }]);
2373
- }(tracking.Tracking);
2374
- var Tracking$1 = Tracking;
2375
-
2376
- exports.ColorsParser = ColorsParser$1;
2377
- exports.ComponentsManager = ComponentsManager$1;
2378
- exports.DefinitionsManager = DefinitionsManager$1;
2379
- exports.EventsManager = EventsManager$1;
2380
- exports.FieldsManager = FieldsManager$1;
2381
- exports.FontsParser = FontsParser$1;
2382
- exports.MediasParser = MediasParser$1;
2383
- exports.PropTypes = PropTypes;
2384
- exports.ScreensManager = ScreensManager$1;
2385
- exports.StoryParser = StoryParser$1;
2386
- exports.ThemeParser = ThemeParser$1;
2387
- exports.Tracking = Tracking$1;