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