|
|
@ -5,6 +5,7 @@ import type { ButtonProps } from '../button';
|
|
|
|
import type { LegacyButtonType } from '../button/buttonTypes';
|
|
|
|
import type { LegacyButtonType } from '../button/buttonTypes';
|
|
|
|
import { convertLegacyProps } from '../button/buttonTypes';
|
|
|
|
import { convertLegacyProps } from '../button/buttonTypes';
|
|
|
|
import useDestroyed from './hooks/useDestroyed';
|
|
|
|
import useDestroyed from './hooks/useDestroyed';
|
|
|
|
|
|
|
|
import { objectType } from './type';
|
|
|
|
|
|
|
|
|
|
|
|
const actionButtonProps = {
|
|
|
|
const actionButtonProps = {
|
|
|
|
type: {
|
|
|
|
type: {
|
|
|
@ -14,15 +15,15 @@ const actionButtonProps = {
|
|
|
|
close: Function,
|
|
|
|
close: Function,
|
|
|
|
autofocus: Boolean,
|
|
|
|
autofocus: Boolean,
|
|
|
|
prefixCls: String,
|
|
|
|
prefixCls: String,
|
|
|
|
buttonProps: Object as PropType<ButtonProps>,
|
|
|
|
buttonProps: objectType<ButtonProps>(),
|
|
|
|
emitEvent: Boolean,
|
|
|
|
emitEvent: Boolean,
|
|
|
|
quitOnNullishReturnValue: Boolean,
|
|
|
|
quitOnNullishReturnValue: Boolean,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type ActionButtonProps = ExtractPropTypes<typeof actionButtonProps>;
|
|
|
|
export type ActionButtonProps = ExtractPropTypes<typeof actionButtonProps>;
|
|
|
|
|
|
|
|
|
|
|
|
function isThenable(thing?: PromiseLike<any>): boolean {
|
|
|
|
function isThenable<T>(thing?: PromiseLike<T>): boolean {
|
|
|
|
return !!(thing && !!thing.then);
|
|
|
|
return !!(thing && thing.then);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
export default defineComponent({
|
|
|
@ -44,8 +45,11 @@ export default defineComponent({
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onInternalClose = (...args: any[]) => {
|
|
|
|
|
|
|
|
props.close?.(...args);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handlePromiseOnOk = (returnValueOfOnOk?: PromiseLike<any>) => {
|
|
|
|
const handlePromiseOnOk = (returnValueOfOnOk?: PromiseLike<any>) => {
|
|
|
|
const { close } = props;
|
|
|
|
|
|
|
|
if (!isThenable(returnValueOfOnOk)) {
|
|
|
|
if (!isThenable(returnValueOfOnOk)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,48 +59,46 @@ export default defineComponent({
|
|
|
|
if (!isDestroyed.value) {
|
|
|
|
if (!isDestroyed.value) {
|
|
|
|
loading.value = false;
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(...args);
|
|
|
|
onInternalClose(...args);
|
|
|
|
clickedRef.value = false;
|
|
|
|
clickedRef.value = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(e: Error) => {
|
|
|
|
(e: Error) => {
|
|
|
|
// Emit error when catch promise reject
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
|
|
|
console.error(e);
|
|
|
|
|
|
|
|
// See: https://github.com/ant-design/ant-design/issues/6183
|
|
|
|
// See: https://github.com/ant-design/ant-design/issues/6183
|
|
|
|
if (!isDestroyed.value) {
|
|
|
|
if (!isDestroyed.value) {
|
|
|
|
loading.value = false;
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clickedRef.value = false;
|
|
|
|
clickedRef.value = false;
|
|
|
|
|
|
|
|
return Promise.reject(e);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const onClick = (e: MouseEvent) => {
|
|
|
|
const onClick = (e: MouseEvent) => {
|
|
|
|
const { actionFn, close = () => {} } = props;
|
|
|
|
const { actionFn } = props;
|
|
|
|
if (clickedRef.value) {
|
|
|
|
if (clickedRef.value) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clickedRef.value = true;
|
|
|
|
clickedRef.value = true;
|
|
|
|
if (!actionFn) {
|
|
|
|
if (!actionFn) {
|
|
|
|
close();
|
|
|
|
onInternalClose();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let returnValueOfOnOk;
|
|
|
|
let returnValueOfOnOk: PromiseLike<any>;
|
|
|
|
if (props.emitEvent) {
|
|
|
|
if (props.emitEvent) {
|
|
|
|
returnValueOfOnOk = actionFn(e);
|
|
|
|
returnValueOfOnOk = actionFn(e);
|
|
|
|
if (props.quitOnNullishReturnValue && !isThenable(returnValueOfOnOk)) {
|
|
|
|
if (props.quitOnNullishReturnValue && !isThenable(returnValueOfOnOk)) {
|
|
|
|
clickedRef.value = false;
|
|
|
|
clickedRef.value = false;
|
|
|
|
close(e);
|
|
|
|
onInternalClose(e);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (actionFn.length) {
|
|
|
|
} else if (actionFn.length) {
|
|
|
|
returnValueOfOnOk = actionFn(close);
|
|
|
|
returnValueOfOnOk = actionFn(props.close);
|
|
|
|
// https://github.com/ant-design/ant-design/issues/23358
|
|
|
|
// https://github.com/ant-design/ant-design/issues/23358
|
|
|
|
clickedRef.value = false;
|
|
|
|
clickedRef.value = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
returnValueOfOnOk = actionFn();
|
|
|
|
returnValueOfOnOk = actionFn();
|
|
|
|
if (!returnValueOfOnOk) {
|
|
|
|
if (!returnValueOfOnOk) {
|
|
|
|
close();
|
|
|
|
onInternalClose();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|