@dxos/react-ui-geo 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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.
Files changed (67) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs → countries-110m-RE5RNRQG.mjs} +1 -1
  3. package/dist/lib/browser/data.mjs +4 -3
  4. package/dist/lib/browser/data.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +355 -449
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/translations.mjs +19 -0
  9. package/dist/lib/browser/translations.mjs.map +7 -0
  10. package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs → countries-110m-4EDBXSFJ.mjs} +1 -1
  11. package/dist/lib/node-esm/data.mjs +5 -3
  12. package/dist/lib/node-esm/data.mjs.map +4 -4
  13. package/dist/lib/node-esm/index.mjs +355 -448
  14. package/dist/lib/node-esm/index.mjs.map +3 -3
  15. package/dist/lib/node-esm/meta.json +1 -1
  16. package/dist/lib/node-esm/translations.mjs +21 -0
  17. package/dist/lib/node-esm/translations.mjs.map +7 -0
  18. package/dist/types/data/airports.d.ts +4 -4
  19. package/dist/types/data/airports.d.ts.map +1 -1
  20. package/dist/types/data/cities.d.ts.map +1 -1
  21. package/dist/types/data/countries-110m.d.ts.map +1 -1
  22. package/dist/types/data/countries-dots-3.d.ts.map +1 -1
  23. package/dist/types/data/countries-dots-4.d.ts.map +1 -1
  24. package/dist/types/src/components/Globe/Globe.d.ts +5 -3
  25. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  26. package/dist/types/src/components/Globe/Globe.stories.d.ts +6 -4
  27. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Map/Map.d.ts +19 -5
  29. package/dist/types/src/components/Map/Map.d.ts.map +1 -1
  30. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
  32. package/dist/types/src/hooks/context.d.ts +1 -3
  33. package/dist/types/src/hooks/context.d.ts.map +1 -1
  34. package/dist/types/src/hooks/useDrag.d.ts.map +1 -1
  35. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +1 -1
  36. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
  37. package/dist/types/src/hooks/useMapZoomHandler.d.ts +1 -1
  38. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
  39. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
  40. package/dist/types/src/hooks/useTour.d.ts.map +1 -1
  41. package/dist/types/src/index.d.ts +0 -1
  42. package/dist/types/src/index.d.ts.map +1 -1
  43. package/dist/types/src/translations.d.ts +12 -0
  44. package/dist/types/src/translations.d.ts.map +1 -0
  45. package/dist/types/src/util/debug.d.ts.map +1 -1
  46. package/dist/types/src/util/inertia.d.ts.map +1 -1
  47. package/dist/types/src/util/path.d.ts.map +1 -1
  48. package/dist/types/src/util/render.d.ts.map +1 -1
  49. package/dist/types/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +42 -36
  51. package/src/components/Globe/Globe.stories.tsx +7 -8
  52. package/src/components/Globe/Globe.tsx +55 -29
  53. package/src/components/Map/Map.stories.tsx +9 -8
  54. package/src/components/Map/Map.tsx +70 -29
  55. package/src/components/Toolbar/Controls.tsx +12 -14
  56. package/src/hooks/context.tsx +5 -34
  57. package/src/hooks/useSpinner.ts +0 -1
  58. package/src/hooks/useTour.ts +1 -0
  59. package/src/index.ts +0 -1
  60. package/src/translations.ts +20 -0
  61. package/src/util/render.ts +0 -1
  62. package/dist/lib/browser/chunk-GMWLKTLN.mjs +0 -9
  63. package/dist/lib/browser/chunk-GMWLKTLN.mjs.map +0 -7
  64. package/dist/lib/node-esm/chunk-JODBF4CC.mjs +0 -11
  65. package/dist/lib/node-esm/chunk-JODBF4CC.mjs.map +0 -7
  66. /package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs.map → countries-110m-RE5RNRQG.mjs.map} +0 -0
  67. /package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs.map → countries-110m-4EDBXSFJ.mjs.map} +0 -0
@@ -1,53 +1,16 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- loadTopology
4
- } from "./chunk-JODBF4CC.mjs";
5
2
 
6
3
  // src/components/Globe/Globe.tsx
7
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
8
4
  import { easeLinear, easeSinOut, geoMercator, geoOrthographic, geoPath as geoPath2, geoTransverseMercator, interpolateNumber, transition } from "d3";
9
- import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo2, useRef, useState as useState3 } from "react";
5
+ import React2, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo2, useRef, useState as useState3 } from "react";
10
6
  import { useResizeDetector } from "react-resize-detector";
11
- import { useDynamicRef, useThemeContext } from "@dxos/react-ui";
12
- import { mx } from "@dxos/react-ui-theme";
7
+ import { useComposedRefs, useControlledState, useDynamicRef, useThemeContext } from "@dxos/react-ui";
8
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
13
9
 
