UNPKG

1.65 kBJavaScriptView Raw
1import{html,render as litRender}from"../lit-html/lit-html.js";export const LitElement=t=>class extends t{static get observedAttributes(){let t=[];for(const e in this.properties)this.properties[e].reflectToAttribute&&t.push(e);return t}constructor(){super(),this.__data={},this.attachShadow({mode:"open"})}connectedCallback(){const t=this.constructor.properties;this._wait=!0;for(let e in t)"object"==typeof t[e]?this._makeComplexGetterSetter(e,t[e]):this._makeGetterSetter(e,t[e]);delete this._wait,litRender(this.render(),this.shadowRoot),this.afterFirstRender&&this.afterFirstRender()}_makeGetterSetter(t,e){Object.defineProperty(this,t,{get(){return this.__data[t]},set(e){this.__data[t]=e,this._propertiesChanged()}}),this[t]=this.getAttribute(t)}_makeComplexGetterSetter(t,e){Object.defineProperty(this,t,{get(){return e.reflectToAttribute&&(e.type!==Object&&e.type!==Array||console.warn("Rich Data shouldn't be set as attribte!")),this.__data[t]},set(r){e.reflectToAttribute?(e.type!==Object&&e.type!==Array||console.warn("Rich Data shouldn't be set as attribte!"),this.setAttribute(t,r)):this.__data[t]=r,this._propertiesChanged()}}),e.value&&("function"==typeof e.value?this[t]=e.value():this[t]=e.value)}_propertiesChanged(){this._wait||litRender(this.render(),this.shadowRoot)}attributeChangedCallback(t,e,r){if(this[t]!==r){const{type:e}=this.constructor.properties[t];"Boolean"===e.name?this.__data[t]="false"!==r&&this.hasAttribute(t):this.__data[t]=e(r),this._propertiesChanged()}}render(){return html`Render Function not defined`}get $(){const t=this.shadowRoot.querySelectorAll("[id]"),e={};for(const r of t)e[r.id]=r;return e}};
\No newline at end of file