@classic-homes/maps-react 0.1.1 → 0.1.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.
package/dist/index.cjs CHANGED
@@ -7,6 +7,7 @@ var jsxRuntime = require('react/jsx-runtime');
7
7
  var maplibregl = require('maplibre-gl');
8
8
  require('maplibre-gl/dist/maplibre-gl.css');
9
9
  require('@classic-homes/maps-core/styles/controls.css');
10
+ require('@classic-homes/maps-core/styles/marker.css');
10
11
  var mapsCore = require('@classic-homes/maps-core');
11
12
  var ReactDOM = require('react-dom');
12
13
  var classVarianceAuthority = require('class-variance-authority');
@@ -921,13 +922,19 @@ var Marker = React6__namespace.forwardRef(
921
922
  const elementRef = React6__namespace.useRef(null);
922
923
  const originalLngLatRef = React6__namespace.useRef();
923
924
  const clickHandlerRef = React6__namespace.useRef(null);
925
+ const [mounted, setMounted] = React6__namespace.useState(false);
926
+ React6__namespace.useEffect(() => {
927
+ setMounted(true);
928
+ return () => setMounted(false);
929
+ }, []);
924
930
  React6__namespace.useEffect(() => {
925
931
  if (children && !elementRef.current) {
926
932
  elementRef.current = document.createElement("div");
927
933
  }
928
934
  }, [children]);
929
935
  React6__namespace.useEffect(() => {
930
- if (!map || !loaded) return;
936
+ if (!map || !loaded || !mounted) return;
937
+ if (markerRef.current) return;
931
938
  const markerOptions = {
932
939
  color: children ? void 0 : color,
933
940
  anchor,
@@ -944,6 +951,11 @@ var Marker = React6__namespace.forwardRef(
944
951
  markerOptions.element = elementRef.current;
945
952
  }
946
953
  const marker = new maplibregl__default.default.Marker(markerOptions).setLngLat(coordinates).addTo(map);
954
+ const el = marker.getElement();
955
+ mapsCore.applyMarkerProtection(el);
956
+ if (children && elementRef.current) {
957
+ mapsCore.applyMarkerChildProtection(elementRef.current);
958
+ }
947
959
  markerRef.current = marker;
948
960
  if (ref) {
949
961
  if (typeof ref === "function") {
@@ -996,14 +1008,17 @@ var Marker = React6__namespace.forwardRef(
996
1008
  });
997
1009
  }
998
1010
  return () => {
999
- if (clickHandlerRef.current) {
1000
- marker.getElement().removeEventListener("click", clickHandlerRef.current);
1011
+ if (clickHandlerRef.current && markerRef.current) {
1012
+ markerRef.current.getElement().removeEventListener("click", clickHandlerRef.current);
1001
1013
  clickHandlerRef.current = null;
1002
1014
  }
1003
- marker.remove();
1004
- markerRef.current = null;
1015
+ if (markerRef.current) {
1016
+ mapsCore.removeMarkerProtection(markerRef.current.getElement());
1017
+ markerRef.current.remove();
1018
+ markerRef.current = null;
1019
+ }
1005
1020
  };
1006
- }, [map, loaded]);
1021
+ }, [map, loaded, mounted]);
1007
1022
  React6__namespace.useEffect(() => {
1008
1023
  if (markerRef.current) {
1009
1024
  markerRef.current.setLngLat(coordinates);
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
  import maplibregl from 'maplibre-gl';
7
7
  import 'maplibre-gl/dist/maplibre-gl.css';
8
8
  import '@classic-homes/maps-core/styles/controls.css';
9
- import { generateMapDescription, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates } from '@classic-homes/maps-core';
9
+ import '@classic-homes/maps-core/styles/marker.css';
10
+ import { generateMapDescription, applyMarkerProtection, applyMarkerChildProtection, removeMarkerProtection, darkBasicStyle, lightBasicStyle, darkTheme, lightTheme, THEME_DARK, THEME_LIGHT, calculateBounds, computeVerticalOffsetStyle, computePositionClasses, formatCoordinates } from '@classic-homes/maps-core';
10
11
  export { THEME_DARK, THEME_LIGHT, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
11
12
  import * as ReactDOM from 'react-dom';
12
13
  import { cva } from 'class-variance-authority';
@@ -897,13 +898,19 @@ var Marker = React6.forwardRef(
897
898
  const elementRef = React6.useRef(null);
898
899
  const originalLngLatRef = React6.useRef();
899
900
  const clickHandlerRef = React6.useRef(null);
901
+ const [mounted, setMounted] = React6.useState(false);
902
+ React6.useEffect(() => {
903
+ setMounted(true);
904
+ return () => setMounted(false);
905
+ }, []);
900
906
  React6.useEffect(() => {
901
907
  if (children && !elementRef.current) {
902
908
  elementRef.current = document.createElement("div");
903
909
  }
904
910
  }, [children]);
905
911
  React6.useEffect(() => {
906
- if (!map || !loaded) return;
912
+ if (!map || !loaded || !mounted) return;
913
+ if (markerRef.current) return;
907
914
  const markerOptions = {
908
915
  color: children ? void 0 : color,
909
916
  anchor,
@@ -920,6 +927,11 @@ var Marker = React6.forwardRef(
920
927
  markerOptions.element = elementRef.current;
921
928
  }
922
929
  const marker = new maplibregl.Marker(markerOptions).setLngLat(coordinates).addTo(map);
930
+ const el = marker.getElement();
931
+ applyMarkerProtection(el);
932
+ if (children && elementRef.current) {
933
+ applyMarkerChildProtection(elementRef.current);
934
+ }
923
935
  markerRef.current = marker;
924
936
  if (ref) {
925
937
  if (typeof ref === "function") {
@@ -972,14 +984,17 @@ var Marker = React6.forwardRef(
972
984
  });
973
985
  }
974
986
  return () => {
975
- if (clickHandlerRef.current) {
976
- marker.getElement().removeEventListener("click", clickHandlerRef.current);
987
+ if (clickHandlerRef.current && markerRef.current) {
988
+ markerRef.current.getElement().removeEventListener("click", clickHandlerRef.current);
977
989
  clickHandlerRef.current = null;
978
990
  }
979
- marker.remove();
980
- markerRef.current = null;
991
+ if (markerRef.current) {
992
+ removeMarkerProtection(markerRef.current.getElement());
993
+ markerRef.current.remove();
994
+ markerRef.current = null;
995
+ }
981
996
  };
982
- }, [map, loaded]);
997
+ }, [map, loaded, mounted]);
983
998
  React6.useEffect(() => {
984
999
  if (markerRef.current) {
985
1000
  markerRef.current.setLngLat(coordinates);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "React MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",