lisichatbot 1.4.6 ā 1.4.8
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 +71 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1889,23 +1889,88 @@ async function handleNext() {
|
|
|
1889
1889
|
if (chatState.returnToStep !== null) {
|
|
1890
1890
|
const targetStep = chatState.returnToStep;
|
|
1891
1891
|
console.log(`\nš Returning to saved step ${targetStep} (edited step complete)`);
|
|
1892
|
-
chatState.returnToStep = null;
|
|
1893
1892
|
|
|
1894
|
-
if
|
|
1895
|
-
|
|
1896
|
-
|
|
1893
|
+
// ā
Check if we should continue to next step or jump back
|
|
1894
|
+
const nextStep = chatState.step + 1;
|
|
1895
|
+
|
|
1896
|
+
if (nextStep < targetStep) {
|
|
1897
|
+
// There are steps between current and target
|
|
1898
|
+
const currentStepIndex = chatState.step;
|
|
1899
|
+
const editedStepField = flowData.flow[currentStepIndex]?.input?.field;
|
|
1900
|
+
|
|
1901
|
+
console.log(` š Checking if step ${nextStep} should be shown (between ${currentStepIndex} and ${targetStep})`);
|
|
1902
|
+
|
|
1903
|
+
// Check if the next step depends on the edited field
|
|
1904
|
+
const nextStepConfig = flowData.flow[nextStep];
|
|
1905
|
+
if (nextStepConfig && nextStepConfig.dependsOn) {
|
|
1906
|
+
const dependencies = Array.isArray(nextStepConfig.dependsOn) ? nextStepConfig.dependsOn : [nextStepConfig.dependsOn];
|
|
1907
|
+
|
|
1908
|
+
if (dependencies.includes(editedStepField)) {
|
|
1909
|
+
console.log(` š Step ${nextStep} depends on ${editedStepField} - checking shouldDisplay`);
|
|
1910
|
+
|
|
1911
|
+
// Check shouldDisplay
|
|
1912
|
+
let shouldShow = true; // Default to true if no shouldDisplay
|
|
1913
|
+
|
|
1914
|
+
if (nextStepConfig.shouldDisplay) {
|
|
1915
|
+
if (typeof nextStepConfig.shouldDisplay === 'function') {
|
|
1916
|
+
try {
|
|
1917
|
+
shouldShow = await nextStepConfig.shouldDisplay(chatState.data);
|
|
1918
|
+
console.log(` š Step ${nextStep} shouldDisplay: ${shouldShow}`);
|
|
1919
|
+
} catch (error) {
|
|
1920
|
+
console.error(`Error in shouldDisplay for step ${nextStep}:`, error);
|
|
1921
|
+
shouldShow = false;
|
|
1922
|
+
}
|
|
1923
|
+
} else if (typeof nextStepConfig.shouldDisplay === 'boolean') {
|
|
1924
|
+
shouldShow = nextStepConfig.shouldDisplay;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
if (shouldShow) {
|
|
1929
|
+
// Show this dependent step, keep returnToStep for later
|
|
1930
|
+
console.log(` ā
Step ${nextStep} should be shown - continuing to it (returnToStep=${targetStep} preserved)`);
|
|
1931
|
+
chatState.step = nextStep;
|
|
1932
|
+
|
|
1933
|
+
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
1934
|
+
allRangeWrappers.forEach(wrapper => {
|
|
1935
|
+
wrapper.style.display = 'none';
|
|
1936
|
+
});
|
|
1937
|
+
|
|
1938
|
+
updateEditIcons();
|
|
1939
|
+
await showNextStep();
|
|
1940
|
+
return;
|
|
1941
|
+
} else {
|
|
1942
|
+
console.log(` āļø Step ${nextStep} shouldDisplay returned false - will check next step`);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
// Next step doesn't depend on edited field or shouldn't be shown
|
|
1948
|
+
// Continue to next step normally (it will check shouldDisplay in showNextStep)
|
|
1949
|
+
console.log(` ā”ļø Continuing to next step ${nextStep} (normal flow)`);
|
|
1950
|
+
chatState.step = nextStep;
|
|
1897
1951
|
|
|
1898
1952
|
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
1899
1953
|
allRangeWrappers.forEach(wrapper => {
|
|
1900
1954
|
wrapper.style.display = 'none';
|
|
1901
1955
|
});
|
|
1902
|
-
console.log(' š Hidden all range-wrappers');
|
|
1903
1956
|
|
|
1904
1957
|
updateEditIcons();
|
|
1905
1958
|
await showNextStep();
|
|
1906
1959
|
return;
|
|
1907
1960
|
} else {
|
|
1908
|
-
|
|
1961
|
+
// Reached or passed target, clear returnToStep and go to target
|
|
1962
|
+
console.log(` āļø Reached target, returning to step ${targetStep}`);
|
|
1963
|
+
chatState.returnToStep = null;
|
|
1964
|
+
chatState.step = targetStep;
|
|
1965
|
+
|
|
1966
|
+
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
1967
|
+
allRangeWrappers.forEach(wrapper => {
|
|
1968
|
+
wrapper.style.display = 'none';
|
|
1969
|
+
});
|
|
1970
|
+
|
|
1971
|
+
updateEditIcons();
|
|
1972
|
+
await showNextStep();
|
|
1973
|
+
return;
|
|
1909
1974
|
}
|
|
1910
1975
|
}
|
|
1911
1976
|
|