@teipublisher/pb-components 2.26.1-next.1 → 2.26.1-next.3

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,26 +1,13 @@
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
- import '@polymer/paper-button/paper-button';
1
+ import { LitElement, html } from 'lit-element';
5
2
  import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
6
3
  import { translate } from "./pb-i18n.js";
4
+ import { pbLightDom } from './pb-light-dom.js';
5
+ import './pb-dialog.js';
7
6
 
8
7
  /**
9
8
  * Show a dialog with buttons. Used by ODD editor.
10
9
  */
11
- export class PbMessage extends LitElement {
12
-
13
- static get styles() {
14
- return css`
15
- :host {
16
- display:block;
17
- }
18
-
19
- paper-dialog{
20
- min-width:300px;
21
- }
22
- `;
23
- }
10
+ export class PbMessage extends pbLightDom(LitElement) {
24
11
 
25
12
  static get properties() {
26
13
  return {
@@ -57,31 +44,21 @@ export class PbMessage extends LitElement {
57
44
 
58
45
  render() {
59
46
  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">
63
- ${ this.message ? unsafeHTML(this.message) : html`<slot></slot>` }
64
- </paper-dialog-scrollable>
65
-
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>
70
- </div>
71
- </paper-dialog>
47
+ <pb-dialog>
48
+ <h2 slot="title">${unsafeHTML(this.title)}</h2>
49
+ ${ this.message ? unsafeHTML(this.message) : null }
50
+
51
+ <button class="close" autofocus="autofocus" ?hidden="${this.isConfirm()}">${translate('dialogs.close')}</button>
52
+ <button class="confirm" autofocus="autofocus" ?hidden="${this.isMessage()}">${translate('dialogs.yes')}</button>
53
+ <button class="reject" autofocus="autofocus" ?hidden="${this.isMessage()}">${translate('dialogs.no')}</button>
54
+ </pb-dialog>
72
55
  `;
73
56
  }
74
57
 
75
58
  firstUpdated() {
76
59
  // this.shadowRoot.getElementById('modal').open();
77
- this.modal = this.shadowRoot.getElementById('modal');
78
-
79
- }
60
+ this.modal = this.renderRoot.querySelector('pb-dialog');
80
61
 
81
- updated() {
82
- if (this.modal) {
83
- this.modal.notifyResize();
84
- }
85
62
  }
86
63
 
87
64
  /**
@@ -92,10 +69,8 @@ export class PbMessage extends LitElement {
92
69
  */
93
70
  show(title, message) {
94
71
  this.type = 'message';
95
- this.set(title, message);
96
- this.modal.noCancelOnOutsideClick = false;
97
- this.modal.noCancelOnEscKey = false;
98
- this.modal.open();
72
+ this.set(`<h1>${title}</h1>`, `<p>${message}</p>`);
73
+ this.modal.openDialog();
99
74
  }
100
75
 
101
76
  /**
@@ -109,12 +84,10 @@ export class PbMessage extends LitElement {
109
84
  */
110
85
  confirm(title, message) {
111
86
  this.type = 'confirm';
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');
87
+ this.set(`<h1>${title}</h1>`, `<p>${message}</p>`);
88
+ this.modal.openDialog();
89
+ const confirm = this.renderRoot.querySelector('.confirm');
90
+ const cancel = this.renderRoot.querySelector('.reject');
118
91
  return new Promise((resolve, reject) => {
119
92
  confirm.addEventListener('click', resolve, { once: true });
120
93
  cancel.addEventListener('click', reject, { once: true })
@@ -125,11 +98,12 @@ export class PbMessage extends LitElement {
125
98
  if (title || message) {
126
99
  if (title) {
127
100
  this.title = title;
101
+ this.modal.title = this.title;
128
102
  }
129
103
  if (message) {
130
104
  this.message = message;
105
+ this.modal.message = this.message;
131
106
  }
132
- this.modal.notifyResize();
133
107
  }
134
108
  }
135
109
 
@@ -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))}});