add confirm

This commit is contained in:
Mohammad Azmi
2025-12-17 21:11:30 +07:00
parent 9fc4ac9bba
commit c6fdc29d2a
5 changed files with 60 additions and 0 deletions

View File

@@ -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")

View File

@@ -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<boolean>;
}
export type PluginContext = {

View File

@@ -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":

View File

@@ -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<boolean>;
}
/**
@@ -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);

View File

@@ -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