home-assistant-query-selector 3.0.0 → 4.0.1
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 +130 -21
- package/dist/esm/index.d.ts +19 -13
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +19 -13
- package/dist/index.js +1 -1
- package/package.json +14 -10
package/README.md
CHANGED
|
@@ -10,14 +10,20 @@ When one wants to build a `Home Assistant` front-end plugin, like many of the on
|
|
|
10
10
|
|
|
11
11
|
As I develop and maintain several `Home Assistant` plugins that change the style of the `DOM` elements, I find myself repeating the same piece of logic over and over to select the elements, and when the `Home Asistant` front-end code changes ([something that occurs more than I would like](https://github.com/NemesisRE/kiosk-mode/issues/27)), I need to go and fix the same in all of them.
|
|
12
12
|
|
|
13
|
-
This is from where the idea of `home-assistant-query-selector` comes from. Imagine instantiating a class, and without querying for any element, just wait for
|
|
13
|
+
This is from where the idea of `home-assistant-query-selector` comes from. Imagine instantiating a class, and without querying for any element, through promises, just wait for the main `Home Assistant` DOM elements to be created and rendered to be able to access them. That sounds great! doesn‘t it?. In that way, the `Home Assistant` plugins that I maintain could be agnostic to the `DOM` tree, and if someting changes with a new version and all the plugins break at the same time, the changes to fix them could be done in a single place, to fix the plugins only a simple update of this library is needed once the patch is released.
|
|
14
14
|
|
|
15
15
|
### How to detect if something will break with a new Home Assistant version?
|
|
16
16
|
|
|
17
17
|
There are exhaustive end-to-end tests in place in this library, when a new version of `Home Assistant` is released, running the end-to-end tests in this repository will ensure that the library still works with the new version, so no need to manually check this.
|
|
18
18
|
|
|
19
|
+
#### End-to-end tests
|
|
20
|
+
|
|
19
21
|

|
|
20
22
|
|
|
23
|
+
#### Code coverage
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
21
27
|
### Code example
|
|
22
28
|
|
|
23
29
|
More details of the API can be consulted in [the API section](#api):
|
|
@@ -27,29 +33,57 @@ import { HAQuerySelector } from 'home-assistant-query-selector';
|
|
|
27
33
|
|
|
28
34
|
const instance = new HAQuerySelector();
|
|
29
35
|
|
|
30
|
-
//This
|
|
31
|
-
|
|
36
|
+
// This even will be triggered when the listen method is called
|
|
37
|
+
// You can also use the enum value HAQuerySelectorEvent.ON_LISTEN
|
|
38
|
+
instance.addEventListener('onListen', ({ detail }) => {
|
|
32
39
|
|
|
33
|
-
const {
|
|
40
|
+
const { HOME_ASSISTANT, HOME_ASSISTANT_MAIN, HA_SIDEBAR } = detail;
|
|
34
41
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
.then((
|
|
38
|
-
//
|
|
42
|
+
// Querying the ha-sidebar element from the home-assistant element
|
|
43
|
+
HOME_ASSISTANT.selector.$.query('home-assistant-main').$.query('ha-sidebar').element
|
|
44
|
+
.then((sidebar) => {
|
|
45
|
+
// sidebar === ha-sidebar element
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Deep-querying the sidebar element
|
|
49
|
+
HOME_ASSISTANT.selector.deepQuery('ha-sidebar').element
|
|
50
|
+
.then((sidebar) => {
|
|
51
|
+
// sidebar === ha-sidebar element
|
|
39
52
|
});
|
|
40
|
-
|
|
53
|
+
|
|
41
54
|
// When the sidebar is available in the DOM
|
|
42
55
|
HA_SIDEBAR.element
|
|
43
56
|
then((sidebar) => {
|
|
44
57
|
// Do whatever we want with the sidebar
|
|
45
58
|
});
|
|
59
|
+
});
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
// This event will be triggered when any panel loads
|
|
62
|
+
// You can also use the enum value HAQuerySelectorEvent.ON_PANEL_LOAD
|
|
63
|
+
instance.addEventListener('onPanelLoad', ({ detail }) => {
|
|
64
|
+
|
|
65
|
+
const { PARTIAL_PANEL_RESOLVER } = detail;
|
|
66
|
+
|
|
67
|
+
// When the partial panel resolver is available in the DOM
|
|
68
|
+
PARTIAL_PANEL_RESOLVER.element
|
|
69
|
+
.then((partialPanelResolver) => {
|
|
70
|
+
// Do whatever we want with the partial panel resolver
|
|
51
71
|
});
|
|
52
72
|
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// This event will be triggered every time a lovelace dashboard loads
|
|
76
|
+
// You can also use the enum value HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD
|
|
77
|
+
instance.addEventListener('onLovelacePanelLoad', ({ detail }) => {
|
|
78
|
+
|
|
79
|
+
const { HEADER, HA_PANEL_LOVELACE } = detail;
|
|
80
|
+
|
|
81
|
+
// When the header is available in the DOM
|
|
82
|
+
HEADER.element
|
|
83
|
+
.then((header) => {
|
|
84
|
+
// Do whatever we want with the header
|
|
85
|
+
});
|
|
86
|
+
|
|
53
87
|
// Querying all the ha-icon-button elements inside the .action-items in the header
|
|
54
88
|
HEADER.selector.query('.action-items ha-icon-button').all
|
|
55
89
|
.then((buttons) => {
|
|
@@ -62,15 +96,10 @@ instance.addEventListener('onPanelLoad', ({ detail }) => {
|
|
|
62
96
|
// shadowRoot === hui-root‘s shadowRoot
|
|
63
97
|
});
|
|
64
98
|
|
|
65
|
-
// Deep-querying the sidebar element
|
|
66
|
-
HOME_ASSISTANT.selector.deepQuery('ha-sidebar').element
|
|
67
|
-
.then((sidebar) => {
|
|
68
|
-
// sidebar === ha-sidebar element
|
|
69
|
-
});
|
|
70
|
-
|
|
71
99
|
});
|
|
72
100
|
|
|
73
101
|
// This event will be triggered every time a more-info dialog is open
|
|
102
|
+
// You can also use the enum value HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN
|
|
74
103
|
instance.addEventListener('onMoreInfoDialogOpen', ({ detail }) => {
|
|
75
104
|
|
|
76
105
|
// When the ha-more-info-info element is available in the DOM
|
|
@@ -130,7 +159,7 @@ new HAQuerySelector([config])
|
|
|
130
159
|
|
|
131
160
|
### Public methods
|
|
132
161
|
|
|
133
|
-
`HAQuerySelector` instances count with a public method. When it is called, this method will trigger the `onPanelLoad`
|
|
162
|
+
`HAQuerySelector` instances count with a public method. When it is called, this method will trigger the `onListen` and `onPanelLoad` (and `onLovelacePanelLoad` if the panel in which it is invoked is a lovelace panel) events inmediatly and start to watch for changes in the `DOM` to trigger the proper events.
|
|
134
163
|
|
|
135
164
|
```typescript
|
|
136
165
|
instance.listen();
|
|
@@ -140,9 +169,49 @@ instance.listen();
|
|
|
140
169
|
|
|
141
170
|
The `HAQuerySelector` class extends from [EventTarget], so it is possible to add events listeners to it. It will dispatch events that will allow us to access the proper elements in the `DOM`.
|
|
142
171
|
|
|
172
|
+
#### onListen
|
|
173
|
+
|
|
174
|
+
This event is triggered when [the listen method](#public-methods) is called. It is useful if you only want to access the main Home Assistant elements only once.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
instance.addEventListener('onListen', function({detail}) {
|
|
178
|
+
/* detail:
|
|
179
|
+
{
|
|
180
|
+
HOME_ASSISTANT: {...},
|
|
181
|
+
HOME_ASSISTANT_MAIN: {...},
|
|
182
|
+
HA_DRAWER: {...},
|
|
183
|
+
...
|
|
184
|
+
}
|
|
185
|
+
*/
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The dispatched event is a [CustomEvent] and its `detail` property is an object containing the main `Home Assistant` `DOM` elements. All the properties and methods included in each element are Promises, so they are async and will be resolved when the element is ready to work with it.
|
|
190
|
+
|
|
191
|
+
##### onListen event elements
|
|
192
|
+
|
|
193
|
+
This is the list of the elements available inside the `detail` property of the `onListen` event:
|
|
194
|
+
|
|
195
|
+

|
|
196
|
+
|
|
197
|
+
| Detail element | DOM element |
|
|
198
|
+
| ------------------------ | ------------------------ |
|
|
199
|
+
| `HOME_ASSISTANT` | `home-assistant` |
|
|
200
|
+
| `HOME_ASSISTANT_MAIN` | `home-assistant-main` |
|
|
201
|
+
| `HA_DRAWER` | `ha-drawer` |
|
|
202
|
+
| `HA_SIDEBAR` | `ha-sidebar` |
|
|
203
|
+
| `PARTIAL_PANEL_RESOLVER` | `partial-panel-resolver` |
|
|
204
|
+
|
|
205
|
+
All the available elements contain an `element` property and the `selector` property:
|
|
206
|
+
|
|
207
|
+
| Property or method | Description |
|
|
208
|
+
| ------------------------- | --------------------------------------------------------------- |
|
|
209
|
+
| `element` | Promise that resolves in the respective `DOM` element |
|
|
210
|
+
| `selector` | Object that allows one to query for elements using dot notation |
|
|
211
|
+
|
|
143
212
|
#### onPanelLoad
|
|
144
213
|
|
|
145
|
-
This event is triggered when [the listen method](#public-methods) is called or when
|
|
214
|
+
This event is triggered when [the listen method](#public-methods) is called or when any panel is loaded.
|
|
146
215
|
|
|
147
216
|
```typescript
|
|
148
217
|
instance.addEventListener('onPanelLoad', function({detail}) {
|
|
@@ -165,6 +234,46 @@ This is the list of the elements available inside the `detail` property of the `
|
|
|
165
234
|
|
|
166
235
|

|
|
167
236
|
|
|
237
|
+
| Detail element | DOM element |
|
|
238
|
+
| ------------------------ | ------------------------ |
|
|
239
|
+
| `HOME_ASSISTANT` | `home-assistant` |
|
|
240
|
+
| `HOME_ASSISTANT_MAIN` | `home-assistant-main` |
|
|
241
|
+
| `HA_DRAWER` | `ha-drawer` |
|
|
242
|
+
| `HA_SIDEBAR` | `ha-sidebar` |
|
|
243
|
+
| `PARTIAL_PANEL_RESOLVER` | `partial-panel-resolver` |
|
|
244
|
+
|
|
245
|
+
All the available elements contain an `element` property and the `selector` property:
|
|
246
|
+
|
|
247
|
+
| Property or method | Description |
|
|
248
|
+
| ------------------------- | --------------------------------------------------------------- |
|
|
249
|
+
| `element` | Promise that resolves in the respective `DOM` element |
|
|
250
|
+
| `selector` | Object that allows one to query for elements using dot notation |
|
|
251
|
+
|
|
252
|
+
#### onLovelacePanelLoad
|
|
253
|
+
|
|
254
|
+
This event is triggered when [the listen method](#public-methods) is called on a lovelace dashboard or when a lovelace dashboard is loaded.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
instance.addEventListener('onLovelacePanelLoad', function({ detail }) {
|
|
258
|
+
/* detail:
|
|
259
|
+
{
|
|
260
|
+
HOME_ASSISTANT: {...},
|
|
261
|
+
HOME_ASSISTANT_MAIN: {...},
|
|
262
|
+
HA_DRAWER: {...},
|
|
263
|
+
...
|
|
264
|
+
}
|
|
265
|
+
*/
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The dispatched event is a [CustomEvent] and its `detail` property is an object containing the main `Home Assistant` `DOM` elements. All the properties and methods included in each element are Promises, so they are async and will be resolved when the element is ready to work with it.
|
|
270
|
+
|
|
271
|
+
##### onLovelacePanelLoad event elements
|
|
272
|
+
|
|
273
|
+
This is the list of the elements available inside the `detail` property of the `onLovelacePanelLoad` event:
|
|
274
|
+
|
|
275
|
+

|
|
276
|
+
|
|
168
277
|
| Detail element | DOM element |
|
|
169
278
|
| ------------------------ | ------------------------ |
|
|
170
279
|
| `HOME_ASSISTANT` | `home-assistant` |
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -23,10 +23,10 @@ declare enum HA_ROOT_ELEMENT {
|
|
|
23
23
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
24
24
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
25
25
|
HA_DRAWER = "HA_DRAWER",
|
|
26
|
-
HA_SIDEBAR = "HA_SIDEBAR"
|
|
26
|
+
HA_SIDEBAR = "HA_SIDEBAR",
|
|
27
|
+
PARTIAL_PANEL_RESOLVER = "PARTIAL_PANEL_RESOLVER"
|
|
27
28
|
}
|
|
28
|
-
declare enum
|
|
29
|
-
PARTIAL_PANEL_RESOLVER = "PARTIAL_PANEL_RESOLVER",
|
|
29
|
+
declare enum HA_LOVELACE_ELEMENT {
|
|
30
30
|
HA_PANEL_LOVELACE = "HA_PANEL_LOVELACE",
|
|
31
31
|
HUI_ROOT = "HUI_ROOT",
|
|
32
32
|
HEADER = "HEADER",
|
|
@@ -41,15 +41,19 @@ declare enum HA_DIALOG_ELEMENT {
|
|
|
41
41
|
HA_DIALOG_MORE_INFO_SETTINGS = "HA_DIALOG_MORE_INFO_SETTINGS"
|
|
42
42
|
}
|
|
43
43
|
declare enum HAQuerySelectorEvent {
|
|
44
|
+
ON_LISTEN = "onListen",
|
|
44
45
|
ON_PANEL_LOAD = "onPanelLoad",
|
|
46
|
+
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad",
|
|
45
47
|
ON_MORE_INFO_DIALOG_OPEN = "onMoreInfoDialogOpen",
|
|
46
48
|
ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onHistoryAndLogBookDialogOpen",
|
|
47
49
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
48
50
|
}
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
51
|
+
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
52
|
+
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
53
|
+
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
54
|
+
type OnMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
55
|
+
type OnHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
56
|
+
type OnSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
|
|
53
57
|
declare class DelegatedEventTarget implements EventTarget {
|
|
54
58
|
private delegate;
|
|
55
59
|
addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
|
|
@@ -77,15 +81,17 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
77
81
|
private _dispatchEvent;
|
|
78
82
|
private _updateDialogElements;
|
|
79
83
|
private _updateRootElements;
|
|
80
|
-
private
|
|
84
|
+
private _updateLovelaceElements;
|
|
81
85
|
private _watchDialogs;
|
|
82
86
|
private _watchDialogsContent;
|
|
83
87
|
private _watchDashboards;
|
|
84
88
|
private _watchLovelace;
|
|
85
89
|
listen(): void;
|
|
86
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
87
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
88
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
89
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
90
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_LISTEN}`, callback: HAQuerySelectorEventListener<OnListenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
91
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnPanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
93
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
94
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
95
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
90
96
|
}
|
|
91
|
-
export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnLovelacePanelLoadDetail,
|
|
97
|
+
export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnListenDetail, OnPanelLoadDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnHistoryAndLogBookDialogOpenDetail, OnSettingsDialogOpenDetail };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(e,t)};var _=function(){return _=Object.assign||function(e){for(var t,o=1,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},_.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,r,O,i,s,a,A,l,
|
|
1
|
+
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(e,t)};var _=function(){return _=Object.assign||function(e){for(var t,o=1,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},_.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,r,O,i,s,a,A,c,l,E,h,I,N,d,L,R,u="$",D={retries:100,delay:50};!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"}(n||(n={})),function(e){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"}(O||(O={})),function(e){e.ON_LISTEN="onListen",e.ON_PANEL_LOAD="onPanelLoad",e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",e.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",e.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen"}(i||(i={})),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"}(R||(R={}));var H=((s={})[n.HOME_ASSISTANT]={selector:R.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(a={},a[n.HOME_ASSISTANT_MAIN]={selector:R.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(A={},A[n.HA_DRAWER]={selector:R.HA_DRAWER,children:(c={},c[n.HA_SIDEBAR]={selector:R.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},c[n.PARTIAL_PANEL_RESOLVER]={selector:R.PARTIAL_PANEL_RESOLVER},c)},A)}}},a)}}},s),p=((l={})[r.HA_PANEL_LOVELACE]={selector:R.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(E={},E[r.HUI_ROOT]={selector:R.HUI_ROOT,children:{shadowRoot:{selector:u,children:(h={},h[r.HEADER]={selector:R.HEADER},h[r.HUI_VIEW]={selector:R.HUI_VIEW},h)}}},E)}}},l),v={shadowRoot:{selector:u,children:(I={},I[O.HA_MORE_INFO_DIALOG]={selector:R.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(N={},N[O.HA_DIALOG]={selector:R.HA_DIALOG,children:(d={},d[O.HA_DIALOG_CONTENT]={selector:R.HA_DIALOG_CONTENT,children:(L={},L[O.HA_MORE_INFO_DIALOG_INFO]={selector:R.HA_MORE_INFO_DIALOG_INFO},L[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},L[O.HA_DIALOG_MORE_INFO_SETTINGS]={selector:R.HA_DIALOG_MORE_INFO_SETTINGS},L)},d)},N)}}},I)}},f=function(o,n,r,O){return void 0===r&&(r=null),void 0===O&&(O=!1),Object.entries(n||{}).reduce((function(n,i){var s=i[0],a=i[1];if(a.selector===u&&r)return a.children?_(_({},n),f(o,a.children,r,!0)):n;var A=r?r.then((function(t){return e(t,(_=a.selector,O?"$ "+_:_),o);var _})):e(a.selector,o);return n[s]={element:A,children:f(o,a.children,A),selector:new t(A,o)},n}),{})},T=function(e,t){for(var o=0,_=Object.entries(t);o<_.length;o++){var n=_[o];if(n[0]===e)return n[1];var r=T(e,n[1].children);if(r)return r}},S=function(e,t){return Object.keys(e).reduce((function(e,o){var n=T(o,t);n.children;var r=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 n=0;for(_=Object.getOwnPropertySymbols(e);n<_.length;n++)t.indexOf(_[n])<0&&Object.prototype.propertyIsEnumerable.call(e,_[n])&&(o[_[n]]=e[_[n]])}return o}(n,["children"]);return e[o]=_({},r),e}),{})},G=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),m=function(e){function t(t){void 0===t&&(t={});var o=e.call(this)||this;return o._config=_(_({},D),t),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function _(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(_.prototype=t.prototype,new _)}(t,e),t.prototype._dispatchEvent=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},t.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=O.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=f(this._config,v,this._haRootElements.HOME_ASSISTANT.element);var _=S(O,this._dialogTree);_.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[O.HA_MORE_INFO_DIALOG,O.HA_DIALOG,O.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(_,e);var n=((t={})[O.HA_MORE_INFO_DIALOG_INFO]=i.ON_MORE_INFO_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=i.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_SETTINGS]=i.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(n[e],this._haDialogElements)},t.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=f(this._config,H),this._haRootElements=S(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{childList:!0})})),this._dispatchEvent(i.ON_LISTEN,this._haRootElements),this._dispatchEvent(i.ON_PANEL_LOAD,this._haRootElements)},t.prototype._updateLovelaceElements=function(){var e=this,t=Date.now();t-this._timestap<500||(this._timestap=t,this._homeAssistantResolverTree=f(this._config,p,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=S(r,this._homeAssistantResolverTree),this._haResolverElements[r.HA_PANEL_LOVELACE].selector.$.element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t,{childList:!0}),e._dispatchEvent(i.ON_LOVELACE_PANEL_LOAD,_(_({},e._haRootElements),e._haResolverElements)))})))},t.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},t.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,_=((o={})[R.HA_MORE_INFO_DIALOG_INFO]=O.HA_MORE_INFO_DIALOG_INFO,o[R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[R.HA_DIALOG_MORE_INFO_SETTINGS]=O.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in _){var n=e.localName;t._updateDialogElements(_[n])}}))}))},t.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(i.ON_PANEL_LOAD,t._haRootElements),e.localName===R.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},t.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HUI_ROOT&&t._updateLovelaceElements()}))}))},t.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},t.prototype.addEventListener=function(t,o,_){e.prototype.addEventListener.call(this,t,o,_)},t}(G);export{m as HAQuerySelector,i as HAQuerySelectorEvent};
|
package/dist/index.d.ts
CHANGED
|
@@ -23,10 +23,10 @@ declare enum HA_ROOT_ELEMENT {
|
|
|
23
23
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
24
24
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
25
25
|
HA_DRAWER = "HA_DRAWER",
|
|
26
|
-
HA_SIDEBAR = "HA_SIDEBAR"
|
|
26
|
+
HA_SIDEBAR = "HA_SIDEBAR",
|
|
27
|
+
PARTIAL_PANEL_RESOLVER = "PARTIAL_PANEL_RESOLVER"
|
|
27
28
|
}
|
|
28
|
-
declare enum
|
|
29
|
-
PARTIAL_PANEL_RESOLVER = "PARTIAL_PANEL_RESOLVER",
|
|
29
|
+
declare enum HA_LOVELACE_ELEMENT {
|
|
30
30
|
HA_PANEL_LOVELACE = "HA_PANEL_LOVELACE",
|
|
31
31
|
HUI_ROOT = "HUI_ROOT",
|
|
32
32
|
HEADER = "HEADER",
|
|
@@ -41,15 +41,19 @@ declare enum HA_DIALOG_ELEMENT {
|
|
|
41
41
|
HA_DIALOG_MORE_INFO_SETTINGS = "HA_DIALOG_MORE_INFO_SETTINGS"
|
|
42
42
|
}
|
|
43
43
|
declare enum HAQuerySelectorEvent {
|
|
44
|
+
ON_LISTEN = "onListen",
|
|
44
45
|
ON_PANEL_LOAD = "onPanelLoad",
|
|
46
|
+
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad",
|
|
45
47
|
ON_MORE_INFO_DIALOG_OPEN = "onMoreInfoDialogOpen",
|
|
46
48
|
ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onHistoryAndLogBookDialogOpen",
|
|
47
49
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
48
50
|
}
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
51
|
+
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
52
|
+
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
53
|
+
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
54
|
+
type OnMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
55
|
+
type OnHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
56
|
+
type OnSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
|
|
53
57
|
declare class DelegatedEventTarget implements EventTarget {
|
|
54
58
|
private delegate;
|
|
55
59
|
addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
|
|
@@ -77,15 +81,17 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
77
81
|
private _dispatchEvent;
|
|
78
82
|
private _updateDialogElements;
|
|
79
83
|
private _updateRootElements;
|
|
80
|
-
private
|
|
84
|
+
private _updateLovelaceElements;
|
|
81
85
|
private _watchDialogs;
|
|
82
86
|
private _watchDialogsContent;
|
|
83
87
|
private _watchDashboards;
|
|
84
88
|
private _watchLovelace;
|
|
85
89
|
listen(): void;
|
|
86
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
87
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
88
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
89
|
-
addEventListener(type: `${HAQuerySelectorEvent.
|
|
90
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_LISTEN}`, callback: HAQuerySelectorEventListener<OnListenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
91
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnPanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
93
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
94
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
95
|
+
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
90
96
|
}
|
|
91
|
-
export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnLovelacePanelLoadDetail,
|
|
97
|
+
export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnListenDetail, OnPanelLoadDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnHistoryAndLogBookDialogOpenDetail, OnSettingsDialogOpenDetail };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("shadow-dom-selector"),t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},t(e,o)};var o=function(){return o=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var
|
|
1
|
+
"use strict";var e=require("shadow-dom-selector"),t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},t(e,o)};var o=function(){return o=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var _ in t=arguments[o])Object.prototype.hasOwnProperty.call(t,_)&&(e[_]=t[_]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,_,r,O,s,i,a,A,c,l,E,h,I,N,d,L,u="$",R={retries:100,delay:50};!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"}(n||(n={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(_||(_={})),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,(O=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LISTEN="onListen",O.ON_PANEL_LOAD="onPanelLoad",O.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",O.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",O.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",O.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen",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"}(L||(L={}));var H=((s={})[n.HOME_ASSISTANT]={selector:L.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(i={},i[n.HOME_ASSISTANT_MAIN]={selector:L.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(a={},a[n.HA_DRAWER]={selector:L.HA_DRAWER,children:(A={},A[n.HA_SIDEBAR]={selector:L.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},A[n.PARTIAL_PANEL_RESOLVER]={selector:L.PARTIAL_PANEL_RESOLVER},A)},a)}}},i)}}},s),v=((c={})[_.HA_PANEL_LOVELACE]={selector:L.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(l={},l[_.HUI_ROOT]={selector:L.HUI_ROOT,children:{shadowRoot:{selector:u,children:(E={},E[_.HEADER]={selector:L.HEADER},E[_.HUI_VIEW]={selector:L.HUI_VIEW},E)}}},l)}}},c),p={shadowRoot:{selector:u,children:(h={},h[r.HA_MORE_INFO_DIALOG]={selector:L.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(I={},I[r.HA_DIALOG]={selector:L.HA_DIALOG,children:(N={},N[r.HA_DIALOG_CONTENT]={selector:L.HA_DIALOG_CONTENT,children:(d={},d[r.HA_MORE_INFO_DIALOG_INFO]={selector:L.HA_MORE_INFO_DIALOG_INFO},d[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},d[r.HA_DIALOG_MORE_INFO_SETTINGS]={selector:L.HA_DIALOG_MORE_INFO_SETTINGS},d)},N)},I)}}},h)}},D=function(t,n,_,r){return void 0===_&&(_=null),void 0===r&&(r=!1),Object.entries(n||{}).reduce((function(n,O){var s=O[0],i=O[1];if(i.selector===u&&_)return i.children?o(o({},n),D(t,i.children,_,!0)):n;var a=_?_.then((function(o){return e.asyncQuerySelector(o,(n=i.selector,r?"$ "+n:n),t);var n})):e.asyncQuerySelector(i.selector,t);return n[s]={element:a,children:D(t,i.children,a),selector:new e.AsyncSelector(a,t)},n}),{})},S=function(e,t){for(var o=0,n=Object.entries(t);o<n.length;o++){var _=n[o];if(_[0]===e)return _[1];var r=S(e,_[1].children);if(r)return r}},f=function(e,t){return Object.keys(e).reduce((function(e,n){var _=S(n,t);_.children;var r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var _=0;for(n=Object.getOwnPropertySymbols(e);_<n.length;_++)t.indexOf(n[_])<0&&Object.prototype.propertyIsEnumerable.call(e,n[_])&&(o[n[_]]=e[n[_]])}return o}(_,["children"]);return e[n]=o({},r),e}),{})},T=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),G=function(e){function O(t){void 0===t&&(t={});var n=e.call(this)||this;return n._config=o(o({},R),t),n}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(O,e),O.prototype._dispatchEvent=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},O.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=r.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=D(this._config,p,this._haRootElements.HOME_ASSISTANT.element);var n=f(r,this._dialogTree);n.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[r.HA_MORE_INFO_DIALOG,r.HA_DIALOG,r.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(n,e);var _=((t={})[r.HA_MORE_INFO_DIALOG_INFO]=exports.HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=exports.HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_SETTINGS]=exports.HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(_[e],this._haDialogElements)},O.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=D(this._config,H),this._haRootElements=f(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{childList:!0})})),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LISTEN,this._haRootElements),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements)},O.prototype._updateLovelaceElements=function(){var e=this,t=Date.now();t-this._timestap<500||(this._timestap=t,this._homeAssistantResolverTree=D(this._config,v,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=f(_,this._homeAssistantResolverTree),this._haResolverElements[_.HA_PANEL_LOVELACE].selector.$.element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t,{childList:!0}),e._dispatchEvent(exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,o(o({},e._haRootElements),e._haResolverElements)))})))},O.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},O.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,n=((o={})[L.HA_MORE_INFO_DIALOG_INFO]=r.HA_MORE_INFO_DIALOG_INFO,o[L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[L.HA_DIALOG_MORE_INFO_SETTINGS]=r.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in n){var _=e.localName;t._updateDialogElements(n[_])}}))}))},O.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,t._haRootElements),e.localName===L.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},O.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HUI_ROOT&&t._updateLovelaceElements()}))}))},O.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},O.prototype.addEventListener=function(t,o,n){e.prototype.addEventListener.call(this,t,o,n)},O}(T);exports.HAQuerySelector=G;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "home-assistant-query-selector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Easily query home-assistant DOM elements in an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -36,18 +36,19 @@
|
|
|
36
36
|
"url": "git+https://github.com/elchininet/home-assistant-query-selector"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"clean": "rm -rf dist
|
|
39
|
+
"clean": "rm -rf dist || true",
|
|
40
|
+
"test:clean": "rm -rf .nyc_output coverage || true",
|
|
40
41
|
"build": "yarn clean && rollup --config rollup.config.js --bundleConfigAsCjs",
|
|
41
42
|
"lint": "eslint \"src/**/*.ts\"",
|
|
42
43
|
"coverage:report": "nyc report --reporter=lcov --reporter=text-summary",
|
|
43
44
|
"test:ts": "tsc --noEmit",
|
|
44
|
-
"test:run": "
|
|
45
|
-
"test:open": "
|
|
46
|
-
"test:ci": "yarn demo:ha && yarn
|
|
47
|
-
"test:copy": "cp test/index.js .hass/config/www/home-assistant-query-selector-tests.js",
|
|
45
|
+
"test:run": "playwright test",
|
|
46
|
+
"test:open": "playwright test --ui",
|
|
47
|
+
"test:ci": "yarn demo:ha && yarn start:playwright && yarn stop:ha",
|
|
48
48
|
"start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant:2023.12.4",
|
|
49
49
|
"stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:2023.12.4) || true",
|
|
50
|
-
"demo:ha": "yarn
|
|
50
|
+
"demo:ha": "yarn test:clean && yarn build && yarn start:ha",
|
|
51
|
+
"start:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright:v1.40.0-jammy sh -c \"yarn test:run && exit\"",
|
|
51
52
|
"prepare": "yarn build",
|
|
52
53
|
"prepublishOnly": "yarn lint && yarn test:ts && yarn test:ci",
|
|
53
54
|
"version": "git add .",
|
|
@@ -57,19 +58,22 @@
|
|
|
57
58
|
"shadow-dom-selector": "^4.1.2"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@
|
|
61
|
+
"@playwright/test": "^1.40.1",
|
|
61
62
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
62
63
|
"@types/eslint": "^8.56.0",
|
|
64
|
+
"@types/node": "^20.10.6",
|
|
65
|
+
"@types/sinon": "^17.0.2",
|
|
63
66
|
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
|
64
67
|
"@typescript-eslint/parser": "^6.16.0",
|
|
65
|
-
"cypress": "13.6.1",
|
|
66
|
-
"cypress-wait-until": "^3.0.1",
|
|
67
68
|
"eslint": "^8.56.0",
|
|
69
|
+
"nyc": "^15.1.0",
|
|
70
|
+
"playwright-test-coverage": "^1.2.12",
|
|
68
71
|
"rollup": "^4.9.2",
|
|
69
72
|
"rollup-plugin-istanbul": "^5.0.0",
|
|
70
73
|
"rollup-plugin-serve": "^2.0.3",
|
|
71
74
|
"rollup-plugin-terser": "^7.0.2",
|
|
72
75
|
"rollup-plugin-ts": "^3.4.5",
|
|
76
|
+
"sinon": "^17.0.1",
|
|
73
77
|
"typescript": "^5.3.3"
|
|
74
78
|
}
|
|
75
79
|
}
|