lisichatbot 1.5.8 → 1.6.0
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 +160 -11
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -293,7 +293,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
293
293
|
// ✅ Get existing data for pre-filling (edit mode)
|
|
294
294
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
295
295
|
const currentStep = flowData.flow[chatState.step];
|
|
296
|
-
const disablePrefill = currentStep?.disableInputValuePrefill === true;
|
|
296
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !chatState.prefillOverride;
|
|
297
297
|
|
|
298
298
|
const existingData = disablePrefill ? [] : (chatState.data[field] || []);
|
|
299
299
|
const selectedValues = new Set(existingData);
|
|
@@ -301,7 +301,11 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
301
301
|
if (disablePrefill) {
|
|
302
302
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
303
303
|
} else {
|
|
304
|
-
|
|
304
|
+
if (chatState.prefillOverride) {
|
|
305
|
+
console.log(` 🔓 Pre-fill override active - filling ${field}:`, Array.from(selectedValues));
|
|
306
|
+
} else {
|
|
307
|
+
console.log(`📝 Pre-filling selections for ${field}:`, Array.from(selectedValues));
|
|
308
|
+
}
|
|
305
309
|
}
|
|
306
310
|
|
|
307
311
|
const allOptions = [];
|
|
@@ -552,14 +556,18 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
552
556
|
|
|
553
557
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
554
558
|
const currentStep = flowData.flow[chatState.step];
|
|
555
|
-
const disablePrefill = currentStep?.disableInputValuePrefill === true;
|
|
559
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !chatState.prefillOverride;
|
|
556
560
|
|
|
557
561
|
const existingData = disablePrefill ? (isSingleSelect ? null : []) : chatState.data[field];
|
|
558
562
|
|
|
559
563
|
if (disablePrefill) {
|
|
560
564
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
561
565
|
} else {
|
|
562
|
-
|
|
566
|
+
if (chatState.prefillOverride) {
|
|
567
|
+
console.log(` 🔓 Pre-fill override active - filling ${field}:`, existingData);
|
|
568
|
+
} else {
|
|
569
|
+
console.log(`📝 Pre-filling ${field}:`, existingData);
|
|
570
|
+
}
|
|
563
571
|
}
|
|
564
572
|
|
|
565
573
|
const optionsWrapper = document.createElement('div');
|
|
@@ -686,14 +694,18 @@ function renderColorOptions(options, field) {
|
|
|
686
694
|
|
|
687
695
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
688
696
|
const currentStep = flowData.flow[chatState.step];
|
|
689
|
-
const disablePrefill = currentStep?.disableInputValuePrefill === true;
|
|
697
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !chatState.prefillOverride;
|
|
690
698
|
|
|
691
699
|
const existingData = disablePrefill ? [] : chatState.data[field];
|
|
692
700
|
|
|
693
701
|
if (disablePrefill) {
|
|
694
702
|
console.log(`⏭️ Pre-fill disabled for ${field} (color) - starting fresh`);
|
|
695
703
|
} else {
|
|
696
|
-
|
|
704
|
+
if (chatState.prefillOverride) {
|
|
705
|
+
console.log(` 🔓 Pre-fill override active - filling ${field} (color):`, existingData);
|
|
706
|
+
} else {
|
|
707
|
+
console.log(`📝 Pre-filling ${field} (color):`, existingData);
|
|
708
|
+
}
|
|
697
709
|
}
|
|
698
710
|
|
|
699
711
|
const optionsWrapper = document.createElement('div');
|
|
@@ -817,14 +829,18 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
817
829
|
|
|
818
830
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
819
831
|
const currentStep = flowData.flow[chatState.step];
|
|
820
|
-
const disablePrefill = currentStep?.disableInputValuePrefill === true;
|
|
832
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !chatState.prefillOverride;
|
|
821
833
|
|
|
822
834
|
const existingData = disablePrefill ? null : chatState.data[field];
|
|
823
835
|
|
|
824
836
|
if (disablePrefill) {
|
|
825
837
|
console.log(`⏭️ Pre-fill disabled for ${field} (custom) - starting fresh`);
|
|
826
838
|
} else {
|
|
827
|
-
|
|
839
|
+
if (chatState.prefillOverride) {
|
|
840
|
+
console.log(` 🔓 Pre-fill override active - filling ${field} (custom):`, existingData);
|
|
841
|
+
} else {
|
|
842
|
+
console.log(`📝 Pre-filling ${field} (custom):`, existingData);
|
|
843
|
+
}
|
|
828
844
|
}
|
|
829
845
|
|
|
830
846
|
const optionsWrapper = document.createElement('div');
|
|
@@ -1439,14 +1455,18 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1439
1455
|
|
|
1440
1456
|
// ✅ NEW: Check if prefill is disabled for this step
|
|
1441
1457
|
const currentStep = flowData.flow[chatState.step];
|
|
1442
|
-
const disablePrefill = currentStep?.disableInputValuePrefill === true;
|
|
1458
|
+
const disablePrefill = currentStep?.disableInputValuePrefill === true && !chatState.prefillOverride;
|
|
1443
1459
|
|
|
1444
1460
|
const existingValue = disablePrefill ? null : chatState.data[field];
|
|
1445
1461
|
|
|
1446
1462
|
if (disablePrefill) {
|
|
1447
1463
|
console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
|
|
1448
1464
|
} else {
|
|
1449
|
-
|
|
1465
|
+
if (chatState.prefillOverride) {
|
|
1466
|
+
console.log(` 🔓 Pre-fill override active - filling ${field}:`, existingValue);
|
|
1467
|
+
} else {
|
|
1468
|
+
console.log(`📝 Pre-filling ${field}:`, existingValue);
|
|
1469
|
+
}
|
|
1450
1470
|
}
|
|
1451
1471
|
|
|
1452
1472
|
const hasValidation = inputType === 'number' &&
|
|
@@ -2051,6 +2071,40 @@ async function handleNext() {
|
|
|
2051
2071
|
});
|
|
2052
2072
|
}
|
|
2053
2073
|
|
|
2074
|
+
// ✅ NEW: Check if onNext wants to jump to step by name
|
|
2075
|
+
if (result && typeof result === 'object' && result.goToStepName) {
|
|
2076
|
+
console.log(`🎯 onNext requested jump to step name: "${result.goToStepName}"`);
|
|
2077
|
+
|
|
2078
|
+
const stepName = result.goToStepName;
|
|
2079
|
+
const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
|
|
2080
|
+
|
|
2081
|
+
if (targetStepIndex !== -1) {
|
|
2082
|
+
console.log(` ✅ Found step "${stepName}" at index ${targetStepIndex}`);
|
|
2083
|
+
|
|
2084
|
+
// ✅ NEW: Handle prefillData to override disableInputValuePrefill
|
|
2085
|
+
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2086
|
+
console.log(` 📝 Pre-filling data for jump:`, result.prefillData);
|
|
2087
|
+
|
|
2088
|
+
// Merge prefillData into chatState.data
|
|
2089
|
+
Object.keys(result.prefillData).forEach(key => {
|
|
2090
|
+
chatState.data[key] = result.prefillData[key];
|
|
2091
|
+
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2092
|
+
});
|
|
2093
|
+
|
|
2094
|
+
// ✅ Store prefill override flag
|
|
2095
|
+
chatState.prefillOverride = true;
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
chatState.step = targetStepIndex;
|
|
2099
|
+
chatState.currentSelection = null;
|
|
2100
|
+
disableNextButton();
|
|
2101
|
+
await showNextStep();
|
|
2102
|
+
return;
|
|
2103
|
+
} else {
|
|
2104
|
+
console.error(`❌ No step found with name: "${stepName}"`);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2054
2108
|
// ✅ NEW: Check if onNext wants to jump to a specific step
|
|
2055
2109
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
2056
2110
|
console.log(`🎯 onNext requested jump to step ${result.goToStep}`);
|
|
@@ -2058,6 +2112,20 @@ async function handleNext() {
|
|
|
2058
2112
|
const targetStep = result.goToStep;
|
|
2059
2113
|
|
|
2060
2114
|
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
2115
|
+
// ✅ NEW: Handle prefillData to override disableInputValuePrefill
|
|
2116
|
+
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2117
|
+
console.log(` 📝 Pre-filling data for jump:`, result.prefillData);
|
|
2118
|
+
|
|
2119
|
+
// Merge prefillData into chatState.data
|
|
2120
|
+
Object.keys(result.prefillData).forEach(key => {
|
|
2121
|
+
chatState.data[key] = result.prefillData[key];
|
|
2122
|
+
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2123
|
+
});
|
|
2124
|
+
|
|
2125
|
+
// ✅ Store prefill override flag
|
|
2126
|
+
chatState.prefillOverride = true;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2061
2129
|
chatState.step = targetStep;
|
|
2062
2130
|
chatState.currentSelection = null;
|
|
2063
2131
|
disableNextButton();
|
|
@@ -2492,6 +2560,40 @@ async function showNextStep() {
|
|
|
2492
2560
|
}
|
|
2493
2561
|
}
|
|
2494
2562
|
|
|
2563
|
+
// ✅ NEW: Check if onStart wants to jump to step by name
|
|
2564
|
+
if (result && typeof result === 'object' && result.goToStepName) {
|
|
2565
|
+
console.log(`🎯 onStart requested jump to step name: "${result.goToStepName}"`);
|
|
2566
|
+
|
|
2567
|
+
const stepName = result.goToStepName;
|
|
2568
|
+
const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
|
|
2569
|
+
|
|
2570
|
+
if (targetStepIndex !== -1) {
|
|
2571
|
+
console.log(` ✅ Found step "${stepName}" at index ${targetStepIndex}`);
|
|
2572
|
+
|
|
2573
|
+
// ✅ NEW: Handle prefillData to override disableInputValuePrefill
|
|
2574
|
+
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2575
|
+
console.log(` 📝 Pre-filling data for jump:`, result.prefillData);
|
|
2576
|
+
|
|
2577
|
+
// Merge prefillData into chatState.data
|
|
2578
|
+
Object.keys(result.prefillData).forEach(key => {
|
|
2579
|
+
chatState.data[key] = result.prefillData[key];
|
|
2580
|
+
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2581
|
+
});
|
|
2582
|
+
|
|
2583
|
+
// ✅ Store prefill override flag
|
|
2584
|
+
chatState.prefillOverride = true;
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
chatState.step = targetStepIndex;
|
|
2588
|
+
chatState.currentSelection = null;
|
|
2589
|
+
disableNextButton();
|
|
2590
|
+
await showNextStep();
|
|
2591
|
+
return;
|
|
2592
|
+
} else {
|
|
2593
|
+
console.error(`❌ No step found with name: "${stepName}"`);
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2495
2597
|
// ✅ NEW: Check if onStart wants to jump to a specific step
|
|
2496
2598
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
2497
2599
|
console.log(`🎯 onStart requested jump to step ${result.goToStep}`);
|
|
@@ -2499,6 +2601,20 @@ async function showNextStep() {
|
|
|
2499
2601
|
const targetStep = result.goToStep;
|
|
2500
2602
|
|
|
2501
2603
|
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
2604
|
+
// ✅ NEW: Handle prefillData to override disableInputValuePrefill
|
|
2605
|
+
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2606
|
+
console.log(` 📝 Pre-filling data for jump:`, result.prefillData);
|
|
2607
|
+
|
|
2608
|
+
// Merge prefillData into chatState.data
|
|
2609
|
+
Object.keys(result.prefillData).forEach(key => {
|
|
2610
|
+
chatState.data[key] = result.prefillData[key];
|
|
2611
|
+
console.log(` → Set ${key}:`, result.prefillData[key]);
|
|
2612
|
+
});
|
|
2613
|
+
|
|
2614
|
+
// ✅ Store prefill override flag
|
|
2615
|
+
chatState.prefillOverride = true;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2502
2618
|
chatState.step = targetStep;
|
|
2503
2619
|
chatState.currentSelection = null;
|
|
2504
2620
|
disableNextButton();
|
|
@@ -2549,7 +2665,33 @@ async function showNextStep() {
|
|
|
2549
2665
|
});
|
|
2550
2666
|
|
|
2551
2667
|
const hasInput = !!nextStep.input;
|
|
2552
|
-
|
|
2668
|
+
|
|
2669
|
+
// ✅ NEW: Support dynamic messages
|
|
2670
|
+
let messageToDisplay = nextStep.message;
|
|
2671
|
+
|
|
2672
|
+
if (typeof nextStep.message === 'function') {
|
|
2673
|
+
// ✅ Message as function: message: (data) => `Hello ${data.name}`
|
|
2674
|
+
try {
|
|
2675
|
+
messageToDisplay = nextStep.message(chatState.data);
|
|
2676
|
+
console.log(` 💬 Dynamic message (function): "${messageToDisplay}"`);
|
|
2677
|
+
} catch (error) {
|
|
2678
|
+
console.error('Error in message function:', error);
|
|
2679
|
+
messageToDisplay = 'Error loading message';
|
|
2680
|
+
}
|
|
2681
|
+
} else if (typeof nextStep.message === 'string' && nextStep.message.includes('${')) {
|
|
2682
|
+
// ✅ Message with template variables: message: "Hello ${name}"
|
|
2683
|
+
try {
|
|
2684
|
+
// Create function from template string
|
|
2685
|
+
const templateFunc = new Function('data', `return \`${nextStep.message}\`;`);
|
|
2686
|
+
messageToDisplay = templateFunc(chatState.data);
|
|
2687
|
+
console.log(` 💬 Dynamic message (template): "${messageToDisplay}"`);
|
|
2688
|
+
} catch (error) {
|
|
2689
|
+
console.error('Error parsing template message:', error);
|
|
2690
|
+
messageToDisplay = nextStep.message; // Fallback to original
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
addMessage(messageToDisplay, 'bot', hasInput, chatState.step);
|
|
2553
2695
|
|
|
2554
2696
|
const inputRequired = nextStep.inputRequired === true;
|
|
2555
2697
|
|
|
@@ -2673,6 +2815,13 @@ async function showNextStep() {
|
|
|
2673
2815
|
}
|
|
2674
2816
|
}
|
|
2675
2817
|
|
|
2818
|
+
// ✅ Clear prefillOverride flag after rendering this step
|
|
2819
|
+
// This ensures it only applies to the first step after goToStep with prefillData
|
|
2820
|
+
if (chatState.prefillOverride) {
|
|
2821
|
+
console.log(` 🔓 Clearing prefill override flag`);
|
|
2822
|
+
chatState.prefillOverride = false;
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2676
2825
|
setTimeout(() => {
|
|
2677
2826
|
updateEditIcons();
|
|
2678
2827
|
}, 10);
|