From c6fdc29d2a3a6f557a068cfa1a6e5ecd0c8cc4bc Mon Sep 17 00:00:00 2001 From: Mohammad Azmi Date: Wed, 17 Dec 2025 21:11:30 +0700 Subject: [PATCH] add confirm --- .../src-commercial/entrypoints/renderer.ts | 1 + apps/studio/src/services/plugin/types.ts | 1 + .../services/plugin/web/WebPluginLoader.ts | 7 +++ .../services/plugin/web/WebPluginManager.ts | 4 ++ docs/plugin_development/api-reference.md | 47 +++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/apps/studio/src-commercial/entrypoints/renderer.ts b/apps/studio/src-commercial/entrypoints/renderer.ts index 73f2ae601..86a4145b2 100644 --- a/apps/studio/src-commercial/entrypoints/renderer.ts +++ b/apps/studio/src-commercial/entrypoints/renderer.ts @@ -206,6 +206,7 @@ import ProductTourPlugin from '@/plugins/ProductTourPlugin' appVersion: window.platformInfo.appVersion, fileHelpers: window.main.fileHelpers, noty: Vue.prototype.$noty, + confirm: app.$confirm.bind(app), }); webPluginManager.initialize().then(() => { store.commit("webPluginManagerStatus", "ready") diff --git a/apps/studio/src/services/plugin/types.ts b/apps/studio/src/services/plugin/types.ts index fed28ea0f..cade4319a 100644 --- a/apps/studio/src/services/plugin/types.ts +++ b/apps/studio/src/services/plugin/types.ts @@ -186,6 +186,7 @@ export type WebPluginContext = { warning(text: string): Noty; info(text: string): Noty; }; + confirm(title?: string, message?: string, options?: { confirmLabel?: string, cancelLabel?: string }): Promise; } export type PluginContext = { diff --git a/apps/studio/src/services/plugin/web/WebPluginLoader.ts b/apps/studio/src/services/plugin/web/WebPluginLoader.ts index 6a6a306b9..638f7c169 100644 --- a/apps/studio/src/services/plugin/web/WebPluginLoader.ts +++ b/apps/studio/src/services/plugin/web/WebPluginLoader.ts @@ -277,6 +277,13 @@ export default class WebPluginLoader { case "noty.warning": this.context.noty.warning(response.args.message); break; + case "confirm": + response.result = await this.context.confirm( + response.args.title, + response.args.message, + response.args.options + ); + break; // ======== UI ACTIONS =========== case "expandTableResult": diff --git a/apps/studio/src/services/plugin/web/WebPluginManager.ts b/apps/studio/src/services/plugin/web/WebPluginManager.ts index 47b1748f6..e9f3f9092 100644 --- a/apps/studio/src/services/plugin/web/WebPluginManager.ts +++ b/apps/studio/src/services/plugin/web/WebPluginManager.ts @@ -21,6 +21,7 @@ export type WebPluginManagerParams = { warning(text: string): Noty; info(text: string): Noty; }; + confirm(title?: string, message?: string, options?: { confirmLabel?: string, cancelLabel?: string }): Promise; } /** @@ -57,6 +58,7 @@ export default class WebPluginManager { public readonly appVersion: string; public readonly fileHelpers: FileHelpers; private readonly noty: WebPluginManagerParams['noty']; + private readonly confirm: WebPluginManagerParams['confirm']; constructor(params: WebPluginManagerParams) { this.utilityConnection = params.utilityConnection; @@ -64,6 +66,7 @@ export default class WebPluginManager { this.appVersion = params.appVersion; this.fileHelpers = params.fileHelpers; this.noty = params.noty; + this.confirm = params.confirm; } async initialize() { @@ -266,6 +269,7 @@ export default class WebPluginManager { appVersion: this.appVersion, fileHelpers: this.fileHelpers, noty: this.noty, + confirm: this.confirm, }); await loader.load(); this.loaders.set(manifest.id, loader); diff --git a/docs/plugin_development/api-reference.md b/docs/plugin_development/api-reference.md index 7635d7d29..6140fa1c4 100644 --- a/docs/plugin_development/api-reference.md +++ b/docs/plugin_development/api-reference.md @@ -380,6 +380,53 @@ await noty.warning('This operation may take a while'); { message: string } ``` +### confirm + +Display a confirmation dialog to the user and wait for their response. + +**Usage:** +```javascript +import { confirm } from '@beekeeperstudio/plugin'; + +// Basic confirmation +const result = await confirm(); +if (result) { + // User clicked confirm +} else { + // User clicked cancel +} + +// With title and message +const result = await confirm('Delete Table', 'Are you sure you want to delete this table?'); + +// With custom button labels +const result = await confirm( + 'Export Data', + 'This will export all data to a CSV file. Continue?', + { + confirmLabel: 'Export', + cancelLabel: 'Cancel' + } +); +``` + +**Arguments Schema:** +```typescript +{ + title?: string; + message?: string; + options?: { + confirmLabel?: string; + cancelLabel?: string; + }; +} +``` + +**Response Schema:** +```typescript +boolean // true if confirmed, false if cancelled +``` + ## Notifications ### themeChanged