lisichatbot 2.0.8 → 2.0.9

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 +37 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -320,8 +320,9 @@ function renderMultiSelectDropdown(options, field) {
320
320
  // ✅ NEW: Check if prefill is disabled for this step
321
321
  const currentStep = flowData.flow[chatState.step];
322
322
  const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
323
- const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
324
-
323
+ const isEditing = chatState.returnToStep !== null && chatState.returnToStep !== undefined;
324
+ const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
325
+
325
326
  const existingData = disablePrefill ? [] : (chatState.data[field] || []);
326
327
  const selectedValues = new Set(existingData);
327
328
 
@@ -621,14 +622,15 @@ function renderOptions(options, field, isSingleSelect = true) {
621
622
  // ✅ NEW: Check if prefill is disabled for this step
622
623
  const currentStep = flowData.flow[chatState.step];
623
624
  const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
624
- const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
625
-
625
+ const isEditing = chatState.returnToStep !== null && chatState.returnToStep !== undefined;
626
+ const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
627
+
626
628
  const existingData = disablePrefill ? (isSingleSelect ? null : []) : chatState.data[field];
627
-
629
+
628
630
  if (disablePrefill) {
629
631
  console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
630
632
  } else {
631
- if (hasOverride) {
633
+ if (hasOverride || isEditing) {
632
634
  console.log(` 🔓 Pre-fill override active for ${field}:`, existingData);
633
635
  } else {
634
636
  console.log(`📝 Pre-filling ${field}:`, existingData);
@@ -761,14 +763,15 @@ function renderColorOptions(options, field) {
761
763
  // ✅ NEW: Check if prefill is disabled for this step
762
764
  const currentStep = flowData.flow[chatState.step];
763
765
  const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
764
- const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
765
-
766
+ const isEditing = chatState.returnToStep !== null && chatState.returnToStep !== undefined;
767
+ const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
768
+
766
769
  const existingData = disablePrefill ? [] : chatState.data[field];
767
-
770
+
768
771
  if (disablePrefill) {
769
772
  console.log(`⏭️ Pre-fill disabled for ${field} (color) - starting fresh`);
770
773
  } else {
771
- if (hasOverride) {
774
+ if (hasOverride || isEditing) {
772
775
  console.log(` 🔓 Pre-fill override active for ${field} (color):`, existingData);
773
776
  } else {
774
777
  console.log(`📝 Pre-filling ${field} (color):`, existingData);
@@ -898,12 +901,14 @@ function renderCustomSelectOptions(options, field, customConfig) {
898
901
  // ✅ NEW: Check if prefill is disabled for this step
899
902
  const currentStep = flowData.flow[chatState.step];
900
903
  const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
901
- const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
902
-
904
+ const isEditing = chatState.returnToStep !== null && chatState.returnToStep !== undefined;
905
+ const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
906
+
903
907
  console.log(`\n🔍 === PREFILL DEBUG for field: ${field} ===`);
904
908
  console.log(` disableInputValuePrefill:`, currentStep?.disableInputValuePrefill);
905
909
  console.log(` prefillOverrideFields:`, chatState.prefillOverrideFields);
906
910
  console.log(` hasOverride:`, hasOverride);
911
+ console.log(` isEditing:`, isEditing);
907
912
  console.log(` disablePrefill:`, disablePrefill);
908
913
  console.log(` chatState.data[${field}]:`, chatState.data[field]);
909
914
 
@@ -1076,7 +1081,7 @@ function renderCustomSelectOptions(options, field, customConfig) {
1076
1081
  // ✅ FIX: Enable Next button if option is pre-selected
1077
1082
  if (hasPreselectedOption) {
1078
1083
  // Set currentSelection
1079
- const isCustomSelected = Array.isArray(existingData) && existingData.length === 2;
1084
+ const isCustomSelected = Array.isArray(existingData) && existingData.length === 2 && !hasMatchingNormalOption;
1080
1085
 
1081
1086
  if (isCustomSelected) {
1082
1087
  // Custom range selected - currentSelection will be set by validateMinMax
@@ -1687,8 +1692,9 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1687
1692
  // ✅ NEW: Check if prefill is disabled for this step
1688
1693
  const currentStep = flowData.flow[chatState.step];
1689
1694
  const hasOverride = chatState.prefillOverrideFields && chatState.prefillOverrideFields.includes(field);
1690
- const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride;
1691
-
1695
+ const isEditing = chatState.returnToStep !== null && chatState.returnToStep !== undefined;
1696
+ const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
1697
+
1692
1698
  const existingValue = disablePrefill ? null : chatState.data[field];
1693
1699
 
1694
1700
  if (disablePrefill) {
@@ -2642,7 +2648,12 @@ async function handleNext() {
2642
2648
  });
2643
2649
 
2644
2650
  updateEditIcons();
2645
- await showNextStep();
2651
+
2652
+ if (chatState.step >= flowData.flow.length) {
2653
+ handleCompletion();
2654
+ } else {
2655
+ await showNextStep();
2656
+ }
2646
2657
  return;
2647
2658
  }
2648
2659
  }
@@ -2689,6 +2700,12 @@ function findNextAccessibleStep(currentStep) {
2689
2700
  }
2690
2701
 
2691
2702
  async function showNextStep() {
2703
+ // ✅ FIX: Bounds check - if step is out of range, trigger completion
2704
+ if (chatState.step >= flowData.flow.length) {
2705
+ handleCompletion();
2706
+ return;
2707
+ }
2708
+
2692
2709
  const nextStep = flowData.flow[chatState.step];
2693
2710
 
2694
2711
  // ✅ NEW: Clean up any previously injected elements (from addElements)
@@ -3422,16 +3439,16 @@ function handleCompletion() {
3422
3439
 
3423
3440
  if (typeof window !== 'undefined') {
3424
3441
  const event = new CustomEvent('conversationalFlowComplete', {
3425
- detail: {
3426
- data: chatState.data,
3427
- history: chatState.history
3442
+ detail: {
3443
+ data: { ...chatState.data },
3444
+ history: [...chatState.history]
3428
3445
  }
3429
3446
  });
3430
3447
  window.dispatchEvent(event);
3431
3448
  }
3432
3449
 
3433
3450
  if (flowData.onComplete && typeof flowData.onComplete === 'function') {
3434
- flowData.onComplete(chatState.data);
3451
+ flowData.onComplete({ ...chatState.data });
3435
3452
  }
3436
3453
  }
3437
3454