@mobil80-dev/chatbot-widget 2.0.5 → 2.0.7
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 +99 -41
- package/dist/index.umd.js +99 -41
- package/index.js +37 -21
- package/package.json +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,54 +122,98 @@ 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
|
|
|
138
170
|
card.innerHTML = `
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
171
|
+
<div style="padding:12px;border-bottom:1px solid ${colors.headerBorder};color:${colors.mutedText};display:flex;justify-content:space-between;align-items:center">
|
|
172
|
+
<span>Powered by <strong>VaultChat</strong></span>
|
|
173
|
+
<button id="vc-close" style="
|
|
174
|
+
background:none;
|
|
175
|
+
border:none;
|
|
176
|
+
color:${colors.mutedText};
|
|
177
|
+
font-size:18px;
|
|
178
|
+
cursor:pointer;
|
|
179
|
+
font-weight:bold;
|
|
180
|
+
padding:0;
|
|
181
|
+
line-height:1;">✖</button>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div id="vc-messages" style="
|
|
185
|
+
flex:1;
|
|
186
|
+
padding:12px;
|
|
187
|
+
overflow-y:auto;
|
|
188
|
+
background:${colors.messagesBg};
|
|
189
|
+
color:${colors.text}">
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<div style="display:flex;padding:10px;border-top:1px solid ${colors.headerBorder};background:${colors.cardBg}">
|
|
193
|
+
<input id="vc-input" placeholder="Type your message..."
|
|
194
|
+
style="flex:1;padding:10px;border-radius:8px;border:1px solid ${colors.inputBorder};
|
|
195
|
+
background:${colors.inputBg};color:${colors.text}" />
|
|
196
|
+
<button id="vc-send" style="
|
|
197
|
+
margin-left:8px;padding:0 14px;border:none;border-radius:8px;
|
|
198
|
+
background:${primaryColor};color:white;cursor:pointer">➤</button>
|
|
199
|
+
</div>
|
|
200
|
+
`;
|
|
201
|
+
|
|
202
|
+
// Add event listener for close button
|
|
203
|
+
const closeBtn = card.querySelector('#vc-close');
|
|
204
|
+
closeBtn.onclick = () => {
|
|
205
|
+
isOpen = false;
|
|
206
|
+
vcCard.style.display = 'none';
|
|
207
|
+
};
|
|
160
208
|
|
|
161
209
|
Object.assign(card.style, {
|
|
162
210
|
position: 'fixed',
|
|
163
211
|
bottom: '90px',
|
|
164
212
|
right: '20px',
|
|
213
|
+
maxWidth: '90vw',
|
|
165
214
|
width: '400px',
|
|
166
215
|
height: '420px',
|
|
216
|
+
maxHeight: '80vh',
|
|
167
217
|
background: colors.cardBg,
|
|
168
218
|
borderRadius: '12px',
|
|
169
219
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
@@ -171,6 +221,10 @@ function updateCard(config) {
|
|
|
171
221
|
display: isOpen ? 'flex' : 'none',
|
|
172
222
|
flexDirection: 'column'
|
|
173
223
|
});
|
|
224
|
+
if (window.innerWidth < 450) {
|
|
225
|
+
card.style.bottom = '10px';
|
|
226
|
+
card.style.right = '5px';
|
|
227
|
+
}
|
|
174
228
|
|
|
175
229
|
card.style.setProperty('--vc-text-muted', colors.mutedText);
|
|
176
230
|
card.style.setProperty('--vc-bot-bg', colors.botBubble);
|
|
@@ -180,7 +234,7 @@ function updateCard(config) {
|
|
|
180
234
|
const sendBtn = card.querySelector('#vc-send');
|
|
181
235
|
|
|
182
236
|
// send message
|
|
183
|
-
async function sendMessage() {
|
|
237
|
+
async function sendMessage () {
|
|
184
238
|
const text = input.value.trim();
|
|
185
239
|
if (!text) return
|
|
186
240
|
|
|
@@ -213,14 +267,16 @@ function updateCard(config) {
|
|
|
213
267
|
});
|
|
214
268
|
const data = await res.json();
|
|
215
269
|
hideLoader(sendBtn);
|
|
216
|
-
addBotMessage(
|
|
270
|
+
addBotMessage(
|
|
271
|
+
data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
|
|
272
|
+
);
|
|
217
273
|
} catch {
|
|
218
274
|
hideLoader(sendBtn);
|
|
219
275
|
addBotMessage('⚠️ Something went wrong');
|
|
220
276
|
}
|
|
221
277
|
}
|
|
222
278
|
|
|
223
|
-
function addBotMessage(text) {
|
|
279
|
+
function addBotMessage (text) {
|
|
224
280
|
const div = document.createElement('div');
|
|
225
281
|
div.style.cssText = `
|
|
226
282
|
background:${colors.botBubble};
|
|
@@ -236,7 +292,9 @@ function updateCard(config) {
|
|
|
236
292
|
|
|
237
293
|
// events
|
|
238
294
|
sendBtn.onclick = sendMessage;
|
|
239
|
-
input.addEventListener('keydown', e => {
|
|
295
|
+
input.addEventListener('keydown', e => {
|
|
296
|
+
if (e.key === 'Enter') sendMessage();
|
|
297
|
+
});
|
|
240
298
|
|
|
241
299
|
return { messages, input, sendBtn }
|
|
242
300
|
}
|
|
@@ -244,7 +302,7 @@ function updateCard(config) {
|
|
|
244
302
|
/* =========================================================
|
|
245
303
|
LOADER
|
|
246
304
|
========================================================= */
|
|
247
|
-
function showLoader(container, sendBtn) {
|
|
305
|
+
function showLoader (container, sendBtn) {
|
|
248
306
|
loaderEl = document.createElement('div');
|
|
249
307
|
loaderEl.className = 'vc-loader';
|
|
250
308
|
loaderEl.innerHTML = '<span></span><span></span><span></span>';
|
|
@@ -257,7 +315,7 @@ function showLoader(container, sendBtn) {
|
|
|
257
315
|
}
|
|
258
316
|
}
|
|
259
317
|
|
|
260
|
-
function hideLoader(sendBtn) {
|
|
318
|
+
function hideLoader (sendBtn) {
|
|
261
319
|
loaderEl?.remove();
|
|
262
320
|
loaderEl = null;
|
|
263
321
|
|
|
@@ -272,7 +330,7 @@ function hideLoader(sendBtn) {
|
|
|
272
330
|
PUBLIC API
|
|
273
331
|
========================================================= */
|
|
274
332
|
const VaultChat = {
|
|
275
|
-
init(config = {}) {
|
|
333
|
+
init (config = {}) {
|
|
276
334
|
injectStylesOnce();
|
|
277
335
|
updateButton(config);
|
|
278
336
|
|
|
@@ -288,7 +346,7 @@ const VaultChat = {
|
|
|
288
346
|
};
|
|
289
347
|
},
|
|
290
348
|
|
|
291
|
-
destroy() {
|
|
349
|
+
destroy () {
|
|
292
350
|
vcButton?.remove();
|
|
293
351
|
vcCard?.remove();
|
|
294
352
|
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,54 +128,98 @@
|
|
|
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
|
|
|
144
176
|
card.innerHTML = `
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
<div style="padding:12px;border-bottom:1px solid ${colors.headerBorder};color:${colors.mutedText};display:flex;justify-content:space-between;align-items:center">
|
|
178
|
+
<span>Powered by <strong>VaultChat</strong></span>
|
|
179
|
+
<button id="vc-close" style="
|
|
180
|
+
background:none;
|
|
181
|
+
border:none;
|
|
182
|
+
color:${colors.mutedText};
|
|
183
|
+
font-size:18px;
|
|
184
|
+
cursor:pointer;
|
|
185
|
+
font-weight:bold;
|
|
186
|
+
padding:0;
|
|
187
|
+
line-height:1;">✖</button>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<div id="vc-messages" style="
|
|
191
|
+
flex:1;
|
|
192
|
+
padding:12px;
|
|
193
|
+
overflow-y:auto;
|
|
194
|
+
background:${colors.messagesBg};
|
|
195
|
+
color:${colors.text}">
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
<div style="display:flex;padding:10px;border-top:1px solid ${colors.headerBorder};background:${colors.cardBg}">
|
|
199
|
+
<input id="vc-input" placeholder="Type your message..."
|
|
200
|
+
style="flex:1;padding:10px;border-radius:8px;border:1px solid ${colors.inputBorder};
|
|
201
|
+
background:${colors.inputBg};color:${colors.text}" />
|
|
202
|
+
<button id="vc-send" style="
|
|
203
|
+
margin-left:8px;padding:0 14px;border:none;border-radius:8px;
|
|
204
|
+
background:${primaryColor};color:white;cursor:pointer">➤</button>
|
|
205
|
+
</div>
|
|
206
|
+
`;
|
|
207
|
+
|
|
208
|
+
// Add event listener for close button
|
|
209
|
+
const closeBtn = card.querySelector('#vc-close');
|
|
210
|
+
closeBtn.onclick = () => {
|
|
211
|
+
isOpen = false;
|
|
212
|
+
vcCard.style.display = 'none';
|
|
213
|
+
};
|
|
166
214
|
|
|
167
215
|
Object.assign(card.style, {
|
|
168
216
|
position: 'fixed',
|
|
169
217
|
bottom: '90px',
|
|
170
218
|
right: '20px',
|
|
219
|
+
maxWidth: '90vw',
|
|
171
220
|
width: '400px',
|
|
172
221
|
height: '420px',
|
|
222
|
+
maxHeight: '80vh',
|
|
173
223
|
background: colors.cardBg,
|
|
174
224
|
borderRadius: '12px',
|
|
175
225
|
boxShadow: '0 10px 30px rgba(0,0,0,.3)',
|
|
@@ -177,6 +227,10 @@
|
|
|
177
227
|
display: isOpen ? 'flex' : 'none',
|
|
178
228
|
flexDirection: 'column'
|
|
179
229
|
});
|
|
230
|
+
if (window.innerWidth < 450) {
|
|
231
|
+
card.style.bottom = '10px';
|
|
232
|
+
card.style.right = '5px';
|
|
233
|
+
}
|
|
180
234
|
|
|
181
235
|
card.style.setProperty('--vc-text-muted', colors.mutedText);
|
|
182
236
|
card.style.setProperty('--vc-bot-bg', colors.botBubble);
|
|
@@ -186,7 +240,7 @@
|
|
|
186
240
|
const sendBtn = card.querySelector('#vc-send');
|
|
187
241
|
|
|
188
242
|
// send message
|
|
189
|
-
async function sendMessage() {
|
|
243
|
+
async function sendMessage () {
|
|
190
244
|
const text = input.value.trim();
|
|
191
245
|
if (!text) return
|
|
192
246
|
|
|
@@ -219,14 +273,16 @@
|
|
|
219
273
|
});
|
|
220
274
|
const data = await res.json();
|
|
221
275
|
hideLoader(sendBtn);
|
|
222
|
-
addBotMessage(
|
|
276
|
+
addBotMessage(
|
|
277
|
+
data?.data?.blocks?.map(b => b.text).join('\n') || 'No response'
|
|
278
|
+
);
|
|
223
279
|
} catch {
|
|
224
280
|
hideLoader(sendBtn);
|
|
225
281
|
addBotMessage('⚠️ Something went wrong');
|
|
226
282
|
}
|
|
227
283
|
}
|
|
228
284
|
|
|
229
|
-
function addBotMessage(text) {
|
|
285
|
+
function addBotMessage (text) {
|
|
230
286
|
const div = document.createElement('div');
|
|
231
287
|
div.style.cssText = `
|
|
232
288
|
background:${colors.botBubble};
|
|
@@ -242,7 +298,9 @@
|
|
|
242
298
|
|
|
243
299
|
// events
|
|
244
300
|
sendBtn.onclick = sendMessage;
|
|
245
|
-
input.addEventListener('keydown', e => {
|
|
301
|
+
input.addEventListener('keydown', e => {
|
|
302
|
+
if (e.key === 'Enter') sendMessage();
|
|
303
|
+
});
|
|
246
304
|
|
|
247
305
|
return { messages, input, sendBtn }
|
|
248
306
|
}
|
|
@@ -250,7 +308,7 @@
|
|
|
250
308
|
/* =========================================================
|
|
251
309
|
LOADER
|
|
252
310
|
========================================================= */
|
|
253
|
-
function showLoader(container, sendBtn) {
|
|
311
|
+
function showLoader (container, sendBtn) {
|
|
254
312
|
loaderEl = document.createElement('div');
|
|
255
313
|
loaderEl.className = 'vc-loader';
|
|
256
314
|
loaderEl.innerHTML = '<span></span><span></span><span></span>';
|
|
@@ -263,7 +321,7 @@
|
|
|
263
321
|
}
|
|
264
322
|
}
|
|
265
323
|
|
|
266
|
-
function hideLoader(sendBtn) {
|
|
324
|
+
function hideLoader (sendBtn) {
|
|
267
325
|
loaderEl?.remove();
|
|
268
326
|
loaderEl = null;
|
|
269
327
|
|
|
@@ -278,7 +336,7 @@
|
|
|
278
336
|
PUBLIC API
|
|
279
337
|
========================================================= */
|
|
280
338
|
const VaultChat = {
|
|
281
|
-
init(config = {}) {
|
|
339
|
+
init (config = {}) {
|
|
282
340
|
injectStylesOnce();
|
|
283
341
|
updateButton(config);
|
|
284
342
|
|
|
@@ -294,7 +352,7 @@
|
|
|
294
352
|
};
|
|
295
353
|
},
|
|
296
354
|
|
|
297
|
-
destroy() {
|
|
355
|
+
destroy () {
|
|
298
356
|
vcButton?.remove();
|
|
299
357
|
vcCard?.remove();
|
|
300
358
|
vcButton = null;
|
package/index.js
CHANGED
|
@@ -168,27 +168,43 @@ function updateCard (config) {
|
|
|
168
168
|
const primaryColor = config.primaryColor || '#2563eb'
|
|
169
169
|
|
|
170
170
|
card.innerHTML = `
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
171
|
+
<div style="padding:12px;border-bottom:1px solid ${colors.headerBorder};color:${colors.mutedText};display:flex;justify-content:space-between;align-items:center">
|
|
172
|
+
<span>Powered by <strong>VaultChat</strong></span>
|
|
173
|
+
<button id="vc-close" style="
|
|
174
|
+
background:none;
|
|
175
|
+
border:none;
|
|
176
|
+
color:${colors.mutedText};
|
|
177
|
+
font-size:18px;
|
|
178
|
+
cursor:pointer;
|
|
179
|
+
font-weight:bold;
|
|
180
|
+
padding:0;
|
|
181
|
+
line-height:1;">✖</button>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div id="vc-messages" style="
|
|
185
|
+
flex:1;
|
|
186
|
+
padding:12px;
|
|
187
|
+
overflow-y:auto;
|
|
188
|
+
background:${colors.messagesBg};
|
|
189
|
+
color:${colors.text}">
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<div style="display:flex;padding:10px;border-top:1px solid ${colors.headerBorder};background:${colors.cardBg}">
|
|
193
|
+
<input id="vc-input" placeholder="Type your message..."
|
|
194
|
+
style="flex:1;padding:10px;border-radius:8px;border:1px solid ${colors.inputBorder};
|
|
195
|
+
background:${colors.inputBg};color:${colors.text}" />
|
|
196
|
+
<button id="vc-send" style="
|
|
197
|
+
margin-left:8px;padding:0 14px;border:none;border-radius:8px;
|
|
198
|
+
background:${primaryColor};color:white;cursor:pointer">➤</button>
|
|
199
|
+
</div>
|
|
200
|
+
`
|
|
201
|
+
|
|
202
|
+
// Add event listener for close button
|
|
203
|
+
const closeBtn = card.querySelector('#vc-close')
|
|
204
|
+
closeBtn.onclick = () => {
|
|
205
|
+
isOpen = false
|
|
206
|
+
vcCard.style.display = 'none'
|
|
207
|
+
}
|
|
192
208
|
|
|
193
209
|
Object.assign(card.style, {
|
|
194
210
|
position: 'fixed',
|