@vinctus/react-maplibre 1.3.1 → 1.3.3

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/Layer.js CHANGED
@@ -80,7 +80,9 @@ export const Layer = ({ layer, source }) => {
80
80
  }, [id, layerStructureString, sourceOptionsString, map, mapLoaded]);
81
81
  useEffect(() => {
82
82
  const current = applied.current;
83
- if (!map || !mapLoaded || !current) {
83
+ // A replaced map is removed before the context hands out the new one, so this effect can run
84
+ // once more against the removed map.
85
+ if (!map || !mapLoaded || !current || map._removed) {
84
86
  return;
85
87
  }
86
88
  // The source disappears when the map's style is replaced, so the source and layer are rebuilt
package/dist/Popup.d.ts CHANGED
@@ -6,5 +6,10 @@ export type PopupProps = {
6
6
  className?: string;
7
7
  closeOnClick?: boolean;
8
8
  closeButton?: boolean;
9
+ /**
10
+ * Called when MapLibre closes the popup through its close button or a map click. The popup is
11
+ * not reopened by a later render, so the parent should stop rendering it here.
12
+ */
13
+ onClose?: () => void;
9
14
  };
10
15
  export declare const Popup: FC<PopupProps>;
package/dist/Popup.js CHANGED
@@ -2,8 +2,10 @@ import { useEffect, useContext, useRef } from 'react';
2
2
  import maplibre from 'maplibre-gl';
3
3
  import ReactDOMServer from 'react-dom/server';
4
4
  import { MapContext } from './Map';
5
- export const Popup = ({ children, longitude, latitude, className, closeOnClick, closeButton, }) => {
5
+ export const Popup = ({ children, longitude, latitude, className, closeOnClick, closeButton, onClose, }) => {
6
6
  const { map, mapLoaded } = useContext(MapContext);
7
+ const onCloseRef = useRef(onClose);
8
+ onCloseRef.current = onClose;
7
9
  // The content is compared by its rendered markup because `children` has a new identity on every
8
10
  // parent render.
9
11
  const html = ReactDOMServer.renderToStaticMarkup(children);
@@ -21,8 +23,12 @@ export const Popup = ({ children, longitude, latitude, className, closeOnClick,
21
23
  .setLngLat(coordinates)
22
24
  .setHTML(initialHtml)
23
25
  .addTo(map);
26
+ const handleClose = () => { var _a; return (_a = onCloseRef.current) === null || _a === void 0 ? void 0 : _a.call(onCloseRef); };
27
+ popup.on('close', handleClose);
24
28
  popupInstance.current = popup;
25
29
  return () => {
30
+ // Removing the popup here also fires `close`, which is not a user closing it.
31
+ popup.off('close', handleClose);
26
32
  try {
27
33
  popup.remove();
28
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinctus/react-maplibre",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Minimalist MapLibre GL JS React wrapper library",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",