@vbotma/sdk 3.1.8
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 +64 -0
- package/dist/dts/composables/AsyncMountable.d.ts +44 -0
- package/dist/dts/composables/Button.d.ts +140 -0
- package/dist/dts/composables/Mountable.d.ts +43 -0
- package/dist/dts/composables/Stateful.d.ts +35 -0
- package/dist/dts/errors.d.ts +51 -0
- package/dist/dts/features/BackButton/BackButton.d.ts +96 -0
- package/dist/dts/features/BackButton/exports.d.ts +2 -0
- package/dist/dts/features/BackButton/instance.d.ts +2 -0
- package/dist/dts/features/Biometry/Biometry.d.ts +121 -0
- package/dist/dts/features/Biometry/exports.d.ts +3 -0
- package/dist/dts/features/Biometry/instance.d.ts +2 -0
- package/dist/dts/features/Biometry/types.d.ts +84 -0
- package/dist/dts/features/ClosingBehavior/ClosingBehavior.d.ts +51 -0
- package/dist/dts/features/ClosingBehavior/exports.d.ts +2 -0
- package/dist/dts/features/ClosingBehavior/instance.d.ts +2 -0
- package/dist/dts/features/CloudStorage/CloudStorage.d.ts +90 -0
- package/dist/dts/features/CloudStorage/exports.d.ts +2 -0
- package/dist/dts/features/CloudStorage/instance.d.ts +2 -0
- package/dist/dts/features/DeviceStorage/DeviceStorage.d.ts +53 -0
- package/dist/dts/features/DeviceStorage/exports.d.ts +2 -0
- package/dist/dts/features/DeviceStorage/instance.d.ts +2 -0
- package/dist/dts/features/HapticFeedback/HapticFeedback.d.ts +57 -0
- package/dist/dts/features/HapticFeedback/exports.d.ts +2 -0
- package/dist/dts/features/HapticFeedback/instance.d.ts +2 -0
- package/dist/dts/features/InitData/InitData.d.ts +87 -0
- package/dist/dts/features/InitData/exports.d.ts +2 -0
- package/dist/dts/features/InitData/instance.d.ts +2 -0
- package/dist/dts/features/Invoice/Invoice.d.ts +54 -0
- package/dist/dts/features/Invoice/exports.d.ts +2 -0
- package/dist/dts/features/Invoice/instance.d.ts +2 -0
- package/dist/dts/features/LocationManager/LocationManager.d.ts +73 -0
- package/dist/dts/features/LocationManager/exports.d.ts +3 -0
- package/dist/dts/features/LocationManager/instance.d.ts +2 -0
- package/dist/dts/features/LocationManager/types.d.ts +65 -0
- package/dist/dts/features/MainButton/MainButton.d.ts +214 -0
- package/dist/dts/features/MainButton/exports.d.ts +2 -0
- package/dist/dts/features/MainButton/instance.d.ts +2 -0
- package/dist/dts/features/MiniApp/MiniApp.d.ts +192 -0
- package/dist/dts/features/MiniApp/exports.d.ts +2 -0
- package/dist/dts/features/MiniApp/instance.d.ts +2 -0
- package/dist/dts/features/Notification/Notification.d.ts +21 -0
- package/dist/dts/features/Notification/exports.d.ts +3 -0
- package/dist/dts/features/Notification/instance.d.ts +2 -0
- package/dist/dts/features/Notification/types.d.ts +19 -0
- package/dist/dts/features/Popup/Popup.d.ts +56 -0
- package/dist/dts/features/Popup/exports.d.ts +3 -0
- package/dist/dts/features/Popup/instance.d.ts +2 -0
- package/dist/dts/features/Popup/prepareParams.d.ts +9 -0
- package/dist/dts/features/Popup/types.d.ts +54 -0
- package/dist/dts/features/QrScanner/QrScanner.d.ts +131 -0
- package/dist/dts/features/QrScanner/exports.d.ts +2 -0
- package/dist/dts/features/QrScanner/instance.d.ts +2 -0
- package/dist/dts/features/Refresh/Refresh.d.ts +39 -0
- package/dist/dts/features/Refresh/exports.d.ts +3 -0
- package/dist/dts/features/Refresh/instance.d.ts +2 -0
- package/dist/dts/features/Refresh/types.d.ts +7 -0
- package/dist/dts/features/SecondaryButton/SecondaryButton.d.ts +253 -0
- package/dist/dts/features/SecondaryButton/exports.d.ts +2 -0
- package/dist/dts/features/SecondaryButton/instance.d.ts +2 -0
- package/dist/dts/features/SecureStorage/SecureStorage.d.ts +68 -0
- package/dist/dts/features/SecureStorage/exports.d.ts +2 -0
- package/dist/dts/features/SecureStorage/instance.d.ts +2 -0
- package/dist/dts/features/SettingsButton/SettingsButton.d.ts +96 -0
- package/dist/dts/features/SettingsButton/exports.d.ts +2 -0
- package/dist/dts/features/SettingsButton/instance.d.ts +2 -0
- package/dist/dts/features/StoragePermission/StoragePermission.d.ts +45 -0
- package/dist/dts/features/StoragePermission/exports.d.ts +3 -0
- package/dist/dts/features/StoragePermission/instance.d.ts +2 -0
- package/dist/dts/features/StoragePermission/types.d.ts +51 -0
- package/dist/dts/features/SwipeBehavior/SwipeBehavior.d.ts +62 -0
- package/dist/dts/features/SwipeBehavior/exports.d.ts +2 -0
- package/dist/dts/features/SwipeBehavior/instance.d.ts +2 -0
- package/dist/dts/features/ThemeParams/ThemeParams.d.ts +127 -0
- package/dist/dts/features/ThemeParams/exports.d.ts +2 -0
- package/dist/dts/features/ThemeParams/instance.d.ts +2 -0
- package/dist/dts/features/Viewport/Viewport.d.ts +219 -0
- package/dist/dts/features/Viewport/exports.d.ts +2 -0
- package/dist/dts/features/Viewport/instance.d.ts +2 -0
- package/dist/dts/features/emoji-status/exports.d.ts +2 -0
- package/dist/dts/features/emoji-status/requestEmojiStatusAccess.d.ts +16 -0
- package/dist/dts/features/emoji-status/setEmojiStatus.d.ts +28 -0
- package/dist/dts/features/home-screen/addToHomeScreen.d.ts +11 -0
- package/dist/dts/features/home-screen/checkHomeScreenStatus.d.ts +14 -0
- package/dist/dts/features/home-screen/exports.d.ts +2 -0
- package/dist/dts/features/links/exports.d.ts +3 -0
- package/dist/dts/features/links/openLink.d.ts +31 -0
- package/dist/dts/features/links/openTelegramLink.d.ts +18 -0
- package/dist/dts/features/links/shareURL.d.ts +18 -0
- package/dist/dts/features/privacy/exports.d.ts +3 -0
- package/dist/dts/features/privacy/requestContact.d.ts +59 -0
- package/dist/dts/features/privacy/requestPhoneAccess.d.ts +19 -0
- package/dist/dts/features/privacy/requestWriteAccess.d.ts +14 -0
- package/dist/dts/features/uncategorized/copyTextToClipboard.d.ts +5 -0
- package/dist/dts/features/uncategorized/downloadFile.d.ts +21 -0
- package/dist/dts/features/uncategorized/exports.d.ts +11 -0
- package/dist/dts/features/uncategorized/getCurrentTime.d.ts +15 -0
- package/dist/dts/features/uncategorized/hideKeyboard.d.ts +13 -0
- package/dist/dts/features/uncategorized/readTextFromClipboard.d.ts +13 -0
- package/dist/dts/features/uncategorized/retrieveAndroidDeviceData.d.ts +6 -0
- package/dist/dts/features/uncategorized/retrieveAndroidDeviceDataFrom.d.ts +14 -0
- package/dist/dts/features/uncategorized/sendData.d.ts +20 -0
- package/dist/dts/features/uncategorized/shareMessage.d.ts +14 -0
- package/dist/dts/features/uncategorized/shareStory.d.ts +50 -0
- package/dist/dts/features/uncategorized/switchInlineQuery.d.ts +28 -0
- package/dist/dts/fn-options/bottomButtonOptions.d.ts +11 -0
- package/dist/dts/fn-options/buttonOptions.d.ts +10 -0
- package/dist/dts/fn-options/createFnOption.d.ts +2 -0
- package/dist/dts/fn-options/sharedFeatureOptions.d.ts +8 -0
- package/dist/dts/fn-options/withCreateRequestId.d.ts +7 -0
- package/dist/dts/fn-options/withInvokeCustomMethod.d.ts +11 -0
- package/dist/dts/fn-options/withPostEvent.d.ts +8 -0
- package/dist/dts/fn-options/withRequest.d.ts +8 -0
- package/dist/dts/fn-options/withStateRestore.d.ts +13 -0
- package/dist/dts/fn-options/withVersion.d.ts +9 -0
- package/dist/dts/globals/createRequestId.d.ts +4 -0
- package/dist/dts/globals/invokeCustomMethod.d.ts +16 -0
- package/dist/dts/globals/isInlineMode.d.ts +4 -0
- package/dist/dts/globals/postEvent.d.ts +4 -0
- package/dist/dts/globals/request.d.ts +13 -0
- package/dist/dts/globals/resetGlobals.d.ts +4 -0
- package/dist/dts/globals/signals-registry.d.ts +39 -0
- package/dist/dts/globals/themeParams.d.ts +4 -0
- package/dist/dts/globals/version.d.ts +4 -0
- package/dist/dts/helpers/access.d.ts +2 -0
- package/dist/dts/helpers/component-storage.d.ts +9 -0
- package/dist/dts/helpers/createIsSupportedSignal.d.ts +5 -0
- package/dist/dts/helpers/css-vars.d.ts +11 -0
- package/dist/dts/helpers/isColorDark.d.ts +11 -0
- package/dist/dts/helpers/navigation.d.ts +5 -0
- package/dist/dts/helpers/removeUndefined.d.ts +10 -0
- package/dist/dts/helpers/shallowEqual.d.ts +1 -0
- package/dist/dts/index.d.ts +38 -0
- package/dist/dts/init.d.ts +42 -0
- package/dist/dts/types.d.ts +6 -0
- package/dist/dts/with-checks/throwifyWithChecksFp.d.ts +3 -0
- package/dist/dts/with-checks/withChecksFp.d.ts +170 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.iife.js +4 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.js +4088 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Maybe } from '@vbotma/toolkit';
|
|
2
|
+
import { SharedFeatureOptions } from '../../fn-options/sharedFeatureOptions.js';
|
|
3
|
+
import { WithPostEvent } from '../../fn-options/withPostEvent.js';
|
|
4
|
+
import { WithRequest } from '../../fn-options/withRequest.js';
|
|
5
|
+
import { WithStateRestore } from '../../fn-options/withStateRestore.js';
|
|
6
|
+
import { WithVersion } from '../../fn-options/withVersion.js';
|
|
7
|
+
export interface LocationManagerRequestLocationResponse {
|
|
8
|
+
/**
|
|
9
|
+
* Latitude in degrees.
|
|
10
|
+
*/
|
|
11
|
+
latitude: number;
|
|
12
|
+
/**
|
|
13
|
+
* Longitude in degrees.
|
|
14
|
+
*/
|
|
15
|
+
longitude: number;
|
|
16
|
+
/**
|
|
17
|
+
* Altitude above sea level in meters.
|
|
18
|
+
*/
|
|
19
|
+
altitude?: Maybe<number>;
|
|
20
|
+
/**
|
|
21
|
+
* The direction the device is moving in degrees.
|
|
22
|
+
*/
|
|
23
|
+
course?: Maybe<number>;
|
|
24
|
+
/**
|
|
25
|
+
* The speed of the device in m/s.
|
|
26
|
+
*/
|
|
27
|
+
speed?: Maybe<number>;
|
|
28
|
+
/**
|
|
29
|
+
* Accuracy of the latitude and longitude values in meters.
|
|
30
|
+
*/
|
|
31
|
+
horizontal_accuracy?: Maybe<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Accuracy of the altitude value in meters.
|
|
34
|
+
*/
|
|
35
|
+
vertical_accuracy?: Maybe<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Accuracy of the course value in degrees.
|
|
38
|
+
*/
|
|
39
|
+
course_accuracy?: Maybe<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Accuracy of the speed value in m/s.
|
|
42
|
+
*/
|
|
43
|
+
speed_accuracy?: Maybe<number>;
|
|
44
|
+
}
|
|
45
|
+
export interface LocationManagerState {
|
|
46
|
+
/**
|
|
47
|
+
* If true, indicates that location data tracking is available on the current device.
|
|
48
|
+
*/
|
|
49
|
+
available: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Indicates whether the app has previously requested permission to track location data.
|
|
52
|
+
*/
|
|
53
|
+
accessRequested: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Indicates whether the user has granted the app permission to track location data.
|
|
56
|
+
*
|
|
57
|
+
* If false and `accessRequested` is true may indicate that:
|
|
58
|
+
*
|
|
59
|
+
* - The user has simply canceled the permission popup.
|
|
60
|
+
* - The user has denied the app permission to track location data.
|
|
61
|
+
*/
|
|
62
|
+
accessGranted: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface LocationManagerOptions extends WithStateRestore<LocationManagerState>, WithRequest, WithVersion, WithPostEvent, SharedFeatureOptions {
|
|
65
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { PostEventError } from '@vbotma/bridge';
|
|
2
|
+
import { Computed } from '@vbotma/signals';
|
|
3
|
+
import { RGB } from '@vbotma/types';
|
|
4
|
+
import { either as E } from 'fp-ts';
|
|
5
|
+
import { ButtonOptions } from '../../composables/Button.js';
|
|
6
|
+
import { MaybeAccessor } from '../../types.js';
|
|
7
|
+
import { WithChecks, WithChecksFp } from '../../with-checks/withChecksFp.js';
|
|
8
|
+
type MainButtonEither = E.Either<PostEventError, void>;
|
|
9
|
+
export interface MainButtonState {
|
|
10
|
+
isVisible: boolean;
|
|
11
|
+
bgColor?: RGB;
|
|
12
|
+
hasShineEffect: boolean;
|
|
13
|
+
isEnabled: boolean;
|
|
14
|
+
isLoaderVisible: boolean;
|
|
15
|
+
text: string;
|
|
16
|
+
textColor?: RGB;
|
|
17
|
+
}
|
|
18
|
+
export interface MainButtonOptions extends Omit<ButtonOptions<MainButtonState, 'web_app_setup_main_button'>, 'initialState' | 'method' | 'payload' | 'version'> {
|
|
19
|
+
/**
|
|
20
|
+
* Default values for different kinds of the button properties.
|
|
21
|
+
*/
|
|
22
|
+
defaults: {
|
|
23
|
+
bgColor: MaybeAccessor<RGB>;
|
|
24
|
+
textColor: MaybeAccessor<RGB>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare class MainButton {
|
|
28
|
+
constructor({ defaults, ...options }: MainButtonOptions);
|
|
29
|
+
/**
|
|
30
|
+
* The button background color.
|
|
31
|
+
*/
|
|
32
|
+
readonly bgColor: Computed<RGB>;
|
|
33
|
+
/**
|
|
34
|
+
* True if the button has a shining effect.
|
|
35
|
+
*/
|
|
36
|
+
readonly hasShineEffect: Computed<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* True if the button is clickable.
|
|
39
|
+
*/
|
|
40
|
+
readonly isEnabled: Computed<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* True if the button loader is visible.
|
|
43
|
+
*/
|
|
44
|
+
readonly isLoaderVisible: Computed<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* True if the button is visible.
|
|
47
|
+
*/
|
|
48
|
+
readonly isVisible: Computed<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Signal indicating if the component is currently mounted.
|
|
51
|
+
*/
|
|
52
|
+
readonly isMounted: Computed<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* The complete button state.
|
|
55
|
+
*/
|
|
56
|
+
readonly state: Computed<MainButtonState>;
|
|
57
|
+
/**
|
|
58
|
+
* The button displayed text.
|
|
59
|
+
*/
|
|
60
|
+
readonly text: Computed<string>;
|
|
61
|
+
/**
|
|
62
|
+
* The button text color.
|
|
63
|
+
*
|
|
64
|
+
* Note that this value is computed based on the external defaults. For
|
|
65
|
+
* example, if not explicitly set, this value may be equal to one of theme
|
|
66
|
+
* params colors.
|
|
67
|
+
*/
|
|
68
|
+
readonly textColor: Computed<RGB>;
|
|
69
|
+
/**
|
|
70
|
+
* Shows the button.
|
|
71
|
+
*/
|
|
72
|
+
readonly showFp: WithChecksFp<() => MainButtonEither, false>;
|
|
73
|
+
/**
|
|
74
|
+
* @see showFp
|
|
75
|
+
*/
|
|
76
|
+
readonly show: WithChecks<() => void, false>;
|
|
77
|
+
/**
|
|
78
|
+
* Hides the button.
|
|
79
|
+
*/
|
|
80
|
+
readonly hideFp: WithChecksFp<() => MainButtonEither, false>;
|
|
81
|
+
/**
|
|
82
|
+
* @see hideFp
|
|
83
|
+
*/
|
|
84
|
+
readonly hide: WithChecks<() => void, false>;
|
|
85
|
+
/**
|
|
86
|
+
* Enables the button.
|
|
87
|
+
*/
|
|
88
|
+
readonly enableFp: WithChecksFp<() => MainButtonEither, false>;
|
|
89
|
+
/**
|
|
90
|
+
* @see enableFp
|
|
91
|
+
*/
|
|
92
|
+
readonly enable: WithChecks<() => void, false>;
|
|
93
|
+
/**
|
|
94
|
+
* Enables the button.
|
|
95
|
+
*/
|
|
96
|
+
readonly enableShineEffectFp: WithChecksFp<() => MainButtonEither, false>;
|
|
97
|
+
/**
|
|
98
|
+
* @see enableShineEffectFp
|
|
99
|
+
*/
|
|
100
|
+
readonly enableShineEffect: WithChecks<() => void, false>;
|
|
101
|
+
/**
|
|
102
|
+
* Disables the button.
|
|
103
|
+
*/
|
|
104
|
+
readonly disableFp: WithChecksFp<() => MainButtonEither, false>;
|
|
105
|
+
/**
|
|
106
|
+
* @see disableFp
|
|
107
|
+
*/
|
|
108
|
+
readonly disable: WithChecks<() => void, false>;
|
|
109
|
+
/**
|
|
110
|
+
* Enables the button.
|
|
111
|
+
*/
|
|
112
|
+
readonly disableShineEffectFp: WithChecksFp<() => MainButtonEither, false>;
|
|
113
|
+
/**
|
|
114
|
+
* @see disableShineEffectFp
|
|
115
|
+
*/
|
|
116
|
+
readonly disableShineEffect: WithChecks<() => void, false>;
|
|
117
|
+
/**
|
|
118
|
+
* Updates the button background color.
|
|
119
|
+
*/
|
|
120
|
+
readonly setBgColorFp: WithChecksFp<(value: RGB) => MainButtonEither, false>;
|
|
121
|
+
/**
|
|
122
|
+
* @see setBgColorFp
|
|
123
|
+
*/
|
|
124
|
+
readonly setBgColor: WithChecks<(value: RGB) => void, false>;
|
|
125
|
+
/**
|
|
126
|
+
* Updates the button text color.
|
|
127
|
+
*/
|
|
128
|
+
readonly setTextColorFp: WithChecksFp<(value: RGB) => MainButtonEither, false>;
|
|
129
|
+
/**
|
|
130
|
+
* @see setTextColorFp
|
|
131
|
+
*/
|
|
132
|
+
readonly setTextColor: WithChecks<(value: RGB) => void, false>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates the button text.
|
|
135
|
+
*/
|
|
136
|
+
readonly setTextFp: WithChecksFp<(value: string) => MainButtonEither, false>;
|
|
137
|
+
/**
|
|
138
|
+
* @see setTextFp
|
|
139
|
+
*/
|
|
140
|
+
readonly setText: WithChecks<(value: string) => void, false>;
|
|
141
|
+
/**
|
|
142
|
+
* Shows the button loader.
|
|
143
|
+
*/
|
|
144
|
+
readonly showLoaderFp: WithChecksFp<() => MainButtonEither, false>;
|
|
145
|
+
/**
|
|
146
|
+
* @see showLoaderFp
|
|
147
|
+
*/
|
|
148
|
+
readonly showLoader: WithChecks<() => void, false>;
|
|
149
|
+
/**
|
|
150
|
+
* Hides the button loader.
|
|
151
|
+
*/
|
|
152
|
+
readonly hideLoaderFp: WithChecksFp<() => MainButtonEither, false>;
|
|
153
|
+
/**
|
|
154
|
+
* @see hideLoaderFp
|
|
155
|
+
*/
|
|
156
|
+
readonly hideLoader: WithChecks<() => void, false>;
|
|
157
|
+
/**
|
|
158
|
+
* Updates the button state.
|
|
159
|
+
* @param state - updates to apply.
|
|
160
|
+
* @example
|
|
161
|
+
* button.setParams({
|
|
162
|
+
* text: 'Submit',
|
|
163
|
+
* isEnabled: true,
|
|
164
|
+
* hasShineEffect: true,
|
|
165
|
+
* });
|
|
166
|
+
*/
|
|
167
|
+
readonly setParamsFp: WithChecksFp<(state: Partial<MainButtonState>) => MainButtonEither, false>;
|
|
168
|
+
readonly setParams: WithChecks<(state: Partial<MainButtonState>) => void, false>;
|
|
169
|
+
/**
|
|
170
|
+
* Mounts the component restoring its state.
|
|
171
|
+
*/
|
|
172
|
+
readonly mountFp: WithChecksFp<() => void, false>;
|
|
173
|
+
/**
|
|
174
|
+
* @see mountFp
|
|
175
|
+
*/
|
|
176
|
+
readonly mount: WithChecks<() => void, false>;
|
|
177
|
+
/**
|
|
178
|
+
* Unmounts the component.
|
|
179
|
+
*/
|
|
180
|
+
readonly unmount: () => void;
|
|
181
|
+
/**
|
|
182
|
+
* Adds a new button listener.
|
|
183
|
+
* @param listener - event listener.
|
|
184
|
+
* @param once - should the listener be called only once.
|
|
185
|
+
* @returns A function to remove bound listener.
|
|
186
|
+
* @example
|
|
187
|
+
* const off = button.onClick(() => {
|
|
188
|
+
* console.log('User clicked the button');
|
|
189
|
+
* off();
|
|
190
|
+
* });
|
|
191
|
+
*/
|
|
192
|
+
readonly onClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => VoidFunction, false>;
|
|
193
|
+
/**
|
|
194
|
+
* @see onClickFp
|
|
195
|
+
*/
|
|
196
|
+
readonly onClick: WithChecks<(listener: VoidFunction, once?: boolean) => VoidFunction, false>;
|
|
197
|
+
/**
|
|
198
|
+
* Removes the button click listener.
|
|
199
|
+
* @param listener - event listener.
|
|
200
|
+
* @param once - should the listener be called only once.
|
|
201
|
+
* @example
|
|
202
|
+
* function listener() {
|
|
203
|
+
* console.log('User clicked the button');
|
|
204
|
+
* button.offClick(listener);
|
|
205
|
+
* }
|
|
206
|
+
* button.onClick(listener);
|
|
207
|
+
*/
|
|
208
|
+
readonly offClickFp: WithChecksFp<(listener: VoidFunction, once?: boolean) => void, false>;
|
|
209
|
+
/**
|
|
210
|
+
* @see offClickFp
|
|
211
|
+
*/
|
|
212
|
+
readonly offClick: WithChecks<(listener: VoidFunction, once?: boolean) => void, false>;
|
|
213
|
+
}
|
|
214
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { PostEventError, EventPayload } from '@vbotma/bridge';
|
|
2
|
+
import { Computed } from '@vbotma/signals';
|
|
3
|
+
import { KnownThemeParamsKey, RGB, ThemeParams } from '@vbotma/types';
|
|
4
|
+
import { either as E } from 'fp-ts';
|
|
5
|
+
import { CSSVarsBoundError, UnknownThemeParamsKeyError } from '../../errors.js';
|
|
6
|
+
import { SharedFeatureOptions } from '../../fn-options/sharedFeatureOptions.js';
|
|
7
|
+
import { WithPostEvent } from '../../fn-options/withPostEvent.js';
|
|
8
|
+
import { WithStateRestore } from '../../fn-options/withStateRestore.js';
|
|
9
|
+
import { WithVersion } from '../../fn-options/withVersion.js';
|
|
10
|
+
import { WithChecks, WithChecksFp } from '../../with-checks/withChecksFp.js';
|
|
11
|
+
type AnyColor = RGB | KnownThemeParamsKey | string;
|
|
12
|
+
export interface MiniAppState {
|
|
13
|
+
bgColor: AnyColor;
|
|
14
|
+
bottomBarColor: AnyColor;
|
|
15
|
+
headerColor: AnyColor;
|
|
16
|
+
isActive: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface MiniAppGetCssVarNameFn {
|
|
19
|
+
/**
|
|
20
|
+
* @param property - mini app property.
|
|
21
|
+
* @returns Computed complete CSS variable name.
|
|
22
|
+
*/
|
|
23
|
+
(property: 'bgColor' | 'bottomBarColor' | 'headerColor'): string;
|
|
24
|
+
}
|
|
25
|
+
type WithListeners<Handlers extends string, Payload> = {
|
|
26
|
+
[K in Handlers]: (listener: (payload: Payload) => void) => void;
|
|
27
|
+
};
|
|
28
|
+
export interface MiniAppOptions extends WithPostEvent, WithVersion, WithStateRestore<MiniAppState>, WithListeners<'onVisibilityChanged' | 'offVisibilityChanged', EventPayload<'visibility_changed'>>, SharedFeatureOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The current theme parameters.
|
|
31
|
+
*/
|
|
32
|
+
theme: Computed<ThemeParams>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @since Mini Apps v6.1
|
|
36
|
+
*/
|
|
37
|
+
export declare class MiniApp {
|
|
38
|
+
constructor({ storage, isPageReload, version, postEvent, isTma, theme, onVisibilityChanged, offVisibilityChanged, }: MiniAppOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Signal indicating if the component is supported.
|
|
41
|
+
*/
|
|
42
|
+
readonly isSupported: Computed<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* True if the current Mini App background color is recognized as dark.
|
|
45
|
+
*/
|
|
46
|
+
readonly isDark: Computed<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Signal indicating if the mini app is currently active.
|
|
49
|
+
*/
|
|
50
|
+
readonly isActive: Computed<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Complete component state.
|
|
53
|
+
*/
|
|
54
|
+
readonly state: Computed<MiniAppState>;
|
|
55
|
+
/**
|
|
56
|
+
* True if the CSS variables are currently bound.
|
|
57
|
+
*/
|
|
58
|
+
readonly isCssVarsBound: Computed<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates CSS variables connected with the mini app.
|
|
61
|
+
*
|
|
62
|
+
* Default variables:
|
|
63
|
+
* - `--tg-bg-color`
|
|
64
|
+
* - `--tg-header-color`
|
|
65
|
+
* - `--tg-bottom-bar-color`
|
|
66
|
+
*
|
|
67
|
+
* Variables are being automatically updated if theme parameters were changed.
|
|
68
|
+
*
|
|
69
|
+
* @param getCSSVarName - function, returning complete CSS variable name for the specified
|
|
70
|
+
* mini app key.
|
|
71
|
+
* @returns Function to stop updating variables.
|
|
72
|
+
* @example Using no arguments
|
|
73
|
+
* miniApp.bindCssVars();
|
|
74
|
+
* @example Using custom CSS vars generator
|
|
75
|
+
* miniApp.bindCssVars(key => `--my-prefix-${key}`);
|
|
76
|
+
*/
|
|
77
|
+
readonly bindCssVarsFp: WithChecksFp<(getCssVarName?: MiniAppGetCssVarNameFn) => E.Either<CSSVarsBoundError, VoidFunction>, false>;
|
|
78
|
+
readonly bindCssVars: WithChecks<(getCssVarName?: MiniAppGetCssVarNameFn) => VoidFunction, false>;
|
|
79
|
+
/**
|
|
80
|
+
* Signal indicating if the component is mounted.
|
|
81
|
+
*/
|
|
82
|
+
readonly isMounted: Computed<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Mounts the component.
|
|
85
|
+
*
|
|
86
|
+
* This function restores the component state and is automatically saving it in the local storage
|
|
87
|
+
* if it changed.
|
|
88
|
+
* @since Mini Apps v6.1
|
|
89
|
+
*/
|
|
90
|
+
readonly mountFp: WithChecksFp<() => void, false>;
|
|
91
|
+
/**
|
|
92
|
+
* @see mount
|
|
93
|
+
*/
|
|
94
|
+
readonly mount: WithChecks<() => void, false>;
|
|
95
|
+
/**
|
|
96
|
+
* Unmounts the component.
|
|
97
|
+
*/
|
|
98
|
+
readonly unmount: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* The Mini App background color.
|
|
101
|
+
*
|
|
102
|
+
* Represents an RGB color, or theme parameters key, like "bg_color", "secondary_bg_color", etc.
|
|
103
|
+
*
|
|
104
|
+
* Note that using a theme parameters key, background color becomes bound to the current
|
|
105
|
+
* theme parameters, making it automatically being updated whenever theme parameters change.
|
|
106
|
+
* In order to remove this bind, use an explicit RGB color.
|
|
107
|
+
*/
|
|
108
|
+
readonly bgColor: Computed<AnyColor>;
|
|
109
|
+
/**
|
|
110
|
+
* RGB representation of the background color.
|
|
111
|
+
*
|
|
112
|
+
* This value requires the Theme Params component to be mounted to extract a valid RGB value
|
|
113
|
+
* of the color key.
|
|
114
|
+
*/
|
|
115
|
+
readonly bgColorRgb: Computed<RGB | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* Updates the mini app background color.
|
|
118
|
+
* @since Mini Apps v6.1
|
|
119
|
+
*/
|
|
120
|
+
readonly setBgColorFp: WithChecksFp<(color: AnyColor) => E.Either<PostEventError | UnknownThemeParamsKeyError, void>, true>;
|
|
121
|
+
/**
|
|
122
|
+
* @see setBgColorFp
|
|
123
|
+
*/
|
|
124
|
+
readonly setBgColor: WithChecks<(color: AnyColor) => void, true>;
|
|
125
|
+
/**
|
|
126
|
+
* The Mini App header color.
|
|
127
|
+
*/
|
|
128
|
+
readonly headerColor: Computed<AnyColor>;
|
|
129
|
+
/**
|
|
130
|
+
* RGB representation of the header color.
|
|
131
|
+
*
|
|
132
|
+
* This value requires the Theme Params component to be mounted to extract a valid RGB value
|
|
133
|
+
* of the color key.
|
|
134
|
+
*/
|
|
135
|
+
readonly headerColorRgb: Computed<RGB | undefined>;
|
|
136
|
+
/**
|
|
137
|
+
* Updates the mini app header color.
|
|
138
|
+
* @since Mini Apps v6.1
|
|
139
|
+
*/
|
|
140
|
+
readonly setHeaderColorFp: WithChecksFp<(color: AnyColor) => E.Either<PostEventError | UnknownThemeParamsKeyError, void>, true, 'rgb'>;
|
|
141
|
+
/**
|
|
142
|
+
* @see setHeaderColorFp
|
|
143
|
+
*/
|
|
144
|
+
readonly setHeaderColor: WithChecks<(color: AnyColor) => void, true, 'rgb'>;
|
|
145
|
+
/**
|
|
146
|
+
* The Mini App bottom bar background color.
|
|
147
|
+
*/
|
|
148
|
+
readonly bottomBarColor: Computed<AnyColor>;
|
|
149
|
+
/**
|
|
150
|
+
* RGB representation of the bottom bar background color.
|
|
151
|
+
*
|
|
152
|
+
* This value requires the Theme Params component to be mounted to extract a valid RGB value
|
|
153
|
+
* of the color key.
|
|
154
|
+
*/
|
|
155
|
+
readonly bottomBarColorRgb: Computed<RGB | undefined>;
|
|
156
|
+
/**
|
|
157
|
+
* Updates the mini app bottom bar bg color.
|
|
158
|
+
* @since Mini Apps v7.10
|
|
159
|
+
*/
|
|
160
|
+
readonly setBottomBarColorFp: WithChecksFp<(color: AnyColor) => E.Either<PostEventError | UnknownThemeParamsKeyError, void>, true>;
|
|
161
|
+
/**
|
|
162
|
+
* @see setBottomBarColorFp
|
|
163
|
+
*/
|
|
164
|
+
readonly setBottomBarColor: WithChecks<(color: AnyColor) => void, true>;
|
|
165
|
+
/**
|
|
166
|
+
* Closes the Mini App.
|
|
167
|
+
* @param returnBack - should the client return to the previous activity.
|
|
168
|
+
*/
|
|
169
|
+
readonly closeFp: WithChecksFp<(returnBack?: boolean) => E.Either<PostEventError, void>, false>;
|
|
170
|
+
/**
|
|
171
|
+
* @see closeFp
|
|
172
|
+
*/
|
|
173
|
+
readonly close: WithChecks<(returnBack?: boolean) => void, false>;
|
|
174
|
+
/**
|
|
175
|
+
* Informs the Telegram app that the Mini App is ready to be displayed.
|
|
176
|
+
*
|
|
177
|
+
* It is recommended to call this method as early as possible, as soon as all
|
|
178
|
+
* essential interface elements loaded.
|
|
179
|
+
*
|
|
180
|
+
* Once this method is called, the loading placeholder is hidden and the Mini
|
|
181
|
+
* App shown.
|
|
182
|
+
*
|
|
183
|
+
* If the method is not called, the placeholder will be hidden only when the
|
|
184
|
+
* page was fully loaded.
|
|
185
|
+
*/
|
|
186
|
+
readonly readyFp: WithChecksFp<() => E.Either<PostEventError, void>, false>;
|
|
187
|
+
/**
|
|
188
|
+
* @see readyFp
|
|
189
|
+
*/
|
|
190
|
+
readonly ready: WithChecks<() => void, false>;
|
|
191
|
+
}
|
|
192
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UnknownEnvError } from '@vbotma/bridge';
|
|
2
|
+
import { BetterPromise } from 'better-promises';
|
|
3
|
+
import { taskEither as TE } from 'fp-ts';
|
|
4
|
+
import { NotificationOptions, SendNotificationOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Notification feature class.
|
|
7
|
+
* @since v9.2
|
|
8
|
+
*/
|
|
9
|
+
export declare class Notification {
|
|
10
|
+
constructor({}: NotificationOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Sends a notification to the native app.
|
|
13
|
+
* @param options - notification options including message, optional title, and optional type (defaults to 'default')
|
|
14
|
+
* @since v9.2
|
|
15
|
+
*/
|
|
16
|
+
readonly sendFp: (options: SendNotificationOptions) => TE.TaskEither<UnknownEnvError, void>;
|
|
17
|
+
/**
|
|
18
|
+
* @see sendFp
|
|
19
|
+
*/
|
|
20
|
+
readonly send: (options: SendNotificationOptions) => BetterPromise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SharedFeatureOptions } from '../../fn-options/sharedFeatureOptions.js';
|
|
2
|
+
export interface NotificationOptions extends SharedFeatureOptions {
|
|
3
|
+
}
|
|
4
|
+
export type NotificationType = 'default' | 'info' | 'success' | 'warning' | 'error';
|
|
5
|
+
export interface SendNotificationOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The message content to display.
|
|
8
|
+
*/
|
|
9
|
+
message: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional title for the notification.
|
|
12
|
+
*/
|
|
13
|
+
title?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The type of notification.
|
|
16
|
+
* @default 'default'
|
|
17
|
+
*/
|
|
18
|
+
type?: NotificationType;
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RequestError } from '@vbotma/bridge';
|
|
2
|
+
import { Computed } from '@vbotma/signals';
|
|
3
|
+
import { BetterPromise } from 'better-promises';
|
|
4
|
+
import { taskEither as TE } from 'fp-ts';
|
|
5
|
+
import { ConcurrentCallError, InvalidArgumentsError } from '../../errors.js';
|
|
6
|
+
import { ShowOptions } from './types.js';
|
|
7
|
+
import { SharedFeatureOptions } from '../../fn-options/sharedFeatureOptions.js';
|
|
8
|
+
import { WithRequest } from '../../fn-options/withRequest.js';
|
|
9
|
+
import { WithVersion } from '../../fn-options/withVersion.js';
|
|
10
|
+
import { WithChecksFp, WithChecks } from '../../with-checks/withChecksFp.js';
|
|
11
|
+
export interface PopupOptions extends SharedFeatureOptions, WithVersion, WithRequest {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @since Mini Apps v6.2
|
|
15
|
+
*/
|
|
16
|
+
export declare class Popup {
|
|
17
|
+
constructor({ version, isTma, request }: PopupOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Signal indicating if any popup is currently opened.
|
|
20
|
+
*/
|
|
21
|
+
readonly isOpened: Computed<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Signal indicating if the component is supported.
|
|
24
|
+
*/
|
|
25
|
+
readonly isSupported: Computed<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* A method that shows a native popup described by the `params` argument.
|
|
28
|
+
* The promise will be resolved when the popup is closed. Resolved value will have
|
|
29
|
+
* an identifier of the pressed button.
|
|
30
|
+
*
|
|
31
|
+
* If a user clicked outside the popup or clicked the top right popup close
|
|
32
|
+
* button, null will be resolved.
|
|
33
|
+
*
|
|
34
|
+
* @param options - popup parameters.
|
|
35
|
+
* @since Mini Apps v6.2
|
|
36
|
+
* @example
|
|
37
|
+
* fn.pipe(
|
|
38
|
+
* popup.showFp({
|
|
39
|
+
* title: 'Confirm action',
|
|
40
|
+
* message: 'Do you really want to buy this burger?',
|
|
41
|
+
* buttons: [
|
|
42
|
+
* { id: 'yes', text: 'Yes' },
|
|
43
|
+
* { id: 'no', type: 'destructive', text: 'No' },
|
|
44
|
+
* ],
|
|
45
|
+
* }),
|
|
46
|
+
* TE.map(buttonId => {
|
|
47
|
+
* console.log('User clicked a button with ID', buttonId);
|
|
48
|
+
* }),
|
|
49
|
+
* );
|
|
50
|
+
*/
|
|
51
|
+
readonly showFp: WithChecksFp<(options: ShowOptions) => TE.TaskEither<RequestError | InvalidArgumentsError | ConcurrentCallError, string | undefined>, true>;
|
|
52
|
+
/**
|
|
53
|
+
* @see showFp
|
|
54
|
+
*/
|
|
55
|
+
readonly show: WithChecks<(options: ShowOptions) => BetterPromise<string | undefined>, true>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PopupParams } from '@vbotma/bridge';
|
|
2
|
+
import { either as E } from 'fp-ts';
|
|
3
|
+
import { InvalidArgumentsError } from '../../errors.js';
|
|
4
|
+
import { ShowOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Prepares popup parameters before sending them to native app.
|
|
7
|
+
* @param params - popup parameters.
|
|
8
|
+
*/
|
|
9
|
+
export declare function prepareParams(params: ShowOptions): E.Either<InvalidArgumentsError, PopupParams>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AsyncOptions } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* This object describes the native popup.
|
|
4
|
+
* @see https://core.telegram.org/bots/webapps#popupparams
|
|
5
|
+
*/
|
|
6
|
+
export interface ShowOptions extends AsyncOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The text to be displayed in the popup title, 0-64 characters.
|
|
9
|
+
* @default ""
|
|
10
|
+
*/
|
|
11
|
+
title?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The message to be displayed in the body of the popup, 1-256 characters.
|
|
14
|
+
*/
|
|
15
|
+
message: string;
|
|
16
|
+
/**
|
|
17
|
+
* List of buttons to be displayed in the popup, 1-3 buttons.
|
|
18
|
+
* @default [{ type: 'close' }]
|
|
19
|
+
*/
|
|
20
|
+
buttons?: ShowOptionsButton[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This object describes the native popup button.
|
|
24
|
+
* @see https://core.telegram.org/bots/webapps#popupbutton
|
|
25
|
+
*/
|
|
26
|
+
export type ShowOptionsButton = {
|
|
27
|
+
/**
|
|
28
|
+
* Identifier of the button, 0-64 characters.
|
|
29
|
+
* @default ""
|
|
30
|
+
*/
|
|
31
|
+
id?: string;
|
|
32
|
+
} & ({
|
|
33
|
+
/**
|
|
34
|
+
* Type of the button:
|
|
35
|
+
* - `default`, a button with the default style;
|
|
36
|
+
* - `destructive`, a button with a style that indicates a destructive
|
|
37
|
+
* action (e.g. "Remove", "Delete", etc.).
|
|
38
|
+
*
|
|
39
|
+
* @default "default"
|
|
40
|
+
*/
|
|
41
|
+
type?: 'default' | 'destructive';
|
|
42
|
+
/**
|
|
43
|
+
* The text to be displayed on the button, 0-64 characters.
|
|
44
|
+
*/
|
|
45
|
+
text: string;
|
|
46
|
+
} | {
|
|
47
|
+
/**
|
|
48
|
+
* Type of the button:
|
|
49
|
+
* - `ok`, a button with the localized text "OK";
|
|
50
|
+
* - `close`, a button with the localized text "Close";
|
|
51
|
+
* - `cancel`, a button with the localized text "Cancel".
|
|
52
|
+
*/
|
|
53
|
+
type: 'ok' | 'close' | 'cancel';
|
|
54
|
+
});
|