lisichatbot 1.0.9 → 1.1.1
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/package.json +1 -1
- package/src/index.js +41 -25
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -161,6 +161,7 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
161
161
|
input.name = field;
|
|
162
162
|
input.value = valueStr;
|
|
163
163
|
input.checked = false; // Ensure unchecked initially
|
|
164
|
+
input.onclick = (e) => e.stopPropagation(); // Prevent click bubbling
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
// Find and ensure tick icon is hidden initially
|
|
@@ -186,10 +187,18 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
186
187
|
elements.messages.appendChild(optionsWrapper);
|
|
187
188
|
scrollToBottom();
|
|
188
189
|
|
|
189
|
-
// Add click handlers
|
|
190
|
+
// Add click handlers with proper event handling
|
|
190
191
|
const optionElements = optionsWrapper.querySelectorAll('[data-chat-input-element="container"]');
|
|
191
192
|
optionElements.forEach(el => {
|
|
192
|
-
|
|
193
|
+
// Clear any existing onclick
|
|
194
|
+
el.onclick = null;
|
|
195
|
+
|
|
196
|
+
// Add new click handler with stopPropagation
|
|
197
|
+
el.onclick = (e) => {
|
|
198
|
+
e.stopPropagation(); // Prevent bubbling
|
|
199
|
+
e.preventDefault(); // Prevent default behavior
|
|
200
|
+
handleOptionClick(el, field, isSingleSelect);
|
|
201
|
+
};
|
|
193
202
|
});
|
|
194
203
|
}
|
|
195
204
|
|
|
@@ -198,6 +207,15 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
198
207
|
// =============================================================================
|
|
199
208
|
|
|
200
209
|
function handleOptionClick(element, field, isSingleSelect) {
|
|
210
|
+
// Prevent rapid double-clicks
|
|
211
|
+
const now = Date.now();
|
|
212
|
+
const lastClick = element.getAttribute('data-last-click');
|
|
213
|
+
if (lastClick && (now - parseInt(lastClick)) < 300) {
|
|
214
|
+
console.log('Ignored double-click');
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
element.setAttribute('data-last-click', now.toString());
|
|
218
|
+
|
|
201
219
|
// Find elements using custom attributes
|
|
202
220
|
const tickIcon = element.querySelector('[data-chat-input-element="tick-icon"]');
|
|
203
221
|
const input = element.querySelector('[data-chat-input-element="input"]');
|
|
@@ -207,6 +225,12 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
207
225
|
const optionName = element.getAttribute('data-name');
|
|
208
226
|
const inputType = element.getAttribute('data-chat-element');
|
|
209
227
|
|
|
228
|
+
console.log(`${isSingleSelect ? 'Single-select' : 'Multi-select'} mode:`, {
|
|
229
|
+
field,
|
|
230
|
+
value: valueStr,
|
|
231
|
+
name: optionName
|
|
232
|
+
});
|
|
233
|
+
|
|
210
234
|
// Parse value
|
|
211
235
|
let value;
|
|
212
236
|
try {
|
|
@@ -245,19 +269,11 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
245
269
|
// Multi-select
|
|
246
270
|
const isChecked = !element.classList.contains('cf-checked');
|
|
247
271
|
|
|
248
|
-
console.log('Multi-select clicked:', {
|
|
249
|
-
field,
|
|
250
|
-
value,
|
|
251
|
-
isChecked,
|
|
252
|
-
selectedBackground: config.selectedBackground
|
|
253
|
-
});
|
|
254
|
-
|
|
255
272
|
if (isChecked) {
|
|
256
273
|
element.classList.add('cf-checked');
|
|
257
274
|
element.style.setProperty('background-color', config.selectedBackground, 'important');
|
|
258
275
|
if (tickIcon) {
|
|
259
276
|
tickIcon.style.setProperty('display', 'block', 'important');
|
|
260
|
-
console.log('Tick icon shown for:', optionName);
|
|
261
277
|
}
|
|
262
278
|
if (input) input.checked = true;
|
|
263
279
|
|
|
@@ -273,7 +289,7 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
273
289
|
chatState.data[field].push(value);
|
|
274
290
|
}
|
|
275
291
|
|
|
276
|
-
console.log(
|
|
292
|
+
console.log(`✅ Added "${optionName}" - Total selected:`, chatState.data[field]);
|
|
277
293
|
} else {
|
|
278
294
|
element.classList.remove('cf-checked');
|
|
279
295
|
element.style.setProperty('background-color', 'transparent', 'important');
|
|
@@ -287,7 +303,7 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
287
303
|
);
|
|
288
304
|
}
|
|
289
305
|
|
|
290
|
-
console.log(
|
|
306
|
+
console.log(`❌ Removed "${optionName}" - Total selected:`, chatState.data[field]);
|
|
291
307
|
}
|
|
292
308
|
|
|
293
309
|
// Get all selected names using custom attribute
|
|
@@ -598,14 +614,13 @@ function injectStyles() {
|
|
|
598
614
|
/* Bot message spacing and alignment */
|
|
599
615
|
[data-chat-element="bot-message-wrapper"] {
|
|
600
616
|
margin-bottom: 16px;
|
|
601
|
-
display: flex;
|
|
602
|
-
|
|
603
|
-
|
|
617
|
+
display: inline-flex;
|
|
618
|
+
max-width: 70%;
|
|
619
|
+
align-self: flex-start;
|
|
604
620
|
}
|
|
605
621
|
|
|
606
622
|
/* Bot message natural width from left */
|
|
607
623
|
[data-chat-element="bot-message-text"] {
|
|
608
|
-
max-width: 70%;
|
|
609
624
|
width: auto;
|
|
610
625
|
display: inline-block;
|
|
611
626
|
}
|
|
@@ -613,19 +628,25 @@ function injectStyles() {
|
|
|
613
628
|
/* User message spacing and alignment */
|
|
614
629
|
[data-chat-element="user-message-wrapper"] {
|
|
615
630
|
margin-bottom: 16px;
|
|
616
|
-
display: flex;
|
|
617
|
-
|
|
618
|
-
|
|
631
|
+
display: inline-flex;
|
|
632
|
+
max-width: 70%;
|
|
633
|
+
align-self: flex-end;
|
|
619
634
|
}
|
|
620
635
|
|
|
621
636
|
/* User message natural width from right */
|
|
622
637
|
[data-chat-element="user-message-text"] {
|
|
623
|
-
max-width: 70%;
|
|
624
638
|
width: auto;
|
|
625
639
|
display: inline-block;
|
|
626
640
|
text-align: left;
|
|
627
641
|
}
|
|
628
642
|
|
|
643
|
+
/* Messages container as flex column */
|
|
644
|
+
[data-chat-element="messages-container"] {
|
|
645
|
+
padding: 20px;
|
|
646
|
+
display: flex;
|
|
647
|
+
flex-direction: column;
|
|
648
|
+
}
|
|
649
|
+
|
|
629
650
|
/* Options wrapper spacing and gap */
|
|
630
651
|
[data-chat-element="options-wrapper"] {
|
|
631
652
|
margin-bottom: 20px;
|
|
@@ -633,11 +654,6 @@ function injectStyles() {
|
|
|
633
654
|
flex-direction: column;
|
|
634
655
|
gap: 12px;
|
|
635
656
|
}
|
|
636
|
-
|
|
637
|
-
/* Messages container padding */
|
|
638
|
-
[data-chat-element="messages-container"] {
|
|
639
|
-
padding: 20px;
|
|
640
|
-
}
|
|
641
657
|
`;
|
|
642
658
|
|
|
643
659
|
document.head.appendChild(style);
|