@teipublisher/pb-components 2.26.0-next-3.11 → 2.26.0-next-3.13

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 (133) 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 +38 -0
  5. package/Dockerfile +78 -70
  6. package/css/components.css +5 -5
  7. package/dist/demo/components.css +2 -8
  8. package/dist/demo/pb-drawer2.html +1 -1
  9. package/dist/demo/pb-leaflet-map.html +1 -1
  10. package/dist/demo/pb-progress.html +2 -2
  11. package/dist/demo/pb-repeat.html +1 -3
  12. package/dist/demo/pb-view3.html +1 -1
  13. package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
  14. package/dist/pb-code-editor.js +25 -20
  15. package/dist/pb-component-docs.js +58 -54
  16. package/dist/pb-components-bundle.js +1937 -1782
  17. package/dist/pb-edit-app.js +167 -107
  18. package/dist/pb-elements.json +45 -45
  19. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  20. package/dist/pb-leaflet-map.js +23 -23
  21. package/dist/pb-mei.js +56 -41
  22. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  23. package/dist/pb-odd-editor.js +923 -756
  24. package/dist/pb-tify.js +2 -2
  25. package/dist/{vaadin-element-mixin-6633322b.js → vaadin-element-mixin-84fb7d82.js} +181 -143
  26. package/gh-pages.js +5 -3
  27. package/i18n/common/pl.json +2 -2
  28. package/lib/openseadragon.min.js +1 -1
  29. package/package.json +2 -2
  30. package/pb-elements.json +45 -45
  31. package/src/assets/components.css +5 -5
  32. package/src/authority/airtable.js +20 -21
  33. package/src/authority/anton.js +129 -129
  34. package/src/authority/custom.js +23 -21
  35. package/src/authority/geonames.js +38 -32
  36. package/src/authority/gnd.js +47 -42
  37. package/src/authority/kbga.js +137 -134
  38. package/src/authority/metagrid.js +44 -46
  39. package/src/authority/reconciliation.js +66 -67
  40. package/src/authority/registry.js +4 -4
  41. package/src/docs/pb-component-docs.js +2 -2
  42. package/src/docs/pb-component-view.js +5 -5
  43. package/src/docs/pb-components-list.js +2 -2
  44. package/src/docs/pb-demo-snippet.js +2 -2
  45. package/src/dts-client.js +299 -297
  46. package/src/dts-select-endpoint.js +90 -82
  47. package/src/parse-date-service.js +184 -135
  48. package/src/pb-ajax.js +150 -146
  49. package/src/pb-authority-lookup.js +183 -146
  50. package/src/pb-autocomplete.js +292 -280
  51. package/src/pb-blacklab-highlight.js +264 -259
  52. package/src/pb-blacklab-results.js +236 -221
  53. package/src/pb-browse-docs.js +540 -475
  54. package/src/pb-browse.js +68 -65
  55. package/src/pb-clipboard.js +79 -76
  56. package/src/pb-code-editor.js +110 -102
  57. package/src/pb-code-highlight.js +209 -204
  58. package/src/pb-codepen.js +79 -72
  59. package/src/pb-collapse.js +212 -207
  60. package/src/pb-combo-box.js +190 -190
  61. package/src/pb-components-bundle.js +1 -1
  62. package/src/pb-custom-form.js +151 -149
  63. package/src/pb-dialog.js +96 -60
  64. package/src/pb-document.js +89 -90
  65. package/src/pb-download.js +210 -198
  66. package/src/pb-drawer.js +145 -148
  67. package/src/pb-edit-app.js +301 -229
  68. package/src/pb-edit-xml.js +98 -96
  69. package/src/pb-events.js +114 -107
  70. package/src/pb-facs-link.js +104 -102
  71. package/src/pb-facsimile.js +411 -413
  72. package/src/pb-formula.js +151 -153
  73. package/src/pb-geolocation.js +129 -131
  74. package/src/pb-grid-action.js +53 -56
  75. package/src/pb-grid.js +231 -228
  76. package/src/pb-highlight.js +140 -140
  77. package/src/pb-hotkeys.js +40 -42
  78. package/src/pb-i18n.js +101 -104
  79. package/src/pb-image-strip.js +84 -78
  80. package/src/pb-lang.js +132 -128
  81. package/src/pb-leaflet-map.js +488 -485
  82. package/src/pb-link.js +126 -124
  83. package/src/pb-load.js +431 -426
  84. package/src/pb-login.js +291 -248
  85. package/src/pb-manage-odds.js +364 -318
  86. package/src/pb-map-icon.js +89 -89
  87. package/src/pb-map-layer.js +85 -85
  88. package/src/pb-markdown.js +90 -99
  89. package/src/pb-media-query.js +74 -72
  90. package/src/pb-mei.js +306 -295
  91. package/src/pb-message.js +144 -144
  92. package/src/pb-mixin.js +269 -264
  93. package/src/pb-navigation.js +80 -82
  94. package/src/pb-observable.js +38 -38
  95. package/src/pb-odd-editor.js +1053 -955
  96. package/src/pb-odd-elementspec-editor.js +348 -297
  97. package/src/pb-odd-model-editor.js +1061 -901
  98. package/src/pb-odd-parameter-editor.js +200 -178
  99. package/src/pb-odd-rendition-editor.js +136 -124
  100. package/src/pb-page.js +431 -421
  101. package/src/pb-paginate.js +202 -190
  102. package/src/pb-panel.js +191 -179
  103. package/src/pb-popover-themes.js +7 -5
  104. package/src/pb-popover.js +296 -287
  105. package/src/pb-print-preview.js +127 -127
  106. package/src/pb-progress.js +51 -51
  107. package/src/pb-repeat.js +105 -104
  108. package/src/pb-restricted.js +84 -77
  109. package/src/pb-search.js +252 -241
  110. package/src/pb-select-feature.js +127 -120
  111. package/src/pb-select-odd.js +132 -124
  112. package/src/pb-select-template.js +89 -78
  113. package/src/pb-select.js +251 -227
  114. package/src/pb-split-list.js +179 -174
  115. package/src/pb-svg.js +80 -79
  116. package/src/pb-table-column.js +54 -54
  117. package/src/pb-table-grid.js +221 -203
  118. package/src/pb-tabs.js +61 -63
  119. package/src/pb-tify.js +154 -154
  120. package/src/pb-timeline.js +271 -229
  121. package/src/pb-toggle-feature.js +182 -175
  122. package/src/pb-upload.js +184 -174
  123. package/src/pb-version.js +30 -30
  124. package/src/pb-view-annotate.js +132 -98
  125. package/src/pb-view.js +1289 -1270
  126. package/src/pb-zoom.js +75 -59
  127. package/src/polymer-hack.js +1 -1
  128. package/src/search-result-service.js +256 -223
  129. package/src/seed-element.js +13 -20
  130. package/src/settings.js +4 -4
  131. package/src/theming.js +96 -96
  132. package/src/urls.js +289 -289
  133. package/src/utils.js +53 -51
