pragma-views2
Version:
1 lines • 1.79 kB
JavaScript
import{addEventsFeatures,removeEventsFeatures}from"./mixin-events.js";import{addPropertyFeatures}from"./mixin-properties.js";import{getValueOnPath}from"./objectpath-helper.js";import{findParentOfInstance}from"./../../lib/dom-helper.js";import{addIntentionHelper,removeIntentionHelper}from"./mixin-intentions.js";import{status}from"../../lib/constants/statuses.js";export class BaseElement extends HTMLElement{constructor(){super(),addEventsFeatures(this),addIntentionHelper(this),addPropertyFeatures(this)}connectedCallback(){addEventsFeatures(this),addIntentionHelper(this),this.setRefProperty()}disconnectedCallback(){removeEventsFeatures(this),removeIntentionHelper(this)}get status(){return this.getProperty("status",(()=>(this.setAttribute("status",status.Loading),status.Loading)))}set status(t){this.setProperty("status",t,(()=>{this.setAttribute("status",t)}))}get visible(){return this._visible}set visible(t){this._visible=t,null!=t&&this.setVisible(t)}attributeChangedCallback(t,e,s){const i=`${t}Changed`;null!=this[i]&&this[i](s,e)}labelElements(t,e,s){const i=[];for(let r=0;r<t.length;r++)i.push({element:this.querySelector(t[r]),path:e[r],attribute:s[r]});for(let t of i){const e=getValueOnPath(globalThis.translations,t.path);"innertext"==t.attribute.toLowerCase()?t.element.innerText=e:t.element.setAttribute(t.attribute,e)}}onMessage(t){"setAttribute"==t.action&&this.setAttribute(t.attribute,t.value)}setRefProperty(){if(!0===this.hasAttribute("ref")){const t=findParentOfInstance(this,BaseElement);if(null!=t){const e=this.getAttribute("ref");t[e]=this;const s=`${e}Changed`;null!=t[s]&&t[s](this)}}}setVisible(t){if(!0===this.isBusy)return requestAnimationFrame((()=>this.setVisible(t)));!1===t?this.setAttribute("aria-hidden",!0):this.removeAttribute("aria-hidden")}}