@tma.js/sdk-react 0.5.3 → 1.0.0

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.
Files changed (150) hide show
  1. package/dist/dts/createHoc.d.ts +12 -0
  2. package/dist/dts/createHook.d.ts +13 -0
  3. package/dist/dts/index.d.ts +3 -2
  4. package/dist/dts/provider/SDKContext.d.ts +3 -0
  5. package/dist/dts/provider/SDKProvider.d.ts +4 -8
  6. package/dist/dts/provider/index.d.ts +5 -3
  7. package/dist/dts/provider/types.d.ts +15 -21
  8. package/dist/dts/provider/useInitResultDynamicValue.d.ts +2 -0
  9. package/dist/dts/provider/useInitResultValue.d.ts +7 -0
  10. package/dist/dts/provider/useSDKContext.d.ts +5 -0
  11. package/dist/dts/provider/{hocs.d.ts → withSDKContext.d.ts} +3 -3
  12. package/dist/dts/tools/back-button.d.ts +8 -0
  13. package/dist/dts/tools/closing-behavior.d.ts +8 -0
  14. package/dist/dts/tools/cloud-storage.d.ts +8 -0
  15. package/dist/dts/tools/haptic-feedback.d.ts +8 -0
  16. package/dist/dts/tools/index.d.ts +16 -0
  17. package/dist/dts/tools/init-data-raw.d.ts +8 -0
  18. package/dist/dts/tools/init-data.d.ts +8 -0
  19. package/dist/dts/tools/invoice.d.ts +8 -0
  20. package/dist/dts/tools/launch-params.d.ts +13 -0
  21. package/dist/dts/tools/main-button.d.ts +8 -0
  22. package/dist/dts/tools/mini-app.d.ts +8 -0
  23. package/dist/dts/tools/popup.d.ts +8 -0
  24. package/dist/dts/tools/post-event.d.ts +8 -0
  25. package/dist/dts/tools/qr-scanner.d.ts +8 -0
  26. package/dist/dts/tools/theme-params.d.ts +8 -0
  27. package/dist/dts/tools/utils.d.ts +8 -0
  28. package/dist/dts/tools/viewport.d.ts +8 -0
  29. package/dist/dts/types.d.ts +23 -0
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.mjs +116 -203
  33. package/dist/index.mjs.map +1 -1
  34. package/package.json +7 -9
  35. package/src/createHoc.tsx +32 -0
  36. package/src/createHook.ts +31 -0
  37. package/src/index.ts +45 -2
  38. package/src/provider/SDKContext.ts +9 -0
  39. package/src/provider/SDKProvider.tsx +54 -37
  40. package/src/provider/index.ts +5 -3
  41. package/src/provider/types.ts +15 -22
  42. package/src/provider/useInitResultDynamicValue.ts +34 -0
  43. package/src/provider/useInitResultValue.ts +16 -0
  44. package/src/provider/useSDKContext.ts +11 -0
  45. package/src/provider/withSDKContext.tsx +21 -0
  46. package/src/tools/back-button.ts +12 -0
  47. package/src/tools/closing-behavior.ts +12 -0
  48. package/src/tools/cloud-storage.ts +12 -0
  49. package/src/tools/haptic-feedback.ts +12 -0
  50. package/src/tools/index.ts +16 -0
  51. package/src/tools/init-data-raw.ts +12 -0
  52. package/src/tools/init-data.ts +12 -0
  53. package/src/tools/invoice.ts +12 -0
  54. package/src/tools/launch-params.tsx +21 -0
  55. package/src/tools/main-button.ts +12 -0
  56. package/src/tools/mini-app.ts +12 -0
  57. package/src/tools/popup.ts +12 -0
  58. package/src/tools/post-event.ts +12 -0
  59. package/src/tools/qr-scanner.ts +12 -0
  60. package/src/tools/theme-params.ts +12 -0
  61. package/src/tools/utils.ts +12 -0
  62. package/src/tools/viewport.ts +12 -0
  63. package/src/types.ts +29 -0
  64. package/dist/dts/lib/back-button/index.d.ts +0 -3
  65. package/dist/dts/lib/back-button/types.d.ts +0 -1
  66. package/dist/dts/lib/back-button/useBackButton.d.ts +0 -5
  67. package/dist/dts/lib/back-button/withBackButton.d.ts +0 -9
  68. package/dist/dts/lib/closing-behavior/index.d.ts +0 -3
  69. package/dist/dts/lib/closing-behavior/types.d.ts +0 -1
  70. package/dist/dts/lib/closing-behavior/useClosingBehaviour.d.ts +0 -5
  71. package/dist/dts/lib/closing-behavior/withClosingBehaviour.d.ts +0 -9
  72. package/dist/dts/lib/cloud-storage.d.ts +0 -14
  73. package/dist/dts/lib/haptic-feedback/index.d.ts +0 -3
  74. package/dist/dts/lib/haptic-feedback/types.d.ts +0 -1
  75. package/dist/dts/lib/haptic-feedback/useHapticFeedback.d.ts +0 -5
  76. package/dist/dts/lib/haptic-feedback/withHapticFeedback.d.ts +0 -9
  77. package/dist/dts/lib/hooks.d.ts +0 -26
  78. package/dist/dts/lib/index.d.ts +0 -13
  79. package/dist/dts/lib/init-data.d.ts +0 -20
  80. package/dist/dts/lib/launch-params/index.d.ts +0 -3
  81. package/dist/dts/lib/launch-params/types.d.ts +0 -1
  82. package/dist/dts/lib/launch-params/useLaunchParams.d.ts +0 -5
  83. package/dist/dts/lib/launch-params/withLaunchParams.d.ts +0 -9
  84. package/dist/dts/lib/main-button/index.d.ts +0 -3
  85. package/dist/dts/lib/main-button/types.d.ts +0 -1
  86. package/dist/dts/lib/main-button/useMainButton.d.ts +0 -5
  87. package/dist/dts/lib/main-button/withMainButton.d.ts +0 -9
  88. package/dist/dts/lib/popup/index.d.ts +0 -3
  89. package/dist/dts/lib/popup/types.d.ts +0 -1
  90. package/dist/dts/lib/popup/usePopup.d.ts +0 -5
  91. package/dist/dts/lib/popup/withPopup.d.ts +0 -9
  92. package/dist/dts/lib/qr-scanner/index.d.ts +0 -3
  93. package/dist/dts/lib/qr-scanner/types.d.ts +0 -1
  94. package/dist/dts/lib/qr-scanner/useQRScanner.d.ts +0 -5
  95. package/dist/dts/lib/qr-scanner/withQRScanner.d.ts +0 -9
  96. package/dist/dts/lib/theme-params.d.ts +0 -13
  97. package/dist/dts/lib/viewport/index.d.ts +0 -3
  98. package/dist/dts/lib/viewport/types.d.ts +0 -1
  99. package/dist/dts/lib/viewport/useViewport.d.ts +0 -5
  100. package/dist/dts/lib/viewport/withViewport.d.ts +0 -9
  101. package/dist/dts/lib/web-app/index.d.ts +0 -3
  102. package/dist/dts/lib/web-app/types.d.ts +0 -1
  103. package/dist/dts/lib/web-app/useWebApp.d.ts +0 -5
  104. package/dist/dts/lib/web-app/withWebApp.d.ts +0 -9
  105. package/dist/dts/provider/context.d.ts +0 -3
  106. package/dist/dts/provider/hooks.d.ts +0 -11
  107. package/src/lib/back-button/index.ts +0 -3
  108. package/src/lib/back-button/types.ts +0 -1
  109. package/src/lib/back-button/useBackButton.ts +0 -13
  110. package/src/lib/back-button/withBackButton.tsx +0 -18
  111. package/src/lib/closing-behavior/index.ts +0 -3
  112. package/src/lib/closing-behavior/types.ts +0 -1
  113. package/src/lib/closing-behavior/useClosingBehaviour.ts +0 -13
  114. package/src/lib/closing-behavior/withClosingBehaviour.tsx +0 -18
  115. package/src/lib/cloud-storage.tsx +0 -28
  116. package/src/lib/haptic-feedback/index.ts +0 -3
  117. package/src/lib/haptic-feedback/types.ts +0 -1
  118. package/src/lib/haptic-feedback/useHapticFeedback.ts +0 -9
  119. package/src/lib/haptic-feedback/withHapticFeedback.tsx +0 -18
  120. package/src/lib/hooks.ts +0 -52
  121. package/src/lib/index.ts +0 -13
  122. package/src/lib/init-data.tsx +0 -43
  123. package/src/lib/launch-params/index.ts +0 -3
  124. package/src/lib/launch-params/types.ts +0 -1
  125. package/src/lib/launch-params/useLaunchParams.ts +0 -11
  126. package/src/lib/launch-params/withLaunchParams.tsx +0 -18
  127. package/src/lib/main-button/index.ts +0 -3
  128. package/src/lib/main-button/types.ts +0 -1
  129. package/src/lib/main-button/useMainButton.ts +0 -16
  130. package/src/lib/main-button/withMainButton.tsx +0 -18
  131. package/src/lib/popup/index.ts +0 -3
  132. package/src/lib/popup/types.ts +0 -1
  133. package/src/lib/popup/usePopup.ts +0 -13
  134. package/src/lib/popup/withPopup.tsx +0 -18
  135. package/src/lib/qr-scanner/index.ts +0 -3
  136. package/src/lib/qr-scanner/types.ts +0 -1
  137. package/src/lib/qr-scanner/useQRScanner.ts +0 -13
  138. package/src/lib/qr-scanner/withQRScanner.tsx +0 -18
  139. package/src/lib/theme-params.tsx +0 -29
  140. package/src/lib/viewport/index.ts +0 -3
  141. package/src/lib/viewport/types.ts +0 -1
  142. package/src/lib/viewport/useViewport.ts +0 -15
  143. package/src/lib/viewport/withViewport.tsx +0 -18
  144. package/src/lib/web-app/index.ts +0 -3
  145. package/src/lib/web-app/types.ts +0 -1
  146. package/src/lib/web-app/useWebApp.ts +0 -13
  147. package/src/lib/web-app/withWebApp.tsx +0 -18
  148. package/src/provider/context.ts +0 -11
  149. package/src/provider/hocs.tsx +0 -18
  150. package/src/provider/hooks.ts +0 -23
