@tma.js/sdk-react 0.4.11 → 0.4.12
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 -21
- package/README.md +28 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -68
- package/src/index.ts +2 -2
- package/src/lib/back-button/index.ts +3 -3
- package/src/lib/back-button/types.ts +1 -1
- package/src/lib/back-button/useBackButton.ts +13 -13
- package/src/lib/back-button/withBackButton.tsx +18 -18
- package/src/lib/closing-behavior/index.ts +3 -3
- package/src/lib/closing-behavior/types.ts +1 -1
- package/src/lib/closing-behavior/useClosingBehaviour.ts +13 -13
- package/src/lib/closing-behavior/withClosingBehaviour.tsx +18 -18
- package/src/lib/cloud-storage.tsx +28 -28
- package/src/lib/haptic-feedback/index.ts +3 -3
- package/src/lib/haptic-feedback/types.ts +1 -1
- package/src/lib/haptic-feedback/useHapticFeedback.ts +9 -9
- package/src/lib/haptic-feedback/withHapticFeedback.tsx +18 -18
- package/src/lib/hooks.ts +52 -52
- package/src/lib/index.ts +13 -13
- package/src/lib/init-data/index.ts +3 -3
- package/src/lib/init-data/types.ts +1 -1
- package/src/lib/init-data/useInitData.ts +9 -9
- package/src/lib/init-data/withInitData.tsx +18 -18
- package/src/lib/launch-params/index.ts +3 -3
- package/src/lib/launch-params/types.ts +1 -1
- package/src/lib/launch-params/useLaunchParams.ts +11 -11
- package/src/lib/launch-params/withLaunchParams.tsx +18 -18
- package/src/lib/main-button/index.ts +3 -3
- package/src/lib/main-button/types.ts +1 -1
- package/src/lib/main-button/useMainButton.ts +16 -16
- package/src/lib/main-button/withMainButton.tsx +18 -18
- package/src/lib/popup/index.ts +3 -3
- package/src/lib/popup/types.ts +1 -1
- package/src/lib/popup/usePopup.ts +13 -13
- package/src/lib/popup/withPopup.tsx +18 -18
- package/src/lib/qr-scanner/index.ts +3 -3
- package/src/lib/qr-scanner/types.ts +1 -1
- package/src/lib/qr-scanner/useQRScanner.ts +13 -13
- package/src/lib/qr-scanner/withQRScanner.tsx +18 -18
- package/src/lib/theme-params.tsx +29 -29
- package/src/lib/viewport/index.ts +3 -3
- package/src/lib/viewport/types.ts +1 -1
- package/src/lib/viewport/useViewport.ts +15 -15
- package/src/lib/viewport/withViewport.tsx +18 -18
- package/src/lib/web-app/index.ts +3 -3
- package/src/lib/web-app/types.ts +1 -1
- package/src/lib/web-app/useWebApp.ts +13 -13
- package/src/lib/web-app/withWebApp.tsx +18 -18
- package/src/provider/SDKProvider.tsx +47 -47
- package/src/provider/context.ts +11 -11
- package/src/provider/hocs.tsx +18 -18
- package/src/provider/hooks.ts +23 -23
- package/src/provider/index.ts +5 -5
- package/src/provider/types.ts +34 -34
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useClosingBehaviour } from './useClosingBehaviour.js';
|
|
4
|
-
import type { ClosingBehaviour } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes ClosingBehaviour SDK component to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withClosingBehaviour<P extends { closingBehaviour?: ClosingBehaviour }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'closingBehaviour'>> {
|
|
13
|
-
return function WithClosingConfirmation(props: Omit<P, 'closingBehaviour'>) {
|
|
14
|
-
const p = { ...props, closingBehaviour: useClosingBehaviour() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useClosingBehaviour } from './useClosingBehaviour.js';
|
|
4
|
+
import type { ClosingBehaviour } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes ClosingBehaviour SDK component to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withClosingBehaviour<P extends { closingBehaviour?: ClosingBehaviour }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'closingBehaviour'>> {
|
|
13
|
+
return function WithClosingConfirmation(props: Omit<P, 'closingBehaviour'>) {
|
|
14
|
+
const p = { ...props, closingBehaviour: useClosingBehaviour() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { CloudStorage } from '@tma.js/sdk';
|
|
4
|
-
|
|
5
|
-
import { useUnit } from '../provider/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns CloudStorage component instance.
|
|
9
|
-
*/
|
|
10
|
-
export function useCloudStorage(): CloudStorage {
|
|
11
|
-
return useUnit('cloudStorage');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* HOC which passes CloudStorage SDK component to wrapped React component.
|
|
16
|
-
* @param Component - component to wrap.
|
|
17
|
-
*/
|
|
18
|
-
export function withCloudStorage<P extends { cloudStorage?: CloudStorage }>(
|
|
19
|
-
Component: ComponentType<P>,
|
|
20
|
-
): ComponentType<Omit<P, 'cloudStorage'>> {
|
|
21
|
-
return function WithCloudStorage(props: Omit<P, 'cloudStorage'>) {
|
|
22
|
-
const p = { ...props, cloudStorage: useCloudStorage() } as P;
|
|
23
|
-
|
|
24
|
-
return <Component {...p} />;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type { CloudStorage };
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { CloudStorage } from '@tma.js/sdk';
|
|
4
|
+
|
|
5
|
+
import { useUnit } from '../provider/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns CloudStorage component instance.
|
|
9
|
+
*/
|
|
10
|
+
export function useCloudStorage(): CloudStorage {
|
|
11
|
+
return useUnit('cloudStorage');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* HOC which passes CloudStorage SDK component to wrapped React component.
|
|
16
|
+
* @param Component - component to wrap.
|
|
17
|
+
*/
|
|
18
|
+
export function withCloudStorage<P extends { cloudStorage?: CloudStorage }>(
|
|
19
|
+
Component: ComponentType<P>,
|
|
20
|
+
): ComponentType<Omit<P, 'cloudStorage'>> {
|
|
21
|
+
return function WithCloudStorage(props: Omit<P, 'cloudStorage'>) {
|
|
22
|
+
const p = { ...props, cloudStorage: useCloudStorage() } as P;
|
|
23
|
+
|
|
24
|
+
return <Component {...p} />;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type { CloudStorage };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './useHapticFeedback.js';
|
|
3
|
-
export * from './withHapticFeedback.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './useHapticFeedback.js';
|
|
3
|
+
export * from './withHapticFeedback.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { HapticFeedback } from '@tma.js/sdk';
|
|
1
|
+
export type { HapticFeedback } from '@tma.js/sdk';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useUnit } from '../../provider/index.js';
|
|
2
|
-
import type { HapticFeedback } from './types.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns HapticFeedback component instance.
|
|
6
|
-
*/
|
|
7
|
-
export function useHapticFeedback(): HapticFeedback {
|
|
8
|
-
return useUnit('haptic');
|
|
9
|
-
}
|
|
1
|
+
import { useUnit } from '../../provider/index.js';
|
|
2
|
+
import type { HapticFeedback } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns HapticFeedback component instance.
|
|
6
|
+
*/
|
|
7
|
+
export function useHapticFeedback(): HapticFeedback {
|
|
8
|
+
return useUnit('haptic');
|
|
9
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useHapticFeedback } from './useHapticFeedback.js';
|
|
4
|
-
import type { HapticFeedback } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes HapticFeedback SDK component to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withHapticFeedback<P extends { hapticFeedback?: HapticFeedback }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'hapticFeedback'>> {
|
|
13
|
-
return function WithHapticFeedback(props: Omit<P, 'hapticFeedback'>) {
|
|
14
|
-
const p = { ...props, hapticFeedback: useHapticFeedback() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useHapticFeedback } from './useHapticFeedback.js';
|
|
4
|
+
import type { HapticFeedback } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes HapticFeedback SDK component to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withHapticFeedback<P extends { hapticFeedback?: HapticFeedback }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'hapticFeedback'>> {
|
|
13
|
+
return function WithHapticFeedback(props: Omit<P, 'hapticFeedback'>) {
|
|
14
|
+
const p = { ...props, hapticFeedback: useHapticFeedback() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/src/lib/hooks.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { useCallback, useState, useEffect } from 'react';
|
|
2
|
-
import type { PostEvent } from '@tma.js/sdk';
|
|
3
|
-
|
|
4
|
-
import { useUnit } from '../provider/index.js';
|
|
5
|
-
|
|
6
|
-
interface Trackable {
|
|
7
|
-
on: (event: any, ...args: any[]) => void;
|
|
8
|
-
off: (event: any, ...args: any[]) => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type EventName<T extends Trackable> = T extends {
|
|
12
|
-
on(event: infer E, ...args: any[]): any
|
|
13
|
-
} ? E : never;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The hook which returns function used for force update.
|
|
17
|
-
*/
|
|
18
|
-
export function useForceUpdate(): (() => void) {
|
|
19
|
-
const [, setHash] = useState(0);
|
|
20
|
-
// TODO: Maybe just assign new symbol?
|
|
21
|
-
return useCallback(() => setHash((hash) => (hash + 1) % 1_000_000), []);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The hook which listens to the specified object events and calls force update
|
|
26
|
-
* in case, some of them was emitted.
|
|
27
|
-
* @param trackable - object which allows events listening.
|
|
28
|
-
* @param events - events to listen. This array will be memoized during first
|
|
29
|
-
* hook call.
|
|
30
|
-
*/
|
|
31
|
-
export function useEventsTracking<T extends Trackable>(
|
|
32
|
-
trackable: T,
|
|
33
|
-
events: EventName<T>[],
|
|
34
|
-
) {
|
|
35
|
-
const forceUpdate = useForceUpdate();
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
// Start listening to each event.
|
|
39
|
-
events.forEach((event) => trackable.on(event, forceUpdate));
|
|
40
|
-
|
|
41
|
-
// On cleanup remove event listeners.
|
|
42
|
-
return () => events.forEach((event) => trackable.off(event, forceUpdate));
|
|
43
|
-
}, [trackable, forceUpdate, events]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Returns event posting function which was created during SDK
|
|
48
|
-
* initialization.
|
|
49
|
-
*/
|
|
50
|
-
export function usePostEvent(): PostEvent {
|
|
51
|
-
return useUnit('postEvent');
|
|
52
|
-
}
|
|
1
|
+
import { useCallback, useState, useEffect } from 'react';
|
|
2
|
+
import type { PostEvent } from '@tma.js/sdk';
|
|
3
|
+
|
|
4
|
+
import { useUnit } from '../provider/index.js';
|
|
5
|
+
|
|
6
|
+
interface Trackable {
|
|
7
|
+
on: (event: any, ...args: any[]) => void;
|
|
8
|
+
off: (event: any, ...args: any[]) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type EventName<T extends Trackable> = T extends {
|
|
12
|
+
on(event: infer E, ...args: any[]): any
|
|
13
|
+
} ? E : never;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The hook which returns function used for force update.
|
|
17
|
+
*/
|
|
18
|
+
export function useForceUpdate(): (() => void) {
|
|
19
|
+
const [, setHash] = useState(0);
|
|
20
|
+
// TODO: Maybe just assign new symbol?
|
|
21
|
+
return useCallback(() => setHash((hash) => (hash + 1) % 1_000_000), []);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The hook which listens to the specified object events and calls force update
|
|
26
|
+
* in case, some of them was emitted.
|
|
27
|
+
* @param trackable - object which allows events listening.
|
|
28
|
+
* @param events - events to listen. This array will be memoized during first
|
|
29
|
+
* hook call.
|
|
30
|
+
*/
|
|
31
|
+
export function useEventsTracking<T extends Trackable>(
|
|
32
|
+
trackable: T,
|
|
33
|
+
events: EventName<T>[],
|
|
34
|
+
) {
|
|
35
|
+
const forceUpdate = useForceUpdate();
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
// Start listening to each event.
|
|
39
|
+
events.forEach((event) => trackable.on(event, forceUpdate));
|
|
40
|
+
|
|
41
|
+
// On cleanup remove event listeners.
|
|
42
|
+
return () => events.forEach((event) => trackable.off(event, forceUpdate));
|
|
43
|
+
}, [trackable, forceUpdate, events]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns event posting function which was created during SDK
|
|
48
|
+
* initialization.
|
|
49
|
+
*/
|
|
50
|
+
export function usePostEvent(): PostEvent {
|
|
51
|
+
return useUnit('postEvent');
|
|
52
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './back-button/index.js';
|
|
2
|
-
export * from './closing-behavior/index.js';
|
|
3
|
-
export * from './haptic-feedback/index.js';
|
|
4
|
-
export * from './init-data/index.js';
|
|
5
|
-
export * from './launch-params/index.js';
|
|
6
|
-
export * from './main-button/index.js';
|
|
7
|
-
export * from './popup/index.js';
|
|
8
|
-
export * from './qr-scanner/index.js';
|
|
9
|
-
export * from './viewport/index.js';
|
|
10
|
-
export * from './web-app/index.js';
|
|
11
|
-
export * from './cloud-storage.js';
|
|
12
|
-
export { usePostEvent } from './hooks.js';
|
|
13
|
-
export * from './theme-params.js';
|
|
1
|
+
export * from './back-button/index.js';
|
|
2
|
+
export * from './closing-behavior/index.js';
|
|
3
|
+
export * from './haptic-feedback/index.js';
|
|
4
|
+
export * from './init-data/index.js';
|
|
5
|
+
export * from './launch-params/index.js';
|
|
6
|
+
export * from './main-button/index.js';
|
|
7
|
+
export * from './popup/index.js';
|
|
8
|
+
export * from './qr-scanner/index.js';
|
|
9
|
+
export * from './viewport/index.js';
|
|
10
|
+
export * from './web-app/index.js';
|
|
11
|
+
export * from './cloud-storage.js';
|
|
12
|
+
export { usePostEvent } from './hooks.js';
|
|
13
|
+
export * from './theme-params.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './useInitData.js';
|
|
3
|
-
export * from './withInitData.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './useInitData.js';
|
|
3
|
+
export * from './withInitData.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { InitData } from '@tma.js/sdk';
|
|
1
|
+
export type { InitData } from '@tma.js/sdk';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useUnit } from '../../provider/index.js';
|
|
2
|
-
import type { InitData } from './types.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns InitData component instance.
|
|
6
|
-
*/
|
|
7
|
-
export function useInitData(): InitData | null {
|
|
8
|
-
return useUnit('initData') || null;
|
|
9
|
-
}
|
|
1
|
+
import { useUnit } from '../../provider/index.js';
|
|
2
|
+
import type { InitData } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns InitData component instance.
|
|
6
|
+
*/
|
|
7
|
+
export function useInitData(): InitData | null {
|
|
8
|
+
return useUnit('initData') || null;
|
|
9
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useInitData } from './useInitData.js';
|
|
4
|
-
import type { InitData } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes InitData SDK component to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withInitData<P extends { initData?: InitData }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'initData'>> {
|
|
13
|
-
return function WithInitData(props: Omit<P, 'initData'>) {
|
|
14
|
-
const p = { ...props, initData: useInitData() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useInitData } from './useInitData.js';
|
|
4
|
+
import type { InitData } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes InitData SDK component to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withInitData<P extends { initData?: InitData }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'initData'>> {
|
|
13
|
+
return function WithInitData(props: Omit<P, 'initData'>) {
|
|
14
|
+
const p = { ...props, initData: useInitData() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './useLaunchParams.js';
|
|
3
|
-
export * from './withLaunchParams.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './useLaunchParams.js';
|
|
3
|
+
export * from './withLaunchParams.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { LaunchParams } from '@tma.js/launch-params';
|
|
1
|
+
export type { LaunchParams } from '@tma.js/launch-params';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { retrieveLaunchParams } from '@tma.js/sdk';
|
|
3
|
-
|
|
4
|
-
import type { LaunchParams } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The hook which returns launch parameters initially passed to Web App.
|
|
8
|
-
*/
|
|
9
|
-
export function useLaunchParams(): LaunchParams {
|
|
10
|
-
return useMemo(retrieveLaunchParams, []);
|
|
11
|
-
}
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { retrieveLaunchParams } from '@tma.js/sdk';
|
|
3
|
+
|
|
4
|
+
import type { LaunchParams } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The hook which returns launch parameters initially passed to Web App.
|
|
8
|
+
*/
|
|
9
|
+
export function useLaunchParams(): LaunchParams {
|
|
10
|
+
return useMemo(retrieveLaunchParams, []);
|
|
11
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useLaunchParams } from './useLaunchParams.js';
|
|
4
|
-
import type { LaunchParams } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes launch parameters to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withLaunchParams<P extends { launchParams?: LaunchParams }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'launchParams'>> {
|
|
13
|
-
return function WithLaunchParams(props: Omit<P, 'launchParams'>) {
|
|
14
|
-
const p = { ...props, launchParams: useLaunchParams() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useLaunchParams } from './useLaunchParams.js';
|
|
4
|
+
import type { LaunchParams } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes launch parameters to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withLaunchParams<P extends { launchParams?: LaunchParams }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'launchParams'>> {
|
|
13
|
+
return function WithLaunchParams(props: Omit<P, 'launchParams'>) {
|
|
14
|
+
const p = { ...props, launchParams: useLaunchParams() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './useMainButton.js';
|
|
3
|
-
export * from './withMainButton.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './useMainButton.js';
|
|
3
|
+
export * from './withMainButton.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { MainButton } from '@tma.js/sdk';
|
|
1
|
+
export type { MainButton } from '@tma.js/sdk';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { useUnit } from '../../provider/index.js';
|
|
2
|
-
import { useEventsTracking } from '../hooks.js';
|
|
3
|
-
import type { MainButton } from './types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns MainButton component instance.
|
|
7
|
-
*/
|
|
8
|
-
export function useMainButton(): MainButton {
|
|
9
|
-
const mainButton = useUnit('mainButton');
|
|
10
|
-
useEventsTracking(mainButton, [
|
|
11
|
-
'isEnabledChanged', 'backgroundColorChanged', 'isProgressVisibleChanged',
|
|
12
|
-
'textChanged', 'textColorChanged', 'isVisibleChanged',
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
return mainButton;
|
|
16
|
-
}
|
|
1
|
+
import { useUnit } from '../../provider/index.js';
|
|
2
|
+
import { useEventsTracking } from '../hooks.js';
|
|
3
|
+
import type { MainButton } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns MainButton component instance.
|
|
7
|
+
*/
|
|
8
|
+
export function useMainButton(): MainButton {
|
|
9
|
+
const mainButton = useUnit('mainButton');
|
|
10
|
+
useEventsTracking(mainButton, [
|
|
11
|
+
'isEnabledChanged', 'backgroundColorChanged', 'isProgressVisibleChanged',
|
|
12
|
+
'textChanged', 'textColorChanged', 'isVisibleChanged',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
return mainButton;
|
|
16
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useMainButton } from './useMainButton.js';
|
|
4
|
-
import type { MainButton } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes MainButton SDK component to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withMainButton<P extends { mainButton?: MainButton }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'mainButton'>> {
|
|
13
|
-
return function WithMainButton(props: Omit<P, 'mainButton'>) {
|
|
14
|
-
const p = { ...props, mainButton: useMainButton() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useMainButton } from './useMainButton.js';
|
|
4
|
+
import type { MainButton } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes MainButton SDK component to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withMainButton<P extends { mainButton?: MainButton }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'mainButton'>> {
|
|
13
|
+
return function WithMainButton(props: Omit<P, 'mainButton'>) {
|
|
14
|
+
const p = { ...props, mainButton: useMainButton() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/src/lib/popup/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './usePopup.js';
|
|
3
|
-
export * from './withPopup.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './usePopup.js';
|
|
3
|
+
export * from './withPopup.js';
|
package/src/lib/popup/types.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { Popup } from '@tma.js/sdk';
|
|
1
|
+
export type { Popup } from '@tma.js/sdk';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useUnit } from '../../provider/index.js';
|
|
2
|
-
import { useEventsTracking } from '../hooks.js';
|
|
3
|
-
import type { Popup } from './types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns Popup component instance.
|
|
7
|
-
*/
|
|
8
|
-
export function usePopup(): Popup {
|
|
9
|
-
const popup = useUnit('popup');
|
|
10
|
-
useEventsTracking(popup, ['isOpenedChanged']);
|
|
11
|
-
|
|
12
|
-
return popup;
|
|
13
|
-
}
|
|
1
|
+
import { useUnit } from '../../provider/index.js';
|
|
2
|
+
import { useEventsTracking } from '../hooks.js';
|
|
3
|
+
import type { Popup } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns Popup component instance.
|
|
7
|
+
*/
|
|
8
|
+
export function usePopup(): Popup {
|
|
9
|
+
const popup = useUnit('popup');
|
|
10
|
+
useEventsTracking(popup, ['isOpenedChanged']);
|
|
11
|
+
|
|
12
|
+
return popup;
|
|
13
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { type ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { usePopup } from './usePopup.js';
|
|
4
|
-
import type { Popup } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* HOC which passes Popup SDK component to wrapped React component.
|
|
8
|
-
* @param Component - component to wrap.
|
|
9
|
-
*/
|
|
10
|
-
export function withPopup<P extends { popup?: Popup }>(
|
|
11
|
-
Component: ComponentType<P>,
|
|
12
|
-
): ComponentType<Omit<P, 'popup'>> {
|
|
13
|
-
return function WithPopup(props: Omit<P, 'popup'>) {
|
|
14
|
-
const p = { ...props, popup: usePopup() } as P;
|
|
15
|
-
|
|
16
|
-
return <Component {...p} />;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
import React, { type ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { usePopup } from './usePopup.js';
|
|
4
|
+
import type { Popup } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HOC which passes Popup SDK component to wrapped React component.
|
|
8
|
+
* @param Component - component to wrap.
|
|
9
|
+
*/
|
|
10
|
+
export function withPopup<P extends { popup?: Popup }>(
|
|
11
|
+
Component: ComponentType<P>,
|
|
12
|
+
): ComponentType<Omit<P, 'popup'>> {
|
|
13
|
+
return function WithPopup(props: Omit<P, 'popup'>) {
|
|
14
|
+
const p = { ...props, popup: usePopup() } as P;
|
|
15
|
+
|
|
16
|
+
return <Component {...p} />;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
|
-
export * from './useQRScanner.js';
|
|
3
|
-
export * from './withQRScanner.js';
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './useQRScanner.js';
|
|
3
|
+
export * from './withQRScanner.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { QRScanner } from '@tma.js/sdk';
|
|
1
|
+
export type { QRScanner } from '@tma.js/sdk';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useUnit } from '../../provider/index.js';
|
|
2
|
-
import { useEventsTracking } from '../hooks.js';
|
|
3
|
-
import type { QRScanner } from './types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns QRScanner component instance.
|
|
7
|
-
*/
|
|
8
|
-
export function useQRScanner(): QRScanner {
|
|
9
|
-
const qrScanner = useUnit('qrScanner');
|
|
10
|
-
useEventsTracking(qrScanner, ['isOpenedChanged']);
|
|
11
|
-
|
|
12
|
-
return qrScanner;
|
|
13
|
-
}
|
|
1
|
+
import { useUnit } from '../../provider/index.js';
|
|
2
|
+
import { useEventsTracking } from '../hooks.js';
|
|
3
|
+
import type { QRScanner } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns QRScanner component instance.
|
|
7
|
+
*/
|
|
8
|
+
export function useQRScanner(): QRScanner {
|
|
9
|
+
const qrScanner = useUnit('qrScanner');
|
|
10
|
+
useEventsTracking(qrScanner, ['isOpenedChanged']);
|
|
11
|
+
|
|
12
|
+
return qrScanner;
|
|
13
|
+
}
|