@teipublisher/pb-components 3.6.1 → 3.6.3
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/CHANGELOG.md +15 -0
- package/dist/pb-components-bundle.js +32 -32
- package/package.json +1 -1
- package/src/authority/kbga.js +52 -5
- package/src/pb-authority-lookup.js +92 -9
- package/src/pb-view-annotate.js +7 -4
package/package.json
CHANGED
package/src/authority/kbga.js
CHANGED
|
@@ -12,10 +12,20 @@ export class KBGA extends Registry {
|
|
|
12
12
|
const results = [];
|
|
13
13
|
|
|
14
14
|
const register = this.getRegister();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
15
|
+
const baseUrl =
|
|
16
|
+
this._register === 'object' ? 'https://kba.karl-barth.ch' : 'https://meta.karl-barth.ch';
|
|
17
|
+
let searchQuery;
|
|
18
|
+
switch (register) {
|
|
19
|
+
case 'objects':
|
|
20
|
+
searchQuery = `fields%5B0%5D=creation_min&values%5B0%5D=${encodeURIComponent(key)}&operators%5B0%5D=%3D`;
|
|
21
|
+
break;
|
|
22
|
+
case 'bibls':
|
|
23
|
+
searchQuery = `biblsearch=${encodeURIComponent(key)}`;
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
searchQuery = `search=${encodeURIComponent(key)}`;
|
|
27
|
+
}
|
|
28
|
+
const url = `${baseUrl}/api/${register}?${searchQuery}&perPage=${this._limit}`;
|
|
19
29
|
const label = this.getLabelField();
|
|
20
30
|
return new Promise(resolve => {
|
|
21
31
|
fetch(url)
|
|
@@ -28,6 +38,18 @@ export class KBGA extends Registry {
|
|
|
28
38
|
) {
|
|
29
39
|
return;
|
|
30
40
|
}
|
|
41
|
+
if (this._register === 'object') {
|
|
42
|
+
results.push({
|
|
43
|
+
register: this._register,
|
|
44
|
+
id: String(item.id),
|
|
45
|
+
label: item.full_id,
|
|
46
|
+
details: item.title,
|
|
47
|
+
link: item.permalink,
|
|
48
|
+
strings: [],
|
|
49
|
+
provider: 'KBGA',
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
31
53
|
const result = {
|
|
32
54
|
register: this._register,
|
|
33
55
|
id: this._prefix ? `${this._prefix}:${item['full-id']}` : item['full-id'],
|
|
@@ -54,6 +76,20 @@ export class KBGA extends Registry {
|
|
|
54
76
|
const label = this.getLabelField();
|
|
55
77
|
return new Promise(resolve => {
|
|
56
78
|
this.getRecord(key).then(json => {
|
|
79
|
+
if (this._register === 'object') {
|
|
80
|
+
const { title, object_creation_min, permalink } = json.data;
|
|
81
|
+
const dates = object_creation_min ? `<p>${object_creation_min}</p>` : '';
|
|
82
|
+
const output = `
|
|
83
|
+
<h3 class="label"><a href="${permalink}" target="_blank">${title}</a></h3>
|
|
84
|
+
${dates}
|
|
85
|
+
`;
|
|
86
|
+
container.innerHTML = output;
|
|
87
|
+
resolve({
|
|
88
|
+
id: String(json.data.id),
|
|
89
|
+
strings: [],
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
57
93
|
const died = json.data.death ? `† ${json.data.death}` : '';
|
|
58
94
|
const dates = json.data.birth ? `<p>* ${json.data.birth} ${died}</p>` : '';
|
|
59
95
|
const note = json.data.note_bio ? `<p>${json.data.note_bio}</p>` : '';
|
|
@@ -81,12 +117,17 @@ export class KBGA extends Registry {
|
|
|
81
117
|
*/
|
|
82
118
|
async getRecord(key) {
|
|
83
119
|
const id = key.replace(/^.*-([^-]+)$/, '$1');
|
|
84
|
-
|
|
120
|
+
const baseUrl =
|
|
121
|
+
this._register === 'object' ? 'https://kba.karl-barth.ch' : 'https://meta.karl-barth.ch';
|
|
122
|
+
return fetch(`${baseUrl}/api/${this.getRegister()}/${id}`)
|
|
85
123
|
.then(response => response.json())
|
|
86
124
|
.then(json => {
|
|
87
125
|
const output = { ...json };
|
|
88
126
|
output.name = json.data[this.getLabelField()];
|
|
89
127
|
switch (this._register) {
|
|
128
|
+
case 'object':
|
|
129
|
+
output.name = `${json.data.title} (${json.data.object_creation_min})`;
|
|
130
|
+
break;
|
|
90
131
|
case 'place':
|
|
91
132
|
output.country = json.data.country;
|
|
92
133
|
output.location = json.data.location.coordinates;
|
|
@@ -109,6 +150,9 @@ export class KBGA extends Registry {
|
|
|
109
150
|
getLabelField() {
|
|
110
151
|
let label;
|
|
111
152
|
switch (this._register) {
|
|
153
|
+
case 'object':
|
|
154
|
+
label = 'title';
|
|
155
|
+
break;
|
|
112
156
|
case 'place':
|
|
113
157
|
label = 'placeName_full';
|
|
114
158
|
break;
|
|
@@ -135,6 +179,9 @@ export class KBGA extends Registry {
|
|
|
135
179
|
}
|
|
136
180
|
let register;
|
|
137
181
|
switch (this._register) {
|
|
182
|
+
case 'object':
|
|
183
|
+
register = 'objects';
|
|
184
|
+
break;
|
|
138
185
|
case 'person':
|
|
139
186
|
case 'organization':
|
|
140
187
|
register = 'actors';
|
|
@@ -87,6 +87,20 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
87
87
|
this._authorities = {};
|
|
88
88
|
this.noOccurrences = false;
|
|
89
89
|
this.group = 'tei';
|
|
90
|
+
this._queryGeneration = 0;
|
|
91
|
+
this._queryDebounceMs = 300;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
disconnectedCallback() {
|
|
95
|
+
super.disconnectedCallback();
|
|
96
|
+
if (this._queryTimer) {
|
|
97
|
+
clearTimeout(this._queryTimer);
|
|
98
|
+
this._queryTimer = null;
|
|
99
|
+
}
|
|
100
|
+
if (this._occurrencesController) {
|
|
101
|
+
this._occurrencesController.abort();
|
|
102
|
+
this._occurrencesController = null;
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
|
|
92
106
|
connectedCallback() {
|
|
@@ -101,7 +115,7 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
101
115
|
this.query = ev.detail.query;
|
|
102
116
|
this.type = ev.detail.type;
|
|
103
117
|
this._results = [];
|
|
104
|
-
this.
|
|
118
|
+
this._scheduleQuery(true);
|
|
105
119
|
});
|
|
106
120
|
|
|
107
121
|
waitOnce('pb-page-ready', () => {
|
|
@@ -110,7 +124,7 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
110
124
|
this._authorities[connector.register] = connector;
|
|
111
125
|
});
|
|
112
126
|
if (this.autoLookup) {
|
|
113
|
-
this.
|
|
127
|
+
this._scheduleQuery(true);
|
|
114
128
|
}
|
|
115
129
|
});
|
|
116
130
|
|
|
@@ -347,28 +361,76 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
347
361
|
}
|
|
348
362
|
this._results = [];
|
|
349
363
|
this.query = e.target.value;
|
|
350
|
-
this.
|
|
364
|
+
this._scheduleQuery();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
_scheduleQuery(immediate = false) {
|
|
368
|
+
if (this._queryTimer) {
|
|
369
|
+
clearTimeout(this._queryTimer);
|
|
370
|
+
this._queryTimer = null;
|
|
371
|
+
}
|
|
372
|
+
if (immediate) {
|
|
373
|
+
this._query();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this._queryTimer = setTimeout(() => {
|
|
377
|
+
this._queryTimer = null;
|
|
378
|
+
this._query();
|
|
379
|
+
}, this._queryDebounceMs);
|
|
351
380
|
}
|
|
352
381
|
|
|
353
382
|
_query() {
|
|
383
|
+
const generation = ++this._queryGeneration;
|
|
384
|
+
|
|
385
|
+
if (this._occurrencesController) {
|
|
386
|
+
this._occurrencesController.abort();
|
|
387
|
+
this._occurrencesController = null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const authority = this._authorities[this.type];
|
|
391
|
+
if (!authority) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
354
395
|
this.emitTo('pb-start-update');
|
|
355
|
-
|
|
356
|
-
|
|
396
|
+
authority
|
|
397
|
+
.query(this.query)
|
|
398
|
+
.then(results => {
|
|
399
|
+
if (generation !== this._queryGeneration) {
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
return this._occurrences(results.items, generation);
|
|
403
|
+
})
|
|
404
|
+
.then(merged => {
|
|
405
|
+
if (merged === undefined || generation !== this._queryGeneration) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
357
408
|
this._results = merged;
|
|
409
|
+
this.emitTo('pb-end-update');
|
|
410
|
+
})
|
|
411
|
+
.catch(err => {
|
|
412
|
+
if (generation !== this._queryGeneration) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
console.error('<pb-authority-lookup> query failed: %s', err.message);
|
|
416
|
+
this.emitTo('pb-end-update');
|
|
358
417
|
});
|
|
359
|
-
this.emitTo('pb-end-update');
|
|
360
|
-
// this.shadowRoot.getElementById('query').focus();
|
|
361
|
-
});
|
|
362
418
|
}
|
|
363
419
|
|
|
364
420
|
_addEntity() {
|
|
365
421
|
this.emitTo('pb-authority-new-entity', { query: this.query, type: this.type });
|
|
366
422
|
}
|
|
367
423
|
|
|
368
|
-
_occurrences(items) {
|
|
424
|
+
_occurrences(items, generation) {
|
|
369
425
|
if (this.noOccurrences) {
|
|
370
426
|
return Promise.resolve(items);
|
|
371
427
|
}
|
|
428
|
+
if (this._occurrencesController) {
|
|
429
|
+
this._occurrencesController.abort();
|
|
430
|
+
}
|
|
431
|
+
const controller = new AbortController();
|
|
432
|
+
this._occurrencesController = controller;
|
|
433
|
+
|
|
372
434
|
const params = new FormData();
|
|
373
435
|
params.append('register', this.type);
|
|
374
436
|
items.forEach(item => {
|
|
@@ -378,13 +440,27 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
378
440
|
fetch(`${this.getEndpoint()}/api/annotations/occurrences`, {
|
|
379
441
|
method: 'POST',
|
|
380
442
|
body: params,
|
|
443
|
+
signal: controller.signal,
|
|
381
444
|
})
|
|
382
445
|
.then(response => {
|
|
446
|
+
if (generation !== this._queryGeneration) {
|
|
447
|
+
resolve(undefined);
|
|
448
|
+
return undefined;
|
|
449
|
+
}
|
|
383
450
|
if (response.ok) {
|
|
384
451
|
return response.json();
|
|
385
452
|
}
|
|
453
|
+
resolve(items);
|
|
454
|
+
return undefined;
|
|
386
455
|
})
|
|
387
456
|
.then(json => {
|
|
457
|
+
if (json === undefined) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (generation !== this._queryGeneration) {
|
|
461
|
+
resolve(undefined);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
388
464
|
items.forEach(item => {
|
|
389
465
|
if (json[item.id]) {
|
|
390
466
|
item.occurrences = json[item.id];
|
|
@@ -406,6 +482,13 @@ export class PbAuthorityLookup extends themableMixin(pbMixin(LitElement)) {
|
|
|
406
482
|
return d;
|
|
407
483
|
});
|
|
408
484
|
resolve(items);
|
|
485
|
+
})
|
|
486
|
+
.catch(err => {
|
|
487
|
+
if (err.name === 'AbortError' || generation !== this._queryGeneration) {
|
|
488
|
+
resolve(undefined);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
resolve(items);
|
|
409
492
|
});
|
|
410
493
|
});
|
|
411
494
|
}
|
package/src/pb-view-annotate.js
CHANGED
|
@@ -342,10 +342,6 @@ class PbViewAnnotate extends PbView {
|
|
|
342
342
|
|
|
343
343
|
this.subscribeTo('pb-add-annotation', ev => this.addAnnotation(ev.detail));
|
|
344
344
|
this.subscribeTo('pb-edit-annotation', this._editAnnotation.bind(this));
|
|
345
|
-
this.subscribeTo('pb-start-update', () => {
|
|
346
|
-
this._cancelMarkerRefresh();
|
|
347
|
-
this._clearMarkers();
|
|
348
|
-
});
|
|
349
345
|
this.subscribeTo('pb-refresh', () => {
|
|
350
346
|
this._ranges = [];
|
|
351
347
|
this._rangesMap.clear();
|
|
@@ -471,6 +467,12 @@ class PbViewAnnotate extends PbView {
|
|
|
471
467
|
}
|
|
472
468
|
}
|
|
473
469
|
|
|
470
|
+
_doLoad(params) {
|
|
471
|
+
this._cancelMarkerRefresh();
|
|
472
|
+
this._clearMarkers();
|
|
473
|
+
super._doLoad(params);
|
|
474
|
+
}
|
|
475
|
+
|
|
474
476
|
_handleContent() {
|
|
475
477
|
super._handleContent();
|
|
476
478
|
this.updateComplete.then(() => {
|
|
@@ -861,6 +863,7 @@ class PbViewAnnotate extends PbView {
|
|
|
861
863
|
if (json[this.getKey(span.dataset.type)] !== '') {
|
|
862
864
|
span.classList.remove('incomplete');
|
|
863
865
|
}
|
|
866
|
+
this._scheduleMarkerRefresh();
|
|
864
867
|
}
|
|
865
868
|
|
|
866
869
|
_editAnnotation(ev) {
|