@@ -1,13 +0,0 @@
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,18 +0,0 @@
1
- import React, { type ComponentType } from 'react';
2
-
3
- import { useQRScanner } from './useQRScanner.js';
4
- import type { QRScanner } from './types.js';
5
-
6
- /**
7
- * HOC which passes QRScanner SDK component to wrapped React component.
8
- * @param Component - component to wrap.
9
- */
10
- export function withQRScanner<P extends { qrScanner?: QRScanner }>(
11
- Component: ComponentType<P>,
12
- ): ComponentType<Omit<P, 'qrScanner'>> {
13
- return function WithQRScanner(props: Omit<P, 'qrScanner'>) {
14
- const p = { ...props, qrScanner: useQRScanner() } as P;
15
-
16
- return <Component {...p} />;
17
- };
18
- }
@@ -1,29 +0,0 @@
1
- import React, { type ComponentType } from 'react';
2
- import type { ThemeParams } from '@tma.js/sdk';
3
-
4
- import { useUnit } from '../provider/index.js';
5
- import { useEventsTracking } from './hooks.js';
6
-
7
- /**
8
- * Returns ThemeParams component instance.
9
- */
10
- export function useThemeParams(): ThemeParams {
11
- const theme = useUnit('themeParams');
12
- useEventsTracking(theme, ['changed']);
13
-
14
- return theme;
15
- }
16
-
17
- /**
18
- * HOC which passes ThemeParams SDK component to wrapped React component.
19
- * @param Component - component to wrap.
20
- */
21
- export function withThemeParams<P extends { themeParams?: ThemeParams }>(
22
- Component: ComponentType<P>,
23
- ): ComponentType<Omit<P, 'themeParams'>> {
24
- return function WithThemeParams(props: Omit<P, 'themeParams'>) {
25
- const p = { ...props, themeParams: useThemeParams() } as P;
26
-
27
- return <Component {...p} />;
28
- };
29
- }
@@ -1,3 +0,0 @@
1
- export * from './types.js';
2
- export * from './useViewport.js';
3
- export * from './withViewport.js';
@@ -1 +0,0 @@
1
- export type { Viewport } from '@tma.js/sdk';
@@ -1,15 +0,0 @@
1
- import { useUnit } from '../../provider/index.js';
2
- import { useEventsTracking } from '../hooks.js';
3
- import type { Viewport } from './types.js';
4
-
5
- /**
6
- * Returns Viewport component instance.
7
- */
8
- export function useViewport(): Viewport {
9
- const viewport = useUnit('viewport');
10
- useEventsTracking(viewport, [
11
- 'stableHeightChanged', 'isExpandedChanged', 'heightChanged', 'widthChanged',
12
- ]);
13
-
14
- return viewport;
15
- }
@@ -1,18 +0,0 @@
1
- import React, { type ComponentType } from 'react';
2
-
3
- import { useViewport } from './useViewport.js';
4
- import type { Viewport } from './types.js';
5
-
6
- /**
7
- * HOC which passes Viewport SDK component to wrapped React component.
8
- * @param Component - component to wrap.
9
- */
10
- export function withViewport<P extends { viewport?: Viewport }>(
11
- Component: ComponentType<P>,
12
- ): ComponentType<Omit<P, 'viewport'>> {
13
- return function WithViewport(props: Omit<P, 'viewport'>) {
14
- const p = { ...props, viewport: useViewport() } as P;
15
-
16
- return <Component {...p} />;
17
- };
18
- }
@@ -1,3 +0,0 @@
1
- export * from './types.js';
2
- export * from './useWebApp.js';
3
- export * from './withWebApp.js';
@@ -1 +0,0 @@
1
- export type { WebApp } from '@tma.js/sdk';
@@ -1,13 +0,0 @@
1
- import { useUnit } from '../../provider/index.js';
2
- import type { WebApp } from './types.js';
3
- import { useEventsTracking } from '../hooks.js';
4
-
5
- /**
6
- * Returns WebApp component instance.
7
- */
8
- export function useWebApp(): WebApp {
9
- const webApp = useUnit('webApp');
10
- useEventsTracking(webApp, ['headerColorChanged', 'backgroundColorChanged']);
11
-
12
- return webApp;
13
- }
@@ -1,18 +0,0 @@
1
- import React, { type ComponentType } from 'react';
2
-
3
- import { useWebApp } from './useWebApp.js';
4
- import type { WebApp } from './types.js';
5
-
6
- /**
7
- * HOC which passes WebApp SDK component to wrapped React component.
8
- * @param Component - component to wrap.
9
- */
10
- export function withWebApp<P extends { webApp?: WebApp }>(
11
- Component: ComponentType<P>,
12
- ): ComponentType<Omit<P, 'webApp'>> {
13
- return function WithWebApp(props: Omit<P, 'webApp'>) {
14
- const p = { ...props, webApp: useWebApp() } as P;
15
-
16
- return <Component {...p} />;
17
- };
18
- }
@@ -1,11 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- import type { SDKContext } from './types.js';
4
-
5
- export const sdkContext = createContext<SDKContext>({
6
- components: null,
7
- didInit: false,
8
- error: null,
9
- });
10
-
11
- sdkContext.displayName = 'SDKContext';
@@ -1,18 +0,0 @@
1
- import React, { type ComponentType } from 'react';
2
-
3
- import type { SDKContext } from './types.js';
4
- import { useSDK } from './hooks.js';
5
-
6
- /**
7
- * HOC which passes SDK context to wrapped React component.
8
- * @param Component - component to wrap.
9
- */
10
- export function withSDK<P extends { sdk?: SDKContext }>(
11
- Component: ComponentType<P>,
12
- ): ComponentType<Omit<P, 'sdk'>> {
13
- return function WithLaunchParams(props: Omit<P, 'sdk'>) {
14
- const p = { ...props, sdk: useSDK() } as P;
15
-
16
- return <Component {...p} />;
17
- };
18
- }
@@ -1,23 +0,0 @@
1
- import { useContext } from 'react';
2
-
3
- import { sdkContext } from './context.js';
4
- import type { SDKComponent, SDKComponentName } from './types.js';
5
-
6
- /**
7
- * Returns current SDK information.
8
- */
9
- export const useSDK = () => useContext(sdkContext);
10
-
11
- /**
12
- * Returns value by its field name from SDK init result.
13
- * @param name - component name.
14
- * @throws {Error} SDK is not initialized.
15
- */
16
- export function useUnit<N extends SDKComponentName>(name: N): SDKComponent<N> {
17
- const { components } = useSDK();
18
-
19
- if (components === null) {
20
- throw new Error(`Unable to get unit "${name}" as long as SDK is not initialized.`);
21
- }
22
- return components[name];
23
- }