lisichatbot 1.6.0 → 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.
- package/package.json +1 -1
- package/src/index.js +99 -34
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -49,9 +49,14 @@ let flowData = null;
|
|
|
49
49
|
|
|
50
50
|
function scrollToBottom() {
|
|
51
51
|
if (elements.messages) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
|
@@ -293,7 +298,8 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
293
298
|
// ✅ Get existing data for pre-filling (edit mode)
|
|
294
299
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
295
300
|
const currentStep = flowData.flow[chatState.step];
|
|
296
|
-
const
|
|
301
|
+
const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
|
|
302
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
|
|
297
303
|
|
|
298
304
|
const existingData = disablePrefill ? [] : (chatState.data[field] || []);
|
|
299
305
|
const selectedValues = new Set(existingData);
|
|
@@ -301,8 +307,8 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
301
307
|
if (disablePrefill) {
|
|
302
308
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
303
309
|
} else {
|
|
304
|
-
if (
|
|
305
|
-
console.log(` 🔓 Pre-fill override active
|
|
310
|
+
if (hasOverride) {
|
|
311
|
+
console.log(` 🔓 Pre-fill override active for ${field}:`, Array.from(selectedValues));
|
|
306
312
|
} else {
|
|
307
313
|
console.log(`📝 Pre-filling selections for ${field}:`, Array.from(selectedValues));
|
|
308
314
|
}
|
|
@@ -556,15 +562,16 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
556
562
|
|
|
557
563
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
558
564
|
const currentStep = flowData.flow[chatState.step];
|
|
559
|
-
const
|
|
565
|
+
const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
|
|
566
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
|
|
560
567
|
|
|
561
568
|
const existingData = disablePrefill ? (isSingleSelect ? null : []) : chatState.data[field];
|
|
562
569
|
|
|
563
570
|
if (disablePrefill) {
|
|
564
571
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
565
572
|
} else {
|
|
566
|
-
if (
|
|
567
|
-
console.log(` 🔓 Pre-fill override active
|
|
573
|
+
if (hasOverride) {
|
|
574
|
+
console.log(` 🔓 Pre-fill override active for ${field}:`, existingData);
|
|
568
575
|
} else {
|
|
569
576
|
console.log(`📝 Pre-filling ${field}:`, existingData);
|
|
570
577
|
}
|
|
@@ -694,15 +701,16 @@ function renderColorOptions(options, field) {
|
|
|
694
701
|
|
|
695
702
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
696
703
|
const currentStep = flowData.flow[chatState.step];
|
|
697
|
-
const
|
|
704
|
+
const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
|
|
705
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
|
|
698
706
|
|
|
699
707
|
const existingData = disablePrefill ? [] : chatState.data[field];
|
|
700
708
|
|
|
701
709
|
if (disablePrefill) {
|
|
702
710
|
console.log(`⏭️ Pre-fill disabled for ${field} (color) - starting fresh`);
|
|
703
711
|
} else {
|
|
704
|
-
if (
|
|
705
|
-
console.log(` 🔓 Pre-fill override active
|
|
712
|
+
if (hasOverride) {
|
|
713
|
+
console.log(` 🔓 Pre-fill override active for ${field} (color):`, existingData);
|
|
706
714
|
} else {
|
|
707
715
|
console.log(`📝 Pre-filling ${field} (color):`, existingData);
|
|
708
716
|
}
|
|
@@ -829,15 +837,16 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
829
837
|
|
|
830
838
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
831
839
|
const currentStep = flowData.flow[chatState.step];
|
|
832
|
-
const
|
|
840
|
+
const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
|
|
841
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
|
|
833
842
|
|
|
834
843
|
const existingData = disablePrefill ? null : chatState.data[field];
|
|
835
844
|
|
|
836
845
|
if (disablePrefill) {
|
|
837
846
|
console.log(`⏭️ Pre-fill disabled for ${field} (custom) - starting fresh`);
|
|
838
847
|
} else {
|
|
839
|
-
if (
|
|
840
|
-
console.log(` 🔓 Pre-fill override active
|
|
848
|
+
if (hasOverride) {
|
|
849
|
+
console.log(` 🔓 Pre-fill override active for ${field} (custom):`, existingData);
|
|
841
850
|
} else {
|
|
842
851
|
console.log(`📝 Pre-filling ${field} (custom):`, existingData);
|
|
843
852
|
}
|
|
@@ -1455,15 +1464,16 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1455
1464
|
|
|
1456
1465
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
1457
1466
|
const currentStep = flowData.flow[chatState.step];
|
|
1458
|
-
const
|
|
1467
|
+
const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
|
|
1468
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
|
|
1459
1469
|
|
|
1460
1470
|
const existingValue = disablePrefill ? null : chatState.data[field];
|
|
1461
1471
|
|
|
1462
1472
|
if (disablePrefill) {
|
|
1463
1473
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
1464
1474
|
} else {
|
|
1465
|
-
if (
|
|
1466
|
-
console.log(` 🔓 Pre-fill override active
|
|
1475
|
+
if (hasOverride) {
|
|
1476
|
+
console.log(` 🔓 Pre-fill override active for ${field}:`, existingValue);
|
|
1467
1477
|
} else {
|
|
1468
1478
|
console.log(`📝 Pre-filling ${field}:`, existingValue);
|
|
1469
1479
|
}
|
|
@@ -2001,6 +2011,10 @@ async function handleNext() {
|
|
|
2001
2011
|
console.log('💬 showMessage called:', message);
|
|
2002
2012
|
addMessage(message, 'bot', false, null);
|
|
2003
2013
|
scrollToBottom();
|
|
2014
|
+
// ✅ Delayed scroll to ensure message is fully rendered
|
|
2015
|
+
setTimeout(() => {
|
|
2016
|
+
scrollToBottom();
|
|
2017
|
+
}, 100);
|
|
2004
2018
|
};
|
|
2005
2019
|
|
|
2006
2020
|
// ✅ Pass showMessage as third parameter
|
|
@@ -2015,6 +2029,10 @@ async function handleNext() {
|
|
|
2015
2029
|
console.log('💬 onNext displaying message from return:', result.showMessage);
|
|
2016
2030
|
addMessage(result.showMessage, 'bot', false, null);
|
|
2017
2031
|
scrollToBottom();
|
|
2032
|
+
// ✅ Delayed scroll to ensure message is fully rendered
|
|
2033
|
+
setTimeout(() => {
|
|
2034
|
+
scrollToBottom();
|
|
2035
|
+
}, 100);
|
|
2018
2036
|
}
|
|
2019
2037
|
|
|
2020
2038
|
// ✅ NEW: Check if onNext wants to update steps by field name
|
|
@@ -2091,8 +2109,9 @@ async function handleNext() {
|
|
|
2091
2109
|
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2092
2110
|
});
|
|
2093
2111
|
|
|
2094
|
-
// ✅ Store
|
|
2095
|
-
chatState.
|
|
2112
|
+
// ✅ Store which fields should override disableInputValuePrefill
|
|
2113
|
+
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2114
|
+
console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
|
|
2096
2115
|
}
|
|
2097
2116
|
|
|
2098
2117
|
chatState.step = targetStepIndex;
|
|
@@ -2122,8 +2141,9 @@ async function handleNext() {
|
|
|
2122
2141
|
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2123
2142
|
});
|
|
2124
2143
|
|
|
2125
|
-
// ✅ Store
|
|
2126
|
-
chatState.
|
|
2144
|
+
// ✅ Store which fields should override disableInputValuePrefill
|
|
2145
|
+
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2146
|
+
console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
|
|
2127
2147
|
}
|
|
2128
2148
|
|
|
2129
2149
|
chatState.step = targetStep;
|
|
@@ -2336,7 +2356,8 @@ async function handleNext() {
|
|
|
2336
2356
|
}
|
|
2337
2357
|
}
|
|
2338
2358
|
|
|
2339
|
-
|
|
2359
|
+
// ✅ NEW: Find next accessible step (skip accessibleViaJumpOnly steps)
|
|
2360
|
+
chatState.step = findNextAccessibleStep(chatState.step);
|
|
2340
2361
|
|
|
2341
2362
|
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
2342
2363
|
allRangeWrappers.forEach(wrapper => {
|
|
@@ -2354,6 +2375,24 @@ async function handleNext() {
|
|
|
2354
2375
|
await showNextStep();
|
|
2355
2376
|
}
|
|
2356
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
|
+
|
|
2357
2396
|
async function showNextStep() {
|
|
2358
2397
|
const nextStep = flowData.flow[chatState.step];
|
|
2359
2398
|
|
|
@@ -2400,6 +2439,10 @@ async function showNextStep() {
|
|
|
2400
2439
|
console.log('💬 showMessage called:', message);
|
|
2401
2440
|
addMessage(message, 'bot', false, null);
|
|
2402
2441
|
scrollToBottom();
|
|
2442
|
+
// ✅ Delayed scroll to ensure message is fully rendered
|
|
2443
|
+
setTimeout(() => {
|
|
2444
|
+
scrollToBottom();
|
|
2445
|
+
}, 100);
|
|
2403
2446
|
};
|
|
2404
2447
|
|
|
2405
2448
|
// ✅ Pass showMessage as second parameter
|
|
@@ -2410,6 +2453,10 @@ async function showNextStep() {
|
|
|
2410
2453
|
console.log('💬 onStart displaying message from return:', result.showMessage);
|
|
2411
2454
|
addMessage(result.showMessage, 'bot', false, null);
|
|
2412
2455
|
scrollToBottom();
|
|
2456
|
+
// ✅ Delayed scroll to ensure message is fully rendered
|
|
2457
|
+
setTimeout(() => {
|
|
2458
|
+
scrollToBottom();
|
|
2459
|
+
}, 100);
|
|
2413
2460
|
}
|
|
2414
2461
|
|
|
2415
2462
|
// ✅ NEW: Check if onStart wants to update steps by field name
|
|
@@ -2580,8 +2627,9 @@ async function showNextStep() {
|
|
|
2580
2627
|
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2581
2628
|
});
|
|
2582
2629
|
|
|
2583
|
-
// ✅ Store
|
|
2584
|
-
chatState.
|
|
2630
|
+
// ✅ Store which fields should override disableInputValuePrefill
|
|
2631
|
+
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2632
|
+
console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
|
|
2585
2633
|
}
|
|
2586
2634
|
|
|
2587
2635
|
chatState.step = targetStepIndex;
|
|
@@ -2611,8 +2659,9 @@ async function showNextStep() {
|
|
|
2611
2659
|
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2612
2660
|
});
|
|
2613
2661
|
|
|
2614
|
-
// ✅ Store
|
|
2615
|
-
chatState.
|
|
2662
|
+
// ✅ Store which fields should override disableInputValuePrefill
|
|
2663
|
+
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2664
|
+
console.log(` 🔓 Override active for fields:`, chatState.prefillOverrideFields);
|
|
2616
2665
|
}
|
|
2617
2666
|
|
|
2618
2667
|
chatState.step = targetStep;
|
|
@@ -2628,7 +2677,8 @@ async function showNextStep() {
|
|
|
2628
2677
|
// ✅ NEW: Check if onStart wants to block this step and skip to next
|
|
2629
2678
|
if (result && typeof result === 'object' && result.blockStep === true) {
|
|
2630
2679
|
console.log('⏭️ Step blocked by onStart - skipping to next step');
|
|
2631
|
-
|
|
2680
|
+
// ✅ NEW: Find next accessible step
|
|
2681
|
+
chatState.step = findNextAccessibleStep(chatState.step);
|
|
2632
2682
|
|
|
2633
2683
|
if (chatState.step >= flowData.flow.length) {
|
|
2634
2684
|
handleCompletion();
|
|
@@ -2776,7 +2826,8 @@ async function showNextStep() {
|
|
|
2776
2826
|
console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
|
|
2777
2827
|
|
|
2778
2828
|
setTimeout(() => {
|
|
2779
|
-
|
|
2829
|
+
// ✅ NEW: Find next accessible step
|
|
2830
|
+
chatState.step = findNextAccessibleStep(chatState.step);
|
|
2780
2831
|
updateEditIcons();
|
|
2781
2832
|
|
|
2782
2833
|
if (chatState.step < flowData.flow.length) {
|
|
@@ -2815,16 +2866,30 @@ async function showNextStep() {
|
|
|
2815
2866
|
}
|
|
2816
2867
|
}
|
|
2817
2868
|
|
|
2818
|
-
// ✅
|
|
2819
|
-
// This ensures
|
|
2820
|
-
if (chatState.
|
|
2821
|
-
|
|
2822
|
-
chatState.
|
|
2869
|
+
// ✅ Remove current field from prefillOverride list after rendering
|
|
2870
|
+
// This ensures override only applies to fields specified in prefillData
|
|
2871
|
+
if (chatState.prefillOverrideFields && chatState.prefillOverrideFields.length > 0) {
|
|
2872
|
+
const currentField = nextStep.input?.field;
|
|
2873
|
+
if (currentField && chatState.prefillOverrideFields.includes(currentField)) {
|
|
2874
|
+
chatState.prefillOverrideFields = chatState.prefillOverrideFields.filter(f => f !== currentField);
|
|
2875
|
+
console.log(` 🔓 Removed ${currentField} from override list. Remaining:`, chatState.prefillOverrideFields);
|
|
2876
|
+
|
|
2877
|
+
// Clear the list entirely if empty
|
|
2878
|
+
if (chatState.prefillOverrideFields.length === 0) {
|
|
2879
|
+
console.log(` 🔓 All override fields processed - clearing list`);
|
|
2880
|
+
delete chatState.prefillOverrideFields;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2823
2883
|
}
|
|
2824
2884
|
|
|
2825
2885
|
setTimeout(() => {
|
|
2826
2886
|
updateEditIcons();
|
|
2827
2887
|
}, 10);
|
|
2888
|
+
|
|
2889
|
+
// ✅ NEW: Delayed scroll to ensure inputs are fully rendered and visible
|
|
2890
|
+
setTimeout(() => {
|
|
2891
|
+
scrollToBottom();
|
|
2892
|
+
}, 150);
|
|
2828
2893
|
}
|
|
2829
2894
|
|
|
2830
2895
|
function handleCompletion() {
|