@a11d/lit 0.2.8 → 0.2.9

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.
Files changed (62) hide show
  1. package/dist/Component/Component.d.ts +22 -22
  2. package/dist/Component/Component.js +35 -35
  3. package/dist/Component/index.d.ts +2 -2
  4. package/dist/Component/index.js +2 -2
  5. package/dist/Component/nothing.d.ts +2 -2
  6. package/dist/Component/nothing.js +2 -2
  7. package/dist/Controller/Controller.d.ts +9 -9
  8. package/dist/Controller/Controller.js +6 -6
  9. package/dist/Controller/index.d.ts +1 -1
  10. package/dist/Controller/index.js +1 -1
  11. package/dist/event/EventDispatcher.d.ts +9 -9
  12. package/dist/event/EventDispatcher.js +1 -1
  13. package/dist/event/HTMLElementEventDispatcher.d.ts +12 -12
  14. package/dist/event/HTMLElementEventDispatcher.js +27 -27
  15. package/dist/event/PureEventDispatcher.d.ts +6 -6
  16. package/dist/event/PureEventDispatcher.js +16 -16
  17. package/dist/event/event.d.ts +1 -1
  18. package/dist/event/event.js +20 -20
  19. package/dist/event/index.d.ts +4 -4
  20. package/dist/event/index.js +4 -4
  21. package/dist/eventListener/EventListenerController.d.ts +23 -23
  22. package/dist/eventListener/EventListenerController.js +57 -57
  23. package/dist/eventListener/EventListenerTarget.d.ts +3 -3
  24. package/dist/eventListener/EventListenerTarget.js +1 -1
  25. package/dist/eventListener/eventListener.d.ts +12 -12
  26. package/dist/eventListener/eventListener.js +31 -31
  27. package/dist/eventListener/extractEventHandler.d.ts +1 -1
  28. package/dist/eventListener/extractEventHandler.js +9 -9
  29. package/dist/eventListener/index.d.ts +4 -4
  30. package/dist/eventListener/index.js +4 -4
  31. package/dist/index.d.ts +35 -35
  32. package/dist/index.js +35 -35
  33. package/dist/query/index.d.ts +3 -3
  34. package/dist/query/index.js +3 -3
  35. package/dist/query/query.d.ts +2 -2
  36. package/dist/query/query.js +9 -9
  37. package/dist/query/queryAll.d.ts +2 -2
  38. package/dist/query/queryAll.js +9 -9
  39. package/dist/query/queryAllAsNodeList.d.ts +2 -2
  40. package/dist/query/queryAllAsNodeList.js +2 -2
  41. package/dist/style/CustomPropertyStyleHandler.d.ts +5 -5
  42. package/dist/style/CustomPropertyStyleHandler.js +14 -14
  43. package/dist/style/index.d.ts +2 -2
  44. package/dist/style/index.js +2 -2
  45. package/dist/style/style.d.ts +16 -16
  46. package/dist/style/style.js +33 -32
  47. package/dist/test/ComponentTestFixture.d.ts +10 -10
  48. package/dist/test/ComponentTestFixture.js +28 -28
  49. package/dist/test/index.d.ts +1 -1
  50. package/dist/test/index.js +1 -1
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/dist/types.d.ts +5 -5
  53. package/dist/types.js +1 -1
  54. package/dist/updated/index.d.ts +3 -3
  55. package/dist/updated/index.js +3 -3
  56. package/dist/updated/property.d.ts +5 -5
  57. package/dist/updated/property.js +10 -10
  58. package/dist/updated/state.d.ts +6 -6
  59. package/dist/updated/state.js +10 -10
  60. package/dist/updated/updated.d.ts +3 -3
  61. package/dist/updated/updated.js +25 -25
  62. package/package.json +1 -1
