vue3-promise-dialog
Version:
Dialogs meet promises in Vue 3 !
48 lines (47 loc) • 1.99 kB
TypeScript
import { Component } from "vue";
import { DefineComponent } from "@vue/runtime-core";
export interface DialogInstance {
comp?: any;
dialog: Component;
wrapper: string;
props: any;
resolve: (data: any) => void;
}
export declare const dialogRef: import("vue").ShallowRef<DialogInstance>;
/**
* Closes the currently opened dialog, resolving the promise with the return value of the dialog, or with the given
* data if any.
*/
export declare function closeDialog(data?: any): void;
/**
* Extracts the type of props from a component definition.
*/
declare type PropsType<C extends DefineComponent<any, any, any>> = InstanceType<C>["$props"];
/**
* Extracts the return type of the dialog from the setup function.
*/
declare type BindingReturnType<C extends DefineComponent<any, any, any>> = C extends DefineComponent<any, infer X, any> ? (X extends {
returnValue: () => infer Y;
} ? Y : never) : never;
/**
* Extracts the return type of the dialog from the methods.
*/
declare type MethodReturnType<C extends DefineComponent<any, any, any, any, any>> = C extends DefineComponent<any, any, any, any, infer X> ? (X extends {
returnValue: () => infer Y;
} ? Y : never) : never;
/**
* Extracts the return type of the dialog either from the setup method or from the methods.
*/
declare type ReturnType<C extends DefineComponent<any, any, any, any, any>> = BindingReturnType<C> extends never ? MethodReturnType<C> : BindingReturnType<C>;
/**
* Opens a dialog.
* @param dialog The dialog you want to open.
* @param props The props to be passed to the dialog.
* @param wrapper The dialog wrapper you want the dialog to open into.
* @return A promise that resolves when the dialog is closed
*/
export declare function openDialog<C extends DefineComponent<any, any, any, any, any>>(dialog: C, props?: PropsType<C>, wrapper?: string): Promise<ReturnType<C>>;
export declare const PromiseDialog: {
install: (app: any, options: any) => void;
};
export {};