lisichatbot 1.6.7 → 1.6.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 +70 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -229,7 +229,10 @@ function updateEditIcons() {
229
229
  return;
230
230
  }
231
231
 
232
- if (hasInput && stepNumber < chatState.step && isLatest) {
232
+ // ✅ NEW: Check if edit icon should be forced to show (even without input)
233
+ const forceShowEdit = stepData && stepData.showEditIcon === true;
234
+
235
+ if ((hasInput || forceShowEdit) && stepNumber < chatState.step && isLatest) {
233
236
  editIcon.onclick = (e) => {
234
237
  e.stopPropagation();
235
238
  e.preventDefault();
@@ -2424,6 +2427,16 @@ function findNextAccessibleStep(currentStep) {
2424
2427
  async function showNextStep() {
2425
2428
  const nextStep = flowData.flow[chatState.step];
2426
2429
 
2430
+ // ✅ NEW: Clean up any previously injected elements (from addElements)
2431
+ // BUT: If this step has addElements, we'll re-inject them below
2432
+ if (elements.messages) {
2433
+ const injectedElements = elements.messages.querySelectorAll('[data-chat-injected="true"]');
2434
+ if (injectedElements.length > 0) {
2435
+ console.log(` 🧹 Removing ${injectedElements.length} previously injected element(s)`);
2436
+ injectedElements.forEach(el => el.remove());
2437
+ }
2438
+ }
2439
+
2427
2440
  // ✅ NEW: Check if step should be displayed based on condition
2428
2441
  if (nextStep.shouldDisplay) {
2429
2442
  let shouldShow = false;
@@ -2777,6 +2790,41 @@ async function showNextStep() {
2777
2790
 
2778
2791
  addMessage(messageToDisplay, 'bot', hasInput, chatState.step);
2779
2792
 
2793
+ // ✅ NEW: Add custom elements if specified
2794
+ if (nextStep.addElements && Array.isArray(nextStep.addElements)) {
2795
+ console.log(` 🎨 Adding ${nextStep.addElements.length} custom element(s) to chat`);
2796
+
2797
+ nextStep.addElements.forEach((selector, index) => {
2798
+ try {
2799
+ // Find the element in the DOM
2800
+ const element = document.querySelector(selector);
2801
+
2802
+ if (element) {
2803
+ // Clone the element to avoid removing it from its original location
2804
+ const clonedElement = element.cloneNode(true);
2805
+
2806
+ // Make it visible (in case it was hidden)
2807
+ clonedElement.style.display = '';
2808
+
2809
+ // ✅ Mark as injected for cleanup
2810
+ clonedElement.setAttribute('data-chat-injected', 'true');
2811
+
2812
+ // Add to messages container
2813
+ elements.messages.appendChild(clonedElement);
2814
+
2815
+ console.log(` ✅ Added element ${index + 1}: ${selector}`);
2816
+ } else {
2817
+ console.warn(` ⚠️ Element not found: ${selector}`);
2818
+ }
2819
+ } catch (error) {
2820
+ console.error(` ❌ Error adding element ${selector}:`, error);
2821
+ }
2822
+ });
2823
+
2824
+ // Scroll after adding elements
2825
+ scrollToBottom();
2826
+ }
2827
+
2780
2828
  const inputRequired = nextStep.inputRequired === true;
2781
2829
 
2782
2830
  if (nextStep.input) {
@@ -2856,20 +2904,29 @@ async function showNextStep() {
2856
2904
  // If hasPreFill, renderOptions already handled it
2857
2905
  }
2858
2906
  } else {
2859
- const delay = nextStep.autoAdvanceDelay !== undefined ? nextStep.autoAdvanceDelay : config.autoAdvanceDelay;
2860
- console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
2907
+ // FIXED: Only auto-advance if explicitly enabled OR if step has autoAdvance
2908
+ const shouldAutoAdvance = nextStep.autoAdvance === true;
2861
2909
 
2862
- setTimeout(() => {
2863
- // NEW: Find next accessible step
2864
- chatState.step = findNextAccessibleStep(chatState.step);
2865
- updateEditIcons();
2910
+ if (shouldAutoAdvance) {
2911
+ const delay = nextStep.autoAdvanceDelay !== undefined ? nextStep.autoAdvanceDelay : config.autoAdvanceDelay;
2912
+ console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
2866
2913
 
2867
- if (chatState.step < flowData.flow.length) {
2868
- showNextStep();
2869
- } else {
2870
- handleCompletion();
2871
- }
2872
- }, delay);
2914
+ setTimeout(() => {
2915
+ // ✅ NEW: Find next accessible step
2916
+ chatState.step = findNextAccessibleStep(chatState.step);
2917
+ updateEditIcons();
2918
+
2919
+ if (chatState.step < flowData.flow.length) {
2920
+ showNextStep();
2921
+ } else {
2922
+ handleCompletion();
2923
+ }
2924
+ }, delay);
2925
+ } else {
2926
+ // ✅ No input and no auto-advance - just enable Next button
2927
+ enableNextButton();
2928
+ console.log(' 🔓 No input field - Next button enabled for manual progression');
2929
+ }
2873
2930
  }
2874
2931
 
2875
2932
  const showNextButton = nextStep.nextButtonDisplay !== false;