@nexvio-ai/widget-js 0.1.0
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/CHANGELOG.md +83 -0
- package/README.md +365 -0
- package/dist/chunk-M2QGY5LN.js +1250 -0
- package/dist/chunk-M2QGY5LN.js.map +1 -0
- package/dist/index.cjs +1284 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +1550 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +29 -0
- package/dist/react.d.ts +29 -0
- package/dist/react.js +273 -0
- package/dist/react.js.map +1 -0
- package/dist/widget.js +1254 -0
- package/package.json +88 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
#### `<nexvio-chat-bot>` Element
|
|
8
|
+
|
|
9
|
+
A new custom element that provides a floating chat button with an animated widget container. This is the recommended way to embed the Nexvio chat widget.
|
|
10
|
+
|
|
11
|
+
**Features:**
|
|
12
|
+
- Floating chat button with smooth animations
|
|
13
|
+
- Automatic widget container management
|
|
14
|
+
- Customizable position (bottom-right, bottom-left, top-right, top-left)
|
|
15
|
+
- Notification badge support (number or dot)
|
|
16
|
+
- Custom button colors and icons
|
|
17
|
+
- Mobile-responsive (full-screen on mobile)
|
|
18
|
+
- Programmatic control API (`open()`, `close()`, `toggle()`)
|
|
19
|
+
- Event forwarding from the underlying widget
|
|
20
|
+
|
|
21
|
+
**Usage:**
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import '@nexvio-ai/widget-js';
|
|
25
|
+
|
|
26
|
+
const chatbot = document.createElement('nexvio-chat-bot');
|
|
27
|
+
chatbot.setOptions({
|
|
28
|
+
publicKey: 'pk_test-123',
|
|
29
|
+
position: 'bottom-right',
|
|
30
|
+
buttonColor: '#6366F1',
|
|
31
|
+
badge: 3,
|
|
32
|
+
});
|
|
33
|
+
document.body.append(chatbot);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**React:**
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { NexvioChatbot } from '@nexvio-ai/widget-js/react';
|
|
40
|
+
|
|
41
|
+
export function App() {
|
|
42
|
+
return (
|
|
43
|
+
<NexvioChatbot
|
|
44
|
+
options={{
|
|
45
|
+
publicKey: 'pk_test-123',
|
|
46
|
+
buttonColor: '#6366F1',
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### React Components
|
|
54
|
+
|
|
55
|
+
- `NexvioChatbot` - React component for the chatbot element
|
|
56
|
+
- `useNexvioChatbot` - React hook for managing chatbot state
|
|
57
|
+
|
|
58
|
+
#### Documentation
|
|
59
|
+
|
|
60
|
+
- Comprehensive README with usage examples
|
|
61
|
+
- HTML example file demonstrating chatbot usage
|
|
62
|
+
- Updated examples README with chatbot information
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- `<nexvio-chat-widget>` continues to work as before (backward compatible)
|
|
67
|
+
- Both elements are automatically registered when the package is imported
|
|
68
|
+
|
|
69
|
+
### Technical Details
|
|
70
|
+
|
|
71
|
+
**New Files:**
|
|
72
|
+
- `src/NexvioChatbotElement.ts` - Custom element implementation
|
|
73
|
+
- `src/react/NexvioChatbot.tsx` - React component
|
|
74
|
+
- `src/react/useNexvioChatbot.ts` - React hook
|
|
75
|
+
- `examples/html/chatbot.html` - HTML example
|
|
76
|
+
|
|
77
|
+
**Modified Files:**
|
|
78
|
+
- `src/index.ts` - Exports chatbot element and types
|
|
79
|
+
- `src/react/index.ts` - Exports React components
|
|
80
|
+
- `src/types/dom-augment.d.ts` - TypeScript definitions
|
|
81
|
+
- `README.md` - Comprehensive documentation
|
|
82
|
+
- `examples/html/README.md` - Updated with chatbot info
|
|
83
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# Nexvio Widget JS
|
|
2
|
+
|
|
3
|
+
Embeddable JavaScript SDK that renders the Nexvio chat experience inside any web
|
|
4
|
+
application. The package exposes two custom elements:
|
|
5
|
+
|
|
6
|
+
- `<nexvio-chat-widget>` - Direct widget embed (for custom integrations)
|
|
7
|
+
- `<nexvio-chat-bot>` - Floating chat button with animated widget (recommended)
|
|
8
|
+
|
|
9
|
+
Plus React bindings for developers who prefer declarative integrations.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @nexvio-ai/widget-js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The package ships ESM, CJS, and type declarations. React bindings are exposed
|
|
18
|
+
via the `@nexvio-ai/widget-js/react` subpath export.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Using `<nexvio-chat-bot>` (Recommended)
|
|
23
|
+
|
|
24
|
+
The easiest way to add a chat widget to your site is using `<nexvio-chat-bot>`, which
|
|
25
|
+
provides a floating chat button and automatically manages the widget container.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import '@nexvio-ai/widget-js';
|
|
29
|
+
|
|
30
|
+
const chatbot = document.createElement('nexvio-chat-bot');
|
|
31
|
+
chatbot.setOptions({ publicKey: 'pk_test-123' });
|
|
32
|
+
document.body.append(chatbot);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**React:**
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { NexvioChatbot } from '@nexvio-ai/widget-js/react';
|
|
39
|
+
|
|
40
|
+
export function App() {
|
|
41
|
+
return (
|
|
42
|
+
<NexvioChatbot
|
|
43
|
+
options={{
|
|
44
|
+
publicKey: 'pk_test-123',
|
|
45
|
+
onEvent: (event) => console.log(event.name, event.detail),
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Using `<nexvio-chat-widget>` (Advanced)
|
|
53
|
+
|
|
54
|
+
For custom integrations where you want full control over the widget container,
|
|
55
|
+
use `<nexvio-chat-widget>` directly.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import '@nexvio-ai/widget-js';
|
|
59
|
+
|
|
60
|
+
const widget = document.createElement('nexvio-chat-widget');
|
|
61
|
+
widget.setOptions({ publicKey: 'pk_test-123' });
|
|
62
|
+
document.body.append(widget);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**React:**
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { NexvioWidget } from '@nexvio-ai/widget-js/react';
|
|
69
|
+
|
|
70
|
+
export function SupportWidget() {
|
|
71
|
+
return (
|
|
72
|
+
<NexvioWidget
|
|
73
|
+
options={{
|
|
74
|
+
publicKey: 'pk_test-123',
|
|
75
|
+
onEvent: (event) => console.log(event.name, event.detail),
|
|
76
|
+
}}
|
|
77
|
+
className="h-full w-full"
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## `<nexvio-chat-bot>` Options
|
|
84
|
+
|
|
85
|
+
The chatbot element extends all widget options and adds the following:
|
|
86
|
+
|
|
87
|
+
### Chatbot-Specific Options
|
|
88
|
+
|
|
89
|
+
- `position` (`'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'`) - Position of the chat button. Default: `'bottom-right'`
|
|
90
|
+
- `defaultOpen` (`boolean`) - Whether the widget should be open initially. Default: `false`
|
|
91
|
+
- `buttonColor` (`string`) - Background color of the chat button. Default: `'#3B82F6'`
|
|
92
|
+
- `badge` (`number | boolean`) - Show a notification badge. Pass a number for unread count, or `true` for a dot. Default: `false`
|
|
93
|
+
- `buttonIcon` (`string`) - Custom SVG icon for the button (replaces default chat icon)
|
|
94
|
+
- `gap` (`number`) - Gap from screen edge in pixels. Default: `20`
|
|
95
|
+
|
|
96
|
+
### Widget Options (Inherited)
|
|
97
|
+
|
|
98
|
+
All options from `<nexvio-chat-widget>` are supported:
|
|
99
|
+
|
|
100
|
+
- `publicKey` (required) – widget identifier used by the Nexvio platform
|
|
101
|
+
- `appearance` – overrides for colours, fonts, or density. Values are passed to the hosted widget frame
|
|
102
|
+
- `metadata` / `context` – arbitrary JSON forwarded downstream
|
|
103
|
+
- `clientActions` – map of callbacks that can be invoked by the iframe for client-side behaviour (e.g. analytics, navigation)
|
|
104
|
+
- `onEvent` – receives all events emitted by the widget (ready, error, custom events defined in the workspace)
|
|
105
|
+
- `fetch` – custom `fetch` implementation used when the frame requests server-side actions through the host
|
|
106
|
+
- `client.tools` – client-side tools that can be called by the AI
|
|
107
|
+
- `startScreen` – configuration for the initial greeting screen
|
|
108
|
+
|
|
109
|
+
### Example: Full Configuration
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const chatbot = document.createElement('nexvio-chat-bot');
|
|
113
|
+
chatbot.setOptions({
|
|
114
|
+
publicKey: 'pk_test-123',
|
|
115
|
+
position: 'bottom-right',
|
|
116
|
+
buttonColor: '#6366F1',
|
|
117
|
+
badge: 3, // Show unread count
|
|
118
|
+
defaultOpen: false,
|
|
119
|
+
gap: 24,
|
|
120
|
+
appearance: {
|
|
121
|
+
colorScheme: 'light',
|
|
122
|
+
},
|
|
123
|
+
context: {
|
|
124
|
+
visitor: {
|
|
125
|
+
name: 'John Doe',
|
|
126
|
+
email: 'john@example.com',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
onEvent: (event) => {
|
|
130
|
+
console.log('Widget event:', event.name, event.detail);
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
document.body.append(chatbot);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Programmatic Control
|
|
137
|
+
|
|
138
|
+
### Methods
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const chatbot = document.querySelector('nexvio-chat-bot');
|
|
142
|
+
|
|
143
|
+
// Open the widget
|
|
144
|
+
chatbot.open();
|
|
145
|
+
|
|
146
|
+
// Close the widget
|
|
147
|
+
chatbot.close();
|
|
148
|
+
|
|
149
|
+
// Toggle open/closed state
|
|
150
|
+
chatbot.toggle();
|
|
151
|
+
|
|
152
|
+
// Check if open
|
|
153
|
+
console.log(chatbot.isOpen); // boolean
|
|
154
|
+
|
|
155
|
+
// Access the underlying widget element
|
|
156
|
+
const widget = chatbot.widget;
|
|
157
|
+
widget?.focusInput();
|
|
158
|
+
widget?.setVisitor({ name: 'Jane Doe' });
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Events
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const chatbot = document.querySelector('nexvio-chat-bot');
|
|
165
|
+
|
|
166
|
+
// Listen to chatbot-specific events
|
|
167
|
+
chatbot.addEventListener('chatbot.opened', () => {
|
|
168
|
+
console.log('Chat opened');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
chatbot.addEventListener('chatbot.closed', () => {
|
|
172
|
+
console.log('Chat closed');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Listen to widget events (forwarded from the widget)
|
|
176
|
+
chatbot.addEventListener('nexvio.event', (event) => {
|
|
177
|
+
console.log('Widget event:', event.detail);
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## React Usage
|
|
182
|
+
|
|
183
|
+
### Basic Example
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
import { NexvioChatbot } from '@nexvio-ai/widget-js/react';
|
|
187
|
+
import { useRef } from 'react';
|
|
188
|
+
|
|
189
|
+
export function App() {
|
|
190
|
+
const chatbotRef = useRef<NexvioChatbotElement>(null);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<>
|
|
194
|
+
<button onClick={() => chatbotRef.current?.open()}>
|
|
195
|
+
Open Chat
|
|
196
|
+
</button>
|
|
197
|
+
|
|
198
|
+
<NexvioChatbot
|
|
199
|
+
ref={chatbotRef}
|
|
200
|
+
options={{
|
|
201
|
+
publicKey: 'pk_test-123',
|
|
202
|
+
buttonColor: '#6366F1',
|
|
203
|
+
badge: 3,
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
</>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### With Event Handling
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { NexvioChatbot } from '@nexvio-ai/widget-js/react';
|
|
215
|
+
import type { NexvioWidgetEvent } from '@nexvio-ai/widget-js';
|
|
216
|
+
|
|
217
|
+
export function App() {
|
|
218
|
+
const handleEvent = (event: NexvioWidgetEvent) => {
|
|
219
|
+
console.log('Event:', event.name, event.detail);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<NexvioChatbot
|
|
224
|
+
options={{
|
|
225
|
+
publicKey: 'pk_test-123',
|
|
226
|
+
onEvent: handleEvent,
|
|
227
|
+
appearance: {
|
|
228
|
+
colorScheme: 'dark',
|
|
229
|
+
},
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Using the Hook
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
import { useNexvioChatbot } from '@nexvio-ai/widget-js/react';
|
|
240
|
+
import { useEffect } from 'react';
|
|
241
|
+
|
|
242
|
+
export function App() {
|
|
243
|
+
const { ref, setElement } = useNexvioChatbot({
|
|
244
|
+
publicKey: 'pk_test-123',
|
|
245
|
+
buttonColor: '#6366F1',
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
// Access the element via ref.current
|
|
250
|
+
const chatbot = ref.current;
|
|
251
|
+
if (chatbot) {
|
|
252
|
+
chatbot.open();
|
|
253
|
+
}
|
|
254
|
+
}, []);
|
|
255
|
+
|
|
256
|
+
return <nexvio-chat-bot ref={setElement} />;
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## `<nexvio-chat-widget>` Options
|
|
261
|
+
|
|
262
|
+
For direct widget usage, see the widget-specific options:
|
|
263
|
+
|
|
264
|
+
- `publicKey` (required) – widget identifier used by the Nexvio platform
|
|
265
|
+
- `appearance` – overrides for colours, fonts, or density. Values are passed to the hosted widget frame
|
|
266
|
+
- `metadata` / `context` – arbitrary JSON forwarded downstream
|
|
267
|
+
- `clientActions` – map of callbacks that can be invoked by the iframe for client-side behaviour (e.g. analytics, navigation)
|
|
268
|
+
- `onEvent` – receives all events emitted by the widget (ready, error, custom events defined in the workspace)
|
|
269
|
+
- `fetch` – custom `fetch` implementation used when the frame requests server-side actions through the host
|
|
270
|
+
- `messageActions` – per-message UI action toggles (copy, feedback, retry)
|
|
271
|
+
- `client.tools` – client-side tools that can be called by the AI
|
|
272
|
+
- `startScreen` – configuration for the initial greeting screen
|
|
273
|
+
|
|
274
|
+
## Styling
|
|
275
|
+
|
|
276
|
+
### CSS Custom Properties
|
|
277
|
+
|
|
278
|
+
The chatbot element exposes CSS custom properties for styling:
|
|
279
|
+
|
|
280
|
+
```css
|
|
281
|
+
nexvio-chat-bot {
|
|
282
|
+
--chatbot-button-size: 60px;
|
|
283
|
+
--chatbot-button-bg: #3B82F6;
|
|
284
|
+
--chatbot-button-color: white;
|
|
285
|
+
--chatbot-widget-width: 420px;
|
|
286
|
+
--chatbot-widget-height: 600px;
|
|
287
|
+
--chatbot-widget-gap: 20px;
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Responsive Behavior
|
|
292
|
+
|
|
293
|
+
On mobile devices (screen width ≤ 768px), the widget automatically switches to full-screen mode for better usability.
|
|
294
|
+
|
|
295
|
+
## Development
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
pnpm install
|
|
299
|
+
pnpm --filter @nexvio-ai/widget-js test
|
|
300
|
+
pnpm --filter @nexvio-ai/widget-js build
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The build pipeline uses `tsup` to emit bundled ESM/CJS outputs with type
|
|
304
|
+
declarations. Vitest covers the base utilities used to exchange data with the
|
|
305
|
+
hosted iframe.
|
|
306
|
+
|
|
307
|
+
## Demo Integration
|
|
308
|
+
|
|
309
|
+
The monorepo includes a live integration at
|
|
310
|
+
`apps/demo-app/src/app/widget/page.tsx`. Launch it with:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
pnpm --filter demo-app dev
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The demo renders `<NexvioWidget />`, lets you swap the widget public key, and
|
|
317
|
+
mirrors all bridge events in a side panel so you can validate host/widget
|
|
318
|
+
communication in real time.
|
|
319
|
+
|
|
320
|
+
## Migration Guide
|
|
321
|
+
|
|
322
|
+
### From `<nexvio-chat-widget>` to `<nexvio-chat-bot>`
|
|
323
|
+
|
|
324
|
+
If you're currently using `<nexvio-chat-widget>` and want to switch to the chatbot:
|
|
325
|
+
|
|
326
|
+
**Before:**
|
|
327
|
+
```ts
|
|
328
|
+
const widget = document.createElement('nexvio-chat-widget');
|
|
329
|
+
widget.setOptions({ publicKey: 'pk_test-123' });
|
|
330
|
+
document.body.append(widget);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**After:**
|
|
334
|
+
```ts
|
|
335
|
+
const chatbot = document.createElement('nexvio-chat-bot');
|
|
336
|
+
chatbot.setOptions({ publicKey: 'pk_test-123' });
|
|
337
|
+
document.body.append(chatbot);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
All widget options work the same way. The chatbot automatically creates and manages the widget internally.
|
|
341
|
+
|
|
342
|
+
## TypeScript Support
|
|
343
|
+
|
|
344
|
+
Full TypeScript support is included:
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import type {
|
|
348
|
+
NexvioWidgetOptions,
|
|
349
|
+
NexvioWidgetEvent,
|
|
350
|
+
NexvioChatbotOptions,
|
|
351
|
+
} from '@nexvio-ai/widget-js';
|
|
352
|
+
import type { NexvioChatbotElement } from '@nexvio-ai/widget-js';
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Browser Support
|
|
356
|
+
|
|
357
|
+
- Chrome/Edge (latest)
|
|
358
|
+
- Firefox (latest)
|
|
359
|
+
- Safari (latest)
|
|
360
|
+
- Mobile browsers (iOS Safari, Chrome Mobile)
|
|
361
|
+
|
|
362
|
+
Requires support for:
|
|
363
|
+
- Custom Elements (Web Components)
|
|
364
|
+
- Shadow DOM
|
|
365
|
+
- ES2017+ features
|