@mochabug/adapt-react 1.0.0-rc12 → 1.0.0-rc15

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.
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AdaptCapWidget, } from "@mochabug/adapt-web";
3
+ import { forwardRef, useEffect, useRef } from "react";
4
+ // Re-export for direct use
5
+ export { AdaptCapWidget, } from "@mochabug/adapt-web";
6
+ /**
7
+ * React component for Cap.js proof-of-work challenges.
8
+ *
9
+ * Use this component independently of the Adapt iframe component
10
+ * to solve PoW challenges and get a token for starting sessions.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { AdaptCap } from "@mochabug/adapt-react";
15
+ * import { createConnectClient } from "@mochabug/adapt-core/connect";
16
+ * import { createAdaptClient } from "@mochabug/adapt-core";
17
+ *
18
+ * function MyComponent() {
19
+ * const rawClient = createConnectClient({ id: "my-automation" });
20
+ *
21
+ * return (
22
+ * <AdaptCap
23
+ * automationId="my-automation"
24
+ * client={rawClient}
25
+ * onSolve={async (token) => {
26
+ * const client = createAdaptClient(rawClient, "my-automation");
27
+ * await client.run({ challengeToken: token });
28
+ * }}
29
+ * />
30
+ * );
31
+ * }
32
+ * ```
33
+ */
34
+ export const AdaptCap = forwardRef(function AdaptCap({ automationId, client, onSolve, onError, workerCount, i18n, darkMode, className, style, }, ref) {
35
+ const internalRef = useRef(null);
36
+ const widgetRef = useRef(null);
37
+ // Merge refs
38
+ const setRef = (element) => {
39
+ internalRef.current = element;
40
+ if (typeof ref === "function") {
41
+ ref(element);
42
+ }
43
+ else if (ref) {
44
+ ref.current = element;
45
+ }
46
+ };
47
+ useEffect(() => {
48
+ if (!internalRef.current)
49
+ return;
50
+ widgetRef.current = new AdaptCapWidget({
51
+ container: internalRef.current,
52
+ automationId,
53
+ client,
54
+ onSolve,
55
+ onError,
56
+ ...(workerCount !== undefined && { workerCount }),
57
+ ...(i18n !== undefined && { i18n }),
58
+ });
59
+ return () => {
60
+ widgetRef.current?.destroy();
61
+ widgetRef.current = null;
62
+ };
63
+ }, [automationId, client]);
64
+ // Update dark mode
65
+ useEffect(() => {
66
+ if (darkMode !== undefined) {
67
+ widgetRef.current?.setDarkMode(darkMode);
68
+ }
69
+ }, [darkMode]);
70
+ return _jsx("div", { ref: setRef, className: className, style: style });
71
+ });
package/dist/esm/index.js CHANGED
@@ -3,10 +3,12 @@ import { AdaptWebClient, } from "@mochabug/adapt-web";
3
3
  import { forwardRef, useEffect, useRef } from "react";
4
4
  // Re-export everything from web
5
5
  export * from "@mochabug/adapt-web";
6
+ // Export standalone Cap widget component
7
+ export { AdaptCap } from "./AdaptCap.js";
6
8
  /**
7
9
  * React component for embedding Adapt automations.
8
10
  */
