@teipublisher/pb-components 2.26.1-next.2 → 3.0.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.
Files changed (154) 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 +4 -4
  4. package/.releaserc.json +2 -2
  5. package/CHANGELOG.md +267 -9
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/css/leaflet/images/layers.png +0 -0
  9. package/dist/demo/components.css +46 -1
  10. package/dist/demo/pb-browse-docs2.html +1 -1
  11. package/dist/demo/pb-dialog.html +3 -5
  12. package/dist/demo/pb-drawer2.html +1 -1
  13. package/dist/demo/pb-facsimile.html +2 -2
  14. package/dist/demo/pb-grid.html +19 -6
  15. package/dist/demo/pb-leaflet-map.html +1 -1
  16. package/dist/demo/pb-login.html +0 -2
  17. package/dist/demo/pb-message.html +1 -2
  18. package/dist/demo/pb-progress.html +2 -2
  19. package/dist/demo/pb-repeat.html +1 -3
  20. package/dist/demo/pb-search.html +7 -4
  21. package/dist/demo/pb-search3.html +1 -1
  22. package/dist/demo/pb-search4.html +2 -2
  23. package/dist/demo/pb-view3.html +1 -1
  24. package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
  25. package/dist/paper-checkbox-645e1077.js +200 -0
  26. package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
  27. package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
  28. package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
  29. package/dist/pb-code-editor.js +25 -20
  30. package/dist/pb-component-docs.js +68 -64
  31. package/dist/pb-components-bundle.js +1983 -2293
  32. package/dist/pb-edit-app.js +167 -107
  33. package/dist/pb-elements.json +176 -120
  34. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  35. package/dist/pb-leaflet-map.js +23 -23
  36. package/dist/pb-mei.js +56 -41
  37. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  38. package/dist/pb-odd-editor.js +1023 -782
  39. package/dist/pb-tify.js +2 -2
  40. package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
  41. package/gh-pages.js +5 -3
  42. package/i18n/common/en.json +6 -0
  43. package/i18n/common/pl.json +2 -2
  44. package/lib/openseadragon.min.js +6 -6
  45. package/package.json +3 -3
  46. package/pb-elements.json +176 -120
  47. package/src/assets/components.css +5 -5
  48. package/src/authority/airtable.js +20 -21
  49. package/src/authority/anton.js +129 -129
  50. package/src/authority/custom.js +23 -21
  51. package/src/authority/geonames.js +38 -32
  52. package/src/authority/gnd.js +50 -42
  53. package/src/authority/kbga.js +137 -134
  54. package/src/authority/metagrid.js +44 -46
  55. package/src/authority/reconciliation.js +66 -67
  56. package/src/authority/registry.js +4 -4
  57. package/src/docs/pb-component-docs.js +2 -2
  58. package/src/docs/pb-component-view.js +5 -5
  59. package/src/docs/pb-components-list.js +2 -2
  60. package/src/docs/pb-demo-snippet.js +2 -2
  61. package/src/dts-client.js +299 -297
  62. package/src/dts-select-endpoint.js +90 -82
  63. package/src/parse-date-service.js +184 -135
  64. package/src/pb-ajax.js +158 -171
  65. package/src/pb-authority-lookup.js +191 -156
  66. package/src/pb-autocomplete.js +292 -280
  67. package/src/pb-blacklab-highlight.js +264 -259
  68. package/src/pb-blacklab-results.js +236 -221
  69. package/src/pb-browse-docs.js +540 -475
  70. package/src/pb-browse.js +68 -65
  71. package/src/pb-clipboard.js +79 -76
  72. package/src/pb-code-editor.js +110 -102
  73. package/src/pb-code-highlight.js +209 -204
  74. package/src/pb-codepen.js +79 -72
  75. package/src/pb-collapse.js +211 -151
  76. package/src/pb-combo-box.js +190 -190
  77. package/src/pb-components-bundle.js +1 -1
  78. package/src/pb-components.js +1 -0
  79. package/src/pb-custom-form.js +173 -153
  80. package/src/pb-dialog.js +98 -62
  81. package/src/pb-document.js +89 -90
  82. package/src/pb-download.js +212 -196
  83. package/src/pb-drawer.js +145 -148
  84. package/src/pb-edit-app.js +301 -229
  85. package/src/pb-edit-xml.js +100 -97
  86. package/src/pb-events.js +114 -107
  87. package/src/pb-facs-link.js +104 -102
  88. package/src/pb-facsimile.js +474 -410
  89. package/src/pb-formula.js +151 -153
  90. package/src/pb-geolocation.js +129 -131
  91. package/src/pb-grid-action.js +53 -56
  92. package/src/pb-grid.js +231 -228
  93. package/src/pb-highlight.js +140 -140
  94. package/src/pb-hotkeys.js +40 -42
  95. package/src/pb-i18n.js +101 -104
  96. package/src/pb-image-strip.js +84 -78
  97. package/src/pb-lang.js +142 -57
  98. package/src/pb-leaflet-map.js +488 -485
  99. package/src/pb-link.js +126 -124
  100. package/src/pb-load.js +431 -429
  101. package/src/pb-login.js +299 -244
  102. package/src/pb-manage-odds.js +352 -336
  103. package/src/pb-map-icon.js +89 -89
  104. package/src/pb-map-layer.js +85 -85
  105. package/src/pb-markdown.js +90 -99
  106. package/src/pb-media-query.js +74 -72
  107. package/src/pb-mei.js +306 -295
  108. package/src/pb-message.js +139 -97
  109. package/src/pb-mixin.js +269 -264
  110. package/src/pb-navigation.js +80 -95
  111. package/src/pb-observable.js +38 -38
  112. package/src/pb-odd-editor.js +1054 -958
  113. package/src/pb-odd-elementspec-editor.js +349 -298
  114. package/src/pb-odd-model-editor.js +1075 -909
  115. package/src/pb-odd-parameter-editor.js +200 -178
  116. package/src/pb-odd-rendition-editor.js +136 -124
  117. package/src/pb-page.js +431 -422
  118. package/src/pb-paginate.js +228 -179
  119. package/src/pb-panel.js +198 -182
  120. package/src/pb-popover-themes.js +15 -8
  121. package/src/pb-popover.js +296 -287
  122. package/src/pb-print-preview.js +127 -127
  123. package/src/pb-progress.js +51 -51
  124. package/src/pb-repeat.js +105 -104
  125. package/src/pb-restricted.js +84 -77
  126. package/src/pb-search.js +256 -228
  127. package/src/pb-select-feature.js +127 -120
  128. package/src/pb-select-odd.js +132 -124
  129. package/src/pb-select-template.js +89 -78
  130. package/src/pb-select.js +251 -227
  131. package/src/pb-split-list.js +179 -174
  132. package/src/pb-svg.js +80 -79
  133. package/src/pb-table-column.js +54 -54
  134. package/src/pb-table-grid.js +221 -203
  135. package/src/pb-tabs.js +61 -63
  136. package/src/pb-tify.js +154 -154
  137. package/src/pb-timeline.js +382 -249
  138. package/src/pb-toggle-feature.js +195 -187
  139. package/src/pb-upload.js +184 -174
  140. package/src/pb-version.js +30 -30
  141. package/src/pb-view-annotate.js +135 -98
  142. package/src/pb-view.js +1282 -1270
  143. package/src/pb-zoom.js +127 -45
  144. package/src/polymer-hack.js +1 -1
  145. package/src/search-result-service.js +256 -223
  146. package/src/seed-element.js +13 -20
  147. package/src/settings.js +4 -4
  148. package/src/theming.js +98 -91
  149. package/src/urls.js +289 -289
  150. package/src/utils.js +53 -51
  151. package/css/pb-styles.css +0 -51
  152. package/dist/vaadin-element-mixin-6e4cee3a.js +0 -527
  153. package/src/assets/pb-styles.css +0 -51
  154. package/src/pb-light-dom.js +0 -40
