lisichatbot 1.6.5 → 1.6.7

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 +49 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -48,16 +48,29 @@ let flowData = null;
48
48
  // =============================================================================
49
49
 
50
50
  function scrollToBottom() {
51
- if (elements.messages) {
52
- // ✅ Use requestAnimationFrame to ensure DOM has updated
51
+ if (!elements.messages) return;
52
+
53
+ // ✅ NEW: Ensure the very last child is fully visible
54
+ const scrollToLastElement = () => {
55
+ const lastChild = elements.messages.lastElementChild;
56
+ if (lastChild) {
57
+ lastChild.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'nearest' });
58
+ console.log(` 📜 Scrolled last element into view`);
59
+ } else {
60
+ // Fallback to scrollHeight
61
+ elements.messages.scrollTop = elements.messages.scrollHeight;
62
+ }
63
+ };
64
+
65
+ // Immediate scroll
66
+ scrollToLastElement();
67
+
68
+ // ✅ Use requestAnimationFrame to ensure DOM layout is complete
69
+ requestAnimationFrame(() => {
53
70
  requestAnimationFrame(() => {
54
- requestAnimationFrame(() => {
55
- // Double RAF ensures layout is complete
56
- elements.messages.scrollTop = elements.messages.scrollHeight;
57
- console.log(` 📜 Scrolled to bottom: ${elements.messages.scrollHeight}px`);
58
- });
71
+ scrollToLastElement();
59
72
  });
60
- }
73
+ });
61
74
  }
62
75
 
63
76
  function enableNextButton() {
@@ -2011,10 +2024,6 @@ async function handleNext() {
2011
2024
  console.log('💬 showMessage called:', message);
2012
2025
  addMessage(message, 'bot', false, null);
2013
2026
  scrollToBottom();
2014
- // ✅ Delayed scroll to ensure message is fully rendered
2015
- setTimeout(() => {
2016
- scrollToBottom();
2017
- }, 100);
2018
2027
  };
2019
2028
 
2020
2029
  // ✅ Pass showMessage as third parameter
@@ -2029,10 +2038,6 @@ async function handleNext() {
2029
2038
  console.log('💬 onNext displaying message from return:', result.showMessage);
2030
2039
  addMessage(result.showMessage, 'bot', false, null);
2031
2040
  scrollToBottom();
2032
- // ✅ Delayed scroll to ensure message is fully rendered
2033
- setTimeout(() => {
2034
- scrollToBottom();
2035
- }, 100);
2036
2041
  }
2037
2042
 
2038
2043
  // ✅ NEW: Check if onNext wants to update steps by field name
@@ -2129,6 +2134,11 @@ async function handleNext() {
2129
2134
  scrollToBottom();
2130
2135
  }, 500);
2131
2136
 
2137
+ // ✅ NEW: Final scroll for steps with multiple inputs
2138
+ setTimeout(() => {
2139
+ scrollToBottom();
2140
+ }, 800);
2141
+
2132
2142
  return;
