@dxos/react-ui-geo 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe
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 +71 -62
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +71 -62
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +3 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.d.ts +6 -9
- package/dist/types/src/components/Map/Map.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts +3 -1
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts +1 -1
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +12 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -20
- package/src/components/Globe/Globe.stories.tsx +6 -5
- package/src/components/Globe/Globe.tsx +5 -4
- package/src/components/Map/Map.stories.tsx +5 -4
- package/src/components/Map/Map.tsx +18 -48
- package/src/components/Toolbar/Controls.tsx +12 -14
- package/src/hooks/context.tsx +14 -8
- package/src/hooks/useGlobeZoomHandler.ts +8 -2
- package/src/hooks/useTour.ts +1 -0
- package/src/index.ts +1 -0
- package/src/translations.ts +20 -0
|
@@ -15,14 +15,21 @@ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
|
15
15
|
import React, { createContext, useContext } from "react";
|
|
16
16
|
import { raise } from "@dxos/debug";
|
|
17
17
|
import { useControlledState } from "@dxos/react-ui";
|
|
18
|
+
var defaults = {
|
|
19
|
+
center: {
|
|
20
|
+
lat: 51,
|
|
21
|
+
lng: 0
|
|
22
|
+
},
|
|
23
|
+
zoom: 4
|
|
24
|
+
};
|
|
18
25
|
var GlobeContext = /* @__PURE__ */ createContext(void 0);
|
|
19
|
-
var GlobeContextProvider = ({ children, size, center:
|
|
26
|
+
var GlobeContextProvider = ({ children, size, center: centerParam = defaults.center, zoom: zoomParam = defaults.zoom, translation: translationParam, rotation: rotationParam }) => {
|
|
20
27
|
var _effect = _useSignals();
|
|
21
28
|
try {
|
|
22
|
-
const [center, setCenter] = useControlledState(
|
|
23
|
-
const [zoom, setZoom] = useControlledState(
|
|
24
|
-
const [translation, setTranslation] = useControlledState(
|
|
25
|
-
const [rotation, setRotation] = useControlledState(
|
|
29
|
+
const [center, setCenter] = useControlledState(centerParam);
|
|
30
|
+
const [zoom, setZoom] = useControlledState(zoomParam);
|
|
31
|
+
const [translation, setTranslation] = useControlledState(translationParam);
|
|
32
|
+
const [rotation, setRotation] = useControlledState(rotationParam);
|
|
26
33
|
return /* @__PURE__ */ React.createElement(GlobeContext.Provider, {
|
|
27
34
|
value: {
|
|
28
35
|
size,
|
|
@@ -376,8 +383,8 @@ var renderLayers = (generator, layers = [], scale, styles) => {
|
|
|
376
383
|
generator.pointRadius(value * scale);
|
|
377
384
|
} else {
|
|
378
385
|
context[key] = value;
|
|
379
|
-
fill
|
|
380
|
-
stroke
|
|
386
|
+
fill ||= key === "fillStyle";
|
|
387
|
+
stroke ||= key === "strokeStyle";
|
|
381
388
|
}
|
|
382
389
|
});
|
|
383
390
|
}
|
|
@@ -427,6 +434,7 @@ var cancelDrag = (node) => node.on(".drag", null);
|
|
|
427
434
|
|
|
428
435
|
// src/hooks/useGlobeZoomHandler.ts
|
|
429
436
|
import { useCallback } from "react";
|
|
437
|
+
var ZOOM_FACTOR = 0.1;
|
|
430
438
|
var useGlobeZoomHandler = (controller) => {
|
|
431
439
|
return useCallback((event) => {
|
|
432
440
|
if (!controller) {
|
|
@@ -434,11 +442,15 @@ var useGlobeZoomHandler = (controller) => {
|
|
|
434
442
|
}
|
|
435
443
|
switch (event) {
|
|
436
444
|
case "zoom-in": {
|
|
437
|
-
controller.setZoom((zoom) =>
|
|
445
|
+
controller.setZoom((zoom) => {
|
|
446
|
+
return zoom * (1 + ZOOM_FACTOR);
|
|
447
|
+
});
|
|
438
448
|
break;
|
|
439
449
|
}
|
|
440
450
|
case "zoom-out": {
|
|
441
|
-
controller.setZoom((zoom) =>
|
|
451
|
+
controller.setZoom((zoom) => {
|
|
452
|
+
return zoom * (1 - ZOOM_FACTOR);
|
|
453
|
+
});
|
|
442
454
|
break;
|
|
443
455
|
}
|
|
444
456
|
}
|
|
@@ -621,7 +633,24 @@ var useTour = (controller, points, options = {}) => {
|
|
|
621
633
|
// src/components/Toolbar/Controls.tsx
|
|
622
634
|
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
623
635
|
import React2 from "react";
|
|
624
|
-
import { IconButton, Toolbar } from "@dxos/react-ui";
|
|
636
|
+
import { IconButton, Toolbar, useTranslation } from "@dxos/react-ui";
|
|
637
|
+
|
|
638
|
+
// src/translations.ts
|
|
639
|
+
var translationKey = "react-ui-geo";
|
|
640
|
+
var translations = [
|
|
641
|
+
{
|
|
642
|
+
"en-US": {
|
|
643
|
+
[translationKey]: {
|
|
644
|
+
"zoom in icon button": "Zoom in",
|
|
645
|
+
"zoom out icon button": "Zoom out",
|
|
646
|
+
"start icon button": "Start",
|
|
647
|
+
"toggle icon button": "Toggle"
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
];
|
|
652
|
+
|
|
653
|
+
// src/components/Toolbar/Controls.tsx
|
|
625
654
|
var controlPositions = {
|
|
626
655
|
topleft: "top-2 left-2",
|
|
627
656
|
topright: "top-2 right-2",
|
|
@@ -631,6 +660,7 @@ var controlPositions = {
|
|
|
631
660
|
var ZoomControls = ({ classNames, onAction }) => {
|
|
632
661
|
var _effect = _useSignals2();
|
|
633
662
|
try {
|
|
663
|
+
const { t } = useTranslation(translationKey);
|
|
634
664
|
return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
|
|
635
665
|
classNames: [
|
|
636
666
|
"gap-2",
|
|
@@ -638,17 +668,13 @@ var ZoomControls = ({ classNames, onAction }) => {
|
|
|
638
668
|
]
|
|
639
669
|
}, /* @__PURE__ */ React2.createElement(IconButton, {
|
|
640
670
|
icon: "ph--plus--regular",
|
|
641
|
-
label: "zoom in",
|
|
642
671
|
iconOnly: true,
|
|
643
|
-
|
|
644
|
-
classNames: "px-0 aspect-square",
|
|
672
|
+
label: t("zoom in icon button"),
|
|
645
673
|
onClick: () => onAction?.("zoom-in")
|
|
646
674
|
}), /* @__PURE__ */ React2.createElement(IconButton, {
|
|
647
675
|
icon: "ph--minus--regular",
|
|
648
|
-
label: "zoom out",
|
|
649
676
|
iconOnly: true,
|
|
650
|
-
|
|
651
|
-
classNames: "px-0 aspect-square",
|
|
677
|
+
label: t("zoom out icon button"),
|
|
652
678
|
onClick: () => onAction?.("zoom-out")
|
|
653
679
|
}));
|
|
654
680
|
} finally {
|
|
@@ -658,24 +684,21 @@ var ZoomControls = ({ classNames, onAction }) => {
|
|
|
658
684
|
var ActionControls = ({ classNames, onAction }) => {
|
|
659
685
|
var _effect = _useSignals2();
|
|
660
686
|
try {
|
|
687
|
+
const { t } = useTranslation(translationKey);
|
|
661
688
|
return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
|
|
662
689
|
classNames: [
|
|
663
690
|
"gap-2",
|
|
664
691
|
classNames
|
|
665
692
|
]
|
|
666
693
|
}, /* @__PURE__ */ React2.createElement(IconButton, {
|
|
667
|
-
icon: "ph--
|
|
668
|
-
label: "start",
|
|
694
|
+
icon: "ph--path--regular",
|
|
669
695
|
iconOnly: true,
|
|
670
|
-
|
|
671
|
-
classNames: "px-0 aspect-square",
|
|
696
|
+
label: t("start icon button"),
|
|
672
697
|
onClick: () => onAction?.("start")
|
|
673
698
|
}), /* @__PURE__ */ React2.createElement(IconButton, {
|
|
674
699
|
icon: "ph--globe-hemisphere-west--regular",
|
|
675
|
-
label: "toggle",
|
|
676
700
|
iconOnly: true,
|
|
677
|
-
|
|
678
|
-
classNames: "px-0 aspect-square",
|
|
701
|
+
label: t("toggle icon button"),
|
|
679
702
|
onClick: () => onAction?.("toggle")
|
|
680
703
|
}));
|
|
681
704
|
} finally {
|
|
@@ -756,18 +779,18 @@ var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
|
756
779
|
_effect.f();
|
|
757
780
|
}
|
|
758
781
|
};
|
|
759
|
-
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection:
|
|
782
|
+
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionParam, topology, features, styles: stylesParam }, forwardRef3) => {
|
|
760
783
|
var _effect = _useSignals3();
|
|
761
784
|
try {
|
|
762
785
|
const { themeMode } = useThemeContext();
|
|
763
|
-
const styles = useMemo2(() =>
|
|
764
|
-
|
|
786
|
+
const styles = useMemo2(() => stylesParam ?? defaultStyles[themeMode], [
|
|
787
|
+
stylesParam,
|
|
765
788
|
themeMode
|
|
766
789
|
]);
|
|
767
790
|
const [canvas, setCanvas] = useState3(null);
|
|
768
791
|
const canvasRef = (canvas2) => setCanvas(canvas2);
|
|
769
|
-
const projection = useMemo2(() => getProjection(
|
|
770
|
-
|
|
792
|
+
const projection = useMemo2(() => getProjection(projectionParam), [
|
|
793
|
+
projectionParam
|
|
771
794
|
]);
|
|
772
795
|
const layers = useMemo2(() => {
|
|
773
796
|
return timer(() => createLayers(topology, features, styles));
|
|
@@ -859,7 +882,7 @@ var GlobeDebug = ({ position = "topleft" }) => {
|
|
|
859
882
|
try {
|
|
860
883
|
const { size, zoom, translation, rotation } = useGlobeContext();
|
|
861
884
|
return /* @__PURE__ */ React3.createElement("div", {
|
|
862
|
-
className: mx("z-10 absolute
|
|
885
|
+
className: mx("z-10 absolute is-96 p-2 overflow-hidden border border-green-700 rounded", controlPositions[position])
|
|
863
886
|
}, /* @__PURE__ */ React3.createElement("pre", {
|
|
864
887
|
className: "font-mono text-xs text-green-700"
|
|
865
888
|
}, JSON.stringify({
|
|
@@ -934,11 +957,10 @@ import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
|
934
957
|
import L, { Control, DomEvent, DomUtil, latLngBounds } from "leaflet";
|
|
935
958
|
import React4, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef2, useState as useState4 } from "react";
|
|
936
959
|
import { createRoot } from "react-dom/client";
|
|
937
|
-
import { MapContainer, Marker, Popup, TileLayer, useMap } from "react-leaflet";
|
|
938
|
-
import { debounce } from "@dxos/async";
|
|
960
|
+
import { MapContainer, Marker, Popup, TileLayer, useMap, useMapEvents } from "react-leaflet";
|
|
939
961
|
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
|
940
962
|
import { defaultTx, mx as mx2 } from "@dxos/react-ui-theme";
|
|
941
|
-
var
|
|
963
|
+
var defaults2 = {
|
|
942
964
|
center: {
|
|
943
965
|
lat: 51,
|
|
944
966
|
lng: 0
|
|
@@ -946,7 +968,7 @@ var defaults = {
|
|
|
946
968
|
zoom: 4
|
|
947
969
|
};
|
|
948
970
|
var [MapContextProvier, useMapContext] = createContext2("Map");
|
|
949
|
-
var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center
|
|
971
|
+
var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, onChange, ...props }, forwardedRef) => {
|
|
950
972
|
var _effect = _useSignals4();
|
|
951
973
|
try {
|
|
952
974
|
const [attention, setAttention] = useState4(false);
|
|
@@ -960,31 +982,6 @@ var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true,
|
|
|
960
982
|
mapRef.current?.setZoom(cb(mapRef.current?.getZoom() ?? 0));
|
|
961
983
|
}
|
|
962
984
|
}), []);
|
|
963
|
-
useEffect5(() => {
|
|
964
|
-
if (!map) {
|
|
965
|
-
return;
|
|
966
|
-
}
|
|
967
|
-
const handler = debounce(() => {
|
|
968
|
-
setAttention(true);
|
|
969
|
-
onChange?.({
|
|
970
|
-
center: map.getCenter(),
|
|
971
|
-
zoom: map.getZoom()
|
|
972
|
-
});
|
|
973
|
-
}, 100);
|
|
974
|
-
map.on("move", handler);
|
|
975
|
-
map.on("zoom", handler);
|
|
976
|
-
map.on("focus", () => setAttention(true));
|
|
977
|
-
map.on("blur", () => setAttention(false));
|
|
978
|
-
return () => {
|
|
979
|
-
map.off("move");
|
|
980
|
-
map.off("zoom");
|
|
981
|
-
map.off("focus");
|
|
982
|
-
map.off("blur");
|
|
983
|
-
};
|
|
984
|
-
}, [
|
|
985
|
-
map,
|
|
986
|
-
onChange
|
|
987
|
-
]);
|
|
988
985
|
useEffect5(() => {
|
|
989
986
|
if (!map) {
|
|
990
987
|
return;
|
|
@@ -999,7 +996,8 @@ var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true,
|
|
|
999
996
|
attention
|
|
1000
997
|
]);
|
|
1001
998
|
return /* @__PURE__ */ React4.createElement(MapContextProvier, {
|
|
1002
|
-
attention
|
|
999
|
+
attention,
|
|
1000
|
+
onChange
|
|
1003
1001
|
}, /* @__PURE__ */ React4.createElement(MapContainer, {
|
|
1004
1002
|
...props,
|
|
1005
1003
|
ref: mapRef,
|
|
@@ -1009,8 +1007,8 @@ var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true,
|
|
|
1009
1007
|
scrollWheelZoom,
|
|
1010
1008
|
doubleClickZoom,
|
|
1011
1009
|
touchZoom,
|
|
1012
|
-
center,
|
|
1013
|
-
zoom
|
|
1010
|
+
center: center ?? defaults2.center,
|
|
1011
|
+
zoom: zoom ?? defaults2.zoom
|
|
1014
1012
|
}));
|
|
1015
1013
|
} finally {
|
|
1016
1014
|
_effect.f();
|
|
@@ -1021,6 +1019,15 @@ var MapTiles = (_props) => {
|
|
|
1021
1019
|
var _effect = _useSignals4();
|
|
1022
1020
|
try {
|
|
1023
1021
|
const ref = useRef2(null);
|
|
1022
|
+
const { onChange } = useMapContext(MapTiles.displayName);
|
|
1023
|
+
useMapEvents({
|
|
1024
|
+
zoomstart: (ev) => {
|
|
1025
|
+
onChange?.({
|
|
1026
|
+
center: ev.target.getCenter(),
|
|
1027
|
+
zoom: ev.target.getZoom()
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1024
1031
|
const { attention } = useMapContext(MapTiles.displayName);
|
|
1025
1032
|
useEffect5(() => {
|
|
1026
1033
|
if (ref.current) {
|
|
@@ -1051,7 +1058,7 @@ var MapMarkers = ({ selected, markers }) => {
|
|
|
1051
1058
|
const bounds = latLngBounds(markers.map((marker) => marker.location));
|
|
1052
1059
|
map.fitBounds(bounds);
|
|
1053
1060
|
} else {
|
|
1054
|
-
map.setView(
|
|
1061
|
+
map.setView(defaults2.center, defaults2.zoom);
|
|
1055
1062
|
}
|
|
1056
1063
|
}, [
|
|
1057
1064
|
markers
|
|
@@ -1180,6 +1187,8 @@ export {
|
|
|
1180
1187
|
renderLayers,
|
|
1181
1188
|
restrictAxis,
|
|
1182
1189
|
timer,
|
|
1190
|
+
translationKey,
|
|
1191
|
+
translations,
|
|
1183
1192
|
useDrag,
|
|
1184
1193
|
useGlobeContext,
|
|
1185
1194
|
useGlobeZoomHandler,
|