@dxos/react-ui-geo 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe

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.
@@ -4,42 +4,15 @@ import {
4
4
 
5
5
  // src/components/Globe/Globe.tsx
6
6
  import { easeLinear, easeSinOut, geoMercator, geoOrthographic, geoPath as geoPath2, geoTransverseMercator, interpolateNumber, transition } from "d3";
7
- import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo2, useRef, useState as useState3 } from "react";
7
+ import React2, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo2, useRef, useState as useState3 } from "react";
8
8
  import { useResizeDetector } from "react-resize-detector";
9
- import { useDynamicRef, useThemeContext } from "@dxos/react-ui";
10
- import { mx } from "@dxos/ui-theme";
9
+ import { useComposedRefs, useControlledState, useDynamicRef, useThemeContext } from "@dxos/react-ui";
10
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
11
11
 
12
12
  // src/hooks/context.tsx
13
- import React, { createContext, useContext } from "react";
13
+ import { createContext, useContext } from "react";
14
14
  import { raise } from "@dxos/debug";
15
- import { useControlledState } from "@dxos/react-ui";
16
- var defaults = {
17
- center: {
18
- lat: 51,
19
- lng: 0
20
- },
21
- zoom: 4
22
- };
23
15
  var GlobeContext = /* @__PURE__ */ createContext(void 0);
24
- var GlobeContextProvider = ({ children, size, center: centerProp = defaults.center, zoom: zoomProp = defaults.zoom, translation: translationProp, rotation: rotationProp }) => {
25
- const [center, setCenter] = useControlledState(centerProp);
26
- const [zoom, setZoom] = useControlledState(zoomProp);
27
- const [translation, setTranslation] = useControlledState(translationProp);
28
- const [rotation, setRotation] = useControlledState(rotationProp);
29
- return /* @__PURE__ */ React.createElement(GlobeContext.Provider, {
30
- value: {
31
- size,
32
- center,
33
- zoom,
34
- translation,
35
- rotation,
36
- setCenter,
37
- setZoom,
38
- setTranslation,
39
- setRotation
40
- }
41
- }, children);
42
- };
43
16
  var useGlobeContext = () => {
44
17
  return useContext(GlobeContext) ?? raise(new Error("Missing GlobeContext"));
45
18
  };
@@ -624,7 +597,7 @@ var useTour = (controller, points, options = {}) => {
624
597
  };
625
598
 
626
599
  // src/components/Toolbar/Controls.tsx
627
- import React2 from "react";
600
+ import React from "react";
628
601
  import { IconButton, Toolbar, useTranslation } from "@dxos/react-ui";
629
602
 
630
603
  // src/translations.ts
