@rws-framework/client 2.20.0 → 2.20.2

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 (85) hide show
  1. package/.bin/emerge.sh +15 -15
  2. package/builder/vite/index.ts +4 -4
  3. package/builder/vite/rws.vite.config.ts +132 -132
  4. package/builder/vite/rws_scss_plugin.ts +61 -61
  5. package/builder/webpack/index.js +10 -10
  6. package/builder/webpack/rws.webpack.config.js +161 -161
  7. package/builder/webpack/rws_scss_plugin.js +90 -90
  8. package/builder/webpack/rws_webpack_plugin.js +137 -137
  9. package/cfg/_default.cfg.js +26 -26
  10. package/cfg/_storage.d.ts +22 -22
  11. package/cfg/_storage.js +42 -42
  12. package/cfg/tsconfigSetup.js +146 -146
  13. package/docs/assets/26e93147f10415a0ed4a.svg +6 -6
  14. package/docs/assets/75c9471662e97ee24f29.svg +7 -7
  15. package/docs/assets/db90e4df2373980c497d.svg +9 -9
  16. package/docs/assets/highlight.css +127 -127
  17. package/docs/assets/main.js +59 -59
  18. package/docs/assets/style.css +1414 -1414
  19. package/docs/classes/ApiServiceInstance.html +25 -25
  20. package/docs/classes/ConfigServiceInstance.html +21 -21
  21. package/docs/classes/DOMServiceInstance.html +17 -17
  22. package/docs/classes/NotifyServiceInstance.html +15 -15
  23. package/docs/classes/RWSClientInstance.html +45 -45
  24. package/docs/classes/RWSPlugin.html +13 -13
  25. package/docs/classes/RWSService.html +10 -10
  26. package/docs/classes/RWSViewComponent.html +1022 -1022
  27. package/docs/classes/ServiceWorkerServiceInstance.html +13 -13
  28. package/docs/classes/UtilsServiceInstance.html +13 -13
  29. package/docs/functions/attr.html +5 -5
  30. package/docs/functions/observable.html +3 -3
  31. package/docs/index.html +179 -179
  32. package/docs/interfaces/HTMLTag.html +3 -3
  33. package/docs/interfaces/IRWSConfig.html +20 -20
  34. package/docs/interfaces/IRWSDecoratorOptions.html +5 -5
  35. package/docs/interfaces/IRWSHttpRoute.html +2 -2
  36. package/docs/interfaces/IRWSPrefixedHTTProutes.html +2 -2
  37. package/docs/interfaces/IRWSUser.html +5 -5
  38. package/docs/modules.html +45 -45
  39. package/foundation/index.js +1 -1
  40. package/foundation/rws-foundation.d.ts +7 -7
  41. package/foundation/rws-foundation.js +7 -7
  42. package/package.json +1 -1
  43. package/service_worker/src/_service_worker.ts +83 -83
  44. package/service_worker/tsconfig.json +20 -20
  45. package/service_worker/webpack.config.js +66 -66
  46. package/src/client/components.ts +67 -67
  47. package/src/client/config.ts +175 -175
  48. package/src/client/hotReload.ts +22 -22
  49. package/src/client/services.ts +27 -27
  50. package/src/client.ts +208 -208
  51. package/src/components/_component.ts +247 -247
  52. package/src/components/_container.ts +15 -15
  53. package/src/components/_decorator.ts +122 -122
  54. package/src/components/_definitions.ts +64 -64
  55. package/src/components/_event_handling.ts +40 -40
  56. package/src/components/index.ts +25 -25
  57. package/src/components/rws/line-splitter/component.ts +1 -3
  58. package/src/index.ts +86 -86
  59. package/src/plugins/_builder.js +31 -31
  60. package/src/plugins/_plugin.ts +60 -60
  61. package/src/services/ApiService.ts +105 -105
  62. package/src/services/ConfigService.ts +125 -125
  63. package/src/services/DOMService.ts +93 -93
  64. package/src/services/NotifyService.ts +47 -47
  65. package/src/services/ServiceWorkerService.ts +60 -60
  66. package/src/services/UtilsService.ts +60 -60
  67. package/src/services/_service.ts +64 -64
  68. package/src/styles/README.md +157 -157
  69. package/src/styles/_darkreader.scss +30 -30
  70. package/src/styles/_grid.scss +75 -75
  71. package/src/styles/_grid_legacy.scss +49 -49
  72. package/src/styles/_misc.scss +8 -8
  73. package/src/styles/_scrollbars.scss +40 -40
  74. package/src/styles/includes.scss +6 -6
  75. package/src/types/IBackendCore.ts +11 -11
  76. package/src/types/IRWSConfig.ts +29 -29
  77. package/src/types/IRWSPlugin.ts +23 -23
  78. package/src/types/IRWSResource.ts +4 -4
  79. package/src/types/IRWSUser.ts +6 -6
  80. package/src/types/IRWSViewComponent.ts +36 -36
  81. package/src/types/IReFormerField.ts +4 -4
  82. package/src/types/RWSNotify.ts +6 -6
  83. package/src/types/RWSWindow.ts +41 -41
  84. package/types/declarations.d.ts +8 -8
  85. package/types/docs-typings.d.ts +15 -15
