@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,131 @@
|
|
|
1
|
+
import { useChromeLayout } from "../chrome/layoutContext.js";
|
|
2
|
+
import { useFormatMessage, useMessages } from "../services/hooks.js";
|
|
3
|
+
import { Icon } from "../ui/Icon/Icon.js";
|
|
4
|
+
import { Surface } from "../ui/Surface/Surface.js";
|
|
5
|
+
import { VisuallyHidden } from "../ui/VisuallyHidden/VisuallyHidden.js";
|
|
6
|
+
import { LegendGlyph } from "./FeatureGlyph.js";
|
|
7
|
+
import { LayerKey } from "./LayerKey.js";
|
|
8
|
+
import { block, blocks, body, chipText, header, heading, layerName, panel, strip, toggle, when } from "./MapKey.styles.js";
|
|
9
|
+
import { mapKeyBlocks } from "./mapKeyBlocks.js";
|
|
10
|
+
import { useScrolls } from "./useScrolls.js";
|
|
11
|
+
import { DEFAULT_MARKER_RADIUS, isCompactViewport } from "@mapcairn/core";
|
|
12
|
+
import { ChevronDown, ChevronUp } from "lucide-react";
|
|
13
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
// src/layers/MapKey.tsx
|
|
16
|
+
/** How many layers' glyphs the minimised chip shows; the count says the rest. */
|
|
17
|
+
var STRIP_LIMIT = 3;
|
|
18
|
+
/** The first row of each block's key, as a strip of small glyphs. */
|
|
19
|
+
function GlyphStrip({ blocks }) {
|
|
20
|
+
return /* @__PURE__ */ jsx("span", {
|
|
21
|
+
className: strip,
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
children: blocks.slice(0, STRIP_LIMIT).map(({ id, entries }) => /* @__PURE__ */ jsx(LegendGlyph, { entry: {
|
|
24
|
+
...entries[0],
|
|
25
|
+
radius: Math.min(entries[0].radius, DEFAULT_MARKER_RADIUS)
|
|
26
|
+
} }, id))
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The key to the layers that are on, for the map itself: a panel named "Map
|
|
31
|
+
* key" with one block for each layer that has a key, so a person can read
|
|
32
|
+
* what the colours and shapes mean without opening the Layers section. It
|
|
33
|
+
* draws the same rows the section does ({@link LayerKey}). It minimises to a
|
|
34
|
+
* chip that shows a strip of glyphs and how many layers it covers, and renders
|
|
35
|
+
* nothing while no layer that is on has a key.
|
|
36
|
+
*
|
|
37
|
+
* @remarks Put it in `MapChrome`'s `mapKey` slot, which keeps it clear of the
|
|
38
|
+
* other floating elements and caps its height. The minimised state is held
|
|
39
|
+
* in memory, so it lasts for the visit but not a reload. The button's name
|
|
40
|
+
* is "Key, 3 layers" open and minimised, and `aria-expanded` says which.
|
|
41
|
+
*/
|
|
42
|
+
function MapKey({ layers, defaultMinimised }) {
|
|
43
|
+
const headingId = useId();
|
|
44
|
+
const bodyId = useId();
|
|
45
|
+
const { viewport } = useChromeLayout();
|
|
46
|
+
const format = useFormatMessage();
|
|
47
|
+
const messages = useMessages();
|
|
48
|
+
const { t } = messages;
|
|
49
|
+
const [chosen, setChosen] = useState(null);
|
|
50
|
+
const [decided, setDecided] = useState(null);
|
|
51
|
+
const bodyRef = useRef(null);
|
|
52
|
+
const blocks$1 = mapKeyBlocks(layers.layers, messages);
|
|
53
|
+
const hasBlocks = blocks$1.length > 0;
|
|
54
|
+
const startsMinimised = defaultMinimised ?? isCompactViewport(viewport);
|
|
55
|
+
const canDecide = defaultMinimised !== void 0 || viewport.width > 0;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (hasBlocks && canDecide) setDecided((current) => current ?? startsMinimised);
|
|
58
|
+
}, [
|
|
59
|
+
hasBlocks,
|
|
60
|
+
canDecide,
|
|
61
|
+
startsMinimised
|
|
62
|
+
]);
|
|
63
|
+
const minimised = chosen ?? decided ?? startsMinimised;
|
|
64
|
+
const scrolls = useScrolls(bodyRef, !minimised && hasBlocks);
|
|
65
|
+
if (!hasBlocks) return null;
|
|
66
|
+
return /* @__PURE__ */ jsxs(Surface, {
|
|
67
|
+
as: "section",
|
|
68
|
+
radius: minimised ? "pill" : "control",
|
|
69
|
+
"aria-labelledby": headingId,
|
|
70
|
+
className: panel,
|
|
71
|
+
"data-minimised": minimised,
|
|
72
|
+
"data-testid": "map-key",
|
|
73
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: header,
|
|
75
|
+
children: [minimised ? /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
76
|
+
as: "h2",
|
|
77
|
+
id: headingId,
|
|
78
|
+
children: t("layers.key.title", {})
|
|
79
|
+
}) : /* @__PURE__ */ jsx("h2", {
|
|
80
|
+
id: headingId,
|
|
81
|
+
className: heading,
|
|
82
|
+
children: t("layers.key.title", {})
|
|
83
|
+
}), /* @__PURE__ */ jsxs("button", {
|
|
84
|
+
type: "button",
|
|
85
|
+
className: toggle,
|
|
86
|
+
"aria-expanded": !minimised,
|
|
87
|
+
"aria-controls": minimised ? void 0 : bodyId,
|
|
88
|
+
"aria-label": messages.plural("layers.key.toggle", { count: blocks$1.length }),
|
|
89
|
+
"data-testid": "map-key-toggle",
|
|
90
|
+
onClick: () => setChosen(!minimised),
|
|
91
|
+
children: [minimised ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(GlyphStrip, { blocks: blocks$1 }), /* @__PURE__ */ jsx("span", {
|
|
92
|
+
className: chipText,
|
|
93
|
+
children: messages.plural("layers.key.chip", { count: blocks$1.length })
|
|
94
|
+
})] }) : null, /* @__PURE__ */ jsx(Icon, { icon: minimised ? ChevronUp : ChevronDown })]
|
|
95
|
+
})]
|
|
96
|
+
}), minimised ? null : /* @__PURE__ */ jsx("section", {
|
|
97
|
+
ref: bodyRef,
|
|
98
|
+
id: bodyId,
|
|
99
|
+
className: body,
|
|
100
|
+
"aria-label": scrolls ? t("layers.key.scrolling", {}) : void 0,
|
|
101
|
+
tabIndex: scrolls ? 0 : void 0,
|
|
102
|
+
"data-testid": "map-key-body",
|
|
103
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
104
|
+
className: blocks,
|
|
105
|
+
children: blocks$1.map((block$1) => /* @__PURE__ */ jsxs("div", {
|
|
106
|
+
className: block,
|
|
107
|
+
"data-testid": `map-key-${block$1.id}`,
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ jsx("h3", {
|
|
110
|
+
className: layerName,
|
|
111
|
+
children: block$1.name
|
|
112
|
+
}),
|
|
113
|
+
block$1.chosenTime ? /* @__PURE__ */ jsx("p", {
|
|
114
|
+
className: when,
|
|
115
|
+
children: t("layers.key.showing", { time: format(block$1.chosenTime) })
|
|
116
|
+
}) : null,
|
|
117
|
+
/* @__PURE__ */ jsx(LayerKey, {
|
|
118
|
+
definition: block$1.definition,
|
|
119
|
+
label: t("layers.key.nameKey", { name: block$1.name }),
|
|
120
|
+
testId: `map-key-list-${block$1.id}`,
|
|
121
|
+
layout: "stacked"
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
}, block$1.id))
|
|
125
|
+
})
|
|
126
|
+
})]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export { MapKey };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=MapKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapKey.js","names":["styles.strip","blocks","styles.panel","styles.header","styles.heading","styles.toggle","_Fragment","styles.chipText","styles.body","styles.blocks","styles.block","block","styles.layerName","styles.when"],"sources":["../../src/layers/MapKey.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { DEFAULT_MARKER_RADIUS, isCompactViewport } from \"@mapcairn/core\";\nimport { ChevronDown, ChevronUp } from \"lucide-react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport { useChromeLayout } from \"../chrome/layoutContext\";\nimport { useFormatMessage, useMessages } from \"../services\";\nimport { Icon } from \"../ui/Icon\";\nimport { Surface } from \"../ui/Surface\";\nimport { VisuallyHidden } from \"../ui/VisuallyHidden\";\nimport { LegendGlyph } from \"./FeatureGlyph\";\nimport { LayerKey } from \"./LayerKey\";\nimport * as styles from \"./MapKey.css\";\nimport { type MapKeyBlock, mapKeyBlocks } from \"./mapKeyBlocks\";\nimport type { DataLayers } from \"./useDataLayers\";\nimport { useScrolls } from \"./useScrolls\";\n\n/** How many layers' glyphs the minimised chip shows; the count says the rest. */\nconst STRIP_LIMIT = 3;\n\n/** Props for {@link MapKey}. */\nexport interface MapKeyProps {\n readonly layers: DataLayers;\n /**\n * Whether the key starts minimised. Left out, a phone in either orientation\n * starts it minimised (the viewport is narrower than the bottom sheet's\n * width or shorter than the side panel's height threshold) and a larger\n * screen starts it open. It is decided when the key first appears, so\n * turning the phone does not change it, and the person's own choice\n * replaces it from then on.\n */\n readonly defaultMinimised?: boolean;\n}\n\n/** The first row of each block's key, as a strip of small glyphs. */\nfunction GlyphStrip({ blocks }: { readonly blocks: readonly MapKeyBlock[] }) {\n return (\n <span className={styles.strip} aria-hidden=\"true\">\n {blocks.slice(0, STRIP_LIMIT).map(({ id, entries }) => (\n <LegendGlyph\n key={id}\n entry={{\n ...entries[0],\n radius: Math.min(entries[0].radius, DEFAULT_MARKER_RADIUS),\n }}\n />\n ))}\n </span>\n );\n}\n\n/**\n * The key to the layers that are on, for the map itself: a panel named \"Map\n * key\" with one block for each layer that has a key, so a person can read\n * what the colours and shapes mean without opening the Layers section. It\n * draws the same rows the section does ({@link LayerKey}). It minimises to a\n * chip that shows a strip of glyphs and how many layers it covers, and renders\n * nothing while no layer that is on has a key.\n *\n * @remarks Put it in `MapChrome`'s `mapKey` slot, which keeps it clear of the\n * other floating elements and caps its height. The minimised state is held\n * in memory, so it lasts for the visit but not a reload. The button's name\n * is \"Key, 3 layers\" open and minimised, and `aria-expanded` says which.\n */\nexport function MapKey({ layers, defaultMinimised }: MapKeyProps) {\n const headingId = useId();\n const bodyId = useId();\n const { viewport } = useChromeLayout();\n const format = useFormatMessage();\n const messages = useMessages();\n const { t } = messages;\n const [chosen, setChosen] = useState<boolean | null>(null);\n const [decided, setDecided] = useState<boolean | null>(null);\n const bodyRef = useRef<HTMLElement>(null);\n const blocks = mapKeyBlocks(layers.layers, messages);\n const hasBlocks = blocks.length > 0;\n const startsMinimised = defaultMinimised ?? isCompactViewport(viewport);\n // Before the chrome has measured, its viewport is empty and the default\n // would be a guess, so wait for it unless the host has decided.\n const canDecide = defaultMinimised !== undefined || viewport.width > 0;\n // The start state is decided once, when the key first appears, so turning a\n // phone to landscape (which is the side panel layout) does not change it.\n useEffect(() => {\n if (hasBlocks && canDecide) {\n setDecided((current) => current ?? startsMinimised);\n }\n }, [hasBlocks, canDecide, startsMinimised]);\n const minimised = chosen ?? decided ?? startsMinimised;\n // A box that scrolls needs a tab stop, or a keyboard cannot scroll it.\n const scrolls = useScrolls(bodyRef, !minimised && hasBlocks);\n if (!hasBlocks) {\n return null;\n }\n return (\n <Surface\n as=\"section\"\n radius={minimised ? \"pill\" : \"control\"}\n aria-labelledby={headingId}\n className={styles.panel}\n data-minimised={minimised}\n data-testid=\"map-key\"\n >\n <div className={styles.header}>\n {minimised ? (\n <VisuallyHidden as=\"h2\" id={headingId}>\n {t(\"layers.key.title\", {})}\n </VisuallyHidden>\n ) : (\n <h2 id={headingId} className={styles.heading}>\n {t(\"layers.key.title\", {})}\n </h2>\n )}\n <button\n type=\"button\"\n className={styles.toggle}\n aria-expanded={!minimised}\n aria-controls={minimised ? undefined : bodyId}\n aria-label={messages.plural(\"layers.key.toggle\", {\n count: blocks.length,\n })}\n data-testid=\"map-key-toggle\"\n onClick={() => setChosen(!minimised)}\n >\n {minimised ? (\n <>\n <GlyphStrip blocks={blocks} />\n <span className={styles.chipText}>\n {messages.plural(\"layers.key.chip\", { count: blocks.length })}\n </span>\n </>\n ) : null}\n <Icon icon={minimised ? ChevronUp : ChevronDown} />\n </button>\n </div>\n {minimised ? null : (\n <section\n ref={bodyRef}\n id={bodyId}\n className={styles.body}\n aria-label={scrolls ? t(\"layers.key.scrolling\", {}) : undefined}\n tabIndex={scrolls ? 0 : undefined}\n data-testid=\"map-key-body\"\n >\n <div className={styles.blocks}>\n {blocks.map((block) => (\n <div\n key={block.id}\n className={styles.block}\n data-testid={`map-key-${block.id}`}\n >\n <h3 className={styles.layerName}>{block.name}</h3>\n {block.chosenTime ? (\n <p className={styles.when}>\n {t(\"layers.key.showing\", {\n time: format(block.chosenTime),\n })}\n </p>\n ) : null}\n <LayerKey\n definition={block.definition}\n label={t(\"layers.key.nameKey\", { name: block.name })}\n testId={`map-key-list-${block.id}`}\n layout=\"stacked\"\n />\n </div>\n ))}\n </div>\n </section>\n )}\n </Surface>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAM,cAAc;;AAiBpB,SAAS,WAAW,EAAE,UAAuD;CAC3E,OACE,oBAAC,QAAD;EAAM,WAAWA;EAAc,eAAY;EACxC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AAA,QAAM,EAkBR,CACN;GACE,CAAA;EACE,CAAA,CAEJ;;AAEb"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
// src/layers/MapKey.css.ts
|
|
3
|
+
var panel = "_19exqy50";
|
|
4
|
+
var header = "_19exqy51";
|
|
5
|
+
var heading = "_19exqy52";
|
|
6
|
+
var toggle = "_19exqy53";
|
|
7
|
+
var strip = "_19exqy54";
|
|
8
|
+
var chipText = "_19exqy55";
|
|
9
|
+
var body = "_19exqy56";
|
|
10
|
+
var blocks = "_19exqy57";
|
|
11
|
+
var block = "_19exqy58";
|
|
12
|
+
var layerName = "_19exqy59";
|
|
13
|
+
var when = "_19exqy5a";
|
|
14
|
+
export { block, blocks, body, chipText, header, heading, layerName, panel, strip, toggle, when };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=MapKey.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapKey.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { glyph } from "./Layers.styles.js";
|
|
2
|
+
import { paletteColour } from "./mapFeatures.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { tokenValues } from "@mapcairn/theme";
|
|
5
|
+
// src/layers/MarkerGlyph.tsx
|
|
6
|
+
var { edge, halo, edgeWidth, haloWidth } = tokenValues.dataMarker;
|
|
7
|
+
/** How far a shape's corners reach past its radius. */
|
|
8
|
+
var SHAPE_REACH = 1.15;
|
|
9
|
+
/** The SVG for a shape of radius `r` centred on the origin. */
|
|
10
|
+
function ShapePath({ shape, r }) {
|
|
11
|
+
switch (shape) {
|
|
12
|
+
case "circle": return /* @__PURE__ */ jsx("circle", { r });
|
|
13
|
+
case "square": {
|
|
14
|
+
const half = r * .86;
|
|
15
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
16
|
+
x: -half,
|
|
17
|
+
y: -half,
|
|
18
|
+
width: half * 2,
|
|
19
|
+
height: half * 2
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
case "diamond": {
|
|
23
|
+
const d = r * 1.13;
|
|
24
|
+
return /* @__PURE__ */ jsx("polygon", { points: `0,${-d} ${d},0 0,${d} ${-d},0` });
|
|
25
|
+
}
|
|
26
|
+
case "triangle": {
|
|
27
|
+
const side = r * 1.1;
|
|
28
|
+
const top = -side * (2 / Math.sqrt(3)) + r * .15;
|
|
29
|
+
const base = side / Math.sqrt(3) + r * .15;
|
|
30
|
+
return /* @__PURE__ */ jsx("polygon", { points: `0,${top} ${side},${base} ${-side},${base}` });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The marker a layer draws for a feature, as a small picture for the legend,
|
|
36
|
+
* the list and the card, so words and map look the same: the fill over a
|
|
37
|
+
* dark edge over a white halo, which shows on a light surface (the edge) and
|
|
38
|
+
* a dark one (the halo) alike. Decorative: the words beside it carry the
|
|
39
|
+
* meaning. Colours are SVG attributes, not styles, so they need nothing from
|
|
40
|
+
* the Content-Security-Policy.
|
|
41
|
+
*/
|
|
42
|
+
function MarkerGlyph({ shape, colour, radius }) {
|
|
43
|
+
const extent = Math.ceil(radius * SHAPE_REACH + edgeWidth + haloWidth);
|
|
44
|
+
const size = extent * 2;
|
|
45
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
46
|
+
className: glyph,
|
|
47
|
+
width: size,
|
|
48
|
+
height: size,
|
|
49
|
+
viewBox: `${-extent} ${-extent} ${size} ${size}`,
|
|
50
|
+
"aria-hidden": "true",
|
|
51
|
+
focusable: "false",
|
|
52
|
+
strokeLinejoin: "round",
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ jsx("g", {
|
|
55
|
+
fill: halo,
|
|
56
|
+
stroke: halo,
|
|
57
|
+
strokeWidth: 2 * (edgeWidth + haloWidth),
|
|
58
|
+
children: /* @__PURE__ */ jsx(ShapePath, {
|
|
59
|
+
shape,
|
|
60
|
+
r: radius
|
|
61
|
+
})
|
|
62
|
+
}),
|
|
63
|
+
/* @__PURE__ */ jsx("g", {
|
|
64
|
+
fill: edge,
|
|
65
|
+
stroke: edge,
|
|
66
|
+
strokeWidth: 2 * edgeWidth,
|
|
67
|
+
children: /* @__PURE__ */ jsx(ShapePath, {
|
|
68
|
+
shape,
|
|
69
|
+
r: radius
|
|
70
|
+
})
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx("g", {
|
|
73
|
+
fill: paletteColour(colour),
|
|
74
|
+
children: /* @__PURE__ */ jsx(ShapePath, {
|
|
75
|
+
shape,
|
|
76
|
+
r: radius
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export { MarkerGlyph };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=MarkerGlyph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkerGlyph.js","names":["styles.glyph"],"sources":["../../src/layers/MarkerGlyph.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { MarkerShape, PaletteSlot } from \"@mapcairn/core\";\nimport { tokenValues } from \"@mapcairn/theme\";\nimport * as styles from \"./Layers.css\";\nimport { paletteColour } from \"./mapFeatures\";\n\nconst { edge, halo, edgeWidth, haloWidth } = tokenValues.dataMarker;\n\n/** How far a shape's corners reach past its radius. */\nconst SHAPE_REACH = 1.15;\n\n/** Props for {@link MarkerGlyph}. */\nexport interface MarkerGlyphProps {\n readonly shape: MarkerShape;\n readonly colour: PaletteSlot;\n /** The radius the map draws it at, in CSS pixels. */\n readonly radius: number;\n}\n\n/** The SVG for a shape of radius `r` centred on the origin. */\nfunction ShapePath({ shape, r }: { shape: MarkerShape; r: number }) {\n switch (shape) {\n case \"circle\":\n return <circle r={r} />;\n case \"square\": {\n const half = r * 0.86;\n return <rect x={-half} y={-half} width={half * 2} height={half * 2} />;\n }\n case \"diamond\": {\n const d = r * 1.13;\n return <polygon points={`0,${-d} ${d},0 0,${d} ${-d},0`} />;\n }\n case \"triangle\": {\n const side = r * 1.1;\n const top = -side * (2 / Math.sqrt(3)) + r * 0.15;\n const base = side / Math.sqrt(3) + r * 0.15;\n return <polygon points={`0,${top} ${side},${base} ${-side},${base}`} />;\n }\n }\n}\n\n/**\n * The marker a layer draws for a feature, as a small picture for the legend,\n * the list and the card, so words and map look the same: the fill over a\n * dark edge over a white halo, which shows on a light surface (the edge) and\n * a dark one (the halo) alike. Decorative: the words beside it carry the\n * meaning. Colours are SVG attributes, not styles, so they need nothing from\n * the Content-Security-Policy.\n */\nexport function MarkerGlyph({ shape, colour, radius }: MarkerGlyphProps) {\n // A diamond's and a triangle's corners reach past the radius.\n const extent = Math.ceil(radius * SHAPE_REACH + edgeWidth + haloWidth);\n const size = extent * 2;\n return (\n <svg\n className={styles.glyph}\n width={size}\n height={size}\n viewBox={`${-extent} ${-extent} ${size} ${size}`}\n aria-hidden=\"true\"\n focusable=\"false\"\n strokeLinejoin=\"round\"\n >\n <g fill={halo} stroke={halo} strokeWidth={2 * (edgeWidth + haloWidth)}>\n <ShapePath shape={shape} r={radius} />\n </g>\n <g fill={edge} stroke={edge} strokeWidth={2 * edgeWidth}>\n <ShapePath shape={shape} r={radius} />\n </g>\n <g fill={paletteColour(colour)}>\n <ShapePath shape={shape} r={radius} />\n </g>\n </svg>\n );\n}\n"],"mappings":";;;;;AAOA,IAAM,EAAE,MAAM,MAAM,WAAW,cAAc,YAAY;;AAGzD,IAAM,cAAc;;AAWpB,SAAS,UAAU,EAAE,OAAO,KAAwC;CAClE,QAAQ,OAAR;EACE,KAAK,UACH,OAAO,oBAAC,UAAD,EAAW,EAAI,CAAA;EACxB,KAAK,UAAU;GACb,MAAM,OAAO,IAAI;GACjB,OAAO,oBAAC,QAAD;IAAM,GAAG,CAAC;IAAM,GAAG,CAAC;IAAM,OAAO,OA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, useContext } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/layers/SelectionProvider.tsx
|
|
4
|
+
var SelectionContext = createContext(void 0);
|
|
5
|
+
/**
|
|
6
|
+
* Hands the selected set down to the components that show or change it, so
|
|
7
|
+
* none needs a prop for it. Put it where the host calls `useFeatureSelection`,
|
|
8
|
+
* around the map and the sheet. With `selection` null it provides nothing, so
|
|
9
|
+
* a host with no store passes the hook's result as it is.
|
|
10
|
+
*/
|
|
11
|
+
function SelectionProvider({ selection, children }) {
|
|
12
|
+
return /* @__PURE__ */ jsx(SelectionContext.Provider, {
|
|
13
|
+
value: selection ?? void 0,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The selected set, or undefined outside a {@link SelectionProvider} or when
|
|
19
|
+
* the host offers no selection. A component that selects or lists features
|
|
20
|
+
* renders nothing then.
|
|
21
|
+
*/
|
|
22
|
+
function useSelection() {
|
|
23
|
+
return useContext(SelectionContext);
|
|
24
|
+
}
|
|
25
|
+
export { SelectionProvider, useSelection };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=SelectionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionProvider.js","names":[],"sources":["../../src/layers/SelectionProvider.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { createContext, type ReactNode, useContext } from \"react\";\nimport type { FeatureSelectionState } from \"./useFeatureSelection\";\n\nconst SelectionContext = createContext<FeatureSelectionState | undefined>(\n undefined,\n);\n\n/** Props for {@link SelectionProvider}. */\nexport interface SelectionProviderProps {\n /** What {@link useFeatureSelection} returned: null when the host has no store. */\n readonly selection: FeatureSelectionState | null;\n readonly children?: ReactNode;\n}\n\n/**\n * Hands the selected set down to the components that show or change it, so\n * none needs a prop for it. Put it where the host calls `useFeatureSelection`,\n * around the map and the sheet. With `selection` null it provides nothing, so\n * a host with no store passes the hook's result as it is.\n */\nexport function SelectionProvider({\n selection,\n children,\n}: SelectionProviderProps) {\n return (\n <SelectionContext.Provider value={selection ?? undefined}>\n {children}\n </SelectionContext.Provider>\n );\n}\n\n/**\n * The selected set, or undefined outside a {@link SelectionProvider} or when\n * the host offers no selection. A component that selects or lists features\n * renders nothing then.\n */\nexport function useSelection(): FeatureSelectionState | undefined {\n return useContext(SelectionContext);\n}\n"],"mappings":";;;AAKA,IAAM,mBAAmB,cACvB,KAAA,CACF;;;;;;;AAeA,SAAgB,kBAAkB,EAChC,WACA,YACyB;CACzB,OACE,oBAAC,iBAAiB,UAAlB;EAA2B,OAAO,aAAa,KAAA;EAC5C;CACwB,CAAA;AAE/B;;;;;;AAOA,SAAgB,eAAkD;CAChE,OAAO,WAAW,gBAAgB;AACpC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { glyph } from "./Layers.styles.js";
|
|
2
|
+
import { paletteColour } from "./mapFeatures.js";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { tokenValues } from "@mapcairn/theme";
|
|
6
|
+
// src/layers/ShapeGlyph.tsx
|
|
7
|
+
var { edge, halo } = tokenValues.dataMarker;
|
|
8
|
+
var WIDTH = 28;
|
|
9
|
+
var HEIGHT = 16;
|
|
10
|
+
/** The widest stroke the swatch can show; wider strokes are drawn at this width. */
|
|
11
|
+
var MAX_STROKE = 6;
|
|
12
|
+
/** Opacity of an area swatch's fill, close to the map's own fill so the key looks like the map. */
|
|
13
|
+
var AREA_FILL_OPACITY = .7;
|
|
14
|
+
/** The dash array of a line style, in swatch pixels. */
|
|
15
|
+
var DASH_ARRAY = {
|
|
16
|
+
solid: void 0,
|
|
17
|
+
dashed: "4 3",
|
|
18
|
+
dotted: "1 3"
|
|
19
|
+
};
|
|
20
|
+
/** The marks of one hatching pattern, in a 6 pixel cell. */
|
|
21
|
+
function PatternMarks({ pattern }) {
|
|
22
|
+
switch (pattern) {
|
|
23
|
+
case "stripes": return /* @__PURE__ */ jsx("path", {
|
|
24
|
+
d: "M-1,1 L1,-1 M0,6 L6,0 M5,7 L7,5",
|
|
25
|
+
stroke: edge,
|
|
26
|
+
strokeWidth: 1
|
|
27
|
+
});
|
|
28
|
+
case "crosshatch": return /* @__PURE__ */ jsx("path", {
|
|
29
|
+
d: "M-1,1 L1,-1 M0,6 L6,0 M5,7 L7,5 M-1,5 L1,7 M0,0 L6,6 M5,-1 L7,1",
|
|
30
|
+
stroke: edge,
|
|
31
|
+
strokeWidth: .8
|
|
32
|
+
});
|
|
33
|
+
case "dots": return /* @__PURE__ */ jsx("circle", {
|
|
34
|
+
cx: 3,
|
|
35
|
+
cy: 3,
|
|
36
|
+
r: 1.1,
|
|
37
|
+
fill: edge
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What a polygon or line looks like on the map, as a small picture for the
|
|
43
|
+
* legend, the list and the card, so the words and the map agree: the fill
|
|
44
|
+
* over its hatching and ink outline, or the coloured line over a white
|
|
45
|
+
* casing. Decorative: the words beside it carry the meaning. Colours are SVG
|
|
46
|
+
* attributes, not styles, so they need nothing from the
|
|
47
|
+
* Content-Security-Policy.
|
|
48
|
+
*/
|
|
49
|
+
function ShapeGlyph({ swatch, colour, pattern = "solid", dash = "solid", width }) {
|
|
50
|
+
const patternId = `mapcairn-hatch-${useId().replaceAll(":", "")}`;
|
|
51
|
+
const fill = paletteColour(colour);
|
|
52
|
+
const stroke = Math.min(width ?? (swatch === "area" ? 1.5 : 3), MAX_STROKE);
|
|
53
|
+
const dashArray = DASH_ARRAY[dash];
|
|
54
|
+
const hatched = swatch === "area" && pattern !== "solid";
|
|
55
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
56
|
+
className: glyph,
|
|
57
|
+
width: WIDTH,
|
|
58
|
+
height: HEIGHT,
|
|
59
|
+
viewBox: `0 0 ${WIDTH} ${HEIGHT}`,
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
focusable: "false",
|
|
62
|
+
"data-pattern": hatched ? pattern : void 0,
|
|
63
|
+
children: [hatched ? /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("pattern", {
|
|
64
|
+
id: patternId,
|
|
65
|
+
width: 6,
|
|
66
|
+
height: 6,
|
|
67
|
+
patternUnits: "userSpaceOnUse",
|
|
68
|
+
children: /* @__PURE__ */ jsx(PatternMarks, { pattern })
|
|
69
|
+
}) }) : null, swatch === "area" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
70
|
+
/* @__PURE__ */ jsx("rect", {
|
|
71
|
+
"data-part": "fill",
|
|
72
|
+
x: 1.5,
|
|
73
|
+
y: 1.5,
|
|
74
|
+
width: 25,
|
|
75
|
+
height: 13,
|
|
76
|
+
fill,
|
|
77
|
+
fillOpacity: AREA_FILL_OPACITY
|
|
78
|
+
}),
|
|
79
|
+
hatched ? /* @__PURE__ */ jsx("rect", {
|
|
80
|
+
"data-part": "hatch",
|
|
81
|
+
x: 1.5,
|
|
82
|
+
y: 1.5,
|
|
83
|
+
width: 25,
|
|
84
|
+
height: 13,
|
|
85
|
+
fill: `url(#${patternId})`
|
|
86
|
+
}) : null,
|
|
87
|
+
/* @__PURE__ */ jsx("rect", {
|
|
88
|
+
"data-part": "outline",
|
|
89
|
+
x: 1.5,
|
|
90
|
+
y: 1.5,
|
|
91
|
+
width: 25,
|
|
92
|
+
height: 13,
|
|
93
|
+
fill: "none",
|
|
94
|
+
stroke: edge,
|
|
95
|
+
strokeWidth: stroke,
|
|
96
|
+
strokeDasharray: dashArray
|
|
97
|
+
})
|
|
98
|
+
] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("line", {
|
|
99
|
+
"data-part": "casing",
|
|
100
|
+
x1: 2,
|
|
101
|
+
y1: HEIGHT / 2,
|
|
102
|
+
x2: 26,
|
|
103
|
+
y2: HEIGHT / 2,
|
|
104
|
+
stroke: halo,
|
|
105
|
+
strokeWidth: stroke + 3,
|
|
106
|
+
strokeLinecap: "butt"
|
|
107
|
+
}), /* @__PURE__ */ jsx("line", {
|
|
108
|
+
"data-part": "line",
|
|
109
|
+
x1: 2,
|
|
110
|
+
y1: HEIGHT / 2,
|
|
111
|
+
x2: 26,
|
|
112
|
+
y2: HEIGHT / 2,
|
|
113
|
+
stroke: fill,
|
|
114
|
+
strokeWidth: stroke,
|
|
115
|
+
strokeDasharray: dashArray,
|
|
116
|
+
strokeLinecap: "butt"
|
|
117
|
+
})] })]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
export { ShapeGlyph };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=ShapeGlyph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShapeGlyph.js","names":["styles.glyph","_Fragment"],"sources":["../../src/layers/ShapeGlyph.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { FillPattern, LineDash, PaletteSlot } from \"@mapcairn/core\";\nimport { tokenValues } from \"@mapcairn/theme\";\nimport { useId } from \"react\";\nimport * as styles from \"./Layers.css\";\nimport { paletteColour } from \"./mapFeatures\";\n\nconst { edge, halo } = tokenValues.dataMarker;\n\nconst WIDTH = 28;\nconst HEIGHT = 16;\n\n/** The widest stroke the swatch can show; wider strokes are drawn at this width. */\nconst MAX_STROKE = 6;\n\n/** Opacity of an area swatch's fill, close to the map's own fill so the key looks like the map. */\nconst AREA_FILL_OPACITY = 0.7;\n\n/** The dash array of a line style, in swatch pixels. */\nconst DASH_ARRAY: Readonly<Record<LineDash, string | undefined>> = {\n solid: undefined,\n dashed: \"4 3\",\n dotted: \"1 3\",\n};\n\n/** Props for {@link ShapeGlyph}. */\nexport interface ShapeGlyphProps {\n /** An area (a filled box) or a line (a stroke). */\n readonly swatch: \"area\" | \"line\";\n readonly colour: PaletteSlot;\n /** Hatching over an area's fill. Defaults to none. */\n readonly pattern?: FillPattern;\n /** Dashing of the outline or line. Defaults to solid. */\n readonly dash?: LineDash;\n /** Outline or line width in pixels. Defaults to 1.5 for an area and 3 for a line. */\n readonly width?: number;\n}\n\n/** The marks of one hatching pattern, in a 6 pixel cell. */\nfunction PatternMarks({ pattern }: { pattern: Exclude<FillPattern, \"solid\"> }) {\n switch (pattern) {\n case \"stripes\":\n return (\n <path\n d=\"M-1,1 L1,-1 M0,6 L6,0 M5,7 L7,5\"\n stroke={edge}\n strokeWidth={1}\n />\n );\n case \"crosshatch\":\n return (\n <path\n d=\"M-1,1 L1,-1 M0,6 L6,0 M5,7 L7,5 M-1,5 L1,7 M0,0 L6,6 M5,-1 L7,1\"\n stroke={edge}\n strokeWidth={0.8}\n />\n );\n case \"dots\":\n return <circle cx={3} cy={3} r={1.1} fill={edge} />;\n }\n}\n\n/**\n * What a polygon or line looks like on the map, as a small picture for the\n * legend, the list and the card, so the words and the map agree: the fill\n * over its hatching and ink outline, or the coloured line over a white\n * casing. Decorative: the words beside it carry the meaning. Colours are SVG\n * attributes, not styles, so they need nothing from the\n * Content-Security-Policy.\n */\nexport function ShapeGlyph({\n swatch,\n colour,\n pattern = \"solid\",\n dash = \"solid\",\n width,\n}: ShapeGlyphProps) {\n const patternId = `mapcairn-hatch-${useId().replaceAll(\":\", \"\")}`;\n const fill = paletteColour(colour);\n const stroke = Math.min(width ?? (swatch === \"area\" ? 1.5 : 3), MAX_STROKE);\n const dashArray = DASH_ARRAY[dash];\n const hatched = swatch === \"area\" && pattern !== \"solid\";\n return (\n <svg\n className={styles.glyph}\n width={WIDTH}\n height={HEIGHT}\n viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n aria-hidden=\"true\"\n focusable=\"false\"\n data-pattern={hatched ? pattern : undefined}\n >\n {hatched ? (\n <defs>\n <pattern\n id={patternId}\n width={6}\n height={6}\n patternUnits=\"userSpaceOnUse\"\n >\n <PatternMarks pattern={pattern} />\n </pattern>\n </defs>\n ) : null}\n {swatch === \"area\" ? (\n <>\n <rect\n data-part=\"fill\"\n x={1.5}\n y={1.5}\n width={WIDTH - 3}\n height={HEIGHT - 3}\n fill={fill}\n fillOpacity={AREA_FILL_OPACITY}\n />\n {hatched ? (\n <rect\n data-part=\"hatch\"\n x={1.5}\n y={1.5}\n width={WIDTH - 3}\n height={HEIGHT - 3}\n fill={`url(#${patternId})`}\n />\n ) : null}\n <rect\n data-part=\"outline\"\n x={1.5}\n y={1.5}\n width={WIDTH - 3}\n height={HEIGHT - 3}\n fill=\"none\"\n stroke={edge}\n strokeWidth={stroke}\n strokeDasharray={dashArray}\n />\n </>\n ) : (\n <>\n <line\n data-part=\"casing\"\n x1={2}\n y1={HEIGHT / 2}\n x2={WIDTH - 2}\n y2={HEIGHT / 2}\n stroke={halo}\n strokeWidth={stroke + 3}\n strokeLinecap=\"butt\"\n />\n <line\n data-part=\"line\"\n x1={2}\n y1={HEIGHT / 2}\n x2={WIDTH - 2}\n y2={HEIGHT / 2}\n stroke={fill}\n strokeWidth={stroke}\n strokeDasharray={dashArray}\n strokeLinecap=\"butt\"\n />\n </>\n )}\n </svg>\n );\n}\n"],"mappings":";;;;;;AAQA,IAAM,EAAE,MAAM,SAAS,YAAY;AAEnC,IAAM,QAAQ;AACd,IAAM,SAAS;;AAGf,IAAM,aAAa;;AAGnB,IAAM,oBAAoB;;AAG1B,IAAM,aAA6D;CACjE,OAAO,KAAA;CACP,QAAQ;CACR,QAAQ;AACV;;AAgBA,SAAS,aAAa,EAAE,WAAuD;CAC7E,QAAQ,SAAR;EACE,KAAK,WACH,OACE,oBAAC,QAAD;GACE,GAAE;GACF,QAAQ;GACR,aAAa;EACd,CAAA;EAEL,KAAK,cACH,OACE,oBAAC,QAAD;GACE,GAAE;GACF,QAAQ;GACR,aAAa;EACd,CAAA;EAEL,KAAK,QACH,OAAO,oBAAC,UAAD;GAAQ,IAAI;GAAG,IAAI;GAAG,GAAG;GAAK,MAAM;EAAO,CAAA;CACtD;A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GACV,IAAI;GACJ,IAAI,SAAS;GACb,IAAI;GACJ,IAAI,SAAS;GACb,QAAQ;GACR,aAAa;GACb,iBAAiB;GACjB,eAAc;EACf,CAAA,CACD,EAAA,CAAA,CAED;;AAET"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useMessages } from "../services/hooks.js";
|
|
2
|
+
import { Button } from "../ui/Button/Button.js";
|
|
3
|
+
import { groupActions, groupTurnOff, turnOffCount, turnOffRow, undoStatus } from "./Layers.styles.js";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/layers/TurnOffActions.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Keeps focus from falling to the page when the button or the Undo that has it
|
|
9
|
+
* leaves. Focus follows to the first button in the row only if it was inside
|
|
10
|
+
* the row and nothing else has taken it since, so a person who moved on is
|
|
11
|
+
* left alone.
|
|
12
|
+
*/
|
|
13
|
+
function useFocusHandoff(showsUndo) {
|
|
14
|
+
const root = useRef(null);
|
|
15
|
+
const hadFocus = useRef(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!hadFocus.current) return;
|
|
18
|
+
hadFocus.current = false;
|
|
19
|
+
const active = document.activeElement;
|
|
20
|
+
if (active && active !== document.body) return;
|
|
21
|
+
root.current?.querySelector("button")?.focus({ preventScroll: true });
|
|
22
|
+
}, [showsUndo]);
|
|
23
|
+
return {
|
|
24
|
+
root,
|
|
25
|
+
onFocus: () => {
|
|
26
|
+
hadFocus.current = true;
|
|
27
|
+
},
|
|
28
|
+
onBlur: (event) => {
|
|
29
|
+
if (event.target.isConnected) hadFocus.current = false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the action says once it has run, with Undo. The countdown to its expiry
|
|
35
|
+
* waits while a mouse is over it and while keyboard focus is inside it, each held and
|
|
36
|
+
* released on its own, and both are let go when it goes. A tap is not a hover:
|
|
37
|
+
* a touch screen reports one as the pointer entering, and nothing then reports
|
|
38
|
+
* it leaving.
|
|
39
|
+
*/
|
|
40
|
+
function UndoStatus({ layers, text, label }) {
|
|
41
|
+
const { holdUndo, releaseUndo, undoTurnOff } = layers;
|
|
42
|
+
const { t } = useMessages();
|
|
43
|
+
useEffect(() => () => {
|
|
44
|
+
releaseUndo("pointer");
|
|
45
|
+
releaseUndo("focus");
|
|
46
|
+
}, [releaseUndo]);
|
|
47
|
+
const enter = (event) => {
|
|
48
|
+
if (event.pointerType !== "touch") holdUndo("pointer");
|
|
49
|
+
};
|
|
50
|
+
const leave = (event) => {
|
|
51
|
+
if (event.pointerType !== "touch") releaseUndo("pointer");
|
|
52
|
+
};
|
|
53
|
+
const hold = (event) => {
|
|
54
|
+
if (event.target.matches(":focus-visible")) holdUndo("focus");
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
className: undoStatus,
|
|
58
|
+
onPointerEnter: enter,
|
|
59
|
+
onPointerLeave: leave,
|
|
60
|
+
onFocus: hold,
|
|
61
|
+
onBlur: () => releaseUndo("focus"),
|
|
62
|
+
children: [text, /* @__PURE__ */ jsx(Button, {
|
|
63
|
+
variant: "quiet",
|
|
64
|
+
"aria-label": label,
|
|
65
|
+
onClick: undoTurnOff,
|
|
66
|
+
children: t("layers.turnOff.undo", {})
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** An action's button with, once it has run, its status and Undo after it. */
|
|
71
|
+
function ActionRow({ layers, undo, className, children }) {
|
|
72
|
+
const handoff = useFocusHandoff(undo !== null);
|
|
73
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
ref: handoff.root,
|
|
75
|
+
className,
|
|
76
|
+
onFocus: handoff.onFocus,
|
|
77
|
+
onBlur: handoff.onBlur,
|
|
78
|
+
children: [children, undo ? /* @__PURE__ */ jsx(UndoStatus, {
|
|
79
|
+
layers,
|
|
80
|
+
...undo
|
|
81
|
+
}) : null]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* "Turn off all layers", with how many are on. It is disabled, not hidden,
|
|
86
|
+
* when none is, and it stays once it has run: the status and Undo follow it.
|
|
87
|
+
* The status is plain text; the hook announces the action once, through the
|
|
88
|
+
* shared live region.
|
|
89
|
+
*/
|
|
90
|
+
function TurnOffAll({ layers, ids }) {
|
|
91
|
+
const messages = useMessages();
|
|
92
|
+
const { turnedOff, turnOff } = layers;
|
|
93
|
+
const undo = turnedOff?.group === null ? {
|
|
94
|
+
text: messages.plural("layers.turnOff.doneAll", { count: turnedOff.count }),
|
|
95
|
+
label: messages.plural("layers.turnOff.undoAll", { count: turnedOff.count })
|
|
96
|
+
} : null;
|
|
97
|
+
return /* @__PURE__ */ jsx(ActionRow, {
|
|
98
|
+
layers,
|
|
99
|
+
undo,
|
|
100
|
+
className: turnOffRow,
|
|
101
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
102
|
+
variant: "secondary",
|
|
103
|
+
disabled: ids.length === 0,
|
|
104
|
+
onClick: () => turnOff(ids),
|
|
105
|
+
children: [messages.t("layers.turnOff.all", {}), /* @__PURE__ */ jsx("span", {
|
|
106
|
+
className: turnOffCount,
|
|
107
|
+
children: messages.plural("layers.turnOff.count", { count: ids.length })
|
|
108
|
+
})]
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* "Turn off N in <group>", shown while the group has layers on. Once it has
|
|
114
|
+
* run, its status and Undo take the row under the group's heading.
|
|
115
|
+
*/
|
|
116
|
+
function TurnOffGroup({ layers, group, heading, ids, holdsUndo }) {
|
|
117
|
+
const { plural } = useMessages();
|
|
118
|
+
const { turnedOff, turnOff } = layers;
|
|
119
|
+
const undo = turnedOff && holdsUndo ? {
|
|
120
|
+
text: plural("layers.turnOff.doneGroup", {
|
|
121
|
+
count: turnedOff.count,
|
|
122
|
+
group: heading
|
|
123
|
+
}),
|
|
124
|
+
label: plural("layers.turnOff.undoGroup", {
|
|
125
|
+
count: turnedOff.count,
|
|
126
|
+
group: heading
|
|
127
|
+
})
|
|
128
|
+
} : null;
|
|
129
|
+
if (undo === null && ids.length === 0) return null;
|
|
130
|
+
return /* @__PURE__ */ jsx(ActionRow, {
|
|
131
|
+
layers,
|
|
132
|
+
undo,
|
|
133
|
+
className: groupActions,
|
|
134
|
+
children: ids.length > 0 ? /* @__PURE__ */ jsx(Button, {
|
|
135
|
+
variant: "quiet",
|
|
136
|
+
className: groupTurnOff,
|
|
137
|
+
onClick: () => turnOff(ids, { group }),
|
|
138
|
+
children: plural("layers.turnOff.group", {
|
|
139
|
+
count: ids.length,
|
|
140
|
+
group: heading
|
|
141
|
+
})
|
|
142
|
+
}) : null
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export { TurnOffAll, TurnOffGroup };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=TurnOffActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TurnOffActions.js","names":["styles.undoStatus","styles.turnOffRow","styles.turnOffCount","styles.groupActions","styles.groupTurnOff"],"sources":["../../src/layers/TurnOffActions.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n type FocusEvent,\n type PointerEvent,\n type ReactNode,\n useEffect,\n useRef,\n} from \"react\";\nimport { useMessages } from \"../services\";\nimport { Button } from \"../ui/Button\";\nimport * as styles from \"./Layers.css\";\nimport type { DataLayers } from \"./useDataLayers\";\n\n/** Props for {@link TurnOffAll}. */\nexport interface TurnOffAllProps {\n readonly layers: DataLayers;\n /** The layers it would turn off: every layer that is on. */\n readonly ids: readonly string[];\n}\n\n/** Props for {@link TurnOffGroup}. */\nexport interface TurnOffGroupProps {\n readonly layers: DataLayers;\n /** The group's key, which does not change with the language: passed to `turnOff` to say which action asked. */\n readonly group: string;\n /** Whether the Undo on offer belongs to this group, which the section works out from the layers it would turn back on. */\n readonly holdsUndo: boolean;\n /** The group's heading as the person reads it, for the button and the status. */\n readonly heading: string;\n /** The layers it would turn off: those of the group that are on. */\n readonly ids: readonly string[];\n}\n\n/** What a Turn off action says once it has run, and how Undo is named. */\ninterface UndoCopy {\n readonly text: string;\n readonly label: string;\n}\n\n/**\n * Keeps focus from falling to the page when the button or the Undo that has it\n * leaves. Focus follows to the first button in the row only if it was inside\n * the row and nothing else has taken it since, so a person who moved on is\n * left alone.\n */\nfunction useFocusHandoff(showsUndo: boolean) {\n const root = useRef<HTMLDivElement>(null);\n const hadFocus = useRef(false);\n // biome-ignore lint/correctness/useExhaustiveDependencies: the Undo appearing or going is the trigger.\n useEffect(() => {\n if (!hadFocus.current) {\n return;\n }\n hadFocus.current = false;\n const active = document.activeElement;\n if (active && active !== document.body) {\n return;\n }\n root.current?.querySelector(\"button\")?.focus({ preventScroll: true });\n }, [showsUndo]);\n return {\n root,\n onFocus: () => {\n hadFocus.current = true;\n },\n // A blur from an element still on the page is a person moving on, to\n // another control or to the page itself. One from an element that has\n // gone is the focused button leaving, which the handoff follows.\n onBlur: (event: FocusEvent) => {\n if ((event.target as Node).isConnected) {\n hadFocus.current = false;\n }\n },\n };\n}\n\ninterface UndoStatusProps extends UndoCopy {\n readonly layers: DataLayers;\n}\n\n/**\n * What the action says once it has run, with Undo. The countdown to its expiry\n * waits while a mouse is over it and while keyboard focus is inside it, each held and\n * released on its own, and both are let go when it goes. A tap is not a hover:\n * a touch screen reports one as the pointer entering, and nothing then reports\n * it leaving.\n */\nfunction UndoStatus({ layers, text, label }: UndoStatusProps) {\n const { holdUndo, releaseUndo, undoTurnOff } = layers;\n const { t } = useMessages();\n useEffect(\n () => () => {\n releaseUndo(\"pointer\");\n releaseUndo(\"focus\");\n },\n [releaseUndo],\n );\n const enter = (event: PointerEvent) => {\n if (event.pointerType !== \"touch\") {\n holdUndo(\"pointer\");\n }\n };\n const leave = (event: PointerEvent) => {\n if (event.pointerType !== \"touch\") {\n releaseUndo(\"pointer\");\n }\n };\n // Only a keyboard user's focus holds the countdown. After a click the\n // handoff gives Undo focus too, without the focus ring, and a mouse or touch\n // user who has moved on must not be left with a status that never goes.\n const hold = (event: FocusEvent) => {\n if ((event.target as Element).matches(\":focus-visible\")) {\n holdUndo(\"focus\");\n }\n };\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: the handlers only pause a countdown; the one control inside, Undo, is a real button.\n // biome-ignore lint/a11y/noNoninteractiveElementInteractions: the handlers only pause a countdown; the one control inside, Undo, is a real button.\n <div\n className={styles.undoStatus}\n onPointerEnter={enter}\n onPointerLeave={leave}\n onFocus={hold}\n onBlur={() => releaseUndo(\"focus\")}\n >\n {text}\n <Button variant=\"quiet\" aria-label={label} onClick={undoTurnOff}>\n {t(\"layers.turnOff.undo\", {})}\n </Button>\n </div>\n );\n}\n\ninterface ActionRowProps {\n readonly layers: DataLayers;\n /** What to say, with Undo, or null when this action has not just run. */\n readonly undo: UndoCopy | null;\n readonly className: string;\n /** The action's button, or nothing when it has none to show. */\n readonly children: ReactNode;\n}\n\n/** An action's button with, once it has run, its status and Undo after it. */\nfunction ActionRow({ layers, undo, className, children }: ActionRowProps) {\n const handoff = useFocusHandoff(undo !== null);\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: the handlers only watch where focus is; the controls inside are real buttons.\n // biome-ignore lint/a11y/noNoninteractiveElementInteractions: the handlers only watch where focus is; the controls inside are real buttons.\n <div\n ref={handoff.root}\n className={className}\n onFocus={handoff.onFocus}\n onBlur={handoff.onBlur}\n >\n {children}\n {undo ? <UndoStatus layers={layers} {...undo} /> : null}\n </div>\n );\n}\n\n/**\n * \"Turn off all layers\", with how many are on. It is disabled, not hidden,\n * when none is, and it stays once it has run: the status and Undo follow it.\n * The status is plain text; the hook announces the action once, through the\n * shared live region.\n */\nexport function TurnOffAll({ layers, ids }: TurnOffAllProps) {\n const messages = useMessages();\n const { turnedOff, turnOff } = layers;\n const undo =\n turnedOff?.group === null\n ? {\n text: messages.plural(\"layers.turnOff.doneAll\", {\n count: turnedOff.count,\n }),\n label: messages.plural(\"layers.turnOff.undoAll\", {\n count: turnedOff.count,\n }),\n }\n : null;\n return (\n <ActionRow layers={layers} undo={undo} className={styles.turnOffRow}>\n <Button\n variant=\"secondary\"\n disabled={ids.length === 0}\n onClick={() => turnOff(ids)}\n >\n {messages.t(\"layers.turnOff.all\", {})}\n <span className={styles.turnOffCount}>\n {messages.plural(\"layers.turnOff.count\", { count: ids.length })}\n </span>\n </Button>\n </ActionRow>\n );\n}\n\n/**\n * \"Turn off N in <group>\", shown while the group has layers on. Once it has\n * run, its status and Undo take the row under the group's heading.\n */\nexport function TurnOffGroup({\n layers,\n group,\n heading,\n ids,\n holdsUndo,\n}: TurnOffGroupProps) {\n const { plural } = useMessages();\n const { turnedOff, turnOff } = layers;\n const undo =\n turnedOff && holdsUndo\n ? {\n text: plural(\"layers.turnOff.doneGroup\", {\n count: turnedOff.count,\n group: heading,\n }),\n label: plural(\"layers.turnOff.undoGroup\", {\n count: turnedOff.count,\n group: heading,\n }),\n }\n : null;\n if (undo === null && ids.length === 0) {\n return null;\n }\n return (\n <ActionRow layers={layers} undo={undo} className={styles.groupActions}>\n {ids.length > 0 ? (\n <Button\n variant=\"quiet\"\n className={styles.groupTurnOff}\n onClick={() => turnOff(ids, { group })}\n >\n {plural(\"layers.turnOff.group\", {\n count: ids.length,\n group: heading,\n })}\n </Button>\n ) : null}\n </ActionRow>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA8CA,SAAS,gBAAgB,WAAoB;CAC3C,MAAM,OAAO,OAAuB,IAAI;CACxC,MAAM,WAAW,OAAO,KAAK;CAE7B,gBAAgB;EACd,IAAI,CAAC,SAAS,SACZ;EAEF,SAAS,UAAU;EACnB,MAAM,SAAS,SAAS;EACxB,IAAI,UAAU,WAAW,SAAS,MAChC;EAEF,KAAK,SAAS,cAAc,QAAQ,CAAC,EAAE,MAAM,EAAE,eAAe,KAAK,CAAC;CACtE,GAAG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AU,OACjB;EACE,MAAM,SAAS,OAAO,0BAA0B,EAC9C,OAAO,UAAU,MACnB,CAAC;EACD,OAAO,SAAS,OAAO,0BAA0B,EAC/C,OAAO,UAAU,MACnB,CAAC;CACH,IACA;CACN,OACE,oBAAC,WAAD;EAAmB;EAAc;EAAM,WAAWC;EAChD,UAAA,qBAAC,QAAD;GACE,SAAQ;GACR,UAAU,IAAI,WAAW;GACzB,eAAe,QAAQ,GAAG;GAH5B,UAAA,CAKG,SAAS,EAAE,sBAAsB,CAAC,CAAC,GACpC,oBAAC,QAAD;IAAM,WAAWC;IACd,UAAA,SAAS,OAAO,wBAAwB,EAAE,OAAO,IAAI,OAAO,CAAC;GAC1D,CAAA,CACA;;CACC,CAAA;AAEf;;;;;AAMA,SAAgB,aAAa,EAC3B,QACA,OACA,SACA,KACA,aACoB;CACpB,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,EAAE,WAAW,YAAY;CAC/B,MAAM,OACJ,aAAa,YACT;EACE,MAAM,OAAO,4BAA4B;GACvC,OAAO,UAAU;GACjB,OAAO;EACT,CAAC;EACD,OAAO,OAAO,4BAA4B;GACxC,OAAO,UAAU;GACjB,OAAO;EACT,CAAC;CACH,IACA;CACN,IAAI,SAAS,QAAQ,IAAI,WAAW,GAClC,OAAO;CAET,OACE,oBAAC,WAAD;EAAmB;EAAc;EAAM,WAAWC;EAC/C,UAAA,IAAI,SAAS,IACZ,oBAAC,QAAD;GACE,SAAQ;GACR,WAAWC;GACX,eAAe,QAAQ,KAAK,EAAE,MAAM,CAAC;GAEpC,UAAA,OAAO,wBAAwB;IAC9B,OAAO,IAAI;IACX,OAAO;GACT,CAAC;EACK,CAAA,IACN;CACK,CAAA;AAEf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isIdentifiable } from "@mapcairn/core";
|
|
2
|
+
// src/layers/answersTap.ts
|
|
3
|
+
/**
|
|
4
|
+
* Whether a layer is one a tap can ask, as far as the Layers section can tell
|
|
5
|
+
* without a place: it is on, has an `identify` block and shows imagery (the map
|
|
6
|
+
* has not reported that none of its tiles loaded), the same tests `identifyAt`
|
|
7
|
+
* makes before it looks at `bounds`. The section's identify lines read this, so
|
|
8
|
+
* they claim only what a tap does. A layer whose `bounds` miss the tapped place
|
|
9
|
+
* is still counted, since that depends on where the person taps.
|
|
10
|
+
*/
|
|
11
|
+
function answersTap(layer) {
|
|
12
|
+
return layer.enabled && isIdentifiable(layer.definition) && layer.status.kind !== "tiles-unavailable";
|
|
13
|
+
}
|
|
14
|
+
export { answersTap };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=answersTap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answersTap.js","names":[],"sources":["../../src/layers/answersTap.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { isIdentifiable } from \"@mapcairn/core\";\nimport type { DataLayerState } from \"./useDataLayers\";\n\n/**\n * Whether a layer is one a tap can ask, as far as the Layers section can tell\n * without a place: it is on, has an `identify` block and shows imagery (the map\n * has not reported that none of its tiles loaded), the same tests `identifyAt`\n * makes before it looks at `bounds`. The section's identify lines read this, so\n * they claim only what a tap does. A layer whose `bounds` miss the tapped place\n * is still counted, since that depends on where the person taps.\n */\nexport function answersTap(layer: DataLayerState): boolean {\n return (\n layer.enabled &&\n isIdentifiable(layer.definition) &&\n layer.status.kind !== \"tiles-unavailable\"\n );\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,WAAW,OAAgC;CACzD,OACE,MAAM,WACN,eAAe,MAAM,UAAU,KAC/B,MAAM,OAAO,SAAS;AAE1B"}
|