@accelint/map-toolkit 0.1.0 → 0.2.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 +29 -0
- package/README.md +91 -18
- package/catalog-info.yaml +13 -10
- package/dist/deckgl/base-map/index.d.ts +91 -8
- package/dist/deckgl/base-map/index.js +26 -20
- package/dist/deckgl/base-map/index.js.map +1 -1
- package/dist/deckgl/base-map/provider.d.ts +133 -0
- package/dist/deckgl/base-map/provider.js +22 -0
- package/dist/deckgl/base-map/provider.js.map +1 -0
- package/dist/deckgl/base-map/types.d.ts +40 -0
- package/dist/deckgl/index.d.ts +3 -2
- package/dist/deckgl/index.js +1 -1
- package/dist/deckgl/text-layer/character-sets.d.ts +20 -0
- package/dist/deckgl/text-layer/character-sets.js +36 -0
- package/dist/deckgl/text-layer/character-sets.js.map +1 -0
- package/dist/deckgl/text-layer/default-settings.d.ts +5 -0
- package/dist/deckgl/text-layer/default-settings.js +23 -0
- package/dist/deckgl/text-layer/default-settings.js.map +1 -0
- package/dist/deckgl/text-layer/fiber.d.ts +31 -0
- package/dist/deckgl/text-layer/fiber.js +6 -0
- package/dist/deckgl/text-layer/fiber.js.map +1 -0
- package/dist/deckgl/text-layer/index.d.ts +43 -0
- package/dist/deckgl/text-layer/index.js +33 -0
- package/dist/deckgl/text-layer/index.js.map +1 -0
- package/dist/decorators/deckgl.js +3 -1
- package/dist/decorators/deckgl.js.map +1 -1
- package/dist/map-mode/events.d.ts +37 -0
- package/dist/map-mode/events.js +15 -0
- package/dist/map-mode/events.js.map +1 -0
- package/dist/map-mode/index.d.ts +6 -0
- package/dist/map-mode/index.js +5 -0
- package/dist/map-mode/index.js.map +1 -0
- package/dist/map-mode/store.d.ts +122 -0
- package/dist/map-mode/store.js +327 -0
- package/dist/map-mode/store.js.map +1 -0
- package/dist/map-mode/types.d.ts +83 -0
- package/dist/map-mode/types.js +3 -0
- package/dist/map-mode/types.js.map +1 -0
- package/dist/map-mode/use-map-mode.d.ts +54 -0
- package/dist/map-mode/use-map-mode.js +31 -0
- package/dist/map-mode/use-map-mode.js.map +1 -0
- package/dist/maplibre/hooks/use-maplibre.d.ts +34 -0
- package/dist/maplibre/hooks/use-maplibre.js +3 -2
- package/dist/maplibre/hooks/use-maplibre.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +43 -36
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.js +0 -11
- package/dist/test/setup.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @accelint/map-toolkit
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b4d1b9b: Add map mode system with authorization flow for managing interaction modes.
|
|
8
|
+
|
|
9
|
+
**New Features:**
|
|
10
|
+
- `MapProvider` component for managing map mode state with instance isolation
|
|
11
|
+
- `useMapMode()` hook for accessing and requesting mode changes
|
|
12
|
+
- Authorization flow for resolving ownership conflicts when switching modes
|
|
13
|
+
- Event bus integration for decoupled mode change communication
|
|
14
|
+
- Support for multiple independent map instances with isolated state
|
|
15
|
+
|
|
16
|
+
**API:**
|
|
17
|
+
- `MapProvider` component (internal to `BaseMap`)
|
|
18
|
+
- `useMapMode(id)` hook for UI components
|
|
19
|
+
- `BaseMap` now requires `id` prop for instance identification
|
|
20
|
+
- Observable store pattern using React's `useSyncExternalStore`
|
|
21
|
+
|
|
22
|
+
- 998dee6: add deckgl-layer-text for default text styling
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 303b61f: Pins the dependency version of Deck.gl to 9.1.14. We are not yet able to support 9.2.
|
|
27
|
+
- 0d697fa: Fixed definitions in package files for longhand repository definitions, while disabling the option in syncpack that changed it.
|
|
28
|
+
- a8b8de2: Update README content in map-toolkit
|
|
29
|
+
- f99f294: Updated syncpack and realigned all packages for dependency versions
|
|
30
|
+
- 935b8e5: Updated the package names in the Constellation configuration file.
|
|
31
|
+
|
|
3
32
|
## 0.1.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,35 +1,108 @@
|
|
|
1
1
|
# @accelint/map-toolkit
|
|
2
2
|
|
|
3
|
+
A collection of components and utilities to simplify visualizing and working with geospatial data. This toolkit provides ready-to-use map components and layers for deck.gl and MapLibre, making it easier to build interactive mapping applications.
|
|
4
|
+
|
|
5
|
+
## What is Map Toolkit?
|
|
6
|
+
|
|
7
|
+
Map Toolkit is a comprehensive library that provides:
|
|
8
|
+
|
|
9
|
+
- **Deck.gl Components**: Pre-configured layers and components for rendering geospatial data, including symbol layers for military symbology (MIL-STD-2525)
|
|
10
|
+
- **MapLibre Integration**: Components and utilities for working with MapLibre GL JS
|
|
11
|
+
- **React Support**: React-friendly components with hooks and utilities via `@deckgl-fiber-renderer`
|
|
12
|
+
- **Geospatial Utilities**: Helper functions and decorators for common mapping tasks
|
|
13
|
+
|
|
14
|
+
The package is organized by technology (e.g., `deckgl/`, `maplibre/`) with feature-specific exports, allowing you to import only what you need.
|
|
15
|
+
|
|
3
16
|
## Installation
|
|
4
17
|
|
|
5
18
|
```sh
|
|
6
19
|
npm install @accelint/map-toolkit
|
|
7
20
|
```
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
### Optional Dependencies
|
|
10
23
|
|
|
11
|
-
|
|
12
|
-
- src
|
|
13
|
-
- deckgl
|
|
14
|
-
- [feature folders]
|
|
15
|
-
- index.ts (generated by indexer)
|
|
24
|
+
To minimize bundle size, Map Toolkit uses optional dependencies. Install only the technologies you need:
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
```sh
|
|
27
|
+
# For deck.gl features
|
|
28
|
+
pnpm i --save-optional @deck.gl/core @deck.gl/layers @deck.gl/extensions
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
# For React/deck.gl features
|
|
31
|
+
pnpm i --save-optional react @deckgl-fiber-renderer/dom
|
|
20
32
|
|
|
21
|
-
|
|
33
|
+
# For MapLibre features
|
|
34
|
+
pnpm i --save-optional maplibre-gl
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
# For military symbology
|
|
37
|
+
pnpm i --save-optional milsymbol
|
|
38
|
+
```
|
|
25
39
|
|
|
26
|
-
|
|
40
|
+
## Usage
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
`pnpm i --save-optional deckgl@latest`
|
|
42
|
+
Import components from their technology-specific paths:
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
```ts
|
|
45
|
+
// Deck.gl components
|
|
46
|
+
import { SymbolLayer } from '@accelint/map-toolkit/deckgl';
|
|
47
|
+
|
|
48
|
+
// MapLibre components
|
|
49
|
+
import { /* components */ } from '@accelint/map-toolkit/maplibre';
|
|
50
|
+
|
|
51
|
+
// React/Fiber components
|
|
52
|
+
import { /* components */ } from '@accelint/map-toolkit/deckgl/fiber';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For detailed examples and interactive demos, see the [Storybook documentation](https://map-toolkit.accelint.io/?path=/docs/deckgl-symbol-layer--docs).
|
|
56
|
+
|
|
57
|
+
## Running Locally
|
|
58
|
+
|
|
59
|
+
To work on Map Toolkit locally:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Install dependencies
|
|
63
|
+
pnpm i
|
|
64
|
+
|
|
65
|
+
# Run Storybook development server
|
|
66
|
+
pnpm --filter=@accelint/map-toolkit preview
|
|
67
|
+
|
|
68
|
+
# Build the package
|
|
69
|
+
pnpm --filter=@accelint/map-toolkit build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
If you encounter errors, try running `pnpm build` after installing dependencies, then run the preview command again.
|
|
73
|
+
|
|
74
|
+
## Testing
|
|
75
|
+
|
|
76
|
+
Run the test suite:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Run tests once
|
|
80
|
+
pnpm --filter=@accelint/map-toolkit test
|
|
81
|
+
|
|
82
|
+
# Run tests in watch mode
|
|
83
|
+
pnpm --filter=@accelint/map-toolkit test:watch
|
|
84
|
+
|
|
85
|
+
# Run benchmarks
|
|
86
|
+
pnpm --filter=@accelint/map-toolkit bench
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
- **[Storybook](https://map-toolkit.accelint.io/?path=/docs/deckgl-symbol-layer--docs)** - Interactive component documentation and examples
|
|
92
|
+
- **[Changelog](./CHANGELOG.md)** - Release notes and version history
|
|
93
|
+
|
|
94
|
+
## Package Structure
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
packages/map-toolkit/
|
|
98
|
+
src/
|
|
99
|
+
deckgl/ # Deck.gl layers and components
|
|
100
|
+
maplibre/ # MapLibre utilities and components
|
|
101
|
+
decorators/ # Shared decorators and utilities
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Each technology folder exports its components via barrel files, and individual features are also exported via `package.json` for granular imports.
|
|
105
|
+
|
|
106
|
+
## License
|
|
33
107
|
|
|
34
|
-
|
|
35
|
-
- To run storybook, use the command `pnpm preview` to run locally.
|
|
108
|
+
Apache-2.0
|
package/catalog-info.yaml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
apiVersion: backstage.io/v1alpha1
|
|
3
3
|
kind: Component
|
|
4
4
|
metadata:
|
|
5
|
-
name:
|
|
5
|
+
name: accelint_map-toolkit
|
|
6
6
|
title: Accelint Map Toolkit
|
|
7
7
|
description: >-
|
|
8
8
|
A collection of components and utilities to simplify visualizing and working
|
|
@@ -11,13 +11,14 @@ metadata:
|
|
|
11
11
|
|
|
12
12
|
Dependencies:
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@
|
|
14
|
+
accelint_biome-config@1.0.2, accelint_bus@2.0.0,
|
|
15
|
+
accelint_constellation-tracker@1.0.1, accelint_core@0.5.0,
|
|
16
|
+
accelint_design-toolkit@7.0.0, accelint_typescript-config@0.1.4,
|
|
17
|
+
accelint_vitest-config@0.1.5
|
|
17
18
|
annotations:
|
|
18
19
|
backstage.io/edit-url: https://github.com/gohypergiant/standard-toolkit/blob/main/packages/map-toolkit/catalog-info.yaml
|
|
19
20
|
backstage.io/techdocs-ref: dir:.
|
|
20
|
-
package/version: 0.0
|
|
21
|
+
package/version: 0.2.0
|
|
21
22
|
github.com/project-slug: gohypergiant/standard-toolkit
|
|
22
23
|
links:
|
|
23
24
|
- url: https://github.com/gohypergiant/standard-toolkit/tree/main/packages/map-toolkit
|
|
@@ -34,8 +35,10 @@ spec:
|
|
|
34
35
|
lifecycle: production
|
|
35
36
|
owner: group:default/pathfinder
|
|
36
37
|
dependsOn:
|
|
37
|
-
- component
|
|
38
|
-
- component
|
|
39
|
-
- component
|
|
40
|
-
- component
|
|
41
|
-
- component
|
|
38
|
+
- component:accelint_biome-config
|
|
39
|
+
- component:accelint_bus
|
|
40
|
+
- component:accelint_constellation-tracker
|
|
41
|
+
- component:accelint_core
|
|
42
|
+
- component:accelint_design-toolkit
|
|
43
|
+
- component:accelint_typescript-config
|
|
44
|
+
- component:accelint_vitest-config
|
|
@@ -1,15 +1,98 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { UniqueId } from '@accelint/core';
|
|
3
3
|
import { DeckglProps } from '@deckgl-fiber-renderer/types';
|
|
4
|
-
import { MapEventType } from './types.js';
|
|
5
|
-
import '@deck.gl/core';
|
|
6
|
-
import 'mjolnir.js';
|
|
7
|
-
import './events.js';
|
|
8
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Props for the BaseMap component.
|
|
7
|
+
* Extends all Deck.gl props and adds additional map-specific properties.
|
|
8
|
+
*/
|
|
9
9
|
type BaseMapProps = DeckglProps & {
|
|
10
|
+
/** Optional CSS class name to apply to the map container element */
|
|
10
11
|
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Unique identifier for this map instance (required).
|
|
14
|
+
*
|
|
15
|
+
* Used to isolate map mode state between multiple map instances (e.g., main map vs minimap).
|
|
16
|
+
* This should be a UUID generated using `uuid()` from `@accelint/core`.
|
|
17
|
+
*
|
|
18
|
+
* The same id should be passed to `useMapMode()` when accessing map mode state
|
|
19
|
+
* from components rendered outside of the BaseMap's children (i.e., as siblings).
|
|
20
|
+
*/
|
|
21
|
+
id: UniqueId;
|
|
11
22
|
};
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A React component that provides a Deck.gl-powered base map with MapLibre GL integration.
|
|
25
|
+
*
|
|
26
|
+
* This component serves as the foundation for building interactive map applications with
|
|
27
|
+
* support for click and hover events through a centralized event bus. It integrates
|
|
28
|
+
* Deck.gl for 3D visualizations with MapLibre GL for the base map tiles.
|
|
29
|
+
*
|
|
30
|
+
* **Map Mode Integration**: BaseMap automatically creates a `MapProvider` internally,
|
|
31
|
+
* which sets up the map mode state management for this instance.
|
|
32
|
+
* - **Children**: Only Deck.gl layer components can be rendered as children. Custom Deck.gl
|
|
33
|
+
* layers can use `useMapMode()` without parameters to access context.
|
|
34
|
+
* - **Siblings**: UI components (buttons, toolbars, etc.) must be rendered as siblings
|
|
35
|
+
* and pass `id` to `useMapMode(id)`.
|
|
36
|
+
*
|
|
37
|
+
* **Event Bus**: Click and hover events are emitted through the event bus with the `id`
|
|
38
|
+
* included in the payload, allowing multiple map instances to coexist without interference.
|
|
39
|
+
*
|
|
40
|
+
* @param props - Component props including id (required), className, onClick, onHover, and all Deck.gl props
|
|
41
|
+
* @returns A map component with Deck.gl and MapLibre GL integration
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Basic usage with id (recommended: module-level constant):
|
|
45
|
+
* ```tsx
|
|
46
|
+
* import { BaseMap } from '@accelint/map-toolkit/deckgl';
|
|
47
|
+
* import { View } from '@deckgl-fiber-renderer/dom';
|
|
48
|
+
* import { uuid } from '@accelint/core';
|
|
49
|
+
*
|
|
50
|
+
* // Create id at module level for stability and easy sharing
|
|
51
|
+
* const MAIN_MAP_ID = uuid();
|
|
52
|
+
*
|
|
53
|
+
* export function MapView() {
|
|
54
|
+
* return (
|
|
55
|
+
* <BaseMap className="w-full h-full" id={MAIN_MAP_ID}>
|
|
56
|
+
* <View id="main" controller />
|
|
57
|
+
* </BaseMap>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* With map mode and event handlers (module-level constant for sharing):
|
|
64
|
+
* ```tsx
|
|
65
|
+
* import { BaseMap } from '@accelint/map-toolkit/deckgl';
|
|
66
|
+
* import { useMapMode } from '@accelint/map-toolkit/map-mode';
|
|
67
|
+
* import { uuid } from '@accelint/core';
|
|
68
|
+
* import type { PickingInfo } from '@deck.gl/core';
|
|
69
|
+
* import type { MjolnirGestureEvent } from 'mjolnir.js';
|
|
70
|
+
*
|
|
71
|
+
* // Module-level constant - stable and shareable across all components
|
|
72
|
+
* const MAIN_MAP_ID = uuid();
|
|
73
|
+
*
|
|
74
|
+
* function Toolbar() {
|
|
75
|
+
* // Access map mode using the shared id
|
|
76
|
+
* const { mode, requestModeChange } = useMapMode(MAIN_MAP_ID);
|
|
77
|
+
* return <div>Current mode: {mode}</div>;
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* export function InteractiveMap() {
|
|
81
|
+
* const handleClick = (info: PickingInfo, event: MjolnirGestureEvent) => {
|
|
82
|
+
* console.log('Clicked:', info.object);
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* return (
|
|
86
|
+
* <div className="relative w-full h-full">
|
|
87
|
+
* <BaseMap className="absolute inset-0" id={MAIN_MAP_ID} onClick={handleClick}>
|
|
88
|
+
* <View id="main" controller />
|
|
89
|
+
* </BaseMap>
|
|
90
|
+
* <Toolbar />
|
|
91
|
+
* </div>
|
|
92
|
+
* );
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
declare function BaseMap({ className, children, id, onClick, onHover, parameters, ...rest }: BaseMapProps): react_jsx_runtime.JSX.Element;
|
|
14
97
|
|
|
15
|
-
export { BaseMap,
|
|
98
|
+
export { BaseMap, type BaseMapProps };
|
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import 'client-only';
|
|
3
|
-
import { Broadcast } from '@accelint/bus';
|
|
4
3
|
import { useEmit } from '@accelint/bus/react';
|
|
5
4
|
import { useDeckgl, Deckgl } from '@deckgl-fiber-renderer/dom';
|
|
6
|
-
import { useId, useCallback } from 'react';
|
|
5
|
+
import { useId, useMemo, useCallback } from 'react';
|
|
7
6
|
import { INITIAL_VIEW_STATE } from '../../maplibre/constants.js';
|
|
8
7
|
import { useMapLibre } from '../../maplibre/hooks/use-maplibre.js';
|
|
9
8
|
import { BASE_MAP_STYLE, PARAMETERS } from './constants.js';
|
|
10
9
|
import { MapEvents } from './events.js';
|
|
10
|
+
import { MapProvider } from './provider.js';
|
|
11
11
|
|
|
12
|
-
const bus = Broadcast.getInstance();
|
|
13
12
|
function BaseMap({
|
|
13
|
+
className,
|
|
14
14
|
children,
|
|
15
|
+
id,
|
|
15
16
|
onClick,
|
|
16
17
|
onHover,
|
|
17
|
-
className,
|
|
18
18
|
parameters,
|
|
19
19
|
...rest
|
|
20
20
|
}) {
|
|
21
21
|
const deckglInstance = useDeckgl();
|
|
22
22
|
const container = useId();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
const mapOptions = useMemo(
|
|
24
|
+
() => ({
|
|
25
|
+
container,
|
|
26
|
+
center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],
|
|
27
|
+
zoom: INITIAL_VIEW_STATE.zoom,
|
|
28
|
+
doubleClickZoom: false,
|
|
29
|
+
dragRotate: false,
|
|
30
|
+
pitchWithRotate: false,
|
|
31
|
+
rollEnabled: false
|
|
32
|
+
}),
|
|
33
|
+
[container]
|
|
34
|
+
);
|
|
35
|
+
useMapLibre(deckglInstance, BASE_MAP_STYLE, mapOptions);
|
|
32
36
|
const emitClick = useEmit(MapEvents.click);
|
|
33
37
|
const emitHover = useEmit(MapEvents.hover);
|
|
34
38
|
const handleMapClick = useCallback(
|
|
@@ -48,10 +52,11 @@ function BaseMap({
|
|
|
48
52
|
} = event;
|
|
49
53
|
emitClick({
|
|
50
54
|
info: infoRest,
|
|
51
|
-
event: eventRest
|
|
55
|
+
event: eventRest,
|
|
56
|
+
id
|
|
52
57
|
});
|
|
53
58
|
},
|
|
54
|
-
[emitClick, onClick]
|
|
59
|
+
[emitClick, id, onClick]
|
|
55
60
|
);
|
|
56
61
|
const handleMapHover = useCallback(
|
|
57
62
|
(info, event) => {
|
|
@@ -68,12 +73,13 @@ function BaseMap({
|
|
|
68
73
|
} = event;
|
|
69
74
|
emitHover({
|
|
70
75
|
info: infoRest,
|
|
71
|
-
event: eventRest
|
|
76
|
+
event: eventRest,
|
|
77
|
+
id
|
|
72
78
|
});
|
|
73
79
|
},
|
|
74
|
-
[emitHover, onHover]
|
|
80
|
+
[emitHover, id, onHover]
|
|
75
81
|
);
|
|
76
|
-
return /* @__PURE__ */ jsx("div", { id: container, className, children: /* @__PURE__ */ jsx(
|
|
82
|
+
return /* @__PURE__ */ jsx("div", { id: container, className, children: /* @__PURE__ */ jsx(MapProvider, { id, children: /* @__PURE__ */ jsx(
|
|
77
83
|
Deckgl,
|
|
78
84
|
{
|
|
79
85
|
...rest,
|
|
@@ -85,9 +91,9 @@ function BaseMap({
|
|
|
85
91
|
parameters: { ...PARAMETERS, ...parameters },
|
|
86
92
|
children
|
|
87
93
|
}
|
|
88
|
-
) });
|
|
94
|
+
) }) });
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
export { BaseMap
|
|
97
|
+
export { BaseMap };
|
|
92
98
|
//# sourceMappingURL=index.js.map
|
|
93
99
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/deckgl/base-map/index.tsx"],"names":[],"mappings":";;;;;;;;;;;AA+BO,MAAM,GAAA,GAAM,UAAU,WAAA;AAEtB,SAAS,OAAA,CAAQ;AAAA,EACtB,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAiB;AACf,EAAA,MAAM,iBAAiB,SAAA,EAAU;AACjC,EAAA,MAAM,YAAY,KAAA,EAAM;AAGxB,EAAA,WAAA,CAAY,gBAA4B,cAAA,EAAgB;AAAA,IACtD,SAAA;AAAA,IACA,MAAA,EAAQ,CAAC,kBAAA,CAAmB,SAAA,EAAW,mBAAmB,QAAQ,CAAA;AAAA,IAClE,MAAM,kBAAA,CAAmB,IAAA;AAAA,IACzB,eAAA,EAAiB,KAAA;AAAA,IACjB,UAAA,EAAY,KAAA;AAAA,IACZ,eAAA,EAAiB,KAAA;AAAA,IACjB,WAAA,EAAa;AAAA,GACd,CAAA;AAED,EAAA,MAAM,SAAA,GAAY,OAAA,CAAuB,SAAA,CAAU,KAAK,CAAA;AACxD,EAAA,MAAM,SAAA,GAAY,OAAA,CAAuB,SAAA,CAAU,KAAK,CAAA;AAExD,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,MAAmB,KAAA,KAA+B;AAEjD,MAAA,OAAA,GAAU,MAAM,KAAK,CAAA;AAGrB,MAAA,MAAM,EAAE,QAAA,EAAU,GAAG,QAAA,EAAS,GAAI,IAAA;AAClC,MAAA,MAAM;AAAA,QACJ,wBAAA;AAAA,QACA,eAAA;AAAA,QACA,cAAA;AAAA,QACA,QAAA;AAAA,QACA,WAAA;AAAA,QACA,MAAA;AAAA,QACA,eAAA;AAAA,QACA,QAAA;AAAA,QACA,GAAG;AAAA,OACL,GAAI,KAAA;AAEJ,MAAA,SAAA,CAAU;AAAA,QACR,IAAA,EAAM,QAAA;AAAA,QACN,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,WAAW,OAAO;AAAA,GACrB;AAEA,EAAA,MAAM,cAAA,GAAiB,WAAA;AAAA,IACrB,CAAC,MAAmB,KAAA,KAA+B;AAEjD,MAAA,OAAA,GAAU,MAAM,KAAK,CAAA;AAGrB,MAAA,MAAM,EAAE,QAAA,EAAU,GAAG,QAAA,EAAS,GAAI,IAAA;AAClC,MAAA,MAAM;AAAA,QACJ,wBAAA;AAAA,QACA,eAAA;AAAA,QACA,cAAA;AAAA,QACA,QAAA;AAAA,QACA,WAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAG;AAAA,OACL,GAAI,KAAA;AAEJ,MAAA,SAAA,CAAU;AAAA,QACR,IAAA,EAAM,QAAA;AAAA,QACN,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,IACH,CAAA;AAAA,IACA,CAAC,WAAW,OAAO;AAAA,GACrB;AAEA,EAAA,uBACE,GAAA,CAAC,KAAA,EAAA,EAAI,EAAA,EAAI,SAAA,EAAW,SAAA,EAClB,QAAA,kBAAA,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACE,GAAG,IAAA;AAAA,MACJ,UAAA,EAAU,IAAA;AAAA,MACV,WAAA,EAAW,IAAA;AAAA,MACX,eAAA,EAAiB,KAAA;AAAA,MACjB,OAAA,EAAS,cAAA;AAAA,MACT,OAAA,EAAS,cAAA;AAAA,MAET,UAAA,EAAY,EAAE,GAAG,UAAA,EAAY,GAAG,UAAA,EAAW;AAAA,MAE1C;AAAA;AAAA,GACH,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport 'client-only';\nimport { Broadcast } from '@accelint/bus';\nimport { useEmit } from '@accelint/bus/react';\nimport { Deckgl, useDeckgl } from '@deckgl-fiber-renderer/dom';\nimport { useCallback, useId } from 'react';\nimport { INITIAL_VIEW_STATE } from '../../maplibre/constants';\nimport { useMapLibre } from '../../maplibre/hooks/use-maplibre';\nimport { BASE_MAP_STYLE, PARAMETERS } from './constants';\nimport { MapEvents } from './events';\nimport type { PickingInfo } from '@deck.gl/core';\nimport type { DeckglProps } from '@deckgl-fiber-renderer/types';\nimport type { IControl } from 'maplibre-gl';\nimport type { MjolnirGestureEvent, MjolnirPointerEvent } from 'mjolnir.js';\nimport type { MapClickEvent, MapEventType, MapHoverEvent } from './types';\n\ntype BaseMapProps = DeckglProps & { className?: string };\n\nexport const bus = Broadcast.getInstance<MapEventType>();\n\nexport function BaseMap({\n children,\n onClick,\n onHover,\n className,\n parameters,\n ...rest\n}: BaseMapProps) {\n const deckglInstance = useDeckgl();\n const container = useId();\n\n // Use the custom hook to handle MapLibre\n useMapLibre(deckglInstance as IControl, BASE_MAP_STYLE, {\n container,\n center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude],\n zoom: INITIAL_VIEW_STATE.zoom,\n doubleClickZoom: false,\n dragRotate: false,\n pitchWithRotate: false,\n rollEnabled: false,\n });\n\n const emitClick = useEmit<MapClickEvent>(MapEvents.click);\n const emitHover = useEmit<MapHoverEvent>(MapEvents.hover);\n\n const handleMapClick = useCallback(\n (info: PickingInfo, event: MjolnirGestureEvent) => {\n // send full pickingInfo and event to user-defined onClick\n onClick?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n changedPointers,\n pointers,\n ...eventRest\n } = event;\n\n emitClick({\n info: infoRest,\n event: eventRest,\n });\n },\n [emitClick, onClick],\n );\n\n const handleMapHover = useCallback(\n (info: PickingInfo, event: MjolnirPointerEvent) => {\n // send full pickingInfo and event to user-defined onHover\n onHover?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n ...eventRest\n } = event;\n\n emitHover({\n info: infoRest,\n event: eventRest,\n });\n },\n [emitHover, onHover],\n );\n\n return (\n <div id={container} className={className}>\n <Deckgl\n {...rest}\n controller\n interleaved\n useDevicePixels={false}\n onHover={handleMapHover}\n onClick={handleMapClick}\n // @ts-expect-error TODO: conflict with deckgl type\n parameters={{ ...PARAMETERS, ...parameters }}\n >\n {children}\n </Deckgl>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/deckgl/base-map/index.tsx"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport 'client-only';\nimport { useEmit } from '@accelint/bus/react';\nimport { Deckgl, useDeckgl } from '@deckgl-fiber-renderer/dom';\nimport { useCallback, useId, useMemo } from 'react';\nimport { INITIAL_VIEW_STATE } from '../../maplibre/constants';\nimport { useMapLibre } from '../../maplibre/hooks/use-maplibre';\nimport { BASE_MAP_STYLE, PARAMETERS } from './constants';\nimport { MapEvents } from './events';\nimport { MapProvider } from './provider';\nimport type { UniqueId } from '@accelint/core';\nimport type { PickingInfo } from '@deck.gl/core';\nimport type { DeckglProps } from '@deckgl-fiber-renderer/types';\nimport type { IControl } from 'maplibre-gl';\nimport type { MjolnirGestureEvent, MjolnirPointerEvent } from 'mjolnir.js';\nimport type { MapClickEvent, MapHoverEvent } from './types';\n\n/**\n * Props for the BaseMap component.\n * Extends all Deck.gl props and adds additional map-specific properties.\n */\nexport type BaseMapProps = DeckglProps & {\n /** Optional CSS class name to apply to the map container element */\n className?: string;\n /**\n * Unique identifier for this map instance (required).\n *\n * Used to isolate map mode state between multiple map instances (e.g., main map vs minimap).\n * This should be a UUID generated using `uuid()` from `@accelint/core`.\n *\n * The same id should be passed to `useMapMode()` when accessing map mode state\n * from components rendered outside of the BaseMap's children (i.e., as siblings).\n */\n id: UniqueId;\n};\n\n/**\n * A React component that provides a Deck.gl-powered base map with MapLibre GL integration.\n *\n * This component serves as the foundation for building interactive map applications with\n * support for click and hover events through a centralized event bus. It integrates\n * Deck.gl for 3D visualizations with MapLibre GL for the base map tiles.\n *\n * **Map Mode Integration**: BaseMap automatically creates a `MapProvider` internally,\n * which sets up the map mode state management for this instance.\n * - **Children**: Only Deck.gl layer components can be rendered as children. Custom Deck.gl\n * layers can use `useMapMode()` without parameters to access context.\n * - **Siblings**: UI components (buttons, toolbars, etc.) must be rendered as siblings\n * and pass `id` to `useMapMode(id)`.\n *\n * **Event Bus**: Click and hover events are emitted through the event bus with the `id`\n * included in the payload, allowing multiple map instances to coexist without interference.\n *\n * @param props - Component props including id (required), className, onClick, onHover, and all Deck.gl props\n * @returns A map component with Deck.gl and MapLibre GL integration\n *\n * @example\n * Basic usage with id (recommended: module-level constant):\n * ```tsx\n * import { BaseMap } from '@accelint/map-toolkit/deckgl';\n * import { View } from '@deckgl-fiber-renderer/dom';\n * import { uuid } from '@accelint/core';\n *\n * // Create id at module level for stability and easy sharing\n * const MAIN_MAP_ID = uuid();\n *\n * export function MapView() {\n * return (\n * <BaseMap className=\"w-full h-full\" id={MAIN_MAP_ID}>\n * <View id=\"main\" controller />\n * </BaseMap>\n * );\n * }\n * ```\n *\n * @example\n * With map mode and event handlers (module-level constant for sharing):\n * ```tsx\n * import { BaseMap } from '@accelint/map-toolkit/deckgl';\n * import { useMapMode } from '@accelint/map-toolkit/map-mode';\n * import { uuid } from '@accelint/core';\n * import type { PickingInfo } from '@deck.gl/core';\n * import type { MjolnirGestureEvent } from 'mjolnir.js';\n *\n * // Module-level constant - stable and shareable across all components\n * const MAIN_MAP_ID = uuid();\n *\n * function Toolbar() {\n * // Access map mode using the shared id\n * const { mode, requestModeChange } = useMapMode(MAIN_MAP_ID);\n * return <div>Current mode: {mode}</div>;\n * }\n *\n * export function InteractiveMap() {\n * const handleClick = (info: PickingInfo, event: MjolnirGestureEvent) => {\n * console.log('Clicked:', info.object);\n * };\n *\n * return (\n * <div className=\"relative w-full h-full\">\n * <BaseMap className=\"absolute inset-0\" id={MAIN_MAP_ID} onClick={handleClick}>\n * <View id=\"main\" controller />\n * </BaseMap>\n * <Toolbar />\n * </div>\n * );\n * }\n * ```\n */\nexport function BaseMap({\n className,\n children,\n id,\n onClick,\n onHover,\n parameters,\n ...rest\n}: BaseMapProps) {\n const deckglInstance = useDeckgl();\n const container = useId();\n\n // Memoize MapLibre options to avoid creating new object on every render\n const mapOptions = useMemo(\n () => ({\n container,\n center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude] as [\n number,\n number,\n ],\n zoom: INITIAL_VIEW_STATE.zoom,\n doubleClickZoom: false,\n dragRotate: false,\n pitchWithRotate: false,\n rollEnabled: false,\n }),\n [container],\n );\n\n // Use the custom hook to handle MapLibre\n useMapLibre(deckglInstance as IControl, BASE_MAP_STYLE, mapOptions);\n\n const emitClick = useEmit<MapClickEvent>(MapEvents.click);\n const emitHover = useEmit<MapHoverEvent>(MapEvents.hover);\n\n const handleMapClick = useCallback(\n (info: PickingInfo, event: MjolnirGestureEvent) => {\n // send full pickingInfo and event to user-defined onClick\n onClick?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n changedPointers,\n pointers,\n ...eventRest\n } = event;\n\n emitClick({\n info: infoRest,\n event: eventRest,\n id,\n });\n },\n [emitClick, id, onClick],\n );\n\n const handleMapHover = useCallback(\n (info: PickingInfo, event: MjolnirPointerEvent) => {\n // send full pickingInfo and event to user-defined onHover\n onHover?.(info, event);\n\n // the bus cannot serialize functions, so we omit them from the event payloads\n const { viewport, ...infoRest } = info;\n const {\n stopImmediatePropagation,\n stopPropagation,\n preventDefault,\n srcEvent,\n rootElement,\n target,\n ...eventRest\n } = event;\n\n emitHover({\n info: infoRest,\n event: eventRest,\n id,\n });\n },\n [emitHover, id, onHover],\n );\n\n return (\n <div id={container} className={className}>\n <MapProvider id={id}>\n <Deckgl\n {...rest}\n controller\n interleaved\n useDevicePixels={false}\n onHover={handleMapHover}\n onClick={handleMapClick}\n // @ts-expect-error - DeckglProps parameters type is overly strict for WebGL parameter spreading.\n // The merged object is valid at runtime but TypeScript cannot verify all possible parameter combinations.\n parameters={{ ...PARAMETERS, ...parameters }}\n >\n {children}\n </Deckgl>\n </MapProvider>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { UniqueId } from '@accelint/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React context for map ID.
|
|
7
|
+
* Use the `useMapMode` hook to access the map mode state.
|
|
8
|
+
*/
|
|
9
|
+
declare const MapContext: React.Context<UniqueId | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Props for the MapProvider component.
|
|
12
|
+
*/
|
|
13
|
+
type MapProviderProps = {
|
|
14
|
+
/** Child components that will have access to map mode context */
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Unique identifier for this map instance.
|
|
18
|
+
*
|
|
19
|
+
* Used to isolate mode changes between different map instances (e.g., main map vs minimap).
|
|
20
|
+
* This is required and should be provided by the parent component (typically BaseMap).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* // Multiple independent map instances
|
|
25
|
+
* const mainMapId = uuid();
|
|
26
|
+
* const minimapId = uuid();
|
|
27
|
+
*
|
|
28
|
+
* <MapProvider id={mainMapId}>
|
|
29
|
+
* // Map layers and components
|
|
30
|
+
* </MapProvider>
|
|
31
|
+
*
|
|
32
|
+
* <MapProvider id={minimapId}>
|
|
33
|
+
* // Minimap layers and components
|
|
34
|
+
* </MapProvider>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
id: UniqueId;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Provider component for managing map modes with ownership and authorization.
|
|
41
|
+
*
|
|
42
|
+
* **Note**: This provider is used internally by `BaseMap` and should not be used directly.
|
|
43
|
+
* Consumers should pass the `id` prop to `BaseMap`, which will create this provider automatically.
|
|
44
|
+
*
|
|
45
|
+
* This component uses a hybrid architecture combining React Context (for map instance identity)
|
|
46
|
+
* with an external observable store (for state management). The provider:
|
|
47
|
+
* - Provides a unique `id` via Context
|
|
48
|
+
* - Creates an isolated MapModeStore instance for this map
|
|
49
|
+
* - Allows components to subscribe to mode changes via `useMapMode` hook (which uses `useSyncExternalStore`)
|
|
50
|
+
*
|
|
51
|
+
* The external store manages a state machine for map modes where components can request
|
|
52
|
+
* mode changes with ownership. When a mode is owned by a component, other components
|
|
53
|
+
* must request authorization to change to a different mode. The store handles:
|
|
54
|
+
*
|
|
55
|
+
* - Automatic mode changes when no ownership conflicts exist
|
|
56
|
+
* - Authorization flow when switching between owned modes
|
|
57
|
+
* - Per-mode ownership tracking that persists throughout the session
|
|
58
|
+
* - Pending request management (one pending request per requester)
|
|
59
|
+
* - Auto-acceptance of first pending request when mode owner returns to default
|
|
60
|
+
* - Auto-rejection of other pending requests when one is approved
|
|
61
|
+
* - Event emission through a centralized event bus
|
|
62
|
+
* - Instance isolation for multiple map scenarios (main map + minimap)
|
|
63
|
+
* - Always initializes in 'default' mode
|
|
64
|
+
*
|
|
65
|
+
* ## Instance Isolation
|
|
66
|
+
*
|
|
67
|
+
* Each MapProvider instance operates independently. Mode changes in one instance
|
|
68
|
+
* do not affect other instances, even when multiple maps are rendered on the same page.
|
|
69
|
+
* This enables scenarios like:
|
|
70
|
+
* - Main map in "drawing" mode while minimap stays in "view" mode
|
|
71
|
+
* - Multiple independent map views with different interaction modes
|
|
72
|
+
*
|
|
73
|
+
* Events are scoped to specific instances using the `id` prop. The event bus
|
|
74
|
+
* filters events to ensure each provider only responds to events for its own instance.
|
|
75
|
+
*
|
|
76
|
+
* ## Pending Request Behavior
|
|
77
|
+
*
|
|
78
|
+
* - Pending requests are stored by requester ID (not mode owner)
|
|
79
|
+
* - Each requester can have only one pending request at a time
|
|
80
|
+
* - New requests from the same requester auto-replace previous requests
|
|
81
|
+
* - Pending requests persist when mode owner switches between their own modes
|
|
82
|
+
* - When any request is approved, all other pending requests are auto-rejected
|
|
83
|
+
* - When mode owner returns to default mode:
|
|
84
|
+
* - If first pending request is for default mode, all pending requests are rejected (already in requested mode)
|
|
85
|
+
* - If first pending request is for a different mode, that request is auto-approved and others are rejected
|
|
86
|
+
*
|
|
87
|
+
* ## Instance ID Stability and Lifecycle
|
|
88
|
+
*
|
|
89
|
+
* The provider uses React's `key` prop to force a complete remount when the `id` changes.
|
|
90
|
+
* This ensures:
|
|
91
|
+
* - Clean cleanup of the old store (no memory leaks)
|
|
92
|
+
* - Fresh initialization for the new ID
|
|
93
|
+
* - All child components remount with the new context
|
|
94
|
+
*
|
|
95
|
+
* While the `id` prop should typically remain stable (created as a module-level constant
|
|
96
|
+
* or with `useState`), changing it will work correctly due to the remount behavior.
|
|
97
|
+
*
|
|
98
|
+
* @param props - Provider props including children and required id
|
|
99
|
+
* @returns Provider component that wraps children with map instance identity context
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* Internal usage within BaseMap:
|
|
103
|
+
* ```tsx
|
|
104
|
+
* // BaseMap automatically creates the provider
|
|
105
|
+
* function BaseMap({ id, children, ...props }: BaseMapProps) {
|
|
106
|
+
* return (
|
|
107
|
+
* <div>
|
|
108
|
+
* <MapProvider id={id}>
|
|
109
|
+
* <Deckgl {...props}>
|
|
110
|
+
* {children}
|
|
111
|
+
* </Deckgl>
|
|
112
|
+
* </MapProvider>
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* With authorization handling - use id in event payloads:
|
|
120
|
+
* ```tsx
|
|
121
|
+
* useOn(MapModeEvents.changeAuthorization, (event) => {
|
|
122
|
+
* const { authId, id } = event.payload;
|
|
123
|
+
* emitDecision({ authId, approved: true, owner: 'tool', id });
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
* Public wrapper that forces remount when id changes.
|
|
129
|
+
* This ensures clean lifecycle management and prevents memory leaks.
|
|
130
|
+
*/
|
|
131
|
+
declare function MapProvider({ children, id }: MapProviderProps): react_jsx_runtime.JSX.Element;
|
|
132
|
+
|
|
133
|
+
export { MapContext, MapProvider, type MapProviderProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import 'client-only';
|
|
3
|
+
import { createContext, useEffect } from 'react';
|
|
4
|
+
import { getOrCreateStore, destroyStore } from '../../map-mode/store.js';
|
|
5
|
+
|
|
6
|
+
const MapContext = createContext(null);
|
|
7
|
+
function MapProvider({ children, id }) {
|
|
8
|
+
return /* @__PURE__ */ jsx(MapProviderInternal, { id, children }, id);
|
|
9
|
+
}
|
|
10
|
+
function MapProviderInternal({ children, id }) {
|
|
11
|
+
getOrCreateStore(id);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
return () => {
|
|
14
|
+
destroyStore(id);
|
|
15
|
+
};
|
|
16
|
+
}, [id]);
|
|
17
|
+
return /* @__PURE__ */ jsx(MapContext.Provider, { value: id, children });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { MapContext, MapProvider };
|
|
21
|
+
//# sourceMappingURL=provider.js.map
|
|
22
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/deckgl/base-map/provider.tsx"],"names":[],"mappings":";;;;;AAuBO,MAAM,UAAA,GAAa,cAA+B,IAAI;AA4HtD,SAAS,WAAA,CAAY,EAAE,QAAA,EAAU,EAAA,EAAG,EAAqB;AAE9D,EAAA,uBACE,GAAA,CAAC,mBAAA,EAAA,EAA6B,EAAA,EAC3B,QAAA,EAAA,EADuB,EAE1B,CAAA;AAEJ;AAMA,SAAS,mBAAA,CAAoB,EAAE,QAAA,EAAU,EAAA,EAAG,EAAqB;AAG/D,EAAA,gBAAA,CAAiB,EAAE,CAAA;AAGnB,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,MAAM;AACX,MAAA,YAAA,CAAa,EAAE,CAAA;AAAA,IACjB,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,EAAE,CAAC,CAAA;AAEP,EAAA,2BAAQ,UAAA,CAAW,QAAA,EAAX,EAAoB,KAAA,EAAO,IAAK,QAAA,EAAS,CAAA;AACnD","file":"provider.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n'use client';\n\nimport 'client-only';\nimport { createContext, type ReactNode, useEffect } from 'react';\nimport { destroyStore, getOrCreateStore } from '../../map-mode/store';\nimport type { UniqueId } from '@accelint/core';\n\n/**\n * React context for map ID.\n * Use the `useMapMode` hook to access the map mode state.\n */\nexport const MapContext = createContext<UniqueId | null>(null);\n\n/**\n * Props for the MapProvider component.\n */\nexport type MapProviderProps = {\n /** Child components that will have access to map mode context */\n children: ReactNode;\n /**\n * Unique identifier for this map instance.\n *\n * Used to isolate mode changes between different map instances (e.g., main map vs minimap).\n * This is required and should be provided by the parent component (typically BaseMap).\n *\n * @example\n * ```tsx\n * // Multiple independent map instances\n * const mainMapId = uuid();\n * const minimapId = uuid();\n *\n * <MapProvider id={mainMapId}>\n * // Map layers and components\n * </MapProvider>\n *\n * <MapProvider id={minimapId}>\n * // Minimap layers and components\n * </MapProvider>\n * ```\n */\n id: UniqueId;\n};\n\n/**\n * Provider component for managing map modes with ownership and authorization.\n *\n * **Note**: This provider is used internally by `BaseMap` and should not be used directly.\n * Consumers should pass the `id` prop to `BaseMap`, which will create this provider automatically.\n *\n * This component uses a hybrid architecture combining React Context (for map instance identity)\n * with an external observable store (for state management). The provider:\n * - Provides a unique `id` via Context\n * - Creates an isolated MapModeStore instance for this map\n * - Allows components to subscribe to mode changes via `useMapMode` hook (which uses `useSyncExternalStore`)\n *\n * The external store manages a state machine for map modes where components can request\n * mode changes with ownership. When a mode is owned by a component, other components\n * must request authorization to change to a different mode. The store handles:\n *\n * - Automatic mode changes when no ownership conflicts exist\n * - Authorization flow when switching between owned modes\n * - Per-mode ownership tracking that persists throughout the session\n * - Pending request management (one pending request per requester)\n * - Auto-acceptance of first pending request when mode owner returns to default\n * - Auto-rejection of other pending requests when one is approved\n * - Event emission through a centralized event bus\n * - Instance isolation for multiple map scenarios (main map + minimap)\n * - Always initializes in 'default' mode\n *\n * ## Instance Isolation\n *\n * Each MapProvider instance operates independently. Mode changes in one instance\n * do not affect other instances, even when multiple maps are rendered on the same page.\n * This enables scenarios like:\n * - Main map in \"drawing\" mode while minimap stays in \"view\" mode\n * - Multiple independent map views with different interaction modes\n *\n * Events are scoped to specific instances using the `id` prop. The event bus\n * filters events to ensure each provider only responds to events for its own instance.\n *\n * ## Pending Request Behavior\n *\n * - Pending requests are stored by requester ID (not mode owner)\n * - Each requester can have only one pending request at a time\n * - New requests from the same requester auto-replace previous requests\n * - Pending requests persist when mode owner switches between their own modes\n * - When any request is approved, all other pending requests are auto-rejected\n * - When mode owner returns to default mode:\n * - If first pending request is for default mode, all pending requests are rejected (already in requested mode)\n * - If first pending request is for a different mode, that request is auto-approved and others are rejected\n *\n * ## Instance ID Stability and Lifecycle\n *\n * The provider uses React's `key` prop to force a complete remount when the `id` changes.\n * This ensures:\n * - Clean cleanup of the old store (no memory leaks)\n * - Fresh initialization for the new ID\n * - All child components remount with the new context\n *\n * While the `id` prop should typically remain stable (created as a module-level constant\n * or with `useState`), changing it will work correctly due to the remount behavior.\n *\n * @param props - Provider props including children and required id\n * @returns Provider component that wraps children with map instance identity context\n *\n * @example\n * Internal usage within BaseMap:\n * ```tsx\n * // BaseMap automatically creates the provider\n * function BaseMap({ id, children, ...props }: BaseMapProps) {\n * return (\n * <div>\n * <MapProvider id={id}>\n * <Deckgl {...props}>\n * {children}\n * </Deckgl>\n * </MapProvider>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * With authorization handling - use id in event payloads:\n * ```tsx\n * useOn(MapModeEvents.changeAuthorization, (event) => {\n * const { authId, id } = event.payload;\n * emitDecision({ authId, approved: true, owner: 'tool', id });\n * });\n * ```\n */\n/**\n * Public wrapper that forces remount when id changes.\n * This ensures clean lifecycle management and prevents memory leaks.\n */\nexport function MapProvider({ children, id }: MapProviderProps) {\n // Force remount when id changes - each id gets a fresh component instance\n return (\n <MapProviderInternal key={id} id={id}>\n {children}\n </MapProviderInternal>\n );\n}\n\n/**\n * Internal implementation with guaranteed stable id.\n * The id cannot change without a remount due to the key prop above.\n */\nfunction MapProviderInternal({ children, id }: MapProviderProps) {\n // Create store synchronously before children render\n // This is required for useSyncExternalStore pattern\n getOrCreateStore(id);\n\n // Cleanup when component unmounts\n useEffect(() => {\n return () => {\n destroyStore(id);\n };\n }, [id]); // id is stable within this component's lifetime due to key prop\n\n return <MapContext.Provider value={id}>{children}</MapContext.Provider>;\n}\n"]}
|