@@ -1,126 +1,126 @@
1
- import TheService from './_service';
2
- import IRWSConfig from '../types/IRWSConfig';
3
- import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
4
- import { sendEventToOutside } from '../components/_event_handling';
5
-
6
-
7
-
8
-
9
- const __SENT_TO_COMPONENTS: string[] = [];
10
-
11
- @RWSFillBuild()
12
- class ConfigService extends TheService {
13
- static _DEFAULT: boolean = false;
14
- static isLoaded: boolean = false;
15
-
16
- _DEFAULTS: Partial<IRWSConfig> = {};
17
- _BUILD_OVERRIDE: IRWSConfig = {};
18
-
19
- private data: IRWSConfig = {};
20
-
21
- constructor() {
22
- super();
23
- }
24
-
25
- public get(key: keyof IRWSConfig): any
26
- {
27
-
28
- if(!this._DEFAULTS){
29
- throw new Error('No _DEFAULTS loaded!');
30
- }
31
-
32
-
33
- const isInDefaults: boolean = Object.keys(this._DEFAULTS).includes(key as string);
34
- const isInData: boolean = Object.keys(this.data).includes(key as string);
35
- const isInBuildVars: boolean = Object.keys(this._BUILD_OVERRIDE).includes(key as string);
36
-
37
- let isDev = false;
38
-
39
- if((Object.keys(this._BUILD_OVERRIDE).includes('dev'))){
40
- isDev = Object.keys(this._BUILD_OVERRIDE).includes('dev') && this._BUILD_OVERRIDE.dev;
41
- }
42
-
43
- if(!isInData){
44
- let defaultVal = null;
45
-
46
- if(isInDefaults){
47
- defaultVal = this._DEFAULTS[key];
48
- }
49
-
50
- if(defaultVal && defaultVal[0] === '@'){
51
- defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
52
- }
53
-
54
- if(isInBuildVars && Object.keys(this._BUILD_OVERRIDE).includes(key as string)){
55
- if(isDev){
56
- console.warn(`.rws.json override [${key}]:`), this._BUILD_OVERRIDE[key];
57
- }
58
-
59
- defaultVal = this._BUILD_OVERRIDE[key];
60
- }
61
-
62
- return defaultVal;
63
- }
64
-
65
- return this.data[key as keyof IRWSConfig];
66
- }
67
-
68
- public set<V extends keyof IRWSConfig>(key: V, value: IRWSConfig[V]){
69
- this.data[key] = value;
70
- }
71
-
72
- async waitForConfig(tagName: string): Promise<boolean>
73
- {
74
- let t: NodeJS.Timeout | null = null;
75
-
76
- if(!this.data._noLoad || __SENT_TO_COMPONENTS.includes(tagName)){
77
- return;
78
- }
79
-
80
- __SENT_TO_COMPONENTS.push(tagName);
81
-
82
- sendEventToOutside<{tagName: string}>('rws_cfg_call', {tagName})
83
-
84
- return new Promise((resolve) => {
85
- const tick = () => {
86
- if(ConfigService.isLoaded){
87
- clearTimeout(t);
88
- resolve(true);
89
- return;
90
- }
91
-
92
- t = setTimeout(tick, 200);
93
- };
94
-
95
- t = setTimeout(tick, 200);
96
- });
97
- }
98
-
99
- isLoaded(): boolean
100
- {
101
- return ConfigService.isLoaded;
102
- }
103
-
104
- mergeConfig(config: IRWSConfig) {
105
- const unloaded = ConfigService.isLoaded;
106
-
107
- this.data.plugins = [];
108
-
109
- this.data = Object.assign(this.data, config);
110
-
111
- if(unloaded){
112
- ConfigService.isLoaded = true;
113
- }
114
-
115
- return this.data;
116
- }
117
-
118
- getData(): IRWSConfig
119
- {
120
- return this.data;
121
- }
122
- }
123
-
124
- export default ConfigService.getSingleton('ConfigService');
125
-
1
+ import TheService from './_service';
2
+ import IRWSConfig from '../types/IRWSConfig';
3
+ import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
4
+ import { sendEventToOutside } from '../components/_event_handling';
5
+
6
+
7
+
8
+
9
+ const __SENT_TO_COMPONENTS: string[] = [];
10
+
11
+ @RWSFillBuild()
12
+ class ConfigService extends TheService {
13
+ static _DEFAULT: boolean = false;
14
+ static isLoaded: boolean = false;
15
+
16
+ _DEFAULTS: Partial<IRWSConfig> = {};
17
+ _BUILD_OVERRIDE: IRWSConfig = {};
18
+
19
+ private data: IRWSConfig = {};
20
+
21
+ constructor() {
22
+ super();
23
+ }
24
+
25
+ public get(key: keyof IRWSConfig): any
26
+ {
27
+
28
+ if(!this._DEFAULTS){
29
+ throw new Error('No _DEFAULTS loaded!');
30
+ }
31
+
32
+
33
+ const isInDefaults: boolean = Object.keys(this._DEFAULTS).includes(key as string);
34
+ const isInData: boolean = Object.keys(this.data).includes(key as string);
35
+ const isInBuildVars: boolean = Object.keys(this._BUILD_OVERRIDE).includes(key as string);
36
+
37
+ let isDev = false;
38
+
39
+ if((Object.keys(this._BUILD_OVERRIDE).includes('dev'))){
40
+ isDev = Object.keys(this._BUILD_OVERRIDE).includes('dev') && this._BUILD_OVERRIDE.dev;
41
+ }
42
+
43
+ if(!isInData){
44
+ let defaultVal = null;
45
+
46
+ if(isInDefaults){
47
+ defaultVal = this._DEFAULTS[key];
48
+ }
49
+
50
+ if(defaultVal && defaultVal[0] === '@'){
51
+ defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
52
+ }
53
+
54
+ if(isInBuildVars && Object.keys(this._BUILD_OVERRIDE).includes(key as string)){
55
+ if(isDev){
56
+ console.warn(`.rws.json override [${key}]:`), this._BUILD_OVERRIDE[key];
57
+ }
58
+
59
+ defaultVal = this._BUILD_OVERRIDE[key];
60
+ }
61
+
62
+ return defaultVal;
63
+ }
64
+
65
+ return this.data[key as keyof IRWSConfig];
66
+ }
67
+
68
+ public set<V extends keyof IRWSConfig>(key: V, value: IRWSConfig[V]){
69
+ this.data[key] = value;
70
+ }
71
+
72
+ async waitForConfig(tagName: string): Promise<boolean>
73
+ {
74
+ let t: NodeJS.Timeout | null = null;
75
+
76
+ if(!this.data._noLoad || __SENT_TO_COMPONENTS.includes(tagName)){
77
+ return;
78
+ }
79
+
80
+ __SENT_TO_COMPONENTS.push(tagName);
81
+
82
+ sendEventToOutside<{tagName: string}>('rws_cfg_call', {tagName})
83
+
84
+ return new Promise((resolve) => {
85
+ const tick = () => {
86
+ if(ConfigService.isLoaded){
87
+ clearTimeout(t);
88
+ resolve(true);
89
+ return;
90
+ }
91
+
92
+ t = setTimeout(tick, 200);
93
+ };
94
+
95
+ t = setTimeout(tick, 200);
96
+ });
97
+ }
98
+
99
+ isLoaded(): boolean
100
+ {
101
+ return ConfigService.isLoaded;
102
+ }
103
+
104
+ mergeConfig(config: IRWSConfig) {
105
+ const unloaded = ConfigService.isLoaded;
106
+
107
+ this.data.plugins = [];
108
+
109
+ this.data = Object.assign(this.data, config);
110
+
111
+ if(unloaded){
112
+ ConfigService.isLoaded = true;
113
+ }
114
+
115
+ return this.data;
116
+ }
117
+
118
+ getData(): IRWSConfig
119
+ {
120
+ return this.data;
121
+ }
122
+ }
123
+
124
+ export default ConfigService.getSingleton('ConfigService');
125
+
126
126
  export { ConfigService as ConfigServiceInstance };
