@micromag/core 0.4.71 → 0.4.77
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/assets/css/styles.css +0 -1
- package/assets/css/vendor.css +2 -3
- package/es/components.d.ts +99 -56
- package/es/components.js +5098 -2330
- package/es/contexts.d.ts +139 -67
- package/es/contexts.js +2182 -1239
- package/es/hooks.d.ts +28 -72
- package/es/hooks.js +2515 -2145
- package/es/index.d.ts +51 -8
- package/es/index.js +1284 -1525
- package/es/styles.css +0 -1
- package/es/utils.d.ts +155 -15
- package/es/utils.js +739 -888
- package/package.json +36 -40
- package/lib/components.js +0 -3404
- package/lib/contexts.js +0 -1762
- package/lib/hooks.js +0 -2532
- package/lib/index.js +0 -1713
- package/lib/styles.css +0 -35
- package/lib/utils.js +0 -1300
package/es/index.js
CHANGED
|
@@ -1,1102 +1,910 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
5
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
6
1
|
import isArray from 'lodash/isArray';
|
|
7
2
|
import isObject from 'lodash/isObject';
|
|
8
3
|
import uniqWith from 'lodash/uniqWith';
|
|
9
4
|
import sortBy from 'lodash/sortBy';
|
|
10
|
-
import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
11
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
12
5
|
import EventEmitter from 'wolfy87-eventemitter';
|
|
13
6
|
import { pascalCase } from 'change-case';
|
|
14
7
|
import uniqBy from 'lodash/uniqBy';
|
|
15
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
16
8
|
import uniq from 'lodash/uniq';
|
|
17
|
-
import _typeof from '@babel/runtime/helpers/typeof';
|
|
18
9
|
import isString from 'lodash/isString';
|
|
19
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
20
10
|
import isEmpty from 'lodash/isEmpty';
|
|
21
11
|
import { Tracking as Tracking$1 } from '@folklore/tracking';
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
};
|
|
31
|
-
var ColorsParser = /*#__PURE__*/function () {
|
|
32
|
-
function ColorsParser(_ref) {
|
|
33
|
-
var fieldsManager = _ref.fieldsManager,
|
|
34
|
-
screensManager = _ref.screensManager;
|
|
35
|
-
_classCallCheck(this, ColorsParser);
|
|
13
|
+
const sortedColors = colors => sortBy(colors, ['color', 'alpha']);
|
|
14
|
+
const uniqueColors = colors => uniqWith(colors, (colorA, colorB) => colorA.alpha === colorB.alpha && colorA.color === colorB.color);
|
|
15
|
+
class ColorsParser {
|
|
16
|
+
constructor({
|
|
17
|
+
fieldsManager,
|
|
18
|
+
screensManager
|
|
19
|
+
}) {
|
|
36
20
|
this.fieldsManager = fieldsManager;
|
|
37
21
|
this.screensManager = screensManager;
|
|
38
22
|
}
|
|
39
23
|
|
|
40
24
|
// Convert medias object to path
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return colors !== null ? sortedColors(uniqueColors(colors || [])) : [];
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "getColorFieldPatterns",
|
|
78
|
-
value: function getColorFieldPatterns(fields) {
|
|
79
|
-
var _this2 = this;
|
|
80
|
-
var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
81
|
-
return fields.reduce(function (patterns, field) {
|
|
82
|
-
var _field$name = field.name,
|
|
83
|
-
name = _field$name === void 0 ? null : _field$name,
|
|
84
|
-
_field$type = field.type,
|
|
85
|
-
type = _field$type === void 0 ? null : _field$type;
|
|
86
|
-
var path = [namePrefix, name].filter(function (it) {
|
|
87
|
-
return it !== null;
|
|
88
|
-
}).join('\\.');
|
|
89
|
-
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
|
|
90
|
-
// also check settings fields
|
|
91
|
-
var _fieldDefinition$fiel = fieldDefinition.fields,
|
|
92
|
-
subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
|
|
93
|
-
_fieldDefinition$item = fieldDefinition.itemsField,
|
|
94
|
-
itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
|
|
95
|
-
_fieldDefinition$sett = fieldDefinition.settings,
|
|
96
|
-
settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
|
|
97
|
-
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]+")) : []));
|
|
98
|
-
}, []);
|
|
99
|
-
}
|
|
100
|
-
}], [{
|
|
101
|
-
key: "fieldIsColor",
|
|
102
|
-
value: function fieldIsColor(_ref5) {
|
|
103
|
-
var _ref5$id = _ref5.id,
|
|
104
|
-
id = _ref5$id === void 0 ? null : _ref5$id;
|
|
105
|
-
return id === 'color';
|
|
25
|
+
parse(story) {
|
|
26
|
+
if (story === null) {
|
|
27
|
+
return story;
|
|
28
|
+
}
|
|
29
|
+
const {
|
|
30
|
+
theme = null,
|
|
31
|
+
components = []
|
|
32
|
+
} = story || {};
|
|
33
|
+
const {
|
|
34
|
+
colors
|
|
35
|
+
} = components.reduce(({
|
|
36
|
+
colors: currentColors = null
|
|
37
|
+
}, screen) => {
|
|
38
|
+
const {
|
|
39
|
+
type
|
|
40
|
+
} = screen;
|
|
41
|
+
const {
|
|
42
|
+
fields = []
|
|
43
|
+
} = this.screensManager.getDefinition(type) || {};
|
|
44
|
+
const fieldsPattern = this.getColorFieldPatterns(fields);
|
|
45
|
+
const {
|
|
46
|
+
colors: newColors
|
|
47
|
+
} = ColorsParser.getColorsFromPath(screen, fieldsPattern);
|
|
48
|
+
return {
|
|
49
|
+
colors: [...currentColors, ...newColors]
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
colors: []
|
|
53
|
+
});
|
|
54
|
+
if (theme !== null) {
|
|
55
|
+
const themeColors = this.parse(theme);
|
|
56
|
+
return colors !== null || themeColors !== null ? uniqueColors([...sortedColors(themeColors || []), ...sortedColors(colors || [])]) : [];
|
|
106
57
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
58
|
+
return colors !== null ? sortedColors(uniqueColors(colors || [])) : [];
|
|
59
|
+
}
|
|
60
|
+
getColorFieldPatterns(fields, namePrefix = null) {
|
|
61
|
+
return fields.reduce((patterns, field) => {
|
|
62
|
+
const {
|
|
63
|
+
name = null,
|
|
64
|
+
type = null
|
|
65
|
+
} = field;
|
|
66
|
+
const path = [namePrefix, name].filter(it => it !== null).join('\\.');
|
|
67
|
+
const fieldDefinition = {
|
|
68
|
+
...(type !== null ? this.fieldsManager.getDefinition(type) : null),
|
|
69
|
+
...field
|
|
70
|
+
};
|
|
71
|
+
// also check settings fields
|
|
72
|
+
const {
|
|
73
|
+
fields: subFields = [],
|
|
74
|
+
itemsField = null,
|
|
75
|
+
settings = []
|
|
76
|
+
} = fieldDefinition;
|
|
77
|
+
return [...patterns, ...(ColorsParser.fieldIsColor(fieldDefinition) ? [new RegExp(`^${path}$`)] : []), ...this.getColorFieldPatterns(subFields, path), ...this.getColorFieldPatterns(settings, path), ...(itemsField !== null ? this.getColorFieldPatterns([itemsField], `${path}\\.[0-9]+`) : [])];
|
|
78
|
+
}, []);
|
|
79
|
+
}
|
|
80
|
+
static fieldIsColor({
|
|
81
|
+
id = null
|
|
82
|
+
}) {
|
|
83
|
+
return id === 'color';
|
|
84
|
+
}
|
|
85
|
+
static getColorsFromPath(data, patterns, colors = null, keyPrefix = null) {
|
|
86
|
+
const dataIsArray = isArray(data);
|
|
87
|
+
const keys = dataIsArray ? [...data.keys()] : Object.keys(data);
|
|
88
|
+
return keys.reduce(({
|
|
89
|
+
data: currentData,
|
|
90
|
+
colors: currentColors = null
|
|
91
|
+
}, key) => {
|
|
92
|
+
const path = [keyPrefix, key].filter(it => it !== null).join('.');
|
|
93
|
+
const patternMatch = patterns.reduce((found, pattern) => found || pattern.test(path), false);
|
|
94
|
+
const value = data[key];
|
|
95
|
+
let color = null;
|
|
96
|
+
let newValue = null;
|
|
97
|
+
let subColors = null;
|
|
98
|
+
if (patternMatch && isObject(value)) {
|
|
99
|
+
if (value.color && value.color.length === 4) {
|
|
100
|
+
const innerColor = value.color.split('').map((hex, i) => i > 0 ? hex + hex : hex).join('').toUpperCase();
|
|
101
|
+
color = {
|
|
102
|
+
alpha: value.alpha || 1,
|
|
103
|
+
color: innerColor
|
|
104
|
+
};
|
|
105
|
+
} else if (value.color) {
|
|
106
|
+
color = {
|
|
107
|
+
alpha: value.alpha,
|
|
108
|
+
color: value.color.toUpperCase()
|
|
109
|
+
};
|
|
149
110
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
111
|
+
} else if (isObject(value) || isArray(value)) {
|
|
112
|
+
const subReturn = ColorsParser.getColorsFromPath(value, patterns, colors, path);
|
|
113
|
+
newValue = subReturn.data;
|
|
114
|
+
subColors = subReturn.colors;
|
|
115
|
+
} else {
|
|
116
|
+
newValue = value;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
data: dataIsArray ? [...(currentData || []), newValue] : {
|
|
120
|
+
...currentData,
|
|
121
|
+
[key]: newValue
|
|
122
|
+
},
|
|
123
|
+
colors: color !== null ? [...(currentColors || []), ...(subColors || []), color] : [...(currentColors || []), ...(subColors || [])]
|
|
124
|
+
};
|
|
125
|
+
}, {
|
|
126
|
+
data: keys.length === 0 ? data : null,
|
|
127
|
+
colors
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
161
131
|
|
|
162
|
-
|
|
163
|
-
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
164
|
-
var components = arguments.length > 1 ? arguments[1] : undefined;
|
|
165
|
-
var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
132
|
+
const getComponentFromName = (name = null, components, defaultComponent = null) => {
|
|
166
133
|
if (components === null || name === null) {
|
|
167
134
|
return defaultComponent;
|
|
168
135
|
}
|
|
169
|
-
|
|
136
|
+
const pascalName = pascalCase(name);
|
|
170
137
|
return components[pascalName] || components[name] || defaultComponent;
|
|
171
138
|
};
|
|
172
139
|
|
|
173
140
|
function getScreenFieldsWithStates(definition) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
states = _ref$states === void 0 ? null : _ref$states;
|
|
141
|
+
const {
|
|
142
|
+
fields: screenFields = null,
|
|
143
|
+
states = null
|
|
144
|
+
} = definition || {};
|
|
179
145
|
if (states === null) {
|
|
180
146
|
return screenFields;
|
|
181
147
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
id
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
_ref2$defaultValue = _ref2.defaultValue,
|
|
193
|
-
defaultValue = _ref2$defaultValue === void 0 ? null : _ref2$defaultValue;
|
|
194
|
-
return [].concat(_toConsumableArray(statesFields), _toConsumableArray(repeatable ? [{
|
|
148
|
+
const extraFields = states.reduce((statesFields, current) => {
|
|
149
|
+
const {
|
|
150
|
+
id,
|
|
151
|
+
fields = [],
|
|
152
|
+
repeatable = false,
|
|
153
|
+
fieldName = null,
|
|
154
|
+
label,
|
|
155
|
+
defaultValue = null
|
|
156
|
+
} = current || {};
|
|
157
|
+
return [...statesFields, ...(repeatable ? [{
|
|
195
158
|
type: 'items',
|
|
196
159
|
name: fieldName || id,
|
|
197
|
-
label
|
|
198
|
-
defaultValue
|
|
160
|
+
label,
|
|
161
|
+
defaultValue,
|
|
199
162
|
stateId: id,
|
|
200
163
|
itemsField: {
|
|
201
|
-
label
|
|
164
|
+
label,
|
|
202
165
|
type: 'fields',
|
|
203
|
-
fields
|
|
166
|
+
fields
|
|
204
167
|
}
|
|
205
|
-
}] : []),
|
|
168
|
+
}] : []), ...(!repeatable && fieldName !== null ? [{
|
|
206
169
|
type: 'fields',
|
|
207
170
|
name: fieldName,
|
|
208
171
|
stateId: id,
|
|
209
|
-
fields
|
|
210
|
-
}] : []),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}) : []));
|
|
172
|
+
fields
|
|
173
|
+
}] : []), ...(!repeatable && fieldName === null ? fields.map(it => ({
|
|
174
|
+
...it,
|
|
175
|
+
stateId: id
|
|
176
|
+
})) : [])];
|
|
215
177
|
}, []);
|
|
216
|
-
return [
|
|
178
|
+
return [...extraFields, ...screenFields];
|
|
217
179
|
}
|
|
218
180
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}, {
|
|
247
|
-
key: "merge",
|
|
248
|
-
value: function merge(manager) {
|
|
249
|
-
var namespace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
250
|
-
return this.addComponents(manager.getComponents(), namespace);
|
|
251
|
-
}
|
|
252
|
-
}, {
|
|
253
|
-
key: "addNamespace",
|
|
254
|
-
value: function addNamespace(namespace) {
|
|
255
|
-
var _this2 = this;
|
|
256
|
-
if (namespace === null) {
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
this.components = Object.keys(this.components).reduce(function (componentsMap, name) {
|
|
260
|
-
return _objectSpread(_objectSpread({}, componentsMap), {}, _defineProperty({}, "".concat(namespace, ".").concat(name), _this2.components[name]));
|
|
261
|
-
}, {});
|
|
181
|
+
class ComponentsManager extends EventEmitter {
|
|
182
|
+
constructor(components = {}) {
|
|
183
|
+
super();
|
|
184
|
+
this.components = components;
|
|
185
|
+
}
|
|
186
|
+
addComponent(name, component, namespace = null) {
|
|
187
|
+
return this.addComponents({
|
|
188
|
+
[name]: component
|
|
189
|
+
}, namespace);
|
|
190
|
+
}
|
|
191
|
+
addComponents(components, namespace = null) {
|
|
192
|
+
const newComponents = namespace !== null ? Object.keys(components).reduce((componentsMaps, name) => ({
|
|
193
|
+
...componentsMaps,
|
|
194
|
+
[`${namespace}.${name}`]: components[name]
|
|
195
|
+
}), {}) : components;
|
|
196
|
+
this.components = {
|
|
197
|
+
...this.components,
|
|
198
|
+
...newComponents
|
|
199
|
+
};
|
|
200
|
+
this.emit('change');
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
merge(manager, namespace = null) {
|
|
204
|
+
return this.addComponents(manager.getComponents(), namespace);
|
|
205
|
+
}
|
|
206
|
+
addNamespace(namespace) {
|
|
207
|
+
if (namespace === null) {
|
|
262
208
|
return this;
|
|
263
209
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}]);
|
|
289
|
-
}(EventEmitter);
|
|
210
|
+
this.components = Object.keys(this.components).reduce((componentsMap, name) => ({
|
|
211
|
+
...componentsMap,
|
|
212
|
+
[`${namespace}.${name}`]: this.components[name]
|
|
213
|
+
}), {});
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
getComponent(name, namespace = null) {
|
|
217
|
+
const components = this.getComponents(namespace);
|
|
218
|
+
return getComponentFromName(name, components);
|
|
219
|
+
}
|
|
220
|
+
getComponents(namespace = null) {
|
|
221
|
+
return namespace !== null ? Object.keys(this.components || {}).reduce((componentsMap, name) => {
|
|
222
|
+
const pattern = new RegExp(`^${namespace}\\.(.*)$`);
|
|
223
|
+
const matches = pattern.exec(name);
|
|
224
|
+
return matches !== null ? {
|
|
225
|
+
...componentsMap,
|
|
226
|
+
[matches[1]]: this.components[name]
|
|
227
|
+
} : componentsMap;
|
|
228
|
+
}, {}) : this.components;
|
|
229
|
+
}
|
|
230
|
+
hasComponent(name, namespace = null) {
|
|
231
|
+
return this.components !== null && typeof this.components[namespace !== null ? `${namespace}.${name}` : name] !== 'undefined';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
290
234
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}, {
|
|
317
|
-
key: "merge",
|
|
318
|
-
value: function merge(manager) {
|
|
319
|
-
return this.addDefinitions(manager.getDefinitions());
|
|
320
|
-
}
|
|
321
|
-
}, {
|
|
322
|
-
key: "filter",
|
|
323
|
-
value: function filter(_filter) {
|
|
324
|
-
// this.definitions = this.definitions.filter(filter);
|
|
325
|
-
// return this;
|
|
326
|
-
return new DefinitionsManager(this.definitions.filter(_filter));
|
|
327
|
-
}
|
|
328
|
-
}, {
|
|
329
|
-
key: "getDefinition",
|
|
330
|
-
value: function getDefinition(id) {
|
|
331
|
-
if (id === null) {
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
return this.definitions.find(function (it) {
|
|
335
|
-
return it.id === id;
|
|
336
|
-
}) || null;
|
|
337
|
-
}
|
|
338
|
-
}, {
|
|
339
|
-
key: "getDefinitions",
|
|
340
|
-
value: function getDefinitions() {
|
|
341
|
-
return this.definitions;
|
|
342
|
-
}
|
|
343
|
-
}, {
|
|
344
|
-
key: "hasDefinition",
|
|
345
|
-
value: function hasDefinition(id) {
|
|
346
|
-
return this.getDefinition(id) !== null;
|
|
347
|
-
}
|
|
348
|
-
}, {
|
|
349
|
-
key: "getComponent",
|
|
350
|
-
value: function getComponent(id) {
|
|
351
|
-
var _ref = this.getDefinition(id) || {},
|
|
352
|
-
_ref$component = _ref.component,
|
|
353
|
-
component = _ref$component === void 0 ? null : _ref$component;
|
|
354
|
-
return component;
|
|
355
|
-
}
|
|
356
|
-
}, {
|
|
357
|
-
key: "getComponents",
|
|
358
|
-
value: function getComponents() {
|
|
359
|
-
return this.definitions.reduce(function (allComponents, _ref2) {
|
|
360
|
-
var id = _ref2.id,
|
|
361
|
-
_ref2$component = _ref2.component,
|
|
362
|
-
component = _ref2$component === void 0 ? null : _ref2$component;
|
|
363
|
-
return component !== null ? _objectSpread(_objectSpread({}, allComponents), {}, _defineProperty({}, id, component)) : allComponents;
|
|
364
|
-
}, {});
|
|
235
|
+
class DefinitionsManager extends EventEmitter {
|
|
236
|
+
constructor(definitions = []) {
|
|
237
|
+
super();
|
|
238
|
+
this.definitions = definitions || [];
|
|
239
|
+
}
|
|
240
|
+
addDefinition(definition) {
|
|
241
|
+
this.addDefinitions(isArray(definition) ? definition : [definition]);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
addDefinitions(definitions) {
|
|
245
|
+
this.definitions = uniqBy([...definitions, ...this.definitions], it => it.id);
|
|
246
|
+
this.emit('change');
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
merge(manager) {
|
|
250
|
+
return this.addDefinitions(manager.getDefinitions());
|
|
251
|
+
}
|
|
252
|
+
filter(filter) {
|
|
253
|
+
// this.definitions = this.definitions.filter(filter);
|
|
254
|
+
// return this;
|
|
255
|
+
return new DefinitionsManager(this.definitions.filter(filter));
|
|
256
|
+
}
|
|
257
|
+
getDefinition(id) {
|
|
258
|
+
if (id === null) {
|
|
259
|
+
return null;
|
|
365
260
|
}
|
|
366
|
-
|
|
367
|
-
}
|
|
261
|
+
return this.definitions.find(it => it.id === id) || null;
|
|
262
|
+
}
|
|
263
|
+
getDefinitions() {
|
|
264
|
+
return this.definitions;
|
|
265
|
+
}
|
|
266
|
+
hasDefinition(id) {
|
|
267
|
+
return this.getDefinition(id) !== null;
|
|
268
|
+
}
|
|
269
|
+
getComponent(id) {
|
|
270
|
+
const {
|
|
271
|
+
component = null
|
|
272
|
+
} = this.getDefinition(id) || {};
|
|
273
|
+
return component;
|
|
274
|
+
}
|
|
275
|
+
getComponents() {
|
|
276
|
+
return this.definitions.reduce((allComponents, {
|
|
277
|
+
id,
|
|
278
|
+
component = null
|
|
279
|
+
}) => component !== null ? {
|
|
280
|
+
...allComponents,
|
|
281
|
+
[id]: component
|
|
282
|
+
} : allComponents, {});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
368
285
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
this.
|
|
384
|
-
this.events = _objectSpread(_objectSpread({}, this.events), {}, _defineProperty({}, event, [].concat(_toConsumableArray(this.events[event] || []), [callback])));
|
|
385
|
-
if (this.events[event].length === 1) {
|
|
386
|
-
this.addEventListener(event);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}, {
|
|
390
|
-
key: "unsubscribe",
|
|
391
|
-
value: function unsubscribe(event, callback) {
|
|
392
|
-
var _this2 = this;
|
|
393
|
-
this.off(event, callback);
|
|
394
|
-
this.events = Object.keys(this.events).reduce(function (newEvents, eventName) {
|
|
395
|
-
if (eventName !== event) {
|
|
396
|
-
return _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, _this2.events[eventName]));
|
|
397
|
-
}
|
|
398
|
-
var newListeners = _this2.events[eventName].filter(function (listener) {
|
|
399
|
-
return listener !== callback;
|
|
400
|
-
});
|
|
401
|
-
return newListeners.length > 0 ? _objectSpread(_objectSpread({}, newEvents), {}, _defineProperty({}, eventName, newListeners)) : newEvents;
|
|
402
|
-
}, {});
|
|
403
|
-
if (typeof this.events[event] === 'undefined') {
|
|
404
|
-
this.removeEventListener(event);
|
|
405
|
-
}
|
|
286
|
+
class EventsManager extends EventEmitter {
|
|
287
|
+
constructor(element) {
|
|
288
|
+
super();
|
|
289
|
+
this.element = element;
|
|
290
|
+
this.events = {};
|
|
291
|
+
this.listeners = {};
|
|
292
|
+
}
|
|
293
|
+
subscribe(event, callback) {
|
|
294
|
+
this.on(event, callback);
|
|
295
|
+
this.events = {
|
|
296
|
+
...this.events,
|
|
297
|
+
[event]: [...(this.events[event] || []), callback]
|
|
298
|
+
};
|
|
299
|
+
if (this.events[event].length === 1) {
|
|
300
|
+
this.addEventListener(event);
|
|
406
301
|
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
return _this3.emit.apply(_this3, [event].concat(args));
|
|
302
|
+
}
|
|
303
|
+
unsubscribe(event, callback) {
|
|
304
|
+
this.off(event, callback);
|
|
305
|
+
this.events = Object.keys(this.events).reduce((newEvents, eventName) => {
|
|
306
|
+
if (eventName !== event) {
|
|
307
|
+
return {
|
|
308
|
+
...newEvents,
|
|
309
|
+
[eventName]: this.events[eventName]
|
|
417
310
|
};
|
|
418
311
|
}
|
|
419
|
-
this.
|
|
312
|
+
const newListeners = this.events[eventName].filter(listener => listener !== callback);
|
|
313
|
+
return newListeners.length > 0 ? {
|
|
314
|
+
...newEvents,
|
|
315
|
+
[eventName]: newListeners
|
|
316
|
+
} : newEvents;
|
|
317
|
+
}, {});
|
|
318
|
+
if (typeof this.events[event] === 'undefined') {
|
|
319
|
+
this.removeEventListener(event);
|
|
420
320
|
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
this.
|
|
321
|
+
}
|
|
322
|
+
addEventListener(event) {
|
|
323
|
+
if (typeof this.listeners[event] === 'undefined') {
|
|
324
|
+
this.listeners[event] = (...args) => this.emit(event, ...args);
|
|
425
325
|
}
|
|
426
|
-
|
|
427
|
-
}
|
|
326
|
+
this.element.addEventListener(event, this.listeners[event]);
|
|
327
|
+
}
|
|
328
|
+
removeEventListener(event) {
|
|
329
|
+
this.element.removeEventListener(event, this.listeners[event]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
428
332
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
_inherits(FieldsManager, _DefinitionsManager);
|
|
435
|
-
return _createClass(FieldsManager, [{
|
|
436
|
-
key: "filter",
|
|
437
|
-
value: function filter(_filter) {
|
|
438
|
-
return new FieldsManager(this.definitions.filter(_filter));
|
|
439
|
-
}
|
|
440
|
-
}]);
|
|
441
|
-
}(DefinitionsManager);
|
|
333
|
+
class FieldsManager extends DefinitionsManager {
|
|
334
|
+
filter(filter) {
|
|
335
|
+
return new FieldsManager(this.definitions.filter(filter));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
442
338
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
_ref$fieldsPattern = _ref.fieldsPattern,
|
|
450
|
-
fieldsPattern = _ref$fieldsPattern === void 0 ? {} : _ref$fieldsPattern;
|
|
451
|
-
_classCallCheck(this, MediasParser);
|
|
339
|
+
class MediasParser {
|
|
340
|
+
constructor({
|
|
341
|
+
fieldsManager,
|
|
342
|
+
screensManager,
|
|
343
|
+
fieldsPattern = {}
|
|
344
|
+
}) {
|
|
452
345
|
this.fieldsManager = fieldsManager;
|
|
453
346
|
this.screensManager = screensManager;
|
|
454
347
|
this.fieldsPatternCache = fieldsPattern || {};
|
|
455
348
|
this.parsedThemesCache = {};
|
|
456
349
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
return this.parsedThemesCache[storyId];
|
|
350
|
+
getParsedStoryTheme(storyId, theme) {
|
|
351
|
+
if (typeof this.parsedThemesCache[storyId] === 'undefined') {
|
|
352
|
+
const {
|
|
353
|
+
medias: themeMedias,
|
|
354
|
+
...newTheme
|
|
355
|
+
} = this.toPath(theme);
|
|
356
|
+
this.parsedThemesCache[storyId] = {
|
|
357
|
+
themeMedias,
|
|
358
|
+
newTheme
|
|
359
|
+
};
|
|
470
360
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
return this.fieldsPatternCache[type];
|
|
361
|
+
return this.parsedThemesCache[storyId];
|
|
362
|
+
}
|
|
363
|
+
getFieldsPatternByScreen(type) {
|
|
364
|
+
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
365
|
+
const fields = getScreenFieldsWithStates(this.screensManager.getDefinition(type) || {});
|
|
366
|
+
this.fieldsPatternCache[type] = this.getFieldsPattern(fields || []);
|
|
479
367
|
}
|
|
368
|
+
return this.fieldsPatternCache[type];
|
|
369
|
+
}
|
|
480
370
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
371
|
+
// Convert medias object to path
|
|
372
|
+
toPath(story) {
|
|
373
|
+
if (story === null) {
|
|
374
|
+
return story;
|
|
375
|
+
}
|
|
376
|
+
const {
|
|
377
|
+
id: storyId = null,
|
|
378
|
+
theme = null,
|
|
379
|
+
components = []
|
|
380
|
+
} = story || {};
|
|
381
|
+
const {
|
|
382
|
+
components: newComponents,
|
|
383
|
+
medias
|
|
384
|
+
} = components.reduce(({
|
|
385
|
+
components: previousComponents,
|
|
386
|
+
medias: currentMedias
|
|
387
|
+
}, screen) => {
|
|
388
|
+
const {
|
|
389
|
+
type
|
|
390
|
+
} = screen;
|
|
391
|
+
const fieldsPattern = this.getFieldsPatternByScreen(type);
|
|
392
|
+
const {
|
|
393
|
+
data: newScreen,
|
|
394
|
+
medias: newMedias
|
|
395
|
+
} = MediasParser.replaceMediasWithPaths(screen, fieldsPattern);
|
|
396
|
+
return {
|
|
397
|
+
components: [...previousComponents, newScreen],
|
|
398
|
+
medias: {
|
|
399
|
+
...currentMedias,
|
|
400
|
+
...newMedias
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
}, {
|
|
404
|
+
components: [],
|
|
405
|
+
medias: null
|
|
406
|
+
});
|
|
407
|
+
if (theme !== null) {
|
|
408
|
+
const {
|
|
409
|
+
medias: themeMedias,
|
|
410
|
+
...newTheme
|
|
411
|
+
} = this.getParsedStoryTheme(storyId, theme);
|
|
412
|
+
return medias !== null || themeMedias !== null ? {
|
|
413
|
+
...story,
|
|
414
|
+
theme: newTheme,
|
|
525
415
|
components: newComponents,
|
|
526
|
-
medias:
|
|
527
|
-
|
|
416
|
+
medias: {
|
|
417
|
+
...themeMedias,
|
|
418
|
+
...medias
|
|
419
|
+
}
|
|
420
|
+
} : story;
|
|
528
421
|
}
|
|
422
|
+
return medias !== null ? {
|
|
423
|
+
...story,
|
|
424
|
+
components: newComponents,
|
|
425
|
+
medias
|
|
426
|
+
} : story;
|
|
427
|
+
}
|
|
529
428
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
_ref4$medias = _ref4.medias,
|
|
544
|
-
medias = _ref4$medias === void 0 ? defaultMedias : _ref4$medias;
|
|
545
|
-
if (medias === null && theme === null) {
|
|
546
|
-
return story;
|
|
547
|
-
}
|
|
429
|
+
// Convert path to medias object
|
|
430
|
+
fromPath(story, defaultMedias = null) {
|
|
431
|
+
if (story === null) {
|
|
432
|
+
return story;
|
|
433
|
+
}
|
|
434
|
+
const {
|
|
435
|
+
theme = null,
|
|
436
|
+
components = [],
|
|
437
|
+
medias = defaultMedias
|
|
438
|
+
} = story || {};
|
|
439
|
+
if (medias === null && theme === null) {
|
|
440
|
+
return story;
|
|
441
|
+
}
|
|
548
442
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
443
|
+
// Replace path with medias objects
|
|
444
|
+
// const newComponents =
|
|
445
|
+
// medias !== null
|
|
446
|
+
// ? components.map((screen) => {
|
|
447
|
+
// const { type } = screen;
|
|
448
|
+
// const fieldsPattern = this.getFieldsPatternByScreen(type);
|
|
449
|
+
// return MediasParser.replacePathsWithMedias(screen, medias, fieldsPattern);
|
|
450
|
+
// })
|
|
451
|
+
// : components;
|
|
558
452
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
453
|
+
// Faster parsing with data only
|
|
454
|
+
const componentsPattern = MediasParser.getMediaPatternsFromData(components);
|
|
455
|
+
const newComponents = medias !== null && componentsPattern.length > 0 ? MediasParser.replacePathsWithMedias(components, medias, componentsPattern) : components;
|
|
562
456
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}) : story;
|
|
570
|
-
}
|
|
571
|
-
return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
|
|
457
|
+
// Replace path with medias object in theme
|
|
458
|
+
if (theme !== null) {
|
|
459
|
+
const newTheme = this.fromPath(theme, medias);
|
|
460
|
+
return newTheme !== theme || newComponents !== components ? {
|
|
461
|
+
...story,
|
|
462
|
+
theme: newTheme,
|
|
572
463
|
components: newComponents
|
|
573
|
-
}
|
|
464
|
+
} : story;
|
|
574
465
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
466
|
+
return newComponents !== components ? {
|
|
467
|
+
...story,
|
|
468
|
+
components: newComponents
|
|
469
|
+
} : story;
|
|
470
|
+
}
|
|
471
|
+
getFieldsPattern(fields, namePrefix = null) {
|
|
472
|
+
return (fields || []).reduce((patterns, field) => {
|
|
473
|
+
const {
|
|
474
|
+
name = null,
|
|
475
|
+
type = null
|
|
476
|
+
} = field;
|
|
477
|
+
const path = [namePrefix, name].filter(it => it !== null && it !== '').join('\\.');
|
|
478
|
+
const fieldDefinition = {
|
|
479
|
+
...(type !== null ? this.fieldsManager.getDefinition(type) : null),
|
|
480
|
+
...field
|
|
481
|
+
};
|
|
589
482
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
var subReturn = MediasParser.replaceMediasWithPaths(value, patterns, medias, path);
|
|
669
|
-
newValue = subReturn.data;
|
|
670
|
-
subMedias = subReturn.medias;
|
|
671
|
-
} else {
|
|
672
|
-
newValue = value;
|
|
483
|
+
// also check settings fields
|
|
484
|
+
const {
|
|
485
|
+
fields: subFields = [],
|
|
486
|
+
itemsField = null,
|
|
487
|
+
settings = []
|
|
488
|
+
} = fieldDefinition;
|
|
489
|
+
return [...patterns, ...(MediasParser.fieldIsMedia(fieldDefinition) ? [new RegExp(`^${path}$`)] : []), ...(MediasParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp(`^${path}\\.media$`), new RegExp(`^${path}\\.variants\\.[0-9]+\\.media$`)] : []), ...this.getFieldsPattern(subFields, path), ...this.getFieldsPattern(settings, path), ...(itemsField !== null ? this.getFieldsPattern([itemsField], `${path}\\.[0-9]+`) : [])];
|
|
490
|
+
}, []);
|
|
491
|
+
}
|
|
492
|
+
static fieldIsMedia({
|
|
493
|
+
media = false
|
|
494
|
+
}) {
|
|
495
|
+
return media;
|
|
496
|
+
}
|
|
497
|
+
static fieldIsFontFamily({
|
|
498
|
+
id = null
|
|
499
|
+
}) {
|
|
500
|
+
return id === 'font-family';
|
|
501
|
+
}
|
|
502
|
+
static replacePathsWithMedias(data, medias, patterns, keyPrefix = null) {
|
|
503
|
+
const dataIsArray = isArray(data);
|
|
504
|
+
return MediasParser.keys(data).reduce((newData, key) => {
|
|
505
|
+
const path = [keyPrefix, key].filter(it => it !== null).join('.');
|
|
506
|
+
const patternMatch = patterns.reduce((found, pattern) => found || pattern.test(path), false);
|
|
507
|
+
const value = data[key];
|
|
508
|
+
let newValue;
|
|
509
|
+
if (patternMatch) {
|
|
510
|
+
newValue = isObject(value) ? value : medias[value] || value;
|
|
511
|
+
} else {
|
|
512
|
+
newValue = isObject(value) || isArray(value) ? MediasParser.replacePathsWithMedias(value, medias, patterns, path) : value;
|
|
513
|
+
}
|
|
514
|
+
return dataIsArray ? [...newData, newValue] : {
|
|
515
|
+
...newData,
|
|
516
|
+
[key]: newValue
|
|
517
|
+
};
|
|
518
|
+
}, dataIsArray ? [] : {});
|
|
519
|
+
}
|
|
520
|
+
static getMediaPath({
|
|
521
|
+
id = null
|
|
522
|
+
}) {
|
|
523
|
+
return id !== null ? `media://${id}` : null;
|
|
524
|
+
}
|
|
525
|
+
static replaceMediasWithPaths(data, patterns, medias = null, keyPrefix = null) {
|
|
526
|
+
const dataIsArray = isArray(data);
|
|
527
|
+
const dataKeys = MediasParser.keys(data);
|
|
528
|
+
return dataKeys.reduce(({
|
|
529
|
+
data: currentData,
|
|
530
|
+
medias: currentMedias
|
|
531
|
+
}, key) => {
|
|
532
|
+
const path = [keyPrefix, key].filter(it => it !== null).join('.');
|
|
533
|
+
const patternMatch = patterns.reduce((found, pattern) => found || pattern.test(path), false);
|
|
534
|
+
const value = data[key];
|
|
535
|
+
let newValue;
|
|
536
|
+
let media = null;
|
|
537
|
+
let subMedias = null;
|
|
538
|
+
if (patternMatch && isObject(value)) {
|
|
539
|
+
const mediaPath = MediasParser.getMediaPath(value);
|
|
540
|
+
newValue = mediaPath !== null ? mediaPath : value;
|
|
541
|
+
media = mediaPath !== null ? value : null;
|
|
542
|
+
} else if (isObject(value) || isArray(value)) {
|
|
543
|
+
const subReturn = MediasParser.replaceMediasWithPaths(value, patterns, medias, path);
|
|
544
|
+
newValue = subReturn.data;
|
|
545
|
+
subMedias = subReturn.medias;
|
|
546
|
+
} else {
|
|
547
|
+
newValue = value;
|
|
548
|
+
}
|
|
549
|
+
return {
|
|
550
|
+
data: dataIsArray ? [...(currentData || []), newValue] : {
|
|
551
|
+
...currentData,
|
|
552
|
+
[key]: newValue
|
|
553
|
+
},
|
|
554
|
+
medias: media !== null ? {
|
|
555
|
+
...currentMedias,
|
|
556
|
+
...subMedias,
|
|
557
|
+
[newValue]: media
|
|
558
|
+
} : {
|
|
559
|
+
...currentMedias,
|
|
560
|
+
...subMedias
|
|
673
561
|
}
|
|
562
|
+
};
|
|
563
|
+
}, {
|
|
564
|
+
data: dataKeys.length === 0 ? data : null,
|
|
565
|
+
medias
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
static getMediaPatternsFromData(obj) {
|
|
569
|
+
const dotObj = MediasParser.dot(obj);
|
|
570
|
+
return Object.keys(dotObj).filter(key => isString(dotObj[key]) && dotObj[key].match(/^media:\/\/([^/]+)$/) !== null).map(it => new RegExp(`^${it}$`));
|
|
571
|
+
}
|
|
572
|
+
static dot(obj) {
|
|
573
|
+
return MediasParser.keys(obj).reduce((acc, key) => {
|
|
574
|
+
if (typeof obj[key] !== 'object' || !obj[key]) {
|
|
674
575
|
return {
|
|
675
|
-
|
|
676
|
-
|
|
576
|
+
...acc,
|
|
577
|
+
[key]: obj[key]
|
|
677
578
|
};
|
|
678
|
-
}, {
|
|
679
|
-
data: dataKeys.length === 0 ? data : null,
|
|
680
|
-
medias: medias
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
}, {
|
|
684
|
-
key: "getMediaPatternsFromData",
|
|
685
|
-
value: function getMediaPatternsFromData(obj) {
|
|
686
|
-
var dotObj = MediasParser.dot(obj);
|
|
687
|
-
return Object.keys(dotObj).filter(function (key) {
|
|
688
|
-
return isString(dotObj[key]) && dotObj[key].match(/^media:\/\/([^/]+)$/) !== null;
|
|
689
|
-
}).map(function (it) {
|
|
690
|
-
return new RegExp("^".concat(it, "$"));
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
}, {
|
|
694
|
-
key: "dot",
|
|
695
|
-
value: function dot(obj) {
|
|
696
|
-
return MediasParser.keys(obj).reduce(function (acc, key) {
|
|
697
|
-
if (_typeof(obj[key]) !== 'object' || !obj[key]) {
|
|
698
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, obj[key]));
|
|
699
|
-
}
|
|
700
|
-
var flattenedChild = MediasParser.dot(obj[key]);
|
|
701
|
-
return _objectSpread(_objectSpread({}, acc), MediasParser.keys(flattenedChild).reduce(function (childAcc, childKey) {
|
|
702
|
-
return _objectSpread(_objectSpread({}, childAcc), {}, _defineProperty({}, "".concat(key, ".").concat(childKey), flattenedChild[childKey]));
|
|
703
|
-
}, {}));
|
|
704
|
-
}, {});
|
|
705
|
-
}
|
|
706
|
-
}, {
|
|
707
|
-
key: "keys",
|
|
708
|
-
value: function keys(obj) {
|
|
709
|
-
return isArray(obj) ? _toConsumableArray(obj.keys()) : Object.keys(obj);
|
|
710
|
-
}
|
|
711
|
-
}]);
|
|
712
|
-
}();
|
|
713
|
-
|
|
714
|
-
var ScreensManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
715
|
-
function ScreensManager() {
|
|
716
|
-
var _this;
|
|
717
|
-
var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
718
|
-
_classCallCheck(this, ScreensManager);
|
|
719
|
-
_this = _callSuper(this, ScreensManager, [definitions]);
|
|
720
|
-
_this.fieldsPattern = null;
|
|
721
|
-
return _this;
|
|
722
|
-
}
|
|
723
|
-
_inherits(ScreensManager, _DefinitionsManager);
|
|
724
|
-
return _createClass(ScreensManager, [{
|
|
725
|
-
key: "getFields",
|
|
726
|
-
value: function getFields(id) {
|
|
727
|
-
var _ref = this.getDefinition(id) || {},
|
|
728
|
-
_ref$fields = _ref.fields,
|
|
729
|
-
fields = _ref$fields === void 0 ? null : _ref$fields;
|
|
730
|
-
return fields;
|
|
731
|
-
}
|
|
732
|
-
}, {
|
|
733
|
-
key: "getLayouts",
|
|
734
|
-
value: function getLayouts(id) {
|
|
735
|
-
var _ref2 = this.getDefinition(id) || {},
|
|
736
|
-
_ref2$layouts = _ref2.layouts,
|
|
737
|
-
layouts = _ref2$layouts === void 0 ? null : _ref2$layouts;
|
|
738
|
-
return layouts;
|
|
739
|
-
}
|
|
740
|
-
}, {
|
|
741
|
-
key: "getFieldsPattern",
|
|
742
|
-
value: function getFieldsPattern() {
|
|
743
|
-
return this.fieldsPattern;
|
|
744
|
-
}
|
|
745
|
-
}, {
|
|
746
|
-
key: "setFieldsPattern",
|
|
747
|
-
value: function setFieldsPattern(fieldsPattern) {
|
|
748
|
-
this.fieldsPattern = fieldsPattern;
|
|
749
|
-
}
|
|
750
|
-
}, {
|
|
751
|
-
key: "filter",
|
|
752
|
-
value: function filter(_filter) {
|
|
753
|
-
return new ScreensManager(this.definitions.filter(_filter));
|
|
754
|
-
// this.definitions = this.definitions.filter(filter);
|
|
755
|
-
// return this;
|
|
756
|
-
}
|
|
757
|
-
}, {
|
|
758
|
-
key: "merge",
|
|
759
|
-
value: function merge(manager) {
|
|
760
|
-
var newFieldsPattern = manager.getFieldsPattern();
|
|
761
|
-
if (newFieldsPattern !== null && this.fieldsPattern === null) {
|
|
762
|
-
this.fieldsPattern = newFieldsPattern;
|
|
763
579
|
}
|
|
764
|
-
|
|
580
|
+
const flattenedChild = MediasParser.dot(obj[key]);
|
|
581
|
+
return {
|
|
582
|
+
...acc,
|
|
583
|
+
...MediasParser.keys(flattenedChild).reduce((childAcc, childKey) => ({
|
|
584
|
+
...childAcc,
|
|
585
|
+
[`${key}.${childKey}`]: flattenedChild[childKey]
|
|
586
|
+
}), {})
|
|
587
|
+
};
|
|
588
|
+
}, {});
|
|
589
|
+
}
|
|
590
|
+
static keys(obj) {
|
|
591
|
+
return isArray(obj) ? [...obj.keys()] : Object.keys(obj);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
class ScreensManager extends DefinitionsManager {
|
|
596
|
+
constructor(definitions = []) {
|
|
597
|
+
super(definitions);
|
|
598
|
+
this.fieldsPattern = null;
|
|
599
|
+
}
|
|
600
|
+
getFields(id) {
|
|
601
|
+
const {
|
|
602
|
+
fields = null
|
|
603
|
+
} = this.getDefinition(id) || {};
|
|
604
|
+
return fields;
|
|
605
|
+
}
|
|
606
|
+
getLayouts(id) {
|
|
607
|
+
const {
|
|
608
|
+
layouts = null
|
|
609
|
+
} = this.getDefinition(id) || {};
|
|
610
|
+
return layouts;
|
|
611
|
+
}
|
|
612
|
+
getFieldsPattern() {
|
|
613
|
+
return this.fieldsPattern;
|
|
614
|
+
}
|
|
615
|
+
setFieldsPattern(fieldsPattern) {
|
|
616
|
+
this.fieldsPattern = fieldsPattern;
|
|
617
|
+
}
|
|
618
|
+
filter(filter) {
|
|
619
|
+
return new ScreensManager(this.definitions.filter(filter));
|
|
620
|
+
// this.definitions = this.definitions.filter(filter);
|
|
621
|
+
// return this;
|
|
622
|
+
}
|
|
623
|
+
merge(manager) {
|
|
624
|
+
const newFieldsPattern = manager.getFieldsPattern();
|
|
625
|
+
if (newFieldsPattern !== null && this.fieldsPattern === null) {
|
|
626
|
+
this.fieldsPattern = newFieldsPattern;
|
|
765
627
|
}
|
|
766
|
-
|
|
767
|
-
}
|
|
628
|
+
return this.addDefinitions(manager.getDefinitions());
|
|
629
|
+
}
|
|
630
|
+
}
|
|
768
631
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
fieldsPattern = _ref$fieldsPattern === void 0 ? {} : _ref$fieldsPattern;
|
|
776
|
-
_classCallCheck(this, FontsParser);
|
|
632
|
+
class FontsParser {
|
|
633
|
+
constructor({
|
|
634
|
+
fieldsManager,
|
|
635
|
+
screensManager,
|
|
636
|
+
fieldsPattern = {}
|
|
637
|
+
}) {
|
|
777
638
|
this.fieldsManager = fieldsManager;
|
|
778
639
|
this.screensManager = screensManager;
|
|
779
640
|
this.fieldsPatternCache = fieldsPattern || {};
|
|
780
641
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
var fields = getScreenFieldsWithStates(this.screensManager.getDefinition(type) || {});
|
|
786
|
-
this.fieldsPatternCache[type] = this.getFieldsPattern(fields || []);
|
|
787
|
-
}
|
|
788
|
-
return this.fieldsPatternCache[type];
|
|
642
|
+
getFieldsPatternByScreen(type) {
|
|
643
|
+
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
644
|
+
const fields = getScreenFieldsWithStates(this.screensManager.getDefinition(type) || {});
|
|
645
|
+
this.fieldsPatternCache[type] = this.getFieldsPattern(fields || []);
|
|
789
646
|
}
|
|
647
|
+
return this.fieldsPatternCache[type];
|
|
648
|
+
}
|
|
790
649
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (story === null) {
|
|
797
|
-
return story;
|
|
798
|
-
}
|
|
650
|
+
// Extract fonts
|
|
651
|
+
parse(story) {
|
|
652
|
+
if (story === null) {
|
|
653
|
+
return story;
|
|
654
|
+
}
|
|
799
655
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
656
|
+
// Extract fonts from screen
|
|
657
|
+
const {
|
|
658
|
+
theme = null,
|
|
659
|
+
components = []
|
|
660
|
+
} = story || {};
|
|
661
|
+
const fonts = uniq(components.reduce((currentFonts, screen) => {
|
|
662
|
+
const {
|
|
663
|
+
type
|
|
664
|
+
} = screen;
|
|
665
|
+
const fieldsPattern = this.getFieldsPatternByScreen(type);
|
|
666
|
+
const newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
|
|
667
|
+
return newFonts.length > 0 ? [...currentFonts, ...newFonts] : currentFonts;
|
|
668
|
+
}, []), 'name');
|
|
812
669
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
|
|
670
|
+
// Extract fonts from theme
|
|
671
|
+
if (theme !== null) {
|
|
672
|
+
const {
|
|
673
|
+
fonts: themeFonts = [],
|
|
674
|
+
...newTheme
|
|
675
|
+
} = this.parse(theme);
|
|
676
|
+
return fonts.length > 0 || themeFonts.length > 0 ? {
|
|
677
|
+
...story,
|
|
678
|
+
theme: newTheme,
|
|
679
|
+
fonts: uniq([...themeFonts, ...fonts], 'name')
|
|
680
|
+
} : story;
|
|
681
|
+
}
|
|
682
|
+
return fonts.length > 0 ? {
|
|
683
|
+
...story,
|
|
684
|
+
fonts
|
|
685
|
+
} : story;
|
|
686
|
+
}
|
|
687
|
+
getFieldsPattern(fields, namePrefix = null) {
|
|
688
|
+
return (fields || []).reduce((patterns, field) => {
|
|
689
|
+
const {
|
|
690
|
+
name = null,
|
|
691
|
+
type = null
|
|
692
|
+
} = field;
|
|
693
|
+
const path = [namePrefix, name].filter(it => it !== null && it !== '').join('\\.');
|
|
694
|
+
const fieldDefinition = {
|
|
695
|
+
...(type !== null ? this.fieldsManager.getDefinition(type) : null),
|
|
696
|
+
...field
|
|
697
|
+
};
|
|
842
698
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
var value = data[key];
|
|
881
|
-
var font = null;
|
|
882
|
-
var subFonts = null;
|
|
883
|
-
if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
|
|
884
|
-
font = value;
|
|
885
|
-
} else if (isObject(value) || isArray(value)) {
|
|
886
|
-
subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
|
|
887
|
-
}
|
|
888
|
-
return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
|
|
889
|
-
}, []);
|
|
890
|
-
}
|
|
891
|
-
}]);
|
|
892
|
-
}();
|
|
699
|
+
// also check settings fields
|
|
700
|
+
const {
|
|
701
|
+
fields: subFields = [],
|
|
702
|
+
itemsField = null,
|
|
703
|
+
settings = []
|
|
704
|
+
} = fieldDefinition;
|
|
705
|
+
return [...patterns, ...(FontsParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp(`^${path}$`)] : []), ...this.getFieldsPattern(subFields, path), ...this.getFieldsPattern(settings, path), ...(itemsField !== null ? this.getFieldsPattern([itemsField], `${path}\\.[0-9]+`) : [])];
|
|
706
|
+
}, []);
|
|
707
|
+
}
|
|
708
|
+
static fieldIsFontFamily({
|
|
709
|
+
id = null
|
|
710
|
+
}) {
|
|
711
|
+
return id === 'font-family';
|
|
712
|
+
}
|
|
713
|
+
static valueIsFont({
|
|
714
|
+
type = null
|
|
715
|
+
}) {
|
|
716
|
+
return type === 'custom' || type === 'google';
|
|
717
|
+
}
|
|
718
|
+
static extractFontsWithPaths(data, patterns, keyPrefix = null) {
|
|
719
|
+
const dataIsArray = isArray(data);
|
|
720
|
+
const keys = dataIsArray ? [...data.keys()] : Object.keys(data);
|
|
721
|
+
return keys.reduce((currentFonts, key) => {
|
|
722
|
+
const path = [keyPrefix, key].filter(it => it !== null).join('.');
|
|
723
|
+
const patternMatch = patterns.reduce((found, pattern) => found || pattern.test(path), false);
|
|
724
|
+
const value = data[key];
|
|
725
|
+
let font = null;
|
|
726
|
+
let subFonts = null;
|
|
727
|
+
if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
|
|
728
|
+
font = value;
|
|
729
|
+
} else if (isObject(value) || isArray(value)) {
|
|
730
|
+
subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
|
|
731
|
+
}
|
|
732
|
+
return subFonts !== null || font !== null ? [...currentFonts, ...(subFonts || []), ...(font !== null ? [font] : [])] : currentFonts;
|
|
733
|
+
}, []);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
893
736
|
|
|
894
|
-
var _excluded$6 = ["shareIncentive", "callToAction"];
|
|
895
737
|
/* eslint-disable class-methods-use-this */
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
_ref2$shareIncentive = _ref2.shareIncentive,
|
|
918
|
-
shareIncentive = _ref2$shareIncentive === void 0 ? null : _ref2$shareIncentive,
|
|
919
|
-
_ref2$callToAction = _ref2.callToAction,
|
|
920
|
-
callToAction = _ref2$callToAction === void 0 ? null : _ref2$callToAction,
|
|
921
|
-
restScreen = _objectWithoutProperties(_ref2, _excluded$6);
|
|
922
|
-
var _ref3 = screen || {},
|
|
923
|
-
_ref3$header = _ref3.header,
|
|
924
|
-
header = _ref3$header === void 0 ? null : _ref3$header,
|
|
925
|
-
_ref3$footer = _ref3.footer,
|
|
926
|
-
footer = _ref3$footer === void 0 ? null : _ref3$footer;
|
|
738
|
+
class ShareCall {
|
|
739
|
+
test(screen) {
|
|
740
|
+
const {
|
|
741
|
+
shareIncentive = null,
|
|
742
|
+
callToAction = null
|
|
743
|
+
} = screen || {};
|
|
744
|
+
if (shareIncentive === null && callToAction === null) {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
parse(screen) {
|
|
750
|
+
const {
|
|
751
|
+
shareIncentive = null,
|
|
752
|
+
callToAction = null,
|
|
753
|
+
...restScreen
|
|
754
|
+
} = screen || {};
|
|
755
|
+
const {
|
|
756
|
+
header = null,
|
|
757
|
+
footer = null
|
|
758
|
+
} = screen || {};
|
|
927
759
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
760
|
+
// Carful for recursivity here cause same key name
|
|
761
|
+
const newHeader = shareIncentive !== null ? {
|
|
762
|
+
...(shareIncentive !== null ? {
|
|
763
|
+
shareIncentive
|
|
764
|
+
} : null),
|
|
765
|
+
...(header !== null ? {
|
|
766
|
+
header
|
|
767
|
+
} : null)
|
|
768
|
+
} : header;
|
|
769
|
+
const newFooter = callToAction !== null ? {
|
|
770
|
+
...(callToAction !== null ? {
|
|
771
|
+
callToAction
|
|
772
|
+
} : null),
|
|
773
|
+
...(footer !== null ? {
|
|
774
|
+
footer
|
|
775
|
+
} : null)
|
|
776
|
+
} : footer;
|
|
777
|
+
const newScreen = {
|
|
778
|
+
...restScreen,
|
|
779
|
+
...(newHeader !== null ? {
|
|
940
780
|
header: newHeader
|
|
941
|
-
} : null),
|
|
781
|
+
} : null),
|
|
782
|
+
...(newFooter !== null ? {
|
|
942
783
|
footer: newFooter
|
|
943
|
-
} : null)
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
}
|
|
947
|
-
}
|
|
784
|
+
} : null)
|
|
785
|
+
};
|
|
786
|
+
return newScreen;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
948
789
|
ShareCall.prototype.priority = 0;
|
|
949
790
|
|
|
950
|
-
var _excluded$5 = ["answers"],
|
|
951
|
-
_excluded2$2 = ["customAnswerLabel"];
|
|
952
791
|
/* eslint-disable class-methods-use-this */
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
restAnswer = _objectWithoutProperties(_ref3, _excluded2$2);
|
|
991
|
-
return _objectSpread(_objectSpread({}, restAnswer), {}, {
|
|
992
|
-
result: customAnswerLabel
|
|
993
|
-
});
|
|
994
|
-
})
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
}]);
|
|
998
|
-
}();
|
|
792
|
+
class CustomAnswerLabel {
|
|
793
|
+
test(screen) {
|
|
794
|
+
const {
|
|
795
|
+
answers = null
|
|
796
|
+
} = screen || {};
|
|
797
|
+
if (answers === null || answers.length === 0) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
const hasCustomAnswerLabel = (answers || []).some((answer = null) => answer !== null && typeof answer.customAnswerLabel !== 'undefined');
|
|
801
|
+
if (!hasCustomAnswerLabel) {
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
parse(screen) {
|
|
807
|
+
const {
|
|
808
|
+
answers = null,
|
|
809
|
+
...restScreen
|
|
810
|
+
} = screen || {};
|
|
811
|
+
return {
|
|
812
|
+
...restScreen,
|
|
813
|
+
answers: answers.map((answer = null) => {
|
|
814
|
+
if (answer === null || typeof answer.customAnswerLabel === 'undefined') {
|
|
815
|
+
return answer;
|
|
816
|
+
}
|
|
817
|
+
const {
|
|
818
|
+
customAnswerLabel,
|
|
819
|
+
...restAnswer
|
|
820
|
+
} = answer || {};
|
|
821
|
+
return {
|
|
822
|
+
...restAnswer,
|
|
823
|
+
result: customAnswerLabel
|
|
824
|
+
};
|
|
825
|
+
})
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
}
|
|
999
829
|
CustomAnswerLabel.prototype.priority = 1;
|
|
1000
830
|
|
|
1001
|
-
var _excluded$4 = ["items"],
|
|
1002
|
-
_excluded2$1 = ["label", "textStyle"];
|
|
1003
|
-
|
|
1004
831
|
/* eslint-disable class-methods-use-this */
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
832
|
+
class KeypadItemLabel {
|
|
833
|
+
test(screen) {
|
|
834
|
+
const {
|
|
835
|
+
type = null,
|
|
836
|
+
items = null
|
|
837
|
+
} = screen || {};
|
|
838
|
+
if (type !== 'keypad' || items === null || items.length === 0) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
const hasStringItemLabel = (items || []).some((item = null) => item !== null && isString(item?.label));
|
|
842
|
+
if (!hasStringItemLabel) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
return true;
|
|
846
|
+
}
|
|
847
|
+
parse(screen) {
|
|
848
|
+
const {
|
|
849
|
+
items = null,
|
|
850
|
+
...restScreen
|
|
851
|
+
} = screen || {};
|
|
852
|
+
return {
|
|
853
|
+
...restScreen,
|
|
854
|
+
items: items.map((item = null) => {
|
|
855
|
+
if (item === null || !isString(item?.label)) {
|
|
856
|
+
return item;
|
|
857
|
+
}
|
|
858
|
+
const {
|
|
859
|
+
label,
|
|
860
|
+
textStyle,
|
|
861
|
+
...restAnswer
|
|
862
|
+
} = item || {};
|
|
863
|
+
return {
|
|
864
|
+
...restAnswer,
|
|
865
|
+
label: {
|
|
866
|
+
body: label,
|
|
867
|
+
textStyle
|
|
1041
868
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
label: {
|
|
1048
|
-
body: label,
|
|
1049
|
-
textStyle: textStyle
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
|
-
})
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
}]);
|
|
1056
|
-
}();
|
|
869
|
+
};
|
|
870
|
+
})
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
}
|
|
1057
874
|
KeypadItemLabel.prototype.priority = 1;
|
|
1058
875
|
|
|
1059
|
-
var _excluded$3 = ["keypadSettings"];
|
|
1060
876
|
/* eslint-disable class-methods-use-this */
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
_ref4$layout = _ref4.layout,
|
|
1093
|
-
keypadSettingsLayout = _ref4$layout === void 0 ? null : _ref4$layout;
|
|
1094
|
-
return _objectSpread(_objectSpread({}, restScreen), {}, {
|
|
1095
|
-
keypadLayout: keypadSettingsLayout
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
}]);
|
|
1099
|
-
}();
|
|
877
|
+
class KeypadSettings {
|
|
878
|
+
test(screen) {
|
|
879
|
+
const {
|
|
880
|
+
type = null,
|
|
881
|
+
keypadSettings = null
|
|
882
|
+
} = screen || {};
|
|
883
|
+
if (type !== 'keypad' || keypadSettings === null) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
const {
|
|
887
|
+
layout: keypadSettingsLayout = null
|
|
888
|
+
} = keypadSettings || {};
|
|
889
|
+
if (keypadSettingsLayout === null) {
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
892
|
+
return true;
|
|
893
|
+
}
|
|
894
|
+
parse(screen) {
|
|
895
|
+
const {
|
|
896
|
+
keypadSettings = null,
|
|
897
|
+
...restScreen
|
|
898
|
+
} = screen || {};
|
|
899
|
+
const {
|
|
900
|
+
layout: keypadSettingsLayout = null
|
|
901
|
+
} = keypadSettings || {};
|
|
902
|
+
return {
|
|
903
|
+
...restScreen,
|
|
904
|
+
keypadLayout: keypadSettingsLayout
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
}
|
|
1100
908
|
KeypadSettings.prototype.priority = 1;
|
|
1101
909
|
|
|
1102
910
|
// export { default as ButtonPadding } from './ButtonPadding';
|
|
@@ -1109,16 +917,13 @@ var migrations = /*#__PURE__*/Object.freeze({
|
|
|
1109
917
|
ShareCall: ShareCall
|
|
1110
918
|
});
|
|
1111
919
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
_classCallCheck(this, MigrationsParser);
|
|
920
|
+
class MigrationsParser {
|
|
921
|
+
constructor({
|
|
922
|
+
screensManager
|
|
923
|
+
}) {
|
|
1117
924
|
this.screensManager = screensManager;
|
|
1118
|
-
this.parsers = Object.keys(migrations).map(
|
|
1119
|
-
|
|
1120
|
-
});
|
|
1121
|
-
this.parsers.sort(function (a, b) {
|
|
925
|
+
this.parsers = Object.keys(migrations).map(migration => new migrations[migration]());
|
|
926
|
+
this.parsers.sort((a, b) => {
|
|
1122
927
|
if (a.priority === undefined || b.priority === undefined) {
|
|
1123
928
|
return 0;
|
|
1124
929
|
}
|
|
@@ -1130,572 +935,526 @@ var MigrationsParser = /*#__PURE__*/function () {
|
|
|
1130
935
|
}
|
|
1131
936
|
|
|
1132
937
|
// eslint-disable-next-line class-methods-use-this
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1157
|
-
}]);
|
|
1158
|
-
}();
|
|
938
|
+
parse(story) {
|
|
939
|
+
if (story === null) {
|
|
940
|
+
return story;
|
|
941
|
+
}
|
|
942
|
+
const {
|
|
943
|
+
components = [],
|
|
944
|
+
...restStory
|
|
945
|
+
} = story || {};
|
|
946
|
+
const finalComponents = components.reduce((currentComponents, screen) => {
|
|
947
|
+
const newScreen = this.parsers.reduce((currentScreen, parser) => {
|
|
948
|
+
if (parser.test(currentScreen, story)) {
|
|
949
|
+
return parser.parse(currentScreen, story);
|
|
950
|
+
}
|
|
951
|
+
return currentScreen;
|
|
952
|
+
}, screen);
|
|
953
|
+
return [...currentComponents, newScreen];
|
|
954
|
+
}, []);
|
|
955
|
+
return {
|
|
956
|
+
...restStory,
|
|
957
|
+
components: finalComponents
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
}
|
|
1159
961
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
_classCallCheck(this, ThemeParser);
|
|
962
|
+
class ThemeParser {
|
|
963
|
+
constructor({
|
|
964
|
+
screensManager
|
|
965
|
+
}) {
|
|
1165
966
|
this.screensManager = screensManager;
|
|
1166
967
|
this.definitionCache = {};
|
|
1167
968
|
this.fieldsCache = {};
|
|
1168
969
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
this.definitionCache[type] = {
|
|
1178
|
-
definition: definition,
|
|
1179
|
-
themeScreen: themeScreen
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
return this.definitionCache[type];
|
|
970
|
+
getDefinitionByScreen(type, themeComponents) {
|
|
971
|
+
if (typeof this.definitionCache[type] === 'undefined') {
|
|
972
|
+
const definition = this.screensManager.getDefinition(type) || {};
|
|
973
|
+
const themeScreen = themeComponents.find(it => it.type === type) || null;
|
|
974
|
+
this.definitionCache[type] = {
|
|
975
|
+
definition,
|
|
976
|
+
themeScreen
|
|
977
|
+
};
|
|
1183
978
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
itemFields = _ref5$fields === void 0 ? [] : _ref5$fields;
|
|
1218
|
-
if (itemFields !== null && itemFields.length > 0) {
|
|
1219
|
-
return acc.concat(itemFields);
|
|
1220
|
-
}
|
|
1221
|
-
return acc;
|
|
1222
|
-
}, finalFields);
|
|
1223
|
-
}
|
|
1224
|
-
this.fieldsCache[definitionId] = {
|
|
1225
|
-
fields: finalFields,
|
|
1226
|
-
repetableStates: repetableStates
|
|
1227
|
-
};
|
|
979
|
+
return this.definitionCache[type];
|
|
980
|
+
}
|
|
981
|
+
getFieldsForDefinition(definition) {
|
|
982
|
+
const {
|
|
983
|
+
id: definitionId = null,
|
|
984
|
+
fields = [],
|
|
985
|
+
states = []
|
|
986
|
+
} = definition || {};
|
|
987
|
+
if (typeof this.fieldsCache[definitionId] === 'undefined') {
|
|
988
|
+
if (states === null || states.length === 0) {
|
|
989
|
+
this.fieldsCache[definitionId] = {
|
|
990
|
+
fields
|
|
991
|
+
};
|
|
992
|
+
} else {
|
|
993
|
+
// TODO: test this
|
|
994
|
+
let finalFields = fields;
|
|
995
|
+
let repetableStates = [];
|
|
996
|
+
if (states !== null && states.length > 0) {
|
|
997
|
+
const nonRepetableStates = states.filter(({
|
|
998
|
+
repeatable = false
|
|
999
|
+
}) => repeatable === false);
|
|
1000
|
+
repetableStates = states.filter(({
|
|
1001
|
+
repeatable = false
|
|
1002
|
+
}) => repeatable === true);
|
|
1003
|
+
finalFields = nonRepetableStates.reduce((acc, it) => {
|
|
1004
|
+
const {
|
|
1005
|
+
fields: itemFields = []
|
|
1006
|
+
} = it || {};
|
|
1007
|
+
if (itemFields !== null && itemFields.length > 0) {
|
|
1008
|
+
return acc.concat(itemFields);
|
|
1009
|
+
}
|
|
1010
|
+
return acc;
|
|
1011
|
+
}, finalFields);
|
|
1228
1012
|
}
|
|
1013
|
+
this.fieldsCache[definitionId] = {
|
|
1014
|
+
fields: finalFields,
|
|
1015
|
+
repetableStates
|
|
1016
|
+
};
|
|
1229
1017
|
}
|
|
1230
|
-
return this.fieldsCache[definitionId];
|
|
1231
1018
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
themeColors = _theme$colors === void 0 ? {} : _theme$colors,
|
|
1253
|
-
_theme$textStyles = theme.textStyles,
|
|
1254
|
-
themeTextStyles = _theme$textStyles === void 0 ? null : _theme$textStyles,
|
|
1255
|
-
_theme$boxStyles = theme.boxStyles,
|
|
1256
|
-
themeBoxStyles = _theme$boxStyles === void 0 ? null : _theme$boxStyles;
|
|
1257
|
-
|
|
1258
|
-
// Speed test
|
|
1259
|
-
// const newComponents = [...components];
|
|
1260
|
-
// for (let index = 0; index < components.length; index += 1) {
|
|
1261
|
-
// const screen = components[index] || {};
|
|
1262
|
-
// const { type } = screen;
|
|
1263
|
-
// const { definition, themeScreen } = this.getDefinitionByScreen(type, themeComponents);
|
|
1264
|
-
// const newScreen = this.parseScreen(
|
|
1265
|
-
// definition,
|
|
1266
|
-
// screen,
|
|
1267
|
-
// themeScreen,
|
|
1268
|
-
// themeBackground,
|
|
1269
|
-
// themeColors,
|
|
1270
|
-
// themeTextStyles,
|
|
1271
|
-
// themeBoxStyles,
|
|
1272
|
-
// );
|
|
1273
|
-
|
|
1274
|
-
// if (newScreen !== screen || themeScreen !== null) {
|
|
1275
|
-
// newComponents[index] = {
|
|
1276
|
-
// ...themeScreen,
|
|
1277
|
-
// ...newScreen,
|
|
1278
|
-
// };
|
|
1279
|
-
// }
|
|
1280
|
-
// }
|
|
1281
|
-
// story.components = newComponents;
|
|
1282
|
-
// return story;
|
|
1283
|
-
|
|
1284
|
-
var newComponents = components.reduce(function (currentComponents, screen, index) {
|
|
1285
|
-
var type = screen.type;
|
|
1286
|
-
var _this$getDefinitionBy = _this.getDefinitionByScreen(type, themeComponents),
|
|
1287
|
-
definition = _this$getDefinitionBy.definition;
|
|
1288
|
-
var themeScreen = null;
|
|
1289
|
-
var newScreen = _this.parseScreen(definition, screen, themeScreen, themeBackground, themeColors, themeTextStyles, themeBoxStyles);
|
|
1290
|
-
|
|
1291
|
-
// Only switch screen if it has changed
|
|
1292
|
-
return newScreen !== screen || themeScreen !== null ? [].concat(_toConsumableArray(currentComponents.slice(0, index)), [_objectSpread(_objectSpread({}, themeScreen), newScreen)], _toConsumableArray(currentComponents.slice(index + 1))) : currentComponents;
|
|
1293
|
-
}, components);
|
|
1294
|
-
return newComponents !== components ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1295
|
-
components: newComponents
|
|
1296
|
-
}) : story;
|
|
1297
|
-
}
|
|
1298
|
-
}, {
|
|
1299
|
-
key: "parseScreen",
|
|
1300
|
-
value: function parseScreen(definition, value, themeValue, themeBackground, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1301
|
-
var _this2 = this;
|
|
1302
|
-
var _this$getFieldsForDef = this.getFieldsForDefinition(definition),
|
|
1303
|
-
_this$getFieldsForDef2 = _this$getFieldsForDef.fields,
|
|
1304
|
-
fields = _this$getFieldsForDef2 === void 0 ? null : _this$getFieldsForDef2,
|
|
1305
|
-
_this$getFieldsForDef3 = _this$getFieldsForDef.repetableStates,
|
|
1306
|
-
repetableStates = _this$getFieldsForDef3 === void 0 ? null : _this$getFieldsForDef3;
|
|
1307
|
-
var newThemeValue = themeValue === null && themeBackground !== null ? {} : themeValue;
|
|
1308
|
-
if (themeBackground !== null && typeof newThemeValue.background !== 'undefined') {
|
|
1309
|
-
newThemeValue.background = _objectSpread(_objectSpread({}, themeBackground), newThemeValue.background);
|
|
1310
|
-
} else if (themeBackground !== null) {
|
|
1311
|
-
newThemeValue.background = themeBackground;
|
|
1312
|
-
}
|
|
1313
|
-
var newScreenValue = Object.keys(value).reduce(function (currentValue, key) {
|
|
1314
|
-
var repetableState = null;
|
|
1315
|
-
if (repetableStates !== null && repetableStates.length > 0) {
|
|
1316
|
-
repetableState = repetableStates.find(function (_ref7) {
|
|
1317
|
-
var _ref7$id = _ref7.id,
|
|
1318
|
-
stateId = _ref7$id === void 0 ? null : _ref7$id;
|
|
1319
|
-
return stateId !== null && stateId === key;
|
|
1320
|
-
}) || null;
|
|
1321
|
-
}
|
|
1322
|
-
var fieldDefinition = (fields || null).find(function (it) {
|
|
1323
|
-
return it.name === key;
|
|
1324
|
-
}) || repetableState || {};
|
|
1325
|
-
var fieldValue = value[key];
|
|
1326
|
-
var fieldThemeValue = newThemeValue !== null ? newThemeValue[key] || null : null;
|
|
1327
|
-
|
|
1328
|
-
// Try for early return
|
|
1329
|
-
var _ref8 = fieldDefinition || {},
|
|
1330
|
-
_ref8$theme = _ref8.theme,
|
|
1331
|
-
theme = _ref8$theme === void 0 ? null : _ref8$theme;
|
|
1332
|
-
if ((theme === null || !isObject(theme)) && fields === null) {
|
|
1333
|
-
return _objectSpread(_objectSpread({}, currentValue), {}, _defineProperty({}, key, fieldValue));
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
// console.log('start', key, fieldValue);
|
|
1337
|
-
var newFieldValue = _this2.parseField(fieldValue, fieldDefinition, fieldThemeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1338
|
-
// console.log('result', newFieldValue);
|
|
1019
|
+
return this.fieldsCache[definitionId];
|
|
1020
|
+
}
|
|
1021
|
+
parse(story) {
|
|
1022
|
+
if (story === null) {
|
|
1023
|
+
return story;
|
|
1024
|
+
}
|
|
1025
|
+
const {
|
|
1026
|
+
theme = null,
|
|
1027
|
+
components = null
|
|
1028
|
+
} = story || {};
|
|
1029
|
+
if (theme === null || components === null) {
|
|
1030
|
+
return story;
|
|
1031
|
+
}
|
|
1032
|
+
const {
|
|
1033
|
+
components: themeComponents = [],
|
|
1034
|
+
background: themeBackground = null,
|
|
1035
|
+
colors: themeColors = {},
|
|
1036
|
+
textStyles: themeTextStyles = null,
|
|
1037
|
+
boxStyles: themeBoxStyles = null
|
|
1038
|
+
} = theme;
|
|
1339
1039
|
|
|
1340
|
-
|
|
1040
|
+
// Speed test
|
|
1041
|
+
// const newComponents = [...components];
|
|
1042
|
+
// for (let index = 0; index < components.length; index += 1) {
|
|
1043
|
+
// const screen = components[index] || {};
|
|
1044
|
+
// const { type } = screen;
|
|
1045
|
+
// const { definition, themeScreen } = this.getDefinitionByScreen(type, themeComponents);
|
|
1046
|
+
// const newScreen = this.parseScreen(
|
|
1047
|
+
// definition,
|
|
1048
|
+
// screen,
|
|
1049
|
+
// themeScreen,
|
|
1050
|
+
// themeBackground,
|
|
1051
|
+
// themeColors,
|
|
1052
|
+
// themeTextStyles,
|
|
1053
|
+
// themeBoxStyles,
|
|
1054
|
+
// );
|
|
1341
1055
|
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1056
|
+
// if (newScreen !== screen || themeScreen !== null) {
|
|
1057
|
+
// newComponents[index] = {
|
|
1058
|
+
// ...themeScreen,
|
|
1059
|
+
// ...newScreen,
|
|
1060
|
+
// };
|
|
1061
|
+
// }
|
|
1062
|
+
// }
|
|
1063
|
+
// story.components = newComponents;
|
|
1064
|
+
// return story;
|
|
1347
1065
|
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1066
|
+
const newComponents = components.reduce((currentComponents, screen, index) => {
|
|
1067
|
+
const {
|
|
1068
|
+
type
|
|
1069
|
+
} = screen;
|
|
1070
|
+
const {
|
|
1071
|
+
definition /* themeScreen */
|
|
1072
|
+
} = this.getDefinitionByScreen(type, themeComponents);
|
|
1073
|
+
const themeScreen = null;
|
|
1074
|
+
const newScreen = this.parseScreen(definition, screen, themeScreen, themeBackground, themeColors, themeTextStyles, themeBoxStyles);
|
|
1357
1075
|
|
|
1358
|
-
//
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1076
|
+
// Only switch screen if it has changed
|
|
1077
|
+
return newScreen !== screen || themeScreen !== null ? [...currentComponents.slice(0, index), {
|
|
1078
|
+
...themeScreen,
|
|
1079
|
+
...newScreen
|
|
1080
|
+
}, ...currentComponents.slice(index + 1)] : currentComponents;
|
|
1081
|
+
}, components);
|
|
1082
|
+
return newComponents !== components ? {
|
|
1083
|
+
...story,
|
|
1084
|
+
components: newComponents
|
|
1085
|
+
} : story;
|
|
1086
|
+
}
|
|
1087
|
+
parseScreen(definition, value, themeValue, themeBackground, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1088
|
+
const {
|
|
1089
|
+
fields = null,
|
|
1090
|
+
repetableStates = null
|
|
1091
|
+
} = this.getFieldsForDefinition(definition);
|
|
1092
|
+
const newThemeValue = themeValue === null && themeBackground !== null ? {} : themeValue;
|
|
1093
|
+
if (themeBackground !== null && typeof newThemeValue.background !== 'undefined') {
|
|
1094
|
+
newThemeValue.background = {
|
|
1095
|
+
...themeBackground,
|
|
1096
|
+
...newThemeValue.background
|
|
1097
|
+
};
|
|
1098
|
+
} else if (themeBackground !== null) {
|
|
1099
|
+
newThemeValue.background = themeBackground;
|
|
1100
|
+
}
|
|
1101
|
+
const newScreenValue = Object.keys(value).reduce((currentValue, key) => {
|
|
1102
|
+
let repetableState = null;
|
|
1103
|
+
if (repetableStates !== null && repetableStates.length > 0) {
|
|
1104
|
+
repetableState = repetableStates.find(({
|
|
1105
|
+
id: stateId = null
|
|
1106
|
+
}) => stateId !== null && stateId === key) || null;
|
|
1366
1107
|
}
|
|
1108
|
+
const fieldDefinition = (fields || null).find(it => it.name === key) || repetableState || {};
|
|
1109
|
+
const fieldValue = value[key];
|
|
1110
|
+
const fieldThemeValue = newThemeValue !== null ? newThemeValue[key] || null : null;
|
|
1367
1111
|
|
|
1368
|
-
//
|
|
1369
|
-
|
|
1370
|
-
|
|
1112
|
+
// Try for early return
|
|
1113
|
+
const {
|
|
1114
|
+
theme = null
|
|
1115
|
+
} = fieldDefinition || {};
|
|
1116
|
+
if ((theme === null || !isObject(theme)) && fields === null) {
|
|
1117
|
+
return {
|
|
1118
|
+
...currentValue,
|
|
1119
|
+
[key]: fieldValue
|
|
1120
|
+
};
|
|
1371
1121
|
}
|
|
1372
1122
|
|
|
1373
|
-
//
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
return innerField !== null ? Object.keys(innerField).reduce(function (newInnerField, innerFieldName) {
|
|
1377
|
-
// Early return
|
|
1378
|
-
if (!isObject(innerField[innerFieldName])) {
|
|
1379
|
-
return newInnerField;
|
|
1380
|
-
}
|
|
1381
|
-
var _ref9 = fieldTheme[innerFieldName] || {},
|
|
1382
|
-
_ref9$textStyle = _ref9.textStyle,
|
|
1383
|
-
innerFieldTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle,
|
|
1384
|
-
_ref9$color = _ref9.color,
|
|
1385
|
-
innerFieldColor = _ref9$color === void 0 ? null : _ref9$color,
|
|
1386
|
-
_ref9$boxStyle = _ref9.boxStyle,
|
|
1387
|
-
innerFieldBoxStyle = _ref9$boxStyle === void 0 ? null : _ref9$boxStyle;
|
|
1123
|
+
// console.log('start', key, fieldValue);
|
|
1124
|
+
const newFieldValue = this.parseField(fieldValue, fieldDefinition, fieldThemeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1125
|
+
// console.log('result', newFieldValue);
|
|
1388
1126
|
|
|
1389
|
-
|
|
1390
|
-
if (innerFieldTextStyle === null && innerFieldColor === null && innerFieldBoxStyle === null) {
|
|
1391
|
-
return newInnerField;
|
|
1392
|
-
}
|
|
1393
|
-
var _ref0 = innerField[innerFieldName] || {},
|
|
1394
|
-
_ref0$textStyle = _ref0.textStyle,
|
|
1395
|
-
valueTextStyle = _ref0$textStyle === void 0 ? false : _ref0$textStyle,
|
|
1396
|
-
_ref0$boxStyle = _ref0.boxStyle,
|
|
1397
|
-
valueBoxStyle = _ref0$boxStyle === void 0 ? false : _ref0$boxStyle;
|
|
1127
|
+
// const newFieldValue = fieldValue;
|
|
1398
1128
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
} : null;
|
|
1411
|
-
if (colorValue === null && textStyleValue === null && boxStyleValue === null) {
|
|
1412
|
-
return newInnerField;
|
|
1413
|
-
}
|
|
1414
|
-
return _objectSpread(_objectSpread({}, newInnerField), {}, _defineProperty({}, innerFieldName, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colorValue), innerField[innerFieldName]), textStyleValue), boxStyleValue)));
|
|
1415
|
-
}, innerField) : innerField;
|
|
1416
|
-
});
|
|
1417
|
-
return newFieldValue;
|
|
1418
|
-
}
|
|
1419
|
-
if (isObject(value)) {
|
|
1420
|
-
return this.parseValue(value, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1421
|
-
}
|
|
1422
|
-
return value;
|
|
1423
|
-
}
|
|
1424
|
-
}, {
|
|
1425
|
-
key: "parseInnerFields",
|
|
1426
|
-
value: function parseInnerFields(value, fieldsOrDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1427
|
-
var _this4 = this;
|
|
1428
|
-
var newValue = Object.keys(value).reduce(function (finalValue, innerFieldName) {
|
|
1429
|
-
var innerDefinition = isArray(fieldsOrDefinition) ? fieldsOrDefinition.find(function (it) {
|
|
1430
|
-
return it.name === innerFieldName;
|
|
1431
|
-
}) || null : fieldsOrDefinition;
|
|
1432
|
-
var _ref1 = innerDefinition || {},
|
|
1433
|
-
_ref1$theme = _ref1.theme,
|
|
1434
|
-
idfTheme = _ref1$theme === void 0 ? null : _ref1$theme;
|
|
1435
|
-
var innerValue = value[innerFieldName];
|
|
1129
|
+
// Only switch field if it has changed
|
|
1130
|
+
return newFieldValue !== fieldValue ? {
|
|
1131
|
+
...currentValue,
|
|
1132
|
+
[key]: newFieldValue
|
|
1133
|
+
} : currentValue;
|
|
1134
|
+
}, value);
|
|
1135
|
+
return newThemeValue !== null ? {
|
|
1136
|
+
...newThemeValue,
|
|
1137
|
+
...newScreenValue
|
|
1138
|
+
} : newScreenValue;
|
|
1139
|
+
}
|
|
1436
1140
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1141
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1142
|
+
parseField(value, fieldDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1143
|
+
const {
|
|
1144
|
+
theme: fieldTheme = null,
|
|
1145
|
+
fields: definitionFields = null
|
|
1146
|
+
} = fieldDefinition;
|
|
1443
1147
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
return
|
|
1148
|
+
// There are sub-fields in this definition
|
|
1149
|
+
if (definitionFields !== null && value !== null) {
|
|
1150
|
+
return isArray(value) ? value.map(innerFieldValue => {
|
|
1151
|
+
if (innerFieldValue === null) {
|
|
1152
|
+
return innerFieldValue;
|
|
1449
1153
|
}
|
|
1154
|
+
return this.parseInnerFields(innerFieldValue, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1155
|
+
}) : this.parseInnerFields(value, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1156
|
+
}
|
|
1450
1157
|
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
}, {});
|
|
1455
|
-
return newValue;
|
|
1158
|
+
// Early return
|
|
1159
|
+
if (fieldTheme === null || !isObject(fieldTheme)) {
|
|
1160
|
+
return value;
|
|
1456
1161
|
}
|
|
1457
1162
|
|
|
1458
|
-
//
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
var value = initialValue || null;
|
|
1465
|
-
var _ref10 = fieldTheme || {},
|
|
1466
|
-
_ref10$textStyle = _ref10.textStyle,
|
|
1467
|
-
fieldTextStyleName = _ref10$textStyle === void 0 ? null : _ref10$textStyle,
|
|
1468
|
-
_ref10$color = _ref10.color,
|
|
1469
|
-
fieldColorName = _ref10$color === void 0 ? null : _ref10$color,
|
|
1470
|
-
_ref10$boxStyle = _ref10.boxStyle,
|
|
1471
|
-
fieldBoxStyleName = _ref10$boxStyle === void 0 ? null : _ref10$boxStyle,
|
|
1472
|
-
otherProps = _objectWithoutProperties(_ref10, _excluded$1);
|
|
1473
|
-
if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty(otherProps) && !isObject(fieldTheme)) {
|
|
1474
|
-
return value;
|
|
1163
|
+
// @TODO very slooow...
|
|
1164
|
+
if (isArray(value)) {
|
|
1165
|
+
const newFieldValue = value.map(innerField => innerField !== null ? Object.keys(innerField).reduce((newInnerField, innerFieldName) => {
|
|
1166
|
+
// Early return
|
|
1167
|
+
if (!isObject(innerField[innerFieldName])) {
|
|
1168
|
+
return newInnerField;
|
|
1475
1169
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1170
|
+
const {
|
|
1171
|
+
textStyle: innerFieldTextStyle = null,
|
|
1172
|
+
color: innerFieldColor = null,
|
|
1173
|
+
boxStyle: innerFieldBoxStyle = null
|
|
1174
|
+
} = fieldTheme[innerFieldName] || {};
|
|
1175
|
+
|
|
1176
|
+
// Early return, no theme
|
|
1177
|
+
if (innerFieldTextStyle === null && innerFieldColor === null && innerFieldBoxStyle === null) {
|
|
1178
|
+
return newInnerField;
|
|
1483
1179
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
valueBoxStyle = _ref12$boxStyle === void 0 ? false : _ref12$boxStyle;
|
|
1180
|
+
const {
|
|
1181
|
+
textStyle: valueTextStyle = false,
|
|
1182
|
+
boxStyle: valueBoxStyle = false
|
|
1183
|
+
} = innerField[innerFieldName] || {};
|
|
1489
1184
|
|
|
1490
1185
|
// Color
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
color: fieldColor
|
|
1186
|
+
const colorValue = innerFieldColor !== null ? {
|
|
1187
|
+
color: innerFieldColor !== null && themeColors !== null ? themeColors[innerFieldColor] || null : null
|
|
1494
1188
|
} : null;
|
|
1495
1189
|
|
|
1496
1190
|
// Text style
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1191
|
+
const textStyleValue = innerFieldTextStyle !== null ? {
|
|
1192
|
+
textStyle: valueTextStyle !== false ? valueTextStyle : {
|
|
1193
|
+
...(innerFieldTextStyle !== null && themeTextStyles !== null ? themeTextStyles[innerFieldTextStyle] || null : null),
|
|
1194
|
+
...valueTextStyle
|
|
1195
|
+
}
|
|
1501
1196
|
} : null;
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
boxStyle: valueBoxStyle !== false ? valueBoxStyle : _objectSpread(_objectSpread(_objectSpread({}, fieldBoxStyle), fieldThemeComponentBoxStyle), valueBoxStyle || null)
|
|
1197
|
+
const boxStyleValue = innerFieldBoxStyle !== null ? {
|
|
1198
|
+
boxStyle: valueBoxStyle !== false ? valueBoxStyle : {
|
|
1199
|
+
...(innerFieldBoxStyle !== null && themeBoxStyles !== null ? themeBoxStyles[innerFieldBoxStyle] || null : null),
|
|
1200
|
+
...valueBoxStyle
|
|
1201
|
+
}
|
|
1508
1202
|
} : null;
|
|
1203
|
+
if (colorValue === null && textStyleValue === null && boxStyleValue === null) {
|
|
1204
|
+
return newInnerField;
|
|
1205
|
+
}
|
|
1206
|
+
return {
|
|
1207
|
+
...newInnerField,
|
|
1208
|
+
[innerFieldName]: {
|
|
1209
|
+
...colorValue,
|
|
1210
|
+
...innerField[innerFieldName],
|
|
1211
|
+
...textStyleValue,
|
|
1212
|
+
...boxStyleValue
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
}, innerField) : innerField);
|
|
1216
|
+
return newFieldValue;
|
|
1217
|
+
}
|
|
1218
|
+
if (isObject(value)) {
|
|
1219
|
+
return this.parseValue(value, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1220
|
+
}
|
|
1221
|
+
return value;
|
|
1222
|
+
}
|
|
1223
|
+
parseInnerFields(value, fieldsOrDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1224
|
+
const newValue = Object.keys(value).reduce((finalValue, innerFieldName) => {
|
|
1225
|
+
const innerDefinition = isArray(fieldsOrDefinition) ? fieldsOrDefinition.find(it => it.name === innerFieldName) || null : fieldsOrDefinition;
|
|
1226
|
+
const {
|
|
1227
|
+
theme: idfTheme = null
|
|
1228
|
+
} = innerDefinition || {};
|
|
1229
|
+
const innerValue = value[innerFieldName];
|
|
1509
1230
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1231
|
+
// For items fields
|
|
1232
|
+
if (innerValue !== null && innerDefinition !== null && isArray(innerValue)) {
|
|
1233
|
+
// eslint-disable-next-line no-param-reassign
|
|
1234
|
+
finalValue[innerFieldName] = this.parseField(innerValue, innerDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1235
|
+
return finalValue;
|
|
1512
1236
|
}
|
|
1513
|
-
return initialValue;
|
|
1514
|
-
}
|
|
1515
|
-
}]);
|
|
1516
|
-
}();
|
|
1517
1237
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1238
|
+
// For fields with fields
|
|
1239
|
+
if (innerValue !== null && idfTheme !== null && isObject(idfTheme) && isObject(innerValue)) {
|
|
1240
|
+
// eslint-disable-next-line no-param-reassign
|
|
1241
|
+
finalValue[innerFieldName] = this.parseValue(innerValue, idfTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1242
|
+
return finalValue;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// eslint-disable-next-line no-param-reassign
|
|
1246
|
+
finalValue[innerFieldName] = value[innerFieldName];
|
|
1247
|
+
return finalValue;
|
|
1248
|
+
}, {});
|
|
1249
|
+
return newValue;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1253
|
+
parseValue(initialValue, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1254
|
+
if (isObject(initialValue) || isObject(fieldTheme)) {
|
|
1255
|
+
const value = initialValue || null;
|
|
1256
|
+
const {
|
|
1257
|
+
textStyle: fieldTextStyleName = null,
|
|
1258
|
+
color: fieldColorName = null,
|
|
1259
|
+
boxStyle: fieldBoxStyleName = null,
|
|
1260
|
+
...otherProps
|
|
1261
|
+
} = fieldTheme || {};
|
|
1262
|
+
if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty(otherProps) && !isObject(fieldTheme)) {
|
|
1263
|
+
return value;
|
|
1264
|
+
}
|
|
1265
|
+
let complexValue = null;
|
|
1266
|
+
if (!isEmpty(otherProps)) {
|
|
1267
|
+
complexValue = Object.keys(otherProps).reduce((newObject, key) => {
|
|
1268
|
+
const innerValue = value !== null ? value[key] || null : null;
|
|
1269
|
+
const newValue = this.parseValue(innerValue, otherProps[key], themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1270
|
+
return {
|
|
1271
|
+
...newObject,
|
|
1272
|
+
...(newValue !== null ? {
|
|
1273
|
+
[key]: newValue
|
|
1274
|
+
} : null)
|
|
1275
|
+
};
|
|
1276
|
+
}, {});
|
|
1277
|
+
}
|
|
1278
|
+
const {
|
|
1279
|
+
textStyle: valueTextStyle = false,
|
|
1280
|
+
boxStyle: valueBoxStyle = false
|
|
1281
|
+
} = value || {};
|
|
1282
|
+
|
|
1283
|
+
// Color
|
|
1284
|
+
const fieldColor = fieldColorName !== null && themeColors !== null ? themeColors[fieldColorName] || null : null;
|
|
1285
|
+
const colorValue = fieldColor !== null ? {
|
|
1286
|
+
color: fieldColor
|
|
1287
|
+
} : null;
|
|
1288
|
+
|
|
1289
|
+
// Text style
|
|
1290
|
+
const fieldTextStyle = fieldTextStyleName !== null && themeTextStyles !== null ? themeTextStyles[fieldTextStyleName] || null : null;
|
|
1291
|
+
const fieldThemeComponentTextStyle = themeValue !== null ? themeValue.textStyle || null : null;
|
|
1292
|
+
const textStyleValue = fieldTextStyle !== null || fieldThemeComponentTextStyle !== null ? {
|
|
1293
|
+
textStyle: valueTextStyle !== false ? valueTextStyle : {
|
|
1294
|
+
...fieldTextStyle,
|
|
1295
|
+
...fieldThemeComponentTextStyle,
|
|
1296
|
+
...(valueTextStyle || null)
|
|
1297
|
+
}
|
|
1298
|
+
} : null;
|
|
1299
|
+
|
|
1300
|
+
// Box style
|
|
1301
|
+
const fieldBoxStyle = fieldBoxStyleName !== null && themeBoxStyles !== null ? themeBoxStyles[fieldBoxStyleName] || null : null;
|
|
1302
|
+
const fieldThemeComponentBoxStyle = themeValue !== null ? themeValue.boxStyle || null : null;
|
|
1303
|
+
const boxStyleValue = fieldBoxStyle !== null || fieldThemeComponentBoxStyle !== null ? {
|
|
1304
|
+
boxStyle: valueBoxStyle !== false ? valueBoxStyle : {
|
|
1305
|
+
...fieldBoxStyle,
|
|
1306
|
+
...fieldThemeComponentBoxStyle,
|
|
1307
|
+
...(valueBoxStyle || null)
|
|
1308
|
+
}
|
|
1309
|
+
} : null;
|
|
1310
|
+
|
|
1311
|
+
// Only change value if something is overrided
|
|
1312
|
+
return colorValue !== null || themeValue !== null || textStyleValue !== null || boxStyleValue !== null || complexValue !== null ? {
|
|
1313
|
+
...colorValue,
|
|
1314
|
+
...themeValue,
|
|
1315
|
+
...value,
|
|
1316
|
+
...boxStyleValue,
|
|
1317
|
+
...textStyleValue,
|
|
1318
|
+
...complexValue
|
|
1319
|
+
} : value;
|
|
1320
|
+
}
|
|
1321
|
+
return initialValue;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
class StoryParser {
|
|
1326
|
+
constructor({
|
|
1327
|
+
screensManager,
|
|
1328
|
+
fieldsManager,
|
|
1329
|
+
fieldsPattern
|
|
1330
|
+
}) {
|
|
1331
|
+
const {
|
|
1332
|
+
medias: mediasPattern = null,
|
|
1333
|
+
fonts: fontsPattern = null
|
|
1334
|
+
} = fieldsPattern || {};
|
|
1529
1335
|
this.themeParser = new ThemeParser({
|
|
1530
|
-
screensManager
|
|
1336
|
+
screensManager
|
|
1531
1337
|
});
|
|
1532
1338
|
this.mediasParser = new MediasParser({
|
|
1533
|
-
screensManager
|
|
1534
|
-
fieldsManager
|
|
1339
|
+
screensManager,
|
|
1340
|
+
fieldsManager,
|
|
1535
1341
|
fieldsPattern: mediasPattern
|
|
1536
1342
|
});
|
|
1537
1343
|
this.fontsParser = new FontsParser({
|
|
1538
|
-
screensManager
|
|
1539
|
-
fieldsManager
|
|
1344
|
+
screensManager,
|
|
1345
|
+
fieldsManager,
|
|
1540
1346
|
fieldsPattern: fontsPattern
|
|
1541
1347
|
});
|
|
1542
1348
|
this.migrationsParser = new MigrationsParser({
|
|
1543
|
-
screensManager
|
|
1349
|
+
screensManager
|
|
1544
1350
|
});
|
|
1545
1351
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (story === null) {
|
|
1560
|
-
return story;
|
|
1561
|
-
}
|
|
1562
|
-
var parsers = [[withMedias, function (newStory) {
|
|
1563
|
-
return _this.mediasParser.fromPath(newStory);
|
|
1564
|
-
}], [withTheme, function (newStory) {
|
|
1565
|
-
return _this.themeParser.parse(newStory);
|
|
1566
|
-
}], [withFonts, function (newStory) {
|
|
1567
|
-
return _this.fontsParser.parse(newStory);
|
|
1568
|
-
}], [withMigrations, function (newStory) {
|
|
1569
|
-
return _this.migrationsParser.parse(newStory);
|
|
1570
|
-
}]];
|
|
1571
|
-
return parsers.reduce(function (parsedStory, _ref4) {
|
|
1572
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
1573
|
-
enabled = _ref5[0],
|
|
1574
|
-
parse = _ref5[1];
|
|
1575
|
-
return enabled ? parse(parsedStory) : parsedStory;
|
|
1576
|
-
}, story);
|
|
1577
|
-
}
|
|
1578
|
-
}]);
|
|
1579
|
-
}();
|
|
1352
|
+
parse(story, {
|
|
1353
|
+
withTheme = true,
|
|
1354
|
+
withMedias = true,
|
|
1355
|
+
withFonts = true,
|
|
1356
|
+
withMigrations = true
|
|
1357
|
+
} = {}) {
|
|
1358
|
+
if (story === null) {
|
|
1359
|
+
return story;
|
|
1360
|
+
}
|
|
1361
|
+
const parsers = [[withMedias, newStory => this.mediasParser.fromPath(newStory)], [withTheme, newStory => this.themeParser.parse(newStory)], [withFonts, newStory => this.fontsParser.parse(newStory)], [withMigrations, newStory => this.migrationsParser.parse(newStory)]];
|
|
1362
|
+
return parsers.reduce((parsedStory, [enabled, parse]) => enabled ? parse(parsedStory) : parsedStory, story);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1580
1365
|
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
var _ref7 = metadata || {},
|
|
1675
|
-
_ref7$duration = _ref7.duration,
|
|
1676
|
-
duration = _ref7$duration === void 0 ? rootDuration : _ref7$duration;
|
|
1677
|
-
var data = _objectSpread(_objectSpread({}, otherOpts || null), {}, {
|
|
1678
|
-
event: 'eventInteraction',
|
|
1679
|
-
eventCategory: type,
|
|
1680
|
-
eventAction: action,
|
|
1681
|
-
eventLabel: mediaName || mediaUrl,
|
|
1682
|
-
eventValue: value,
|
|
1683
|
-
mediaId: mediaId,
|
|
1684
|
-
mediaUrl: mediaUrl,
|
|
1685
|
-
mediaName: mediaName
|
|
1686
|
-
});
|
|
1687
|
-
if (duration !== null) {
|
|
1688
|
-
data.mediaDuration = Math.round(duration);
|
|
1689
|
-
}
|
|
1690
|
-
if (currentTime !== null) {
|
|
1691
|
-
data.mediaCurrentTime = Math.round(currentTime);
|
|
1692
|
-
}
|
|
1693
|
-
if (currentTime !== null && duration !== null && duration > 0) {
|
|
1694
|
-
data.mediaProgress = currentTime / duration;
|
|
1695
|
-
}
|
|
1696
|
-
this.push(data);
|
|
1697
|
-
}
|
|
1698
|
-
}]);
|
|
1699
|
-
}(Tracking$1);
|
|
1366
|
+
/* eslint-disable no-console */
|
|
1367
|
+
class Tracking extends Tracking$1 {
|
|
1368
|
+
constructor(opts = {}) {
|
|
1369
|
+
super(opts);
|
|
1370
|
+
this.screensViewed = [];
|
|
1371
|
+
}
|
|
1372
|
+
trackScreenView(screen, screenIndex) {
|
|
1373
|
+
const {
|
|
1374
|
+
screensCount = null
|
|
1375
|
+
} = this.variables || {};
|
|
1376
|
+
const {
|
|
1377
|
+
id: screenId = null,
|
|
1378
|
+
type: screenType = null,
|
|
1379
|
+
metadata = null,
|
|
1380
|
+
parameters: {
|
|
1381
|
+
metadata: parametersMetadata
|
|
1382
|
+
} = {}
|
|
1383
|
+
} = screen || {};
|
|
1384
|
+
const {
|
|
1385
|
+
title: screenTitle,
|
|
1386
|
+
description: screenDescrition
|
|
1387
|
+
} = metadata || parametersMetadata || {};
|
|
1388
|
+
if (this.screensViewed.indexOf(screenId || screenIndex) === -1) {
|
|
1389
|
+
this.screensViewed = [...this.screensViewed, screenId || screenIndex];
|
|
1390
|
+
}
|
|
1391
|
+
const data = {
|
|
1392
|
+
event: 'screenView',
|
|
1393
|
+
screenId,
|
|
1394
|
+
screenType,
|
|
1395
|
+
screenIndex,
|
|
1396
|
+
screenTitle,
|
|
1397
|
+
screenDescrition,
|
|
1398
|
+
screenProgress: screensCount !== null && screenIndex !== null ? (screenIndex + 1) / screensCount : null,
|
|
1399
|
+
screensViewed: this.screensViewed,
|
|
1400
|
+
screensViewedProgress: screensCount !== null ? this.screensViewed.length / screensCount : null
|
|
1401
|
+
};
|
|
1402
|
+
this.push(data);
|
|
1403
|
+
}
|
|
1404
|
+
trackEvent(category = null, action = null, label = null, opts = null) {
|
|
1405
|
+
const {
|
|
1406
|
+
value = null,
|
|
1407
|
+
...otherOpts
|
|
1408
|
+
} = opts || {};
|
|
1409
|
+
const data = {
|
|
1410
|
+
...(otherOpts || null),
|
|
1411
|
+
event: 'eventInteraction',
|
|
1412
|
+
eventCategory: category,
|
|
1413
|
+
eventAction: action,
|
|
1414
|
+
eventLabel: label,
|
|
1415
|
+
eventValue: value
|
|
1416
|
+
};
|
|
1417
|
+
this.push(data);
|
|
1418
|
+
}
|
|
1419
|
+
trackMedia(type = null, media = null, action = null, opts = null) {
|
|
1420
|
+
const {
|
|
1421
|
+
value = null,
|
|
1422
|
+
currentTime: optsCurrentTime = null,
|
|
1423
|
+
...otherOpts
|
|
1424
|
+
} = opts || {};
|
|
1425
|
+
const {
|
|
1426
|
+
id: mediaId = null,
|
|
1427
|
+
url: mediaUrl = null,
|
|
1428
|
+
name: mediaName = null,
|
|
1429
|
+
duration: rootDuration = null,
|
|
1430
|
+
currentTime = optsCurrentTime,
|
|
1431
|
+
metadata = {}
|
|
1432
|
+
} = media || {};
|
|
1433
|
+
const {
|
|
1434
|
+
duration = rootDuration
|
|
1435
|
+
} = metadata || {};
|
|
1436
|
+
const data = {
|
|
1437
|
+
...(otherOpts || null),
|
|
1438
|
+
event: 'eventInteraction',
|
|
1439
|
+
eventCategory: type,
|
|
1440
|
+
eventAction: action,
|
|
1441
|
+
eventLabel: mediaName || mediaUrl,
|
|
1442
|
+
eventValue: value,
|
|
1443
|
+
mediaId,
|
|
1444
|
+
mediaUrl,
|
|
1445
|
+
mediaName
|
|
1446
|
+
};
|
|
1447
|
+
if (duration !== null) {
|
|
1448
|
+
data.mediaDuration = Math.round(duration);
|
|
1449
|
+
}
|
|
1450
|
+
if (currentTime !== null) {
|
|
1451
|
+
data.mediaCurrentTime = Math.round(currentTime);
|
|
1452
|
+
}
|
|
1453
|
+
if (currentTime !== null && duration !== null && duration > 0) {
|
|
1454
|
+
data.mediaProgress = currentTime / duration;
|
|
1455
|
+
}
|
|
1456
|
+
this.push(data);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1700
1459
|
|
|
1701
1460
|
export { ColorsParser, ComponentsManager, DefinitionsManager, EventsManager, FieldsManager, FontsParser, MediasParser, ScreensManager, StoryParser, ThemeParser, Tracking };
|