33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import type { IDialogButton } from './components/types'
7- import type Vue from 'vue'
8-
6+ import type { IDialogButton , IDialogSeverity } from './components/types.ts'
97import { spawnDialog } from '@nextcloud/vue/functions/dialog'
108
11- import { DialogSeverity } from './components/types'
129import GenericDialog from './components/GenericDialog.vue'
1310
14- export { DialogSeverity } from './components/types'
11+ export type * from './components/types.ts '
1512
1613/**
1714 * This class provides generic Nextcloud themed dialogs
@@ -21,8 +18,7 @@ export class Dialog {
2118 #name: string
2219 #text: string
2320 #buttons: IDialogButton [ ]
24- #severity?: DialogSeverity
25- #dialog?: Vue
21+ #severity?: IDialogSeverity
2622
2723 /** @deprecated */
2824 #html?: string
@@ -31,13 +27,12 @@ export class Dialog {
3127 name : string ,
3228 text : string ,
3329 buttons : IDialogButton [ ] = [ ] ,
34- severity ?: DialogSeverity ,
30+ severity ?: IDialogSeverity ,
3531 ) {
3632 this . #name = name
3733 this . #text = text
3834 this . #buttons = buttons
3935 this . #severity = severity
40- this . #dialog = undefined
4136 this . #html = undefined
4237 }
4338
@@ -52,34 +47,22 @@ export class Dialog {
5247
5348 /**
5449 * Spawn and show the dialog - if already open the previous instance will be destroyed
50+ *
5551 * @return Promise that resolves when the dialog is answered successfully and rejects on close
5652 */
5753 async show ( ) {
58- if ( this . #dialog) {
59- this . #dialog. $destroy ( )
54+ const result = await spawnDialog ( GenericDialog ,
55+ {
56+ buttons : this . #buttons,
57+ name : this . #name,
58+ text : this . #text,
59+ severity : this . #severity,
60+ html : this . #html,
61+ } ,
62+ )
63+ if ( ! result ) {
64+ throw new Error ( 'Dialog closed' )
6065 }
61-
62- return new Promise ( ( resolve ) => {
63- this . #dialog = spawnDialog ( GenericDialog ,
64- {
65- buttons : this . #buttons,
66- name : this . #name,
67- text : this . #text,
68- severity : this . #severity,
69- html : this . #html,
70- } ,
71- resolve ,
72- )
73- } )
74- }
75-
76- /**
77- * Hide and destroy the current dialog instance
78- *
79- * @deprecated use the promise of the `show` methods for the user interaction.
80- */
81- hide ( ) {
82- this . #dialog?. $destroy ( )
8366 }
8467
8568}
@@ -103,7 +86,7 @@ export class Dialog {
10386 */
10487export class DialogBuilder {
10588
106- #severity?: DialogSeverity
89+ #severity?: IDialogSeverity
10790 #text: string
10891 #name: string
10992 #buttons: IDialogButton [ ]
@@ -137,7 +120,7 @@ export class DialogBuilder {
137120 * Set the severity of the dialog
138121 * @param severity Severity of the dialog
139122 */
140- setSeverity ( severity : DialogSeverity ) {
123+ setSeverity ( severity : IDialogSeverity ) {
141124 this . #severity = severity
142125 return this
143126 }
0 commit comments