@trackunit/react-map-adapter-shared 0.0.162 → 0.0.165

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/README.md CHANGED
@@ -24,6 +24,7 @@ Adapter libraries do not import `@trackunit/react-map`.
24
24
  ## What lives here
25
25
 
26
26
  - Core map types and interaction types (e.g. viewport, theme, GeoJSON-related types, layer port surface).
27
+ - The optional `DrawPort` capability contract (ADR 0030): a controlled mode/value input for polygon drawing, implemented once in `@trackunit/react-map-draw` and bridged by each adapter.
27
28
  - `defineAdapter`, `AdapterRendererProps`, and related adapter wiring types.
28
29
  - Shared constants (e.g. default center/zoom, map cursors), `restrictBounds` helpers, layer port utilities, antimeridian merge, map-specific viewport validation (`validateInitialViewport`), and other adapter-facing helpers.
29
30
  - Provider CSP directive factories. These framework-agnostic implementations are re-exported from their corresponding adapter packages; application code should import them from the provider adapter.
package/index.cjs.js CHANGED
@@ -867,6 +867,9 @@ const mercatorCenterFromBounds = (bounds) => {
867
867
  return [centerLon, centerLat];
868
868
  };
869
869
 
870
+ /** A `DrawValue` with no features. Stable reference, safe for snapshot comparisons. */
871
+ const EMPTY_DRAW_VALUE = { type: "FeatureCollection", features: [] };
872
+
870
873
  // ============================================================================
871
874
  // Constants
872
875
  // ============================================================================
@@ -1855,6 +1858,7 @@ const INITIAL_MAP_STATUS = {
1855
1858
  initializationFailed: false,
1856
1859
  appearance: DEFAULT_MAP_APPEARANCE,
1857
1860
  tileSize: 256,
1861
+ drawing: false,
1858
1862
  };
1859
1863
  /**
1860
1864
  * Initial map state - default values before map loads
@@ -2682,6 +2686,7 @@ exports.CIRCLE_SYMBOL_DEFAULT_OPACITY = CIRCLE_SYMBOL_DEFAULT_OPACITY;
2682
2686
  exports.DEFAULT_CENTER = DEFAULT_CENTER;
2683
2687
  exports.DEFAULT_MAP_APPEARANCE = DEFAULT_MAP_APPEARANCE;
2684
2688
  exports.DEFAULT_ZOOM = DEFAULT_ZOOM;
2689
+ exports.EMPTY_DRAW_VALUE = EMPTY_DRAW_VALUE;
2685
2690
  exports.GEODESIC_MAX_SEGMENT_KM = GEODESIC_MAX_SEGMENT_KM;
2686
2691
  exports.HIT_SURFACE_SELECTOR = HIT_SURFACE_SELECTOR;
2687
2692
  exports.INITIAL_CAMERA_STATE = INITIAL_CAMERA_STATE;
package/index.esm.js CHANGED
@@ -865,6 +865,9 @@ const mercatorCenterFromBounds = (bounds) => {
865
865
  return [centerLon, centerLat];
866
866
  };
867
867
 
868
+ /** A `DrawValue` with no features. Stable reference, safe for snapshot comparisons. */
869
+ const EMPTY_DRAW_VALUE = { type: "FeatureCollection", features: [] };
870
+
868
871
  // ============================================================================
869
872
  // Constants
870
873
  // ============================================================================
@@ -1853,6 +1856,7 @@ const INITIAL_MAP_STATUS = {
1853
1856
  initializationFailed: false,
1854
1857
  appearance: DEFAULT_MAP_APPEARANCE,
1855
1858
  tileSize: 256,
1859
+ drawing: false,
1856
1860
  };
