2022-05-26 15:18:53 +08:00
|
|
|
import {isMobile} from "../util/functions";
|
|
|
|
|
import {Dialog} from "./index";
|
2024-11-15 00:38:44 +08:00
|
|
|
import {Constants} from "../constants";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2024-10-28 22:04:48 +08:00
|
|
|
export const confirmDialog = (title: string, text: string,
|
|
|
|
|
confirm?: (dialog?: Dialog) => void,
|
|
|
|
|
cancel?: (dialog: Dialog) => void,
|
|
|
|
|
isDelete = false) => {
|
2024-03-25 11:15:00 +08:00
|
|
|
if (!text && !title) {
|
|
|
|
|
confirm();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
const dialog = new Dialog({
|
|
|
|
|
title,
|
2023-04-14 20:21:09 +08:00
|
|
|
content: `<div class="b3-dialog__content">
|
|
|
|
|
<div class="ft__breakword">${text}</div>
|
|
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<div class="b3-dialog__action">
|
2024-12-20 18:57:49 +08:00
|
|
|
<button class="b3-button b3-button--cancel" id="cancelDialogConfirmBtn">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
2024-10-28 22:04:48 +08:00
|
|
|
<button class="b3-button ${isDelete ? "b3-button--remove" : "b3-button--text"}" id="confirmDialogConfirmBtn">${window.siyuan.languages[isDelete ? "delete" : "confirm"]}</button>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>`,
|
2023-04-20 10:05:24 +08:00
|
|
|
width: isMobile() ? "92vw" : "520px",
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
2024-12-20 18:57:49 +08:00
|
|
|
|
|
|
|
|
dialog.element.addEventListener("click", (event) => {
|
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
const isDispatch = typeof event.detail === "string";
|
|
|
|
|
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
|
|
|
|
if (target.id === "cancelDialogConfirmBtn" || (isDispatch && event.detail=== "Escape")) {
|
|
|
|
|
if (cancel) {
|
|
|
|
|
cancel(dialog);
|
|
|
|
|
}
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
break;
|
|
|
|
|
} else if (target.id === "confirmDialogConfirmBtn" || (isDispatch && event.detail=== "Enter")) {
|
|
|
|
|
if (confirm) {
|
|
|
|
|
confirm(dialog);
|
|
|
|
|
}
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
target = target.parentElement;
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
});
|
2024-11-15 00:38:44 +08:00
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
2022-05-26 15:18:53 +08:00
|
|
|
};
|