home-assistant-query-selector 5.0.0 → 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.
@@ -1,14 +1,8 @@
1
- import { AsyncSelector, AsyncParams } from "shadow-dom-selector";
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, "children">;
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
- export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnListenDetail, OnPanelLoadDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnHistoryAndLogBookDialogOpenDetail, OnSettingsDialogOpenDetail };
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";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(e,t)};var _=function(){return _=Object.assign||function(e){for(var t,o=1,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},_.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,r,O,i,s,a,A,l,c,E,h,I,d,N,L,R,u="$",D={retries:100,delay:50,eventThreshold:450};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(n||(n={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(r||(r={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(O||(O={})),function(e){e.ON_LISTEN="onListen",e.ON_PANEL_LOAD="onPanelLoad",e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",e.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",e.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen"}(i||(i={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-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={}));var v=((s={})[n.HOME_ASSISTANT]={selector:R.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(a={},a[n.HOME_ASSISTANT_MAIN]={selector:R.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(A={},A[n.HA_DRAWER]={selector:R.HA_DRAWER,children:(l={},l[n.HA_SIDEBAR]={selector:R.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},l[n.PARTIAL_PANEL_RESOLVER]={selector:R.PARTIAL_PANEL_RESOLVER},l)},A)}}},a)}}},s),H=((c={})[r.HA_PANEL_LOVELACE]={selector:R.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(E={},E[r.HUI_ROOT]={selector:R.HUI_ROOT,children:{shadowRoot:{selector:u,children:(h={},h[r.HEADER]={selector:R.HEADER},h[r.HUI_VIEW]={selector:R.HUI_VIEW},h)}}},E)}}},c),p={shadowRoot:{selector:u,children:(I={},I[O.HA_MORE_INFO_DIALOG]={selector:R.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(d={},d[O.HA_DIALOG]={selector:R.HA_DIALOG,children:(N={},N[O.HA_DIALOG_CONTENT]={selector:R.HA_DIALOG_CONTENT,children:(L={},L[O.HA_MORE_INFO_DIALOG_INFO]={selector:R.HA_MORE_INFO_DIALOG_INFO},L[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},L[O.HA_DIALOG_MORE_INFO_SETTINGS]={selector:R.HA_DIALOG_MORE_INFO_SETTINGS},L)},N)},d)}}},I)}},f=function(o,n,r,O){return void 0===r&&(r=null),void 0===O&&(O=!1),Object.entries(n||{}).reduce((function(n,i){var s=i[0],a=i[1];if(a.selector===u&&r)return a.children?_(_({},n),f(o,a.children,r,!0)):n;var A=r?r.then((function(t){return t?e(t,(_=a.selector,O?"$ "+_:_),o):null;var _})):e(a.selector,o);return n[s]={element:A,children:f(o,a.children,A),selector:new t(A,o)},n}),{})},T=function(e,t){for(var o=0,_=Object.entries(t);o<_.length;o++){var n=_[o];if(n[0]===e)return n[1];var r=T(e,n[1].children);if(r)return r}},S=function(e,t){return Object.keys(e).reduce((function(e,o){var n=T(o,t);n.children;var r=function(e,t){var o={};for(var _ in e)Object.prototype.hasOwnProperty.call(e,_)&&t.indexOf(_)<0&&(o[_]=e[_]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(_=Object.getOwnPropertySymbols(e);n<_.length;n++)t.indexOf(_[n])<0&&Object.prototype.propertyIsEnumerable.call(e,_[n])&&(o[_[n]]=e[_[n]])}return o}(n,["children"]);return e[o]=_({},r),e}),{})},G=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),m=function(e){function t(t){void 0===t&&(t={});var o=e.call(this)||this;return o._config=_(_({},D),t),o._timestaps={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function _(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(_.prototype=t.prototype,new _)}(t,e),t.prototype._dispatchEvent=function(e,t){var o=Date.now();o-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=o,this.dispatchEvent(new CustomEvent(e,{detail:t})))},t.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=O.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=f(this._config,p,this._haRootElements.HOME_ASSISTANT.element);var _=S(O,this._dialogTree);_.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[O.HA_MORE_INFO_DIALOG,O.HA_DIALOG,O.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(_,e);var n=((t={})[O.HA_MORE_INFO_DIALOG_INFO]=i.ON_MORE_INFO_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=i.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_SETTINGS]=i.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(n[e],this._haDialogElements)},t.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=f(this._config,v),this._haRootElements=S(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{subtree:!0,childList:!0})})),this._dispatchEvent(i.ON_LISTEN,this._haRootElements),this._dispatchEvent(i.ON_PANEL_LOAD,this._haRootElements)},t.prototype._updateLovelaceElements=function(){var e=this;this._homeAssistantResolverTree=f(this._config,H,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=S(r,this._homeAssistantResolverTree),this._haResolverElements[r.HA_PANEL_LOVELACE].element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t.shadowRoot,{childList:!0}),e._dispatchEvent(i.ON_LOVELACE_PANEL_LOAD,_(_({},e._haRootElements),e._haResolverElements)))}))},t.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},t.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,_=((o={})[R.HA_MORE_INFO_DIALOG_INFO]=O.HA_MORE_INFO_DIALOG_INFO,o[R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[R.HA_DIALOG_MORE_INFO_SETTINGS]=O.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in _){var n=e.localName;t._updateDialogElements(_[n])}}))}))},t.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(i.ON_PANEL_LOAD,t._haRootElements),e.localName===R.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},t.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HUI_ROOT&&t._updateLovelaceElements()}))}))},t.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},t.prototype.addEventListener=function(t,o,_){e.prototype.addEventListener.call(this,t,o,_)},t}(G);export{m as HAQuerySelector,i as HAQuerySelectorEvent};
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 "shadow-dom-selector";
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, "children">;
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
- export { HAQuerySelector, HAQuerySelectorEvent, HAElement, OnListenDetail, OnPanelLoadDetail, OnLovelacePanelLoadDetail, OnMoreInfoDialogOpenDetail, OnHistoryAndLogBookDialogOpenDetail, OnSettingsDialogOpenDetail };
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"),t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},t(e,o)};var o=function(){return o=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var _ in t=arguments[o])Object.prototype.hasOwnProperty.call(t,_)&&(e[_]=t[_]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,_,r,s,O,i,a,A,c,l,E,h,I,d,N,L,u="$",R={retries:100,delay:50,eventThreshold:450};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(n||(n={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(_||(_={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(r||(r={})),exports.HAQuerySelectorEvent=void 0,(s=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LISTEN="onListen",s.ON_PANEL_LOAD="onPanelLoad",s.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",s.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",s.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",s.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"}(L||(L={}));var v=((O={})[n.HOME_ASSISTANT]={selector:L.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(i={},i[n.HOME_ASSISTANT_MAIN]={selector:L.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(a={},a[n.HA_DRAWER]={selector:L.HA_DRAWER,children:(A={},A[n.HA_SIDEBAR]={selector:L.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},A[n.PARTIAL_PANEL_RESOLVER]={selector:L.PARTIAL_PANEL_RESOLVER},A)},a)}}},i)}}},O),H=((c={})[_.HA_PANEL_LOVELACE]={selector:L.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(l={},l[_.HUI_ROOT]={selector:L.HUI_ROOT,children:{shadowRoot:{selector:u,children:(E={},E[_.HEADER]={selector:L.HEADER},E[_.HUI_VIEW]={selector:L.HUI_VIEW},E)}}},l)}}},c),p={shadowRoot:{selector:u,children:(h={},h[r.HA_MORE_INFO_DIALOG]={selector:L.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(I={},I[r.HA_DIALOG]={selector:L.HA_DIALOG,children:(d={},d[r.HA_DIALOG_CONTENT]={selector:L.HA_DIALOG_CONTENT,children:(N={},N[r.HA_MORE_INFO_DIALOG_INFO]={selector:L.HA_MORE_INFO_DIALOG_INFO},N[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},N[r.HA_DIALOG_MORE_INFO_SETTINGS]={selector:L.HA_DIALOG_MORE_INFO_SETTINGS},N)},d)},I)}}},h)}},D=function(t,n,_,r){return void 0===_&&(_=null),void 0===r&&(r=!1),Object.entries(n||{}).reduce((function(n,s){var O=s[0],i=s[1];if(i.selector===u&&_)return i.children?o(o({},n),D(t,i.children,_,!0)):n;var a=_?_.then((function(o){return o?e.asyncQuerySelector(o,(n=i.selector,r?"$ "+n:n),t):null;var n})):e.asyncQuerySelector(i.selector,t);return n[O]={element:a,children:D(t,i.children,a),selector:new e.AsyncSelector(a,t)},n}),{})},S=function(e,t){for(var o=0,n=Object.entries(t);o<n.length;o++){var _=n[o];if(_[0]===e)return _[1];var r=S(e,_[1].children);if(r)return r}},f=function(e,t){return Object.keys(e).reduce((function(e,n){var _=S(n,t);_.children;var r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var _=0;for(n=Object.getOwnPropertySymbols(e);_<n.length;_++)t.indexOf(n[_])<0&&Object.prototype.propertyIsEnumerable.call(e,n[_])&&(o[n[_]]=e[n[_]])}return o}(_,["children"]);return e[n]=o({},r),e}),{})},T=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),G=function(e){function s(t){void 0===t&&(t={});var n=e.call(this)||this;return n._config=o(o({},R),t),n._timestaps={},n}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(s,e),s.prototype._dispatchEvent=function(e,t){var o=Date.now();o-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=o,this.dispatchEvent(new CustomEvent(e,{detail:t})))},s.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=r.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=D(this._config,p,this._haRootElements.HOME_ASSISTANT.element);var n=f(r,this._dialogTree);n.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[r.HA_MORE_INFO_DIALOG,r.HA_DIALOG,r.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(n,e);var _=((t={})[r.HA_MORE_INFO_DIALOG_INFO]=exports.HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=exports.HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_SETTINGS]=exports.HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(_[e],this._haDialogElements)},s.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=D(this._config,v),this._haRootElements=f(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{subtree:!0,childList:!0})})),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LISTEN,this._haRootElements),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements)},s.prototype._updateLovelaceElements=function(){var e=this;this._homeAssistantResolverTree=D(this._config,H,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=f(_,this._homeAssistantResolverTree),this._haResolverElements[_.HA_PANEL_LOVELACE].element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t.shadowRoot,{childList:!0}),e._dispatchEvent(exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,o(o({},e._haRootElements),e._haResolverElements)))}))},s.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},s.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,n=((o={})[L.HA_MORE_INFO_DIALOG_INFO]=r.HA_MORE_INFO_DIALOG_INFO,o[L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[L.HA_DIALOG_MORE_INFO_SETTINGS]=r.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in n){var _=e.localName;t._updateDialogElements(n[_])}}))}))},s.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,t._haRootElements),e.localName===L.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},s.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HUI_ROOT&&t._updateLovelaceElements()}))}))},s.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},s.prototype.addEventListener=function(t,o,n){e.prototype.addEventListener.call(this,t,o,n)},s}(T);exports.HAQuerySelector=G;
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": "5.0.0",
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",
@@ -62,26 +62,31 @@
62
62
  "@eslint/js": "^10.0.1",
