@teipublisher/pb-components 1.27.0 → 1.27.1
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 +7 -0
- package/dist/pb-components-bundle.js +119 -119
- package/package.json +1 -1
- package/src/authority/connectors.js +4 -0
- package/src/authority/reconciliation.js +124 -0
- package/src/pb-view-annotate.js +21 -6
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { Airtable } from './airtable.js';
|
|
|
4
4
|
import { GND } from './gnd.js';
|
|
5
5
|
import { KBGA } from './kbga.js';
|
|
6
6
|
import { GF } from './gf.js';
|
|
7
|
+
import { ReconciliationService } from './reconciliation.js';
|
|
7
8
|
import { Custom } from './custom.js';
|
|
8
9
|
|
|
9
10
|
export function createConnectors(endpoint, root) {
|
|
@@ -27,6 +28,9 @@ export function createConnectors(endpoint, root) {
|
|
|
27
28
|
case 'GF':
|
|
28
29
|
instance = new GF(configElem);
|
|
29
30
|
break;
|
|
31
|
+
case 'ReconciliationService':
|
|
32
|
+
instance = new ReconciliationService(configElem);
|
|
33
|
+
break;
|
|
30
34
|
case 'Custom':
|
|
31
35
|
instance = new Custom(endpoint, configElem);
|
|
32
36
|
break;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import { Registry } from './registry.js'
|
|
3
|
+
|
|
4
|
+
// Todo:
|
|
5
|
+
// - strings <- types
|
|
6
|
+
// - use scheme#types in @type output?
|
|
7
|
+
// - test with other providers, inside custom connector
|
|
8
|
+
// - documentation
|
|
9
|
+
|
|
10
|
+
async function getServiceManifest (endpoint) {
|
|
11
|
+
const response = await fetch(endpoint);
|
|
12
|
+
const data = await response.json();
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ReconciliationService extends Registry {
|
|
17
|
+
constructor(configElem) {
|
|
18
|
+
super(configElem)
|
|
19
|
+
this.endpoint = configElem.getAttribute('endpoint');
|
|
20
|
+
this.debug = configElem.getAttribute('debug');
|
|
21
|
+
getServiceManifest(this.endpoint).then((result) => {
|
|
22
|
+
this.ORConfig = result;
|
|
23
|
+
if (this.debug) {
|
|
24
|
+
console.log(
|
|
25
|
+
'OpenReconcile connector for register \'%s\' at endpoint <%s>. Using config: %o',
|
|
26
|
+
this._register, this.endpoint, this.ORConfig
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Query the authority and return a RegistryResult.
|
|
34
|
+
*
|
|
35
|
+
* @param {String} key the search string
|
|
36
|
+
*/
|
|
37
|
+
async query(key) {
|
|
38
|
+
const results = [];
|
|
39
|
+
const paramsObj = {
|
|
40
|
+
q1: {
|
|
41
|
+
query: key
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
fetch(this.endpoint, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Accept': 'application/json',
|
|
50
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
51
|
+
},
|
|
52
|
+
body: "queries=".concat(JSON.stringify(paramsObj))
|
|
53
|
+
})
|
|
54
|
+
.then((response) => response.json())
|
|
55
|
+
.then((json) => {
|
|
56
|
+
json.q1.result.forEach((item) => {
|
|
57
|
+
if (this.ORConfig.view) {
|
|
58
|
+
this.view = this.ORConfig.view.url.replace('{{id}}', item.id);
|
|
59
|
+
} else {
|
|
60
|
+
this.view = item.id;
|
|
61
|
+
}
|
|
62
|
+
if (item.description) {
|
|
63
|
+
this.description = item.description;
|
|
64
|
+
} else if (item.type) {
|
|
65
|
+
this.description = item.type.map(t => t.name.toString() ).join(', ')
|
|
66
|
+
} else {
|
|
67
|
+
this.description = ""
|
|
68
|
+
}
|
|
69
|
+
const result = {
|
|
70
|
+
register: this._register,
|
|
71
|
+
id: (this._prefix ? `${this._prefix}-${item.id}` : item.id),
|
|
72
|
+
label: item.name,
|
|
73
|
+
link: this.view,
|
|
74
|
+
details: this.description,
|
|
75
|
+
provider: 'OpenReconcile'
|
|
76
|
+
};
|
|
77
|
+
results.push(result);
|
|
78
|
+
});
|
|
79
|
+
if (this.debug) {
|
|
80
|
+
console.log(
|
|
81
|
+
'OpenReconcile results: %o',
|
|
82
|
+
results
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
resolve({
|
|
86
|
+
totalItems: json.q1.result.length,
|
|
87
|
+
items: results,
|
|
88
|
+
});
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Retrieve information about a registry entry and display it
|
|
95
|
+
* using the given container.
|
|
96
|
+
*
|
|
97
|
+
* @param {String} id the id to look up
|
|
98
|
+
* @param {HTMLElement} container reference to an element which should be used as container for displaying the information
|
|
99
|
+
* @returns {Promise} a promise
|
|
100
|
+
*/
|
|
101
|
+
info(id, container) {
|
|
102
|
+
if (!id) {
|
|
103
|
+
return Promise.resolve({});
|
|
104
|
+
}
|
|
105
|
+
if (!this.ORConfig.preview) {
|
|
106
|
+
container.innerHTML = 'no \'preview\' information in endpoint\'s manifest';
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const rawid = this._prefix ? id.substring(this._prefix.length + 1) : id;
|
|
112
|
+
const url = this.ORConfig.preview.url.replace('{{id}}', encodeURIComponent(rawid));
|
|
113
|
+
fetch(url)
|
|
114
|
+
.then(response => response.text())
|
|
115
|
+
.then((output) => {
|
|
116
|
+
container.innerHTML = output;
|
|
117
|
+
resolve({
|
|
118
|
+
id: this._prefix ? `${this._prefix}-${rawid}` : rawid
|
|
119
|
+
});
|
|
120
|
+
})
|
|
121
|
+
.catch(() => reject());
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
package/src/pb-view-annotate.js
CHANGED
|
@@ -454,7 +454,8 @@ class PbViewAnnotate extends PbView {
|
|
|
454
454
|
|
|
455
455
|
console.log('<pb-view-annotate> Range: %o', range);
|
|
456
456
|
const span = document.createElement('span');
|
|
457
|
-
|
|
457
|
+
const addClass = teiRange.properties[this.key] === '' ? 'incomplete' : '';
|
|
458
|
+
span.className = `annotation annotation-${teiRange.type} ${teiRange.type} ${addClass}`;
|
|
458
459
|
span.dataset.type = teiRange.type;
|
|
459
460
|
span.dataset.annotation = JSON.stringify(teiRange.properties);
|
|
460
461
|
|
|
@@ -657,9 +658,12 @@ class PbViewAnnotate extends PbView {
|
|
|
657
658
|
range = clearProperties(range);
|
|
658
659
|
this.emitTo('pb-annotations-changed', { ranges: this._ranges });
|
|
659
660
|
}
|
|
660
|
-
|
|
661
|
-
const json = Object.assign(
|
|
661
|
+
const jsonOld = JSON.parse(span.dataset.annotation);
|
|
662
|
+
const json = Object.assign(jsonOld || {}, properties);
|
|
662
663
|
span.dataset.annotation = JSON.stringify(json);
|
|
664
|
+
if (json[this.key] !== '') {
|
|
665
|
+
span.classList.remove('incomplete');
|
|
666
|
+
}
|
|
663
667
|
}
|
|
664
668
|
|
|
665
669
|
_editAnnotation(ev) {
|
|
@@ -753,7 +757,7 @@ class PbViewAnnotate extends PbView {
|
|
|
753
757
|
ev.preventDefault();
|
|
754
758
|
ev.stopPropagation();
|
|
755
759
|
const type = span.dataset.type;
|
|
756
|
-
const data = JSON.parse(span.dataset.annotation);
|
|
760
|
+
const data = JSON.parse(span.dataset.annotation) || {};
|
|
757
761
|
const color = this._annotationColors.get(type);
|
|
758
762
|
typeInd.innerHTML = type;
|
|
759
763
|
typeInd.style.backgroundColor = `var(--pb-annotation-${type})`;
|
|
@@ -896,7 +900,7 @@ class PbViewAnnotate extends PbView {
|
|
|
896
900
|
const annoData = node.parentNode.dataset.annotation;
|
|
897
901
|
const annoType = node.parentNode.dataset.type;
|
|
898
902
|
if (annoData && annoType) {
|
|
899
|
-
const parsed = JSON.parse(annoData);
|
|
903
|
+
const parsed = JSON.parse(annoData) || {};
|
|
900
904
|
isAnnotated = annoType === type;
|
|
901
905
|
ref = parsed[this.key];
|
|
902
906
|
}
|
|
@@ -1004,6 +1008,17 @@ class PbViewAnnotate extends PbView {
|
|
|
1004
1008
|
classes.push(`
|
|
1005
1009
|
.annotation-${type}::after {
|
|
1006
1010
|
background-color: var(--pb-annotation-${type});
|
|
1011
|
+
border-color: var(--pb-annotation-${type});
|
|
1012
|
+
color: var(${color.isLight ? '--pb-color-primary' : '--pb-color-inverse'});
|
|
1013
|
+
}
|
|
1014
|
+
.annotation-${type}.incomplete::after {
|
|
1015
|
+
background: repeating-linear-gradient(
|
|
1016
|
+
315deg,
|
|
1017
|
+
var(--pb-annotation-${type}),
|
|
1018
|
+
var(--pb-annotation-${type}) 5px,
|
|
1019
|
+
var(${color.isLight ? '--pb-annotation-stripes-light' : '--pb-annotation-stripes-dark'}) 5px,
|
|
1020
|
+
var(${color.isLight ? '--pb-annotation-stripes-light' : '--pb-annotation-stripes-dark'}) 10px
|
|
1021
|
+
);
|
|
1007
1022
|
color: var(${color.isLight ? '--pb-color-primary' : '--pb-color-inverse'});
|
|
1008
1023
|
}
|
|
1009
1024
|
`);
|
|
@@ -1064,7 +1079,7 @@ class PbViewAnnotate extends PbView {
|
|
|
1064
1079
|
font-variant: normal;
|
|
1065
1080
|
padding: 2px;
|
|
1066
1081
|
}
|
|
1067
|
-
|
|
1082
|
+
|
|
1068
1083
|
[part=highlight] {
|
|
1069
1084
|
border: 3px solid rgb(255, 174, 0);
|
|
1070
1085
|
border-radius: 8px;
|