@mochabug/adapt-vue 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 +101 -0
- package/dist/esm/index.js +122 -0
- package/dist/types/index.d.ts +165 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @mochabug/adapt-vue
|
|
2
|
+
|
|
3
|
+
Vue component for Adapt.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @mochabug/adapt-vue
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Requires Vue 3.
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<script setup>
|
|
15
|
+
import { AdaptAutomation } from '@mochabug/adapt-vue';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<AdaptAutomation id="auto-123" :style="{ height: '600px' }" />
|
|
20
|
+
</template>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
If the automation requires authentication:
|
|
24
|
+
|
|
25
|
+
```vue
|
|
26
|
+
<AdaptAutomation id="auto-123" auth-token="your-token" :style="{ height: '600px' }" />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## SSR (Nuxt)
|
|
30
|
+
|
|
31
|
+
Keep auth token on server:
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<script setup>
|
|
35
|
+
import { AdaptAutomation } from '@mochabug/adapt-vue';
|
|
36
|
+
import { startSession } from '@mochabug/adapt-core';
|
|
37
|
+
|
|
38
|
+
const authToken = await getAuthTokenFromBackend();
|
|
39
|
+
const { token } = await startSession({ id: 'auto-123' }, authToken);
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<AdaptAutomation
|
|
44
|
+
id="auto-123"
|
|
45
|
+
:session-token="token"
|
|
46
|
+
:style="{ height: '600px' }"
|
|
47
|
+
/>
|
|
48
|
+
</template>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Session inheritance
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<!-- direct -->
|
|
55
|
+
<AdaptAutomation id="auto-123" inherit-token="token-from-parent" />
|
|
56
|
+
|
|
57
|
+
<!-- from URL hash: example.com#mb_session=xxx -->
|
|
58
|
+
<AdaptAutomation id="auto-123" :inherit-from="{ hash: 'mb_session' }" />
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Fork display
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<!-- side-by-side -->
|
|
65
|
+
<AdaptAutomation
|
|
66
|
+
id="auto-123"
|
|
67
|
+
fork-display-mode="side-by-side"
|
|
68
|
+
:side-by-side-split="60"
|
|
69
|
+
/>
|
|
70
|
+
|
|
71
|
+
<!-- dialog -->
|
|
72
|
+
<AdaptAutomation
|
|
73
|
+
id="auto-123"
|
|
74
|
+
fork-display-mode="dialog"
|
|
75
|
+
:dialog-backdrop-close="true"
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Props
|
|
80
|
+
|
|
81
|
+
| Prop | Type |
|
|
82
|
+
|------|------|
|
|
83
|
+
| `id` | `string` (required) |
|
|
84
|
+
| `session-token` | `string` |
|
|
85
|
+
| `auth-token` | `string` |
|
|
86
|
+
| `inherit-token` | `string` |
|
|
87
|
+
| `inherit-from` | `{ hash: string } \| { param: string }` |
|
|
88
|
+
| `fork-display-mode` | `'side-by-side' \| 'dialog'` |
|
|
89
|
+
| `side-by-side-split` | `number` (0-100) |
|
|
90
|
+
| `dialog-backdrop-close` | `boolean` |
|
|
91
|
+
|
|
92
|
+
## Events
|
|
93
|
+
|
|
94
|
+
| Event | Payload |
|
|
95
|
+
|-------|---------|
|
|
96
|
+
| `session` | `(status, fork?)` |
|
|
97
|
+
| `output` | `(output)` |
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
ISC © mochabug AB
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { defineComponent, ref, onMounted, onUnmounted, watch, h, } from "vue";
|
|
2
|
+
import { AdaptWebClient } from "@mochabug/adapt-web";
|
|
3
|
+
/**
|
|
4
|
+
* Vue component for embedding Adapt automations.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```vue
|
|
8
|
+
* <template>
|
|
9
|
+
* <AdaptAutomation
|
|
10
|
+
* id="automation-123"
|
|
11
|
+
* class="my-automation"
|
|
12
|
+
* :style="{ height: '600px' }"
|
|
13
|
+
* @session="handleSession"
|
|
14
|
+
* />
|
|
15
|
+
* </template>
|
|
16
|
+
*
|
|
17
|
+
* <script setup>
|
|
18
|
+
* import { AdaptAutomation } from '@mochabug/adapt-vue';
|
|
19
|
+
*
|
|
20
|
+
* const handleSession = (status, fork) => {
|
|
21
|
+
* console.log('Status:', status, fork);
|
|
22
|
+
* };
|
|
23
|
+
* </script>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const AdaptAutomation = defineComponent({
|
|
27
|
+
name: "AdaptAutomation",
|
|
28
|
+
inheritAttrs: false,
|
|
29
|
+
props: {
|
|
30
|
+
/** Automation ID to connect to */
|
|
31
|
+
id: {
|
|
32
|
+
type: String,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
/** Pre-created session token from server-side session creation */
|
|
36
|
+
sessionToken: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: undefined,
|
|
39
|
+
},
|
|
40
|
+
/** Authentication token for starting new sessions */
|
|
41
|
+
authToken: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: undefined,
|
|
44
|
+
},
|
|
45
|
+
/** Token to inherit an existing session */
|
|
46
|
+
inheritToken: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: undefined,
|
|
49
|
+
},
|
|
50
|
+
/** Auto-parse inherit token from URL */
|
|
51
|
+
inheritFrom: {
|
|
52
|
+
type: Object,
|
|
53
|
+
default: undefined,
|
|
54
|
+
},
|
|
55
|
+
/** Fork display mode (default: 'side-by-side') */
|
|
56
|
+
forkDisplayMode: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: "side-by-side",
|
|
59
|
+
},
|
|
60
|
+
/** Split percentage for side-by-side mode, 0-100 (default: 50) */
|
|
61
|
+
sideBySideSplit: {
|
|
62
|
+
type: Number,
|
|
63
|
+
default: 50,
|
|
64
|
+
},
|
|
65
|
+
/** Allow closing dialog via backdrop click (default: false) */
|
|
66
|
+
dialogBackdropClose: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: false,
|
|
69
|
+
},
|
|
70
|
+
/** Custom CSS class names for internal elements */
|
|
71
|
+
classNames: {
|
|
72
|
+
type: Object,
|
|
73
|
+
default: undefined,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
emits: {
|
|
77
|
+
/** Emitted when session status changes */
|
|
78
|
+
session: (_status, _fork) => true,
|
|
79
|
+
/** Emitted when automation produces output */
|
|
80
|
+
output: (_output) => true,
|
|
81
|
+
},
|
|
82
|
+
setup(props, { emit, attrs }) {
|
|
83
|
+
const containerId = `adapt-${Math.random().toString(36).slice(2, 11)}`;
|
|
84
|
+
const clientRef = ref(null);
|
|
85
|
+
const createClient = () => {
|
|
86
|
+
if (clientRef.value) {
|
|
87
|
+
clientRef.value.destroy();
|
|
88
|
+
clientRef.value = null;
|
|
89
|
+
}
|
|
90
|
+
clientRef.value = new AdaptWebClient({
|
|
91
|
+
container: containerId,
|
|
92
|
+
id: props.id,
|
|
93
|
+
sessionToken: props.sessionToken,
|
|
94
|
+
authToken: props.authToken,
|
|
95
|
+
inheritToken: props.inheritToken,
|
|
96
|
+
inheritFrom: props.inheritFrom,
|
|
97
|
+
forkDisplayMode: props.forkDisplayMode,
|
|
98
|
+
sideBySideSplit: props.sideBySideSplit,
|
|
99
|
+
dialogBackdropClose: props.dialogBackdropClose,
|
|
100
|
+
classNames: props.classNames,
|
|
101
|
+
onSession: (status, fork) => {
|
|
102
|
+
emit("session", status, fork);
|
|
103
|
+
},
|
|
104
|
+
onOutput: (output) => {
|
|
105
|
+
emit("output", output);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
onMounted(() => {
|
|
110
|
+
createClient();
|
|
111
|
+
});
|
|
112
|
+
onUnmounted(() => {
|
|
113
|
+
if (clientRef.value) {
|
|
114
|
+
clientRef.value.destroy();
|
|
115
|
+
clientRef.value = null;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
watch(() => props.id, createClient);
|
|
119
|
+
return () => h("div", { id: containerId, ...attrs });
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
export default AdaptAutomation;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type PropType } from "vue";
|
|
2
|
+
import { type AdaptWebClientOptions } from "@mochabug/adapt-web";
|
|
3
|
+
import type { Output, StatusJson } from "@mochabug/adapt-core";
|
|
4
|
+
export type { Output, StatusJson };
|
|
5
|
+
/**
|
|
6
|
+
* Vue component for embedding Adapt automations.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```vue
|
|
10
|
+
* <template>
|
|
11
|
+
* <AdaptAutomation
|
|
12
|
+
* id="automation-123"
|
|
13
|
+
* class="my-automation"
|
|
14
|
+
* :style="{ height: '600px' }"
|
|
15
|
+
* @session="handleSession"
|
|
16
|
+
* />
|
|
17
|
+
* </template>
|
|
18
|
+
*
|
|
19
|
+
* <script setup>
|
|
20
|
+
* import { AdaptAutomation } from '@mochabug/adapt-vue';
|
|
21
|
+
*
|
|
22
|
+
* const handleSession = (status, fork) => {
|
|
23
|
+
* console.log('Status:', status, fork);
|
|
24
|
+
* };
|
|
25
|
+
* </script>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const AdaptAutomation: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
29
|
+
/** Automation ID to connect to */
|
|
30
|
+
id: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
required: true;
|
|
33
|
+
};
|
|
34
|
+
/** Pre-created session token from server-side session creation */
|
|
35
|
+
sessionToken: {
|
|
36
|
+
type: StringConstructor;
|
|
37
|
+
default: undefined;
|
|
38
|
+
};
|
|
39
|
+
/** Authentication token for starting new sessions */
|
|
40
|
+
authToken: {
|
|
41
|
+
type: StringConstructor;
|
|
42
|
+
default: undefined;
|
|
43
|
+
};
|
|
44
|
+
/** Token to inherit an existing session */
|
|
45
|
+
inheritToken: {
|
|
46
|
+
type: StringConstructor;
|
|
47
|
+
default: undefined;
|
|
48
|
+
};
|
|
49
|
+
/** Auto-parse inherit token from URL */
|
|
50
|
+
inheritFrom: {
|
|
51
|
+
type: PropType<{
|
|
52
|
+
hash: string;
|
|
53
|
+
} | {
|
|
54
|
+
param: string;
|
|
55
|
+
}>;
|
|
56
|
+
default: undefined;
|
|
57
|
+
};
|
|
58
|
+
/** Fork display mode (default: 'side-by-side') */
|
|
59
|
+
forkDisplayMode: {
|
|
60
|
+
type: PropType<"side-by-side" | "dialog">;
|
|
61
|
+
default: string;
|
|
62
|
+
};
|
|
63
|
+
/** Split percentage for side-by-side mode, 0-100 (default: 50) */
|
|
64
|
+
sideBySideSplit: {
|
|
65
|
+
type: NumberConstructor;
|
|
66
|
+
default: number;
|
|
67
|
+
};
|
|
68
|
+
/** Allow closing dialog via backdrop click (default: false) */
|
|
69
|
+
dialogBackdropClose: {
|
|
70
|
+
type: BooleanConstructor;
|
|
71
|
+
default: boolean;
|
|
72
|
+
};
|
|
73
|
+
/** Custom CSS class names for internal elements */
|
|
74
|
+
classNames: {
|
|
75
|
+
type: PropType<AdaptWebClientOptions["classNames"]>;
|
|
76
|
+
default: undefined;
|
|
77
|
+
};
|
|
78
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
81
|
+
/** Emitted when session status changes */
|
|
82
|
+
session: (_status: StatusJson, _fork?: string) => true;
|
|
83
|
+
/** Emitted when automation produces output */
|
|
84
|
+
output: (_output: Output) => true;
|
|
85
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
86
|
+
/** Automation ID to connect to */
|
|
87
|
+
id: {
|
|
88
|
+
type: StringConstructor;
|
|
89
|
+
required: true;
|
|
90
|
+
};
|
|
91
|
+
/** Pre-created session token from server-side session creation */
|
|
92
|
+
sessionToken: {
|
|
93
|
+
type: StringConstructor;
|
|
94
|
+
default: undefined;
|
|
95
|
+
};
|
|
96
|
+
/** Authentication token for starting new sessions */
|
|
97
|
+
authToken: {
|
|
98
|
+
type: StringConstructor;
|
|
99
|
+
default: undefined;
|
|
100
|
+
};
|
|
101
|
+
/** Token to inherit an existing session */
|
|
102
|
+
inheritToken: {
|
|
103
|
+
type: StringConstructor;
|
|
104
|
+
default: undefined;
|
|
105
|
+
};
|
|
106
|
+
/** Auto-parse inherit token from URL */
|
|
107
|
+
inheritFrom: {
|
|
108
|
+
type: PropType<{
|
|
109
|
+
hash: string;
|
|
110
|
+
} | {
|
|
111
|
+
param: string;
|
|
112
|
+
}>;
|
|
113
|
+
default: undefined;
|
|
114
|
+
};
|
|
115
|
+
/** Fork display mode (default: 'side-by-side') */
|
|
116
|
+
forkDisplayMode: {
|
|
117
|
+
type: PropType<"side-by-side" | "dialog">;
|
|
118
|
+
default: string;
|
|
119
|
+
};
|
|
120
|
+
/** Split percentage for side-by-side mode, 0-100 (default: 50) */
|
|
121
|
+
sideBySideSplit: {
|
|
122
|
+
type: NumberConstructor;
|
|
123
|
+
default: number;
|
|
124
|
+
};
|
|
125
|
+
/** Allow closing dialog via backdrop click (default: false) */
|
|
126
|
+
dialogBackdropClose: {
|
|
127
|
+
type: BooleanConstructor;
|
|
128
|
+
default: boolean;
|
|
129
|
+
};
|
|
130
|
+
/** Custom CSS class names for internal elements */
|
|
131
|
+
classNames: {
|
|
132
|
+
type: PropType<AdaptWebClientOptions["classNames"]>;
|
|
133
|
+
default: undefined;
|
|
134
|
+
};
|
|
135
|
+
}>> & Readonly<{
|
|
136
|
+
onSession?: ((_status: StatusJson, _fork?: string | undefined) => any) | undefined;
|
|
137
|
+
onOutput?: ((_output: Output) => any) | undefined;
|
|
138
|
+
}>, {
|
|
139
|
+
classNames: {
|
|
140
|
+
root?: string;
|
|
141
|
+
wrapper?: string;
|
|
142
|
+
frame?: string;
|
|
143
|
+
frameMain?: string;
|
|
144
|
+
frameFork?: string;
|
|
145
|
+
iframe?: string;
|
|
146
|
+
dialogBackdrop?: string;
|
|
147
|
+
dialog?: string;
|
|
148
|
+
dialogBanner?: string;
|
|
149
|
+
dialogClose?: string;
|
|
150
|
+
dragHandle?: string;
|
|
151
|
+
expandButton?: string;
|
|
152
|
+
} | undefined;
|
|
153
|
+
sessionToken: string;
|
|
154
|
+
authToken: string;
|
|
155
|
+
inheritToken: string;
|
|
156
|
+
inheritFrom: {
|
|
157
|
+
hash: string;
|
|
158
|
+
} | {
|
|
159
|
+
param: string;
|
|
160
|
+
};
|
|
161
|
+
forkDisplayMode: "side-by-side" | "dialog";
|
|
162
|
+
sideBySideSplit: number;
|
|
163
|
+
dialogBackdropClose: boolean;
|
|
164
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
165
|
+
export default AdaptAutomation;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mochabug/adapt-vue",
|
|
3
|
+
"version": "1.0.0-rc1",
|
|
4
|
+
"description": "Vue component for Adapt automation platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
19
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
20
|
+
"build": "rm -rf dist && npm run build:esm && npm run build:types",
|
|
21
|
+
"sample": "cd sample && npm run dev"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"adapt",
|
|
25
|
+
"automations",
|
|
26
|
+
"mochabug",
|
|
27
|
+
"vue"
|
|
28
|
+
],
|
|
29
|
+
"author": "mochabug AB",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"vue": "^3.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vue": "^3.5.24"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@mochabug/adapt-web": "^1.0.0-rc22"
|
|
40
|
+
}
|
|
41
|
+
}
|