14
10
  // src/hooks/context.tsx
15
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
16
- import React, { createContext, useContext } from "react";
11
+ import { createContext, useContext } from "react";
17
12
  import { raise } from "@dxos/debug";
18
- import { useControlledState } from "@dxos/react-ui";
19
- var defaults = {
20
- center: {
21
- lat: 51,
22
- lng: 0
23
- },
24
- zoom: 4
25
- };
26
13
  var GlobeContext = /* @__PURE__ */ createContext(void 0);
27
- var GlobeContextProvider = ({ children, size, center: centerParam = defaults.center, zoom: zoomParam = defaults.zoom, translation: translationParam, rotation: rotationParam }) => {
28
- var _effect = _useSignals();
29
- try {
30
- const [center, setCenter] = useControlledState(centerParam);
31
- const [zoom, setZoom] = useControlledState(zoomParam);
32
- const [translation, setTranslation] = useControlledState(translationParam);
33
- const [rotation, setRotation] = useControlledState(rotationParam);
34
- return /* @__PURE__ */ React.createElement(GlobeContext.Provider, {
35
- value: {
36
- size,
37
- center,
38
- zoom,
39
- translation,
40
- rotation,
41
- setCenter,
42
- setZoom,
43
- setTranslation,
44
- setRotation
45
- }
46
- }, children);
47
- } finally {
48
- _effect.f();
49
- }
50
- };
51
14
  var useGlobeContext = () => {
52
15
  return useContext(GlobeContext) ?? raise(new Error("Missing GlobeContext"));
53
16
  };
@@ -632,9 +595,9 @@ var useTour = (controller, points, options = {}) => {
632
595
  };
633
596
 
634
597
  // src/components/Toolbar/Controls.tsx
635
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
636
- import React2 from "react";
637
- import { IconButton, Toolbar } from "@dxos/react-ui";
598
+ import React from "react";
599
+ import { IconButton, Toolbar, useTranslation } from "@dxos/react-ui";
600
+ import { translationKey } from "#translations";
638
601
  var controlPositions = {
639
602
  topleft: "top-2 left-2",
640
603
  topright: "top-2 right-2",
@@ -642,58 +605,42 @@ var controlPositions = {
642
605
  bottomright: "bottom-2 right-2"
643
606
  };
644
607
  var ZoomControls = ({ classNames, onAction }) => {
645
- var _effect = _useSignals2();
646
- try {
647
- return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
648
- classNames: [
649
- "gap-2",
650
- classNames
651
- ]
652
- }, /* @__PURE__ */ React2.createElement(IconButton, {
653
- icon: "ph--plus--regular",
654
- label: "zoom in",
655
- iconOnly: true,
656
- size: 5,
657
- classNames: "px-0 aspect-square",
658
- onClick: () => onAction?.("zoom-in")
659
- }), /* @__PURE__ */ React2.createElement(IconButton, {
660
- icon: "ph--minus--regular",
661
- label: "zoom out",
662
- iconOnly: true,
663
- size: 5,
664
- classNames: "px-0 aspect-square",
665
- onClick: () => onAction?.("zoom-out")
666
- }));
667
- } finally {
668
- _effect.f();
669
- }
608
+ const { t } = useTranslation(translationKey);
609
+ return /* @__PURE__ */ React.createElement(Toolbar.Root, {
610
+ classNames: [
611
+ "gap-2",
612
+ classNames
613
+ ]
614
+ }, /* @__PURE__ */ React.createElement(IconButton, {
615
+ icon: "ph--plus--regular",
616
+ iconOnly: true,
617
+ label: t("zoom-in-icon.button"),
618
+ onClick: () => onAction?.("zoom-in")
619
+ }), /* @__PURE__ */ React.createElement(IconButton, {
620
+ icon: "ph--minus--regular",
621
+ iconOnly: true,
622
+ label: t("zoom-out-icon.button"),
623
+ onClick: () => onAction?.("zoom-out")
624
+ }));
670
625
  };