1857
1861
  /**
1858
1862
  * Initial map state - default values before map loads
@@ -2674,4 +2678,4 @@ const resolveStrokeColors = (style, shapeType, theme) => {
2674
2678
  };
2675
2679
  };
2676
2680
 
2677
- export { ANCHOR_SELECTOR, CIRCLE_SYMBOL_DEFAULT_DIAMETER_PX, CIRCLE_SYMBOL_DEFAULT_OPACITY, DEFAULT_CENTER, DEFAULT_MAP_APPEARANCE, DEFAULT_ZOOM, GEODESIC_MAX_SEGMENT_KM, HIT_SURFACE_SELECTOR, INITIAL_CAMERA_STATE, INITIAL_INTERACTION_STATE, INITIAL_MAP_STATE, INITIAL_MAP_STATUS, KEYBOARD_PAN_AMOUNT, KEYBOARD_ZOOM_AMOUNT, LAYER_FADE_DURATION_MS, MAP_CURSORS, MAX_ZOOM, MIN_ZOOM, SAFE_AREA_DEFAULT_BUFFER_PX, TRAFFIC_MIN_ZOOM, WORLD_BBOX, allocSafeAreaDebugId, anchorFromBottomCenter, angularDistance, attachSafeAreaHoverListeners, bboxEquals, bufferRectCorners, buildAdaptiveDomEntries, buildAdaptiveDomRenderFn, buildAdaptiveSymbolStyleFn, cameraStateEquals, canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, clearSafeArea, collectFeatureIdSet, computeInitialState, computeMarkerDomPortalZIndex, convexHull, createClusterPinElement, createDefaultClusterElement, createSymbolDotElement, defineAdapter, densifyGeodesicFeatures, disableSafeAreaDebug, discriminateRenderResult, enableSafeAreaDebug, estimateZoomFromBounds, extractLineCoordinates, extractPointCoordinates, extractPolygonPaths, extractSourceData, fadeInElement, filterRectsByCursorDirection, geometryTypeToShapeType, getAdaptiveDomFeatureIds, getAnchorRect, getEffectiveRestrictBounds, getHitSurfaceRect, googleMapCspDirectives, hasSameFeatureIds, intermediatePoint, isCanvasMarkerMode, isEventOfType, isSafeAreaDebugEnabled, mapAppearanceSchema, mapStateEquals, mapThemeSchema, mapTypeSchema, mapboxMapCspDirectives, mercatorCenterFromBounds, mergeAntimeridianFeatures, patchPortalDescriptors, pointInPolygon, removeGoneIndexedMarkers, renderSafeArea, resolveCircleSymbolDefaults, resolveHoveredStyle, resolveSelectedStyle, resolveStrokeColors, resolveSymbolDescriptor, safePolygon, toDeg, toRad, unwrapLongitudeNear, validateInitialViewport, watchSafeAreaLeave };
2681
+ export { ANCHOR_SELECTOR, CIRCLE_SYMBOL_DEFAULT_DIAMETER_PX, CIRCLE_SYMBOL_DEFAULT_OPACITY, DEFAULT_CENTER, DEFAULT_MAP_APPEARANCE, DEFAULT_ZOOM, EMPTY_DRAW_VALUE, GEODESIC_MAX_SEGMENT_KM, HIT_SURFACE_SELECTOR, INITIAL_CAMERA_STATE, INITIAL_INTERACTION_STATE, INITIAL_MAP_STATE, INITIAL_MAP_STATUS, KEYBOARD_PAN_AMOUNT, KEYBOARD_ZOOM_AMOUNT, LAYER_FADE_DURATION_MS, MAP_CURSORS, MAX_ZOOM, MIN_ZOOM, SAFE_AREA_DEFAULT_BUFFER_PX, TRAFFIC_MIN_ZOOM, WORLD_BBOX, allocSafeAreaDebugId, anchorFromBottomCenter, angularDistance, attachSafeAreaHoverListeners, bboxEquals, bufferRectCorners, buildAdaptiveDomEntries, buildAdaptiveDomRenderFn, buildAdaptiveSymbolStyleFn, cameraStateEquals, canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, clearSafeArea, collectFeatureIdSet, computeInitialState, computeMarkerDomPortalZIndex, convexHull, createClusterPinElement, createDefaultClusterElement, createSymbolDotElement, defineAdapter, densifyGeodesicFeatures, disableSafeAreaDebug, discriminateRenderResult, enableSafeAreaDebug, estimateZoomFromBounds, extractLineCoordinates, extractPointCoordinates, extractPolygonPaths, extractSourceData, fadeInElement, filterRectsByCursorDirection, geometryTypeToShapeType, getAdaptiveDomFeatureIds, getAnchorRect, getEffectiveRestrictBounds, getHitSurfaceRect, googleMapCspDirectives, hasSameFeatureIds, intermediatePoint, isCanvasMarkerMode, isEventOfType, isSafeAreaDebugEnabled, mapAppearanceSchema, mapStateEquals, mapThemeSchema, mapTypeSchema, mapboxMapCspDirectives, mercatorCenterFromBounds, mergeAntimeridianFeatures, patchPortalDescriptors, pointInPolygon, removeGoneIndexedMarkers, renderSafeArea, resolveCircleSymbolDefaults, resolveHoveredStyle, resolveSelectedStyle, resolveStrokeColors, resolveSymbolDescriptor, safePolygon, toDeg, toRad, unwrapLongitudeNear, validateInitialViewport, watchSafeAreaLeave };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@trackunit/react-map-adapter-shared",
3
- "version": "0.0.162",
3
+ "version": "0.0.165",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
7
7
  "node": ">=24.x"
8
8
  },
9
9
  "dependencies": {
10
- "@trackunit/react-map-color-utils": "0.0.136",
11
- "@trackunit/geo-json-utils": "1.18.10",
12
- "@trackunit/ui-design-tokens": "1.18.9",
10
+ "@trackunit/react-map-color-utils": "0.0.139",
11
+ "@trackunit/geo-json-utils": "1.20.0",
12
+ "@trackunit/ui-design-tokens": "1.20.0",
13
13
  "es-toolkit": "^1.52.0",
14
14
  "zod": "^3.25.76"
15
15
  },
@@ -0,0 +1,54 @@
1
+ import type { GeoJsonFeatureCollection } from "@trackunit/geo-json-utils";
2
+ /**
3
+ * Interaction mode of the drawing capability (ADR 0030).
4
+ *
5
+ * - `"idle"` — nothing is being drawn; the map behaves as usual
6
+ * - `"polygon"` — clicks place vertices of a new polygon
7
+ * - `"select"` — existing polygons can be selected and their vertices moved or deleted
8
+ */
9
+ export type DrawMode = "idle" | "polygon" | "select";
10
+ /**
11
+ * The committed drawing: a standard GeoJSON FeatureCollection whose features are
12
+ * `Polygon` geometries with a single outer ring, lon/lat positions, closed.
13
+ * Adapters never expose in-progress geometry here — a polygon appears once the user
14
+ * has finished it.
15
+ */
16
+ export type DrawValue = GeoJsonFeatureCollection;
17
+ /** A `DrawValue` with no features. Stable reference, safe for snapshot comparisons. */
18
+ export declare const EMPTY_DRAW_VALUE: DrawValue;
19
+ /**
20
+ * Optional adapter capability for interactive polygon drawing (ADR 0030).
21
+ *
22
+ * Mirrors `LayerPort` as the adapter extension point, but drawing is a controlled
23
+ * input rather than a declarative snapshot: the consumer owns `mode` and `value`,
24
+ * and the adapter reports user edits back through `subscribe` + `getValue`.
25
+ *
26
+ * Adapters that cannot draw leave `AdapterInstance.draw` undefined or null. The
27
+ * built-in draw control hides itself when `api.actions.draw` is undefined, in the
28
+ * same way the traffic toggle hides when `setShowTraffic` is undefined (ADR 0028).
29
+ *
30
+ * The port must survive native map recreation (theme switch on Google Maps) and
31
+ * style reloads (Mapbox GL): after a reconnect, the adapter rebuilds the engine from
32
+ * the committed `getValue()` and the current `getMode()`.
33
+ */
34
+ export type DrawPort = Readonly<{
35
+ /**
36
+ * Enter a drawing mode. `"idle"` ends drawing; a completed polygon stays in the
37
+ * value, an in-progress one is discarded.
38
+ */
39
+ setMode: (mode: DrawMode) => void;
40
+ /**
41
+ * Replace the committed drawing. Features that are not single-ring polygons are
42
+ * dropped. Setting a value equal to the current one is a no-op (no notification).
43
+ */
44
+ setValue: (value: DrawValue) => void;
45
+ /** Current mode snapshot. Stable until `setMode` or the engine changes it. */
46
+ getMode: () => DrawMode;
47
+ /** Current committed drawing snapshot. Stable until it changes. */
48
+ getValue: () => DrawValue;
49
+ /**
50
+ * Subscribe to mode and value changes. Compatible with
51
+ * `useSyncExternalStore(subscribe, getValue)`.
52
+ */
53
+ subscribe: (listener: () => void) => () => void;
54
+ }>;
@@ -1,3 +1,4 @@
1
+ import type { DrawPort } from "./DrawPort";
1
2
  import type { LayerPort } from "./LayerPort";
