@dxos/react-ui-geo 0.8.4-main.bc674ce → 0.8.4-main.bd9b33e6c8

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