671
626
  var ActionControls = ({ classNames, onAction }) => {
672
- var _effect = _useSignals2();
673
- try {
674
- return /* @__PURE__ */ React2.createElement(Toolbar.Root, {
675
- classNames: [
676
- "gap-2",
677
- classNames
678
- ]
679
- }, /* @__PURE__ */ React2.createElement(IconButton, {
680
- icon: "ph--play--regular",
681
- label: "start",
682
- iconOnly: true,
683
- size: 5,
684
- classNames: "px-0 aspect-square",
685
- onClick: () => onAction?.("start")
686
- }), /* @__PURE__ */ React2.createElement(IconButton, {
687
- icon: "ph--globe-hemisphere-west--regular",
688
- label: "toggle",
689
- iconOnly: true,
690
- size: 5,
691
- classNames: "px-0 aspect-square",
692
- onClick: () => onAction?.("toggle")
693
- }));
694
- } finally {
695
- _effect.f();
696
- }
627
+ const { t } = useTranslation(translationKey);
628
+ return /* @__PURE__ */ React.createElement(Toolbar.Root, {
629
+ classNames: [
630
+ "gap-2",
631
+ classNames
632
+ ]
633
+ }, /* @__PURE__ */ React.createElement(IconButton, {
634
+ icon: "ph--path--regular",
635
+ iconOnly: true,
636
+ label: t("start-icon.button"),
637
+ onClick: () => onAction?.("start")
638
+ }), /* @__PURE__ */ React.createElement(IconButton, {
639
+ icon: "ph--globe-hemisphere-west--regular",
640
+ iconOnly: true,
641
+ label: t("toggle-icon.button"),
642
+ onClick: () => onAction?.("toggle")
643
+ }));
697
644
  };
698
645
 
699
646
  // src/components/Globe/Globe.tsx
@@ -751,186 +698,166 @@ var getProjection = (type = "orthographic") => {
751
698
  }
752
699
  return type ?? geoOrthographic();
753
700
  };
754
- var GlobeRoot = ({ classNames, children, ...props }) => {
755
- var _effect = _useSignals3();
756
- try {
757
- const { ref, width, height } = useResizeDetector();
758
- return /* @__PURE__ */ React3.createElement("div", {
759
- ref,
760
- className: mx("relative flex grow overflow-hidden", classNames)
761
- }, /* @__PURE__ */ React3.createElement(GlobeContextProvider, {
701
+ var GlobeRoot = composable(({ children, center: centerProp, zoom: zoomProp, translation: translationProp, rotation: rotationProp, ...props }, forwardedRef) => {
702
+ const localRef = useRef(null);
703
+ const composedRef = useComposedRefs(localRef, forwardedRef);
704
+ const { width, height } = useResizeDetector({
705
+ targetRef: localRef
706
+ });
707
+ const [center, setCenter] = useControlledState(centerProp);
708
+ const [zoom, setZoom] = useControlledState(zoomProp ?? 4);
709
+ const [translation, setTranslation] = useControlledState(translationProp);
710
+ const [rotation, setRotation] = useControlledState(rotationProp);
711
+ return /* @__PURE__ */ React2.createElement(GlobeContext.Provider, {
712
+ value: {
762
713
  size: {
763
714
  width,
764
715
  height
765
716
  },
766
- ...props
767
- }, children));
768
- } finally {
769
- _effect.f();
770
- }
771
- };
772
- var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionParam, topology, features, styles: stylesParam }, forwardRef3) => {
773
- var _effect = _useSignals3();
774
- try {
775
- const { themeMode } = useThemeContext();
776
- const styles = useMemo2(() => stylesParam ?? defaultStyles[themeMode], [
777
- stylesParam,
778
- themeMode
779
- ]);
780
- const [canvas, setCanvas] = useState3(null);
781
- const canvasRef = (canvas2) => setCanvas(canvas2);
782
- const projection = useMemo2(() => getProjection(projectionParam), [
783
- projectionParam
784
- ]);
785
- const layers = useMemo2(() => {
786
- return timer(() => createLayers(topology, features, styles));
787
- }, [
788
- topology,
789
- features,
790
- styles
791
- ]);
792
- const { size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation } = useGlobeContext();
793
- const zoomRef = useDynamicRef(zoom);
794
- useEffect4(() => {
795
- if (center) {
796
- setZoom(1);
797
- setRotation(positionToRotation(geoToPosition(center)));
798
- }
799
- }, [
800
- center
801
- ]);
802
- const zooming = useRef(false);
803
- useImperativeHandle(forwardRef3, () => {
804
- return {
805
- canvas,
806
- projection,
807
- center,
808
- get zoom() {
809
- return zoomRef.current;
810
- },
811
- translation,
812
- rotation,
813
- setCenter,
814
- setZoom: (s) => {
815
- if (typeof s === "function") {
816
- const is = interpolateNumber(zoomRef.current, s(zoomRef.current));
817
- transition().ease(zooming.current ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => setZoom(is(t))).on("end", () => {
818
- zooming.current = false;
819
- });
820
- } else {
821
- setZoom(s);
822
- }
823
- },
824
- setTranslation,
825
- setRotation
826
- };
827
- }, [
828
- canvas
829
- ]);
830
- const generator = useMemo2(() => canvas && projection && geoPath2(projection, canvas.getContext("2d", {
831
- alpha: false
832
- })), [
833
- canvas,
834
- projection
835
- ]);
836
- useEffect4(() => {
837
- if (canvas && projection) {
838
- timer(() => {
839
- projection.scale(Math.min(size.width, size.height) / 2 * zoom).translate([
840
- size.width / 2 + (translation?.x ?? 0),
841
- size.height / 2 + (translation?.y ?? 0)
842
- ]).rotate(rotation ?? [
843
- 0,
844
- 0,
845
- 0
846
- ]);
847
- renderLayers(generator, layers, zoom, styles);
848
- });
849
- }
850
- }, [
851
- generator,
852
- size,
717
+ center,
853
718
  zoom,
854
719
  translation,
855
720
  rotation,
856
- layers
857
- ]);
858
- if (!size.width || !size.height) {
859
- return null;
721
+ setCenter,
722
+ setZoom,
723
+ setTranslation,
724
+ setRotation
860
725
  }
861
- return /* @__PURE__ */ React3.createElement("canvas", {
862
- ref: canvasRef,
863
- width: size.width,
864
- height: size.height
865
- });
866
- } finally {
867
- _effect.f();
868
- }
726
+ }, /* @__PURE__ */ React2.createElement("div", {
727
+ ...composableProps(props, {
728
+ classNames: "relative dx-container"
729
+ }),
730
+ ref: composedRef
731
+ }, children));
869
732
  });