2
3
  import type { CameraState, FitBoundsOptions, GeoJsonBbox, GeoJsonPosition, InitialViewport, MapComponentProps, MapEvent, MapEventHandler, MapStatus, MapTheme, MapType } from "./primitiveMapTypes";
3
4
  type ComponentType<TProps> = import("react").ComponentType<TProps>;
@@ -114,6 +115,13 @@ export type AdapterInstance<TConfig extends Record<string, unknown> = Record<str
114
115
  * Adapters can implement this incrementally.
115
116
  */
116
117
  layers: LayerPort | null;
118
+ /**
119
+ * Interactive drawing capability (ADR 0030).
120
+ *
121
+ * Optional: adapters that cannot draw leave it undefined or null, and
122
+ * `api.actions.draw` stays undefined so the built-in draw control hides itself.
123
+ */
124
+ draw?: DrawPort | null;
117
125
  }>;
118
126
  /**
119
127
  * Pixel insets representing areas reserved by the map provider's own UI
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./adapterContract";
2
2
  export * from "./antimeridianMerge";
3
3
  export * from "./constants";
4
+ export * from "./DrawPort";
4
5
  export * from "./geodesicDensify";
5
6
  export * from "./google-map-csp-directives";
6
7
  export * from "./initialViewportValidation";
@@ -74,6 +74,11 @@ export type MapStatus = Readonly<{
74
74
  appearance: MapAppearance;
75
75
  /** Base tile size in pixels used by the map provider (256 for Google Maps, 512 for Mapbox GL) */
76
76
  tileSize: number;
77
+ /**
78
+ * True while the drawing capability is in a non-idle mode (ADR 0030). Optional so
79
+ * adapters without `draw` keep compiling; read it as `status.drawing === true`.
80
+ */
81
+ drawing?: boolean;
77
82
  }>;
78
83
  /**
79
84
  * Full map state — union of CameraState and MapStatus.