@tma.js/sdk-react 2.2.6 → 2.2.7
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as re, useContext as ie, useState as rt, useEffect as
|
|
1
|
+
import { jsx as xt } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as re, useContext as ie, useState as rt, useEffect as x, useRef as bt, useCallback as oe, useMemo as ae } from "react";
|
|
3
3
|
var ce = Object.defineProperty, he = (e, t, s) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, c = (e, t, s) => he(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
-
function
|
|
4
|
+
function Rt(e, t) {
|
|
5
5
|
let s;
|
|
6
6
|
const n = () => {
|
|
7
7
|
s !== void 0 && t && t(s), s = void 0;
|
|
@@ -238,7 +238,7 @@ function w(e, t) {
|
|
|
238
238
|
return Tt(e, (r) => n[r]);
|
|
239
239
|
}, !1, t);
|
|
240
240
|
}
|
|
241
|
-
const
|
|
241
|
+
const R = A((e) => {
|
|
242
242
|
if (typeof e == "number")
|
|
243
243
|
return e;
|
|
244
244
|
if (typeof e == "string") {
|
|
@@ -283,7 +283,7 @@ function kt(e) {
|
|
|
283
283
|
eventData: (t) => t
|
|
284
284
|
}).parse(e);
|
|
285
285
|
}
|
|
286
|
-
function
|
|
286
|
+
function xe() {
|
|
287
287
|
["TelegramGameProxy_receiveEvent", "TelegramGameProxy", "Telegram"].forEach((e) => {
|
|
288
288
|
delete window[e];
|
|
289
289
|
});
|
|
@@ -295,7 +295,7 @@ function et(e, t) {
|
|
|
295
295
|
source: window.parent
|
|
296
296
|
}));
|
|
297
297
|
}
|
|
298
|
-
function
|
|
298
|
+
function Re() {
|
|
299
299
|
[
|
|
300
300
|
["TelegramGameProxy_receiveEvent"],
|
|
301
301
|
// Windows Phone.
|
|
@@ -341,8 +341,8 @@ const Ce = {
|
|
|
341
341
|
}
|
|
342
342
|
}),
|
|
343
343
|
viewport_changed: w({
|
|
344
|
-
height:
|
|
345
|
-
width: (e) => e == null ? window.innerWidth :
|
|
344
|
+
height: R(),
|
|
345
|
+
width: (e) => e == null ? window.innerWidth : R().parse(e),
|
|
346
346
|
is_state_stable: E(),
|
|
347
347
|
is_expanded: E()
|
|
348
348
|
}),
|
|
@@ -352,10 +352,10 @@ function Se() {
|
|
|
352
352
|
const e = new D(), t = new D();
|
|
353
353
|
t.subscribe((n) => {
|
|
354
354
|
e.emit("event", { name: n.event, payload: n.args[0] });
|
|
355
|
-
}),
|
|
355
|
+
}), Re();
|
|
356
356
|
const [, s] = ot(
|
|
357
357
|
// Don't forget to remove created handlers.
|
|
358
|
-
|
|
358
|
+
xe,
|
|
359
359
|
// Add "resize" event listener to make sure, we always have fresh viewport information.
|
|
360
360
|
// Desktop version of Telegram is sometimes not sending the viewport_changed
|
|
361
361
|
// event. For example, when the MainButton is shown. That's why we should
|
|
@@ -410,7 +410,7 @@ function Se() {
|
|
|
410
410
|
}
|
|
411
411
|
}, s];
|
|
412
412
|
}
|
|
413
|
-
const [Te, Ae] =
|
|
413
|
+
const [Te, Ae] = Rt(
|
|
414
414
|
(e) => {
|
|
415
415
|
const [t, s] = Se(), n = t.off.bind(t);
|
|
416
416
|
return t.off = (r, i) => {
|
|
@@ -695,7 +695,7 @@ class Ne extends ut {
|
|
|
695
695
|
this.isVisible = !0;
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
|
-
const $t = A((e) => e instanceof Date ? e : new Date(
|
|
698
|
+
const $t = A((e) => e instanceof Date ? e : new Date(R().parse(e) * 1e3), "Date");
|
|
699
699
|
function lt(e, t) {
|
|
700
700
|
return new G((s) => {
|
|
701
701
|
if (typeof s != "string" && !(s instanceof URLSearchParams))
|
|
@@ -708,7 +708,7 @@ function lt(e, t) {
|
|
|
708
708
|
}, !1, t);
|
|
709
709
|
}
|
|
710
710
|
const De = w({
|
|
711
|
-
id:
|
|
711
|
+
id: R(),
|
|
712
712
|
type: h(),
|
|
713
713
|
title: h(),
|
|
714
714
|
photoUrl: {
|
|
@@ -729,7 +729,7 @@ const De = w({
|
|
|
729
729
|
type: h(),
|
|
730
730
|
from: "first_name"
|
|
731
731
|
},
|
|
732
|
-
id:
|
|
732
|
+
id: R(),
|
|
733
733
|
isBot: {
|
|
734
734
|
type: E().optional(),
|
|
735
735
|
from: "is_bot"
|
|
@@ -759,7 +759,7 @@ function Ht() {
|
|
|
759
759
|
from: "auth_date"
|
|
760
760
|
},
|
|
761
761
|
canSendAfter: {
|
|
762
|
-
type:
|
|
762
|
+
type: R().optional(),
|
|
763
763
|
from: "can_send_after"
|
|
764
764
|
},
|
|
765
765
|
chat: De,
|
|
@@ -913,7 +913,7 @@ function Ue() {
|
|
|
913
913
|
let e = 0;
|
|
914
914
|
return () => (e += 1).toString();
|
|
915
915
|
}
|
|
916
|
-
const [We] =
|
|
916
|
+
const [We] = Rt(Ue);
|
|
917
917
|
function l(e, t) {
|
|
918
918
|
return () => {
|
|
919
919
|
const s = nt(), n = {
|
|
@@ -1570,7 +1570,7 @@ function hs() {
|
|
|
1570
1570
|
return lt({
|
|
1571
1571
|
contact: w({
|
|
1572
1572
|
userId: {
|
|
1573
|
-
type:
|
|
1573
|
+
type: R(),
|
|
1574
1574
|
from: "user_id"
|
|
1575
1575
|
},
|
|
1576
1576
|
phoneNumber: {
|
|
@@ -1873,7 +1873,7 @@ class gs extends L {
|
|
|
1873
1873
|
}), this.postEvent = n;
|
|
1874
1874
|
}
|
|
1875
1875
|
/**
|
|
1876
|
-
* Closes scanner.
|
|
1876
|
+
* Closes the scanner.
|
|
1877
1877
|
*/
|
|
1878
1878
|
close() {
|
|
1879
1879
|
this.postEvent("web_app_close_scan_qr_popup"), this.isOpened = !1;
|
|
@@ -1882,14 +1882,14 @@ class gs extends L {
|
|
|
1882
1882
|
this.set("isOpened", t);
|
|
1883
1883
|
}
|
|
1884
1884
|
/**
|
|
1885
|
-
* Returns true
|
|
1885
|
+
* Returns true if the scanner is currently opened.
|
|
1886
1886
|
*/
|
|
1887
1887
|
get isOpened() {
|
|
1888
1888
|
return this.get("isOpened");
|
|
1889
1889
|
}
|
|
1890
1890
|
async open(t) {
|
|
1891
1891
|
if (this.isOpened)
|
|
1892
|
-
throw new Error("
|
|
1892
|
+
throw new Error("The scanner is already opened");
|
|
1893
1893
|
const { text: s, capture: n } = (typeof t == "string" ? { text: t } : t) || {};
|
|
1894
1894
|
this.isOpened = !0;
|
|
1895
1895
|
try {
|
|
@@ -1903,10 +1903,11 @@ class gs extends L {
|
|
|
1903
1903
|
}
|
|
1904
1904
|
}) || {}).data || null;
|
|
1905
1905
|
return r && this.close(), r;
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1906
|
+
} finally {
|
|
1907
|
+
this.isOpened = !1;
|
|
1908
1908
|
}
|
|
1909
1909
|
}
|
|
1910
|
+
// TODO: Streaming mode, allowing to scan several QRs until closed.
|
|
1910
1911
|
}
|
|
1911
1912
|
const fs = l(
|
|
1912
1913
|
({ version: e, postEvent: t }) => new gs(!1, e, t)
|
|
@@ -2143,7 +2144,7 @@ async function te(e = {}) {
|
|
|
2143
2144
|
function q(e) {
|
|
2144
2145
|
return e < 0 ? 0 : e;
|
|
2145
2146
|
}
|
|
2146
|
-
class
|
|
2147
|
+
class xs extends _t {
|
|
2147
2148
|
constructor({ postEvent: t, stableHeight: s, height: n, width: r, isExpanded: i }) {
|
|
2148
2149
|
super({
|
|
2149
2150
|
height: q(n),
|
|
@@ -2250,7 +2251,7 @@ class Rs extends _t {
|
|
|
2250
2251
|
return this.stableHeight === this.height;
|
|
2251
2252
|
}
|
|
2252
2253
|
}
|
|
2253
|
-
const
|
|
2254
|
+
const Rs = l(
|
|
2254
2255
|
"viewport",
|
|
2255
2256
|
async ({ state: e, platform: t, postEvent: s, addCleanup: n }) => {
|
|
2256
2257
|
let r = !1, i = 0, o = 0, a = 0;
|
|
@@ -2262,7 +2263,7 @@ const xs = l(
|
|
|
2262
2263
|
const u = await te({ timeout: 1e3, postEvent: s });
|
|
2263
2264
|
r = u.isExpanded, i = u.height, o = u.width, a = u.isStateStable ? i : 0;
|
|
2264
2265
|
}
|
|
2265
|
-
const p = new
|
|
2266
|
+
const p = new xs({
|
|
2266
2267
|
postEvent: s,
|
|
2267
2268
|
height: i,
|
|
2268
2269
|
width: o,
|
|
@@ -2386,7 +2387,7 @@ function Pn(e) {
|
|
|
2386
2387
|
function Ts(e) {
|
|
2387
2388
|
return e instanceof W;
|
|
2388
2389
|
}
|
|
2389
|
-
function
|
|
2390
|
+
function xn(e, t) {
|
|
2390
2391
|
return Ts(e) && e.type === t;
|
|
2391
2392
|
}
|
|
2392
2393
|
function J(e, t) {
|
|
@@ -2783,7 +2784,7 @@ function ks(e) {
|
|
|
2783
2784
|
}
|
|
2784
2785
|
return new se([n], 0, e);
|
|
2785
2786
|
}
|
|
2786
|
-
function
|
|
2787
|
+
function Rn(e) {
|
|
2787
2788
|
const t = e.match(/#(.+)/);
|
|
2788
2789
|
return t ? t[1] : null;
|
|
2789
2790
|
}
|
|
@@ -2819,7 +2820,7 @@ function d(e, t) {
|
|
|
2819
2820
|
...p,
|
|
2820
2821
|
[i]: n(o)
|
|
2821
2822
|
};
|
|
2822
|
-
return /* @__PURE__ */
|
|
2823
|
+
return /* @__PURE__ */ xt(a, { ...u });
|
|
2823
2824
|
};
|
|
2824
2825
|
};
|
|
2825
2826
|
}
|
|
@@ -2841,7 +2842,7 @@ function _(e) {
|
|
|
2841
2842
|
return r.use(e);
|
|
2842
2843
|
}
|
|
2843
2844
|
);
|
|
2844
|
-
return
|
|
2845
|
+
return x(() => {
|
|
2845
2846
|
o(r.use(e));
|
|
2846
2847
|
}, [r]), i;
|
|
2847
2848
|
}
|
|
@@ -2876,11 +2877,11 @@ const [Ns, Ds] = _(Ge), [Sn, Tn] = d(
|
|
|
2876
2877
|
), [rn, on] = _(ys), [Yn, Zn] = d(rn, on);
|
|
2877
2878
|
function Xn(e) {
|
|
2878
2879
|
const [t, s] = rt(() => e ? void 0 : nt());
|
|
2879
|
-
return
|
|
2880
|
+
return x(() => {
|
|
2880
2881
|
e && s(nt());
|
|
2881
2882
|
}, []), t;
|
|
2882
2883
|
}
|
|
2883
|
-
const [an, cn] = _(Ps), [tr, er] = d(an, cn), [hn, pn] = _(
|
|
2884
|
+
const [an, cn] = _(Ps), [tr, er] = d(an, cn), [hn, pn] = _(Rs), [sr, nr] = d(hn, pn);
|
|
2884
2885
|
function rr({ children: e, acceptCustomStyles: t, debug: s }) {
|
|
2885
2886
|
const n = bt(!0), [r, i] = rt(/* @__PURE__ */ new Map()), o = bt(r), a = oe(
|
|
2886
2887
|
(u) => {
|
|
@@ -2921,20 +2922,20 @@ function rr({ children: e, acceptCustomStyles: t, debug: s }) {
|
|
|
2921
2922
|
), $({})) : $(ft(v));
|
|
2922
2923
|
}
|
|
2923
2924
|
}), [r]);
|
|
2924
|
-
return
|
|
2925
|
+
return x(() => (n.current = !0, () => {
|
|
2925
2926
|
n.current = !1;
|
|
2926
|
-
}), []),
|
|
2927
|
+
}), []), x(() => {
|
|
2927
2928
|
if (ht())
|
|
2928
2929
|
return Cs(t);
|
|
2929
|
-
}, [t]),
|
|
2930
|
+
}, [t]), x(() => {
|
|
2930
2931
|
le(s || !1);
|
|
2931
|
-
}, [s]),
|
|
2932
|
+
}, [s]), x(() => {
|
|
2932
2933
|
o.current = r;
|
|
2933
|
-
}, [r]),
|
|
2934
|
+
}, [r]), x(() => () => {
|
|
2934
2935
|
o.current.forEach((u) => {
|
|
2935
2936
|
"cleanup" in u && u.cleanup && u.cleanup();
|
|
2936
2937
|
});
|
|
2937
|
-
}, []), /* @__PURE__ */
|
|
2938
|
+
}, []), /* @__PURE__ */ xt(ne.Provider, { value: p, children: e });
|
|
2938
2939
|
}
|
|
2939
2940
|
export {
|
|
2940
2941
|
Ne as BackButton,
|
|
@@ -2968,7 +2969,7 @@ export {
|
|
|
2968
2969
|
ms as SettingsButton,
|
|
2969
2970
|
vs as ThemeParams,
|
|
2970
2971
|
Es as Utils,
|
|
2971
|
-
|
|
2972
|
+
xs as Viewport,
|
|
2972
2973
|
Ze as array,
|
|
2973
2974
|
bn as bindMiniAppCSSVars,
|
|
2974
2975
|
vn as bindThemeParamsCSSVars,
|
|
@@ -2981,7 +2982,7 @@ export {
|
|
|
2981
2982
|
qe as createPostEvent,
|
|
2982
2983
|
H as createSafeURL,
|
|
2983
2984
|
$t as date,
|
|
2984
|
-
|
|
2985
|
+
Rn as getHash,
|
|
2985
2986
|
ee as getPathname,
|
|
2986
2987
|
Ge as initBackButton,
|
|
2987
2988
|
Ke as initBiometryManager,
|
|
@@ -2998,7 +2999,7 @@ export {
|
|
|
2998
2999
|
bs as initSettingsButton,
|
|
2999
3000
|
ys as initThemeParams,
|
|
3000
3001
|
Ps as initUtils,
|
|
3001
|
-
|
|
3002
|
+
Rs as initViewport,
|
|
3002
3003
|
Cs as initWeb,
|
|
3003
3004
|
O as invokeCustomMethod,
|
|
3004
3005
|
Vt as isColorDark,
|
|
@@ -3007,13 +3008,13 @@ export {
|
|
|
3007
3008
|
ct as isRGB,
|
|
3008
3009
|
Pe as isRGBShort,
|
|
3009
3010
|
Ts as isSDKError,
|
|
3010
|
-
|
|
3011
|
+
xn as isSDKErrorOfType,
|
|
3011
3012
|
Ss as isSSR,
|
|
3012
3013
|
En as isTMA,
|
|
3013
3014
|
w as json,
|
|
3014
3015
|
gn as mergeClassNames,
|
|
3015
3016
|
Pn as mockTelegramEnv,
|
|
3016
|
-
|
|
3017
|
+
R as number,
|
|
3017
3018
|
z as off,
|
|
3018
3019
|
y as on,
|
|
3019
3020
|
fn as parseInitData,
|