lisichatbot 1.7.9 โ†’ 1.8.1

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 +41 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.7.9",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -2517,12 +2517,37 @@ async function showNextStep() {
2517
2517
  const nextStep = flowData.flow[chatState.step];
2518
2518
 
2519
2519
  // โœ… NEW: Clean up any previously injected elements (from addElements)
2520
- // BUT: If this step has addElements, we'll re-inject them below
2520
+ // Restore them to their original location instead of deleting
2521
2521
  if (elements.messages) {
2522
2522
  const injectedElements = elements.messages.querySelectorAll('[data-chat-injected="true"]');
2523
2523
  if (injectedElements.length > 0) {
2524
- console.log(` ๐Ÿงน Removing ${injectedElements.length} previously injected element(s)`);
2525
- injectedElements.forEach(el => el.remove());
2524
+ console.log(` ๐Ÿงน Restoring ${injectedElements.length} previously injected element(s) to original location`);
2525
+ injectedElements.forEach(el => {
2526
+ // Remove the injected marker
2527
+ el.removeAttribute('data-chat-injected');
2528
+
2529
+ // Restore to original location
2530
+ if (el._originalParent) {
2531
+ if (el._originalNextSibling) {
2532
+ el._originalParent.insertBefore(el, el._originalNextSibling);
2533
+ } else {
2534
+ el._originalParent.appendChild(el);
2535
+ }
2536
+ // Hide it again
2537
+ el.style.display = 'none';
2538
+
2539
+ // Clean up references
2540
+ delete el._originalParent;
2541
+ delete el._originalNextSibling;
2542
+ el.removeAttribute('data-original-parent');
2543
+
2544
+ console.log(` โœ… Restored element to original location`);
2545
+ } else {
2546
+ // Fallback: just remove if no original parent stored
2547
+ el.remove();
2548
+ console.log(` โš ๏ธ No original parent - removed element`);
2549
+ }
2550
+ });
2526
2551
  }
2527
2552
  }
2528
2553
 
@@ -2889,17 +2914,24 @@ async function showNextStep() {
2889
2914
  const element = document.querySelector(selector);
2890
2915
 
2891
2916
  if (element) {
2892
- // Clone the element to avoid removing it from its original location
2893
- const clonedElement = element.cloneNode(true);
2917
+ // โœ… NEW: Move element instead of cloning to preserve event listeners
2918
+ // Save original parent and position for restoration
2919
+ const originalParent = element.parentNode;
2920
+ const originalNextSibling = element.nextSibling;
2921
+
2922
+ // Store restoration info on the element
2923
+ element.setAttribute('data-original-parent', 'true');
2924
+ element._originalParent = originalParent;
2925
+ element._originalNextSibling = originalNextSibling;
2894
2926
 
2895
2927
  // Make it visible (in case it was hidden)
2896
- clonedElement.style.display = '';
2928
+ element.style.display = '';
2897
2929
 
2898
2930
  // โœ… Mark as injected for cleanup
2899
- clonedElement.setAttribute('data-chat-injected', 'true');
2931
+ element.setAttribute('data-chat-injected', 'true');
2900
2932
 
2901
- // Add to messages container
2902
- elements.messages.appendChild(clonedElement);
2933
+ // Move to messages container (preserves event listeners!)
2934
+ elements.messages.appendChild(element);
2903
2935
 
2904
2936
  console.log(` โœ… Added element ${index + 1}: ${selector}`);
2905
2937
  } else {