@mapcairn/map 0.0.0-stage → 0.1.0-rc.1
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/LICENSE +661 -0
- package/README.md +167 -2
- package/dist/chrome/Attribution/Attribution.js +304 -0
- package/dist/chrome/Attribution/Attribution.js.map +1 -0
- package/dist/chrome/Attribution/Attribution.styles.js +10 -0
- package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.js +157 -0
- package/dist/chrome/EndStack/EndStack.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.styles.js +12 -0
- package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/endStackHeight.js +22 -0
- package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.js +488 -0
- package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
- package/dist/chrome/MapChrome/chromeSurface.js +18 -0
- package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
- package/dist/chrome/MapChrome/chromeVars.js +71 -0
- package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
- package/dist/chrome/MapChrome/sharesWidth.js +13 -0
- package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.js +199 -0
- package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.js +412 -0
- package/dist/chrome/Sheet/Sheet.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.styles.js +14 -0
- package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
- package/dist/chrome/focusRegistry.js +76 -0
- package/dist/chrome/focusRegistry.js.map +1 -0
- package/dist/chrome/layoutContext.js +30 -0
- package/dist/chrome/layoutContext.js.map +1 -0
- package/dist/chrome/useScrollEdges.js +53 -0
- package/dist/chrome/useScrollEdges.js.map +1 -0
- package/dist/host/MapContext.js +16 -0
- package/dist/host/MapContext.js.map +1 -0
- package/dist/host/MapView.js +189 -0
- package/dist/host/MapView.js.map +1 -0
- package/dist/host/MapView.styles.js +16 -0
- package/dist/host/MapView.styles.js.map +1 -0
- package/dist/host/overlays/AccuracyCircle.js +36 -0
- package/dist/host/overlays/AccuracyCircle.js.map +1 -0
- package/dist/host/overlays/CentreCrosshair.js +40 -0
- package/dist/host/overlays/CentreCrosshair.js.map +1 -0
- package/dist/host/overlays/DrawOverlay.js +221 -0
- package/dist/host/overlays/DrawOverlay.js.map +1 -0
- package/dist/host/overlays/MapOverlayLayer.js +27 -0
- package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
- package/dist/host/overlays/MeasureOverlay.js +87 -0
- package/dist/host/overlays/MeasureOverlay.js.map +1 -0
- package/dist/host/overlays/PinMarker.js +40 -0
- package/dist/host/overlays/PinMarker.js.map +1 -0
- package/dist/host/overlays/geometry.js +41 -0
- package/dist/host/overlays/geometry.js.map +1 -0
- package/dist/host/overlays/overlays.styles.js +27 -0
- package/dist/host/overlays/overlays.styles.js.map +1 -0
- package/dist/host/pointerTargets.js +22 -0
- package/dist/host/pointerTargets.js.map +1 -0
- package/dist/host/useLongPress.js +102 -0
- package/dist/host/useLongPress.js.map +1 -0
- package/dist/host/useMapEngine.js +352 -0
- package/dist/host/useMapEngine.js.map +1 -0
- package/dist/host/usePointerPosition.js +60 -0
- package/dist/host/usePointerPosition.js.map +1 -0
- package/dist/index.d.ts +3845 -0
- package/dist/index.js +89 -0
- package/dist/layers/CatalogueStatus.js +138 -0
- package/dist/layers/CatalogueStatus.js.map +1 -0
- package/dist/layers/DateTimeControl.js +101 -0
- package/dist/layers/DateTimeControl.js.map +1 -0
- package/dist/layers/FeatureCard.js +147 -0
- package/dist/layers/FeatureCard.js.map +1 -0
- package/dist/layers/FeatureChoices.js +101 -0
- package/dist/layers/FeatureChoices.js.map +1 -0
- package/dist/layers/FeatureGlyph.js +56 -0
- package/dist/layers/FeatureGlyph.js.map +1 -0
- package/dist/layers/IdentifyStatus.js +36 -0
- package/dist/layers/IdentifyStatus.js.map +1 -0
- package/dist/layers/LayerItem.js +321 -0
- package/dist/layers/LayerItem.js.map +1 -0
- package/dist/layers/LayerKey.js +36 -0
- package/dist/layers/LayerKey.js.map +1 -0
- package/dist/layers/Layers.styles.js +50 -0
- package/dist/layers/Layers.styles.js.map +1 -0
- package/dist/layers/LayersSection.js +267 -0
- package/dist/layers/LayersSection.js.map +1 -0
- package/dist/layers/MapDataLayers.js +261 -0
- package/dist/layers/MapDataLayers.js.map +1 -0
- package/dist/layers/MapKey.js +131 -0
- package/dist/layers/MapKey.js.map +1 -0
- package/dist/layers/MapKey.styles.js +16 -0
- package/dist/layers/MapKey.styles.js.map +1 -0
- package/dist/layers/MarkerGlyph.js +84 -0
- package/dist/layers/MarkerGlyph.js.map +1 -0
- package/dist/layers/SelectionProvider.js +27 -0
- package/dist/layers/SelectionProvider.js.map +1 -0
- package/dist/layers/ShapeGlyph.js +122 -0
- package/dist/layers/ShapeGlyph.js.map +1 -0
- package/dist/layers/TurnOffActions.js +147 -0
- package/dist/layers/TurnOffActions.js.map +1 -0
- package/dist/layers/answersTap.js +16 -0
- package/dist/layers/answersTap.js.map +1 -0
- package/dist/layers/catalogueNotice.js +65 -0
- package/dist/layers/catalogueNotice.js.map +1 -0
- package/dist/layers/catalogueReconcile.js +55 -0
- package/dist/layers/catalogueReconcile.js.map +1 -0
- package/dist/layers/catalogueView.js +32 -0
- package/dist/layers/catalogueView.js.map +1 -0
- package/dist/layers/featureTitle.js +14 -0
- package/dist/layers/featureTitle.js.map +1 -0
- package/dist/layers/identifyFeedback.js +30 -0
- package/dist/layers/identifyFeedback.js.map +1 -0
- package/dist/layers/identifyRun.js +148 -0
- package/dist/layers/identifyRun.js.map +1 -0
- package/dist/layers/layerStatus.js +13 -0
- package/dist/layers/layerStatus.js.map +1 -0
- package/dist/layers/loadOutcome.js +107 -0
- package/dist/layers/loadOutcome.js.map +1 -0
- package/dist/layers/loadReport.js +33 -0
- package/dist/layers/loadReport.js.map +1 -0
- package/dist/layers/loadRequests.js +73 -0
- package/dist/layers/loadRequests.js.map +1 -0
- package/dist/layers/mapFeatures.js +307 -0
- package/dist/layers/mapFeatures.js.map +1 -0
- package/dist/layers/mapKeyBlocks.js +24 -0
- package/dist/layers/mapKeyBlocks.js.map +1 -0
- package/dist/layers/reveal.js +119 -0
- package/dist/layers/reveal.js.map +1 -0
- package/dist/layers/selectionMessages.js +53 -0
- package/dist/layers/selectionMessages.js.map +1 -0
- package/dist/layers/selectionResolve.js +111 -0
- package/dist/layers/selectionResolve.js.map +1 -0
- package/dist/layers/useDataLayers.js +940 -0
- package/dist/layers/useDataLayers.js.map +1 -0
- package/dist/layers/useFeatureSelection.js +179 -0
- package/dist/layers/useFeatureSelection.js.map +1 -0
- package/dist/layers/useScrolls.js +37 -0
- package/dist/layers/useScrolls.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
- package/dist/panels/ExportSection/ExportSection.js +91 -0
- package/dist/panels/ExportSection/ExportSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.js +163 -0
- package/dist/panels/HelpSection/HelpSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
- package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
- package/dist/panels/PinSection/PinSection.js +39 -0
- package/dist/panels/PinSection/PinSection.js.map +1 -0
- package/dist/panels/Section/Section.js +43 -0
- package/dist/panels/Section/Section.js.map +1 -0
- package/dist/panels/Section/Section.styles.js +13 -0
- package/dist/panels/Section/Section.styles.js.map +1 -0
- package/dist/panels/SettingsSection/LanguageField.js +126 -0
- package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.js +175 -0
- package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.js +229 -0
- package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.js +92 -0
- package/dist/panels/SheetContent/SheetContent.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
- package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
- package/dist/services/ServicesProvider.js +42 -0
- package/dist/services/ServicesProvider.js.map +1 -0
- package/dist/services/activeMessages.js +140 -0
- package/dist/services/activeMessages.js.map +1 -0
- package/dist/services/basemapAvailability.js +78 -0
- package/dist/services/basemapAvailability.js.map +1 -0
- package/dist/services/englishMessages.js +10 -0
- package/dist/services/englishMessages.js.map +1 -0
- package/dist/services/hooks.js +214 -0
- package/dist/services/hooks.js.map +1 -0
- package/dist/styles.css +2866 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/tools/Directions/Directions.styles.js +25 -0
- package/dist/tools/Directions/Directions.styles.js.map +1 -0
- package/dist/tools/Directions/DirectionsOverlay.js +46 -0
- package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
- package/dist/tools/Directions/DirectionsPanel.js +428 -0
- package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
- package/dist/tools/Directions/MapDirections.js +84 -0
- package/dist/tools/Directions/MapDirections.js.map +1 -0
- package/dist/tools/Directions/useDirections.js +226 -0
- package/dist/tools/Directions/useDirections.js.map +1 -0
- package/dist/tools/Directions/useFreeCentre.js +30 -0
- package/dist/tools/Directions/useFreeCentre.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
- package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
- package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
- package/dist/tools/DrawToolbar/useDraw.js +543 -0
- package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
- package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
- package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
- package/dist/tools/PinCard/PinCard.js +174 -0
- package/dist/tools/PinCard/PinCard.js.map +1 -0
- package/dist/tools/PinCard/PinCard.styles.js +16 -0
- package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
- package/dist/tools/PinCard/useReverseAddress.js +77 -0
- package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.js +292 -0
- package/dist/tools/SearchPill/SearchPill.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
- package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
- package/dist/tools/SearchPill/useSearch.js +143 -0
- package/dist/tools/SearchPill/useSearch.js.map +1 -0
- package/dist/tools/SearchPill/useSuggestions.js +105 -0
- package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
- package/dist/tools/Tour/TourCard.js +156 -0
- package/dist/tools/Tour/TourCard.js.map +1 -0
- package/dist/tools/Tour/TourCard.styles.js +10 -0
- package/dist/tools/Tour/TourCard.styles.js.map +1 -0
- package/dist/tools/Tour/useTour.js +110 -0
- package/dist/tools/Tour/useTour.js.map +1 -0
- package/dist/tools/locate/useLocate.js +94 -0
- package/dist/tools/locate/useLocate.js.map +1 -0
- package/dist/ui/Button/Button.js +36 -0
- package/dist/ui/Button/Button.js.map +1 -0
- package/dist/ui/Button/Button.styles.js +17 -0
- package/dist/ui/Button/Button.styles.js.map +1 -0
- package/dist/ui/Chip/Chip.js +37 -0
- package/dist/ui/Chip/Chip.js.map +1 -0
- package/dist/ui/Chip/Chip.styles.js +29 -0
- package/dist/ui/Chip/Chip.styles.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.js +23 -0
- package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.js +37 -0
- package/dist/ui/EmptyState/EmptyState.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
- package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
- package/dist/ui/Icon/Icon.js +28 -0
- package/dist/ui/Icon/Icon.js.map +1 -0
- package/dist/ui/Icon/Icon.styles.js +8 -0
- package/dist/ui/Icon/Icon.styles.js.map +1 -0
- package/dist/ui/IconButton/IconButton.js +47 -0
- package/dist/ui/IconButton/IconButton.js.map +1 -0
- package/dist/ui/IconButton/IconButton.styles.js +27 -0
- package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
- package/dist/ui/Isolate/Isolate.js +26 -0
- package/dist/ui/Isolate/Isolate.js.map +1 -0
- package/dist/ui/Isolate/fillSlots.js +27 -0
- package/dist/ui/Isolate/fillSlots.js.map +1 -0
- package/dist/ui/ListRow/ListRow.js +59 -0
- package/dist/ui/ListRow/ListRow.js.map +1 -0
- package/dist/ui/ListRow/ListRow.styles.js +30 -0
- package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
- package/dist/ui/LiveRegion/LiveRegion.js +88 -0
- package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
- package/dist/ui/LiveRegion/announcer.js +114 -0
- package/dist/ui/LiveRegion/announcer.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.js +35 -0
- package/dist/ui/SkipLink/SkipLink.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
- package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
- package/dist/ui/Slider/Slider.js +68 -0
- package/dist/ui/Slider/Slider.js.map +1 -0
- package/dist/ui/Slider/Slider.styles.js +13 -0
- package/dist/ui/Slider/Slider.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.js +124 -0
- package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
- package/dist/ui/Surface/Surface.js +22 -0
- package/dist/ui/Surface/Surface.js.map +1 -0
- package/dist/ui/Surface/Surface.styles.js +27 -0
- package/dist/ui/Surface/Surface.styles.js.map +1 -0
- package/dist/ui/Switch/Switch.js +58 -0
- package/dist/ui/Switch/Switch.js.map +1 -0
- package/dist/ui/Switch/Switch.styles.js +13 -0
- package/dist/ui/Switch/Switch.styles.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.js +66 -0
- package/dist/ui/Tooltip/Tooltip.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
- package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
- package/dist/ui/Tooltip/inheritColours.js +27 -0
- package/dist/ui/Tooltip/inheritColours.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapDirections.js","names":[],"sources":["../../../src/tools/Directions/MapDirections.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { type LayerGeometry, routeBounds } from \"@mapcairn/core\";\nimport { useReadingDirection } from \"@mapcairn/react\";\nimport { tokenValues } from \"@mapcairn/theme\";\nimport { useEffect } from \"react\";\nimport { useChromeLayout } from \"../../chrome/layoutContext\";\nimport { useMap } from \"../../host\";\nimport { FIT_MAX_ZOOM, fitPadding } from \"../../layers/reveal\";\nimport type { DirectionsOutcome } from \"./useDirections\";\n\n/**\n * Map ids of what directions draws. Definition ids cannot contain a colon, so they never meet a layer's.\n *\n * @internal\n */\nexport const ROUTE_CASING_LAYER_ID = \":route-casing\";\n/**\n * Map id of the route line.\n *\n * @internal\n */\nexport const ROUTE_LAYER_ID = \":route\";\n/**\n * Map id of the travel-time area.\n *\n * @internal\n */\nexport const AREA_LAYER_ID = \":area\";\n\n/** Width of the route line, in pixels, and of the white casing under it. */\nconst ROUTE_WIDTH_PX = 5;\nconst ROUTE_CASING_WIDTH_PX = 9;\n\n/** Props for {@link MapDirections}. */\nexport interface MapDirectionsProps {\n /** The route or area to draw, or null for none. */\n readonly result: DirectionsOutcome | null;\n}\n\n/**\n * Draws a route as a line with a white casing, or a travel-time area as an\n * outlined, tinted shape, through the map adapter's shape layers, and fits the\n * map to it, clear of the sheet or side panel. Renders nothing; put it inside\n * `MapView`. The engine draws the shapes, so they stay sharp while the map\n * moves and come back after a basemap swap.\n */\nexport function MapDirections({ result }: MapDirectionsProps) {\n const { adapter } = useMap();\n const { layout, viewport, panelEdge } = useChromeLayout();\n const direction = useReadingDirection();\n\n useEffect(() => {\n if (!adapter || !result) {\n return;\n }\n const colour = tokenValues.dataPalette.blue;\n if (result.kind === \"route\") {\n // The port's positions are readonly pairs; the features hold plain arrays.\n const geometries = result.legs.map(\n (leg) => leg.geometry as unknown as LayerGeometry,\n );\n adapter.setShapeLayer(ROUTE_CASING_LAYER_ID, {\n geometries,\n colour: tokenValues.dataMarker.halo,\n lineWidth: ROUTE_CASING_WIDTH_PX,\n });\n adapter.setShapeLayer(ROUTE_LAYER_ID, {\n geometries,\n colour,\n lineWidth: ROUTE_WIDTH_PX,\n });\n } else {\n adapter.setShapeLayer(AREA_LAYER_ID, {\n geometries: result.features.map(\n (feature) => feature.geometry as unknown as LayerGeometry,\n ),\n colour,\n });\n }\n return () => {\n adapter.removeLayer(ROUTE_CASING_LAYER_ID);\n adapter.removeLayer(ROUTE_LAYER_ID);\n adapter.removeLayer(AREA_LAYER_ID);\n };\n }, [adapter, result]);\n\n // The fit runs once for each new result, not when the panel moves.\n // biome-ignore lint/correctness/useExhaustiveDependencies: the result is the trigger; the layout is read as it is then.\n useEffect(() => {\n if (!adapter || !result) {\n return;\n }\n const bounds = routeBounds(\n result.kind === \"route\" ? result.legs : result.features,\n );\n if (!bounds) {\n return;\n }\n adapter.fitBounds(bounds, {\n maxZoom: FIT_MAX_ZOOM,\n padding: fitPadding({ layout, viewport, panelEdge, direction }),\n });\n }, [adapter, result]);\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,IAAa,wBAAwB;;;;;;AAMrC,IAAa,iBAAiB;;;;;;AAM9B,IAAa,gBAAgB;;AAG7B,IAAM,iBAAiB;AACvB,IAAM,wBAAwB;;;;;;;;AAe9B,SAAgB,cAAc,EAAE,UAA8B;CAC5D,MAAM,EAAE,YAAY,OAAO;CAC3B,MAAM,EAAE,QAAQ,UAAU,cAAc,gBAAgB;CACxD,MAAM,YAAY,oBAAoB;CAEtC,gBAAgB;EACd,IAAI,CAAC,WAAW,CAAC,QACf;EAEF,MAAM,SAAS,YAAY,YAAY;EACvC,IAAI,OAAO,SAAS,SAAS;GAE3B,MAAM,aAAa,OAAO,KAAK,KAC5B,QAAQ,IAAI,QACf;GACA,QAAQ,cAAc,uBAAuB;IAC3C;IACA,QAAQ,YAAY,WAAW;IAC/B,WAAW;GACb,CAAC;GACD,QAAQ,cAAc,gBAAgB;IACpC;IACA;IACA,WAAW;GACb,CAAC;EACH,OACE,QAAQ,cAAc,eAAe;GACnC,YAAY,OAAO,SAAS,KACzB,YAAY,QAAQ,QACvB;GACA;EACF,CAAC;EAEH,aAAa;GACX,QAAQ,YAAY,qBAAqB;GACzC,QAAQ,YAAY,cAAc;GAClC,QAAQ,YAAY,aAAa;EACnC;CACF,GAAG,CAAC,SAAS,MAAM,CAAC;CAIpB,gBAAgB;EACd,IAAI,CAAC,WAAW,CAAC,QACf;EAEF,MAAM,SAAS,YACb,OAAO,SAAS,UAAU,OAAO,OAAO,OAAO,QACjD;EACA,IAAI,CAAC,QACH;EAEF,QAAQ,UAAU,QAAQ;GACxB,SAAA;GACA,SAAS,WAAW;IAAE;IAAQ;IAAU;IAAW;GAAU,CAAC;EAChE,CAAC;CACH,GAAG,CAAC,SAAS,MAAM,CAAC;CAEpB,OAAO;AACT"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { useRoutingProvider } from "../../services/hooks.js";
|
|
2
|
+
import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
|
|
3
|
+
import { MAX_DIRECTION_STOPS, RoutingError, addStop, announceAreaFound, announceDirectionsCleared, announceRouteFound, announceRoutingCancelled, announceRoutingError, announceStopAdded, announceStopLimit, announceStopMoved, announceStopRemoved, canAddStop, moveStop, reachableAreaSize, removeStop } from "@mapcairn/core";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
6
|
+
// src/tools/Directions/useDirections.ts
|
|
7
|
+
var IDLE = { status: "idle" };
|
|
8
|
+
/** Asks the service for what `request` describes, and shapes the answer as an outcome. */
|
|
9
|
+
async function find(service, request, places, mode, signal) {
|
|
10
|
+
if (request.kind === "route") {
|
|
11
|
+
const found = await service.route({
|
|
12
|
+
stops: places.map((stop) => stop.position),
|
|
13
|
+
mode,
|
|
14
|
+
signal
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
kind: "route",
|
|
18
|
+
mode,
|
|
19
|
+
stops: places,
|
|
20
|
+
legs: found.features,
|
|
21
|
+
distance: found.distance,
|
|
22
|
+
duration: found.duration
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const origin = places[0]?.position;
|
|
26
|
+
const found = await service.reachableArea({
|
|
27
|
+
origin,
|
|
28
|
+
minutes: request.minutes,
|
|
29
|
+
mode,
|
|
30
|
+
signal
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
kind: "area",
|
|
34
|
+
mode,
|
|
35
|
+
minutes: request.minutes,
|
|
36
|
+
origin,
|
|
37
|
+
features: found.features,
|
|
38
|
+
size: reachableAreaSize(found.features)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** The announcement for a route or area that has been found. */
|
|
42
|
+
function describeOutcome(outcome, units) {
|
|
43
|
+
return outcome.kind === "route" ? announceRouteFound(outcome.distance, outcome.duration, outcome.mode, units) : announceAreaFound(outcome.minutes, outcome.size, outcome.mode, units);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The state of one set of directions: the stops, the travel mode and the
|
|
47
|
+
* route or travel-time area the service found for them, with the requests
|
|
48
|
+
* cancellable and nothing stored. A request is sent only when the person asks
|
|
49
|
+
* (`requestRoute`, `requestArea`, `retry`), never as stops change.
|
|
50
|
+
*
|
|
51
|
+
* @remarks A result belongs to the stops and mode it was found for, so
|
|
52
|
+
* changing either goes back to idle: a line that no longer matches the
|
|
53
|
+
* stops is never left on the map. One request runs at a time; a newer one
|
|
54
|
+
* replaces it, and the answer to a replaced or cancelled request is ignored.
|
|
55
|
+
* Outcomes are announced through the app-wide announcer, errors assertively.
|
|
56
|
+
* Any failure the service does not describe is a `network` failure.
|
|
57
|
+
* @param units - The unit system for the announcements.
|
|
58
|
+
*/
|
|
59
|
+
function useDirections(units) {
|
|
60
|
+
const provider = useRoutingProvider();
|
|
61
|
+
const announce = useAnnounce();
|
|
62
|
+
const announceRef = useLatestRef(announce);
|
|
63
|
+
const providerRef = useLatestRef(provider);
|
|
64
|
+
const unitsRef = useLatestRef(units);
|
|
65
|
+
const [stops, setStopsState] = useState([]);
|
|
66
|
+
const [mode, setModeState] = useState("drive");
|
|
67
|
+
const [state, setState] = useState(IDLE);
|
|
68
|
+
const stateRef = useLatestRef(state);
|
|
69
|
+
const stopsRef = useRef([]);
|
|
70
|
+
const modeRef = useRef("drive");
|
|
71
|
+
const controller = useRef(null);
|
|
72
|
+
const lastRequest = useRef(null);
|
|
73
|
+
const nextId = useRef(0);
|
|
74
|
+
const abort = useCallback(() => {
|
|
75
|
+
controller.current?.abort();
|
|
76
|
+
controller.current = null;
|
|
77
|
+
}, []);
|
|
78
|
+
/** A result belongs to its stops and mode, so a change of either ends the request and the result. */
|
|
79
|
+
const invalidate = useCallback(() => {
|
|
80
|
+
abort();
|
|
81
|
+
setState((current) => current.status === "idle" ? current : IDLE);
|
|
82
|
+
}, [abort]);
|
|
83
|
+
const commitStops = useCallback((next) => {
|
|
84
|
+
stopsRef.current = next;
|
|
85
|
+
setStopsState(next);
|
|
86
|
+
invalidate();
|
|
87
|
+
}, [invalidate]);
|
|
88
|
+
const addStopAction = useCallback((position, label) => {
|
|
89
|
+
const current = stopsRef.current;
|
|
90
|
+
if (!canAddStop(current)) {
|
|
91
|
+
announceRef.current(announceStopLimit(MAX_DIRECTION_STOPS), { priority: "polite" });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
nextId.current += 1;
|
|
95
|
+
const stop = label === void 0 ? {
|
|
96
|
+
id: `stop-${nextId.current}`,
|
|
97
|
+
position
|
|
98
|
+
} : {
|
|
99
|
+
id: `stop-${nextId.current}`,
|
|
100
|
+
position,
|
|
101
|
+
label
|
|
102
|
+
};
|
|
103
|
+
const next = addStop(current, stop);
|
|
104
|
+
commitStops(next);
|
|
105
|
+
announceRef.current(announceStopAdded(next.length - 1, next.length), { priority: "polite" });
|
|
106
|
+
}, [announceRef, commitStops]);
|
|
107
|
+
const removeStopAction = useCallback((id) => {
|
|
108
|
+
const current = stopsRef.current;
|
|
109
|
+
const index = current.findIndex((stop) => stop.id === id);
|
|
110
|
+
const next = removeStop(current, id);
|
|
111
|
+
if (next === current) return;
|
|
112
|
+
commitStops(next);
|
|
113
|
+
announceRef.current(announceStopRemoved(index), { priority: "polite" });
|
|
114
|
+
}, [announceRef, commitStops]);
|
|
115
|
+
const moveStopAction = useCallback((id, direction) => {
|
|
116
|
+
const current = stopsRef.current;
|
|
117
|
+
const next = moveStop(current, id, direction);
|
|
118
|
+
if (next === current) return;
|
|
119
|
+
commitStops(next);
|
|
120
|
+
const index = next.findIndex((stop) => stop.id === id);
|
|
121
|
+
announceRef.current(announceStopMoved(index, next.length), { priority: "polite" });
|
|
122
|
+
}, [announceRef, commitStops]);
|
|
123
|
+
const setMode = useCallback((next) => {
|
|
124
|
+
if (modeRef.current === next) return;
|
|
125
|
+
modeRef.current = next;
|
|
126
|
+
setModeState(next);
|
|
127
|
+
invalidate();
|
|
128
|
+
}, [invalidate]);
|
|
129
|
+
const run = useCallback(async (request) => {
|
|
130
|
+
const service = providerRef.current;
|
|
131
|
+
const route = request.kind === "route";
|
|
132
|
+
const places = stopsRef.current;
|
|
133
|
+
const travelMode = modeRef.current;
|
|
134
|
+
const origin = places[0]?.position;
|
|
135
|
+
if (!service || (route ? places.length < 2 : origin === void 0)) return;
|
|
136
|
+
abort();
|
|
137
|
+
const own = new AbortController();
|
|
138
|
+
controller.current = own;
|
|
139
|
+
lastRequest.current = request;
|
|
140
|
+
setState(request.kind === "area" ? {
|
|
141
|
+
status: "loading",
|
|
142
|
+
request: "area",
|
|
143
|
+
minutes: request.minutes
|
|
144
|
+
} : {
|
|
145
|
+
status: "loading",
|
|
146
|
+
request: "route"
|
|
147
|
+
});
|
|
148
|
+
try {
|
|
149
|
+
const outcome = await find(service, request, places, travelMode, own.signal);
|
|
150
|
+
if (own.signal.aborted) return;
|
|
151
|
+
setState({
|
|
152
|
+
status: "done",
|
|
153
|
+
result: outcome
|
|
154
|
+
});
|
|
155
|
+
announceRef.current(describeOutcome(outcome, unitsRef.current), { priority: "polite" });
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (own.signal.aborted) return;
|
|
158
|
+
const kind = error instanceof RoutingError ? error.kind : "network";
|
|
159
|
+
if (kind === "aborted") {
|
|
160
|
+
setState(IDLE);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
setState({
|
|
164
|
+
status: "error",
|
|
165
|
+
request: request.kind,
|
|
166
|
+
kind
|
|
167
|
+
});
|
|
168
|
+
announceRef.current(announceRoutingError(kind, request.kind), { priority: "assertive" });
|
|
169
|
+
}
|
|
170
|
+
}, [
|
|
171
|
+
abort,
|
|
172
|
+
announceRef,
|
|
173
|
+
providerRef,
|
|
174
|
+
unitsRef
|
|
175
|
+
]);
|
|
176
|
+
const requestRoute = useCallback(() => {
|
|
177
|
+
run({ kind: "route" });
|
|
178
|
+
}, [run]);
|
|
179
|
+
const requestArea = useCallback((minutes) => {
|
|
180
|
+
run({
|
|
181
|
+
kind: "area",
|
|
182
|
+
minutes
|
|
183
|
+
});
|
|
184
|
+
}, [run]);
|
|
185
|
+
const retry = useCallback(() => {
|
|
186
|
+
if (lastRequest.current) run(lastRequest.current);
|
|
187
|
+
}, [run]);
|
|
188
|
+
const cancel = useCallback(() => {
|
|
189
|
+
if (stateRef.current.status !== "loading") return;
|
|
190
|
+
abort();
|
|
191
|
+
setState(IDLE);
|
|
192
|
+
announceRef.current(announceRoutingCancelled(), { priority: "polite" });
|
|
193
|
+
}, [
|
|
194
|
+
abort,
|
|
195
|
+
announceRef,
|
|
196
|
+
stateRef
|
|
197
|
+
]);
|
|
198
|
+
const clear = useCallback(() => {
|
|
199
|
+
stopsRef.current = [];
|
|
200
|
+
setStopsState([]);
|
|
201
|
+
invalidate();
|
|
202
|
+
lastRequest.current = null;
|
|
203
|
+
announceRef.current(announceDirectionsCleared(), { priority: "polite" });
|
|
204
|
+
}, [announceRef, invalidate]);
|
|
205
|
+
useEffect(() => abort, [abort]);
|
|
206
|
+
return {
|
|
207
|
+
available: provider !== void 0,
|
|
208
|
+
stops,
|
|
209
|
+
mode,
|
|
210
|
+
state,
|
|
211
|
+
result: state.status === "done" ? state.result : null,
|
|
212
|
+
canAddStop: canAddStop(stops),
|
|
213
|
+
addStop: addStopAction,
|
|
214
|
+
removeStop: removeStopAction,
|
|
215
|
+
moveStop: moveStopAction,
|
|
216
|
+
setMode,
|
|
217
|
+
requestRoute,
|
|
218
|
+
requestArea,
|
|
219
|
+
retry,
|
|
220
|
+
cancel,
|
|
221
|
+
clear
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export { useDirections };
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=useDirections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDirections.js","names":["stopsHaveRoom"],"sources":["../../../src/tools/Directions/useDirections.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n addStop,\n announceAreaFound,\n announceDirectionsCleared,\n announceRouteFound,\n announceRoutingCancelled,\n announceRoutingError,\n announceStopAdded,\n announceStopLimit,\n announceStopMoved,\n announceStopRemoved,\n type DirectionStop,\n type LatLng,\n MAX_DIRECTION_STOPS,\n type Message,\n moveStop,\n type ReachableAreaFeature,\n type RouteLeg,\n RoutingError,\n type RoutingErrorKind,\n type RoutingProvider,\n type RoutingRequestKind,\n reachableAreaSize,\n removeStop,\n canAddStop as stopsHaveRoom,\n type TravelMode,\n type UnitSystem,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useRoutingProvider } from \"../../services/hooks\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\n\n/** The failures a person is told about. A cancelled request is never one of them. */\nexport type DirectionsFailure = Exclude<RoutingErrorKind, \"aborted\">;\n\n/** A route that is on the map. */\nexport interface RouteOutcome {\n readonly kind: \"route\";\n readonly mode: TravelMode;\n /** The stops it was found for, in order. */\n readonly stops: readonly DirectionStop[];\n /** One line for each pair of consecutive stops. */\n readonly legs: readonly RouteLeg[];\n /** The whole route's length, in metres. */\n readonly distance: number;\n /** The whole route's travel time, in seconds. */\n readonly duration: number;\n}\n\n/** A travel-time area that is on the map. */\nexport interface AreaOutcome {\n readonly kind: \"area\";\n readonly mode: TravelMode;\n readonly minutes: number;\n /** Where the area is reachable from: the first stop. */\n readonly origin: LatLng;\n readonly features: readonly ReachableAreaFeature[];\n /** The ground area, in square metres. */\n readonly size: number;\n}\n\n/** What the directions tool has put on the map. */\nexport type DirectionsOutcome = RouteOutcome | AreaOutcome;\n\n/** Where the directions tool stands. Exactly one of these is true at a time. */\nexport type DirectionsState =\n | { readonly status: \"idle\" }\n | {\n readonly status: \"loading\";\n readonly request: RoutingRequestKind;\n /** The travel time of an area request, so its button can show it is working. */\n readonly minutes?: number;\n }\n | { readonly status: \"done\"; readonly result: DirectionsOutcome }\n | {\n readonly status: \"error\";\n readonly request: RoutingRequestKind;\n readonly kind: DirectionsFailure;\n };\n\n/** What {@link useDirections} returns. */\nexport interface UseDirections {\n /** Whether the host provides a routing service. Without one the tool is not offered. */\n readonly available: boolean;\n /** The stops, in order. */\n readonly stops: readonly DirectionStop[];\n readonly mode: TravelMode;\n readonly state: DirectionsState;\n /** The route or area on the map, or null. */\n readonly result: DirectionsOutcome | null;\n /** Whether another stop fits. */\n readonly canAddStop: boolean;\n /** Adds a stop at the end, naming it when `label` is given. Says so when the list is full. */\n readonly addStop: (position: LatLng, label?: string) => void;\n readonly removeStop: (id: string) => void;\n /** Moves a stop one place earlier (`-1`) or later (`1`). */\n readonly moveStop: (id: string, direction: -1 | 1) => void;\n /** Chooses how to travel. A different mode clears the result, which was for the old one. */\n readonly setMode: (mode: TravelMode) => void;\n /** Asks the service for a route through the stops. Needs at least two. */\n readonly requestRoute: () => void;\n /** Asks the service for the area reachable from the first stop within `minutes`. */\n readonly requestArea: (minutes: number) => void;\n /** Asks again for the request that failed. */\n readonly retry: () => void;\n /** Stops a request that is running. */\n readonly cancel: () => void;\n /** Removes every stop and the result, and stops a request that is running. */\n readonly clear: () => void;\n}\n\ntype Request =\n | { readonly kind: \"route\" }\n | { readonly kind: \"area\"; readonly minutes: number };\n\nconst IDLE: DirectionsState = { status: \"idle\" };\n\n/** Asks the service for what `request` describes, and shapes the answer as an outcome. */\nasync function find(\n service: RoutingProvider,\n request: Request,\n places: readonly DirectionStop[],\n mode: TravelMode,\n signal: AbortSignal,\n): Promise<DirectionsOutcome> {\n if (request.kind === \"route\") {\n const found = await service.route({\n stops: places.map((stop) => stop.position),\n mode,\n signal,\n });\n return {\n kind: \"route\",\n mode,\n stops: places,\n legs: found.features,\n distance: found.distance,\n duration: found.duration,\n };\n }\n const origin = places[0]?.position as LatLng;\n const found = await service.reachableArea({\n origin,\n minutes: request.minutes,\n mode,\n signal,\n });\n return {\n kind: \"area\",\n mode,\n minutes: request.minutes,\n origin,\n features: found.features,\n size: reachableAreaSize(found.features),\n };\n}\n\n/** The announcement for a route or area that has been found. */\nfunction describeOutcome(\n outcome: DirectionsOutcome,\n units: UnitSystem,\n): Message {\n return outcome.kind === \"route\"\n ? announceRouteFound(\n outcome.distance,\n outcome.duration,\n outcome.mode,\n units,\n )\n : announceAreaFound(outcome.minutes, outcome.size, outcome.mode, units);\n}\n\n/**\n * The state of one set of directions: the stops, the travel mode and the\n * route or travel-time area the service found for them, with the requests\n * cancellable and nothing stored. A request is sent only when the person asks\n * (`requestRoute`, `requestArea`, `retry`), never as stops change.\n *\n * @remarks A result belongs to the stops and mode it was found for, so\n * changing either goes back to idle: a line that no longer matches the\n * stops is never left on the map. One request runs at a time; a newer one\n * replaces it, and the answer to a replaced or cancelled request is ignored.\n * Outcomes are announced through the app-wide announcer, errors assertively.\n * Any failure the service does not describe is a `network` failure.\n * @param units - The unit system for the announcements.\n */\nexport function useDirections(units: UnitSystem): UseDirections {\n const provider = useRoutingProvider();\n const announce = useAnnounce();\n const announceRef = useLatestRef(announce);\n const providerRef = useLatestRef(provider);\n const unitsRef = useLatestRef(units);\n\n const [stops, setStopsState] = useState<readonly DirectionStop[]>([]);\n const [mode, setModeState] = useState<TravelMode>(\"drive\");\n const [state, setState] = useState<DirectionsState>(IDLE);\n const stateRef = useLatestRef(state);\n // Current values for callbacks that run before the next render.\n const stopsRef = useRef<readonly DirectionStop[]>([]);\n const modeRef = useRef<TravelMode>(\"drive\");\n const controller = useRef<AbortController | null>(null);\n const lastRequest = useRef<Request | null>(null);\n const nextId = useRef(0);\n\n const abort = useCallback(() => {\n controller.current?.abort();\n controller.current = null;\n }, []);\n\n /** A result belongs to its stops and mode, so a change of either ends the request and the result. */\n const invalidate = useCallback(() => {\n abort();\n setState((current) => (current.status === \"idle\" ? current : IDLE));\n }, [abort]);\n\n const commitStops = useCallback(\n (next: readonly DirectionStop[]) => {\n stopsRef.current = next;\n setStopsState(next);\n invalidate();\n },\n [invalidate],\n );\n\n const addStopAction = useCallback(\n (position: LatLng, label?: string) => {\n const current = stopsRef.current;\n if (!stopsHaveRoom(current)) {\n announceRef.current(announceStopLimit(MAX_DIRECTION_STOPS), {\n priority: \"polite\",\n });\n return;\n }\n nextId.current += 1;\n const stop: DirectionStop =\n label === undefined\n ? { id: `stop-${nextId.current}`, position }\n : { id: `stop-${nextId.current}`, position, label };\n const next = addStop(current, stop);\n commitStops(next);\n announceRef.current(announceStopAdded(next.length - 1, next.length), {\n priority: \"polite\",\n });\n },\n [announceRef, commitStops],\n );\n\n const removeStopAction = useCallback(\n (id: string) => {\n const current = stopsRef.current;\n const index = current.findIndex((stop) => stop.id === id);\n const next = removeStop(current, id);\n if (next === current) {\n return;\n }\n commitStops(next);\n announceRef.current(announceStopRemoved(index), { priority: \"polite\" });\n },\n [announceRef, commitStops],\n );\n\n const moveStopAction = useCallback(\n (id: string, direction: -1 | 1) => {\n const current = stopsRef.current;\n const next = moveStop(current, id, direction);\n if (next === current) {\n return;\n }\n commitStops(next);\n const index = next.findIndex((stop) => stop.id === id);\n announceRef.current(announceStopMoved(index, next.length), {\n priority: \"polite\",\n });\n },\n [announceRef, commitStops],\n );\n\n const setMode = useCallback(\n (next: TravelMode) => {\n if (modeRef.current === next) {\n return;\n }\n modeRef.current = next;\n setModeState(next);\n invalidate();\n },\n [invalidate],\n );\n\n const run = useCallback(\n async (request: Request) => {\n const service = providerRef.current;\n const route = request.kind === \"route\";\n const places = stopsRef.current;\n const travelMode = modeRef.current;\n const origin = places[0]?.position;\n if (!service || (route ? places.length < 2 : origin === undefined)) {\n return;\n }\n abort();\n const own = new AbortController();\n controller.current = own;\n lastRequest.current = request;\n setState(\n request.kind === \"area\"\n ? { status: \"loading\", request: \"area\", minutes: request.minutes }\n : { status: \"loading\", request: \"route\" },\n );\n try {\n const outcome = await find(\n service,\n request,\n places,\n travelMode,\n own.signal,\n );\n if (own.signal.aborted) {\n return;\n }\n setState({ status: \"done\", result: outcome });\n announceRef.current(describeOutcome(outcome, unitsRef.current), {\n priority: \"polite\",\n });\n } catch (error) {\n if (own.signal.aborted) {\n return;\n }\n const kind: RoutingErrorKind =\n error instanceof RoutingError ? error.kind : \"network\";\n if (kind === \"aborted\") {\n setState(IDLE);\n return;\n }\n setState({ status: \"error\", request: request.kind, kind });\n announceRef.current(announceRoutingError(kind, request.kind), {\n priority: \"assertive\",\n });\n }\n },\n [abort, announceRef, providerRef, unitsRef],\n );\n\n const requestRoute = useCallback(() => {\n void run({ kind: \"route\" });\n }, [run]);\n\n const requestArea = useCallback(\n (minutes: number) => {\n void run({ kind: \"area\", minutes });\n },\n [run],\n );\n\n const retry = useCallback(() => {\n if (lastRequest.current) {\n void run(lastRequest.current);\n }\n }, [run]);\n\n const cancel = useCallback(() => {\n if (stateRef.current.status !== \"loading\") {\n return;\n }\n abort();\n setState(IDLE);\n announceRef.current(announceRoutingCancelled(), { priority: \"polite\" });\n }, [abort, announceRef, stateRef]);\n\n const clear = useCallback(() => {\n stopsRef.current = [];\n setStopsState([]);\n invalidate();\n lastRequest.current = null;\n announceRef.current(announceDirectionsCleared(), { priority: \"polite\" });\n }, [announceRef, invalidate]);\n\n useEffect(() => abort, [abort]);\n\n return {\n available: provider !== undefined,\n stops,\n mode,\n state,\n result: state.status === \"done\" ? state.result : null,\n canAddStop: stopsHaveRoom(stops),\n addStop: addStopAction,\n removeStop: removeStopAction,\n moveStop: moveStopAction,\n setMode,\n requestRoute,\n requestArea,\n retry,\n cancel,\n clear,\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useChromeLayout } from "../../chrome/layoutContext.js";
|
|
2
|
+
import { useMap } from "../../host/MapContext.js";
|
|
3
|
+
import { freeCentre } from "../../layers/reveal.js";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { useReadingDirection } from "@mapcairn/react";
|
|
6
|
+
// src/tools/Directions/useFreeCentre.ts
|
|
7
|
+
/**
|
|
8
|
+
* The target of "at the map centre" for a tool whose panel covers part of the
|
|
9
|
+
* map: the middle of what is left uncovered, so it is never under the sheet.
|
|
10
|
+
* Read it inside the map context and the chrome.
|
|
11
|
+
*/
|
|
12
|
+
function useFreeCentre() {
|
|
13
|
+
const { adapter, view } = useMap();
|
|
14
|
+
const { layout, viewport, panelEdge } = useChromeLayout();
|
|
15
|
+
const direction = useReadingDirection();
|
|
16
|
+
const covered = freeCentre({
|
|
17
|
+
layout,
|
|
18
|
+
viewport,
|
|
19
|
+
panelEdge,
|
|
20
|
+
direction
|
|
21
|
+
});
|
|
22
|
+
const pixel = adapter ? covered ?? adapter.project(view.center) : null;
|
|
23
|
+
return {
|
|
24
|
+
pixel,
|
|
25
|
+
position: useCallback(() => adapter && pixel ? adapter.unproject(pixel) : null, [adapter, pixel])
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { useFreeCentre };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=useFreeCentre.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFreeCentre.js","names":[],"sources":["../../../src/tools/Directions/useFreeCentre.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { LatLng, PixelPoint } from \"@mapcairn/core\";\nimport { useReadingDirection } from \"@mapcairn/react\";\nimport { useCallback } from \"react\";\nimport { useChromeLayout } from \"../../chrome/layoutContext\";\nimport { useMap } from \"../../host\";\nimport { freeCentre } from \"../../layers/reveal\";\n\n/** What {@link useFreeCentre} returns. */\nexport interface FreeCentre {\n /**\n * The middle of the part of the map the sheet or side panel leaves free, in\n * pixels, or the middle of the whole map before the chrome has measured.\n * Null before the map has mounted.\n */\n readonly pixel: PixelPoint | null;\n /** The place under {@link FreeCentre.pixel}, read when asked, or null before the map has mounted. */\n readonly position: () => LatLng | null;\n}\n\n/**\n * The target of \"at the map centre\" for a tool whose panel covers part of the\n * map: the middle of what is left uncovered, so it is never under the sheet.\n * Read it inside the map context and the chrome.\n */\nexport function useFreeCentre(): FreeCentre {\n const { adapter, view } = useMap();\n const { layout, viewport, panelEdge } = useChromeLayout();\n const direction = useReadingDirection();\n const covered = freeCentre({\n layout,\n viewport,\n panelEdge,\n direction,\n });\n const pixel = adapter ? (covered ?? adapter.project(view.center)) : null;\n const position = useCallback(\n () => (adapter && pixel ? adapter.unproject(pixel) : null),\n [adapter, pixel],\n );\n return { pixel, position };\n}\n"],"mappings":";;;;;;;;;;;AA0BA,SAAgB,gBAA4B;CAC1C,MAAM,EAAE,SAAS,SAAS,OAAO;CACjC,MAAM,EAAE,QAAQ,UAAU,cAAc,gBAAgB;CACxD,MAAM,YAAY,oBAAoB;CACtC,MAAM,UAAU,WAAW;EACzB;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,QAAQ,UAAW,WAAW,QAAQ,QAAQ,KAAK,MAAM,IAAK;CAKpE,OAAO;EAAE;EAAO,UAJC,kBACR,WAAW,QAAQ,QAAQ,UAAU,KAAK,IAAI,MACrD,CAAC,SAAS,KAAK,CAED;CAAS;AAC3B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useMap } from "../../host/MapContext.js";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
// src/tools/DrawToolbar/DrawMapBindings.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Connects the draw tool to the live map without drawing anything: it gives
|
|
6
|
+
* the adapter the handles of the selected shape, and passes the adapter's
|
|
7
|
+
* handle presses and hovers to the tool. Render it inside `MapView`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks The handles are cleared when the tool closes or the map goes, so a
|
|
10
|
+
* press on the bare map never starts a drag that nothing draws.
|
|
11
|
+
*/
|
|
12
|
+
function DrawMapBindings({ draw }) {
|
|
13
|
+
const { adapter } = useMap();
|
|
14
|
+
const { handles, onHandleDrag, onHandleHover } = draw;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
adapter?.setEditHandles(handles);
|
|
17
|
+
}, [adapter, handles]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!adapter) return;
|
|
20
|
+
const stops = [adapter.on("handleDrag", onHandleDrag), adapter.on("handleHover", onHandleHover)];
|
|
21
|
+
return () => {
|
|
22
|
+
for (const stop of stops) stop();
|
|
23
|
+
adapter.setEditHandles([]);
|
|
24
|
+
};
|
|
25
|
+
}, [
|
|
26
|
+
adapter,
|
|
27
|
+
onHandleDrag,
|
|
28
|
+
onHandleHover
|
|
29
|
+
]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
export { DrawMapBindings };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=DrawMapBindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DrawMapBindings.js","names":[],"sources":["../../../src/tools/DrawToolbar/DrawMapBindings.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useEffect } from \"react\";\nimport { useMap } from \"../../host/MapContext\";\nimport type { UseDraw } from \"./useDraw\";\n\n/** Props for {@link DrawMapBindings}. */\nexport interface DrawMapBindingsProps {\n /** The drawing state from `useDraw`. */\n readonly draw: UseDraw;\n}\n\n/**\n * Connects the draw tool to the live map without drawing anything: it gives\n * the adapter the handles of the selected shape, and passes the adapter's\n * handle presses and hovers to the tool. Render it inside `MapView`.\n *\n * @remarks The handles are cleared when the tool closes or the map goes, so a\n * press on the bare map never starts a drag that nothing draws.\n */\nexport function DrawMapBindings({ draw }: DrawMapBindingsProps) {\n const { adapter } = useMap();\n const { handles, onHandleDrag, onHandleHover } = draw;\n\n useEffect(() => {\n adapter?.setEditHandles(handles);\n }, [adapter, handles]);\n\n useEffect(() => {\n if (!adapter) {\n return;\n }\n const stops = [\n adapter.on(\"handleDrag\", onHandleDrag),\n adapter.on(\"handleHover\", onHandleHover),\n ];\n return () => {\n for (const stop of stops) {\n stop();\n }\n adapter.setEditHandles([]);\n };\n }, [adapter, onHandleDrag, onHandleHover]);\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;AAoBA,SAAgB,gBAAgB,EAAE,QAA8B;CAC9D,MAAM,EAAE,YAAY,OAAO;CAC3B,MAAM,EAAE,SAAS,cAAc,kBAAkB;CAEjD,gBAAgB;EACd,SAAS,eAAe,OAAO;CACjC,GAAG,CAAC,SAAS,OAAO,CAAC;CAErB,gBAAgB;EACd,IAAI,CAAC,SACH;EAEF,MAAM,QAAQ,CACZ,QAAQ,GAAG,cAAc,YAAY,GACrC,QAAQ,GAAG,eAAe,aAAa,CACzC;EACA,aAAa;GACX,KAAK,MAAM,QAAQ,OACjB,KAAK;GAEP,QAAQ,eAAe,CAAC,CAAC;EAC3B;CACF,GAAG;EAAC;EAAS;EAAc;CAAa,CAAC;CAEzC,OAAO;AACT"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { useFocusTarget } from "../../chrome/focusRegistry.js";
|
|
2
|
+
import { useScrollEdges } from "../../chrome/useScrollEdges.js";
|
|
3
|
+
import { useFormatMessage, useMessages } from "../../services/hooks.js";
|
|
4
|
+
import { Button } from "../../ui/Button/Button.js";
|
|
5
|
+
import { Icon } from "../../ui/Icon/Icon.js";
|
|
6
|
+
import { IconButton } from "../../ui/IconButton/IconButton.js";
|
|
7
|
+
import { SegmentedControl } from "../../ui/SegmentedControl/SegmentedControl.js";
|
|
8
|
+
import { Surface } from "../../ui/Surface/Surface.js";
|
|
9
|
+
import { VisuallyHidden } from "../../ui/VisuallyHidden/VisuallyHidden.js";
|
|
10
|
+
import { actions, actionsRow, group, groupLabel, hint, issue, measure, modes, modesRow, primaryLabel, readout, root, scroller, status, toolbar } from "./DrawToolbar.styles.js";
|
|
11
|
+
import { hintFor } from "@mapcairn/core";
|
|
12
|
+
import { Check, ChevronLeft, ChevronRight, CircleMinus, CirclePlus, Crosshair, Minus, Plus, Redo2, Shapes, Trash2, TriangleAlert, Undo2, X } from "lucide-react";
|
|
13
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
// src/tools/DrawToolbar/DrawToolbar.tsx
|
|
16
|
+
function modeOptions(t) {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
value: "point",
|
|
20
|
+
label: t("tools.draw.mode.point", {})
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
value: "line",
|
|
24
|
+
label: t("tools.draw.mode.line", {})
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
value: "polygon",
|
|
28
|
+
label: t("tools.draw.mode.polygon", {})
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
value: "circle",
|
|
32
|
+
label: t("tools.draw.mode.circle", {})
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
/** The keys the selected shape's group handles itself, because its buttons do not use them. */
|
|
37
|
+
var GROUP_KEYS = /* @__PURE__ */ new Set([
|
|
38
|
+
"ArrowLeft",
|
|
39
|
+
"ArrowRight",
|
|
40
|
+
"ArrowUp",
|
|
41
|
+
"ArrowDown",
|
|
42
|
+
"Delete",
|
|
43
|
+
"Backspace",
|
|
44
|
+
"[",
|
|
45
|
+
"]"
|
|
46
|
+
]);
|
|
47
|
+
function selectedGroupLabel(messages, shape, vertex) {
|
|
48
|
+
if (shape.kind !== "line" && shape.kind !== "polygon") return shape.label;
|
|
49
|
+
const total = shape.vertices.length;
|
|
50
|
+
return vertex === null ? messages.plural("tools.draw.selectedPoints", {
|
|
51
|
+
label: shape.label,
|
|
52
|
+
count: total
|
|
53
|
+
}) : messages.t("tools.draw.selectedPoint", {
|
|
54
|
+
label: shape.label,
|
|
55
|
+
index: vertex + 1,
|
|
56
|
+
total
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The controls for the selected shape: step between its points, move one to
|
|
61
|
+
* the map centre, add or remove one, or change a circle's radius. Each is a
|
|
62
|
+
* single tap, and the arrow keys move the selected point.
|
|
63
|
+
*/
|
|
64
|
+
function SelectedGroup({ draw, shape }) {
|
|
65
|
+
const messages = useMessages();
|
|
66
|
+
const { t } = messages;
|
|
67
|
+
const vertex = draw.selection?.vertex ?? null;
|
|
68
|
+
const path = shape.kind === "line" || shape.kind === "polygon";
|
|
69
|
+
const circle = shape.kind === "circle";
|
|
70
|
+
const hasVertex = vertex !== null;
|
|
71
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
72
|
+
className: group,
|
|
73
|
+
"data-testid": "draw-selected-group",
|
|
74
|
+
"data-draw-group": "",
|
|
75
|
+
children: [/* @__PURE__ */ jsx("legend", {
|
|
76
|
+
className: groupLabel,
|
|
77
|
+
"data-testid": "draw-selected-label",
|
|
78
|
+
children: selectedGroupLabel(messages, shape, vertex)
|
|
79
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
80
|
+
className: actions,
|
|
81
|
+
children: [
|
|
82
|
+
path ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(IconButton, {
|
|
83
|
+
label: t("tools.draw.previousPoint", {}),
|
|
84
|
+
icon: ChevronLeft,
|
|
85
|
+
mirrorInRtl: true,
|
|
86
|
+
"data-testid": "draw-vertex-prev",
|
|
87
|
+
onClick: () => draw.stepVertex(-1)
|
|
88
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
89
|
+
label: t("tools.draw.nextPoint", {}),
|
|
90
|
+
icon: ChevronRight,
|
|
91
|
+
mirrorInRtl: true,
|
|
92
|
+
"data-testid": "draw-vertex-next",
|
|
93
|
+
onClick: () => draw.stepVertex(1)
|
|
94
|
+
})] }) : null,
|
|
95
|
+
path ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(IconButton, {
|
|
96
|
+
label: t("tools.draw.insertPoint", {}),
|
|
97
|
+
icon: CirclePlus,
|
|
98
|
+
disabled: !hasVertex,
|
|
99
|
+
"data-testid": "draw-vertex-insert",
|
|
100
|
+
onClick: draw.insertAtCentre
|
|
101
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
102
|
+
label: t("tools.draw.removePoint", {}),
|
|
103
|
+
icon: CircleMinus,
|
|
104
|
+
disabled: !hasVertex,
|
|
105
|
+
"data-testid": "draw-vertex-remove",
|
|
106
|
+
onClick: draw.removeVertex
|
|
107
|
+
})] }) : null,
|
|
108
|
+
circle ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
109
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
110
|
+
label: t("tools.draw.smallerRadius", {}),
|
|
111
|
+
icon: Minus,
|
|
112
|
+
"data-testid": "draw-radius-smaller",
|
|
113
|
+
onClick: () => draw.scaleRadius(1 / 1.1)
|
|
114
|
+
}),
|
|
115
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
116
|
+
label: t("tools.draw.largerRadius", {}),
|
|
117
|
+
icon: Plus,
|
|
118
|
+
"data-testid": "draw-radius-larger",
|
|
119
|
+
onClick: () => draw.scaleRadius(1.1)
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
122
|
+
label: t("tools.draw.radiusToCentre", {}),
|
|
123
|
+
icon: Crosshair,
|
|
124
|
+
"data-testid": "draw-radius-centre",
|
|
125
|
+
onClick: draw.setRadiusToCentre
|
|
126
|
+
})
|
|
127
|
+
] }) : null
|
|
128
|
+
]
|
|
129
|
+
})]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The draw toolbar: a switch for what to draw, the name and measures of the
|
|
134
|
+
* shape under way or selected, buttons to add a point at the map centre, undo,
|
|
135
|
+
* redo, cancel or delete, open the list of shapes and finish, and a group of
|
|
136
|
+
* controls for the selected shape. It sits in a landmark named "Drawing", so
|
|
137
|
+
* it is inside a landmark wherever the host places it.
|
|
138
|
+
*
|
|
139
|
+
* On mount focus moves to the chosen shape type, because the person has just
|
|
140
|
+
* chosen Draw and the next thing to do is here. The bottom-centre slot it sits
|
|
141
|
+
* in is what the slots below it ride above. The toolbar registers its Shapes
|
|
142
|
+
* button as a focus target, so closing the sheet over a drawing puts focus
|
|
143
|
+
* back on it.
|
|
144
|
+
* @remarks Every pointer action has a button: Add point at map centre places a
|
|
145
|
+
* point (or moves the selected one), Previous and Next point select, the
|
|
146
|
+
* group moves, adds and removes points, and the circle group sets the
|
|
147
|
+
* radius. The arrow keys move the selected point from the map, or while
|
|
148
|
+
* focus is in the selected shape's group, and Escape and the undo keys work
|
|
149
|
+
* from anywhere in the toolbar. The primary button is Finish while a shape
|
|
150
|
+
* is being drawn and Done otherwise, in one element, so focus stays put when
|
|
151
|
+
* it changes. Cancel and Delete are one button for the same reason. The
|
|
152
|
+
* button keeps the width of the longer label and its check mark in both
|
|
153
|
+
* states, so the row does not wrap, and the toolbar does not change height,
|
|
154
|
+
* when the label changes.
|
|
155
|
+
*/
|
|
156
|
+
function DrawToolbar({ draw, onDone, onOpenShapes }) {
|
|
157
|
+
const rootRef = useRef(null);
|
|
158
|
+
const format = useFormatMessage();
|
|
159
|
+
const { t } = useMessages();
|
|
160
|
+
const registerShapes = useFocusTarget("draw-shapes");
|
|
161
|
+
const scrollerRef = useRef(null);
|
|
162
|
+
useScrollEdges(scrollerRef);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
const root = rootRef.current;
|
|
165
|
+
if (!root || root.contains(root.ownerDocument.activeElement)) return;
|
|
166
|
+
root.querySelector("[role=\"radio\"][data-state=\"on\"]")?.focus();
|
|
167
|
+
}, []);
|
|
168
|
+
const setRoot = useCallback((root) => {
|
|
169
|
+
rootRef.current = root;
|
|
170
|
+
registerShapes(root?.querySelector("[data-focus-target=\"draw-shapes\"]") ?? null);
|
|
171
|
+
}, [registerShapes]);
|
|
172
|
+
const { draft, selected, mode } = draw;
|
|
173
|
+
const drawing = draft !== null;
|
|
174
|
+
const toolbarKeys = (event) => {
|
|
175
|
+
if (event.defaultPrevented) return;
|
|
176
|
+
const inGroup = event.target instanceof Element && event.target.closest("[data-draw-group]") !== null;
|
|
177
|
+
if ((event.key === "Escape" || event.ctrlKey || event.metaKey || inGroup && GROUP_KEYS.has(event.key)) && draw.keyCommand(event)) event.preventDefault();
|
|
178
|
+
};
|
|
179
|
+
const addLabel = draw.selection?.vertex != null ? t("tools.draw.movePoint", {}) : t("tools.addPointAtCentre", {});
|
|
180
|
+
const finishLabel = t("tools.draw.finish", {});
|
|
181
|
+
const doneLabel = t("tools.done", {});
|
|
182
|
+
const [primaryLabel$1, otherLabel] = drawing ? [finishLabel, doneLabel] : [doneLabel, finishLabel];
|
|
183
|
+
const removeLabel = drawing ? t("tools.draw.cancelShape", {}) : t("tools.draw.deleteShape", {});
|
|
184
|
+
return /* @__PURE__ */ jsx("section", {
|
|
185
|
+
ref: setRoot,
|
|
186
|
+
"aria-label": t("tools.draw.region", {}),
|
|
187
|
+
className: root,
|
|
188
|
+
"data-chrome": "draw-toolbar",
|
|
189
|
+
children: /* @__PURE__ */ jsx(Surface, {
|
|
190
|
+
role: "toolbar",
|
|
191
|
+
"aria-label": t("tools.draw.toolbar", {}),
|
|
192
|
+
className: toolbar,
|
|
193
|
+
"data-testid": "draw-toolbar",
|
|
194
|
+
onKeyDown: toolbarKeys,
|
|
195
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
196
|
+
ref: scrollerRef,
|
|
197
|
+
className: scroller,
|
|
198
|
+
"data-testid": "draw-toolbar-scroll",
|
|
199
|
+
children: [
|
|
200
|
+
/* @__PURE__ */ jsx("div", {
|
|
201
|
+
className: modesRow,
|
|
202
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
203
|
+
className: modes,
|
|
204
|
+
label: t("tools.draw.shapeToDraw", {}),
|
|
205
|
+
options: modeOptions(t),
|
|
206
|
+
value: mode,
|
|
207
|
+
onValueChange: (next) => draw.setMode(next),
|
|
208
|
+
"data-testid": "draw-mode"
|
|
209
|
+
})
|
|
210
|
+
}),
|
|
211
|
+
/* @__PURE__ */ jsxs("p", {
|
|
212
|
+
className: readout,
|
|
213
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
214
|
+
className: status,
|
|
215
|
+
"data-testid": "draw-status",
|
|
216
|
+
children: draw.status
|
|
217
|
+
}), draw.measure ? /* @__PURE__ */ jsxs("span", {
|
|
218
|
+
className: measure,
|
|
219
|
+
"data-testid": "draw-measure",
|
|
220
|
+
children: [/* @__PURE__ */ jsx(VisuallyHidden, { children: ", " }), draw.measure]
|
|
221
|
+
}) : null]
|
|
222
|
+
}),
|
|
223
|
+
draw.issueMessage ? /* @__PURE__ */ jsxs("p", {
|
|
224
|
+
className: issue,
|
|
225
|
+
"data-testid": "draw-issue",
|
|
226
|
+
children: [/* @__PURE__ */ jsx(Icon, { icon: TriangleAlert }), /* @__PURE__ */ jsx("span", { children: draw.issueMessage })]
|
|
227
|
+
}) : null,
|
|
228
|
+
/* @__PURE__ */ jsxs("div", {
|
|
229
|
+
className: actionsRow,
|
|
230
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
231
|
+
className: actions,
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
234
|
+
label: addLabel,
|
|
235
|
+
icon: Crosshair,
|
|
236
|
+
"data-testid": "draw-add-point",
|
|
237
|
+
onClick: draw.placeAtCentre
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
240
|
+
label: t("tools.draw.undo", {}),
|
|
241
|
+
icon: Undo2,
|
|
242
|
+
mirrorInRtl: true,
|
|
243
|
+
disabled: !draw.canUndo,
|
|
244
|
+
"data-testid": "draw-undo",
|
|
245
|
+
onClick: draw.undo
|
|
246
|
+
}),
|
|
247
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
248
|
+
label: t("tools.draw.redo", {}),
|
|
249
|
+
icon: Redo2,
|
|
250
|
+
mirrorInRtl: true,
|
|
251
|
+
disabled: !draw.canRedo,
|
|
252
|
+
"data-testid": "draw-redo",
|
|
253
|
+
onClick: draw.redo
|
|
254
|
+
}),
|
|
255
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
256
|
+
label: removeLabel,
|
|
257
|
+
icon: drawing ? X : Trash2,
|
|
258
|
+
disabled: !drawing && selected === null,
|
|
259
|
+
"data-testid": "draw-remove",
|
|
260
|
+
onClick: drawing ? draw.cancel : draw.deleteSelected
|
|
261
|
+
}),
|
|
262
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
263
|
+
label: t("tools.draw.shapesAndExport", {}),
|
|
264
|
+
icon: Shapes,
|
|
265
|
+
"data-focus-target": "draw-shapes",
|
|
266
|
+
"data-testid": "draw-shapes",
|
|
267
|
+
onClick: onOpenShapes
|
|
268
|
+
})
|
|
269
|
+
]
|
|
270
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
271
|
+
icon: Check,
|
|
272
|
+
"data-testid": "draw-done",
|
|
273
|
+
onClick: drawing ? draw.finish : onDone,
|
|
274
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
275
|
+
className: primaryLabel,
|
|
276
|
+
"data-reserve": otherLabel,
|
|
277
|
+
children: primaryLabel$1
|
|
278
|
+
})
|
|
279
|
+
})]
|
|
280
|
+
}),
|
|
281
|
+
selected && selected.kind !== "point" && !drawing ? /* @__PURE__ */ jsx(SelectedGroup, {
|
|
282
|
+
draw,
|
|
283
|
+
shape: selected
|
|
284
|
+
}) : null,
|
|
285
|
+
/* @__PURE__ */ jsx("p", {
|
|
286
|
+
className: hint,
|
|
287
|
+
children: selected && !drawing ? t("tools.draw.selectedHint", {}) : format(hintFor(mode))
|
|
288
|
+
})
|
|
289
|
+
]
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
export { DrawToolbar };
|
|
295
|
+
|
|
296
|
+
//# sourceMappingURL=DrawToolbar.js.map
|