-
Notifications
You must be signed in to change notification settings - Fork 0
/
sepcon.js
3801 lines (3343 loc) · 155 KB
/
sepcon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
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
842
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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
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
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "./";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SepCon = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _root = __webpack_require__(21);
var _root2 = _interopRequireDefault(_root);
var _constants = __webpack_require__(2);
var _utils = __webpack_require__(1);
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var formatShorthand = function formatShorthand(def) {
if (def && def.lifecycle) {
var segments = ['pre', 'on', 'post'];
def.lifecycle = Object.assign({
pre: {},
on: {},
post: {}
}, def.lifecycle);
Object.keys(def.lifecycle).forEach(function (key) {
if (segments.indexOf(key) === -1) {
def.lifecycle.on[key] = def.lifecycle[key];
}
});
Object.keys(def.lifecycle.on).forEach(function (key) {
def.lifecycle[key] = def.lifecycle.on[key];
});
}
};
function create(meta, def, type, defs, cls) {
var _this = this;
switch (type) {
case 'component':
formatShorthand(def.state);
formatShorthand(def.view);
break;
default:
formatShorthand(def);
}
var definition = _utils2.default.clone(def);
var defInstance = void 0;
if (defs[meta.id]) {
this.root.logs.print({
title: { content: 'Tried To Create A Definition With Existing Id' },
rows: [{ style: 'label', content: 'Object Type' }, { style: 'code', content: type }, { style: 'label', content: 'Definition Id' }, { style: 'code', content: meta.id }]
});
return false;
} else {
if (meta.extend) {
if (!meta.extend.proto) {
this.root.logs.print({
title: { content: 'Tried To Extend A Non-Existing Definition' },
rows: [{ style: 'label', content: 'Object Type' }, { style: 'code', content: type }, { style: 'label', content: 'Definition Id' }, { style: 'code', content: meta.id }, { style: 'label', content: 'Extended Id' }, { style: 'code', content: meta.extend }]
});
} else {
meta.extend = _utils2.default.clone(meta.extend.proto);
}
}
if (meta.decorators) {
meta.decorators = meta.decorators.filter(function (dec) {
if (!defs[dec]) {
_this.root.logs.print({
title: { content: 'Tried To Decorate A Definition With a Non-Existing One' },
rows: [{ style: 'label', content: 'Object Type' }, { style: 'code', content: type }, { style: 'label', content: 'Definition Id' }, { style: 'code', content: meta.id }, { style: 'label', content: 'Decorator Id' }, { style: 'code', content: dec }]
});
return false;
}
return true;
});
meta.decorators = meta.decorators.map(function (dec) {
return _utils2.default.clone(defs[dec].definition);
});
}
defInstance = defs[meta.id] = new cls(meta, definition, this.root);
}
var instance = {
id: meta.id,
proto: defInstance.definition
};
if (type !== 'component') {
if (def.endpoints) {
for (var key in def.endpoints) {
if (key !== 'id' && key !== 'proto' && typeof def.endpoints[key] === 'function') {
instance[key] = def.endpoints[key].bind(defInstance.scoped);
}
}
}
}
return instance;
}
var SepConClass = function () {
function SepConClass(options) {
_classCallCheck(this, SepConClass);
if (options) {
this.hash = options.hash;
}
this.root = new _root2.default(this, options);
this.classes = this.root.classes;
this.setConfiguration = this.root.setConfiguration.bind(this.root);
}
_createClass(SepConClass, [{
key: 'modifier',
value: function modifier(_modifier) {
if (this.root.modifiers[_modifier]) {
return this.root.modifiers[_modifier].scoped.methods;
}
}
}, {
key: 'service',
value: function service(_service) {
var provider = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var services = void 0;
provider = provider || this.root.defaultProvider;
if (provider && this.root.providers[provider] && this.root.providers[provider].services[_service]) {
services = this.root.providers[provider].services;
} else {
services = this.root.services;
}
if (services[_service]) {
return services[_service].api;
}
return null;
}
}, {
key: 'createData',
value: function createData(meta) {
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return create.call(this, meta, def, 'data', this.root.datas, this.root.classes.Data);
}
}, {
key: 'createModifier',
value: function createModifier(meta) {
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return create.call(this, meta, def, 'modifier', this.root.modifiers, this.root.classes.Modifier);
}
}, {
key: 'createProvider',
value: function createProvider(meta) {
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return create.call(this, meta, def, 'provider', this.root.providers, this.root.classes.Provider);
}
}, {
key: 'createService',
value: function createService(meta) {
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (meta.provider && !this.root.providers[meta.provider]) {
this.root.logs.print({
title: { content: 'Reference to Non-Existing Service Provider' },
rows: [{ style: 'label', content: 'Service Id' }, { style: 'code', content: meta.id }, { style: 'label', content: 'Provider Id' }, { style: 'code', content: meta.provider }]
});
return false;
}
return create.call(this, meta, def, 'service', meta.provider ? this.root.providers[meta.provider].services : this.root.services, this.root.classes.Service);
}
}, {
key: 'createComponent',
value: function createComponent(meta) {
var _this2 = this;
var def = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var created = create.call(this, meta, def, 'component', this.root.components, this.root.classes.ComponentDefinition);
return Object.assign(created, {
createTag: function createTag() {
return _this2.createTag(meta.id);
},
toString: function toString() {
return _this2.createTag(meta.id).render();
}
});
}
}, {
key: 'createTag',
value: function createTag(id) {
return new this.root.classes.ComponentTag(this, id);
}
}, {
key: 'createUid',
value: function createUid() {
return _utils2.default.buildUid();
}
}]);
return SepConClass;
}();
var _sepCon = function sepConHandler() {
var sepCon = new SepConClass();
sepCon.createScope = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
options.hash = options.hash || _utils2.default.buildUid();
return new SepConClass(options);
};
return sepCon;
}();
exports.SepCon = _sepCon;
exports.default = _sepCon;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _constants = __webpack_require__(2);
var internalCounterForUids = 0;
exports.default = {
/**
* get a deep cloned + extended (if 'to' argument is set) object
* @param from
* @param to
* @returns {object}
*/
clone: function clone(from, to) {
if (from === null || (typeof from === 'undefined' ? 'undefined' : _typeof(from)) != "object") return from;
if (from.constructor != Object && from.constructor != Array) return from;
if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function || from.constructor == String || from.constructor == Number || from.constructor == Boolean) return new from.constructor(from);
to = to || new from.constructor();
for (var name in from) {
to[name] = typeof to[name] == 'undefined' ? this.clone(from[name], null) : to[name];
}
return to;
},
extend: function extend(base, _extend) {
var res = this.clone(base);
if (!res) {
res = {};
}
for (var i in _extend) {
if (res.hasOwnProperty(i)) {
if (_typeof(_extend[i]) === 'object') {
res[i] = this.extend(base[i], _extend[i]);
} else {
res[i] = _extend[i];
}
} else {
res[i] = _extend[i];
}
}
return res;
},
concatMethods: function concatMethods(meth1, meth2) {
return function () {
meth1.apply(this, arguments);
return meth2.apply(this, arguments);
};
},
buildUid: function buildUid() {
return parseInt((Date.now() + internalCounterForUids++) * 1000 + Math.round(Math.random() * 1000)).toString(36);
},
formatValueForValidJSON: function formatValueForValidJSON(obj) {
if (obj === 0) return 0;
if (obj === undefined) return null;
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
if (obj instanceof Array) {
for (var i = 0, e = obj.length; i < e; i++) {
obj[i] = this.formatValueForValidJSON(obj[i]);
}
} else {
for (var key in obj) {
obj[key] = this.formatValueForValidJSON(obj[key]);
}
}
}
return obj;
},
//Component Functions
isInDOM: function isInDOM(element) {
if (!element) return false;
return document.body.contains(element);
},
isDeepNestedInSameComponent: function isDeepNestedInSameComponent(element) {
var path = this.getComponentElementsPath(element, true, true);
for (var i = 0, e = path.length - 1; i < e; i++) {
if (path[i] === element.tagName) return true;
}
return false;
},
getParentComponentElement: function getParentComponentElement(element) {
var child = element;
var parent = void 0;
do {
parent = child.parentNode;
if (!parent) break;
if (parent._componentElement || parent.tagName.toLowerCase().indexOf(_constants.TAG_PREFIX) === 0) {
return parent;
}
child = parent;
} while (parent.tagName.toLowerCase() != 'body');
return false;
},
getComponentElementNameForPath: function getComponentElementNameForPath(element) {
var id = element.getAttribute(_constants.TAG_IDENTIFIER) || null;
if (!id) {
var siblings = this.getComponentElementSiblings(element);
var siblingsIndex = this.getComponentElementIndex(element, siblings);
id = '(' + siblingsIndex + ')';
}
return element.tagName + ' ' + id;
},
getComponentElementsPath: function getComponentElementsPath(element, typesOnly, asArray) {
var child = element;
var parent = void 0;
var path = [];
do {
parent = this.getParentComponentElement(child);
if (!typesOnly && parent.tagName) {
path.push(this.getComponentElementNameForPath(parent));
} else if (parent.tagName) {
path.push(parent.tagName);
}
child = parent;
} while (parent);
path.reverse();
if (!typesOnly) {
path.push(this.getComponentElementNameForPath(element));
} else {
path.push(element.tagName);
}
if (asArray) return path;
return path.join('>');
},
getComponentElementSiblings: function getComponentElementSiblings(element) {
var _this = this;
var parent = this.getParentComponentElement(element);
var siblings = parent ? Array.from(parent.getElementsByTagName(element.tagName)) : [];
if (siblings.length > 1) {
siblings = siblings.filter(function (node) {
if (node._componentElement && node._componentElement.parent === parent) return true;
return _this.getParentComponentElement(node) === parent;
});
}
return siblings;
},
getComponentElementIndex: function getComponentElementIndex(element, siblings) {
for (var i = 0, e = siblings.length; i < e; i++) {
if (siblings[i] === element) return i;
}
return 0;
},
getComponent: function getComponent(list, element) {
if (element.component && element.component.mapItem) return element.component.mapItem;
var path = element._componentElement.path;
for (var i = 0, e = list.length; i < e; i++) {
var _item = list[i];
if (_item && (_item.element === element || _item.path === path)) {
element.component = _item.element.component;
_item.setElement(element);
return _item;
}
}
return false;
},
getLooseComponent: function getLooseComponent(list, element) {
var tagName = element.tagName;
var id = element.getAttribute(_constants.TAG_IDENTIFIER);
var sameTagList = list.filter(function (_item) {
return _item && _item.tag === tagName;
});
if (id && tagName) {
for (var i = 0, e = sameTagList.length; i < e; i++) {
var _item = sameTagList[i];
var isSameIdentifier = _item.id === id;
var isSameTag = _item.tag === tagName;
if (isSameTag && isSameIdentifier) {
element.component = _item.element.component;
_item.setElement(element);
return _item;
}
}
}
return this.getComponent(sameTagList, element);
},
getCookie: function getCookie(key) {
return document.cookie.split(';').forEach(function (cookie) {
var cookiePair = cookie.split('=');
if (cookiePair[0] === key) {
return cookiePair[1];
}
});
},
setCookie: function setCookie(key, value) {
document.cookie = key + '=' + value + ';path=/';
}
};
/***/ }),
/* 2 */
/***/ (function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
//component element tag creation
var TAG_PREFIX = exports.TAG_PREFIX = 'x-sepcon-';
var TAG_PROPERTIES = exports.TAG_PROPERTIES = 'data-properties';
var TAG_METHODS = exports.TAG_METHODS = 'data-methods';
var TAG_IDENTIFIER = exports.TAG_IDENTIFIER = 'data-identifier';
//web worker events
var ADD_COMPONENT_DEFINITION = exports.ADD_COMPONENT_DEFINITION = 'add-component-definition';
var ADD_COMPONENT = exports.ADD_COMPONENT = 'add-component';
var DATA_CHANGED = exports.DATA_CHANGED = 'data-changed';
var DATA_CHANGES_AFFECTING = exports.DATA_CHANGES_AFFECTING = 'data-changes-affecting';
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _utils = __webpack_require__(1);
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var references = new Map();
var keys = {};
var ReferenceMap = {
add: function add(val) {
if (references.has(val)) {
return references.get(val);
} else {
var key = _utils2.default.buildUid();
references.set(val, key);
keys[key] = val;
return key;
}
},
get: function get(key) {
if (keys[key] !== undefined) {
return keys[key];
}
return null;
}
};
exports.default = ReferenceMap;
/***/ }),
/* 4 */
/***/ (function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = {
setChanges: function setChanges(source, map, change, isShallow, path, parent, parentKey) {
if (!source) {
source = {};
}
if (!map) {
map = {};
}
var changedProps = {};
for (var prop in map) {
var isSourceObject = _typeof(source[prop]) === 'object' && source[prop] !== null;
var isMapObject = _typeof(map[prop]) === 'object' && map[prop] !== null;
var isDifferent = false;
if (isSourceObject || isMapObject) {
var flatSource = source[prop] ? JSON.stringify(source[prop]) : '';
var flatMap = map[prop] ? JSON.stringify(map[prop]) : '';
isDifferent = flatSource !== flatMap;
if (isDifferent) {
if (isShallow) {
changedProps[prop] = this.getChangedAsObject(source[prop], map[prop]);
} else {
var propPath = path ? path + '.' + prop : prop;
changedProps[propPath] = this.getChangedAsObject(source[prop], map[prop]);
var changedObject = this.setChanges(source[prop], map[prop], isSourceObject && change, isShallow, propPath, source, prop);
if (Object.keys(changedObject).length > 0) {
Object.assign(changedProps, changedObject);
}
}
}
} else {
isDifferent = source[prop] != map[prop];
if (isDifferent) {
var _propPath = path ? path + '.' + prop : prop;
var clonedNewValue = map[prop] ? JSON.parse(JSON.stringify(map[prop])) : map[prop];
var clonedOldValue = source[prop] ? JSON.parse(JSON.stringify(source[prop])) : source[prop];
changedProps[_propPath] = this.getChangedAsObject(clonedOldValue, clonedNewValue);
}
}
if (isDifferent && change) {
if (parent) {
if (!parent[parentKey]) {
parent[parentKey] = map;
}
parent[parentKey][prop] = map[prop];
} else {
source[prop] = map[prop];
}
}
}
return changedProps;
},
getChangedAsObject: function getChangedAsObject(oldValue, newValue) {
return {
oldValue: typeof oldValue !== 'undefined' ? JSON.parse(JSON.stringify(oldValue)) : null,
newValue: typeof newValue !== 'undefined' ? JSON.parse(JSON.stringify(newValue)) : null
};
}
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
__webpack_require__(22);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Logs = function () {
function Logs(config) {
_classCallCheck(this, Logs);
this.active = true;
}
_createClass(Logs, [{
key: 'setActive',
value: function setActive(active) {
this.active = active;
return this;
}
}, {
key: 'print',
value: function print(data) {
var _this = this;
if (!this.active) return false;
if (data.content) {
this.executeConsole(data);
}
if (data.title) {
data.title.style = 'title';
data.title.type = 'groupCollapsed';
this.executeConsole(data.title);
}
data.rows.forEach(function (row) {
return _this.executeConsole(row);
});
if (data.title) {
data.title.type = 'groupEnd';
this.executeConsole(data.title);
}
}
}, {
key: 'getStyle',
value: function getStyle(stl) {
switch (stl) {
case 'title':
return 'font-weight: bold; color: black; background: #f0f0f0; line-height: 1.2em; padding: .1em .2em';
case 'label':
return 'color: white; background: #aaaaaa; border-bottom: solid 0.2em #999999; line-height: 1.4em; padding: .1em .2em';
case 'code':
return 'font-style: italic; background: #f5f5f5; line-height: 1.2em; padding: .1em 0 .1em';
case 'info':
return 'line-height: 1.4em; padding: .1em .2em';
}
return stl;
}
}, {
key: 'executeConsole',
value: function executeConsole(row) {
row.type = row.type || 'log';
if (_typeof(row.content) === 'object' && row.content !== null && !(row.content instanceof Element)) {
row.content = JSON.stringify(row.content, null, 2);
}
if (row.style) {
row.style = this.getStyle(row.style);
console[row.type]('%c%s', row.style, row.content);
} else {
console[row.type](row.content);
}
}
}]);
return Logs;
}();
exports.default = Logs;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _utils = __webpack_require__(1);
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _class = function () {
function _class(base, config) {
_classCallCheck(this, _class);
this.base = base;
//this.state = comp.state;
this.config = config;
}
_createClass(_class, [{
key: 'startSequence',
value: function startSequence() {
var _this = this;
var sequence = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'mount';
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var seq = this.config[sequence];
var promise = Promise;
return new Promise(function (resolve, reject) {
if (_this.handleSequenceStep('pre', seq, params)) {
promise.resolve().then(function () {
if (_this.handleSequenceStep(false, seq, params)) {
window.requestAnimationFrame(function () {
_this.handleSequenceStep('post', seq, params);
resolve();
});
} else {
resolve();
}
});
} else {
resolve();
}
});
}
}, {
key: 'handleSequenceStep',
value: function handleSequenceStep(hook, seq, params) {
for (var i = 0, e = seq.sequence.length; i < e; i++) {
var sequenceStep = seq.sequence[i];
params = this.getStepParams(sequenceStep, hook, seq, params);
var target = void 0;
switch (sequenceStep.target) {
default:
target = this.base.scoped;
break;
case 'state':
target = this.base.state.scoped;
break;
}
//let target = sequenceStep.target === 'state' ? this.state.scoped : this.component.scoped;
// const actionHook = common.hookString(hook, sequenceStep.action);
var hasLifecycle = !!target.lifecycle;
var action = false;
if (hasLifecycle) {
var hookKey = hook || 'on';
var hasHook = !!target.lifecycle[hookKey];
if (hasHook) {
action = target.lifecycle[hookKey][sequenceStep.action];
}
if (!action && !hook) {
action = target.lifecycle[sequenceStep.action];
}
}
if (action) {
var res = action.apply(target, params);
if (res === false) {
return false;
}
this.handleStepResponse(sequenceStep, hook, seq, res);
} else {
this.handleStepResponse(sequenceStep, hook, seq);
}
}
return true;
}
}, {
key: 'getStepParams',
value: function getStepParams(step, hook, seq, params) {
if (seq.send) {
return seq.send.apply(this, [step, hook, params]);
} else return params;
}
}, {
key: 'handleStepResponse',
value: function handleStepResponse(step, hook, seq, res) {
if (seq.retrieve) {
return seq.retrieve.apply(this, [step, hook, res]);
} else {
return res;
}
}
}]);
return _class;
}();
exports.default = _class;
/***/ }),
/* 7 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
formatGlobals: function formatGlobals(global) {
var globals = {};
if (!global) return globals;
for (var _prop in global) {
var prop = global[_prop];
var data = prop.data; //data
var key = prop.key || true; //key
if (!globals[data]) {
globals[data] = [];
}
globals[data].push(key);
}
return globals;
},
isGlobalChanged: function isGlobalChanged(global, data, changed) {
if (global && global[data]) {
if (global[data].indexOf(true) >= 0) {
return true;
}
for (var i = 0, e = changed.length; i < e; i++) {
if (global[data].indexOf(changed[i]) >= 0) {
return true;
}
}
}
return false;
}
};
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _utils = __webpack_require__(1);
var _utils2 = _interopRequireDefault(_utils);
__webpack_require__(23);
var _constants = __webpack_require__(2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//defining the component and registering its element
var ComponentDefinition = function () {
function ComponentDefinition(meta, def, root) {
_classCallCheck(this, ComponentDefinition);
var definition = {
state: def.state || {},
view: def.view || {}
};
if (meta.extend) {
definition = _utils2.default.extend(meta.extend, definition);
}
this.definition = definition;
this.id = meta.id;
this.root = root;
this.tag = _constants.TAG_PREFIX + (this.root.hash ? this.root.hash + '-' : '') + meta.id;
if (meta.decorators && meta.decorators.length && meta.decorators.length > 0) {
meta.decorators.forEach(this.addDecorator.bind(this));
}
this.root.addComponentDefinition(this);
this.registerElement();
return this;
}
_createClass(ComponentDefinition, [{
key: 'addDecorator',
value: function addDecorator(decorator) {
if (decorator.state) {
if (!this.definition.state) {
this.definition.state = {};
}
this.addDecoratorToState(decorator);
}
this.addDecoratorToComponent(decorator);
}
}, {
key: 'addDecoratorToState',
value: function addDecoratorToState(decorator) {
var _this = this;
var segs = ['local', 'external', 'global'];
if (decorator.state.props) {
segs.forEach(function (seg) {
if (decorator.state.props[seg]) {
_this.addToStateSegregation(decorator.state.props[seg], 'props', seg);
}
});
decorator.state.props = null;
}
if (decorator.state.methods) {
if (!this.definition.state.methods) {
this.definition.state.methods = {};
}
segs.forEach(function (seg) {
if (decorator.state.methods[seg]) {
_this.addToStateSegregation(decorator.state.methods[seg], 'methods', seg);
}
});
decorator.state.methods = null;
}
if (decorator.state.routes) {
this.addToStateRoutes(decorator.state.routes);
decorator.state.routes = null;
}
this.addToState(decorator.state);
decorator.state = null;
}
}, {
key: 'addToStateSegregation',
value: function addToStateSegregation(map, key, seg) {
if (!this.definition.state[key]) {
this.definition.state[key] = {};
}
if (!this.definition.state[key][seg]) {
this.definition.state[key][seg] = {};
}
for (var prop in map) {
if (!this.definition.state[key][seg][prop]) {
this.definition.state[key][seg][prop] = map[prop];
} else if (key === 'methods' && (seg === 'local' || seg === 'eternal')) {
this.definition.state[key][seg][prop] = _utils2.default.concatMethods(map[prop], this.definition.state[key][seg][prop]);
}
}
}
}, {
key: 'addToStateRoutes',
value: function addToStateRoutes(routes) {
if (!this.definition.state.routes || this.definition.state.routes.length === 0) {
this.definition.state.routes = routes;
} else {
this.definition.state.routes = this.definition.state.routes.concat(routes);
}
}
}, {
key: 'addToState',
value: function addToState(map) {
for (var prop in map) {
if (!this.definition.state[prop]) {
this.definition.state[prop] = map[prop];
} else {
if (typeof map[prop] === 'function') {
this.definition.state[prop] = _utils2.default.concatMethods(map[prop], this.definition.state[prop]);