home-assistant-query-selector 5.0.0-alpha → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +9 -11
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +9 -11
- package/dist/index.js +1 -1
- package/package.json +18 -12
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { AsyncSelector, AsyncParams } from
|
|
1
|
+
import { AsyncSelector, AsyncParams } from 'shadow-dom-selector';
|
|
2
|
+
|
|
2
3
|
type HAQuerySelectorConfig = AsyncParams & {
|
|
3
4
|
eventThreshold?: number;
|
|
4
5
|
};
|
|
5
|
-
type NodeDescriptorProps = {
|
|
6
|
-
selector: string;
|
|
7
|
-
children?: HomeAssistantNodeDescriptor;
|
|
8
|
-
};
|
|
9
|
-
type HomeAssistantNodeDescriptor = {
|
|
10
|
-
[key: string]: NodeDescriptorProps;
|
|
11
|
-
};
|
|
12
6
|
type ElementProps = {
|
|
13
7
|
element: Promise<Element | null>;
|
|
14
8
|
children?: HomeAssistantElement;
|
|
@@ -17,10 +11,11 @@ type ElementProps = {
|
|
|
17
11
|
type HomeAssistantElement = {
|
|
18
12
|
[key: string]: ElementProps;
|
|
19
13
|
};
|
|
20
|
-
type HAElement = Omit<ElementProps,
|
|
21
|
-
interface HAQuerySelectorEventListener<T> {
|
|
14
|
+
type HAElement = Omit<ElementProps, 'children'>;
|
|
15
|
+
interface HAQuerySelectorEventListener<T> extends EventListener {
|
|
22
16
|
(evt: CustomEvent<T>): void;
|
|
23
17
|
}
|
|
18
|
+
|
|
24
19
|
declare enum HA_ROOT_ELEMENT {
|
|
25
20
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
26
21
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
@@ -50,6 +45,7 @@ declare enum HAQuerySelectorEvent {
|
|
|
50
45
|
ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onHistoryAndLogBookDialogOpen",
|
|
51
46
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
52
47
|
}
|
|
48
|
+
|
|
53
49
|
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
54
50
|
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
55
51
|
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
@@ -96,4 +92,6 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
96
92
|
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
97
93
|
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
98
94
|
}
|
|
99
|
-
|
|
95
|
+
|
|
96
|
+
export { HAQuerySelector, HAQuerySelectorEvent };
|
|
97
|
+
export type { HAElement, OnHistoryAndLogBookDialogOpenDetail, OnListenDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnPanelLoadDetail, OnSettingsDialogOpenDetail };
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";
|
|
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-adaptive-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"}(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}}}}}}}}}},E={shadowRoot:{selector:_,children:{[n.HA_MORE_INFO_DIALOG]:{selector:A.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:_,children:{[n.HA_DIALOG]:{selector: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 h=(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),h(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:h(s,a.children,r),selector:new t(r,s)},O},{}),l=(e,t)=>{const _=Object.entries(t);for(const t of _){if(t[0]===e)return t[1];{const _=l(e,t[1].children);if(_)return _}}},c=(e,t)=>Object.keys(e).reduce((e,_)=>{const s=l(_,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 N 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=h(this._config,E,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=h(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=h(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._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._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()}addEventListener(e,t,_){super.addEventListener(e,t,_)}}export{N as HAQuerySelector,i as HAQuerySelectorEvent};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { AsyncSelector, AsyncParams } from
|
|
1
|
+
import { AsyncSelector, AsyncParams } from 'shadow-dom-selector';
|
|
2
|
+
|
|
2
3
|
type HAQuerySelectorConfig = AsyncParams & {
|
|
3
4
|
eventThreshold?: number;
|
|
4
5
|
};
|
|
5
|
-
type NodeDescriptorProps = {
|
|
6
|
-
selector: string;
|
|
7
|
-
children?: HomeAssistantNodeDescriptor;
|
|
8
|
-
};
|
|
9
|
-
type HomeAssistantNodeDescriptor = {
|
|
10
|
-
[key: string]: NodeDescriptorProps;
|
|
11
|
-
};
|
|
12
6
|
type ElementProps = {
|
|
13
7
|
element: Promise<Element | null>;
|
|
14
8
|
children?: HomeAssistantElement;
|
|
@@ -17,10 +11,11 @@ type ElementProps = {
|
|
|
17
11
|
type HomeAssistantElement = {
|
|
18
12
|
[key: string]: ElementProps;
|
|
19
13
|
};
|
|
20
|
-
type HAElement = Omit<ElementProps,
|
|
21
|
-
interface HAQuerySelectorEventListener<T> {
|
|
14
|
+
type HAElement = Omit<ElementProps, 'children'>;
|
|
15
|
+
interface HAQuerySelectorEventListener<T> extends EventListener {
|
|
22
16
|
(evt: CustomEvent<T>): void;
|
|
23
17
|
}
|
|
18
|
+
|
|
24
19
|
declare enum HA_ROOT_ELEMENT {
|
|
25
20
|
HOME_ASSISTANT = "HOME_ASSISTANT",
|
|
26
21
|
HOME_ASSISTANT_MAIN = "HOME_ASSISTANT_MAIN",
|
|
@@ -50,6 +45,7 @@ declare enum HAQuerySelectorEvent {
|
|
|
50
45
|
ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN = "onHistoryAndLogBookDialogOpen",
|
|
51
46
|
ON_SETTINGS_DIALOG_OPEN = "onSettingsDialogOpen"
|
|
52
47
|
}
|
|
48
|
+
|
|
53
49
|
type OnListenDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
54
50
|
type OnPanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT, HAElement>;
|
|
55
51
|
type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typeof HA_LOVELACE_ELEMENT, HAElement>;
|
|
@@ -96,4 +92,6 @@ declare class HAQuerySelector extends DelegatedEventTarget {
|
|
|
96
92
|
addEventListener(type: `${HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnHistoryAndLogBookDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
97
93
|
addEventListener(type: `${HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnSettingsDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
|
|
98
94
|
}
|
|
99
|
-
|
|
95
|
+
|
|
96
|
+
export { HAQuerySelector, HAQuerySelectorEvent };
|
|
97
|
+
export type { HAElement, OnHistoryAndLogBookDialogOpenDetail, OnListenDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnPanelLoadDetail, OnSettingsDialogOpenDetail };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("shadow-dom-selector")
|
|
1
|
+
"use strict";var e=require("shadow-dom-selector");const t="$",_={retries:100,delay:50,eventThreshold:450};var s,o,O,n,r;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(s||(s={})),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-adaptive-dialog, ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(r||(r={}));const i={[s.HOME_ASSISTANT]:{selector:r.HOME_ASSISTANT,children:{shadowRoot:{selector:t,children:{[s.HOME_ASSISTANT_MAIN]:{selector:r.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:t,children:{[s.HA_DRAWER]:{selector:r.HA_DRAWER,children:{[s.HA_SIDEBAR]:{selector:r.HA_SIDEBAR,children:{shadowRoot:{selector:t}}},[s.PARTIAL_PANEL_RESOLVER]:{selector:r.PARTIAL_PANEL_RESOLVER}}}}}}}}}}}},A={[o.HA_PANEL_LOVELACE]:{selector:r.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:t,children:{[o.HUI_ROOT]:{selector:r.HUI_ROOT,children:{shadowRoot:{selector:t,children:{[o.HEADER]:{selector:r.HEADER},[o.HUI_VIEW]:{selector:r.HUI_VIEW}}}}}}}}}},a={shadowRoot:{selector:t,children:{[O.HA_MORE_INFO_DIALOG]:{selector:r.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:t,children:{[O.HA_DIALOG]:{selector:r.HA_DIALOG,children:{[O.HA_DIALOG_CONTENT]:{selector:r.HA_DIALOG_CONTENT,children:{[O.HA_MORE_INFO_DIALOG_INFO]:{selector:r.HA_MORE_INFO_DIALOG_INFO},[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[O.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:r.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}};"function"==typeof SuppressedError&&SuppressedError;const E=(_,s,o,O=!1)=>Object.entries(s||{}).reduce((s,n)=>{const[r,i]=n;if(i.selector===t&&o)return i.children?Object.assign(Object.assign({},s),E(_,i.children,o,!0)):s;const A=o?o.then(t=>{return t?e.asyncQuerySelector(t,(s=i.selector,O?"$ "+s:s),_):null;var s}):e.asyncQuerySelector(i.selector,_);return s[r]={element:A,children:E(_,i.children,A),selector:new e.AsyncSelector(A,_)},s},{}),l=(e,t)=>{const _=Object.entries(t);for(const t of _){if(t[0]===e)return t[1];{const _=l(e,t[1].children);if(_)return _}}},c=(e,t)=>Object.keys(e).reduce((e,_)=>{const s=l(_,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 h{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 h{constructor(e={}){super(),this._config=Object.assign(Object.assign({},_),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=O.HA_MORE_INFO_DIALOG_INFO){this._dialogTree=E(this._config,a,this._haRootElements.HOME_ASSISTANT.element);const t=c(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,_)=>(t[_]=e[_],t),{}))(t,e);const _={[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(_[e],this._haDialogElements)}_updateRootElements(){this._homeAssistantRootTree=E(this._config,i),this._haRootElements=c(s,this._homeAssistantRootTree),this._haRootElements[s.HOME_ASSISTANT].selector.$.element.then(e=>{this._dialogsObserver.disconnect(),this._dialogsObserver.observe(e,{childList:!0})}),this._haRootElements[s.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=E(this._config,A,this._haRootElements[s.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(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===r.HA_MORE_INFO_DIALOG&&this._updateDialogElements()})})}_watchDialogsContent(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{const t={[r.HA_MORE_INFO_DIALOG_INFO]:O.HA_MORE_INFO_DIALOG_INFO,[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[r.HA_DIALOG_MORE_INFO_SETTINGS]:O.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(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements),e instanceof Element&&e.localName===r.HA_PANEL_LOVELACE&&this._updateLovelaceElements()})})}_watchLovelace(e){e.forEach(({addedNodes:e})=>{e.forEach(e=>{e instanceof Element&&e.localName===r.HUI_ROOT&&this._updateLovelaceElements()})})}listen(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()}addEventListener(e,t,_){super.addEventListener(e,t,_)}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "home-assistant-query-selector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Easily query home-assistant DOM elements in an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -49,9 +49,10 @@
|
|
|
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
51
|
"reset:ha": "git add .hass/config/.HA_VERSION && git checkout .hass/config",
|
|
52
|
-
"demo:ha": "pnpm test:clean && pnpm build && pnpm start:ha",
|
|
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\"",
|
|
55
|
+
"trace:show-report": "npx playwright show-report",
|
|
55
56
|
"prepare": "pnpm build",
|
|
56
57
|
"prepublishOnly": "pnpm lint && pnpm test:ts && pnpm test:ci",
|
|
57
58
|
"version": "git add .",
|
|
@@ -61,26 +62,31 @@
|
|
|
61
62
|
"@eslint/js": "^10.0.1",
|
|
62
63
|
"@playwright/test": "1.58.2",
|
|
63
64
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
64
|
-
"@rollup/plugin-terser": "^0.
|
|
65
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
66
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
65
67
|
"@types/eslint": "^9.6.1",
|
|
66
|
-
"@types/node": "^25.
|
|
68
|
+
"@types/node": "^25.5.0",
|
|
67
69
|
"@types/sinon": "^21.0.0",
|
|
68
|
-
"eslint": "^10.
|
|
69
|
-
"globals": "^17.
|
|
70
|
-
"nyc": "^
|
|
70
|
+
"eslint": "^10.1.0",
|
|
71
|
+
"globals": "^17.4.0",
|
|
72
|
+
"nyc": "^18.0.0",
|
|
71
73
|
"playwright-test-coverage": "^1.2.12",
|
|
72
|
-
"rollup": "^4.
|
|
74
|
+
"rollup": "^4.60.0",
|
|
75
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
73
76
|
"rollup-plugin-istanbul": "^5.0.0",
|
|
74
77
|
"rollup-plugin-serve": "^2.0.3",
|
|
75
|
-
"rollup-plugin-
|
|
76
|
-
"sinon": "^21.0.
|
|
78
|
+
"rollup-plugin-tsconfig-paths": "^1.5.2",
|
|
79
|
+
"sinon": "^21.0.3",
|
|
77
80
|
"tslib": "^2.8.1",
|
|
78
|
-
"typescript": "^
|
|
79
|
-
"typescript-eslint": "^8.
|
|
81
|
+
"typescript": "^6.0.2",
|
|
82
|
+
"typescript-eslint": "^8.57.2"
|
|
80
83
|
},
|
|
81
84
|
"dependencies": {
|
|
82
85
|
"shadow-dom-selector": "^5.0.1"
|
|
83
86
|
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"shadow-dom-selector": "^5.0.1"
|
|
89
|
+
},
|
|
84
90
|
"pnpm": {
|
|
85
91
|
"overrides": {
|
|
86
92
|
"diff@>=6.0.0 <8.0.3": ">=8.0.3"
|