870
- var GlobeDebug = ({ position = "topleft" }) => {
871
- var _effect = _useSignals3();
872
- try {
873
- const { size, zoom, translation, rotation } = useGlobeContext();
874
- return /* @__PURE__ */ React3.createElement("div", {
875
- className: mx("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded", controlPositions[position])
876
- }, /* @__PURE__ */ React3.createElement("pre", {
877
- className: "font-mono text-xs text-green-700"
878
- }, JSON.stringify({
879
- size,
880
- zoom,
733
+ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: projectionProp, topology, features, styles: stylesProp }, forwardRef3) => {
734
+ const { themeMode } = useThemeContext();
735
+ const styles = useMemo2(() => stylesProp ?? defaultStyles[themeMode], [
736
+ stylesProp,
737
+ themeMode
738
+ ]);
739
+ const [canvas, setCanvas] = useState3(null);
740
+ const canvasRef = (canvas2) => setCanvas(canvas2);
741
+ const projection = useMemo2(() => getProjection(projectionProp), [
742
+ projectionProp
743
+ ]);
744
+ const layers = useMemo2(() => {
745
+ return timer(() => createLayers(topology, features, styles));
746
+ }, [
747
+ topology,
748
+ features,
749
+ styles
750
+ ]);
751
+ const { size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation } = useGlobeContext();
752
+ const zoomRef = useDynamicRef(zoom);
753
+ useEffect4(() => {
754
+ if (center) {
755
+ setZoom(1);
756
+ setRotation(positionToRotation(geoToPosition(center)));
757
+ }
758
+ }, [
759
+ center
760
+ ]);
761
+ const zooming = useRef(false);
762
+ useImperativeHandle(forwardRef3, () => {
763
+ return {
764
+ canvas,
765
+ projection,
766
+ center,
767
+ get zoom() {
768
+ return zoomRef.current;
769
+ },
881
770
  translation,
882
- rotation
883
- }, null, 2)));
884
- } finally {
885
- _effect.f();
771
+ rotation,
772
+ setCenter,
773
+ setZoom: (state) => {
774
+ if (typeof state === "function") {
775
+ const is = interpolateNumber(zoomRef.current, state(zoomRef.current));
776
+ transition().ease(zooming.current ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => setZoom(is(t))).on("end", () => {
777
+ zooming.current = false;
778
+ });
779
+ } else {
780
+ setZoom(state);
781
+ }
782
+ },
783
+ setTranslation,
784
+ setRotation
785
+ };
786
+ }, [
787
+ canvas
788
+ ]);
789
+ const generator = useMemo2(() => canvas && projection && geoPath2(projection, canvas.getContext("2d", {
790
+ alpha: false
791
+ })), [
792
+ canvas,
793
+ projection
794
+ ]);
795
+ useEffect4(() => {
796
+ if (canvas && projection) {
797
+ timer(() => {
798
+ projection.scale(Math.min(size.width, size.height) / 2 * zoom).translate([
799
+ size.width / 2 + (translation?.x ?? 0),
800
+ size.height / 2 + (translation?.y ?? 0)
801
+ ]).rotate(rotation ?? [
802
+ 0,
803
+ 0,
804
+ 0
805
+ ]);
806
+ renderLayers(generator, layers, zoom, styles);
807
+ });
808
+ }
809
+ }, [
810
+ generator,
811
+ size,
812
+ zoom,
813
+ translation,
814
+ rotation,
815
+ layers
816
+ ]);
817
+ if (!size.width || !size.height) {
818
+ return null;
886
819
  }
820
+ return /* @__PURE__ */ React2.createElement("canvas", {
821
+ ref: canvasRef,
822
+ width: size.width,
823
+ height: size.height
824
+ });
825
+ });
826
+ var GlobeDebug = ({ position = "topleft" }) => {
827
+ const { size, zoom, translation, rotation } = useGlobeContext();
828
+ return /* @__PURE__ */ React2.createElement("div", {
829
+ className: mx("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm", controlPositions[position])
830
+ }, /* @__PURE__ */ React2.createElement("pre", {
831
+ className: "font-mono text-xs text-green-700"
832
+ }, JSON.stringify({
833
+ size,
834
+ zoom,
835
+ translation,
836
+ rotation
837
+ }, null, 2)));
887
838
  };
