iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 5.48 kB
JavaScript
export const __rspack_esm_id=44619;export const __rspack_esm_ids=[44619];export const __webpack_modules__={84334(t,e,i){i.d(e,{H:()=>o,R:()=>s});const s=(t,e,i)=>t.subscribeMessage(t=>e(t),{type:"render_template",...i}),o=(t,e,i,s,o)=>t.connection.subscribeMessage(o,{type:"template/start_preview",flow_id:e,flow_type:i,user_input:s})},67334(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{HuiMarkdownCard:()=>w});var o=i(62826),n=i(5124),r=i(22441),a=i(6412),h=i(63672),c=i(30015),l=i.n(c),d=i(42372),_=i(1087),p=i(38962),u=(i(76776),i(3587),i(54276),i(84334)),g=i(996),m=i(19037),f=i(22064),v=i(97176),y=t([p]);p=(y.then?(await y)():y)[0];const b=new g.G(1e3);class w extends n.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(){return(0,v.h)(this._config?.tap_action)||(0,v.h)(this._config?.hold_action)||(0,v.h)(this._config?.double_tap_action)}setConfig(t){if(!t.content)throw new Error("Content required");this._config?.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();b.set(t,this._templateResult)}}willUpdate(t){if(super.willUpdate(t),this._config&&!this._templateResult){const t=this._computeCacheKey();b.has(t)&&(this._templateResult=b.get(t))}}render(){if(!this._config)return n.s6;const t=this._interactive?this._handleAction:void 0,e=this._interactive?(0,m.T)({hasHold:(0,v.h)(this._config.hold_action),hasDoubleClick:(0,v.h)(this._config.double_tap_action)}):void 0;return n.qy` ${this._error?n.qy` <ha-alert .alertType="${this._errorLevel?.toLowerCase()||"error"}"> ${this._error} </ha-alert> `:n.s6} <ha-card .header="${this._config.text_only?void 0:this._config.title}" class="${(0,a.H)({"with-header":!!this._config.title,"text-only":this._config.text_only??!1,action:this._interactive})}" tabindex="${(0,h.J)(this._interactive?"0":void 0)}" role="${(0,h.J)(this._interactive?"button":void 0)}" ="${t}" .actionHandler="${e}"> ${this._interactive?n.qy`<div class="background" ="${this._handleFocus}" ="${this._handleBlur}"> <ha-ripple></ha-ripple> </div>`:n.s6} <ha-markdown cache breaks .content="${this._templateResult?.result}"></ha-markdown> </ha-card> `}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"),s=t.get("_config");i&&s&&i.themes===this.hass.themes&&s.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,u.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}}w.styles=n.AH`: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,o.Cg)([(0,r.MZ)({attribute:!1})],w.prototype,"hass",void 0),(0,o.Cg)([(0,r.MZ)({type:Boolean})],w.prototype,"preview",void 0),(0,o.Cg)([(0,r.wk)()],w.prototype,"_config",void 0),(0,o.Cg)([(0,r.wk)()],w.prototype,"_error",void 0),(0,o.Cg)([(0,r.wk)()],w.prototype,"_errorLevel",void 0),(0,o.Cg)([(0,r.wk)()],w.prototype,"_templateResult",void 0),w=(0,o.Cg)([(0,r.EM)("hui-markdown-card")],w),s()}catch(t){s(t)}})}};