@teipublisher/pb-components 1.38.7 → 1.40.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/pb-elements.json CHANGED
@@ -1397,6 +1397,7 @@
1397
1397
  },
1398
1398
  {
1399
1399
  "name": "userParams",
1400
+ "description": "Additional, user-defined parameters to be sent with the request.",
1400
1401
  "type": "object"
1401
1402
  },
1402
1403
  {
@@ -1413,14 +1414,22 @@
1413
1414
  },
1414
1415
  {
1415
1416
  "name": "history",
1417
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
1416
1418
  "type": "boolean",
1417
1419
  "default": "false"
1418
1420
  },
1419
1421
  {
1420
1422
  "name": "event",
1423
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
1421
1424
  "type": "string",
1422
1425
  "default": "\"pb-load\""
1423
1426
  },
1427
+ {
1428
+ "name": "no-credentials",
1429
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
1430
+ "type": "boolean",
1431
+ "default": "true"
1432
+ },
1424
1433
  {
1425
1434
  "name": "subscribe",
1426
1435
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -1581,6 +1590,7 @@
1581
1590
  {
1582
1591
  "name": "userParams",
1583
1592
  "attribute": "userParams",
1593
+ "description": "Additional, user-defined parameters to be sent with the request.",
1584
1594
  "type": "object"
1585
1595
  },
1586
1596
  {
@@ -1600,12 +1610,14 @@
1600
1610
  {
1601
1611
  "name": "history",
1602
1612
  "attribute": "history",
1613
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
1603
1614
  "type": "boolean",
1604
1615
  "default": "false"
1605
1616
  },
1606
1617
  {
1607
1618
  "name": "event",
1608
1619
  "attribute": "event",
1620
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
1609
1621
  "type": "string",
1610
1622
  "default": "\"pb-load\""
1611
1623
  },
@@ -1617,6 +1629,13 @@
1617
1629
  {
1618
1630
  "name": "language"
1619
1631
  },
1632
+ {
1633
+ "name": "noCredentials",
1634
+ "attribute": "no-credentials",
1635
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
1636
+ "type": "boolean",
1637
+ "default": "true"
1638
+ },
1620
1639
  {
1621
1640
  "name": "subscribe",
1622
1641
  "attribute": "subscribe",
@@ -2012,6 +2031,11 @@
2012
2031
  "name": "--pb-code-highlight-white-space",
2013
2032
  "description": "configures line wrapping",
2014
2033
  "default": "\"pre\""
2034
+ },
2035
+ {
2036
+ "name": "--pb-code-highlight-theme",
2037
+ "description": "configures the default theme to be used",
2038
+ "default": "\"default\""
2015
2039
  }
2016
2040
  ]
2017
2041
  },
@@ -2487,6 +2511,7 @@
2487
2511
  },
2488
2512
  {
2489
2513
  "name": "userParams",
2514
+ "description": "Additional, user-defined parameters to be sent with the request.",
2490
2515
  "type": "object"
2491
2516
  },
2492
2517
  {
@@ -2503,14 +2528,22 @@
2503
2528
  },
2504
2529
  {
2505
2530
  "name": "history",
2531
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
2506
2532
  "type": "boolean",
2507
2533
  "default": "false"
2508
2534
  },
2509
2535
  {
2510
2536
  "name": "event",
2537
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
2511
2538
  "type": "string",
2512
2539
  "default": "\"pb-load\""
2513
2540
  },
