refactor(editor): Fix NodeView/Canvas related TS errors (#9581)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
import type { ElMessageBoxOptions } from 'element-plus';
|
||||
import type { ElMessageBoxOptions, Action, MessageBoxInputData } from 'element-plus';
|
||||
import { ElMessageBox as MessageBox } from 'element-plus';
|
||||
|
||||
export type MessageBoxConfirmResult = 'confirm' | 'cancel';
|
||||
|
||||
export function useMessage() {
|
||||
const handleCancelOrClose = (e: unknown) => {
|
||||
const handleCancelOrClose = (e: Action | Error): Action => {
|
||||
if (e instanceof Error) throw e;
|
||||
else return e;
|
||||
|
||||
return e;
|
||||
};
|
||||
|
||||
const handleCancelOrClosePrompt = (e: Error | Action): MessageBoxInputData => {
|
||||
if (e instanceof Error) throw e;
|
||||
|
||||
return { value: '', action: e };
|
||||
};
|
||||
|
||||
async function alert(
|
||||
@@ -15,7 +22,7 @@ export function useMessage() {
|
||||
config?: ElMessageBoxOptions,
|
||||
) {
|
||||
const resolvedConfig = {
|
||||
...(config || (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
...(config ?? (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
cancelButtonClass: 'btn--cancel',
|
||||
confirmButtonClass: 'btn--confirm',
|
||||
};
|
||||
@@ -32,24 +39,23 @@ export function useMessage() {
|
||||
message: ElMessageBoxOptions['message'],
|
||||
configOrTitle?: string | ElMessageBoxOptions,
|
||||
config?: ElMessageBoxOptions,
|
||||
): Promise<MessageBoxConfirmResult> {
|
||||
) {
|
||||
const resolvedConfig = {
|
||||
...(config || (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
...(config ?? (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
cancelButtonClass: 'btn--cancel',
|
||||
confirmButtonClass: 'btn--confirm',
|
||||
distinguishCancelAndClose: true,
|
||||
showClose: config?.showClose || false,
|
||||
showClose: config?.showClose ?? false,
|
||||
closeOnClickModal: false,
|
||||
};
|
||||
|
||||
if (typeof configOrTitle === 'string') {
|
||||
return await (MessageBox.confirm(message, configOrTitle, resolvedConfig).catch(
|
||||
return await MessageBox.confirm(message, configOrTitle, resolvedConfig).catch(
|
||||
handleCancelOrClose,
|
||||
) as unknown as Promise<MessageBoxConfirmResult>);
|
||||
);
|
||||
}
|
||||
return await (MessageBox.confirm(message, resolvedConfig).catch(
|
||||
handleCancelOrClose,
|
||||
) as unknown as Promise<MessageBoxConfirmResult>);
|
||||
|
||||
return await MessageBox.confirm(message, resolvedConfig).catch(handleCancelOrClose);
|
||||
}
|
||||
|
||||
async function prompt(
|
||||
@@ -58,17 +64,17 @@ export function useMessage() {
|
||||
config?: ElMessageBoxOptions,
|
||||
) {
|
||||
const resolvedConfig = {
|
||||
...(config || (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
...(config ?? (typeof configOrTitle === 'object' ? configOrTitle : {})),
|
||||
cancelButtonClass: 'btn--cancel',
|
||||
confirmButtonClass: 'btn--confirm',
|
||||
};
|
||||
|
||||
if (typeof configOrTitle === 'string') {
|
||||
return await MessageBox.prompt(message, configOrTitle, resolvedConfig).catch(
|
||||
handleCancelOrClose,
|
||||
handleCancelOrClosePrompt,
|
||||
);
|
||||
}
|
||||
return await MessageBox.prompt(message, resolvedConfig).catch(handleCancelOrClose);
|
||||
return await MessageBox.prompt(message, resolvedConfig).catch(handleCancelOrClosePrompt);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user