lisichatbot 1.6.1 → 1.6.2

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 +53 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
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 => {
@@ -2361,6 +2375,24 @@ async function handleNext() {
2361
2375
  await showNextStep();
2362
2376
  }
2363
2377
 
2378
+ // ✅ NEW: Helper function to find next step that is accessible in normal flow
2379
+ function findNextAccessibleStep(currentStep) {
2380
+ let nextStep = currentStep + 1;
2381
+
2382
+ while (nextStep < flowData.flow.length) {
2383
+ const stepConfig = flowData.flow[nextStep];
2384
+
2385
+ if (stepConfig.accessibleViaJumpOnly === true) {
2386
+ console.log(` ⏭️ Skipping step ${nextStep} (accessibleViaJumpOnly)`);
2387
+ nextStep++;
2388
+ } else {
2389
+ return nextStep;
2390
+ }
2391
+ }
2392
+
2393
+ return nextStep; // Return even if >= flow.length (will be handled by caller)
2394
+ }
2395
+
2364
2396
  async function showNextStep() {
2365
2397
  const nextStep = flowData.flow[chatState.step];
2366
2398
 
@@ -2407,6 +2439,10 @@ async function showNextStep() {
2407
2439
  console.log('💬 showMessage called:', message);
2408
2440
  addMessage(message, 'bot', false, null);
2409
2441
  scrollToBottom();
2442
+ // ✅ Delayed scroll to ensure message is fully rendered
2443
+ setTimeout(() => {
2444
+ scrollToBottom();
2445
+ }, 100);
2410
2446
  };
2411
2447
 
2412
2448
  // ✅ Pass showMessage as second parameter
@@ -2417,6 +2453,10 @@ async function showNextStep() {
2417
2453
  console.log('💬 onStart displaying message from return:', result.showMessage);
2418
2454
  addMessage(result.showMessage, 'bot', false, null);
2419
2455
  scrollToBottom();
2456
+ // ✅ Delayed scroll to ensure message is fully rendered
2457
+ setTimeout(() => {
2458
+ scrollToBottom();
2459
+ }, 100);
2420
2460
  }
2421
2461
 
2422
2462
  // ✅ NEW: Check if onStart wants to update steps by field name
@@ -2637,7 +2677,8 @@ async function showNextStep() {
2637
2677
  // ✅ NEW: Check if onStart wants to block this step and skip to next
2638
2678
  if (result && typeof result === 'object' && result.blockStep === true) {
2639
2679
  console.log('⏭️ Step blocked by onStart - skipping to next step');
2640
- chatState.step++;
2680
+ // ✅ NEW: Find next accessible step
2681
+ chatState.step = findNextAccessibleStep(chatState.step);
2641
2682
 
2642
2683
  if (chatState.step >= flowData.flow.length) {
2643
2684
  handleCompletion();
@@ -2785,7 +2826,8 @@ async function showNextStep() {
2785
2826
  console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
2786
2827
 
2787
2828
  setTimeout(() => {
2788
- chatState.step++;
2829
+ // ✅ NEW: Find next accessible step
2830
+ chatState.step = findNextAccessibleStep(chatState.step);
2789
2831
  updateEditIcons();
2790
2832
 
2791
2833
  if (chatState.step < flowData.flow.length) {
@@ -2843,6 +2885,11 @@ async function showNextStep() {
2843
2885
  setTimeout(() => {
2844
2886
  updateEditIcons();
2845
2887
  }, 10);
2888
+
2889
+ // ✅ NEW: Delayed scroll to ensure inputs are fully rendered and visible
2890
+ setTimeout(() => {
2891
+ scrollToBottom();
2892
+ }, 150);
2846
2893
  }
2847
2894
 
2848
2895
  function handleCompletion() {