From 0cdaa512c8bddfd07583e7bb40042b9045856f06 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Thu, 29 May 2025 21:05:52 +1000 Subject: [PATCH] Allow extensions to raise their own Vue dialogs (#4008) --- src/services/dialogService.ts | 19 +++++++++++++++++++ src/stores/dialogStore.ts | 25 ++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/services/dialogService.ts b/src/services/dialogService.ts index dff67e533..224f83f93 100644 --- a/src/services/dialogService.ts +++ b/src/services/dialogService.ts @@ -379,6 +379,24 @@ export const useDialogService = () => { }) } + /** + * Shows a dialog from a third party extension. + * @param options - The dialog options. + * @param options.key - The dialog key. + * @param options.title - The dialog title. + * @param options.headerComponent - The dialog header component. + * @param options.footerComponent - The dialog footer component. + * @param options.component - The dialog component. + * @param options.props - The dialog props. + * @returns The dialog instance and a function to close the dialog. + */ + function showExtensionDialog(options: ShowDialogOptions & { key: string }) { + return { + dialog: dialogStore.showExtensionDialog(options), + closeDialog: () => dialogStore.closeDialog({ key: options.key }) + } + } + return { showLoadWorkflowWarning, showMissingModelsWarning, @@ -394,6 +412,7 @@ export const useDialogService = () => { showSignInDialog, showTopUpCreditsDialog, showUpdatePasswordDialog, + showExtensionDialog, prompt, confirm } diff --git a/src/stores/dialogStore.ts b/src/stores/dialogStore.ts index 675858a5a..35a10b668 100644 --- a/src/stores/dialogStore.ts +++ b/src/stores/dialogStore.ts @@ -147,10 +147,33 @@ export const useDialogStore = defineStore('dialog', () => { return dialog } + /** + * Shows a dialog from a third party extension. + * Explicitly keys extension dialogs with `extension-` prefix, + * to avoid conflicts & prevent use of internal dialogs (available via `dialogService`). + */ + function showExtensionDialog(options: ShowDialogOptions & { key: string }) { + const { key } = options + if (!key) { + console.error('Extension dialog key is required') + return + } + + const extKey = key.startsWith('extension-') ? key : `extension-${key}` + + const dialog = dialogStack.value.find((d) => d.key === extKey) + if (!dialog) return createDialog({ ...options, key: extKey }) + + dialog.visible = true + riseDialog(dialog) + return dialog + } + return { dialogStack, riseDialog, showDialog, - closeDialog + closeDialog, + showExtensionDialog } })