@mochabug/adapt-react 1.0.0-rc1 → 1.0.0-rc10
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/README.md +44 -24
- package/dist/esm/index.js +33 -30
- package/dist/types/index.d.ts +4 -30
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -11,15 +11,15 @@ Requires React 17, 18, or 19.
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
|
-
import {
|
|
14
|
+
import { Adapt } from '@mochabug/adapt-react';
|
|
15
15
|
|
|
16
|
-
<
|
|
16
|
+
<Adapt id="auto-123" style={{ height: 600 }} />
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
If the automation requires authentication:
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
22
|
-
<
|
|
22
|
+
<Adapt id="auto-123" authToken="your-token" style={{ height: 600 }} />
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## SSR (Next.js)
|
|
@@ -39,16 +39,10 @@ export default async function Page() {
|
|
|
39
39
|
|
|
40
40
|
// components/AutomationClient.tsx (Client Component)
|
|
41
41
|
'use client';
|
|
42
|
-
import {
|
|
42
|
+
import { Adapt } from '@mochabug/adapt-react';
|
|
43
43
|
|
|
44
44
|
export function AutomationClient({ sessionToken }) {
|
|
45
|
-
return
|
|
46
|
-
<AdaptAutomation
|
|
47
|
-
id="auto-123"
|
|
48
|
-
sessionToken={sessionToken}
|
|
49
|
-
style={{ height: 600 }}
|
|
50
|
-
/>
|
|
51
|
-
);
|
|
45
|
+
return <Adapt id="auto-123" sessionToken={sessionToken} style={{ height: 600 }} />;
|
|
52
46
|
}
|
|
53
47
|
```
|
|
54
48
|
|
|
@@ -56,40 +50,64 @@ export function AutomationClient({ sessionToken }) {
|
|
|
56
50
|
|
|
57
51
|
```tsx
|
|
58
52
|
// direct
|
|
59
|
-
<
|
|
53
|
+
<Adapt id="auto-123" inheritToken="token-from-parent" />
|
|
60
54
|
|
|
61
55
|
// from URL hash: example.com#mb_session=xxx
|
|
62
|
-
<
|
|
56
|
+
<Adapt id="auto-123" inheritFrom={{ hash: 'mb_session' }} />
|
|
63
57
|
```
|
|
64
58
|
|
|
65
59
|
## Fork display
|
|
66
60
|
|
|
67
61
|
```tsx
|
|
68
62
|
// side-by-side
|
|
69
|
-
<
|
|
70
|
-
id="auto-123"
|
|
71
|
-
forkDisplayMode="side-by-side"
|
|
72
|
-
sideBySideSplit={60}
|
|
73
|
-
/>
|
|
63
|
+
<Adapt id="auto-123" forkDisplayMode="side-by-side" sideBySideSplit={60} />
|
|
74
64
|
|
|
75
65
|
// dialog
|
|
76
|
-
<
|
|
77
|
-
id="auto-123"
|
|
78
|
-
forkDisplayMode="dialog"
|
|
79
|
-
dialogBackdropClose
|
|
80
|
-
/>
|
|
66
|
+
<Adapt id="auto-123" forkDisplayMode="dialog" dialogBackdropClose />
|
|
81
67
|
```
|
|
82
68
|
|
|
83
69
|
## Callbacks
|
|
84
70
|
|
|
85
71
|
```tsx
|
|
86
|
-
<
|
|
72
|
+
<Adapt
|
|
87
73
|
id="auto-123"
|
|
88
74
|
onSession={(status, fork) => console.log(status, fork)}
|
|
89
75
|
onOutput={(output) => console.log(output)}
|
|
90
76
|
/>
|
|
91
77
|
```
|
|
92
78
|
|
|
79
|
+
## Advanced: Multiple transmitters or initial signals
|
|
80
|
+
|
|
81
|
+
For automations with multiple entry points or when you need to pass initial data:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { Adapt, type SignalDataJson } from '@mochabug/adapt-react';
|
|
85
|
+
|
|
86
|
+
// Start from a specific transmitter
|
|
87
|
+
<Adapt
|
|
88
|
+
id="auto-123"
|
|
89
|
+
authToken="your-token"
|
|
90
|
+
transmitter="my-transmitter"
|
|
91
|
+
style={{ height: 600 }}
|
|
92
|
+
/>
|
|
93
|
+
|
|
94
|
+
// Start with initial signals (data must be base64 encoded)
|
|
95
|
+
const signals: { [key: string]: SignalDataJson } = {
|
|
96
|
+
'input': {
|
|
97
|
+
mimeType: 'text/plain',
|
|
98
|
+
data: btoa('Hello World')
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
<Adapt
|
|
103
|
+
id="auto-123"
|
|
104
|
+
authToken="your-token"
|
|
105
|
+
transmitter="file-processor"
|
|
106
|
+
signals={signals}
|
|
107
|
+
style={{ height: 600 }}
|
|
108
|
+
/>
|
|
109
|
+
```
|
|
110
|
+
|
|
93
111
|
## Props
|
|
94
112
|
|
|
95
113
|
| Prop | Type |
|
|
@@ -97,6 +115,8 @@ export function AutomationClient({ sessionToken }) {
|
|
|
97
115
|
| `id` | `string` (required) |
|
|
98
116
|
| `sessionToken` | `string` |
|
|
99
117
|
| `authToken` | `string` |
|
|
118
|
+
| `transmitter` | `string` |
|
|
119
|
+
| `signals` | `{ [key: string]: SignalDataJson }` |
|
|
100
120
|
| `inheritToken` | `string` |
|
|
101
121
|
| `inheritFrom` | `{ hash: string } \| { param: string }` |
|
|
102
122
|
| `forkDisplayMode` | `'side-by-side' \| 'dialog'` |
|
package/dist/esm/index.js
CHANGED
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, forwardRef } from "react";
|
|
3
2
|
import { AdaptWebClient, } from "@mochabug/adapt-web";
|
|
3
|
+
import { forwardRef, useEffect, useRef } from "react";
|
|
4
|
+
// Re-export everything from web
|
|
5
|
+
export * from "@mochabug/adapt-web";
|
|
4
6
|
/**
|
|
5
7
|
* React component for embedding Adapt automations.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```tsx
|
|
9
|
-
* import { AdaptAutomation } from '@mochabug/adapt-react';
|
|
10
|
-
*
|
|
11
|
-
* function App() {
|
|
12
|
-
* return (
|
|
13
|
-
* <AdaptAutomation
|
|
14
|
-
* id="automation-123"
|
|
15
|
-
* style={{ height: '600px' }}
|
|
16
|
-
* onSession={(status) => console.log('Status:', status)}
|
|
17
|
-
* />
|
|
18
|
-
* );
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```tsx
|
|
24
|
-
* // With session inheritance from URL hash
|
|
25
|
-
* <AdaptAutomation
|
|
26
|
-
* id="automation-123"
|
|
27
|
-
* inheritFrom={{ hash: 'mb_session' }}
|
|
28
|
-
* style={{ height: '100vh' }}
|
|
29
|
-
* />
|
|
30
|
-
* ```
|
|
31
8
|
*/
|
|
32
|
-
export const
|
|
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) {
|
|
33
10
|
const clientRef = useRef(null);
|
|
34
11
|
const internalRef = useRef(null);
|
|
35
12
|
const containerIdRef = useRef(`adapt-${Math.random().toString(36).slice(2, 11)}`);
|
|
36
13
|
const containerId = containerIdRef.current;
|
|
37
14
|
// Merge refs
|
|
38
15
|
const setRef = (element) => {
|
|
39
|
-
internalRef.current =
|
|
40
|
-
element;
|
|
16
|
+
internalRef.current = element;
|
|
41
17
|
if (typeof ref === "function") {
|
|
42
18
|
ref(element);
|
|
43
19
|
}
|
|
@@ -51,11 +27,15 @@ export const AdaptAutomation = forwardRef(function AdaptAutomation({ id, session
|
|
|
51
27
|
id,
|
|
52
28
|
sessionToken,
|
|
53
29
|
authToken,
|
|
30
|
+
transmitter,
|
|
31
|
+
signals,
|
|
54
32
|
inheritToken,
|
|
55
33
|
inheritFrom,
|
|
56
34
|
forkDisplayMode,
|
|
57
35
|
sideBySideSplit,
|
|
58
36
|
dialogBackdropClose,
|
|
37
|
+
darkMode,
|
|
38
|
+
autoResizing,
|
|
59
39
|
onSession,
|
|
60
40
|
onOutput,
|
|
61
41
|
classNames,
|
|
@@ -65,7 +45,30 @@ export const AdaptAutomation = forwardRef(function AdaptAutomation({ id, session
|
|
|
65
45
|
clientRef.current = null;
|
|
66
46
|
};
|
|
67
47
|
// Only recreate client if automation ID changes
|
|
68
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
48
|
}, [id]);
|
|
49
|
+
// Runtime updates for darkMode
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (darkMode !== undefined) {
|
|
52
|
+
clientRef.current?.setDarkMode(darkMode);
|
|
53
|
+
}
|
|
54
|
+
}, [darkMode]);
|
|
55
|
+
// Runtime updates for autoResizing
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (autoResizing !== undefined) {
|
|
58
|
+
clientRef.current?.setAutoResizing(autoResizing);
|
|
59
|
+
}
|
|
60
|
+
}, [autoResizing]);
|
|
61
|
+
// Runtime updates for forkDisplayMode
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (forkDisplayMode !== undefined) {
|
|
64
|
+
clientRef.current?.setForkDisplayMode(forkDisplayMode);
|
|
65
|
+
}
|
|
66
|
+
}, [forkDisplayMode]);
|
|
67
|
+
// Runtime updates for dialogBackdropClose
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (dialogBackdropClose !== undefined) {
|
|
70
|
+
clientRef.current?.setDialogBackdropClose(dialogBackdropClose);
|
|
71
|
+
}
|
|
72
|
+
}, [dialogBackdropClose]);
|
|
70
73
|
return (_jsx("div", { ref: setRef, id: containerId, className: className, style: style }));
|
|
71
74
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type AdaptWebClientOptions } from "@mochabug/adapt-web";
|
|
2
|
-
|
|
3
|
-
export type { Output, StatusJson };
|
|
2
|
+
export * from "@mochabug/adapt-web";
|
|
4
3
|
/**
|
|
5
|
-
* Props for the
|
|
4
|
+
* Props for the Adapt React component.
|
|
6
5
|
*/
|
|
7
|
-
export interface
|
|
6
|
+
export interface AdaptProps extends Pick<AdaptWebClientOptions, "id" | "sessionToken" | "authToken" | "transmitter" | "signals" | "inheritToken" | "inheritFrom" | "forkDisplayMode" | "sideBySideSplit" | "dialogBackdropClose" | "darkMode" | "autoResizing" | "onSession" | "onOutput" | "classNames"> {
|
|
8
7
|
/** CSS class name for the container */
|
|
9
8
|
className?: string;
|
|
10
9
|
/** Inline styles for the container */
|
|
@@ -12,30 +11,5 @@ export interface AdaptAutomationProps extends Pick<AdaptWebClientOptions, "id" |
|
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* React component for embedding Adapt automations.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* import { AdaptAutomation } from '@mochabug/adapt-react';
|
|
19
|
-
*
|
|
20
|
-
* function App() {
|
|
21
|
-
* return (
|
|
22
|
-
* <AdaptAutomation
|
|
23
|
-
* id="automation-123"
|
|
24
|
-
* style={{ height: '600px' }}
|
|
25
|
-
* onSession={(status) => console.log('Status:', status)}
|
|
26
|
-
* />
|
|
27
|
-
* );
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```tsx
|
|
33
|
-
* // With session inheritance from URL hash
|
|
34
|
-
* <AdaptAutomation
|
|
35
|
-
* id="automation-123"
|
|
36
|
-
* inheritFrom={{ hash: 'mb_session' }}
|
|
37
|
-
* style={{ height: '100vh' }}
|
|
38
|
-
* />
|
|
39
|
-
* ```
|
|
40
14
|
*/
|
|
41
|
-
export declare const
|
|
15
|
+
export declare const Adapt: import("react").ForwardRefExoticComponent<AdaptProps & import("react").RefAttributes<HTMLDivElement>>;
|
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-rc10",
|
|
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.7",
|
|
36
|
+
"react": "^19.2.3",
|
|
37
37
|
"typescript": "^5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mochabug/adapt-web": "
|
|
40
|
+
"@mochabug/adapt-web": "*"
|
|
41
41
|
}
|
|
42
42
|
}
|