neo.mjs 5.13.10 → 5.14.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.
- package/apps/ServiceWorker.mjs +2 -2
- package/examples/ServiceWorker.mjs +2 -2
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +2 -2
- package/src/controller/Application.mjs +23 -9
- package/src/main/DomEvents.mjs +46 -48
- package/src/util/Logger.mjs +134 -150
- package/src/worker/App.mjs +31 -39
package/apps/ServiceWorker.mjs
CHANGED
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -245,12 +245,12 @@ const DefaultConfig = {
|
|
245
245
|
useVdomWorker: true,
|
246
246
|
/**
|
247
247
|
* buildScripts/injectPackageVersion.mjs will update this value
|
248
|
-
* @default '5.
|
248
|
+
* @default '5.14.0'
|
249
249
|
* @memberOf! module:Neo
|
250
250
|
* @name config.version
|
251
251
|
* @type String
|
252
252
|
*/
|
253
|
-
version: '5.
|
253
|
+
version: '5.14.0'
|
254
254
|
};
|
255
255
|
|
256
256
|
Object.assign(DefaultConfig, {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import Base from './Base.mjs';
|
2
2
|
import ClassSystemUtil from '../util/ClassSystem.mjs';
|
3
|
+
import Logger from '../util/Logger.mjs';
|
3
4
|
|
4
5
|
/**
|
5
6
|
* @class Neo.controller.Application
|
@@ -72,7 +73,7 @@ class Application extends Base {
|
|
72
73
|
Neo.currentWorker.registerApp(me.name);
|
73
74
|
|
74
75
|
if (mainView) {
|
75
|
-
me.mainView = mainView
|
76
|
+
me.mainView = mainView
|
76
77
|
}
|
77
78
|
}
|
78
79
|
|
@@ -82,11 +83,17 @@ class Application extends Base {
|
|
82
83
|
* @param {Neo.component.Base|null} oldValue
|
83
84
|
* @protected
|
84
85
|
*/
|
85
|
-
afterSetMainView(value, oldValue) {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
async afterSetMainView(value, oldValue) {
|
87
|
+
if (value) {
|
88
|
+
let me = this;
|
89
|
+
|
90
|
+
// short delay to ensure changes from onHashChange() got applied
|
91
|
+
await Neo.timeout(Neo.config.hash ? 200 : 10);
|
92
|
+
|
93
|
+
value.on('mounted', me.registerLoggerClickEvent, me);
|
94
|
+
|
95
|
+
value.render(true)
|
96
|
+
}
|
90
97
|
}
|
91
98
|
|
92
99
|
/**
|
@@ -101,10 +108,10 @@ class Application extends Base {
|
|
101
108
|
return ClassSystemUtil.beforeSetInstance(value, null, {
|
102
109
|
appName : this.name,
|
103
110
|
parentId: this.parentId
|
104
|
-
})
|
111
|
+
})
|
105
112
|
}
|
106
113
|
|
107
|
-
return null
|
114
|
+
return null
|
108
115
|
}
|
109
116
|
|
110
117
|
/**
|
@@ -113,7 +120,14 @@ class Application extends Base {
|
|
113
120
|
*/
|
114
121
|
destroy(...args) {
|
115
122
|
Neo.currentWorker.removeAppFromThemeMap(this.name);
|
116
|
-
super.destroy(...args)
|
123
|
+
super.destroy(...args)
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @protected
|
128
|
+
*/
|
129
|
+
registerLoggerClickEvent() {
|
130
|
+
Logger.addContextMenuListener(this.mainView)
|
117
131
|
}
|
118
132
|
}
|
119
133
|
|
package/src/main/DomEvents.mjs
CHANGED
@@ -121,7 +121,7 @@ class DomEvents extends Base {
|
|
121
121
|
window .addEventListener('hashchange', me.onHashChange .bind(me));
|
122
122
|
|
123
123
|
if (Neo.config.useSharedWorkers) {
|
124
|
-
window.addEventListener('beforeunload', me.onBeforeUnload.bind(me))
|
124
|
+
window.addEventListener('beforeunload', me.onBeforeUnload.bind(me))
|
125
125
|
}
|
126
126
|
}
|
127
127
|
|
@@ -138,17 +138,17 @@ class DomEvents extends Base {
|
|
138
138
|
event = data.events[i];
|
139
139
|
|
140
140
|
if (!me[event.handler]) {
|
141
|
-
me[event.handler] = Neo.emptyFn
|
141
|
+
me[event.handler] = Neo.emptyFn
|
142
142
|
}
|
143
143
|
|
144
144
|
id = event.vnodeId || data.vnodeId;
|
145
145
|
|
146
146
|
if (id === 'document.body') {
|
147
|
-
targetNode = document.body
|
147
|
+
targetNode = document.body
|
148
148
|
} else if (Neo.config.useDomIds) {
|
149
|
-
targetNode = document.getElementById(id)
|
149
|
+
targetNode = document.getElementById(id)
|
150
150
|
} else {
|
151
|
-
targetNode = document.querySelector(`[data-neo-id='${id}']`)
|
151
|
+
targetNode = document.querySelector(`[data-neo-id='${id}']`)
|
152
152
|
}
|
153
153
|
|
154
154
|
targetNode.addEventListener(event.name, me[event.handler].bind(me));
|
@@ -159,7 +159,7 @@ class DomEvents extends Base {
|
|
159
159
|
data,
|
160
160
|
replyId: data.id,
|
161
161
|
success: true
|
162
|
-
})
|
162
|
+
})
|
163
163
|
}
|
164
164
|
|
165
165
|
/**
|
@@ -169,7 +169,7 @@ class DomEvents extends Base {
|
|
169
169
|
let me = this;
|
170
170
|
|
171
171
|
[...globalDomEvents].concat(Neo.config.useTouchEvents ? touchEvents : []).forEach(event => {
|
172
|
-
document.body.addEventListener(event.name, me[event.handler].bind(me), event.options)
|
172
|
+
document.body.addEventListener(event.name, me[event.handler].bind(me), event.options)
|
173
173
|
});
|
174
174
|
}
|
175
175
|
|
@@ -233,7 +233,7 @@ class DomEvents extends Base {
|
|
233
233
|
break;
|
234
234
|
}
|
235
235
|
|
236
|
-
Neo.worker.Manager.sendMessage('app', config)
|
236
|
+
Neo.worker.Manager.sendMessage('app', config)
|
237
237
|
}
|
238
238
|
|
239
239
|
/**
|
@@ -323,11 +323,11 @@ class DomEvents extends Base {
|
|
323
323
|
|
324
324
|
while (element.parentNode) {
|
325
325
|
path.push(element.parentNode);
|
326
|
-
element = element.parentNode
|
326
|
+
element = element.parentNode
|
327
327
|
}
|
328
328
|
}
|
329
329
|
|
330
|
-
return path
|
330
|
+
return path
|
331
331
|
}
|
332
332
|
|
333
333
|
/**
|
@@ -388,8 +388,8 @@ class DomEvents extends Base {
|
|
388
388
|
* @returns {Touch}
|
389
389
|
*/
|
390
390
|
getTouchCoords(event) {
|
391
|
-
|
392
|
-
return touches?.[0] || changedTouches?.[0]
|
391
|
+
let {touches, changedTouches} = event;
|
392
|
+
return touches?.[0] || changedTouches?.[0]
|
393
393
|
}
|
394
394
|
|
395
395
|
/**
|
@@ -400,10 +400,7 @@ class DomEvents extends Base {
|
|
400
400
|
let manager = Neo.worker.Manager;
|
401
401
|
|
402
402
|
manager.appNames.forEach(appName => {
|
403
|
-
manager.broadcast({
|
404
|
-
action : 'disconnect',
|
405
|
-
appName
|
406
|
-
});
|
403
|
+
manager.broadcast({action : 'disconnect', appName})
|
407
404
|
})
|
408
405
|
}
|
409
406
|
|
@@ -424,10 +421,10 @@ class DomEvents extends Base {
|
|
424
421
|
|
425
422
|
// input and change events can pass a FileList for input type file
|
426
423
|
if (target.files) {
|
427
|
-
data.files = target.files
|
424
|
+
data.files = target.files
|
428
425
|
}
|
429
426
|
|
430
|
-
me.sendMessageToApp(data)
|
427
|
+
me.sendMessageToApp(data)
|
431
428
|
}
|
432
429
|
|
433
430
|
/**
|
@@ -438,7 +435,7 @@ class DomEvents extends Base {
|
|
438
435
|
|
439
436
|
me.sendMessageToApp(me.getMouseEventData(event));
|
440
437
|
|
441
|
-
me.testPathInclusion(event, preventClickTargets) && event.preventDefault()
|
438
|
+
me.testPathInclusion(event, preventClickTargets) && event.preventDefault()
|
442
439
|
}
|
443
440
|
|
444
441
|
/**
|
@@ -449,7 +446,9 @@ class DomEvents extends Base {
|
|
449
446
|
|
450
447
|
me.sendMessageToApp(me.getMouseEventData(event));
|
451
448
|
|
452
|
-
me.testPathInclusion(event, preventContextmenuTargets)
|
449
|
+
if (event.ctrlKey || me.testPathInclusion(event, preventContextmenuTargets)) {
|
450
|
+
event.preventDefault()
|
451
|
+
}
|
453
452
|
}
|
454
453
|
|
455
454
|
/**
|
@@ -457,7 +456,7 @@ class DomEvents extends Base {
|
|
457
456
|
*/
|
458
457
|
onDomContentLoaded() {
|
459
458
|
this.addGlobalDomListeners();
|
460
|
-
this.fire('domContentLoaded')
|
459
|
+
this.fire('domContentLoaded')
|
461
460
|
}
|
462
461
|
|
463
462
|
/**
|
@@ -468,29 +467,28 @@ class DomEvents extends Base {
|
|
468
467
|
|
469
468
|
me.sendMessageToApp(me.getMouseEventData(event));
|
470
469
|
|
471
|
-
me.testPathInclusion(event, preventClickTargets) && event.preventDefault()
|
470
|
+
me.testPathInclusion(event, preventClickTargets) && event.preventDefault()
|
472
471
|
}
|
473
472
|
|
474
473
|
/**
|
475
474
|
* @param {Object} event
|
476
475
|
*/
|
477
476
|
onDragOver(event) {
|
478
|
-
event.dataTransfer.dropEffect = 'move'
|
479
|
-
//console.log('onDragOver', event);
|
477
|
+
event.dataTransfer.dropEffect = 'move'
|
480
478
|
}
|
481
479
|
|
482
480
|
/**
|
483
481
|
* @param {Object} event
|
484
482
|
*/
|
485
483
|
onFocusIn(event) {
|
486
|
-
this.sendMessageToApp(this.getEventData(event))
|
484
|
+
this.sendMessageToApp(this.getEventData(event))
|
487
485
|
}
|
488
486
|
|
489
487
|
/**
|
490
488
|
* @param {Object} event
|
491
489
|
*/
|
492
490
|
onFocusOut(event) {
|
493
|
-
this.sendMessageToApp(this.getEventData(event))
|
491
|
+
this.sendMessageToApp(this.getEventData(event))
|
494
492
|
}
|
495
493
|
|
496
494
|
/**
|
@@ -507,7 +505,7 @@ class DomEvents extends Base {
|
|
507
505
|
hash : this.parseHash(hashString),
|
508
506
|
hashString
|
509
507
|
}
|
510
|
-
})
|
508
|
+
})
|
511
509
|
}
|
512
510
|
|
513
511
|
/**
|
@@ -519,13 +517,13 @@ class DomEvents extends Base {
|
|
519
517
|
isInput = tagName === 'INPUT' || tagName === 'TEXTAREA';
|
520
518
|
|
521
519
|
if (isInput && disabledInputKeys[target.id]?.includes(event.key)) {
|
522
|
-
event.preventDefault()
|
520
|
+
event.preventDefault()
|
523
521
|
} else {
|
524
522
|
this.sendMessageToApp(this.getKeyboardEventData(event));
|
525
523
|
|
526
524
|
if (!isInput) { // see: https://github.com/neomjs/neo/issues/1729
|
527
525
|
if (['ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp'].includes(event.key)) {
|
528
|
-
event.preventDefault()
|
526
|
+
event.preventDefault()
|
529
527
|
}
|
530
528
|
}
|
531
529
|
}
|
@@ -535,14 +533,14 @@ class DomEvents extends Base {
|
|
535
533
|
* @param {Object} event
|
536
534
|
*/
|
537
535
|
onKeyUp(event) {
|
538
|
-
this.sendMessageToApp(this.getKeyboardEventData(event))
|
536
|
+
this.sendMessageToApp(this.getKeyboardEventData(event))
|
539
537
|
}
|
540
538
|
|
541
539
|
/**
|
542
540
|
* @param {Object} event
|
543
541
|
*/
|
544
542
|
onMouseDown(event) {
|
545
|
-
this.sendMessageToApp(this.getMouseEventData(event))
|
543
|
+
this.sendMessageToApp(this.getMouseEventData(event))
|
546
544
|
}
|
547
545
|
|
548
546
|
/**
|
@@ -553,7 +551,7 @@ class DomEvents extends Base {
|
|
553
551
|
appEvent = {...me.getMouseEventData(event), fromElementId: event.fromElement?.id || null};
|
554
552
|
|
555
553
|
me.sendMessageToApp(appEvent);
|
556
|
-
me.fire('mouseEnter', appEvent)
|
554
|
+
me.fire('mouseEnter', appEvent)
|
557
555
|
}
|
558
556
|
|
559
557
|
/**
|
@@ -564,14 +562,14 @@ class DomEvents extends Base {
|
|
564
562
|
appEvent = {...me.getMouseEventData(event), toElementId: event.toElement?.id || null};
|
565
563
|
|
566
564
|
me.sendMessageToApp(appEvent);
|
567
|
-
me.fire('mouseLeave', appEvent)
|
565
|
+
me.fire('mouseLeave', appEvent)
|
568
566
|
}
|
569
567
|
|
570
568
|
/**
|
571
569
|
* @param {Object} event
|
572
570
|
*/
|
573
571
|
onMouseUp(event) {
|
574
|
-
this.sendMessageToApp(this.getMouseEventData(event))
|
572
|
+
this.sendMessageToApp(this.getMouseEventData(event))
|
575
573
|
}
|
576
574
|
|
577
575
|
/**
|
@@ -589,12 +587,12 @@ class DomEvents extends Base {
|
|
589
587
|
let date = new Date();
|
590
588
|
|
591
589
|
if (lastWheelEvent.date && lastWheelEvent.target === targetCls && date - lastWheelEvent.date < globalWheelTargetsBuffer[targetCls]) {
|
592
|
-
preventUpdate = true
|
590
|
+
preventUpdate = true
|
593
591
|
} else {
|
594
592
|
Object.assign(lastWheelEvent, {
|
595
593
|
date,
|
596
594
|
target: targetCls
|
597
|
-
})
|
595
|
+
})
|
598
596
|
}
|
599
597
|
}
|
600
598
|
|
@@ -610,11 +608,11 @@ class DomEvents extends Base {
|
|
610
608
|
deltaZ,
|
611
609
|
scrollLeft : target.node.scrollLeft,
|
612
610
|
scrollTop : target.node.scrollTop
|
613
|
-
})
|
611
|
+
})
|
614
612
|
}
|
615
613
|
|
616
614
|
if (!globalWheelTargetsKeepEvent.includes(targetCls)) {
|
617
|
-
event.preventDefault()
|
615
|
+
event.preventDefault()
|
618
616
|
}
|
619
617
|
}
|
620
618
|
}
|
@@ -626,7 +624,7 @@ class DomEvents extends Base {
|
|
626
624
|
*/
|
627
625
|
parseHash(str) {
|
628
626
|
if (str === '') {
|
629
|
-
return {}
|
627
|
+
return {}
|
630
628
|
}
|
631
629
|
|
632
630
|
let pieces = str.split('&'),
|
@@ -637,7 +635,7 @@ class DomEvents extends Base {
|
|
637
635
|
parts = pieces[i].split('=');
|
638
636
|
|
639
637
|
if (parts.length < 2) {
|
640
|
-
parts.push('')
|
638
|
+
parts.push('')
|
641
639
|
}
|
642
640
|
|
643
641
|
key = decodeURIComponent(parts[0]);
|
@@ -650,13 +648,13 @@ class DomEvents extends Base {
|
|
650
648
|
data[key] = [];
|
651
649
|
}
|
652
650
|
|
653
|
-
data[key].push(this.parseValue(value))
|
651
|
+
data[key].push(this.parseValue(value))
|
654
652
|
} else {
|
655
|
-
data[key] = this.parseValue(value)
|
653
|
+
data[key] = this.parseValue(value)
|
656
654
|
}
|
657
655
|
}
|
658
656
|
|
659
|
-
return data
|
657
|
+
return data
|
660
658
|
}
|
661
659
|
|
662
660
|
/**
|
@@ -667,11 +665,11 @@ class DomEvents extends Base {
|
|
667
665
|
*/
|
668
666
|
parseValue(value) {
|
669
667
|
if (value == parseInt(value)) {
|
670
|
-
value = parseInt(value)
|
668
|
+
value = parseInt(value)
|
671
669
|
} else if (value === 'false') {
|
672
|
-
value = false
|
670
|
+
value = false
|
673
671
|
} else if (value === 'true') {
|
674
|
-
value = true
|
672
|
+
value = true
|
675
673
|
}
|
676
674
|
|
677
675
|
return value
|
@@ -708,7 +706,7 @@ class DomEvents extends Base {
|
|
708
706
|
}
|
709
707
|
|
710
708
|
data.cls.forEach(cls => {
|
711
|
-
!preventArray.includes(cls) && preventArray.push(cls)
|
709
|
+
!preventArray.includes(cls) && preventArray.push(cls)
|
712
710
|
});
|
713
711
|
}
|
714
712
|
|
@@ -733,7 +731,7 @@ class DomEvents extends Base {
|
|
733
731
|
stripHtml(value) {
|
734
732
|
let doc = new DOMParser().parseFromString(value, 'text/html');
|
735
733
|
|
736
|
-
return doc.body.textContent || ''
|
734
|
+
return doc.body.textContent || ''
|
737
735
|
}
|
738
736
|
|
739
737
|
/**
|
package/src/util/Logger.mjs
CHANGED
@@ -6,38 +6,6 @@ import Base from '../core/Base.mjs';
|
|
6
6
|
* @singleton
|
7
7
|
*/
|
8
8
|
class Logger extends Base {
|
9
|
-
/**
|
10
|
-
* Colors
|
11
|
-
* @property {Object} colors
|
12
|
-
*/
|
13
|
-
logColors = {
|
14
|
-
error: 'indianred',
|
15
|
-
info : '#acacac',
|
16
|
-
log : '#448888',
|
17
|
-
warn : '#6d6d00'
|
18
|
-
}
|
19
|
-
/**
|
20
|
-
* Character
|
21
|
-
* @property {Object} logChar
|
22
|
-
*/
|
23
|
-
logChars = {
|
24
|
-
error: 'E',
|
25
|
-
info : 'I',
|
26
|
-
log : 'L',
|
27
|
-
warn : 'W'
|
28
|
-
}
|
29
|
-
/**
|
30
|
-
* LogLevels
|
31
|
-
* @property {String[]} logLevels
|
32
|
-
*/
|
33
|
-
logLevels = ['info', 'log', 'warn', 'error']
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Timeout
|
37
|
-
* @property {Number} timeToStart in ms
|
38
|
-
*/
|
39
|
-
timeToStartComponentLogger = 1500
|
40
|
-
|
41
9
|
static config = {
|
42
10
|
/**
|
43
11
|
* @member {String} className='Neo.util.Logger'
|
@@ -73,19 +41,43 @@ class Logger extends Base {
|
|
73
41
|
*/
|
74
42
|
level_: 'info',
|
75
43
|
/**
|
76
|
-
* @member {
|
44
|
+
* @member {Boolean} enableLogs=true
|
77
45
|
* @protected
|
78
46
|
*/
|
79
47
|
singleton: true
|
80
48
|
}
|
81
49
|
|
50
|
+
/**
|
51
|
+
* @member {Object} logChar
|
52
|
+
*/
|
53
|
+
logChars = {
|
54
|
+
error: 'E',
|
55
|
+
info : 'I',
|
56
|
+
log : 'L',
|
57
|
+
warn : 'W'
|
58
|
+
}
|
59
|
+
/**
|
60
|
+
* @member {Object} colors
|
61
|
+
*/
|
62
|
+
logColors = {
|
63
|
+
error: 'indianred',
|
64
|
+
info : '#acacac',
|
65
|
+
log : '#448888',
|
66
|
+
warn : '#6d6d00'
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* LogLevels
|
70
|
+
* @member {String[]} logLevels
|
71
|
+
*/
|
72
|
+
logLevels = ['info', 'log', 'warn', 'error']
|
73
|
+
|
82
74
|
/**
|
83
75
|
* @param config
|
84
76
|
*/
|
85
77
|
construct(config) {
|
86
78
|
super.construct(config);
|
87
79
|
|
88
|
-
|
80
|
+
let me = this;
|
89
81
|
|
90
82
|
// aliases
|
91
83
|
Neo.applyFromNs(Neo, me, {
|
@@ -98,188 +90,180 @@ class Logger extends Base {
|
|
98
90
|
|
99
91
|
setTimeout(() => {
|
100
92
|
if (!me.enableLogsInProduction && Neo.config.environment === 'dist/production') {
|
101
|
-
me.write = Neo.emptyFn
|
93
|
+
me.write = Neo.emptyFn
|
102
94
|
}
|
103
|
-
}, 50)
|
95
|
+
}, 50)
|
104
96
|
}
|
105
97
|
|
106
98
|
/**
|
107
99
|
* Ctrl-Right Click will show the current component
|
108
|
-
* @param {
|
109
|
-
* @param {Boolean} oldValue
|
100
|
+
* @param {Neo.component.Base} view
|
110
101
|
*/
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
const viewport = Neo.getComponent('neo-viewport-1') || Neo.getComponent('neo-configuration-viewport-1');
|
117
|
-
if (!viewport) {
|
118
|
-
console.warn('[LOGGER] could not find viewport.');
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
|
122
|
-
viewport.addDomListeners({
|
123
|
-
contextmenu: (data) => {
|
124
|
-
if (data.ctrlKey) {
|
125
|
-
let isGroupSet = false;
|
126
|
-
|
127
|
-
data.path.forEach((item) => {
|
128
|
-
const component = Neo.getComponent(item.id);
|
129
|
-
|
130
|
-
if (component) {
|
131
|
-
if (!isGroupSet) {
|
132
|
-
isGroupSet = true;
|
133
|
-
console.group(item.id);
|
134
|
-
}
|
135
|
-
console.log(component);
|
136
|
-
}
|
137
|
-
});
|
138
|
-
|
139
|
-
if (isGroupSet) {
|
140
|
-
console.groupEnd();
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
});
|
145
|
-
}
|
146
|
-
}, this.timeToStartComponentLogger);
|
102
|
+
addContextMenuListener(view) {
|
103
|
+
view.addDomListeners({
|
104
|
+
contextmenu: this.onContextMenu
|
105
|
+
})
|
147
106
|
}
|
148
107
|
|
149
108
|
/**
|
150
109
|
* Set level to number based on position in logLevels
|
151
110
|
* @param {String} value
|
152
111
|
* @param {String|Number} oldValue
|
153
|
-
* @returns {
|
112
|
+
* @returns {Number}
|
154
113
|
*/
|
155
114
|
beforeSetLevel(value, oldValue) {
|
156
|
-
return this.logLevels.indexOf(value)
|
115
|
+
return this.logLevels.indexOf(value)
|
157
116
|
}
|
158
117
|
|
159
118
|
/**
|
160
|
-
* @param value
|
119
|
+
* @param {String} value
|
161
120
|
*/
|
162
121
|
error(value) {
|
163
|
-
throw new Error(value)
|
122
|
+
throw new Error(value)
|
164
123
|
}
|
165
124
|
|
166
125
|
/**
|
167
|
-
*
|
126
|
+
* internal helper to catch caller
|
127
|
+
* no known native way in modern JS to know what file that triggered the current method
|
128
|
+
* therefore we use Error, we can get the caller file from the stack trace string.
|
129
|
+
* @protected
|
130
|
+
* @returns {String}
|
168
131
|
*/
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
132
|
+
getCaller() {
|
133
|
+
let caller_path = undefined,
|
134
|
+
err = new Error(),
|
135
|
+
stack_lines = err.stack.split('\n'),
|
136
|
+
found_this = false,
|
137
|
+
i, line;
|
138
|
+
|
139
|
+
for (i in stack_lines) {
|
140
|
+
line = stack_lines[i];
|
141
|
+
|
142
|
+
if (!found_this && /Logger\.mjs/.test(line)) {
|
143
|
+
found_this = true
|
144
|
+
} else if (found_this) {
|
145
|
+
if (!/Logger\.mjs/.test(line)) {
|
146
|
+
// remove the closing )
|
147
|
+
line = line.replace(')', '');
|
148
|
+
// get the part after the last /
|
149
|
+
caller_path = line.match(/([^\/]+)$/)[1].match(/([^ ]+)$/)[1];
|
150
|
+
|
151
|
+
break;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
173
155
|
|
174
|
-
|
175
|
-
* @param args
|
176
|
-
*/
|
177
|
-
log(...args) {
|
178
|
-
args = this.resolveArgs(...args);
|
179
|
-
this.write(args, 'log');
|
156
|
+
return caller_path
|
180
157
|
}
|
181
158
|
|
182
159
|
/**
|
183
160
|
* @param args
|
184
161
|
*/
|
185
|
-
|
162
|
+
info(...args) {
|
186
163
|
args = this.resolveArgs(...args);
|
187
|
-
this.write(args, '
|
164
|
+
this.write(args, 'info')
|
188
165
|
}
|
189
166
|
|
190
167
|
/**
|
191
168
|
* @param args
|
192
169
|
*/
|
193
|
-
|
170
|
+
log(...args) {
|
194
171
|
args = this.resolveArgs(...args);
|
195
|
-
this.write(args, '
|
172
|
+
this.write(args, 'log')
|
196
173
|
}
|
197
174
|
|
198
175
|
/**
|
199
|
-
* Output method
|
200
176
|
* @param args
|
201
|
-
* @param {String} level
|
202
|
-
* @protected
|
203
177
|
*/
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
const logColor = me.logColors[level],
|
209
|
-
logChar = me.logChars[level],
|
210
|
-
bg = `background-color:${logColor}; color: white; font-weight: 900;`,
|
211
|
-
color = `color:${logColor};`,
|
212
|
-
msg = `[${me.getCaller()}] ${args.msg}`;
|
213
|
-
|
214
|
-
if (args.data) {
|
215
|
-
console.groupCollapsed(`%c ${logChar} %c ${msg}`, bg, color)
|
216
|
-
console.log(args.data);
|
217
|
-
console.groupEnd();
|
218
|
-
} else {
|
219
|
-
console.log(`%c ${logChar} %c ${msg}`, bg, color)
|
220
|
-
}
|
178
|
+
logError(...args) {
|
179
|
+
args = this.resolveArgs(...args);
|
180
|
+
this.write(args, 'error')
|
221
181
|
}
|
222
182
|
|
223
183
|
/**
|
224
|
-
*
|
225
|
-
* no known native way in modern JS to know what file that triggered the current method
|
226
|
-
* therefore we use Error, we can get the caller file from the stack trace string.
|
184
|
+
* @param {Object} data
|
227
185
|
*/
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
if (!found_this && /Logger\.mjs/.test(line)) {
|
242
|
-
found_this = true
|
243
|
-
|
244
|
-
} else if (found_this) {
|
245
|
-
if (!/Logger\.mjs/.test(line)) {
|
246
|
-
// remove the closing )
|
247
|
-
line = line.replace(')', '');
|
248
|
-
// get the part after the last /
|
249
|
-
caller_path = line.match(/([^\/]+)$/)[1].match(/([^ ]+)$/)[1];
|
250
|
-
|
251
|
-
break;
|
186
|
+
onContextMenu(data) {
|
187
|
+
if (data.ctrlKey) {
|
188
|
+
let isGroupSet = false,
|
189
|
+
component;
|
190
|
+
|
191
|
+
data.path.forEach(item => {
|
192
|
+
component = Neo.getComponent(item.id);
|
193
|
+
|
194
|
+
if (component) {
|
195
|
+
if (!isGroupSet) {
|
196
|
+
isGroupSet = true;
|
197
|
+
console.group(item.id)
|
252
198
|
}
|
253
|
-
}
|
254
199
|
|
255
|
-
|
200
|
+
console.log(component)
|
201
|
+
}
|
202
|
+
});
|
256
203
|
|
257
|
-
|
204
|
+
isGroupSet && console.groupEnd()
|
258
205
|
}
|
259
206
|
}
|
260
207
|
|
261
208
|
/**
|
262
|
-
*
|
209
|
+
* Internal helper for args
|
263
210
|
* @param {Array} args
|
264
|
-
* @
|
211
|
+
* @returns {Object}
|
212
|
+
* @protected
|
265
213
|
*/
|
266
214
|
resolveArgs(...args) {
|
267
215
|
const identifier = args[0];
|
268
|
-
let argsObject
|
216
|
+
let argsObject = {};
|
269
217
|
|
270
218
|
if (args.length === 1) {
|
271
219
|
if (Neo.isString(identifier)) {
|
272
|
-
argsObject.msg = args[0]
|
220
|
+
argsObject.msg = args[0]
|
273
221
|
} else if (Neo.isObject(identifier)) {
|
274
|
-
argsObject = identifier
|
222
|
+
argsObject = identifier
|
275
223
|
}
|
276
224
|
} else if (args.length === 2) {
|
277
|
-
argsObject.msg
|
278
|
-
argsObject.data = args[1]
|
225
|
+
argsObject.msg = args[0];
|
226
|
+
argsObject.data = args[1]
|
279
227
|
}
|
280
228
|
|
281
229
|
return argsObject
|
282
230
|
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* @param args
|
234
|
+
*/
|
235
|
+
warn(...args) {
|
236
|
+
args = this.resolveArgs(...args);
|
237
|
+
this.write(args, 'warn')
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Output method
|
242
|
+
* @param {Object} args
|
243
|
+
* @param {String} level
|
244
|
+
* @protected
|
245
|
+
*/
|
246
|
+
write(args, level) {
|
247
|
+
let me = this;
|
248
|
+
|
249
|
+
if (me.beforeSetLevel(level) < me.level) {
|
250
|
+
return
|
251
|
+
}
|
252
|
+
|
253
|
+
let logColor = me.logColors[level],
|
254
|
+
logChar = me.logChars[level],
|
255
|
+
bg = `background-color:${logColor}; color: white; font-weight: 900;`,
|
256
|
+
color = `color:${logColor};`,
|
257
|
+
msg = `[${me.getCaller()}] ${args.msg}`;
|
258
|
+
|
259
|
+
if (args.data) {
|
260
|
+
console.groupCollapsed(`%c ${logChar} %c ${msg}`, bg, color)
|
261
|
+
console.log(args.data);
|
262
|
+
console.groupEnd()
|
263
|
+
} else {
|
264
|
+
console.log(`%c ${logChar} %c ${msg}`, bg, color)
|
265
|
+
}
|
266
|
+
}
|
283
267
|
}
|
284
268
|
|
285
269
|
let instance = Neo.applyClassConfig(Logger);
|
package/src/worker/App.mjs
CHANGED
@@ -60,7 +60,7 @@ class App extends Base {
|
|
60
60
|
|
61
61
|
// convenience shortcuts
|
62
62
|
Neo.applyDeltas = me.applyDeltas .bind(me);
|
63
|
-
Neo.setCssVariable = me.setCssVariable.bind(me)
|
63
|
+
Neo.setCssVariable = me.setCssVariable.bind(me)
|
64
64
|
}
|
65
65
|
|
66
66
|
/**
|
@@ -69,11 +69,7 @@ class App extends Base {
|
|
69
69
|
* @returns {Promise<*>}
|
70
70
|
*/
|
71
71
|
applyDeltas(appName, deltas) {
|
72
|
-
return this.promiseMessage('main', {
|
73
|
-
action: 'updateDom',
|
74
|
-
appName,
|
75
|
-
deltas
|
76
|
-
});
|
72
|
+
return this.promiseMessage('main', {action: 'updateDom', appName, deltas})
|
77
73
|
}
|
78
74
|
|
79
75
|
/**
|
@@ -82,7 +78,7 @@ class App extends Base {
|
|
82
78
|
createThemeMap(data) {
|
83
79
|
Neo.ns('Neo.cssMap.fileInfo', true);
|
84
80
|
Neo.cssMap.fileInfo = data;
|
85
|
-
this.resolveThemeFilesCache()
|
81
|
+
this.resolveThemeFilesCache()
|
86
82
|
}
|
87
83
|
|
88
84
|
/**
|
@@ -92,8 +88,8 @@ class App extends Base {
|
|
92
88
|
*/
|
93
89
|
fireMainViewsEvent(eventName, data) {
|
94
90
|
this.ports.forEach(port => {
|
95
|
-
Neo.apps[port.appName].mainViewInstance.fire(eventName, data)
|
96
|
-
})
|
91
|
+
Neo.apps[port.appName].mainViewInstance.fire(eventName, data)
|
92
|
+
})
|
97
93
|
}
|
98
94
|
|
99
95
|
/**
|
@@ -102,7 +98,7 @@ class App extends Base {
|
|
102
98
|
*/
|
103
99
|
importApp(path) {
|
104
100
|
if (path.endsWith('.mjs')) {
|
105
|
-
path = path.slice(0, -4)
|
101
|
+
path = path.slice(0, -4)
|
106
102
|
}
|
107
103
|
|
108
104
|
return import(
|
@@ -110,7 +106,7 @@ class App extends Base {
|
|
110
106
|
/* webpackExclude: /[\\\/]node_modules/ */
|
111
107
|
/* webpackMode: "lazy" */
|
112
108
|
`../../${path}.mjs`
|
113
|
-
)
|
109
|
+
)
|
114
110
|
}
|
115
111
|
|
116
112
|
/**
|
@@ -130,7 +126,7 @@ class App extends Base {
|
|
130
126
|
classPath, classRoot, fileName, mapClassName, ns, themeFolders;
|
131
127
|
|
132
128
|
if (!cssMap) {
|
133
|
-
me.themeFilesCache.push([appName, proto])
|
129
|
+
me.themeFilesCache.push([appName, proto])
|
134
130
|
} else {
|
135
131
|
// we need to modify app related class names
|
136
132
|
if (!className.startsWith('Neo.')) {
|
@@ -140,12 +136,12 @@ class App extends Base {
|
|
140
136
|
className[0] === 'view' && className.shift();
|
141
137
|
|
142
138
|
mapClassName = `apps.${Neo.apps[appName].appThemeFolder || classRoot}.${className.join('.')}`;
|
143
|
-
className = `apps.${lAppName}.${className.join('.')}
|
139
|
+
className = `apps.${lAppName}.${className.join('.')}`
|
144
140
|
}
|
145
141
|
|
146
142
|
if (parent && parent !== Neo.core.Base.prototype) {
|
147
143
|
if (!Neo.ns(`${lAppName}.${parent.className}`, false, cssMap)) {
|
148
|
-
me.insertThemeFiles(appName, parent)
|
144
|
+
me.insertThemeFiles(appName, parent)
|
149
145
|
}
|
150
146
|
}
|
151
147
|
|
@@ -163,7 +159,7 @@ class App extends Base {
|
|
163
159
|
appName,
|
164
160
|
className: mapClassName || className,
|
165
161
|
folders : themeFolders
|
166
|
-
})
|
162
|
+
})
|
167
163
|
}
|
168
164
|
}
|
169
165
|
}
|
@@ -174,7 +170,7 @@ class App extends Base {
|
|
174
170
|
* @param {Object} data useful event properties, differs for different event types. See Neo.main.DomEvents.
|
175
171
|
*/
|
176
172
|
onDomEvent(data) {
|
177
|
-
DomEventManager.fire(data)
|
173
|
+
DomEventManager.fire(data)
|
178
174
|
}
|
179
175
|
|
180
176
|
/**
|
@@ -182,7 +178,7 @@ class App extends Base {
|
|
182
178
|
* @param {Object} data parsed key-value pairs for each hash value
|
183
179
|
*/
|
184
180
|
onHashChange(data) {
|
185
|
-
HashHistory.push(data.data)
|
181
|
+
HashHistory.push(data.data)
|
186
182
|
}
|
187
183
|
|
188
184
|
/**
|
@@ -192,25 +188,25 @@ class App extends Base {
|
|
192
188
|
onLoadApplication(data) {
|
193
189
|
let me = this,
|
194
190
|
config = Neo.config,
|
195
|
-
path;
|
191
|
+
app, path;
|
196
192
|
|
197
193
|
if (data) {
|
198
194
|
me.data = data;
|
199
|
-
config.resourcesPath = data.resourcesPath
|
195
|
+
config.resourcesPath = data.resourcesPath
|
200
196
|
}
|
201
197
|
|
202
198
|
path = me.data.path;
|
203
199
|
|
204
200
|
if (config.environment !== 'development') {
|
205
|
-
path = path.startsWith('/') ? path.substring(1) : path
|
201
|
+
path = path.startsWith('/') ? path.substring(1) : path
|
206
202
|
}
|
207
203
|
|
208
204
|
me.importApp(path).then(module => {
|
209
|
-
module.onStart();
|
205
|
+
app = module.onStart();
|
210
206
|
|
211
207
|
// short delay to ensure Component Controllers are ready
|
212
|
-
config.hash && setTimeout(() => HashHistory.push(config.hash), 5)
|
213
|
-
})
|
208
|
+
config.hash && setTimeout(() => HashHistory.push(config.hash), 5)
|
209
|
+
})
|
214
210
|
}
|
215
211
|
|
216
212
|
/**
|
@@ -223,15 +219,15 @@ class App extends Base {
|
|
223
219
|
url = `resources/theme-map${config.useCssVars ? '' : '-no-vars'}.json`;
|
224
220
|
|
225
221
|
if (config.environment === 'development') {
|
226
|
-
url = `../../${url}
|
222
|
+
url = `../../${url}`
|
227
223
|
}
|
228
224
|
|
229
225
|
if (config.workerBasePath?.includes('node_modules')) {
|
230
|
-
url = `../../${url}
|
226
|
+
url = `../../${url}`
|
231
227
|
}
|
232
228
|
|
233
229
|
if (url[0] !== '.') {
|
234
|
-
url = `./${url}
|
230
|
+
url = `./${url}`
|
235
231
|
}
|
236
232
|
|
237
233
|
fetch(url)
|
@@ -239,7 +235,7 @@ class App extends Base {
|
|
239
235
|
.then(data => {this.createThemeMap(data)});
|
240
236
|
|
241
237
|
config.remotesApiUrl && import('../remotes/Api.mjs').then(module => module.default.load());
|
242
|
-
!config.useVdomWorker && import('../vdom/Helper.mjs')
|
238
|
+
!config.useVdomWorker && import('../vdom/Helper.mjs')
|
243
239
|
}
|
244
240
|
|
245
241
|
/**
|
@@ -251,14 +247,14 @@ class App extends Base {
|
|
251
247
|
|
252
248
|
port.onmessage = me.onMessage.bind(me);
|
253
249
|
|
254
|
-
me.channelPorts[msg.origin] = port
|
250
|
+
me.channelPorts[msg.origin] = port
|
255
251
|
}
|
256
252
|
|
257
253
|
/**
|
258
254
|
* @param {Object} data
|
259
255
|
*/
|
260
256
|
onWindowPositionChange(data) {
|
261
|
-
this.fireMainViewsEvent('windowPositionChange', data.data)
|
257
|
+
this.fireMainViewsEvent('windowPositionChange', data.data)
|
262
258
|
}
|
263
259
|
|
264
260
|
/**
|
@@ -268,11 +264,7 @@ class App extends Base {
|
|
268
264
|
registerApp(appName) {
|
269
265
|
// register the name as fast as possible
|
270
266
|
this.onRegisterApp({ appName });
|
271
|
-
|
272
|
-
this.sendMessage('main', {
|
273
|
-
action: 'registerAppName',
|
274
|
-
appName
|
275
|
-
});
|
267
|
+
this.sendMessage('main', {action: 'registerAppName', appName})
|
276
268
|
}
|
277
269
|
|
278
270
|
/**
|
@@ -281,7 +273,7 @@ class App extends Base {
|
|
281
273
|
* @param {String} appName
|
282
274
|
*/
|
283
275
|
removeAppFromThemeMap(appName) {
|
284
|
-
delete Neo.cssMap[appName.toLowerCase()]
|
276
|
+
delete Neo.cssMap[appName.toLowerCase()]
|
285
277
|
}
|
286
278
|
|
287
279
|
/**
|
@@ -291,10 +283,10 @@ class App extends Base {
|
|
291
283
|
let me = this;
|
292
284
|
|
293
285
|
me.themeFilesCache.forEach(item => {
|
294
|
-
me.insertThemeFiles(...item)
|
286
|
+
me.insertThemeFiles(...item)
|
295
287
|
});
|
296
288
|
|
297
|
-
me.themeFilesCache = []
|
289
|
+
me.themeFilesCache = []
|
298
290
|
}
|
299
291
|
|
300
292
|
/**
|
@@ -310,13 +302,13 @@ class App extends Base {
|
|
310
302
|
theme = Neo.config.themes?.[0];
|
311
303
|
|
312
304
|
if (!addon) {
|
313
|
-
return Promise.reject('Neo.main.addon.Stylesheet not imported')
|
305
|
+
return Promise.reject('Neo.main.addon.Stylesheet not imported')
|
314
306
|
} else {
|
315
307
|
if (theme.startsWith('neo-')) {
|
316
308
|
theme = theme.substring(4);
|
317
309
|
}
|
318
310
|
|
319
|
-
return addon.setCssVariable({theme, ...data})
|
311
|
+
return addon.setCssVariable({theme, ...data})
|
320
312
|
}
|
321
313
|
}
|
322
314
|
}
|