888
839
  var GlobePanel = ({ position, classNames, children }) => {
889
- var _effect = _useSignals3();
890
- try {
891
- return /* @__PURE__ */ React3.createElement("div", {
892
- className: mx("z-10 absolute overflow-hidden", controlPositions[position], classNames)
893
- }, children);
894
- } finally {
895
- _effect.f();
896
- }
840
+ return /* @__PURE__ */ React2.createElement("div", {
841
+ className: mx("z-10 absolute overflow-hidden", controlPositions[position], classNames)
842
+ }, children);
897
843
  };
898
844
  var CustomControl = ({ position, children }) => {
899
- var _effect = _useSignals3();
900
- try {
901
- return /* @__PURE__ */ React3.createElement("div", {
902
- className: mx("z-10 absolute overflow-hidden", controlPositions[position])
903
- }, children);
904
- } finally {
905
- _effect.f();
906
- }
907
- };
908
- var GlobeZoom = ({ onAction, position = "bottomleft", ...props }) => {
909
- var _effect = _useSignals3();
910
- try {
911
- return /* @__PURE__ */ React3.createElement(CustomControl, {
912
- position,
913
- ...props
914
- }, /* @__PURE__ */ React3.createElement(ZoomControls, {
915
- onAction
916
- }));
917
- } finally {
918
- _effect.f();
919
- }
920
- };
921
- var GlobeAction = ({ onAction, position = "bottomright", ...props }) => {
922
- var _effect = _useSignals3();
923
- try {
924
- return /* @__PURE__ */ React3.createElement(CustomControl, {
925
- position,
926
- ...props
927
- }, /* @__PURE__ */ React3.createElement(ActionControls, {
928
- onAction
929
- }));
930
- } finally {
931
- _effect.f();
932
- }
845
+ return /* @__PURE__ */ React2.createElement("div", {
846
+ className: mx("z-10 absolute overflow-hidden", controlPositions[position])
847
+ }, children);
933
848
  };
849
+ var GlobeZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
850
+ position,
851
+ ...props
852
+ }, /* @__PURE__ */ React2.createElement(ZoomControls, {
853
+ onAction
854
+ }));
855
+ var GlobeAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React2.createElement(CustomControl, {
856
+ position,
857
+ ...props
858
+ }, /* @__PURE__ */ React2.createElement(ActionControls, {
859
+ onAction
860
+ }));
934
861
  var Globe = {
935
862
  Root: GlobeRoot,
936
863
  Canvas: GlobeCanvas,
@@ -941,217 +868,198 @@ var Globe = {
941
868
  };
942
869
 
943
870
  // src/components/Map/Map.tsx
944
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
945
871
  import "leaflet/dist/leaflet.css";
946
872
  import { createContext as createContext2 } from "@radix-ui/react-context";
947
873
  import L, { Control, DomEvent, DomUtil, latLngBounds } from "leaflet";
948
- import React4, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef2, useState as useState4 } from "react";
874
+ import React3, { forwardRef as forwardRef2, useEffect as useEffect5, useImperativeHandle as useImperativeHandle2, useRef as useRef2 } from "react";
949
875
  import { createRoot } from "react-dom/client";
950
876
  import { MapContainer, Marker, Popup, TileLayer, useMap, useMapEvents } from "react-leaflet";
951
877
  import { ThemeProvider, Tooltip } from "@dxos/react-ui";
