iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 4.1 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[24837],{25995:function(e,t,n){n.d(t,{Vw:function(){return a},kG:function(){return o},y6:function(){return r}});n(3362);const s=(e,t,n)=>new Promise((s,r)=>{const o=document.createElement(e);let a="src",i="body";switch(o.onload=()=>s(t),o.onerror=()=>r(t),e){case"script":o.async=!0,n&&(o.type=n);break;case"link":o.type="text/css",o.rel="stylesheet",a="href",i="head"}o[a]=t,document[i].appendChild(o)}),r=e=>s("link",e),o=e=>s("script",e),a=e=>s("script",e,"module")},45796:function(e,t,n){n.r(t),n.d(t,{HaPanelCustom:function(){return p}});n(74423),n(42762),n(62953);var s=n(40445),r=n(5124),o=n(67576),a=n(91926),i=n(19459);n(3362);var l=n(25995);const c={},u=e=>e.html_url?{type:"html",url:e.html_url}:e.module_url&&e.js_url?{type:"js",url:e.js_url}:e.module_url?{type:"module",url:e.module_url}:{type:"js",url:e.js_url};n(18111),n(7588);const h=(e,t)=>{"setProperties"in e?e.setProperties(t):Object.keys(t).forEach(n=>{e[n]=t[n]})};class p extends r.mN{createRenderRoot(){return this}registerIframe(e,t){var n;e(this.panel,{hass:this.hass,narrow:this.narrow,route:this.route}),this._setProperties=t,null===(n=this.querySelector("iframe"))||void 0===n||n.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 n of e.keys())t[n]=this[n];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,n=u(t),s=document.createElement("a");if(s.href=n.url,!t.trust_external&&!["localhost","127.0.0.1",location.hostname].includes(s.hostname)&&!confirm(`${this.hass.localize("ui.panel.custom.external_panel.question_trust",{name:t.name,link:s.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=u(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 n=(e=>{const t="html_url"in e?`ha-panel-${e.name}`:e.name;return document.createElement(t)})(t);this._setProperties=e=>h(n,e),h(n,{panel:e,hass:this.hass,narrow:this.narrow,route:this.route}),this.appendChild(n)},()=>{alert(`Unable to load custom panel from ${s.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,s.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean})],p.prototype,"narrow",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"route",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],p.prototype,"panel",void 0),p=(0,s.Cg)([(0,o.EM)("ha-panel-custom")],p)}}]);