lisichatbot 1.2.1 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +56 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -16,7 +16,8 @@ let chatState = {
16
16
  data: {},
17
17
  history: [],
18
18
  currentSelection: null,
19
- returnToStep: null // Track where to return after editing
19
+ returnToStep: null, // Track where to return after editing
20
+ completed: false // Track if flow is completed
20
21
  };
21
22
 
22
23
  let elements = {
@@ -89,6 +90,17 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
89
90
  // Add step number if provided
90
91
  if (stepNumber !== null) {
91
92
  clone.setAttribute('data-chat-step', stepNumber);
93
+
94
+ // Mark all previous instances of this step as NOT latest
95
+ const previousInstances = elements.messages.querySelectorAll(
96
+ `[data-chat-element="${type}-message-wrapper"][data-chat-step="${stepNumber}"]`
97
+ );
98
+ previousInstances.forEach(prev => {
99
+ prev.removeAttribute('data-chat-latest');
100
+ });
101
+
102
+ // Mark this as the latest instance of this step
103
+ clone.setAttribute('data-chat-latest', 'true');
92
104
  }
93
105
 
94
106
  // Find text element in clone and set content
@@ -111,8 +123,11 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
111
123
  editIcon.style.setProperty('display', 'none', 'important');
112
124
  console.log(' ✓ Edit icon hidden (display: none !important)');
113
125
 
114
- // Only show if this step has input AND it's a PREVIOUS step (not current)
115
- if (hasInput && stepNumber !== null && stepNumber < chatState.step) {
126
+ // Check if this is the latest instance (it should be since we just marked it)
127
+ const isLatest = clone.hasAttribute('data-chat-latest');
128
+
129
+ // Only show if this step has input AND it's a PREVIOUS step AND it's the latest instance
130
+ if (hasInput && stepNumber !== null && stepNumber < chatState.step && isLatest) {
116
131
  editIcon.setAttribute('data-chat-step', stepNumber);
117
132
  editIcon.onclick = (e) => {
118
133
  e.stopPropagation();
@@ -125,9 +140,11 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
125
140
  editIcon.style.setProperty('display', 'block', 'important');
126
141
  editIcon.style.setProperty('margin-left', '8px', 'important');
127
142
  editIcon.style.setProperty('cursor', 'pointer', 'important');
128
- console.log(` ✏️ Edit icon SHOWN (step ${stepNumber} is previous step with input)`);
143
+ console.log(` ✏️ Edit icon SHOWN (step ${stepNumber} is latest previous step with input)`);
129
144
  } else if (hasInput && stepNumber === chatState.step) {
130
145
  console.log(` ⏸️ Edit icon HIDDEN (step ${stepNumber} is CURRENT step)`);
146
+ } else if (!isLatest && hasInput && stepNumber < chatState.step) {
147
+ console.log(` 📜 Edit icon HIDDEN (step ${stepNumber} is OLD instance)`);
131
148
  } else {
132
149
  console.log(` ⚪ Edit icon HIDDEN (step ${stepNumber || 'N/A'} has no input)`);
133
150
  }
@@ -155,8 +172,10 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
155
172
  editIconAfterAppend.style.setProperty('display', 'none', 'important');
156
173
  editIconAfterAppend.style.setProperty('margin-left', '8px', 'important');
157
174
 
158
- // Only show if has input AND it's a previous step
159
- if (hasInput && stepNumber !== null && stepNumber < chatState.step) {
175
+ const isLatest = clone.hasAttribute('data-chat-latest');
176
+
177
+ // Only show if has input AND it's a previous step AND it's latest instance
178
+ if (hasInput && stepNumber !== null && stepNumber < chatState.step && isLatest) {
160
179
  editIconAfterAppend.style.setProperty('display', 'block', 'important');
161
180
 
162
181
  // Debug: Check spacing
@@ -180,19 +199,27 @@ function updateEditIcons() {
180
199
  // Find all rendered bot message wrappers
181
200
  const allBotMessages = elements.messages.querySelectorAll('[data-chat-element="bot-message-wrapper"]');
182
201
 
183
- console.log(`\n🔄 Updating edit icons - Current step: ${chatState.step}`);
202
+ console.log(`\n🔄 Updating edit icons - Current step: ${chatState.step}, Completed: ${chatState.completed}`);
184
203
 
185
204
  allBotMessages.forEach(wrapper => {
186
205
  const stepNumber = parseInt(wrapper.getAttribute('data-chat-step'));
187
206
  const editIcon = wrapper.querySelector('[data-chat-element="bot-edit-icon"]');
207
+ const isLatest = wrapper.hasAttribute('data-chat-latest');
188
208
 
189
209
  if (editIcon && !isNaN(stepNumber)) {
190
210
  // Check if this step has input by looking at the flow
191
211
  const stepData = flowData.flow[stepNumber];
192
212
  const hasInput = stepData && !!stepData.input;
193
213
 
194
- // Show icon if: has input AND is previous step
195
- if (hasInput && stepNumber < chatState.step) {
214
+ // Hide ALL icons if flow is completed
215
+ if (chatState.completed) {
216
+ editIcon.style.setProperty('display', 'none', 'important');
217
+ console.log(` 🏁 Step ${stepNumber}: Icon HIDDEN (flow completed)`);
218
+ return;
219
+ }
220
+
221
+ // Only show icon if: has input AND is previous step AND is latest instance
222
+ if (hasInput && stepNumber < chatState.step && isLatest) {
196
223
  // Set onclick handler
197
224
  editIcon.onclick = (e) => {
198
225
  e.stopPropagation();
@@ -206,10 +233,12 @@ function updateEditIcons() {
206
233
  editIcon.style.setProperty('display', 'block', 'important');
207
234
  editIcon.style.setProperty('cursor', 'pointer', 'important');
208
235
  editIcon.style.setProperty('margin-left', '8px', 'important');
209
- console.log(` ✏️ Step ${stepNumber}: Icon SHOWN (previous step)`);
236
+ console.log(` ✏️ Step ${stepNumber}: Icon SHOWN (latest previous step)`);
210
237
  } else {
211
238
  editIcon.style.setProperty('display', 'none', 'important');
212
- if (stepNumber === chatState.step) {
239
+ if (!isLatest && hasInput && stepNumber < chatState.step) {
240
+ console.log(` 📜 Step ${stepNumber}: Icon HIDDEN (old instance)`);
241
+ } else if (stepNumber === chatState.step) {
213
242
  console.log(` ⏸️ Step ${stepNumber}: Icon HIDDEN (current step)`);
214
243
  } else if (!hasInput) {
215
244
  console.log(` ⚪ Step ${stepNumber}: Icon HIDDEN (no input)`);
@@ -675,6 +704,13 @@ async function showNextStep() {
675
704
  function handleCompletion() {
676
705
  console.log('✅ Flow completed. Data:', chatState.data);
677
706
 
707
+ // Mark flow as completed
708
+ chatState.completed = true;
709
+ console.log(' 🏁 Flow marked as completed');
710
+
711
+ // Hide all edit icons
712
+ updateEditIcons();
713
+
678
714
  // Hide Next button
679
715
  if (elements.nextBtn) {
680
716
  elements.nextBtn.style.display = 'none';
@@ -814,10 +850,9 @@ function goToStep(stepNumber) {
814
850
  chatState.step = stepNumber;
815
851
  chatState.currentSelection = null;
816
852
 
817
- console.log(` Clearing messages container...`);
818
- if (elements.messages) {
819
- elements.messages.innerHTML = '';
820
- }
853
+ // DON'T clear messages - keep chat history visible!
854
+ // User can see their previous answers
855
+ console.log(` Keeping messages visible (not clearing)...`);
821
856
 
822
857
  console.log(` Disabling next button and calling showNextStep()...`);
823
858
  disableNextButton();
@@ -836,6 +871,12 @@ function editStep(stepNumber) {
836
871
  // Save where we are now so we can return after editing
837
872
  chatState.returnToStep = chatState.step;
838
873
  console.log(` 💾 Saved return step: ${chatState.returnToStep}`);
874
+
875
+ // Reset completed flag since we're editing
876
+ if (chatState.completed) {
877
+ chatState.completed = false;
878
+ console.log(` 🔓 Flow unmarked as completed (editing)`);
879
+ }
839
880
 
840
881
  console.log(` Clearing history from step ${stepNumber} forward...`);
841
882
  // Clear history from this step forward