@teipublisher/pb-components 2.25.3 → 2.26.0-next-3.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/src/pb-message.js CHANGED
@@ -1,24 +1,20 @@
1
1
  import { LitElement, html, css } from 'lit-element';
2
- import '@polymer/paper-dialog/paper-dialog';
3
- import '@polymer/paper-dialog-scrollable/paper-dialog-scrollable';
4
2
  import '@polymer/paper-button/paper-button';
5
3
  import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
6
4
  import { translate } from "./pb-i18n.js";
5
+ import './pb-dialog.js';
6
+ import { themableMixin } from './theming.js';
7
7
 
8
8
  /**
9
9
  * Show a dialog with buttons. Used by ODD editor.
10
10
  */
11
- export class PbMessage extends LitElement {
11
+ export class PbMessage extends themableMixin(LitElement) {
12
12
 
13
13
  static get styles() {
14
14
  return css`
15
15
  :host {
16
16
  display:block;
17
17
  }
18
-
19
- paper-dialog{
20
- min-width:300px;
21
- }
22
18
  `;
23
19
  }
24
20
 
@@ -57,33 +53,28 @@ export class PbMessage extends LitElement {
57
53
 
58
54
  render() {
59
55
  return html`
60
- <paper-dialog id="modal">
61
- <h2 id="title">${unsafeHTML(this.title)}</h2>
62
- <paper-dialog-scrollable id="message" class="message" tabindex="0">
56
+ <pb-dialog>
57
+ <h2 id="title" slot="title">${unsafeHTML(this.title)}</h2>
58
+ <div id="message" class="message" tabindex="0">
63
59
  ${ this.message ? unsafeHTML(this.message) : html`<slot></slot>` }
64
- </paper-dialog-scrollable>
60
+ </div>
65
61
 
66
- <div class="buttons">
67
- <paper-button dialog-confirm="dialog-confirm" autofocus="autofocus" ?hidden="${this.isConfirm()}">${translate('dialogs.close')}</paper-button>
68
- <paper-button id="confirm" dialog-confirm="dialog-confirm" autofocus="autofocus" ?hidden="${this.isMessage()}">${translate('dialogs.yes')}</paper-button>
69
- <paper-button id="reject" dialog-confirm="dialog-confirm" autofocus="autofocus" ?hidden="${this.isMessage()}">${translate('dialogs.no')}</paper-button>
62
+ <div class="buttons" slot="footer">
63
+ ${ this.isMessage() ? html`<button class="close" autofocus="autofocus">${translate('dialogs.close')}</button>` : html`
64
+ <button class="confirm" autofocus="autofocus">${translate('dialogs.yes')}</button>
65
+ <button class="reject" autofocus="autofocus">${translate('dialogs.no')}</button>
66
+ `}
70
67
  </div>
71
- </paper-dialog>
68
+ </pb-dialog>
72
69
  `;
73
70
  }
74
71
 
75
72
  firstUpdated() {
76
73
  // this.shadowRoot.getElementById('modal').open();
77
- this.modal = this.shadowRoot.getElementById('modal');
74
+ this.modal = this.renderRoot.querySelector('pb-dialog');
78
75
 
79
76
  }
80
77
 
81
- updated() {
82
- if (this.modal) {
83
- this.modal.notifyResize();
84
- }
85
- }
86
-
87
78
  /**
88
79
  * Open a modal dialog to display a message to the user.
89
80
  *
@@ -93,9 +84,18 @@ export class PbMessage extends LitElement {
93
84
  show(title, message) {
94
85
  this.type = 'message';
95
86
  this.set(title, message);
96
- this.modal.noCancelOnOutsideClick = false;
97
- this.modal.noCancelOnEscKey = false;
98
- this.modal.open();
87
+ this.modal.openDialog();
88
+
89
+ return new Promise((resolve, reject) => {
90
+ // Wait for the next render cycle to ensure elements are available
91
+ requestAnimationFrame(() => {
92
+ const close = this.renderRoot.querySelector('.close');
93
+ close.addEventListener('click', () => {
94
+ this.modal.closeDialog();
95
+ resolve({ once: true });
96
+ });
97
+ });
98
+ });
99
99
  }
100
100
 
101
101
  /**
@@ -110,14 +110,22 @@ export class PbMessage extends LitElement {
110
110
  confirm(title, message) {
111
111
  this.type = 'confirm';
112
112
  this.set(title, message);
113
- this.modal.noCancelOnOutsideClick = true;
114
- this.modal.noCancelOnEscKey = true;
115
- this.modal.open();
116
- const confirm = this.shadowRoot.getElementById('confirm');
117
- const cancel = this.shadowRoot.getElementById('reject');
113
+ this.modal.openDialog();
114
+
118
115
  return new Promise((resolve, reject) => {
119
- confirm.addEventListener('click', resolve, { once: true });
120
- cancel.addEventListener('click', reject, { once: true })
116
+ // Wait for the next render cycle to ensure elements are available
117
+ requestAnimationFrame(() => {
118
+ const confirm = this.renderRoot.querySelector('.confirm');
119
+ const cancel = this.renderRoot.querySelector('.reject');
120
+ confirm.addEventListener('click', () => {
121
+ this.modal.closeDialog();
122
+ resolve({ once: true });
123
+ });
124
+ cancel.addEventListener('click', () => {
125
+ this.modal.closeDialog();
126
+ reject({ once: true });
127
+ });
128
+ });
121
129
  });
122
130
  }
123
131
 
@@ -129,7 +137,6 @@ export class PbMessage extends LitElement {
129
137
  if (message) {
130
138
  this.message = message;
131
139
  }
132
- this.modal.notifyResize();
133
140
  }
134
141
  }
135
142
 
package/src/pb-page.js CHANGED
@@ -267,12 +267,11 @@ export class PbPage extends pbMixin(LitElement) {
267
267
  this.apiVersion = apiVersion;
268
268
  }
269
269
 
270
- const stylesheetURLs = [
271
- // TODO: replace with this.toAbsoluteURL
272
- this.toAbsoluteURL('resources/css/components.css', this.endpoint)
273
- ];
270
+ const stylesheetURLs = [];
274
271
  if (this.theme) {
275
272
  stylesheetURLs.push(this.toAbsoluteURL(this.theme, this.endpoint));
273
+ } else {
274
+ stylesheetURLs.push('components.css');
276
275
  }
277
276
  console.log('<pb-page> Loading component theme stylesheets from %s', stylesheetURLs.join(', '));
278
277
  this._themeSheet = await loadStylesheets(stylesheetURLs);
package/src/theming.js CHANGED
@@ -55,16 +55,10 @@ function loadResource(url) {
55
55
  * @returns {CSSStyleSheet|null} a new CSSStylesheet or null
56
56
  */
57
57
  export function importStyles(elem) {
58
- const page = document.querySelector('pb-page');
59
- if (!page) {
60
- return null;
61
- }
62
- const theme = page.stylesheet;
58
+ const theme = getThemeCSS();
63
59
  if (!theme) {
64
- // no component styles defined
65
60
  return null;
66
61
  }
67
-
68
62
  const selectors = getSelectors(elem).join('|');
69
63
  if (themeMap.has(selectors)) {
70
64
  return themeMap.get(selectors);
@@ -82,6 +76,19 @@ export function importStyles(elem) {
82
76
  return adoptedSheet;
83
77
  }
84
78
 
79
+ export function getThemeCSS() {
80
+ const page = document.querySelector('pb-page');
81
+ if (!page) {
82
+ return null;
83
+ }
84
+ const theme = page.stylesheet;
85
+ if (!theme) {
86
+ // no component styles defined
87
+ return null;
88
+ }
89
+ return theme;
90
+ }
91
+
85
92
  /**
86
93
  * Recursively copy matching styles from the theme CSS
87
94
  * to create a new CSS stylesheet having all styles required
@@ -140,7 +147,7 @@ export const themableMixin = (superclass) => class ThemableMixin extends supercl
140
147
  connectedCallback() {
141
148
  super.connectedCallback();
142
149
  waitOnce('pb-page-ready', (options) => {
143
- const theme = importStyles(this);
150
+ const theme = getThemeCSS();
144
151
  if (theme) {
145
152
  this.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, theme];
146
153
  }
@@ -1,23 +0,0 @@
1
- import{P as e,h as t,d as i}from"./paper-checkbox-4f410b1f.js";import"./paper-listbox-5f42cff5.js";
2
- /**
3
- @license
4
- Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5
- This code may only be used under the BSD style license found at
6
- http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
7
- http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
8
- found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
9
- part of the polymer project is also subject to an additional IP rights grant
10
- found at http://polymer.github.io/PATENTS.txt
11
- */e({_template:t`
12
- <style>
13
- :host {
14
- display: block;
15
- }
16
- </style>
17
-
18
- <!-- This form is used to collect the elements that should be submitted -->
19
- <slot></slot>
20
-
21
- <!-- This form is used for submission -->
22
- <form id="helper" action\$="[[action]]" method\$="[[method]]" enctype\$="[[enctype]]"></form>
23
- `,is:"iron-form",properties:{allowRedirect:{type:Boolean,value:!1},headers:{type:Object,value:function(){return{}}},withCredentials:{type:Boolean,value:!1}},attached:function(){this._form||(this._form=i(this).querySelector("form"),this._form?(this._init(),this.async(this._saveInitialValues.bind(this),1)):this._nodeObserver=i(this).observeNodes(function(e){for(var t=0;t<e.addedNodes.length;t++)"FORM"===e.addedNodes[t].tagName&&(this._form=e.addedNodes[t],this._init(),i(this).unobserveNodes(this._nodeObserver),this._nodeObserver=null)}.bind(this)))},detached:function(){this._nodeObserver&&(i(this).unobserveNodes(this._nodeObserver),this._nodeObserver=null)},_init:function(){this._form.addEventListener("submit",this.submit.bind(this)),this._form.addEventListener("reset",this.reset.bind(this)),this._defaults=this._defaults||new WeakMap,this._saveInitialValues()},saveResetValues:function(){this._saveInitialValues(!0)},_saveInitialValues:function(e){for(var t=this._getValidatableElements(),i=0;i<t.length;i++){var s=t[i];if(!this._defaults.has(s)||e){var r={value:s.value};"checked"in s&&(r.checked=s.checked),"invalid"in s&&(r.invalid=s.invalid),this._defaults.set(s,r)}}},validate:function(){if(!this._form)return!1;if(""===this._form.getAttribute("novalidate"))return!0;for(var e,t=this._form.checkValidity(),i=this._getValidatableElements(),s=0;e=i[s],s<i.length;s++){var r=e;r.validate&&(t=!!r.validate()&&t)}return t},submit:function(e){if(e&&e.preventDefault(),this._form)if(this.validate()){this.$.helper.textContent="";var t=this.serializeForm();if(this.allowRedirect){for(var i in t)this.$.helper.appendChild(this._createHiddenElement(i,t[i]));this.$.helper.action=this._form.getAttribute("action"),this.$.helper.method=this._form.getAttribute("method")||"GET",this.$.helper.contentType=this._form.getAttribute("enctype")||"application/x-www-form-urlencoded",this.$.helper.submit(),this.fire("iron-form-submit")}else this._makeAjaxRequest(t)}else this.fire("iron-form-invalid")},reset:function(e){if(e&&e.preventDefault(),this._form)if(e&&"reset"===e.type&&e.target===this._form){for(var t=this._getValidatableElements(),i=0;i<t.length;i++){var s=t[i];if(this._defaults.has(s)){var r=this._defaults.get(s);for(var n in r)s[n]=r[n]}}this.fire("iron-form-reset")}else this._form.reset()},serializeForm:function(){for(var e=this._getSubmittableElements(),t={},i=0;i<e.length;i++)for(var s=this._serializeElementValues(e[i]),r=0;r<s.length;r++)this._addSerializedElement(t,e[i].name,s[r]);return t},_handleFormResponse:function(e){this.fire("iron-form-response",e.detail)},_handleFormError:function(e){this.fire("iron-form-error",e.detail)},_makeAjaxRequest:function(e){this.request||(this.request=document.createElement("iron-ajax"),this.request.addEventListener("response",this._handleFormResponse.bind(this)),this.request.addEventListener("error",this._handleFormError.bind(this))),this.request.url=this._form.getAttribute("action"),this.request.method=this._form.getAttribute("method")||"GET",this.request.contentType=this._form.getAttribute("enctype")||"application/x-www-form-urlencoded",this.request.withCredentials=this.withCredentials,this.request.headers=this.headers,"POST"===this._form.method.toUpperCase()?this.request.body=e:this.request.params=e,this.fire("iron-form-presubmit",{},{cancelable:!0}).defaultPrevented||(this.request.generateRequest(),this.fire("iron-form-submit",e))},_getValidatableElements:function(){return this._findElements(this._form,!0,!1)},_getSubmittableElements:function(){return this._findElements(this._form,!1,!1)},_findElements:function(e,t,s,r){r=r||[];for(var n=i(e).querySelectorAll("*"),a=0;a<n.length;a++)s||"slot"!==n[a].localName&&"content"!==n[a].localName?this._searchSubmittable(r,n[a],t):this._searchSubmittableInSlot(r,n[a],t);return r},_searchSubmittableInSlot:function(e,t,s){for(var r=i(t).getDistributedNodes(),n=0;n<r.length;n++)if(r[n].nodeType!==Node.TEXT_NODE){this._searchSubmittable(e,r[n],s);for(var a=i(r[n]).querySelectorAll("*"),o=0;o<a.length;o++)this._searchSubmittable(e,a[o],s)}},_searchSubmittable:function(e,t,i){this._isSubmittable(t,i)?e.push(t):t.root&&this._findElements(t.root,i,!0,e)},_isSubmittable:function(e,t){return!e.disabled&&(t?e.name||"function"==typeof e.validate:e.name)},_serializeElementValues:function(e){var t=e.tagName.toLowerCase();return"button"===t||"input"===t&&("submit"===e.type||"reset"===e.type)?[]:"select"===t?this._serializeSelectValues(e):"input"===t?this._serializeInputValues(e):e._hasIronCheckedElementBehavior&&!e.checked?[]:[e.value]},_serializeSelectValues:function(e){for(var t=[],i=0;i<e.options.length;i++)e.options[i].selected&&t.push(e.options[i].value);return t},_serializeInputValues:function(e){var t=e.type.toLowerCase();return("checkbox"!==t&&"radio"!==t||e.checked)&&"file"!==t?[e.value]:[]},_createHiddenElement:function(e,t){var i=document.createElement("input");return i.setAttribute("type","hidden"),i.setAttribute("name",e),i.setAttribute("value",t),i},_addSerializedElement:function(e,t,i){void 0===e[t]?e[t]=i:(Array.isArray(e[t])||(e[t]=[e[t]]),e[t].push(i))}});