package/src/pb-load.js CHANGED
@@ -1,8 +1,8 @@
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
7
  import '@polymer/paper-dialog';
8
8
  import '@polymer/paper-dialog-scrollable';
@@ -11,7 +11,7 @@ import '@polymer/paper-dialog-scrollable';
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
@@ -19,462 +19,467 @@ import '@polymer/paper-dialog-scrollable';
19
19
  * @fires pb-toggle - When received, changes the state of the feature
20
20
  */
21
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
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;
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;
227
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
+ <paper-dialog id="errorDialog">
246
+ <h2>${translate('dialogs.error')}</h2>
247
+ <paper-dialog-scrollable></paper-dialog-scrollable>
248
+ <div class="buttons">
249
+ <paper-button dialog-confirm="dialog-confirm" autofocus="autofocus">
250
+ ${translate('dialogs.close')}
251
+ </paper-button>
252
+ </div>
253
+ </paper-dialog>
254
+ `;
255
+ }
256
+
257
+ static get styles() {
258
+ return css`
259
+ :host {
260
+ display: block;
261
+ }
262
+ `;
263
+ }
264
+
265
+ toggleFeature(ev) {
266
+ this.userParams = registry.getState(this);
267
+ console.log('<pb-load> toggle feature %o', this.userParams);
268
+ if (ev.detail.refresh) {
269
+ if (this.history) {
270
+ registry.commit(this, this.userParams);
271
+ }
272
+ this.load();
259
273
  }
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();
274
+ }
275
+
276
+ getURL(params) {
277
+ let { url } = this;
278
+ if (this.expand) {
279
+ url = url.replace(/{([^})]+)}/g, (match, key) => {
280
+ if (!params[key]) {
281
+ return '';
269
282
  }
283
+ const param = encodeURIComponent(params[key] || key);
284
+ delete params[key];
285
+ return param;
286
+ });
270
287
  }
288
+ return this.toAbsoluteURL(url);
289
+ }
271
290
 
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);
291
+ load(ev) {
292
+ if (!this.url) {
293
+ return;
294
+ }
295
+ if (this.loadOnce && this.loaded) {
296
+ return;
285
297
  }
286
298
 
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');
299
+ this.emitTo('pb-start-update');
296
300
 
297
- let params = {};
301
+ let params = {};
298
302
 
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
- }
303
+ if (ev) {
304
+ if (ev instanceof Event) {
305
+ if (ev.detail && ev.detail.params) {
306
+ params = ev.detail.params;
307
307
  }
308
+ } else {
309
+ params = ev;
310
+ }
311
+ }
308
312
 
309
- const doc = this.getDocument();
310
- if (!this.plain) {
311
- if (doc) {
312
- params.doc = doc.path;
313
- }
313
+ const doc = this.getDocument();
314
+ if (!this.plain) {
315
+ if (doc) {
316
+ params.doc = doc.path;
317
+ }
314
318
 
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
- }
319
+ // set start parameter to start property, but only if not provided otherwise already
320
+ if (this.start && !params.start) {
321
+ params.start = this.start;
322
+ }
319
323
 
320
- if (this.language) {
321
- params.language = this.language;
322
- }
323
- }
324
- params = this.prepareParameters(params);
324
+ if (this.language) {
325
+ params.language = this.language;
326
+ }
327
+ }
328
+ params = this.prepareParameters(params);
325
329
 
326
- // filter null values
327
- for (const [k,v] of Object.entries(params)) {
328
- if (v === null) { delete params[k] }
329
- }
330
+ // filter null values
331
+ for (const [k, v] of Object.entries(params)) {
332
+ if (v === null) {
333
+ delete params[k];
334
+ }
335
+ }
330
336
 
331
- const url = this.getURL(params);
337
+ const url = this.getURL(params);
332
338
 
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();
339
+ console.log('<pb-load> Loading %s with parameters %o', url, params);
340
+ const loader = this.shadowRoot.getElementById('loadContent');
341
+ loader.params = params;
342
+ loader.url = url;
343
+ loader.generateRequest();
338
344
 
339
- if (this.loadOnce) {
340
- this.loaded = true;
341
- }
345
+ if (this.loadOnce) {
346
+ this.loaded = true;
342
347
  }
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;
348
+ }
349
+
350
+ /**
351
+ * Allow subclasses to set parameters before the request is being sent.
352
+ *
353
+ * @param params Map of parameters
354
+ * @return new or modified parameters map
355
+ */
356
+ prepareParameters(params) {
357
+ if (this.userParams) {
358
+ return Object.assign(params, this.userParams);
359
+ }
360
+ return params;
361
+ }
362
+
363
+ _handleContent(ev) {
364
+ const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
365
+ if (this.container) {
366
+ this.style.display = 'none';
367
+ document.querySelectorAll(this.container).forEach(elem => {
368
+ elem.innerHTML = resp;
369
+ this._parseHeaders(ev.detail.xhr, elem);
370
+ this._fixLinks(elem);
371
+ this._onLoad(elem);
372
+ });
373
+ } else {
374
+ this.style.display = '';
375
+ this._clearContent();
376
+
377
+ const div = document.createElement('div');
378
+ div.innerHTML = resp;
379
+ this._parseHeaders(ev.detail.xhr, div);
380
+ div.slot = '';
381
+ this.appendChild(div);
382
+ this._fixLinks(div);
383
+
384
+ this._onLoad(div);
355
385
  }
356
386
 
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
- }
387
+ this.emitTo('pb-end-update');
388
+ }
380
389
 
381
- this.emitTo('pb-end-update');
390
+ _clearContent() {
391
+ const contentSlot = this.shadowRoot.querySelector('slot:not([name])');
392
+ if (contentSlot) {
393
+ // clear content from slot
394
+ contentSlot.assignedNodes().forEach(node => node.parentNode.removeChild(node));
382
395
  }
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
- }
396
+ }
397
+
398
+ _handleError() {
399
+ this.emitTo('pb-end-update');
400
+ const loader = this.shadowRoot.getElementById('loadContent');
401
+ const { response } = loader.lastError;
402
+ if (this.silent) {
403
+ console.error('Request failed: %s', response ? response.description : '');
404
+ return;
390
405
  }
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();
406
+ let message;
407
+ if (response) {
408
+ message = response.description;
409
+ } else {
410
+ message = '<pb-i18n key="dialogs.serverError"></pb-i18n>';
410
411
  }
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
- });
412
+ const dialog = this.shadowRoot.getElementById('errorDialog');
413
+ const body = dialog.querySelector('paper-dialog-scrollable');
414
+ body.innerHTML = `<p><pb-i18n key="dialogs.serverError"></pb-i18n>: ${message} </p>`;
415
+ dialog.open();
416
+ }
417
+
418
+ _parseHeaders(xhr, content) {
419
+ // Try to determine number of pages and current position
420
+ // Search for data-pagination-* attributes first and if they
421
+ // can't be found, check HTTP headers
422
+ //
423
+ // However, if noCredentials is set, we won't be able to access the headers
424
+ function getPaginationParam(type, noHeaders) {
425
+ const elem = content.querySelector(`[data-pagination-${type}]`);
426
+ if (elem) {
427
+ return elem.getAttribute(`data-pagination-${type}`);
428
+ }
429
+ return noHeaders ? 0 : xhr.getResponseHeader(`pb-${type}`);
438
430
  }
439
431
 
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
- }
432
+ const total = getPaginationParam('total', this.noCredentials);
433
+ const start = getPaginationParam('start', this.noCredentials);
455
434
 
456
- _onLoad(content) {
435
+ if (this.start !== start) {
436
+ this.start = parseInt(start);
457
437
  }
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
- */
438
+ this.emitTo('pb-results-received', {
439
+ count: total ? parseInt(total, 10) : 0,
440
+ start: this.start,
441
+ content,
442
+ params: this.shadowRoot.getElementById('loadContent').params,
443
+ });
444
+ }
445
+
446
+ _fixLinks(content) {
447
+ typesetMath(content);
448
+ if (this.fixLinks) {
449
+ content.querySelectorAll('img').forEach(image => {
450
+ const oldSrc = image.getAttribute('src');
451
+ const src = new URL(oldSrc, `${this.getEndpoint()}/`);
452
+ image.src = src;
453
+ });
454
+ content.querySelectorAll('a').forEach(link => {
455
+ const oldHref = link.getAttribute('href');
456
+ const href = new URL(oldHref, `${this.getEndpoint()}/`);
457
+ link.href = href;
458
+ });
459
+ }
460
+ }
461
+
462
+ _onLoad(content) {}
463
+
464
+ /**
465
+ * Fired before the element updates its content
466
+ *
467
+ * @event pb-start-update
468
+ * @param {object} Parameters to be passed to the request
469
+ */
470
+
471
+ /**
472
+ * Fired after the element has finished updating its content
473
+ *
474
+ * @event pb-end-update
475
+ */
476
+
477
+ /**
478
+ * Fired after the element has received content from the server
479
+ *
480
+ * @event pb-results-received
481
+ * @param {int} count number of results received (according to `pb-total` header)
482
+ * @param {int} start offset into the result set (according to `pb-start` header)
483
+ */
479
484
  }
480
- customElements.define('pb-load', PbLoad);
485
+ customElements.define('pb-load', PbLoad);