@@ -633,10 +606,10 @@ var translations = [
633
606
  {
634
607
  "en-US": {
635
608
  [translationKey]: {
636
- "zoom in icon button": "Zoom in",
637
- "zoom out icon button": "Zoom out",
638
- "start icon button": "Start",
639
- "toggle icon button": "Toggle"
609
+ "zoom-in-icon.button": "Zoom in",
610
+ "zoom-out-icon.button": "Zoom out",
611
+ "start-icon.button": "Start",
612
+ "toggle-icon.button": "Toggle"
640
613
  }
641
614
  }
642
615
  }
@@ -651,39 +624,39 @@ var controlPositions = {
651
624
  };
652
625
  var ZoomControls = ({ classNames, onAction }) => {
653
626
  const { t } = useTranslation(translationKey);
654
- return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
627
+ return /* @__PURE__ */ React.createElement(Toolbar.Root, {
655
628
  classNames: [
656
629
  "gap-2",
657
630
  classNames
658
631
  ]
659
- }, /* @__PURE__ */ React2.createElement(IconButton, {
632
+ }, /* @__PURE__ */ React.createElement(IconButton, {
660
633
  icon: "ph--plus--regular",
661
634
  iconOnly: true,
662
- label: t("zoom in icon button"),
635
+ label: t("zoom-in-icon.button"),
663
636
  onClick: () => onAction?.("zoom-in")
664
- }), /* @__PURE__ */ React2.createElement(IconButton, {
637
+ }), /* @__PURE__ */ React.createElement(IconButton, {
665
638
  icon: "ph--minus--regular",
666
639
  iconOnly: true,
667
- label: t("zoom out icon button"),
640
+ label: t("zoom-out-icon.button"),
668
641
  onClick: () => onAction?.("zoom-out")
669
642
  }));
670
643
  };
671
644
  var ActionControls = ({ classNames, onAction }) => {
672
645
  const { t } = useTranslation(translationKey);
673
- return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
646
+ return /* @__PURE__ */ React.createElement(Toolbar.Root, {
674
647
  classNames: [
675
648
  "gap-2",
676
649
  classNames
677
650
  ]
678
- }, /* @__PURE__ */ React2.createElement(IconButton, {
651
+ }, /* @__PURE__ */ React.createElement(IconButton, {
679
652
  icon: "ph--path--regular",
680
653
  iconOnly: true,
681
- label: t("start icon button"),
654
+ label: t("start-icon.button"),
682
655
  onClick: () => onAction?.("start")
683
- }), /* @__PURE__ */ React2.createElement(IconButton, {
656
+ }), /* @__PURE__ */ React.createElement(IconButton, {
684
657
  icon: "ph--globe-hemisphere-west--regular",
685
658
  iconOnly: true,
686
- label: t("toggle icon button"),
659
+ label: t("toggle-icon.button"),
687
660
  onClick: () => onAction?.("toggle")
688
661
  }));
689
662
  };
@@ -743,19 +716,38 @@ var getProjection = (type = "orthographic") => {
743
716
  }
744
717
  return type ?? geoOrthographic();
745
718
  };
746
- var GlobeRoot = ({ classNames, children, ...props }) => {
747
- const { ref, width, height } = useResizeDetector();
748
- return /* @__PURE__ */ React3.createElement("div", {
749
- ref,
750
- className: mx("relative flex grow overflow-hidden", classNames)
751
- }, /* @__PURE__ */ React3.createElement(GlobeContextProvider, {
752
- size: {
753
- width,
754
- height
755
- },
756
- ...props
719
+ var GlobeRoot = composable(({ children, center: centerProp, zoom: zoomProp, translation: translationProp, rotation: rotationProp, ...props }, forwardedRef) => {
720
+ const localRef = useRef(null);
721
+ const composedRef = useComposedRefs(localRef, forwardedRef);
722
+ const { width, height } = useResizeDetector({
723
+ targetRef: localRef
724
+ });
725
+ const [center, setCenter] = useControlledState(centerProp);
726
+ const [zoom, setZoom] = useControlledState(zoomProp ?? 4);
727
+ const [translation, setTranslation] = useControlledState(translationProp);
728
+ const [rotation, setRotation] = useControlledState(rotationProp);
729
+ return /* @__PURE__ */ React2.createElement(GlobeContext.Provider, {
730
+ value: {
731
+ size: {
732
+ width,
733
+ height
734
+ },
735
+ center,
736
+ zoom,
737
+ translation,
738
+ rotation,
739
+ setCenter,
740
+ setZoom,
741
+ setTranslation,
742
+ setRotation
743
+ }
744
+ }, /* @__PURE__ */ React2.createElement("div", {
745
+ ...composableProps(props, {
746
+ classNames: "relative dx-container"
747
+ }),
748
+ ref: composedRef
757
749
  }, children));
758
- };
750
+ });
759
751
  var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionProp, topology, features, styles: stylesProp }, forwardRef3) => {
760
752
  const { themeMode } = useThemeContext();
761
753
  const styles = useMemo2(() => stylesProp ?? defaultStyles[themeMode], [
@@ -796,14 +788,14 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionProp, topo
796
788
  translation,
797
789
  rotation,
798
790
  setCenter,
799
- setZoom: (s) => {
800
- if (typeof s === "function") {
801
- const is = interpolateNumber(zoomRef.current, s(zoomRef.current));
791
+ setZoom: (state) => {
792
+ if (typeof state === "function") {
793
+ const is = interpolateNumber(zoomRef.current, state(zoomRef.current));
802
794
  transition().ease(zooming.current ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => setZoom(is(t))).on("end", () => {
803
795
  zooming.current = false;
804
796
  });
805
797
  } else {
806
- setZoom(s);
798
+ setZoom(state);
807
799
  }
808
800
  },
809
801
  setTranslation,
@@ -843,7 +835,7 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionProp, topo
843
835
  if (!size.width || !size.height) {
844
836
  return null;
845
837
  }
846
- return /* @__PURE__ */ React3.createElement("canvas", {
838
+ return /* @__PURE__ */ React2.createElement("canvas", {
847
839
  ref: canvasRef,
848
840
  width: size.width,
849
841
  height: size.height
@@ -851,9 +843,9 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionProp, topo
851
843
  });
852
844
  var GlobeDebug = ({ position = "topleft" }) => {
853
845
  const { size, zoom, translation, rotation } = useGlobeContext();
854
- return /* @__PURE__ */ React3.createElement("div", {
855
- className: mx("z-10 absolute is-96 p-2 overflow-hidden border border-green-700 rounded", controlPositions[position])
856
- }, /* @__PURE__ */ React3.createElement("pre", {
846
+ return /* @__PURE__ */ React2.createElement("div", {
847
+ className: mx("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm", controlPositions[position])
848
+ }, /* @__PURE__ */ React2.createElement("pre", {
857
849
  className: "font-mono text-xs text-green-700"
858
850
  }, JSON.stringify({
859
851
  size,
@@ -863,25 +855,25 @@ var GlobeDebug = ({ position = "topleft" }) => {
863
855
  }, null, 2)));
864
856
  };
865
857
  var GlobePanel = ({ position, classNames, children }) => {
866
- return /* @__PURE__ */ React3.createElement("div", {
858
+ return /* @__PURE__ */ React2.createElement("div", {
867
859
  className: mx("z-10 absolute overflow-hidden", controlPositions[position], classNames)
868
860
  }, children);
869
861
  };
870
862
  var CustomControl = ({ position, children }) => {
871
- return /* @__PURE__ */ React3.createElement("div", {
863
+ return /* @__PURE__ */ React2.createElement("div", {
872
864
  className: mx("z-10 absolute overflow-hidden", controlPositions[position])
873
865
  }, children);
874
866
  };
875
- var GlobeZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl, {
867
+ var GlobeZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
876
868
  position,
877
869
  ...props
878
- }, /* @__PURE__ */ React3.createElement(ZoomControls, {
870
+ }, /* @__PURE__ */ React2.createElement(ZoomControls, {
879
871
  onAction
880
872
  }));
881
- var GlobeAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl, {
873
+ var GlobeAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
882
874
  position,
883
875
  ...props
884
- }, /* @__PURE__ */ React3.createElement(ActionControls, {
876
+ }, /* @__PURE__ */ React2.createElement(ActionControls, {
885
877
  onAction
886
878
  }));
887
879
  var Globe = {
@@ -897,21 +889,36 @@ var Globe = {
897
889
  import "leaflet/dist/leaflet.css";
898
890
  import { createContext as createContext2 } from "@radix-ui/react-context";
899
891
  import L, { Control, DomEvent, DomUtil, latLngBounds } from "leaflet";
900
- import React4, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef2, useState as useState4 } from "react";
892
+ import React3, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef2 } from "react";
901
893
  import { createRoot } from "react-dom/client";
902
894
  import { MapContainer, Marker, Popup, TileLayer, useMap, useMapEvents } from "react-leaflet";
903
895
  import { ThemeProvider, Tooltip } from "@dxos/react-ui";
904
- import { defaultTx, mx as mx2 } from "@dxos/ui-theme";
905
- var defaults2 = {
896
+ import { composable as composable2, composableProps as composableProps2, defaultTx, mx as mx2 } from "@dxos/ui-theme";
897
+ var defaults = {
906
898
  center: {
907
899
  lat: 51,
908
900
  lng: 0
909
901
  },
910
902
  zoom: 4
911
903
  };
912
- var [MapContextProvier, useMapContext] = createContext2("Map");
913
- var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, onChange, ...props }, forwardedRef) => {
914
- const [attention, setAttention] = useState4(false);
904
+ var [MapContextProvider, useMapContext] = createContext2("Map");
905
+ var MapRoot = composable2(({ children, onChange, ...props }, forwardedRef) => {
906
+ const attention = false;
907
+ return /* @__PURE__ */ React3.createElement(MapContextProvider, {
908
+ attention,
909
+ onChange
910
+ }, /* @__PURE__ */ React3.createElement("div", {
911
+ ...composableProps2(props, {
912
+ role: "none",
913
+ classNames: "dx-container grid dx-focus-ring-inset"
914
+ }),
915
+ ref: forwardedRef
916
+ }, children));
917
+ });
918
+ MapRoot.displayName = "Map.Root";
919
+ var MAP_CONTENT_NAME = "Map.Content";
920
+ var MapContent = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, children, ...props }, forwardedRef) => {
921
+ const { attention } = useMapContext(MAP_CONTENT_NAME);
915
922
  const mapRef = useRef2(null);
916
923
  const map = mapRef.current;
917
924
  useImperativeHandle2(forwardedRef, () => ({
@@ -935,26 +942,26 @@ var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true,
935
942
  map,
936
943
  attention
937
944
  ]);
938
- return /* @__PURE__ */ React4.createElement(MapContextProvier, {
939
- attention,
940
- onChange
941
- }, /* @__PURE__ */ React4.createElement(MapContainer, {
945
+ return /* @__PURE__ */ React3.createElement(MapContainer, {
942
946
  ...props,
943
- ref: mapRef,
944
- className: mx2("group relative grid bs-full is-full !bg-baseSurface dx-focus-ring-inset", classNames),
947
+ className: mx2("group relative grid bg-base-surface!", classNames),
945
948
  attributionControl: false,
946
949
  zoomControl: false,
947
950
  scrollWheelZoom,
948
951
  doubleClickZoom,
949
952
  touchZoom,
950
- center: center ?? defaults2.center,
951
- zoom: zoom ?? defaults2.zoom
952
- }));
953
+ center: center ?? defaults.center,
954
+ zoom: zoom ?? defaults.zoom,
955
+ whenReady: () => {
956
+ },
957
+ ref: mapRef
958
+ }, children);
953
959
  });
954
- MapRoot.displayName = "Map.Root";
960
+ MapContent.displayName = "Map.Content";
961
+ var MAP_TILES_NAME = "Map.Tiles";
955
962
  var MapTiles = (_props) => {
956
963
  const ref = useRef2(null);
957
- const { onChange } = useMapContext(MapTiles.displayName);
964
+ const { onChange } = useMapContext(MAP_TILES_NAME);
958
965
  useMapEvents({
959
966
  zoomstart: (ev) => {
960
967
  onChange?.({
@@ -963,7 +970,7 @@ var MapTiles = (_props) => {
963
970
  });
964
971
  }
965
972
  });
966
- const { attention } = useMapContext(MapTiles.displayName);
973
+ const { attention } = useMapContext(MAP_TILES_NAME);
967
974
  useEffect5(() => {
968
975
  if (ref.current) {
969
976
  ref.current.getContainer().dataset.attention = attention ? "1" : "0";
@@ -971,7 +978,7 @@ var MapTiles = (_props) => {
971
978
  }, [
972
979
  attention
973
980
  ]);
974
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(TileLayer, {
981
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(TileLayer, {
975
982
  ref,
976
983
  "data-attention": attention,
977
984
  detectRetina: true,
@@ -980,7 +987,7 @@ var MapTiles = (_props) => {
980
987
  keepBuffer: 4
981
988
  }));
982
989
  };
983
- MapTiles.displayName = "Map.Tiles";
990
+ MapTiles.displayName = MAP_TILES_NAME;
984
991
  var MapMarkers = ({ selected, markers }) => {
985
992
  const map = useMap();
986
993
  useEffect5(() => {
@@ -988,13 +995,13 @@ var MapMarkers = ({ selected, markers }) => {
988
995
  const bounds = latLngBounds(markers.map((marker) => marker.location));
989
996
  map.fitBounds(bounds);
990
997
  } else {
991
- map.setView(defaults2.center, defaults2.zoom);
998
+ map.setView(defaults.center, defaults.zoom);
992
999
  }
993
1000
  }, [
994
1001
  markers
995
1002
  ]);
996
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, markers?.map(({ id, title, location: { lat, lng } }) => {
997
- return /* @__PURE__ */ React4.createElement(Marker, {
1003
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, markers?.map(({ id, title, location: { lat, lng } }) => {
1004
+ return /* @__PURE__ */ React3.createElement(Marker, {
998
1005
  key: id,
999
1006
  position: {
1000
1007
  lat,
@@ -1025,7 +1032,7 @@ var MapMarkers = ({ selected, markers }) => {
1025
1032
  ]
1026
1033
  })
1027
1034
  )
1028
- }, title && /* @__PURE__ */ React4.createElement(Popup, null, title));
1035
+ }, title && /* @__PURE__ */ React3.createElement(Popup, null, title));
1029
1036
  }));
1030
1037
  };
1031
1038
  MapMarkers.displayName = "Map.Markers";
@@ -1036,13 +1043,13 @@ var CustomControl2 = ({ position, children }) => {
1036
1043
  position
1037
1044
  });
1038
1045
  control.onAdd = () => {
1039
- const container = DomUtil.create("div", mx2("!m-0", controlPositions[position]));
1046
+ const container = DomUtil.create("div", mx2("m-0!", controlPositions[position]));
1040
1047
  DomEvent.disableClickPropagation(container);
1041
1048
  DomEvent.disableScrollPropagation(container);
1042
1049
  const root = createRoot(container);
1043
- root.render(/* @__PURE__ */ React4.createElement(ThemeProvider, {
1050
+ root.render(/* @__PURE__ */ React3.createElement(ThemeProvider, {
1044
1051
  tx: defaultTx
1045
- }, /* @__PURE__ */ React4.createElement(Tooltip.Provider, null, children)));
1052
+ }, /* @__PURE__ */ React3.createElement(Tooltip.Provider, null, children)));
1046
1053
  return container;
1047
1054
  };
1048
1055
  control.addTo(map);
@@ -1056,20 +1063,21 @@ var CustomControl2 = ({ position, children }) => {
1056
1063
  ]);
1057
1064
  return null;
1058
1065
  };
1059
- var MapZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React4.createElement(CustomControl2, {
1066
+ var MapZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
1060
1067
  position,
1061
1068
  ...props
1062
- }, /* @__PURE__ */ React4.createElement(ZoomControls, {
1069
+ }, /* @__PURE__ */ React3.createElement(ZoomControls, {
1063
1070
  onAction
1064
1071
  }));
1065
- var MapAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React4.createElement(CustomControl2, {
1072
+ var MapAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
1066
1073
  position,
1067
1074
  ...props
1068
- }, /* @__PURE__ */ React4.createElement(ActionControls, {
1075
+ }, /* @__PURE__ */ React3.createElement(ActionControls, {
1069
1076
  onAction
1070
1077
  }));
1071
1078
  var Map = {
1072
1079
  Root: MapRoot,
1080
+ Content: MapContent,
1073
1081
  Tiles: MapTiles,
1074
1082
  Markers: MapMarkers,
1075
1083
  Zoom: MapZoom,
@@ -1078,7 +1086,7 @@ var Map = {
1078
1086
  export {
1079
1087
  ActionControls,
1080
1088
  Globe,
1081
- GlobeContextProvider,
1089
+ GlobeContext,
1082
1090
  Map,
1083
1091
  ZoomControls,
1084
1092
  closestPoint,