@mochabug/adapt-react 1.0.0-rc2 → 1.0.0-rc20
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/esm/AdaptCap.js +35 -0
- package/dist/esm/index.js +26 -30
- package/dist/types/AdaptCap.d.ts +35 -0
- package/dist/types/index.d.ts +53 -7
- package/package.json +5 -5
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AdaptCapElement, } from "@mochabug/adapt-web";
|
|
3
|
+
import { forwardRef, useLayoutEffect, useRef } from "react";
|
|
4
|
+
// Re-export for direct use
|
|
5
|
+
export { AdaptCapWidget, } from "@mochabug/adapt-web";
|
|
6
|
+
// Ensure custom element is registered
|
|
7
|
+
void AdaptCapElement;
|
|
8
|
+
/**
|
|
9
|
+
* React component for Cap.js proof-of-work challenges.
|
|
10
|
+
* Renders `<adapt-cap>` custom element and syncs non-serializable properties via ref.
|
|
11
|
+
*/
|
|
12
|
+
export const AdaptCap = forwardRef(function AdaptCap({ automationId, client, onSolve, onError, workerCount, i18n, darkMode, className, style, }, ref) {
|
|
13
|
+
const internalRef = useRef(null);
|
|
14
|
+
// Merge refs
|
|
15
|
+
const setRef = (element) => {
|
|
16
|
+
internalRef.current = element;
|
|
17
|
+
if (typeof ref === "function") {
|
|
18
|
+
ref(element);
|
|
19
|
+
}
|
|
20
|
+
else if (ref) {
|
|
21
|
+
ref.current = element;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
// Sync non-serializable properties
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
const el = internalRef.current;
|
|
27
|
+
if (!el)
|
|
28
|
+
return;
|
|
29
|
+
el.client = client;
|
|
30
|
+
el.i18n = i18n;
|
|
31
|
+
el.onSolveCallback = onSolve;
|
|
32
|
+
el.onErrorCallback = onError;
|
|
33
|
+
});
|
|
34
|
+
return (_jsx("adapt-cap", { ref: setRef, className: className, style: style, "automation-id": automationId, "dark-mode": darkMode ? "" : undefined, "worker-count": workerCount !== undefined ? String(workerCount) : undefined }));
|
|
35
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { forwardRef,
|
|
2
|
+
import { AdaptAutomationElement, } from "@mochabug/adapt-web";
|
|
3
|
+
import { forwardRef, useLayoutEffect, useRef } from "react";
|
|
4
|
+
// Re-export everything from web
|
|
5
|
+
export * from "@mochabug/adapt-web";
|
|
6
|
+
// Export standalone Cap widget component
|
|
7
|
+
export { AdaptCap } from "./AdaptCap.js";
|
|
8
|
+
// Ensure custom element is registered
|
|
9
|
+
void AdaptAutomationElement;
|
|
4
10
|
/**
|
|
5
11
|
* React component for embedding Adapt automations.
|
|
12
|
+
* Renders `<adapt-automation>` custom element and syncs non-serializable properties via ref.
|
|
6
13
|
*/
|
|
7
|
-
export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, transmitter, signals, inheritToken, inheritFrom, forkDisplayMode, sideBySideSplit, dialogBackdropClose, onSession, onOutput, classNames, className, style, }, ref) {
|
|
8
|
-
const clientRef = useRef(null);
|
|
14
|
+
export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, transmitter, signals, challengeToken, requiresChallenge, capWidgetOptions, inheritToken, inheritFrom, forkDisplayMode, sideBySideSplit, dialogBackdropClose, darkMode, autoResizing, onSession, onOutput, classNames, styles, className, style, }, ref) {
|
|
9
15
|
const internalRef = useRef(null);
|
|
10
|
-
const containerIdRef = useRef(`adapt-${Math.random().toString(36).slice(2, 11)}`);
|
|
11
|
-
const containerId = containerIdRef.current;
|
|
12
16
|
// Merge refs
|
|
13
17
|
const setRef = (element) => {
|
|
14
18
|
internalRef.current = element;
|
|
@@ -19,28 +23,20 @@ export const Adapt = forwardRef(function Adapt({ id, sessionToken, authToken, tr
|
|
|
19
23
|
ref.current = element;
|
|
20
24
|
}
|
|
21
25
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
return () => {
|
|
40
|
-
clientRef.current?.destroy();
|
|
41
|
-
clientRef.current = null;
|
|
42
|
-
};
|
|
43
|
-
// Only recreate client if automation ID changes
|
|
44
|
-
}, [id]);
|
|
45
|
-
return (_jsx("div", { ref: setRef, id: containerId, className: className, style: style }));
|
|
26
|
+
// Sync non-serializable properties to the element
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const el = internalRef.current;
|
|
29
|
+
if (!el)
|
|
30
|
+
return;
|
|
31
|
+
el.signals = signals;
|
|
32
|
+
el.capWidgetOptions = capWidgetOptions;
|
|
33
|
+
el.inheritFrom = inheritFrom;
|
|
34
|
+
el.classNames = classNames;
|
|
35
|
+
el.styles = styles;
|
|
36
|
+
el.onSessionCallback = onSession;
|
|
37
|
+
el.onOutputCallback = onOutput;
|
|
38
|
+
});
|
|
39
|
+
// React doesn't natively set properties on custom elements (pre-19),
|
|
40
|
+
// so we use attributes for serializable values and ref for the rest.
|
|
41
|
+
return (_jsx("adapt-automation", { ref: setRef, className: className, style: style, "automation-id": id, "session-token": sessionToken, "auth-token": authToken, transmitter: transmitter, "challenge-token": challengeToken, "requires-challenge": requiresChallenge ? "" : undefined, "inherit-token": inheritToken, "fork-display-mode": forkDisplayMode, "side-by-side-split": sideBySideSplit !== undefined ? String(sideBySideSplit) : undefined, "dialog-backdrop-close": dialogBackdropClose ? "" : undefined, "dark-mode": darkMode ? "" : undefined, "auto-resizing": autoResizing ? "" : undefined }));
|
|
46
42
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AutomationClient } from "@mochabug/adapt-core";
|
|
2
|
+
import { AdaptCapElement, type CapWidgetI18n } from "@mochabug/adapt-web";
|
|
3
|
+
export { AdaptCapWidget, type AdaptCapWidgetOptions, } from "@mochabug/adapt-web";
|
|
4
|
+
declare module "react" {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
"adapt-cap": React.DetailedHTMLProps<React.HTMLAttributes<AdaptCapElement> & {
|
|
8
|
+
"automation-id"?: string;
|
|
9
|
+
"dark-mode"?: string;
|
|
10
|
+
"worker-count"?: string;
|
|
11
|
+
}, AdaptCapElement>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Props for the AdaptCap React component.
|
|
17
|
+
*/
|
|
18
|
+
export interface AdaptCapProps {
|
|
19
|
+
automationId: string;
|
|
20
|
+
client: AutomationClient;
|
|
21
|
+
workerCount?: number;
|
|
22
|
+
i18n?: CapWidgetI18n;
|
|
23
|
+
darkMode?: boolean;
|
|
24
|
+
onSolve?: (token: string, expires: Date) => void;
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
/** CSS class name for the container */
|
|
27
|
+
className?: string;
|
|
28
|
+
/** Inline styles for the container */
|
|
29
|
+
style?: React.CSSProperties;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* React component for Cap.js proof-of-work challenges.
|
|
33
|
+
* Renders `<adapt-cap>` custom element and syncs non-serializable properties via ref.
|
|
34
|
+
*/
|
|
35
|
+
export declare const AdaptCap: import("react").ForwardRefExoticComponent<AdaptCapProps & import("react").RefAttributes<AdaptCapElement>>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AdaptAutomationElement, type AdaptWebClientOptions, type Output, type SignalValue, type StatusJson } from "@mochabug/adapt-web";
|
|
2
|
+
declare module "react" {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
"adapt-automation": React.DetailedHTMLProps<React.HTMLAttributes<AdaptAutomationElement> & {
|
|
6
|
+
"automation-id"?: string;
|
|
7
|
+
"session-token"?: string;
|
|
8
|
+
"auth-token"?: string;
|
|
9
|
+
transmitter?: string;
|
|
10
|
+
"challenge-token"?: string;
|
|
11
|
+
"requires-challenge"?: string;
|
|
12
|
+
"inherit-token"?: string;
|
|
13
|
+
"fork-display-mode"?: string;
|
|
14
|
+
"side-by-side-split"?: string;
|
|
15
|
+
"dialog-backdrop-close"?: string;
|
|
16
|
+
"dark-mode"?: string;
|
|
17
|
+
"auto-resizing"?: string;
|
|
18
|
+
}, AdaptAutomationElement>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export * from "@mochabug/adapt-web";
|
|
23
|
+
export { AdaptCap, type AdaptCapProps } from "./AdaptCap.js";
|
|
4
24
|
/**
|
|
5
25
|
* Props for the Adapt React component.
|
|
6
26
|
*/
|
|
7
|
-
export interface AdaptProps
|
|
8
|
-
|
|
27
|
+
export interface AdaptProps {
|
|
28
|
+
id: string;
|
|
29
|
+
sessionToken?: string;
|
|
30
|
+
authToken?: string;
|
|
31
|
+
transmitter?: string;
|
|
32
|
+
signals?: {
|
|
33
|
+
[key: string]: SignalValue;
|
|
34
|
+
};
|
|
35
|
+
challengeToken?: string;
|
|
36
|
+
requiresChallenge?: boolean;
|
|
37
|
+
capWidgetOptions?: AdaptWebClientOptions["capWidgetOptions"];
|
|
38
|
+
inheritToken?: string;
|
|
39
|
+
inheritFrom?: {
|
|
40
|
+
hash: string;
|
|
41
|
+
} | {
|
|
42
|
+
param: string;
|
|
43
|
+
};
|
|
44
|
+
forkDisplayMode?: "side-by-side" | "dialog";
|
|
45
|
+
sideBySideSplit?: number;
|
|
46
|
+
dialogBackdropClose?: boolean;
|
|
47
|
+
darkMode?: boolean;
|
|
48
|
+
autoResizing?: boolean;
|
|
49
|
+
onSession?: (status: StatusJson, fork?: string) => void;
|
|
50
|
+
onOutput?: (output: Output) => void;
|
|
51
|
+
classNames?: AdaptWebClientOptions["classNames"];
|
|
52
|
+
styles?: Partial<CSSStyleDeclaration>;
|
|
53
|
+
/** CSS class name for the host element */
|
|
9
54
|
className?: string;
|
|
10
|
-
/** Inline styles for the
|
|
55
|
+
/** Inline styles for the host element */
|
|
11
56
|
style?: React.CSSProperties;
|
|
12
57
|
}
|
|
13
58
|
/**
|
|
14
59
|
* React component for embedding Adapt automations.
|
|
60
|
+
* Renders `<adapt-automation>` custom element and syncs non-serializable properties via ref.
|
|
15
61
|
*/
|
|
16
|
-
export declare const Adapt: import("react").ForwardRefExoticComponent<AdaptProps & import("react").RefAttributes<
|
|
62
|
+
export declare const Adapt: import("react").ForwardRefExoticComponent<AdaptProps & import("react").RefAttributes<AdaptAutomationElement>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mochabug/adapt-react",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc20",
|
|
4
4
|
"description": "React component for Adapt automation platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build:esm": "tsc --project tsconfig.esm.json",
|
|
19
19
|
"build:types": "tsc --project tsconfig.types.json",
|
|
20
20
|
"build": "rm -rf dist && npm run build:esm && npm run build:types",
|
|
21
|
-
"sample": "cd sample && npm run dev"
|
|
21
|
+
"sample": "npm run build && cd sample && npm run dev"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"adapt",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/react": "^19.2.
|
|
36
|
-
"react": "^19.2.
|
|
35
|
+
"@types/react": "^19.2.14",
|
|
36
|
+
"react": "^19.2.4",
|
|
37
37
|
"typescript": "^5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mochabug/adapt-web": "^1.0.0-
|
|
40
|
+
"@mochabug/adapt-web": "^1.0.0-rc42"
|
|
41
41
|
}
|
|
42
42
|
}
|