lisichatbot 1.3.1 β†’ 1.3.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 +43 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -922,6 +922,9 @@ function handleCustomSelectClick(element, field, customConfig) {
922
922
  function validateMinMax(field, customConfig) {
923
923
  console.log(`\nπŸ” === VALIDATING MIN/MAX for field: ${field} ===`);
924
924
 
925
+ // Always use global config errors
926
+ const errors = config.customRangeErrors;
927
+
925
928
  // Fixed selectors - input has all attributes on it directly
926
929
  const minInput = document.querySelector(`[data-field="${field}"][data-input-type="min"][data-chat-input-element="input"]`);
927
930
  const maxInput = document.querySelector(`[data-field="${field}"][data-input-type="max"][data-chat-input-element="input"]`);
@@ -976,7 +979,7 @@ function validateMinMax(field, customConfig) {
976
979
 
977
980
  // 1. Check if only one is filled
978
981
  if (minFilled && !maxFilled) {
979
- const error = config.customRangeErrors.maxRequired;
982
+ const error = errors.maxRequired;
980
983
  showErrorDiv(error);
981
984
  console.log(`❌ FAIL: Only min filled`);
982
985
  disableNextButton();
@@ -984,7 +987,7 @@ function validateMinMax(field, customConfig) {
984
987
  }
985
988
 
986
989
  if (!minFilled && maxFilled) {
987
- const error = config.customRangeErrors.minRequired;
990
+ const error = errors.minRequired;
988
991
  showErrorDiv(error);
989
992
  console.log(`❌ FAIL: Only max filled`);
990
993
  disableNextButton();
@@ -1003,7 +1006,7 @@ function validateMinMax(field, customConfig) {
1003
1006
 
1004
1007
  // 3. Check if values are valid numbers
1005
1008
  if (isNaN(minValue) || isNaN(maxValue)) {
1006
- const error = config.customRangeErrors.bothRequired;
1009
+ const error = errors.bothRequired;
1007
1010
  showErrorDiv(error);
1008
1011
  console.log(`❌ FAIL: Invalid numbers (min: ${minValue}, max: ${maxValue})`);
1009
1012
  disableNextButton();
@@ -1013,7 +1016,7 @@ function validateMinMax(field, customConfig) {
1013
1016
  // 4. Check min constraint
1014
1017
  console.log(`πŸ” Checking: ${minValue} < ${minConstraint}?`);
1015
1018
  if (minValue < minConstraint) {
1016
- const error = config.customRangeErrors.minBelowConstraint.replace('{min}', minConstraint);
1019
+ const error = errors.minBelowConstraint.replace('{min}', minConstraint);
1017
1020
  showErrorDiv(error);
1018
1021
  console.log(`❌ FAIL: Min (${minValue}) < constraint (${minConstraint})`);
1019
1022
  disableNextButton();
@@ -1024,7 +1027,7 @@ function validateMinMax(field, customConfig) {
1024
1027
  // 5. Check max constraint
1025
1028
  console.log(`πŸ” Checking: ${maxValue} > ${maxConstraint}?`);
1026
1029
  if (maxValue > maxConstraint) {
1027
- const error = config.customRangeErrors.maxAboveConstraint.replace('{max}', maxConstraint);
1030
+ const error = errors.maxAboveConstraint.replace('{max}', maxConstraint);
1028
1031
  showErrorDiv(error);
1029
1032
  console.log(`❌ FAIL: Max (${maxValue}) > constraint (${maxConstraint})`);
1030
1033
  disableNextButton();
@@ -1035,7 +1038,7 @@ function validateMinMax(field, customConfig) {
1035
1038
  // 6. Check min < max
1036
1039
  console.log(`πŸ” Checking: ${minValue} >= ${maxValue}?`);
1037
1040
  if (minValue >= maxValue) {
1038
- const error = config.customRangeErrors.minGreaterThanMax;
1041
+ const error = errors.minGreaterThanMax;
1039
1042
  showErrorDiv(error);
1040
1043
  console.log(`❌ FAIL: Min (${minValue}) >= Max (${maxValue})`);
1041
1044
  disableNextButton();
@@ -1380,6 +1383,7 @@ async function handleNext() {
1380
1383
  if (isCustomRange && customConfig) {
1381
1384
  // Validate the custom range one more time before proceeding
1382
1385
  console.log(`πŸ”„ Running final validation before proceeding...`);
1386
+
1383
1387
  const validation = validateMinMax(field, customConfig);
1384
1388
 
1385
1389
  console.log(`Validation result:`, validation);
@@ -1620,27 +1624,19 @@ async function showNextStep() {
1620
1624
  }
1621
1625
  }
1622
1626
  } else {
1623
- // No input
1624
- const shouldAutoAdvance = nextStep.nextButtonDisplay !== false;
1625
-
1626
- if (shouldAutoAdvance) {
1627
- // Auto-advance for steps without input (default behavior)
1628
- setTimeout(() => {
1629
- chatState.step++;
1630
-
1631
- // Update edit icons after auto-advance
1632
- updateEditIcons();
1633
-
1634
- if (chatState.step < flowData.flow.length) {
1635
- showNextStep();
1636
- } else {
1637
- handleCompletion();
1638
- }
1639
- }, config.autoAdvanceDelay);
1640
- } else {
1641
- // Don't auto-advance if nextButtonDisplay is explicitly false
1642
- console.log(' ⏸️ Not auto-advancing (nextButtonDisplay: false)');
1643
- }
1627
+ // No input - always auto-advance (nextButtonDisplay only controls button visibility)
1628
+ setTimeout(() => {
1629
+ chatState.step++;
1630
+
1631
+ // Update edit icons after auto-advance
1632
+ updateEditIcons();
1633
+
1634
+ if (chatState.step < flowData.flow.length) {
1635
+ showNextStep();
1636
+ } else {
1637
+ handleCompletion();
1638
+ }
1639
+ }, config.autoAdvanceDelay);
1644
1640
  }
1645
1641
 
1646
1642
  // Handle nextButtonDisplay - default is true
@@ -1698,7 +1694,7 @@ function handleCompletion() {
1698
1694
  // INITIALIZATION
1699
1695
  // =============================================================================
1700
1696
 
1701
- function init(flowName, flowConfig) {
1697
+ function init(flowName, flowConfig, options = {}) {
1702
1698
  // Find container by data-chat-element="chat-wrapper"
1703
1699
  elements.container = document.querySelector('[data-chat-element="chat-wrapper"]');
1704
1700
 
@@ -1713,10 +1709,24 @@ function init(flowName, flowConfig) {
1713
1709
  Object.assign(config, flowConfig.config);
1714
1710
  }
1715
1711
 
1712
+ // Merge customRangeErrors - priority: options param > flow object > defaults
1713
+ // 1. First, try flow object customRangeErrors
1714
+ if (flowConfig.customRangeErrors) {
1715
+ console.log('βœ… Using custom range errors from flow object');
1716
+ Object.assign(config.customRangeErrors, flowConfig.customRangeErrors);
1717
+ }
1718
+
1719
+ // 2. Then, options parameter (overrides flow object if both provided)
1720
+ if (options.customRangeErrors) {
1721
+ console.log('βœ… Using custom range errors from options parameter');
1722
+ Object.assign(config.customRangeErrors, options.customRangeErrors);
1723
+ }
1724
+
1716
1725
  console.log('βœ… Flow initialized:', {
1717
1726
  flowName,
1718
1727
  selectedBackground: config.selectedBackground,
1719
- autoAdvanceDelay: config.autoAdvanceDelay
1728
+ autoAdvanceDelay: config.autoAdvanceDelay,
1729
+ customRangeErrors: config.customRangeErrors
1720
1730
  });
1721
1731
 
1722
1732
  // Store flow data
@@ -1843,15 +1853,10 @@ function editStep(stepNumber) {
1843
1853
  // Clear history from this step forward
1844
1854
  chatState.history = chatState.history.filter(h => h.step < stepNumber);
1845
1855
 
1846
- console.log(` Resetting data for step ${stepNumber} and beyond...`);
1847
- // Reset data for this field and beyond
1848
- const stepsToReset = flowData.flow.slice(stepNumber);
1849
- stepsToReset.forEach(step => {
1850
- if (step.input && step.input.field) {
1851
- console.log(` Deleting field: ${step.input.field}`);
1852
- delete chatState.data[step.input.field];
1853
- }
1854
- });
1856
+ console.log(` βœ… Keeping ALL data intact for editing (no data deleted)`);
1857
+ console.log(` Current data:`, chatState.data);
1858
+ // Don't delete any data - keep everything for pre-filling
1859
+ // Data will be replaced when user submits the edited step
1855
1860
 
1856
1861
  console.log(` Calling goToStep(${stepNumber})...`);
1857
1862
  // Go to that step