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