textbrowser 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.ncurc.cjs +3 -0
  2. package/CHANGES.md +13 -0
  3. package/dist/WorkInfo-es.js +655 -165
  4. package/dist/activateCallback-es.js +81 -10
  5. package/dist/dist/WorkInfo-es.d.ts +331 -0
  6. package/dist/dist/WorkInfo-es.d.ts.map +1 -0
  7. package/dist/dist/activateCallback-es.d.ts +17 -0
  8. package/dist/dist/activateCallback-es.d.ts.map +1 -0
  9. package/dist/dist/index-es.d.ts +619 -0
  10. package/dist/dist/index-es.d.ts.map +1 -0
  11. package/dist/dist/sw-helper.d.ts +3 -0
  12. package/dist/dist/sw-helper.d.ts.map +1 -0
  13. package/dist/eslint.config.d.ts +126 -0
  14. package/dist/eslint.config.d.ts.map +1 -0
  15. package/dist/index-es.js +3449 -1848
  16. package/dist/index-es.min.js +4 -4
  17. package/dist/resources/activateCallback.d.ts +23 -0
  18. package/dist/resources/activateCallback.d.ts.map +1 -0
  19. package/dist/resources/index.d.ts +128 -0
  20. package/dist/resources/index.d.ts.map +1 -0
  21. package/dist/resources/resultsDisplay.d.ts +110 -0
  22. package/dist/resources/resultsDisplay.d.ts.map +1 -0
  23. package/dist/resources/templates/index.d.ts +59 -0
  24. package/dist/resources/templates/index.d.ts.map +1 -0
  25. package/dist/resources/templates/languageSelect.d.ts +18 -0
  26. package/dist/resources/templates/languageSelect.d.ts.map +1 -0
  27. package/dist/resources/templates/resultsDisplayClient.d.ts +26 -0
  28. package/dist/resources/templates/resultsDisplayClient.d.ts.map +1 -0
  29. package/dist/resources/templates/resultsDisplayServerOrClient.d.ts +131 -0
  30. package/dist/resources/templates/resultsDisplayServerOrClient.d.ts.map +1 -0
  31. package/dist/resources/templates/utils/dom.d.ts +15 -0
  32. package/dist/resources/templates/utils/dom.d.ts.map +1 -0
  33. package/dist/resources/templates/utils/html.d.ts +3 -0
  34. package/dist/resources/templates/utils/html.d.ts.map +1 -0
  35. package/dist/resources/templates/workDisplay.d.ts +183 -0
  36. package/dist/resources/templates/workDisplay.d.ts.map +1 -0
  37. package/dist/resources/templates/workSelect.d.ts +18 -0
  38. package/dist/resources/templates/workSelect.d.ts.map +1 -0
  39. package/dist/resources/user-sample.d.ts +2 -0
  40. package/dist/resources/user-sample.d.ts.map +1 -0
  41. package/dist/resources/user.d.ts +2 -0
  42. package/dist/resources/user.d.ts.map +1 -0
  43. package/dist/resources/utils/IntlURLSearchParams.d.ts +56 -0
  44. package/dist/resources/utils/IntlURLSearchParams.d.ts.map +1 -0
  45. package/dist/resources/utils/Languages.d.ts +81 -0
  46. package/dist/resources/utils/Languages.d.ts.map +1 -0
  47. package/dist/resources/utils/Metadata.d.ts +133 -0
  48. package/dist/resources/utils/Metadata.d.ts.map +1 -0
  49. package/dist/resources/utils/Params.d.ts +30 -0
  50. package/dist/resources/utils/Params.d.ts.map +1 -0
  51. package/dist/resources/utils/Plugin.d.ts +278 -0
  52. package/dist/resources/utils/Plugin.d.ts.map +1 -0
  53. package/dist/resources/utils/ServiceWorker.d.ts +26 -0
  54. package/dist/resources/utils/ServiceWorker.d.ts.map +1 -0
  55. package/dist/resources/utils/WorkInfo.d.ts +104 -0
  56. package/dist/resources/utils/WorkInfo.d.ts.map +1 -0
  57. package/dist/resources/utils/dialogs.d.ts +155 -0
  58. package/dist/resources/utils/dialogs.d.ts.map +1 -0
  59. package/dist/resources/utils/getLocaleFallbackResults.d.ts +19 -0
  60. package/dist/resources/utils/getLocaleFallbackResults.d.ts.map +1 -0
  61. package/dist/resources/utils/sanitize.d.ts +6 -0
  62. package/dist/resources/utils/sanitize.d.ts.map +1 -0
  63. package/dist/resources/vendor/json-refs-min.d.ts +3 -0
  64. package/dist/resources/vendor/json-refs-min.d.ts.map +1 -0
  65. package/dist/resources/workDisplay.d.ts +81 -0
  66. package/dist/resources/workDisplay.d.ts.map +1 -0
  67. package/dist/resources/workSelect.d.ts +17 -0
  68. package/dist/resources/workSelect.d.ts.map +1 -0
  69. package/dist/rollup.config.d.ts +19 -0
  70. package/dist/rollup.config.d.ts.map +1 -0
  71. package/dist/server/main.d.ts +47 -0
  72. package/dist/server/main.d.ts.map +1 -0
  73. package/dist/sw-helper.d.ts +3 -0
  74. package/dist/sw-helper.d.ts.map +1 -0
  75. package/dist/sw-helper.js +52 -12
  76. package/dist/sw-sample.d.ts +2 -0
  77. package/dist/sw-sample.d.ts.map +1 -0
  78. package/general-schemas/files.jsonschema +6 -0
  79. package/package.json +32 -19
  80. package/resources/activateCallback.js +81 -10
  81. package/resources/index.js +169 -58
  82. package/resources/resultsDisplay.js +520 -153
  83. package/resources/templates/index.js +39 -17
  84. package/resources/templates/languageSelect.js +14 -1
  85. package/resources/templates/resultsDisplayClient.js +22 -3
  86. package/resources/templates/resultsDisplayServerOrClient.js +188 -49
  87. package/resources/templates/utils/dom.js +13 -2
  88. package/resources/templates/workDisplay.js +299 -76
  89. package/resources/templates/workSelect.js +16 -3
  90. package/resources/user-sample.js +1 -0
  91. package/resources/utils/IntlURLSearchParams.js +46 -4
  92. package/resources/utils/Languages.js +71 -4
  93. package/resources/utils/Metadata.js +222 -23
  94. package/resources/utils/Params.js +70 -23
  95. package/resources/utils/Plugin.js +175 -1
  96. package/resources/utils/ServiceWorker.js +49 -21
  97. package/resources/utils/WorkInfo.js +256 -44
  98. package/resources/utils/dialogs.js +105 -7
  99. package/resources/utils/getLocaleFallbackResults.js +15 -3
  100. package/resources/utils/sanitize.js +4 -0
  101. package/resources/workDisplay.js +151 -25
  102. package/resources/workSelect.js +37 -17
  103. package/server/main.js +118 -20
  104. package/sw-sample.js +2 -1
  105. package/tsconfig.json +30 -0
  106. package/resources/user.js +0 -20