@@ -1,94 +1,94 @@
1
- import RWSService from './_service';
2
- import { DOM } from '@microsoft/fast-element';
3
- import DOMPurify from 'dompurify';
4
-
5
- type TagsProcessorType = { [tagName: string]: string | Transformer };
6
- type DOMOutputType<T extends Element> = NodeListOf<T> | T | null;
7
-
8
- //@ts-ignore
9
- declare let trustedTypes: TrustedTypePolicyFactory;
10
-
11
-
12
- class DOMService extends RWSService {
13
- static _DEFAULT: boolean = true;
14
- parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
15
- if(input.length > 1 || directReturn) {
16
- return input;
17
- }
18
-
19
- if(input.length === 1) {
20
- return input[0];
21
- }
22
-
23
- return null;
24
- }
25
-
26
- $<T extends Element>(shadowRoot: ShadowRoot, selectors: string, directReturn: boolean = false): DOMOutputType<T> {
27
- const elements = shadowRoot.querySelectorAll<T>(selectors);
28
- return elements ? this.parse$<T>(elements, directReturn) : null;
29
- }
30
-
31
- async scrollToBottom(scrollContainer: HTMLDivElement, contentSelector: string = '.scroll-content') {
32
- if (scrollContainer) {
33
- const scrollContent = scrollContainer.querySelector(contentSelector) as HTMLElement;
34
-
35
- if (scrollContent) {
36
- scrollContainer.scrollTop = (scrollContent.scrollHeight - scrollContainer.clientHeight) + 150;
37
- }
38
- }
39
- }
40
-
41
- setHTMLPolicy(policyName: string, policyImplementation: (html: string) => string): void
42
- {
43
- const myPolicy = trustedTypes.createPolicy(policyName, {
44
- createHTML(html: string) {
45
- return policyImplementation(html);
46
- }
47
- });
48
-
49
- DOM.setHTMLPolicy(myPolicy as any);
50
- }
51
-
52
- private enforceAllowedTags(htmlText: string, allowedHTMLTags: string[]): string
53
- {
54
- // Create a regular expression pattern to match HTML tags
55
- const tagPattern = /<\s*\/?\s*([^\s>/]+)(\s+[^>]*)?>/g;
56
-
57
- // Replace any tags in the htmlText that are not in allowedHTMLTags array
58
- const sanitizedText = htmlText.replace(tagPattern, (match, tag, attributes) => {
59
- const lowerCaseTag = tag.toLowerCase();
60
-
61
- if (allowedHTMLTags.includes(lowerCaseTag)) {
62
- return match; // Return the original tag if it's allowed
63
- } else {
64
- // Replace the disallowed tag with an empty string
65
- return '';
66
- }
67
- });
68
-
69
- return sanitizedText;
70
- }
71
-
72
- async onDOMLoad(): Promise<void>
73
- {
74
- return new Promise<void>((resolve) => {
75
- document.addEventListener('DOMContentLoaded', () => {
76
- resolve();
77
- });
78
- });
79
- }
80
-
81
- sanitizeHTML(
82
- line: string,
83
- sanitizeOptions: DOMPurify.Config = { })
84
- {
85
- const output: string = line.trim();
86
- const sanitized = DOMPurify.sanitize(output, { USE_PROFILES: { html: true }, ...sanitizeOptions});
87
- return sanitized;
88
- }
89
- }
90
-
91
-
92
-
93
- export default DOMService.getSingleton();
1
+ import RWSService from './_service';
2
+ import { DOM } from '@microsoft/fast-element';
3
+ import DOMPurify from 'dompurify';
4
+
5
+ type TagsProcessorType = { [tagName: string]: string | Transformer };
6
+ type DOMOutputType<T extends Element> = NodeListOf<T> | T | null;
7
+
8
+ //@ts-ignore
9
+ declare let trustedTypes: TrustedTypePolicyFactory;
10
+
11
+
12
+ class DOMService extends RWSService {
13
+ static _DEFAULT: boolean = true;
14
+ parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
15
+ if(input.length > 1 || directReturn) {
16
+ return input;
17
+ }
18
+
19
+ if(input.length === 1) {
20
+ return input[0];
21
+ }
22
+
23
+ return null;
24
+ }
25
+
26
+ $<T extends Element>(shadowRoot: ShadowRoot, selectors: string, directReturn: boolean = false): DOMOutputType<T> {
27
+ const elements = shadowRoot.querySelectorAll<T>(selectors);
28
+ return elements ? this.parse$<T>(elements, directReturn) : null;
29
+ }
30
+
31
+ async scrollToBottom(scrollContainer: HTMLDivElement, contentSelector: string = '.scroll-content') {
32
+ if (scrollContainer) {
33
+ const scrollContent = scrollContainer.querySelector(contentSelector) as HTMLElement;
34
+
35
+ if (scrollContent) {
36
+ scrollContainer.scrollTop = (scrollContent.scrollHeight - scrollContainer.clientHeight) + 150;
37
+ }
38
+ }
39
+ }
40
+
41
+ setHTMLPolicy(policyName: string, policyImplementation: (html: string) => string): void
42
+ {
43
+ const myPolicy = trustedTypes.createPolicy(policyName, {
44
+ createHTML(html: string) {
45
+ return policyImplementation(html);
46
+ }
47
+ });
48
+
49
+ DOM.setHTMLPolicy(myPolicy as any);
50
+ }
51
+
52
+ private enforceAllowedTags(htmlText: string, allowedHTMLTags: string[]): string
53
+ {
54
+ // Create a regular expression pattern to match HTML tags
55
+ const tagPattern = /<\s*\/?\s*([^\s>/]+)(\s+[^>]*)?>/g;
56
+
57
+ // Replace any tags in the htmlText that are not in allowedHTMLTags array
58
+ const sanitizedText = htmlText.replace(tagPattern, (match, tag, attributes) => {
59
+ const lowerCaseTag = tag.toLowerCase();
60
+
61
+ if (allowedHTMLTags.includes(lowerCaseTag)) {
62
+ return match; // Return the original tag if it's allowed
63
+ } else {
64
+ // Replace the disallowed tag with an empty string
65
+ return '';
66
+ }
67
+ });
68
+
69
+ return sanitizedText;
70
+ }
71
+
72
+ async onDOMLoad(): Promise<void>
73
+ {
74
+ return new Promise<void>((resolve) => {
75
+ document.addEventListener('DOMContentLoaded', () => {
76
+ resolve();
77
+ });
78
+ });
79
+ }
80
+
81
+ sanitizeHTML(
82
+ line: string,
83
+ sanitizeOptions: DOMPurify.Config = { })
84
+ {
85
+ const output: string = line.trim();
86
+ const sanitized = DOMPurify.sanitize(output, { USE_PROFILES: { html: true }, ...sanitizeOptions});
87
+ return sanitized;
88
+ }
89
+ }
90
+
91
+
92
+
93
+ export default DOMService.getSingleton();
94
94
  export { DOMOutputType, DOMService, TagsProcessorType, DOMService as DOMServiceInstance };
