smart-webcomponents
Version:
Web Components & Custom Elements for Professional Web Applications
2 lines • 3.87 kB
JavaScript
/*! For license information please see smart.ui.listitemsgroup.js.LICENSE.txt */
(()=>{"use strict";class e extends HTMLElement{get _isUpdating(){return this.nativeElement?this.nativeElement._isUpdating:void 0}set _isUpdating(e){this.nativeElement&&(this.nativeElement._isUpdating=e)}get label(){return this.nativeElement?this.nativeElement.label:void 0}set label(e){if(this.nativeElement){this.nativeElement.label=e,this._isUpdatingAttribute=!0;const t=this.nativeElement.getAttribute("label");this.nativeElement.hasAttribute("label")?this.setAttribute("label",t):this.removeAttribute("label"),this._isUpdatingAttribute=!1}}static get observedAttributes(){return["style","class","label"]}get properties(){return["label"]}constructor(){super()}get eventListeners(){return[]}componentDidRender(e){const t=this,n={},s={};let i=null;for(let e in t.props)"children"!==e&&("style"!==e?e.startsWith("on")&&-1===t.properties.indexOf(e)?s[e]=t.props[e]:n[e]=t.props[e]:i=t.props[e]);for(let e in t.attributes){const n=t.attributes[e].name;if(n)if("class"!==n)"style"===n&&t.nativeElement.setAttribute(n,t.getAttribute(n)),-1!==t.properties.indexOf(n.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()})))&&t.nativeElement.setAttribute(n,t.getAttribute(n));else{const e=t.getAttribute(n).trim().split(" ");for(let n in e)t.nativeElement.classList.contains(e[n])||""===e[n]||t.nativeElement.classList.add(e[n])}}for(let e in n)if("class"!==e&&"className"!==e){if(n[e]!==t.nativeElement[e]){const s=e=>e.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}));"hover"!==e&&"active"!==e&&"focus"!==e&&"selected"!==e||t.nativeElement.setAttribute(e,"");const i=s(e);t.nativeElement[i]=n[e]}}else{const s=n[e].trim().split(" ");for(let e in s)t.nativeElement.classList.contains(s[e])||""===s[e]||t.nativeElement.classList.add(s[e])}for(let e in s)t[e]=s[e],t.nativeElement[e.toLowerCase()]=s[e];if(i)for(let e in i)t.nativeElement.style[e]=i[e]}componentDidMount(){this.componentDidRender(!0)}componentDidUpdate(){this.componentDidRender(!1)}componentWillUnmount(){const e=this;if(e.nativeElement){e.nativeElement.whenRenderedCallbacks=[];for(let t=0;t<e.eventListeners.length;t++){const n=e.eventListeners[t];e.nativeElement.removeEventListener(n.substring(2).toLowerCase(),e[n])}}}connectedCallback(){this.shadowRoot||this._render()}disconnectedCallback(){this.componentWillUnmount()}addStylesToElement(e,t){const n=document.createElement("style");n.type="text/css";for(let e=0;e<t.length;e++){let s=document.createTextNode(t[e]);s.textContent=s.textContent.replace(":root",":host"),n.appendChild(s)}if(document.adoptedStyleSheets){const t=new CSSStyleSheet;t.replaceSync(n.innerHTML),e.adoptedStyleSheets?e.adoptedStyleSheets=[...e.adoptedStyleSheets,t]:-1===document.adoptedStyleSheets.indexOf(t)&&(document.adoptedStyleSheets=[...document.adoptedStyleSheets,t])}else e.appendChild(n)}addStyle(e){const t=this.shadowRoot;if("string"==typeof e){const n=document.createElement("style");n.type="text/css";const s=document.createTextNode(e);n.appendChild(s),t.appendChild(n)}else t.appendChild(e)}attributeChangedCallback(e,t,n){const s=this;if(s.shadowRoot&&s.isReady&&!s._isUpdatingAttribute)if("class"!==e)s.nativeElement.setAttribute(e,n);else{const e=n.trim().split(" "),i=t.trim().split(" ");for(let e in i)""!==i[e]&&s.nativeElement.classList.remove(i[e]);for(let t in e)s.nativeElement.classList.contains(e[t])||""===e[t]||s.nativeElement.classList.add(e[t])}}_render(){const e=this;if(e.parentNode){const t=document.createElement("smart-list-items-group");e.parentNode?e.parentNode.replaceChild(t,e):e.getRootNode().host.shadowRoot.replaceChild(t,e),e.nativeElement=t,e.componentDidMount(),e.isReady=!0,e.classList.add("smart-ui-component")}}}window.customElements.get("smart-ui-list-items-group")||window.customElements.define("smart-ui-list-items-group",e)})();