@alien_org/react 0.2.2 → 0.2.3

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
@@ -23,7 +23,7 @@ const AlienContext = (0, react.createContext)(null);
23
23
  * }
24
24
  * ```
25
25
  */
26
- function AlienProvider({ children, autoReady = true }) {
26
+ function AlienProvider({ children, autoReady = true, interceptLinks = true }) {
27
27
  const readySent = (0, react.useRef)(false);
28
28
  const ready = (0, react.useCallback)(() => {
29
29
  if (readySent.current) return;
@@ -50,6 +50,9 @@ function AlienProvider({ children, autoReady = true }) {
50
50
  (0, react.useEffect)(() => {
51
51
  if (autoReady) ready();
52
52
  }, [autoReady, ready]);
53
+ (0, react.useEffect)(() => {
54
+ if (interceptLinks) return (0, _alien_org_bridge.enableLinkInterceptor)();
55
+ }, [interceptLinks]);
53
56
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AlienContext.Provider, {
54
57
  value,
55
58
  children
@@ -293,6 +296,29 @@ function useLaunchParams() {
293
296
  return params;
294
297
  }
295
298
 
299
+ //#endregion
300
+ //#region src/hooks/useLinkInterceptor.ts
301
+ /**
302
+ * Intercepts external link clicks and routes them through the bridge.
303
+ * Activates when the bridge is available, cleans up on unmount.
304
+ *
305
+ * @example
306
+ * ```tsx
307
+ * function App() {
308
+ * useLinkInterceptor();
309
+ * return <a href="https://external.com">Opens via host app</a>;
310
+ * }
311
+ * ```
312
+ */
313
+ function useLinkInterceptor(options = {}) {
314
+ const { isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
315
+ const { openMode } = options;
316
+ (0, react.useEffect)(() => {
317
+ if (!isBridgeAvailable$1) return;
318
+ return (0, _alien_org_bridge.enableLinkInterceptor)({ openMode });
319
+ }, [isBridgeAvailable$1, openMode]);
320
+ }
321
+
296
322
  //#endregion
297
323
  //#region src/hooks/useMethod.ts
298
324
  /**
@@ -639,5 +665,6 @@ exports.useClipboard = useClipboard;
639
665
  exports.useEvent = useEvent;
640
666
  exports.useIsMethodSupported = useIsMethodSupported;
641
667
  exports.useLaunchParams = useLaunchParams;
668
+ exports.useLinkInterceptor = useLinkInterceptor;
642
669
  exports.useMethod = useMethod;
643
670
  exports.usePayment = usePayment;
package/dist/index.d.cts CHANGED
@@ -477,6 +477,17 @@ declare global {
477
477
  * Error thrown when launch params cannot be retrieved.
478
478
  */
479
479
  //#endregion
480
+ //#region ../bridge/src/link-interceptor.d.ts
481
+ interface LinkInterceptorOptions {
482
+ /**
483
+ * Where to open intercepted links.
484
+ * - `external` (default): System browser or app handler
485
+ * - `internal`: Within the host app
486
+ * @default 'external'
487
+ */
488
+ openMode?: 'external' | 'internal';
489
+ }
490
+ //#endregion
480
491
  //#region ../bridge/src/request.d.ts
481
492
  interface RequestOptions {
482
493
  reqId?: string;
@@ -565,6 +576,12 @@ interface AlienProviderProps {
565
576
  * ```
566
577
  */
567
578
  autoReady?: boolean;
579
+ /**
580
+ * Whether to intercept external link clicks and route them through the
581
+ * bridge's `link:open` method. Same-origin links are unaffected.
582
+ * @default true
583
+ */
584
+ interceptLinks?: boolean;
568
585
  }
569
586
  /**
570
587
  * Provider component that initializes the Alien miniapp context.
@@ -585,7 +602,8 @@ interface AlienProviderProps {
585
602
  */
586
603
  declare function AlienProvider({
587
604
  children,
588
- autoReady
605
+ autoReady,
606
+ interceptLinks
589
607
  }: AlienProviderProps): ReactNode;
590
608
  //#endregion
591
609
  //#region src/errors.d.ts
@@ -763,6 +781,21 @@ declare function useIsMethodSupported(method: MethodName): MethodSupportResult;
763
781
  */
764
782
  declare function useLaunchParams(): LaunchParams | undefined;
765
783
  //#endregion
784
+ //#region src/hooks/useLinkInterceptor.d.ts
785
+ /**
786
+ * Intercepts external link clicks and routes them through the bridge.
787
+ * Activates when the bridge is available, cleans up on unmount.
788
+ *
789
+ * @example
790
+ * ```tsx
791
+ * function App() {
792
+ * useLinkInterceptor();
793
+ * return <a href="https://external.com">Opens via host app</a>;
794
+ * }
795
+ * ```
796
+ */
797
+ declare function useLinkInterceptor(options?: LinkInterceptorOptions): void;
798
+ //#endregion
766
799
  //#region src/hooks/useMethod.d.ts
