@classic-homes/maps-react 0.3.1 → 0.5.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 (3) hide show
  1. package/dist/index.cjs +100 -20
  2. package/dist/index.js +100 -20
  3. package/package.json +3 -2
package/dist/index.cjs CHANGED
@@ -374,6 +374,11 @@ var Map2 = React26__namespace.forwardRef(
374
374
  const mapRef = React26__namespace.useRef(null);
375
375
  const [mapLoaded, setMapLoaded] = React26__namespace.useState(false);
376
376
  const [mapError, setMapError] = React26__namespace.useState(null);
377
+ const [initAttempt, setInitAttempt] = React26__namespace.useState(0);
378
+ const retryInit = React26__namespace.useCallback(() => {
379
+ setMapError(null);
380
+ setInitAttempt((attempt) => attempt + 1);
381
+ }, []);
377
382
  const [styleVersion, setStyleVersion] = React26__namespace.useState(0);
378
383
  const styleVersionRef = React26__namespace.useRef(0);
379
384
  const bumpStyleVersion = React26__namespace.useCallback(() => {
@@ -454,7 +459,16 @@ var Map2 = React26__namespace.forwardRef(
454
459
  touchZoomRotate,
455
460
  keyboard,
456
461
  cooperativeGestures,
457
- attributionControl: attributionControl ? { customAttribution } : false
462
+ attributionControl: attributionControl ? { customAttribution } : false,
463
+ // Frame the bounds from the first frame; `center`/`zoom` alone put
464
+ // the map at its defaults ([0, 0] z2) until the load handler's
465
+ // fitBounds, which then flew in from the other side of the world.
466
+ ...bounds ? {
467
+ bounds,
468
+ fitBoundsOptions: {
469
+ padding: boundsPadding
470
+ }
471
+ } : {}
458
472
  });
459
473
  mapRef.current = map;
460
474
  if (navigationControl) {
@@ -533,11 +547,14 @@ var Map2 = React26__namespace.forwardRef(
533
547
  onErrorRef.current?.({
534
548
  type: "error",
535
549
  message: errorMessage,
536
- error: new Error(errorMessage)
550
+ error: new Error(errorMessage),
551
+ fatal: true
537
552
  });
538
553
  }
539
554
  }, 3e4);
555
+ let hasLoaded = false;
540
556
  map.on("load", () => {
557
+ hasLoaded = true;
541
558
  clearTimeout(initTimeoutId);
542
559
  setMapLoaded(true);
543
560
  if (bounds) {
@@ -550,25 +567,36 @@ var Map2 = React26__namespace.forwardRef(
550
567
  });
551
568
  map.on("error", (e) => {
552
569
  const errorMessage = e.error?.message || "Map error";
553
- const isTransient = errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
570
+ const isTransient = hasLoaded || errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
554
571
  if (!isTransient) {
555
572
  clearTimeout(initTimeoutId);
556
573
  setMapError(errorMessage);
557
574
  }
558
- onErrorRef.current?.({ type: "error", message: errorMessage, error: e.error });
575
+ onErrorRef.current?.({
576
+ type: "error",
577
+ message: errorMessage,
578
+ error: e.error,
579
+ fatal: !isTransient
580
+ });
559
581
  });
560
582
  return () => {
561
583
  clearTimeout(initTimeoutId);
562
584
  map.remove();
563
585
  mapRef.current = null;
564
586
  setMapLoaded(false);
587
+ styleInitialized.current = false;
565
588
  };
566
589
  } catch (err) {
567
590
  const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
568
591
  setMapError(errorMessage);
569
- onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
592
+ onErrorRef.current?.({
593
+ type: "error",
594
+ message: errorMessage,
595
+ error: err,
596
+ fatal: true
597
+ });
570
598
  }
571
- }, []);
599
+ }, [initAttempt]);
572
600
  React26__namespace.useEffect(() => {
573
601
  const map = mapRef.current;
574
602
  if (!map || !mapLoaded) return;
@@ -711,6 +739,7 @@ var Map2 = React26__namespace.forwardRef(
711
739
  width,
712
740
  loading,
713
741
  error: combinedError,
742
+ onRetry: mapError && !error ? retryInit : void 0,
714
743
  emptyMessage,
715
744
  className,
716
745
  children: /* @__PURE__ */ jsxRuntime.jsxs(MapContext.Provider, { value: contextValue, children: [
@@ -744,6 +773,7 @@ var Source = ({
744
773
  const { map, loaded, styleVersion } = useMap();
745
774
  const initialFitDone = React26__namespace.useRef(false);
746
775
  const lastStyleVersionRef = React26__namespace.useRef(styleVersion);
776
+ const appliedDataRef = React26__namespace.useRef(void 0);
747
777
  const fitBoundsParamsRef = React26__namespace.useRef({
748
778
  shouldFitBounds,
749
779
  data,
@@ -897,6 +927,7 @@ var Source = ({
897
927
  };
898
928
  map.once("idle", handleIdle);
899
929
  map.addSource(id, sourceConfig);
930
+ appliedDataRef.current = type === "geojson" ? data : void 0;
900
931
  const source = map.getSource(id);
901
932
  if (source && map.isSourceLoaded(id)) {
902
933
  map.off("sourcedata", handleSourceData);
@@ -963,6 +994,7 @@ var Source = ({
963
994
  try {
964
995
  const newData = typeof data === "string" ? data : data && typeof data === "object" ? data : null;
965
996
  if (!newData) return;
997
+ if (data === appliedDataRef.current) return;
966
998
  const handleSourceData = (e) => {
967
999
  if (cancelled) return;
968
1000
  if (e.sourceId === id && e.isSourceLoaded) {
@@ -974,6 +1006,7 @@ var Source = ({
974
1006
  map.on("sourcedata", handleSourceData);
975
1007
  }
976
1008
  source.setData(newData);
1009
+ appliedDataRef.current = data;
977
1010
  return () => {
978
1011
  cancelled = true;
979
1012
  if (cluster) {
@@ -1200,24 +1233,34 @@ var Marker = React26__namespace.forwardRef(
1200
1233
  }
1201
1234
  );
1202
1235
  Marker.displayName = "Marker";
1236
+ function useStructuralValue(next) {
1237
+ const ref = React26__namespace.useRef(next);
1238
+ if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1239
+ ref.current = next;
1240
+ }
1241
+ return ref.current;
1242
+ }
1203
1243
  var Popup = React26__namespace.forwardRef(
1204
1244
  ({
1205
- coordinates,
1245
+ coordinates: coordinatesProp,
1206
1246
  closeButton = true,
1207
1247
  closeOnClick = true,
1208
1248
  closeOnMove = false,
1209
1249
  anchor,
1210
- offset,
1250
+ offset: offsetProp,
1211
1251
  maxWidth = "300px",
1212
1252
  focusAfterOpen = true,
1213
1253
  autoPan = true,
1214
- autoPanPadding = 50,
1254
+ autoPanPadding: autoPanPaddingProp = 50,
1215
1255
  open = true,
1216
1256
  onOpen,
1217
1257
  onClose,
1218
1258
  children
1219
1259
  }, ref) => {
1220
1260
  const { map, loaded } = useMap();
1261
+ const coordinates = useStructuralValue(coordinatesProp);
1262
+ const offset = useStructuralValue(offsetProp);
1263
+ const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1221
1264
  const popupRef = React26__namespace.useRef(null);
1222
1265
  const onOpenRef = React26__namespace.useRef(onOpen);
1223
1266
  onOpenRef.current = onOpen;
@@ -1231,6 +1274,7 @@ var Popup = React26__namespace.forwardRef(
1231
1274
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1232
1275
  }
1233
1276
  const [contentReady, setContentReady] = React26__namespace.useState(false);
1277
+ const [popupVersion, setPopupVersion] = React26__namespace.useState(0);
1234
1278
  const contentCallbackRef = React26__namespace.useCallback((node) => {
1235
1279
  if (node && containerRef.current) {
1236
1280
  setContentReady(true);
@@ -1249,6 +1293,7 @@ var Popup = React26__namespace.forwardRef(
1249
1293
  });
1250
1294
  popup.setDOMContent(containerRef.current);
1251
1295
  popupRef.current = popup;
1296
+ setPopupVersion((v) => v + 1);
1252
1297
  popup.on("open", () => {
1253
1298
  onOpenRef.current?.({
1254
1299
  type: "open",
@@ -1283,7 +1328,7 @@ var Popup = React26__namespace.forwardRef(
1283
1328
  } else {
1284
1329
  ref.current = popupRef.current;
1285
1330
  }
1286
- }, [ref]);
1331
+ }, [ref, popupVersion]);
1287
1332
  React26__namespace.useEffect(() => {
1288
1333
  if (popupRef.current) {
1289
1334
  popupRef.current.setLngLat(coordinates);
@@ -1309,7 +1354,7 @@ var Popup = React26__namespace.forwardRef(
1309
1354
  cancelAnimationFrame(rafHandle);
1310
1355
  }
1311
1356
  };
1312
- }, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
1357
+ }, [map, open, coordinates, autoPan, autoPanPadding, contentReady, popupVersion]);
1313
1358
  if (!containerRef.current) return null;
1314
1359
  return ReactDOM__namespace.createPortal(
1315
1360
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentCallbackRef, children }),
@@ -1499,10 +1544,34 @@ function useLayer({
1499
1544
  } catch {
1500
1545
  }
1501
1546
  }, [map, id, paint, layerAdded]);
1547
+ const lastAppliedLayoutRef = React26__namespace.useRef(void 0);
1548
+ React26__namespace.useEffect(() => {
1549
+ if (!map || !layerAdded) return;
1550
+ if (!map.getLayer(id)) return;
1551
+ const next = { ...layout };
1552
+ delete next.visibility;
1553
+ const diff = mapsCore.getChangedPaintProps(lastAppliedLayoutRef.current, next);
1554
+ if (!diff.hasChanges) return;
1555
+ try {
1556
+ for (const [key, value] of Object.entries(diff.changed)) {
1557
+ map.setLayoutProperty(id, key, value);
1558
+ }
1559
+ for (const key of diff.removed) {
1560
+ map.setLayoutProperty(id, key, void 0);
1561
+ }
1562
+ lastAppliedLayoutRef.current = next;
1563
+ } catch {
1564
+ }
1565
+ }, [map, id, layout, layerAdded]);
1502
1566
  React26__namespace.useEffect(() => {
1503
- if (!map || !layerAdded || !filter) return;
1567
+ if (!map || !layerAdded) return;
1568
+ if (!map.getLayer(id)) return;
1569
+ map.setLayerZoomRange(id, minZoom ?? 0, maxZoom ?? 24);
1570
+ }, [map, id, minZoom, maxZoom, layerAdded]);
1571
+ React26__namespace.useEffect(() => {
1572
+ if (!map || !layerAdded) return;
1504
1573
  if (!map.getLayer(id)) return;
1505
- map.setFilter(id, filter);
1574
+ map.setFilter(id, filter ?? null);
1506
1575
  }, [map, id, filter, layerAdded]);
1507
1576
  React26__namespace.useEffect(() => {
1508
1577
  if (!map || !layerAdded) return;
@@ -2699,7 +2768,7 @@ var BasemapSwitcher = ({
2699
2768
  children: /* @__PURE__ */ jsxRuntime.jsx(
2700
2769
  "div",
2701
2770
  {
2702
- role: "listbox",
2771
+ role: "group",
2703
2772
  "aria-label": "Select basemap",
2704
2773
  className: "grid gap-1.5",
2705
2774
  style: {
@@ -2712,8 +2781,7 @@ var BasemapSwitcher = ({
2712
2781
  "button",
2713
2782
  {
2714
2783
  type: "button",
2715
- role: "option",
2716
- "aria-selected": isActive,
2784
+ "aria-pressed": isActive,
2717
2785
  className: cn(
2718
2786
  "flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
2719
2787
  "hover:bg-muted transition-colors",
@@ -2726,7 +2794,7 @@ var BasemapSwitcher = ({
2726
2794
  "img",
2727
2795
  {
2728
2796
  src: thumbUrl,
2729
- alt: basemap.name,
2797
+ alt: "",
2730
2798
  loading: "lazy",
2731
2799
  className: "rounded object-cover",
2732
2800
  style: {
@@ -2811,6 +2879,15 @@ var LayerManager = ({
2811
2879
  const uniqueId = React26__namespace.useId();
2812
2880
  const managerId = `layer-manager${uniqueId}`;
2813
2881
  const lastLayerIdsRef = React26__namespace.useRef(new Set(layers.map((l) => l.id)));
2882
+ const tilesCacheRef = React26__namespace.useRef(/* @__PURE__ */ new Map());
2883
+ const getTiles = (url) => {
2884
+ let tiles = tilesCacheRef.current.get(url);
2885
+ if (!tiles) {
2886
+ tiles = [url];
2887
+ tilesCacheRef.current.set(url, tiles);
2888
+ }
2889
+ return tiles;
2890
+ };
2814
2891
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2815
2892
  id: managerId,
2816
2893
  type: "layer-manager",
@@ -3064,8 +3141,7 @@ var LayerManager = ({
3064
3141
  id: sourceId,
3065
3142
  type: layer.source.type === "vector-tiles" ? "vector" : "geojson",
3066
3143
  data: layer.source.type !== "vector-tiles" ? sourceData : void 0,
3067
- url: layer.source.type === "vector-tiles" ? sourceUrl ?? void 0 : void 0,
3068
- tiles: layer.source.type === "vector-tiles" ? [sourceUrl ?? ""] : void 0,
3144
+ tiles: layer.source.type === "vector-tiles" ? getTiles(sourceUrl ?? "") : void 0,
3069
3145
  attribution: layer.source.attribution,
3070
3146
  children: layerComponent
3071
3147
  },
@@ -3142,7 +3218,8 @@ var LayerManager = ({
3142
3218
  type: "button",
3143
3219
  className: "text-muted-foreground hover:text-foreground p-1",
3144
3220
  onClick: () => setExpandedOpacity(expandedOpacity === layer.id ? null : layer.id),
3145
- "aria-label": "Adjust opacity",
3221
+ "aria-label": `Adjust ${layer.name} opacity`,
3222
+ "aria-expanded": expandedOpacity === layer.id,
3146
3223
  children: /* @__PURE__ */ jsxRuntime.jsxs(
3147
3224
  "svg",
3148
3225
  {
@@ -3169,6 +3246,7 @@ var LayerManager = ({
3169
3246
  if (expandedOpacity !== layerId) return null;
3170
3247
  const state = layerStates.get(layerId);
3171
3248
  if (!state) return null;
3249
+ const layerName = layers.find((l) => l.id === layerId)?.name ?? layerId;
3172
3250
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3 pb-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
3173
3251
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground w-12", children: "Opacity" }),
3174
3252
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -3178,6 +3256,8 @@ var LayerManager = ({
3178
3256
  min: "0",
3179
3257
  max: "100",
3180
3258
  value: state.opacity * 100,
3259
+ "aria-label": `${layerName} opacity`,
3260
+ "aria-valuetext": `${Math.round(state.opacity * 100)}%`,
3181
3261
  onChange: (e) => handleOpacityChange(layerId, Number(e.target.value) / 100),
3182
3262
  className: "classic-layer-opacity-slider flex-1"
3183
3263
  }
package/dist/index.js CHANGED
@@ -350,6 +350,11 @@ var Map2 = React26.forwardRef(
350
350
  const mapRef = React26.useRef(null);
351
351
  const [mapLoaded, setMapLoaded] = React26.useState(false);
352
352
  const [mapError, setMapError] = React26.useState(null);
353
+ const [initAttempt, setInitAttempt] = React26.useState(0);
354
+ const retryInit = React26.useCallback(() => {
355
+ setMapError(null);
356
+ setInitAttempt((attempt) => attempt + 1);
357
+ }, []);
353
358
  const [styleVersion, setStyleVersion] = React26.useState(0);
354
359
  const styleVersionRef = React26.useRef(0);
355
360
  const bumpStyleVersion = React26.useCallback(() => {
@@ -430,7 +435,16 @@ var Map2 = React26.forwardRef(
430
435
  touchZoomRotate,
431
436
  keyboard,
432
437
  cooperativeGestures,
433
- attributionControl: attributionControl ? { customAttribution } : false
438
+ attributionControl: attributionControl ? { customAttribution } : false,
439
+ // Frame the bounds from the first frame; `center`/`zoom` alone put
440
+ // the map at its defaults ([0, 0] z2) until the load handler's
441
+ // fitBounds, which then flew in from the other side of the world.
442
+ ...bounds ? {
443
+ bounds,
444
+ fitBoundsOptions: {
445
+ padding: boundsPadding
446
+ }
447
+ } : {}
434
448
  });
435
449
  mapRef.current = map;
436
450
  if (navigationControl) {
@@ -509,11 +523,14 @@ var Map2 = React26.forwardRef(
509
523
  onErrorRef.current?.({
510
524
  type: "error",
511
525
  message: errorMessage,
512
- error: new Error(errorMessage)
526
+ error: new Error(errorMessage),
527
+ fatal: true
513
528
  });
514
529
  }
515
530
  }, 3e4);
531
+ let hasLoaded = false;
516
532
  map.on("load", () => {
533
+ hasLoaded = true;
517
534
  clearTimeout(initTimeoutId);
518
535
  setMapLoaded(true);
519
536
  if (bounds) {
@@ -526,25 +543,36 @@ var Map2 = React26.forwardRef(
526
543
  });
527
544
  map.on("error", (e) => {
528
545
  const errorMessage = e.error?.message || "Map error";
529
- const isTransient = errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
546
+ const isTransient = hasLoaded || errorMessage.includes("non-existing layer") || errorMessage.includes("Cannot filter");
530
547
  if (!isTransient) {
531
548
  clearTimeout(initTimeoutId);
532
549
  setMapError(errorMessage);
533
550
  }
534
- onErrorRef.current?.({ type: "error", message: errorMessage, error: e.error });
551
+ onErrorRef.current?.({
552
+ type: "error",
553
+ message: errorMessage,
554
+ error: e.error,
555
+ fatal: !isTransient
556
+ });
535
557
  });
536
558
  return () => {
537
559
  clearTimeout(initTimeoutId);
538
560
  map.remove();
539
561
  mapRef.current = null;
540
562
  setMapLoaded(false);
563
+ styleInitialized.current = false;
541
564
  };
542
565
  } catch (err) {
543
566
  const errorMessage = err instanceof Error ? err.message : "Failed to initialize map";
544
567
  setMapError(errorMessage);
545
- onErrorRef.current?.({ type: "error", message: errorMessage, error: err });
568
+ onErrorRef.current?.({
569
+ type: "error",
570
+ message: errorMessage,
571
+ error: err,
572
+ fatal: true
573
+ });
546
574
  }
547
- }, []);
575
+ }, [initAttempt]);
548
576
  React26.useEffect(() => {
549
577
  const map = mapRef.current;
550
578
  if (!map || !mapLoaded) return;
@@ -687,6 +715,7 @@ var Map2 = React26.forwardRef(
687
715
  width,
688
716
  loading,
689
717
  error: combinedError,
718
+ onRetry: mapError && !error ? retryInit : void 0,
690
719
  emptyMessage,
691
720
  className,
692
721
  children: /* @__PURE__ */ jsxs(MapContext.Provider, { value: contextValue, children: [
@@ -720,6 +749,7 @@ var Source = ({
720
749
  const { map, loaded, styleVersion } = useMap();
721
750
  const initialFitDone = React26.useRef(false);
722
751
  const lastStyleVersionRef = React26.useRef(styleVersion);
752
+ const appliedDataRef = React26.useRef(void 0);
723
753
  const fitBoundsParamsRef = React26.useRef({
724
754
  shouldFitBounds,
725
755
  data,
@@ -873,6 +903,7 @@ var Source = ({
873
903
  };
874
904
  map.once("idle", handleIdle);
875
905
  map.addSource(id, sourceConfig);
906
+ appliedDataRef.current = type === "geojson" ? data : void 0;
876
907
  const source = map.getSource(id);
877
908
  if (source && map.isSourceLoaded(id)) {
878
909
  map.off("sourcedata", handleSourceData);
@@ -939,6 +970,7 @@ var Source = ({
939
970
  try {
940
971
  const newData = typeof data === "string" ? data : data && typeof data === "object" ? data : null;
941
972
  if (!newData) return;
973
+ if (data === appliedDataRef.current) return;
942
974
  const handleSourceData = (e) => {
943
975
  if (cancelled) return;
944
976
  if (e.sourceId === id && e.isSourceLoaded) {
@@ -950,6 +982,7 @@ var Source = ({
950
982
  map.on("sourcedata", handleSourceData);
951
983
  }
952
984
  source.setData(newData);
985
+ appliedDataRef.current = data;
953
986
  return () => {
954
987
  cancelled = true;
955
988
  if (cluster) {
@@ -1176,24 +1209,34 @@ var Marker = React26.forwardRef(
1176
1209
  }
1177
1210
  );
1178
1211
  Marker.displayName = "Marker";
1212
+ function useStructuralValue(next) {
1213
+ const ref = React26.useRef(next);
1214
+ if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1215
+ ref.current = next;
1216
+ }
1217
+ return ref.current;
1218
+ }
1179
1219
  var Popup = React26.forwardRef(
1180
1220
  ({
1181
- coordinates,
1221
+ coordinates: coordinatesProp,
1182
1222
  closeButton = true,
1183
1223
  closeOnClick = true,
1184
1224
  closeOnMove = false,
1185
1225
  anchor,
1186
- offset,
1226
+ offset: offsetProp,
1187
1227
  maxWidth = "300px",
1188
1228
  focusAfterOpen = true,
1189
1229
  autoPan = true,
1190
- autoPanPadding = 50,
1230
+ autoPanPadding: autoPanPaddingProp = 50,
1191
1231
  open = true,
1192
1232
  onOpen,
1193
1233
  onClose,
1194
1234
  children
1195
1235
  }, ref) => {
1196
1236
  const { map, loaded } = useMap();
1237
+ const coordinates = useStructuralValue(coordinatesProp);
1238
+ const offset = useStructuralValue(offsetProp);
1239
+ const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1197
1240
  const popupRef = React26.useRef(null);
1198
1241
  const onOpenRef = React26.useRef(onOpen);
1199
1242
  onOpenRef.current = onOpen;
@@ -1207,6 +1250,7 @@ var Popup = React26.forwardRef(
1207
1250
  containerRef.current.className = "maplibregl-popup-content-wrapper";
1208
1251
  }
1209
1252
  const [contentReady, setContentReady] = React26.useState(false);
1253
+ const [popupVersion, setPopupVersion] = React26.useState(0);
1210
1254
  const contentCallbackRef = React26.useCallback((node) => {
1211
1255
  if (node && containerRef.current) {
1212
1256
  setContentReady(true);
@@ -1225,6 +1269,7 @@ var Popup = React26.forwardRef(
1225
1269
  });
1226
1270
  popup.setDOMContent(containerRef.current);
1227
1271
  popupRef.current = popup;
1272
+ setPopupVersion((v) => v + 1);
1228
1273
  popup.on("open", () => {
1229
1274
  onOpenRef.current?.({
1230
1275
  type: "open",
@@ -1259,7 +1304,7 @@ var Popup = React26.forwardRef(
1259
1304
  } else {
1260
1305
  ref.current = popupRef.current;
1261
1306
  }
1262
- }, [ref]);
1307
+ }, [ref, popupVersion]);
1263
1308
  React26.useEffect(() => {
1264
1309
  if (popupRef.current) {
1265
1310
  popupRef.current.setLngLat(coordinates);
@@ -1285,7 +1330,7 @@ var Popup = React26.forwardRef(
1285
1330
  cancelAnimationFrame(rafHandle);
1286
1331
  }
1287
1332
  };
1288
- }, [map, open, coordinates, autoPan, autoPanPadding, contentReady]);
1333
+ }, [map, open, coordinates, autoPan, autoPanPadding, contentReady, popupVersion]);
1289
1334
  if (!containerRef.current) return null;
1290
1335
  return ReactDOM.createPortal(
1291
1336
  /* @__PURE__ */ jsx("div", { ref: contentCallbackRef, children }),
@@ -1475,10 +1520,34 @@ function useLayer({
1475
1520
  } catch {
1476
1521
  }
1477
1522
  }, [map, id, paint, layerAdded]);
1523
+ const lastAppliedLayoutRef = React26.useRef(void 0);
1524
+ React26.useEffect(() => {
1525
+ if (!map || !layerAdded) return;
1526
+ if (!map.getLayer(id)) return;
1527
+ const next = { ...layout };
1528
+ delete next.visibility;
1529
+ const diff = getChangedPaintProps(lastAppliedLayoutRef.current, next);
1530
+ if (!diff.hasChanges) return;
1531
+ try {
1532
+ for (const [key, value] of Object.entries(diff.changed)) {
1533
+ map.setLayoutProperty(id, key, value);
1534
+ }
1535
+ for (const key of diff.removed) {
1536
+ map.setLayoutProperty(id, key, void 0);
1537
+ }
1538
+ lastAppliedLayoutRef.current = next;
1539
+ } catch {
1540
+ }
1541
+ }, [map, id, layout, layerAdded]);
1478
1542
  React26.useEffect(() => {
1479
- if (!map || !layerAdded || !filter) return;
1543
+ if (!map || !layerAdded) return;
1544
+ if (!map.getLayer(id)) return;
1545
+ map.setLayerZoomRange(id, minZoom ?? 0, maxZoom ?? 24);
1546
+ }, [map, id, minZoom, maxZoom, layerAdded]);
1547
+ React26.useEffect(() => {
1548
+ if (!map || !layerAdded) return;
1480
1549
  if (!map.getLayer(id)) return;
1481
- map.setFilter(id, filter);
1550
+ map.setFilter(id, filter ?? null);
1482
1551
  }, [map, id, filter, layerAdded]);
1483
1552
  React26.useEffect(() => {
1484
1553
  if (!map || !layerAdded) return;
@@ -2675,7 +2744,7 @@ var BasemapSwitcher = ({
2675
2744
  children: /* @__PURE__ */ jsx(
2676
2745
  "div",
2677
2746
  {
2678
- role: "listbox",
2747
+ role: "group",
2679
2748
  "aria-label": "Select basemap",
2680
2749
  className: "grid gap-1.5",
2681
2750
  style: {
@@ -2688,8 +2757,7 @@ var BasemapSwitcher = ({
2688
2757
  "button",
2689
2758
  {
2690
2759
  type: "button",
2691
- role: "option",
2692
- "aria-selected": isActive,
2760
+ "aria-pressed": isActive,
2693
2761
  className: cn(
2694
2762
  "flex flex-col items-center gap-1 p-1 rounded cursor-pointer",
2695
2763
  "hover:bg-muted transition-colors",
@@ -2702,7 +2770,7 @@ var BasemapSwitcher = ({
2702
2770
  "img",
2703
2771
  {
2704
2772
  src: thumbUrl,
2705
- alt: basemap.name,
2773
+ alt: "",
2706
2774
  loading: "lazy",
2707
2775
  className: "rounded object-cover",
2708
2776
  style: {
@@ -2787,6 +2855,15 @@ var LayerManager = ({
2787
2855
  const uniqueId = React26.useId();
2788
2856
  const managerId = `layer-manager${uniqueId}`;
2789
2857
  const lastLayerIdsRef = React26.useRef(new Set(layers.map((l) => l.id)));
2858
+ const tilesCacheRef = React26.useRef(/* @__PURE__ */ new Map());
2859
+ const getTiles = (url) => {
2860
+ let tiles = tilesCacheRef.current.get(url);
2861
+ if (!tiles) {
2862
+ tiles = [url];
2863
+ tilesCacheRef.current.set(url, tiles);
2864
+ }
2865
+ return tiles;
2866
+ };
2790
2867
  const { style, visible, setExpanded } = useControlPosition(containerRef, {
2791
2868
  id: managerId,
2792
2869
  type: "layer-manager",
@@ -3040,8 +3117,7 @@ var LayerManager = ({
3040
3117
  id: sourceId,
3041
3118
  type: layer.source.type === "vector-tiles" ? "vector" : "geojson",
3042
3119
  data: layer.source.type !== "vector-tiles" ? sourceData : void 0,
3043
- url: layer.source.type === "vector-tiles" ? sourceUrl ?? void 0 : void 0,
3044
- tiles: layer.source.type === "vector-tiles" ? [sourceUrl ?? ""] : void 0,
3120
+ tiles: layer.source.type === "vector-tiles" ? getTiles(sourceUrl ?? "") : void 0,
3045
3121
  attribution: layer.source.attribution,
3046
3122
  children: layerComponent
3047
3123
  },
@@ -3118,7 +3194,8 @@ var LayerManager = ({
3118
3194
  type: "button",
3119
3195
  className: "text-muted-foreground hover:text-foreground p-1",
3120
3196
  onClick: () => setExpandedOpacity(expandedOpacity === layer.id ? null : layer.id),
3121
- "aria-label": "Adjust opacity",
3197
+ "aria-label": `Adjust ${layer.name} opacity`,
3198
+ "aria-expanded": expandedOpacity === layer.id,
3122
3199
  children: /* @__PURE__ */ jsxs(
3123
3200
  "svg",
3124
3201
  {
@@ -3145,6 +3222,7 @@ var LayerManager = ({
3145
3222
  if (expandedOpacity !== layerId) return null;
3146
3223
  const state = layerStates.get(layerId);
3147
3224
  if (!state) return null;
3225
+ const layerName = layers.find((l) => l.id === layerId)?.name ?? layerId;
3148
3226
  return /* @__PURE__ */ jsx("div", { className: "px-3 pb-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3149
3227
  /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground w-12", children: "Opacity" }),
3150
3228
  /* @__PURE__ */ jsx(
@@ -3154,6 +3232,8 @@ var LayerManager = ({
3154
3232
  min: "0",
3155
3233
  max: "100",
3156
3234
  value: state.opacity * 100,
3235
+ "aria-label": `${layerName} opacity`,
3236
+ "aria-valuetext": `${Math.round(state.opacity * 100)}%`,
3157
3237
  onChange: (e) => handleOpacityChange(layerId, Number(e.target.value) / 100),
3158
3238
  className: "classic-layer-opacity-slider flex-1"
3159
3239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-react",
3
- "version": "0.3.1",
3
+ "version": "0.5.2",
4
4
  "description": "React MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",
@@ -74,7 +74,8 @@
74
74
  "react": "^18.2.0",
75
75
  "react-dom": "^18.2.0",
76
76
  "tsup": "^8.0.0",
77
- "typescript": "^5.3.0"
77
+ "typescript": "^5.3.0",
78
+ "vitest": "^4.1.10"
78
79
  },
79
80
  "publishConfig": {
80
81
  "access": "public"