@liquidcommercedev/rmn-sdk 1.5.0-beta.37 → 1.5.0-beta.38

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.
package/dist/index.cjs CHANGED
@@ -17412,6 +17412,7 @@ class ProximityObserver {
17412
17412
  this.mutationObserver = new MutationObserver((mutations) => {
17413
17413
  mutations.forEach((mutation) => {
17414
17414
  if (mutation.type === 'childList') {
17415
+ // Handle added nodes
17415
17416
  mutation.addedNodes.forEach((node) => {
17416
17417
  if (node instanceof HTMLElement) {
17417
17418
  this.checkElement(node);
@@ -17422,14 +17423,33 @@ class ProximityObserver {
17422
17423
  });
17423
17424
  }
17424
17425
  });
17426
+ // Handle removed nodes
17427
+ mutation.removedNodes.forEach((node) => {
17428
+ if (node instanceof HTMLElement) {
17429
+ this.handleRemovedElement(node);
17430
+ node.querySelectorAll('*').forEach((el) => {
17431
+ if (el instanceof HTMLElement) {
17432
+ this.handleRemovedElement(el);
17433
+ }
17434
+ });
17435
+ }
17436
+ });
17425
17437
  }
17426
17438
  });
17427
17439
  });
17428
17440
  // Start observing DOM changes
17429
- this.mutationObserver.observe(document.body, {
17430
- childList: true,
17431
- subtree: true,
17432
- });
17441
+ if (document.body) {
17442
+ this.mutationObserver.observe(document.body, {
17443
+ childList: true,
17444
+ subtree: true,
17445
+ });
17446
+ }
17447
+ }
17448
+ handleRemovedElement(element) {
17449
+ if (element.id && this.processedIds.has(element.id)) {
17450
+ this.processedIds.delete(element.id);
17451
+ this.intersectionObserver.unobserve(element);
17452
+ }
17433
17453
  }
17434
17454
  checkElement(element) {
17435
17455
  if (element.id && this.targetIds.has(element.id) && !this.processedIds.has(element.id)) {
@@ -17483,10 +17503,6 @@ class ProximityObserver {
17483
17503
  });
17484
17504
  // Trigger callback with the group
17485
17505
  this.callback(groupIdsToProcess);
17486
- // Cleanup if all elements have been processed
17487
- if (this.targetIds.size === this.processedIds.size) {
17488
- this.cleanup();
17489
- }
17490
17506
  });
17491
17507
  }
17492
17508
  /**
@@ -17513,12 +17529,6 @@ class ProximityObserver {
17513
17529
  }
17514
17530
  });
17515
17531
  }
17516
- cleanup() {
17517
- this.intersectionObserver.disconnect();
17518
- this.mutationObserver.disconnect();
17519
- this.processedIds.clear();
17520
- this.targetIds.clear();
17521
- }
17522
17532
  }
17523
17533
 
17524
17534
  /**
package/dist/index.esm.js CHANGED
@@ -17410,6 +17410,7 @@ class ProximityObserver {
17410
17410
  this.mutationObserver = new MutationObserver((mutations) => {
17411
17411
  mutations.forEach((mutation) => {
17412
17412
  if (mutation.type === 'childList') {
17413
+ // Handle added nodes
17413
17414
  mutation.addedNodes.forEach((node) => {
17414
17415
  if (node instanceof HTMLElement) {
17415
17416
  this.checkElement(node);
@@ -17420,14 +17421,33 @@ class ProximityObserver {
17420
17421
  });
17421
17422
  }
17422
17423
  });
17424
+ // Handle removed nodes
17425
+ mutation.removedNodes.forEach((node) => {
17426
+ if (node instanceof HTMLElement) {
17427
+ this.handleRemovedElement(node);
17428
+ node.querySelectorAll('*').forEach((el) => {
17429
+ if (el instanceof HTMLElement) {
17430
+ this.handleRemovedElement(el);
17431
+ }
17432
+ });
17433
+ }
17434
+ });
17423
17435
  }
17424
17436
  });
17425
17437
  });
17426
17438
  // Start observing DOM changes
17427
- this.mutationObserver.observe(document.body, {
17428
- childList: true,
17429
- subtree: true,
17430
- });
17439
+ if (document.body) {
17440
+ this.mutationObserver.observe(document.body, {
17441
+ childList: true,
17442
+ subtree: true,
17443
+ });
17444
+ }
17445
+ }
17446
+ handleRemovedElement(element) {
17447
+ if (element.id && this.processedIds.has(element.id)) {
17448
+ this.processedIds.delete(element.id);
17449
+ this.intersectionObserver.unobserve(element);
17450
+ }
17431
17451
  }
17432
17452
  checkElement(element) {
17433
17453
  if (element.id && this.targetIds.has(element.id) && !this.processedIds.has(element.id)) {
@@ -17481,10 +17501,6 @@ class ProximityObserver {
17481
17501
  });
17482
17502
  // Trigger callback with the group
17483
17503
  this.callback(groupIdsToProcess);
17484
- // Cleanup if all elements have been processed
17485
- if (this.targetIds.size === this.processedIds.size) {
17486
- this.cleanup();
17487
- }
17488
17504
  });
17489
17505
  }
17490
17506
  /**
@@ -17511,12 +17527,6 @@ class ProximityObserver {
17511
17527
  }
17512
17528
  });
17513
17529
  }
17514
- cleanup() {
17515
- this.intersectionObserver.disconnect();
17516
- this.mutationObserver.disconnect();
17517
- this.processedIds.clear();
17518
- this.targetIds.clear();
17519
- }
17520
17530
  }
17521
17531
 
17522
17532
  /**
@@ -13,6 +13,7 @@ export declare class ProximityObserver {
13
13
  private readonly maxGroupSize;
14
14
  constructor(elementIds: string[], callback: (intersectingIds: string[]) => void, options?: IProximityObserverOptions);
15
15
  private initializeObservers;
16
+ private handleRemovedElement;
16
17
  private checkElement;
17
18
  private findNearbyTargetIds;
18
19
  private handleIntersection;
@@ -25,6 +26,5 @@ export declare class ProximityObserver {
25
26
  */
26
27
  private calculateDistance;
27
28
  private observeExistingElements;
28
- private cleanup;
29
29
  }
30
30
  export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@liquidcommercedev/rmn-sdk",
3
3
  "description": "LiquidCommerce RMN SDK",
4
4
  "author": "LiquidCommerce Tech",
5
- "version": "1.5.0-beta.37",
5
+ "version": "1.5.0-beta.38",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",