767
800
  interface UseMethodExecuteResult<E extends EventName> {
768
801
  data: EventPayload<E> | undefined;
@@ -955,4 +988,4 @@ interface UsePaymentReturn {
955
988
  */
956
989
  declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
957
990
  //#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 };
991
+ 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
@@ -477,6 +477,17 @@ declare global {
477
477
  * Error thrown when launch params cannot be retrieved.
478
478
  */
479
479
  //#endregion
480
+ //#region ../bridge/src/link-interceptor.d.ts
481
+ interface LinkInterceptorOptions {
482
+ /**
483
+ * Where to open intercepted links.
484
+ * - `external` (default): System browser or app handler
485
+ * - `internal`: Within the host app
486
+ * @default 'external'
487
+ */
488
+ openMode?: 'external' | 'internal';
489
+ }
490
+ //#endregion
480
491
  //#region ../bridge/src/request.d.ts
481
492
  interface RequestOptions {
482
493
  reqId?: string;
@@ -565,6 +576,12 @@ interface AlienProviderProps {
565
576
  * ```
566
577
  */
567
578
  autoReady?: boolean;
579
+ /**
580
+ * Whether to intercept external link clicks and route them through the
581
+ * bridge's `link:open` method. Same-origin links are unaffected.
582
+ * @default true
583
+ */
584
+ interceptLinks?: boolean;
568
585
  }
569
586
  /**
570
587
  * Provider component that initializes the Alien miniapp context.
@@ -585,7 +602,8 @@ interface AlienProviderProps {
585
602
  */
586
603
  declare function AlienProvider({
587
604
  children,
588
- autoReady
605
+ autoReady,
606
+ interceptLinks
589
607
  }: AlienProviderProps): ReactNode;
590
608
  //#endregion
591
609
  //#region src/errors.d.ts
@@ -763,6 +781,21 @@ declare function useIsMethodSupported(method: MethodName): MethodSupportResult;
763
781
  */
764
782
  declare function useLaunchParams(): LaunchParams | undefined;
765
783
  //#endregion
784
+ //#region src/hooks/useLinkInterceptor.d.ts
785
+ /**
786
+ * Intercepts external link clicks and routes them through the bridge.
787
+ * Activates when the bridge is available, cleans up on unmount.
788
+ *
789
+ * @example
790
+ * ```tsx
791
+ * function App() {
792
+ * useLinkInterceptor();
793
+ * return <a href="https://external.com">Opens via host app</a>;
794
+ * }
795
+ * ```
796
+ */
797
+ declare function useLinkInterceptor(options?: LinkInterceptorOptions): void;
798
+ //#endregion
766
799
  //#region src/hooks/useMethod.d.ts
767
800
  interface UseMethodExecuteResult<E extends EventName> {
768
801
  data: EventPayload<E> | undefined;
@@ -955,4 +988,4 @@ interface UsePaymentReturn {
955
988
  */
956
989
  declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
957
990
  //#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 };
991
+ 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";
@@ -23,7 +23,7 @@ const AlienContext = createContext(null);
23
23
  * }
24
24
  * ```
25
25
  */
26
- function AlienProvider({ children, autoReady = true }) {
26
+ function AlienProvider({ children, autoReady = true, interceptLinks = true }) {
27
27
  const readySent = useRef(false);
28
28
  const ready = useCallback(() => {
29
29
  if (readySent.current) return;
@@ -50,6 +50,9 @@ function AlienProvider({ children, autoReady = true }) {
50
50
  useEffect(() => {
51
51
  if (autoReady) ready();
52
52
  }, [autoReady, ready]);
53
+ useEffect(() => {
54
+ if (interceptLinks) return enableLinkInterceptor();
55
+ }, [interceptLinks]);
53
56
  return /* @__PURE__ */ jsx(AlienContext.Provider, {
54
57
  value,
55
58
  children
@@ -293,6 +296,29 @@ function useLaunchParams() {
293
296
  return params;
294
297
  }
295
298
 
299
+ //#endregion
300
+ //#region src/hooks/useLinkInterceptor.ts
301
+ /**
302
+ * Intercepts external link clicks and routes them through the bridge.
303
+ * Activates when the bridge is available, cleans up on unmount.
304
+ *
305
+ * @example
306
+ * ```tsx
307
+ * function App() {
308
+ * useLinkInterceptor();
309
+ * return <a href="https://external.com">Opens via host app</a>;
310
+ * }
311
+ * ```
312
+ */
313
+ function useLinkInterceptor(options = {}) {
314
+ const { isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
315
+ const { openMode } = options;
316
+ useEffect(() => {
317
+ if (!isBridgeAvailable$1) return;
318
+ return enableLinkInterceptor({ openMode });
319
+ }, [isBridgeAvailable$1, openMode]);
320
+ }
321
+
296
322
  //#endregion
297
323
  //#region src/hooks/useMethod.ts
298
324
  /**
@@ -609,4 +635,4 @@ function usePayment(options = {}) {
609
635
  }
610
636
 
611
637
  //#endregion
612
- export { AlienProvider, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, MethodNotSupportedError, ReactSDKError, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
638
+ 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.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -34,7 +34,7 @@
34
34
  "prepublishOnly": "bun run build"
35
35
  },
36
36
  "dependencies": {
37
- "@alien_org/bridge": "0.2.1",
37
+ "@alien_org/bridge": "0.2.2",
38
38
  "@alien_org/contract": "0.2.1"
39
39
  },
40
40
  "peerDependencies": {