@mochabug/adapt-svelte 1.0.0-rc15 → 1.0.0-rc17

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/Adapt.svelte CHANGED
@@ -1,8 +1,9 @@
1
1
  <script lang="ts">
2
- import { AdaptWebClient, type AdaptWebClientOptions, type Output, type SignalValue, type StatusJson } from '@mochabug/adapt-web';
3
- import { onDestroy, onMount } from 'svelte';
2
+ import { AdaptAutomationElement, type AdaptWebClientOptions, type Output, type SignalValue, type StatusJson } from '@mochabug/adapt-web';
3
+ // Ensure custom element is registered
4
+ void AdaptAutomationElement;
4
5
 
5
- // Props interface matching AdaptWebClientOptions
6
+ // Props interface
6
7
  interface Props {
7
8
  id: string;
8
9
  sessionToken?: string;
@@ -20,6 +21,7 @@
20
21
  darkMode?: boolean;
21
22
  autoResizing?: boolean;
22
23
  classNames?: AdaptWebClientOptions['classNames'];
24
+ styles?: Partial<CSSStyleDeclaration>;
23
25
  onsession?: (event: { status: StatusJson; fork?: string }) => void;
24
26
  onoutput?: (event: { output: Output }) => void;
25
27
  [key: string]: unknown;
@@ -42,81 +44,47 @@
42
44
  darkMode = false,
43
45
  autoResizing = false,
44
46
  classNames = undefined,
47
+ styles = undefined,
45
48
  onsession,
46
49
  onoutput,
47
50
  ...restProps
48
51
  }: Props = $props();
49
52
 
50
- const containerId = `adapt-${Math.random().toString(36).slice(2, 11)}`;
51
- let client: AdaptWebClient | null = null;
53
+ let element: AdaptAutomationElement;
52
54
 
