lisichatbot 2.1.7 → 2.1.9

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 +30 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -23,7 +23,8 @@ let chatState = {
23
23
  editSteps: null, // ✅ Array of step indices to walk through in edit-steps mode
24
24
  editStepsIndex: 0, // ✅ Current position within editSteps array
25
25
  onEditComplete: null, // ✅ Callback when editSteps flow finishes
26
- editFinalButtonText: null // ✅ Button text for the last step in editSteps
26
+ editFinalButtonText: null, // ✅ Button text for the last step in editSteps
27
+ autoAdvanceTimer: null // ✅ Track auto-advance timeout so it can be cleared
27
28
  };
28
29
 
29
30
  let elements = {
@@ -1538,7 +1539,9 @@ function handleCustomSelectClick(element, field, customConfig) {
1538
1539
  const delay = currentStep.autoAdvanceDelay || 500;
1539
1540
  // console.log(` ⏱️ Waiting ${delay}ms before advancing`);
1540
1541
 
1541
- setTimeout(() => {
1542
+ if (chatState.autoAdvanceTimer) clearTimeout(chatState.autoAdvanceTimer);
1543
+ chatState.autoAdvanceTimer = setTimeout(() => {
1544
+ chatState.autoAdvanceTimer = null;
1542
1545
  if (elements.nextBtn && !elements.nextBtn.disabled) {
1543
1546
  // console.log(' ▶️ Auto-advancing to next step');
1544
1547
  handleNext();
@@ -2007,7 +2010,9 @@ function handleOptionClick(element, field, isSingleSelect, options) {
2007
2010
  const delay = currentStep.autoAdvanceDelay || 500;
2008
2011
  // console.log(` ⏱️ Waiting ${delay}ms before advancing`);
2009
2012
 
2010
- setTimeout(() => {
2013
+ if (chatState.autoAdvanceTimer) clearTimeout(chatState.autoAdvanceTimer);
2014
+ chatState.autoAdvanceTimer = setTimeout(() => {
2015
+ chatState.autoAdvanceTimer = null;
2011
2016
  if (elements.nextBtn && !elements.nextBtn.disabled) {
2012
2017
  // console.log(' ▶️ Auto-advancing to next step');
2013
2018
  handleNext();
@@ -2099,7 +2104,11 @@ function handleOptionClick(element, field, isSingleSelect, options) {
2099
2104
  // NAVIGATION
2100
2105
  // =============================================================================
2101
2106
 
2107
+ let _handleNextRunning = false;
2102
2108
  async function handleNext() {
2109
+ if (_handleNextRunning) return;
2110
+ _handleNextRunning = true;
2111
+ try {
2103
2112
  const currentStep = flowData.flow[chatState.step];
2104
2113
 
2105
2114
  const inputRequired = currentStep.inputRequired === true;
@@ -2372,11 +2381,17 @@ async function handleNext() {
2372
2381
  // console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
2373
2382
  }
2374
2383
 
2384
+ // ✅ Clear any pending auto-advance timer
2385
+ if (chatState.autoAdvanceTimer) {
2386
+ clearTimeout(chatState.autoAdvanceTimer);
2387
+ chatState.autoAdvanceTimer = null;
2388
+ }
2389
+
2375
2390
  chatState.step = targetStepIndex;
2376
2391
  chatState.currentSelection = null;
2377
2392
  disableNextButton();
2378
2393
  await showNextStep();
2379
-
2394
+
2380
2395
  // ✅ NEW: Extra scroll after jump to ensure inputs are visible
2381
2396
  setTimeout(() => {
2382
2397
  scrollToBottom();
@@ -2787,9 +2802,12 @@ async function handleNext() {
2787
2802
  }
2788
2803
 
2789
2804
  await showNextStep();
2790
-
2805
+
2791
2806
  // ✅ Final scroll after showNextStep completes
2792
2807
  scrollToBottom();
2808
+ } finally {
2809
+ _handleNextRunning = false;
2810
+ }
2793
2811
  }
2794
2812
 
2795
2813
  // ✅ NEW: Helper function to find next step that is accessible in normal flow
@@ -3116,9 +3134,15 @@ async function showNextStep() {
3116
3134
  // console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
3117
3135
  }
3118
3136
 
3137
+ // ✅ Clear any pending auto-advance timer
3138
+ if (chatState.autoAdvanceTimer) {
3139
+ clearTimeout(chatState.autoAdvanceTimer);
3140
+ chatState.autoAdvanceTimer = null;
3141
+ }
3142
+
3119
3143
  // ✅ Check if we're jumping from the very first step (needs extra time to initialize)
3120
3144
  const isJumpingFromFirstStep = chatState.step === 0;
3121
-
3145
+
3122
3146
  chatState.step = targetStepIndex;
3123
3147
  chatState.currentSelection = null;
3124
3148
  disableNextButton();