c.7948d625.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import{_ as e,n as t,a as i,H as a,e as s,b as r,m as o,$ as l,o as c,c as d,s as n,d as h,r as u}from"./main-ad130be7.js";import"./c.82eccc94.js";import{s as p,S as f,a as m}from"./c.42d6aebd.js";import"./c.f1291e50.js";import"./c.9b92f489.js";import"./c.11ad1623.js";import{f as v}from"./c.3243a8b0.js";import{b as g}from"./c.0a1cf8d0.js";import"./c.a5f69ed4.js";import"./c.82e03b89.js";import"./c.8e28b461.js";import"./c.3f859915.js";import"./c.710a50fc.js";let y=class extends f{};y.styles=[p],y=e([t("mwc-select")],y);const _=["stars","last_updated","name"];let k=i([t("hacs-add-repository-dialog")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[s({attribute:!1})],key:"filters",value:()=>[]},{kind:"field",decorators:[s({type:Number})],key:"_load",value:()=>30},{kind:"field",decorators:[s({type:Number})],key:"_top",value:()=>0},{kind:"field",decorators:[s()],key:"_searchInput",value:()=>""},{kind:"field",decorators:[s()],key:"_sortBy",value:()=>_[0]},{kind:"field",decorators:[s()],key:"section",value:void 0},{kind:"method",key:"shouldUpdate",value:function(e){return e.forEach(((e,t)=>{"hass"===t&&(this.sidebarDocked='"docked"'===window.localStorage.getItem("dockedSidebar"))})),e.has("narrow")||e.has("filters")||e.has("active")||e.has("_searchInput")||e.has("_load")||e.has("_sortBy")}},{kind:"field",key:"_repositoriesInActiveCategory",value(){return(e,t)=>null==e?void 0:e.filter((e=>{var i,a;return!e.installed&&(null===(i=this.hacs.sections)||void 0===i||null===(a=i.find((e=>e.id===this.section)).categories)||void 0===a?void 0:a.includes(e.category))&&!e.installed&&(null==t?void 0:t.includes(e.category))}))}},{kind:"method",key:"firstUpdated",value:async function(){var e;if(this.addEventListener("filter-change",(e=>this._updateFilters(e))),0===(null===(e=this.filters)||void 0===e?void 0:e.length)){var t;const e=null===(t=r(this.hacs.language,this.route))||void 0===t?void 0:t.categories;null==e||e.filter((e=>{var t;return null===(t=this.hacs.info)||void 0===t?void 0:t.categories.includes(e)})).forEach((e=>{this.filters.push({id:e,value:e,checked:!0})})),this.requestUpdate("filters")}}},{kind:"method",key:"_updateFilters",value:function(e){const t=this.filters.find((t=>t.id===e.detail.id));this.filters.find((e=>e.id===t.id)).checked=!t.checked,this.requestUpdate("filters")}},{kind:"field",key:"_filterRepositories",value:()=>o(v)},{kind:"method",key:"render",value:function(){var e;if(!this.active)return l``;this._searchInput=window.localStorage.getItem("hacs-search")||"";let t=this._filterRepositories(this._repositoriesInActiveCategory(this.repositories,null===(e=this.hacs.info)||void 0===e?void 0:e.categories),this._searchInput);return 0!==this.filters.length&&(t=t.filter((e=>{var t;return null===(t=this.filters.find((t=>t.id===e.category)))||void 0===t?void 0:t.checked}))),l`
  2. <hacs-dialog
  3. .active=${this.active}
  4. .hass=${this.hass}
  5. .title=${this.hacs.localize("dialog_add_repo.title")}
  6. hideActions
  7. scrimClickAction
  8. maxWidth
  9. >
  10. <div class="searchandfilter" ?narrow=${this.narrow}>
  11. <search-input
  12. .hass=${this.hass}
  13. .label=${this.hacs.localize("search.placeholder")}
  14. .filter=${this._searchInput}
  15. @value-changed=${this._inputValueChanged}
  16. ?narrow=${this.narrow}
  17. ></search-input>
  18. <mwc-select
  19. ?narrow=${this.narrow}
  20. .label=${this.hacs.localize("dialog_add_repo.sort_by")}
  21. .value=${this._sortBy}
  22. @selected=${e=>this._sortBy=e.currentTarget.value}
  23. @closed=${m}
  24. >
  25. ${_.map((e=>l`<mwc-list-item .value=${e}>
  26. ${this.hacs.localize(`dialog_add_repo.sort_by_values.${e}`)||e}
  27. </mwc-list-item>`))}
  28. </mwc-select>
  29. </div>
  30. ${this.filters.length>1?l`<div class="filters">
  31. <hacs-filter .hacs=${this.hacs} .filters="${this.filters}"></hacs-filter>
  32. </div>`:""}
  33. <div class=${c({content:!0,narrow:this.narrow})} @scroll=${this._loadMore}>
  34. <mwc-list>
  35. ${0===t.length?l`<ha-alert>${this.hacs.localize("dialog_add_repo.no_match")}</ha-alert>`:t.sort(((e,t)=>"name"===this._sortBy?e.name.toLocaleLowerCase()<t.name.toLocaleLowerCase()?-1:1:e[this._sortBy]>t[this._sortBy]?-1:1)).slice(0,this._load).map((e=>l`<ha-clickable-list-item
  36. graphic=${this.narrow?"":"avatar"}
  37. twoline
  38. @click=${()=>this.active=!1}
  39. href="/hacs/repository/${e.id}"
  40. .hasMeta=${!this.narrow&&"integration"!==e.category}
  41. >
  42. ${this.narrow?"":"integration"===e.category?l`
  43. <img
  44. loading="lazy"
  45. .src=${g({domain:e.domain,darkOptimized:this.hass.themes.darkMode,type:"icon"})}
  46. referrerpolicy="no-referrer"
  47. @error=${this._onImageError}
  48. @load=${this._onImageLoad}
  49. slot="graphic"
  50. />
  51. `:l`
  52. <ha-svg-icon
  53. slot="graphic"
  54. path="${d}"
  55. style="padding-left: 0; height: 40px; width: 40px;"
  56. >
  57. </ha-svg-icon>
  58. `}
  59. <span>${e.name}</span>
  60. <span slot="secondary">${e.description}</span>
  61. <ha-chip slot="meta">
  62. ${this.hacs.localize(`common.${e.category}`)}
  63. </ha-chip>
  64. </ha-clickable-list-item>`))}
  65. </mwc-list>
  66. </div>
  67. </hacs-dialog>
  68. `}},{kind:"method",key:"_loadMore",value:function(e){const t=e.target.scrollTop;t>=this._top?this._load+=1:this._load-=1,this._top=t}},{kind:"method",key:"_inputValueChanged",value:function(e){this._searchInput=e.detail.value,window.localStorage.setItem("hacs-search",this._searchInput)}},{kind:"method",key:"_onImageLoad",value:function(e){e.target.style.visibility="initial"}},{kind:"method",key:"_onImageError",value:function(e){var t;if(null!==(t=e.target)&&void 0!==t&&t.outerHTML)try{e.target.outerHTML=`<ha-svg-icon path="${d}" slot="graphic"></ha-svg-icon>`}catch(e){}}},{kind:"get",static:!0,key:"styles",value:function(){return[n,h,u`
  69. .content {
  70. width: 100%;
  71. overflow: auto;
  72. max-height: 70vh;
  73. }
  74. .filter {
  75. margin-top: -12px;
  76. display: flex;
  77. width: 200px;
  78. float: right;
  79. }
  80. .list {
  81. margin-top: 16px;
  82. width: 1024px;
  83. max-width: 100%;
  84. }
  85. search-input {
  86. display: block;
  87. float: left;
  88. width: 75%;
  89. }
  90. search-input[narrow],
  91. mwc-select[narrow] {
  92. width: 100%;
  93. margin: 4px 0;
  94. }
  95. .filters {
  96. width: 100%;
  97. display: flex;
  98. }
  99. hacs-filter {
  100. width: 100%;
  101. margin-left: -32px;
  102. }
  103. .searchandfilter {
  104. display: flex;
  105. justify-content: space-between;
  106. align-items: self-end;
  107. }
  108. .searchandfilter[narrow] {
  109. flex-direction: column;
  110. }
  111. ha-chip {
  112. margin-left: -52px;
  113. }
  114. `]}}]}}),a);export{k as HacsAddRepositoryDialog};