1
+ import type { AbortablePromise } from 'better-promises' ;
2
+
1
3
import { request } from '@/globals.js' ;
2
4
import { createIsSupported } from '@/scopes/createIsSupported.js' ;
3
5
import { createWrapSupported } from '@/scopes/wrappers/createWrapSupported.js' ;
4
6
import { defineNonConcurrentFn } from '@/scopes/defineNonConcurrentFn.js' ;
5
7
6
8
import { prepareParams } from './prepareParams.js' ;
7
- import type { OpenOptions } from './types.js' ;
9
+ import type { ShowOptions } from './types.js' ;
8
10
9
11
const OPEN_METHOD = 'web_app_open_popup' ;
10
12
const wrapSupported = createWrapSupported ( 'popup' , OPEN_METHOD ) ;
@@ -14,16 +16,38 @@ const wrapSupported = createWrapSupported('popup', OPEN_METHOD);
14
16
*/
15
17
export const isSupported = createIsSupported ( OPEN_METHOD ) ;
16
18
17
- const [
18
- fn ,
19
- tOpenPromise ,
20
- tOpenError ,
21
- ] = defineNonConcurrentFn ( ( options : OpenOptions ) => {
22
- return request ( OPEN_METHOD , 'popup_closed' , {
23
- ...options ,
24
- params : prepareParams ( options ) ,
25
- } ) . then ( ( { button_id : buttonId } ) => buttonId === undefined ? null : buttonId ) ;
26
- } , 'A popup is already opened' ) ;
19
+ const [ fn , tPromise , tShowError ] = defineNonConcurrentFn (
20
+ ( options : ShowOptions ) : AbortablePromise < string | null > => {
21
+ return request ( OPEN_METHOD , 'popup_closed' , {
22
+ ...options ,
23
+ params : prepareParams ( options ) ,
24
+ } ) . then ( ( { button_id : buttonId } ) => buttonId === undefined ? null : buttonId ) ;
25
+ } ,
26
+ 'A popup is already opened' ,
27
+ ) ;
28
+
29
+ /**
30
+ * @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
31
+ * `show` instead.
32
+ */
33
+ export const open = wrapSupported ( 'open' , fn ) ;
34
+ /**
35
+ * @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
36
+ * `showPromise` instead.
37
+ */
38
+ const openPromise = tPromise [ 1 ] ;
39
+ /**
40
+ * @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
41
+ * `isShown` instead.
42
+ */
43
+ const isOpened = tPromise [ 2 ] ;
44
+ /**
45
+ * @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
46
+ * `showError` instead.
47
+ */
48
+ const openError = tShowError [ 1 ] ;
49
+
50
+ export { openPromise , isOpened , openError } ;
27
51
28
52
/**
29
53
* A method that shows a native popup described by the `params` argument.
@@ -56,6 +80,6 @@ const [
56
80
* });
57
81
* }
58
82
*/
59
- export const open = wrapSupported ( 'open ' , fn ) ;
60
- export const [ , openPromise , isOpened ] = tOpenPromise ;
61
- export const [ , openError ] = tOpenError ;
83
+ export const show = wrapSupported ( 'show ' , fn ) ;
84
+ export const [ , showPromise , isShown ] = tPromise ;
85
+ export const [ , showError ] = tShowError ;
0 commit comments