@tma.js/sdk 0.11.3
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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/lib/browser.js +2 -0
- package/dist/lib/browser.js.map +1 -0
- package/dist/lib/index.cjs +2 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.mjs +2 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/components/BackButton/BackButton.d.ts +44 -0
- package/dist/types/components/BackButton/index.d.ts +2 -0
- package/dist/types/components/BackButton/types.d.ts +9 -0
- package/dist/types/components/ClosingBehaviour/ClosingBehaviour.d.ts +35 -0
- package/dist/types/components/ClosingBehaviour/index.d.ts +2 -0
- package/dist/types/components/ClosingBehaviour/types.d.ts +7 -0
- package/dist/types/components/CloudStorage/CloudStorage.d.ts +47 -0
- package/dist/types/components/CloudStorage/index.d.ts +1 -0
- package/dist/types/components/HapticFeedback/HapticFeedback.d.ts +37 -0
- package/dist/types/components/HapticFeedback/index.d.ts +1 -0
- package/dist/types/components/InitData/InitData.d.ts +52 -0
- package/dist/types/components/InitData/index.d.ts +1 -0
- package/dist/types/components/MainButton/MainButton.d.ts +114 -0
- package/dist/types/components/MainButton/index.d.ts +2 -0
- package/dist/types/components/MainButton/types.d.ts +15 -0
- package/dist/types/components/Popup/Popup.d.ts +44 -0
- package/dist/types/components/Popup/index.d.ts +2 -0
- package/dist/types/components/Popup/types.d.ts +60 -0
- package/dist/types/components/Popup/utils.d.ts +7 -0
- package/dist/types/components/QRScanner/QRScanner.d.ts +40 -0
- package/dist/types/components/QRScanner/index.d.ts +2 -0
- package/dist/types/components/QRScanner/types.d.ts +7 -0
- package/dist/types/components/ThemeParams/ThemeParams.d.ts +73 -0
- package/dist/types/components/ThemeParams/index.d.ts +2 -0
- package/dist/types/components/ThemeParams/types.d.ts +9 -0
- package/dist/types/components/Viewport/Viewport.d.ts +108 -0
- package/dist/types/components/Viewport/index.d.ts +2 -0
- package/dist/types/components/Viewport/types.d.ts +10 -0
- package/dist/types/components/WebApp/WebApp.d.ts +145 -0
- package/dist/types/components/WebApp/index.d.ts +2 -0
- package/dist/types/components/WebApp/types.d.ts +11 -0
- package/dist/types/components/index.d.ts +11 -0
- package/dist/types/env.d.ts +8 -0
- package/dist/types/errors/MethodNotSupportedError.d.ts +6 -0
- package/dist/types/errors/ParameterNotSupportedError.d.ts +6 -0
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/init/creators/createBackButton.d.ts +9 -0
- package/dist/types/init/creators/createClosingBehavior.d.ts +8 -0
- package/dist/types/init/creators/createMainButton.d.ts +11 -0
- package/dist/types/init/creators/createPostEvent.d.ts +7 -0
- package/dist/types/init/creators/createRequestIdGenerator.d.ts +5 -0
- package/dist/types/init/creators/createSyncedThemeParams.d.ts +7 -0
- package/dist/types/init/creators/createViewport.d.ts +10 -0
- package/dist/types/init/creators/createWebApp.d.ts +14 -0
- package/dist/types/init/creators/index.d.ts +8 -0
- package/dist/types/init/css.d.ts +57 -0
- package/dist/types/init/index.d.ts +2 -0
- package/dist/types/init/init.d.ts +6 -0
- package/dist/types/init/types.d.ts +107 -0
- package/dist/types/launch-params.d.ts +20 -0
- package/dist/types/state/State.d.ts +15 -0
- package/dist/types/state/index.d.ts +2 -0
- package/dist/types/state/types.d.ts +30 -0
- package/dist/types/storage.d.ts +48 -0
- package/dist/types/supports.d.ts +22 -0
- package/dist/types/theme-params.d.ts +18 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/url.d.ts +7 -0
- package/package.json +67 -0
- package/src/components/BackButton/BackButton.ts +90 -0
- package/src/components/BackButton/index.ts +2 -0
- package/src/components/BackButton/types.ts +13 -0
- package/src/components/ClosingBehaviour/ClosingBehaviour.ts +62 -0
- package/src/components/ClosingBehaviour/index.ts +6 -0
- package/src/components/ClosingBehaviour/types.ts +12 -0
- package/src/components/CloudStorage/CloudStorage.ts +135 -0
- package/src/components/CloudStorage/index.ts +1 -0
- package/src/components/HapticFeedback/HapticFeedback.ts +62 -0
- package/src/components/HapticFeedback/index.ts +1 -0
- package/src/components/InitData/InitData.ts +116 -0
- package/src/components/InitData/index.ts +1 -0
- package/src/components/MainButton/MainButton.ts +243 -0
- package/src/components/MainButton/index.ts +2 -0
- package/src/components/MainButton/types.ts +20 -0
- package/src/components/Popup/Popup.ts +81 -0
- package/src/components/Popup/index.ts +8 -0
- package/src/components/Popup/types.ts +69 -0
- package/src/components/Popup/utils.ts +59 -0
- package/src/components/QRScanner/QRScanner.ts +87 -0
- package/src/components/QRScanner/index.ts +2 -0
- package/src/components/QRScanner/types.ts +11 -0
- package/src/components/ThemeParams/ThemeParams.ts +154 -0
- package/src/components/ThemeParams/index.ts +2 -0
- package/src/components/ThemeParams/types.ts +18 -0
- package/src/components/Viewport/Viewport.ts +197 -0
- package/src/components/Viewport/index.ts +2 -0
- package/src/components/Viewport/types.ts +14 -0
- package/src/components/WebApp/WebApp.ts +310 -0
- package/src/components/WebApp/index.ts +2 -0
- package/src/components/WebApp/types.ts +17 -0
- package/src/components/index.ts +11 -0
- package/src/env.ts +17 -0
- package/src/errors/MethodNotSupportedError.ts +9 -0
- package/src/errors/ParameterNotSupportedError.ts +9 -0
- package/src/errors/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/init/creators/createBackButton.ts +22 -0
- package/src/init/creators/createClosingBehavior.ts +22 -0
- package/src/init/creators/createMainButton.ts +56 -0
- package/src/init/creators/createPostEvent.ts +36 -0
- package/src/init/creators/createRequestIdGenerator.ts +13 -0
- package/src/init/creators/createSyncedThemeParams.ts +14 -0
- package/src/init/creators/createViewport.ts +50 -0
- package/src/init/creators/createWebApp.ts +49 -0
- package/src/init/creators/index.ts +8 -0
- package/src/init/css.ts +166 -0
- package/src/init/index.ts +2 -0
- package/src/init/init.ts +160 -0
- package/src/init/types.ts +133 -0
- package/src/launch-params.ts +70 -0
- package/src/state/State.ts +53 -0
- package/src/state/index.ts +2 -0
- package/src/state/types.ts +34 -0
- package/src/storage.ts +65 -0
- package/src/supports.ts +44 -0
- package/src/theme-params.ts +34 -0
- package/src/types.ts +28 -0
- package/src/url.ts +24 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import type { Version } from '@tma.js/utils';
|
|
3
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
4
|
+
/**
|
|
5
|
+
* Class which controls the back button displayed in the header
|
|
6
|
+
* of the Web App in the Telegram interface. It is mostly used in case, when
|
|
7
|
+
* you want to provide a way to go bach in routing history or "rollback" some
|
|
8
|
+
* action.
|
|
9
|
+
*/
|
|
10
|
+
export declare class BackButton {
|
|
11
|
+
private readonly postEvent;
|
|
12
|
+
private readonly ee;
|
|
13
|
+
private readonly state;
|
|
14
|
+
constructor(isVisible: boolean, version: Version, postEvent?: PostEvent);
|
|
15
|
+
private set isVisible(value);
|
|
16
|
+
/**
|
|
17
|
+
* True if BackButton is currently visible.
|
|
18
|
+
*/
|
|
19
|
+
get isVisible(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Hides the BackButton.
|
|
22
|
+
*/
|
|
23
|
+
hide(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Adds event listener.
|
|
26
|
+
* @param event - event name.
|
|
27
|
+
* @param listener - event listener.
|
|
28
|
+
*/
|
|
29
|
+
on: typeof this.ee.on;
|
|
30
|
+
/**
|
|
31
|
+
* Removes event listener.
|
|
32
|
+
* @param event - event name.
|
|
33
|
+
* @param listener - event listener.
|
|
34
|
+
*/
|
|
35
|
+
off: typeof this.ee.off;
|
|
36
|
+
/**
|
|
37
|
+
* Shows the BackButton.
|
|
38
|
+
*/
|
|
39
|
+
show(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if specified method is supported by current component.
|
|
42
|
+
*/
|
|
43
|
+
supports: SupportsFunc<'show' | 'hide'>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StateEvents } from '../../state/index.js';
|
|
2
|
+
export interface BackButtonState {
|
|
3
|
+
isVisible: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface BackButtonEvents extends StateEvents<BackButtonState> {
|
|
6
|
+
click: () => void;
|
|
7
|
+
}
|
|
8
|
+
export type BackButtonEventName = keyof BackButtonEvents;
|
|
9
|
+
export type BackButtonEventListener<E extends BackButtonEventName> = BackButtonEvents[E];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
/**
|
|
3
|
+
* Component responsible for controlling current closing confirmation
|
|
4
|
+
* status.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ClosingBehaviour {
|
|
7
|
+
private readonly postEvent;
|
|
8
|
+
private readonly ee;
|
|
9
|
+
private readonly state;
|
|
10
|
+
constructor(isConfirmationNeeded: boolean, postEvent?: PostEvent);
|
|
11
|
+
private set isConfirmationNeeded(value);
|
|
12
|
+
/**
|
|
13
|
+
* Returns true, if the confirmation dialog enabled while the user is trying
|
|
14
|
+
* to close the Web App.
|
|
15
|
+
*/
|
|
16
|
+
get isConfirmationNeeded(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Disables the confirmation dialog while the user is trying to close the
|
|
19
|
+
* Web App.
|
|
20
|
+
*/
|
|
21
|
+
disableConfirmation(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Enables the confirmation dialog while the user is trying to close the
|
|
24
|
+
* Web App.
|
|
25
|
+
*/
|
|
26
|
+
enableConfirmation(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Adds new event listener.
|
|
29
|
+
*/
|
|
30
|
+
on: typeof this.ee.on;
|
|
31
|
+
/**
|
|
32
|
+
* Removes event listener.
|
|
33
|
+
*/
|
|
34
|
+
off: typeof this.ee.off;
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StateEvents } from '../../state/index.js';
|
|
2
|
+
export interface ClosingBehaviourState {
|
|
3
|
+
isConfirmationNeeded: boolean;
|
|
4
|
+
}
|
|
5
|
+
export type ClosingBehaviourEvents = StateEvents<ClosingBehaviourState>;
|
|
6
|
+
export type ClosingBehaviourEventName = keyof ClosingBehaviourEvents;
|
|
7
|
+
export type ClosingBehaviourEventListener<E extends ClosingBehaviourEventName> = ClosingBehaviourEvents[E];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { postEvent as defaultPostEvent, type RequestOptions } from '@tma.js/bridge';
|
|
2
|
+
import type { Version } from '@tma.js/utils';
|
|
3
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
4
|
+
import type { CreateRequestIdFunc } from '../../types.js';
|
|
5
|
+
type WiredRequestOptions = Omit<RequestOptions, 'postEvent'>;
|
|
6
|
+
export declare class CloudStorage {
|
|
7
|
+
private readonly createRequestId;
|
|
8
|
+
private readonly postEvent;
|
|
9
|
+
constructor(version: Version, createRequestId: CreateRequestIdFunc, postEvent?: typeof defaultPostEvent);
|
|
10
|
+
/**
|
|
11
|
+
* Invokes custom method related to CloudStorage.
|
|
12
|
+
* @param method - method name.
|
|
13
|
+
* @param params - method parameters.
|
|
14
|
+
* @param options - execution options.
|
|
15
|
+
*/
|
|
16
|
+
private invokeCustomMethod;
|
|
17
|
+
/**
|
|
18
|
+
* Deletes specified keys from the CloudStorage.
|
|
19
|
+
* @param keys - keys list.
|
|
20
|
+
* @param options - request execution options.
|
|
21
|
+
*/
|
|
22
|
+
deleteKeys(keys: string[], options?: WiredRequestOptions): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns list of all keys presented in CloudStorage.
|
|
25
|
+
* @param options - request execution options.
|
|
26
|
+
*/
|
|
27
|
+
getKeys(options?: WiredRequestOptions): Promise<string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns map, where key is one of the specified in keys argument, and value is according
|
|
30
|
+
* storage value.
|
|
31
|
+
* @param keys - keys list.
|
|
32
|
+
* @param options - request execution options.
|
|
33
|
+
*/
|
|
34
|
+
getValues<K extends string>(keys: K[], options?: WiredRequestOptions): Promise<Record<K, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Saves specified value by key.
|
|
37
|
+
* @param key - storage key.
|
|
38
|
+
* @param value - storage value.
|
|
39
|
+
* @param options - request execution options.
|
|
40
|
+
*/
|
|
41
|
+
saveValue(key: string, value: string, options?: WiredRequestOptions): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if specified method is supported by current component.
|
|
44
|
+
*/
|
|
45
|
+
supports: SupportsFunc<'deleteKeys' | 'getKeys' | 'getValues' | 'saveValue'>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CloudStorage.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Version } from '@tma.js/utils';
|
|
2
|
+
import { type PostEvent, type ImpactHapticFeedbackStyle, type NotificationHapticFeedbackType } from '@tma.js/bridge';
|
|
3
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
4
|
+
/**
|
|
5
|
+
* Class which controls haptic feedback. It allows calling different types of
|
|
6
|
+
* haptic notifications which usually occur after user interaction with
|
|
7
|
+
* application.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HapticFeedback {
|
|
10
|
+
private readonly postEvent;
|
|
11
|
+
constructor(version: Version, postEvent?: PostEvent);
|
|
12
|
+
/**
|
|
13
|
+
* A method tells that an impact occurred. The Telegram app may play the
|
|
14
|
+
* appropriate haptics based on style value passed.
|
|
15
|
+
* @param style - impact style.
|
|
16
|
+
*/
|
|
17
|
+
impactOccurred(style: ImpactHapticFeedbackStyle): void;
|
|
18
|
+
/**
|
|
19
|
+
* A method tells that a task or action has succeeded, failed, or produced
|
|
20
|
+
* a warning. The Telegram app may play the appropriate haptics based on
|
|
21
|
+
* type value passed.
|
|
22
|
+
* @param type - notification type.
|
|
23
|
+
*/
|
|
24
|
+
notificationOccurred(type: NotificationHapticFeedbackType): void;
|
|
25
|
+
/**
|
|
26
|
+
* A method tells that the user has changed a selection. The Telegram app
|
|
27
|
+
* may play the appropriate haptics.
|
|
28
|
+
*
|
|
29
|
+
* Do not use this feedback when the user makes or confirms a selection;
|
|
30
|
+
* use it only when the selection changes.
|
|
31
|
+
*/
|
|
32
|
+
selectionChanged(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if specified method is supported by current component.
|
|
35
|
+
*/
|
|
36
|
+
supports: SupportsFunc<'impactOccurred' | 'notificationOccurred' | 'selectionChanged'>;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HapticFeedback.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Chat, InitData as InitDataType, User } from '@tma.js/init-data';
|
|
2
|
+
/**
|
|
3
|
+
* Class which is responsible for displaying Web Apps init data.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InitData {
|
|
6
|
+
private readonly state;
|
|
7
|
+
constructor(authDate: Date, hash: string, options?: Omit<InitDataType, 'authDate' | 'hash'>);
|
|
8
|
+
/**
|
|
9
|
+
* Init data generation date.
|
|
10
|
+
*/
|
|
11
|
+
get authDate(): Date;
|
|
12
|
+
/**
|
|
13
|
+
* Date after which a message can be sent via the answerWebAppQuery
|
|
14
|
+
* method.
|
|
15
|
+
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
16
|
+
*/
|
|
17
|
+
get canSendAfter(): Date | null;
|
|
18
|
+
/**
|
|
19
|
+
* An object containing data about the chat where the bot was
|
|
20
|
+
* launched via the attachment menu. Returned for supergroups, channels and
|
|
21
|
+
* group chats – only for Web Apps launched via the attachment menu.
|
|
22
|
+
*/
|
|
23
|
+
get chat(): Chat | null;
|
|
24
|
+
/**
|
|
25
|
+
* A hash of all passed parameters, which the bot server can use to
|
|
26
|
+
* check their validity.
|
|
27
|
+
* @see https://core.telegram.org/bots/webapps#validating-data-received-via-the-web-app
|
|
28
|
+
*/
|
|
29
|
+
get hash(): string;
|
|
30
|
+
/**
|
|
31
|
+
* A unique identifier for the Web App session, required for sending
|
|
32
|
+
* messages via the `answerWebAppQuery` method.
|
|
33
|
+
* @see https://core.telegram.org/bots/api#answerwebappquery
|
|
34
|
+
*/
|
|
35
|
+
get queryId(): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* An object containing data about the chat partner of the current
|
|
38
|
+
* user in the chat where the bot was launched via the attachment menu.
|
|
39
|
+
* Returned only for private chats and only for Web Apps launched
|
|
40
|
+
* via the attachment menu.
|
|
41
|
+
*/
|
|
42
|
+
get receiver(): User | null;
|
|
43
|
+
/**
|
|
44
|
+
* The value of the `startattach` parameter, passed via link. Only
|
|
45
|
+
* returned for Web Apps when launched from the attachment menu via link.
|
|
46
|
+
*/
|
|
47
|
+
get startParam(): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* An object containing data about the current user.
|
|
50
|
+
*/
|
|
51
|
+
get user(): User | null;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './InitData.js';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import type { RGB } from '@tma.js/colors';
|
|
3
|
+
/**
|
|
4
|
+
* Controls the main button, which is displayed at the bottom
|
|
5
|
+
* of the Web App in the Telegram interface.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MainButton {
|
|
8
|
+
private readonly postEvent;
|
|
9
|
+
private readonly ee;
|
|
10
|
+
private readonly state;
|
|
11
|
+
constructor(backgroundColor: RGB, isEnabled: boolean, isVisible: boolean, isProgressVisible: boolean, text: string, textColor: RGB, postEvent?: PostEvent);
|
|
12
|
+
private set isEnabled(value);
|
|
13
|
+
/**
|
|
14
|
+
* Returns true in case, MainButton is currently enabled.
|
|
15
|
+
*/
|
|
16
|
+
get isEnabled(): boolean;
|
|
17
|
+
private set isProgressVisible(value);
|
|
18
|
+
/**
|
|
19
|
+
* Returns true in case, MainButton loading progress is currently visible.
|
|
20
|
+
*/
|
|
21
|
+
get isProgressVisible(): boolean;
|
|
22
|
+
private set isVisible(value);
|
|
23
|
+
/**
|
|
24
|
+
* Returns true in case, MainButton is currently visible.
|
|
25
|
+
*/
|
|
26
|
+
get isVisible(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Sends current local button state to Telegram application.
|
|
29
|
+
*/
|
|
30
|
+
private commit;
|
|
31
|
+
/**
|
|
32
|
+
* Returns current main button background color.
|
|
33
|
+
*/
|
|
34
|
+
get backgroundColor(): RGB;
|
|
35
|
+
/**
|
|
36
|
+
* Returns current main button text.
|
|
37
|
+
*/
|
|
38
|
+
get text(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns current main button text color.
|
|
41
|
+
*/
|
|
42
|
+
get textColor(): RGB;
|
|
43
|
+
/**
|
|
44
|
+
* Disables button. Returns current button instance for chaining.
|
|
45
|
+
*/
|
|
46
|
+
disable(): this;
|
|
47
|
+
/**
|
|
48
|
+
* Enables button. Returns current button instance for chaining.
|
|
49
|
+
*/
|
|
50
|
+
enable(): this;
|
|
51
|
+
/**
|
|
52
|
+
* Hides button. Returns current button instance for chaining.
|
|
53
|
+
*/
|
|
54
|
+
hide(): this;
|
|
55
|
+
/**
|
|
56
|
+
* Hides button progress. Returns current button instance for chaining.
|
|
57
|
+
*/
|
|
58
|
+
hideProgress(): this;
|
|
59
|
+
/**
|
|
60
|
+
* Adds new event listener.
|
|
61
|
+
* FIXME: Event 'main_button_pressed' is still being received on Android
|
|
62
|
+
* even if the main button is disabled.
|
|
63
|
+
* Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/3
|
|
64
|
+
* @param event - event name.
|
|
65
|
+
* @param listener - event listener.
|
|
66
|
+
*/
|
|
67
|
+
on: typeof this.ee.on;
|
|
68
|
+
/**
|
|
69
|
+
* Removes event listener.
|
|
70
|
+
* @param event - event name.
|
|
71
|
+
* @param listener - event listener.
|
|
72
|
+
*/
|
|
73
|
+
off: typeof this.ee.off;
|
|
74
|
+
/**
|
|
75
|
+
* Shows the button. Note that opening the Web App from the attachment
|
|
76
|
+
* menu hides the main button until the user interacts with the Web App
|
|
77
|
+
* interface.
|
|
78
|
+
*
|
|
79
|
+
* Returns current button instance for chaining.
|
|
80
|
+
*/
|
|
81
|
+
show(): this;
|
|
82
|
+
/**
|
|
83
|
+
* A method to show a loading indicator on the button.
|
|
84
|
+
* It is recommended to display loading progress if the action tied to the
|
|
85
|
+
* button may take a long time.
|
|
86
|
+
*
|
|
87
|
+
* Returns current button instance for chaining.
|
|
88
|
+
*/
|
|
89
|
+
showProgress(): this;
|
|
90
|
+
/**
|
|
91
|
+
* Sets new main button text. Returns current button instance for chaining.
|
|
92
|
+
* Minimal length for text is 1 symbol, and maximum is 64 symbols.
|
|
93
|
+
*
|
|
94
|
+
* Returns current button instance for chaining.
|
|
95
|
+
* @param value - new text.
|
|
96
|
+
*/
|
|
97
|
+
setText(value: string): this;
|
|
98
|
+
/**
|
|
99
|
+
* Sets new main button text color. Returns current button instance for
|
|
100
|
+
* chaining.
|
|
101
|
+
*
|
|
102
|
+
* Returns current button instance for chaining.
|
|
103
|
+
* @param value - new text color.
|
|
104
|
+
*/
|
|
105
|
+
setTextColor(value: RGB): this;
|
|
106
|
+
/**
|
|
107
|
+
* Updates current button color. Returns current button instance for
|
|
108
|
+
* chaining.
|
|
109
|
+
*
|
|
110
|
+
* Returns current button instance for chaining.
|
|
111
|
+
* @param value - color to set.
|
|
112
|
+
*/
|
|
113
|
+
setBackgroundColor(value: RGB): this;
|
|
114
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RGB } from '@tma.js/colors';
|
|
2
|
+
import type { StateEvents } from '../../state/index.js';
|
|
3
|
+
export interface MainButtonState {
|
|
4
|
+
backgroundColor: RGB;
|
|
5
|
+
isEnabled: boolean;
|
|
6
|
+
isVisible: boolean;
|
|
7
|
+
isProgressVisible: boolean;
|
|
8
|
+
text: string;
|
|
9
|
+
textColor: RGB;
|
|
10
|
+
}
|
|
11
|
+
export interface MainButtonEvents extends StateEvents<MainButtonState> {
|
|
12
|
+
click: () => void;
|
|
13
|
+
}
|
|
14
|
+
export type MainButtonEventName = keyof MainButtonEvents;
|
|
15
|
+
export type MainButtonEventListener<E extends MainButtonEventName> = MainButtonEvents[E];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import type { Version } from '@tma.js/utils';
|
|
3
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
4
|
+
import type { PopupParams } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Controls currently displayed application popup. It allows developers to
|
|
7
|
+
* open new custom popups and detect popup-connected events.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Popup {
|
|
10
|
+
private readonly postEvent;
|
|
11
|
+
private readonly ee;
|
|
12
|
+
private readonly state;
|
|
13
|
+
constructor(version: Version, postEvent?: PostEvent);
|
|
14
|
+
/**
|
|
15
|
+
* Shows whether popup is currently opened.
|
|
16
|
+
*/
|
|
17
|
+
get isOpened(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Adds new event listener.
|
|
20
|
+
*/
|
|
21
|
+
on: typeof this.ee.on;
|
|
22
|
+
/**
|
|
23
|
+
* Removes event listener.
|
|
24
|
+
*/
|
|
25
|
+
off: typeof this.ee.off;
|
|
26
|
+
/**
|
|
27
|
+
* A method that shows a native popup described by the `params` argument.
|
|
28
|
+
* Promise will be resolved when popup is closed. Resolved value will have
|
|
29
|
+
* an identifier of pressed button.
|
|
30
|
+
*
|
|
31
|
+
* In case, user clicked outside the popup or clicked top right popup close
|
|
32
|
+
* button, null will be returned.
|
|
33
|
+
*
|
|
34
|
+
* FIXME: In desktop, this function may work incorrectly.
|
|
35
|
+
* Issue: https://github.com/Telegram-Mini-Apps/tma.js/issues/7
|
|
36
|
+
* @param params - popup parameters.
|
|
37
|
+
* @throws {Error} Popup is already opened.
|
|
38
|
+
*/
|
|
39
|
+
open(params: PopupParams): Promise<string | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if specified method is supported by current component.
|
|
42
|
+
*/
|
|
43
|
+
supports: SupportsFunc<'open'>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { StateEvents } from '../../state/index.js';
|
|
2
|
+
export interface PopupState {
|
|
3
|
+
isOpened: boolean;
|
|
4
|
+
}
|
|
5
|
+
export type PopupEvents = StateEvents<PopupState>;
|
|
6
|
+
export type PopupEventName = keyof PopupEvents;
|
|
7
|
+
export type PopupEventListener<E extends PopupEventName> = PopupEvents[E];
|
|
8
|
+
/**
|
|
9
|
+
* This object describes the native popup.
|
|
10
|
+
* @see https://core.telegram.org/bots/webapps#popupparams
|
|
11
|
+
*/
|
|
12
|
+
export interface PopupParams {
|
|
13
|
+
/**
|
|
14
|
+
* The text to be displayed in the popup title, 0-64 characters.
|
|
15
|
+
* @default ""
|
|
16
|
+
*/
|
|
17
|
+
title?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The message to be displayed in the body of the popup, 1-256 characters.
|
|
20
|
+
*/
|
|
21
|
+
message: string;
|
|
22
|
+
/**
|
|
23
|
+
* List of buttons to be displayed in the popup, 1-3 buttons.
|
|
24
|
+
* @default [{type: 'close'}]
|
|
25
|
+
*/
|
|
26
|
+
buttons?: PopupButton[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* This object describes the native popup button.
|
|
30
|
+
* @see https://core.telegram.org/bots/webapps#popupbutton
|
|
31
|
+
*/
|
|
32
|
+
export type PopupButton = {
|
|
33
|
+
/**
|
|
34
|
+
* Identifier of the button, 0-64 characters.
|
|
35
|
+
* @default ""
|
|
36
|
+
*/
|
|
37
|
+
id?: string;
|
|
38
|
+
} & ({
|
|
39
|
+
/**
|
|
40
|
+
* Type of the button:
|
|
41
|
+
* - `default`, a button with the default style;
|
|
42
|
+
* - `destructive`, a button with a style that indicates a destructive
|
|
43
|
+
* action (e.g. "Remove", "Delete", etc.).
|
|
44
|
+
*
|
|
45
|
+
* @default "default"
|
|
46
|
+
*/
|
|
47
|
+
type?: 'default' | 'destructive';
|
|
48
|
+
/**
|
|
49
|
+
* The text to be displayed on the button, 0-64 characters.
|
|
50
|
+
*/
|
|
51
|
+
text: string;
|
|
52
|
+
} | {
|
|
53
|
+
/**
|
|
54
|
+
* Type of the button:
|
|
55
|
+
* - `ok`, a button with the localized text "OK";
|
|
56
|
+
* - `close`, a button with the localized text "Close";
|
|
57
|
+
* - `cancel`, a button with the localized text "Cancel".
|
|
58
|
+
*/
|
|
59
|
+
type: 'ok' | 'close' | 'cancel';
|
|
60
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PopupParams as BridgePopupParams } from '@tma.js/bridge';
|
|
2
|
+
import type { PopupParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Prepares popup parameters before sending them to native app.
|
|
5
|
+
* @param params - popup parameters.
|
|
6
|
+
*/
|
|
7
|
+
export declare function preparePopupParams(params: PopupParams): BridgePopupParams;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type PostEvent } from '@tma.js/bridge';
|
|
2
|
+
import type { Version } from '@tma.js/utils';
|
|
3
|
+
import { type SupportsFunc } from '../../supports.js';
|
|
4
|
+
/**
|
|
5
|
+
* Provides QR scanner functionality.
|
|
6
|
+
*/
|
|
7
|
+
export declare class QRScanner {
|
|
8
|
+
private readonly postEvent;
|
|
9
|
+
private readonly ee;
|
|
10
|
+
private readonly state;
|
|
11
|
+
constructor(version: Version, postEvent?: PostEvent);
|
|
12
|
+
/**
|
|
13
|
+
* Closes scanner.
|
|
14
|
+
*/
|
|
15
|
+
close(): void;
|
|
16
|
+
private set isOpened(value);
|
|
17
|
+
/**
|
|
18
|
+
* Returns true in case, QR scanner is currently opened.
|
|
19
|
+
*/
|
|
20
|
+
get isOpened(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Opens scanner with specified title shown to user. Method returns promise
|
|
23
|
+
* with scanned QR content in case, it was scanned. It will contain null in
|
|
24
|
+
* case, scanner was closed.
|
|
25
|
+
* @param text - title to display.
|
|
26
|
+
*/
|
|
27
|
+
open(text?: string): Promise<string | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Adds new event listener.
|
|
30
|
+
*/
|
|
31
|
+
on: typeof this.ee.on;
|
|
32
|
+
/**
|
|
33
|
+
* Removes event listener.
|
|
34
|
+
*/
|
|
35
|
+
off: typeof this.ee.off;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if specified method is supported by current component.
|
|
38
|
+
*/
|
|
39
|
+
supports: SupportsFunc<'open' | 'close'>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StateEvents } from '../../state/index.js';
|
|
2
|
+
export interface QRScannerState {
|
|
3
|
+
isOpened: boolean;
|
|
4
|
+
}
|
|
5
|
+
export type QRScannerEvents = StateEvents<QRScannerState>;
|
|
6
|
+
export type QRScannerEventName = keyof QRScannerEvents;
|
|
7
|
+
export type QRScannerEventListener<E extends QRScannerEventName> = QRScannerEvents[E];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type RequestOptions } from '@tma.js/bridge';
|
|
2
|
+
import type { RGB } from '@tma.js/colors';
|
|
3
|
+
import { type ThemeParamsType } from '../../theme-params.js';
|
|
4
|
+
import type { ThemeParamsEvents } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Contains information about currently used theme by application.
|
|
7
|
+
* @see https://core.telegram.org/bots/webapps#themeparams
|
|
8
|
+
*/
|
|
9
|
+
export declare class ThemeParams {
|
|
10
|
+
/**
|
|
11
|
+
* Requests fresh information about current theme.
|
|
12
|
+
* FIXME: Be careful using this function in desktop version of Telegram as
|
|
13
|
+
* long as method web_app_request_theme does not work on `macos` platform.
|
|
14
|
+
* @param options - method options.
|
|
15
|
+
*/
|
|
16
|
+
static request(options?: RequestOptions): Promise<ThemeParamsType>;
|
|
17
|
+
/**
|
|
18
|
+
* Synchronizes specified instance of ThemeParams with the actual value in the native
|
|
19
|
+
* application.
|
|
20
|
+
* @param themeParams - ThemeParams instance.
|
|
21
|
+
*/
|
|
22
|
+
static sync(themeParams: ThemeParams): void;
|
|
23
|
+
/**
|
|
24
|
+
* Returns instance of ThemeParams which is synchronized with external
|
|
25
|
+
* environment.
|
|
26
|
+
* @param options - method options.
|
|
27
|
+
*/
|
|
28
|
+
static synced(options?: RequestOptions): Promise<ThemeParams>;
|
|
29
|
+
private readonly ee;
|
|
30
|
+
private readonly state;
|
|
31
|
+
constructor(params: ThemeParamsType);
|
|
32
|
+
/**
|
|
33
|
+
* Returns background color.
|
|
34
|
+
*/
|
|
35
|
+
get backgroundColor(): RGB | null;
|
|
36
|
+
/**
|
|
37
|
+
* Returns button color.
|
|
38
|
+
*/
|
|
39
|
+
get buttonColor(): RGB | null;
|
|
40
|
+
/**
|
|
41
|
+
* Returns button text color.
|
|
42
|
+
*/
|
|
43
|
+
get buttonTextColor(): RGB | null;
|
|
44
|
+
/**
|
|
45
|
+
* Returns hint color.
|
|
46
|
+
*/
|
|
47
|
+
get hintColor(): RGB | null;
|
|
48
|
+
/**
|
|
49
|
+
* Returns true in case, current color scheme is recognized as dark. This
|
|
50
|
+
* value is calculated according to theme background color.
|
|
51
|
+
*/
|
|
52
|
+
get isDark(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns current link color.
|
|
55
|
+
*/
|
|
56
|
+
get linkColor(): RGB | null;
|
|
57
|
+
/**
|
|
58
|
+
* Adds new event listener.
|
|
59
|
+
*/
|
|
60
|
+
on: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Removes event listener.
|
|
63
|
+
*/
|
|
64
|
+
off: <E extends "changed" | "backgroundColorChanged" | "textColorChanged" | "buttonColorChanged" | "buttonTextColorChanged" | "hintColorChanged" | "linkColorChanged" | "secondaryBackgroundColorChanged">(event: E, listener: import("@tma.js/event-emitter").EventListener<ThemeParamsEvents[E]>) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Returns secondary background color.
|
|
67
|
+
*/
|
|
68
|
+
get secondaryBackgroundColor(): RGB | null;
|
|
69
|
+
/**
|
|
70
|
+
* Returns text color.
|
|
71
|
+
*/
|
|
72
|
+
get textColor(): RGB | null;
|
|
73
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HasUndefined, If } from '@tma.js/util-types';
|
|
2
|
+
import type { ThemeParamsType } from '../../theme-params.js';
|
|
3
|
+
import type { StateEvents } from '../../state/index.js';
|
|
4
|
+
export type ThemeParamsState = {
|
|
5
|
+
[K in keyof ThemeParamsType]-?: If<HasUndefined<ThemeParamsType[K]>, Exclude<ThemeParamsType[K], undefined> | null, ThemeParamsType[K]>;
|
|
6
|
+
};
|
|
7
|
+
export type ThemeParamsEvents = StateEvents<ThemeParamsState>;
|
|
8
|
+
export type ThemeParamsEventName = keyof ThemeParamsEvents;
|
|
9
|
+
export type ThemeParamsEventListener<E extends ThemeParamsEventName> = ThemeParamsEvents[E];
|