1+ import type { AbortablePromise } from 'better-promises' ;
2+
13import { request } from '@/globals.js' ;
24import { createIsSupported } from '@/scopes/createIsSupported.js' ;
35import { createWrapSupported } from '@/scopes/wrappers/createWrapSupported.js' ;
46import { defineNonConcurrentFn } from '@/scopes/defineNonConcurrentFn.js' ;
57
68import { prepareParams } from './prepareParams.js' ;
7- import type { OpenOptions } from './types.js' ;
9+ import type { ShowOptions } from './types.js' ;
810
911const OPEN_METHOD = 'web_app_open_popup' ;
1012const wrapSupported = createWrapSupported ( 'popup' , OPEN_METHOD ) ;
@@ -14,16 +16,38 @@ const wrapSupported = createWrapSupported('popup', OPEN_METHOD);
1416 */
1517export const isSupported = createIsSupported ( OPEN_METHOD ) ;
1618
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 } ;
2751
2852/**
2953 * A method that shows a native popup described by the `params` argument.
@@ -56,6 +80,6 @@ const [
5680 * });
5781 * }
5882 */
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