iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 18.7 kB
JavaScript
/*! For license information please see 18377.85616daae8fab084.js.LICENSE.txt */
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[18377],{85938:function(e,t,i){i(18111),i(22489),i(3362),i(46058),i(62953);var o=i(40445),n=i(5124),s=i(67576),a=i(1087);let r,l=e=>e;class d extends n.WF{updated(e){e.has("disabled")&&(this.disabled?this._destroySortable():this._createSortable())}disconnectedCallback(){super.disconnectedCallback(),this._shouldBeDestroy=!0,setTimeout(()=>{this._shouldBeDestroy&&(this._destroySortable(),this._shouldBeDestroy=!1)},1)}connectedCallback(){super.connectedCallback(),this._shouldBeDestroy=!1,this.hasUpdated&&!this.disabled&&this._createSortable()}createRenderRoot(){return this}render(){return this.noStyle?n.s6:(0,n.qy)(r||(r=l` <style>.sortable-fallback{display:none!important}.sortable-ghost{box-shadow:0 0 0 2px var(--primary-color);background:rgba(var(--rgb-primary-color),.25);border-radius:var(--ha-border-radius-sm);opacity:.4}.sortable-drag{border-radius:var(--ha-border-radius-sm);opacity:1;background:var(--card-background-color);box-shadow:0px 4px 8px 3px #00000026;cursor:grabbing}</style> `))}async _createSortable(){if(this._sortable)return;const e=this.children[0];if(!e)return;const t=(await Promise.all([i.e(85283),i.e(70322)]).then(i.bind(i,80745))).default,o=Object.assign(Object.assign({scroll:!0,forceAutoScrollFallback:!0,scrollSpeed:20,animation:150},this.options),{},{onChoose:this._handleChoose,onStart:this._handleStart,onEnd:this._handleEnd,onUpdate:this._handleUpdate,onAdd:this._handleAdd,onRemove:this._handleRemove});this.draggableSelector&&(o.draggable=this.draggableSelector),this.handleSelector&&(o.handle=this.handleSelector),void 0!==this.invertSwap&&(o.invertSwap=this.invertSwap),this.group&&(o.group=this.group),this.filter&&(o.filter=this.filter),this._sortable=new t(e,o)}_destroySortable(){this._sortable&&(this._sortable.destroy(),this._sortable=void 0)}constructor(...e){super(...e),this.disabled=!1,this.noStyle=!1,this.invertSwap=!1,this.rollback=!0,this._shouldBeDestroy=!1,this._handleUpdate=e=>{(0,a.r)(this,"item-moved",{newIndex:e.newIndex,oldIndex:e.oldIndex})},this._handleAdd=e=>{(0,a.r)(this,"item-added",{index:e.newIndex,data:e.item.sortableData,item:e.item})},this._handleRemove=e=>{(0,a.r)(this,"item-removed",{index:e.oldIndex})},this._handleEnd=async e=>{(0,a.r)(this,"drag-end"),this.rollback&&e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder)},this._handleStart=()=>{(0,a.r)(this,"drag-start")},this._handleChoose=e=>{this.rollback&&(e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder))}}}(0,o.Cg)([(0,s.MZ)({type:Boolean})],d.prototype,"disabled",void 0),(0,o.Cg)([(0,s.MZ)({type:Boolean,attribute:"no-style"})],d.prototype,"noStyle",void 0),(0,o.Cg)([(0,s.MZ)({type:String,attribute:"draggable-selector"})],d.prototype,"draggableSelector",void 0),(0,o.Cg)([(0,s.MZ)({type:String,attribute:"handle-selector"})],d.prototype,"handleSelector",void 0),(0,o.Cg)([(0,s.MZ)({type:String,attribute:"filter"})],d.prototype,"filter",void 0),(0,o.Cg)([(0,s.MZ)({type:String})],d.prototype,"group",void 0),(0,o.Cg)([(0,s.MZ)({type:Boolean,attribute:"invert-swap"})],d.prototype,"invertSwap",void 0),(0,o.Cg)([(0,s.MZ)({attribute:!1})],d.prototype,"options",void 0),(0,o.Cg)([(0,s.MZ)({type:Boolean})],d.prototype,"rollback",void 0),d=(0,o.Cg)([(0,s.EM)("ha-sortable")],d)},48324:function(e,t,i){i.a(e,async function(e,o){try{i.d(t,{H:function(){return a}});i(3362);var n=i(82743),s=e([n]);n=(s.then?(await s)():s)[0];const a=async(e,t,i,o)=>{let s={type:t};"conditional"===t?s={type:t,conditions:[],elements:[]}:s.style={left:"50%",top:"50%"};const a=await(0,n.j)(t);if(a&&a.getStubConfig){const t=await a.getStubConfig(e,i,o);s=Object.assign(Object.assign({},s),t)}return s};o()}catch(a){o(a)}})},39039:function(e,t,i){i.d(t,{r:function(){return o}});i(16280);class o extends Error{constructor(e,t,i){super(e),this.name="GUISupportError",this.warnings=t,this.errors=i}}},91322:function(e,t,i){i.a(e,async function(e,o){try{i.d(t,{m:function(){return H}});i(18111),i(7588),i(61701),i(3362),i(62953);var n=i(40445),s=i(5124),a=i(67576),r=i(74985),l=i(1087),d=i(78978),h=i(19459),c=i(38962),u=i(65829),g=i(10763),p=i(39039),m=e([c,u,g]);[c,u,g]=m.then?(await m)():m;let v,_,f,y,b,C,E,w,$,x,S,M,k=e=>e;class H extends s.WF{get value(){return this._config}set value(e){this._config&&(0,h.b)(e,this._config,{compareSymbols:!0})||(this._config=e,this._errors=void 0,this._setConfig())}_setConfig(){if(!this._errors&&!this._yamlError)try{this._updateConfigElement()}catch(e){this._errors=[e.message]}this.updateComplete.then(()=>{var e;(0,l.r)(this,"config-changed",{config:this.value,error:null===(e=this._errors)||void 0===e?void 0:e.join(", "),guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})})}get hasWarning(){return void 0!==this._warnings&&this._warnings.length>0}get hasError(){return this._yamlError||void 0!==this._errors&&this._errors.length>0}get GUImode(){return this._guiMode}set GUImode(e){this._guiMode=e,this.updateComplete.then(()=>{(0,l.r)(this,"GUImode-changed",{guiMode:e,guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})})}toggleMode(){var e;this.GUImode||(null===(e=this._yamlEditor)||void 0===e||e.disableCodeEditorFullscreen());this.GUImode=!this.GUImode}focusYamlEditor(){var e;null!==(e=this._configElement)&&void 0!==e&&e.focusYamlEditor&&this._configElement.focusYamlEditor(),this._yamlEditor&&this._yamlEditor.focus()}async getConfigElement(){}async getConfigForm(){}renderConfigElement(){return(0,s.qy)(v||(v=k`${0}`),this._configElement)}_renderSubElement(){return(0,s.qy)(_||(_=k` <hui-sub-element-editor .hass="${0}" .config="${0}" -back="${0}" -changed="${0}"> </hui-sub-element-editor> `),this.hass,this._subElementEditorConfig,this._goBack,this._subElementChanged)}_subElementChanged(e){var t,i;e.stopPropagation();const o=e.detail.config;this._subElementEditorConfig=Object.assign(Object.assign({},this._subElementEditorConfig),{},{elementConfig:o}),null===(t=(i=this._subElementEditorConfig).saveElementConfig)||void 0===t||t.call(i,o)}_goBack(e){e.stopPropagation(),this._subElementEditorConfig=void 0}async _editSubElement(e){e.stopPropagation(),await Promise.all([i.e(92769),i.e(3283),i.e(80131),i.e(70183),i.e(67218),i.e(98470),i.e(99788),i.e(58303),i.e(21543),i.e(66283),i.e(46601),i.e(94956),i.e(26092),i.e(39005),i.e(8851),i.e(59704),i.e(25322),i.e(55392),i.e(71572),i.e(55076),i.e(36332),i.e(77563),i.e(15862),i.e(99143),i.e(97500),i.e(12009),i.e(66990),i.e(20282),i.e(87857),i.e(81804),i.e(92363),i.e(53387)]).then(i.bind(i,81287)),this._subElementEditorConfig={type:e.detail.type,elementConfig:e.detail.config,context:e.detail.context,saveElementConfig:e.detail.saveConfig}}render(){var e;return(0,s.qy)(f||(f=k` <div class="wrapper"> ${0} ${0} ${0} ${0} </div> `),this.GUImode?(0,s.qy)(y||(y=k` <div class="gui-editor" -sub-element="${0}"> ${0} </div> `),this._editSubElement,this._loading?(0,s.qy)(b||(b=k` <ha-spinner class="center margin-bot"></ha-spinner> `)):(0,r.P)(this._subElementEditorConfig?this._renderSubElement():this.renderConfigElement())):(0,s.qy)(C||(C=k` <div class="yaml-editor"> <ha-yaml-editor .defaultValue="${0}" autofocus .inDialog="${0}" -changed="${0}" ="${0}" dir="ltr"></ha-yaml-editor> </div> `),this._config,this.inDialog,this._handleYAMLChanged,this._ignoreKeydown),!1===this._guiSupported&&!1===this._loading?(0,s.qy)(E||(E=k` <ha-alert alert-type="info" .title="${0}"> ${0} <br> ${0} </ha-alert> `),this.hass.localize("ui.errors.config.visual_editor_not_supported"),this.hass.localize("ui.errors.config.visual_editor_not_supported_reason_type"),this.hass.localize("ui.errors.config.edit_in_yaml_supported")):s.s6,null!==(e=this._errors)&&void 0!==e&&e.length?(0,s.qy)(w||(w=k` <ha-alert alert-type="error" .title="${0}"> <ul> ${0} </ul> </ha-alert> `),this.hass.localize("ui.errors.config.configuration_error"),this._errors.map(e=>(0,s.qy)($||($=k`<li>${0}</li>`),e))):s.s6,this.hasWarning?(0,s.qy)(x||(x=k` <ha-alert alert-type="warning" .title="${0}"> <ul> ${0} </ul> ${0} </ha-alert> `),this.hass.localize("ui.errors.config.visual_editor_not_supported"),this._warnings.map(e=>(0,s.qy)(S||(S=k`<li>${0}</li>`),e)),this.hass.localize("ui.errors.config.edit_in_yaml_supported")):s.s6)}updated(e){super.updated(e),this._configElement&&e.has("hass")&&(this._configElement.hass=this.hass),this._configElement&&"lovelace"in this._configElement&&e.has("lovelace")&&(this._configElement.lovelace=this.lovelace),this._configElement&&e.has("context")&&(this._configElement.context=this.context)}_handleUIConfigChanged(e){if(e.stopPropagation(),!this.GUImode)return;const t=e.detail.config;Object.keys(t).forEach(e=>{void 0===t[e]&&delete t[e]}),this.value=t}_handleYAMLChanged(e){e.stopPropagation(),e.detail.isValid?(this._config=e.detail.value,this._errors=void 0,this._yamlError=!1):this._yamlError=!0,this._setConfig()}async unloadConfigElement(){this._configElement=void 0,this._guiSupported=void 0}async loadConfigElement(){if(this._configElement)return;let e=await this.getConfigElement();if(!e){const t=await this.getConfigForm();if(t){await i.e(15106).then(i.bind(i,15737)),e=document.createElement("hui-form-editor");const{schema:o,assertConfig:n,computeLabel:s,computeHelper:a}=t;e.schema=o,s&&(e.computeLabel=s),a&&(e.computeHelper=a),n&&(e.assertConfig=n)}}e?(e.hass=this.hass,"lovelace"in e&&(e.lovelace=this.lovelace),e.context=this.context,e.addEventListener("config-changed",e=>this._handleUIConfigChanged(e)),this._guiSupported=!0):this._guiSupported=!1,this._configElement=e}async _updateConfigElement(){if(!this.value)return;const e=++this._loadCount;try{if(this._errors=void 0,this._warnings=void 0,await this.loadConfigElement(),this._configElement)try{this._configElement.setConfig(this.value)}catch(i){const e=(0,d._)(this.hass,i);throw new p.r("Config is not supported",e.warnings,e.errors)}else this._guiSupported=!1,this.GUImode=!1}catch(i){if(e!==this._loadCount)return;var t;if(i instanceof p.r)this._warnings=null!==(t=i.warnings)&&void 0!==t?t:[i.message],this._errors=i.errors||void 0;else this._errors=[i.message];this.GUImode=!1}finally{this._loading=!1}}_ignoreKeydown(e){e.stopPropagation()}constructor(...e){super(...e),this.inDialog=!1,this._guiMode=!0,this._loading=!1,this._yamlError=!1,this._loadCount=0}}H.styles=(0,s.AH)(M||(M=k`:host{display:flex}.wrapper{width:100%}.gui-editor,.yaml-editor{padding:8px 0px}ha-code-editor{--code-mirror-max-height:calc(100vh - 245px)}ha-spinner{display:block;margin:auto}`)),(0,n.Cg)([(0,a.MZ)({attribute:!1})],H.prototype,"hass",void 0),(0,n.Cg)([(0,a.MZ)({attribute:!1})],H.prototype,"lovelace",void 0),(0,n.Cg)([(0,a.MZ)({attribute:!1})],H.prototype,"context",void 0),(0,n.Cg)([(0,a.MZ)({type:Boolean,attribute:"in-dialog"})],H.prototype,"inDialog",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_config",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_configElement",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_subElementEditorConfig",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_guiMode",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_errors",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_warnings",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_guiSupported",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_loading",void 0),(0,n.Cg)([(0,a.wk)()],H.prototype,"_yamlError",void 0),(0,n.Cg)([(0,a.P)("ha-yaml-editor")],H.prototype,"_yamlEditor",void 0),o()}catch(v){o(v)}})},37258:function(e,t,i){i.a(e,async function(e,t){try{i(18111),i(61701),i(3362),i(62953);var o=i(40445),n=i(34271),s=i(5124),a=i(67576),r=i(1087),l=i(18350),d=i(29823),h=(i(70947),i(26300)),c=(i(85938),i(67094),i(65063)),u=i(48324),g=e([l,d,h,u]);[l,d,h,u]=g.then?(await g)():g;let p,m,v,_,f,y=e=>e;const b="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z",C="M11,17H4A2,2 0 0,1 2,15V3A2,2 0 0,1 4,1H16V3H4V15H11V13L15,16L11,19V17M19,21V7H8V13H6V7A2,2 0 0,1 8,5H19A2,2 0 0,1 21,7V21A2,2 0 0,1 19,23H8A2,2 0 0,1 6,21V19H8V21H19Z",E="M21 11H3V9H21V11M21 13H3V15H21V13Z",w="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z",$="M3 16H10V14H3M18 14V10H16V14H12V16H16V20H18V16H22V14M14 6H3V8H14M14 10H3V12H14V10Z",x=["state-badge","state-icon","state-label","action-button","icon","image","conditional"];class S extends s.WF{render(){return this.elements&&this.hass?(0,s.qy)(p||(p=y` <h3> ${0} </h3> <div class="elements"> <ha-sortable handle-selector=".handle" -moved="${0}"> <div> ${0} </div> </ha-sortable> <ha-dropdown -select="${0}"> <ha-button size="small" slot="trigger" appearance="filled"> <ha-svg-icon slot="start" .path="${0}"></ha-svg-icon> ${0} </ha-button> ${0} </ha-dropdown> </div> `),this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.elements"),this._elementMoved,this.elements.map((e,t)=>{var i;return(0,s.qy)(m||(m=y` <div class="element"> <div class="handle"> <ha-svg-icon .path="${0}"></ha-svg-icon> </div> ${0} <ha-icon-button .label="${0}" .path="${0}" class="remove-icon" .index="${0}" ="${0}"></ha-icon-button> <ha-icon-button .label="${0}" .path="${0}" class="edit-icon" .index="${0}" ="${0}"></ha-icon-button> <ha-icon-button .label="${0}" .path="${0}" class="duplicate-icon" .index="${0}" ="${0}"></ha-icon-button> </div> `),E,e.type?(0,s.qy)(v||(v=y` <div class="element-row"> <div> <span> ${0} </span> <span class="secondary">${0}</span> </div> </div> `),(null===(i=this.hass)||void 0===i?void 0:i.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${e.type}`))||e.type,this._getSecondaryDescription(e)):s.s6,this.hass.localize("ui.common.delete"),b,t,this._removeRow,this.hass.localize("ui.common.edit"),w,t,this._editRow,this.hass.localize("ui.common.duplicate"),C,t,this._duplicateRow)}),this._addElement,$,this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.new_element"),x.map(e=>{var t;return(0,s.qy)(_||(_=y` <ha-dropdown-item .value="${0}"> ${0} </ha-dropdown-item> `),e,(null===(t=this.hass)||void 0===t?void 0:t.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${e}`))||e)})):s.s6}_getSecondaryDescription(e){var t,i,o,n,s,a,r,l,d,h;switch(e.type){case"icon":return null!==(t=null!==(i=e.title)&&void 0!==i?i:e.icon)&&void 0!==t?t:"";case"state-badge":case"state-icon":case"state-label":return null!==(o=null!==(n=e.title)&&void 0!==n?n:e.entity)&&void 0!==o?o:"";case"action-button":case"service-button":return null!==(s=null!==(a=null!==(r=e.title)&&void 0!==r?r:e.action)&&void 0!==a?a:e.service)&&void 0!==s?s:"";case"image":{if(e.title)return e.title;const t=e;var c;return t.image?"string"==typeof t.image?t.image:(null===(c=t.image.metadata)||void 0===c?void 0:c.title)||t.image.media_content_id||"":t.camera_image||""}case"conditional":return null!==(l=e.title)&&void 0!==l?l:`${(e.elements||[]).length.toString()} ${null===(d=this.hass)||void 0===d?void 0:d.localize("ui.panel.lovelace.editor.card.picture-elements.elements")}`}return null!==(h=e.title)&&void 0!==h?h:"Unknown type"}async _addElement(e){const t=e.detail.item.value;if(""===t)return;const i=this.elements.concat(await(0,u.H)(this.hass,t,Object.keys(this.hass.entities),[]));(0,r.r)(this,"elements-changed",{elements:i})}_elementMoved(e){e.stopPropagation();const{oldIndex:t,newIndex:i}=e.detail,o=this.elements.concat();o.splice(i,0,o.splice(t,1)[0]),(0,r.r)(this,"elements-changed",{elements:o})}_removeRow(e){var t;const i=e.currentTarget.index,o=null===(t=this.elements)||void 0===t?void 0:t[i];o&&(0,c.dk)(this,{text:this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.confirm_delete_element",{type:this.hass.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${o.type}`)||o.type}),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{const e=this.elements.concat();e.splice(i,1),(0,r.r)(this,"elements-changed",{elements:e})}})}_editRow(e){const t=e.currentTarget.index;(0,r.r)(this,"edit-detail-element",{subElementConfig:{index:t,type:"element",elementConfig:this.elements[t]}})}_duplicateRow(e){const t=e.currentTarget.index,i=[...this.elements,(0,n.A)(this.elements[t])];(0,r.r)(this,"elements-changed",{elements:i})}}S.styles=(0,s.AH)(f||(f=y`.element{display:flex;align-items:center}.handle{padding-right:var(--ha-space-2);cursor:move;cursor:grab;padding-inline-end:var(--ha-space-2);padding-inline-start:initial;direction:var(--direction)}.handle>*{pointer-events:none}.element-row{height:60px;font-size:var(--ha-font-size-l);display:flex;align-items:center;justify-content:space-between;flex-grow:1}.element-row div{display:flex;flex-direction:column}.duplicate-icon,.edit-icon,.remove-icon{--ha-icon-button-size:36px;color:var(--secondary-text-color)}.secondary{font-size:var(--ha-font-size-s);color:var(--secondary-text-color)}`)),(0,o.Cg)([(0,a.MZ)({attribute:!1})],S.prototype,"hass",void 0),(0,o.Cg)([(0,a.MZ)({attribute:!1})],S.prototype,"elements",void 0),S=(0,o.Cg)([(0,a.EM)("hui-picture-elements-card-row-editor")],S),t()}catch(p){t(p)}})},63277:function(e,t,i){i.a(e,async function(e,o){try{i.d(t,{U:function(){return l}});i(16280),i(3362);var n=i(40445),s=i(67576),a=i(91322),r=e([a]);a=(r.then?(await r)():r)[0];class l extends a.m{get configElementType(){return this.value?this.value.type:void 0}async loadConfigElement(){if(this._configElementType!==this.configElementType){if(this.unloadConfigElement(),!this.configElementType)throw new Error(this.hass.localize("ui.errors.config.no_type_provided"));this._configElementType=this.configElementType}return super.loadConfigElement()}}(0,n.Cg)([(0,s.wk)()],l.prototype,"_configElementType",void 0),o()}catch(l){o(l)}})},74985:function(e,t,i){i.d(t,{P:function(){return r}});i(88454),i(29452),i(62953);var o=i(5055),n=i(42017),s=i(63937);const a=e=>(0,s.ps)(e)?e._$litType$.h:e.strings,r=(0,n.u$)(class extends n.WL{render(e){return[e]}update(e,[t]){const i=(0,s.qb)(this.it)?a(this.it):null,n=(0,s.qb)(t)?a(t):null;if(null!==i&&(null===n||i!==n)){const t=(0,s.cN)(e).pop();let n=this.et.get(i);if(void 0===n){const e=document.createDocumentFragment();n=(0,o.XX)(o.s6,e),n.setConnected(!1),this.et.set(i,n)}(0,s.mY)(n,[t]),(0,s.Dx)(n,void 0,t)}if(null!==n){if(null===i||i!==n){const t=this.et.get(n);if(void 0!==t){const i=(0,s.cN)(t).pop();(0,s.Jz)(e),(0,s.Dx)(e,void 0,i),(0,s.mY)(e,[i])}}this.it=t}else this.it=void 0;return this.render(t)}constructor(e){super(e),this.et=new WeakMap}})}}]);