@alien_org/react 0.2.1 → 0.2.2
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 +19 -8
- package/dist/index.mjs +20 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ let react = require("react");
|
|
|
4
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
5
|
|
|
6
6
|
//#region src/context.tsx
|
|
7
|
+
const useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
7
8
|
const AlienContext = (0, react.createContext)(null);
|
|
8
9
|
/**
|
|
9
10
|
* Provider component that initializes the Alien miniapp context.
|
|
@@ -29,18 +30,23 @@ function AlienProvider({ children, autoReady = true }) {
|
|
|
29
30
|
readySent.current = true;
|
|
30
31
|
if ((0, _alien_org_bridge.isBridgeAvailable)()) (0, _alien_org_bridge.send)("app:ready", {});
|
|
31
32
|
}, []);
|
|
32
|
-
const value = (0, react.
|
|
33
|
+
const [value, setValue] = (0, react.useState)(() => ({
|
|
34
|
+
authToken: void 0,
|
|
35
|
+
contractVersion: void 0,
|
|
36
|
+
isBridgeAvailable: false,
|
|
37
|
+
ready
|
|
38
|
+
}));
|
|
39
|
+
useIsomorphicLayoutEffect$1(() => {
|
|
33
40
|
const launchParams = (0, _alien_org_bridge.getLaunchParams)();
|
|
34
|
-
|
|
41
|
+
const bridgeAvailable = (0, _alien_org_bridge.isBridgeAvailable)();
|
|
42
|
+
setValue({
|
|
35
43
|
authToken: launchParams?.authToken,
|
|
36
44
|
contractVersion: launchParams?.contractVersion,
|
|
37
|
-
isBridgeAvailable:
|
|
45
|
+
isBridgeAvailable: bridgeAvailable,
|
|
38
46
|
ready
|
|
39
|
-
};
|
|
47
|
+
});
|
|
48
|
+
if (!bridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
40
49
|
}, [ready]);
|
|
41
|
-
(0, react.useEffect)(() => {
|
|
42
|
-
if (!value.isBridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
43
|
-
}, [value.isBridgeAvailable]);
|
|
44
50
|
(0, react.useEffect)(() => {
|
|
45
51
|
if (autoReady) ready();
|
|
46
52
|
}, [autoReady, ready]);
|
|
@@ -259,6 +265,7 @@ function useIsMethodSupported(method) {
|
|
|
259
265
|
|
|
260
266
|
//#endregion
|
|
261
267
|
//#region src/hooks/useLaunchParams.ts
|
|
268
|
+
const useIsomorphicLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
262
269
|
/**
|
|
263
270
|
* Hook to get launch params.
|
|
264
271
|
* Returns undefined if params unavailable (use mockLaunchParamsForDev in dev).
|
|
@@ -279,7 +286,11 @@ function useIsMethodSupported(method) {
|
|
|
279
286
|
* ```
|
|
280
287
|
*/
|
|
281
288
|
function useLaunchParams() {
|
|
282
|
-
|
|
289
|
+
const [params, setParams] = (0, react.useState)(void 0);
|
|
290
|
+
useIsomorphicLayoutEffect(() => {
|
|
291
|
+
setParams((0, _alien_org_bridge.getLaunchParams)());
|
|
292
|
+
}, []);
|
|
293
|
+
return params;
|
|
283
294
|
}
|
|
284
295
|
|
|
285
296
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, getLaunchParams, isBridgeAvailable, on, request, send, send as send$1 } from "@alien_org/bridge";
|
|
2
2
|
import { getMethodMinVersion, getMethodMinVersion as getMethodMinVersion$1, isMethodSupported, isMethodSupported as isMethodSupported$1 } from "@alien_org/contract";
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/context.tsx
|
|
7
|
+
const useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
7
8
|
const AlienContext = createContext(null);
|
|
8
9
|
/**
|
|
9
10
|
* Provider component that initializes the Alien miniapp context.
|
|
@@ -29,18 +30,23 @@ function AlienProvider({ children, autoReady = true }) {
|
|
|
29
30
|
readySent.current = true;
|
|
30
31
|
if (isBridgeAvailable()) send$1("app:ready", {});
|
|
31
32
|
}, []);
|
|
32
|
-
const value =
|
|
33
|
+
const [value, setValue] = useState(() => ({
|
|
34
|
+
authToken: void 0,
|
|
35
|
+
contractVersion: void 0,
|
|
36
|
+
isBridgeAvailable: false,
|
|
37
|
+
ready
|
|
38
|
+
}));
|
|
39
|
+
useIsomorphicLayoutEffect$1(() => {
|
|
33
40
|
const launchParams = getLaunchParams();
|
|
34
|
-
|
|
41
|
+
const bridgeAvailable = isBridgeAvailable();
|
|
42
|
+
setValue({
|
|
35
43
|
authToken: launchParams?.authToken,
|
|
36
44
|
contractVersion: launchParams?.contractVersion,
|
|
37
|
-
isBridgeAvailable:
|
|
45
|
+
isBridgeAvailable: bridgeAvailable,
|
|
38
46
|
ready
|
|
39
|
-
};
|
|
47
|
+
});
|
|
48
|
+
if (!bridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
40
49
|
}, [ready]);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!value.isBridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
43
|
-
}, [value.isBridgeAvailable]);
|
|
44
50
|
useEffect(() => {
|
|
45
51
|
if (autoReady) ready();
|
|
46
52
|
}, [autoReady, ready]);
|
|
@@ -259,6 +265,7 @@ function useIsMethodSupported(method) {
|
|
|
259
265
|
|
|
260
266
|
//#endregion
|
|
261
267
|
//#region src/hooks/useLaunchParams.ts
|
|
268
|
+
const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
262
269
|
/**
|
|
263
270
|
* Hook to get launch params.
|
|
264
271
|
* Returns undefined if params unavailable (use mockLaunchParamsForDev in dev).
|
|
@@ -279,7 +286,11 @@ function useIsMethodSupported(method) {
|
|
|
279
286
|
* ```
|
|
280
287
|
*/
|
|
281
288
|
function useLaunchParams() {
|
|
282
|
-
|
|
289
|
+
const [params, setParams] = useState(void 0);
|
|
290
|
+
useIsomorphicLayoutEffect(() => {
|
|
291
|
+
setParams(getLaunchParams());
|
|
292
|
+
}, []);
|
|
293
|
+
return params;
|
|
283
294
|
}
|
|
284
295
|
|
|
285
296
|
//#endregion
|