@@ -1,19 +1,58 @@
1
1
  // Todo: Reimplement this with `formSerialize.deserialize` as possible
2
+
3
+ // @ts-expect-error Todo: Add types
2
4
  import {serialize as formSerialize} from 'form-serialization';
3
5
 
6
+ /**
7
+ * @param {URLSearchParams} paramsCopy
8
+ */
4
9
  export const replaceHash = (paramsCopy) => {
5
10
  return location.href.replace(/#.*$/, '') + '#' + paramsCopy.toString();
6
11
  };
7
12
 
8
- export const getSerializeParamsAsURL = function (...args) {
9
- const setter = getParamsSetter(...args);
10
- return function (...innerArgs) {
11
- const paramsCopy = setter(...innerArgs);
13
+ /**
14
+ * @param {{
15
+ * l: import('intl-dom').I18NCallback,
16
+ * lParam: (key: string) => string,
17
+ * $p: import('./IntlURLSearchParams.js').default
18
+ * }} args
19
+ */
20
+ export const getSerializeParamsAsURL = function (args) {
21
+ const setter = getParamsSetter(args);
22
+ /**
23
+ * @param {{
24
+ * form: HTMLFormElement,
25
+ * random: {checked: boolean},
26
+ * checkboxes: HTMLInputElement[],
27
+ * type: string,
28
+ * fieldAliasOrNames?: string[],
29
+ * workName?: string
30
+ * }} innerArg
31
+ */
32
+ return function (innerArg) {
33
+ const paramsCopy = setter(innerArg);
12
34
  return replaceHash(paramsCopy);
13
35
  };
14
36
  };
15
37
 
38
+ /**
39
+ * @param {{
40
+ * l: import('intl-dom').I18NCallback,
41
+ * lParam: (key: string) => string,
42
+ * $p: import('./IntlURLSearchParams.js').default
43
+ * }} cfg
44
+ */
16
45
  export const getParamsSetter = function ({l, lParam, $p}) {
46
+ /**
47
+ * @param {{
48
+ * form: HTMLFormElement,
49
+ * random: {checked: boolean},
50
+ * checkboxes: HTMLInputElement[],
51
+ * type: string,
52
+ * fieldAliasOrNames?: string[],
53
+ * workName?: string
54
+ * }} cfg
55
+ */
17
56
  return function ({form, random = {
18
57
  checked: false
19
58
  }, checkboxes, type, fieldAliasOrNames = [], workName}) {
@@ -26,7 +65,11 @@ export const getParamsSetter = function ({l, lParam, $p}) {
26
65
 
27
66
  // Follow the same style (and order) for checkboxes
28
67
  paramsCopy.delete(lParam('rand'));
29
- paramsCopy.set(lParam('rand'), random.checked ? l('yes') : l('no'));
68
+ paramsCopy.set(
69
+ lParam('rand'), /** @type {string} */ (
70
+ random.checked ? l('yes') : l('no')
71
+ )
72
+ );
30
73
 
31
74
  // We want checkboxes to typically show by default, so we cannot use the
32
75
  // standard serialization
@@ -34,7 +77,11 @@ export const getParamsSetter = function ({l, lParam, $p}) {
34
77
  // Let's ensure the checked items are all together (at the end)
35
78
  paramsCopy.delete(checkbox.name);
36
79
  if (checkbox.name) { // We don't want, e.g., preference controls added to URL
37
- paramsCopy.set(checkbox.name, checkbox.checked ? l('yes') : l('no'));
80
+ paramsCopy.set(
81
+ checkbox.name,
82
+ /** @type {string} */
83
+ (checkbox.checked ? l('yes') : l('no'))
84
+ );
38
85
  }
39
86
  });
40
87
 
@@ -45,11 +92,11 @@ export const getParamsSetter = function ({l, lParam, $p}) {
45
92
  function removeStartsEndsAndAnchors () {
46
93
  let num = 1;
47
94
  let num2 = 1;
48
- while (paramsCopy.has(`${workName}-start${num}-${num2}`, true)) {
49
- while (paramsCopy.has(`${workName}-start${num}-${num2}`, true)) {
50
- paramsCopy.delete(`${workName}-start${num}-${num2}`, true);
51
- paramsCopy.delete(`${workName}-end${num}-${num2}`, true);
52
- paramsCopy.delete(`${workName}-anchor${num}-${num2}`, true);
95
+ while (paramsCopy.has(`${workName}-start${num}-${num2}`)) {
96
+ while (paramsCopy.has(`${workName}-start${num}-${num2}`)) {
97
+ paramsCopy.delete(`${workName}-start${num}-${num2}`);
98
+ paramsCopy.delete(`${workName}-end${num}-${num2}`);
99
+ paramsCopy.delete(`${workName}-anchor${num}-${num2}`);
53
100
  num2++;
54
101
  }
55
102
  num2 = 1;
@@ -67,29 +114,29 @@ export const getParamsSetter = function ({l, lParam, $p}) {
67
114
  case 'shortcutResult': {
68
115
  paramsCopy.delete(lParam('rand'));
69
116
  let num = 1;
70
- while (paramsCopy.has(`anchorfield${num}`, true)) {
71
- paramsCopy.delete(`anchorfield${num}`, true);
117
+ while (paramsCopy.has(`anchorfield${num}`)) {
118
+ paramsCopy.delete(`anchorfield${num}`);
72
119
  num++;
73
120
  }
74
121
  removeStartsEndsAndAnchors();
75
122
 
76
123
  num = 1;
77
124
  // Delete field-specific so we can add our own
78
- while (paramsCopy.has(`field${num}`, true)) {
79
- paramsCopy.delete(`field${num}`, true);
80
- paramsCopy.delete(`checked${num}`, true);
81
- paramsCopy.delete(`interlin${num}`, true);
82
- paramsCopy.delete(`css${num}`, true);
125
+ while (paramsCopy.has(`field${num}`)) {
126
+ paramsCopy.delete(`field${num}`);
127
+ paramsCopy.delete(`checked${num}`);
128
+ paramsCopy.delete(`interlin${num}`);
129
+ paramsCopy.delete(`css${num}`);
83
130
  num++;
84
131
  }
85
132
  fieldAliasOrNames.forEach((fieldAliasOrName, i) => {
86
- paramsCopy.set(`field${i + 1}`, fieldAliasOrName, true);
133
+ paramsCopy.set(`field${i + 1}`, fieldAliasOrName);
87
134
  // Todo: Restrict by content locale?
88
- paramsCopy.set(`checked${i + 1}`, l('yes'), true);
135
+ paramsCopy.set(`checked${i + 1}`, /** @type {string} */ (l('yes')));
89
136
  paramsCopy.set(`interlin${i + 1}`, '');
90
137
  paramsCopy.set(`css${i + 1}`, '');
91
138
  });
92
- paramsCopy.delete('work', true);
139
+ paramsCopy.delete('work');
93
140
  }
94
141
  // Fallthrough
95
142
  case 'startEndResult':
@@ -102,9 +149,9 @@ export const getParamsSetter = function ({l, lParam, $p}) {
102
149
  // let's put random again toward the end.
103
150
  if (type === 'randomResult' || random.checked) {
104
151
  paramsCopy.delete(lParam('rand'));
105
- paramsCopy.set(lParam('rand'), l('yes'));
152
+ paramsCopy.set(lParam('rand'), /** @type {string} */ (l('yes')));
106
153
  }
107
- paramsCopy.set(lParam('result'), l('yes'));
154
+ paramsCopy.set(lParam('result'), /** @type {string} */ (l('yes')));
108
155
  break;
109
156
  }
110
157
  default: {
@@ -1,8 +1,18 @@
1
+ /**
2
+ * @typedef {number} Integer
3
+ */
4
+
5
+ /**
6
+ * @param {string} pluginName
7
+ */
1
8
  export const escapePluginComponent = (pluginName) => {
2
9
  return pluginName.replaceAll('^', '^^'). // Escape our escape
3
10
  replaceAll('-', '^0');
4
11
  };
5
12
 
13
+ /**
14
+ * @param {string|undefined} pluginName
15
+ */
6
16
  export const unescapePluginComponent = (pluginName) => {
7
17
  if (!pluginName) {
8
18
  return pluginName;
@@ -17,18 +27,126 @@ export const unescapePluginComponent = (pluginName) => {
17
27
  ).replaceAll('^^', '^');
18
28
  };
19
29
 
30
+ /**
31
+ * @param {{
32
+ * pluginName: string,
33
+ * applicableField: string,
34
+ * targetLanguage: string
35
+ * }} cfg
36
+ */
20
37
  export const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
21
38
  return escapePluginComponent(pluginName) +
22
39
  (applicableField ? '-' + escapePluginComponent(applicableField) : '-') +
23
40
  (targetLanguage ? '-' + escapePluginComponent(targetLanguage) : '');
24
41
  };
25
42
 
43
+ /* eslint-disable jsdoc/reject-any-type -- How to resolve? */
44
+ /**
45
+ * @typedef {any} MetaValue
46
+ */
47
+ /* eslint-enable jsdoc/reject-any-type -- Arbitrary */
48
+
49
+ /**
50
+ * @todo Complete
51
+ * @typedef {{
52
+ * path: string,
53
+ * onByDefault?: boolean,
54
+ * lang?: string,
55
+ * meta?: {[key: string]: string}
56
+ * getCellData?: (info: {
57
+ * tr: (string|Integer)[],
58
+ * tableData: (string|Integer)[][],
59
+ * i: number,
60
+ * j: number,
61
+ * applicableField?: string,
62
+ * fieldInfo: import('../resultsDisplay.js').FieldInfo,
63
+ * applicableFieldIdx: number,
64
+ * applicableFieldText: string|Integer,
65
+ * fieldLang: string,
66
+ * getLangDir: (locale: string) => string,
67
+ * meta: {
68
+ * [key: string]: string
69
+ * }|undefined,
70
+ * metaApplicableField?: {
71
+ * [key: string]: string
72
+ * },
73
+ * $p: import('./IntlURLSearchParams.js').default,
74
+ * thisObj: import('../index.js').default|import('../../server/main.js').ResultsDisplayServerContext
75
+ * }) => string|Integer,
76
+ * done: (info: {
77
+ * $p: import('./IntlURLSearchParams.js').default,
78
+ * applicableField: string|undefined,
79
+ * meta?: {[key: string]: string}
80
+ * thisObj: import('../index.js').default
81
+ * j?: number
82
+ * }) => void,
83
+ * getTargetLanguage: (info: {
84
+ * applicableField: string,
85
+ * targetLanguage?: string,
86
+ * pluginLang: string,
87
+ * applicableFieldLang?: string
88
+ * }) => string,
89
+ * escapeColumn?: boolean,
90
+ * getFieldAliasOrName: (info: {
91
+ * locales: string[],
92
+ * workI18n: import('intl-dom').I18NCallback,
93
+ * targetLanguage: string,
94
+ * applicableField: string,
95
+ * applicableFieldI18N: string|string[]|import("../../server/main.js").LocalizationStrings,
96
+ * meta: MetaValue,
97
+ * metaApplicableField: {
98
+ * [key: string]: string
99
+ * },
100
+ * targetLanguageI18N: string
101
+ * }) => string
102
+ * }} PluginObject
103
+ */
104
+
105
+ /**
106
+ * @typedef {{
107
+ * path: string,
108
+ * lang: string,
109
+ * meta: MetaValue,
110
+ * onByDefault: boolean
111
+ * }} PluginInfo
112
+ */
113
+
114
+ /**
115
+ * @typedef {{
116
+ * placement: "end"|number,
117
+ * 'applicable-fields': {
118
+ * [field: string]: {
119
+ * targetLanguage: string|string[],
120
+ * onByDefault: boolean,
121
+ * meta: {
122
+ * [key: string]: string
123
+ * },
124
+ * [args: string]: {}
125
+ * }
126
+ * },
127
+ * [fieldArgs: string]: {
128
+ * }
129
+ * }} PluginFieldMappingForWork
130
+ */
131
+
26
132
  export class PluginsForWork {
133
+ /**
134
+ * @param {{
135
+ * pluginsInWork: [string, PluginInfo][],
136
+ * pluginFieldMappings: PluginFieldMappingForWork[],
137
+ * pluginObjects: PluginObject[]
138
+ * }} cfg
139
+ */
27
140
  constructor ({pluginsInWork, pluginFieldMappings, pluginObjects}) {
28
141
  this.pluginsInWork = pluginsInWork;
29
142
  this.pluginFieldMappings = pluginFieldMappings;
30
143
  this.pluginObjects = pluginObjects;
31
144
  }
145
+
146
+ /**
147
+ * @param {string} pluginName
148
+ * @returns {PluginObject}
149
+ */
32
150
  getPluginObject (pluginName) {
33
151
  const idx = this.pluginsInWork.findIndex(([name]) => {
34
152
  return name === pluginName;
@@ -36,6 +154,25 @@ export class PluginsForWork {
36
154
  const plugin = this.pluginObjects[idx];
37
155
  return plugin;
38
156
  }
157
+
158
+ /**
159
+ * @param {(cfg: {
160
+ * plugin: PluginObject,
161
+ * placement: "end"|number,
162
+ * applicableFields: {
163
+ * [applicableField: string]: {
164
+ * targetLanguage: string|string[],
165
+ * onByDefault: boolean,
166
+ * meta: MetaValue
167
+ * }
168
+ * },
169
+ * pluginName: string,
170
+ * pluginLang: string,
171
+ * onByDefaultDefault: boolean,
172
+ * meta: {}
173
+ * }) => void} cb
174
+ * @returns {void}
175
+ */
39
176
  iterateMappings (cb) {
40
177
  this.pluginFieldMappings.forEach(({
41
178
  placement,
@@ -62,6 +199,25 @@ export class PluginsForWork {
62
199
  });
63
200
  });
64
201
  }
202
+
203
+ /**
204
+ * @param {{
205
+ * [applicableField: string]: {
206
+ * targetLanguage: string|string[],
207
+ * onByDefault: boolean,
208
+ * meta: MetaValue
209
+ * }
210
+ * }} applicableFields
211
+ * @param {(cfg: {
212
+ * applicableField: string,
213
+ * targetLanguage: string,
214
+ * onByDefault: boolean,
215
+ * metaApplicableField: {
216
+ * [key: string]: string
217
+ * }
218
+ * }) => void} cb
219
+ * @returns {boolean}
220
+ */
65
221
  processTargetLanguages (applicableFields, cb) {
66
222
  if (!applicableFields) {
67
223
  return false;
@@ -79,9 +235,25 @@ export class PluginsForWork {
79
235
  });
80
236
  return true;
81
237
  }
238
+
239
+ /**
240
+ * @param {{
241
+ * namespace: string,
242
+ * field: string
243
+ * }} cfg
244
+ * @returns {boolean}
245
+ */
82
246
  isPluginField ({namespace, field}) {
83
247
  return field.startsWith(`${namespace}-plugin-`);
84
248
  }
249
+
250
+ /**
251
+ * @param {{
252
+ * namespace: string,
253
+ * field: string
254
+ * }} cfg
255
+ * @returns {[string, string|undefined, string|undefined]}
256
+ */
85
257
  getPluginFieldParts ({namespace, field}) {
86
258
  field = field.replace(`${namespace}-plugin-`, '');
87
259
  let pluginName, applicableField, targetLanguage;
@@ -90,6 +262,8 @@ export class PluginsForWork {
90
262
  } else {
91
263
  pluginName = field;
92
264
  }
93
- return [pluginName, applicableField, targetLanguage].map(unescapePluginComponent);
265
+ return /** @type {[string, string|undefined, string|undefined]} */ (
266
+ [pluginName, applicableField, targetLanguage].map(unescapePluginComponent)
267
+ );
94
268
  }
95
269
  }
@@ -2,16 +2,21 @@
2
2
  import {dialogs} from './dialogs.js';
3
3
 
4
4
  /**
5
- * Note that this function be kept as a polyglot client-server file.
6
- * @param {PlainObject} target
7
- * @param {PlainObject} source
8
- * @returns {{
5
+ * @typedef {{
9
6
  * userJSON: string,
10
7
  * languages: string,
11
8
  * serviceWorkerPath: string,
12
9
  * files: string,
13
- * namespace: string
14
- * }}
10
+ * namespace: string,
11
+ * stylesheets?: string[]
12
+ * }} ServiceWorkerConfig
13
+ */
14
+
15
+ /**
16
+ * Note that this function be kept as a polyglot client-server file.
17
+ * @param {Partial<ServiceWorkerConfig>} target
18
+ * @param {Partial<ServiceWorkerConfig>} source
19
+ * @returns {ServiceWorkerConfig}
15
20
  */
16
21
  export const setServiceWorkerDefaults = (target, source) => {
17
22
  target.userJSON = source.userJSON || 'resources/user.json';
@@ -27,13 +32,18 @@ export const setServiceWorkerDefaults = (target, source) => {
27
32
  }`;
28
33
  target.files = source.files || 'files.json';
29
34
  target.namespace = source.namespace || 'textbrowser';
30
- return target;
35
+ return /** @type {ServiceWorkerConfig} */ (target);
31
36
  };
32
37
 
33
38
  // (Unless skipped in code, will wait between install
34
39
  // of new and activation of new or existing if still
35
40
  // some tabs open)
36
41
 
42
+ /**
43
+ * @param {{
44
+ * r: ServiceWorkerRegistration
45
+ * }} cfg
46
+ */
37
47
  export const listenForWorkerUpdate = ({
38
48
  r
39
49
  // logger
@@ -43,7 +53,7 @@ export const listenForWorkerUpdate = ({
43
53
  // r.installing now available (though r.active is also,
44
54
  // apparently due to prior activation; but not r.waiting)
45
55
  console.log('update found', e);
46
- const newWorker = r.installing;
56
+ const newWorker = /** @type {ServiceWorker} */ (r.installing);
47
57
 
48
58
  // statechange won't catch this installing event as already installing
49
59
 
@@ -97,13 +107,25 @@ for offline installation.
97
107
  });
98
108
  };
99
109
 
110
+ /**
111
+ * @typedef {{
112
+ * addLogEntry: (entry: {text: string}) => void,
113
+ * }} Logger
114
+ */
115
+
116
+ /**
117
+ * @param {{
118
+ * r: ServiceWorkerRegistration,
119
+ * logger: Logger
120
+ * }} cfg
121
+ */
100
122
  export const respondToState = async ({
101
123
  r, logger
102
124
  }) => {
103
125
  // We use this promise for rejecting (inside a listener)
104
126
  // to a common catch and to prevent continuation by
105
127
  // failing to return
106
- return new Promise(async () => { // eslint-disable-line no-async-promise-executor, sonarjs/no-misused-promises -- See above
128
+ return new Promise(async () => { // eslint-disable-line no-async-promise-executor -- See above
107
129
  navigator.serviceWorker.addEventListener('message', ({data}) => {
108
130
  const {message, type, name, errorType} = data;
109
131
  console.log('msg1', message, r);
@@ -157,20 +179,20 @@ export const respondToState = async ({
157
179
  }; trying again...`
158
180
  });
159
181
  /*
160
- if (errorType === 'dbError') {
161
- logger.dbError({
162
- type: name || errorType,
163
- escapedErrorMessage: escapeHTML(message)
164
- });
165
- }
166
- */
182
+ if (errorType === 'dbError') {
183
+ logger.dbError({
184
+ type: name || errorType,
185
+ escapedErrorMessage: escapeHTML(message)
186
+ });
187
+ }
188
+ */
167
189
  // Todo: auto-close any dbError dialog if retrying
168
190
  // No longer rejecting as should auto-retry
169
191
  /*
170
- const err = new Error(message);
171
- err.type = type;
172
- reject(err);
173
- */
192
+ const err = new Error(message);
193
+ err.type = type;
194
+ reject(err);
195
+ */
174
196
  break;
175
197
  default:
176
198
  console.error('Unexpected type', type);
@@ -219,6 +241,13 @@ any indication it is installing.
219
241
 
220
242
  // Keep in this file as may wish to avoid using for server (while still
221
243
  // doing other service worker work)
244
+
245
+ /**
246
+ * @param {{
247
+ * serviceWorkerPath: string,
248
+ * logger: Logger
249
+ * }} cfg
250
+ */
222
251
  export const registerServiceWorker = async ({
223
252
  serviceWorkerPath,
224
253
  logger
@@ -263,7 +292,6 @@ export const registerServiceWorker = async ({
263
292
  type: 'module'
264
293
  }
265
294
  );
266
- // eslint-disable-next-line no-unused-vars -- Ok
267
295
  } catch (err) {
268
296
  console.log('serviceWorkerPath', serviceWorkerPath);
269
297
  await dialogs.alert(`