home-assistant-query-selector 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,24 +39,25 @@ instance.addEventListener('onLovelacePanelLoad', ({ detail }) => {
39
39
  });
40
40
 
41
41
  // When the sidebar is available in the DOM
42
- HA_SIDEBAR.then((sidebar) => {
43
- // Do whatever we want with the sidebar
44
- });
42
+ HA_SIDEBAR.element
43
+ then((sidebar) => {
44
+ // Do whatever we want with the sidebar
45
+ });
45
46
 
46
47
  // Querying the ha-sidebar element from the home-assistant element
47
- HOME_ASSISTANT.querySelector('$ home-assistant-main$ ha-sidebar')
48
+ HOME_ASSISTANT.selector.$['home-assistant-main'].$['ha-sidebar'].element
48
49
  .then((sidebar) => {
49
50
  // sidebar === ha-sidebar element
50
51
  });
51
52
 
52
53
  // Querying all the ha-icon-button elements inside the .action-items in the header
53
- HEADER.querySelectorAll('.action-items ha-icon-button')
54
+ HEADER.selector['.action-items ha-icon-button'].all
54
55
  .then((buttons) => {
55
56
  // buttons === Search, Assist, and Open dashboard menu elements (top-right header buttons)
56
57
  });
57
58
 
58
- // In all the methods one can Specify custom retries and delay
59
- HA_PANEL_LOVELACE.shadowRootQuerySelector('$ hui-root$', { retries: 50, delay: 20 })
59
+ // Querying the hui-root shadowRoot
60
+ HA_PANEL_LOVELACE.selector.$['hui-root'].$.element
60
61
  .then((shadowRoot) => {
61
62
  // shadowRoot === hui-root‘s shadowRoot
62
63
  });
@@ -170,14 +171,12 @@ This is the list of the elements available inside the `detail` property of the `
170
171
  | `HEADER` | `.header` |
171
172
  | `HUI_VIEW` | `hui-view` |
172
173
 
173
- All the available elements contain an `element` property and three methods:
174
+ All the available elements contain an `element` property and the `selector` property:
174
175
 
175
- | Property or method | Description |
176
- | ------------------------- | ------------------------------------------------------------ |
177
- | `element` | Promise that resolves in the respective `DOM` element |
178
- | `querySelector` | Method to query for descendants of this element |
179
- | `querySelectorAll` | Method to query multiple decendants of this element |
180
- | `shadowRootQuerySelector` | Method to query for descendants shadowRoots of this element |
176
+ | Property or method | Description |
177
+ | ------------------------- | --------------------------------------------------------------- |
178
+ | `element` | Promise that resolves in the respective `DOM` element |
179
+ | `selector` | Object that allows one to query for elements using dot notation |
181
180
 
182
181
  #### onLovelaceMoreInfoDialogOpen
183
182
 
@@ -213,12 +212,10 @@ This is the list of the elements available inside the `detail` property of the `
213
212
 
214
213
  All the available elements contain an `element` property and three methods:
215
214
 
216
- | Property or method | Description |
217
- | ------------------------- | ------------------------------------------------------------ |
218
- | `element` | Promise that resolves in the respective `DOM` element |
219
- | `querySelector` | Method to query for descendants of this element |
220
- | `querySelectorAll` | Method to query multiple decendants of this element |
221
- | `shadowRootQuerySelector` | Method to query for descendants shadowRoots of this element |
215
+ | Property or method | Description |
216
+ | ------------------------- | --------------------------------------------------------------- |
217
+ | `element` | Promise that resolves in the respective `DOM` element |
218
+ | `selector` | Object that allows one to query for elements using dot notation |
222
219
 
223
220
  #### onLovelaceHistoryAndLogBookDialogOpen
224
221
 
@@ -254,12 +251,10 @@ This is the list of the elements available inside the `detail` property of the `
254
251
 
255
252
  All the available elements contain an `element` property and three methods:
256
253
 
257
- | Property or method | Description |
258
- | ------------------------- | ------------------------------------------------------------ |
259
- | `element` | Promise that resolves in the respective `DOM` element |
260
- | `querySelector` | Method to query for descendants of this element |
261
- | `querySelectorAll` | Method to query multiple decendants of this element |
262
- | `shadowRootQuerySelector` | Method to query for descendants shadowRoots of this element |
254
+ | Property or method | Description |
255
+ | ------------------------- | --------------------------------------------------------------- |
256
+ | `element` | Promise that resolves in the respective `DOM` element |
257
+ | `selector` | Object that allows one to query for elements using dot notation |
263
258
 
264
259
  #### onLovelaceSettingsDialogOpen
265
260
 
@@ -295,16 +290,14 @@ This is the list of the elements available inside the `detail` property of the `
295
290
 
296
291
  All the available elements contain an `element` property and three methods:
297
292
 
298
- | Property or method | Description |
299
- | ------------------------- | ------------------------------------------------------------ |
300
- | `element` | Promise that resolves in the respective `DOM` element |
301
- | `querySelector` | Method to query for descendants of this element |
302
- | `querySelectorAll` | Method to query multiple decendants of this element |
303
- | `shadowRootQuerySelector` | Method to query for descendants shadowRoots of this element |
293
+ | Property or method | Description |
294
+ | ------------------------- | --------------------------------------------------------------- |
295
+ | `element` | Promise that resolves in the respective `DOM` element |
296
+ | `selector` | Object that allows one to query for elements using dot notation |
304
297
 
