From 0df069494e70eafa7217b79d133bb248865baa85 Mon Sep 17 00:00:00 2001 From: zyoshoka <107108195+zyoshoka@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:02:30 +0900 Subject: [PATCH] =?UTF-8?q?refactor(frontend):=20`os.popup()`=E3=81=AE`eve?= =?UTF-8?q?nts`=E3=81=AE=E5=9E=8B=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=92=E6=9C=89=E5=8A=B9=E5=8C=96=20(#13165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/os.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 7cce77cdf7..010fdbb6d8 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -128,9 +128,10 @@ export function promiseDialog>( let popupIdCount = 0; export const popups = ref([]) as Ref<{ - id: any; - component: any; + id: number; + component: Component; props: Record; + events: Record; }[]>; const zIndexes = { @@ -144,7 +145,18 @@ export function claimZIndex(priority: keyof typeof zIndexes = 'low'): number { return zIndexes[priority]; } -export async function popup(component: T, props: ComponentProps, events = {}, disposeEvent?: string) { +// InstanceType['$emit'] だとインターセクション型が返ってきて +// 使い物にならないので、代わりに ['$props'] から色々省くことで emit の型を生成する +// FIXME: 何故か *.ts ファイルからだと型がうまく取れない?ことがあるのをなんとかしたい +type ComponentEmit = T extends new () => { $props: infer Props } + ? EmitsExtractor + : never; + +type EmitsExtractor = { + [K in keyof T as K extends `onVnode${string}` ? never : K extends `on${infer E}` ? Uncapitalize : K extends string ? never : K]: T[K]; +}; + +export async function popup(component: T, props: ComponentProps, events: ComponentEmit = {} as ComponentEmit, disposeEvent?: keyof ComponentEmit) { markRaw(component); const id = ++popupIdCount;