Skip to content

Commit 966b1dd

Browse files
authored
Extension API to add toast message (#491)
* Extension API to add toast message * Update readme
1 parent 0697663 commit 966b1dd

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ We will support custom icons later.
116116
![image](https://github.com/user-attachments/assets/7bff028a-bf91-4cab-bf97-55c243b3f5e0)
117117
</details>
118118

119+
<details>
120+
<summary>v1.2.27: Extension API to add toast message</summary>
121+
122+
Extensions can call the following API to add toast messages.
123+
124+
```js
125+
app.extensionManager.toast.add({
126+
severity: 'info',
127+
summary: 'Loaded!',
128+
detail: 'Extension loaded!'
129+
})
130+
```
131+
132+
![image](https://github.com/user-attachments/assets/de02cd7e-cd81-43d1-a0b0-bccef92ff487)
133+
</details>
119134

120135
## Road Map
121136

src/stores/workspaceStateStore.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { SidebarTabExtension } from '@/types/extensionTypes'
1+
import { SidebarTabExtension, ToastManager } from '@/types/extensionTypes'
22
import { defineStore } from 'pinia'
3+
import { useToastStore } from './toastStore'
34

45
interface WorkspaceState {
56
spinner: boolean
@@ -13,6 +14,11 @@ export const useWorkspaceStore = defineStore('workspace', {
1314
activeSidebarTab: null,
1415
sidebarTabs: []
1516
}),
17+
getters: {
18+
toast(): ToastManager {
19+
return useToastStore()
20+
}
21+
},
1622
actions: {
1723
updateActiveSidebarTab(tabId: string) {
1824
this.activeSidebarTab = tabId

src/types/extensionTypes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ToastMessageOptions } from 'primevue/toast'
12
import { Component } from 'vue'
23

34
export interface BaseSidebarTabExtension {
@@ -24,8 +25,18 @@ export type SidebarTabExtension =
2425
| VueSidebarTabExtension
2526
| CustomSidebarTabExtension
2627

28+
export type ToastManager = {
29+
add(message: ToastMessageOptions): void
30+
remove(message: ToastMessageOptions): void
31+
removeAll(): void
32+
}
33+
2734
export interface ExtensionManager {
35+
// Sidebar tabs
2836
registerSidebarTab(tab: SidebarTabExtension): void
2937
unregisterSidebarTab(id: string): void
3038
getSidebarTabs(): SidebarTabExtension[]
39+
40+
// Toast
41+
toast: ToastManager
3142
}

0 commit comments

Comments
 (0)