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