ebt-vue3 2.14.24 → 2.15.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.
- package/package.json +3 -3
- package/src/assets/main.css +5 -4
- package/src/components/SegmentHeader.vue +2 -1
- package/src/components/SuttaView.vue +36 -4
- package/src/defines.mjs +5 -0
- package/src/idb-audio.mjs +1 -1
- package/src/idb-sutta.mjs +69 -29
- package/src/stores/suttas.mjs +36 -14
- package/test/card-factory.mjs +1 -1
- package/test/idb-audio.mjs +1 -1
- package/test/idb-sutta.mjs +58 -16
- package/test/suttas-store.mjs +70 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ebt-vue3",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.2",
|
|
4
4
|
"description": "Vue3 Library for SuttaCentral Voice EBT-Sites",
|
|
5
5
|
"author": "Karl Lew",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"merkle-json": "^2.7.0",
|
|
38
38
|
"pinia": "^2.0.16",
|
|
39
39
|
"roboto-fontface": "*",
|
|
40
|
-
"scv-esm": "^1.111.
|
|
40
|
+
"scv-esm": "^1.111.89",
|
|
41
41
|
"serve-favicon": "^2.5.0",
|
|
42
42
|
"uuid": "^9.0.0",
|
|
43
43
|
"vite-plugin-vuetify": "^2.0.3",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"mocha": "^10.0.0",
|
|
62
62
|
"mock-local-storage": "^1.1.23",
|
|
63
63
|
"node-fetch": "^3.2.10",
|
|
64
|
-
"scv-bilara": "^3.
|
|
64
|
+
"scv-bilara": "^3.167.6",
|
|
65
65
|
"should": "^13.2.3",
|
|
66
66
|
"supertest": "^7.0.0",
|
|
67
67
|
"ts-import": "^4.0.0-beta.6",
|
package/src/assets/main.css
CHANGED
|
@@ -313,7 +313,7 @@ code {
|
|
|
313
313
|
.ebt-card {
|
|
314
314
|
background: rgb(var(--v-theme-surface)) !important;
|
|
315
315
|
margin-left: 2px;
|
|
316
|
-
margin-right:
|
|
316
|
+
margin-right: 1em;
|
|
317
317
|
border-radius: 4px;
|
|
318
318
|
}
|
|
319
319
|
.ebt-card-current {
|
|
@@ -330,9 +330,6 @@ code {
|
|
|
330
330
|
.ebt-card-current > .v-card--variant-flat {
|
|
331
331
|
opacity: 1 !important;
|
|
332
332
|
}
|
|
333
|
-
.ebt-card {
|
|
334
|
-
margin-right: 1em;
|
|
335
|
-
}
|
|
336
333
|
.ebt-card-search {
|
|
337
334
|
max-width: 600px;
|
|
338
335
|
min-height: calc(min(100vh - 50px, 500px));
|
|
@@ -592,6 +589,10 @@ div[title]:hover::before {
|
|
|
592
589
|
/************** EbtCards (END) ***************/
|
|
593
590
|
|
|
594
591
|
/************** SegmentView (BEGIN) ***************/
|
|
592
|
+
.seg-footer {
|
|
593
|
+
font-size: smaller;
|
|
594
|
+
padding-top: 1em;
|
|
595
|
+
}
|
|
595
596
|
.seg-match {
|
|
596
597
|
display: flex;
|
|
597
598
|
border-left: 2pt solid rgba(0,0,0,0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div :class="segMatchedClass(segment)">
|
|
3
3
|
<div class="seg-text seg-header"
|
|
4
|
-
:title="
|
|
4
|
+
:title="title"
|
|
5
5
|
style="text-align: center"
|
|
6
6
|
>
|
|
7
7
|
<div :class="langClass('root')"
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
idbSuttaRef: { type: Object, required:true },
|
|
36
36
|
card: { type: Object, required:true },
|
|
37
37
|
routeCard: { type: Object, required:true },
|
|
38
|
+
title: { type: String, required:true },
|
|
38
39
|
},
|
|
39
40
|
setup() {
|
|
40
41
|
const settings = useSettingsStore();
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
:idbSuttaRef="idbSuttaRef"
|
|
18
18
|
:card="card"
|
|
19
19
|
:routeCard="routeCard"
|
|
20
|
+
:title="$t('ebt.author')"
|
|
20
21
|
/>
|
|
21
22
|
</template>
|
|
22
23
|
<template v-for="seg in idbSuttaSegments"
|
|
@@ -29,6 +30,16 @@
|
|
|
29
30
|
:routeCard="routeCard"
|
|
30
31
|
/>
|
|
31
32
|
</template>
|
|
33
|
+
<template v-if="idbSuttaRef">
|
|
34
|
+
<segment-header
|
|
35
|
+
:segment="footerSeg"
|
|
36
|
+
:idbSuttaRef="idbSuttaRef"
|
|
37
|
+
:card="card"
|
|
38
|
+
:routeCard="routeCard"
|
|
39
|
+
title=""
|
|
40
|
+
class="seg-footer"
|
|
41
|
+
/>
|
|
42
|
+
</template>
|
|
32
43
|
<tipitaka-nav :card="card" class="mt-3"/>
|
|
33
44
|
</v-sheet>
|
|
34
45
|
</template>
|
|
@@ -242,19 +253,21 @@
|
|
|
242
253
|
let { $t, idbSuttaRef, settings } = ctx;
|
|
243
254
|
let { showReference } = settings;
|
|
244
255
|
let {
|
|
245
|
-
author, lang,
|
|
246
|
-
docLang, docAuthor,
|
|
256
|
+
author, lang, trilingual,
|
|
257
|
+
docLang, docAuthor, docAuthorName,
|
|
258
|
+
refAuthor, refLang, refAuthorName,
|
|
247
259
|
} = idbSuttaRef;
|
|
248
260
|
|
|
249
261
|
docLang = docLang || lang;
|
|
250
262
|
docAuthor = docAuthor || author;
|
|
251
263
|
let docInfo = AuthorsV2.authorInfo(docAuthor, docLang);
|
|
252
|
-
let docText = docInfo && docInfo.name.join(', ') ||
|
|
264
|
+
let docText = docInfo && docInfo.name.join(', ') ||
|
|
265
|
+
docAuthorName || "–∅–";
|
|
253
266
|
|
|
254
267
|
refLang = refLang || settings.refLang;
|
|
255
268
|
refAuthor = refAuthor || AuthorsV2.langAuthor(refLang);
|
|
256
269
|
let refInfo = AuthorsV2.authorInfo(refAuthor);
|
|
257
|
-
let refText = refInfo?.name.join(', ');
|
|
270
|
+
let refText = refInfo?.name.join(', ') || refAuthorName;
|
|
258
271
|
let refKey = trilingual ? "ref" : refLang;
|
|
259
272
|
let seg = Object.assign({}, {
|
|
260
273
|
scid: $t('ebt.author'),
|
|
@@ -264,6 +277,25 @@
|
|
|
264
277
|
});
|
|
265
278
|
return seg;
|
|
266
279
|
},
|
|
280
|
+
footerSeg(ctx) {
|
|
281
|
+
const msg = "SuttaView.footerSeg()";
|
|
282
|
+
let { $t, idbSuttaRef, settings } = ctx;
|
|
283
|
+
let { showReference } = settings;
|
|
284
|
+
let {
|
|
285
|
+
trilingual, docLang, lang, docFooter = 'df?', refFooter='rf?',
|
|
286
|
+
} = idbSuttaRef;
|
|
287
|
+
|
|
288
|
+
let msInfo = AuthorsV2.authorInfo('ms', 'pli');
|
|
289
|
+
let refKey = trilingual ? "ref" : refLang;
|
|
290
|
+
|
|
291
|
+
let seg = Object.assign({}, {
|
|
292
|
+
scid: $t('ebt.footer'),
|
|
293
|
+
pli: msInfo.name,
|
|
294
|
+
[docLang||lang]: docFooter,
|
|
295
|
+
[refKey]: refFooter,
|
|
296
|
+
});
|
|
297
|
+
return seg;
|
|
298
|
+
},
|
|
267
299
|
},
|
|
268
300
|
}
|
|
269
301
|
</script>
|
package/src/defines.mjs
CHANGED
|
@@ -19,6 +19,9 @@ export const DBG = {
|
|
|
19
19
|
FOCUS: 0,
|
|
20
20
|
FOCUS_ELT: 0,
|
|
21
21
|
IDB_SUTTA: 0,
|
|
22
|
+
IDB_SUTTA_MERGE: 0,
|
|
23
|
+
I6A_CREATE: 0,
|
|
24
|
+
I6A_IDB_KEY: 0,
|
|
22
25
|
IS_READY: 0,
|
|
23
26
|
LOG_HTML: 0,
|
|
24
27
|
MOUNTED: 0,
|
|
@@ -32,6 +35,8 @@ export const DBG = {
|
|
|
32
35
|
ROUTE: 0,
|
|
33
36
|
ROUTE_HASH: 0,
|
|
34
37
|
SCROLL: 0,
|
|
38
|
+
S4S_LOAD_IDB_SUTTA: 0,
|
|
39
|
+
S4S_SAVE_IDB_SUTTA: 0,
|
|
35
40
|
SEG_MOUNTED: 0,
|
|
36
41
|
SET_ROUTE: 0,
|
|
37
42
|
SUTTA_MOUNTED: 0,
|
package/src/idb-audio.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from './defines.mjs'
|
|
8
8
|
|
|
9
9
|
const HEADERS_MPEG = { ["Accept"]: "audio/mpeg", };
|
|
10
|
-
const URL_NO_AUDIO = "https://
|
|
10
|
+
const URL_NO_AUDIO = "https://www.sc-voice.net/audio/no_audio.mp3";
|
|
11
11
|
|
|
12
12
|
const dbg = DBG_IDB_AUDIO;
|
|
13
13
|
|
package/src/idb-sutta.mjs
CHANGED
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
import { DBG } from './defines.mjs';
|
|
7
7
|
import * as Idb from "idb-keyval";
|
|
8
8
|
|
|
9
|
-
const OPTIONAL_PROPS = ['saved',
|
|
9
|
+
const OPTIONAL_PROPS = ['saved',
|
|
10
|
+
'refLang', 'refAuthor', 'refAuthorName', 'refFooter',
|
|
11
|
+
'docLang', 'docAuthor', 'docAuthorName', 'docFooter',
|
|
12
|
+
];
|
|
10
13
|
const EXAMPLE_CLASS = 'ebt-example';
|
|
11
14
|
const RE_EXAMPLE_CLASS = new RegExp(EXAMPLE_CLASS);
|
|
12
15
|
const EXAMPLE_TEMPLATE = `<span class="${EXAMPLE_CLASS}">\$&</span>`;
|
|
@@ -40,17 +43,15 @@ export default class IdbSutta {
|
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static create(opts = {}) {
|
|
43
|
-
const msg = '
|
|
44
|
-
const dbg = DBG.IDB_SUTTA;
|
|
46
|
+
const msg = 'I6a.create()';
|
|
47
|
+
const dbg = DBG.IDB_SUTTA || DBG.I6A_CREATE;
|
|
45
48
|
let {
|
|
46
49
|
sutta_uid,
|
|
47
50
|
lang,
|
|
48
51
|
author = opts.author_uid,
|
|
49
52
|
title,
|
|
50
|
-
docLang,
|
|
51
|
-
|
|
52
|
-
refLang,
|
|
53
|
-
refAuthor,
|
|
53
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
54
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
54
55
|
trilingual,
|
|
55
56
|
segments,
|
|
56
57
|
} = opts;
|
|
@@ -61,8 +62,9 @@ export default class IdbSutta {
|
|
|
61
62
|
if (segments) { // opts is IdbSutta-like
|
|
62
63
|
let idbSutta = {
|
|
63
64
|
sutta_uid, lang, author, title,
|
|
64
|
-
docLang, docAuthor,
|
|
65
|
-
|
|
65
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
66
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
67
|
+
trilingual, segments,
|
|
66
68
|
};
|
|
67
69
|
IdbSutta.#copyOptional(opts, idbSutta);
|
|
68
70
|
return new IdbSutta(idbSutta);
|
|
@@ -76,12 +78,16 @@ export default class IdbSutta {
|
|
|
76
78
|
}
|
|
77
79
|
let idbSutta = new IdbSutta({
|
|
78
80
|
sutta_uid, lang, author, title,
|
|
79
|
-
docLang, docAuthor,
|
|
81
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
82
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
83
|
+
trilingual,
|
|
80
84
|
segments:[],
|
|
81
85
|
});
|
|
82
86
|
let mlDoc = {
|
|
83
87
|
sutta_uid, lang, author_uid:author, title, segMap,
|
|
84
|
-
docLang, docAuthor,
|
|
88
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
89
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
90
|
+
trilingual,
|
|
85
91
|
};
|
|
86
92
|
idbSutta.merge({mlDoc});
|
|
87
93
|
return idbSutta;
|
|
@@ -93,9 +99,8 @@ export default class IdbSutta {
|
|
|
93
99
|
static idbKey({
|
|
94
100
|
sutta_uid, docLang='en', docAuthor, refLang='en', refAuthor,
|
|
95
101
|
}) {
|
|
96
|
-
const msg = '
|
|
97
|
-
const dbg = DBG.
|
|
98
|
-
const dbgv = DBG.VERBOSE && dbg;
|
|
102
|
+
const msg = 'I6a.idbKey()';
|
|
103
|
+
const dbg = DBG.I6A_IDB_KEY;
|
|
99
104
|
|
|
100
105
|
let idbKey = [
|
|
101
106
|
sutta_uid,
|
|
@@ -105,11 +110,13 @@ export default class IdbSutta {
|
|
|
105
110
|
refAuthor || AuthorsV2.langAuthor(refLang),
|
|
106
111
|
].join('/');
|
|
107
112
|
|
|
113
|
+
dbg && console.log(msg, '[1]', idbKey);
|
|
114
|
+
|
|
108
115
|
return idbKey;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
static suttaRefToIdbKey(suttaRef, settings={}) {
|
|
112
|
-
const msg = '
|
|
119
|
+
const msg = 'I6a.suttaRefToIdbKey()';
|
|
113
120
|
let { docLang = 'en', refLang = 'en', } = settings;
|
|
114
121
|
let {
|
|
115
122
|
docAuthor = AuthorsV2.langAuthor(docLang),
|
|
@@ -122,10 +129,16 @@ export default class IdbSutta {
|
|
|
122
129
|
lang=docLang,
|
|
123
130
|
author,
|
|
124
131
|
} = SuttaRef.create(suttaRef, docLang);
|
|
132
|
+
if (author == null) {
|
|
133
|
+
author = AuthorsV2.langAuthor(lang);
|
|
134
|
+
}
|
|
135
|
+
if (author == null && docLang === lang) {
|
|
136
|
+
author = docAuthor;
|
|
137
|
+
}
|
|
125
138
|
return IdbSutta.idbKey({
|
|
126
139
|
sutta_uid,
|
|
127
140
|
docLang: lang,
|
|
128
|
-
docAuthor: author
|
|
141
|
+
docAuthor: author,
|
|
129
142
|
refLang,
|
|
130
143
|
refAuthor,
|
|
131
144
|
});
|
|
@@ -140,10 +153,15 @@ export default class IdbSutta {
|
|
|
140
153
|
return IdbSutta.idbKey(this);
|
|
141
154
|
}
|
|
142
155
|
|
|
143
|
-
|
|
156
|
+
// Merge new information from srcNew
|
|
157
|
+
merge(srcNew={}) {
|
|
144
158
|
const msg = 'IdbSutta.merge()';
|
|
145
|
-
const dbg = DBG.IDB_SUTTA;
|
|
146
|
-
let {
|
|
159
|
+
const dbg = DBG.IDB_SUTTA || DBG.IDB_SUTTA_MERGE;
|
|
160
|
+
let {
|
|
161
|
+
mlDoc,
|
|
162
|
+
refLang:refLangOpts, // WHY?
|
|
163
|
+
highlightExamples=false,
|
|
164
|
+
} = srcNew;
|
|
147
165
|
if (mlDoc == null) {
|
|
148
166
|
let emsg = `${msg} [1]mlDoc?`;
|
|
149
167
|
console.warn(emsg);
|
|
@@ -155,8 +173,12 @@ export default class IdbSutta {
|
|
|
155
173
|
return a;
|
|
156
174
|
}, {});
|
|
157
175
|
let {
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
segMap:srcSegMap,
|
|
177
|
+
sutta_uid, lang, author_uid,
|
|
178
|
+
title,
|
|
179
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
180
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
181
|
+
trilingual,
|
|
160
182
|
} = mlDoc;
|
|
161
183
|
if (srcSegMap == null) {
|
|
162
184
|
let emsg = `${msg} [2]srcSegMap?`;
|
|
@@ -165,20 +187,38 @@ export default class IdbSutta {
|
|
|
165
187
|
}
|
|
166
188
|
this.trilingual = trilingual;
|
|
167
189
|
if (trilingual) {
|
|
168
|
-
|
|
190
|
+
if (dbg) {
|
|
191
|
+
let dbgOut = dbg > 1 ? srcNew : {
|
|
192
|
+
sutta_uid,
|
|
193
|
+
docLang,
|
|
194
|
+
docAuthor,
|
|
195
|
+
docAuthorName,
|
|
196
|
+
docFooter,
|
|
197
|
+
refLang,
|
|
198
|
+
refAuthor,
|
|
199
|
+
refAuthorName,
|
|
200
|
+
refFooter,
|
|
201
|
+
title,
|
|
202
|
+
};
|
|
203
|
+
console.log(msg, '[3]trilingual', dbgOut);
|
|
204
|
+
}
|
|
169
205
|
this.author = docAuthor;
|
|
170
206
|
this.lang = docLang;
|
|
171
|
-
this.docAuthor = docAuthor;
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
174
|
-
this.
|
|
207
|
+
this.docAuthor = docAuthor || this.docAuthor;
|
|
208
|
+
this.docAuthorName = docAuthorName || this.docAuthorName;
|
|
209
|
+
this.docLang = docLang || this.docLang;
|
|
210
|
+
this.docFooter = docFooter || this.docFooter;
|
|
211
|
+
this.refLang = refLang || this.refLang || refLang;
|
|
212
|
+
this.refAuthor = refAuthor || this.refAuthor;
|
|
213
|
+
this.refAuthorName = refAuthorName || this.refAuthorName;
|
|
214
|
+
this.refFooter = refFooter || this.refFooter;
|
|
175
215
|
} else {
|
|
176
216
|
if (refLangOpts) {
|
|
177
|
-
dbg && console.warn(msg, '[4]legacy',
|
|
217
|
+
dbg && console.warn(msg, '[4]legacy', srcNew);
|
|
178
218
|
this.refAuthor = author_uid;
|
|
179
219
|
this.refLang = refLangOpts;
|
|
180
220
|
} else {
|
|
181
|
-
dbg && console.warn(msg, '[5]legacy',
|
|
221
|
+
dbg && console.warn(msg, '[5]legacy', srcNew);
|
|
182
222
|
this.author = author_uid;
|
|
183
223
|
this.lang = lang;
|
|
184
224
|
this.title = title;
|
|
@@ -208,7 +248,7 @@ export default class IdbSutta {
|
|
|
208
248
|
}, []);
|
|
209
249
|
if (highlightExamples) {
|
|
210
250
|
dbg && console.log(msg, '[6]highlightExamples');
|
|
211
|
-
this.highlightExamples(
|
|
251
|
+
this.highlightExamples(srcNew);
|
|
212
252
|
}
|
|
213
253
|
}
|
|
214
254
|
|
package/src/stores/suttas.mjs
CHANGED
|
@@ -38,22 +38,37 @@ export const useSuttasStore = defineStore('suttas', {
|
|
|
38
38
|
return url;
|
|
39
39
|
},
|
|
40
40
|
async loadIdbSutta(suttaRef, opts={}) { // low-level API
|
|
41
|
-
const msg =
|
|
42
|
-
const dbg = DBG_LOAD;
|
|
43
|
-
|
|
44
|
-
let {
|
|
45
|
-
|
|
41
|
+
const msg = 's4s.loadIdbSutta:';
|
|
42
|
+
const dbg = DBG_LOAD || DBG.S4S_LOAD_IDB_SUTTA;
|
|
43
|
+
suttaRef = SuttaRef.create(suttaRef);
|
|
44
|
+
let {
|
|
45
|
+
settings = useSettingsStore(),
|
|
46
|
+
refresh=false,
|
|
47
|
+
} = opts;
|
|
48
|
+
let sref = suttaRef.toString();
|
|
46
49
|
let idbKey = IdbSutta.suttaRefToIdbKey(suttaRef, settings);
|
|
50
|
+
dbg && console.log(msg, '[1.0]idbKey', suttaRef, idbKey);
|
|
51
|
+
let { maxAge } = this;
|
|
47
52
|
let idbData = await Idb.get(idbKey);
|
|
48
53
|
this.nGet++;
|
|
49
54
|
let age = idbData?.saved ? Date.now()-idbData.saved : maxAge+1;
|
|
50
55
|
let idbSutta;
|
|
56
|
+
let fetchSutta = false;
|
|
51
57
|
|
|
52
|
-
if (
|
|
58
|
+
if (!idbData) {
|
|
59
|
+
fetchSutta = true;
|
|
60
|
+
dbg && console.log(msg, '[1.1]!cached', idbKey);
|
|
61
|
+
} else if (refresh) {
|
|
62
|
+
fetchSutta = true;
|
|
63
|
+
dbg && console.log(msg, '[1.2]refersh', idbKey);
|
|
64
|
+
} else if (maxAge < age) {
|
|
65
|
+
fetchSutta = true;
|
|
66
|
+
dbg && console.log(msg, `[1.3]maxAge:${maxAge}<age${age}`);
|
|
67
|
+
}
|
|
68
|
+
if (fetchSutta) {
|
|
53
69
|
let volatile = useVolatileStore();
|
|
54
70
|
let url = this.suttaUrl(suttaRef);
|
|
55
|
-
|
|
56
|
-
volatile.waitBegin('ebt.loadingSutta', undefined, suttaRef.toString());
|
|
71
|
+
volatile.waitBegin('ebt.loadingSutta', undefined, sref);
|
|
57
72
|
let json = await volatile.fetchJson(url);
|
|
58
73
|
volatile.waitEnd('ebt.loadingSutta', undefined, msg);
|
|
59
74
|
this.nFetch++;
|
|
@@ -64,26 +79,33 @@ export const useSuttasStore = defineStore('suttas', {
|
|
|
64
79
|
return null;
|
|
65
80
|
}
|
|
66
81
|
idbSutta = IdbSutta.create(mlDocs[0]);
|
|
67
|
-
dbg && console.log(msg,
|
|
82
|
+
dbg && console.log(msg, `[2]${url}=>`,
|
|
68
83
|
`segments:${idbSutta.segments.length}`);
|
|
69
84
|
await this.saveIdbSutta(idbSutta);
|
|
70
85
|
} else {
|
|
71
|
-
dbg && console.log(msg,
|
|
86
|
+
dbg && console.log(msg, '[3]cached', idbKey);
|
|
72
87
|
idbSutta = IdbSutta.create(idbData);
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
return idbSutta;
|
|
76
91
|
},
|
|
77
92
|
async saveIdbSutta(idbSutta) { // low-level API
|
|
78
|
-
const msg = '
|
|
79
|
-
const dbg = DBG_LOAD || DBG.IDB_SUTTA;
|
|
93
|
+
const msg = 'S4s.saveIdbSutta()';
|
|
94
|
+
const dbg = DBG_LOAD || DBG.IDB_SUTTA || DBG.S4S_SAVE_IDB_SUTTA;
|
|
80
95
|
let { idbKey } = idbSutta;
|
|
81
96
|
let vueRef = VUEREFS.get(idbKey);
|
|
82
97
|
if (vueRef == null) {
|
|
83
98
|
vueRef = ref(idbSutta);
|
|
84
|
-
|
|
99
|
+
let saved = Date.now();
|
|
100
|
+
idbSutta.saved = saved;
|
|
101
|
+
if (dbg) {
|
|
102
|
+
if (dbg === 1) {
|
|
103
|
+
console.log(msg, '[1.1]VUEREFS.set', {idbKey, saved});
|
|
104
|
+
} else {
|
|
105
|
+
console.log(msg, '[1.2]VUEREFS.set', {idbKey, idbSutta});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
85
108
|
VUEREFS.set(idbKey, vueRef);
|
|
86
|
-
idbSutta.saved = Date.now();
|
|
87
109
|
} else if (vueRef.value !== idbSutta) {
|
|
88
110
|
dbg && console.log(msg, '[2]vueRef <=', {
|
|
89
111
|
idbKey, vueRef, idbSutta});
|
package/test/card-factory.mjs
CHANGED
package/test/idb-audio.mjs
CHANGED
|
@@ -235,7 +235,7 @@ global.AudioContext = MockAudioContext; // NodeJs has no AudioContext
|
|
|
235
235
|
should(audio.currentTime).above(playTime);
|
|
236
236
|
|
|
237
237
|
let abuf = result; // unspecified in Web Api
|
|
238
|
-
should(abuf.byteLength).above(
|
|
238
|
+
should(abuf.byteLength).above(5000).below(6000);
|
|
239
239
|
should(abuf).instanceOf(ArrayBuffer);
|
|
240
240
|
});
|
|
241
241
|
it("clear()", async()=>{
|
package/test/idb-sutta.mjs
CHANGED
|
@@ -98,14 +98,32 @@ const TESTMLDOC_EN = {
|
|
|
98
98
|
let author = 'test-author';
|
|
99
99
|
let segMap = TESTMAP;
|
|
100
100
|
let title = 'test-title';
|
|
101
|
-
let
|
|
101
|
+
let docLang = 'test-doc-lang';
|
|
102
|
+
let docAuthor = 'test-doc-author';
|
|
103
|
+
let docAuthorName = 'test-doc-author-name';
|
|
104
|
+
let docFooter = 'test-doc-footer';
|
|
105
|
+
let refLang = 'test-ref-lang';
|
|
106
|
+
let refAuthor = 'test-ref-author';
|
|
107
|
+
let refAuthorName = 'test-ref-author-name';
|
|
108
|
+
let refFooter = 'test-ref-footer';
|
|
109
|
+
let trilingual = true;
|
|
110
|
+
let mlDoc = {
|
|
111
|
+
sutta_uid, lang, author_uid:author, title, segMap,
|
|
112
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
113
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
114
|
+
trilingual
|
|
115
|
+
}
|
|
102
116
|
let sutta = IdbSutta.create(mlDoc);
|
|
103
|
-
should(sutta).
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
should(sutta.trilingual).equal(true);
|
|
118
|
+
should(sutta.docLang).equal(docLang);
|
|
119
|
+
should(sutta.docAuthor).equal(docAuthor);
|
|
120
|
+
should(sutta.docAuthorName).equal(docAuthorName);
|
|
121
|
+
should(sutta.docFooter).equal(docFooter);
|
|
122
|
+
should(sutta.refLang).equal(refLang);
|
|
123
|
+
should(sutta.refAuthor).equal(refAuthor);
|
|
124
|
+
should(sutta.refAuthorName).equal(refAuthorName);
|
|
125
|
+
should(sutta.refFooter).equal(refFooter);
|
|
126
|
+
should(sutta).properties({ sutta_uid, title, });
|
|
109
127
|
should.deepEqual(sutta.segments, TESTSEGS);
|
|
110
128
|
});
|
|
111
129
|
it("create(mlDoc) segment order", ()=>{
|
|
@@ -172,13 +190,26 @@ const TESTMLDOC_EN = {
|
|
|
172
190
|
.equal('thig1.1/en/soma/en/sujato');
|
|
173
191
|
});
|
|
174
192
|
it("suttaRefToIdbKey settings", ()=>{
|
|
175
|
-
let sref = 'thig1.1/de';
|
|
176
193
|
let settings = {
|
|
194
|
+
docLang: 'de',
|
|
195
|
+
docAuthor: 'sabbamitta',
|
|
177
196
|
refLang: 'en',
|
|
178
197
|
refAuthor: 'soma',
|
|
179
198
|
}
|
|
180
|
-
should(IdbSutta.suttaRefToIdbKey(
|
|
199
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1', settings))
|
|
181
200
|
.equal('thig1.1/de/sabbamitta/en/soma');
|
|
201
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/de', settings))
|
|
202
|
+
.equal('thig1.1/de/sabbamitta/en/soma');
|
|
203
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/de/sabbamitta', settings))
|
|
204
|
+
.equal('thig1.1/de/sabbamitta/en/soma');
|
|
205
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/en', settings))
|
|
206
|
+
.equal('thig1.1/en/sujato/en/soma');
|
|
207
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/en/sujato', settings))
|
|
208
|
+
.equal('thig1.1/en/sujato/en/soma');
|
|
209
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/fr', settings))
|
|
210
|
+
.equal('thig1.1/fr/noeismet/en/soma');
|
|
211
|
+
should(IdbSutta.suttaRefToIdbKey('thig1.1/fr/wijayaratna', settings))
|
|
212
|
+
.equal('thig1.1/fr/wijayaratna/en/soma');
|
|
182
213
|
});
|
|
183
214
|
it("suttaRefToIdbKey an1.1-10", ()=>{
|
|
184
215
|
let sref = 'an1.1-10:1.2';
|
|
@@ -191,13 +222,24 @@ const TESTMLDOC_EN = {
|
|
|
191
222
|
.equal('an1.1-10/de/sabbamitta/en/soma');
|
|
192
223
|
});
|
|
193
224
|
it("idbKey", ()=>{
|
|
194
|
-
let
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
should(IdbSutta.idbKey(
|
|
200
|
-
|
|
225
|
+
let sutta_uid = 'test-sutta-uid';
|
|
226
|
+
let docLang = 'test-doc-lang';
|
|
227
|
+
let docAuthor = 'test-doc-author';
|
|
228
|
+
let refLang = 'test-ref-lang';
|
|
229
|
+
let refAuthor = 'test-ref-author';
|
|
230
|
+
should(IdbSutta.idbKey({
|
|
231
|
+
sutta_uid, docLang, docAuthor, refLang, refAuthor
|
|
232
|
+
})).equal([
|
|
233
|
+
sutta_uid, docLang, docAuthor, refLang, refAuthor
|
|
234
|
+
].join('/'));
|
|
235
|
+
|
|
236
|
+
should(IdbSutta.idbKey({ sutta_uid, docLang, docAuthor })).equal([
|
|
237
|
+
sutta_uid, docLang, docAuthor, 'en', 'sujato',
|
|
238
|
+
].join('/'));
|
|
239
|
+
|
|
240
|
+
should(IdbSutta.idbKey({ sutta_uid })).equal([
|
|
241
|
+
sutta_uid, 'en', 'sujato', 'en', 'sujato',
|
|
242
|
+
].join('/'));
|
|
201
243
|
});
|
|
202
244
|
it("idbKey settings", ()=>{
|
|
203
245
|
let args = {
|
package/test/suttas-store.mjs
CHANGED
|
@@ -58,14 +58,16 @@ const MSDAY = 24*3600*MSSEC;
|
|
|
58
58
|
'zz?maxResults=5',
|
|
59
59
|
].join('/'));
|
|
60
60
|
});
|
|
61
|
-
it("
|
|
62
|
-
|
|
61
|
+
it("TESTTESTloadIdbSutta", async () => {
|
|
62
|
+
const msg = 'ts4s.loadIdbSutta';
|
|
63
|
+
const dbg = 0;
|
|
63
64
|
let suttas = useSuttasStore();
|
|
64
65
|
let { nFetch, nGet, nSet } = suttas;
|
|
65
66
|
let suttaRef = SuttaRef.create('thig1.11/en/soma');
|
|
66
67
|
|
|
67
68
|
// Load sutta from cloud
|
|
68
69
|
let idbSutta = await suttas.loadIdbSutta(suttaRef);
|
|
70
|
+
let { idbKey } = idbSutta;
|
|
69
71
|
should(idbSutta).properties({
|
|
70
72
|
sutta_uid: 'thig1.11',
|
|
71
73
|
lang: 'en',
|
|
@@ -82,6 +84,9 @@ const MSDAY = 24*3600*MSSEC;
|
|
|
82
84
|
|
|
83
85
|
// Load cached sutta
|
|
84
86
|
let idbSutta2 = await suttas.loadIdbSutta(suttaRef);
|
|
87
|
+
should.deepEqual(
|
|
88
|
+
Object.keys(idbSutta2).sort(),
|
|
89
|
+
Object.keys(idbSutta).sort());
|
|
85
90
|
should.deepEqual(idbSutta2, idbSutta);
|
|
86
91
|
should(suttas.nGet).equal(nGet+2);
|
|
87
92
|
should(suttas.nSet).equal(nSet+1);
|
|
@@ -89,7 +94,7 @@ const MSDAY = 24*3600*MSSEC;
|
|
|
89
94
|
|
|
90
95
|
// Don't refresh almost stale data
|
|
91
96
|
let freshSaved = Date.now() - MSDAY + MSSEC;
|
|
92
|
-
Idb.set(
|
|
97
|
+
Idb.set(idbKey,
|
|
93
98
|
Object.assign({}, idbSutta, {saved:freshSaved}));
|
|
94
99
|
let idbSutta3 = await suttas.loadIdbSutta(suttaRef);
|
|
95
100
|
should(idbSutta3.saved).equal(freshSaved);
|
|
@@ -98,40 +103,88 @@ const MSDAY = 24*3600*MSSEC;
|
|
|
98
103
|
should(suttas.nFetch).equal(nFetch+1);
|
|
99
104
|
|
|
100
105
|
// Re-fetch stale sutta
|
|
101
|
-
let
|
|
102
|
-
|
|
106
|
+
let now = Date.now();
|
|
107
|
+
let staleSaved = now - MSDAY - 1;
|
|
108
|
+
dbg && console.log(msg, {staleSaved});
|
|
109
|
+
Idb.set(idbKey,
|
|
103
110
|
Object.assign({}, idbSutta, {saved:staleSaved}));
|
|
104
111
|
let idbSutta4 = await suttas.loadIdbSutta(suttaRef);
|
|
105
|
-
let age =
|
|
112
|
+
let age = now - idbSutta4.saved;
|
|
113
|
+
should(idbSutta4.saved).not.equal(staleSaved);
|
|
114
|
+
dbg && console.log(msg, {age, now, MSDAY});
|
|
106
115
|
should(age).below(MSSEC);
|
|
107
116
|
});
|
|
108
117
|
it("saveIdbSutta()", async () => {
|
|
118
|
+
const msg = 'TS14e.saveIdbSutta:';
|
|
119
|
+
const dbg = 0;
|
|
109
120
|
let suttas = useSuttasStore();
|
|
110
121
|
let { nFetch, nGet, nSet } = suttas;
|
|
111
|
-
let author = '
|
|
112
|
-
let lang = '
|
|
113
|
-
let docLang = lang;
|
|
114
|
-
let docAuthor = author;
|
|
115
|
-
let
|
|
116
|
-
let
|
|
122
|
+
let author = 't-author';
|
|
123
|
+
let lang = 't-lang';
|
|
124
|
+
let docLang = 't-doc-lang';
|
|
125
|
+
let docAuthor = 't-doc-author';
|
|
126
|
+
let docAuthorName = 't-doc-author-name';
|
|
127
|
+
let docFooter = 't-doc-footer';
|
|
128
|
+
let refLang = 't-ref-lang';
|
|
129
|
+
let refAuthor = 't-ref-author';
|
|
130
|
+
let refAuthorName = 't-ref-author-name';
|
|
131
|
+
let refFooter = 't-ref-footer';
|
|
132
|
+
let trilingual = true;
|
|
117
133
|
let sutta_uid = "thig1.1";
|
|
134
|
+
let sref = `${sutta_uid}/${docLang}/${docAuthor}`;
|
|
118
135
|
let segments = [{
|
|
119
|
-
"
|
|
136
|
+
"t-suid:0.1": "T-SEGMENT",
|
|
120
137
|
}];
|
|
138
|
+
let mockSettings = { docLang, docAuthor, refLang, refAuthor };
|
|
121
139
|
let idbSutta = IdbSutta.create({
|
|
122
140
|
author, lang, sutta_uid, segments,
|
|
123
|
-
docLang, docAuthor,
|
|
141
|
+
docLang, docAuthor, docAuthorName, docFooter,
|
|
142
|
+
refLang, refAuthor, refAuthorName, refFooter,
|
|
143
|
+
trilingual,
|
|
124
144
|
});
|
|
145
|
+
dbg>1 && console.log(msg, 'idbSutta', idbSutta);
|
|
125
146
|
|
|
126
147
|
let idbSuttaSaved = await suttas.saveIdbSutta(idbSutta);
|
|
127
|
-
|
|
148
|
+
let saved = idbSuttaSaved.value;
|
|
149
|
+
dbg>1 && console.log(msg, 'idbSuttaSaved', idbSuttaSaved);
|
|
150
|
+
should(saved.docLang).equal(docLang);
|
|
151
|
+
should(saved.docAuthor).equal(docAuthor);
|
|
152
|
+
should(saved.docAuthorName).equal(docAuthorName);
|
|
153
|
+
should(saved.docFooter).equal(docFooter);
|
|
154
|
+
should(saved.refLang).equal(refLang);
|
|
155
|
+
should(saved.refAuthor).equal(refAuthor);
|
|
156
|
+
should(saved.refAuthorName).equal(refAuthorName);
|
|
157
|
+
should(saved.refFooter).equal(refFooter);
|
|
158
|
+
should(saved).properties(idbSutta);
|
|
128
159
|
let now = Date.now();
|
|
129
160
|
should(now - idbSuttaSaved.value.saved).above(-1).below(MSSEC);
|
|
130
161
|
should(suttas.nGet).equal(nGet);
|
|
131
162
|
should(suttas.nSet).equal(nSet+1);
|
|
132
163
|
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
dbg && console.log(msg, 'settings', mockSettings);
|
|
165
|
+
let loaded = await suttas.loadIdbSutta(sref, {
|
|
166
|
+
settings: mockSettings
|
|
167
|
+
});
|
|
168
|
+
saved = idbSuttaSaved.value;
|
|
169
|
+
//should(loaded.author).equal(saved.author);
|
|
170
|
+
should(loaded.docLang).equal(saved.docLang);
|
|
171
|
+
should(loaded.docAuthor).equal(saved.docAuthor);
|
|
172
|
+
should(loaded.docAuthorName).equal(saved.docAuthorName);
|
|
173
|
+
should(loaded.docFooter).equal(saved.docFooter);
|
|
174
|
+
should(loaded.refLang).equal(saved.refLang);
|
|
175
|
+
should(loaded.refAuthor).equal(saved.refAuthor);
|
|
176
|
+
should(loaded.refAuthorName).equal(saved.refAuthorName);
|
|
177
|
+
should(loaded.refFooter).equal(saved.refFooter);
|
|
178
|
+
should(loaded.author).equal(saved.author);
|
|
179
|
+
should(loaded.author).equal(saved.author);
|
|
180
|
+
should(loaded.author).equal(saved.author);
|
|
181
|
+
should(loaded.author).equal(saved.author);
|
|
182
|
+
should(loaded.author).equal(saved.author);
|
|
183
|
+
should(loaded.author).equal(saved.author);
|
|
184
|
+
should(loaded.author).equal(saved.author);
|
|
185
|
+
should(loaded.author).equal(saved.author);
|
|
186
|
+
should(loaded.author).equal(saved.author);
|
|
187
|
+
should.deepEqual(loaded, idbSuttaSaved.value);
|
|
135
188
|
should(suttas.nGet).equal(nGet+1);
|
|
136
189
|
should(suttas.nSet).equal(nSet+1);
|
|
137
190
|
});
|