305
298
  ### Note
306
299
 
307
- >`querySelector`, `querySelectorAll` and `shadowRootQuerySelector` methods used in the library sue behind the secenes the [asyncQuerySelector], [asyncQuerySelectorAll] and [asyncShadowRootQuerySelector] functions from [shadow-dom-selector], which is highly inspired in the query philosophy of [lovelace-card-mod].
300
+ >The `selector` property used in the library uses behind the secenes the [buildAsyncSelector] utility from [shadow-dom-selector], which is highly inspired in the query philosophy of [lovelace-card-mod].
308
301
 
309
302
 
310
303
  [Home Assistant]: https://www.home-assistant.io
@@ -313,8 +306,6 @@ All the available elements contain an `element` property and three methods:
313
306
  [ShadowDOM]: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM
314
307
  [EventTarget]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
315
308
  [CustomEvent]: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
316
- [asyncQuerySelector]: https://github.com/elchininet/shadow-dom-selector#asyncqueryselector
317
- [asyncQuerySelectorAll]: https://github.com/elchininet/shadow-dom-selector#asyncqueryselectorall
318
- [asyncShadowRootQuerySelector]: https://github.com/elchininet/shadow-dom-selector#asyncshadowrootqueryselector
309
+ [buildAsyncSelector]: https://github.com/elchininet/shadow-dom-selector#buildasyncselector
319
310
  [shadow-dom-selector]: https://github.com/elchininet/shadow-dom-selector
320
311
  [lovelace-card-mod]: https://github.com/thomasloven/lovelace-card-mod
