home-assistant-query-selector 1.0.0 → 1.1.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 +179 -37
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/test/index.d.ts +5 -2
- package/dist/test/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
# home-assistant-query-selector (HAQuerySelector)
|
|
2
2
|
|
|
3
|
-
Easily query [Home Assistant] DOM elements in an
|
|
3
|
+
Easily query [Home Assistant] DOM elements in an asynchronous way.
|
|
4
4
|
|
|
5
5
|
[](https://github.com/elchininet/home-assistant-query-selector/actions/workflows/deploy.yaml) [](https://coveralls.io/github/elchininet/home-assistant-query-selector?branch=master) [](https://badge.fury.io/js/home-assistant-query-selector)
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
8
8
|
|
|
9
|
-
When one wants to build a `Home Assistant` front-end plugin, like many of the ones published in [HACS], first thing to do
|
|
9
|
+
When one wants to build a `Home Assistant` front-end plugin, like many of the ones published in [HACS], most of the time first thing to do is dealing with query-selection of `DOM` elements. This is a tedius task, because `Home Assistant` elements are custom [WebComponents], so when the `DOM` loads, most of those elements don‘t exist, they will be created in an asynchronous way and not all of them at the same time. On top of that, as they are `WebComponents`, many of them have their own `DOM` subtree under a [ShadowDOM], something that makes the task of query-selecting elements double tedious.
|
|
10
10
|
|
|
11
|
-
As I develop and maintain several Home Assistant plugins that
|
|
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
|
|
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 them to be created and rendered in the `DOM`, and after that, a function that you have created gets automatically executed. 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
|
+
|
|
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.
|
|
16
18
|
|
|
17
19
|

|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
### Code example
|
|
22
|
+
|
|
23
|
+
More details of the API can be consulted in [the API section](#api):
|
|
20
24
|
|
|
21
25
|
```typescript
|
|
22
26
|
import { HAQuerySelector } from 'home-assistant-query-selector';
|
|
@@ -24,25 +28,56 @@ import { HAQuerySelector } from 'home-assistant-query-selector';
|
|
|
24
28
|
const instance = new HAQuerySelector();
|
|
25
29
|
|
|
26
30
|
//This event will be triggered every time the lovelace dashboard changes
|
|
27
|
-
instance.addEventListener('onLovelacePanelLoad', ({detail}) => {
|
|
31
|
+
instance.addEventListener('onLovelacePanelLoad', ({ detail }) => {
|
|
32
|
+
|
|
33
|
+
const { HEADER, HA_SIDEBAR, HOME_ASSISTANT, HA_PANEL_LOVELACE } = detail;
|
|
28
34
|
|
|
29
|
-
// When the header
|
|
30
|
-
|
|
35
|
+
// When the header is available in the DOM
|
|
36
|
+
HEADER.element
|
|
31
37
|
.then((header) => {
|
|
32
38
|
// Do whatever we want with the header
|
|
33
39
|
});
|
|
34
40
|
|
|
35
|
-
// When the sidebar
|
|
36
|
-
|
|
41
|
+
// When the sidebar is available in the DOM
|
|
42
|
+
HA_SIDEBAR.then((sidebar) => {
|
|
37
43
|
// Do whatever we want with the sidebar
|
|
38
44
|
});
|
|
45
|
+
|
|
46
|
+
// Querying the ha-sidebar element from the home-assistant element
|
|
47
|
+
HOME_ASSISTANT.querySelector('$ home-assistant-main$ ha-sidebar')
|
|
48
|
+
.then((sidebar) => {
|
|
49
|
+
// sidebar === ha-sidebar element
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Querying all the ha-icon-button elements inside the .action-items in the header
|
|
53
|
+
HEADER.querySelectorAll('.action-items ha-icon-button')
|
|
54
|
+
.then((buttons) => {
|
|
55
|
+
// buttons === Search, Assist, and Open dashboard menu elements (top-right header buttons)
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// In all the methods one can Specify custom retries and delay
|
|
59
|
+
HA_PANEL_LOVELACE.shadowRootQuerySelector('$ hui-root$', { retries: 50, delay: 20 })
|
|
60
|
+
.then((shadowRoot) => {
|
|
61
|
+
// shadowRoot === hui-root‘s shadowRoot
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// This event will be triggered every time a more-info dialog is open
|
|
67
|
+
instance.addEventListener('onLovelaveMoreInfoDialogOpen', ({ detail }) => {
|
|
68
|
+
|
|
69
|
+
// When the ha-more-info-info element is available in the DOM
|
|
70
|
+
detail.HA_MORE_INFO_DIALOG_INFO.element.then((dialogInfo) => {
|
|
71
|
+
// Do whatever we want with the dialogInfo element
|
|
72
|
+
});
|
|
73
|
+
|
|
39
74
|
});
|
|
40
75
|
|
|
41
76
|
// Start to listen
|
|
42
77
|
instance.listen();
|
|
43
78
|
```
|
|
44
79
|
|
|
45
|
-
## Installation
|
|
80
|
+
## Installation of the library
|
|
46
81
|
|
|
47
82
|
#### npm
|
|
48
83
|
|
|
@@ -88,7 +123,7 @@ new HAQuerySelector([config])
|
|
|
88
123
|
|
|
89
124
|
### Public methods
|
|
90
125
|
|
|
91
|
-
`HAQuerySelector` instances count with a public method.
|
|
126
|
+
`HAQuerySelector` instances count with a public method. When it is called, this method will trigger the `onLovelacePanelLoad` event inmediatly and start to watchg for changes in the `DOM` to trigger the proper events.
|
|
92
127
|
|
|
93
128
|
```typescript
|
|
94
129
|
instance.listen();
|
|
@@ -96,7 +131,11 @@ instance.listen();
|
|
|
96
131
|
|
|
97
132
|
### Events
|
|
98
133
|
|
|
99
|
-
The `HAQuerySelector` class extends from [EventTarget], so it is possible to add events listeners to it. It will dispatch
|
|
134
|
+
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`.
|
|
135
|
+
|
|
136
|
+
#### onLovelacePanelLoad
|
|
137
|
+
|
|
138
|
+
This event is triggered when [the listen method](#public-methods) is called or when the lovelace dashboard is rendered (every time that, after being abandoned the the lovelace dashboard containing your code you return to it).
|
|
100
139
|
|
|
101
140
|
```typescript
|
|
102
141
|
instance.addEventListener('onLovelacePanelLoad', function({detail}) {
|
|
@@ -105,19 +144,17 @@ instance.addEventListener('onLovelacePanelLoad', function({detail}) {
|
|
|
105
144
|
HOME_ASSISTANT: {...},
|
|
106
145
|
HOME_ASSISTANT_MAIN: {...},
|
|
107
146
|
HA_DRAWER: {...},
|
|
108
|
-
HA_SIDEBAR: {...},
|
|
109
|
-
PARTIAL_PANEL_RESOLVER: {...},
|
|
110
147
|
...
|
|
111
148
|
}
|
|
112
149
|
*/
|
|
113
150
|
});
|
|
114
151
|
```
|
|
115
152
|
|
|
116
|
-
The dispatched event is a [CustomEvent] and its `detail` property is an object containing
|
|
153
|
+
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.
|
|
117
154
|
|
|
118
|
-
|
|
155
|
+
##### onLovelacePanelLoad event elements
|
|
119
156
|
|
|
120
|
-
This is the list of the elements available inside the `
|
|
157
|
+
This is the list of the elements available inside the `detail` property of the `onLovelacePanelLoad` event:
|
|
121
158
|
|
|
122
159
|

|
|
123
160
|
|
|
@@ -133,37 +170,142 @@ This is the list of the elements available inside the `CustomEvent` `detail` pro
|
|
|
133
170
|
| `HEADER` | `.header` |
|
|
134
171
|
| `HUI_VIEW` | `hui-view` |
|
|
135
172
|
|
|
136
|
-
All the available elements contain
|
|
173
|
+
All the available elements contain an `element` property and three methods:
|
|
137
174
|
|
|
138
175
|
| Property or method | Description |
|
|
139
176
|
| ------------------------- | ------------------------------------------------------------ |
|
|
140
|
-
| `element` | Promise that resolves in the DOM element |
|
|
177
|
+
| `element` | Promise that resolves in the respective `DOM` element |
|
|
141
178
|
| `querySelector` | Method to query for descendants of this element |
|
|
142
|
-
| `querySelectorAll` | Method to query multiple decendants
|
|
179
|
+
| `querySelectorAll` | Method to query multiple decendants of this element |
|
|
143
180
|
| `shadowRootQuerySelector` | Method to query for descendants shadowRoots of this element |
|
|
144
181
|
|
|
145
|
-
|
|
182
|
+
#### onLovelaveMoreInfoDialogOpen
|
|
146
183
|
|
|
147
|
-
|
|
184
|
+
This event is triggered when a more-info dialog is open or when one returns to the main view of the more-info dialog from the `History` or `Settings` view inside the dialog.
|
|
148
185
|
|
|
149
186
|
```typescript
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
187
|
+
instance.addEventListener('onLovelaveMoreInfoDialogOpen', function({detail}) {
|
|
188
|
+
/* detail:
|
|
189
|
+
{
|
|
190
|
+
HA_MORE_INFO_DIALOG: {...},
|
|
191
|
+
HA_DIALOG: {...},
|
|
192
|
+
HA_DIALOG_CONTENT: {...},
|
|
193
|
+
...
|
|
194
|
+
}
|
|
195
|
+
*/
|
|
196
|
+
});
|
|
197
|
+
```
|
|
154
198
|
|
|
155
|
-
detail.
|
|
156
|
-
.then((buttons) => {
|
|
157
|
-
// buttons === Search, Assist, and Open dashboard menu elements (top-right header buttons)
|
|
158
|
-
});
|
|
199
|
+
The dispatched event is a [CustomEvent] and its `detail` property is an object containing the main `Home Assistant` `DOM` elements inside a more-info dialog. 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.
|
|
159
200
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
201
|
+
##### onLovelaveMoreInfoDialogOpen event elements
|
|
202
|
+
|
|
203
|
+
This is the list of the elements available inside the `detail` property of the `onLovelaveMoreInfoDialogOpen` event:
|
|
204
|
+
|
|
205
|
+

|
|
206
|
+
|
|
207
|
+
| Detail element | DOM element |
|
|
208
|
+
| -------------------------- | ------------------------ |
|
|
209
|
+
| `HA_MORE_INFO_DIALOG` | `ha-more-info-dialog` |
|
|
210
|
+
| `HA_DIALOG` | `ha-dialog` |
|
|
211
|
+
| `HA_DIALOG_CONTENT` | `.content` |
|
|
212
|
+
| `HA_MORE_INFO_DIALOG_INFO` | `ha-more-info-info` |
|
|
213
|
+
|
|
214
|
+
All the available elements contain an `element` property and three methods:
|
|
215
|
+
|
|
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 |
|
|
222
|
+
|
|
223
|
+
#### onLovelaveHistoryAndLogBookDialogOpen
|
|
224
|
+
|
|
225
|
+
This event is triggered when the `History` view is opened from the header actions of a more-info dialog.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
instance.addEventListener('onLovelaveHistoryAndLogBookDialogOpen', function({detail}) {
|
|
229
|
+
/* detail:
|
|
230
|
+
{
|
|
231
|
+
HA_MORE_INFO_DIALOG: {...},
|
|
232
|
+
HA_DIALOG: {...},
|
|
233
|
+
HA_DIALOG_CONTENT: {...},
|
|
234
|
+
...
|
|
235
|
+
}
|
|
236
|
+
*/
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The dispatched event is a [CustomEvent] and its `detail` property is an object containing the main `Home Assistant` `DOM` elements inside a more-info dialog `History` view. 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.
|
|
241
|
+
|
|
242
|
+
##### onLovelaveHistoryAndLogBookDialogOpen event elements
|
|
243
|
+
|
|
244
|
+
This is the list of the elements available inside the `detail` property of the `onLovelaveHistoryAndLogBookDialogOpen` event:
|
|
245
|
+
|
|
246
|
+

|
|
247
|
+
|
|
248
|
+
| Detail element | DOM element |
|
|
249
|
+
| ----------------------------------------- | ---------------------------------- |
|
|
250
|
+
| `HA_MORE_INFO_DIALOG` | `ha-more-info-dialog` |
|
|
251
|
+
| `HA_DIALOG` | `ha-dialog` |
|
|
252
|
+
| `HA_DIALOG_CONTENT` | `.content` |
|
|
253
|
+
| `HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK` | `ha-more-info-history-and-logbook` |
|
|
254
|
+
|
|
255
|
+
All the available elements contain an `element` property and three methods:
|
|
256
|
+
|
|
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 |
|
|
263
|
+
|
|
264
|
+
#### onLovelaveSettingsDialogOpen
|
|
265
|
+
|
|
266
|
+
This event is triggered when the `Settings` view is opened from the header actions of a more-info dialog.
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
instance.addEventListener('onLovelaveSettingsDialogOpen', function({detail}) {
|
|
270
|
+
/* detail:
|
|
271
|
+
{
|
|
272
|
+
HA_MORE_INFO_DIALOG: {...},
|
|
273
|
+
HA_DIALOG: {...},
|
|
274
|
+
HA_DIALOG_CONTENT: {...},
|
|
275
|
+
...
|
|
276
|
+
}
|
|
277
|
+
*/
|
|
278
|
+
});
|
|
165
279
|
```
|
|
166
280
|
|
|
281
|
+
The dispatched event is a [CustomEvent] and its `detail` property is an object containing the main `Home Assistant` `DOM` elements inside a more-info dialog `Settings` view. 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.
|
|
282
|
+
|
|
283
|
+
##### onLovelaveSettingsDialogOpen event elements
|
|
284
|
+
|
|
285
|
+
This is the list of the elements available inside the `detail` property of the `onLovelaveSettingsDialogOpen` event:
|
|
286
|
+
|
|
287
|
+

|
|
288
|
+
|
|
289
|
+
| Detail element | DOM element |
|
|
290
|
+
| ------------------------------ | ----------------------- |
|
|
291
|
+
| `HA_MORE_INFO_DIALOG` | `ha-more-info-dialog` |
|
|
292
|
+
| `HA_DIALOG` | `ha-dialog` |
|
|
293
|
+
| `HA_DIALOG_CONTENT` | `.content` |
|
|
294
|
+
| `HA_DIALOG_MORE_INFO_SETTINGS` | `ha-more-info-settings` |
|
|
295
|
+
|
|
296
|
+
All the available elements contain an `element` property and three methods:
|
|
297
|
+
|
|
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 |
|
|
304
|
+
|
|
305
|
+
### Note
|
|
306
|
+
|
|
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].
|
|
308
|
+
|
|
167
309
|
|
|
168
310
|
[Home Assistant]: https://www.home-assistant.io
|
|
169
311
|
[HACS]: https://hacs.xyz
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,11 +20,14 @@ type HomeAssistantElement = {
|
|
|
20
20
|
[key: string]: ElementProps;
|
|
21
21
|
};
|
|
22
22
|
declare enum HAQuerySelectorEvent {
|
|
23
|
-
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad"
|
|
23
|
+
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad",
|
|
24
|
+
ON_LOVELACE_MORE_INFO_DIALOG_OPEN = "onLovelaveMoreInfoDialogOpen",
|
|
25
|
+
ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onLovelaveHistoryAndLogBookDialogOpen",
|
|
26
|
+
ON_LOVELACE_SETTINGS_DIALOG_OPEN = "onLovelaveSettingsDialogOpen"
|
|
24
27
|
}
|
|
25
28
|
declare class HAQuerySelector extends EventTarget {
|
|
26
29
|
#private;
|
|
27
30
|
constructor(config?: HAQuerySelectorConfig);
|
|
28
31
|
listen(): void;
|
|
29
32
|
}
|
|
30
|
-
export { HAQuerySelector,
|
|
33
|
+
export { HAQuerySelector, HomeAssistantElement, HAQuerySelectorEvent };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function t(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function n(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const r="$",o={retries:100,delay:50};var i,c,s,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"}(i||(i={})),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"}(c||(c={})),function(e){e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad"}(s||(s={})),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"}(a||(a={}));const l={[i.HOME_ASSISTANT]:{selector:a.HOME_ASSISTANT,children:{shadowRoot:{selector:r,children:{[i.HOME_ASSISTANT_MAIN]:{selector:a.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:r,children:{[i.HA_DRAWER]:{selector:a.HA_DRAWER,children:{[i.HA_SIDEBAR]:{selector:a.HA_SIDEBAR,children:{shadowRoot:{selector:r}}}}}}}}}}}}}},u={[c.PARTIAL_PANEL_RESOLVER]:{selector:a.PARTIAL_PANEL_RESOLVER,children:{[c.HA_PANEL_LOVELACE]:{selector:a.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:r,children:{[c.HUI_ROOT]:{selector:a.HUI_ROOT,children:{shadowRoot:{selector:r,children:{[c.HEADER]:{selector:a.HEADER},[c.HUI_VIEW]:{selector:a.HUI_VIEW}}}}}}}}}}}};function h(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,r=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){c.label=s[1];break}if(6===s[0]&&c.label<o[1]){c.label=o[1],o=s;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(s);break}o[2]&&c.ops.pop(),c.trys.pop();continue}s=t.call(e,c)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}"function"==typeof SuppressedError&&SuppressedError;var d="$",v=":host",A="invalid selector",E=10,w=10,y=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function p(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(d).map((function(e){return e.trim()}))}(e);return t(n)}))}function b(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var c=0,s=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++c<n?setTimeout(s,r):i(o?document.querySelectorAll(A):null)};s()}))}function S(e,t,n){return new Promise((function(r){var o=0,i=function(){var c=e.shadowRoot;c?r(c):++o<t?setTimeout(i,n):r(null)};i()}))}function _(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(d,").").concat(n)}function O(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(d,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function R(){return"You can not select a shadowRoot (".concat(d,") of the document.")}function m(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s,a,l;return f(this,(function(u){switch(u.label){case 0:o=null,i=e.length,c=0,u.label=1;case 1:if(!(c<i))return[3,15];if(0!==c)return[3,8];if(e[c].length)return[3,5];if(t instanceof Document)throw new SyntaxError(R());return t.shadowRoot?[4,b(t.shadowRoot,e[++c],n,r)]:[3,3];case 2:return s=u.sent(),[3,4];case 3:s=null,u.label=4;case 4:return o=s,[3,7];case 5:return[4,b(t,e[c],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,S(o,n,r)];case 9:return(a=u.sent())?[4,b(a,"".concat(v," ").concat(e[c]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return c++,[3,1];case 15:return[2,o]}}))}))}function L(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s,a,l;return f(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,b(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,m(o,t,n,r)];case 3:return(c=u.sent())?[4,S(c,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(s=a)?[4,b(s,"".concat(v," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function g(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i;return f(this,(function(c){switch(c.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(R());return[2,S(t,n,r)]}return[4,m(e,t,n,r)];case 1:return(o=c.sent())?[4,S(o,n,r)]:[3,3];case 2:return i=c.sent(),[3,4];case 3:i=null,c.label=4;case 4:return[2,i]}}))}))}function I(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=p(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(_("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,m(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function H(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=p(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(_("asyncQuerySelectorAll"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,L(o[c],t,n,r)]:[3,4];case 2:if(null==(s=a.sent())?void 0:s.length)return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,document.querySelectorAll(A)]}}))}))}function T(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=p(e,(function(e){if(e.pop().length)throw new SyntaxError(O("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,g(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function N(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,I(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:case 3:return[2,c.sent()];case 2:return o=e[0],i=e[1],[4,I(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}const P=(t,n,o=null,i=!1)=>Object.entries(n||{}).reduce(((n,c)=>{const[s,a]=c;if(a.selector===r&&o)return a.children?Object.assign(Object.assign({},n),P(t,a.children,o,!0)):n;const l=o?o.then((e=>{return N(e,(n=a.selector,i?"$ "+n:n),t);var n})):N(a.selector,t);return n[s]={element:l,children:P(t,a.children,l),querySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield N(e,n,Object.assign(Object.assign({},t),r))}))},querySelectorAll(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,H(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,H(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))},shadowRootQuerySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,T(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,T(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))}},n}),{}),M=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=M(e,t[1].children);if(n)return n}}},j=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(M(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var D,V,W,x,k,C,U,q,Q,B,$,G;class Y extends EventTarget{constructor(e={}){super(),D.add(this),V.set(this,void 0),W.set(this,void 0),x.set(this,void 0),k.set(this,void 0),C.set(this,void 0),U.set(this,void 0),q.set(this,void 0),n(this,V,Object.assign(Object.assign({},o),e),"f")}listen(){var e;n(this,q,t(this,D,"m",G).bind(this),"f"),t(this,D,"m",B).call(this),t(this,D,"m",$).call(this),null===(e=t(this,U,"f"))||void 0===e||e.disconnect(),n(this,U,new MutationObserver(t(this,q,"f")),"f"),t(this,C,"f")[c.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,U,"f").observe(e,{childList:!0})}))}}V=new WeakMap,W=new WeakMap,x=new WeakMap,k=new WeakMap,C=new WeakMap,U=new WeakMap,q=new WeakMap,D=new WeakSet,Q=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},B=function(){n(this,W,P(t(this,V,"f"),l),"f"),n(this,k,j(i,t(this,W,"f")),"f")},$=function(){n(this,x,P(t(this,V,"f"),u,t(this,k,"f")[i.HA_DRAWER].element),"f"),n(this,C,j(c,t(this,x,"f")),"f"),t(this,D,"m",Q).call(this,s.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,k,"f")),t(this,C,"f")))},G=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===a.HA_PANEL_LOVELACE&&t(this,D,"m",$).call(this)}))}))};export{Y as HAQuerySelector,s as HAQuerySelectorEvent};
|
|
1
|
+
function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function t(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function n(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const r="$",o={retries:100,delay:50};var i,s,c,a,l;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(i||(i={})),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"}(s||(s={})),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="onLovelaveMoreInfoDialogOpen",e.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaveHistoryAndLogBookDialogOpen",e.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaveSettingsDialogOpen"}(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"}(l||(l={}));const u={[i.HOME_ASSISTANT]:{selector:l.HOME_ASSISTANT,children:{shadowRoot:{selector:r,children:{[i.HOME_ASSISTANT_MAIN]:{selector:l.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:r,children:{[i.HA_DRAWER]:{selector:l.HA_DRAWER,children:{[i.HA_SIDEBAR]:{selector:l.HA_SIDEBAR,children:{shadowRoot:{selector:r}}}}}}}}}}}}}},O={[s.PARTIAL_PANEL_RESOLVER]:{selector:l.PARTIAL_PANEL_RESOLVER,children:{[s.HA_PANEL_LOVELACE]:{selector:l.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:r,children:{[s.HUI_ROOT]:{selector:l.HUI_ROOT,children:{shadowRoot:{selector:r,children:{[s.HEADER]:{selector:l.HEADER},[s.HUI_VIEW]:{selector:l.HUI_VIEW}}}}}}}}}}}},_={shadowRoot:{selector:r,children:{[c.HA_MORE_INFO_DIALOG]:{selector:l.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:r,children:{[c.HA_DIALOG]:{selector:l.HA_DIALOG,children:{[c.HA_DIALOG_CONTENT]:{selector:l.HA_DIALOG_CONTENT,children:{[c.HA_MORE_INFO_DIALOG_INFO]:{selector:l.HA_MORE_INFO_DIALOG_INFO},[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:l.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[c.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:l.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};function h(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function A(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var f="$",d=":host",E="invalid selector",I=10,N=10,L=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function v(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(f).map((function(e){return e.trim()}))}(e);return t(n)}))}function R(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var s=0,c=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++s<n?setTimeout(c,r):i(o?document.querySelectorAll(E):null)};c()}))}function S(e,t,n){return new Promise((function(r){var o=0,i=function(){var s=e.shadowRoot;s?r(s):++o<t?setTimeout(i,n):r(null)};i()}))}function H(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(f,").").concat(n)}function w(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(f,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function T(){return"You can not select a shadowRoot (".concat(f,") of the document.")}function D(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c,a,l;return A(this,(function(u){switch(u.label){case 0:o=null,i=e.length,s=0,u.label=1;case 1:if(!(s<i))return[3,15];if(0!==s)return[3,8];if(e[s].length)return[3,5];if(t instanceof Document)throw new SyntaxError(T());return t.shadowRoot?[4,R(t.shadowRoot,e[++s],n,r)]:[3,3];case 2:return c=u.sent(),[3,4];case 3:c=null,u.label=4;case 4:return o=c,[3,7];case 5:return[4,R(t,e[s],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,S(o,n,r)];case 9:return(a=u.sent())?[4,R(a,"".concat(d," ").concat(e[s]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return s++,[3,1];case 15:return[2,o]}}))}))}function p(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c,a,l;return A(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,R(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,D(o,t,n,r)];case 3:return(s=u.sent())?[4,S(s,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(c=a)?[4,R(c,"".concat(d," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function y(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i;return A(this,(function(s){switch(s.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(T());return[2,S(t,n,r)]}return[4,D(e,t,n,r)];case 1:return(o=s.sent())?[4,S(o,n,r)]:[3,3];case 2:return i=s.sent(),[3,4];case 3:i=null,s.label=4;case 4:return[2,i]}}))}))}function b(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(H("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,D(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function G(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(H("asyncQuerySelectorAll"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,p(o[s],t,n,r)]:[3,4];case 2:if(null==(c=a.sent())?void 0:c.length)return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,document.querySelectorAll(E)]}}))}))}function M(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(e.pop().length)throw new SyntaxError(w("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,y(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function m(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,b(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:case 3:return[2,s.sent()];case 2:return o=e[0],i=e[1],[4,b(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}const g=(t,n,o=null,i=!1)=>Object.entries(n||{}).reduce(((n,s)=>{const[c,a]=s;if(a.selector===r&&o)return a.children?Object.assign(Object.assign({},n),g(t,a.children,o,!0)):n;const l=o?o.then((e=>{return m(e,(n=a.selector,i?"$ "+n:n),t);var n})):m(a.selector,t);return n[c]={element:l,children:g(t,a.children,l),querySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield m(e,n,Object.assign(Object.assign({},t),r))}))},querySelectorAll(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,G(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,G(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))},shadowRootQuerySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,M(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,M(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))}},n}),{}),F=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=F(e,t[1].children);if(n)return n}}},P=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(F(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var V,W,C,j,k,x,B,Y,K,U,Q,q,$,z,J,X,Z,ee,te,ne,re;class oe extends EventTarget{constructor(e={}){super(),V.add(this),W.set(this,void 0),C.set(this,void 0),j.set(this,void 0),k.set(this,void 0),x.set(this,void 0),B.set(this,void 0),Y.set(this,void 0),K.set(this,void 0),U.set(this,void 0),Q.set(this,void 0),q.set(this,void 0),$.set(this,void 0),z.set(this,void 0),n(this,W,Object.assign(Object.assign({},o),e),"f")}listen(){n(this,q,t(this,V,"m",te).bind(this),"f"),n(this,$,t(this,V,"m",ne).bind(this),"f"),n(this,z,t(this,V,"m",re).bind(this),"f"),n(this,K,new MutationObserver(t(this,q,"f")),"f"),n(this,U,new MutationObserver(t(this,$,"f")),"f"),n(this,Q,new MutationObserver(t(this,z,"f")),"f"),t(this,V,"m",Z).call(this),t(this,V,"m",ee).call(this)}}W=new WeakMap,C=new WeakMap,j=new WeakMap,k=new WeakMap,x=new WeakMap,B=new WeakMap,Y=new WeakMap,K=new WeakMap,U=new WeakMap,Q=new WeakMap,q=new WeakMap,$=new WeakMap,z=new WeakMap,V=new WeakSet,J=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},X=function(e=c.HA_MORE_INFO_DIALOG_INFO){n(this,C,g(t(this,W,"f"),_,t(this,B,"f").HOME_ASSISTANT.element),"f");const r=P(c,t(this,C,"f"));r.HA_DIALOG_CONTENT.element.then((e=>{t(this,U,"f").disconnect(),t(this,U,"f").observe(e,{childList:!0})})),n(this,x,((e,t)=>[c.HA_MORE_INFO_DIALOG,c.HA_DIALOG,c.HA_DIALOG_CONTENT,t].reduce(((t,n)=>(t[n]=e[n],t)),{}))(r,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};t(this,V,"m",J).call(this,o[e],t(this,x,"f"))},Z=function(){n(this,j,g(t(this,W,"f"),u),"f"),n(this,B,P(i,t(this,j,"f")),"f"),t(this,B,"f")[i.HOME_ASSISTANT].shadowRootQuerySelector("$").then((e=>{t(this,K,"f").disconnect(),t(this,K,"f").observe(e,{childList:!0})}))},ee=function(){n(this,k,g(t(this,W,"f"),O,t(this,B,"f")[i.HA_DRAWER].element),"f"),n(this,Y,P(s,t(this,k,"f")),"f"),t(this,Y,"f")[s.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,Q,"f").disconnect(),t(this,Q,"f").observe(e,{childList:!0})})),t(this,V,"m",J).call(this,a.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,B,"f")),t(this,Y,"f")))},te=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===l.HA_MORE_INFO_DIALOG&&t(this,V,"m",X).call(this)}))}))},ne=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const n={[l.HA_MORE_INFO_DIALOG_INFO]:c.HA_MORE_INFO_DIALOG_INFO,[l.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[l.HA_DIALOG_MORE_INFO_SETTINGS]:c.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in n){const r=e.localName;t(this,V,"m",X).call(this,n[r])}}))}))},re=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===l.HA_PANEL_LOVELACE&&t(this,V,"m",ee).call(this)}))}))};export{oe as HAQuerySelector,a as HAQuerySelectorEvent};
|
package/dist/index.d.ts
CHANGED
|
@@ -20,11 +20,14 @@ type HomeAssistantElement = {
|
|
|
20
20
|
[key: string]: ElementProps;
|
|
21
21
|
};
|
|
22
22
|
declare enum HAQuerySelectorEvent {
|
|
23
|
-
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad"
|
|
23
|
+
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad",
|
|
24
|
+
ON_LOVELACE_MORE_INFO_DIALOG_OPEN = "onLovelaveMoreInfoDialogOpen",
|
|
25
|
+
ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onLovelaveHistoryAndLogBookDialogOpen",
|
|
26
|
+
ON_LOVELACE_SETTINGS_DIALOG_OPEN = "onLovelaveSettingsDialogOpen"
|
|
24
27
|
}
|
|
25
28
|
declare class HAQuerySelector extends EventTarget {
|
|
26
29
|
#private;
|
|
27
30
|
constructor(config?: HAQuerySelectorConfig);
|
|
28
31
|
listen(): void;
|
|
29
32
|
}
|
|
30
|
-
export { HAQuerySelector,
|
|
33
|
+
export { HAQuerySelector, HomeAssistantElement, HAQuerySelectorEvent };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function t(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function n(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const r="$",o={retries:100,delay:50};var i,c,s;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(i||(i={})),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"}(c||(c={})),exports.HAQuerySelectorEvent=void 0,(exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",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"}(s||(s={}));const a={[i.HOME_ASSISTANT]:{selector:s.HOME_ASSISTANT,children:{shadowRoot:{selector:r,children:{[i.HOME_ASSISTANT_MAIN]:{selector:s.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:r,children:{[i.HA_DRAWER]:{selector:s.HA_DRAWER,children:{[i.HA_SIDEBAR]:{selector:s.HA_SIDEBAR,children:{shadowRoot:{selector:r}}}}}}}}}}}}}},l={[c.PARTIAL_PANEL_RESOLVER]:{selector:s.PARTIAL_PANEL_RESOLVER,children:{[c.HA_PANEL_LOVELACE]:{selector:s.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:r,children:{[c.HUI_ROOT]:{selector:s.HUI_ROOT,children:{shadowRoot:{selector:r,children:{[c.HEADER]:{selector:s.HEADER},[c.HUI_VIEW]:{selector:s.HUI_VIEW}}}}}}}}}}}};function u(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function h(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,r=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){c.label=s[1];break}if(6===s[0]&&c.label<o[1]){c.label=o[1],o=s;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(s);break}o[2]&&c.ops.pop(),c.trys.pop();continue}s=t.call(e,c)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}"function"==typeof SuppressedError&&SuppressedError;var f="$",d=":host",v="invalid selector",A=10,E=10,w=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function y(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(f).map((function(e){return e.trim()}))}(e);return t(n)}))}function p(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var c=0,s=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++c<n?setTimeout(s,r):i(o?document.querySelectorAll(v):null)};s()}))}function S(e,t,n){return new Promise((function(r){var o=0,i=function(){var c=e.shadowRoot;c?r(c):++o<t?setTimeout(i,n):r(null)};i()}))}function b(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(f,").").concat(n)}function _(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(f,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function O(){return"You can not select a shadowRoot (".concat(f,") of the document.")}function R(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i,c,s,a,l;return h(this,(function(u){switch(u.label){case 0:o=null,i=e.length,c=0,u.label=1;case 1:if(!(c<i))return[3,15];if(0!==c)return[3,8];if(e[c].length)return[3,5];if(t instanceof Document)throw new SyntaxError(O());return t.shadowRoot?[4,p(t.shadowRoot,e[++c],n,r)]:[3,3];case 2:return s=u.sent(),[3,4];case 3:s=null,u.label=4;case 4:return o=s,[3,7];case 5:return[4,p(t,e[c],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,S(o,n,r)];case 9:return(a=u.sent())?[4,p(a,"".concat(d," ").concat(e[c]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return c++,[3,1];case 15:return[2,o]}}))}))}function m(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i,c,s,a,l;return h(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,p(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,R(o,t,n,r)];case 3:return(c=u.sent())?[4,S(c,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(s=a)?[4,p(s,"".concat(d," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function H(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i;return h(this,(function(c){switch(c.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(O());return[2,S(t,n,r)]}return[4,R(e,t,n,r)];case 1:return(o=c.sent())?[4,S(o,n,r)]:[3,3];case 2:return i=c.sent(),[3,4];case 3:i=null,c.label=4;case 4:return[2,i]}}))}))}function L(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i,c,s;return h(this,(function(a){switch(a.label){case 0:o=y(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(b("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,R(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function g(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i,c,s;return h(this,(function(a){switch(a.label){case 0:o=y(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(b("asyncQuerySelectorAll"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,m(o[c],t,n,r)]:[3,4];case 2:if(null==(s=a.sent())?void 0:s.length)return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,document.querySelectorAll(v)]}}))}))}function I(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i,c,s;return h(this,(function(a){switch(a.label){case 0:o=y(e,(function(e){if(e.pop().length)throw new SyntaxError(_("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,H(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function T(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return u(this,void 0,void 0,(function(){var t,n,r,o,i;return h(this,(function(c){switch(c.label){case 0:return w(e)?(t=e[0],n=e[1],r=e[2],[4,L(n,t,(null==r?void 0:r.retries)||A,(null==r?void 0:r.delay)||E)]):[3,2];case 1:case 3:return[2,c.sent()];case 2:return o=e[0],i=e[1],[4,L(o,document,(null==i?void 0:i.retries)||A,(null==i?void 0:i.delay)||E)]}}))}))}const N=(t,n,o=null,i=!1)=>Object.entries(n||{}).reduce(((n,c)=>{const[s,a]=c;if(a.selector===r&&o)return a.children?Object.assign(Object.assign({},n),N(t,a.children,o,!0)):n;const l=o?o.then((e=>{return T(e,(n=a.selector,i?"$ "+n:n),t);var n})):T(a.selector,t);return n[s]={element:l,children:N(t,a.children,l),querySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield T(e,n,Object.assign(Object.assign({},t),r))}))},querySelectorAll(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return u(this,void 0,void 0,(function(){var t,n,r,o,i;return h(this,(function(c){switch(c.label){case 0:return w(e)?(t=e[0],n=e[1],r=e[2],[4,g(n,t,(null==r?void 0:r.retries)||A,(null==r?void 0:r.delay)||E)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,g(o,document,(null==i?void 0:i.retries)||A,(null==i?void 0:i.delay)||E)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))},shadowRootQuerySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return u(this,void 0,void 0,(function(){var t,n,r,o,i;return h(this,(function(c){switch(c.label){case 0:return w(e)?(t=e[0],n=e[1],r=e[2],[4,I(n,t,(null==r?void 0:r.retries)||A,(null==r?void 0:r.delay)||E)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,I(o,document,(null==i?void 0:i.retries)||A,(null==i?void 0:i.delay)||E)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))}},n}),{}),P=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=P(e,t[1].children);if(n)return n}}},M=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(P(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var j,D,x,V,W,k,C,Q,U,q,B,$;class G extends EventTarget{constructor(e={}){super(),j.add(this),D.set(this,void 0),x.set(this,void 0),V.set(this,void 0),W.set(this,void 0),k.set(this,void 0),C.set(this,void 0),Q.set(this,void 0),n(this,D,Object.assign(Object.assign({},o),e),"f")}listen(){var e;n(this,Q,t(this,j,"m",$).bind(this),"f"),t(this,j,"m",q).call(this),t(this,j,"m",B).call(this),null===(e=t(this,C,"f"))||void 0===e||e.disconnect(),n(this,C,new MutationObserver(t(this,Q,"f")),"f"),t(this,k,"f")[c.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,C,"f").observe(e,{childList:!0})}))}}D=new WeakMap,x=new WeakMap,V=new WeakMap,W=new WeakMap,k=new WeakMap,C=new WeakMap,Q=new WeakMap,j=new WeakSet,U=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},q=function(){n(this,x,N(t(this,D,"f"),a),"f"),n(this,W,M(i,t(this,x,"f")),"f")},B=function(){n(this,V,N(t(this,D,"f"),l,t(this,W,"f")[i.HA_DRAWER].element),"f"),n(this,k,M(c,t(this,V,"f")),"f"),t(this,j,"m",U).call(this,exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,W,"f")),t(this,k,"f")))},$=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===s.HA_PANEL_LOVELACE&&t(this,j,"m",B).call(this)}))}))},exports.HAQuerySelector=G;
|
|
1
|
+
"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function t(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function n(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const r="$",o={retries:100,delay:50};var i,s,c,a,l;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(i||(i={})),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"}(s||(s={})),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={})),exports.HAQuerySelectorEvent=void 0,(a=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",a.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaveMoreInfoDialogOpen",a.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaveHistoryAndLogBookDialogOpen",a.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaveSettingsDialogOpen",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={}));const u={[i.HOME_ASSISTANT]:{selector:l.HOME_ASSISTANT,children:{shadowRoot:{selector:r,children:{[i.HOME_ASSISTANT_MAIN]:{selector:l.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:r,children:{[i.HA_DRAWER]:{selector:l.HA_DRAWER,children:{[i.HA_SIDEBAR]:{selector:l.HA_SIDEBAR,children:{shadowRoot:{selector:r}}}}}}}}}}}}}},O={[s.PARTIAL_PANEL_RESOLVER]:{selector:l.PARTIAL_PANEL_RESOLVER,children:{[s.HA_PANEL_LOVELACE]:{selector:l.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:r,children:{[s.HUI_ROOT]:{selector:l.HUI_ROOT,children:{shadowRoot:{selector:r,children:{[s.HEADER]:{selector:l.HEADER},[s.HUI_VIEW]:{selector:l.HUI_VIEW}}}}}}}}}}}},_={shadowRoot:{selector:r,children:{[c.HA_MORE_INFO_DIALOG]:{selector:l.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:r,children:{[c.HA_DIALOG]:{selector:l.HA_DIALOG,children:{[c.HA_DIALOG_CONTENT]:{selector:l.HA_DIALOG_CONTENT,children:{[c.HA_MORE_INFO_DIALOG_INFO]:{selector:l.HA_MORE_INFO_DIALOG_INFO},[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:l.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[c.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:l.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};function h(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function A(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var f="$",d=":host",E="invalid selector",I=10,N=10,L=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function v(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(f).map((function(e){return e.trim()}))}(e);return t(n)}))}function S(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var s=0,c=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++s<n?setTimeout(c,r):i(o?document.querySelectorAll(E):null)};c()}))}function H(e,t,n){return new Promise((function(r){var o=0,i=function(){var s=e.shadowRoot;s?r(s):++o<t?setTimeout(i,n):r(null)};i()}))}function R(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(f,").").concat(n)}function w(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(f,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function p(){return"You can not select a shadowRoot (".concat(f,") of the document.")}function y(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c,a,l;return A(this,(function(u){switch(u.label){case 0:o=null,i=e.length,s=0,u.label=1;case 1:if(!(s<i))return[3,15];if(0!==s)return[3,8];if(e[s].length)return[3,5];if(t instanceof Document)throw new SyntaxError(p());return t.shadowRoot?[4,S(t.shadowRoot,e[++s],n,r)]:[3,3];case 2:return c=u.sent(),[3,4];case 3:c=null,u.label=4;case 4:return o=c,[3,7];case 5:return[4,S(t,e[s],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,H(o,n,r)];case 9:return(a=u.sent())?[4,S(a,"".concat(d," ").concat(e[s]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return s++,[3,1];case 15:return[2,o]}}))}))}function T(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c,a,l;return A(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,S(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,y(o,t,n,r)];case 3:return(s=u.sent())?[4,H(s,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(c=a)?[4,S(c,"".concat(d," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function D(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i;return A(this,(function(s){switch(s.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(p());return[2,H(t,n,r)]}return[4,y(e,t,n,r)];case 1:return(o=s.sent())?[4,H(o,n,r)]:[3,3];case 2:return i=s.sent(),[3,4];case 3:i=null,s.label=4;case 4:return[2,i]}}))}))}function b(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(R("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,y(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function G(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(R("asyncQuerySelectorAll"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,T(o[s],t,n,r)]:[3,4];case 2:if(null==(c=a.sent())?void 0:c.length)return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,document.querySelectorAll(E)]}}))}))}function M(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,s,c;return A(this,(function(a){switch(a.label){case 0:o=v(e,(function(e){if(e.pop().length)throw new SyntaxError(w("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,D(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function m(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,b(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:case 3:return[2,s.sent()];case 2:return o=e[0],i=e[1],[4,b(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}const g=(t,n,o=null,i=!1)=>Object.entries(n||{}).reduce(((n,s)=>{const[c,a]=s;if(a.selector===r&&o)return a.children?Object.assign(Object.assign({},n),g(t,a.children,o,!0)):n;const l=o?o.then((e=>{return m(e,(n=a.selector,i?"$ "+n:n),t);var n})):m(a.selector,t);return n[c]={element:l,children:g(t,a.children,l),querySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield m(e,n,Object.assign(Object.assign({},t),r))}))},querySelectorAll(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,G(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,G(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))},shadowRootQuerySelector(n,r={}){return e(this,void 0,void 0,(function*(){const e=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return A(this,(function(s){switch(s.label){case 0:return L(e)?(t=e[0],n=e[1],r=e[2],[4,M(n,t,(null==r?void 0:r.retries)||I,(null==r?void 0:r.delay)||N)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,M(o,document,(null==i?void 0:i.retries)||I,(null==i?void 0:i.delay)||N)]}}))}))}(e,n,Object.assign(Object.assign({},t),r))}))}},n}),{}),F=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=F(e,t[1].children);if(n)return n}}},P=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(F(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var V,W,C,x,j,k,B,Q,Y,K,U,q,$,z,J,X,Z,ee,te,ne,re;class oe extends EventTarget{constructor(e={}){super(),V.add(this),W.set(this,void 0),C.set(this,void 0),x.set(this,void 0),j.set(this,void 0),k.set(this,void 0),B.set(this,void 0),Q.set(this,void 0),Y.set(this,void 0),K.set(this,void 0),U.set(this,void 0),q.set(this,void 0),$.set(this,void 0),z.set(this,void 0),n(this,W,Object.assign(Object.assign({},o),e),"f")}listen(){n(this,q,t(this,V,"m",te).bind(this),"f"),n(this,$,t(this,V,"m",ne).bind(this),"f"),n(this,z,t(this,V,"m",re).bind(this),"f"),n(this,Y,new MutationObserver(t(this,q,"f")),"f"),n(this,K,new MutationObserver(t(this,$,"f")),"f"),n(this,U,new MutationObserver(t(this,z,"f")),"f"),t(this,V,"m",Z).call(this),t(this,V,"m",ee).call(this)}}W=new WeakMap,C=new WeakMap,x=new WeakMap,j=new WeakMap,k=new WeakMap,B=new WeakMap,Q=new WeakMap,Y=new WeakMap,K=new WeakMap,U=new WeakMap,q=new WeakMap,$=new WeakMap,z=new WeakMap,V=new WeakSet,J=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},X=function(e=c.HA_MORE_INFO_DIALOG_INFO){n(this,C,g(t(this,W,"f"),_,t(this,B,"f").HOME_ASSISTANT.element),"f");const r=P(c,t(this,C,"f"));r.HA_DIALOG_CONTENT.element.then((e=>{t(this,K,"f").disconnect(),t(this,K,"f").observe(e,{childList:!0})})),n(this,k,((e,t)=>[c.HA_MORE_INFO_DIALOG,c.HA_DIALOG,c.HA_DIALOG_CONTENT,t].reduce(((t,n)=>(t[n]=e[n],t)),{}))(r,e),"f");const o={[c.HA_MORE_INFO_DIALOG_INFO]:exports.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:exports.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[c.HA_DIALOG_MORE_INFO_SETTINGS]:exports.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN};t(this,V,"m",J).call(this,o[e],t(this,k,"f"))},Z=function(){n(this,x,g(t(this,W,"f"),u),"f"),n(this,B,P(i,t(this,x,"f")),"f"),t(this,B,"f")[i.HOME_ASSISTANT].shadowRootQuerySelector("$").then((e=>{t(this,Y,"f").disconnect(),t(this,Y,"f").observe(e,{childList:!0})}))},ee=function(){n(this,j,g(t(this,W,"f"),O,t(this,B,"f")[i.HA_DRAWER].element),"f"),n(this,Q,P(s,t(this,j,"f")),"f"),t(this,Q,"f")[s.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,U,"f").disconnect(),t(this,U,"f").observe(e,{childList:!0})})),t(this,V,"m",J).call(this,exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,B,"f")),t(this,Q,"f")))},te=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===l.HA_MORE_INFO_DIALOG&&t(this,V,"m",X).call(this)}))}))},ne=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const n={[l.HA_MORE_INFO_DIALOG_INFO]:c.HA_MORE_INFO_DIALOG_INFO,[l.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:c.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[l.HA_DIALOG_MORE_INFO_SETTINGS]:c.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in n){const r=e.localName;t(this,V,"m",X).call(this,n[r])}}))}))},re=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===l.HA_PANEL_LOVELACE&&t(this,V,"m",ee).call(this)}))}))},exports.HAQuerySelector=oe;
|
package/dist/test/index.d.ts
CHANGED
|
@@ -20,11 +20,14 @@ type HomeAssistantElement = {
|
|
|
20
20
|
[key: string]: ElementProps;
|
|
21
21
|
};
|
|
22
22
|
declare enum HAQuerySelectorEvent {
|
|
23
|
-
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad"
|
|
23
|
+
ON_LOVELACE_PANEL_LOAD = "onLovelacePanelLoad",
|
|
24
|
+
ON_LOVELACE_MORE_INFO_DIALOG_OPEN = "onLovelaveMoreInfoDialogOpen",
|
|
25
|
+
ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onLovelaveHistoryAndLogBookDialogOpen",
|
|
26
|
+
ON_LOVELACE_SETTINGS_DIALOG_OPEN = "onLovelaveSettingsDialogOpen"
|
|
24
27
|
}
|
|
25
28
|
declare class HAQuerySelector extends EventTarget {
|
|
26
29
|
#private;
|
|
27
30
|
constructor(config?: HAQuerySelectorConfig);
|
|
28
31
|
listen(): void;
|
|
29
32
|
}
|
|
30
|
-
export { HAQuerySelector,
|
|
33
|
+
export { HAQuerySelector, HomeAssistantElement, HAQuerySelectorEvent };
|
package/dist/test/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var HomeAssistantQuerySelector=function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function n(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const o="$",i={retries:100,delay:50};var c,s,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"}(c||(c={})),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"}(s||(s={})),e.HAQuerySelectorEvent=void 0,(e.HAQuerySelectorEvent||(e.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",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"}(a||(a={}));const l={[c.HOME_ASSISTANT]:{selector:a.HOME_ASSISTANT,children:{shadowRoot:{selector:o,children:{[c.HOME_ASSISTANT_MAIN]:{selector:a.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:o,children:{[c.HA_DRAWER]:{selector:a.HA_DRAWER,children:{[c.HA_SIDEBAR]:{selector:a.HA_SIDEBAR,children:{shadowRoot:{selector:o}}}}}}}}}}}}}},u={[s.PARTIAL_PANEL_RESOLVER]:{selector:a.PARTIAL_PANEL_RESOLVER,children:{[s.HA_PANEL_LOVELACE]:{selector:a.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:o,children:{[s.HUI_ROOT]:{selector:a.HUI_ROOT,children:{shadowRoot:{selector:o,children:{[s.HEADER]:{selector:a.HEADER},[s.HUI_VIEW]:{selector:a.HUI_VIEW}}}}}}}}}}}};function h(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return c.label++,{value:s[1],done:!1};case 5:c.label++,r=s[1],s=[0];continue;case 7:s=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){c=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){c.label=s[1];break}if(6===s[0]&&c.label<o[1]){c.label=o[1],o=s;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(s);break}o[2]&&c.ops.pop(),c.trys.pop();continue}s=t.call(e,c)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}"function"==typeof SuppressedError&&SuppressedError;var d="$",v=":host",A="invalid selector",E=10,w=10,y=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function S(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(d).map((function(e){return e.trim()}))}(e);return t(n)}))}function p(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var c=0,s=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++c<n?setTimeout(s,r):i(o?document.querySelectorAll(A):null)};s()}))}function b(e,t,n){return new Promise((function(r){var o=0,i=function(){var c=e.shadowRoot;c?r(c):++o<t?setTimeout(i,n):r(null)};i()}))}function _(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(d,").").concat(n)}function O(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(d,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function R(){return"You can not select a shadowRoot (".concat(d,") of the document.")}function m(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s,a,l;return f(this,(function(u){switch(u.label){case 0:o=null,i=e.length,c=0,u.label=1;case 1:if(!(c<i))return[3,15];if(0!==c)return[3,8];if(e[c].length)return[3,5];if(t instanceof Document)throw new SyntaxError(R());return t.shadowRoot?[4,p(t.shadowRoot,e[++c],n,r)]:[3,3];case 2:return s=u.sent(),[3,4];case 3:s=null,u.label=4;case 4:return o=s,[3,7];case 5:return[4,p(t,e[c],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,b(o,n,r)];case 9:return(a=u.sent())?[4,p(a,"".concat(v," ").concat(e[c]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return c++,[3,1];case 15:return[2,o]}}))}))}function H(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s,a,l;return f(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,p(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,m(o,t,n,r)];case 3:return(c=u.sent())?[4,b(c,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(s=a)?[4,p(s,"".concat(v," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function L(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i;return f(this,(function(c){switch(c.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(R());return[2,b(t,n,r)]}return[4,m(e,t,n,r)];case 1:return(o=c.sent())?[4,b(o,n,r)]:[3,3];case 2:return i=c.sent(),[3,4];case 3:i=null,c.label=4;case 4:return[2,i]}}))}))}function g(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(_("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,m(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function I(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(_("asyncQuerySelectorAll"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,H(o[c],t,n,r)]:[3,4];case 2:if(null==(s=a.sent())?void 0:s.length)return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,document.querySelectorAll(A)]}}))}))}function T(e,t,n,r){return h(this,void 0,void 0,(function(){var o,i,c,s;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(e.pop().length)throw new SyntaxError(O("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,c=0,a.label=1;case 1:return c<i?[4,L(o[c],t,n,r)]:[3,4];case 2:if(s=a.sent())return[2,s];a.label=3;case 3:return c++,[3,1];case 4:return[2,null]}}))}))}function N(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,g(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:case 3:return[2,c.sent()];case 2:return o=e[0],i=e[1],[4,g(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}const P=(e,n,r=null,i=!1)=>Object.entries(n||{}).reduce(((n,c)=>{const[s,a]=c;if(a.selector===o&&r)return a.children?Object.assign(Object.assign({},n),P(e,a.children,r,!0)):n;const l=r?r.then((t=>{return N(t,(n=a.selector,i?"$ "+n:n),e);var n})):N(a.selector,e);return n[s]={element:l,children:P(e,a.children,l),querySelector(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield N(t,n,Object.assign(Object.assign({},e),r))}))},querySelectorAll(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,I(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,I(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}(t,n,Object.assign(Object.assign({},e),r))}))},shadowRootQuerySelector(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return h(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(c){switch(c.label){case 0:return y(e)?(t=e[0],n=e[1],r=e[2],[4,T(n,t,(null==r?void 0:r.retries)||E,(null==r?void 0:r.delay)||w)]):[3,2];case 1:return[2,c.sent()];case 2:return o=e[0],i=e[1],[2,T(o,document,(null==i?void 0:i.retries)||E,(null==i?void 0:i.delay)||w)]}}))}))}(t,n,Object.assign(Object.assign({},e),r))}))}},n}),{}),M=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=M(e,t[1].children);if(n)return n}}},j=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(M(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var D,V,W,x,k,Q,C,U,q,B,$,G;class Y extends EventTarget{constructor(e={}){super(),D.add(this),V.set(this,void 0),W.set(this,void 0),x.set(this,void 0),k.set(this,void 0),Q.set(this,void 0),C.set(this,void 0),U.set(this,void 0),r(this,V,Object.assign(Object.assign({},i),e),"f")}listen(){var e;r(this,U,n(this,D,"m",G).bind(this),"f"),n(this,D,"m",B).call(this),n(this,D,"m",$).call(this),null===(e=n(this,C,"f"))||void 0===e||e.disconnect(),r(this,C,new MutationObserver(n(this,U,"f")),"f"),n(this,Q,"f")[s.PARTIAL_PANEL_RESOLVER].element.then((e=>{n(this,C,"f").observe(e,{childList:!0})}))}}return V=new WeakMap,W=new WeakMap,x=new WeakMap,k=new WeakMap,Q=new WeakMap,C=new WeakMap,U=new WeakMap,D=new WeakSet,q=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},B=function(){r(this,W,P(n(this,V,"f"),l),"f"),r(this,k,j(c,n(this,W,"f")),"f")},$=function(){r(this,x,P(n(this,V,"f"),u,n(this,k,"f")[c.HA_DRAWER].element),"f"),r(this,Q,j(s,n(this,x,"f")),"f"),n(this,D,"m",q).call(this,e.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},n(this,k,"f")),n(this,Q,"f")))},G=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===a.HA_PANEL_LOVELACE&&n(this,D,"m",$).call(this)}))}))},e.HAQuerySelector=Y,e}({});
|
|
1
|
+
var HomeAssistantQuerySelector=function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function n(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;const o="$",i={retries:100,delay:50};var s,c,a,l,u;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(s||(s={})),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"}(c||(c={})),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={})),e.HAQuerySelectorEvent=void 0,(l=e.HAQuerySelectorEvent||(e.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",l.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaveMoreInfoDialogOpen",l.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaveHistoryAndLogBookDialogOpen",l.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaveSettingsDialogOpen",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"}(u||(u={}));const O={[s.HOME_ASSISTANT]:{selector:u.HOME_ASSISTANT,children:{shadowRoot:{selector:o,children:{[s.HOME_ASSISTANT_MAIN]:{selector:u.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:o,children:{[s.HA_DRAWER]:{selector:u.HA_DRAWER,children:{[s.HA_SIDEBAR]:{selector:u.HA_SIDEBAR,children:{shadowRoot:{selector:o}}}}}}}}}}}}}},_={[c.PARTIAL_PANEL_RESOLVER]:{selector:u.PARTIAL_PANEL_RESOLVER,children:{[c.HA_PANEL_LOVELACE]:{selector:u.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:o,children:{[c.HUI_ROOT]:{selector:u.HUI_ROOT,children:{shadowRoot:{selector:o,children:{[c.HEADER]:{selector:u.HEADER},[c.HUI_VIEW]:{selector:u.HUI_VIEW}}}}}}}}}}}},h={shadowRoot:{selector:o,children:{[a.HA_MORE_INFO_DIALOG]:{selector:u.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:o,children:{[a.HA_DIALOG]:{selector:u.HA_DIALOG,children:{[a.HA_DIALOG_CONTENT]:{selector:u.HA_DIALOG_CONTENT,children:{[a.HA_MORE_INFO_DIALOG_INFO]:{selector:u.HA_MORE_INFO_DIALOG_INFO},[a.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:u.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[a.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:u.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};function A(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var d="$",E=":host",I="invalid selector",N=10,L=10,v=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element)&&"string"==typeof r};function S(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(d).map((function(e){return e.trim()}))}(e);return t(n)}))}function H(e,t,n,r,o){return void 0===o&&(o=!1),new Promise((function(i){var s=0,c=function(){var a=o?e.querySelectorAll(t):e.querySelector(t);o&&a.length||!o&&null!==a?i(a):++s<n?setTimeout(c,r):i(o?document.querySelectorAll(I):null)};c()}))}function R(e,t,n){return new Promise((function(r){var o=0,i=function(){var s=e.shadowRoot;s?r(s):++o<t?setTimeout(i,n):r(null)};i()}))}function w(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(d,").").concat(n)}function y(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(d,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}function T(){return"You can not select a shadowRoot (".concat(d,") of the document.")}function D(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i,s,c,a,l;return f(this,(function(u){switch(u.label){case 0:o=null,i=e.length,s=0,u.label=1;case 1:if(!(s<i))return[3,15];if(0!==s)return[3,8];if(e[s].length)return[3,5];if(t instanceof Document)throw new SyntaxError(T());return t.shadowRoot?[4,H(t.shadowRoot,e[++s],n,r)]:[3,3];case 2:return c=u.sent(),[3,4];case 3:c=null,u.label=4;case 4:return o=c,[3,7];case 5:return[4,H(t,e[s],n,r)];case 6:o=u.sent(),u.label=7;case 7:return[3,13];case 8:return[4,R(o,n,r)];case 9:return(a=u.sent())?[4,H(a,"".concat(E," ").concat(e[s]),n,r)]:[3,11];case 10:return l=u.sent(),[3,12];case 11:l=null,u.label=12;case 12:o=l,u.label=13;case 13:if(null===o)return[2,null];u.label=14;case 14:return s++,[3,1];case 15:return[2,o]}}))}))}function p(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i,s,c,a,l;return f(this,(function(u){switch(u.label){case 0:return o=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),i=o.pop(),o.length?[3,2]:[4,H(t,i,n,r,!0)];case 1:return[2,u.sent()];case 2:return[4,D(o,t,n,r)];case 3:return(s=u.sent())?[4,R(s,n,r)]:[3,5];case 4:return a=u.sent(),[3,6];case 5:a=null,u.label=6;case 6:return(c=a)?[4,H(c,"".concat(E," ").concat(i),n,r,!0)]:[3,8];case 7:return l=u.sent(),[3,9];case 8:l=null,u.label=9;case 9:return[2,l]}}))}))}function b(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i;return f(this,(function(s){switch(s.label){case 0:if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(T());return[2,R(t,n,r)]}return[4,D(e,t,n,r)];case 1:return(o=s.sent())?[4,R(o,n,r)]:[3,3];case 2:return i=s.sent(),[3,4];case 3:i=null,s.label=4;case 4:return[2,i]}}))}))}function G(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i,s,c;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(w("asyncQuerySelector","asyncShadowRootQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,D(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function M(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i,s,c;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(w("asyncQuerySelectorAll"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,p(o[s],t,n,r)]:[3,4];case 2:if(null==(c=a.sent())?void 0:c.length)return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,document.querySelectorAll(I)]}}))}))}function m(e,t,n,r){return A(this,void 0,void 0,(function(){var o,i,s,c;return f(this,(function(a){switch(a.label){case 0:o=S(e,(function(e){if(e.pop().length)throw new SyntaxError(y("asyncShadowRootQuerySelector","asyncQuerySelector"));return e})),i=o.length,s=0,a.label=1;case 1:return s<i?[4,b(o[s],t,n,r)]:[3,4];case 2:if(c=a.sent())return[2,c];a.label=3;case 3:return s++,[3,1];case 4:return[2,null]}}))}))}function g(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return A(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(s){switch(s.label){case 0:return v(e)?(t=e[0],n=e[1],r=e[2],[4,G(n,t,(null==r?void 0:r.retries)||N,(null==r?void 0:r.delay)||L)]):[3,2];case 1:case 3:return[2,s.sent()];case 2:return o=e[0],i=e[1],[4,G(o,document,(null==i?void 0:i.retries)||N,(null==i?void 0:i.delay)||L)]}}))}))}const F=(e,n,r=null,i=!1)=>Object.entries(n||{}).reduce(((n,s)=>{const[c,a]=s;if(a.selector===o&&r)return a.children?Object.assign(Object.assign({},n),F(e,a.children,r,!0)):n;const l=r?r.then((t=>{return g(t,(n=a.selector,i?"$ "+n:n),e);var n})):g(a.selector,e);return n[c]={element:l,children:F(e,a.children,l),querySelector(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield g(t,n,Object.assign(Object.assign({},e),r))}))},querySelectorAll(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return A(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(s){switch(s.label){case 0:return v(e)?(t=e[0],n=e[1],r=e[2],[4,M(n,t,(null==r?void 0:r.retries)||N,(null==r?void 0:r.delay)||L)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,M(o,document,(null==i?void 0:i.retries)||N,(null==i?void 0:i.delay)||L)]}}))}))}(t,n,Object.assign(Object.assign({},e),r))}))},shadowRootQuerySelector(n,r={}){return t(this,void 0,void 0,(function*(){const t=yield l;return yield function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return A(this,void 0,void 0,(function(){var t,n,r,o,i;return f(this,(function(s){switch(s.label){case 0:return v(e)?(t=e[0],n=e[1],r=e[2],[4,m(n,t,(null==r?void 0:r.retries)||N,(null==r?void 0:r.delay)||L)]):[3,2];case 1:return[2,s.sent()];case 2:return o=e[0],i=e[1],[2,m(o,document,(null==i?void 0:i.retries)||N,(null==i?void 0:i.delay)||L)]}}))}))}(t,n,Object.assign(Object.assign({},e),r))}))}},n}),{}),P=(e,t)=>{const n=Object.entries(t);for(const t of n){if(t[0]===e)return t[1];{const n=P(e,t[1].children);if(n)return n}}},V=(e,t)=>Object.keys(e).reduce(((e,n)=>{const r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(P(n,t),["children"]);return e[n]=Object.assign({},r),e}),{});var W,C,j,k,B,Q,x,Y,K,U,q,$,z,J,X,Z,ee,te,ne,re,oe;class ie extends EventTarget{constructor(e={}){super(),W.add(this),C.set(this,void 0),j.set(this,void 0),k.set(this,void 0),B.set(this,void 0),Q.set(this,void 0),x.set(this,void 0),Y.set(this,void 0),K.set(this,void 0),U.set(this,void 0),q.set(this,void 0),$.set(this,void 0),z.set(this,void 0),J.set(this,void 0),r(this,C,Object.assign(Object.assign({},i),e),"f")}listen(){r(this,$,n(this,W,"m",ne).bind(this),"f"),r(this,z,n(this,W,"m",re).bind(this),"f"),r(this,J,n(this,W,"m",oe).bind(this),"f"),r(this,K,new MutationObserver(n(this,$,"f")),"f"),r(this,U,new MutationObserver(n(this,z,"f")),"f"),r(this,q,new MutationObserver(n(this,J,"f")),"f"),n(this,W,"m",ee).call(this),n(this,W,"m",te).call(this)}}return C=new WeakMap,j=new WeakMap,k=new WeakMap,B=new WeakMap,Q=new WeakMap,x=new WeakMap,Y=new WeakMap,K=new WeakMap,U=new WeakMap,q=new WeakMap,$=new WeakMap,z=new WeakMap,J=new WeakMap,W=new WeakSet,X=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},Z=function(t=a.HA_MORE_INFO_DIALOG_INFO){r(this,j,F(n(this,C,"f"),h,n(this,x,"f").HOME_ASSISTANT.element),"f");const o=V(a,n(this,j,"f"));o.HA_DIALOG_CONTENT.element.then((e=>{n(this,U,"f").disconnect(),n(this,U,"f").observe(e,{childList:!0})})),r(this,Q,((e,t)=>[a.HA_MORE_INFO_DIALOG,a.HA_DIALOG,a.HA_DIALOG_CONTENT,t].reduce(((t,n)=>(t[n]=e[n],t)),{}))(o,t),"f");const i={[a.HA_MORE_INFO_DIALOG_INFO]:e.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[a.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:e.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[a.HA_DIALOG_MORE_INFO_SETTINGS]:e.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN};n(this,W,"m",X).call(this,i[t],n(this,Q,"f"))},ee=function(){r(this,k,F(n(this,C,"f"),O),"f"),r(this,x,V(s,n(this,k,"f")),"f"),n(this,x,"f")[s.HOME_ASSISTANT].shadowRootQuerySelector("$").then((e=>{n(this,K,"f").disconnect(),n(this,K,"f").observe(e,{childList:!0})}))},te=function(){r(this,B,F(n(this,C,"f"),_,n(this,x,"f")[s.HA_DRAWER].element),"f"),r(this,Y,V(c,n(this,B,"f")),"f"),n(this,Y,"f")[c.PARTIAL_PANEL_RESOLVER].element.then((e=>{n(this,q,"f").disconnect(),n(this,q,"f").observe(e,{childList:!0})})),n(this,W,"m",X).call(this,e.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},n(this,x,"f")),n(this,Y,"f")))},ne=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===u.HA_MORE_INFO_DIALOG&&n(this,W,"m",Z).call(this)}))}))},re=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const t={[u.HA_MORE_INFO_DIALOG_INFO]:a.HA_MORE_INFO_DIALOG_INFO,[u.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:a.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[u.HA_DIALOG_MORE_INFO_SETTINGS]:a.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in t){const r=e.localName;n(this,W,"m",Z).call(this,t[r])}}))}))},oe=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===u.HA_PANEL_LOVELACE&&n(this,W,"m",te).call(this)}))}))},e.HAQuerySelector=ie,e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "home-assistant-query-selector",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Easily query home-assistant DOM elements in an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "ElChiniNet",
|
|
33
33
|
"license": "Apache-2.0",
|
|
34
34
|
"scripts": {
|
|
35
|
-
"clean": "rm -rf dist .nyc_output coverage
|
|
35
|
+
"clean": "rm -rf dist .nyc_output coverage",
|
|
36
36
|
"build": "yarn clean && rollup --config rollup.config.js --bundleConfigAsCjs",
|
|
37
37
|
"lint": "eslint \"src/**/*.ts\"",
|
|
38
38
|
"coverage:report": "nyc report --reporter=lcov --reporter=text-summary",
|