iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 5.93 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[44619],{84334:function(t,e,i){i.d(e,{H:function(){return n},R:function(){return o}});const o=(t,e,i)=>t.subscribeMessage(t=>e(t),Object.assign({type:"render_template"},i)),n=(t,e,i,o,n)=>t.connection.subscribeMessage(n,{type:"template/start_preview",flow_id:e,flow_type:i,user_input:o})},67334:function(t,e,i){i.a(t,async function(t,o){try{i.r(e),i.d(e,{HuiMarkdownCard:function(){return $}});i(49255),i(16280),i(3362),i(62953);var n=i(40445),s=i(5124),r=i(67576),a=i(6412),h=i(63672),c=i(30015),l=i.n(c),d=i(42372),_=i(1087),u=i(38962),p=(i(76776),i(3587),i(54276),i(84334)),g=i(996),v=i(19037),f=i(22064),m=i(97176),y=t([u]);u=(y.then?(await y)():y)[0];let b,w,k,C,R=t=>t;const x=new g.G(1e3);class $ extends s.WF{static async getConfigElement(){return await i.e(90742).then(i.bind(i,4757)),document.createElement("hui-markdown-card-editor")}static getStubConfig(){return{type:"markdown",content:"The **Markdown** card allows you to write any text. You can style it **bold**, *italicized*, ~strikethrough~ etc. You can do images, links, and more.\n\nFor more information see the [Markdown Cheatsheet](https://commonmark.org/help)."}}getCardSize(){return void 0===this._config?3:void 0===this._config.card_size?Math.round(this._config.content.split("\n").length/2)+(this._config.title?1:0):this._config.card_size}get _interactive(){var t,e,i;return(0,m.h)(null===(t=this._config)||void 0===t?void 0:t.tap_action)||(0,m.h)(null===(e=this._config)||void 0===e?void 0:e.hold_action)||(0,m.h)(null===(i=this._config)||void 0===i?void 0:i.double_tap_action)}setConfig(t){var e;if(!t.content)throw new Error("Content required");(null===(e=this._config)||void 0===e?void 0:e.content)!==t.content&&this._tryDisconnect(),this._config=t}connectedCallback(){super.connectedCallback(),this._tryConnect()}_computeCacheKey(){return l()(this._config)}disconnectedCallback(){if(super.disconnectedCallback(),this._tryDisconnect(),this._config&&this._templateResult){const t=this._computeCacheKey();x.set(t,this._templateResult)}}willUpdate(t){if(super.willUpdate(t),this._config&&!this._templateResult){const t=this._computeCacheKey();x.has(t)&&(this._templateResult=x.get(t))}}render(){var t,e,i;if(!this._config)return s.s6;const o=this._interactive?this._handleAction:void 0,n=this._interactive?(0,v.T)({hasHold:(0,m.h)(this._config.hold_action),hasDoubleClick:(0,m.h)(this._config.double_tap_action)}):void 0;return(0,s.qy)(b||(b=R` ${0} <ha-card .header="${0}" class="${0}" tabindex="${0}" role="${0}" ="${0}" .actionHandler="${0}"> ${0} <ha-markdown cache breaks .content="${0}"></ha-markdown> </ha-card> `),this._error?(0,s.qy)(w||(w=R` <ha-alert .alertType="${0}"> ${0} </ha-alert> `),(null===(t=this._errorLevel)||void 0===t?void 0:t.toLowerCase())||"error",this._error):s.s6,this._config.text_only?void 0:this._config.title,(0,a.H)({"with-header":!!this._config.title,"text-only":null!==(e=this._config.text_only)&&void 0!==e&&e,action:this._interactive}),(0,h.J)(this._interactive?"0":void 0),(0,h.J)(this._interactive?"button":void 0),o,n,this._interactive?(0,s.qy)(k||(k=R`<div class="background" ="${0}" ="${0}"> <ha-ripple></ha-ripple> </div>`),this._handleFocus,this._handleBlur):s.s6,null===(i=this._templateResult)||void 0===i?void 0:i.result)}updated(t){if(super.updated(t),!this._config||!this.hass)return;t.has("_config")&&this._tryConnect();const e=!!this._templateResult&&!1===this._config.show_empty&&0===this._templateResult.result.length;e!==this.hidden&&(this.style.display=e?"none":"",this.toggleAttribute("hidden",e),(0,_.r)(this,"card-visibility-changed",{value:!e}));const i=t.get("hass"),o=t.get("_config");i&&o&&i.themes===this.hass.themes&&o.theme===this._config.theme||(0,d.Q)(this,this.hass.themes,this._config.theme)}async _tryConnect(){if(void 0===this._unsubRenderTemplate&&this.hass&&this._config){this._error=void 0,this._errorLevel=void 0;try{this._unsubRenderTemplate=(0,p.R)(this.hass.connection,t=>{"error"in t?"ERROR"!==t.level&&"ERROR"===this._errorLevel||(this._error=t.error,this._errorLevel=t.level):this._templateResult=t},{template:this._config.content,entity_ids:this._config.entity_id,variables:{config:this._config,user:this.hass.user.name},strict:!0,report_errors:this.preview}),await this._unsubRenderTemplate}catch(t){this.preview&&(this._error=t.message,this._errorLevel=void 0),this._templateResult={result:this._config.content,listeners:{all:!1,domains:[],entities:[],time:!1}},this._unsubRenderTemplate=void 0}}}async _tryDisconnect(){this._unsubRenderTemplate&&(this._unsubRenderTemplate.then(t=>t()).catch(),this._unsubRenderTemplate=void 0,this._error=void 0,this._errorLevel=void 0)}_handleAction(t){(0,f.$)(this,this.hass,this._config,t.detail.action)}_handleFocus(t){t.target.matches(":focus-visible")&&this.setAttribute("focused","")}_handleBlur(){this.removeAttribute("focused")}constructor(...t){super(...t),this.preview=!1}}$.styles=(0,s.AH)(C||(C=R`:host{-webkit-tap-highlight-color:transparent;--ha-ripple-hover-opacity:0.04;--ha-ripple-pressed-opacity:0.12}ha-card{height:100%;overflow-y:auto}.background{position:absolute;top:0;left:0;bottom:0;right:0}ha-alert{margin-bottom:8px}ha-markdown{padding:16px;word-wrap:break-word;text-align:var(--card-text-align,inherit)}.with-header ha-markdown{padding:0 16px 16px}.text-only{background:0 0;box-shadow:none;border:none}.text-only ha-markdown{padding:2px 4px}.action{cursor:pointer}`)),(0,n.Cg)([(0,r.MZ)({attribute:!1})],$.prototype,"hass",void 0),(0,n.Cg)([(0,r.MZ)({type:Boolean})],$.prototype,"preview",void 0),(0,n.Cg)([(0,r.wk)()],$.prototype,"_config",void 0),(0,n.Cg)([(0,r.wk)()],$.prototype,"_error",void 0),(0,n.Cg)([(0,r.wk)()],$.prototype,"_errorLevel",void 0),(0,n.Cg)([(0,r.wk)()],$.prototype,"_templateResult",void 0),$=(0,n.Cg)([(0,r.EM)("hui-markdown-card")],$),o()}catch(b){o(b)}})}}]);