9
- export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, transmitter, signals, inheritToken, inheritFrom, forkDisplayMode, sideBySideSplit, dialogBackdropClose, darkMode, autoResizing, onSession, onOutput, classNames, className, style, }, ref) {
11
+ export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, transmitter, signals, challengeToken, requiresChallenge, capWidgetOptions, inheritToken, inheritFrom, forkDisplayMode, sideBySideSplit, dialogBackdropClose, darkMode, autoResizing, onSession, onOutput, classNames, className, style, }, ref) {
10
12
  const clientRef = useRef(null);
11
13
  const internalRef = useRef(null);
12
14
  const containerIdRef = useRef(`adapt-${Math.random().toString(36).slice(2, 11)}`);
@@ -29,6 +31,9 @@ export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, tr
29
31
  authToken,
30
32
  transmitter,
31
33
  signals,
34
+ challengeToken,
35
+ requiresChallenge,
36
+ capWidgetOptions,
32
37
  inheritToken,
33
38
  inheritFrom,
34
39
  forkDisplayMode,
@@ -0,0 +1,42 @@
1
+ import { type AdaptCapWidgetOptions } from "@mochabug/adapt-web";
2
+ export { AdaptCapWidget, type AdaptCapWidgetOptions, } from "@mochabug/adapt-web";
3
+ /**
4
+ * Props for the AdaptCap React component.
5
+ */
6
+ export interface AdaptCapProps extends Omit<AdaptCapWidgetOptions, "container"> {
7
+ /** CSS class name for the container */
8
+ className?: string;
9
+ /** Inline styles for the container */
10
+ style?: React.CSSProperties;
11
+ /** Enable dark mode styling */
12
+ darkMode?: boolean;
13
+ }
14
+ /**
15
+ * React component for Cap.js proof-of-work challenges.
16
+ *
17
+ * Use this component independently of the Adapt iframe component
18
+ * to solve PoW challenges and get a token for starting sessions.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import { AdaptCap } from "@mochabug/adapt-react";
23
+ * import { createConnectClient } from "@mochabug/adapt-core/connect";
24
+ * import { createAdaptClient } from "@mochabug/adapt-core";
25
+ *
26
+ * function MyComponent() {
27
+ * const rawClient = createConnectClient({ id: "my-automation" });
28
+ *
29
+ * return (
30
+ * <AdaptCap
31
+ * automationId="my-automation"
32
+ * client={rawClient}
33
+ * onSolve={async (token) => {
34
+ * const client = createAdaptClient(rawClient, "my-automation");
35
+ * await client.run({ challengeToken: token });
36
+ * }}
37
+ * />
38
+ * );
39
+ * }
40
+ * ```
41
+ */
42
+ export declare const AdaptCap: import("react").ForwardRefExoticComponent<AdaptCapProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,9 +1,10 @@
1
1
  import { type AdaptWebClientOptions } from "@mochabug/adapt-web";
2
2
  export * from "@mochabug/adapt-web";
3
+ export { AdaptCap, type AdaptCapProps } from "./AdaptCap.js";
3
4
  /**
4
5
  * Props for the Adapt React component.
5
6
  */
6
- export interface AdaptProps extends Pick<AdaptWebClientOptions, "id" | "sessionToken" | "authToken" | "transmitter" | "signals" | "inheritToken" | "inheritFrom" | "forkDisplayMode" | "sideBySideSplit" | "dialogBackdropClose" | "darkMode" | "autoResizing" | "onSession" | "onOutput" | "classNames"> {
7
+ export interface AdaptProps extends Pick<AdaptWebClientOptions, "id" | "sessionToken" | "authToken" | "transmitter" | "signals" | "challengeToken" | "requiresChallenge" | "capWidgetOptions" | "inheritToken" | "inheritFrom" | "forkDisplayMode" | "sideBySideSplit" | "dialogBackdropClose" | "darkMode" | "autoResizing" | "onSession" | "onOutput" | "classNames"> {
7
8
  /** CSS class name for the container */
8
9
  className?: string;
9
10
  /** Inline styles for the container */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adapt-react",
3
- "version": "1.0.0-rc12",
3
+ "version": "1.0.0-rc15",
4
4
  "description": "React component for Adapt automation platform",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/index.js",
@@ -37,6 +37,6 @@
37
37
  "typescript": "^5.9.3"
38
38
  },
39
39
  "dependencies": {
40
- "@mochabug/adapt-web": "^1.0.0-rc34"
40
+ "@mochabug/adapt-web": "^1.0.0-rc37"
41
41
  }
42
42
  }