lisichatbot 1.4.5 ā 1.4.7
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 +130 -15
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1889,24 +1889,78 @@ 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
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1893
|
+
// ā
NEW: Check if there are dependent steps between current and target that should now be shown
|
|
1894
|
+
const currentStepIndex = chatState.step;
|
|
1895
|
+
const editedStepField = flowData.flow[currentStepIndex]?.input?.field;
|
|
1896
|
+
|
|
1897
|
+
console.log(` š Checking for dependent steps between ${currentStepIndex} and ${targetStep}`);
|
|
1898
|
+
|
|
1899
|
+
let nextStepToShow = null;
|
|
1900
|
+
|
|
1901
|
+
// Check all steps between current and target
|
|
1902
|
+
for (let i = currentStepIndex + 1; i < targetStep; i++) {
|
|
1903
|
+
const step = flowData.flow[i];
|
|
1903
1904
|
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1905
|
+
// Check if this step depends on the edited field
|
|
1906
|
+
if (step.dependsOn) {
|
|
1907
|
+
const dependencies = Array.isArray(step.dependsOn) ? step.dependsOn : [step.dependsOn];
|
|
1908
|
+
|
|
1909
|
+
if (dependencies.includes(editedStepField)) {
|
|
1910
|
+
console.log(` š Found dependent step ${i} (depends on ${editedStepField})`);
|
|
1911
|
+
|
|
1912
|
+
// Check if this step should now be displayed
|
|
1913
|
+
if (step.shouldDisplay) {
|
|
1914
|
+
let shouldShow = false;
|
|
1915
|
+
|
|
1916
|
+
if (typeof step.shouldDisplay === 'function') {
|
|
1917
|
+
try {
|
|
1918
|
+
shouldShow = await step.shouldDisplay(chatState.data);
|
|
1919
|
+
console.log(` š Step ${i} shouldDisplay: ${shouldShow}`);
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
console.error(`Error in shouldDisplay for step ${i}:`, error);
|
|
1922
|
+
}
|
|
1923
|
+
} else if (typeof step.shouldDisplay === 'boolean') {
|
|
1924
|
+
shouldShow = step.shouldDisplay;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
if (shouldShow) {
|
|
1928
|
+
console.log(` ā
Step ${i} should now be shown - showing it first`);
|
|
1929
|
+
nextStepToShow = i;
|
|
1930
|
+
break; // Show the first dependent step that should be displayed
|
|
1931
|
+
} else {
|
|
1932
|
+
console.log(` āļø Step ${i} shouldDisplay returned false - skipping`);
|
|
1933
|
+
}
|
|
1934
|
+
} else {
|
|
1935
|
+
// No shouldDisplay means always show
|
|
1936
|
+
console.log(` ā
Step ${i} has no shouldDisplay - showing it`);
|
|
1937
|
+
nextStepToShow = i;
|
|
1938
|
+
break;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
if (nextStepToShow !== null) {
|
|
1945
|
+
// Show the dependent step that should be displayed
|
|
1946
|
+
console.log(` š Showing dependent step ${nextStepToShow} before returning to ${targetStep}`);
|
|
1947
|
+
chatState.step = nextStepToShow;
|
|
1907
1948
|
} else {
|
|
1908
|
-
|
|
1949
|
+
// No dependent steps to show, return to target
|
|
1950
|
+
console.log(` āļø No dependent steps to show, returning directly to step ${targetStep}`);
|
|
1951
|
+
chatState.returnToStep = null;
|
|
1952
|
+
chatState.step = targetStep;
|
|
1909
1953
|
}
|
|
1954
|
+
|
|
1955
|
+
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
1956
|
+
allRangeWrappers.forEach(wrapper => {
|
|
1957
|
+
wrapper.style.display = 'none';
|
|
1958
|
+
});
|
|
1959
|
+
console.log(' š Hidden all range-wrappers');
|
|
1960
|
+
|
|
1961
|
+
updateEditIcons();
|
|
1962
|
+
await showNextStep();
|
|
1963
|
+
return;
|
|
1910
1964
|
}
|
|
1911
1965
|
|
|
1912
1966
|
chatState.step++;
|
|
@@ -1930,6 +1984,42 @@ async function handleNext() {
|
|
|
1930
1984
|
async function showNextStep() {
|
|
1931
1985
|
const nextStep = flowData.flow[chatState.step];
|
|
1932
1986
|
|
|
1987
|
+
// ā
NEW: Check if step should be displayed based on condition
|
|
1988
|
+
if (nextStep.shouldDisplay) {
|
|
1989
|
+
let shouldShow = false;
|
|
1990
|
+
|
|
1991
|
+
if (typeof nextStep.shouldDisplay === 'function') {
|
|
1992
|
+
// Custom function
|
|
1993
|
+
try {
|
|
1994
|
+
shouldShow = await nextStep.shouldDisplay(chatState.data);
|
|
1995
|
+
console.log(` š shouldDisplay function returned: ${shouldShow}`);
|
|
1996
|
+
} catch (error) {
|
|
1997
|
+
console.error('Error in shouldDisplay function:', error);
|
|
1998
|
+
shouldShow = false;
|
|
1999
|
+
}
|
|
2000
|
+
} else if (typeof nextStep.shouldDisplay === 'boolean') {
|
|
2001
|
+
// Simple boolean
|
|
2002
|
+
shouldShow = nextStep.shouldDisplay;
|
|
2003
|
+
console.log(` š shouldDisplay boolean: ${shouldShow}`);
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
if (!shouldShow) {
|
|
2007
|
+
console.log(` āļø Skipping step ${chatState.step} (shouldDisplay returned false)`);
|
|
2008
|
+
chatState.step++;
|
|
2009
|
+
|
|
2010
|
+
if (chatState.step >= flowData.flow.length) {
|
|
2011
|
+
handleCompletion();
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
// Recursively check next step
|
|
2016
|
+
await showNextStep();
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
console.log(` ā
Displaying step ${chatState.step} (shouldDisplay returned true)`);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1933
2023
|
if (nextStep.onStart) {
|
|
1934
2024
|
try {
|
|
1935
2025
|
const canStart = await nextStep.onStart(chatState.data);
|
|
@@ -2264,7 +2354,32 @@ function editStep(stepNumber) {
|
|
|
2264
2354
|
console.log(` Clearing history from step ${stepNumber} forward...`);
|
|
2265
2355
|
chatState.history = chatState.history.filter(h => h.step < stepNumber);
|
|
2266
2356
|
|
|
2267
|
-
|
|
2357
|
+
// ā
Find dependent steps (but don't clear anything)
|
|
2358
|
+
const editedStepField = flowData.flow[stepNumber]?.input?.field;
|
|
2359
|
+
console.log(` š Checking for steps dependent on: ${editedStepField}`);
|
|
2360
|
+
|
|
2361
|
+
if (editedStepField) {
|
|
2362
|
+
// Find all steps that depend on the edited step
|
|
2363
|
+
const dependentSteps = [];
|
|
2364
|
+
flowData.flow.forEach((step, index) => {
|
|
2365
|
+
if (index > stepNumber && step.dependsOn) {
|
|
2366
|
+
// Check if this step depends on the edited field
|
|
2367
|
+
const dependencies = Array.isArray(step.dependsOn) ? step.dependsOn : [step.dependsOn];
|
|
2368
|
+
|
|
2369
|
+
if (dependencies.includes(editedStepField)) {
|
|
2370
|
+
dependentSteps.push(index);
|
|
2371
|
+
console.log(` š Found dependent step ${index} (depends on ${editedStepField})`);
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
});
|
|
2375
|
+
|
|
2376
|
+
if (dependentSteps.length > 0) {
|
|
2377
|
+
console.log(` ā
${dependentSteps.length} dependent steps will be re-shown after editing`);
|
|
2378
|
+
console.log(` ā
All data, messages, and history kept intact`);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
console.log(` ā
Keeping ALL data, messages, and history intact for editing`);
|
|
2268
2383
|
console.log(` Current data:`, chatState.data);
|
|
2269
2384
|
|
|
2270
2385
|
console.log(` Calling goToStep(${stepNumber})...`);
|