@wishbone-media/spark 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishbone-media/spark",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,6 +1,8 @@
1
1
  <template>
2
2
  <TransitionRoot as="template" :show="sparkModalService.state.isVisible">
3
- <Dialog class="relative z-1000" @close="sparkModalService.hide">
3
+ <!-- Headless UI emits close with a payload (false); call hide() without it
4
+ so a backdrop/ESC dismiss resolves the show() promise with null -->
5
+ <Dialog class="relative z-1000" @close="() => sparkModalService.hide()">
4
6
  <TransitionChild
5
7
  as="template"
6
8
  enter="ease-out duration-300"
@@ -9,18 +9,40 @@ class SparkModalService {
9
9
  props: {},
10
10
  eventHandlers: {},
11
11
  })
12
+ this._resolveShow = null
12
13
  }
13
14
 
15
+ /**
16
+ * Show a modal with a custom component.
17
+ *
18
+ * @param {Object} component - Vue component to render inside the modal
19
+ * @param {Object} [props] - Props passed to the component
20
+ * @param {Object} [eventHandlers] - Event handlers bound to the component
21
+ * @returns {Promise<any>} - Resolves when the modal closes: with the value
22
+ * passed to hide(result), or null on a plain hide() / backdrop / ESC dismiss
23
+ */
14
24
  show = (component, props = {}, eventHandlers = {}) => {
25
+ this._resolveShow?.(null) // a new modal supersedes a still-pending one
15
26
  this.state.content = markRaw(component)
16
27
  this.state.props = props
17
28
  this.state.eventHandlers = eventHandlers
18
29
  this.state.isVisible = true
30
+ return new Promise((resolve) => {
31
+ this._resolveShow = resolve
32
+ })
19
33
  }
20
34
 
21
- hide = () => {
35
+ /**
36
+ * Close the current modal, resolving the pending show() promise.
37
+ *
38
+ * @param {any} [result=null] - Value the show() promise resolves with
39
+ */
40
+ hide = (result = null) => {
22
41
  this.state.isVisible = false
23
42
  this.state.eventHandlers = {}
43
+ const resolve = this._resolveShow
44
+ this._resolveShow = null
45
+ resolve?.(result)
24
46
  }
25
47
 
26
48
  /**
@@ -33,42 +55,37 @@ class SparkModalService {
33
55
  * @param {string} [options.confirmText='Confirm'] - Confirm button text
34
56
  * @param {string} [options.cancelText='Cancel'] - Cancel button text
35
57
  * @param {string} [options.confirmVariant='primary'] - Confirm button variant
36
- * @returns {Promise<boolean>} - Resolves to true if confirmed, false if cancelled
58
+ * @returns {Promise<boolean>} - Resolves to true if confirmed, false if
59
+ * cancelled or dismissed (backdrop / ESC)
37
60
  */
38
- confirm = (options = {}) => {
39
- return new Promise((resolve) => {
40
- const {
41
- title = 'Confirm',
42
- message = 'Are you sure?',
43
- type = 'warning',
44
- confirmText = 'Confirm',
45
- cancelText = 'Cancel',
46
- confirmVariant = 'primary',
47
- } = options
61
+ confirm = async (options = {}) => {
62
+ const {
63
+ title = 'Confirm',
64
+ message = 'Are you sure?',
65
+ type = 'warning',
66
+ confirmText = 'Confirm',
67
+ cancelText = 'Cancel',
68
+ confirmVariant = 'primary',
69
+ } = options
48
70
 
49
- this.show(
50
- SparkModalDialog,
51
- {
52
- title,
53
- message,
54
- type,
55
- buttons: [
56
- { text: confirmText, variant: confirmVariant, event: 'confirm' },
57
- { text: cancelText, variant: 'secondary', event: 'cancel' },
58
- ],
59
- },
60
- {
61
- confirm: () => {
62
- this.hide()
63
- resolve(true)
64
- },
65
- cancel: () => {
66
- this.hide()
67
- resolve(false)
68
- },
69
- },
70
- )
71
- })
71
+ const result = await this.show(
72
+ SparkModalDialog,
73
+ {
74
+ title,
75
+ message,
76
+ type,
77
+ buttons: [
78
+ { text: confirmText, variant: confirmVariant, event: 'confirm' },
79
+ { text: cancelText, variant: 'secondary', event: 'cancel' },
80
+ ],
81
+ },
82
+ {
83
+ confirm: () => this.hide(true),
84
+ cancel: () => this.hide(false),
85
+ },
86
+ )
87
+
88
+ return Boolean(result)
72
89
  }
73
90
  }
74
91