@mapcairn/map 0.0.0-stage → 0.1.0-rc.2
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":"DrawToolbar.js","names":["styles.group","styles.groupLabel","styles.actions","_Fragment","primaryLabel","styles.root","styles.toolbar","styles.scroller","styles.modesRow","styles.modes","styles.readout","styles.status","styles.measure","styles.issue","styles.actionsRow","styles.primaryLabel","styles.hint"],"sources":["../../../src/tools/DrawToolbar/DrawToolbar.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type DrawKind,\n type DrawShape,\n hintFor,\n type MessageCatalogue,\n} from \"@mapcairn/core\";\nimport {\n Check,\n ChevronLeft,\n ChevronRight,\n CircleMinus,\n CirclePlus,\n Crosshair,\n Minus,\n Plus,\n Redo2,\n Shapes,\n Trash2,\n TriangleAlert,\n Undo2,\n X,\n} from \"lucide-react\";\nimport { type KeyboardEvent, useCallback, useEffect, useRef } from \"react\";\nimport { useFocusTarget } from \"../../chrome/focusRegistry\";\nimport { useScrollEdges } from \"../../chrome/useScrollEdges\";\nimport { useFormatMessage, useMessages } from \"../../services\";\nimport { Button } from \"../../ui/Button\";\nimport { Icon } from \"../../ui/Icon\";\nimport { IconButton } from \"../../ui/IconButton\";\nimport { SegmentedControl } from \"../../ui/SegmentedControl\";\nimport { Surface } from \"../../ui/Surface\";\nimport { VisuallyHidden } from \"../../ui/VisuallyHidden\";\nimport * as styles from \"./DrawToolbar.css\";\nimport type { UseDraw } from \"./useDraw\";\n\n/** Props for {@link DrawToolbar}. */\nexport interface DrawToolbarProps {\n /** The drawing state from `useDraw`. */\n readonly draw: UseDraw;\n /** Called by \"Done\". */\n readonly onDone: () => void;\n /** Called by \"Shapes and export\", which opens the list of shapes in the sheet. */\n readonly onOpenShapes: () => void;\n}\n\nfunction modeOptions(\n t: MessageCatalogue[\"t\"],\n): readonly { value: DrawKind; label: string }[] {\n return [\n { value: \"point\", label: t(\"tools.draw.mode.point\", {}) },\n { value: \"line\", label: t(\"tools.draw.mode.line\", {}) },\n { value: \"polygon\", label: t(\"tools.draw.mode.polygon\", {}) },\n { value: \"circle\", label: t(\"tools.draw.mode.circle\", {}) },\n ];\n}\n\n/** The keys the selected shape's group handles itself, because its buttons do not use them. */\nconst GROUP_KEYS = new Set([\n \"ArrowLeft\",\n \"ArrowRight\",\n \"ArrowUp\",\n \"ArrowDown\",\n \"Delete\",\n \"Backspace\",\n \"[\",\n \"]\",\n]);\n\nfunction selectedGroupLabel(\n messages: MessageCatalogue,\n shape: DrawShape,\n vertex: number | null,\n): string {\n if (shape.kind !== \"line\" && shape.kind !== \"polygon\") {\n return shape.label;\n }\n const total = shape.vertices.length;\n return vertex === null\n ? messages.plural(\"tools.draw.selectedPoints\", {\n label: shape.label,\n count: total,\n })\n : messages.t(\"tools.draw.selectedPoint\", {\n label: shape.label,\n index: vertex + 1,\n total,\n });\n}\n\ninterface SelectedGroupProps {\n readonly draw: UseDraw;\n readonly shape: DrawShape;\n}\n\n/**\n * The controls for the selected shape: step between its points, move one to\n * the map centre, add or remove one, or change a circle's radius. Each is a\n * single tap, and the arrow keys move the selected point.\n */\nfunction SelectedGroup({ draw, shape }: SelectedGroupProps) {\n const messages = useMessages();\n const { t } = messages;\n const vertex = draw.selection?.vertex ?? null;\n const path = shape.kind === \"line\" || shape.kind === \"polygon\";\n const circle = shape.kind === \"circle\";\n const hasVertex = vertex !== null;\n return (\n <fieldset\n className={styles.group}\n data-testid=\"draw-selected-group\"\n data-draw-group=\"\"\n >\n <legend className={styles.groupLabel} data-testid=\"draw-selected-label\">\n {selectedGroupLabel(messages, shape, vertex)}\n </legend>\n <div className={styles.actions}>\n {path ? (\n <>\n <IconButton\n label={t(\"tools.draw.previousPoint\", {})}\n icon={ChevronLeft}\n mirrorInRtl\n data-testid=\"draw-vertex-prev\"\n onClick={() => draw.stepVertex(-1)}\n />\n <IconButton\n label={t(\"tools.draw.nextPoint\", {})}\n icon={ChevronRight}\n mirrorInRtl\n data-testid=\"draw-vertex-next\"\n onClick={() => draw.stepVertex(1)}\n />\n </>\n ) : null}\n {path ? (\n <>\n <IconButton\n label={t(\"tools.draw.insertPoint\", {})}\n icon={CirclePlus}\n disabled={!hasVertex}\n data-testid=\"draw-vertex-insert\"\n onClick={draw.insertAtCentre}\n />\n <IconButton\n label={t(\"tools.draw.removePoint\", {})}\n icon={CircleMinus}\n disabled={!hasVertex}\n data-testid=\"draw-vertex-remove\"\n onClick={draw.removeVertex}\n />\n </>\n ) : null}\n {circle ? (\n <>\n <IconButton\n label={t(\"tools.draw.smallerRadius\", {})}\n icon={Minus}\n data-testid=\"draw-radius-smaller\"\n onClick={() => draw.scaleRadius(1 / 1.1)}\n />\n <IconButton\n label={t(\"tools.draw.largerRadius\", {})}\n icon={Plus}\n data-testid=\"draw-radius-larger\"\n onClick={() => draw.scaleRadius(1.1)}\n />\n <IconButton\n label={t(\"tools.draw.radiusToCentre\", {})}\n icon={Crosshair}\n data-testid=\"draw-radius-centre\"\n onClick={draw.setRadiusToCentre}\n />\n </>\n ) : null}\n </div>\n </fieldset>\n );\n}\n\n/**\n * The draw toolbar: a switch for what to draw, the name and measures of the\n * shape under way or selected, buttons to add a point at the map centre, undo,\n * redo, cancel or delete, open the list of shapes and finish, and a group of\n * controls for the selected shape. It sits in a landmark named \"Drawing\", so\n * it is inside a landmark wherever the host places it.\n *\n * On mount focus moves to the chosen shape type, because the person has just\n * chosen Draw and the next thing to do is here. The bottom-centre slot it sits\n * in is what the slots below it ride above. The toolbar registers its Shapes\n * button as a focus target, so closing the sheet over a drawing puts focus\n * back on it.\n * @remarks Every pointer action has a button: Add point at map centre places a\n * point (or moves the selected one), Previous and Next point select, the\n * group moves, adds and removes points, and the circle group sets the\n * radius. The arrow keys move the selected point from the map, or while\n * focus is in the selected shape's group, and Escape and the undo keys work\n * from anywhere in the toolbar. The primary button is Finish while a shape\n * is being drawn and Done otherwise, in one element, so focus stays put when\n * it changes. Cancel and Delete are one button for the same reason. The\n * button keeps the width of the longer label and its check mark in both\n * states, so the row does not wrap, and the toolbar does not change height,\n * when the label changes.\n */\nexport function DrawToolbar({ draw, onDone, onOpenShapes }: DrawToolbarProps) {\n const rootRef = useRef<HTMLElement>(null);\n const format = useFormatMessage();\n const { t } = useMessages();\n const registerShapes = useFocusTarget(\"draw-shapes\");\n const scrollerRef = useRef<HTMLDivElement>(null);\n useScrollEdges(scrollerRef);\n\n // Coming back from the sheet, focus is put on the Shapes button before this\n // runs, and the toolbar leaves it there.\n useEffect(() => {\n const root = rootRef.current;\n if (!root || root.contains(root.ownerDocument.activeElement)) {\n return;\n }\n root.querySelector<HTMLElement>('[role=\"radio\"][data-state=\"on\"]')?.focus();\n }, []);\n\n const setRoot = useCallback(\n (root: HTMLElement | null) => {\n rootRef.current = root;\n registerShapes(\n root?.querySelector<HTMLElement>('[data-focus-target=\"draw-shapes\"]') ??\n null,\n );\n },\n [registerShapes],\n );\n\n const { draft, selected, mode } = draw;\n const drawing = draft !== null;\n\n const toolbarKeys = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented) {\n return;\n }\n // Escape and the undo keys work anywhere in the toolbar. The arrow, delete\n // and bracket keys are the selected shape's group's, because the shape\n // switch beside it uses the arrows itself.\n const inGroup =\n event.target instanceof Element &&\n event.target.closest(\"[data-draw-group]\") !== null;\n const handled =\n event.key === \"Escape\" ||\n event.ctrlKey ||\n event.metaKey ||\n (inGroup && GROUP_KEYS.has(event.key));\n if (handled && draw.keyCommand(event)) {\n event.preventDefault();\n }\n };\n\n const addLabel =\n draw.selection?.vertex != null\n ? t(\"tools.draw.movePoint\", {})\n : t(\"tools.addPointAtCentre\", {});\n const finishLabel = t(\"tools.draw.finish\", {});\n const doneLabel = t(\"tools.done\", {});\n const [primaryLabel, otherLabel] = drawing\n ? [finishLabel, doneLabel]\n : [doneLabel, finishLabel];\n const removeLabel = drawing\n ? t(\"tools.draw.cancelShape\", {})\n : t(\"tools.draw.deleteShape\", {});\n\n return (\n <section\n ref={setRoot}\n aria-label={t(\"tools.draw.region\", {})}\n className={styles.root}\n data-chrome=\"draw-toolbar\"\n >\n <Surface\n role=\"toolbar\"\n aria-label={t(\"tools.draw.toolbar\", {})}\n className={styles.toolbar}\n data-testid=\"draw-toolbar\"\n onKeyDown={toolbarKeys}\n >\n <div\n ref={scrollerRef}\n className={styles.scroller}\n data-testid=\"draw-toolbar-scroll\"\n >\n <div className={styles.modesRow}>\n <SegmentedControl\n className={styles.modes}\n label={t(\"tools.draw.shapeToDraw\", {})}\n options={modeOptions(t)}\n value={mode}\n onValueChange={(next) => draw.setMode(next as DrawKind)}\n data-testid=\"draw-mode\"\n />\n </div>\n <p className={styles.readout}>\n <span className={styles.status} data-testid=\"draw-status\">\n {draw.status}\n </span>\n {draw.measure ? (\n <span className={styles.measure} data-testid=\"draw-measure\">\n <VisuallyHidden>, </VisuallyHidden>\n {draw.measure}\n </span>\n ) : null}\n </p>\n {draw.issueMessage ? (\n <p className={styles.issue} data-testid=\"draw-issue\">\n <Icon icon={TriangleAlert} />\n <span>{draw.issueMessage}</span>\n </p>\n ) : null}\n <div className={styles.actionsRow}>\n <div className={styles.actions}>\n <IconButton\n label={addLabel}\n icon={Crosshair}\n data-testid=\"draw-add-point\"\n onClick={draw.placeAtCentre}\n />\n <IconButton\n label={t(\"tools.draw.undo\", {})}\n icon={Undo2}\n mirrorInRtl\n disabled={!draw.canUndo}\n data-testid=\"draw-undo\"\n onClick={draw.undo}\n />\n <IconButton\n label={t(\"tools.draw.redo\", {})}\n icon={Redo2}\n mirrorInRtl\n disabled={!draw.canRedo}\n data-testid=\"draw-redo\"\n onClick={draw.redo}\n />\n <IconButton\n label={removeLabel}\n icon={drawing ? X : Trash2}\n disabled={!drawing && selected === null}\n data-testid=\"draw-remove\"\n onClick={drawing ? draw.cancel : draw.deleteSelected}\n />\n <IconButton\n label={t(\"tools.draw.shapesAndExport\", {})}\n icon={Shapes}\n data-focus-target=\"draw-shapes\"\n data-testid=\"draw-shapes\"\n onClick={onOpenShapes}\n />\n </div>\n <Button\n icon={Check}\n data-testid=\"draw-done\"\n onClick={drawing ? draw.finish : onDone}\n >\n <span className={styles.primaryLabel} data-reserve={otherLabel}>\n {primaryLabel}\n </span>\n </Button>\n </div>\n {selected && selected.kind !== \"point\" && !drawing ? (\n <SelectedGroup draw={draw} shape={selected} />\n ) : null}\n <p className={styles.hint}>\n {selected && !drawing\n ? t(\"tools.draw.selectedHint\", {})\n : format(hintFor(mode))}\n </p>\n </div>\n </Surface>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+CA,SAAS,YACP,GAC+C;CAC/C,OAAO;EACL;GAAE,OAAO;GAAS,OAAO,EAAE,yBAAyB,CAAC,CAAC;EAAE;EACxD;GAAE,OAAO;GAAQ,OAAO,EAAE,wBAAwB,CAAC,CAAC;EAAE;EACtD;GAAE,OAAO;G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D;OACE,MAAM;OACN,eAAY;OACZ,SAAS,UAAU,KAAK,SAAS;OAEjC,UAAA,oBAAC,QAAD;QAAM,WAAWa;QAAqB,gBAAc;QACjD,UAAAX;OACG,CAAA;MACA,CAAA,CACL;;KACJ,YAAY,SAAS,SAAS,WAAW,CAAC,UACzC,oBAAC,eAAD;MAAqB;MAAM,OAAO;KAAW,CAAA,IAC3C;KACJ,oBAAC,KAAD;MAAG,WAAWY;MACX,UAAA,YAAY,CAAC,UACV,EAAE,2BAA2B,CAAC,CAAC,IAC/B,OAAO,QAAQ,IAAI,CAAC;KACvB,CAAA;IACA;;EACE,CAAA;CACF,CAAA;AAEb"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
/* empty css */
|
|
3
|
+
// src/tools/DrawToolbar/DrawToolbar.css.ts
|
|
4
|
+
var root = "_1f5grbt0";
|
|
5
|
+
var toolbar = "_1f5grbt1";
|
|
6
|
+
var scroller = "_1f5grbt2 _1c0yelp0";
|
|
7
|
+
var modesRow = "_1f5grbt3";
|
|
8
|
+
var actionsRow = "_1f5grbt4";
|
|
9
|
+
var modes = "_1f5grbt5";
|
|
10
|
+
var readout = "_1f5grbt6";
|
|
11
|
+
var status = "_1f5grbt7";
|
|
12
|
+
var measure = "_1f5grbt8";
|
|
13
|
+
var actions = "_1f5grbt9";
|
|
14
|
+
var primaryLabel = "_1f5grbta";
|
|
15
|
+
var group = "_1f5grbtb";
|
|
16
|
+
var groupLabel = "_1f5grbtc";
|
|
17
|
+
var issue = "_1f5grbtd";
|
|
18
|
+
var hint = "_1f5grbte";
|
|
19
|
+
export { actions, actionsRow, group, groupLabel, hint, issue, measure, modes, modesRow, primaryLabel, readout, root, scroller, status, toolbar };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=DrawToolbar.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DrawToolbar.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { imageMarksFor } from "@mapcairn/core";
|
|
2
|
+
import { parseColour, toHex, tokenValues } from "@mapcairn/theme";
|
|
3
|
+
// src/tools/DrawToolbar/imageDrawing.ts
|
|
4
|
+
/**
|
|
5
|
+
* The shapes as a drawing for a saved map image, in the overlay's colours for
|
|
6
|
+
* the light theme (the basemap never follows the theme, so the image does not
|
|
7
|
+
* either). Undefined when there is nothing to draw, so the image is the map
|
|
8
|
+
* alone.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
function drawingForImage(shapes) {
|
|
13
|
+
const marks = imageMarksFor(shapes);
|
|
14
|
+
if (marks.length === 0) return;
|
|
15
|
+
const colours = tokenValues.themeValues.light.colour;
|
|
16
|
+
return {
|
|
17
|
+
colour: toHex(parseColour(colours.mapMeasureLine)),
|
|
18
|
+
halo: toHex(parseColour(colours.mapHalo)),
|
|
19
|
+
marks
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { drawingForImage };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=imageDrawing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageDrawing.js","names":[],"sources":["../../../src/tools/DrawToolbar/imageDrawing.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type DrawShape,\n imageMarksFor,\n type MapImageDrawing,\n} from \"@mapcairn/core\";\nimport { parseColour, toHex, tokenValues } from \"@mapcairn/theme\";\n\n/**\n * The shapes as a drawing for a saved map image, in the overlay's colours for\n * the light theme (the basemap never follows the theme, so the image does not\n * either). Undefined when there is nothing to draw, so the image is the map\n * alone.\n *\n * @internal\n */\nexport function drawingForImage(\n shapes: readonly DrawShape[],\n): MapImageDrawing | undefined {\n const marks = imageMarksFor(shapes);\n if (marks.length === 0) {\n return undefined;\n }\n const colours = tokenValues.themeValues.light.colour;\n return {\n colour: toHex(parseColour(colours.mapMeasureLine)),\n halo: toHex(parseColour(colours.mapHalo)),\n marks,\n };\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,gBACd,QAC6B;CAC7B,MAAM,QAAQ,cAAc,MAAM;CAClC,IAAI,MAAM,WAAW,GACnB;CAEF,MAAM,UAAU,YAAY,YAAY,MAAM;CAC9C,OAAO;EACL,QAAQ,MAAM,YAAY,QAAQ,cAAc,CAAC;EACjD,MAAM,MAAM,YAAY,QAAQ,OAAO,CAAC;EACxC;CACF;AACF"}
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { overlayPlacement } from "../../host/overlays/geometry.js";
|
|
2
|
+
import { useClipboard, useFileOpener, useFileSaver, useFormatMessage, useMessages, useSettings, useUrlState } from "../../services/hooks.js";
|
|
3
|
+
import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
|
|
4
|
+
import { DRAW_ISSUE_MESSAGES, FileOpenError, MAX_DRAWING_SHAPES, MAX_IMPORT_BYTES, MAX_SHARE_SHAPES, SHAPE_FILE_TYPES, announceDrawEvent, createDrawReducer, decodeShapes, describeAxisSuggestion, describeShapeImport, distanceMetres, draftOf, drawKeyCommand, editHandlesFor, encodeShapes, exportableShapes, formatShapeMeasure, initialDrawState, message, parseHandleId, parseShapeFile, pickShape, selectedShape, shapeInputBounds, shapesToCsv, shapesToGeoJsonText, shapesToWkt, suggestWktAxisOrder, unsharableShapes, validateShape } from "@mapcairn/core";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
6
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
7
|
+
// src/tools/DrawToolbar/useDraw.ts
|
|
8
|
+
/**
|
|
9
|
+
* How long a moved vertex must stay still before the new measure is announced, in milliseconds.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
var DRAW_ANNOUNCE_DELAY_MS = 800;
|
|
14
|
+
/** How near, in CSS pixels, a tap must be to a shape's edge, line or point to select it. */
|
|
15
|
+
var SHAPE_PICK_TOLERANCE_PX = 12;
|
|
16
|
+
/** The name of the GeoJSON file. */
|
|
17
|
+
var GEOJSON_FILENAME = "mapcairn-shapes.geojson";
|
|
18
|
+
/** The name of the CSV file. */
|
|
19
|
+
var CSV_FILENAME = "mapcairn-shapes.csv";
|
|
20
|
+
/** The name of the WKT file. */
|
|
21
|
+
var WKT_FILENAME = "mapcairn-shapes.wkt";
|
|
22
|
+
/** What to say when no file could be opened. A cancelled picker says nothing. */
|
|
23
|
+
var FILE_OPEN_MESSAGES = {
|
|
24
|
+
"too-large": describeShapeImport({
|
|
25
|
+
ok: false,
|
|
26
|
+
refusal: "too-large"
|
|
27
|
+
}),
|
|
28
|
+
unreadable: message("tools.draw.file.unreadable", {}),
|
|
29
|
+
unsupported: message("tools.draw.file.unsupported", {})
|
|
30
|
+
};
|
|
31
|
+
/** Added to an import's result when the shapes are more than a link can carry. */
|
|
32
|
+
var LINK_LIMIT_NOTE = message("tools.draw.linkLimitNote", { max: MAX_SHARE_SHAPES });
|
|
33
|
+
/** What pressing a handle selects: a vertex, or the shape for a radius handle. A midpoint selects nothing until it is used. */
|
|
34
|
+
function pressAction(parsed) {
|
|
35
|
+
if (parsed.kind === "midpoint") return null;
|
|
36
|
+
return {
|
|
37
|
+
type: "select",
|
|
38
|
+
shapeId: parsed.shapeId,
|
|
39
|
+
vertex: parsed.kind === "vertex" ? parsed.index : null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A tap on a midpoint adds a vertex there; a tap on anything else is already handled by the press. */
|
|
43
|
+
function tapAction(current, drag, state, projection) {
|
|
44
|
+
if (drag.moved || current.kind !== "midpoint") return null;
|
|
45
|
+
const handle = editHandlesFor(state.shapes, state.selection, projection).find((candidate) => candidate.id === drag.id);
|
|
46
|
+
return handle ? {
|
|
47
|
+
type: "insertVertex",
|
|
48
|
+
shapeId: current.shapeId,
|
|
49
|
+
index: current.index,
|
|
50
|
+
at: handle.position
|
|
51
|
+
} : null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a drag step does. A midpoint becomes a new vertex under the pointer,
|
|
55
|
+
* which the rest of the drag then moves, so one drag is one undo step.
|
|
56
|
+
*/
|
|
57
|
+
function moveAction(current, drag, state) {
|
|
58
|
+
if (current.kind === "midpoint") {
|
|
59
|
+
current.kind = "vertex";
|
|
60
|
+
return {
|
|
61
|
+
type: "insertVertex",
|
|
62
|
+
shapeId: current.shapeId,
|
|
63
|
+
index: current.index,
|
|
64
|
+
at: drag.latlng,
|
|
65
|
+
coalesceKey: current.key
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (current.kind === "vertex") return {
|
|
69
|
+
type: "moveVertex",
|
|
70
|
+
shapeId: current.shapeId,
|
|
71
|
+
index: current.index,
|
|
72
|
+
to: drag.latlng,
|
|
73
|
+
coalesceKey: current.key
|
|
74
|
+
};
|
|
75
|
+
const middle = state.shapes.find((candidate) => candidate.id === current.shapeId)?.vertices[0];
|
|
76
|
+
return middle ? {
|
|
77
|
+
type: "setRadius",
|
|
78
|
+
shapeId: current.shapeId,
|
|
79
|
+
metres: distanceMetres(middle, drag.latlng),
|
|
80
|
+
coalesceKey: current.key
|
|
81
|
+
} : null;
|
|
82
|
+
}
|
|
83
|
+
function initialState(encoded, reducer) {
|
|
84
|
+
const shapes = encoded ? decodeShapes(encoded) : null;
|
|
85
|
+
return shapes ? reducer(initialDrawState, {
|
|
86
|
+
type: "load",
|
|
87
|
+
shapes
|
|
88
|
+
}) : initialDrawState;
|
|
89
|
+
}
|
|
90
|
+
/** The line for the toolbar: what is drawn or selected, or how many shapes there are. */
|
|
91
|
+
function statusText(format, draft, selected, count) {
|
|
92
|
+
if (draft) return format(message("tools.draw.status.drawing", {
|
|
93
|
+
label: draft.label,
|
|
94
|
+
count: draft.vertices.length
|
|
95
|
+
}));
|
|
96
|
+
if (selected) return selected.label;
|
|
97
|
+
return format(count > 0 ? message("tools.draw.status.shapes", { count }) : message("tools.draw.status.empty", {}));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The state of the Draw tool: the shapes, what is selected, undo, and every
|
|
101
|
+
* way to change them, by pointer and by keyboard.
|
|
102
|
+
*
|
|
103
|
+
* @remarks The pure rules live in core (`drawReducer` and friends). This hook
|
|
104
|
+
* adds what needs the map and the ports: the map centre and projection for
|
|
105
|
+
* "at map centre", nudges and shape picking; the announcer; the file saver
|
|
106
|
+
* and the clipboard for export; and the address for a link with shapes.
|
|
107
|
+
*
|
|
108
|
+
* Shapes belong to the app, not to the toolbar, so they stay on the map when
|
|
109
|
+
* the tool closes. Nothing is stored, and nothing reaches the address bar:
|
|
110
|
+
* shapes are read once, from a link that carries them, and written only into
|
|
111
|
+
* the link {@link UseDraw.copyLink} builds.
|
|
112
|
+
*
|
|
113
|
+
* Announcements follow the reducer's `lastEvent`, so a drag that moves a
|
|
114
|
+
* vertex many times is announced once, {@link DRAW_ANNOUNCE_DELAY_MS} after
|
|
115
|
+
* it settles, and a refusal is announced assertively.
|
|
116
|
+
*/
|
|
117
|
+
function useDraw({ units, active, getAdapter }) {
|
|
118
|
+
const announce = useAnnounce();
|
|
119
|
+
const announceRef = useLatestRef(announce);
|
|
120
|
+
const messages = useMessages();
|
|
121
|
+
const format = useFormatMessage();
|
|
122
|
+
const formatRef = useLatestRef(format);
|
|
123
|
+
const fileSaver = useFileSaver();
|
|
124
|
+
const clipboard = useClipboard();
|
|
125
|
+
const url = useUrlState();
|
|
126
|
+
const reducer = useMemo(() => createDrawReducer(messages), [messages]);
|
|
127
|
+
const [state, dispatch] = useReducer(reducer, void 0, () => initialState(url.read().shapes, reducer));
|
|
128
|
+
const stateRef = useLatestRef(state);
|
|
129
|
+
const getAdapterRef = useLatestRef(getAdapter);
|
|
130
|
+
const { projection } = useSettings().settings;
|
|
131
|
+
const projectionRef = useLatestRef(projection);
|
|
132
|
+
const activeRef = useLatestRef(active);
|
|
133
|
+
const [hoveredHandle, setHoveredHandle] = useState(null);
|
|
134
|
+
const [feedback, setFeedback] = useState(null);
|
|
135
|
+
const [importFeedback, setImportFeedback] = useState(null);
|
|
136
|
+
const fileOpener = useFileOpener();
|
|
137
|
+
const importAbort = useRef(null);
|
|
138
|
+
const [wktAxisOrder, setWktAxisOrder] = useState("lng-lat");
|
|
139
|
+
const wktAxisOrderRef = useLatestRef(wktAxisOrder);
|
|
140
|
+
const offeredText = useRef(null);
|
|
141
|
+
const session = useRef(null);
|
|
142
|
+
const dragCount = useRef(0);
|
|
143
|
+
const { shapes, selection, lastEvent } = state;
|
|
144
|
+
const draft = draftOf(state);
|
|
145
|
+
const selected = selectedShape(state);
|
|
146
|
+
const unitsRef = useLatestRef(units);
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
const text = announceDrawEvent(lastEvent, stateRef.current.shapes, unitsRef.current);
|
|
149
|
+
if (!text) return;
|
|
150
|
+
const delay = lastEvent?.type === "vertex-moved" ? 800 : 0;
|
|
151
|
+
const timer = setTimeout(() => {
|
|
152
|
+
announceRef.current(text, { priority: lastEvent?.type === "rejected" ? "assertive" : "polite" });
|
|
153
|
+
}, delay);
|
|
154
|
+
return () => clearTimeout(timer);
|
|
155
|
+
}, [
|
|
156
|
+
lastEvent,
|
|
157
|
+
stateRef,
|
|
158
|
+
unitsRef,
|
|
159
|
+
announceRef
|
|
160
|
+
]);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
setFeedback(null);
|
|
163
|
+
if (lastEvent?.type !== "imported") {
|
|
164
|
+
setImportFeedback(null);
|
|
165
|
+
offeredText.current = null;
|
|
166
|
+
}
|
|
167
|
+
}, [shapes]);
|
|
168
|
+
useEffect(() => () => importAbort.current?.abort(), []);
|
|
169
|
+
const act = useCallback((action) => dispatch(action), []);
|
|
170
|
+
const setMode = useCallback((kind) => act({
|
|
171
|
+
type: "setMode",
|
|
172
|
+
kind
|
|
173
|
+
}), [act]);
|
|
174
|
+
const undo = useCallback(() => act({ type: "undo" }), [act]);
|
|
175
|
+
const redo = useCallback(() => act({ type: "redo" }), [act]);
|
|
176
|
+
const finish = useCallback(() => act({ type: "finish" }), [act]);
|
|
177
|
+
const cancel = useCallback(() => act({ type: "cancel" }), [act]);
|
|
178
|
+
const clear = useCallback(() => act({ type: "clear" }), [act]);
|
|
179
|
+
const deselect = useCallback(() => act({ type: "deselect" }), [act]);
|
|
180
|
+
const select = useCallback((shapeId, vertex) => {
|
|
181
|
+
const shape = stateRef.current.shapes.find((candidate) => candidate.id === shapeId);
|
|
182
|
+
const centre = shape?.kind === "point" || shape?.kind === "circle" ? 0 : null;
|
|
183
|
+
act({
|
|
184
|
+
type: "select",
|
|
185
|
+
shapeId,
|
|
186
|
+
vertex: vertex === void 0 ? centre : vertex
|
|
187
|
+
});
|
|
188
|
+
}, [act, stateRef]);
|
|
189
|
+
const stepVertex = useCallback((delta) => act({
|
|
190
|
+
type: "stepVertex",
|
|
191
|
+
delta
|
|
192
|
+
}), [act]);
|
|
193
|
+
const deleteShape = useCallback((shapeId) => act({
|
|
194
|
+
type: "deleteShape",
|
|
195
|
+
shapeId
|
|
196
|
+
}), [act]);
|
|
197
|
+
const discardDraft = useCallback(() => {
|
|
198
|
+
if (draftOf(stateRef.current)) dispatch({ type: "cancel" });
|
|
199
|
+
}, [stateRef]);
|
|
200
|
+
const centre = useCallback(() => getAdapterRef.current()?.getView().center ?? null, [getAdapterRef]);
|
|
201
|
+
const moveSelectedTo = useCallback((at) => {
|
|
202
|
+
const { selection: current } = stateRef.current;
|
|
203
|
+
if (current && current.vertex !== null) dispatch({
|
|
204
|
+
type: "moveVertex",
|
|
205
|
+
shapeId: current.shapeId,
|
|
206
|
+
index: current.vertex,
|
|
207
|
+
to: at
|
|
208
|
+
});
|
|
209
|
+
}, [stateRef]);
|
|
210
|
+
const addPoint = useCallback((at) => dispatch({
|
|
211
|
+
type: "addVertex",
|
|
212
|
+
at
|
|
213
|
+
}), []);
|
|
214
|
+
const placeAtCentre = useCallback(() => {
|
|
215
|
+
const at = centre();
|
|
216
|
+
if (!at) return;
|
|
217
|
+
if (stateRef.current.selection?.vertex != null) moveSelectedTo(at);
|
|
218
|
+
else addPoint(at);
|
|
219
|
+
}, [
|
|
220
|
+
centre,
|
|
221
|
+
stateRef,
|
|
222
|
+
moveSelectedTo,
|
|
223
|
+
addPoint
|
|
224
|
+
]);
|
|
225
|
+
const nudge = useCallback((dx, dy) => {
|
|
226
|
+
const adapter = getAdapterRef.current();
|
|
227
|
+
const current = stateRef.current;
|
|
228
|
+
const shape = selectedShape(current);
|
|
229
|
+
const vertex = current.selection?.vertex ?? null;
|
|
230
|
+
const from = shape && vertex !== null ? shape.vertices[vertex] : void 0;
|
|
231
|
+
if (!adapter || !shape || vertex === null || !from) return;
|
|
232
|
+
const point = adapter.project(from);
|
|
233
|
+
dispatch({
|
|
234
|
+
type: "moveVertex",
|
|
235
|
+
shapeId: shape.id,
|
|
236
|
+
index: vertex,
|
|
237
|
+
to: adapter.unproject({
|
|
238
|
+
x: point.x + dx,
|
|
239
|
+
y: point.y + dy
|
|
240
|
+
}),
|
|
241
|
+
coalesceKey: `nudge:${shape.id}:${vertex}`
|
|
242
|
+
});
|
|
243
|
+
}, [getAdapterRef, stateRef]);
|
|
244
|
+
const removeVertex = useCallback(() => {
|
|
245
|
+
const current = stateRef.current.selection;
|
|
246
|
+
if (current && current.vertex !== null) dispatch({
|
|
247
|
+
type: "removeVertex",
|
|
248
|
+
shapeId: current.shapeId,
|
|
249
|
+
index: current.vertex
|
|
250
|
+
});
|
|
251
|
+
}, [stateRef]);
|
|
252
|
+
const insertAtCentre = useCallback(() => {
|
|
253
|
+
const at = centre();
|
|
254
|
+
const current = stateRef.current.selection;
|
|
255
|
+
if (at && current && current.vertex !== null) dispatch({
|
|
256
|
+
type: "insertVertex",
|
|
257
|
+
shapeId: current.shapeId,
|
|
258
|
+
index: current.vertex + 1,
|
|
259
|
+
at
|
|
260
|
+
});
|
|
261
|
+
}, [centre, stateRef]);
|
|
262
|
+
const deleteSelected = useCallback(() => {
|
|
263
|
+
const current = stateRef.current.selection;
|
|
264
|
+
if (current) dispatch({
|
|
265
|
+
type: "deleteShape",
|
|
266
|
+
shapeId: current.shapeId
|
|
267
|
+
});
|
|
268
|
+
}, [stateRef]);
|
|
269
|
+
const setRadius = useCallback((metres, key) => {
|
|
270
|
+
const shape = selectedShape(stateRef.current);
|
|
271
|
+
if (shape?.kind === "circle") dispatch({
|
|
272
|
+
type: "setRadius",
|
|
273
|
+
shapeId: shape.id,
|
|
274
|
+
metres,
|
|
275
|
+
...key === void 0 ? {} : { coalesceKey: key }
|
|
276
|
+
});
|
|
277
|
+
}, [stateRef]);
|
|
278
|
+
const setRadiusToCentre = useCallback(() => {
|
|
279
|
+
const shape = selectedShape(stateRef.current);
|
|
280
|
+
const at = centre();
|
|
281
|
+
const middle = shape?.vertices[0];
|
|
282
|
+
if (shape?.kind === "circle" && at && middle) setRadius(distanceMetres(middle, at));
|
|
283
|
+
}, [
|
|
284
|
+
centre,
|
|
285
|
+
setRadius,
|
|
286
|
+
stateRef
|
|
287
|
+
]);
|
|
288
|
+
const scaleRadius = useCallback((factor) => {
|
|
289
|
+
const shape = selectedShape(stateRef.current);
|
|
290
|
+
if (shape?.kind === "circle" && shape.radiusMetres !== void 0) setRadius(shape.radiusMetres * factor, "radius-scale");
|
|
291
|
+
}, [setRadius, stateRef]);
|
|
292
|
+
const onMapClick = useCallback((event) => {
|
|
293
|
+
if (!activeRef.current) return;
|
|
294
|
+
const adapter = getAdapterRef.current();
|
|
295
|
+
const current = stateRef.current;
|
|
296
|
+
if (adapter && !draftOf(current)) {
|
|
297
|
+
const hit = pickShape(current.shapes, event.point, overlayPlacement(adapter, adapter.getView(), projectionRef.current), SHAPE_PICK_TOLERANCE_PX, false);
|
|
298
|
+
if (hit) {
|
|
299
|
+
select(hit);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
dispatch({
|
|
304
|
+
type: "addVertex",
|
|
305
|
+
at: event.latlng
|
|
306
|
+
});
|
|
307
|
+
}, [
|
|
308
|
+
activeRef,
|
|
309
|
+
getAdapterRef,
|
|
310
|
+
stateRef,
|
|
311
|
+
select,
|
|
312
|
+
projectionRef
|
|
313
|
+
]);
|
|
314
|
+
const onHandleDrag = useCallback((drag) => {
|
|
315
|
+
if (drag.phase === "start") {
|
|
316
|
+
const parsed = parseHandleId(drag.id);
|
|
317
|
+
session.current = parsed ? {
|
|
318
|
+
shapeId: parsed.shapeId,
|
|
319
|
+
kind: parsed.kind,
|
|
320
|
+
index: parsed.index,
|
|
321
|
+
key: `drag:${++dragCount.current}`
|
|
322
|
+
} : null;
|
|
323
|
+
const action = parsed ? pressAction(parsed) : null;
|
|
324
|
+
if (action) dispatch(action);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const current = session.current;
|
|
328
|
+
if (!current) return;
|
|
329
|
+
if (drag.phase === "end") session.current = null;
|
|
330
|
+
const action = drag.phase === "end" ? tapAction(current, drag, stateRef.current, projectionRef.current) : moveAction(current, drag, stateRef.current);
|
|
331
|
+
if (action) dispatch(action);
|
|
332
|
+
}, [stateRef, projectionRef]);
|
|
333
|
+
const keyCommand = useCallback((event) => {
|
|
334
|
+
if (!activeRef.current) return false;
|
|
335
|
+
const command = drawKeyCommand(stateRef.current, event);
|
|
336
|
+
if (!command) return false;
|
|
337
|
+
if (command.type === "dispatch") dispatch(command.action);
|
|
338
|
+
else if (command.type === "nudge") nudge(command.dx, command.dy);
|
|
339
|
+
else placeAtCentre();
|
|
340
|
+
return true;
|
|
341
|
+
}, [
|
|
342
|
+
activeRef,
|
|
343
|
+
stateRef,
|
|
344
|
+
nudge,
|
|
345
|
+
placeAtCentre
|
|
346
|
+
]);
|
|
347
|
+
const report = useCallback((kind, said) => {
|
|
348
|
+
setFeedback({
|
|
349
|
+
kind,
|
|
350
|
+
text: formatRef.current(said)
|
|
351
|
+
});
|
|
352
|
+
announceRef.current(said, { priority: kind === "error" ? "assertive" : "polite" });
|
|
353
|
+
}, [announceRef, formatRef]);
|
|
354
|
+
const exportFile = useCallback(async (filename, mimeType, build) => {
|
|
355
|
+
const ready = exportableShapes(stateRef.current.shapes);
|
|
356
|
+
if (ready.length === 0) {
|
|
357
|
+
report("error", message("tools.draw.nothingToExport", {}));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if ((await fileSaver.save({
|
|
361
|
+
filename,
|
|
362
|
+
mimeType,
|
|
363
|
+
content: build(ready)
|
|
364
|
+
})).ok) report("success", message("tools.draw.saved", {
|
|
365
|
+
count: ready.length,
|
|
366
|
+
filename
|
|
367
|
+
}));
|
|
368
|
+
else report("error", message("tools.draw.saveFailed", {}));
|
|
369
|
+
}, [
|
|
370
|
+
fileSaver,
|
|
371
|
+
report,
|
|
372
|
+
stateRef
|
|
373
|
+
]);
|
|
374
|
+
const exportGeoJson = useCallback(() => exportFile(GEOJSON_FILENAME, "application/geo+json", shapesToGeoJsonText), [exportFile]);
|
|
375
|
+
const exportCsv = useCallback(() => exportFile(CSV_FILENAME, "text/csv;charset=utf-8", shapesToCsv), [exportFile]);
|
|
376
|
+
const exportWkt = useCallback(() => exportFile(WKT_FILENAME, "text/plain;charset=utf-8", shapesToWkt), [exportFile]);
|
|
377
|
+
const copyLink = useCallback(async () => {
|
|
378
|
+
const current = stateRef.current.shapes;
|
|
379
|
+
const encoded = encodeShapes(current);
|
|
380
|
+
const leftOut = unsharableShapes(current).length;
|
|
381
|
+
if (encoded === null) {
|
|
382
|
+
report("error", message("tools.draw.tooManyToShare", {}));
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (encoded === "") {
|
|
386
|
+
report("error", leftOut === 0 ? message("tools.draw.nothingToShare", {}) : message("tools.draw.nothingToCopy", { count: leftOut }));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (!(await clipboard.writeText(url.link({
|
|
390
|
+
...url.read(),
|
|
391
|
+
shapes: encoded
|
|
392
|
+
}))).ok) {
|
|
393
|
+
report("error", message("tools.draw.linkCopyFailed", {}));
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
report("success", leftOut === 0 ? message("tools.draw.linkCopied", {}) : message("tools.draw.linkCopiedLeftOut", { count: leftOut }));
|
|
397
|
+
}, [
|
|
398
|
+
clipboard,
|
|
399
|
+
report,
|
|
400
|
+
stateRef,
|
|
401
|
+
url
|
|
402
|
+
]);
|
|
403
|
+
const reportImport = useCallback((kind, said, readAs) => {
|
|
404
|
+
setImportFeedback({
|
|
405
|
+
kind,
|
|
406
|
+
text: formatRef.current(said),
|
|
407
|
+
...readAs ? { readAs } : {}
|
|
408
|
+
});
|
|
409
|
+
announceRef.current(said, { priority: kind === "error" ? "assertive" : "polite" });
|
|
410
|
+
}, [announceRef, formatRef]);
|
|
411
|
+
/** Adds what the text holds, read in `order`, or says why not; the box of the shapes it added. */
|
|
412
|
+
const importText = useCallback((text, order) => {
|
|
413
|
+
const suggested = suggestWktAxisOrder(text, order);
|
|
414
|
+
if (suggested) {
|
|
415
|
+
offeredText.current = text;
|
|
416
|
+
reportImport("error", describeAxisSuggestion(suggested), suggested);
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
offeredText.current = null;
|
|
420
|
+
const result = parseShapeFile(text, { wktAxisOrder: order });
|
|
421
|
+
const words = describeShapeImport(result);
|
|
422
|
+
if (!result.ok || result.shapes.length === 0) {
|
|
423
|
+
reportImport("error", words);
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
if (stateRef.current.shapes.length + result.shapes.length > MAX_DRAWING_SHAPES) {
|
|
427
|
+
reportImport("error", describeShapeImport({
|
|
428
|
+
ok: false,
|
|
429
|
+
refusal: "drawing-full"
|
|
430
|
+
}));
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
const total = exportableShapes(stateRef.current.shapes).length + result.shapes.length;
|
|
434
|
+
dispatch({
|
|
435
|
+
type: "import",
|
|
436
|
+
shapes: result.shapes
|
|
437
|
+
});
|
|
438
|
+
reportImport("success", total > MAX_SHARE_SHAPES ? message("common.followedBy", {
|
|
439
|
+
first: words,
|
|
440
|
+
second: LINK_LIMIT_NOTE
|
|
441
|
+
}) : words);
|
|
442
|
+
return shapeInputBounds(result.shapes) ?? null;
|
|
443
|
+
}, [reportImport, stateRef]);
|
|
444
|
+
/** A choice made by hand: the offer to read a file the other way no longer applies, so it and the file it kept are dropped. */
|
|
445
|
+
const chooseWktAxisOrder = useCallback((order) => {
|
|
446
|
+
setWktAxisOrder(order);
|
|
447
|
+
offeredText.current = null;
|
|
448
|
+
setImportFeedback((current) => current?.readAs ? null : current);
|
|
449
|
+
}, []);
|
|
450
|
+
const rereadImport = useCallback((order) => {
|
|
451
|
+
setWktAxisOrder(order);
|
|
452
|
+
return offeredText.current === null ? null : importText(offeredText.current, order);
|
|
453
|
+
}, [importText]);
|
|
454
|
+
const importFile = useCallback(async () => {
|
|
455
|
+
if (!fileOpener) return null;
|
|
456
|
+
importAbort.current?.abort();
|
|
457
|
+
const controller = new AbortController();
|
|
458
|
+
importAbort.current = controller;
|
|
459
|
+
let text;
|
|
460
|
+
try {
|
|
461
|
+
({text} = await fileOpener.open({
|
|
462
|
+
accept: SHAPE_FILE_TYPES,
|
|
463
|
+
maxBytes: MAX_IMPORT_BYTES,
|
|
464
|
+
signal: controller.signal
|
|
465
|
+
}));
|
|
466
|
+
} catch (error) {
|
|
467
|
+
const kind = error instanceof FileOpenError ? error.kind : "unreadable";
|
|
468
|
+
if (kind !== "cancelled") {
|
|
469
|
+
offeredText.current = null;
|
|
470
|
+
reportImport("error", FILE_OPEN_MESSAGES[kind]);
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
return importText(text, wktAxisOrderRef.current);
|
|
475
|
+
}, [
|
|
476
|
+
fileOpener,
|
|
477
|
+
importText,
|
|
478
|
+
reportImport,
|
|
479
|
+
wktAxisOrderRef
|
|
480
|
+
]);
|
|
481
|
+
const handles = useMemo(() => active ? editHandlesFor(shapes, selection, projection) : [], [
|
|
482
|
+
active,
|
|
483
|
+
shapes,
|
|
484
|
+
selection,
|
|
485
|
+
projection
|
|
486
|
+
]);
|
|
487
|
+
const issue = useMemo(() => selected?.done ? validateShape(selected) : null, [selected]);
|
|
488
|
+
const focus = draft ?? selected;
|
|
489
|
+
const status = statusText(format, draft, selected, shapes.length);
|
|
490
|
+
return {
|
|
491
|
+
state,
|
|
492
|
+
shapes,
|
|
493
|
+
mode: state.mode,
|
|
494
|
+
selection,
|
|
495
|
+
draft,
|
|
496
|
+
selected,
|
|
497
|
+
status,
|
|
498
|
+
measure: focus ? formatShapeMeasure(focus, units, messages) : "",
|
|
499
|
+
issue,
|
|
500
|
+
issueMessage: issue ? formatRef.current(DRAW_ISSUE_MESSAGES[issue]) : "",
|
|
501
|
+
canUndo: state.past.length > 0,
|
|
502
|
+
canRedo: state.future.length > 0,
|
|
503
|
+
handles,
|
|
504
|
+
hoveredHandle,
|
|
505
|
+
feedback,
|
|
506
|
+
importFeedback,
|
|
507
|
+
setMode,
|
|
508
|
+
addPoint,
|
|
509
|
+
placeAtCentre,
|
|
510
|
+
moveSelectedTo,
|
|
511
|
+
nudge,
|
|
512
|
+
undo,
|
|
513
|
+
redo,
|
|
514
|
+
finish,
|
|
515
|
+
cancel,
|
|
516
|
+
discardDraft,
|
|
517
|
+
select,
|
|
518
|
+
deselect,
|
|
519
|
+
stepVertex,
|
|
520
|
+
removeVertex,
|
|
521
|
+
insertAtCentre,
|
|
522
|
+
deleteSelected,
|
|
523
|
+
deleteShape,
|
|
524
|
+
clear,
|
|
525
|
+
setRadiusToCentre,
|
|
526
|
+
scaleRadius,
|
|
527
|
+
onMapClick,
|
|
528
|
+
onHandleDrag,
|
|
529
|
+
onHandleHover: setHoveredHandle,
|
|
530
|
+
keyCommand,
|
|
531
|
+
exportGeoJson,
|
|
532
|
+
exportCsv,
|
|
533
|
+
exportWkt,
|
|
534
|
+
copyLink,
|
|
535
|
+
importFile,
|
|
536
|
+
wktAxisOrder,
|
|
537
|
+
setWktAxisOrder: chooseWktAxisOrder,
|
|
538
|
+
rereadImport
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
export { DRAW_ANNOUNCE_DELAY_MS, useDraw };
|
|
542
|
+
|
|
543
|
+
//# sourceMappingURL=useDraw.js.map
|