home-assistant-query-selector 6.0.0 → 6.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/dist/esm/index.d.ts +32 -22
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +32 -22
- package/dist/index.js +1 -1
- package/package.json +15 -12
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import { AsyncSelector, AsyncParams } from 'shadow-dom-selector';
|
|
2
2
|
|
|
3
|
-
type HAQuerySelectorConfig = AsyncParams & {
|
|
4
|
-
eventThreshold?: number;
|
|
5
|
-
};
|
|
6
|
-
type ElementProps = {
|
|
7
|
-
element: Promise<Element | null>;
|
|
8
|
-
children?: HomeAssistantElement;
|
|
9
|
-
selector: AsyncSelector<Element>;
|
|
10
|
-
};
|
|
11
|
-
type HomeAssistantElement = {
|
|
12
|
-
[key: string]: ElementProps;
|
|
13
|
-
};
|
|
14
|
-
type HAElement = Omit<ElementProps, 'children'>;
|
|
15
|
-
interface HAQuerySelectorEventListener<T> extends EventListener {
|
|
16
|
-
(evt: CustomEvent<T>): void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
3
|
declare enum HA_ROOT_ELEMENT {
|
|
20
4
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
21
5
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
@@ -46,12 +30,40 @@ declare enum HAQuerySelectorEvent {
|
|
|
46
30
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
47
31
|
}
|
|
48
32
|
|
|
33
|
+
type HAQuerySelectorConfig = AsyncParams & {
|
|
34
|
+
eventThreshold?: number;
|
|
35
|
+
};
|
|
36
|
+
type ElementProps = {
|
|
37
|
+
element: Promise<Element | null>;
|
|
38
|
+
children?: HomeAssistantElement;
|
|
39
|
+
selector: AsyncSelector<Element>;
|
|
40
|
+
};
|
|
41
|
+
type HomeAssistantElement = {
|
|
42
|
+
[key: string]: ElementProps;
|
|
43
|
+
};
|
|
44
|
+
type HAElement = Omit<ElementProps, 'children'>;
|
|
45
|
+
interface HAQuerySelectorEventListenerFunction<T> {
|
|
46
|
+
(evt: CustomEvent<T>): void;
|
|
47
|
+
}
|
|
48
|
+
interface HAQuerySelectorEventListenerObject<T> {
|
|
49
|
+
handleEvent(object: CustomEvent<T>): void;
|
|
50
|
+
}
|
|
51
|
+
type HAQuerySelectorEventListener<T> = HAQuerySelectorEventListenerFunction<T> | HAQuerySelectorEventListenerObject<T> | null;
|
|
49
52
|
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
50
53
|
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
51
54
|
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
52
55
|
type OnMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
53
56
|
type OnHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
54
57
|
type OnSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
|
|
58
|
+
interface HAQuerySelectorEventListenerEventMap {
|
|
59
|
+
[HAQuerySelectorEvent.ON_LISTEN]: HAQuerySelectorEventListener<OnListenDetail>;
|
|
60
|
+
[HAQuerySelectorEvent.ON_PANEL_LOAD]: HAQuerySelectorEventListener<OnPanelLoadDetail>;
|
|
61
|
+
[HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD]: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>;
|
|
62
|
+
[HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN]: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>;
|
|
63
|
+
[HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN]: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>;
|
|
64
|
+
[HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN]: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>;
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
declare class DelegatedEventTarget implements EventTarget {
|
|
56
68
|
private delegate;
|
|
57
69
|
addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
|
|
@@ -68,10 +80,12 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
68
80
|
private _haRootElements;
|
|
69
81
|
private _haResolverElements;
|
|
70
82
|
private _dialogsObserver;
|
|
83
|
+
private _dialogsChildrenObserver;
|
|
71
84
|
private _dialogsContentObserver;
|
|
72
85
|
private _panelResolverObserver;
|
|
73
86
|
private _lovelaceObserver;
|
|
74
87
|
private _watchDialogsBinded;
|
|
88
|
+
private _watchDialogsChildrenBinded;
|
|
75
89
|
private _watchDialogsContentBinded;
|
|
76
90
|
private _watchDashboardsBinded;
|
|
77
91
|
private _watchLovelaceBinded;
|
|
@@ -81,16 +95,12 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
81
95
|
private _updateRootElements;
|
|
82
96
|
private _updateLovelaceElements;
|
|
83
97
|
private _watchDialogs;
|
|
98
|
+
private _watchDialogsChildren;
|
|
84
99
|
private _watchDialogsContent;
|
|
85
100
|
private _watchDashboards;
|
|
86
101
|
private _watchLovelace;
|
|
87
102
|
listen(): void;
|
|
88
|
-
addEventListener(type:
|
|
89
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnPanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
90
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
91
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
93
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
103
|
+
addEventListener<E extends keyof HAQuerySelectorEventListenerEventMap>(type: E, callback: HAQuerySelectorEventListenerEventMap[E], options?: boolean | AddEventListenerOptions): void;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export { HAQuerySelector, HAQuerySelectorEvent };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";const _="$",s={retries:100,delay:50,eventThreshold:450};var O,
|
|
1
|
+
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";const _="$",s={retries:100,delay:50,eventThreshold:450};var o,O,n,i,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"}(o||(o={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(O||(O={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(n||(n={})),function(e){e.ON_LISTEN="onListen",e.ON_PANEL_LOAD="onPanelLoad",e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",e.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",e.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen"}(i||(i={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_ADAPTATIVE_DIALOG="ha-adaptive-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"}(A||(A={}));const a={[o.HOME_ASSISTANT]:{selector:A.HOME_ASSISTANT,children:{shadowRoot:{selector:_,children:{[o.HOME_ASSISTANT_MAIN]:{selector:A.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:_,children:{[o.HA_DRAWER]:{selector:A.HA_DRAWER,children:{[o.HA_SIDEBAR]:{selector:A.HA_SIDEBAR,children:{shadowRoot:{selector:_}}},[o.PARTIAL_PANEL_RESOLVER]:{selector:A.PARTIAL_PANEL_RESOLVER}}}}}}}}}}}},r={[O.HA_PANEL_LOVELACE]:{selector:A.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:_,children:{[O.HUI_ROOT]:{selector:A.HUI_ROOT,children:{shadowRoot:{selector:_,children:{[O.HEADER]:{selector:A.HEADER},[O.HUI_VIEW]:{selector:A.HUI_VIEW}}}}}}}}}},h={shadowRoot:{selector:_,children:{[n.HA_MORE_INFO_DIALOG]:{selector:A.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:_,children:{[n.HA_DIALOG]:{selector:`${A.HA_ADAPTATIVE_DIALOG}, ${A.HA_DIALOG}`,children:{[n.HA_DIALOG_CONTENT]:{selector:A.HA_DIALOG_CONTENT,children:{[n.HA_MORE_INFO_DIALOG_INFO]:{selector:A.HA_MORE_INFO_DIALOG_INFO},[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[n.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:A.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};"function"==typeof SuppressedError&&SuppressedError;const l=(s,o,O,n=!1)=>Object.entries(o||{}).reduce((o,i)=>{const[A,a]=i;if(a.selector===_&&O)return a.children?Object.assign(Object.assign({},o),l(s,a.children,O,!0)):o;const r=O?O.then(t=>{return t?e(t,(_=a.selector,n?"$ "+_:_),s):null;var _}):e(a.selector,s);return o[A]={element:r,children:l(s,a.children,r),selector:new t(r,s)},o},{}),E=(e,t)=>{const _=Object.entries(t);for(const t of _){if(t[0]===e)return t[1];{const _=E(e,t[1].children);if(_)return _}}},c=(e,t)=>Object.keys(e).reduce((e,_)=>{const s=E(_,t);if(s){const{children:t}=s,o=function(e,t){var _={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(_[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(_[s[o]]=e[s[o]])}return _}(s,["children"]);e[_]=Object.assign({},o)}return e},{});class I{constructor(){this.delegate=document.createDocumentFragment()}addEventListener(...e){this.delegate.addEventListener(...e)}dispatchEvent(...e){return this.delegate.dispatchEvent(...e)}removeEventListener(...e){return this.delegate.removeEventListener(...e)}}class d extends I{constructor(e={}){super(),this._config=Object.assign(Object.assign({},s),e),this._timestaps={}}_dispatchEvent(e,t){const _=Date.now();this._timestaps[e]&&_-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=_,this.dispatchEvent(new CustomEvent(e,{detail:t})))}_updateDialogElements(e=n.HA_MORE_INFO_DIALOG_INFO){this._dialogTree=l(this._config,h,this._haRootElements.HOME_ASSISTANT.element);const t=c(n,this._dialogTree);t.HA_DIALOG_CONTENT.element.then(e=>{this._dialogsContentObserver.disconnect(),this._dialogsContentObserver.observe(e,{childList:!0})}),this._haDialogElements=((e,t)=>[n.HA_MORE_INFO_DIALOG,n.HA_DIALOG,n.HA_DIALOG_CONTENT,t].reduce((t,_)=>(t[_]=e[_],t),{}))(t,e);const _={[n.HA_MORE_INFO_DIALOG_INFO]:i.ON_MORE_INFO_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:i.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_SETTINGS]:i.ON_SETTINGS_DIALOG_OPEN};this._dispatchEvent(_[e],this._haDialogElements)}_updateRootElements(){this._homeAssistantRootTree=l(this._config,a),this._haRootElements=c(o,this._homeAssistantRootTree),this._haRootElements[o.HOME_ASSISTANT].selector.$.element.then(e=>{this._dialogsObserver.disconnect(),this._dialogsObserver.observe(e,{childList:!0})}),this._haRootElements[o.PARTIAL_PANEL_RESOLVER].element.then(e=>{this._panelResolverObserver.disconnect(),e&&this._panelResolverObserver.observe(e,{subtree:!0,childList:!0})}),this._dispatchEvent(i.ON_LISTEN,this._haRootElements),this._dispatchEvent(i.ON_PANEL_LOAD,this._haRootElements)}_updateLovelaceElements(){this._homeAssistantResolverTree=l(this._config,r,this._haRootElements[o.HA_DRAWER].element),this._haResolverElements=c(O,this._homeAssistantResolverTree),this._haResolverElements[O.HA_PANEL_LOVELACE].element.then(e=>{this._lovelaceObserver.disconnect(),e&&(this._lovelaceObserver.observe(e.shadowRoot,{childList:!0}),this._dispatchEvent(i.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},this._haRootElements),this._haResolverElements)))})}_watchDialogs(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{e instanceof Element&&e.localName===A.HA_MORE_INFO_DIALOG&&(this._dialogsChildrenObserver.disconnect(),this._dialogsChildrenObserver.observe(e.shadowRoot,{childList:!0}),this._updateDialogElements())})})}_watchDialogsChildren(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{const t=[`${A.HA_DIALOG}`,`${A.HA_ADAPTATIVE_DIALOG}`];e instanceof Element&&t.includes(e.localName)&&this._updateDialogElements()})})}_watchDialogsContent(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{const t={[A.HA_MORE_INFO_DIALOG_INFO]:n.HA_MORE_INFO_DIALOG_INFO,[A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[A.HA_DIALOG_MORE_INFO_SETTINGS]:n.HA_DIALOG_MORE_INFO_SETTINGS};if(e instanceof Element&&e.localName&&e.localName in t){const _=e.localName;this._updateDialogElements(t[_])}})})}_watchDashboards(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{this._dispatchEvent(i.ON_PANEL_LOAD,this._haRootElements),e instanceof Element&&e.localName===A.HA_PANEL_LOVELACE&&this._updateLovelaceElements()})})}_watchLovelace(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{e instanceof Element&&e.localName===A.HUI_ROOT&&this._updateLovelaceElements()})})}listen(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsChildrenBinded=this._watchDialogsChildren.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsChildrenObserver=new MutationObserver(this._watchDialogsChildrenBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()}addEventListener(e,t,_){super.addEventListener(e,t,_)}}export{d as HAQuerySelector,i as HAQuerySelectorEvent};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import { AsyncSelector, AsyncParams } from 'shadow-dom-selector';
|
|
2
2
|
|
|
3
|
-
type HAQuerySelectorConfig = AsyncParams & {
|
|
4
|
-
eventThreshold?: number;
|
|
5
|
-
};
|
|
6
|
-
type ElementProps = {
|
|
7
|
-
element: Promise<Element | null>;
|
|
8
|
-
children?: HomeAssistantElement;
|
|
9
|
-
selector: AsyncSelector<Element>;
|
|
10
|
-
};
|
|
11
|
-
type HomeAssistantElement = {
|
|
12
|
-
[key: string]: ElementProps;
|
|
13
|
-
};
|
|
14
|
-
type HAElement = Omit<ElementProps, 'children'>;
|
|
15
|
-
interface HAQuerySelectorEventListener<T> extends EventListener {
|
|
16
|
-
(evt: CustomEvent<T>): void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
3
|
declare enum HA_ROOT_ELEMENT {
|
|
20
4
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
21
5
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
@@ -46,12 +30,40 @@ declare enum HAQuerySelectorEvent {
|
|
|
46
30
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
47
31
|
}
|
|
48
32
|
|
|
33
|
+
type HAQuerySelectorConfig = AsyncParams & {
|
|
34
|
+
eventThreshold?: number;
|
|
35
|
+
};
|
|
36
|
+
type ElementProps = {
|
|
37
|
+
element: Promise<Element | null>;
|
|
38
|
+
children?: HomeAssistantElement;
|
|
39
|
+
selector: AsyncSelector<Element>;
|
|
40
|
+
};
|
|
41
|
+
type HomeAssistantElement = {
|
|
42
|
+
[key: string]: ElementProps;
|
|
43
|
+
};
|
|
44
|
+
type HAElement = Omit<ElementProps, 'children'>;
|
|
45
|
+
interface HAQuerySelectorEventListenerFunction<T> {
|
|
46
|
+
(evt: CustomEvent<T>): void;
|
|
47
|
+
}
|
|
48
|
+
interface HAQuerySelectorEventListenerObject<T> {
|
|
49
|
+
handleEvent(object: CustomEvent<T>): void;
|
|
50
|
+
}
|
|
51
|
+
type HAQuerySelectorEventListener<T> = HAQuerySelectorEventListenerFunction<T> | HAQuerySelectorEventListenerObject<T> | null;
|
|
49
52
|
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
50
53
|
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
51
54
|
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
52
55
|
type OnMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
53
56
|
type OnHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
|
|
54
57
|
type OnSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
|
|
58
|
+
interface HAQuerySelectorEventListenerEventMap {
|
|
59
|
+
[HAQuerySelectorEvent.ON_LISTEN]: HAQuerySelectorEventListener<OnListenDetail>;
|
|
60
|
+
[HAQuerySelectorEvent.ON_PANEL_LOAD]: HAQuerySelectorEventListener<OnPanelLoadDetail>;
|
|
61
|
+
[HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD]: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>;
|
|
62
|
+
[HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN]: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>;
|
|
63
|
+
[HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN]: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>;
|
|
64
|
+
[HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN]: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>;
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
declare class DelegatedEventTarget implements EventTarget {
|
|
56
68
|
private delegate;
|
|
57
69
|
addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
|
|
@@ -68,10 +80,12 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
68
80
|
private _haRootElements;
|
|
69
81
|
private _haResolverElements;
|
|
70
82
|
private _dialogsObserver;
|
|
83
|
+
private _dialogsChildrenObserver;
|
|
71
84
|
private _dialogsContentObserver;
|
|
72
85
|
private _panelResolverObserver;
|
|
73
86
|
private _lovelaceObserver;
|
|
74
87
|
private _watchDialogsBinded;
|
|
88
|
+
private _watchDialogsChildrenBinded;
|
|
75
89
|
private _watchDialogsContentBinded;
|
|
76
90
|
private _watchDashboardsBinded;
|
|
77
91
|
private _watchLovelaceBinded;
|
|
@@ -81,16 +95,12 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
81
95
|
private _updateRootElements;
|
|
82
96
|
private _updateLovelaceElements;
|
|
83
97
|
private _watchDialogs;
|
|
98
|
+
private _watchDialogsChildren;
|
|
84
99
|
private _watchDialogsContent;
|
|
85
100
|
private _watchDashboards;
|
|
86
101
|
private _watchLovelace;
|
|
87
102
|
listen(): void;
|
|
88
|
-
addEventListener(type:
|
|
89
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnPanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
90
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
91
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
93
|
-
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
103
|
+
addEventListener<E extends keyof HAQuerySelectorEventListenerEventMap>(type: E, callback: HAQuerySelectorEventListenerEventMap[E], options?: boolean | AddEventListenerOptions): void;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export { HAQuerySelector, HAQuerySelectorEvent };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("shadow-dom-selector");const t="$",
|
|
1
|
+
"use strict";var e=require("shadow-dom-selector");const t="$",s={retries:100,delay:50,eventThreshold:450};var _,o,O,n,i;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(_||(_={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(o||(o={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(O||(O={})),exports.HAQuerySelectorEvent=void 0,(n=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LISTEN="onListen",n.ON_PANEL_LOAD="onPanelLoad",n.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",n.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",n.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",n.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_ADAPTATIVE_DIALOG="ha-adaptive-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"}(i||(i={}));const r={[_.HOME_ASSISTANT]:{selector:i.HOME_ASSISTANT,children:{shadowRoot:{selector:t,children:{[_.HOME_ASSISTANT_MAIN]:{selector:i.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:t,children:{[_.HA_DRAWER]:{selector:i.HA_DRAWER,children:{[_.HA_SIDEBAR]:{selector:i.HA_SIDEBAR,children:{shadowRoot:{selector:t}}},[_.PARTIAL_PANEL_RESOLVER]:{selector:i.PARTIAL_PANEL_RESOLVER}}}}}}}}}}}},A={[o.HA_PANEL_LOVELACE]:{selector:i.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:t,children:{[o.HUI_ROOT]:{selector:i.HUI_ROOT,children:{shadowRoot:{selector:t,children:{[o.HEADER]:{selector:i.HEADER},[o.HUI_VIEW]:{selector:i.HUI_VIEW}}}}}}}}}},a={shadowRoot:{selector:t,children:{[O.HA_MORE_INFO_DIALOG]:{selector:i.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:t,children:{[O.HA_DIALOG]:{selector:`${i.HA_ADAPTATIVE_DIALOG}, ${i.HA_DIALOG}`,children:{[O.HA_DIALOG_CONTENT]:{selector:i.HA_DIALOG_CONTENT,children:{[O.HA_MORE_INFO_DIALOG_INFO]:{selector:i.HA_MORE_INFO_DIALOG_INFO},[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:i.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[O.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:i.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};"function"==typeof SuppressedError&&SuppressedError;const l=(s,_,o,O=!1)=>Object.entries(_||{}).reduce((_,n)=>{const[i,r]=n;if(r.selector===t&&o)return r.children?Object.assign(Object.assign({},_),l(s,r.children,o,!0)):_;const A=o?o.then(t=>{return t?e.asyncQuerySelector(t,(_=r.selector,O?"$ "+_:_),s):null;var _}):e.asyncQuerySelector(r.selector,s);return _[i]={element:A,children:l(s,r.children,A),selector:new e.AsyncSelector(A,s)},_},{}),E=(e,t)=>{const s=Object.entries(t);for(const t of s){if(t[0]===e)return t[1];{const s=E(e,t[1].children);if(s)return s}}},h=(e,t)=>Object.keys(e).reduce((e,s)=>{const _=E(s,t);if(_){const{children:t}=_,o=function(e,t){var s={};for(var _ in e)Object.prototype.hasOwnProperty.call(e,_)&&t.indexOf(_)<0&&(s[_]=e[_]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(_=Object.getOwnPropertySymbols(e);o<_.length;o++)t.indexOf(_[o])<0&&Object.prototype.propertyIsEnumerable.call(e,_[o])&&(s[_[o]]=e[_[o]])}return s}(_,["children"]);e[s]=Object.assign({},o)}return e},{});class c{constructor(){this.delegate=document.createDocumentFragment()}addEventListener(...e){this.delegate.addEventListener(...e)}dispatchEvent(...e){return this.delegate.dispatchEvent(...e)}removeEventListener(...e){return this.delegate.removeEventListener(...e)}}exports.HAQuerySelector=class extends c{constructor(e={}){super(),this._config=Object.assign(Object.assign({},s),e),this._timestaps={}}_dispatchEvent(e,t){const s=Date.now();this._timestaps[e]&&s-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=s,this.dispatchEvent(new CustomEvent(e,{detail:t})))}_updateDialogElements(e=O.HA_MORE_INFO_DIALOG_INFO){this._dialogTree=l(this._config,a,this._haRootElements.HOME_ASSISTANT.element);const t=h(O,this._dialogTree);t.HA_DIALOG_CONTENT.element.then(e=>{this._dialogsContentObserver.disconnect(),this._dialogsContentObserver.observe(e,{childList:!0})}),this._haDialogElements=((e,t)=>[O.HA_MORE_INFO_DIALOG,O.HA_DIALOG,O.HA_DIALOG_CONTENT,t].reduce((t,s)=>(t[s]=e[s],t),{}))(t,e);const s={[O.HA_MORE_INFO_DIALOG_INFO]:exports.HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN,[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:exports.HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[O.HA_DIALOG_MORE_INFO_SETTINGS]:exports.HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN};this._dispatchEvent(s[e],this._haDialogElements)}_updateRootElements(){this._homeAssistantRootTree=l(this._config,r),this._haRootElements=h(_,this._homeAssistantRootTree),this._haRootElements[_.HOME_ASSISTANT].selector.$.element.then(e=>{this._dialogsObserver.disconnect(),this._dialogsObserver.observe(e,{childList:!0})}),this._haRootElements[_.PARTIAL_PANEL_RESOLVER].element.then(e=>{this._panelResolverObserver.disconnect(),e&&this._panelResolverObserver.observe(e,{subtree:!0,childList:!0})}),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LISTEN,this._haRootElements),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements)}_updateLovelaceElements(){this._homeAssistantResolverTree=l(this._config,A,this._haRootElements[_.HA_DRAWER].element),this._haResolverElements=h(o,this._homeAssistantResolverTree),this._haResolverElements[o.HA_PANEL_LOVELACE].element.then(e=>{this._lovelaceObserver.disconnect(),e&&(this._lovelaceObserver.observe(e.shadowRoot,{childList:!0}),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},this._haRootElements),this._haResolverElements)))})}_watchDialogs(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{e instanceof Element&&e.localName===i.HA_MORE_INFO_DIALOG&&(this._dialogsChildrenObserver.disconnect(),this._dialogsChildrenObserver.observe(e.shadowRoot,{childList:!0}),this._updateDialogElements())})})}_watchDialogsChildren(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{const t=[`${i.HA_DIALOG}`,`${i.HA_ADAPTATIVE_DIALOG}`];e instanceof Element&&t.includes(e.localName)&&this._updateDialogElements()})})}_watchDialogsContent(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{const t={[i.HA_MORE_INFO_DIALOG_INFO]:O.HA_MORE_INFO_DIALOG_INFO,[i.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[i.HA_DIALOG_MORE_INFO_SETTINGS]:O.HA_DIALOG_MORE_INFO_SETTINGS};if(e instanceof Element&&e.localName&&e.localName in t){const s=e.localName;this._updateDialogElements(t[s])}})})}_watchDashboards(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{this._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements),e instanceof Element&&e.localName===i.HA_PANEL_LOVELACE&&this._updateLovelaceElements()})})}_watchLovelace(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{e instanceof Element&&e.localName===i.HUI_ROOT&&this._updateLovelaceElements()})})}listen(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsChildrenBinded=this._watchDialogsChildren.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsChildrenObserver=new MutationObserver(this._watchDialogsChildrenBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()}addEventListener(e,t,s){super.addEventListener(e,t,s)}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "home-assistant-query-selector",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Easily query home-assistant DOM elements in an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"test:tag": "pnpm reset:ha && pnpm test:clean && pnpm demo:ha && pnpm tag:playwright && pnpm stop:ha",
|
|
49
49
|
"start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant:${TAG:-$(cat .hass/config/.HA_VERSION)}",
|
|
50
50
|
"stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:${TAG:-$(cat .hass/config/.HA_VERSION)}) || true",
|
|
51
|
-
"reset:ha": "git add .hass/config/.HA_VERSION && git checkout .hass/config",
|
|
51
|
+
"reset:ha": "git add .hass/config/.HA_VERSION && git checkout .hass/config && git clean -fd",
|
|
52
52
|
"demo:ha": "pnpm test:clean && pnpm build && pnpm start:ha && sleep 5",
|
|
53
53
|
"start:playwright": "docker run -e CI=true --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright:v$(jq -r '.devDependencies[\"@playwright/test\"]' package.json)-jammy sh -c \"npx playwright test\"",
|
|
54
54
|
"tag:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright:v$(jq -r '.devDependencies[\"@playwright/test\"]' package.json)-jammy sh -c \"npx playwright test --grep @testing --trace on\"",
|
|
@@ -60,36 +60,39 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@eslint/js": "^10.0.1",
|
|
63
|
-
"@playwright/test": "1.
|
|
63
|
+
"@playwright/test": "1.59.1",
|
|
64
64
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
65
65
|
"@rollup/plugin-terser": "^1.0.0",
|
|
66
66
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
67
67
|
"@types/eslint": "^9.6.1",
|
|
68
|
-
"@types/node": "^25.5.
|
|
69
|
-
"@types/sinon": "^21.0.
|
|
70
|
-
"eslint": "^10.
|
|
68
|
+
"@types/node": "^25.5.2",
|
|
69
|
+
"@types/sinon": "^21.0.1",
|
|
70
|
+
"eslint": "^10.2.0",
|
|
71
71
|
"globals": "^17.4.0",
|
|
72
72
|
"nyc": "^18.0.0",
|
|
73
73
|
"playwright-test-coverage": "^1.2.12",
|
|
74
|
-
"rollup": "^4.60.
|
|
74
|
+
"rollup": "^4.60.1",
|
|
75
75
|
"rollup-plugin-dts": "^6.4.1",
|
|
76
76
|
"rollup-plugin-istanbul": "^5.0.0",
|
|
77
|
-
"rollup-plugin-serve": "^
|
|
77
|
+
"rollup-plugin-serve": "^3.0.0",
|
|
78
78
|
"rollup-plugin-tsconfig-paths": "^1.5.2",
|
|
79
79
|
"sinon": "^21.0.3",
|
|
80
80
|
"tslib": "^2.8.1",
|
|
81
81
|
"typescript": "^6.0.2",
|
|
82
|
-
"typescript-eslint": "^8.
|
|
82
|
+
"typescript-eslint": "^8.58.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"shadow-dom-selector": "^
|
|
85
|
+
"shadow-dom-selector": "^6.1.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"shadow-dom-selector": "^
|
|
88
|
+
"shadow-dom-selector": "^6.1.0"
|
|
89
89
|
},
|
|
90
90
|
"pnpm": {
|
|
91
91
|
"overrides": {
|
|
92
|
-
"
|
|
92
|
+
"brace-expansion@>=4.0.0 <5.0.5": ">=5.0.5",
|
|
93
|
+
"picomatch@<2.3.2": ">=2.3.2",
|
|
94
|
+
"picomatch@>=4.0.0 <4.0.4": ">=4.0.4",
|
|
95
|
+
"serialize-javascript@<7.0.5": ">=7.0.5"
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
}
|