iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 3.92 kB
JavaScript
export const __rspack_esm_id=24837;export const __rspack_esm_ids=[24837];export const __webpack_modules__={25995(e,t,s){s.d(t,{Vw:()=>a,kG:()=>o,y6:()=>r});const n=(e,t,s)=>new Promise((n,r)=>{const o=document.createElement(e);let a="src",i="body";switch(o.onload=()=>n(t),o.onerror=()=>r(t),e){case"script":o.async=!0,s&&(o.type=s);break;case"link":o.type="text/css",o.rel="stylesheet",a="href",i="head"}o[a]=t,document[i].appendChild(o)}),r=e=>n("link",e),o=e=>n("script",e),a=e=>n("script",e,"module")},45796(e,t,s){s.r(t),s.d(t,{HaPanelCustom:()=>p});s(74423);var n=s(62826),r=s(5124),o=s(22441),a=s(91926),i=s(19459);var l=s(25995);const c={},h=e=>e.html_url?{type:"html",url:e.html_url}:e.module_url&&e.js_url||e.module_url?{type:"module",url:e.module_url}:{type:"js",url:e.js_url};s(18111),s(7588);const u=(e,t)=>{"setProperties"in e?e.setProperties(t):Object.keys(t).forEach(s=>{e[s]=t[s]})};class p extends r.mN{createRenderRoot(){return this}registerIframe(e,t){e(this.panel,{hass:this.hass,narrow:this.narrow,route:this.route}),this._setProperties=t,this.querySelector("iframe")?.classList.add("loaded")}connectedCallback(){super.connectedCallback(),this._wasDisconnected&&this.panel&&(this._wasDisconnected=!1,this._createPanel(this.panel))}disconnectedCallback(){super.disconnectedCallback(),this._wasDisconnected=!0,this._cleanupPanel()}update(e){if(super.update(e),e.has("panel")){const t=e.get("panel");if(!(0,i.b)(t,this.panel))return t&&this._cleanupPanel(),void this._createPanel(this.panel)}if(!this._setProperties)return;const t={};for(const s of e.keys())t[s]=this[s];this._setProperties(t)}_cleanupPanel(){for(delete window.customPanel,this._setProperties=void 0;this.lastChild;)this.removeChild(this.lastChild)}_createPanel(e){this.style.backgroundColor="var(--primary-background-color)";const t=e.config._panel_custom,s=h(t),n=document.createElement("a");if(n.href=s.url,!t.trust_external&&!["localhost","127.0.0.1",location.hostname].includes(n.hostname)&&!confirm(`${this.hass.localize("ui.panel.custom.external_panel.question_trust",{name:t.name,link:n.href})}\n\n ${this.hass.localize("ui.panel.custom.external_panel.complete_access")}\n\n (${this.hass.localize("ui.panel.custom.external_panel.hide_message")})`))return;if(!t.embed_iframe)return void(e=>{const t=h(e);return"js"===t.type?(t.url in c||(c[t.url]=(0,l.kG)(t.url)),c[t.url]):"module"===t.type?(0,l.Vw)(t.url):Promise.reject("No valid url found in panel config.")})(t).then(()=>{if(!this.isConnected||this._setProperties)return;const s=(e=>{const t="html_url"in e?`ha-panel-${e.name}`:e.name;return document.createElement(t)})(t);this._setProperties=e=>u(s,e),u(s,{panel:e,hass:this.hass,narrow:this.narrow,route:this.route}),this.appendChild(s)},()=>{alert(`Unable to load custom panel from ${n.href}`)});window.customPanel=this;const r=this.panel.title?`title="${this.panel.title}"`:"";this.innerHTML=`\n <style>\n iframe {\n border: none;\n width: 100%;\n height: 100vh;\n height: 100dvh;\n display: block;\n background-color: var(--primary-background-color);\n opacity: 0;\n transition: opacity var(--ha-animation-duration-normal) ease;\n }\n iframe.loaded {\n opacity: 1;\n }\n </style>\n <iframe ${r}></iframe>`.trim();const o=this.querySelector("iframe").contentWindow.document;o.open(),o.write(`<!doctype html><script src='${window.customPanelJS}'><\/script>`),o.close()}constructor(...e){super(...e),this.narrow=!1,this._wasDisconnected=!1,this.navigate=(e,t)=>(0,a.oo)(e,t)}}(0,n.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"hass",void 0),(0,n.Cg)([(0,o.MZ)({type:Boolean})],p.prototype,"narrow",void 0),(0,n.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"route",void 0),(0,n.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"panel",void 0),p=(0,n.Cg)([(0,o.EM)("ha-panel-custom")],p)}};