@mochabug/adapt-svelte 1.0.0-rc1

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 ADDED
@@ -0,0 +1,111 @@
1
+ # @mochabug/adapt-svelte
2
+
3
+ Svelte component for Adapt.
4
+
5
+ ```bash
6
+ npm install @mochabug/adapt-svelte
7
+ ```
8
+
9
+ Requires Svelte 4 or 5.
10
+
11
+ ## Quickstart
12
+
13
+ ```svelte
14
+ <script>
15
+ import { AdaptAutomation } from '@mochabug/adapt-svelte';
16
+ </script>
17
+
18
+ <AdaptAutomation id="auto-123" style="height: 600px;" />
19
+ ```
20
+
21
+ If the automation requires authentication:
22
+
23
+ ```svelte
24
+ <AdaptAutomation id="auto-123" authToken="your-token" style="height: 600px;" />
25
+ ```
26
+
27
+ ## SSR (SvelteKit)
28
+
29
+ Keep auth token on server:
30
+
31
+ ```typescript
32
+ // +page.server.ts
33
+ import { startSession } from '@mochabug/adapt-core';
34
+
35
+ export async function load() {
36
+ const authToken = await getAuthTokenFromBackend();
37
+ const { token } = await startSession({ id: 'auto-123' }, authToken);
38
+ return { sessionToken: token };
39
+ }
40
+ ```
41
+
42
+ ```svelte
43
+ <!-- +page.svelte -->
44
+ <script>
45
+ import { AdaptAutomation } from '@mochabug/adapt-svelte';
46
+ export let data;
47
+ </script>
48
+
49
+ <AdaptAutomation
50
+ id="auto-123"
51
+ sessionToken={data.sessionToken}
52
+ style="height: 600px;"
53
+ />
54
+ ```
55
+
56
+ ## Session inheritance
57
+
58
+ ```svelte
59
+ <!-- direct -->
60
+ <AdaptAutomation id="auto-123" inheritToken="token-from-parent" />
61
+
62
+ <!-- from URL hash: example.com#mb_session=xxx -->
63
+ <AdaptAutomation id="auto-123" inheritFrom={{ hash: 'mb_session' }} />
64
+ ```
65
+
66
+ ## Fork display
67
+
68
+ ```svelte
69
+ <!-- side-by-side -->
70
+ <AdaptAutomation
71
+ id="auto-123"
72
+ forkDisplayMode="side-by-side"
73
+ sideBySideSplit={60}
74
+ />
75
+
76
+ <!-- dialog -->
77
+ <AdaptAutomation
78
+ id="auto-123"
79
+ forkDisplayMode="dialog"
80
+ dialogBackdropClose={true}
81
+ />
82
+ ```
83
+
84
+ ## Callbacks
85
+
86
+ ```svelte
87
+ <AdaptAutomation
88
+ id="auto-123"
89
+ onsession={(e) => console.log(e.status, e.fork)}
90
+ onoutput={(e) => console.log(e.output)}
91
+ />
92
+ ```
93
+
94
+ ## Props
95
+
96
+ | Prop | Type |
97
+ |------|------|
98
+ | `id` | `string` (required) |
99
+ | `sessionToken` | `string` |
100
+ | `authToken` | `string` |
101
+ | `inheritToken` | `string` |
102
+ | `inheritFrom` | `{ hash: string } \| { param: string }` |
103
+ | `forkDisplayMode` | `'side-by-side' \| 'dialog'` |
104
+ | `sideBySideSplit` | `number` (0-100) |
105
+ | `dialogBackdropClose` | `boolean` |
106
+ | `onsession` | `(event) => void` |
107
+ | `onoutput` | `(event) => void` |
108
+
109
+ ## License
110
+
111
+ ISC © mochabug AB
@@ -0,0 +1,85 @@
1
+ <script lang="ts">
2
+ import { onMount, onDestroy } from 'svelte';
3
+ import { AdaptWebClient, type AdaptWebClientOptions } from '@mochabug/adapt-web';
4
+ import type { Output, StatusJson } from '@mochabug/adapt-core';
5
+
6
+ // Props
7
+ interface Props {
8
+ id: string;
9
+ sessionToken?: string;
10
+ authToken?: string;
11
+ inheritToken?: string;
12
+ inheritFrom?: { hash: string } | { param: string };
13
+ forkDisplayMode?: 'side-by-side' | 'dialog';
14
+ sideBySideSplit?: number;
15
+ dialogBackdropClose?: boolean;
16
+ classNames?: AdaptWebClientOptions['classNames'];
17
+ onsession?: (event: { status: StatusJson; fork?: string }) => void;
18
+ onoutput?: (event: { output: Output }) => void;
19
+ [key: string]: unknown;
20
+ }
21
+
22
+ let {
23
+ id,
24
+ sessionToken = undefined,
25
+ authToken = undefined,
26
+ inheritToken = undefined,
27
+ inheritFrom = undefined,
28
+ forkDisplayMode = 'side-by-side',
29
+ sideBySideSplit = 50,
30
+ dialogBackdropClose = false,
31
+ classNames = undefined,
32
+ onsession,
33
+ onoutput,
34
+ ...restProps
35
+ }: Props = $props();
36
+
37
+ const containerId = `adapt-${Math.random().toString(36).slice(2, 11)}`;
38
+ let client: AdaptWebClient | null = null;
39
+
40
+ function createClient() {
41
+ if (client) {
42
+ client.destroy();
43
+ client = null;
44
+ }
45
+
46
+ client = new AdaptWebClient({
47
+ container: containerId,
48
+ id,
49
+ sessionToken,
50
+ authToken,
51
+ inheritToken,
52
+ inheritFrom,
53
+ forkDisplayMode,
54
+ sideBySideSplit,
55
+ dialogBackdropClose,
56
+ classNames,
57
+ onSession: (status, fork) => {
58
+ onsession?.({ status, fork });
59
+ },
60
+ onOutput: (output) => {
61
+ onoutput?.({ output });
62
+ },
63
+ });
64
+ }
65
+
66
+ onMount(() => {
67
+ createClient();
68
+ });
69
+
70
+ onDestroy(() => {
71
+ if (client) {
72
+ client.destroy();
73
+ client = null;
74
+ }
75
+ });
76
+
77
+ // Recreate client when id changes
78
+ $effect(() => {
79
+ if (id && typeof window !== 'undefined') {
80
+ createClient();
81
+ }
82
+ });
83
+ </script>
84
+
85
+ <div id={containerId} {...restProps}></div>
@@ -0,0 +1,28 @@
1
+ import { type AdaptWebClientOptions } from '@mochabug/adapt-web';
2
+ import type { Output, StatusJson } from '@mochabug/adapt-core';
3
+ interface Props {
4
+ id: string;
5
+ sessionToken?: string;
6
+ authToken?: string;
7
+ inheritToken?: string;
8
+ inheritFrom?: {
9
+ hash: string;
10
+ } | {
11
+ param: string;
12
+ };
13
+ forkDisplayMode?: 'side-by-side' | 'dialog';
14
+ sideBySideSplit?: number;
15
+ dialogBackdropClose?: boolean;
16
+ classNames?: AdaptWebClientOptions['classNames'];
17
+ onsession?: (event: {
18
+ status: StatusJson;
19
+ fork?: string;
20
+ }) => void;
21
+ onoutput?: (event: {
22
+ output: Output;
23
+ }) => void;
24
+ [key: string]: unknown;
25
+ }
26
+ declare const AdaptAutomation: import("svelte").Component<Props, {}, "">;
27
+ type AdaptAutomation = ReturnType<typeof AdaptAutomation>;
28
+ export default AdaptAutomation;
@@ -0,0 +1,2 @@
1
+ export { default as AdaptAutomation } from './AdaptAutomation.svelte';
2
+ export type { Output, StatusJson } from '@mochabug/adapt-core';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as AdaptAutomation } from './AdaptAutomation.svelte';
@@ -0,0 +1,5 @@
1
+ declare module '*.svelte' {
2
+ import type { ComponentType, SvelteComponent } from 'svelte';
3
+ const component: ComponentType<SvelteComponent>;
4
+ export default component;
5
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mochabug/adapt-svelte",
3
+ "version": "1.0.0-rc1",
4
+ "description": "Svelte component for Adapt automation platform",
5
+ "type": "module",
6
+ "svelte": "./dist/index.js",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "svelte-package -i src -o dist",
21
+ "sample": "cd sample && npm install && npm run dev"
22
+ },
23
+ "keywords": [
24
+ "adapt",
25
+ "automations",
26
+ "mochabug",
27
+ "svelte"
28
+ ],
29
+ "author": "mochabug AB",
30
+ "license": "ISC",
31
+ "peerDependencies": {
32
+ "svelte": "^4.0.0 || ^5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@sveltejs/package": "^2.5.6",
36
+ "svelte": "^5.43.14",
37
+ "typescript": "^5.9.3"
38
+ },
39
+ "dependencies": {
40
+ "@mochabug/adapt-web": "^1.0.0-rc22"
41
+ }
42
+ }