@dxos/react-ui-geo 0.8.4-main.40e3dcdf1b → 0.8.4-main.422d1c7879
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/lib/browser/index.mjs +102 -95
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +102 -95
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts +5 -3
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +6 -4
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +10 -4
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts +1 -3
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +4 -4
- package/dist/types/src/util/render.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -18
- package/src/components/Globe/Globe.stories.tsx +5 -6
- package/src/components/Globe/Globe.tsx +47 -21
- package/src/components/Map/Map.stories.tsx +7 -6
- package/src/components/Map/Map.tsx +64 -25
- package/src/components/Toolbar/Controls.tsx +4 -4
- package/src/hooks/context.tsx +5 -34
- package/src/hooks/useSpinner.ts +0 -1
- package/src/translations.ts +4 -4
- package/src/util/render.ts +0 -1
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
637
|
-
"zoom
|
|
638
|
-
"start
|
|
639
|
-
"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__ */
|
|
627
|
+
return /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
655
628
|
classNames: [
|
|
656
629
|
"gap-2",
|
|
657
630
|
classNames
|
|
658
631
|
]
|
|
659
|
-
}, /* @__PURE__ */
|
|
632
|
+
}, /* @__PURE__ */ React.createElement(IconButton, {
|
|
660
633
|
icon: "ph--plus--regular",
|
|
661
634
|
iconOnly: true,
|
|
662
|
-
label: t("zoom
|
|
635
|
+
label: t("zoom-in-icon.button"),
|
|
663
636
|
onClick: () => onAction?.("zoom-in")
|
|
664
|
-
}), /* @__PURE__ */
|
|
637
|
+
}), /* @__PURE__ */ React.createElement(IconButton, {
|
|
665
638
|
icon: "ph--minus--regular",
|
|
666
639
|
iconOnly: true,
|
|
667
|
-
label: t("zoom
|
|
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__ */
|
|
646
|
+
return /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
674
647
|
classNames: [
|
|
675
648
|
"gap-2",
|
|
676
649
|
classNames
|
|
677
650
|
]
|
|
678
|
-
}, /* @__PURE__ */
|
|
651
|
+
}, /* @__PURE__ */ React.createElement(IconButton, {
|
|
679
652
|
icon: "ph--path--regular",
|
|
680
653
|
iconOnly: true,
|
|
681
|
-
label: t("start
|
|
654
|
+
label: t("start-icon.button"),
|
|
682
655
|
onClick: () => onAction?.("start")
|
|
683
|
-
}), /* @__PURE__ */
|
|
656
|
+
}), /* @__PURE__ */ React.createElement(IconButton, {
|
|
684
657
|
icon: "ph--globe-hemisphere-west--regular",
|
|
685
658
|
iconOnly: true,
|
|
686
|
-
label: t("toggle
|
|
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 = ({
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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], [
|
|
@@ -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__ */
|
|
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__ */
|
|
846
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
855
847
|
className: mx("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm", controlPositions[position])
|
|
856
|
-
}, /* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
867
|
+
var GlobeZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
|
|
876
868
|
position,
|
|
877
869
|
...props
|
|
878
|
-
}, /* @__PURE__ */
|
|
870
|
+
}, /* @__PURE__ */ React2.createElement(ZoomControls, {
|
|
879
871
|
onAction
|
|
880
872
|
}));
|
|
881
|
-
var GlobeAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */
|
|
873
|
+
var GlobeAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
|
|
882
874
|
position,
|
|
883
875
|
...props
|
|
884
|
-
}, /* @__PURE__ */
|
|
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
|
|
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
|
|
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 [
|
|
913
|
-
var MapRoot =
|
|
914
|
-
const
|
|
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,23 +942,22 @@ var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true,
|
|
|
935
942
|
map,
|
|
936
943
|
attention
|
|
937
944
|
]);
|
|
938
|
-
return /* @__PURE__ */
|
|
939
|
-
attention,
|
|
940
|
-
onChange
|
|
941
|
-
}, /* @__PURE__ */ React4.createElement(MapContainer, {
|
|
945
|
+
return /* @__PURE__ */ React3.createElement(MapContainer, {
|
|
942
946
|
...props,
|
|
943
|
-
|
|
944
|
-
className: mx2("group relative grid h-full w-full !bg-base-surface 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 ??
|
|
951
|
-
zoom: zoom ??
|
|
952
|
-
|
|
953
|
+
center: center ?? defaults.center,
|
|
954
|
+
zoom: zoom ?? defaults.zoom,
|
|
955
|
+
whenReady: () => {
|
|
956
|
+
},
|
|
957
|
+
ref: mapRef
|
|
958
|
+
}, children);
|
|
953
959
|
});
|
|
954
|
-
|
|
960
|
+
MapContent.displayName = "Map.Content";
|
|
955
961
|
var MAP_TILES_NAME = "Map.Tiles";
|
|
956
962
|
var MapTiles = (_props) => {
|
|
957
963
|
const ref = useRef2(null);
|
|
@@ -972,7 +978,7 @@ var MapTiles = (_props) => {
|
|
|
972
978
|
}, [
|
|
973
979
|
attention
|
|
974
980
|
]);
|
|
975
|
-
return /* @__PURE__ */
|
|
981
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(TileLayer, {
|
|
976
982
|
ref,
|
|
977
983
|
"data-attention": attention,
|
|
978
984
|
detectRetina: true,
|
|
@@ -989,13 +995,13 @@ var MapMarkers = ({ selected, markers }) => {
|
|
|
989
995
|
const bounds = latLngBounds(markers.map((marker) => marker.location));
|
|
990
996
|
map.fitBounds(bounds);
|
|
991
997
|
} else {
|
|
992
|
-
map.setView(
|
|
998
|
+
map.setView(defaults.center, defaults.zoom);
|
|
993
999
|
}
|
|
994
1000
|
}, [
|
|
995
1001
|
markers
|
|
996
1002
|
]);
|
|
997
|
-
return /* @__PURE__ */
|
|
998
|
-
return /* @__PURE__ */
|
|
1003
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, markers?.map(({ id, title, location: { lat, lng } }) => {
|
|
1004
|
+
return /* @__PURE__ */ React3.createElement(Marker, {
|
|
999
1005
|
key: id,
|
|
1000
1006
|
position: {
|
|
1001
1007
|
lat,
|
|
@@ -1026,7 +1032,7 @@ var MapMarkers = ({ selected, markers }) => {
|
|
|
1026
1032
|
]
|
|
1027
1033
|
})
|
|
1028
1034
|
)
|
|
1029
|
-
}, title && /* @__PURE__ */
|
|
1035
|
+
}, title && /* @__PURE__ */ React3.createElement(Popup, null, title));
|
|
1030
1036
|
}));
|
|
1031
1037
|
};
|
|
1032
1038
|
MapMarkers.displayName = "Map.Markers";
|
|
@@ -1041,9 +1047,9 @@ var CustomControl2 = ({ position, children }) => {
|
|
|
1041
1047
|
DomEvent.disableClickPropagation(container);
|
|
1042
1048
|
DomEvent.disableScrollPropagation(container);
|
|
1043
1049
|
const root = createRoot(container);
|
|
1044
|
-
root.render(/* @__PURE__ */
|
|
1050
|
+
root.render(/* @__PURE__ */ React3.createElement(ThemeProvider, {
|
|
1045
1051
|
tx: defaultTx
|
|
1046
|
-
}, /* @__PURE__ */
|
|
1052
|
+
}, /* @__PURE__ */ React3.createElement(Tooltip.Provider, null, children)));
|
|
1047
1053
|
return container;
|
|
1048
1054
|
};
|
|
1049
1055
|
control.addTo(map);
|
|
@@ -1057,20 +1063,21 @@ var CustomControl2 = ({ position, children }) => {
|
|
|
1057
1063
|
]);
|
|
1058
1064
|
return null;
|
|
1059
1065
|
};
|
|
1060
|
-
var MapZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */
|
|
1066
|
+
var MapZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
|
|
1061
1067
|
position,
|
|
1062
1068
|
...props
|
|
1063
|
-
}, /* @__PURE__ */
|
|
1069
|
+
}, /* @__PURE__ */ React3.createElement(ZoomControls, {
|
|
1064
1070
|
onAction
|
|
1065
1071
|
}));
|
|
1066
|
-
var MapAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */
|
|
1072
|
+
var MapAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
|
|
1067
1073
|
position,
|
|
1068
1074
|
...props
|
|
1069
|
-
}, /* @__PURE__ */
|
|
1075
|
+
}, /* @__PURE__ */ React3.createElement(ActionControls, {
|
|
1070
1076
|
onAction
|
|
1071
1077
|
}));
|
|
1072
1078
|
var Map = {
|
|
1073
1079
|
Root: MapRoot,
|
|
1080
|
+
Content: MapContent,
|
|
1074
1081
|
Tiles: MapTiles,
|
|
1075
1082
|
Markers: MapMarkers,
|
|
1076
1083
|
Zoom: MapZoom,
|
|
@@ -1079,7 +1086,7 @@ var Map = {
|
|
|
1079
1086
|
export {
|
|
1080
1087
|
ActionControls,
|
|
1081
1088
|
Globe,
|
|
1082
|
-
|
|
1089
|
+
GlobeContext,
|
|
1083
1090
|
Map,
|
|
1084
1091
|
ZoomControls,
|
|
1085
1092
|
closestPoint,
|