@carto/ps-react-maps 1.2.0 → 1.3.1-alpha.0
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/index.cjs +10 -10
- package/dist/index.js +567 -444
- package/dist/types/index.d.ts +1 -0
- package/dist/types/map-provider/index.d.ts +1 -1
- package/dist/types/map-provider/map-provider.const.d.ts +1 -1
- package/dist/types/map-provider/map-provider.hook.d.ts +60 -15
- package/dist/types/map-provider/map-provider.provider.d.ts +0 -3
- package/dist/types/map-provider/map-provider.reducer.d.ts +2 -1
- package/dist/types/map-provider/map-provider.types.d.ts +19 -10
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/object-to-html/index.d.ts +2 -0
- package/dist/types/utils/object-to-html/object-to-html.contants.d.ts +2 -0
- package/dist/types/utils/object-to-html/object-to-html.d.ts +37 -0
- package/dist/types/utils/object-to-html/types.d.ts +26 -0
- package/package.json +3 -3
package/dist/types/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from './map-provider.const';
|
|
|
2
2
|
export * from './map-provider.types';
|
|
3
3
|
export { INITIAL_STATE, MapContext, MapActionsContext, } from './map-provider.context';
|
|
4
4
|
export { reducer } from './map-provider.reducer';
|
|
5
|
-
export { useMap, useMapActions, useMapByID, useMapActionsByID, useMapReferencesByID, } from './map-provider.hook';
|
|
5
|
+
export { useMap, useMapActions, useMapRefences, useMapByID, useMapActionsByID, useMapReferencesByID, } from './map-provider.hook';
|
|
6
6
|
export { MapProvider } from './map-provider.provider';
|
|
@@ -1,31 +1,76 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeckGLMapsProps, MapProviderMapProps, MapReferences, MapResize, OverlayMapRef, ViewportRect } from './map-provider.types';
|
|
2
|
+
import type { Deck, WebMercatorViewport } from '@deck.gl/core/typed';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
4
|
+
* Custom hook that retrieves the map configuration for a given ID.
|
|
5
|
+
* @param id - The ID of the map.
|
|
6
|
+
* @returns The map configuration for the specified ID.
|
|
5
7
|
*/
|
|
6
|
-
export declare function useMap():
|
|
7
|
-
export declare function useRefences(): import("react").MutableRefObject<import("./map-provider.types").MapReferencesState>;
|
|
8
|
+
export declare function useMap(id: string): MapProviderMapProps;
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Custom hook that provides access to the map references and related functions.
|
|
11
|
+
*
|
|
12
|
+
* @param id - The ID of the map reference.
|
|
13
|
+
* @returns An object containing the map references and functions.
|
|
11
14
|
*/
|
|
12
|
-
export declare function
|
|
15
|
+
export declare function useMapRefences(id: string): MapReferences & {
|
|
16
|
+
getDeckInstance: () => Deck | undefined;
|
|
17
|
+
getOverlayInstance: () => OverlayMapRef | undefined;
|
|
18
|
+
getViewState: () => DeckGLMapsProps['viewState'];
|
|
19
|
+
getViewports: (rect?: ViewportRect) => WebMercatorViewport[];
|
|
20
|
+
getViewport: (index?: number, rect?: ViewportRect) => WebMercatorViewport;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Custom hook that provides map actions for a specific map ID.
|
|
24
|
+
* @param id - The ID of the map.
|
|
25
|
+
* @returns An object containing map actions.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useMapActions(id: string): {
|
|
28
|
+
setBasemap: (basemap: any) => void;
|
|
29
|
+
setResize: (props: MapResize) => void;
|
|
30
|
+
setViewState: (viewState: DeckGLMapsProps['viewState']) => void;
|
|
31
|
+
setZoom: (zoom: number) => void;
|
|
32
|
+
setLoaded: (loaded: boolean) => void;
|
|
33
|
+
fitBounds: (bounds: Parameters<WebMercatorViewport['fitBounds']>[0], { boundsOptions, viewStateOptions, }?: {
|
|
34
|
+
boundsOptions?: Parameters<WebMercatorViewport['fitBounds']>[1];
|
|
35
|
+
viewStateOptions?: any;
|
|
36
|
+
}) => void;
|
|
37
|
+
};
|
|
13
38
|
/**
|
|
14
39
|
* Returns the map with the given ID from the current map state.
|
|
15
40
|
* @param {string} id - The ID of the map to retrieve.
|
|
16
41
|
* @returns {MapContextInterface['state']['maps'][string]} The map with the given ID.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated Use `useMap` with id param instead.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useMapByID(id: string): MapProviderMapProps;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `useMapReferences` with id param instead.
|
|
17
48
|
*/
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function useMapReferencesByID(id: string): {
|
|
20
|
-
instanceRef: import("react").MutableRefObject<import("./map-provider.types").InstanceMapRef>;
|
|
21
|
-
overlayRef: import("react").MutableRefObject<import("./map-provider.types").OverlayMapRef>;
|
|
49
|
+
export declare function useMapReferencesByID(id: string): MapReferences & {
|
|
22
50
|
getDeckInstance: () => Deck | undefined;
|
|
23
|
-
getOverlayInstance: () =>
|
|
51
|
+
getOverlayInstance: () => OverlayMapRef | undefined;
|
|
24
52
|
getViewState: () => any;
|
|
53
|
+
getViewports: (rect?: ViewportRect | undefined) => WebMercatorViewport[];
|
|
54
|
+
getViewport: (index?: number | undefined, rect?: ViewportRect | undefined) => WebMercatorViewport;
|
|
25
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
@deprecated Use `useMapActions` with id param instead.
|
|
58
|
+
*/
|
|
26
59
|
export declare function useMapActionsByID(id: string): {
|
|
27
|
-
setBasemap: (basemap:
|
|
28
|
-
setResize: (props:
|
|
60
|
+
setBasemap: (basemap: any) => void;
|
|
61
|
+
setResize: (props: MapResize) => void;
|
|
29
62
|
setViewState: (viewState: any) => void;
|
|
30
63
|
setZoom: (zoom: number) => void;
|
|
64
|
+
setLoaded: (loaded: boolean) => void;
|
|
65
|
+
fitBounds: (bounds: [[number, number], [number, number]], { boundsOptions, viewStateOptions, }?: {
|
|
66
|
+
boundsOptions?: {
|
|
67
|
+
width?: number | undefined;
|
|
68
|
+
height?: number | undefined;
|
|
69
|
+
minExtent?: number | undefined;
|
|
70
|
+
maxZoom?: number | undefined;
|
|
71
|
+
padding?: number | Required<import("@deck.gl/core/typed/viewports/viewport").Padding> | undefined;
|
|
72
|
+
offset?: number[] | undefined;
|
|
73
|
+
} | undefined;
|
|
74
|
+
viewStateOptions?: any;
|
|
75
|
+
}) => void;
|
|
31
76
|
};
|
|
@@ -2,9 +2,6 @@ import type { MapProviderProps } from './map-provider.types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Provides a context for maps and their state management.
|
|
4
4
|
* @param {MapProviderProps} props - The props for the MapProvider component.
|
|
5
|
-
* @param {ReactNode} props.children - The child components to be rendered.
|
|
6
|
-
* @param {MapsProps[]} props.maps - An array of maps to be managed by the provider.
|
|
7
|
-
* @param {Function} props.externalSync - A function to sync the state with an external source.
|
|
8
5
|
* @returns {JSX.Element} - The MapProvider component.
|
|
9
6
|
*
|
|
10
7
|
* @remarks
|
|
@@ -8,16 +8,18 @@ import type { MutableRefObject, ReactNode } from 'react';
|
|
|
8
8
|
import type { MapRef } from 'react-map-gl';
|
|
9
9
|
import { CartoBasemapsNames, GMapsBasemap } from './map-provider.const';
|
|
10
10
|
import type { Actions } from './map-provider.reducer';
|
|
11
|
+
export type MapProviderMapProps = {
|
|
12
|
+
id: MapsProps['id'];
|
|
13
|
+
basemap: MapsProps['basemap'];
|
|
14
|
+
viewState: MapsProps['viewState'];
|
|
15
|
+
isLoaded?: boolean;
|
|
16
|
+
};
|
|
11
17
|
/**
|
|
12
18
|
* Props for the MapProvider component.
|
|
13
19
|
*/
|
|
14
20
|
export type MapProviderProps = {
|
|
15
21
|
children: ReactNode;
|
|
16
|
-
maps:
|
|
17
|
-
id: MapsProps['id'];
|
|
18
|
-
basemap: MapsProps['basemap'];
|
|
19
|
-
viewState: MapsProps['viewState'];
|
|
20
|
-
}[];
|
|
22
|
+
maps: MapProviderMapProps[];
|
|
21
23
|
externalSync?: ExternalSync;
|
|
22
24
|
};
|
|
23
25
|
export type ExternalSync = (data: ExternalSyncProps) => void;
|
|
@@ -32,7 +34,7 @@ export type ExternalSyncProps = {
|
|
|
32
34
|
* State for the MapProvider component.
|
|
33
35
|
*/
|
|
34
36
|
export type MapState = {
|
|
35
|
-
maps: Record<MapsProps['id'],
|
|
37
|
+
maps: Record<MapsProps['id'], MapProviderMapProps>;
|
|
36
38
|
};
|
|
37
39
|
/**
|
|
38
40
|
* Resize properties for the map.
|
|
@@ -50,10 +52,11 @@ export type MapReferencesState = Record<MapsProps['id'], MapReferences>;
|
|
|
50
52
|
* Actions that can be performed on the map.
|
|
51
53
|
*/
|
|
52
54
|
export type MapActionsState = {
|
|
53
|
-
setViewState: (
|
|
54
|
-
setResize: (id: MapsProps['id']
|
|
55
|
-
setBasemap: (id: MapsProps['id']
|
|
56
|
-
setZoom: (id: MapsProps['id']
|
|
55
|
+
setViewState: (viewState: DeckGLMapsProps['viewState'], id: MapsProps['id']) => void;
|
|
56
|
+
setResize: (props: MapResize, id: MapsProps['id']) => void;
|
|
57
|
+
setBasemap: (basemap: Basemap, id: MapsProps['id']) => void;
|
|
58
|
+
setZoom: (zoom: number, id: MapsProps['id']) => void;
|
|
59
|
+
setLoaded: (loaded: boolean, id: MapsProps['id']) => void;
|
|
57
60
|
};
|
|
58
61
|
/**
|
|
59
62
|
* Context interface for the MapProvider component.
|
|
@@ -112,3 +115,9 @@ export type Tooltip = {
|
|
|
112
115
|
className?: string | undefined;
|
|
113
116
|
style?: Partial<CSSStyleDeclaration> | undefined;
|
|
114
117
|
} & PickingInfo;
|
|
118
|
+
export type ViewportRect = {
|
|
119
|
+
x: number;
|
|
120
|
+
y: number;
|
|
121
|
+
width?: number;
|
|
122
|
+
height?: number;
|
|
123
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './object-to-html';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ObjectToHtmlOptions, Value } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a string with the HTML content for an object.
|
|
4
|
+
*
|
|
5
|
+
* @param {ObjectToHtmlOptions} - The options of the formatter.
|
|
6
|
+
*
|
|
7
|
+
* @return {string}
|
|
8
|
+
*
|
|
9
|
+
* @defaultValues
|
|
10
|
+
*
|
|
11
|
+
* | Prop | Value |
|
|
12
|
+
* | --- | --- |
|
|
13
|
+
* | `formatters` | `{}` |
|
|
14
|
+
* | `includeColumns` | `Object.keys(properties)` |
|
|
15
|
+
* | `locale` | `en-US` |
|
|
16
|
+
* | `showColumnName` | `true` |
|
|
17
|
+
* | `title` | `''` |
|
|
18
|
+
* | `getColumnName` | `Function` |
|
|
19
|
+
* | `getFieldHtml` | `Function` |
|
|
20
|
+
* | `getTitle` | `Function` |
|
|
21
|
+
* | `getValue` | `Function` |
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const properties = {
|
|
25
|
+
* name: 'I am a feature',
|
|
26
|
+
* price: 100,
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* const html = objectToHtml({
|
|
30
|
+
* properties,
|
|
31
|
+
* formatters: {
|
|
32
|
+
* price: 'CURRENCY',
|
|
33
|
+
* },
|
|
34
|
+
* locale: 'es-ES',
|
|
35
|
+
* })
|
|
36
|
+
*/
|
|
37
|
+
export declare function objectToHtml<T extends Record<string, Value>>({ properties, formatters, includeColumns, locale, showColumnName, title, getColumnName, getFieldHtml, getTitle, getValue, }: ObjectToHtmlOptions<T>): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum FormatterTypes {
|
|
2
|
+
CURRENCY = "CURRENCY",
|
|
3
|
+
DEFAULT = "DEFAULT",
|
|
4
|
+
NUMBER = "NUMBER"
|
|
5
|
+
}
|
|
6
|
+
export type Format = (value: Value, locale: string) => string;
|
|
7
|
+
export type FormatterType = `${FormatterTypes}` | FormatterTypes;
|
|
8
|
+
export interface Formatter {
|
|
9
|
+
type: FormatterType;
|
|
10
|
+
format: Format;
|
|
11
|
+
}
|
|
12
|
+
export type Formatters = Record<FormatterType, Formatter>;
|
|
13
|
+
export type FieldFormatter = FormatterType | Format;
|
|
14
|
+
export type Value = string | number;
|
|
15
|
+
export interface ObjectToHtmlOptions<T extends Record<string, Value>> {
|
|
16
|
+
properties: T;
|
|
17
|
+
formatters?: Record<string, FieldFormatter>;
|
|
18
|
+
includeColumns?: string[];
|
|
19
|
+
locale?: string;
|
|
20
|
+
showColumnName?: boolean;
|
|
21
|
+
title?: string;
|
|
22
|
+
getColumnName?: (name: string) => string;
|
|
23
|
+
getFieldHtml?: (column: string, value: Value) => string;
|
|
24
|
+
getTitle?: (title: string) => string;
|
|
25
|
+
getValue?: (value: Value, locale: string, formatter: FieldFormatter) => string;
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carto/ps-react-maps",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1-alpha.0",
|
|
4
4
|
"description": "CARTO's Professional Service React Maps library",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@carto/react-basemaps": "2.3.
|
|
33
|
+
"@carto/react-basemaps": "2.3.6",
|
|
34
34
|
"@deck.gl/core": "8.9.33",
|
|
35
35
|
"@deck.gl/google-maps": "8.9.33",
|
|
36
36
|
"@deck.gl/react": "8.9.33",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@storybook/react": "7.6.7",
|
|
45
45
|
"@storybook/react-vite": "7.6.7",
|
|
46
46
|
"@storybook/testing-library": "0.2.2",
|
|
47
|
-
"@testing-library/jest-dom": "6.
|
|
47
|
+
"@testing-library/jest-dom": "6.2.0",
|
|
48
48
|
"@testing-library/react": "14.1.2",
|
|
49
49
|
"@testing-library/user-event": "14.5.2",
|
|
50
50
|
"@types/google.maps": "3.54.10",
|