lisichatbot 1.4.4 → 1.4.6
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 +94 -22
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -610,7 +610,7 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
610
610
|
el.onclick = (e) => {
|
|
611
611
|
e.stopPropagation();
|
|
612
612
|
e.preventDefault();
|
|
613
|
-
handleOptionClick(el, field, isSingleSelect);
|
|
613
|
+
handleOptionClick(el, field, isSingleSelect, options); // ✅ Pass options
|
|
614
614
|
};
|
|
615
615
|
});
|
|
616
616
|
|
|
@@ -739,7 +739,7 @@ function renderColorOptions(options, field) {
|
|
|
739
739
|
el.onclick = (e) => {
|
|
740
740
|
e.stopPropagation();
|
|
741
741
|
e.preventDefault();
|
|
742
|
-
handleOptionClick(el, field, false);
|
|
742
|
+
handleOptionClick(el, field, false, options); // ✅ Pass options
|
|
743
743
|
};
|
|
744
744
|
});
|
|
745
745
|
|
|
@@ -1555,7 +1555,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1555
1555
|
// OPTION CLICK HANDLER USING CUSTOM ATTRIBUTES
|
|
1556
1556
|
// =============================================================================
|
|
1557
1557
|
|
|
1558
|
-
function handleOptionClick(element, field, isSingleSelect) {
|
|
1558
|
+
function handleOptionClick(element, field, isSingleSelect, options) {
|
|
1559
1559
|
const now = Date.now();
|
|
1560
1560
|
const lastClick = element.getAttribute('data-last-click');
|
|
1561
1561
|
if (lastClick && (now - parseInt(lastClick)) < 300) {
|
|
@@ -1705,24 +1705,35 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
1705
1705
|
console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
1706
1706
|
}
|
|
1707
1707
|
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1708
|
+
// ✅ FIX: Build currentSelection from actual data array, not DOM elements
|
|
1709
|
+
// The DOM might have duplicate/old elements that still have cf-checked class
|
|
1710
|
+
if (!chatState.data[field] || chatState.data[field].length === 0) {
|
|
1711
|
+
// No selections
|
|
1712
|
+
chatState.currentSelection = null;
|
|
1713
|
+
console.log(`📊 No selections - currentSelection set to null`);
|
|
1714
|
+
} else {
|
|
1715
|
+
// Build name from actual data array by finding matching options
|
|
1716
|
+
const selectedNames = chatState.data[field].map(val => {
|
|
1717
|
+
// Find the option config that matches this value
|
|
1718
|
+
const matchingOption = options.find(opt => {
|
|
1719
|
+
const optValue = opt.value !== undefined ? opt.value : opt;
|
|
1720
|
+
return JSON.stringify(optValue) === JSON.stringify(val);
|
|
1721
|
+
});
|
|
1722
|
+
return matchingOption ? (matchingOption.name || matchingOption) : val;
|
|
1723
|
+
}).join(', ');
|
|
1724
|
+
|
|
1725
|
+
chatState.currentSelection = {
|
|
1726
|
+
field,
|
|
1727
|
+
value: chatState.data[field],
|
|
1728
|
+
name: selectedNames || 'None selected'
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
console.log(`📊 Final state after toggle:`, {
|
|
1732
|
+
field,
|
|
1733
|
+
dataValue: chatState.data[field],
|
|
1734
|
+
currentSelectionName: chatState.currentSelection.name
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1726
1737
|
}
|
|
1727
1738
|
|
|
1728
1739
|
enableNextButton();
|
|
@@ -1919,6 +1930,42 @@ async function handleNext() {
|
|
|
1919
1930
|
async function showNextStep() {
|
|
1920
1931
|
const nextStep = flowData.flow[chatState.step];
|
|
1921
1932
|
|
|
1933
|
+
// ✅ NEW: Check if step should be displayed based on condition
|
|
1934
|
+
if (nextStep.shouldDisplay) {
|
|
1935
|
+
let shouldShow = false;
|
|
1936
|
+
|
|
1937
|
+
if (typeof nextStep.shouldDisplay === 'function') {
|
|
1938
|
+
// Custom function
|
|
1939
|
+
try {
|
|
1940
|
+
shouldShow = await nextStep.shouldDisplay(chatState.data);
|
|
1941
|
+
console.log(` 🔍 shouldDisplay function returned: ${shouldShow}`);
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
console.error('Error in shouldDisplay function:', error);
|
|
1944
|
+
shouldShow = false;
|
|
1945
|
+
}
|
|
1946
|
+
} else if (typeof nextStep.shouldDisplay === 'boolean') {
|
|
1947
|
+
// Simple boolean
|
|
1948
|
+
shouldShow = nextStep.shouldDisplay;
|
|
1949
|
+
console.log(` 🔍 shouldDisplay boolean: ${shouldShow}`);
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
if (!shouldShow) {
|
|
1953
|
+
console.log(` ⏭️ Skipping step ${chatState.step} (shouldDisplay returned false)`);
|
|
1954
|
+
chatState.step++;
|
|
1955
|
+
|
|
1956
|
+
if (chatState.step >= flowData.flow.length) {
|
|
1957
|
+
handleCompletion();
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
// Recursively check next step
|
|
1962
|
+
await showNextStep();
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
console.log(` ✅ Displaying step ${chatState.step} (shouldDisplay returned true)`);
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1922
1969
|
if (nextStep.onStart) {
|
|
1923
1970
|
try {
|
|
1924
1971
|
const canStart = await nextStep.onStart(chatState.data);
|
|
@@ -2253,7 +2300,32 @@ function editStep(stepNumber) {
|
|
|
2253
2300
|
console.log(` Clearing history from step ${stepNumber} forward...`);
|
|
2254
2301
|
chatState.history = chatState.history.filter(h => h.step < stepNumber);
|
|
2255
2302
|
|
|
2256
|
-
|
|
2303
|
+
// ✅ Find dependent steps (but don't clear anything)
|
|
2304
|
+
const editedStepField = flowData.flow[stepNumber]?.input?.field;
|
|
2305
|
+
console.log(` 🔗 Checking for steps dependent on: ${editedStepField}`);
|
|
2306
|
+
|
|
2307
|
+
if (editedStepField) {
|
|
2308
|
+
// Find all steps that depend on the edited step
|
|
2309
|
+
const dependentSteps = [];
|
|
2310
|
+
flowData.flow.forEach((step, index) => {
|
|
2311
|
+
if (index > stepNumber && step.dependsOn) {
|
|
2312
|
+
// Check if this step depends on the edited field
|
|
2313
|
+
const dependencies = Array.isArray(step.dependsOn) ? step.dependsOn : [step.dependsOn];
|
|
2314
|
+
|
|
2315
|
+
if (dependencies.includes(editedStepField)) {
|
|
2316
|
+
dependentSteps.push(index);
|
|
2317
|
+
console.log(` 🔗 Found dependent step ${index} (depends on ${editedStepField})`);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
});
|
|
2321
|
+
|
|
2322
|
+
if (dependentSteps.length > 0) {
|
|
2323
|
+
console.log(` ✅ ${dependentSteps.length} dependent steps will be re-shown after editing`);
|
|
2324
|
+
console.log(` ✅ All data, messages, and history kept intact`);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
console.log(` ✅ Keeping ALL data, messages, and history intact for editing`);
|
|
2257
2329
|
console.log(` Current data:`, chatState.data);
|
|
2258
2330
|
|
|
2259
2331
|
console.log(` Calling goToStep(${stepNumber})...`);
|