@dxos/react-ui-geo 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (68) hide show
  1. package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs → countries-110m-RE5RNRQG.mjs} +1 -1
  2. package/dist/lib/browser/data.mjs +4 -3
  3. package/dist/lib/browser/data.mjs.map +4 -4
  4. package/dist/lib/browser/index.mjs +364 -462
  5. package/dist/lib/browser/index.mjs.map +3 -3
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/translations.mjs +19 -0
  8. package/dist/lib/browser/translations.mjs.map +7 -0
  9. package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs → countries-110m-4EDBXSFJ.mjs} +1 -1
  10. package/dist/lib/node-esm/data.mjs +5 -3
  11. package/dist/lib/node-esm/data.mjs.map +4 -4
  12. package/dist/lib/node-esm/index.mjs +364 -461
  13. package/dist/lib/node-esm/index.mjs.map +3 -3
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/translations.mjs +21 -0
  16. package/dist/lib/node-esm/translations.mjs.map +7 -0
  17. package/dist/types/data/airports.d.ts +4 -4
  18. package/dist/types/data/airports.d.ts.map +1 -1
  19. package/dist/types/data/cities.d.ts.map +1 -1
  20. package/dist/types/data/countries-110m.d.ts.map +1 -1
  21. package/dist/types/data/countries-dots-3.d.ts.map +1 -1
  22. package/dist/types/data/countries-dots-4.d.ts.map +1 -1
  23. package/dist/types/src/components/Globe/Globe.d.ts +5 -3
  24. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  25. package/dist/types/src/components/Globe/Globe.stories.d.ts +9 -5
  26. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  27. package/dist/types/src/components/Map/Map.d.ts +22 -11
  28. package/dist/types/src/components/Map/Map.d.ts.map +1 -1
  29. package/dist/types/src/components/Map/Map.stories.d.ts +3 -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 +10 -10
  52. package/src/components/Globe/Globe.tsx +55 -28
  53. package/src/components/Map/Map.stories.tsx +12 -10
  54. package/src/components/Map/Map.tsx +82 -71
  55. package/src/components/Toolbar/Controls.tsx +12 -14
  56. package/src/hooks/context.tsx +6 -29
  57. package/src/hooks/useGlobeZoomHandler.ts +8 -2
  58. package/src/hooks/useSpinner.ts +0 -1
  59. package/src/hooks/useTour.ts +1 -0
  60. package/src/index.ts +0 -1
  61. package/src/translations.ts +20 -0
  62. package/src/util/render.ts +0 -1
  63. package/dist/lib/browser/chunk-GMWLKTLN.mjs +0 -9
  64. package/dist/lib/browser/chunk-GMWLKTLN.mjs.map +0 -7
  65. package/dist/lib/node-esm/chunk-JODBF4CC.mjs +0 -11
  66. package/dist/lib/node-esm/chunk-JODBF4CC.mjs.map +0 -7
  67. /package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs.map → countries-110m-RE5RNRQG.mjs.map} +0 -0
  68. /package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs.map → countries-110m-4EDBXSFJ.mjs.map} +0 -0
@@ -5,7 +5,9 @@
5
5
  import { type ControlPosition } from 'leaflet';
6
6
  import React from 'react';
7
7
 