952
- import { defaultTx, mx as mx2 } from "@dxos/react-ui-theme";
953
- var defaults2 = {
878
+ import { composable as composable2, composableProps as composableProps2, defaultTx, mx as mx2 } from "@dxos/ui-theme";
879
+ var defaults = {
954
880
  center: {
955
881
  lat: 51,
956
882
  lng: 0
957
883
  },
958
884
  zoom: 4
959
885
  };
960
- var [MapContextProvier, useMapContext] = createContext2("Map");
961
- var MapRoot = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, onChange, ...props }, forwardedRef) => {
962
- var _effect = _useSignals4();
963
- try {
964
- const [attention, setAttention] = useState4(false);
965
- const mapRef = useRef2(null);
966
- const map = mapRef.current;
967
- useImperativeHandle2(forwardedRef, () => ({
968
- setCenter: (center2, zoom2) => {
969
- mapRef.current?.setView(center2, zoom2);
970
- },
971
- setZoom: (cb) => {
972
- mapRef.current?.setZoom(cb(mapRef.current?.getZoom() ?? 0));
973
- }
974
- }), []);
975
- useEffect5(() => {
976
- if (!map) {
977
- return;
978
- }
979
- if (attention) {
980
- map.scrollWheelZoom.enable();
981
- } else {
982
- map.scrollWheelZoom.disable();
983
- }
984
- }, [
985
- map,
986
- attention
987
- ]);
988
- return /* @__PURE__ */ React4.createElement(MapContextProvier, {
989
- attention,
990
- onChange
991
- }, /* @__PURE__ */ React4.createElement(MapContainer, {
992
- ...props,
993
- ref: mapRef,
994
- className: mx2("group relative grid bs-full is-full !bg-baseSurface dx-focus-ring-inset", classNames),
995
- attributionControl: false,
996
- zoomControl: false,
997
- scrollWheelZoom,
998
- doubleClickZoom,
999
- touchZoom,
1000
- center: center ?? defaults2.center,
1001
- zoom: zoom ?? defaults2.zoom
1002
- }));
1003
- } finally {
1004
- _effect.f();
1005
- }
886
+ var [MapContextProvider, useMapContext] = createContext2("Map");
887
+ var MapRoot = composable2(({ children, onChange, ...props }, forwardedRef) => {
888
+ const attention = false;
889
+ return /* @__PURE__ */ React3.createElement(MapContextProvider, {
890
+ attention,
891
+ onChange
892
+ }, /* @__PURE__ */ React3.createElement("div", {
893
+ ...composableProps2(props, {
894
+ role: "none",
895
+ classNames: "dx-container grid dx-focus-ring-inset"
896
+ }),
897
+ ref: forwardedRef
898
+ }, children));
1006
899
  });
1007
900
  MapRoot.displayName = "Map.Root";
901
+ var MAP_CONTENT_NAME = "Map.Content";
902
+ var MapContent = /* @__PURE__ */ forwardRef2(({ classNames, scrollWheelZoom = true, doubleClickZoom = true, touchZoom = true, center, zoom, children, ...props }, forwardedRef) => {
903
+ const { attention } = useMapContext(MAP_CONTENT_NAME);
904
+ const mapRef = useRef2(null);
905
+ const map = mapRef.current;
906
+ useImperativeHandle2(forwardedRef, () => ({
907
+ setCenter: (center2, zoom2) => {
908
+ mapRef.current?.setView(center2, zoom2);
909
+ },
910
+ setZoom: (cb) => {
911
+ mapRef.current?.setZoom(cb(mapRef.current?.getZoom() ?? 0));
912
+ }
913
+ }), []);
914
+ useEffect5(() => {
915
+ if (!map) {
916
+ return;
917
+ }
918
+ if (attention) {
919
+ map.scrollWheelZoom.enable();
920
+ } else {
921
+ map.scrollWheelZoom.disable();
922
+ }
923
+ }, [
924
+ map,
925
+ attention
926
+ ]);
927
+ return /* @__PURE__ */ React3.createElement(MapContainer, {
928
+ ...props,
929
+ className: mx2("group relative grid bg-base-surface!", classNames),
930
+ attributionControl: false,
931
+ zoomControl: false,
932
+ scrollWheelZoom,
933
+ doubleClickZoom,
934
+ touchZoom,
935
+ center: center ?? defaults.center,
936
+ zoom: zoom ?? defaults.zoom,
937
+ whenReady: () => {
938
+ },
939
+ ref: mapRef
940
+ }, children);
941
+ });
942
+ MapContent.displayName = "Map.Content";
943
+ var MAP_TILES_NAME = "Map.Tiles";
1008
944
  var MapTiles = (_props) => {
1009
- var _effect = _useSignals4();
1010
- try {
1011
- const ref = useRef2(null);
1012
- const { onChange } = useMapContext(MapTiles.displayName);
1013
- useMapEvents({
1014
- zoomstart: (ev) => {
1015
- onChange?.({
1016
- center: ev.target.getCenter(),
1017
- zoom: ev.target.getZoom()
1018
- });
1019
- }
1020
- });
1021
- const { attention } = useMapContext(MapTiles.displayName);
1022
- useEffect5(() => {
1023
- if (ref.current) {
1024
- ref.current.getContainer().dataset.attention = attention ? "1" : "0";
1025
- }
1026
- }, [
1027
- attention
1028
- ]);
1029
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(TileLayer, {
1030
- ref,
1031
- "data-attention": attention,
1032
- detectRetina: true,
1033
- className: 'dark:grayscale dark:invert data-[attention="0"]:!opacity-80',
1034
- url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
1035
- keepBuffer: 4
1036
- }));
1037
- } finally {
1038
- _effect.f();
1039
- }
945
+ const ref = useRef2(null);
946
+ const { onChange } = useMapContext(MAP_TILES_NAME);
947
+ useMapEvents({
948
+ zoomstart: (ev) => {
949
+ onChange?.({
950
+ center: ev.target.getCenter(),
951
+ zoom: ev.target.getZoom()
952
+ });
953
+ }
954
+ });
955
+ const { attention } = useMapContext(MAP_TILES_NAME);
956
+ useEffect5(() => {
957
+ if (ref.current) {
958
+ ref.current.getContainer().dataset.attention = attention ? "1" : "0";
959
+ }
960
+ }, [
961
+ attention
962
+ ]);
963
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(TileLayer, {
964
+ ref,
965
+ "data-attention": attention,
966
+ detectRetina: true,
967
+ className: 'dark:grayscale dark:invert data-[attention="0"]:!opacity-80',
968
+ url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
969
+ keepBuffer: 4
970
+ }));
1040
971
  };
