lisichatbot 1.1.2 → 1.1.3
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 +49 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -64,7 +64,7 @@ function disableNextButton() {
|
|
|
64
64
|
// MESSAGE FUNCTIONS
|
|
65
65
|
// =============================================================================
|
|
66
66
|
|
|
67
|
-
function addMessage(content, type = 'bot',
|
|
67
|
+
function addMessage(content, type = 'bot', hasInput = false, stepNumber = null) {
|
|
68
68
|
if (!elements.messages) return;
|
|
69
69
|
|
|
70
70
|
// Find the wrapper element directly by data-chat-element
|
|
@@ -92,16 +92,19 @@ function addMessage(content, type = 'bot', isEditable = false, stepNumber = null
|
|
|
92
92
|
console.error(`Element with data-chat-element="${type}-message-text" not found in wrapper`);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// Handle edit
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
// Handle edit icon for bot messages with input
|
|
96
|
+
if (type === 'bot' && hasInput && stepNumber !== null) {
|
|
97
|
+
const editIcon = clone.querySelector('[data-chat-element="bot-edit-icon"]');
|
|
98
|
+
if (editIcon) {
|
|
99
|
+
editIcon.setAttribute('data-chat-step', stepNumber);
|
|
100
|
+
editIcon.onclick = () => editStep(stepNumber);
|
|
101
|
+
editIcon.style.display = 'inline-block';
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// Make clone visible
|
|
106
|
+
clone.style.display = '';
|
|
107
|
+
|
|
105
108
|
// Append to messages container
|
|
106
109
|
elements.messages.appendChild(clone);
|
|
107
110
|
scrollToBottom();
|
|
@@ -424,9 +427,9 @@ async function handleNext() {
|
|
|
424
427
|
}
|
|
425
428
|
}
|
|
426
429
|
|
|
427
|
-
// Add user message
|
|
430
|
+
// Add user message (only if selection was made)
|
|
428
431
|
if (chatState.currentSelection) {
|
|
429
|
-
addMessage(chatState.currentSelection.name, 'user',
|
|
432
|
+
addMessage(chatState.currentSelection.name, 'user', false, chatState.step);
|
|
430
433
|
|
|
431
434
|
// Save to history
|
|
432
435
|
chatState.history.push({
|
|
@@ -471,8 +474,19 @@ async function showNextStep() {
|
|
|
471
474
|
}
|
|
472
475
|
}
|
|
473
476
|
|
|
474
|
-
//
|
|
475
|
-
|
|
477
|
+
// Hide previous inputs (options, text inputs, number inputs)
|
|
478
|
+
const previousInputs = elements.messages.querySelectorAll(
|
|
479
|
+
'[data-chat-element="options-wrapper"], ' +
|
|
480
|
+
'[data-chat-element="text-input"]:not([style*="display: none"]), ' +
|
|
481
|
+
'[data-chat-element="number-input"]:not([style*="display: none"])'
|
|
482
|
+
);
|
|
483
|
+
previousInputs.forEach(input => {
|
|
484
|
+
input.style.display = 'none';
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// Add bot message with edit icon if has input
|
|
488
|
+
const hasInput = !!nextStep.input;
|
|
489
|
+
addMessage(nextStep.message, 'bot', hasInput, chatState.step);
|
|
476
490
|
|
|
477
491
|
// Check if input is required (default false)
|
|
478
492
|
const inputRequired = nextStep.inputRequired === true;
|
|
@@ -733,6 +747,29 @@ function injectStyles() {
|
|
|
733
747
|
flex-direction: column;
|
|
734
748
|
gap: 12px;
|
|
735
749
|
}
|
|
750
|
+
|
|
751
|
+
/* Text input spacing */
|
|
752
|
+
[data-chat-element="text-input"] {
|
|
753
|
+
margin-bottom: 20px;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/* Number input spacing */
|
|
757
|
+
[data-chat-element="number-input"] {
|
|
758
|
+
margin-bottom: 20px;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/* Bot edit icon styling */
|
|
762
|
+
[data-chat-element="bot-edit-icon"] {
|
|
763
|
+
margin-left: 8px;
|
|
764
|
+
display: none;
|
|
765
|
+
cursor: pointer;
|
|
766
|
+
opacity: 0.6;
|
|
767
|
+
transition: opacity 0.2s ease;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
[data-chat-element="bot-edit-icon"]:hover {
|
|
771
|
+
opacity: 1;
|
|
772
|
+
}
|
|
736
773
|
`;
|
|
737
774
|
|
|
738
775
|
document.head.appendChild(style);
|