@teipublisher/pb-components 1.43.5 → 1.44.1
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 +22 -0
- package/CHANGELOG.md +14 -0
- package/dist/demo/pb-facsimile.html +1 -1
- package/dist/demo/pb-table-grid.html +16 -16
- package/dist/demo/pb-view2.html +135 -135
- package/dist/demo/redirect.html +4 -0
- package/dist/pb-code-editor.js +1 -1
- package/dist/pb-components-bundle.js +95 -104
- package/dist/pb-edit-app.js +1 -1
- package/dist/pb-elements.json +1026 -691
- package/dist/{pb-i18n-dc551878.js → pb-i18n-3963b098.js} +1 -1
- package/dist/pb-leaflet-map.js +1 -1
- package/dist/pb-odd-editor.js +1 -1
- package/dist/{pb-message-fbc1b645.js → vaadin-element-mixin-08cf11b5.js} +21 -19
- package/gh-pages.js +27 -0
- package/i18n/common/en.json +7 -2
- package/package.json +5 -3
- package/pb-elements.json +1026 -691
- package/src/pb-ajax.js +37 -19
- package/src/pb-browse-docs.js +520 -520
- package/src/pb-browse.js +77 -0
- package/src/pb-components.js +1 -0
- package/src/pb-facsimile.js +10 -2
- package/src/pb-message.js +6 -10
- package/src/pb-mixin.js +542 -542
- package/src/pb-page.js +399 -399
- package/src/pb-split-list.js +226 -188
- package/src/pb-table-grid.js +218 -218
- package/src/pb-timeline.js +31 -1
- package/src/pb-view.js +1366 -1366
- /package/dist/{pb-mixin-f8b22e51.js → pb-mixin-88125cb2.js} +0 -0
package/src/pb-split-list.js
CHANGED
|
@@ -1,189 +1,227 @@
|
|
|
1
|
-
import { LitElement, html, css } from 'lit-element';
|
|
2
|
-
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
|
|
3
|
-
import { pbMixin } from './pb-mixin.js';
|
|
4
|
-
import { themableMixin } from "./theming.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Implements a list which is split into different categories
|
|
8
|
-
* (e.g. letters of the alphabet, countries ...).
|
|
9
|
-
* Only one category is shown at a time unless the server reports
|
|
10
|
-
* no categories (e.g. if the number of items to display goes below
|
|
11
|
-
* a defined threshold).
|
|
12
|
-
*
|
|
13
|
-
* The server-side API endpoint should return a JSON object with two
|
|
14
|
-
* properties:
|
|
15
|
-
*
|
|
16
|
-
* + `categories`: an array of category descriptions: each item should
|
|
17
|
-
* be an object with two properties: `category` - containing the name of the category
|
|
18
|
-
* and `count` - containing a count of items available under this category.
|
|
19
|
-
* + `items`: an array with the items to be shown for the currently selected
|
|
20
|
-
* category. Those may contain HTML markup.
|
|
21
|
-
*
|
|
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
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
1
|
+
import { LitElement, html, css } from 'lit-element';
|
|
2
|
+
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
|
|
3
|
+
import { pbMixin } from './pb-mixin.js';
|
|
4
|
+
import { themableMixin } from "./theming.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Implements a list which is split into different categories
|
|
8
|
+
* (e.g. letters of the alphabet, countries ...).
|
|
9
|
+
* Only one category is shown at a time unless the server reports
|
|
10
|
+
* no categories (e.g. if the number of items to display goes below
|
|
11
|
+
* a defined threshold).
|
|
12
|
+
*
|
|
13
|
+
* The server-side API endpoint should return a JSON object with two
|
|
14
|
+
* properties:
|
|
15
|
+
*
|
|
16
|
+
* + `categories`: an array of category descriptions: each item should
|
|
17
|
+
* be an object with two properties: `category` - containing the name of the category
|
|
18
|
+
* and `count` - containing a count of items available under this category.
|
|
19
|
+
* + `items`: an array with the items to be shown for the currently selected
|
|
20
|
+
* category. Those may contain HTML markup.
|
|
21
|
+
*
|
|
22
|
+
* Sample JSON object for pb-split-list
|
|
23
|
+
* ```javascript
|
|
24
|
+
* {
|
|
25
|
+
* "items": [
|
|
26
|
+
* "<span><a href='Abegg-Arter Carl?category=A&view=correspondents&search='>Abegg-Arter, Carl</a><span class='dates'> (1836–1912)</span></span>",
|
|
27
|
+
* "<span><a href='Abegg Hans Heinrich?category=A&view=correspondents&search='>Abegg, Hans Heinrich</a><span class='dates'> (1805–1874)</span></span>",
|
|
28
|
+
* "<span><a href='Abegg Jakob?category=A&view=correspondents&search='>Abegg, Jakob</a><span class='dates'> (1801–1871)</span></span>",
|
|
29
|
+
* "<span><a href='Abys Raget?category=A&view=correspondents&search='>Abys, Raget</a><span class='dates'> (1790–1861)</span></span>",
|
|
30
|
+
* "<span><a href='Aebli Johann Peter?category=A&view=correspondents&search='>Aebli, Johann Peter</a><span class='dates'> (1804–1879)</span></span>",
|
|
31
|
+
* "<span><a href='Aepli Arnold Otto?category=A&view=correspondents&search='>Aepli, Arnold Otto</a><span class='dates'> (1816–1897)</span></span>",
|
|
32
|
+
* ...
|
|
33
|
+
* ],
|
|
34
|
+
* "categories": [
|
|
35
|
+
* {
|
|
36
|
+
* "category": "A",
|
|
37
|
+
* "count": 22
|
|
38
|
+
* },
|
|
39
|
+
* {
|
|
40
|
+
* "category": "B",
|
|
41
|
+
* "count": 77
|
|
42
|
+
* },
|
|
43
|
+
* {
|
|
44
|
+
* "category": "C",
|
|
45
|
+
* "count": 19
|
|
46
|
+
* },
|
|
47
|
+
* ...
|
|
48
|
+
* ]
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Sample Usage
|
|
53
|
+
* ```xml
|
|
54
|
+
* <pb-split-list url="api/people" subforms="#options" selected="A" emit="transcription" subscribe="transcription"></pb-split-list>
|
|
55
|
+
* ```
|
|
56
|
+
* See https://www.briefedition.alfred-escher.ch/kontexte/personen/?category=A&search=&view=correspondents for a running sample. The source code of the webpage is here: https://github.com/stazh/briefedition-escher. Relevant files are:
|
|
57
|
+
* - [templates/index.html](https://github.com/stazh/briefedition-escher/blob/master/templates/index.html#L223) - usage of pb-timeline
|
|
58
|
+
* - [modules/custom-api.json](https://github.com/stazh/briefedition-escher/blob/master/modules/custom-api.json#L1098) - `/api/people` endpoint delivering required JSON object
|
|
59
|
+
*
|
|
60
|
+
* @cssprop --pb-categorized-list-columns - the number of columns to display (default: 2)
|
|
61
|
+
* @fires pb-submit - when received, submit a request to the server and refresh
|
|
62
|
+
* @fires pb-start-update - sent before the element sends the request to the server
|
|
63
|
+
* @fires pb-end-update - sent after new content has been received
|
|
64
|
+
*/
|
|
65
|
+
export class PbSplitList extends themableMixin(pbMixin(LitElement)) {
|
|
66
|
+
static get properties() {
|
|
67
|
+
return {
|
|
68
|
+
/**
|
|
69
|
+
* Server-side API endpoint to retrieve items from
|
|
70
|
+
*/
|
|
71
|
+
url: {
|
|
72
|
+
type: String
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* The initially selected category
|
|
76
|
+
*/
|
|
77
|
+
selected: {
|
|
78
|
+
type: String
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* A CSS selector pointing to one or more `pb-custom-form`
|
|
82
|
+
* instances. The element will collect additional parameters
|
|
83
|
+
* from those forms and includes them in the request to the server
|
|
84
|
+
*/
|
|
85
|
+
subforms: {
|
|
86
|
+
type: String
|
|
87
|
+
},
|
|
88
|
+
_categories: {
|
|
89
|
+
type: Array
|
|
90
|
+
},
|
|
91
|
+
...super.properties
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
constructor() {
|
|
96
|
+
super();
|
|
97
|
+
this._categories = [];
|
|
98
|
+
this._params = {};
|
|
99
|
+
this.selected = null;
|
|
100
|
+
this.subforms = null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
connectedCallback() {
|
|
104
|
+
super.connectedCallback();
|
|
105
|
+
|
|
106
|
+
this.selected = this.getParameter('category', this.selected);
|
|
107
|
+
|
|
108
|
+
window.addEventListener('popstate', (ev) => {
|
|
109
|
+
console.log('<pb-split-list> popstate: %o', ev);
|
|
110
|
+
this.selected = ev.state.category;
|
|
111
|
+
this.submit();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
this.subscribeTo('pb-submit', this.load.bind(this));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
firstUpdated() {
|
|
118
|
+
super.firstUpdated();
|
|
119
|
+
|
|
120
|
+
PbSplitList.waitOnce('pb-page-ready', () => {
|
|
121
|
+
this.load();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
submit() {
|
|
126
|
+
this.load();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
load() {
|
|
130
|
+
const formParams = this._paramsFromSubforms({ category: this.selected });
|
|
131
|
+
this.setParameters(formParams);
|
|
132
|
+
this.pushHistory('pb-split-list', formParams);
|
|
133
|
+
|
|
134
|
+
const params = new URLSearchParams(formParams);
|
|
135
|
+
|
|
136
|
+
const url = `${this.toAbsoluteURL(this.url)}?${params.toString()}`;
|
|
137
|
+
console.log(`<pb-split-list> Fetching from URL: ${url}`);
|
|
138
|
+
|
|
139
|
+
this.emitTo('pb-start-update');
|
|
140
|
+
|
|
141
|
+
fetch(url)
|
|
142
|
+
.then((response) => {
|
|
143
|
+
if (response.ok) {
|
|
144
|
+
return response.json();
|
|
145
|
+
}
|
|
146
|
+
return Promise.reject(response.status);
|
|
147
|
+
})
|
|
148
|
+
.then((json) => {
|
|
149
|
+
this._categories = json.categories;
|
|
150
|
+
this.innerHTML = json.items.join('');
|
|
151
|
+
this.emitTo('pb-end-update');
|
|
152
|
+
})
|
|
153
|
+
.catch((error) => {
|
|
154
|
+
console.error(`<pb-split-list> Error caught: ${error}`);
|
|
155
|
+
this.emitTo('pb-end-update');
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_selectCategory(ev, category) {
|
|
160
|
+
ev.preventDefault();
|
|
161
|
+
this.selected = category;
|
|
162
|
+
this.load();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_paramsFromSubforms(params) {
|
|
166
|
+
if (this.subforms) {
|
|
167
|
+
document.querySelectorAll(this.subforms).forEach((form) => {
|
|
168
|
+
if (form.serializeForm) {
|
|
169
|
+
Object.assign(params, form.serializeForm());
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return params;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
render() {
|
|
177
|
+
return html`
|
|
178
|
+
<header>
|
|
179
|
+
${
|
|
180
|
+
this._categories.map((cat) =>
|
|
181
|
+
html`
|
|
182
|
+
<a part="${this.selected === cat.category ? 'active-category' : 'category'}" href="#${cat.category}" title="${cat.count}" class="${this.selected === cat.category ? 'active' : ''}"
|
|
183
|
+
@click="${(ev) => this._selectCategory(ev, cat.category)}">
|
|
184
|
+
${cat.label ? unsafeHTML(cat.label) : cat.category}
|
|
185
|
+
</a>
|
|
186
|
+
`
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
</header>
|
|
190
|
+
<div id="items" part="items"><slot></slot></div>
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static get styles() {
|
|
195
|
+
return css`
|
|
196
|
+
:host {
|
|
197
|
+
display: block;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
header {
|
|
201
|
+
display: flex;
|
|
202
|
+
flex-wrap: wrap;
|
|
203
|
+
column-gap: 10px;
|
|
204
|
+
width: 100%;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
#items {
|
|
208
|
+
display: grid;
|
|
209
|
+
grid-template-columns: repeat(var(--pb-categorized-list-columns, 2), auto);
|
|
210
|
+
grid-auto-rows: 1fr;
|
|
211
|
+
column-gap: 10px;
|
|
212
|
+
width: 100%;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
[part=category], #items a {
|
|
216
|
+
text-decoration: none;
|
|
217
|
+
color: var(--pb-link-color);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
[part=active-category] {
|
|
221
|
+
text-decoration: none;
|
|
222
|
+
color: var(--pb-highlight-color);
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
189
227
|
customElements.define('pb-split-list', PbSplitList);
|