@teipublisher/pb-components 1.43.4 → 1.44.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 +21 -0
- package/CHANGELOG.md +14 -0
- package/dist/demo/pb-table-grid.html +16 -16
- package/dist/demo/pb-view2.html +135 -135
- package/dist/demo/redirect.html +3 -0
- package/dist/jinn-codemirror-9718e0e0.js +1 -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 +1009 -690
- 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 +23 -0
- package/i18n/common/en.json +7 -2
- package/package.json +6 -4
- package/pb-elements.json +1009 -690
- 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-message.js +6 -10
- package/src/pb-mixin.js +542 -542
- package/src/pb-page.js +399 -399
- package/src/pb-split-list.js +188 -188
- package/src/pb-table-grid.js +218 -218
- package/src/pb-view.js +1366 -1366
- package/dist/jinn-codemirror-d437848a.js +0 -1
- /package/dist/{pb-mixin-f8b22e51.js → pb-mixin-88125cb2.js} +0 -0
package/src/pb-split-list.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
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
|
-
* @cssprop --pb-categorized-list-columns - the number of columns to display (default: 2)
|
|
23
|
-
* @fires pb-submit - when received, submit a request to the server and refresh
|
|
24
|
-
* @fires pb-start-update - sent before the element sends the request to the server
|
|
25
|
-
* @fires pb-end-update - sent after new content has been received
|
|
26
|
-
*/
|
|
27
|
-
export class PbSplitList extends themableMixin(pbMixin(LitElement)) {
|
|
28
|
-
static get properties() {
|
|
29
|
-
return {
|
|
30
|
-
/**
|
|
31
|
-
* Server-side API endpoint to retrieve items from
|
|
32
|
-
*/
|
|
33
|
-
url: {
|
|
34
|
-
type: String
|
|
35
|
-
},
|
|
36
|
-
/**
|
|
37
|
-
* The initially selected category
|
|
38
|
-
*/
|
|
39
|
-
selected: {
|
|
40
|
-
type: String
|
|
41
|
-
},
|
|
42
|
-
/**
|
|
43
|
-
* A CSS selector pointing to one or more `pb-custom-form`
|
|
44
|
-
* instances. The element will collect additional parameters
|
|
45
|
-
* from those forms and includes them in the request to the server
|
|
46
|
-
*/
|
|
47
|
-
subforms: {
|
|
48
|
-
type: String
|
|
49
|
-
},
|
|
50
|
-
_categories: {
|
|
51
|
-
type: Array
|
|
52
|
-
},
|
|
53
|
-
...super.properties
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
constructor() {
|
|
58
|
-
super();
|
|
59
|
-
this._categories = [];
|
|
60
|
-
this._params = {};
|
|
61
|
-
this.selected = null;
|
|
62
|
-
this.subforms = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
connectedCallback() {
|
|
66
|
-
super.connectedCallback();
|
|
67
|
-
|
|
68
|
-
this.selected = this.getParameter('category', this.selected);
|
|
69
|
-
|
|
70
|
-
window.addEventListener('popstate', (ev) => {
|
|
71
|
-
console.log('<pb-split-list> popstate: %o', ev);
|
|
72
|
-
this.selected = ev.state.category;
|
|
73
|
-
this.submit();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this.subscribeTo('pb-submit', this.load.bind(this));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
firstUpdated() {
|
|
80
|
-
super.firstUpdated();
|
|
81
|
-
|
|
82
|
-
PbSplitList.waitOnce('pb-page-ready', () => {
|
|
83
|
-
this.load();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
submit() {
|
|
88
|
-
this.load();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
load() {
|
|
92
|
-
const formParams = this._paramsFromSubforms({ category: this.selected });
|
|
93
|
-
this.setParameters(formParams);
|
|
94
|
-
this.pushHistory('pb-split-list', formParams);
|
|
95
|
-
|
|
96
|
-
const params = new URLSearchParams(formParams);
|
|
97
|
-
|
|
98
|
-
const url = `${this.toAbsoluteURL(this.url)}?${params.toString()}`;
|
|
99
|
-
console.log(`<pb-split-list> Fetching from URL: ${url}`);
|
|
100
|
-
|
|
101
|
-
this.emitTo('pb-start-update');
|
|
102
|
-
|
|
103
|
-
fetch(url)
|
|
104
|
-
.then((response) => {
|
|
105
|
-
if (response.ok) {
|
|
106
|
-
return response.json();
|
|
107
|
-
}
|
|
108
|
-
return Promise.reject(response.status);
|
|
109
|
-
})
|
|
110
|
-
.then((json) => {
|
|
111
|
-
this._categories = json.categories;
|
|
112
|
-
this.innerHTML = json.items.join('');
|
|
113
|
-
this.emitTo('pb-end-update');
|
|
114
|
-
})
|
|
115
|
-
.catch((error) => {
|
|
116
|
-
console.error(`<pb-split-list> Error caught: ${error}`);
|
|
117
|
-
this.emitTo('pb-end-update');
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_selectCategory(ev, category) {
|
|
122
|
-
ev.preventDefault();
|
|
123
|
-
this.selected = category;
|
|
124
|
-
this.load();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
_paramsFromSubforms(params) {
|
|
128
|
-
if (this.subforms) {
|
|
129
|
-
document.querySelectorAll(this.subforms).forEach((form) => {
|
|
130
|
-
if (form.serializeForm) {
|
|
131
|
-
Object.assign(params, form.serializeForm());
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
return params;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
render() {
|
|
139
|
-
return html`
|
|
140
|
-
<header>
|
|
141
|
-
${
|
|
142
|
-
this._categories.map((cat) =>
|
|
143
|
-
html`
|
|
144
|
-
<a part="${this.selected === cat.category ? 'active-category' : 'category'}" href="#${cat.category}" title="${cat.count}" class="${this.selected === cat.category ? 'active' : ''}"
|
|
145
|
-
@click="${(ev) => this._selectCategory(ev, cat.category)}">
|
|
146
|
-
${cat.label ? unsafeHTML(cat.label) : cat.category}
|
|
147
|
-
</a>
|
|
148
|
-
`
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
</header>
|
|
152
|
-
<div id="items" part="items"><slot></slot></div>
|
|
153
|
-
`;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static get styles() {
|
|
157
|
-
return css`
|
|
158
|
-
:host {
|
|
159
|
-
display: block;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
header {
|
|
163
|
-
display: flex;
|
|
164
|
-
flex-wrap: wrap;
|
|
165
|
-
column-gap: 10px;
|
|
166
|
-
width: 100%;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
#items {
|
|
170
|
-
display: grid;
|
|
171
|
-
grid-template-columns: repeat(var(--pb-categorized-list-columns, 2), auto);
|
|
172
|
-
grid-auto-rows: 1fr;
|
|
173
|
-
column-gap: 10px;
|
|
174
|
-
width: 100%;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
[part=category], #items a {
|
|
178
|
-
text-decoration: none;
|
|
179
|
-
color: var(--pb-link-color);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
[part=active-category] {
|
|
183
|
-
text-decoration: none;
|
|
184
|
-
color: var(--pb-highlight-color);
|
|
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
|
+
* @cssprop --pb-categorized-list-columns - the number of columns to display (default: 2)
|
|
23
|
+
* @fires pb-submit - when received, submit a request to the server and refresh
|
|
24
|
+
* @fires pb-start-update - sent before the element sends the request to the server
|
|
25
|
+
* @fires pb-end-update - sent after new content has been received
|
|
26
|
+
*/
|
|
27
|
+
export class PbSplitList extends themableMixin(pbMixin(LitElement)) {
|
|
28
|
+
static get properties() {
|
|
29
|
+
return {
|
|
30
|
+
/**
|
|
31
|
+
* Server-side API endpoint to retrieve items from
|
|
32
|
+
*/
|
|
33
|
+
url: {
|
|
34
|
+
type: String
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* The initially selected category
|
|
38
|
+
*/
|
|
39
|
+
selected: {
|
|
40
|
+
type: String
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* A CSS selector pointing to one or more `pb-custom-form`
|
|
44
|
+
* instances. The element will collect additional parameters
|
|
45
|
+
* from those forms and includes them in the request to the server
|
|
46
|
+
*/
|
|
47
|
+
subforms: {
|
|
48
|
+
type: String
|
|
49
|
+
},
|
|
50
|
+
_categories: {
|
|
51
|
+
type: Array
|
|
52
|
+
},
|
|
53
|
+
...super.properties
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
super();
|
|
59
|
+
this._categories = [];
|
|
60
|
+
this._params = {};
|
|
61
|
+
this.selected = null;
|
|
62
|
+
this.subforms = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
connectedCallback() {
|
|
66
|
+
super.connectedCallback();
|
|
67
|
+
|
|
68
|
+
this.selected = this.getParameter('category', this.selected);
|
|
69
|
+
|
|
70
|
+
window.addEventListener('popstate', (ev) => {
|
|
71
|
+
console.log('<pb-split-list> popstate: %o', ev);
|
|
72
|
+
this.selected = ev.state.category;
|
|
73
|
+
this.submit();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.subscribeTo('pb-submit', this.load.bind(this));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
firstUpdated() {
|
|
80
|
+
super.firstUpdated();
|
|
81
|
+
|
|
82
|
+
PbSplitList.waitOnce('pb-page-ready', () => {
|
|
83
|
+
this.load();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
submit() {
|
|
88
|
+
this.load();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
load() {
|
|
92
|
+
const formParams = this._paramsFromSubforms({ category: this.selected });
|
|
93
|
+
this.setParameters(formParams);
|
|
94
|
+
this.pushHistory('pb-split-list', formParams);
|
|
95
|
+
|
|
96
|
+
const params = new URLSearchParams(formParams);
|
|
97
|
+
|
|
98
|
+
const url = `${this.toAbsoluteURL(this.url)}?${params.toString()}`;
|
|
99
|
+
console.log(`<pb-split-list> Fetching from URL: ${url}`);
|
|
100
|
+
|
|
101
|
+
this.emitTo('pb-start-update');
|
|
102
|
+
|
|
103
|
+
fetch(url)
|
|
104
|
+
.then((response) => {
|
|
105
|
+
if (response.ok) {
|
|
106
|
+
return response.json();
|
|
107
|
+
}
|
|
108
|
+
return Promise.reject(response.status);
|
|
109
|
+
})
|
|
110
|
+
.then((json) => {
|
|
111
|
+
this._categories = json.categories;
|
|
112
|
+
this.innerHTML = json.items.join('');
|
|
113
|
+
this.emitTo('pb-end-update');
|
|
114
|
+
})
|
|
115
|
+
.catch((error) => {
|
|
116
|
+
console.error(`<pb-split-list> Error caught: ${error}`);
|
|
117
|
+
this.emitTo('pb-end-update');
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_selectCategory(ev, category) {
|
|
122
|
+
ev.preventDefault();
|
|
123
|
+
this.selected = category;
|
|
124
|
+
this.load();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_paramsFromSubforms(params) {
|
|
128
|
+
if (this.subforms) {
|
|
129
|
+
document.querySelectorAll(this.subforms).forEach((form) => {
|
|
130
|
+
if (form.serializeForm) {
|
|
131
|
+
Object.assign(params, form.serializeForm());
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return params;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
render() {
|
|
139
|
+
return html`
|
|
140
|
+
<header>
|
|
141
|
+
${
|
|
142
|
+
this._categories.map((cat) =>
|
|
143
|
+
html`
|
|
144
|
+
<a part="${this.selected === cat.category ? 'active-category' : 'category'}" href="#${cat.category}" title="${cat.count}" class="${this.selected === cat.category ? 'active' : ''}"
|
|
145
|
+
@click="${(ev) => this._selectCategory(ev, cat.category)}">
|
|
146
|
+
${cat.label ? unsafeHTML(cat.label) : cat.category}
|
|
147
|
+
</a>
|
|
148
|
+
`
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
</header>
|
|
152
|
+
<div id="items" part="items"><slot></slot></div>
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static get styles() {
|
|
157
|
+
return css`
|
|
158
|
+
:host {
|
|
159
|
+
display: block;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
header {
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-wrap: wrap;
|
|
165
|
+
column-gap: 10px;
|
|
166
|
+
width: 100%;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#items {
|
|
170
|
+
display: grid;
|
|
171
|
+
grid-template-columns: repeat(var(--pb-categorized-list-columns, 2), auto);
|
|
172
|
+
grid-auto-rows: 1fr;
|
|
173
|
+
column-gap: 10px;
|
|
174
|
+
width: 100%;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
[part=category], #items a {
|
|
178
|
+
text-decoration: none;
|
|
179
|
+
color: var(--pb-link-color);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
[part=active-category] {
|
|
183
|
+
text-decoration: none;
|
|
184
|
+
color: var(--pb-highlight-color);
|
|
185
|
+
}
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
189
|
customElements.define('pb-split-list', PbSplitList);
|