8
- import { IconButton, type ThemedClassName, Toolbar } from '@dxos/react-ui';
8
+ import { IconButton, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
9
+
10
+ import { translationKey } from '#translations';
9
11
 
10
12
  export type ControlAction = 'toggle' | 'start' | 'zoom-in' | 'zoom-out';
11
13
 
@@ -21,22 +23,20 @@ export const controlPositions: Record<ControlPosition, string> = {
21
23
  };
22
24
 
23
25
  export const ZoomControls = ({ classNames, onAction }: ControlProps) => {
26
+ const { t } = useTranslation(translationKey);
27
+
24
28
  return (
25
29
  <Toolbar.Root classNames={['gap-2', classNames]}>
26
30
  <IconButton
27
31
  icon='ph--plus--regular'
28
- label='zoom in'
29
32
  iconOnly
30
- size={5}
31
- classNames='px-0 aspect-square'
33
+ label={t('zoom-in-icon.button')}
32
34
  onClick={() => onAction?.('zoom-in')}
33
35
  />
34
36
  <IconButton
35
37
  icon='ph--minus--regular'
36
- label='zoom out'
37
38
  iconOnly
38
- size={5}
39
- classNames='px-0 aspect-square'
39
+ label={t('zoom-out-icon.button')}
40
40
  onClick={() => onAction?.('zoom-out')}
41
41
  />
42
42
  </Toolbar.Root>
@@ -44,22 +44,20 @@ export const ZoomControls = ({ classNames, onAction }: ControlProps) => {
44
44
  };
45
45
 
46
46
  export const ActionControls = ({ classNames, onAction }: ControlProps) => {
47
+ const { t } = useTranslation(translationKey);
48
+
47
49
  return (
48
50
  <Toolbar.Root classNames={['gap-2', classNames]}>
49
51
  <IconButton
50
- icon='ph--play--regular'
51
- label='start'
52
+ icon='ph--path--regular'
52
53
  iconOnly
53
- size={5}
54
- classNames='px-0 aspect-square'
54
+ label={t('start-icon.button')}
55
55
  onClick={() => onAction?.('start')}
56
56
  />
57
57
  <IconButton
58
58
  icon='ph--globe-hemisphere-west--regular'
59
- label='toggle'
60
59
  iconOnly
61
- size={5}
62
- classNames='px-0 aspect-square'
60
+ label={t('toggle-icon.button')}
63
61
  onClick={() => onAction?.('toggle')}
64
62
  />
65
63
  </Toolbar.Root>
@@ -2,16 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { type Dispatch, type PropsWithChildren, type SetStateAction, createContext, useContext } from 'react';
5
+ import { type Dispatch, type SetStateAction, createContext, useContext } from 'react';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
- import { useControlledState } from '@dxos/react-ui';
9
8
 
10
9
  import { type LatLngLiteral } from '../types';
11
10
 
12
11
  // TODO(burdon): Factor out common geometry types.
13
12
  export type Size = { width: number; height: number };
13
+
14
14
  export type Point = { x: number; y: number };
15
+
15
16
  export type Vector = [number, number, number];
16
17
 
17
18
  export type GlobeContextType = {
@@ -26,33 +27,9 @@ export type GlobeContextType = {
26
27
  setRotation: Dispatch<SetStateAction<Vector>>;
27
28
  };
28
29
 
29
- const GlobeContext = createContext<GlobeContextType>(undefined);
30
-
31
- export type GlobeContextProviderProps = PropsWithChildren<
32
- Partial<Pick<GlobeContextType, 'size' | 'center' | 'zoom' | 'translation' | 'rotation'>>
33
- >;
34
-
35
- export const GlobeContextProvider = ({
36
- children,
37
- size,
38
- center: _center,
39
- zoom: _zoom,
40
- translation: _translation,
41
- rotation: _rotation,
42
- }: GlobeContextProviderProps) => {
43
- const [center, setCenter] = useControlledState(_center);
44
- const [zoom, setZoom] = useControlledState(_zoom);
45
- const [translation, setTranslation] = useControlledState<Point>(_translation);
46
- const [rotation, setRotation] = useControlledState<Vector>(_rotation);
47
-
48
- return (
49
- <GlobeContext.Provider
50
- value={{ size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation }}
51
- >
52
- {children}
53
- </GlobeContext.Provider>
54
- );
55
- };
30
+ /** @internal */
31
+ // TODO(burdon): Replace with radix.
32
+ export const GlobeContext = createContext<GlobeContextType>(undefined);
56
33
 
57
34
  export const useGlobeContext = () => {
58
35
  return useContext(GlobeContext) ?? raise(new Error('Missing GlobeContext'));
@@ -6,6 +6,8 @@ import { useCallback } from 'react';
6
6
 
7
7
  import { type ControlProps, type GlobeController } from '../components';
8
8
 
9
+ const ZOOM_FACTOR = 0.1;
10
+
9
11
  export const useGlobeZoomHandler = (controller: GlobeController | null | undefined): ControlProps['onAction'] => {
10
12
  return useCallback<ControlProps['onAction']>(
11
13
  (event) => {
@@ -15,11 +17,15 @@ export const useGlobeZoomHandler = (controller: GlobeController | null | undefin
15
17
 
16
18
  switch (event) {
17
19
  case 'zoom-in': {
18
- controller.setZoom((zoom) => zoom * 1.1);
20
+ controller.setZoom((zoom) => {
21
+ return zoom * (1 + ZOOM_FACTOR);
22
+ });
19
23
  break;
20
24
  }
21
25
  case 'zoom-out': {
22
- controller.setZoom((zoom) => zoom * 0.9);
26
+ controller.setZoom((zoom) => {
27
+ return zoom * (1 - ZOOM_FACTOR);
28
+ });
23
29
  break;
24
30
  }
25
31
  }
@@ -7,7 +7,6 @@ import { type Timer } from 'd3';
7
7
  import { useEffect, useState } from 'react';
8
8
 
9
9
  import { type GlobeController } from '../components';
10
-
11
10
  import { type Vector } from './context';
12
11
 
13
12
  export type SpinnerOptions = {
@@ -34,6 +34,7 @@ export const useTour = (
34
34
  options: TourOptions = {},
35
35
  ): [boolean, Dispatch<SetStateAction<boolean>>] => {
36
36
  const selection = useMemo(() => d3Selection(), []);
37
+ // TODO(burdon): Redo controlled state.
37
38
  const [running, setRunning] = useState(options.running ?? false);
38
39
  useEffect(() => {
39
40
  if (!running) {
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from './components';
6
- export * from './data';
7
6
  export * from './hooks';
8
7
  export type * from './types';
9
8
  export * from './util';
@@ -0,0 +1,20 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type Resource } from '@dxos/react-ui';
6
+
7
+ export const translationKey = '@dxos/react-ui-geo';
8
+
9
+ export const translations = [
10
+ {
11
+ 'en-US': {
12
+ [translationKey]: {
13
+ 'zoom-in-icon.button': 'Zoom in',
14
+ 'zoom-out-icon.button': 'Zoom out',
15
+ 'start-icon.button': 'Start',
16
+ 'toggle-icon.button': 'Toggle',
17
+ },
18
+ },
19
+ },
20
+ ] as const satisfies Resource[];
@@ -7,7 +7,6 @@ import { feature, mesh } from 'topojson-client';
7
7
  import { type Topology } from 'topojson-specification';
8
8
 
9
9
  import { type LatLngLiteral } from '../types';
10
-
11
10
  import { geoLine, geoPoint } from './path';
12
11
 
13
12
  export type Styles = Record<string, any>;
@@ -1,9 +0,0 @@
1
- // src/data.ts
2
- var loadTopology = async () => {
3
- return (await import("./countries-110m-ZM3ZIEFS.mjs")).default;
4
- };
5
-
6
- export {
7
- loadTopology
8
- };
9
- //# sourceMappingURL=chunk-GMWLKTLN.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/data.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Topology } from 'topojson-specification';\n\nexport const loadTopology = async (): Promise<Topology> => {\n return (await import('../data/countries-110m.ts')).default;\n};\n"],
5
- "mappings": ";AAMO,IAAMA,eAAe,YAAA;AAC1B,UAAQ,MAAM,OAAO,+BAAA,GAA8BC;AACrD;",
6
- "names": ["loadTopology", "default"]
7
- }
@@ -1,11 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/data.ts
4
- var loadTopology = async () => {
5
- return (await import("./countries-110m-3SFASWVD.mjs")).default;
6
- };
7
-
8
- export {
9
- loadTopology
10
- };
11
- //# sourceMappingURL=chunk-JODBF4CC.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/data.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Topology } from 'topojson-specification';\n\nexport const loadTopology = async (): Promise<Topology> => {\n return (await import('../data/countries-110m.ts')).default;\n};\n"],
5
- "mappings": ";;;AAMO,IAAMA,eAAe,YAAA;AAC1B,UAAQ,MAAM,OAAO,+BAAA,GAA8BC;AACrD;",
6
- "names": ["loadTopology", "default"]
7
- }