@open-pioneer/map-test-utils 1.0.0-dev.20251020091932 → 1.0.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/CHANGELOG.md +7 -5
- package/README.md +0 -2
- package/index.d.ts +2 -1
- package/index.js +1 -4
- package/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @open-pioneer/map-test-utils
|
|
2
2
|
|
|
3
|
-
## 1.0.0
|
|
3
|
+
## 1.0.0
|
|
4
4
|
|
|
5
5
|
### Major Changes
|
|
6
6
|
|
|
@@ -12,24 +12,25 @@
|
|
|
12
12
|
### Minor Changes
|
|
13
13
|
|
|
14
14
|
- 14c484e: Create a new test helper `createTestOlLayer()` that returns a simple, empty (tile) layer.
|
|
15
|
-
- 2abcaaf: Update to chakra-ui 3.
|
|
15
|
+
- 2abcaaf: Update to chakra-ui 3.28.0
|
|
16
16
|
|
|
17
17
|
### Patch Changes
|
|
18
18
|
|
|
19
19
|
- 10d2fe7: Update dependencies
|
|
20
|
-
- 138d85b: Update core packages to 4.
|
|
20
|
+
- 138d85b: Update core packages to 4.2.0
|
|
21
21
|
- da6a410: Update dependencies
|
|
22
22
|
- Updated dependencies [c6180c6]
|
|
23
23
|
- Updated dependencies [29a10df]
|
|
24
24
|
- Updated dependencies [10d2fe7]
|
|
25
|
+
- Updated dependencies [4f1e7bd]
|
|
25
26
|
- Updated dependencies [2702df4]
|
|
26
27
|
- Updated dependencies [12561fe]
|
|
27
28
|
- Updated dependencies [5df900f]
|
|
28
29
|
- Updated dependencies [8986b3b]
|
|
29
30
|
- Updated dependencies [b3709f1]
|
|
30
|
-
- Updated dependencies [dfd7c7e]
|
|
31
31
|
- Updated dependencies [14c484e]
|
|
32
32
|
- Updated dependencies [138d85b]
|
|
33
|
+
- Updated dependencies [4f1e7bd]
|
|
33
34
|
- Updated dependencies [aeb9000]
|
|
34
35
|
- Updated dependencies [9e9bc6e]
|
|
35
36
|
- Updated dependencies [b3709f1]
|
|
@@ -37,10 +38,11 @@
|
|
|
37
38
|
- Updated dependencies [b3709f1]
|
|
38
39
|
- Updated dependencies [5df900f]
|
|
39
40
|
- Updated dependencies [f1f69f2]
|
|
41
|
+
- Updated dependencies [a1614de]
|
|
40
42
|
- Updated dependencies [773fa2d]
|
|
41
43
|
- Updated dependencies [2abcaaf]
|
|
42
44
|
- Updated dependencies [da6a410]
|
|
43
|
-
- @open-pioneer/map@1.0.0
|
|
45
|
+
- @open-pioneer/map@1.0.0
|
|
44
46
|
|
|
45
47
|
## 0.11.0
|
|
46
48
|
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpServiceRequestInit } from "@open-pioneer/http";
|
|
2
|
-
import { ExtentConfig, Layer, LayerCreateOptions, MapModel, LayerConfig as MapPackageLayerConfig, MapRegistry, OlMapOptions, SimpleLayer, SimpleLayerConfig } from "@open-pioneer/map";
|
|
2
|
+
import { ExtentConfig, Layer, LayerCreateOptions, LayerFactory, MapModel, LayerConfig as MapPackageLayerConfig, MapRegistry, OlMapOptions, SimpleLayer, SimpleLayerConfig } from "@open-pioneer/map";
|
|
3
3
|
import TileLayer from "ol/layer/Tile";
|
|
4
4
|
export type LayerConfig = SimpleLayerConfig | Layer;
|
|
5
5
|
export interface SimpleMapOptions {
|
|
@@ -60,6 +60,7 @@ export declare function waitForInitialExtent(model: MapModel): Promise<void>;
|
|
|
60
60
|
export interface SetupMapResult {
|
|
61
61
|
mapId: string;
|
|
62
62
|
registry: MapRegistry;
|
|
63
|
+
layerFactory: LayerFactory;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Creates a simple map registry service with exactly one map configuration.
|
package/index.js
CHANGED
|
@@ -83,7 +83,7 @@ async function setupMap(options) {
|
|
|
83
83
|
} else {
|
|
84
84
|
promise.catch(() => void 0);
|
|
85
85
|
}
|
|
86
|
-
return { mapId, registry, map };
|
|
86
|
+
return { mapId, registry, layerFactory, map };
|
|
87
87
|
}
|
|
88
88
|
function getInitialView(options) {
|
|
89
89
|
if (options?.extent) {
|
|
@@ -132,9 +132,6 @@ function mockVectorLayer() {
|
|
|
132
132
|
VectorLayer.prototype.render = () => {
|
|
133
133
|
return div;
|
|
134
134
|
};
|
|
135
|
-
VectorLayer.prototype.setStyle = () => {
|
|
136
|
-
};
|
|
137
|
-
VectorLayer.prototype.getStyleFunction = () => () => [];
|
|
138
135
|
}
|
|
139
136
|
mockVectorLayer();
|
|
140
137
|
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { watch } from \"@conterra/reactivity-core\";\nimport { HttpService, HttpServiceRequestInit } from \"@open-pioneer/http\";\nimport {\n ExtentConfig,\n InitialViewConfig,\n Layer,\n LayerCreateOptions,\n LayerFactory,\n MapConfig,\n MapModel,\n LayerConfig as MapPackageLayerConfig,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig\n} from \"@open-pioneer/map\";\nimport {\n LayerFactory as LayerFactoryImpl,\n MapRegistry as MapRegistryImpl\n} from \"@open-pioneer/map/internalTestSupport\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport TileLayer from \"ol/layer/Tile\";\nimport VectorLayer from \"ol/layer/Vector\";\n\nexport type LayerConfig = SimpleLayerConfig | Layer;\n\nexport interface SimpleMapOptions {\n /** ID of the map.\n * Defaults to \"test\". */\n mapId?: string;\n\n /** Center coordinates for the map. */\n center?: { x: number; y: number };\n\n /** Zoom level of the map. */\n zoom?: number;\n\n /**\n * Initial extent (don't mix with center / zoom).\n */\n extent?: ExtentConfig;\n\n /**\n * The map's projection.\n */\n projection?: string;\n\n /**\n * Layers used by the map.\n */\n layers?: LayerConfig[];\n\n /**\n * Overrides fetching of network resources (such as service capabilities).\n */\n fetch?: (resource: URL, init: HttpServiceRequestInit | undefined) => Promise<Response>;\n\n /**\n * Passed to the open layers map constructor.\n */\n advanced?: OlMapOptions;\n\n /**\n * Disables the initial view when set to true.\n */\n noInitialView?: boolean;\n\n /**\n * Disables the default projection when set to true.\n */\n noProjection?: boolean;\n\n /**\n * Also returns the map object in the return value.\n * True by default.\n *\n * Use `false` to test the async loading behavior of the registry.\n */\n returnMap?: boolean;\n}\nconst DUMMY_HTTP_SERVICE = {\n async fetch() {\n throw new Error(\n \"Network requests are not implemented (override fetch via map test utils if your test requires network access).\"\n );\n }\n} satisfies Partial<HttpService> as HttpService;\nconst DUMMY_LAYER_FACTORY = createLayerFactory();\n\n/**\n * Waits until the OpenLayers map has been mounted in the parent with the given id.\n */\nexport async function waitForMapMount(parentTestId = \"base\") {\n return await waitFor(async () => {\n const domElement = await screen.findByTestId(parentTestId);\n const container = domElement.querySelector(\".ol-viewport\");\n if (!container) {\n throw new Error(\"map not mounted\");\n }\n return domElement;\n });\n}\n\n/**\n * Waits until the model has an initial extent.\n */\nexport async function waitForInitialExtent(model: MapModel) {\n if (model.initialExtent) {\n return;\n }\n\n await new Promise<void>((resolve, reject) => {\n const resource = watch(\n () => [model.initialExtent],\n ([extent]) => {\n resource.destroy();\n if (extent) {\n resolve();\n } else {\n reject(new Error(\"Expected a valid initial extent\"));\n }\n }\n );\n });\n}\n\nexport interface SetupMapResult {\n mapId: string;\n registry: MapRegistry;\n}\n\n/**\n * Creates a simple map registry service with exactly one map configuration.\n *\n * The map is configured by using the `options` parameter.\n * If `options.returnMap` is `true` (the default), the map model is also returned.\n *\n * Returns the map registry and the id of the configured map.\n */\nexport async function setupMap(\n options?: SimpleMapOptions & { returnMap?: true }\n): Promise<SetupMapResult & { map: MapModel }>;\nexport async function setupMap(options?: SimpleMapOptions): Promise<SetupMapResult>;\nexport async function setupMap(\n options?: SimpleMapOptions\n): Promise<SetupMapResult & { map: MapModel | undefined }> {\n const mapId = options?.mapId ?? \"test\";\n const mapConfig: MapConfig = {\n initialView: options?.noInitialView ? undefined : getInitialView(options),\n projection: options?.noProjection ? undefined : (options?.projection ?? \"EPSG:3857\"),\n layers: options?.layers?.map(\n (config) =>\n \"map\" in config\n ? config\n : createTestLayer({ type: SimpleLayer, ...(config as SimpleLayerConfig) })\n // using map as discriminator (no prototype for Layer)\n ) ?? [createTestLayer()],\n advanced: options?.advanced\n };\n\n const httpService = {\n async fetch(resource, init) {\n if (options?.fetch) {\n const url = new URL(resource, \"http://localhost:1234\");\n return options.fetch(url, init);\n }\n throw new Error(\n \"Network requests are not implemented (override fetch via map test utils if your test requires network access).\"\n );\n }\n } satisfies Partial<HttpService> as HttpService;\n\n const layerFactory = await createService(LayerFactoryImpl, {\n references: {\n httpService\n }\n });\n\n const registry = await createService(MapRegistryImpl, {\n references: {\n providers: [],\n httpService,\n layerFactory\n }\n });\n\n let map: MapModel | undefined;\n const promise = registry.createMapModel(mapId, mapConfig);\n if (options?.returnMap !== false) {\n map = await promise;\n } else {\n // Ignore error on this promise (prevents unhandled error in tests)\n promise.catch(() => undefined);\n }\n return { mapId, registry, map };\n}\n\nfunction getInitialView(options: SimpleMapOptions | undefined): InitialViewConfig {\n if (options?.extent) {\n return {\n kind: \"extent\",\n extent: options.extent\n };\n }\n return {\n kind: \"position\",\n center: options?.center ?? { x: 847541, y: 6793584 },\n zoom: options?.zoom ?? 10\n };\n}\n\n/** Creates an new layer of the specified type for testing. */\nexport function createTestLayer<LayerType extends Layer, Config extends MapPackageLayerConfig>(\n config: LayerCreateOptions<LayerType, Config>,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): LayerType;\n\n/** Creates a new, basic SimpleLayer for testing. */\nexport function createTestLayer(\n config?: SimpleLayerConfig,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): SimpleLayer;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTestLayer(config?: any, mapOptions?: Pick<SimpleMapOptions, \"fetch\">): Layer {\n // Basic case: If no config is given, use SimpleLayer\n if (!config) {\n config = {\n type: SimpleLayer,\n title: \"Test layer\",\n olLayer: new VectorLayer()\n } as LayerCreateOptions<SimpleLayer, SimpleLayerConfig>;\n } else if (!config.type) {\n config.type = SimpleLayer;\n }\n\n const factory = mapOptions?.fetch\n ? createLayerFactory({ fetch: mapOptions.fetch })\n : DUMMY_LAYER_FACTORY;\n return factory.create(config);\n}\n\n/**\n * Returns a simple, empty OpenLayers layer object.\n *\n * Use this if you need any kind of `olLayer` in your test.\n */\nexport function createTestOlLayer(): TileLayer {\n return new TileLayer();\n}\n\n/**\n * Creates (service name, service implementation)-pairs suitable for the `services`\n * option of the `PackageContextProvider`.\n *\n * This helper method can be used to avoid hard-coding service names used in the implementation.\n *\n * @deprecated This function is no longer needed, since most widgets no longer depend on the registry\n * and accept the `map` directly.\n */\nexport function createServiceOptions(services: { registry: MapRegistry }): Record<string, unknown> {\n return {\n \"map.MapRegistry\": services.registry\n };\n}\n\nfunction createLayerFactory(httpService?: HttpService): LayerFactory {\n return new LayerFactoryImpl({\n intl: {} satisfies Partial<PackageIntl> as PackageIntl,\n references: { httpService: httpService ?? DUMMY_HTTP_SERVICE },\n properties: {},\n referencesMeta: { httpService: { serviceId: \"http.HttpService\" } }\n });\n}\n\nfunction mockVectorLayer() {\n // Overwrite render so it doesn't actually do anything during tests.\n // Would otherwise error because <canvas /> is not fully implemented in happy dom.\n const div = document.createElement(\"div\");\n VectorLayer.prototype.render = () => {\n return div;\n };\n\n // Needed by tests in editing package\n VectorLayer.prototype.setStyle = () => {};\n VectorLayer.prototype.getStyleFunction = () => () => [];\n}\n\nmockVectorLayer();\n"],"names":["LayerFactoryImpl","MapRegistryImpl"],"mappings":";;;;;;;;AAoFA,MAAM,kBAAA,GAAqB;AAAA,EACvB,MAAM,KAAA,GAAQ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Y,EAAE,WAAA,EAAa,WAAA,IAAe,kBAAA,EAAmB;AAAA,IAC7D,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAE,WAAA,EAAa,EAAE,SAAA,EAAW,oBAAmB;AAAE,GACpE,CAAA;AACL;AAEA,SAAS,eAAA,GAAkB;AAGvB,EAAA,MAAM,GAAA,GAAM,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,SAAS,MAAM;AACjC,IAAA,OAAO,GAAA;AAAA,EACX,CAAA;AAGA,EAAA,WAAA,CAAY,SAAA,CAAU,WAAW,MAAM;AAAA,EAAC,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,gBAAA,GAAmB,MAAM,MAAM,EAAC;AAC1D;AAEA,eAAA,EAAgB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { watch } from \"@conterra/reactivity-core\";\nimport { HttpService, HttpServiceRequestInit } from \"@open-pioneer/http\";\nimport {\n ExtentConfig,\n InitialViewConfig,\n Layer,\n LayerCreateOptions,\n LayerFactory,\n MapConfig,\n MapModel,\n LayerConfig as MapPackageLayerConfig,\n MapRegistry,\n OlMapOptions,\n SimpleLayer,\n SimpleLayerConfig\n} from \"@open-pioneer/map\";\nimport {\n LayerFactory as LayerFactoryImpl,\n MapRegistry as MapRegistryImpl\n} from \"@open-pioneer/map/internalTestSupport\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { createService } from \"@open-pioneer/test-utils/services\";\nimport { screen, waitFor } from \"@testing-library/react\";\nimport TileLayer from \"ol/layer/Tile\";\nimport VectorLayer from \"ol/layer/Vector\";\n\nexport type LayerConfig = SimpleLayerConfig | Layer;\n\nexport interface SimpleMapOptions {\n /** ID of the map.\n * Defaults to \"test\". */\n mapId?: string;\n\n /** Center coordinates for the map. */\n center?: { x: number; y: number };\n\n /** Zoom level of the map. */\n zoom?: number;\n\n /**\n * Initial extent (don't mix with center / zoom).\n */\n extent?: ExtentConfig;\n\n /**\n * The map's projection.\n */\n projection?: string;\n\n /**\n * Layers used by the map.\n */\n layers?: LayerConfig[];\n\n /**\n * Overrides fetching of network resources (such as service capabilities).\n */\n fetch?: (resource: URL, init: HttpServiceRequestInit | undefined) => Promise<Response>;\n\n /**\n * Passed to the open layers map constructor.\n */\n advanced?: OlMapOptions;\n\n /**\n * Disables the initial view when set to true.\n */\n noInitialView?: boolean;\n\n /**\n * Disables the default projection when set to true.\n */\n noProjection?: boolean;\n\n /**\n * Also returns the map object in the return value.\n * True by default.\n *\n * Use `false` to test the async loading behavior of the registry.\n */\n returnMap?: boolean;\n}\nconst DUMMY_HTTP_SERVICE = {\n async fetch() {\n throw new Error(\n \"Network requests are not implemented (override fetch via map test utils if your test requires network access).\"\n );\n }\n} satisfies Partial<HttpService> as HttpService;\nconst DUMMY_LAYER_FACTORY = createLayerFactory();\n\n/**\n * Waits until the OpenLayers map has been mounted in the parent with the given id.\n */\nexport async function waitForMapMount(parentTestId = \"base\") {\n return await waitFor(async () => {\n const domElement = await screen.findByTestId(parentTestId);\n const container = domElement.querySelector(\".ol-viewport\");\n if (!container) {\n throw new Error(\"map not mounted\");\n }\n return domElement;\n });\n}\n\n/**\n * Waits until the model has an initial extent.\n */\nexport async function waitForInitialExtent(model: MapModel) {\n if (model.initialExtent) {\n return;\n }\n\n await new Promise<void>((resolve, reject) => {\n const resource = watch(\n () => [model.initialExtent],\n ([extent]) => {\n resource.destroy();\n if (extent) {\n resolve();\n } else {\n reject(new Error(\"Expected a valid initial extent\"));\n }\n }\n );\n });\n}\n\nexport interface SetupMapResult {\n mapId: string;\n registry: MapRegistry;\n layerFactory: LayerFactory;\n}\n\n/**\n * Creates a simple map registry service with exactly one map configuration.\n *\n * The map is configured by using the `options` parameter.\n * If `options.returnMap` is `true` (the default), the map model is also returned.\n *\n * Returns the map registry and the id of the configured map.\n */\nexport async function setupMap(\n options?: SimpleMapOptions & { returnMap?: true }\n): Promise<SetupMapResult & { map: MapModel }>;\nexport async function setupMap(options?: SimpleMapOptions): Promise<SetupMapResult>;\nexport async function setupMap(\n options?: SimpleMapOptions\n): Promise<SetupMapResult & { map: MapModel | undefined }> {\n const mapId = options?.mapId ?? \"test\";\n const mapConfig: MapConfig = {\n initialView: options?.noInitialView ? undefined : getInitialView(options),\n projection: options?.noProjection ? undefined : (options?.projection ?? \"EPSG:3857\"),\n layers: options?.layers?.map(\n (config) =>\n \"map\" in config\n ? config\n : createTestLayer({ type: SimpleLayer, ...(config as SimpleLayerConfig) })\n // using map as discriminator (no prototype for Layer)\n ) ?? [createTestLayer()],\n advanced: options?.advanced\n };\n\n const httpService = {\n async fetch(resource, init) {\n if (options?.fetch) {\n const url = new URL(resource, \"http://localhost:1234\");\n return options.fetch(url, init);\n }\n throw new Error(\n \"Network requests are not implemented (override fetch via map test utils if your test requires network access).\"\n );\n }\n } satisfies Partial<HttpService> as HttpService;\n\n const layerFactory = await createService(LayerFactoryImpl, {\n references: {\n httpService\n }\n });\n\n const registry = await createService(MapRegistryImpl, {\n references: {\n providers: [],\n httpService,\n layerFactory\n }\n });\n\n let map: MapModel | undefined;\n const promise = registry.createMapModel(mapId, mapConfig);\n if (options?.returnMap !== false) {\n map = await promise;\n } else {\n // Ignore error on this promise (prevents unhandled error in tests)\n promise.catch(() => undefined);\n }\n return { mapId, registry, layerFactory, map };\n}\n\nfunction getInitialView(options: SimpleMapOptions | undefined): InitialViewConfig {\n if (options?.extent) {\n return {\n kind: \"extent\",\n extent: options.extent\n };\n }\n return {\n kind: \"position\",\n center: options?.center ?? { x: 847541, y: 6793584 },\n zoom: options?.zoom ?? 10\n };\n}\n\n/** Creates an new layer of the specified type for testing. */\nexport function createTestLayer<LayerType extends Layer, Config extends MapPackageLayerConfig>(\n config: LayerCreateOptions<LayerType, Config>,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): LayerType;\n\n/** Creates a new, basic SimpleLayer for testing. */\nexport function createTestLayer(\n config?: SimpleLayerConfig,\n mapOptions?: Pick<SimpleMapOptions, \"fetch\">\n): SimpleLayer;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTestLayer(config?: any, mapOptions?: Pick<SimpleMapOptions, \"fetch\">): Layer {\n // Basic case: If no config is given, use SimpleLayer\n if (!config) {\n config = {\n type: SimpleLayer,\n title: \"Test layer\",\n olLayer: new VectorLayer()\n } as LayerCreateOptions<SimpleLayer, SimpleLayerConfig>;\n } else if (!config.type) {\n config.type = SimpleLayer;\n }\n\n const factory = mapOptions?.fetch\n ? createLayerFactory({ fetch: mapOptions.fetch })\n : DUMMY_LAYER_FACTORY;\n return factory.create(config);\n}\n\n/**\n * Returns a simple, empty OpenLayers layer object.\n *\n * Use this if you need any kind of `olLayer` in your test.\n */\nexport function createTestOlLayer(): TileLayer {\n return new TileLayer();\n}\n\n/**\n * Creates (service name, service implementation)-pairs suitable for the `services`\n * option of the `PackageContextProvider`.\n *\n * This helper method can be used to avoid hard-coding service names used in the implementation.\n *\n * @deprecated This function is no longer needed, since most widgets no longer depend on the registry\n * and accept the `map` directly.\n */\nexport function createServiceOptions(services: { registry: MapRegistry }): Record<string, unknown> {\n return {\n \"map.MapRegistry\": services.registry\n };\n}\n\nfunction createLayerFactory(httpService?: HttpService): LayerFactory {\n return new LayerFactoryImpl({\n intl: {} satisfies Partial<PackageIntl> as PackageIntl,\n references: { httpService: httpService ?? DUMMY_HTTP_SERVICE },\n properties: {},\n referencesMeta: { httpService: { serviceId: \"http.HttpService\" } }\n });\n}\n\nfunction mockVectorLayer() {\n // Overwrite render so it doesn't actually do anything during tests.\n // Would otherwise error because <canvas /> is not fully implemented in happy dom.\n const div = document.createElement(\"div\");\n VectorLayer.prototype.render = () => {\n return div;\n };\n}\n\nmockVectorLayer();\n"],"names":["LayerFactoryImpl","MapRegistryImpl"],"mappings":";;;;;;;;AAo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O,IAAID,YAAA,CAAiB;AAAA,IACxB,MAAM,EAAC;AAAA,IACP,UAAA,EAAY,EAAE,WAAA,EAAa,WAAA,IAAe,kBAAA,EAAmB;AAAA,IAC7D,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAE,WAAA,EAAa,EAAE,SAAA,EAAW,oBAAmB;AAAE,GACpE,CAAA;AACL;AAEA,SAAS,eAAA,GAAkB;AAGvB,EAAA,MAAM,GAAA,GAAM,QAAA,CAAS,aAAA,CAAc,KAAK,CAAA;AACxC,EAAA,WAAA,CAAY,SAAA,CAAU,SAAS,MAAM;AACjC,IAAA,OAAO,GAAA;AAAA,EACX,CAAA;AACJ;AAEA,eAAA,EAAgB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-test-utils",
|
|
4
|
-
"version": "1.0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "This package is an internal support package for testing map-related UI components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"directory": "src/packages/map-test-utils"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@open-pioneer/test-utils": "4.2.0
|
|
17
|
+
"@open-pioneer/test-utils": "^4.2.0",
|
|
18
18
|
"@testing-library/react": "^16.3.0",
|
|
19
19
|
"ol": "^10.6.1",
|
|
20
20
|
"@conterra/reactivity-core": "^0.8.0",
|
|
21
|
-
"@open-pioneer/map": "1.0.0
|
|
21
|
+
"@open-pioneer/map": "^1.0.0"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
"./package.json": "./package.json",
|