@tma.js/sdk-solid 0.1.20 → 1.0.1
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/dist/dts/createHook.d.ts +14 -0
- package/dist/dts/index.d.ts +3 -6
- package/dist/dts/{context.d.ts → provider/SDKContext.d.ts} +1 -1
- package/dist/dts/provider/SDKProvider.d.ts +2 -0
- package/dist/dts/provider/index.d.ts +6 -0
- package/dist/dts/provider/types.d.ts +22 -0
- package/dist/dts/provider/useInitResultDynamicValue.d.ts +3 -0
- package/dist/dts/provider/useInitResultValue.d.ts +8 -0
- package/dist/dts/{hooks.d.ts → provider/useSDKContext.d.ts} +1 -1
- package/dist/dts/tools/back-button.d.ts +4 -0
- package/dist/dts/tools/closing-behavior.d.ts +4 -0
- package/dist/dts/tools/cloud-storage.d.ts +4 -0
- package/dist/dts/tools/haptic-feedback.d.ts +4 -0
- package/dist/dts/tools/index.d.ts +16 -0
- package/dist/dts/tools/init-data-raw.d.ts +4 -0
- package/dist/dts/tools/init-data.d.ts +4 -0
- package/dist/dts/tools/invoice.d.ts +4 -0
- package/dist/dts/tools/launch-params.d.ts +5 -0
- package/dist/dts/tools/main-button.d.ts +4 -0
- package/dist/dts/tools/mini-app.d.ts +4 -0
- package/dist/dts/tools/popup.d.ts +4 -0
- package/dist/dts/tools/post-event.d.ts +4 -0
- package/dist/dts/tools/qr-scanner.d.ts +4 -0
- package/dist/dts/tools/theme-params.d.ts +4 -0
- package/dist/dts/tools/utils.d.ts +4 -0
- package/dist/dts/tools/viewport.d.ts +4 -0
- package/dist/dts/types.d.ts +22 -10
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +59 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/createHook.ts +33 -0
- package/src/index.ts +28 -6
- package/src/provider/SDKContext.ts +9 -0
- package/src/provider/SDKProvider.tsx +21 -0
- package/src/provider/index.ts +6 -0
- package/src/provider/types.ts +26 -0
- package/src/provider/useInitResultDynamicValue.ts +34 -0
- package/src/provider/useInitResultValue.ts +23 -0
- package/src/provider/useSDKContext.ts +11 -0
- package/src/tools/back-button.ts +6 -0
- package/src/tools/closing-behavior.ts +6 -0
- package/src/tools/cloud-storage.ts +6 -0
- package/src/tools/haptic-feedback.ts +6 -0
- package/src/tools/index.ts +16 -0
- package/src/tools/init-data-raw.ts +6 -0
- package/src/tools/init-data.ts +6 -0
- package/src/tools/invoice.ts +6 -0
- package/src/tools/launch-params.tsx +8 -0
- package/src/tools/main-button.ts +6 -0
- package/src/tools/mini-app.ts +6 -0
- package/src/tools/popup.ts +6 -0
- package/src/tools/post-event.ts +6 -0
- package/src/tools/qr-scanner.ts +6 -0
- package/src/tools/theme-params.ts +6 -0
- package/src/tools/utils.ts +6 -0
- package/src/tools/viewport.ts +6 -0
- package/src/types.ts +29 -13
- package/dist/dts/SDKProvider.d.ts +0 -6
- package/dist/dts/useDynamicInitResultValue.d.ts +0 -21
- package/dist/dts/useInitResultValue.d.ts +0 -8
- package/dist/dts/useSDK.d.ts +0 -9
- package/src/SDKProvider.tsx +0 -24
- package/src/context.ts +0 -5
- package/src/hooks.ts +0 -16
- package/src/useDynamicInitResultValue.ts +0 -52
- package/src/useInitResultValue.ts +0 -14
- package/src/useSDK.ts +0 -54
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import type { DynamicInitResultKey, InitResultKey, InitResultValue, StaticInitResultKey } from './types.js';
|
|
3
|
+
export type Hook<K extends InitResultKey> = () => Accessor<InitResultValue<K>>;
|
|
4
|
+
/**
|
|
5
|
+
* Creates hook to retrieve static init result value.
|
|
6
|
+
* @param initResultKey - init result key.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createHook<K extends StaticInitResultKey>(initResultKey: K): Hook<K>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates hook to retrieve dynamic init result value.
|
|
11
|
+
* @param initResultKey - init result key.
|
|
12
|
+
* @param dynamic - flag to let function know this init result value is dynamic.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createHook<K extends DynamicInitResultKey>(initResultKey: K, dynamic: true): Hook<K>;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export * from './types.js';
|
|
5
|
-
export * from './useSDK.js';
|
|
6
|
-
export { classNames, mergeClassNames } from '@tma.js/utils';
|
|
1
|
+
export { useThemeParams, useInitData, useBackButton, useClosingBehavior, useInitDataRaw, useCloudStorage, useLaunchParams, useMainButton, useHapticFeedback, useInvoice, useMiniApp, usePopup, usePostEvent, useQRScanner, useUtils, useViewport, } from './tools/index.js';
|
|
2
|
+
export { useSDKContext, SDKProvider, type SDKProviderProps, type SDKContextType, } from './provider/index.js';
|
|
3
|
+
export type { InitOptions, InitResult, } from './types.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { SDKContextType } from './types.js';
|
|
2
|
-
export declare const SDKContext: import("solid-js").Context<SDKContextType
|
|
2
|
+
export declare const SDKContext: import("solid-js").Context<SDKContextType>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InitOptions, InitResult } from '@tma.js/sdk';
|
|
2
|
+
import type { Accessor, ParentProps } from 'solid-js';
|
|
3
|
+
export type SDKProviderProps = ParentProps<{
|
|
4
|
+
/**
|
|
5
|
+
* Init function options.
|
|
6
|
+
*/
|
|
7
|
+
options?: InitOptions;
|
|
8
|
+
}>;
|
|
9
|
+
export interface SDKContextType {
|
|
10
|
+
/**
|
|
11
|
+
* Error occurred during initialization.
|
|
12
|
+
*/
|
|
13
|
+
error: Accessor<unknown | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Initialization result.
|
|
16
|
+
*/
|
|
17
|
+
initResult: Accessor<InitResult | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* True if SDK is loading.
|
|
20
|
+
*/
|
|
21
|
+
loading: Accessor<boolean>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { InitResultKey, InitResultValue } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns value by its field name from SDK init result.
|
|
5
|
+
* @param key - init result key.
|
|
6
|
+
* @throws {Error} SDK is not initialized.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useInitResultValue<K extends InitResultKey>(key: K): Accessor<InitResultValue<K>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './back-button.js';
|
|
2
|
+
export * from './closing-behavior.js';
|
|
3
|
+
export * from './cloud-storage.js';
|
|
4
|
+
export * from './haptic-feedback.js';
|
|
5
|
+
export * from './init-data.js';
|
|
6
|
+
export * from './init-data-raw.js';
|
|
7
|
+
export * from './invoice.js';
|
|
8
|
+
export * from './launch-params.js';
|
|
9
|
+
export * from './main-button.js';
|
|
10
|
+
export * from './mini-app.js';
|
|
11
|
+
export * from './popup.js';
|
|
12
|
+
export * from './post-event.js';
|
|
13
|
+
export * from './qr-scanner.js';
|
|
14
|
+
export * from './theme-params.js';
|
|
15
|
+
export * from './viewport.js';
|
|
16
|
+
export * from './utils.js';
|
package/dist/dts/types.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export type SDKInitResultKey = keyof SDKInitResult;
|
|
6
|
-
export type SDKInitResultValue<K extends SDKInitResultKey> = SDKInitResult[K];
|
|
7
|
-
export interface SDKContextType {
|
|
8
|
-
initResult: Accessor<SDKInitResult | null>;
|
|
9
|
-
loading: Accessor<boolean>;
|
|
10
|
-
error: Accessor<unknown | null>;
|
|
1
|
+
import type { InitOptions, InitResult } from '@tma.js/sdk';
|
|
2
|
+
export { InitOptions, InitResult };
|
|
3
|
+
export interface Trackable {
|
|
4
|
+
on(event: 'change', listener: () => void): () => void;
|
|
11
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* SDK init result keys, which describe values with trackable changes.
|
|
8
|
+
*/
|
|
9
|
+
export type DynamicInitResultKey = {
|
|
10
|
+
[K in InitResultKey]-?: InitResultValue<K> extends Trackable ? K : never;
|
|
11
|
+
}[InitResultKey];
|
|
12
|
+
/**
|
|
13
|
+
* SDK init result keys, which describe static values.
|
|
14
|
+
*/
|
|
15
|
+
export type StaticInitResultKey = Exclude<InitResultKey, DynamicInitResultKey>;
|
|
16
|
+
/**
|
|
17
|
+
* SDK initialization result key.
|
|
18
|
+
*/
|
|
19
|
+
export type InitResultKey = keyof InitResult;
|
|
20
|
+
/**
|
|
21
|
+
* Returns SDK init result value type by its key.
|
|
22
|
+
*/
|
|
23
|
+
export type InitResultValue<K extends InitResultKey> = InitResult[K];
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("solid-js"),a=require("@tma.js/sdk"),i=n.createContext({loading:()=>!1,error:()=>{},initResult:()=>{}},{name:"SDKContext"});function d(o){const[t]=n.createResource(()=>o.options,a.init),s=n.createMemo(()=>t.state==="ready"?t():void 0),u=n.createMemo(()=>t.loading),r=n.createMemo(()=>t.error===void 0?null:t.error);return n.createComponent(i.Provider,{value:{initResult:s,loading:u,error:r},get children(){return o.children}})}function c(){return n.useContext(i)}function l(o){const{initResult:t}=c();return n.createMemo(()=>{const s=t();if(!s)throw new Error(`Unable to get init result key "${o}" as long as SDK is not initialized`);return s[o]})}function p(o){const t=l(o),[s,u]=n.createSignal(t(),{equals:!1});return n.createEffect(()=>{n.onCleanup(t().on("change",()=>{u(r=>r)}))}),s}function e(o,t){return t?()=>p(o):()=>l(o)}const m=e("backButton",!0),g=e("closingBehavior",!0),v=e("cloudStorage"),S=e("hapticFeedback"),h=e("initData"),D=e("initDataRaw"),f=e("invoice",!0);function P(){return a.retrieveLaunchData().launchParams}const C=e("mainButton",!0),B=e("miniApp",!0),R=e("popup",!0),M=e("postEvent"),k=e("qrScanner",!0),w=e("themeParams",!0),I=e("viewport",!0),b=e("utils");exports.SDKProvider=d;exports.useBackButton=m;exports.useClosingBehavior=g;exports.useCloudStorage=v;exports.useHapticFeedback=S;exports.useInitData=h;exports.useInitDataRaw=D;exports.useInvoice=f;exports.useLaunchParams=P;exports.useMainButton=C;exports.useMiniApp=B;exports.usePopup=R;exports.usePostEvent=M;exports.useQRScanner=k;exports.useSDKContext=c;exports.useThemeParams=w;exports.useUtils=b;exports.useViewport=I;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/provider/SDKContext.ts","../src/provider/SDKProvider.tsx","../src/provider/useSDKContext.ts","../src/provider/useInitResultValue.ts","../src/provider/useInitResultDynamicValue.ts","../src/createHook.ts","../src/tools/back-button.ts","../src/tools/closing-behavior.ts","../src/tools/cloud-storage.ts","../src/tools/haptic-feedback.ts","../src/tools/init-data.ts","../src/tools/init-data-raw.ts","../src/tools/invoice.ts","../src/tools/launch-params.tsx","../src/tools/main-button.ts","../src/tools/mini-app.ts","../src/tools/popup.ts","../src/tools/post-event.ts","../src/tools/qr-scanner.ts","../src/tools/theme-params.ts","../src/tools/viewport.ts","../src/tools/utils.ts"],"sourcesContent":["import { createContext } from 'solid-js';\n\nimport type { SDKContextType } from './types.js';\n\nexport const SDKContext = createContext<SDKContextType>({\n loading: () => false,\n error: () => undefined,\n initResult: () => undefined,\n}, { name: 'SDKContext' });\n","import { init } from '@tma.js/sdk';\nimport { createMemo, createResource } from 'solid-js';\n\nimport { SDKContext } from './SDKContext.js';\nimport type { SDKProviderProps } from './types.js';\n\nexport function SDKProvider(props: SDKProviderProps) {\n const [data] = createResource(() => props.options, init);\n\n const initResult = createMemo(() => {\n return data.state === 'ready' ? data() : undefined;\n });\n const loading = createMemo(() => data.loading);\n const error = createMemo(() => (data.error === undefined ? null : data.error));\n\n return (\n <SDKContext.Provider value={{ initResult, loading, error }}>\n {props.children}\n </SDKContext.Provider>\n );\n}\n","import { useContext } from 'solid-js';\n\nimport { SDKContext } from './SDKContext.js';\nimport type { SDKContextType } from './types.js';\n\n/**\n * Returns current SDK information.\n */\nexport function useSDKContext(): SDKContextType {\n return useContext(SDKContext);\n}\n","import { type Accessor, createMemo } from 'solid-js';\n\nimport { useSDKContext } from './useSDKContext.js';\nimport type { InitResultKey, InitResultValue } from '../types.js';\n\n/**\n * Returns value by its field name from SDK init result.\n * @param key - init result key.\n * @throws {Error} SDK is not initialized.\n */\nexport function useInitResultValue<K extends InitResultKey>(key: K): Accessor<InitResultValue<K>> {\n const { initResult } = useSDKContext();\n\n // eslint-disable-next-line solid/reactivity\n return createMemo<InitResultValue<K>>(() => {\n const result = initResult();\n\n if (!result) {\n throw new Error(`Unable to get init result key \"${key}\" as long as SDK is not initialized`);\n }\n return result[key];\n });\n}\n","import {\n type Accessor,\n createEffect,\n createSignal,\n onCleanup,\n} from 'solid-js';\n\nimport { useInitResultValue } from './useInitResultValue.js';\nimport type {\n DynamicInitResultKey,\n InitResultValue,\n Trackable,\n} from '../types.js';\n\nexport function useInitResultDynamicValue<K extends DynamicInitResultKey>(\n initResultKey: K,\n): Accessor<InitResultValue<K>> {\n // Extract init result value.\n const initial = useInitResultValue(initResultKey);\n\n // Create value which will be returned to the external environment.\n const [signal, setSignal] = createSignal(initial(), { equals: false });\n\n // Effect which listens to change event and calls update.\n createEffect(() => {\n onCleanup(\n (initial() as Trackable).on('change', () => {\n setSignal((prev) => prev);\n }),\n );\n });\n\n return signal;\n}\n","import type { Accessor } from 'solid-js';\n\nimport { useInitResultDynamicValue, useInitResultValue } from './provider/index.js';\nimport type {\n DynamicInitResultKey,\n InitResultKey,\n InitResultValue,\n StaticInitResultKey,\n} from './types.js';\n\nexport type Hook<K extends InitResultKey> = () => Accessor<InitResultValue<K>>;\n\n/**\n * Creates hook to retrieve static init result value.\n * @param initResultKey - init result key.\n */\nexport function createHook<K extends StaticInitResultKey>(initResultKey: K): Hook<K>;\n\n/**\n * Creates hook to retrieve dynamic init result value.\n * @param initResultKey - init result key.\n * @param dynamic - flag to let function know this init result value is dynamic.\n */\nexport function createHook<K extends DynamicInitResultKey>(\n initResultKey: K,\n dynamic: true,\n): Hook<K>;\n\nexport function createHook(initResultKey: InitResultKey, dynamic?: true): Hook<any> {\n return dynamic\n ? () => useInitResultDynamicValue(initResultKey as DynamicInitResultKey)\n : () => useInitResultValue(initResultKey);\n}\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve BackButton component.\n */\nexport const useBackButton = createHook('backButton', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve ClosingBehavior component.\n */\nexport const useClosingBehavior = createHook('closingBehavior', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve CloudStorage component.\n */\nexport const useCloudStorage = createHook('cloudStorage');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve HapticFeedback component.\n */\nexport const useHapticFeedback = createHook('hapticFeedback');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve InitData component.\n */\nexport const useInitData = createHook('initData');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve init data raw representation.\n */\nexport const useInitDataRaw = createHook('initDataRaw');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Invoice component.\n */\nexport const useInvoice = createHook('invoice', true);\n","import { type LaunchParams, retrieveLaunchData } from '@tma.js/sdk';\n\n/**\n * Hooks to retrieve launch parameters.\n */\nexport function useLaunchParams(): LaunchParams {\n return retrieveLaunchData().launchParams;\n}\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve MainButton component.\n */\nexport const useMainButton = createHook('mainButton', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve MiniApp component.\n */\nexport const useMiniApp = createHook('miniApp', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Popup component.\n */\nexport const usePopup = createHook('popup', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve postEvent function.\n */\nexport const usePostEvent = createHook('postEvent');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve QRScanner component.\n */\nexport const useQRScanner = createHook('qrScanner', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve ThemeParams component.\n */\nexport const useThemeParams = createHook('themeParams', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Viewport component.\n */\nexport const useViewport = createHook('viewport', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Utils component.\n */\nexport const useUtils = createHook('utils');\n"],"names":["SDKContext","createContext","SDKProvider","props","data","createResource","options","init","initResult","createMemo","state","undefined","loading","error","_$createComponent","Provider","value","children","useSDKContext","useContext","useInitResultValue","key","result","useInitResultDynamicValue","initResultKey","initial","signal","setSignal","createSignal","createEffect","onCleanup","prev","createHook","dynamic","useBackButton","useClosingBehavior","useCloudStorage","useHapticFeedback","useInitData","useInitDataRaw","useInvoice","useLaunchParams","retrieveLaunchData","launchParams","useMainButton","useMiniApp","usePopup","usePostEvent","useQRScanner","useThemeParams","useViewport","useUtils"],"mappings":"qIAIaA,EAAaC,EAAAA,cAA8B,CACtD,QAAS,IAAM,GACf,MAAO,IAAM,GACb,WAAY,IAAM,EACpB,EAAG,CAAE,KAAM,aAAc,ECFlB,SAASC,EAAYC,EAAyB,CACnD,KAAM,CAACC,CAAI,EAAIC,EAAc,eAAC,IAAMF,EAAMG,QAASC,EAAAA,IAAI,EAEjDC,EAAaC,EAAAA,WAAW,IACrBL,EAAKM,QAAU,QAAUN,EAAI,EAAKO,MAC1C,EACKC,EAAUH,EAAU,WAAC,IAAML,EAAKQ,OAAO,EACvCC,EAAQJ,aAAW,IAAOL,EAAKS,QAAUF,OAAY,KAAOP,EAAKS,KAAM,EAE7E,OAAAC,EAAA,gBACGd,EAAWe,SAAQ,CAACC,MAAO,CAAER,WAAAA,EAAYI,QAAAA,EAASC,MAAAA,CAAO,EAAA,IAAAI,UAAA,CAAA,OACvDd,EAAMc,QAAQ,CAAA,CAAA,CAGrB,CCZO,SAASC,GAAgC,CAC9C,OAAOC,EAAAA,WAAWnB,CAAU,CAC9B,CCAO,SAASoB,EAA4CC,EAAsC,CAC1F,KAAA,CAAE,WAAAb,GAAeU,IAGvB,OAAOT,aAA+B,IAAM,CAC1C,MAAMa,EAASd,IAEf,GAAI,CAACc,EACH,MAAM,IAAI,MAAM,kCAAkCD,CAAG,qCAAqC,EAE5F,OAAOC,EAAOD,CAAG,CAAA,CAClB,CACH,CCRO,SAASE,EACdC,EAC8B,CAExB,MAAAC,EAAUL,EAAmBI,CAAa,EAG1C,CAACE,EAAQC,CAAS,EAAIC,EAAA,aAAaH,IAAW,CAAE,OAAQ,EAAA,CAAO,EAGrEI,OAAAA,EAAAA,aAAa,IAAM,CACjBC,EAAA,UACGL,EAAQ,EAAgB,GAAG,SAAU,IAAM,CAChCE,EAACI,GAASA,CAAI,CAAA,CACzB,CAAA,CACH,CACD,EAEML,CACT,CCLgB,SAAAM,EAAWR,EAA8BS,EAA2B,CAClF,OAAOA,EACH,IAAMV,EAA0BC,CAAqC,EACrE,IAAMJ,EAAmBI,CAAa,CAC5C,CC3Ba,MAAAU,EAAgBF,EAAW,aAAc,EAAI,ECA7CG,EAAqBH,EAAW,kBAAmB,EAAI,ECAvDI,EAAkBJ,EAAW,cAAc,ECA3CK,EAAoBL,EAAW,gBAAgB,ECA/CM,EAAcN,EAAW,UAAU,ECAnCO,EAAiBP,EAAW,aAAa,ECAzCQ,EAAaR,EAAW,UAAW,EAAI,ECA7C,SAASS,GAAgC,CAC9C,OAAOC,EAAAA,mBAAoB,EAACC,YAC9B,CCFa,MAAAC,EAAgBZ,EAAW,aAAc,EAAI,ECA7Ca,EAAab,EAAW,UAAW,EAAI,ECAvCc,EAAWd,EAAW,QAAS,EAAI,ECAnCe,EAAef,EAAW,WAAW,ECArCgB,EAAehB,EAAW,YAAa,EAAI,ECA3CiB,EAAiBjB,EAAW,cAAe,EAAI,ECA/CkB,EAAclB,EAAW,WAAY,EAAI,ECAzCmB,EAAWnB,EAAW,OAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,81 +1,73 @@
|
|
|
1
|
-
import { createContext as
|
|
2
|
-
import { init as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return f(h.Provider, {
|
|
1
|
+
import { createContext as c, createResource as l, createMemo as r, createComponent as d, useContext as p, createSignal as m, createEffect as f, onCleanup as g } from "solid-js";
|
|
2
|
+
import { init as v, retrieveLaunchData as h } from "@tma.js/sdk";
|
|
3
|
+
const a = c({
|
|
4
|
+
loading: () => !1,
|
|
5
|
+
error: () => {
|
|
6
|
+
},
|
|
7
|
+
initResult: () => {
|
|
8
|
+
}
|
|
9
|
+
}, { name: "SDKContext" });
|
|
10
|
+
function R(n) {
|
|
11
|
+
const [e] = l(() => n.options, v), o = r(() => e.state === "ready" ? e() : void 0), u = r(() => e.loading), s = r(() => e.error === void 0 ? null : e.error);
|
|
12
|
+
return d(a.Provider, {
|
|
14
13
|
value: {
|
|
15
|
-
initResult:
|
|
14
|
+
initResult: o,
|
|
16
15
|
loading: u,
|
|
17
|
-
error:
|
|
16
|
+
error: s
|
|
18
17
|
},
|
|
19
18
|
get children() {
|
|
20
|
-
return
|
|
19
|
+
return n.children;
|
|
21
20
|
}
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
23
|
+
function D() {
|
|
24
|
+
return p(a);
|
|
25
|
+
}
|
|
26
|
+
function i(n) {
|
|
27
|
+
const { initResult: e } = D();
|
|
28
|
+
return r(() => {
|
|
29
|
+
const o = e();
|
|
30
|
+
if (!o)
|
|
31
|
+
throw new Error(`Unable to get init result key "${n}" as long as SDK is not initialized`);
|
|
32
|
+
return o[n];
|
|
33
|
+
});
|
|
26
34
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}), u;
|
|
35
|
+
function S(n) {
|
|
36
|
+
const e = i(n), [o, u] = m(e(), { equals: !1 });
|
|
37
|
+
return f(() => {
|
|
38
|
+
g(
|
|
39
|
+
e().on("change", () => {
|
|
40
|
+
u((s) => s);
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}), o;
|
|
37
44
|
}
|
|
45
|
+
function t(n, e) {
|
|
46
|
+
return e ? () => S(n) : () => i(n);
|
|
47
|
+
}
|
|
48
|
+
const B = t("backButton", !0), w = t("closingBehavior", !0), x = t("cloudStorage"), k = t("hapticFeedback"), I = t("initData"), b = t("initDataRaw"), E = t("invoice", !0);
|
|
38
49
|
function K() {
|
|
39
|
-
|
|
40
|
-
const n = t();
|
|
41
|
-
if (n === null)
|
|
42
|
-
throw new Error("Unable to use SDK as it is not ready.");
|
|
43
|
-
return n;
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
backButton: o(e, "backButton", ["isVisibleChanged"]),
|
|
47
|
-
closingBehavior: o(e, "closingBehavior", ["isConfirmationNeededChanged"]),
|
|
48
|
-
cloudStorage: a(e, "cloudStorage"),
|
|
49
|
-
haptic: a(e, "haptic"),
|
|
50
|
-
initData: a(e, "initData"),
|
|
51
|
-
initDataRaw: a(e, "initDataRaw"),
|
|
52
|
-
mainButton: o(e, "mainButton", [
|
|
53
|
-
"backgroundColorChanged",
|
|
54
|
-
"isVisibleChanged",
|
|
55
|
-
"isProgressVisibleChanged",
|
|
56
|
-
"isEnabledChanged",
|
|
57
|
-
"textChanged",
|
|
58
|
-
"textColorChanged"
|
|
59
|
-
]),
|
|
60
|
-
popup: o(e, "popup", ["isOpenedChanged"]),
|
|
61
|
-
postEvent: a(e, "postEvent"),
|
|
62
|
-
qrScanner: o(e, "qrScanner", ["isOpenedChanged"]),
|
|
63
|
-
themeParams: o(e, "themeParams", ["changed"]),
|
|
64
|
-
viewport: o(e, "viewport", [
|
|
65
|
-
"heightChanged",
|
|
66
|
-
"isExpandedChanged",
|
|
67
|
-
"stableHeightChanged",
|
|
68
|
-
"widthChanged"
|
|
69
|
-
]),
|
|
70
|
-
webApp: o(e, "webApp", ["backgroundColorChanged", "headerColorChanged"])
|
|
71
|
-
};
|
|
50
|
+
return h().launchParams;
|
|
72
51
|
}
|
|
52
|
+
const M = t("mainButton", !0), V = t("miniApp", !0), q = t("popup", !0), A = t("postEvent"), F = t("qrScanner", !0), H = t("themeParams", !0), L = t("viewport", !0), U = t("utils");
|
|
73
53
|
export {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
54
|
+
R as SDKProvider,
|
|
55
|
+
B as useBackButton,
|
|
56
|
+
w as useClosingBehavior,
|
|
57
|
+
x as useCloudStorage,
|
|
58
|
+
k as useHapticFeedback,
|
|
59
|
+
I as useInitData,
|
|
60
|
+
b as useInitDataRaw,
|
|
61
|
+
E as useInvoice,
|
|
62
|
+
K as useLaunchParams,
|
|
63
|
+
M as useMainButton,
|
|
64
|
+
V as useMiniApp,
|
|
65
|
+
q as usePopup,
|
|
66
|
+
A as usePostEvent,
|
|
67
|
+
F as useQRScanner,
|
|
68
|
+
D as useSDKContext,
|
|
69
|
+
H as useThemeParams,
|
|
70
|
+
U as useUtils,
|
|
71
|
+
L as useViewport
|
|
80
72
|
};
|
|
81
73
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/provider/SDKContext.ts","../src/provider/SDKProvider.tsx","../src/provider/useSDKContext.ts","../src/provider/useInitResultValue.ts","../src/provider/useInitResultDynamicValue.ts","../src/createHook.ts","../src/tools/back-button.ts","../src/tools/closing-behavior.ts","../src/tools/cloud-storage.ts","../src/tools/haptic-feedback.ts","../src/tools/init-data.ts","../src/tools/init-data-raw.ts","../src/tools/invoice.ts","../src/tools/launch-params.tsx","../src/tools/main-button.ts","../src/tools/mini-app.ts","../src/tools/popup.ts","../src/tools/post-event.ts","../src/tools/qr-scanner.ts","../src/tools/theme-params.ts","../src/tools/viewport.ts","../src/tools/utils.ts"],"sourcesContent":["import { createContext } from 'solid-js';\n\nimport type { SDKContextType } from './types.js';\n\nexport const SDKContext = createContext<SDKContextType>({\n loading: () => false,\n error: () => undefined,\n initResult: () => undefined,\n}, { name: 'SDKContext' });\n","import { init } from '@tma.js/sdk';\nimport { createMemo, createResource } from 'solid-js';\n\nimport { SDKContext } from './SDKContext.js';\nimport type { SDKProviderProps } from './types.js';\n\nexport function SDKProvider(props: SDKProviderProps) {\n const [data] = createResource(() => props.options, init);\n\n const initResult = createMemo(() => {\n return data.state === 'ready' ? data() : undefined;\n });\n const loading = createMemo(() => data.loading);\n const error = createMemo(() => (data.error === undefined ? null : data.error));\n\n return (\n <SDKContext.Provider value={{ initResult, loading, error }}>\n {props.children}\n </SDKContext.Provider>\n );\n}\n","import { useContext } from 'solid-js';\n\nimport { SDKContext } from './SDKContext.js';\nimport type { SDKContextType } from './types.js';\n\n/**\n * Returns current SDK information.\n */\nexport function useSDKContext(): SDKContextType {\n return useContext(SDKContext);\n}\n","import { type Accessor, createMemo } from 'solid-js';\n\nimport { useSDKContext } from './useSDKContext.js';\nimport type { InitResultKey, InitResultValue } from '../types.js';\n\n/**\n * Returns value by its field name from SDK init result.\n * @param key - init result key.\n * @throws {Error} SDK is not initialized.\n */\nexport function useInitResultValue<K extends InitResultKey>(key: K): Accessor<InitResultValue<K>> {\n const { initResult } = useSDKContext();\n\n // eslint-disable-next-line solid/reactivity\n return createMemo<InitResultValue<K>>(() => {\n const result = initResult();\n\n if (!result) {\n throw new Error(`Unable to get init result key \"${key}\" as long as SDK is not initialized`);\n }\n return result[key];\n });\n}\n","import {\n type Accessor,\n createEffect,\n createSignal,\n onCleanup,\n} from 'solid-js';\n\nimport { useInitResultValue } from './useInitResultValue.js';\nimport type {\n DynamicInitResultKey,\n InitResultValue,\n Trackable,\n} from '../types.js';\n\nexport function useInitResultDynamicValue<K extends DynamicInitResultKey>(\n initResultKey: K,\n): Accessor<InitResultValue<K>> {\n // Extract init result value.\n const initial = useInitResultValue(initResultKey);\n\n // Create value which will be returned to the external environment.\n const [signal, setSignal] = createSignal(initial(), { equals: false });\n\n // Effect which listens to change event and calls update.\n createEffect(() => {\n onCleanup(\n (initial() as Trackable).on('change', () => {\n setSignal((prev) => prev);\n }),\n );\n });\n\n return signal;\n}\n","import type { Accessor } from 'solid-js';\n\nimport { useInitResultDynamicValue, useInitResultValue } from './provider/index.js';\nimport type {\n DynamicInitResultKey,\n InitResultKey,\n InitResultValue,\n StaticInitResultKey,\n} from './types.js';\n\nexport type Hook<K extends InitResultKey> = () => Accessor<InitResultValue<K>>;\n\n/**\n * Creates hook to retrieve static init result value.\n * @param initResultKey - init result key.\n */\nexport function createHook<K extends StaticInitResultKey>(initResultKey: K): Hook<K>;\n\n/**\n * Creates hook to retrieve dynamic init result value.\n * @param initResultKey - init result key.\n * @param dynamic - flag to let function know this init result value is dynamic.\n */\nexport function createHook<K extends DynamicInitResultKey>(\n initResultKey: K,\n dynamic: true,\n): Hook<K>;\n\nexport function createHook(initResultKey: InitResultKey, dynamic?: true): Hook<any> {\n return dynamic\n ? () => useInitResultDynamicValue(initResultKey as DynamicInitResultKey)\n : () => useInitResultValue(initResultKey);\n}\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve BackButton component.\n */\nexport const useBackButton = createHook('backButton', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve ClosingBehavior component.\n */\nexport const useClosingBehavior = createHook('closingBehavior', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve CloudStorage component.\n */\nexport const useCloudStorage = createHook('cloudStorage');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve HapticFeedback component.\n */\nexport const useHapticFeedback = createHook('hapticFeedback');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve InitData component.\n */\nexport const useInitData = createHook('initData');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve init data raw representation.\n */\nexport const useInitDataRaw = createHook('initDataRaw');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Invoice component.\n */\nexport const useInvoice = createHook('invoice', true);\n","import { type LaunchParams, retrieveLaunchData } from '@tma.js/sdk';\n\n/**\n * Hooks to retrieve launch parameters.\n */\nexport function useLaunchParams(): LaunchParams {\n return retrieveLaunchData().launchParams;\n}\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve MainButton component.\n */\nexport const useMainButton = createHook('mainButton', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve MiniApp component.\n */\nexport const useMiniApp = createHook('miniApp', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Popup component.\n */\nexport const usePopup = createHook('popup', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve postEvent function.\n */\nexport const usePostEvent = createHook('postEvent');\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve QRScanner component.\n */\nexport const useQRScanner = createHook('qrScanner', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve ThemeParams component.\n */\nexport const useThemeParams = createHook('themeParams', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Viewport component.\n */\nexport const useViewport = createHook('viewport', true);\n","import { createHook } from '../createHook.js';\n\n/**\n * Hook to retrieve Utils component.\n */\nexport const useUtils = createHook('utils');\n"],"names":["SDKContext","createContext","SDKProvider","props","data","createResource","options","init","initResult","createMemo","state","undefined","loading","error","_$createComponent","Provider","value","children","useSDKContext","useContext","useInitResultValue","key","result","useInitResultDynamicValue","initResultKey","initial","signal","setSignal","createSignal","createEffect","onCleanup","prev","createHook","dynamic","useBackButton","useClosingBehavior","useCloudStorage","useHapticFeedback","useInitData","useInitDataRaw","useInvoice","useLaunchParams","retrieveLaunchData","launchParams","useMainButton","useMiniApp","usePopup","usePostEvent","useQRScanner","useThemeParams","useViewport","useUtils"],"mappings":";;AAIO,MAAMA,IAAaC,EAA8B;AAAA,EACtD,SAAS,MAAM;AAAA,EACf,OAAO,MAAM;AAAA;AAAA,EACb,YAAY,MAAM;AAAA;AACpB,GAAG,EAAE,MAAM,cAAc;ACFlB,SAASC,EAAYC,GAAyB;AACnD,QAAM,CAACC,CAAI,IAAIC,EAAe,MAAMF,EAAMG,SAASC,CAAI,GAEjDC,IAAaC,EAAW,MACrBL,EAAKM,UAAU,UAAUN,EAAI,IAAKO,MAC1C,GACKC,IAAUH,EAAW,MAAML,EAAKQ,OAAO,GACvCC,IAAQJ,EAAW,MAAOL,EAAKS,UAAUF,SAAY,OAAOP,EAAKS,KAAM;AAE7E,SAAAC,EACGd,EAAWe,UAAQ;AAAA,IAACC,OAAO;AAAA,MAAER,YAAAA;AAAAA,MAAYI,SAAAA;AAAAA,MAASC,OAAAA;AAAAA,IAAO;AAAA,IAAA,IAAAI,WAAA;AAAA,aACvDd,EAAMc;AAAAA,IAAQ;AAAA,EAAA,CAAA;AAGrB;ACZO,SAASC,IAAgC;AAC9C,SAAOC,EAAWnB,CAAU;AAC9B;ACAO,SAASoB,EAA4CC,GAAsC;AAC1F,QAAA,EAAE,YAAAb,MAAeU;AAGvB,SAAOT,EAA+B,MAAM;AAC1C,UAAMa,IAASd;AAEf,QAAI,CAACc;AACH,YAAM,IAAI,MAAM,kCAAkCD,CAAG,qCAAqC;AAE5F,WAAOC,EAAOD,CAAG;AAAA,EAAA,CAClB;AACH;ACRO,SAASE,EACdC,GAC8B;AAExB,QAAAC,IAAUL,EAAmBI,CAAa,GAG1C,CAACE,GAAQC,CAAS,IAAIC,EAAaH,KAAW,EAAE,QAAQ,GAAA,CAAO;AAGrE,SAAAI,EAAa,MAAM;AACjB,IAAAC;AAAA,MACGL,EAAQ,EAAgB,GAAG,UAAU,MAAM;AAChC,QAAAE,EAAA,CAACI,MAASA,CAAI;AAAA,MAAA,CACzB;AAAA,IAAA;AAAA,EACH,CACD,GAEML;AACT;ACLgB,SAAAM,EAAWR,GAA8BS,GAA2B;AAClF,SAAOA,IACH,MAAMV,EAA0BC,CAAqC,IACrE,MAAMJ,EAAmBI,CAAa;AAC5C;AC3Ba,MAAAU,IAAgBF,EAAW,cAAc,EAAI,GCA7CG,IAAqBH,EAAW,mBAAmB,EAAI,GCAvDI,IAAkBJ,EAAW,cAAc,GCA3CK,IAAoBL,EAAW,gBAAgB,GCA/CM,IAAcN,EAAW,UAAU,GCAnCO,IAAiBP,EAAW,aAAa,GCAzCQ,IAAaR,EAAW,WAAW,EAAI;ACA7C,SAASS,IAAgC;AAC9C,SAAOC,EAAoB,EAACC;AAC9B;ACFa,MAAAC,IAAgBZ,EAAW,cAAc,EAAI,GCA7Ca,IAAab,EAAW,WAAW,EAAI,GCAvCc,IAAWd,EAAW,SAAS,EAAI,GCAnCe,IAAef,EAAW,WAAW,GCArCgB,IAAehB,EAAW,aAAa,EAAI,GCA3CiB,IAAiBjB,EAAW,eAAe,EAAI,GCA/CkB,IAAclB,EAAW,YAAY,EAAI,GCAzCmB,IAAWnB,EAAW,OAAO;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tma.js/sdk-solid",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Solid JS bindings for Mini Apps client SDK.",
|
|
5
5
|
"author": "Vladislav Kibenko <wolfram.deus@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/Telegram-Mini-Apps/tma.js#readme",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tma.js/
|
|
41
|
-
"@tma.js/sdk": "0.13.3"
|
|
40
|
+
"@tma.js/sdk": "1.0.1"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
44
43
|
"solid-js": "^1.0.0"
|
|
@@ -52,8 +51,9 @@
|
|
|
52
51
|
"access": "public"
|
|
53
52
|
},
|
|
54
53
|
"scripts": {
|
|
55
|
-
"lint": "eslint
|
|
56
|
-
"
|
|
54
|
+
"lint": "eslint src/**/*",
|
|
55
|
+
"lint:fix": "pnpm run lint --fix",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
57
|
"build": "vite build"
|
|
58
58
|
}
|
|
59
59
|
}
|