1041
- MapTiles.displayName = "Map.Tiles";
972
+ MapTiles.displayName = MAP_TILES_NAME;
1042
973
  var MapMarkers = ({ selected, markers }) => {
1043
- var _effect = _useSignals4();
1044
- try {
1045
- const map = useMap();
1046
- useEffect5(() => {
1047
- if (markers.length > 0) {
1048
- const bounds = latLngBounds(markers.map((marker) => marker.location));
1049
- map.fitBounds(bounds);
1050
- } else {
1051
- map.setView(defaults2.center, defaults2.zoom);
1052
- }
1053
- }, [
1054
- markers
1055
- ]);
1056
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, markers?.map(({ id, title, location: { lat, lng } }) => {
1057
- return /* @__PURE__ */ React4.createElement(Marker, {
1058
- key: id,
1059
- position: {
1060
- lat,
1061
- lng
1062
- },
1063
- icon: (
1064
- // TODO(burdon): Create custom icon from bundled assets.
1065
- // TODO(burdon): Selection state.
1066
- new L.Icon({
1067
- iconUrl: "https://dxos.network/marker-icon.png",
1068
- iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
1069
- shadowUrl: "https://dxos.network/marker-shadow.png",
1070
- iconSize: [
1071
- 25,
1072
- 41
1073
- ],
1074
- iconAnchor: [
1075
- 12,
1076
- 41
1077
- ],
1078
- popupAnchor: [
1079
- 1,
1080
- -34
1081
- ],
1082
- shadowSize: [
1083
- 41,
1084
- 41
1085
- ]
1086
- })
1087
- )
1088
- }, title && /* @__PURE__ */ React4.createElement(Popup, null, title));
1089
- }));
1090
- } finally {
1091
- _effect.f();
1092
- }
974
+ const map = useMap();
975
+ useEffect5(() => {
976
+ if (markers.length > 0) {
977
+ const bounds = latLngBounds(markers.map((marker) => marker.location));
978
+ map.fitBounds(bounds);
979
+ } else {
980
+ map.setView(defaults.center, defaults.zoom);
981
+ }
982
+ }, [
983
+ markers
984
+ ]);
985
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, markers?.map(({ id, title, location: { lat, lng } }) => {
986
+ return /* @__PURE__ */ React3.createElement(Marker, {
987
+ key: id,
988
+ position: {
989
+ lat,
990
+ lng
991
+ },
992
+ icon: (
993
+ // TODO(burdon): Create custom icon from bundled assets.
994
+ // TODO(burdon): Selection state.
995
+ new L.Icon({
996
+ iconUrl: "https://dxos.network/marker-icon.png",
997
+ iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
998
+ shadowUrl: "https://dxos.network/marker-shadow.png",
999
+ iconSize: [
1000
+ 25,
1001
+ 41
1002
+ ],
1003
+ iconAnchor: [
1004
+ 12,
1005
+ 41
1006
+ ],
1007
+ popupAnchor: [
1008
+ 1,
1009
+ -34
1010
+ ],
1011
+ shadowSize: [
1012
+ 41,
1013
+ 41
1014
+ ]
1015
+ })
1016
+ )
1017
+ }, title && /* @__PURE__ */ React3.createElement(Popup, null, title));
1018
+ }));
1093
1019
  };