2133
2143
  } else {
2134
2144
  console.error(`❌ No step found with name: "${stepName}"`);
@@ -2162,15 +2172,8 @@ async function handleNext() {
2162
2172
  disableNextButton();
2163
2173
  await showNextStep();
2164
2174
 
2165
- // ✅ NEW: Extra scroll after jump to ensure inputs are visible
2166
- setTimeout(() => {
2167
- scrollToBottom();
2168
- }, 350);
2169
-
2170
- // ✅ NEW: Additional delayed scroll for cases with multiple showMessage calls
2171
- setTimeout(() => {
2172
- scrollToBottom();
2173
- }, 500);
2175
+ // ✅ Single scroll call - MutationObserver will handle the rest
2176
+ scrollToBottom();
2174
2177
 
2175
2178
  return;
2176
2179
  } else {
@@ -2396,11 +2399,8 @@ async function handleNext() {
2396
2399
 
2397
2400
  await showNextStep();
2398
2401
 
2399
- // ✅ NEW: Extra scroll after step is shown to ensure visibility
2400
- // This catches cases where showMessage was called in onNext before progressing
2401
- setTimeout(() => {
2402
- scrollToBottom();
2403
- }, 350);
2402
+ // ✅ Final scroll after showNextStep completes
2403
+ scrollToBottom();
2404
2404
  }
2405
2405
 
2406
2406
  // ✅ NEW: Helper function to find next step that is accessible in normal flow
@@ -2467,10 +2467,6 @@ async function showNextStep() {
2467
2467
  console.log('💬 showMessage called:', message);
2468
2468
  addMessage(message, 'bot', false, null);
2469
2469
  scrollToBottom();
2470
- // ✅ Delayed scroll to ensure message is fully rendered
2471
- setTimeout(() => {
2472
- scrollToBottom();
2473
- }, 100);
2474
2470
  };
2475
2471
 
2476
2472
  // ✅ Pass showMessage as second parameter
@@ -2481,10 +2477,6 @@ async function showNextStep() {
2481
2477
  console.log('💬 onStart displaying message from return:', result.showMessage);
2482
2478
  addMessage(result.showMessage, 'bot', false, null);
2483
2479
  scrollToBottom();
2484
- // ✅ Delayed scroll to ensure message is fully rendered
2485
- setTimeout(() => {
2486
- scrollToBottom();
2487
- }, 100);
2488
2480
  }
2489
2481
 
2490
2482
  // ✅ NEW: Check if onStart wants to update steps by field name
@@ -2660,20 +2652,16 @@ async function showNextStep() {
2660
2652
  console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
2661
2653
  }
2662
2654
 
2655
+ // ✅ Check if we're jumping from the very first step (needs extra time to initialize)
2656
+ const isJumpingFromFirstStep = chatState.step === 0;
2657
+
2663
2658
  chatState.step = targetStepIndex;
2664
2659
  chatState.currentSelection = null;
2665
2660
  disableNextButton();
2666
2661
  await showNextStep();
2667
2662
 
2668
- // ✅ NEW: Extra scroll after jump to ensure inputs are visible
2669
- setTimeout(() => {
2670
- scrollToBottom();
2671
- }, 350);
2672
-
2673
- // ✅ NEW: Additional delayed scroll for cases with multiple showMessage calls
2674
- setTimeout(() => {
2675
- scrollToBottom();
2676
- }, 500);
2663
+ // ✅ Single scroll call - MutationObserver will handle the rest
2664
+ scrollToBottom();
2677
2665
 
2678
2666
  return;
2679
2667
  } else {
@@ -2703,20 +2691,16 @@ async function showNextStep() {
2703
2691
  console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
2704
2692
  }
2705
2693
 
2694
+ // ✅ Check if we're jumping from the very first step (needs extra time to initialize)
2695
+ const isJumpingFromFirstStep = chatState.step === 0;
2696
+
2706
2697
  chatState.step = targetStep;
2707
2698
  chatState.currentSelection = null;
2708
2699
  disableNextButton();
2709
2700
  await showNextStep();
2710
2701
 
2711
- // ✅ NEW: Extra scroll after jump to ensure inputs are visible
2712
- setTimeout(() => {
2713
- scrollToBottom();
2714
- }, 350);
2715
-
2716
- // ✅ NEW: Additional delayed scroll for cases with multiple showMessage calls
2717
- setTimeout(() => {
2718
- scrollToBottom();
2719
- }, 500);
2702
+ // ✅ Single scroll call - MutationObserver will handle the rest
2703
+ scrollToBottom();
2720
2704
 
2721
2705
  return;
2722
2706
  } else {
@@ -2936,15 +2920,15 @@ async function showNextStep() {
2936
2920
  updateEditIcons();
2937
2921
  }, 10);
2938
2922
 
2939
- // ✅ NEW: Delayed scroll to ensure inputs are fully rendered and visible
2940
- setTimeout(() => {
2941
- scrollToBottom();
2942
- }, 150);
2943
-
2944
- // ✅ NEW: Extra delayed scroll to catch cases where showMessage was called before this step
2945
- setTimeout(() => {
2946
- scrollToBottom();
2947
- }, 300);
2923
+ // ✅ Final scroll after all rendering completes
2924
+ requestAnimationFrame(() => {
2925
+ requestAnimationFrame(() => {
2926
+ requestAnimationFrame(() => {
2927
+ // Triple RAF to ensure everything is laid out
2928
+ scrollToBottom();
2929
+ });
2930
+ });
2931
+ });
2948
2932
  }
2949
2933
 
2950
2934
  function handleCompletion() {