@classic-homes/maps-react 0.3.1 → 0.4.0

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
@@ -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: [
@@ -1200,24 +1229,34 @@ var Marker = React26__namespace.forwardRef(
1200
1229
  }
1201
1230
  );
1202
1231
  Marker.displayName = "Marker";
1232
+ function useStructuralValue(next) {
1233
+ const ref = React26__namespace.useRef(next);
1234
+ if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1235
+ ref.current = next;
1236
+ }
1237
+ return ref.current;
1238
+ }
1203
1239
  var Popup = React26__namespace.forwardRef(
1204
1240
  ({
1205
- coordinates,
1241
+ coordinates: coordinatesProp,
1206
1242
  closeButton = true,
1207
1243
  closeOnClick = true,
1208
1244
  closeOnMove = false,
1209
1245
  anchor,
1210
- offset,
1246
+ offset: offsetProp,
1211
1247
  maxWidth = "300px",
1212
1248
  focusAfterOpen = true,
1213
1249
  autoPan = true,
1214
- autoPanPadding = 50,
1250
+ autoPanPadding: autoPanPaddingProp = 50,
1215
1251
  open = true,
1216
1252
  onOpen,
1217
1253
  onClose,
1218
1254
  children
1219
1255
  }, ref) => {
1220
1256
  const { map, loaded } = useMap();
1257
+ const coordinates = useStructuralValue(coordinatesProp);
1258
+ const offset = useStructuralValue(offsetProp);
1259
+ const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1221
1260
  const popupRef = React26__namespace.useRef(null);
1222
1261
  const onOpenRef = React26__namespace.useRef(onOpen);
1223
1262
  onOpenRef.current = onOpen;
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: [
@@ -1176,24 +1205,34 @@ var Marker = React26.forwardRef(
1176
1205
  }
1177
1206
  );
1178
1207
  Marker.displayName = "Marker";
1208
+ function useStructuralValue(next) {
1209
+ const ref = React26.useRef(next);
1210
+ if (ref.current !== next && JSON.stringify(ref.current) !== JSON.stringify(next)) {
1211
+ ref.current = next;
1212
+ }
1213
+ return ref.current;
1214
+ }
1179
1215
  var Popup = React26.forwardRef(
1180
1216
  ({
1181
- coordinates,
1217
+ coordinates: coordinatesProp,
1182
1218
  closeButton = true,
1183
1219
  closeOnClick = true,
1184
1220
  closeOnMove = false,
1185
1221
  anchor,
1186
- offset,
1222
+ offset: offsetProp,
1187
1223
  maxWidth = "300px",
1188
1224
  focusAfterOpen = true,
1189
1225
  autoPan = true,
1190
- autoPanPadding = 50,
1226
+ autoPanPadding: autoPanPaddingProp = 50,
1191
1227
  open = true,
1192
1228
  onOpen,
1193
1229
  onClose,
1194
1230
  children
1195
1231
  }, ref) => {
1196
1232
  const { map, loaded } = useMap();
1233
+ const coordinates = useStructuralValue(coordinatesProp);
1234
+ const offset = useStructuralValue(offsetProp);
1235
+ const autoPanPadding = useStructuralValue(autoPanPaddingProp);
1197
1236
  const popupRef = React26.useRef(null);
1198
1237
  const onOpenRef = React26.useRef(onOpen);
1199
1238
  onOpenRef.current = onOpen;
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.4.0",
4
4
  "description": "React MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",