lisichatbot 2.2.1 → 2.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +24 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -2709,6 +2709,18 @@ async function handleNext() {
2709
2709
  }
2710
2710
 
2711
2711
  if (shouldShow) {
2712
+ // Remove stale selections that no longer exist in the new options
2713
+ const dependentField = nextStepConfig?.input?.field;
2714
+ if (dependentField && chatState.data[dependentField] !== undefined) {
2715
+ const validOptions = (nextStepConfig.input?.options || []).map(o => o.value);
2716
+ const currentValue = chatState.data[dependentField];
2717
+ if (Array.isArray(currentValue)) {
2718
+ const filtered = currentValue.filter(v => validOptions.includes(v));
2719
+ chatState.data[dependentField] = filtered.length > 0 ? filtered : undefined;
2720
+ } else if (!validOptions.includes(currentValue)) {
2721
+ delete chatState.data[dependentField];
2722
+ }
2723
+ }
2712
2724
  // Show this dependent step, keep returnToStep for later
2713
2725
  // console.log(` ✅ Step ${nextStep} should be shown - continuing to it (returnToStep=${targetStep} preserved)`);
2714
2726
  chatState.step = nextStep;
@@ -2728,17 +2740,23 @@ async function handleNext() {
2728
2740
  }
2729
2741
 
2730
2742
  // Next step doesn't depend on edited field or shouldn't be shown
2731
- // Continue to next step normally (it will check shouldDisplay in showNextStep)
2732
- // console.log(` ➡️ Continuing to next step ${nextStep} (normal flow)`);
2733
- chatState.step = nextStep;
2734
-
2743
+ // Jump back to the target step instead of continuing forward
2744
+ chatState.returnToStep = null;
2745
+ chatState.editPath = [];
2746
+ chatState.step = targetStep;
2747
+
2735
2748
  const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
2736
2749
  allRangeWrappers.forEach(wrapper => {
2737
2750
  wrapper.style.display = 'none';
2738
2751
  });
2739
-
2752
+
2740
2753
  updateEditIcons();
2741
- await showNextStep();
2754
+
2755
+ if (chatState.step >= flowData.flow.length) {
2756
+ handleCompletion();
2757
+ } else {
2758
+ await showNextStep();
2759
+ }
2742
2760
  return;
2743
2761
  } else {
2744
2762
  // Reached or passed target