1094
1020
  MapMarkers.displayName = "Map.Markers";
1095
1021
  var CustomControl2 = ({ position, children }) => {
1096
- var _effect = _useSignals4();
1097
- try {
1098
- const map = useMap();
1099
- useEffect5(() => {
1100
- const control = new Control({
1101
- position
1102
- });
1103
- control.onAdd = () => {
1104
- const container = DomUtil.create("div", mx2("!m-0", controlPositions[position]));
1105
- DomEvent.disableClickPropagation(container);
1106
- DomEvent.disableScrollPropagation(container);
1107
- const root = createRoot(container);
1108
- root.render(/* @__PURE__ */ React4.createElement(ThemeProvider, {
1109
- tx: defaultTx
1110
- }, /* @__PURE__ */ React4.createElement(Tooltip.Provider, null, children)));
1111
- return container;
1112
- };
1113
- control.addTo(map);
1114
- return () => {
1115
- control.remove();
1116
- };
1117
- }, [
1118
- map,
1119
- position,
1120
- children
1121
- ]);
1122
- return null;
1123
- } finally {
1124
- _effect.f();
1125
- }
1126
- };
1127
- var MapZoom = ({ onAction, position = "bottomleft", ...props }) => {
1128
- var _effect = _useSignals4();
1129
- try {
1130
- return /* @__PURE__ */ React4.createElement(CustomControl2, {
1131
- position,
1132
- ...props
1133
- }, /* @__PURE__ */ React4.createElement(ZoomControls, {
1134
- onAction
1135
- }));
1136
- } finally {
1137
- _effect.f();
1138
- }
1139
- };
1140
- var MapAction = ({ onAction, position = "bottomright", ...props }) => {
1141
- var _effect = _useSignals4();
1142
- try {
1143
- return /* @__PURE__ */ React4.createElement(CustomControl2, {
1144
- position,
1145
- ...props
1146
- }, /* @__PURE__ */ React4.createElement(ActionControls, {
1147
- onAction
1148
- }));
1149
- } finally {
1150
- _effect.f();
1151
- }
1022
+ const map = useMap();
1023
+ useEffect5(() => {
1024
+ const control = new Control({
1025
+ position
1026
+ });
1027
+ control.onAdd = () => {
1028
+ const container = DomUtil.create("div", mx2("m-0!", controlPositions[position]));
1029
+ DomEvent.disableClickPropagation(container);
1030
+ DomEvent.disableScrollPropagation(container);
1031
+ const root = createRoot(container);
1032
+ root.render(/* @__PURE__ */ React3.createElement(ThemeProvider, {
1033
+ tx: defaultTx
1034
+ }, /* @__PURE__ */ React3.createElement(Tooltip.Provider, null, children)));
1035
+ return container;
1036
+ };
1037
+ control.addTo(map);
1038
+ return () => {
1039
+ control.remove();
1040
+ };
1041
+ }, [
1042
+ map,
1043
+ position,
1044
+ children
1045
+ ]);
1046
+ return null;
1152
1047
  };
1048
+ var MapZoom = ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
1049
+ position,
1050
+ ...props
1051
+ }, /* @__PURE__ */ React3.createElement(ZoomControls, {
1052
+ onAction
1053
+ }));
1054
+ var MapAction = ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React3.createElement(CustomControl2, {
1055
+ position,
1056
+ ...props
1057
+ }, /* @__PURE__ */ React3.createElement(ActionControls, {
1058
+ onAction
1059
+ }));
1153
1060
  var Map = {
1154
1061
  Root: MapRoot,
1062
+ Content: MapContent,
1155
1063
  Tiles: MapTiles,
1156
1064
  Markers: MapMarkers,
1157
1065
  Zoom: MapZoom,
@@ -1160,7 +1068,7 @@ var Map = {
1160
1068
  export {
1161
1069
  ActionControls,
1162
1070
  Globe,
1163
- GlobeContextProvider,
1071
+ GlobeContext,
1164
1072
  Map,
1165
1073
  ZoomControls,
1166
1074
  closestPoint,
@@ -1172,7 +1080,6 @@ export {
1172
1080
  geoPoint,
1173
1081
  geoToPosition,
1174
1082
  getDistance,
1175
- loadTopology,
1176
1083
  positionToRotation,
1177
1084
  renderLayers,
1178
1085
  restrictAxis,