@@ -1,48 +1,48 @@
1
- import RWSNotify, { NotifyLogType } from '../types/RWSNotify';
2
- import TheService from './_service';
3
- /**
4
- * @class
5
- * @extends TheService
6
- */
7
- class NotifyService extends TheService {
8
- static _DEFAULT: boolean = true;
9
- private notifier: RWSNotify;
10
-
11
- public setNotifier(notifier: RWSNotify)
12
- {
13
- this.notifier = notifier;
14
- }
15
-
16
- public alert(message: string, logType: NotifyLogType = 'info', onConfirm?: (params: any) => void, alertOptions?: any): any
17
- {
18
- if(!this.notifier){
19
- console.warn('No notifier added to RWS Client');
20
- return;
21
- }
22
-
23
- return this.notifier(message, logType, 'alert', onConfirm, alertOptions);
24
- }
25
-
26
- public notify(message: string, logType: NotifyLogType = 'info', onConfirm?: (params: any) => void): void
27
- {
28
- if(!this.notifier){
29
- console.warn('No notifier added to RWS Client');
30
- return;
31
- }
32
-
33
- this.notifier(message, logType, 'notification', onConfirm);
34
- }
35
-
36
- public silent(message: string, logType: NotifyLogType = 'info'): void
37
- {
38
- if(!this.notifier){
39
- console.warn('No notifier added to RWS Client');
40
- return;
41
- }
42
-
43
- this.notifier(message, logType, 'silent');
44
- }
45
- }
46
-
47
- export default NotifyService.getSingleton();
1
+ import RWSNotify, { NotifyLogType } from '../types/RWSNotify';
2
+ import TheService from './_service';
3
+ /**
4
+ * @class
5
+ * @extends TheService
6
+ */
7
+ class NotifyService extends TheService {
8
+ static _DEFAULT: boolean = true;
9
+ private notifier: RWSNotify;
10
+
11
+ public setNotifier(notifier: RWSNotify)
12
+ {
13
+ this.notifier = notifier;
14
+ }
15
+
16
+ public alert(message: string, logType: NotifyLogType = 'info', onConfirm?: (params: any) => void, alertOptions?: any): any
17
+ {
18
+ if(!this.notifier){
19
+ console.warn('No notifier added to RWS Client');
20
+ return;
21
+ }
22
+
23
+ return this.notifier(message, logType, 'alert', onConfirm, alertOptions);
24
+ }
25
+
26
+ public notify(message: string, logType: NotifyLogType = 'info', onConfirm?: (params: any) => void): void
27
+ {
28
+ if(!this.notifier){
29
+ console.warn('No notifier added to RWS Client');
30
+ return;
31
+ }
32
+
33
+ this.notifier(message, logType, 'notification', onConfirm);
34
+ }
35
+
36
+ public silent(message: string, logType: NotifyLogType = 'info'): void
37
+ {
38
+ if(!this.notifier){
39
+ console.warn('No notifier added to RWS Client');
40
+ return;
41
+ }
42
+
43
+ this.notifier(message, logType, 'silent');
44
+ }
45
+ }
46
+
47
+ export default NotifyService.getSingleton();
48
48
  export { NotifyService as NotifyServiceInstance };