@@ -1,22 +1,22 @@
1
- import { LitElement, PropertyValues } from 'lit';
2
- export declare const component: (tagName: string) => (classOrDescriptor: {
3
- prototype: HTMLElement;
4
- } | import("@lit/reactive-element/decorators/base.js").ClassDescriptor) => any;
5
- export declare abstract class Component extends LitElement {
6
- /** Invoked after first update i.e. render is completed */
7
- protected initialized(): void;
8
- /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
- protected connected(): void;
10
- /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
- protected disconnected(): void;
12
- /** The template rendered into renderRoot. Invoked on each update to perform rendering tasks. */
13
- protected get template(): import("lit-html").HTMLTemplateResult;
14
- /** @final */
15
- protected render(): import("lit-html").HTMLTemplateResult;
16
- /** @final */
17
- protected firstUpdated(props: PropertyValues): void;
18
- /** @final */
19
- connectedCallback(): void;
20
- /** @final */
21
- disconnectedCallback(): void;
22
- }
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ export declare const component: (tagName: string) => (classOrDescriptor: {
3
+ prototype: HTMLElement;
4
+ } | import("@lit/reactive-element/decorators/base.js").ClassDescriptor) => any;
5
+ export declare abstract class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ protected initialized(): void;
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ protected connected(): void;
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ protected disconnected(): void;
12
+ /** The template rendered into renderRoot. Invoked on each update to perform rendering tasks. */
13
+ protected get template(): import("lit-html").HTMLTemplateResult;
14
+ /** @final */
15
+ protected render(): import("lit-html").HTMLTemplateResult;
16
+ /** @final */
17
+ protected firstUpdated(props: PropertyValues): void;
18
+ /** @final */
19
+ connectedCallback(): void;
20
+ /** @final */
21
+ disconnectedCallback(): void;
22
+ }
@@ -1,35 +1,35 @@
1
- import { LitElement } from 'lit';
2
- import { customElement } from 'lit/decorators.js';
3
- import { nothing } from './nothing.js';
4
- export const component = customElement;
5
- export class Component extends LitElement {
6
- /** Invoked after first update i.e. render is completed */
7
- initialized() { }
8
- /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
- connected() { }
10
- /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
- disconnected() { }
12
- /** The template rendered into renderRoot. Invoked on each update to perform rendering tasks. */
13
- get template() {
14
- return nothing;
15
- }
16
- /** @final */
17
- render() {
18
- return this.template;
19
- }
20
- /** @final */
21
- firstUpdated(props) {
22
- super.firstUpdated(props);
23
- this.initialized();
24
- }
25
- /** @final */
26
- connectedCallback() {
27
- super.connectedCallback();
28
- this.connected();
29
- }
30
- /** @final */
31
- disconnectedCallback() {
32
- super.disconnectedCallback();
33
- this.disconnected();
34
- }
35
- }
1
+ import { LitElement } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import { nothing } from './nothing.js';
4
+ export const component = customElement;
5
+ export class Component extends LitElement {
6
+ /** Invoked after first update i.e. render is completed */
7
+ initialized() { }
8
+ /** Invoked every time the component is connected to the Document Object Model (DOM) */
9
+ connected() { }
10
+ /** Invoked every time the component is disconnected from the Document Object Model (DOM) */
11
+ disconnected() { }
12
+ /** The template rendered into renderRoot. Invoked on each update to perform rendering tasks. */
13
+ get template() {
14
+ return nothing;
15
+ }
16
+ /** @final */
17
+ render() {
18
+ return this.template;
19
+ }
20
+ /** @final */
21
+ firstUpdated(props) {
22
+ super.firstUpdated(props);
23
+ this.initialized();
24
+ }
25
+ /** @final */
26
+ connectedCallback() {
27
+ super.connectedCallback();
28
+ this.connected();
29
+ }
30
+ /** @final */
31
+ disconnectedCallback() {
32
+ super.disconnectedCallback();
33
+ this.disconnected();
34
+ }
35
+ }
@@ -1,2 +1,2 @@
1
- export * from './nothing.js';
2
- export * from './Component.js';
1
+ export * from './nothing.js';
2
+ export * from './Component.js';
@@ -1,2 +1,2 @@
1
- export * from './nothing.js';
2
- export * from './Component.js';
1
+ export * from './nothing.js';
2
+ export * from './Component.js';
@@ -1,2 +1,2 @@
1
- import { HTMLTemplateResult } from 'lit';
2
- export declare const nothing: HTMLTemplateResult;
1
+ import { HTMLTemplateResult } from 'lit';
2
+ export declare const nothing: HTMLTemplateResult;
@@ -1,2 +1,2 @@
1
- import { nothing as litNothing } from 'lit';
2
- export const nothing = litNothing;
1
+ import { nothing as litNothing } from 'lit';
2
+ export const nothing = litNothing;
@@ -1,9 +1,9 @@
1
- import { ReactiveController, ReactiveControllerHost } from 'lit';
2
- export declare abstract class Controller implements ReactiveController {
3
- protected readonly host: ReactiveControllerHost;
4
- constructor(host: ReactiveControllerHost);
5
- hostConnected?(): void;
6
- hostDisconnected?(): void;
7
- hostUpdate?(): void;
8
- hostUpdated?(): void;
9
- }
1
+ import { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ export declare abstract class Controller implements ReactiveController {
3
+ protected readonly host: ReactiveControllerHost;
4
+ constructor(host: ReactiveControllerHost);
5
+ hostConnected?(): void;
6
+ hostDisconnected?(): void;
7
+ hostUpdate?(): void;
8
+ hostUpdated?(): void;
9
+ }
@@ -1,6 +1,6 @@
1
- export class Controller {
2
- constructor(host) {
3
- this.host = host;
4
- this.host.addController(this);
5
- }
6
- }
1
+ export class Controller {
2
+ constructor(host) {
3
+ this.host = host;
4
+ this.host.addController(this);
5
+ }
6
+ }
@@ -1 +1 @@
1
- export * from './Controller.js';
1
+ export * from './Controller.js';
@@ -1 +1 @@
1
- export * from './Controller.js';
1
+ export * from './Controller.js';
@@ -1,9 +1,9 @@
1
- declare global {
2
- export type EventHandler<T> = (data: T) => void;
3
- export interface EventDispatcher<T = void> {
4
- dispatch(value: T): void;
5
- subscribe(handler: EventHandler<T>): void;
6
- unsubscribe(handler: EventHandler<T>): void;
7
- }
8
- }
9
- export {};
1
+ declare global {
2
+ export type EventHandler<T> = (data: T) => void;
3
+ export interface EventDispatcher<T = void> {
4
+ dispatch(value: T): void;
5
+ subscribe(handler: EventHandler<T>): void;
6
+ unsubscribe(handler: EventHandler<T>): void;
7
+ }
8
+ }
9
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,12 +1,12 @@
1
- type CustomEventHandler<T> = (event: CustomEvent<T>) => void;
2
- export declare class HTMLElementEventDispatcher<T = void> implements EventDispatcher<T> {
3
- protected readonly element: HTMLElement;
4
- protected readonly type: string;
5
- protected readonly options?: EventInit | undefined;
6
- protected readonly handlersMap: Map<EventHandler<T>, CustomEventHandler<T>>;
7
- constructor(element: HTMLElement, type: string, options?: EventInit | undefined);
8
- dispatch(value: T | CustomEvent<T>): void;
9
- subscribe(handler: EventHandler<T>): void;
10
- unsubscribe(handler: EventHandler<T>): void;
11
- }
12
- export {};
1
+ type CustomEventHandler<T> = (event: CustomEvent<T>) => void;
2
+ export declare class HTMLElementEventDispatcher<T = void> implements EventDispatcher<T> {
3
+ protected readonly element: HTMLElement;
4
+ protected readonly type: string;
5
+ protected readonly options?: EventInit | undefined;
6
+ protected readonly handlersMap: Map<EventHandler<T>, CustomEventHandler<T>>;
7
+ constructor(element: HTMLElement, type: string, options?: EventInit | undefined);
8
+ dispatch(value: T | CustomEvent<T>): void;
9
+ subscribe(handler: EventHandler<T>): void;
10
+ unsubscribe(handler: EventHandler<T>): void;
11
+ }
12
+ export {};
@@ -1,27 +1,27 @@
1
- export class HTMLElementEventDispatcher {
2
- constructor(element, type, options) {
3
- this.element = element;
4
- this.type = type;
5
- this.options = options;
6
- this.handlersMap = new Map();
7
- }
8
- dispatch(value) {
9
- this.element.dispatchEvent(value instanceof CustomEvent
10
- ? value
11
- : new CustomEvent(this.type, { detail: value, ...this.options }));
12
- }
13
- subscribe(handler) {
14
- if (this.handlersMap.has(handler) === false) {
15
- const nativeHandler = (event) => handler(event.detail);
16
- this.element.addEventListener(this.type, nativeHandler);
17
- this.handlersMap.set(handler, nativeHandler);
18
- }
19
- }
20
- unsubscribe(handler) {
21
- const nativeHandler = this.handlersMap.get(handler);
22
- if (nativeHandler) {
23
- this.element.removeEventListener(this.type, nativeHandler);
24
- }
25
- this.handlersMap.delete(handler);
26
- }
27
- }
1
+ export class HTMLElementEventDispatcher {
2
+ constructor(element, type, options) {
3
+ this.element = element;
4
+ this.type = type;
5
+ this.options = options;
6
+ this.handlersMap = new Map();
7
+ }
8
+ dispatch(value) {
9
+ this.element.dispatchEvent(value instanceof CustomEvent
10
+ ? value
11
+ : new CustomEvent(this.type, { detail: value, ...this.options }));
12
+ }
13
+ subscribe(handler) {
14
+ if (this.handlersMap.has(handler) === false) {
15
+ const nativeHandler = (event) => handler(event.detail);
16
+ this.element.addEventListener(this.type, nativeHandler);
17
+ this.handlersMap.set(handler, nativeHandler);
18
+ }
19
+ }
20
+ unsubscribe(handler) {
21
+ const nativeHandler = this.handlersMap.get(handler);
22
+ if (nativeHandler) {
23
+ this.element.removeEventListener(this.type, nativeHandler);
24
+ }
25
+ this.handlersMap.delete(handler);
26
+ }
27
+ }
@@ -1,6 +1,6 @@
1
- export declare class PureEventDispatcher<T = void> implements EventDispatcher<T> {
2
- private readonly handlers;
3
- subscribe(handler: EventHandler<T>): void;
4
- unsubscribe(handler: EventHandler<T>): void;
5
- dispatch(data: T): void;
6
- }
1
+ export declare class PureEventDispatcher<T = void> implements EventDispatcher<T> {
2
+ private readonly handlers;
3
+ subscribe(handler: EventHandler<T>): void;
4
+ unsubscribe(handler: EventHandler<T>): void;
5
+ dispatch(data: T): void;
6
+ }
@@ -1,16 +1,16 @@
1
- export class PureEventDispatcher {
2
- constructor() {
3
- this.handlers = new Set();
4
- }
5
- subscribe(handler) {
6
- this.handlers.add(handler);
7
- }
8
- unsubscribe(handler) {
9
- this.handlers.delete(handler);
10
- }
11
- dispatch(data) {
12
- for (const handler of this.handlers) {
13
- handler(data);
14
- }
15
- }
16
- }
1
+ export class PureEventDispatcher {
2
+ constructor() {
3
+ this.handlers = new Set();
4
+ }
5
+ subscribe(handler) {
6
+ this.handlers.add(handler);
7
+ }
8
+ unsubscribe(handler) {
9
+ this.handlers.delete(handler);
10
+ }
11
+ dispatch(data) {
12
+ for (const handler of this.handlers) {
13
+ handler(data);
14
+ }
15
+ }
16
+ }
@@ -1 +1 @@
1
- export declare function event(options?: EventInit): (prototype: unknown, propertyKey?: string) => void;
1
+ export declare function event(options?: EventInit): (prototype: unknown, propertyKey?: string) => void;
@@ -1,20 +1,20 @@
1
- import { HTMLElementEventDispatcher } from './HTMLElementEventDispatcher.js';
2
- import { PureEventDispatcher } from './PureEventDispatcher.js';
3
- export function event(options) {
4
- return (prototype, propertyKey) => {
5
- if (propertyKey === undefined) {
6
- return;
7
- }
8
- const eventFieldName = `$${propertyKey}Event$`;
9
- Object.defineProperty(prototype, propertyKey, {
10
- get() {
11
- if (!this[eventFieldName]) {
12
- this[eventFieldName] = this instanceof HTMLElement
13
- ? new HTMLElementEventDispatcher(this, propertyKey, options)
14
- : new PureEventDispatcher();
15
- }
16
- return this[eventFieldName];
17
- }
18
- });
19
- };
20
- }
1
+ import { HTMLElementEventDispatcher } from './HTMLElementEventDispatcher.js';
2
+ import { PureEventDispatcher } from './PureEventDispatcher.js';
3
+ export function event(options) {
4
+ return (prototype, propertyKey) => {
5
+ if (propertyKey === undefined) {
6
+ return;
7
+ }
8
+ const eventFieldName = `$${propertyKey}Event$`;
9
+ Object.defineProperty(prototype, propertyKey, {
10
+ get() {
11
+ if (!this[eventFieldName]) {
12
+ this[eventFieldName] = this instanceof HTMLElement
13
+ ? new HTMLElementEventDispatcher(this, propertyKey, options)
14
+ : new PureEventDispatcher();
15
+ }
16
+ return this[eventFieldName];
17
+ }
18
+ });
19
+ };
20
+ }
@@ -1,4 +1,4 @@
1
- import './EventDispatcher.js';
2
- export * from './PureEventDispatcher.js';
3
- export * from './HTMLElementEventDispatcher.js';
4
- export * from './event.js';
1
+ import './EventDispatcher.js';
2
+ export * from './PureEventDispatcher.js';
3
+ export * from './HTMLElementEventDispatcher.js';
4
+ export * from './event.js';
@@ -1,4 +1,4 @@
1
- import './EventDispatcher.js';
2
- export * from './PureEventDispatcher.js';
3
- export * from './HTMLElementEventDispatcher.js';
4
- export * from './event.js';
1
+ import './EventDispatcher.js';
2
+ export * from './PureEventDispatcher.js';
3
+ export * from './HTMLElementEventDispatcher.js';
4
+ export * from './event.js';
@@ -1,23 +1,23 @@
1
- import { ReactiveElement } from 'lit';
2
- import { Controller } from '../Controller/Controller.js';
3
- import type { EventListenerTarget } from './EventListenerTarget.js';
4
- export declare function extractEventTargets(this: any, target: EventListenerTarget | undefined): Promise<EventTarget[]>;
5
- type Listener = EventListenerObject | ((e: any) => void);
6
- type FullEventListenerControllerOptions = {
7
- type: string;
8
- listener: Listener;
9
- target?: EventListenerTarget;
10
- options?: EventListenerOptions | boolean;
11
- };
12
- type ShorthandEventListenerControllerOptions = [type: string, listener: Listener, options?: EventListenerOptions | boolean];
13
- type EventListenerControllerOptions = ShorthandEventListenerControllerOptions | [FullEventListenerControllerOptions];
14
- export declare class EventListenerController extends Controller {
15
- protected readonly host: ReactiveElement;
16
- protected readonly options: FullEventListenerControllerOptions;
17
- constructor(host: ReactiveElement, ...options: EventListenerControllerOptions);
18
- subscribe(): Promise<void>;
19
- unsubscribe(): Promise<void>;
20
- hostDisconnected(): Promise<void>;
21
- hostConnected(): Promise<void>;
22
- }
23
- export {};
1
+ import { ReactiveElement } from 'lit';
2
+ import { Controller } from '../Controller/Controller.js';
3
+ import type { EventListenerTarget } from './EventListenerTarget.js';
4
+ export declare function extractEventTargets(this: any, target: EventListenerTarget | undefined): Promise<EventTarget[]>;
5
+ type Listener = EventListenerObject | ((e: any) => void);
6
+ type FullEventListenerControllerOptions = {
7
+ type: string;
8
+ listener: Listener;
9
+ target?: EventListenerTarget;
10
+ options?: EventListenerOptions | boolean;
11
+ };
12
+ type ShorthandEventListenerControllerOptions = [type: string, listener: Listener, options?: EventListenerOptions | boolean];
13
+ type EventListenerControllerOptions = ShorthandEventListenerControllerOptions | [FullEventListenerControllerOptions];
14
+ export declare class EventListenerController extends Controller {
15
+ protected readonly host: ReactiveElement;
16
+ protected readonly options: FullEventListenerControllerOptions;
17
+ constructor(host: ReactiveElement, ...options: EventListenerControllerOptions);
18
+ subscribe(): Promise<void>;
19
+ unsubscribe(): Promise<void>;
20
+ hostDisconnected(): Promise<void>;
21
+ hostConnected(): Promise<void>;
22
+ }
23
+ export {};
@@ -1,57 +1,57 @@
1
- import { Controller } from '../Controller/Controller.js';
2
- export async function extractEventTargets(target) {
3
- const handle = (value) => {
4
- return Symbol.iterator in value ? [...value] : [value];
5
- };
6
- if (target === undefined) {
7
- return handle(this);
8
- }
9
- if (typeof target === 'function') {
10
- let eventTarget = target.call(this);
11
- if (eventTarget instanceof Promise) {
12
- eventTarget = await eventTarget;
13
- }
14
- if (eventTarget instanceof EventTarget) {
15
- return handle(eventTarget);
16
- }
17
- if (Symbol.iterator in eventTarget && [...eventTarget].every(t => t instanceof EventTarget)) {
18
- return handle(eventTarget);
19
- }
20
- throw new TypeError(`${this.constructor}.target is not an EventTarget`);
21
- }
22
- return handle(target ?? this);
23
- }
24
- function extractOptions(options) {
25
- const short = ((args) => typeof args[0] === 'string')(options);
26
- return {
27
- target: short ? undefined : options[0].target,
28
- type: short ? options[0] : options[0].type,
29
- listener: short ? options[1] : options[0].listener,
30
- options: short ? options[2] : options[0].options,
31
- };
32
- }
33
- export class EventListenerController extends Controller {
34
- constructor(host, ...options) {
35
- super(host);
36
- this.host = host;
37
- this.options = extractOptions(options);
38
- }
39
- async subscribe() {
40
- const targets = await extractEventTargets.call(this.host, this.options.target);
41
- for (const target of targets) {
42
- target.removeEventListener(this.options.type, this.options.listener, this.options.options);
43
- }
44
- }
45
- async unsubscribe() {
46
- const targets = await extractEventTargets.call(this.host, this.options.target);
47
- for (const target of targets) {
48
- target?.addEventListener(this.options.type, this.options.listener, this.options.options);
49
- }
50
- }
51
- async hostDisconnected() {
52
- await this.subscribe();
53
- }
54
- async hostConnected() {
55
- await this.unsubscribe();
56
- }
57
- }
1
+ import { Controller } from '../Controller/Controller.js';
2
+ export async function extractEventTargets(target) {
3
+ const handle = (value) => {
4
+ return Symbol.iterator in value ? [...value] : [value];
5
+ };
6
+ if (target === undefined) {
7
+ return handle(this);
8
+ }
9
+ if (typeof target === 'function') {
10
+ let eventTarget = target.call(this);
11
+ if (eventTarget instanceof Promise) {
12
+ eventTarget = await eventTarget;
13
+ }
14
+ if (eventTarget instanceof EventTarget) {
15
+ return handle(eventTarget);
16
+ }
17
+ if (Symbol.iterator in eventTarget && [...eventTarget].every(t => t instanceof EventTarget)) {
18
+ return handle(eventTarget);
19
+ }
20
+ throw new TypeError(`${this.constructor}.target is not an EventTarget`);
21
+ }
22
+ return handle(target ?? this);
23
+ }
24
+ function extractOptions(options) {
25
+ const short = ((args) => typeof args[0] === 'string')(options);
26
+ return {
27
+ target: short ? undefined : options[0].target,
28
+ type: short ? options[0] : options[0].type,
29
+ listener: short ? options[1] : options[0].listener,
30
+ options: short ? options[2] : options[0].options,
31
+ };
32
+ }
33
+ export class EventListenerController extends Controller {
34
+ constructor(host, ...options) {
35
+ super(host);
36
+ this.host = host;
37
+ this.options = extractOptions(options);
38
+ }
39
+ async subscribe() {
40
+ const targets = await extractEventTargets.call(this.host, this.options.target);
41
+ for (const target of targets) {
42
+ target.removeEventListener(this.options.type, this.options.listener, this.options.options);
43
+ }
44
+ }
45
+ async unsubscribe() {
46
+ const targets = await extractEventTargets.call(this.host, this.options.target);
47
+ for (const target of targets) {
48
+ target?.addEventListener(this.options.type, this.options.listener, this.options.options);
49
+ }
50
+ }
51
+ async hostDisconnected() {
52
+ await this.subscribe();
53
+ }
54
+ async hostConnected() {
55
+ await this.unsubscribe();
56
+ }
57
+ }
@@ -1,3 +1,3 @@
1
- type Targets = EventTarget | Iterable<EventTarget>;
2
- export type EventListenerTarget = Targets | ((this: any) => Targets | Promise<Targets>);
3
- export {};
1
+ type Targets = EventTarget | Iterable<EventTarget>;
2
+ export type EventListenerTarget = Targets | ((this: any) => Targets | Promise<Targets>);
3
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,12 +1,12 @@
1
- import type { ReactiveElement } from 'lit';
2
- import type { EventListenerTarget } from './EventListenerTarget.js';
3
- type ShorthandEventListenerDecoratorOptions = [type: string, options?: EventListenerOptions | boolean];
4
- type FullEventListenerDecoratorOptions = {
5
- type: string;
6
- target?: EventListenerTarget;
7
- options?: EventListenerOptions | boolean;
8
- };
9
- type EventListenerDecoratorOptions = ShorthandEventListenerDecoratorOptions | [FullEventListenerDecoratorOptions];
10
- export declare function extractOptions(args: EventListenerDecoratorOptions): FullEventListenerDecoratorOptions;
11
- export declare const eventListener: (...eventListenerOptions: EventListenerDecoratorOptions) => (prototype: ReactiveElement, propertyKey: string, descriptor?: PropertyDescriptor) => void;
12
- export {};
1
+ import type { ReactiveElement } from 'lit';
2
+ import type { EventListenerTarget } from './EventListenerTarget.js';
3
+ type ShorthandEventListenerDecoratorOptions = [type: string, options?: EventListenerOptions | boolean];
4
+ type FullEventListenerDecoratorOptions = {
5
+ type: string;
6
+ target?: EventListenerTarget;
7
+ options?: EventListenerOptions | boolean;
8
+ };
9
+ type EventListenerDecoratorOptions = ShorthandEventListenerDecoratorOptions | [FullEventListenerDecoratorOptions];
10
+ export declare function extractOptions(args: EventListenerDecoratorOptions): FullEventListenerDecoratorOptions;
11
+ export declare const eventListener: (...eventListenerOptions: EventListenerDecoratorOptions) => (prototype: ReactiveElement, propertyKey: string, descriptor?: PropertyDescriptor) => void;
12
+ export {};