@@ -1,7 +1,5 @@
1
- type HAQuerySelectorConfig = {
2
- retries?: number;
3
- delay?: number;
4
- };
1
+ import { AsyncSelectorProxy, AsyncParams } from "shadow-dom-selector";
2
+ type HAQuerySelectorConfig = AsyncParams;
5
3
  type NodeDescriptorProps = {
6
4
  selector: string;
7
5
  children?: HomeAssistantNodeDescriptor;
@@ -12,9 +10,7 @@ type HomeAssistantNodeDescriptor = {
12
10
  type ElementProps = {
13
11
  element: Promise<Element | null>;
14
12
  children?: HomeAssistantElement;
15
- querySelector: <E extends Element = Element>(selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<E | null>;
16
- querySelectorAll: <E extends Element = Element>(selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<NodeListOf<E>>;
17
- shadowRootQuerySelector: (selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<ShadowRoot | null>;
13
+ selector: AsyncSelectorProxy;
18
14
  };
19
15
  type HomeAssistantElement = {
20
16
  [key: string]: ElementProps;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{asyncQuerySelector as e,asyncQuerySelectorAll as t,asyncShadowRootQuerySelector as O}from"shadow-dom-selector";function i(e,t,O,i){return new(O||(O=Promise))((function(s,_){function o(e){try{A(i.next(e))}catch(e){_(e)}}function n(e){try{A(i.throw(e))}catch(e){_(e)}}function A(e){var t;e.done?s(e.value):(t=e.value,t instanceof O?t:new O((function(e){e(t)}))).then(o,n)}A((i=i.apply(e,t||[])).next())}))}function s(e,t,O,i){if("a"===O&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===O?i:"a"===O?i.call(e):i?i.value:t.get(e)}function _(e,t,O,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,O):s?s.value=O:t.set(e,O),O}"function"==typeof SuppressedError&&SuppressedError;const o="$",n={retries:100,delay:50};var A,r,c,a,E;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(A||(A={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(r||(r={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(c||(c={})),function(e){e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",e.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",e.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen"}(a||(a={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(E||(E={}));const h={[A.HOME_ASSISTANT]:{selector:E.HOME_ASSISTANT,children:{shadowRoot:{selector:o,children:{[A.HOME_ASSISTANT_MAIN]:{selector:E.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:o,children:{[A.HA_DRAWER]:{selector:E.HA_DRAWER,children:{[A.HA_SIDEBAR]:{selector:E.HA_SIDEBAR,children:{shadowRoot:{selector:o}}}}}}}}}}}}}},I={[r.PARTIAL_PANEL_RESOLVER]:{selector:E.PARTIAL_PANEL_RESOLVER,children:{[r.HA_PANEL_LOVELACE]:{selector:E.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:o,children:{[r.HUI_ROOT]:{selector:E.HUI_ROOT,children:{shadowRoot:{selector:o,children:{[r.HEADER]:{selector:E.HEADER},[r.HUI_VIEW]:{selector:E.HUI_VIEW}}}}}}}}}}}},l={shadowRoot:{selector:o,children:{[c.HA_MORE_INFO_DIALOG]:{selector:E.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:o,children:{[c.HA_DIALOG]:{selector:E.HA_DIALOG,children:{[c.HA_DIALOG_CONTENT]:{selector:E.HA_DIALOG_CONTENT,children:{[c.HA_MORE_INFO_DIALOG_INFO]:{selector:E.HA_MORE_INFO_DIALOG_INFO},[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[c.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:E.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},N=(s,_,n=null,A=!1)=>Object.entries(_||{}).reduce(((_,r)=>{const[c,a]=r;if(a.selector===o&&n)return a.children?Object.assign(Object.assign({},_),N(s,a.children,n,!0)):_;const E=n?n.then((t=>{return e(t,(O=a.selector,A?"$ "+O:O),s);var O})):e(a.selector,s);return _[c]={element:E,children:N(s,a.children,E),querySelector(t,O={}){return i(this,void 0,void 0,(function*(){const i=yield E;return yield e(i,t,Object.assign(Object.assign({},s),O))}))},querySelectorAll(e,O={}){return i(this,void 0,void 0,(function*(){const i=yield E;return yield t(i,e,Object.assign(Object.assign({},s),O))}))},shadowRootQuerySelector(e,t={}){return i(this,void 0,void 0,(function*(){const i=yield E;return yield O(i,e,Object.assign(Object.assign({},s),t))}))}},_}),{}),L=(e,t)=>{const O=Object.entries(t);for(const t of O){if(t[0]===e)return t[1];{const O=L(e,t[1].children);if(O)return O}}},d=(e,t)=>Object.keys(e).reduce(((e,O)=>{const i=function(e,t){var O={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(O[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(e);s<i.length;s++)t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s])&&(O[i[s]]=e[i[s]])}return O}(L(O,t),["children"]);return e[O]=Object.assign({},i),e}),{});var f,H,R,S,T,D,u,M,G,w,v,p,m,F,b,y,P,g,W,V,C,j,k,B,U;class K extends EventTarget{constructor(e={}){super(),f.add(this),H.set(this,void 0),R.set(this,void 0),S.set(this,void 0),T.set(this,void 0),D.set(this,void 0),u.set(this,void 0),M.set(this,void 0),G.set(this,void 0),w.set(this,void 0),v.set(this,void 0),p.set(this,void 0),m.set(this,void 0),F.set(this,void 0),b.set(this,void 0),y.set(this,void 0),P.set(this,void 0),_(this,H,Object.assign(Object.assign({},n),e),"f")}listen(){_(this,m,s(this,f,"m",j).bind(this),"f"),_(this,F,s(this,f,"m",k).bind(this),"f"),_(this,b,s(this,f,"m",B).bind(this),"f"),_(this,y,s(this,f,"m",U).bind(this),"f"),_(this,G,new MutationObserver(s(this,m,"f")),"f"),_(this,w,new MutationObserver(s(this,F,"f")),"f"),_(this,v,new MutationObserver(s(this,b,"f")),"f"),_(this,p,new MutationObserver(s(this,y,"f")),"f"),s(this,f,"m",V).call(this),s(this,f,"m",C).call(this)}addEventListener(e,t,O){super.addEventListener(e,t,O)}}H=new WeakMap,R=new WeakMap,S=new WeakMap,T=new WeakMap,D=new WeakMap,u=new WeakMap,M=new WeakMap,G=new WeakMap,w=new WeakMap,v=new WeakMap,p=new WeakMap,m=new WeakMap,F=new WeakMap,b=new WeakMap,y=new WeakMap,P=new WeakMap,f=new WeakSet,g=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},W=function(e=c.HA_MORE_INFO_DIALOG_INFO){_(this,R,N(s(this,H,"f"),l,s(this,u,"f").HOME_ASSISTANT.element),"f");const t=d(c,s(this,R,"f"));t.HA_DIALOG_CONTENT.element.then((e=>{s(this,w,"f").disconnect(),s(this,w,"f").observe(e,{childList:!0})})),_(this,D,((e,t)=>[c.HA_MORE_INFO_DIALOG,c.HA_DIALOG,c.HA_DIALOG_CONTENT,t].reduce(((t,O)=>(t[O]=e[O],t)),{}))(t,e),"f");const O={[c.HA_MORE_INFO_DIALOG_INFO]:a.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:a.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[c.HA_DIALOG_MORE_INFO_SETTINGS]:a.ON_LOVELACE_SETTINGS_DIALOG_OPEN};s(this,f,"m",g).call(this,O[e],s(this,D,"f"))},V=function(){_(this,S,N(s(this,H,"f"),h),"f"),_(this,u,d(A,s(this,S,"f")),"f"),s(this,u,"f")[A.HOME_ASSISTANT].shadowRootQuerySelector("$").then((e=>{s(this,G,"f").disconnect(),s(this,G,"f").observe(e,{childList:!0})}))},C=function(){const e=Date.now();e-s(this,P,"f")<500||(_(this,P,e,"f"),_(this,T,N(s(this,H,"f"),I,s(this,u,"f")[A.HA_DRAWER].element),"f"),_(this,M,d(r,s(this,T,"f")),"f"),s(this,M,"f")[r.PARTIAL_PANEL_RESOLVER].element.then((e=>{s(this,v,"f").disconnect(),s(this,v,"f").observe(e,{childList:!0})})),s(this,M,"f")[r.HA_PANEL_LOVELACE].shadowRootQuerySelector("$").then((e=>{s(this,p,"f").disconnect(),s(this,p,"f").observe(e,{childList:!0})})),s(this,f,"m",g).call(this,a.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},s(this,u,"f")),s(this,M,"f"))))},j=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_MORE_INFO_DIALOG&&s(this,f,"m",W).call(this)}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const t={[E.HA_MORE_INFO_DIALOG_INFO]:c.HA_MORE_INFO_DIALOG_INFO,[E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[E.HA_DIALOG_MORE_INFO_SETTINGS]:c.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in t){const O=e.localName;s(this,f,"m",W).call(this,t[O])}}))}))},B=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_PANEL_LOVELACE&&s(this,f,"m",C).call(this)}))}))},U=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HUI_ROOT&&s(this,f,"m",C).call(this)}))}))};export{K as HAQuerySelector,a as HAQuerySelectorEvent};
1
+ import{asyncQuerySelector as e,buildAsyncSelector as t}from"shadow-dom-selector";function O(e,t,O,_){if("a"===O&&!_)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!_:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===O?_:"a"===O?_.call(e):_?_.value:t.get(e)}function _(e,t,O,_,s){if("m"===_)throw new TypeError("Private method is not writable");if("a"===_&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===_?s.call(e,O):s?s.value=O:t.set(e,O),O}"function"==typeof SuppressedError&&SuppressedError;const s="$",i={retries:100,delay:50};var o,A,n,r,E;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(o||(o={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(A||(A={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(n||(n={})),function(e){e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",e.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",e.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen"}(r||(r={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(E||(E={}));const a={[o.HOME_ASSISTANT]:{selector:E.HOME_ASSISTANT,children:{shadowRoot:{selector:s,children:{[o.HOME_ASSISTANT_MAIN]:{selector:E.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:s,children:{[o.HA_DRAWER]:{selector:E.HA_DRAWER,children:{[o.HA_SIDEBAR]:{selector:E.HA_SIDEBAR,children:{shadowRoot:{selector:s}}}}}}}}}}}}}},h={[A.PARTIAL_PANEL_RESOLVER]:{selector:E.PARTIAL_PANEL_RESOLVER,children:{[A.HA_PANEL_LOVELACE]:{selector:E.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:s,children:{[A.HUI_ROOT]:{selector:E.HUI_ROOT,children:{shadowRoot:{selector:s,children:{[A.HEADER]:{selector:E.HEADER},[A.HUI_VIEW]:{selector:E.HUI_VIEW}}}}}}}}}}}},I={shadowRoot:{selector:s,children:{[n.HA_MORE_INFO_DIALOG]:{selector:E.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:s,children:{[n.HA_DIALOG]:{selector:E.HA_DIALOG,children:{[n.HA_DIALOG_CONTENT]:{selector:E.HA_DIALOG_CONTENT,children:{[n.HA_MORE_INFO_DIALOG_INFO]:{selector:E.HA_MORE_INFO_DIALOG_INFO},[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[n.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:E.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},c=(O,_,i=null,o=!1)=>Object.entries(_||{}).reduce(((_,A)=>{const[n,r]=A;if(r.selector===s&&i)return r.children?Object.assign(Object.assign({},_),c(O,r.children,i,!0)):_;const E=i?i.then((t=>{return e(t,(_=r.selector,o?"$ "+_:_),O);var _})):e(r.selector,O);return _[n]={element:E,children:c(O,r.children,E),selector:t(E,O)},_}),{}),l=(e,t)=>{const O=Object.entries(t);for(const t of O){if(t[0]===e)return t[1];{const O=l(e,t[1].children);if(O)return O}}},N=(e,t)=>Object.keys(e).reduce(((e,O)=>{const _=function(e,t){var O={};for(var _ in e)Object.prototype.hasOwnProperty.call(e,_)&&t.indexOf(_)<0&&(O[_]=e[_]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(_=Object.getOwnPropertySymbols(e);s<_.length;s++)t.indexOf(_[s])<0&&Object.prototype.propertyIsEnumerable.call(e,_[s])&&(O[_[s]]=e[_[s]])}return O}(l(O,t),["children"]);return e[O]=Object.assign({},_),e}),{});var L,d,H,f,R,T,D,S,M,G,w,p,u,v,m,F,b,P,W,V,C,g,y,k,j;class B extends EventTarget{constructor(e={}){super(),L.add(this),d.set(this,void 0),H.set(this,void 0),f.set(this,void 0),R.set(this,void 0),T.set(this,void 0),D.set(this,void 0),S.set(this,void 0),M.set(this,void 0),G.set(this,void 0),w.set(this,void 0),p.set(this,void 0),u.set(this,void 0),v.set(this,void 0),m.set(this,void 0),F.set(this,void 0),b.set(this,void 0),_(this,d,Object.assign(Object.assign({},i),e),"f")}listen(){_(this,u,O(this,L,"m",g).bind(this),"f"),_(this,v,O(this,L,"m",y).bind(this),"f"),_(this,m,O(this,L,"m",k).bind(this),"f"),_(this,F,O(this,L,"m",j).bind(this),"f"),_(this,M,new MutationObserver(O(this,u,"f")),"f"),_(this,G,new MutationObserver(O(this,v,"f")),"f"),_(this,w,new MutationObserver(O(this,m,"f")),"f"),_(this,p,new MutationObserver(O(this,F,"f")),"f"),O(this,L,"m",V).call(this),O(this,L,"m",C).call(this)}addEventListener(e,t,O){super.addEventListener(e,t,O)}}d=new WeakMap,H=new WeakMap,f=new WeakMap,R=new WeakMap,T=new WeakMap,D=new WeakMap,S=new WeakMap,M=new WeakMap,G=new WeakMap,w=new WeakMap,p=new WeakMap,u=new WeakMap,v=new WeakMap,m=new WeakMap,F=new WeakMap,b=new WeakMap,L=new WeakSet,P=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},W=function(e=n.HA_MORE_INFO_DIALOG_INFO){_(this,H,c(O(this,d,"f"),I,O(this,D,"f").HOME_ASSISTANT.element),"f");const t=N(n,O(this,H,"f"));t.HA_DIALOG_CONTENT.element.then((e=>{O(this,G,"f").disconnect(),O(this,G,"f").observe(e,{childList:!0})})),_(this,T,((e,t)=>[n.HA_MORE_INFO_DIALOG,n.HA_DIALOG,n.HA_DIALOG_CONTENT,t].reduce(((t,O)=>(t[O]=e[O],t)),{}))(t,e),"f");const s={[n.HA_MORE_INFO_DIALOG_INFO]:r.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:r.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_SETTINGS]:r.ON_LOVELACE_SETTINGS_DIALOG_OPEN};O(this,L,"m",P).call(this,s[e],O(this,T,"f"))},V=function(){_(this,f,c(O(this,d,"f"),a),"f"),_(this,D,N(o,O(this,f,"f")),"f"),O(this,D,"f")[o.HOME_ASSISTANT].selector.$.element.then((e=>{O(this,M,"f").disconnect(),O(this,M,"f").observe(e,{childList:!0})}))},C=function(){const e=Date.now();e-O(this,b,"f")<500||(_(this,b,e,"f"),_(this,R,c(O(this,d,"f"),h,O(this,D,"f")[o.HA_DRAWER].element),"f"),_(this,S,N(A,O(this,R,"f")),"f"),O(this,S,"f")[A.PARTIAL_PANEL_RESOLVER].element.then((e=>{O(this,w,"f").disconnect(),O(this,w,"f").observe(e,{childList:!0})})),O(this,S,"f")[A.HA_PANEL_LOVELACE].selector.$.element.then((e=>{O(this,p,"f").disconnect(),O(this,p,"f").observe(e,{childList:!0})})),O(this,L,"m",P).call(this,r.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},O(this,D,"f")),O(this,S,"f"))))},g=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_MORE_INFO_DIALOG&&O(this,L,"m",W).call(this)}))}))},y=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const t={[E.HA_MORE_INFO_DIALOG_INFO]:n.HA_MORE_INFO_DIALOG_INFO,[E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[E.HA_DIALOG_MORE_INFO_SETTINGS]:n.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in t){const _=e.localName;O(this,L,"m",W).call(this,t[_])}}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_PANEL_LOVELACE&&O(this,L,"m",C).call(this)}))}))},j=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HUI_ROOT&&O(this,L,"m",C).call(this)}))}))};export{B as HAQuerySelector,r as HAQuerySelectorEvent};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- type HAQuerySelectorConfig = {
2
- retries?: number;
3
- delay?: number;
4
- };
1
+ import { AsyncSelectorProxy, AsyncParams } from "shadow-dom-selector";
2
+ type HAQuerySelectorConfig = AsyncParams;
5
3
  type NodeDescriptorProps = {
6
4
  selector: string;
7
5
  children?: HomeAssistantNodeDescriptor;
@@ -12,9 +10,7 @@ type HomeAssistantNodeDescriptor = {
12
10
  type ElementProps = {
13
11
  element: Promise<Element | null>;
14
12
  children?: HomeAssistantElement;
15
- querySelector: <E extends Element = Element>(selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<E | null>;
16
- querySelectorAll: <E extends Element = Element>(selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<NodeListOf<E>>;
17
- shadowRootQuerySelector: (selector: string, asyncProps?: HAQuerySelectorConfig) => Promise<ShadowRoot | null>;
13
+ selector: AsyncSelectorProxy;
18
14
  };
19
15
  type HomeAssistantElement = {
20
16
  [key: string]: ElementProps;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("shadow-dom-selector");function t(e,t,o,s){return new(o||(o=Promise))((function(O,i){function _(e){try{r(s.next(e))}catch(e){i(e)}}function n(e){try{r(s.throw(e))}catch(e){i(e)}}function r(e){var t;e.done?O(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(_,n)}r((s=s.apply(e,t||[])).next())}))}function o(e,t,o,s){if("a"===o&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?s:"a"===o?s.call(e):s?s.value:t.get(e)}function s(e,t,o,s,O){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!O)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!O:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?O.call(e,o):O?O.value=o:t.set(e,o),o}"function"==typeof SuppressedError&&SuppressedError;const O="$",i={retries:100,delay:50};var _,n,r,A,c;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(_||(_={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(n||(n={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(r||(r={})),exports.HAQuerySelectorEvent=void 0,(A=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",A.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",A.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",A.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(c||(c={}));const a={[_.HOME_ASSISTANT]:{selector:c.HOME_ASSISTANT,children:{shadowRoot:{selector:O,children:{[_.HOME_ASSISTANT_MAIN]:{selector:c.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:O,children:{[_.HA_DRAWER]:{selector:c.HA_DRAWER,children:{[_.HA_SIDEBAR]:{selector:c.HA_SIDEBAR,children:{shadowRoot:{selector:O}}}}}}}}}}}}}},E={[n.PARTIAL_PANEL_RESOLVER]:{selector:c.PARTIAL_PANEL_RESOLVER,children:{[n.HA_PANEL_LOVELACE]:{selector:c.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:O,children:{[n.HUI_ROOT]:{selector:c.HUI_ROOT,children:{shadowRoot:{selector:O,children:{[n.HEADER]:{selector:c.HEADER},[n.HUI_VIEW]:{selector:c.HUI_VIEW}}}}}}}}}}}},h={shadowRoot:{selector:O,children:{[r.HA_MORE_INFO_DIALOG]:{selector:c.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:O,children:{[r.HA_DIALOG]:{selector:c.HA_DIALOG,children:{[r.HA_DIALOG_CONTENT]:{selector:c.HA_DIALOG_CONTENT,children:{[r.HA_MORE_INFO_DIALOG_INFO]:{selector:c.HA_MORE_INFO_DIALOG_INFO},[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[r.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:c.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},l=(o,s,i=null,_=!1)=>Object.entries(s||{}).reduce(((s,n)=>{const[r,A]=n;if(A.selector===O&&i)return A.children?Object.assign(Object.assign({},s),l(o,A.children,i,!0)):s;const c=i?i.then((t=>{return e.asyncQuerySelector(t,(s=A.selector,_?"$ "+s:s),o);var s})):e.asyncQuerySelector(A.selector,o);return s[r]={element:c,children:l(o,A.children,c),querySelector(s,O={}){return t(this,void 0,void 0,(function*(){const t=yield c;return yield e.asyncQuerySelector(t,s,Object.assign(Object.assign({},o),O))}))},querySelectorAll(s,O={}){return t(this,void 0,void 0,(function*(){const t=yield c;return yield e.asyncQuerySelectorAll(t,s,Object.assign(Object.assign({},o),O))}))},shadowRootQuerySelector(s,O={}){return t(this,void 0,void 0,(function*(){const t=yield c;return yield e.asyncShadowRootQuerySelector(t,s,Object.assign(Object.assign({},o),O))}))}},s}),{}),I=(e,t)=>{const o=Object.entries(t);for(const t of o){if(t[0]===e)return t[1];{const o=I(e,t[1].children);if(o)return o}}},N=(e,t)=>Object.keys(e).reduce(((e,o)=>{const s=function(e,t){var o={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var O=0;for(s=Object.getOwnPropertySymbols(e);O<s.length;O++)t.indexOf(s[O])<0&&Object.prototype.propertyIsEnumerable.call(e,s[O])&&(o[s[O]]=e[s[O]])}return o}(I(o,t),["children"]);return e[o]=Object.assign({},s),e}),{});var L,d,H,f,S,R,u,T,D,M,G,v,w,p,y,m,F,b,P,g,W,V,C,j,k;class B extends EventTarget{constructor(e={}){super(),L.add(this),d.set(this,void 0),H.set(this,void 0),f.set(this,void 0),S.set(this,void 0),R.set(this,void 0),u.set(this,void 0),T.set(this,void 0),D.set(this,void 0),M.set(this,void 0),G.set(this,void 0),v.set(this,void 0),w.set(this,void 0),p.set(this,void 0),y.set(this,void 0),m.set(this,void 0),F.set(this,void 0),s(this,d,Object.assign(Object.assign({},i),e),"f")}listen(){s(this,w,o(this,L,"m",V).bind(this),"f"),s(this,p,o(this,L,"m",C).bind(this),"f"),s(this,y,o(this,L,"m",j).bind(this),"f"),s(this,m,o(this,L,"m",k).bind(this),"f"),s(this,D,new MutationObserver(o(this,w,"f")),"f"),s(this,M,new MutationObserver(o(this,p,"f")),"f"),s(this,G,new MutationObserver(o(this,y,"f")),"f"),s(this,v,new MutationObserver(o(this,m,"f")),"f"),o(this,L,"m",g).call(this),o(this,L,"m",W).call(this)}addEventListener(e,t,o){super.addEventListener(e,t,o)}}d=new WeakMap,H=new WeakMap,f=new WeakMap,S=new WeakMap,R=new WeakMap,u=new WeakMap,T=new WeakMap,D=new WeakMap,M=new WeakMap,G=new WeakMap,v=new WeakMap,w=new WeakMap,p=new WeakMap,y=new WeakMap,m=new WeakMap,F=new WeakMap,L=new WeakSet,b=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},P=function(e=r.HA_MORE_INFO_DIALOG_INFO){s(this,H,l(o(this,d,"f"),h,o(this,u,"f").HOME_ASSISTANT.element),"f");const t=N(r,o(this,H,"f"));t.HA_DIALOG_CONTENT.element.then((e=>{o(this,M,"f").disconnect(),o(this,M,"f").observe(e,{childList:!0})})),s(this,R,((e,t)=>[r.HA_MORE_INFO_DIALOG,r.HA_DIALOG,r.HA_DIALOG_CONTENT,t].reduce(((t,o)=>(t[o]=e[o],t)),{}))(t,e),"f");const O={[r.HA_MORE_INFO_DIALOG_INFO]:exports.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:exports.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[r.HA_DIALOG_MORE_INFO_SETTINGS]:exports.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN};o(this,L,"m",b).call(this,O[e],o(this,R,"f"))},g=function(){s(this,f,l(o(this,d,"f"),a),"f"),s(this,u,N(_,o(this,f,"f")),"f"),o(this,u,"f")[_.HOME_ASSISTANT].shadowRootQuerySelector("$").then((e=>{o(this,D,"f").disconnect(),o(this,D,"f").observe(e,{childList:!0})}))},W=function(){const e=Date.now();e-o(this,F,"f")<500||(s(this,F,e,"f"),s(this,S,l(o(this,d,"f"),E,o(this,u,"f")[_.HA_DRAWER].element),"f"),s(this,T,N(n,o(this,S,"f")),"f"),o(this,T,"f")[n.PARTIAL_PANEL_RESOLVER].element.then((e=>{o(this,G,"f").disconnect(),o(this,G,"f").observe(e,{childList:!0})})),o(this,T,"f")[n.HA_PANEL_LOVELACE].shadowRootQuerySelector("$").then((e=>{o(this,v,"f").disconnect(),o(this,v,"f").observe(e,{childList:!0})})),o(this,L,"m",b).call(this,exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},o(this,u,"f")),o(this,T,"f"))))},V=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===c.HA_MORE_INFO_DIALOG&&o(this,L,"m",P).call(this)}))}))},C=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const t={[c.HA_MORE_INFO_DIALOG_INFO]:r.HA_MORE_INFO_DIALOG_INFO,[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[c.HA_DIALOG_MORE_INFO_SETTINGS]:r.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in t){const s=e.localName;o(this,L,"m",P).call(this,t[s])}}))}))},j=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===c.HA_PANEL_LOVELACE&&o(this,L,"m",W).call(this)}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===c.HUI_ROOT&&o(this,L,"m",W).call(this)}))}))},exports.HAQuerySelector=B;
1
+ "use strict";var e=require("shadow-dom-selector");function t(e,t,O,_){if("a"===O&&!_)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!_:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===O?_:"a"===O?_.call(e):_?_.value:t.get(e)}function O(e,t,O,_,s){if("m"===_)throw new TypeError("Private method is not writable");if("a"===_&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===_?s.call(e,O):s?s.value=O:t.set(e,O),O}"function"==typeof SuppressedError&&SuppressedError;const _="$",s={retries:100,delay:50};var o,i,A,r,n;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(o||(o={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(i||(i={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(A||(A={})),exports.HAQuerySelectorEvent=void 0,(r=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",r.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",r.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",r.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(n||(n={}));const E={[o.HOME_ASSISTANT]:{selector:n.HOME_ASSISTANT,children:{shadowRoot:{selector:_,children:{[o.HOME_ASSISTANT_MAIN]:{selector:n.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:_,children:{[o.HA_DRAWER]:{selector:n.HA_DRAWER,children:{[o.HA_SIDEBAR]:{selector:n.HA_SIDEBAR,children:{shadowRoot:{selector:_}}}}}}}}}}}}}},c={[i.PARTIAL_PANEL_RESOLVER]:{selector:n.PARTIAL_PANEL_RESOLVER,children:{[i.HA_PANEL_LOVELACE]:{selector:n.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:_,children:{[i.HUI_ROOT]:{selector:n.HUI_ROOT,children:{shadowRoot:{selector:_,children:{[i.HEADER]:{selector:n.HEADER},[i.HUI_VIEW]:{selector:n.HUI_VIEW}}}}}}}}}}}},a={shadowRoot:{selector:_,children:{[A.HA_MORE_INFO_DIALOG]:{selector:n.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:_,children:{[A.HA_DIALOG]:{selector:n.HA_DIALOG,children:{[A.HA_DIALOG_CONTENT]:{selector:n.HA_DIALOG_CONTENT,children:{[A.HA_MORE_INFO_DIALOG_INFO]:{selector:n.HA_MORE_INFO_DIALOG_INFO},[A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[A.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:n.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},h=(t,O,s=null,o=!1)=>Object.entries(O||{}).reduce(((O,i)=>{const[A,r]=i;if(r.selector===_&&s)return r.children?Object.assign(Object.assign({},O),h(t,r.children,s,!0)):O;const n=s?s.then((O=>{return e.asyncQuerySelector(O,(_=r.selector,o?"$ "+_:_),t);var _})):e.asyncQuerySelector(r.selector,t);return O[A]={element:n,children:h(t,r.children,n),selector:e.buildAsyncSelector(n,t)},O}),{}),I=(e,t)=>{const O=Object.entries(t);for(const t of O){if(t[0]===e)return t[1];{const O=I(e,t[1].children);if(O)return O}}},l=(e,t)=>Object.keys(e).reduce(((e,O)=>{const _=function(e,t){var O={};for(var _ in e)Object.prototype.hasOwnProperty.call(e,_)&&t.indexOf(_)<0&&(O[_]=e[_]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(_=Object.getOwnPropertySymbols(e);s<_.length;s++)t.indexOf(_[s])<0&&Object.prototype.propertyIsEnumerable.call(e,_[s])&&(O[_[s]]=e[_[s]])}return O}(I(O,t),["children"]);return e[O]=Object.assign({},_),e}),{});var N,L,d,H,f,R,S,T,D,M,G,u,v,p,w,m,F,b,y,P,W,V,C,g,k;class j extends EventTarget{constructor(e={}){super(),N.add(this),L.set(this,void 0),d.set(this,void 0),H.set(this,void 0),f.set(this,void 0),R.set(this,void 0),S.set(this,void 0),T.set(this,void 0),D.set(this,void 0),M.set(this,void 0),G.set(this,void 0),u.set(this,void 0),v.set(this,void 0),p.set(this,void 0),w.set(this,void 0),m.set(this,void 0),F.set(this,void 0),O(this,L,Object.assign(Object.assign({},s),e),"f")}listen(){O(this,v,t(this,N,"m",V).bind(this),"f"),O(this,p,t(this,N,"m",C).bind(this),"f"),O(this,w,t(this,N,"m",g).bind(this),"f"),O(this,m,t(this,N,"m",k).bind(this),"f"),O(this,D,new MutationObserver(t(this,v,"f")),"f"),O(this,M,new MutationObserver(t(this,p,"f")),"f"),O(this,G,new MutationObserver(t(this,w,"f")),"f"),O(this,u,new MutationObserver(t(this,m,"f")),"f"),t(this,N,"m",P).call(this),t(this,N,"m",W).call(this)}addEventListener(e,t,O){super.addEventListener(e,t,O)}}L=new WeakMap,d=new WeakMap,H=new WeakMap,f=new WeakMap,R=new WeakMap,S=new WeakMap,T=new WeakMap,D=new WeakMap,M=new WeakMap,G=new WeakMap,u=new WeakMap,v=new WeakMap,p=new WeakMap,w=new WeakMap,m=new WeakMap,F=new WeakMap,N=new WeakSet,b=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},y=function(e=A.HA_MORE_INFO_DIALOG_INFO){O(this,d,h(t(this,L,"f"),a,t(this,S,"f").HOME_ASSISTANT.element),"f");const _=l(A,t(this,d,"f"));_.HA_DIALOG_CONTENT.element.then((e=>{t(this,M,"f").disconnect(),t(this,M,"f").observe(e,{childList:!0})})),O(this,R,((e,t)=>[A.HA_MORE_INFO_DIALOG,A.HA_DIALOG,A.HA_DIALOG_CONTENT,t].reduce(((t,O)=>(t[O]=e[O],t)),{}))(_,e),"f");const s={[A.HA_MORE_INFO_DIALOG_INFO]:exports.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:exports.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[A.HA_DIALOG_MORE_INFO_SETTINGS]:exports.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN};t(this,N,"m",b).call(this,s[e],t(this,R,"f"))},P=function(){O(this,H,h(t(this,L,"f"),E),"f"),O(this,S,l(o,t(this,H,"f")),"f"),t(this,S,"f")[o.HOME_ASSISTANT].selector.$.element.then((e=>{t(this,D,"f").disconnect(),t(this,D,"f").observe(e,{childList:!0})}))},W=function(){const e=Date.now();e-t(this,F,"f")<500||(O(this,F,e,"f"),O(this,f,h(t(this,L,"f"),c,t(this,S,"f")[o.HA_DRAWER].element),"f"),O(this,T,l(i,t(this,f,"f")),"f"),t(this,T,"f")[i.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,G,"f").disconnect(),t(this,G,"f").observe(e,{childList:!0})})),t(this,T,"f")[i.HA_PANEL_LOVELACE].selector.$.element.then((e=>{t(this,u,"f").disconnect(),t(this,u,"f").observe(e,{childList:!0})})),t(this,N,"m",b).call(this,exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,S,"f")),t(this,T,"f"))))},V=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HA_MORE_INFO_DIALOG&&t(this,N,"m",y).call(this)}))}))},C=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const O={[n.HA_MORE_INFO_DIALOG_INFO]:A.HA_MORE_INFO_DIALOG_INFO,[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[n.HA_DIALOG_MORE_INFO_SETTINGS]:A.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in O){const _=e.localName;t(this,N,"m",y).call(this,O[_])}}))}))},g=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HA_PANEL_LOVELACE&&t(this,N,"m",W).call(this)}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HUI_ROOT&&t(this,N,"m",W).call(this)}))}))},exports.HAQuerySelector=j;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "home-assistant-query-selector",
3
- "version": "1.1.3",
3
+ "version": "2.0.0",
4
4
  "description": "Easily query home-assistant DOM elements in an async way",
5
5
  "keywords": [
6
6
  "query-selector",
@@ -50,7 +50,7 @@
50
50
  "postversion": "git push && git push --tags"
51
51
  },
52
52
  "dependencies": {
53
- "shadow-dom-selector": "^1.0.2"
53
+ "shadow-dom-selector": "^2.0.4"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@cypress/code-coverage": "^3.12.10",