44// #region Interfaces
55export interface ConnectPanelChannelOptions < Protocol extends InPageChannelProtocol = InPageChannelProtocol > extends InPageChannelCommonOptions {
66 functions : ConnectPanelChannelOptionsFunctions < Protocol > ;
7- events : { [ NAME in keyof PanelProtocolEvents < Protocol > & string ] : InPageEventOption < PanelProtocolEvents < Protocol > [ NAME ] > ; } ;
7+ events ? : { [ NAME in keyof PanelProtocolEvents < Protocol > & string ] ? : InPageEventOption < PanelProtocolEvents < Protocol > [ NAME ] > ; } ;
88 window ?: Window | false ;
99 targets ?: Window [ ] ;
1010 transport ?: MessagePort ;
@@ -14,7 +14,7 @@ export interface ConnectPanelChannelOptions<Protocol extends InPageChannelProtoc
1414}
1515export interface CreatePageScriptChannelOptions < Protocol extends InPageChannelProtocol = InPageChannelProtocol > extends InPageChannelCommonOptions {
1616 functions : CreatePageScriptChannelOptionsFunctions < Protocol > ;
17- events : { [ NAME in keyof PageScriptProtocolEvents < Protocol > & string ] : InPageEventOption < PageScriptProtocolEvents < Protocol > [ NAME ] > ; } ;
17+ events ? : { [ NAME in keyof PageScriptProtocolEvents < Protocol > & string ] ? : InPageEventOption < PageScriptProtocolEvents < Protocol > [ NAME ] > ; } ;
1818 window ?: Window | false ;
1919}
2020export interface InPageChannelProtocol {
@@ -33,9 +33,9 @@ export interface PageScriptChannel<P extends InPageChannelProtocol> {
3333 readonly instanceId : string ;
3434 readonly panels : readonly PanelPeer < P > [ ] ;
3535 readonly events : Pick < EventEmitter < PageScriptChannelEvents < P > > , 'on' | 'once' > ;
36- emit : < K extends FunctionNames < PanelProtocolEvents < P > > > ( _ : K , ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ;
37- callEvent : < K extends FunctionNames < PanelProtocolEvents < P > > > ( _ : K , ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ;
38- on : < K extends FunctionNames < PageScriptProtocolEvents < P > > > ( _ : K , _ : ( ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ) => ( ) => void ;
36+ emit : < K extends keyof PanelProtocolEvents < P > & string > ( _ : K , ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ;
37+ callEvent : < K extends keyof PanelProtocolEvents < P > & string > ( _ : K , ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ;
38+ on : < K extends keyof PageScriptProtocolEvents < P > & string > ( _ : K , _ : ( ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ) => ( ) => void ;
3939 readonly sharedState : InPageSharedStateHost < P > ;
4040 addPanelPort : ( _ : MessagePort ) => PanelPeer < P > ;
4141 close : ( ) => void ;
@@ -48,16 +48,16 @@ export interface PanelChannel<P extends InPageChannelProtocol> {
4848 } | undefined ;
4949 readonly events : Pick < EventEmitter < PanelChannelEvents > , 'on' | 'once' > ;
5050 whenConnected : ( _ ?: number ) => Promise < void > ;
51- call : < K extends FunctionNames < PageScriptFunctions < P > > > ( _ : K , ..._ : FnArgs < PageScriptFunctions < P > [ K ] > ) => Promise < FnReturn < PageScriptFunctions < P > [ K ] > > ;
52- emit : < K extends FunctionNames < PageScriptProtocolEvents < P > > > ( _ : K , ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ;
53- callEvent : < K extends FunctionNames < PageScriptProtocolEvents < P > > > ( _ : K , ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ;
54- on : < K extends FunctionNames < PanelProtocolEvents < P > > > ( _ : K , _ : ( ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ) => ( ) => void ;
51+ call : < K extends keyof PageScriptFunctions < P > & string > ( _ : K , ..._ : FnArgs < PageScriptFunctions < P > [ K ] > ) => Promise < FnReturn < PageScriptFunctions < P > [ K ] > > ;
52+ emit : < K extends keyof PageScriptProtocolEvents < P > & string > ( _ : K , ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ;
53+ callEvent : < K extends keyof PageScriptProtocolEvents < P > & string > ( _ : K , ..._ : FnArgs < PageScriptProtocolEvents < P > [ K ] > ) => void ;
54+ on : < K extends keyof PanelProtocolEvents < P > & string > ( _ : K , _ : ( ..._ : FnArgs < PanelProtocolEvents < P > [ K ] > ) => void ) => ( ) => void ;
5555 readonly sharedState : InPageSharedStateHost < P > ;
5656 close : ( ) => void ;
5757}
5858export interface PanelPeer < P extends InPageChannelProtocol > {
5959 readonly id : string ;
60- call : < K extends FunctionNames < PanelFunctions < P > > > ( _ : K , ..._ : FnArgs < PanelFunctions < P > [ K ] > ) => Promise < FnReturn < PanelFunctions < P > [ K ] > > ;
60+ call : < K extends keyof PanelFunctions < P > & string > ( _ : K , ..._ : FnArgs < PanelFunctions < P > [ K ] > ) => Promise < FnReturn < PanelFunctions < P > [ K ] > > ;
6161 close : ( ) => void ;
6262}
6363// #endregion
@@ -94,7 +94,6 @@ type ConnectPanelChannelOptionsFunctions<P extends InPageChannelProtocol> = { [N
9494type CreatePageScriptChannelOptionsFunctions < P extends InPageChannelProtocol > = { [ NAME in keyof PageScriptFunctions < P > & string ] : InPageFunctionOption < PageScriptFunctions < P > [ NAME ] > ; } ;
9595type FnArgs < F > = F extends ( ( ...args : infer A ) => any ) ? A : never ;
9696type FnReturn < F > = F extends ( ( ...args : any [ ] ) => infer R ) ? Awaited < R > : never ;
97- type FunctionNames < T > = { [ K in keyof T ] : [ T [ K ] ] extends [ never ] ? never : K ; } [ keyof T ] & string ;
9897interface InPageChannelCommonOptions {
9998 name : string ;
10099 allowedOrigins ?: string [ ] ;
0 commit comments