@teipublisher/pb-components 1.35.2 → 1.36.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.
@@ -10131,10 +10131,16 @@
10131
10131
  "attributes": [
10132
10132
  {
10133
10133
  "name": "key",
10134
- "description": "Configures the annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.",
10134
+ "description": "Configures the default annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.\n\nYou can also define a custom mapping of annotation types to key properties, e.g. if you would\nlike to use @key for some elements, but @corresp for others.",
10135
10135
  "type": "string",
10136
10136
  "default": "\"ref\""
10137
10137
  },
10138
+ {
10139
+ "name": "key-map",
10140
+ "description": "Optional mapping of annotation type names to key properties",
10141
+ "type": "object",
10142
+ "default": "{}"
10143
+ },
10138
10144
  {
10139
10145
  "name": "caseSensitive",
10140
10146
  "description": "When searching the displayed text for other potential occurrences of an entity,\nshould the search be done in case-sensitive manner?",
@@ -10309,10 +10315,17 @@
10309
10315
  {
10310
10316
  "name": "key",
10311
10317
  "attribute": "key",
10312
- "description": "Configures the annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.",
10318
+ "description": "Configures the default annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.\n\nYou can also define a custom mapping of annotation types to key properties, e.g. if you would\nlike to use @key for some elements, but @corresp for others.",
10313
10319
  "type": "string",
10314
10320
  "default": "\"ref\""
10315
10321
  },
10322
+ {
10323
+ "name": "keyMap",
10324
+ "attribute": "key-map",
10325
+ "description": "Optional mapping of annotation type names to key properties",
10326
+ "type": "object",
10327
+ "default": "{}"
10328
+ },
10316
10329
  {
10317
10330
  "name": "caseSensitive",
10318
10331
  "attribute": "caseSensitive",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "1.35.2",
3
+ "version": "1.36.0",
4
4
  "description": "Collection of webcomponents underlying TEI Publisher",
5
5
  "repository": "https://github.com/eeditiones/tei-publisher-components.git",
6
6
  "main": "index.html",
package/pb-elements.json CHANGED
@@ -10131,10 +10131,16 @@
10131
10131
  "attributes": [
10132
10132
  {
10133
10133
  "name": "key",
10134
- "description": "Configures the annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.",
10134
+ "description": "Configures the default annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.\n\nYou can also define a custom mapping of annotation types to key properties, e.g. if you would\nlike to use @key for some elements, but @corresp for others.",
10135
10135
  "type": "string",
10136
10136
  "default": "\"ref\""
10137
10137
  },
10138
+ {
10139
+ "name": "key-map",
10140
+ "description": "Optional mapping of annotation type names to key properties",
10141
+ "type": "object",
10142
+ "default": "{}"
10143
+ },
10138
10144
  {
10139
10145
  "name": "caseSensitive",
10140
10146
  "description": "When searching the displayed text for other potential occurrences of an entity,\nshould the search be done in case-sensitive manner?",
@@ -10309,10 +10315,17 @@
10309
10315
  {
10310
10316
  "name": "key",
10311
10317
  "attribute": "key",
10312
- "description": "Configures the annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.",
10318
+ "description": "Configures the default annotation property containing the key for authority entries.\nDefault: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when\nusing those attributes instead.\n\nYou can also define a custom mapping of annotation types to key properties, e.g. if you would\nlike to use @key for some elements, but @corresp for others.",
10313
10319
  "type": "string",
10314
10320
  "default": "\"ref\""
10315
10321
  },
10322
+ {
10323
+ "name": "keyMap",
10324
+ "attribute": "key-map",
10325
+ "description": "Optional mapping of annotation type names to key properties",
10326
+ "type": "object",
10327
+ "default": "{}"
10328
+ },
10316
10329
  {
10317
10330
  "name": "caseSensitive",
10318
10331
  "attribute": "caseSensitive",
@@ -11,8 +11,10 @@ export class KBGA extends Registry {
11
11
  const results = [];
12
12
 
13
13
  const register = this.getRegister();
14
- const url = `https://meta.karl-barth.ch/api/${register}?search=${encodeURIComponent(key)}`;
14
+ const searchParam = register === 'bibls' ? 'biblsearch' : 'search';
15
+ const url = `https://meta.karl-barth.ch/api/${register}?${searchParam}=${encodeURIComponent(key)}`;
15
16
  const label = this.getLabelField();
17
+ console.log(label);
16
18
  return new Promise((resolve) => {
17
19
  fetch(url)
18
20
  .then(response => response.json())
@@ -26,10 +28,10 @@ export class KBGA extends Registry {
26
28
  const result = {
27
29
  register: this._register,
28
30
  id: (this._prefix ? `${this._prefix}:${item['full-id']}` : item['full-id']),
29
- label: item[label],
31
+ label: typeof label === "string" ? item[label] : label(item),
30
32
  details: `${item['full-id']}`,
31
33
  link: `https://meta.karl-barth.ch/${register}/${item.id}`,
32
- strings: [item[label]],
34
+ strings: [typeof label === "string" ? item[label] : label(item)],
33
35
  provider: 'KBGA'
34
36
  };
35
37
  results.push(result);
@@ -54,7 +56,7 @@ export class KBGA extends Registry {
54
56
  const dates = json.data.birth ? `<p>* ${json.data.birth} ${died}</p>` : '';
55
57
  const note = json.data.note_bio ? `<p>${json.data.note_bio}</p>` : '';
56
58
  const output = `
57
- <h3 class="label"><a href="https://${json.wikipediaURL}" target="_blank">${json.data[label]}</a></h3>
59
+ <h3 class="label"><a href="https://${json.wikipediaURL}" target="_blank">${typeof label === 'string' ? json.data[label] : label(json.data)}</a></h3>
58
60
  ${dates}
59
61
  ${note}
60
62
  `;
@@ -112,6 +114,9 @@ export class KBGA extends Registry {
112
114
  case 'abbreviation':
113
115
  label = 'label';
114
116
  break;
117
+ case 'bibl':
118
+ label = (data) => data.title.m || data.title.s;
119
+ break;
115
120
  default:
116
121
  label = 'persName_full';
117
122
  break;
@@ -138,6 +143,9 @@ export class KBGA extends Registry {
138
143
  case 'abbreviation':
139
144
  register = 'abbreviations';
140
145
  break;
146
+ case 'bibl':
147
+ register = 'bibls';
148
+ break;
141
149
  default:
142
150
  register = this._register;
143
151
  }
@@ -223,13 +223,23 @@ class PbViewAnnotate extends PbView {
223
223
  static get properties() {
224
224
  return {
225
225
  /**
226
- * Configures the annotation property containing the key for authority entries.
226
+ * Configures the default annotation property containing the key for authority entries.
227
227
  * Default: 'ref', corresponding to TEI attribute @ref. Change to 'corresp' or 'key' when
228
228
  * using those attributes instead.
229
+ *
230
+ * You can also define a custom mapping of annotation types to key properties, e.g. if you would
231
+ * like to use @key for some elements, but @corresp for others.
229
232
  */
230
233
  key: {
231
234
  type: String
232
235
  },
236
+ /**
237
+ * Optional mapping of annotation type names to key properties
238
+ */
239
+ keyMap: {
240
+ type: Object,
241
+ attribute: 'key-map'
242
+ },
233
243
  /**
234
244
  * When searching the displayed text for other potential occurrences of an entity,
235
245
  * should the search be done in case-sensitive manner?
@@ -244,6 +254,7 @@ class PbViewAnnotate extends PbView {
244
254
  constructor() {
245
255
  super();
246
256
  this.key = 'ref';
257
+ this.keyMap = {};
247
258
  this.caseSensitive = false;
248
259
  this._ranges = [];
249
260
  this._rangesMap = new Map();
@@ -373,6 +384,10 @@ class PbViewAnnotate extends PbView {
373
384
  window.requestAnimationFrame(() => this.refreshMarkers());
374
385
  }
375
386
 
387
+ getKey(type) {
388
+ return this.keyMap[type] || this.key;
389
+ }
390
+
376
391
  _resizeHandler() {
377
392
  let _pendingCallback = null;
378
393
 
@@ -406,6 +421,7 @@ class PbViewAnnotate extends PbView {
406
421
  this._initAnnotationColors();
407
422
  this._annotationStyles();
408
423
  this.updateAnnotations();
424
+ this._markIncompleteAnnotations();
409
425
  if (this._scrollTop) {
410
426
  this.scrollTop = this._scrollTop;
411
427
  this._scrollTop = undefined;
@@ -459,7 +475,7 @@ class PbViewAnnotate extends PbView {
459
475
 
460
476
  console.log('<pb-view-annotate> Range: %o', range);
461
477
  const span = document.createElement('span');
462
- const addClass = teiRange.properties[this.key] === '' ? 'incomplete' : '';
478
+ const addClass = teiRange.properties[this.getKey(teiRange.type)] === '' ? 'incomplete' : '';
463
479
  span.className = `annotation annotation-${teiRange.type} ${teiRange.type} ${addClass}`;
464
480
  span.dataset.type = teiRange.type;
465
481
  span.dataset.annotation = JSON.stringify(teiRange.properties);
@@ -669,7 +685,7 @@ class PbViewAnnotate extends PbView {
669
685
  const jsonOld = JSON.parse(span.dataset.annotation);
670
686
  const json = Object.assign(jsonOld || {}, properties);
671
687
  span.dataset.annotation = JSON.stringify(json);
672
- if (json[this.key] !== '') {
688
+ if (json[this.getKey(span.dataset.type)] !== '') {
673
689
  span.classList.remove('incomplete');
674
690
  }
675
691
  }
@@ -770,10 +786,10 @@ class PbViewAnnotate extends PbView {
770
786
  typeInd.innerHTML = type;
771
787
  typeInd.style.backgroundColor = `var(--pb-annotation-${type})`;
772
788
  typeInd.style.color = `var(${color && color.isLight ? '--pb-color-primary' : '--pb-color-inverse'})`;
773
- if (data[this.key]) {
789
+ if (data[this.getKey(type)]) {
774
790
  this.emitTo('pb-annotation-detail', {
775
791
  type,
776
- id: data[this.key],
792
+ id: data[this.getKey(type)],
777
793
  container: info,
778
794
  span,
779
795
  });
@@ -910,7 +926,7 @@ class PbViewAnnotate extends PbView {
910
926
  if (annoData && annoType) {
911
927
  const parsed = JSON.parse(annoData) || {};
912
928
  isAnnotated = annoType === type;
913
- ref = parsed[this.key];
929
+ ref = parsed[this.getKey(type)];
914
930
  }
915
931
 
916
932
  const startRange = rangeToPoint(node, match.index);
@@ -925,7 +941,7 @@ class PbViewAnnotate extends PbView {
925
941
  textNode: node,
926
942
  kwic: kwicText(str, start + match.index, start + end),
927
943
  };
928
- entry[this.key] = ref;
944
+ entry[this.getKey(type)] = ref;
929
945
  result.push(entry);
930
946
  }
931
947
  }
@@ -973,10 +989,23 @@ class PbViewAnnotate extends PbView {
973
989
  }
974
990
  }
975
991
 
992
+ _markIncompleteAnnotations() {
993
+ const elem = this.shadowRoot.getElementById('view')
994
+ elem.querySelectorAll('.annotation.authority').forEach((annotation) => {
995
+ if (annotation.dataset.type) {
996
+ const data = JSON.parse(annotation.dataset.annotation);
997
+ const key = this.getKey(annotation.dataset.type);
998
+ if (!data[key] || data[key].length === 0) {
999
+ annotation.classList.add('incomplete');
1000
+ }
1001
+ }
1002
+ });
1003
+ }
1004
+
976
1005
  _initAnnotationColors() {
977
1006
  this._annotationColors = new Map();
978
1007
  const types = new Set();
979
- const elem = this.shadowRoot.getElementById('view')
1008
+ const elem = this.shadowRoot.getElementById('view');
980
1009
  elem.querySelectorAll('.annotation').forEach((annotation) => {
981
1010
  if (annotation.dataset.type) {
982
1011
  types.add(annotation.dataset.type);
@@ -1043,7 +1072,7 @@ class PbViewAnnotate extends PbView {
1043
1072
  styles = document.createElement('style');
1044
1073
  styles.className = '_annotation-styles';
1045
1074
  styles.innerHTML = css;
1046
- view.appendChild(styles);
1075
+ view.insertBefore(styles, view.firstChild);
1047
1076
  }
1048
1077
 
1049
1078
  static get styles() {