lisichatbot 1.6.1 → 1.6.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 +64 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -49,9 +49,14 @@ let flowData = null;
49
49
 
50
50
  function scrollToBottom() {
51
51
  if (elements.messages) {
52
- setTimeout(() => {
53
- elements.messages.scrollTop = elements.messages.scrollHeight;
54
- }, 100);
52
+ // Use requestAnimationFrame to ensure DOM has updated
53
+ 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
+ });
59
+ });
55
60
  }
56
61
  }
57
62
 
@@ -2006,6 +2011,10 @@ async function handleNext() {
2006
2011
  console.log('💬 showMessage called:', message);
2007
2012
  addMessage(message, 'bot', false, null);
2008
2013
  scrollToBottom();
2014
+ // ✅ Delayed scroll to ensure message is fully rendered
2015
+ setTimeout(() => {
2016
+ scrollToBottom();
2017
+ }, 100);
2009
2018
  };
2010
2019
 
2011
2020
  // ✅ Pass showMessage as third parameter
@@ -2020,6 +2029,10 @@ async function handleNext() {
2020
2029
  console.log('💬 onNext displaying message from return:', result.showMessage);
2021
2030
  addMessage(result.showMessage, 'bot', false, null);
2022
2031
  scrollToBottom();
2032
+ // ✅ Delayed scroll to ensure message is fully rendered
2033
+ setTimeout(() => {
2034
+ scrollToBottom();
2035
+ }, 100);
2023
2036
  }
2024
2037
 
2025
2038
  // ✅ NEW: Check if onNext wants to update steps by field name
@@ -2343,7 +2356,8 @@ async function handleNext() {
2343
2356
  }
2344
2357
  }
2345
2358
 
2346
- chatState.step++;
2359
+ // ✅ NEW: Find next accessible step (skip accessibleViaJumpOnly steps)
2360
+ chatState.step = findNextAccessibleStep(chatState.step);
2347
2361
 
2348
2362
  const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
2349
2363
  allRangeWrappers.forEach(wrapper => {
@@ -2359,6 +2373,30 @@ async function handleNext() {
2359
2373
  }
2360
2374
 
2361
2375
  await showNextStep();
2376
+
2377
+ // ✅ NEW: Extra scroll after step is shown to ensure visibility
2378
+ // This catches cases where showMessage was called in onNext before progressing
2379
+ setTimeout(() => {
2380
+ scrollToBottom();
2381
+ }, 350);
2382
+ }
2383
+
2384
+ // ✅ NEW: Helper function to find next step that is accessible in normal flow
2385
+ function findNextAccessibleStep(currentStep) {
2386
+ let nextStep = currentStep + 1;
2387
+
2388
+ while (nextStep < flowData.flow.length) {
2389
+ const stepConfig = flowData.flow[nextStep];
2390
+
2391
+ if (stepConfig.accessibleViaJumpOnly === true) {
2392
+ console.log(` ⏭️ Skipping step ${nextStep} (accessibleViaJumpOnly)`);
2393
+ nextStep++;
2394
+ } else {
2395
+ return nextStep;
2396
+ }
2397
+ }
2398
+
2399
+ return nextStep; // Return even if >= flow.length (will be handled by caller)
2362
2400
  }
2363
2401
 
2364
2402
  async function showNextStep() {
@@ -2407,6 +2445,10 @@ async function showNextStep() {
2407
2445
  console.log('💬 showMessage called:', message);
2408
2446
  addMessage(message, 'bot', false, null);
2409
2447
  scrollToBottom();
2448
+ // ✅ Delayed scroll to ensure message is fully rendered
2449
+ setTimeout(() => {
2450
+ scrollToBottom();
2451
+ }, 100);
2410
2452
  };
2411
2453
 
2412
2454
  // ✅ Pass showMessage as second parameter
@@ -2417,6 +2459,10 @@ async function showNextStep() {
2417
2459
  console.log('💬 onStart displaying message from return:', result.showMessage);
2418
2460
  addMessage(result.showMessage, 'bot', false, null);
2419
2461
  scrollToBottom();
2462
+ // ✅ Delayed scroll to ensure message is fully rendered
2463
+ setTimeout(() => {
2464
+ scrollToBottom();
2465
+ }, 100);
2420
2466
  }
2421
2467
 
2422
2468
  // ✅ NEW: Check if onStart wants to update steps by field name
@@ -2637,7 +2683,8 @@ async function showNextStep() {
2637
2683
  // ✅ NEW: Check if onStart wants to block this step and skip to next
2638
2684
  if (result && typeof result === 'object' && result.blockStep === true) {
2639
2685
  console.log('⏭️ Step blocked by onStart - skipping to next step');
2640
- chatState.step++;
2686
+ // ✅ NEW: Find next accessible step
2687
+ chatState.step = findNextAccessibleStep(chatState.step);
2641
2688
 
2642
2689
  if (chatState.step >= flowData.flow.length) {
2643
2690
  handleCompletion();
@@ -2785,7 +2832,8 @@ async function showNextStep() {
2785
2832
  console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
2786
2833
 
2787
2834
  setTimeout(() => {
2788
- chatState.step++;
2835
+ // ✅ NEW: Find next accessible step
2836
+ chatState.step = findNextAccessibleStep(chatState.step);
2789
2837
  updateEditIcons();
2790
2838
 
2791
2839
  if (chatState.step < flowData.flow.length) {
@@ -2843,6 +2891,16 @@ async function showNextStep() {
2843
2891
  setTimeout(() => {
2844
2892
  updateEditIcons();
2845
2893
  }, 10);
2894
+
2895
+ // ✅ NEW: Delayed scroll to ensure inputs are fully rendered and visible
2896
+ setTimeout(() => {
2897
+ scrollToBottom();
2898
+ }, 150);
2899
+
2900
+ // ✅ NEW: Extra delayed scroll to catch cases where showMessage was called before this step
2901
+ setTimeout(() => {
2902
+ scrollToBottom();
2903
+ }, 300);
2846
2904
  }
2847
2905
 
2848
2906
  function handleCompletion() {