@esportsplus/template 0.40.3 → 0.41.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,10 +1,10 @@
1
- import { Element } from '../types.js';
1
+ import { Attributes, Element } from '../types.js';
2
2
  import onconnect from './onconnect.js';
3
3
  import onresize from './onresize.js';
4
4
  import ontick from './ontick.js';
5
- declare const delegate: (element: Element, event: string, listener: Function) => void;
6
- declare const on: (element: Element, event: string, listener: Function) => void;
7
- declare const ondisconnect: (element: Element, listener: Function) => void;
8
- declare const onrender: (element: Element, listener: Function) => void;
9
- declare const runtime: (element: Element, event: `on${string}`, listener: Function) => void;
5
+ declare const delegate: <E extends string>(element: Element, event: E, listener: Attributes[`on${E}`]) => void;
6
+ declare const on: <E extends string>(element: Element, event: E, listener: Attributes[`on${E}`]) => void;
7
+ declare const ondisconnect: (element: Element, listener: NonNullable<Attributes[`ondisconnect`]>) => void;
8
+ declare const onrender: (element: Element, listener: NonNullable<Attributes[`onrender`]>) => void;
9
+ declare const runtime: <E extends `on${string}`>(element: Element, event: E, listener: Attributes[E]) => void;
10
10
  export { delegate, on, onconnect, ondisconnect, onrender, onresize, ontick, runtime };
@@ -1,3 +1,3 @@
1
- import { Element } from '../types.js';
2
- declare const _default: (element: Element, listener: Function) => void;
1
+ import { Attributes, Element } from '../types.js';
2
+ declare const _default: (element: Element, listener: NonNullable<Attributes["onconnect"]>) => void;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import { Element } from '../types.js';
2
- declare const _default: (element: Element, listener: Function) => void;
1
+ import { Attributes, Element } from '../types.js';
2
+ declare const _default: (element: Element, listener: NonNullable<Attributes["onresize"]>) => void;
3
3
  export default _default;
@@ -1,6 +1,6 @@
1
- import { Element } from '../types.js';
1
+ import { Attributes, Element } from '../types.js';
2
2
  declare const add: (task: VoidFunction) => void;
3
3
  declare const remove: (task: VoidFunction) => void;
4
- declare const _default: (element: Element, listener: Function) => void;
4
+ declare const _default: (element: Element, listener: NonNullable<Attributes["ontick"]>) => void;
5
5
  export default _default;
6
6
  export { add, remove };
package/build/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
+ export * from '@esportsplus/reactivity';
2
+ export * from './attributes.js';
3
+ export * from './event/index.js';
4
+ export * from './utilities.js';
1
5
  export { default as html } from './html.js';
2
6
  export { default as render } from './render.js';
3
7
  export { default as svg } from './svg.js';
4
- export * from './attributes.js';
5
- export * from './event/index.js';
6
8
  export { ArraySlot } from './slot/array.js';
7
9
  export { EffectSlot } from './slot/effect.js';
8
10
  export { default as slot } from './slot/index.js';
9
11
  export type { Attributes, Element, Renderable } from './types.js';
10
- export * from './utilities.js';
package/build/index.js CHANGED
@@ -3,12 +3,13 @@ if (typeof Node !== 'undefined') {
3
3
  Node.prototype[CLEANUP] = null;
4
4
  Node.prototype[STORE] = null;
5
5
  }
6
+ export * from '@esportsplus/reactivity';
7
+ export * from './attributes.js';
8
+ export * from './event/index.js';
9
+ export * from './utilities.js';
6
10
  export { default as html } from './html.js';
7
11
  export { default as render } from './render.js';
8
12
  export { default as svg } from './svg.js';
9
- export * from './attributes.js';
10
- export * from './event/index.js';
11
13
  export { ArraySlot } from './slot/array.js';
12
14
  export { EffectSlot } from './slot/effect.js';
13
15
  export { default as slot } from './slot/index.js';
14
- export * from './utilities.js';
package/package.json CHANGED
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "type": "module",
41
41
  "types": "./build/index.d.ts",
