@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":"useDataLayers.js","names":[],"sources":["../../src/layers/useDataLayers.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceDetailError,\n announceDetailShown,\n announceFeaturesFound,\n announceIdentified,\n announceLayerOn,\n announceLayersTurnedBackOn,\n announceLayersTurnedOff,\n announceTilesRecovered,\n announceTilesSlow,\n announceTilesUnavailable,\n type Bounds,\n type CatalogueState,\n type ControlValues,\n describeChosenTime,\n type FieldValue,\n type IdentifyTarget,\n isFeedLayer,\n isQueryLayer,\n isRasterTileLayer,\n type LayerAttribution,\n type LayerDefinition,\n type LayerFeature,\n type LayersUrlState,\n loadsFeatures,\n parseTime,\n readyLayers,\n resolveControlValues,\n textOrMessage,\n tileUrl,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { useMessages, useOnline, useServices } from \"../services\";\nimport { useAnnounce } from \"../ui/LiveRegion\";\nimport { type CatalogueMessage, catalogueNotice } from \"./catalogueNotice\";\nimport { type Link, type Reconciled, reconcile } from \"./catalogueReconcile\";\nimport { type CatalogueView, catalogueView, loadFailed } from \"./catalogueView\";\nimport {\n askableLayers,\n type IdentifiedEntry,\n IdentifyRun,\n identifiableLayers,\n MAX_IDENTIFY_LAYERS,\n outcomeOf,\n stillCurrent,\n} from \"./identifyRun\";\nimport { errorKind, type LayerStatus } from \"./layerStatus\";\nimport { type LoadResult, loadOutcome } from \"./loadOutcome\";\nimport {\n type AnnouncedStates,\n type LimitedLayer,\n reportLoad,\n reportZoomLimits,\n} from \"./loadReport\";\nimport {\n planLoads,\n type QueryView,\n rememberWindows,\n viewZoomLimit,\n type WantedLoad,\n wantedLoads,\n} from \"./loadRequests\";\n\nexport { IDENTIFY_TIMEOUT_MS, MAX_IDENTIFY_LAYERS } from \"./identifyRun\";\nexport type { CatalogueView, LayerStatus };\n\n/**\n * How long the Undo after turning layers off stays on offer, in milliseconds.\n * It is not shorter than a status message's shortest stay, so there is time to\n * read it and to reach Undo by keyboard.\n */\nexport const UNDO_TIMEOUT_MS = 10_000;\n\n/** One layer as the ui shows it. */\nexport interface DataLayerState {\n readonly definition: LayerDefinition;\n readonly enabled: boolean;\n /** Every control's value, resolved against the definition. */\n readonly controls: ControlValues;\n readonly status: LayerStatus;\n /** The loaded features, in the order the provider sent them. */\n readonly features: readonly LayerFeature[];\n /** The id of the list's sort option. */\n readonly sortId: string;\n /** The features in list order. */\n readonly sorted: readonly LayerFeature[];\n}\n\n/** The feature whose card is open, with its layer. */\nexport interface SelectedFeature {\n readonly layer: DataLayerState;\n readonly feature: LayerFeature;\n}\n\n/** A feature's affected area, loaded on request. */\nexport interface DetailState {\n readonly layerId: string;\n readonly featureId: string;\n readonly status: \"loading\" | \"shown\" | \"error\";\n readonly shapes: readonly LayerFeature[];\n}\n\n/** What a tap that asked raster layers came to. */\nexport interface IdentifyResult {\n /** How many layers were asked. Zero when none could be, and then nothing was requested. */\n readonly asked: number;\n /** How many features the layers that answered found, in all. */\n readonly found: number;\n}\n\n/** What can hold the countdown to an Undo offer's expiry: the pointer over its status, or focus inside it. */\nexport type UndoHolder = \"pointer\" | \"focus\";\n\n/** The batch of layers that was last turned off at once, which Undo would turn back on. */\nexport interface TurnedOff {\n /** How many layers Undo would turn back on: those of the batch that are still off and still in the catalogue. */\n readonly count: number;\n /** The ids Undo would turn back on, so the ui can find the group they belong to by its layers, whatever the language calls it. */\n readonly ids: readonly string[];\n /** The `group` the ui passed to `turnOff`, or null when the action covered every layer. */\n readonly group: string | null;\n}\n\n/** What {@link useDataLayers} returns: the layers' state and every action on them. */\nexport interface DataLayers {\n /** Every registered layer, in catalogue order. Empty while the catalogue is loading or has failed. */\n readonly layers: readonly DataLayerState[];\n /** What the catalogue is doing besides holding layers: loading, failed, how many definitions it skipped, and how a refresh went. */\n readonly catalogue: CatalogueView;\n /**\n * Asks the catalogue to load again after a failed load or a failed refresh,\n * which the section's Try again does. It does nothing in any other state:\n * only the host refreshes a catalogue that is working.\n */\n retryCatalogue(): void;\n readonly selected: SelectedFeature | null;\n /**\n * The features a tap or the keyboard found together, when there were\n * several, so one can be chosen. Null when no list is open. The open card\n * offers a way back to it while it is.\n */\n readonly choices: readonly SelectedFeature[] | null;\n readonly detail: DetailState | null;\n /** Grows each time opening a card asks for it to take focus (a tap on the map). */\n readonly focusRequest: number;\n /**\n * True from a request for the card to take focus until\n * {@link DataLayers.consumeFocus}. The section that shows the card is\n * unmounted whenever the sheet closes, so what has been acted on is kept\n * here: reopening the sheet later must not repeat it.\n */\n readonly focusPending: boolean;\n /** Marks the latest focus request as acted on. */\n readonly consumeFocus: () => void;\n /**\n * The layers part of the permalink: the layers that are on, and the\n * link's layers still waiting for a catalogue that is loading or has\n * failed, so writing the address does not erase them.\n */\n readonly urlValue: LayersUrlState;\n /** The credits of the layers that are on, for the map credits. */\n readonly credits: readonly LayerAttribution[];\n /** The clock the hook uses, for relative times in cards and lists. */\n readonly now: () => number;\n setEnabled(id: string, enabled: boolean): void;\n /**\n * Turns several layers off as one change: one state update, so one redraw\n * and one address update, and one announcement (\"3 layers turned off. Undo available\"). Ids\n * that are not on, or not known, are ignored, and nothing happens when none\n * is on. Each layer's open card, list of choices and affected area\n * close as they do for a single layer. It offers {@link DataLayers.turnedOff}\n * for {@link UNDO_TIMEOUT_MS}, replacing any earlier offer. `group` says\n * which group's action asked, so the ui can tell a group's action from the\n * one for every layer; it is not words, and the ui finds the group to show\n * the Undo beside by {@link TurnedOff.ids}.\n */\n turnOff(ids: readonly string[], options?: { readonly group?: string }): void;\n /** The batch Undo would turn back on, or null when none is on offer (none yet, used, replaced, expired or every layer of it already on again). */\n readonly turnedOff: TurnedOff | null;\n /**\n * Turns back on the layers of the last {@link DataLayers.turnOff}, in one\n * change and one announcement. A layer's control values stay while it is\n * off, so they come back as they are. A layer that is on again, or no\n * longer in the catalogue, is skipped; the rest of what the person changed\n * meanwhile is left as it is. Does nothing when no offer is open.\n */\n undoTurnOff(): void;\n /** Pauses the offer's countdown while `by` is on its status. The countdown waits until every holder has released. */\n holdUndo(by: UndoHolder): void;\n /** Ends `by`'s hold; once none is left the countdown starts again, in full. */\n releaseUndo(by: UndoHolder): void;\n setControl(id: string, controlId: string, value: string): void;\n setSort(id: string, sortId: string): void;\n retry(id: string): void;\n /**\n * Records that a tile layer has had tiles asked for and none has loaded for\n * a long while, which `MapDataLayers` calls from the adapter's report. `tiles`\n * is the template those tiles came from: a report for anything but the\n * layer's current tiles, or for a layer that is off, is ignored, as is one\n * for tiles the layer already reported as slow or unavailable. The layer then\n * says it is still waiting, and announces it once in a message that is kept,\n * because the person turned the layer on and would otherwise see nothing,\n * until its tiles change, it is turned off, or a tile loads later (see\n * {@link DataLayers.reportTilesRecovered}).\n */\n reportTilesSlow(id: string, tiles: string): void;\n /**\n * Records that the map settled with none of a tile layer's tiles loaded,\n * which `MapDataLayers` calls from the adapter's report. `tiles` is the\n * template those tiles came from: a report for anything but the layer's\n * current tiles, or for a layer that is off, is ignored. The layer then\n * says so and announces it once, until its tiles change, it is turned off, or\n * a tile loads later (see {@link DataLayers.reportTilesRecovered}). It\n * replaces the status of a layer reported slow for the same tiles.\n */\n reportTilesUnavailable(id: string, tiles: string): void;\n /**\n * Records that a tile loaded for the `tiles` a layer had reported slow or\n * with no tiles, which `MapDataLayers` calls from the adapter's report. The\n * layer's status goes and the layer says so once, politely. A recovery for\n * any other tiles, or for a layer that is not showing the status, is ignored.\n */\n reportTilesRecovered(id: string, tiles: string): void;\n /**\n * Opens a feature's card, or closes it (and any list) with `null`. A card\n * opened without `keepChoices` also closes the list of features found\n * together.\n */\n select(\n layerId: string,\n featureId: string | null,\n options?: {\n readonly focus?: boolean;\n /** Keeps the list of features found together open behind the card. */\n readonly keepChoices?: boolean;\n },\n ): void;\n /**\n * Handles several features found at once (a tap or the keyboard route):\n * with one it opens its card, with more it opens the list to choose from,\n * and with none it does nothing. Features no loaded layer has are dropped.\n */\n choose(\n hits: readonly { readonly layerId: string; readonly featureId: string }[],\n options?: { readonly focus?: boolean },\n ): void;\n /**\n * Asks the raster layers that answer a tap what is at a place, and opens\n * what they find: one feature opens its card, several open the list to\n * choose from, and none leaves an open card alone.\n *\n * It asks each layer that is on, has an `identify` block, shows imagery and\n * whose `bounds` hold the place, at most {@link MAX_IDENTIFY_LAYERS} in\n * catalogue order. The requests start together, each with\n * {@link IDENTIFY_TIMEOUT_MS} to answer. It waits for all of them, changes\n * the state once and says one message: how many were found, which layers\n * did not answer, and how many it asked when the cap held some back. A\n * layer that did not answer leaves what it showed before as it was.\n *\n * Resolves with how many layers were asked and how many features they\n * found, or with null when this tap was replaced or cancelled before it\n * settled, which opens and says nothing. When no layer can be asked it\n * resolves at once with `asked` of zero, changes nothing and says nothing,\n * so the caller can fall back to its own message. Starting a tap cancels the\n * one in flight.\n */\n identifyAt(\n target: IdentifyTarget,\n options?: { readonly focus?: boolean },\n ): Promise<IdentifyResult | null>;\n /**\n * Cancels the tap in flight, if there is one: its requests are aborted and it\n * opens and says nothing. Returns whether there was one. The host calls it\n * when the person leaves the plain map (another surface opens, taps stop\n * meaning \"look here\", a long press), and Escape calls it before it closes\n * anything. A layer turned off, whose tiles change, or an unmount cancels\n * what concerns it without a call, and so does opening a card or a list\n * with {@link DataLayers.select} or {@link DataLayers.choose}.\n */\n cancelIdentify(): boolean;\n /**\n * True from the start of {@link DataLayers.identifyAt} until it settles or is\n * cancelled. It is the status data for a \"looking up\" line, which waits a\n * moment before it shows so a quick answer never flickers.\n */\n readonly identifying: boolean;\n /** Closes the open card and returns to the list of features found together. */\n backToChoices(options?: { readonly focus?: boolean }): void;\n /**\n * Tells layers what the map shows, once it has settled: the visible box and\n * the normalised zoom. A query layer asks for the features in a window\n * around it. A layer with a zoom window in its definition (a query layer's\n * `minzoom`, a vector tile layer's `minzoom` and `maxzoom`) says which\n * level to zoom to when the zoom is outside it.\n */\n setView(area: Bounds, zoom: number): void;\n showDetail(layerId: string, featureId: string): void;\n hideDetail(): void;\n}\n\n/** Options for {@link useDataLayers}. */\nexport interface UseDataLayersOptions {\n /**\n * Layers and control values from a permalink. Control values are resolved\n * against each layer's definition, so an invalid one becomes the default.\n * A layer the catalogue has not got is dropped. A catalogue that is still\n * loading has no layers yet, so the link's layers wait for its first list\n * and stay in {@link DataLayers.urlValue} meanwhile; one that is not there\n * when the list arrives is dropped then, and said once, for good. The ids\n * the link carried past its limit (`initial.dropped`) are said in the same\n * message.\n */\n readonly initial?: LayersUrlState;\n /** The clock. Defaults to `Date.now`. */\n readonly now?: () => number;\n}\n\ninterface State {\n readonly enabled: readonly string[];\n /** Every listed layer's control values. */\n readonly controls: Readonly<Record<string, ControlValues>>;\n /** The link's layers that no list has answered for yet. */\n readonly link: Link;\n /** The list the choices were last reconciled with. */\n readonly known: readonly LayerDefinition[];\n /** The catalogue state last reconciled, so each change is applied once. */\n readonly reconciled: CatalogueState | null;\n /** What the last change to the catalogue asks the hook to say and forget once it is committed. */\n readonly notice: CatalogueNotice | null;\n readonly sorts: Readonly<Record<string, string>>;\n readonly results: Readonly<Record<string, LoadResult>>;\n readonly retries: Readonly<Record<string, number>>;\n /** The tiles each tile layer found no imagery for, by layer id (see `reportTilesUnavailable`). */\n readonly tilesUnavailable: Readonly<Record<string, string>>;\n /** The tiles each tile layer is still waiting for its first of, by layer id (see `reportTilesSlow`). */\n readonly tilesSlow: Readonly<Record<string, string>>;\n /**\n * What each tile layer found at the last tap that answered for it. It sits\n * apart from `results`, which feeds the list and the drawing, because these\n * features are neither listed nor drawn and their ids are not stable.\n */\n readonly identified: Readonly<Record<string, IdentifiedEntry>>;\n /** A tap is waiting for the layers it asked. */\n readonly identifying: boolean;\n /**\n * The open card's feature. Its snapshot keeps the card open when a query\n * layer refreshes for another part of the map and no longer lists it.\n */\n readonly selection: {\n readonly layerId: string;\n readonly featureId: string;\n readonly snapshot?: LayerFeature;\n } | null;\n readonly choices:\n | readonly { readonly layerId: string; readonly featureId: string }[]\n | null;\n /** What the map last showed, for query layers. */\n readonly view: QueryView | null;\n readonly focusRequest: number;\n /** The `focusRequest` that has been acted on. */\n readonly focusHandled: number;\n readonly detail: DetailState | null;\n /** The last batch turned off at once, for Undo. */\n readonly undo: UndoOffer | null;\n}\n\n/** The layers a batch turned off, and the group whose action asked, if any. */\ninterface UndoOffer {\n readonly ids: readonly string[];\n readonly group: string | null;\n}\n\n/** A change to the catalogue that is to be said aloud, and the layers that went with it. */\ninterface CatalogueNotice extends CatalogueMessage {\n /** The ids of the enabled layers that went. */\n readonly gone: readonly string[];\n}\n\n/**\n * The offer without the layers a refresh removed from the catalogue, so a\n * layer that is listed again later is not one Undo would turn on. Null when\n * nothing is left.\n */\nfunction withoutRemoved(\n offer: UndoOffer | null,\n removed: readonly string[],\n): UndoOffer | null {\n if (!offer || removed.length === 0) {\n return offer;\n }\n const ids = offer.ids.filter((id) => !removed.includes(id));\n return ids.length > 0 ? { ...offer, ids } : null;\n}\n\n/** The layers of an offer that Undo would turn on: still off, and still in the catalogue. */\nfunction stillOff(\n offer: UndoOffer,\n enabled: readonly string[],\n known: ReadonlyMap<string, LayerDefinition>,\n): string[] {\n return offer.ids.filter((id) => known.has(id) && !enabled.includes(id));\n}\n\nconst OFF: LoadResult = { status: { kind: \"off\" }, features: [] };\n\n/**\n * The state at mount: the link's layers wait, and are resolved at once when\n * the catalogue is ready already (a static one), as they are when a list\n * arrives later. `awaited` says the catalogue was not ready at mount, so its\n * list arrives later: only then is a link layer the list lacks said aloud, and\n * an empty list, because a host whose layers are there from the start has no\n * list to wait for.\n */\nfunction initialState(\n initial: LayersUrlState | undefined,\n catalogue: CatalogueState,\n awaited: boolean,\n now: number,\n): State {\n return applyCatalogue(\n {\n enabled: [],\n controls: {},\n link: {\n waiting: initial?.enabled ?? [],\n controls: initial?.controls ?? {},\n dropped: initial?.dropped,\n },\n known: [],\n reconciled: null,\n notice: null,\n sorts: {},\n results: {},\n retries: {},\n tilesUnavailable: {},\n tilesSlow: {},\n identified: {},\n identifying: false,\n selection: null,\n choices: null,\n view: null,\n focusRequest: 0,\n focusHandled: 0,\n detail: null,\n undo: null,\n },\n catalogue,\n awaited,\n now,\n );\n}\n\n/** The record without these layers' entries. */\nfunction without<T>(\n record: Readonly<Record<string, T>>,\n ids: ReadonlySet<string>,\n): Record<string, T> {\n return Object.fromEntries(\n Object.entries(record).filter(([id]) => !ids.has(id)),\n );\n}\n\n/** The state with the open card, the entries in a list of choices and the affected area of these layers closed. */\nfunction withoutOpenIn(state: State, ids: ReadonlySet<string>): State {\n const choices = state.choices?.filter((choice) => !ids.has(choice.layerId));\n return {\n ...state,\n selection:\n state.selection && ids.has(state.selection.layerId)\n ? null\n : state.selection,\n choices: choices && choices.length > 0 ? choices : null,\n detail: state.detail && ids.has(state.detail.layerId) ? null : state.detail,\n };\n}\n\n/**\n * The state with what belongs to these layers cleared, for layers that are\n * turning on or off: what they loaded, what a tap found, tiles known to have\n * failed, their open card, their entries in a list of choices and their\n * affected area.\n */\nfunction withoutTraces(state: State, ids: ReadonlySet<string>): State {\n return {\n ...withoutOpenIn(state, ids),\n results: without(state.results, ids),\n identified: without(state.identified, ids),\n tilesUnavailable: without(state.tilesUnavailable, ids),\n tilesSlow: without(state.tilesSlow, ids),\n };\n}\n\n/** A feature to open, by its layer and its id. */\ninterface FeatureHit {\n readonly layerId: string;\n readonly featureId: string;\n}\n\n/**\n * The state with these features open: one opens its card, several open the\n * list to choose from. `focus` asks for the card or list to take focus.\n */\nfunction withOpened(\n state: State,\n hits: readonly FeatureHit[],\n focus: boolean,\n): State {\n const [only] = hits;\n return {\n ...state,\n selection: hits.length === 1 && only ? { ...only } : null,\n choices: hits.length > 1 ? hits : null,\n focusRequest: state.focusRequest + (focus ? 1 : 0),\n };\n}\n\n/**\n * The state once a tap settled: the layers that answered keep what they\n * found, replacing what an earlier tap found, and what was found opens. When\n * nothing was found the card that is open stays, unless it points into a\n * layer that answered, whose features it was a feature of before.\n */\nfunction withIdentified(\n state: State,\n entries: Readonly<Record<string, IdentifiedEntry>>,\n hits: readonly FeatureHit[],\n focus: boolean,\n): State {\n const settled = {\n ...state,\n identified: { ...state.identified, ...entries },\n identifying: false,\n };\n return hits.length === 0\n ? withoutOpenIn(settled, new Set(Object.keys(entries)))\n : withOpened(settled, hits, focus);\n}\n\n/**\n * The state without what a tap found for a layer, once the tiles it asked\n * about are not the ones it shows now: the answer describes other imagery.\n * `tiles` is the URL the layer shows now, or null for a layer without tiles.\n */\nfunction withoutStaleIdentified(\n state: State,\n id: string,\n tiles: string | null,\n): State {\n const entry = state.identified[id];\n return entry === undefined || entry.tiles === tiles\n ? state\n : {\n ...withoutOpenIn(state, new Set([id])),\n identified: without(state.identified, new Set([id])),\n };\n}\n\n/** The features a layer has: those a tap found for it, else the `loaded` ones (a feed's or a query's). */\nfunction featuresFor(\n identified: State[\"identified\"],\n layerId: string,\n loaded: readonly LayerFeature[] | undefined,\n): readonly LayerFeature[] | undefined {\n return identified[layerId]?.features ?? loaded;\n}\n\n/**\n * Takes a ready list in, when it is a new one or a link layer is waiting for\n * it: the choices `reconcile` works out, the layers that went cleared as\n * turning them off clears them, and the list remembered as the one the\n * choices match. Anything else (the list already taken in, a loading or\n * failed catalogue) changes no choice, and has no result.\n */\nfunction takeIn(\n state: State,\n catalogue: CatalogueState,\n now: number,\n): { readonly taken: State; readonly result: Reconciled | null } {\n if (\n catalogue.status !== \"ready\" ||\n (catalogue.layers === state.known && state.link.waiting.length === 0)\n ) {\n return { taken: state, result: null };\n }\n const result = reconcile({\n chosen: { enabled: state.enabled, controls: state.controls },\n link: state.link,\n known: state.known,\n next: catalogue.layers,\n now,\n });\n const gone = result.switchedOff.map(({ id }) => id);\n return {\n taken: {\n ...(gone.length > 0 ? withoutTraces(state, new Set(gone)) : state),\n ...result.chosen,\n link: result.link,\n known: catalogue.layers,\n undo: withoutRemoved(state.undo, result.removed),\n },\n result,\n };\n}\n\n/**\n * The state once it has taken in a catalogue state. Only a ready list changes\n * the choices (see `takeIn`): while the catalogue loads or has failed the\n * link's layers keep waiting. A list that is the one already taken in changes\n * no choice, though its skipped count or refresh state may. Whatever the state\n * says aloud is kept as a notice for the effect that says it (see\n * `catalogueNotice`), so every transition is said once.\n */\nfunction applyCatalogue(\n state: State,\n catalogue: CatalogueState,\n awaited: boolean,\n now: number,\n): State {\n const { taken, result } = takeIn(state, catalogue, now);\n const message = catalogueNotice({\n previous: state.reconciled,\n next: catalogue,\n linkWaiting: state.link.waiting.length,\n awaited,\n change: result,\n });\n return {\n ...taken,\n reconciled: catalogue,\n notice: message\n ? { ...message, gone: result?.switchedOff.map(({ id }) => id) ?? [] }\n : taken.notice,\n };\n}\n\n/**\n * The state with a layer loading. A query layer keeps what it draws while the\n * next window loads; a feed clears its features.\n */\nfunction withLoading(state: State, load: WantedLoad): State {\n const { id, definition } = load;\n const kept = isQueryLayer(definition)\n ? (state.results[id]?.features ?? [])\n : [];\n return {\n ...state,\n results: {\n ...state.results,\n [id]: { status: { kind: \"loading\" }, features: kept },\n },\n };\n}\n\n/** The tiles a raster tile layer asks for with these controls, or null for any other layer. */\nfunction tilesOf(\n definition: LayerDefinition,\n controls: ControlValues,\n now: number,\n): string | null {\n return isRasterTileLayer(definition)\n ? tileUrl(definition, controls, now)\n : null;\n}\n\n/** The status of a tile layer that is on: unavailable outranks slow, which outranks nothing reported. */\nfunction tileStatusKind(\n state: State,\n id: string,\n): \"on\" | \"tiles-slow\" | \"tiles-unavailable\" {\n if (state.tilesUnavailable[id] !== undefined) {\n return \"tiles-unavailable\";\n }\n return state.tilesSlow[id] === undefined ? \"on\" : \"tiles-slow\";\n}\n\n/**\n * What is known of reported tiles (slow or unavailable) once the layer asks for\n * `tiles`: nothing, if they are not the ones that were reported.\n */\nfunction reportedTilesFor(\n reported: State[\"tilesUnavailable\"],\n id: string,\n tiles: string | null,\n): State[\"tilesUnavailable\"] {\n if (reported[id] === undefined || reported[id] === tiles) {\n return reported;\n }\n const rest = { ...reported };\n delete rest[id];\n return rest;\n}\n\n/** A value to sort by: numbers and readable times as numbers, else text. */\nfunction sortable(value: FieldValue | undefined): number | string | null {\n if (typeof value === \"number\") {\n return value;\n }\n if (typeof value === \"string\") {\n return parseTime(value) ?? value;\n }\n return null;\n}\n\nfunction compare(\n a: FieldValue | undefined,\n b: FieldValue | undefined,\n collator: Intl.Collator,\n): number {\n const left = sortable(a);\n const right = sortable(b);\n if (left === null || right === null) {\n if (left === right) {\n return 0;\n }\n // A missing value sorts last.\n return left === null ? 1 : -1;\n }\n if (typeof left === \"number\" && typeof right === \"number\") {\n return left - right;\n }\n return collator.compare(String(left), String(right));\n}\n\nfunction sortFeatures(\n definition: LayerDefinition,\n features: readonly LayerFeature[],\n sortId: string,\n collator: Intl.Collator,\n): readonly LayerFeature[] {\n if (!isFeedLayer(definition)) {\n return features;\n }\n const sorts = definition.list.sorts;\n const sort = sorts.find((item) => item.id === sortId) ?? sorts[0];\n if (!sort) {\n return features;\n }\n const direction = sort.direction === \"desc\" ? -1 : 1;\n return [...features].sort((a, b) => {\n const order = compare(a.fields[sort.field], b.fields[sort.field], collator);\n // Missing values stay last whichever way the list runs.\n const missing =\n a.fields[sort.field] == null || b.fields[sort.field] == null;\n return missing ? order : order * direction;\n });\n}\n\n/**\n * The state of every data layer and the actions on it, driven entirely by\n * the definitions in the catalogue: nothing here names a layer. It reads the\n * catalogue as a store, so the layers appear when a catalogue that loads\n * becomes ready; while it is loading or has failed there are none, and the\n * layers a link names wait for the first list. Each list that arrives is\n * reconciled with the choices in the same render, before anything is drawn\n * or requested: a layer that arrives has its controls' defaults, one that\n * changed keeps the values that are still valid, and an enabled one that went\n * is turned off as `setEnabled(id, false)` turns it off and said once.\n *\n * @remarks Nothing is requested until a layer is turned on. A feed layer is\n * loaded on enable, on a control change and on retry; the request for the\n * previous URL is cancelled. Tile layers need no request here: the map\n * draws their tiles, and says through `reportTilesSlow` when none has\n * loaded for a long while, `reportTilesUnavailable` when the map settled\n * with none loaded and `reportTilesRecovered` when one loads later. Loads,\n * empty feeds and failures are announced once each through the shared live\n * region, failures assertively and a tile layer that is slow or has no\n * tiles, and its recovery, politely. Turning a layer off clears its features, its open card\n * and its affected area.\n */\nexport function useDataLayers(options: UseDataLayersOptions = {}): DataLayers {\n const { layers: catalogue, layerSource } = useServices();\n const { language } = useMessages();\n const collator = useMemo(() => new Intl.Collator(language), [language]);\n const announce = useAnnounce();\n const now = useCallback(() => (options.now ?? Date.now)(), [options.now]);\n // Read when a load fails, not when it starts, and kept out of the load\n // effect's dependencies so the connection coming and going starts no load.\n const onlineRef = useLatestRef(useOnline());\n const isOffline = useCallback(() => !onlineRef.current, [onlineRef]);\n const catalogueState = useSyncExternalStore(\n catalogue.subscribe,\n catalogue.getState,\n catalogue.getState,\n );\n const definitions = readyLayers(catalogueState);\n // Fixed at mount: only a catalogue that was not ready then makes a note of a\n // link layer it does not have, or says its first list is empty.\n const [awaited] = useState(catalogueState.status !== \"ready\");\n const [stored, setState] = useState(() =>\n initialState(options.initial, catalogueState, awaited, now()),\n );\n // A new catalogue state is taken in during this render, so no render sees\n // its layers before their controls and choices are in step with them.\n let state = stored;\n if (stored.reconciled !== catalogueState) {\n state = applyCatalogue(stored, catalogueState, awaited, now());\n setState(state);\n }\n const statusView = useMemo(\n () => catalogueView(catalogueState, awaited),\n [catalogueState, awaited],\n );\n const retryCatalogue = useCallback(() => {\n if (loadFailed(catalogue.getState())) {\n void catalogue.refresh();\n }\n }, [catalogue]);\n /**\n * What the handlers below read. It follows the last committed state, set in\n * a layout effect so a render React throws away (a transition that\n * suspends) never leaves its state here, and before any effect of the\n * same commit runs. A layout effect of a child that calls a handler in the\n * same commit would still see the previous state; the handlers are only\n * called from events and the map's callbacks.\n */\n const stateRef = useRef(state);\n useLayoutEffect(() => {\n stateRef.current = state;\n }, [state]);\n const requests = useRef(\n new Map<string, { key: string; controller: AbortController }>(),\n );\n /** The request key each layer last settled for, so a settled layer is not loaded again. */\n const loadedKeys = useRef(new Map<string, string>());\n /** The window each query layer last asked for, remembered once its request is committed. */\n const queryWindows = useRef(new Map<string, Bounds>());\n const announcedStates = useRef<AnnouncedStates>(new Map());\n const detailRequest = useRef<AbortController | null>(null);\n /** The tap in flight, if there is one. */\n const identifyRun = useRef<IdentifyRun | null>(null);\n\n const byId = useMemo(\n () => new Map(definitions.map((definition) => [definition.id, definition])),\n [definitions],\n );\n\n const wanted = wantedLoads({\n enabled: state.enabled,\n definitions: byId,\n controls: state.controls,\n retries: state.retries,\n view: state.view,\n windows: queryWindows.current,\n now: now(),\n });\n const signature = wanted.map(({ id, key }) => `${id} ${key}`).join(\"\\n\");\n\n // Layers outside their zoom window, so each is told once which way to zoom.\n const limited = state.enabled.flatMap((id): LimitedLayer[] => {\n const definition = byId.get(id);\n const limit = definition && viewZoomLimit(definition, state.view);\n return definition && limit ? [{ definition, limit }] : [];\n });\n const limitedSignature = limited\n .map(({ definition, limit }) => `${definition.id} ${limit.kind}`)\n .join(\"\\n\");\n\n // A tap's request for a layer that has been turned off, left the catalogue or\n // changed its tiles in the meantime is aborted: what it would find describes\n // imagery that is no longer shown.\n const identifiable = identifiableLayers({\n definitions,\n enabled: state.enabled,\n controls: state.controls,\n now: now(),\n });\n const identifiableSignature = identifiable\n .map(({ definition, tiles }) => `${definition.id} ${tiles}`)\n .join(\"\\n\");\n // biome-ignore lint/correctness/useExhaustiveDependencies: the signature is the trigger; everything else is read through refs or is stable.\n useEffect(() => {\n identifyRun.current?.abortStale(\n new Map(\n identifiable.map(({ definition, tiles }) => [definition.id, tiles]),\n ),\n );\n }, [identifiableSignature]);\n\n // Remembers the windows asked for, and forgets those of layers that no\n // longer ask (turned off, or too far out). It runs after every commit: that\n // is cheap, and it needs no dependency list to keep in step with `wanted`.\n useEffect(() => {\n rememberWindows(queryWindows.current, wanted);\n });\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: the signatures are the triggers; everything else is read through refs or is stable.\n useEffect(() => {\n reportZoomLimits(limited, announcedStates.current, announce);\n }, [limitedSignature]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: the signature is the trigger; everything else is read through refs or is stable.\n useEffect(() => {\n /** Starts one load, shows the layer as loading, and settles it when the source answers. */\n const startLoad = (load: WantedLoad) => {\n const { id, key, definition } = load;\n const controller = new AbortController();\n requests.current.set(id, { key, controller });\n setState((current) => withLoading(current, load));\n void loadOutcome(\n layerSource,\n load,\n now,\n controller.signal,\n isOffline,\n ).then((outcome) => {\n // A load that was cancelled or replaced meanwhile is neither shown nor said.\n if (!outcome || requests.current.get(id)?.controller !== controller) {\n return;\n }\n requests.current.delete(id);\n loadedKeys.current.set(id, key);\n setState((current) => ({\n ...current,\n results: { ...current.results, [id]: outcome.result },\n }));\n reportLoad(\n definition,\n outcome.spoken,\n announcedStates.current,\n announce,\n );\n });\n };\n\n const plan = planLoads(wanted, requests.current, loadedKeys.current);\n for (const id of plan.cancel) {\n requests.current.get(id)?.controller.abort();\n requests.current.delete(id);\n }\n for (const id of plan.forget) {\n loadedKeys.current.delete(id);\n }\n for (const load of plan.start) {\n startLoad(load);\n }\n }, [signature]);\n\n // The offer to undo lets go after UNDO_TIMEOUT_MS, counted from when it was\n // made, and waits while the person is on it. It is state, not a ui timer:\n // the section unmounts when the sheet closes, and a stale offer must not\n // be there when it opens again.\n const offer = state.undo;\n const [undoHolds, setUndoHolds] = useState<Record<UndoHolder, boolean>>({\n pointer: false,\n focus: false,\n });\n const undoHeld = undoHolds.pointer || undoHolds.focus;\n useEffect(() => {\n if (!offer || undoHeld) {\n return;\n }\n const timer = setTimeout(\n () =>\n setState((previous) =>\n previous.undo === offer ? { ...previous, undo: null } : previous,\n ),\n UNDO_TIMEOUT_MS,\n );\n return () => clearTimeout(timer);\n }, [offer, undoHeld]);\n\n useEffect(\n () => () => {\n for (const request of requests.current.values()) {\n request.controller.abort();\n }\n requests.current.clear();\n detailRequest.current?.abort();\n identifyRun.current?.cancel();\n identifyRun.current = null;\n },\n [],\n );\n\n /** Drops what the hook holds outside the state for these layers: their open request for an affected area, and what they last said. */\n const forgetLayers = useCallback((ids: ReadonlySet<string>) => {\n const detail = stateRef.current.detail;\n if (detail && ids.has(detail.layerId)) {\n detailRequest.current?.abort();\n }\n for (const id of ids) {\n announcedStates.current.delete(id);\n }\n }, []);\n\n // Says a change to the catalogue, once, and lets go of what the layers that\n // went had in flight. The change is in the state, not in the render that\n // found it, so a render that React repeats or throws away says nothing.\n const spokenNotice = useRef<CatalogueNotice | null>(null);\n const notice = state.notice;\n useEffect(() => {\n if (!notice || spokenNotice.current === notice) {\n return;\n }\n spokenNotice.current = notice;\n // The change already closed the affected area of a layer that went, so no\n // request for an area should stay open.\n if (stateRef.current.detail === null) {\n detailRequest.current?.abort();\n }\n forgetLayers(new Set(notice.gone));\n announce(notice.message, {\n priority: notice.priority,\n keep: notice.keep,\n });\n }, [notice, forgetLayers, announce]);\n\n const setEnabled = useCallback(\n (id: string, enabled: boolean) => {\n const definition = byId.get(id);\n const current = stateRef.current;\n if (!definition || current.enabled.includes(id) === enabled) {\n return;\n }\n const ids = new Set([id]);\n forgetLayers(ids);\n setState((previous) => ({\n ...withoutTraces(previous, ids),\n enabled: enabled\n ? [...previous.enabled, id]\n : previous.enabled.filter((item) => item !== id),\n }));\n if (enabled && !loadsFeatures(definition)) {\n announce(announceLayerOn(textOrMessage(definition.name)), {\n priority: \"polite\",\n keep: true,\n });\n }\n },\n [announce, byId, forgetLayers],\n );\n\n const turnOff = useCallback(\n (ids: readonly string[], offOptions: { readonly group?: string } = {}) => {\n const current = stateRef.current;\n const leaving = new Set(\n ids.filter((id) => byId.has(id) && current.enabled.includes(id)),\n );\n if (leaving.size === 0) {\n return;\n }\n forgetLayers(leaving);\n setState((previous) => ({\n ...withoutTraces(previous, leaving),\n enabled: previous.enabled.filter((id) => !leaving.has(id)),\n undo: { ids: [...leaving], group: offOptions.group ?? null },\n }));\n announce(announceLayersTurnedOff(leaving.size), {\n priority: \"polite\",\n keep: true,\n });\n },\n [announce, byId, forgetLayers],\n );\n\n const undoTurnOff = useCallback(() => {\n const { undo, enabled } = stateRef.current;\n if (!undo) {\n return;\n }\n const returning = stillOff(undo, enabled, byId);\n forgetLayers(new Set(returning));\n setState((previous) => ({\n ...previous,\n // Read from `previous`, so two calls before a render add nothing twice.\n enabled: [...previous.enabled, ...stillOff(undo, previous.enabled, byId)],\n undo: null,\n }));\n if (returning.length > 0) {\n announce(announceLayersTurnedBackOn(returning.length), {\n priority: \"polite\",\n keep: true,\n });\n }\n }, [announce, byId, forgetLayers]);\n\n const holdUndo = useCallback(\n (by: UndoHolder) => setUndoHolds((holds) => ({ ...holds, [by]: true })),\n [],\n );\n const releaseUndo = useCallback(\n (by: UndoHolder) => setUndoHolds((holds) => ({ ...holds, [by]: false })),\n [],\n );\n\n const setControl = useCallback(\n (id: string, controlId: string, value: string) => {\n const definition = byId.get(id);\n if (!definition) {\n return;\n }\n setState((previous) => {\n const controls = resolveControlValues(\n definition,\n { ...previous.controls[id], [controlId]: value },\n now(),\n );\n const tiles = tilesOf(definition, controls, now());\n return withoutStaleIdentified(\n {\n ...previous,\n controls: { ...previous.controls, [id]: controls },\n tilesUnavailable: reportedTilesFor(\n previous.tilesUnavailable,\n id,\n tiles,\n ),\n tilesSlow: reportedTilesFor(previous.tilesSlow, id, tiles),\n },\n id,\n tiles,\n );\n });\n },\n [byId, now],\n );\n\n const reportTilesSlow = useCallback(\n (id: string, tiles: string) => {\n const definition = byId.get(id);\n const current = stateRef.current;\n if (\n !definition ||\n !current.enabled.includes(id) ||\n current.tilesSlow[id] === tiles ||\n current.tilesUnavailable[id] === tiles\n ) {\n return;\n }\n if (tilesOf(definition, current.controls[id] ?? {}, now()) !== tiles) {\n return;\n }\n setState((previous) => ({\n ...previous,\n tilesSlow: { ...previous.tilesSlow, [id]: tiles },\n }));\n announce(announceTilesSlow(textOrMessage(definition.name)), {\n priority: \"polite\",\n keep: true,\n });\n },\n [announce, byId, now],\n );\n\n const reportTilesUnavailable = useCallback(\n (id: string, tiles: string) => {\n const definition = byId.get(id);\n const current = stateRef.current;\n if (\n !definition ||\n !current.enabled.includes(id) ||\n current.tilesUnavailable[id] === tiles\n ) {\n return;\n }\n const controls = current.controls[id] ?? {};\n if (tilesOf(definition, controls, now()) !== tiles) {\n return;\n }\n setState((previous) => ({\n ...previous,\n tilesUnavailable: { ...previous.tilesUnavailable, [id]: tiles },\n tilesSlow: reportedTilesFor(previous.tilesSlow, id, null),\n }));\n announce(\n announceTilesUnavailable(\n textOrMessage(definition.name),\n describeChosenTime(definition, controls),\n ),\n { priority: \"polite\" },\n );\n },\n [announce, byId, now],\n );\n\n const reportTilesRecovered = useCallback(\n (id: string, tiles: string) => {\n const definition = byId.get(id);\n const current = stateRef.current;\n if (\n !definition ||\n (current.tilesUnavailable[id] !== tiles &&\n current.tilesSlow[id] !== tiles)\n ) {\n return;\n }\n setState((previous) => ({\n ...previous,\n tilesUnavailable: reportedTilesFor(previous.tilesUnavailable, id, null),\n tilesSlow: reportedTilesFor(previous.tilesSlow, id, null),\n }));\n announce(announceTilesRecovered(textOrMessage(definition.name)), {\n priority: \"polite\",\n });\n },\n [announce, byId],\n );\n\n const setSort = useCallback((id: string, sortId: string) => {\n setState((previous) => ({\n ...previous,\n sorts: { ...previous.sorts, [id]: sortId },\n }));\n }, []);\n\n const retry = useCallback((id: string) => {\n setState((previous) => ({\n ...previous,\n retries: { ...previous.retries, [id]: (previous.retries[id] ?? 0) + 1 },\n }));\n }, []);\n\n /** Cancels the tap in flight, and reports whether there was one. */\n const cancelIdentify = useCallback((): boolean => {\n const run = identifyRun.current;\n if (!run) {\n return false;\n }\n identifyRun.current = null;\n run.cancel();\n setState((previous) =>\n previous.identifying ? { ...previous, identifying: false } : previous,\n );\n return true;\n }, []);\n\n const select = useCallback(\n (\n layerId: string,\n featureId: string | null,\n selectOptions: {\n readonly focus?: boolean;\n readonly keepChoices?: boolean;\n } = {},\n ) => {\n // A card opened another way wins over a lookup still waiting: its late\n // answer must not replace the card or take focus from it.\n if (featureId !== null) {\n cancelIdentify();\n }\n setState((previous) => {\n const snapshot =\n featureId === null\n ? undefined\n : featuresFor(\n previous.identified,\n layerId,\n previous.results[layerId]?.features,\n )?.find((item) => item.id === featureId);\n return {\n ...previous,\n selection:\n featureId === null\n ? null\n : { layerId, featureId, ...(snapshot ? { snapshot } : {}) },\n choices:\n featureId !== null && selectOptions.keepChoices\n ? previous.choices\n : null,\n focusRequest: previous.focusRequest + (selectOptions.focus ? 1 : 0),\n };\n });\n },\n [cancelIdentify],\n );\n\n const choose = useCallback(\n (\n hits: readonly { readonly layerId: string; readonly featureId: string }[],\n chooseOptions: { readonly focus?: boolean } = {},\n ) => {\n const { results } = stateRef.current;\n const seen = new Set<string>();\n const found = hits.filter((hit) => {\n const key = `${hit.layerId}\\u0000${hit.featureId}`;\n if (\n seen.has(key) ||\n !results[hit.layerId]?.features.some(\n (item) => item.id === hit.featureId,\n )\n ) {\n return false;\n }\n seen.add(key);\n return true;\n });\n const [only] = found;\n if (!only) {\n return;\n }\n if (found.length === 1) {\n select(only.layerId, only.featureId, chooseOptions);\n return;\n }\n cancelIdentify();\n setState((previous) =>\n withOpened(previous, found, chooseOptions.focus === true),\n );\n announce(announceFeaturesFound(found.length), {\n priority: \"polite\",\n keep: true,\n });\n },\n [announce, cancelIdentify, select],\n );\n\n const identifyAt = useCallback(\n async (\n target: IdentifyTarget,\n identifyOptions: { readonly focus?: boolean } = {},\n ): Promise<IdentifyResult | null> => {\n cancelIdentify();\n const current = stateRef.current;\n const available = askableLayers(\n identifiableLayers({\n definitions,\n enabled: current.enabled,\n controls: current.controls,\n now: now(),\n }),\n current.tilesUnavailable,\n target.latlng,\n );\n const asking = available.slice(0, MAX_IDENTIFY_LAYERS);\n if (asking.length === 0) {\n return { asked: 0, found: 0 };\n }\n const run = new IdentifyRun();\n identifyRun.current = run;\n setState((previous) => ({ ...previous, identifying: true }));\n const answers = await Promise.all(\n asking.map((layer) => run.ask(layerSource, layer, target, now())),\n );\n if (identifyRun.current !== run) {\n return null;\n }\n identifyRun.current = null;\n // A layer turned off or re-timed while another was still held may have\n // answered before the change, and its answer no longer describes the map.\n const latest = stateRef.current;\n const shown = new Map(\n identifiableLayers({\n definitions,\n enabled: latest.enabled,\n controls: latest.controls,\n now: now(),\n }).map(({ definition, tiles }) => [definition.id, tiles]),\n );\n const outcome = outcomeOf(stillCurrent(answers, shown), available.length);\n if (!outcome) {\n setState((previous) => ({ ...previous, identifying: false }));\n return null;\n }\n setState((previous) =>\n withIdentified(\n previous,\n outcome.entries,\n outcome.hits,\n identifyOptions.focus === true,\n ),\n );\n const said = announceIdentified(outcome.report);\n if (said) {\n announce(said.message, { priority: said.priority, keep: true });\n }\n return { asked: outcome.report.asked, found: outcome.report.found };\n },\n [announce, cancelIdentify, definitions, layerSource, now],\n );\n\n const backToChoices = useCallback(\n (backOptions: { readonly focus?: boolean } = {}) => {\n setState((previous) =>\n previous.choices\n ? {\n ...previous,\n selection: null,\n detail: null,\n focusRequest: previous.focusRequest + (backOptions.focus ? 1 : 0),\n }\n : previous,\n );\n },\n [],\n );\n\n const setView = useCallback((area: Bounds, zoom: number) => {\n setState((previous) => {\n const last = previous.view;\n return last &&\n last.zoom === zoom &&\n last.area.west === area.west &&\n last.area.south === area.south &&\n last.area.east === area.east &&\n last.area.north === area.north\n ? previous\n : { ...previous, view: { area, zoom } };\n });\n }, []);\n\n const consumeFocus = useCallback(() => {\n setState((previous) =>\n previous.focusHandled === previous.focusRequest\n ? previous\n : { ...previous, focusHandled: previous.focusRequest },\n );\n }, []);\n\n const hideDetail = useCallback(() => {\n detailRequest.current?.abort();\n detailRequest.current = null;\n setState((previous) => ({ ...previous, detail: null }));\n }, []);\n\n const showDetail = useCallback(\n (layerId: string, featureId: string) => {\n const definition = byId.get(layerId);\n const feature = stateRef.current.results[layerId]?.features.find(\n (item) => item.id === featureId,\n );\n if (!definition || !feature) {\n return;\n }\n detailRequest.current?.abort();\n const controller = new AbortController();\n detailRequest.current = controller;\n const finish = (detail: Partial<DetailState>) => {\n if (detailRequest.current !== controller) {\n return;\n }\n setState((previous) =>\n previous.detail\n ? { ...previous, detail: { ...previous.detail, ...detail } }\n : previous,\n );\n };\n setState((previous) => ({\n ...previous,\n detail: { layerId, featureId, status: \"loading\", shapes: [] },\n }));\n layerSource\n .loadDetail({ definition, feature, signal: controller.signal })\n .then(\n (shapes) => {\n finish({ status: \"shown\", shapes });\n announce(announceDetailShown(String(feature.fields.title ?? \"\")), {\n priority: \"polite\",\n });\n },\n (error: unknown) => {\n if (errorKind(error) === \"aborted\" || controller.signal.aborted) {\n return;\n }\n finish({ status: \"error\", shapes: [] });\n announce(announceDetailError(), { priority: \"assertive\" });\n },\n );\n },\n [announce, byId, layerSource],\n );\n\n const layers = useMemo(\n () =>\n definitions.map((definition): DataLayerState => {\n const id = definition.id;\n const enabled = state.enabled.includes(id);\n let result = OFF;\n const limit = enabled ? viewZoomLimit(definition, state.view) : null;\n if (limit) {\n result = { status: limit, features: [] };\n } else if (enabled) {\n result =\n state.results[id] ??\n (loadsFeatures(definition)\n ? { status: { kind: \"loading\" }, features: [] }\n : {\n status: { kind: tileStatusKind(state, id) },\n features: [],\n });\n }\n const sortId =\n state.sorts[id] ??\n (isFeedLayer(definition) ? (definition.list.sorts[0]?.id ?? \"\") : \"\");\n return {\n definition,\n enabled,\n controls: state.controls[id] ?? {},\n status: result.status,\n features: result.features,\n sortId,\n sorted: sortFeatures(definition, result.features, sortId, collator),\n };\n }),\n [collator, definitions, state],\n );\n\n const selected = useMemo(() => {\n const selection = state.selection;\n const layer = layers.find(\n (item) => item.definition.id === selection?.layerId,\n );\n // A query layer's card stays open when a refresh for another part of the\n // map no longer lists its feature. Other layers close it, as they reload.\n const feature =\n featuresFor(\n state.identified,\n layer?.definition.id ?? \"\",\n layer?.features,\n )?.find((item) => item.id === selection?.featureId) ??\n (layer?.enabled && isQueryLayer(layer.definition)\n ? selection?.snapshot\n : undefined);\n return layer && feature ? { layer, feature } : null;\n }, [layers, state.identified, state.selection]);\n\n const choices = useMemo<readonly SelectedFeature[] | null>(() => {\n if (!state.choices) {\n return null;\n }\n const found = state.choices.flatMap((choice) => {\n const layer = layers.find(\n (item) => item.definition.id === choice.layerId,\n );\n const feature = featuresFor(\n state.identified,\n choice.layerId,\n layer?.features,\n )?.find((item) => item.id === choice.featureId);\n return layer && feature ? [{ layer, feature }] : [];\n });\n return found.length > 0 ? found : null;\n }, [layers, state.identified, state.choices]);\n\n const turnedOff = useMemo<TurnedOff | null>(() => {\n const ids = offer ? stillOff(offer, state.enabled, byId) : [];\n return offer && ids.length > 0\n ? { count: ids.length, ids, group: offer.group }\n : null;\n }, [offer, state.enabled, byId]);\n\n const urlValue = useMemo<LayersUrlState>(() => {\n const { waiting, controls: linked } = state.link;\n return {\n enabled: [...state.enabled, ...waiting],\n controls: Object.fromEntries([\n ...state.enabled.map((id) => [id, state.controls[id] ?? {}]),\n ...waiting.map((id) => [id, linked[id] ?? {}]),\n ]),\n };\n }, [state.enabled, state.controls, state.link]);\n\n // Several layers can share a provider; its credit is listed once. A\n // provider's notice that asks for the year gets the current one.\n const year = String(new Date(now()).getUTCFullYear());\n const credits = useMemo(() => {\n const byText = new Map<string, LayerAttribution>();\n for (const id of state.enabled) {\n for (const credit of byId.get(id)?.attribution ?? []) {\n const text = credit.text.replaceAll(\"{year}\", year);\n if (!byText.has(text)) {\n byText.set(text, { ...credit, text });\n }\n }\n }\n return [...byText.values()];\n }, [state.enabled, byId, year]);\n\n return {\n layers,\n catalogue: statusView,\n retryCatalogue,\n selected,\n choices,\n detail: state.detail,\n focusRequest: state.focusRequest,\n focusPending: state.focusRequest > state.focusHandled,\n consumeFocus,\n urlValue,\n credits,\n now,\n setEnabled,\n turnOff,\n turnedOff,\n undoTurnOff,\n holdUndo,\n releaseUndo,\n setControl,\n setSort,\n retry,\n reportTilesSlow,\n reportTilesUnavailable,\n reportTilesRecovered,\n select,\n choose,\n identifyAt,\n cancelIdentify,\n identifying: state.identifying,\n backToChoices,\n setView,\n showDetail,\n hideDetail,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkFA,IAAa,kBAAkB;;;;;;AAwT/B,SAAS,eACP,OACA,SACkB;CAClB,IAAI,CAAC,SAAS,QAAQ,WAAW,GAC/B,OAAO;CAET,MAAM,MAAM,MAAM,IAAI,QAAQ,OAAO,CAAC,QAAQ,SAAS,EAAE,CAAC;CAC1D,OAAO,IAAI,SAAS,IAAI;EAAE,GAAG;EAAO;CAAI,IAAI;AAC9C;;AAGA,SAAS,SACP,OACA,SACA,OACU;CACV,OAAO,MAAM,IAAI,QAAQ,OAAO,MAAM,IAAI,EAAE,KAAK,CAAC,QAAQ,SAAS,EAAE,CAAC;AACxE;AAEA,IAAM,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KAAK,OAAO,CAAC,IAAI,MAAM,SAAS,OAAO,CAAC,CAAC,CAAC,GAC3D,GAAG,QAAQ,KAAK,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC,CAC/C,CAAC;EACH;CACF,GAAG;EAAC,MAAM;EAAS,MAAM;EAAU,MAAM;CAAI,CAAC;CAI9C,MAAM,OAAO,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC;CACpD,MAAM,UAAU,cAAc;EAC5B,MAAM,yBAAS,IAAI,IAA8B;EACjD,KAAK,MAAM,MAAM,MAAM,SACrB,KAAK,MAAM,UAAU,KAAK,IAAI,EAAE,CAAC,EAAE,eAAe,CAAC,GAAG;GACpD,MAAM,OAAO,OAAO,KAAK,WAAW,UAAU,IAAI;GAClD,IAAI,CAAC,OAAO,IAAI,IAAI,GAClB,OAAO,IAAI,MAAM;IAAE,GAAG;IAAQ;GAAK,CAAC;EAExC;EAEF,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC;CAC5B,GAAG;EAAC,MAAM;EAAS;EAAM;CAAI,CAAC;CAE9B,OAAO;EACL;EACA,WAAW;EACX;EACA;EACA;EACA,QAAQ,MAAM;EACd,cAAc,MAAM;EACpB,cAAc,MAAM,eAAe,MAAM;EACzC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,MAAM;EACnB;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useMessages, useSelectionStore } from "../services/hooks.js";
|
|
2
|
+
import { useAnnounce } from "../ui/LiveRegion/LiveRegion.js";
|
|
3
|
+
import { featureTitle } from "./featureTitle.js";
|
|
4
|
+
import { addedAnnouncement, clearedAnnouncement, removedAnnouncement } from "./selectionMessages.js";
|
|
5
|
+
import { reconcileSnapshots, refsOfRemovedLayers, resolveSelection, selectableRefs } from "./selectionResolve.js";
|
|
6
|
+
import { createFormatterRegistry, featureRefKey } from "@mapcairn/core";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
8
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
9
|
+
// src/layers/useFeatureSelection.ts
|
|
10
|
+
var DEFAULT_FORMATTERS = createFormatterRegistry();
|
|
11
|
+
var NO_SNAPSHOTS = /* @__PURE__ */ new Map();
|
|
12
|
+
var NO_ENTRIES = [];
|
|
13
|
+
/** A change that does nothing: the methods of {@link NO_STORE}. */
|
|
14
|
+
var DO_NOTHING = () => void 0;
|
|
15
|
+
var NO_REFS = Object.freeze([]);
|
|
16
|
+
/**
|
|
17
|
+
* Stands in while the host supplies no store, so every hook below is called
|
|
18
|
+
* either way. It holds nothing, refuses every addition (its limit is zero),
|
|
19
|
+
* and the state built from it is never returned.
|
|
20
|
+
*/
|
|
21
|
+
var NO_STORE = {
|
|
22
|
+
limit: 0,
|
|
23
|
+
getState: () => NO_REFS,
|
|
24
|
+
subscribe: () => DO_NOTHING,
|
|
25
|
+
add: DO_NOTHING,
|
|
26
|
+
remove: DO_NOTHING,
|
|
27
|
+
replace: DO_NOTHING,
|
|
28
|
+
clear: DO_NOTHING
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The selected set as the ui shows it: the host's `FeatureSelection` store,
|
|
32
|
+
* resolved against the layers, with the select-mode flag and one message to
|
|
33
|
+
* the live region for each change a person makes.
|
|
34
|
+
*
|
|
35
|
+
* Call it once, in the host beside `useDataLayers`, and hand the result down
|
|
36
|
+
* with `SelectionProvider`: its state outlives the sheet's sections, which
|
|
37
|
+
* unmount. It returns null when the host supplies no store, so a host without
|
|
38
|
+
* one offers no selection.
|
|
39
|
+
*
|
|
40
|
+
* @remarks A reference shows its layer's loaded feature, else a snapshot kept
|
|
41
|
+
* while it was loaded, but only while its layer is on and is a feed layer.
|
|
42
|
+
* Otherwise it is not shown, and it stays in the store and counts. Turning a
|
|
43
|
+
* layer off drops nothing and says nothing here: `useDataLayers` announces
|
|
44
|
+
* the turning off itself, and its Undo brings the references back. A layer
|
|
45
|
+
* that a ready catalogue removes is different: it cannot come back by Undo,
|
|
46
|
+
* so its references are dropped, once and in one message, when the removal
|
|
47
|
+
* is seen. Nothing is dropped at mount, while the catalogue is loading or
|
|
48
|
+
* has failed, for a layer the catalogue never listed, or for a reference a
|
|
49
|
+
* store hydrates later. A change made outside (hydration, a failed save)
|
|
50
|
+
* updates `entries` and is not announced. Each message carries the new
|
|
51
|
+
* total, because the live region replaces a waiting message that is not
|
|
52
|
+
* kept with a later one when both arrive within `THROTTLE_MS` of the last
|
|
53
|
+
* one sent. The refusal of a batch past the limit is assertive, the rest
|
|
54
|
+
* polite.
|
|
55
|
+
*/
|
|
56
|
+
function useFeatureSelection(layers, options = {}) {
|
|
57
|
+
const { formatters = DEFAULT_FORMATTERS } = options;
|
|
58
|
+
const hostStore = useSelectionStore();
|
|
59
|
+
const store = hostStore ?? NO_STORE;
|
|
60
|
+
const announce = useAnnounce();
|
|
61
|
+
const messages = useMessages();
|
|
62
|
+
const refs = useSyncExternalStore(store.subscribe, store.getState, store.getState);
|
|
63
|
+
const [selecting, setSelecting] = useState(false);
|
|
64
|
+
const [snapshots, setSnapshots] = useState(NO_SNAPSHOTS);
|
|
65
|
+
const layerStates = layers.layers;
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!hostStore) return;
|
|
68
|
+
setSnapshots((previous) => reconcileSnapshots(previous, refs, layerStates));
|
|
69
|
+
}, [
|
|
70
|
+
hostStore,
|
|
71
|
+
refs,
|
|
72
|
+
layerStates
|
|
73
|
+
]);
|
|
74
|
+
/**
|
|
75
|
+
* The entries of the last render. Resolving against them keeps every entry
|
|
76
|
+
* that did not change, so a map move, which makes new layer states with the
|
|
77
|
+
* same features, leaves `entries` and the state built from it as they were.
|
|
78
|
+
* A render React discards can leave a result here, which is harmless: it is
|
|
79
|
+
* only compared with by value.
|
|
80
|
+
*/
|
|
81
|
+
const keptEntries = useRef(NO_ENTRIES);
|
|
82
|
+
const entries = useMemo(() => {
|
|
83
|
+
if (!hostStore) return NO_ENTRIES;
|
|
84
|
+
const next = resolveSelection(refs, layerStates, snapshots, keptEntries.current);
|
|
85
|
+
keptEntries.current = next;
|
|
86
|
+
return next;
|
|
87
|
+
}, [
|
|
88
|
+
hostStore,
|
|
89
|
+
refs,
|
|
90
|
+
layerStates,
|
|
91
|
+
snapshots
|
|
92
|
+
]);
|
|
93
|
+
const latest = useLatestRef({
|
|
94
|
+
layerStates,
|
|
95
|
+
snapshots,
|
|
96
|
+
formatters,
|
|
97
|
+
now: layers.now,
|
|
98
|
+
messages
|
|
99
|
+
});
|
|
100
|
+
const titleOf = useCallback((ref) => {
|
|
101
|
+
const current = latest.current;
|
|
102
|
+
const [entry] = resolveSelection([ref], current.layerStates, current.snapshots);
|
|
103
|
+
return entry?.status === "shown" ? featureTitle(entry.definition, entry.feature, current.formatters, {
|
|
104
|
+
now: current.now(),
|
|
105
|
+
catalogue: current.messages
|
|
106
|
+
}) : null;
|
|
107
|
+
}, [latest]);
|
|
108
|
+
/**
|
|
109
|
+
* Changes the store, then says what the change did, worked out from the set
|
|
110
|
+
* before and after it. The store gives no result, so a refused batch is told
|
|
111
|
+
* from one of duplicates by comparing the two sets.
|
|
112
|
+
*/
|
|
113
|
+
const change = useCallback((mutate, describe) => {
|
|
114
|
+
const before = store.getState();
|
|
115
|
+
mutate(store);
|
|
116
|
+
const said = describe(before, store.getState(), store);
|
|
117
|
+
if (said) announce(said.message, said.options);
|
|
118
|
+
}, [store, announce]);
|
|
119
|
+
const add = useCallback((requested) => {
|
|
120
|
+
const wanted = selectableRefs(requested, latest.current.layerStates);
|
|
121
|
+
change((selection) => selection.add(wanted), (before, after, selection) => addedAnnouncement(wanted, before, after, selection.limit, titleOf));
|
|
122
|
+
}, [
|
|
123
|
+
change,
|
|
124
|
+
titleOf,
|
|
125
|
+
latest
|
|
126
|
+
]);
|
|
127
|
+
const remove = useCallback((removed) => change((selection) => selection.remove(removed), (before, after) => removedAnnouncement(before, after, titleOf)), [change, titleOf]);
|
|
128
|
+
const clear = useCallback(() => change((selection) => selection.clear(), (before) => clearedAnnouncement(before)), [change]);
|
|
129
|
+
/**
|
|
130
|
+
* The ids of the list the catalogue last held while it was ready: none
|
|
131
|
+
* until its first ready list. Loading and failed states leave it as it was,
|
|
132
|
+
* so a later list is compared with the last one that was ready.
|
|
133
|
+
*/
|
|
134
|
+
const listedLayerIds = useRef(null);
|
|
135
|
+
const catalogueReady = layers.catalogue.status === "ready";
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!hostStore || !catalogueReady) return;
|
|
138
|
+
const before = listedLayerIds.current;
|
|
139
|
+
const now = new Set(layerStates.map((layer) => layer.definition.id));
|
|
140
|
+
listedLayerIds.current = now;
|
|
141
|
+
if (!before) return;
|
|
142
|
+
const removed = refsOfRemovedLayers(hostStore.getState(), before, now);
|
|
143
|
+
if (removed.length > 0) remove(removed);
|
|
144
|
+
}, [
|
|
145
|
+
hostStore,
|
|
146
|
+
catalogueReady,
|
|
147
|
+
layerStates,
|
|
148
|
+
remove
|
|
149
|
+
]);
|
|
150
|
+
const toggle = useCallback((ref) => {
|
|
151
|
+
const key = featureRefKey(ref);
|
|
152
|
+
(store.getState().some((held) => featureRefKey(held) === key) ? remove : add)([ref]);
|
|
153
|
+
}, [
|
|
154
|
+
store,
|
|
155
|
+
add,
|
|
156
|
+
remove
|
|
157
|
+
]);
|
|
158
|
+
return useMemo(() => hostStore ? {
|
|
159
|
+
entries,
|
|
160
|
+
limit: hostStore.limit,
|
|
161
|
+
selecting,
|
|
162
|
+
setSelecting,
|
|
163
|
+
toggle,
|
|
164
|
+
add,
|
|
165
|
+
remove,
|
|
166
|
+
clear
|
|
167
|
+
} : null, [
|
|
168
|
+
hostStore,
|
|
169
|
+
entries,
|
|
170
|
+
selecting,
|
|
171
|
+
toggle,
|
|
172
|
+
add,
|
|
173
|
+
remove,
|
|
174
|
+
clear
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
export { useFeatureSelection };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=useFeatureSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeatureSelection.js","names":[],"sources":["../../src/layers/useFeatureSelection.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n createFormatterRegistry,\n type FeatureRef,\n type FeatureSelection,\n type FormatterRegistry,\n featureRefKey,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { useMessages, useSelectionStore } from \"../services\";\nimport { useAnnounce } from \"../ui/LiveRegion\";\nimport { featureTitle } from \"./featureTitle\";\nimport {\n addedAnnouncement,\n clearedAnnouncement,\n removedAnnouncement,\n type SelectionAnnouncement,\n type TitleOf,\n} from \"./selectionMessages\";\nimport {\n reconcileSnapshots,\n refsOfRemovedLayers,\n resolveSelection,\n type SelectedEntry,\n type SelectionSnapshots,\n selectableRefs,\n} from \"./selectionResolve\";\nimport type { DataLayers } from \"./useDataLayers\";\n\nconst DEFAULT_FORMATTERS = createFormatterRegistry();\nconst NO_SNAPSHOTS: SelectionSnapshots = new Map();\nconst NO_ENTRIES: readonly SelectedEntry[] = [];\n\n/** A change that does nothing: the methods of {@link NO_STORE}. */\nconst DO_NOTHING = () => undefined;\nconst NO_REFS: readonly FeatureRef[] = Object.freeze([]);\n\n/**\n * Stands in while the host supplies no store, so every hook below is called\n * either way. It holds nothing, refuses every addition (its limit is zero),\n * and the state built from it is never returned.\n */\nconst NO_STORE: FeatureSelection = {\n limit: 0,\n getState: () => NO_REFS,\n subscribe: () => DO_NOTHING,\n add: DO_NOTHING,\n remove: DO_NOTHING,\n replace: DO_NOTHING,\n clear: DO_NOTHING,\n};\n\n/** Options for {@link useFeatureSelection}. */\nexport interface UseFeatureSelectionOptions {\n /** The formatters card templates may name, for the titles in messages. Defaults to the built-ins. */\n readonly formatters?: FormatterRegistry;\n}\n\n/** What {@link useFeatureSelection} returns: the selected set as the ui shows it, and every action on it. */\nexport interface FeatureSelectionState {\n /** The selected references in selection order, each resolved against the layers (see {@link SelectedEntry}). */\n readonly entries: readonly SelectedEntry[];\n /** The most references the store holds. */\n readonly limit: number;\n /** Whether select mode is on. It is only a flag: nothing here reads it. */\n readonly selecting: boolean;\n /** Turns select mode on or off. */\n setSelecting(selecting: boolean): void;\n /** Selects the feature, or deselects it when it is selected. */\n toggle(ref: FeatureRef): void;\n /**\n * Selects the references that are not yet selected and belong to a feed\n * layer. The store refuses the whole batch when it would pass its limit.\n */\n add(refs: readonly FeatureRef[]): void;\n /** Deselects the references that are selected. Always allowed. */\n remove(refs: readonly FeatureRef[]): void;\n /** Empties the selection. */\n clear(): void;\n}\n\n/**\n * The selected set as the ui shows it: the host's `FeatureSelection` store,\n * resolved against the layers, with the select-mode flag and one message to\n * the live region for each change a person makes.\n *\n * Call it once, in the host beside `useDataLayers`, and hand the result down\n * with `SelectionProvider`: its state outlives the sheet's sections, which\n * unmount. It returns null when the host supplies no store, so a host without\n * one offers no selection.\n *\n * @remarks A reference shows its layer's loaded feature, else a snapshot kept\n * while it was loaded, but only while its layer is on and is a feed layer.\n * Otherwise it is not shown, and it stays in the store and counts. Turning a\n * layer off drops nothing and says nothing here: `useDataLayers` announces\n * the turning off itself, and its Undo brings the references back. A layer\n * that a ready catalogue removes is different: it cannot come back by Undo,\n * so its references are dropped, once and in one message, when the removal\n * is seen. Nothing is dropped at mount, while the catalogue is loading or\n * has failed, for a layer the catalogue never listed, or for a reference a\n * store hydrates later. A change made outside (hydration, a failed save)\n * updates `entries` and is not announced. Each message carries the new\n * total, because the live region replaces a waiting message that is not\n * kept with a later one when both arrive within `THROTTLE_MS` of the last\n * one sent. The refusal of a batch past the limit is assertive, the rest\n * polite.\n */\nexport function useFeatureSelection(\n layers: DataLayers,\n options: UseFeatureSelectionOptions = {},\n): FeatureSelectionState | null {\n const { formatters = DEFAULT_FORMATTERS } = options;\n const hostStore = useSelectionStore();\n const store = hostStore ?? NO_STORE;\n const announce = useAnnounce();\n const messages = useMessages();\n const refs = useSyncExternalStore(\n store.subscribe,\n store.getState,\n store.getState,\n );\n const [selecting, setSelecting] = useState(false);\n const [snapshots, setSnapshots] = useState(NO_SNAPSHOTS);\n const layerStates = layers.layers;\n\n useEffect(() => {\n if (!hostStore) {\n return;\n }\n setSnapshots((previous) => reconcileSnapshots(previous, refs, layerStates));\n }, [hostStore, refs, layerStates]);\n\n /**\n * The entries of the last render. Resolving against them keeps every entry\n * that did not change, so a map move, which makes new layer states with the\n * same features, leaves `entries` and the state built from it as they were.\n * A render React discards can leave a result here, which is harmless: it is\n * only compared with by value.\n */\n const keptEntries = useRef(NO_ENTRIES);\n const entries = useMemo(() => {\n if (!hostStore) {\n return NO_ENTRIES;\n }\n const next = resolveSelection(\n refs,\n layerStates,\n snapshots,\n keptEntries.current,\n );\n keptEntries.current = next;\n return next;\n }, [hostStore, refs, layerStates, snapshots]);\n\n const latest = useLatestRef({\n layerStates,\n snapshots,\n formatters,\n now: layers.now,\n messages,\n });\n const titleOf = useCallback<TitleOf>(\n (ref) => {\n const current = latest.current;\n const [entry] = resolveSelection(\n [ref],\n current.layerStates,\n current.snapshots,\n );\n return entry?.status === \"shown\"\n ? featureTitle(entry.definition, entry.feature, current.formatters, {\n now: current.now(),\n catalogue: current.messages,\n })\n : null;\n },\n [latest],\n );\n\n /**\n * Changes the store, then says what the change did, worked out from the set\n * before and after it. The store gives no result, so a refused batch is told\n * from one of duplicates by comparing the two sets.\n */\n const change = useCallback(\n (\n mutate: (selection: FeatureSelection) => void,\n describe: (\n before: readonly FeatureRef[],\n after: readonly FeatureRef[],\n selection: FeatureSelection,\n ) => SelectionAnnouncement | null,\n ) => {\n const before = store.getState();\n mutate(store);\n const said = describe(before, store.getState(), store);\n if (said) {\n announce(said.message, said.options);\n }\n },\n [store, announce],\n );\n\n const add = useCallback(\n (requested: readonly FeatureRef[]) => {\n const wanted = selectableRefs(requested, latest.current.layerStates);\n change(\n (selection) => selection.add(wanted),\n (before, after, selection) =>\n addedAnnouncement(wanted, before, after, selection.limit, titleOf),\n );\n },\n [change, titleOf, latest],\n );\n\n const remove = useCallback(\n (removed: readonly FeatureRef[]) =>\n change(\n (selection) => selection.remove(removed),\n (before, after) => removedAnnouncement(before, after, titleOf),\n ),\n [change, titleOf],\n );\n\n const clear = useCallback(\n () =>\n change(\n (selection) => selection.clear(),\n (before) => clearedAnnouncement(before),\n ),\n [change],\n );\n\n /**\n * The ids of the list the catalogue last held while it was ready: none\n * until its first ready list. Loading and failed states leave it as it was,\n * so a later list is compared with the last one that was ready.\n */\n const listedLayerIds = useRef<ReadonlySet<string> | null>(null);\n const catalogueReady = layers.catalogue.status === \"ready\";\n useEffect(() => {\n if (!hostStore || !catalogueReady) {\n return;\n }\n const before = listedLayerIds.current;\n const now = new Set(layerStates.map((layer) => layer.definition.id));\n listedLayerIds.current = now;\n if (!before) {\n return;\n }\n const removed = refsOfRemovedLayers(hostStore.getState(), before, now);\n if (removed.length > 0) {\n remove(removed);\n }\n }, [hostStore, catalogueReady, layerStates, remove]);\n\n const toggle = useCallback(\n (ref: FeatureRef) => {\n const key = featureRefKey(ref);\n const selected = store\n .getState()\n .some((held) => featureRefKey(held) === key);\n (selected ? remove : add)([ref]);\n },\n [store, add, remove],\n );\n\n return useMemo(\n () =>\n hostStore\n ? {\n entries,\n limit: hostStore.limit,\n selecting,\n setSelecting,\n toggle,\n add,\n remove,\n clear,\n }\n : null,\n [hostStore, entries, selecting, toggle, add, remove, clear],\n );\n}\n"],"mappings":";;;;;;;;;AAsCA,IAAM,qBAAqB,wBAAwB;AACnD,IAAM,+BAAmC,IAAI,IAAI;AACjD,IAAM,aAAuC,CAAC;;AAG9C,IAAM,mBAAmB,KAAA;AACzB,IAAM,UAAiC,OAAO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AAc,IAAI,MAAM,GACzC,IAAW,SAAS,IAAA,CAAK,CAAC,GAAG,CAAC;CACjC,GACA;EAAC;EAAO;EAAK;CAAM,CACrB;CAEA,OAAO,cAEH,YACI;EACE;EACA,OAAO,UAAU;EACjB;EACA;EACA;EACA;EACA;EACA;CACF,IACA,MACN;EAAC;EAAW;EAAS;EAAW;EAAQ;EAAK;EAAQ;CAAK,CAC5D;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from "react";
|
|
2
|
+
// src/layers/useScrolls.ts
|
|
3
|
+
/**
|
|
4
|
+
* Whether the element's content is taller than the element, so it scrolls.
|
|
5
|
+
* Re-checked when the element or its content changes size: the content grows
|
|
6
|
+
* without the element growing when something else caps its height.
|
|
7
|
+
*
|
|
8
|
+
* @param ref - The scrolling element. Its children are observed too, because
|
|
9
|
+
* a child changes size as content comes and goes while the element, capped,
|
|
10
|
+
* does not.
|
|
11
|
+
* @param active - Whether the element is on the page. Nothing is observed, and
|
|
12
|
+
* the answer is false, while it is not.
|
|
13
|
+
*/
|
|
14
|
+
function useScrolls(ref, active) {
|
|
15
|
+
const [scrolls, setScrolls] = useState(false);
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
const element = ref.current;
|
|
18
|
+
if (!(active && element) || typeof ResizeObserver === "undefined") {
|
|
19
|
+
setScrolls(false);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const check = () => {
|
|
23
|
+
setScrolls(element.scrollHeight > element.clientHeight);
|
|
24
|
+
};
|
|
25
|
+
check();
|
|
26
|
+
const observer = new ResizeObserver(check);
|
|
27
|
+
observer.observe(element);
|
|
28
|
+
for (const child of element.children) observer.observe(child);
|
|
29
|
+
return () => {
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
};
|
|
32
|
+
}, [ref, active]);
|
|
33
|
+
return scrolls;
|
|
34
|
+
}
|
|
35
|
+
export { useScrolls };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=useScrolls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrolls.js","names":[],"sources":["../../src/layers/useScrolls.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { type RefObject, useLayoutEffect, useState } from \"react\";\n\n/**\n * Whether the element's content is taller than the element, so it scrolls.\n * Re-checked when the element or its content changes size: the content grows\n * without the element growing when something else caps its height.\n *\n * @param ref - The scrolling element. Its children are observed too, because\n * a child changes size as content comes and goes while the element, capped,\n * does not.\n * @param active - Whether the element is on the page. Nothing is observed, and\n * the answer is false, while it is not.\n */\nexport function useScrolls(\n ref: RefObject<HTMLElement | null>,\n active: boolean,\n): boolean {\n const [scrolls, setScrolls] = useState(false);\n useLayoutEffect(() => {\n const element = ref.current;\n if (!(active && element) || typeof ResizeObserver === \"undefined\") {\n setScrolls(false);\n return;\n }\n const check = () => {\n setScrolls(element.scrollHeight > element.clientHeight);\n };\n check();\n const observer = new ResizeObserver(check);\n observer.observe(element);\n for (const child of element.children) {\n observer.observe(child);\n }\n return () => {\n observer.disconnect();\n };\n }, [ref, active]);\n return scrolls;\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,WACd,KACA,QACS;CACT,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,sBAAsB;EACpB,MAAM,UAAU,IAAI;EACpB,IAAI,EAAE,UAAU,YAAY,OAAO,mBAAmB,aAAa;GACjE,WAAW,KAAK;GAChB;EACF;EACA,MAAM,cAAc;GAClB,WAAW,QAAQ,eAAe,QAAQ,YAAY;EACxD;EACA,MAAM;EACN,MAAM,WAAW,IAAI,eAAe,KAAK;EACzC,SAAS,QAAQ,OAAO;EACxB,KAAK,MAAM,SAAS,QAAQ,UAC1B,SAAS,QAAQ,KAAK;EAExB,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG,CAAC,KAAK,MAAM,CAAC;CAChB,OAAO;AACT"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { useBasemapAvailability } from "../../services/basemapAvailability.js";
|
|
2
|
+
import { useBasemaps, useMessages, useResolveText, useSaveData } from "../../services/hooks.js";
|
|
3
|
+
import { Button } from "../../ui/Button/Button.js";
|
|
4
|
+
import { Icon } from "../../ui/Icon/Icon.js";
|
|
5
|
+
import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
|
|
6
|
+
import { visuallyHidden } from "../../ui/VisuallyHidden/VisuallyHidden.styles.js";
|
|
7
|
+
import { badge, badgeIcon, dataNote, grid, image, name, retry, swatch, swatchColourVar, thumb, tile } from "./BasemapPicker.styles.js";
|
|
8
|
+
import { announceBasemap, usesMoreData } from "@mapcairn/core";
|
|
9
|
+
import { Check } from "lucide-react";
|
|
10
|
+
import { useCallback, useId, useRef, useState } from "react";
|
|
11
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
// src/panels/BasemapPicker/BasemapPicker.tsx
|
|
13
|
+
/** Intrinsic size of a basemap preview, in CSS pixels. Reserves the space before load. */
|
|
14
|
+
var THUMB_WIDTH = 160;
|
|
15
|
+
var THUMB_HEIGHT = 120;
|
|
16
|
+
/**
|
|
17
|
+
* Chooses the basemap: a three-across grid of previews as a radio group, one
|
|
18
|
+
* tile for each basemap the host offers (`useBasemaps`).
|
|
19
|
+
*
|
|
20
|
+
* Each tile is a native radio input, visually hidden and drawn through its
|
|
21
|
+
* label. Native radios give one tab stop for the group, arrow keys that move
|
|
22
|
+
* and select in one step (wrapping at the ends and following the writing
|
|
23
|
+
* direction) and the radio role in every screen reader, with no script. The
|
|
24
|
+
* selected tile has an accent outline and a check badge, so selection never
|
|
25
|
+
* relies on colour. A preview that fails to load gives way to the basemap's
|
|
26
|
+
* swatch, as a basemap with no preview does, with the name still visible. The
|
|
27
|
+
* basemap does not follow the interface theme: a host's dark basemap is an
|
|
28
|
+
* ordinary choice, as the others are.
|
|
29
|
+
*
|
|
30
|
+
* @remarks In Save data mode (`useSaveData`), and for a basemap that has no
|
|
31
|
+
* preview image, no preview is requested: the tile shows the same frame
|
|
32
|
+
* with a plain colour swatch, the basemap's own `swatch` colour or else the
|
|
33
|
+
* map background. A basemap whose tiles are images (`usesMoreData`: a
|
|
34
|
+
* raster map, or imagery under labels) carries the note "Uses more data". Names,
|
|
35
|
+
* the radios and the selection badge are unchanged, and every basemap can
|
|
36
|
+
* still be chosen.
|
|
37
|
+
*
|
|
38
|
+
* A basemap marked unavailable (`useBasemapAvailability`, which the host
|
|
39
|
+
* sets when every tile of it failed) has the words "Not available right
|
|
40
|
+
* now" inside its label, so they are part of the radio's name, and its
|
|
41
|
+
* radio is natively disabled, so the arrow keys skip it, unless it is the
|
|
42
|
+
* chosen one. While any basemap is marked, a "Try again" button under the
|
|
43
|
+
* group clears every mark, so the map judges a basemap again when it is
|
|
44
|
+
* chosen, and moves focus to the chosen radio, because the button goes.
|
|
45
|
+
*/
|
|
46
|
+
function BasemapPicker({ value, onChange }) {
|
|
47
|
+
const groupName = useId();
|
|
48
|
+
const announce = useAnnounce();
|
|
49
|
+
const catalogue = useBasemaps();
|
|
50
|
+
const { t } = useMessages();
|
|
51
|
+
const resolve = useResolveText();
|
|
52
|
+
const shownId = catalogue.resolve(value).id;
|
|
53
|
+
const saveData = useSaveData();
|
|
54
|
+
const { unavailable, clear } = useBasemapAvailability();
|
|
55
|
+
const group = useRef(null);
|
|
56
|
+
const tryAgain = () => {
|
|
57
|
+
clear();
|
|
58
|
+
group.current?.querySelector("input:checked")?.focus();
|
|
59
|
+
};
|
|
60
|
+
const choose = (basemap) => {
|
|
61
|
+
announce(announceBasemap(resolve(basemap.name)));
|
|
62
|
+
onChange(basemap.id);
|
|
63
|
+
};
|
|
64
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
65
|
+
ref: group,
|
|
66
|
+
role: "radiogroup",
|
|
67
|
+
"aria-label": t("panels.basemap.groupLabel", {}),
|
|
68
|
+
className: grid,
|
|
69
|
+
"data-testid": "basemap-picker",
|
|
70
|
+
children: catalogue.basemaps.map((basemap) => /* @__PURE__ */ jsx(BasemapTile, {
|
|
71
|
+
basemap,
|
|
72
|
+
groupName,
|
|
73
|
+
selected: basemap.id === shownId,
|
|
74
|
+
saveData,
|
|
75
|
+
unavailable: unavailable.has(basemap.id),
|
|
76
|
+
onChoose: () => choose(basemap)
|
|
77
|
+
}, basemap.id))
|
|
78
|
+
}), unavailable.size > 0 ? /* @__PURE__ */ jsx("div", {
|
|
79
|
+
className: retry,
|
|
80
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
81
|
+
variant: "quiet",
|
|
82
|
+
onClick: tryAgain,
|
|
83
|
+
"data-testid": "basemap-try-again",
|
|
84
|
+
children: t("panels.basemap.tryAgain", {})
|
|
85
|
+
})
|
|
86
|
+
}) : null] });
|
|
87
|
+
}
|
|
88
|
+
function BasemapTile({ basemap, groupName, selected, saveData, unavailable, onChoose }) {
|
|
89
|
+
const { t } = useMessages();
|
|
90
|
+
const resolve = useResolveText();
|
|
91
|
+
const [failed, setFailed] = useState(false);
|
|
92
|
+
const preview = saveData ? void 0 : basemap.thumbnail;
|
|
93
|
+
const showSwatch = preview === void 0 || failed;
|
|
94
|
+
const watchImage = useCallback((node) => {
|
|
95
|
+
if (!node) return;
|
|
96
|
+
const fail = () => setFailed(true);
|
|
97
|
+
node.addEventListener("error", fail);
|
|
98
|
+
return () => node.removeEventListener("error", fail);
|
|
99
|
+
}, []);
|
|
100
|
+
const swatchColour = basemap.swatch;
|
|
101
|
+
const paintSwatch = useCallback((element) => {
|
|
102
|
+
if (!element) return;
|
|
103
|
+
if (swatchColour === void 0) element.style.removeProperty(swatchColourVar);
|
|
104
|
+
else element.style.setProperty(swatchColourVar, swatchColour);
|
|
105
|
+
}, [swatchColour]);
|
|
106
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
107
|
+
className: tile,
|
|
108
|
+
"data-testid": `basemap-option-${basemap.id}`,
|
|
109
|
+
children: [
|
|
110
|
+
/* @__PURE__ */ jsx("input", {
|
|
111
|
+
type: "radio",
|
|
112
|
+
className: visuallyHidden,
|
|
113
|
+
name: groupName,
|
|
114
|
+
value: basemap.id,
|
|
115
|
+
checked: selected,
|
|
116
|
+
disabled: unavailable && !selected,
|
|
117
|
+
onChange: onChoose
|
|
118
|
+
}),
|
|
119
|
+
/* @__PURE__ */ jsxs("span", {
|
|
120
|
+
className: thumb({
|
|
121
|
+
selected,
|
|
122
|
+
unavailable
|
|
123
|
+
}),
|
|
124
|
+
children: [
|
|
125
|
+
showSwatch ? /* @__PURE__ */ jsx("span", {
|
|
126
|
+
className: swatch,
|
|
127
|
+
ref: paintSwatch,
|
|
128
|
+
"data-testid": `basemap-swatch-${basemap.id}`
|
|
129
|
+
}) : null,
|
|
130
|
+
showSwatch ? null : /* @__PURE__ */ jsx("img", {
|
|
131
|
+
className: image,
|
|
132
|
+
src: preview,
|
|
133
|
+
alt: "",
|
|
134
|
+
width: THUMB_WIDTH,
|
|
135
|
+
height: THUMB_HEIGHT,
|
|
136
|
+
loading: "lazy",
|
|
137
|
+
decoding: "async",
|
|
138
|
+
ref: watchImage
|
|
139
|
+
}),
|
|
140
|
+
selected ? /* @__PURE__ */ jsx("span", {
|
|
141
|
+
className: badge,
|
|
142
|
+
"data-testid": `basemap-selected-${basemap.id}`,
|
|
143
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
144
|
+
icon: Check,
|
|
145
|
+
className: badgeIcon
|
|
146
|
+
})
|
|
147
|
+
}) : null
|
|
148
|
+
]
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ jsx("span", {
|
|
151
|
+
className: name({ selected }),
|
|
152
|
+
children: resolve(basemap.name)
|
|
153
|
+
}),
|
|
154
|
+
unavailable ? /* @__PURE__ */ jsx("span", {
|
|
155
|
+
className: dataNote,
|
|
156
|
+
"data-testid": `basemap-unavailable-note-${basemap.id}`,
|
|
157
|
+
children: t("panels.basemap.unavailable", {})
|
|
158
|
+
}) : null,
|
|
159
|
+
saveData && usesMoreData(basemap) ? /* @__PURE__ */ jsx("span", {
|
|
160
|
+
className: dataNote,
|
|
161
|
+
"data-testid": `basemap-data-note-${basemap.id}`,
|
|
162
|
+
children: t("panels.basemap.usesMoreData", {})
|
|
163
|
+
}) : null
|
|
164
|
+
]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
export { BasemapPicker };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=BasemapPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasemapPicker.js","names":["_Fragment"],"sources":["../../../src/panels/BasemapPicker/BasemapPicker.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceBasemap,\n type BasemapDefinition,\n usesMoreData,\n} from \"@mapcairn/core\";\nimport { Check } from \"lucide-react\";\nimport { useCallback, useId, useRef, useState } from \"react\";\nimport {\n useBasemapAvailability,\n useBasemaps,\n useMessages,\n useResolveText,\n useSaveData,\n} from \"../../services\";\nimport { Button } from \"../../ui/Button\";\nimport { Icon } from \"../../ui/Icon\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\nimport { visuallyHidden } from \"../../ui/VisuallyHidden/VisuallyHidden.css\";\nimport {\n badge,\n badgeIcon,\n dataNote,\n grid,\n image,\n name,\n retry,\n swatch,\n swatchColourVar,\n thumb,\n tile,\n} from \"./BasemapPicker.css\";\n\n/** Intrinsic size of a basemap preview, in CSS pixels. Reserves the space before load. */\nconst THUMB_WIDTH = 160;\nconst THUMB_HEIGHT = 120;\n\n/** Props for {@link BasemapPicker}. */\nexport interface BasemapPickerProps {\n /**\n * The chosen basemap id. An id that names no basemap on offer is shown as\n * the default basemap.\n */\n readonly value: string;\n /** Called with the id of the tile the user chose. */\n readonly onChange: (id: string) => void;\n}\n\n/**\n * Chooses the basemap: a three-across grid of previews as a radio group, one\n * tile for each basemap the host offers (`useBasemaps`).\n *\n * Each tile is a native radio input, visually hidden and drawn through its\n * label. Native radios give one tab stop for the group, arrow keys that move\n * and select in one step (wrapping at the ends and following the writing\n * direction) and the radio role in every screen reader, with no script. The\n * selected tile has an accent outline and a check badge, so selection never\n * relies on colour. A preview that fails to load gives way to the basemap's\n * swatch, as a basemap with no preview does, with the name still visible. The\n * basemap does not follow the interface theme: a host's dark basemap is an\n * ordinary choice, as the others are.\n *\n * @remarks In Save data mode (`useSaveData`), and for a basemap that has no\n * preview image, no preview is requested: the tile shows the same frame\n * with a plain colour swatch, the basemap's own `swatch` colour or else the\n * map background. A basemap whose tiles are images (`usesMoreData`: a\n * raster map, or imagery under labels) carries the note \"Uses more data\". Names,\n * the radios and the selection badge are unchanged, and every basemap can\n * still be chosen.\n *\n * A basemap marked unavailable (`useBasemapAvailability`, which the host\n * sets when every tile of it failed) has the words \"Not available right\n * now\" inside its label, so they are part of the radio's name, and its\n * radio is natively disabled, so the arrow keys skip it, unless it is the\n * chosen one. While any basemap is marked, a \"Try again\" button under the\n * group clears every mark, so the map judges a basemap again when it is\n * chosen, and moves focus to the chosen radio, because the button goes.\n */\nexport function BasemapPicker({ value, onChange }: BasemapPickerProps) {\n const groupName = useId();\n const announce = useAnnounce();\n const catalogue = useBasemaps();\n const { t } = useMessages();\n const resolve = useResolveText();\n const shownId = catalogue.resolve(value).id;\n const saveData = useSaveData();\n const { unavailable, clear } = useBasemapAvailability();\n const group = useRef<HTMLDivElement>(null);\n\n // Clearing the marks removes this button, so focus moves to the chosen\n // radio instead of being lost with it.\n const tryAgain = () => {\n clear();\n group.current?.querySelector<HTMLInputElement>(\"input:checked\")?.focus();\n };\n\n const choose = (basemap: BasemapDefinition) => {\n announce(announceBasemap(resolve(basemap.name)));\n onChange(basemap.id);\n };\n\n return (\n <>\n <div\n ref={group}\n role=\"radiogroup\"\n aria-label={t(\"panels.basemap.groupLabel\", {})}\n className={grid}\n data-testid=\"basemap-picker\"\n >\n {catalogue.basemaps.map((basemap) => (\n <BasemapTile\n key={basemap.id}\n basemap={basemap}\n groupName={groupName}\n selected={basemap.id === shownId}\n saveData={saveData}\n unavailable={unavailable.has(basemap.id)}\n onChoose={() => choose(basemap)}\n />\n ))}\n </div>\n {unavailable.size > 0 ? (\n <div className={retry}>\n <Button\n variant=\"quiet\"\n onClick={tryAgain}\n data-testid=\"basemap-try-again\"\n >\n {t(\"panels.basemap.tryAgain\", {})}\n </Button>\n </div>\n ) : null}\n </>\n );\n}\n\ninterface BasemapTileProps {\n readonly basemap: BasemapDefinition;\n readonly groupName: string;\n readonly selected: boolean;\n /** Save data mode: a swatch instead of the preview, and a note on raster basemaps. */\n readonly saveData: boolean;\n /**\n * The basemap's provider is not working right now. The tile says so, and is\n * disabled unless it is the chosen one, which stays enabled so the group is\n * never left with a checked radio the keyboard cannot reach.\n */\n readonly unavailable: boolean;\n /** Called when this tile is chosen. */\n readonly onChoose: () => void;\n}\n\nfunction BasemapTile({\n basemap,\n groupName,\n selected,\n saveData,\n unavailable,\n onChoose,\n}: BasemapTileProps) {\n const { t } = useMessages();\n const resolve = useResolveText();\n const [failed, setFailed] = useState(false);\n const preview = saveData ? undefined : basemap.thumbnail;\n const showSwatch = preview === undefined || failed;\n // A ref callback with a listener, not an onError prop, which the a11y lint\n // rejects on a non-interactive element.\n const watchImage = useCallback((node: HTMLImageElement | null) => {\n if (!node) {\n return;\n }\n const fail = () => setFailed(true);\n node.addEventListener(\"error\", fail);\n return () => node.removeEventListener(\"error\", fail);\n }, []);\n // The basemap's own swatch colour, through a custom property.\n const swatchColour = basemap.swatch;\n const paintSwatch = useCallback(\n (element: HTMLElement | null) => {\n if (!element) {\n return;\n }\n if (swatchColour === undefined) {\n element.style.removeProperty(swatchColourVar);\n } else {\n element.style.setProperty(swatchColourVar, swatchColour);\n }\n },\n [swatchColour],\n );\n return (\n <label className={tile} data-testid={`basemap-option-${basemap.id}`}>\n <input\n type=\"radio\"\n className={visuallyHidden}\n name={groupName}\n value={basemap.id}\n checked={selected}\n disabled={unavailable && !selected}\n onChange={onChoose}\n />\n <span className={thumb({ selected, unavailable })}>\n {showSwatch ? (\n <span\n className={swatch}\n ref={paintSwatch}\n data-testid={`basemap-swatch-${basemap.id}`}\n />\n ) : null}\n {showSwatch ? null : (\n <img\n className={image}\n src={preview}\n alt=\"\"\n width={THUMB_WIDTH}\n height={THUMB_HEIGHT}\n loading=\"lazy\"\n decoding=\"async\"\n ref={watchImage}\n />\n )}\n {selected ? (\n <span\n className={badge}\n data-testid={`basemap-selected-${basemap.id}`}\n >\n <Icon icon={Check} className={badgeIcon} />\n </span>\n ) : null}\n </span>\n <span className={name({ selected })}>{resolve(basemap.name)}</span>\n {unavailable ? (\n <span\n className={dataNote}\n data-testid={`basemap-unavailable-note-${basemap.id}`}\n >\n {t(\"panels.basemap.unavailable\", {})}\n </span>\n ) : null}\n {saveData && usesMoreData(basemap) ? (\n <span\n className={dataNote}\n data-testid={`basemap-data-note-${basemap.id}`}\n >\n {t(\"panels.basemap.usesMoreData\", {})}\n </span>\n ) : null}\n </label>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,IAAM,cAAc;AACpB,IAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CrB,SAAgB,cAAc,EAAE,OAAO,YAAgC;CACrE,MAAM,YAAY,MAAM;CACxB,MAAM,WAAW,YAAY;CAC7B,MAAM,YAAY,YAAY;CAC9B,MAAM,EAAE,MAAM,YAAY;CAC1B,MAAM,UAAU,eAAe;CAC/B,MAAM,UAAU,UAAU,QAAQ,KAAK,CAAC,CAAC;CACzC,MAAM,WAAW,YAAY;CAC7B,MAAM,EAAE,aAAa,UAAU,uBAAuB;CACtD,MAAM,QAAQ,OAAuB,IAAI;CAIzC,MAAM,iBAAiB;EACrB,MAAM;EACN,MAAM,SAAS,cAAgC,eAAe,CAAC,EAAE,MAAM;CACzE;CAEA,MAAM,UAAU,YAA+B;EAC7C,SAAS,gBAAgB,QAAQ,QAAQ,IAAI,CAAC,CAAC;EAC/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