@@ -11,17 +11,54 @@ export type CustomElement = HTMLElement & {
1111 connectedCallback ?( ) : void ;
1212 disconnectedCallback ?( ) : void ;
1313 elements ?: { [ k : string ] : HTMLElement } ;
14- [ StateSymbol ] : State ;
14+ state : Partial < State > ;
1515} ;
16- export type Constructor < E extends CustomElement > = {
16+ export type Constructor < E extends CustomElement = CustomElement > = {
1717 new ( ) : E ;
1818} & { observedAttributes : Array < string > } ;
19- export type HOF < E extends CustomElement , S extends State > = (
19+ export type HOF < S extends State , E extends CustomElement = CustomElement > = (
2020 factorize : (
2121 f : ( Component : Constructor < E > , render : ( e : E , s : S ) => void ) => void ,
2222 ) => void ,
23- construct ? : ( f : ( e : E ) => void ) => void ,
23+ construct : ( f : ( e : E ) => void ) => void ,
2424) => void ;
25+ export type AsyncRenderCallback <
26+ S extends State ,
27+ E extends CustomElement = CustomElement ,
28+ > = ( $e : E , s : S , e : Event ) => S | undefined ;
29+ export type AsyncRender <
30+ S extends State ,
31+ E extends CustomElement = CustomElement ,
32+ > = (
33+ f : AsyncRenderCallback < S , E > ,
34+ ) => ( e : Event ) => void ;
35+ export type Render < S extends State , E extends CustomElement = CustomElement > = (
36+ element : E ,
37+ state : S ,
38+ ) => void ;
39+ export type AttributeCallback <
40+ S extends State ,
41+ E extends CustomElement = CustomElement ,
42+ > = < X extends ValueOf < S > > (
43+ attributes : { name : keyof S ; oldValue : X ; value : X } ,
44+ element ?: E ,
45+ state ?: S ,
46+ ) => Partial < S > | boolean ;
47+ export type LifeCycleCallback <
48+ S extends State ,
49+ E extends CustomElement = CustomElement ,
50+ > =
51+ | ( (
52+ element : E ,
53+ render : AsyncRender < S , E > ,
54+ ) => void )
55+ | ( (
56+ element : E ,
57+ render : AsyncRender < S , E > ,
58+ name : string ,
59+ oldValue : string ,
60+ value : string ,
61+ ) => S | void ) ;
2562
2663export declare enum Callbacks {
2764 "adoptedCallback" ,
@@ -33,45 +70,42 @@ export declare enum Callbacks {
3370type ValueOf < T > = T [ keyof T ] ;
3471
3572export function factorizeComponent <
36- E extends CustomElement = CustomElement ,
3773 S extends State ,
74+ E extends CustomElement = CustomElement ,
3875> (
39- render : ( element : E , state : S ) => void ,
76+ render : Render < S , E > ,
4077 state : S ,
41- ...fs : Array < HOF < E , S > >
78+ ...fs : Array < HOF < S , E > >
4279) : Constructor < E > ;
4380
44- export function useAttributes < E extends CustomElement , S extends State > (
45- validateAttribute : < X extends ValueOf < S > > (
46- attributes : { name : keyof S ; oldValue : X ; value : X } ,
47- element ?: E ,
48- state ?: S ,
49- ) => Partial < S > | boolean ,
81+ export function useAttributes <
82+ S extends State ,
83+ E extends CustomElement = CustomElement ,
84+ > (
85+ validateAttribute : AttributeCallback < S , E > ,
5086 map ?: { [ K in keyof S ] : ( x : string ) => S [ K ] } ,
51- ) : HOF < E , S > ;
87+ ) : HOF < S , E > ;
5288
53- export function useCallbacks < E extends CustomElement , S extends State > (
89+ export function useCallbacks <
90+ S extends State ,
91+ E extends CustomElement = CustomElement ,
92+ > (
5493 callbacks : {
55- [ K in keyof typeof Callbacks ] ?:
56- | ( (
57- element : E ,
58- render : ( $e : E , s : State , e : Event ) => void ,
59- ) => void )
60- | ( (
61- element : E ,
62- name : string ,
63- oldValue : string ,
64- value : string ,
65- render : ( $e : E , s : State , e : Event ) => void ,
66- ) => void ) ;
94+ [ K in keyof typeof Callbacks ] ?: LifeCycleCallback < S , E > ;
6795 } ,
68- ) : HOF < E , S > ;
96+ ) : HOF < S , E > ;
6997
70- export function useShadow < E extends CustomElement , S extends State > (
98+ export function useShadow <
99+ S extends State ,
100+ E extends CustomElement = CustomElement ,
101+ > (
71102 options ?: { mode : "open" | "closed" } ,
72- ) : HOF < E , S > ;
103+ ) : HOF < S , E > ;
73104
74- export function useTemplate < E extends CustomElement , S extends State > (
105+ export function useTemplate <
106+ S extends State ,
107+ E extends CustomElement = CustomElement ,
108+ > (
75109 getTemplate : ( ) => HTMLTemplateElement ,
76110 map ?: { [ k : string ] : ( e : E ) => CustomElement } ,
77- ) : HOF < E , S > ;
111+ ) : HOF < S , E > ;
0 commit comments