42
- "version": "0.40.3",
42
+ "version": "0.41.0",
43
43
  "scripts": {
44
44
  "build": "tsc",
45
45
  "build:test": "vite build --config test/vite.config.ts",
@@ -1,6 +1,6 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { defineProperty } from '@esportsplus/utilities';
3
- import { Element } from '~/types';
3
+ import { Attributes, Element } from '~/types';
4
4
  import { ondisconnect as disconnect } from '~/slot/cleanup';
5
5
  import onconnect from './onconnect';
6
6
  import onresize from './onresize';
@@ -88,13 +88,13 @@ function register(element: Element, event: string) {
88
88
  }
89
89
 
90
90
 
91
- const delegate = (element: Element, event: string, listener: Function): void => {
91
+ const delegate = <E extends string>(element: Element, event: E, listener: Attributes[`on${E}`]): void => {
92
92
  element[ keys[event] || register(element, event) ] = listener;
93
93
  };
94
94
 
95
95
  // DIRECT_ATTACH_EVENTS in ./constants.ts tells compiler to use this function
96
- const on = (element: Element, event: string, listener: Function): void => {
97
- let handler = (e: Event) => listener.call(element, e);
96
+ const on = <E extends string>(element: Element, event: E, listener: Attributes[`on${E}`]): void => {
97
+ let handler = (e: Event) => (listener as Function).call(element, e);
98
98
 
99
99
  element.addEventListener(event, handler, {
100
100
  passive: passive.has(event)
@@ -105,31 +105,31 @@ const on = (element: Element, event: string, listener: Function): void => {
105
105
  });
106
106
  };
107
107
 
108
- const ondisconnect = (element: Element, listener: Function) => {
108
+ const ondisconnect = (element: Element, listener: NonNullable<Attributes[`ondisconnect`]>) => {
109
109
  disconnect(element, () => listener(element));
110
110
  };
111
111
 
112
- const onrender = (element: Element, listener: Function) => {
112
+ const onrender = (element: Element, listener: NonNullable<Attributes[`onrender`]>) => {
113
113
  root(() => listener(element));
114
114
  };
115
115
 
116
116
  const lifecycle = { onconnect, ondisconnect, onrender, onresize, ontick };
117
117
 
118
- const runtime = (element: Element, event: `on${string}`, listener: Function): void => {
118
+ const runtime = <E extends `on${string}`>(element: Element, event: E, listener: Attributes[E]): void => {
119
119
  let key = event.toLowerCase();
120
120
 
121
121
  if (LIFECYCLE_EVENTS.has(key)) {
122
- lifecycle[key as keyof typeof lifecycle](element, listener);
122
+ lifecycle[key as keyof typeof lifecycle](element, listener as any);
123
123
  return;
124
124
  }
125
125
 
126
126
  let e = event.slice(2).toLowerCase();
127
127
 
128
128
  if (DIRECT_ATTACH_EVENTS.has(key)) {
129
- on(element, e, listener);
129
+ on(element, e, listener as Attributes[`on${typeof e}`]);
130
130
  }
131
131
  else {
132
- delegate(element, e, listener);
132
+ delegate(element, e, listener as Attributes[`on${typeof e}`]);
133
133
  }
134
134
  };
135
135
 
@@ -1,9 +1,9 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { add, remove } from './ontick';
3
- import { Element } from '~/types';
3
+ import { Attributes, Element } from '~/types';
4
4
 
5
5
 
6
- export default (element: Element, listener: Function) => {
6
+ export default (element: Element, listener: NonNullable<Attributes['onconnect']>) => {
7
7
  let fn = () => {
8
8
  retry--;
9
9
 
@@ -1,5 +1,5 @@
1
1
  import { onCleanup } from '@esportsplus/reactivity';
2
- import { Element } from '~/types';
2
+ import { Attributes, Element } from '~/types';
3
3
 
4
4
 
5
5
  let listeners = new Map<Element, Function>(),
@@ -23,7 +23,7 @@ function onresize() {
23
23
  }
24
24
 
25
25
 
26
- export default (element: Element, listener: Function) => {
26
+ export default (element: Element, listener: NonNullable<Attributes['onresize']>) => {
27
27
  listeners.set(element, listener);
28
28
 
29
29
  onCleanup(() => {
@@ -1,4 +1,4 @@
1
- import { Element } from '~/types';
1
+ import { Attributes, Element } from '~/types';
2
2
  import { raf } from '~/utilities';
3
3
 
4
4
 
@@ -33,7 +33,7 @@ const remove = (task: VoidFunction) => {
33
33
  };
34
34
 
35
35
 
36
- export default (element: Element, listener: Function) => {
36
+ export default (element: Element, listener: NonNullable<Attributes['ontick']>) => {
37
37
  let connected = false,
38
38
  fn = () => {
39
39
  if (connected === false) {
package/src/index.ts CHANGED
@@ -8,13 +8,16 @@ if (typeof Node !== 'undefined') {
8
8
  }
9
9
 
10
10
 
11
+ export * from '@esportsplus/reactivity';
12
+
13
+ export * from './attributes';
14
+ export * from './event';
15
+ export * from './utilities';
16
+
11
17
  export { default as html } from './html';
12
18
  export { default as render } from './render';
13
19
  export { default as svg } from './svg';
14
- export * from './attributes';
15
- export * from './event';
16
20
  export { ArraySlot } from './slot/array';
17
21
  export { EffectSlot } from './slot/effect';
18
22
  export { default as slot } from './slot';
19
- export type { Attributes, Element, Renderable } from './types';
20
- export * from './utilities';
23
+ export type { Attributes, Element, Renderable } from './types';