@alien_org/react 0.2.2 → 0.2.4

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 CHANGED
@@ -6,6 +6,17 @@ let react_jsx_runtime = require("react/jsx-runtime");
6
6
  //#region src/context.tsx
7
7
  const useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
8
8
  const AlienContext = (0, react.createContext)(null);
9
+ const SAFE_AREA_EDGES = [
10
+ "top",
11
+ "right",
12
+ "bottom",
13
+ "left"
14
+ ];
15
+ function setSafeAreaCssVars(insets) {
16
+ if (typeof document === "undefined") return;
17
+ const root = document.documentElement;
18
+ for (const edge of SAFE_AREA_EDGES) root.style.setProperty(`--alien-safe-area-inset-${edge}`, `${insets?.[edge] ?? 0}px`);
19
+ }
9
20
  /**
10
21
  * Provider component that initializes the Alien miniapp context.
11
22
  * Must wrap your app to use Alien hooks.
@@ -23,7 +34,7 @@ const AlienContext = (0, react.createContext)(null);
23
34
  * }
24
35
  * ```
25
36
  */
26
- function AlienProvider({ children, autoReady = true }) {
37
+ function AlienProvider({ children, autoReady = true, interceptLinks = true }) {
27
38
  const readySent = (0, react.useRef)(false);
28
39
  const ready = (0, react.useCallback)(() => {
29
40
  if (readySent.current) return;
@@ -45,11 +56,15 @@ function AlienProvider({ children, autoReady = true }) {
45
56
  isBridgeAvailable: bridgeAvailable,
46
57
  ready
47
58
  });
59
+ setSafeAreaCssVars(launchParams?.safeAreaInsets);
48
60
  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.");
49
61
  }, [ready]);
50
62
  (0, react.useEffect)(() => {
51
63
  if (autoReady) ready();
52
64
  }, [autoReady, ready]);
65
+ (0, react.useEffect)(() => {
66
+ if (interceptLinks) return (0, _alien_org_bridge.enableLinkInterceptor)();
67
+ }, [interceptLinks]);
53
68
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AlienContext.Provider, {
54
69
  value,
55
70
  children
@@ -293,6 +308,29 @@ function useLaunchParams() {
293
308
  return params;
294
309
  }
295
310
 
311
+ //#endregion
312
+ //#region src/hooks/useLinkInterceptor.ts
313
+ /**
314
+ * Intercepts external link clicks and routes them through the bridge.
315
+ * Activates when the bridge is available, cleans up on unmount.
316
+ *
317
+ * @example
318
+ * ```tsx
319
+ * function App() {
320
+ * useLinkInterceptor();
321
+ * return <a href="https://external.com">Opens via host app</a>;
322
+ * }
323
+ * ```
324
+ */
325
+ function useLinkInterceptor(options = {}) {
326
+ const { isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
327
+ const { openMode } = options;
328
+ (0, react.useEffect)(() => {
329
+ if (!isBridgeAvailable$1) return;
330
+ return (0, _alien_org_bridge.enableLinkInterceptor)({ openMode });
331
+ }, [isBridgeAvailable$1, openMode]);
332
+ }
333
+
296
334
  //#endregion
297
335
  //#region src/hooks/useMethod.ts
298
336
  /**
@@ -639,5 +677,6 @@ exports.useClipboard = useClipboard;
639
677
  exports.useEvent = useEvent;
640
678
  exports.useIsMethodSupported = useIsMethodSupported;
641
679
  exports.useLaunchParams = useLaunchParams;
680
+ exports.useLinkInterceptor = useLinkInterceptor;
642
681
  exports.useMethod = useMethod;
643
682
  exports.usePayment = usePayment;
package/dist/index.d.cts CHANGED
@@ -178,6 +178,16 @@ declare const PLATFORMS: readonly ["ios", "android"];
178
178
  * Platform the miniapp is running on.
179
179
  */
180
180
  type Platform = (typeof PLATFORMS)[number];
181
+ /**
182
+ * Safe area insets in CSS pixels, injected by the host app.
183
+ * Accounts for system UI (status bar, notch, home indicator, nav bar).
184
+ */
185
+ interface SafeAreaInsets {
186
+ top: number;
187
+ right: number;
188
+ bottom: number;
189
+ left: number;
190
+ }
181
191
  /**
182
192
  * Launch parameters injected by the host app.
183
193
  */
@@ -190,6 +200,8 @@ interface LaunchParams {
190
200
  hostAppVersion: string | undefined;
191
201
  /** Platform the miniapp is running on */
192
202
  platform: Platform | undefined;
203
+ /** Safe area insets for the webview in CSS pixels */
204
+ safeAreaInsets: SafeAreaInsets | undefined;
193
205
  /**
194
206
  * Custom start parameter injected by host app.
195
207
  * Used for referral codes, campaign tracking, or custom routing.
@@ -470,6 +482,7 @@ declare global {
470
482
  __ALIEN_CONTRACT_VERSION__?: string;
471
483
  __ALIEN_HOST_VERSION__?: string;
472
484
  __ALIEN_PLATFORM__?: string;
485
+ __ALIEN_SAFE_AREA_INSETS__?: SafeAreaInsets;
473
486
  __ALIEN_START_PARAM__?: string;
474
487
  }
475
488
  }
@@ -477,6 +490,17 @@ declare global {
477
490
  * Error thrown when launch params cannot be retrieved.
478
491
  */
479
492
  //#endregion
493
+ //#region ../bridge/src/link-interceptor.d.ts
494
+ interface LinkInterceptorOptions {
495
+ /**
496
+ * Where to open intercepted links.
497
+ * - `external` (default): System browser or app handler
498
+ * - `internal`: Within the host app
499
+ * @default 'external'
500
+ */
501
+ openMode?: 'external' | 'internal';
502
+ }
503
+ //#endregion
480
504
  //#region ../bridge/src/request.d.ts
481
505
  interface RequestOptions {
482
506
  reqId?: string;
@@ -565,6 +589,12 @@ interface AlienProviderProps {
565
589
  * ```
566
590
  */
567
591
  autoReady?: boolean;
592
+ /**
593
+ * Whether to intercept external link clicks and route them through the
594
+ * bridge's `link:open` method. Same-origin links are unaffected.
595
+ * @default true
596
+ */
597
+ interceptLinks?: boolean;
568
598
  }
569
599
  /**
570
600
  * Provider component that initializes the Alien miniapp context.
@@ -585,7 +615,8 @@ interface AlienProviderProps {
585
615
  */
586
616
  declare function AlienProvider({
587
617
  children,
588
- autoReady
618
+ autoReady,
619
+ interceptLinks
589
620
  }: AlienProviderProps): ReactNode;
590
621
  //#endregion
591
622
  //#region src/errors.d.ts
@@ -763,6 +794,21 @@ declare function useIsMethodSupported(method: MethodName): MethodSupportResult;
763
794
  */
764
795
  declare function useLaunchParams(): LaunchParams | undefined;
765
796
  //#endregion
797
+ //#region src/hooks/useLinkInterceptor.d.ts
798
+ /**
799
+ * Intercepts external link clicks and routes them through the bridge.
800
+ * Activates when the bridge is available, cleans up on unmount.
801
+ *
802
+ * @example
803
+ * ```tsx
804
+ * function App() {
805
+ * useLinkInterceptor();
806
+ * return <a href="https://external.com">Opens via host app</a>;
807
+ * }
808
+ * ```
809
+ */
810
+ declare function useLinkInterceptor(options?: LinkInterceptorOptions): void;
811
+ //#endregion
766
812
  //#region src/hooks/useMethod.d.ts
767
813
  interface UseMethodExecuteResult<E extends EventName> {
768
814
  data: EventPayload<E> | undefined;
@@ -955,4 +1001,4 @@ interface UsePaymentReturn {
955
1001
  */
956
1002
  declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
957
1003
  //#endregion
958
- export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
1004
+ export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type LinkInterceptorOptions, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useLinkInterceptor, useMethod, usePayment };
package/dist/index.d.mts CHANGED
@@ -178,6 +178,16 @@ declare const PLATFORMS: readonly ["ios", "android"];
178
178
  * Platform the miniapp is running on.
179
179
  */
180
180
  type Platform = (typeof PLATFORMS)[number];
181
+ /**
182
+ * Safe area insets in CSS pixels, injected by the host app.
183
+ * Accounts for system UI (status bar, notch, home indicator, nav bar).
184
+ */
185
+ interface SafeAreaInsets {
186
+ top: number;
187
+ right: number;
188
+ bottom: number;
189
+ left: number;
190
+ }
181
191
  /**
182
192
  * Launch parameters injected by the host app.
183
193
  */
@@ -190,6 +200,8 @@ interface LaunchParams {
190
200
  hostAppVersion: string | undefined;
191
201
  /** Platform the miniapp is running on */
192
202
  platform: Platform | undefined;
203
+ /** Safe area insets for the webview in CSS pixels */
204
+ safeAreaInsets: SafeAreaInsets | undefined;
193
205
  /**
194
206
  * Custom start parameter injected by host app.
195
207
  * Used for referral codes, campaign tracking, or custom routing.
@@ -470,6 +482,7 @@ declare global {
470
482
  __ALIEN_CONTRACT_VERSION__?: string;
471
483
  __ALIEN_HOST_VERSION__?: string;
472
484
  __ALIEN_PLATFORM__?: string;
485
+ __ALIEN_SAFE_AREA_INSETS__?: SafeAreaInsets;
473
486
  __ALIEN_START_PARAM__?: string;
474
487
  }
475
488
  }
@@ -477,6 +490,17 @@ declare global {
477
490
  * Error thrown when launch params cannot be retrieved.
478
491
  */
479
492
  //#endregion
493
+ //#region ../bridge/src/link-interceptor.d.ts
494
+ interface LinkInterceptorOptions {
495
+ /**
496
+ * Where to open intercepted links.
497
+ * - `external` (default): System browser or app handler
498
+ * - `internal`: Within the host app
499
+ * @default 'external'
500
+ */
501
+ openMode?: 'external' | 'internal';
502
+ }
503
+ //#endregion
480
504
  //#region ../bridge/src/request.d.ts
481
505
  interface RequestOptions {
482
506
  reqId?: string;
@@ -565,6 +589,12 @@ interface AlienProviderProps {
565
589
  * ```
566
590
  */
567
591
  autoReady?: boolean;
592
+ /**
593
+ * Whether to intercept external link clicks and route them through the
594
+ * bridge's `link:open` method. Same-origin links are unaffected.
595
+ * @default true
596
+ */
597
+ interceptLinks?: boolean;
568
598
  }
569
599
  /**
570
600
  * Provider component that initializes the Alien miniapp context.
@@ -585,7 +615,8 @@ interface AlienProviderProps {
585
615
  */
586
616
  declare function AlienProvider({
587
617
  children,
588
- autoReady
618
+ autoReady,
619
+ interceptLinks
589
620
  }: AlienProviderProps): ReactNode;
590
621
  //#endregion
591
622
  //#region src/errors.d.ts
@@ -763,6 +794,21 @@ declare function useIsMethodSupported(method: MethodName): MethodSupportResult;
763
794
  */
764
795
  declare function useLaunchParams(): LaunchParams | undefined;
765
796
  //#endregion
797
+ //#region src/hooks/useLinkInterceptor.d.ts
798
+ /**
799
+ * Intercepts external link clicks and routes them through the bridge.
800
+ * Activates when the bridge is available, cleans up on unmount.
801
+ *
802
+ * @example
803
+ * ```tsx
804
+ * function App() {
805
+ * useLinkInterceptor();
806
+ * return <a href="https://external.com">Opens via host app</a>;
807
+ * }
808
+ * ```
809
+ */
810
+ declare function useLinkInterceptor(options?: LinkInterceptorOptions): void;
811
+ //#endregion
766
812
  //#region src/hooks/useMethod.d.ts
767
813
  interface UseMethodExecuteResult<E extends EventName> {
768
814
  data: EventPayload<E> | undefined;
@@ -955,4 +1001,4 @@ interface UsePaymentReturn {
955
1001
  */
956
1002
  declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
957
1003
  //#endregion
958
- export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
1004
+ export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type LinkInterceptorOptions, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useLinkInterceptor, useMethod, usePayment };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, getLaunchParams, isBridgeAvailable, on, request, send, send as send$1 } from "@alien_org/bridge";
1
+ import { BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, enableLinkInterceptor, 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
3
  import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
@@ -6,6 +6,17 @@ import { jsx } from "react/jsx-runtime";
6
6
  //#region src/context.tsx
7
7
  const useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
8
8
  const AlienContext = createContext(null);
9
+ const SAFE_AREA_EDGES = [
10
+ "top",
11
+ "right",
12
+ "bottom",
13
+ "left"
14
+ ];
15
+ function setSafeAreaCssVars(insets) {
16
+ if (typeof document === "undefined") return;
17
+ const root = document.documentElement;
18
+ for (const edge of SAFE_AREA_EDGES) root.style.setProperty(`--alien-safe-area-inset-${edge}`, `${insets?.[edge] ?? 0}px`);
19
+ }
9
20
  /**
10
21
  * Provider component that initializes the Alien miniapp context.
11
22
  * Must wrap your app to use Alien hooks.
@@ -23,7 +34,7 @@ const AlienContext = createContext(null);
23
34
  * }
24
35
  * ```
25
36
  */
26
- function AlienProvider({ children, autoReady = true }) {
37
+ function AlienProvider({ children, autoReady = true, interceptLinks = true }) {
27
38
  const readySent = useRef(false);
28
39
  const ready = useCallback(() => {
29
40
  if (readySent.current) return;
@@ -45,11 +56,15 @@ function AlienProvider({ children, autoReady = true }) {
45
56
  isBridgeAvailable: bridgeAvailable,
46
57
  ready
47
58
  });
59
+ setSafeAreaCssVars(launchParams?.safeAreaInsets);
48
60
  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.");
49
61
  }, [ready]);
50
62
  useEffect(() => {
51
63
  if (autoReady) ready();
52
64
  }, [autoReady, ready]);
65
+ useEffect(() => {
66
+ if (interceptLinks) return enableLinkInterceptor();
67
+ }, [interceptLinks]);
53
68
  return /* @__PURE__ */ jsx(AlienContext.Provider, {
54
69
  value,
55
70
  children
@@ -293,6 +308,29 @@ function useLaunchParams() {
293
308
  return params;
294
309
  }
295
310
 
311
+ //#endregion
312
+ //#region src/hooks/useLinkInterceptor.ts
313
+ /**
314
+ * Intercepts external link clicks and routes them through the bridge.
315
+ * Activates when the bridge is available, cleans up on unmount.
316
+ *
317
+ * @example
318
+ * ```tsx
319
+ * function App() {
320
+ * useLinkInterceptor();
321
+ * return <a href="https://external.com">Opens via host app</a>;
322
+ * }
323
+ * ```
324
+ */
325
+ function useLinkInterceptor(options = {}) {
326
+ const { isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
327
+ const { openMode } = options;
328
+ useEffect(() => {
329
+ if (!isBridgeAvailable$1) return;
330
+ return enableLinkInterceptor({ openMode });
331
+ }, [isBridgeAvailable$1, openMode]);
332
+ }
333
+
296
334
  //#endregion
297
335
  //#region src/hooks/useMethod.ts
298
336
  /**
@@ -609,4 +647,4 @@ function usePayment(options = {}) {
609
647
  }
610
648
 
611
649
  //#endregion
612
- export { AlienProvider, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, MethodNotSupportedError, ReactSDKError, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
650
+ export { AlienProvider, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, MethodNotSupportedError, ReactSDKError, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useLinkInterceptor, useMethod, usePayment };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alien_org/react",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -34,8 +34,8 @@
34
34
  "prepublishOnly": "bun run build"
35
35
  },
36
36
  "dependencies": {
37
- "@alien_org/bridge": "0.2.1",
38
- "@alien_org/contract": "0.2.1"
37
+ "@alien_org/bridge": "0.2.3",
38
+ "@alien_org/contract": "0.2.2"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "^18 || ^19",