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 +27 -36
- package/dist/esm/index.d.ts +3 -7
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.js +1 -1
- package/package.json +2 -2
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.
|
|
43
|
-
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
59
|
-
HA_PANEL_LOVELACE.
|
|
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
|
|
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
|
-
| `
|
|
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
|
-
| `
|
|
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
|
-
| `
|
|
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
|
-
| `
|
|
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
|
-
|
|
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
|
-
[
|
|
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
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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,
|
|
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": "
|
|
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": "^
|
|
53
|
+
"shadow-dom-selector": "^2.0.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@cypress/code-coverage": "^3.12.10",
|