fix(frontend): モーダルが複数個開ける問題を修正

This commit is contained in:
kakkokari-gtyih 2024-07-13 12:35:39 +09:00
parent 91de35ecdf
commit e9ad7cf226
2 changed files with 25 additions and 0 deletions

View File

@ -170,13 +170,33 @@ type EmitsExtractor<T> = {
[K in keyof T as K extends `onVnode${string}` ? never : K extends `on${infer E}` ? Uncapitalize<E> : K extends string ? never : K]: T[K];
};
type PopupOptions = {
/** @default false */
allowMultiple?: boolean;
};
export function popup<T extends Component>(
component: T,
props: ComponentProps<T>,
events: ComponentEmit<T> = {} as ComponentEmit<T>,
options: PopupOptions = {},
): { dispose: () => void } {
markRaw(component);
const _options: Required<PopupOptions> = Object.assign({
allowMultiple: false,
}, options);
if (
_options.allowMultiple === false &&
popups.value.some(popup => popup.component === component)
) {
if (_DEV_) console.warn('Popup already exists');
return {
dispose: () => { },
};
}
const id = ++popupIdCount;
const dispose = () => {
// このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ
@ -203,6 +223,8 @@ export function pageWindow(path: string) {
initialPath: path,
}, {
closed: () => dispose(),
}, {
allowMultiple: true,
});
}
@ -211,6 +233,8 @@ export function toast(message: string) {
message,
}, {
closed: () => dispose(),
}, {
allowMultiple: true,
});
}

View File

@ -114,6 +114,7 @@ const matchPatterns = (ev: KeyboardEvent, action: Action) => {
const key = ev.key.toLowerCase();
return patterns.some(({ which, ctrl, shift, alt }) => {
if (
options.allowRepeat === false &&
latestHotkey != null &&
latestHotkey.which.includes(key) &&
latestHotkey.ctrl === ctrl &&