lisichatbot 1.2.0 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +59 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -15,7 +15,8 @@ let chatState = {
15
15
  step: 0,
16
16
  data: {},
17
17
  history: [],
18
- currentSelection: null
18
+ currentSelection: null,
19
+ returnToStep: null // Track where to return after editing
19
20
  };
20
21
 
21
22
  let elements = {
@@ -115,10 +116,15 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
115
116
  editIcon.setAttribute('data-chat-step', stepNumber);
116
117
  editIcon.onclick = (e) => {
117
118
  e.stopPropagation();
119
+ e.preventDefault();
120
+ console.log(`\n🖱️ EDIT ICON CLICKED - Step ${stepNumber}`);
121
+ console.log(` Current step: ${chatState.step}`);
122
+ console.log(` Calling editStep(${stepNumber})...`);
118
123
  editStep(stepNumber);
119
124
  };
120
125
  editIcon.style.setProperty('display', 'block', 'important');
121
126
  editIcon.style.setProperty('margin-left', '8px', 'important');
127
+ editIcon.style.setProperty('cursor', 'pointer', 'important');
122
128
  console.log(` ✏️ Edit icon SHOWN (step ${stepNumber} is previous step with input)`);
123
129
  } else if (hasInput && stepNumber === chatState.step) {
124
130
  console.log(` ⏸️ Edit icon HIDDEN (step ${stepNumber} is CURRENT step)`);
@@ -187,7 +193,19 @@ function updateEditIcons() {
187
193
 
188
194
  // Show icon if: has input AND is previous step
189
195
  if (hasInput && stepNumber < chatState.step) {
196
+ // Set onclick handler
197
+ editIcon.onclick = (e) => {
198
+ e.stopPropagation();
199
+ e.preventDefault();
200
+ console.log(`\n🖱️ EDIT ICON CLICKED (from updateEditIcons) - Step ${stepNumber}`);
201
+ console.log(` Current step: ${chatState.step}`);
202
+ console.log(` Calling editStep(${stepNumber})...`);
203
+ editStep(stepNumber);
204
+ };
205
+ editIcon.setAttribute('data-chat-step', stepNumber);
190
206
  editIcon.style.setProperty('display', 'block', 'important');
207
+ editIcon.style.setProperty('cursor', 'pointer', 'important');
208
+ editIcon.style.setProperty('margin-left', '8px', 'important');
191
209
  console.log(` ✏️ Step ${stepNumber}: Icon SHOWN (previous step)`);
192
210
  } else {
193
211
  editIcon.style.setProperty('display', 'none', 'important');
@@ -535,7 +553,29 @@ async function handleNext() {
535
553
  chatState.currentSelection = null;
536
554
  disableNextButton();
537
555
 
538
- // Move to next step
556
+ // Check if we should return to a saved step (after editing)
557
+ if (chatState.returnToStep !== null) {
558
+ const targetStep = chatState.returnToStep;
559
+ console.log(`\n🔙 Returning to saved step ${targetStep} (edited step complete)`);
560
+ chatState.returnToStep = null; // Clear the return step
561
+
562
+ // Check if target step is valid
563
+ if (targetStep >= 0 && targetStep < flowData.flow.length) {
564
+ chatState.step = targetStep;
565
+ console.log(` ✅ Jumped to step ${targetStep}`);
566
+
567
+ // Update edit icons for the new position
568
+ updateEditIcons();
569
+
570
+ // Show the step we returned to
571
+ await showNextStep();
572
+ return;
573
+ } else {
574
+ console.log(` ⚠️ Invalid return step ${targetStep}, continuing normally`);
575
+ }
576
+ }
577
+
578
+ // Normal flow: Move to next step
539
579
  chatState.step++;
540
580
 
541
581
  // Update edit icons for all previous steps
@@ -762,39 +802,56 @@ function reset() {
762
802
  }
763
803
 
764
804
  function goToStep(stepNumber) {
805
+ console.log(`\n🎯 goToStep() called with stepNumber: ${stepNumber}`);
806
+ console.log(` Current step before: ${chatState.step}`);
807
+
765
808
  if (stepNumber < 0 || stepNumber >= flowData.flow.length) {
766
809
  console.error('Invalid step number:', stepNumber);
767
810
  return;
768
811
  }
769
812
 
813
+ console.log(` Setting chatState.step to ${stepNumber}`);
770
814
  chatState.step = stepNumber;
771
815
  chatState.currentSelection = null;
772
816
 
817
+ console.log(` Clearing messages container...`);
773
818
  if (elements.messages) {
774
819
  elements.messages.innerHTML = '';
775
820
  }
776
821
 
822
+ console.log(` Disabling next button and calling showNextStep()...`);
777
823
  disableNextButton();
778
824
  showNextStep();
779
825
  }
780
826
 
781
827
  function editStep(stepNumber) {
828
+ console.log(`\n📝 editStep() called with stepNumber: ${stepNumber}`);
829
+ console.log(` Current step before edit: ${chatState.step}`);
830
+
782
831
  if (stepNumber < 0 || stepNumber >= flowData.flow.length) {
783
832
  console.error('Invalid step number:', stepNumber);
784
833
  return;
785
834
  }
786
835
 
836
+ // Save where we are now so we can return after editing
837
+ chatState.returnToStep = chatState.step;
838
+ console.log(` 💾 Saved return step: ${chatState.returnToStep}`);
839
+
840
+ console.log(` Clearing history from step ${stepNumber} forward...`);
787
841
  // Clear history from this step forward
788
842
  chatState.history = chatState.history.filter(h => h.step < stepNumber);
789
843
 
844
+ console.log(` Resetting data for step ${stepNumber} and beyond...`);
790
845
  // Reset data for this field and beyond
791
846
  const stepsToReset = flowData.flow.slice(stepNumber);
792
847
  stepsToReset.forEach(step => {
793
848
  if (step.input && step.input.field) {
849
+ console.log(` Deleting field: ${step.input.field}`);
794
850
  delete chatState.data[step.input.field];
795
851
  }
796
852
  });
797
853
 
854
+ console.log(` Calling goToStep(${stepNumber})...`);
798
855
  // Go to that step
799
856
  goToStep(stepNumber);
800
857
  }