lisichatbot 1.1.2 → 1.1.4
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 +64 -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,33 @@ 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
|
|
96
|
+
if (type === 'bot') {
|
|
97
|
+
const editIcon = clone.querySelector('[data-chat-element="bot-edit-icon"]');
|
|
98
|
+
if (editIcon) {
|
|
99
|
+
// Always hide first
|
|
100
|
+
editIcon.style.display = 'none';
|
|
101
|
+
|
|
102
|
+
// Only show if this step has input
|
|
103
|
+
if (hasInput && stepNumber !== null) {
|
|
104
|
+
editIcon.setAttribute('data-chat-step', stepNumber);
|
|
105
|
+
editIcon.onclick = (e) => {
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
editStep(stepNumber);
|
|
108
|
+
};
|
|
109
|
+
editIcon.style.display = 'inline';
|
|
110
|
+
console.log(`✏️ Edit icon shown for step ${stepNumber} (has input)`);
|
|
111
|
+
} else {
|
|
112
|
+
console.log(`⚪ Edit icon hidden for step ${stepNumber} (no input)`);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.warn('⚠️ Edit icon element not found in bot-message-wrapper');
|
|
102
116
|
}
|
|
103
117
|
}
|
|
104
118
|
|
|
119
|
+
// Make clone visible
|
|
120
|
+
clone.style.display = '';
|
|
121
|
+
|
|
105
122
|
// Append to messages container
|
|
106
123
|
elements.messages.appendChild(clone);
|
|
107
124
|
scrollToBottom();
|
|
@@ -424,9 +441,9 @@ async function handleNext() {
|
|
|
424
441
|
}
|
|
425
442
|
}
|
|
426
443
|
|
|
427
|
-
// Add user message
|
|
444
|
+
// Add user message (only if selection was made)
|
|
428
445
|
if (chatState.currentSelection) {
|
|
429
|
-
addMessage(chatState.currentSelection.name, 'user',
|
|
446
|
+
addMessage(chatState.currentSelection.name, 'user', false, chatState.step);
|
|
430
447
|
|
|
431
448
|
// Save to history
|
|
432
449
|
chatState.history.push({
|
|
@@ -471,8 +488,19 @@ async function showNextStep() {
|
|
|
471
488
|
}
|
|
472
489
|
}
|
|
473
490
|
|
|
474
|
-
//
|
|
475
|
-
|
|
491
|
+
// Hide previous inputs (options, text inputs, number inputs)
|
|
492
|
+
const previousInputs = elements.messages.querySelectorAll(
|
|
493
|
+
'[data-chat-element="options-wrapper"], ' +
|
|
494
|
+
'[data-chat-element="text-input"]:not([style*="display: none"]), ' +
|
|
495
|
+
'[data-chat-element="number-input"]:not([style*="display: none"])'
|
|
496
|
+
);
|
|
497
|
+
previousInputs.forEach(input => {
|
|
498
|
+
input.style.display = 'none';
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Add bot message with edit icon if has input
|
|
502
|
+
const hasInput = !!nextStep.input;
|
|
503
|
+
addMessage(nextStep.message, 'bot', hasInput, chatState.step);
|
|
476
504
|
|
|
477
505
|
// Check if input is required (default false)
|
|
478
506
|
const inputRequired = nextStep.inputRequired === true;
|
|
@@ -694,6 +722,8 @@ function injectStyles() {
|
|
|
694
722
|
[data-chat-element="bot-message-wrapper"] {
|
|
695
723
|
margin-bottom: 16px;
|
|
696
724
|
display: inline-flex;
|
|
725
|
+
align-items: center;
|
|
726
|
+
gap: 8px;
|
|
697
727
|
max-width: 70%;
|
|
698
728
|
align-self: flex-start;
|
|
699
729
|
}
|
|
@@ -733,6 +763,28 @@ function injectStyles() {
|
|
|
733
763
|
flex-direction: column;
|
|
734
764
|
gap: 12px;
|
|
735
765
|
}
|
|
766
|
+
|
|
767
|
+
/* Text input spacing */
|
|
768
|
+
[data-chat-element="text-input"] {
|
|
769
|
+
margin-bottom: 20px;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/* Number input spacing */
|
|
773
|
+
[data-chat-element="number-input"] {
|
|
774
|
+
margin-bottom: 20px;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/* Bot edit icon styling */
|
|
778
|
+
[data-chat-element="bot-edit-icon"] {
|
|
779
|
+
display: none;
|
|
780
|
+
cursor: pointer;
|
|
781
|
+
opacity: 0.6;
|
|
782
|
+
transition: opacity 0.2s ease;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
[data-chat-element="bot-edit-icon"]:hover {
|
|
786
|
+
opacity: 1;
|
|
787
|
+
}
|
|
736
788
|
`;
|
|
737
789
|
|
|
738
790
|
document.head.appendChild(style);
|