neo.mjs 8.31.1 → 8.33.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/.github/LLM_PROMPTS.md +463 -0
- package/README.md +138 -55
- package/apps/ServiceWorker.mjs +2 -2
- package/apps/finance/app.mjs +6 -0
- package/apps/finance/index.html +12 -0
- package/apps/finance/model/Company.mjs +37 -0
- package/apps/finance/neo-config.json +7 -0
- package/apps/finance/resources/data/companies.json +103 -0
- package/apps/finance/resources/images/neo_logo_favicon.svg +16 -0
- package/apps/finance/store/Companies.mjs +37 -0
- package/apps/finance/view/GridContainer.mjs +58 -0
- package/apps/finance/view/Viewport.mjs +43 -0
- package/apps/finance/view/ViewportController.mjs +35 -0
- package/apps/finance/view/ViewportStateProvider.mjs +32 -0
- package/apps/portal/index.html +1 -1
- package/apps/portal/view/home/FooterContainer.mjs +1 -1
- package/apps/portal/view/home/MainContainer.mjs +1 -1
- package/apps/portal/view/home/parts/Colors.mjs +4 -8
- package/apps/portal/view/home/parts/Helix.mjs +5 -1
- package/buildScripts/buildAll.mjs +1 -1
- package/buildScripts/buildThemes.mjs +1 -1
- package/buildScripts/createApp.mjs +1 -1
- package/buildScripts/createAppMinimal.mjs +1 -1
- package/buildScripts/docs/jsdocx.mjs +1 -1
- package/buildScripts/injectPackageVersion.mjs +1 -1
- package/buildScripts/watchThemes.mjs +1 -1
- package/buildScripts/webpack/buildThreads.mjs +1 -1
- package/buildScripts/webpack/development/webpack.config.appworker.mjs +1 -1
- package/buildScripts/webpack/development/webpack.config.main.mjs +1 -1
- package/buildScripts/webpack/development/webpack.config.worker.mjs +1 -1
- package/buildScripts/webpack/production/webpack.config.appworker.mjs +1 -1
- package/buildScripts/webpack/production/webpack.config.main.mjs +1 -1
- package/buildScripts/webpack/production/webpack.config.worker.mjs +1 -1
- package/examples/README.md +5 -14
- package/examples/ServiceWorker.mjs +2 -2
- package/package.json +3 -3
- package/resources/scss/src/grid/plugin/AnimateRows.scss +10 -0
- package/src/DefaultConfig.mjs +2 -2
- package/src/calendar/view/SettingsContainer.mjs +3 -5
- package/src/calendar/view/week/Component.mjs +3 -5
- package/src/component/Base.mjs +3 -6
- package/src/component/Helix.mjs +2 -3
- package/src/component/MagicMoveText.mjs +13 -6
- package/src/controller/Component.mjs +3 -5
- package/src/data/Store.mjs +1 -1
- package/src/dialog/Base.mjs +3 -4
- package/src/grid/Container.mjs +6 -6
- package/src/grid/View.mjs +1 -7
- package/src/grid/column/AnimatedChange.mjs +8 -5
- package/src/grid/column/Base.mjs +6 -2
- package/src/grid/column/Currency.mjs +72 -0
- package/src/grid/column/_export.mjs +2 -1
- package/src/grid/plugin/AnimateRows.mjs +9 -31
- package/src/list/Base.mjs +1 -3
- package/src/list/plugin/Animate.mjs +3 -3
- package/src/main/addon/ServiceWorker.mjs +29 -19
- package/src/manager/Component.mjs +1 -3
- package/src/plugin/Base.mjs +23 -3
- package/src/selection/HelixModel.mjs +3 -6
- package/src/tab/Container.mjs +3 -4
- package/src/table/Container.mjs +6 -7
- package/src/util/Css.mjs +6 -6
- package/src/worker/App.mjs +0 -11
- package/src/worker/Manager.mjs +4 -0
- package/src/worker/ServiceBase.mjs +40 -30
@@ -0,0 +1,72 @@
|
|
1
|
+
import Column from './Base.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @class Neo.grid.column.Currency
|
5
|
+
* @extends Neo.grid.column.Base
|
6
|
+
*/
|
7
|
+
class Currency extends Column {
|
8
|
+
static config = {
|
9
|
+
/**
|
10
|
+
* @member {String} className='Neo.grid.column.Currency'
|
11
|
+
* @protected
|
12
|
+
*/
|
13
|
+
className: 'Neo.grid.column.Currency',
|
14
|
+
/**
|
15
|
+
* @member {String} type='currency'
|
16
|
+
* @protected
|
17
|
+
*/
|
18
|
+
type: 'currency',
|
19
|
+
/**
|
20
|
+
* @member {String} currency='USD'
|
21
|
+
*/
|
22
|
+
currency: 'USD',
|
23
|
+
/**
|
24
|
+
* @member {String} locale='default'
|
25
|
+
*/
|
26
|
+
locale: 'default'
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @member {Intl.NumberFormat|null} formatter=null
|
31
|
+
*/
|
32
|
+
formatter = null
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @param {Object} config
|
36
|
+
*/
|
37
|
+
construct(config) {
|
38
|
+
super.construct(config);
|
39
|
+
this.createFormatter()
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @param {Object} data
|
44
|
+
* @param {Neo.button.Base} data.column
|
45
|
+
* @param {Number} data.columnIndex
|
46
|
+
* @param {String} data.dataField
|
47
|
+
* @param {Neo.grid.Container} data.gridContainer
|
48
|
+
* @param {Object} data.record
|
49
|
+
* @param {Number} data.rowIndex
|
50
|
+
* @param {Neo.data.Store} data.store
|
51
|
+
* @param {Number|String} data.value
|
52
|
+
* @returns {*}
|
53
|
+
*/
|
54
|
+
cellRenderer({value}) {
|
55
|
+
if (value === null || value === undefined) {
|
56
|
+
return ''
|
57
|
+
}
|
58
|
+
|
59
|
+
return this.formatter.format(value)
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
*
|
64
|
+
*/
|
65
|
+
createFormatter() {
|
66
|
+
let me = this;
|
67
|
+
|
68
|
+
me.formatter = new Intl.NumberFormat(me.locale, {style: 'currency', currency: me.currency})
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
export default Neo.setupClass(Currency);
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import AnimatedChange from './AnimatedChange.mjs';
|
2
2
|
import Base from './Base.mjs';
|
3
3
|
import Component from './Component.mjs';
|
4
|
+
import Currency from './Currency.mjs';
|
4
5
|
import Index from './Index.mjs';
|
5
6
|
import Progress from './Progress.mjs';
|
6
7
|
|
7
|
-
export {AnimatedChange, Base, Component, Index, Progress};
|
8
|
+
export {AnimatedChange, Base, Component, Currency, Index, Progress};
|
@@ -27,7 +27,7 @@ class AnimateRows extends Base {
|
|
27
27
|
*/
|
28
28
|
ntype: 'plugin-grid-animate-rows',
|
29
29
|
/**
|
30
|
-
* Time in ms
|
30
|
+
* Time in ms for the background-color, opacity & transform transitions
|
31
31
|
* @member {Number} transitionDuration_=500
|
32
32
|
*/
|
33
33
|
transitionDuration_: 500,
|
@@ -65,7 +65,7 @@ class AnimateRows extends Base {
|
|
65
65
|
// Add the re-bound listeners
|
66
66
|
owner.store = store;
|
67
67
|
|
68
|
-
|
68
|
+
owner.addCls('neo-animate-rows')
|
69
69
|
}
|
70
70
|
|
71
71
|
/**
|
@@ -75,7 +75,7 @@ class AnimateRows extends Base {
|
|
75
75
|
* @protected
|
76
76
|
*/
|
77
77
|
afterSetTransitionDuration(value, oldValue) {
|
78
|
-
this.
|
78
|
+
this.owner.addStyle({'--neo-duration': value + 'ms'})
|
79
79
|
}
|
80
80
|
|
81
81
|
/**
|
@@ -85,7 +85,7 @@ class AnimateRows extends Base {
|
|
85
85
|
* @protected
|
86
86
|
*/
|
87
87
|
afterSetTransitionEasing(value, oldValue) {
|
88
|
-
this.
|
88
|
+
this.owner.addStyle({'--neo-easing': value})
|
89
89
|
}
|
90
90
|
|
91
91
|
/**
|
@@ -102,7 +102,11 @@ class AnimateRows extends Base {
|
|
102
102
|
* @param {Object} args
|
103
103
|
*/
|
104
104
|
destroy(...args) {
|
105
|
-
|
105
|
+
this.owner.addStyle({
|
106
|
+
'--neo-duration': null,
|
107
|
+
'--neo-easing' : null
|
108
|
+
});
|
109
|
+
|
106
110
|
super.destroy(...args)
|
107
111
|
}
|
108
112
|
|
@@ -125,32 +129,6 @@ class AnimateRows extends Base {
|
|
125
129
|
this.updateView()
|
126
130
|
}
|
127
131
|
|
128
|
-
/**
|
129
|
-
* We do not want to apply the style to each list item itself,
|
130
|
-
* so we are using Neo.util.Css
|
131
|
-
* @param {Boolean} deleteRule=false
|
132
|
-
* @protected
|
133
|
-
*/
|
134
|
-
async updateTransitionDetails(deleteRule=false) {
|
135
|
-
let me = this,
|
136
|
-
duration = me.transitionDuration,
|
137
|
-
easing = me.transitionEasing,
|
138
|
-
{id} = me.owner;
|
139
|
-
|
140
|
-
if (deleteRule) {
|
141
|
-
await CssUtil.deleteRules(me.appName, `#${id} .neo-grid-row`)
|
142
|
-
}
|
143
|
-
|
144
|
-
CssUtil.insertRules(me.appName, [
|
145
|
-
`#${id} .neo-grid-row {`,
|
146
|
-
'transition:',
|
147
|
-
`background-color ${duration}ms ${easing},`,
|
148
|
-
`opacity ${duration}ms ${easing},`,
|
149
|
-
`transform ${duration}ms ${easing}`,
|
150
|
-
'}'
|
151
|
-
].join(''))
|
152
|
-
}
|
153
|
-
|
154
132
|
/**
|
155
133
|
*
|
156
134
|
*/
|
package/src/list/Base.mjs
CHANGED
@@ -156,7 +156,7 @@ class Animate extends Base {
|
|
156
156
|
* @param {Object} args
|
157
157
|
*/
|
158
158
|
destroy(...args) {
|
159
|
-
CssUtil.deleteRules(this.
|
159
|
+
CssUtil.deleteRules(this.windowId, `#${this.owner.id} .neo-list-item`);
|
160
160
|
super.destroy(...args)
|
161
161
|
}
|
162
162
|
|
@@ -431,10 +431,10 @@ class Animate extends Base {
|
|
431
431
|
{id} = me.owner;
|
432
432
|
|
433
433
|
if (deleteRule) {
|
434
|
-
await CssUtil.deleteRules(me.
|
434
|
+
await CssUtil.deleteRules(me.windowId, `#${id} .neo-list-item`)
|
435
435
|
}
|
436
436
|
|
437
|
-
CssUtil.insertRules(me.
|
437
|
+
CssUtil.insertRules(me.windowId, [
|
438
438
|
`#${id} .neo-list-item {`,
|
439
439
|
`transition: opacity ${duration}ms ${easing}, transform ${duration}ms ${easing}`,
|
440
440
|
'}'
|
@@ -19,6 +19,14 @@ class ServiceWorker extends Base {
|
|
19
19
|
* @param {Object} config
|
20
20
|
*/
|
21
21
|
construct(config) {
|
22
|
+
super.construct(config);
|
23
|
+
this.registerServiceWorker()
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* @returns {Promise<void>}
|
28
|
+
*/
|
29
|
+
async registerServiceWorker() {
|
22
30
|
if ('serviceWorker' in navigator) {
|
23
31
|
let me = this,
|
24
32
|
{config} = Neo,
|
@@ -27,30 +35,32 @@ class ServiceWorker extends Base {
|
|
27
35
|
folder = window.location.pathname.includes('/examples/') ? 'examples/' : 'apps/',
|
28
36
|
opts = devMode ? {type: 'module'} : {},
|
29
37
|
path = (devMode ? config.basePath : config.workerBasePath) + (devMode ? folder : '') + fileName,
|
30
|
-
{serviceWorker} = navigator
|
38
|
+
{serviceWorker} = navigator,
|
39
|
+
registration = await serviceWorker.register(path, opts);
|
31
40
|
|
32
41
|
window.addEventListener('beforeunload', me.onBeforeUnload.bind(me));
|
33
42
|
|
34
|
-
|
35
|
-
.
|
36
|
-
|
37
|
-
|
43
|
+
registration.addEventListener('updatefound', () => {
|
44
|
+
window.location.reload()
|
45
|
+
})
|
46
|
+
|
47
|
+
await serviceWorker.ready;
|
48
|
+
|
49
|
+
serviceWorker.onmessage = WorkerManager.onWorkerMessage.bind(WorkerManager);
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
if (!WorkerManager.getWorker('service')) {
|
52
|
+
/*
|
53
|
+
* navigator.serviceWorker.controller can be null in case we load a page for the first time
|
54
|
+
* or in case of a force refresh.
|
55
|
+
* See: https://www.w3.org/TR/service-workers/#navigator-service-worker-controller
|
56
|
+
*/
|
57
|
+
WorkerManager.serviceWorker = registration.active
|
58
|
+
}
|
47
59
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
})
|
53
|
-
})
|
60
|
+
WorkerManager.sendMessage('service', {
|
61
|
+
action: 'registerNeoConfig',
|
62
|
+
data : config
|
63
|
+
})
|
54
64
|
}
|
55
65
|
}
|
56
66
|
|
@@ -400,8 +400,6 @@ class Component extends Manager {
|
|
400
400
|
if (vdom.cn) {
|
401
401
|
output.cn = [];
|
402
402
|
|
403
|
-
childDepth = depth === -1 ? -1 : depth > 1 ? depth-1 : 1;
|
404
|
-
|
405
403
|
vdom.cn.forEach(item => {
|
406
404
|
childDepth = depth;
|
407
405
|
|
@@ -445,7 +443,7 @@ class Component extends Manager {
|
|
445
443
|
component = this.get(item.componentId);
|
446
444
|
|
447
445
|
// keep references in case there is no vnode (cmp not mounted)
|
448
|
-
if (component
|
446
|
+
if (component?.vnode) {
|
449
447
|
item = component.vnode
|
450
448
|
}
|
451
449
|
}
|
package/src/plugin/Base.mjs
CHANGED
@@ -37,12 +37,21 @@ class Plugin extends Base {
|
|
37
37
|
construct(config) {
|
38
38
|
super.construct(config);
|
39
39
|
|
40
|
-
let me
|
40
|
+
let me = this,
|
41
|
+
{owner} = me;
|
41
42
|
|
42
|
-
if (
|
43
|
+
if (owner.isConstructed) {
|
44
|
+
me.onOwnerConstructed()
|
45
|
+
} else {
|
46
|
+
owner.on('constructed', () => {
|
47
|
+
me.onOwnerConstructed()
|
48
|
+
}, me, {once: true})
|
49
|
+
}
|
50
|
+
|
51
|
+
if (owner.mounted) {
|
43
52
|
me.onOwnerMounted();
|
44
53
|
} else {
|
45
|
-
|
54
|
+
owner.on('mounted', me.onOwnerMounted, me);
|
46
55
|
}
|
47
56
|
}
|
48
57
|
|
@@ -56,6 +65,17 @@ class Plugin extends Base {
|
|
56
65
|
value && Neo.currentWorker.insertThemeFiles(value, this.__proto__)
|
57
66
|
}
|
58
67
|
|
68
|
+
/**
|
69
|
+
* Override this method to apply changes to the owner Component when it is constructed
|
70
|
+
*/
|
71
|
+
onOwnerConstructed() {
|
72
|
+
let {owner} = this;
|
73
|
+
|
74
|
+
if (owner.windowId) {
|
75
|
+
this.windowId = owner.windowId
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
59
79
|
/**
|
60
80
|
* Override this method to apply changes to the owner Component when it does get mounted
|
61
81
|
*/
|
@@ -223,8 +223,7 @@ class HelixModel extends Model {
|
|
223
223
|
isSelected = toggleSelection === false ? false : me.items.includes(itemId),
|
224
224
|
items = me.items,
|
225
225
|
oldItems = [...items],
|
226
|
-
deltas = []
|
227
|
-
listenerId;
|
226
|
+
deltas = [];
|
228
227
|
|
229
228
|
// a select() call can happen before the view is registered
|
230
229
|
if (!view) {
|
@@ -232,13 +231,11 @@ class HelixModel extends Model {
|
|
232
231
|
}
|
233
232
|
|
234
233
|
if (!view.mounted) {
|
235
|
-
|
236
|
-
view.un('mounted', listenerId);
|
237
|
-
|
234
|
+
view.on('mounted', () => {
|
238
235
|
me.timeout(300).then(() => {
|
239
236
|
me.select(itemId, toggleSelection)
|
240
237
|
})
|
241
|
-
})
|
238
|
+
}, me, {once: true})
|
242
239
|
}
|
243
240
|
|
244
241
|
if (me.singleSelect) {
|
package/src/tab/Container.mjs
CHANGED
@@ -524,7 +524,7 @@ class Container extends BaseContainer {
|
|
524
524
|
i = 0,
|
525
525
|
len = tabBar.items.length,
|
526
526
|
index = -1,
|
527
|
-
card
|
527
|
+
card;
|
528
528
|
|
529
529
|
for (; i < len; i++) {
|
530
530
|
if (tabBar.items[i].id === buttonId) {
|
@@ -537,10 +537,9 @@ class Container extends BaseContainer {
|
|
537
537
|
card = cardContainer.items[index];
|
538
538
|
|
539
539
|
if (me.vnode && !card.mounted) {
|
540
|
-
|
541
|
-
card.un('mounted', listenerId);
|
540
|
+
card.on('mounted', () => {
|
542
541
|
me.activeIndex = index
|
543
|
-
})
|
542
|
+
}, me, {once: true})
|
544
543
|
} else {
|
545
544
|
me.activeIndex = index
|
546
545
|
}
|
package/src/table/Container.mjs
CHANGED
@@ -161,14 +161,13 @@ class Container extends BaseContainer {
|
|
161
161
|
afterSetCellEditing(value, oldValue) {
|
162
162
|
if (value) {
|
163
163
|
import('./plugin/CellEditing.mjs').then(module => {
|
164
|
-
let me
|
165
|
-
{appName
|
166
|
-
plugins
|
164
|
+
let me = this,
|
165
|
+
{appName} = me,
|
166
|
+
plugins = me.plugins || [];
|
167
167
|
|
168
168
|
plugins.push({
|
169
|
-
module
|
170
|
-
appName
|
171
|
-
windowId
|
169
|
+
module: module.default,
|
170
|
+
appName
|
172
171
|
});
|
173
172
|
|
174
173
|
me.plugins = plugins
|
@@ -262,7 +261,7 @@ class Container extends BaseContainer {
|
|
262
261
|
}
|
263
262
|
|
264
263
|
if (cssRules.length > 0) {
|
265
|
-
CssUtil.insertRules(me.
|
264
|
+
CssUtil.insertRules(me.windowId, cssRules)
|
266
265
|
}
|
267
266
|
|
268
267
|
me.scrollbarsCssApplied = true
|
package/src/util/Css.mjs
CHANGED
@@ -15,27 +15,27 @@ class Css extends Base {
|
|
15
15
|
|
16
16
|
/**
|
17
17
|
* Pass the selectorText of the rules which you want to remove
|
18
|
-
* @param {
|
18
|
+
* @param {Number} windowId
|
19
19
|
* @param {String[]|String} rules
|
20
20
|
*/
|
21
|
-
static deleteRules(
|
21
|
+
static deleteRules(windowId, rules) {
|
22
22
|
if (!Array.isArray(rules)) {
|
23
23
|
rules = [rules]
|
24
24
|
}
|
25
25
|
|
26
|
-
Neo.main.addon.Stylesheet.deleteCssRules({
|
26
|
+
Neo.main.addon.Stylesheet.deleteCssRules({rules, windowId})
|
27
27
|
}
|
28
28
|
|
29
29
|
/**
|
30
|
-
* @param {
|
30
|
+
* @param {Number} windowId
|
31
31
|
* @param {String[]|String} rules
|
32
32
|
*/
|
33
|
-
static insertRules(
|
33
|
+
static insertRules(windowId, rules) {
|
34
34
|
if (!Array.isArray(rules)) {
|
35
35
|
rules = [rules]
|
36
36
|
}
|
37
37
|
|
38
|
-
Neo.main.addon.Stylesheet.insertCssRules({
|
38
|
+
Neo.main.addon.Stylesheet.insertCssRules({rules, windowId})
|
39
39
|
}
|
40
40
|
}
|
41
41
|
|
package/src/worker/App.mjs
CHANGED
@@ -413,17 +413,6 @@ class App extends Base {
|
|
413
413
|
})
|
414
414
|
})
|
415
415
|
}
|
416
|
-
/**
|
417
|
-
* Triggered in case a connected ServiceWorker receives a new version.
|
418
|
-
* Especially inside dist envs, a reload of the connecting window is required,
|
419
|
-
* since the SW will clear its caches and the app can receive conflicting bundle versions.
|
420
|
-
* @param {Object} data
|
421
|
-
* @param {String} data.newVersion
|
422
|
-
* @param {String} data.oldVersion
|
423
|
-
*/
|
424
|
-
onNewVersion(data) {
|
425
|
-
Neo.Main.reloadWindow({});
|
426
|
-
}
|
427
416
|
|
428
417
|
/**
|
429
418
|
* Fire event on all apps
|
package/src/worker/Manager.mjs
CHANGED
@@ -8,6 +8,10 @@ import RemoteMethodAccess from './mixin/RemoteMethodAccess.mjs';
|
|
8
8
|
const NeoConfig = Neo.config,
|
9
9
|
devMode = NeoConfig.environment === 'development';
|
10
10
|
|
11
|
+
navigator.serviceWorker.addEventListener('controllerchange', function() {
|
12
|
+
window.location.reload()
|
13
|
+
}, {once: true});
|
14
|
+
|
11
15
|
/**
|
12
16
|
* The worker manager lives inside the main thread and creates the App, Data & VDom worker.
|
13
17
|
* Also, responsible for sending messages from the main thread to the different workers.
|
@@ -14,6 +14,10 @@ class ServiceBase extends Base {
|
|
14
14
|
* @protected
|
15
15
|
*/
|
16
16
|
className: 'Neo.worker.ServiceBase',
|
17
|
+
/**
|
18
|
+
* @member {String} cacheName_='neo-runtime'
|
19
|
+
*/
|
20
|
+
cacheName_: 'neo-runtime',
|
17
21
|
/**
|
18
22
|
* @member {String[]|Neo.core.Base[]|null} mixins=[RemoteMethodAccess]
|
19
23
|
*/
|
@@ -33,10 +37,6 @@ class ServiceBase extends Base {
|
|
33
37
|
}
|
34
38
|
}
|
35
39
|
|
36
|
-
/**
|
37
|
-
* @member {String} cacheName='neo-runtime'
|
38
|
-
*/
|
39
|
-
cacheName = 'neo-runtime'
|
40
40
|
/**
|
41
41
|
* @member {String[]} cachePaths
|
42
42
|
*/
|
@@ -94,6 +94,15 @@ class ServiceBase extends Base {
|
|
94
94
|
Neo.workerId = me.workerId
|
95
95
|
}
|
96
96
|
|
97
|
+
/**
|
98
|
+
* Triggered when accessing the cacheName config
|
99
|
+
* @param {String} value
|
100
|
+
* @protected
|
101
|
+
*/
|
102
|
+
beforeGetCacheName(value) {
|
103
|
+
return value + '-' + this.version
|
104
|
+
}
|
105
|
+
|
97
106
|
/**
|
98
107
|
* @param {String} name=this.cacheName
|
99
108
|
* @returns {Promise<Object>}
|
@@ -163,14 +172,26 @@ class ServiceBase extends Base {
|
|
163
172
|
/**
|
164
173
|
* @param {ExtendableMessageEvent} event
|
165
174
|
*/
|
166
|
-
onActivate(event) {
|
167
|
-
console.log('onActivate', event)
|
175
|
+
async onActivate(event) {
|
176
|
+
console.log('onActivate', event);
|
177
|
+
|
178
|
+
let me = this,
|
179
|
+
keys = await caches.keys(),
|
180
|
+
key;
|
181
|
+
|
182
|
+
for (key of keys) {
|
183
|
+
// Clear caches for prior SW versions, without touching non-related caches
|
184
|
+
if (key.startsWith(me._cacheName) && key !== me.cacheName) {
|
185
|
+
// No need to await the method execution
|
186
|
+
me.clearCache(key)
|
187
|
+
}
|
188
|
+
}
|
168
189
|
}
|
169
190
|
|
170
191
|
/**
|
171
192
|
* @param {Client} source
|
172
193
|
*/
|
173
|
-
onConnect(source) {
|
194
|
+
async onConnect(source) {
|
174
195
|
console.log('onConnect', source);
|
175
196
|
|
176
197
|
this.createMessageChannel(source);
|
@@ -181,8 +202,8 @@ class ServiceBase extends Base {
|
|
181
202
|
* @param {ExtendableMessageEvent} event
|
182
203
|
*/
|
183
204
|
onFetch(event) {
|
184
|
-
let hasMatch
|
185
|
-
{request}
|
205
|
+
let hasMatch = false,
|
206
|
+
{request} = event,
|
186
207
|
key;
|
187
208
|
|
188
209
|
for (key of this.cachePaths) {
|
@@ -192,7 +213,7 @@ class ServiceBase extends Base {
|
|
192
213
|
}
|
193
214
|
}
|
194
215
|
|
195
|
-
hasMatch && event.respondWith(
|
216
|
+
hasMatch && request.method === 'GET' && event.respondWith(
|
196
217
|
caches.match(request)
|
197
218
|
.then(cachedResponse => cachedResponse || caches.open(this.cacheName)
|
198
219
|
.then(cache => fetch(request)
|
@@ -206,8 +227,7 @@ class ServiceBase extends Base {
|
|
206
227
|
* @param {ExtendableMessageEvent} event
|
207
228
|
*/
|
208
229
|
onInstall(event) {
|
209
|
-
console.log('onInstall', event)
|
210
|
-
globalThis.skipWaiting()
|
230
|
+
console.log('onInstall', event)
|
211
231
|
}
|
212
232
|
|
213
233
|
/**
|
@@ -250,25 +270,15 @@ class ServiceBase extends Base {
|
|
250
270
|
* @param {ExtendableMessageEvent} event
|
251
271
|
*/
|
252
272
|
async onRegisterNeoConfig(msg, event) {
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
Neo.config = Neo.config || {};
|
257
|
-
Object.assign(Neo.config, msg.data);
|
258
|
-
|
259
|
-
if (version !== Neo.config.version) {
|
260
|
-
await me.clearCaches();
|
261
|
-
|
262
|
-
me.version = Neo.config.version;
|
273
|
+
this.onConnect(event.source)
|
274
|
+
}
|
263
275
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
me.onConnect(event.source)
|
271
|
-
}
|
276
|
+
/**
|
277
|
+
* @param {Object} msg
|
278
|
+
* @param {ExtendableMessageEvent} event
|
279
|
+
*/
|
280
|
+
async onSkipWaiting(msg, event) {
|
281
|
+
await globalThis.skipWaiting()
|
272
282
|
}
|
273
283
|
|
274
284
|
/**
|