lisichatbot 1.8.1 → 1.8.2

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 +51 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -2527,21 +2527,17 @@ async function showNextStep() {
2527
2527
  el.removeAttribute('data-chat-injected');
2528
2528
 
2529
2529
  // Restore to original location
2530
- if (el._originalParent) {
2531
- if (el._originalNextSibling) {
2530
+ if (el._originalParent && document.contains(el._originalParent)) {
2531
+ // Hide element
2532
+ el.style.display = 'none';
2533
+
2534
+ // Insert back at original position
2535
+ if (el._originalNextSibling && el._originalParent.contains(el._originalNextSibling)) {
2532
2536
  el._originalParent.insertBefore(el, el._originalNextSibling);
2533
2537
  } else {
2534
2538
  el._originalParent.appendChild(el);
2535
2539
  }
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`);
2540
+ console.log(' ↩️ Moved element back to original parent (hidden)');
2545
2541
  } else {
2546
2542
  // Fallback: just remove if no original parent stored
2547
2543
  el.remove();
@@ -2910,19 +2906,35 @@ async function showNextStep() {
2910
2906
 
2911
2907
  nextStep.addElements.forEach((selector, index) => {
2912
2908
  try {
2913
- // Find the element in the DOM
2914
- const element = document.querySelector(selector);
2909
+ // Find the element in the DOM (check multiple locations)
2910
+ let element = document.querySelector(selector);
2911
+
2912
+ // If not found in normal location, check if it's still in chat from previous init
2913
+ if (!element) {
2914
+ element = elements.messages.querySelector(selector);
2915
+ if (element) {
2916
+ console.log(' ℹ️ Found element in chat messages (from previous init)');
2917
+ }
2918
+ }
2919
+
2920
+ // If still not found, search entire document
2921
+ if (!element) {
2922
+ element = document.body.querySelector(selector);
2923
+ if (element) {
2924
+ console.log(' ℹ️ Found element in body (moved during cleanup)');
2925
+ }
2926
+ }
2915
2927
 
2916
2928
  if (element) {
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;
2929
+ // ✅ MOVE element instead of cloning to preserve event listeners
2930
+ // Store original parent ONLY on first injection
2931
+ if (!element._originalParent) {
2932
+ element._originalParent = element.parentElement;
2933
+ element._originalNextSibling = element.nextSibling;
2934
+ console.log(' 💾 Stored original parent for:', selector);
2935
+ } else {
2936
+ console.log(' ♻️ Using existing parent reference for:', selector);
2937
+ }
2926
2938
 
2927
2939
  // Make it visible (in case it was hidden)
2928
2940
  element.style.display = '';
@@ -3302,7 +3314,24 @@ function reset() {
3302
3314
  chatState.history = [];
3303
3315
  chatState.currentSelection = null;
3304
3316
 
3317
+ // ✅ Move back any injected elements before clearing
3305
3318
  if (elements.messages) {
3319
+ const injectedElements = elements.messages.querySelectorAll('[data-chat-injected="true"]');
3320
+ injectedElements.forEach(el => {
3321
+ el.style.display = 'none';
3322
+ el.removeAttribute('data-chat-injected');
3323
+
3324
+ // Move back to original parent
3325
+ if (el._originalParent && document.contains(el._originalParent)) {
3326
+ if (el._originalNextSibling && el._originalParent.contains(el._originalNextSibling)) {
3327
+ el._originalParent.insertBefore(el, el._originalNextSibling);
3328
+ } else {
3329
+ el._originalParent.appendChild(el);
3330
+ }
3331
+ console.log(' ↩️ Moved element back during reset');
3332
+ }
3333
+ });
3334
+
3306
3335
  elements.messages.innerHTML = '';
3307
3336
  }
3308
3337