@open-pioneer/legend 0.11.0 → 0.12.0-dev.20250725080856
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/CHANGELOG.md +18 -1
- package/Legend.js +6 -4
- package/Legend.js.map +1 -1
- package/README.md +4 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @open-pioneer/legend
|
|
2
2
|
|
|
3
|
+
## 0.12.0-dev.20250725080856
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2702df4: A layer's `internal` property is now respected by the Legend widget. If a layer is marked as internal (`internal` is `true`) no legend entry is displayed for this layer even if the legend is configured in the layer attributes.
|
|
8
|
+
- 2732052: Icons have been changed to unify the appearance of the components. Preferably, Lucide react-icons are used.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 10d2fe7: Update dependencies
|
|
13
|
+
- da6a410: Update dependencies
|
|
14
|
+
- Updated dependencies [10d2fe7]
|
|
15
|
+
- Updated dependencies [2702df4]
|
|
16
|
+
- Updated dependencies [8986b3b]
|
|
17
|
+
- Updated dependencies [f1f69f2]
|
|
18
|
+
- Updated dependencies [da6a410]
|
|
19
|
+
- @open-pioneer/map@0.12.0-dev.20250725080856
|
|
20
|
+
|
|
3
21
|
## 0.11.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -72,7 +90,6 @@
|
|
|
72
90
|
### Minor Changes
|
|
73
91
|
|
|
74
92
|
- 2fa8020: Update trails core package dependencies.
|
|
75
|
-
|
|
76
93
|
- Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
|
|
77
94
|
- Removes any obsolete references to `@chakra-ui/system`.
|
|
78
95
|
This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
|
package/Legend.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { LuTriangleAlert } from 'react-icons/lu';
|
|
3
3
|
import { Box, List, Text, Icon, Image } from '@chakra-ui/react';
|
|
4
4
|
import { useMapModel, isLayer } from '@open-pioneer/map';
|
|
5
5
|
import { useCommonComponentProps } from '@open-pioneer/react-utils';
|
|
@@ -33,9 +33,11 @@ function LegendList(props) {
|
|
|
33
33
|
}
|
|
34
34
|
function LegendItem(props) {
|
|
35
35
|
const { layer, showBaseLayers } = props;
|
|
36
|
-
const isVisible = useReactiveSnapshot(() =>
|
|
36
|
+
const { isVisible, isInternal } = useReactiveSnapshot(() => {
|
|
37
|
+
return { isVisible: layer.visible, isInternal: layer.internal };
|
|
38
|
+
}, [layer]);
|
|
37
39
|
const childLayers = useChildLayers(layer);
|
|
38
|
-
if (!isVisible) {
|
|
40
|
+
if (!isVisible || isInternal) {
|
|
39
41
|
return void 0;
|
|
40
42
|
}
|
|
41
43
|
if (!showBaseLayers && isLayer(layer) && isBaseLayer(layer)) {
|
|
@@ -95,7 +97,7 @@ function LegendImage(props) {
|
|
|
95
97
|
const content = useMemo(() => {
|
|
96
98
|
if (isError) {
|
|
97
99
|
return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
98
|
-
/* @__PURE__ */ jsx(Icon, { me: 2, children: /* @__PURE__ */ jsx(
|
|
100
|
+
/* @__PURE__ */ jsx(Icon, { me: 2, children: /* @__PURE__ */ jsx(LuTriangleAlert, {}) }),
|
|
99
101
|
intl.formatMessage({ id: "fallbackLabel" })
|
|
100
102
|
] }) });
|
|
101
103
|
}
|
package/Legend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Legend.js","sources":["Legend.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { IoIosWarning } from \"react-icons/io\";\nimport { Box, Image, List, Text, Icon } from \"@chakra-ui/react\";\nimport { Layer, AnyLayer, MapModel, useMapModel, MapModelProps, isLayer } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport classNames from \"classnames\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { ComponentType, FC, ReactNode, useEffect, useMemo, useState } from \"react\";\n\n/**\n * Properties of a legend item React component.\n */\nexport interface LegendItemComponentProps {\n /**\n * Related layer of the legend.\n */\n layer: AnyLayer;\n}\n\n/**\n * Attributes of the legend attribute that can be specified on a layer.\n *\n * To show a legend for the layer, provide an imageUrl to an image to show\n * or provide a React component that will be rendered as a legend.\n *\n * LegendItemAttributes should be registered with a layer as the `\"legend\"` attribute.\n */\nexport interface LegendItemAttributes {\n /**\n * (Optional) URL to an image that will be shown as a legend for the layer.\n */\n imageUrl?: string;\n\n /**\n * (Optional) React component that will be shown as customized legend for the layer.\n */\n Component?: ComponentType<LegendItemComponentProps>;\n}\n\n/**\n * These are special properties for the Legend.\n */\nexport interface LegendProps extends CommonComponentProps, MapModelProps {\n /**\n * Specifies whether legend for active base layer is shown in the legend UI.\n * Defaults to `false`.\n */\n showBaseLayers?: boolean;\n}\n\n/**\n * The `Legend` component can be used to display the legend of layers that are visible in the map.\n */\nexport const Legend: FC<LegendProps> = (props) => {\n const { showBaseLayers = false } = props;\n const { containerProps } = useCommonComponentProps(\"legend\", props);\n const { map } = useMapModel(props);\n\n return (\n <Box {...containerProps}>\n {map ? <LegendList map={map} showBaseLayers={showBaseLayers} /> : null}\n </Box>\n );\n};\n\nfunction LegendList(props: { map: MapModel; showBaseLayers: boolean }): ReactNode {\n const { map, showBaseLayers } = props;\n\n const layers = useLayers(map);\n const legendListItems: ReactNode[] = layers.map((layer) => {\n return (\n <LegendItem key={layer.id} layer={layer} showBaseLayers={showBaseLayers}></LegendItem>\n );\n });\n\n return (\n <List.Root\n // Note: not using UnorderedList because it adds default margins\n as=\"ul\"\n className=\"legend-layer-list\"\n listStyleType=\"none\"\n gap={2}\n >\n {legendListItems}\n </List.Root>\n );\n}\n\nfunction LegendItem(props: { layer: AnyLayer; showBaseLayers: boolean }): ReactNode {\n const { layer, showBaseLayers } = props;\n const isVisible = useReactiveSnapshot(() => layer.visible, [layer]);\n const childLayers = useChildLayers(layer);\n\n if (!isVisible) {\n return undefined;\n }\n\n if (!showBaseLayers && isLayer(layer) && isBaseLayer(layer)) {\n return undefined;\n }\n\n // legend items for all child layers (sublayers or layers in a group)\n const childItems: ReactNode[] = [];\n if (childLayers?.length) {\n childLayers.forEach((childLayer) => {\n childItems.push(\n <LegendItem\n key={childLayer.id}\n layer={childLayer}\n showBaseLayers={showBaseLayers}\n />\n );\n });\n }\n\n return (\n <>\n <LegendContent layer={layer} showBaseLayers={showBaseLayers} />\n {childItems}\n </>\n );\n}\n\nfunction LegendContent(props: { layer: AnyLayer; showBaseLayers: boolean }) {\n const intl = useIntl();\n\n const { layer, showBaseLayers } = props;\n const baseLayer = isBaseLayer(layer);\n const legendAttributes = useLegendAttributes(layer);\n const legendUrl = useReactiveSnapshot(() => layer.legend, [layer]);\n\n let renderedComponent: ReactNode | undefined;\n if (legendAttributes?.Component) {\n renderedComponent = <legendAttributes.Component layer={layer} />;\n } else if (legendAttributes?.imageUrl) {\n renderedComponent = <LegendImage layer={layer} imageUrl={legendAttributes.imageUrl} />;\n } else {\n if (legendUrl) {\n renderedComponent = <LegendImage layer={layer} imageUrl={legendUrl} />;\n }\n }\n\n return renderedComponent ? (\n <Box as=\"li\" className={classNames(\"legend-item\", `layer-${slug(layer.id)}`)}>\n {showBaseLayers && baseLayer ? (\n /* Render additional text, if layer is a configured basemap */\n <Text as=\"b\">{intl.formatMessage({ id: \"basemapLabel\" })}</Text>\n ) : null}\n {renderedComponent}\n </Box>\n ) : undefined;\n}\n\nfunction LegendImage(props: { imageUrl: string; layer: AnyLayer }) {\n const intl = useIntl();\n\n const { layer, imageUrl } = props;\n\n const [isError, setIsError] = useState(false);\n useEffect(() => {\n setIsError(false);\n }, [imageUrl]);\n\n const content = useMemo(() => {\n if (isError) {\n return (\n <Box>\n <Text>\n <Icon me={2}>\n <IoIosWarning />\n </Icon>\n {intl.formatMessage({ id: \"fallbackLabel\" })}\n </Text>\n </Box>\n );\n }\n\n return (\n <Image\n maxW=\"none\"\n maxH=\"none\"\n src={imageUrl}\n alt={intl.formatMessage({ id: \"altLabel\" }, { layerName: layer.title })}\n className={\"legend-item__image\"}\n onError={() => setIsError(true)}\n />\n );\n }, [intl, layer.title, imageUrl, isError]);\n\n return (\n <Box>\n <Text>{layer.title}</Text>\n {content}\n </Box>\n );\n}\n\n/** Returns the top level operational layers in render order (topmost layer first). */\nfunction useLayers(map: MapModel): Layer[] {\n return useReactiveSnapshot(() => {\n const layers = map.layers.getLayers({ sortByDisplayOrder: true }) ?? [];\n layers.reverse(); // render topmost layer first\n return layers;\n }, [map]);\n}\n\n/**\n * Returns the child layers (sublayers or layers belonging to a GroupLayer) of the given layer\n * (or undefined, if the child layer cannot have any).\n * Layers are returned in render order (topmost layer first).\n */\nfunction useChildLayers(layer: AnyLayer): AnyLayer[] | undefined {\n return useReactiveSnapshot(() => {\n const childLayers = layer.children?.getItems();\n if (!childLayers) {\n return undefined;\n }\n\n childLayers.reverse(); // render topmost layer first\n return childLayers;\n }, [layer]);\n}\n\nfunction useLegendAttributes(layer: AnyLayer): LegendItemAttributes | undefined {\n return useReactiveSnapshot(\n () => layer.attributes.legend as LegendItemAttributes | undefined,\n [layer]\n );\n}\n\nfunction isBaseLayer(layer: AnyLayer) {\n return !(\"parentLayer\" in layer) && layer.isBaseLayer;\n}\n\nfunction slug(id: string) {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9 -]/g, \"\")\n .replace(/\\s+/g, \"-\")\n .replace(/-+/g, \"-\");\n}\n"],"names":[],"mappings":";;;;;;;;;;AAuDa,MAAA,MAAA,GAA0B,CAAC,KA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AAA;AACpB,IAAO,OAAA,WAAA;AAAA,GACX,EAAG,CAAC,KAAK,CAAC,CAAA;AACd;AAEA,SAAS,oBAAoB,KAAmD,EAAA;AAC5E,EAAO,OAAA,mBAAA;AAAA,IACH,MAAM,MAAM,UAAW,CAAA,MAAA;AAAA,IACvB,CAAC,KAAK;AAAA,GACV;AACJ;AAEA,SAAS,YAAY,KAAiB,EAAA;AAClC,EAAO,OAAA,EAAE,aAAiB,IAAA,KAAA,CAAA,IAAU,KAAM,CAAA,WAAA;AAC9C;AAEA,SAAS,KAAK,EAAY,EAAA;AACtB,EAAA,OAAO,EACF,CAAA,WAAA,EACA,CAAA,OAAA,CAAQ,cAAgB,EAAA,EAAE,CAC1B,CAAA,OAAA,CAAQ,MAAQ,EAAA,GAAG,CACnB,CAAA,OAAA,CAAQ,OAAO,GAAG,CAAA;AAC3B;;;;"}
|
|
1
|
+
{"version":3,"file":"Legend.js","sources":["Legend.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { LuTriangleAlert } from \"react-icons/lu\";\nimport { Box, Image, List, Text, Icon } from \"@chakra-ui/react\";\nimport { Layer, AnyLayer, MapModel, useMapModel, MapModelProps, isLayer } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport classNames from \"classnames\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { ComponentType, FC, ReactNode, useEffect, useMemo, useState } from \"react\";\n\n/**\n * Properties of a legend item React component.\n */\nexport interface LegendItemComponentProps {\n /**\n * Related layer of the legend.\n */\n layer: AnyLayer;\n}\n\n/**\n * Attributes of the legend attribute that can be specified on a layer.\n *\n * To show a legend for the layer, provide an imageUrl to an image to show\n * or provide a React component that will be rendered as a legend.\n *\n * LegendItemAttributes should be registered with a layer as the `\"legend\"` attribute.\n */\nexport interface LegendItemAttributes {\n /**\n * (Optional) URL to an image that will be shown as a legend for the layer.\n */\n imageUrl?: string;\n\n /**\n * (Optional) React component that will be shown as customized legend for the layer.\n */\n Component?: ComponentType<LegendItemComponentProps>;\n}\n\n/**\n * These are special properties for the Legend.\n */\nexport interface LegendProps extends CommonComponentProps, MapModelProps {\n /**\n * Specifies whether legend for active base layer is shown in the legend UI.\n * Defaults to `false`.\n */\n showBaseLayers?: boolean;\n}\n\n/**\n * The `Legend` component can be used to display the legend of layers that are visible in the map.\n */\nexport const Legend: FC<LegendProps> = (props) => {\n const { showBaseLayers = false } = props;\n const { containerProps } = useCommonComponentProps(\"legend\", props);\n const { map } = useMapModel(props);\n\n return (\n <Box {...containerProps}>\n {map ? <LegendList map={map} showBaseLayers={showBaseLayers} /> : null}\n </Box>\n );\n};\n\nfunction LegendList(props: { map: MapModel; showBaseLayers: boolean }): ReactNode {\n const { map, showBaseLayers } = props;\n\n const layers = useLayers(map);\n const legendListItems: ReactNode[] = layers.map((layer) => {\n return (\n <LegendItem key={layer.id} layer={layer} showBaseLayers={showBaseLayers}></LegendItem>\n );\n });\n\n return (\n <List.Root\n // Note: not using UnorderedList because it adds default margins\n as=\"ul\"\n className=\"legend-layer-list\"\n listStyleType=\"none\"\n gap={2}\n >\n {legendListItems}\n </List.Root>\n );\n}\n\nfunction LegendItem(props: { layer: AnyLayer; showBaseLayers: boolean }): ReactNode {\n const { layer, showBaseLayers } = props;\n const { isVisible, isInternal } = useReactiveSnapshot(() => {\n return { isVisible: layer.visible, isInternal: layer.internal };\n }, [layer]);\n const childLayers = useChildLayers(layer);\n\n if (!isVisible || isInternal) {\n return undefined;\n }\n\n if (!showBaseLayers && isLayer(layer) && isBaseLayer(layer)) {\n return undefined;\n }\n\n // legend items for all child layers (sublayers or layers in a group)\n const childItems: ReactNode[] = [];\n if (childLayers?.length) {\n childLayers.forEach((childLayer) => {\n childItems.push(\n <LegendItem\n key={childLayer.id}\n layer={childLayer}\n showBaseLayers={showBaseLayers}\n />\n );\n });\n }\n\n return (\n <>\n <LegendContent layer={layer} showBaseLayers={showBaseLayers} />\n {childItems}\n </>\n );\n}\n\nfunction LegendContent(props: { layer: AnyLayer; showBaseLayers: boolean }) {\n const intl = useIntl();\n\n const { layer, showBaseLayers } = props;\n const baseLayer = isBaseLayer(layer);\n const legendAttributes = useLegendAttributes(layer);\n const legendUrl = useReactiveSnapshot(() => layer.legend, [layer]);\n\n let renderedComponent: ReactNode | undefined;\n if (legendAttributes?.Component) {\n renderedComponent = <legendAttributes.Component layer={layer} />;\n } else if (legendAttributes?.imageUrl) {\n renderedComponent = <LegendImage layer={layer} imageUrl={legendAttributes.imageUrl} />;\n } else {\n if (legendUrl) {\n renderedComponent = <LegendImage layer={layer} imageUrl={legendUrl} />;\n }\n }\n\n return renderedComponent ? (\n <Box as=\"li\" className={classNames(\"legend-item\", `layer-${slug(layer.id)}`)}>\n {showBaseLayers && baseLayer ? (\n /* Render additional text, if layer is a configured basemap */\n <Text as=\"b\">{intl.formatMessage({ id: \"basemapLabel\" })}</Text>\n ) : null}\n {renderedComponent}\n </Box>\n ) : undefined;\n}\n\nfunction LegendImage(props: { imageUrl: string; layer: AnyLayer }) {\n const intl = useIntl();\n\n const { layer, imageUrl } = props;\n\n const [isError, setIsError] = useState(false);\n useEffect(() => {\n setIsError(false);\n }, [imageUrl]);\n\n const content = useMemo(() => {\n if (isError) {\n return (\n <Box>\n <Text>\n <Icon me={2}>\n <LuTriangleAlert />\n </Icon>\n {intl.formatMessage({ id: \"fallbackLabel\" })}\n </Text>\n </Box>\n );\n }\n\n return (\n <Image\n maxW=\"none\"\n maxH=\"none\"\n src={imageUrl}\n alt={intl.formatMessage({ id: \"altLabel\" }, { layerName: layer.title })}\n className={\"legend-item__image\"}\n onError={() => setIsError(true)}\n />\n );\n }, [intl, layer.title, imageUrl, isError]);\n\n return (\n <Box>\n <Text>{layer.title}</Text>\n {content}\n </Box>\n );\n}\n\n/** Returns the top level operational layers in render order (topmost layer first). */\nfunction useLayers(map: MapModel): Layer[] {\n return useReactiveSnapshot(() => {\n const layers = map.layers.getLayers({ sortByDisplayOrder: true }) ?? [];\n layers.reverse(); // render topmost layer first\n return layers;\n }, [map]);\n}\n\n/**\n * Returns the child layers (sublayers or layers belonging to a GroupLayer) of the given layer\n * (or undefined, if the child layer cannot have any).\n * Layers are returned in render order (topmost layer first).\n */\nfunction useChildLayers(layer: AnyLayer): AnyLayer[] | undefined {\n return useReactiveSnapshot(() => {\n const childLayers = layer.children?.getItems();\n if (!childLayers) {\n return undefined;\n }\n\n childLayers.reverse(); // render topmost layer first\n return childLayers;\n }, [layer]);\n}\n\nfunction useLegendAttributes(layer: AnyLayer): LegendItemAttributes | undefined {\n return useReactiveSnapshot(\n () => layer.attributes.legend as LegendItemAttributes | undefined,\n [layer]\n );\n}\n\nfunction isBaseLayer(layer: AnyLayer) {\n return !(\"parentLayer\" in layer) && layer.isBaseLayer;\n}\n\nfunction slug(id: string) {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9 -]/g, \"\")\n .replace(/\\s+/g, \"-\")\n .replace(/-+/g, \"-\");\n}\n"],"names":[],"mappings":";;;;;;;;;;AAuDa,MAAA,MAAA,GAA0B,CAAC,KAAU,KAAA;AAC9C,EAAM,MAAA,EAAE,cAAiB,GAAA,KAAA,EAAU,GAAA,KAAA;AACnC,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,UAAU,KAAK,CAAA;AAClE,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,KAAK,CAAA;AAEjC,EACI,uBAAA,GAAA,CAAC,GAAK,EAAA,EAAA,GAAG,cACJ,EAAA,QAAA,EAAA,GAAA,uBAAO,UAAW,EAAA,EAAA,GAAA,EAAU,cAAgC,EAAA,CAAA,GAAK,IACtE,EAAA,CAAA;AAER;AAEA,SAAS,WAAW,KAA8D,EAAA;AAC9E,EAAM,MAAA,EAAE,GAAK,EAAA,cAAA,EAAmB,GA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AY,EAAA;AACtB,EAAA,OAAO,EACF,CAAA,WAAA,EACA,CAAA,OAAA,CAAQ,cAAgB,EAAA,EAAE,CAC1B,CAAA,OAAA,CAAQ,MAAQ,EAAA,GAAG,CACnB,CAAA,OAAA,CAAQ,OAAO,GAAG,CAAA;AAC3B;;;;"}
|
package/README.md
CHANGED
|
@@ -69,6 +69,10 @@ If a configuration is done, it supersedes the automatic legend retrieval.
|
|
|
69
69
|
Showing legend entries is also supported for **sublayers** (configuration and automatic retrieval).
|
|
70
70
|
The legend content for sublayers is shown plain and without hierarchical structure in the Legend UI.
|
|
71
71
|
|
|
72
|
+
#### Internal layers
|
|
73
|
+
|
|
74
|
+
If a layer is marked as internal (layer's `internal` property is `true`) it will not be considered in the legend widget. Even if a legend is configured it will not be displayed. The `internal` property also affects other UI widgets (e.g. Toc).
|
|
75
|
+
|
|
72
76
|
### Showing legend for basemap
|
|
73
77
|
|
|
74
78
|
By default, the legend for the active basemap is not shown.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/legend",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0-dev.20250725080856",
|
|
5
5
|
"description": "This package provides a legend UI component that allows a user to see legend information for layers in the map.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"directory": "src/packages/legend"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@chakra-ui/react": "^3.
|
|
17
|
+
"@chakra-ui/react": "^3.21.1",
|
|
18
18
|
"@open-pioneer/react-utils": "^4.0.0",
|
|
19
19
|
"@open-pioneer/runtime": "^4.0.0",
|
|
20
20
|
"classnames": "^2.5.1",
|
|
21
|
-
"ol": "^10.
|
|
21
|
+
"ol": "^10.6.1",
|
|
22
22
|
"react": "^19.1.0",
|
|
23
23
|
"@open-pioneer/reactivity": "^4.0.0",
|
|
24
24
|
"react-icons": "^5.5.0",
|
|
25
|
-
"@open-pioneer/map": "
|
|
25
|
+
"@open-pioneer/map": "0.12.0-dev.20250725080856"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|