@teipublisher/pb-components 1.42.5 → 1.42.6

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.
@@ -362,7 +362,6 @@ export class PbOddModelEditor extends LitElement {
362
362
 
363
363
  this.outputs = ["",
364
364
  "web",
365
- "printcss",
366
365
  "print",
367
366
  "epub",
368
367
  "fo",
@@ -1,188 +1,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
-
5
- /**
6
- * Implements a list which is split into different categories
7
- * (e.g. letters of the alphabet, countries ...).
8
- * Only one category is shown at a time unless the server reports
9
- * no categories (e.g. if the number of items to display goes below
10
- * a defined threshold).
11
- *
12
- * The server-side API endpoint should return a JSON object with two
13
- * properties:
14
- *
15
- * + `categories`: an array of category descriptions: each item should
16
- * be an object with two properties: `category` - containing the name of the category
17
- * and `count` - containing a count of items available under this category.
18
- * + `items`: an array with the items to be shown for the currently selected
19
- * category. Those may contain HTML markup.
20
- *
21
- * @cssprop --pb-categorized-list-columns - the number of columns to display (default: 2)
22
- * @fires pb-submit - when received, submit a request to the server and refresh
23
- * @fires pb-start-update - sent before the element sends the request to the server
24
- * @fires pb-end-update - sent after new content has been received
25
- */
26
- export class PbSplitList extends pbMixin(LitElement) {
27
- static get properties() {
28
- return {
29
- /**
30
- * Server-side API endpoint to retrieve items from
31
- */
32
- url: {
33
- type: String
34
- },
35
- /**
36
- * The initially selected category
37
- */
38
- selected: {
39
- type: String
40
- },
41
- /**
42
- * A CSS selector pointing to one or more `pb-custom-form`
43
- * instances. The element will collect additional parameters
44
- * from those forms and includes them in the request to the server
45
- */
46
- subforms: {
47
- type: String
48
- },
49
- _categories: {
50
- type: Array
51
- },
52
- ...super.properties
53
- };
54
- }
55
-
56
- constructor() {
57
- super();
58
- this._categories = [];
59
- this._params = {};
60
- this.selected = null;
61
- this.subforms = null;
62
- }
63
-
64
- connectedCallback() {
65
- super.connectedCallback();
66
-
67
- this.selected = this.getParameter('category', this.selected);
68
-
69
- window.addEventListener('popstate', (ev) => {
70
- console.log('<pb-split-list> popstate: %o', ev);
71
- this.selected = ev.state.category;
72
- this.submit();
73
- });
74
-
75
- this.subscribeTo('pb-submit', this.load.bind(this));
76
- }
77
-
78
- firstUpdated() {
79
- super.firstUpdated();
80
-
81
- PbSplitList.waitOnce('pb-page-ready', () => {
82
- this.load();
83
- });
84
- }
85
-
86
- submit() {
87
- this.load();
88
- }
89
-
90
- load() {
91
- const formParams = this._paramsFromSubforms({ category: this.selected });
92
- this.setParameters(formParams);
93
- this.pushHistory('pb-split-list', formParams);
94
-
95
- const params = new URLSearchParams(formParams);
96
-
97
- const url = `${this.toAbsoluteURL(this.url)}?${params.toString()}`;
98
- console.log(`<pb-split-list> Fetching from URL: ${url}`);
99
-
100
- this.emitTo('pb-start-update');
101
-
102
- fetch(url)
103
- .then((response) => {
104
- if (response.ok) {
105
- return response.json();
106
- }
107
- return Promise.reject(response.status);
108
- })
109
- .then((json) => {
110
- this._categories = json.categories;
111
- this.innerHTML = json.items.join('');
112
- this.emitTo('pb-end-update');
113
- })
114
- .catch((error) => {
115
- console.error(`<pb-split-list> Error caught: ${error}`);
116
- this.emitTo('pb-end-update');
117
- });
118
- }
119
-
120
- _selectCategory(ev, category) {
121
- ev.preventDefault();
122
- this.selected = category;
123
- this.load();
124
- }
125
-
126
- _paramsFromSubforms(params) {
127
- if (this.subforms) {
128
- document.querySelectorAll(this.subforms).forEach((form) => {
129
- if (form.serializeForm) {
130
- Object.assign(params, form.serializeForm());
131
- }
132
- });
133
- }
134
- return params;
135
- }
136
-
137
- render() {
138
- return html`
139
- <header>
140
- ${
141
- this._categories.map((cat) =>
142
- html`
143
- <a part="${this.selected === cat.category ? 'active-category' : 'category'}" href="#${cat.category}" title="${cat.count}" class="${this.selected === cat.category ? 'active' : ''}"
144
- @click="${(ev) => this._selectCategory(ev, cat.category)}">
145
- ${cat.category}
146
- </a>
147
- `
148
- )
149
- }
150
- </header>
151
- <div id="items" part="items"><slot></slot></div>
152
- `;
153
- }
154
-
155
- static get styles() {
156
- return css`
157
- :host {
158
- display: block;
159
- }
160
-
161
- header {
162
- display: flex;
163
- flex-wrap: wrap;
164
- column-gap: 10px;
165
- width: 100%;
166
- }
167
-
168
- #items {
169
- display: grid;
170
- grid-template-columns: repeat(var(--pb-categorized-list-columns, 2), auto);
171
- grid-auto-rows: 1fr;
172
- column-gap: 10px;
173
- width: 100%;
174
- }
175
-
176
- [part=category], #items a {
177
- text-decoration: none;
178
- color: var(--pb-link-color);
179
- }
180
-
181
- [part=active-category] {
182
- text-decoration: none;
183
- color: var(--pb-highlight-color);
184
- }
185
- `;
186
- }
187
- }
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
+
5
+ /**
6
+ * Implements a list which is split into different categories
7
+ * (e.g. letters of the alphabet, countries ...).
8
+ * Only one category is shown at a time unless the server reports
9
+ * no categories (e.g. if the number of items to display goes below
10
+ * a defined threshold).
11
+ *
12
+ * The server-side API endpoint should return a JSON object with two
13
+ * properties:
14
+ *
15
+ * + `categories`: an array of category descriptions: each item should
16
+ * be an object with two properties: `category` - containing the name of the category
17
+ * and `count` - containing a count of items available under this category.
18
+ * + `items`: an array with the items to be shown for the currently selected
19
+ * category. Those may contain HTML markup.
20
+ *
21
+ * @cssprop --pb-categorized-list-columns - the number of columns to display (default: 2)
22
+ * @fires pb-submit - when received, submit a request to the server and refresh
23
+ * @fires pb-start-update - sent before the element sends the request to the server
24
+ * @fires pb-end-update - sent after new content has been received
25
+ */
26
+ export class PbSplitList extends pbMixin(LitElement) {
27
+ static get properties() {
28
+ return {
29
+ /**
30
+ * Server-side API endpoint to retrieve items from
31
+ */
32
+ url: {
33
+ type: String
34
+ },
35
+ /**
36
+ * The initially selected category
37
+ */
38
+ selected: {
39
+ type: String
40
+ },
41
+ /**
42
+ * A CSS selector pointing to one or more `pb-custom-form`
43
+ * instances. The element will collect additional parameters
44
+ * from those forms and includes them in the request to the server
45
+ */
46
+ subforms: {
47
+ type: String
48
+ },
49
+ _categories: {
50
+ type: Array
51
+ },
52
+ ...super.properties
53
+ };
54
+ }
55
+
56
+ constructor() {
57
+ super();
58
+ this._categories = [];
59
+ this._params = {};
60
+ this.selected = null;
61
+ this.subforms = null;
62
+ }
63
+
64
+ connectedCallback() {
65
+ super.connectedCallback();
66
+
67
+ this.selected = this.getParameter('category', this.selected);
68
+
69
+ window.addEventListener('popstate', (ev) => {
70
+ console.log('<pb-split-list> popstate: %o', ev);
71
+ this.selected = ev.state.category;
72
+ this.submit();
73
+ });
74
+
75
+ this.subscribeTo('pb-submit', this.load.bind(this));
76
+ }
77
+
78
+ firstUpdated() {
79
+ super.firstUpdated();
80
+
81
+ PbSplitList.waitOnce('pb-page-ready', () => {
82
+ this.load();
83
+ });
84
+ }
85
+
86
+ submit() {
87
+ this.load();
88
+ }
89
+
90
+ load() {
91
+ const formParams = this._paramsFromSubforms({ category: this.selected });
92
+ this.setParameters(formParams);
93
+ this.pushHistory('pb-split-list', formParams);
94
+
95
+ const params = new URLSearchParams(formParams);
96
+
97
+ const url = `${this.toAbsoluteURL(this.url)}?${params.toString()}`;
98
+ console.log(`<pb-split-list> Fetching from URL: ${url}`);
99
+
100
+ this.emitTo('pb-start-update');
101
+
102
+ fetch(url)
103
+ .then((response) => {
104
+ if (response.ok) {
105
+ return response.json();
106
+ }
107
+ return Promise.reject(response.status);
108
+ })
109
+ .then((json) => {
110
+ this._categories = json.categories;
111
+ this.innerHTML = json.items.join('');
112
+ this.emitTo('pb-end-update');
113
+ })
114
+ .catch((error) => {
115
+ console.error(`<pb-split-list> Error caught: ${error}`);
116
+ this.emitTo('pb-end-update');
117
+ });
118
+ }
119
+
120
+ _selectCategory(ev, category) {
121
+ ev.preventDefault();
122
+ this.selected = category;
123
+ this.load();
124
+ }
125
+
126
+ _paramsFromSubforms(params) {
127
+ if (this.subforms) {
128
+ document.querySelectorAll(this.subforms).forEach((form) => {
129
+ if (form.serializeForm) {
130
+ Object.assign(params, form.serializeForm());
131
+ }
132
+ });
133
+ }
134
+ return params;
135
+ }
136
+
137
+ render() {
138
+ return html`
139
+ <header>
140
+ ${
141
+ this._categories.map((cat) =>
142
+ html`
143
+ <a part="${this.selected === cat.category ? 'active-category' : 'category'}" href="#${cat.category}" title="${cat.count}" class="${this.selected === cat.category ? 'active' : ''}"
144
+ @click="${(ev) => this._selectCategory(ev, cat.category)}">
145
+ ${unsafeHTML(cat.category)}
146
+ </a>
147
+ `
148
+ )
149
+ }
150
+ </header>
151
+ <div id="items" part="items"><slot></slot></div>
152
+ `;
153
+ }
154
+
155
+ static get styles() {
156
+ return css`
157
+ :host {
158
+ display: block;
159
+ }
160
+
161
+ header {
162
+ display: flex;
163
+ flex-wrap: wrap;
164
+ column-gap: 10px;
165
+ width: 100%;
166
+ }
167
+
168
+ #items {
169
+ display: grid;
170
+ grid-template-columns: repeat(var(--pb-categorized-list-columns, 2), auto);
171
+ grid-auto-rows: 1fr;
172
+ column-gap: 10px;
173
+ width: 100%;
174
+ }
175
+
176
+ [part=category], #items a {
177
+ text-decoration: none;
178
+ color: var(--pb-link-color);
179
+ }
180
+
181
+ [part=active-category] {
182
+ text-decoration: none;
183
+ color: var(--pb-highlight-color);
184
+ }
185
+ `;
186
+ }
187
+ }
188
188
  customElements.define('pb-split-list', PbSplitList);