package/src/pb-load.js CHANGED
@@ -1,480 +1,482 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import { pbMixin, waitOnce } from './pb-mixin.js';
3
- import { translate } from "./pb-i18n.js";
4
- import { typesetMath } from "./pb-formula.js";
5
- import { registry } from "./urls.js";
3
+ import { translate } from './pb-i18n.js';
4
+ import { typesetMath } from './pb-formula.js';
5
+ import { registry } from './urls.js';
6
6
  import '@polymer/iron-ajax';
7
- import '@polymer/paper-dialog';
8
- import '@polymer/paper-dialog-scrollable';
7
+ import './pb-dialog.js';
8
+ import { themableMixin } from './theming.js';
9
9
 
10
10
  /**
11
11
  * Dynamically load data by calling a server-side script, optionally triggered by an event.
12
12
  * This is used for e.g. the document list on the start page or the table
13
13
  * of contents.
14
- *
14
+ *
15
15
  * @slot - default unnamed slot for content
16
16
  * @fires pb-start-update - Fired before the element updates its content
17
17
  * @fires pb-end-update - Fired after the element has finished updating its content
18
18
  * @fires pb-results-received - Fired when the component received content from the server
19
19
  * @fires pb-toggle - When received, changes the state of the feature
20
20
  */
21
- export class PbLoad extends pbMixin(LitElement) {
22
-
23
- static get properties() {
24
- return {
25
- ...super.properties,
26
- /** The URL for the AJAX request. If a relative URL is passed, it will be resolved
27
- * against the current API endpoint.
28
- */
29
- url: {
30
- type: String
31
- },
32
- /**
33
- * If set to true, the `url` property will be interpreted as a template string
34
- * containing placeholders for parameters in `{parameter-name}`. The placeholders
35
- * will be replaced by the actual parameters when building the final URL. Each parameter
36
- * used in the URL template will be removed from the request parameter list.
37
- */
38
- expand: {
39
- type: Boolean
40
- },
41
- /** ID of the pb-document this element is connected to. The document path to
42
- * load will be taken from the pb-document.
43
- */
44
- src: {
45
- type: String
46
- },
47
- /**
48
- * The container element into which the results returned by
49
- * the AJAX request will be loaded.
50
- */
51
- container: {
52
- type: String
53
- },
54
- /**
55
- * Should content be loaded immediately when the component is initialized?
56
- */
57
- auto: {
58
- type: Boolean
59
- },
60
- /**
61
- * Only load content once, not every time a `pb-load` event is received.
62
- */
63
- loadOnce: {
64
- type: Boolean
65
- },
66
- /**
67
- * If set, relative links (img, a) will be made absolute.
68
- */
69
- fixLinks: {
70
- type: Boolean,
71
- attribute: 'fix-links'
72
- },
73
- /**
74
- * Start offset to use for showing paginated content.
75
- */
76
- start: {
77
- type: Number
78
- },
79
- /**
80
- * If set, a parameter "language" will be added to the parameter list.
81
- * Also, a refresh will be triggered if a `pb-i18n-update` event is received,
82
- * e.g. due to the user selecting a different interface language.
83
- *
84
- * Also requires `requireLanguage` to be set on the surrounding `pb-page`.
85
- * See there for more information.
86
- */
87
- useLanguage: {
88
- type: Boolean,
89
- attribute: 'use-language'
90
- },
91
- /**
92
- * Indicates whether or not cross-site Access-Control requests should be made.
93
- * Default is false.
94
- */
95
- noCredentials: {
96
- type: Boolean,
97
- attribute: 'no-credentials'
98
- },
99
- /**
100
- * Indicates if the parameters of the request made should be saved to the browser
101
- * history and URL. Default: false.
102
- */
103
- history: {
104
- type: Boolean
105
- },
106
- /**
107
- * The event which will trigger a new request to be sent. Default is 'pb-load'.
108
- */
109
- event: {
110
- type: String
111
- },
112
- /**
113
- * Additional, user-defined parameters to be sent with the request.
114
- */
115
- userParams: {
116
- type: Object
117
- },
118
- /**
119
- * If set, silently ignore errors when sending the request.
120
- */
121
- silent: {
122
- type: Boolean
123
- },
124
- /**
125
- * Do not add internal parameters like 'start' or 'language' to the URL
126
- * but leave it untouched.
127
- */
128
- plain: {
129
- type: Boolean
21
+ export class PbLoad extends themableMixin(pbMixin(LitElement)) {
22
+ static get properties() {
23
+ return {
24
+ ...super.properties,
25
+ /** The URL for the AJAX request. If a relative URL is passed, it will be resolved
26
+ * against the current API endpoint.
27
+ */
28
+ url: {
29
+ type: String,
30
+ },
31
+ /**
32
+ * If set to true, the `url` property will be interpreted as a template string
33
+ * containing placeholders for parameters in `{parameter-name}`. The placeholders
34
+ * will be replaced by the actual parameters when building the final URL. Each parameter
35
+ * used in the URL template will be removed from the request parameter list.
36
+ */
37
+ expand: {
38
+ type: Boolean,
39
+ },
40
+ /** ID of the pb-document this element is connected to. The document path to
41
+ * load will be taken from the pb-document.
42
+ */
43
+ src: {
44
+ type: String,
45
+ },
46
+ /**
47
+ * The container element into which the results returned by
48
+ * the AJAX request will be loaded.
49
+ */
50
+ container: {
51
+ type: String,
52
+ },
53
+ /**
54
+ * Should content be loaded immediately when the component is initialized?
55
+ */
56
+ auto: {
57
+ type: Boolean,
58
+ },
59
+ /**
60
+ * Only load content once, not every time a `pb-load` event is received.
61
+ */
62
+ loadOnce: {
63
+ type: Boolean,
64
+ },
65
+ /**
66
+ * If set, relative links (img, a) will be made absolute.
67
+ */
68
+ fixLinks: {
69
+ type: Boolean,
70
+ attribute: 'fix-links',
71
+ },
72
+ /**
73
+ * Start offset to use for showing paginated content.
74
+ */
75
+ start: {
76
+ type: Number,
77
+ },
78
+ /**
79
+ * If set, a parameter "language" will be added to the parameter list.
80
+ * Also, a refresh will be triggered if a `pb-i18n-update` event is received,
81
+ * e.g. due to the user selecting a different interface language.
82
+ *
83
+ * Also requires `requireLanguage` to be set on the surrounding `pb-page`.
84
+ * See there for more information.
85
+ */
86
+ useLanguage: {
87
+ type: Boolean,
88
+ attribute: 'use-language',
89
+ },
90
+ /**
91
+ * Indicates whether or not cross-site Access-Control requests should be made.
92
+ * Default is false.
93
+ */
94
+ noCredentials: {
95
+ type: Boolean,
96
+ attribute: 'no-credentials',
97
+ },
98
+ /**
99
+ * Indicates if the parameters of the request made should be saved to the browser
100
+ * history and URL. Default: false.
101
+ */
102
+ history: {
103
+ type: Boolean,
104
+ },
105
+ /**
106
+ * The event which will trigger a new request to be sent. Default is 'pb-load'.
107
+ */
108
+ event: {
109
+ type: String,
110
+ },
111
+ /**
112
+ * Additional, user-defined parameters to be sent with the request.
113
+ */
114
+ userParams: {
115
+ type: Object,
116
+ },
117
+ /**
118
+ * If set, silently ignore errors when sending the request.
119
+ */
120
+ silent: {
121
+ type: Boolean,
122
+ },
123
+ /**
124
+ * Do not add internal parameters like 'start' or 'language' to the URL
125
+ * but leave it untouched.
126
+ */
127
+ plain: {
128
+ type: Boolean,
129
+ },
130
+ };
131
+ }
132
+
133
+ constructor() {
134
+ super();
135
+ this.auto = false;
136
+ this.loadOnce = false;
137
+ this.history = false;
138
+ this.event = 'pb-load';
139
+ this.loaded = false;
140
+ this.language = null;
141
+ this.noCredentials = false;
142
+ this.silent = false;
143
+ }
144
+
145
+ connectedCallback() {
146
+ super.connectedCallback();
147
+ this.subscribeTo(this.event, ev => {
148
+ waitOnce('pb-page-ready', () => {
149
+ if (this.history) {
150
+ if (ev.detail && ev.detail.params) {
151
+ const { start } = ev.detail.params;
152
+ if (start) {
153
+ registry.commit(this, { start });
130
154
  }
131
- };
132
- }
133
-
134
- constructor() {
135
- super();
136
- this.auto = false;
137
- this.loadOnce = false;
138
- this.history = false;
139
- this.event = 'pb-load';
140
- this.loaded = false;
141
- this.language = null;
142
- this.noCredentials = false;
143
- this.silent = false;
144
- }
145
-
146
- connectedCallback() {
147
- super.connectedCallback();
148
- this.subscribeTo(this.event, (ev) => {
149
- waitOnce('pb-page-ready', () => {
150
- if (this.history) {
151
- if (ev.detail && ev.detail.params) {
152
- const start = ev.detail.params.start;
153
- if (start) {
154
- registry.commit(this, { start });
155
- }
156
- }
157
- this.userParams = registry.state;
158
- registry.subscribe(this, (state) => {
159
- if (state.start) {
160
- this.start = state.start;
161
- this.load();
162
- }
163
- });
164
- registry.replace(this, this.userParams);
165
- }
166
- this.load(ev);
167
- });
168
- });
169
-
170
- this.subscribeTo('pb-toggle', ev => {
171
- this.toggleFeature(ev);
172
- });
173
-
174
- this.subscribeTo('pb-i18n-update', ev => {
175
- const needsRefresh = this.language && this.language !== ev.detail.language;
176
- this.language = ev.detail.language;
177
- if (this.useLanguage && needsRefresh) {
178
- this.load();
155
+ }
156
+ this.userParams = registry.state;
157
+ registry.subscribe(this, state => {
158
+ if (state.start) {
159
+ this.start = state.start;
160
+ this.load();
179
161
  }
180
- }, []);
181
-
182
- if (this.history) {
183
- registry.subscribe(this, (state) => {
184
- this.start = state.start;
185
- this.userParams = state;
186
- this.load();
187
- });
162
+ });
163
+ registry.replace(this, this.userParams);
188
164
  }
189
-
190
- this.signalReady();
191
- }
192
-
193
- firstUpdated() {
194
- if (this.auto) {
195
- this.start = registry.state.start || 1;
196
- waitOnce('pb-page-ready', (data) => {
197
- if (data && data.language) {
198
- this.language = data.language;
199
- }
200
- this.wait(() => this.load());
201
- });
202
- } else {
203
- waitOnce('pb-page-ready', (data) => {
204
- if (data && data.language) {
205
- this.language = data.language;
206
- }
207
- });
165
+ this.load(ev);
166
+ });
167
+ });
168
+
169
+ this.subscribeTo('pb-toggle', ev => {
170
+ this.toggleFeature(ev);
171
+ });
172
+
173
+ this.subscribeTo(
174
+ 'pb-i18n-update',
175
+ ev => {
176
+ const needsRefresh = this.language && this.language !== ev.detail.language;
177
+ this.language = ev.detail.language;
178
+ if (this.useLanguage && needsRefresh) {
179
+ this.load();
208
180
  }
181
+ },
182
+ [],
183
+ );
184
+
185
+ if (this.history) {
186
+ registry.subscribe(this, state => {
187
+ this.start = state.start;
188
+ this.userParams = state;
189
+ this.load();
190
+ });
209
191
  }
210
192
 
211
- attributeChangedCallback(name, oldValue, newValue) {
212
- super.attributeChangedCallback(name, oldValue, newValue);
213
- if (oldValue && oldValue !== newValue) {
214
- switch (name) {
215
- case 'url':
216
- case 'userParams':
217
- case 'start':
218
- if (this.auto && this.loader) {
219
- waitOnce('pb-page-ready', () => {
220
- this.wait(() => this.load());
221
- });
222
- }
223
- break;
224
- default:
225
- break;
226
- }
193
+ this.signalReady();
194
+ }
195
+
196
+ firstUpdated() {
197
+ if (this.auto) {
198
+ this.start = registry.state.start || 1;
199
+ waitOnce('pb-page-ready', data => {
200
+ if (data && data.language) {
201
+ this.language = data.language;
227
202
  }
203
+ this.wait(() => this.load());
204
+ });
205
+ } else {
206
+ waitOnce('pb-page-ready', data => {
207
+ if (data && data.language) {
208
+ this.language = data.language;
209
+ }
210
+ });
228
211
  }
229
-
230
- render() {
231
- return html`
232
- <slot></slot>
233
- <iron-ajax
234
- id="loadContent"
235
- verbose
236
- handle-as="text"
237
- method="get"
238
- ?with-credentials="${!this.noCredentials}"
239
- @response="${this._handleContent}"
240
- @error="${this._handleError}"></iron-ajax>
241
- <paper-dialog id="errorDialog">
242
- <h2>${translate('dialogs.error')}</h2>
243
- <paper-dialog-scrollable></paper-dialog-scrollable>
244
- <div class="buttons">
245
- <paper-button dialog-confirm="dialog-confirm" autofocus="autofocus">
246
- ${translate('dialogs.close')}
247
- </paper-button>
248
- </div>
249
- </paper-dialog>
250
- `;
212
+ }
213
+
214
+ attributeChangedCallback(name, oldValue, newValue) {
215
+ super.attributeChangedCallback(name, oldValue, newValue);
216
+ if (oldValue && oldValue !== newValue) {
217
+ switch (name) {
218
+ case 'url':
219
+ case 'userParams':
220
+ case 'start':
221
+ if (this.auto && this.loader) {
222
+ waitOnce('pb-page-ready', () => {
223
+ this.wait(() => this.load());
224
+ });
225
+ }
226
+ break;
227
+ default:
228
+ break;
229
+ }
251
230
  }
252
-
253
- static get styles() {
254
- return css`
255
- :host {
256
- display: block;
257
- }
258
- `;
231
+ }
232
+
233
+ render() {
234
+ return html`
235
+ <slot></slot>
236
+ <iron-ajax
237
+ id="loadContent"
238
+ verbose
239
+ handle-as="text"
240
+ method="get"
241
+ ?with-credentials="${!this.noCredentials}"
242
+ @response="${this._handleContent}"
243
+ @error="${this._handleError}"
244
+ ></iron-ajax>
245
+ <pb-dialog id="errorDialog" title="${translate('dialogs.error')}">
246
+ <p id="errorMessage"></p>
247
+ <div slot="footer">
248
+ <button rel="prev">${translate('dialogs.close')}</button>
249
+ </div>
250
+ </pb-dialog>
251
+ `;
252
+ }
253
+
254
+ static get styles() {
255
+ return css`
256
+ :host {
257
+ display: block;
258
+ }
259
+ `;
260
+ }
261
+
262
+ toggleFeature(ev) {
263
+ this.userParams = registry.getState(this);
264
+ console.log('<pb-load> toggle feature %o', this.userParams);
265
+ if (ev.detail.refresh) {
266
+ if (this.history) {
267
+ registry.commit(this, this.userParams);
268
+ }
269
+ this.load();
259
270
  }
260
-
261
- toggleFeature(ev) {
262
- this.userParams = registry.getState(this);
263
- console.log('<pb-load> toggle feature %o', this.userParams);
264
- if (ev.detail.refresh) {
265
- if (this.history) {
266
- registry.commit(this, this.userParams);
267
- }
268
- this.load();
271
+ }
272
+
273
+ getURL(params) {
274
+ let { url } = this;
275
+ if (this.expand) {
276
+ url = url.replace(/{([^})]+)}/g, (match, key) => {
277
+ if (!params[key]) {
278
+ return '';
269
279
  }
280
+ const param = encodeURIComponent(params[key] || key);
281
+ delete params[key];
282
+ return param;
283
+ });
270
284
  }
285
+ return this.toAbsoluteURL(url);
286
+ }
271
287
 
272
- getURL(params) {
273
- let url = this.url;
274
- if (this.expand) {
275
- url = url.replace(/{([^})]+)}/g, (match, key) => {
276
- if (!params[key]) {
277
- return '';
278
- }
279
- const param = encodeURIComponent(params[key] || key);
280
- delete params[key];
281
- return param;
282
- });
283
- }
284
- return this.toAbsoluteURL(url);
288
+ load(ev) {
289
+ if (!this.url) {
290
+ return;
291
+ }
292
+ if (this.loadOnce && this.loaded) {
293
+ return;
285
294
  }
286
295
 
287
- load(ev) {
288
- if (!this.url) {
289
- return;
290
- }
291
- if (this.loadOnce && this.loaded) {
292
- return;
293
- }
294
-
295
- this.emitTo('pb-start-update');
296
+ this.emitTo('pb-start-update');
296
297
 
297
- let params = {};
298
+ let params = {};
298
299
 
299
- if (ev) {
300
- if (ev instanceof Event) {
301
- if (ev.detail && ev.detail.params) {
302
- params = ev.detail.params;
303
- }
304
- } else {
305
- params = ev;
306
- }
300
+ if (ev) {
301
+ if (ev instanceof Event) {
302
+ if (ev.detail && ev.detail.params) {
303
+ params = ev.detail.params;
307
304
  }
305
+ } else {
306
+ params = ev;
307
+ }
308
+ }
308
309
 
309
- const doc = this.getDocument();
310
- if (!this.plain) {
311
- if (doc) {
312
- params.doc = doc.path;
313
- }
310
+ const doc = this.getDocument();
311
+ if (!this.plain) {
312
+ if (doc) {
313
+ params.doc = doc.path;
314
+ }
314
315
 
315
- // set start parameter to start property, but only if not provided otherwise already
316
- if (this.start && !params.start) {
317
- params.start = this.start;
318
- }
316
+ // set start parameter to start property, but only if not provided otherwise already
317
+ if (this.start && !params.start) {
318
+ params.start = this.start;
319
+ }
319
320
 
320
- if (this.language) {
321
- params.language = this.language;
322
- }
323
- }
324
- params = this.prepareParameters(params);
321
+ if (this.language) {
322
+ params.language = this.language;
323
+ }
324
+ }
325
+ params = this.prepareParameters(params);
325
326
 
326
- // filter null values
327
- for (const [k,v] of Object.entries(params)) {
328
- if (v === null) { delete params[k] }
329
- }
327
+ // filter null values
328
+ for (const [k, v] of Object.entries(params)) {
329
+ if (v === null) {
330
+ delete params[k];
331
+ }
332
+ }
330
333
 
331
- const url = this.getURL(params);
334
+ const url = this.getURL(params);
332
335
 
333
- console.log("<pb-load> Loading %s with parameters %o", url, params);
334
- const loader = this.shadowRoot.getElementById('loadContent');
335
- loader.params = params;
336
- loader.url = url;
337
- loader.generateRequest();
336
+ console.log('<pb-load> Loading %s with parameters %o', url, params);
337
+ const loader = this.shadowRoot.getElementById('loadContent');
338
+ loader.params = params;
339
+ loader.url = url;
340
+ loader.generateRequest();
338
341
 
339
- if (this.loadOnce) {
340
- this.loaded = true;
341
- }
342
+ if (this.loadOnce) {
343
+ this.loaded = true;
342
344
  }
343
-
344
- /**
345
- * Allow subclasses to set parameters before the request is being sent.
346
- *
347
- * @param params Map of parameters
348
- * @return new or modified parameters map
349
- */
350
- prepareParameters(params) {
351
- if (this.userParams) {
352
- return Object.assign(params, this.userParams);
353
- }
354
- return params;
345
+ }
346
+
347
+ /**
348
+ * Allow subclasses to set parameters before the request is being sent.
349
+ *
350
+ * @param params Map of parameters
351
+ * @return new or modified parameters map
352
+ */
353
+ prepareParameters(params) {
354
+ if (this.userParams) {
355
+ return Object.assign(params, this.userParams);
356
+ }
357
+ return params;
358
+ }
359
+
360
+ _handleContent(ev) {
361
+ const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
362
+ if (this.container) {
363
+ this.style.display = 'none';
364
+ document.querySelectorAll(this.container).forEach(elem => {
365
+ elem.innerHTML = resp;
366
+ this._parseHeaders(ev.detail.xhr, elem);
367
+ this._fixLinks(elem);
368
+ this._onLoad(elem);
369
+ });
370
+ } else {
371
+ this.style.display = '';
372
+ this._clearContent();
373
+
374
+ const div = document.createElement('div');
375
+ div.innerHTML = resp;
376
+ this._parseHeaders(ev.detail.xhr, div);
377
+ div.slot = '';
378
+ this.appendChild(div);
379
+ this._fixLinks(div);
380
+
381
+ this._onLoad(div);
355
382
  }
356
383
 
357
- _handleContent(ev) {
358
- const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
359
- if (this.container) {
360
- this.style.display = 'none';
361
- document.querySelectorAll(this.container).forEach((elem) => {
362
- elem.innerHTML = resp;
363
- this._parseHeaders(ev.detail.xhr, elem);
364
- this._fixLinks(elem);
365
- this._onLoad(elem);
366
- });
367
- } else {
368
- this.style.display = '';
369
- this._clearContent();
370
-
371
- const div = document.createElement('div');
372
- div.innerHTML = resp;
373
- this._parseHeaders(ev.detail.xhr, div);
374
- div.slot = '';
375
- this.appendChild(div);
376
- this._fixLinks(div);
377
-
378
- this._onLoad(div);
379
- }
384
+ this.emitTo('pb-end-update');
385
+ }
380
386
 
381
- this.emitTo('pb-end-update');
387
+ _clearContent() {
388
+ const contentSlot = this.shadowRoot.querySelector('slot:not([name])');
389
+ if (contentSlot) {
390
+ // clear content from slot
391
+ contentSlot.assignedNodes().forEach(node => node.parentNode.removeChild(node));
382
392
  }
383
-
384
- _clearContent() {
385
- const contentSlot = this.shadowRoot.querySelector('slot:not([name])');
386
- if (contentSlot) {
387
- // clear content from slot
388
- contentSlot.assignedNodes().forEach((node) => node.parentNode.removeChild(node));
389
- }
393
+ }
394
+
395
+ _handleError() {
396
+ this.emitTo('pb-end-update');
397
+ const loader = this.shadowRoot.getElementById('loadContent');
398
+ const { response } = loader.lastError;
399
+ if (this.silent) {
400
+ console.error('Request failed: %s', response ? response.description : '');
401
+ return;
390
402
  }
391
-
392
- _handleError() {
393
- this.emitTo('pb-end-update');
394
- const loader = this.shadowRoot.getElementById('loadContent');
395
- const { response } = loader.lastError;
396
- if (this.silent) {
397
- console.error('Request failed: %s', response ? response.description : '');
398
- return;
399
- }
400
- let message;
401
- if (response) {
402
- message = response.description;
403
- } else {
404
- message = '<pb-i18n key="dialogs.serverError"></pb-i18n>';
405
- }
406
- const dialog = this.shadowRoot.getElementById('errorDialog');
407
- const body = dialog.querySelector("paper-dialog-scrollable");
408
- body.innerHTML = `<p><pb-i18n key="dialogs.serverError"></pb-i18n>: ${message} </p>`;
409
- dialog.open();
403
+ let message;
404
+ if (response) {
405
+ message = response.description;
406
+ } else {
407
+ message = '<pb-i18n key="dialogs.serverError"></pb-i18n>';
410
408
  }
411
-
412
- _parseHeaders(xhr, content) {
413
- // Try to determine number of pages and current position
414
- // Search for data-pagination-* attributes first and if they
415
- // can't be found, check HTTP headers
416
- //
417
- // However, if noCredentials is set, we won't be able to access the headers
418
- function getPaginationParam(type, noHeaders) {
419
- const elem = content.querySelector(`[data-pagination-${type}]`);
420
- if (elem) {
421
- return elem.getAttribute(`data-pagination-${type}`);
422
- }
423
- return noHeaders ? 0 : xhr.getResponseHeader(`pb-${type}`);
424
- }
425
-
426
- const total = getPaginationParam('total', this.noCredentials);
427
- const start = getPaginationParam('start', this.noCredentials);
428
-
429
- if (this.start !== start) {
430
- this.start = parseInt(start);
431
- }
432
- this.emitTo('pb-results-received', {
433
- "count": total ? parseInt(total, 10) : 0,
434
- "start": this.start,
435
- "content": content,
436
- "params": this.shadowRoot.getElementById('loadContent').params
437
- });
409
+ const dialog = this.shadowRoot.getElementById('errorDialog');
410
+ const messageElement = this.shadowRoot.getElementById('errorMessage');
411
+ messageElement.innerHTML = `<pb-i18n key="dialogs.serverError"></pb-i18n>: ${message}`;
412
+ dialog.openDialog();
413
+ }
414
+
415
+ _parseHeaders(xhr, content) {
416
+ // Try to determine number of pages and current position
417
+ // Search for data-pagination-* attributes first and if they
418
+ // can't be found, check HTTP headers
419
+ //
420
+ // However, if noCredentials is set, we won't be able to access the headers
421
+ function getPaginationParam(type, noHeaders) {
422
+ const elem = content.querySelector(`[data-pagination-${type}]`);
423
+ if (elem) {
424
+ return elem.getAttribute(`data-pagination-${type}`);
425
+ }
426
+ return noHeaders ? 0 : xhr.getResponseHeader(`pb-${type}`);
438
427
  }
439
428
 
440
- _fixLinks(content) {
441
- typesetMath(content);
442
- if (this.fixLinks) {
443
- content.querySelectorAll('img').forEach((image) => {
444
- const oldSrc = image.getAttribute('src');
445
- const src = new URL(oldSrc, `${this.getEndpoint()}/`);
446
- image.src = src;
447
- });
448
- content.querySelectorAll('a').forEach((link) => {
449
- const oldHref = link.getAttribute('href');
450
- const href = new URL(oldHref, `${this.getEndpoint()}/`);
451
- link.href = href;
452
- });
453
- }
454
- }
429
+ const total = getPaginationParam('total', this.noCredentials);
430
+ const start = getPaginationParam('start', this.noCredentials);
455
431
 
456
- _onLoad(content) {
432
+ if (this.start !== start) {
433
+ this.start = parseInt(start);
457
434
  }
458
-
459
- /**
460
- * Fired before the element updates its content
461
- *
462
- * @event pb-start-update
463
- * @param {object} Parameters to be passed to the request
464
- */
465
-
466
- /**
467
- * Fired after the element has finished updating its content
468
- *
469
- * @event pb-end-update
470
- */
471
-
472
- /**
473
- * Fired after the element has received content from the server
474
- *
475
- * @event pb-results-received
476
- * @param {int} count number of results received (according to `pb-total` header)
477
- * @param {int} start offset into the result set (according to `pb-start` header)
478
- */
435
+ this.emitTo('pb-results-received', {
436
+ count: total ? parseInt(total, 10) : 0,
437
+ start: this.start,
438
+ content,
439
+ params: this.shadowRoot.getElementById('loadContent').params,
440
+ });
441
+ }
442
+
443
+ _fixLinks(content) {
444
+ typesetMath(content);
445
+ if (this.fixLinks) {
446
+ content.querySelectorAll('img').forEach(image => {
447
+ const oldSrc = image.getAttribute('src');
448
+ const src = new URL(oldSrc, `${this.getEndpoint()}/`);
449
+ image.src = src;
450
+ });
451
+ content.querySelectorAll('a').forEach(link => {
452
+ const oldHref = link.getAttribute('href');
453
+ const href = new URL(oldHref, `${this.getEndpoint()}/`);
454
+ link.href = href;
455
+ });
456
+ }
457
+ }
458
+
459
+ _onLoad(content) {}
460
+
461
+ /**
462
+ * Fired before the element updates its content
463
+ *
464
+ * @event pb-start-update
465
+ * @param {object} Parameters to be passed to the request
466
+ */
467
+
468
+ /**
469
+ * Fired after the element has finished updating its content
470
+ *
471
+ * @event pb-end-update
472
+ */
473
+
474
+ /**
475
+ * Fired after the element has received content from the server
476
+ *
477
+ * @event pb-results-received
478
+ * @param {int} count number of results received (according to `pb-total` header)
479
+ * @param {int} start offset into the result set (according to `pb-start` header)
480
+ */
479
481
  }
480
- customElements.define('pb-load', PbLoad);
482
+ customElements.define('pb-load', PbLoad);