@teipublisher/pb-components 2.25.5 → 2.25.6

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.
Files changed (128) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +3 -3
  4. package/CHANGELOG.md +8 -0
  5. package/Dockerfile +78 -70
  6. package/css/components.css +5 -5
  7. package/dist/demo/pb-drawer2.html +1 -1
  8. package/dist/demo/pb-leaflet-map.html +1 -1
  9. package/dist/demo/pb-repeat.html +1 -3
  10. package/dist/demo/pb-view3.html +1 -1
  11. package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
  12. package/dist/pb-code-editor.js +25 -20
  13. package/dist/pb-component-docs.js +58 -54
  14. package/dist/pb-components-bundle.js +1827 -1520
  15. package/dist/pb-edit-app.js +167 -107
  16. package/dist/pb-elements.json +54 -54
  17. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  18. package/dist/pb-leaflet-map.js +23 -23
  19. package/dist/pb-mei.js +56 -41
  20. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  21. package/dist/pb-odd-editor.js +925 -758
  22. package/dist/pb-tify.js +2 -2
  23. package/dist/{vaadin-element-mixin-859a0132.js → vaadin-element-mixin-ad07ba25.js} +88 -61
  24. package/gh-pages.js +5 -3
  25. package/package.json +2 -2
  26. package/pb-elements.json +54 -54
  27. package/src/assets/components.css +5 -5
  28. package/src/authority/airtable.js +20 -21
  29. package/src/authority/anton.js +129 -129
  30. package/src/authority/custom.js +23 -21
  31. package/src/authority/geonames.js +38 -32
  32. package/src/authority/gnd.js +47 -42
  33. package/src/authority/kbga.js +137 -134
  34. package/src/authority/metagrid.js +44 -46
  35. package/src/authority/reconciliation.js +66 -67
  36. package/src/authority/registry.js +4 -4
  37. package/src/docs/pb-component-docs.js +2 -2
  38. package/src/docs/pb-component-view.js +5 -5
  39. package/src/docs/pb-components-list.js +2 -2
  40. package/src/docs/pb-demo-snippet.js +2 -2
  41. package/src/dts-client.js +299 -297
  42. package/src/dts-select-endpoint.js +90 -82
  43. package/src/parse-date-service.js +184 -135
  44. package/src/pb-ajax.js +171 -167
  45. package/src/pb-authority-lookup.js +96 -81
  46. package/src/pb-autocomplete.js +292 -280
  47. package/src/pb-blacklab-highlight.js +264 -259
  48. package/src/pb-blacklab-results.js +236 -221
  49. package/src/pb-browse-docs.js +540 -475
  50. package/src/pb-browse.js +68 -65
  51. package/src/pb-clipboard.js +79 -76
  52. package/src/pb-code-editor.js +110 -102
  53. package/src/pb-code-highlight.js +209 -204
  54. package/src/pb-codepen.js +79 -72
  55. package/src/pb-collapse.js +149 -146
  56. package/src/pb-combo-box.js +190 -190
  57. package/src/pb-components-bundle.js +1 -1
  58. package/src/pb-custom-form.js +150 -149
  59. package/src/pb-document.js +89 -90
  60. package/src/pb-download.js +208 -195
  61. package/src/pb-drawer.js +145 -148
  62. package/src/pb-edit-app.js +301 -229
  63. package/src/pb-edit-xml.js +99 -96
  64. package/src/pb-events.js +114 -107
  65. package/src/pb-facs-link.js +104 -102
  66. package/src/pb-facsimile.js +411 -413
  67. package/src/pb-formula.js +151 -153
  68. package/src/pb-geolocation.js +129 -131
  69. package/src/pb-grid-action.js +53 -56
  70. package/src/pb-grid.js +231 -228
  71. package/src/pb-highlight.js +140 -140
  72. package/src/pb-hotkeys.js +40 -42
  73. package/src/pb-i18n.js +101 -104
  74. package/src/pb-image-strip.js +84 -78
  75. package/src/pb-lang.js +83 -70
  76. package/src/pb-leaflet-map.js +488 -485
  77. package/src/pb-link.js +126 -124
  78. package/src/pb-load.js +431 -426
  79. package/src/pb-login.js +275 -254
  80. package/src/pb-manage-odds.js +364 -318
  81. package/src/pb-map-icon.js +89 -89
  82. package/src/pb-map-layer.js +85 -85
  83. package/src/pb-markdown.js +90 -99
  84. package/src/pb-media-query.js +74 -72
  85. package/src/pb-mei.js +306 -295
  86. package/src/pb-message.js +143 -130
  87. package/src/pb-mixin.js +269 -264
  88. package/src/pb-navigation.js +80 -82
  89. package/src/pb-observable.js +38 -38
  90. package/src/pb-odd-editor.js +1056 -958
  91. package/src/pb-odd-elementspec-editor.js +348 -297
  92. package/src/pb-odd-model-editor.js +1058 -898
  93. package/src/pb-odd-parameter-editor.js +200 -178
  94. package/src/pb-odd-rendition-editor.js +136 -124
  95. package/src/pb-page.js +432 -422
  96. package/src/pb-paginate.js +202 -190
  97. package/src/pb-panel.js +191 -179
  98. package/src/pb-popover-themes.js +7 -5
  99. package/src/pb-popover.js +296 -287
  100. package/src/pb-print-preview.js +127 -127
  101. package/src/pb-progress.js +49 -49
  102. package/src/pb-repeat.js +105 -104
  103. package/src/pb-restricted.js +84 -77
  104. package/src/pb-search.js +238 -221
  105. package/src/pb-select-feature.js +127 -120
  106. package/src/pb-select-odd.js +132 -124
  107. package/src/pb-select-template.js +89 -78
  108. package/src/pb-select.js +251 -227
  109. package/src/pb-split-list.js +179 -174
  110. package/src/pb-svg.js +80 -79
  111. package/src/pb-table-column.js +54 -54
  112. package/src/pb-table-grid.js +221 -203
  113. package/src/pb-tabs.js +61 -63
  114. package/src/pb-tify.js +154 -154
  115. package/src/pb-timeline.js +271 -229
  116. package/src/pb-toggle-feature.js +198 -185
  117. package/src/pb-upload.js +184 -174
  118. package/src/pb-version.js +30 -30
  119. package/src/pb-view-annotate.js +132 -98
  120. package/src/pb-view.js +1282 -1263
  121. package/src/pb-zoom.js +40 -40
  122. package/src/polymer-hack.js +1 -1
  123. package/src/search-result-service.js +256 -223
  124. package/src/seed-element.js +13 -20
  125. package/src/settings.js +4 -4
  126. package/src/theming.js +91 -91
  127. package/src/urls.js +289 -289
  128. package/src/utils.js +53 -51