53
- function createClient() {
54
- if (client) {
55
- client.destroy();
56
- client = null;
57
- }
58
-
59
- client = new AdaptWebClient({
60
- container: containerId,
61
- id,
62
- sessionToken,
63
- authToken,
64
- transmitter,
65
- signals,
66
- challengeToken,
67
- requiresChallenge,
68
- capWidgetOptions,
69
- inheritToken,
70
- inheritFrom,
71
- forkDisplayMode,
72
- sideBySideSplit,
73
- dialogBackdropClose,
74
- darkMode,
75
- autoResizing,
76
- classNames,
77
- onSession: (status, fork) => {
78
- onsession?.({ status, fork });
79
- },
80
- onOutput: (output) => {
81
- onoutput?.({ output });
82
- },
83
- });
55
+ function syncProperties() {
56
+ if (!element) return;
57
+ element.signals = signals;
58
+ element.capWidgetOptions = capWidgetOptions;
59
+ element.inheritFrom = inheritFrom;
60
+ element.classNames = classNames;
61
+ element.styles = styles;
62
+ element.onSessionCallback = (status, fork) => {
63
+ onsession?.({ status, fork });
64
+ };
65
+ element.onOutputCallback = (output) => {
66
+ onoutput?.({ output });
67
+ };
84
68
  }
85
69
 
86
- onMount(() => {
87
- createClient();
88
- });
89
-
90
- onDestroy(() => {
91
- if (client) {
92
- client.destroy();
93
- client = null;
94
- }
95
- });
96
-
97
- // Recreate client when id changes
98
- $effect(() => {
99
- if (id && typeof window !== 'undefined') {
100
- createClient();
101
- }
102
- });
103
-
104
- // Runtime updates
105
- $effect(() => {
106
- client?.setDarkMode(darkMode);
107
- });
108
-
109
- $effect(() => {
110
- client?.setAutoResizing(autoResizing);
111
- });
112
-
113
- $effect(() => {
114
- client?.setForkDisplayMode(forkDisplayMode);
115
- });
116
-
117
70
  $effect(() => {
118
- client?.setDialogBackdropClose(dialogBackdropClose);
71
+ syncProperties();
119
72
  });
120
73
  </script>
121
74
 
122
- <div id={containerId} {...restProps}></div>
75
+ <adapt-automation
76
+ bind:this={element}
77
+ automation-id={id}
78
+ session-token={sessionToken}
79
+ auth-token={authToken}
80
+ transmitter={transmitter}
81
+ challenge-token={challengeToken}
82
+ requires-challenge={requiresChallenge ? '' : undefined}
83
+ inherit-token={inheritToken}
84
+ fork-display-mode={forkDisplayMode}
85
+ side-by-side-split={sideBySideSplit !== undefined ? String(sideBySideSplit) : undefined}
86
+ dialog-backdrop-close={dialogBackdropClose ? '' : undefined}
87
+ dark-mode={darkMode ? '' : undefined}
88
+ auto-resizing={autoResizing ? '' : undefined}
89
+ {...restProps}
90
+ ></adapt-automation>
@@ -22,6 +22,7 @@ interface Props {
22
22
  darkMode?: boolean;
23
23
  autoResizing?: boolean;
24
24
  classNames?: AdaptWebClientOptions['classNames'];
25
+ styles?: Partial<CSSStyleDeclaration>;
25
26
  onsession?: (event: {
26
27
  status: StatusJson;
27
28
  fork?: string;
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { AutomationClient } from '@mochabug/adapt-core';
3
- import { AdaptCapWidget, type CapWidgetI18n } from '@mochabug/adapt-web';
4
- import { onDestroy, onMount } from 'svelte';
3
+ import { AdaptCapElement, type CapWidgetI18n } from '@mochabug/adapt-web';
4
+ // Ensure custom element is registered
5
+ void AdaptCapElement;
5
6
 
6
7
  // Props interface
7
8
  interface Props {
@@ -26,58 +27,29 @@
26
27
  ...restProps
27
28
  }: Props = $props();
28
29
 
29
- let container: HTMLElement;
30
- let widget: AdaptCapWidget | null = null;
31
-
32
- function createWidget() {
33
- if (!container || !client) return;
34
-
35
- if (widget) {
36
- widget.destroy();
37
- widget = null;
38
- }
39
-
40
- widget = new AdaptCapWidget({
41
- container,
42
- automationId,
43
- client,
44
- onSolve: (token, expires) => {
45
- onsolve?.({ token, expires });
46
- },
47
- onError: (error) => {
48
- onerror?.({ error });
49
- },
50
- ...(workerCount !== undefined && { workerCount }),
51
- ...(i18n !== undefined && { i18n }),
52
- });
53
-
54
- if (darkMode) {
55
- widget.setDarkMode(true);
56
- }
30
+ let element: AdaptCapElement;
31
+
32
+ function syncProperties() {
33
+ if (!element) return;
34
+ element.client = client;
35
+ element.i18n = i18n;
36
+ element.onSolveCallback = (token, expires) => {
37
+ onsolve?.({ token, expires });
38
+ };
39
+ element.onErrorCallback = (error) => {
40
+ onerror?.({ error });
41
+ };
57
42
  }
58
43
 
59
- onMount(() => {
60
- createWidget();
61
- });
62
-
63
- onDestroy(() => {
64
- if (widget) {
65
- widget.destroy();
66
- widget = null;
67
- }
68
- });
69
-
70
- // Recreate widget when automationId or client changes
71
- $effect(() => {
72
- if (automationId && client && typeof window !== 'undefined') {
73
- createWidget();
74
- }
75
- });
76
-
77
- // Update dark mode
78
44
  $effect(() => {
79
- widget?.setDarkMode(darkMode);
45
+ syncProperties();
80
46
  });
81
47
  </script>
82
48
 
83
- <div bind:this={container} {...restProps}></div>
49
+ <adapt-cap
50
+ bind:this={element}
51
+ automation-id={automationId}
52
+ dark-mode={darkMode ? '' : undefined}
53
+ worker-count={workerCount !== undefined ? String(workerCount) : undefined}
54
+ {...restProps}
55
+ ></adapt-cap>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adapt-svelte",
3
- "version": "1.0.0-rc15",
3
+ "version": "1.0.0-rc17",
4
4
  "description": "Svelte component for Adapt automation platform",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -33,10 +33,10 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sveltejs/package": "^2.5.7",
36
- "svelte": "^5.46.1",
36
+ "svelte": "^5.50.0",
37
37
  "typescript": "^5.9.3"
38
38
  },
39
39
  "dependencies": {
40
- "@mochabug/adapt-web": "^1.0.0-rc37"
40
+ "@mochabug/adapt-web": "^1.0.0-rc39"
41
41
  }
42
42
  }