textbrowser 0.49.1 → 0.51.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/.ncurc.cjs +3 -0
- package/CHANGES.md +14 -0
- package/dist/WorkInfo-es.js +262 -13
- package/dist/activateCallback-es.js +72 -10
- package/dist/dist/WorkInfo-es.d.ts +331 -0
- package/dist/dist/WorkInfo-es.d.ts.map +1 -0
- package/dist/dist/activateCallback-es.d.ts +17 -0
- package/dist/dist/activateCallback-es.d.ts.map +1 -0
- package/dist/dist/index-es.d.ts +619 -0
- package/dist/dist/index-es.d.ts.map +1 -0
- package/dist/dist/sw-helper.d.ts +3 -0
- package/dist/dist/sw-helper.d.ts.map +1 -0
- package/dist/eslint.config.d.ts +126 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/index-es.js +860 -134
- package/dist/index-es.min.js +2 -2
- package/dist/resources/activateCallback.d.ts +23 -0
- package/dist/resources/activateCallback.d.ts.map +1 -0
- package/dist/resources/index.d.ts +128 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/resultsDisplay.d.ts +110 -0
- package/dist/resources/resultsDisplay.d.ts.map +1 -0
- package/dist/resources/templates/index.d.ts +59 -0
- package/dist/resources/templates/index.d.ts.map +1 -0
- package/dist/resources/templates/languageSelect.d.ts +18 -0
- package/dist/resources/templates/languageSelect.d.ts.map +1 -0
- package/dist/resources/templates/resultsDisplayClient.d.ts +26 -0
- package/dist/resources/templates/resultsDisplayClient.d.ts.map +1 -0
- package/dist/resources/templates/resultsDisplayServerOrClient.d.ts +131 -0
- package/dist/resources/templates/resultsDisplayServerOrClient.d.ts.map +1 -0
- package/dist/resources/templates/utils/dom.d.ts +15 -0
- package/dist/resources/templates/utils/dom.d.ts.map +1 -0
- package/dist/resources/templates/utils/html.d.ts +3 -0
- package/dist/resources/templates/utils/html.d.ts.map +1 -0
- package/dist/resources/templates/workDisplay.d.ts +183 -0
- package/dist/resources/templates/workDisplay.d.ts.map +1 -0
- package/dist/resources/templates/workSelect.d.ts +18 -0
- package/dist/resources/templates/workSelect.d.ts.map +1 -0
- package/dist/resources/user-sample.d.ts +2 -0
- package/dist/resources/user-sample.d.ts.map +1 -0
- package/dist/resources/user.d.ts +2 -0
- package/dist/resources/user.d.ts.map +1 -0
- package/dist/resources/utils/IntlURLSearchParams.d.ts +56 -0
- package/dist/resources/utils/IntlURLSearchParams.d.ts.map +1 -0
- package/dist/resources/utils/Languages.d.ts +81 -0
- package/dist/resources/utils/Languages.d.ts.map +1 -0
- package/dist/resources/utils/Metadata.d.ts +133 -0
- package/dist/resources/utils/Metadata.d.ts.map +1 -0
- package/dist/resources/utils/Params.d.ts +30 -0
- package/dist/resources/utils/Params.d.ts.map +1 -0
- package/dist/resources/utils/Plugin.d.ts +274 -0
- package/dist/resources/utils/Plugin.d.ts.map +1 -0
- package/dist/resources/utils/ServiceWorker.d.ts +26 -0
- package/dist/resources/utils/ServiceWorker.d.ts.map +1 -0
- package/dist/resources/utils/WorkInfo.d.ts +104 -0
- package/dist/resources/utils/WorkInfo.d.ts.map +1 -0
- package/dist/resources/utils/dialogs.d.ts +155 -0
- package/dist/resources/utils/dialogs.d.ts.map +1 -0
- package/dist/resources/utils/getLocaleFallbackResults.d.ts +19 -0
- package/dist/resources/utils/getLocaleFallbackResults.d.ts.map +1 -0
- package/dist/resources/utils/sanitize.d.ts +6 -0
- package/dist/resources/utils/sanitize.d.ts.map +1 -0
- package/dist/resources/vendor/json-refs-min.d.ts +3 -0
- package/dist/resources/vendor/json-refs-min.d.ts.map +1 -0
- package/dist/resources/workDisplay.d.ts +81 -0
- package/dist/resources/workDisplay.d.ts.map +1 -0
- package/dist/resources/workSelect.d.ts +17 -0
- package/dist/resources/workSelect.d.ts.map +1 -0
- package/dist/rollup.config.d.ts +19 -0
- package/dist/rollup.config.d.ts.map +1 -0
- package/dist/server/main.d.ts +46 -0
- package/dist/server/main.d.ts.map +1 -0
- package/dist/sw-helper.d.ts +3 -0
- package/dist/sw-helper.d.ts.map +1 -0
- package/dist/sw-helper.js +52 -12
- package/dist/sw-sample.d.ts +2 -0
- package/dist/sw-sample.d.ts.map +1 -0
- package/general-schemas/files.jsonschema +6 -0
- package/package.json +22 -9
- package/resources/activateCallback.js +75 -10
- package/resources/index.js +161 -49
- package/resources/resultsDisplay.js +517 -152
- package/resources/templates/index.js +39 -16
- package/resources/templates/languageSelect.js +14 -1
- package/resources/templates/resultsDisplayClient.js +22 -3
- package/resources/templates/resultsDisplayServerOrClient.js +188 -49
- package/resources/templates/utils/dom.js +13 -2
- package/resources/templates/workDisplay.js +299 -75
- package/resources/templates/workSelect.js +16 -3
- package/resources/utils/IntlURLSearchParams.js +46 -4
- package/resources/utils/Languages.js +71 -4
- package/resources/utils/Metadata.js +219 -22
- package/resources/utils/Params.js +70 -23
- package/resources/utils/Plugin.js +169 -1
- package/resources/utils/ServiceWorker.js +48 -19
- package/resources/utils/WorkInfo.js +255 -43
- package/resources/utils/dialogs.js +105 -7
- package/resources/utils/getLocaleFallbackResults.js +12 -2
- package/resources/utils/sanitize.js +4 -0
- package/resources/workDisplay.js +151 -25
- package/resources/workSelect.js +37 -17
- package/server/main.js +111 -19
- package/tsconfig.json +30 -0
- package/resources/user.js +0 -20
package/.ncurc.cjs
CHANGED
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# CHANGES to `textbrowser`
|
|
2
2
|
|
|
3
|
+
## 0.51.0
|
|
4
|
+
|
|
5
|
+
- feat: TS support
|
|
6
|
+
- fix: `rememberRefusal` was not checking properly
|
|
7
|
+
- fix: request permissions would have been erring out
|
|
8
|
+
- fix: ensure `showEmptyInterlinear` and `showTitleOnSingleInterlinear` are
|
|
9
|
+
being passed on
|
|
10
|
+
|
|
11
|
+
## 0.50.0
|
|
12
|
+
|
|
13
|
+
- fix: revert apparent indexeddbshim regression
|
|
14
|
+
|
|
15
|
+
Versions past 12 have some apparent node-sqlite3 issues (after rollup, can't run server script)
|
|
16
|
+
|
|
3
17
|
## 0.49.1
|
|
4
18
|
|
|
5
19
|
- fix: apparent regression with `nodeActivate`
|
package/dist/WorkInfo-es.js
CHANGED
|
@@ -3195,12 +3195,23 @@ var i18n = function i18n() {
|
|
|
3195
3195
|
};
|
|
3196
3196
|
|
|
3197
3197
|
// Todo: remember this locales choice by cookie?
|
|
3198
|
+
|
|
3199
|
+
/**
|
|
3200
|
+
* @param {{
|
|
3201
|
+
* namespace: string,
|
|
3202
|
+
* preferredLocale: string
|
|
3203
|
+
* }} cfg
|
|
3204
|
+
*/
|
|
3198
3205
|
const getPreferredLanguages = ({namespace, preferredLocale}) => {
|
|
3199
3206
|
// Todo: Add to this optionally with one-off tag input box
|
|
3200
3207
|
// Todo: Switch to fallbackLanguages so can default to
|
|
3201
3208
|
// navigator.languages?
|
|
3202
3209
|
const langCodes = localStorage.getItem(namespace + '-langCodes');
|
|
3203
|
-
const lngs =
|
|
3210
|
+
const lngs = /** @type {string[]} */ (
|
|
3211
|
+
(langCodes && JSON.parse(langCodes)) || [preferredLocale]
|
|
3212
|
+
);
|
|
3213
|
+
|
|
3214
|
+
/** @type {string[]} */
|
|
3204
3215
|
const langArr = [];
|
|
3205
3216
|
lngs.forEach((lng) => {
|
|
3206
3217
|
// Todo: Check for multiple separate hyphenated
|
|
@@ -3234,14 +3245,46 @@ const getCurrDir = () => {
|
|
|
3234
3245
|
return window.location.href.replace(/(index\.html)?#.*$/, '');
|
|
3235
3246
|
};
|
|
3236
3247
|
|
|
3248
|
+
/**
|
|
3249
|
+
* @typedef {{
|
|
3250
|
+
* "localization-strings": import('../../server/main.js').LocalizationStrings
|
|
3251
|
+
* table: {browse_fields: (string|{
|
|
3252
|
+
* name?: string,
|
|
3253
|
+
* set: string[],
|
|
3254
|
+
* presort?: boolean
|
|
3255
|
+
* })[]}
|
|
3256
|
+
* fields: {
|
|
3257
|
+
* [key: string]: {
|
|
3258
|
+
* prefer_alias: boolean,
|
|
3259
|
+
* lang: string,
|
|
3260
|
+
* 'fieldvalue-aliases': {
|
|
3261
|
+
* localeKey: string,
|
|
3262
|
+
* [key: string]: string|string[]
|
|
3263
|
+
* }
|
|
3264
|
+
* }
|
|
3265
|
+
* }
|
|
3266
|
+
* }} MetadataObj
|
|
3267
|
+
*/
|
|
3268
|
+
|
|
3269
|
+
/**
|
|
3270
|
+
* @param {string[]} lang
|
|
3271
|
+
* @param {MetadataObj} metadataObj
|
|
3272
|
+
* @param {string|string[]} properties
|
|
3273
|
+
* @param {boolean} [allowObjects]
|
|
3274
|
+
* @returns {string|string[]|import('../../server/main.js').LocalizationStrings}
|
|
3275
|
+
*/
|
|
3237
3276
|
const getMetaProp = function getMetaProp (lang, metadataObj, properties, allowObjects) {
|
|
3238
3277
|
let prop;
|
|
3239
3278
|
properties = typeof properties === 'string' ? [properties] : properties;
|
|
3240
|
-
|
|
3279
|
+
for (const lan of lang) {
|
|
3241
3280
|
const p = [...properties];
|
|
3242
|
-
let strings =
|
|
3281
|
+
let strings = /** @type {string | string[]|import('../../server/main.js').LocalizationStrings} */ (
|
|
3282
|
+
metadataObj['localization-strings'][lan]
|
|
3283
|
+
);
|
|
3243
3284
|
while (strings && p.length) {
|
|
3244
|
-
strings =
|
|
3285
|
+
strings = /** @type {import('../../server/main.js').LocalizationStrings} */ (
|
|
3286
|
+
strings
|
|
3287
|
+
)[/** @type {string} */ (p.shift())];
|
|
3245
3288
|
}
|
|
3246
3289
|
// Todo: Fix this allowance for allowObjects (as it does not properly
|
|
3247
3290
|
// fallback if an object is returned from a language because
|
|
@@ -3250,9 +3293,13 @@ const getMetaProp = function getMetaProp (lang, metadataObj, properties, allowOb
|
|
|
3250
3293
|
prop = (typeof strings === 'string')
|
|
3251
3294
|
? strings
|
|
3252
3295
|
: undefined;
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3296
|
+
if (prop) {
|
|
3297
|
+
break;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
return /** @type {string|string[]|import('../../server/main.js').LocalizationStrings} */ (
|
|
3301
|
+
prop
|
|
3302
|
+
);
|
|
3256
3303
|
};
|
|
3257
3304
|
|
|
3258
3305
|
// Use the following to dynamically add specific file schema in place of
|
|
@@ -3260,6 +3307,12 @@ const getMetaProp = function getMetaProp (lang, metadataObj, properties, allowOb
|
|
|
3260
3307
|
// filesSchema.properties.groups.items.properties.files.items.properties.
|
|
3261
3308
|
// file.anyOf.splice(1, 1, {$ref: schemaFile});
|
|
3262
3309
|
// Todo: Allow use of dbs and fileGroup together in base directories?
|
|
3310
|
+
|
|
3311
|
+
/**
|
|
3312
|
+
* @param {string} file
|
|
3313
|
+
* @param {string} property
|
|
3314
|
+
* @param {string} basePath
|
|
3315
|
+
*/
|
|
3263
3316
|
const getMetadata = async (file, property, basePath) => {
|
|
3264
3317
|
const url = new URL(basePath || getCurrDir());
|
|
3265
3318
|
url.search = ''; // Clear out query string, e.g., `?fbclid` from Facebook
|
|
@@ -3271,6 +3324,13 @@ const getMetadata = async (file, property, basePath) => {
|
|
|
3271
3324
|
url.toString(),
|
|
3272
3325
|
{
|
|
3273
3326
|
loaderOptions: {
|
|
3327
|
+
/**
|
|
3328
|
+
* @param {{
|
|
3329
|
+
* text: string,
|
|
3330
|
+
* body: any
|
|
3331
|
+
* }} res
|
|
3332
|
+
* @param {(err?: Error, cbValue: any) => void} callback
|
|
3333
|
+
*/
|
|
3274
3334
|
processContent (res, callback) {
|
|
3275
3335
|
callback(undefined, JSON.parse(
|
|
3276
3336
|
res.text ||
|
|
@@ -3286,16 +3346,37 @@ const getMetadata = async (file, property, basePath) => {
|
|
|
3286
3346
|
|
|
3287
3347
|
// Todo: Incorporate other methods into this class
|
|
3288
3348
|
class Metadata {
|
|
3349
|
+
/**
|
|
3350
|
+
* @param {{
|
|
3351
|
+
* metadataObj: MetadataObj
|
|
3352
|
+
* }} cfg
|
|
3353
|
+
*/
|
|
3289
3354
|
constructor ({metadataObj}) {
|
|
3290
3355
|
this.metadataObj = metadataObj;
|
|
3291
3356
|
}
|
|
3292
3357
|
|
|
3358
|
+
/**
|
|
3359
|
+
* @param {string} field
|
|
3360
|
+
* @returns {string|undefined}
|
|
3361
|
+
*/
|
|
3293
3362
|
getFieldLang (field) {
|
|
3294
3363
|
const {metadataObj} = this;
|
|
3295
3364
|
const fields = metadataObj && metadataObj.fields;
|
|
3296
3365
|
return fields && fields[field] && fields[field].lang;
|
|
3297
3366
|
}
|
|
3298
3367
|
|
|
3368
|
+
/**
|
|
3369
|
+
* @param {{
|
|
3370
|
+
* namespace: string,
|
|
3371
|
+
* preferredLocale: string,
|
|
3372
|
+
* schemaItems: {
|
|
3373
|
+
* title: string,
|
|
3374
|
+
* type: string
|
|
3375
|
+
* }[],
|
|
3376
|
+
* pluginsForWork: import('./Plugin.js').PluginsForWork
|
|
3377
|
+
* }} cfg
|
|
3378
|
+
* @returns {(field: string) => boolean}
|
|
3379
|
+
*/
|
|
3299
3380
|
getFieldMatchesLocale ({
|
|
3300
3381
|
namespace, preferredLocale, schemaItems,
|
|
3301
3382
|
pluginsForWork
|
|
@@ -3322,7 +3403,9 @@ class Metadata {
|
|
|
3322
3403
|
const hasFieldValue = localeStrings &&
|
|
3323
3404
|
Object.keys(localeStrings).some((lng) => {
|
|
3324
3405
|
const fv = localeStrings[lng] &&
|
|
3325
|
-
|
|
3406
|
+
/** @type {import('../../server/main.js').LocalizationStrings} */
|
|
3407
|
+
(/** @type {import('../../server/main.js').LocalizationStrings} */
|
|
3408
|
+
(localeStrings[lng]).fieldvalue);
|
|
3326
3409
|
return fv && fv[field];
|
|
3327
3410
|
});
|
|
3328
3411
|
|
|
@@ -3335,11 +3418,17 @@ class Metadata {
|
|
|
3335
3418
|
}
|
|
3336
3419
|
}
|
|
3337
3420
|
|
|
3421
|
+
/**
|
|
3422
|
+
* @param {string} pluginName
|
|
3423
|
+
*/
|
|
3338
3424
|
const escapePluginComponent = (pluginName) => {
|
|
3339
3425
|
return pluginName.replaceAll('^', '^^'). // Escape our escape
|
|
3340
3426
|
replaceAll('-', '^0');
|
|
3341
3427
|
};
|
|
3342
3428
|
|
|
3429
|
+
/**
|
|
3430
|
+
* @param {string|undefined} pluginName
|
|
3431
|
+
*/
|
|
3343
3432
|
const unescapePluginComponent = (pluginName) => {
|
|
3344
3433
|
if (!pluginName) {
|
|
3345
3434
|
return pluginName;
|
|
@@ -3354,18 +3443,50 @@ const unescapePluginComponent = (pluginName) => {
|
|
|
3354
3443
|
).replaceAll('^^', '^');
|
|
3355
3444
|
};
|
|
3356
3445
|
|
|
3446
|
+
/**
|
|
3447
|
+
* @param {{
|
|
3448
|
+
* pluginName: string,
|
|
3449
|
+
* applicableField: string,
|
|
3450
|
+
* targetLanguage: string
|
|
3451
|
+
* }} cfg
|
|
3452
|
+
*/
|
|
3357
3453
|
const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
|
|
3358
3454
|
return escapePluginComponent(pluginName) +
|
|
3359
3455
|
(applicableField ? '-' + escapePluginComponent(applicableField) : '-') +
|
|
3360
3456
|
(targetLanguage ? '-' + escapePluginComponent(targetLanguage) : '');
|
|
3361
3457
|
};
|
|
3362
3458
|
|
|
3459
|
+
/**
|
|
3460
|
+
* @todo Complete
|
|
3461
|
+
* @typedef {{}} PluginObject
|
|
3462
|
+
*/
|
|
3463
|
+
|
|
3363
3464
|
class PluginsForWork {
|
|
3465
|
+
/**
|
|
3466
|
+
* @param {{
|
|
3467
|
+
* pluginsInWork: [string, {
|
|
3468
|
+
* lang: string,
|
|
3469
|
+
* meta: any,
|
|
3470
|
+
* onByDefault: boolean
|
|
3471
|
+
* }][],
|
|
3472
|
+
* pluginFieldMappings: {
|
|
3473
|
+
* placement: string,
|
|
3474
|
+
* 'applicable-fields': {
|
|
3475
|
+
* }
|
|
3476
|
+
* }[],
|
|
3477
|
+
* pluginObjects: PluginObject[]
|
|
3478
|
+
* }} cfg
|
|
3479
|
+
*/
|
|
3364
3480
|
constructor ({pluginsInWork, pluginFieldMappings, pluginObjects}) {
|
|
3365
3481
|
this.pluginsInWork = pluginsInWork;
|
|
3366
3482
|
this.pluginFieldMappings = pluginFieldMappings;
|
|
3367
3483
|
this.pluginObjects = pluginObjects;
|
|
3368
3484
|
}
|
|
3485
|
+
|
|
3486
|
+
/**
|
|
3487
|
+
* @param {string} pluginName
|
|
3488
|
+
* @returns {PluginObject}
|
|
3489
|
+
*/
|
|
3369
3490
|
getPluginObject (pluginName) {
|
|
3370
3491
|
const idx = this.pluginsInWork.findIndex(([name]) => {
|
|
3371
3492
|
return name === pluginName;
|
|
@@ -3373,6 +3494,25 @@ class PluginsForWork {
|
|
|
3373
3494
|
const plugin = this.pluginObjects[idx];
|
|
3374
3495
|
return plugin;
|
|
3375
3496
|
}
|
|
3497
|
+
|
|
3498
|
+
/**
|
|
3499
|
+
* @param {(cfg: {
|
|
3500
|
+
* plugin: PluginObject,
|
|
3501
|
+
* placement: string,
|
|
3502
|
+
* applicableFields: {
|
|
3503
|
+
* [applicableField: string]: {
|
|
3504
|
+
* targetLanguage: string|string[],
|
|
3505
|
+
* onByDefault: boolean,
|
|
3506
|
+
* meta: any
|
|
3507
|
+
* }
|
|
3508
|
+
* },
|
|
3509
|
+
* pluginName: string,
|
|
3510
|
+
* pluginLang: string,
|
|
3511
|
+
* onByDefaultDefault: boolean,
|
|
3512
|
+
* meta: {}
|
|
3513
|
+
* }) => void} cb
|
|
3514
|
+
* @returns {void}
|
|
3515
|
+
*/
|
|
3376
3516
|
iterateMappings (cb) {
|
|
3377
3517
|
this.pluginFieldMappings.forEach(({
|
|
3378
3518
|
placement,
|
|
@@ -3399,6 +3539,25 @@ class PluginsForWork {
|
|
|
3399
3539
|
});
|
|
3400
3540
|
});
|
|
3401
3541
|
}
|
|
3542
|
+
|
|
3543
|
+
/**
|
|
3544
|
+
* @param {{
|
|
3545
|
+
* [applicableField: string]: {
|
|
3546
|
+
* targetLanguage: string|string[],
|
|
3547
|
+
* onByDefault: boolean,
|
|
3548
|
+
* meta: any
|
|
3549
|
+
* }
|
|
3550
|
+
* }} applicableFields
|
|
3551
|
+
* @param {(cfg: {
|
|
3552
|
+
* applicableField: string,
|
|
3553
|
+
* targetLanguage: string,
|
|
3554
|
+
* onByDefault: boolean,
|
|
3555
|
+
* metaApplicableField: {
|
|
3556
|
+
* [key: string]: string
|
|
3557
|
+
* }
|
|
3558
|
+
* }) => void} cb
|
|
3559
|
+
* @returns {boolean}
|
|
3560
|
+
*/
|
|
3402
3561
|
processTargetLanguages (applicableFields, cb) {
|
|
3403
3562
|
if (!applicableFields) {
|
|
3404
3563
|
return false;
|
|
@@ -3416,9 +3575,25 @@ class PluginsForWork {
|
|
|
3416
3575
|
});
|
|
3417
3576
|
return true;
|
|
3418
3577
|
}
|
|
3578
|
+
|
|
3579
|
+
/**
|
|
3580
|
+
* @param {{
|
|
3581
|
+
* namespace: string,
|
|
3582
|
+
* field: string
|
|
3583
|
+
* }} cfg
|
|
3584
|
+
* @returns {boolean}
|
|
3585
|
+
*/
|
|
3419
3586
|
isPluginField ({namespace, field}) {
|
|
3420
3587
|
return field.startsWith(`${namespace}-plugin-`);
|
|
3421
3588
|
}
|
|
3589
|
+
|
|
3590
|
+
/**
|
|
3591
|
+
* @param {{
|
|
3592
|
+
* namespace: string,
|
|
3593
|
+
* field: string
|
|
3594
|
+
* }} cfg
|
|
3595
|
+
* @returns {[string, string|undefined, string|undefined]}
|
|
3596
|
+
*/
|
|
3422
3597
|
getPluginFieldParts ({namespace, field}) {
|
|
3423
3598
|
field = field.replace(`${namespace}-plugin-`, '');
|
|
3424
3599
|
let pluginName, applicableField, targetLanguage;
|
|
@@ -3427,20 +3602,64 @@ class PluginsForWork {
|
|
|
3427
3602
|
} else {
|
|
3428
3603
|
pluginName = field;
|
|
3429
3604
|
}
|
|
3430
|
-
return [
|
|
3605
|
+
return /** @type {[string, string|undefined, string|undefined]} */ (
|
|
3606
|
+
[pluginName, applicableField, targetLanguage].map(unescapePluginComponent)
|
|
3607
|
+
);
|
|
3431
3608
|
}
|
|
3432
3609
|
}
|
|
3433
3610
|
|
|
3434
3611
|
/* globals process -- Node polyglot */
|
|
3435
3612
|
|
|
3613
|
+
/**
|
|
3614
|
+
* @typedef {number} Integer
|
|
3615
|
+
*/
|
|
3616
|
+
/**
|
|
3617
|
+
* @typedef {{
|
|
3618
|
+
* schema: {$ref: string},
|
|
3619
|
+
* metadata: {$ref: string},
|
|
3620
|
+
* data: (Integer|string)[]
|
|
3621
|
+
* }} WorkTableContainer
|
|
3622
|
+
*/
|
|
3623
|
+
|
|
3624
|
+
/**
|
|
3625
|
+
* @typedef {{
|
|
3626
|
+
* file: {
|
|
3627
|
+
* $ref: string
|
|
3628
|
+
* },
|
|
3629
|
+
* schemaFile: string,
|
|
3630
|
+
* metadataFile: string,
|
|
3631
|
+
* name: string,
|
|
3632
|
+
* }} FileData
|
|
3633
|
+
*/
|
|
3634
|
+
|
|
3635
|
+
/**
|
|
3636
|
+
* @typedef {{
|
|
3637
|
+
* files: FileData[],
|
|
3638
|
+
* baseDirectory?: string,
|
|
3639
|
+
* schemaBaseDirectory?: string,
|
|
3640
|
+
* metadataBaseDirectory?: string,
|
|
3641
|
+
* }} FileGroup
|
|
3642
|
+
*/
|
|
3643
|
+
|
|
3644
|
+
/**
|
|
3645
|
+
* INCOMPLETE typing.
|
|
3646
|
+
* @typedef {{
|
|
3647
|
+
* groups: FileGroup[],
|
|
3648
|
+
* plugins: {[key: string]: {path: string}},
|
|
3649
|
+
* baseDirectory?: string,
|
|
3650
|
+
* schemaBaseDirectory?: string,
|
|
3651
|
+
* metadataBaseDirectory?: string,
|
|
3652
|
+
* }} FilesObject
|
|
3653
|
+
*/
|
|
3654
|
+
|
|
3436
3655
|
/**
|
|
3437
3656
|
* Imported by the `dist/sw-helper.js`
|
|
3438
3657
|
* @param {string} files The files.json file path
|
|
3439
|
-
* @returns {
|
|
3658
|
+
* @returns {Promise<string[]>}
|
|
3440
3659
|
*/
|
|
3441
3660
|
const getWorkFiles = async function getWorkFiles (files) {
|
|
3442
|
-
const filesObj = await getJSON(files);
|
|
3443
|
-
const dataFiles = [];
|
|
3661
|
+
const filesObj = /** @type {FilesObject} */ (await getJSON(files));
|
|
3662
|
+
const dataFiles = /** @type {string[]} */ ([]);
|
|
3444
3663
|
filesObj.groups.forEach((fileGroup) => {
|
|
3445
3664
|
fileGroup.files.forEach((fileData) => {
|
|
3446
3665
|
const {file, schemaFile, metadataFile} =
|
|
@@ -3454,6 +3673,11 @@ const getWorkFiles = async function getWorkFiles (files) {
|
|
|
3454
3673
|
return dataFiles;
|
|
3455
3674
|
};
|
|
3456
3675
|
|
|
3676
|
+
/**
|
|
3677
|
+
* @param {FilesObject} filesObj
|
|
3678
|
+
* @param {FileGroup} fileGroup
|
|
3679
|
+
* @param {FileData} fileData
|
|
3680
|
+
*/
|
|
3457
3681
|
const getFilePaths = function getFilePaths (filesObj, fileGroup, fileData) {
|
|
3458
3682
|
const baseDir = (filesObj.baseDirectory || '') + (fileGroup.baseDirectory || '') + '/';
|
|
3459
3683
|
const schemaBaseDir = (filesObj.schemaBaseDirectory || '') +
|
|
@@ -3467,12 +3691,37 @@ const getFilePaths = function getFilePaths (filesObj, fileGroup, fileData) {
|
|
|
3467
3691
|
return {file, schemaFile, metadataFile};
|
|
3468
3692
|
};
|
|
3469
3693
|
|
|
3694
|
+
/**
|
|
3695
|
+
* @typedef {{
|
|
3696
|
+
* lang: string[],
|
|
3697
|
+
* fallbackLanguages: string[],
|
|
3698
|
+
* work: string,
|
|
3699
|
+
* files: string,
|
|
3700
|
+
* allowPlugins: boolean|undefined,
|
|
3701
|
+
* basePath: string,
|
|
3702
|
+
* languages: import('./Languages.js').Languages,
|
|
3703
|
+
* preferredLocale: string
|
|
3704
|
+
* }} GetWorkDataOptions
|
|
3705
|
+
*/
|
|
3706
|
+
|
|
3707
|
+
/**
|
|
3708
|
+
* @param {GetWorkDataOptions} cfg
|
|
3709
|
+
*/
|
|
3470
3710
|
const getWorkData = async function ({
|
|
3471
3711
|
lang, fallbackLanguages, work, files, allowPlugins, basePath,
|
|
3472
3712
|
languages, preferredLocale
|
|
3473
3713
|
}) {
|
|
3474
3714
|
const filesObj = await getJSON(files);
|
|
3475
|
-
const localizationStrings =
|
|
3715
|
+
const localizationStrings =
|
|
3716
|
+
/**
|
|
3717
|
+
* @type {{
|
|
3718
|
+
* "localization-strings": {
|
|
3719
|
+
* [key: string]: {}
|
|
3720
|
+
* }
|
|
3721
|
+
* }}
|
|
3722
|
+
*/ (
|
|
3723
|
+
filesObj
|
|
3724
|
+
)?.['localization-strings'];
|
|
3476
3725
|
|
|
3477
3726
|
const workI18n = await i18n({
|
|
3478
3727
|
messageStyle: 'plainNested',
|
|
@@ -4,7 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/* eslint-env worker -- Worker environment */
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('./utils/Metadata.js')} MetadataFile
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {number} Integer
|
|
13
|
+
*/
|
|
7
14
|
const {ceil} = Math;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {any[]} arr
|
|
18
|
+
* @param {number} size
|
|
19
|
+
*/
|
|
8
20
|
const arrayChunk = (arr, size) => {
|
|
9
21
|
return Array.from({length: ceil(arr.length / size)}, (_, i) => {
|
|
10
22
|
const offset = i * size;
|
|
@@ -25,9 +37,9 @@ const arrayChunk = (arr, size) => {
|
|
|
25
37
|
*/
|
|
26
38
|
|
|
27
39
|
/**
|
|
28
|
-
* @param {
|
|
40
|
+
* @param {object} cfg
|
|
29
41
|
* @param {string} cfg.namespace
|
|
30
|
-
* @param {string
|
|
42
|
+
* @param {string} cfg.files The files.json path
|
|
31
43
|
* @param {Logger} cfg.log
|
|
32
44
|
* @param {string} [cfg.basePath]
|
|
33
45
|
* @returns {Promise<void>}
|
|
@@ -41,17 +53,34 @@ async function activateCallback ({
|
|
|
41
53
|
// already-running versions upon future sw updates
|
|
42
54
|
log('Activate: Callback called');
|
|
43
55
|
const r = await fetch(files);
|
|
44
|
-
const {groups} =
|
|
56
|
+
const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
|
|
57
|
+
await r.json()
|
|
58
|
+
);
|
|
45
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @param {any[]} arr
|
|
62
|
+
* @param {string} path
|
|
63
|
+
*/
|
|
46
64
|
const addJSONFetch = (arr, path) => {
|
|
47
65
|
arr.push(
|
|
48
66
|
(async () => (await fetch(basePath + path)).json())()
|
|
49
67
|
);
|
|
50
68
|
};
|
|
51
69
|
|
|
70
|
+
/** @type {string[]} */
|
|
52
71
|
const dataFileNames = [];
|
|
72
|
+
|
|
73
|
+
/** @type {import('./utils/WorkInfo.js').WorkTableContainer[]} */
|
|
53
74
|
const dataFiles = [];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {import('json-schema').JSONSchema4} SchemaFile
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/** @type {SchemaFile[]} */
|
|
54
81
|
const schemaFiles = [];
|
|
82
|
+
|
|
83
|
+
/** @type {MetadataFile[]} */
|
|
55
84
|
const metadataFiles = [];
|
|
56
85
|
groups.forEach(
|
|
57
86
|
({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
|
|
@@ -59,8 +88,8 @@ async function activateCallback ({
|
|
|
59
88
|
// We don't i18nize the name here
|
|
60
89
|
dataFileNames.push(name);
|
|
61
90
|
addJSONFetch(dataFiles, filePath);
|
|
62
|
-
addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
|
|
63
91
|
addJSONFetch(schemaFiles, schemaBaseDirectory + '/' + schemaFile);
|
|
92
|
+
addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
|
|
64
93
|
});
|
|
65
94
|
}
|
|
66
95
|
);
|
|
@@ -69,18 +98,20 @@ async function activateCallback ({
|
|
|
69
98
|
]);
|
|
70
99
|
const chunked = arrayChunk(promises, dataFiles.length);
|
|
71
100
|
const [
|
|
72
|
-
|
|
101
|
+
, schemaFileResponses, metadataFileResponses
|
|
73
102
|
] = chunked;
|
|
103
|
+
const dataFileResponses = /** @type {{data: (Integer|string)[][]}[]} */ (chunked[0]);
|
|
74
104
|
|
|
75
105
|
log('Activate: Files fetched');
|
|
76
106
|
const dbName = namespace + '-textbrowser-cache-data';
|
|
77
107
|
indexedDB.deleteDatabase(dbName);
|
|
78
108
|
return new Promise((resolve, reject) => {
|
|
79
109
|
const req = indexedDB.open(dbName);
|
|
110
|
+
// @ts-expect-error Ok
|
|
80
111
|
req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
|
|
81
112
|
db.onversionchange = () => {
|
|
82
113
|
db.close();
|
|
83
|
-
const err = new Error('versionchange');
|
|
114
|
+
const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
|
|
84
115
|
err.type = 'versionchange';
|
|
85
116
|
reject(err);
|
|
86
117
|
};
|
|
@@ -90,11 +121,27 @@ async function activateCallback ({
|
|
|
90
121
|
|
|
91
122
|
const schemaFileResponse = schemaFileResponses[i];
|
|
92
123
|
const metadataFileResponse = metadataFileResponses[i];
|
|
93
|
-
const fieldItems =
|
|
124
|
+
const fieldItems = /** @type {{title: string}[]} */ (
|
|
125
|
+
schemaFileResponse.items.items
|
|
126
|
+
);
|
|
94
127
|
|
|
95
|
-
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {{
|
|
130
|
+
* name?: string,
|
|
131
|
+
* presort?: boolean,
|
|
132
|
+
* set: string[]
|
|
133
|
+
* }} NameSet
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
let browseFields =
|
|
137
|
+
/**
|
|
138
|
+
* @type {(string|NameSet)[]|NameSet}
|
|
139
|
+
*/ (
|
|
140
|
+
metadataFileResponse.table.browse_fields
|
|
141
|
+
);
|
|
96
142
|
browseFields = Array.isArray(browseFields) ? browseFields : [browseFields];
|
|
97
143
|
|
|
144
|
+
/** @type {string[]} */
|
|
98
145
|
const columnIndexes = [];
|
|
99
146
|
browseFields.forEach((browseFieldSetObj) => {
|
|
100
147
|
if (typeof browseFieldSetObj === 'string') {
|
|
@@ -133,24 +180,39 @@ async function activateCallback ({
|
|
|
133
180
|
// Todo: Optionally send notice when complete
|
|
134
181
|
// To take advantage of indexes on our arrays, we
|
|
135
182
|
// need to transform them to objects! See https://github.com/w3c/IndexedDB/issues/209
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @type {{
|
|
186
|
+
* [key: string]: string|Integer|(Integer|string)[]
|
|
187
|
+
* }}
|
|
188
|
+
*/
|
|
136
189
|
const objRow = {
|
|
137
190
|
value: tableRow
|
|
138
191
|
};
|
|
139
192
|
uniqueColumnIndexes.forEach((colIdx) => {
|
|
140
|
-
objRow[colIdx] = tableRow[colIdx.slice(1)];
|
|
193
|
+
objRow[colIdx] = tableRow[Number.parseInt(colIdx.slice(1))];
|
|
141
194
|
});
|
|
142
195
|
// log('objRow', objRow);
|
|
143
196
|
store.put(objRow, j);
|
|
144
197
|
});
|
|
145
198
|
});
|
|
146
199
|
});
|
|
200
|
+
|
|
201
|
+
// @ts-expect-error Ok
|
|
147
202
|
req.addEventListener('success', ({target: {result: db}}) => {
|
|
148
203
|
log('Activate: Database set-up complete', db);
|
|
149
204
|
// Todo: Replace this with `ready()` check
|
|
150
205
|
// in calling code?
|
|
151
206
|
resolve();
|
|
152
207
|
});
|
|
153
|
-
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @param {Event & {error?: Error}} ev
|
|
211
|
+
*/
|
|
212
|
+
const onerr = (ev) => {
|
|
213
|
+
const error = /** @type {Error & {type: string}} */ (
|
|
214
|
+
ev.error ?? new Error('dbError')
|
|
215
|
+
);
|
|
154
216
|
error.type = 'dbError';
|
|
155
217
|
reject(error);
|
|
156
218
|
};
|