lisichatbot 1.3.3 → 1.3.5

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 +32 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -23,7 +23,8 @@ let chatState = {
23
23
  let elements = {
24
24
  container: null,
25
25
  messages: null,
26
- nextBtn: null
26
+ nextBtn: null,
27
+ originalNextBtnText: null // Store original button text
27
28
  };
28
29
 
29
30
  let config = {
@@ -1373,14 +1374,19 @@ async function handleNext() {
1373
1374
  console.log(`Field: ${field}`);
1374
1375
  console.log(`Custom config:`, customConfig);
1375
1376
 
1376
- // Check if custom range was selected (data is array)
1377
+ // Check if the CUSTOM OPTION is actually selected (not just if value is array)
1378
+ // Regular options can also have array values!
1379
+ const customOptionElement = document.querySelector(
1380
+ `[data-field="${field}"][data-is-custom="true"][data-chat-element="single-select-input"]`
1381
+ );
1382
+ const isCustomOptionSelected = customOptionElement?.classList.contains('cf-checked');
1383
+
1377
1384
  const selectedValue = chatState.data[field];
1378
- const isCustomRange = Array.isArray(selectedValue);
1379
1385
 
1380
1386
  console.log(`Selected value:`, selectedValue);
1381
- console.log(`Is custom range (array)? ${isCustomRange}`);
1387
+ console.log(`Is custom option selected? ${isCustomOptionSelected}`);
1382
1388
 
1383
- if (isCustomRange && customConfig) {
1389
+ if (isCustomOptionSelected && customConfig) {
1384
1390
  // Validate the custom range one more time before proceeding
1385
1391
  console.log(`🔄 Running final validation before proceeding...`);
1386
1392
 
@@ -1625,6 +1631,10 @@ async function showNextStep() {
1625
1631
  }
1626
1632
  } else {
1627
1633
  // No input - always auto-advance (nextButtonDisplay only controls button visibility)
1634
+ // Use step-level autoAdvanceDelay if provided, otherwise use global config
1635
+ const delay = nextStep.autoAdvanceDelay !== undefined ? nextStep.autoAdvanceDelay : config.autoAdvanceDelay;
1636
+ console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
1637
+
1628
1638
  setTimeout(() => {
1629
1639
  chatState.step++;
1630
1640
 
@@ -1636,7 +1646,7 @@ async function showNextStep() {
1636
1646
  } else {
1637
1647
  handleCompletion();
1638
1648
  }
1639
- }, config.autoAdvanceDelay);
1649
+ }, delay);
1640
1650
  }
1641
1651
 
1642
1652
  // Handle nextButtonDisplay - default is true
@@ -1651,6 +1661,18 @@ async function showNextStep() {
1651
1661
  }
1652
1662
  }
1653
1663
 
1664
+ // Handle nextButtonText - update button text if specified at step level
1665
+ if (elements.nextBtn) {
1666
+ if (nextStep.nextButtonText) {
1667
+ elements.nextBtn.textContent = nextStep.nextButtonText;
1668
+ console.log(` 📝 Next button text: "${nextStep.nextButtonText}" (step-level)`);
1669
+ } else {
1670
+ // Restore original text
1671
+ elements.nextBtn.textContent = elements.originalNextBtnText;
1672
+ console.log(` 📝 Next button text: "${elements.originalNextBtnText}" (original)`);
1673
+ }
1674
+ }
1675
+
1654
1676
  // Always update edit icons at the end to ensure correct state
1655
1677
  // Use setTimeout to ensure it runs after any DOM updates
1656
1678
  setTimeout(() => {
@@ -1752,6 +1774,10 @@ function init(flowName, flowConfig, options = {}) {
1752
1774
  console.error('next-button not found. Please add <button data-chat-element="next-button"></button>');
1753
1775
  return null;
1754
1776
  }
1777
+
1778
+ // Store original button text
1779
+ elements.originalNextBtnText = elements.nextBtn.textContent || elements.nextBtn.innerText || 'Next';
1780
+ console.log(`💾 Stored original button text: "${elements.originalNextBtnText}"`);
1755
1781
 
1756
1782
  // Clear ONLY messages container (not entire chat-wrapper)
1757
1783
  elements.messages.innerHTML = '';