This commit is contained in:
syuilo
2020-11-03 15:22:55 +09:00
parent 5ef4a52bbd
commit c3ae6f3a4a
25 changed files with 73 additions and 62 deletions

View File

@ -147,7 +147,9 @@ export const popups = ref([]) as Ref<{
props: Record<string, any>;
}[]>;
export function popup(component: Component | typeof import('*.vue'), props: Record<string, any>, events = {}, disposeEvent?: string) {
export async function popup(component: Component | typeof import('*.vue') | Promise<Component | typeof import('*.vue')>, props: Record<string, any>, events = {}, disposeEvent?: string) {
if (component.then) component = await component;
if (isModule(component)) component = component.default;
markRaw(component);
@ -179,7 +181,7 @@ export function popup(component: Component | typeof import('*.vue'), props: Reco
export function pageWindow(path: string) {
const { component, props } = resolve(path);
popup(defineAsyncComponent(() => import('@/components/page-window.vue')), {
popup(import('@/components/page-window.vue'), {
initialPath: path,
initialComponent: markRaw(component),
initialProps: props,
@ -188,7 +190,7 @@ export function pageWindow(path: string) {
export function dialog(props: Record<string, any>) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/dialog.vue')), props, {
popup(import('@/components/dialog.vue'), props, {
done: result => {
resolve(result ? result : { canceled: true });
},
@ -202,7 +204,7 @@ export function success() {
setTimeout(() => {
showing.value = false;
}, 1000);
popup(defineAsyncComponent(() => import('@/components/waiting-dialog.vue')), {
popup(import('@/components/waiting-dialog.vue'), {
success: true,
showing: showing
}, {
@ -214,7 +216,7 @@ export function success() {
export function waiting() {
return new Promise((resolve, reject) => {
const showing = ref(true);
popup(defineAsyncComponent(() => import('@/components/waiting-dialog.vue')), {
popup(import('@/components/waiting-dialog.vue'), {
success: false,
showing: showing
}, {
@ -225,7 +227,7 @@ export function waiting() {
export function form(title, form) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/form-dialog.vue')), { title, form }, {
popup(import('@/components/form-dialog.vue'), { title, form }, {
done: result => {
resolve(result);
},
@ -235,7 +237,7 @@ export function form(title, form) {
export async function selectUser() {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/user-select-dialog.vue')), {}, {
popup(import('@/components/user-select-dialog.vue'), {}, {
ok: user => {
resolve(user);
},
@ -245,7 +247,7 @@ export async function selectUser() {
export async function selectDriveFile(multiple: boolean) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/drive-select-dialog.vue')), {
popup(import('@/components/drive-select-dialog.vue'), {
type: 'file',
multiple
}, {
@ -260,7 +262,7 @@ export async function selectDriveFile(multiple: boolean) {
export async function selectDriveFolder(multiple: boolean) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/drive-select-dialog.vue')), {
popup(import('@/components/drive-select-dialog.vue'), {
type: 'folder',
multiple
}, {
@ -275,7 +277,7 @@ export async function selectDriveFolder(multiple: boolean) {
export async function pickEmoji(src?: HTMLElement) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/emoji-picker.vue')), {
popup(import('@/components/emoji-picker.vue'), {
src
}, {
done: emoji => {
@ -287,7 +289,8 @@ export async function pickEmoji(src?: HTMLElement) {
export function modalMenu(items: any[], src?: HTMLElement, options?: { align?: string; viaKeyboard?: boolean }) {
return new Promise((resolve, reject) => {
const { dispose } = popup(defineAsyncComponent(() => import('@/components/ui/modal-menu.vue')), {
let dispose;
popup(import('@/components/ui/modal-menu.vue'), {
items,
src,
align: options?.align,
@ -297,6 +300,8 @@ export function modalMenu(items: any[], src?: HTMLElement, options?: { align?: s
resolve();
dispose();
},
}).then(_dispose => {
dispose = _dispose;
});
});
}
@ -304,7 +309,8 @@ export function modalMenu(items: any[], src?: HTMLElement, options?: { align?: s
export function contextMenu(items: any[], ev: MouseEvent) {
ev.preventDefault();
return new Promise((resolve, reject) => {
const { dispose } = popup(defineAsyncComponent(() => import('@/components/ui/context-menu.vue')), {
let dispose;
popup(import('@/components/ui/context-menu.vue'), {
items,
ev,
}, {
@ -312,6 +318,8 @@ export function contextMenu(items: any[], ev: MouseEvent) {
resolve();
dispose();
},
}).then(_dispose => {
dispose = _dispose;
});
});
}
@ -323,11 +331,14 @@ export function post(props: Record<string, any>) {
// Vueが渡されたコンポーネントに内部的に__propsというプロパティを生やす影響で、
// 複数のpost formを開いたときに場合によってはエラーになる
// もちろん複数のpost formを開けること自体Misskeyサイドのバグなのだが
const { dispose } = popup(MkPostFormDialog, props, {
let dispose;
popup(MkPostFormDialog, props, {
closed: () => {
resolve();
dispose();
},
}).then(_dispose => {
dispose = _dispose;
});
});
}