63
63
  "@playwright/test": "1.58.2",
64
64
  "@rollup/plugin-node-resolve": "^16.0.3",
65
- "@rollup/plugin-terser": "^0.4.4",
65
+ "@rollup/plugin-terser": "^1.0.0",
66
+ "@rollup/plugin-typescript": "^12.3.0",
66
67
  "@types/eslint": "^9.6.1",
67
- "@types/node": "^25.3.3",
68
+ "@types/node": "^25.5.0",
68
69
  "@types/sinon": "^21.0.0",
69
- "eslint": "^10.0.2",
70
+ "eslint": "^10.1.0",
70
71
  "globals": "^17.4.0",
71
72
  "nyc": "^18.0.0",
72
73
  "playwright-test-coverage": "^1.2.12",
73
- "rollup": "^4.59.0",
74
+ "rollup": "^4.60.0",
75
+ "rollup-plugin-dts": "^6.4.1",
74
76
  "rollup-plugin-istanbul": "^5.0.0",
75
77
  "rollup-plugin-serve": "^2.0.3",
76
- "rollup-plugin-ts": "^3.4.5",
77
- "sinon": "^21.0.1",
78
+ "rollup-plugin-tsconfig-paths": "^1.5.2",
79
+ "sinon": "^21.0.3",
78
80
  "tslib": "^2.8.1",
79
- "typescript": "^5.9.3",
80
- "typescript-eslint": "^8.56.1"
81
+ "typescript": "^6.0.2",
82
+ "typescript-eslint": "^8.57.2"
81
83
  },
82
84
  "dependencies": {
83
85
  "shadow-dom-selector": "^5.0.1"
84
86
  },
87
+ "peerDependencies": {
88
+ "shadow-dom-selector": "^5.0.1"
89
+ },
85
90
  "pnpm": {
86
91
  "overrides": {
87
92
  "diff@>=6.0.0 <8.0.3": ">=8.0.3"