@mobil80-dev/chatbot-widget 2.0.4 → 2.0.6
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/index.js +62 -20
- package/dist/index.umd.js +62 -20
- package/index.js +62 -20
- package/package.json +1 -1
- package/rollup.config.js +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ let isOpen = false;
|
|
|
10
10
|
/* =========================================================
|
|
11
11
|
STYLE INJECTION (ONCE)
|
|
12
12
|
========================================================= */
|
|
13
|
-
function injectStylesOnce() {
|
|
13
|
+
function injectStylesOnce () {
|
|
14
14
|
if (stylesInjected) return
|
|
15
15
|
stylesInjected = true;
|
|
16
16
|
|
|
@@ -51,7 +51,7 @@ function injectStylesOnce() {
|
|
|
51
51
|
/* =========================================================
|
|
52
52
|
HELPER TO RESOLVE CONTAINER
|
|
53
53
|
========================================================= */
|
|
54
|
-
function getAttachContainer(selector) {
|
|
54
|
+
function getAttachContainer (selector) {
|
|
55
55
|
if (!selector) return document.body
|
|
56
56
|
if (typeof selector === 'string') {
|
|
57
57
|
const el = document.querySelector(selector);
|
|
@@ -63,18 +63,23 @@ function getAttachContainer(selector) {
|
|
|
63
63
|
/* =========================================================
|
|
64
64
|
BUTTON
|
|
65
65
|
========================================================= */
|
|
66
|
-
function getButton() {
|
|
66
|
+
function getButton () {
|
|
67
67
|
if (vcButton) return vcButton
|
|
68
68
|
vcButton = document.createElement('div');
|
|
69
69
|
vcButton.className = 'vc-fab';
|
|
70
70
|
return vcButton
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function updateButton(config) {
|
|
73
|
+
function updateButton (config) {
|
|
74
74
|
const button = getButton();
|
|
75
75
|
button.innerHTML = '';
|
|
76
76
|
|
|
77
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
buttonType = 'text',
|
|
79
|
+
buttonContent = '🤖',
|
|
80
|
+
buttonShape = 'circle',
|
|
81
|
+
primaryColor = '#2563eb'
|
|
82
|
+
} = config;
|
|
78
83
|
const isText = buttonType === 'text';
|
|
79
84
|
|
|
80
85
|
if (buttonType === 'image') {
|
|
@@ -88,7 +93,8 @@ function updateButton(config) {
|
|
|
88
93
|
button.textContent = buttonContent;
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
const borderRadius =
|
|
96
|
+
const borderRadius =
|
|
97
|
+
buttonShape === 'pill' ? '999px' : buttonShape === 'square' ? '8px' : '50%';
|
|
92
98
|
|
|
93
99
|
Object.assign(button.style, {
|
|
94
100
|
position: 'fixed',
|
|
@@ -116,22 +122,48 @@ function updateButton(config) {
|
|
|
116
122
|
/* =========================================================
|
|
117
123
|
CARD
|
|
118
124
|
========================================================= */
|
|
119
|
-
function getCard() {
|
|
125
|
+
function getCard () {
|
|
120
126
|
if (vcCard) return vcCard
|
|
121
127
|
vcCard = document.createElement('div');
|
|
122
128
|
return vcCard
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
function updateCard(config) {
|
|
131
|
+
function updateCard (config) {
|
|
126
132
|
const card = getCard();
|
|
127
133
|
|
|
128
|
-
const theme =
|
|
129
|
-
|
|
134
|
+
const theme =
|
|
135
|
+
config.theme === 'dark'
|
|
136
|
+
? 'dark'
|
|
137
|
+
: config.theme === 'light'
|
|
138
|
+
? 'light'
|
|
139
|
+
: window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
140
|
+
? 'dark'
|
|
141
|
+
: 'light';
|
|
130
142
|
const isDark = theme === 'dark';
|
|
131
143
|
|
|
132
144
|
const colors = isDark
|
|
133
|
-
? {
|
|
134
|
-
|
|
145
|
+
? {
|
|
146
|
+
cardBg: '#0f172a',
|
|
147
|
+
headerBorder: '#1e293b',
|
|
148
|
+
text: '#e5e7eb',
|
|
149
|
+
mutedText: '#94a3b8',
|
|
150
|
+
inputBg: '#020617',
|
|
151
|
+
inputBorder: '#334155',
|
|
152
|
+
botBubble: '#1e293b',
|
|
153
|
+
userText: '#ffffff',
|
|
154
|
+
messagesBg: '#020617'
|
|
155
|
+
}
|
|
156
|
+
: {
|
|
157
|
+
cardBg: '#ffffff',
|
|
158
|
+
headerBorder: '#e5e7eb',
|
|
159
|
+
text: '#0f172a',
|
|
160
|
+
mutedText: '#64748b',
|
|
161
|
+
inputBg: '#ffffff',
|
|
162
|
+
inputBorder: '#cbd5f5',
|
|
163
|
+
botBubble: '#e5e7eb',
|
|
164
|
+
userText: '#ffffff',
|
|
165
|
+
messagesBg: '#f8fafc'
|
|
166
|
+
};
|
|
135
167
|
|
|
136
168
|
const primaryColor = config.primaryColor || '#2563eb';
|
|
137
169
|
|
|
@@ -162,8 +194,10 @@ function updateCard(config) {
|
|
|
162
194
|
position: 'fixed',
|
|
163
195
|
bottom: '90px',
|
|
164
196
|
right: '20px',
|
|
197
|
+
maxWidth: '90vw',
|
|
165
198
|
width: '400px',
|
|
166
199
|
height: '420px',
|
|
200
|
+
maxHeight: '80vh',
|
|
167
201
|
background: colors.cardBg,
|
|
168
202
|
borderRadius: '12px',
|
|
169
203
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
@@ -171,6 +205,10 @@ function updateCard(config) {
|
|
|
171
205
|
display: isOpen ? 'flex' : 'none',
|
|
172
206
|
flexDirection: 'column'
|
|
173
207
|
});
|
|
208
|
+
if (window.innerWidth < 450) {
|
|
209
|
+
card.style.bottom = '10px';
|
|
210
|
+
card.style.right = '5px';
|
|
211
|
+
}
|
|
174
212
|
|
|
175
213
|
card.style.setProperty('--vc-text-muted', colors.mutedText);
|
|
176
214
|
card.style.setProperty('--vc-bot-bg', colors.botBubble);
|
|
@@ -180,7 +218,7 @@ function updateCard(config) {
|
|
|
180
218
|
const sendBtn = card.querySelector('#vc-send');
|
|
181
219
|
|
|
182
220
|
// send message
|
|
183
|
-
async function sendMessage() {
|
|
221
|
+
async function sendMessage () {
|
|
184
222
|
const text = input.value.trim();
|
|
185
223
|
if (!text) return
|
|
186
224
|
|
|
@@ -213,14 +251,16 @@ function updateCard(config) {
|
|
|
213
251
|
});
|
|
214
252
|
const data = await res.json();
|
|
215
253
|
hideLoader(sendBtn);
|
|
216
|
-
addBotMessage(
|
|
254
|
+
addBotMessage(
|
|
255
|
+
data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
|
|
256
|
+
);
|
|
217
257
|
} catch {
|
|
218
258
|
hideLoader(sendBtn);
|
|
219
259
|
addBotMessage('⚠️ Something went wrong');
|
|
220
260
|
}
|
|
221
261
|
}
|
|
222
262
|
|
|
223
|
-
function addBotMessage(text) {
|
|
263
|
+
function addBotMessage (text) {
|
|
224
264
|
const div = document.createElement('div');
|
|
225
265
|
div.style.cssText = `
|
|
226
266
|
background:${colors.botBubble};
|
|
@@ -236,7 +276,9 @@ function updateCard(config) {
|
|
|
236
276
|
|
|
237
277
|
// events
|
|
238
278
|
sendBtn.onclick = sendMessage;
|
|
239
|
-
input.addEventListener('keydown', e => {
|
|
279
|
+
input.addEventListener('keydown', e => {
|
|
280
|
+
if (e.key === 'Enter') sendMessage();
|
|
281
|
+
});
|
|
240
282
|
|
|
241
283
|
return { messages, input, sendBtn }
|
|
242
284
|
}
|
|
@@ -244,7 +286,7 @@ function updateCard(config) {
|
|
|
244
286
|
/* =========================================================
|
|
245
287
|
LOADER
|
|
246
288
|
========================================================= */
|
|
247
|
-
function showLoader(container, sendBtn) {
|
|
289
|
+
function showLoader (container, sendBtn) {
|
|
248
290
|
loaderEl = document.createElement('div');
|
|
249
291
|
loaderEl.className = 'vc-loader';
|
|
250
292
|
loaderEl.innerHTML = '<span></span><span></span><span></span>';
|
|
@@ -257,7 +299,7 @@ function showLoader(container, sendBtn) {
|
|
|
257
299
|
}
|
|
258
300
|
}
|
|
259
301
|
|
|
260
|
-
function hideLoader(sendBtn) {
|
|
302
|
+
function hideLoader (sendBtn) {
|
|
261
303
|
loaderEl?.remove();
|
|
262
304
|
loaderEl = null;
|
|
263
305
|
|
|
@@ -272,7 +314,7 @@ function hideLoader(sendBtn) {
|
|
|
272
314
|
PUBLIC API
|
|
273
315
|
========================================================= */
|
|
274
316
|
const VaultChat = {
|
|
275
|
-
init(config = {}) {
|
|
317
|
+
init (config = {}) {
|
|
276
318
|
injectStylesOnce();
|
|
277
319
|
updateButton(config);
|
|
278
320
|
|
|
@@ -288,7 +330,7 @@ const VaultChat = {
|
|
|
288
330
|
};
|
|
289
331
|
},
|
|
290
332
|
|
|
291
|
-
destroy() {
|
|
333
|
+
destroy () {
|
|
292
334
|
vcButton?.remove();
|
|
293
335
|
vcCard?.remove();
|
|
294
336
|
vcButton = null;
|
package/dist/index.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/* =========================================================
|
|
17
17
|
STYLE INJECTION (ONCE)
|
|
18
18
|
========================================================= */
|
|
19
|
-
function injectStylesOnce() {
|
|
19
|
+
function injectStylesOnce () {
|
|
20
20
|
if (stylesInjected) return
|
|
21
21
|
stylesInjected = true;
|
|
22
22
|
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
/* =========================================================
|
|
58
58
|
HELPER TO RESOLVE CONTAINER
|
|
59
59
|
========================================================= */
|
|
60
|
-
function getAttachContainer(selector) {
|
|
60
|
+
function getAttachContainer (selector) {
|
|
61
61
|
if (!selector) return document.body
|
|
62
62
|
if (typeof selector === 'string') {
|
|
63
63
|
const el = document.querySelector(selector);
|
|
@@ -69,18 +69,23 @@
|
|
|
69
69
|
/* =========================================================
|
|
70
70
|
BUTTON
|
|
71
71
|
========================================================= */
|
|
72
|
-
function getButton() {
|
|
72
|
+
function getButton () {
|
|
73
73
|
if (vcButton) return vcButton
|
|
74
74
|
vcButton = document.createElement('div');
|
|
75
75
|
vcButton.className = 'vc-fab';
|
|
76
76
|
return vcButton
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function updateButton(config) {
|
|
79
|
+
function updateButton (config) {
|
|
80
80
|
const button = getButton();
|
|
81
81
|
button.innerHTML = '';
|
|
82
82
|
|
|
83
|
-
const {
|
|
83
|
+
const {
|
|
84
|
+
buttonType = 'text',
|
|
85
|
+
buttonContent = '🤖',
|
|
86
|
+
buttonShape = 'circle',
|
|
87
|
+
primaryColor = '#2563eb'
|
|
88
|
+
} = config;
|
|
84
89
|
const isText = buttonType === 'text';
|
|
85
90
|
|
|
86
91
|
if (buttonType === 'image') {
|
|
@@ -94,7 +99,8 @@
|
|
|
94
99
|
button.textContent = buttonContent;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
const borderRadius =
|
|
102
|
+
const borderRadius =
|
|
103
|
+
buttonShape === 'pill' ? '999px' : buttonShape === 'square' ? '8px' : '50%';
|
|
98
104
|
|
|
99
105
|
Object.assign(button.style, {
|
|
100
106
|
position: 'fixed',
|
|
@@ -122,22 +128,48 @@
|
|
|
122
128
|
/* =========================================================
|
|
123
129
|
CARD
|
|
124
130
|
========================================================= */
|
|
125
|
-
function getCard() {
|
|
131
|
+
function getCard () {
|
|
126
132
|
if (vcCard) return vcCard
|
|
127
133
|
vcCard = document.createElement('div');
|
|
128
134
|
return vcCard
|
|
129
135
|
}
|
|
130
136
|
|
|
131
|
-
function updateCard(config) {
|
|
137
|
+
function updateCard (config) {
|
|
132
138
|
const card = getCard();
|
|
133
139
|
|
|
134
|
-
const theme =
|
|
135
|
-
|
|
140
|
+
const theme =
|
|
141
|
+
config.theme === 'dark'
|
|
142
|
+
? 'dark'
|
|
143
|
+
: config.theme === 'light'
|
|
144
|
+
? 'light'
|
|
145
|
+
: window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
146
|
+
? 'dark'
|
|
147
|
+
: 'light';
|
|
136
148
|
const isDark = theme === 'dark';
|
|
137
149
|
|
|
138
150
|
const colors = isDark
|
|
139
|
-
? {
|
|
140
|
-
|
|
151
|
+
? {
|
|
152
|
+
cardBg: '#0f172a',
|
|
153
|
+
headerBorder: '#1e293b',
|
|
154
|
+
text: '#e5e7eb',
|
|
155
|
+
mutedText: '#94a3b8',
|
|
156
|
+
inputBg: '#020617',
|
|
157
|
+
inputBorder: '#334155',
|
|
158
|
+
botBubble: '#1e293b',
|
|
159
|
+
userText: '#ffffff',
|
|
160
|
+
messagesBg: '#020617'
|
|
161
|
+
}
|
|
162
|
+
: {
|
|
163
|
+
cardBg: '#ffffff',
|
|
164
|
+
headerBorder: '#e5e7eb',
|
|
165
|
+
text: '#0f172a',
|
|
166
|
+
mutedText: '#64748b',
|
|
167
|
+
inputBg: '#ffffff',
|
|
168
|
+
inputBorder: '#cbd5f5',
|
|
169
|
+
botBubble: '#e5e7eb',
|
|
170
|
+
userText: '#ffffff',
|
|
171
|
+
messagesBg: '#f8fafc'
|
|
172
|
+
};
|
|
141
173
|
|
|
142
174
|
const primaryColor = config.primaryColor || '#2563eb';
|
|
143
175
|
|
|
@@ -168,8 +200,10 @@
|
|
|
168
200
|
position: 'fixed',
|
|
169
201
|
bottom: '90px',
|
|
170
202
|
right: '20px',
|
|
203
|
+
maxWidth: '90vw',
|
|
171
204
|
width: '400px',
|
|
172
205
|
height: '420px',
|
|
206
|
+
maxHeight: '80vh',
|
|
173
207
|
background: colors.cardBg,
|
|
174
208
|
borderRadius: '12px',
|
|
175
209
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
@@ -177,6 +211,10 @@
|
|
|
177
211
|
display: isOpen ? 'flex' : 'none',
|
|
178
212
|
flexDirection: 'column'
|
|
179
213
|
});
|
|
214
|
+
if (window.innerWidth < 450) {
|
|
215
|
+
card.style.bottom = '10px';
|
|
216
|
+
card.style.right = '5px';
|
|
217
|
+
}
|
|
180
218
|
|
|
181
219
|
card.style.setProperty('--vc-text-muted', colors.mutedText);
|
|
182
220
|
card.style.setProperty('--vc-bot-bg', colors.botBubble);
|
|
@@ -186,7 +224,7 @@
|
|
|
186
224
|
const sendBtn = card.querySelector('#vc-send');
|
|
187
225
|
|
|
188
226
|
// send message
|
|
189
|
-
async function sendMessage() {
|
|
227
|
+
async function sendMessage () {
|
|
190
228
|
const text = input.value.trim();
|
|
191
229
|
if (!text) return
|
|
192
230
|
|
|
@@ -219,14 +257,16 @@
|
|
|
219
257
|
});
|
|
220
258
|
const data = await res.json();
|
|
221
259
|
hideLoader(sendBtn);
|
|
222
|
-
addBotMessage(
|
|
260
|
+
addBotMessage(
|
|
261
|
+
data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
|
|
262
|
+
);
|
|
223
263
|
} catch {
|
|
224
264
|
hideLoader(sendBtn);
|
|
225
265
|
addBotMessage('⚠️ Something went wrong');
|
|
226
266
|
}
|
|
227
267
|
}
|
|
228
268
|
|
|
229
|
-
function addBotMessage(text) {
|
|
269
|
+
function addBotMessage (text) {
|
|
230
270
|
const div = document.createElement('div');
|
|
231
271
|
div.style.cssText = `
|
|
232
272
|
background:${colors.botBubble};
|
|
@@ -242,7 +282,9 @@
|
|
|
242
282
|
|
|
243
283
|
// events
|
|
244
284
|
sendBtn.onclick = sendMessage;
|
|
245
|
-
input.addEventListener('keydown', e => {
|
|
285
|
+
input.addEventListener('keydown', e => {
|
|
286
|
+
if (e.key === 'Enter') sendMessage();
|
|
287
|
+
});
|
|
246
288
|
|
|
247
289
|
return { messages, input, sendBtn }
|
|
248
290
|
}
|
|
@@ -250,7 +292,7 @@
|
|
|
250
292
|
/* =========================================================
|
|
251
293
|
LOADER
|
|
252
294
|
========================================================= */
|
|
253
|
-
function showLoader(container, sendBtn) {
|
|
295
|
+
function showLoader (container, sendBtn) {
|
|
254
296
|
loaderEl = document.createElement('div');
|
|
255
297
|
loaderEl.className = 'vc-loader';
|
|
256
298
|
loaderEl.innerHTML = '<span></span><span></span><span></span>';
|
|
@@ -263,7 +305,7 @@
|
|
|
263
305
|
}
|
|
264
306
|
}
|
|
265
307
|
|
|
266
|
-
function hideLoader(sendBtn) {
|
|
308
|
+
function hideLoader (sendBtn) {
|
|
267
309
|
loaderEl?.remove();
|
|
268
310
|
loaderEl = null;
|
|
269
311
|
|
|
@@ -278,7 +320,7 @@
|
|
|
278
320
|
PUBLIC API
|
|
279
321
|
========================================================= */
|
|
280
322
|
const VaultChat = {
|
|
281
|
-
init(config = {}) {
|
|
323
|
+
init (config = {}) {
|
|
282
324
|
injectStylesOnce();
|
|
283
325
|
updateButton(config);
|
|
284
326
|
|
|
@@ -294,7 +336,7 @@
|
|
|
294
336
|
};
|
|
295
337
|
},
|
|
296
338
|
|
|
297
|
-
destroy() {
|
|
339
|
+
destroy () {
|
|
298
340
|
vcButton?.remove();
|
|
299
341
|
vcCard?.remove();
|
|
300
342
|
vcButton = null;
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ let isOpen = false
|
|
|
10
10
|
/* =========================================================
|
|
11
11
|
STYLE INJECTION (ONCE)
|
|
12
12
|
========================================================= */
|
|
13
|
-
function injectStylesOnce() {
|
|
13
|
+
function injectStylesOnce () {
|
|
14
14
|
if (stylesInjected) return
|
|
15
15
|
stylesInjected = true
|
|
16
16
|
|
|
@@ -51,7 +51,7 @@ function injectStylesOnce() {
|
|
|
51
51
|
/* =========================================================
|
|
52
52
|
HELPER TO RESOLVE CONTAINER
|
|
53
53
|
========================================================= */
|
|
54
|
-
function getAttachContainer(selector) {
|
|
54
|
+
function getAttachContainer (selector) {
|
|
55
55
|
if (!selector) return document.body
|
|
56
56
|
if (typeof selector === 'string') {
|
|
57
57
|
const el = document.querySelector(selector)
|
|
@@ -63,18 +63,23 @@ function getAttachContainer(selector) {
|
|
|
63
63
|
/* =========================================================
|
|
64
64
|
BUTTON
|
|
65
65
|
========================================================= */
|
|
66
|
-
function getButton() {
|
|
66
|
+
function getButton () {
|
|
67
67
|
if (vcButton) return vcButton
|
|
68
68
|
vcButton = document.createElement('div')
|
|
69
69
|
vcButton.className = 'vc-fab'
|
|
70
70
|
return vcButton
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function updateButton(config) {
|
|
73
|
+
function updateButton (config) {
|
|
74
74
|
const button = getButton()
|
|
75
75
|
button.innerHTML = ''
|
|
76
76
|
|
|
77
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
buttonType = 'text',
|
|
79
|
+
buttonContent = '🤖',
|
|
80
|
+
buttonShape = 'circle',
|
|
81
|
+
primaryColor = '#2563eb'
|
|
82
|
+
} = config
|
|
78
83
|
const isText = buttonType === 'text'
|
|
79
84
|
|
|
80
85
|
if (buttonType === 'image') {
|
|
@@ -88,7 +93,8 @@ function updateButton(config) {
|
|
|
88
93
|
button.textContent = buttonContent
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
const borderRadius =
|
|
96
|
+
const borderRadius =
|
|
97
|
+
buttonShape === 'pill' ? '999px' : buttonShape === 'square' ? '8px' : '50%'
|
|
92
98
|
|
|
93
99
|
Object.assign(button.style, {
|
|
94
100
|
position: 'fixed',
|
|
@@ -116,22 +122,48 @@ function updateButton(config) {
|
|
|
116
122
|
/* =========================================================
|
|
117
123
|
CARD
|
|
118
124
|
========================================================= */
|
|
119
|
-
function getCard() {
|
|
125
|
+
function getCard () {
|
|
120
126
|
if (vcCard) return vcCard
|
|
121
127
|
vcCard = document.createElement('div')
|
|
122
128
|
return vcCard
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
function updateCard(config) {
|
|
131
|
+
function updateCard (config) {
|
|
126
132
|
const card = getCard()
|
|
127
133
|
|
|
128
|
-
const theme =
|
|
129
|
-
|
|
134
|
+
const theme =
|
|
135
|
+
config.theme === 'dark'
|
|
136
|
+
? 'dark'
|
|
137
|
+
: config.theme === 'light'
|
|
138
|
+
? 'light'
|
|
139
|
+
: window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
140
|
+
? 'dark'
|
|
141
|
+
: 'light'
|
|
130
142
|
const isDark = theme === 'dark'
|
|
131
143
|
|
|
132
144
|
const colors = isDark
|
|
133
|
-
? {
|
|
134
|
-
|
|
145
|
+
? {
|
|
146
|
+
cardBg: '#0f172a',
|
|
147
|
+
headerBorder: '#1e293b',
|
|
148
|
+
text: '#e5e7eb',
|
|
149
|
+
mutedText: '#94a3b8',
|
|
150
|
+
inputBg: '#020617',
|
|
151
|
+
inputBorder: '#334155',
|
|
152
|
+
botBubble: '#1e293b',
|
|
153
|
+
userText: '#ffffff',
|
|
154
|
+
messagesBg: '#020617'
|
|
155
|
+
}
|
|
156
|
+
: {
|
|
157
|
+
cardBg: '#ffffff',
|
|
158
|
+
headerBorder: '#e5e7eb',
|
|
159
|
+
text: '#0f172a',
|
|
160
|
+
mutedText: '#64748b',
|
|
161
|
+
inputBg: '#ffffff',
|
|
162
|
+
inputBorder: '#cbd5f5',
|
|
163
|
+
botBubble: '#e5e7eb',
|
|
164
|
+
userText: '#ffffff',
|
|
165
|
+
messagesBg: '#f8fafc'
|
|
166
|
+
}
|
|
135
167
|
|
|
136
168
|
const primaryColor = config.primaryColor || '#2563eb'
|
|
137
169
|
|
|
@@ -162,8 +194,10 @@ function updateCard(config) {
|
|
|
162
194
|
position: 'fixed',
|
|
163
195
|
bottom: '90px',
|
|
164
196
|
right: '20px',
|
|
197
|
+
maxWidth: '90vw',
|
|
165
198
|
width: '400px',
|
|
166
199
|
height: '420px',
|
|
200
|
+
maxHeight: '80vh',
|
|
167
201
|
background: colors.cardBg,
|
|
168
202
|
borderRadius: '12px',
|
|
169
203
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
@@ -171,6 +205,10 @@ function updateCard(config) {
|
|
|
171
205
|
display: isOpen ? 'flex' : 'none',
|
|
172
206
|
flexDirection: 'column'
|
|
173
207
|
})
|
|
208
|
+
if (window.innerWidth < 450) {
|
|
209
|
+
card.style.bottom = '10px'
|
|
210
|
+
card.style.right = '5px'
|
|
211
|
+
}
|
|
174
212
|
|
|
175
213
|
card.style.setProperty('--vc-text-muted', colors.mutedText)
|
|
176
214
|
card.style.setProperty('--vc-bot-bg', colors.botBubble)
|
|
@@ -180,7 +218,7 @@ function updateCard(config) {
|
|
|
180
218
|
const sendBtn = card.querySelector('#vc-send')
|
|
181
219
|
|
|
182
220
|
// send message
|
|
183
|
-
async function sendMessage() {
|
|
221
|
+
async function sendMessage () {
|
|
184
222
|
const text = input.value.trim()
|
|
185
223
|
if (!text) return
|
|
186
224
|
|
|
@@ -213,14 +251,16 @@ function updateCard(config) {
|
|
|
213
251
|
})
|
|
214
252
|
const data = await res.json()
|
|
215
253
|
hideLoader(sendBtn)
|
|
216
|
-
addBotMessage(
|
|
254
|
+
addBotMessage(
|
|
255
|
+
data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
|
|
256
|
+
)
|
|
217
257
|
} catch {
|
|
218
258
|
hideLoader(sendBtn)
|
|
219
259
|
addBotMessage('⚠️ Something went wrong')
|
|
220
260
|
}
|
|
221
261
|
}
|
|
222
262
|
|
|
223
|
-
function addBotMessage(text) {
|
|
263
|
+
function addBotMessage (text) {
|
|
224
264
|
const div = document.createElement('div')
|
|
225
265
|
div.style.cssText = `
|
|
226
266
|
background:${colors.botBubble};
|
|
@@ -236,7 +276,9 @@ function updateCard(config) {
|
|
|
236
276
|
|
|
237
277
|
// events
|
|
238
278
|
sendBtn.onclick = sendMessage
|
|
239
|
-
input.addEventListener('keydown', e => {
|
|
279
|
+
input.addEventListener('keydown', e => {
|
|
280
|
+
if (e.key === 'Enter') sendMessage()
|
|
281
|
+
})
|
|
240
282
|
|
|
241
283
|
return { messages, input, sendBtn }
|
|
242
284
|
}
|
|
@@ -244,7 +286,7 @@ function updateCard(config) {
|
|
|
244
286
|
/* =========================================================
|
|
245
287
|
LOADER
|
|
246
288
|
========================================================= */
|
|
247
|
-
function showLoader(container, sendBtn) {
|
|
289
|
+
function showLoader (container, sendBtn) {
|
|
248
290
|
loaderEl = document.createElement('div')
|
|
249
291
|
loaderEl.className = 'vc-loader'
|
|
250
292
|
loaderEl.innerHTML = '<span></span><span></span><span></span>'
|
|
@@ -257,7 +299,7 @@ function showLoader(container, sendBtn) {
|
|
|
257
299
|
}
|
|
258
300
|
}
|
|
259
301
|
|
|
260
|
-
function hideLoader(sendBtn) {
|
|
302
|
+
function hideLoader (sendBtn) {
|
|
261
303
|
loaderEl?.remove()
|
|
262
304
|
loaderEl = null
|
|
263
305
|
|
|
@@ -272,7 +314,7 @@ function hideLoader(sendBtn) {
|
|
|
272
314
|
PUBLIC API
|
|
273
315
|
========================================================= */
|
|
274
316
|
const VaultChat = {
|
|
275
|
-
init(config = {}) {
|
|
317
|
+
init (config = {}) {
|
|
276
318
|
injectStylesOnce()
|
|
277
319
|
updateButton(config)
|
|
278
320
|
|
|
@@ -288,7 +330,7 @@ const VaultChat = {
|
|
|
288
330
|
}
|
|
289
331
|
},
|
|
290
332
|
|
|
291
|
-
destroy() {
|
|
333
|
+
destroy () {
|
|
292
334
|
vcButton?.remove()
|
|
293
335
|
vcCard?.remove()
|
|
294
336
|
vcButton = null
|
package/package.json
CHANGED
package/rollup.config.js
CHANGED