home-assistant-query-selector 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,6 +62,12 @@ instance.addEventListener('onLovelacePanelLoad', ({ detail }) => {
62
62
  // shadowRoot === hui-root‘s shadowRoot
63
63
  });
64
64
 
65
+ // Deep-querying the sidebar element
66
+ HOME_ASSISTANT.selector.deepQuery('ha-sidebar').element
67
+ .then((sidebar) => {
68
+ // sidebar === ha-sidebar element
69
+ });
70
+
65
71
  });
66
72
 
67
73
  // This event will be triggered every time a more-info dialog is open
@@ -50,9 +50,38 @@ type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typ
50
50
  type OnLovelaceMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
51
51
  type OnLovelaceHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
52
52
  type OnLovelaceSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
53
- declare class HAQuerySelector extends EventTarget {
54
- #private;
53
+ declare class DelegatedEventTarget implements EventTarget {
54
+ private delegate;
55
+ addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
56
+ dispatchEvent(...args: Parameters<EventTarget['dispatchEvent']>): boolean;
57
+ removeEventListener(...args: Parameters<EventTarget['removeEventListener']>): void;
58
+ }
59
+ declare class HAQuerySelector extends DelegatedEventTarget {
55
60
  constructor(config?: HAQuerySelectorConfig);
61
+ private _config;
62
+ private _dialogTree;
63
+ private _homeAssistantRootTree;
64
+ private _homeAssistantResolverTree;
65
+ private _haDialogElements;
66
+ private _haRootElements;
67
+ private _haResolverElements;
68
+ private _dialogsObserver;
69
+ private _dialogsContentObserver;
70
+ private _panelResolverObserver;
71
+ private _lovelaceObserver;
72
+ private _watchDialogsBinded;
73
+ private _watchDialogsContentBinded;
74
+ private _watchDashboardsBinded;
75
+ private _watchLovelaceBinded;
76
+ private _timestap;
77
+ private _dispatchEvent;
78
+ private _updateDialogElements;
79
+ private _updateRootElements;
80
+ private _updateResolverElements;
81
+ private _watchDialogs;
82
+ private _watchDialogsContent;
83
+ private _watchDashboards;
84
+ private _watchLovelace;
56
85
  listen(): void;
57
86
  addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
58
87
  addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnLovelaceMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";function O(e,t,O,_){if("a"===O&&!_)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!_:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===O?_:"a"===O?_.call(e):_?_.value:t.get(e)}function _(e,t,O,_,s){if("m"===_)throw new TypeError("Private method is not writable");if("a"===_&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===_?s.call(e,O):s?s.value=O:t.set(e,O),O}"function"==typeof SuppressedError&&SuppressedError;const s="$",i={retries:100,delay:50};var o,A,n,r,E;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(o||(o={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(A||(A={})),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_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",e.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",e.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen"}(r||(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",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(E||(E={}));const a={[o.HOME_ASSISTANT]:{selector:E.HOME_ASSISTANT,children:{shadowRoot:{selector:s,children:{[o.HOME_ASSISTANT_MAIN]:{selector:E.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:s,children:{[o.HA_DRAWER]:{selector:E.HA_DRAWER,children:{[o.HA_SIDEBAR]:{selector:E.HA_SIDEBAR,children:{shadowRoot:{selector:s}}}}}}}}}}}}}},h={[A.PARTIAL_PANEL_RESOLVER]:{selector:E.PARTIAL_PANEL_RESOLVER,children:{[A.HA_PANEL_LOVELACE]:{selector:E.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:s,children:{[A.HUI_ROOT]:{selector:E.HUI_ROOT,children:{shadowRoot:{selector:s,children:{[A.HEADER]:{selector:E.HEADER},[A.HUI_VIEW]:{selector:E.HUI_VIEW}}}}}}}}}}}},I={shadowRoot:{selector:s,children:{[n.HA_MORE_INFO_DIALOG]:{selector:E.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:s,children:{[n.HA_DIALOG]:{selector:E.HA_DIALOG,children:{[n.HA_DIALOG_CONTENT]:{selector:E.HA_DIALOG_CONTENT,children:{[n.HA_MORE_INFO_DIALOG_INFO]:{selector:E.HA_MORE_INFO_DIALOG_INFO},[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[n.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:E.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},c=(O,_,i=null,o=!1)=>Object.entries(_||{}).reduce(((_,A)=>{const[n,r]=A;if(r.selector===s&&i)return r.children?Object.assign(Object.assign({},_),c(O,r.children,i,!0)):_;const E=i?i.then((t=>{return e(t,(_=r.selector,o?"$ "+_:_),O);var _})):e(r.selector,O);return _[n]={element:E,children:c(O,r.children,E),selector:new t(E,O)},_}),{}),l=(e,t)=>{const O=Object.entries(t);for(const t of O){if(t[0]===e)return t[1];{const O=l(e,t[1].children);if(O)return O}}},N=(e,t)=>Object.keys(e).reduce(((e,O)=>{const _=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 s=0;for(_=Object.getOwnPropertySymbols(e);s<_.length;s++)t.indexOf(_[s])<0&&Object.prototype.propertyIsEnumerable.call(e,_[s])&&(O[_[s]]=e[_[s]])}return O}(l(O,t),["children"]);return e[O]=Object.assign({},_),e}),{});var L,d,H,f,R,T,D,S,M,G,w,p,u,v,m,F,b,P,W,V,C,g,y,k,j;class B extends EventTarget{constructor(e={}){super(),L.add(this),d.set(this,void 0),H.set(this,void 0),f.set(this,void 0),R.set(this,void 0),T.set(this,void 0),D.set(this,void 0),S.set(this,void 0),M.set(this,void 0),G.set(this,void 0),w.set(this,void 0),p.set(this,void 0),u.set(this,void 0),v.set(this,void 0),m.set(this,void 0),F.set(this,void 0),b.set(this,void 0),_(this,d,Object.assign(Object.assign({},i),e),"f")}listen(){_(this,u,O(this,L,"m",g).bind(this),"f"),_(this,v,O(this,L,"m",y).bind(this),"f"),_(this,m,O(this,L,"m",k).bind(this),"f"),_(this,F,O(this,L,"m",j).bind(this),"f"),_(this,M,new MutationObserver(O(this,u,"f")),"f"),_(this,G,new MutationObserver(O(this,v,"f")),"f"),_(this,w,new MutationObserver(O(this,m,"f")),"f"),_(this,p,new MutationObserver(O(this,F,"f")),"f"),O(this,L,"m",V).call(this),O(this,L,"m",C).call(this)}addEventListener(e,t,O){super.addEventListener(e,t,O)}}d=new WeakMap,H=new WeakMap,f=new WeakMap,R=new WeakMap,T=new WeakMap,D=new WeakMap,S=new WeakMap,M=new WeakMap,G=new WeakMap,w=new WeakMap,p=new WeakMap,u=new WeakMap,v=new WeakMap,m=new WeakMap,F=new WeakMap,b=new WeakMap,L=new WeakSet,P=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},W=function(e=n.HA_MORE_INFO_DIALOG_INFO){_(this,H,c(O(this,d,"f"),I,O(this,D,"f").HOME_ASSISTANT.element),"f");const t=N(n,O(this,H,"f"));t.HA_DIALOG_CONTENT.element.then((e=>{O(this,G,"f").disconnect(),O(this,G,"f").observe(e,{childList:!0})})),_(this,T,((e,t)=>[n.HA_MORE_INFO_DIALOG,n.HA_DIALOG,n.HA_DIALOG_CONTENT,t].reduce(((t,O)=>(t[O]=e[O],t)),{}))(t,e),"f");const s={[n.HA_MORE_INFO_DIALOG_INFO]:r.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:r.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[n.HA_DIALOG_MORE_INFO_SETTINGS]:r.ON_LOVELACE_SETTINGS_DIALOG_OPEN};O(this,L,"m",P).call(this,s[e],O(this,T,"f"))},V=function(){_(this,f,c(O(this,d,"f"),a),"f"),_(this,D,N(o,O(this,f,"f")),"f"),O(this,D,"f")[o.HOME_ASSISTANT].selector.$.element.then((e=>{O(this,M,"f").disconnect(),O(this,M,"f").observe(e,{childList:!0})}))},C=function(){const e=Date.now();e-O(this,b,"f")<500||(_(this,b,e,"f"),_(this,R,c(O(this,d,"f"),h,O(this,D,"f")[o.HA_DRAWER].element),"f"),_(this,S,N(A,O(this,R,"f")),"f"),O(this,S,"f")[A.PARTIAL_PANEL_RESOLVER].element.then((e=>{O(this,w,"f").disconnect(),O(this,w,"f").observe(e,{childList:!0})})),O(this,S,"f")[A.HA_PANEL_LOVELACE].selector.$.element.then((e=>{O(this,p,"f").disconnect(),O(this,p,"f").observe(e,{childList:!0})})),O(this,L,"m",P).call(this,r.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},O(this,D,"f")),O(this,S,"f"))))},g=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_MORE_INFO_DIALOG&&O(this,L,"m",W).call(this)}))}))},y=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const t={[E.HA_MORE_INFO_DIALOG_INFO]:n.HA_MORE_INFO_DIALOG_INFO,[E.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[E.HA_DIALOG_MORE_INFO_SETTINGS]:n.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in t){const _=e.localName;O(this,L,"m",W).call(this,t[_])}}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HA_PANEL_LOVELACE&&O(this,L,"m",C).call(this)}))}))},j=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===E.HUI_ROOT&&O(this,L,"m",C).call(this)}))}))};export{B as HAQuerySelector,r as HAQuerySelectorEvent};
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,L,d,N,R,u,H="$",D={retries:100,delay:50};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(n||(n={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(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_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",e.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",e.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen"}(i||(i={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(u||(u={}));var v=((s={})[n.HOME_ASSISTANT]={selector:u.HOME_ASSISTANT,children:{shadowRoot:{selector:H,children:(a={},a[n.HOME_ASSISTANT_MAIN]={selector:u.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:H,children:(A={},A[n.HA_DRAWER]={selector:u.HA_DRAWER,children:(l={},l[n.HA_SIDEBAR]={selector:u.HA_SIDEBAR,children:{shadowRoot:{selector:H}}},l)},A)}}},a)}}},s),p=((c={})[r.PARTIAL_PANEL_RESOLVER]={selector:u.PARTIAL_PANEL_RESOLVER,children:(E={},E[r.HA_PANEL_LOVELACE]={selector:u.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:H,children:(h={},h[r.HUI_ROOT]={selector:u.HUI_ROOT,children:{shadowRoot:{selector:H,children:(I={},I[r.HEADER]={selector:u.HEADER},I[r.HUI_VIEW]={selector:u.HUI_VIEW},I)}}},h)}}},E)},c),f={shadowRoot:{selector:H,children:(L={},L[O.HA_MORE_INFO_DIALOG]={selector:u.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:H,children:(d={},d[O.HA_DIALOG]={selector:u.HA_DIALOG,children:(N={},N[O.HA_DIALOG_CONTENT]={selector:u.HA_DIALOG_CONTENT,children:(R={},R[O.HA_MORE_INFO_DIALOG_INFO]={selector:u.HA_MORE_INFO_DIALOG_INFO},R[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:u.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},R[O.HA_DIALOG_MORE_INFO_SETTINGS]={selector:u.HA_DIALOG_MORE_INFO_SETTINGS},R)},N)},d)}}},L)}},T=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===H&&r)return a.children?_(_({},n),T(o,a.children,r,!0)):n;var A=r?r.then((function(t){return e(t,(_=a.selector,O?"$ "+_:_),o);var _})):e(a.selector,o);return n[s]={element:A,children:T(o,a.children,A),selector:new t(A,o)},n}),{})},S=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=S(e,n[1].children);if(r)return r}},G=function(e,t){return Object.keys(e).reduce((function(e,o){var n=S(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}),{})},m=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),M=function(e){function t(t){void 0===t&&(t={});var o=e.call(this)||this;return o._config=_(_({},D),t),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function _(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(_.prototype=t.prototype,new _)}(t,e),t.prototype._dispatchEvent=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},t.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=O.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=T(this._config,f,this._haRootElements.HOME_ASSISTANT.element);var _=G(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_LOVELACE_MORE_INFO_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=i.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_SETTINGS]=i.ON_LOVELACE_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(n[e],this._haDialogElements)},t.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=T(this._config,v),this._haRootElements=G(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})}))},t.prototype._updateResolverElements=function(){var e=this,t=Date.now();t-this._timestap<500||(this._timestap=t,this._homeAssistantResolverTree=T(this._config,p,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=G(r,this._homeAssistantResolverTree),this._haResolverElements[r.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),e._panelResolverObserver.observe(t,{childList:!0})})),this._haResolverElements[r.HA_PANEL_LOVELACE].selector.$.element.then((function(t){e._lovelaceObserver.disconnect(),e._lovelaceObserver.observe(t,{childList:!0})})),this._dispatchEvent(i.ON_LOVELACE_PANEL_LOAD,_(_({},this._haRootElements),this._haResolverElements)))},t.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===u.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={})[u.HA_MORE_INFO_DIALOG_INFO]=O.HA_MORE_INFO_DIALOG_INFO,o[u.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[u.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){e.localName===u.HA_PANEL_LOVELACE&&t._updateResolverElements()}))}))},t.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===u.HUI_ROOT&&t._updateResolverElements()}))}))},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._updateResolverElements()},t.prototype.addEventListener=function(t,o,_){e.prototype.addEventListener.call(this,t,o,_)},t}(m);export{M as HAQuerySelector,i as HAQuerySelectorEvent};
package/dist/index.d.ts CHANGED
@@ -50,9 +50,38 @@ type OnLovelacePanelLoadDetail = Record<keyof typeof HA_ROOT_ELEMENT | keyof typ
50
50
  type OnLovelaceMoreInfoDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
51
51
  type OnLovelaceHistoryAndLogBookDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_SETTINGS'>, HAElement>;
52
52
  type OnLovelaceSettingsDialogOpenDetail = Record<Exclude<keyof typeof HA_DIALOG_ELEMENT, 'HA_MORE_INFO_DIALOG_INFO' | 'HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK'>, HAElement>;
53
- declare class HAQuerySelector extends EventTarget {
54
- #private;
53
+ declare class DelegatedEventTarget implements EventTarget {
54
+ private delegate;
55
+ addEventListener(...args: Parameters<EventTarget['addEventListener']>): void;
56
+ dispatchEvent(...args: Parameters<EventTarget['dispatchEvent']>): boolean;
57
+ removeEventListener(...args: Parameters<EventTarget['removeEventListener']>): void;
58
+ }
59
+ declare class HAQuerySelector extends DelegatedEventTarget {
55
60
  constructor(config?: HAQuerySelectorConfig);
61
+ private _config;
62
+ private _dialogTree;
63
+ private _homeAssistantRootTree;
64
+ private _homeAssistantResolverTree;
65
+ private _haDialogElements;
66
+ private _haRootElements;
67
+ private _haResolverElements;
68
+ private _dialogsObserver;
69
+ private _dialogsContentObserver;
70
+ private _panelResolverObserver;
71
+ private _lovelaceObserver;
72
+ private _watchDialogsBinded;
73
+ private _watchDialogsContentBinded;
74
+ private _watchDashboardsBinded;
75
+ private _watchLovelaceBinded;
76
+ private _timestap;
77
+ private _dispatchEvent;
78
+ private _updateDialogElements;
79
+ private _updateRootElements;
80
+ private _updateResolverElements;
81
+ private _watchDialogs;
82
+ private _watchDialogsContent;
83
+ private _watchDashboards;
84
+ private _watchLovelace;
56
85
  listen(): void;
57
86
  addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD}`, callback: HAQuerySelectorEventListener<OnLovelacePanelLoadDetail>, options?: boolean | AddEventListenerOptions): void;
58
87
  addEventListener(type: `${HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN}`, callback: HAQuerySelectorEventListener<OnLovelaceMoreInfoDialogOpenDetail>, options?: boolean | AddEventListenerOptions): void;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("shadow-dom-selector");function t(e,t,O,_){if("a"===O&&!_)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!_:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===O?_:"a"===O?_.call(e):_?_.value:t.get(e)}function O(e,t,O,_,s){if("m"===_)throw new TypeError("Private method is not writable");if("a"===_&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===_?s.call(e,O):s?s.value=O:t.set(e,O),O}"function"==typeof SuppressedError&&SuppressedError;const _="$",s={retries:100,delay:50};var o,i,A,r,n;!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(o||(o={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(i||(i={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(A||(A={})),exports.HAQuerySelectorEvent=void 0,(r=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",r.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",r.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",r.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(n||(n={}));const E={[o.HOME_ASSISTANT]:{selector:n.HOME_ASSISTANT,children:{shadowRoot:{selector:_,children:{[o.HOME_ASSISTANT_MAIN]:{selector:n.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:_,children:{[o.HA_DRAWER]:{selector:n.HA_DRAWER,children:{[o.HA_SIDEBAR]:{selector:n.HA_SIDEBAR,children:{shadowRoot:{selector:_}}}}}}}}}}}}}},c={[i.PARTIAL_PANEL_RESOLVER]:{selector:n.PARTIAL_PANEL_RESOLVER,children:{[i.HA_PANEL_LOVELACE]:{selector:n.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:_,children:{[i.HUI_ROOT]:{selector:n.HUI_ROOT,children:{shadowRoot:{selector:_,children:{[i.HEADER]:{selector:n.HEADER},[i.HUI_VIEW]:{selector:n.HUI_VIEW}}}}}}}}}}}},a={shadowRoot:{selector:_,children:{[A.HA_MORE_INFO_DIALOG]:{selector:n.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:_,children:{[A.HA_DIALOG]:{selector:n.HA_DIALOG,children:{[A.HA_DIALOG_CONTENT]:{selector:n.HA_DIALOG_CONTENT,children:{[A.HA_MORE_INFO_DIALOG_INFO]:{selector:n.HA_MORE_INFO_DIALOG_INFO},[A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:{selector:n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},[A.HA_DIALOG_MORE_INFO_SETTINGS]:{selector:n.HA_DIALOG_MORE_INFO_SETTINGS}}}}}}}}}}}},h=(t,O,s=null,o=!1)=>Object.entries(O||{}).reduce(((O,i)=>{const[A,r]=i;if(r.selector===_&&s)return r.children?Object.assign(Object.assign({},O),h(t,r.children,s,!0)):O;const n=s?s.then((O=>{return e.asyncQuerySelector(O,(_=r.selector,o?"$ "+_:_),t);var _})):e.asyncQuerySelector(r.selector,t);return O[A]={element:n,children:h(t,r.children,n),selector:new e.AsyncSelector(n,t)},O}),{}),I=(e,t)=>{const O=Object.entries(t);for(const t of O){if(t[0]===e)return t[1];{const O=I(e,t[1].children);if(O)return O}}},l=(e,t)=>Object.keys(e).reduce(((e,O)=>{const _=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 s=0;for(_=Object.getOwnPropertySymbols(e);s<_.length;s++)t.indexOf(_[s])<0&&Object.prototype.propertyIsEnumerable.call(e,_[s])&&(O[_[s]]=e[_[s]])}return O}(I(O,t),["children"]);return e[O]=Object.assign({},_),e}),{});var N,L,d,H,f,R,S,T,D,M,G,u,v,p,w,m,F,b,y,P,W,V,C,g,k;class j extends EventTarget{constructor(e={}){super(),N.add(this),L.set(this,void 0),d.set(this,void 0),H.set(this,void 0),f.set(this,void 0),R.set(this,void 0),S.set(this,void 0),T.set(this,void 0),D.set(this,void 0),M.set(this,void 0),G.set(this,void 0),u.set(this,void 0),v.set(this,void 0),p.set(this,void 0),w.set(this,void 0),m.set(this,void 0),F.set(this,void 0),O(this,L,Object.assign(Object.assign({},s),e),"f")}listen(){O(this,v,t(this,N,"m",V).bind(this),"f"),O(this,p,t(this,N,"m",C).bind(this),"f"),O(this,w,t(this,N,"m",g).bind(this),"f"),O(this,m,t(this,N,"m",k).bind(this),"f"),O(this,D,new MutationObserver(t(this,v,"f")),"f"),O(this,M,new MutationObserver(t(this,p,"f")),"f"),O(this,G,new MutationObserver(t(this,w,"f")),"f"),O(this,u,new MutationObserver(t(this,m,"f")),"f"),t(this,N,"m",P).call(this),t(this,N,"m",W).call(this)}addEventListener(e,t,O){super.addEventListener(e,t,O)}}L=new WeakMap,d=new WeakMap,H=new WeakMap,f=new WeakMap,R=new WeakMap,S=new WeakMap,T=new WeakMap,D=new WeakMap,M=new WeakMap,G=new WeakMap,u=new WeakMap,v=new WeakMap,p=new WeakMap,w=new WeakMap,m=new WeakMap,F=new WeakMap,N=new WeakSet,b=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},y=function(e=A.HA_MORE_INFO_DIALOG_INFO){O(this,d,h(t(this,L,"f"),a,t(this,S,"f").HOME_ASSISTANT.element),"f");const _=l(A,t(this,d,"f"));_.HA_DIALOG_CONTENT.element.then((e=>{t(this,M,"f").disconnect(),t(this,M,"f").observe(e,{childList:!0})})),O(this,R,((e,t)=>[A.HA_MORE_INFO_DIALOG,A.HA_DIALOG,A.HA_DIALOG_CONTENT,t].reduce(((t,O)=>(t[O]=e[O],t)),{}))(_,e),"f");const s={[A.HA_MORE_INFO_DIALOG_INFO]:exports.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,[A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:exports.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,[A.HA_DIALOG_MORE_INFO_SETTINGS]:exports.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN};t(this,N,"m",b).call(this,s[e],t(this,R,"f"))},P=function(){O(this,H,h(t(this,L,"f"),E),"f"),O(this,S,l(o,t(this,H,"f")),"f"),t(this,S,"f")[o.HOME_ASSISTANT].selector.$.element.then((e=>{t(this,D,"f").disconnect(),t(this,D,"f").observe(e,{childList:!0})}))},W=function(){const e=Date.now();e-t(this,F,"f")<500||(O(this,F,e,"f"),O(this,f,h(t(this,L,"f"),c,t(this,S,"f")[o.HA_DRAWER].element),"f"),O(this,T,l(i,t(this,f,"f")),"f"),t(this,T,"f")[i.PARTIAL_PANEL_RESOLVER].element.then((e=>{t(this,G,"f").disconnect(),t(this,G,"f").observe(e,{childList:!0})})),t(this,T,"f")[i.HA_PANEL_LOVELACE].selector.$.element.then((e=>{t(this,u,"f").disconnect(),t(this,u,"f").observe(e,{childList:!0})})),t(this,N,"m",b).call(this,exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,Object.assign(Object.assign({},t(this,S,"f")),t(this,T,"f"))))},V=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HA_MORE_INFO_DIALOG&&t(this,N,"m",y).call(this)}))}))},C=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{const O={[n.HA_MORE_INFO_DIALOG_INFO]:A.HA_MORE_INFO_DIALOG_INFO,[n.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]:A.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,[n.HA_DIALOG_MORE_INFO_SETTINGS]:A.HA_DIALOG_MORE_INFO_SETTINGS};if(e.localName&&e.localName in O){const _=e.localName;t(this,N,"m",y).call(this,O[_])}}))}))},g=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HA_PANEL_LOVELACE&&t(this,N,"m",W).call(this)}))}))},k=function(e){e.forEach((({addedNodes:e})=>{e.forEach((e=>{e.localName===n.HUI_ROOT&&t(this,N,"m",W).call(this)}))}))},exports.HAQuerySelector=j;
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,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var _,n,r,O,s,i,A,a,c,l,E,h,I,L,d,N,R,u="$",H={retries:100,delay:50};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR"}(_||(_={})),function(e){e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER",e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(n||(n={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(r||(r={})),exports.HAQuerySelectorEvent=void 0,(O=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",O.ON_LOVELACE_MORE_INFO_DIALOG_OPEN="onLovelaceMoreInfoDialogOpen",O.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onLovelaceHistoryAndLogBookDialogOpen",O.ON_LOVELACE_SETTINGS_DIALOG_OPEN="onLovelaceSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(R||(R={}));var v=((s={})[_.HOME_ASSISTANT]={selector:R.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(i={},i[_.HOME_ASSISTANT_MAIN]={selector:R.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(A={},A[_.HA_DRAWER]={selector:R.HA_DRAWER,children:(a={},a[_.HA_SIDEBAR]={selector:R.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},a)},A)}}},i)}}},s),p=((c={})[n.PARTIAL_PANEL_RESOLVER]={selector:R.PARTIAL_PANEL_RESOLVER,children:(l={},l[n.HA_PANEL_LOVELACE]={selector:R.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(E={},E[n.HUI_ROOT]={selector:R.HUI_ROOT,children:{shadowRoot:{selector:u,children:(h={},h[n.HEADER]={selector:R.HEADER},h[n.HUI_VIEW]={selector:R.HUI_VIEW},h)}}},E)}}},l)},c),D={shadowRoot:{selector:u,children:(I={},I[r.HA_MORE_INFO_DIALOG]={selector:R.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(L={},L[r.HA_DIALOG]={selector:R.HA_DIALOG,children:(d={},d[r.HA_DIALOG_CONTENT]={selector:R.HA_DIALOG_CONTENT,children:(N={},N[r.HA_MORE_INFO_DIALOG_INFO]={selector:R.HA_MORE_INFO_DIALOG_INFO},N[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},N[r.HA_DIALOG_MORE_INFO_SETTINGS]={selector:R.HA_DIALOG_MORE_INFO_SETTINGS},N)},d)},L)}}},I)}},S=function(t,_,n,r){return void 0===n&&(n=null),void 0===r&&(r=!1),Object.entries(_||{}).reduce((function(_,O){var s=O[0],i=O[1];if(i.selector===u&&n)return i.children?o(o({},_),S(t,i.children,n,!0)):_;var A=n?n.then((function(o){return e.asyncQuerySelector(o,(_=i.selector,r?"$ "+_:_),t);var _})):e.asyncQuerySelector(i.selector,t);return _[s]={element:A,children:S(t,i.children,A),selector:new e.AsyncSelector(A,t)},_}),{})},f=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=f(e,n[1].children);if(r)return r}},T=function(e,t){return Object.keys(e).reduce((function(e,_){var n=f(_,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 O(t){void 0===t&&(t={});var _=e.call(this)||this;return _._config=o(o({},H),t),_}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 _(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(_.prototype=o.prototype,new _)}(O,e),O.prototype._dispatchEvent=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},O.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=r.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=S(this._config,D,this._haRootElements.HOME_ASSISTANT.element);var _=T(r,this._dialogTree);_.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}),{})}(_,e);var n=((t={})[r.HA_MORE_INFO_DIALOG_INFO]=exports.HAQuerySelectorEvent.ON_LOVELACE_MORE_INFO_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=exports.HAQuerySelectorEvent.ON_LOVELACE_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_SETTINGS]=exports.HAQuerySelectorEvent.ON_LOVELACE_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(n[e],this._haDialogElements)},O.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=S(this._config,v),this._haRootElements=T(_,this._homeAssistantRootTree),this._haRootElements[_.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})}))},O.prototype._updateResolverElements=function(){var e=this,t=Date.now();t-this._timestap<500||(this._timestap=t,this._homeAssistantResolverTree=S(this._config,p,this._haRootElements[_.HA_DRAWER].element),this._haResolverElements=T(n,this._homeAssistantResolverTree),this._haResolverElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),e._panelResolverObserver.observe(t,{childList:!0})})),this._haResolverElements[n.HA_PANEL_LOVELACE].selector.$.element.then((function(t){e._lovelaceObserver.disconnect(),e._lovelaceObserver.observe(t,{childList:!0})})),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,o(o({},this._haRootElements),this._haResolverElements)))},O.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()}))}))},O.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]=r.HA_MORE_INFO_DIALOG_INFO,o[R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[R.HA_DIALOG_MORE_INFO_SETTINGS]=r.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in _){var n=e.localName;t._updateDialogElements(_[n])}}))}))},O.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HA_PANEL_LOVELACE&&t._updateResolverElements()}))}))},O.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HUI_ROOT&&t._updateResolverElements()}))}))},O.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateResolverElements()},O.prototype.addEventListener=function(t,o,_){e.prototype.addEventListener.call(this,t,o,_)},O}(G);exports.HAQuerySelector=m;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "home-assistant-query-selector",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Easily query home-assistant DOM elements in an async way",
5
5
  "keywords": [
6
6
  "query-selector",
@@ -41,8 +41,8 @@
41
41
  "test:open": "cypress open",
42
42
  "test:ci": "yarn demo:ha && yarn test:run && yarn coverage:report && yarn stop:ha",
43
43
  "test:copy": "cp test/index.js .hass/config/www/home-assistant-query-selector-tests.js",
44
- "start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant:2023.11.1",
45
- "stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:2023.11.1) || true",
44
+ "start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant:2023.12.1",
45
+ "stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:2023.12.1) || true",
46
46
  "demo:ha": "yarn build && yarn test:copy && yarn start:ha",
47
47
  "prepare": "yarn build",
48
48
  "prepublishOnly": "yarn lint && yarn test:ts && yarn test:ci",
@@ -50,7 +50,7 @@
50
50
  "postversion": "git push && git push --tags"
51
51
  },
52
52
  "dependencies": {
53
- "shadow-dom-selector": "^3.0.0"
53
+ "shadow-dom-selector": "^4.0.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@cypress/code-coverage": "^3.12.10",