|
|
@@ -4,46 +4,39 @@ import type { DialogAlertOptions } from "./DialogRoot.vue";
|
|
|
import type { ToastShowProps } from "../feedback/Toast.vue";
|
|
|
import type { ActionSheetOptions } from "./ActionSheetRoot.vue";
|
|
|
|
|
|
-let currentRoot : ICommonRoot|null = null;
|
|
|
+const currentRootStack : ICommonRoot[] = [];
|
|
|
|
|
|
export function setCurrentRoot(root : ICommonRoot) {
|
|
|
- currentRoot = root;
|
|
|
+ currentRootStack.push(root);
|
|
|
+}
|
|
|
+export function destroyCurrentRoot(root : ICommonRoot) {
|
|
|
+ const index = currentRootStack.indexOf(root);
|
|
|
+ if (index !== -1)
|
|
|
+ currentRootStack.splice(index, 1);
|
|
|
}
|
|
|
export function NaDialogRoot() : ICommonRoot {
|
|
|
- if (!currentRoot)
|
|
|
+ if (!currentRootStack.length)
|
|
|
throw new Error("No dialog root found.");
|
|
|
- return currentRoot;
|
|
|
+ return currentRootStack[currentRootStack.length - 1];
|
|
|
}
|
|
|
|
|
|
export function alert(options: DialogAlertOptions) {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.alert(options);
|
|
|
+ return NaDialogRoot().alert(options);
|
|
|
}
|
|
|
export function confirm(options: DialogAlertOptions) {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.confirm(options);
|
|
|
+ return NaDialogRoot().confirm(options);
|
|
|
}
|
|
|
export function toast(options: ToastShowProps) {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.toast(options);
|
|
|
+ return NaDialogRoot().toast(options);
|
|
|
}
|
|
|
export function closeToast() {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.closeToast();
|
|
|
+ return NaDialogRoot().closeToast();
|
|
|
}
|
|
|
export function actionSheet(options: ActionSheetOptions) {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.actionSheet(options);
|
|
|
+ return NaDialogRoot().actionSheet(options);
|
|
|
}
|
|
|
export function notify(options: ToastShowProps) {
|
|
|
- if (!currentRoot)
|
|
|
- throw new Error("No dialog root found.");
|
|
|
- return currentRoot.notify(options);
|
|
|
+ return NaDialogRoot().notify(options);
|
|
|
}
|
|
|
|
|
|
export default {
|