@panneau/core 1.0.1-alpha.0 → 1.0.3-alpha.0

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