@teipublisher/pb-components 2.26.0-next-3.12 → 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.
- package/.github/workflows/main.yml +3 -3
- package/.github/workflows/node.js.yml +3 -3
- package/.github/workflows/release.js.yml +3 -3
- package/CHANGELOG.md +30 -0
- package/Dockerfile +78 -70
- package/css/components.css +5 -5
- package/dist/demo/pb-drawer2.html +1 -1
- package/dist/demo/pb-leaflet-map.html +1 -1
- package/dist/demo/pb-progress.html +2 -2
- package/dist/demo/pb-repeat.html +1 -3
- package/dist/demo/pb-view3.html +1 -1
- package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +58 -54
- package/dist/pb-components-bundle.js +1937 -1782
- package/dist/pb-edit-app.js +167 -107
- package/dist/pb-elements.json +45 -45
- package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
- package/dist/pb-leaflet-map.js +23 -23
- package/dist/pb-mei.js +56 -41
- package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
- package/dist/pb-odd-editor.js +923 -756
- package/dist/pb-tify.js +2 -2
- package/dist/{vaadin-element-mixin-49ab4037.js → vaadin-element-mixin-84fb7d82.js} +178 -163
- package/gh-pages.js +5 -3
- package/i18n/common/pl.json +2 -2
- package/lib/openseadragon.min.js +1 -1
- package/package.json +2 -2
- package/pb-elements.json +45 -45
- package/src/assets/components.css +5 -5
- package/src/authority/airtable.js +20 -21
- package/src/authority/anton.js +129 -129
- package/src/authority/custom.js +23 -21
- package/src/authority/geonames.js +38 -32
- package/src/authority/gnd.js +47 -42
- package/src/authority/kbga.js +137 -134
- package/src/authority/metagrid.js +44 -46
- package/src/authority/reconciliation.js +66 -67
- package/src/authority/registry.js +4 -4
- package/src/docs/pb-component-docs.js +2 -2
- package/src/docs/pb-component-view.js +5 -5
- package/src/docs/pb-components-list.js +2 -2
- package/src/docs/pb-demo-snippet.js +2 -2
- package/src/dts-client.js +299 -297
- package/src/dts-select-endpoint.js +90 -82
- package/src/parse-date-service.js +184 -135
- package/src/pb-ajax.js +150 -146
- package/src/pb-authority-lookup.js +183 -146
- package/src/pb-autocomplete.js +292 -280
- package/src/pb-blacklab-highlight.js +264 -259
- package/src/pb-blacklab-results.js +236 -221
- package/src/pb-browse-docs.js +540 -475
- package/src/pb-browse.js +68 -65
- package/src/pb-clipboard.js +79 -76
- package/src/pb-code-editor.js +110 -102
- package/src/pb-code-highlight.js +209 -204
- package/src/pb-codepen.js +79 -72
- package/src/pb-collapse.js +212 -207
- package/src/pb-combo-box.js +190 -190
- package/src/pb-components-bundle.js +1 -1
- package/src/pb-custom-form.js +151 -149
- package/src/pb-dialog.js +94 -85
- package/src/pb-document.js +89 -90
- package/src/pb-download.js +210 -198
- package/src/pb-drawer.js +145 -148
- package/src/pb-edit-app.js +301 -229
- package/src/pb-edit-xml.js +98 -96
- package/src/pb-events.js +114 -107
- package/src/pb-facs-link.js +104 -102
- package/src/pb-facsimile.js +411 -413
- package/src/pb-formula.js +151 -153
- package/src/pb-geolocation.js +129 -131
- package/src/pb-grid-action.js +53 -56
- package/src/pb-grid.js +231 -228
- package/src/pb-highlight.js +140 -140
- package/src/pb-hotkeys.js +40 -42
- package/src/pb-i18n.js +101 -104
- package/src/pb-image-strip.js +84 -78
- package/src/pb-lang.js +132 -128
- package/src/pb-leaflet-map.js +488 -485
- package/src/pb-link.js +126 -124
- package/src/pb-load.js +431 -426
- package/src/pb-login.js +291 -248
- package/src/pb-manage-odds.js +364 -318
- package/src/pb-map-icon.js +89 -89
- package/src/pb-map-layer.js +85 -85
- package/src/pb-markdown.js +90 -99
- package/src/pb-media-query.js +74 -72
- package/src/pb-mei.js +306 -295
- package/src/pb-message.js +144 -144
- package/src/pb-mixin.js +269 -264
- package/src/pb-navigation.js +80 -82
- package/src/pb-observable.js +38 -38
- package/src/pb-odd-editor.js +1053 -955
- package/src/pb-odd-elementspec-editor.js +348 -297
- package/src/pb-odd-model-editor.js +1061 -901
- package/src/pb-odd-parameter-editor.js +200 -178
- package/src/pb-odd-rendition-editor.js +136 -124
- package/src/pb-page.js +431 -421
- package/src/pb-paginate.js +202 -190
- package/src/pb-panel.js +191 -179
- package/src/pb-popover-themes.js +7 -5
- package/src/pb-popover.js +296 -287
- package/src/pb-print-preview.js +127 -127
- package/src/pb-progress.js +51 -51
- package/src/pb-repeat.js +105 -104
- package/src/pb-restricted.js +84 -77
- package/src/pb-search.js +252 -241
- package/src/pb-select-feature.js +127 -120
- package/src/pb-select-odd.js +132 -124
- package/src/pb-select-template.js +89 -78
- package/src/pb-select.js +251 -227
- package/src/pb-split-list.js +179 -174
- package/src/pb-svg.js +80 -79
- package/src/pb-table-column.js +54 -54
- package/src/pb-table-grid.js +221 -203
- package/src/pb-tabs.js +61 -63
- package/src/pb-tify.js +154 -154
- package/src/pb-timeline.js +271 -229
- package/src/pb-toggle-feature.js +182 -175
- package/src/pb-upload.js +184 -174
- package/src/pb-version.js +30 -30
- package/src/pb-view-annotate.js +132 -98
- package/src/pb-view.js +1289 -1270
- package/src/pb-zoom.js +75 -59
- package/src/polymer-hack.js +1 -1
- package/src/search-result-service.js +256 -223
- package/src/seed-element.js +13 -20
- package/src/settings.js +4 -4
- package/src/theming.js +96 -96
- package/src/urls.js +289 -289
- 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
|
|
4
|
-
import { typesetMath } from
|
|
5
|
-
import { registry } from
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
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
|
-
|
|
301
|
+
let params = {};
|
|
298
302
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
const doc = this.getDocument();
|
|
314
|
+
if (!this.plain) {
|
|
315
|
+
if (doc) {
|
|
316
|
+
params.doc = doc.path;
|
|
317
|
+
}
|
|
314
318
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
324
|
+
if (this.language) {
|
|
325
|
+
params.language = this.language;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
params = this.prepareParameters(params);
|
|
325
329
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
337
|
+
const url = this.getURL(params);
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
345
|
+
if (this.loadOnce) {
|
|
346
|
+
this.loaded = true;
|
|
342
347
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
441
|
-
|
|
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
|
-
|
|
435
|
+
if (this.start !== start) {
|
|
436
|
+
this.start = parseInt(start);
|
|
457
437
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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);
|