@geolonia/embed 2.1.0 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "src/embed.d.ts",
@@ -56,7 +56,7 @@
56
56
  "@turf/center": "^6.0.1",
57
57
  "core-js": "^3.6.5",
58
58
  "intersection-observer": "^0.5.1",
59
- "maplibre-gl": ">=1.14.0",
59
+ "maplibre-gl": "1.15.2",
60
60
  "promise-polyfill": "^8.1.0",
61
61
  "sanitize-html": "^2.3.2",
62
62
  "tinycolor2": "^1.4.1",
package/src/embed.js CHANGED
@@ -33,6 +33,16 @@ if ( util.checkPermission() ) {
33
33
  map[isRemoved] = true;
34
34
  });
35
35
 
36
+ // remove map instance automatically if the container removed.
37
+ // prevent memory leak
38
+ const observer = new MutationObserver((mutationRecords) => {
39
+ const removed = mutationRecords.some((record) => [...record.removedNodes].some((node) => node === target));
40
+ if (removed && !map[isRemoved]) {
41
+ map.remove();
42
+ }
43
+ });
44
+ observer.observe(target.parentNode, { childList: true });
45
+
36
46
  // plugin
37
47
  const atts = parseAtts(target);
38
48
  if (isDOMContentLoaded && !map[isRemoved]) {