2541
+ {
2542
+ "name": "no-credentials",
2543
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
2544
+ "type": "boolean",
2545
+ "default": "true"
2546
+ },
2514
2547
  {
2515
2548
  "name": "subscribe",
2516
2549
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -2595,6 +2628,7 @@
2595
2628
  {
2596
2629
  "name": "userParams",
2597
2630
  "attribute": "userParams",
2631
+ "description": "Additional, user-defined parameters to be sent with the request.",
2598
2632
  "type": "object"
2599
2633
  },
2600
2634
  {
@@ -2614,12 +2648,14 @@
2614
2648
  {
2615
2649
  "name": "history",
2616
2650
  "attribute": "history",
2651
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
2617
2652
  "type": "boolean",
2618
2653
  "default": "false"
2619
2654
  },
2620
2655
  {
2621
2656
  "name": "event",
2622
2657
  "attribute": "event",
2658
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
2623
2659
  "type": "string",
2624
2660
  "default": "\"pb-load\""
2625
2661
  },
@@ -2631,6 +2667,13 @@
2631
2667
  {
2632
2668
  "name": "language"
2633
2669
  },
2670
+ {
2671
+ "name": "noCredentials",
2672
+ "attribute": "no-credentials",
2673
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
2674
+ "type": "boolean",
2675
+ "default": "true"
2676
+ },
2634
2677
  {
2635
2678
  "name": "subscribe",
2636
2679
  "attribute": "subscribe",
@@ -5196,6 +5239,7 @@
5196
5239
  },
5197
5240
  {
5198
5241
  "name": "userParams",
5242
+ "description": "Additional, user-defined parameters to be sent with the request.",
5199
5243
  "type": "object"
5200
5244
  },
5201
5245
  {
@@ -5212,14 +5256,22 @@
5212
5256
  },
5213
5257
  {
5214
5258
  "name": "history",
5259
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
5215
5260
  "type": "boolean",
5216
5261
  "default": "false"
5217
5262
  },
5218
5263
  {
5219
5264
  "name": "event",
5265
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
5220
5266
  "type": "string",
5221
5267
  "default": "\"pb-load\""
5222
5268
  },
5269
+ {
5270
+ "name": "no-credentials",
5271
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
5272
+ "type": "boolean",
5273
+ "default": "true"
5274
+ },
5223
5275
  {
5224
5276
  "name": "subscribe",
5225
5277
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -5298,6 +5350,7 @@
5298
5350
  {
5299
5351
  "name": "userParams",
5300
5352
  "attribute": "userParams",
5353
+ "description": "Additional, user-defined parameters to be sent with the request.",
5301
5354
  "type": "object"
5302
5355
  },
5303
5356
  {
@@ -5317,12 +5370,14 @@
5317
5370
  {
5318
5371
  "name": "history",
5319
5372
  "attribute": "history",
5373
+ "description": "Indicates if the parameters of the request made should be saved to the browser\nhistory and URL. Default: false.",
5320
5374
  "type": "boolean",
5321
5375
  "default": "false"
5322
5376
  },
5323
5377
  {
5324
5378
  "name": "event",
5325
5379
  "attribute": "event",
5380
+ "description": "The event which will trigger a new request to be sent. Default is 'pb-load'.",
5326
5381
  "type": "string",
5327
5382
  "default": "\"pb-load\""
5328
5383
  },
@@ -5334,6 +5389,13 @@
5334
5389
  {
5335
5390
  "name": "language"
5336
5391
  },
5392
+ {
5393
+ "name": "noCredentials",
5394
+ "attribute": "no-credentials",
5395
+ "description": "Indicates whether or not cross-site Access-Control requests should be made.\nDefault is false.",
5396
+ "type": "boolean",
5397
+ "default": "true"
5398
+ },
5337
5399
  {
5338
5400
  "name": "subscribe",
5339
5401
  "attribute": "subscribe",
@@ -3,7 +3,30 @@ import "prismjs/prism";
3
3
  import 'prismjs/components/prism-xquery';
4
4
  import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace';
5
5
  import 'prismjs/plugins/line-numbers/prism-line-numbers';
6
- import { resolveURL } from './utils.js';
6
+ import { resolveURL, getCSSProperty } from './utils.js';
7
+
8
+ const PRISM_THEMES = new Map();
9
+
10
+ function loadTheme(theme) {
11
+ const themeName = theme === 'default' ? 'prism.css' : `prism-${theme}.css`;
12
+ if (PRISM_THEMES.has(themeName)) {
13
+ console.log('Using cached theme: %s', themeName);
14
+ return PRISM_THEMES.get(themeName);
15
+ }
16
+
17
+ const promise = new Promise((resolve) => {
18
+ const resource = resolveURL('../css/prismjs/') + themeName;
19
+ console.log('<pb-code-highlight> loading theme %s from %s', theme, resource);
20
+ fetch(resource)
21
+ .then(response => response.text())
22
+ .catch(() => resolve(''))
23
+ .then(text => {
24
+ resolve(html`<style>${text}</style>`);
25
+ });
26
+ });
27
+ PRISM_THEMES.set(themeName, promise);
28
+ return promise;
29
+ }
7
30
 
8
31
  /**
9
32
  * Highlight a code snippet. The snippet may either be passed in a template child
@@ -12,6 +35,7 @@ import { resolveURL } from './utils.js';
12
35
  * pass the code to be highlighted in the `code` property.
13
36
  *
14
37
  * @cssprop [--pb-code-highlight-white-space=pre] - configures line wrapping
38
+ * @cssprop [--pb-code-highlight-theme=default] - configures the default theme to be used
15
39
  */
16
40
  export class PbCodeHighlight extends LitElement {
17
41
  static get properties() {
@@ -41,7 +65,7 @@ export class PbCodeHighlight extends LitElement {
41
65
  type: Boolean,
42
66
  attribute: 'line-numbers'
43
67
  },
44
- _styles: {
68
+ _themeStyles: {
45
69
  type: String
46
70
  }
47
71
  };
@@ -52,13 +76,15 @@ export class PbCodeHighlight extends LitElement {
52
76
  this.language = 'xml';
53
77
  this.theme = 'default';
54
78
  this.lineNumbers = false;
79
+ this._themeStyles = null;
55
80
  }
56
81
 
57
82
  connectedCallback() {
58
83
  super.connectedCallback();
59
- const theme = this.getAttribute('theme');
84
+ let theme = this.getAttribute('theme');
60
85
  if (theme === null) {
61
- this.setAttribute('theme', 'default');
86
+ theme = getCSSProperty(this, '--pb-code-highlight-theme', 'default');
87
+ this.setAttribute('theme', theme);
62
88
  }
63
89
  }
64
90
 
@@ -79,8 +105,8 @@ export class PbCodeHighlight extends LitElement {
79
105
  super.attributeChangedCallback(name, oldValue, newValue);
80
106
  switch (name) {
81
107
  case 'theme':
82
- PbCodeHighlight.loadTheme(newValue).then((styles) => {
83
- this._styles = styles;
108
+ loadTheme(newValue).then(loadedStyles => {
109
+ this._themeStyles = loadedStyles;
84
110
  });
85
111
  break;
86
112
  default:
@@ -102,23 +128,13 @@ export class PbCodeHighlight extends LitElement {
102
128
  render() {
103
129
  if (this.code) {
104
130
  return html`
105
- ${this._styles}
131
+ ${this._themeStyles}
106
132
  <pre class="${this.lineNumbers ? 'line-numbers' : ''} language-${this.language}"><code>${this.code}</code></pre>
107
133
  `;
108
134
  }
109
135
  return html`<pre class="line-numbers"><code><code></pre>`;
110
136
  }
111
137
 
112
- static async loadTheme(theme) {
113
- const themeName = theme === 'default' ? 'prism.css' : `prism-${theme}.css`;
114
- const resource = resolveURL('../css/prismjs/') + themeName;
115
- console.log('<pb-code-highlight> loading theme %s from %s', theme, resource);
116
-
117
- const fetchedStyles = await fetch(resource).then(async response => response.text()).catch(e => '');
118
-
119
- return html`<style>${fetchedStyles}</style>`;
120
- }
121
-
122
138
  static get styles() {
123
139
  return css`
124
140
  :host {
package/src/pb-load.js CHANGED
@@ -87,12 +87,30 @@ export class PbLoad extends pbMixin(LitElement) {
87
87
  type: Boolean,
88
88
  attribute: 'use-language'
89
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
+ */
90
102
  history: {
91
103
  type: Boolean
92
104
  },
105
+ /**
106
+ * The event which will trigger a new request to be sent. Default is 'pb-load'.
107
+ */
93
108
  event: {
94
109
  type: String
95
110
  },
111
+ /**
112
+ * Additional, user-defined parameters to be sent with the request.
113
+ */
96
114
  userParams: {
97
115
  type: Object
98
116
  }
@@ -107,6 +125,7 @@ export class PbLoad extends pbMixin(LitElement) {
107
125
  this.event = 'pb-load';
108
126
  this.loaded = false;
109
127
  this.language = null;
128
+ this.noCredentials = true;
110
129
  }
111
130
 
112
131
  connectedCallback() {
@@ -169,6 +188,23 @@ export class PbLoad extends pbMixin(LitElement) {
169
188
  }
170
189
  }
171
190
 
191
+ attributeChangedCallback(name, oldValue, newValue) {
192
+ super.attributeChangedCallback(name, oldValue, newValue);
193
+ if (oldValue && oldValue !== newValue) {
194
+ switch (name) {
195
+ case 'url':
196
+ case 'userParams':
197
+ case 'start':
198
+ PbLoad.waitOnce('pb-page-ready', () => {
199
+ this.load();
200
+ });
201
+ break;
202
+ default:
203
+ break;
204
+ }
205
+ }
206
+ }
207
+
172
208
  render() {
173
209
  return html`
174
210
  <slot></slot>
@@ -177,7 +213,7 @@ export class PbLoad extends pbMixin(LitElement) {
177
213
  verbose
178
214
  handle-as="text"
179
215
  method="get"
180
- with-credentials
216
+ ?with-credentials="${!this.noCredentials}"
181
217
  @response="${this._handleContent}"
182
218
  @error="${this._handleError}"></iron-ajax>
183
219
  <paper-dialog id="errorDialog">
package/src/pb-page.js CHANGED
@@ -174,6 +174,8 @@ class PbPage extends pbMixin(LitElement) {
174
174
  return;
175
175
  }
176
176
 
177
+ this.endpoint = this.endpoint.replace(/\/+$/, '');
178
+
177
179
  if (this.locales && this._localeFallbacks.indexOf('app') === -1) {
178
180
  this._localeFallbacks.push('app');
179
181
  }
@@ -202,7 +204,12 @@ class PbPage extends pbMixin(LitElement) {
202
204
  return fetch(`${this.endpoint}/api/version`)
203
205
  .then((res2) => res2.json());
204
206
  })
205
- .catch(() => null)
207
+ .catch((error) => {
208
+ if (error.response.status === 404) {
209
+ return fetch(`${this.endpoint}/api/version`)
210
+ .then((res2) => res2.json());
211
+ }
212
+ });
206
213
 
207
214
  if (json) {
208
215
  this.apiVersion = json.api;
@@ -219,6 +226,13 @@ class PbPage extends pbMixin(LitElement) {
219
226
  template: this.template,
220
227
  apiVersion: this.apiVersion
221
228
  });
229
+ } else if (this._i18nInstance) {
230
+ this.signalReady('pb-page-ready', {
231
+ endpoint: this.endpoint,
232
+ apiVersion: this.apiVersion,
233
+ template: this.template,
234
+ language: this._i18nInstance.language
235
+ });
222
236
  }
223
237
  }
224
238
 
@@ -287,7 +301,7 @@ class PbPage extends pbMixin(LitElement) {
287
301
  // initialized and ready to go!
288
302
  this._updateI18n(t);
289
303
  this.signalReady('pb-i18n-update', { t, language: this._i18nInstance.language });
290
- if (this.requireLanguage) {
304
+ if (this.requireLanguage && this.apiVersion) {
291
305
  this.signalReady('pb-page-ready', {
292
306
  endpoint: this.endpoint,
293
307
  apiVersion: this.apiVersion,
package/src/pb-popover.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import tippy from 'tippy.js';
3
3
  import { pbMixin } from './pb-mixin.js';
4
+ import { getCSSProperty } from "./utils.js";
4
5
  import * as themes from './pb-popover-themes.js';
5
6
 
6
7
  function _injectStylesheet(root, name, cssCode) {
@@ -161,34 +162,22 @@ export class PbPopover extends pbMixin(LitElement) {
161
162
 
162
163
  _checkCSSProperties() {
163
164
  if (!this.theme && this.theme !== 'none') {
164
- this.theme = this._getCSSProperty('--pb-popover-theme', 'none');
165
+ this.theme = getCSSProperty(this, '--pb-popover-theme', 'none');
165
166
  }
166
167
  if (!this.placement) {
167
- this.placement = this._getCSSProperty('--pb-popover-placement', 'auto');
168
+ this.placement = getCSSProperty(this, '--pb-popover-placement', 'auto');
168
169
  }
169
170
  if (!this.fallbackPlacement) {
170
- this.fallbackPlacement = this._getCSSProperty('--pb-popover-fallback-placement', null);
171
+ this.fallbackPlacement = getCSSProperty(this, '--pb-popover-fallback-placement', null);
171
172
  }
172
173
  if (!this.persistent) {
173
- this.persistent = this._getCSSProperty('--pb-popover-persistent', false);
174
+ this.persistent = getCSSProperty(this, '--pb-popover-persistent', false);
174
175
  }
175
176
  if (!this.trigger) {
176
- this.trigger = this._getCSSProperty('--pb-popover-trigger', null);
177
+ this.trigger = getCSSProperty(this, '--pb-popover-trigger', null);
177
178
  }
178
179
  }
179
180
 
180
- _getCSSProperty(name, defaultValue) {
181
- const property = getComputedStyle(this).getPropertyValue(name);
182
- if (property) {
183
- try {
184
- return JSON.parse(property);
185
- } catch (e) {
186
- return defaultValue;
187
- }
188
- }
189
- return defaultValue;
190
- }
191
-
192
181
  _injectStyles() {
193
182
  this._checkCSSProperties();
194
183
 
package/src/pb-upload.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
2
  import { pbMixin } from './pb-mixin.js';
3
3
  import { translate } from "./pb-i18n.js";
4
+ import { getCSSProperty } from "./utils.js";
4
5
  import '@vaadin/vaadin-upload';
5
6
  import '@polymer/paper-button';
6
7
  import '@polymer/paper-icon-button';
@@ -108,8 +109,8 @@ export class PbUpload extends pbMixin(LitElement) {
108
109
  }
109
110
 
110
111
  render() {
111
- const uploadIcon = this._getCSSProperty('--pb-upload-button-icon', 'icons:file-upload');
112
- const dropLabelIcon = this._getCSSProperty('--pb-upload-drop-icon', null);
112
+ const uploadIcon = getCSSProperty(this, '--pb-upload-button-icon', 'icons:file-upload');
113
+ const dropLabelIcon = getCSSProperty(this, '--pb-upload-drop-icon', null);
113
114
  return html`
114
115
  <vaadin-upload id="uploader" accept="${this.accept}" method="post" tabindex="-1" form-data-name="files[]"
115
116
  with-credentials>
@@ -170,18 +171,6 @@ export class PbUpload extends pbMixin(LitElement) {
170
171
  this.requestUpdate();
171
172
  }
172
173
 
173
- _getCSSProperty(name, defaultValue) {
174
- const property = getComputedStyle(this).getPropertyValue(name);
175
- if (property) {
176
- try {
177
- return JSON.parse(property);
178
- } catch (e) {
179
- return defaultValue;
180
- }
181
- }
182
- return defaultValue;
183
- }
184
-
185
174
  static get styles() {
186
175
  return css`
187
176
  ul {
package/src/utils.js CHANGED
@@ -29,4 +29,24 @@ export function cmpVersion(a, b) {
29
29
 
30
30
  export function minVersion(given, required) {
31
31
  return cmpVersion(given, required) >= 0;
32
+ }
33
+
34
+ /**
35
+ * Retrieve value of a CSS property.
36
+ *
37
+ * @param {Element} elem the component
38
+ * @param {string} name name of the property
39
+ * @param {any} defaultValue default value
40
+ * @returns the value or defaultValue if it does not exist
41
+ */
42
+ export function getCSSProperty(elem, name, defaultValue) {
43
+ const property = getComputedStyle(elem).getPropertyValue(name);
44
+ if (property) {
45
+ try {
46
+ return JSON.parse(property);
47
+ } catch (e) {
48
+ return defaultValue;
49
+ }
50
+ }
51
+ return defaultValue;
32
52
  }