mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-26 22:29:28 +09:00
better types
This commit is contained in:
parent
2968e1be4b
commit
774b46be94
@ -11,10 +11,18 @@ export const postMessageEventTypes = [
|
|||||||
|
|
||||||
export type PostMessageEventType = typeof postMessageEventTypes[number];
|
export type PostMessageEventType = typeof postMessageEventTypes[number];
|
||||||
|
|
||||||
export type MiPostMessageEvent = {
|
export interface PostMessageEventPayload extends Record<PostMessageEventType, any> {
|
||||||
type: PostMessageEventType;
|
'misskey:shareForm:shareCompleted': undefined;
|
||||||
|
'misskey:embed:ready': undefined;
|
||||||
|
'misskey:embed:changeHeight': {
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MiPostMessageEvent<T extends PostMessageEventType = PostMessageEventType> = {
|
||||||
|
type: T;
|
||||||
iframeId?: string;
|
iframeId?: string;
|
||||||
payload?: any;
|
payload?: PostMessageEventPayload[T];
|
||||||
};
|
};
|
||||||
|
|
||||||
let defaultIframeId: string | null = null;
|
let defaultIframeId: string | null = null;
|
||||||
@ -27,7 +35,7 @@ export function setIframeId(id: string): void {
|
|||||||
/**
|
/**
|
||||||
* 親フレームにイベントを送信
|
* 親フレームにイベントを送信
|
||||||
*/
|
*/
|
||||||
export function postMessageToParentWindow(type: PostMessageEventType, payload?: any, iframeId: string | null = null): void {
|
export function postMessageToParentWindow<T extends PostMessageEventType = PostMessageEventType>(type: T, payload?: PostMessageEventPayload[T], iframeId: string | null = null): void {
|
||||||
let _iframeId = iframeId;
|
let _iframeId = iframeId;
|
||||||
if (_iframeId == null) {
|
if (_iframeId == null) {
|
||||||
_iframeId = defaultIframeId;
|
_iframeId = defaultIframeId;
|
||||||
|
Loading…
Reference in New Issue
Block a user