@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.
- package/.github/workflows/main.yml +3 -3
- package/.github/workflows/node.js.yml +3 -3
- package/.github/workflows/release.js.yml +4 -4
- package/.releaserc.json +2 -2
- package/CHANGELOG.md +267 -9
- package/Dockerfile +78 -70
- package/css/components.css +5 -5
- package/css/leaflet/images/layers.png +0 -0
- package/dist/demo/components.css +46 -1
- package/dist/demo/pb-browse-docs2.html +1 -1
- package/dist/demo/pb-dialog.html +3 -5
- package/dist/demo/pb-drawer2.html +1 -1
- package/dist/demo/pb-facsimile.html +2 -2
- package/dist/demo/pb-grid.html +19 -6
- package/dist/demo/pb-leaflet-map.html +1 -1
- package/dist/demo/pb-login.html +0 -2
- package/dist/demo/pb-message.html +1 -2
- package/dist/demo/pb-progress.html +2 -2
- package/dist/demo/pb-repeat.html +1 -3
- package/dist/demo/pb-search.html +7 -4
- package/dist/demo/pb-search3.html +1 -1
- package/dist/demo/pb-search4.html +2 -2
- package/dist/demo/pb-view3.html +1 -1
- package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
- package/dist/paper-checkbox-645e1077.js +200 -0
- package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
- package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
- package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +68 -64
- package/dist/pb-components-bundle.js +1983 -2293
- package/dist/pb-edit-app.js +167 -107
- package/dist/pb-elements.json +176 -120
- 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 +1023 -782
- package/dist/pb-tify.js +2 -2
- package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
- package/gh-pages.js +5 -3
- package/i18n/common/en.json +6 -0
- package/i18n/common/pl.json +2 -2
- package/lib/openseadragon.min.js +6 -6
- package/package.json +3 -3
- package/pb-elements.json +176 -120
- 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 +50 -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 +158 -171
- package/src/pb-authority-lookup.js +191 -156
- 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 +211 -151
- package/src/pb-combo-box.js +190 -190
- package/src/pb-components-bundle.js +1 -1
- package/src/pb-components.js +1 -0
- package/src/pb-custom-form.js +173 -153
- package/src/pb-dialog.js +98 -62
- package/src/pb-document.js +89 -90
- package/src/pb-download.js +212 -196
- package/src/pb-drawer.js +145 -148
- package/src/pb-edit-app.js +301 -229
- package/src/pb-edit-xml.js +100 -97
- package/src/pb-events.js +114 -107
- package/src/pb-facs-link.js +104 -102
- package/src/pb-facsimile.js +474 -410
- 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 +142 -57
- package/src/pb-leaflet-map.js +488 -485
- package/src/pb-link.js +126 -124
- package/src/pb-load.js +431 -429
- package/src/pb-login.js +299 -244
- package/src/pb-manage-odds.js +352 -336
- 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 +139 -97
- package/src/pb-mixin.js +269 -264
- package/src/pb-navigation.js +80 -95
- package/src/pb-observable.js +38 -38
- package/src/pb-odd-editor.js +1054 -958
- package/src/pb-odd-elementspec-editor.js +349 -298
- package/src/pb-odd-model-editor.js +1075 -909
- package/src/pb-odd-parameter-editor.js +200 -178
- package/src/pb-odd-rendition-editor.js +136 -124
- package/src/pb-page.js +431 -422
- package/src/pb-paginate.js +228 -179
- package/src/pb-panel.js +198 -182
- package/src/pb-popover-themes.js +15 -8
- 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 +256 -228
- 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 +382 -249
- package/src/pb-toggle-feature.js +195 -187
- package/src/pb-upload.js +184 -174
- package/src/pb-version.js +30 -30
- package/src/pb-view-annotate.js +135 -98
- package/src/pb-view.js +1282 -1270
- package/src/pb-zoom.js +127 -45
- 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 +98 -91
- package/src/urls.js +289 -289
- package/src/utils.js +53 -51
- package/css/pb-styles.css +0 -51
- package/dist/vaadin-element-mixin-6e4cee3a.js +0 -527
- package/src/assets/pb-styles.css +0 -51
- 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
|
|
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
|
-
import '
|
|
8
|
-
import '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
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
|
-
|
|
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
|
+
<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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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);
|
|
288
|
+
load(ev) {
|
|
289
|
+
if (!this.url) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (this.loadOnce && this.loaded) {
|
|
293
|
+
return;
|
|
285
294
|
}
|
|
286
295
|
|
|
287
|
-
|
|
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
|
-
|
|
298
|
+
let params = {};
|
|
298
299
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
310
|
+
const doc = this.getDocument();
|
|
311
|
+
if (!this.plain) {
|
|
312
|
+
if (doc) {
|
|
313
|
+
params.doc = doc.path;
|
|
314
|
+
}
|
|
314
315
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
321
|
+
if (this.language) {
|
|
322
|
+
params.language = this.language;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
params = this.prepareParameters(params);
|
|
325
326
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
334
|
+
const url = this.getURL(params);
|
|
332
335
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
+
if (this.loadOnce) {
|
|
343
|
+
this.loaded = true;
|
|
342
344
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
384
|
+
this.emitTo('pb-end-update');
|
|
385
|
+
}
|
|
380
386
|
|
|
381
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
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();
|
|
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
|
-
|
|
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
|
-
});
|
|
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
|
-
|
|
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
|
-
}
|
|
429
|
+
const total = getPaginationParam('total', this.noCredentials);
|
|
430
|
+
const start = getPaginationParam('start', this.noCredentials);
|
|
455
431
|
|
|
456
|
-
|
|
432
|
+
if (this.start !== start) {
|
|
433
|
+
this.start = parseInt(start);
|
|
457
434
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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);
|