@@ -1,61 +1,61 @@
1
- import RWSService from './_service';
2
-
3
-
4
- class ServiceWorkerService extends RWSService {
5
- static _DEFAULT: boolean = true;
6
- async registerServiceWorker(): Promise<void>
7
- {
8
- await ServiceWorkerService.registerServiceWorker();
9
- }
10
-
11
- static registerServiceWorker(): Promise<void>
12
- {
13
- if ('serviceWorker' in navigator)
14
- {
15
- navigator.serviceWorker.getRegistrations().then(registrations => {
16
- if (registrations.length) {
17
- return;
18
- }
19
-
20
- try {
21
- return (navigator.serviceWorker.register(
22
- '/service_worker.js',
23
- {
24
- scope: '/'
25
- }
26
- ).then((registration) => {
27
- if (registration.installing) {
28
- console.log('Service worker installing');
29
- } else if (registration.waiting) {
30
- console.log('Service worker installed');
31
- } else if (registration.active) {
32
- console.log('Service worker active');
33
- }
34
- }));
35
-
36
- } catch (error) {
37
- console.error(`Registration failed with ${error}`);
38
- }
39
- });
40
-
41
- return;
42
- }
43
- }
44
-
45
- sendDataToServiceWorker(type: string, data: any, asset_type: string = 'data_push')
46
- {
47
- if (navigator.serviceWorker.controller) {
48
- navigator.serviceWorker.controller.postMessage({
49
- command: type,
50
- asset_type,
51
- params: data
52
- });
53
- } else {
54
- throw new Error('Service worker is not available');
55
- }
56
- }
57
- }
58
-
59
-
60
- export default ServiceWorkerService.getSingleton();
1
+ import RWSService from './_service';
2
+
3
+
4
+ class ServiceWorkerService extends RWSService {
5
+ static _DEFAULT: boolean = true;
6
+ async registerServiceWorker(): Promise<void>
7
+ {
8
+ await ServiceWorkerService.registerServiceWorker();
9
+ }
10
+
11
+ static registerServiceWorker(): Promise<void>
12
+ {
13
+ if ('serviceWorker' in navigator)
14
+ {
15
+ navigator.serviceWorker.getRegistrations().then(registrations => {
16
+ if (registrations.length) {
17
+ return;
18
+ }
19
+
20
+ try {
21
+ return (navigator.serviceWorker.register(
22
+ '/service_worker.js',
23
+ {
24
+ scope: '/'
25
+ }
26
+ ).then((registration) => {
27
+ if (registration.installing) {
28
+ console.log('Service worker installing');
29
+ } else if (registration.waiting) {
30
+ console.log('Service worker installed');
31
+ } else if (registration.active) {
32
+ console.log('Service worker active');
33
+ }
34
+ }));
35
+
36
+ } catch (error) {
37
+ console.error(`Registration failed with ${error}`);
38
+ }
39
+ });
40
+
41
+ return;
42
+ }
43
+ }
44
+
45
+ sendDataToServiceWorker(type: string, data: any, asset_type: string = 'data_push')
46
+ {
47
+ if (navigator.serviceWorker.controller) {
48
+ navigator.serviceWorker.controller.postMessage({
49
+ command: type,
50
+ asset_type,
51
+ params: data
52
+ });
53
+ } else {
54
+ throw new Error('Service worker is not available');
55
+ }
56
+ }
57
+ }
58
+
59
+
60
+ export default ServiceWorkerService.getSingleton();
61
61
  export { ServiceWorkerService as ServiceWorkerServiceInstance };