@@ -4,11 +4,11 @@ import { resolveURL } from '../utils.js';
4
4
 
5
5
  function expandTemplate(template = '', options) {
6
6
  return template.replace(/\${([^}]+)}/g, (match, p) => {
7
- let replacement;
8
- if (options[p]) {
9
- replacement = options[p];
10
- }
11
- return replacement || '';
7
+ let replacement;
8
+ if (options[p]) {
9
+ replacement = options[p];
10
+ }
11
+ return replacement || '';
12
12
  });
13
13
  }
14
14
 
@@ -23,7 +23,6 @@ function getTemplate(configElem, selector) {
23
23
  }
24
24
 
25
25
  export class Airtable extends Registry {
26
-
27
26
  constructor(configElem) {
28
27
  super(configElem);
29
28
  this.apiKey = configElem.getAttribute('api-key');
@@ -45,7 +44,7 @@ export class Airtable extends Registry {
45
44
  this.tokenize = [this.fields[0]];
46
45
  }
47
46
 
48
- this.tokenizeChars = configElem.getAttribute('tokenize-regex') || "\\W";
47
+ this.tokenizeChars = configElem.getAttribute('tokenize-regex') || '\\W';
49
48
 
50
49
  this.infoExpr = getTemplate(configElem, '.info');
51
50
  this.detailExpr = getTemplate(configElem, '.detail');
@@ -54,14 +53,12 @@ export class Airtable extends Registry {
54
53
  }
55
54
 
56
55
  _init() {
57
- window.ESGlobalBridge.requestAvailability();
58
- const path = resolveURL('../lib/airtable.browser.js');
59
- window.ESGlobalBridge.instance.load('airtable', path);
60
- window.addEventListener(
61
- 'es-bridge-airtable-loaded',
62
- this._initAirtable.bind(this),
63
- { once: true },
64
- );
56
+ window.ESGlobalBridge.requestAvailability();
57
+ const path = resolveURL('../lib/airtable.browser.js');
58
+ window.ESGlobalBridge.instance.load('airtable', path);
59
+ window.addEventListener('es-bridge-airtable-loaded', this._initAirtable.bind(this), {
60
+ once: true,
61
+ });
65
62
  }
66
63
 
67
64
  _initAirtable() {
@@ -76,7 +73,7 @@ export class Airtable extends Registry {
76
73
  const options = {
77
74
  fields: this.fields,
78
75
  // Selecting the first 3 records in Grid view:
79
- maxRecords: 100
76
+ maxRecords: 100,
80
77
  };
81
78
  if (this.view) {
82
79
  options.view = this.view;
@@ -95,13 +92,15 @@ export class Airtable extends Registry {
95
92
  }
96
93
  records.forEach(record => {
97
94
  const data = {};
98
- this.fields.forEach((field) => { data[field] = record.get(field); });
95
+ this.fields.forEach(field => {
96
+ data[field] = record.get(field);
97
+ });
99
98
  const result = {
100
99
  register: this._register,
101
100
  id: record.id,
102
101
  label: expandTemplate(this.labelExpr, data),
103
102
  details: expandTemplate(this.detailExpr, data),
104
- provider: 'airtable'
103
+ provider: 'airtable',
105
104
  };
106
105
  results.push(result);
107
106
  });
@@ -133,7 +132,7 @@ export class Airtable extends Registry {
133
132
  }
134
133
  let strings = [];
135
134
  const data = {};
136
- this.fields.forEach((field) => {
135
+ this.fields.forEach(field => {
137
136
  const value = record.get(field);
138
137
  if (value) {
139
138
  data[field] = value;
@@ -141,7 +140,7 @@ export class Airtable extends Registry {
141
140
  }
142
141
  });
143
142
  const regex = new RegExp(this.tokenizeChars);
144
- this.tokenize.forEach((key) => {
143
+ this.tokenize.forEach(key => {
145
144
  if (data[key]) {
146
145
  strings = strings.concat(data[key].split(regex));
147
146
  }
@@ -152,7 +151,7 @@ export class Airtable extends Registry {
152
151
 
153
152
  resolve({
154
153
  id: record.id,
155
- strings
154
+ strings,
156
155
  });
157
156
  });
158
157
  });
@@ -1,89 +1,89 @@
1
- import { Registry } from "./registry.js";
1
+ import { Registry } from './registry.js';
2
2
 
3
3
  /**
4
4
  * Connector for the corporate archive of Georgfischer AG.
5
5
  */
6
6
  export class Anton extends Registry {
7
-
8
- constructor(configElem) {
9
- super(configElem);
10
- this._url = configElem.getAttribute('url') || `https://archives.georgfischer.com/api`;
11
- this._api = configElem.getAttribute('api');
12
- this._limit = configElem.getAttribute('limit') || 999999;
13
- this._provider = configElem.getAttribute('provider') || configElem.getAttribute('connector')
14
- }
7
+ constructor(configElem) {
8
+ super(configElem);
9
+ this._url = configElem.getAttribute('url') || `https://archives.georgfischer.com/api`;
10
+ this._api = configElem.getAttribute('api');
11
+ this._limit = configElem.getAttribute('limit') || 999999;
12
+ this._provider = configElem.getAttribute('provider') || configElem.getAttribute('connector');
13
+ }
15
14
 
16
- async query(key) {
17
- const results = [];
18
-
19
- const register = this.getRegister();
20
- const url = `${this._url}/${register}?search=${encodeURIComponent(key)}&perPage=${this._limit}`;
21
- const label = this.getLabelField();
22
- return new Promise((resolve) => {
23
- fetch(url)
24
- .then(response => response.json())
25
- .then(json => {
26
- if (!json.data) {
27
- resolve({
28
- totalItems: 0,
29
- items: []
30
- });
31
- return;
32
- }
33
- json.data.forEach(item => {
34
- if ((this._register === 'organization' && item.authority_type === 'Person') ||
35
- (this._register === 'person' && item.authority_type !== 'Person')) {
36
- return;
37
- }
38
- const result = {
39
- register: this._register,
40
- id: (this._prefix ? `${this._prefix}-${item.id}` : item.id),
41
- label: item[label],
42
- details: `${item.id}`,
43
- link: `${this._url}/${register}/${item.id}`,
44
- strings: [item[label]],
45
- provider: this._provider
46
- };
47
- results.push(result);
48
- });
49
- resolve({
50
- totalItems: json.meta.total,
51
- items: results,
52
- });
53
- })
54
- .catch((reason) => Promise.reject(reason));
55
- })
56
- }
15
+ async query(key) {
16
+ const results = [];
57
17
 
58
- info(key, container) {
59
- if (!key) {
60
- return Promise.resolve({});
61
- }
62
- const id = this._prefix ? key.substring(this._prefix.length + 1) : key;
63
- const label = this.getLabelField();
64
- return new Promise((resolve) => {
65
- this.getRecord(id)
18
+ const register = this.getRegister();
19
+ const url = `${this._url}/${register}?search=${encodeURIComponent(key)}&perPage=${this._limit}`;
20
+ const label = this.getLabelField();
21
+ return new Promise(resolve => {
22
+ fetch(url)
23
+ .then(response => response.json())
66
24
  .then(json => {
67
- const died = json.data.death ? `† ${json.data.death}` : '';
68
- const dates = json.data.birth ? `<p>* ${json.data.birth} ${died}</p>` : '';
69
- const note = json.data.note_bio ? `<p>${json.data.note_bio}</p>` : '';
70
- const output = `
25
+ if (!json.data) {
26
+ resolve({
27
+ totalItems: 0,
28
+ items: [],
29
+ });
30
+ return;
31
+ }
32
+ json.data.forEach(item => {
33
+ if (
34
+ (this._register === 'organization' && item.authority_type === 'Person') ||
35
+ (this._register === 'person' && item.authority_type !== 'Person')
36
+ ) {
37
+ return;
38
+ }
39
+ const result = {
40
+ register: this._register,
41
+ id: this._prefix ? `${this._prefix}-${item.id}` : item.id,
42
+ label: item[label],
43
+ details: `${item.id}`,
44
+ link: `${this._url}/${register}/${item.id}`,
45
+ strings: [item[label]],
46
+ provider: this._provider,
47
+ };
48
+ results.push(result);
49
+ });
50
+ resolve({
51
+ totalItems: json.meta.total,
52
+ items: results,
53
+ });
54
+ })
55
+ .catch(reason => Promise.reject(reason));
56
+ });
57
+ }
58
+
59
+ info(key, container) {
60
+ if (!key) {
61
+ return Promise.resolve({});
62
+ }
63
+ const id = this._prefix ? key.substring(this._prefix.length + 1) : key;
64
+ const label = this.getLabelField();
65
+ return new Promise(resolve => {
66
+ this.getRecord(id).then(json => {
67
+ const died = json.data.death ? `† ${json.data.death}` : '';
68
+ const dates = json.data.birth ? `<p>* ${json.data.birth} ${died}</p>` : '';
69
+ const note = json.data.note_bio ? `<p>${json.data.note_bio}</p>` : '';
70
+ const output = `
71
71
  <h3 class="label"><a href="https://${json.wikipediaURL}" target="_blank">${json.data[label]}</a></h3>
72
72
  ${dates}
73
73
  ${note}
74
74
  `;
75
- container.innerHTML = output;
76
- resolve({
77
- id: (this._prefix ? `${this._prefix}-${json.data.id}` : json.data.id),
78
- strings: [json.data[label]]
79
- });
75
+ container.innerHTML = output;
76
+ resolve({
77
+ id: this._prefix ? `${this._prefix}-${json.data.id}` : json.data.id,
78
+ strings: [json.data[label]],
80
79
  });
81
80
  });
82
- }
81
+ });
82
+ }
83
83
 
84
- /**
84
+ /**
85
85
  * Retrieve a raw JSON record for the given key as returned by the endpoint.
86
- *
86
+ *
87
87
  * @param {string} key the key to look up
88
88
  * @returns {Promise<any>} promise resolving to the JSON record returned by the endpoint
89
89
  */
@@ -91,68 +91,68 @@ export class Anton extends Registry {
91
91
  const id = key.replace(/^.*-([^-]+)$/, '$1');
92
92
  const url = `${this._url}/${this.getRegister()}/${id}`;
93
93
  return fetch(url)
94
- .then(response => response.json())
95
- .then(json => {
96
- const output = Object.assign({}, json);
97
- output.name = json.data[this.getLabelField()];
98
- switch (this._register) {
99
- case 'place':
100
- output.country = json.data.country;
101
- if (json.data.location && json.data.location.coordinates) {
102
- output.location = json.data.location.coordinates;
103
- }
104
- output.links = json.data.links.map((link) => link.url);
105
- break;
106
- case 'person':
107
- output.birth = json.data.birth;
108
- output.death = json.data.death;
109
- output.note = json.data.note_bio;
110
- output.links = [`https://${json.wikipediaURL}`];
111
- break;
112
- default:
113
- break;
114
- }
115
- return output;
116
- })
117
- .catch((reason) => Promise.reject(reason));
94
+ .then(response => response.json())
95
+ .then(json => {
96
+ const output = { ...json };
97
+ output.name = json.data[this.getLabelField()];
98
+ switch (this._register) {
99
+ case 'place':
100
+ output.country = json.data.country;
101
+ if (json.data.location && json.data.location.coordinates) {
102
+ output.location = json.data.location.coordinates;
103
+ }
104
+ output.links = json.data.links.map(link => link.url);
105
+ break;
106
+ case 'person':
107
+ output.birth = json.data.birth;
108
+ output.death = json.data.death;
109
+ output.note = json.data.note_bio;
110
+ output.links = [`https://${json.wikipediaURL}`];
111
+ break;
112
+ default:
113
+ break;
114
+ }
115
+ return output;
116
+ })
117
+ .catch(reason => Promise.reject(reason));
118
118
  }
119
119
 
120
- getLabelField() {
121
- let label;
122
- switch (this._register) {
123
- case 'term':
124
- label = 'label';
125
- break;
126
- default:
127
- label = 'fullname';
128
- break;
129
- }
130
- return label;
120
+ getLabelField() {
121
+ let label;
122
+ switch (this._register) {
123
+ case 'term':
124
+ label = 'label';
125
+ break;
126
+ default:
127
+ label = 'fullname';
128
+ break;
131
129
  }
130
+ return label;
131
+ }
132
132
 
133
- getRegister() {
134
- if (this._api) {
135
- return this._api;
136
- }
137
- let register;
138
- switch(this._register) {
139
- case 'person':
140
- case 'organization':
141
- register = 'actors';
142
- break;
143
- case 'origPlace':
144
- case 'place':
145
- register = 'places';
146
- break;
147
- case 'term':
148
- register = 'keywords';
149
- break;
150
- case 'abbreviation':
151
- register = 'abbreviations';
152
- break;
153
- default:
154
- register = this._register;
155
- }
156
- return register;
133
+ getRegister() {
134
+ if (this._api) {
135
+ return this._api;
157
136
  }
137
+ let register;
138
+ switch (this._register) {
139
+ case 'person':
140
+ case 'organization':
141
+ register = 'actors';
142
+ break;
143
+ case 'origPlace':
144
+ case 'place':
145
+ register = 'places';
146
+ break;
147
+ case 'term':
148
+ register = 'keywords';
149
+ break;
150
+ case 'abbreviation':
151
+ register = 'abbreviations';
152
+ break;
153
+ default:
154
+ register = this._register;
155
+ }
156
+ return register;
157
+ }
158
158
  }
@@ -3,13 +3,12 @@ import { Registry } from './registry.js';
3
3
  import { createConnectors } from './connectors.js';
4
4
 
5
5
  export class Custom extends Registry {
6
-
7
6
  constructor(endpoint, configElem) {
8
7
  super(configElem);
9
8
  this._editable = configElem.hasAttribute('edit');
10
9
  this._endpoint = endpoint;
11
10
  this._connectors = createConnectors(endpoint, configElem);
12
- this._connectors.forEach((connector) => {
11
+ this._connectors.forEach(connector => {
13
12
  connector.name = this.name;
14
13
  });
15
14
  console.log(
@@ -39,7 +38,7 @@ export class Custom extends Registry {
39
38
  label: item.label,
40
39
  link: item.link,
41
40
  details: item.details,
42
- provider: 'local'
41
+ provider: 'local',
43
42
  });
44
43
  localResults.add(item.id);
45
44
  });
@@ -48,7 +47,7 @@ export class Custom extends Registry {
48
47
  for (const connector of this._connectors) {
49
48
  // eslint-disable-next-line no-await-in-loop
50
49
  const dr = await connector.query(key);
51
- results = results.concat(dr.items.filter((result) => !localResults.has(result.id)));
50
+ results = results.concat(dr.items.filter(result => !localResults.has(result.id)));
52
51
  totalItems += dr.totalItems;
53
52
  }
54
53
  resolve({
@@ -65,15 +64,15 @@ export class Custom extends Registry {
65
64
  }
66
65
  const id = key;
67
66
  return new Promise((resolve, reject) => {
68
- fetch(`${this._endpoint}/api/register/${this._register}/${encodeURIComponent(id)}`)
69
- .then(async (response) => {
67
+ fetch(`${this._endpoint}/api/register/${this._register}/${encodeURIComponent(id)}`).then(
68
+ async response => {
70
69
  if (response.ok) {
71
70
  const json = await response.json();
72
71
  container.innerHTML = json.details;
73
72
  resolve({
74
73
  id: json.id,
75
74
  strings: json.strings,
76
- editable: this._editable
75
+ editable: this._editable,
77
76
  });
78
77
  return;
79
78
  }
@@ -87,17 +86,18 @@ export class Custom extends Registry {
87
86
  }
88
87
  } catch (e) {
89
88
  // not found: continue
90
- };
89
+ }
91
90
  }
92
91
  }
93
92
  reject();
94
- });
93
+ },
94
+ );
95
95
  });
96
96
  }
97
97
 
98
98
  /**
99
- *
100
- * @param {any} item
99
+ *
100
+ * @param {any} item
101
101
  * @returns {Promise}
102
102
  */
103
103
  async select(item) {
@@ -112,16 +112,18 @@ export class Custom extends Registry {
112
112
  if (!entry) {
113
113
  return Promise.resolve(item);
114
114
  }
115
- return fetch(`${this._endpoint}/api/register/${this._register}/${encodeURIComponent(item.id)}`, {
116
- method: 'POST',
117
- mode: "cors",
118
- credentials: "same-origin",
119
- headers: {
120
- "Content-Type": "application/json",
121
- },
122
- body: JSON.stringify(entry),
123
- })
124
- .then((response) => {
115
+ return fetch(
116
+ `${this._endpoint}/api/register/${this._register}/${encodeURIComponent(item.id)}`,
117
+ {
118
+ method: 'POST',
119
+ mode: 'cors',
120
+ credentials: 'same-origin',
121
+ headers: {
122
+ 'Content-Type': 'application/json',
123
+ },
124
+ body: JSON.stringify(entry),
125
+ },
126
+ ).then(response => {
125
127
  if (response.ok) {
126
128
  return response.json();
127
129
  }
@@ -1,7 +1,6 @@
1
1
  import { Registry } from './registry.js';
2
2
 
3
3
  export class GeoNames extends Registry {
4
-
5
4
  constructor(configElem) {
6
5
  super(configElem);
7
6
  this.user = configElem.getAttribute('user');
@@ -26,7 +25,7 @@ export class GeoNames extends Registry {
26
25
  details: `${item.fcodeName} - ${item.adminName1}, ${item.countryName}`,
27
26
  link: `https://www.geonames.org/${item.geonameId}`,
28
27
  strings: [item.toponymName],
29
- provider: 'geonames.org'
28
+ provider: 'geonames.org',
30
29
  };
31
30
  results.push(result);
32
31
  });
@@ -43,24 +42,25 @@ export class GeoNames extends Registry {
43
42
  return Promise.resolve({});
44
43
  }
45
44
  return new Promise((resolve, reject) => {
46
- this.getRecord(key).then(json => {
47
- if (json.status) {
48
- reject(json.status.message);
49
- return;
50
- }
51
- const output = `
45
+ this.getRecord(key)
46
+ .then(json => {
47
+ if (json.status) {
48
+ reject(json.status.message);
49
+ return;
50
+ }
51
+ const output = `
52
52
  <h3 class="label">
53
53
  <a href="${json.link}" target="_blank">${json.name}</a>
54
54
  </h3>
55
55
  <p class="fcode">${json.note} - ${json.region}, ${json.country}</p>
56
56
  `;
57
- container.innerHTML = output;
58
- resolve({
59
- id: this._prefix ? `${this._prefix}-${json.geonameId}` : json.geonameId,
60
- strings: [json.name],
61
- });
62
- })
63
- .catch(() => reject());
57
+ container.innerHTML = output;
58
+ resolve({
59
+ id: this._prefix ? `${this._prefix}-${json.geonameId}` : json.geonameId,
60
+ strings: [json.name],
61
+ });
62
+ })
63
+ .catch(() => reject());
64
64
  });
65
65
  }
66
66
 
@@ -73,22 +73,28 @@ export class GeoNames extends Registry {
73
73
  async getRecord(key) {
74
74
  const id = this._prefix ? key.substring(this._prefix.length + 1) : key;
75
75
  return fetch(
76
- `https://secure.geonames.org/getJSON?geonameId=${encodeURIComponent(id)}&username=${this.user}`,
77
- ).then(response => {
78
- if (response.ok) {
79
- return response.json();
80
- }
81
- return Promise.reject(response.status);
82
- })
83
- .then((json) => {
84
- const output = Object.assign({}, json);
85
- output.name = json.toponymName;
86
- output.country = json.countryName;
87
- output.region = json.adminName1;
88
- output.note = json.fcodeName;
89
- output.links = [`https://www.geonames.org/${json.geonameId}`, `https://${json.wikipediaURL}`];
90
- return output;
91
- })
92
- .catch(() => Promise.reject());
76
+ `https://secure.geonames.org/getJSON?geonameId=${encodeURIComponent(id)}&username=${
77
+ this.user
78
+ }`,
79
+ )
80
+ .then(response => {
81
+ if (response.ok) {
82
+ return response.json();
83
+ }
84
+ return Promise.reject(response.status);
85
+ })
86
+ .then(json => {
87
+ const output = { ...json };
88
+ output.name = json.toponymName;
89
+ output.country = json.countryName;
90
+ output.region = json.adminName1;
91
+ output.note = json.fcodeName;
92
+ output.links = [
93
+ `https://www.geonames.org/${json.geonameId}`,
94
+ `https://${json.wikipediaURL}`,
95
+ ];
96
+ return output;
97
+ })
98
+ .catch(() => Promise.reject());
93
99
  }
94
100
  }